@shapeshiftoss/swapper 17.6.10 → 17.6.11
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 +29 -18
- 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 -0
- package/dist/cjs/index.js +1 -0
- 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 +9 -0
- 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/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/DebridgeSwapper/endpoints.d.ts +2 -0
- package/dist/cjs/swappers/DebridgeSwapper/endpoints.js +217 -0
- package/dist/cjs/swappers/DebridgeSwapper/getTradeQuote/getTradeQuote.d.ts +3 -0
- package/dist/cjs/swappers/DebridgeSwapper/getTradeQuote/getTradeQuote.js +31 -0
- package/dist/cjs/swappers/DebridgeSwapper/getTradeRate/getTradeRate.d.ts +3 -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/DebridgeSwapper/utils/debridgeService.d.ts +5 -0
- 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 +369 -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/JupiterSwapper/swapperApi/getTradeQuote.js +32 -0
- package/dist/cjs/swappers/JupiterSwapper/swapperApi/getTradeRate.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 +4 -3
- package/dist/cjs/swappers/RelaySwapper/utils/getTrade.js +44 -5
- package/dist/cjs/swappers/RelaySwapper/utils/relayTokenToAssetId.js +17 -7
- package/dist/cjs/swappers/StonfiSwapper/swapperApi/getTradeQuote.js +10 -0
- 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/thorchain-utils/solana/index.js +19 -0
- package/dist/cjs/types.d.ts +44 -5
- package/dist/cjs/types.js +1 -0
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/constants.js +11 -0
- 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 -0
- package/dist/esm/index.js +1 -0
- 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 +9 -0
- 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/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/DebridgeSwapper/DebridgeSwapper.d.ts +2 -0
- 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/DebridgeSwapper/endpoints.d.ts +2 -0
- package/dist/esm/swappers/DebridgeSwapper/endpoints.js +211 -0
- package/dist/esm/swappers/DebridgeSwapper/getTradeQuote/getTradeQuote.d.ts +3 -0
- package/dist/esm/swappers/DebridgeSwapper/getTradeQuote/getTradeQuote.js +27 -0
- package/dist/esm/swappers/DebridgeSwapper/getTradeRate/getTradeRate.d.ts +3 -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/DebridgeSwapper/utils/debridgeService.d.ts +5 -0
- 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 +362 -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/JupiterSwapper/swapperApi/getTradeQuote.js +33 -1
- package/dist/esm/swappers/JupiterSwapper/swapperApi/getTradeRate.js +9 -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 +6 -5
- package/dist/esm/swappers/RelaySwapper/utils/getTrade.js +47 -8
- package/dist/esm/swappers/RelaySwapper/utils/relayTokenToAssetId.js +17 -7
- package/dist/esm/swappers/StonfiSwapper/swapperApi/getTradeQuote.js +10 -0
- 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/types.d.ts +44 -5
- package/dist/esm/types.js +1 -0
- package/package.json +19 -18
package/dist/esm/constants.js
CHANGED
|
@@ -15,6 +15,8 @@ import { chainflipSwapper } from './swappers/ChainflipSwapper/ChainflipSwapper.j
|
|
|
15
15
|
import { chainflipApi } from './swappers/ChainflipSwapper/endpoints.js';
|
|
16
16
|
import { cowSwapper } from './swappers/CowSwapper/CowSwapper.js';
|
|
17
17
|
import { cowApi } from './swappers/CowSwapper/endpoints.js';
|
|
18
|
+
import { debridgeSwapper } from './swappers/DebridgeSwapper/index.js';
|
|
19
|
+
import { debridgeApi } from './swappers/DebridgeSwapper/endpoints.js';
|
|
18
20
|
import { jupiterApi } from './swappers/JupiterSwapper/endpoints.js';
|
|
19
21
|
import { jupiterSwapper } from './swappers/JupiterSwapper/JupiterSwapper.js';
|
|
20
22
|
import { mayachainApi } from './swappers/MayachainSwapper/endpoints.js';
|
|
@@ -111,6 +113,10 @@ export const swappers = {
|
|
|
111
113
|
...acrossSwapper,
|
|
112
114
|
...acrossApi,
|
|
113
115
|
},
|
|
116
|
+
[SwapperName.Debridge]: {
|
|
117
|
+
...debridgeSwapper,
|
|
118
|
+
...debridgeApi,
|
|
119
|
+
},
|
|
114
120
|
[SwapperName.Test]: undefined,
|
|
115
121
|
};
|
|
116
122
|
const DEFAULT_SLIPPAGE_DECIMAL_PERCENTAGE = '0.002';
|
|
@@ -127,6 +133,8 @@ const DEFAULT_SUNIO_SLIPPAGE_DECIMAL_PERCENTAGE = '0.005';
|
|
|
127
133
|
// Starknet swaps can have more latency, so use higher default slippage
|
|
128
134
|
const DEFAULT_AVNU_SLIPPAGE_DECIMAL_PERCENTAGE = '0.02';
|
|
129
135
|
const DEFAULT_STONFI_SLIPPAGE_DECIMAL_PERCENTAGE = '0.01';
|
|
136
|
+
// deBridge API off-chain simulation overestimates output on some chains (e.g. SEI ~2.4%), so auto slippage (1%) is insufficient
|
|
137
|
+
const DEFAULT_DEBRIDGE_SLIPPAGE_DECIMAL_PERCENTAGE = '0.03';
|
|
130
138
|
export const getDefaultSlippageDecimalPercentageForSwapper = (swapperName) => {
|
|
131
139
|
if (swapperName === undefined)
|
|
132
140
|
return DEFAULT_SLIPPAGE_DECIMAL_PERCENTAGE;
|
|
@@ -153,6 +161,8 @@ export const getDefaultSlippageDecimalPercentageForSwapper = (swapperName) => {
|
|
|
153
161
|
throw new Error('Default slippage not supported by Relay');
|
|
154
162
|
case SwapperName.Across:
|
|
155
163
|
throw new Error('Default slippage not supported by Across');
|
|
164
|
+
case SwapperName.Debridge:
|
|
165
|
+
return DEFAULT_DEBRIDGE_SLIPPAGE_DECIMAL_PERCENTAGE;
|
|
156
166
|
case SwapperName.ButterSwap:
|
|
157
167
|
return DEFAULT_BUTTERSWAP_SLIPPAGE_DECIMAL_PERCENTAGE;
|
|
158
168
|
case SwapperName.NearIntents:
|
|
@@ -175,6 +185,7 @@ export const isAutoSlippageSupportedBySwapper = (swapperName) => {
|
|
|
175
185
|
return true;
|
|
176
186
|
case SwapperName.Relay:
|
|
177
187
|
case SwapperName.Across:
|
|
188
|
+
case SwapperName.Debridge:
|
|
178
189
|
return true;
|
|
179
190
|
default:
|
|
180
191
|
return false;
|
|
@@ -24,6 +24,9 @@ export const SUPPORTED_CHAIN_IDS = [
|
|
|
24
24
|
KnownChainIds.AvalancheMainnet,
|
|
25
25
|
KnownChainIds.PolygonMainnet,
|
|
26
26
|
KnownChainIds.BnbSmartChainMainnet,
|
|
27
|
+
KnownChainIds.PlasmaMainnet,
|
|
28
|
+
KnownChainIds.LineaMainnet,
|
|
29
|
+
KnownChainIds.InkMainnet,
|
|
27
30
|
];
|
|
28
31
|
export const COW_SWAP_VAULT_RELAYER_ADDRESS = '0xc92e8bdf79f0507f65a392b0ab4667716bfe0110';
|
|
29
32
|
export const COW_SWAP_SETTLEMENT_ADDRESS = '0x9008D19f58AAbD9eD0D60971565AA8510560ab41';
|
|
@@ -24,6 +24,12 @@ export const getCowNetwork = (chainId) => {
|
|
|
24
24
|
return CowNetwork.Polygon;
|
|
25
25
|
case KnownChainIds.BnbSmartChainMainnet:
|
|
26
26
|
return CowNetwork.Bnb;
|
|
27
|
+
case KnownChainIds.PlasmaMainnet:
|
|
28
|
+
return CowNetwork.Plasma;
|
|
29
|
+
case KnownChainIds.LineaMainnet:
|
|
30
|
+
return CowNetwork.Linea;
|
|
31
|
+
case KnownChainIds.InkMainnet:
|
|
32
|
+
return CowNetwork.Ink;
|
|
27
33
|
default:
|
|
28
34
|
return;
|
|
29
35
|
}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export * from './swappers/CetusSwapper/index.js';
|
|
|
9
9
|
export * from './swappers/ChainflipSwapper/index.js';
|
|
10
10
|
export * from './swappers/SunioSwapper/index.js';
|
|
11
11
|
export * from './swappers/CowSwapper/index.js';
|
|
12
|
+
export * from './swappers/DebridgeSwapper/index.js';
|
|
12
13
|
export * from './swappers/JupiterSwapper/index.js';
|
|
13
14
|
export * from './swappers/PortalsSwapper/index.js';
|
|
14
15
|
export * from './swappers/ThorchainSwapper/index.js';
|
package/dist/esm/index.js
CHANGED
|
@@ -9,6 +9,7 @@ export * from './swappers/CetusSwapper/index.js';
|
|
|
9
9
|
export * from './swappers/ChainflipSwapper/index.js';
|
|
10
10
|
export * from './swappers/SunioSwapper/index.js';
|
|
11
11
|
export * from './swappers/CowSwapper/index.js';
|
|
12
|
+
export * from './swappers/DebridgeSwapper/index.js';
|
|
12
13
|
export * from './swappers/JupiterSwapper/index.js';
|
|
13
14
|
export * from './swappers/PortalsSwapper/index.js';
|
|
14
15
|
export * from './swappers/ThorchainSwapper/index.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { arbitrumChainId, baseChainId, blastChainId, bscChainId, ethChainId, hyperEvmChainId, inkChainId, lineaChainId, modeChainId, monadChainId, optimismChainId, plasmaChainId, polygonChainId, solanaChainId, soneiumChainId, unichainChainId, worldChainChainId, zkSyncEraChainId, } from '@shapeshiftoss/caip';
|
|
1
|
+
import { arbitrumChainId, baseChainId, blastChainId, bscChainId, ethChainId, hyperEvmChainId, inkChainId, lineaChainId, megaethChainId, modeChainId, monadChainId, optimismChainId, plasmaChainId, polygonChainId, scrollChainId, solanaChainId, soneiumChainId, unichainChainId, worldChainChainId, zkSyncEraChainId, } from '@shapeshiftoss/caip';
|
|
2
2
|
import invert from 'lodash/invert';
|
|
3
3
|
import { zeroAddress } from 'viem';
|
|
4
|
-
import { arbitrum, base, blast, bsc, hyperEvm, ink, linea, mainnet as ethereum, mode, monad, optimism, plasma, polygon, soneium, unichain, worldchain, zksync, } from 'viem/chains';
|
|
4
|
+
import { arbitrum, base, blast, bsc, hyperEvm, ink, linea, mainnet as ethereum, mode, monad, optimism, plasma, polygon, scroll, soneium, unichain, worldchain, zksync, } from 'viem/chains';
|
|
5
5
|
import { TradeQuoteError } from '../../types.js';
|
|
6
6
|
import { AcrossErrorCode } from './utils/types.js';
|
|
7
7
|
export const chainIdToAcrossChainId = {
|
|
@@ -24,6 +24,8 @@ export const chainIdToAcrossChainId = {
|
|
|
24
24
|
[soneiumChainId]: soneium.id,
|
|
25
25
|
// Across uses a custom Solana chain ID
|
|
26
26
|
[solanaChainId]: 34268394551451,
|
|
27
|
+
[scrollChainId]: scroll.id,
|
|
28
|
+
[megaethChainId]: 4326,
|
|
27
29
|
};
|
|
28
30
|
export const acrossChainIdToChainId = invert(chainIdToAcrossChainId);
|
|
29
31
|
export const ACROSS_SUPPORTED_CHAIN_IDS = Object.keys(chainIdToAcrossChainId);
|
|
@@ -7,6 +7,7 @@ import axios from 'axios';
|
|
|
7
7
|
import { zeroAddress } from 'viem';
|
|
8
8
|
import { SwapperName, TradeQuoteError } from '../../../types.js';
|
|
9
9
|
import { getInputOutputRate, makeSwapErrorRight } from '../../../utils.js';
|
|
10
|
+
import { buildAffiliateFee } from '../../utils/affiliateFee.js';
|
|
10
11
|
import { getTreasuryAddressFromChainId, isNativeEvmAsset } from '../../utils/helpers/helpers.js';
|
|
11
12
|
import { ACROSS_SOLANA_TOKEN_ADDRESS, acrossChainIdToChainId, acrossErrorCodeToTradeQuoteError, chainIdToAcrossChainId, DEFAULT_ACROSS_EVM_TOKEN_ADDRESS, DEFAULT_ACROSS_EVM_USER_ADDRESS, DEFAULT_ACROSS_SOLANA_USER_ADDRESS, } from '../constant.js';
|
|
12
13
|
import { fetchAcrossTrade } from './fetchAcrossTrade.js';
|
|
@@ -178,7 +179,9 @@ export async function getTrade({ input, deps, }) {
|
|
|
178
179
|
if (quote.swapTx.ecosystem !== 'svm')
|
|
179
180
|
return Ok(undefined);
|
|
180
181
|
try {
|
|
181
|
-
const
|
|
182
|
+
const txBytes = Buffer.from(quote.swapTx.data, 'base64');
|
|
183
|
+
const isOversized = txBytes.length > 1232;
|
|
184
|
+
const versionedTransaction = VersionedTransaction.deserialize(new Uint8Array(txBytes));
|
|
182
185
|
const adapter = deps.assertGetSolanaChainAdapter(sellAsset.chainId);
|
|
183
186
|
const addressLookupTableAccountKeys = versionedTransaction.message.addressTableLookups.map(lookup => lookup.accountKey.toString());
|
|
184
187
|
const addressLookupTableAccountsInfos = await adapter.getAddressLookupTableAccounts(addressLookupTableAccountKeys);
|
|
@@ -194,6 +197,7 @@ export async function getTrade({ input, deps, }) {
|
|
|
194
197
|
return Ok({
|
|
195
198
|
instructions: instructionsWithoutComputeBudget,
|
|
196
199
|
addressLookupTableAddresses: addressLookupTableAccountKeys,
|
|
200
|
+
isOversized,
|
|
197
201
|
});
|
|
198
202
|
}
|
|
199
203
|
catch (e) {
|
|
@@ -295,6 +299,16 @@ export async function getTrade({ input, deps, }) {
|
|
|
295
299
|
estimatedExecutionTimeMs: quote.expectedFillTime * 1000,
|
|
296
300
|
acrossTransactionMetadata,
|
|
297
301
|
solanaTransactionMetadata,
|
|
302
|
+
affiliateFee: appFee !== undefined && appFeeRecipient !== undefined
|
|
303
|
+
? buildAffiliateFee({
|
|
304
|
+
strategy: 'buy_asset',
|
|
305
|
+
affiliateBps,
|
|
306
|
+
sellAsset,
|
|
307
|
+
buyAsset,
|
|
308
|
+
sellAmountCryptoBaseUnit: sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
309
|
+
buyAmountCryptoBaseUnit: buyAmountAfterFeesCryptoBaseUnit,
|
|
310
|
+
})
|
|
311
|
+
: undefined,
|
|
298
312
|
};
|
|
299
313
|
const baseQuoteOrRate = {
|
|
300
314
|
id: quote.id,
|
|
@@ -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 { getInputOutputRate, makeSwapErrorRight } from '../../../utils.js';
|
|
9
|
+
import { buildAffiliateFee } from '../../utils/affiliateFee.js';
|
|
9
10
|
import { getTreasuryAddressFromChainId } from '../../utils/helpers/helpers.js';
|
|
10
11
|
import { AVNU_SUPPORTED_CHAIN_IDS } from '../utils/constants.js';
|
|
11
12
|
import { getTokenAddress } from '../utils/helpers.js';
|
|
@@ -128,6 +129,14 @@ export const getTradeQuote = async (input, deps) => {
|
|
|
128
129
|
quoteId: bestQuote.quoteId,
|
|
129
130
|
routes: bestQuote.routes,
|
|
130
131
|
},
|
|
132
|
+
affiliateFee: buildAffiliateFee({
|
|
133
|
+
strategy: 'buy_asset',
|
|
134
|
+
affiliateBps,
|
|
135
|
+
sellAsset,
|
|
136
|
+
buyAsset,
|
|
137
|
+
sellAmountCryptoBaseUnit: sellAmount,
|
|
138
|
+
buyAmountCryptoBaseUnit: buyAmountAfterFeesCryptoBaseUnit,
|
|
139
|
+
}),
|
|
131
140
|
},
|
|
132
141
|
],
|
|
133
142
|
};
|
|
@@ -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 { getInputOutputRate, makeSwapErrorRight } from '../../../utils.js';
|
|
9
|
+
import { buildAffiliateFee } from '../../utils/affiliateFee.js';
|
|
9
10
|
import { getTreasuryAddressFromChainId } from '../../utils/helpers/helpers.js';
|
|
10
11
|
import { AVNU_SUPPORTED_CHAIN_IDS } from '../utils/constants.js';
|
|
11
12
|
import { getTokenAddress } from '../utils/helpers.js';
|
|
@@ -105,6 +106,14 @@ export const getTradeRate = async (input, deps) => {
|
|
|
105
106
|
sellAsset,
|
|
106
107
|
source: SwapperName.Avnu,
|
|
107
108
|
estimatedExecutionTimeMs: undefined,
|
|
109
|
+
affiliateFee: buildAffiliateFee({
|
|
110
|
+
strategy: 'buy_asset',
|
|
111
|
+
affiliateBps,
|
|
112
|
+
sellAsset,
|
|
113
|
+
buyAsset,
|
|
114
|
+
sellAmountCryptoBaseUnit: sellAmount,
|
|
115
|
+
buyAmountCryptoBaseUnit: buyAmountAfterFeesCryptoBaseUnit,
|
|
116
|
+
}),
|
|
108
117
|
},
|
|
109
118
|
],
|
|
110
119
|
};
|
|
@@ -1,15 +1,27 @@
|
|
|
1
|
+
import { solanaChainId } from '@shapeshiftoss/caip';
|
|
1
2
|
import { evm } from '@shapeshiftoss/chain-adapters';
|
|
2
3
|
import BigNumber from 'bignumber.js';
|
|
3
4
|
import { fromHex } from 'viem';
|
|
4
|
-
import { checkEvmSwapStatus, getExecutableTradeStep, isExecutableTradeQuote } from '../../utils.js';
|
|
5
|
+
import { checkEvmSwapStatus, checkSolanaSwapStatus, getExecutableTradeStep, isExecutableTradeQuote, } from '../../utils.js';
|
|
6
|
+
import { getBebopSolanaTradeQuote } from './getBebopSolanaTradeQuote/getBebopSolanaTradeQuote.js';
|
|
7
|
+
import { getBebopSolanaTradeRate } from './getBebopSolanaTradeRate/getBebopSolanaTradeRate.js';
|
|
5
8
|
import { getBebopTradeQuote } from './getBebopTradeQuote/getBebopTradeQuote.js';
|
|
6
9
|
import { getBebopTradeRate } from './getBebopTradeRate/getBebopTradeRate.js';
|
|
10
|
+
import { isSolanaChainId } from './utils/helpers/helpers.js';
|
|
7
11
|
export const bebopApi = {
|
|
8
12
|
getTradeQuote: async (input, { assertGetEvmChainAdapter, assetsById, config }) => {
|
|
13
|
+
if (isSolanaChainId(input.sellAsset.chainId)) {
|
|
14
|
+
const tradeQuoteResult = await getBebopSolanaTradeQuote(input, assetsById, config.VITE_BEBOP_API_KEY);
|
|
15
|
+
return tradeQuoteResult.map(tradeQuote => [tradeQuote]);
|
|
16
|
+
}
|
|
9
17
|
const tradeQuoteResult = await getBebopTradeQuote(input, assertGetEvmChainAdapter, assetsById, config.VITE_BEBOP_API_KEY);
|
|
10
18
|
return tradeQuoteResult.map(tradeQuote => [tradeQuote]);
|
|
11
19
|
},
|
|
12
20
|
getTradeRate: async (input, { assertGetEvmChainAdapter, assetsById, config }) => {
|
|
21
|
+
if (isSolanaChainId(input.sellAsset.chainId)) {
|
|
22
|
+
const tradeRateResult = await getBebopSolanaTradeRate(input, assetsById, config.VITE_BEBOP_API_KEY);
|
|
23
|
+
return tradeRateResult.map(tradeRate => [tradeRate]);
|
|
24
|
+
}
|
|
13
25
|
const tradeRateResult = await getBebopTradeRate(input, assertGetEvmChainAdapter, assetsById, config.VITE_BEBOP_API_KEY);
|
|
14
26
|
return tradeRateResult.map(tradeRate => [tradeRate]);
|
|
15
27
|
},
|
|
@@ -34,10 +46,22 @@ export const bebopApi = {
|
|
|
34
46
|
to,
|
|
35
47
|
value,
|
|
36
48
|
...feeData,
|
|
37
|
-
// Use the higher amount of the node or the API, as the node doesn't always provide enough gas padding
|
|
38
49
|
gasLimit: BigNumber.max(feeData.gasLimit, gas).toFixed(),
|
|
39
50
|
});
|
|
40
51
|
},
|
|
52
|
+
getUnsignedSolanaMessage: ({ tradeQuote, stepIndex }) => {
|
|
53
|
+
if (!isExecutableTradeQuote(tradeQuote))
|
|
54
|
+
throw new Error('Unable to execute a trade rate quote');
|
|
55
|
+
const step = getExecutableTradeStep(tradeQuote, stepIndex);
|
|
56
|
+
const { bebopSolanaSerializedTx, bebopQuoteId } = step;
|
|
57
|
+
if (!bebopSolanaSerializedTx || !bebopQuoteId) {
|
|
58
|
+
throw new Error('Bebop Solana transaction metadata is required');
|
|
59
|
+
}
|
|
60
|
+
return Promise.resolve({
|
|
61
|
+
serializedTx: bebopSolanaSerializedTx,
|
|
62
|
+
quoteId: bebopQuoteId,
|
|
63
|
+
});
|
|
64
|
+
},
|
|
41
65
|
getEvmTransactionFees: async ({ from, stepIndex, tradeQuote, supportsEIP1559, assertGetEvmChainAdapter, }) => {
|
|
42
66
|
if (!isExecutableTradeQuote(tradeQuote))
|
|
43
67
|
throw new Error('Unable to execute a trade rate quote');
|
|
@@ -51,5 +75,14 @@ export const bebopApi = {
|
|
|
51
75
|
const feeData = await evm.getFees({ adapter, data, to, value, from, supportsEIP1559 });
|
|
52
76
|
return feeData.networkFeeCryptoBaseUnit;
|
|
53
77
|
},
|
|
54
|
-
checkTradeStatus:
|
|
78
|
+
checkTradeStatus: input => {
|
|
79
|
+
if (input.chainId === solanaChainId) {
|
|
80
|
+
return checkSolanaSwapStatus({
|
|
81
|
+
txHash: input.txHash,
|
|
82
|
+
address: input.address,
|
|
83
|
+
assertGetSolanaChainAdapter: input.assertGetSolanaChainAdapter,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return checkEvmSwapStatus(input);
|
|
87
|
+
},
|
|
55
88
|
};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import type { SolanaMessageExecutionProps, SolanaMessageToSign, SwapperConfig } from '../../types.js';
|
|
2
|
+
export declare const executeSolanaMessage: (messageData: SolanaMessageToSign, { signSerializedTransaction }: SolanaMessageExecutionProps, config: SwapperConfig) => Promise<string>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import bs58 from 'bs58';
|
|
2
|
+
import { bebopServiceFactory } from './utils/bebopService.js';
|
|
3
|
+
export const executeSolanaMessage = async (messageData, { signSerializedTransaction }, config) => {
|
|
4
|
+
const { serializedTx, quoteId } = messageData;
|
|
5
|
+
if (!serializedTx || !quoteId) {
|
|
6
|
+
throw new Error('Missing serializedTx or quoteId in message data');
|
|
7
|
+
}
|
|
8
|
+
const signatures = await signSerializedTransaction(serializedTx);
|
|
9
|
+
if (!signatures.length) {
|
|
10
|
+
throw new Error('No signatures returned from wallet');
|
|
11
|
+
}
|
|
12
|
+
// Find the actual non-zero user signature (skip empty placeholder slots from co-signers)
|
|
13
|
+
const nonZeroSigIndex = signatures.findIndex(sig => {
|
|
14
|
+
const bytes = Buffer.from(sig, 'base64');
|
|
15
|
+
return !bytes.every(b => b === 0);
|
|
16
|
+
});
|
|
17
|
+
if (nonZeroSigIndex === -1) {
|
|
18
|
+
throw new Error('No non-zero signatures found after signing');
|
|
19
|
+
}
|
|
20
|
+
const userSignatureBase64 = signatures[nonZeroSigIndex];
|
|
21
|
+
const userSignatureBytes = Buffer.from(userSignatureBase64, 'base64');
|
|
22
|
+
const userSignatureBase58 = bs58.encode(userSignatureBytes);
|
|
23
|
+
const bebopService = bebopServiceFactory({ apiKey: config.VITE_BEBOP_API_KEY });
|
|
24
|
+
const maybeOrderResponse = await bebopService.post('https://api.bebop.xyz/pmm/solana/v3/order', {
|
|
25
|
+
quote_id: quoteId,
|
|
26
|
+
signature: userSignatureBase58,
|
|
27
|
+
});
|
|
28
|
+
if (maybeOrderResponse.isErr()) {
|
|
29
|
+
const error = maybeOrderResponse.unwrapErr();
|
|
30
|
+
throw new Error(`Bebop order submission failed: ${error.cause ?? error.message}`);
|
|
31
|
+
}
|
|
32
|
+
const { data: orderResponse } = maybeOrderResponse.unwrap();
|
|
33
|
+
if (orderResponse.error) {
|
|
34
|
+
throw new Error(`Bebop order failed: ${orderResponse.error.message} (code ${orderResponse.error.errorCode})`);
|
|
35
|
+
}
|
|
36
|
+
if (!orderResponse.txHash) {
|
|
37
|
+
throw new Error(`Bebop order response missing txHash: ${JSON.stringify(orderResponse)}`);
|
|
38
|
+
}
|
|
39
|
+
return orderResponse.txHash;
|
|
40
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { AssetsByIdPartial } from '@shapeshiftoss/types';
|
|
2
|
+
import type { Result } from '@sniptt/monads';
|
|
3
|
+
import type { GetSolanaTradeQuoteInput, SwapErrorRight, TradeQuote } from '../../../types.js';
|
|
4
|
+
export declare function getBebopSolanaTradeQuote(input: GetSolanaTradeQuoteInput, _assetsById: AssetsByIdPartial, apiKey: string): Promise<Result<TradeQuote, SwapErrorRight>>;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { Err, Ok } from '@sniptt/monads';
|
|
2
|
+
import { v4 as uuid } from 'uuid';
|
|
3
|
+
import { getDefaultSlippageDecimalPercentageForSwapper } from '../../../constants.js';
|
|
4
|
+
import { SwapperName, TradeQuoteError } from '../../../types.js';
|
|
5
|
+
import { makeSwapErrorRight } from '../../../utils.js';
|
|
6
|
+
import { fetchBebopSolanaQuote } from '../utils/fetchFromBebop.js';
|
|
7
|
+
import { assertValidTrade, calculateRate, isBebopSolanaTxSafe } from '../utils/helpers/helpers.js';
|
|
8
|
+
export async function getBebopSolanaTradeQuote(input, _assetsById, apiKey) {
|
|
9
|
+
const { sellAsset, buyAsset, accountNumber, sendAddress, receiveAddress, affiliateBps, sellAmountIncludingProtocolFeesCryptoBaseUnit, } = input;
|
|
10
|
+
const assertion = assertValidTrade({ buyAsset, sellAsset });
|
|
11
|
+
if (assertion.isErr())
|
|
12
|
+
return Err(assertion.unwrapErr());
|
|
13
|
+
const takerAddress = sendAddress || receiveAddress;
|
|
14
|
+
if (!takerAddress) {
|
|
15
|
+
return Err(makeSwapErrorRight({
|
|
16
|
+
message: 'Cannot execute quote without a wallet address',
|
|
17
|
+
code: TradeQuoteError.UnknownError,
|
|
18
|
+
}));
|
|
19
|
+
}
|
|
20
|
+
const slippageTolerancePercentageDecimal = input.slippageTolerancePercentageDecimal ??
|
|
21
|
+
getDefaultSlippageDecimalPercentageForSwapper(SwapperName.Bebop);
|
|
22
|
+
const maybeBebopQuoteResponse = await fetchBebopSolanaQuote({
|
|
23
|
+
buyAsset,
|
|
24
|
+
sellAsset,
|
|
25
|
+
sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
26
|
+
takerAddress,
|
|
27
|
+
receiverAddress: receiveAddress ?? takerAddress,
|
|
28
|
+
slippageTolerancePercentageDecimal,
|
|
29
|
+
affiliateBps,
|
|
30
|
+
apiKey,
|
|
31
|
+
});
|
|
32
|
+
if (maybeBebopQuoteResponse.isErr())
|
|
33
|
+
return Err(maybeBebopQuoteResponse.unwrapErr());
|
|
34
|
+
const bebopQuoteResponse = maybeBebopQuoteResponse.unwrap();
|
|
35
|
+
const sellTokenAddress = Object.keys(bebopQuoteResponse.sellTokens)[0];
|
|
36
|
+
const buyTokenAddress = Object.keys(bebopQuoteResponse.buyTokens)[0];
|
|
37
|
+
if (!sellTokenAddress || !buyTokenAddress) {
|
|
38
|
+
return Err(makeSwapErrorRight({
|
|
39
|
+
message: 'Invalid token addresses in response',
|
|
40
|
+
code: TradeQuoteError.InvalidResponse,
|
|
41
|
+
}));
|
|
42
|
+
}
|
|
43
|
+
if (bebopQuoteResponse.solana_tx &&
|
|
44
|
+
!isBebopSolanaTxSafe(bebopQuoteResponse.solana_tx, takerAddress)) {
|
|
45
|
+
return Err(makeSwapErrorRight({
|
|
46
|
+
message: 'Bebop signer index mismatch - taker not at expected position',
|
|
47
|
+
code: TradeQuoteError.NoRouteFound,
|
|
48
|
+
}));
|
|
49
|
+
}
|
|
50
|
+
const sellAmount = bebopQuoteResponse.sellTokens[sellTokenAddress].amount;
|
|
51
|
+
const buyAmount = bebopQuoteResponse.buyTokens[buyTokenAddress].amount;
|
|
52
|
+
const rate = calculateRate({ buyAmount, sellAmount, buyAsset, sellAsset });
|
|
53
|
+
const buyTokenData = bebopQuoteResponse.buyTokens[buyTokenAddress];
|
|
54
|
+
const buyAmountBeforeFeesCryptoBaseUnit = buyTokenData.amountBeforeFee || buyAmount;
|
|
55
|
+
const buyAmountAfterFeesCryptoBaseUnit = buyAmount;
|
|
56
|
+
// Bebop Solana is gasless - Bebop pays the network fees via co-signing
|
|
57
|
+
const networkFeeCryptoBaseUnit = '0';
|
|
58
|
+
return Ok({
|
|
59
|
+
id: uuid(),
|
|
60
|
+
quoteOrRate: 'quote',
|
|
61
|
+
receiveAddress: receiveAddress ?? takerAddress,
|
|
62
|
+
affiliateBps,
|
|
63
|
+
slippageTolerancePercentageDecimal,
|
|
64
|
+
rate,
|
|
65
|
+
swapperName: SwapperName.Bebop,
|
|
66
|
+
steps: [
|
|
67
|
+
{
|
|
68
|
+
estimatedExecutionTimeMs: 0,
|
|
69
|
+
allowanceContract: '0x0',
|
|
70
|
+
buyAsset,
|
|
71
|
+
sellAsset,
|
|
72
|
+
accountNumber,
|
|
73
|
+
rate,
|
|
74
|
+
feeData: {
|
|
75
|
+
protocolFees: {},
|
|
76
|
+
networkFeeCryptoBaseUnit,
|
|
77
|
+
},
|
|
78
|
+
buyAmountBeforeFeesCryptoBaseUnit,
|
|
79
|
+
buyAmountAfterFeesCryptoBaseUnit,
|
|
80
|
+
sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
81
|
+
source: SwapperName.Bebop,
|
|
82
|
+
bebopSolanaSerializedTx: bebopQuoteResponse.solana_tx,
|
|
83
|
+
bebopQuoteId: bebopQuoteResponse.quoteId,
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
});
|
|
87
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { AssetsByIdPartial } from '@shapeshiftoss/types';
|
|
2
|
+
import type { Result } from '@sniptt/monads';
|
|
3
|
+
import type { GetSolanaTradeRateInput, SwapErrorRight, TradeRate } from '../../../types.js';
|
|
4
|
+
export declare function getBebopSolanaTradeRate(input: GetSolanaTradeRateInput, _assetsById: AssetsByIdPartial, apiKey: string): Promise<Result<TradeRate, SwapErrorRight>>;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { Err, Ok } from '@sniptt/monads';
|
|
2
|
+
import { v4 as uuid } from 'uuid';
|
|
3
|
+
import { getDefaultSlippageDecimalPercentageForSwapper } from '../../../constants.js';
|
|
4
|
+
import { SwapperName, TradeQuoteError } from '../../../types.js';
|
|
5
|
+
import { makeSwapErrorRight } from '../../../utils.js';
|
|
6
|
+
import { fetchBebopSolanaPrice } from '../utils/fetchFromBebop.js';
|
|
7
|
+
import { assertValidTrade, calculateRate, isBebopSolanaTxSafe } from '../utils/helpers/helpers.js';
|
|
8
|
+
export async function getBebopSolanaTradeRate(input, _assetsById, apiKey) {
|
|
9
|
+
const { sellAsset, buyAsset, accountNumber, receiveAddress, affiliateBps, sellAmountIncludingProtocolFeesCryptoBaseUnit, } = input;
|
|
10
|
+
const assertion = assertValidTrade({ buyAsset, sellAsset });
|
|
11
|
+
if (assertion.isErr())
|
|
12
|
+
return Err(assertion.unwrapErr());
|
|
13
|
+
const slippageTolerancePercentageDecimal = input.slippageTolerancePercentageDecimal ??
|
|
14
|
+
getDefaultSlippageDecimalPercentageForSwapper(SwapperName.Bebop);
|
|
15
|
+
const maybeBebopPriceResponse = await fetchBebopSolanaPrice({
|
|
16
|
+
buyAsset,
|
|
17
|
+
sellAsset,
|
|
18
|
+
sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
19
|
+
receiveAddress,
|
|
20
|
+
affiliateBps,
|
|
21
|
+
apiKey,
|
|
22
|
+
});
|
|
23
|
+
if (maybeBebopPriceResponse.isErr())
|
|
24
|
+
return Err(maybeBebopPriceResponse.unwrapErr());
|
|
25
|
+
const bebopPriceResponse = maybeBebopPriceResponse.unwrap();
|
|
26
|
+
const sellTokenAddress = Object.keys(bebopPriceResponse.sellTokens)[0];
|
|
27
|
+
const buyTokenAddress = Object.keys(bebopPriceResponse.buyTokens)[0];
|
|
28
|
+
if (!sellTokenAddress || !buyTokenAddress) {
|
|
29
|
+
return Err(makeSwapErrorRight({
|
|
30
|
+
message: 'Invalid token addresses in response',
|
|
31
|
+
code: TradeQuoteError.InvalidResponse,
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
34
|
+
if (bebopPriceResponse.solana_tx) {
|
|
35
|
+
if (!receiveAddress) {
|
|
36
|
+
return Err(makeSwapErrorRight({
|
|
37
|
+
message: 'Cannot validate Bebop Solana tx without a taker address',
|
|
38
|
+
code: TradeQuoteError.NoRouteFound,
|
|
39
|
+
}));
|
|
40
|
+
}
|
|
41
|
+
if (!isBebopSolanaTxSafe(bebopPriceResponse.solana_tx, receiveAddress)) {
|
|
42
|
+
return Err(makeSwapErrorRight({
|
|
43
|
+
message: 'Bebop signer index mismatch - taker not at expected position',
|
|
44
|
+
code: TradeQuoteError.NoRouteFound,
|
|
45
|
+
}));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const sellAmount = bebopPriceResponse.sellTokens[sellTokenAddress].amount;
|
|
49
|
+
const buyAmount = bebopPriceResponse.buyTokens[buyTokenAddress].amount;
|
|
50
|
+
const rate = calculateRate({ buyAmount, sellAmount, buyAsset, sellAsset });
|
|
51
|
+
const buyTokenData = bebopPriceResponse.buyTokens[buyTokenAddress];
|
|
52
|
+
const buyAmountBeforeFeesCryptoBaseUnit = buyTokenData.amountBeforeFee || buyAmount;
|
|
53
|
+
const buyAmountAfterFeesCryptoBaseUnit = buyAmount;
|
|
54
|
+
// Bebop Solana is gasless - Bebop pays the network fees via co-signing
|
|
55
|
+
const networkFeeCryptoBaseUnit = '0';
|
|
56
|
+
return Ok({
|
|
57
|
+
id: uuid(),
|
|
58
|
+
quoteOrRate: 'rate',
|
|
59
|
+
accountNumber: undefined,
|
|
60
|
+
receiveAddress,
|
|
61
|
+
affiliateBps,
|
|
62
|
+
slippageTolerancePercentageDecimal,
|
|
63
|
+
rate,
|
|
64
|
+
swapperName: SwapperName.Bebop,
|
|
65
|
+
steps: [
|
|
66
|
+
{
|
|
67
|
+
estimatedExecutionTimeMs: 0,
|
|
68
|
+
allowanceContract: '0x0',
|
|
69
|
+
buyAsset,
|
|
70
|
+
sellAsset,
|
|
71
|
+
accountNumber,
|
|
72
|
+
rate,
|
|
73
|
+
feeData: {
|
|
74
|
+
protocolFees: {},
|
|
75
|
+
networkFeeCryptoBaseUnit,
|
|
76
|
+
},
|
|
77
|
+
buyAmountBeforeFeesCryptoBaseUnit,
|
|
78
|
+
buyAmountAfterFeesCryptoBaseUnit,
|
|
79
|
+
sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
80
|
+
source: SwapperName.Bebop,
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
});
|
|
84
|
+
}
|
|
@@ -6,6 +6,7 @@ import { isAddress } from 'viem';
|
|
|
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 { BEBOP_DUMMY_ADDRESS } from '../types.js';
|
|
11
12
|
import { fetchBebopQuote } from '../utils/fetchFromBebop.js';
|
|
@@ -99,6 +100,15 @@ export async function getBebopTradeQuote(input, assertGetEvmChainAdapter, _asset
|
|
|
99
100
|
sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
100
101
|
source: SwapperName.Bebop,
|
|
101
102
|
bebopTransactionMetadata: transactionMetadata,
|
|
103
|
+
affiliateFee: buildAffiliateFee({
|
|
104
|
+
strategy: 'buy_asset',
|
|
105
|
+
affiliateBps,
|
|
106
|
+
sellAsset,
|
|
107
|
+
buyAsset,
|
|
108
|
+
sellAmountCryptoBaseUnit: sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
109
|
+
buyAmountCryptoBaseUnit: buyAmountAfterFeesCryptoBaseUnit,
|
|
110
|
+
isEstimate: true,
|
|
111
|
+
}),
|
|
102
112
|
},
|
|
103
113
|
],
|
|
104
114
|
});
|
|
@@ -6,6 +6,7 @@ import { isAddress } from 'viem';
|
|
|
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 { fetchBebopPrice } from '../utils/fetchFromBebop.js';
|
|
11
12
|
import { assertValidTrade, calculateRate } from '../utils/helpers/helpers.js';
|
|
@@ -82,6 +83,15 @@ export async function getBebopTradeRate(input, assertGetEvmChainAdapter, _assets
|
|
|
82
83
|
buyAmountAfterFeesCryptoBaseUnit,
|
|
83
84
|
sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
84
85
|
source: SwapperName.Bebop,
|
|
86
|
+
affiliateFee: buildAffiliateFee({
|
|
87
|
+
strategy: 'buy_asset',
|
|
88
|
+
affiliateBps,
|
|
89
|
+
sellAsset,
|
|
90
|
+
buyAsset,
|
|
91
|
+
sellAmountCryptoBaseUnit: sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
92
|
+
buyAmountCryptoBaseUnit: buyAmountAfterFeesCryptoBaseUnit,
|
|
93
|
+
isEstimate: true,
|
|
94
|
+
}),
|
|
85
95
|
},
|
|
86
96
|
],
|
|
87
97
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { KnownChainIds } from '@shapeshiftoss/types';
|
|
2
2
|
import type { Address, Hex } from 'viem';
|
|
3
|
-
export declare const
|
|
3
|
+
export declare const bebopSupportedEvmChainIds: readonly [KnownChainIds.EthereumMainnet, KnownChainIds.PolygonMainnet, KnownChainIds.ArbitrumMainnet, KnownChainIds.BaseMainnet, KnownChainIds.AvalancheMainnet, KnownChainIds.OptimismMainnet, KnownChainIds.BnbSmartChainMainnet];
|
|
4
|
+
export declare const bebopSupportedChainIds: readonly [KnownChainIds.EthereumMainnet, KnownChainIds.PolygonMainnet, KnownChainIds.ArbitrumMainnet, KnownChainIds.BaseMainnet, KnownChainIds.AvalancheMainnet, KnownChainIds.OptimismMainnet, KnownChainIds.BnbSmartChainMainnet, KnownChainIds.SolanaMainnet];
|
|
4
5
|
export type BebopSupportedChainId = (typeof bebopSupportedChainIds)[number];
|
|
5
6
|
export type BebopQuoteRoute = {
|
|
6
7
|
type: string;
|
|
@@ -87,3 +88,50 @@ export type BebopQuoteResponse = {
|
|
|
87
88
|
export declare const chainIdToBebopChain: Record<BebopSupportedChainId, string>;
|
|
88
89
|
export declare const BEBOP_NATIVE_MARKER = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
|
|
89
90
|
export declare const BEBOP_DUMMY_ADDRESS: `0x${string}`;
|
|
91
|
+
export declare const BEBOP_SOLANA_DUMMY_ADDRESS = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
|
|
92
|
+
export type BebopSolanaQuoteResponse = {
|
|
93
|
+
requestId: string;
|
|
94
|
+
type: string;
|
|
95
|
+
status: 'QUOTE_SUCCESS' | 'QUOTE_INDIC_ROUTE';
|
|
96
|
+
quoteId: string;
|
|
97
|
+
chainId: number;
|
|
98
|
+
approvalType: string;
|
|
99
|
+
nativeToken: string;
|
|
100
|
+
taker: string;
|
|
101
|
+
receiver: string;
|
|
102
|
+
expiry: number;
|
|
103
|
+
slippage: number;
|
|
104
|
+
gasFee: {
|
|
105
|
+
native: string;
|
|
106
|
+
usd: number;
|
|
107
|
+
};
|
|
108
|
+
buyTokens: Record<string, {
|
|
109
|
+
amount: string;
|
|
110
|
+
decimals: number;
|
|
111
|
+
priceUsd: number;
|
|
112
|
+
symbol: string;
|
|
113
|
+
minimumAmount: string;
|
|
114
|
+
price: number;
|
|
115
|
+
priceBeforeFee: number;
|
|
116
|
+
amountBeforeFee: string;
|
|
117
|
+
deltaFromExpected: number;
|
|
118
|
+
}>;
|
|
119
|
+
sellTokens: Record<string, {
|
|
120
|
+
amount: string;
|
|
121
|
+
decimals: number;
|
|
122
|
+
priceUsd: number;
|
|
123
|
+
symbol: string;
|
|
124
|
+
price: number;
|
|
125
|
+
priceBeforeFee: number;
|
|
126
|
+
}>;
|
|
127
|
+
settlementAddress: string;
|
|
128
|
+
approvalTarget: string;
|
|
129
|
+
requiredSignatures: string[];
|
|
130
|
+
priceImpact: number;
|
|
131
|
+
warnings: string[];
|
|
132
|
+
solana_tx: string;
|
|
133
|
+
blockhash: string;
|
|
134
|
+
makers: string[];
|
|
135
|
+
partnerFee?: Record<string, string>;
|
|
136
|
+
protocolFee?: Record<string, string>;
|
|
137
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { KnownChainIds } from '@shapeshiftoss/types';
|
|
2
|
-
export const
|
|
2
|
+
export const bebopSupportedEvmChainIds = [
|
|
3
3
|
KnownChainIds.EthereumMainnet,
|
|
4
4
|
KnownChainIds.PolygonMainnet,
|
|
5
5
|
KnownChainIds.ArbitrumMainnet,
|
|
@@ -8,6 +8,10 @@ export const bebopSupportedChainIds = [
|
|
|
8
8
|
KnownChainIds.OptimismMainnet,
|
|
9
9
|
KnownChainIds.BnbSmartChainMainnet,
|
|
10
10
|
];
|
|
11
|
+
export const bebopSupportedChainIds = [
|
|
12
|
+
...bebopSupportedEvmChainIds,
|
|
13
|
+
KnownChainIds.SolanaMainnet,
|
|
14
|
+
];
|
|
11
15
|
export const chainIdToBebopChain = {
|
|
12
16
|
[KnownChainIds.EthereumMainnet]: 'ethereum',
|
|
13
17
|
[KnownChainIds.PolygonMainnet]: 'polygon',
|
|
@@ -16,9 +20,12 @@ export const chainIdToBebopChain = {
|
|
|
16
20
|
[KnownChainIds.AvalancheMainnet]: 'avalanche',
|
|
17
21
|
[KnownChainIds.OptimismMainnet]: 'optimism',
|
|
18
22
|
[KnownChainIds.BnbSmartChainMainnet]: 'bsc',
|
|
23
|
+
[KnownChainIds.SolanaMainnet]: 'solana',
|
|
19
24
|
};
|
|
20
25
|
export const BEBOP_NATIVE_MARKER = '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE';
|
|
21
26
|
// Dummy address used for rate quotes when no wallet is connected.
|
|
22
27
|
// This is Vitalik's address, same as what Bebop's own UI uses for price-only quotes.
|
|
23
28
|
// MUST NEVER be used for executable quote transactions.
|
|
24
29
|
export const BEBOP_DUMMY_ADDRESS = '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045';
|
|
30
|
+
// Solana dummy address for rate quotes - uses the Token Program address which cannot be a real wallet
|
|
31
|
+
export const BEBOP_SOLANA_DUMMY_ADDRESS = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA';
|