Skip to content

Commit c495864

Browse files
committed
feat: call multicall v3 contract, add unit test for amoy, base, polygon chain
1 parent fb84bcc commit c495864

8 files changed

Lines changed: 1464 additions & 244 deletions

File tree

package-lock.json

Lines changed: 1166 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "ethers-multicall",
3-
"version": "0.2.3",
2+
"name": "@ixswap1/ethers-multicall",
3+
"version": "0.1.0",
44
"description": "Make multiple Ethereum network requests in a single HTTP query. ethcall for ethers v5.",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
@@ -20,6 +20,7 @@
2020
"@ts-tools/node": "^0.8.3",
2121
"@types/chai": "^4.1.7",
2222
"@types/mocha": "^5.2.5",
23+
"@types/node": "^20.14.10",
2324
"chai": "^4.2.0",
2425
"mocha": "^5.2.0",
2526
"tslint": "^5.12.0",

src/provider.ts

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,20 @@ export class Provider {
3333
}
3434

3535
const multicallAddresses = {
36-
1: '0xeefba1e63905ef1d7acba5a8513c70307c1ce441',
37-
3: '0xF24b01476a55d635118ca848fbc7Dab69d403be3',
38-
4: '0x42ad527de7d4e9d9d011ac45b31d8551f8fe9821',
39-
5: '0x77dca2c955b15e9de4dbbcf1246b4b85b651e50e',
40-
42: '0x2cc8688c5f75e365aaeeb4ea8d6a480405a48d2a',
41-
56: '0x1Ee38d535d541c55C9dae27B12edf090C608E6Fb',
42-
66: '0x94fEadE0D3D832E4A05d459eBeA9350c6cDd3bCa',
43-
97: '0x3A09ad1B8535F25b48e6Fa0CFd07dB6B017b31B2',
44-
100: '0xb5b692a88bdfc81ca69dcb1d924f59f0413a602a',
45-
128: '0x2C55D51804CF5b436BA5AF37bD7b8E5DB70EBf29',
46-
137: '0x11ce4B23bD875D7F5C6a31084f55fDe1e9A87507',
47-
250: '0x0118EF741097D0d3cc88e46233Da1e407d9ac139',
48-
1337: '0x77dca2c955b15e9de4dbbcf1246b4b85b651e50e',
49-
42161: '0x813715eF627B01f4931d8C6F8D2459F26E19137E',
50-
43114: '0x7f3aC7C283d7E6662D886F494f7bc6F1993cDacf',
51-
80001: '0x08411ADd0b5AA8ee47563b146743C13b3556c9Cc',
36+
1: '0xcA11bde05977b3631167028862bE2a173976CA11',
37+
5: '0xcA11bde05977b3631167028862bE2a173976CA11',
38+
56: '0xcA11bde05977b3631167028862bE2a173976CA11',
39+
97: '0xcA11bde05977b3631167028862bE2a173976CA11',
40+
100: '0xcA11bde05977b3631167028862bE2a173976CA11',
41+
128: '0xcA11bde05977b3631167028862bE2a173976CA11',
42+
137: '0xcA11bde05977b3631167028862bE2a173976CA11', // Polygon
43+
250: '0xcA11bde05977b3631167028862bE2a173976CA11',
44+
8453: '0xca11bde05977b3631167028862be2a173976ca11', // BASE
45+
42161: '0xcA11bde05977b3631167028862bE2a173976CA11',
46+
43114: '0xcA11bde05977b3631167028862bE2a173976CA11',
47+
80001: '0xcA11bde05977b3631167028862bE2a173976CA11',
48+
80002: '0xcA11bde05977b3631167028862bE2a173976CA11',
49+
84532: '0xcA11bde05977b3631167028862bE2a173976CA11', // BASE Sepolia
5250
};
5351

5452
export function setMulticallAddress(chainId: number, address: string) {

test/amoy.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { ethers } from 'ethers';
2+
import { assert } from 'chai';
3+
import { Contract, Provider } from '../src';
4+
5+
const rpcUrl = 'https://polygon-amoy.drpc.org'
6+
const provider = new ethers.providers.JsonRpcProvider(rpcUrl);
7+
const ethcallProvider = new Provider(provider, 80002);
8+
9+
describe('amoy network', () => {
10+
it('should retrieve totalSupply both of the tokens successfully', async () => {
11+
const abi = ['function totalSupply() public view returns (uint256)'];
12+
const addresses = [
13+
'0x0Fd9e8d3aF1aaee056EB9e802c3A762a667b1904',
14+
'0x6EEBe75caf9c579B3FBA9030760B84050283b50a'
15+
];
16+
17+
const linkContract = new Contract(addresses[0], abi);
18+
const usdcContract = new Contract(addresses[1], abi);
19+
20+
const calls = [linkContract.totalSupply(), usdcContract.totalSupply()];
21+
const [linkSupply, usdcSupply] = await ethcallProvider.all(calls);
22+
23+
assert.equal(linkSupply.toString(), '10001000000000000000000000');
24+
assert.equal(usdcSupply.toString(), '100000000000000000000000000');
25+
})
26+
})

test/base.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { ethers } from 'ethers';
2+
import { assert } from 'chai';
3+
import { Contract, Provider } from '../src';
4+
5+
const rpcUrl = 'https://base-pokt.nodies.app'
6+
const provider = new ethers.providers.JsonRpcProvider(rpcUrl);
7+
const ethcallProvider = new Provider(provider, 8453);
8+
9+
describe('base network', () => {
10+
it('should retrieve totalSupply both of the tokens successfully', async () => {
11+
const abi = ['function totalSupply() public view returns (uint256)'];
12+
const addresses = [
13+
'0xfA980cEd6895AC314E7dE34Ef1bFAE90a5AdD21b',
14+
'0x1C7a460413dD4e964f96D8dFC56E7223cE88CD85'
15+
];
16+
17+
const primeContract = new Contract(addresses[0], abi);
18+
const seamContract = new Contract(addresses[1], abi);
19+
20+
const calls = [primeContract.totalSupply(), seamContract.totalSupply()];
21+
const [primeSupply, seamSupply] = await ethcallProvider.all(calls);
22+
23+
assert.equal(primeSupply.toString(), '655283967592417997806328');
24+
assert.equal(seamSupply.toString(), '100000000000000000000000000');
25+
})
26+
})

test/index.test.ts

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,58 @@
1-
import {InfuraProvider} from '@ethersproject/providers';
1+
import { InfuraProvider } from '@ethersproject/providers';
22
import { assert } from 'chai';
33
import { Contract, Provider } from '../src';
44

55
const provider = new InfuraProvider('mainnet');
66
const ethcallProvider = new Provider(provider, 1);
77

8-
it('human readable abi', async () => {
9-
const abi = ['function totalSupply() public view returns (uint256)'];
10-
const addresses = [
11-
'0x0bc529c00C6401aEF6D220BE8C6Ea1667F6Ad93e',
12-
'0x1f9840a85d5af5bf1d1762f925bdaddc4201f984'
13-
];
8+
describe('ethereum network', () => {
9+
it('human readable abi', async () => {
10+
const abi = ['function totalSupply() public view returns (uint256)'];
11+
const addresses = [
12+
'0x0bc529c00C6401aEF6D220BE8C6Ea1667F6Ad93e',
13+
'0x1f9840a85d5af5bf1d1762f925bdaddc4201f984'
14+
];
1415

15-
const yfiContract = new Contract(addresses[0], abi);
16-
const uniContract = new Contract(addresses[1], abi);
16+
const yfiContract = new Contract(addresses[0], abi);
17+
const uniContract = new Contract(addresses[1], abi);
1718

18-
const calls = [yfiContract.totalSupply(), uniContract.totalSupply()];
19-
const [yfiSupply, uniSupply] = await ethcallProvider.all(calls);
19+
const calls = [yfiContract.totalSupply(), uniContract.totalSupply()];
20+
const [yfiSupply, uniSupply] = await ethcallProvider.all(calls);
2021

21-
assert.equal(yfiSupply.toString(), '36666000000000000000000');
22-
assert.equal(uniSupply.toString(), '1000000000000000000000000000');
23-
});
22+
assert.equal(yfiSupply.toString(), '36666000000000000000000');
23+
assert.equal(uniSupply.toString(), '1000000000000000000000000000');
24+
}).timeout(5_000);
2425

25-
it('json abi', async () => {
26-
const abi = [
27-
{
26+
it('json abi', async () => {
27+
const abi = [
28+
{
2829
constant: true,
2930
inputs: [],
3031
name: 'totalSupply',
3132
outputs: [
32-
{
33-
internalType: 'uint256',
34-
name: '',
35-
type: 'uint256'
36-
}
33+
{
34+
internalType: 'uint256',
35+
name: '',
36+
type: 'uint256'
37+
}
3738
],
3839
payable: false,
3940
stateMutability: 'view',
4041
type: 'function'
41-
}
42-
];
43-
const addresses = [
44-
'0x0bc529c00C6401aEF6D220BE8C6Ea1667F6Ad93e',
45-
'0x1f9840a85d5af5bf1d1762f925bdaddc4201f984'
46-
];
47-
48-
const yfiContract = new Contract(addresses[0], abi);
49-
const uniContract = new Contract(addresses[1], abi);
50-
51-
const calls = [yfiContract.totalSupply(), uniContract.totalSupply()];
52-
const [yfiSupply, uniSupply] = await ethcallProvider.all(calls);
53-
54-
assert.equal(yfiSupply.toString(), '36666000000000000000000');
55-
assert.equal(uniSupply.toString(), '1000000000000000000000000000');
56-
});
42+
}
43+
];
44+
const addresses = [
45+
'0x0bc529c00C6401aEF6D220BE8C6Ea1667F6Ad93e',
46+
'0x1f9840a85d5af5bf1d1762f925bdaddc4201f984'
47+
];
48+
49+
const yfiContract = new Contract(addresses[0], abi);
50+
const uniContract = new Contract(addresses[1], abi);
51+
52+
const calls = [yfiContract.totalSupply(), uniContract.totalSupply()];
53+
const [yfiSupply, uniSupply] = await ethcallProvider.all(calls);
54+
55+
assert.equal(yfiSupply.toString(), '36666000000000000000000');
56+
assert.equal(uniSupply.toString(), '1000000000000000000000000000');
57+
})
58+
})

test/polygon.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { ethers } from 'ethers';
2+
import { assert } from 'chai';
3+
import { Contract, Provider } from '../src';
4+
5+
const rpcUrl = 'https://polygon-pokt.nodies.app'
6+
const provider = new ethers.providers.JsonRpcProvider(rpcUrl);
7+
const ethcallProvider = new Provider(provider, 137);
8+
9+
describe('polygon network', () => {
10+
it('should retrieve totalSupply both of the tokens successfully', async () => {
11+
const abi = ['function totalSupply() public view returns (uint256)'];
12+
const addresses = [
13+
'0x0000000000000000000000000000000000001010',
14+
'0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619'
15+
];
16+
17+
const maticContract = new Contract(addresses[0], abi);
18+
const wethContract = new Contract(addresses[1], abi);
19+
20+
const calls = [maticContract.totalSupply(), wethContract.totalSupply()];
21+
const [maticSupply, wethSupply] = await ethcallProvider.all(calls);
22+
23+
assert.equal(maticSupply.toString(), '10000000000000000000000000000');
24+
assert.equal(wethSupply.toString(), '151625134652898175725399');
25+
})
26+
})

0 commit comments

Comments
 (0)