@defillama/sdk 5.0.73 → 5.0.76
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 +11 -9
- package/build/ChainApi.js +11 -2
- package/build/abi/abi2.d.ts +1 -1
- package/build/abi/abi2.js +92 -18
- package/build/abi/multicall3.js +1 -0
- package/build/providers.json +1 -1
- package/build/types.d.ts +12 -1
- package/build/util/updateProviderList.js +2 -0
- package/package.json +1 -1
package/build/ChainApi.d.ts
CHANGED
|
@@ -3,6 +3,14 @@ import Balances from "./Balances";
|
|
|
3
3
|
import { Chain } from "./general";
|
|
4
4
|
import { Provider } from "ethers";
|
|
5
5
|
import { GetLogsOptions } from "./util/logs";
|
|
6
|
+
type Erc4626SumOptions = {
|
|
7
|
+
calls: string[];
|
|
8
|
+
tokenAbi?: string;
|
|
9
|
+
balanceAbi?: string;
|
|
10
|
+
balanceCalls?: any[];
|
|
11
|
+
permitFailure?: boolean;
|
|
12
|
+
isOG4626?: boolean;
|
|
13
|
+
};
|
|
6
14
|
export declare class ChainApi {
|
|
7
15
|
block?: Block;
|
|
8
16
|
chain: Chain | string;
|
|
@@ -21,7 +29,7 @@ export declare class ChainApi {
|
|
|
21
29
|
call(params: CallOptions): Promise<any>;
|
|
22
30
|
batchCall(params: CallOptions[]): Promise<any[]>;
|
|
23
31
|
multiCall(params: MulticallOptions): Promise<any[]>;
|
|
24
|
-
fetchList(params: FetchListOptions): Promise<any
|
|
32
|
+
fetchList(params: FetchListOptions): Promise<any>;
|
|
25
33
|
bytecodeCall(params: ByteCodeCallOptions): Promise<any>;
|
|
26
34
|
getBlock(): Promise<number>;
|
|
27
35
|
log(...args: any): void;
|
|
@@ -44,14 +52,8 @@ export declare class ChainApi {
|
|
|
44
52
|
removeTokenBalance(token: string): void;
|
|
45
53
|
deleteToken(token: string): void;
|
|
46
54
|
deleteTokens(tokens: string[]): void;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
tokenAbi?: string;
|
|
50
|
-
balanceAbi?: string;
|
|
51
|
-
balanceCalls?: any[];
|
|
52
|
-
permitFailure?: boolean;
|
|
53
|
-
isOG4626?: boolean;
|
|
54
|
-
}): Promise<BalancesV1>;
|
|
55
|
+
erc4626Sum2(options: Erc4626SumOptions): Promise<BalancesV1>;
|
|
56
|
+
erc4626Sum({ calls, tokenAbi, balanceAbi, balanceCalls, permitFailure, isOG4626 }: Erc4626SumOptions): Promise<BalancesV1>;
|
|
55
57
|
sumTokens({ token, tokens, owners, owner, tokensAndOwners, tokensAndOwners2, blacklistedTokens, blacklistedOwners, ownerTokens, }: {
|
|
56
58
|
token?: string;
|
|
57
59
|
tokens?: string[];
|
package/build/ChainApi.js
CHANGED
|
@@ -106,11 +106,20 @@ class ChainApi {
|
|
|
106
106
|
deleteTokens(tokens) {
|
|
107
107
|
tokens.forEach(i => this.deleteToken(i));
|
|
108
108
|
}
|
|
109
|
-
async
|
|
110
|
-
if (isOG4626)
|
|
109
|
+
async erc4626Sum2(options) {
|
|
110
|
+
if (options.isOG4626 !== false)
|
|
111
|
+
options.isOG4626 = true;
|
|
112
|
+
return this.erc4626Sum(options);
|
|
113
|
+
}
|
|
114
|
+
async erc4626Sum({ calls, tokenAbi, balanceAbi, balanceCalls, permitFailure = false, isOG4626 = false }) {
|
|
115
|
+
if (isOG4626 && !tokenAbi && !balanceAbi) {
|
|
111
116
|
tokenAbi = 'asset';
|
|
112
117
|
balanceAbi = 'totalAssets';
|
|
113
118
|
}
|
|
119
|
+
if (!tokenAbi)
|
|
120
|
+
tokenAbi = 'address:token';
|
|
121
|
+
if (!balanceAbi)
|
|
122
|
+
balanceAbi = 'uint256:balance';
|
|
114
123
|
if (typeof tokenAbi === 'string' && (!tokenAbi.includes(':') && !tokenAbi.includes('(')))
|
|
115
124
|
tokenAbi = `address:${tokenAbi}`;
|
|
116
125
|
if (typeof balanceAbi === 'string' && (!balanceAbi.includes(':') && !balanceAbi.includes('(')))
|
package/build/abi/abi2.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CallOptions, MulticallOptions, FetchListOptions, ByteCodeCallOptions } from "../types";
|
|
2
2
|
export declare function call(params: CallOptions): Promise<any>;
|
|
3
3
|
export declare function multiCall(params: MulticallOptions): Promise<any[]>;
|
|
4
|
-
export declare function fetchList(params: FetchListOptions): Promise<any
|
|
4
|
+
export declare function fetchList(params: FetchListOptions): Promise<any>;
|
|
5
5
|
export declare function bytecodeCall(params: ByteCodeCallOptions): Promise<any>;
|
package/build/abi/abi2.js
CHANGED
|
@@ -27,13 +27,26 @@ exports.bytecodeCall = exports.fetchList = exports.multiCall = exports.call = vo
|
|
|
27
27
|
const abi1 = __importStar(require("./index"));
|
|
28
28
|
const debugLog_1 = require("../util/debugLog");
|
|
29
29
|
async function call(params) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
try {
|
|
31
|
+
const response = await abi1.call(params);
|
|
32
|
+
if (params.field)
|
|
33
|
+
response.output = response.output[params.field];
|
|
34
|
+
if (params.withMetadata)
|
|
35
|
+
return response;
|
|
36
|
+
return response.output;
|
|
37
|
+
}
|
|
38
|
+
catch (e) {
|
|
39
|
+
if (!params.permitFailure)
|
|
40
|
+
throw e;
|
|
41
|
+
if (params.withMetadata)
|
|
42
|
+
return { success: false, error: e };
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
34
45
|
}
|
|
35
46
|
exports.call = call;
|
|
36
47
|
async function multiCall(params) {
|
|
48
|
+
if (params.excludeFailed)
|
|
49
|
+
params.permitFailure = true;
|
|
37
50
|
params.calls = params.calls.map(i => {
|
|
38
51
|
if (typeof i === 'object')
|
|
39
52
|
return i;
|
|
@@ -44,33 +57,94 @@ async function multiCall(params) {
|
|
|
44
57
|
}
|
|
45
58
|
return { params: i };
|
|
46
59
|
});
|
|
47
|
-
|
|
60
|
+
let { output } = await abi1.multiCall(params);
|
|
61
|
+
if (params.excludeFailed)
|
|
62
|
+
output = output.filter((i) => i.success);
|
|
63
|
+
if (params.field)
|
|
64
|
+
output = output.forEach((i) => i.output = i.output[params.field]);
|
|
48
65
|
if (params.withMetadata)
|
|
49
66
|
return output;
|
|
50
67
|
return output.map((i) => i.output);
|
|
51
68
|
}
|
|
52
69
|
exports.multiCall = multiCall;
|
|
53
70
|
async function fetchList(params) {
|
|
54
|
-
|
|
71
|
+
// itemAbi2 is used when we need to make a second call to get the final result
|
|
72
|
+
let { startFrom = 0, lengthAbi, itemAbi, withMetadata, startFromOne = false, itemCount, target, targets, calls: _targets, chain, block, permitFailure, groupedByInput, excludeFailed, itemAbi2, field, field2, } = params;
|
|
73
|
+
if (!targets)
|
|
74
|
+
targets = _targets;
|
|
75
|
+
const _groupedByInputOrignal = groupedByInput;
|
|
76
|
+
if (targets && itemAbi2)
|
|
77
|
+
groupedByInput = true;
|
|
78
|
+
permitFailure = permitFailure || excludeFailed;
|
|
79
|
+
if (excludeFailed && groupedByInput)
|
|
80
|
+
throw new Error('excludeFailed and groupedByInput cannot be used together!');
|
|
81
|
+
if (withMetadata && groupedByInput)
|
|
82
|
+
throw new Error('withMetadata and groupedByInput cannot be used together!');
|
|
55
83
|
if (typeof lengthAbi === 'string' && (!lengthAbi.includes(':') && !lengthAbi.includes('(')))
|
|
56
84
|
lengthAbi = `uint256:${lengthAbi}`;
|
|
57
85
|
if (typeof itemAbi === 'string' && (!itemAbi.includes(':') && !itemAbi.includes('(')))
|
|
58
86
|
itemAbi = `function ${itemAbi}(uint256) view returns (address)`;
|
|
59
|
-
let itemLength;
|
|
87
|
+
let itemLength, itemLengths;
|
|
88
|
+
const calls = [];
|
|
89
|
+
if (!target && !targets)
|
|
90
|
+
throw new Error('Need to provide either target or targets parameter!');
|
|
91
|
+
if (target) {
|
|
92
|
+
if (itemCount)
|
|
93
|
+
itemLength = itemCount;
|
|
94
|
+
else
|
|
95
|
+
itemLength = await call({ chain, block, target, abi: lengthAbi, });
|
|
96
|
+
(0, debugLog_1.debugLog)('length: ', itemLength);
|
|
97
|
+
if (startFromOne) {
|
|
98
|
+
itemLength++;
|
|
99
|
+
if (startFrom === 0)
|
|
100
|
+
startFrom = 1;
|
|
101
|
+
}
|
|
102
|
+
for (let i = startFrom; i < itemLength; i++)
|
|
103
|
+
calls.push({ target, params: [i] });
|
|
104
|
+
const response = await multiCall({ chain, block, permitFailure, abi: itemAbi, calls, withMetadata, excludeFailed, field, });
|
|
105
|
+
if (!itemAbi2)
|
|
106
|
+
return response;
|
|
107
|
+
return multiCall({ chain, block, target, permitFailure, abi: itemAbi2, calls: response, withMetadata, excludeFailed, field: field2, });
|
|
108
|
+
}
|
|
60
109
|
if (itemCount)
|
|
61
|
-
|
|
110
|
+
itemLengths = targets.map(() => itemCount);
|
|
62
111
|
else
|
|
63
|
-
|
|
64
|
-
(0, debugLog_1.debugLog)('
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
112
|
+
itemLengths = await multiCall({ chain, block, calls: targets, abi: lengthAbi, });
|
|
113
|
+
(0, debugLog_1.debugLog)('itemLengths: ', itemLengths);
|
|
114
|
+
let groupedByRes = itemLengths.map(() => []);
|
|
115
|
+
const indexToTargetMapping = {};
|
|
116
|
+
let k = 0;
|
|
117
|
+
for (let i = 0; i < itemLengths.length; i++) {
|
|
118
|
+
let itemLength = itemLengths[i];
|
|
119
|
+
if (startFromOne) {
|
|
120
|
+
itemLength++;
|
|
121
|
+
if (startFrom === 0)
|
|
122
|
+
startFrom = 1;
|
|
123
|
+
}
|
|
124
|
+
for (let j = startFrom; j < itemLength; j++) {
|
|
125
|
+
calls.push({ target: targets[i], params: [j] });
|
|
126
|
+
indexToTargetMapping[k] = i;
|
|
127
|
+
k++;
|
|
128
|
+
}
|
|
69
129
|
}
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
130
|
+
const res = await multiCall({ chain, block, permitFailure, abi: itemAbi, calls, withMetadata, excludeFailed, field, });
|
|
131
|
+
if (!groupedByInput)
|
|
132
|
+
return res;
|
|
133
|
+
res.forEach((i, idx) => groupedByRes[indexToTargetMapping[idx]].push(i));
|
|
134
|
+
if (!itemAbi2)
|
|
135
|
+
return groupedByRes;
|
|
136
|
+
const calls2 = [];
|
|
137
|
+
for (let i = 0; i < targets.length; i++) {
|
|
138
|
+
for (let j = 0; j < groupedByRes[i].length; j++) {
|
|
139
|
+
calls2.push({ target: targets[i], params: groupedByRes[i][j] });
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
const res2 = await multiCall({ chain, block, permitFailure, abi: itemAbi2, calls: calls2, withMetadata, excludeFailed, field: field2, });
|
|
143
|
+
if (!_groupedByInputOrignal)
|
|
144
|
+
return res2;
|
|
145
|
+
groupedByRes = itemLengths.map(() => []);
|
|
146
|
+
res2.forEach((i, idx) => groupedByRes[indexToTargetMapping[idx]].push(i));
|
|
147
|
+
return groupedByRes;
|
|
74
148
|
}
|
|
75
149
|
exports.fetchList = fetchList;
|
|
76
150
|
async function bytecodeCall(params) {
|