• Stars
    star
    245
  • Rank 165,304 (Top 4 %)
  • Language
    Python
  • License
    MIT License
  • Created almost 5 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

aggregate results of multiple smart contract calls into one

multicall.py

python interface for makerdao's multicall and a port of multicall.js

installation

pip install multicall

example

from multicall import Call, Multicall

# assuming you are on kovan
MKR_TOKEN = '0xaaf64bfcc32d0f15873a02163e7e500671a4ffcd'
MKR_WHALE = '0xdb33dfd3d61308c33c63209845dad3e6bfb2c674'
MKR_FISH = '0x2dfcedcb401557354d0cf174876ab17bfd6f4efd'

def from_wei(value):
    return value / 1e18

multi = Multicall([
    Call(MKR_TOKEN, ['balanceOf(address)(uint256)', MKR_WHALE], [('whale', from_wei)]),
    Call(MKR_TOKEN, ['balanceOf(address)(uint256)', MKR_FISH], [('fish', from_wei)]),
    Call(MKR_TOKEN, 'totalSupply()(uint256)', [('supply', from_wei)]),
])

multi()  # {'whale': 566437.0921992733, 'fish': 7005.0, 'supply': 1000003.1220798912}

# seth-style calls
Call(MKR_TOKEN, ['balanceOf(address)(uint256)', MKR_WHALE])()
Call(MKR_TOKEN, 'balanceOf(address)(uint256)')(MKR_WHALE)
# return values processing
Call(MKR_TOKEN, 'totalSupply()(uint256)', [('supply', from_wei)])()

for a full example, see implementation of daistats. original daistats.com made by nanexcool.

api

Signature(signature)

  • signature is a seth-style function signature of function_name(input,types)(output,types). it also supports structs which need to be broken down to basic parts, e.g. (address,bytes)[].

use encode_data(args) with input args to get the calldata. use decode_data(output) with the output to decode the result.

Call(target, function, returns)

  • target is the to address which is supplied to eth_call.
  • function can be either seth-style signature of method(input,types)(output,types) or a list of [signature, *args].
  • returns is a list of tuples of (name, handler) for return values. if returns argument is omitted, you get a tuple, otherwise you get a dict. to skip processing of a value, pass None as a handler.

use Call(...)() with predefined args or Call(...)(args) to reuse a prepared call with different args.

use decode_output(output) with to decode the output and process it with returns handlers.

Multicall(calls)

  • calls is a list of calls with prepared values.

use Multicall(...)() to get the result of a prepared multicall.

Environment Variables

  • GAS_LIMIT: sets overridable default gas limit for Multicall to prevent out of gas errors. Default: 50,000,000
  • MULTICALL_DEBUG: if set, sets logging level for all library loggers to logging.DEBUG
  • MULTICALL_PROCESSES: pass an integer > 1 to use multiprocessing for encoding args and decoding results. Default: 1, which executes all code in the main process.
  • AIOHTTP_TIMEOUT: sets aiohttp timeout period in seconds for async calls to node. Default: 30

test

export WEB3_INFURE_PROJECT_ID=<your_infura_id>
export PYTEST_NETWORK='mainnet'
poetry run python -m pytest

More Repositories

1

brownie-safe

gnosis safe tx builder
Python
268
star
2

evil-jar

evil jar attack technical post-mortem
Python
137
star
3

storage-layout

readable evm state diffs, enumerate full contract storage
Python
134
star
4

cryogen

helps you preserve the ethereum dataset fresh, fast and small
Python
115
star
5

seed-liquidity

Pool funds to bootstrap a Uniswap pair
Python
77
star
6

vyper-reentrancy

Vyper
63
star
7

erigon-kv

python bindings for erigon kv gprc api
Python
54
star
8

disperse-research

research behind disperse protocol
TeX
52
star
9

fast

fast.com cli speedtest
Python
49
star
10

yfi-buyer

buys yfi at current price
Python
42
star
11

ape-llamapay

ape sdk for llamapay
Python
42
star
12

lobsterdao

Lazy airdrop based on private temporary ids
Python
41
star
13

raycast-eips

look up ethereum proposals and read them in raycast
TypeScript
38
star
14

gasprice

estimate ethereum gas price
Python
34
star
15

yearn-fees

a quest for accurate fee accounting
Vyper
30
star
16

etherscan-cache

Python
30
star
17

lido-vault

Yearn Vault wrapper for Lido St. Ether
Python
27
star
18

httpie-image

HTTPie plugin to display images in iTerm2
Python
24
star
19

cornichon

Python
23
star
20

your-eminence

distribution scripts for eminence compensation
Python
22
star
21

liqui

liqui.io api wrapper
Python
21
star
22

permit-deposit

Python
19
star
23

telegram

a very minimal telegram api wrapper
Python
18
star
24

dpack

python implementation of dpack evm packaging format
Python
18
star
25

imagehashmasks

hashmask reverse lookup
Python
17
star
26

exploit-ycredit

Python
17
star
27

strategy-uni-lp-pickle

Python
17
star
28

vmtrace

evm-trace vmtrace demo and playground
Python
17
star
29

baseline-looper

loop into YES or unwind a baseline credit account
Python
16
star
30

uniswap

uniswap analytics
Python
14
star
31

gas-costs

a quick way to calculate gas costs for a bunch of accounts
Python
13
star
32

feil-proposal

governance proposal to make fei redeemable for eth
Python
13
star
33

bitcointalk

parses bitcointalk ann topics and sends them to telegram channel
Python
12
star
34

lido-keep3r

Python
12
star
35

yearn-vault-keeper

keep yearn vaults tightly invested while maintaining the withdrawal buffer
Python
12
star
36

ape-events

ape log caching plugin
Python
12
star
37

defi-apy

Python
11
star
38

brownie-ds-proxy

Python
11
star
39

yfi-pact

our pact with the devil
Python
11
star
40

blue-pill

The Blue Pill: A spiritual guide for the past, present and future of Yearn
Python
10
star
41

vyper-cwia

vyper contract that can access immutable arguments passed as calldata
Python
10
star
42

woofy-snapshot

Solidity
10
star
43

baseline-snapshot

YES token snapshot
Jupyter Notebook
10
star
44

coinlisting

cryptocurrency exchanges new coins listing
Python
9
star
45

yearn-principles

8
star
46

parasitic-vault

Python
8
star
47

staking-deposit

simple gΓΆrli mass deposit contract
Python
8
star
48

docsend

convert docsend to pdf or png sequence
Python
7
star
49

universal-router

Python
7
star
50

snek3

msgspec definitions of ethereum execution client api
Python
6
star
51

vyper-eip6909

eip-6909: minimal multi-token interface in vyper
Vyper
6
star
52

veyfi-model

Jupyter Notebook
6
star
53

itf

Python
5
star
54

uniswap-distribution

5
star
55

maker-chief

tally makerdao governance votes
Python
5
star
56

tellor

python tools for tellor
Python
5
star
57

yearn-permit

TypeScript
5
star
58

pip-blame

finds packages that prevent upgrading a transitive dependency
Python
4
star
59

spank-uni-distribution

Python
4
star
60

curvefi

Python
4
star
61

blockfolio

blockfolio cli
Python
4
star
62

docker-as-venv

an example of how to use docker for python web development
Python
3
star
63

pink-duck

Quack quack
Python
3
star
64

sign-test

test of how github displays author/committer spoofing
3
star
65

vyper-eip1967

Vyper
2
star
66

poloniex

minimal poloniex api wrapper
Python
2
star
67

vyper-traceback-bug

looking into compat issue in ape-vyper
Vyper
1
star
68

pickle-snapshot

1
star
69

stamps

Python
1
star
70

lto-bridge

three-way lto bridge monitoring
Python
1
star
71

pytho

Akropolis IOU token
Python
1
star
72

hug_raven

Sentry integration for hug
Python
1
star
73

unswerve

liquid wrapper for vote-locked swrv
Python
1
star