pub struct VirtualOffset { /* private fields */ }Expand description
Follows the OpenZeppelin’s ERC4626 mitigation strategy for inflation attack. Using a “virtual” offset to +1 to both total shares and assets representing the virtual total shares and virtual total assets. A donation of 1 and under will be completely captured by the vault—without affecting the user. A donation greater than 1, the attacker will suffer loss greater than the user. [https://github.com/OpenZeppelin/openzeppelin-contracts/blob/fa995ef1fe66e1447783cb6038470aba23a6343f/contracts/token/ERC20/extensions/ERC4626.sol#L30-L37]
Implementations§
Source§impl VirtualOffset
impl VirtualOffset
Sourcepub fn new(total_shares: Uint128, total_assets: Uint128) -> StdResult<Self>
pub fn new(total_shares: Uint128, total_assets: Uint128) -> StdResult<Self>
Create a new VirtualOffset with the given total shares and total 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
Trait Implementations§
Auto Trait Implementations§
impl Freeze for VirtualOffset
impl RefUnwindSafe for VirtualOffset
impl Send for VirtualOffset
impl Sync for VirtualOffset
impl Unpin for VirtualOffset
impl UnwindSafe for VirtualOffset
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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