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

Implemented cooldown for OperatorFee change #215

Closed
Closed
Show file tree
Hide file tree
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
25 changes: 23 additions & 2 deletions abi/StakingV2.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,27 @@
"name": "OnlyProfileAdminFunction",
"type": "error"
},
{
"inputs": [
{
"internalType": "uint72",
"name": "identityId",
"type": "uint72"
},
{
"internalType": "uint256",
"name": "timeNow",
"type": "uint256"
},
{
"internalType": "uint96",
"name": "delayEnd",
"type": "uint96"
}
],
"name": "OperatorFeeChangeOnCooldown",
"type": "error"
},
{
"inputs": [
{
Expand Down Expand Up @@ -149,9 +170,9 @@
},
{
"indexed": false,
"internalType": "uint8",
"internalType": "uint96",
"name": "operatorFee",
"type": "uint8"
"type": "uint96"
}
],
"name": "OperatorFeeUpdated",
Expand Down
37 changes: 33 additions & 4 deletions contracts/v2/Staking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ contract StakingV2 is Named, Versioned, ContractStatus, Initializable {
uint96 oldAccumulatedOperatorFee,
uint96 newAccumulatedOperatorFee
);
event OperatorFeeUpdated(uint72 indexed identityId, bytes nodeId, uint8 operatorFee);
event OperatorFeeUpdated(
uint72 indexed identityId,
bytes nodeId,
uint8 newOperatorFee,
uint96 operatorFeeChangeCooldownEndTimestamp
);

string private constant _NAME = "Staking";
string private constant _VERSION = "2.0.0";
Expand Down Expand Up @@ -157,7 +162,7 @@ contract StakingV2 is Named, Versioned, ContractStatus, Initializable {
ServiceAgreementStorageProxy sasProxy = serviceAgreementStorageProxy;
StakingStorage ss = stakingStorage;

uint96 operatorFee = (rewardAmount * ss.operatorFees(identityId)) / 100;
uint96 operatorFee = (rewardAmount * (ss.operatorFees(identityId) & 127)) / 100;
uint96 delegatorsReward = rewardAmount - operatorFee;

ProfileStorage ps = profileStorage;
Expand Down Expand Up @@ -197,11 +202,35 @@ contract StakingV2 is Named, Versioned, ContractStatus, Initializable {
// TBD
}

function getOperatorFee(uint72 identityId) external view returns (uint8) {
return uint8(stakingStorage.operatorFees(identityId) & 127);
}

function getOperatorFeeChangeCooldownEndTimestamp(uint72 identityId) external view returns (uint96) {
return stakingStorage.operatorFees(identityId) >> 7;
}

function setOperatorFee(uint72 identityId, uint8 operatorFee) external onlyAdmin(identityId) {
if (operatorFee > 100) revert StakingErrors.InvalidOperatorFee();
stakingStorage.setOperatorFee(identityId, operatorFee);

emit OperatorFeeUpdated(identityId, profileStorage.getNodeId(identityId), operatorFee);
StakingStorage ss = stakingStorage;

uint96 operatorFeeChangeCooldownEnd = ss.operatorFees(identityId) >> 7;

if (block.timestamp < operatorFeeChangeCooldownEnd) {
revert StakingErrors.OperatorFeeChangeOnCooldown(identityId, block.timestamp, operatorFeeChangeCooldownEnd);
}

uint96 newOperatorFeeChangeCooldownEnd = uint96(block.timestamp + parametersStorage.stakeWithdrawalDelay());

ss.setOperatorFee(identityId, (newOperatorFeeChangeCooldownEnd << 7) | operatorFee);

emit OperatorFeeUpdated(
identityId,
profileStorage.getNodeId(identityId),
operatorFee,
newOperatorFeeChangeCooldownEnd
);
}

function _addStake(address sender, uint72 identityId, uint96 stakeAmount) internal virtual {
Expand Down
1 change: 1 addition & 0 deletions contracts/v2/errors/StakingErrors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ library StakingErrors {
error WithdrawalPeriodPending(uint256 endTimestamp);
error InvalidOperatorFee();
error MaximumStakeExceeded(uint256 amount);
error OperatorFeeChangeOnCooldown(uint72 identityId, uint256 timeNow, uint96 delayEnd);
}
2 changes: 1 addition & 1 deletion deployments/parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@
"replacementWindowDurationPerc": "0",
"rewardWithdrawalDelay": "300",
"slashingFreezeDuration": "63072000",
"stakeWithdrawalDelay": "3600",
"stakeWithdrawalDelay": "2419200",
"updateCommitWindowDuration": "1800"
},
"ProofManagerV1": {
Expand Down