A Gasless, Sponsored Stablecoin Implementation
Flux USD (FUSD) is an ERC-20 stablecoin designed to eliminate the friction of blockchain payments. By implementing meta-transaction standards (EIP-2771, EIP-2612, EIP-3009), FUSD allows users to send and receive tokens without holding ETH or paying gas fees directly.
This repository contains the smart contract implementation, deployment scripts, and test suites demonstrating the gasless workflow using a Relayer pattern.
Traditional stablecoins require users to hold native currency (ETH) to pay for transaction fees. This creates a significant onboarding barrier. FUSD solves this by shifting the gas burden to a "Sponsor" (Relayer).
Core Logic:
- Off-Chain Signature: The user signs a structured message (EIP-712) authorizing a transfer.
- Relayer Submission: A trusted relayer receives the signature and submits the transaction to the blockchain, paying the gas fees.
- On-Chain Verification: The FUSD contract verifies the signature and executes the transfer on behalf of the user.
- Standard ERC-20 Compliance: Fully compatible with wallets and exchanges.
- Meta-Transactions (EIP-2771): Native support for Trusted Forwarders (Relayers) to enable gas abstraction.
- Gasless Approvals (EIP-2612): Built-in
permitfunction allows modifying allowances via signatures. - Atomic Gasless Transfers (EIP-3009): Implements
transferWithAuthorizationfor one-step, "pay-as-digital-cash" payments without prior approval. - Secure Access Control: Uses OpenZeppelin's
Ownablefor minting and administrative tasks.
- Framework: Hardhat
- Language: Solidity ^0.8.20, TypeScript
- Libraries: OpenZeppelin Contracts v5.x
- Testing: Mocha, Chai, Ethers.js v6
- Node.js (v18 or later recommended)
- pnpm
Clone the repository and install dependencies:
git clone <repository-url>
cd <repository-directory>
pnpm installCompile the smart contracts:
pnpm compileRun the test suite to verify the gasless transfer logic. The tests simulate a full EIP-3009 flow where a user signs a message and a relayer executes it.
pnpm run testThis is the core feature for payments. Unlike permit + transferFrom (which requires two steps), transferWithAuthorization is atomic.
- TypeHash:
TransferWithAuthorization(address from,address to,uint256 value,uint256 validAfter,uint256 validBefore,bytes32 nonce) - Nonce Handling: Uses a unique 32-byte nonce to prevent replay attacks.
The contract inherits ERC2771Context. It overrides _msgSender() to ensure that when a Relayer calls the contract, the internal logic sees the original user as the sender, not the Relayer.