@vultisig/core-chain 4.1.1 → 5.1.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/CHANGELOG.md +90 -0
- package/dist/Chain.d.ts +0 -4
- package/dist/Chain.d.ts.map +1 -1
- package/dist/Chain.js +0 -1
- package/dist/Chain.js.map +1 -1
- package/dist/ChainKind.d.ts +0 -1
- package/dist/ChainKind.d.ts.map +1 -1
- package/dist/ChainKind.js +0 -1
- package/dist/ChainKind.js.map +1 -1
- package/dist/chainRegistry.d.ts +0 -1
- package/dist/chainRegistry.d.ts.map +1 -1
- package/dist/chainRegistry.js +0 -1
- package/dist/chainRegistry.js.map +1 -1
- package/dist/chains/cosmos/account/getCosmosAccountInfo.d.ts.map +1 -1
- package/dist/chains/cosmos/account/getCosmosAccountInfo.js +0 -5
- package/dist/chains/cosmos/account/getCosmosAccountInfo.js.map +1 -1
- package/dist/chains/cosmos/chainInfo.d.ts.map +1 -1
- package/dist/chains/cosmos/chainInfo.js +0 -1
- package/dist/chains/cosmos/chainInfo.js.map +1 -1
- package/dist/chains/cosmos/cosmosFeeCoinDenom.d.ts.map +1 -1
- package/dist/chains/cosmos/cosmosFeeCoinDenom.js +0 -1
- package/dist/chains/cosmos/cosmosFeeCoinDenom.js.map +1 -1
- package/dist/chains/cosmos/cosmosGasLimitRecord.d.ts.map +1 -1
- package/dist/chains/cosmos/cosmosGasLimitRecord.js +0 -2
- package/dist/chains/cosmos/cosmosGasLimitRecord.js.map +1 -1
- package/dist/chains/cosmos/cosmosMemoCap.d.ts.map +1 -1
- package/dist/chains/cosmos/cosmosMemoCap.js +0 -1
- package/dist/chains/cosmos/cosmosMemoCap.js.map +1 -1
- package/dist/chains/cosmos/cosmosRpcUrl.d.ts.map +1 -1
- package/dist/chains/cosmos/cosmosRpcUrl.js +0 -3
- package/dist/chains/cosmos/cosmosRpcUrl.js.map +1 -1
- package/dist/chains/cosmos/gas.d.ts.map +1 -1
- package/dist/chains/cosmos/gas.js +0 -1
- package/dist/chains/cosmos/gas.js.map +1 -1
- package/dist/chains/cosmos/tendermintRpcUrl.d.ts.map +1 -1
- package/dist/chains/cosmos/tendermintRpcUrl.js +0 -1
- package/dist/chains/cosmos/tendermintRpcUrl.js.map +1 -1
- package/dist/chains/cosmos/thor/thorchainLp.d.ts.map +1 -1
- package/dist/chains/cosmos/thor/thorchainLp.js +0 -1
- package/dist/chains/cosmos/thor/thorchainLp.js.map +1 -1
- package/dist/chains/ripple/issuedCurrency.d.ts +13 -3
- package/dist/chains/ripple/issuedCurrency.d.ts.map +1 -1
- package/dist/chains/ripple/issuedCurrency.js +65 -6
- package/dist/chains/ripple/issuedCurrency.js.map +1 -1
- package/dist/chains/ripple/trustLine.d.ts +22 -0
- package/dist/chains/ripple/trustLine.d.ts.map +1 -0
- package/dist/chains/ripple/trustLine.js +14 -0
- package/dist/chains/ripple/trustLine.js.map +1 -0
- package/dist/chains/ton/address.d.ts +32 -0
- package/dist/chains/ton/address.d.ts.map +1 -1
- package/dist/chains/ton/address.js +45 -0
- package/dist/chains/ton/address.js.map +1 -1
- package/dist/chains/ton/api.d.ts +49 -0
- package/dist/chains/ton/api.d.ts.map +1 -1
- package/dist/chains/ton/api.js +131 -24
- package/dist/chains/ton/api.js.map +1 -1
- package/dist/chains/ton/comment.d.ts +51 -0
- package/dist/chains/ton/comment.d.ts.map +1 -0
- package/dist/chains/ton/comment.js +75 -0
- package/dist/chains/ton/comment.js.map +1 -0
- package/dist/chains/ton/jetton/symbol.d.ts +9 -0
- package/dist/chains/ton/jetton/symbol.d.ts.map +1 -0
- package/dist/chains/ton/jetton/symbol.js +61 -0
- package/dist/chains/ton/jetton/symbol.js.map +1 -0
- package/dist/chains/ton/jetton/verification.d.ts +35 -0
- package/dist/chains/ton/jetton/verification.d.ts.map +1 -0
- package/dist/chains/ton/jetton/verification.js +45 -0
- package/dist/chains/ton/jetton/verification.js.map +1 -0
- package/dist/chains/ton/jetton/verifiedRegistry.d.ts +43 -0
- package/dist/chains/ton/jetton/verifiedRegistry.d.ts.map +1 -0
- package/dist/chains/ton/jetton/verifiedRegistry.js +94 -0
- package/dist/chains/ton/jetton/verifiedRegistry.js.map +1 -0
- package/dist/chains/ton/messageBounce.d.ts +17 -0
- package/dist/chains/ton/messageBounce.d.ts.map +1 -0
- package/dist/chains/ton/messageBounce.js +41 -0
- package/dist/chains/ton/messageBounce.js.map +1 -0
- package/dist/chains/tron/getTronBlockInfo.d.ts.map +1 -1
- package/dist/chains/tron/getTronBlockInfo.js +4 -5
- package/dist/chains/tron/getTronBlockInfo.js.map +1 -1
- package/dist/coin/balance/resolvers/ripple.d.ts.map +1 -1
- package/dist/coin/balance/resolvers/ripple.js +3 -2
- package/dist/coin/balance/resolvers/ripple.js.map +1 -1
- package/dist/coin/chainFeeCoin.d.ts.map +1 -1
- package/dist/coin/chainFeeCoin.js +0 -5
- package/dist/coin/chainFeeCoin.js.map +1 -1
- package/dist/coin/coinType.d.ts.map +1 -1
- package/dist/coin/coinType.js +0 -1
- package/dist/coin/coinType.js.map +1 -1
- package/dist/coin/find/CoinFinderChainKind.d.ts +1 -1
- package/dist/coin/find/CoinFinderChainKind.d.ts.map +1 -1
- package/dist/coin/find/CoinFinderChainKind.js +1 -1
- package/dist/coin/find/CoinFinderChainKind.js.map +1 -1
- package/dist/coin/find/index.d.ts.map +1 -1
- package/dist/coin/find/index.js +2 -0
- package/dist/coin/find/index.js.map +1 -1
- package/dist/coin/find/resolvers/ton.d.ts +15 -0
- package/dist/coin/find/resolvers/ton.d.ts.map +1 -0
- package/dist/coin/find/resolvers/ton.js +61 -0
- package/dist/coin/find/resolvers/ton.js.map +1 -0
- package/dist/coin/knownTokens/cosmos.d.ts.map +1 -1
- package/dist/coin/knownTokens/cosmos.js +0 -64
- package/dist/coin/knownTokens/cosmos.js.map +1 -1
- package/dist/coin/knownTokens/index.d.ts +1 -1
- package/dist/coin/knownTokens/index.d.ts.map +1 -1
- package/dist/coin/token/metadata/chains.d.ts +1 -1
- package/dist/coin/token/metadata/chains.d.ts.map +1 -1
- package/dist/coin/tokenVerification.d.ts +13 -0
- package/dist/coin/tokenVerification.d.ts.map +1 -0
- package/dist/coin/tokenVerification.js +12 -0
- package/dist/coin/tokenVerification.js.map +1 -0
- package/dist/swap/general/swapkit/SwapKitEnabledChains.d.ts +14 -3
- package/dist/swap/general/swapkit/SwapKitEnabledChains.d.ts.map +1 -1
- package/dist/swap/general/swapkit/SwapKitEnabledChains.js +14 -1
- package/dist/swap/general/swapkit/SwapKitEnabledChains.js.map +1 -1
- package/dist/swap/general/swapkit/SwapKitProviders.d.ts +19 -3
- package/dist/swap/general/swapkit/SwapKitProviders.d.ts.map +1 -1
- package/dist/swap/general/swapkit/SwapKitProviders.js +161 -8
- package/dist/swap/general/swapkit/SwapKitProviders.js.map +1 -1
- package/dist/swap/general/swapkit/api/getSwapKitQuote.d.ts +1 -3
- package/dist/swap/general/swapkit/api/getSwapKitQuote.d.ts.map +1 -1
- package/dist/swap/general/swapkit/api/getSwapKitQuote.js +148 -78
- package/dist/swap/general/swapkit/api/getSwapKitQuote.js.map +1 -1
- package/dist/swap/general/swapkit/getSwapKitTrackerUrl.d.ts +2 -1
- package/dist/swap/general/swapkit/getSwapKitTrackerUrl.d.ts.map +1 -1
- package/dist/swap/general/swapkit/getSwapKitTrackerUrl.js +2 -1
- package/dist/swap/general/swapkit/getSwapKitTrackerUrl.js.map +1 -1
- package/dist/swap/native/NativeSwapChain.d.ts +1 -2
- package/dist/swap/native/NativeSwapChain.d.ts.map +1 -1
- package/dist/swap/native/NativeSwapChain.js +0 -2
- package/dist/swap/native/NativeSwapChain.js.map +1 -1
- package/dist/swap/native/limitSwapMemo.d.ts.map +1 -1
- package/dist/swap/native/limitSwapMemo.js +18 -5
- package/dist/swap/native/limitSwapMemo.js.map +1 -1
- package/dist/swap/native/thorchainMemoAsset.d.ts +1 -1
- package/dist/swap/native/thorchainMemoAsset.js +1 -1
- package/dist/swap/quote/findSwapQuote.d.ts.map +1 -1
- package/dist/swap/quote/findSwapQuote.js +2 -2
- package/dist/swap/quote/findSwapQuote.js.map +1 -1
- package/dist/swap/skip/skipRouting.d.ts.map +1 -1
- package/dist/swap/skip/skipRouting.js +0 -1
- package/dist/swap/skip/skipRouting.js.map +1 -1
- package/dist/swap/swapEnabledChains.d.ts +1 -1
- package/dist/swap/swapEnabledChains.d.ts.map +1 -1
- package/dist/tx/broadcast/resolvers/tron.d.ts.map +1 -1
- package/dist/tx/broadcast/resolvers/tron.js +6 -1
- package/dist/tx/broadcast/resolvers/tron.js.map +1 -1
- package/dist/tx/broadcast/verifyBroadcastByHash.js +1 -1
- package/dist/tx/broadcast/verifyBroadcastByHash.js.map +1 -1
- package/dist/tx/status/resolver.d.ts +9 -1
- package/dist/tx/status/resolver.d.ts.map +1 -1
- package/dist/tx/status/resolvers/ripple.d.ts.map +1 -1
- package/dist/tx/status/resolvers/ripple.js +62 -0
- package/dist/tx/status/resolvers/ripple.js.map +1 -1
- package/dist/tx/status/resolvers/tron.d.ts.map +1 -1
- package/dist/tx/status/resolvers/tron.js +18 -2
- package/dist/tx/status/resolvers/tron.js.map +1 -1
- package/package.json +41 -1
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { Chain } from '@vultisig/core-chain/Chain';
|
|
2
|
+
import { isChainOfKind } from '@vultisig/core-chain/ChainKind';
|
|
3
|
+
import { getEvmNumericChainId } from '@vultisig/core-chain/chains/evm/chainInfo';
|
|
2
4
|
import { getSwapKitConfig } from '@vultisig/core-chain/swap/general/swapkit/config';
|
|
3
5
|
import { attempt } from '@vultisig/lib-utils/attempt';
|
|
4
6
|
/**
|
|
@@ -13,6 +15,26 @@ export const swapKitExcludedProviders = new Set([
|
|
|
13
15
|
'MAYACHAIN_STREAMING',
|
|
14
16
|
]);
|
|
15
17
|
export const normalizeSwapKitProvider = (provider) => provider.trim().toUpperCase().replace(/[-\s]/g, '_');
|
|
18
|
+
export const swapKitAllowedProviders = [
|
|
19
|
+
'CHAINFLIP',
|
|
20
|
+
'CHAINFLIP_STREAMING',
|
|
21
|
+
'NEAR',
|
|
22
|
+
'GARDEN',
|
|
23
|
+
'FLASHNET',
|
|
24
|
+
'HARBOR',
|
|
25
|
+
'ONEINCH',
|
|
26
|
+
'UNISWAP_V2',
|
|
27
|
+
'UNISWAP_V3',
|
|
28
|
+
'JUPITER',
|
|
29
|
+
'OKX',
|
|
30
|
+
'PANCAKESWAP',
|
|
31
|
+
'SUSHISWAP_V2',
|
|
32
|
+
'TRADERJOE_V2',
|
|
33
|
+
'PANGOLIN_V1',
|
|
34
|
+
'CAMELOT_V3',
|
|
35
|
+
'OPENOCEAN_V2',
|
|
36
|
+
];
|
|
37
|
+
const swapKitAllowedProviderNames = new Set(swapKitAllowedProviders);
|
|
16
38
|
/**
|
|
17
39
|
* Chain → SwapKit `enabledChainIds` token as returned by `/providers`. EVM chains
|
|
18
40
|
* use their numeric EVM chain id; non-EVM chains use SwapKit's named id. This is a
|
|
@@ -26,6 +48,8 @@ const swapKitProviderChainId = {
|
|
|
26
48
|
[Chain.BSC]: '56',
|
|
27
49
|
[Chain.Optimism]: '10',
|
|
28
50
|
[Chain.Polygon]: '137',
|
|
51
|
+
[Chain.Hyperliquid]: '999',
|
|
52
|
+
[Chain.Robinhood]: '4663',
|
|
29
53
|
[Chain.Solana]: 'solana',
|
|
30
54
|
[Chain.Bitcoin]: 'bitcoin',
|
|
31
55
|
[Chain.BitcoinCash]: 'bitcoincash',
|
|
@@ -38,20 +62,47 @@ const swapKitProviderChainId = {
|
|
|
38
62
|
[Chain.Cardano]: 'cardano',
|
|
39
63
|
[Chain.Cosmos]: 'cosmos',
|
|
40
64
|
[Chain.Dash]: 'dash',
|
|
41
|
-
[Chain.Kujira]: 'kaiyo-1',
|
|
42
65
|
[Chain.MayaChain]: 'mayachain-mainnet-v1',
|
|
43
66
|
[Chain.Sui]: 'sui',
|
|
44
67
|
[Chain.THORChain]: 'thorchain-1',
|
|
45
68
|
};
|
|
69
|
+
const swapKitAssetPrefix = {
|
|
70
|
+
[Chain.Arbitrum]: 'ARB',
|
|
71
|
+
[Chain.Avalanche]: 'AVAX',
|
|
72
|
+
[Chain.Base]: 'BASE',
|
|
73
|
+
[Chain.Bitcoin]: 'BTC',
|
|
74
|
+
[Chain.BitcoinCash]: 'BCH',
|
|
75
|
+
[Chain.BSC]: 'BSC',
|
|
76
|
+
[Chain.Cardano]: 'ADA',
|
|
77
|
+
[Chain.Cosmos]: 'GAIA',
|
|
78
|
+
[Chain.Dash]: 'DASH',
|
|
79
|
+
[Chain.Dogecoin]: 'DOGE',
|
|
80
|
+
[Chain.Ethereum]: 'ETH',
|
|
81
|
+
[Chain.Hyperliquid]: 'HYPEREVM',
|
|
82
|
+
[Chain.Litecoin]: 'LTC',
|
|
83
|
+
[Chain.MayaChain]: 'MAYA',
|
|
84
|
+
[Chain.Optimism]: 'OP',
|
|
85
|
+
[Chain.Polygon]: 'POL',
|
|
86
|
+
[Chain.Ripple]: 'XRP',
|
|
87
|
+
[Chain.Robinhood]: 'HOOD',
|
|
88
|
+
[Chain.Solana]: 'SOL',
|
|
89
|
+
[Chain.Sui]: 'SUI',
|
|
90
|
+
[Chain.THORChain]: 'THOR',
|
|
91
|
+
[Chain.Ton]: 'TON',
|
|
92
|
+
[Chain.Tron]: 'TRON',
|
|
93
|
+
[Chain.Zcash]: 'ZEC',
|
|
94
|
+
};
|
|
46
95
|
const PROVIDERS_CACHE_TTL_MS = 10 * 60 * 1000;
|
|
47
96
|
// Short timeout so a stalled /providers call fails open fast instead of dragging
|
|
48
97
|
// out the no-route classification path (the outer findSwapQuote per-fetcher
|
|
49
98
|
// timeout would also catch it, but much later).
|
|
50
99
|
const PROVIDERS_FETCH_TIMEOUT_MS = 5_000;
|
|
51
100
|
let providersCache = null;
|
|
101
|
+
const tokensCache = new Map();
|
|
52
102
|
/** Test-only: clear the in-memory `/providers` snapshot. */
|
|
53
103
|
export const resetSwapKitProvidersCache = () => {
|
|
54
104
|
providersCache = null;
|
|
105
|
+
tokensCache.clear();
|
|
55
106
|
};
|
|
56
107
|
const parseProviders = (data) => {
|
|
57
108
|
const list = Array.isArray(data) ? data : [];
|
|
@@ -59,18 +110,117 @@ const parseProviders = (data) => {
|
|
|
59
110
|
if (typeof entry !== 'object' || entry === null) {
|
|
60
111
|
return [];
|
|
61
112
|
}
|
|
62
|
-
const { provider, enabledChainIds } = entry;
|
|
63
|
-
|
|
113
|
+
const { provider, enabledChainIds, supportedChainIds } = entry;
|
|
114
|
+
const chainIds = Array.isArray(enabledChainIds) ? enabledChainIds : supportedChainIds;
|
|
115
|
+
if (typeof provider !== 'string' || !Array.isArray(chainIds)) {
|
|
64
116
|
return [];
|
|
65
117
|
}
|
|
66
118
|
return [
|
|
67
119
|
{
|
|
68
120
|
provider,
|
|
69
|
-
enabledChainIds:
|
|
121
|
+
enabledChainIds: chainIds.flatMap(id => (typeof id === 'string' || typeof id === 'number' ? [String(id)] : [])),
|
|
70
122
|
},
|
|
71
123
|
];
|
|
72
124
|
});
|
|
73
125
|
};
|
|
126
|
+
const parseTokens = (data) => {
|
|
127
|
+
if (typeof data !== 'object' || data === null || !Array.isArray(data.tokens)) {
|
|
128
|
+
return [];
|
|
129
|
+
}
|
|
130
|
+
return data.tokens.flatMap(entry => {
|
|
131
|
+
if (typeof entry !== 'object' || entry === null) {
|
|
132
|
+
return [];
|
|
133
|
+
}
|
|
134
|
+
const { chain, chainId } = entry;
|
|
135
|
+
if (typeof chain !== 'string' || (typeof chainId !== 'string' && typeof chainId !== 'number')) {
|
|
136
|
+
return [];
|
|
137
|
+
}
|
|
138
|
+
return [{ chain, chainId: String(chainId) }];
|
|
139
|
+
});
|
|
140
|
+
};
|
|
141
|
+
const getSwapKitTokens = async (provider) => {
|
|
142
|
+
const { apiKey, baseUrl } = getSwapKitConfig();
|
|
143
|
+
const cacheKey = `${baseUrl}\u0000${provider}`;
|
|
144
|
+
const cached = tokensCache.get(cacheKey);
|
|
145
|
+
if (cached && Date.now() - cached.fetchedAt < PROVIDERS_CACHE_TTL_MS) {
|
|
146
|
+
return cached.tokens;
|
|
147
|
+
}
|
|
148
|
+
const trimmedApiKey = apiKey?.trim();
|
|
149
|
+
const result = await attempt(async () => {
|
|
150
|
+
const controller = new AbortController();
|
|
151
|
+
const timeoutId = setTimeout(() => controller.abort(), PROVIDERS_FETCH_TIMEOUT_MS);
|
|
152
|
+
try {
|
|
153
|
+
const url = `${baseUrl.replace(/\/$/, '')}/tokens?provider=${encodeURIComponent(provider)}`;
|
|
154
|
+
const response = await fetch(url, {
|
|
155
|
+
headers: trimmedApiKey ? { 'x-api-key': trimmedApiKey } : {},
|
|
156
|
+
signal: controller.signal,
|
|
157
|
+
});
|
|
158
|
+
if (!response.ok) {
|
|
159
|
+
throw new Error(`SwapKit tokens request failed (${response.status})`);
|
|
160
|
+
}
|
|
161
|
+
return parseTokens(await response.json());
|
|
162
|
+
}
|
|
163
|
+
finally {
|
|
164
|
+
clearTimeout(timeoutId);
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
if ('error' in result) {
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
tokensCache.set(cacheKey, {
|
|
171
|
+
baseUrl,
|
|
172
|
+
provider,
|
|
173
|
+
tokens: result.data,
|
|
174
|
+
fetchedAt: Date.now(),
|
|
175
|
+
});
|
|
176
|
+
return result.data;
|
|
177
|
+
};
|
|
178
|
+
const getSwapKitProviderChainId = (chain) => {
|
|
179
|
+
const configured = swapKitProviderChainId[chain];
|
|
180
|
+
if (configured) {
|
|
181
|
+
return configured;
|
|
182
|
+
}
|
|
183
|
+
return isChainOfKind(chain, 'evm') ? String(getEvmNumericChainId(chain)) : undefined;
|
|
184
|
+
};
|
|
185
|
+
/**
|
|
186
|
+
* Resolve the two distinct identifiers SwapKit needs for a chain. Shipping
|
|
187
|
+
* legacy chains retain their stable prefix, while newly opened EVM corridors
|
|
188
|
+
* must be present in the current provider catalog and agree on one asset
|
|
189
|
+
* prefix across every quote provider that advertises the canonical EIP-155 id.
|
|
190
|
+
* Missing, partially unavailable, or ambiguous catalog data fails closed for
|
|
191
|
+
* SwapKit only.
|
|
192
|
+
*/
|
|
193
|
+
export const resolveSwapKitChainMetadata = async (chain) => {
|
|
194
|
+
const providerChainId = getSwapKitProviderChainId(chain);
|
|
195
|
+
if (!providerChainId) {
|
|
196
|
+
return undefined;
|
|
197
|
+
}
|
|
198
|
+
const knownPrefix = swapKitAssetPrefix[chain];
|
|
199
|
+
if (knownPrefix) {
|
|
200
|
+
return { assetPrefix: knownPrefix, providerChainId };
|
|
201
|
+
}
|
|
202
|
+
const providers = (await getSwapKitProviders()).filter(({ provider, enabledChainIds }) => swapKitAllowedProviderNames.has(normalizeSwapKitProvider(provider)) && enabledChainIds.includes(providerChainId));
|
|
203
|
+
if (providers.length === 0) {
|
|
204
|
+
return undefined;
|
|
205
|
+
}
|
|
206
|
+
const tokenLists = await Promise.all(providers.map(({ provider }) => getSwapKitTokens(provider)));
|
|
207
|
+
if (tokenLists.some(tokens => tokens === null)) {
|
|
208
|
+
return undefined;
|
|
209
|
+
}
|
|
210
|
+
const providerPrefixes = tokenLists.map(tokens => new Set((tokens ?? []).filter(token => token.chainId === providerChainId).map(token => token.chain.trim().toUpperCase())));
|
|
211
|
+
if (providerPrefixes.some(prefixes => prefixes.size !== 1)) {
|
|
212
|
+
return undefined;
|
|
213
|
+
}
|
|
214
|
+
const prefixes = new Set(providerPrefixes.flatMap(prefixes => [...prefixes]));
|
|
215
|
+
if (prefixes.size !== 1) {
|
|
216
|
+
return undefined;
|
|
217
|
+
}
|
|
218
|
+
const [assetPrefix] = prefixes;
|
|
219
|
+
if (!assetPrefix || (knownPrefix && assetPrefix !== knownPrefix)) {
|
|
220
|
+
return undefined;
|
|
221
|
+
}
|
|
222
|
+
return { assetPrefix, providerChainId };
|
|
223
|
+
};
|
|
74
224
|
/**
|
|
75
225
|
* Fetches and caches SwapKit's `/providers` snapshot. The snapshot rarely changes
|
|
76
226
|
* and is only needed on the unhappy path, so a coarse TTL is enough. On any
|
|
@@ -110,7 +260,7 @@ export const getSwapKitProviders = async () => {
|
|
|
110
260
|
/**
|
|
111
261
|
* SwapKit collapses "amount below provider minimum" and "pair not supported" into
|
|
112
262
|
* the same `noRoutesFound` 404, so the envelope alone can't disambiguate them.
|
|
113
|
-
* Cross-check the cached `/providers` snapshot: if a single
|
|
263
|
+
* Cross-check the cached `/providers` snapshot: if a single quote-allowlisted provider
|
|
114
264
|
* enables BOTH chains, the pair is structurally supported, so a no-route result
|
|
115
265
|
* must be amount-related. Mirrors vultisig-ios #4418.
|
|
116
266
|
*
|
|
@@ -125,9 +275,12 @@ export const isSwapKitPairSupported = async ({ from, to, }) => {
|
|
|
125
275
|
if (providers.length === 0) {
|
|
126
276
|
return true;
|
|
127
277
|
}
|
|
128
|
-
const fromId =
|
|
129
|
-
const toId =
|
|
130
|
-
|
|
278
|
+
const fromId = getSwapKitProviderChainId(from);
|
|
279
|
+
const toId = getSwapKitProviderChainId(to);
|
|
280
|
+
if (!fromId || !toId) {
|
|
281
|
+
return false;
|
|
282
|
+
}
|
|
283
|
+
return providers.some(({ provider, enabledChainIds }) => swapKitAllowedProviderNames.has(normalizeSwapKitProvider(provider)) &&
|
|
131
284
|
enabledChainIds.includes(fromId) &&
|
|
132
285
|
enabledChainIds.includes(toId));
|
|
133
286
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SwapKitProviders.js","sourceRoot":"","sources":["../../../../../../../packages/core/chain/swap/general/swapkit/SwapKitProviders.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"SwapKitProviders.js","sourceRoot":"","sources":["../../../../../../../packages/core/chain/swap/general/swapkit/SwapKitProviders.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAY,MAAM,4BAA4B,CAAA;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAA;AAC9D,OAAO,EAAE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AAI,CACnB,CAAC,EAAE,QAAQ,EAAE,eAAe,EAAE,EAAE,EAAE,CAChC,2BAA2B,CAAC,GAAG,CAAC,wBAAwB,CAAC,QAAQ,CAAC,CAAC;QACnE,eAAe,CAAC,QAAQ,CAAC,MAAM,CAAC;QAChC,eAAe,CAAC,QAAQ,CAAC,IAAI,CAAC,CACjC,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { AccountCoin } from '@vultisig/core-chain/coin/AccountCoin';
|
|
2
2
|
import { GeneralSwapQuote } from '@vultisig/core-chain/swap/general/GeneralSwapQuote';
|
|
3
|
-
import { SwapKitEnabledChain, SwapKitSourceChain } from '@vultisig/core-chain/swap/general/swapkit/SwapKitEnabledChains';
|
|
4
3
|
import { TransferDirection } from '@vultisig/lib-utils/TransferDirection';
|
|
5
|
-
type Input = Record<TransferDirection, AccountCoin
|
|
6
|
-
from: AccountCoin<SwapKitSourceChain>;
|
|
4
|
+
type Input = Record<TransferDirection, AccountCoin> & {
|
|
7
5
|
amount: bigint;
|
|
8
6
|
affiliateBps?: number;
|
|
9
7
|
/** Slippage tolerance in percent (e.g. 1 = 1%). Defaults to 3. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getSwapKitQuote.d.ts","sourceRoot":"","sources":["../../../../../../../../packages/core/chain/swap/general/swapkit/api/getSwapKitQuote.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getSwapKitQuote.d.ts","sourceRoot":"","sources":["../../../../../../../../packages/core/chain/swap/general/swapkit/api/getSwapKitQuote.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,WAAW,EAAE,MAAM,uCAAuC,CAAA;AAGnE,OAAO,EAAE,gBAAgB,EAAiB,MAAM,oDAAoD,CAAA;AA4BpG,OAAO,EAAE,iBAAiB,EAAE,MAAM,uCAAuC,CAAA;AAGzE,KAAK,KAAK,GAAG,MAAM,CAAC,iBAAiB,EAAE,WAAW,CAAC,GAAG;IACpD,MAAM,EAAE,MAAM,CAAA;IACd,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,kEAAkE;IAClE,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB,CAAA;AA++BD,eAAO,MAAM,eAAe,GAAU,+CAMnC,KAAK,KAAG,OAAO,CAAC,gBAAgB,CAwElC,CAAA"}
|
|
@@ -1,34 +1,18 @@
|
|
|
1
1
|
import { base64Decode } from '@bufbuild/protobuf/wire';
|
|
2
2
|
import { toChainAmount } from '@vultisig/core-chain/amount/toChainAmount';
|
|
3
3
|
import { Chain } from '@vultisig/core-chain/Chain';
|
|
4
|
+
import { areEqualTonAddresses, tonAddressToBounceable } from '@vultisig/core-chain/chains/ton/address';
|
|
4
5
|
import { chainFeeCoin } from '@vultisig/core-chain/coin/chainFeeCoin';
|
|
5
6
|
import { usdc } from '@vultisig/core-chain/coin/knownTokens';
|
|
6
7
|
import { assertSwapKitAddressReputation, assertSwapKitDestinationMatchesTarget, } from '@vultisig/core-chain/swap/general/knownAggregatorRouters';
|
|
7
8
|
import { getSwapKitConfig } from '@vultisig/core-chain/swap/general/swapkit/config';
|
|
9
|
+
import { isSwapKitSourceChain, } from '@vultisig/core-chain/swap/general/swapkit/SwapKitEnabledChains';
|
|
8
10
|
import { SwapKitAmountBelowMinimumError, SwapKitFeeShapeError, SwapKitNoEligibleRoutesError, } from '@vultisig/core-chain/swap/general/swapkit/SwapKitErrors';
|
|
9
|
-
import { isSwapKitPairSupported, normalizeSwapKitProvider, swapKitExcludedProviders, } from '@vultisig/core-chain/swap/general/swapkit/SwapKitProviders';
|
|
11
|
+
import { isSwapKitPairSupported, normalizeSwapKitProvider, resolveSwapKitChainMetadata, swapKitAllowedProviders, swapKitExcludedProviders, } from '@vultisig/core-chain/swap/general/swapkit/SwapKitProviders';
|
|
10
12
|
import { isOneOf } from '@vultisig/lib-utils/array/isOneOf';
|
|
13
|
+
import { attempt } from '@vultisig/lib-utils/attempt';
|
|
11
14
|
import { withoutUndefinedFields } from '@vultisig/lib-utils/record/withoutUndefinedFields';
|
|
12
15
|
import { address as btcAddress, networks, Psbt } from 'bitcoinjs-lib';
|
|
13
|
-
const swapKitAllowedProviders = [
|
|
14
|
-
'CHAINFLIP',
|
|
15
|
-
'CHAINFLIP_STREAMING',
|
|
16
|
-
'NEAR',
|
|
17
|
-
'GARDEN',
|
|
18
|
-
'FLASHNET',
|
|
19
|
-
'HARBOR',
|
|
20
|
-
'ONEINCH',
|
|
21
|
-
'UNISWAP_V2',
|
|
22
|
-
'UNISWAP_V3',
|
|
23
|
-
'JUPITER',
|
|
24
|
-
'OKX',
|
|
25
|
-
'PANCAKESWAP',
|
|
26
|
-
'SUSHISWAP_V2',
|
|
27
|
-
'TRADERJOE_V2',
|
|
28
|
-
'PANGOLIN_V1',
|
|
29
|
-
'CAMELOT_V3',
|
|
30
|
-
'OPENOCEAN_V2',
|
|
31
|
-
];
|
|
32
16
|
const swapKitProviderQuoteAttempts = [
|
|
33
17
|
swapKitAllowedProviders,
|
|
34
18
|
['NEAR'],
|
|
@@ -50,31 +34,6 @@ const swapKitProviderQuoteAttempts = [
|
|
|
50
34
|
'OPENOCEAN_V2',
|
|
51
35
|
],
|
|
52
36
|
];
|
|
53
|
-
const swapKitChainId = {
|
|
54
|
-
[Chain.Arbitrum]: 'ARB',
|
|
55
|
-
[Chain.Avalanche]: 'AVAX',
|
|
56
|
-
[Chain.Base]: 'BASE',
|
|
57
|
-
[Chain.Bitcoin]: 'BTC',
|
|
58
|
-
[Chain.BitcoinCash]: 'BCH',
|
|
59
|
-
[Chain.BSC]: 'BSC',
|
|
60
|
-
[Chain.Cardano]: 'ADA',
|
|
61
|
-
[Chain.Cosmos]: 'GAIA',
|
|
62
|
-
[Chain.Dash]: 'DASH',
|
|
63
|
-
[Chain.Dogecoin]: 'DOGE',
|
|
64
|
-
[Chain.Ethereum]: 'ETH',
|
|
65
|
-
[Chain.Kujira]: 'KUJI',
|
|
66
|
-
[Chain.Litecoin]: 'LTC',
|
|
67
|
-
[Chain.MayaChain]: 'MAYA',
|
|
68
|
-
[Chain.Optimism]: 'OP',
|
|
69
|
-
[Chain.Polygon]: 'POL',
|
|
70
|
-
[Chain.Ripple]: 'XRP',
|
|
71
|
-
[Chain.Solana]: 'SOL',
|
|
72
|
-
[Chain.Sui]: 'SUI',
|
|
73
|
-
[Chain.THORChain]: 'THOR',
|
|
74
|
-
[Chain.Ton]: 'TON',
|
|
75
|
-
[Chain.Tron]: 'TRON',
|
|
76
|
-
[Chain.Zcash]: 'ZEC',
|
|
77
|
-
};
|
|
78
37
|
const swapKitTransferSourceChains = [
|
|
79
38
|
Chain.Bitcoin,
|
|
80
39
|
Chain.BitcoinCash,
|
|
@@ -187,10 +146,9 @@ const postSwapKit = async (path, body) => {
|
|
|
187
146
|
}
|
|
188
147
|
return data;
|
|
189
148
|
};
|
|
190
|
-
const toSwapKitAsset = ({ chain, id, ticker }) => {
|
|
191
|
-
const chainId = swapKitChainId[chain];
|
|
149
|
+
const toSwapKitAsset = ({ chain, id, ticker }, { assetPrefix }) => {
|
|
192
150
|
const symbol = id ? ticker : chainFeeCoin[chain].ticker;
|
|
193
|
-
return id ? `${
|
|
151
|
+
return id ? `${assetPrefix}.${symbol}-${id}` : `${assetPrefix}.${symbol}`;
|
|
194
152
|
};
|
|
195
153
|
const bigintString = (value, fallback = '0') => {
|
|
196
154
|
if (value === undefined) {
|
|
@@ -289,20 +247,26 @@ const chainflipStableFeeCoin = {
|
|
|
289
247
|
ticker: usdc.ticker,
|
|
290
248
|
};
|
|
291
249
|
const isChainflipProvider = (provider) => provider === 'CHAINFLIP' || provider === 'CHAINFLIP_STREAMING';
|
|
292
|
-
const matchesSwapKitFeeChain = (feeChain, coinChain) => {
|
|
250
|
+
const matchesSwapKitFeeChain = (feeChain, coinChain, { assetPrefix }) => {
|
|
293
251
|
if (!feeChain) {
|
|
294
252
|
return true;
|
|
295
253
|
}
|
|
296
254
|
const normalized = feeChain.toLowerCase();
|
|
297
|
-
return normalized === coinChain.toLowerCase() || normalized ===
|
|
255
|
+
return normalized === coinChain.toLowerCase() || normalized === assetPrefix.toLowerCase();
|
|
298
256
|
};
|
|
299
|
-
const getSwapKitSwapFee = (fees, from, to, routeProvider) => {
|
|
257
|
+
const getSwapKitSwapFee = (fees, from, to, routeProvider, fromMetadata, toMetadata) => {
|
|
300
258
|
const feeCoins = [
|
|
301
|
-
from,
|
|
302
|
-
to,
|
|
303
|
-
...(isChainflipProvider(routeProvider)
|
|
259
|
+
{ coin: from, metadata: fromMetadata },
|
|
260
|
+
{ coin: to, metadata: toMetadata },
|
|
261
|
+
...(isChainflipProvider(routeProvider)
|
|
262
|
+
? [{ coin: chainflipStableFeeCoin, metadata: { assetPrefix: 'ETH', providerChainId: '1' } }]
|
|
263
|
+
: []),
|
|
304
264
|
];
|
|
305
|
-
const candidates = feeCoins.map(
|
|
265
|
+
const candidates = feeCoins.map(({ coin, metadata }) => ({
|
|
266
|
+
coin,
|
|
267
|
+
metadata,
|
|
268
|
+
asset: toSwapKitAsset(coin, metadata).toLowerCase(),
|
|
269
|
+
}));
|
|
306
270
|
let result;
|
|
307
271
|
for (const fee of fees ?? []) {
|
|
308
272
|
const type = fee.type?.toLowerCase();
|
|
@@ -312,7 +276,7 @@ const getSwapKitSwapFee = (fees, from, to, routeProvider) => {
|
|
|
312
276
|
if (!fee.asset) {
|
|
313
277
|
throw new SwapKitFeeShapeError(`SwapKit ${type} fee is missing its asset.`);
|
|
314
278
|
}
|
|
315
|
-
const candidate = candidates.find(({ asset, coin }) => asset === fee.asset.toLowerCase() && matchesSwapKitFeeChain(fee.chain, coin.chain));
|
|
279
|
+
const candidate = candidates.find(({ asset, coin, metadata }) => asset === fee.asset.toLowerCase() && matchesSwapKitFeeChain(fee.chain, coin.chain, metadata));
|
|
316
280
|
if (!candidate) {
|
|
317
281
|
throw new SwapKitFeeShapeError(`SwapKit ${type} fee uses unsupported asset ${fee.asset}.`);
|
|
318
282
|
}
|
|
@@ -332,13 +296,19 @@ const getSwapKitSwapFee = (fees, from, to, routeProvider) => {
|
|
|
332
296
|
}
|
|
333
297
|
return result ?? { amount: 0n, chain: from.chain, id: from.id, decimals: from.decimals };
|
|
334
298
|
};
|
|
335
|
-
const buildSolanaTx = (tx, fees, from, to, routeProvider) => {
|
|
299
|
+
const buildSolanaTx = (tx, fees, from, to, routeProvider, fromMetadata, toMetadata) => {
|
|
336
300
|
if (typeof tx !== 'string') {
|
|
337
301
|
throw new Error('SwapKit Solana route did not return a serialized transaction string.');
|
|
338
302
|
}
|
|
339
303
|
const decimals = chainFeeCoin[Chain.Solana].decimals;
|
|
340
304
|
const networkFee = getSwapKitFeeAmount(fees, 'network', decimals);
|
|
341
|
-
return {
|
|
305
|
+
return {
|
|
306
|
+
solana: {
|
|
307
|
+
data: tx,
|
|
308
|
+
networkFee,
|
|
309
|
+
swapFee: getSwapKitSwapFee(fees, from, to, routeProvider, fromMetadata, toMetadata),
|
|
310
|
+
},
|
|
311
|
+
};
|
|
342
312
|
};
|
|
343
313
|
const getTransferTargetAddress = ({ targetAddress, depositAddress, tx }) => {
|
|
344
314
|
if (targetAddress) {
|
|
@@ -364,17 +334,97 @@ const toTransferAmount = (value, decimals) => {
|
|
|
364
334
|
}
|
|
365
335
|
return value.includes('.') ? toChainAmount(value, decimals) : BigInt(value);
|
|
366
336
|
};
|
|
337
|
+
const isTransferAmountValue = (value) => typeof value === 'string' || typeof value === 'number' || typeof value === 'bigint';
|
|
367
338
|
const getTransferAmount = ({ depositAmount, tx }, amount, decimals) => {
|
|
368
339
|
if (depositAmount) {
|
|
369
340
|
return toChainAmount(depositAmount, decimals);
|
|
370
341
|
}
|
|
371
|
-
if (Array.isArray(tx) &&
|
|
372
|
-
isRecord(tx[0]) &&
|
|
373
|
-
(typeof tx[0].amount === 'string' || typeof tx[0].amount === 'number' || typeof tx[0].amount === 'bigint')) {
|
|
342
|
+
if (Array.isArray(tx) && isRecord(tx[0]) && isTransferAmountValue(tx[0].amount)) {
|
|
374
343
|
return toTransferAmount(tx[0].amount, decimals);
|
|
375
344
|
}
|
|
376
345
|
return amount;
|
|
377
346
|
};
|
|
347
|
+
/**
|
|
348
|
+
* The single transfer SwapKit describes in its `tx[]` array, or `undefined`
|
|
349
|
+
* when `tx` is any other shape — an EVM object, an opaque PSBT / PTB string, or
|
|
350
|
+
* absent because `disableBuildTx` was sent.
|
|
351
|
+
*
|
|
352
|
+
* More than one entry is rejected rather than ignored: only `tx[0]` is ever
|
|
353
|
+
* built, so a multi-transfer route would be signed as a partial deposit that
|
|
354
|
+
* under-funds the swap. The count is checked before the entry shape so a
|
|
355
|
+
* malformed trailing entry cannot slip a multi-transfer array past this guard.
|
|
356
|
+
*/
|
|
357
|
+
const getTransferTxEntry = (tx) => {
|
|
358
|
+
if (!Array.isArray(tx) || tx.length === 0) {
|
|
359
|
+
return undefined;
|
|
360
|
+
}
|
|
361
|
+
if (tx.length > 1) {
|
|
362
|
+
throw new Error(`SwapKit transfer route returned ${tx.length} transfers; only the first would be signed, so the swap would be under-funded.`);
|
|
363
|
+
}
|
|
364
|
+
return isRecord(tx[0]) ? tx[0] : undefined;
|
|
365
|
+
};
|
|
366
|
+
/**
|
|
367
|
+
* The agreed TON deposit destination in its bounceable (`EQ…`) form.
|
|
368
|
+
*
|
|
369
|
+
* `assertTransferAgreement` compares TON spellings by account, so a route whose
|
|
370
|
+
* fields spell one account as `UQ…`, raw `0:hex` and `EQ…` passes — and the
|
|
371
|
+
* spelling that wins the precedence order is what the signer would otherwise
|
|
372
|
+
* read the bounce flag from. A deposit that goes out non-bounceable to a
|
|
373
|
+
* rejecting contract is absorbed instead of refunded, so the agreed account is
|
|
374
|
+
* re-spelled bounceable here, whichever field it came from. A string that is
|
|
375
|
+
* not a TON address at all cannot be a deposit destination and is refused.
|
|
376
|
+
*/
|
|
377
|
+
const toCanonicalTonDeposit = (destination) => {
|
|
378
|
+
const canonical = attempt(() => tonAddressToBounceable(destination));
|
|
379
|
+
if ('error' in canonical) {
|
|
380
|
+
throw new Error(`SwapKit transfer route returned an invalid TON deposit address: ${destination}`);
|
|
381
|
+
}
|
|
382
|
+
return canonical.data;
|
|
383
|
+
};
|
|
384
|
+
const areEqualTransferAddresses = (left, right, chain) => chain === Chain.Ton ? areEqualTonAddresses(left, right) : left === right;
|
|
385
|
+
/**
|
|
386
|
+
* Fail closed when the `/v3/swap` response disagrees with itself about where
|
|
387
|
+
* the deposit goes or how large it is.
|
|
388
|
+
*
|
|
389
|
+
* `targetAddress`, `depositAddress` and `tx[]` are independent fields carrying
|
|
390
|
+
* the same fact, and the resolvers above take the first one that is present and
|
|
391
|
+
* never look at the rest. So a response whose halves diverge — a provider bug,
|
|
392
|
+
* an API change, a tampered payload — signs whichever field happens to win the
|
|
393
|
+
* precedence order while the others name a different recipient or size, and
|
|
394
|
+
* nothing downstream can tell. Neither field is authoritative enough to pick a
|
|
395
|
+
* winner from, so a divergence is refused instead of resolved.
|
|
396
|
+
*
|
|
397
|
+
* Addresses are compared per chain because TON spells one account as `EQ…`,
|
|
398
|
+
* `UQ…` or raw `workchain:hex` — comparing those as strings would reject
|
|
399
|
+
* healthy routes.
|
|
400
|
+
*/
|
|
401
|
+
const assertTransferAgreement = (response, chain, decimals) => {
|
|
402
|
+
const entry = getTransferTxEntry(response.tx);
|
|
403
|
+
const destinations = [
|
|
404
|
+
{ field: 'targetAddress', value: response.targetAddress },
|
|
405
|
+
{ field: 'depositAddress', value: response.depositAddress },
|
|
406
|
+
{ field: 'tx[0].address', value: typeof entry?.address === 'string' ? entry.address : undefined },
|
|
407
|
+
].flatMap(({ field, value }) => (value?.trim() ? [{ field, value: value.trim() }] : []));
|
|
408
|
+
const [primaryDestination, ...otherDestinations] = destinations;
|
|
409
|
+
if (primaryDestination) {
|
|
410
|
+
const divergent = otherDestinations.find(({ value }) => !areEqualTransferAddresses(value, primaryDestination.value, chain));
|
|
411
|
+
if (divergent) {
|
|
412
|
+
throw new Error(`SwapKit transfer route disagrees with itself about the destination: ` +
|
|
413
|
+
`${primaryDestination.field} is ${primaryDestination.value} but ${divergent.field} is ${divergent.value}.`);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
const txAmountValue = entry && isTransferAmountValue(entry.amount) ? entry.amount : undefined;
|
|
417
|
+
if (txAmountValue === undefined || !response.depositAmount) {
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
const txAmount = toTransferAmount(txAmountValue, decimals);
|
|
421
|
+
const depositAmount = toChainAmount(response.depositAmount, decimals);
|
|
422
|
+
if (txAmount !== depositAmount) {
|
|
423
|
+
throw new Error(`SwapKit transfer route disagrees with itself about the amount: ` +
|
|
424
|
+
`depositAmount is ${response.depositAmount} (${depositAmount} base units) ` +
|
|
425
|
+
`but tx[0].amount is ${txAmountValue} (${txAmount} base units).`);
|
|
426
|
+
}
|
|
427
|
+
};
|
|
378
428
|
const shouldUseTransferTx = (chain) => isOneOf(chain, swapKitTransferSourceChains);
|
|
379
429
|
// Transfer-arm chains that still need SwapKit to BUILD the transaction, so
|
|
380
430
|
// `/v3/swap` must not be sent `disableBuildTx`. Bitcoin gets a PSBT and Sui a
|
|
@@ -429,10 +479,12 @@ const getBitcoinPsbtDestinationAmount = ({ txPayload, senderAddress, targetAddre
|
|
|
429
479
|
}
|
|
430
480
|
};
|
|
431
481
|
const buildTransferTx = (response, from, amount) => {
|
|
432
|
-
|
|
433
|
-
|
|
482
|
+
assertTransferAgreement(response, from.chain, from.decimals);
|
|
483
|
+
const agreedDestination = getTransferTargetAddress(response);
|
|
484
|
+
if (!agreedDestination) {
|
|
434
485
|
throw new Error('SwapKit transfer route did not return a target address.');
|
|
435
486
|
}
|
|
487
|
+
const to = from.chain === Chain.Ton ? toCanonicalTonDeposit(agreedDestination) : agreedDestination;
|
|
436
488
|
// SwapKit renames base64 tx types on the wire without versioning — `SOLANA`
|
|
437
489
|
// became `SERIALIZED_BASE64` and `CARDANO` became `CBOR` mid-flight (iOS
|
|
438
490
|
// accepts both spellings in `SwapKitSwapResponse.decodeTx`). A Sui route's
|
|
@@ -471,9 +523,9 @@ const buildTransferTx = (response, from, amount) => {
|
|
|
471
523
|
// Rejected in `getSwapKitQuote` BEFORE the network round-trip (no route/swap
|
|
472
524
|
// API calls wasted on a request that can never produce a signable tx).
|
|
473
525
|
const SWAP_SOURCE_TX_BUILD_UNSUPPORTED = new Set([Chain.Cardano]);
|
|
474
|
-
const buildSwapKitTx = (response, from, to, amount, routeProvider) => {
|
|
526
|
+
const buildSwapKitTx = (response, from, to, amount, routeProvider, fromMetadata, toMetadata) => {
|
|
475
527
|
if (from.chain === Chain.Solana) {
|
|
476
|
-
return buildSolanaTx(response.tx, response.fees, from, to, routeProvider);
|
|
528
|
+
return buildSolanaTx(response.tx, response.fees, from, to, routeProvider, fromMetadata, toMetadata);
|
|
477
529
|
}
|
|
478
530
|
if (shouldUseTransferTx(from.chain)) {
|
|
479
531
|
return buildTransferTx(response, from, amount);
|
|
@@ -484,7 +536,14 @@ const buildSwapKitTx = (response, from, to, amount, routeProvider) => {
|
|
|
484
536
|
targetAddress: response.targetAddress,
|
|
485
537
|
chain: from.chain,
|
|
486
538
|
approvalTx: response.approvalTx,
|
|
487
|
-
affiliateFee: getSwapKitEvmSwapFee({
|
|
539
|
+
affiliateFee: getSwapKitEvmSwapFee({
|
|
540
|
+
fees: response.fees,
|
|
541
|
+
from,
|
|
542
|
+
to,
|
|
543
|
+
routeProvider,
|
|
544
|
+
fromMetadata,
|
|
545
|
+
toMetadata,
|
|
546
|
+
}),
|
|
488
547
|
});
|
|
489
548
|
};
|
|
490
549
|
/**
|
|
@@ -498,9 +557,9 @@ const buildSwapKitTx = (response, from, to, amount, routeProvider) => {
|
|
|
498
557
|
* `getSwapKitSwapFee` bare and lets it throw on purpose: its tx type requires
|
|
499
558
|
* the fee, so an unresolved one really is fatal there.
|
|
500
559
|
*/
|
|
501
|
-
const getSwapKitEvmSwapFee = ({ fees, from, to, routeProvider }) => {
|
|
560
|
+
const getSwapKitEvmSwapFee = ({ fees, from, to, routeProvider, fromMetadata, toMetadata, }) => {
|
|
502
561
|
try {
|
|
503
|
-
return getSwapKitSwapFee(fees, from, to, routeProvider);
|
|
562
|
+
return getSwapKitSwapFee(fees, from, to, routeProvider, fromMetadata, toMetadata);
|
|
504
563
|
}
|
|
505
564
|
catch (error) {
|
|
506
565
|
if (!(error instanceof SwapKitFeeShapeError)) {
|
|
@@ -633,14 +692,25 @@ const getBestSwapKitRoute = async (body, decimals) => {
|
|
|
633
692
|
throw new SwapKitNoEligibleRoutesError();
|
|
634
693
|
};
|
|
635
694
|
export const getSwapKitQuote = async ({ from, to, amount, affiliateBps, slippage = 3, }) => {
|
|
636
|
-
if (
|
|
637
|
-
throw new Error(`SwapKit ${from.chain} source swaps are
|
|
695
|
+
if (!isSwapKitSourceChain(from.chain)) {
|
|
696
|
+
throw new Error(`SwapKit ${from.chain} source swaps are unavailable without safe signing and Blockaid coverage.`);
|
|
697
|
+
}
|
|
698
|
+
const source = from;
|
|
699
|
+
if (SWAP_SOURCE_TX_BUILD_UNSUPPORTED.has(source.chain)) {
|
|
700
|
+
throw new Error(`SwapKit ${source.chain} source swaps are not yet supported for signing (quote-only for now). ` +
|
|
638
701
|
'Try a different source chain, or swap the other direction.');
|
|
639
702
|
}
|
|
703
|
+
const [fromMetadata, toMetadata] = await Promise.all([
|
|
704
|
+
resolveSwapKitChainMetadata(source.chain),
|
|
705
|
+
resolveSwapKitChainMetadata(to.chain),
|
|
706
|
+
]);
|
|
707
|
+
if (!fromMetadata || !toMetadata) {
|
|
708
|
+
throw new Error(`SwapKit catalog does not unambiguously support ${source.chain} -> ${to.chain}.`);
|
|
709
|
+
}
|
|
640
710
|
const quoteBody = {
|
|
641
|
-
sellAsset: toSwapKitAsset(
|
|
642
|
-
buyAsset: toSwapKitAsset(to),
|
|
643
|
-
sellAmount: formatBasicUnitAmount(amount,
|
|
711
|
+
sellAsset: toSwapKitAsset(source, fromMetadata),
|
|
712
|
+
buyAsset: toSwapKitAsset(to, toMetadata),
|
|
713
|
+
sellAmount: formatBasicUnitAmount(amount, source.decimals),
|
|
644
714
|
slippage,
|
|
645
715
|
affiliateFee: affiliateBps,
|
|
646
716
|
};
|
|
@@ -654,17 +724,17 @@ export const getSwapKitQuote = async ({ from, to, amount, affiliateBps, slippage
|
|
|
654
724
|
// (per the /providers snapshot), reclassify so the form shows the actionable
|
|
655
725
|
// "amount too small" copy instead of a misleading "no route" error (#4418).
|
|
656
726
|
if (error instanceof SwapKitNoEligibleRoutesError &&
|
|
657
|
-
(await isSwapKitPairSupported({ from:
|
|
658
|
-
throw new SwapKitAmountBelowMinimumError(
|
|
727
|
+
(await isSwapKitPairSupported({ from: source.chain, to: to.chain }))) {
|
|
728
|
+
throw new SwapKitAmountBelowMinimumError(source.chain, to.chain);
|
|
659
729
|
}
|
|
660
730
|
throw error;
|
|
661
731
|
}
|
|
662
732
|
const swapResponse = await postSwapKit('/v3/swap', withoutUndefinedFields({
|
|
663
733
|
routeId: route.routeId,
|
|
664
|
-
sourceAddress:
|
|
734
|
+
sourceAddress: source.address,
|
|
665
735
|
destinationAddress: to.address,
|
|
666
736
|
disableBalanceCheck: true,
|
|
667
|
-
disableBuildTx: shouldUseTransferTx(
|
|
737
|
+
disableBuildTx: shouldUseTransferTx(source.chain) && !swapKitPrebuiltTxSourceChains.has(source.chain) ? true : undefined,
|
|
668
738
|
}));
|
|
669
739
|
const routeProvider = getRouteProviderName(swapResponse) ?? getRouteProviderName(route);
|
|
670
740
|
// Read from the quote-stage route, unlike `dstAmount` and `routeProvider`
|
|
@@ -677,7 +747,7 @@ export const getSwapKitQuote = async ({ from, to, amount, affiliateBps, slippage
|
|
|
677
747
|
provider: 'swapkit',
|
|
678
748
|
routeProvider,
|
|
679
749
|
...(priceImpactFraction === undefined ? {} : { priceImpactFraction }),
|
|
680
|
-
tx: await buildSwapKitTx(swapResponse,
|
|
750
|
+
tx: await buildSwapKitTx(swapResponse, source, to, amount, routeProvider, fromMetadata, toMetadata),
|
|
681
751
|
};
|
|
682
752
|
};
|
|
683
753
|
//# sourceMappingURL=getSwapKitQuote.js.map
|