Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions packages/swapper/src/okx/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,27 @@ import { Chain } from "@gemwallet/types";

export const CHAIN_INDEX: Record<string, string> = {
[Chain.Solana]: "501",
[Chain.Ethereum]: "1",
[Chain.SmartChain]: "56",
[Chain.Polygon]: "137",
[Chain.Arbitrum]: "42161",
[Chain.Optimism]: "10",
[Chain.Base]: "8453",
[Chain.AvalancheC]: "43114",
[Chain.OpBNB]: "204",
[Chain.Fantom]: "250",
[Chain.Gnosis]: "100",
[Chain.Manta]: "169",
[Chain.Blast]: "81457",
[Chain.ZkSync]: "324",
[Chain.Linea]: "59144",
[Chain.Mantle]: "5000",
[Chain.Celo]: "42220",
[Chain.Sonic]: "146",
[Chain.Abstract]: "2741",
[Chain.Berachain]: "80094",
[Chain.Unichain]: "130",
[Chain.Monad]: "143",
[Chain.XLayer]: "196",
};

Expand All @@ -31,13 +49,13 @@ export const SOLANA_CHAIN_INDEX = CHAIN_INDEX[Chain.Solana];
export const SOLANA_NATIVE_TOKEN_ADDRESS = "11111111111111111111111111111111";
export const SOLANA_DEX_IDS_PARAM = SOLANA_DEX_IDS.join(",");
export const DEFAULT_SLIPPAGE_PERCENT = "1";
export const DEFAULT_EVM_GAS_LIMIT = "920000";
const EVM_GAS_LIMITS: Partial<Record<string, string>> = {
[Chain.Base]: "800000",
[Chain.Manta]: "600000",
[Chain.ZkSync]: "2000000",
[Chain.Mantle]: "2000000000",
[Chain.XLayer]: "800000",
};

export function evmGasLimit(chain: Chain): string | undefined {
return EVM_GAS_LIMITS[chain];
export function evmGasLimit(chain: Chain): string {
return EVM_GAS_LIMITS[chain] ?? DEFAULT_EVM_GAS_LIMIT;
}
4 changes: 2 additions & 2 deletions packages/swapper/src/okx/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Chain, QuoteRequest } from "@gemwallet/types";

import { createOkxEvmQuoteRequest, createSolanaUsdcQuoteRequest } from "../testkit/mock";
import { OkxDexClient } from "./client";
import { CHAIN_INDEX } from "./constants";
import { CHAIN_INDEX, DEFAULT_EVM_GAS_LIMIT } from "./constants";
import { OkxProvider } from "./provider";

const OKX_ENV_KEYS = ["OKX_API_KEY", "OKX_SECRET_KEY", "OKX_API_PASSPHRASE", "OKX_PROJECT_ID"];
Expand Down Expand Up @@ -88,7 +88,7 @@ describe("OKX live integration", () => {

expect(quoteData.dataType).toBe("contract");
expect(quoteData.data).toMatch(/^0x/);
expect(quoteData.gasLimit).toBe("800000");
expect(quoteData.gasLimit).toBe(DEFAULT_EVM_GAS_LIMIT);
expect(quoteData.approval).toBeUndefined();
});
});
Expand Down
3 changes: 2 additions & 1 deletion packages/swapper/src/okx/provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
XLAYER_USD0_ADDRESS,
} from "../testkit/mock";
import type { OkxDexClient } from "./client";
import { DEFAULT_EVM_GAS_LIMIT } from "./constants";
import { OkxProvider } from "./provider";

const SOL_MINT = "11111111111111111111111111111111";
Expand Down Expand Up @@ -255,7 +256,7 @@ describe("OkxProvider", () => {

expect(result.data).toBe("0xswapCalldata");
expect(result.value).toBe("0");
expect(result.gasLimit).toBe("800000");
expect(result.gasLimit).toBe(DEFAULT_EVM_GAS_LIMIT);
expect(result.approval).toEqual({
token: XLAYER_USD0_ADDRESS,
spender: MOCK_APPROVE_ADDRESS,
Expand Down
Loading