contracts
contracts copied to clipboard
Average delegation unbonding on multiple requests
trafficstars
Summary
When a delegator undelegates some tokens a delegationUnbondingPeriod is used to calculate the epoch when the tokens will be unlocked. On each new undelegation the period is reset to the unbonding period even if there are tokens waiting to be unlocked. This PR change this behaviour to use a weighted average of time and tokens like on the indexer thawing period.
Current Behavior
It currently works by resetting the unlock epoch on each undelegation.
Example:
- Epoch 1: Undelegation for 100 GRT, unlock epoch is set to 29
- Epoch 2: 27 epochs to go for unlocking the tokens
- Epoch 3: 26 epochs to go for unlocking the tokens
- Epoch 4: Undelegation for 50 GRT, unlock epoch is set to 32 <- the period is reset for the 150 GRT total tokens
Solution
Use a weighted average formula that consider the time some tokens have already been locked, weighted by the old tokens and the new tokens being undelegated. The formula will round up any fractional epoch value as there is no such thing as half an epoch.