Skip to main content

VaultOsToken

Git Source

Inherits: VaultImmutables, VaultState, VaultEnterExit, IVaultOsToken

Author: StakeWise

Defines the functionality for minting OsToken

State Variables

_wad

uint256 private constant _wad = 1e18;

_hfLiqThreshold

uint256 private constant _hfLiqThreshold = 1e18;

_maxPercent

uint256 private constant _maxPercent = 1e18;

_disabledLiqThreshold

uint256 private constant _disabledLiqThreshold = type(uint64).max;

_osTokenVaultController

Note: oz-upgrades-unsafe-allow: state-variable-immutable

IOsTokenVaultController private immutable _osTokenVaultController;

_osTokenConfig

Note: oz-upgrades-unsafe-allow: state-variable-immutable

IOsTokenConfig internal immutable _osTokenConfig;

_osTokenVaultEscrow

Note: oz-upgrades-unsafe-allow: state-variable-immutable

IOsTokenVaultEscrow private immutable _osTokenVaultEscrow;

_positions

mapping(address => OsTokenPosition) private _positions;

__gap

This empty reserved space is put in place to allow future versions to add new variables without shifting down storage in the inheritance chain. See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps

uint256[50] private __gap;

Functions

constructor

Constructor

Since the immutable variable value is stored in the bytecode, its value would be shared among all proxies pointing to a given contract instead of each proxy’s storage.

Note: oz-upgrades-unsafe-allow: constructor

constructor(address osTokenVaultController, address osTokenConfig, address osTokenVaultEscrow);

Parameters

NameTypeDescription
osTokenVaultControlleraddressThe address of the OsTokenVaultController contract
osTokenConfigaddressThe address of the OsTokenConfig contract
osTokenVaultEscrowaddressThe address of the OsTokenVaultEscrow contract

osTokenPositions

Get total amount of minted osToken shares

function osTokenPositions(address user) public view override returns (uint128 shares);

Parameters

NameTypeDescription
useraddressThe address of the user

Returns

NameTypeDescription
sharesuint128The number of minted osToken shares

mintOsToken

Mints OsToken shares

function mintOsToken(address receiver, uint256 osTokenShares, address referrer)
public
virtual
override
returns (uint256 assets);

Parameters

NameTypeDescription
receiveraddressThe address that will receive the minted OsToken shares
osTokenSharesuint256The number of OsToken shares to mint to the receiver. To mint the maximum amount of shares, use 2^256 - 1.
referreraddressThe address of the referrer

Returns

NameTypeDescription
assetsuint256The number of assets minted to the receiver

burnOsToken

Burns osToken shares

function burnOsToken(uint128 osTokenShares) external override returns (uint256 assets);

Parameters

NameTypeDescription
osTokenSharesuint128The number of shares to burn

Returns

NameTypeDescription
assetsuint256The number of assets burned

liquidateOsToken

Liquidates a user position and returns the number of received assets. Can only be called when health factor is below 1 by the liquidator.

function liquidateOsToken(uint256 osTokenShares, address owner, address receiver) external override;

Parameters

NameTypeDescription
osTokenSharesuint256The number of shares to cover
owneraddressThe address of the position owner to liquidate
receiveraddressThe address of the receiver of the liquidated assets

redeemOsToken

Redeems osToken shares for assets. Can only be called when health factor is above redeemFromHealthFactor by the redeemer.

function redeemOsToken(uint256 osTokenShares, address owner, address receiver) external override;

Parameters

NameTypeDescription
osTokenSharesuint256The number of osToken shares to redeem
owneraddressThe address of the position owner to redeem from
receiveraddressThe address of the receiver of the redeemed assets

transferOsTokenPositionToEscrow

Transfers minted osToken shares to the OsTokenVaultEscrow contract, enters the exit queue for staked assets

function transferOsTokenPositionToEscrow(uint256 osTokenShares) external override returns (uint256 positionTicket);

Parameters

NameTypeDescription
osTokenSharesuint256The number of osToken shares to transfer

Returns

NameTypeDescription
positionTicketuint256The exit position ticket

enterExitQueue

Locks shares to the exit queue. The shares continue earning rewards until they will be burned by the Vault.

function enterExitQueue(uint256 shares, address receiver)
public
virtual
override(IVaultEnterExit, VaultEnterExit)
returns (uint256 positionTicket);

Parameters

NameTypeDescription
sharesuint256The number of shares to lock
receiveraddressThe address that will receive assets upon withdrawal

Returns

NameTypeDescription
positionTicketuint256The position ticket of the exit queue. Returns uint256 max if no ticket created.

_mintOsToken

Internal function for minting osToken shares

function _mintOsToken(address owner, address receiver, uint256 osTokenShares, address referrer)
internal
returns (uint256 assets);

Parameters

NameTypeDescription
owneraddressThe owner of the osToken position
receiveraddressThe receiver of the osToken shares
osTokenSharesuint256The amount of osToken shares to mint
referreraddressThe address of the referrer

Returns

NameTypeDescription
assetsuint256The amount of assets minted

_redeemOsToken

Internal function for redeeming and liquidating osToken shares

function _redeemOsToken(address owner, address receiver, uint256 osTokenShares, bool isLiquidation)
private
returns (uint256 burnedShares, uint256 receivedAssets);

Parameters

NameTypeDescription
owneraddressThe minter of the osToken shares
receiveraddressThe receiver of the assets
osTokenSharesuint256The amount of osToken shares to redeem or liquidate
isLiquidationboolWhether the liquidation or redemption is being performed

Returns

NameTypeDescription
burnedSharesuint256The amount of shares burned
receivedAssetsuint256The amount of assets received

_syncPositionFee

Internal function for syncing the osToken fee

function _syncPositionFee(OsTokenPosition memory position) private view;

Parameters

NameTypeDescription
positionOsTokenPositionThe position to sync the fee for

_checkOsTokenPosition

Internal function for checking position validity. Reverts if it is invalid.

function _checkOsTokenPosition(address user) internal view;

Parameters

NameTypeDescription
useraddressThe address of the user

_calcMaxOsTokenShares

Internal function for calculating the maximum amount of osToken shares that can be minted

function _calcMaxOsTokenShares(uint256 assets) internal view returns (uint256);

Parameters

NameTypeDescription
assetsuint256The amount of assets to convert to osToken shares

Returns

NameTypeDescription
<none>uint256maxOsTokenShares The maximum amount of osToken shares that can be minted