Spock Analytics
  • GET STARTED
    • 📊Spock Analytics
    • ❓Why Spock Analytics
    • 💡Use Cases
    • ⚙️Onboarding
    • 🖖Learn about Spock
      • View
      • Understand
  • CONTRACT CONFIGURATION
    • Contract Form
  • SDK CONFIGURATION
    • SDK
    • Full API Reference
    • Supported Wallets
    • NPM package
    • Example applications
  • ADAPTER CONFIGURATION
    • Adapter
    • Transformers
    • TVL Extractors
    • How to code an adapter?
    • Functions we have written so you don't have to
      • Multicall
      • Sum Balances
    • GitHub repo
Powered by GitBook
On this page
  • Overview
  • Multicall.singleContractMultipleData
  • Multicall.multipleContractMultipleData
  • Multicall.multipleContractSingleData
  • Multicall.singleCall
  • Multicall.execute
  • Call Params
  • Call Result
  1. ADAPTER CONFIGURATION
  2. Functions we have written so you don't have to

Multicall

Multicall simply aggregates multiple contract calls into a single JSON RPC request.

Overview

In order to extract a large amount of data in an efficient way we have used Uniswap Multicall Contract for all JSON RPC requests in adapters.

We have coded a JS wrapper over the contracts and placed it in the abi module of our adapter SDK @spockanalytics/base. You can use it for contract calls in your project adapter.

Multicall.singleContractMultipleData

Execute multiple inputs for a single contract.

Usage

abi.Multicall.singleContractMultipleData<Erc20>({
    address: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
    chain: 1,
    contractInterface: Erc20_factory.createInterface(),
    fragment: 'balanceOf',
    callInput: ['0xF04a5cC80B1E94C69B48f5ee68a08CD2F09A7c3E','0x2F0b23f53734252Bda2277357e97e1517d6B042A']
});
Argument
Type
Description

address

string

contract address

blockNumber

number optional

Block number at which you want to query

chain

number

Network chainId

contractInterface

Interface

Interface of contract generated through typechain

fragment

string

Method name of contract

callInput

OptionalMethodInputs

Input parameters

Multicall.multipleContractMultipleData

Execute multiple inputs for multiple contracts.

Usage

abi.Multicall.multipleContractMultipleData<Erc20>({
    address: ['0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2','0x37c997b35c619c21323f3518b9357914e8b99525'],
    chain: 1,
    contractInterface: Erc20_factory.createInterface(),
    fragment: 'balanceOf',
    callInput: ['0xF04a5cC80B1E94C69B48f5ee68a08CD2F09A7c3E','0x2F0b23f53734252Bda2277357e97e1517d6B042A']
})
Argument
Type
Description

address

string[]

Contract addresses

blockNumber

number optional

Block at which you want to query

chain

number

Network chainId

contractInterface

Interface

Interface of contract generated through typechain

fragment

string

Method name of contract

callInput

OptionalMethodInputs

Input parameters

Multicall.multipleContractSingleData

Execute single input for multiple contracts.

Usage

abi.Multicall.multipleContractSingleData<Erc20>({
    address: ['0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2','0x37c997b35c619c21323f3518b9357914e8b99525'],
    chain: 1,
    contractInterface: Erc20_factory.createInterface(),
    fragment: 'balanceOf',
    callInput: ['0xF04a5cC80B1E94C69B48f5ee68a08CD2F09A7c3E']
})
Argument
Type
Description

address

string[]

Contract addresses

blockNumber

number optional

Block at which you want to query

chain

number

Network chainId

contractInterface

Interface

Interface of contract generated through typechain

fragment

string

Method name of contract

callInput

OptionalMethodInputs optional

Input parameters

Multicall.singleCall

Execute single input for a single contract.

Usage

abi.Multicall.singleCall<Erc20>({
    address: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
    chain: 1,
    contractInterface: Erc20_factory.createInterface(),
    fragment: 'balanceOf',
    callInput: ['0xF04a5cC80B1E94C69B48f5ee68a08CD2F09A7c3E']
})
Argument
Type
Description

address

string

Contract address

blockNumber

number optional

Block at which you want to query

chain

number

Network chainId

contractInterface

Interface

Interface of contract generated through typechain

fragment

string

Method name of contract

callInput

OptionalMethodInputs optional

Input parameters

Multicall.execute

Execute multiple calls in one request.

Usage

const WETH = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2';
const contractInterface = Erc20_factory.createInterface();

const calls = [
  new abi.Call<Erc20>({address:WETH, contractInterface, fragment:"name"}),
  new abi.Call<Erc20>({address:WETH, contractInterface, fragment:"symbol"}),
  new abi.Call<Erc20>({address:WETH, contractInterface, fragment:"decimals"})
];

abi.Multicall.execute({calls, chain:1});

Call

Argument
Type
Description

address

string

Contract address

contractInterface

Interface

Interface of contract generated through typechain.

fragment

string

Method name of contract

callInput

OptionalMethodInputs optional

Input parameters

Execute

Argument
Type
Description

blockNumber

number optional

Block at which you want to query

calls

Call[]

Calls to be executed

chain

number

Network chainId

disableChunk

boolean

Disable chunk calls on out of gas error

Call Params

import { BigNumber } from '@ethersproject/bignumber';

type MethodArg = string | number | BigNumber;
type OptionalMethodInputs =
  | Array<MethodArg | MethodArg[] | undefined>
  | undefined;

Call Result

The return type of each method.

//each method return an array of CallResult promise
// Promise<Array<CallResult>>

interface CallResult {
  call: {
    address: string;
    input: OptionalMethodInputs;
  };
  output: any;
  success: boolean;
}
PreviousFunctions we have written so you don't have toNextSum Balances

Last updated 1 year ago