Skip to main content

Unstake seSCRT

To withdraw SCRT, user calls Unstake seSCRT. Unstake call transfers seSCRT tokens from users wallet to contract and the process of withdrawal starts.

An image

When user sends seSCRT tokens to withdraw Receive call automatically gets triggered which triggers try_withdraw function.

To keep track of undelegating scrt from validators we are using a data structure named window_manager. The schematic is as follows :

`window_manager`
|-- queue_window
|-- ongoing_window (It is a vecDeque of type ongoingWithWithdrawWindows)

`queue_window`
|-- total_seSCRT amount (total sescrt in the queue for undelegation)
|-- sescrt_users_amount (hashmap which contains seSCRT amount per user)

`ongoingWithWithdrawWindows`
|-- total_seSCRT amount (total sescrt)
|-- total_SCRT amount (corrosponding total scrt for undelegation)
|-- scrt_users_amount (hashmap which contains SCRT corrosponding each user)

On receiving seSCRT tokens, try_withdraw function only updates queue_window's data of window_manager.

Now, to undelegate SCRT from validators, contract manager advances the window and call AdvanceWindow which triggers advance_window_1 function.