Skip to content

Commit

Permalink
feat :batch delegate
Browse files Browse the repository at this point in the history
  • Loading branch information
= committed Dec 25, 2024
1 parent e36d93b commit 70ee5db
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
1 change: 1 addition & 0 deletions chapter1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Structure

- [contracts](./contracts): Solidity smart contracts powering the examples
- [batch-delegate](./batch-delegate/): Example of batch delegation authorization using EIP-7702
- [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
Expand Down
40 changes: 40 additions & 0 deletions chapter1/batch-delegate/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Batch Delegate Authorization Example

This example demonstrates how to perform batch delegation authorization using EIP-7702. It allows a user to authorize multiple delegates to execute transactions on their behalf.

## Steps involved

- Start a local Anvil node with Odyssey features enabled:

```bash
anvil --odyssey
```

- Set up environment variables for the accounts:
```bash
export ALICE_ADDRESS="0x70997970C51812dc3A010C7d01b50e0d17dc79C8"
export ALICE_PK="0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d"
export BOB_PK="0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a"
export CHARLIE_PK="0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC"
```

- Deploy a batch delegate contract:

```bash
forge create BatchDelegateContract --private-key $BOB_PK
```
- Authorize multiple delegates:
```bash
SIGNED_AUTH=$(cast wallet sign-auth $BATCH_DELEGATE_ADDRESS --private-key $ALICE_PK)
```

- Execute a batch transaction on behalf of Alice:
```bash
cast send $ALICE_ADDRESS "executeBatch((bytes,address,uint256)[])" "[("0x",$(cast az),0),("0x",$(cast az),0)]" --private-key $BOB_PK --auth $SIGNED_AUTH
```

- Verify that the batch transaction was successful:

```bash
cast code $ALICE_ADDRESS
```
24 changes: 24 additions & 0 deletions chapter1/contracts/src/BatchDelegateContract.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;
contract BatchDelegateContract {

struct Call {
bytes data;
address to;
uint256 value;
}

event Executed(address indexed to, uint256 value, bytes data);

function executeBatch(Call[] memory calls) external payable {
for (uint256 i = 0; i < calls.length; i++) {
Call memory call = calls[i];
(bool success,) = call.to.call{value: call.value}(call.data);
require(success, "Call failed");
emit Executed(call.to, call.value, call.data);
}

}
receive() external payable {}

}

0 comments on commit 70ee5db

Please sign in to comment.