@shapeshiftoss/swapper 18.1.0 → 19.0.0
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/cjs/.tsbuildinfo +1 -1
- package/dist/cjs/swappers/AcrossSwapper/constant.js +2 -1
- package/dist/cjs/swappers/AcrossSwapper/endpoints.js +1 -1
- package/dist/cjs/swappers/AcrossSwapper/getTradeQuote/getTradeQuote.js +2 -1
- package/dist/cjs/swappers/AcrossSwapper/utils/acrossService.d.ts +6 -3
- package/dist/cjs/swappers/AcrossSwapper/utils/acrossService.js +5 -1
- package/dist/cjs/swappers/AcrossSwapper/utils/fetchAcrossTrade.js +1 -1
- package/dist/cjs/swappers/AcrossSwapper/utils/getAcrossTradeContext.d.ts +1 -0
- package/dist/cjs/swappers/AcrossSwapper/utils/getAcrossTradeContext.js +1 -0
- package/dist/cjs/swappers/ArbitrumBridgeSwapper/getTradeQuote/getTradeQuote.js +2 -0
- package/dist/cjs/swappers/AvnuSwapper/swapperApi/getTradeQuote.js +3 -1
- package/dist/cjs/swappers/AvnuSwapper/utils/getAvnuTradeContext.d.ts +1 -0
- package/dist/cjs/swappers/AvnuSwapper/utils/getAvnuTradeContext.js +1 -0
- package/dist/cjs/swappers/BebopSwapper/getBebopSolanaTradeQuote/getBebopSolanaTradeQuote.js +5 -2
- package/dist/cjs/swappers/BebopSwapper/getBebopTradeQuote/getBebopTradeQuote.js +2 -1
- package/dist/cjs/swappers/BebopSwapper/types.d.ts +2 -2
- package/dist/cjs/swappers/BebopSwapper/types.js +2 -0
- package/dist/cjs/swappers/BebopSwapper/utils/getBebopTradeContext.d.ts +1 -0
- package/dist/cjs/swappers/BebopSwapper/utils/getBebopTradeContext.js +1 -0
- package/dist/cjs/swappers/BebopSwapper/utils/helpers.d.ts +1 -1
- package/dist/cjs/swappers/BobGatewaySwapper/swapperApi/getTradeQuote.js +2 -0
- package/dist/cjs/swappers/ButterSwap/swapperApi/getTradeQuote.js +2 -0
- package/dist/cjs/swappers/ButterSwap/utils/helpers.js +10 -8
- package/dist/cjs/swappers/CetusSwapper/swapperApi/getTradeQuote.js +2 -0
- package/dist/cjs/swappers/ChainflipSwapper/constants.d.ts +1 -0
- package/dist/cjs/swappers/ChainflipSwapper/constants.js +3 -1
- package/dist/cjs/swappers/ChainflipSwapper/swapperApi/getTradeQuote.js +2 -0
- package/dist/cjs/swappers/CowSwapper/getCowSwapTradeQuote/getCowSwapTradeQuote.js +1 -0
- package/dist/cjs/swappers/DebridgeSwapper/constant.js +10 -8
- package/dist/cjs/swappers/DebridgeSwapper/getTradeQuote/getTradeQuote.js +2 -0
- package/dist/cjs/swappers/NearIntentsSwapper/endpoints.js +3 -1
- package/dist/cjs/swappers/NearIntentsSwapper/swapperApi/getTradeQuote.js +7 -0
- package/dist/cjs/swappers/PortalsSwapper/getPortalsTradeQuote/getPortalsTradeQuote.js +11 -0
- package/dist/cjs/swappers/RelaySwapper/constant.js +4 -3
- package/dist/cjs/swappers/RelaySwapper/endpoints.js +6 -2
- package/dist/cjs/swappers/RelaySwapper/getTradeQuote/getTradeQuote.js +2 -0
- package/dist/cjs/swappers/RelaySwapper/utils/fetchRelayTrade.js +1 -1
- package/dist/cjs/swappers/RelaySwapper/utils/getLatestRelayStatusMessage.js +3 -1
- package/dist/cjs/swappers/RelaySwapper/utils/notifyTransactionIndexing.js +1 -1
- package/dist/cjs/swappers/RelaySwapper/utils/relayService.d.ts +6 -3
- package/dist/cjs/swappers/RelaySwapper/utils/relayService.js +3 -1
- package/dist/cjs/swappers/RelaySwapper/utils/relayTokenToAssetId.js +5 -0
- package/dist/cjs/swappers/RelaySwapper/utils/types.d.ts +2 -2
- package/dist/cjs/swappers/StonfiSwapper/endpoints.js +40 -14
- package/dist/cjs/swappers/StonfiSwapper/swapperApi/getTradeQuote.js +2 -0
- package/dist/cjs/swappers/SunioSwapper/getSunioTradeQuote/getSunioTradeQuote.js +2 -0
- package/dist/cjs/swappers/ThorchainSwapper/getTradeQuote/getTradeQuote.test.js +2 -0
- package/dist/cjs/swappers/ThorchainSwapper/utils/getLongtailQuote.js +2 -0
- package/dist/cjs/swappers/ZrxSwapper/getZrxTradeQuote/getZrxTradeQuote.js +1 -0
- package/dist/cjs/swappers/ZrxSwapper/types.d.ts +1 -1
- package/dist/cjs/swappers/ZrxSwapper/types.js +1 -0
- package/dist/cjs/swappers/ZrxSwapper/utils/constants.js +1 -0
- package/dist/cjs/swappers/ZrxSwapper/utils/helpers.d.ts +1 -1
- package/dist/cjs/swappers/ZrxSwapper/utils/helpers.js +5 -0
- package/dist/cjs/types.d.ts +3 -0
- package/dist/cjs/utils/helpers.d.ts +2 -0
- package/dist/cjs/utils/helpers.js +14 -1
- package/dist/cjs/utils/helpers.test.js +17 -0
- package/dist/cjs/utils/test-data/setupSwapQuote.js +1 -0
- package/dist/cjs/utils/thorchain/getThorL1TradeQuote.js +3 -0
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/swappers/AcrossSwapper/constant.js +4 -3
- package/dist/esm/swappers/AcrossSwapper/endpoints.js +2 -2
- package/dist/esm/swappers/AcrossSwapper/getTradeQuote/getTradeQuote.js +2 -1
- package/dist/esm/swappers/AcrossSwapper/utils/acrossService.d.ts +6 -3
- package/dist/esm/swappers/AcrossSwapper/utils/acrossService.js +3 -0
- package/dist/esm/swappers/AcrossSwapper/utils/fetchAcrossTrade.js +2 -2
- package/dist/esm/swappers/AcrossSwapper/utils/getAcrossTradeContext.d.ts +1 -0
- package/dist/esm/swappers/AcrossSwapper/utils/getAcrossTradeContext.js +2 -1
- package/dist/esm/swappers/ArbitrumBridgeSwapper/getTradeQuote/getTradeQuote.js +2 -0
- package/dist/esm/swappers/AvnuSwapper/swapperApi/getTradeQuote.js +3 -1
- package/dist/esm/swappers/AvnuSwapper/utils/getAvnuTradeContext.d.ts +1 -0
- package/dist/esm/swappers/AvnuSwapper/utils/getAvnuTradeContext.js +2 -1
- package/dist/esm/swappers/BebopSwapper/getBebopSolanaTradeQuote/getBebopSolanaTradeQuote.js +3 -0
- package/dist/esm/swappers/BebopSwapper/getBebopTradeQuote/getBebopTradeQuote.js +2 -1
- package/dist/esm/swappers/BebopSwapper/types.d.ts +2 -2
- package/dist/esm/swappers/BebopSwapper/types.js +2 -0
- package/dist/esm/swappers/BebopSwapper/utils/getBebopTradeContext.d.ts +1 -0
- package/dist/esm/swappers/BebopSwapper/utils/getBebopTradeContext.js +2 -1
- package/dist/esm/swappers/BebopSwapper/utils/helpers.d.ts +1 -1
- package/dist/esm/swappers/BobGatewaySwapper/swapperApi/getTradeQuote.js +2 -0
- package/dist/esm/swappers/ButterSwap/swapperApi/getTradeQuote.js +2 -0
- package/dist/esm/swappers/ButterSwap/utils/helpers.js +10 -8
- package/dist/esm/swappers/CetusSwapper/swapperApi/getTradeQuote.js +2 -0
- package/dist/esm/swappers/ChainflipSwapper/constants.d.ts +1 -0
- package/dist/esm/swappers/ChainflipSwapper/constants.js +2 -0
- package/dist/esm/swappers/ChainflipSwapper/swapperApi/getTradeQuote.js +2 -0
- package/dist/esm/swappers/CowSwapper/getCowSwapTradeQuote/getCowSwapTradeQuote.js +1 -0
- package/dist/esm/swappers/DebridgeSwapper/constant.js +11 -9
- package/dist/esm/swappers/DebridgeSwapper/getTradeQuote/getTradeQuote.js +2 -0
- package/dist/esm/swappers/NearIntentsSwapper/endpoints.js +3 -1
- package/dist/esm/swappers/NearIntentsSwapper/swapperApi/getTradeQuote.js +7 -0
- package/dist/esm/swappers/PortalsSwapper/getPortalsTradeQuote/getPortalsTradeQuote.js +12 -1
- package/dist/esm/swappers/RelaySwapper/constant.js +6 -5
- package/dist/esm/swappers/RelaySwapper/endpoints.js +7 -3
- package/dist/esm/swappers/RelaySwapper/getTradeQuote/getTradeQuote.js +2 -0
- package/dist/esm/swappers/RelaySwapper/utils/fetchRelayTrade.js +2 -2
- package/dist/esm/swappers/RelaySwapper/utils/getLatestRelayStatusMessage.js +3 -1
- package/dist/esm/swappers/RelaySwapper/utils/notifyTransactionIndexing.js +2 -2
- package/dist/esm/swappers/RelaySwapper/utils/relayService.d.ts +6 -3
- package/dist/esm/swappers/RelaySwapper/utils/relayService.js +1 -0
- package/dist/esm/swappers/RelaySwapper/utils/relayTokenToAssetId.js +5 -0
- package/dist/esm/swappers/RelaySwapper/utils/types.d.ts +2 -2
- package/dist/esm/swappers/StonfiSwapper/endpoints.js +41 -15
- package/dist/esm/swappers/StonfiSwapper/swapperApi/getTradeQuote.js +2 -0
- package/dist/esm/swappers/SunioSwapper/getSunioTradeQuote/getSunioTradeQuote.js +2 -0
- package/dist/esm/swappers/ThorchainSwapper/getTradeQuote/getTradeQuote.test.js +2 -0
- package/dist/esm/swappers/ThorchainSwapper/utils/getLongtailQuote.js +2 -0
- package/dist/esm/swappers/ZrxSwapper/getZrxTradeQuote/getZrxTradeQuote.js +2 -1
- package/dist/esm/swappers/ZrxSwapper/types.d.ts +1 -1
- package/dist/esm/swappers/ZrxSwapper/types.js +1 -0
- package/dist/esm/swappers/ZrxSwapper/utils/constants.js +1 -0
- package/dist/esm/swappers/ZrxSwapper/utils/helpers.d.ts +1 -1
- package/dist/esm/swappers/ZrxSwapper/utils/helpers.js +5 -0
- package/dist/esm/types.d.ts +3 -0
- package/dist/esm/utils/helpers.d.ts +2 -0
- package/dist/esm/utils/helpers.js +12 -0
- package/dist/esm/utils/helpers.test.js +18 -1
- package/dist/esm/utils/test-data/setupSwapQuote.js +1 -0
- package/dist/esm/utils/thorchain/getThorL1TradeQuote.js +3 -0
- package/package.json +5 -5
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import type { AxiosRequestConfig } from 'axios';
|
|
2
|
+
import type { SwapperConfig } from '../../../types';
|
|
1
3
|
export declare const relayService: {
|
|
2
|
-
get: <T = any>(url: string, config?:
|
|
3
|
-
post: <T_1 = any>(url: string, data: any, config?:
|
|
4
|
-
delete: <T_2 = any>(url: string, data: any, config?:
|
|
4
|
+
get: <T = any>(url: string, config?: AxiosRequestConfig<any> | undefined) => Promise<import("@sniptt/monads").Result<import("axios").AxiosResponse<T, any, {}>, import("../../../types").SwapErrorRight>>;
|
|
5
|
+
post: <T_1 = any>(url: string, data: any, config?: AxiosRequestConfig<any> | undefined) => Promise<import("@sniptt/monads").Result<import("axios").AxiosResponse<T_1, any, {}>, import("../../../types").SwapErrorRight>>;
|
|
6
|
+
delete: <T_2 = any>(url: string, data: any, config?: AxiosRequestConfig<any> | undefined) => Promise<import("@sniptt/monads").Result<import("axios").AxiosResponse<T_2, any, {}>, import("../../../types").SwapErrorRight>>;
|
|
5
7
|
};
|
|
8
|
+
export declare const getRelayRequestConfig: (config: SwapperConfig) => AxiosRequestConfig | undefined;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.relayService = void 0;
|
|
3
|
+
exports.getRelayRequestConfig = exports.relayService = void 0;
|
|
4
4
|
const utils_1 = require("../../../utils");
|
|
5
5
|
const maxAgeMillis = 15 * 1000;
|
|
6
6
|
const cachedUrls = [];
|
|
@@ -13,3 +13,5 @@ const axiosConfig = {
|
|
|
13
13
|
};
|
|
14
14
|
const relayServiceBase = (0, utils_1.createCache)(maxAgeMillis, cachedUrls, axiosConfig);
|
|
15
15
|
exports.relayService = (0, utils_1.makeSwapperAxiosServiceMonadic)(relayServiceBase);
|
|
16
|
+
const getRelayRequestConfig = (config) => config.VITE_RELAY_API_KEY ? { headers: { 'x-api-key': config.VITE_RELAY_API_KEY } } : undefined;
|
|
17
|
+
exports.getRelayRequestConfig = getRelayRequestConfig;
|
|
@@ -232,6 +232,11 @@ const relayTokenToAssetId = (relayToken) => {
|
|
|
232
232
|
assetReference: caip_1.ASSET_REFERENCE.Abstract,
|
|
233
233
|
assetNamespace: caip_1.ASSET_NAMESPACE.slip44,
|
|
234
234
|
};
|
|
235
|
+
case caip_1.CHAIN_REFERENCE.RobinhoodMainnet:
|
|
236
|
+
return {
|
|
237
|
+
assetReference: caip_1.ASSET_REFERENCE.Robinhood,
|
|
238
|
+
assetNamespace: caip_1.ASSET_NAMESPACE.slip44,
|
|
239
|
+
};
|
|
235
240
|
default:
|
|
236
241
|
throw Error(`chainId '${relayToken.chainId}' not supported`);
|
|
237
242
|
}
|
|
@@ -11,11 +11,11 @@ export type RelayMetadata = {
|
|
|
11
11
|
data?: string;
|
|
12
12
|
};
|
|
13
13
|
export type RelayStatus = {
|
|
14
|
-
status: 'success' | '
|
|
14
|
+
status: 'success' | 'failure' | 'pending' | 'submitted' | 'depositing' | 'refund' | 'delayed' | 'waiting';
|
|
15
15
|
details?: string;
|
|
16
16
|
inTxHashes: string[];
|
|
17
17
|
txHashes: string[];
|
|
18
|
-
|
|
18
|
+
updatedAt: number;
|
|
19
19
|
originChainId: number;
|
|
20
20
|
destinationChainId: number;
|
|
21
21
|
};
|
|
@@ -100,6 +100,20 @@ exports.stonfiApi = {
|
|
|
100
100
|
}
|
|
101
101
|
};
|
|
102
102
|
const { quoteId } = (0, utils_1.getSwapMetadata)(swap.metadata.swapperMetadata, 'stonfi');
|
|
103
|
+
// Settlement precedes toncenter's jetton indexer, and confirmed rows are never re-parsed -
|
|
104
|
+
// hold confirmation until the receive leg is visible so the confirmed-time parse and upsert
|
|
105
|
+
// carries both legs of the swap
|
|
106
|
+
const hasVisibleReceiveLeg = async () => {
|
|
107
|
+
const adapter = assertGetTonChainAdapter(swap.sellAsset.chainId);
|
|
108
|
+
const sellAddress = swap.sellAccountId.split(':')[2] ?? '';
|
|
109
|
+
const addresses = new Set([sellAddress, swap.receiveAddress].filter((address) => Boolean(address)));
|
|
110
|
+
for (const address of addresses) {
|
|
111
|
+
const tx = await adapter.parseTx(sellTxHash, address);
|
|
112
|
+
if (tx.transfers.some(transfer => transfer.type === unchained_client_1.TransferType.Receive))
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
return false;
|
|
116
|
+
};
|
|
103
117
|
try {
|
|
104
118
|
const tradeStatus = await (0, helpers_1.waitForFirstTradeStatus)({
|
|
105
119
|
quoteId,
|
|
@@ -113,14 +127,13 @@ exports.stonfiApi = {
|
|
|
113
127
|
return checkTxStatusViaChainAdapter();
|
|
114
128
|
}
|
|
115
129
|
const statusOneOf = tradeStatus.status;
|
|
130
|
+
// While the trade is in flight the wallet tx may already be confirmed, but the payout leg
|
|
131
|
+
// hasn't landed - confirming here would parse and upsert a trace without the receive, so
|
|
132
|
+
// completion waits for settlement
|
|
116
133
|
if (statusOneOf.awaitingTransfer ||
|
|
117
134
|
statusOneOf.transferring ||
|
|
118
135
|
statusOneOf.swapping ||
|
|
119
136
|
statusOneOf.receivingFunds) {
|
|
120
|
-
const chainStatus = await checkTxStatusViaChainAdapter();
|
|
121
|
-
if (chainStatus.status === unchained_client_1.TxStatus.Confirmed) {
|
|
122
|
-
return chainStatus;
|
|
123
|
-
}
|
|
124
137
|
if (statusOneOf.awaitingTransfer) {
|
|
125
138
|
return {
|
|
126
139
|
status: unchained_client_1.TxStatus.Pending,
|
|
@@ -152,19 +165,32 @@ exports.stonfiApi = {
|
|
|
152
165
|
}
|
|
153
166
|
if (statusOneOf.tradeSettled) {
|
|
154
167
|
const result = statusOneOf.tradeSettled.result;
|
|
155
|
-
if (result === 'TRADE_RESULT_FULLY_FILLED') {
|
|
156
|
-
|
|
157
|
-
status: unchained_client_1.TxStatus.Confirmed,
|
|
158
|
-
buyTxHash: sellTxHash,
|
|
159
|
-
message: undefined,
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
if (result === 'TRADE_RESULT_PARTIALLY_FILLED') {
|
|
163
|
-
return {
|
|
168
|
+
if (result === 'TRADE_RESULT_FULLY_FILLED' || result === 'TRADE_RESULT_PARTIALLY_FILLED') {
|
|
169
|
+
const settled = {
|
|
164
170
|
status: unchained_client_1.TxStatus.Confirmed,
|
|
165
171
|
buyTxHash: sellTxHash,
|
|
166
|
-
message: '
|
|
172
|
+
message: result === 'TRADE_RESULT_PARTIALLY_FILLED'
|
|
173
|
+
? 'trade.statuses.partiallyFilled'
|
|
174
|
+
: undefined,
|
|
167
175
|
};
|
|
176
|
+
try {
|
|
177
|
+
if (await hasVisibleReceiveLeg())
|
|
178
|
+
return settled;
|
|
179
|
+
return {
|
|
180
|
+
status: unchained_client_1.TxStatus.Pending,
|
|
181
|
+
buyTxHash: undefined,
|
|
182
|
+
message: 'trade.statuses.receivingFunds',
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
catch (error) {
|
|
186
|
+
// Indexer/API failure must not block completion
|
|
187
|
+
console.error('[Stonfi] Error verifying settlement receive leg:', {
|
|
188
|
+
sellTxHash,
|
|
189
|
+
result,
|
|
190
|
+
error,
|
|
191
|
+
});
|
|
192
|
+
return settled;
|
|
193
|
+
}
|
|
168
194
|
}
|
|
169
195
|
if (result === 'TRADE_RESULT_ABORTED') {
|
|
170
196
|
return {
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getTradeQuote = void 0;
|
|
4
4
|
const monads_1 = require("@sniptt/monads");
|
|
5
5
|
const utils_1 = require("../../../utils");
|
|
6
|
+
const helpers_1 = require("../../../utils/helpers");
|
|
6
7
|
const getStonfiStepData_1 = require("../utils/getStonfiStepData");
|
|
7
8
|
const getStonfiTradeContext_1 = require("../utils/getStonfiTradeContext");
|
|
8
9
|
const getTradeQuote = async (input, deps) => {
|
|
@@ -27,6 +28,7 @@ const getTradeQuote = async (input, deps) => {
|
|
|
27
28
|
const tradeQuote = {
|
|
28
29
|
...tradeCommon,
|
|
29
30
|
quoteOrRate: 'quote',
|
|
31
|
+
deadline: (0, helpers_1.normalizeEpochToMs)(stonfiTransactionData.tradeStartDeadline),
|
|
30
32
|
receiveAddress,
|
|
31
33
|
steps: [
|
|
32
34
|
{
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getSunioTradeQuote = void 0;
|
|
4
4
|
const monads_1 = require("@sniptt/monads");
|
|
5
5
|
const utils_1 = require("../../../utils");
|
|
6
|
+
const helpers_1 = require("../../../utils/helpers");
|
|
6
7
|
const getSunioStepData_1 = require("../utils/getSunioStepData");
|
|
7
8
|
const getSunioTradeContext_1 = require("../utils/getSunioTradeContext");
|
|
8
9
|
const getSunioTradeQuote = async (input, deps) => {
|
|
@@ -27,6 +28,7 @@ const getSunioTradeQuote = async (input, deps) => {
|
|
|
27
28
|
const tradeQuote = {
|
|
28
29
|
...tradeCommon,
|
|
29
30
|
quoteOrRate: 'quote',
|
|
31
|
+
deadline: Date.now() + helpers_1.FALLBACK_QUOTE_DEADLINE_MS,
|
|
30
32
|
receiveAddress,
|
|
31
33
|
steps: [
|
|
32
34
|
{
|
|
@@ -64,6 +64,7 @@ const expectedQuoteResponse = [
|
|
|
64
64
|
tradeType: thorchain_1.TradeType.L1ToL1,
|
|
65
65
|
slippageTolerancePercentageDecimal: '0.04357',
|
|
66
66
|
expiry: 1713710808,
|
|
67
|
+
deadline: 1713710808000,
|
|
67
68
|
swapperName: types_1.SwapperName.Thorchain,
|
|
68
69
|
steps: [
|
|
69
70
|
{
|
|
@@ -114,6 +115,7 @@ const expectedQuoteResponse = [
|
|
|
114
115
|
tradeType: thorchain_1.TradeType.L1ToL1,
|
|
115
116
|
slippageTolerancePercentageDecimal: undefined,
|
|
116
117
|
expiry: 1713710808,
|
|
118
|
+
deadline: 1713710808000,
|
|
117
119
|
swapperName: types_1.SwapperName.Thorchain,
|
|
118
120
|
steps: [
|
|
119
121
|
{
|
|
@@ -76,6 +76,8 @@ const getLongtailToL1Quote = async (input, deps, streamingInterval, swapperName)
|
|
|
76
76
|
const { data, transactionData, networkFeeCryptoBaseUnit } = maybeStepData.unwrap();
|
|
77
77
|
return (0, monads_1.Ok)({
|
|
78
78
|
...quote,
|
|
79
|
+
// The aggregator swapIn deadline is tighter than the daemon quote expiry
|
|
80
|
+
deadline: Math.min(quote.deadline, Number(deadline) * 1000),
|
|
79
81
|
data: data ?? quote.data,
|
|
80
82
|
// This logic will need to be updated to support multi-hop, if that's ever implemented for THORChain
|
|
81
83
|
steps: quote.steps.map(s => ({
|
|
@@ -3,7 +3,7 @@ import type { Address, TypedData } from 'viem';
|
|
|
3
3
|
import type { GetEvmTradeQuoteInput, GetEvmTradeRateInput } from '../../types';
|
|
4
4
|
export type ZrxTradeQuoteInput = GetEvmTradeQuoteInput;
|
|
5
5
|
export type ZrxTradeRateInput = GetEvmTradeRateInput;
|
|
6
|
-
export declare const zrxSupportedChainIds: readonly [KnownChainIds.EthereumMainnet, KnownChainIds.AvalancheMainnet, KnownChainIds.OptimismMainnet, KnownChainIds.BnbSmartChainMainnet, KnownChainIds.PolygonMainnet, KnownChainIds.ArbitrumMainnet, KnownChainIds.BaseMainnet];
|
|
6
|
+
export declare const zrxSupportedChainIds: readonly [KnownChainIds.EthereumMainnet, KnownChainIds.AvalancheMainnet, KnownChainIds.OptimismMainnet, KnownChainIds.BnbSmartChainMainnet, KnownChainIds.PolygonMainnet, KnownChainIds.ArbitrumMainnet, KnownChainIds.BaseMainnet, KnownChainIds.RobinhoodMainnet];
|
|
7
7
|
export type ZrxSupportedChainId = (typeof zrxSupportedChainIds)[number];
|
|
8
8
|
type ZrxFee = {
|
|
9
9
|
amount: string;
|
|
@@ -21,6 +21,7 @@ exports.ZRX_SUPPORTED_CHAINIDS = Object.freeze([
|
|
|
21
21
|
types_1.KnownChainIds.PolygonMainnet,
|
|
22
22
|
types_1.KnownChainIds.ArbitrumMainnet,
|
|
23
23
|
types_1.KnownChainIds.BaseMainnet,
|
|
24
|
+
types_1.KnownChainIds.RobinhoodMainnet,
|
|
24
25
|
]);
|
|
25
26
|
// https://0x.org/docs/developer-resources/faqs-and-troubleshooting
|
|
26
27
|
exports.ZRX_NATIVE_ASSET_ADDRESS = '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE';
|
|
@@ -6,7 +6,7 @@ import type { SwapErrorRight } from '../../../types';
|
|
|
6
6
|
import type { ZrxFees, ZrxPriceResponse } from '../types';
|
|
7
7
|
export declare const assetIdToZrxToken: (assetId: AssetId) => string;
|
|
8
8
|
export declare const zrxTokenToAssetId: (token: string, chainId: ChainId) => AssetId;
|
|
9
|
-
export declare const isSupportedChainId: (chainId: ChainId) => chainId is KnownChainIds.EthereumMainnet | KnownChainIds.AvalancheMainnet | KnownChainIds.OptimismMainnet | KnownChainIds.BnbSmartChainMainnet | KnownChainIds.PolygonMainnet | KnownChainIds.ArbitrumMainnet | KnownChainIds.BaseMainnet;
|
|
9
|
+
export declare const isSupportedChainId: (chainId: ChainId) => chainId is KnownChainIds.EthereumMainnet | KnownChainIds.AvalancheMainnet | KnownChainIds.OptimismMainnet | KnownChainIds.BnbSmartChainMainnet | KnownChainIds.PolygonMainnet | KnownChainIds.ArbitrumMainnet | KnownChainIds.BaseMainnet | KnownChainIds.RobinhoodMainnet;
|
|
10
10
|
export declare const isWrappedNativeSell: (route: ZrxPriceResponse['route']) => boolean;
|
|
11
11
|
export declare const assertValidTrade: ({ buyAsset, sellAsset, }: {
|
|
12
12
|
buyAsset: Asset;
|
|
@@ -60,6 +60,11 @@ const zrxTokenToAssetId = (token, chainId) => {
|
|
|
60
60
|
assetReference: caip_1.ASSET_REFERENCE.Base,
|
|
61
61
|
assetNamespace: caip_1.ASSET_NAMESPACE.slip44,
|
|
62
62
|
};
|
|
63
|
+
case types_1.KnownChainIds.RobinhoodMainnet:
|
|
64
|
+
return {
|
|
65
|
+
assetReference: caip_1.ASSET_REFERENCE.Robinhood,
|
|
66
|
+
assetNamespace: caip_1.ASSET_NAMESPACE.slip44,
|
|
67
|
+
};
|
|
63
68
|
default:
|
|
64
69
|
throw Error(`chainId '${chainId}' not supported`);
|
|
65
70
|
}
|
package/dist/cjs/types.d.ts
CHANGED
|
@@ -49,11 +49,13 @@ export type SwapperConfig = {
|
|
|
49
49
|
VITE_CHAINFLIP_API_URL: string;
|
|
50
50
|
VITE_FEATURE_CHAINFLIP_SWAP_DCA: boolean;
|
|
51
51
|
VITE_RELAY_API_URL: string;
|
|
52
|
+
VITE_RELAY_API_KEY: string;
|
|
52
53
|
VITE_BEBOP_API_KEY: string;
|
|
53
54
|
VITE_NEAR_INTENTS_API_KEY: string;
|
|
54
55
|
VITE_SUI_NODE_URL: string;
|
|
55
56
|
VITE_ACROSS_API_URL: string;
|
|
56
57
|
VITE_ACROSS_INTEGRATOR_ID: string;
|
|
58
|
+
VITE_ACROSS_API_KEY: string;
|
|
57
59
|
VITE_DEBRIDGE_API_URL: string;
|
|
58
60
|
VITE_BOB_GATEWAY_API_KEY: string;
|
|
59
61
|
};
|
|
@@ -439,6 +441,7 @@ export type TradeQuote = TradeQuoteBase & {
|
|
|
439
441
|
} & {
|
|
440
442
|
quoteOrRate: 'quote';
|
|
441
443
|
receiveAddress: string;
|
|
444
|
+
deadline: number;
|
|
442
445
|
};
|
|
443
446
|
export type MultiHopTradeQuote = TradeQuote & {
|
|
444
447
|
steps: MultiHopTradeQuoteSteps;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import type { AssetId, ChainId } from '@shapeshiftoss/caip';
|
|
2
|
+
export declare const FALLBACK_QUOTE_DEADLINE_MS = 60000;
|
|
3
|
+
export declare const normalizeEpochToMs: (value: number) => number;
|
|
2
4
|
export declare const isNativeEvmAsset: (assetId: AssetId) => boolean;
|
|
3
5
|
export declare const getTreasuryAddressFromChainId: (chainId: ChainId) => string;
|
|
@@ -1,9 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getTreasuryAddressFromChainId = exports.isNativeEvmAsset = void 0;
|
|
3
|
+
exports.getTreasuryAddressFromChainId = exports.isNativeEvmAsset = exports.normalizeEpochToMs = exports.FALLBACK_QUOTE_DEADLINE_MS = void 0;
|
|
4
4
|
const caip_1 = require("@shapeshiftoss/caip");
|
|
5
5
|
const types_1 = require("@shapeshiftoss/types");
|
|
6
6
|
const utils_1 = require("@shapeshiftoss/utils");
|
|
7
|
+
// Deadline for providers without their own expiry - short enough to keep priced amounts honest
|
|
8
|
+
exports.FALLBACK_QUOTE_DEADLINE_MS = 60_000;
|
|
9
|
+
// Bands are unambiguous for any realistic date: unix s land ~2e9, ms ~2e12, µs ~2e15, ns ~2e18
|
|
10
|
+
const normalizeEpochToMs = (value) => {
|
|
11
|
+
if (value < 1e12)
|
|
12
|
+
return value * 1000;
|
|
13
|
+
if (value < 1e15)
|
|
14
|
+
return value;
|
|
15
|
+
if (value < 1e18)
|
|
16
|
+
return Math.floor(value / 1000);
|
|
17
|
+
return Math.floor(value / 1e6);
|
|
18
|
+
};
|
|
19
|
+
exports.normalizeEpochToMs = normalizeEpochToMs;
|
|
7
20
|
const isNativeEvmAsset = (assetId) => {
|
|
8
21
|
const { chainId } = (0, caip_1.fromAssetId)(assetId);
|
|
9
22
|
switch (chainId) {
|
|
@@ -32,3 +32,20 @@ const helpers_1 = require("./helpers");
|
|
|
32
32
|
(0, vitest_1.expect)(() => (0, helpers_1.getTreasuryAddressFromChainId)(caip_1.thorchainChainId)).toThrow('[getTreasuryAddressFromChainId] - Unsupported chainId');
|
|
33
33
|
});
|
|
34
34
|
});
|
|
35
|
+
(0, vitest_1.describe)('normalizeEpochToMs', () => {
|
|
36
|
+
// 2026-08-05T00:00:00Z expressed in each unit
|
|
37
|
+
const epochS = 1785888000;
|
|
38
|
+
const epochMs = epochS * 1000;
|
|
39
|
+
(0, vitest_1.it)('converts unix seconds to ms', () => {
|
|
40
|
+
(0, vitest_1.expect)((0, helpers_1.normalizeEpochToMs)(epochS)).toBe(epochMs);
|
|
41
|
+
});
|
|
42
|
+
(0, vitest_1.it)('passes milliseconds through', () => {
|
|
43
|
+
(0, vitest_1.expect)((0, helpers_1.normalizeEpochToMs)(epochMs)).toBe(epochMs);
|
|
44
|
+
});
|
|
45
|
+
(0, vitest_1.it)('converts microseconds to ms', () => {
|
|
46
|
+
(0, vitest_1.expect)((0, helpers_1.normalizeEpochToMs)(epochMs * 1000)).toBe(epochMs);
|
|
47
|
+
});
|
|
48
|
+
(0, vitest_1.it)('converts nanoseconds to ms', () => {
|
|
49
|
+
(0, vitest_1.expect)((0, helpers_1.normalizeEpochToMs)(epochMs * 1e6)).toBe(epochMs);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getThorL1TradeQuote = void 0;
|
|
4
4
|
const monads_1 = require("@sniptt/monads");
|
|
5
5
|
const utils_1 = require("../../utils");
|
|
6
|
+
const helpers_1 = require("../helpers");
|
|
6
7
|
const getLimitWithManualSlippage_1 = require("./getLimitWithManualSlippage/getLimitWithManualSlippage");
|
|
7
8
|
const getThorL1TradeContexts_1 = require("./getThorL1TradeContexts");
|
|
8
9
|
const getThorStepData_1 = require("./getThorStepData");
|
|
@@ -53,6 +54,8 @@ const getThorL1TradeQuote = async (input, deps, streamingInterval, tradeType, sw
|
|
|
53
54
|
const quote = {
|
|
54
55
|
...tradeCommon,
|
|
55
56
|
quoteOrRate: 'quote',
|
|
57
|
+
// The daemon quote expiry scopes the inbound address - sending later risks a rotated vault
|
|
58
|
+
deadline: (0, helpers_1.normalizeEpochToMs)(tradeCommon.expiry),
|
|
56
59
|
memo,
|
|
57
60
|
receiveAddress,
|
|
58
61
|
data,
|