Skip to content

Commit

Permalink
chore: fmt + README updates
Browse files Browse the repository at this point in the history
  • Loading branch information
klkvr committed Oct 31, 2024
1 parent b7d1494 commit 0d3497e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
3 changes: 2 additions & 1 deletion chapter1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
- [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
16 changes: 12 additions & 4 deletions chapter1/contracts/src/ERC20Fee.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand All @@ -36,4 +44,4 @@ contract ERC20Fee {
require(success, "call failed");
require(feeToken.transfer(msg.sender, fee));
}
}
}
6 changes: 3 additions & 3 deletions chapter1/erc20-fee/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export CHARLES_ADDRESS="0x90F79bf6EB2c4f870365E785982E1f101E93b906"
forge create TestERC20 --private-key $BOB_PK
export ERC20=<ERC20 addr>
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.:
Expand Down Expand Up @@ -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
```

0 comments on commit 0d3497e

Please sign in to comment.