-
Couldn't load subscription status.
- Fork 2.2k
feat(cast): add cast erc20 with subcommands balance, transfer, approve, allowance #12258
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marcvernet31 thank you! since you mentioned you tested with an anvil node, we could add same in unit tests, here's an example of a cast test that starts anvil and then send cast mktx commands, could you replicate your tests this way?
foundry/crates/cast/tests/cli/main.rs
Lines 1639 to 1665 in 1b115d8
| casttest!(mktx_raw_unsigned_no_from_missing_chain, async |_prj, cmd| { | |
| // As chain is not provided, a query is made to the provider to get the chain id, before the tx | |
| // is built. Anvil is configured to use chain id 1 so that the produced tx will be the same | |
| // as in the `mktx_raw_unsigned` test. | |
| let (_, handle) = anvil::spawn(NodeConfig::test().with_chain_id(Some(1u64))).await; | |
| cmd.args([ | |
| "mktx", | |
| "--nonce", | |
| "0", | |
| "--gas-limit", | |
| "21000", | |
| "--gas-price", | |
| "10000000000", | |
| "--priority-gas-price", | |
| "1000000000", | |
| "0x0000000000000000000000000000000000000001", | |
| "--raw-unsigned", | |
| "--rpc-url", | |
| &handle.http_endpoint(), | |
| ]) | |
| .assert_success() | |
| .stdout_eq(str![[ | |
| r#"0x02e80180843b9aca008502540be4008252089400000000000000000000000000000000000000018080c0 | |
| "# | |
| ]]); | |
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great job!
left some minor nits
| impl Erc20Subcommand { | ||
| pub async fn run(self) -> eyre::Result<()> { | ||
| match self { | ||
| // TODO: change account for who??? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please rmv the todo.
you can add an alias for who instead if u want.
| Some(token) => { | ||
| let balance = | ||
| Cast::new(&provider).erc20_balance(token, account_addr, block).await?; | ||
| sh_warn!("--erc20 flag is deprecated, use cast erc20 balance instead")?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| sh_warn!("--erc20 flag is deprecated, use cast erc20 balance instead")?; | |
| sh_warn!("--erc20 flag is deprecated, use `cast erc20 balance` instead")?; |
| /// The account to query. | ||
| #[arg(value_parser = NameOrAddress::from_str)] | ||
| account: NameOrAddress, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we rename it to owner to stick to the ERC20 interface? account was previously used cause --erc20 was just a flag on top of the cmd that would get teh eth balance of an account.
| /// ERC20 token subcommands. | ||
| /// CLI arguments for `cast tx-pool`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this shows up in the help output, so please fix this up
| /// ERC20 token subcommands. | |
| /// CLI arguments for `cast tx-pool`. | |
| /// Interact with ERC20 tokens. |
Motivation
Refactor usage of
--erc20flag into commandcast erc20. Onboard additional actions as defined here: #12095Solution
Introduce a dedicated cast erc20 command with various subcommands for common ERC20 operations:
cast erc20 balance <TOKEN> <ACCOUNT>- Query ERC20 token balance (replaces cast balance --erc20)cast erc20 transfer <TOKEN> <TO> <AMOUNT>- Transfer tokens using transfer(address,uint256)cast erc20 approve <TOKEN> <SPENDER> <AMOUNT>- Approve token spending usingapprove(address,uint256)
cast erc20 allowance <TOKEN> <OWNER> <SPENDER>- Query allowance usingallowance(address,address)
Also added a deprecation warning on the --erc20 command.
Tested with a local Anvil node.
PR Checklist