@tokenlon/v6-sdk 1.4.1 → 1.5.0-canary.7ff7a50
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/actions/public/getDecimals.js.map +1 -1
- package/dist/cjs/addressBook.js +12 -42
- package/dist/cjs/addressBook.js.map +1 -1
- package/dist/cjs/constants/abis/IERC20.js +226 -0
- package/dist/cjs/constants/abis/IERC20.js.map +1 -0
- package/dist/cjs/constants/abis/allowance.js +22 -0
- package/dist/cjs/constants/abis/allowance.js.map +1 -0
- package/dist/cjs/constants/abis/genericSwap.js +220 -0
- package/dist/cjs/constants/abis/genericSwap.js.map +1 -0
- package/dist/cjs/constants/abis/gsEIP712Types.js +48 -0
- package/dist/cjs/constants/abis/gsEIP712Types.js.map +1 -0
- package/dist/cjs/constants/abis/index.js +25 -0
- package/dist/cjs/constants/abis/index.js.map +1 -0
- package/dist/cjs/constants/abis/lon.js +580 -0
- package/dist/cjs/constants/abis/lon.js.map +1 -0
- package/dist/cjs/constants/abis/lonStaking.js +860 -0
- package/dist/cjs/constants/abis/lonStaking.js.map +1 -0
- package/dist/cjs/constants/abis/permit2.js +522 -0
- package/dist/cjs/constants/abis/permit2.js.map +1 -0
- package/dist/cjs/constants/abis/weth.js +283 -0
- package/dist/cjs/constants/abis/weth.js.map +1 -0
- package/dist/cjs/constants/addresses.js +18 -1
- package/dist/cjs/constants/addresses.js.map +1 -1
- package/dist/cjs/constants/index.js +3 -2
- package/dist/cjs/constants/index.js.map +1 -1
- package/dist/cjs/constants/protocol.js +12 -0
- package/dist/cjs/constants/protocol.js.map +1 -0
- package/dist/cjs/errors/base.js +5 -30
- package/dist/cjs/errors/base.js.map +1 -1
- package/dist/cjs/errors/primitives.js +2 -12
- package/dist/cjs/errors/primitives.js.map +1 -1
- package/dist/cjs/errors/request.js +10 -55
- package/dist/cjs/errors/request.js.map +1 -1
- package/dist/cjs/index.js +6 -3
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/limitOrder/index.js +126 -0
- package/dist/cjs/limitOrder/index.js.map +1 -0
- package/dist/cjs/limitOrder/type.js.map +1 -0
- package/dist/cjs/permit/index.js +195 -270
- package/dist/cjs/permit/index.js.map +1 -1
- package/dist/cjs/price/index.js +70 -103
- package/dist/cjs/price/index.js.map +1 -1
- package/dist/cjs/profile/index.js +79 -0
- package/dist/cjs/profile/index.js.map +1 -0
- package/dist/cjs/profile/type.js +3 -0
- package/dist/cjs/profile/type.js.map +1 -0
- package/dist/cjs/sdk.js +27 -49
- package/dist/cjs/sdk.js.map +1 -1
- package/dist/cjs/service/contextHost.js +24 -54
- package/dist/cjs/service/contextHost.js.map +1 -1
- package/dist/cjs/serviceHost.js +6 -1
- package/dist/cjs/serviceHost.js.map +1 -1
- package/dist/cjs/signer/index.js +168 -0
- package/dist/cjs/signer/index.js.map +1 -0
- package/dist/cjs/signer/type.js +3 -0
- package/dist/{esm → cjs/signer}/type.js.map +1 -1
- package/dist/cjs/staking/index.js +110 -0
- package/dist/cjs/staking/index.js.map +1 -0
- package/dist/cjs/staking/type.js +9 -0
- package/dist/cjs/staking/type.js.map +1 -0
- package/dist/cjs/swap/index.js +289 -409
- package/dist/cjs/swap/index.js.map +1 -1
- package/dist/cjs/types/index.js +22 -0
- package/dist/cjs/types/index.js.map +1 -0
- package/dist/cjs/utils/gas.js.map +1 -1
- package/dist/cjs/utils/promise/withTimeout.js.map +1 -1
- package/dist/cjs/utils/request/http.js +3 -3
- package/dist/cjs/utils/request/http.js.map +1 -1
- package/dist/cjs/utils/request/rpc.js +1 -1
- package/dist/cjs/utils/request/rpc.js.map +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/version.js.map +1 -1
- package/dist/esm/actions/public/getDecimals.js.map +1 -1
- package/dist/esm/addressBook.js +12 -43
- package/dist/esm/addressBook.js.map +1 -1
- package/dist/esm/constants/abis/IERC20.js +223 -0
- package/dist/esm/constants/abis/IERC20.js.map +1 -0
- package/dist/esm/constants/abis/allowance.js +19 -0
- package/dist/esm/constants/abis/allowance.js.map +1 -0
- package/dist/esm/constants/abis/genericSwap.js +217 -0
- package/dist/esm/constants/abis/genericSwap.js.map +1 -0
- package/dist/esm/constants/abis/gsEIP712Types.js +45 -0
- package/dist/esm/constants/abis/gsEIP712Types.js.map +1 -0
- package/dist/esm/constants/abis/index.js +9 -0
- package/dist/esm/constants/abis/index.js.map +1 -0
- package/dist/esm/constants/abis/lon.js +577 -0
- package/dist/esm/constants/abis/lon.js.map +1 -0
- package/dist/esm/constants/abis/lonStaking.js +857 -0
- package/dist/esm/constants/abis/lonStaking.js.map +1 -0
- package/dist/esm/constants/abis/permit2.js +519 -0
- package/dist/esm/constants/abis/permit2.js.map +1 -0
- package/dist/esm/constants/abis/weth.js +280 -0
- package/dist/esm/constants/abis/weth.js.map +1 -0
- package/dist/esm/constants/addresses.js +17 -0
- package/dist/esm/constants/addresses.js.map +1 -1
- package/dist/esm/constants/chains.js.map +1 -1
- package/dist/esm/constants/index.js +3 -2
- package/dist/esm/constants/index.js.map +1 -1
- package/dist/esm/constants/protocol.js +9 -0
- package/dist/esm/constants/protocol.js.map +1 -0
- package/dist/esm/errors/base.js +5 -30
- package/dist/esm/errors/base.js.map +1 -1
- package/dist/esm/errors/primitives.js +2 -12
- package/dist/esm/errors/primitives.js.map +1 -1
- package/dist/esm/errors/request.js +10 -55
- package/dist/esm/errors/request.js.map +1 -1
- package/dist/esm/index.js +6 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/limitOrder/index.js +122 -0
- package/dist/esm/limitOrder/index.js.map +1 -0
- package/dist/esm/limitOrder/type.js.map +1 -0
- package/dist/esm/permit/index.js +194 -270
- package/dist/esm/permit/index.js.map +1 -1
- package/dist/esm/price/index.js +70 -103
- package/dist/esm/price/index.js.map +1 -1
- package/dist/esm/profile/index.js +75 -0
- package/dist/esm/profile/index.js.map +1 -0
- package/dist/esm/profile/type.js +2 -0
- package/dist/esm/profile/type.js.map +1 -0
- package/dist/esm/sdk.js +21 -44
- package/dist/esm/sdk.js.map +1 -1
- package/dist/esm/service/contextHost.js +24 -54
- package/dist/esm/service/contextHost.js.map +1 -1
- package/dist/esm/serviceHost.js +5 -0
- package/dist/esm/serviceHost.js.map +1 -1
- package/dist/esm/signer/index.js +164 -0
- package/dist/esm/signer/index.js.map +1 -0
- package/dist/esm/signer/type.js +2 -0
- package/dist/{cjs → esm/signer}/type.js.map +1 -1
- package/dist/esm/staking/index.js +106 -0
- package/dist/esm/staking/index.js.map +1 -0
- package/dist/esm/staking/type.js +8 -0
- package/dist/esm/staking/type.js.map +1 -0
- package/dist/esm/swap/index.js +290 -412
- package/dist/esm/swap/index.js.map +1 -1
- package/dist/esm/swap/type.js +0 -2
- package/dist/esm/swap/type.js.map +1 -1
- package/dist/esm/types/index.js +6 -0
- package/dist/esm/types/index.js.map +1 -0
- package/dist/esm/utils/gas.js.map +1 -1
- package/dist/esm/utils/promise/withTimeout.js.map +1 -1
- package/dist/esm/utils/request/http.js +3 -3
- package/dist/esm/utils/request/http.js.map +1 -1
- package/dist/esm/utils/request/rpc.js +1 -1
- package/dist/esm/utils/request/rpc.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/actions/public/getDecimals.d.ts.map +1 -1
- package/dist/types/addressBook.d.ts +1 -1
- package/dist/types/addressBook.d.ts.map +1 -1
- package/dist/types/constants/abis/IERC20.d.ts +169 -0
- package/dist/types/constants/abis/IERC20.d.ts.map +1 -0
- package/dist/types/constants/abis/allowance.d.ts +16 -0
- package/dist/types/constants/abis/allowance.d.ts.map +1 -0
- package/dist/types/constants/abis/genericSwap.d.ts +284 -0
- package/dist/types/constants/abis/genericSwap.d.ts.map +1 -0
- package/dist/types/constants/abis/gsEIP712Types.d.ts +7 -0
- package/dist/types/constants/abis/gsEIP712Types.d.ts.map +1 -0
- package/dist/types/constants/abis/index.d.ts +9 -0
- package/dist/types/constants/abis/index.d.ts.map +1 -0
- package/dist/types/constants/abis/lon.d.ts +444 -0
- package/dist/types/constants/abis/lon.d.ts.map +1 -0
- package/dist/types/constants/abis/lonStaking.d.ts +664 -0
- package/dist/types/constants/abis/lonStaking.d.ts.map +1 -0
- package/dist/types/constants/{abis.d.ts → abis/permit2.d.ts} +1 -754
- package/dist/types/constants/abis/permit2.d.ts.map +1 -0
- package/dist/types/constants/abis/weth.d.ts +214 -0
- package/dist/types/constants/abis/weth.d.ts.map +1 -0
- package/dist/types/constants/addresses.d.ts +4 -0
- package/dist/types/constants/addresses.d.ts.map +1 -1
- package/dist/types/constants/chains.d.ts.map +1 -1
- package/dist/types/constants/index.d.ts +3 -2
- package/dist/types/constants/index.d.ts.map +1 -1
- package/dist/types/constants/protocol.d.ts +8 -0
- package/dist/types/constants/protocol.d.ts.map +1 -0
- package/dist/types/errors/base.d.ts +1 -1
- package/dist/types/errors/base.d.ts.map +1 -1
- package/dist/types/errors/request.d.ts.map +1 -1
- package/dist/types/index.d.ts +6 -3
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/limitOrder/index.d.ts +26 -0
- package/dist/types/limitOrder/index.d.ts.map +1 -0
- package/dist/types/limitOrder/type.d.ts +39 -0
- package/dist/types/limitOrder/type.d.ts.map +1 -0
- package/dist/types/permit/index.d.ts +3 -3
- package/dist/types/permit/index.d.ts.map +1 -1
- package/dist/types/price/index.d.ts +1 -1
- package/dist/types/price/index.d.ts.map +1 -1
- package/dist/types/profile/index.d.ts +16 -0
- package/dist/types/profile/index.d.ts.map +1 -0
- package/dist/types/profile/type.d.ts +6 -0
- package/dist/types/profile/type.d.ts.map +1 -0
- package/dist/types/sdk.d.ts +7 -2
- package/dist/types/sdk.d.ts.map +1 -1
- package/dist/types/service/contextHost.d.ts +2 -2
- package/dist/types/service/contextHost.d.ts.map +1 -1
- package/dist/types/serviceHost.d.ts +1 -0
- package/dist/types/serviceHost.d.ts.map +1 -1
- package/dist/types/signer/index.d.ts +18 -0
- package/dist/types/signer/index.d.ts.map +1 -0
- package/dist/types/signer/type.d.ts +10 -0
- package/dist/types/signer/type.d.ts.map +1 -0
- package/dist/types/staking/index.d.ts +10 -0
- package/dist/types/staking/index.d.ts.map +1 -0
- package/dist/types/staking/type.d.ts +33 -0
- package/dist/types/staking/type.d.ts.map +1 -0
- package/dist/types/swap/index.d.ts +3 -3
- package/dist/types/swap/index.d.ts.map +1 -1
- package/dist/types/swap/type.d.ts +4 -4
- package/dist/types/swap/type.d.ts.map +1 -1
- package/dist/types/types/index.d.ts +6 -0
- package/dist/types/types/index.d.ts.map +1 -0
- package/dist/types/types/token.d.ts +30 -0
- package/dist/types/types/token.d.ts.map +1 -1
- package/dist/types/utils/gas.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/dist/types/version.d.ts.map +1 -1
- package/package.json +32 -24
- package/dist/cjs/constants/abis.js +0 -1380
- package/dist/cjs/constants/abis.js.map +0 -1
- package/dist/esm/constants/abis.js +0 -1377
- package/dist/esm/constants/abis.js.map +0 -1
- package/dist/types/constants/abis.d.ts.map +0 -1
- package/dist/types/type.d.ts +0 -2
- package/dist/types/type.d.ts.map +0 -1
- /package/dist/cjs/{type.js → limitOrder/type.js} +0 -0
- /package/dist/esm/{type.js → limitOrder/type.js} +0 -0
package/dist/cjs/swap/index.js
CHANGED
|
@@ -1,447 +1,327 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Swap = exports.strategyOperationsABI = void 0;
|
|
4
|
+
const viem_1 = require("viem");
|
|
4
5
|
const index_js_1 = require("../constants/index.js");
|
|
5
6
|
const contextHost_js_1 = require("../service/contextHost.js");
|
|
7
|
+
const serviceHost_js_1 = require("./../serviceHost.js");
|
|
6
8
|
const permit2_js_1 = require("../types/permit2.js");
|
|
7
9
|
const index_js_2 = require("../utils/request/index.js");
|
|
8
|
-
const serviceHost_js_1 = require("./../serviceHost.js");
|
|
9
|
-
const viem_1 = require("viem");
|
|
10
10
|
exports.strategyOperationsABI = (0, viem_1.parseAbiParameters)('(address dest, address inputToken, uint128 inputRatio, uint128 dataOffset, uint256 value, bytes data)[]');
|
|
11
11
|
class Swap extends contextHost_js_1.ContextHost {
|
|
12
|
+
price;
|
|
13
|
+
addressBook;
|
|
12
14
|
constructor(config, injected) {
|
|
13
15
|
super({ env: config.env, chainId: config.chain }, {
|
|
14
16
|
publicClient: injected.publicClient,
|
|
15
17
|
walletClient: injected.walletClient,
|
|
16
18
|
});
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
19
|
+
this.price = injected.price;
|
|
20
|
+
this.addressBook = injected.addressBook;
|
|
21
|
+
}
|
|
22
|
+
rebuildStrategyData = (fee, swapData, operations) => {
|
|
23
|
+
const newOperations = [...operations];
|
|
24
|
+
if (fee > 0n) {
|
|
25
|
+
const feeTransfer = (0, viem_1.encodeFunctionData)({
|
|
26
|
+
abi: [(0, viem_1.parseAbiItem)('function transfer(address to, uint256 amount)')],
|
|
27
|
+
functionName: 'transfer',
|
|
28
|
+
args: [index_js_1.FEE_RECIPIENT_ADDRESS, fee],
|
|
29
|
+
});
|
|
30
|
+
if (!this.addressBook.wrappedToken) {
|
|
31
|
+
throw new Error('wrapper token address not found');
|
|
32
|
+
}
|
|
33
|
+
const feeToken = this.isNativeToken(swapData.makerToken)
|
|
34
|
+
? this.addressBook.wrappedToken
|
|
35
|
+
: swapData.makerToken;
|
|
36
|
+
const feeOperation = {
|
|
37
|
+
dest: feeToken,
|
|
38
|
+
inputToken: feeToken,
|
|
39
|
+
inputRatio: 0n,
|
|
40
|
+
dataOffset: 0n,
|
|
41
|
+
value: 0n,
|
|
42
|
+
data: feeTransfer,
|
|
43
|
+
};
|
|
44
|
+
newOperations.push(feeOperation);
|
|
45
|
+
}
|
|
46
|
+
const newStrategyData = (0, viem_1.encodeAbiParameters)(exports.strategyOperationsABI, [
|
|
47
|
+
newOperations,
|
|
48
|
+
]);
|
|
49
|
+
return newStrategyData;
|
|
50
|
+
};
|
|
51
|
+
getProtocolFeeAmount = (order) => {
|
|
52
|
+
const { swapData, feeFactor } = order;
|
|
53
|
+
const { makerTokenAmount } = swapData;
|
|
54
|
+
const protocolFeeAmount = (BigInt(makerTokenAmount) * BigInt(feeFactor)) / index_js_1.bpBase;
|
|
55
|
+
return protocolFeeAmount;
|
|
56
|
+
};
|
|
57
|
+
getSlippageAmount = (order, slippage) => {
|
|
58
|
+
const { swapData } = order;
|
|
59
|
+
const { makerTokenAmount } = swapData;
|
|
60
|
+
const slippageAmount = (BigInt(makerTokenAmount) * BigInt(slippage)) / index_js_1.bpBase;
|
|
61
|
+
return slippageAmount;
|
|
62
|
+
};
|
|
63
|
+
calcGasFeeTokenAmount = async ({ gasFeeAmount, feeToken, }) => {
|
|
64
|
+
const gasFeeValue = await this.price.getTokenValue(viem_1.zeroAddress, gasFeeAmount);
|
|
65
|
+
const gasFeeToTokenAmount = await this.price.convertTokenValueToAmount({
|
|
66
|
+
value: gasFeeValue,
|
|
67
|
+
tokenAddress: feeToken,
|
|
28
68
|
});
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
69
|
+
return gasFeeToTokenAmount;
|
|
70
|
+
};
|
|
71
|
+
calcRelayerFee = async ({ protocolFeeAmount, gasFeeTokenAmount, }) => {
|
|
72
|
+
return gasFeeTokenAmount + protocolFeeAmount;
|
|
73
|
+
};
|
|
74
|
+
getRoutesApproveStrategy = async (takerTokenAmount, needApprovalDestinations) => {
|
|
75
|
+
if (!Array.isArray(needApprovalDestinations) ||
|
|
76
|
+
needApprovalDestinations.length === 0) {
|
|
77
|
+
return [];
|
|
78
|
+
}
|
|
79
|
+
const allowances = await Promise.all([
|
|
80
|
+
...needApprovalDestinations.map(({ dest, inputToken }) => this.publicClient.readContract({
|
|
81
|
+
abi: [
|
|
82
|
+
(0, viem_1.parseAbiItem)('function allowance(address owner, address spender) view returns (uint256)'),
|
|
83
|
+
],
|
|
84
|
+
functionName: 'allowance',
|
|
85
|
+
address: inputToken,
|
|
86
|
+
args: [this.addressBook.smartOrderStrategy, dest],
|
|
87
|
+
})),
|
|
88
|
+
]);
|
|
89
|
+
const approveStrategies = allowances.reduce((acc, allowance, index) => {
|
|
90
|
+
try {
|
|
91
|
+
if (BigInt(allowance) < BigInt(takerTokenAmount)) {
|
|
92
|
+
const { dest, inputToken } = needApprovalDestinations[index];
|
|
93
|
+
const approve = (0, viem_1.encodeFunctionData)({
|
|
94
|
+
abi: [
|
|
95
|
+
(0, viem_1.parseAbiItem)('function approve(address spender, uint256 amount) returns (bool)'),
|
|
96
|
+
],
|
|
97
|
+
functionName: 'approve',
|
|
98
|
+
args: [dest, index_js_1.MAX_UINT256],
|
|
40
99
|
});
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const feeToken = this.isNativeToken(swapData.makerToken)
|
|
45
|
-
? this.addressBook.wrappedToken
|
|
46
|
-
: swapData.makerToken;
|
|
47
|
-
const feeOperation = {
|
|
48
|
-
dest: feeToken,
|
|
49
|
-
inputToken: feeToken,
|
|
100
|
+
const approveOperation = {
|
|
101
|
+
dest: inputToken,
|
|
102
|
+
inputToken: inputToken,
|
|
50
103
|
inputRatio: 0n,
|
|
51
104
|
dataOffset: 0n,
|
|
52
105
|
value: 0n,
|
|
53
|
-
data:
|
|
106
|
+
data: approve,
|
|
54
107
|
};
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
Object.defineProperty(this, "getSlippageAmount", {
|
|
75
|
-
enumerable: true,
|
|
76
|
-
configurable: true,
|
|
77
|
-
writable: true,
|
|
78
|
-
value: (order, slippage) => {
|
|
79
|
-
const { swapData } = order;
|
|
80
|
-
const { makerTokenAmount } = swapData;
|
|
81
|
-
const slippageAmount = (BigInt(makerTokenAmount) * BigInt(slippage)) / index_js_1.bpBase;
|
|
82
|
-
return slippageAmount;
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
Object.defineProperty(this, "calcGasFeeTokenAmount", {
|
|
86
|
-
enumerable: true,
|
|
87
|
-
configurable: true,
|
|
88
|
-
writable: true,
|
|
89
|
-
value: async ({ gasFeeAmount, feeToken, }) => {
|
|
90
|
-
const gasFeeValue = await this.price.getTokenValue(viem_1.zeroAddress, gasFeeAmount);
|
|
91
|
-
const gasFeeToTokenAmount = await this.price.convertTokenValueToAmount({
|
|
92
|
-
value: gasFeeValue,
|
|
93
|
-
tokenAddress: feeToken,
|
|
94
|
-
});
|
|
95
|
-
return gasFeeToTokenAmount;
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
Object.defineProperty(this, "calcRelayerFee", {
|
|
99
|
-
enumerable: true,
|
|
100
|
-
configurable: true,
|
|
101
|
-
writable: true,
|
|
102
|
-
value: async ({ protocolFeeAmount, gasFeeTokenAmount, }) => {
|
|
103
|
-
return gasFeeTokenAmount + protocolFeeAmount;
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
Object.defineProperty(this, "getRoutesApproveStrategy", {
|
|
107
|
-
enumerable: true,
|
|
108
|
-
configurable: true,
|
|
109
|
-
writable: true,
|
|
110
|
-
value: async (takerTokenAmount, needApprovalDestinations) => {
|
|
111
|
-
if (!Array.isArray(needApprovalDestinations) ||
|
|
112
|
-
needApprovalDestinations.length === 0) {
|
|
113
|
-
return [];
|
|
114
|
-
}
|
|
115
|
-
const allowances = await Promise.all([
|
|
116
|
-
...needApprovalDestinations.map(({ dest, inputToken }) => this.publicClient.readContract({
|
|
117
|
-
abi: [
|
|
118
|
-
(0, viem_1.parseAbiItem)('function allowance(address owner, address spender) view returns (uint256)'),
|
|
119
|
-
],
|
|
120
|
-
functionName: 'allowance',
|
|
121
|
-
address: inputToken,
|
|
122
|
-
args: [this.addressBook.smartOrderStrategy, dest],
|
|
123
|
-
})),
|
|
124
|
-
]);
|
|
125
|
-
const approveStrategies = allowances.reduce((acc, allowance, index) => {
|
|
126
|
-
try {
|
|
127
|
-
if (BigInt(allowance) < BigInt(takerTokenAmount)) {
|
|
128
|
-
const { dest, inputToken } = needApprovalDestinations[index];
|
|
129
|
-
const approve = (0, viem_1.encodeFunctionData)({
|
|
130
|
-
abi: [
|
|
131
|
-
(0, viem_1.parseAbiItem)('function approve(address spender, uint256 amount) returns (bool)'),
|
|
132
|
-
],
|
|
133
|
-
functionName: 'approve',
|
|
134
|
-
args: [dest, index_js_1.MAX_UINT256],
|
|
135
|
-
});
|
|
136
|
-
const approveOperation = {
|
|
137
|
-
dest: inputToken,
|
|
138
|
-
inputToken: inputToken,
|
|
139
|
-
inputRatio: 0n,
|
|
140
|
-
dataOffset: 0n,
|
|
141
|
-
value: 0n,
|
|
142
|
-
data: approve,
|
|
143
|
-
};
|
|
144
|
-
acc.push(approveOperation);
|
|
145
|
-
if (inputToken.toLowerCase() === this.addressBook.USDT?.toLowerCase() &&
|
|
146
|
-
BigInt(allowance) > 0n) {
|
|
147
|
-
const approve2Zero = (0, viem_1.encodeFunctionData)({
|
|
148
|
-
abi: [
|
|
149
|
-
(0, viem_1.parseAbiItem)('function approve(address spender, uint256 amount) returns (bool)'),
|
|
150
|
-
],
|
|
151
|
-
functionName: 'approve',
|
|
152
|
-
args: [dest, 0n],
|
|
153
|
-
});
|
|
154
|
-
const approveOperation = {
|
|
155
|
-
dest: inputToken,
|
|
156
|
-
inputToken: inputToken,
|
|
157
|
-
inputRatio: 0n,
|
|
158
|
-
dataOffset: 0n,
|
|
159
|
-
value: 0n,
|
|
160
|
-
data: approve2Zero,
|
|
161
|
-
};
|
|
162
|
-
acc.unshift(approveOperation);
|
|
163
|
-
}
|
|
164
|
-
return acc;
|
|
165
|
-
}
|
|
166
|
-
return acc;
|
|
167
|
-
}
|
|
168
|
-
catch {
|
|
169
|
-
return acc;
|
|
108
|
+
acc.push(approveOperation);
|
|
109
|
+
if (inputToken.toLowerCase() === this.addressBook.USDT?.toLowerCase() &&
|
|
110
|
+
BigInt(allowance) > 0n) {
|
|
111
|
+
const approve2Zero = (0, viem_1.encodeFunctionData)({
|
|
112
|
+
abi: [
|
|
113
|
+
(0, viem_1.parseAbiItem)('function approve(address spender, uint256 amount) returns (bool)'),
|
|
114
|
+
],
|
|
115
|
+
functionName: 'approve',
|
|
116
|
+
args: [dest, 0n],
|
|
117
|
+
});
|
|
118
|
+
const approveOperation = {
|
|
119
|
+
dest: inputToken,
|
|
120
|
+
inputToken: inputToken,
|
|
121
|
+
inputRatio: 0n,
|
|
122
|
+
dataOffset: 0n,
|
|
123
|
+
value: 0n,
|
|
124
|
+
data: approve2Zero,
|
|
125
|
+
};
|
|
126
|
+
acc.unshift(approveOperation);
|
|
170
127
|
}
|
|
171
|
-
|
|
172
|
-
return approveStrategies;
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
Object.defineProperty(this, "prepareOrder", {
|
|
176
|
-
enumerable: true,
|
|
177
|
-
configurable: true,
|
|
178
|
-
writable: true,
|
|
179
|
-
value: async ({ order, slippage, gasFee = 0n, sendByRelayer, }) => {
|
|
180
|
-
const { swapData, needApprovalDestinations } = order;
|
|
181
|
-
const { recipient, strategyData, makerToken } = swapData;
|
|
182
|
-
const makerTokenAmount = BigInt(swapData.makerTokenAmount);
|
|
183
|
-
const slippageAmount = this.getSlippageAmount(order, slippage);
|
|
184
|
-
const protocolFeeAmount = this.getProtocolFeeAmount(order);
|
|
185
|
-
let fee = protocolFeeAmount;
|
|
186
|
-
let gasFeeTokenAmount = gasFee;
|
|
187
|
-
if (sendByRelayer) {
|
|
188
|
-
gasFeeTokenAmount = await this.calcGasFeeTokenAmount({
|
|
189
|
-
gasFeeAmount: gasFee,
|
|
190
|
-
feeToken: makerToken,
|
|
191
|
-
});
|
|
192
|
-
fee = await this.calcRelayerFee({
|
|
193
|
-
protocolFeeAmount,
|
|
194
|
-
gasFeeTokenAmount,
|
|
195
|
-
});
|
|
128
|
+
return acc;
|
|
196
129
|
}
|
|
197
|
-
|
|
198
|
-
swapData.minMakerTokenAmount = minMakerTokenAmount.toString();
|
|
199
|
-
const [operations] = (0, viem_1.decodeAbiParameters)(exports.strategyOperationsABI, strategyData);
|
|
200
|
-
const approveOperations = await this.getRoutesApproveStrategy(swapData.takerTokenAmount, needApprovalDestinations);
|
|
201
|
-
const newStrategyData = this.rebuildStrategyData(fee, swapData, [
|
|
202
|
-
...approveOperations,
|
|
203
|
-
...operations,
|
|
204
|
-
]);
|
|
205
|
-
const value = (0, viem_1.isAddressEqual)(swapData.takerToken, index_js_1.nullAddress) ||
|
|
206
|
-
(0, viem_1.isAddressEqual)(swapData.takerToken, viem_1.zeroAddress)
|
|
207
|
-
? BigInt(swapData.takerTokenAmount)
|
|
208
|
-
: 0n;
|
|
209
|
-
const newSwapData = {
|
|
210
|
-
...swapData,
|
|
211
|
-
strategyData: newStrategyData,
|
|
212
|
-
takerTokenAmount: BigInt(swapData.takerTokenAmount),
|
|
213
|
-
makerTokenAmount: BigInt(swapData.makerTokenAmount),
|
|
214
|
-
minMakerTokenAmount: BigInt(swapData.minMakerTokenAmount),
|
|
215
|
-
salt: BigInt(swapData.salt),
|
|
216
|
-
expiry: BigInt(swapData.expiry),
|
|
217
|
-
};
|
|
218
|
-
return {
|
|
219
|
-
swapData: newSwapData,
|
|
220
|
-
protocolFee: protocolFeeAmount,
|
|
221
|
-
gasFeeTokenAmount,
|
|
222
|
-
gasFee,
|
|
223
|
-
fee,
|
|
224
|
-
recipient,
|
|
225
|
-
strategyData: newStrategyData,
|
|
226
|
-
value,
|
|
227
|
-
};
|
|
130
|
+
return acc;
|
|
228
131
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
enumerable: true,
|
|
232
|
-
configurable: true,
|
|
233
|
-
writable: true,
|
|
234
|
-
value: async (chainId) => {
|
|
235
|
-
const _chainId = chainId ?? this.chainId;
|
|
236
|
-
const tokenList = await (0, index_js_2.http)(`${this.host(serviceHost_js_1.httpServiceHost)}/${index_js_1.apiVersion}/swap/tokenlist/${_chainId}`);
|
|
237
|
-
return tokenList;
|
|
132
|
+
catch {
|
|
133
|
+
return acc;
|
|
238
134
|
}
|
|
135
|
+
}, []);
|
|
136
|
+
return approveStrategies;
|
|
137
|
+
};
|
|
138
|
+
prepareOrder = async ({ order, slippage, gasFee = 0n, sendByRelayer, }) => {
|
|
139
|
+
const { swapData, needApprovalDestinations } = order;
|
|
140
|
+
const { recipient, strategyData, makerToken } = swapData;
|
|
141
|
+
const makerTokenAmount = BigInt(swapData.makerTokenAmount);
|
|
142
|
+
const slippageAmount = this.getSlippageAmount(order, slippage);
|
|
143
|
+
const protocolFeeAmount = this.getProtocolFeeAmount(order);
|
|
144
|
+
let fee = protocolFeeAmount;
|
|
145
|
+
let gasFeeTokenAmount = gasFee;
|
|
146
|
+
if (sendByRelayer) {
|
|
147
|
+
gasFeeTokenAmount = await this.calcGasFeeTokenAmount({
|
|
148
|
+
gasFeeAmount: gasFee,
|
|
149
|
+
feeToken: makerToken,
|
|
150
|
+
});
|
|
151
|
+
fee = await this.calcRelayerFee({
|
|
152
|
+
protocolFeeAmount,
|
|
153
|
+
gasFeeTokenAmount,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
const minMakerTokenAmount = makerTokenAmount - slippageAmount - fee;
|
|
157
|
+
swapData.minMakerTokenAmount = minMakerTokenAmount.toString();
|
|
158
|
+
const [operations] = (0, viem_1.decodeAbiParameters)(exports.strategyOperationsABI, strategyData);
|
|
159
|
+
const approveOperations = await this.getRoutesApproveStrategy(swapData.takerTokenAmount, needApprovalDestinations);
|
|
160
|
+
const newStrategyData = this.rebuildStrategyData(fee, swapData, [
|
|
161
|
+
...approveOperations,
|
|
162
|
+
...operations,
|
|
163
|
+
]);
|
|
164
|
+
const value = (0, viem_1.isAddressEqual)(swapData.takerToken, index_js_1.nullAddress) ||
|
|
165
|
+
(0, viem_1.isAddressEqual)(swapData.takerToken, viem_1.zeroAddress)
|
|
166
|
+
? BigInt(swapData.takerTokenAmount)
|
|
167
|
+
: 0n;
|
|
168
|
+
const newSwapData = {
|
|
169
|
+
...swapData,
|
|
170
|
+
strategyData: newStrategyData,
|
|
171
|
+
takerTokenAmount: BigInt(swapData.takerTokenAmount),
|
|
172
|
+
makerTokenAmount: BigInt(swapData.makerTokenAmount),
|
|
173
|
+
minMakerTokenAmount: BigInt(swapData.minMakerTokenAmount),
|
|
174
|
+
salt: BigInt(swapData.salt),
|
|
175
|
+
expiry: BigInt(swapData.expiry),
|
|
176
|
+
};
|
|
177
|
+
return {
|
|
178
|
+
swapData: newSwapData,
|
|
179
|
+
protocolFee: protocolFeeAmount,
|
|
180
|
+
gasFeeTokenAmount,
|
|
181
|
+
gasFee,
|
|
182
|
+
fee,
|
|
183
|
+
recipient,
|
|
184
|
+
strategyData: newStrategyData,
|
|
185
|
+
value,
|
|
186
|
+
};
|
|
187
|
+
};
|
|
188
|
+
getTokenList = async (chainId) => {
|
|
189
|
+
const _chainId = chainId ?? this.chainId;
|
|
190
|
+
const tokenList = await (0, index_js_2.http)(`${this.host(serviceHost_js_1.httpServiceHost)}/${index_js_1.apiVersion}/swap/tokenlist/${_chainId}`);
|
|
191
|
+
return tokenList;
|
|
192
|
+
};
|
|
193
|
+
quote = async (dto) => {
|
|
194
|
+
if (!dto.chainId)
|
|
195
|
+
dto.chainId = this.chainId;
|
|
196
|
+
const { chainId, toChainId, ...rest } = dto;
|
|
197
|
+
const isCrossSwap = toChainId && chainId !== toChainId;
|
|
198
|
+
const chainIdPath = isCrossSwap ? `${chainId}/${toChainId}` : `${chainId}`;
|
|
199
|
+
const p = new URLSearchParams();
|
|
200
|
+
Object.entries(rest).forEach(([key, value]) => {
|
|
201
|
+
p.append(key, value.toString());
|
|
239
202
|
});
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
203
|
+
const order = await (0, index_js_2.http)(`${this.host(serviceHost_js_1.httpServiceHost)}/${index_js_1.apiVersion}/swap/quote/${chainIdPath}?${p.toString()}`);
|
|
204
|
+
return order;
|
|
205
|
+
};
|
|
206
|
+
getTokenPermitData = (token, permitType = permit2_js_1.PermitSource.Permit2AllowanceTransfer) => {
|
|
207
|
+
const permitToAllowanceTarget = (0, viem_1.encodePacked)(['uint8', 'bytes'], [permitType, '0x']);
|
|
208
|
+
let takerTokenPermit = permitToAllowanceTarget;
|
|
209
|
+
if (this.isNativeToken(token)) {
|
|
210
|
+
takerTokenPermit = '0x';
|
|
211
|
+
}
|
|
212
|
+
return takerTokenPermit;
|
|
213
|
+
};
|
|
214
|
+
isNativeToken = (tokenAddress) => {
|
|
215
|
+
return ((0, viem_1.isAddressEqual)(tokenAddress, index_js_1.nullAddress) ||
|
|
216
|
+
(0, viem_1.isAddressEqual)(tokenAddress, viem_1.zeroAddress));
|
|
217
|
+
};
|
|
218
|
+
estimate = async ({ account, order, slippage, permit, }) => {
|
|
219
|
+
const { swapData, value } = await this.prepareOrder({
|
|
220
|
+
order,
|
|
221
|
+
slippage,
|
|
257
222
|
});
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
takerTokenPermit = '0x';
|
|
267
|
-
}
|
|
268
|
-
return takerTokenPermit;
|
|
269
|
-
}
|
|
223
|
+
const takerTokenPermit = permit ?? this.getTokenPermitData(swapData.takerToken);
|
|
224
|
+
const gasEstimate = await this.publicClient.estimateContractGas({
|
|
225
|
+
address: this.addressBook.genericSwap,
|
|
226
|
+
abi: index_js_1.GENERIC_SWAP_ABI,
|
|
227
|
+
functionName: 'executeSwap',
|
|
228
|
+
args: [swapData, takerTokenPermit],
|
|
229
|
+
value,
|
|
230
|
+
account,
|
|
270
231
|
});
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
232
|
+
return gasEstimate;
|
|
233
|
+
};
|
|
234
|
+
sign = async (params) => {
|
|
235
|
+
const { account, swapData, takerTokenPermit, value = 0n, isAcrossSwap, txOverride, } = params;
|
|
236
|
+
const salt = swapData.salt.toString(16).padStart(64, '0');
|
|
237
|
+
const tokenlonIdentifier = `4c4f4e3130${salt}`;
|
|
238
|
+
const acrossIdentifier = '1dc0de004e';
|
|
239
|
+
const dataSuffix = `0x${tokenlonIdentifier}${isAcrossSwap ? acrossIdentifier : ''}`;
|
|
240
|
+
const walletClient = this.useWalletClient();
|
|
241
|
+
const txHash = await walletClient.writeContract({
|
|
242
|
+
address: this.addressBook.genericSwap,
|
|
243
|
+
abi: index_js_1.GENERIC_SWAP_ABI,
|
|
244
|
+
account,
|
|
245
|
+
functionName: 'executeSwap',
|
|
246
|
+
args: [swapData, takerTokenPermit],
|
|
247
|
+
value,
|
|
248
|
+
dataSuffix,
|
|
249
|
+
chain: walletClient.chain,
|
|
250
|
+
...txOverride,
|
|
279
251
|
});
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
order,
|
|
287
|
-
slippage,
|
|
288
|
-
});
|
|
289
|
-
const takerTokenPermit = permit ?? this.getTokenPermitData(swapData.takerToken);
|
|
290
|
-
const gasEstimate = await this.publicClient.estimateContractGas({
|
|
291
|
-
address: this.addressBook.genericSwap,
|
|
292
|
-
abi: index_js_1.GENERIC_SWAP_ABI,
|
|
293
|
-
functionName: 'executeSwap',
|
|
294
|
-
args: [swapData, takerTokenPermit],
|
|
295
|
-
value,
|
|
296
|
-
account,
|
|
297
|
-
});
|
|
298
|
-
return gasEstimate;
|
|
299
|
-
}
|
|
252
|
+
return txHash;
|
|
253
|
+
};
|
|
254
|
+
signWithReceipt = async (params) => {
|
|
255
|
+
const txHash = await this.sign(params);
|
|
256
|
+
const receipt = await this.publicClient.waitForTransactionReceipt({
|
|
257
|
+
hash: txHash,
|
|
300
258
|
});
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
chain: walletClient.chain,
|
|
321
|
-
...txOverride,
|
|
322
|
-
});
|
|
323
|
-
return txHash;
|
|
324
|
-
}
|
|
259
|
+
return receipt;
|
|
260
|
+
};
|
|
261
|
+
signTypedData = async (swapData, account) => {
|
|
262
|
+
const walletClient = this.useWalletClient();
|
|
263
|
+
const EIP712_DOMAIN = {
|
|
264
|
+
name: 'Tokenlon',
|
|
265
|
+
version: 'v6',
|
|
266
|
+
chainId: this.chainId,
|
|
267
|
+
verifyingContract: this.addressBook.genericSwap,
|
|
268
|
+
};
|
|
269
|
+
const EIP712_TYPED = {
|
|
270
|
+
domain: EIP712_DOMAIN,
|
|
271
|
+
types: index_js_1.GS_EIP712_TYPES,
|
|
272
|
+
primaryType: 'GenericSwapData',
|
|
273
|
+
};
|
|
274
|
+
return walletClient.signTypedData({
|
|
275
|
+
...EIP712_TYPED,
|
|
276
|
+
message: swapData,
|
|
277
|
+
account,
|
|
325
278
|
});
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
hash: txHash,
|
|
334
|
-
});
|
|
335
|
-
return receipt;
|
|
336
|
-
}
|
|
279
|
+
};
|
|
280
|
+
submit = async (dto) => {
|
|
281
|
+
return (0, index_js_2.http)(`${this.host(serviceHost_js_1.httpServiceHost)}/${index_js_1.apiVersion}/swap/submit/${this.chainId}`, {
|
|
282
|
+
fetchOptions: {
|
|
283
|
+
method: 'POST',
|
|
284
|
+
},
|
|
285
|
+
body: dto,
|
|
337
286
|
});
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
value: async (swapData, account) => {
|
|
343
|
-
const walletClient = this.useWalletClient();
|
|
344
|
-
const EIP712_DOMAIN = {
|
|
345
|
-
name: 'Tokenlon',
|
|
346
|
-
version: 'v6',
|
|
347
|
-
chainId: this.chainId,
|
|
348
|
-
verifyingContract: this.addressBook.genericSwap,
|
|
349
|
-
};
|
|
350
|
-
const EIP712_TYPED = {
|
|
351
|
-
domain: EIP712_DOMAIN,
|
|
352
|
-
types: index_js_1.GS_EIP712_TYPES,
|
|
353
|
-
primaryType: 'GenericSwapData',
|
|
354
|
-
};
|
|
355
|
-
return walletClient.signTypedData({
|
|
356
|
-
...EIP712_TYPED,
|
|
357
|
-
message: swapData,
|
|
358
|
-
account,
|
|
359
|
-
});
|
|
360
|
-
}
|
|
287
|
+
};
|
|
288
|
+
list = async (dto) => {
|
|
289
|
+
const params = new URLSearchParams({
|
|
290
|
+
userAddress: dto.account,
|
|
361
291
|
});
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
fetchOptions: {
|
|
369
|
-
method: 'POST',
|
|
370
|
-
},
|
|
371
|
-
body: dto,
|
|
372
|
-
});
|
|
373
|
-
}
|
|
292
|
+
return (0, index_js_2.http)(`${this.host(serviceHost_js_1.httpServiceHost)}?${params}`);
|
|
293
|
+
};
|
|
294
|
+
status = async (dto) => {
|
|
295
|
+
const { toChainId, ...rest } = dto;
|
|
296
|
+
const params = new URLSearchParams({
|
|
297
|
+
...rest,
|
|
374
298
|
});
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
configurable: true,
|
|
389
|
-
writable: true,
|
|
390
|
-
value: async (dto) => {
|
|
391
|
-
const { toChainId, ...rest } = dto;
|
|
392
|
-
const params = new URLSearchParams({
|
|
393
|
-
...rest,
|
|
394
|
-
});
|
|
395
|
-
const chainIdPath = toChainId
|
|
396
|
-
? `${this.chainId}/${toChainId}`
|
|
397
|
-
: `${this.chainId}`;
|
|
398
|
-
return (0, index_js_2.http)(`${this.host(serviceHost_js_1.httpServiceHost)}/${index_js_1.apiVersion}/swap/status/${chainIdPath}?${params}`);
|
|
399
|
-
}
|
|
299
|
+
const chainIdPath = toChainId
|
|
300
|
+
? `${this.chainId}/${toChainId}`
|
|
301
|
+
: `${this.chainId}`;
|
|
302
|
+
return (0, index_js_2.http)(`${this.host(serviceHost_js_1.httpServiceHost)}/${index_js_1.apiVersion}/swap/status/${chainIdPath}?${params}`);
|
|
303
|
+
};
|
|
304
|
+
config = async (appVersion) => {
|
|
305
|
+
return (0, index_js_2.http)(`${this.host(serviceHost_js_1.httpServiceHost)}/${index_js_1.apiVersion}/swap/config?appVersion=${appVersion}`);
|
|
306
|
+
};
|
|
307
|
+
ordersHistory = async ({ chainId, userAddress, limit, offset, }) => {
|
|
308
|
+
const params = new URLSearchParams({
|
|
309
|
+
userAddress,
|
|
310
|
+
limit: limit.toString(),
|
|
311
|
+
offset: offset.toString(),
|
|
400
312
|
});
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
313
|
+
return (0, index_js_2.http)(`${this.host(serviceHost_js_1.httpServiceHost)}/${index_js_1.apiVersion}/swap/orders/${chainId}?${params}`);
|
|
314
|
+
};
|
|
315
|
+
trendingList = async () => {
|
|
316
|
+
return (0, index_js_2.http)(`${this.host(serviceHost_js_1.httpServiceHost)}/${index_js_1.apiVersion}/swap/trendinglist`);
|
|
317
|
+
};
|
|
318
|
+
tradingAmountLimits = async ({ fromChainId, toChainId, fromToken, toToken, }) => {
|
|
319
|
+
const params = new URLSearchParams({
|
|
320
|
+
fromToken,
|
|
321
|
+
toToken,
|
|
408
322
|
});
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
configurable: true,
|
|
412
|
-
writable: true,
|
|
413
|
-
value: async ({ chainId, userAddress, limit, offset, }) => {
|
|
414
|
-
const params = new URLSearchParams({
|
|
415
|
-
userAddress,
|
|
416
|
-
limit: limit.toString(),
|
|
417
|
-
offset: offset.toString(),
|
|
418
|
-
});
|
|
419
|
-
return (0, index_js_2.http)(`${this.host(serviceHost_js_1.httpServiceHost)}/${index_js_1.apiVersion}/swap/orders/${chainId}?${params}`);
|
|
420
|
-
}
|
|
421
|
-
});
|
|
422
|
-
Object.defineProperty(this, "trendingList", {
|
|
423
|
-
enumerable: true,
|
|
424
|
-
configurable: true,
|
|
425
|
-
writable: true,
|
|
426
|
-
value: async () => {
|
|
427
|
-
return (0, index_js_2.http)(`${this.host(serviceHost_js_1.httpServiceHost)}/${index_js_1.apiVersion}/swap/trendinglist`);
|
|
428
|
-
}
|
|
429
|
-
});
|
|
430
|
-
Object.defineProperty(this, "tradingAmountLimits", {
|
|
431
|
-
enumerable: true,
|
|
432
|
-
configurable: true,
|
|
433
|
-
writable: true,
|
|
434
|
-
value: async ({ fromChainId, toChainId, fromToken, toToken, }) => {
|
|
435
|
-
const params = new URLSearchParams({
|
|
436
|
-
fromToken,
|
|
437
|
-
toToken,
|
|
438
|
-
});
|
|
439
|
-
return (0, index_js_2.http)(`${this.host(serviceHost_js_1.httpServiceHost)}/${index_js_1.apiVersion}/swap/limits/${fromChainId}/${toChainId}?${params}`);
|
|
440
|
-
}
|
|
441
|
-
});
|
|
442
|
-
this.price = injected.price;
|
|
443
|
-
this.addressBook = injected.addressBook;
|
|
444
|
-
}
|
|
323
|
+
return (0, index_js_2.http)(`${this.host(serviceHost_js_1.httpServiceHost)}/${index_js_1.apiVersion}/swap/limits/${fromChainId}/${toChainId}?${params}`);
|
|
324
|
+
};
|
|
445
325
|
}
|
|
446
326
|
exports.Swap = Swap;
|
|
447
327
|
//# sourceMappingURL=index.js.map
|