Skip to content

Add paymaster integration for sponsored (gasless) transactions #30

Description

@ch4r10t33r

Title

Add paymaster integration for sponsored (gasless) transactions

Labels

enhancement, account-abstraction, paymaster, gasless

Description

Implement paymaster functionality to enable sponsored transactions where users don't pay gas fees directly, following the ERC-4337 paymaster specification.

Requirements

Paymaster Data Types

  • Define PaymasterData struct:
    • paymaster: Address - Paymaster contract address
    • paymaster_verification_gas_limit: u256 - Gas for paymaster validation
    • paymaster_post_op_gas_limit: u256 - Gas for post-operation logic
    • paymaster_data: []u8 - Custom data for paymaster

Paymaster Middleware

  • Create PaymasterMiddleware:
    • getPaymasterData(userOp: *UserOperation) PaymasterData - Get paymaster approval
    • signPaymasterData(data: PaymasterData) []u8 - Sign if needed
    • verifyPaymasterData(data: PaymasterData) bool - Validate response

Common Paymaster Patterns

  • Verifying Paymaster:

    • Sponsor based on off-chain signature
    • Whitelist validation
    • Rate limiting
  • Token Paymaster:

    • Pay gas fees with ERC-20 tokens
    • Automatic token approval
    • Price oracle integration
  • Deposit Paymaster:

    • Pre-funded deposit system
    • Balance checking

Integration

  • Integrate with UserOperation builder:

    var userOp = try UserOperationBuilder.init(allocator)
        .setSender(account)
        .setCallData(data)
        .usePaymaster(paymaster_service)  // <-- automatic paymaster
        .build();
  • Add to providers:

    • withPaymaster(paymaster_url: []u8) Provider

Paymaster Service Integration

  • Support for popular paymaster services:

    • Pimlico
    • Biconomy
    • Alchemy Gas Manager
    • Stackup
  • Custom paymaster API integration:

    • pm_sponsorUserOperation RPC method
    • Context data passing
    • Signature validation

File Structure

src/account_abstraction/
  ├── paymaster.zig            # Paymaster types and logic
  ├── paymaster_middleware.zig # Middleware integration
  └── paymaster_services/
      ├── pimlico.zig
      ├── biconomy.zig
      └── custom.zig

Example Usage

// Using a paymaster service
const paymaster = try PimlicoPaymaster.init(allocator, api_key);

var userOp = try UserOperationBuilder.init(allocator)
    .setSender(smart_account)
    .setCallData(call_data)
    .usePaymaster(&paymaster)  // Gas will be sponsored!
    .build();

const hash = try bundler.sendUserOperation(userOp);
// User pays 0 ETH for gas! 🎉

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions