@shapeshiftoss/swapper 17.6.7 → 17.6.9
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 +42 -24
- package/dist/cjs/cowswap-utils/constants.js +1 -0
- package/dist/cjs/cowswap-utils/index.js +2 -0
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/swappers/AvnuSwapper/AvnuSwapper.d.ts +2 -0
- package/dist/cjs/swappers/AvnuSwapper/AvnuSwapper.js +7 -0
- package/dist/cjs/swappers/AvnuSwapper/endpoints.d.ts +2 -0
- package/dist/cjs/swappers/AvnuSwapper/endpoints.js +181 -0
- package/dist/cjs/swappers/AvnuSwapper/index.d.ts +1 -0
- package/dist/cjs/swappers/AvnuSwapper/index.js +5 -0
- package/dist/cjs/swappers/AvnuSwapper/swapperApi/getTradeQuote.d.ts +3 -0
- package/dist/cjs/swappers/AvnuSwapper/swapperApi/getTradeQuote.js +142 -0
- package/dist/cjs/swappers/AvnuSwapper/swapperApi/getTradeRate.d.ts +3 -0
- package/dist/cjs/swappers/AvnuSwapper/swapperApi/getTradeRate.js +120 -0
- package/dist/cjs/swappers/AvnuSwapper/types.d.ts +2 -0
- package/dist/cjs/swappers/AvnuSwapper/types.js +2 -0
- package/dist/cjs/swappers/AvnuSwapper/utils/constants.d.ts +5 -0
- package/dist/cjs/swappers/AvnuSwapper/utils/constants.js +11 -0
- package/dist/cjs/swappers/AvnuSwapper/utils/helpers.d.ts +7 -0
- package/dist/cjs/swappers/AvnuSwapper/utils/helpers.js +21 -0
- package/dist/cjs/swappers/ButterSwap/swapperApi/getTradeQuote.test.js +2 -0
- package/dist/cjs/swappers/ButterSwap/swapperApi/getTradeRate.test.js +4 -0
- package/dist/cjs/swappers/ButterSwap/utils/helpers.js +1 -0
- package/dist/cjs/swappers/CetusSwapper/endpoints.js +33 -27
- package/dist/cjs/swappers/CetusSwapper/swapperApi/getCetusTradeData.d.ts +24 -0
- package/dist/cjs/swappers/CetusSwapper/swapperApi/getCetusTradeData.js +79 -0
- package/dist/cjs/swappers/CetusSwapper/swapperApi/getTradeQuote.js +44 -69
- package/dist/cjs/swappers/CetusSwapper/swapperApi/getTradeRate.js +49 -65
- package/dist/cjs/swappers/CetusSwapper/utils/constants.d.ts +1 -0
- package/dist/cjs/swappers/CetusSwapper/utils/constants.js +2 -1
- package/dist/cjs/swappers/CetusSwapper/utils/helpers.d.ts +6 -11
- package/dist/cjs/swappers/CetusSwapper/utils/helpers.js +41 -96
- package/dist/cjs/swappers/JupiterSwapper/utils/helpers.d.ts +0 -2
- package/dist/cjs/swappers/MayachainSwapper/generated/generatedTradableAssetMap.json +1 -0
- package/dist/cjs/swappers/NearIntentsSwapper/NearIntentsSwapper.js +2 -0
- package/dist/cjs/swappers/NearIntentsSwapper/endpoints.js +68 -0
- package/dist/cjs/swappers/NearIntentsSwapper/swapperApi/getTradeQuote.js +30 -0
- package/dist/cjs/swappers/NearIntentsSwapper/swapperApi/getTradeRate.js +53 -5
- package/dist/cjs/swappers/NearIntentsSwapper/types.d.ts +1 -1
- package/dist/cjs/swappers/NearIntentsSwapper/types.js +8 -0
- package/dist/cjs/swappers/NearIntentsSwapper/utils/helpers/helpers.js +28 -8
- package/dist/cjs/swappers/PortalsSwapper/constants.js +1 -1
- package/dist/cjs/swappers/PortalsSwapper/endpoints.js +92 -1
- package/dist/cjs/swappers/PortalsSwapper/getPortalsTradeQuote/getPortalsTradeQuote.js +29 -17
- package/dist/cjs/swappers/PortalsSwapper/getPortalsTradeRate/getPortalsTradeRate.js +21 -17
- package/dist/cjs/swappers/PortalsSwapper/types.js +1 -0
- package/dist/cjs/swappers/PortalsSwapper/utils/fetchAxelarscanStatus.d.ts +9 -0
- package/dist/cjs/swappers/PortalsSwapper/utils/fetchAxelarscanStatus.js +52 -0
- package/dist/cjs/swappers/PortalsSwapper/utils/fetchPortalsTradeOrder.d.ts +1 -0
- package/dist/cjs/swappers/PortalsSwapper/utils/fetchSquidStatus.d.ts +9 -0
- package/dist/cjs/swappers/PortalsSwapper/utils/fetchSquidStatus.js +57 -0
- package/dist/cjs/swappers/RelaySwapper/constant.js +3 -0
- package/dist/cjs/swappers/RelaySwapper/utils/fetchRelayTrade.js +1 -1
- package/dist/cjs/swappers/RelaySwapper/utils/getTrade.js +16 -1
- package/dist/cjs/swappers/RelaySwapper/utils/relayTokenToAssetId.js +20 -0
- package/dist/cjs/swappers/RelaySwapper/utils/types.d.ts +13 -4
- package/dist/cjs/swappers/RelaySwapper/utils/types.js +5 -1
- package/dist/cjs/swappers/SunioSwapper/SunioSwapper.d.ts +2 -0
- package/dist/cjs/swappers/SunioSwapper/SunioSwapper.js +7 -0
- package/dist/cjs/swappers/SunioSwapper/endpoints.d.ts +2 -0
- package/dist/cjs/swappers/SunioSwapper/endpoints.js +131 -0
- package/dist/cjs/swappers/SunioSwapper/getSunioTradeQuote/getSunioTradeQuote.d.ts +3 -0
- package/dist/cjs/swappers/SunioSwapper/getSunioTradeQuote/getSunioTradeQuote.js +8 -0
- package/dist/cjs/swappers/SunioSwapper/getSunioTradeRate/getSunioTradeRate.d.ts +3 -0
- package/dist/cjs/swappers/SunioSwapper/getSunioTradeRate/getSunioTradeRate.js +8 -0
- package/dist/cjs/swappers/SunioSwapper/index.d.ts +4 -0
- package/dist/cjs/swappers/SunioSwapper/index.js +23 -0
- package/dist/cjs/swappers/SunioSwapper/types.d.ts +22 -0
- package/dist/cjs/swappers/SunioSwapper/types.js +12 -0
- package/dist/cjs/swappers/SunioSwapper/utils/abi.d.ts +48 -0
- package/dist/cjs/swappers/SunioSwapper/utils/abi.js +28 -0
- package/dist/cjs/swappers/SunioSwapper/utils/buildSwapRouteParameters.d.ts +14 -0
- package/dist/cjs/swappers/SunioSwapper/utils/buildSwapRouteParameters.js +32 -0
- package/dist/cjs/swappers/SunioSwapper/utils/buildSwapTransaction.d.ts +11 -0
- package/dist/cjs/swappers/SunioSwapper/utils/buildSwapTransaction.js +57 -0
- package/dist/cjs/swappers/SunioSwapper/utils/constants.d.ts +6 -0
- package/dist/cjs/swappers/SunioSwapper/utils/constants.js +16 -0
- package/dist/cjs/swappers/SunioSwapper/utils/fetchFromSunio.d.ts +11 -0
- package/dist/cjs/swappers/SunioSwapper/utils/fetchFromSunio.js +45 -0
- package/dist/cjs/swappers/SunioSwapper/utils/getQuoteOrRate.d.ts +4 -0
- package/dist/cjs/swappers/SunioSwapper/utils/getQuoteOrRate.js +203 -0
- package/dist/cjs/swappers/SunioSwapper/utils/helpers/helpers.d.ts +4 -0
- package/dist/cjs/swappers/SunioSwapper/utils/helpers/helpers.js +22 -0
- package/dist/cjs/swappers/SunioSwapper/utils/sunioService.d.ts +6 -0
- package/dist/cjs/swappers/SunioSwapper/utils/sunioService.js +18 -0
- package/dist/cjs/swappers/ThorchainSwapper/ThorchainSwapper.js +3 -0
- package/dist/cjs/swappers/ThorchainSwapper/endpoints.js +2 -0
- package/dist/cjs/swappers/ThorchainSwapper/generated/generatedTradableAssetMap.json +2 -2
- package/dist/cjs/swappers/utils/helpers/helpers.js +7 -0
- package/dist/cjs/thorchain-utils/getL1RateOrQuote.js +80 -3
- package/dist/cjs/thorchain-utils/index.d.ts +1 -0
- package/dist/cjs/thorchain-utils/index.js +2 -1
- package/dist/cjs/thorchain-utils/tron/getThorTxData.d.ts +12 -0
- package/dist/cjs/thorchain-utils/tron/getThorTxData.js +14 -0
- package/dist/cjs/thorchain-utils/tron/getTronTransactionFees.d.ts +2 -0
- package/dist/cjs/thorchain-utils/tron/getTronTransactionFees.js +65 -0
- package/dist/cjs/thorchain-utils/tron/getUnsignedTronTransaction.d.ts +3 -0
- package/dist/cjs/thorchain-utils/tron/getUnsignedTronTransaction.js +35 -0
- package/dist/cjs/thorchain-utils/tron/index.d.ts +3 -0
- package/dist/cjs/thorchain-utils/tron/index.js +19 -0
- package/dist/cjs/types.d.ts +74 -9
- package/dist/cjs/types.js +2 -0
- package/dist/cjs/utils/tenderly/simulate.d.ts +6 -1
- package/dist/cjs/utils/tenderly/simulate.js +22 -2
- package/dist/cjs/utils/tenderly/types.d.ts +21 -0
- package/dist/cjs/utils.d.ts +10 -4
- package/dist/cjs/utils.js +53 -1
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/constants.js +18 -0
- package/dist/esm/cowswap-utils/constants.js +1 -0
- package/dist/esm/cowswap-utils/index.js +2 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/swappers/AvnuSwapper/AvnuSwapper.d.ts +2 -0
- package/dist/esm/swappers/AvnuSwapper/AvnuSwapper.js +4 -0
- package/dist/esm/swappers/AvnuSwapper/endpoints.d.ts +2 -0
- package/dist/esm/swappers/AvnuSwapper/endpoints.js +178 -0
- package/dist/esm/swappers/AvnuSwapper/index.d.ts +1 -0
- package/dist/esm/swappers/AvnuSwapper/index.js +1 -0
- package/dist/esm/swappers/AvnuSwapper/swapperApi/getTradeQuote.d.ts +3 -0
- package/dist/esm/swappers/AvnuSwapper/swapperApi/getTradeQuote.js +138 -0
- package/dist/esm/swappers/AvnuSwapper/swapperApi/getTradeRate.d.ts +3 -0
- package/dist/esm/swappers/AvnuSwapper/swapperApi/getTradeRate.js +116 -0
- package/dist/esm/swappers/AvnuSwapper/types.d.ts +2 -0
- package/dist/esm/swappers/AvnuSwapper/types.js +1 -0
- package/dist/esm/swappers/AvnuSwapper/utils/constants.d.ts +5 -0
- package/dist/esm/swappers/AvnuSwapper/utils/constants.js +7 -0
- package/dist/esm/swappers/AvnuSwapper/utils/helpers.d.ts +7 -0
- package/dist/esm/swappers/AvnuSwapper/utils/helpers.js +17 -0
- package/dist/esm/swappers/ButterSwap/swapperApi/getTradeQuote.test.js +2 -0
- package/dist/esm/swappers/ButterSwap/swapperApi/getTradeRate.test.js +4 -0
- package/dist/esm/swappers/ButterSwap/utils/helpers.js +1 -0
- package/dist/esm/swappers/CetusSwapper/endpoints.js +28 -22
- package/dist/esm/swappers/CetusSwapper/swapperApi/getCetusTradeData.d.ts +24 -0
- package/dist/esm/swappers/CetusSwapper/swapperApi/getCetusTradeData.js +75 -0
- package/dist/esm/swappers/CetusSwapper/swapperApi/getTradeQuote.js +44 -69
- package/dist/esm/swappers/CetusSwapper/swapperApi/getTradeRate.js +50 -66
- package/dist/esm/swappers/CetusSwapper/utils/constants.d.ts +1 -0
- package/dist/esm/swappers/CetusSwapper/utils/constants.js +1 -0
- package/dist/esm/swappers/CetusSwapper/utils/helpers.d.ts +6 -11
- package/dist/esm/swappers/CetusSwapper/utils/helpers.js +37 -67
- package/dist/esm/swappers/JupiterSwapper/utils/helpers.d.ts +0 -2
- package/dist/esm/swappers/MayachainSwapper/generated/generatedTradableAssetMap.json +1 -0
- package/dist/esm/swappers/NearIntentsSwapper/NearIntentsSwapper.js +3 -1
- package/dist/esm/swappers/NearIntentsSwapper/endpoints.js +68 -0
- package/dist/esm/swappers/NearIntentsSwapper/swapperApi/getTradeQuote.js +30 -0
- package/dist/esm/swappers/NearIntentsSwapper/swapperApi/getTradeRate.js +54 -6
- package/dist/esm/swappers/NearIntentsSwapper/types.d.ts +1 -1
- package/dist/esm/swappers/NearIntentsSwapper/types.js +8 -0
- package/dist/esm/swappers/NearIntentsSwapper/utils/helpers/helpers.js +29 -9
- package/dist/esm/swappers/PortalsSwapper/constants.js +1 -1
- package/dist/esm/swappers/PortalsSwapper/endpoints.js +92 -1
- package/dist/esm/swappers/PortalsSwapper/getPortalsTradeQuote/getPortalsTradeQuote.js +30 -18
- package/dist/esm/swappers/PortalsSwapper/getPortalsTradeRate/getPortalsTradeRate.js +21 -17
- package/dist/esm/swappers/PortalsSwapper/types.js +1 -0
- package/dist/esm/swappers/PortalsSwapper/utils/fetchAxelarscanStatus.d.ts +9 -0
- package/dist/esm/swappers/PortalsSwapper/utils/fetchAxelarscanStatus.js +47 -0
- package/dist/esm/swappers/PortalsSwapper/utils/fetchPortalsTradeOrder.d.ts +1 -0
- package/dist/esm/swappers/PortalsSwapper/utils/fetchSquidStatus.d.ts +9 -0
- package/dist/esm/swappers/PortalsSwapper/utils/fetchSquidStatus.js +52 -0
- package/dist/esm/swappers/RelaySwapper/constant.js +5 -2
- package/dist/esm/swappers/RelaySwapper/utils/fetchRelayTrade.js +1 -1
- package/dist/esm/swappers/RelaySwapper/utils/getTrade.js +18 -3
- package/dist/esm/swappers/RelaySwapper/utils/relayTokenToAssetId.js +20 -0
- package/dist/esm/swappers/RelaySwapper/utils/types.d.ts +13 -4
- package/dist/esm/swappers/RelaySwapper/utils/types.js +3 -0
- package/dist/esm/swappers/SunioSwapper/SunioSwapper.d.ts +2 -0
- package/dist/esm/swappers/SunioSwapper/SunioSwapper.js +4 -0
- package/dist/esm/swappers/SunioSwapper/endpoints.d.ts +2 -0
- package/dist/esm/swappers/SunioSwapper/endpoints.js +128 -0
- package/dist/esm/swappers/SunioSwapper/getSunioTradeQuote/getSunioTradeQuote.d.ts +3 -0
- package/dist/esm/swappers/SunioSwapper/getSunioTradeQuote/getSunioTradeQuote.js +4 -0
- package/dist/esm/swappers/SunioSwapper/getSunioTradeRate/getSunioTradeRate.d.ts +3 -0
- package/dist/esm/swappers/SunioSwapper/getSunioTradeRate/getSunioTradeRate.js +4 -0
- package/dist/esm/swappers/SunioSwapper/index.d.ts +4 -0
- package/dist/esm/swappers/SunioSwapper/index.js +4 -0
- package/dist/esm/swappers/SunioSwapper/types.d.ts +22 -0
- package/dist/esm/swappers/SunioSwapper/types.js +9 -0
- package/dist/esm/swappers/SunioSwapper/utils/abi.d.ts +48 -0
- package/dist/esm/swappers/SunioSwapper/utils/abi.js +25 -0
- package/dist/esm/swappers/SunioSwapper/utils/buildSwapRouteParameters.d.ts +14 -0
- package/dist/esm/swappers/SunioSwapper/utils/buildSwapRouteParameters.js +28 -0
- package/dist/esm/swappers/SunioSwapper/utils/buildSwapTransaction.d.ts +11 -0
- package/dist/esm/swappers/SunioSwapper/utils/buildSwapTransaction.js +53 -0
- package/dist/esm/swappers/SunioSwapper/utils/constants.d.ts +6 -0
- package/dist/esm/swappers/SunioSwapper/utils/constants.js +13 -0
- package/dist/esm/swappers/SunioSwapper/utils/fetchFromSunio.d.ts +11 -0
- package/dist/esm/swappers/SunioSwapper/utils/fetchFromSunio.js +41 -0
- package/dist/esm/swappers/SunioSwapper/utils/getQuoteOrRate.d.ts +4 -0
- package/dist/esm/swappers/SunioSwapper/utils/getQuoteOrRate.js +199 -0
- package/dist/esm/swappers/SunioSwapper/utils/helpers/helpers.d.ts +4 -0
- package/dist/esm/swappers/SunioSwapper/utils/helpers/helpers.js +16 -0
- package/dist/esm/swappers/SunioSwapper/utils/sunioService.d.ts +6 -0
- package/dist/esm/swappers/SunioSwapper/utils/sunioService.js +14 -0
- package/dist/esm/swappers/ThorchainSwapper/ThorchainSwapper.js +3 -0
- package/dist/esm/swappers/ThorchainSwapper/endpoints.js +3 -1
- package/dist/esm/swappers/ThorchainSwapper/generated/generatedTradableAssetMap.json +2 -2
- package/dist/esm/swappers/utils/helpers/helpers.js +9 -2
- package/dist/esm/thorchain-utils/getL1RateOrQuote.js +81 -4
- package/dist/esm/thorchain-utils/index.d.ts +1 -0
- package/dist/esm/thorchain-utils/index.js +1 -0
- package/dist/esm/thorchain-utils/tron/getThorTxData.d.ts +12 -0
- package/dist/esm/thorchain-utils/tron/getThorTxData.js +10 -0
- package/dist/esm/thorchain-utils/tron/getTronTransactionFees.d.ts +2 -0
- package/dist/esm/thorchain-utils/tron/getTronTransactionFees.js +61 -0
- package/dist/esm/thorchain-utils/tron/getUnsignedTronTransaction.d.ts +3 -0
- package/dist/esm/thorchain-utils/tron/getUnsignedTronTransaction.js +31 -0
- package/dist/esm/thorchain-utils/tron/index.d.ts +3 -0
- package/dist/esm/thorchain-utils/tron/index.js +3 -0
- package/dist/esm/types.d.ts +74 -9
- package/dist/esm/types.js +2 -0
- package/dist/esm/utils/tenderly/simulate.d.ts +6 -1
- package/dist/esm/utils/tenderly/simulate.js +20 -1
- package/dist/esm/utils/tenderly/types.d.ts +21 -0
- package/dist/esm/utils.d.ts +10 -4
- package/dist/esm/utils.js +50 -1
- package/package.json +5 -4
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { executeEvmTransaction, executeSolanaTransaction, executeSuiTransaction, executeTronTransaction, } from '../../utils.js';
|
|
1
|
+
import { executeEvmTransaction, executeNearTransaction, executeSolanaTransaction, executeStarknetTransaction, executeSuiTransaction, executeTronTransaction, } from '../../utils.js';
|
|
2
2
|
export const nearIntentsSwapper = {
|
|
3
3
|
executeEvmTransaction,
|
|
4
4
|
executeSolanaTransaction,
|
|
5
|
+
executeStarknetTransaction,
|
|
5
6
|
executeTronTransaction,
|
|
6
7
|
executeSuiTransaction,
|
|
8
|
+
executeNearTransaction,
|
|
7
9
|
executeUtxoTransaction: (txToSign, { signAndBroadcastTransaction }) => {
|
|
8
10
|
return signAndBroadcastTransaction(txToSign);
|
|
9
11
|
},
|
|
@@ -177,6 +177,74 @@ export const nearIntentsApi = {
|
|
|
177
177
|
}
|
|
178
178
|
return Promise.resolve(step.feeData.networkFeeCryptoBaseUnit);
|
|
179
179
|
},
|
|
180
|
+
getUnsignedNearTransaction: async ({ stepIndex, tradeQuote, from, assertGetNearChainAdapter, }) => {
|
|
181
|
+
if (!isExecutableTradeQuote(tradeQuote))
|
|
182
|
+
throw new Error('Unable to execute a trade rate quote');
|
|
183
|
+
const step = getExecutableTradeStep(tradeQuote, stepIndex);
|
|
184
|
+
const { accountNumber, sellAsset, nearIntentsSpecific } = step;
|
|
185
|
+
if (!nearIntentsSpecific)
|
|
186
|
+
throw new Error('nearIntentsSpecific is required');
|
|
187
|
+
const adapter = assertGetNearChainAdapter(sellAsset.chainId);
|
|
188
|
+
const to = nearIntentsSpecific.depositAddress;
|
|
189
|
+
const value = step.sellAmountIncludingProtocolFeesCryptoBaseUnit;
|
|
190
|
+
const contractAddress = contractAddressOrUndefined(sellAsset.assetId);
|
|
191
|
+
return await adapter.buildSendApiTransaction({
|
|
192
|
+
to,
|
|
193
|
+
from,
|
|
194
|
+
value,
|
|
195
|
+
accountNumber,
|
|
196
|
+
chainSpecific: { contractAddress },
|
|
197
|
+
});
|
|
198
|
+
},
|
|
199
|
+
getNearTransactionFees: ({ tradeQuote, stepIndex }) => {
|
|
200
|
+
if (!isExecutableTradeQuote(tradeQuote))
|
|
201
|
+
throw new Error('Unable to execute a trade rate quote');
|
|
202
|
+
const step = getExecutableTradeStep(tradeQuote, stepIndex);
|
|
203
|
+
if (!step.feeData.networkFeeCryptoBaseUnit) {
|
|
204
|
+
throw new Error('Missing network fee in quote');
|
|
205
|
+
}
|
|
206
|
+
return Promise.resolve(step.feeData.networkFeeCryptoBaseUnit);
|
|
207
|
+
},
|
|
208
|
+
getUnsignedStarknetTransaction: async ({ stepIndex, tradeQuote, from, assertGetStarknetChainAdapter, }) => {
|
|
209
|
+
if (!isExecutableTradeQuote(tradeQuote))
|
|
210
|
+
throw new Error('Unable to execute a trade rate quote');
|
|
211
|
+
const step = getExecutableTradeStep(tradeQuote, stepIndex);
|
|
212
|
+
const { accountNumber, sellAsset, nearIntentsSpecific } = step;
|
|
213
|
+
if (!nearIntentsSpecific)
|
|
214
|
+
throw new Error('nearIntentsSpecific is required');
|
|
215
|
+
const adapter = assertGetStarknetChainAdapter(sellAsset.chainId);
|
|
216
|
+
const to = nearIntentsSpecific.depositAddress;
|
|
217
|
+
const value = step.sellAmountIncludingProtocolFeesCryptoBaseUnit;
|
|
218
|
+
const tokenContractAddress = contractAddressOrUndefined(sellAsset.assetId);
|
|
219
|
+
const { fast } = await adapter.getFeeData({
|
|
220
|
+
to,
|
|
221
|
+
value,
|
|
222
|
+
chainSpecific: {
|
|
223
|
+
from,
|
|
224
|
+
tokenContractAddress,
|
|
225
|
+
},
|
|
226
|
+
sendMax: false,
|
|
227
|
+
});
|
|
228
|
+
return adapter.buildSendApiTransaction({
|
|
229
|
+
from,
|
|
230
|
+
to,
|
|
231
|
+
value,
|
|
232
|
+
accountNumber,
|
|
233
|
+
chainSpecific: {
|
|
234
|
+
tokenContractAddress,
|
|
235
|
+
maxFee: fast.chainSpecific.maxFee,
|
|
236
|
+
},
|
|
237
|
+
});
|
|
238
|
+
},
|
|
239
|
+
getStarknetTransactionFees: ({ tradeQuote, stepIndex }) => {
|
|
240
|
+
if (!isExecutableTradeQuote(tradeQuote))
|
|
241
|
+
throw new Error('Unable to execute a trade rate quote');
|
|
242
|
+
const step = getExecutableTradeStep(tradeQuote, stepIndex);
|
|
243
|
+
if (!step.feeData.networkFeeCryptoBaseUnit) {
|
|
244
|
+
throw new Error('Missing network fee in quote');
|
|
245
|
+
}
|
|
246
|
+
return Promise.resolve(step.feeData.networkFeeCryptoBaseUnit);
|
|
247
|
+
},
|
|
180
248
|
checkTradeStatus: async ({ config, swap }) => {
|
|
181
249
|
const { nearIntentsSpecific } = swap?.metadata ?? {};
|
|
182
250
|
if (!nearIntentsSpecific?.depositAddress) {
|
|
@@ -145,9 +145,14 @@ export const getTradeQuote = async (input, deps) => {
|
|
|
145
145
|
}
|
|
146
146
|
case CHAIN_NAMESPACE.Tron: {
|
|
147
147
|
const sellAdapter = deps.assertGetTronChainAdapter(sellAsset.chainId);
|
|
148
|
+
const contractAddress = contractAddressOrUndefined(sellAsset.assetId);
|
|
148
149
|
const feeData = await sellAdapter.getFeeData({
|
|
149
150
|
to: depositAddress,
|
|
150
151
|
value: sellAmount,
|
|
152
|
+
chainSpecific: {
|
|
153
|
+
from: sendAddress,
|
|
154
|
+
contractAddress,
|
|
155
|
+
},
|
|
151
156
|
});
|
|
152
157
|
return { networkFeeCryptoBaseUnit: feeData.fast.txFee };
|
|
153
158
|
}
|
|
@@ -167,6 +172,31 @@ export const getTradeQuote = async (input, deps) => {
|
|
|
167
172
|
});
|
|
168
173
|
return { networkFeeCryptoBaseUnit: feeData.fast.txFee };
|
|
169
174
|
}
|
|
175
|
+
case CHAIN_NAMESPACE.Near: {
|
|
176
|
+
const sellAdapter = deps.assertGetNearChainAdapter(sellAsset.chainId);
|
|
177
|
+
const feeData = await sellAdapter.getFeeData({
|
|
178
|
+
to: depositAddress,
|
|
179
|
+
value: sellAmount,
|
|
180
|
+
chainSpecific: { from },
|
|
181
|
+
});
|
|
182
|
+
return { networkFeeCryptoBaseUnit: feeData.fast.txFee };
|
|
183
|
+
}
|
|
184
|
+
case CHAIN_NAMESPACE.Starknet: {
|
|
185
|
+
const sellAdapter = deps.assertGetStarknetChainAdapter(sellAsset.chainId);
|
|
186
|
+
const tokenContractAddress = isToken(sellAsset.assetId)
|
|
187
|
+
? fromAssetId(sellAsset.assetId).assetReference
|
|
188
|
+
: undefined;
|
|
189
|
+
const feeData = await sellAdapter.getFeeData({
|
|
190
|
+
to: depositAddress,
|
|
191
|
+
value: sellAmount,
|
|
192
|
+
chainSpecific: {
|
|
193
|
+
from,
|
|
194
|
+
tokenContractAddress,
|
|
195
|
+
},
|
|
196
|
+
sendMax: false,
|
|
197
|
+
});
|
|
198
|
+
return { networkFeeCryptoBaseUnit: feeData.fast.txFee };
|
|
199
|
+
}
|
|
170
200
|
default:
|
|
171
201
|
throw new Error(`Unsupported chain namespace: ${chainNamespace}`);
|
|
172
202
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CHAIN_NAMESPACE, fromAssetId } from '@shapeshiftoss/caip';
|
|
1
|
+
import { CHAIN_NAMESPACE, fromAssetId, monadChainId } from '@shapeshiftoss/caip';
|
|
2
2
|
import { evm } from '@shapeshiftoss/chain-adapters';
|
|
3
3
|
import { bn, bnOrZero, contractAddressOrUndefined, DAO_TREASURY_NEAR, isToken, } from '@shapeshiftoss/utils';
|
|
4
4
|
import { Err, Ok } from '@sniptt/monads';
|
|
@@ -20,14 +20,12 @@ export const getTradeRate = async (input, deps) => {
|
|
|
20
20
|
const originAsset = await assetToNearIntentsAsset(sellAsset);
|
|
21
21
|
const destinationAsset = await assetToNearIntentsAsset(buyAsset);
|
|
22
22
|
if (!originAsset) {
|
|
23
|
-
console.log('[NEAR] Returning error - originAsset not supported');
|
|
24
23
|
return Err(makeSwapErrorRight({
|
|
25
24
|
code: TradeQuoteError.UnsupportedTradePair,
|
|
26
25
|
message: `Asset ${sellAsset.symbol} on ${sellAsset.networkName || sellAsset.chainId} is not supported by NEAR Intents`,
|
|
27
26
|
}));
|
|
28
27
|
}
|
|
29
28
|
if (!destinationAsset) {
|
|
30
|
-
console.log('[NEAR] Returning error - destinationAsset not supported');
|
|
31
29
|
return Err(makeSwapErrorRight({
|
|
32
30
|
code: TradeQuoteError.UnsupportedTradePair,
|
|
33
31
|
message: `Asset ${buyAsset.symbol} on ${buyAsset.networkName || buyAsset.chainId} is not supported by NEAR Intents`,
|
|
@@ -73,9 +71,31 @@ export const getTradeRate = async (input, deps) => {
|
|
|
73
71
|
const getFeeData = async () => {
|
|
74
72
|
switch (chainNamespace) {
|
|
75
73
|
case CHAIN_NAMESPACE.Evm: {
|
|
74
|
+
const sellAdapter = deps.assertGetEvmChainAdapter(sellAsset.chainId);
|
|
75
|
+
const contractAddress = contractAddressOrUndefined(sellAsset.assetId);
|
|
76
|
+
const data = evm.getErc20Data(depositAddress, sellAmount, contractAddress);
|
|
77
|
+
// For Monad, skip Tenderly and use adapter's getFeeData directly
|
|
78
|
+
if (sellAsset.chainId === monadChainId) {
|
|
79
|
+
try {
|
|
80
|
+
const feeData = await sellAdapter.getFeeData({
|
|
81
|
+
to: contractAddress ?? depositAddress,
|
|
82
|
+
value: isNativeEvmAsset(sellAsset.assetId) ? sellAmount : '0',
|
|
83
|
+
chainSpecific: {
|
|
84
|
+
from: sendAddress || depositAddress,
|
|
85
|
+
contractAddress,
|
|
86
|
+
data: data || '0x',
|
|
87
|
+
},
|
|
88
|
+
sendMax: false,
|
|
89
|
+
});
|
|
90
|
+
return feeData.fast.txFee;
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
console.error('Failed to estimate fees for Monad Near Intents:', error);
|
|
94
|
+
return '0';
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
// For other EVM chains, use Tenderly simulation
|
|
76
98
|
try {
|
|
77
|
-
const contractAddress = contractAddressOrUndefined(sellAsset.assetId);
|
|
78
|
-
const data = evm.getErc20Data(depositAddress, sellAmount, contractAddress);
|
|
79
99
|
const simulationResult = await simulateWithStateOverrides({
|
|
80
100
|
chainId: sellAsset.chainId,
|
|
81
101
|
from: getAddress(sendAddress || depositAddress),
|
|
@@ -92,7 +112,6 @@ export const getTradeRate = async (input, deps) => {
|
|
|
92
112
|
return '0';
|
|
93
113
|
}
|
|
94
114
|
// Calculate network fee using the simulated gas limit
|
|
95
|
-
const sellAdapter = deps.assertGetEvmChainAdapter(sellAsset.chainId);
|
|
96
115
|
const { average } = await sellAdapter.getGasFeeData();
|
|
97
116
|
const supportsEIP1559 = 'maxFeePerGas' in average;
|
|
98
117
|
const networkFeeCryptoBaseUnit = evm.calcNetworkFeeCryptoBaseUnit({
|
|
@@ -156,9 +175,14 @@ export const getTradeRate = async (input, deps) => {
|
|
|
156
175
|
case CHAIN_NAMESPACE.Tron: {
|
|
157
176
|
try {
|
|
158
177
|
const sellAdapter = deps.assertGetTronChainAdapter(sellAsset.chainId);
|
|
178
|
+
const contractAddress = contractAddressOrUndefined(sellAsset.assetId);
|
|
159
179
|
const feeData = await sellAdapter.getFeeData({
|
|
160
180
|
to: depositAddress,
|
|
161
181
|
value: sellAmount,
|
|
182
|
+
chainSpecific: {
|
|
183
|
+
from: sendAddress,
|
|
184
|
+
contractAddress,
|
|
185
|
+
},
|
|
162
186
|
});
|
|
163
187
|
return feeData.fast.txFee;
|
|
164
188
|
}
|
|
@@ -190,6 +214,30 @@ export const getTradeRate = async (input, deps) => {
|
|
|
190
214
|
return '0';
|
|
191
215
|
}
|
|
192
216
|
}
|
|
217
|
+
case CHAIN_NAMESPACE.Starknet: {
|
|
218
|
+
try {
|
|
219
|
+
const sellAdapter = deps.assertGetStarknetChainAdapter(sellAsset.chainId);
|
|
220
|
+
const tokenContractAddress = isToken(sellAsset.assetId)
|
|
221
|
+
? fromAssetId(sellAsset.assetId).assetReference
|
|
222
|
+
: undefined;
|
|
223
|
+
if (!sendAddress) {
|
|
224
|
+
return '0';
|
|
225
|
+
}
|
|
226
|
+
const feeData = await sellAdapter.getFeeData({
|
|
227
|
+
to: depositAddress,
|
|
228
|
+
value: sellAmount,
|
|
229
|
+
chainSpecific: {
|
|
230
|
+
from: sendAddress,
|
|
231
|
+
tokenContractAddress,
|
|
232
|
+
},
|
|
233
|
+
sendMax: false,
|
|
234
|
+
});
|
|
235
|
+
return feeData.fast.txFee;
|
|
236
|
+
}
|
|
237
|
+
catch (error) {
|
|
238
|
+
return '0';
|
|
239
|
+
}
|
|
240
|
+
}
|
|
193
241
|
default:
|
|
194
242
|
return undefined;
|
|
195
243
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { KnownChainIds } from '@shapeshiftoss/types';
|
|
2
2
|
export { QuoteRequest } from '@defuse-protocol/one-click-sdk-typescript';
|
|
3
3
|
export type { GetExecutionStatusResponse, QuoteResponse, TokenResponse, } from '@defuse-protocol/one-click-sdk-typescript';
|
|
4
|
-
export declare const nearIntentsSupportedChainIds: readonly [KnownChainIds.EthereumMainnet, KnownChainIds.ArbitrumMainnet, KnownChainIds.BaseMainnet, KnownChainIds.GnosisMainnet, KnownChainIds.BnbSmartChainMainnet, KnownChainIds.PolygonMainnet, KnownChainIds.AvalancheMainnet, KnownChainIds.OptimismMainnet, KnownChainIds.BitcoinMainnet, KnownChainIds.DogecoinMainnet, KnownChainIds.SolanaMainnet, KnownChainIds.TronMainnet, KnownChainIds.SuiMainnet];
|
|
4
|
+
export declare const nearIntentsSupportedChainIds: readonly [KnownChainIds.EthereumMainnet, KnownChainIds.ArbitrumMainnet, KnownChainIds.BaseMainnet, KnownChainIds.GnosisMainnet, KnownChainIds.BnbSmartChainMainnet, KnownChainIds.PolygonMainnet, KnownChainIds.AvalancheMainnet, KnownChainIds.OptimismMainnet, KnownChainIds.BitcoinMainnet, KnownChainIds.DogecoinMainnet, KnownChainIds.ZcashMainnet, KnownChainIds.SolanaMainnet, KnownChainIds.TronMainnet, KnownChainIds.SuiMainnet, KnownChainIds.StarknetMainnet, KnownChainIds.MonadMainnet, KnownChainIds.NearMainnet];
|
|
5
5
|
export type NearIntentsSupportedChainId = (typeof nearIntentsSupportedChainIds)[number];
|
|
6
6
|
export declare const chainIdToNearIntentsChain: Record<NearIntentsSupportedChainId, string>;
|
|
@@ -11,9 +11,13 @@ export const nearIntentsSupportedChainIds = [
|
|
|
11
11
|
KnownChainIds.OptimismMainnet,
|
|
12
12
|
KnownChainIds.BitcoinMainnet,
|
|
13
13
|
KnownChainIds.DogecoinMainnet,
|
|
14
|
+
KnownChainIds.ZcashMainnet,
|
|
14
15
|
KnownChainIds.SolanaMainnet,
|
|
15
16
|
KnownChainIds.TronMainnet,
|
|
16
17
|
KnownChainIds.SuiMainnet,
|
|
18
|
+
KnownChainIds.StarknetMainnet,
|
|
19
|
+
KnownChainIds.MonadMainnet,
|
|
20
|
+
KnownChainIds.NearMainnet,
|
|
17
21
|
];
|
|
18
22
|
export const chainIdToNearIntentsChain = {
|
|
19
23
|
[KnownChainIds.EthereumMainnet]: 'eth',
|
|
@@ -26,7 +30,11 @@ export const chainIdToNearIntentsChain = {
|
|
|
26
30
|
[KnownChainIds.OptimismMainnet]: 'op',
|
|
27
31
|
[KnownChainIds.BitcoinMainnet]: 'btc',
|
|
28
32
|
[KnownChainIds.DogecoinMainnet]: 'doge',
|
|
33
|
+
[KnownChainIds.ZcashMainnet]: 'zec',
|
|
29
34
|
[KnownChainIds.SolanaMainnet]: 'sol',
|
|
30
35
|
[KnownChainIds.TronMainnet]: 'tron',
|
|
31
36
|
[KnownChainIds.SuiMainnet]: 'sui',
|
|
37
|
+
[KnownChainIds.StarknetMainnet]: 'starknet',
|
|
38
|
+
[KnownChainIds.MonadMainnet]: 'monad',
|
|
39
|
+
[KnownChainIds.NearMainnet]: 'near',
|
|
32
40
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ASSOCIATED_PROGRAM_ID } from '@coral-xyz/anchor/dist/cjs/utils/token';
|
|
2
|
-
import { fromAssetId, solanaChainId
|
|
2
|
+
import { fromAssetId, solanaChainId } from '@shapeshiftoss/caip';
|
|
3
3
|
import { TxStatus } from '@shapeshiftoss/unchained-client';
|
|
4
4
|
import { bnOrZero, isToken } from '@shapeshiftoss/utils';
|
|
5
5
|
import { zeroAddress } from 'viem';
|
|
@@ -23,25 +23,45 @@ export const getNearIntentsAsset = ({ nearNetwork, contractAddress, }) => {
|
|
|
23
23
|
// ERC20 tokens: "nep141:eth-0x{address}.omft.near"
|
|
24
24
|
return `nep141:${nearNetwork}-${contractAddress.toLowerCase()}.omft.near`;
|
|
25
25
|
};
|
|
26
|
-
const NEP245_CHAINS = ['bsc', 'pol', 'avax', 'op', 'tron'];
|
|
27
|
-
const TOKEN_LOOKUP_CHAINS = ['sui'];
|
|
26
|
+
const NEP245_CHAINS = ['bsc', 'pol', 'avax', 'op', 'tron', 'monad'];
|
|
27
|
+
const TOKEN_LOOKUP_CHAINS = ['sui', 'starknet'];
|
|
28
|
+
const NEAR_CHAIN = 'near';
|
|
29
|
+
const WNEAR_CONTRACT_ADDRESS = 'wrap.near';
|
|
30
|
+
const isNep245Chain = (chain) => {
|
|
31
|
+
return NEP245_CHAINS.includes(chain);
|
|
32
|
+
};
|
|
33
|
+
const isTokenLookupChain = (chain) => {
|
|
34
|
+
return TOKEN_LOOKUP_CHAINS.includes(chain);
|
|
35
|
+
};
|
|
28
36
|
export const assetToNearIntentsAsset = async (asset) => {
|
|
29
37
|
const nearNetwork = chainIdToNearIntentsChain[asset.chainId];
|
|
30
38
|
if (!nearNetwork)
|
|
31
39
|
return null;
|
|
32
|
-
//
|
|
40
|
+
// NEAR chain requires special handling
|
|
41
|
+
// Native NEAR maps to wNEAR (wrap.near)
|
|
42
|
+
if (nearNetwork === NEAR_CHAIN) {
|
|
43
|
+
const tokens = await OneClickService.getTokens();
|
|
44
|
+
const { assetNamespace, assetReference } = fromAssetId(asset.assetId);
|
|
45
|
+
const isNativeAsset = assetNamespace === 'slip44';
|
|
46
|
+
// Native NEAR maps to wNEAR, tokens use their contract address directly
|
|
47
|
+
const contractAddress = isNativeAsset ? WNEAR_CONTRACT_ADDRESS : assetReference;
|
|
48
|
+
const match = tokens.find((t) => {
|
|
49
|
+
if (t.blockchain !== NEAR_CHAIN)
|
|
50
|
+
return false;
|
|
51
|
+
return t.contractAddress === contractAddress;
|
|
52
|
+
});
|
|
53
|
+
return match?.assetId ?? null;
|
|
54
|
+
}
|
|
55
|
+
// NEP-245 chains (BSC, Polygon, Avalanche, Optimism, TRON, Monad), Token lookup chains (Sui, Starknet), and Solana require token lookup
|
|
33
56
|
// Asset IDs use hashed format that can't be generated from contract addresses
|
|
34
|
-
const requiresLookup =
|
|
35
|
-
TOKEN_LOOKUP_CHAINS.includes(nearNetwork) ||
|
|
36
|
-
asset.chainId === solanaChainId ||
|
|
37
|
-
asset.chainId === suiChainId;
|
|
57
|
+
const requiresLookup = isNep245Chain(nearNetwork) || isTokenLookupChain(nearNetwork) || asset.chainId === solanaChainId;
|
|
38
58
|
if (requiresLookup) {
|
|
39
59
|
const tokens = await OneClickService.getTokens();
|
|
40
60
|
const { assetNamespace, assetReference } = fromAssetId(asset.assetId);
|
|
41
61
|
const isNativeAsset = assetNamespace === 'slip44';
|
|
42
62
|
const contractAddress = !isNativeAsset ? assetReference.toLowerCase() : null;
|
|
43
63
|
const match = tokens.find((t) => {
|
|
44
|
-
if (t.blockchain !== nearNetwork)
|
|
64
|
+
if (typeof t.blockchain !== 'string' || t.blockchain !== nearNetwork)
|
|
45
65
|
return false;
|
|
46
66
|
return contractAddress
|
|
47
67
|
? t.contractAddress?.toLowerCase() === contractAddress
|
|
@@ -5,7 +5,7 @@ export const chainIdToPortalsNetwork = {
|
|
|
5
5
|
[KnownChainIds.OptimismMainnet]: 'optimism',
|
|
6
6
|
[KnownChainIds.BnbSmartChainMainnet]: 'bsc',
|
|
7
7
|
[KnownChainIds.PolygonMainnet]: 'polygon',
|
|
8
|
-
[KnownChainIds.GnosisMainnet]: 'gnosis',
|
|
9
8
|
[KnownChainIds.ArbitrumMainnet]: 'arbitrum',
|
|
10
9
|
[KnownChainIds.BaseMainnet]: 'base',
|
|
10
|
+
[KnownChainIds.HyperEvmMainnet]: 'hyperevm',
|
|
11
11
|
};
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { evm } from '@shapeshiftoss/chain-adapters';
|
|
2
|
+
import { TxStatus } from '@shapeshiftoss/unchained-client';
|
|
2
3
|
import BigNumber from 'bignumber.js';
|
|
3
4
|
import { checkEvmSwapStatus, getExecutableTradeStep, isExecutableTradeQuote } from '../../utils.js';
|
|
4
5
|
import { getPortalsTradeQuote } from './getPortalsTradeQuote/getPortalsTradeQuote.js';
|
|
5
6
|
import { getPortalsTradeRate } from './getPortalsTradeRate/getPortalsTradeRate.js';
|
|
7
|
+
import { fetchAxelarscanBridgeStatus, getAxelarscanTrackingLink, } from './utils/fetchAxelarscanStatus.js';
|
|
8
|
+
import { fetchSquidBridgeStatus, getSquidTrackingLink } from './utils/fetchSquidStatus.js';
|
|
6
9
|
export const portalsApi = {
|
|
7
10
|
getTradeQuote: async (input, { config, assertGetEvmChainAdapter }) => {
|
|
8
11
|
const tradeQuoteResult = await getPortalsTradeQuote(input, assertGetEvmChainAdapter, config);
|
|
@@ -46,5 +49,93 @@ export const portalsApi = {
|
|
|
46
49
|
gasLimit: BigNumber.max(feeData.gasLimit, estimatedGas).toFixed(),
|
|
47
50
|
});
|
|
48
51
|
},
|
|
49
|
-
checkTradeStatus:
|
|
52
|
+
checkTradeStatus: async (input) => {
|
|
53
|
+
const { txHash, chainId, swap, assertGetEvmChainAdapter, address, fetchIsSmartContractAddressQuery, } = input;
|
|
54
|
+
const isCrossChain = Boolean(swap && swap.sellAsset.chainId !== swap.buyAsset?.chainId);
|
|
55
|
+
if (!isCrossChain) {
|
|
56
|
+
return checkEvmSwapStatus({
|
|
57
|
+
txHash,
|
|
58
|
+
chainId,
|
|
59
|
+
address,
|
|
60
|
+
assertGetEvmChainAdapter,
|
|
61
|
+
fetchIsSmartContractAddressQuery,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
const sourceTxStatus = await checkEvmSwapStatus({
|
|
65
|
+
txHash,
|
|
66
|
+
chainId,
|
|
67
|
+
address,
|
|
68
|
+
assertGetEvmChainAdapter,
|
|
69
|
+
fetchIsSmartContractAddressQuery,
|
|
70
|
+
});
|
|
71
|
+
if (sourceTxStatus.status === TxStatus.Pending || sourceTxStatus.status === TxStatus.Unknown) {
|
|
72
|
+
return {
|
|
73
|
+
status: TxStatus.Pending,
|
|
74
|
+
buyTxHash: undefined,
|
|
75
|
+
message: 'Source transaction pending',
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
if (sourceTxStatus.status === TxStatus.Failed) {
|
|
79
|
+
return sourceTxStatus;
|
|
80
|
+
}
|
|
81
|
+
const axelarscanResult = await fetchAxelarscanBridgeStatus(txHash);
|
|
82
|
+
if ((axelarscanResult.isErr() || !axelarscanResult.unwrap()) && swap) {
|
|
83
|
+
const squidResult = await fetchSquidBridgeStatus(txHash, swap.sellAsset.chainId, swap.buyAsset.chainId);
|
|
84
|
+
if (squidResult.isOk()) {
|
|
85
|
+
const squidStatus = squidResult.unwrap();
|
|
86
|
+
const squidTxStatus = (() => {
|
|
87
|
+
switch (squidStatus.status) {
|
|
88
|
+
case 'confirmed':
|
|
89
|
+
return TxStatus.Confirmed;
|
|
90
|
+
case 'failed':
|
|
91
|
+
return TxStatus.Failed;
|
|
92
|
+
case 'pending':
|
|
93
|
+
default:
|
|
94
|
+
return TxStatus.Pending;
|
|
95
|
+
}
|
|
96
|
+
})();
|
|
97
|
+
return {
|
|
98
|
+
status: squidTxStatus,
|
|
99
|
+
buyTxHash: squidStatus.destinationTxHash,
|
|
100
|
+
relayerExplorerTxLink: getSquidTrackingLink(txHash, squidStatus, swap.sellAsset.explorerTxLink, swap.buyAsset.explorerTxLink),
|
|
101
|
+
message: squidTxStatus === TxStatus.Pending ? 'Cross-chain swap in progress' : undefined,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
status: TxStatus.Pending,
|
|
106
|
+
buyTxHash: undefined,
|
|
107
|
+
relayerExplorerTxLink: getAxelarscanTrackingLink(txHash),
|
|
108
|
+
message: 'Bridge status check failed - track manually',
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
const bridgeStatus = axelarscanResult.unwrap();
|
|
112
|
+
if (!bridgeStatus) {
|
|
113
|
+
return {
|
|
114
|
+
status: TxStatus.Pending,
|
|
115
|
+
buyTxHash: undefined,
|
|
116
|
+
message: 'Cross-chain swap in progress',
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
const txStatus = (() => {
|
|
120
|
+
switch (bridgeStatus.status) {
|
|
121
|
+
case 'confirmed':
|
|
122
|
+
return TxStatus.Confirmed;
|
|
123
|
+
case 'failed':
|
|
124
|
+
return TxStatus.Failed;
|
|
125
|
+
case 'pending':
|
|
126
|
+
default:
|
|
127
|
+
return TxStatus.Pending;
|
|
128
|
+
}
|
|
129
|
+
})();
|
|
130
|
+
return {
|
|
131
|
+
status: txStatus,
|
|
132
|
+
buyTxHash: bridgeStatus.destinationTxHash,
|
|
133
|
+
relayerExplorerTxLink: getAxelarscanTrackingLink(txHash),
|
|
134
|
+
message: txStatus === TxStatus.Pending
|
|
135
|
+
? 'Bridge in progress'
|
|
136
|
+
: txStatus === TxStatus.Failed
|
|
137
|
+
? bridgeStatus.errorMessage
|
|
138
|
+
: undefined,
|
|
139
|
+
};
|
|
140
|
+
},
|
|
50
141
|
};
|
|
@@ -9,7 +9,7 @@ import { getInputOutputRate, makeSwapErrorRight } from '../../../utils.js';
|
|
|
9
9
|
import { getTreasuryAddressFromChainId, isNativeEvmAsset } from '../../utils/helpers/helpers.js';
|
|
10
10
|
import { chainIdToPortalsNetwork } from '../constants.js';
|
|
11
11
|
import { fetchPortalsTradeOrder, PortalsError } from '../utils/fetchPortalsTradeOrder.js';
|
|
12
|
-
import { isSupportedChainId } from '../utils/helpers.js';
|
|
12
|
+
import { getPortalsRouterAddressByChainId, isSupportedChainId } from '../utils/helpers.js';
|
|
13
13
|
export async function getPortalsTradeQuote(input, assertGetEvmChainAdapter, swapperConfig) {
|
|
14
14
|
const { sellAsset, buyAsset, sendAddress, accountNumber, affiliateBps, chainId, supportsEIP1559, sellAmountIncludingProtocolFeesCryptoBaseUnit, } = input;
|
|
15
15
|
const sellAssetChainId = sellAsset.chainId;
|
|
@@ -25,16 +25,10 @@ export async function getPortalsTradeQuote(input, assertGetEvmChainAdapter, swap
|
|
|
25
25
|
return Err(makeSwapErrorRight({
|
|
26
26
|
message: `unsupported chainId`,
|
|
27
27
|
code: TradeQuoteError.UnsupportedChain,
|
|
28
|
-
details: { chainId:
|
|
29
|
-
}));
|
|
30
|
-
}
|
|
31
|
-
if (sellAssetChainId !== buyAssetChainId) {
|
|
32
|
-
return Err(makeSwapErrorRight({
|
|
33
|
-
message: `cross-chain not supported - both assets must be on chainId ${sellAsset.chainId}`,
|
|
34
|
-
code: TradeQuoteError.CrossChainNotSupported,
|
|
35
|
-
details: { buyAsset, sellAsset },
|
|
28
|
+
details: { chainId: buyAsset.chainId },
|
|
36
29
|
}));
|
|
37
30
|
}
|
|
31
|
+
const isCrossChain = sellAssetChainId !== buyAssetChainId;
|
|
38
32
|
// Not a decimal percentage, just a good ol' percentage e.g 1 for 1%
|
|
39
33
|
const affiliateBpsPercentage = convertBasisPointsToDecimalPercentage(affiliateBps)
|
|
40
34
|
.times(100)
|
|
@@ -46,12 +40,20 @@ export async function getPortalsTradeQuote(input, assertGetEvmChainAdapter, swap
|
|
|
46
40
|
.toNumber();
|
|
47
41
|
if (!sendAddress)
|
|
48
42
|
return Err(makeSwapErrorRight({ message: 'missing sendAddress' }));
|
|
49
|
-
const
|
|
50
|
-
|
|
43
|
+
const sellPortalsNetwork = chainIdToPortalsNetwork[sellAssetChainId];
|
|
44
|
+
const buyPortalsNetwork = chainIdToPortalsNetwork[buyAssetChainId];
|
|
45
|
+
if (!sellPortalsNetwork) {
|
|
46
|
+
return Err(makeSwapErrorRight({
|
|
47
|
+
message: `unsupported ChainId`,
|
|
48
|
+
code: TradeQuoteError.UnsupportedChain,
|
|
49
|
+
details: { chainId: sellAssetChainId },
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
52
|
+
if (!buyPortalsNetwork) {
|
|
51
53
|
return Err(makeSwapErrorRight({
|
|
52
54
|
message: `unsupported ChainId`,
|
|
53
55
|
code: TradeQuoteError.UnsupportedChain,
|
|
54
|
-
details: { chainId:
|
|
56
|
+
details: { chainId: buyAssetChainId },
|
|
55
57
|
}));
|
|
56
58
|
}
|
|
57
59
|
const sellAssetAddress = isNativeEvmAsset(sellAsset.assetId)
|
|
@@ -60,8 +62,8 @@ export async function getPortalsTradeQuote(input, assertGetEvmChainAdapter, swap
|
|
|
60
62
|
const buyAssetAddress = isNativeEvmAsset(buyAsset.assetId)
|
|
61
63
|
? zeroAddress
|
|
62
64
|
: fromAssetId(buyAsset.assetId).assetReference;
|
|
63
|
-
const inputToken = `${
|
|
64
|
-
const outputToken = `${
|
|
65
|
+
const inputToken = `${sellPortalsNetwork}:${sellAssetAddress}`;
|
|
66
|
+
const outputToken = `${buyPortalsNetwork}:${buyAssetAddress}`;
|
|
65
67
|
try {
|
|
66
68
|
const maybePortalsTradeOrderResponse = await fetchPortalsTradeOrder({
|
|
67
69
|
sender: sendAddress,
|
|
@@ -127,7 +129,9 @@ export async function getPortalsTradeQuote(input, assertGetEvmChainAdapter, swap
|
|
|
127
129
|
if (maybePortalsTradeOrderResponse.isErr())
|
|
128
130
|
return Err(maybePortalsTradeOrderResponse.unwrapErr());
|
|
129
131
|
const portalsTradeOrderResponse = maybePortalsTradeOrderResponse.unwrap();
|
|
130
|
-
const { context: { orderId, outputAmount
|
|
132
|
+
const { context: { orderId, outputAmount, minOutputAmount, target, feeAmount, gasLimit, feeToken }, tx, } = portalsTradeOrderResponse;
|
|
133
|
+
const allowanceContract = isCrossChain ? target : getPortalsRouterAddressByChainId(chainId);
|
|
134
|
+
const buyAmountAfterFeesCryptoBaseUnit = isCrossChain ? minOutputAmount : outputAmount;
|
|
131
135
|
const protocolFeeAsset = feeToken === inputToken ? sellAsset : buyAsset;
|
|
132
136
|
if (!tx)
|
|
133
137
|
throw new Error('Portals Tx simulation failed upstream');
|
|
@@ -186,9 +190,17 @@ export async function getPortalsTradeQuote(input, assertGetEvmChainAdapter, swap
|
|
|
186
190
|
},
|
|
187
191
|
},
|
|
188
192
|
source: SwapperName.Portals,
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
193
|
+
estimatedExecutionTimeMs: isCrossChain ? 300000 : 0,
|
|
194
|
+
portalsTransactionMetadata: {
|
|
195
|
+
...tx,
|
|
196
|
+
isCrossChain,
|
|
197
|
+
buyAssetChainId: isCrossChain ? buyAssetChainId : undefined,
|
|
198
|
+
expiry: portalsTradeOrderResponse.context.expiry
|
|
199
|
+
? Number(portalsTradeOrderResponse.context.expiry)
|
|
200
|
+
: undefined,
|
|
201
|
+
steps: portalsTradeOrderResponse.context.steps,
|
|
202
|
+
route: portalsTradeOrderResponse.context.route,
|
|
203
|
+
},
|
|
192
204
|
},
|
|
193
205
|
],
|
|
194
206
|
};
|
|
@@ -31,22 +31,24 @@ export async function getPortalsTradeRate(input, assertGetEvmChainAdapter, swapp
|
|
|
31
31
|
details: { chainId: sellAsset.chainId },
|
|
32
32
|
}));
|
|
33
33
|
}
|
|
34
|
-
|
|
35
|
-
return Err(makeSwapErrorRight({
|
|
36
|
-
message: `cross-chain not supported - both assets must be on chainId ${sellAsset.chainId}`,
|
|
37
|
-
code: TradeQuoteError.CrossChainNotSupported,
|
|
38
|
-
details: { buyAsset, sellAsset },
|
|
39
|
-
}));
|
|
40
|
-
}
|
|
34
|
+
const isCrossChain = sellAssetChainId !== buyAssetChainId;
|
|
41
35
|
try {
|
|
42
36
|
if (!isSupportedChainId(chainId))
|
|
43
37
|
throw new Error(`Unsupported chainId ${sellAsset.chainId}`);
|
|
44
|
-
const
|
|
45
|
-
|
|
38
|
+
const sellPortalsNetwork = chainIdToPortalsNetwork[sellAssetChainId];
|
|
39
|
+
const buyPortalsNetwork = chainIdToPortalsNetwork[buyAssetChainId];
|
|
40
|
+
if (!sellPortalsNetwork) {
|
|
41
|
+
return Err(makeSwapErrorRight({
|
|
42
|
+
message: `unsupported ChainId`,
|
|
43
|
+
code: TradeQuoteError.UnsupportedChain,
|
|
44
|
+
details: { chainId: sellAssetChainId },
|
|
45
|
+
}));
|
|
46
|
+
}
|
|
47
|
+
if (!buyPortalsNetwork) {
|
|
46
48
|
return Err(makeSwapErrorRight({
|
|
47
49
|
message: `unsupported ChainId`,
|
|
48
50
|
code: TradeQuoteError.UnsupportedChain,
|
|
49
|
-
details: { chainId:
|
|
51
|
+
details: { chainId: buyAssetChainId },
|
|
50
52
|
}));
|
|
51
53
|
}
|
|
52
54
|
const sellAssetAddress = isNativeEvmAsset(sellAsset.assetId)
|
|
@@ -55,8 +57,8 @@ export async function getPortalsTradeRate(input, assertGetEvmChainAdapter, swapp
|
|
|
55
57
|
const buyAssetAddress = isNativeEvmAsset(buyAsset.assetId)
|
|
56
58
|
? zeroAddress
|
|
57
59
|
: fromAssetId(buyAsset.assetId).assetReference;
|
|
58
|
-
const inputToken = `${
|
|
59
|
-
const outputToken = `${
|
|
60
|
+
const inputToken = `${sellPortalsNetwork}:${sellAssetAddress}`;
|
|
61
|
+
const outputToken = `${buyPortalsNetwork}:${buyAssetAddress}`;
|
|
60
62
|
const userSlippageTolerancePercentageDecimalOrDefault = input.slippageTolerancePercentageDecimal
|
|
61
63
|
? bnOrZero(input.slippageTolerancePercentageDecimal).times(100).toNumber()
|
|
62
64
|
: bnOrZero(getDefaultSlippageDecimalPercentageForSwapper(SwapperName.Portals))
|
|
@@ -86,15 +88,18 @@ export async function getPortalsTradeRate(input, assertGetEvmChainAdapter, swapp
|
|
|
86
88
|
throw new Error('Portals quote response missing transaction data');
|
|
87
89
|
}
|
|
88
90
|
const { context, tx } = quoteResponse;
|
|
89
|
-
|
|
90
|
-
|
|
91
|
+
const buyAmountAfterFeesCryptoBaseUnit = isCrossChain
|
|
92
|
+
? context.minOutputAmount
|
|
93
|
+
: context.outputAmount;
|
|
91
94
|
const inputOutputRate = getInputOutputRate({
|
|
92
95
|
sellAmountCryptoBaseUnit: input.sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
93
96
|
buyAmountCryptoBaseUnit: buyAmountAfterFeesCryptoBaseUnit,
|
|
94
97
|
sellAsset,
|
|
95
98
|
buyAsset,
|
|
96
99
|
});
|
|
97
|
-
const allowanceContract =
|
|
100
|
+
const allowanceContract = isCrossChain
|
|
101
|
+
? context.target
|
|
102
|
+
: getPortalsRouterAddressByChainId(chainId);
|
|
98
103
|
// Don't use Portals' slippageTolerancePercentage field (it's a price indicator, not actual buffer)
|
|
99
104
|
// Instead, calculate the actual buffer Portals applied from the amounts
|
|
100
105
|
const actualBufferDecimal = bnOrZero(context.outputAmount)
|
|
@@ -150,8 +155,7 @@ export async function getPortalsTradeRate(input, assertGetEvmChainAdapter, swapp
|
|
|
150
155
|
swapperName: SwapperName.Portals,
|
|
151
156
|
steps: [
|
|
152
157
|
{
|
|
153
|
-
|
|
154
|
-
estimatedExecutionTimeMs: 0,
|
|
158
|
+
estimatedExecutionTimeMs: isCrossChain ? 300000 : 0,
|
|
155
159
|
allowanceContract,
|
|
156
160
|
accountNumber,
|
|
157
161
|
rate: inputOutputRate,
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Result } from '@sniptt/monads';
|
|
2
|
+
import type { SwapErrorRight } from '../../../types.js';
|
|
3
|
+
export type AxelarscanBridgeStatus = {
|
|
4
|
+
status: 'pending' | 'confirmed' | 'failed';
|
|
5
|
+
destinationTxHash?: string;
|
|
6
|
+
errorMessage?: string;
|
|
7
|
+
};
|
|
8
|
+
export declare const fetchAxelarscanBridgeStatus: (sourceTxHash: string) => Promise<Result<AxelarscanBridgeStatus | undefined, SwapErrorRight>>;
|
|
9
|
+
export declare const getAxelarscanTrackingLink: (sourceTxHash: string) => string;
|