@silentswap/sdk 0.0.58 → 0.0.59
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/caip19.js +2 -1
- package/dist/quote-utils.d.ts +2 -0
- package/dist/quote-utils.js +30 -0
- package/package.json +1 -1
package/dist/caip19.js
CHANGED
|
@@ -176,7 +176,8 @@ export function isNativeToken(caip19) {
|
|
|
176
176
|
* @returns True if EVM asset
|
|
177
177
|
*/
|
|
178
178
|
export function isEvmAsset(caip19) {
|
|
179
|
-
|
|
179
|
+
// eip155:1440000/slip44:144 - it is XRPL, not EVM
|
|
180
|
+
return caip19.startsWith('eip155:') && !caip19.includes('eip155:1440000/slip44:144');
|
|
180
181
|
}
|
|
181
182
|
/**
|
|
182
183
|
* Check if CAIP-19 represents a Solana asset
|
package/dist/quote-utils.d.ts
CHANGED
|
@@ -51,6 +51,8 @@ export interface BridgeQuoteResult {
|
|
|
51
51
|
txCount: number;
|
|
52
52
|
/** Raw response from the provider */
|
|
53
53
|
rawResponse: RelayQuoteResponse | DeBridgeOrderResponse;
|
|
54
|
+
/** First PSBT from relay steps (BTC swaps only); also present in rawResponse.steps */
|
|
55
|
+
psbt?: string;
|
|
54
56
|
}
|
|
55
57
|
/**
|
|
56
58
|
* Calculate metrics from a Relay.link quote response
|
package/dist/quote-utils.js
CHANGED
|
@@ -119,6 +119,23 @@ export function selectBestQuote(relayQuote, debridgeQuote, srcAmount) {
|
|
|
119
119
|
const outputAmount = bestProvider === 'relay'
|
|
120
120
|
? bestQuote.details.currencyOut.amount
|
|
121
121
|
: bestQuote.estimation.dstChainTokenOut.amount;
|
|
122
|
+
// Extract first PSBT from relay steps for BTC swaps (convenience; also in rawResponse)
|
|
123
|
+
let psbt;
|
|
124
|
+
if (bestProvider === 'relay') {
|
|
125
|
+
const steps = bestQuote.steps || [];
|
|
126
|
+
for (const step of steps) {
|
|
127
|
+
for (const item of step.items || []) {
|
|
128
|
+
const d = item.data || {};
|
|
129
|
+
const p = d.psbt || d.hex || d.data;
|
|
130
|
+
if (p && !d.to && !Array.isArray(d.instructions)) {
|
|
131
|
+
psbt = typeof p === 'string' ? p : undefined;
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if (psbt)
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
122
139
|
return {
|
|
123
140
|
provider: bestProvider,
|
|
124
141
|
outputAmount: outputAmount || '0',
|
|
@@ -129,6 +146,7 @@ export function selectBestQuote(relayQuote, debridgeQuote, srcAmount) {
|
|
|
129
146
|
retentionRate: bestMetrics.retention,
|
|
130
147
|
txCount: bestMetrics.txCount,
|
|
131
148
|
rawResponse: bestQuote,
|
|
149
|
+
...(psbt !== undefined && { psbt }),
|
|
132
150
|
};
|
|
133
151
|
}
|
|
134
152
|
/**
|
|
@@ -454,6 +472,18 @@ export function convertQuoteResultToQuote(result, srcChainId) {
|
|
|
454
472
|
const senderAddress = relayResponse.details?.sender;
|
|
455
473
|
txs = (relayResponse.steps || []).flatMap((step) => (step.items || []).map((item) => {
|
|
456
474
|
const itemData = item.data || {};
|
|
475
|
+
// Check if this is a Bitcoin transaction (has psbt, hex, or data for PSBT)
|
|
476
|
+
const psbtData = itemData.psbt || itemData.hex || itemData.data;
|
|
477
|
+
const isBitcoinStep = step.chainId === N_RELAY_CHAIN_ID_BITCOIN ||
|
|
478
|
+
('psbt' in itemData && itemData.psbt) ||
|
|
479
|
+
(psbtData && !itemData.to && !('instructions' in itemData));
|
|
480
|
+
if (isBitcoinStep && psbtData) {
|
|
481
|
+
return {
|
|
482
|
+
chainId: N_RELAY_CHAIN_ID_BITCOIN,
|
|
483
|
+
data: psbtData,
|
|
484
|
+
...{ psbt: psbtData },
|
|
485
|
+
};
|
|
486
|
+
}
|
|
457
487
|
// Check if this is a Solana transaction (has instructions field)
|
|
458
488
|
if ('instructions' in itemData && Array.isArray(itemData.instructions)) {
|
|
459
489
|
// Solana transaction
|