Skip to main content

Undelegate

Manager - Undelegate from validators

After every three days, contract manager needs to call AdvanceWindow to undelegate unstaked SCRT from validators. AdvanceWindow triggers advance_window_1 function.

Advance_window_1 function first gets exchange rate from exchange_rate function and fetches total_sescrt from queue window of window manager and calculate the SCRT amount that needs to be undelegated from validators, and sends the cosmos message to undelegate. After that current window manager is being advanced by calling advance_window_2 function. It will create a variable of type ongoingWithWithdrawWindows and update the data from current window_manager and push it on the back of ongoing_window(VecDeque) and reset the queue_window.

`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)

Now to check if the undelegation is done(scrt received in contract from validators), In advance_window_1 we iterate over the ongoing_window(VeqDeque) and check for the maturity of ongoingWithWithdrawWindows and pop the mature one from ongoing_window and gets the amount available for claim to the users and updates User_claimable data structure.

User_claimable data structure keep the track of users scrt which is avalailable for claim and total SCRT available for claim as key value pair.