-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathetherplex.js
37 lines (29 loc) · 1.1 KB
/
etherplex.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
const { ethers } = require('ethers');
const { batch, contract } = require('@pooltogether/etherplex');
const { abi, username, password, rpcEndpoint, walletAddress } = require('./constant.js');
const { convertToNumber, getTokens } = require('./utils');
const provider = new ethers.providers.JsonRpcProvider({
url: rpcEndpoint,
user: username,
password: password,
});
const generateContractFunctionList = tokens =>
tokens.map(({ address: tokenAddress, symbol }) =>
contract(symbol, abi, tokenAddress).balanceOf(walletAddress),
);
const main = async () => {
const { tokens } = await getTokens();
const start = new Date().getTime();
const args = generateContractFunctionList(tokens);
const tokenBalances = await batch.apply(null, [provider, ...args])
.then(balances => {
const output = {};
Object.entries(balances).map(([symbol, { balanceOf }], index) => {
const balance = convertToNumber(balanceOf[0]._hex, tokens[index].decimals);
output[tokens[index].name] = `${balance} ${symbol}`;
});
return output;
});
console.log(tokenBalances);
};
main();