-
Notifications
You must be signed in to change notification settings - Fork 0
/
multicall.js
44 lines (41 loc) · 1.22 KB
/
multicall.js
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
const { MultiCall } = require("@indexed-finance/multicall");
const { abi } = require("./AggregatorV3Interface.json");
const ETHUSDpriceFeedAddress = "0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419";
const ethers = require("ethers");
require("dotenv").config();
const NUM_ROUNDS = process.env.NUM_ROUNDS || 10;
async function main() {
let provider = new ethers.providers.JsonRpcProvider(
process.env.INFURA_ETHEREUM_HTTPS
);
const multi = new MultiCall(provider);
const inputs = [];
const priceFeed = new ethers.Contract(ETHUSDpriceFeedAddress, abi, provider);
latestRound = (await priceFeed.latestRoundData())[0];
for (
let round = latestRound.sub(NUM_ROUNDS);
round.lt(latestRound);
round = round.add(1)
) {
inputs.push({
target: ETHUSDpriceFeedAddress,
function: "getRoundData",
args: [round.toString()],
});
}
const before = Date.now();
const roundData = await multi.multiCall(abi, inputs);
const after = Date.now();
console.log(
`Multicall of ${NUM_ROUNDS} calls to chainlink ETHUSD price feed took ${
after - before
}s`
);
return roundData;
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});