FraxNetDeposit
Overview
FraxNetDeposit is a cross-chain deposit and redemption contract used in the FraxNet ecosystem. It enables the minting of frxUSD from USDC, and its transfer to another chain using LayerZero’s OFT mechanism. It also supports redemption of frxUSD to USDC through the USDC custodian and the RWA redeemer, and sends the USDC to the target chain.
A branded deposit contract does the same for a branded stablecoin: it mints the branded token instead of frxUSD, and redeems the branded token to USDC.
This contract serves as the implementation for EIP-1967 (opens in a new tab) Beacon Proxies deployed from the FraxNetDeposit Factory contract. The current implementation is FraxNetDepositV4, version 4.0.0.
Key Features
- Deposits USDC to mint frxUSD
- Sends frxUSD cross-chain via LayerZero
- Redeems frxUSD back to USDC and sends it to the target chain
- Integrates with Circle’s CCTP V2
- Supports branded stablecoins
- Anyone can process deposits and redemptions, and the factory can pause both
Initialization
constructor(address _factory)
function initialize(uint32 _targetEid, bytes32 _targetAddress, bytes32 _targetUsdcAtaAddress) external
function initialize(address _targetAsset, uint32 _targetEid, bytes32 _targetAddress, bytes32 _targetUsdcAtaAddress) public- Called once by the factory upon deployment. Other callers get
Forbidden, and a second call reverts withAlreadyInitialized. - Sets the target LayerZero endpoint ID, the target recipient address and, for Solana (
30168), the recipient's USDC associated token account. It reverts withAtaAccountNotInitializedif the target is Solana and_targetUsdcAtaAddressis zero. - The factory uses the 3-argument form for frxUSD deposit contracts and the 4-argument form for branded ones. The 4-argument form stores
_targetAssetand reads itscustodianandrouterfrom the factory'sbrandFactory. It reverts withNoAllowedForSiloedif the asset uses a siloed custodian. - The constructor sets the immutable
factoryand marks the implementation itself as initialized.
Constants
| Name | Type | Description |
|---|---|---|
frxUSD | IERC20 | frxUSD token address |
USDC | IERC20 | USDC token address |
oft | address | LayerZero OFT address for frxUSD |
STARGATE_USDCE_POOL | address | Stargate USDC pool used for Somnia redemptions |
State Variables
| Name | Type | Description |
|---|---|---|
wasInitialized | bool | Whether this contract has been initialized |
factory | IFraxNetDepositFactory | The factory contract that deployed this instance (immutable) |
targetEid | uint32 | Destination LayerZero endpoint ID |
targetAddress | bytes32 | Target address in bytes32 format on destination chain |
targetUsdcAtaAddress | bytes32 | Recipient's USDC associated token account if the target is Solana, otherwise zero |
router | address | Branded token's CrossChainRouter, zero for frxUSD deposit contracts |
custodian | address | Branded token's BrandedCustodian, zero for frxUSD deposit contracts |
Events
| Name | Description |
|---|---|
ProcessedDeposit | Emitted after successful USDC deposit and frxUSD (or branded token) send |
ProcessedRedemption | Emitted after successful frxUSD (or branded token) redemption to USDC |
Custom Errors
| Error | Description |
|---|---|
Forbidden() | Caller is not authorized |
InsufficientBalance() | Not enough tokens to complete the operation |
RefundFailed() | Refunding ETH to the caller failed |
CCTPNotConfiguredForThisChain() | No CCTP V2 messenger or CCTP domain configured for target chain |
AlreadyInitialized() | Initialization was already performed |
AtaAccountNotInitialized() | Target is Solana and the USDC token account is zero |
SizeTooLarge() | Deposit above 1,000,000 USDC, or redemption above what the custodian and RWA redeemer can cover |
Paused() | The factory has paused processing |
NoAllowedForSiloed() | Branded token uses a siloed custodian |
Functions
Deposit Flow
function processDeposit(uint256 amount) external payable returns (uint256 frxUSDOut)-
User must have previously sent USDC to their
FraxNetDepositcontract. The contract does not pull USDC from the caller. -
Anyone can call it. It reverts with
Pausedwhile the factory is paused, withSizeTooLargeifamountis above 1,000,000 USDC, and withInsufficientBalanceif the contract holds less thanamountUSDC. -
Deposits the USDC into the factory's
frxUSDCustodianto mintfrxUSD. -
Sends frxUSD to
targetAddressvia:- Direct transfer (if Ethereum)
- LayerZero OFT through the factory's
remoteHop(if other chains), withmsg.valuepaying the fee fromquote
-
Branded deposit contracts mint the branded token instead, through its
BrandedCustodiantotargetAddress(if Ethereum) or through itsCrossChainRouter, which bridges the frxUSD and mints on the target chain (if other chains). -
Refunds the contract's entire ETH balance to the caller.
Redemption Flow
function processRedemption(uint256 amount) external payable returns (uint256 usdcOut)-
User must have previously sent frxUSD, or the branded token, to their
FraxNetDepositcontract. -
Anyone can call it. It reverts with
Pausedwhile the factory is paused, and withInsufficientBalanceif the contract holds less thanamountfrxUSD. -
Branded deposit contracts first redeem
amountof the branded token for frxUSD through itsBrandedCustodian. -
Redeems
frxUSDforUSDCusing:- The factory's
frxUSDCustodian, up to the amount it can currently redeem - The factory's
rwaRedeemer(RWA Redemption Coordinator) for the remainder - It reverts with
SizeTooLargeif the two together cannot coveramount
- The factory's
-
Sends USDC to target:
- Direct transfer to
targetAddress(if Ethereum) - Stargate's USDC pool,
STARGATE_USDCE_POOL(if Somnia,30380).msg.valuepays the LayerZero fee, which the pool'squoteSendreturns, and the pool refunds any excess to the caller. - Circle CCTP V2 (if other chains):
depositForBurnthrough the factory'scctpTokenMessengerV2, to the CCTP domain ineidToCCTPDomain. It is a standard transfer (maxFee0,minFinalityThreshold2000) with nodestinationCaller, so anyone can complete the mint on the target chain. The mint recipient istargetAddress, ortargetUsdcAtaAddressif the target is Solana (30168). It reverts withCCTPNotConfiguredForThisChainif the messenger or the domain is not set, or withAtaAccountNotInitializedif the recipient is zero, and refunds the contract's entire ETH balance to the caller.
- Direct transfer to
Quoting
function quote(uint256 amount) external view returns (IRemoteHop.MessagingFee memory)- Returns the LayerZero fee for
processDeposit(amount)innativeFee. It previews the frxUSD minted fromamountUSDC and quotes the factory'sremoteHopor, for branded deposit contracts, the brandedCrossChainRouter. - Deposits to Ethereum need no fee.
Admin
function recoverERC20(address tokenAddress, uint256 tokenAmount, address recipient) external
function setBrandedRouter(address _router) external
function setBrandedCustodian(address _custodian) externalrecoverERC20can only be called by the factory, which lets the factory owner recover ERC20 tokens.setBrandedRouterandsetBrandedCustodianlet the factory owner replace the brandedrouterandcustodianset at initialization.
Utility Functions
function asset() external view returns (address)
function version() external pure returns (uint256 major, uint256 minor, uint256 patch)
function scaleUpTo1e18(uint256 amount1e6) public pure returns (uint256)
function scaleDownTo1e6(uint256 amount1e18) public pure returns (uint256)assetreturns the branded token for branded deposit contracts, andfrxUSDotherwise.versionreturns4.0.0.- Helper conversions between
1e6and1e18decimal representations.
Dependencies
FraxNetDepositFactoryIRemoteHop,IFrxUSDCustodian,IRWAUSDCRedeemer,ITokenMessenger,IStargatePoolUSDCIBrandedFactory,IBrandedCustodian,IRouterfor branded stablecoins
Notes
- Factory is used for access control (e.g. pausing, recovering tokens) and holds the shared configuration: custodian, RemoteHop, RWA redeemer, CCTP V2 messenger and CCTP domains
- Redemptions use the USDC custodian's liquidity first and the RWA redeemer for the rest
- Emits an event for every processed deposit or redemption
- Calls that refund ETH send the contract's entire ETH balance to the caller, so only send ETH as
msg.valueon a call that pays a fee
Author: Frax Finance License: AGPL-3.0-only