diff --git a/src/libs/AxelarQueryAPI.ts b/src/libs/AxelarQueryAPI.ts index 46ad7cf2..8717fa81 100644 --- a/src/libs/AxelarQueryAPI.ts +++ b/src/libs/AxelarQueryAPI.ts @@ -230,6 +230,7 @@ export class AxelarQueryAPI { destination_native_token, express_fee_string, express_supported, + l2_type, } = response.result; const execute_gas_multiplier = response.result.execute_gas_multiplier as number; const { decimals: sourceTokenDecimals } = source_token; @@ -251,6 +252,7 @@ export class AxelarQueryAPI { symbol: destination_native_token.symbol, l1_gas_price_in_units: destination_native_token.l1_gas_price_in_units, }, + l2_type, ethereumToken: ethereum_token as BaseFeeResponse["ethereumToken"], apiResponse: response, success: true, @@ -270,7 +272,7 @@ export class AxelarQueryAPI { const provider = new ethers.providers.JsonRpcProvider(rpcMap[destChainId]); - return getL1FeeForL2(provider, destChainId, l1FeeParams); + return getL1FeeForL2(provider, l1FeeParams); } public async calculateL1FeeForDestL2( @@ -279,7 +281,8 @@ export class AxelarQueryAPI { executeData: `0x${string}` | undefined, sourceToken: FeeToken, ethereumToken: BaseFeeResponse["ethereumToken"], - actualGasMultiplier: number + actualGasMultiplier: number, + l2Type: BaseFeeResponse["l2_type"] ): Promise<[BigNumber, BigNumber]> { let l1ExecutionFee = BigNumber.from(0); let l1ExecutionFeeWithMultiplier = BigNumber.from(0); @@ -296,6 +299,7 @@ export class AxelarQueryAPI { l1ExecutionFee = await this.estimateL1GasFee(destChainId, { executeData: executeData || "0x", l1GasPrice: destToken.l1_gas_price_in_units, + l2Type, }); // Convert the L1 execution fee to the source token @@ -353,6 +357,7 @@ export class AxelarQueryAPI { executeGasMultiplier, destToken, apiResponse, + l2_type, success, expressSupported, } = await this.getNativeGasBaseFee( @@ -400,7 +405,8 @@ export class AxelarQueryAPI { executeData, sourceToken, ethereumToken, - actualGasMultiplier + actualGasMultiplier, + l2_type ); return gmpParams?.showDetailedFees diff --git a/src/libs/fee/getL1Fee.spec.ts b/src/libs/fee/getL1Fee.spec.ts index a6605403..42c146ba 100644 --- a/src/libs/fee/getL1Fee.spec.ts +++ b/src/libs/fee/getL1Fee.spec.ts @@ -16,16 +16,17 @@ describe("getL1Fee", () => { const queryAPI = new AxelarQueryAPI({ environment: env }); - const { destToken } = await queryAPI.getNativeGasBaseFee(srcChain, destChain); + const { destToken, l2_type } = await queryAPI.getNativeGasBaseFee(srcChain, destChain); const provider = new ethers.providers.JsonRpcProvider(rpcMap[destChain]); const params: EstimateL1FeeParams = { executeData: MOCK_EXECUTE_DATA, l1GasPrice: destToken.l1_gas_price_in_units!, + l2Type: l2_type, }; - const fee = await getL1FeeForL2(provider, destChain, params); + const fee = await getL1FeeForL2(provider, params); expect(fee).toBeDefined(); }); @@ -36,16 +37,17 @@ describe("getL1Fee", () => { const queryAPI = new AxelarQueryAPI({ environment: env }); - const { destToken } = await queryAPI.getNativeGasBaseFee(srcChain, destChain); + const { destToken, l2_type } = await queryAPI.getNativeGasBaseFee(srcChain, destChain); const provider = new ethers.providers.JsonRpcProvider(rpcMap[destChain]); const params: EstimateL1FeeParams = { executeData: MOCK_EXECUTE_DATA, l1GasPrice: destToken.l1_gas_price_in_units!, + l2Type: l2_type, }; - const fee = await getL1FeeForL2(provider, destChain, params); + const fee = await getL1FeeForL2(provider, params); expect(fee).toBeDefined(); }); diff --git a/src/libs/fee/getL1Fee.ts b/src/libs/fee/getL1Fee.ts index 2e1ede25..f65a05f8 100644 --- a/src/libs/fee/getL1Fee.ts +++ b/src/libs/fee/getL1Fee.ts @@ -22,21 +22,17 @@ const ABI = { */ export function getL1FeeForL2( provider: ethers.providers.JsonRpcProvider, - chain: string, params: EstimateL1FeeParams ): Promise { const multicall = new Multicall({ ethersProvider: provider, tryAggregate: true }); - switch (chain) { + switch (params.l2Type) { case "mantle": return getMantleL1Fee(multicall, params); - case "optimism": - case "scroll": - case "base": + case "op": return getOptimismL1Fee(multicall, params); // Most of the ethereum clients are already included L1 fee in the gas estimation for Arbitrum. - case "arbitrum": - case "arbitrum-sepolia": + case "arb": default: return Promise.resolve(BigNumber.from(0)); } diff --git a/src/libs/test/AxelarQueryAPI.spec.ts b/src/libs/test/AxelarQueryAPI.spec.ts index 573ff44b..43802880 100644 --- a/src/libs/test/AxelarQueryAPI.spec.ts +++ b/src/libs/test/AxelarQueryAPI.spec.ts @@ -107,6 +107,7 @@ describe("AxelarQueryAPI", () => { decimals: 18, value: "32534506865", }, + l2Type: "op", }); expect(gasAmount.gt(parseEther("0.00001"))).toBeTruthy(); }); @@ -128,7 +129,7 @@ describe("AxelarQueryAPI", () => { expect(ethers.utils.parseEther("10000").gt(gasAmount as BigNumberish)).toBeTruthy(); }); - test("It should include L1 fee for L2 destination chain", async () => { + test.only("It should include L1 fee for L2 destination chain", async () => { const mainnetApi = new AxelarQueryAPI({ environment: Environment.MAINNET }); const gasAmount = await mainnetApi.estimateGasFee( EvmChain.ETHEREUM, diff --git a/src/libs/types/index.ts b/src/libs/types/index.ts index b4d07ec0..c0962cae 100644 --- a/src/libs/types/index.ts +++ b/src/libs/types/index.ts @@ -85,6 +85,7 @@ export interface BaseFeeResponse { executeGasMultiplier: number; sourceToken: FeeToken; destToken: FeeToken; + l2_type: "op" | "arb" | "mantle" | undefined; ethereumToken: { name: string; symbol: string; @@ -245,4 +246,5 @@ export type TokenUnit = { export type EstimateL1FeeParams = { executeData: `0x${string}`; l1GasPrice: TokenUnit; + l2Type?: "op" | "arb" | "mantle" | undefined; };