pub struct LiquidStakingPool { /* private fields */ }Expand description
Liquid staking pool manager
Manages the stTNZO liquid staking derivative for Tenzro Network.
Implementations§
Source§impl LiquidStakingPool
impl LiquidStakingPool
Sourcepub fn new(config: LiquidStakingConfig) -> Result<Self>
pub fn new(config: LiquidStakingConfig) -> Result<Self>
Create a new liquid staking pool
Sourcepub fn with_storage(
config: LiquidStakingConfig,
storage: Arc<dyn KvStore>,
) -> Result<Self>
pub fn with_storage( config: LiquidStakingConfig, storage: Arc<dyn KvStore>, ) -> Result<Self>
Create a liquid staking pool with persistent backing in CF_TOKENS.
Hydrates config, aggregate totals, per-holder balances, validator
delegations, and pending withdrawal requests on construction.
Sourcepub fn update_config(&self, new_config: LiquidStakingConfig) -> Result<()>
pub fn update_config(&self, new_config: LiquidStakingConfig) -> Result<()>
Update the config (governance-driven). Validates and persists.
Sourcepub fn exchange_rate(&self) -> u128
pub fn exchange_rate(&self) -> u128
Get the current exchange rate: TNZO per stTNZO.
exchange_rate = total_underlying_wei / total_sttnzo_supply
Returns the rate as a fixed-point number with 18 decimals.
A rate of 1_000_000_000_000_000_000 (10^18) means 1:1.
Sourcepub fn deposit(&self, depositor: Address, tnzo_amount: u128) -> Result<u128>
pub fn deposit(&self, depositor: Address, tnzo_amount: u128) -> Result<u128>
Deposit TNZO and receive stTNZO.
The amount of stTNZO minted is calculated from the current exchange rate:
sttnzo_amount = tnzo_amount * 10^18 / exchange_rate
Sourcepub fn request_withdrawal(
&self,
requester: Address,
sttnzo_amount: u128,
) -> Result<WithdrawalRequest>
pub fn request_withdrawal( &self, requester: Address, sttnzo_amount: u128, ) -> Result<WithdrawalRequest>
Request withdrawal: burn stTNZO and start unbonding.
The TNZO amount is calculated from the current exchange rate at request time. User must wait the unbonding period before claiming.
Sourcepub fn claim_withdrawal(&self, request_id: &str) -> Result<(Address, u128)>
pub fn claim_withdrawal(&self, request_id: &str) -> Result<(Address, u128)>
Claim a completed withdrawal after the unbonding period.
Returns the TNZO amount to transfer to the user.
Sourcepub fn distribute_rewards(
&self,
reward_amount: u128,
) -> Result<RewardDistribution>
pub fn distribute_rewards( &self, reward_amount: u128, ) -> Result<RewardDistribution>
Distribute staking rewards to the pool.
This is called by the reward distributor when staking rewards are earned. The rewards increase the exchange rate (underlying TNZO goes up, stTNZO supply stays the same).
Sourcepub fn balance_of(&self, address: &Address) -> u128
pub fn balance_of(&self, address: &Address) -> u128
Get stTNZO balance for an address
Sourcepub fn tnzo_value(&self, sttnzo_amount: u128) -> u128
pub fn tnzo_value(&self, sttnzo_amount: u128) -> u128
Get the TNZO value of a stTNZO amount at the current exchange rate
Sourcepub fn stats(&self) -> LiquidStakingStats
pub fn stats(&self) -> LiquidStakingStats
Get pool statistics
Sourcepub fn add_validator(&self, validator: Address, amount: u128)
pub fn add_validator(&self, validator: Address, amount: u128)
Add a validator delegation
Sourcepub fn validator_delegations(&self) -> Vec<(Address, u128)>
pub fn validator_delegations(&self) -> Vec<(Address, u128)>
Get all validator delegations
Sourcepub fn transfer(&self, from: &Address, to: &Address, amount: u128) -> Result<()>
pub fn transfer(&self, from: &Address, to: &Address, amount: u128) -> Result<()>
Transfer stTNZO between addresses
Sourcepub fn pending_withdrawals_for(
&self,
holder: &Address,
) -> Vec<WithdrawalRequest>
pub fn pending_withdrawals_for( &self, holder: &Address, ) -> Vec<WithdrawalRequest>
List all pending (unclaimed) withdrawal requests for a holder.
Sourcepub fn get_withdrawal(&self, request_id: &str) -> Option<WithdrawalRequest>
pub fn get_withdrawal(&self, request_id: &str) -> Option<WithdrawalRequest>
Look up a single withdrawal request by ID.
Sourcepub fn config(&self) -> LiquidStakingConfig
pub fn config(&self) -> LiquidStakingConfig
Read a snapshot of the current liquid staking config.