From 28278f7fe133acfab2f3851e0d20e636e7eff6b4 Mon Sep 17 00:00:00 2001 From: Arsenii Kulikov Date: Fri, 1 Nov 2024 02:09:47 +0400 Subject: [PATCH] chore: fmt + README updates (#18) --- chapter1/README.md | 3 ++- chapter1/contracts/src/ERC20Fee.sol | 16 ++++++++++++---- chapter1/erc20-fee/README.md | 6 +++--- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/chapter1/README.md b/chapter1/README.md index 78f11db..0125645 100644 --- a/chapter1/README.md +++ b/chapter1/README.md @@ -6,4 +6,5 @@ - [bls-multisig](./bls-multisig): Multisig based on BLS signatures verified through precompiles from EIP-2537 - [eof](./eof): Introduction to EOF - [simple-7702](./simple-7702): Demo of full EIP-7702 flow with cast and forge -- [delegate-p256](./delegate-p256): Account controlled by a P256 key through EIP-7702 and EIP-7212 \ No newline at end of file +- [delegate-p256](./delegate-p256): Account controlled by a P256 key through EIP-7702 and EIP-7212 +- [erc20-fee](./erc20-fee): Demo of EIP-7702 delegation contract allowing to pay gas fee in ERC20 \ No newline at end of file diff --git a/chapter1/contracts/src/ERC20Fee.sol b/chapter1/contracts/src/ERC20Fee.sol index 4f3903b..c116312 100644 --- a/chapter1/contracts/src/ERC20Fee.sol +++ b/chapter1/contracts/src/ERC20Fee.sol @@ -6,7 +6,7 @@ interface IERC20 { } contract TestERC20 { - mapping (address => uint256) public balance; + mapping(address => uint256) public balance; function transfer(address _to, uint256 _value) public returns (bool success) { balance[msg.sender] -= _value; @@ -21,12 +21,20 @@ contract TestERC20 { /// @notice Contract designed for being delegated to by EOAs to authorize an ERC20 transfer with ERC20 as fee. contract ERC20Fee { - /// @notice Internal nonce used for replay protection, must be tracked and included into prehashed message. uint256 public nonce; /// @notice Main entrypoint to send tx. - function execute(address to, bytes memory data, uint256 value, IERC20 feeToken, uint256 fee, uint8 v, bytes32 r, bytes32 s) public { + function execute( + address to, + bytes memory data, + uint256 value, + IERC20 feeToken, + uint256 fee, + uint8 v, + bytes32 r, + bytes32 s + ) public { bytes32 digest = keccak256(abi.encode(nonce++, to, data, value, feeToken, fee)); address addr = ecrecover(digest, v, r, s); @@ -36,4 +44,4 @@ contract ERC20Fee { require(success, "call failed"); require(feeToken.transfer(msg.sender, fee)); } -} \ No newline at end of file +} diff --git a/chapter1/erc20-fee/README.md b/chapter1/erc20-fee/README.md index 546ef2f..dc2472d 100644 --- a/chapter1/erc20-fee/README.md +++ b/chapter1/erc20-fee/README.md @@ -26,7 +26,7 @@ export CHARLES_ADDRESS="0x90F79bf6EB2c4f870365E785982E1f101E93b906" forge create TestERC20 --private-key $BOB_PK export ERC20= cast send $ERC20 'mint(address,uint256)' $ALICE_ADDRESS 10000000000000000000 --private-key $BOB_PK # 10E9 tokens -cast call $ERC20 'balance(address)' $ALICE_ADDRESS +cast call $ERC20 'balance(address)(uint256)' $ALICE_ADDRESS ``` - We need to deploy a contract which verifies the user signature and execute ERC20 transfers.: @@ -71,7 +71,7 @@ cast send $ALICE_ADDRESS "execute(address,bytes,uint256,address,uint256,uint8,by - Bob will receive the ERC20 token as the fee, and Charles will receive the ERC20 token ```bash -cast call $ERC20 "balance(address)" $BOB_ADDRESS -cast call $ERC20 "balance(address)" $CHARLES_ADDRESS +cast call $ERC20 "balance(address)(uint256)" $BOB_ADDRESS +cast call $ERC20 "balance(address)(uint256)" $CHARLES_ADDRESS ```