Open Paymaster
Decentralized ERC-4337 paymaster enabling cross-chain gasless transactions via liquidity pools.
Problem Statement
Open Paymaster is a decentralized, trustless paymaster built on ERC-4337 that enables gasless blockchain transactions through community-funded liquidity pools.The frustrating problem:Users face three fundamental barriers when using Ethereum-compatible networks:The Gas Paradox: Having tokens but being unable to use them due to lack of native currency for gasAcquisition Friction: Getting gas requires bridging funds or using centralized exchanges with KYCComplexity Barrier: End users shouldn't need to understand gas, it's an implementation detail that should be abstracted awayWhy Centralized Paymasters available today Don't Solve This:Trust dependency: Users rely on third party managed Paymasters to maintain operations and liquidityLiveness risk: No guarantee the service will stay operational or fundedHigh fees: Typically charge 10%+ markup on gas costsA proposed solutionOpen Paymaster enables users to pay transaction fees with any supported ERC-20 token. Liquidity providers earn yield on native ETH deposits, while users get seamless access without ever touching gas tokens.How It Works:Community-funded liquidity pools: LPs deposit native ETH to the tokens they are willing to support and earn yield from the user operations fees.Token-to-gas conversion: Users pay fees in tokens they already holdPermissionless rebalancing: anyone can "rebalance" the pools by re-filling them ETH and claiming the accumulated tokens plus a `rebalancing fee, effectively "buying tokens at a discount price", before being able to sell them outside the system, fulfilling arbitrage opportunities that maintain the pools operable.ERC-4337 infrastructure: Leverages account abstraction and can be integrated into any ERC-4337 Wallet.Complementation with EILOpen Paymaster strongly complements the Ethereum Interoperability Layer (EIL) to achieve a truly unified Ethereum experience. While EIL CrossChainPaymaster covers gas on destination chains, the Open Paymaster covers the gas on the origin chain. Together, these systems eliminate the need to maintain ETH balances across multiple chains or trust centralized intermediaries.Example:Alice has 100 USDC on Ethereum mainnet. She wants to send 50 USDC to Bob on Base. Neither of them has or understands what gas is.Traditional approach (broken UX):Buy ETH with USDC on mainnetBridge ETH to BaseBridge USDC to BaseSend USDC to BobBob needs Base ETH to use the fundsWith Open Paymaster + EIL:Alice sends 50 USDC to Bob's Base addressOpen Paymaster takes gas payment in USDC on mainnet (origin)EIL Voucher Request is fulfilled by an XLP on Base (destination)Bob receives 50 USDC on Base, usable immediatelyNeither Alice nor Bob needed to understand gas, acquire native tokens, or trust centralized services.Key Properties:Trustless: No reliance on centralized operators Permissionless: Anyone can become a liquidity provider Gasless UX: Users pay fees in tokens they already hold ERC-4337 native: Built on the account abstraction standard Cross-chain ready: Integrates with EIL for multi-chain operations
Solution
`The system is built in Solidity with Foundry as the development framework. The OpenPaymaster contract inherits from three base contracts: BasePaymaster (ERC-4337 interface), EntryPointVault (ERC-6909 multi-token vault for LP share accounting), and PythOracleAdapter (Pyth Network price feed integration).The contract defines three roles: Liquidity Providers deposit ETH and earn fees, Users pay gas in tokens, and Rebalancers arbitrage token accumulation to keep pools balanced.SYSTEM COMPONENTSOpen Paymaster: Singleton on-chain contract holding all liquidity pools. Handles token-to-gas conversion, gas sponsorship, and LP share management.Paymaster Router (optional): Off-chain service that queries all pools for a given token and returns the cheapest option. Example: "I want to pay in USDC, which pool gives me the best rate right now?"Frontend (optional): Next.js web app providing fallback UI for liquidity providers to deposit, withdraw, and rebalance pools. Also serves as a fallback for users whose wallets don't support Open Paymaster yet, enabling cross-chain gasless transactions directly through the web interface.HOW A TRANSACTION WORKSWhen a user wants to pay gas in USDC instead of ETH:User signs a permit allowing the paymaster to transfer tokens (gasless approval using EIP-2612)User submits a UserOperation with paymasterData encoding the token address and Pyth price update dataValidation phase (_validatePaymasterUserOp): Verifies the pool exists and has sufficient ETH reserves Queries cached token/ETH price from Pyth oracle Calculates conservative prefund estimate including LP fees and rebalancing fees Transfers tokens from user to paymaster Returns context data for postOpEntryPoint executes the user's transaction, sponsored by the paymaster's ETHPostOp phase (_postOp): Updates Pyth price feeds with fresh off-chain data Recalculates actual gas cost using current prices Refunds excess tokens to user Updates pool accounting (decreases ETH reserves, increases token reserves)The two-phase pricing (cached for validation, fresh for settlement) prevents MEV and ensures users pay fair market rates while giving bundlers predictable validation.POOL MANAGEMENTAnyone can initialize a new token pool by calling initializePool with token address, Pyth feed ID, LP fee (basis points), and rebalancing fee (basis points). The contract uses ERC-6909 to track LP shares per pool, encoding the pool ID as uint256(uint160(tokenAddress)).Liquidity providers deposit ETH by calling deposit() with a specific pool ID. They receive ERC-6909 shares representing their portion of that pool's ETH reserves. Withdrawals burn shares and return proportional ETH.REBALANCING MECHANISMAs users pay gas in tokens, pools accumulate tokens and deplete ETH reserves. The rebalance() function allows anyone to buy accumulated tokens at a discount (the rebalancingFeeBps). This creates an arbitrage opportunity: rebalancers deposit ETH, extract tokens below market price, and resell them elsewhere for profit. This keeps pools healthy without requiring active management.PYTH ORACLE INTEGRATIONPyth provides pull-based price feeds where off-chain price data is submitted on-chain only when needed. The paymaster stores two feed IDs: ETH/USD and the token's feed ID. During validation, we use the cached on-chain price. During postOp, we update both feeds with signed price data from Pyth's off-chain service and pay the update fee from the paymaster's balance.EIL CROSS-CHAIN INTEGRATIONFor cross-chain transactions, Open Paymaster handles origin chain gas while EIL's CrossChainPaymaster handles destination chain gas. A user paying USDC on Ethereum to send funds to Base only signs once. The origin transaction is sponsored by Open Paymaster (paid in USDC), which creates an EIL voucher request. An XLP fulfills the voucher on Base, and the destination transaction executes gaslessly from the user's perspective.FRONTEND & SDKThe frontend is Next.js 14 with TypeScript, using wagmi and viem for wallet interaction. The SDK abstracts the complexity: developers call paymasterClient.estimateUserOpGas(token) and the SDK queries Pyth feed IDs, fetches current prices, encodes paymasterData, and constructs the UserOperation.The system is fully permissionless with no admin keys, upgrade mechanisms, or pause functionality. Anyone can create pools, provide liquidity, or rebalance without permission.