@audren-xyz/sdk 1.3.4 → 1.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/aggregators.js +58 -37
- package/package.json +1 -1
package/dist/aggregators.js
CHANGED
|
@@ -429,12 +429,14 @@ export function createDFlowSwapAdapter(config = {}) {
|
|
|
429
429
|
}
|
|
430
430
|
const base = resolveBase();
|
|
431
431
|
const t0 = Date.now();
|
|
432
|
+
const excluded = req.excludeDexes ?? JUPITER_CPI_EXCLUDED_DEXES;
|
|
432
433
|
const qs = new URLSearchParams({
|
|
433
434
|
inputMint: req.inputMint,
|
|
434
435
|
outputMint: req.outputMint,
|
|
435
436
|
amount: req.amount,
|
|
436
437
|
slippageBps: String(req.slippageBps),
|
|
437
438
|
transactionVersion: 'v1',
|
|
439
|
+
...(excluded.length > 0 ? { excludeDexes: excluded.join(',') } : {}),
|
|
438
440
|
...(req.onlyDirectRoutes ? { onlyDirectRoutes: 'true' } : {}),
|
|
439
441
|
...(req.platformFeeBps && req.platformFeeBps > 0
|
|
440
442
|
? { platformFeeBps: String(req.platformFeeBps) }
|
|
@@ -588,44 +590,63 @@ export function createOkxSwapAdapter(config = {}) {
|
|
|
588
590
|
}
|
|
589
591
|
const base = resolveBase();
|
|
590
592
|
const t0 = Date.now();
|
|
591
|
-
const
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
const
|
|
622
|
-
|
|
593
|
+
const escrowPubkey = req.escrowPubkey;
|
|
594
|
+
const fetchOkxCandidate = async (directRoute) => {
|
|
595
|
+
const qs = new URLSearchParams({
|
|
596
|
+
chainIndex: OKX_CHAIN_INDEX,
|
|
597
|
+
amount: req.amount,
|
|
598
|
+
fromTokenAddress: req.inputMint,
|
|
599
|
+
toTokenAddress: req.outputMint,
|
|
600
|
+
slippagePercent: (req.slippageBps / 100).toString(),
|
|
601
|
+
userWalletAddress: escrowPubkey,
|
|
602
|
+
swapMode: 'exactIn',
|
|
603
|
+
...(directRoute ? { directRoute: 'true' } : {}),
|
|
604
|
+
...(req.platformFeeBps && req.platformFeeBps > 0 && req.feeOwnerWallet
|
|
605
|
+
? {
|
|
606
|
+
feePercent: (req.platformFeeBps / 100).toFixed(4).replace(/\.?0+$/, ''),
|
|
607
|
+
toTokenReferrerWalletAddress: req.feeOwnerWallet,
|
|
608
|
+
}
|
|
609
|
+
: {}),
|
|
610
|
+
});
|
|
611
|
+
const queryString = `?${qs.toString()}`;
|
|
612
|
+
const headers = await signHeaders('GET', OKX_SWAP_IX_PATH, queryString);
|
|
613
|
+
const res = await safeAggregatorFetch(fetchImpl, `${base}${OKX_SWAP_IX_PATH}${queryString}`, {
|
|
614
|
+
headers,
|
|
615
|
+
signal: buildFetchSignal(req.signal, req.timeoutMs ?? 10_000),
|
|
616
|
+
}, 'OKX');
|
|
617
|
+
if (!res.ok)
|
|
618
|
+
throw new Error(`OKX swap-instruction HTTP ${res.status}`);
|
|
619
|
+
const bodyRaw = await res.json();
|
|
620
|
+
if (!isPlainObject(bodyRaw))
|
|
621
|
+
throw new Error('OKX returned non-object response JSON');
|
|
622
|
+
const body = bodyRaw;
|
|
623
|
+
const entry = Array.isArray(body.data) ? body.data[0] : body.data;
|
|
624
|
+
const outBi = parsePositiveUintString(entry?.routerResult?.toTokenAmount);
|
|
625
|
+
if (body.code !== '0' || !entry?.routerResult || outBi === null) {
|
|
626
|
+
const safeCode = typeof body.code === 'string' && body.code.trim() ? body.code.trim().slice(0, 16) : 'unknown';
|
|
627
|
+
throw new Error(`OKX API returned no valid route (code ${safeCode})`);
|
|
628
|
+
}
|
|
629
|
+
const prebuiltIxs = Array.isArray(entry.instructionLists)
|
|
630
|
+
? entry.instructionLists.filter(isValidRouterInstruction)
|
|
631
|
+
: [];
|
|
632
|
+
const swapIx = validatePrebuiltEscrowInstructionBounds(prebuiltIxs, escrowPubkey, 'OKX');
|
|
633
|
+
return { entry, rr: entry.routerResult, outBi, swapIx };
|
|
634
|
+
};
|
|
635
|
+
let candidate;
|
|
636
|
+
try {
|
|
637
|
+
candidate = await fetchOkxCandidate(Boolean(req.onlyDirectRoutes));
|
|
623
638
|
}
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
639
|
+
catch (err) {
|
|
640
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
641
|
+
const isBoundsRejection = /exceeds ExecViaEscrow max|exceeds Solana Tx v1|non-wrapper swap instruction/i.test(msg);
|
|
642
|
+
if (!req.onlyDirectRoutes && isBoundsRejection && !req.signal?.aborted) {
|
|
643
|
+
candidate = await fetchOkxCandidate(true);
|
|
644
|
+
}
|
|
645
|
+
else {
|
|
646
|
+
throw err;
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
const { entry, rr, outBi, swapIx } = candidate;
|
|
629
650
|
const outAmount = outBi.toString();
|
|
630
651
|
const minOut = ((outBi * BigInt(10_000 - req.slippageBps)) / 10000n).toString();
|
|
631
652
|
const routePlan = [];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@audren-xyz/sdk",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"description": "TypeScript SDK for Audren — zero-indexer BN254 Groth16 global MASP core (PDAs, Poseidon, layouts, CompactWalletStore, gateway/relayer client, tx v1) plus WASM Groth16 prover (@audren-xyz/sdk/prover) and IDLs (@audren-xyz/sdk/idl)",
|