Skip to content

feat: added rpc method to deal ERC20 tokens #10495

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Soubhik-10
Copy link
Contributor

closes #8956

@@ -359,6 +359,10 @@ pub enum EthRequest {
#[serde(rename = "anvil_setBalance", alias = "hardhat_setBalance")]
SetBalance(Address, #[serde(deserialize_with = "deserialize_number")] U256),

/// Modifies the ERC20 balance of an account.
#[serde(rename = "anvil_dealERC20", alias = "hardhat_dealERC20")]
DealERC20(Address, #[serde(deserialize_with = "deserialize_number")] U256, Address),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's swap the order here, similar to setBalance


let calldata = IERC20::balanceOfCall { target: address }.abi_encode();
let tx = TransactionRequest::default().with_input(calldata);
let access_list_result = self.create_access_list(WithOtherFields::new(tx), None).await?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great

Comment on lines +1854 to +1859
let access_list = access_list_result.access_list;
for item in access_list.0 {
if item.address != token_address {
continue;
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now here we need to loop over all slots and send an ethcall with a stateoverride for the slot in order to find the slot that has the balance:

https://github.com/Rubilmax/viem-deal/blob/cf378cedcb28bbcc18fcbfac2c6f9e5c333edcf3/src/actions/test/deal.ts#L106-L108

and then finally we need to call set storage for that slot and value

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

feat(anvil): add RPC method similar to the ERC20 deal cheatcode
2 participants