|
| 1 | +--- |
| 2 | +title: Contract |
| 3 | +--- |
| 4 | + |
| 5 | +# Contract |
| 6 | + |
| 7 | +The stack for ULST consists of four contracts: 1. LsdNetworkFactory, an utility contract which deploys project contracts by a single call; 2. LsdToken, an ERC20-compatible token which represents users' receipt of their staking; 3. StakePool, delegates stablecoin assets to Ondo Finance for RWA token subscription; 4. StakeManager, manages project internal and external states and interacts with users. |
| 8 | + |
| 9 | +The ULST system integrates with Real World Assets (RWA) through Ondo Finance, enabling users to deposit stablecoins and receive liquid staking derivative tokens that generate yield through RWA investments. |
| 10 | + |
| 11 | +## LsdNetworkFactory.sol |
| 12 | + |
| 13 | +The `LsdNetworkFactory` is a utility contract that simplifies the deployment of new LSD networks. Instead of manually deploying multiple contracts, you can use the factory to create a complete LSD network with a single transaction. |
| 14 | + |
| 15 | +Network Contracts Structure |
| 16 | + |
| 17 | +```solidity |
| 18 | +struct NetworkContracts { |
| 19 | + address _stakeManager; |
| 20 | + address _stakePool; |
| 21 | + address _lsdToken; |
| 22 | + uint256 _block; |
| 23 | +} |
| 24 | +``` |
| 25 | + |
| 26 | +Events |
| 27 | + |
| 28 | +```solidity |
| 29 | +event LsdNetwork(NetworkContracts contracts); |
| 30 | +``` |
| 31 | + |
| 32 | +### createLsdNetwork() |
| 33 | + |
| 34 | +Creates a new LSD network with immediate admin control. |
| 35 | + |
| 36 | +```solidity |
| 37 | +function createLsdNetwork( |
| 38 | + string memory _lsdTokenName, |
| 39 | + string memory _lsdTokenSymbol, |
| 40 | + address _govInstantManagerAddress, |
| 41 | + address _govOracleAddress, |
| 42 | + address[] memory _stablecoins |
| 43 | +) external |
| 44 | +``` |
| 45 | + |
| 46 | +**Parameters:** |
| 47 | +- `_lsdTokenName` - Name of the LSD token (e.g., "StaFi rULST") |
| 48 | +- `_lsdTokenSymbol` - Symbol of the LSD token (e.g., "rULST") |
| 49 | +- `_govInstantManagerAddress` - Ondo Instant Manager contract address for RWA operations |
| 50 | +- `_govOracleAddress` - Ondo Oracle contract address for RWA price feeds |
| 51 | +- `_stablecoins` - Array of supported stablecoin addresses (USDC, PYUSD, etc.) |
| 52 | + |
| 53 | +### createLsdNetworkWithTimelock() |
| 54 | + |
| 55 | +Creates a new LSD network with timelock governance for enhanced security. |
| 56 | + |
| 57 | +```solidity |
| 58 | +function createLsdNetworkWithTimelock( |
| 59 | + string memory _lsdTokenName, |
| 60 | + string memory _lsdTokenSymbol, |
| 61 | + address _govInstantManagerAddress, |
| 62 | + address _govOracleAddress, |
| 63 | + address[] memory _stablecoins, |
| 64 | + uint256 minDelay, |
| 65 | + address[] memory proposers |
| 66 | +) external |
| 67 | +``` |
| 68 | + |
| 69 | +**Additional Parameters:** |
| 70 | +- `minDelay` - Minimum delay for timelock operations (in seconds) |
| 71 | +- `proposers` - Array of addresses who can submit timelock proposals |
| 72 | + |
| 73 | +## StakeManager.sol |
| 74 | + |
| 75 | +The `StakeManager` is the main orchestration contract that manages the entire staking lifecycle and coordinates between users and the underlying RWA protocols. |
| 76 | + |
| 77 | +### Stakers methods |
| 78 | + |
| 79 | +`stake`: Allows users to deposit stablecoins and receive LSD tokens. |
| 80 | + |
| 81 | +- `stablecoin` - Address of the stablecoin to stake (USDC, PYUSD) |
| 82 | +- `amount` - Amount of stablecoin to stake |
| 83 | + |
| 84 | +```solidity |
| 85 | +function stake(address _stablecoin, uint256 _amount) |
| 86 | +``` |
| 87 | + |
| 88 | +`unstake`: Allows users to initiate unstaking by burning LSD tokens. |
| 89 | + |
| 90 | +- `_stablecoin` - Address of the stablecoin to unstake (USDC, PYUSD) |
| 91 | +- `_lsdTokenAmount` - Amount of LSD tokens to unstake |
| 92 | + |
| 93 | +```solidity |
| 94 | +function unstake(address _stablecoin, uint256 _lsdTokenAmount) |
| 95 | +``` |
| 96 | + |
| 97 | + |
| 98 | +`withdraw`: Allows users to withdraw stablecoins after the unbonding period. |
| 99 | + |
| 100 | +```solidity |
| 101 | +function withdraw() external |
| 102 | +``` |
| 103 | + |
| 104 | +### Administrative methods |
| 105 | + |
| 106 | +- `addStablecoin` - Add a new supported stablecoin to the system |
| 107 | +- `rmStablecoin` - Remove a stablecoin from the supported list |
| 108 | +- `setIsUnstakePaused` - Pause or resume unstaking operations |
| 109 | +- `addStakePool` - Add a new stake pool to the network |
| 110 | +- `withdrawProtocolFee` - Withdraw accumulated protocol fees |
| 111 | + |
| 112 | +### Parameters adjustment methods |
| 113 | + |
| 114 | +- `setProtocolFeeCommission` - Set the protocol fee rate for reward distribution |
| 115 | +- `setFactoryFeeCommission` - Set the factory fee rate for protocol fees |
| 116 | +- `setEraParams` - Configure era duration and timing parameters |
| 117 | +- `setRateChangeLimit` - Set maximum allowed exchange rate change per era |
| 118 | +- `setMinStakeAmount` - Set minimum stake amount threshold |
| 119 | +- `setUnbondingDuration` - Set unbonding period duration in eras |
| 120 | +- `setUnstakeFee` - Set fee rate for unstaking operations |
| 121 | + |
| 122 | + |
| 123 | +### Era Method |
| 124 | + |
| 125 | +Triggers era progression and processes pending operations. This is a permissionless function that can be called by anyone once sufficient time has elapsed. |
| 126 | + |
| 127 | +The `newEra()` function executes a multi-phase pipeline that processes all bonded pools in the network: |
| 128 | + |
| 129 | +1. Era Validation: Calculates next era number and validates sufficient time has passed |
| 130 | +2. Delegation Processing: Delegates accumulated stablecoins to Ondo Finance for RWA token subscription |
| 131 | +3. Undelegation Processing: Redeems RWA tokens back to stablecoins for pending withdrawals |
| 132 | +4. Reward Calculation: Calculates rewards from RWA token appreciation |
| 133 | +5. Rate Updates: Updates exchange rates based on total RWA value vs LSD supply |
| 134 | +6. Protocol Fee Distribution: Distributes protocol fees from newly earned rewards |
| 135 | + |
| 136 | +**Rate Calculation:** |
| 137 | +``` |
| 138 | +if (totalLst == 0 || totalActive < totalLst): |
| 139 | + return 1e18 |
| 140 | +else: |
| 141 | + calRate = (totalActive * 1e18) / totalLst |
| 142 | +``` |
| 143 | + |
| 144 | +**Events Emitted:** |
| 145 | +- `ExecuteNewEra(uint256 indexed era, uint256 rate)` - Era transition and new exchange rate |
| 146 | +- `NewReward(address poolAddress, uint256 newReward)` - Rewards earned by each pool |
| 147 | +- `GovRedeemFee(address pool, address stablecoin, uint256 amount)` - Ondo redemption fees |
0 commit comments