Skip to content

Commit

Permalink
Support resolving on Base chain for UD
Browse files Browse the repository at this point in the history
  • Loading branch information
supermassive committed Jan 13, 2025
1 parent afd4e02 commit 74d02f3
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 13 deletions.
15 changes: 9 additions & 6 deletions components/brave_wallet/browser/brave_wallet_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,17 @@ bool IsValidEntropySize(size_t entropy_size) {
return true;
}

// Addresses taken from https://docs.unstoppabledomains.com/developer-toolkit/
// smart-contracts/uns-smart-contracts/#proxyreader
const base::flat_map<std::string, std::string>
const base::flat_map<std::string_view, std::string_view>
kUnstoppableDomainsProxyReaderContractAddressMap = {
// https://github.com/unstoppabledomains/uns/blob/abd9e12409094dd6ea8611ebffdade8db49c4b56/uns-config.json#L76
{brave_wallet::mojom::kMainnetChainId,
"0xc3C2BAB5e3e52DBF311b2aAcEf2e40344f19494E"},
"0x578853aa776Eef10CeE6c4dd2B5862bdcE767A8B"},
// https://github.com/unstoppabledomains/uns/blob/abd9e12409094dd6ea8611ebffdade8db49c4b56/uns-config.json#L221
{brave_wallet::mojom::kPolygonMainnetChainId,
"0xA3f32c8cd786dc089Bd1fC175F2707223aeE5d00"}};
"0x91EDd8708062bd4233f4Dd0FCE15A7cb4d500091"},
// https://github.com/unstoppabledomains/uns/blob/abd9e12409094dd6ea8611ebffdade8db49c4b56/uns-config.json#L545
{brave_wallet::mojom::kBaseMainnetChainId,
"0x78c4b414e1abdf0de267deda01dffd4cd0817a16"}};

constexpr const char kEnsRegistryContractAddress[] =
"0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e";
Expand Down Expand Up @@ -550,7 +553,7 @@ std::string GetDefaultBaseCryptocurrency(PrefService* prefs) {
return prefs->GetString(kDefaultBaseCryptocurrency);
}

std::string GetUnstoppableDomainsProxyReaderContractAddress(
std::string_view GetUnstoppableDomainsProxyReaderContractAddress(
std::string_view chain_id) {
std::string chain_id_lower = base::ToLowerASCII(chain_id);
if (kUnstoppableDomainsProxyReaderContractAddressMap.contains(
Expand Down
2 changes: 1 addition & 1 deletion components/brave_wallet/browser/brave_wallet_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void SetDefaultBaseCryptocurrency(PrefService* prefs,
std::string_view cryptocurrency);
std::string GetDefaultBaseCryptocurrency(PrefService* prefs);

std::string GetUnstoppableDomainsProxyReaderContractAddress(
std::string_view GetUnstoppableDomainsProxyReaderContractAddress(
std::string_view chain_id);
std::string GetEnsRegistryContractAddress(std::string_view chain_id);

Expand Down
11 changes: 6 additions & 5 deletions components/brave_wallet/browser/json_rpc_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1715,8 +1715,9 @@ void JsonRpcService::UnstoppableDomainsResolveDns(
base::BindOnce(&JsonRpcService::OnUnstoppableDomainsResolveDns,
weak_ptr_factory_.GetWeakPtr(), domain, chain_id);
auto eth_call = eth::eth_call(
"", GetUnstoppableDomainsProxyReaderContractAddress(chain_id), "", "",
"", *data, kEthereumBlockTagLatest);
"",
std::string(GetUnstoppableDomainsProxyReaderContractAddress(chain_id)),
"", "", "", *data, kEthereumBlockTagLatest);
RequestInternal(std::move(eth_call), true,
NetworkManager::GetUnstoppableDomainsRpcUrl(chain_id),
std::move(internal_callback));
Expand Down Expand Up @@ -1787,9 +1788,9 @@ void JsonRpcService::UnstoppableDomainsGetWalletAddr(
auto internal_callback =
base::BindOnce(&JsonRpcService::OnUnstoppableDomainsGetWalletAddr,
weak_ptr_factory_.GetWeakPtr(), key, chain_id);
auto eth_call =
eth::eth_call(GetUnstoppableDomainsProxyReaderContractAddress(chain_id),
ToHex(call_data));
auto eth_call = eth::eth_call(
std::string(GetUnstoppableDomainsProxyReaderContractAddress(chain_id)),
ToHex(call_data));
RequestInternal(std::move(eth_call), true,
NetworkManager::GetUnstoppableDomainsRpcUrl(chain_id),
std::move(internal_callback));
Expand Down
2 changes: 2 additions & 0 deletions components/brave_wallet/browser/network_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,8 @@ GURL NetworkManager::GetUnstoppableDomainsRpcUrl(std::string_view chain_id) {
return GetEthMainnet()->rpc_endpoints.front();
} else if (chain_id == mojom::kPolygonMainnetChainId) {
return GetPolygonMainnet()->rpc_endpoints.front();
} else if (chain_id == mojom::kBaseMainnetChainId) {
return GetBaseMainnet()->rpc_endpoints.front();
}

NOTREACHED();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ MultichainCall<ResultType>::GetEffectiveResponse() {
return nullptr;
}

auto base_result = responses_.find(mojom::kBaseMainnetChainId);
if (base_result == responses_.end()) {
return nullptr;
}

auto eth_mainnet_result = responses_.find(mojom::kMainnetChainId);
if (eth_mainnet_result == responses_.end()) {
return nullptr;
Expand All @@ -63,6 +68,10 @@ MultichainCall<ResultType>::GetEffectiveResponse() {
return &polygon_result->second;
}

if (base_result->second.result || base_result->second.error) {
return &base_result->second;
}

return &eth_mainnet_result->second;
}

Expand All @@ -86,7 +95,8 @@ bool MultichainCall<ResultType>::MaybeResolveCallbacks() {
template <class KeyType, class ResultType>
std::vector<std::string> MultichainCalls<KeyType, ResultType>::GetChains()
const {
return {mojom::kPolygonMainnetChainId, mojom::kMainnetChainId};
return {mojom::kPolygonMainnetChainId, mojom::kBaseMainnetChainId,
mojom::kMainnetChainId};
}

template <class KeyType, class ResultType>
Expand Down

0 comments on commit 74d02f3

Please sign in to comment.