Merge pull request #8446 from blockscout/vb-fix-market-cap-calc

Fix market cap calculation in case of CMC
pull/8338/head
Victor Baranov 1 year ago committed by GitHub
commit d82cd12147
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 6
      apps/explorer/lib/explorer/exchange_rates/source/coin_market_cap.ex
  3. 99
      apps/explorer/test/explorer/exchange_rates/source/coin_market_cap_test.exs
  4. 4
      cspell.json

@ -15,6 +15,7 @@
### Fixes
- [#8446](https://github.com/blockscout/blockscout/pull/8446) - Fix market cap calculation in case of CMC
- [#8431](https://github.com/blockscout/blockscout/pull/8431) - Fix contracts' output decoding
- [#8354](https://github.com/blockscout/blockscout/pull/8354) - Hotfix for proper addresses' tokens displaying
- [#8350](https://github.com/blockscout/blockscout/pull/8350) - Add Base Mainnet support for tx actions

@ -107,7 +107,11 @@ defmodule Explorer.ExchangeRates.Source.CoinMarketCap do
true <- Enum.count(token_values_list) > 0,
token_values <- token_values_list |> Enum.at(0),
true <- Enum.count(token_values) > 0 do
token_values |> Enum.at(0)
if is_list(token_values) do
token_values |> Enum.at(0)
else
token_values
end
else
_ -> %{}
end

@ -34,4 +34,103 @@ defmodule Explorer.ExchangeRates.Source.CoinMarketCapTest do
CoinMarketCap.source_url("ETH")
end
end
@token_properties %{
"circulating_supply" => 0,
"cmc_rank" => 2977,
"date_added" => "2021-12-06T11:25:31.000Z",
"id" => 15658,
"infinite_supply" => false,
"is_active" => 1,
"is_fiat" => 0,
"last_updated" => "2023-09-12T09:03:00.000Z",
"max_supply" => 210_240_000,
"name" => "Qitmeer Network",
"num_market_pairs" => 10,
"platform" => nil,
"quote" => %{
"USD" => %{
"fully_diluted_market_cap" => 27_390_222.61,
"last_updated" => "2023-09-12T09:03:00.000Z",
"market_cap" => 0,
"market_cap_dominance" => 0,
"percent_change_1h" => -0.14807635,
"percent_change_24h" => -4.05784287,
"percent_change_30d" => -20.18918329,
"percent_change_60d" => 85.21384726,
"percent_change_7d" => -5.49776979,
"percent_change_90d" => 22.27442093,
"price" => 0.13028073920022334,
"tvl" => nil,
"volume_24h" => 93766.09652096,
"volume_change_24h" => -0.9423
}
},
"self_reported_circulating_supply" => 71_348_557,
"self_reported_market_cap" => 9_295_342.74682927,
"slug" => "qitmeer-network",
"symbol" => "MEER",
"tags" => [],
"total_supply" => 71_348_557,
"tvl_ratio" => nil
}
@market_data_multiple_tokens %{
"MEER" => [
@token_properties,
%{
"circulating_supply" => nil,
"cmc_rank" => nil,
"date_added" => "2023-05-12T15:52:05.000Z",
"id" => 25240,
"infinite_supply" => false,
"is_active" => 0,
"is_fiat" => 0,
"last_updated" => "2023-09-12T09:05:15.725Z",
"max_supply" => 210_240_000,
"name" => "Meer Coin",
"num_market_pairs" => nil,
"platform" => nil,
"quote" => %{
"USD" => %{
"fully_diluted_market_cap" => nil,
"last_updated" => "2023-09-12T09:05:15.725Z",
"market_cap" => nil,
"market_cap_dominance" => nil,
"percent_change_1h" => nil,
"percent_change_24h" => nil,
"percent_change_30d" => nil,
"percent_change_60d" => nil,
"percent_change_7d" => nil,
"percent_change_90d" => nil,
"price" => 0,
"tvl" => nil,
"volume_24h" => nil,
"volume_change_24h" => nil
}
},
"self_reported_circulating_supply" => nil,
"self_reported_market_cap" => nil,
"slug" => "meer-coin",
"symbol" => "MEER",
"tags" => [],
"total_supply" => nil,
"tvl_ratio" => nil
}
]
}
@market_data_single_token %{
"15658" => @token_properties
}
describe "get_token_properties/1" do
test "returns a single token property, when market_data contains multiple tokens" do
assert CoinMarketCap.get_token_properties(@market_data_multiple_tokens) == @token_properties
end
test "returns a single token property, when market_data contains a single token" do
assert CoinMarketCap.get_token_properties(@market_data_single_token) == @token_properties
end
end
end

@ -522,7 +522,9 @@
"secp",
"qwertyuioiuytrewertyuioiuytrertyuio",
"urlset",
"lastmod"
"lastmod",
"qitmeer",
"meer",
],
"enableFiletypes": [
"dotenv",

Loading…
Cancel
Save