@defillama/sdk 4.0.81 → 5.0.1
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/build/ChainApi.d.ts +4 -2
- package/build/ChainApi.js +7 -0
- package/build/abi/convertResults.d.ts +1 -1
- package/build/abi/convertResults.js +25 -3
- package/build/abi/index.js +18 -17
- package/build/abi/multicall.d.ts +3 -3
- package/build/abi/multicall.js +90 -59
- package/build/abi/multicall3.d.ts +3 -4
- package/build/abi/multicall3.js +10 -5
- package/build/abi/rpcCall.d.ts +2 -3
- package/build/abi/rpcCall.js +1 -0
- package/build/abi/tron.js +8 -9
- package/build/erc20/index.d.ts +2 -2
- package/build/erc20/index.js +25 -24
- package/build/general.d.ts +3 -4
- package/build/general.js +58 -15
- package/build/generalUtil.d.ts +2 -2
- package/build/generalUtil.js +28 -20
- package/build/providers.json +1 -1
- package/build/util/blocks.js +1 -2
- package/build/util/index.d.ts +3 -3
- package/build/util/index.js +2 -2
- package/package.json +4 -4
package/build/ChainApi.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { Block, CallOptions, MulticallOptions, FetchListOptions, ByteCodeCallOptions, Balances as BalancesV1 } from "./types";
|
|
2
2
|
import Balances from "./Balances";
|
|
3
3
|
import { Chain } from "./general";
|
|
4
|
-
import {
|
|
4
|
+
import { Provider } from "ethers";
|
|
5
5
|
export declare class ChainApi {
|
|
6
6
|
block?: Block;
|
|
7
7
|
chain: Chain | string;
|
|
8
8
|
chainId?: number;
|
|
9
9
|
timestamp?: number;
|
|
10
|
-
provider:
|
|
10
|
+
provider: Provider;
|
|
11
11
|
_balances: Balances;
|
|
12
12
|
constructor(params: {
|
|
13
13
|
block?: Block;
|
|
@@ -36,6 +36,8 @@ export declare class ChainApi {
|
|
|
36
36
|
getBalances(): BalancesV1;
|
|
37
37
|
getChainId(): number | undefined;
|
|
38
38
|
removeTokenBalance(token: string): void;
|
|
39
|
+
deleteToken(token: string): void;
|
|
40
|
+
deleteTokens(tokens: string[]): void;
|
|
39
41
|
erc4626Sum({ calls, tokenAbi, balanceAbi, balanceCalls, permitFailure }: any): Promise<void>;
|
|
40
42
|
sumTokens({ tokens, owners, owner, tokensAndOwners, tokensAndOwners2, blacklistedTokens, blacklistedOwners, ownerTokens, }: {
|
|
41
43
|
tokens?: string[];
|
package/build/ChainApi.js
CHANGED
|
@@ -146,6 +146,13 @@ var ChainApi = /** @class */ (function () {
|
|
|
146
146
|
ChainApi.prototype.removeTokenBalance = function (token) {
|
|
147
147
|
this._balances.removeTokenBalance(token);
|
|
148
148
|
};
|
|
149
|
+
ChainApi.prototype.deleteToken = function (token) {
|
|
150
|
+
this._balances.removeTokenBalance(token);
|
|
151
|
+
};
|
|
152
|
+
ChainApi.prototype.deleteTokens = function (tokens) {
|
|
153
|
+
var _this = this;
|
|
154
|
+
tokens.forEach(function (i) { return _this.deleteToken(i); });
|
|
155
|
+
};
|
|
149
156
|
ChainApi.prototype.erc4626Sum = function (_a) {
|
|
150
157
|
var calls = _a.calls, _b = _a.tokenAbi, tokenAbi = _b === void 0 ? 'address:token' : _b, _c = _a.balanceAbi, balanceAbi = _c === void 0 ? 'uint256:balance' : _c, balanceCalls = _a.balanceCalls, _d = _a.permitFailure, permitFailure = _d === void 0 ? false : _d;
|
|
151
158
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { ethers } from "ethers";
|
|
2
|
-
export default function (results: ethers.
|
|
2
|
+
export default function (results: ethers.Result, functionABI?: ethers.FunctionFragment): any;
|
|
@@ -20,9 +20,8 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
20
20
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
21
21
|
};
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
var bignumber_1 = require("@ethersproject/bignumber");
|
|
24
23
|
function isNumberOrBigNumber(value) {
|
|
25
|
-
return
|
|
24
|
+
return typeof value === 'bigint' || typeof value === "number";
|
|
26
25
|
}
|
|
27
26
|
function stringifyBigNumbers(result) {
|
|
28
27
|
var final = __assign({}, result);
|
|
@@ -38,16 +37,39 @@ function stringifyBigNumbers(result) {
|
|
|
38
37
|
});
|
|
39
38
|
return final;
|
|
40
39
|
}
|
|
41
|
-
function default_1(results) {
|
|
40
|
+
function default_1(results, functionABI) {
|
|
42
41
|
var response;
|
|
43
42
|
if (typeof results === "string" || typeof results === "boolean")
|
|
44
43
|
return results;
|
|
45
44
|
if (isNumberOrBigNumber(results))
|
|
46
45
|
return results.toString();
|
|
47
46
|
response = stringifyBigNumbers(results);
|
|
47
|
+
if (functionABI && functionABI.outputs) {
|
|
48
|
+
var outputNames = functionABI.outputs.map(function (i) { return i.name; });
|
|
49
|
+
outputNames.map(function (name, i) {
|
|
50
|
+
setComponentDetails(response[i], functionABI.outputs[i]);
|
|
51
|
+
if (name)
|
|
52
|
+
response[name] = response[i];
|
|
53
|
+
});
|
|
54
|
+
}
|
|
48
55
|
if (response instanceof Array)
|
|
49
56
|
if (response.length === 1)
|
|
50
57
|
return response[0];
|
|
51
58
|
return response;
|
|
52
59
|
}
|
|
53
60
|
exports.default = default_1;
|
|
61
|
+
function setComponentDetails(component, componentDefinition) {
|
|
62
|
+
if (componentDefinition.type === "tuple[]")
|
|
63
|
+
return component.map(setDetails);
|
|
64
|
+
if (componentDefinition.type === "tuple")
|
|
65
|
+
return setDetails(component);
|
|
66
|
+
function setDetails(value) {
|
|
67
|
+
var definitions = componentDefinition.components || componentDefinition.arrayChildren.components;
|
|
68
|
+
definitions.map(function (def, i) {
|
|
69
|
+
setComponentDetails(value[i], def);
|
|
70
|
+
var name = def.name;
|
|
71
|
+
if (name)
|
|
72
|
+
value[name] = value[i];
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
package/build/abi/index.js
CHANGED
|
@@ -109,8 +109,8 @@ function resolveABI(providedAbi) {
|
|
|
109
109
|
if (typeof abi === "string") {
|
|
110
110
|
var _a = providedAbi.split(':'), outputType = _a[0], name_1 = _a[1];
|
|
111
111
|
if (!knownTypes.includes(outputType) || !name_1) {
|
|
112
|
-
var contractInterface = new ethers_1.ethers.
|
|
113
|
-
var jsonAbi = contractInterface.
|
|
112
|
+
var contractInterface = new ethers_1.ethers.Interface([providedAbi]);
|
|
113
|
+
var jsonAbi = contractInterface.formatJson();
|
|
114
114
|
return JSON.parse(jsonAbi)[0];
|
|
115
115
|
}
|
|
116
116
|
abi = {
|
|
@@ -160,11 +160,11 @@ function isValidTarget(target, chain) {
|
|
|
160
160
|
return target.startsWith('0x') && target !== nullAddress;
|
|
161
161
|
}
|
|
162
162
|
function call(params) {
|
|
163
|
-
var _a
|
|
163
|
+
var _a;
|
|
164
164
|
return __awaiter(this, void 0, void 0, function () {
|
|
165
165
|
var chain, errorParams, abi, callParams, contractInterface, functionABI, callData, provider, result, decodedResult, output, e_1;
|
|
166
|
-
return __generator(this, function (
|
|
167
|
-
switch (
|
|
166
|
+
return __generator(this, function (_b) {
|
|
167
|
+
switch (_b.label) {
|
|
168
168
|
case 0:
|
|
169
169
|
if (!isValidTarget(params.target, params.chain))
|
|
170
170
|
throw new Error('Invalid target: ' + params.target);
|
|
@@ -173,29 +173,30 @@ function call(params) {
|
|
|
173
173
|
if (cachedABIs_1.default[params.abi])
|
|
174
174
|
params.abi = cachedABIs_1.default[params.abi];
|
|
175
175
|
errorParams = __assign({}, params);
|
|
176
|
-
|
|
176
|
+
_b.label = 1;
|
|
177
177
|
case 1:
|
|
178
|
-
|
|
178
|
+
_b.trys.push([1, 3, , 4]);
|
|
179
179
|
if (!params.skipCache)
|
|
180
180
|
return [2 /*return*/, cachedCall(params)];
|
|
181
181
|
abi = resolveABI(params.abi);
|
|
182
182
|
callParams = normalizeParams(params.params);
|
|
183
183
|
if (chain === 'tron')
|
|
184
184
|
return [2 /*return*/, Tron.call(__assign(__assign({}, params), { abi: abi, params: callParams }))];
|
|
185
|
-
contractInterface = new ethers_1.ethers.
|
|
186
|
-
functionABI = ethers_1.ethers.
|
|
185
|
+
contractInterface = new ethers_1.ethers.Interface([abi]);
|
|
186
|
+
functionABI = ethers_1.ethers.FunctionFragment.from(abi);
|
|
187
187
|
callData = contractInterface.encodeFunctionData(functionABI, callParams);
|
|
188
188
|
provider = (0, general_1.getProvider)(chain);
|
|
189
189
|
errorParams.provider = provider;
|
|
190
190
|
return [4 /*yield*/, provider.call({
|
|
191
191
|
to: params.target,
|
|
192
192
|
data: callData,
|
|
193
|
-
|
|
193
|
+
blockTag: params.block,
|
|
194
|
+
})];
|
|
194
195
|
case 2:
|
|
195
|
-
result =
|
|
196
|
+
result = _b.sent();
|
|
196
197
|
errorParams.result = result;
|
|
197
|
-
decodedResult = contractInterface.decodeFunctionResult(
|
|
198
|
-
output = (0, convertResults_1.default)(decodedResult);
|
|
198
|
+
decodedResult = contractInterface.decodeFunctionResult(abi, result);
|
|
199
|
+
output = (0, convertResults_1.default)(decodedResult, functionABI);
|
|
199
200
|
if (params.logArray && abi.name == 'balanceOf' && abi.outputs[0].type == 'uint256')
|
|
200
201
|
params.logArray.push({
|
|
201
202
|
chain: chain,
|
|
@@ -207,7 +208,7 @@ function call(params) {
|
|
|
207
208
|
output: output,
|
|
208
209
|
}];
|
|
209
210
|
case 3:
|
|
210
|
-
e_1 =
|
|
211
|
+
e_1 = _b.sent();
|
|
211
212
|
errorParams.isCallError = true;
|
|
212
213
|
throw (0, generalUtil_1.formError)(e_1, errorParams);
|
|
213
214
|
case 4: return [2 /*return*/];
|
|
@@ -228,12 +229,12 @@ function bytecodeCall(params) {
|
|
|
228
229
|
throw new Error('Missing bytecode parameter!');
|
|
229
230
|
if (chain === 'tron')
|
|
230
231
|
throw new Error('Bytecode call is not supported on Tron');
|
|
231
|
-
inputData = ethers_1.ethers.
|
|
232
|
+
inputData = ethers_1.ethers.AbiCoder.defaultAbiCoder().encode(inputTypes, inputs);
|
|
232
233
|
callData = '0x' + bytecode.concat(inputData.slice(2));
|
|
233
|
-
return [4 /*yield*/, (0, general_1.getProvider)(chain).call({ data: callData,
|
|
234
|
+
return [4 /*yield*/, (0, general_1.getProvider)(chain).call({ data: callData, blockTag: block })];
|
|
234
235
|
case 1:
|
|
235
236
|
result = _a.sent();
|
|
236
|
-
decodedResult = ethers_1.ethers.
|
|
237
|
+
decodedResult = ethers_1.ethers.AbiCoder.defaultAbiCoder().decode(outputTypes, result);
|
|
237
238
|
return [2 /*return*/, {
|
|
238
239
|
output: (0, convertResults_1.default)(decodedResult),
|
|
239
240
|
}];
|
package/build/abi/multicall.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Chain } from "../general";
|
|
2
|
-
import { BlockTag } from "@ethersproject/providers";
|
|
3
2
|
export declare const MULTICALL_ADDRESS_MAINNET = "0xeefba1e63905ef1d7acba5a8513c70307c1ce441";
|
|
4
3
|
export declare const MULTICALL_ADDRESS_KOVAN = "0x2cc8688c5f75e365aaeeb4ea8d6a480405a48d2a";
|
|
5
4
|
export declare const MULTICALL_ADDRESS_RINKEBY = "0x42ad527de7d4e9d9d011ac45b31d8551f8fe9821";
|
|
@@ -19,5 +18,6 @@ export declare const AGGREGATE_SELECTOR = "0x252dba42";
|
|
|
19
18
|
export default function makeMultiCall(functionABI: any, calls: {
|
|
20
19
|
contract: string;
|
|
21
20
|
params: any[];
|
|
22
|
-
}[], chain: Chain, block?:
|
|
23
|
-
export declare function
|
|
21
|
+
}[], chain: Chain, block?: string | number): Promise<any>;
|
|
22
|
+
export declare function multicallAddressOrThrow(chain: Chain): Promise<string>;
|
|
23
|
+
export declare function networkSupportsMulticall(chain: Chain): Promise<boolean>;
|
package/build/abi/multicall.js
CHANGED
|
@@ -62,9 +62,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
62
62
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
63
63
|
};
|
|
64
64
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
65
|
-
exports.networkSupportsMulticall = exports.AGGREGATE_SELECTOR = exports.MULTICALL_ADDRESS_OPTIMISM = exports.MULTICALL_ADDRESS_AURORA = exports.MULTICALL_ADDRESS_MOONRIVER = exports.MULTICALL_ADDRESS_AVAX = exports.MULTICALL_ADDRESS_ARBITRUM = exports.MULTICALL_ADDRESS_HARMONY = exports.MULTICALL_ADDRESS_HECO = exports.MULTICALL_ADDRESS_XDAI = exports.MULTICALL_ADDRESS_FANTOM = exports.MULTICALL_ADDRESS_BSC = exports.MULTICALL_ADDRESS_POLYGON = exports.MULTICALL_ADDRESS_GOERLI = exports.MULTICALL_ADDRESS_RINKEBY = exports.MULTICALL_ADDRESS_KOVAN = exports.MULTICALL_ADDRESS_MAINNET = void 0;
|
|
65
|
+
exports.networkSupportsMulticall = exports.multicallAddressOrThrow = exports.AGGREGATE_SELECTOR = exports.MULTICALL_ADDRESS_OPTIMISM = exports.MULTICALL_ADDRESS_AURORA = exports.MULTICALL_ADDRESS_MOONRIVER = exports.MULTICALL_ADDRESS_AVAX = exports.MULTICALL_ADDRESS_ARBITRUM = exports.MULTICALL_ADDRESS_HARMONY = exports.MULTICALL_ADDRESS_HECO = exports.MULTICALL_ADDRESS_XDAI = exports.MULTICALL_ADDRESS_FANTOM = exports.MULTICALL_ADDRESS_BSC = exports.MULTICALL_ADDRESS_POLYGON = exports.MULTICALL_ADDRESS_GOERLI = exports.MULTICALL_ADDRESS_RINKEBY = exports.MULTICALL_ADDRESS_KOVAN = exports.MULTICALL_ADDRESS_MAINNET = void 0;
|
|
66
66
|
var ethers_1 = require("ethers");
|
|
67
|
-
var utils_1 = require("ethers/lib/utils");
|
|
68
67
|
var general_1 = require("../general");
|
|
69
68
|
var convertResults_1 = __importDefault(require("./convertResults"));
|
|
70
69
|
var rpcCall_1 = require("./rpcCall");
|
|
@@ -95,8 +94,8 @@ function makeMultiCall(functionABI, calls, chain, block) {
|
|
|
95
94
|
case 0:
|
|
96
95
|
if (chain === 'tron')
|
|
97
96
|
return [2 /*return*/, Tron.multiCall(functionABI, calls)];
|
|
98
|
-
contractInterface = new ethers_1.ethers.
|
|
99
|
-
fd =
|
|
97
|
+
contractInterface = new ethers_1.ethers.Interface([functionABI]);
|
|
98
|
+
fd = contractInterface.fragments[0];
|
|
100
99
|
contractCalls = calls.map(function (call) {
|
|
101
100
|
var data = contractInterface.encodeFunctionData(fd, call.params);
|
|
102
101
|
return {
|
|
@@ -111,7 +110,7 @@ function makeMultiCall(functionABI, calls, chain, block) {
|
|
|
111
110
|
var output;
|
|
112
111
|
var error = undefined;
|
|
113
112
|
try {
|
|
114
|
-
output = (0, convertResults_1.default)(contractInterface.decodeFunctionResult(fd, values));
|
|
113
|
+
output = (0, convertResults_1.default)(contractInterface.decodeFunctionResult(fd, values), fd);
|
|
115
114
|
}
|
|
116
115
|
catch (e) {
|
|
117
116
|
output = null;
|
|
@@ -136,17 +135,19 @@ function makeMultiCall(functionABI, calls, chain, block) {
|
|
|
136
135
|
exports.default = makeMultiCall;
|
|
137
136
|
function executeCalls(contractCalls, chain, block) {
|
|
138
137
|
return __awaiter(this, void 0, void 0, function () {
|
|
139
|
-
var multicallData, address, callData, tx, returnData, _a, blockNumber, returnValues, e_1, chunkSize, chunks, response;
|
|
138
|
+
var multicallData, address, callData, tx, returnData, _a, blockNumber, returnValues, e_1, chunkSize, chunks, response, _b;
|
|
139
|
+
var _c;
|
|
140
140
|
var _this = this;
|
|
141
|
-
return __generator(this, function (
|
|
142
|
-
switch (
|
|
143
|
-
case 0:
|
|
144
|
-
if (!networkSupportsMulticall(chain)) return [3 /*break*/, 7];
|
|
145
|
-
_b.label = 1;
|
|
141
|
+
return __generator(this, function (_d) {
|
|
142
|
+
switch (_d.label) {
|
|
143
|
+
case 0: return [4 /*yield*/, networkSupportsMulticall(chain)];
|
|
146
144
|
case 1:
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
145
|
+
if (!_d.sent()) return [3 /*break*/, 8];
|
|
146
|
+
_d.label = 2;
|
|
147
|
+
case 2:
|
|
148
|
+
_d.trys.push([2, 5, , 8]);
|
|
149
|
+
multicallData = ethers_1.ethers.AbiCoder.defaultAbiCoder().encode([
|
|
150
|
+
ethers_1.ethers.ParamType.from({
|
|
150
151
|
components: [
|
|
151
152
|
{ name: "target", type: "address" },
|
|
152
153
|
{ name: "callData", type: "bytes" },
|
|
@@ -156,21 +157,21 @@ function executeCalls(contractCalls, chain, block) {
|
|
|
156
157
|
}),
|
|
157
158
|
], [contractCalls.map(function (call) { return [call.to, call.data]; })]);
|
|
158
159
|
return [4 /*yield*/, multicallAddressOrThrow(chain)];
|
|
159
|
-
case
|
|
160
|
-
address =
|
|
160
|
+
case 3:
|
|
161
|
+
address = _d.sent();
|
|
161
162
|
callData = exports.AGGREGATE_SELECTOR + multicallData.substr(2);
|
|
162
163
|
tx = {
|
|
163
164
|
to: address,
|
|
164
165
|
data: callData,
|
|
165
166
|
};
|
|
166
|
-
return [4 /*yield*/, (0, rpcCall_1.call)((0, general_1.getProvider)(chain), tx, block
|
|
167
|
-
case 3:
|
|
168
|
-
returnData = _b.sent();
|
|
169
|
-
_a = ethers_1.ethers.utils.defaultAbiCoder.decode(["uint256", "bytes[]"], returnData), blockNumber = _a[0], returnValues = _a[1];
|
|
170
|
-
return [2 /*return*/, returnValues];
|
|
167
|
+
return [4 /*yield*/, (0, rpcCall_1.call)((0, general_1.getProvider)(chain), tx, block, chain)];
|
|
171
168
|
case 4:
|
|
172
|
-
|
|
173
|
-
|
|
169
|
+
returnData = _d.sent();
|
|
170
|
+
_a = ethers_1.ethers.AbiCoder.defaultAbiCoder().decode(["uint256", "bytes[]"], returnData), blockNumber = _a[0], returnValues = _a[1];
|
|
171
|
+
return [2 /*return*/, returnValues];
|
|
172
|
+
case 5:
|
|
173
|
+
e_1 = _d.sent();
|
|
174
|
+
if (!(contractCalls.length > 10)) return [3 /*break*/, 7];
|
|
174
175
|
chunkSize = Math.ceil(contractCalls.length / 5);
|
|
175
176
|
chunks = (0, util_1.sliceIntoChunks)(contractCalls, chunkSize);
|
|
176
177
|
(0, debugLog_1.debugLog)("Multicall failed, call size: ".concat(contractCalls.length, ", splitting into smaller chunks and trying again, new call size: ").concat(chunks[0].length));
|
|
@@ -179,50 +180,58 @@ function executeCalls(contractCalls, chain, block) {
|
|
|
179
180
|
concurrency: 2,
|
|
180
181
|
processor: function (calls) { return executeCalls(calls, chain, block); }
|
|
181
182
|
})];
|
|
182
|
-
case 5:
|
|
183
|
-
response = _b.sent();
|
|
184
|
-
return [2 /*return*/, response.flat()];
|
|
185
183
|
case 6:
|
|
184
|
+
response = _d.sent();
|
|
185
|
+
return [2 /*return*/, response.flat()];
|
|
186
|
+
case 7:
|
|
186
187
|
(0, debugLog_1.debugLog)("Multicall failed, defaulting to single transactions...");
|
|
187
|
-
return [3 /*break*/,
|
|
188
|
-
case
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
188
|
+
return [3 /*break*/, 8];
|
|
189
|
+
case 8:
|
|
190
|
+
_b = util_1.runInPromisePool;
|
|
191
|
+
_c = {
|
|
192
|
+
items: contractCalls
|
|
193
|
+
};
|
|
194
|
+
return [4 /*yield*/, networkSupportsMulticall(chain)];
|
|
195
|
+
case 9: return [2 /*return*/, _b.apply(void 0, [(_c.concurrency = (_d.sent()) ? 2 : 10,
|
|
196
|
+
_c.processor = function (_a) {
|
|
197
|
+
var to = _a.to, data = _a.data;
|
|
198
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
199
|
+
var result, e_2;
|
|
200
|
+
return __generator(this, function (_b) {
|
|
201
|
+
switch (_b.label) {
|
|
202
|
+
case 0:
|
|
203
|
+
result = null;
|
|
204
|
+
_b.label = 1;
|
|
205
|
+
case 1:
|
|
206
|
+
_b.trys.push([1, 3, , 4]);
|
|
207
|
+
return [4 /*yield*/, (0, rpcCall_1.call)((0, general_1.getProvider)(chain), { to: to, data: data }, block, chain)];
|
|
208
|
+
case 2:
|
|
209
|
+
result = _b.sent();
|
|
210
|
+
return [3 /*break*/, 4];
|
|
211
|
+
case 3:
|
|
212
|
+
e_2 = _b.sent();
|
|
213
|
+
(0, debugLog_1.debugLog)(e_2);
|
|
214
|
+
return [3 /*break*/, 4];
|
|
215
|
+
case 4: return [2 /*return*/, result];
|
|
216
|
+
}
|
|
217
|
+
});
|
|
212
218
|
});
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
})];
|
|
219
|
+
},
|
|
220
|
+
_c)])];
|
|
216
221
|
}
|
|
217
222
|
});
|
|
218
223
|
});
|
|
219
224
|
}
|
|
220
225
|
function multicallAddressOrThrow(chain) {
|
|
221
226
|
return __awaiter(this, void 0, void 0, function () {
|
|
222
|
-
var network, address, msg;
|
|
227
|
+
var multicallEnv, network, address, msg;
|
|
223
228
|
return __generator(this, function (_a) {
|
|
224
229
|
switch (_a.label) {
|
|
225
|
-
case 0:
|
|
230
|
+
case 0:
|
|
231
|
+
multicallEnv = process.env["".concat(chain.toUpperCase(), "_RPC_MULTICALL")];
|
|
232
|
+
if (multicallEnv)
|
|
233
|
+
return [2 /*return*/, multicallEnv];
|
|
234
|
+
return [4 /*yield*/, (0, general_1.getProvider)(chain).getNetwork()];
|
|
226
235
|
case 1:
|
|
227
236
|
network = _a.sent();
|
|
228
237
|
address = multicallAddress(network === null || network === void 0 ? void 0 : network.chainId);
|
|
@@ -236,14 +245,34 @@ function multicallAddressOrThrow(chain) {
|
|
|
236
245
|
});
|
|
237
246
|
});
|
|
238
247
|
}
|
|
248
|
+
exports.multicallAddressOrThrow = multicallAddressOrThrow;
|
|
249
|
+
var networkMulticallCache = {};
|
|
239
250
|
function networkSupportsMulticall(chain) {
|
|
240
251
|
var _a;
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
252
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
253
|
+
var multicallEnv, network, address;
|
|
254
|
+
return __generator(this, function (_b) {
|
|
255
|
+
switch (_b.label) {
|
|
256
|
+
case 0:
|
|
257
|
+
multicallEnv = process.env["".concat(chain.toUpperCase(), "_RPC_MULTICALL")];
|
|
258
|
+
if (multicallEnv)
|
|
259
|
+
networkMulticallCache[chain] = true;
|
|
260
|
+
if (!!networkMulticallCache.hasOwnProperty(chain)) return [3 /*break*/, 2];
|
|
261
|
+
return [4 /*yield*/, ((_a = (0, general_1.getProvider)(chain)) === null || _a === void 0 ? void 0 : _a.getNetwork())];
|
|
262
|
+
case 1:
|
|
263
|
+
network = _b.sent();
|
|
264
|
+
address = multicallAddress(network === null || network === void 0 ? void 0 : network.chainId);
|
|
265
|
+
networkMulticallCache[chain] = address !== null;
|
|
266
|
+
_b.label = 2;
|
|
267
|
+
case 2: return [2 /*return*/, networkMulticallCache[chain]];
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
});
|
|
244
271
|
}
|
|
245
272
|
exports.networkSupportsMulticall = networkSupportsMulticall;
|
|
246
273
|
function multicallAddress(chainId) {
|
|
274
|
+
if (typeof chainId === "bigint")
|
|
275
|
+
chainId = Number(chainId);
|
|
247
276
|
switch (chainId) {
|
|
248
277
|
case 1:
|
|
249
278
|
case 10001:
|
|
@@ -428,6 +457,8 @@ function multicallAddress(chainId) {
|
|
|
428
457
|
return '0x952e846E505d4e4ddf579541A0d739f1681F2282';
|
|
429
458
|
case 34443: // mode
|
|
430
459
|
return '0xA1da7a7eB5A858da410dE8FBC5092c2079B58413';
|
|
460
|
+
case 42766: // zkfair
|
|
461
|
+
return '0x9eF6667974Fb12D07774221AAB1E90b2ec48896E';
|
|
431
462
|
default:
|
|
432
463
|
return null;
|
|
433
464
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Chain } from "../general";
|
|
2
|
-
import { BlockTag } from "@ethersproject/providers";
|
|
3
2
|
export default function makeMultiCall(functionABI: any, calls: {
|
|
4
3
|
contract: string;
|
|
5
4
|
params: any[];
|
|
6
|
-
}[], chain: Chain, block?:
|
|
7
|
-
export declare function isMulticallV3Supported(chain: Chain, block?:
|
|
8
|
-
export declare function getMulticallAddress(chain: Chain, block?:
|
|
5
|
+
}[], chain: Chain, block?: string | number): Promise<any>;
|
|
6
|
+
export declare function isMulticallV3Supported(chain: Chain, block?: string | number): boolean;
|
|
7
|
+
export declare function getMulticallAddress(chain: Chain, block?: string | number): string | null;
|
package/build/abi/multicall3.js
CHANGED
|
@@ -142,6 +142,11 @@ var DEPLOYMENT_BLOCK = {
|
|
|
142
142
|
azktn: 31317,
|
|
143
143
|
lightlink_phoenix: 51289975,
|
|
144
144
|
eon: 646592,
|
|
145
|
+
jfin: 13857465,
|
|
146
|
+
ethereumclassic: 18288646,
|
|
147
|
+
core: 6988931,
|
|
148
|
+
callisto: 13811517,
|
|
149
|
+
bittorrent: 31078552,
|
|
145
150
|
};
|
|
146
151
|
function makeMultiCall(functionABI, calls, chain, block) {
|
|
147
152
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -173,8 +178,8 @@ function makeMultiCall(functionABI, calls, chain, block) {
|
|
|
173
178
|
throw new Error('Missing target, abi:' + functionABI);
|
|
174
179
|
if (!isMulticallV3Supported(chain, block))
|
|
175
180
|
return [2 /*return*/, (0, multicall_1.default)(functionABI, calls, chain, block)];
|
|
176
|
-
contractInterface = new ethers_1.ethers.
|
|
177
|
-
fd =
|
|
181
|
+
contractInterface = new ethers_1.ethers.Interface([functionABI]);
|
|
182
|
+
fd = contractInterface.fragments[0];
|
|
178
183
|
contractCalls = calls.map(function (call) {
|
|
179
184
|
var data = contractInterface.encodeFunctionData(fd, call.params);
|
|
180
185
|
return {
|
|
@@ -197,12 +202,12 @@ function makeMultiCall(functionABI, calls, chain, block) {
|
|
|
197
202
|
// debugLog(chain, 'Multicall failed, retrying call...')
|
|
198
203
|
_a.sent();
|
|
199
204
|
return [3 /*break*/, 5];
|
|
200
|
-
case 5: return [2 /*return*/, returnValues.map(function (
|
|
205
|
+
case 5: return [2 /*return*/, returnValues.map(function (_a, index) {
|
|
206
|
+
var success = _a[0], values = _a[1];
|
|
201
207
|
var output = null;
|
|
202
|
-
var success = true;
|
|
203
208
|
var error = null;
|
|
204
209
|
try {
|
|
205
|
-
output = (0, convertResults_1.default)(contractInterface.decodeFunctionResult(fd, values
|
|
210
|
+
output = (0, convertResults_1.default)(contractInterface.decodeFunctionResult(fd, values), fd);
|
|
206
211
|
}
|
|
207
212
|
catch (e) {
|
|
208
213
|
error = e;
|
package/build/abi/rpcCall.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export declare function call(provider: BaseProvider, data: Deferrable<TransactionRequest>, block: BlockTag, chain?: string, options?: {
|
|
1
|
+
import { ethers } from "ethers";
|
|
2
|
+
export declare function call(provider: ethers.Provider, data: ethers.JsonRpcTransactionRequest, block?: string | number, chain?: string, options?: {
|
|
4
3
|
retry: boolean;
|
|
5
4
|
}): Promise<any>;
|
package/build/abi/rpcCall.js
CHANGED
package/build/abi/tron.js
CHANGED
|
@@ -51,7 +51,6 @@ var _a;
|
|
|
51
51
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
52
52
|
exports.getBalances = exports.getBalance = exports.multiCall = exports.call = void 0;
|
|
53
53
|
var node_fetch_1 = __importDefault(require("node-fetch"));
|
|
54
|
-
var utils_1 = require("ethers/lib/utils");
|
|
55
54
|
var ethers_1 = require("ethers");
|
|
56
55
|
var tron_format_address_1 = require("tron-format-address");
|
|
57
56
|
var convertResults_1 = __importDefault(require("./convertResults"));
|
|
@@ -73,11 +72,11 @@ function call(options) {
|
|
|
73
72
|
case 0:
|
|
74
73
|
target = options.target, abi = options.abi, params = options.params, isMulticall = options.isMulticall;
|
|
75
74
|
target = unhexifyTarget(target);
|
|
76
|
-
contractInterface = new ethers_1.ethers.
|
|
77
|
-
functionABI = ethers_1.ethers.
|
|
75
|
+
contractInterface = new ethers_1.ethers.Interface([abi]);
|
|
76
|
+
functionABI = ethers_1.ethers.FunctionFragment.from(abi);
|
|
78
77
|
inputTypes = ((_a = abi.inputs) !== null && _a !== void 0 ? _a : []).map(function (i) { return i.type; });
|
|
79
78
|
if (isMulticall)
|
|
80
|
-
inputTypes = [
|
|
79
|
+
inputTypes = [ethers_1.ethers.ParamType.from({
|
|
81
80
|
components: [
|
|
82
81
|
{ name: "target", type: "address" },
|
|
83
82
|
{ name: "callData", type: "bytes" },
|
|
@@ -94,7 +93,7 @@ function call(options) {
|
|
|
94
93
|
body = {
|
|
95
94
|
owner_address: ownerAddress,
|
|
96
95
|
contract_address: target,
|
|
97
|
-
function_selector:
|
|
96
|
+
function_selector: contractInterface.fragments[0].format(),
|
|
98
97
|
parameter: callData.slice(2),
|
|
99
98
|
visible: true,
|
|
100
99
|
};
|
|
@@ -113,7 +112,7 @@ function call(options) {
|
|
|
113
112
|
decodedResult[outputName] = v;
|
|
114
113
|
});
|
|
115
114
|
return [2 /*return*/, {
|
|
116
|
-
output: (0, convertResults_1.default)(decodedResult),
|
|
115
|
+
output: (0, convertResults_1.default)(decodedResult, functionABI),
|
|
117
116
|
}];
|
|
118
117
|
}
|
|
119
118
|
});
|
|
@@ -201,8 +200,8 @@ function executeCalls(functionABI, calls) {
|
|
|
201
200
|
return __generator(this, function (_b) {
|
|
202
201
|
switch (_b.label) {
|
|
203
202
|
case 0:
|
|
204
|
-
contractInterface = new ethers_1.ethers.
|
|
205
|
-
fd =
|
|
203
|
+
contractInterface = new ethers_1.ethers.Interface([functionABI]);
|
|
204
|
+
fd = contractInterface.fragments[0];
|
|
206
205
|
contractCalls = calls.map(function (call) {
|
|
207
206
|
var data = contractInterface.encodeFunctionData(fd, call.params);
|
|
208
207
|
return {
|
|
@@ -230,7 +229,7 @@ function executeCalls(functionABI, calls) {
|
|
|
230
229
|
if (outputName && outputName.length)
|
|
231
230
|
output[outputName] = v;
|
|
232
231
|
});
|
|
233
|
-
return (0, convertResults_1.default)(output);
|
|
232
|
+
return (0, convertResults_1.default)(output, fd);
|
|
234
233
|
})];
|
|
235
234
|
case 3:
|
|
236
235
|
e_1 = _b.sent();
|
package/build/erc20/index.d.ts
CHANGED
|
@@ -3,14 +3,14 @@ import { Chain } from "../general";
|
|
|
3
3
|
export declare function info(tokenAddress: Address, chain?: Chain): Promise<{
|
|
4
4
|
output: {
|
|
5
5
|
symbol: any;
|
|
6
|
-
decimals:
|
|
6
|
+
decimals: number;
|
|
7
7
|
};
|
|
8
8
|
}>;
|
|
9
9
|
export declare function symbol(tokenAddress: Address, chain?: Chain): Promise<{
|
|
10
10
|
output: any;
|
|
11
11
|
}>;
|
|
12
12
|
export declare function decimals(tokenAddress: Address, chain?: Chain): Promise<{
|
|
13
|
-
output:
|
|
13
|
+
output: number;
|
|
14
14
|
}>;
|
|
15
15
|
export declare function totalSupply(params: {
|
|
16
16
|
target: Address;
|