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

Conversation

DefiDebauchery
Copy link
Contributor

@DefiDebauchery DefiDebauchery commented Apr 22, 2025

The core Multicall contracts have various methods for accessing base attributes of the chain at the executed block number, the most important (IMO) being getEthBalance() and getCurrentBlockTimestamp().

getBlockNumber() is slightly redundant since it's already provided via aggregate() / tryBlockAndAggregate() (exposed via #74), but added, along with all other methods, for completeness.

One real-world example that I use in my own code:

calls = [
	Call(wrapped_native, ['balanceOf(address)(uint256)', my_address], [['weth_balance', None]])
]
mc = Multicall(calls, _w3=rpc)
mc.get_eth_balance(my_address)

results = await mc.coroutine()
// {'weth_balance': 4858579460227, 'eth_balance': 60178543536789}

The return signature can be overridden to a different key or formatter.

Edits to overall structure or nomenclature welcome.

@BobTheBuidler
Copy link
Collaborator

Could you add a test case for each of these new methods?

@BobTheBuidler
Copy link
Collaborator

just out of curiosity, why don't you query these from the w3 object directly? It should be faster for you

@DefiDebauchery
Copy link
Contributor Author

DefiDebauchery commented May 8, 2025

just out of curiosity, why don't you query these from the w3 object directly? It should be faster for you

Not sure I understand; how/why would it be any faster than doing it from within the context of a query I'm already making?

As for the intent overall, it's more or less separation of concerns; the multicall module should handle everything related to making multicall queries, without me having to remember the address or signature.

Will add test cases as soon as I remember how to do that 😅 My least favorite part

@BobTheBuidler
Copy link
Collaborator

Sorry, that was an oversight. I was thinking "theres a specialized method for that on the rpc" but missed the fact that you're referring to the timestamp

If you get the tests added I'll setup a testing workflow so this PR and future PRs is tested right here on github

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants