@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
package/dist/esm/constants.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { assertUnreachable } from '@shapeshiftoss/utils';
|
|
2
|
+
import { acrossSwapper } from './swappers/AcrossSwapper/index.js';
|
|
3
|
+
import { acrossApi } from './swappers/AcrossSwapper/endpoints.js';
|
|
2
4
|
import { arbitrumBridgeSwapper } from './swappers/ArbitrumBridgeSwapper/ArbitrumBridgeSwapper.js';
|
|
3
5
|
import { arbitrumBridgeApi } from './swappers/ArbitrumBridgeSwapper/endpoints.js';
|
|
4
6
|
import { avnuSwapper } from './swappers/AvnuSwapper/AvnuSwapper.js';
|
|
@@ -23,6 +25,8 @@ import { portalsApi } from './swappers/PortalsSwapper/endpoints.js';
|
|
|
23
25
|
import { portalsSwapper } from './swappers/PortalsSwapper/PortalsSwapper.js';
|
|
24
26
|
import { relaySwapper } from './swappers/RelaySwapper/index.js';
|
|
25
27
|
import { relayApi } from './swappers/RelaySwapper/endpoints.js';
|
|
28
|
+
import { stonfiApi } from './swappers/StonfiSwapper/endpoints.js';
|
|
29
|
+
import { stonfiSwapper } from './swappers/StonfiSwapper/StonfiSwapper.js';
|
|
26
30
|
import { sunioApi } from './swappers/SunioSwapper/endpoints.js';
|
|
27
31
|
import { sunioSwapper } from './swappers/SunioSwapper/SunioSwapper.js';
|
|
28
32
|
import { thorchainApi } from './swappers/ThorchainSwapper/endpoints.js';
|
|
@@ -99,21 +103,30 @@ export const swappers = {
|
|
|
99
103
|
...avnuSwapper,
|
|
100
104
|
...avnuApi,
|
|
101
105
|
},
|
|
106
|
+
[SwapperName.Stonfi]: {
|
|
107
|
+
...stonfiSwapper,
|
|
108
|
+
...stonfiApi,
|
|
109
|
+
},
|
|
110
|
+
[SwapperName.Across]: {
|
|
111
|
+
...acrossSwapper,
|
|
112
|
+
...acrossApi,
|
|
113
|
+
},
|
|
102
114
|
[SwapperName.Test]: undefined,
|
|
103
115
|
};
|
|
104
|
-
|
|
105
|
-
const
|
|
106
|
-
const
|
|
107
|
-
const
|
|
108
|
-
const
|
|
109
|
-
const
|
|
110
|
-
const
|
|
111
|
-
const
|
|
112
|
-
const
|
|
113
|
-
const
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
const DEFAULT_AVNU_SLIPPAGE_DECIMAL_PERCENTAGE = '0.
|
|
116
|
+
const DEFAULT_SLIPPAGE_DECIMAL_PERCENTAGE = '0.002';
|
|
117
|
+
const DEFAULT_COWSWAP_SLIPPAGE_DECIMAL_PERCENTAGE = '0.005';
|
|
118
|
+
const DEFAULT_NEAR_INTENTS_SLIPPAGE_DECIMAL_PERCENTAGE = '0.005';
|
|
119
|
+
const DEFAULT_PORTALS_SLIPPAGE_DECIMAL_PERCENTAGE = '0.025';
|
|
120
|
+
const DEFAULT_THOR_SLIPPAGE_DECIMAL_PERCENTAGE = '0.01';
|
|
121
|
+
const DEFAULT_MAYA_SLIPPAGE_DECIMAL_PERCENTAGE = '0.01';
|
|
122
|
+
const DEFAULT_ARBITRUM_BRIDGE_SLIPPAGE_DECIMAL_PERCENTAGE = '0';
|
|
123
|
+
const DEFAULT_CHAINFLIP_SLIPPAGE_DECIMAL_PERCENTAGE = '0.02';
|
|
124
|
+
const DEFAULT_BUTTERSWAP_SLIPPAGE_DECIMAL_PERCENTAGE = '0.015';
|
|
125
|
+
const DEFAULT_CETUS_SLIPPAGE_DECIMAL_PERCENTAGE = '0.005';
|
|
126
|
+
const DEFAULT_SUNIO_SLIPPAGE_DECIMAL_PERCENTAGE = '0.005';
|
|
127
|
+
// Starknet swaps can have more latency, so use higher default slippage
|
|
128
|
+
const DEFAULT_AVNU_SLIPPAGE_DECIMAL_PERCENTAGE = '0.02';
|
|
129
|
+
const DEFAULT_STONFI_SLIPPAGE_DECIMAL_PERCENTAGE = '0.01';
|
|
117
130
|
export const getDefaultSlippageDecimalPercentageForSwapper = (swapperName) => {
|
|
118
131
|
if (swapperName === undefined)
|
|
119
132
|
return DEFAULT_SLIPPAGE_DECIMAL_PERCENTAGE;
|
|
@@ -138,6 +151,8 @@ export const getDefaultSlippageDecimalPercentageForSwapper = (swapperName) => {
|
|
|
138
151
|
throw new Error('Default slippage not supported by Jupiter');
|
|
139
152
|
case SwapperName.Relay:
|
|
140
153
|
throw new Error('Default slippage not supported by Relay');
|
|
154
|
+
case SwapperName.Across:
|
|
155
|
+
throw new Error('Default slippage not supported by Across');
|
|
141
156
|
case SwapperName.ButterSwap:
|
|
142
157
|
return DEFAULT_BUTTERSWAP_SLIPPAGE_DECIMAL_PERCENTAGE;
|
|
143
158
|
case SwapperName.NearIntents:
|
|
@@ -148,6 +163,8 @@ export const getDefaultSlippageDecimalPercentageForSwapper = (swapperName) => {
|
|
|
148
163
|
return DEFAULT_SUNIO_SLIPPAGE_DECIMAL_PERCENTAGE;
|
|
149
164
|
case SwapperName.Avnu:
|
|
150
165
|
return DEFAULT_AVNU_SLIPPAGE_DECIMAL_PERCENTAGE;
|
|
166
|
+
case SwapperName.Stonfi:
|
|
167
|
+
return DEFAULT_STONFI_SLIPPAGE_DECIMAL_PERCENTAGE;
|
|
151
168
|
default:
|
|
152
169
|
return assertUnreachable(swapperName);
|
|
153
170
|
}
|
|
@@ -157,6 +174,7 @@ export const isAutoSlippageSupportedBySwapper = (swapperName) => {
|
|
|
157
174
|
case SwapperName.Jupiter:
|
|
158
175
|
return true;
|
|
159
176
|
case SwapperName.Relay:
|
|
177
|
+
case SwapperName.Across:
|
|
160
178
|
return true;
|
|
161
179
|
default:
|
|
162
180
|
return false;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { TradeQuoteError } from '../../types.js';
|
|
2
|
+
export declare const chainIdToAcrossChainId: Record<string, number>;
|
|
3
|
+
export declare const acrossChainIdToChainId: import("lodash").Dictionary<string>;
|
|
4
|
+
export declare const ACROSS_SUPPORTED_CHAIN_IDS: string[];
|
|
5
|
+
export declare const DEFAULT_ACROSS_EVM_TOKEN_ADDRESS: "0x0000000000000000000000000000000000000000";
|
|
6
|
+
export declare const ACROSS_SOLANA_TOKEN_ADDRESS = "11111111111111111111111111111111";
|
|
7
|
+
export declare const DEFAULT_ACROSS_EVM_USER_ADDRESS = "0x000000000000000000000000000000000000dead";
|
|
8
|
+
export declare const DEFAULT_ACROSS_SOLANA_USER_ADDRESS = "CbKGgVKLJFb8bBrf58DnAkdryX6ubewVytn7X957YwNr";
|
|
9
|
+
export declare const acrossErrorCodeToTradeQuoteError: Partial<Record<string, TradeQuoteError>>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { arbitrumChainId, baseChainId, blastChainId, bscChainId, ethChainId, hyperEvmChainId, inkChainId, lineaChainId, modeChainId, monadChainId, optimismChainId, plasmaChainId, polygonChainId, solanaChainId, soneiumChainId, unichainChainId, worldChainChainId, zkSyncEraChainId, } from '@shapeshiftoss/caip';
|
|
2
|
+
import invert from 'lodash/invert';
|
|
3
|
+
import { zeroAddress } from 'viem';
|
|
4
|
+
import { arbitrum, base, blast, bsc, hyperEvm, ink, linea, mainnet as ethereum, mode, monad, optimism, plasma, polygon, soneium, unichain, worldchain, zksync, } from 'viem/chains';
|
|
5
|
+
import { TradeQuoteError } from '../../types.js';
|
|
6
|
+
import { AcrossErrorCode } from './utils/types.js';
|
|
7
|
+
export const chainIdToAcrossChainId = {
|
|
8
|
+
[ethChainId]: ethereum.id,
|
|
9
|
+
[arbitrumChainId]: arbitrum.id,
|
|
10
|
+
[baseChainId]: base.id,
|
|
11
|
+
[optimismChainId]: optimism.id,
|
|
12
|
+
[polygonChainId]: polygon.id,
|
|
13
|
+
[bscChainId]: bsc.id,
|
|
14
|
+
[monadChainId]: monad.id,
|
|
15
|
+
[hyperEvmChainId]: hyperEvm.id,
|
|
16
|
+
[inkChainId]: ink.id,
|
|
17
|
+
[lineaChainId]: linea.id,
|
|
18
|
+
[modeChainId]: mode.id,
|
|
19
|
+
[plasmaChainId]: plasma.id,
|
|
20
|
+
[zkSyncEraChainId]: zksync.id,
|
|
21
|
+
[blastChainId]: blast.id,
|
|
22
|
+
[worldChainChainId]: worldchain.id,
|
|
23
|
+
[unichainChainId]: unichain.id,
|
|
24
|
+
[soneiumChainId]: soneium.id,
|
|
25
|
+
// Across uses a custom Solana chain ID
|
|
26
|
+
[solanaChainId]: 34268394551451,
|
|
27
|
+
};
|
|
28
|
+
export const acrossChainIdToChainId = invert(chainIdToAcrossChainId);
|
|
29
|
+
export const ACROSS_SUPPORTED_CHAIN_IDS = Object.keys(chainIdToAcrossChainId);
|
|
30
|
+
export const DEFAULT_ACROSS_EVM_TOKEN_ADDRESS = zeroAddress;
|
|
31
|
+
export const ACROSS_SOLANA_TOKEN_ADDRESS = '11111111111111111111111111111111';
|
|
32
|
+
export const DEFAULT_ACROSS_EVM_USER_ADDRESS = '0x000000000000000000000000000000000000dead';
|
|
33
|
+
export const DEFAULT_ACROSS_SOLANA_USER_ADDRESS = 'CbKGgVKLJFb8bBrf58DnAkdryX6ubewVytn7X957YwNr';
|
|
34
|
+
export const acrossErrorCodeToTradeQuoteError = {
|
|
35
|
+
[AcrossErrorCode.AmountTooLow]: TradeQuoteError.SellAmountBelowMinimum,
|
|
36
|
+
[AcrossErrorCode.RouteNotFound]: TradeQuoteError.NoRouteFound,
|
|
37
|
+
[AcrossErrorCode.NoBridgeRoutes]: TradeQuoteError.NoRouteFound,
|
|
38
|
+
[AcrossErrorCode.UnsupportedToken]: TradeQuoteError.UnsupportedTradePair,
|
|
39
|
+
[AcrossErrorCode.InsufficientLiquidity]: TradeQuoteError.SellAmountBelowTradeFee,
|
|
40
|
+
[AcrossErrorCode.InvalidParam]: TradeQuoteError.UnknownError,
|
|
41
|
+
[AcrossErrorCode.InternalError]: TradeQuoteError.InternalError,
|
|
42
|
+
};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { evm, isEvmChainId } from '@shapeshiftoss/chain-adapters';
|
|
2
|
+
import { TxStatus } from '@shapeshiftoss/unchained-client';
|
|
3
|
+
import BigNumber from 'bignumber.js';
|
|
4
|
+
import { getSolanaTransactionFees } from '../../solana-utils/getSolanaTransactionFees.js';
|
|
5
|
+
import { getUnsignedSolanaTransaction } from '../../solana-utils/getUnsignedSolanaTransaction.js';
|
|
6
|
+
import { checkEvmSwapStatus, getExecutableTradeStep, isExecutableTradeQuote } from '../../utils.js';
|
|
7
|
+
import { getTradeQuote } from './getTradeQuote/getTradeQuote.js';
|
|
8
|
+
import { getTradeRate } from './getTradeRate/getTradeRate.js';
|
|
9
|
+
import { acrossService } from './utils/acrossService.js';
|
|
10
|
+
export const acrossApi = {
|
|
11
|
+
getTradeQuote: (input, deps) => getTradeQuote(input, deps),
|
|
12
|
+
getTradeRate: (input, deps) => getTradeRate(input, deps),
|
|
13
|
+
getEvmTransactionFees: async ({ from, stepIndex, tradeQuote, supportsEIP1559, assertGetEvmChainAdapter, }) => {
|
|
14
|
+
if (!isExecutableTradeQuote(tradeQuote))
|
|
15
|
+
throw new Error('Unable to execute a trade rate quote');
|
|
16
|
+
const step = getExecutableTradeStep(tradeQuote, stepIndex);
|
|
17
|
+
const { acrossTransactionMetadata, sellAsset } = step;
|
|
18
|
+
if (!acrossTransactionMetadata)
|
|
19
|
+
throw new Error('Missing Across transaction metadata');
|
|
20
|
+
const { to, value, data } = acrossTransactionMetadata;
|
|
21
|
+
const adapter = assertGetEvmChainAdapter(sellAsset.chainId);
|
|
22
|
+
const feeData = await evm.getFees({ adapter, data, to, value, from, supportsEIP1559 });
|
|
23
|
+
return feeData.networkFeeCryptoBaseUnit;
|
|
24
|
+
},
|
|
25
|
+
getUnsignedEvmTransaction: async ({ from, stepIndex, tradeQuote, supportsEIP1559, assertGetEvmChainAdapter, }) => {
|
|
26
|
+
if (!isExecutableTradeQuote(tradeQuote))
|
|
27
|
+
throw new Error('Unable to execute a trade rate quote');
|
|
28
|
+
const step = getExecutableTradeStep(tradeQuote, stepIndex);
|
|
29
|
+
const { accountNumber, acrossTransactionMetadata, sellAsset } = step;
|
|
30
|
+
if (!acrossTransactionMetadata)
|
|
31
|
+
throw new Error('Missing Across transaction metadata');
|
|
32
|
+
const { to, value, data, gasLimit: gasLimitFromApi } = acrossTransactionMetadata;
|
|
33
|
+
const adapter = assertGetEvmChainAdapter(sellAsset.chainId);
|
|
34
|
+
const feeData = await evm.getFees({ adapter, data, to, value, from, supportsEIP1559 });
|
|
35
|
+
const unsignedTx = await adapter.buildCustomApiTx({
|
|
36
|
+
accountNumber,
|
|
37
|
+
data,
|
|
38
|
+
from,
|
|
39
|
+
to,
|
|
40
|
+
value,
|
|
41
|
+
...feeData,
|
|
42
|
+
gasLimit: BigNumber.max(gasLimitFromApi ?? '0', feeData.gasLimit).toFixed(),
|
|
43
|
+
});
|
|
44
|
+
return unsignedTx;
|
|
45
|
+
},
|
|
46
|
+
checkTradeStatus: async ({ txHash, chainId, address, config, fetchIsSmartContractAddressQuery, assertGetEvmChainAdapter, }) => {
|
|
47
|
+
if (isEvmChainId(chainId)) {
|
|
48
|
+
const sourceTxStatus = await checkEvmSwapStatus({
|
|
49
|
+
txHash,
|
|
50
|
+
chainId,
|
|
51
|
+
address,
|
|
52
|
+
assertGetEvmChainAdapter,
|
|
53
|
+
fetchIsSmartContractAddressQuery,
|
|
54
|
+
});
|
|
55
|
+
if (sourceTxStatus.status !== TxStatus.Confirmed)
|
|
56
|
+
return sourceTxStatus;
|
|
57
|
+
txHash = sourceTxStatus.buyTxHash ?? txHash;
|
|
58
|
+
}
|
|
59
|
+
const maybeStatusResponse = await acrossService.get(`${config.VITE_ACROSS_API_URL}/deposit/status?depositTxnRef=${txHash}`);
|
|
60
|
+
if (maybeStatusResponse.isErr()) {
|
|
61
|
+
return {
|
|
62
|
+
buyTxHash: undefined,
|
|
63
|
+
status: TxStatus.Unknown,
|
|
64
|
+
message: undefined,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
const { data: statusResponse } = maybeStatusResponse.unwrap();
|
|
68
|
+
const status = (() => {
|
|
69
|
+
switch (statusResponse.status) {
|
|
70
|
+
case 'filled':
|
|
71
|
+
return TxStatus.Confirmed;
|
|
72
|
+
case 'pending':
|
|
73
|
+
return TxStatus.Pending;
|
|
74
|
+
case 'slowFillRequested':
|
|
75
|
+
return TxStatus.Pending;
|
|
76
|
+
case 'expired':
|
|
77
|
+
return TxStatus.Failed;
|
|
78
|
+
case 'refunded':
|
|
79
|
+
return TxStatus.Failed;
|
|
80
|
+
default:
|
|
81
|
+
return TxStatus.Unknown;
|
|
82
|
+
}
|
|
83
|
+
})();
|
|
84
|
+
const message = (() => {
|
|
85
|
+
switch (statusResponse.status) {
|
|
86
|
+
case 'pending':
|
|
87
|
+
return 'Deposit detected, processing...';
|
|
88
|
+
case 'slowFillRequested':
|
|
89
|
+
return 'Taking longer than usual, waiting for fill...';
|
|
90
|
+
case 'expired':
|
|
91
|
+
return 'Deposit expired';
|
|
92
|
+
case 'refunded':
|
|
93
|
+
return 'Deposit refunded on origin chain';
|
|
94
|
+
default:
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
})();
|
|
98
|
+
const buyTxHash = statusResponse.fillTxnRef;
|
|
99
|
+
return {
|
|
100
|
+
status,
|
|
101
|
+
buyTxHash,
|
|
102
|
+
message,
|
|
103
|
+
};
|
|
104
|
+
},
|
|
105
|
+
getUnsignedSolanaTransaction,
|
|
106
|
+
getSolanaTransactionFees,
|
|
107
|
+
};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { Result } from '@sniptt/monads';
|
|
2
|
+
import type { CommonTradeQuoteInput, SwapErrorRight, SwapperDeps, TradeQuote } from '../../../types.js';
|
|
3
|
+
export declare const getTradeQuote: (input: CommonTradeQuoteInput, deps: SwapperDeps) => Promise<Result<TradeQuote[], SwapErrorRight>>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Err } from '@sniptt/monads';
|
|
2
|
+
import { makeSwapErrorRight } from '../../../utils.js';
|
|
3
|
+
import { getTrade } from '../utils/getTrade.js';
|
|
4
|
+
export const getTradeQuote = (input, deps) => {
|
|
5
|
+
if (!input.sendAddress) {
|
|
6
|
+
return Promise.resolve(Err(makeSwapErrorRight({
|
|
7
|
+
message: 'sendAddress is required',
|
|
8
|
+
})));
|
|
9
|
+
}
|
|
10
|
+
if (!input.receiveAddress) {
|
|
11
|
+
return Promise.resolve(Err(makeSwapErrorRight({
|
|
12
|
+
message: 'receiveAddress is required',
|
|
13
|
+
})));
|
|
14
|
+
}
|
|
15
|
+
const args = {
|
|
16
|
+
buyAsset: input.buyAsset,
|
|
17
|
+
receiveAddress: input.receiveAddress,
|
|
18
|
+
sellAmountIncludingProtocolFeesCryptoBaseUnit: input.sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
19
|
+
sellAsset: input.sellAsset,
|
|
20
|
+
sendAddress: input.sendAddress,
|
|
21
|
+
quoteOrRate: 'quote',
|
|
22
|
+
accountNumber: input.accountNumber,
|
|
23
|
+
affiliateBps: input.affiliateBps,
|
|
24
|
+
slippageTolerancePercentageDecimal: input.slippageTolerancePercentageDecimal,
|
|
25
|
+
};
|
|
26
|
+
return getTrade({ input: args, deps });
|
|
27
|
+
};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { Result } from '@sniptt/monads';
|
|
2
|
+
import type { GetTradeRateInput, SwapErrorRight, SwapperDeps, TradeRate } from '../../../types.js';
|
|
3
|
+
export declare const getTradeRate: (input: GetTradeRateInput, deps: SwapperDeps) => Promise<Result<TradeRate[], SwapErrorRight>>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { getTrade } from '../utils/getTrade.js';
|
|
2
|
+
export const getTradeRate = (input, deps) => {
|
|
3
|
+
const args = {
|
|
4
|
+
quoteOrRate: 'rate',
|
|
5
|
+
buyAsset: input.buyAsset,
|
|
6
|
+
receiveAddress: input.receiveAddress,
|
|
7
|
+
sellAmountIncludingProtocolFeesCryptoBaseUnit: input.sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
8
|
+
sellAsset: input.sellAsset,
|
|
9
|
+
sendAddress: input.sendAddress,
|
|
10
|
+
accountNumber: input.accountNumber,
|
|
11
|
+
affiliateBps: input.affiliateBps,
|
|
12
|
+
slippageTolerancePercentageDecimal: input.slippageTolerancePercentageDecimal,
|
|
13
|
+
};
|
|
14
|
+
return getTrade({ input: args, deps });
|
|
15
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { acrossSwapper } from './AcrossSwapper.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { acrossSwapper } from './AcrossSwapper.js';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const acrossService: {
|
|
2
|
+
get: <T = any>(url: string, config?: import("axios").AxiosRequestConfig<any> | undefined) => Promise<import("@sniptt/monads").Result<import("axios").AxiosResponse<T, any, {}>, import("../../../index.js").SwapErrorRight>>;
|
|
3
|
+
post: <T_1 = any>(url: string, data: any, config?: import("axios").AxiosRequestConfig<any> | undefined) => Promise<import("@sniptt/monads").Result<import("axios").AxiosResponse<T_1, any, {}>, import("../../../index.js").SwapErrorRight>>;
|
|
4
|
+
delete: <T_2 = any>(url: string, data: any, config?: import("axios").AxiosRequestConfig<any> | undefined) => Promise<import("@sniptt/monads").Result<import("axios").AxiosResponse<T_2, any, {}>, import("../../../index.js").SwapErrorRight>>;
|
|
5
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { makeSwapperAxiosServiceMonadic } from '../../../utils.js';
|
|
3
|
+
const axiosConfig = {
|
|
4
|
+
timeout: 10000,
|
|
5
|
+
headers: {
|
|
6
|
+
Accept: 'application/json',
|
|
7
|
+
'Content-Type': 'application/json',
|
|
8
|
+
},
|
|
9
|
+
};
|
|
10
|
+
const acrossServiceBase = axios.create(axiosConfig);
|
|
11
|
+
export const acrossService = makeSwapperAxiosServiceMonadic(acrossServiceBase);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Result } from '@sniptt/monads';
|
|
2
|
+
import type { AxiosResponse } from 'axios';
|
|
3
|
+
import type { SwapErrorRight, SwapperConfig } from '../../../types.js';
|
|
4
|
+
import type { AcrossSwapApprovalResponse } from './types.js';
|
|
5
|
+
export type AcrossFetchQuoteParams = {
|
|
6
|
+
tradeType: 'exactInput';
|
|
7
|
+
amount: string;
|
|
8
|
+
inputToken: string;
|
|
9
|
+
outputToken: string;
|
|
10
|
+
originChainId: number;
|
|
11
|
+
destinationChainId: number;
|
|
12
|
+
depositor: string;
|
|
13
|
+
recipient?: string;
|
|
14
|
+
appFee?: number;
|
|
15
|
+
appFeeRecipient?: string;
|
|
16
|
+
integratorId?: string;
|
|
17
|
+
slippage?: string;
|
|
18
|
+
};
|
|
19
|
+
export declare const fetchAcrossTrade: (params: AcrossFetchQuoteParams, config: SwapperConfig) => Promise<Result<AxiosResponse<AcrossSwapApprovalResponse>, SwapErrorRight>>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { acrossService } from './acrossService.js';
|
|
2
|
+
export const fetchAcrossTrade = (params, config) => {
|
|
3
|
+
const searchParams = new URLSearchParams();
|
|
4
|
+
searchParams.set('tradeType', params.tradeType);
|
|
5
|
+
searchParams.set('amount', params.amount);
|
|
6
|
+
searchParams.set('inputToken', params.inputToken);
|
|
7
|
+
searchParams.set('outputToken', params.outputToken);
|
|
8
|
+
searchParams.set('originChainId', params.originChainId.toString());
|
|
9
|
+
searchParams.set('destinationChainId', params.destinationChainId.toString());
|
|
10
|
+
searchParams.set('depositor', params.depositor);
|
|
11
|
+
if (params.recipient)
|
|
12
|
+
searchParams.set('recipient', params.recipient);
|
|
13
|
+
if (params.appFee !== undefined && params.appFee > 0 && params.appFeeRecipient) {
|
|
14
|
+
searchParams.set('appFee', params.appFee.toString());
|
|
15
|
+
searchParams.set('appFeeRecipient', params.appFeeRecipient);
|
|
16
|
+
}
|
|
17
|
+
if (params.integratorId)
|
|
18
|
+
searchParams.set('integratorId', params.integratorId);
|
|
19
|
+
if (params.slippage)
|
|
20
|
+
searchParams.set('slippage', params.slippage);
|
|
21
|
+
const url = `${config.VITE_ACROSS_API_URL}/swap/approval?${searchParams.toString()}`;
|
|
22
|
+
return acrossService.get(url);
|
|
23
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Result } from '@sniptt/monads';
|
|
2
|
+
import type { SwapErrorRight, SwapperDeps, TradeQuote, TradeRate } from '../../../types.js';
|
|
3
|
+
import type { AcrossTradeInputParams } from './types.js';
|
|
4
|
+
export declare function getTrade(args: {
|
|
5
|
+
input: AcrossTradeInputParams<'quote'>;
|
|
6
|
+
deps: SwapperDeps;
|
|
7
|
+
}): Promise<Result<TradeQuote[], SwapErrorRight>>;
|
|
8
|
+
export declare function getTrade(args: {
|
|
9
|
+
input: AcrossTradeInputParams<'rate'>;
|
|
10
|
+
deps: SwapperDeps;
|
|
11
|
+
}): Promise<Result<TradeRate[], SwapErrorRight>>;
|