|
|
|
@ -14,7 +14,7 @@ defmodule Explorer.Chain.Supply.TokenBridge do |
|
|
|
|
alias Explorer.Chain.Cache.TokenExchangeRate, as: TokenExchangeRateCache |
|
|
|
|
alias Explorer.Counters.Bridge |
|
|
|
|
alias Explorer.ExchangeRates.Source |
|
|
|
|
alias Explorer.Repo |
|
|
|
|
alias Explorer.{CustomContractsHelpers, Repo} |
|
|
|
|
alias Explorer.SmartContract.Reader |
|
|
|
|
|
|
|
|
|
@token_bridge_contract_address "0x7301CFA0e1756B71869E93d4e4Dca5c7d0eb0AA6" |
|
|
|
@ -210,7 +210,7 @@ defmodule Explorer.Chain.Supply.TokenBridge do |
|
|
|
|
on: t.contract_address_hash == bt.home_token_contract_address_hash, |
|
|
|
|
where: bt.foreign_chain_id == ^1, |
|
|
|
|
where: t.bridged == true, |
|
|
|
|
select: {bt.home_token_contract_address_hash, t.symbol, bt.custom_cap}, |
|
|
|
|
select: {bt.home_token_contract_address_hash, t.symbol, bt.custom_cap, bt.foreign_token_contract_address_hash}, |
|
|
|
|
order_by: [desc: t.holder_count] |
|
|
|
|
) |
|
|
|
|
|
|
|
|
@ -221,17 +221,19 @@ defmodule Explorer.Chain.Supply.TokenBridge do |
|
|
|
|
defp get_bridged_mainnet_tokens_supply(bridged_mainnet_tokens_list) do |
|
|
|
|
bridged_mainnet_tokens_with_supply = |
|
|
|
|
bridged_mainnet_tokens_list |
|
|
|
|
|> Enum.map(fn {bridged_token_hash, bridged_token_symbol, bridged_token_custom_cap} -> |
|
|
|
|
|> Enum.map(fn {bridged_token_hash, _bridged_token_symbol, bridged_token_custom_cap, |
|
|
|
|
foreign_token_contract_address_hash} -> |
|
|
|
|
if bridged_token_custom_cap do |
|
|
|
|
{bridged_token_hash, Decimal.new(0), Decimal.new(0), bridged_token_custom_cap} |
|
|
|
|
else |
|
|
|
|
bridged_token_price_from_cache = TokenExchangeRateCache.fetch(bridged_token_hash, bridged_token_symbol) |
|
|
|
|
bridged_token_price_from_cache = |
|
|
|
|
TokenExchangeRateCache.fetch(bridged_token_hash, foreign_token_contract_address_hash) |
|
|
|
|
|
|
|
|
|
bridged_token_price = |
|
|
|
|
if bridged_token_price_from_cache && Decimal.cmp(bridged_token_price_from_cache, 0) == :gt do |
|
|
|
|
bridged_token_price_from_cache |
|
|
|
|
else |
|
|
|
|
TokenExchangeRateCache.fetch_token_exchange_rate(bridged_token_symbol) |
|
|
|
|
TokenExchangeRateCache.fetch_token_exchange_rate_by_address(foreign_token_contract_address_hash) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
query = |
|
|
|
@ -266,11 +268,17 @@ defmodule Explorer.Chain.Supply.TokenBridge do |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
defp calc_omni_bridge_market_cap(bridged_mainnet_tokens_with_supply) do |
|
|
|
|
test_token_addresses = CustomContractsHelpers.get_custom_addresses_list(:test_tokens_addresses) |
|
|
|
|
|
|
|
|
|
config = Application.get_env(:explorer, Explorer.Counters.Bridge) |
|
|
|
|
disable_lp_tokens_in_market_cap = Keyword.get(config, :disable_lp_tokens_in_market_cap) |
|
|
|
|
|
|
|
|
|
omni_bridge_market_cap = |
|
|
|
|
bridged_mainnet_tokens_with_supply |
|
|
|
|
|> Enum.filter(fn {bridged_token_hash, _, _, _} -> |
|
|
|
|
bridged_token_hash_str = "0x" <> Base.encode16(bridged_token_hash.bytes, case: :lower) |
|
|
|
|
!Enum.member?(test_token_addresses, bridged_token_hash_str) |
|
|
|
|
end) |
|
|
|
|
|> Enum.reduce(Decimal.new(0), fn {_bridged_token_hash, bridged_token_price, bridged_token_balance, |
|
|
|
|
bridged_token_custom_cap}, |
|
|
|
|
acc -> |
|
|
|
@ -278,7 +286,8 @@ defmodule Explorer.Chain.Supply.TokenBridge do |
|
|
|
|
Decimal.add(acc, bridged_token_custom_cap) |
|
|
|
|
else |
|
|
|
|
if bridged_token_price do |
|
|
|
|
Decimal.add(acc, Decimal.mult(bridged_token_price, bridged_token_balance)) |
|
|
|
|
bridged_token_cap = Decimal.mult(bridged_token_price, bridged_token_balance) |
|
|
|
|
Decimal.add(acc, bridged_token_cap) |
|
|
|
|
else |
|
|
|
|
acc |
|
|
|
|
end |
|
|
|
|