From 8761e017e5340d78c96a8c097fb1a32bb25697fb Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Mon, 15 Feb 2021 14:22:54 +0300 Subject: [PATCH 1/6] BSC OMNI bridge support --- CHANGELOG.md | 1 + .../assets/css/components/_dropdown.scss | 1 + .../assets/css/components/_label.scss | 8 +++ apps/block_scout_web/config/config.exs | 3 +- .../tokens/bridged_tokens_controller.ex | 51 ++++++++++++++-- .../templates/bridged_tokens/_tile.html.eex | 5 +- .../templates/bridged_tokens/index.html.eex | 2 +- .../templates/layout/_topnav.html.eex | 13 ++-- .../templates/tokens/_tile.html.eex | 2 +- .../templates/tokens/index.html.eex | 2 +- .../views/bridged_tokens_view.ex | 16 +++++ .../lib/block_scout_web/views/tokens_view.ex | 7 +-- .../lib/block_scout_web/web_router.ex | 2 +- apps/block_scout_web/priv/gettext/default.pot | 51 +++++++++------- .../priv/gettext/en/LC_MESSAGES/default.po | 51 +++++++++------- apps/explorer/lib/explorer/chain.ex | 61 ++++++++++++++++--- apps/indexer/lib/indexer/supervisor.ex | 5 +- 17 files changed, 202 insertions(+), 79 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 326fa47265..984aed9cd7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## Current ### Features +- [#3631](https://github.com/poanetwork/blockscout/pull/3631) - BSC OMNI bridge support - [#3603](https://github.com/poanetwork/blockscout/pull/3603) - Display method output parameter name at contract read page - [#3597](https://github.com/poanetwork/blockscout/pull/3597) - Show APY for delegators in Staking DApp - [#3584](https://github.com/poanetwork/blockscout/pull/3584) - Token holders API endpoint diff --git a/apps/block_scout_web/assets/css/components/_dropdown.scss b/apps/block_scout_web/assets/css/components/_dropdown.scss index b15f6c5c4a..3fe3831dcc 100644 --- a/apps/block_scout_web/assets/css/components/_dropdown.scss +++ b/apps/block_scout_web/assets/css/components/_dropdown.scss @@ -40,6 +40,7 @@ $dropdown-menu-item-hover-background: rgba($secondary, 0.1) !default; font-size: 12px; padding: 10px 20px; transition: $transition-cont; + white-space: initial; & { &.active, diff --git a/apps/block_scout_web/assets/css/components/_label.scss b/apps/block_scout_web/assets/css/components/_label.scss index 970dadba8c..f9fd228461 100644 --- a/apps/block_scout_web/assets/css/components/_label.scss +++ b/apps/block_scout_web/assets/css/components/_label.scss @@ -17,6 +17,14 @@ background: $secondary; color: #fff; } + &.destination-eth { + background: #253358; + color: #fff; + } + &.destination-bsc { + background: #e7b941; + color: #fff; + } &.secondary { background: $secondary; color: #fff; diff --git a/apps/block_scout_web/config/config.exs b/apps/block_scout_web/config/config.exs index 6ab54f6e8b..c865533fcb 100644 --- a/apps/block_scout_web/config/config.exs +++ b/apps/block_scout_web/config/config.exs @@ -35,7 +35,8 @@ config :block_scout_web, api_url: System.get_env("API_URL"), apps_menu: if(System.get_env("APPS_MENU", "false") == "true", do: true, else: false), external_apps: System.get_env("EXTERNAL_APPS"), - omni_bridge_mediator: System.get_env("OMNI_BRIDGE_MEDIATOR"), + eth_omni_bridge_mediator: System.get_env("ETH_OMNI_BRIDGE_MEDIATOR"), + bsc_omni_bridge_mediator: System.get_env("BSC_OMNI_BRIDGE_MEDIATOR"), amb_bridge_mediators: System.get_env("AMB_BRIDGE_MEDIATORS"), foreign_json_rpc: System.get_env("FOREIGN_JSON_RPC", ""), gas_price: System.get_env("GAS_PRICE", nil), diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/tokens/bridged_tokens_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/tokens/bridged_tokens_controller.ex index 7f5f34b470..6e29635c63 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/tokens/bridged_tokens_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/tokens/bridged_tokens_controller.ex @@ -7,11 +7,46 @@ defmodule BlockScoutWeb.BridgedTokensController do alias Explorer.Chain alias Phoenix.View - def index(conn, %{"type" => "JSON"} = params) do - tokens = + def show(conn, %{"type" => "JSON", "id" => "eth"} = params) do + show(conn, params, :eth) + end + + def show(conn, %{"type" => "JSON", "id" => "bsc"} = params) do + show(conn, params, :bsc) + end + + def show(conn, %{"id" => "eth"}) do + total_supply = Chain.total_supply() + + render(conn, "index.html", + current_path: current_path(conn), + total_supply: total_supply, + chain: "Ethereum", + chain_id: 1 + ) + end + + def show(conn, %{"id" => "bsc"}) do + total_supply = Chain.total_supply() + + render(conn, "index.html", + current_path: current_path(conn), + total_supply: total_supply, + chain: "Binance Smart Chain", + chain_id: 56 + ) + end + + def show(conn, _params) do + not_found(conn) + end + + defp show(conn, params, destination) do + full_params = params |> paging_options() - |> Chain.list_top_bridged_tokens() + + tokens = Chain.list_top_bridged_tokens(destination, full_params) {tokens_page, next_page} = split_list_by_page(tokens) @@ -23,7 +58,8 @@ defmodule BlockScoutWeb.BridgedTokensController do next_page_params -> bridged_tokens_path( conn, - :index, + :show, + destination, Map.delete(next_page_params, "type") ) end @@ -60,12 +96,17 @@ defmodule BlockScoutWeb.BridgedTokensController do ) end + def index(conn, %{"type" => "JSON"} = params) do + show(conn, params, :eth) + end + def index(conn, _params) do total_supply = Chain.total_supply() render(conn, "index.html", current_path: current_path(conn), - total_supply: total_supply + total_supply: total_supply, + chain: "Ethereum" ) end end diff --git a/apps/block_scout_web/lib/block_scout_web/templates/bridged_tokens/_tile.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/bridged_tokens/_tile.html.eex index 1ddaf92a8b..f76e36d6fb 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/bridged_tokens/_tile.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/bridged_tokens/_tile.html.eex @@ -30,9 +30,12 @@ <% end %> - <%= if @bridged_token.type do %> + <%= if @bridged_token && @bridged_token.type do %>
<%= String.upcase(@bridged_token.type) %>
<% end %> + <%= if @bridged_token && @bridged_token.foreign_chain_id do %> +
<%= String.upcase(chain_id_display_name(@bridged_token.foreign_chain_id)) %>
+ <% end %> diff --git a/apps/block_scout_web/lib/block_scout_web/templates/bridged_tokens/index.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/bridged_tokens/index.html.eex index 891a95ac01..237f9dcb7c 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/bridged_tokens/index.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/bridged_tokens/index.html.eex @@ -1,7 +1,7 @@
-

<%= gettext "Bridged Tokens" %>

+

<%= gettext "Bridged Tokens from " %><%= @chain %>
<%= String.upcase(chain_id_display_name(@chain_id)) %>

List of the tokens bridged through OmniBridge OMNI and Arbitrary Message Bridge AMB extensions

diff --git a/apps/block_scout_web/lib/block_scout_web/templates/layout/_topnav.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/layout/_topnav.html.eex index 537aa6d55c..3e196dac10 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/layout/_topnav.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/layout/_topnav.html.eex @@ -78,7 +78,7 @@ <%= gettext("Accounts") %> <% end %> - <%= if Application.get_env(:block_scout_web, :omni_bridge_mediator) && Application.get_env(:block_scout_web, :omni_bridge_mediator) != "" do %> + <%= if Chain.bridged_tokens_enabled?() do %>
-
- <%= if Map.has_key?(@token, :custom_metadata) do %> + <%= if Map.has_key?(@token, :custom_metadata) do %> +
<%= @token.custom_metadata %> - <% end %> -
+
+ <% end %> <% end %> -

<%= Address.checksum(@token.contract_address_hash) %>

+

<%= Address.checksum(@token.contract_address_hash) %>

diff --git a/apps/block_scout_web/lib/block_scout_web/views/bridged_tokens_view.ex b/apps/block_scout_web/lib/block_scout_web/views/bridged_tokens_view.ex index 57808ea34f..04d9d2096a 100644 --- a/apps/block_scout_web/lib/block_scout_web/views/bridged_tokens_view.ex +++ b/apps/block_scout_web/lib/block_scout_web/views/bridged_tokens_view.ex @@ -1,6 +1,7 @@ defmodule BlockScoutWeb.BridgedTokensView do use BlockScoutWeb, :view + alias Explorer.Chain alias Explorer.Chain.Token @owl_token_amb "0x0905Ab807F8FD040255F0cF8fa14756c1D824931" @@ -28,20 +29,4 @@ defmodule BlockScoutWeb.BridgedTokensView do def owl_token_omni_info do "
OWL token bridged through OmniBridge without support of burnOWL method. It is not recommended to use.
" end - - def chain_id_display_name(chain_id) do - chain_id_int = - if is_integer(chain_id) do - chain_id - else - chain_id - |> Decimal.to_integer() - end - - case chain_id_int do - 1 -> "eth" - 56 -> "bsc" - _ -> "" - end - end end diff --git a/apps/block_scout_web/priv/gettext/default.pot b/apps/block_scout_web/priv/gettext/default.pot index 1701efea91..62d8911c72 100644 --- a/apps/block_scout_web/priv/gettext/default.pot +++ b/apps/block_scout_web/priv/gettext/default.pot @@ -405,8 +405,8 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/address/overview.html.eex:34 #: lib/block_scout_web/templates/address/overview.html.eex:38 -#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:32 -#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:36 +#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:38 +#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:42 msgid "Copy Address" msgstr "" @@ -861,7 +861,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/tokens/instance/overview/_details.html.eex:10 -#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:26 +#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:32 msgid "Token Details" msgstr "" @@ -1181,8 +1181,8 @@ msgstr "" #: lib/block_scout_web/templates/address/overview.html.eex:158 #: lib/block_scout_web/templates/tokens/instance/overview/_details.html.eex:51 #: lib/block_scout_web/templates/tokens/instance/overview/_details.html.eex:107 -#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:52 -#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:137 +#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:58 +#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:140 msgid "QR Code" msgstr "" @@ -1291,7 +1291,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/address/overview.html.eex:55 #: lib/block_scout_web/templates/tokens/instance/overview/_details.html.eex:52 -#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:53 +#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:59 msgid "Show QR Code" msgstr "" @@ -1453,7 +1453,7 @@ msgid "Topics" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:107 +#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:110 msgid "Total Supply" msgstr "" @@ -1610,7 +1610,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/tokens/instance/overview/_details.html.eex:16 #: lib/block_scout_web/templates/tokens/instance/overview/_details.html.eex:20 -#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:87 +#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:90 msgid "View Contract" msgstr "" @@ -1725,8 +1725,8 @@ msgstr "" #: lib/block_scout_web/templates/address/overview.html.eex:167 #: lib/block_scout_web/templates/tokens/instance/overview/_details.html.eex:108 #: lib/block_scout_web/templates/tokens/instance/overview/_details.html.eex:116 -#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:138 -#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:146 +#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:141 +#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:149 msgid "Close" msgstr "" @@ -1743,7 +1743,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/tokens/instance/overview/_details.html.eex:76 -#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:95 +#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:98 msgid "Decimals" msgstr "" @@ -2678,7 +2678,7 @@ msgid "Approximate Current Annual Percentage Yield. If you see N/A, please wait msgstr "" #, elixir-format -#: lib/block_scout_web/templates/bridged_tokens/index.html.eex:5 +#: lib/block_scout_web/templates/bridged_tokens/index.html.eex:6 msgid "Bridged Tokens from " msgstr "" diff --git a/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po b/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po index 1701efea91..62d8911c72 100644 --- a/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po +++ b/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po @@ -405,8 +405,8 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/address/overview.html.eex:34 #: lib/block_scout_web/templates/address/overview.html.eex:38 -#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:32 -#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:36 +#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:38 +#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:42 msgid "Copy Address" msgstr "" @@ -861,7 +861,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/tokens/instance/overview/_details.html.eex:10 -#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:26 +#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:32 msgid "Token Details" msgstr "" @@ -1181,8 +1181,8 @@ msgstr "" #: lib/block_scout_web/templates/address/overview.html.eex:158 #: lib/block_scout_web/templates/tokens/instance/overview/_details.html.eex:51 #: lib/block_scout_web/templates/tokens/instance/overview/_details.html.eex:107 -#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:52 -#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:137 +#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:58 +#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:140 msgid "QR Code" msgstr "" @@ -1291,7 +1291,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/address/overview.html.eex:55 #: lib/block_scout_web/templates/tokens/instance/overview/_details.html.eex:52 -#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:53 +#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:59 msgid "Show QR Code" msgstr "" @@ -1453,7 +1453,7 @@ msgid "Topics" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:107 +#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:110 msgid "Total Supply" msgstr "" @@ -1610,7 +1610,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/tokens/instance/overview/_details.html.eex:16 #: lib/block_scout_web/templates/tokens/instance/overview/_details.html.eex:20 -#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:87 +#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:90 msgid "View Contract" msgstr "" @@ -1725,8 +1725,8 @@ msgstr "" #: lib/block_scout_web/templates/address/overview.html.eex:167 #: lib/block_scout_web/templates/tokens/instance/overview/_details.html.eex:108 #: lib/block_scout_web/templates/tokens/instance/overview/_details.html.eex:116 -#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:138 -#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:146 +#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:141 +#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:149 msgid "Close" msgstr "" @@ -1743,7 +1743,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/tokens/instance/overview/_details.html.eex:76 -#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:95 +#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:98 msgid "Decimals" msgstr "" @@ -2678,7 +2678,7 @@ msgid "Approximate Current Annual Percentage Yield. If you see N/A, please wait msgstr "" #, elixir-format -#: lib/block_scout_web/templates/bridged_tokens/index.html.eex:5 +#: lib/block_scout_web/templates/bridged_tokens/index.html.eex:6 msgid "Bridged Tokens from " msgstr "" diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index d62a26e1e4..7832c32293 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -5797,4 +5797,22 @@ defmodule Explorer.Chain do bsc_omni_bridge_mediator && bsc_omni_bridge_mediator !== "" end + + def chain_id_display_name(nil), do: "" + + def chain_id_display_name(chain_id) do + chain_id_int = + if is_integer(chain_id) do + chain_id + else + chain_id + |> Decimal.to_integer() + end + + case chain_id_int do + 1 -> "eth" + 56 -> "bsc" + _ -> "" + end + end end From f5447574e48db2b4c5d6dc99000a5433594f1e3e Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Thu, 18 Feb 2021 21:39:12 +0300 Subject: [PATCH 5/6] Correct price for surf.finance token --- CHANGELOG.md | 1 + apps/explorer/lib/explorer/exchange_rates/source/coin_gecko.ex | 1 + 2 files changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ea20248b5..78ee563a4b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ - [#3577](https://github.com/poanetwork/blockscout/pull/3577) - Eliminate GraphiQL page XSS attack ### Chore +- [#3644](https://github.com/poanetwork/blockscout/pull/3644) - Correct exchange rate for SURF.finance token - [#3618](https://github.com/poanetwork/blockscout/pull/3618) - Contracts verification up to 10 libraries - [#3616](https://github.com/poanetwork/blockscout/pull/3616) - POSDAO refactoring: use zero address instead of staker address for certain cases - [#3612](https://github.com/poanetwork/blockscout/pull/3612) - POSDAO refactoring: use 'getDelegatorPools' getter instead of 'getStakerPools' in Staking DApp diff --git a/apps/explorer/lib/explorer/exchange_rates/source/coin_gecko.ex b/apps/explorer/lib/explorer/exchange_rates/source/coin_gecko.ex index a178ab5883..7c138fd1a9 100644 --- a/apps/explorer/lib/explorer/exchange_rates/source/coin_gecko.ex +++ b/apps/explorer/lib/explorer/exchange_rates/source/coin_gecko.ex @@ -182,6 +182,7 @@ defmodule Explorer.ExchangeRates.Source.CoinGecko do defp bridged_token_symbol_to_id_mapping_to_get_price(symbol) do case symbol do "UNI" -> "uniswap" + "SURF" -> "surf-finance" _symbol -> nil end end From d376b8b1ca935d4e023ee78bf161d74b7bebec91 Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Fri, 19 Feb 2021 08:49:14 +0300 Subject: [PATCH 6/6] Change Twitter handle --- CHANGELOG.md | 1 + .../lib/block_scout_web/templates/layout/_footer.html.eex | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 78ee563a4b..b8aa537a15 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ - [#3577](https://github.com/poanetwork/blockscout/pull/3577) - Eliminate GraphiQL page XSS attack ### Chore +- [#3645](https://github.com/poanetwork/blockscout/pull/3645) - Change Twitter handle - [#3644](https://github.com/poanetwork/blockscout/pull/3644) - Correct exchange rate for SURF.finance token - [#3618](https://github.com/poanetwork/blockscout/pull/3618) - Contracts verification up to 10 libraries - [#3616](https://github.com/poanetwork/blockscout/pull/3616) - POSDAO refactoring: use zero address instead of staker address for certain cases diff --git a/apps/block_scout_web/lib/block_scout_web/templates/layout/_footer.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/layout/_footer.html.eex index c82bb8b1cf..e972d44a11 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/layout/_footer.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/layout/_footer.html.eex @@ -22,7 +22,7 @@ - +