Skip to content

Add EntryPoint v0.6 and v0.7 contract bindings #31

Description

@ch4r10t33r

Title

Add EntryPoint v0.6 and v0.7 contract bindings

Labels

enhancement, account-abstraction, contract, entrypoint

Description

Implement contract bindings for the ERC-4337 EntryPoint contract, which is the core singleton contract that processes UserOperations. Reference: eth-infinitism/account-abstraction

Requirements

Contract Addresses

  • Add EntryPoint v0.6 address: 0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789
  • Add EntryPoint v0.7 address (when finalized)
  • Network-specific EntryPoint registry

Core Methods

  • handleOps:

    pub fn handleOps(
        ops: []const UserOperation,
        beneficiary: Address,
    ) !Hash
  • handleAggregatedOps:

    pub fn handleAggregatedOps(
        opsPerAggregator: []const UserOpsPerAggregator,
        beneficiary: Address,
    ) !Hash
  • getUserOpHash:

    pub fn getUserOpHash(userOp: UserOperation) Hash
  • getNonce:

    pub fn getNonce(sender: Address, key: u256) u256

View Functions

  • balanceOf(account: Address) u256 - Get account's deposit
  • getDepositInfo(account: Address) DepositInfo
  • getSenderAddress(initCode: []u8) Address - Calculate sender address

Deposit Management

  • depositTo(account: Address, amount: u256) - Add deposit
  • withdrawTo(withdrawAddress: Address, amount: u256) - Withdraw
  • addStake(unstakeDelaySec: u32, amount: u256) - Stake for entity

Events

  • Define event types:
    • UserOperationEvent - UserOp executed
    • AccountDeployed - New account created
    • UserOperationRevertReason - UserOp failed
    • Deposited - Deposit made
    • Withdrawn - Withdrawal made
    • StakeLocked - Entity staked
    • StakeUnlocked - Stake unlocked
    • StakeWithdrawn - Stake withdrawn

Event Parsing

  • Parse UserOperationEvent:
    pub const UserOperationEvent = struct {
        userOpHash: Hash,
        sender: Address,
        paymaster: Address,
        nonce: u256,
        success: bool,
        actualGasCost: u256,
        actualGasUsed: u256,
    };

EntryPoint Contract Binding

  • Create contract wrapper:
    pub const EntryPoint = struct {
        address: Address,
        provider: *Provider,
        
        pub fn v06(provider: *Provider) EntryPoint;
        pub fn v07(provider: *Provider) EntryPoint;
        pub fn at(address: Address, provider: *Provider) EntryPoint;
    };

File Structure

src/account_abstraction/
  ├── entrypoint.zig           # EntryPoint contract bindings
  ├── entrypoint_abi.zig       # ABI definitions
  └── events.zig               # Event types and parsing

Example Usage

const entrypoint = zigeth.accountAbstraction.EntryPoint.v06(provider);

// Get account nonce
const nonce = try entrypoint.getNonce(account_address, 0);

// Check deposit
const deposit = try entrypoint.balanceOf(account_address);

// Listen for UserOperationEvents
const filter = try entrypoint.createUserOpFilter(account_address);
const logs = try provider.eth.getLogs(filter);

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions