Smart Accounts
ERC-4337 Account Abstraction with modular validation and gas sponsorship
Smart Accounts
ERC-4337 compliant smart contract wallets with modular validation, session keys, and gas sponsorship via paymasters.
Overview
Smart Account
Core smart account contract with modular architecture
Factory
Deploy and manage smart account instances
Modules
Session keys, validation rules, and extensions
Paymasters
Gas sponsorship and ERC20 gas payment
Architecture
┌─────────────────────────────────────────────────────────────────────────┐
│ Account Abstraction (ERC-4337) │
├─────────────────────────────────────────────────────────────────────────┤
│ EntryPoint │
│ (Central contract that validates and executes UserOps) │
├───────────────┬───────────────────────────────────────┬─────────────────┤
│ Smart Account│ Modules │ Paymaster │
│ ┌───────────┐│ ┌─────────────┐ ┌───────────────┐ │ ┌───────────┐ │
│ │ Proxy ││ │Session Keys │ │ Passkey Valid │ │ │ Verifying │ │
│ ├───────────┤│ └─────────────┘ └───────────────┘ │ │ Paymaster │ │
│ │ Base ││ ┌─────────────┐ ┌───────────────┐ │ ├───────────┤ │
│ │ Account ││ │ Batched │ │ Social │ │ │ ERC20 │ │
│ ├───────────┤│ │ Session │ │ Recovery │ │ │ Payment │ │
│ │ Executor ││ └─────────────┘ └───────────────┘ │ └───────────┘ │
│ ├───────────┤│ │ │
│ │ Module ││ │ │
│ │ Manager ││ │ │
│ └───────────┘│ │ │
└───────────────┴──────────────────────────────────────┴─────────────────┘
│
▼
┌───────────────────────────────┐
│ Bundler │
│ (Off-chain UserOp relayer) │
└───────────────────────────────┘Key Concepts
UserOperation
The core data structure for account abstraction:
struct UserOperation {
address sender; // Smart account address
uint256 nonce; // Anti-replay nonce
bytes initCode; // Factory calldata (if deploying)
bytes callData; // Execution calldata
uint256 callGasLimit; // Gas for execution
uint256 verificationGasLimit;// Gas for validation
uint256 preVerificationGas; // Gas for bundler
uint256 maxFeePerGas; // EIP-1559 max fee
uint256 maxPriorityFeePerGas;// EIP-1559 priority fee
bytes paymasterAndData; // Paymaster address + data
bytes signature; // Validation signature
}Validation Flow
1. User creates UserOperation
2. Signs with EOA or module
3. Bundler submits to EntryPoint
4. EntryPoint calls validateUserOp()
5. Smart Account validates signature
6. Paymaster validates (if used)
7. EntryPoint executes callData
8. Gas accounting and refundsQuick Start
import "@luxfi/standard/src/eoa/contracts/smart-account/SmartAccount.sol";
import "@luxfi/standard/src/eoa/contracts/smart-account/factory/SmartAccountFactory.sol";
// Deploy smart account via factory
SmartAccountFactory factory = SmartAccountFactory(FACTORY_ADDRESS);
address smartAccount = factory.deployCounterFactualAccount(
owner, // EOA owner
index // Salt for address derivation
);
// Execute transaction via smart account
SmartAccount(smartAccount).execute(
target, // Contract to call
value, // ETH value
callData // Function calldata
);
// Batch execute multiple transactions
SmartAccount(smartAccount).executeBatch(
targets, // Array of addresses
values, // Array of values
calldatas // Array of calldatas
);Core Contracts
| Contract | Description |
|---|---|
| SmartAccount | Main account implementation |
| SmartAccountFactory | Deploys new smart accounts |
| EntryPoint | ERC-4337 entry point |
| Proxy | UUPS upgradeable proxy |
| ModuleManager | Manages installed modules |
| Executor | Executes calls and delegatecalls |
| FallbackManager | Handles fallback calls |
Module Types
| Module | Purpose |
|---|---|
| Session Keys | Time/value-limited signing keys |
| Batched Sessions | Multiple operations per session |
| Passkey Validation | WebAuthn/FIDO2 authentication |
| Social Recovery | Guardian-based account recovery |
Benefits
- No ETH Required: Paymasters sponsor gas
- Batch Transactions: Execute multiple ops atomically
- Session Keys: Grant limited permissions to dapps
- Social Recovery: Recover access via guardians
- Upgradeable: Update account logic via UUPS
- Modular: Add/remove features via modules
Integration
With Lending Pools
// Session key for automated position management
bytes memory sessionData = abi.encode(
lendingPool, // Target contract
0, // No ETH
"repay(uint256)", // Allowed function
block.timestamp + 1 days // Expiry
);
// Grant session key
account.enableModule(sessionKeyModule);With AMM
// Batch: approve + swap in one tx
address[] memory targets = new address[](2);
uint256[] memory values = new uint256[](2);
bytes[] memory calldatas = new bytes[](2);
targets[0] = WLUX;
calldatas[0] = abi.encodeWithSignature("approve(address,uint256)", router, amount);
targets[1] = router;
calldatas[1] = abi.encodeWithSignature(
"swapExactTokensForTokens(uint256,uint256,address[],address)",
amount, minOut, path, address(account)
);
account.executeBatch(targets, values, calldatas);Related
- Smart Account - Core account contract
- Factory - Account deployment
- Modules - Session keys and validation
- Paymasters - Gas sponsorship
- Safe - Multi-signature wallet