Skip to content

Commit

Permalink
fix: add isAutoUndelegate for auto DistributeUndelegatedSynPackage (
Browse files Browse the repository at this point in the history
#464)

* fix: add `isAutoUndelegate` for auto `DistributeUndelegatedSynPackage`

* add annotation
  • Loading branch information
pythonberg1997 committed Jan 12, 2024
1 parent 1e21529 commit c069e9e
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions contracts/Staking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,7 @@ contract Staking is IStaking, System, IParamSubscriber, IApplication {
address recipient;
address validator;
uint256 amount;
bool isAutoUndelegate;
while (iter.hasNext()) {
if (idx == 0) {
recipient = address(uint160(iter.next().toAddress()));
Expand All @@ -628,6 +629,8 @@ contract Staking is IStaking, System, IParamSubscriber, IApplication {
} else if (idx == 2) {
amount = uint256(iter.next().toUint());
success = true;
} else if (idx == 3) {
isAutoUndelegate = iter.next().toBoolean();
} else {
break;
}
Expand All @@ -643,6 +646,13 @@ contract Staking is IStaking, System, IParamSubscriber, IApplication {
pendingUndelegateTime[recipient][validator] = 0;
undelegated[recipient] = undelegated[recipient].add(amount);

// this is to address the issue that the contract state will not being updated
// when the Beacon Chain system undelegate all the funds after second sunset upgrade
if (isAutoUndelegate) {
delegated[recipient] = delegated[recipient].sub(amount);
delegatedOfValidator[recipient][validator] = delegatedOfValidator[recipient][validator].sub(amount);
}

emit undelegatedReceived(recipient, validator, amount);
return (CODE_OK, new bytes(0));
}
Expand Down

0 comments on commit c069e9e

Please sign in to comment.