Skip to content

Commit 0c6a7de

Browse files
authored
Remove stake lock (#84)
1 parent 1d315ce commit 0c6a7de

12 files changed

+36
-739
lines changed

contracts/sfc/ConstantsManager.sol

-36
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@ contract ConstantsManager is Ownable {
1515
uint256 public burntFeeShare;
1616
// The percentage of fees to transfer to treasury address, e.g., 10%
1717
uint256 public treasuryFeeShare;
18-
// The ratio of the reward rate at base rate (no lock), e.g., 30%
19-
uint256 public unlockedRewardRatio;
20-
// The minimum duration of a stake/delegation lockup, e.g. 2 weeks
21-
uint256 public minLockupDuration;
22-
// The maximum duration of a stake/delegation lockup, e.g. 1 year
23-
uint256 public maxLockupDuration;
2418
// the number of epochs that undelegated stake is locked for
2519
uint256 public withdrawalPeriodEpochs;
2620
// the number of seconds that undelegated stake is locked for
@@ -87,36 +81,6 @@ contract ConstantsManager is Ownable {
8781
treasuryFeeShare = v;
8882
}
8983

90-
function updateUnlockedRewardRatio(uint256 v) external virtual onlyOwner {
91-
if (v < (5 * Decimal.unit()) / 100) {
92-
revert ValueTooSmall();
93-
}
94-
if (v > Decimal.unit() / 2) {
95-
revert ValueTooLarge();
96-
}
97-
unlockedRewardRatio = v;
98-
}
99-
100-
function updateMinLockupDuration(uint256 v) external virtual onlyOwner {
101-
if (v < 86400) {
102-
revert ValueTooSmall();
103-
}
104-
if (v > 86400 * 30) {
105-
revert ValueTooLarge();
106-
}
107-
minLockupDuration = v;
108-
}
109-
110-
function updateMaxLockupDuration(uint256 v) external virtual onlyOwner {
111-
if (v < 86400 * 30) {
112-
revert ValueTooSmall();
113-
}
114-
if (v > 86400 * 1460) {
115-
revert ValueTooLarge();
116-
}
117-
maxLockupDuration = v;
118-
}
119-
12084
function updateWithdrawalPeriodEpochs(uint256 v) external virtual onlyOwner {
12185
if (v < 2) {
12286
revert ValueTooSmall();

contracts/sfc/NetworkInitializer.sol

-3
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ contract NetworkInitializer {
2828
consts.updateValidatorCommission((15 * Decimal.unit()) / 100);
2929
consts.updateBurntFeeShare((20 * Decimal.unit()) / 100);
3030
consts.updateTreasuryFeeShare((10 * Decimal.unit()) / 100);
31-
consts.updateUnlockedRewardRatio((30 * Decimal.unit()) / 100);
32-
consts.updateMinLockupDuration(86400 * 14);
33-
consts.updateMaxLockupDuration(86400 * 365);
3431
consts.updateWithdrawalPeriodEpochs(3);
3532
consts.updateWithdrawalPeriodTime(60 * 60 * 24 * 7);
3633
consts.updateBaseRewardPerSecond(2668658453701531600);

contracts/sfc/NodeDriver.sol

+2-22
Original file line numberDiff line numberDiff line change
@@ -110,28 +110,8 @@ contract NodeDriver is Initializable {
110110
);
111111
}
112112

113-
function setGenesisDelegation(
114-
address delegator,
115-
uint256 toValidatorID,
116-
uint256 stake,
117-
uint256 lockedStake,
118-
uint256 lockupFromEpoch,
119-
uint256 lockupEndTime,
120-
uint256 lockupDuration,
121-
uint256 earlyUnlockPenalty,
122-
uint256 rewards
123-
) external onlyNode {
124-
backend.setGenesisDelegation(
125-
delegator,
126-
toValidatorID,
127-
stake,
128-
lockedStake,
129-
lockupFromEpoch,
130-
lockupEndTime,
131-
lockupDuration,
132-
earlyUnlockPenalty,
133-
rewards
134-
);
113+
function setGenesisDelegation(address delegator, uint256 toValidatorID, uint256 stake) external onlyNode {
114+
backend.setGenesisDelegation(delegator, toValidatorID, stake);
135115
}
136116

137117
function deactivateValidator(uint256 validatorID, uint256 status) external onlyNode {

contracts/sfc/NodeDriverAuth.sol

+2-22
Original file line numberDiff line numberDiff line change
@@ -141,28 +141,8 @@ contract NodeDriverAuth is Initializable, Ownable {
141141
);
142142
}
143143

144-
function setGenesisDelegation(
145-
address delegator,
146-
uint256 toValidatorID,
147-
uint256 stake,
148-
uint256 lockedStake,
149-
uint256 lockupFromEpoch,
150-
uint256 lockupEndTime,
151-
uint256 lockupDuration,
152-
uint256 earlyUnlockPenalty,
153-
uint256 rewards
154-
) external onlyDriver {
155-
sfc.setGenesisDelegation(
156-
delegator,
157-
toValidatorID,
158-
stake,
159-
lockedStake,
160-
lockupFromEpoch,
161-
lockupEndTime,
162-
lockupDuration,
163-
earlyUnlockPenalty,
164-
rewards
165-
);
144+
function setGenesisDelegation(address delegator, uint256 toValidatorID, uint256 stake) external onlyDriver {
145+
sfc.setGenesisDelegation(delegator, toValidatorID, stake);
166146
}
167147

168148
function deactivateValidator(uint256 validatorID, uint256 status) external onlyDriver {

contracts/sfc/NodeDriverI.sol

+1-11
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,7 @@ interface NodeDriverI {
1313
uint256 deactivatedTime
1414
) external;
1515

16-
function setGenesisDelegation(
17-
address delegator,
18-
uint256 toValidatorID,
19-
uint256 stake,
20-
uint256 lockedStake,
21-
uint256 lockupFromEpoch,
22-
uint256 lockupEndTime,
23-
uint256 lockupDuration,
24-
uint256 earlyUnlockPenalty,
25-
uint256 rewards
26-
) external;
16+
function setGenesisDelegation(address delegator, uint256 toValidatorID, uint256 stake) external;
2717

2818
function deactivateValidator(uint256 validatorID, uint256 status) external;
2919

contracts/sfc/SFC.sol

+3-20
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ contract SFC is SFCBase, Version {
8787
}
8888

8989
function rewardsStash(address delegator, uint256 validatorID) public view returns (uint256) {
90-
Rewards memory stash = _rewardsStash[delegator][validatorID];
91-
return stash.lockupBaseReward + stash.lockupExtraReward + stash.unlockedReward;
90+
return _rewardsStash[delegator][validatorID];
9291
}
9392

9493
/*
@@ -295,25 +294,9 @@ contract SFC is SFCBase, Version {
295294
uint256 commissionRewardFull = _calcValidatorCommission(rawReward, c.validatorCommission());
296295
uint256 selfStake = getStake[validatorAddr][validatorID];
297296
if (selfStake != 0) {
298-
uint256 lCommissionRewardFull = (commissionRewardFull * getLockedStake(validatorAddr, validatorID)) /
299-
selfStake;
300-
uint256 uCommissionRewardFull = commissionRewardFull - lCommissionRewardFull;
301-
Rewards memory lCommissionReward = _scaleLockupReward(
302-
lCommissionRewardFull,
303-
getLockupInfo[validatorAddr][validatorID].duration
304-
);
305-
Rewards memory uCommissionReward = _scaleLockupReward(uCommissionRewardFull, 0);
306-
_rewardsStash[validatorAddr][validatorID] = sumRewards(
307-
_rewardsStash[validatorAddr][validatorID],
308-
lCommissionReward,
309-
uCommissionReward
310-
);
311-
getStashedLockupRewards[validatorAddr][validatorID] = sumRewards(
312-
getStashedLockupRewards[validatorAddr][validatorID],
313-
lCommissionReward,
314-
uCommissionReward
315-
);
297+
_rewardsStash[validatorAddr][validatorID] += commissionRewardFull;
316298
}
299+
317300
// accounting reward per token for delegators
318301
uint256 delegatorsReward = rawReward - commissionRewardFull;
319302
// note: use latest stake for the sake of rewards distribution accuracy, not snapshot.receivedStake

contracts/sfc/SFCBase.sol

-55
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,10 @@ contract SFCBase is SFCState {
6060
error GovVotesRecountFailed();
6161

6262
// staking
63-
error LockedStakeGreaterThanTotalStake();
6463
error InsufficientSelfStake();
65-
error NotEnoughUnlockedStake();
66-
error NotEnoughLockedStake();
6764
error NotEnoughTimePassed();
6865
error NotEnoughEpochsPassed();
6966
error StakeIsFullySlashed();
70-
error IncorrectDuration();
71-
error ValidatorLockupTooShort();
72-
error TooManyReLocks();
73-
error TooFrequentReLocks();
74-
error LockupDurationDecreased();
75-
error AlreadyLockedUp();
76-
error NotLockedUp();
7767

7868
// stashing
7969
error NothingToStash();
@@ -132,37 +122,6 @@ contract SFCBase is SFCState {
132122
totalSupply = totalSupply + amount;
133123
}
134124

135-
function sumRewards(Rewards memory a, Rewards memory b) internal pure returns (Rewards memory) {
136-
return
137-
Rewards(
138-
a.lockupExtraReward + b.lockupExtraReward,
139-
a.lockupBaseReward + b.lockupBaseReward,
140-
a.unlockedReward + b.unlockedReward
141-
);
142-
}
143-
144-
function sumRewards(Rewards memory a, Rewards memory b, Rewards memory c) internal pure returns (Rewards memory) {
145-
return sumRewards(sumRewards(a, b), c);
146-
}
147-
148-
function _scaleLockupReward(
149-
uint256 fullReward,
150-
uint256 lockupDuration
151-
) internal view returns (Rewards memory reward) {
152-
reward = Rewards(0, 0, 0);
153-
uint256 unlockedRewardRatio = c.unlockedRewardRatio();
154-
if (lockupDuration != 0) {
155-
uint256 maxLockupExtraRatio = Decimal.unit() - unlockedRewardRatio;
156-
uint256 lockupExtraRatio = (maxLockupExtraRatio * lockupDuration) / c.maxLockupDuration();
157-
uint256 totalScaledReward = (fullReward * (unlockedRewardRatio + lockupExtraRatio)) / Decimal.unit();
158-
reward.lockupBaseReward = (fullReward * unlockedRewardRatio) / Decimal.unit();
159-
reward.lockupExtraReward = totalScaledReward - reward.lockupBaseReward;
160-
} else {
161-
reward.unlockedReward = (fullReward * unlockedRewardRatio) / Decimal.unit();
162-
}
163-
return reward;
164-
}
165-
166125
function _recountVotes(address delegator, address validatorAuth, bool strict) internal {
167126
if (voteBookAddress != address(0)) {
168127
// Don't allow recountVotes to use up all the gas
@@ -220,20 +179,6 @@ contract SFCBase is SFCState {
220179
return (rawReward * commission) / Decimal.unit();
221180
}
222181

223-
function getLockedStake(address delegator, uint256 toValidatorID) public view returns (uint256) {
224-
if (!isLockedUp(delegator, toValidatorID)) {
225-
return 0;
226-
}
227-
return getLockupInfo[delegator][toValidatorID].lockedStake;
228-
}
229-
230-
function isLockedUp(address delegator, uint256 toValidatorID) public view returns (bool) {
231-
return
232-
getLockupInfo[delegator][toValidatorID].endTime != 0 &&
233-
getLockupInfo[delegator][toValidatorID].lockedStake != 0 &&
234-
_now() <= getLockupInfo[delegator][toValidatorID].endTime;
235-
}
236-
237182
function _now() internal view virtual returns (uint256) {
238183
return block.timestamp;
239184
}

contracts/sfc/SFCI.sol

+3-51
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,9 @@ interface SFCI {
1111
event Delegated(address indexed delegator, uint256 indexed toValidatorID, uint256 amount);
1212
event Undelegated(address indexed delegator, uint256 indexed toValidatorID, uint256 indexed wrID, uint256 amount);
1313
event Withdrawn(address indexed delegator, uint256 indexed toValidatorID, uint256 indexed wrID, uint256 amount);
14-
event ClaimedRewards(
15-
address indexed delegator,
16-
uint256 indexed toValidatorID,
17-
uint256 lockupExtraReward,
18-
uint256 lockupBaseReward,
19-
uint256 unlockedReward
20-
);
21-
event RestakedRewards(
22-
address indexed delegator,
23-
uint256 indexed toValidatorID,
24-
uint256 lockupExtraReward,
25-
uint256 lockupBaseReward,
26-
uint256 unlockedReward
27-
);
14+
event ClaimedRewards(address indexed delegator, uint256 indexed toValidatorID, uint256 rewards);
15+
event RestakedRewards(address indexed delegator, uint256 indexed toValidatorID, uint256 rewards);
2816
event BurntFTM(uint256 amount);
29-
event LockedUpStake(address indexed delegator, uint256 indexed validatorID, uint256 duration, uint256 amount);
30-
event UnlockedStake(address indexed delegator, uint256 indexed validatorID, uint256 amount, uint256 penalty);
3117
event UpdatedSlashingRefundRatio(uint256 indexed validatorID, uint256 refundRatio);
3218
event RefundedSlashedLegacyDelegation(address indexed delegator, uint256 indexed validatorID, uint256 amount);
3319

@@ -53,18 +39,8 @@ interface SFCI {
5339
uint256 totalSupply
5440
);
5541

56-
function getLockupInfo(
57-
address,
58-
uint256
59-
) external view returns (uint256 lockedStake, uint256 fromEpoch, uint256 endTime, uint256 duration);
60-
6142
function getStake(address, uint256) external view returns (uint256);
6243

63-
function getStashedLockupRewards(
64-
address,
65-
uint256
66-
) external view returns (uint256 lockupExtraReward, uint256 lockupBaseReward, uint256 unlockedReward);
67-
6844
function getValidator(
6945
uint256
7046
)
@@ -106,8 +82,6 @@ interface SFCI {
10682

10783
function totalActiveStake() external view returns (uint256);
10884

109-
function totalSlashedStake() external view returns (uint256);
110-
11185
function totalStake() external view returns (uint256);
11286

11387
function totalSupply() external view returns (uint256);
@@ -142,8 +116,6 @@ interface SFCI {
142116

143117
function rewardsStash(address delegator, uint256 validatorID) external view returns (uint256);
144118

145-
function getLockedStake(address delegator, uint256 toValidatorID) external view returns (uint256);
146-
147119
function createValidator(bytes calldata pubkey) external payable;
148120

149121
function getSelfStake(uint256 validatorID) external view returns (uint256);
@@ -186,16 +158,6 @@ interface SFCI {
186158

187159
function sealEpochValidators(uint256[] calldata nextValidatorIDs) external;
188160

189-
function isLockedUp(address delegator, uint256 toValidatorID) external view returns (bool);
190-
191-
function getUnlockedStake(address delegator, uint256 toValidatorID) external view returns (uint256);
192-
193-
function lockStake(uint256 toValidatorID, uint256 lockupDuration, uint256 amount) external;
194-
195-
function relockStake(uint256 toValidatorID, uint256 lockupDuration, uint256 amount) external;
196-
197-
function unlockStake(uint256 toValidatorID, uint256 amount) external returns (uint256);
198-
199161
function initialize(
200162
uint256 sealedEpoch,
201163
uint256 _totalSupply,
@@ -216,17 +178,7 @@ interface SFCI {
216178
uint256 deactivatedTime
217179
) external;
218180

219-
function setGenesisDelegation(
220-
address delegator,
221-
uint256 toValidatorID,
222-
uint256 stake,
223-
uint256 lockedStake,
224-
uint256 lockupFromEpoch,
225-
uint256 lockupEndTime,
226-
uint256 lockupDuration,
227-
uint256 earlyUnlockPenalty,
228-
uint256 rewards
229-
) external;
181+
function setGenesisDelegation(address delegator, uint256 toValidatorID, uint256 stake) external;
230182

231183
function updateVoteBookAddress(address v) external;
232184

0 commit comments

Comments
 (0)