@shapeshiftoss/swapper 17.6.9 → 17.6.10
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/constants.js +61 -43
- package/dist/cjs/swappers/AcrossSwapper/AcrossSwapper.d.ts +2 -0
- package/dist/cjs/swappers/AcrossSwapper/AcrossSwapper.js +8 -0
- package/dist/cjs/swappers/AcrossSwapper/constant.d.ts +9 -0
- package/dist/cjs/swappers/AcrossSwapper/constant.js +48 -0
- package/dist/cjs/swappers/AcrossSwapper/endpoints.d.ts +2 -0
- package/dist/cjs/swappers/AcrossSwapper/endpoints.js +113 -0
- package/dist/cjs/swappers/AcrossSwapper/getTradeQuote/getTradeQuote.d.ts +3 -0
- package/dist/cjs/swappers/AcrossSwapper/getTradeQuote/getTradeQuote.js +31 -0
- package/dist/cjs/swappers/AcrossSwapper/getTradeRate/getTradeRate.d.ts +3 -0
- package/dist/cjs/swappers/AcrossSwapper/getTradeRate/getTradeRate.js +19 -0
- package/dist/cjs/swappers/AcrossSwapper/index.d.ts +1 -0
- package/dist/cjs/swappers/AcrossSwapper/index.js +5 -0
- package/dist/cjs/swappers/AcrossSwapper/utils/acrossService.d.ts +5 -0
- package/dist/cjs/swappers/AcrossSwapper/utils/acrossService.js +17 -0
- package/dist/cjs/swappers/AcrossSwapper/utils/fetchAcrossTrade.d.ts +19 -0
- package/dist/cjs/swappers/AcrossSwapper/utils/fetchAcrossTrade.js +27 -0
- package/dist/cjs/swappers/AcrossSwapper/utils/getTrade.d.ts +11 -0
- package/dist/cjs/swappers/AcrossSwapper/utils/getTrade.js +335 -0
- package/dist/cjs/swappers/AcrossSwapper/utils/types.d.ts +177 -0
- package/dist/cjs/swappers/AcrossSwapper/utils/types.js +17 -0
- package/dist/cjs/swappers/AvnuSwapper/endpoints.js +42 -14
- package/dist/cjs/swappers/AvnuSwapper/swapperApi/getTradeQuote.js +10 -5
- package/dist/cjs/swappers/AvnuSwapper/swapperApi/getTradeRate.js +8 -4
- package/dist/cjs/swappers/BebopSwapper/utils/helpers/helpers.d.ts +1 -1
- package/dist/cjs/swappers/ButterSwap/ButterSwap.js +1 -0
- package/dist/cjs/swappers/ButterSwap/endpoints.js +56 -0
- package/dist/cjs/swappers/ButterSwap/swapperApi/checkTradeStatus.js +19 -0
- package/dist/cjs/swappers/ButterSwap/swapperApi/getTradeQuote.js +27 -14
- package/dist/cjs/swappers/ButterSwap/swapperApi/getTradeQuote.test.js +1 -0
- package/dist/cjs/swappers/ButterSwap/swapperApi/getTradeRate.js +23 -16
- package/dist/cjs/swappers/ButterSwap/swapperApi/getTradeRate.test.js +2 -0
- package/dist/cjs/swappers/ButterSwap/types.d.ts +1 -0
- package/dist/cjs/swappers/ButterSwap/utils/helpers.js +1 -0
- package/dist/cjs/swappers/ButterSwap/xhr.d.ts +2 -2
- package/dist/cjs/swappers/ButterSwap/xhr.js +7 -2
- package/dist/cjs/swappers/CetusSwapper/endpoints.js +3 -8
- package/dist/cjs/swappers/CetusSwapper/swapperApi/getTradeQuote.js +1 -1
- package/dist/cjs/swappers/CetusSwapper/swapperApi/getTradeRate.js +1 -1
- package/dist/cjs/swappers/ChainflipSwapper/utils/getQuoteOrRate.js +11 -5
- package/dist/cjs/swappers/ChainflipSwapper/utils/helpers.js +8 -2
- package/dist/cjs/swappers/CowSwapper/CowSwapper.js +1 -1
- package/dist/cjs/swappers/CowSwapper/getCowSwapTradeQuote/getCowSwapTradeQuote.js +1 -1
- package/dist/cjs/swappers/CowSwapper/getCowSwapTradeQuote/getCowSwapTradeQuote.test.js +5 -5
- package/dist/cjs/swappers/CowSwapper/getCowSwapTradeRate/getCowSwapTradeRate.js +1 -1
- package/dist/cjs/swappers/CowSwapper/utils/helpers/helpers.js +8 -2
- package/dist/cjs/swappers/NearIntentsSwapper/NearIntentsSwapper.js +1 -0
- package/dist/cjs/swappers/NearIntentsSwapper/endpoints.js +31 -0
- package/dist/cjs/swappers/NearIntentsSwapper/swapperApi/getTradeQuote.js +36 -1
- package/dist/cjs/swappers/NearIntentsSwapper/swapperApi/getTradeRate.js +61 -1
- package/dist/cjs/swappers/NearIntentsSwapper/types.d.ts +1 -1
- package/dist/cjs/swappers/NearIntentsSwapper/types.js +6 -0
- package/dist/cjs/swappers/NearIntentsSwapper/utils/helpers/helpers.js +23 -4
- package/dist/cjs/swappers/PortalsSwapper/getPortalsTradeRate/getPortalsTradeRate.js +8 -3
- package/dist/cjs/swappers/RelaySwapper/constant.js +26 -1
- package/dist/cjs/swappers/RelaySwapper/utils/getRelayDefaultUserAddress.d.ts +1 -1
- package/dist/cjs/swappers/RelaySwapper/utils/getTrade.js +13 -2
- package/dist/cjs/swappers/RelaySwapper/utils/relayTokenToAssetId.js +100 -0
- package/dist/cjs/swappers/RelaySwapper/utils/types.d.ts +15 -0
- package/dist/cjs/swappers/StonfiSwapper/StonfiSwapper.d.ts +2 -0
- package/dist/cjs/swappers/StonfiSwapper/StonfiSwapper.js +8 -0
- package/dist/cjs/swappers/StonfiSwapper/endpoints.d.ts +2 -0
- package/dist/cjs/swappers/StonfiSwapper/endpoints.js +227 -0
- package/dist/cjs/swappers/StonfiSwapper/index.d.ts +4 -0
- package/dist/cjs/swappers/StonfiSwapper/index.js +25 -0
- package/dist/cjs/swappers/StonfiSwapper/swapperApi/getTradeQuote.d.ts +2 -0
- package/dist/cjs/swappers/StonfiSwapper/swapperApi/getTradeQuote.js +119 -0
- package/dist/cjs/swappers/StonfiSwapper/swapperApi/getTradeRate.d.ts +2 -0
- package/dist/cjs/swappers/StonfiSwapper/swapperApi/getTradeRate.js +105 -0
- package/dist/cjs/swappers/StonfiSwapper/types.d.ts +60 -0
- package/dist/cjs/swappers/StonfiSwapper/types.js +5 -0
- package/dist/cjs/swappers/StonfiSwapper/utils/constants.d.ts +5 -0
- package/dist/cjs/swappers/StonfiSwapper/utils/constants.js +8 -0
- package/dist/cjs/swappers/StonfiSwapper/utils/helpers.d.ts +11 -0
- package/dist/cjs/swappers/StonfiSwapper/utils/helpers.js +135 -0
- package/dist/cjs/swappers/StonfiSwapper/utils/omnistonManager.d.ts +5 -0
- package/dist/cjs/swappers/StonfiSwapper/utils/omnistonManager.js +20 -0
- package/dist/cjs/swappers/SunioSwapper/endpoints.js +1 -1
- package/dist/cjs/swappers/SunioSwapper/utils/getQuoteOrRate.js +4 -3
- package/dist/cjs/swappers/ZrxSwapper/utils/helpers/helpers.d.ts +1 -1
- package/dist/cjs/swappers/utils/filterBuyAssetsBySellAssetId/filterBuyAssetsBySellAssetId.js +2 -5
- package/dist/cjs/swappers/utils/helpers/helpers.js +3 -0
- package/dist/cjs/thorchain-utils/getCallDataFromQuote.d.ts +1 -1
- package/dist/cjs/thorchain-utils/getL1RateOrQuote.js +30 -5
- package/dist/cjs/thorchain-utils/getQuote.js +8 -2
- package/dist/cjs/tron-utils/getUnsignedTronTransaction.js +22 -2
- package/dist/cjs/types.d.ts +79 -8
- package/dist/cjs/types.js +2 -0
- package/dist/cjs/utils.d.ts +4 -3
- package/dist/cjs/utils.js +35 -7
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/constants.js +31 -13
- package/dist/esm/swappers/AcrossSwapper/AcrossSwapper.d.ts +2 -0
- package/dist/esm/swappers/AcrossSwapper/AcrossSwapper.js +5 -0
- package/dist/esm/swappers/AcrossSwapper/constant.d.ts +9 -0
- package/dist/esm/swappers/AcrossSwapper/constant.js +42 -0
- package/dist/esm/swappers/AcrossSwapper/endpoints.d.ts +2 -0
- package/dist/esm/swappers/AcrossSwapper/endpoints.js +107 -0
- package/dist/esm/swappers/AcrossSwapper/getTradeQuote/getTradeQuote.d.ts +3 -0
- package/dist/esm/swappers/AcrossSwapper/getTradeQuote/getTradeQuote.js +27 -0
- package/dist/esm/swappers/AcrossSwapper/getTradeRate/getTradeRate.d.ts +3 -0
- package/dist/esm/swappers/AcrossSwapper/getTradeRate/getTradeRate.js +15 -0
- package/dist/esm/swappers/AcrossSwapper/index.d.ts +1 -0
- package/dist/esm/swappers/AcrossSwapper/index.js +1 -0
- package/dist/esm/swappers/AcrossSwapper/utils/acrossService.d.ts +5 -0
- package/dist/esm/swappers/AcrossSwapper/utils/acrossService.js +11 -0
- package/dist/esm/swappers/AcrossSwapper/utils/fetchAcrossTrade.d.ts +19 -0
- package/dist/esm/swappers/AcrossSwapper/utils/fetchAcrossTrade.js +23 -0
- package/dist/esm/swappers/AcrossSwapper/utils/getTrade.d.ts +11 -0
- package/dist/esm/swappers/AcrossSwapper/utils/getTrade.js +328 -0
- package/dist/esm/swappers/AcrossSwapper/utils/types.d.ts +177 -0
- package/dist/esm/swappers/AcrossSwapper/utils/types.js +13 -0
- package/dist/esm/swappers/AvnuSwapper/endpoints.js +43 -15
- package/dist/esm/swappers/AvnuSwapper/swapperApi/getTradeQuote.js +10 -5
- package/dist/esm/swappers/AvnuSwapper/swapperApi/getTradeRate.js +8 -4
- package/dist/esm/swappers/BebopSwapper/utils/helpers/helpers.d.ts +1 -1
- package/dist/esm/swappers/ButterSwap/ButterSwap.js +2 -1
- package/dist/esm/swappers/ButterSwap/endpoints.js +56 -0
- package/dist/esm/swappers/ButterSwap/swapperApi/checkTradeStatus.js +20 -1
- package/dist/esm/swappers/ButterSwap/swapperApi/getTradeQuote.js +29 -16
- package/dist/esm/swappers/ButterSwap/swapperApi/getTradeQuote.test.js +1 -0
- package/dist/esm/swappers/ButterSwap/swapperApi/getTradeRate.js +25 -18
- package/dist/esm/swappers/ButterSwap/swapperApi/getTradeRate.test.js +2 -0
- package/dist/esm/swappers/ButterSwap/types.d.ts +1 -0
- package/dist/esm/swappers/ButterSwap/utils/helpers.js +1 -0
- package/dist/esm/swappers/ButterSwap/xhr.d.ts +2 -2
- package/dist/esm/swappers/ButterSwap/xhr.js +8 -3
- package/dist/esm/swappers/CetusSwapper/endpoints.js +3 -8
- package/dist/esm/swappers/CetusSwapper/swapperApi/getTradeQuote.js +1 -1
- package/dist/esm/swappers/CetusSwapper/swapperApi/getTradeRate.js +1 -1
- package/dist/esm/swappers/ChainflipSwapper/utils/getQuoteOrRate.js +12 -6
- package/dist/esm/swappers/ChainflipSwapper/utils/helpers.js +9 -3
- package/dist/esm/swappers/CowSwapper/CowSwapper.js +1 -1
- package/dist/esm/swappers/CowSwapper/getCowSwapTradeQuote/getCowSwapTradeQuote.js +1 -1
- package/dist/esm/swappers/CowSwapper/getCowSwapTradeQuote/getCowSwapTradeQuote.test.js +5 -5
- package/dist/esm/swappers/CowSwapper/getCowSwapTradeRate/getCowSwapTradeRate.js +1 -1
- package/dist/esm/swappers/CowSwapper/utils/helpers/helpers.js +9 -3
- package/dist/esm/swappers/NearIntentsSwapper/NearIntentsSwapper.js +2 -1
- package/dist/esm/swappers/NearIntentsSwapper/endpoints.js +31 -0
- package/dist/esm/swappers/NearIntentsSwapper/swapperApi/getTradeQuote.js +36 -1
- package/dist/esm/swappers/NearIntentsSwapper/swapperApi/getTradeRate.js +61 -1
- package/dist/esm/swappers/NearIntentsSwapper/types.d.ts +1 -1
- package/dist/esm/swappers/NearIntentsSwapper/types.js +6 -0
- package/dist/esm/swappers/NearIntentsSwapper/utils/helpers/helpers.js +23 -4
- package/dist/esm/swappers/PortalsSwapper/getPortalsTradeRate/getPortalsTradeRate.js +8 -3
- package/dist/esm/swappers/RelaySwapper/constant.js +28 -3
- package/dist/esm/swappers/RelaySwapper/utils/getRelayDefaultUserAddress.d.ts +1 -1
- package/dist/esm/swappers/RelaySwapper/utils/getTrade.js +13 -2
- package/dist/esm/swappers/RelaySwapper/utils/relayTokenToAssetId.js +100 -0
- package/dist/esm/swappers/RelaySwapper/utils/types.d.ts +15 -0
- package/dist/esm/swappers/StonfiSwapper/StonfiSwapper.d.ts +2 -0
- package/dist/esm/swappers/StonfiSwapper/StonfiSwapper.js +5 -0
- package/dist/esm/swappers/StonfiSwapper/endpoints.d.ts +2 -0
- package/dist/esm/swappers/StonfiSwapper/endpoints.js +224 -0
- package/dist/esm/swappers/StonfiSwapper/index.d.ts +4 -0
- package/dist/esm/swappers/StonfiSwapper/index.js +4 -0
- package/dist/esm/swappers/StonfiSwapper/swapperApi/getTradeQuote.d.ts +2 -0
- package/dist/esm/swappers/StonfiSwapper/swapperApi/getTradeQuote.js +115 -0
- package/dist/esm/swappers/StonfiSwapper/swapperApi/getTradeRate.d.ts +2 -0
- package/dist/esm/swappers/StonfiSwapper/swapperApi/getTradeRate.js +101 -0
- package/dist/esm/swappers/StonfiSwapper/types.d.ts +60 -0
- package/dist/esm/swappers/StonfiSwapper/types.js +2 -0
- package/dist/esm/swappers/StonfiSwapper/utils/constants.d.ts +5 -0
- package/dist/esm/swappers/StonfiSwapper/utils/constants.js +5 -0
- package/dist/esm/swappers/StonfiSwapper/utils/helpers.d.ts +11 -0
- package/dist/esm/swappers/StonfiSwapper/utils/helpers.js +124 -0
- package/dist/esm/swappers/StonfiSwapper/utils/omnistonManager.d.ts +5 -0
- package/dist/esm/swappers/StonfiSwapper/utils/omnistonManager.js +17 -0
- package/dist/esm/swappers/SunioSwapper/endpoints.js +1 -1
- package/dist/esm/swappers/SunioSwapper/utils/getQuoteOrRate.js +5 -4
- package/dist/esm/swappers/ZrxSwapper/utils/helpers/helpers.d.ts +1 -1
- package/dist/esm/swappers/utils/filterBuyAssetsBySellAssetId/filterBuyAssetsBySellAssetId.js +2 -5
- package/dist/esm/swappers/utils/helpers/helpers.js +4 -1
- package/dist/esm/thorchain-utils/getCallDataFromQuote.d.ts +1 -1
- package/dist/esm/thorchain-utils/getL1RateOrQuote.js +31 -6
- package/dist/esm/thorchain-utils/getQuote.js +9 -3
- package/dist/esm/tron-utils/getUnsignedTronTransaction.js +22 -2
- package/dist/esm/types.d.ts +79 -8
- package/dist/esm/types.js +2 -0
- package/dist/esm/utils.d.ts +4 -3
- package/dist/esm/utils.js +34 -7
- package/package.json +17 -15
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { fromAssetId } from '@shapeshiftoss/caip';
|
|
2
|
+
import { KnownChainIds } from '@shapeshiftoss/types';
|
|
3
|
+
import { bn, convertPrecision } from '@shapeshiftoss/utils';
|
|
4
|
+
import { Err } from '@sniptt/monads';
|
|
5
|
+
import { Blockchain } from '@ston-fi/omniston-sdk';
|
|
6
|
+
import { TradeQuoteError } from '../../../types.js';
|
|
7
|
+
import { makeSwapErrorRight } from '../../../utils.js';
|
|
8
|
+
export const isTonAsset = (asset) => {
|
|
9
|
+
return asset.chainId === KnownChainIds.TonMainnet;
|
|
10
|
+
};
|
|
11
|
+
export const assetToOmnistonAddress = (asset) => {
|
|
12
|
+
if (!isTonAsset(asset))
|
|
13
|
+
return null;
|
|
14
|
+
const { assetNamespace, assetReference } = fromAssetId(asset.assetId);
|
|
15
|
+
if (assetNamespace === 'slip44') {
|
|
16
|
+
return {
|
|
17
|
+
blockchain: Blockchain.TON,
|
|
18
|
+
address: 'EQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAM9c',
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
if (assetNamespace === 'jetton') {
|
|
22
|
+
return { blockchain: Blockchain.TON, address: assetReference };
|
|
23
|
+
}
|
|
24
|
+
return null;
|
|
25
|
+
};
|
|
26
|
+
export const validateTonAssets = (sellAsset, buyAsset) => {
|
|
27
|
+
if (sellAsset.chainId !== KnownChainIds.TonMainnet) {
|
|
28
|
+
return {
|
|
29
|
+
isValid: false,
|
|
30
|
+
error: Err(makeSwapErrorRight({
|
|
31
|
+
message: `[Stonfi] Unsupported sell asset chain: ${sellAsset.chainId}`,
|
|
32
|
+
code: TradeQuoteError.UnsupportedChain,
|
|
33
|
+
})),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
if (buyAsset.chainId !== KnownChainIds.TonMainnet) {
|
|
37
|
+
return {
|
|
38
|
+
isValid: false,
|
|
39
|
+
error: Err(makeSwapErrorRight({
|
|
40
|
+
message: `[Stonfi] Cross-chain swaps not supported`,
|
|
41
|
+
code: TradeQuoteError.CrossChainNotSupported,
|
|
42
|
+
})),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
const bidAssetAddress = assetToOmnistonAddress(sellAsset);
|
|
46
|
+
const askAssetAddress = assetToOmnistonAddress(buyAsset);
|
|
47
|
+
if (!bidAssetAddress || !askAssetAddress) {
|
|
48
|
+
return {
|
|
49
|
+
isValid: false,
|
|
50
|
+
error: Err(makeSwapErrorRight({
|
|
51
|
+
message: `[Stonfi] Unable to convert assets to Omniston addresses`,
|
|
52
|
+
code: TradeQuoteError.UnsupportedTradePair,
|
|
53
|
+
})),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
isValid: true,
|
|
58
|
+
bidAssetAddress,
|
|
59
|
+
askAssetAddress,
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
export const calculateRate = (buyAmountCryptoBaseUnit, sellAmountCryptoBaseUnit, buyAssetPrecision, sellAssetPrecision) => {
|
|
63
|
+
if (bn(buyAmountCryptoBaseUnit).gt(0) && bn(sellAmountCryptoBaseUnit).gt(0)) {
|
|
64
|
+
return convertPrecision({
|
|
65
|
+
value: buyAmountCryptoBaseUnit,
|
|
66
|
+
inputExponent: buyAssetPrecision,
|
|
67
|
+
outputExponent: sellAssetPrecision,
|
|
68
|
+
})
|
|
69
|
+
.dividedBy(bn(sellAmountCryptoBaseUnit))
|
|
70
|
+
.toFixed();
|
|
71
|
+
}
|
|
72
|
+
return '0';
|
|
73
|
+
};
|
|
74
|
+
export const slippageDecimalToBps = (slippageTolerancePercentageDecimal, defaultSlippageBps) => {
|
|
75
|
+
if (!slippageTolerancePercentageDecimal) {
|
|
76
|
+
return defaultSlippageBps;
|
|
77
|
+
}
|
|
78
|
+
const parsed = parseFloat(slippageTolerancePercentageDecimal);
|
|
79
|
+
if (Number.isNaN(parsed) || !Number.isFinite(parsed) || parsed < 0) {
|
|
80
|
+
return defaultSlippageBps;
|
|
81
|
+
}
|
|
82
|
+
return Math.round(parsed * 10000);
|
|
83
|
+
};
|
|
84
|
+
export const tonAddressToOmnistonAddress = (address) => {
|
|
85
|
+
return {
|
|
86
|
+
blockchain: Blockchain.TON,
|
|
87
|
+
address,
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
export const affiliateBpsToNumber = (affiliateBps) => {
|
|
91
|
+
if (!affiliateBps)
|
|
92
|
+
return 0;
|
|
93
|
+
const parsed = parseInt(affiliateBps, 10);
|
|
94
|
+
if (Number.isNaN(parsed) || !Number.isFinite(parsed) || parsed < 0)
|
|
95
|
+
return 0;
|
|
96
|
+
return parsed;
|
|
97
|
+
};
|
|
98
|
+
export const waitForQuote = (omniston, request, timeoutMs) => {
|
|
99
|
+
return new Promise(resolve => {
|
|
100
|
+
const timer = setTimeout(() => {
|
|
101
|
+
subscription.unsubscribe();
|
|
102
|
+
resolve({ type: 'timeout' });
|
|
103
|
+
}, timeoutMs);
|
|
104
|
+
const subscription = omniston.requestForQuote(request).subscribe({
|
|
105
|
+
next: (event) => {
|
|
106
|
+
if (event.type === 'quoteUpdated' && event.quote) {
|
|
107
|
+
clearTimeout(timer);
|
|
108
|
+
subscription.unsubscribe();
|
|
109
|
+
resolve({ type: 'success', quote: event.quote });
|
|
110
|
+
}
|
|
111
|
+
else if (event.type === 'noQuote') {
|
|
112
|
+
clearTimeout(timer);
|
|
113
|
+
subscription.unsubscribe();
|
|
114
|
+
resolve({ type: 'noQuote' });
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
error: err => {
|
|
118
|
+
clearTimeout(timer);
|
|
119
|
+
subscription.unsubscribe();
|
|
120
|
+
resolve({ type: 'error', error: err });
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Omniston } from '@ston-fi/omniston-sdk';
|
|
2
|
+
import { STONFI_WEBSOCKET_URL } from './constants.js';
|
|
3
|
+
let cachedOmniston = null;
|
|
4
|
+
export const omnistonManager = {
|
|
5
|
+
getInstance: () => {
|
|
6
|
+
if (!cachedOmniston) {
|
|
7
|
+
cachedOmniston = new Omniston({ apiUrl: STONFI_WEBSOCKET_URL });
|
|
8
|
+
}
|
|
9
|
+
return cachedOmniston;
|
|
10
|
+
},
|
|
11
|
+
disconnect: () => {
|
|
12
|
+
if (cachedOmniston) {
|
|
13
|
+
cachedOmniston.close();
|
|
14
|
+
cachedOmniston = null;
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
};
|
|
@@ -43,7 +43,7 @@ export const sunioApi = {
|
|
|
43
43
|
const tronWeb = new TronWeb({
|
|
44
44
|
fullHost: rpcUrl,
|
|
45
45
|
});
|
|
46
|
-
const routeParams = buildSwapRouteParameters(sunioMetadata.route, step.sellAmountIncludingProtocolFeesCryptoBaseUnit, step.buyAmountAfterFeesCryptoBaseUnit,
|
|
46
|
+
const routeParams = buildSwapRouteParameters(sunioMetadata.route, step.sellAmountIncludingProtocolFeesCryptoBaseUnit, step.buyAmountAfterFeesCryptoBaseUnit, tradeQuote.receiveAddress, slippageTolerancePercentageDecimal);
|
|
47
47
|
const parameters = [
|
|
48
48
|
{ type: 'address[]', value: routeParams.path },
|
|
49
49
|
{ type: 'string[]', value: routeParams.poolVersion },
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { tronChainId } from '@shapeshiftoss/caip';
|
|
2
|
-
import { bn, contractAddressOrUndefined } from '@shapeshiftoss/utils';
|
|
2
|
+
import { BigAmount, bn, contractAddressOrUndefined } from '@shapeshiftoss/utils';
|
|
3
3
|
import { Err, Ok } from '@sniptt/monads';
|
|
4
4
|
import { TronWeb } from 'tronweb';
|
|
5
5
|
import { SwapperName, TradeQuoteError } from '../../../types.js';
|
|
@@ -133,9 +133,10 @@ export async function getQuoteOrRate(input, deps) {
|
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
|
-
const buyAmountCryptoBaseUnit =
|
|
137
|
-
.
|
|
138
|
-
.
|
|
136
|
+
const buyAmountCryptoBaseUnit = BigAmount.fromPrecision({
|
|
137
|
+
value: bestRoute.amountOut,
|
|
138
|
+
precision: buyAsset.precision,
|
|
139
|
+
}).toBaseUnit();
|
|
139
140
|
// Calculate protocol fees only for quotes
|
|
140
141
|
const protocolFeeCryptoBaseUnit = isQuote
|
|
141
142
|
? bn(bestRoute.fee).times(sellAmountIncludingProtocolFeesCryptoBaseUnit).toFixed(0)
|
|
@@ -8,7 +8,7 @@ export declare const isSupportedChainId: (chainId: ChainId) => chainId is KnownC
|
|
|
8
8
|
export declare const assertValidTrade: ({ buyAsset, sellAsset, }: {
|
|
9
9
|
buyAsset: Asset;
|
|
10
10
|
sellAsset: Asset;
|
|
11
|
-
}) => import("@sniptt/monads/build/result/result").
|
|
11
|
+
}) => import("@sniptt/monads/build/result/result").ResErr<unknown, import("../../../../types.js").SwapErrorRight> | import("@sniptt/monads/build/result/result").ResOk<boolean, never>;
|
|
12
12
|
export declare const calculateRate: ({ buyAmount, sellAmount, buyAsset, sellAsset, }: {
|
|
13
13
|
buyAmount: string;
|
|
14
14
|
sellAmount: string;
|
package/dist/esm/swappers/utils/filterBuyAssetsBySellAssetId/filterBuyAssetsBySellAssetId.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import { arbitrumNovaChainId } from '@shapeshiftoss/caip';
|
|
2
1
|
import { isEvmChainId } from '@shapeshiftoss/chain-adapters';
|
|
3
2
|
const _filterEvmBuyAssetsBySellAssetId = ({ assets, sellAsset }, chainIdPredicate) => {
|
|
4
3
|
// evm only
|
|
5
4
|
if (!isEvmChainId(sellAsset.chainId))
|
|
6
5
|
return [];
|
|
7
6
|
return assets.filter(buyAsset => {
|
|
8
|
-
// evm only AND chain id predicate
|
|
9
|
-
return
|
|
10
|
-
chainIdPredicate(buyAsset.chainId, sellAsset.chainId) &&
|
|
11
|
-
buyAsset.chainId !== arbitrumNovaChainId);
|
|
7
|
+
// evm only AND chain id predicate
|
|
8
|
+
return isEvmChainId(buyAsset.chainId) && chainIdPredicate(buyAsset.chainId, sellAsset.chainId);
|
|
12
9
|
});
|
|
13
10
|
};
|
|
14
11
|
export const filterSameChainEvmBuyAssetsBySellAssetId = (input) => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { arbitrumAssetId, avalancheAssetId, baseAssetId, bscAssetId, ethAssetId, fromAssetId, gnosisAssetId, katanaAssetId, monadAssetId, optimismAssetId, plasmaAssetId, polygonAssetId, } from '@shapeshiftoss/caip';
|
|
2
2
|
import { KnownChainIds } from '@shapeshiftoss/types';
|
|
3
|
-
import { DAO_TREASURY_ARBITRUM, DAO_TREASURY_AVALANCHE, DAO_TREASURY_BASE, DAO_TREASURY_BITCOIN, DAO_TREASURY_BSC, DAO_TREASURY_ETHEREUM_MAINNET, DAO_TREASURY_GNOSIS, DAO_TREASURY_OPTIMISM, DAO_TREASURY_POLYGON, DAO_TREASURY_SOLANA, DAO_TREASURY_STARKNET, isTreasuryChainId, } from '@shapeshiftoss/utils';
|
|
3
|
+
import { DAO_TREASURY_ARBITRUM, DAO_TREASURY_AVALANCHE, DAO_TREASURY_BASE, DAO_TREASURY_BITCOIN, DAO_TREASURY_BSC, DAO_TREASURY_ETHEREUM_MAINNET, DAO_TREASURY_GNOSIS, DAO_TREASURY_HYPEREVM, DAO_TREASURY_MONAD, DAO_TREASURY_OPTIMISM, DAO_TREASURY_POLYGON, DAO_TREASURY_SOLANA, DAO_TREASURY_STARKNET, DAO_TREASURY_TON, isTreasuryChainId, } from '@shapeshiftoss/utils';
|
|
4
4
|
export const isNativeEvmAsset = (assetId) => {
|
|
5
5
|
const { chainId } = fromAssetId(assetId);
|
|
6
6
|
switch (chainId) {
|
|
@@ -42,6 +42,9 @@ const DAO_TREASURY_BY_CHAIN_ID = {
|
|
|
42
42
|
[KnownChainIds.SolanaMainnet]: DAO_TREASURY_SOLANA,
|
|
43
43
|
[KnownChainIds.BitcoinMainnet]: DAO_TREASURY_BITCOIN,
|
|
44
44
|
[KnownChainIds.StarknetMainnet]: DAO_TREASURY_STARKNET,
|
|
45
|
+
[KnownChainIds.TonMainnet]: DAO_TREASURY_TON,
|
|
46
|
+
[KnownChainIds.MonadMainnet]: DAO_TREASURY_MONAD,
|
|
47
|
+
[KnownChainIds.HyperEvmMainnet]: DAO_TREASURY_HYPEREVM,
|
|
45
48
|
};
|
|
46
49
|
export const getTreasuryAddressFromChainId = (chainId) => {
|
|
47
50
|
const maybeTreasuryChainId = isTreasuryChainId(chainId) ? chainId : undefined;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Asset } from '@shapeshiftoss/types';
|
|
2
2
|
import type { SwapperConfig, SwapperName } from '../types.js';
|
|
3
3
|
import type { ThorEvmTradeQuote } from './types.js';
|
|
4
|
-
export declare const getCallDataFromQuote: ({ tradeType, data, sellAsset, sellAmountIncludingProtocolFeesCryptoBaseUnit, memo: tcMemo, expiry, config, longtailData, slippageTolerancePercentageDecimal, vault, swapperName, }: Pick<ThorEvmTradeQuote, "data" | "slippageTolerancePercentageDecimal" | "memo" | "
|
|
4
|
+
export declare const getCallDataFromQuote: ({ tradeType, data, sellAsset, sellAmountIncludingProtocolFeesCryptoBaseUnit, memo: tcMemo, expiry, config, longtailData, slippageTolerancePercentageDecimal, vault, swapperName, }: Pick<ThorEvmTradeQuote, "data" | "slippageTolerancePercentageDecimal" | "memo" | "expiry" | "tradeType" | "aggregator" | "vault" | "longtailData"> & {
|
|
5
5
|
sellAmountIncludingProtocolFeesCryptoBaseUnit: string;
|
|
6
6
|
config: SwapperConfig;
|
|
7
7
|
sellAsset: Asset;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CHAIN_NAMESPACE, fromAssetId } from '@shapeshiftoss/caip';
|
|
2
2
|
import * as adapters from '@shapeshiftoss/chain-adapters';
|
|
3
|
-
import { assertUnreachable, bn, bnOrZero, contractAddressOrUndefined, convertDecimalPercentageToBasisPoints, convertPrecision,
|
|
3
|
+
import { assertUnreachable, BigAmount, bn, bnOrZero, contractAddressOrUndefined, convertDecimalPercentageToBasisPoints, convertPrecision, isFulfilled, isRejected, } from '@shapeshiftoss/utils';
|
|
4
4
|
import { Err, Ok } from '@sniptt/monads';
|
|
5
5
|
import { TronWeb } from 'tronweb';
|
|
6
6
|
import { v4 as uuid } from 'uuid';
|
|
@@ -75,7 +75,13 @@ export const getL1RateOrQuote = async (input, deps, streamingInterval, tradeType
|
|
|
75
75
|
: '0';
|
|
76
76
|
const getRouteBuyAmountBeforeFeesCryptoBaseUnit = (quote) => {
|
|
77
77
|
const buyAmountBeforeFeesCryptoThorPrecision = bn(quote.expected_amount_out).plus(quote.fees.total);
|
|
78
|
-
return
|
|
78
|
+
return BigAmount.fromPrecision({
|
|
79
|
+
value: BigAmount.fromBaseUnit({
|
|
80
|
+
value: buyAmountBeforeFeesCryptoThorPrecision,
|
|
81
|
+
precision: buyAssetNativePrecision,
|
|
82
|
+
}).toPrecision(),
|
|
83
|
+
precision: buyAsset.precision,
|
|
84
|
+
}).toBaseUnit();
|
|
79
85
|
};
|
|
80
86
|
const getProtocolFees = (quote) => {
|
|
81
87
|
// Fees consist of liquidity, outbound, and affiliate fees
|
|
@@ -215,7 +221,11 @@ export const getL1RateOrQuote = async (input, deps, streamingInterval, tradeType
|
|
|
215
221
|
const sellAdapter = assertGetUtxoChainAdapter(sellAsset.chainId);
|
|
216
222
|
const maybeRoutes = await Promise.allSettled(perRouteValues.map(async (route) => {
|
|
217
223
|
const memo = getMemo(route);
|
|
218
|
-
const { vault } = await utxo.getThorTxData({
|
|
224
|
+
const { vault } = await utxo.getThorTxData({
|
|
225
|
+
sellAsset,
|
|
226
|
+
config,
|
|
227
|
+
swapperName,
|
|
228
|
+
});
|
|
219
229
|
const feeData = await (async () => {
|
|
220
230
|
const protocolFees = getProtocolFees(route.quote);
|
|
221
231
|
// This is a rate without a wallet connected, so we can't get fees
|
|
@@ -284,9 +294,15 @@ export const getL1RateOrQuote = async (input, deps, streamingInterval, tradeType
|
|
|
284
294
|
const { sellAsset, sellAmountIncludingProtocolFeesCryptoBaseUnit } = input;
|
|
285
295
|
const contractAddress = contractAddressOrUndefined(sellAsset.assetId);
|
|
286
296
|
// Get vault address
|
|
287
|
-
const { vault } = await tron.getThorTxData({
|
|
297
|
+
const { vault } = await tron.getThorTxData({
|
|
298
|
+
sellAsset,
|
|
299
|
+
config,
|
|
300
|
+
swapperName,
|
|
301
|
+
});
|
|
288
302
|
// Estimate fees using the receive address for accurate energy calculation
|
|
289
|
-
const tronWeb = new TronWeb({
|
|
303
|
+
const tronWeb = new TronWeb({
|
|
304
|
+
fullHost: deps.config.VITE_TRON_NODE_URL,
|
|
305
|
+
});
|
|
290
306
|
const params = await tronWeb.trx.getChainParameters();
|
|
291
307
|
const bandwidthPrice = params.find(p => p.key === 'getTransactionFee')?.value ?? 1000;
|
|
292
308
|
const energyPrice = params.find(p => p.key === 'getEnergyFee')?.value ?? 100;
|
|
@@ -296,7 +312,10 @@ export const getL1RateOrQuote = async (input, deps, streamingInterval, tradeType
|
|
|
296
312
|
try {
|
|
297
313
|
const result = await tronWeb.transactionBuilder.triggerConstantContract(contractAddress, 'transfer(address,uint256)', {}, [
|
|
298
314
|
{ type: 'address', value: vault },
|
|
299
|
-
{
|
|
315
|
+
{
|
|
316
|
+
type: 'uint256',
|
|
317
|
+
value: sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
318
|
+
},
|
|
300
319
|
], input.receiveAddress);
|
|
301
320
|
const energyUsed = result.energy_used ?? 65000;
|
|
302
321
|
const energyFee = energyUsed * energyPrice * 1.5; // 1.5x safety margin
|
|
@@ -361,6 +380,12 @@ export const getL1RateOrQuote = async (input, deps, streamingInterval, tradeType
|
|
|
361
380
|
code: TradeQuoteError.UnsupportedTradePair,
|
|
362
381
|
}));
|
|
363
382
|
}
|
|
383
|
+
case CHAIN_NAMESPACE.Ton: {
|
|
384
|
+
return Err(makeSwapErrorRight({
|
|
385
|
+
message: 'TON is not supported',
|
|
386
|
+
code: TradeQuoteError.UnsupportedTradePair,
|
|
387
|
+
}));
|
|
388
|
+
}
|
|
364
389
|
default:
|
|
365
390
|
return assertUnreachable(chainNamespace);
|
|
366
391
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { bchAssetId } from '@shapeshiftoss/caip';
|
|
2
|
-
import {
|
|
2
|
+
import { BigAmount, bn } from '@shapeshiftoss/utils';
|
|
3
3
|
import { Err, Ok } from '@sniptt/monads';
|
|
4
4
|
import qs from 'qs';
|
|
5
5
|
import { TradeQuoteError } from '../types.js';
|
|
@@ -19,9 +19,15 @@ export const getQuote = async (input, deps) => {
|
|
|
19
19
|
});
|
|
20
20
|
const buyPoolId = getPoolAssetId({ assetId: buyAssetId, swapperName });
|
|
21
21
|
const sellPoolId = getPoolAssetId({ assetId: sellAsset.assetId, swapperName });
|
|
22
|
-
const sellAmountCryptoPrecision = fromBaseUnit(
|
|
22
|
+
const sellAmountCryptoPrecision = BigAmount.fromBaseUnit({
|
|
23
|
+
value: sellAmountCryptoBaseUnit,
|
|
24
|
+
precision: sellAsset.precision,
|
|
25
|
+
}).toPrecision();
|
|
23
26
|
// All pool amounts are native precision regardless of token precision
|
|
24
|
-
const sellAmountCryptoThorBaseUnit = bn(
|
|
27
|
+
const sellAmountCryptoThorBaseUnit = bn(BigAmount.fromPrecision({
|
|
28
|
+
value: sellAmountCryptoPrecision,
|
|
29
|
+
precision: getNativePrecision(sellAsset.assetId, swapperName),
|
|
30
|
+
}).toBaseUnit());
|
|
25
31
|
// The swap endpoint expects BCH receiveAddress's to be stripped of the "bitcoincash:" prefix
|
|
26
32
|
const parsedReceiveAddress = receiveAddress && buyAssetId === bchAssetId
|
|
27
33
|
? receiveAddress.replace('bitcoincash:', '')
|
|
@@ -1,16 +1,36 @@
|
|
|
1
|
+
import { tronAssetId } from '@shapeshiftoss/caip';
|
|
1
2
|
import { contractAddressOrUndefined } from '@shapeshiftoss/utils';
|
|
2
3
|
import { getExecutableTradeStep, isExecutableTradeQuote } from '../utils.js';
|
|
3
4
|
export const getUnsignedTronTransaction = ({ stepIndex, tradeQuote, from, assertGetTronChainAdapter, }) => {
|
|
4
5
|
if (!isExecutableTradeQuote(tradeQuote))
|
|
5
6
|
throw new Error('Unable to execute a trade rate quote');
|
|
6
7
|
const step = getExecutableTradeStep(tradeQuote, stepIndex);
|
|
7
|
-
const { accountNumber, sellAsset, relayTransactionMetadata, nearIntentsSpecific } = step;
|
|
8
|
+
const { accountNumber, sellAsset, relayTransactionMetadata, nearIntentsSpecific, butterSwapTransactionMetadata, } = step;
|
|
8
9
|
const adapter = assertGetTronChainAdapter(sellAsset.chainId);
|
|
10
|
+
if (butterSwapTransactionMetadata) {
|
|
11
|
+
const { to, data, method, args, value: butterValue } = butterSwapTransactionMetadata;
|
|
12
|
+
if (!to)
|
|
13
|
+
throw new Error('Missing Butter swap contract address');
|
|
14
|
+
if (!data)
|
|
15
|
+
throw new Error('Missing Butter swap transaction data');
|
|
16
|
+
// Use Butter's value field which includes swap fees for same-chain swaps
|
|
17
|
+
// For native TRX sells, also include the sell amount
|
|
18
|
+
const isNativeTron = sellAsset.assetId === tronAssetId;
|
|
19
|
+
const value = isNativeTron ? step.sellAmountIncludingProtocolFeesCryptoBaseUnit : butterValue;
|
|
20
|
+
return adapter.buildCustomApiTx({
|
|
21
|
+
from,
|
|
22
|
+
to,
|
|
23
|
+
accountNumber,
|
|
24
|
+
data,
|
|
25
|
+
value,
|
|
26
|
+
method,
|
|
27
|
+
args,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
9
30
|
const to = relayTransactionMetadata?.to ?? nearIntentsSpecific?.depositAddress;
|
|
10
31
|
if (!to)
|
|
11
32
|
throw new Error('Missing transaction destination address');
|
|
12
33
|
const value = step.sellAmountIncludingProtocolFeesCryptoBaseUnit;
|
|
13
|
-
// Extract contract address for TRC20 tokens
|
|
14
34
|
const contractAddress = contractAddressOrUndefined(sellAsset.assetId);
|
|
15
35
|
return adapter.buildSendApiTransaction({
|
|
16
36
|
to,
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { QuoteResponse } from '@jup-ag/api';
|
|
2
2
|
import type { AccountId, AssetId, ChainId, Nominal } from '@shapeshiftoss/caip';
|
|
3
|
-
import type { ChainAdapter, CosmosSdkChainAdapter, EvmChainAdapter, near, SignTx, solana, starknet, sui, tron, UtxoChainAdapter } from '@shapeshiftoss/chain-adapters';
|
|
3
|
+
import type { ChainAdapter, CosmosSdkChainAdapter, EvmChainAdapter, near, SignTx, solana, starknet, sui, ton, tron, UtxoChainAdapter } from '@shapeshiftoss/chain-adapters';
|
|
4
4
|
import type { HDWallet, SolanaSignTx, StarknetSignTx, SuiSignTx } from '@shapeshiftoss/hdwallet-core';
|
|
5
|
-
import type { AccountMetadata, Asset, AssetsByIdPartial, CosmosSdkChainId, EvmChainId, KnownChainIds, NearChainId, OrderQuoteResponse, PartialRecord, TronChainId, UtxoAccountType, UtxoChainId } from '@shapeshiftoss/types';
|
|
5
|
+
import type { AccountMetadata, Asset, AssetsByIdPartial, CosmosSdkChainId, EvmChainId, KnownChainIds, NearChainId, OrderQuoteResponse, PartialRecord, TonChainId, TronChainId, UtxoAccountType, UtxoChainId } from '@shapeshiftoss/types';
|
|
6
6
|
import type { TxStatus } from '@shapeshiftoss/unchained-client';
|
|
7
7
|
import type { Result } from '@sniptt/monads';
|
|
8
8
|
import type { TransactionInstruction } from '@solana/web3.js';
|
|
@@ -11,6 +11,7 @@ import type { Mixpanel } from 'mixpanel-browser';
|
|
|
11
11
|
import type Polyglot from 'node-polyglot';
|
|
12
12
|
import type { InterpolationOptions } from 'node-polyglot';
|
|
13
13
|
import type { Address, Hex } from 'viem';
|
|
14
|
+
import type { AcrossTransactionMetadata } from './swappers/AcrossSwapper/utils/types.js';
|
|
14
15
|
import type { CowMessageToSign } from './swappers/CowSwapper/types.js';
|
|
15
16
|
import type { RelayTransactionMetadata } from './swappers/RelaySwapper/utils/types.js';
|
|
16
17
|
import type { makeSwapperAxiosServiceMonadic } from './utils.js';
|
|
@@ -47,6 +48,8 @@ export type SwapperConfig = {
|
|
|
47
48
|
VITE_TENDERLY_ACCOUNT_SLUG: string;
|
|
48
49
|
VITE_TENDERLY_PROJECT_SLUG: string;
|
|
49
50
|
VITE_SUI_NODE_URL: string;
|
|
51
|
+
VITE_ACROSS_API_URL: string;
|
|
52
|
+
VITE_ACROSS_INTEGRATOR_ID: string;
|
|
50
53
|
};
|
|
51
54
|
export declare enum SwapperName {
|
|
52
55
|
Thorchain = "THORChain",
|
|
@@ -64,7 +67,9 @@ export declare enum SwapperName {
|
|
|
64
67
|
NearIntents = "NEAR Intents",
|
|
65
68
|
Cetus = "Cetus",
|
|
66
69
|
Sunio = "Sun.io",
|
|
67
|
-
Avnu = "AVNU"
|
|
70
|
+
Avnu = "AVNU",
|
|
71
|
+
Stonfi = "STON.fi",
|
|
72
|
+
Across = "Across"
|
|
68
73
|
}
|
|
69
74
|
export type SwapSource = SwapperName | `${SwapperName} • ${string}`;
|
|
70
75
|
export type SwapErrorRight = {
|
|
@@ -183,6 +188,15 @@ export type GetNearTradeQuoteInput = CommonTradeInput & {
|
|
|
183
188
|
export type GetNearTradeRateInput = CommonTradeRateInput & {
|
|
184
189
|
chainId: NearChainId;
|
|
185
190
|
};
|
|
191
|
+
export type GetTonTradeQuoteInputBase = CommonTradeInput & {
|
|
192
|
+
chainId: TonChainId;
|
|
193
|
+
};
|
|
194
|
+
export type GetTonTradeQuoteInput = CommonTradeInput & {
|
|
195
|
+
chainId: TonChainId;
|
|
196
|
+
};
|
|
197
|
+
export type GetTonTradeRateInput = CommonTradeRateInput & {
|
|
198
|
+
chainId: TonChainId;
|
|
199
|
+
};
|
|
186
200
|
type GetUtxoTradeQuoteWithWallet = CommonTradeQuoteInput & {
|
|
187
201
|
chainId: UtxoChainId;
|
|
188
202
|
accountType: UtxoAccountType;
|
|
@@ -196,9 +210,9 @@ export type GetUtxoTradeRateInput = CommonTradeRateInput & {
|
|
|
196
210
|
xpub: string | undefined;
|
|
197
211
|
};
|
|
198
212
|
export type GetUtxoTradeQuoteInput = GetUtxoTradeQuoteWithWallet;
|
|
199
|
-
export type GetTradeQuoteInput = GetUtxoTradeQuoteInput | GetEvmTradeQuoteInput | GetCosmosSdkTradeQuoteInput | GetTronTradeQuoteInput | GetNearTradeQuoteInput;
|
|
200
|
-
export type GetTradeRateInput = GetEvmTradeRateInput | GetCosmosSdkTradeRateInput | GetUtxoTradeRateInput | GetTronTradeRateInput | GetNearTradeRateInput;
|
|
201
|
-
export type GetTradeQuoteInputWithWallet = GetUtxoTradeQuoteWithWallet | GetEvmTradeQuoteInputBase | GetCosmosSdkTradeQuoteInputBase | GetTronTradeQuoteInputBase | GetNearTradeQuoteInputBase;
|
|
213
|
+
export type GetTradeQuoteInput = GetUtxoTradeQuoteInput | GetEvmTradeQuoteInput | GetCosmosSdkTradeQuoteInput | GetTronTradeQuoteInput | GetNearTradeQuoteInput | GetTonTradeQuoteInput;
|
|
214
|
+
export type GetTradeRateInput = GetEvmTradeRateInput | GetCosmosSdkTradeRateInput | GetUtxoTradeRateInput | GetTronTradeRateInput | GetNearTradeRateInput | GetTonTradeRateInput;
|
|
215
|
+
export type GetTradeQuoteInputWithWallet = GetUtxoTradeQuoteWithWallet | GetEvmTradeQuoteInputBase | GetCosmosSdkTradeQuoteInputBase | GetTronTradeQuoteInputBase | GetNearTradeQuoteInputBase | GetTonTradeQuoteInputBase;
|
|
202
216
|
export type EvmSwapperDeps = {
|
|
203
217
|
assertGetEvmChainAdapter: (chainId: ChainId) => EvmChainAdapter;
|
|
204
218
|
fetchIsSmartContractAddressQuery: (userAddress: string, chainId: ChainId) => Promise<boolean>;
|
|
@@ -224,12 +238,15 @@ export type NearSwapperDeps = {
|
|
|
224
238
|
export type StarknetSwapperDeps = {
|
|
225
239
|
assertGetStarknetChainAdapter: (chainId: ChainId) => starknet.ChainAdapter;
|
|
226
240
|
};
|
|
241
|
+
export type TonSwapperDeps = {
|
|
242
|
+
assertGetTonChainAdapter: (chainId: ChainId) => ton.ChainAdapter;
|
|
243
|
+
};
|
|
227
244
|
export type SwapperDeps = {
|
|
228
245
|
assetsById: AssetsByIdPartial;
|
|
229
246
|
config: SwapperConfig;
|
|
230
247
|
mixPanel: Mixpanel | undefined;
|
|
231
248
|
assertGetChainAdapter: (chainId: ChainId) => ChainAdapter<KnownChainIds>;
|
|
232
|
-
} & EvmSwapperDeps & UtxoSwapperDeps & CosmosSdkSwapperDeps & SolanaSwapperDeps & TronSwapperDeps & SuiSwapperDeps & NearSwapperDeps & StarknetSwapperDeps;
|
|
249
|
+
} & EvmSwapperDeps & UtxoSwapperDeps & CosmosSdkSwapperDeps & SolanaSwapperDeps & TronSwapperDeps & SuiSwapperDeps & NearSwapperDeps & StarknetSwapperDeps & TonSwapperDeps;
|
|
233
250
|
export type TradeQuoteStep = {
|
|
234
251
|
buyAmountBeforeFeesCryptoBaseUnit: string;
|
|
235
252
|
buyAmountAfterFeesCryptoBaseUnit: string;
|
|
@@ -297,6 +314,13 @@ export type TradeQuoteStep = {
|
|
|
297
314
|
data: string;
|
|
298
315
|
value: Hex;
|
|
299
316
|
gasLimit: string;
|
|
317
|
+
method?: string;
|
|
318
|
+
args?: {
|
|
319
|
+
type: string;
|
|
320
|
+
value: unknown;
|
|
321
|
+
}[];
|
|
322
|
+
memo?: string;
|
|
323
|
+
serializedSolanaTransaction?: string;
|
|
300
324
|
};
|
|
301
325
|
sunioTransactionMetadata?: {
|
|
302
326
|
route: {
|
|
@@ -317,6 +341,41 @@ export type TradeQuoteStep = {
|
|
|
317
341
|
quoteId: string;
|
|
318
342
|
routes: any[];
|
|
319
343
|
};
|
|
344
|
+
stonfiSpecific?: {
|
|
345
|
+
quoteId: string;
|
|
346
|
+
resolverId: string;
|
|
347
|
+
resolverName: string;
|
|
348
|
+
tradeStartDeadline: number;
|
|
349
|
+
gasBudget: string;
|
|
350
|
+
bidAssetAddress: {
|
|
351
|
+
blockchain: number;
|
|
352
|
+
address: string;
|
|
353
|
+
};
|
|
354
|
+
askAssetAddress: {
|
|
355
|
+
blockchain: number;
|
|
356
|
+
address: string;
|
|
357
|
+
};
|
|
358
|
+
bidUnits: string;
|
|
359
|
+
askUnits: string;
|
|
360
|
+
referrerAddress?: {
|
|
361
|
+
blockchain: number;
|
|
362
|
+
address: string;
|
|
363
|
+
};
|
|
364
|
+
referrerFeeAsset?: {
|
|
365
|
+
blockchain: number;
|
|
366
|
+
address: string;
|
|
367
|
+
};
|
|
368
|
+
referrerFeeUnits: string;
|
|
369
|
+
protocolFeeAsset?: {
|
|
370
|
+
blockchain: number;
|
|
371
|
+
address: string;
|
|
372
|
+
};
|
|
373
|
+
protocolFeeUnits: string;
|
|
374
|
+
quoteTimestamp: number;
|
|
375
|
+
estimatedGasConsumption: string;
|
|
376
|
+
params?: unknown;
|
|
377
|
+
};
|
|
378
|
+
acrossTransactionMetadata?: AcrossTransactionMetadata;
|
|
320
379
|
};
|
|
321
380
|
export type TradeRateStep = Omit<TradeQuoteStep, 'accountNumber'> & {
|
|
322
381
|
accountNumber: undefined;
|
|
@@ -370,6 +429,7 @@ export type SwapperSpecificMetadata = {
|
|
|
370
429
|
deadline: string;
|
|
371
430
|
};
|
|
372
431
|
relayTransactionMetadata: RelayTransactionMetadata | undefined;
|
|
432
|
+
acrossTransactionMetadata: AcrossTransactionMetadata | undefined;
|
|
373
433
|
relayerExplorerTxLink: string | undefined;
|
|
374
434
|
relayerTxHash: string | undefined;
|
|
375
435
|
stepIndex: SupportedTradeQuoteStepIndex;
|
|
@@ -475,6 +535,9 @@ export type NearTransactionExecutionProps = {
|
|
|
475
535
|
export type StarknetTransactionExecutionProps = {
|
|
476
536
|
signAndBroadcastTransaction: (txToSign: StarknetSignTx) => Promise<string>;
|
|
477
537
|
};
|
|
538
|
+
export type TonTransactionExecutionProps = {
|
|
539
|
+
signAndBroadcastTransaction: (txToSign: ton.TonSignTx) => Promise<string>;
|
|
540
|
+
};
|
|
478
541
|
type EvmAccountMetadata = {
|
|
479
542
|
from: string;
|
|
480
543
|
};
|
|
@@ -517,6 +580,10 @@ export type GetUnsignedTronTransactionArgs = CommonGetUnsignedTransactionArgs &
|
|
|
517
580
|
export type GetUnsignedSuiTransactionArgs = CommonGetUnsignedTransactionArgs & SuiAccountMetadata & SuiSwapperDeps;
|
|
518
581
|
export type GetUnsignedNearTransactionArgs = CommonGetUnsignedTransactionArgs & NearAccountMetadata & NearSwapperDeps;
|
|
519
582
|
export type GetUnsignedStarknetTransactionArgs = CommonGetUnsignedTransactionArgs & StarknetAccountMetadata & StarknetSwapperDeps;
|
|
583
|
+
type TonAccountMetadata = {
|
|
584
|
+
from: string;
|
|
585
|
+
};
|
|
586
|
+
export type GetUnsignedTonTransactionArgs = CommonGetUnsignedTransactionArgs & TonAccountMetadata & TonSwapperDeps;
|
|
520
587
|
export type GetUnsignedEvmMessageArgs = CommonGetUnsignedTransactionArgs & EvmAccountMetadata & Omit<EvmSwapperDeps, 'fetchIsSmartContractAddressQuery'>;
|
|
521
588
|
export type GetUnsignedUtxoTransactionArgs = CommonGetUnsignedTransactionArgs & UtxoAccountMetadata & UtxoSwapperDeps;
|
|
522
589
|
export type GetUnsignedCosmosSdkTransactionArgs = CommonGetUnsignedTransactionArgs & CosmosSdkAccountMetadata & CosmosSdkSwapperDeps;
|
|
@@ -535,7 +602,7 @@ export type CheckTradeStatusInput = {
|
|
|
535
602
|
stepIndex: SupportedTradeQuoteStepIndex;
|
|
536
603
|
config: SwapperConfig;
|
|
537
604
|
swap: Swap | undefined;
|
|
538
|
-
} & EvmSwapperDeps & UtxoSwapperDeps & CosmosSdkSwapperDeps & SolanaSwapperDeps & TronSwapperDeps & SuiSwapperDeps & NearSwapperDeps & StarknetSwapperDeps;
|
|
605
|
+
} & EvmSwapperDeps & UtxoSwapperDeps & CosmosSdkSwapperDeps & SolanaSwapperDeps & TronSwapperDeps & SuiSwapperDeps & NearSwapperDeps & StarknetSwapperDeps & TonSwapperDeps;
|
|
539
606
|
export type TradeStatus = {
|
|
540
607
|
status: TxStatus;
|
|
541
608
|
buyTxHash: string | undefined;
|
|
@@ -558,6 +625,7 @@ export type Swapper = {
|
|
|
558
625
|
executeSuiTransaction?: (txToSign: SuiSignTx, callbacks: SuiTransactionExecutionProps) => Promise<string>;
|
|
559
626
|
executeNearTransaction?: (txToSign: near.NearSignTx, callbacks: NearTransactionExecutionProps) => Promise<string>;
|
|
560
627
|
executeStarknetTransaction?: (txToSign: StarknetSignTx, callbacks: StarknetTransactionExecutionProps) => Promise<string>;
|
|
628
|
+
executeTonTransaction?: (txToSign: ton.TonSignTx, callbacks: TonTransactionExecutionProps) => Promise<string>;
|
|
561
629
|
};
|
|
562
630
|
export type SwapperApi = {
|
|
563
631
|
checkTradeStatus: (input: CheckTradeStatusInput) => Promise<TradeStatus>;
|
|
@@ -573,6 +641,7 @@ export type SwapperApi = {
|
|
|
573
641
|
getUnsignedSuiTransaction?: (input: GetUnsignedSuiTransactionArgs) => Promise<SuiSignTx>;
|
|
574
642
|
getUnsignedNearTransaction?: (input: GetUnsignedNearTransactionArgs) => Promise<near.NearSignTx>;
|
|
575
643
|
getUnsignedStarknetTransaction?: (input: GetUnsignedStarknetTransactionArgs) => Promise<StarknetSignTx>;
|
|
644
|
+
getUnsignedTonTransaction?: (input: GetUnsignedTonTransactionArgs) => Promise<ton.TonSignTx>;
|
|
576
645
|
getEvmTransactionFees?: (input: GetUnsignedEvmTransactionArgs) => Promise<string>;
|
|
577
646
|
getSolanaTransactionFees?: (input: GetUnsignedSolanaTransactionArgs) => Promise<string>;
|
|
578
647
|
getSuiTransactionFees?: (input: GetUnsignedSuiTransactionArgs) => Promise<string>;
|
|
@@ -581,6 +650,7 @@ export type SwapperApi = {
|
|
|
581
650
|
getTronTransactionFees?: (input: GetUnsignedTronTransactionArgs) => Promise<string>;
|
|
582
651
|
getNearTransactionFees?: (input: GetUnsignedNearTransactionArgs) => Promise<string>;
|
|
583
652
|
getStarknetTransactionFees?: (input: GetUnsignedStarknetTransactionArgs) => Promise<string>;
|
|
653
|
+
getTonTransactionFees?: (input: GetUnsignedTonTransactionArgs) => Promise<string>;
|
|
584
654
|
};
|
|
585
655
|
export type QuoteResult = Result<TradeQuote[], SwapErrorRight> & {
|
|
586
656
|
swapperName: SwapperName;
|
|
@@ -607,6 +677,7 @@ export type TronTransactionExecutionInput = CommonTradeExecutionInput & TronTran
|
|
|
607
677
|
export type SuiTransactionExecutionInput = CommonTradeExecutionInput & SuiTransactionExecutionProps & SuiAccountMetadata;
|
|
608
678
|
export type NearTransactionExecutionInput = CommonTradeExecutionInput & NearTransactionExecutionProps & NearAccountMetadata;
|
|
609
679
|
export type StarknetTransactionExecutionInput = CommonTradeExecutionInput & StarknetTransactionExecutionProps & StarknetAccountMetadata;
|
|
680
|
+
export type TonTransactionExecutionInput = CommonTradeExecutionInput & TonTransactionExecutionProps & TonAccountMetadata;
|
|
610
681
|
export declare enum TradeExecutionEvent {
|
|
611
682
|
SellTxHash = "sellTxHash",
|
|
612
683
|
RelayerTxHash = "relayerTxHash",
|
package/dist/esm/types.js
CHANGED
|
@@ -16,6 +16,8 @@ export var SwapperName;
|
|
|
16
16
|
SwapperName["Cetus"] = "Cetus";
|
|
17
17
|
SwapperName["Sunio"] = "Sun.io";
|
|
18
18
|
SwapperName["Avnu"] = "AVNU";
|
|
19
|
+
SwapperName["Stonfi"] = "STON.fi";
|
|
20
|
+
SwapperName["Across"] = "Across";
|
|
19
21
|
})(SwapperName || (SwapperName = {}));
|
|
20
22
|
export var TradeQuoteError;
|
|
21
23
|
(function (TradeQuoteError) {
|
package/dist/esm/utils.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { AssetId, ChainId } from '@shapeshiftoss/caip';
|
|
2
|
-
import type { EvmChainAdapter, near, SignTx, solana, starknet, sui } from '@shapeshiftoss/chain-adapters';
|
|
2
|
+
import type { EvmChainAdapter, near, SignTx, solana, starknet, sui, ton } from '@shapeshiftoss/chain-adapters';
|
|
3
|
+
import type { TronSignTx } from '@shapeshiftoss/chain-adapters/src/tron/types';
|
|
3
4
|
import type { SolanaSignTx, StarknetSignTx, SuiSignTx } from '@shapeshiftoss/hdwallet-core';
|
|
4
5
|
import type { Asset, EvmChainId } from '@shapeshiftoss/types';
|
|
5
6
|
import { TxStatus } from '@shapeshiftoss/unchained-client';
|
|
6
7
|
import type { Result } from '@sniptt/monads';
|
|
7
8
|
import type { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
8
|
-
import type {
|
|
9
|
-
import type { EvmTransactionExecutionProps, ExecutableTradeStep, NearTransactionExecutionProps, SolanaTransactionExecutionProps, StarknetTransactionExecutionProps, SuiTransactionExecutionProps, SupportedTradeQuoteStepIndex, SwapErrorRight, TradeQuote, TradeQuoteStep, TradeRate, TradeStatus, TronTransactionExecutionProps } from './types.js';
|
|
9
|
+
import type { EvmTransactionExecutionProps, ExecutableTradeStep, NearTransactionExecutionProps, SolanaTransactionExecutionProps, StarknetTransactionExecutionProps, SuiTransactionExecutionProps, SupportedTradeQuoteStepIndex, SwapErrorRight, TonTransactionExecutionProps, TradeQuote, TradeQuoteStep, TradeRate, TradeStatus, TronTransactionExecutionProps } from './types.js';
|
|
10
10
|
import { TradeQuoteError } from './types.js';
|
|
11
11
|
export declare const makeSwapErrorRight: ({ details, cause, code, message, }: {
|
|
12
12
|
message: string;
|
|
@@ -32,6 +32,7 @@ export declare const executeTronTransaction: (txToSign: TronSignTx, callbacks: T
|
|
|
32
32
|
export declare const executeSuiTransaction: (txToSign: SuiSignTx, callbacks: SuiTransactionExecutionProps) => Promise<string>;
|
|
33
33
|
export declare const executeNearTransaction: (txToSign: near.NearSignTx, callbacks: NearTransactionExecutionProps) => Promise<string>;
|
|
34
34
|
export declare const executeStarknetTransaction: (txToSign: StarknetSignTx, callbacks: StarknetTransactionExecutionProps) => Promise<string>;
|
|
35
|
+
export declare const executeTonTransaction: (txToSign: ton.TonSignTx, callbacks: TonTransactionExecutionProps) => Promise<string>;
|
|
35
36
|
export declare const createDefaultStatusResponse: (buyTxHash?: string) => {
|
|
36
37
|
status: TxStatus;
|
|
37
38
|
buyTxHash: string | undefined;
|