-
Notifications
You must be signed in to change notification settings - Fork 3
/
multicallDynamicAbi.ts
159 lines (149 loc) · 4.69 KB
/
multicallDynamicAbi.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// import { AbiCall, Call, multicallDynamicAbi , multicallDynamicAbiIndexedCalls } from '@defifofum/multicall';
import { AbiCall, Call, multicallDynamicAbi, multicallDynamicAbiIndexedCalls } from '../dist/index'
import { getDefaultProvider, utils } from 'ethers'
const RPC_PROVIDER = 'https://bsc-dataseed.binance.org/';
const ABIs = {
getStakeTokenFeeBalance: [utils.Fragment.from(
{
"inputs": [],
"name": "getStakeTokenFeeBalance",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
}
)],
totalSupply: [utils.Fragment.from(
{
"inputs": [],
"name": "totalSupply",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
}
)],
}
const calls: Call[] = [
{
functionName: 'getStakeTokenFeeBalance',
address: '0x5798271B134e27c4dE28CB33aa8D18e5753e83fC',
params: []
},
{
functionName: 'totalSupply',
address: '0x603c7f932ED1fc6575303D8Fb018fDCBb0f39a95',
params: []
},
{
functionName: 'getStakeTokenFeeBalance',
address: '0x6FbB19A87f1E86f027A084C8bfc3528120Cf8249',
params: []
},
{
functionName: 'totalSupply',
address: '0xdDb3Bd8645775F59496c821E4F55A7eA6A6dc299',
params: []
},
{
functionName: 'getStakeTokenFeeBalance',
address: '0x7124d635a4bb82319acfd57ce9da18137a7a6f22',
params: []
},
{
functionName: 'totalSupply',
address: '0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56',
params: []
},
{
functionName: 'getStakeTokenFeeBalance',
address: '0xEedd7475Eb5D05D591bE0927B178AcBBdC5ee1c1',
params: []
},
{
functionName: 'totalSupply',
address: '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c',
params: []
},
{
functionName: 'getStakeTokenFeeBalance',
address: '0x48ee3f7748fac3e8e4858bd0b09483c4339d3d7e',
params: []
},
{
functionName: 'totalSupply',
address: '0x2170Ed0880ac9A755fd29B2688956BD959F933F8',
params: []
},
]
async function runExampleMulticallDynamicAbi() {
let expandedCalls: Call[] = [];
for (let index = 0; index < 500; index++) {
expandedCalls = [...expandedCalls, ...calls];
}
// setup multicall
// AbiCall[]
const callDataArray: any[] = [];
for (const call of expandedCalls) {
callDataArray.push({
address: call.address,
functionName: call.functionName,
params: call.params,
abi: ABIs[call.functionName]
});
}
let data: {
address: string;
bscscanUrl: string;
functionName: string;
returnValue: string;
tx: string;
}[] = [];
// send multicall data
if (callDataArray.length) {
// Can pass in the direct RPC_PROVIDER url as well
const provider = getDefaultProvider(RPC_PROVIDER);
// multicallDynamicAbi(rpcUrl: string, calls: AbiCall[], maxCallsPerTx = 1000)
// const returnedData = await multicallDynamicAbi(provider, callDataArray);
const returnedData = (await multicallDynamicAbiIndexedCalls(provider, [callDataArray]))[0];
// Pull addresses out of return data
data = returnedData.map((dataArray, index) => {
return {
address: expandedCalls[index].address,
bscscanUrl: `https://bscscan.com/address/${expandedCalls[index].address}#readContract`,
functionName: expandedCalls[index].functionName,
// Values are returned as an array for each return value. We are pulling out the singular balance variable here
returnValue: dataArray[0].toString(),
tx: ''
}
});
}
console.dir(data);
console.log(`Total calls: ${expandedCalls.length}.`);
}
async function timeScript(script: any) {
const start = new Date();
await script();
const scriptTime = new Date() as any - Number(start);
console.log(`Script took ${scriptTime} ms to run.`)
}
(async function () {
try {
await timeScript(runExampleMulticallDynamicAbi);
process.exit(0);
} catch (e) {
console.error(`Error running example script:`)
console.dir(e);
process.exit(1);
}
}());