foundry-rs / foundry

Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.
https://getfoundry.sh
Apache License 2.0
8.27k stars 1.74k forks source link

feat(`anvil`): add RPC method similar to the ERC20 `deal` cheatcode #8956

Open anajuliabit opened 1 month ago

anajuliabit commented 1 month ago

Component

Anvil

Describe the feature you would like

I'd like to request the creation of an RPC method similar to the ERC20 deal cheatcode for the following use case:

I need to gather enough votes in a governor to approve a proposal. If a deal equivalent RPC method exists, I could simply deal the quorum amount to any wallet, rather than having to impersonate multiple whale wallets to meet the quorum.

Thank you!

Additional context

No response

mattsse commented 1 month ago

I think this is a reasonable feature

roninjin10 commented 3 weeks ago

+1 on this but would prefer it not be called deal

Rubilmax commented 3 weeks ago

This would be very helpful to use anvil as a backend for tests where you need to handle ERC20 tokens

Rubilmax commented 3 weeks ago

@roninjin10 had the idea to request an access list for a call to erc20.balanceOf(account) which would return the storage slot most probably as the last element of the access list returned

That should speed things up right?

maxslimb commented 2 weeks ago

can I work on this, please?

yash-atreya commented 2 weeks ago

Assigned @maxslimb

Rubilmax commented 2 weeks ago

@roninjin10 had the idea to request an access list for a call to erc20.balanceOf(account) which would return the storage slot most probably as the last element of the access list returned

That should speed things up right?

For reference, I implemented this using viem in TypeScript here

Results are much much faster, which avoid having to rely on some external cache because only a few RPC queries are made and no brute-force is required anymore

Also, it adds support for non-trivial tokens such as stETH and USD0. I highly recommend doing something similar at anvil's level: request the access list and try each slot of the access list instead of brute-forcing the balanceOf slot

maxslimb commented 1 week ago

@yash-atreya do you have any guidelines to contribute and for creating a pr?