Skip to content

Commit

Permalink
add label to W3
Browse files Browse the repository at this point in the history
  • Loading branch information
0rtis committed Jun 13, 2023
1 parent b8b9adf commit faa1471
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ However, [multicall.py](https://github.com/banteg/multicall.py) is built on [asy

This implementation fixes that.

# Multicall Smart Contract
# W3Multicall

## Multicall Smart Contract
[Multicall](https://github.com/mds1/multicall) smart contract are deployed on numerous chains and can help reduce the strain
put on RPC by order of magnitude by *batching* multiple requests into a single one.

# Simple Multicall
## Simple Multicall

```
from web3 import Web3
Expand All @@ -49,7 +51,7 @@ print("Vitalik holds {:.2f} USDC".format(results[0]/10**6))

[See full example](/examples/simple_multicall.py)

# Multithread Multicall
## Multithread Multicall

```
w3_pool = W3Pool([
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"
name = "w3multicall"
description = "Python interface and utilities for Solidity multicall contract"
authors = [{name = "Ortis", email = "[email protected]"}]
version = "0.1.1"
version = "0.1.2"
readme = "README.md"
keywords = ["blockchain", "web3", "etherum", "solidity"]
license = {file = "LICENSE"}
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = w3multicall
version = 0.1.1
version = 0.1.2
author = Ortis
author_email = [email protected]
description = Python interface and utilities for Solidity multicall contract
Expand Down
5 changes: 5 additions & 0 deletions src/w3multicall/multicall.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ class W3Multicall:

class Call:
def __init__(self, address: str, signature: str, args=None):
"""
:param address: address of the contract to call
:param signature: method signature to call (no space. Example: 'balanceOf(address)(uint256)')
:param args: arguments of the contract method to call (use python tuple for solidity struct, python list for solidity arrays and python int for solidity uint/int)
"""
self.address = address
self.signature = signature.replace(" ", "")

Expand Down
5 changes: 3 additions & 2 deletions src/w3multicall/threading/w3multicall_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@

class W3:

def __init__(self, w3: Web3, delay_between_call: float):
def __init__(self, w3: Web3, delay_between_call: float, label: Union[str, None] = None):
self.w3 = w3
self.delay_between_call = delay_between_call
self.limit_rate_per_seconds = 1 / self.delay_between_call
self.last_call_at = 0
self.label = str(self) if label is None else label

def __repr__(self):
return '{} {:.2f}/s'.format(self.w3, self.limit_rate_per_seconds)
return '{} {:.2f}/s'.format(self.label, self.limit_rate_per_seconds)

def use(self) -> Web3:
self.last_call_at = time.time()
Expand Down

0 comments on commit faa1471

Please sign in to comment.