Skip to main content

OsTokenRedeemer

Git Source ↗

Inherits: Ownable2Step ↗, Multicall, IOsTokenRedeemer

This contract is used to redeem OsTokens for the underlying asset.

State Variables

_vaultsRegistry

IVaultsRegistry private immutable _vaultsRegistry

_osToken

IERC20 private immutable _osToken

_osTokenVaultController

IOsTokenVaultController private immutable _osTokenVaultController

exitQueueUpdateDelay

The delay in seconds for the exit queue updates

uint256 public immutable override exitQueueUpdateDelay

positionsManager

The address authorized to redeem OsToken positions

address public override positionsManager

nonce

The current nonce for the redemptions

uint256 public override nonce

queuedShares

The number of queued OsToken shares

uint128 public override queuedShares

unclaimedAssets

The number of unclaimed assets in the exit queue

uint128 public override unclaimedAssets

redeemedShares

The number of redeemed OsToken shares

uint128 public override redeemedShares

redeemedAssets

The number of redeemed assets

uint128 public override redeemedAssets

swappedShares

The number of swapped OsToken shares

uint128 public override swappedShares

swappedAssets

The number of swapped assets

uint128 public override swappedAssets

leafToProcessedShares

mapping(bytes32 leaf => uint256 processedShares) public override leafToProcessedShares

exitRequests

mapping(bytes32 exitRequestHash => uint256 shares) public override exitRequests

exitQueueTimestamp

The timestamp when the exit queue was last updated

uint256 public override exitQueueTimestamp

_redeemablePositions

RedeemablePositions private _redeemablePositions

_exitQueue

ExitQueue.History private _exitQueue

Functions

constructor

Constructor

constructor(
address vaultsRegistry_,
address osToken_,
address osTokenVaultController_,
address owner_,
uint256 exitQueueUpdateDelay_
) Ownable(owner_);

Parameters

NameTypeDescription
vaultsRegistry_addressThe address of the VaultsRegistry contract
osToken_addressThe address of the OsToken contract
osTokenVaultController_addressThe address of the OsTokenVaultController contract
owner_addressThe address of the owner
exitQueueUpdateDelay_uint256The delay in seconds for exit queue updates

getExitQueueData

Get the current exit queue data

function getExitQueueData() public view override returns (uint256, uint256, uint256);

Returns

NameTypeDescription
<none>uint256queuedShares The total number of shares currently queued for exit
<none>uint256unclaimedAssets The total number of assets that have not been claimed yet
<none>uint256totalTickets The total number of tickets (shares) processed in the exit queue

getExitQueueCumulativeTickets

Gets the cumulative tickets in the exit queue

function getExitQueueCumulativeTickets() external view override returns (uint256);

Returns

NameTypeDescription
<none>uint256The cumulative tickets in the exit queue

redeemablePositions

The current redeemable positions Merkle root and IPFS hash

function redeemablePositions() external view override returns (bytes32 merkleRoot, string memory ipfsHash);

Returns

NameTypeDescription
merkleRootbytes32The Merkle root of the redeemable positions
ipfsHashstringThe IPFS hash of the redeemable positions

getExitQueueIndex

Gets the index of the exit queue for a given position ticket.

function getExitQueueIndex(uint256 positionTicket) external view override returns (int256);

Parameters

NameTypeDescription
positionTicketuint256The position ticket to search for

Returns

NameTypeDescription
<none>int256The index of the exit queue or -1 if not found

canProcessExitQueue

Checks if the exit queue can be processed

function canProcessExitQueue() external view override returns (bool);

Returns

NameTypeDescription
<none>boolTrue if the exit queue can be processed, false otherwise

calculateExitedAssets

Calculates the exited assets for a given position ticket and exit queue index.

function calculateExitedAssets(address receiver, uint256 positionTicket, uint256 exitQueueIndex)
public
view
override
returns (uint256 leftTickets, uint256 exitedTickets, uint256 exitedAssets);

Parameters

NameTypeDescription
receiveraddressThe address of the receiver
positionTicketuint256The position ticket to calculate exited assets for
exitQueueIndexuint256The index of the exit queue to calculate exited assets for

Returns

NameTypeDescription
leftTicketsuint256The number of tickets left in the exit queue
exitedTicketsuint256The number of tickets that have exited
exitedAssetsuint256The number of assets that have exited

setPositionsManager

Update the address of the positions manager. Can only be called by the owner.

function setPositionsManager(address positionsManager_) external override onlyOwner;

Parameters

NameTypeDescription
positionsManager_addressThe address of the new positions manager

getExitQueueMissingAssets

Calculates the missing assets in the exit queue for a target cumulative tickets.

function getExitQueueMissingAssets(uint256 targetCumulativeTickets)
external
view
override
returns (uint256 missingAssets);

Parameters

NameTypeDescription
targetCumulativeTicketsuint256The target cumulative tickets in the exit queue

Returns

NameTypeDescription
missingAssetsuint256The number of missing assets in the exit queue

setRedeemablePositions

Set new redeemable positions. Can only be called by the owner.

function setRedeemablePositions(RedeemablePositions calldata newPositions) external override onlyOwner;

Parameters

NameTypeDescription
newPositionsRedeemablePositionsThe new redeemable positions

permitOsToken

Permit OsToken shares to be used for redemption.

function permitOsToken(uint256 shares, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external override;

Parameters

NameTypeDescription
sharesuint256The number of shares to permit
deadlineuint256The deadline for the permit
vuint8The recovery byte of the signature
rbytes32The output of the ECDSA signature
sbytes32The output of the ECDSA signature

enterExitQueue

Enters the exit queue with a given number of shares and receiver address.

function enterExitQueue(uint256 shares, address receiver) external override returns (uint256 positionTicket);

Parameters

NameTypeDescription
sharesuint256The number of shares to enter the exit queue with
receiveraddressThe address that will receive the assets after exit

Returns

NameTypeDescription
positionTicketuint256The position ticket for the entered exit queue

claimExitedAssets

Claims exited assets for a given position ticket and exit queue index.

function claimExitedAssets(uint256 positionTicket, uint256 exitQueueIndex) external override;

Parameters

NameTypeDescription
positionTicketuint256The position ticket to claim exited assets for
exitQueueIndexuint256The index of the exit queue to claim exited assets for

redeemSubVaultsAssets

Redeem assets from the sub-vaults to the meta vault. Can only be called by the positions manager.

function redeemSubVaultsAssets(address metaVault, uint256 assetsToRedeem)
external
override
returns (uint256 totalRedeemedAssets);

Parameters

NameTypeDescription
metaVaultaddressThe address of the meta vault
assetsToRedeemuint256The number of assets to redeem

Returns

NameTypeDescription
totalRedeemedAssetsuint256The total number of redeemed assets

redeemSubVaultOsToken

Redeem OsToken shares from a specific sub-vault. Can only be called by the meta vault.

function redeemSubVaultOsToken(address subVault, uint256 osTokenShares) external override returns (uint256);

Parameters

NameTypeDescription
subVaultaddressThe address of the sub-vault
osTokenSharesuint256The number of OsToken shares to redeem

Returns

NameTypeDescription
<none>uint256The amount of redeemed assets

redeemOsTokenPositions

Redeem OsToken shares from the vault positions.

function redeemOsTokenPositions(
OsTokenPosition[] memory positions,
bytes32[] calldata proof,
bool[] calldata proofFlags
) external override;

Parameters

NameTypeDescription
positionsOsTokenPosition[]The array of OsToken positions to redeem
proofbytes32[]The Merkle proof for the positions root
proofFlagsbool[]The flags for the Merkle proof

processExitQueue

Process the exit queue and checkpoint swapped or redeemed shares. Can only be called once per exitQueueUpdateDelay.

function processExitQueue() external override;

updateVaultState

Updates the vault state. To be used in multicall to update state and redeem positions.

function updateVaultState(address vault, IKeeperRewards.HarvestParams calldata harvestParams) external override;

Parameters

NameTypeDescription
vaultaddressThe address of the vault to update
harvestParamsIKeeperRewards.HarvestParamsThe harvest parameters for the vault state update

_swapAssetsToOsTokenShares

Internal function to swap assets to OsToken shares

function _swapAssetsToOsTokenShares(address receiver, uint256 assets) internal returns (uint256 osTokenShares);

Parameters

NameTypeDescription
receiveraddressThe address that will receive the OsToken shares
assetsuint256The number of assets to swap

Returns

NameTypeDescription
osTokenSharesuint256The number of OsToken shares swapped

_isMetaVault

Internal function to check whether the caller is a meta vault

function _isMetaVault(address vault) private view returns (bool);

Parameters

NameTypeDescription
vaultaddressThe address of the vault to check

Returns

NameTypeDescription
<none>boolTrue if the caller is a meta vault, false otherwise

_getAssets

Internal function that must be implemented to return the account assets

function _getAssets(address account) internal view virtual returns (uint256);

Parameters

NameTypeDescription
accountaddressThe address of the account

Returns

NameTypeDescription
<none>uint256The amount of assets in the vault

_transferAssets

Internal function for transferring assets to the receiver

IMPORTANT: because control is transferred to the receiver, care must be taken to not create reentrancy vulnerabilities. The Vault must follow the checks-effects-interactions pattern: https://docs.soliditylang.org/en/v0.8.22/security-considerations.html#use-the-checks-effects-interactions-pattern

function _transferAssets(address receiver, uint256 assets) internal virtual;

Parameters

NameTypeDescription
receiveraddressThe address that will receive the assets
assetsuint256The number of assets to transfer