melonask/viem-sweep-skills
Overview
This skill is a practical guide and reference for implementing advanced sweeping and transaction strategies with viem v2. It consolidates patterns for moving tokens and assets using Legacy, Factory (CREATE2), Permit (EIP-2612), Auth (EIP-3009), and EIP-7702 delegation flows. Use it to design gas-optimized, gasless, or delegated sweeping pipelines that fit your infrastructure and tokens.
How this skill works
The skill explains how each strategy constructs and executes transfers: direct private-key sends, factory address prediction and deploy+flush, off-chain permit or authorization signatures submitted by a relayer, and delegation-based execution for temporary contract-like behavior. It identifies required clients (PublicClient for simulation and WalletClient for signing/sending), necessary ABIs, and typical transaction sequencing. Implementation guidance includes signature formats, nonce handling, and batching patterns for high-throughput sweeps.
When to use it
- You control source private keys and need a simple, universal solution (Legacy).
- You manage many deposit addresses and need minimal per-address gas (Factory/CREATE2).
- You want gasless UX where users sign permits instead of paying gas (EIP-2612).
- Your token supports TransferWithAuthorization and you need non-sequential nonce handling (EIP-3009).
- You want temporary delegation so EOAs can behave like contracts for batching or sponsored gas (EIP-7702).
Best practices
- Simulate all flows with PublicClient before submitting to mainnet to catch revert reasons and gas estimates.
- Prefer Factory for high-volume, predictable address models to minimize per-account gas overhead.
- Validate token compatibility first: confirm EIP-2612 or EIP-3009 support before building permit/auth flows.
- Store and verify off-chain signatures with expiration and replay protections; enforce nonce or unique id checks.
- Bundle multiple moves into single batched transactions where supported to reduce gas and on-chain operations.
Example use cases
- Exchange deposit sweep: use Factory addresses and a single flush transaction to move balances to custodial wallets.
- Mobile dApp gasless payout: have users sign EIP-2612 permits and a relayer submit batched transfers.
- USDC payroll distribution: collect EIP-3009 authorizations and execute a multi-transfer run without user gas.
- Account recovery/upgrade: use EIP-7702 delegation to temporarily grant contract-like powers to an EOA for migration or batched operations.
- Periodic dust cleanup: legacy sweeps funded by an admin wallet to consolidate small ERC20 balances.
FAQ
Fallback to Legacy or Factory strategies; Factory reduces per-address gas if you control address generation, otherwise Legacy direct transfers are universal.
How do I choose between Permit and Auth?
Choose Permit (EIP-2612) when the token implements that standard for approval-based gasless transfers; choose Auth (EIP-3009) for tokens offering TransferWithAuthorization semantics like USDC, especially when nonce ordering is non-sequential.