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 27, 2022
1 parent 2e64e76 commit afd1157
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
13 changes: 13 additions & 0 deletions components/brave_wallet/browser/eth_json_rpc_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,19 @@ void EthJsonRpcController::UpdateIsEip1559(const std::string& chain_id,
if (!success)
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,41 @@ TEST_F(EthJsonRpcControllerUnitTest, UpdateIsEip1559CustomChain) {
EXPECT_FALSE(GetIsEip1559FromPrefs(chain2.chain_id));
}

TEST_F(EthJsonRpcControllerUnitTest, 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.
TestEthJsonRpcControllerObserver observer(polygon.chain_id, false);
rpc_controller_->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(EthJsonRpcControllerUnitTest, GetEthAddrInvalidDomain) {
const std::vector<std::string> invalid_domains = {"", ".eth", "-brave.eth",
"brave-.eth", "b.eth"};
Expand Down

0 comments on commit afd1157

Please sign in to comment.