Skip to content

Add access to core Multicall contract methods #123

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
43 changes: 43 additions & 0 deletions multicall/multicall.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,49 @@ async def coroutine(self) -> Dict[str, Any]:
)
return dict(mapcat(dict.items, concat(batches)))

def _contract_method(self, request_signature: list, return_signature: tuple) -> None:
self.calls.append(Call(self.multicall_address, request_signature, (return_signature)))

def get_base_fee(self, return_signature: tuple = ('base_fee', None)) -> None:
signature = ['getBasefee()(uint256)']
self._contract_method(signature, return_signature)

def get_block_hash(self, block_number: int, return_signature: tuple = ('block_hash', None)) -> None:
signature = ['getBlockHash(uint256)(bytes32)', int]
self._contract_method(signature, return_signature)

def get_block_number(self, return_signature: tuple = ('block_number', None)) -> None:
signature = ['getBlockNumber()(uint256)']
self._contract_method(signature, return_signature)

def get_chain_id(self, return_signature: tuple = ('chain_id', None)) -> None:
signature = ['getChainId()(uint256)']
self._contract_method(signature, return_signature)

def get_block_coinbase(self, return_signature: tuple = ('coinbase', None)) -> None:
signature = ['getCurrentBlockCoinbase()(address)']
self._contract_method(signature, return_signature)

def get_block_difficulty(self, return_signature: tuple = ('difficulty', None)) -> None:
signature = ['getCurrentBlockDifficulty()(address)']
self._contract_method(signature, return_signature)

def get_block_gas_limit(self, return_signature: tuple = ('gas_limit', None)) -> None:
signature = ['getCurrentBlockGasLimit()(uint256)']
self._contract_method(signature, return_signature)

def get_block_timestamp(self, return_signature: tuple = ('timestamp', None)) -> None:
signature = ['getCurrentBlockTimestamp()(uint256)']
self._contract_method(signature, return_signature)

def get_eth_balance(self, address: AnyAddress, return_signature: tuple = ('eth_balance', None)) -> None:
signature = ['getEthBalance(address)(uint256)', address]
self._contract_method(signature, return_signature)

def get_last_block_hash(self, return_signature: tuple = ('last_block_hash', None)) -> None:
signature = ['getLastBlockHash()(bytes32)']
self._contract_method(signature, return_signature)

async def fetch_outputs(
self, calls: List[Call], ConnErr_retries: int = 0, id: str = ""
) -> List[CallResponse]:
Expand Down
Loading