Skip to content

Commit

Permalink
Increase erc20 xcm gas cost (#2408)
Browse files Browse the repository at this point in the history
* improve erc20 amount conversion

* increase Erc20XcmBridgeTransferGasLimit from 80,000 to 200,000

* fix ts tests
  • Loading branch information
librelois committed Jul 25, 2023
1 parent 030f898 commit 82d38ce
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 6 deletions.
25 changes: 23 additions & 2 deletions pallets/erc20-xcm-bridge/src/erc20_matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ impl<Erc20MultilocationPrefix: Get<MultiLocation>> MatchesFungibles<H160, U256>
};
let contract_address = Self::matches_erc20_multilocation(id)
.map_err(|_| MatchError::AssetIdConversionFailed)?;
let amount =
U256::try_from(*amount).map_err(|_| MatchError::AmountToBalanceConversionFailed)?;
let amount = U256::from(*amount);

Ok((contract_address, amount))
}
Expand Down Expand Up @@ -114,6 +113,28 @@ mod tests {
);
}

#[test]
fn should_match_valid_erc20_location_with_amount_greater_than_u64() {
let location = MultiLocation {
parents: 0,
interior: Junctions::X2(
PalletInstance(42u8),
AccountKey20 {
key: [0; 20],
network: None,
},
),
};

assert_ok!(
Erc20Matcher::<Erc20MultilocationPrefix>::matches_fungibles(&MultiAsset::from((
location,
100000000000000000u128
))),
(H160([0; 20]), U256::from(100000000000000000u128))
);
}

#[test]
fn should_not_match_invalid_erc20_location() {
let invalid_location = MultiLocation {
Expand Down
2 changes: 1 addition & 1 deletion runtime/moonbase/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ parameter_types! {

// To be able to support almost all erc20 implementations,
// we provide a sufficiently hight gas limit.
pub Erc20XcmBridgeTransferGasLimit: u64 = 80_000;
pub Erc20XcmBridgeTransferGasLimit: u64 = 200_000;
}

impl pallet_erc20_xcm_bridge::Config for Runtime {
Expand Down
2 changes: 1 addition & 1 deletion runtime/moonbeam/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ parameter_types! {

// To be able to support almost all erc20 implementations,
// we provide a sufficiently hight gas limit.
pub Erc20XcmBridgeTransferGasLimit: u64 = 80_000;
pub Erc20XcmBridgeTransferGasLimit: u64 = 200_000;
}

impl pallet_erc20_xcm_bridge::Config for Runtime {
Expand Down
2 changes: 1 addition & 1 deletion runtime/moonriver/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ parameter_types! {

// To be able to support almost all erc20 implementations,
// we provide a sufficiently hight gas limit.
pub Erc20XcmBridgeTransferGasLimit: u64 = 80_000;
pub Erc20XcmBridgeTransferGasLimit: u64 = 200_000;
}

impl pallet_erc20_xcm_bridge::Config for Runtime {
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/test-precompile/test-precompile-wormhole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ describeDevMoonbeam(`Test local Wormhole`, (context) => {
const result = await context.createBlock(
createTransaction(context, {
to: PRECOMPILE_GMP_ADDRESS,
gas: 500_000,
gas: 600_000,
data,
})
);
Expand Down

0 comments on commit 82d38ce

Please sign in to comment.