Managing withdrawal requests in IERC4626
Last updated
Last updated
To request a withdrawal a user calls withdraw(uint256 assets, address receiver, address owner)
specifying the amount of LP tokens they want to withdraw. At this point they are added to the queue.
Every ~7 days Alluo Booster Pool calls loopRewards()
, where the following steps are executed:
funds are unlocked from Frax
_processWithdrawalRequests()
keeps the amount of LPs requested for withdrawals and burns the shares of users who are in the withdrawal queue
_relockToFrax()
relocks the remaing funds into Frax Convex again
current rewards per share are updated
Since shares are minted 1:1 ot deposited assets, total supply of shares should always be equal to total amount of assets in the vault. Total assets comprise the following:
underlying pool lp token
wrapped lp token
funds locked in frax convex
When shares are burnt during a harvest, factual amount of assets does not change until users claim their withdrawals. Up until then to balance out burnt shares the contract keeps track of unsatisfied withdrawal requests in totalRequestedWithdrawals
which is included into totalAssets()
calculation.
Example
Imagine you deposit $100.
userWithdrawals.withdrawalRequested=0,
userWithdrawals.withdrawalAvailable=0,
balanceOf() = 100
you withdraw() $50
userWithdrawals.withdrawalRequested=50,
userWithdrawals.withdrawalAvailable=0,
balanceOf() = 100
you decide to withdraw $20 more, you call withdraw(20).
userWithdrawals.withdrawalRequested=70,
userWithdrawals.withdrawalAvailable=0,
balanceOf() = 100
Funds are unlocked by resolver.
userWithdrawals.withdrawalRequested=0,
userWithdrawals.withdrawalAvailable=70
,
balanceOf() = 30
You put another request to withdraw $10.
userWithdrawals.withdrawalRequested=10,
userWithdrawals.withdrawalAvailable=70,
balanceOf() = 30
Funds are unlocked after the next cycle.
userWithdrawals.withdrawalRequested=0,
userWithdrawals.withdrawalAvailable=80,
balanceOf() = 20
You finally claim() and $80 are transferred to you.
userWithdrawals.withdrawalRequested=0,
userWithdrawals.withdrawalAvailable=0
,
balanceOf() = 20