@shapeshiftoss/swapper 20.4.0 → 20.6.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/dist/cjs/.tsbuildinfo +1 -1
- package/dist/cjs/constants.js +6 -0
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/swappers/AcrossSwapper/utils/getAcrossStepData.js +7 -15
- package/dist/cjs/swappers/AvnuSwapper/endpoints.js +17 -12
- package/dist/cjs/swappers/BebopSwapper/utils/getBebopStepData.js +17 -22
- package/dist/cjs/swappers/ButterSwap/swapperApi/getTradeQuote.test.js +1 -0
- package/dist/cjs/swappers/ButterSwap/swapperApi/getTradeRate.test.js +1 -0
- package/dist/cjs/swappers/ButterSwap/utils/getButterSwapStepData.js +3 -4
- package/dist/cjs/swappers/ButterSwap/utils/getButterSwapStepData.test.js +2 -2
- package/dist/cjs/swappers/CetusSwapper/endpoints.js +2 -3
- package/dist/cjs/swappers/CetusSwapper/swapperApi/getCetusStepData.js +13 -8
- package/dist/cjs/swappers/CetusSwapper/swapperApi/getCetusTradeContext.js +1 -2
- package/dist/cjs/swappers/CetusSwapper/utils/constants.d.ts +0 -1
- package/dist/cjs/swappers/CetusSwapper/utils/constants.js +1 -2
- package/dist/cjs/swappers/CetusSwapper/utils/helpers.d.ts +3 -3
- package/dist/cjs/swappers/CetusSwapper/utils/helpers.js +6 -17
- package/dist/cjs/swappers/DebridgeSwapper/utils/getDebridgeStepData.d.ts +0 -1
- package/dist/cjs/swappers/DebridgeSwapper/utils/getDebridgeStepData.js +9 -16
- package/dist/cjs/swappers/DebridgeSwapper/utils/getDebridgeTradeContext.js +0 -3
- package/dist/cjs/swappers/FyndSwapper/utils/getFyndStepData.js +5 -7
- package/dist/cjs/swappers/KyberSwapper/KyberSwapper.d.ts +2 -0
- package/dist/cjs/swappers/KyberSwapper/KyberSwapper.js +5 -0
- package/dist/cjs/swappers/KyberSwapper/endpoints.d.ts +2 -0
- package/dist/cjs/swappers/KyberSwapper/endpoints.js +14 -0
- package/dist/cjs/swappers/KyberSwapper/index.d.ts +2 -0
- package/dist/cjs/swappers/KyberSwapper/index.js +7 -0
- package/dist/cjs/swappers/KyberSwapper/swapperApi/getKyberTradeQuote.d.ts +4 -0
- package/dist/cjs/swappers/KyberSwapper/swapperApi/getKyberTradeQuote.js +64 -0
- package/dist/cjs/swappers/KyberSwapper/swapperApi/getKyberTradeRate.d.ts +4 -0
- package/dist/cjs/swappers/KyberSwapper/swapperApi/getKyberTradeRate.js +31 -0
- package/dist/cjs/swappers/KyberSwapper/types.d.ts +62 -0
- package/dist/cjs/swappers/KyberSwapper/types.js +2 -0
- package/dist/cjs/swappers/KyberSwapper/utils/constants.d.ts +22 -0
- package/dist/cjs/swappers/KyberSwapper/utils/constants.js +25 -0
- package/dist/cjs/swappers/KyberSwapper/utils/fetchFromKyber.d.ts +23 -0
- package/dist/cjs/swappers/KyberSwapper/utils/fetchFromKyber.js +38 -0
- package/dist/cjs/swappers/KyberSwapper/utils/getKyberStepData.d.ts +27 -0
- package/dist/cjs/swappers/KyberSwapper/utils/getKyberStepData.js +47 -0
- package/dist/cjs/swappers/KyberSwapper/utils/getKyberStepData.test.d.ts +1 -0
- package/dist/cjs/swappers/KyberSwapper/utils/getKyberStepData.test.js +92 -0
- package/dist/cjs/swappers/KyberSwapper/utils/getKyberTradeContext.d.ts +20 -0
- package/dist/cjs/swappers/KyberSwapper/utils/getKyberTradeContext.js +63 -0
- package/dist/cjs/swappers/KyberSwapper/utils/helpers.d.ts +27 -0
- package/dist/cjs/swappers/KyberSwapper/utils/helpers.js +172 -0
- package/dist/cjs/swappers/KyberSwapper/utils/helpers.test.d.ts +1 -0
- package/dist/cjs/swappers/KyberSwapper/utils/helpers.test.js +110 -0
- package/dist/cjs/swappers/KyberSwapper/utils/kyberService.d.ts +5 -0
- package/dist/cjs/swappers/KyberSwapper/utils/kyberService.js +9 -0
- package/dist/cjs/swappers/NearIntentsSwapper/NearIntentsSwapper.js +1 -0
- package/dist/cjs/swappers/NearIntentsSwapper/endpoints.js +13 -14
- package/dist/cjs/swappers/NearIntentsSwapper/swapperApi/getTradeRate.js +1 -1
- package/dist/cjs/swappers/NearIntentsSwapper/types.d.ts +4 -4
- package/dist/cjs/swappers/NearIntentsSwapper/types.js +2 -0
- package/dist/cjs/swappers/NearIntentsSwapper/utils/getNearIntentsStepData.js +28 -0
- package/dist/cjs/swappers/NearIntentsSwapper/utils/helpers.js +2 -2
- package/dist/cjs/swappers/PortalsSwapper/utils/getPortalsStepData.js +36 -55
- package/dist/cjs/swappers/PortalsSwapper/utils/getPortalsStepData.test.js +2 -2
- package/dist/cjs/swappers/RelaySwapper/constant.js +1 -0
- package/dist/cjs/swappers/RelaySwapper/utils/getRelayStepData.js +7 -15
- package/dist/cjs/swappers/RelaySwapper/utils/relayTokenToAssetId.js +5 -0
- package/dist/cjs/swappers/ThorchainSwapper/generated/generatedThorLongtailTokens.json +1 -0
- package/dist/cjs/swappers/ThorchainSwapper/getTradeQuote/getTradeQuote.test.js +2 -2
- package/dist/cjs/swappers/ZrxSwapper/getZrxTradeQuote/getZrxTradeQuote.js +3 -1
- package/dist/cjs/swappers/ZrxSwapper/types.d.ts +1 -1
- package/dist/cjs/swappers/ZrxSwapper/types.js +1 -0
- package/dist/cjs/swappers/ZrxSwapper/utils/constants.js +1 -0
- package/dist/cjs/swappers/ZrxSwapper/utils/getZrxStepData.d.ts +3 -1
- package/dist/cjs/swappers/ZrxSwapper/utils/getZrxStepData.js +29 -10
- package/dist/cjs/swappers/ZrxSwapper/utils/helpers.d.ts +1 -1
- package/dist/cjs/swappers/ZrxSwapper/utils/helpers.js +5 -0
- package/dist/cjs/types.d.ts +36 -8
- package/dist/cjs/types.js +1 -0
- package/dist/cjs/utils/aptos/constants.d.ts +2 -0
- package/dist/cjs/utils/aptos/constants.js +7 -0
- package/dist/cjs/utils/aptos/getAptosTransactionFees.d.ts +2 -0
- package/dist/cjs/utils/aptos/getAptosTransactionFees.js +13 -0
- package/dist/cjs/utils/aptos/getUnsignedAptosTransaction.d.ts +2 -0
- package/dist/cjs/utils/aptos/getUnsignedAptosTransaction.js +16 -0
- package/dist/cjs/utils/aptos/index.d.ts +3 -0
- package/dist/cjs/utils/aptos/index.js +19 -0
- package/dist/cjs/utils/evm/getEvmNetworkFeeCryptoBaseUnit.d.ts +19 -6
- package/dist/cjs/utils/evm/getEvmNetworkFeeCryptoBaseUnit.js +45 -35
- package/dist/cjs/utils/evm/getEvmNetworkFeeCryptoBaseUnit.test.d.ts +1 -0
- package/dist/cjs/utils/evm/getEvmNetworkFeeCryptoBaseUnit.test.js +103 -0
- package/dist/cjs/utils/evm/stateOverride.d.ts +3 -0
- package/dist/cjs/utils/evm/stateOverride.js +10 -4
- package/dist/cjs/utils/helpers.js +2 -0
- package/dist/cjs/utils/helpers.test.js +2 -0
- package/dist/cjs/utils/index.d.ts +3 -2
- package/dist/cjs/utils/index.js +11 -27
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/constants.js +6 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/swappers/AcrossSwapper/utils/getAcrossStepData.js +8 -16
- package/dist/esm/swappers/AvnuSwapper/endpoints.js +18 -13
- package/dist/esm/swappers/BebopSwapper/utils/getBebopStepData.js +18 -23
- package/dist/esm/swappers/ButterSwap/swapperApi/getTradeQuote.test.js +1 -0
- package/dist/esm/swappers/ButterSwap/swapperApi/getTradeRate.test.js +1 -0
- package/dist/esm/swappers/ButterSwap/utils/getButterSwapStepData.js +4 -5
- package/dist/esm/swappers/ButterSwap/utils/getButterSwapStepData.test.js +2 -2
- package/dist/esm/swappers/CetusSwapper/endpoints.js +3 -4
- package/dist/esm/swappers/CetusSwapper/swapperApi/getCetusStepData.js +13 -8
- package/dist/esm/swappers/CetusSwapper/swapperApi/getCetusTradeContext.js +2 -3
- package/dist/esm/swappers/CetusSwapper/utils/constants.d.ts +0 -1
- package/dist/esm/swappers/CetusSwapper/utils/constants.js +0 -1
- package/dist/esm/swappers/CetusSwapper/utils/helpers.d.ts +3 -3
- package/dist/esm/swappers/CetusSwapper/utils/helpers.js +4 -15
- package/dist/esm/swappers/DebridgeSwapper/utils/getDebridgeStepData.d.ts +0 -1
- package/dist/esm/swappers/DebridgeSwapper/utils/getDebridgeStepData.js +9 -16
- package/dist/esm/swappers/DebridgeSwapper/utils/getDebridgeTradeContext.js +0 -3
- package/dist/esm/swappers/FyndSwapper/utils/getFyndStepData.js +6 -8
- package/dist/esm/swappers/KyberSwapper/KyberSwapper.d.ts +2 -0
- package/dist/esm/swappers/KyberSwapper/KyberSwapper.js +2 -0
- package/dist/esm/swappers/KyberSwapper/endpoints.d.ts +2 -0
- package/dist/esm/swappers/KyberSwapper/endpoints.js +11 -0
- package/dist/esm/swappers/KyberSwapper/index.d.ts +2 -0
- package/dist/esm/swappers/KyberSwapper/index.js +2 -0
- package/dist/esm/swappers/KyberSwapper/swapperApi/getKyberTradeQuote.d.ts +4 -0
- package/dist/esm/swappers/KyberSwapper/swapperApi/getKyberTradeQuote.js +60 -0
- package/dist/esm/swappers/KyberSwapper/swapperApi/getKyberTradeRate.d.ts +4 -0
- package/dist/esm/swappers/KyberSwapper/swapperApi/getKyberTradeRate.js +27 -0
- package/dist/esm/swappers/KyberSwapper/types.d.ts +62 -0
- package/dist/esm/swappers/KyberSwapper/types.js +1 -0
- package/dist/esm/swappers/KyberSwapper/utils/constants.d.ts +22 -0
- package/dist/esm/swappers/KyberSwapper/utils/constants.js +22 -0
- package/dist/esm/swappers/KyberSwapper/utils/fetchFromKyber.d.ts +23 -0
- package/dist/esm/swappers/KyberSwapper/utils/fetchFromKyber.js +33 -0
- package/dist/esm/swappers/KyberSwapper/utils/getKyberStepData.d.ts +27 -0
- package/dist/esm/swappers/KyberSwapper/utils/getKyberStepData.js +43 -0
- package/dist/esm/swappers/KyberSwapper/utils/getKyberStepData.test.d.ts +1 -0
- package/dist/esm/swappers/KyberSwapper/utils/getKyberStepData.test.js +90 -0
- package/dist/esm/swappers/KyberSwapper/utils/getKyberTradeContext.d.ts +20 -0
- package/dist/esm/swappers/KyberSwapper/utils/getKyberTradeContext.js +59 -0
- package/dist/esm/swappers/KyberSwapper/utils/helpers.d.ts +27 -0
- package/dist/esm/swappers/KyberSwapper/utils/helpers.js +158 -0
- package/dist/esm/swappers/KyberSwapper/utils/helpers.test.d.ts +1 -0
- package/dist/esm/swappers/KyberSwapper/utils/helpers.test.js +108 -0
- package/dist/esm/swappers/KyberSwapper/utils/kyberService.d.ts +5 -0
- package/dist/esm/swappers/KyberSwapper/utils/kyberService.js +3 -0
- package/dist/esm/swappers/NearIntentsSwapper/NearIntentsSwapper.js +2 -1
- package/dist/esm/swappers/NearIntentsSwapper/endpoints.js +13 -14
- package/dist/esm/swappers/NearIntentsSwapper/swapperApi/getTradeRate.js +1 -1
- package/dist/esm/swappers/NearIntentsSwapper/types.d.ts +4 -4
- package/dist/esm/swappers/NearIntentsSwapper/types.js +2 -0
- package/dist/esm/swappers/NearIntentsSwapper/utils/getNearIntentsStepData.js +29 -1
- package/dist/esm/swappers/NearIntentsSwapper/utils/helpers.js +2 -2
- package/dist/esm/swappers/PortalsSwapper/utils/getPortalsStepData.js +34 -53
- package/dist/esm/swappers/PortalsSwapper/utils/getPortalsStepData.test.js +2 -2
- package/dist/esm/swappers/RelaySwapper/constant.js +2 -1
- package/dist/esm/swappers/RelaySwapper/utils/getRelayStepData.js +9 -17
- package/dist/esm/swappers/RelaySwapper/utils/relayTokenToAssetId.js +5 -0
- package/dist/esm/swappers/ThorchainSwapper/generated/generatedThorLongtailTokens.json +1 -0
- package/dist/esm/swappers/ThorchainSwapper/getTradeQuote/getTradeQuote.test.js +2 -2
- package/dist/esm/swappers/ZrxSwapper/getZrxTradeQuote/getZrxTradeQuote.js +3 -1
- package/dist/esm/swappers/ZrxSwapper/types.d.ts +1 -1
- package/dist/esm/swappers/ZrxSwapper/types.js +1 -0
- package/dist/esm/swappers/ZrxSwapper/utils/constants.js +1 -0
- package/dist/esm/swappers/ZrxSwapper/utils/getZrxStepData.d.ts +3 -1
- package/dist/esm/swappers/ZrxSwapper/utils/getZrxStepData.js +31 -12
- package/dist/esm/swappers/ZrxSwapper/utils/helpers.d.ts +1 -1
- package/dist/esm/swappers/ZrxSwapper/utils/helpers.js +5 -0
- package/dist/esm/types.d.ts +36 -8
- package/dist/esm/types.js +1 -0
- package/dist/esm/utils/aptos/constants.d.ts +2 -0
- package/dist/esm/utils/aptos/constants.js +4 -0
- package/dist/esm/utils/aptos/getAptosTransactionFees.d.ts +2 -0
- package/dist/esm/utils/aptos/getAptosTransactionFees.js +9 -0
- package/dist/esm/utils/aptos/getUnsignedAptosTransaction.d.ts +2 -0
- package/dist/esm/utils/aptos/getUnsignedAptosTransaction.js +12 -0
- package/dist/esm/utils/aptos/index.d.ts +3 -0
- package/dist/esm/utils/aptos/index.js +3 -0
- package/dist/esm/utils/evm/getEvmNetworkFeeCryptoBaseUnit.d.ts +19 -6
- package/dist/esm/utils/evm/getEvmNetworkFeeCryptoBaseUnit.js +42 -35
- package/dist/esm/utils/evm/getEvmNetworkFeeCryptoBaseUnit.test.d.ts +1 -0
- package/dist/esm/utils/evm/getEvmNetworkFeeCryptoBaseUnit.test.js +101 -0
- package/dist/esm/utils/evm/stateOverride.d.ts +3 -0
- package/dist/esm/utils/evm/stateOverride.js +8 -3
- package/dist/esm/utils/helpers.js +3 -1
- package/dist/esm/utils/helpers.test.js +2 -0
- package/dist/esm/utils/index.d.ts +3 -2
- package/dist/esm/utils/index.js +9 -26
- package/package.json +10 -11
package/dist/esm/constants.js
CHANGED
|
@@ -10,6 +10,7 @@ import { chainflipApi, chainflipSwapper } from './swappers/ChainflipSwapper/inde
|
|
|
10
10
|
import { cowApi, cowSwapper } from './swappers/CowSwapper/index.js';
|
|
11
11
|
import { debridgeApi, debridgeSwapper } from './swappers/DebridgeSwapper/index.js';
|
|
12
12
|
import { fyndApi, fyndSwapper } from './swappers/FyndSwapper/index.js';
|
|
13
|
+
import { kyberApi, kyberSwapper } from './swappers/KyberSwapper/index.js';
|
|
13
14
|
import { mayachainApi, mayachainSwapper } from './swappers/MayachainSwapper/index.js';
|
|
14
15
|
import { nearIntentsApi, nearIntentsSwapper } from './swappers/NearIntentsSwapper/index.js';
|
|
15
16
|
import { portalsApi, portalsSwapper } from './swappers/PortalsSwapper/index.js';
|
|
@@ -109,6 +110,10 @@ export const swappers = {
|
|
|
109
110
|
...fyndSwapper,
|
|
110
111
|
...fyndApi,
|
|
111
112
|
},
|
|
113
|
+
[SwapperName.KyberSwap]: {
|
|
114
|
+
...kyberSwapper,
|
|
115
|
+
...kyberApi,
|
|
116
|
+
},
|
|
112
117
|
[SwapperName.Test]: undefined,
|
|
113
118
|
};
|
|
114
119
|
const DEFAULT_SLIPPAGE_DECIMAL_PERCENTAGE = '0.002';
|
|
@@ -137,6 +142,7 @@ export const getDefaultSlippageDecimalPercentageForSwapper = (swapperName) => {
|
|
|
137
142
|
case SwapperName.Zrx:
|
|
138
143
|
case SwapperName.Bebop:
|
|
139
144
|
case SwapperName.Fynd:
|
|
145
|
+
case SwapperName.KyberSwap:
|
|
140
146
|
case SwapperName.Test:
|
|
141
147
|
return DEFAULT_SLIPPAGE_DECIMAL_PERCENTAGE;
|
|
142
148
|
case SwapperName.CowSwap:
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export * from './swappers/SunioSwapper/index.js';
|
|
|
16
16
|
export * from './swappers/CowSwapper/index.js';
|
|
17
17
|
export * from './swappers/DebridgeSwapper/index.js';
|
|
18
18
|
export * from './swappers/FyndSwapper/index.js';
|
|
19
|
+
export * from './swappers/KyberSwapper/index.js';
|
|
19
20
|
export * from './swappers/PortalsSwapper/index.js';
|
|
20
21
|
export * from './swappers/ThorchainSwapper/index.js';
|
|
21
22
|
export * from './swappers/MayachainSwapper/index.js';
|
package/dist/esm/index.js
CHANGED
|
@@ -16,6 +16,7 @@ export * from './swappers/SunioSwapper/index.js';
|
|
|
16
16
|
export * from './swappers/CowSwapper/index.js';
|
|
17
17
|
export * from './swappers/DebridgeSwapper/index.js';
|
|
18
18
|
export * from './swappers/FyndSwapper/index.js';
|
|
19
|
+
export * from './swappers/KyberSwapper/index.js';
|
|
19
20
|
export * from './swappers/PortalsSwapper/index.js';
|
|
20
21
|
export * from './swappers/ThorchainSwapper/index.js';
|
|
21
22
|
export * from './swappers/MayachainSwapper/index.js';
|
|
@@ -4,7 +4,7 @@ import { Err, Ok } from '@sniptt/monads';
|
|
|
4
4
|
import { AddressLookupTableAccount, PublicKey, TransactionMessage, VersionedTransaction, } from '@solana/web3.js';
|
|
5
5
|
import { TradeQuoteError } from '../../../types.js';
|
|
6
6
|
import { makeNetworkFeeEstimationFailedErr, makeSwapErrorRight, makeTradeStepBuildFailedErr, } from '../../../utils/index.js';
|
|
7
|
-
import { getEvmNetworkFeeCryptoBaseUnit } from '../../../utils/evm/index.js';
|
|
7
|
+
import { getEvmNetworkFeeCryptoBaseUnit, getEvmRateNetworkFeeCryptoBaseUnit, } from '../../../utils/evm/index.js';
|
|
8
8
|
import { getSolanaNetworkFeeCryptoBaseUnit } from '../../../utils/solana/index.js';
|
|
9
9
|
export async function getAcrossStepData(args) {
|
|
10
10
|
const { swapTx, sellAsset, sellAmountCryptoBaseUnit, spenderAddress, from, type, input, fallbackNetworkFeeCryptoBaseUnit, deps, } = args;
|
|
@@ -18,7 +18,6 @@ export async function getAcrossStepData(args) {
|
|
|
18
18
|
to: swapTx.to,
|
|
19
19
|
data: swapTx.data,
|
|
20
20
|
value: swapTx.value ?? '0',
|
|
21
|
-
gasLimit: swapTx.gas,
|
|
22
21
|
};
|
|
23
22
|
const stateOverride = {
|
|
24
23
|
sellAsset,
|
|
@@ -26,20 +25,12 @@ export async function getAcrossStepData(args) {
|
|
|
26
25
|
spenderAddress,
|
|
27
26
|
};
|
|
28
27
|
if (type === 'rate') {
|
|
29
|
-
const networkFeeCryptoBaseUnit = await (
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
supportsEIP1559,
|
|
36
|
-
stateOverride,
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
catch {
|
|
40
|
-
return fallbackNetworkFeeCryptoBaseUnit;
|
|
41
|
-
}
|
|
42
|
-
})();
|
|
28
|
+
const networkFeeCryptoBaseUnit = await getEvmRateNetworkFeeCryptoBaseUnit({
|
|
29
|
+
adapter,
|
|
30
|
+
supportsEIP1559,
|
|
31
|
+
providerGasLimit: swapTx.gas,
|
|
32
|
+
simulation: { transactionData, from, stateOverride },
|
|
33
|
+
}).catch(() => fallbackNetworkFeeCryptoBaseUnit);
|
|
43
34
|
const stepData = { networkFeeCryptoBaseUnit };
|
|
44
35
|
return Ok(stepData);
|
|
45
36
|
}
|
|
@@ -50,6 +41,7 @@ export async function getAcrossStepData(args) {
|
|
|
50
41
|
from,
|
|
51
42
|
supportsEIP1559,
|
|
52
43
|
stateOverride,
|
|
44
|
+
providerGasLimit: swapTx.gas,
|
|
53
45
|
});
|
|
54
46
|
const stepData = { transactionData, networkFeeCryptoBaseUnit };
|
|
55
47
|
return Ok(stepData);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { quoteToCalls } from '@avnu/avnu-sdk';
|
|
2
2
|
import { toAddressNList } from '@shapeshiftoss/chain-adapters';
|
|
3
|
-
import { CallData, hash, validateAndParseAddress } from 'starknet';
|
|
3
|
+
import { CallData, hash, transaction, validateAndParseAddress } from 'starknet';
|
|
4
4
|
import { checkStarknetSwapStatus, createDefaultStatusResponse, getExecutableTradeStep, getSwapMetadata, isExecutableTradeQuote, } from '../../utils/index.js';
|
|
5
5
|
import { getTradeQuote } from './swapperApi/getTradeQuote.js';
|
|
6
6
|
import { getTradeRate } from './swapperApi/getTradeRate.js';
|
|
@@ -8,7 +8,7 @@ import { toHexString } from './utils/helpers.js';
|
|
|
8
8
|
export const avnuApi = {
|
|
9
9
|
getTradeQuote: (input, deps) => getTradeQuote(input, deps),
|
|
10
10
|
getTradeRate: (input, deps) => getTradeRate(input, deps),
|
|
11
|
-
getUnsignedStarknetTransaction: async ({ stepIndex, tradeQuote, from, slippageTolerancePercentageDecimal, assertGetStarknetChainAdapter, }) => {
|
|
11
|
+
getUnsignedStarknetTransaction: async ({ stepIndex, tradeQuote, from, callsOnly, slippageTolerancePercentageDecimal, assertGetStarknetChainAdapter, }) => {
|
|
12
12
|
if (!isExecutableTradeQuote(tradeQuote))
|
|
13
13
|
throw new Error('Unable to execute a trade rate quote');
|
|
14
14
|
const step = getExecutableTradeStep(tradeQuote, stepIndex);
|
|
@@ -34,19 +34,23 @@ export const avnuApi = {
|
|
|
34
34
|
if (!avnuCalls || avnuCalls.length === 0) {
|
|
35
35
|
throw new Error('No swap calls returned from AVNU - quote may have expired');
|
|
36
36
|
}
|
|
37
|
-
|
|
38
|
-
// Format: [call_array_length, contract1, selector1, calldata_len1, ...calldata1, ...]
|
|
39
|
-
const fullCalldata = [avnuCalls.length.toString()];
|
|
40
|
-
for (const call of avnuCalls) {
|
|
37
|
+
const calls = avnuCalls.map(call => {
|
|
41
38
|
const rawCalldata = call.calldata ?? [];
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
39
|
+
const calldata = Array.isArray(rawCalldata) ? rawCalldata : CallData.compile(rawCalldata);
|
|
40
|
+
return {
|
|
41
|
+
contractAddress: validateAndParseAddress(call.contractAddress),
|
|
42
|
+
entrypoint: call.entrypoint,
|
|
43
|
+
calldata: calldata.map(String),
|
|
44
|
+
};
|
|
45
|
+
});
|
|
46
|
+
if (callsOnly) {
|
|
47
|
+
return {
|
|
48
|
+
addressNList: toAddressNList(adapter.getBip44Params({ accountNumber })),
|
|
49
|
+
txHash: '',
|
|
50
|
+
calls,
|
|
51
|
+
};
|
|
47
52
|
}
|
|
48
|
-
|
|
49
|
-
const formattedCalldata = fullCalldata.map(toHexString);
|
|
53
|
+
const formattedCalldata = transaction.getExecuteCalldata(calls, '1').map(toHexString);
|
|
50
54
|
// Get nonce using adapter method (checks deployment status and returns appropriate nonce)
|
|
51
55
|
const chainIdHex = await adapter.getStarknetProvider().getChainId();
|
|
52
56
|
const nonce = await adapter.getNonce(normalizedFrom);
|
|
@@ -144,6 +148,7 @@ export const avnuApi = {
|
|
|
144
148
|
return {
|
|
145
149
|
addressNList: toAddressNList(adapter.getBip44Params({ accountNumber })),
|
|
146
150
|
txHash,
|
|
151
|
+
calls,
|
|
147
152
|
_txDetails: {
|
|
148
153
|
fromAddress: normalizedFrom,
|
|
149
154
|
calldata: formattedCalldata,
|
|
@@ -3,46 +3,41 @@ import { bnOrZero } from '@shapeshiftoss/utils';
|
|
|
3
3
|
import { Err, Ok } from '@sniptt/monads';
|
|
4
4
|
import { fromHex } from 'viem';
|
|
5
5
|
import { makeNetworkFeeEstimationFailedErr } from '../../../utils/index.js';
|
|
6
|
-
import { getEvmNetworkFeeCryptoBaseUnit } from '../../../utils/evm/index.js';
|
|
6
|
+
import { getEvmNetworkFeeCryptoBaseUnit, getEvmRateNetworkFeeCryptoBaseUnit, } from '../../../utils/evm/index.js';
|
|
7
7
|
export async function getBebopStepData(args) {
|
|
8
8
|
const { tx, spenderAddress, sellAsset, sellAmountCryptoBaseUnit, type, input, from, deps } = args;
|
|
9
9
|
const adapter = deps.assertGetEvmChainAdapter(sellAsset.chainId);
|
|
10
10
|
const supportsEIP1559 = 'supportsEIP1559' in input ? input.supportsEIP1559 : false;
|
|
11
|
-
if (type === 'rate') {
|
|
12
|
-
const networkFeeCryptoBaseUnit = await (async () => {
|
|
13
|
-
try {
|
|
14
|
-
return await getEvmNetworkFeeCryptoBaseUnit({
|
|
15
|
-
adapter,
|
|
16
|
-
supportsEIP1559,
|
|
17
|
-
gasLimit: bnOrZero(tx.gas).toString(),
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
catch {
|
|
21
|
-
return bnOrZero(tx.gas).times(bnOrZero(tx.gasPrice)).toFixed(0);
|
|
22
|
-
}
|
|
23
|
-
})();
|
|
24
|
-
const stepData = { networkFeeCryptoBaseUnit };
|
|
25
|
-
return Ok(stepData);
|
|
26
|
-
}
|
|
27
11
|
const transactionData = {
|
|
28
12
|
type: 'evm',
|
|
29
13
|
chainId: Number(fromChainId(sellAsset.chainId).chainReference),
|
|
30
14
|
to: tx.to,
|
|
31
15
|
data: tx.data,
|
|
32
16
|
value: fromHex(tx.value, 'bigint').toString(),
|
|
33
|
-
gasLimit: tx.gas?.toString(),
|
|
34
17
|
};
|
|
18
|
+
const stateOverride = {
|
|
19
|
+
sellAsset,
|
|
20
|
+
sellAmountCryptoBaseUnit,
|
|
21
|
+
spenderAddress,
|
|
22
|
+
};
|
|
23
|
+
if (type === 'rate') {
|
|
24
|
+
const networkFeeCryptoBaseUnit = await getEvmRateNetworkFeeCryptoBaseUnit({
|
|
25
|
+
adapter,
|
|
26
|
+
supportsEIP1559,
|
|
27
|
+
providerGasLimit: tx.gas?.toString(),
|
|
28
|
+
simulation: { transactionData, from, stateOverride },
|
|
29
|
+
}).catch(() => bnOrZero(tx.gas).times(bnOrZero(tx.gasPrice)).toFixed(0));
|
|
30
|
+
const stepData = { networkFeeCryptoBaseUnit };
|
|
31
|
+
return Ok(stepData);
|
|
32
|
+
}
|
|
35
33
|
try {
|
|
36
34
|
const networkFeeCryptoBaseUnit = await getEvmNetworkFeeCryptoBaseUnit({
|
|
37
35
|
adapter,
|
|
38
36
|
transactionData,
|
|
39
37
|
from,
|
|
40
38
|
supportsEIP1559,
|
|
41
|
-
stateOverride
|
|
42
|
-
|
|
43
|
-
sellAmountCryptoBaseUnit,
|
|
44
|
-
spenderAddress,
|
|
45
|
-
},
|
|
39
|
+
stateOverride,
|
|
40
|
+
providerGasLimit: tx.gas?.toString(),
|
|
46
41
|
});
|
|
47
42
|
const stepData = { transactionData, networkFeeCryptoBaseUnit };
|
|
48
43
|
return Ok(stepData);
|
|
@@ -54,6 +54,7 @@ describe('getTradeQuote', () => {
|
|
|
54
54
|
assertGetNearChainAdapter: () => vi.fn(),
|
|
55
55
|
assertGetStarknetChainAdapter: () => vi.fn(),
|
|
56
56
|
assertGetTonChainAdapter: () => vi.fn(),
|
|
57
|
+
assertGetAptosChainAdapter: () => vi.fn(),
|
|
57
58
|
config: {
|
|
58
59
|
VITE_BUTTERSWAP_CLIENT_ID: 'test',
|
|
59
60
|
},
|
|
@@ -34,6 +34,7 @@ describe('getTradeRate', () => {
|
|
|
34
34
|
assertGetNearChainAdapter: () => vi.fn(),
|
|
35
35
|
assertGetStarknetChainAdapter: () => vi.fn(),
|
|
36
36
|
assertGetTonChainAdapter: () => vi.fn(),
|
|
37
|
+
assertGetAptosChainAdapter: () => vi.fn(),
|
|
37
38
|
config: {
|
|
38
39
|
VITE_BUTTERSWAP_CLIENT_ID: 'test',
|
|
39
40
|
},
|
|
@@ -5,7 +5,7 @@ import { AddressLookupTableAccount, PublicKey, TransactionMessage, VersionedTran
|
|
|
5
5
|
import { fromHex } from 'viem';
|
|
6
6
|
import { TradeQuoteError } from '../../../types.js';
|
|
7
7
|
import { makeNetworkFeeEstimationFailedErr, makeSwapErrorRight, makeTradeStepBuildFailedErr, } from '../../../utils/index.js';
|
|
8
|
-
import { getEvmNetworkFeeCryptoBaseUnit } from '../../../utils/evm/index.js';
|
|
8
|
+
import { getEvmNetworkFeeCryptoBaseUnit, getEvmRateNetworkFeeCryptoBaseUnit, } from '../../../utils/evm/index.js';
|
|
9
9
|
import { getSolanaNetworkFeeCryptoBaseUnit, omitComputeBudgetInstructions, withComputeUnitLimit, } from '../../../utils/solana/index.js';
|
|
10
10
|
import { getTronContractCallFallbackFeeCryptoBaseUnit, getTronContractCallNetworkFeeCryptoBaseUnit, } from '../../../utils/tron/index.js';
|
|
11
11
|
import { BUTTERSWAP_TRON_DEFAULT_BANDWIDTH_BYTES, BUTTERSWAP_TRON_FALLBACK_SWAP_ENERGY, } from './constants.js';
|
|
@@ -25,10 +25,10 @@ export async function getButterSwapStepData(args) {
|
|
|
25
25
|
if (args.type === 'rate') {
|
|
26
26
|
const networkFeeCryptoBaseUnit = await (async () => {
|
|
27
27
|
try {
|
|
28
|
-
return await
|
|
28
|
+
return await getEvmRateNetworkFeeCryptoBaseUnit({
|
|
29
29
|
adapter,
|
|
30
30
|
supportsEIP1559,
|
|
31
|
-
|
|
31
|
+
providerGasLimit: bnOrZero(route.gasEstimatedTarget).toFixed(),
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
34
|
catch {
|
|
@@ -52,13 +52,12 @@ export async function getButterSwapStepData(args) {
|
|
|
52
52
|
supportsEIP1559,
|
|
53
53
|
transactionData,
|
|
54
54
|
from,
|
|
55
|
-
// Butter's gasEstimatedTarget lands short on chain (observed 24% under actual, causing
|
|
56
|
-
// in-flight OOG/SWAP_FAIL reverts) - estimate ourselves instead
|
|
57
55
|
stateOverride: {
|
|
58
56
|
sellAsset,
|
|
59
57
|
sellAmountCryptoBaseUnit,
|
|
60
58
|
spenderAddress,
|
|
61
59
|
},
|
|
60
|
+
providerGasLimit: bnOrZero(route.gasEstimatedTarget).toFixed(),
|
|
62
61
|
});
|
|
63
62
|
const stepData = { transactionData, networkFeeCryptoBaseUnit };
|
|
64
63
|
return Ok(stepData);
|
|
@@ -94,7 +94,7 @@ describe('getButterSwapStepData', () => {
|
|
|
94
94
|
});
|
|
95
95
|
// gasEstimatedTarget 1159118 is ignored - the tx carries the buffered on chain estimate
|
|
96
96
|
expect(actual.unwrap()).toEqual({
|
|
97
|
-
networkFeeCryptoBaseUnit: '
|
|
97
|
+
networkFeeCryptoBaseUnit: '600000000000000',
|
|
98
98
|
transactionData: {
|
|
99
99
|
type: 'evm',
|
|
100
100
|
chainId: 1,
|
|
@@ -121,7 +121,7 @@ describe('getButterSwapStepData', () => {
|
|
|
121
121
|
const { transactionData, networkFeeCryptoBaseUnit } = actual.unwrap();
|
|
122
122
|
// The buffered limit is set on the tx data in place, so the executable tx always carries one
|
|
123
123
|
expect(transactionData).toMatchObject({ gasLimit: '600000' });
|
|
124
|
-
expect(networkFeeCryptoBaseUnit).toBe('
|
|
124
|
+
expect(networkFeeCryptoBaseUnit).toBe('600000000000000');
|
|
125
125
|
});
|
|
126
126
|
it('errors rather than falling back to the provider fee when quote estimation fails', async () => {
|
|
127
127
|
const actual = await getButterSwapStepData({
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getProvidersExcluding } from '@cetusprotocol/aggregator-sdk';
|
|
1
|
+
import { getProvidersExcluding, PYTH_ORACLE_BASED_DEXES } from '@cetusprotocol/aggregator-sdk';
|
|
2
2
|
import { Transaction } from '@mysten/sui/transactions';
|
|
3
3
|
import { toAddressNList } from '@shapeshiftoss/chain-adapters';
|
|
4
4
|
import { TxStatus } from '@shapeshiftoss/unchained-client';
|
|
@@ -8,7 +8,6 @@ import { SwapperName } from '../../types.js';
|
|
|
8
8
|
import { checkSuiSwapStatus, getExecutableTradeStep, isExecutableTradeQuote } from '../../utils/index.js';
|
|
9
9
|
import { getTradeQuote } from './swapperApi/getTradeQuote.js';
|
|
10
10
|
import { getTradeRate } from './swapperApi/getTradeRate.js';
|
|
11
|
-
import { PYTH_DEPENDENT_PROVIDERS } from './utils/constants.js';
|
|
12
11
|
import { findBestRoute, getAggregatorClient, getCoinType, getSuiClient } from './utils/helpers.js';
|
|
13
12
|
export const cetusApi = {
|
|
14
13
|
getTradeQuote: (input, deps) => getTradeQuote(input, deps),
|
|
@@ -20,12 +19,12 @@ export const cetusApi = {
|
|
|
20
19
|
const { accountNumber, sellAsset, buyAsset, sellAmountIncludingProtocolFeesCryptoBaseUnit } = step;
|
|
21
20
|
const adapter = assertGetSuiChainAdapter(sellAsset.chainId);
|
|
22
21
|
const rpcUrl = config.VITE_SUI_NODE_URL;
|
|
23
|
-
const client = getAggregatorClient(rpcUrl);
|
|
22
|
+
const client = getAggregatorClient(rpcUrl, from);
|
|
24
23
|
const suiClient = getSuiClient(rpcUrl);
|
|
25
24
|
const sellCoinType = getCoinType(sellAsset);
|
|
26
25
|
const buyCoinType = getCoinType(buyAsset);
|
|
27
26
|
// Exclude Pyth-dependent providers to avoid oracle failures
|
|
28
|
-
const providersWithoutPyth = getProvidersExcluding(
|
|
27
|
+
const providersWithoutPyth = getProvidersExcluding(PYTH_ORACLE_BASED_DEXES);
|
|
29
28
|
const routerData = await findBestRoute(client, sellCoinType, buyCoinType, sellAmountIncludingProtocolFeesCryptoBaseUnit, providersWithoutPyth);
|
|
30
29
|
if (!routerData) {
|
|
31
30
|
throw new Error(`No route found for ${sellAsset.symbol}/${buyAsset.symbol}`);
|
|
@@ -5,9 +5,11 @@ import { getDefaultSlippageDecimalPercentageForSwapper } from '../../../constant
|
|
|
5
5
|
import { SwapperName } from '../../../types.js';
|
|
6
6
|
import { makeNetworkFeeEstimationFailedErr } from '../../../utils/index.js';
|
|
7
7
|
import { getAggregatorClient, getSuiClient } from '../utils/helpers.js';
|
|
8
|
+
// The 0x0 dummy sender only holds dust SUI, so server-side gas selection exceeds the payment object limit
|
|
9
|
+
const UNFUNDED_SENDER_ERRORS = ['Insufficient balance of', 'maximum number of gas payment objects'];
|
|
8
10
|
export async function getCetusStepData(args) {
|
|
9
11
|
const { routerData, rpcUrl, slippageTolerancePercentageDecimal, from } = args;
|
|
10
|
-
const client = getAggregatorClient(rpcUrl);
|
|
12
|
+
const client = getAggregatorClient(rpcUrl, from);
|
|
11
13
|
const suiClient = getSuiClient(rpcUrl);
|
|
12
14
|
const slippage = bnOrZero(slippageTolerancePercentageDecimal ??
|
|
13
15
|
getDefaultSlippageDecimalPercentageForSwapper(SwapperName.Cetus)).toNumber();
|
|
@@ -17,12 +19,14 @@ export async function getCetusStepData(args) {
|
|
|
17
19
|
txb.setSender(from);
|
|
18
20
|
await client.fastRouterSwap({ router: routerData, slippage, txb, refreshAllCoins: true });
|
|
19
21
|
const transactionBytes = await txb.build({ client: suiClient });
|
|
20
|
-
const dryRunResult = await suiClient.
|
|
21
|
-
|
|
22
|
+
const dryRunResult = await suiClient.simulateTransaction({
|
|
23
|
+
transaction: transactionBytes,
|
|
24
|
+
include: { effects: true },
|
|
22
25
|
});
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
+
const { gasUsed } = (dryRunResult.Transaction ?? dryRunResult.FailedTransaction).effects;
|
|
27
|
+
const computationCost = BigInt(gasUsed.computationCost);
|
|
28
|
+
const storageCost = BigInt(gasUsed.storageCost);
|
|
29
|
+
const storageRebate = BigInt(gasUsed.storageRebate);
|
|
26
30
|
const netStorageCost = storageCost > storageRebate ? storageCost - storageRebate : 0n;
|
|
27
31
|
return (computationCost + netStorageCost).toString();
|
|
28
32
|
};
|
|
@@ -33,8 +37,9 @@ export async function getCetusStepData(args) {
|
|
|
33
37
|
return Ok(stepData);
|
|
34
38
|
}
|
|
35
39
|
catch (error) {
|
|
36
|
-
// Walletless rates have no coins to dry-run against - degrade to an unknown fee, but a real route/build error still fails
|
|
37
|
-
|
|
40
|
+
// Walletless rates have no usable coins to dry-run against - degrade to an unknown fee, but a real route/build error still fails
|
|
41
|
+
const errorMessage = error instanceof Error ? error.message : '';
|
|
42
|
+
if (UNFUNDED_SENDER_ERRORS.some(message => errorMessage.includes(message))) {
|
|
38
43
|
const stepData = { networkFeeCryptoBaseUnit: undefined };
|
|
39
44
|
return Ok(stepData);
|
|
40
45
|
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { getProvidersExcluding } from '@cetusprotocol/aggregator-sdk';
|
|
1
|
+
import { getProvidersExcluding, PYTH_ORACLE_BASED_DEXES } from '@cetusprotocol/aggregator-sdk';
|
|
2
2
|
import { Err, Ok } from '@sniptt/monads';
|
|
3
3
|
import { v4 as uuid } from 'uuid';
|
|
4
4
|
import { SwapperName, TradeQuoteError } from '../../../types.js';
|
|
5
5
|
import { getInputOutputRate, makeSwapErrorRight } from '../../../utils/index.js';
|
|
6
6
|
import { buildAffiliateFee } from '../../../utils/affiliateFee.js';
|
|
7
|
-
import { PYTH_DEPENDENT_PROVIDERS } from '../utils/constants.js';
|
|
8
7
|
import { assertValidTrade, findBestRoute, getAggregatorClient, getCoinType } from '../utils/helpers.js';
|
|
9
8
|
export const getCetusTradeContext = async (input, deps) => {
|
|
10
9
|
const { sellAsset, buyAsset, sellAmountIncludingProtocolFeesCryptoBaseUnit, affiliateBps } = input;
|
|
@@ -17,7 +16,7 @@ export const getCetusTradeContext = async (input, deps) => {
|
|
|
17
16
|
const sellCoinType = getCoinType(sellAsset);
|
|
18
17
|
const buyCoinType = getCoinType(buyAsset);
|
|
19
18
|
// Exclude Pyth-dependent providers to avoid oracle failures
|
|
20
|
-
const providersWithoutPyth = getProvidersExcluding(
|
|
19
|
+
const providersWithoutPyth = getProvidersExcluding(PYTH_ORACLE_BASED_DEXES);
|
|
21
20
|
const routerData = await findBestRoute(client, sellCoinType, buyCoinType, sellAmountIncludingProtocolFeesCryptoBaseUnit, providersWithoutPyth);
|
|
22
21
|
if (!routerData) {
|
|
23
22
|
return Err(makeSwapErrorRight({
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { ChainId } from '@shapeshiftoss/caip';
|
|
2
2
|
export declare const SUPPORTED_CETUS_CHAIN_IDS: readonly ChainId[];
|
|
3
3
|
export declare const isSupportedChainId: (chainId: ChainId) => chainId is ChainId;
|
|
4
|
-
export declare const PYTH_DEPENDENT_PROVIDERS: string[];
|
|
5
4
|
export declare const CETUS_FEE_ESTIMATE_DUMMY_ADDRESS = "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
@@ -3,6 +3,5 @@ export const SUPPORTED_CETUS_CHAIN_IDS = [suiChainId];
|
|
|
3
3
|
export const isSupportedChainId = (chainId) => {
|
|
4
4
|
return SUPPORTED_CETUS_CHAIN_IDS.includes(chainId);
|
|
5
5
|
};
|
|
6
|
-
export const PYTH_DEPENDENT_PROVIDERS = ['HAEDALPMM', 'HAEDALHMMV2', 'METASTABLE'];
|
|
7
6
|
// Placeholder sender for walletless rate fee estimation - dry-run needs a sender, real coins aren't required
|
|
8
7
|
export const CETUS_FEE_ESTIMATE_DUMMY_ADDRESS = '0x0000000000000000000000000000000000000000000000000000000000000000';
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { RouterDataV3 } from '@cetusprotocol/aggregator-sdk';
|
|
2
2
|
import { AggregatorClient } from '@cetusprotocol/aggregator-sdk';
|
|
3
|
-
import {
|
|
3
|
+
import { SuiGrpcClient } from '@mysten/sui/grpc';
|
|
4
4
|
import type { Asset } from '@shapeshiftoss/types';
|
|
5
5
|
import type { Result } from '@sniptt/monads';
|
|
6
6
|
import type { SwapErrorRight } from '../../../types.js';
|
|
7
|
-
export declare const
|
|
8
|
-
export declare const
|
|
7
|
+
export declare const getSuiClient: (rpcUrl: string) => SuiGrpcClient;
|
|
8
|
+
export declare const getAggregatorClient: (rpcUrl: string, signer?: string) => AggregatorClient;
|
|
9
9
|
export declare const assertValidTrade: ({ sellAsset, buyAsset, }: {
|
|
10
10
|
sellAsset: Asset;
|
|
11
11
|
buyAsset: Asset;
|
|
@@ -1,32 +1,21 @@
|
|
|
1
1
|
import { AggregatorClient, Env } from '@cetusprotocol/aggregator-sdk';
|
|
2
|
-
import {
|
|
2
|
+
import { SuiGrpcClient } from '@mysten/sui/grpc';
|
|
3
3
|
import { fromAssetId } from '@shapeshiftoss/caip';
|
|
4
4
|
import { Err, Ok } from '@sniptt/monads';
|
|
5
5
|
import { TradeQuoteError } from '../../../types.js';
|
|
6
6
|
import { makeSwapErrorRight } from '../../../utils/index.js';
|
|
7
7
|
import { isSupportedChainId } from './constants.js';
|
|
8
8
|
let suiClientInstance;
|
|
9
|
-
let aggregatorClientInstance;
|
|
10
9
|
let currentRpcUrl;
|
|
11
|
-
export const getAggregatorClient = (rpcUrl) => {
|
|
12
|
-
if (!aggregatorClientInstance || !suiClientInstance || currentRpcUrl !== rpcUrl) {
|
|
13
|
-
suiClientInstance = new SuiClient({ url: rpcUrl });
|
|
14
|
-
aggregatorClientInstance = new AggregatorClient({
|
|
15
|
-
client: suiClientInstance,
|
|
16
|
-
env: Env.Mainnet,
|
|
17
|
-
signer: '0x0',
|
|
18
|
-
});
|
|
19
|
-
currentRpcUrl = rpcUrl;
|
|
20
|
-
}
|
|
21
|
-
return aggregatorClientInstance;
|
|
22
|
-
};
|
|
23
10
|
export const getSuiClient = (rpcUrl) => {
|
|
24
11
|
if (!suiClientInstance || currentRpcUrl !== rpcUrl) {
|
|
25
|
-
suiClientInstance = new
|
|
12
|
+
suiClientInstance = new SuiGrpcClient({ network: 'mainnet', baseUrl: rpcUrl });
|
|
26
13
|
currentRpcUrl = rpcUrl;
|
|
27
14
|
}
|
|
28
15
|
return suiClientInstance;
|
|
29
16
|
};
|
|
17
|
+
// Cetus merges the swap output into an existing coin owned by signer, so it must be the tx sender
|
|
18
|
+
export const getAggregatorClient = (rpcUrl, signer) => new AggregatorClient({ client: getSuiClient(rpcUrl), env: Env.Mainnet, signer });
|
|
30
19
|
export const assertValidTrade = ({ sellAsset, buyAsset, }) => {
|
|
31
20
|
if (!isSupportedChainId(sellAsset.chainId)) {
|
|
32
21
|
return Err(makeSwapErrorRight({
|
|
@@ -3,7 +3,7 @@ import { Err, Ok } from '@sniptt/monads';
|
|
|
3
3
|
import { makeNetworkFeeEstimationFailedErr } from '../../../utils/index.js';
|
|
4
4
|
import { getEvmNetworkFeeCryptoBaseUnit } from '../../../utils/evm/index.js';
|
|
5
5
|
export async function getDebridgeStepData(args) {
|
|
6
|
-
const { tx, sellAmountCryptoBaseUnit,
|
|
6
|
+
const { tx, sellAmountCryptoBaseUnit, spenderAddress, fallbackNetworkFeeCryptoBaseUnit, sellAsset, from, type, input, deps, } = args;
|
|
7
7
|
const adapter = deps.assertGetEvmChainAdapter(sellAsset.chainId);
|
|
8
8
|
const supportsEIP1559 = 'supportsEIP1559' in input ? input.supportsEIP1559 : false;
|
|
9
9
|
const transactionData = {
|
|
@@ -12,7 +12,6 @@ export async function getDebridgeStepData(args) {
|
|
|
12
12
|
to: tx.to,
|
|
13
13
|
data: tx.data,
|
|
14
14
|
value: tx.value,
|
|
15
|
-
gasLimit,
|
|
16
15
|
};
|
|
17
16
|
const stateOverride = {
|
|
18
17
|
sellAsset,
|
|
@@ -20,20 +19,14 @@ export async function getDebridgeStepData(args) {
|
|
|
20
19
|
spenderAddress,
|
|
21
20
|
};
|
|
22
21
|
if (type === 'rate') {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
catch {
|
|
34
|
-
return fallbackNetworkFeeCryptoBaseUnit;
|
|
35
|
-
}
|
|
36
|
-
})();
|
|
22
|
+
// deBridge returns a flat gas limit far above actual usage, so rates simulate instead
|
|
23
|
+
const networkFeeCryptoBaseUnit = await getEvmNetworkFeeCryptoBaseUnit({
|
|
24
|
+
adapter,
|
|
25
|
+
transactionData,
|
|
26
|
+
from,
|
|
27
|
+
supportsEIP1559,
|
|
28
|
+
stateOverride,
|
|
29
|
+
}).catch(() => fallbackNetworkFeeCryptoBaseUnit);
|
|
37
30
|
const stepData = { networkFeeCryptoBaseUnit };
|
|
38
31
|
return Ok(stepData);
|
|
39
32
|
}
|
|
@@ -82,7 +82,6 @@ export const getDebridgeTradeContext = async ({ input, deps, senderAddress, reci
|
|
|
82
82
|
stepDataArgs: {
|
|
83
83
|
tx: quote.tx,
|
|
84
84
|
sellAmountCryptoBaseUnit: sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
85
|
-
gasLimit: quote.gasLimit,
|
|
86
85
|
fallbackNetworkFeeCryptoBaseUnit: quote.fallbackNetworkFeeCryptoBaseUnit,
|
|
87
86
|
sellAsset,
|
|
88
87
|
spenderAddress: allowanceContract,
|
|
@@ -135,7 +134,6 @@ const fetchCrossChainQuote = async ({ input, deps, sellDebridgeChainId, buyDebri
|
|
|
135
134
|
isSameChainSwap: false,
|
|
136
135
|
slippageTolerancePercentageDecimal: input.slippageTolerancePercentageDecimal,
|
|
137
136
|
tx: quote.tx,
|
|
138
|
-
gasLimit: quote.estimatedTransactionFee?.details.gasLimit,
|
|
139
137
|
fallbackNetworkFeeCryptoBaseUnit: quote.estimatedTransactionFee?.total,
|
|
140
138
|
});
|
|
141
139
|
};
|
|
@@ -191,7 +189,6 @@ const fetchSameChainQuote = async ({ input, deps, sellDebridgeChainId, senderAdd
|
|
|
191
189
|
slippageTolerancePercentageDecimal: input.slippageTolerancePercentageDecimal ??
|
|
192
190
|
(quote.slippage ? bnOrZero(quote.slippage).div(100).toString() : undefined),
|
|
193
191
|
tx: quote.tx,
|
|
194
|
-
gasLimit: quote.estimatedTransactionFee?.details.gasLimit,
|
|
195
192
|
fallbackNetworkFeeCryptoBaseUnit: quote.estimatedTransactionFee?.total,
|
|
196
193
|
});
|
|
197
194
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { fromChainId } from '@shapeshiftoss/caip';
|
|
2
2
|
import { Err, Ok } from '@sniptt/monads';
|
|
3
3
|
import { makeNetworkFeeEstimationFailedErr } from '../../../utils/index.js';
|
|
4
|
-
import { getEvmNetworkFeeCryptoBaseUnit } from '../../../utils/evm/index.js';
|
|
4
|
+
import { getEvmNetworkFeeCryptoBaseUnit, getEvmRateNetworkFeeCryptoBaseUnit, } from '../../../utils/evm/index.js';
|
|
5
5
|
export async function getFyndStepData(args) {
|
|
6
6
|
const { quote, sellAsset, sellAmountCryptoBaseUnit, spenderAddress, from, type, input, deps } = args;
|
|
7
7
|
const adapter = deps.assertGetEvmChainAdapter(sellAsset.chainId);
|
|
@@ -15,15 +15,12 @@ export async function getFyndStepData(args) {
|
|
|
15
15
|
};
|
|
16
16
|
const stateOverride = { sellAsset, sellAmountCryptoBaseUnit, spenderAddress };
|
|
17
17
|
if (type === 'rate') {
|
|
18
|
-
const networkFeeCryptoBaseUnit = await
|
|
18
|
+
const networkFeeCryptoBaseUnit = await getEvmRateNetworkFeeCryptoBaseUnit({
|
|
19
19
|
adapter,
|
|
20
|
-
transactionData,
|
|
21
|
-
from,
|
|
22
20
|
supportsEIP1559,
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
.catch(() => undefined);
|
|
21
|
+
providerGasLimit: quote.gas_estimate,
|
|
22
|
+
simulation: { transactionData, from, stateOverride },
|
|
23
|
+
}).catch(() => undefined);
|
|
27
24
|
const stepData = { networkFeeCryptoBaseUnit };
|
|
28
25
|
return Ok(stepData);
|
|
29
26
|
}
|
|
@@ -34,6 +31,7 @@ export async function getFyndStepData(args) {
|
|
|
34
31
|
from,
|
|
35
32
|
supportsEIP1559,
|
|
36
33
|
stateOverride,
|
|
34
|
+
providerGasLimit: quote.gas_estimate,
|
|
37
35
|
});
|
|
38
36
|
const stepData = { transactionData, networkFeeCryptoBaseUnit };
|
|
39
37
|
return Ok(stepData);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { checkEvmSwapStatus } from '../../utils/index.js';
|
|
2
|
+
import { getEvmTransactionFees, getUnsignedEvmTransaction } from '../../utils/evm/index.js';
|
|
3
|
+
import { getKyberTradeQuote } from './swapperApi/getKyberTradeQuote.js';
|
|
4
|
+
import { getKyberTradeRate } from './swapperApi/getKyberTradeRate.js';
|
|
5
|
+
export const kyberApi = {
|
|
6
|
+
getTradeQuote: (input, deps) => getKyberTradeQuote(input, deps),
|
|
7
|
+
getTradeRate: (input, deps) => getKyberTradeRate(input, deps),
|
|
8
|
+
getUnsignedEvmTransaction,
|
|
9
|
+
getEvmTransactionFees,
|
|
10
|
+
checkTradeStatus: checkEvmSwapStatus,
|
|
11
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Result } from '@sniptt/monads';
|
|
2
|
+
import type { SwapErrorRight, SwapperDeps, TradeQuote } from '../../../types.js';
|
|
3
|
+
import type { KyberTradeQuoteInput } from '../types.js';
|
|
4
|
+
export declare const getKyberTradeQuote: (input: KyberTradeQuoteInput, deps: SwapperDeps) => Promise<Result<TradeQuote[], SwapErrorRight>>;
|