Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: call multicall v3 contract, add unit test for amoy chain #61

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,166 changes: 1,166 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ethers-multicall",
"version": "0.2.3",
"name": "@ixswap1/ethers-multicall",
"version": "0.1.0",
"description": "Make multiple Ethereum network requests in a single HTTP query. ethcall for ethers v5.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand All @@ -20,6 +20,7 @@
"@ts-tools/node": "^0.8.3",
"@types/chai": "^4.1.7",
"@types/mocha": "^5.2.5",
"@types/node": "^20.14.10",
"chai": "^4.2.0",
"mocha": "^5.2.0",
"tslint": "^5.12.0",
Expand Down
30 changes: 14 additions & 16 deletions src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,20 @@ export class Provider {
}

const multicallAddresses = {
1: '0xeefba1e63905ef1d7acba5a8513c70307c1ce441',
3: '0xF24b01476a55d635118ca848fbc7Dab69d403be3',
4: '0x42ad527de7d4e9d9d011ac45b31d8551f8fe9821',
5: '0x77dca2c955b15e9de4dbbcf1246b4b85b651e50e',
42: '0x2cc8688c5f75e365aaeeb4ea8d6a480405a48d2a',
56: '0x1Ee38d535d541c55C9dae27B12edf090C608E6Fb',
66: '0x94fEadE0D3D832E4A05d459eBeA9350c6cDd3bCa',
97: '0x3A09ad1B8535F25b48e6Fa0CFd07dB6B017b31B2',
100: '0xb5b692a88bdfc81ca69dcb1d924f59f0413a602a',
128: '0x2C55D51804CF5b436BA5AF37bD7b8E5DB70EBf29',
137: '0x11ce4B23bD875D7F5C6a31084f55fDe1e9A87507',
250: '0x0118EF741097D0d3cc88e46233Da1e407d9ac139',
1337: '0x77dca2c955b15e9de4dbbcf1246b4b85b651e50e',
42161: '0x813715eF627B01f4931d8C6F8D2459F26E19137E',
43114: '0x7f3aC7C283d7E6662D886F494f7bc6F1993cDacf',
80001: '0x08411ADd0b5AA8ee47563b146743C13b3556c9Cc',
1: '0xcA11bde05977b3631167028862bE2a173976CA11',
5: '0xcA11bde05977b3631167028862bE2a173976CA11',
56: '0xcA11bde05977b3631167028862bE2a173976CA11',
97: '0xcA11bde05977b3631167028862bE2a173976CA11',
100: '0xcA11bde05977b3631167028862bE2a173976CA11',
128: '0xcA11bde05977b3631167028862bE2a173976CA11',
137: '0xcA11bde05977b3631167028862bE2a173976CA11', // Polygon
250: '0xcA11bde05977b3631167028862bE2a173976CA11',
8453: '0xca11bde05977b3631167028862be2a173976ca11', // BASE
42161: '0xcA11bde05977b3631167028862bE2a173976CA11',
43114: '0xcA11bde05977b3631167028862bE2a173976CA11',
80001: '0xcA11bde05977b3631167028862bE2a173976CA11',
80002: '0xcA11bde05977b3631167028862bE2a173976CA11',
84532: '0xcA11bde05977b3631167028862bE2a173976CA11', // BASE Sepolia
};

export function setMulticallAddress(chainId: number, address: string) {
Expand Down
26 changes: 26 additions & 0 deletions test/amoy.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { ethers } from 'ethers';
import { assert } from 'chai';
import { Contract, Provider } from '../src';

const rpcUrl = 'https://polygon-amoy.drpc.org'
const provider = new ethers.providers.JsonRpcProvider(rpcUrl);
const ethcallProvider = new Provider(provider, 80002);

describe('amoy network', () => {
it('should retrieve totalSupply both of the tokens successfully', async () => {
const abi = ['function totalSupply() public view returns (uint256)'];
const addresses = [
'0x0Fd9e8d3aF1aaee056EB9e802c3A762a667b1904',
'0x6EEBe75caf9c579B3FBA9030760B84050283b50a'
];

const linkContract = new Contract(addresses[0], abi);
const usdcContract = new Contract(addresses[1], abi);

const calls = [linkContract.totalSupply(), usdcContract.totalSupply()];
const [linkSupply, usdcSupply] = await ethcallProvider.all(calls);

assert.equal(linkSupply.toString(), '10001000000000000000000000');
assert.equal(usdcSupply.toString(), '100000000000000000000000000');
})
})
46 changes: 46 additions & 0 deletions test/base.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { assert } from 'chai';
import { ethers } from 'ethers';
import { Contract, Provider } from '../src';

const rpcUrl = 'https://base-pokt.nodies.app';
const provider = new ethers.providers.JsonRpcProvider(rpcUrl);
const ethcallProvider = new Provider(provider, 8453);

describe('base network', () => {
const addresses = [
'0xfA980cEd6895AC314E7dE34Ef1bFAE90a5AdD21b',
'0x1C7a460413dD4e964f96D8dFC56E7223cE88CD85'
];

it('should retrieve totalSupply both of the tokens successfully', async () => {
const abi = ['function totalSupply() public view returns (uint256)'];
const seamContract = new Contract(addresses[1], abi);

const calls = [seamContract.totalSupply()];
const [seamSupply] = await ethcallProvider.all(calls);

assert.equal(seamSupply.toString(), '100000000000000000000000000');
});

it('should returns symbol and decimals', async () => {
const abi = [
'function symbol() public view returns (string)',
'function decimals() public view returns (uint8)',
];
const primeContract = new Contract(addresses[0], abi);
const seamContract = new Contract(addresses[1], abi);

const calls = [primeContract.symbol(), seamContract.symbol(), primeContract.decimals(), seamContract.decimals()];
const [
primeSymbol,
seamSymbol,
primeDecimals,
seamDecimals
] = await ethcallProvider.all(calls);

assert.equal(primeSymbol, 'PRIME');
assert.equal(seamSymbol, 'SEAM');
assert.equal(primeDecimals.toString(), '18');
assert.equal(seamDecimals.toString(), '18');
});
});
78 changes: 40 additions & 38 deletions test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,56 +1,58 @@
import {InfuraProvider} from '@ethersproject/providers';
import { InfuraProvider } from '@ethersproject/providers';
import { assert } from 'chai';
import { Contract, Provider } from '../src';

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

it('human readable abi', async () => {
const abi = ['function totalSupply() public view returns (uint256)'];
const addresses = [
'0x0bc529c00C6401aEF6D220BE8C6Ea1667F6Ad93e',
'0x1f9840a85d5af5bf1d1762f925bdaddc4201f984'
];
describe('ethereum network', () => {
it('human readable abi', async () => {
const abi = ['function totalSupply() public view returns (uint256)'];
const addresses = [
'0x0bc529c00C6401aEF6D220BE8C6Ea1667F6Ad93e',
'0x1f9840a85d5af5bf1d1762f925bdaddc4201f984'
];

const yfiContract = new Contract(addresses[0], abi);
const uniContract = new Contract(addresses[1], abi);
const yfiContract = new Contract(addresses[0], abi);
const uniContract = new Contract(addresses[1], abi);

const calls = [yfiContract.totalSupply(), uniContract.totalSupply()];
const [yfiSupply, uniSupply] = await ethcallProvider.all(calls);
const calls = [yfiContract.totalSupply(), uniContract.totalSupply()];
const [yfiSupply, uniSupply] = await ethcallProvider.all(calls);

assert.equal(yfiSupply.toString(), '36666000000000000000000');
assert.equal(uniSupply.toString(), '1000000000000000000000000000');
});
assert.equal(yfiSupply.toString(), '36666000000000000000000');
assert.equal(uniSupply.toString(), '1000000000000000000000000000');
}).timeout(5_000);

it('json abi', async () => {
const abi = [
{
it('json abi', async () => {
const abi = [
{
constant: true,
inputs: [],
name: 'totalSupply',
outputs: [
{
internalType: 'uint256',
name: '',
type: 'uint256'
}
{
internalType: 'uint256',
name: '',
type: 'uint256'
}
],
payable: false,
stateMutability: 'view',
type: 'function'
}
];
const addresses = [
'0x0bc529c00C6401aEF6D220BE8C6Ea1667F6Ad93e',
'0x1f9840a85d5af5bf1d1762f925bdaddc4201f984'
];

const yfiContract = new Contract(addresses[0], abi);
const uniContract = new Contract(addresses[1], abi);

const calls = [yfiContract.totalSupply(), uniContract.totalSupply()];
const [yfiSupply, uniSupply] = await ethcallProvider.all(calls);

assert.equal(yfiSupply.toString(), '36666000000000000000000');
assert.equal(uniSupply.toString(), '1000000000000000000000000000');
});
}
];
const addresses = [
'0x0bc529c00C6401aEF6D220BE8C6Ea1667F6Ad93e',
'0x1f9840a85d5af5bf1d1762f925bdaddc4201f984'
];

const yfiContract = new Contract(addresses[0], abi);
const uniContract = new Contract(addresses[1], abi);

const calls = [yfiContract.totalSupply(), uniContract.totalSupply()];
const [yfiSupply, uniSupply] = await ethcallProvider.all(calls);

assert.equal(yfiSupply.toString(), '36666000000000000000000');
assert.equal(uniSupply.toString(), '1000000000000000000000000000');
})
})
47 changes: 47 additions & 0 deletions test/polygon.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { assert } from 'chai';
import { ethers } from 'ethers';
import { Contract, Provider } from '../src';

const rpcUrl = 'https://polygon-pokt.nodies.app';
const provider = new ethers.providers.JsonRpcProvider(rpcUrl);
const ethcallProvider = new Provider(provider, 137);

describe('polygon network', () => {
const addresses = [
'0x0000000000000000000000000000000000001010',
'0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619'
];

it('should retrieve totalSupply both of the tokens successfully', async () => {
const abi = ['function totalSupply() public view returns (uint256)'];

const maticContract = new Contract(addresses[0], abi);

const calls = [maticContract.totalSupply()];
const [maticSupply] = await ethcallProvider.all(calls);

assert.equal(maticSupply.toString(), '10000000000000000000000000000');
});

it('should returns symbol and decimals', async () => {
const abi = [
'function symbol() public view returns (string)',
'function decimals() public view returns (uint8)',
];
const maticContract = new Contract(addresses[0], abi);
const wethContract = new Contract(addresses[1], abi);

const calls = [maticContract.symbol(), wethContract.symbol(), maticContract.decimals(), wethContract.decimals()];
const [
maticSymbol,
wethSymbol,
maticDecimals,
wethDecimals
] = await ethcallProvider.all(calls);

assert.equal(maticSymbol, 'MATIC');
assert.equal(wethSymbol, 'WETH');
assert.equal(maticDecimals.toString(), '18');
assert.equal(wethDecimals.toString(), '18');
});
});
Loading