@defillama/sdk 5.0.198 → 5.0.204
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 +1 -0
- package/build/ChainApi.js +6 -2
- package/build/abi/abi2.js +52 -1
- package/build/abi/index.js +4 -0
- package/build/abi/multicall3.js +1 -0
- package/build/providers.json +1 -1
- package/build/types.d.ts +4 -2
- package/build/util/common.js +3 -0
- package/build/util/computeTVL.js +5 -0
- package/build/util/indexer.js +1 -0
- package/build/util/updateProviderList.js +48 -27
- package/package.json +1 -1
package/build/ChainApi.d.ts
CHANGED
|
@@ -111,6 +111,7 @@ export declare class ChainApi {
|
|
|
111
111
|
getBalancesV2(): Balances;
|
|
112
112
|
getTransactions(params: GetTransactionOptions): Promise<any>;
|
|
113
113
|
getTransactionReceipt(tx: string): Promise<import("ethers").TransactionReceipt | null>;
|
|
114
|
+
getStats(): DebugStats;
|
|
114
115
|
}
|
|
115
116
|
export default ChainApi;
|
|
116
117
|
export declare function getDebugStats(): Record<string, DebugStats>;
|
package/build/ChainApi.js
CHANGED
|
@@ -29,7 +29,7 @@ class ChainApi {
|
|
|
29
29
|
this.chainId = (_b = providers_json_1.default[this.chain]) === null || _b === void 0 ? void 0 : _b.chainId;
|
|
30
30
|
this.storedKey = params.storedKey;
|
|
31
31
|
this.api = this;
|
|
32
|
-
const uKey = `${params.protocol}:${this.storedKey}
|
|
32
|
+
const uKey = this.storedKey ? `${params.protocol}:${this.storedKey}` : (params.protocol ? `${params.protocol}` : `chain-${this.chain}`);
|
|
33
33
|
const stats = {
|
|
34
34
|
meta: {
|
|
35
35
|
chain: this.chain,
|
|
@@ -98,7 +98,8 @@ class ChainApi {
|
|
|
98
98
|
});
|
|
99
99
|
}
|
|
100
100
|
async getBlock() {
|
|
101
|
-
this.
|
|
101
|
+
if (!this.block)
|
|
102
|
+
this.addStat('getBlock');
|
|
102
103
|
if (!this.block)
|
|
103
104
|
this.block = await (0, blocks_1.getBlockNumber)(this.chain, this.timestamp);
|
|
104
105
|
return this.block;
|
|
@@ -277,6 +278,9 @@ class ChainApi {
|
|
|
277
278
|
this.addStat('getTransactionReceipt');
|
|
278
279
|
return this.provider.getTransactionReceipt(tx);
|
|
279
280
|
}
|
|
281
|
+
getStats() {
|
|
282
|
+
return this.stats;
|
|
283
|
+
}
|
|
280
284
|
}
|
|
281
285
|
exports.ChainApi = ChainApi;
|
|
282
286
|
exports.default = ChainApi;
|
package/build/abi/abi2.js
CHANGED
|
@@ -39,8 +39,10 @@ exports.fetchList = fetchList;
|
|
|
39
39
|
exports.bytecodeCall = bytecodeCall;
|
|
40
40
|
const abi1 = __importStar(require("./index"));
|
|
41
41
|
async function call(params) {
|
|
42
|
+
if (params.abis)
|
|
43
|
+
return callWithAlternateAbis();
|
|
42
44
|
try {
|
|
43
|
-
const response = await abi1.call(params);
|
|
45
|
+
const response = await abi1.call(params); // abi v1 doesnt have support for 'abis' param
|
|
44
46
|
if (params.field)
|
|
45
47
|
response.output = response.output[params.field];
|
|
46
48
|
if (params.withMetadata)
|
|
@@ -54,10 +56,25 @@ async function call(params) {
|
|
|
54
56
|
return { success: false, error: e };
|
|
55
57
|
return null;
|
|
56
58
|
}
|
|
59
|
+
async function callWithAlternateAbis() {
|
|
60
|
+
const { abis, ...restParams } = params;
|
|
61
|
+
if (!abis || abis.length === 0)
|
|
62
|
+
throw new Error('No alternate ABIs provided!');
|
|
63
|
+
for (let i = 0; i < abis.length - 1; i++) {
|
|
64
|
+
const res = await call({ ...restParams, abi: abis[i], permitFailure: true, withMetadata: true });
|
|
65
|
+
const response = params.withMetadata ? res : res.output;
|
|
66
|
+
if (res.success)
|
|
67
|
+
return response;
|
|
68
|
+
}
|
|
69
|
+
const lastAbi = abis[abis.length - 1];
|
|
70
|
+
return call({ ...restParams, abi: lastAbi, });
|
|
71
|
+
}
|
|
57
72
|
}
|
|
58
73
|
async function multiCall(params) {
|
|
59
74
|
if (params.excludeFailed)
|
|
60
75
|
params.permitFailure = true;
|
|
76
|
+
if (params.abis)
|
|
77
|
+
return multiCallWithAlternateAbis();
|
|
61
78
|
params.calls = params.calls.map(i => {
|
|
62
79
|
if (typeof i === 'object')
|
|
63
80
|
return i;
|
|
@@ -76,6 +93,40 @@ async function multiCall(params) {
|
|
|
76
93
|
if (params.withMetadata)
|
|
77
94
|
return output;
|
|
78
95
|
return output.map((i) => i.output);
|
|
96
|
+
async function multiCallWithAlternateAbis() {
|
|
97
|
+
const { abis, ...restParams } = params;
|
|
98
|
+
if (!abis || abis.length === 0)
|
|
99
|
+
throw new Error('No alternate ABIs provided!');
|
|
100
|
+
const outputs = [];
|
|
101
|
+
for (let i = 0; i < abis.length; i++) {
|
|
102
|
+
const res = await multiCall({ ...restParams, abi: abis[i], permitFailure: true, withMetadata: true, excludeFailed: false, });
|
|
103
|
+
outputs.push(res);
|
|
104
|
+
}
|
|
105
|
+
let finalOutput;
|
|
106
|
+
const permitFailure = params.permitFailure || params.excludeFailed;
|
|
107
|
+
outputs.forEach((res) => {
|
|
108
|
+
if (!finalOutput) { // First iteration
|
|
109
|
+
finalOutput = res;
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
res.forEach((callRes, idx) => {
|
|
113
|
+
var _a;
|
|
114
|
+
if ((_a = finalOutput[idx]) === null || _a === void 0 ? void 0 : _a.success)
|
|
115
|
+
return; // Already succeeded with an earlier ABI
|
|
116
|
+
finalOutput[idx] = callRes;
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
if (!permitFailure)
|
|
120
|
+
finalOutput.forEach((data) => {
|
|
121
|
+
if (!(data === null || data === void 0 ? void 0 : data.success))
|
|
122
|
+
throw new Error(`All ABI alternatives failed for multiCall! Last error: ${data === null || data === void 0 ? void 0 : data.error}`);
|
|
123
|
+
});
|
|
124
|
+
if (params.excludeFailed)
|
|
125
|
+
finalOutput = finalOutput.filter((i) => i === null || i === void 0 ? void 0 : i.success);
|
|
126
|
+
if (params.withMetadata)
|
|
127
|
+
return finalOutput;
|
|
128
|
+
return finalOutput.map((i) => i.output);
|
|
129
|
+
}
|
|
79
130
|
}
|
|
80
131
|
async function fetchList(params) {
|
|
81
132
|
// itemAbi2 is used when we need to make a second call to get the final result
|
package/build/abi/index.js
CHANGED
|
@@ -84,6 +84,8 @@ function isValidTarget(target, chain) {
|
|
|
84
84
|
}
|
|
85
85
|
async function call(params) {
|
|
86
86
|
var _a;
|
|
87
|
+
if (!params.abi)
|
|
88
|
+
throw new Error('Missing ABI parameter ("abis" is supported only in abi2/ChainApi)!');
|
|
87
89
|
if (params.chain === 'tron')
|
|
88
90
|
(0, common_1.fixTronCallParams)(params);
|
|
89
91
|
if (!isValidTarget(params.target, params.chain))
|
|
@@ -145,6 +147,8 @@ async function bytecodeCall(params) {
|
|
|
145
147
|
}
|
|
146
148
|
async function multiCall(params) {
|
|
147
149
|
var _a;
|
|
150
|
+
if (!params.abi)
|
|
151
|
+
throw new Error('Missing ABI parameter ("abis" is supported only in abi2/ChainApi)!');
|
|
148
152
|
fixBlockTag(params);
|
|
149
153
|
if (params.chain === 'tron')
|
|
150
154
|
(0, common_1.fixTronCallParams)(params);
|