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

chore: remove 2 step claim of validator reward. #356

Merged
merged 1 commit into from
Jul 23, 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
64 changes: 0 additions & 64 deletions packages/contracts/contracts/L1/AssetManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -548,70 +548,6 @@ contract AssetManager is ISemver, IERC721Receiver, IAssetManager {
emit KghBatchUndelegated(validator, msg.sender, tokenIds, totalKroAsset, kroShares);
}

/**
* @inheritdoc IAssetManager
*/
function initClaimValidatorReward(uint128 amount) external {
Asset storage asset = _vaults[msg.sender].asset;
Pending storage pendingAsset = _vaults[msg.sender].pending;

if (amount == 0) revert NotAllowedZeroInput();
if (amount > asset.validatorRewardKro) revert InsufficientAsset();

unchecked {
asset.validatorRewardKro -= amount;
pendingAsset.pendingValidatorRewards[block.timestamp] += amount;
pendingAsset.totalPendingValidatorRewards += amount;
pendingAsset.claimRequestTimes.push(block.timestamp);
}

VALIDATOR_MANAGER.updateValidatorTree(msg.sender, true);

emit RewardClaimInitiated(msg.sender, amount);
}

/**
* @inheritdoc IAssetManager
*/
function finalizeClaimValidatorReward() external {
Pending storage pendingAsset = _vaults[msg.sender].pending;
if (pendingAsset.totalPendingValidatorRewards == 0) revert PendingNotExists();

uint256[] memory requestTimes = pendingAsset.claimRequestTimes;
uint128 rewardsToClaim;
for (uint256 i = requestTimes.length - 1; i >= 0 && requestTimes[i] > 0; ) {
if (requestTimes[i] + UNDELEGATION_PERIOD <= block.timestamp) {
unchecked {
rewardsToClaim += pendingAsset.pendingValidatorRewards[requestTimes[i]];
}

delete pendingAsset.pendingValidatorRewards[requestTimes[i]];
delete pendingAsset.claimRequestTimes[i];
}

if (i == 0) {
break;
}
unchecked {
--i;
}
}

if (rewardsToClaim == 0) revert FinalizedPendingNotExists();

// To prevent the underflow of the totalPendingValidatorRewards when the validator is slashed.
if (pendingAsset.totalPendingValidatorRewards < rewardsToClaim) {
rewardsToClaim = pendingAsset.totalPendingValidatorRewards;
}

unchecked {
pendingAsset.totalPendingValidatorRewards -= rewardsToClaim;
}
ASSET_TOKEN.safeTransfer(msg.sender, rewardsToClaim);

emit RewardClaimFinalized(msg.sender, rewardsToClaim);
}

/**
* @inheritdoc IAssetManager
*/
Expand Down
Loading