@silentswap/sdk 0.0.67 → 0.0.68
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/bridge.d.ts +6 -0
- package/dist/quote-utils.d.ts +8 -1
- package/dist/quote-utils.js +27 -6
- package/package.json +1 -1
package/dist/bridge.d.ts
CHANGED
|
@@ -202,6 +202,12 @@ export interface DeBridgeOrderParams {
|
|
|
202
202
|
srcChainOrderAuthorityAddress?: string;
|
|
203
203
|
srcChainRefundAddress?: string;
|
|
204
204
|
dstChainOrderAuthorityAddress?: string;
|
|
205
|
+
referralCode?: number;
|
|
206
|
+
additionalTakerRewardBps?: number;
|
|
207
|
+
allowedTaker?: string;
|
|
208
|
+
deBridgeApp?: string;
|
|
209
|
+
ptp?: boolean;
|
|
210
|
+
srcChainPriorityLevel?: 'normal' | 'aggressive';
|
|
205
211
|
}
|
|
206
212
|
export interface DeBridgeOrderResponse {
|
|
207
213
|
tx: {
|
package/dist/quote-utils.d.ts
CHANGED
|
@@ -73,14 +73,21 @@ export declare function selectBestQuote(relayQuote: RelayQuoteResponse | null, d
|
|
|
73
73
|
* Interpolate retention rate from samples
|
|
74
74
|
*/
|
|
75
75
|
export declare function interpolateSamples(samples: EstimateSample[], usdValue: number, marginHi?: number): number;
|
|
76
|
+
/**
|
|
77
|
+
* When set, only the specified provider is used for quotes (for testing).
|
|
78
|
+
*/
|
|
79
|
+
export type ForceBridgeProvider = 'relay' | 'debridge';
|
|
76
80
|
/**
|
|
77
81
|
* Get quote for cross-chain swap from multiple providers
|
|
78
82
|
* This is the core logic shared between React and Vue
|
|
79
83
|
* @param recipientAddress - Optional recipient address (required for Solana destinations)
|
|
84
|
+
* @param sourceAddress - Optional source chain address (if different from userAddress)
|
|
85
|
+
* @param forceProvider - Optional: use only this provider (for testing; skips the other)
|
|
80
86
|
*/
|
|
81
87
|
export declare function getBridgeQuote(srcChainId: number, srcToken: string, srcAmount: string, dstChainId: number, dstToken: string, userAddress: `0x${string}` | string, // Can be EVM (0x) or Solana (base58) address
|
|
82
88
|
signal?: AbortSignal, recipientAddress?: string, // Optional recipient address (required for Solana destinations)
|
|
83
|
-
sourceAddress?: string)
|
|
89
|
+
sourceAddress?: string, // Optional source chain address (if different from userAddress)
|
|
90
|
+
forceProvider?: ForceBridgeProvider): Promise<BridgeQuoteResult>;
|
|
84
91
|
/**
|
|
85
92
|
* Convert BridgeQuoteResult to BridgeQuote with transaction data
|
|
86
93
|
* Extracts transactions from the raw response based on provider
|
package/dist/quote-utils.js
CHANGED
|
@@ -221,11 +221,13 @@ export function interpolateSamples(samples, usdValue, marginHi = Infinity) {
|
|
|
221
221
|
* Get quote for cross-chain swap from multiple providers
|
|
222
222
|
* This is the core logic shared between React and Vue
|
|
223
223
|
* @param recipientAddress - Optional recipient address (required for Solana destinations)
|
|
224
|
+
* @param sourceAddress - Optional source chain address (if different from userAddress)
|
|
225
|
+
* @param forceProvider - Optional: use only this provider (for testing; skips the other)
|
|
224
226
|
*/
|
|
225
227
|
export async function getBridgeQuote(srcChainId, srcToken, srcAmount, dstChainId, dstToken, userAddress, // Can be EVM (0x) or Solana (base58) address
|
|
226
228
|
signal, recipientAddress, // Optional recipient address (required for Solana destinations)
|
|
227
|
-
sourceAddress // Optional source chain address (if different from userAddress)
|
|
228
|
-
) {
|
|
229
|
+
sourceAddress, // Optional source chain address (if different from userAddress)
|
|
230
|
+
forceProvider) {
|
|
229
231
|
console.log('recipientAddress', recipientAddress);
|
|
230
232
|
console.log('sourceAddress', sourceAddress);
|
|
231
233
|
console.log('userAddress', userAddress);
|
|
@@ -300,10 +302,14 @@ sourceAddress // Optional source chain address (if different from userAddress)
|
|
|
300
302
|
relayUserAddress = DEAD_ADDRESS;
|
|
301
303
|
}
|
|
302
304
|
}
|
|
303
|
-
// Fetch quotes from both providers in parallel
|
|
305
|
+
// Fetch quotes from both providers in parallel (skip one if forceProvider is set)
|
|
306
|
+
const useRelay = forceProvider !== 'debridge';
|
|
307
|
+
const useDebridge = forceProvider !== 'relay';
|
|
304
308
|
const [relayResult, debridgeResult] = await Promise.allSettled([
|
|
305
|
-
// Relay.link quote
|
|
309
|
+
// Relay.link quote (skipped when forceProvider === 'debridge')
|
|
306
310
|
(async () => {
|
|
311
|
+
if (!useRelay)
|
|
312
|
+
return null;
|
|
307
313
|
try {
|
|
308
314
|
// Map chain IDs to Relay chain IDs if needed
|
|
309
315
|
// For Solana, Relay.link uses N_RELAY_CHAIN_ID_SOLANA (792703809)
|
|
@@ -409,8 +415,10 @@ sourceAddress // Optional source chain address (if different from userAddress)
|
|
|
409
415
|
return null;
|
|
410
416
|
}
|
|
411
417
|
})(),
|
|
412
|
-
// deBridge quote
|
|
418
|
+
// deBridge quote (skipped when forceProvider === 'relay')
|
|
413
419
|
(async () => {
|
|
420
|
+
if (!useDebridge)
|
|
421
|
+
return null;
|
|
414
422
|
try {
|
|
415
423
|
// Skip deBridge for Bitcoin - Bitcoin only supports relay
|
|
416
424
|
if (isSrcBitcoin || isDestBitcoin) {
|
|
@@ -462,9 +470,22 @@ sourceAddress // Optional source chain address (if different from userAddress)
|
|
|
462
470
|
}
|
|
463
471
|
}
|
|
464
472
|
else {
|
|
465
|
-
// Both source and destination are EVM
|
|
473
|
+
// Both source and destination are EVM
|
|
474
|
+
// API requires dstChainTokenOutRecipient, srcChainOrderAuthorityAddress, dstChainOrderAuthorityAddress for transaction construction
|
|
475
|
+
debridgeParams.dstChainTokenOutRecipient = userAddress;
|
|
476
|
+
debridgeParams.srcChainOrderAuthorityAddress = userAddress;
|
|
477
|
+
debridgeParams.dstChainOrderAuthorityAddress = userAddress;
|
|
478
|
+
debridgeParams.srcChainRefundAddress = userAddress;
|
|
479
|
+
debridgeParams.senderAddress = userAddress;
|
|
466
480
|
debridgeParams.dstChainTokenOutAmount = 'auto';
|
|
467
481
|
debridgeParams.enableEstimate = true;
|
|
482
|
+
// Optional params matching deSwap app for consistent API behavior
|
|
483
|
+
debridgeParams.additionalTakerRewardBps = 0;
|
|
484
|
+
debridgeParams.deBridgeApp = 'DESWAP';
|
|
485
|
+
debridgeParams.ptp = false;
|
|
486
|
+
debridgeParams.srcChainPriorityLevel = 'normal';
|
|
487
|
+
// Use standard API param names (senderAddress, dstChainTokenOutRecipient); omit account
|
|
488
|
+
// delete debridgeParams.account;
|
|
468
489
|
}
|
|
469
490
|
const quote = await fetchDebridgeOrder(debridgeParams, signal);
|
|
470
491
|
return quote;
|