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
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ APTOS_URL=https://fullnode.mainnet.aptoslabs.com/v1
MANTA_URL=https://pacific-rpc.manta.network/http
MANTLE_URL=https://rpc.mantle.xyz
XLAYER_URL=https://rpc.xlayer.tech
MAYAN_API_KEY=
PANORA_API_KEY=""
OKX_API_KEY=
OKX_SECRET_KEY=
Expand Down
3 changes: 3 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ updates:
schedule:
interval: "daily"
ignore:
- dependency-name: "*"
update-types:
- "version-update:semver-patch"
- dependency-name: "@mysten/sui"
update-types:
- "version-update:semver-major"
Expand Down
13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
"devDependencies": {
"@types/jest": "30.0.0",
"jest": "30.2.0",
"knip": "5.86.0",
"oxfmt": "0.37.0",
"oxlint": "1.52.0",
"knip": "5.87.0",
"oxfmt": "0.41.0",
"oxlint": "1.56.0",
"ts-jest": "29.4.5",
"typescript": "5.9.3"
},
Expand All @@ -38,7 +38,12 @@
"@types/jest": "30.0.0",
"jest": "30.2.0",
"ts-jest": "29.4.6",
"typescript": "5.9.3"
"typescript": "5.9.3",
"axios": "1.13.6",
"diff": "8.0.3",
"minimatch": "9.0.9",
"glob": "10.5.0",
"qs": "6.15.0"
}
}
}
8 changes: 3 additions & 5 deletions packages/swapper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@
},
"dependencies": {
"@cetusprotocol/aggregator-sdk": "1.4.5",
"@coral-xyz/anchor": "0.32.1",
"@gemwallet/types": "workspace:*",
"@mayanfinance/swap-sdk": "13.0.0",
"@mayanfinance/swap-sdk": "13.1.0",
"@mysten/sui": "1.45.2",
"@orca-so/whirlpools": "7.0.1",
"@orca-so/whirlpools-client": "6.2.1",
"@orca-so/whirlpools-client": "6.2.0",
"@orca-so/whirlpools-core": "3.1.0",
"@solana-program/token-2022": "0.6.1",
"@solana/instructions": "5.5.1",
Expand All @@ -34,7 +33,6 @@
"@ton/ton": "16.2.2",
"@types/bn.js": "5.2.0",
"bn.js": "5.2.3",
"bs58": "6.0.0",
"js-sha3": "0.9.3"
"bs58": "6.0.0"
}
}
11 changes: 9 additions & 2 deletions packages/swapper/src/chain/evm/allowance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import { Chain } from "@gemwallet/types";

import { evmRpcUrl, jsonRpcCall } from "./jsonrpc";

export async function getErc20Allowance(rpcUrl: string, token: string, owner: string, spender: string): Promise<bigint> {
export async function getErc20Allowance(
rpcUrl: string,
token: string,
owner: string,
spender: string,
): Promise<bigint> {
const ownerPadded = owner.slice(2).toLowerCase().padStart(64, "0");
const spenderPadded = spender.slice(2).toLowerCase().padStart(64, "0");
const data = `0xdd62ed3e${ownerPadded}${spenderPadded}`;
Expand Down Expand Up @@ -37,7 +42,9 @@ export async function checkEvmApproval(
if (allowance >= BigInt(fromValue)) {
return undefined;
}
} catch { /* fall through to return approval */ }
} catch {
/* fall through to return approval */
}
}
return { token: tokenId, spender, value: fromValue };
}
4 changes: 3 additions & 1 deletion packages/swapper/src/chain/solana/tx_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ export async function estimateComputeUnitLimit(
if (response.value.unitsConsumed && response.value.unitsConsumed > 0) {
return Math.ceil(response.value.unitsConsumed * COMPUTE_UNIT_MULTIPLIER);
}
} catch (error) { void error; }
} catch (error) {
void error;
}
return undefined;
}

Expand Down
3 changes: 3 additions & 0 deletions packages/swapper/src/mayan/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ import { buildSuiQuoteData } from "./sui";
export class MayanProvider implements Protocol {
private solanaRpc: string;
private suiRpc: string;
private apiKey: string | undefined;

constructor(solanaRpc: string, suiRpc: string) {
this.solanaRpc = solanaRpc;
this.suiRpc = suiRpc;
this.apiKey = process.env.MAYAN_API_KEY;
}

mapAssetToTokenId(asset: AssetId): string {
Expand Down Expand Up @@ -75,6 +77,7 @@ export class MayanProvider implements Protocol {
shuttle: false,
fastMctp: true,
onlyDirect: false,
apiKey: this.apiKey,
};

let quotes: MayanQuote[];
Expand Down
11 changes: 9 additions & 2 deletions packages/swapper/src/okx/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,15 @@ describe("OKX auth", () => {

describe("sign", () => {
it("produces stable HMAC-SHA256 signature", () => {
const sig = sign("2026-01-01T00:00:00.000Z", "GET", "/api/v6/dex/aggregator/quote?chainIndex=501", "test-secret");
expect(sig).toBe(sign("2026-01-01T00:00:00.000Z", "GET", "/api/v6/dex/aggregator/quote?chainIndex=501", "test-secret"));
const sig = sign(
"2026-01-01T00:00:00.000Z",
"GET",
"/api/v6/dex/aggregator/quote?chainIndex=501",
"test-secret",
);
expect(sig).toBe(
sign("2026-01-01T00:00:00.000Z", "GET", "/api/v6/dex/aggregator/quote?chainIndex=501", "test-secret"),
);
expect(typeof sig).toBe("string");
expect(sig.length).toBeGreaterThan(0);
});
Expand Down
4 changes: 3 additions & 1 deletion packages/swapper/src/okx/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ export function buildQueryString(params: object): string {
}

export function sign(timestamp: string, method: string, path: string, secretKey: string): string {
return createHmac("sha256", secretKey).update(timestamp + method + path).digest("base64");
return createHmac("sha256", secretKey)
.update(timestamp + method + path)
.digest("base64");
}

const HEADER_KEY = "OK-ACCESS-KEY";
Expand Down
2 changes: 1 addition & 1 deletion packages/swapper/src/okx/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class OkxDexClient {
throw new Error(`OKX API ${response.status}: ${text}`);
}

const json = await response.json() as T;
const json = (await response.json()) as T;
return json;
}
}
2 changes: 1 addition & 1 deletion packages/swapper/src/okx/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ require("dotenv").config({ path: "../../.env" });

import { Chain, QuoteRequest } from "@gemwallet/types";

import { createOkxEvmQuoteRequest, createSolanaUsdcQuoteRequest, XLAYER_USD0_ADDRESS } from "../testkit/mock";
import { createOkxEvmQuoteRequest, createSolanaUsdcQuoteRequest } from "../testkit/mock";
import { OkxDexClient } from "./client";
import { CHAIN_INDEX } from "./constants";
import { OkxProvider } from "./provider";
Expand Down
8 changes: 6 additions & 2 deletions packages/swapper/src/okx/provider.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { Chain, Quote } from "@gemwallet/types";

import { createOkxEvmQuoteRequest, createSolanaUsdcQuoteRequest, SOLANA_USDC_MINT, XLAYER_USD0_ADDRESS } from "../testkit/mock";
import {
createOkxEvmQuoteRequest,
createSolanaUsdcQuoteRequest,
SOLANA_USDC_MINT,
XLAYER_USD0_ADDRESS,
} from "../testkit/mock";
import type { OkxDexClient } from "./client";

import { OkxProvider } from "./provider";

const SOL_MINT = "11111111111111111111111111111111";
Expand Down
20 changes: 13 additions & 7 deletions packages/swapper/src/okx/provider.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { AssetId, Chain, Quote, QuoteRequest, SwapQuoteData, SwapQuoteDataType } from "@gemwallet/types";
import bs58 from "bs58";

import { OkxDexClient } from "./client";
import type { QuoteData, SwapParams, TransactionData } from "./models";

import { Connection, VersionedTransaction } from "@solana/web3.js";
import bs58 from "bs58";

import { BigIntMath } from "../bigint_math";
import { checkEvmApproval } from "../chain/evm/allowance";
Expand All @@ -13,6 +9,7 @@ import { estimateComputeUnitLimit as simulateComputeUnits } from "../chain/solan
import { SwapperException } from "../error";
import { Protocol } from "../protocol";
import { getReferrerAddresses, preferInputAsFeeToken } from "../referrer";
import { OkxDexClient } from "./client";
import {
CHAIN_INDEX,
DEFAULT_SLIPPAGE_PERCENT,
Expand All @@ -21,6 +18,7 @@ import {
SOLANA_NATIVE_TOKEN_ADDRESS,
evmGasLimit,
} from "./constants";
import type { QuoteData, SwapParams, TransactionData } from "./models";

function bpsToPercent(bps: number): string {
return (bps / 100).toString();
Expand Down Expand Up @@ -159,7 +157,9 @@ export class OkxProvider implements Protocol {
const tx = VersionedTransaction.deserialize(bytes);
const estimate = await simulateComputeUnits(this.connection, tx);
return estimate?.toString();
} catch (error) { void error; }
} catch (error) {
void error;
}
return undefined;
}

Expand Down Expand Up @@ -230,7 +230,13 @@ export class OkxProvider implements Protocol {
}

if (isEvmChain(chain)) {
return this.buildEvmQuoteData(swapData.tx, fromAsset, quote.quote.from_address, quote.quote.from_value, approveSpender);
return this.buildEvmQuoteData(
swapData.tx,
fromAsset,
quote.quote.from_address,
quote.quote.from_value,
approveSpender,
);
}

return this.buildSolanaQuoteData(swapData.tx);
Expand Down
2 changes: 1 addition & 1 deletion packages/swapper/src/orca/fee.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BN } from "@coral-xyz/anchor";
import { Quote } from "@gemwallet/types";
import BN from "bn.js";

import { buildOrcaQuoteFixture } from "../testkit/mock";
import { calculateReferralFeeAmount, bnToNumberSafe, BASIS_POINTS_DENOMINATOR, MAX_SAFE_NUMBER_BN } from "./fee";
Expand Down
2 changes: 1 addition & 1 deletion packages/swapper/src/orca/fee.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BN } from "@coral-xyz/anchor";
import { AssetId, Quote } from "@gemwallet/types";
import { TOKEN_PROGRAM_ID } from "@solana/spl-token";
import { PublicKey } from "@solana/web3.js";
import BN from "bn.js";

import { parsePublicKey } from "../chain/solana/account";

Expand Down
Loading
Loading