pub struct TotalShares(/* private fields */);Expand description
This struct wraps the VirtualOffset struct with [TOTAL_SHARES] storage features
checked_add_shares and checked_sub_shares implemented.
Other methods are mapped to the underlying VirtualOffset instance.
TotalShares is only used to account for the total shares (and total assets). Individual staker shares are stored here to allow for different staking strategies (e.g., Tokenized Vault).
Implementations§
Sourcepub fn load(deps: &Deps<'_>, total_assets: Uint128) -> StdResult<Self>
pub fn load(deps: &Deps<'_>, total_assets: Uint128) -> StdResult<Self>
Load the virtual total shares from storage (supports rebasing, by default).
A fixed [OFFSET] of 1 will be added to both total shares and total assets
to mitigate against inflation attack.
Use [shares_to_assets] and [assets_to_shares] to convert between shares and assets.
Shares to underlying assets
Underlying assets to shares
Get the total shares in circulation
Sourcepub fn total_assets(&self) -> Uint128
pub fn total_assets(&self) -> Uint128
Get the total assets under management
Add the new shares to the total shares and refresh the virtual shares and virtual assets. This method is checked:
- New shares cannot be zero.
- Total shares cannot overflow.
- Virtual shares cannot overflow.
Subtract the shares from the total shares and refresh the virtual shares and virtual assets.
Trait Implementations§
Auto Trait Implementations§
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more