Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix l1 gas for scroll and blast #307

Merged
merged 14 commits into from
Mar 13, 2024
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.15.0] - 2024-MARCH-X

- Improved the accuracy of `estimateGasFee` function by incorporating L1 rollup fee for destination L2 chain.
- Fix for `manualRelayToDestinationChain` to respect optional `provider` parameter
- Add support for recovery of cosmos-to-cosmos GMP calls
- Fixed gas estimation for scroll and blast
- Fixed for `manualRelayToDestinationChain` to respect optional `provider` parameter
- Added support for recovery of cosmos-to-cosmos GMP calls

Breaking Changes:

Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@axelar-network/axelarjs-sdk",
"version": "0.15.0-alpha.1",
"version": "0.15.0-alpha.2",
"description": "The JavaScript SDK for Axelar Network",
"repository": {
"type": "git",
Expand Down Expand Up @@ -52,7 +52,6 @@
"bech32": "^2.0.0",
"clone-deep": "^4.0.1",
"cross-fetch": "^3.1.5",
"ethereum-multicall": "^2.21.0",
"ethers": "^5.7.2",
"socket.io-client": "^4.6.1",
"standard-http-error": "^2.0.1",
Expand Down
13 changes: 0 additions & 13 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions src/chains/supported-chains-list.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
export const CHAINS = {
TESTNET: {
ACRE: "acre",
ARBITRUM: "arbitrum",
ARBITRUM_SEPOLIA: "arbitrum-sepolia",
AURA: "aura",
AURORA: "aurora",
AXELAR: "Axelarnet",
AVALANCHE: "Avalanche",
BASE: "base",
BINANCE: "binance",
BNBCHAIN: "binance",
BURNT: "burnt-2",
CELESTIA: "celestia",
CELO: "celo",
CENTRIFUGE: "centrifuge-2",
COMDEX: "comdex-2",
ETHEREUM: "ethereum-2",
EVMOS: "evmos",
FANTOM: "Fantom",
FETCH: "fetch",
Expand All @@ -29,12 +26,10 @@ export const CHAINS = {
KAVA: "kava",
KUJIRA: "kujira",
LINEA: "linea",
MANTLE: "mantle",
MIGALOO: "migaloo",
MOONBEAM: "Moonbeam",
NEUTRON: "neutron",
ODIN: "odin",
OPTIMISM: "optimism",
OSMOSIS: "osmosis-7",
PERSISTENCE: "persistence",
POLYGON: "Polygon",
Expand Down
7 changes: 6 additions & 1 deletion src/libs/AxelarQueryAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ export class AxelarQueryAPI {
token_price: destination_native_token.token_price,
name: destination_native_token.name,
symbol: destination_native_token.symbol,
l1_gas_oracle_address: destination_native_token.l1_gas_oracle_address,
l1_gas_price_in_units: destination_native_token.l1_gas_price_in_units,
},
l2_type,
Expand Down Expand Up @@ -299,6 +300,8 @@ export class AxelarQueryAPI {
l1ExecutionFee = await this.estimateL1GasFee(destChainId, {
executeData: executeData || "0x",
l1GasPrice: destToken.l1_gas_price_in_units,
l1GasOracleAddress: destToken.l1_gas_oracle_address,
destChain: destChainId,
l2Type,
});

Expand All @@ -307,7 +310,9 @@ export class AxelarQueryAPI {
const ethTokenPrice = Number(ethereumToken.token_price.usd);
const ethToSrcTokenPriceRatio = ethTokenPrice / srcTokenPrice;

const actualL1ExecutionFee = Math.ceil(l1ExecutionFee.toNumber() * ethToSrcTokenPriceRatio);
const actualL1ExecutionFee = l1ExecutionFee
.mul(Math.ceil(ethToSrcTokenPriceRatio * 1000))
.div(1000);

l1ExecutionFee = BigNumber.from(actualL1ExecutionFee.toString());

Expand Down
26 changes: 0 additions & 26 deletions src/libs/TransactionRecoveryApi/constants/chain/testnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,13 @@ export const rpcMap: Record<EvmChain | string, string> = {
[EvmChain.POLYGON]: "https://rpc-mumbai.maticvigil.com",
[EvmChain.MOONBEAM]: "https://rpc.api.moonbase.moonbeam.network",
[EvmChain.AVALANCHE]: "https://api.avax-test.network/ext/bc/C/rpc",
"ethereum-2": "https://ethereum-goerli-rpc.publicnode.com",
[EvmChain.AURORA]: "https://testnet.aurora.dev",
[EvmChain.BINANCE]: "https://data-seed-prebsc-1-s1.binance.org:8545",
[EvmChain.BNBCHAIN]: "https://data-seed-prebsc-1-s1.binance.org:8545",
[EvmChain.ARBITRUM]: "https://goerli-rollup.arbitrum.io/rpc",
[EvmChain.CELO]: "https://alfajores-forno.celo-testnet.org",
[EvmChain.KAVA]: "https://evm.testnet.kava.io",
[EvmChain.BASE]: "https://goerli.base.org",
"filecoin-2": "https://rpc.ankr.com/filecoin_testnet",
[EvmChain.OPTIMISM]: "https://goerli.optimism.io",
[EvmChain.LINEA]: "https://rpc.goerli.linea.build",
[EvmChain.POLYGON_ZKEVM]: "https://testnet-zkevm.polygonscan.com",
[EvmChain.MANTLE]: "https://rpc.testnet.mantle.xyz",
[EvmChain.SCROLL]: "https://sepolia-rpc.scroll.io",
[EvmChain.IMMUTABLE]: "https://rpc.testnet.immutable.com",
[EvmChain.SEPOLIA]: "https://1rpc.io/sepolia",
Expand Down Expand Up @@ -53,10 +47,6 @@ export const networkInfo: Record<EvmChain | string, Network> = {
chainId: 43113,
name: EvmChain.AVALANCHE,
},
"ethereum-2": {
chainId: 5,
name: EvmChain.ETHEREUM,
},
[EvmChain.AURORA]: {
chainId: 1313161555,
name: EvmChain.AURORA,
Expand All @@ -69,10 +59,6 @@ export const networkInfo: Record<EvmChain | string, Network> = {
chainId: 97,
name: EvmChain.BNBCHAIN,
},
[EvmChain.ARBITRUM]: {
chainId: 421613,
name: `${EvmChain.ARBITRUM}-goerli`,
},
[EvmChain.CELO]: {
chainId: 44787,
name: EvmChain.CELO,
Expand All @@ -81,26 +67,14 @@ export const networkInfo: Record<EvmChain | string, Network> = {
chainId: 2221,
name: EvmChain.KAVA,
},
[EvmChain.BASE]: {
chainId: 84_531,
name: EvmChain.BASE,
},
"filecoin-2": {
chainId: 314159,
name: EvmChain.FILECOIN,
},
[EvmChain.OPTIMISM]: {
chainId: 420,
name: `${EvmChain.OPTIMISM}-goerli`,
},
[EvmChain.LINEA]: {
chainId: 59140,
name: EvmChain.LINEA,
},
[EvmChain.MANTLE]: {
chainId: 5001,
name: EvmChain.MANTLE,
},
[EvmChain.SCROLL]: {
chainId: 534351,
name: EvmChain.SCROLL,
Expand Down
54 changes: 28 additions & 26 deletions src/libs/fee/getL1Fee.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,43 @@
import { getL1FeeForL2 } from "./getL1Fee";
import { AxelarQueryAPI } from "../AxelarQueryAPI";

const MOCK_EXECUTE_DATA =
const MOCK_EXECUTE_DATA: `0x${string}` =
"0x1a98b2e0e68ba0eb84262d4bcf91955ec2680b37bcedd59a1f48e18d183dac9961bf9d1400000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001600000000000000000000000000000000000000000000000000000000000000d40000000000000000000000000000000000000000000000000000000000deac2c6000000000000000000000000000000000000000000000000000000000000000762696e616e636500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002a307863653136463639333735353230616230313337376365374238386635424138433438463844363636000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000bc000000000000000000000000000000000000000000000000000000000000000400000000000000000000000004607cad6135d7a119185ebe062d3b369b1b536ef000000000000000000000000000000000000000000000000000000000000000700000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000001e000000000000000000000000000000000000000000000000000000000000003600000000000000000000000000000000000000000000000000000000000000580000000000000000000000000000000000000000000000000000000000000070000000000000000000000000000000000000000000000000000000000000009200000000000000000000000000000000000000000000000000000000000000a8000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000eb466342c4d449bc9f53a865d5cb90586f4052150000000000000000000000000000000000000000000000000000000000000001000000000000000000000000eb466342c4d449bc9f53a865d5cb90586f405215000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000044095ea7b300000000000000000000000068b3465833fb72a70ecdf485e0e4c7bd8665fc450000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000eb466342c4d449bc9f53a865d5cb90586f4052150000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000100000000000000000000000068b3465833fb72a70ecdf485e0e4c7bd8665fc45000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000000e404e45aaf000000000000000000000000eb466342c4d449bc9f53a865d5cb90586f405215000000000000000000000000ff970a61a04b1ca14834a43f5de4533ebddb5cc800000000000000000000000000000000000000000000000000000000000000640000000000000000000000004fd39c9e151e50580779bd04b1f7ecc310079fd3000000000000000000000000000000000000000000000000000000000deac2c6000000000000000000000000000000000000000000000000000000000dc647500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000eb466342c4d449bc9f53a865d5cb90586f40521500000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001000000000000000000000000ff970a61a04b1ca14834a43f5de4533ebddb5cc8000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000044095ea7b300000000000000000000000068b3465833fb72a70ecdf485e0e4c7bd8665fc450000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000ff970a61a04b1ca14834a43f5de4533ebddb5cc80000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000100000000000000000000000068b3465833fb72a70ecdf485e0e4c7bd8665fc45000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000000e404e45aaf000000000000000000000000ff970a61a04b1ca14834a43f5de4533ebddb5cc800000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab100000000000000000000000000000000000000000000000000000000000000640000000000000000000000004fd39c9e151e50580779bd04b1f7ecc310079fd3000000000000000000000000000000000000000000000000000000000de83dbf000000000000000000000000000000000000000000000000015d8c7908dbe7130000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000ff970a61a04b1ca14834a43f5de4533ebddb5cc80000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000100000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000242e1a7d4d000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000004607cad6135d7a119185ebe062d3b369b1b536ef000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000761786c5553444300000000000000000000000000000000000000000000000000";
const env = Environment.MAINNET;

describe("getL1Fee", () => {
const env = Environment.MAINNET;
async function getL1Fee(srcChain: string, destChain: string) {
const queryAPI = new AxelarQueryAPI({ environment: env });

const { destToken, l2_type } = await queryAPI.getNativeGasBaseFee(srcChain, destChain);

const params: EstimateL1FeeParams = {
executeData: MOCK_EXECUTE_DATA,
destChain,
l1GasPrice: destToken.l1_gas_price_in_units!,

Check warning on line 19 in src/libs/fee/getL1Fee.spec.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/libs/fee/getL1Fee.spec.ts#L19

Forbidden non-null assertion (@typescript-eslint/no-non-null-assertion)
l2Type: l2_type,
};

const provider = new ethers.providers.JsonRpcProvider(rpcMap[destChain]);
const fee = await getL1FeeForL2(provider, params);

return fee;
}

describe("getL1Fee", () => {
it("query optimism l1 fee should work", async () => {
const srcChain = "avalanche";
const destChain = "optimism";

const queryAPI = new AxelarQueryAPI({ environment: env });

const { destToken, l2_type } = await queryAPI.getNativeGasBaseFee(srcChain, destChain);
const fee = await getL1Fee(srcChain, destChain);

const provider = new ethers.providers.JsonRpcProvider(rpcMap[destChain]);
expect(fee).toBeDefined();
});

const params: EstimateL1FeeParams = {
executeData: MOCK_EXECUTE_DATA,
l1GasPrice: destToken.l1_gas_price_in_units!,
l2Type: l2_type,
};
it("query blast l1 fee should work", async () => {
const srcChain = "avalanche";
const destChain = "blast";

const fee = await getL1FeeForL2(provider, params);
const fee = await getL1Fee(srcChain, destChain);

expect(fee).toBeDefined();
});
Expand All @@ -35,19 +49,7 @@
const srcChain = "avalanche";
const destChain = "mantle";

const queryAPI = new AxelarQueryAPI({ environment: env });

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, params);
const fee = await getL1Fee(srcChain, destChain);

expect(fee).toBeDefined();
});
Expand Down
Loading
Loading