@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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { evm
|
|
1
|
+
import { evm } from '@shapeshiftoss/chain-adapters';
|
|
2
2
|
import { TxStatus } from '@shapeshiftoss/unchained-client';
|
|
3
3
|
import BigNumber from 'bignumber.js';
|
|
4
4
|
import { getSolanaTransactionFees } from '../../solana-utils/getSolanaTransactionFees.js';
|
|
@@ -143,7 +143,7 @@ export const relayApi = {
|
|
|
143
143
|
}
|
|
144
144
|
if (swap.metadata.relayTransactionMetadata &&
|
|
145
145
|
!txIndexingMap.has(swap.id) &&
|
|
146
|
-
|
|
146
|
+
chainIdToRelayChainId[chainId] !== undefined) {
|
|
147
147
|
const relayTxParam = {
|
|
148
148
|
...swap.metadata.relayTransactionMetadata,
|
|
149
149
|
txHash,
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { btcChainId, fromChainId, monadChainId, solanaChainId, tronChainId, } from '@shapeshiftoss/caip';
|
|
1
|
+
import { baseChainId, btcChainId, fromChainId, monadChainId, solanaChainId, tronChainId, } from '@shapeshiftoss/caip';
|
|
2
2
|
import { evm, isEvmChainId } from '@shapeshiftoss/chain-adapters';
|
|
3
|
-
import { bnOrZero, convertBasisPointsToPercentage, convertDecimalPercentageToBasisPoints, convertPrecision, DAO_TREASURY_BASE, } from '@shapeshiftoss/utils';
|
|
3
|
+
import { bnOrZero, chainIdToFeeAssetId, convertBasisPointsToPercentage, convertDecimalPercentageToBasisPoints, convertPrecision, DAO_TREASURY_BASE, isToken, } from '@shapeshiftoss/utils';
|
|
4
4
|
import { Err, Ok } from '@sniptt/monads';
|
|
5
|
-
import { PublicKey } from '@solana/web3.js';
|
|
5
|
+
import { AddressLookupTableAccount, MessageV0, PublicKey, VersionedTransaction, } from '@solana/web3.js';
|
|
6
6
|
import axios from 'axios';
|
|
7
7
|
import { getAddress, zeroAddress } from 'viem';
|
|
8
8
|
import { MixPanelEvent, SwapperName, TradeQuoteError } from '../../../types.js';
|
|
9
9
|
import { 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 { MAXIMUM_SUPPORTED_RELAY_STEPS, relayErrorCodeToTradeQuoteError } from '../constant.js';
|
|
13
14
|
import { getRelayAssetAddress } from '../utils/getRelayAssetAddress.js';
|
|
@@ -390,7 +391,7 @@ export async function getTrade({ input, deps, relayChainMap, }) {
|
|
|
390
391
|
// Fallback to Relay's gas amount
|
|
391
392
|
return quote.fees.gas.amount;
|
|
392
393
|
})();
|
|
393
|
-
const steps = swapSteps.map((quoteStep) => {
|
|
394
|
+
const steps = await Promise.all(swapSteps.map(async (quoteStep) => {
|
|
394
395
|
const selectedItem = quoteStep.items?.[0];
|
|
395
396
|
if (!selectedItem)
|
|
396
397
|
throw new Error('Relay quote step contains no items');
|
|
@@ -400,7 +401,7 @@ export async function getTrade({ input, deps, relayChainMap, }) {
|
|
|
400
401
|
.plus(relayerFeesBuyAssetCryptoBaseUnit)
|
|
401
402
|
.plus(appFeesBaseUnit)
|
|
402
403
|
.toFixed();
|
|
403
|
-
const { allowanceContract, relayTransactionMetadata, solanaTransactionMetadata } = (() => {
|
|
404
|
+
const { allowanceContract, relayTransactionMetadata, solanaTransactionMetadata } = await (async () => {
|
|
404
405
|
if (!selectedItem.data)
|
|
405
406
|
throw new Error('Relay quote step contains no data');
|
|
406
407
|
if (isRelayQuoteUtxoItemData(selectedItem.data)) {
|
|
@@ -439,11 +440,38 @@ export async function getTrade({ input, deps, relayChainMap, }) {
|
|
|
439
440
|
};
|
|
440
441
|
}
|
|
441
442
|
if (isRelayQuoteSolanaItemData(selectedItem.data)) {
|
|
443
|
+
const solanaInstructions = selectedItem.data?.instructions?.map(convertSolanaInstruction);
|
|
444
|
+
const addressLookupTableAddresses = selectedItem.data?.addressLookupTableAddresses;
|
|
445
|
+
// Build a trial VersionedTransaction to check if it exceeds the 1232-byte Solana tx size limit
|
|
446
|
+
const isOversized = await (async () => {
|
|
447
|
+
if (!solanaInstructions?.length || !sendAddress)
|
|
448
|
+
return false;
|
|
449
|
+
try {
|
|
450
|
+
const adapter = deps.assertGetSolanaChainAdapter(sellAsset.chainId);
|
|
451
|
+
const lookupTableInfos = await adapter.getAddressLookupTableAccounts(addressLookupTableAddresses);
|
|
452
|
+
const lookupTableAccounts = lookupTableInfos.map(info => new AddressLookupTableAccount({
|
|
453
|
+
key: new PublicKey(info.key),
|
|
454
|
+
state: AddressLookupTableAccount.deserialize(new Uint8Array(info.data)),
|
|
455
|
+
}));
|
|
456
|
+
const messageV0 = MessageV0.compile({
|
|
457
|
+
payerKey: new PublicKey(sendAddress),
|
|
458
|
+
instructions: solanaInstructions,
|
|
459
|
+
recentBlockhash: PublicKey.default.toString(),
|
|
460
|
+
addressLookupTableAccounts: lookupTableAccounts,
|
|
461
|
+
});
|
|
462
|
+
const txBytes = new VersionedTransaction(messageV0).serialize();
|
|
463
|
+
return txBytes.length > 1232;
|
|
464
|
+
}
|
|
465
|
+
catch {
|
|
466
|
+
return false;
|
|
467
|
+
}
|
|
468
|
+
})();
|
|
442
469
|
return {
|
|
443
470
|
allowanceContract: '',
|
|
444
471
|
solanaTransactionMetadata: {
|
|
445
|
-
addressLookupTableAddresses
|
|
446
|
-
instructions:
|
|
472
|
+
addressLookupTableAddresses,
|
|
473
|
+
instructions: solanaInstructions,
|
|
474
|
+
isOversized,
|
|
447
475
|
},
|
|
448
476
|
relayTransactionMetadata: {
|
|
449
477
|
relayId: quote.steps[0].requestId,
|
|
@@ -452,13 +480,23 @@ export async function getTrade({ input, deps, relayChainMap, }) {
|
|
|
452
480
|
};
|
|
453
481
|
}
|
|
454
482
|
if (isRelayQuoteTronItemData(selectedItem.data)) {
|
|
483
|
+
const contractAddress = selectedItem.data.parameter?.contract_address;
|
|
484
|
+
const callData = selectedItem.data.parameter?.data;
|
|
485
|
+
const isTronToken = isToken(sellAsset.assetId);
|
|
486
|
+
if (isTronToken && !contractAddress) {
|
|
487
|
+
throw new Error('Missing Relay Tron contract address');
|
|
488
|
+
}
|
|
489
|
+
if (isTronToken && !callData) {
|
|
490
|
+
throw new Error('Missing Relay Tron transaction data');
|
|
491
|
+
}
|
|
455
492
|
return {
|
|
456
|
-
allowanceContract: '',
|
|
493
|
+
allowanceContract: contractAddress ?? '',
|
|
457
494
|
solanaTransactionMetadata: undefined,
|
|
458
495
|
relayTransactionMetadata: {
|
|
459
496
|
relayId: quote.steps[0].requestId,
|
|
460
497
|
orderId,
|
|
461
|
-
to:
|
|
498
|
+
to: contractAddress,
|
|
499
|
+
data: callData,
|
|
462
500
|
},
|
|
463
501
|
};
|
|
464
502
|
}
|
|
@@ -488,8 +526,19 @@ export async function getTrade({ input, deps, relayChainMap, }) {
|
|
|
488
526
|
estimatedExecutionTimeMs: timeEstimate * 1000,
|
|
489
527
|
solanaTransactionMetadata,
|
|
490
528
|
relayTransactionMetadata,
|
|
529
|
+
affiliateFee: buildAffiliateFee({
|
|
530
|
+
strategy: 'fixed_asset',
|
|
531
|
+
affiliateBps,
|
|
532
|
+
sellAsset,
|
|
533
|
+
buyAsset,
|
|
534
|
+
sellAmountCryptoBaseUnit: sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
535
|
+
buyAmountCryptoBaseUnit: buyAmountAfterFeesCryptoBaseUnit,
|
|
536
|
+
fixedAssetId: chainIdToFeeAssetId(baseChainId),
|
|
537
|
+
fixedAsset: deps.assetsById[chainIdToFeeAssetId(baseChainId)],
|
|
538
|
+
isEstimate: true,
|
|
539
|
+
}),
|
|
491
540
|
};
|
|
492
|
-
});
|
|
541
|
+
}));
|
|
493
542
|
const baseQuoteOrRate = {
|
|
494
543
|
id: quote.steps[0].requestId,
|
|
495
544
|
rate,
|
|
@@ -109,11 +109,6 @@ export const relayTokenToAssetId = (relayToken) => {
|
|
|
109
109
|
assetReference: ASSET_REFERENCE.Plasma,
|
|
110
110
|
assetNamespace: ASSET_NAMESPACE.slip44,
|
|
111
111
|
};
|
|
112
|
-
case CHAIN_REFERENCE.PlumeMainnet:
|
|
113
|
-
return {
|
|
114
|
-
assetReference: ASSET_REFERENCE.Plume,
|
|
115
|
-
assetNamespace: ASSET_NAMESPACE.slip44,
|
|
116
|
-
};
|
|
117
112
|
case CHAIN_REFERENCE.MantleMainnet:
|
|
118
113
|
return {
|
|
119
114
|
assetReference: ASSET_REFERENCE.Mantle,
|
|
@@ -139,9 +134,9 @@ export const relayTokenToAssetId = (relayToken) => {
|
|
|
139
134
|
assetReference: ASSET_REFERENCE.Katana,
|
|
140
135
|
assetNamespace: ASSET_NAMESPACE.slip44,
|
|
141
136
|
};
|
|
142
|
-
case CHAIN_REFERENCE.
|
|
137
|
+
case CHAIN_REFERENCE.EtherealMainnet:
|
|
143
138
|
return {
|
|
144
|
-
assetReference: ASSET_REFERENCE.
|
|
139
|
+
assetReference: ASSET_REFERENCE.Ethereal,
|
|
145
140
|
assetNamespace: ASSET_NAMESPACE.slip44,
|
|
146
141
|
};
|
|
147
142
|
case CHAIN_REFERENCE.CeloMainnet:
|
|
@@ -149,6 +144,16 @@ export const relayTokenToAssetId = (relayToken) => {
|
|
|
149
144
|
assetReference: ASSET_REFERENCE.Celo,
|
|
150
145
|
assetNamespace: ASSET_NAMESPACE.slip44,
|
|
151
146
|
};
|
|
147
|
+
case CHAIN_REFERENCE.FlowEvmMainnet:
|
|
148
|
+
return {
|
|
149
|
+
assetReference: ASSET_REFERENCE.FlowEvm,
|
|
150
|
+
assetNamespace: ASSET_NAMESPACE.slip44,
|
|
151
|
+
};
|
|
152
|
+
case CHAIN_REFERENCE.PlumeMainnet:
|
|
153
|
+
return {
|
|
154
|
+
assetReference: ASSET_REFERENCE.Plume,
|
|
155
|
+
assetNamespace: ASSET_NAMESPACE.slip44,
|
|
156
|
+
};
|
|
152
157
|
case CHAIN_REFERENCE.StoryMainnet:
|
|
153
158
|
return {
|
|
154
159
|
assetReference: ASSET_REFERENCE.Story,
|
|
@@ -214,6 +219,16 @@ export const relayTokenToAssetId = (relayToken) => {
|
|
|
214
219
|
assetReference: ASSET_REFERENCE.Soneium,
|
|
215
220
|
assetNamespace: ASSET_NAMESPACE.slip44,
|
|
216
221
|
};
|
|
222
|
+
case CHAIN_REFERENCE.SeiMainnet:
|
|
223
|
+
return {
|
|
224
|
+
assetReference: ASSET_REFERENCE.Sei,
|
|
225
|
+
assetNamespace: ASSET_NAMESPACE.slip44,
|
|
226
|
+
};
|
|
227
|
+
case CHAIN_REFERENCE.AbstractMainnet:
|
|
228
|
+
return {
|
|
229
|
+
assetReference: ASSET_REFERENCE.Abstract,
|
|
230
|
+
assetNamespace: ASSET_NAMESPACE.slip44,
|
|
231
|
+
};
|
|
217
232
|
default:
|
|
218
233
|
throw Error(`chainId '${relayToken.chainId}' not supported`);
|
|
219
234
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { tonChainId } from '@shapeshiftoss/caip';
|
|
1
2
|
import { Err, Ok } from '@sniptt/monads';
|
|
2
3
|
import { SettlementMethod } from '@ston-fi/omniston-sdk';
|
|
3
4
|
import { SwapperName, TradeQuoteError } from '../../../types.js';
|
|
4
5
|
import { makeSwapErrorRight } from '../../../utils.js';
|
|
6
|
+
import { buildAffiliateFee } from '../../utils/affiliateFee.js';
|
|
5
7
|
import { getTreasuryAddressFromChainId } from '../../utils/helpers/helpers.js';
|
|
6
8
|
import { STONFI_DEFAULT_SLIPPAGE_BPS, STONFI_QUOTE_TIMEOUT_MS } from '../utils/constants.js';
|
|
7
9
|
import { affiliateBpsToNumber, calculateRate, slippageDecimalToBps, tonAddressToOmnistonAddress, validateTonAssets, waitForQuote, } from '../utils/helpers.js';
|
|
@@ -36,7 +38,7 @@ export const getTradeQuote = async (input) => {
|
|
|
36
38
|
try {
|
|
37
39
|
const slippageBps = slippageDecimalToBps(slippageTolerancePercentageDecimal, STONFI_DEFAULT_SLIPPAGE_BPS);
|
|
38
40
|
const referrerFeeBps = affiliateBpsToNumber(affiliateBps);
|
|
39
|
-
const tonTreasuryAddress = getTreasuryAddressFromChainId(
|
|
41
|
+
const tonTreasuryAddress = getTreasuryAddressFromChainId(tonChainId);
|
|
40
42
|
const referrerAddress = tonAddressToOmnistonAddress(tonTreasuryAddress);
|
|
41
43
|
const quoteResult = await waitForQuote(omniston, {
|
|
42
44
|
settlementMethods: [SettlementMethod.SETTLEMENT_METHOD_SWAP],
|
|
@@ -100,6 +102,15 @@ export const getTradeQuote = async (input) => {
|
|
|
100
102
|
allowanceContract: '0x0',
|
|
101
103
|
estimatedExecutionTimeMs: 30000,
|
|
102
104
|
stonfiSpecific: buildStonfiSpecific(quote, bidAssetAddress, askAssetAddress),
|
|
105
|
+
affiliateFee: buildAffiliateFee({
|
|
106
|
+
strategy: 'buy_asset',
|
|
107
|
+
affiliateBps,
|
|
108
|
+
sellAsset,
|
|
109
|
+
buyAsset,
|
|
110
|
+
sellAmountCryptoBaseUnit: sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
111
|
+
buyAmountCryptoBaseUnit,
|
|
112
|
+
isEstimate: true,
|
|
113
|
+
}),
|
|
103
114
|
},
|
|
104
115
|
],
|
|
105
116
|
};
|
|
@@ -2,6 +2,7 @@ import { Err, Ok } from '@sniptt/monads';
|
|
|
2
2
|
import { SettlementMethod } from '@ston-fi/omniston-sdk';
|
|
3
3
|
import { SwapperName, TradeQuoteError } from '../../../types.js';
|
|
4
4
|
import { makeSwapErrorRight } from '../../../utils.js';
|
|
5
|
+
import { buildAffiliateFee } from '../../utils/affiliateFee.js';
|
|
5
6
|
import { getTreasuryAddressFromChainId } from '../../utils/helpers/helpers.js';
|
|
6
7
|
import { STONFI_DEFAULT_SLIPPAGE_BPS, STONFI_QUOTE_TIMEOUT_MS } from '../utils/constants.js';
|
|
7
8
|
import { affiliateBpsToNumber, calculateRate, slippageDecimalToBps, tonAddressToOmnistonAddress, validateTonAssets, waitForQuote, } from '../utils/helpers.js';
|
|
@@ -86,6 +87,15 @@ export const getTradeRate = async (input) => {
|
|
|
86
87
|
allowanceContract: '0x0000000000000000000000000000000000000000',
|
|
87
88
|
estimatedExecutionTimeMs: 30000,
|
|
88
89
|
stonfiSpecific: buildStonfiSpecific(quote, bidAssetAddress, askAssetAddress),
|
|
90
|
+
affiliateFee: buildAffiliateFee({
|
|
91
|
+
strategy: 'buy_asset',
|
|
92
|
+
affiliateBps,
|
|
93
|
+
sellAsset,
|
|
94
|
+
buyAsset,
|
|
95
|
+
sellAmountCryptoBaseUnit: sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
96
|
+
buyAmountCryptoBaseUnit,
|
|
97
|
+
isEstimate: true,
|
|
98
|
+
}),
|
|
89
99
|
},
|
|
90
100
|
],
|
|
91
101
|
};
|
|
@@ -4,6 +4,7 @@ import { Err, Ok } from '@sniptt/monads';
|
|
|
4
4
|
import { TronWeb } from 'tronweb';
|
|
5
5
|
import { SwapperName, TradeQuoteError } from '../../../types.js';
|
|
6
6
|
import { getInputOutputRate, makeSwapErrorRight } from '../../../utils.js';
|
|
7
|
+
import { buildAffiliateFee } from '../../utils/affiliateFee.js';
|
|
7
8
|
import { DEFAULT_SLIPPAGE_PERCENTAGE, SUNIO_SMART_ROUTER_CONTRACT } from './constants.js';
|
|
8
9
|
import { fetchSunioQuote } from './fetchFromSunio.js';
|
|
9
10
|
import { isSupportedChainId } from './helpers/helpers.js';
|
|
@@ -184,6 +185,15 @@ export async function getQuoteOrRate(input, deps) {
|
|
|
184
185
|
route: bestRoute,
|
|
185
186
|
},
|
|
186
187
|
}),
|
|
188
|
+
affiliateFee: buildAffiliateFee({
|
|
189
|
+
strategy: 'buy_asset',
|
|
190
|
+
affiliateBps,
|
|
191
|
+
sellAsset,
|
|
192
|
+
buyAsset,
|
|
193
|
+
sellAmountCryptoBaseUnit: sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
194
|
+
buyAmountCryptoBaseUnit: buyAmountAfterFeesCryptoBaseUnit,
|
|
195
|
+
isEstimate: true,
|
|
196
|
+
}),
|
|
187
197
|
},
|
|
188
198
|
],
|
|
189
199
|
swapperName: SwapperName.Sunio,
|
|
@@ -7,6 +7,9 @@ export const thorchainSwapper = {
|
|
|
7
7
|
executeUtxoTransaction: (txToSign, { signAndBroadcastTransaction }) => {
|
|
8
8
|
return signAndBroadcastTransaction(txToSign);
|
|
9
9
|
},
|
|
10
|
+
executeSolanaTransaction: (txToSign, { signAndBroadcastTransaction }) => {
|
|
11
|
+
return signAndBroadcastTransaction(txToSign);
|
|
12
|
+
},
|
|
10
13
|
executeTronTransaction: (txToSign, { signAndBroadcastTransaction }) => {
|
|
11
14
|
return signAndBroadcastTransaction(txToSign);
|
|
12
15
|
},
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { cosmosAssetId, rujiAssetId, tcyAssetId, thorchainAssetId } from '@shapeshiftoss/caip';
|
|
2
|
-
import { checkTradeStatus, cosmossdk, evm, getInboundAddressDataForChain, tron, utxo, } from '../../thorchain-utils/index.js';
|
|
2
|
+
import { checkTradeStatus, cosmossdk, evm, getInboundAddressDataForChain, solana, tron, utxo, } from '../../thorchain-utils/index.js';
|
|
3
3
|
import { SwapperName } from '../../types.js';
|
|
4
4
|
import { getExecutableTradeStep, isExecutableTradeQuote } from '../../utils.js';
|
|
5
5
|
import { getTradeQuote } from './getTradeQuote/getTradeQuote.js';
|
|
@@ -12,6 +12,8 @@ export const thorchainApi = {
|
|
|
12
12
|
getEvmTransactionFees: input => evm.getEvmTransactionFees(input, swapperName),
|
|
13
13
|
getUnsignedUtxoTransaction: input => utxo.getUnsignedUtxoTransaction(input, swapperName),
|
|
14
14
|
getUtxoTransactionFees: input => utxo.getUtxoTransactionFees(input, swapperName),
|
|
15
|
+
getUnsignedSolanaTransaction: input => solana.getUnsignedSolanaTransaction(input, swapperName),
|
|
16
|
+
getSolanaTransactionFees: input => solana.getSolanaTransactionFees(input, swapperName),
|
|
15
17
|
getUnsignedTronTransaction: input => tron.getUnsignedTronTransaction(input, swapperName),
|
|
16
18
|
getTronTransactionFees: input => tron.getTronTransactionFees(input, swapperName),
|
|
17
19
|
getUnsignedCosmosSdkTransaction: async ({ tradeQuote, stepIndex, from, config, assertGetCosmosSdkChainAdapter, }) => {
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"ETH.YFI-0X0BC529C00C6401AEF6D220BE8C6EA1667F6AD93E": "eip155:1/erc20:0x0bc529c00c6401aef6d220be8c6ea1667f6ad93e",
|
|
38
38
|
"GAIA.ATOM": "cosmos:cosmoshub-4/slip44:118",
|
|
39
39
|
"LTC.LTC": "bip122:12a765e31ffd4059bada1e25190f6e98/slip44:2",
|
|
40
|
+
"SOL.SOL": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/slip44:501",
|
|
40
41
|
"THOR.RUJI": "cosmos:thorchain-1/slip44:ruji",
|
|
41
42
|
"THOR.TCY": "cosmos:thorchain-1/slip44:tcy",
|
|
42
43
|
"TRON.TRX": "tron:0x2b6653dc/slip44:195",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AssetId } from '@shapeshiftoss/caip';
|
|
2
|
-
export declare const assetIdToThorPoolAssetIdMap:
|
|
2
|
+
export declare const assetIdToThorPoolAssetIdMap: Record<string, string>;
|
|
3
3
|
export declare const thorPoolAssetIdToAssetId: (id: string) => AssetId | undefined;
|
|
4
4
|
export declare const assetIdToThorPoolAssetId: ({ assetId }: {
|
|
5
5
|
assetId: AssetId;
|
|
@@ -2,5 +2,6 @@ import invert from 'lodash/invert';
|
|
|
2
2
|
import generatedTradableAssetMap from '../../generated/generatedTradableAssetMap.json';
|
|
3
3
|
const thorPoolIdAssetIdSymbolMap = generatedTradableAssetMap;
|
|
4
4
|
export const assetIdToThorPoolAssetIdMap = invert(thorPoolIdAssetIdSymbolMap);
|
|
5
|
+
const assetIdToThorPoolAssetIdMapLower = Object.fromEntries(Object.entries(assetIdToThorPoolAssetIdMap).map(([k, v]) => [k.toLowerCase(), v]));
|
|
5
6
|
export const thorPoolAssetIdToAssetId = (id) => thorPoolIdAssetIdSymbolMap[id.toUpperCase()];
|
|
6
|
-
export const assetIdToThorPoolAssetId = ({ assetId }) =>
|
|
7
|
+
export const assetIdToThorPoolAssetId = ({ assetId }) => assetIdToThorPoolAssetIdMapLower[assetId.toLowerCase()];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { btcAssetId, ethAssetId } from '@shapeshiftoss/caip';
|
|
1
|
+
import { btcAssetId, ethAssetId, solAssetId } from '@shapeshiftoss/caip';
|
|
2
2
|
import { describe, expect, it } from 'vitest';
|
|
3
3
|
import { assetIdToThorPoolAssetId, thorPoolAssetIdToAssetId } from './poolAssetHelpers.js';
|
|
4
4
|
describe('poolAssetHelpers', () => {
|
|
@@ -16,6 +16,10 @@ describe('poolAssetHelpers', () => {
|
|
|
16
16
|
const result = thorPoolAssetIdToAssetId('ETH.USDC-0XA0B86991C6218B36C1D19D4A2E9EB0CE3606EB48');
|
|
17
17
|
expect(result).toEqual(usdcAssetId);
|
|
18
18
|
});
|
|
19
|
+
it('returns Solana assetId when poolAssetId is SOL.SOL', () => {
|
|
20
|
+
const result = thorPoolAssetIdToAssetId('SOL.SOL');
|
|
21
|
+
expect(result).toEqual(solAssetId);
|
|
22
|
+
});
|
|
19
23
|
it('returns undefined for an asset we dont support', () => {
|
|
20
24
|
const result = thorPoolAssetIdToAssetId('BNB.AVA-645');
|
|
21
25
|
expect(result).toEqual(undefined);
|
|
@@ -44,6 +48,12 @@ describe('poolAssetHelpers', () => {
|
|
|
44
48
|
const poolAssetId = 'ETH.USDC-0XA0B86991C6218B36C1D19D4A2E9EB0CE3606EB48';
|
|
45
49
|
expect(result).toEqual(poolAssetId);
|
|
46
50
|
});
|
|
51
|
+
it('returns SOL pool when assetId is solAssetId (base58 case-sensitive)', () => {
|
|
52
|
+
const assetId = solAssetId;
|
|
53
|
+
const result = assetIdToThorPoolAssetId({ assetId });
|
|
54
|
+
const poolAssetId = 'SOL.SOL';
|
|
55
|
+
expect(result).toEqual(poolAssetId);
|
|
56
|
+
});
|
|
47
57
|
it('returns undefined for an unsupported asset', () => {
|
|
48
58
|
const assetId = 'foobar';
|
|
49
59
|
const result = assetIdToThorPoolAssetId({ assetId });
|
|
@@ -6,6 +6,7 @@ import { v4 as uuid } from 'uuid';
|
|
|
6
6
|
import { getDefaultSlippageDecimalPercentageForSwapper } from '../../../constants.js';
|
|
7
7
|
import { SwapperName, TradeQuoteError } from '../../../types.js';
|
|
8
8
|
import { makeSwapErrorRight } from '../../../utils.js';
|
|
9
|
+
import { buildAffiliateFee } from '../../utils/affiliateFee.js';
|
|
9
10
|
import { isNativeEvmAsset } from '../../utils/helpers/helpers.js';
|
|
10
11
|
import { fetchZrxQuote } from '../utils/fetchFromZrx.js';
|
|
11
12
|
import { assertValidTrade, calculateBuyAmountBeforeFeesCryptoBaseUnit, calculateRate, getProtocolFees, } from '../utils/helpers/helpers.js';
|
|
@@ -96,6 +97,14 @@ export async function getZrxTradeQuote(input, assertGetEvmChainAdapter, assetsBy
|
|
|
96
97
|
buyAmountAfterFeesCryptoBaseUnit: buyAmount,
|
|
97
98
|
sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
98
99
|
source: SwapperName.Zrx,
|
|
100
|
+
affiliateFee: buildAffiliateFee({
|
|
101
|
+
strategy: 'buy_asset',
|
|
102
|
+
affiliateBps,
|
|
103
|
+
sellAsset,
|
|
104
|
+
buyAsset,
|
|
105
|
+
sellAmountCryptoBaseUnit: sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
106
|
+
buyAmountCryptoBaseUnit: buyAmount,
|
|
107
|
+
}),
|
|
99
108
|
permit2Eip712: permit2Eip712,
|
|
100
109
|
zrxTransactionMetadata: transactionMetadata,
|
|
101
110
|
},
|
|
@@ -3,6 +3,7 @@ import { Err, Ok } from '@sniptt/monads';
|
|
|
3
3
|
import { v4 as uuid } from 'uuid';
|
|
4
4
|
import { getDefaultSlippageDecimalPercentageForSwapper } from '../../../constants.js';
|
|
5
5
|
import { SwapperName } from '../../../types.js';
|
|
6
|
+
import { buildAffiliateFee } from '../../utils/affiliateFee.js';
|
|
6
7
|
import { isNativeEvmAsset } from '../../utils/helpers/helpers.js';
|
|
7
8
|
import { fetchZrxPrice } from '../utils/fetchFromZrx.js';
|
|
8
9
|
import { assertValidTrade, calculateBuyAmountBeforeFeesCryptoBaseUnit, calculateRate, getProtocolFees, } from '../utils/helpers/helpers.js';
|
|
@@ -62,6 +63,14 @@ export async function getZrxTradeRate(input, assetsById, zrxBaseUrl) {
|
|
|
62
63
|
buyAmountAfterFeesCryptoBaseUnit: buyAmount,
|
|
63
64
|
sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
64
65
|
source: SwapperName.Zrx,
|
|
66
|
+
affiliateFee: buildAffiliateFee({
|
|
67
|
+
strategy: 'buy_asset',
|
|
68
|
+
affiliateBps,
|
|
69
|
+
sellAsset,
|
|
70
|
+
buyAsset,
|
|
71
|
+
sellAmountCryptoBaseUnit: sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
72
|
+
buyAmountCryptoBaseUnit: buyAmount,
|
|
73
|
+
}),
|
|
65
74
|
},
|
|
66
75
|
],
|
|
67
76
|
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { AssetId } from '@shapeshiftoss/caip';
|
|
2
|
+
import type { Asset } from '@shapeshiftoss/types';
|
|
3
|
+
import type { AffiliateFee } from '../../types.js';
|
|
4
|
+
export type AffiliateFeeStrategy = 'buy_asset' | 'sell_asset' | 'fixed_asset';
|
|
5
|
+
type BuildAffiliateFeeParams = {
|
|
6
|
+
strategy: AffiliateFeeStrategy;
|
|
7
|
+
affiliateBps: string;
|
|
8
|
+
sellAsset: Asset;
|
|
9
|
+
buyAsset: Asset;
|
|
10
|
+
sellAmountCryptoBaseUnit: string;
|
|
11
|
+
buyAmountCryptoBaseUnit: string;
|
|
12
|
+
fixedAsset?: Asset;
|
|
13
|
+
fixedAssetId?: AssetId;
|
|
14
|
+
isEstimate?: boolean;
|
|
15
|
+
};
|
|
16
|
+
export declare const buildAffiliateFee: (params: BuildAffiliateFeeParams) => AffiliateFee | undefined;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { bn, bnOrZero } from '@shapeshiftoss/utils';
|
|
2
|
+
export const buildAffiliateFee = (params) => {
|
|
3
|
+
const { strategy, affiliateBps, sellAsset, buyAsset, sellAmountCryptoBaseUnit, buyAmountCryptoBaseUnit, fixedAsset, fixedAssetId, isEstimate, } = params;
|
|
4
|
+
if (bnOrZero(affiliateBps).lte(0))
|
|
5
|
+
return undefined;
|
|
6
|
+
const bpsDecimal = bn(affiliateBps).div(10000);
|
|
7
|
+
switch (strategy) {
|
|
8
|
+
case 'buy_asset': {
|
|
9
|
+
const feeAmount = bnOrZero(buyAmountCryptoBaseUnit).times(bpsDecimal).toFixed(0);
|
|
10
|
+
return {
|
|
11
|
+
assetId: buyAsset.assetId,
|
|
12
|
+
amountCryptoBaseUnit: feeAmount,
|
|
13
|
+
asset: buyAsset,
|
|
14
|
+
isEstimate,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
case 'sell_asset': {
|
|
18
|
+
const feeAmount = bnOrZero(sellAmountCryptoBaseUnit).times(bpsDecimal).toFixed(0);
|
|
19
|
+
return {
|
|
20
|
+
assetId: sellAsset.assetId,
|
|
21
|
+
amountCryptoBaseUnit: feeAmount,
|
|
22
|
+
asset: sellAsset,
|
|
23
|
+
isEstimate,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
case 'fixed_asset': {
|
|
27
|
+
if (!fixedAsset || !fixedAssetId)
|
|
28
|
+
return undefined;
|
|
29
|
+
return {
|
|
30
|
+
assetId: fixedAssetId,
|
|
31
|
+
amountCryptoBaseUnit: '0',
|
|
32
|
+
asset: fixedAsset,
|
|
33
|
+
isEstimate: true,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
default:
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
@@ -2,21 +2,25 @@ import { CHAIN_NAMESPACE, fromAssetId } from '@shapeshiftoss/caip';
|
|
|
2
2
|
import * as adapters from '@shapeshiftoss/chain-adapters';
|
|
3
3
|
import { assertUnreachable, BigAmount, bn, bnOrZero, contractAddressOrUndefined, convertDecimalPercentageToBasisPoints, convertPrecision, isFulfilled, isRejected, } from '@shapeshiftoss/utils';
|
|
4
4
|
import { Err, Ok } from '@sniptt/monads';
|
|
5
|
+
import { PublicKey, SystemProgram, TransactionInstruction } from '@solana/web3.js';
|
|
5
6
|
import { TronWeb } from 'tronweb';
|
|
6
7
|
import { v4 as uuid } from 'uuid';
|
|
7
8
|
import { getDefaultSlippageDecimalPercentageForSwapper } from '../index.js';
|
|
9
|
+
import { buildAffiliateFee } from '../swappers/utils/affiliateFee.js';
|
|
8
10
|
import { TradeQuoteError } from '../types.js';
|
|
9
11
|
import { getInputOutputRate, makeSwapErrorRight } from '../utils.js';
|
|
10
12
|
import * as evm from './evm/index.js';
|
|
11
13
|
import { getLimitWithManualSlippage } from './getLimitWithManualSlippage/getLimitWithManualSlippage.js';
|
|
12
14
|
import { getQuote } from './getQuote.js';
|
|
13
15
|
import { addLimitToMemo, assertAndProcessMemo, getAffiliate, getNativePrecision, getSwapSource, } from './index.js';
|
|
16
|
+
import * as solana from './solana/index.js';
|
|
14
17
|
import * as tron from './tron/index.js';
|
|
15
18
|
import * as utxo from './utxo/index.js';
|
|
16
19
|
const SAFE_GAS_LIMIT = '100000'; // depositWithExpiry()
|
|
20
|
+
const SOLANA_MEMO_PROGRAM_ID = 'MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr';
|
|
17
21
|
export const getL1RateOrQuote = async (input, deps, streamingInterval, tradeType, swapperName) => {
|
|
18
22
|
const { sellAsset, buyAsset, sellAmountIncludingProtocolFeesCryptoBaseUnit: sellAmountCryptoBaseUnit, accountNumber, receiveAddress, affiliateBps: requestedAffiliateBps, } = input;
|
|
19
|
-
const { config, assertGetEvmChainAdapter, assertGetUtxoChainAdapter, assertGetCosmosSdkChainAdapter, } = deps;
|
|
23
|
+
const { config, assertGetEvmChainAdapter, assertGetUtxoChainAdapter, assertGetCosmosSdkChainAdapter, assertGetSolanaChainAdapter, } = deps;
|
|
20
24
|
// "NativePrecision" is intended to indicate the base unit precision of the asset
|
|
21
25
|
// for the corresponding swapper network (THORChain or MAYAChain)
|
|
22
26
|
// (CACAO = 10, everything else = 8)
|
|
@@ -167,6 +171,14 @@ export const getL1RateOrQuote = async (input, deps, streamingInterval, tradeType
|
|
|
167
171
|
accountNumber,
|
|
168
172
|
allowanceContract,
|
|
169
173
|
feeData,
|
|
174
|
+
affiliateFee: buildAffiliateFee({
|
|
175
|
+
strategy: 'buy_asset',
|
|
176
|
+
affiliateBps: route.affiliateBps,
|
|
177
|
+
sellAsset,
|
|
178
|
+
buyAsset,
|
|
179
|
+
sellAmountCryptoBaseUnit,
|
|
180
|
+
buyAmountCryptoBaseUnit: buyAmountAfterFeesCryptoBaseUnit,
|
|
181
|
+
}),
|
|
170
182
|
thorchainSpecific: {
|
|
171
183
|
maxStreamingQuantity: route.quote.max_streaming_quantity,
|
|
172
184
|
},
|
|
@@ -279,10 +291,51 @@ export const getL1RateOrQuote = async (input, deps, streamingInterval, tradeType
|
|
|
279
291
|
}));
|
|
280
292
|
}
|
|
281
293
|
case CHAIN_NAMESPACE.Solana: {
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
294
|
+
const adapter = assertGetSolanaChainAdapter(sellAsset.chainId);
|
|
295
|
+
const sendAddress = input.sendAddress;
|
|
296
|
+
const maybeRoutes = await Promise.allSettled(perRouteValues.map(async (route) => {
|
|
297
|
+
const memo = getMemo(route);
|
|
298
|
+
const protocolFees = getProtocolFees(route.quote);
|
|
299
|
+
const feeData = await (async () => {
|
|
300
|
+
if (!sendAddress)
|
|
301
|
+
return { networkFeeCryptoBaseUnit: undefined, protocolFees };
|
|
302
|
+
const { vault } = await solana.getThorTxData({ sellAsset, config, swapperName });
|
|
303
|
+
const memoInstruction = new TransactionInstruction({
|
|
304
|
+
keys: [],
|
|
305
|
+
programId: new PublicKey(SOLANA_MEMO_PROGRAM_ID),
|
|
306
|
+
data: Buffer.from(memo, 'utf8'),
|
|
307
|
+
});
|
|
308
|
+
const transferInstruction = SystemProgram.transfer({
|
|
309
|
+
fromPubkey: new PublicKey(sendAddress),
|
|
310
|
+
toPubkey: new PublicKey(vault),
|
|
311
|
+
lamports: BigInt(sellAmountCryptoBaseUnit),
|
|
312
|
+
});
|
|
313
|
+
const { fast } = await adapter.getFeeData({
|
|
314
|
+
to: vault,
|
|
315
|
+
value: '0',
|
|
316
|
+
chainSpecific: {
|
|
317
|
+
from: sendAddress,
|
|
318
|
+
tokenId: contractAddressOrUndefined(sellAsset.assetId),
|
|
319
|
+
instructions: [memoInstruction, transferInstruction],
|
|
320
|
+
},
|
|
321
|
+
});
|
|
322
|
+
return { networkFeeCryptoBaseUnit: fast.txFee, protocolFees };
|
|
323
|
+
})();
|
|
324
|
+
return makeThorTradeRateOrQuote({
|
|
325
|
+
route,
|
|
326
|
+
allowanceContract: '0x0',
|
|
327
|
+
memo,
|
|
328
|
+
feeData,
|
|
329
|
+
});
|
|
285
330
|
}));
|
|
331
|
+
const routes = maybeRoutes.filter(isFulfilled).map(r => r.value);
|
|
332
|
+
if (!routes.length)
|
|
333
|
+
return Err(makeSwapErrorRight({
|
|
334
|
+
message: 'Unable to create any routes',
|
|
335
|
+
code: TradeQuoteError.UnsupportedTradePair,
|
|
336
|
+
cause: maybeRoutes.filter(isRejected).map(r => r.reason),
|
|
337
|
+
}));
|
|
338
|
+
return Ok(routes);
|
|
286
339
|
}
|
|
287
340
|
case CHAIN_NAMESPACE.Tron: {
|
|
288
341
|
const maybeRoutes = await Promise.allSettled(perRouteValues.map(async (route) => {
|
|
@@ -13,6 +13,7 @@ export * from './getL1RateOrQuote.js';
|
|
|
13
13
|
export * from './getPoolDetails.js';
|
|
14
14
|
export * as cosmossdk from './cosmossdk/index.js';
|
|
15
15
|
export * as evm from './evm/index.js';
|
|
16
|
+
export * as solana from './solana/index.js';
|
|
16
17
|
export * as tron from './tron/index.js';
|
|
17
18
|
export * as utxo from './utxo/index.js';
|
|
18
19
|
export declare const getChainIdBySwapper: (swapperName: SwapperName) => import("@shapeshiftoss/caip").ChainId;
|
|
@@ -21,7 +22,7 @@ export declare const isThorTradeQuote: (quote: TradeQuote | undefined) => quote
|
|
|
21
22
|
export declare const getDaemonUrl: (config: SwapperConfig, swapperName: SwapperName) => string;
|
|
22
23
|
export declare const getMidgardUrl: (config: SwapperConfig, swapperName: SwapperName) => string;
|
|
23
24
|
export declare const isNativeAsset: (assetId: AssetId, swapperName: SwapperName) => boolean;
|
|
24
|
-
export declare const getNativePrecision: (assetId: AssetId, swapperName: SwapperName) =>
|
|
25
|
+
export declare const getNativePrecision: (assetId: AssetId, swapperName: SwapperName) => 8 | 10;
|
|
25
26
|
export declare const getNativeFee: (swapperName: SwapperName) => "2000000" | "2000000000";
|
|
26
27
|
export declare const getAffiliate: (swapperName: SwapperName) => "ss" | "ssmaya";
|
|
27
28
|
export declare const getPoolAssetId: ({ assetId, swapperName, }: {
|
|
@@ -14,6 +14,7 @@ export * from './getL1RateOrQuote.js';
|
|
|
14
14
|
export * from './getPoolDetails.js';
|
|
15
15
|
export * as cosmossdk from './cosmossdk/index.js';
|
|
16
16
|
export * as evm from './evm/index.js';
|
|
17
|
+
export * as solana from './solana/index.js';
|
|
17
18
|
export * as tron from './tron/index.js';
|
|
18
19
|
export * as utxo from './utxo/index.js';
|
|
19
20
|
export const getChainIdBySwapper = (swapperName) => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const MEMO_PROGRAM_ID = "MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr";
|