@lifi/sdk 2.2.3 → 3.0.0-alpha.2
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/LiFi.d.ts +69 -62
- package/dist/LiFi.js +71 -60
- package/dist/allowance/getAllowance.d.ts +6 -0
- package/dist/allowance/getAllowance.js +78 -0
- package/dist/allowance/index.d.ts +3 -2
- package/dist/allowance/index.js +3 -2
- package/dist/allowance/setAllowance.d.ts +5 -0
- package/dist/allowance/setAllowance.js +50 -0
- package/dist/allowance/types.d.ts +27 -0
- package/dist/allowance/types.js +1 -0
- package/dist/balance/getBalance.d.ts +2 -0
- package/dist/balance/getBalance.js +93 -0
- package/dist/balance/getTokenBalance.d.ts +2 -2
- package/dist/balance/getTokenBalance.js +4 -4
- package/dist/balance/index.d.ts +1 -12
- package/dist/balance/index.js +1 -9
- package/dist/cjs/LiFi.d.ts +69 -62
- package/dist/cjs/LiFi.js +69 -58
- package/dist/cjs/allowance/getAllowance.d.ts +6 -0
- package/dist/cjs/allowance/getAllowance.js +85 -0
- package/dist/cjs/allowance/index.d.ts +3 -2
- package/dist/cjs/allowance/index.js +3 -2
- package/dist/cjs/allowance/setAllowance.d.ts +5 -0
- package/dist/cjs/allowance/setAllowance.js +56 -0
- package/dist/cjs/allowance/types.d.ts +27 -0
- package/dist/cjs/allowance/types.js +2 -0
- package/dist/cjs/balance/getBalance.d.ts +2 -0
- package/dist/cjs/balance/getBalance.js +97 -0
- package/dist/cjs/balance/getTokenBalance.d.ts +2 -2
- package/dist/cjs/balance/getTokenBalance.js +6 -9
- package/dist/cjs/balance/index.d.ts +1 -12
- package/dist/cjs/balance/index.js +1 -9
- package/dist/cjs/connectors.d.ts +7 -5
- package/dist/cjs/connectors.js +45 -37
- package/dist/cjs/constants.d.ts +6 -0
- package/dist/cjs/constants.js +9 -0
- package/dist/cjs/execution/RouteExecutionManager.d.ts +24 -30
- package/dist/cjs/execution/RouteExecutionManager.js +27 -45
- package/dist/cjs/execution/StatusManager.d.ts +22 -23
- package/dist/cjs/execution/StatusManager.js +21 -22
- package/dist/cjs/execution/StepExecutionManager.d.ts +3 -3
- package/dist/cjs/execution/StepExecutionManager.js +118 -125
- package/dist/cjs/execution/StepExecutor.d.ts +4 -4
- package/dist/cjs/execution/StepExecutor.js +6 -6
- package/dist/cjs/execution/checkAllowance.d.ts +4 -0
- package/dist/cjs/execution/checkAllowance.js +77 -0
- package/dist/cjs/execution/checkBalance.d.ts +2 -0
- package/dist/cjs/execution/checkBalance.js +42 -0
- package/dist/cjs/execution/multisig.d.ts +4 -3
- package/dist/cjs/execution/multisig.js +9 -11
- package/dist/cjs/execution/prepareRestart.d.ts +3 -0
- package/dist/cjs/execution/prepareRestart.js +65 -0
- package/dist/cjs/execution/stepComparison.d.ts +3 -3
- package/dist/cjs/execution/stepComparison.js +2 -2
- package/dist/cjs/execution/switchChain.d.ts +13 -8
- package/dist/cjs/execution/switchChain.js +16 -11
- package/dist/cjs/execution/utils.d.ts +9 -3
- package/dist/cjs/execution/utils.js +19 -66
- package/dist/cjs/execution/waitForReceivingTransaction.d.ts +3 -0
- package/dist/cjs/execution/waitForReceivingTransaction.js +58 -0
- package/dist/cjs/helpers.d.ts +7 -17
- package/dist/cjs/helpers.js +6 -38
- package/dist/cjs/request.js +1 -1
- package/dist/cjs/services/ApiService.d.ts +2 -2
- package/dist/cjs/services/ApiService.js +4 -2
- package/dist/cjs/services/ChainsService.d.ts +1 -1
- package/dist/cjs/services/ConfigService.d.ts +1 -1
- package/dist/cjs/services/ConfigService.js +1 -2
- package/dist/cjs/typeguards.d.ts +1 -1
- package/dist/cjs/types/abi.d.ts +5 -0
- package/dist/cjs/types/abi.js +45 -0
- package/dist/cjs/types/index.d.ts +2 -2
- package/dist/cjs/types/index.js +3 -3
- package/dist/cjs/types/internal.types.d.ts +24 -31
- package/dist/cjs/utils/errors.d.ts +15 -14
- package/dist/cjs/utils/errors.js +38 -37
- package/dist/cjs/utils/getMaxPriorityFeePerGas.d.ts +2 -0
- package/dist/cjs/utils/getMaxPriorityFeePerGas.js +22 -0
- package/dist/cjs/utils/index.d.ts +5 -0
- package/dist/cjs/utils/index.js +21 -0
- package/dist/cjs/utils/median.d.ts +1 -0
- package/dist/cjs/utils/median.js +15 -0
- package/dist/cjs/utils/parseError.d.ts +4 -4
- package/dist/cjs/utils/parseError.js +41 -38
- package/dist/cjs/utils/utils.d.ts +1 -16
- package/dist/cjs/utils/utils.js +9 -78
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/connectors.d.ts +7 -5
- package/dist/connectors.js +19 -35
- package/dist/constants.d.ts +6 -0
- package/dist/constants.js +6 -0
- package/dist/execution/RouteExecutionManager.d.ts +24 -30
- package/dist/execution/RouteExecutionManager.js +27 -45
- package/dist/execution/StatusManager.d.ts +22 -23
- package/dist/execution/StatusManager.js +22 -23
- package/dist/execution/StepExecutionManager.d.ts +3 -3
- package/dist/execution/StepExecutionManager.js +116 -123
- package/dist/execution/StepExecutor.d.ts +4 -4
- package/dist/execution/StepExecutor.js +6 -6
- package/dist/execution/checkAllowance.d.ts +4 -0
- package/dist/execution/checkAllowance.js +73 -0
- package/dist/execution/checkBalance.d.ts +2 -0
- package/dist/execution/checkBalance.js +38 -0
- package/dist/execution/multisig.d.ts +4 -3
- package/dist/execution/multisig.js +10 -12
- package/dist/execution/prepareRestart.d.ts +3 -0
- package/dist/execution/prepareRestart.js +61 -0
- package/dist/execution/stepComparison.d.ts +3 -3
- package/dist/execution/stepComparison.js +3 -3
- package/dist/execution/switchChain.d.ts +13 -8
- package/dist/execution/switchChain.js +17 -12
- package/dist/execution/utils.d.ts +9 -3
- package/dist/execution/utils.js +18 -61
- package/dist/execution/waitForReceivingTransaction.d.ts +3 -0
- package/dist/execution/waitForReceivingTransaction.js +51 -0
- package/dist/helpers.d.ts +7 -17
- package/dist/helpers.js +5 -34
- package/dist/request.js +2 -2
- package/dist/services/ApiService.d.ts +2 -2
- package/dist/services/ApiService.js +4 -2
- package/dist/services/ChainsService.d.ts +1 -1
- package/dist/services/ConfigService.d.ts +1 -1
- package/dist/services/ConfigService.js +2 -3
- package/dist/typeguards.d.ts +1 -1
- package/dist/types/abi.d.ts +5 -0
- package/dist/types/abi.js +42 -0
- package/dist/types/index.d.ts +2 -2
- package/dist/types/index.js +2 -2
- package/dist/types/internal.types.d.ts +24 -31
- package/dist/utils/errors.d.ts +15 -14
- package/dist/utils/errors.js +36 -35
- package/dist/utils/getMaxPriorityFeePerGas.d.ts +2 -0
- package/dist/utils/getMaxPriorityFeePerGas.js +18 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.js +5 -0
- package/dist/utils/median.d.ts +1 -0
- package/dist/utils/median.js +11 -0
- package/dist/utils/parseError.d.ts +4 -4
- package/dist/utils/parseError.js +42 -39
- package/dist/utils/utils.d.ts +1 -16
- package/dist/utils/utils.js +7 -69
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +43 -40
- package/dist/allowance/checkAllowance.d.ts +0 -4
- package/dist/allowance/checkAllowance.js +0 -96
- package/dist/allowance/tokenApproval.d.ts +0 -22
- package/dist/allowance/tokenApproval.js +0 -59
- package/dist/allowance/utils.d.ts +0 -15
- package/dist/allowance/utils.js +0 -77
- package/dist/balance/checkBalance.d.ts +0 -3
- package/dist/balance/checkBalance.js +0 -38
- package/dist/balance/utils.d.ts +0 -6
- package/dist/balance/utils.js +0 -143
- package/dist/cjs/allowance/checkAllowance.d.ts +0 -4
- package/dist/cjs/allowance/checkAllowance.js +0 -103
- package/dist/cjs/allowance/tokenApproval.d.ts +0 -22
- package/dist/cjs/allowance/tokenApproval.js +0 -69
- package/dist/cjs/allowance/utils.d.ts +0 -15
- package/dist/cjs/allowance/utils.js +0 -87
- package/dist/cjs/balance/checkBalance.d.ts +0 -3
- package/dist/cjs/balance/checkBalance.js +0 -45
- package/dist/cjs/balance/utils.d.ts +0 -6
- package/dist/cjs/balance/utils.js +0 -150
- package/dist/cjs/types/ERC20.d.ts +0 -22
- package/dist/cjs/types/ERC20.js +0 -53
- package/dist/cjs/utils/getProvider.d.ts +0 -3
- package/dist/cjs/utils/getProvider.js +0 -11
- package/dist/cjs/utils/multicall.d.ts +0 -10
- package/dist/cjs/utils/multicall.js +0 -68
- package/dist/cjs/utils/multicallAbi.json +0 -313
- package/dist/cjs/utils/preRestart.d.ts +0 -3
- package/dist/cjs/utils/preRestart.js +0 -56
- package/dist/types/ERC20.d.ts +0 -22
- package/dist/types/ERC20.js +0 -50
- package/dist/utils/getProvider.d.ts +0 -3
- package/dist/utils/getProvider.js +0 -7
- package/dist/utils/multicall.d.ts +0 -10
- package/dist/utils/multicall.js +0 -61
- package/dist/utils/multicallAbi.json +0 -313
- package/dist/utils/preRestart.d.ts +0 -3
- package/dist/utils/preRestart.js +0 -52
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.fetchDataUsingMulticall = void 0;
|
|
7
|
-
const abi_1 = require("@ethersproject/abi");
|
|
8
|
-
const contracts_1 = require("@ethersproject/contracts");
|
|
9
|
-
const connectors_1 = require("../connectors");
|
|
10
|
-
const utils_1 = require("./utils");
|
|
11
|
-
const multicallAbi_json_1 = __importDefault(require("./multicallAbi.json"));
|
|
12
|
-
const MAX_MULTICALL_SIZE = 100;
|
|
13
|
-
const fetchDataUsingMulticall = async (calls, abi, chainId, multicallAddress, requireSuccess = false) => {
|
|
14
|
-
// 1. create contract using multicall contract address and abi...
|
|
15
|
-
const provider = await (0, connectors_1.getRpcProvider)(chainId);
|
|
16
|
-
const multicallContract = new contracts_1.Contract(multicallAddress, multicallAbi_json_1.default, provider);
|
|
17
|
-
const abiInterface = new abi_1.Interface(abi);
|
|
18
|
-
// split up lists into chunks to stay below multicall limit
|
|
19
|
-
const chunkedList = (0, utils_1.splitListIntoChunks)(calls, MAX_MULTICALL_SIZE);
|
|
20
|
-
const chunkedResults = await Promise.all(chunkedList.map(async (chunkedCalls) => {
|
|
21
|
-
const callData = chunkedCalls.map((call) => [
|
|
22
|
-
call.address.toLowerCase(),
|
|
23
|
-
abiInterface.encodeFunctionData(call.name, call.params),
|
|
24
|
-
]);
|
|
25
|
-
try {
|
|
26
|
-
// 3. get bytes array from multicall contract by process aggregate method...
|
|
27
|
-
const { blockNumber, returnData } = await multicallContract.tryBlockAndAggregate(requireSuccess, callData);
|
|
28
|
-
// 4. decode bytes array to useful data array...
|
|
29
|
-
return returnData
|
|
30
|
-
.map(({ success, returnData }, i) => {
|
|
31
|
-
if (!success) {
|
|
32
|
-
// requested function failed
|
|
33
|
-
console.error(`Multicall unsuccessful for address "${chunkedCalls[i].address}", ` +
|
|
34
|
-
`function "${chunkedCalls[i].name}", chainId "${chainId}"`);
|
|
35
|
-
return [];
|
|
36
|
-
}
|
|
37
|
-
if (returnData.toString() === '0x') {
|
|
38
|
-
// requested function does probably not exist
|
|
39
|
-
console.error(`Multicall no response for address "${chunkedCalls[i].address}", ` +
|
|
40
|
-
`function "${chunkedCalls[i].name}", chainId "${chainId}"`);
|
|
41
|
-
return [];
|
|
42
|
-
}
|
|
43
|
-
try {
|
|
44
|
-
return abiInterface.decodeFunctionResult(chunkedCalls[i].name, returnData);
|
|
45
|
-
}
|
|
46
|
-
catch (e) {
|
|
47
|
-
// requested function returns other data than expected
|
|
48
|
-
console.error(`Multicall parsing unsuccessful for address "${chunkedCalls[i].address}", ` +
|
|
49
|
-
`function "${chunkedCalls[i].name}", chainId "${chainId}"`);
|
|
50
|
-
return [];
|
|
51
|
-
}
|
|
52
|
-
})
|
|
53
|
-
.map((data) => {
|
|
54
|
-
return {
|
|
55
|
-
data: data[0],
|
|
56
|
-
blockNumber: blockNumber.toNumber(),
|
|
57
|
-
};
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
catch (e) {
|
|
61
|
-
// whole rpc call failed, probably an rpc issue
|
|
62
|
-
console.error(`Multicall failed on chainId "${chainId}"`, chunkedList, e);
|
|
63
|
-
return [];
|
|
64
|
-
}
|
|
65
|
-
}));
|
|
66
|
-
return chunkedResults.flat();
|
|
67
|
-
};
|
|
68
|
-
exports.fetchDataUsingMulticall = fetchDataUsingMulticall;
|
|
@@ -1,313 +0,0 @@
|
|
|
1
|
-
[
|
|
2
|
-
{
|
|
3
|
-
"inputs": [
|
|
4
|
-
{
|
|
5
|
-
"components": [
|
|
6
|
-
{
|
|
7
|
-
"internalType": "address",
|
|
8
|
-
"name": "target",
|
|
9
|
-
"type": "address"
|
|
10
|
-
},
|
|
11
|
-
{
|
|
12
|
-
"internalType": "bytes",
|
|
13
|
-
"name": "callData",
|
|
14
|
-
"type": "bytes"
|
|
15
|
-
}
|
|
16
|
-
],
|
|
17
|
-
"internalType": "struct Multicall2.Call[]",
|
|
18
|
-
"name": "calls",
|
|
19
|
-
"type": "tuple[]"
|
|
20
|
-
}
|
|
21
|
-
],
|
|
22
|
-
"name": "aggregate",
|
|
23
|
-
"outputs": [
|
|
24
|
-
{
|
|
25
|
-
"internalType": "uint256",
|
|
26
|
-
"name": "blockNumber",
|
|
27
|
-
"type": "uint256"
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
"internalType": "bytes[]",
|
|
31
|
-
"name": "returnData",
|
|
32
|
-
"type": "bytes[]"
|
|
33
|
-
}
|
|
34
|
-
],
|
|
35
|
-
"stateMutability": "view",
|
|
36
|
-
"type": "function"
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
"inputs": [
|
|
40
|
-
{
|
|
41
|
-
"components": [
|
|
42
|
-
{
|
|
43
|
-
"internalType": "address",
|
|
44
|
-
"name": "target",
|
|
45
|
-
"type": "address"
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
"internalType": "bytes",
|
|
49
|
-
"name": "callData",
|
|
50
|
-
"type": "bytes"
|
|
51
|
-
}
|
|
52
|
-
],
|
|
53
|
-
"internalType": "struct Multicall2.Call[]",
|
|
54
|
-
"name": "calls",
|
|
55
|
-
"type": "tuple[]"
|
|
56
|
-
}
|
|
57
|
-
],
|
|
58
|
-
"name": "blockAndAggregate",
|
|
59
|
-
"outputs": [
|
|
60
|
-
{
|
|
61
|
-
"internalType": "uint256",
|
|
62
|
-
"name": "blockNumber",
|
|
63
|
-
"type": "uint256"
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
"internalType": "bytes32",
|
|
67
|
-
"name": "blockHash",
|
|
68
|
-
"type": "bytes32"
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
"components": [
|
|
72
|
-
{
|
|
73
|
-
"internalType": "bool",
|
|
74
|
-
"name": "success",
|
|
75
|
-
"type": "bool"
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
"internalType": "bytes",
|
|
79
|
-
"name": "returnData",
|
|
80
|
-
"type": "bytes"
|
|
81
|
-
}
|
|
82
|
-
],
|
|
83
|
-
"internalType": "struct Multicall2.Result[]",
|
|
84
|
-
"name": "returnData",
|
|
85
|
-
"type": "tuple[]"
|
|
86
|
-
}
|
|
87
|
-
],
|
|
88
|
-
"stateMutability": "nonpayable",
|
|
89
|
-
"type": "function"
|
|
90
|
-
},
|
|
91
|
-
{
|
|
92
|
-
"inputs": [
|
|
93
|
-
{
|
|
94
|
-
"internalType": "uint256",
|
|
95
|
-
"name": "blockNumber",
|
|
96
|
-
"type": "uint256"
|
|
97
|
-
}
|
|
98
|
-
],
|
|
99
|
-
"name": "getBlockHash",
|
|
100
|
-
"outputs": [
|
|
101
|
-
{
|
|
102
|
-
"internalType": "bytes32",
|
|
103
|
-
"name": "blockHash",
|
|
104
|
-
"type": "bytes32"
|
|
105
|
-
}
|
|
106
|
-
],
|
|
107
|
-
"stateMutability": "view",
|
|
108
|
-
"type": "function"
|
|
109
|
-
},
|
|
110
|
-
{
|
|
111
|
-
"inputs": [],
|
|
112
|
-
"name": "getBlockNumber",
|
|
113
|
-
"outputs": [
|
|
114
|
-
{
|
|
115
|
-
"internalType": "uint256",
|
|
116
|
-
"name": "blockNumber",
|
|
117
|
-
"type": "uint256"
|
|
118
|
-
}
|
|
119
|
-
],
|
|
120
|
-
"stateMutability": "view",
|
|
121
|
-
"type": "function"
|
|
122
|
-
},
|
|
123
|
-
{
|
|
124
|
-
"inputs": [],
|
|
125
|
-
"name": "getCurrentBlockCoinbase",
|
|
126
|
-
"outputs": [
|
|
127
|
-
{
|
|
128
|
-
"internalType": "address",
|
|
129
|
-
"name": "coinbase",
|
|
130
|
-
"type": "address"
|
|
131
|
-
}
|
|
132
|
-
],
|
|
133
|
-
"stateMutability": "view",
|
|
134
|
-
"type": "function"
|
|
135
|
-
},
|
|
136
|
-
{
|
|
137
|
-
"inputs": [],
|
|
138
|
-
"name": "getCurrentBlockDifficulty",
|
|
139
|
-
"outputs": [
|
|
140
|
-
{
|
|
141
|
-
"internalType": "uint256",
|
|
142
|
-
"name": "difficulty",
|
|
143
|
-
"type": "uint256"
|
|
144
|
-
}
|
|
145
|
-
],
|
|
146
|
-
"stateMutability": "view",
|
|
147
|
-
"type": "function"
|
|
148
|
-
},
|
|
149
|
-
{
|
|
150
|
-
"inputs": [],
|
|
151
|
-
"name": "getCurrentBlockGasLimit",
|
|
152
|
-
"outputs": [
|
|
153
|
-
{
|
|
154
|
-
"internalType": "uint256",
|
|
155
|
-
"name": "gaslimit",
|
|
156
|
-
"type": "uint256"
|
|
157
|
-
}
|
|
158
|
-
],
|
|
159
|
-
"stateMutability": "view",
|
|
160
|
-
"type": "function"
|
|
161
|
-
},
|
|
162
|
-
{
|
|
163
|
-
"inputs": [],
|
|
164
|
-
"name": "getCurrentBlockTimestamp",
|
|
165
|
-
"outputs": [
|
|
166
|
-
{
|
|
167
|
-
"internalType": "uint256",
|
|
168
|
-
"name": "timestamp",
|
|
169
|
-
"type": "uint256"
|
|
170
|
-
}
|
|
171
|
-
],
|
|
172
|
-
"stateMutability": "view",
|
|
173
|
-
"type": "function"
|
|
174
|
-
},
|
|
175
|
-
{
|
|
176
|
-
"inputs": [
|
|
177
|
-
{
|
|
178
|
-
"internalType": "address",
|
|
179
|
-
"name": "addr",
|
|
180
|
-
"type": "address"
|
|
181
|
-
}
|
|
182
|
-
],
|
|
183
|
-
"name": "getEthBalance",
|
|
184
|
-
"outputs": [
|
|
185
|
-
{
|
|
186
|
-
"internalType": "uint256",
|
|
187
|
-
"name": "balance",
|
|
188
|
-
"type": "uint256"
|
|
189
|
-
}
|
|
190
|
-
],
|
|
191
|
-
"stateMutability": "view",
|
|
192
|
-
"type": "function"
|
|
193
|
-
},
|
|
194
|
-
{
|
|
195
|
-
"inputs": [],
|
|
196
|
-
"name": "getLastBlockHash",
|
|
197
|
-
"outputs": [
|
|
198
|
-
{
|
|
199
|
-
"internalType": "bytes32",
|
|
200
|
-
"name": "blockHash",
|
|
201
|
-
"type": "bytes32"
|
|
202
|
-
}
|
|
203
|
-
],
|
|
204
|
-
"stateMutability": "view",
|
|
205
|
-
"type": "function"
|
|
206
|
-
},
|
|
207
|
-
{
|
|
208
|
-
"inputs": [
|
|
209
|
-
{
|
|
210
|
-
"internalType": "bool",
|
|
211
|
-
"name": "requireSuccess",
|
|
212
|
-
"type": "bool"
|
|
213
|
-
},
|
|
214
|
-
{
|
|
215
|
-
"components": [
|
|
216
|
-
{
|
|
217
|
-
"internalType": "address",
|
|
218
|
-
"name": "target",
|
|
219
|
-
"type": "address"
|
|
220
|
-
},
|
|
221
|
-
{
|
|
222
|
-
"internalType": "bytes",
|
|
223
|
-
"name": "callData",
|
|
224
|
-
"type": "bytes"
|
|
225
|
-
}
|
|
226
|
-
],
|
|
227
|
-
"internalType": "struct Multicall2.Call[]",
|
|
228
|
-
"name": "calls",
|
|
229
|
-
"type": "tuple[]"
|
|
230
|
-
}
|
|
231
|
-
],
|
|
232
|
-
"name": "tryAggregate",
|
|
233
|
-
"outputs": [
|
|
234
|
-
{
|
|
235
|
-
"components": [
|
|
236
|
-
{
|
|
237
|
-
"internalType": "bool",
|
|
238
|
-
"name": "success",
|
|
239
|
-
"type": "bool"
|
|
240
|
-
},
|
|
241
|
-
{
|
|
242
|
-
"internalType": "bytes",
|
|
243
|
-
"name": "returnData",
|
|
244
|
-
"type": "bytes"
|
|
245
|
-
}
|
|
246
|
-
],
|
|
247
|
-
"internalType": "struct Multicall2.Result[]",
|
|
248
|
-
"name": "returnData",
|
|
249
|
-
"type": "tuple[]"
|
|
250
|
-
}
|
|
251
|
-
],
|
|
252
|
-
"stateMutability": "view",
|
|
253
|
-
"type": "function"
|
|
254
|
-
},
|
|
255
|
-
{
|
|
256
|
-
"inputs": [
|
|
257
|
-
{
|
|
258
|
-
"internalType": "bool",
|
|
259
|
-
"name": "requireSuccess",
|
|
260
|
-
"type": "bool"
|
|
261
|
-
},
|
|
262
|
-
{
|
|
263
|
-
"components": [
|
|
264
|
-
{
|
|
265
|
-
"internalType": "address",
|
|
266
|
-
"name": "target",
|
|
267
|
-
"type": "address"
|
|
268
|
-
},
|
|
269
|
-
{
|
|
270
|
-
"internalType": "bytes",
|
|
271
|
-
"name": "callData",
|
|
272
|
-
"type": "bytes"
|
|
273
|
-
}
|
|
274
|
-
],
|
|
275
|
-
"internalType": "struct Multicall2.Call[]",
|
|
276
|
-
"name": "calls",
|
|
277
|
-
"type": "tuple[]"
|
|
278
|
-
}
|
|
279
|
-
],
|
|
280
|
-
"name": "tryBlockAndAggregate",
|
|
281
|
-
"outputs": [
|
|
282
|
-
{
|
|
283
|
-
"internalType": "uint256",
|
|
284
|
-
"name": "blockNumber",
|
|
285
|
-
"type": "uint256"
|
|
286
|
-
},
|
|
287
|
-
{
|
|
288
|
-
"internalType": "bytes32",
|
|
289
|
-
"name": "blockHash",
|
|
290
|
-
"type": "bytes32"
|
|
291
|
-
},
|
|
292
|
-
{
|
|
293
|
-
"components": [
|
|
294
|
-
{
|
|
295
|
-
"internalType": "bool",
|
|
296
|
-
"name": "success",
|
|
297
|
-
"type": "bool"
|
|
298
|
-
},
|
|
299
|
-
{
|
|
300
|
-
"internalType": "bytes",
|
|
301
|
-
"name": "returnData",
|
|
302
|
-
"type": "bytes"
|
|
303
|
-
}
|
|
304
|
-
],
|
|
305
|
-
"internalType": "struct Multicall2.Result[]",
|
|
306
|
-
"name": "returnData",
|
|
307
|
-
"type": "tuple[]"
|
|
308
|
-
}
|
|
309
|
-
],
|
|
310
|
-
"stateMutability": "view",
|
|
311
|
-
"type": "function"
|
|
312
|
-
}
|
|
313
|
-
]
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.handlePreRestart = void 0;
|
|
4
|
-
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
5
|
-
const ethers_1 = require("ethers");
|
|
6
|
-
const errors_1 = require("./errors");
|
|
7
|
-
const handlePreRestart = async (route, signer) => {
|
|
8
|
-
for (let index = 0; index < route.steps.length; index++) {
|
|
9
|
-
const stepHasFailed = route.steps[index].execution?.status === 'FAILED';
|
|
10
|
-
if (stepHasFailed) {
|
|
11
|
-
await handleErrorType(route, index, signer);
|
|
12
|
-
deleteFailedProcesses(route, index);
|
|
13
|
-
deleteTransactionData(route, index);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
exports.handlePreRestart = handlePreRestart;
|
|
18
|
-
const handleErrorType = async (route, index, signer) => {
|
|
19
|
-
const isGasLimitError = route.steps[index].execution?.process.some((p) => p.error?.code === errors_1.LifiErrorCode.GasLimitError);
|
|
20
|
-
const isGasPriceError = route.steps[index].execution?.process.some((p) => p.error?.code === errors_1.LifiErrorCode.TransactionUnderpriced);
|
|
21
|
-
const { transactionRequest } = route.steps[index];
|
|
22
|
-
if (isGasLimitError) {
|
|
23
|
-
if (transactionRequest) {
|
|
24
|
-
let gasLimit = transactionRequest.gasLimit;
|
|
25
|
-
try {
|
|
26
|
-
gasLimit = await signer.estimateGas(transactionRequest);
|
|
27
|
-
}
|
|
28
|
-
catch (error) { }
|
|
29
|
-
if (gasLimit) {
|
|
30
|
-
transactionRequest.gasLimit = ethers_1.BigNumber.from(`${(BigInt(gasLimit.toString()) * 125n) / 100n}`);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
route.steps[index].estimate.gasCosts?.forEach((gasCost) => (gasCost.limit = `${Math.round(Number(gasCost.limit) * 1.25)}`));
|
|
34
|
-
}
|
|
35
|
-
if (isGasPriceError) {
|
|
36
|
-
if (transactionRequest) {
|
|
37
|
-
let gasPrice = transactionRequest.gasPrice;
|
|
38
|
-
try {
|
|
39
|
-
gasPrice = await signer.getGasPrice();
|
|
40
|
-
}
|
|
41
|
-
catch (error) { }
|
|
42
|
-
if (gasPrice) {
|
|
43
|
-
transactionRequest.gasPrice = ethers_1.BigNumber.from(`${(BigInt(gasPrice.toString()) * 125n) / 100n}`);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
route.steps[index].estimate.gasCosts?.forEach((gasCost) => (gasCost.price = `${Math.round(Number(gasCost.price) * 1.25)}`));
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
const deleteFailedProcesses = (route, index) => {
|
|
50
|
-
if (route.steps[index].execution) {
|
|
51
|
-
route.steps[index].execution.process = route.steps[index].execution.process.filter((process) => process.status === 'DONE');
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
const deleteTransactionData = (route, index) => {
|
|
55
|
-
route.steps[index].transactionRequest = undefined;
|
|
56
|
-
};
|
package/dist/types/ERC20.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { BaseContract, BigNumber, BigNumberish, CallOverrides, ContractTransaction, Overrides } from 'ethers';
|
|
2
|
-
export declare const ERC20_ABI: {
|
|
3
|
-
name: string;
|
|
4
|
-
inputs: {
|
|
5
|
-
internalType: string;
|
|
6
|
-
name: string;
|
|
7
|
-
type: string;
|
|
8
|
-
}[];
|
|
9
|
-
outputs: {
|
|
10
|
-
internalType: string;
|
|
11
|
-
name: string;
|
|
12
|
-
type: string;
|
|
13
|
-
}[];
|
|
14
|
-
stateMutability: string;
|
|
15
|
-
type: string;
|
|
16
|
-
}[];
|
|
17
|
-
export interface ERC20Contract extends BaseContract {
|
|
18
|
-
allowance(owner: string, spender: string, overrides?: CallOverrides): Promise<BigNumber>;
|
|
19
|
-
approve(spender: string, amount: BigNumberish, overrides?: Overrides & {
|
|
20
|
-
from?: string | Promise<string>;
|
|
21
|
-
}): Promise<ContractTransaction>;
|
|
22
|
-
}
|
package/dist/types/ERC20.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
export const ERC20_ABI = [
|
|
2
|
-
{
|
|
3
|
-
name: 'approve',
|
|
4
|
-
inputs: [
|
|
5
|
-
{
|
|
6
|
-
internalType: 'address',
|
|
7
|
-
name: 'spender',
|
|
8
|
-
type: 'address',
|
|
9
|
-
},
|
|
10
|
-
{
|
|
11
|
-
internalType: 'uint256',
|
|
12
|
-
name: 'amount',
|
|
13
|
-
type: 'uint256',
|
|
14
|
-
},
|
|
15
|
-
],
|
|
16
|
-
outputs: [
|
|
17
|
-
{
|
|
18
|
-
internalType: 'bool',
|
|
19
|
-
name: '',
|
|
20
|
-
type: 'bool',
|
|
21
|
-
},
|
|
22
|
-
],
|
|
23
|
-
stateMutability: 'nonpayable',
|
|
24
|
-
type: 'function',
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
name: 'allowance',
|
|
28
|
-
inputs: [
|
|
29
|
-
{
|
|
30
|
-
internalType: 'address',
|
|
31
|
-
name: 'owner',
|
|
32
|
-
type: 'address',
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
internalType: 'address',
|
|
36
|
-
name: 'spender',
|
|
37
|
-
type: 'address',
|
|
38
|
-
},
|
|
39
|
-
],
|
|
40
|
-
outputs: [
|
|
41
|
-
{
|
|
42
|
-
internalType: 'uint256',
|
|
43
|
-
name: '',
|
|
44
|
-
type: 'uint256',
|
|
45
|
-
},
|
|
46
|
-
],
|
|
47
|
-
stateMutability: 'view',
|
|
48
|
-
type: 'function',
|
|
49
|
-
},
|
|
50
|
-
];
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Fragment, JsonFragment } from '@ethersproject/abi';
|
|
2
|
-
export type MultiCallData = {
|
|
3
|
-
address: string;
|
|
4
|
-
name: string;
|
|
5
|
-
params?: any[];
|
|
6
|
-
};
|
|
7
|
-
export declare const fetchDataUsingMulticall: (calls: Array<MultiCallData>, abi: ReadonlyArray<Fragment | JsonFragment | string>, chainId: number, multicallAddress: string, requireSuccess?: boolean) => Promise<{
|
|
8
|
-
data: unknown;
|
|
9
|
-
blockNumber: number;
|
|
10
|
-
}[]>;
|
package/dist/utils/multicall.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { Interface } from '@ethersproject/abi';
|
|
2
|
-
import { Contract } from '@ethersproject/contracts';
|
|
3
|
-
import { getRpcProvider } from '../connectors';
|
|
4
|
-
import { splitListIntoChunks } from './utils';
|
|
5
|
-
import MULTICALL_ABI from './multicallAbi.json';
|
|
6
|
-
const MAX_MULTICALL_SIZE = 100;
|
|
7
|
-
export const fetchDataUsingMulticall = async (calls, abi, chainId, multicallAddress, requireSuccess = false) => {
|
|
8
|
-
// 1. create contract using multicall contract address and abi...
|
|
9
|
-
const provider = await getRpcProvider(chainId);
|
|
10
|
-
const multicallContract = new Contract(multicallAddress, MULTICALL_ABI, provider);
|
|
11
|
-
const abiInterface = new Interface(abi);
|
|
12
|
-
// split up lists into chunks to stay below multicall limit
|
|
13
|
-
const chunkedList = splitListIntoChunks(calls, MAX_MULTICALL_SIZE);
|
|
14
|
-
const chunkedResults = await Promise.all(chunkedList.map(async (chunkedCalls) => {
|
|
15
|
-
const callData = chunkedCalls.map((call) => [
|
|
16
|
-
call.address.toLowerCase(),
|
|
17
|
-
abiInterface.encodeFunctionData(call.name, call.params),
|
|
18
|
-
]);
|
|
19
|
-
try {
|
|
20
|
-
// 3. get bytes array from multicall contract by process aggregate method...
|
|
21
|
-
const { blockNumber, returnData } = await multicallContract.tryBlockAndAggregate(requireSuccess, callData);
|
|
22
|
-
// 4. decode bytes array to useful data array...
|
|
23
|
-
return returnData
|
|
24
|
-
.map(({ success, returnData }, i) => {
|
|
25
|
-
if (!success) {
|
|
26
|
-
// requested function failed
|
|
27
|
-
console.error(`Multicall unsuccessful for address "${chunkedCalls[i].address}", ` +
|
|
28
|
-
`function "${chunkedCalls[i].name}", chainId "${chainId}"`);
|
|
29
|
-
return [];
|
|
30
|
-
}
|
|
31
|
-
if (returnData.toString() === '0x') {
|
|
32
|
-
// requested function does probably not exist
|
|
33
|
-
console.error(`Multicall no response for address "${chunkedCalls[i].address}", ` +
|
|
34
|
-
`function "${chunkedCalls[i].name}", chainId "${chainId}"`);
|
|
35
|
-
return [];
|
|
36
|
-
}
|
|
37
|
-
try {
|
|
38
|
-
return abiInterface.decodeFunctionResult(chunkedCalls[i].name, returnData);
|
|
39
|
-
}
|
|
40
|
-
catch (e) {
|
|
41
|
-
// requested function returns other data than expected
|
|
42
|
-
console.error(`Multicall parsing unsuccessful for address "${chunkedCalls[i].address}", ` +
|
|
43
|
-
`function "${chunkedCalls[i].name}", chainId "${chainId}"`);
|
|
44
|
-
return [];
|
|
45
|
-
}
|
|
46
|
-
})
|
|
47
|
-
.map((data) => {
|
|
48
|
-
return {
|
|
49
|
-
data: data[0],
|
|
50
|
-
blockNumber: blockNumber.toNumber(),
|
|
51
|
-
};
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
catch (e) {
|
|
55
|
-
// whole rpc call failed, probably an rpc issue
|
|
56
|
-
console.error(`Multicall failed on chainId "${chainId}"`, chunkedList, e);
|
|
57
|
-
return [];
|
|
58
|
-
}
|
|
59
|
-
}));
|
|
60
|
-
return chunkedResults.flat();
|
|
61
|
-
};
|