ElUSDStake
Inherits: ElaraBase, IElUSDStake
Title: ElUSD Stake Contract
Staking contract that converts ElUSD to sElUSD shares
Implements share-based staking with no lock periods or NFTs Invariants:
Exchange rate between ElUSD and sElUSD is determined by totalElUSD / totalSElUSD
Users can stake and unstake at any time (permissionless)
First staker gets 1:1 ratio, subsequent stakes use the current exchange rate
Treasury can deposit yield to increase share value without minting new shares Upgradeability:
Uses ElaraBase for UUPS upgradeability
Initializer must be called exactly once; preserve storage layout
Note: security-contact: [email protected]
State Variables
_elUSD
ElUSD token contract
IElUSD internal _elUSD_sElUSD
sElUSD token contract
_vault
Vault contract address (only vault can call receiveYield)
__gap
Reserved storage gap for future upgrades to prevent storage collisions
Functions
initialize
Security:
Only callable during initialization via {initializer} modifier
Validates non-zero addresses for all parameters (vault can be zero and set later)
Establishes access control via {__ElaraBase_init}
Critical for contract initialization; must be called exactly once per proxy
Parameters
_accessManager
address
Address of the AccessManager contract
elUSDAddress
address
Address of the ElUSD token
sElUSDAddress
address
Address of the sElUSD token
vaultAddress
address
Address of the Vault contract (can be zero)
stake
Security:
Uses {whenNotPaused} from ElaraBase to prevent staking when paused
Uses {nonReentrant} from ElaraBase to prevent reentrancy attacks
Follows checks-effects-interactions pattern
Transfers ElUSD from user before minting sElUSD to prevent reentrancy
unstake
Security:
Uses {whenNotPaused} from ElaraBase to prevent unstaking when paused
Uses {nonReentrant} from ElaraBase to prevent reentrancy attacks
Follows checks-effects-interactions pattern
Burns sElUSD before transferring ElUSD to prevent reentrancy
receiveYield
Security:
Only callable by Vault contract
Uses {nonReentrant} from ElaraBase to prevent reentrancy attacks
Does NOT transfer ElUSD (already minted to this contract by Vault)
Share price increases automatically due to increased ElUSD balance
Emits {YieldReceived} event with new share price
elUSD
sElUSD
vault
setVaultAddress
Security:
Uses {restricted} modifier to allow only authorized callers (admin role)
Can be called after initialization to resolve circular dependency with Vault
totalElUSD
sharePrice
Returns the current price per sElUSD share in ElUSD
If no shares exist, returns 1e18 (1:1 ratio)
Otherwise: price = (totalElUSD * 1e18) / totalSupply
previewStake
Implements ERC4626-style share calculation
If no sElUSD exists, mints 1:1
Otherwise: shares = (amount * totalSupply) / totalAssets
previewUnstake
Implements ERC4626-style asset calculation
amount = (shares * totalAssets) / totalSupply
Last updated
Was this helpful?