Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add isAutoUndelegate for auto DistributeUndelegatedSynPackage #464

Merged
merged 2 commits into from
Jan 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading