Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 10 additions & 0 deletions packages/swapper/src/okx/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
import { Chain } from "@gemwallet/types";

export const EVM_CHAIN_INDEX: Record<string, string> = {
[Chain.Manta]: "169",
[Chain.Mantle]: "5000",
[Chain.XLayer]: "196",
};

export const EVM_NATIVE_TOKEN_ADDRESS = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";

const SOLANA_DEX_IDS = [
"277", // Raydium
"278", // Raydium CL
Expand Down
87 changes: 71 additions & 16 deletions packages/swapper/src/okx/integration.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { QuoteRequest } from "@gemwallet/types";
import { Chain, QuoteRequest } from "@gemwallet/types";

import { createSolanaUsdcQuoteRequest } from "../testkit/mock";
import { createOkxEvmQuoteRequest, createSolanaUsdcQuoteRequest, MANTA_USDC_ADDRESS } from "../testkit/mock";
import { OkxProvider } from "./provider";

const OKX_ENV_KEYS = ["OKX_API_KEY", "OKX_SECRET_KEY", "OKX_API_PASSPHRASE", "OKX_PROJECT_ID"];
Expand All @@ -13,27 +13,82 @@ const hasAuth = hasAuthEnv();
const runIntegration = process.env.OKX_INTEGRATION_TEST === "1" && hasAuth;
const itIntegration = runIntegration ? it : it.skip;

const REQUEST_TEMPLATE: QuoteRequest = createSolanaUsdcQuoteRequest();
const SOLANA_REQUEST: QuoteRequest = createSolanaUsdcQuoteRequest();

const MANTA_NATIVE_TO_USDC_REQUEST: QuoteRequest = createOkxEvmQuoteRequest({
from_value: "10000000000000000",
});

const MANTA_USDC_TO_NATIVE_REQUEST: QuoteRequest = createOkxEvmQuoteRequest({
from_asset: {
id: `${Chain.Manta}_${MANTA_USDC_ADDRESS}`,
symbol: "USDC",
decimals: 6,
},
to_asset: {
id: Chain.Manta,
symbol: "ETH",
decimals: 18,
},
from_value: "1000000",
});

describe("OKX live integration", () => {
jest.setTimeout(60_000);

itIntegration("fetches a live quote and builds quote data", async () => {
const provider = new OkxProvider(process.env.SOLANA_URL || "https://solana-rpc.publicnode.com");
const quote = await provider.get_quote(REQUEST_TEMPLATE);
describe("Solana", () => {
itIntegration("fetches a live quote and builds quote data", async () => {
const provider = new OkxProvider(process.env.SOLANA_URL || "https://solana-rpc.publicnode.com");
const quote = await provider.get_quote(SOLANA_REQUEST);

expect(BigInt(quote.output_value) > BigInt(0)).toBe(true);
expect(quote.route_data).toBeDefined();

const quoteData = await provider.get_quote_data(quote);

expect(quoteData.dataType).toBe("contract");
expect(typeof quoteData.data).toBe("string");
expect(quoteData.data.length).toBeGreaterThan(0);
expect(typeof quoteData.to).toBe("string");
expect(quoteData.to.length).toBeGreaterThan(0);

const serialized = Buffer.from(quoteData.data, "base64");
expect(serialized.length).toBeGreaterThan(0);
});
});

describe("EVM (Manta)", () => {
itIntegration("fetches a live quote for native to token swap", async () => {
const provider = new OkxProvider(process.env.SOLANA_URL || "https://solana-rpc.publicnode.com");
const quote = await provider.get_quote(MANTA_NATIVE_TO_USDC_REQUEST);

expect(BigInt(quote.output_value) > BigInt(0)).toBe(true);
expect(quote.route_data).toBeDefined();
});

expect(BigInt(quote.output_value) > BigInt(0)).toBe(true);
expect(quote.route_data).toBeDefined();
itIntegration("builds quote data for native to token swap", async () => {
const provider = new OkxProvider(process.env.SOLANA_URL || "https://solana-rpc.publicnode.com");
const quote = await provider.get_quote(MANTA_NATIVE_TO_USDC_REQUEST);
const quoteData = await provider.get_quote_data(quote);

const quoteData = await provider.get_quote_data(quote);
expect(quoteData.dataType).toBe("contract");
expect(quoteData.data).toMatch(/^0x/);
expect(quoteData.to).toMatch(/^0x/);
expect(quoteData.value).toBeDefined();
expect(quoteData.approval).toBeUndefined();
});

expect(quoteData.dataType).toBe("contract");
expect(typeof quoteData.data).toBe("string");
expect(quoteData.data.length).toBeGreaterThan(0);
expect(typeof quoteData.to).toBe("string");
expect(quoteData.to.length).toBeGreaterThan(0);
itIntegration("builds quote data with approval for token to native swap", async () => {
const provider = new OkxProvider(process.env.SOLANA_URL || "https://solana-rpc.publicnode.com");
const quote = await provider.get_quote(MANTA_USDC_TO_NATIVE_REQUEST);
const quoteData = await provider.get_quote_data(quote);

const serialized = Buffer.from(quoteData.data, "base64");
expect(serialized.length).toBeGreaterThan(0);
expect(quoteData.dataType).toBe("contract");
expect(quoteData.data).toMatch(/^0x/);
expect(quoteData.approval).toBeDefined();
expect(quoteData.approval!.token).toBe(MANTA_USDC_ADDRESS);
expect(quoteData.approval!.spender).toMatch(/^0x/);
expect(quoteData.approval!.value).toBe("1000000");
});
});
});
Loading
Loading