@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
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { fromChainId } from '@shapeshiftoss/caip';
|
|
2
2
|
import { tron } from '@shapeshiftoss/chain-adapters';
|
|
3
|
-
import {
|
|
3
|
+
import { contractAddressOrUndefined, isToken } from '@shapeshiftoss/utils';
|
|
4
4
|
import { Err, Ok } from '@sniptt/monads';
|
|
5
5
|
import { makeNetworkFeeEstimationFailedErr, makeTradeStepBuildFailedErr } from '../../../utils/index.js';
|
|
6
|
-
import { getEvmNetworkFeeCryptoBaseUnit } from '../../../utils/evm/index.js';
|
|
6
|
+
import { getEvmNetworkFeeCryptoBaseUnit, getEvmRateNetworkFeeCryptoBaseUnit, } from '../../../utils/evm/index.js';
|
|
7
7
|
import { getSolanaNetworkFeeCryptoBaseUnit, omitComputeBudgetInstructions, withComputeUnitLimit, } from '../../../utils/solana/index.js';
|
|
8
8
|
import { getTronContractCallFallbackFeeCryptoBaseUnit, getTronContractCallNetworkFeeCryptoBaseUnit, } from '../../../utils/tron/index.js';
|
|
9
9
|
import { getUtxoNetworkFeeCryptoBaseUnit } from '../../../utils/utxo/index.js';
|
|
@@ -34,7 +34,6 @@ export async function getRelayStepData({ data, sellAsset, sellAmountCryptoBaseUn
|
|
|
34
34
|
to,
|
|
35
35
|
value,
|
|
36
36
|
data: callData,
|
|
37
|
-
gasLimit: bnOrZero(relayGasLimit).gt(0) ? relayGasLimit : undefined,
|
|
38
37
|
};
|
|
39
38
|
const adapter = deps.assertGetEvmChainAdapter(sellAsset.chainId);
|
|
40
39
|
const stateOverride = {
|
|
@@ -43,20 +42,12 @@ export async function getRelayStepData({ data, sellAsset, sellAmountCryptoBaseUn
|
|
|
43
42
|
spenderAddress,
|
|
44
43
|
};
|
|
45
44
|
if (type === 'rate') {
|
|
46
|
-
const networkFeeCryptoBaseUnit = await (
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
supportsEIP1559,
|
|
53
|
-
stateOverride,
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
catch {
|
|
57
|
-
return fallbackNetworkFeeCryptoBaseUnit;
|
|
58
|
-
}
|
|
59
|
-
})();
|
|
45
|
+
const networkFeeCryptoBaseUnit = await getEvmRateNetworkFeeCryptoBaseUnit({
|
|
46
|
+
adapter,
|
|
47
|
+
supportsEIP1559,
|
|
48
|
+
providerGasLimit: relayGasLimit,
|
|
49
|
+
simulation: { transactionData, from, stateOverride },
|
|
50
|
+
}).catch(() => fallbackNetworkFeeCryptoBaseUnit);
|
|
60
51
|
const stepData = { networkFeeCryptoBaseUnit };
|
|
61
52
|
return Ok(stepData);
|
|
62
53
|
}
|
|
@@ -68,6 +59,7 @@ export async function getRelayStepData({ data, sellAsset, sellAmountCryptoBaseUn
|
|
|
68
59
|
from,
|
|
69
60
|
supportsEIP1559,
|
|
70
61
|
stateOverride,
|
|
62
|
+
providerGasLimit: relayGasLimit,
|
|
71
63
|
});
|
|
72
64
|
const stepData = { transactionData, networkFeeCryptoBaseUnit };
|
|
73
65
|
return Ok(stepData);
|
|
@@ -234,6 +234,11 @@ export const relayTokenToAssetId = (relayToken) => {
|
|
|
234
234
|
assetReference: ASSET_REFERENCE.Robinhood,
|
|
235
235
|
assetNamespace: ASSET_NAMESPACE.slip44,
|
|
236
236
|
};
|
|
237
|
+
case CHAIN_REFERENCE.ElysiumMainnet:
|
|
238
|
+
return {
|
|
239
|
+
assetReference: ASSET_REFERENCE.Elysium,
|
|
240
|
+
assetNamespace: ASSET_NAMESPACE.slip44,
|
|
241
|
+
};
|
|
237
242
|
default:
|
|
238
243
|
throw Error(`chainId '${relayToken.chainId}' not supported`);
|
|
239
244
|
}
|
|
@@ -1018,6 +1018,7 @@
|
|
|
1018
1018
|
"eip155:1/erc20:0xcbb8f1bda10b9696c57e13bc128fe674769dcec0",
|
|
1019
1019
|
"eip155:1/erc20:0x72dfb2e44f59c5ad2bafe84314e5b99a7cd5075e",
|
|
1020
1020
|
"eip155:1/erc20:0xce682c89c63d2850cb2ca898e44d6c7c30d897a6",
|
|
1021
|
+
"eip155:1/erc20:0x68749665ff8d2d112fa859aa293f07a622782f38",
|
|
1021
1022
|
"eip155:43114/erc20:0xc891eb4cbdeff6e073e859e987815ed1505c2acd",
|
|
1022
1023
|
"eip155:43114/erc20:0xd24c2ad096400b6fbcd2ad8b24e7acbc21a1da64",
|
|
1023
1024
|
"eip155:43114/erc20:0x47c3118ad183712acd42648e9e522e13690f29a0",
|
|
@@ -79,7 +79,7 @@ const expectedQuoteResponse = [
|
|
|
79
79
|
asset: ETH,
|
|
80
80
|
},
|
|
81
81
|
},
|
|
82
|
-
networkFeeCryptoBaseUnit: '
|
|
82
|
+
networkFeeCryptoBaseUnit: '480000',
|
|
83
83
|
},
|
|
84
84
|
rate: '143505.61489594191334131621',
|
|
85
85
|
source: SwapperName.Thorchain,
|
|
@@ -130,7 +130,7 @@ const expectedQuoteResponse = [
|
|
|
130
130
|
asset: ETH,
|
|
131
131
|
},
|
|
132
132
|
},
|
|
133
|
-
networkFeeCryptoBaseUnit: '
|
|
133
|
+
networkFeeCryptoBaseUnit: '480000',
|
|
134
134
|
},
|
|
135
135
|
rate: '157530.57158846677816130059',
|
|
136
136
|
source: `${SwapperName.Thorchain} • Streaming`,
|
|
@@ -39,7 +39,7 @@ export const getZrxTradeQuote = async (input, deps) => {
|
|
|
39
39
|
});
|
|
40
40
|
if (maybeZrxQuoteResponse.isErr())
|
|
41
41
|
return Err(maybeZrxQuoteResponse.unwrapErr());
|
|
42
|
-
const { sellAmount, buyAmount, fees, permit2, transaction, route } = maybeZrxQuoteResponse.unwrap();
|
|
42
|
+
const { sellAmount, buyAmount, fees, permit2, transaction, totalNetworkFee, route } = maybeZrxQuoteResponse.unwrap();
|
|
43
43
|
const permit2Eip712 = permit2?.eip712;
|
|
44
44
|
const permit2Deadline = permit2Eip712 ? Number(permit2Eip712.message.deadline) : undefined;
|
|
45
45
|
if (permit2Deadline !== undefined &&
|
|
@@ -90,6 +90,8 @@ export const getZrxTradeQuote = async (input, deps) => {
|
|
|
90
90
|
type: 'quote',
|
|
91
91
|
input,
|
|
92
92
|
transaction,
|
|
93
|
+
totalNetworkFee,
|
|
94
|
+
sellAmountCryptoBaseUnit: sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
93
95
|
permit2Eip712,
|
|
94
96
|
from: receiveAddress,
|
|
95
97
|
});
|
|
@@ -4,7 +4,7 @@ import type { Address } from 'viem';
|
|
|
4
4
|
import type { GetEvmTradeQuoteInput, GetEvmTradeRateInput } from '../../types.js';
|
|
5
5
|
export type ZrxTradeQuoteInput = GetEvmTradeQuoteInput;
|
|
6
6
|
export type ZrxTradeRateInput = GetEvmTradeRateInput;
|
|
7
|
-
export declare const zrxSupportedChainIds: readonly [KnownChainIds.EthereumMainnet, KnownChainIds.AvalancheMainnet, KnownChainIds.OptimismMainnet, KnownChainIds.BnbSmartChainMainnet, KnownChainIds.PolygonMainnet, KnownChainIds.ArbitrumMainnet, KnownChainIds.BaseMainnet, KnownChainIds.RobinhoodMainnet];
|
|
7
|
+
export declare const zrxSupportedChainIds: readonly [KnownChainIds.EthereumMainnet, KnownChainIds.AvalancheMainnet, KnownChainIds.OptimismMainnet, KnownChainIds.BnbSmartChainMainnet, KnownChainIds.PolygonMainnet, KnownChainIds.ArbitrumMainnet, KnownChainIds.BaseMainnet, KnownChainIds.RobinhoodMainnet, KnownChainIds.ElysiumMainnet];
|
|
8
8
|
export type ZrxSupportedChainId = (typeof zrxSupportedChainIds)[number];
|
|
9
9
|
type ZrxFee = {
|
|
10
10
|
amount: string;
|
|
@@ -19,6 +19,7 @@ export const ZRX_SUPPORTED_CHAINIDS = Object.freeze([
|
|
|
19
19
|
KnownChainIds.ArbitrumMainnet,
|
|
20
20
|
KnownChainIds.BaseMainnet,
|
|
21
21
|
KnownChainIds.RobinhoodMainnet,
|
|
22
|
+
KnownChainIds.ElysiumMainnet,
|
|
22
23
|
]);
|
|
23
24
|
// https://0x.org/docs/developer-resources/faqs-and-troubleshooting
|
|
24
25
|
export const ZRX_NATIVE_ASSET_ADDRESS = '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE';
|
|
@@ -5,10 +5,12 @@ export type GetZrxStepDataArgs = StepDataArgs<unknown, {
|
|
|
5
5
|
totalNetworkFee: string | null;
|
|
6
6
|
}, {
|
|
7
7
|
transaction: ZrxQuoteResponse['transaction'];
|
|
8
|
+
totalNetworkFee: string | null;
|
|
9
|
+
sellAmountCryptoBaseUnit: string;
|
|
8
10
|
permit2Eip712: NonNullable<ZrxQuoteResponse['permit2']>['eip712'] | undefined;
|
|
9
11
|
}>;
|
|
10
12
|
type ZrxRateStepData = {
|
|
11
|
-
networkFeeCryptoBaseUnit: string;
|
|
13
|
+
networkFeeCryptoBaseUnit: string | undefined;
|
|
12
14
|
};
|
|
13
15
|
type ZrxQuoteStepData = {
|
|
14
16
|
transactionData: TxBuildData;
|
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
import { fromChainId } from '@shapeshiftoss/caip';
|
|
2
|
-
import { bnOrZero } from '@shapeshiftoss/utils';
|
|
2
|
+
import { BigNumber, bnOrZero } from '@shapeshiftoss/utils';
|
|
3
3
|
import { Err, Ok } from '@sniptt/monads';
|
|
4
4
|
import { makeNetworkFeeEstimationFailedErr } from '../../../utils/index.js';
|
|
5
|
-
import { getEvmNetworkFeeCryptoBaseUnit } from '../../../utils/evm/index.js';
|
|
5
|
+
import { bufferGasLimit, getEvmNetworkFeeCryptoBaseUnit, isPositiveGasLimit, } from '../../../utils/evm/index.js';
|
|
6
6
|
export async function getZrxStepData(args) {
|
|
7
|
+
// 0x's total includes the L1 data fee on OP-stack chains, which pricing their gas limit would drop
|
|
7
8
|
if (args.type === 'rate') {
|
|
8
9
|
const stepData = {
|
|
9
|
-
networkFeeCryptoBaseUnit:
|
|
10
|
+
networkFeeCryptoBaseUnit: args.totalNetworkFee ?? undefined,
|
|
10
11
|
};
|
|
11
12
|
return Ok(stepData);
|
|
12
13
|
}
|
|
13
|
-
const { sellAsset, transaction, permit2Eip712, from, input, deps } = args;
|
|
14
|
+
const { sellAsset, sellAmountCryptoBaseUnit, transaction, totalNetworkFee, permit2Eip712, from, input, deps, } = args;
|
|
15
|
+
const adapter = deps.assertGetEvmChainAdapter(sellAsset.chainId);
|
|
16
|
+
const supportsEIP1559 = 'supportsEIP1559' in input ? input.supportsEIP1559 : false;
|
|
14
17
|
const transactionData = {
|
|
15
18
|
type: 'evm',
|
|
16
19
|
chainId: Number(fromChainId(sellAsset.chainId).chainReference),
|
|
17
20
|
to: transaction.to,
|
|
18
21
|
data: transaction.data,
|
|
19
22
|
value: transaction.value,
|
|
20
|
-
// 0x simulate with a valid permit2 signature, which can't be reproduced before signing, so trust their gas limit
|
|
21
|
-
gasLimit: transaction.gas || undefined,
|
|
22
23
|
...(permit2Eip712 && {
|
|
23
24
|
signatureRequired: {
|
|
24
25
|
type: 'permit2',
|
|
@@ -27,12 +28,30 @@ export async function getZrxStepData(args) {
|
|
|
27
28
|
}),
|
|
28
29
|
};
|
|
29
30
|
try {
|
|
30
|
-
const networkFeeCryptoBaseUnit = await
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
const networkFeeCryptoBaseUnit = await (async () => {
|
|
32
|
+
// Permit2 calldata needs the signature, so it can't be simulated before signing
|
|
33
|
+
if (permit2Eip712) {
|
|
34
|
+
if (!isPositiveGasLimit(transaction.gas))
|
|
35
|
+
throw new Error('missing 0x gas limit');
|
|
36
|
+
transactionData.gasLimit = bufferGasLimit(transaction.gas);
|
|
37
|
+
// 0x's total is their gas cost plus the L1 data fee on OP-stack chains
|
|
38
|
+
const l1FeeCryptoBaseUnit = BigNumber.max(bnOrZero(totalNetworkFee).minus(bnOrZero(transaction.gas).times(transaction.gasPrice)), 0);
|
|
39
|
+
const networkFeeCryptoBaseUnit = await getEvmNetworkFeeCryptoBaseUnit({
|
|
40
|
+
adapter,
|
|
41
|
+
supportsEIP1559,
|
|
42
|
+
gasLimit: transactionData.gasLimit,
|
|
43
|
+
});
|
|
44
|
+
return bnOrZero(networkFeeCryptoBaseUnit).plus(l1FeeCryptoBaseUnit).toFixed(0);
|
|
45
|
+
}
|
|
46
|
+
return getEvmNetworkFeeCryptoBaseUnit({
|
|
47
|
+
adapter,
|
|
48
|
+
transactionData,
|
|
49
|
+
from,
|
|
50
|
+
supportsEIP1559,
|
|
51
|
+
stateOverride: { sellAsset, sellAmountCryptoBaseUnit },
|
|
52
|
+
providerGasLimit: transaction.gas,
|
|
53
|
+
});
|
|
54
|
+
})();
|
|
36
55
|
const stepData = { transactionData, networkFeeCryptoBaseUnit };
|
|
37
56
|
return Ok(stepData);
|
|
38
57
|
}
|
|
@@ -6,7 +6,7 @@ import type { SwapErrorRight } from '../../../types.js';
|
|
|
6
6
|
import type { ZrxFees, ZrxPriceResponse } from '../types.js';
|
|
7
7
|
export declare const assetIdToZrxToken: (assetId: AssetId) => string;
|
|
8
8
|
export declare const zrxTokenToAssetId: (token: string, chainId: ChainId) => AssetId;
|
|
9
|
-
export declare const isSupportedChainId: (chainId: ChainId) => chainId is KnownChainIds.EthereumMainnet | KnownChainIds.AvalancheMainnet | KnownChainIds.OptimismMainnet | KnownChainIds.BnbSmartChainMainnet | KnownChainIds.PolygonMainnet | KnownChainIds.ArbitrumMainnet | KnownChainIds.BaseMainnet | KnownChainIds.RobinhoodMainnet;
|
|
9
|
+
export declare const isSupportedChainId: (chainId: ChainId) => chainId is KnownChainIds.EthereumMainnet | KnownChainIds.AvalancheMainnet | KnownChainIds.OptimismMainnet | KnownChainIds.BnbSmartChainMainnet | KnownChainIds.PolygonMainnet | KnownChainIds.ArbitrumMainnet | KnownChainIds.BaseMainnet | KnownChainIds.RobinhoodMainnet | KnownChainIds.ElysiumMainnet;
|
|
10
10
|
export declare const isWrappedNativeSell: (route: ZrxPriceResponse['route']) => boolean;
|
|
11
11
|
export declare const assertValidTrade: ({ buyAsset, sellAsset, }: {
|
|
12
12
|
buyAsset: Asset;
|
|
@@ -61,6 +61,11 @@ export const zrxTokenToAssetId = (token, chainId) => {
|
|
|
61
61
|
assetReference: ASSET_REFERENCE.Robinhood,
|
|
62
62
|
assetNamespace: ASSET_NAMESPACE.slip44,
|
|
63
63
|
};
|
|
64
|
+
case KnownChainIds.ElysiumMainnet:
|
|
65
|
+
return {
|
|
66
|
+
assetReference: ASSET_REFERENCE.Elysium,
|
|
67
|
+
assetNamespace: ASSET_NAMESPACE.slip44,
|
|
68
|
+
};
|
|
64
69
|
default:
|
|
65
70
|
throw Error(`chainId '${chainId}' not supported`);
|
|
66
71
|
}
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AccountId, AssetId, ChainId } from '@shapeshiftoss/caip';
|
|
2
|
-
import type { ChainAdapter, CosmosSdkChainAdapter, EvmChainAdapter, near, SignTx, solana, starknet, sui, ton, tron, UtxoChainAdapter } from '@shapeshiftoss/chain-adapters';
|
|
3
|
-
import type { HDWallet, SolanaSignTx, StarknetSignTx, SuiSignTx } from '@shapeshiftoss/hdwallet-core';
|
|
4
|
-
import type { Asset, AssetsByIdPartial, CosmosSdkChainId, EvmChainId, KnownChainIds, NearChainId, OrderCreation, PartialRecord, SolanaChainId, StarknetChainId, SuiChainId, TonChainId, TronChainId, UtxoAccountType, UtxoChainId } from '@shapeshiftoss/types';
|
|
2
|
+
import type { aptos, ChainAdapter, CosmosSdkChainAdapter, EvmChainAdapter, near, SignTx, solana, starknet, sui, ton, tron, UtxoChainAdapter } from '@shapeshiftoss/chain-adapters';
|
|
3
|
+
import type { AptosSignTx, HDWallet, SolanaSignTx, StarknetSignTx, SuiSignTx } from '@shapeshiftoss/hdwallet-core';
|
|
4
|
+
import type { AptosChainId, Asset, AssetsByIdPartial, CosmosSdkChainId, EvmChainId, KnownChainIds, NearChainId, OrderCreation, PartialRecord, SolanaChainId, StarknetChainId, SuiChainId, TonChainId, TronChainId, UtxoAccountType, UtxoChainId } from '@shapeshiftoss/types';
|
|
5
5
|
import type { TxStatus } from '@shapeshiftoss/unchained-client';
|
|
6
6
|
import type { Result } from '@sniptt/monads';
|
|
7
7
|
import type { TransactionInstruction } from '@solana/web3.js';
|
|
@@ -44,6 +44,7 @@ export type SwapperConfig = {
|
|
|
44
44
|
VITE_PORTALS_BASE_URL: string;
|
|
45
45
|
VITE_ZRX_BASE_URL: string;
|
|
46
46
|
VITE_FYND_BASE_URL: string;
|
|
47
|
+
VITE_KYBER_BASE_URL: string;
|
|
47
48
|
VITE_CHAINFLIP_API_KEY: string;
|
|
48
49
|
VITE_CHAINFLIP_API_URL: string;
|
|
49
50
|
VITE_FEATURE_CHAINFLIP_SWAP_DCA: boolean;
|
|
@@ -80,7 +81,8 @@ export declare enum SwapperName {
|
|
|
80
81
|
Debridge = "deBridge",
|
|
81
82
|
BobGateway = "BOB Gateway",
|
|
82
83
|
Symbiosis = "Symbiosis",
|
|
83
|
-
Fynd = "Fynd"
|
|
84
|
+
Fynd = "Fynd",
|
|
85
|
+
KyberSwap = "KyberSwap"
|
|
84
86
|
}
|
|
85
87
|
export type SwapSource = SwapperName | `${SwapperName} • ${string}`;
|
|
86
88
|
export type SwapErrorRight = {
|
|
@@ -182,6 +184,12 @@ export type GetTonTradeQuoteInput = CommonTradeQuoteInput & {
|
|
|
182
184
|
export type GetTonTradeRateInput = CommonTradeRateInput & {
|
|
183
185
|
chainId: TonChainId;
|
|
184
186
|
};
|
|
187
|
+
export type GetAptosTradeQuoteInput = CommonTradeQuoteInput & {
|
|
188
|
+
chainId: AptosChainId;
|
|
189
|
+
};
|
|
190
|
+
export type GetAptosTradeRateInput = CommonTradeRateInput & {
|
|
191
|
+
chainId: AptosChainId;
|
|
192
|
+
};
|
|
185
193
|
export type GetSolanaTradeQuoteInput = CommonTradeQuoteInput & {
|
|
186
194
|
chainId: SolanaChainId;
|
|
187
195
|
};
|
|
@@ -213,8 +221,8 @@ export type GetUtxoTradeRateInput = CommonTradeRateInput & {
|
|
|
213
221
|
xpub: string | undefined;
|
|
214
222
|
};
|
|
215
223
|
export type GetUtxoTradeQuoteInput = GetUtxoTradeQuoteWithWallet;
|
|
216
|
-
export type GetTradeQuoteInput = GetUtxoTradeQuoteInput | GetEvmTradeQuoteInput | GetCosmosSdkTradeQuoteInput | GetTronTradeQuoteInput | GetNearTradeQuoteInput | GetTonTradeQuoteInput | GetSolanaTradeQuoteInput | GetStarknetTradeQuoteInput | GetSuiTradeQuoteInput;
|
|
217
|
-
export type GetTradeRateInput = GetEvmTradeRateInput | GetCosmosSdkTradeRateInput | GetUtxoTradeRateInput | GetTronTradeRateInput | GetNearTradeRateInput | GetTonTradeRateInput | GetSolanaTradeRateInput | GetStarknetTradeRateInput | GetSuiTradeRateInput;
|
|
224
|
+
export type GetTradeQuoteInput = GetUtxoTradeQuoteInput | GetEvmTradeQuoteInput | GetCosmosSdkTradeQuoteInput | GetTronTradeQuoteInput | GetNearTradeQuoteInput | GetTonTradeQuoteInput | GetSolanaTradeQuoteInput | GetStarknetTradeQuoteInput | GetSuiTradeQuoteInput | GetAptosTradeQuoteInput;
|
|
225
|
+
export type GetTradeRateInput = GetEvmTradeRateInput | GetCosmosSdkTradeRateInput | GetUtxoTradeRateInput | GetTronTradeRateInput | GetNearTradeRateInput | GetTonTradeRateInput | GetSolanaTradeRateInput | GetStarknetTradeRateInput | GetSuiTradeRateInput | GetAptosTradeRateInput;
|
|
218
226
|
export type WithExactBuyAmount<T extends {
|
|
219
227
|
sellAmountIncludingProtocolFeesCryptoBaseUnit: string;
|
|
220
228
|
}> = T extends unknown ? Omit<T, 'sellAmountIncludingProtocolFeesCryptoBaseUnit'> & {
|
|
@@ -269,12 +277,15 @@ export type StarknetSwapperDeps = {
|
|
|
269
277
|
export type TonSwapperDeps = {
|
|
270
278
|
assertGetTonChainAdapter: (chainId: ChainId) => ton.ChainAdapter;
|
|
271
279
|
};
|
|
280
|
+
export type AptosSwapperDeps = {
|
|
281
|
+
assertGetAptosChainAdapter: (chainId: ChainId) => aptos.ChainAdapter;
|
|
282
|
+
};
|
|
272
283
|
export type SwapperDeps = {
|
|
273
284
|
assetsById: AssetsByIdPartial;
|
|
274
285
|
config: SwapperConfig;
|
|
275
286
|
mixPanel: Mixpanel | undefined;
|
|
276
287
|
assertGetChainAdapter: (chainId: ChainId) => ChainAdapter<KnownChainIds>;
|
|
277
|
-
} & EvmSwapperDeps & UtxoSwapperDeps & CosmosSdkSwapperDeps & SolanaSwapperDeps & TronSwapperDeps & SuiSwapperDeps & NearSwapperDeps & StarknetSwapperDeps & TonSwapperDeps;
|
|
288
|
+
} & EvmSwapperDeps & UtxoSwapperDeps & CosmosSdkSwapperDeps & SolanaSwapperDeps & TronSwapperDeps & SuiSwapperDeps & NearSwapperDeps & StarknetSwapperDeps & TonSwapperDeps & AptosSwapperDeps;
|
|
278
289
|
export type AffiliateFee = {
|
|
279
290
|
assetId: AssetId;
|
|
280
291
|
amountCryptoBaseUnit: string;
|
|
@@ -328,6 +339,11 @@ export type TxBuildData = {
|
|
|
328
339
|
value: string;
|
|
329
340
|
data?: string;
|
|
330
341
|
memo?: string;
|
|
342
|
+
} | {
|
|
343
|
+
type: 'aptos';
|
|
344
|
+
payload: string;
|
|
345
|
+
gasUnitPrice: string;
|
|
346
|
+
maxGasAmount: string;
|
|
331
347
|
} | {
|
|
332
348
|
type: 'cowswap';
|
|
333
349
|
chainId: ChainId;
|
|
@@ -515,6 +531,9 @@ export type StarknetTransactionExecutionProps = {
|
|
|
515
531
|
export type TonTransactionExecutionProps = {
|
|
516
532
|
signAndBroadcastTransaction: (txToSign: ton.TonSignTx) => Promise<string>;
|
|
517
533
|
};
|
|
534
|
+
export type AptosTransactionExecutionProps = {
|
|
535
|
+
signAndBroadcastTransaction: (txToSign: AptosSignTx) => Promise<string>;
|
|
536
|
+
};
|
|
518
537
|
type EvmAccountMetadata = {
|
|
519
538
|
from: string;
|
|
520
539
|
};
|
|
@@ -532,6 +551,7 @@ type NearAccountMetadata = {
|
|
|
532
551
|
};
|
|
533
552
|
type StarknetAccountMetadata = {
|
|
534
553
|
from: string;
|
|
554
|
+
callsOnly?: boolean;
|
|
535
555
|
};
|
|
536
556
|
type UtxoAccountMetadata = {
|
|
537
557
|
senderAddress: string;
|
|
@@ -561,6 +581,10 @@ type TonAccountMetadata = {
|
|
|
561
581
|
from: string;
|
|
562
582
|
};
|
|
563
583
|
export type GetUnsignedTonTransactionArgs = CommonGetUnsignedTransactionArgs & TonAccountMetadata & TonSwapperDeps;
|
|
584
|
+
type AptosAccountMetadata = {
|
|
585
|
+
from: string;
|
|
586
|
+
};
|
|
587
|
+
export type GetUnsignedAptosTransactionArgs = CommonGetUnsignedTransactionArgs & AptosAccountMetadata & AptosSwapperDeps;
|
|
564
588
|
export type GetUnsignedEvmMessageArgs = CommonGetUnsignedTransactionArgs & EvmAccountMetadata & Omit<EvmSwapperDeps, 'fetchIsSmartContractAddressQuery'>;
|
|
565
589
|
export type GetUnsignedSolanaMessageArgs = CommonGetUnsignedTransactionArgs;
|
|
566
590
|
export type GetUnsignedUtxoTransactionArgs = CommonGetUnsignedTransactionArgs & UtxoAccountMetadata & UtxoSwapperDeps;
|
|
@@ -572,7 +596,7 @@ export type CheckTradeStatusInput = {
|
|
|
572
596
|
stepIndex: SupportedTradeQuoteStepIndex;
|
|
573
597
|
config: SwapperConfig;
|
|
574
598
|
swap: Swap | undefined;
|
|
575
|
-
} & EvmSwapperDeps & UtxoSwapperDeps & CosmosSdkSwapperDeps & SolanaSwapperDeps & TronSwapperDeps & SuiSwapperDeps & NearSwapperDeps & StarknetSwapperDeps & TonSwapperDeps;
|
|
599
|
+
} & EvmSwapperDeps & UtxoSwapperDeps & CosmosSdkSwapperDeps & SolanaSwapperDeps & TronSwapperDeps & SuiSwapperDeps & NearSwapperDeps & StarknetSwapperDeps & TonSwapperDeps & AptosSwapperDeps;
|
|
576
600
|
export type TradeStatus = {
|
|
577
601
|
status: TxStatus;
|
|
578
602
|
buyTxHash: string | undefined;
|
|
@@ -598,6 +622,7 @@ export type Swapper = {
|
|
|
598
622
|
executeNearTransaction?: (txToSign: near.NearSignTx, callbacks: NearTransactionExecutionProps) => Promise<string>;
|
|
599
623
|
executeStarknetTransaction?: (txToSign: StarknetSignTx, callbacks: StarknetTransactionExecutionProps) => Promise<string>;
|
|
600
624
|
executeTonTransaction?: (txToSign: ton.TonSignTx, callbacks: TonTransactionExecutionProps) => Promise<string>;
|
|
625
|
+
executeAptosTransaction?: (txToSign: AptosSignTx, callbacks: AptosTransactionExecutionProps) => Promise<string>;
|
|
601
626
|
};
|
|
602
627
|
export type SwapperApi = {
|
|
603
628
|
checkTradeStatus: (input: CheckTradeStatusInput) => Promise<TradeStatus>;
|
|
@@ -616,6 +641,7 @@ export type SwapperApi = {
|
|
|
616
641
|
getUnsignedNearTransaction?: (input: GetUnsignedNearTransactionArgs) => Promise<near.NearSignTx>;
|
|
617
642
|
getUnsignedStarknetTransaction?: (input: GetUnsignedStarknetTransactionArgs) => Promise<StarknetSignTx>;
|
|
618
643
|
getUnsignedTonTransaction?: (input: GetUnsignedTonTransactionArgs) => Promise<ton.TonSignTx>;
|
|
644
|
+
getUnsignedAptosTransaction?: (input: GetUnsignedAptosTransactionArgs) => Promise<AptosSignTx>;
|
|
619
645
|
getEvmTransactionFees?: (input: GetUnsignedEvmTransactionArgs) => Promise<string>;
|
|
620
646
|
getSolanaTransactionFees?: (input: GetUnsignedSolanaTransactionArgs) => Promise<string>;
|
|
621
647
|
getSuiTransactionFees?: (input: GetUnsignedSuiTransactionArgs) => Promise<string>;
|
|
@@ -625,6 +651,7 @@ export type SwapperApi = {
|
|
|
625
651
|
getNearTransactionFees?: (input: GetUnsignedNearTransactionArgs) => Promise<string>;
|
|
626
652
|
getStarknetTransactionFees?: (input: GetUnsignedStarknetTransactionArgs) => Promise<string>;
|
|
627
653
|
getTonTransactionFees?: (input: GetUnsignedTonTransactionArgs) => Promise<string>;
|
|
654
|
+
getAptosTransactionFees?: (input: GetUnsignedAptosTransactionArgs) => Promise<string>;
|
|
628
655
|
};
|
|
629
656
|
export type QuoteResult = Result<TradeQuote[], SwapErrorRight> & {
|
|
630
657
|
swapperName: SwapperName;
|
|
@@ -653,6 +680,7 @@ export type SuiTransactionExecutionInput = CommonTradeExecutionInput & SuiTransa
|
|
|
653
680
|
export type NearTransactionExecutionInput = CommonTradeExecutionInput & NearTransactionExecutionProps & NearAccountMetadata;
|
|
654
681
|
export type StarknetTransactionExecutionInput = CommonTradeExecutionInput & StarknetTransactionExecutionProps & StarknetAccountMetadata;
|
|
655
682
|
export type TonTransactionExecutionInput = CommonTradeExecutionInput & TonTransactionExecutionProps & TonAccountMetadata;
|
|
683
|
+
export type AptosTransactionExecutionInput = CommonTradeExecutionInput & AptosTransactionExecutionProps & AptosAccountMetadata;
|
|
656
684
|
export declare enum TradeExecutionEvent {
|
|
657
685
|
SellTxHash = "sellTxHash",
|
|
658
686
|
Status = "status",
|
package/dist/esm/types.js
CHANGED
|
@@ -21,6 +21,7 @@ export var SwapperName;
|
|
|
21
21
|
SwapperName["BobGateway"] = "BOB Gateway";
|
|
22
22
|
SwapperName["Symbiosis"] = "Symbiosis";
|
|
23
23
|
SwapperName["Fynd"] = "Fynd";
|
|
24
|
+
SwapperName["KyberSwap"] = "KyberSwap";
|
|
24
25
|
})(SwapperName || (SwapperName = {}));
|
|
25
26
|
export var TradeQuoteError;
|
|
26
27
|
(function (TradeQuoteError) {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { getExecutableTradeStep, isExecutableTradeQuote } from '../../utils/index.js';
|
|
2
|
+
export const getAptosTransactionFees = ({ tradeQuote, stepIndex, }) => {
|
|
3
|
+
if (!isExecutableTradeQuote(tradeQuote))
|
|
4
|
+
throw new Error('Unable to execute a trade rate quote');
|
|
5
|
+
const step = getExecutableTradeStep(tradeQuote, stepIndex);
|
|
6
|
+
if (!step.feeData.networkFeeCryptoBaseUnit)
|
|
7
|
+
throw new Error('Missing network fee in quote');
|
|
8
|
+
return Promise.resolve(step.feeData.networkFeeCryptoBaseUnit);
|
|
9
|
+
};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import type { GetUnsignedAptosTransactionArgs } from '../../types.js';
|
|
2
|
+
export declare const getUnsignedAptosTransaction: ({ stepIndex, tradeQuote, from, assertGetAptosChainAdapter, }: GetUnsignedAptosTransactionArgs) => Promise<import("@shapeshiftoss/hdwallet-core").AptosSignTx>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { getExecutableTradeStep, isExecutableTradeQuote } from '../../utils/index.js';
|
|
2
|
+
export const getUnsignedAptosTransaction = ({ stepIndex, tradeQuote, from, assertGetAptosChainAdapter, }) => {
|
|
3
|
+
if (!isExecutableTradeQuote(tradeQuote))
|
|
4
|
+
throw new Error('Unable to execute a trade rate');
|
|
5
|
+
const step = getExecutableTradeStep(tradeQuote, stepIndex);
|
|
6
|
+
const { accountNumber, sellAsset, transactionData } = step;
|
|
7
|
+
if (transactionData?.type !== 'aptos')
|
|
8
|
+
throw new Error('Missing aptos transactionData');
|
|
9
|
+
const adapter = assertGetAptosChainAdapter(sellAsset.chainId);
|
|
10
|
+
const { payload, gasUnitPrice, maxGasAmount } = transactionData;
|
|
11
|
+
return adapter.buildCustomApiTx({ from, accountNumber, payload, gasUnitPrice, maxGasAmount });
|
|
12
|
+
};
|
|
@@ -1,22 +1,35 @@
|
|
|
1
1
|
import type { EvmChainAdapter } from '@shapeshiftoss/chain-adapters';
|
|
2
2
|
import type { Asset } from '@shapeshiftoss/types';
|
|
3
3
|
import type { TxBuildData } from '../../types.js';
|
|
4
|
-
|
|
4
|
+
export declare const EVM_GAS_LIMIT_BUFFER = 1.2;
|
|
5
|
+
export declare const bufferGasLimit: (gasLimit: string) => string;
|
|
6
|
+
export declare const isPositiveGasLimit: (gasLimit: string | null | undefined) => gasLimit is string;
|
|
7
|
+
type EvmFeeArgs = {
|
|
5
8
|
adapter: EvmChainAdapter;
|
|
6
9
|
supportsEIP1559: boolean;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
} | {
|
|
10
|
+
};
|
|
11
|
+
type EvmSimulationArgs = {
|
|
10
12
|
transactionData: Extract<TxBuildData, {
|
|
11
13
|
type: 'evm';
|
|
12
14
|
}>;
|
|
13
15
|
from: string;
|
|
14
|
-
gasLimitBuffer?: number;
|
|
15
16
|
stateOverride?: {
|
|
16
17
|
sellAsset: Asset;
|
|
17
18
|
sellAmountCryptoBaseUnit: string;
|
|
18
19
|
spenderAddress?: string;
|
|
19
20
|
};
|
|
20
|
-
}
|
|
21
|
+
};
|
|
22
|
+
type FixedGasLimitArgs = {
|
|
23
|
+
gasLimit: string;
|
|
24
|
+
};
|
|
25
|
+
type SimulatedGasLimitArgs = EvmSimulationArgs & {
|
|
26
|
+
providerGasLimit?: string | null;
|
|
27
|
+
};
|
|
28
|
+
type GetEvmNetworkFeeCryptoBaseUnitArgs = EvmFeeArgs & (FixedGasLimitArgs | SimulatedGasLimitArgs);
|
|
21
29
|
export declare const getEvmNetworkFeeCryptoBaseUnit: (args: GetEvmNetworkFeeCryptoBaseUnitArgs) => Promise<string>;
|
|
30
|
+
type GetEvmRateNetworkFeeCryptoBaseUnitArgs = EvmFeeArgs & {
|
|
31
|
+
providerGasLimit: string | null | undefined;
|
|
32
|
+
simulation?: EvmSimulationArgs;
|
|
33
|
+
};
|
|
34
|
+
export declare const getEvmRateNetworkFeeCryptoBaseUnit: ({ providerGasLimit, simulation, ...feeArgs }: GetEvmRateNetworkFeeCryptoBaseUnitArgs) => Promise<string>;
|
|
22
35
|
export {};
|
|
@@ -1,48 +1,55 @@
|
|
|
1
1
|
import { evm } from '@shapeshiftoss/chain-adapters';
|
|
2
2
|
import { bnOrZero } from '@shapeshiftoss/utils';
|
|
3
|
-
import { estimateGasWithStateOverride, getMinimalStateOverride, withTimeout } from './stateOverride.js';
|
|
3
|
+
import { estimateGasWithStateOverride, EstimationTimeoutError, getMinimalStateOverride, withTimeout, } from './stateOverride.js';
|
|
4
|
+
export const EVM_GAS_LIMIT_BUFFER = 1.2;
|
|
5
|
+
export const bufferGasLimit = (gasLimit) => bnOrZero(gasLimit).times(EVM_GAS_LIMIT_BUFFER).toFixed(0);
|
|
6
|
+
export const isPositiveGasLimit = (gasLimit) => bnOrZero(gasLimit).gt(0);
|
|
7
|
+
const priceGasLimit = async ({ adapter, supportsEIP1559 }, gasLimit) => {
|
|
8
|
+
const { average: gasPrices } = await adapter.getGasFeeData();
|
|
9
|
+
return evm.calcNetworkFeeCryptoBaseUnit({ ...gasPrices, supportsEIP1559, gasLimit });
|
|
10
|
+
};
|
|
11
|
+
// Prices the buffered limit, since the signer must hold enough to cover the full limit
|
|
4
12
|
export const getEvmNetworkFeeCryptoBaseUnit = async (args) => {
|
|
5
13
|
const { adapter, supportsEIP1559 } = args;
|
|
6
|
-
// Price a provider gas limit with fresh gas prices - no on chain estimation
|
|
7
|
-
const priceProviderGasLimit = async (gasLimit) => {
|
|
8
|
-
const { average: gasPrices } = await adapter.getGasFeeData();
|
|
9
|
-
return evm.calcNetworkFeeCryptoBaseUnit({ ...gasPrices, supportsEIP1559, gasLimit });
|
|
10
|
-
};
|
|
11
|
-
// Rate network fee: the caller passed a provider gas limit directly
|
|
12
14
|
if (!('transactionData' in args))
|
|
13
|
-
return
|
|
14
|
-
const { transactionData, from,
|
|
15
|
-
// Executable quote: the provider supplied a gas limit on the tx data, price it as-is
|
|
16
|
-
const providerGasLimit = transactionData.gasLimit;
|
|
17
|
-
if (providerGasLimit && bnOrZero(providerGasLimit).gt(0)) {
|
|
18
|
-
return priceProviderGasLimit(providerGasLimit);
|
|
19
|
-
}
|
|
15
|
+
return priceGasLimit(args, args.gasLimit);
|
|
16
|
+
const { transactionData, from, providerGasLimit } = args;
|
|
20
17
|
const { to, data, value } = transactionData;
|
|
21
18
|
if (args.stateOverride) {
|
|
22
19
|
const { sellAsset, sellAmountCryptoBaseUnit, spenderAddress } = args.stateOverride;
|
|
23
|
-
|
|
24
|
-
//
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
spenderAddress,
|
|
31
|
-
value,
|
|
32
|
-
};
|
|
33
|
-
const stateOverride = await getMinimalStateOverride(overrideArgs);
|
|
34
|
-
if (!stateOverride)
|
|
20
|
+
const overrideArgs = { sellAsset, sellAmountCryptoBaseUnit, from, spenderAddress, value };
|
|
21
|
+
// null when the override can't be built (an undiscoverable storage slot or a failed read),
|
|
22
|
+
// undefined when nothing needs overriding or the simulation timed out
|
|
23
|
+
const overriddenGasLimit = await withTimeout(getMinimalStateOverride(overrideArgs).then(stateOverride => stateOverride &&
|
|
24
|
+
estimateGasWithStateOverride({ ...overrideArgs, to, data, stateOverride }), () => null)).catch(error => {
|
|
25
|
+
// The missing state makes a plain estimate revert too, so only a timeout falls through to it
|
|
26
|
+
if (error instanceof EstimationTimeoutError)
|
|
35
27
|
return undefined;
|
|
36
|
-
|
|
37
|
-
})
|
|
28
|
+
throw error;
|
|
29
|
+
});
|
|
30
|
+
if (overriddenGasLimit === null && isPositiveGasLimit(providerGasLimit)) {
|
|
31
|
+
transactionData.gasLimit = bufferGasLimit(providerGasLimit);
|
|
32
|
+
return priceGasLimit(args, transactionData.gasLimit);
|
|
33
|
+
}
|
|
38
34
|
if (overriddenGasLimit) {
|
|
39
|
-
transactionData.gasLimit =
|
|
40
|
-
return
|
|
35
|
+
transactionData.gasLimit = bufferGasLimit(overriddenGasLimit);
|
|
36
|
+
return priceGasLimit(args, transactionData.gasLimit);
|
|
41
37
|
}
|
|
42
38
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
39
|
+
const { average: { chainSpecific: feeData }, } = await adapter.getFeeData({ to, value, chainSpecific: { from, data } });
|
|
40
|
+
transactionData.gasLimit = bufferGasLimit(feeData.gasLimit);
|
|
41
|
+
return evm.calcNetworkFeeCryptoBaseUnit({
|
|
42
|
+
...feeData,
|
|
43
|
+
supportsEIP1559,
|
|
44
|
+
gasLimit: transactionData.gasLimit,
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
// Rates price a provider's limit as given (it carries its own margin) and simulate without one
|
|
48
|
+
export const getEvmRateNetworkFeeCryptoBaseUnit = ({ providerGasLimit, simulation, ...feeArgs }) => {
|
|
49
|
+
if (isPositiveGasLimit(providerGasLimit)) {
|
|
50
|
+
return priceGasLimit(feeArgs, providerGasLimit);
|
|
51
|
+
}
|
|
52
|
+
if (simulation)
|
|
53
|
+
return getEvmNetworkFeeCryptoBaseUnit({ ...feeArgs, ...simulation });
|
|
54
|
+
return Promise.reject(new Error('no gas limit to price'));
|
|
48
55
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|