liquality / chainify

Blockchain abstraction layer
https://liquality.io
MIT License
220 stars 69 forks source link

feat: add evm multicall provider #496

Closed kraikov closed 2 years ago

kraikov commented 2 years ago

Description

Add multicall support using this contract

Currently the following networks are supported:

  1: '0xeefba1e63905ef1d7acba5a8513c70307c1ce441',
  3: '0xF24b01476a55d635118ca848fbc7Dab69d403be3',
  4: '0x42ad527de7d4e9d9d011ac45b31d8551f8fe9821',
  5: '0x77dca2c955b15e9de4dbbcf1246b4b85b651e50e',
  42: '0x2cc8688c5f75e365aaeeb4ea8d6a480405a48d2a',
  56: '0x1Ee38d535d541c55C9dae27B12edf090C608E6Fb',
  100: '0xb5b692a88bdfc81ca69dcb1d924f59f0413a602a',
  137: '0xc4f1501f337079077842343Ce02665D8960150B0',
  1337: '0x77dca2c955b15e9de4dbbcf1246b4b85b651e50e',
  43114: '0xdDCbf776dF3dE60163066A5ddDF2277cB445E0F3',
  80001: '0x5a0439824F4c0275faa88F2a7C5037F9833E29f1'

Usage:

const provider = new EvmMulticallProvider(
      new StaticJsonRpcProvider('rpc_url', 'ropsten'),
      3 /* ropsten chain id */
    )

const ERC20BalanceABI = [
  {
    inputs: [{ internalType: 'address', name: '', type: 'address' }],
    name: 'balanceOf',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function'
  }
]

const result = await provider.multicall([
{
    target: '0xc8b23857d66ae204d195968714840a75d28dc217',
    abi: ERC20BalanceABI,
    name: 'balanceOf',
    params: ['0xF180525Ef03D5e5bFd09156823e0eA49da561c5F']
},
{
    target: '0x1371597fc11aedbd2446f5390fa1dbf22491752a',
    abi: ERC20BalanceABI,
    name: 'balanceOf',
    params: ['0xF180525Ef03D5e5bFd09156823e0eA49da561c5F']
}
])

console.log(result)