Skip to content

Commit

Permalink
feat(wallet): disable EIP-1559 on Polygon and Avalanche
Browse files Browse the repository at this point in the history
Our current EIP-1559 gas oracle queries the Etherscan API, which only
supports Ethereum mainnet. As a result, priority fee estimations on
custom networks use results for Ethereum mainnet, which can either
result in transactions being stuck in the mempool forever, or in
over-payment of gas fees.

This commit will be reverted in brave/brave-browser#20469.
  • Loading branch information
onyb committed Jan 25, 2022
1 parent ba7bcad commit 328346f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
14 changes: 14 additions & 0 deletions components/brave_wallet/browser/json_rpc_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,21 @@ void JsonRpcService::UpdateIsEip1559(const std::string& chain_id,
if (error != mojom::ProviderError::kSuccess)
return;

// Disable EIP-1559 on selected networks, by overwriting is_eip1559 to
// false.
//
// This list needs to be updated until we have a generic EIP-1559 gas
// oracle. See: https://github.com/brave/brave-browser/issues/20469.
if (chain_id == "0x13881" || // Polygon Mumbai Testnet
chain_id == "0x89" || // Polygon Mainnet
chain_id == "0xa86a" || // Avalanche Mainnet
chain_id == "0xa869" // Avalanche Fuji Testnet
) {
is_eip1559 = false;
}

bool changed = false;

if (chain_id == brave_wallet::mojom::kLocalhostChainId) {
changed = prefs_->GetBoolean(kSupportEip1559OnLocalhostChain) != is_eip1559;
prefs_->SetBoolean(kSupportEip1559OnLocalhostChain, is_eip1559);
Expand Down
35 changes: 35 additions & 0 deletions components/brave_wallet/browser/json_rpc_service_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1386,6 +1386,41 @@ TEST_F(JsonRpcServiceUnitTest, UpdateIsEip1559CustomChain) {
EXPECT_FALSE(GetIsEip1559FromPrefs(chain2.chain_id));
}

TEST_F(JsonRpcServiceUnitTest, UpdateIsEip1559DisablePolygon) {
std::vector<base::Value> values;

// Define EthereumChain for Polygon network with is_eip1559 set to true.
brave_wallet::mojom::EthereumChain polygon(
"0x89", "Polygon Mainnet", {"https://url.com"}, {"https://url.com"},
{"https://url.com"}, "Polygon Matic", "MATIC", 18, true);
auto polygon_ptr = polygon.Clone();
values.push_back(brave_wallet::EthereumChainToValue(polygon_ptr));

UpdateCustomNetworks(prefs(), &values);

// Expected is_eip1559 should always be false for Polygon.
TestJsonRpcServiceObserver observer(polygon.chain_id, false);
json_rpc_service_->AddObserver(observer.GetReceiver());

// Switching to Polygon should update is_eip1559 to false, even if it
// was previously set to true.
EXPECT_TRUE(GetIsEip1559FromPrefs(polygon.chain_id));
SetIsEip1559Interceptor(true);
SetNetwork(polygon.chain_id);
EXPECT_TRUE(observer.chain_changed_called());
EXPECT_TRUE(observer.is_eip1559_changed_called());
EXPECT_FALSE(GetIsEip1559FromPrefs(polygon.chain_id));

// Switching to Polygon again should not call observer methods for change
// in is_eip1559.
observer.Reset(polygon.chain_id, false);
SetIsEip1559Interceptor(true);
SetNetwork(polygon.chain_id);
EXPECT_TRUE(observer.chain_changed_called());
EXPECT_FALSE(observer.is_eip1559_changed_called());
EXPECT_FALSE(GetIsEip1559FromPrefs(polygon.chain_id));
}

TEST_F(JsonRpcServiceUnitTest, GetEthAddrInvalidDomain) {
const std::vector<std::string> invalid_domains = {"", ".eth", "-brave.eth",
"brave-.eth", "b.eth"};
Expand Down

0 comments on commit 328346f

Please sign in to comment.