@audren-xyz/sdk 1.3.5 → 1.3.6
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.d.ts +4 -0
- package/dist/aggregators.js +57 -18
- package/dist/swap.js +2 -0
- package/package.json +1 -1
package/dist/aggregators.d.ts
CHANGED
|
@@ -127,6 +127,10 @@ export interface AudrenSwapQuoteRequest extends SwapAdapterQuoteRequest {
|
|
|
127
127
|
poolId?: number;
|
|
128
128
|
shardId?: number;
|
|
129
129
|
programId?: string;
|
|
130
|
+
/** Optional per-request router allowlist override (checked for prebuilt adapters like OKX/Titan). */
|
|
131
|
+
allowedRouterPrograms?: readonly string[];
|
|
132
|
+
/** Optional per-request opt-out of prebuilt router allowlist checks. */
|
|
133
|
+
allowUnverifiedRouter?: boolean;
|
|
130
134
|
}
|
|
131
135
|
export interface AudrenSwapQuoteResult {
|
|
132
136
|
winner: NormalizedSwapQuote;
|
package/dist/aggregators.js
CHANGED
|
@@ -177,21 +177,35 @@ function isValidRouterInstruction(v) {
|
|
|
177
177
|
typeof a.isSigner === 'boolean' &&
|
|
178
178
|
typeof a.isWritable === 'boolean');
|
|
179
179
|
}
|
|
180
|
+
class PrebuiltRouteBoundsError extends Error {
|
|
181
|
+
constructor(message) {
|
|
182
|
+
super(message);
|
|
183
|
+
this.name = 'PrebuiltRouteBoundsError';
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
async function cancelBodyQuietly(res) {
|
|
187
|
+
try {
|
|
188
|
+
await res.body?.cancel?.();
|
|
189
|
+
}
|
|
190
|
+
catch {
|
|
191
|
+
// ignore already-locked or closed stream
|
|
192
|
+
}
|
|
193
|
+
}
|
|
180
194
|
function validatePrebuiltEscrowInstructionBounds(ixs, escrowPubkey, providerLabel) {
|
|
181
195
|
const nonWrapper = ixs.filter((ix) => !WRAPPER_PROGRAMS.has(ix.programId));
|
|
182
196
|
if (nonWrapper.length !== 1) {
|
|
183
|
-
throw new
|
|
197
|
+
throw new PrebuiltRouteBoundsError(`${providerLabel} route must expose exactly 1 non-wrapper swap instruction (got ${nonWrapper.length})`);
|
|
184
198
|
}
|
|
185
199
|
const swapIx = nonWrapper[0];
|
|
186
200
|
if (!swapIx.accounts.some((a) => a.pubkey === escrowPubkey)) {
|
|
187
201
|
throw new Error(`${providerLabel} did not include an escrow-signed swap instruction`);
|
|
188
202
|
}
|
|
189
203
|
if (swapIx.accounts.length > MAX_EXEC_ROUTER_CPI_ACCOUNTS) {
|
|
190
|
-
throw new
|
|
204
|
+
throw new PrebuiltRouteBoundsError(`${providerLabel} route requires ${swapIx.accounts.length} router accounts (exceeds ExecViaEscrow max ${MAX_EXEC_ROUTER_CPI_ACCOUNTS})`);
|
|
191
205
|
}
|
|
192
206
|
const uniquePubkeys = new Set(swapIx.accounts.map((a) => a.pubkey)).size;
|
|
193
207
|
if (uniquePubkeys > MAX_TX_V1_UNIQUE_ROUTER_ACCOUNTS) {
|
|
194
|
-
throw new
|
|
208
|
+
throw new PrebuiltRouteBoundsError(`${providerLabel} route requires ${uniquePubkeys} unique router accounts (exceeds Tx v1 safe budget ${MAX_TX_V1_UNIQUE_ROUTER_ACCOUNTS})`);
|
|
195
209
|
}
|
|
196
210
|
return swapIx;
|
|
197
211
|
}
|
|
@@ -357,6 +371,9 @@ export function createJupiterSwapAdapter(config = {}) {
|
|
|
357
371
|
};
|
|
358
372
|
},
|
|
359
373
|
async swapInstructions(req) {
|
|
374
|
+
if (!this.isConfigured()) {
|
|
375
|
+
throw new Error('Jupiter adapter not configured (set apiKey or apiUrl)');
|
|
376
|
+
}
|
|
360
377
|
const body = {
|
|
361
378
|
quoteResponse: req.quoteResponse,
|
|
362
379
|
userPublicKey: req.escrowPubkey,
|
|
@@ -373,8 +390,10 @@ export function createJupiterSwapAdapter(config = {}) {
|
|
|
373
390
|
signal: req.signal,
|
|
374
391
|
timeoutMs: req.timeoutMs,
|
|
375
392
|
});
|
|
376
|
-
if (!res.ok)
|
|
393
|
+
if (!res.ok) {
|
|
394
|
+
await cancelBodyQuietly(res);
|
|
377
395
|
throw new Error(`Jupiter swap-instructions HTTP ${res.status}`);
|
|
396
|
+
}
|
|
378
397
|
const payloadRaw = await res.json();
|
|
379
398
|
if (!isPlainObject(payloadRaw))
|
|
380
399
|
throw new Error('Jupiter returned non-object swap-instructions JSON');
|
|
@@ -446,8 +465,10 @@ export function createDFlowSwapAdapter(config = {}) {
|
|
|
446
465
|
headers: makeHeaders(),
|
|
447
466
|
signal: buildFetchSignal(req.signal, req.timeoutMs ?? 10_000),
|
|
448
467
|
}, 'DFlow');
|
|
449
|
-
if (!res.ok)
|
|
468
|
+
if (!res.ok) {
|
|
469
|
+
await cancelBodyQuietly(res);
|
|
450
470
|
throw new Error(`DFlow quote HTTP ${res.status}`);
|
|
471
|
+
}
|
|
451
472
|
const rawJson = await res.json();
|
|
452
473
|
if (!isPlainObject(rawJson))
|
|
453
474
|
throw new Error('DFlow returned non-object quote JSON');
|
|
@@ -502,6 +523,9 @@ export function createDFlowSwapAdapter(config = {}) {
|
|
|
502
523
|
};
|
|
503
524
|
},
|
|
504
525
|
async swapInstructions(req) {
|
|
526
|
+
if (!this.isConfigured()) {
|
|
527
|
+
throw new Error('DFlow adapter not configured (set apiKey or apiUrl)');
|
|
528
|
+
}
|
|
505
529
|
const base = resolveBase();
|
|
506
530
|
const res = await safeAggregatorFetch(fetchImpl, `${base}/swap-instructions`, {
|
|
507
531
|
method: 'POST',
|
|
@@ -515,8 +539,10 @@ export function createDFlowSwapAdapter(config = {}) {
|
|
|
515
539
|
}),
|
|
516
540
|
signal: buildFetchSignal(req.signal, req.timeoutMs ?? 10_000),
|
|
517
541
|
}, 'DFlow');
|
|
518
|
-
if (!res.ok)
|
|
542
|
+
if (!res.ok) {
|
|
543
|
+
await cancelBodyQuietly(res);
|
|
519
544
|
throw new Error(`DFlow swap-instructions HTTP ${res.status}`);
|
|
545
|
+
}
|
|
520
546
|
const payloadRaw = await res.json();
|
|
521
547
|
if (!isPlainObject(payloadRaw))
|
|
522
548
|
throw new Error('DFlow returned non-object swap-instructions JSON');
|
|
@@ -614,8 +640,10 @@ export function createOkxSwapAdapter(config = {}) {
|
|
|
614
640
|
headers,
|
|
615
641
|
signal: buildFetchSignal(req.signal, req.timeoutMs ?? 10_000),
|
|
616
642
|
}, 'OKX');
|
|
617
|
-
if (!res.ok)
|
|
643
|
+
if (!res.ok) {
|
|
644
|
+
await cancelBodyQuietly(res);
|
|
618
645
|
throw new Error(`OKX swap-instruction HTTP ${res.status}`);
|
|
646
|
+
}
|
|
619
647
|
const bodyRaw = await res.json();
|
|
620
648
|
if (!isPlainObject(bodyRaw))
|
|
621
649
|
throw new Error('OKX returned non-object response JSON');
|
|
@@ -637,9 +665,7 @@ export function createOkxSwapAdapter(config = {}) {
|
|
|
637
665
|
candidate = await fetchOkxCandidate(Boolean(req.onlyDirectRoutes));
|
|
638
666
|
}
|
|
639
667
|
catch (err) {
|
|
640
|
-
|
|
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) {
|
|
668
|
+
if (!req.onlyDirectRoutes && err instanceof PrebuiltRouteBoundsError && !req.signal?.aborted) {
|
|
643
669
|
candidate = await fetchOkxCandidate(true);
|
|
644
670
|
}
|
|
645
671
|
else {
|
|
@@ -842,8 +868,10 @@ export function createTitanSwapAdapter(config = {}) {
|
|
|
842
868
|
},
|
|
843
869
|
signal: buildFetchSignal(req.signal, req.timeoutMs ?? 10_000),
|
|
844
870
|
}, 'Titan');
|
|
845
|
-
if (!res.ok)
|
|
871
|
+
if (!res.ok) {
|
|
872
|
+
await cancelBodyQuietly(res);
|
|
846
873
|
throw new Error(`Titan quote HTTP ${res.status}`);
|
|
874
|
+
}
|
|
847
875
|
const decodedRaw = await res.json();
|
|
848
876
|
if (!isPlainObject(decodedRaw))
|
|
849
877
|
throw new Error('Titan returned non-object quote JSON');
|
|
@@ -1024,8 +1052,10 @@ export function createBedrockSwapAdapter(config = {}) {
|
|
|
1024
1052
|
headers: makeHeaders(),
|
|
1025
1053
|
signal: buildFetchSignal(req.signal, req.timeoutMs ?? 10_000),
|
|
1026
1054
|
}, 'Bedrock');
|
|
1027
|
-
if (!res.ok)
|
|
1055
|
+
if (!res.ok) {
|
|
1056
|
+
await cancelBodyQuietly(res);
|
|
1028
1057
|
throw new Error(`Bedrock quote HTTP ${res.status}`);
|
|
1058
|
+
}
|
|
1029
1059
|
const rawJson = await res.json();
|
|
1030
1060
|
if (!isPlainObject(rawJson))
|
|
1031
1061
|
throw new Error('Bedrock returned non-object quote JSON');
|
|
@@ -1075,6 +1105,9 @@ export function createBedrockSwapAdapter(config = {}) {
|
|
|
1075
1105
|
};
|
|
1076
1106
|
},
|
|
1077
1107
|
async swapInstructions(req) {
|
|
1108
|
+
if (!this.isConfigured()) {
|
|
1109
|
+
throw new Error('Bedrock adapter not configured (set apiUrl)');
|
|
1110
|
+
}
|
|
1078
1111
|
const base = resolveBase();
|
|
1079
1112
|
const res = await safeAggregatorFetch(fetchImpl, `${base}/swap-instructions`, {
|
|
1080
1113
|
method: 'POST',
|
|
@@ -1088,8 +1121,10 @@ export function createBedrockSwapAdapter(config = {}) {
|
|
|
1088
1121
|
}),
|
|
1089
1122
|
signal: buildFetchSignal(req.signal, req.timeoutMs ?? 10_000),
|
|
1090
1123
|
}, 'Bedrock');
|
|
1091
|
-
if (!res.ok)
|
|
1124
|
+
if (!res.ok) {
|
|
1125
|
+
await cancelBodyQuietly(res);
|
|
1092
1126
|
throw new Error(`Bedrock swap-instructions HTTP ${res.status}`);
|
|
1127
|
+
}
|
|
1093
1128
|
const payloadRaw = await res.json();
|
|
1094
1129
|
if (!isPlainObject(payloadRaw))
|
|
1095
1130
|
throw new Error('Bedrock returned non-object swap-instructions JSON');
|
|
@@ -1225,11 +1260,13 @@ export class AudrenSwapRouter {
|
|
|
1225
1260
|
}
|
|
1226
1261
|
return null;
|
|
1227
1262
|
}
|
|
1228
|
-
checkPrebuiltRouterAllowlist(quote) {
|
|
1229
|
-
|
|
1263
|
+
checkPrebuiltRouterAllowlist(quote, req) {
|
|
1264
|
+
const allowUnverified = req.allowUnverifiedRouter ?? this.allowUnverifiedRouter;
|
|
1265
|
+
if (allowUnverified)
|
|
1230
1266
|
return null;
|
|
1267
|
+
const allowed = req.allowedRouterPrograms ?? this.allowedRouterPrograms;
|
|
1231
1268
|
const prebuiltRouter = extractPrebuiltRouterProgramId(quote.rawQuote);
|
|
1232
|
-
if (prebuiltRouter && !
|
|
1269
|
+
if (prebuiltRouter && !allowed.includes(prebuiltRouter)) {
|
|
1233
1270
|
return `Aggregator "${quote.provider}" returned unapproved swap router program ${prebuiltRouter}`;
|
|
1234
1271
|
}
|
|
1235
1272
|
return null;
|
|
@@ -1264,7 +1301,7 @@ export class AudrenSwapRouter {
|
|
|
1264
1301
|
if (badVenue) {
|
|
1265
1302
|
throw new Error(`Aggregator "${chosen}" routed via PDA-CPI-excluded venue "${badVenue}"`);
|
|
1266
1303
|
}
|
|
1267
|
-
const routerErr = this.checkPrebuiltRouterAllowlist(quote);
|
|
1304
|
+
const routerErr = this.checkPrebuiltRouterAllowlist(quote, req);
|
|
1268
1305
|
if (routerErr)
|
|
1269
1306
|
throw new Error(routerErr);
|
|
1270
1307
|
return {
|
|
@@ -1302,7 +1339,7 @@ export class AudrenSwapRouter {
|
|
|
1302
1339
|
});
|
|
1303
1340
|
return;
|
|
1304
1341
|
}
|
|
1305
|
-
const routerErr = this.checkPrebuiltRouterAllowlist(res.value);
|
|
1342
|
+
const routerErr = this.checkPrebuiltRouterAllowlist(res.value, req);
|
|
1306
1343
|
if (routerErr) {
|
|
1307
1344
|
candidates.push({
|
|
1308
1345
|
provider: id,
|
|
@@ -1400,6 +1437,8 @@ export class AudrenSwapRouter {
|
|
|
1400
1437
|
platformFeeBps: req.platformFeeBps,
|
|
1401
1438
|
feeAccountAta: req.feeAccountAta,
|
|
1402
1439
|
feeOwnerWallet: req.feeOwnerWallet,
|
|
1440
|
+
allowedRouterPrograms: req.allowedRouterPrograms,
|
|
1441
|
+
allowUnverifiedRouter: req.allowUnverifiedRouter,
|
|
1403
1442
|
timeoutMs: req.timeoutMs,
|
|
1404
1443
|
signal: req.signal,
|
|
1405
1444
|
});
|
package/dist/swap.js
CHANGED
|
@@ -78,6 +78,7 @@ export async function fetchAggregatorPrivateSwapRoute(aggregatorBaseUrl, quotePa
|
|
|
78
78
|
throw new Error(`Aggregator /quote returned unexpected HTTP ${quoteRes.status} redirect`);
|
|
79
79
|
}
|
|
80
80
|
if (!quoteRes.ok) {
|
|
81
|
+
await quoteRes.body?.cancel?.().catch(() => { });
|
|
81
82
|
throw new Error(`Aggregator /quote failed: HTTP ${quoteRes.status}`);
|
|
82
83
|
}
|
|
83
84
|
const quote = (await quoteRes.json());
|
|
@@ -100,6 +101,7 @@ export async function fetchAggregatorPrivateSwapRoute(aggregatorBaseUrl, quotePa
|
|
|
100
101
|
throw new Error(`Aggregator /swap-instructions returned unexpected HTTP ${swapRes.status} redirect`);
|
|
101
102
|
}
|
|
102
103
|
if (!swapRes.ok) {
|
|
104
|
+
await swapRes.body?.cancel?.().catch(() => { });
|
|
103
105
|
throw new Error(`Aggregator /swap-instructions failed: HTTP ${swapRes.status}`);
|
|
104
106
|
}
|
|
105
107
|
const swap = (await swapRes.json());
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@audren-xyz/sdk",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.6",
|
|
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)",
|