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.34k stars 1.77k forks source link

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

Open anajuliabit opened 2 months ago

anajuliabit commented 2 months 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 2 months ago

I think this is a reasonable feature

roninjin10 commented 1 month ago

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

Rubilmax commented 1 month ago

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

Rubilmax commented 1 month 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 1 month ago

can I work on this, please?

yash-atreya commented 1 month ago

Assigned @maxslimb

Rubilmax commented 1 month 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 month ago

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

grandizzy commented 2 weeks ago

@maxslimb pls see https://github.com/foundry-rs/foundry/blob/master/CONTRIBUTING.md thanks!