8000 Support token price for multiple symbol with same token by tdroxler · Pull Request #630 · alephium/explorer-backend · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Support token price for multiple symbol with same token #630

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions app/src/main/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,24 @@ explorer {

market {
symbol-name {
"ALPH" = "alephium",
"USDC" = "usd-coin",
"USDT" = "tether",
"WBTC" = "wrapped-bitcoin",
"WETH" = "weth",
"DAI" = "dai",
"AYIN" = "ayin",
"ABX" = "alphbanx",
"APAD" = "alphpad"
"EX" = "elexium"
"ONION" = "myonion-fun"
"ALPH" = "alephium",
# USDC values
"USDC" = "usd-coin",
"USDCeth" = "usd-coin",
"USDCbsc" = "usd-coin",
# USDT values
"USDT" = "tether",
"USDTeth" = "tether",
"USDTbsc" = "tether",
# Others
"WBTC" = "wrapped-bitcoin",
"WETH" = "weth",
"DAI" = "dai",
"AYIN" = "ayin",
"ABX" = "alphbanx",
"APAD" = "alphpad"
"EX" = "elexium"
"ONION" = "myonion-fun"
}
chart-symbol-name {
"ALPH" = "alephium"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ object MarketService extends StrictLogging {
private val chartIds: ListMap[String, String] = marketConfig.chartSymbolName

private def symbolNames: ListMap[String, String] = marketConfi 10000 g.symbolName
private val symbolNamesR = symbolNames.map(_.swap)
private val symbolNamesR: Map[String, Iterable[String]] =
symbolNames.groupMap { case (_, v) => v } { case (k, _) => k }

private val baseCurrency: String = "usd"

Expand Down Expand Up @@ -542,11 +543,15 @@ object MarketService extends StrictLogging {
json match {
case obj: ujson.Obj =>
Try {
ArraySeq.from(obj.value.flatMap { case (name, value) =>
symbolNamesR.get(name).map { id =>
CoingeckoPrice(id, value(baseCurrency).num)
}
})
ArraySeq
.from(obj.value.flatMap { case (name, value) =>
symbolNamesR.get(name).map { ids =>
ids.map { id =>
CoingeckoPrice(id, value(baseCurrency).num)
}
}
})
.flatten
}.toEither.left.map { error =>
error.getMessage
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,16 @@ class MarketServiceSpec extends AlephiumFutureSpec {
}
}

"support multiple symbol with same token" in new Fixture {

marketService.start().futureValue

eventually {
marketService.getPrices(ArraySeq("USDC"), "usd").rightValue is ArraySeq(Some(usdcPrice))
marketService.getPrices(ArraySeq("USDCeth"), "usd").rightValue is ArraySeq(Some(usdcPrice))
}
}

trait Fixture {
val localhost: InetAddress = InetAddress.getByName("127.0.0.1")
val coingeckoPort = SocketUtil.temporaryLocalPort(SocketUtil.Both)
Expand Down Expand Up @@ -183,16 +193,18 @@ object MarketServiceSpec {
Codec.string.map(value => ujson.read(value))(_.toString)

val alphPrice = 1.223123123
val usdcPrice = 1.0012412
var usdtPrice = 1.0012412

val symbolNames = ListMap(
"ALPH" -> "alephium",
"USDC" -> "usd-coin",
"USDT" -> "tether",
"WBTC" -> "wrapped-bitcoin",
"WETH" -> "weth",
"DAI" -> "dai",
"AYIN" -> "ayin"
"ALPH" -> "alephium",
"USDC" -> "usd-coin",
"USDCeth" -> "usd-coin",
"USDT" -> "tether",
"WBTC" -> "wrapped-bitcoin",
"WETH" -> "weth",
"DAI" -> "dai",
"AYIN" -> "ayin"
)
val currencies =
ArraySeq("btc", "usd", "eur", "chf", "gbp", "idr", "vnd", "rub", "try", "cad", "aud")
Expand Down Expand Up @@ -314,6 +326,9 @@ object MarketServiceSpec {
val coingeckoPrices: String = s"""{
"alephium": {
"usd": $alphPrice
},
"usd-coin": {
"usd": $usdcPrice
}
}"""

Expand Down
2 changes: 1 addition & 1 deletion e2e/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: "3.9"

services:
alephium:
image: alephium/alephium:v3.14.2
image: alephium/alephium:v4.0.0
restart: unless-stopped
ports:
- 19973:19973/tcp
Expand Down
0