@silentswap/sdk 0.0.65 → 0.0.67

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.
@@ -59,7 +59,10 @@ export interface BridgeQuoteResult {
59
59
  */
60
60
  export declare function calculateRelayMetrics(relayQuote: RelayQuoteResponse): QuoteMetrics;
61
61
  /**
62
- * Calculate metrics from a deBridge quote response
62
+ * Calculate metrics from a deBridge quote response.
63
+ * Prefer estimation.protocolFeeUsd (from API protocolFeeApproximateUsdValue); costDetails
64
+ * payload feeApproximateUsdValue can be wrong when normalized from single-chain response
65
+ * (fee amounts are in different token units than swap input).
63
66
  */
64
67
  export declare function calculateDebridgeMetrics(debridgeQuote: DeBridgeOrderResponse): QuoteMetrics;
65
68
  /**
@@ -76,17 +76,22 @@ export function calculateRelayMetrics(relayQuote) {
76
76
  };
77
77
  }
78
78
  /**
79
- * Calculate metrics from a deBridge quote response
79
+ * Calculate metrics from a deBridge quote response.
80
+ * Prefer estimation.protocolFeeUsd (from API protocolFeeApproximateUsdValue); costDetails
81
+ * payload feeApproximateUsdValue can be wrong when normalized from single-chain response
82
+ * (fee amounts are in different token units than swap input).
80
83
  */
81
84
  export function calculateDebridgeMetrics(debridgeQuote) {
82
85
  const usdIn = debridgeQuote.estimation.srcChainTokenIn.approximateUsdValue;
83
86
  const usdOut = debridgeQuote.estimation.dstChainTokenOut.approximateUsdValue;
87
+ const feeUsd = debridgeQuote.estimation.protocolFeeUsd != null && debridgeQuote.estimation.protocolFeeUsd >= 0
88
+ ? debridgeQuote.estimation.protocolFeeUsd
89
+ : (debridgeQuote.estimation.costDetails?.reduce((sum, detail) => sum + Number(detail.payload?.feeApproximateUsdValue || 0), 0) ?? 0);
84
90
  return {
85
91
  retention: BigNumber(usdOut).div(usdIn).toNumber(),
86
- feeUsd: debridgeQuote.estimation.costDetails
87
- ?.reduce((sum, detail) => sum + Number(detail.payload?.feeApproximateUsdValue || 0), 0) || 0,
92
+ feeUsd,
88
93
  slippage: 100 * (1 - usdOut / usdIn),
89
- time: debridgeQuote.order?.approximateFulfillmentDelay || 600,
94
+ time: debridgeQuote.order?.approximateFulfillmentDelay ?? 600,
90
95
  txCount: 2, // DeBridge typically requires 2 txs
91
96
  };
92
97
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@silentswap/sdk",
3
3
  "type": "module",
4
- "version": "0.0.65",
4
+ "version": "0.0.67",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
7
7
  "files": [