@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
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getKyberTradeQuote = void 0;
|
|
4
|
+
const monads_1 = require("@sniptt/monads");
|
|
5
|
+
const utils_1 = require("../../../utils");
|
|
6
|
+
const constants_1 = require("../utils/constants");
|
|
7
|
+
const fetchFromKyber_1 = require("../utils/fetchFromKyber");
|
|
8
|
+
const getKyberStepData_1 = require("../utils/getKyberStepData");
|
|
9
|
+
const getKyberTradeContext_1 = require("../utils/getKyberTradeContext");
|
|
10
|
+
const helpers_1 = require("../utils/helpers");
|
|
11
|
+
const getKyberTradeQuote = async (input, deps) => {
|
|
12
|
+
const { accountNumber } = input;
|
|
13
|
+
const maybeAddresses = (0, utils_1.assertQuoteAddresses)(input);
|
|
14
|
+
if (maybeAddresses.isErr())
|
|
15
|
+
return (0, monads_1.Err)(maybeAddresses.unwrapErr());
|
|
16
|
+
const { sendAddress, receiveAddress } = maybeAddresses.unwrap();
|
|
17
|
+
const maybeContext = await (0, getKyberTradeContext_1.getKyberTradeContext)({ input, deps });
|
|
18
|
+
if (maybeContext.isErr())
|
|
19
|
+
return (0, monads_1.Err)(maybeContext.unwrapErr());
|
|
20
|
+
const { tradeCommon, stepCommon, protocolFees, chainId, route, stepDataArgs } = maybeContext.unwrap();
|
|
21
|
+
const deadline = Math.floor(Date.now() / 1000) + constants_1.KYBER_DEADLINE_SECONDS;
|
|
22
|
+
const maybeBuild = await (0, fetchFromKyber_1.fetchKyberBuild)({
|
|
23
|
+
chainId,
|
|
24
|
+
route,
|
|
25
|
+
slippageTolerancePercentageDecimal: tradeCommon.slippageTolerancePercentageDecimal,
|
|
26
|
+
baseUrl: deps.config.VITE_KYBER_BASE_URL,
|
|
27
|
+
sendAddress,
|
|
28
|
+
receiveAddress,
|
|
29
|
+
deadline,
|
|
30
|
+
});
|
|
31
|
+
if (maybeBuild.isErr())
|
|
32
|
+
return (0, monads_1.Err)(maybeBuild.unwrapErr());
|
|
33
|
+
const build = maybeBuild.unwrap();
|
|
34
|
+
// Kyber re-prices at build time and derives the calldata's minimum return from the built amount
|
|
35
|
+
const tradeAmounts = (0, helpers_1.getKyberTradeAmounts)({ input, amountOut: build.amountOut });
|
|
36
|
+
const maybeStepData = await (0, getKyberStepData_1.getKyberStepData)({
|
|
37
|
+
...stepDataArgs,
|
|
38
|
+
type: 'quote',
|
|
39
|
+
input,
|
|
40
|
+
from: sendAddress,
|
|
41
|
+
build,
|
|
42
|
+
});
|
|
43
|
+
if (maybeStepData.isErr())
|
|
44
|
+
return (0, monads_1.Err)(maybeStepData.unwrapErr());
|
|
45
|
+
const { transactionData, networkFeeCryptoBaseUnit } = maybeStepData.unwrap();
|
|
46
|
+
const tradeQuote = {
|
|
47
|
+
...tradeCommon,
|
|
48
|
+
rate: tradeAmounts.rate,
|
|
49
|
+
quoteOrRate: 'quote',
|
|
50
|
+
receiveAddress,
|
|
51
|
+
deadline: deadline * 1000,
|
|
52
|
+
steps: [
|
|
53
|
+
{
|
|
54
|
+
...stepCommon,
|
|
55
|
+
...tradeAmounts,
|
|
56
|
+
accountNumber,
|
|
57
|
+
transactionData,
|
|
58
|
+
feeData: { networkFeeCryptoBaseUnit, protocolFees },
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
};
|
|
62
|
+
return (0, monads_1.Ok)([tradeQuote]);
|
|
63
|
+
};
|
|
64
|
+
exports.getKyberTradeQuote = getKyberTradeQuote;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Result } from '@sniptt/monads';
|
|
2
|
+
import type { SwapErrorRight, SwapperDeps, TradeRate } from '../../../types';
|
|
3
|
+
import type { KyberTradeRateInput } from '../types';
|
|
4
|
+
export declare const getKyberTradeRate: (input: KyberTradeRateInput, deps: SwapperDeps) => Promise<Result<TradeRate[], SwapErrorRight>>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getKyberTradeRate = void 0;
|
|
4
|
+
const monads_1 = require("@sniptt/monads");
|
|
5
|
+
const getKyberStepData_1 = require("../utils/getKyberStepData");
|
|
6
|
+
const getKyberTradeContext_1 = require("../utils/getKyberTradeContext");
|
|
7
|
+
const getKyberTradeRate = async (input, deps) => {
|
|
8
|
+
const { accountNumber, receiveAddress } = input;
|
|
9
|
+
const maybeContext = await (0, getKyberTradeContext_1.getKyberTradeContext)({ input, deps });
|
|
10
|
+
if (maybeContext.isErr())
|
|
11
|
+
return (0, monads_1.Err)(maybeContext.unwrapErr());
|
|
12
|
+
const { tradeCommon, stepCommon, protocolFees, stepDataArgs } = maybeContext.unwrap();
|
|
13
|
+
const maybeStepData = await (0, getKyberStepData_1.getKyberStepData)({ ...stepDataArgs, type: 'rate', input });
|
|
14
|
+
if (maybeStepData.isErr())
|
|
15
|
+
return (0, monads_1.Err)(maybeStepData.unwrapErr());
|
|
16
|
+
const { networkFeeCryptoBaseUnit } = maybeStepData.unwrap();
|
|
17
|
+
const tradeRate = {
|
|
18
|
+
...tradeCommon,
|
|
19
|
+
quoteOrRate: 'rate',
|
|
20
|
+
receiveAddress,
|
|
21
|
+
steps: [
|
|
22
|
+
{
|
|
23
|
+
...stepCommon,
|
|
24
|
+
accountNumber,
|
|
25
|
+
feeData: { networkFeeCryptoBaseUnit, protocolFees },
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
};
|
|
29
|
+
return (0, monads_1.Ok)([tradeRate]);
|
|
30
|
+
};
|
|
31
|
+
exports.getKyberTradeRate = getKyberTradeRate;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { Address, Hex } from 'viem';
|
|
2
|
+
import type { GetEvmTradeQuoteInput, GetEvmTradeRateInput } from '../../types';
|
|
3
|
+
export type KyberTradeQuoteInput = GetEvmTradeQuoteInput;
|
|
4
|
+
export type KyberTradeRateInput = GetEvmTradeRateInput;
|
|
5
|
+
export type KyberExtraFee = {
|
|
6
|
+
feeAmount: string;
|
|
7
|
+
chargeFeeBy: '' | 'currency_in' | 'currency_out';
|
|
8
|
+
isInBps: boolean;
|
|
9
|
+
feeReceiver: string;
|
|
10
|
+
};
|
|
11
|
+
export type KyberFeeParams = {
|
|
12
|
+
feeAmount: string;
|
|
13
|
+
chargeFeeBy: 'currency_out';
|
|
14
|
+
isInBps: true;
|
|
15
|
+
feeReceiver: Address;
|
|
16
|
+
};
|
|
17
|
+
export type KyberRouteSummary = {
|
|
18
|
+
tokenIn: string;
|
|
19
|
+
amountIn: string;
|
|
20
|
+
amountInUsd: string;
|
|
21
|
+
tokenOut: string;
|
|
22
|
+
amountOut: string;
|
|
23
|
+
amountOutUsd: string;
|
|
24
|
+
gas: string;
|
|
25
|
+
gasPrice: string;
|
|
26
|
+
gasUsd: string;
|
|
27
|
+
l1FeeUsd: string;
|
|
28
|
+
extraFee: KyberExtraFee;
|
|
29
|
+
route: unknown;
|
|
30
|
+
routerAddress: Address;
|
|
31
|
+
routeID: string;
|
|
32
|
+
checksum: string;
|
|
33
|
+
timestamp: number;
|
|
34
|
+
};
|
|
35
|
+
export type KyberRouteData = {
|
|
36
|
+
routeSummary: KyberRouteSummary;
|
|
37
|
+
routerAddress: Address;
|
|
38
|
+
};
|
|
39
|
+
export type KyberRoutesResponse = {
|
|
40
|
+
code: number;
|
|
41
|
+
message: string;
|
|
42
|
+
data?: KyberRouteData;
|
|
43
|
+
requestId: string;
|
|
44
|
+
};
|
|
45
|
+
export type KyberBuildData = {
|
|
46
|
+
amountOut: string;
|
|
47
|
+
gas: string;
|
|
48
|
+
data: Hex;
|
|
49
|
+
routerAddress: Address;
|
|
50
|
+
transactionValue: string;
|
|
51
|
+
};
|
|
52
|
+
export type KyberBuildResponse = {
|
|
53
|
+
code: number;
|
|
54
|
+
message: string;
|
|
55
|
+
data?: KyberBuildData;
|
|
56
|
+
requestId: string;
|
|
57
|
+
};
|
|
58
|
+
export type KyberErrorResponse = {
|
|
59
|
+
code: number;
|
|
60
|
+
message: string;
|
|
61
|
+
requestId?: string;
|
|
62
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Address } from 'viem';
|
|
2
|
+
export declare const KYBER_CLIENT_ID = "shapeshift";
|
|
3
|
+
export declare const KYBER_DEADLINE_SECONDS = 1200;
|
|
4
|
+
export declare const KYBER_CHAINS: {
|
|
5
|
+
readonly "eip155:1": "ethereum";
|
|
6
|
+
readonly "eip155:10": "optimism";
|
|
7
|
+
readonly "eip155:56": "bsc";
|
|
8
|
+
readonly "eip155:137": "polygon";
|
|
9
|
+
readonly "eip155:42161": "arbitrum";
|
|
10
|
+
readonly "eip155:8453": "base";
|
|
11
|
+
readonly "eip155:43114": "avalanche";
|
|
12
|
+
readonly "eip155:130": "unichain";
|
|
13
|
+
readonly "eip155:4663": "robinhood";
|
|
14
|
+
readonly "eip155:143": "monad";
|
|
15
|
+
readonly "eip155:999": "hyperevm";
|
|
16
|
+
readonly "eip155:4326": "megaeth";
|
|
17
|
+
readonly "eip155:9745": "plasma";
|
|
18
|
+
readonly "eip155:99901": "elysium";
|
|
19
|
+
};
|
|
20
|
+
export type KyberSupportedChainId = keyof typeof KYBER_CHAINS;
|
|
21
|
+
export declare const KYBER_ROUTER_ADDRESS: Address;
|
|
22
|
+
export declare const KYBER_NATIVE_TOKEN: Address;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.KYBER_NATIVE_TOKEN = exports.KYBER_ROUTER_ADDRESS = exports.KYBER_CHAINS = exports.KYBER_DEADLINE_SECONDS = exports.KYBER_CLIENT_ID = void 0;
|
|
4
|
+
const types_1 = require("@shapeshiftoss/types");
|
|
5
|
+
exports.KYBER_CLIENT_ID = 'shapeshift';
|
|
6
|
+
exports.KYBER_DEADLINE_SECONDS = 1200;
|
|
7
|
+
exports.KYBER_CHAINS = {
|
|
8
|
+
[types_1.KnownChainIds.EthereumMainnet]: 'ethereum',
|
|
9
|
+
[types_1.KnownChainIds.OptimismMainnet]: 'optimism',
|
|
10
|
+
[types_1.KnownChainIds.BnbSmartChainMainnet]: 'bsc',
|
|
11
|
+
[types_1.KnownChainIds.PolygonMainnet]: 'polygon',
|
|
12
|
+
[types_1.KnownChainIds.ArbitrumMainnet]: 'arbitrum',
|
|
13
|
+
[types_1.KnownChainIds.BaseMainnet]: 'base',
|
|
14
|
+
[types_1.KnownChainIds.AvalancheMainnet]: 'avalanche',
|
|
15
|
+
[types_1.KnownChainIds.UnichainMainnet]: 'unichain',
|
|
16
|
+
[types_1.KnownChainIds.RobinhoodMainnet]: 'robinhood',
|
|
17
|
+
[types_1.KnownChainIds.MonadMainnet]: 'monad',
|
|
18
|
+
[types_1.KnownChainIds.HyperEvmMainnet]: 'hyperevm',
|
|
19
|
+
[types_1.KnownChainIds.MegaEthMainnet]: 'megaeth',
|
|
20
|
+
[types_1.KnownChainIds.PlasmaMainnet]: 'plasma',
|
|
21
|
+
[types_1.KnownChainIds.ElysiumMainnet]: 'elysium',
|
|
22
|
+
};
|
|
23
|
+
// MetaAggregationRouterV2, same address on every chain: https://docs.kyberswap.com/developer-guide/aggregator-api/contracts
|
|
24
|
+
exports.KYBER_ROUTER_ADDRESS = '0x6131B5fae19EA4f9D964eAc0408E4408b66337b5';
|
|
25
|
+
exports.KYBER_NATIVE_TOKEN = '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Result } from '@sniptt/monads';
|
|
2
|
+
import type { Address } from 'viem';
|
|
3
|
+
import type { SwapErrorRight } from '../../../types';
|
|
4
|
+
import type { KyberBuildData, KyberFeeParams, KyberRouteSummary } from '../types';
|
|
5
|
+
import type { KyberSupportedChainId } from './constants';
|
|
6
|
+
export declare const fetchKyberRoute: ({ chainId, tokenIn, tokenOut, sellAmountCryptoBaseUnit, feeParams, sendAddress, baseUrl, }: {
|
|
7
|
+
chainId: KyberSupportedChainId;
|
|
8
|
+
tokenIn: Address;
|
|
9
|
+
tokenOut: Address;
|
|
10
|
+
sellAmountCryptoBaseUnit: string;
|
|
11
|
+
feeParams: KyberFeeParams | undefined;
|
|
12
|
+
sendAddress: string | undefined;
|
|
13
|
+
baseUrl: string;
|
|
14
|
+
}) => Promise<Result<KyberRouteSummary, SwapErrorRight>>;
|
|
15
|
+
export declare const fetchKyberBuild: ({ chainId, route, slippageTolerancePercentageDecimal, baseUrl, sendAddress, receiveAddress, deadline, }: {
|
|
16
|
+
chainId: KyberSupportedChainId;
|
|
17
|
+
route: KyberRouteSummary;
|
|
18
|
+
slippageTolerancePercentageDecimal: string;
|
|
19
|
+
baseUrl: string;
|
|
20
|
+
sendAddress: string;
|
|
21
|
+
receiveAddress: string;
|
|
22
|
+
deadline: number;
|
|
23
|
+
}) => Promise<Result<KyberBuildData, SwapErrorRight>>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchKyberBuild = exports.fetchKyberRoute = void 0;
|
|
4
|
+
const utils_1 = require("@shapeshiftoss/utils");
|
|
5
|
+
const monads_1 = require("@sniptt/monads");
|
|
6
|
+
const constants_1 = require("./constants");
|
|
7
|
+
const helpers_1 = require("./helpers");
|
|
8
|
+
const kyberService_1 = require("./kyberService");
|
|
9
|
+
const fetchKyberRoute = async ({ chainId, tokenIn, tokenOut, sellAmountCryptoBaseUnit, feeParams, sendAddress, baseUrl, }) => {
|
|
10
|
+
const maybeResponse = await kyberService_1.kyberService.get(`${baseUrl}/${constants_1.KYBER_CHAINS[chainId]}/api/v1/routes`, {
|
|
11
|
+
params: {
|
|
12
|
+
tokenIn,
|
|
13
|
+
tokenOut,
|
|
14
|
+
amountIn: sellAmountCryptoBaseUnit,
|
|
15
|
+
...(sendAddress ? { origin: sendAddress } : {}),
|
|
16
|
+
...feeParams,
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
if (maybeResponse.isErr())
|
|
20
|
+
return (0, monads_1.Err)((0, helpers_1.getKyberRequestError)(maybeResponse.unwrapErr()));
|
|
21
|
+
return (0, helpers_1.validateKyberRoute)(maybeResponse.unwrap().data, feeParams);
|
|
22
|
+
};
|
|
23
|
+
exports.fetchKyberRoute = fetchKyberRoute;
|
|
24
|
+
const fetchKyberBuild = async ({ chainId, route, slippageTolerancePercentageDecimal, baseUrl, sendAddress, receiveAddress, deadline, }) => {
|
|
25
|
+
const maybeResponse = await kyberService_1.kyberService.post(`${baseUrl}/${constants_1.KYBER_CHAINS[chainId]}/api/v1/route/build`, {
|
|
26
|
+
routeSummary: route,
|
|
27
|
+
sender: sendAddress,
|
|
28
|
+
recipient: receiveAddress,
|
|
29
|
+
origin: sendAddress,
|
|
30
|
+
slippageTolerance: (0, utils_1.convertDecimalPercentageToBasisPoints)(slippageTolerancePercentageDecimal).toNumber(),
|
|
31
|
+
deadline,
|
|
32
|
+
source: constants_1.KYBER_CLIENT_ID,
|
|
33
|
+
});
|
|
34
|
+
if (maybeResponse.isErr())
|
|
35
|
+
return (0, monads_1.Err)((0, helpers_1.getKyberRequestError)(maybeResponse.unwrapErr()));
|
|
36
|
+
return (0, helpers_1.validateKyberBuild)(maybeResponse.unwrap().data);
|
|
37
|
+
};
|
|
38
|
+
exports.fetchKyberBuild = fetchKyberBuild;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Result } from '@sniptt/monads';
|
|
2
|
+
import type { StepDataArgs, SwapErrorRight, TxBuildData } from '../../../types';
|
|
3
|
+
import type { KyberBuildData, KyberRouteSummary } from '../types';
|
|
4
|
+
type BaseArgs = {
|
|
5
|
+
sellAmountCryptoBaseUnit: string;
|
|
6
|
+
spenderAddress: string;
|
|
7
|
+
route: KyberRouteSummary;
|
|
8
|
+
};
|
|
9
|
+
export type GetKyberStepDataArgs = StepDataArgs<BaseArgs, {
|
|
10
|
+
build?: undefined;
|
|
11
|
+
}, {
|
|
12
|
+
build: KyberBuildData;
|
|
13
|
+
}>;
|
|
14
|
+
type KyberRateStepData = {
|
|
15
|
+
networkFeeCryptoBaseUnit: string;
|
|
16
|
+
};
|
|
17
|
+
type KyberQuoteStepData = {
|
|
18
|
+
transactionData: TxBuildData;
|
|
19
|
+
networkFeeCryptoBaseUnit: string;
|
|
20
|
+
};
|
|
21
|
+
export declare function getKyberStepData(args: Extract<GetKyberStepDataArgs, {
|
|
22
|
+
type: 'rate';
|
|
23
|
+
}>): Promise<Result<KyberRateStepData, SwapErrorRight>>;
|
|
24
|
+
export declare function getKyberStepData(args: Extract<GetKyberStepDataArgs, {
|
|
25
|
+
type: 'quote';
|
|
26
|
+
}>): Promise<Result<KyberQuoteStepData, SwapErrorRight>>;
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getKyberStepData = void 0;
|
|
4
|
+
const caip_1 = require("@shapeshiftoss/caip");
|
|
5
|
+
const utils_1 = require("@shapeshiftoss/utils");
|
|
6
|
+
const monads_1 = require("@sniptt/monads");
|
|
7
|
+
const utils_2 = require("../../../utils");
|
|
8
|
+
const evm_1 = require("../../../utils/evm");
|
|
9
|
+
const constants_1 = require("./constants");
|
|
10
|
+
async function getKyberStepData(args) {
|
|
11
|
+
const { sellAsset, sellAmountCryptoBaseUnit, spenderAddress, route, input, deps } = args;
|
|
12
|
+
const adapter = deps.assertGetEvmChainAdapter(sellAsset.chainId);
|
|
13
|
+
const supportsEIP1559 = 'supportsEIP1559' in input ? input.supportsEIP1559 : false;
|
|
14
|
+
if (args.type === 'rate') {
|
|
15
|
+
const networkFeeCryptoBaseUnit = await (0, evm_1.getEvmRateNetworkFeeCryptoBaseUnit)({
|
|
16
|
+
adapter,
|
|
17
|
+
supportsEIP1559,
|
|
18
|
+
providerGasLimit: route.gas,
|
|
19
|
+
}).catch(() => (0, utils_1.bnOrZero)(route.gas).times((0, utils_1.bnOrZero)(route.gasPrice)).toFixed(0));
|
|
20
|
+
const stepData = { networkFeeCryptoBaseUnit };
|
|
21
|
+
return (0, monads_1.Ok)(stepData);
|
|
22
|
+
}
|
|
23
|
+
const { build, from } = args;
|
|
24
|
+
const transactionData = {
|
|
25
|
+
type: 'evm',
|
|
26
|
+
chainId: Number((0, caip_1.fromChainId)(sellAsset.chainId).chainReference),
|
|
27
|
+
to: constants_1.KYBER_ROUTER_ADDRESS,
|
|
28
|
+
data: build.data,
|
|
29
|
+
value: build.transactionValue,
|
|
30
|
+
};
|
|
31
|
+
try {
|
|
32
|
+
const networkFeeCryptoBaseUnit = await (0, evm_1.getEvmNetworkFeeCryptoBaseUnit)({
|
|
33
|
+
adapter,
|
|
34
|
+
supportsEIP1559,
|
|
35
|
+
transactionData,
|
|
36
|
+
from,
|
|
37
|
+
stateOverride: { sellAsset, sellAmountCryptoBaseUnit, spenderAddress },
|
|
38
|
+
providerGasLimit: build.gas,
|
|
39
|
+
});
|
|
40
|
+
const stepData = { transactionData, networkFeeCryptoBaseUnit };
|
|
41
|
+
return (0, monads_1.Ok)(stepData);
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
return (0, monads_1.Err)((0, utils_2.makeNetworkFeeEstimationFailedErr)('getKyberStepData', error));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.getKyberStepData = getKyberStepData;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const types_1 = require("@shapeshiftoss/types");
|
|
4
|
+
const vitest_1 = require("vitest");
|
|
5
|
+
const assets_1 = require("../../../utils/test-data/assets");
|
|
6
|
+
const constants_1 = require("./constants");
|
|
7
|
+
const getKyberStepData_1 = require("./getKyberStepData");
|
|
8
|
+
// The override path reads live chain state, so resolve to no override and hit the mocked adapter
|
|
9
|
+
vitest_1.vi.mock('../../../utils/evm/stateOverride', async (importOriginal) => ({
|
|
10
|
+
...(await importOriginal()),
|
|
11
|
+
getMinimalStateOverride: vitest_1.vi.fn().mockResolvedValue(undefined),
|
|
12
|
+
}));
|
|
13
|
+
const HYPE = {
|
|
14
|
+
...assets_1.ETH,
|
|
15
|
+
assetId: 'eip155:999/slip44:60',
|
|
16
|
+
chainId: types_1.KnownChainIds.HyperEvmMainnet,
|
|
17
|
+
symbol: 'HYPE',
|
|
18
|
+
name: 'HYPE',
|
|
19
|
+
};
|
|
20
|
+
const build = {
|
|
21
|
+
amountOut: '255332539',
|
|
22
|
+
gas: '679101',
|
|
23
|
+
data: '0xe21fd0e9',
|
|
24
|
+
routerAddress: '0x6131B5fae19EA4f9D964eAc0408E4408b66337b5',
|
|
25
|
+
transactionValue: '3000000000000000000',
|
|
26
|
+
};
|
|
27
|
+
const makeDeps = (adapter) => ({ assertGetEvmChainAdapter: () => adapter });
|
|
28
|
+
const evmAdapter = ({ gasPrice = '1000000000', estimatedGasLimit = '500000', throwOnGasFeeData = false, throwOnFeeData = false, } = {}) => ({
|
|
29
|
+
getGasFeeData: () => {
|
|
30
|
+
if (throwOnGasFeeData)
|
|
31
|
+
return Promise.reject(new Error('rpc down'));
|
|
32
|
+
return Promise.resolve({ average: { gasPrice, maxFeePerGas: '0', maxPriorityFeePerGas: '0' } });
|
|
33
|
+
},
|
|
34
|
+
getFeeData: () => {
|
|
35
|
+
if (throwOnFeeData)
|
|
36
|
+
return Promise.reject(new Error('execution reverted'));
|
|
37
|
+
return Promise.resolve({
|
|
38
|
+
average: { chainSpecific: { gasLimit: estimatedGasLimit, gasPrice } },
|
|
39
|
+
});
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
const rateInput = { supportsEIP1559: false };
|
|
43
|
+
const quoteInput = { supportsEIP1559: false };
|
|
44
|
+
const baseArgs = {
|
|
45
|
+
sellAsset: HYPE,
|
|
46
|
+
sellAmountCryptoBaseUnit: '3000000000000000000',
|
|
47
|
+
spenderAddress: '',
|
|
48
|
+
route: { gas: '679101', gasPrice: '2000000000' },
|
|
49
|
+
};
|
|
50
|
+
(0, vitest_1.describe)('getKyberStepData', () => {
|
|
51
|
+
(0, vitest_1.it)('prices the provider gas limit for a rate', async () => {
|
|
52
|
+
const actual = await (0, getKyberStepData_1.getKyberStepData)({
|
|
53
|
+
...baseArgs,
|
|
54
|
+
type: 'rate',
|
|
55
|
+
input: rateInput,
|
|
56
|
+
deps: makeDeps(evmAdapter()),
|
|
57
|
+
});
|
|
58
|
+
// gas 679101 * gasPrice 1000000000
|
|
59
|
+
(0, vitest_1.expect)(actual.unwrap()).toEqual({ networkFeeCryptoBaseUnit: '679101000000000' });
|
|
60
|
+
});
|
|
61
|
+
(0, vitest_1.it)('falls back to the provider gas price when rate pricing fails', async () => {
|
|
62
|
+
const actual = await (0, getKyberStepData_1.getKyberStepData)({
|
|
63
|
+
...baseArgs,
|
|
64
|
+
type: 'rate',
|
|
65
|
+
input: rateInput,
|
|
66
|
+
deps: makeDeps(evmAdapter({ throwOnGasFeeData: true })),
|
|
67
|
+
});
|
|
68
|
+
// gas 679101 * provider gasPrice 2000000000
|
|
69
|
+
(0, vitest_1.expect)(actual.unwrap()).toEqual({ networkFeeCryptoBaseUnit: '1358202000000000' });
|
|
70
|
+
});
|
|
71
|
+
(0, vitest_1.it)('builds the router transaction and sets the buffered on chain estimate for a quote', async () => {
|
|
72
|
+
const actual = await (0, getKyberStepData_1.getKyberStepData)({
|
|
73
|
+
...baseArgs,
|
|
74
|
+
type: 'quote',
|
|
75
|
+
input: quoteInput,
|
|
76
|
+
from: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045',
|
|
77
|
+
build,
|
|
78
|
+
deps: makeDeps(evmAdapter({ estimatedGasLimit: '500000' })),
|
|
79
|
+
});
|
|
80
|
+
(0, vitest_1.expect)(actual.unwrap()).toEqual({
|
|
81
|
+
networkFeeCryptoBaseUnit: '600000000000000',
|
|
82
|
+
transactionData: {
|
|
83
|
+
type: 'evm',
|
|
84
|
+
chainId: 999,
|
|
85
|
+
to: constants_1.KYBER_ROUTER_ADDRESS,
|
|
86
|
+
data: build.data,
|
|
87
|
+
value: '3000000000000000000',
|
|
88
|
+
gasLimit: '600000',
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Result } from '@sniptt/monads';
|
|
2
|
+
import type { QuoteFeeData, SwapErrorRight, SwapperDeps, TradeCommon, TradeStepCommon } from '../../../types';
|
|
3
|
+
import type { KyberRouteSummary, KyberTradeQuoteInput, KyberTradeRateInput } from '../types';
|
|
4
|
+
import type { KyberSupportedChainId } from './constants';
|
|
5
|
+
import type { GetKyberStepDataArgs } from './getKyberStepData';
|
|
6
|
+
type KyberTradeContext = {
|
|
7
|
+
tradeCommon: TradeCommon & {
|
|
8
|
+
slippageTolerancePercentageDecimal: string;
|
|
9
|
+
};
|
|
10
|
+
stepCommon: Omit<TradeStepCommon, 'feeData'>;
|
|
11
|
+
protocolFees: QuoteFeeData['protocolFees'];
|
|
12
|
+
chainId: KyberSupportedChainId;
|
|
13
|
+
route: KyberRouteSummary;
|
|
14
|
+
stepDataArgs: Omit<GetKyberStepDataArgs, 'type' | 'input' | 'from' | 'build'>;
|
|
15
|
+
};
|
|
16
|
+
export declare const getKyberTradeContext: ({ input, deps, }: {
|
|
17
|
+
input: KyberTradeQuoteInput | KyberTradeRateInput;
|
|
18
|
+
deps: SwapperDeps;
|
|
19
|
+
}) => Promise<Result<KyberTradeContext, SwapErrorRight>>;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getKyberTradeContext = void 0;
|
|
4
|
+
const monads_1 = require("@sniptt/monads");
|
|
5
|
+
const uuid_1 = require("uuid");
|
|
6
|
+
const constants_1 = require("../../../constants");
|
|
7
|
+
const types_1 = require("../../../types");
|
|
8
|
+
const helpers_1 = require("../../../utils/helpers");
|
|
9
|
+
const constants_2 = require("./constants");
|
|
10
|
+
const fetchFromKyber_1 = require("./fetchFromKyber");
|
|
11
|
+
const helpers_2 = require("./helpers");
|
|
12
|
+
const getKyberTradeContext = async ({ input, deps, }) => {
|
|
13
|
+
const { sellAsset, buyAsset, sellAmountIncludingProtocolFeesCryptoBaseUnit, affiliateBps, sendAddress, } = input;
|
|
14
|
+
const maybeChainId = (0, helpers_2.assertValidTrade)({ sellAsset, buyAsset });
|
|
15
|
+
if (maybeChainId.isErr())
|
|
16
|
+
return (0, monads_1.Err)(maybeChainId.unwrapErr());
|
|
17
|
+
const chainId = maybeChainId.unwrap();
|
|
18
|
+
const slippageTolerancePercentageDecimal = input.slippageTolerancePercentageDecimal ??
|
|
19
|
+
(0, constants_1.getDefaultSlippageDecimalPercentageForSwapper)(types_1.SwapperName.KyberSwap);
|
|
20
|
+
const maybeRoute = await (0, fetchFromKyber_1.fetchKyberRoute)({
|
|
21
|
+
chainId,
|
|
22
|
+
tokenIn: (0, helpers_2.assetIdToKyberToken)(sellAsset.assetId),
|
|
23
|
+
tokenOut: (0, helpers_2.assetIdToKyberToken)(buyAsset.assetId),
|
|
24
|
+
sellAmountCryptoBaseUnit: sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
25
|
+
feeParams: (0, helpers_2.getKyberFeeParams)({ chainId, affiliateBps }),
|
|
26
|
+
sendAddress,
|
|
27
|
+
baseUrl: deps.config.VITE_KYBER_BASE_URL,
|
|
28
|
+
});
|
|
29
|
+
if (maybeRoute.isErr())
|
|
30
|
+
return (0, monads_1.Err)(maybeRoute.unwrapErr());
|
|
31
|
+
const route = maybeRoute.unwrap();
|
|
32
|
+
const tradeAmounts = (0, helpers_2.getKyberTradeAmounts)({ input, amountOut: route.amountOut });
|
|
33
|
+
const allowanceContract = (0, helpers_1.isNativeEvmAsset)(sellAsset.assetId) ? '' : constants_2.KYBER_ROUTER_ADDRESS;
|
|
34
|
+
return (0, monads_1.Ok)({
|
|
35
|
+
tradeCommon: {
|
|
36
|
+
id: (0, uuid_1.v4)(),
|
|
37
|
+
rate: tradeAmounts.rate,
|
|
38
|
+
swapperName: types_1.SwapperName.KyberSwap,
|
|
39
|
+
affiliateBps,
|
|
40
|
+
slippageTolerancePercentageDecimal,
|
|
41
|
+
},
|
|
42
|
+
stepCommon: {
|
|
43
|
+
estimatedExecutionTimeMs: 0,
|
|
44
|
+
allowanceContract,
|
|
45
|
+
sellAsset,
|
|
46
|
+
buyAsset,
|
|
47
|
+
sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
48
|
+
...tradeAmounts,
|
|
49
|
+
source: types_1.SwapperName.KyberSwap,
|
|
50
|
+
},
|
|
51
|
+
protocolFees: {},
|
|
52
|
+
chainId,
|
|
53
|
+
route,
|
|
54
|
+
stepDataArgs: {
|
|
55
|
+
deps,
|
|
56
|
+
sellAsset,
|
|
57
|
+
sellAmountCryptoBaseUnit: sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
58
|
+
spenderAddress: allowanceContract,
|
|
59
|
+
route,
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
exports.getKyberTradeContext = getKyberTradeContext;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { AssetId } from '@shapeshiftoss/caip';
|
|
2
|
+
import type { Asset } from '@shapeshiftoss/types';
|
|
3
|
+
import type { Result } from '@sniptt/monads';
|
|
4
|
+
import type { Address } from 'viem';
|
|
5
|
+
import type { SwapErrorRight, TradeStepCommon } from '../../../types';
|
|
6
|
+
import type { KyberBuildData, KyberBuildResponse, KyberFeeParams, KyberRoutesResponse, KyberRouteSummary, KyberTradeQuoteInput, KyberTradeRateInput } from '../types';
|
|
7
|
+
import type { KyberSupportedChainId } from './constants';
|
|
8
|
+
export declare const assertValidTrade: ({ sellAsset, buyAsset, }: {
|
|
9
|
+
sellAsset: Asset;
|
|
10
|
+
buyAsset: Asset;
|
|
11
|
+
}) => Result<KyberSupportedChainId, SwapErrorRight>;
|
|
12
|
+
export declare const assetIdToKyberToken: (assetId: AssetId) => Address;
|
|
13
|
+
export declare const getKyberFeeParams: ({ chainId, affiliateBps, }: {
|
|
14
|
+
chainId: KyberSupportedChainId;
|
|
15
|
+
affiliateBps: string;
|
|
16
|
+
}) => KyberFeeParams | undefined;
|
|
17
|
+
export declare const getKyberBuyAmountBeforeFees: ({ buyAmountAfterFeesCryptoBaseUnit, affiliateBps, }: {
|
|
18
|
+
buyAmountAfterFeesCryptoBaseUnit: string;
|
|
19
|
+
affiliateBps: string;
|
|
20
|
+
}) => string;
|
|
21
|
+
export declare const getKyberTradeAmounts: ({ input, amountOut, }: {
|
|
22
|
+
input: KyberTradeQuoteInput | KyberTradeRateInput;
|
|
23
|
+
amountOut: string;
|
|
24
|
+
}) => Pick<TradeStepCommon, 'rate' | 'buyAmountBeforeFeesCryptoBaseUnit' | 'buyAmountAfterFeesCryptoBaseUnit' | 'affiliateFee'>;
|
|
25
|
+
export declare const getKyberRequestError: (error: SwapErrorRight) => SwapErrorRight;
|
|
26
|
+
export declare const validateKyberRoute: (response: KyberRoutesResponse, feeParams: KyberFeeParams | undefined) => Result<KyberRouteSummary, SwapErrorRight>;
|
|
27
|
+
export declare const validateKyberBuild: (response: KyberBuildResponse) => Result<KyberBuildData, SwapErrorRight>;
|