Skip to content

Commit

Permalink
fix: Tune gas limit for popular tokens (#1636)
Browse files Browse the repository at this point in the history
  • Loading branch information
wcgcyx authored Mar 28, 2024
1 parent cfa0103 commit 600efa6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
24 changes: 22 additions & 2 deletions packages/internal/bridge/sdk/src/tokenBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,17 @@ export class TokenBridge {
const imtblFee: ethers.BigNumber = ethers.BigNumber.from(0);

if ('token' in req && req.token !== 'NATIVE') {
let approvalLimit = BridgeMethodsGasLimit.APPROVE_TOKEN;
if (req.token === 'USDC') {
approvalLimit = BridgeMethodsGasLimit.APPROVE_TOKEN_USDC;
} else if (req.token === 'GOG') {
approvalLimit = BridgeMethodsGasLimit.APPROVE_TOKEN_GOG;
} else if (req.token === 'IMX') {
approvalLimit = BridgeMethodsGasLimit.APPROVE_TOKEN_IMX;
}
approvalFee = await this.getGasEstimates(
this.config.rootProvider,
BridgeMethodsGasLimit.APPROVE_TOKEN,
approvalLimit,
);
}

Expand All @@ -162,9 +170,21 @@ export class TokenBridge {
const sourceProvider:ethers.providers.Provider = (req.action === BridgeFeeActions.WITHDRAW)
? this.config.childProvider : this.config.rootProvider;

let sourceLimit = BridgeMethodsGasLimit[`${req.action}_SOURCE`];
if ('token' in req && req.action === 'DEPOSIT') {
if (req.token === 'NATIVE') {
sourceLimit = BridgeMethodsGasLimit.DEPOSIT_SOURCE_ETH;
} else if (req.token === 'USDC') {
sourceLimit = BridgeMethodsGasLimit.DEPOSIT_SOURCE_USDC;
} else if (req.token === 'GOG') {
sourceLimit = BridgeMethodsGasLimit.DEPOSIT_SOURCE_GOG;
} else if (req.token === 'IMX') {
sourceLimit = BridgeMethodsGasLimit.DEPOSIT_SOURCE_IMX;
}
}
sourceChainGas = await this.getGasEstimates(
sourceProvider,
BridgeMethodsGasLimit[`${req.action}_SOURCE`],
sourceLimit,
);

const feeResult = await this.calculateBridgeFee(
Expand Down
9 changes: 9 additions & 0 deletions packages/internal/bridge/sdk/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,15 @@ export enum BridgeMethodsGasLimit { // @TODO test methods on chain and put corre
MAP_TOKEN_DESTINATION = 200000,
FINALISE_WITHDRAWAL = 200000,
APPROVE_TOKEN = 55000,

DEPOSIT_SOURCE_ETH = 125000,
DEPOSIT_SOURCE_USDC = 158000,
DEPOSIT_SOURCE_GOG = 142000,
DEPOSIT_SOURCE_IMX = 148000,

APPROVE_TOKEN_USDC = 55600,
APPROVE_TOKEN_GOG = 46300,
APPROVE_TOKEN_IMX = 47000,
}

export interface FeeData {
Expand Down

0 comments on commit 600efa6

Please sign in to comment.