Skip to content
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

abigen multicall support #30217

Closed
jbrower95 opened this issue Jul 24, 2024 · 5 comments
Closed

abigen multicall support #30217

jbrower95 opened this issue Jul 24, 2024 · 5 comments

Comments

@jbrower95
Copy link

Rationale

Why should this feature exist?
What are the use-cases?

abigen is a great way to interact with contracts onchain, but it doesn't (to my knowledge) support a mechanism for eth_multicall batching of requests, which makes it significantly harder to use than equivalent frameworks like Viem, which support batching via multicall already.

Implementation

Do you have ideas regarding the implementation of this feature?
Are you willing to implement this feature?

  • Could potentially codegen a multicall variant of each function, that instead returns data on the function to execute, and then provide one general utility function that accepts a varargs of these multicall outputs and submits them. You could also use golang generics and offer (2) and (3) bounded versions of this that are parameterized on the types of the Outputs, so that the user gets the correct struct type back in a typed tuple.
a, b, err := multicall(MyContractReadOneMulticall(), MyContractReadTwoMulticall())

Something like this for that 2->5 cases would be sufficient for me, and very nice.

References:

@rjl493456442
Copy link
Member

So your feature request is to have a function aggregating the results of different calls? I don't see a big value of it.

Btw, eth_multicall might be adopted as a standard JSONPRC API which supports a tons of flexibilities. It might be interesting for you ethereum/execution-apis#484

@jbrower95
Copy link
Author

ether-rs (rust), viem (js), and ape (python) all support multicall out-of-the-box.

People are building indexers and other data-intensive apps on top of abigen's autogenerated classes, and having 1st class native support for multicall would severely reduce the # roundtrips to their nodes needed, reducing infrastructure bills in the way. I'm nearly ready to migrate away from golang on our backend for this reason alone.

I plan to put up a PR here updating the codegen to support multicall via the multicall3 contracts -- happy to fork if you don't want it included in the main repo. (https://www.multicall3.com/)

Thanks!

@jbrower95
Copy link
Author

jbrower95 commented Sep 6, 2024

I've implemented a typed version of interacting with Multicall here for Eigen Labs (Layr-Labs/eigenpod-proofs-generation#151). Part of it relies on writing a completely deterministic deserialization function which I'll be codegenning in a fork of abigen later this weekend. Would love to upstream something here as this shows up in every Go web3 codebase i've worked in -- it's a PITA to use multicall.

Then, that code can clean up to be 1-2 understandable lines on the caller side.

@jbrower95
Copy link
Author

#30416

I've put up a draft PR for feedback on the approach. If maintainers like the approach, I'll finish this up and we can push to merge upstream. It would be phenomenal if geth's clients / contracts supported multicall out of the box.

Recent adoption of multicall lowered our querying times to the node by over 90% -- this is important for people who are writing indexers or using saas node vendors (where multicall can lower the # of node credits used over a period of time).

Excited to push this forward with ya'll :)

@rjl493456442
Copy link
Member

#30416 (comment)

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

No branches or pull requests

2 participants