@shapeshiftoss/swapper 17.6.10 → 17.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +21 -0
- package/dist/cjs/.tsbuildinfo +1 -1
- package/dist/cjs/constants.js +11 -10
- package/dist/cjs/cowswap-utils/constants.js +3 -0
- package/dist/cjs/cowswap-utils/index.js +6 -0
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/solana-utils/getUnsignedSolanaTransaction.js +4 -2
- package/dist/cjs/swappers/AcrossSwapper/constant.js +2 -0
- package/dist/cjs/swappers/AcrossSwapper/utils/getTrade.js +15 -1
- package/dist/cjs/swappers/AvnuSwapper/swapperApi/getTradeQuote.js +12 -1
- package/dist/cjs/swappers/AvnuSwapper/swapperApi/getTradeRate.js +9 -0
- package/dist/cjs/swappers/BebopSwapper/BebopSwapper.js +2 -0
- package/dist/cjs/swappers/BebopSwapper/endpoints.js +35 -2
- package/dist/cjs/swappers/BebopSwapper/executeSolanaMessage.d.ts +2 -0
- package/dist/cjs/swappers/BebopSwapper/executeSolanaMessage.js +47 -0
- package/dist/cjs/swappers/BebopSwapper/getBebopSolanaTradeQuote/getBebopSolanaTradeQuote.d.ts +4 -0
- package/dist/cjs/swappers/BebopSwapper/getBebopSolanaTradeQuote/getBebopSolanaTradeQuote.js +91 -0
- package/dist/cjs/swappers/BebopSwapper/getBebopSolanaTradeRate/getBebopSolanaTradeRate.d.ts +4 -0
- package/dist/cjs/swappers/BebopSwapper/getBebopSolanaTradeRate/getBebopSolanaTradeRate.js +88 -0
- package/dist/cjs/swappers/BebopSwapper/getBebopTradeQuote/getBebopTradeQuote.js +10 -0
- package/dist/cjs/swappers/BebopSwapper/getBebopTradeRate/getBebopTradeRate.js +10 -0
- package/dist/cjs/swappers/BebopSwapper/types.d.ts +49 -1
- package/dist/cjs/swappers/BebopSwapper/types.js +9 -2
- package/dist/cjs/swappers/BebopSwapper/utils/fetchFromBebop.d.ts +19 -1
- package/dist/cjs/swappers/BebopSwapper/utils/fetchFromBebop.js +86 -1
- package/dist/cjs/swappers/BebopSwapper/utils/helpers/helpers.d.ts +13 -1
- package/dist/cjs/swappers/BebopSwapper/utils/helpers/helpers.js +47 -1
- package/dist/cjs/swappers/ButterSwap/swapperApi/getTradeQuote.js +17 -1
- package/dist/cjs/swappers/ButterSwap/swapperApi/getTradeRate.js +10 -0
- package/dist/cjs/swappers/CetusSwapper/swapperApi/getTradeQuote.js +10 -0
- package/dist/cjs/swappers/CetusSwapper/swapperApi/getTradeRate.js +10 -0
- package/dist/cjs/swappers/CetusSwapper/utils/helpers.d.ts +1 -1
- package/dist/cjs/swappers/CetusSwapper/utils/helpers.js +1 -1
- package/dist/cjs/swappers/ChainflipSwapper/constants.js +7 -3
- package/dist/cjs/swappers/ChainflipSwapper/endpoints.js +14 -4
- package/dist/cjs/swappers/ChainflipSwapper/types.d.ts +1 -0
- package/dist/cjs/swappers/ChainflipSwapper/utils/getQuoteOrRate.js +17 -0
- package/dist/cjs/swappers/CowSwapper/getCowSwapTradeQuote/getCowSwapTradeQuote.js +10 -0
- package/dist/cjs/swappers/CowSwapper/getCowSwapTradeRate/getCowSwapTradeRate.js +9 -0
- package/dist/cjs/swappers/DebridgeSwapper/DebridgeSwapper.d.ts +2 -0
- package/dist/cjs/swappers/DebridgeSwapper/DebridgeSwapper.js +7 -0
- package/dist/cjs/swappers/DebridgeSwapper/constant.d.ts +5 -0
- package/dist/cjs/swappers/DebridgeSwapper/constant.js +36 -0
- package/dist/cjs/swappers/{JupiterSwapper → DebridgeSwapper}/endpoints.d.ts +1 -1
- package/dist/cjs/swappers/DebridgeSwapper/endpoints.js +217 -0
- package/dist/cjs/swappers/DebridgeSwapper/getTradeQuote/getTradeQuote.js +31 -0
- package/dist/cjs/swappers/DebridgeSwapper/getTradeRate/getTradeRate.js +19 -0
- package/dist/cjs/swappers/DebridgeSwapper/index.d.ts +1 -0
- package/dist/cjs/swappers/DebridgeSwapper/index.js +5 -0
- package/dist/cjs/swappers/{JupiterSwapper/utils/jupiterService.d.ts → DebridgeSwapper/utils/debridgeService.d.ts} +1 -1
- package/dist/cjs/swappers/DebridgeSwapper/utils/debridgeService.js +17 -0
- package/dist/cjs/swappers/DebridgeSwapper/utils/fetchDebridgeSingleChainTrade.d.ts +16 -0
- package/dist/cjs/swappers/DebridgeSwapper/utils/fetchDebridgeSingleChainTrade.js +23 -0
- package/dist/cjs/swappers/DebridgeSwapper/utils/fetchDebridgeTrade.d.ts +20 -0
- package/dist/cjs/swappers/DebridgeSwapper/utils/fetchDebridgeTrade.js +29 -0
- package/dist/cjs/swappers/DebridgeSwapper/utils/getTrade.d.ts +11 -0
- package/dist/cjs/swappers/DebridgeSwapper/utils/getTrade.js +367 -0
- package/dist/cjs/swappers/DebridgeSwapper/utils/types.d.ts +155 -0
- package/dist/cjs/swappers/DebridgeSwapper/utils/types.js +9 -0
- package/dist/cjs/swappers/MayachainSwapper/utils/poolAssetHelpers/poolAssetHelpers.js +1 -1
- package/dist/cjs/swappers/NearIntentsSwapper/swapperApi/getTradeQuote.js +12 -0
- package/dist/cjs/swappers/NearIntentsSwapper/swapperApi/getTradeRate.js +12 -0
- package/dist/cjs/swappers/PortalsSwapper/getPortalsTradeQuote/getPortalsTradeQuote.js +10 -0
- package/dist/cjs/swappers/RelaySwapper/constant.js +7 -10
- package/dist/cjs/swappers/RelaySwapper/endpoints.js +1 -1
- package/dist/cjs/swappers/RelaySwapper/utils/getTrade.js +56 -7
- package/dist/cjs/swappers/RelaySwapper/utils/relayTokenToAssetId.js +22 -7
- package/dist/cjs/swappers/StonfiSwapper/swapperApi/getTradeQuote.js +12 -1
- package/dist/cjs/swappers/StonfiSwapper/swapperApi/getTradeRate.js +10 -0
- package/dist/cjs/swappers/SunioSwapper/utils/getQuoteOrRate.js +10 -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 +1 -0
- package/dist/cjs/swappers/ThorchainSwapper/utils/poolAssetHelpers/poolAssetHelpers.d.ts +1 -1
- package/dist/cjs/swappers/ThorchainSwapper/utils/poolAssetHelpers/poolAssetHelpers.js +2 -1
- package/dist/cjs/swappers/ThorchainSwapper/utils/poolAssetHelpers/poolAssetHelpers.test.js +10 -0
- package/dist/cjs/swappers/ZrxSwapper/getZrxTradeQuote/getZrxTradeQuote.js +9 -0
- package/dist/cjs/swappers/ZrxSwapper/getZrxTradeRate/getZrxTradeRate.js +9 -0
- package/dist/cjs/swappers/utils/affiliateFee.d.ts +17 -0
- package/dist/cjs/swappers/utils/affiliateFee.js +43 -0
- package/dist/cjs/thorchain-utils/getL1RateOrQuote.js +57 -4
- package/dist/cjs/thorchain-utils/index.d.ts +2 -1
- package/dist/cjs/thorchain-utils/index.js +2 -1
- package/dist/cjs/thorchain-utils/solana/constants.d.ts +1 -0
- package/dist/cjs/thorchain-utils/solana/constants.js +6 -0
- package/dist/cjs/thorchain-utils/solana/getSolanaTransactionFees.d.ts +2 -0
- package/dist/cjs/thorchain-utils/solana/getSolanaTransactionFees.js +41 -0
- package/dist/cjs/thorchain-utils/solana/getThorTxData.d.ts +12 -0
- package/dist/cjs/thorchain-utils/solana/getThorTxData.js +14 -0
- package/dist/cjs/thorchain-utils/solana/getUnsignedSolanaTransaction.d.ts +3 -0
- package/dist/cjs/thorchain-utils/solana/getUnsignedSolanaTransaction.js +64 -0
- package/dist/cjs/thorchain-utils/solana/index.d.ts +3 -0
- package/dist/cjs/{swappers/JupiterSwapper → thorchain-utils/solana}/index.js +3 -2
- package/dist/cjs/tron-utils/getUnsignedTronTransaction.js +16 -0
- package/dist/cjs/types.d.ts +47 -11
- package/dist/cjs/types.js +1 -1
- package/dist/cjs/utils.d.ts +3 -0
- package/dist/cjs/utils.js +9 -3
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/constants.js +11 -10
- package/dist/esm/cowswap-utils/constants.js +3 -0
- package/dist/esm/cowswap-utils/index.js +6 -0
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/solana-utils/getUnsignedSolanaTransaction.js +3 -1
- package/dist/esm/swappers/AcrossSwapper/constant.js +4 -2
- package/dist/esm/swappers/AcrossSwapper/utils/getTrade.js +15 -1
- package/dist/esm/swappers/AvnuSwapper/swapperApi/getTradeQuote.js +12 -1
- package/dist/esm/swappers/AvnuSwapper/swapperApi/getTradeRate.js +9 -0
- package/dist/esm/swappers/BebopSwapper/BebopSwapper.js +2 -0
- package/dist/esm/swappers/BebopSwapper/endpoints.js +36 -3
- package/dist/esm/swappers/BebopSwapper/executeSolanaMessage.d.ts +2 -0
- package/dist/esm/swappers/BebopSwapper/executeSolanaMessage.js +40 -0
- package/dist/esm/swappers/BebopSwapper/getBebopSolanaTradeQuote/getBebopSolanaTradeQuote.d.ts +4 -0
- package/dist/esm/swappers/BebopSwapper/getBebopSolanaTradeQuote/getBebopSolanaTradeQuote.js +87 -0
- package/dist/esm/swappers/BebopSwapper/getBebopSolanaTradeRate/getBebopSolanaTradeRate.d.ts +4 -0
- package/dist/esm/swappers/BebopSwapper/getBebopSolanaTradeRate/getBebopSolanaTradeRate.js +84 -0
- package/dist/esm/swappers/BebopSwapper/getBebopTradeQuote/getBebopTradeQuote.js +10 -0
- package/dist/esm/swappers/BebopSwapper/getBebopTradeRate/getBebopTradeRate.js +10 -0
- package/dist/esm/swappers/BebopSwapper/types.d.ts +49 -1
- package/dist/esm/swappers/BebopSwapper/types.js +8 -1
- package/dist/esm/swappers/BebopSwapper/utils/fetchFromBebop.d.ts +19 -1
- package/dist/esm/swappers/BebopSwapper/utils/fetchFromBebop.js +85 -2
- package/dist/esm/swappers/BebopSwapper/utils/helpers/helpers.d.ts +13 -1
- package/dist/esm/swappers/BebopSwapper/utils/helpers/helpers.js +44 -1
- package/dist/esm/swappers/ButterSwap/swapperApi/getTradeQuote.js +17 -1
- package/dist/esm/swappers/ButterSwap/swapperApi/getTradeRate.js +10 -0
- package/dist/esm/swappers/CetusSwapper/swapperApi/getTradeQuote.js +10 -0
- package/dist/esm/swappers/CetusSwapper/swapperApi/getTradeRate.js +10 -0
- package/dist/esm/swappers/CetusSwapper/utils/helpers.d.ts +1 -1
- package/dist/esm/swappers/CetusSwapper/utils/helpers.js +1 -1
- package/dist/esm/swappers/ChainflipSwapper/constants.js +8 -4
- package/dist/esm/swappers/ChainflipSwapper/endpoints.js +14 -4
- package/dist/esm/swappers/ChainflipSwapper/types.d.ts +1 -0
- package/dist/esm/swappers/ChainflipSwapper/utils/getQuoteOrRate.js +17 -0
- package/dist/esm/swappers/CowSwapper/getCowSwapTradeQuote/getCowSwapTradeQuote.js +10 -0
- package/dist/esm/swappers/CowSwapper/getCowSwapTradeRate/getCowSwapTradeRate.js +9 -0
- package/dist/esm/swappers/{JupiterSwapper/JupiterSwapper.d.ts → DebridgeSwapper/DebridgeSwapper.d.ts} +1 -1
- package/dist/esm/swappers/DebridgeSwapper/DebridgeSwapper.js +4 -0
- package/dist/esm/swappers/DebridgeSwapper/constant.d.ts +5 -0
- package/dist/esm/swappers/DebridgeSwapper/constant.js +30 -0
- package/dist/esm/swappers/{JupiterSwapper → DebridgeSwapper}/endpoints.d.ts +1 -1
- package/dist/esm/swappers/DebridgeSwapper/endpoints.js +211 -0
- package/dist/esm/swappers/DebridgeSwapper/getTradeQuote/getTradeQuote.js +27 -0
- package/dist/esm/swappers/DebridgeSwapper/getTradeRate/getTradeRate.js +15 -0
- package/dist/esm/swappers/DebridgeSwapper/index.d.ts +1 -0
- package/dist/esm/swappers/DebridgeSwapper/index.js +1 -0
- package/dist/esm/swappers/{JupiterSwapper/utils/jupiterService.d.ts → DebridgeSwapper/utils/debridgeService.d.ts} +1 -1
- package/dist/esm/swappers/DebridgeSwapper/utils/debridgeService.js +11 -0
- package/dist/esm/swappers/DebridgeSwapper/utils/fetchDebridgeSingleChainTrade.d.ts +16 -0
- package/dist/esm/swappers/DebridgeSwapper/utils/fetchDebridgeSingleChainTrade.js +19 -0
- package/dist/esm/swappers/DebridgeSwapper/utils/fetchDebridgeTrade.d.ts +20 -0
- package/dist/esm/swappers/DebridgeSwapper/utils/fetchDebridgeTrade.js +25 -0
- package/dist/esm/swappers/DebridgeSwapper/utils/getTrade.d.ts +11 -0
- package/dist/esm/swappers/DebridgeSwapper/utils/getTrade.js +360 -0
- package/dist/esm/swappers/DebridgeSwapper/utils/types.d.ts +155 -0
- package/dist/esm/swappers/DebridgeSwapper/utils/types.js +5 -0
- package/dist/esm/swappers/MayachainSwapper/utils/poolAssetHelpers/poolAssetHelpers.js +1 -1
- package/dist/esm/swappers/NearIntentsSwapper/swapperApi/getTradeQuote.js +14 -2
- package/dist/esm/swappers/NearIntentsSwapper/swapperApi/getTradeRate.js +14 -2
- package/dist/esm/swappers/PortalsSwapper/getPortalsTradeQuote/getPortalsTradeQuote.js +10 -0
- package/dist/esm/swappers/RelaySwapper/constant.js +9 -12
- package/dist/esm/swappers/RelaySwapper/endpoints.js +2 -2
- package/dist/esm/swappers/RelaySwapper/utils/getTrade.js +59 -10
- package/dist/esm/swappers/RelaySwapper/utils/relayTokenToAssetId.js +22 -7
- package/dist/esm/swappers/StonfiSwapper/swapperApi/getTradeQuote.js +12 -1
- package/dist/esm/swappers/StonfiSwapper/swapperApi/getTradeRate.js +10 -0
- package/dist/esm/swappers/SunioSwapper/utils/getQuoteOrRate.js +10 -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 +1 -0
- package/dist/esm/swappers/ThorchainSwapper/utils/poolAssetHelpers/poolAssetHelpers.d.ts +1 -1
- package/dist/esm/swappers/ThorchainSwapper/utils/poolAssetHelpers/poolAssetHelpers.js +2 -1
- package/dist/esm/swappers/ThorchainSwapper/utils/poolAssetHelpers/poolAssetHelpers.test.js +11 -1
- package/dist/esm/swappers/ZrxSwapper/getZrxTradeQuote/getZrxTradeQuote.js +9 -0
- package/dist/esm/swappers/ZrxSwapper/getZrxTradeRate/getZrxTradeRate.js +9 -0
- package/dist/esm/swappers/utils/affiliateFee.d.ts +17 -0
- package/dist/esm/swappers/utils/affiliateFee.js +39 -0
- package/dist/esm/thorchain-utils/getL1RateOrQuote.js +57 -4
- package/dist/esm/thorchain-utils/index.d.ts +2 -1
- package/dist/esm/thorchain-utils/index.js +1 -0
- package/dist/esm/thorchain-utils/solana/constants.d.ts +1 -0
- package/dist/esm/thorchain-utils/solana/constants.js +3 -0
- package/dist/esm/thorchain-utils/solana/getSolanaTransactionFees.d.ts +2 -0
- package/dist/esm/thorchain-utils/solana/getSolanaTransactionFees.js +37 -0
- package/dist/esm/thorchain-utils/solana/getThorTxData.d.ts +12 -0
- package/dist/esm/thorchain-utils/solana/getThorTxData.js +10 -0
- package/dist/esm/thorchain-utils/solana/getUnsignedSolanaTransaction.d.ts +3 -0
- package/dist/esm/thorchain-utils/solana/getUnsignedSolanaTransaction.js +60 -0
- package/dist/esm/thorchain-utils/solana/index.d.ts +3 -0
- package/dist/esm/thorchain-utils/solana/index.js +3 -0
- package/dist/esm/tron-utils/getUnsignedTronTransaction.js +16 -0
- package/dist/esm/types.d.ts +47 -11
- package/dist/esm/types.js +1 -1
- package/dist/esm/utils.d.ts +3 -0
- package/dist/esm/utils.js +7 -2
- package/package.json +19 -19
- package/dist/cjs/swappers/JupiterSwapper/JupiterSwapper.d.ts +0 -2
- package/dist/cjs/swappers/JupiterSwapper/JupiterSwapper.js +0 -27
- package/dist/cjs/swappers/JupiterSwapper/endpoints.js +0 -15
- package/dist/cjs/swappers/JupiterSwapper/errorPatterns.d.ts +0 -15
- package/dist/cjs/swappers/JupiterSwapper/errorPatterns.js +0 -29
- package/dist/cjs/swappers/JupiterSwapper/idls/referral.d.ts +0 -739
- package/dist/cjs/swappers/JupiterSwapper/idls/referral.js +0 -741
- package/dist/cjs/swappers/JupiterSwapper/index.d.ts +0 -2
- package/dist/cjs/swappers/JupiterSwapper/swapperApi/getTradeQuote.js +0 -191
- package/dist/cjs/swappers/JupiterSwapper/swapperApi/getTradeRate.js +0 -172
- package/dist/cjs/swappers/JupiterSwapper/utils/constants.d.ts +0 -9
- package/dist/cjs/swappers/JupiterSwapper/utils/constants.js +0 -14
- package/dist/cjs/swappers/JupiterSwapper/utils/helpers.d.ts +0 -56
- package/dist/cjs/swappers/JupiterSwapper/utils/helpers.js +0 -178
- package/dist/cjs/swappers/JupiterSwapper/utils/jupiterService.js +0 -15
- package/dist/esm/swappers/JupiterSwapper/JupiterSwapper.js +0 -24
- package/dist/esm/swappers/JupiterSwapper/endpoints.js +0 -12
- package/dist/esm/swappers/JupiterSwapper/errorPatterns.d.ts +0 -15
- package/dist/esm/swappers/JupiterSwapper/errorPatterns.js +0 -25
- package/dist/esm/swappers/JupiterSwapper/idls/referral.d.ts +0 -739
- package/dist/esm/swappers/JupiterSwapper/idls/referral.js +0 -738
- package/dist/esm/swappers/JupiterSwapper/index.d.ts +0 -2
- package/dist/esm/swappers/JupiterSwapper/index.js +0 -2
- package/dist/esm/swappers/JupiterSwapper/swapperApi/getTradeQuote.js +0 -187
- package/dist/esm/swappers/JupiterSwapper/swapperApi/getTradeRate.js +0 -168
- package/dist/esm/swappers/JupiterSwapper/utils/constants.d.ts +0 -9
- package/dist/esm/swappers/JupiterSwapper/utils/constants.js +0 -11
- package/dist/esm/swappers/JupiterSwapper/utils/helpers.d.ts +0 -56
- package/dist/esm/swappers/JupiterSwapper/utils/helpers.js +0 -169
- package/dist/esm/swappers/JupiterSwapper/utils/jupiterService.js +0 -12
- /package/dist/cjs/swappers/{JupiterSwapper/swapperApi → DebridgeSwapper/getTradeQuote}/getTradeQuote.d.ts +0 -0
- /package/dist/cjs/swappers/{JupiterSwapper/swapperApi → DebridgeSwapper/getTradeRate}/getTradeRate.d.ts +0 -0
- /package/dist/esm/swappers/{JupiterSwapper/swapperApi → DebridgeSwapper/getTradeQuote}/getTradeQuote.d.ts +0 -0
- /package/dist/esm/swappers/{JupiterSwapper/swapperApi → DebridgeSwapper/getTradeRate}/getTradeRate.d.ts +0 -0
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
import { fromAssetId, isAssetReference } from '@shapeshiftoss/caip';
|
|
2
|
+
import { evm, isEvmChainId } from '@shapeshiftoss/chain-adapters';
|
|
3
|
+
import { BigAmount, bnOrZero, chainIdToFeeAssetId, getBaseAsset, isTreasuryChainId, } from '@shapeshiftoss/utils';
|
|
4
|
+
import { Err, Ok } from '@sniptt/monads';
|
|
5
|
+
import axios from 'axios';
|
|
6
|
+
import { v4 as uuid } from 'uuid';
|
|
7
|
+
import { zeroAddress } from 'viem';
|
|
8
|
+
import { SwapperName, TradeQuoteError } from '../../../types.js';
|
|
9
|
+
import { getInputOutputRate, makeSwapErrorRight } from '../../../utils.js';
|
|
10
|
+
import { getTreasuryAddressFromChainId, isNativeEvmAsset } from '../../utils/helpers/helpers.js';
|
|
11
|
+
import { chainIdToDebridgeChainId, debridgeChainIdToChainId, DEFAULT_DEBRIDGE_TOKEN_ADDRESS, DEFAULT_DEBRIDGE_USER_ADDRESS, } from '../constant.js';
|
|
12
|
+
import { fetchDebridgeSingleChainTrade } from './fetchDebridgeSingleChainTrade.js';
|
|
13
|
+
import { fetchDebridgeTrade } from './fetchDebridgeTrade.js';
|
|
14
|
+
import { isDebridgeError } from './types.js';
|
|
15
|
+
const getDebridgeAssetAddress = (assetId) => {
|
|
16
|
+
if (isNativeEvmAsset(assetId))
|
|
17
|
+
return DEFAULT_DEBRIDGE_TOKEN_ADDRESS;
|
|
18
|
+
const { assetReference } = fromAssetId(assetId);
|
|
19
|
+
return isAssetReference(assetReference) ? zeroAddress : assetReference;
|
|
20
|
+
};
|
|
21
|
+
export async function getTrade({ input, deps, }) {
|
|
22
|
+
const { sellAsset, buyAsset, sellAmountIncludingProtocolFeesCryptoBaseUnit, affiliateBps } = input;
|
|
23
|
+
const isSameChainSwap = sellAsset.chainId === buyAsset.chainId;
|
|
24
|
+
const sellDebridgeChainId = chainIdToDebridgeChainId[sellAsset.chainId];
|
|
25
|
+
if (sellDebridgeChainId === undefined) {
|
|
26
|
+
return Err(makeSwapErrorRight({
|
|
27
|
+
message: `Sell asset chain '${sellAsset.chainId}' not supported by deBridge`,
|
|
28
|
+
code: TradeQuoteError.UnsupportedChain,
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
31
|
+
if (!isSameChainSwap) {
|
|
32
|
+
const buyDebridgeChainId = chainIdToDebridgeChainId[buyAsset.chainId];
|
|
33
|
+
if (buyDebridgeChainId === undefined) {
|
|
34
|
+
return Err(makeSwapErrorRight({
|
|
35
|
+
message: `Buy asset chain '${buyAsset.chainId}' not supported by deBridge`,
|
|
36
|
+
code: TradeQuoteError.UnsupportedChain,
|
|
37
|
+
}));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const senderAddress = (() => {
|
|
41
|
+
if (input.quoteOrRate === 'rate') {
|
|
42
|
+
if (input.sendAddress)
|
|
43
|
+
return input.sendAddress;
|
|
44
|
+
return DEFAULT_DEBRIDGE_USER_ADDRESS;
|
|
45
|
+
}
|
|
46
|
+
return input.sendAddress ?? DEFAULT_DEBRIDGE_USER_ADDRESS;
|
|
47
|
+
})();
|
|
48
|
+
const recipientAddress = (() => {
|
|
49
|
+
if (input.quoteOrRate === 'rate') {
|
|
50
|
+
if (input.receiveAddress)
|
|
51
|
+
return input.receiveAddress;
|
|
52
|
+
return DEFAULT_DEBRIDGE_USER_ADDRESS;
|
|
53
|
+
}
|
|
54
|
+
return input.receiveAddress;
|
|
55
|
+
})();
|
|
56
|
+
const affiliateFeePercent = (() => {
|
|
57
|
+
if (!isTreasuryChainId(sellAsset.chainId))
|
|
58
|
+
return undefined;
|
|
59
|
+
const bps = bnOrZero(affiliateBps);
|
|
60
|
+
if (!bps.isFinite() || bps.lte(0))
|
|
61
|
+
return undefined;
|
|
62
|
+
return bps.div(100).toFixed();
|
|
63
|
+
})();
|
|
64
|
+
const affiliateFeeRecipient = (() => {
|
|
65
|
+
if (affiliateFeePercent === undefined)
|
|
66
|
+
return undefined;
|
|
67
|
+
try {
|
|
68
|
+
return getTreasuryAddressFromChainId(sellAsset.chainId).toLowerCase();
|
|
69
|
+
}
|
|
70
|
+
catch (e) {
|
|
71
|
+
console.error(`[getTrade] Failed to get treasury address for chainId ${sellAsset.chainId}, affiliate fee will not be applied`, e);
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
})();
|
|
75
|
+
if (isSameChainSwap) {
|
|
76
|
+
return getSameChainTrade({
|
|
77
|
+
input,
|
|
78
|
+
deps,
|
|
79
|
+
sellDebridgeChainId,
|
|
80
|
+
senderAddress,
|
|
81
|
+
recipientAddress,
|
|
82
|
+
affiliateFeePercent,
|
|
83
|
+
affiliateFeeRecipient,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
const buyDebridgeChainId = chainIdToDebridgeChainId[buyAsset.chainId];
|
|
87
|
+
if (buyDebridgeChainId === undefined) {
|
|
88
|
+
return Err(makeSwapErrorRight({
|
|
89
|
+
message: `Buy asset chain '${buyAsset.chainId}' not supported by deBridge`,
|
|
90
|
+
code: TradeQuoteError.UnsupportedChain,
|
|
91
|
+
}));
|
|
92
|
+
}
|
|
93
|
+
const maybeQuote = await fetchDebridgeTrade({
|
|
94
|
+
srcChainId: sellDebridgeChainId,
|
|
95
|
+
srcChainTokenIn: getDebridgeAssetAddress(sellAsset.assetId),
|
|
96
|
+
srcChainTokenInAmount: sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
97
|
+
dstChainId: buyDebridgeChainId,
|
|
98
|
+
dstChainTokenOut: getDebridgeAssetAddress(buyAsset.assetId),
|
|
99
|
+
dstChainTokenOutAmount: 'auto',
|
|
100
|
+
dstChainTokenOutRecipient: recipientAddress,
|
|
101
|
+
srcChainOrderAuthorityAddress: senderAddress,
|
|
102
|
+
dstChainOrderAuthorityAddress: recipientAddress,
|
|
103
|
+
senderAddress,
|
|
104
|
+
prependOperatingExpenses: 'false',
|
|
105
|
+
affiliateFeePercent,
|
|
106
|
+
affiliateFeeRecipient,
|
|
107
|
+
}, deps.config);
|
|
108
|
+
if (maybeQuote.isErr()) {
|
|
109
|
+
return handleDebridgeError(maybeQuote.unwrapErr());
|
|
110
|
+
}
|
|
111
|
+
const { data: quote } = maybeQuote.unwrap();
|
|
112
|
+
const buyAmountAfterFeesCryptoBaseUnit = quote.estimation.dstChainTokenOut.recommendedAmount;
|
|
113
|
+
const rate = getInputOutputRate({
|
|
114
|
+
sellAmountCryptoBaseUnit: sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
115
|
+
buyAmountCryptoBaseUnit: buyAmountAfterFeesCryptoBaseUnit,
|
|
116
|
+
sellAsset,
|
|
117
|
+
buyAsset,
|
|
118
|
+
});
|
|
119
|
+
const fixFee = bnOrZero(quote.fixFee).toFixed();
|
|
120
|
+
const buyAmountBeforeFeesCryptoBaseUnit = buyAmountAfterFeesCryptoBaseUnit;
|
|
121
|
+
const allowanceContract = isEvmChainId(sellAsset.chainId) ? quote.tx.to : '';
|
|
122
|
+
const debridgeTransactionMetadata = {
|
|
123
|
+
to: quote.tx.to,
|
|
124
|
+
data: quote.tx.data,
|
|
125
|
+
value: quote.tx.value,
|
|
126
|
+
orderId: quote.orderId,
|
|
127
|
+
gasLimit: quote.estimatedTransactionFee?.details.gasLimit,
|
|
128
|
+
};
|
|
129
|
+
const networkFeeCryptoBaseUnit = await getNetworkFee({
|
|
130
|
+
sellAsset,
|
|
131
|
+
debridgeTransactionMetadata,
|
|
132
|
+
senderAddress,
|
|
133
|
+
deps,
|
|
134
|
+
});
|
|
135
|
+
const protocolFeeAssetCaipChainId = debridgeChainIdToChainId[sellDebridgeChainId.toString()];
|
|
136
|
+
const protocolFeeAssetIdForFees = (() => {
|
|
137
|
+
if (!protocolFeeAssetCaipChainId)
|
|
138
|
+
return undefined;
|
|
139
|
+
return chainIdToFeeAssetId(protocolFeeAssetCaipChainId);
|
|
140
|
+
})();
|
|
141
|
+
const accountNumber = input.accountNumber;
|
|
142
|
+
const step = {
|
|
143
|
+
allowanceContract,
|
|
144
|
+
rate,
|
|
145
|
+
buyAmountBeforeFeesCryptoBaseUnit,
|
|
146
|
+
buyAmountAfterFeesCryptoBaseUnit,
|
|
147
|
+
sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
148
|
+
buyAsset,
|
|
149
|
+
sellAsset,
|
|
150
|
+
accountNumber,
|
|
151
|
+
feeData: {
|
|
152
|
+
networkFeeCryptoBaseUnit,
|
|
153
|
+
protocolFees: protocolFeeAssetIdForFees && bnOrZero(fixFee).gt(0)
|
|
154
|
+
? {
|
|
155
|
+
[protocolFeeAssetIdForFees]: {
|
|
156
|
+
amountCryptoBaseUnit: fixFee,
|
|
157
|
+
asset: getBaseAsset(sellAsset.chainId),
|
|
158
|
+
requiresBalance: true,
|
|
159
|
+
},
|
|
160
|
+
}
|
|
161
|
+
: {},
|
|
162
|
+
},
|
|
163
|
+
source: SwapperName.Debridge,
|
|
164
|
+
estimatedExecutionTimeMs: quote.order.approximateFulfillmentDelay * 1000,
|
|
165
|
+
debridgeTransactionMetadata,
|
|
166
|
+
};
|
|
167
|
+
const baseQuoteOrRate = {
|
|
168
|
+
id: quote.orderId,
|
|
169
|
+
rate,
|
|
170
|
+
swapperName: SwapperName.Debridge,
|
|
171
|
+
affiliateBps,
|
|
172
|
+
slippageTolerancePercentageDecimal: input.slippageTolerancePercentageDecimal,
|
|
173
|
+
};
|
|
174
|
+
if (input.quoteOrRate === 'quote') {
|
|
175
|
+
if (!input.receiveAddress) {
|
|
176
|
+
return Err(makeSwapErrorRight({
|
|
177
|
+
message: 'Receive address is required for quote',
|
|
178
|
+
code: TradeQuoteError.InternalError,
|
|
179
|
+
}));
|
|
180
|
+
}
|
|
181
|
+
const tradeQuote = {
|
|
182
|
+
...baseQuoteOrRate,
|
|
183
|
+
steps: [step],
|
|
184
|
+
receiveAddress: input.receiveAddress,
|
|
185
|
+
quoteOrRate: 'quote',
|
|
186
|
+
};
|
|
187
|
+
return Ok([tradeQuote]);
|
|
188
|
+
}
|
|
189
|
+
const tradeRate = {
|
|
190
|
+
...baseQuoteOrRate,
|
|
191
|
+
steps: [step],
|
|
192
|
+
receiveAddress: recipientAddress,
|
|
193
|
+
quoteOrRate: 'rate',
|
|
194
|
+
};
|
|
195
|
+
return Ok([tradeRate]);
|
|
196
|
+
}
|
|
197
|
+
function handleDebridgeError(error) {
|
|
198
|
+
if (!axios.isAxiosError(error.cause)) {
|
|
199
|
+
return Err(makeSwapErrorRight({
|
|
200
|
+
message: 'Unknown error',
|
|
201
|
+
code: TradeQuoteError.UnknownError,
|
|
202
|
+
}));
|
|
203
|
+
}
|
|
204
|
+
const debridgeError = error.cause?.response?.data;
|
|
205
|
+
if (!isDebridgeError(debridgeError)) {
|
|
206
|
+
return Err(makeSwapErrorRight({
|
|
207
|
+
message: 'Unknown error',
|
|
208
|
+
code: TradeQuoteError.UnknownError,
|
|
209
|
+
}));
|
|
210
|
+
}
|
|
211
|
+
const errorMessage = debridgeError.errorMessage ?? debridgeError.message ?? 'Unknown error';
|
|
212
|
+
return Err(makeSwapErrorRight({
|
|
213
|
+
message: errorMessage,
|
|
214
|
+
code: TradeQuoteError.UnknownError,
|
|
215
|
+
}));
|
|
216
|
+
}
|
|
217
|
+
async function getNetworkFee({ sellAsset, debridgeTransactionMetadata, senderAddress, deps, }) {
|
|
218
|
+
if (!isEvmChainId(sellAsset.chainId))
|
|
219
|
+
return undefined;
|
|
220
|
+
const adapter = deps.assertGetEvmChainAdapter(sellAsset.chainId);
|
|
221
|
+
const { average } = await adapter.getGasFeeData();
|
|
222
|
+
const supportsEIP1559 = 'maxFeePerGas' in average;
|
|
223
|
+
try {
|
|
224
|
+
const feeData = await evm.getFees({
|
|
225
|
+
adapter,
|
|
226
|
+
data: debridgeTransactionMetadata.data,
|
|
227
|
+
to: debridgeTransactionMetadata.to,
|
|
228
|
+
value: debridgeTransactionMetadata.value,
|
|
229
|
+
from: senderAddress,
|
|
230
|
+
supportsEIP1559,
|
|
231
|
+
});
|
|
232
|
+
return feeData.networkFeeCryptoBaseUnit;
|
|
233
|
+
}
|
|
234
|
+
catch {
|
|
235
|
+
const gasLimitFromApi = debridgeTransactionMetadata.gasLimit;
|
|
236
|
+
if (!gasLimitFromApi)
|
|
237
|
+
return undefined;
|
|
238
|
+
return evm.calcNetworkFeeCryptoBaseUnit({
|
|
239
|
+
...average,
|
|
240
|
+
gasLimit: gasLimitFromApi,
|
|
241
|
+
supportsEIP1559,
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
async function getSameChainTrade({ input, deps, sellDebridgeChainId, senderAddress, recipientAddress, affiliateFeePercent, affiliateFeeRecipient, }) {
|
|
246
|
+
const { sellAsset, buyAsset, sellAmountIncludingProtocolFeesCryptoBaseUnit, affiliateBps } = input;
|
|
247
|
+
const slippage = input.slippageTolerancePercentageDecimal
|
|
248
|
+
? bnOrZero(input.slippageTolerancePercentageDecimal).times(100).toFixed()
|
|
249
|
+
: '5';
|
|
250
|
+
const maybeQuote = await fetchDebridgeSingleChainTrade({
|
|
251
|
+
chainId: sellDebridgeChainId,
|
|
252
|
+
tokenIn: getDebridgeAssetAddress(sellAsset.assetId),
|
|
253
|
+
tokenInAmount: sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
254
|
+
tokenOut: getDebridgeAssetAddress(buyAsset.assetId),
|
|
255
|
+
tokenOutRecipient: recipientAddress,
|
|
256
|
+
senderAddress,
|
|
257
|
+
slippage,
|
|
258
|
+
affiliateFeePercent,
|
|
259
|
+
affiliateFeeRecipient,
|
|
260
|
+
}, deps.config);
|
|
261
|
+
if (maybeQuote.isErr()) {
|
|
262
|
+
return handleDebridgeError(maybeQuote.unwrapErr());
|
|
263
|
+
}
|
|
264
|
+
const { data: quote } = maybeQuote.unwrap();
|
|
265
|
+
const buyAmountAfterFeesCryptoBaseUnit = quote.tokenOut.amount;
|
|
266
|
+
const rate = getInputOutputRate({
|
|
267
|
+
sellAmountCryptoBaseUnit: sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
268
|
+
buyAmountCryptoBaseUnit: buyAmountAfterFeesCryptoBaseUnit,
|
|
269
|
+
sellAsset,
|
|
270
|
+
buyAsset,
|
|
271
|
+
});
|
|
272
|
+
const protocolFeeAmount = quote.protocolFee ?? '0';
|
|
273
|
+
const buyAmountBeforeFeesCryptoBaseUnit = (() => {
|
|
274
|
+
if (protocolFeeAmount === '0')
|
|
275
|
+
return buyAmountAfterFeesCryptoBaseUnit;
|
|
276
|
+
return BigAmount.fromBaseUnit({
|
|
277
|
+
value: buyAmountAfterFeesCryptoBaseUnit,
|
|
278
|
+
precision: buyAsset.precision,
|
|
279
|
+
})
|
|
280
|
+
.plus(BigAmount.fromBaseUnit({
|
|
281
|
+
value: protocolFeeAmount,
|
|
282
|
+
precision: buyAsset.precision,
|
|
283
|
+
}))
|
|
284
|
+
.toBaseUnit();
|
|
285
|
+
})();
|
|
286
|
+
const allowanceContract = isEvmChainId(sellAsset.chainId) ? quote.tx.to : '';
|
|
287
|
+
const debridgeTransactionMetadata = {
|
|
288
|
+
to: quote.tx.to,
|
|
289
|
+
data: quote.tx.data,
|
|
290
|
+
value: quote.tx.value,
|
|
291
|
+
gasLimit: quote.estimatedTransactionFee?.details.gasLimit,
|
|
292
|
+
isSameChainSwap: true,
|
|
293
|
+
};
|
|
294
|
+
const networkFeeCryptoBaseUnit = await getNetworkFee({
|
|
295
|
+
sellAsset,
|
|
296
|
+
debridgeTransactionMetadata,
|
|
297
|
+
senderAddress,
|
|
298
|
+
deps,
|
|
299
|
+
});
|
|
300
|
+
const tradeId = uuid();
|
|
301
|
+
const step = {
|
|
302
|
+
allowanceContract,
|
|
303
|
+
rate,
|
|
304
|
+
buyAmountBeforeFeesCryptoBaseUnit,
|
|
305
|
+
buyAmountAfterFeesCryptoBaseUnit,
|
|
306
|
+
sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
307
|
+
buyAsset,
|
|
308
|
+
sellAsset,
|
|
309
|
+
accountNumber: input.accountNumber,
|
|
310
|
+
feeData: {
|
|
311
|
+
networkFeeCryptoBaseUnit,
|
|
312
|
+
protocolFees: protocolFeeAmount !== '0'
|
|
313
|
+
? {
|
|
314
|
+
[buyAsset.assetId]: {
|
|
315
|
+
amountCryptoBaseUnit: protocolFeeAmount,
|
|
316
|
+
asset: {
|
|
317
|
+
symbol: quote.tokenOut.symbol,
|
|
318
|
+
chainId: buyAsset.chainId,
|
|
319
|
+
precision: buyAsset.precision,
|
|
320
|
+
},
|
|
321
|
+
requiresBalance: false,
|
|
322
|
+
},
|
|
323
|
+
}
|
|
324
|
+
: {},
|
|
325
|
+
},
|
|
326
|
+
source: SwapperName.Debridge,
|
|
327
|
+
estimatedExecutionTimeMs: 15_000,
|
|
328
|
+
debridgeTransactionMetadata,
|
|
329
|
+
};
|
|
330
|
+
const baseQuoteOrRate = {
|
|
331
|
+
id: tradeId,
|
|
332
|
+
rate,
|
|
333
|
+
swapperName: SwapperName.Debridge,
|
|
334
|
+
affiliateBps,
|
|
335
|
+
slippageTolerancePercentageDecimal: input.slippageTolerancePercentageDecimal ??
|
|
336
|
+
(quote.slippage ? bnOrZero(quote.slippage).div(100).toString() : undefined),
|
|
337
|
+
};
|
|
338
|
+
if (input.quoteOrRate === 'quote') {
|
|
339
|
+
if (!input.receiveAddress) {
|
|
340
|
+
return Err(makeSwapErrorRight({
|
|
341
|
+
message: 'Receive address is required for quote',
|
|
342
|
+
code: TradeQuoteError.InternalError,
|
|
343
|
+
}));
|
|
344
|
+
}
|
|
345
|
+
const tradeQuote = {
|
|
346
|
+
...baseQuoteOrRate,
|
|
347
|
+
steps: [step],
|
|
348
|
+
receiveAddress: input.receiveAddress,
|
|
349
|
+
quoteOrRate: 'quote',
|
|
350
|
+
};
|
|
351
|
+
return Ok([tradeQuote]);
|
|
352
|
+
}
|
|
353
|
+
const tradeRate = {
|
|
354
|
+
...baseQuoteOrRate,
|
|
355
|
+
steps: [step],
|
|
356
|
+
receiveAddress: recipientAddress,
|
|
357
|
+
quoteOrRate: 'rate',
|
|
358
|
+
};
|
|
359
|
+
return Ok([tradeRate]);
|
|
360
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import type { Asset } from '@shapeshiftoss/types';
|
|
2
|
+
export type DebridgeTradeBaseParams = {
|
|
3
|
+
buyAsset: Asset;
|
|
4
|
+
sellAsset: Asset;
|
|
5
|
+
sellAmountIncludingProtocolFeesCryptoBaseUnit: string;
|
|
6
|
+
affiliateBps: string;
|
|
7
|
+
};
|
|
8
|
+
export type DebridgeTradeInputParams<T extends 'rate' | 'quote'> = DebridgeTradeBaseParams & {
|
|
9
|
+
quoteOrRate: T;
|
|
10
|
+
receiveAddress: T extends 'rate' ? string | undefined : string;
|
|
11
|
+
sendAddress: T extends 'rate' ? undefined : string;
|
|
12
|
+
accountNumber: T extends 'rate' ? undefined : number;
|
|
13
|
+
slippageTolerancePercentageDecimal?: string;
|
|
14
|
+
};
|
|
15
|
+
export type DebridgeTransactionMetadata = {
|
|
16
|
+
to: string;
|
|
17
|
+
data: string;
|
|
18
|
+
value: string;
|
|
19
|
+
gasLimit?: string;
|
|
20
|
+
orderId?: string;
|
|
21
|
+
isSameChainSwap?: boolean;
|
|
22
|
+
};
|
|
23
|
+
export type DebridgeTokenInfo = {
|
|
24
|
+
address: string;
|
|
25
|
+
chainId: number;
|
|
26
|
+
decimals: number;
|
|
27
|
+
name: string;
|
|
28
|
+
symbol: string;
|
|
29
|
+
amount: string;
|
|
30
|
+
approximateOperatingExpense?: string;
|
|
31
|
+
mutatedWithOperatingExpense?: boolean;
|
|
32
|
+
approximateUsdValue?: number;
|
|
33
|
+
maxRefundAmount?: string;
|
|
34
|
+
};
|
|
35
|
+
export type DebridgeCostDetail = {
|
|
36
|
+
type: 'DlnProtocolFee' | 'TakerMargin' | 'EstimatedOperatingExpenses' | 'InputTokenFee' | 'OutputTokenFee';
|
|
37
|
+
payload: {
|
|
38
|
+
feeAmount: string;
|
|
39
|
+
feeBps?: string;
|
|
40
|
+
chain?: string;
|
|
41
|
+
tokenAddress?: string;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
export type DebridgeEstimation = {
|
|
45
|
+
srcChainTokenIn: DebridgeTokenInfo;
|
|
46
|
+
srcChainTokenOut?: DebridgeTokenInfo;
|
|
47
|
+
dstChainTokenOut: DebridgeTokenInfo & {
|
|
48
|
+
recommendedAmount: string;
|
|
49
|
+
};
|
|
50
|
+
costsDetails: DebridgeCostDetail[];
|
|
51
|
+
recommendedSlippage: number;
|
|
52
|
+
};
|
|
53
|
+
export type DebridgeTx = {
|
|
54
|
+
to: string;
|
|
55
|
+
data: string;
|
|
56
|
+
value: string;
|
|
57
|
+
};
|
|
58
|
+
export type DebridgeOrder = {
|
|
59
|
+
approximateFulfillmentDelay: number;
|
|
60
|
+
salt: number;
|
|
61
|
+
metadata: string;
|
|
62
|
+
};
|
|
63
|
+
export type DebridgeCreateTxResponse = {
|
|
64
|
+
estimation: DebridgeEstimation;
|
|
65
|
+
tx: DebridgeTx;
|
|
66
|
+
orderId: string;
|
|
67
|
+
order: DebridgeOrder;
|
|
68
|
+
fixFee: string;
|
|
69
|
+
prependedOperatingExpenseCost?: string;
|
|
70
|
+
estimatedTransactionFee?: DebridgeSingleChainEstimatedTransactionFee;
|
|
71
|
+
};
|
|
72
|
+
export type DebridgeOrderStatus = {
|
|
73
|
+
orderId: string;
|
|
74
|
+
status: 'None' | 'Created' | 'Fulfilled' | 'SentUnlock' | 'ClaimedUnlock' | 'OrderCancelled' | 'SentOrderCancel' | 'ClaimedOrderCancel';
|
|
75
|
+
};
|
|
76
|
+
export type DebridgeHashObject = {
|
|
77
|
+
stringValue: string;
|
|
78
|
+
bytesValue: string;
|
|
79
|
+
bytesArrayValue: string;
|
|
80
|
+
};
|
|
81
|
+
export type DebridgeOrderDetail = {
|
|
82
|
+
orderId: DebridgeHashObject;
|
|
83
|
+
fulfilledDstEventMetadata?: {
|
|
84
|
+
transactionHash?: DebridgeHashObject;
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
export type DebridgeOrderId = {
|
|
88
|
+
bytesValue: string;
|
|
89
|
+
bytesArrayValue: string;
|
|
90
|
+
stringValue: string;
|
|
91
|
+
};
|
|
92
|
+
export type DebridgeOrderIdsResponse = {
|
|
93
|
+
orderIds: DebridgeOrderId[];
|
|
94
|
+
};
|
|
95
|
+
export type DebridgeSingleChainTokenInfo = {
|
|
96
|
+
address: string;
|
|
97
|
+
name: string;
|
|
98
|
+
symbol: string;
|
|
99
|
+
decimals: number;
|
|
100
|
+
amount: string;
|
|
101
|
+
approximateUsdValue?: number;
|
|
102
|
+
};
|
|
103
|
+
export type DebridgeSingleChainTokenOut = DebridgeSingleChainTokenInfo & {
|
|
104
|
+
minAmount: string;
|
|
105
|
+
};
|
|
106
|
+
export type DebridgeSingleChainCostDetail = {
|
|
107
|
+
chain: string;
|
|
108
|
+
tokenIn: string;
|
|
109
|
+
tokenOut: string;
|
|
110
|
+
amountIn: string;
|
|
111
|
+
amountOut: string;
|
|
112
|
+
type: string;
|
|
113
|
+
payload: {
|
|
114
|
+
feeAmount?: string;
|
|
115
|
+
feeBps?: string;
|
|
116
|
+
amountOutBeforeCorrection?: string;
|
|
117
|
+
estimatedVolatilityBps?: string;
|
|
118
|
+
actualFeeAmount?: string;
|
|
119
|
+
actualFeeBps?: string;
|
|
120
|
+
subsidyAmount?: string;
|
|
121
|
+
feeApproximateUsdValue?: string;
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
export type DebridgeSingleChainEstimatedTransactionFee = {
|
|
125
|
+
total: string;
|
|
126
|
+
details: {
|
|
127
|
+
gasLimit: string;
|
|
128
|
+
baseFee?: string;
|
|
129
|
+
maxFeePerGas?: string;
|
|
130
|
+
maxPriorityFeePerGas?: string;
|
|
131
|
+
};
|
|
132
|
+
approximateUsdValue?: number;
|
|
133
|
+
};
|
|
134
|
+
export type DebridgeSingleChainTransactionResponse = {
|
|
135
|
+
tokenIn: DebridgeSingleChainTokenInfo;
|
|
136
|
+
tokenOut: DebridgeSingleChainTokenOut;
|
|
137
|
+
slippage: number;
|
|
138
|
+
recommendedSlippage: number;
|
|
139
|
+
protocolFee?: string;
|
|
140
|
+
costsDetails: DebridgeSingleChainCostDetail[];
|
|
141
|
+
estimatedTransactionFee?: DebridgeSingleChainEstimatedTransactionFee;
|
|
142
|
+
tx: {
|
|
143
|
+
to: string;
|
|
144
|
+
data: string;
|
|
145
|
+
value: string;
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
|
+
export type DebridgeError = {
|
|
149
|
+
errorCode?: number;
|
|
150
|
+
errorId?: string;
|
|
151
|
+
errorMessage?: string;
|
|
152
|
+
statusCode?: number;
|
|
153
|
+
message?: string;
|
|
154
|
+
};
|
|
155
|
+
export declare const isDebridgeError: (error: unknown) => error is DebridgeError;
|
|
@@ -3,4 +3,4 @@ import generatedTradableAssetMap from '../../generated/generatedTradableAssetMap
|
|
|
3
3
|
const mayaPoolIdAssetIdSymbolMap = generatedTradableAssetMap;
|
|
4
4
|
export const assetIdToMayaPoolAssetIdMap = invert(mayaPoolIdAssetIdSymbolMap);
|
|
5
5
|
export const mayaPoolAssetIdToAssetId = (id) => mayaPoolIdAssetIdSymbolMap[id.toUpperCase()];
|
|
6
|
-
export const assetIdToMayaPoolAssetId = ({ assetId }) => assetIdToMayaPoolAssetIdMap[assetId
|
|
6
|
+
export const assetIdToMayaPoolAssetId = ({ assetId }) => assetIdToMayaPoolAssetIdMap[assetId];
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { CHAIN_NAMESPACE, fromAssetId } from '@shapeshiftoss/caip';
|
|
1
|
+
import { CHAIN_NAMESPACE, fromAssetId, nearChainId } from '@shapeshiftoss/caip';
|
|
2
2
|
import { evm } from '@shapeshiftoss/chain-adapters';
|
|
3
|
-
import { bn, bnOrZero, contractAddressOrUndefined, DAO_TREASURY_NEAR, isToken, } from '@shapeshiftoss/utils';
|
|
3
|
+
import { bn, bnOrZero, chainIdToFeeAssetId, contractAddressOrUndefined, DAO_TREASURY_NEAR, isToken, } from '@shapeshiftoss/utils';
|
|
4
4
|
import { Err, Ok } from '@sniptt/monads';
|
|
5
5
|
import { v4 as uuid } from 'uuid';
|
|
6
6
|
import { getDefaultSlippageDecimalPercentageForSwapper } from '../../../constants.js';
|
|
7
7
|
import { SwapperName, TradeQuoteError } from '../../../types.js';
|
|
8
8
|
import { createTradeAmountTooSmallErr, getInputOutputRate, makeSwapErrorRight, } from '../../../utils.js';
|
|
9
|
+
import { buildAffiliateFee } from '../../utils/affiliateFee.js';
|
|
9
10
|
import { isNativeEvmAsset } from '../../utils/helpers/helpers.js';
|
|
10
11
|
import { DEFAULT_QUOTE_DEADLINE_MS, DEFAULT_SLIPPAGE_BPS } from '../constants.js';
|
|
11
12
|
import { QuoteRequest } from '../types.js';
|
|
@@ -275,6 +276,17 @@ export const getTradeQuote = async (input, deps) => {
|
|
|
275
276
|
timeEstimate: quote.timeEstimate,
|
|
276
277
|
deadline: quote.deadline ?? '',
|
|
277
278
|
},
|
|
279
|
+
affiliateFee: buildAffiliateFee({
|
|
280
|
+
strategy: 'fixed_asset',
|
|
281
|
+
affiliateBps,
|
|
282
|
+
sellAsset,
|
|
283
|
+
buyAsset,
|
|
284
|
+
sellAmountCryptoBaseUnit: quote.amountIn,
|
|
285
|
+
buyAmountCryptoBaseUnit: quote.amountOut,
|
|
286
|
+
fixedAssetId: chainIdToFeeAssetId(nearChainId),
|
|
287
|
+
fixedAsset: deps.assetsById[chainIdToFeeAssetId(nearChainId)],
|
|
288
|
+
isEstimate: true,
|
|
289
|
+
}),
|
|
278
290
|
},
|
|
279
291
|
],
|
|
280
292
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { CHAIN_NAMESPACE, fromAssetId, monadChainId } from '@shapeshiftoss/caip';
|
|
1
|
+
import { CHAIN_NAMESPACE, fromAssetId, monadChainId, nearChainId } from '@shapeshiftoss/caip';
|
|
2
2
|
import { evm } from '@shapeshiftoss/chain-adapters';
|
|
3
|
-
import { bn, bnOrZero, contractAddressOrUndefined, DAO_TREASURY_NEAR, isToken, } from '@shapeshiftoss/utils';
|
|
3
|
+
import { bn, bnOrZero, chainIdToFeeAssetId, contractAddressOrUndefined, DAO_TREASURY_NEAR, isToken, } from '@shapeshiftoss/utils';
|
|
4
4
|
import { Err, Ok } from '@sniptt/monads';
|
|
5
5
|
import { v4 as uuid } from 'uuid';
|
|
6
6
|
import { getAddress } from 'viem';
|
|
@@ -8,6 +8,7 @@ import { getDefaultSlippageDecimalPercentageForSwapper } from '../../../constant
|
|
|
8
8
|
import { SwapperName, TradeQuoteError } from '../../../types.js';
|
|
9
9
|
import { createTradeAmountTooSmallErr, getInputOutputRate, makeSwapErrorRight, } from '../../../utils.js';
|
|
10
10
|
import { simulateWithStateOverrides } from '../../../utils/tenderly/index.js';
|
|
11
|
+
import { buildAffiliateFee } from '../../utils/affiliateFee.js';
|
|
11
12
|
import { isNativeEvmAsset } from '../../utils/helpers/helpers.js';
|
|
12
13
|
import { DEFAULT_QUOTE_DEADLINE_MS, DEFAULT_SLIPPAGE_BPS } from '../constants.js';
|
|
13
14
|
import { QuoteRequest } from '../types.js';
|
|
@@ -334,6 +335,17 @@ export const getTradeRate = async (input, deps) => {
|
|
|
334
335
|
sellAsset,
|
|
335
336
|
source: SwapperName.NearIntents,
|
|
336
337
|
estimatedExecutionTimeMs: quote.timeEstimate ? quote.timeEstimate * 1000 : undefined,
|
|
338
|
+
affiliateFee: buildAffiliateFee({
|
|
339
|
+
strategy: 'fixed_asset',
|
|
340
|
+
affiliateBps,
|
|
341
|
+
sellAsset,
|
|
342
|
+
buyAsset,
|
|
343
|
+
sellAmountCryptoBaseUnit: quote.amountIn,
|
|
344
|
+
buyAmountCryptoBaseUnit: quote.amountOut,
|
|
345
|
+
fixedAssetId: chainIdToFeeAssetId(nearChainId),
|
|
346
|
+
fixedAsset: deps.assetsById[chainIdToFeeAssetId(nearChainId)],
|
|
347
|
+
isEstimate: true,
|
|
348
|
+
}),
|
|
337
349
|
},
|
|
338
350
|
],
|
|
339
351
|
};
|
|
@@ -6,6 +6,7 @@ import { zeroAddress } from 'viem';
|
|
|
6
6
|
import { getDefaultSlippageDecimalPercentageForSwapper } from '../../../index.js';
|
|
7
7
|
import { SwapperName, TradeQuoteError } from '../../../types.js';
|
|
8
8
|
import { getInputOutputRate, makeSwapErrorRight } from '../../../utils.js';
|
|
9
|
+
import { buildAffiliateFee } from '../../utils/affiliateFee.js';
|
|
9
10
|
import { getTreasuryAddressFromChainId, isNativeEvmAsset } from '../../utils/helpers/helpers.js';
|
|
10
11
|
import { chainIdToPortalsNetwork } from '../constants.js';
|
|
11
12
|
import { fetchPortalsTradeOrder, PortalsError } from '../utils/fetchPortalsTradeOrder.js';
|
|
@@ -201,6 +202,15 @@ export async function getPortalsTradeQuote(input, assertGetEvmChainAdapter, swap
|
|
|
201
202
|
steps: portalsTradeOrderResponse.context.steps,
|
|
202
203
|
route: portalsTradeOrderResponse.context.route,
|
|
203
204
|
},
|
|
205
|
+
affiliateFee: buildAffiliateFee({
|
|
206
|
+
strategy: 'buy_asset',
|
|
207
|
+
affiliateBps,
|
|
208
|
+
sellAsset,
|
|
209
|
+
buyAsset,
|
|
210
|
+
sellAmountCryptoBaseUnit: input.sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
211
|
+
buyAmountCryptoBaseUnit: buyAmountAfterFeesCryptoBaseUnit,
|
|
212
|
+
isEstimate: true,
|
|
213
|
+
}),
|
|
204
214
|
},
|
|
205
215
|
],
|
|
206
216
|
};
|
|
@@ -1,38 +1,33 @@
|
|
|
1
|
-
import { arbitrumChainId, avalancheChainId, baseChainId, berachainChainId, blastChainId, bobChainId, bscChainId, btcChainId, celoChainId, cronosChainId, ethChainId, flowEvmChainId, gnosisChainId, hemiChainId, hyperEvmChainId, inkChainId, katanaChainId, lineaChainId, mantleChainId, megaethChainId, modeChainId, monadChainId, optimismChainId, plasmaChainId, plumeChainId, polygonChainId, scrollChainId, solanaChainId, soneiumChainId, sonicChainId, storyChainId, unichainChainId, worldChainChainId, zkSyncEraChainId, } from '@shapeshiftoss/caip';
|
|
2
|
-
import { flowEvmChain } from '@shapeshiftoss/contracts';
|
|
1
|
+
import { abstractChainId, arbitrumChainId, avalancheChainId, baseChainId, berachainChainId, blastChainId, bobChainId, bscChainId, btcChainId, celoChainId, cronosChainId, ethChainId, etherealChainId, flowEvmChainId, gnosisChainId, hemiChainId, hyperEvmChainId, inkChainId, katanaChainId, lineaChainId, mantleChainId, megaethChainId, modeChainId, monadChainId, optimismChainId, plasmaChainId, plumeChainId, polygonChainId, scrollChainId, seiChainId, solanaChainId, soneiumChainId, sonicChainId, storyChainId, tronChainId, unichainChainId, worldChainChainId, zkSyncEraChainId, } from '@shapeshiftoss/caip';
|
|
3
2
|
import invert from 'lodash/invert';
|
|
4
3
|
import { zeroAddress } from 'viem';
|
|
5
|
-
import { arbitrum, avalanche, base, berachain, blast, bob, bsc, celo, cronos, gnosis, hemi, hyperEvm, ink, katana, linea, mainnet as ethereum, mantle, mode, monad, optimism, plasma, plumeMainnet, polygon, scroll, soneium, sonic, story, unichain, worldchain, zksync, } from 'viem/chains';
|
|
4
|
+
import { arbitrum, avalanche, base, berachain, blast, bob, bsc, celo, cronos, flowMainnet, gnosis, hemi, hyperEvm, ink, katana, linea, mainnet as ethereum, mantle, mode, monad, optimism, plasma, plumeMainnet, polygon, scroll, sei, soneium, sonic, story, unichain, worldchain, zksync, } from 'viem/chains';
|
|
6
5
|
import { TradeQuoteError } from '../../types.js';
|
|
7
6
|
import { RelayErrorCode } from './utils/types.js';
|
|
7
|
+
// https://docs.relay.link/resources/supported-chains
|
|
8
8
|
export const chainIdToRelayChainId = {
|
|
9
|
-
// https://docs.relay.link/resources/supported-chains
|
|
10
9
|
[btcChainId]: 8253038,
|
|
11
10
|
[ethChainId]: ethereum.id,
|
|
12
11
|
[arbitrumChainId]: arbitrum.id,
|
|
13
12
|
[baseChainId]: base.id,
|
|
14
13
|
[optimismChainId]: optimism.id,
|
|
15
14
|
[polygonChainId]: polygon.id,
|
|
16
|
-
// https://docs.relay.link/resources/supported-chains
|
|
17
15
|
[solanaChainId]: 792703809,
|
|
18
16
|
[gnosisChainId]: gnosis.id,
|
|
19
17
|
[avalancheChainId]: avalanche.id,
|
|
20
18
|
[bscChainId]: bsc.id,
|
|
21
|
-
|
|
22
|
-
// and the Relay indexer notification is never sent for non-EVM chains. This causes deposits to be
|
|
23
|
-
// untracked by Relay, resulting in stuck/lost funds. Re-enable once the Tron transaction building
|
|
24
|
-
// is verified to use the Relay quote calldata (depositErc20) correctly.
|
|
25
|
-
// [tronChainId]: 728126428,
|
|
19
|
+
[tronChainId]: 728126428,
|
|
26
20
|
[monadChainId]: monad.id,
|
|
27
21
|
[hyperEvmChainId]: hyperEvm.id,
|
|
28
22
|
[mantleChainId]: mantle.id,
|
|
29
23
|
[inkChainId]: ink.id,
|
|
30
24
|
[megaethChainId]: 4326,
|
|
31
25
|
[plasmaChainId]: plasma.id,
|
|
32
|
-
[plumeChainId]: plumeMainnet.id,
|
|
33
26
|
[katanaChainId]: katana.id,
|
|
34
|
-
[
|
|
27
|
+
[etherealChainId]: 5064014,
|
|
35
28
|
[celoChainId]: celo.id,
|
|
29
|
+
[flowEvmChainId]: flowMainnet.id,
|
|
30
|
+
[plumeChainId]: plumeMainnet.id,
|
|
36
31
|
[storyChainId]: story.id,
|
|
37
32
|
[zkSyncEraChainId]: zksync.id,
|
|
38
33
|
[blastChainId]: blast.id,
|
|
@@ -47,6 +42,8 @@ export const chainIdToRelayChainId = {
|
|
|
47
42
|
[bobChainId]: bob.id,
|
|
48
43
|
[modeChainId]: mode.id,
|
|
49
44
|
[soneiumChainId]: soneium.id,
|
|
45
|
+
[seiChainId]: sei.id,
|
|
46
|
+
[abstractChainId]: 2741,
|
|
50
47
|
};
|
|
51
48
|
export var RelayStatusMessage;
|
|
52
49
|
(function (RelayStatusMessage) {
|