Skip to content

Commit 74035ef

Browse files
committed
Apply suggestions from code review
1 parent 6c00479 commit 74035ef

File tree

5 files changed

+85
-49
lines changed

5 files changed

+85
-49
lines changed

contracts/staking/IApplicationWithDecreaseDelay.sol

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ import "./IApplication.sol";
1919

2020
/// @title Interface for Threshold Network applications with delay after decrease request
2121
interface IApplicationWithDecreaseDelay is IApplication {
22+
/// @notice Approves the previously registered authorization decrease
23+
/// request. Reverts if authorization decrease delay has not passed
24+
/// yet or if the authorization decrease was not requested for the
25+
/// given staking provider.
26+
function approveAuthorizationDecrease(address stakingProvider) external;
27+
2228
/// @notice Returns authorization-related parameters of the application.
2329
/// @dev The minimum authorization is also returned by `minimumAuthorization()`
2430
/// function, as a requirement of `IApplication` interface.
@@ -59,10 +65,4 @@ interface IApplicationWithDecreaseDelay is IApplication {
5965
external
6066
view
6167
returns (uint64);
62-
63-
/// @notice Approves the previously registered authorization decrease
64-
/// request. Reverts if authorization decrease delay has not passed
65-
/// yet or if the authorization decrease was not requested for the
66-
/// given staking provider.
67-
function approveAuthorizationDecrease(address stakingProvider) external;
6868
}

contracts/staking/IApplicationWithOperator.sol

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ import "./IApplication.sol";
1919

2020
/// @title Interface for Threshold Network applications with operator role
2121
interface IApplicationWithOperator is IApplication {
22+
/// @notice Used by staking provider to set operator address that will
23+
/// operate a node. The operator address must be unique.
24+
/// Reverts if the operator is already set for the staking provider
25+
/// or if the operator address is already in use.
26+
/// @dev Depending on application the given staking provider can set operator
27+
/// address only once or multiple times. Besides that, application can decide
28+
/// if function reverts if there is a pending authorization decrease for
29+
/// the staking provider.
30+
function registerOperator(address operator) external;
31+
2232
/// @notice Returns operator registered for the given staking provider.
2333
function stakingProviderToOperator(address stakingProvider)
2434
external
@@ -30,14 +40,4 @@ interface IApplicationWithOperator is IApplication {
3040
external
3141
view
3242
returns (address);
33-
34-
/// @notice Used by staking provider to set operator address that will
35-
/// operate a node. The operator address must be unique.
36-
/// Reverts if the operator is already set for the staking provider
37-
/// or if the operator address is already in use.
38-
/// @dev Depending on application the given staking provider can set operator
39-
/// address only once or multiple times. Besides that, application can decide
40-
/// if function reverts if there is a pending authorization decrease for
41-
/// the staking provider.
42-
function registerOperator(address operator) external;
4343
}

contracts/staking/TokenStaking.sol

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
3737
using SafeTUpgradeable for T;
3838
using SafeCastUpgradeable for uint256;
3939

40+
// enum is used for Staked event to have backward compatibility
41+
enum StakeType {
42+
NU,
43+
KEEP,
44+
T
45+
}
46+
4047
enum ApplicationStatus {
4148
NOT_APPROVED,
4249
APPROVED,
@@ -101,11 +108,25 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
101108
// slither-disable-next-line constable-states
102109
uint256 private legacySlashingQueueIndex;
103110

111+
event Staked(
112+
StakeType indexed stakeType,
113+
address indexed owner,
114+
address indexed stakingProvider,
115+
address beneficiary,
116+
address authorizer,
117+
uint96 amount
118+
);
104119
event MinimumStakeAmountSet(uint96 amount);
105120
event ApplicationStatusChanged(
106121
address indexed application,
107122
ApplicationStatus indexed newStatus
108123
);
124+
event AuthorizationIncreased(
125+
address indexed stakingProvider,
126+
address indexed application,
127+
uint96 fromAmount,
128+
uint96 toAmount
129+
);
109130
event AuthorizationDecreaseRequested(
110131
address indexed stakingProvider,
111132
address indexed application,
@@ -130,8 +151,26 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
130151
address indexed panicButton
131152
);
132153
event AuthorizationCeilingSet(uint256 ceiling);
154+
event ToppedUp(address indexed stakingProvider, uint96 amount);
155+
event AutoIncreaseToggled(
156+
address indexed stakingProvider,
157+
bool autoIncrease
158+
);
133159
event Unstaked(address indexed stakingProvider, uint96 amount);
160+
event TokensSeized(
161+
address indexed stakingProvider,
162+
uint96 amount,
163+
bool indexed discrepancy
164+
);
165+
event NotificationRewardSet(uint96 reward);
166+
event NotificationRewardPushed(uint96 reward);
134167
event NotificationRewardWithdrawn(address recipient, uint96 amount);
168+
event NotifierRewarded(address indexed notifier, uint256 amount);
169+
event SlashingProcessed(
170+
address indexed caller,
171+
uint256 count,
172+
uint256 tAmount
173+
);
135174
event GovernanceTransferred(address oldGovernance, address newGovernance);
136175

137176
modifier onlyGovernance() {
@@ -343,15 +382,14 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
343382
cleanAuthorizedApplications(stakingProviderStruct, 1);
344383
}
345384

346-
// TODO consider rename
347385
/// @notice Forced deauthorization of stake above 15m T.
348386
/// Can be called by anyone.
349-
function forceCapDecreaseAuthorization(address[] memory _stakingProviders)
387+
function forceAuthorizationCap(address[] memory _stakingProviders)
350388
external
351389
{
352390
require(_stakingProviders.length > 0, "Wrong input parameters");
353391
for (uint256 i = 0; i < _stakingProviders.length; i++) {
354-
forceCapDecreaseAuthorization(_stakingProviders[i]);
392+
forceAuthorizationCap(_stakingProviders[i]);
355393
}
356394
}
357395

@@ -375,7 +413,7 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
375413
maxAuthorization = MAX_STAKE;
376414
availableToOptOut = HALF_MAX_STAKE;
377415
}
378-
require(availableToOptOut >= amount, "Opt-out is not available"); // TODO rephrase
416+
require(availableToOptOut >= amount, "Opt-out amount too high");
379417
forceDecreaseAuthorization(stakingProvider, maxAuthorization - amount);
380418
stakingProviderStruct.optOutAmount += amount;
381419
}
@@ -710,9 +748,7 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
710748

711749
/// @notice Forced deauthorization of stake above 15m T.
712750
/// Can be called by anyone.
713-
// TODO consider rename
714-
function forceCapDecreaseAuthorization(address stakingProvider) public {
715-
//override {
751+
function forceAuthorizationCap(address stakingProvider) public {
716752
forceDecreaseAuthorization(stakingProvider, MAX_STAKE);
717753
}
718754

@@ -950,7 +986,7 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
950986
}
951987
}
952988

953-
require(deauthorized > 0, "Nothing was deauthorized");
989+
require(deauthorized > 0, "Nothing to deauthorize");
954990
}
955991

956992
function getAvailableOptOutAmount(

contracts/test/TokenStakingTestSet.sol

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,6 @@ contract ExtendedTokenStaking is TokenStaking {
161161
.authorizedApplications = _applications;
162162
}
163163

164-
function getAuthorizedApplications(address stakingProvider)
165-
external
166-
view
167-
returns (address[] memory)
168-
{
169-
return stakingProviders[stakingProvider].authorizedApplications;
170-
}
171-
172164
/// @notice Creates a delegation with `msg.sender` owner with the given
173165
/// staking provider, beneficiary, and authorizer. Transfers the
174166
/// given amount of T to the staking contract.
@@ -267,13 +259,12 @@ contract ExtendedTokenStaking is TokenStaking {
267259
token.safeTransferFrom(msg.sender, address(this), reward);
268260
}
269261

270-
/// @notice Creates new checkpoints due to an increment of a stakers' stake
271-
/// @param _delegator Address of the staking provider acting as delegator
272-
/// @param _amount Amount of T to increment
273-
function increaseStakeCheckpoint(address _delegator, uint96 _amount)
274-
internal
262+
function getAuthorizedApplications(address stakingProvider)
263+
external
264+
view
265+
returns (address[] memory)
275266
{
276-
newStakeCheckpoint(_delegator, _amount, true);
267+
return stakingProviders[stakingProvider].authorizedApplications;
277268
}
278269

279270
function getDeauthorizingAmount(
@@ -285,4 +276,13 @@ contract ExtendedTokenStaking is TokenStaking {
285276
.authorizations[application]
286277
.deauthorizing;
287278
}
279+
280+
/// @notice Creates new checkpoints due to an increment of a stakers' stake
281+
/// @param _delegator Address of the staking provider acting as delegator
282+
/// @param _amount Amount of T to increment
283+
function increaseStakeCheckpoint(address _delegator, uint96 _amount)
284+
internal
285+
{
286+
newStakeCheckpoint(_delegator, _amount, true);
287+
}
288288
}

test/staking/TokenStaking.test.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,7 @@ describe("TokenStaking", () => {
915915
})
916916
})
917917

918-
describe("forceCapDecreaseAuthorization", () => {
918+
describe("forceAuthorizationCap", () => {
919919
const maxStake = to1e18("15000000") // 15m
920920
const amount = maxStake.mul(2)
921921

@@ -948,8 +948,8 @@ describe("TokenStaking", () => {
948948
await expect(
949949
tokenStaking
950950
.connect(authorizer)
951-
["forceCapDecreaseAuthorization(address)"](stakingProvider.address)
952-
).to.be.revertedWith("Nothing was deauthorized")
951+
["forceAuthorizationCap(address)"](stakingProvider.address)
952+
).to.be.revertedWith("Nothing to deauthorize")
953953
})
954954
})
955955

@@ -980,7 +980,7 @@ describe("TokenStaking", () => {
980980

981981
tx = await tokenStaking
982982
.connect(deployer)
983-
["forceCapDecreaseAuthorization(address)"](stakingProvider.address)
983+
["forceAuthorizationCap(address)"](stakingProvider.address)
984984
})
985985

986986
it("should set authorized amount to max", async () => {
@@ -1053,7 +1053,7 @@ describe("TokenStaking", () => {
10531053

10541054
tx = await tokenStaking
10551055
.connect(deployer)
1056-
["forceCapDecreaseAuthorization(address)"](stakingProvider.address)
1056+
["forceAuthorizationCap(address)"](stakingProvider.address)
10571057
})
10581058

10591059
it("should set authorized amount to max", async () => {
@@ -1132,7 +1132,7 @@ describe("TokenStaking", () => {
11321132

11331133
tx = await tokenStaking
11341134
.connect(deployer)
1135-
["forceCapDecreaseAuthorization(address[])"]([
1135+
["forceAuthorizationCap(address[])"]([
11361136
stakingProvider.address,
11371137
otherStaker.address,
11381138
])
@@ -1222,7 +1222,7 @@ describe("TokenStaking", () => {
12221222
tokenStaking
12231223
.connect(stakingProvider)
12241224
.optOutDecreaseAuthorization(stakingProvider.address, 1)
1225-
).to.be.revertedWith("Opt-out is not available")
1225+
).to.be.revertedWith("Opt-out amount too high")
12261226

12271227
await tokenStaking
12281228
.connect(authorizer)
@@ -1238,7 +1238,7 @@ describe("TokenStaking", () => {
12381238
stakingProvider.address,
12391239
amountToOptOut.add(1)
12401240
)
1241-
).to.be.revertedWith("Opt-out is not available")
1241+
).to.be.revertedWith("Opt-out amount too high")
12421242

12431243
await tokenStaking
12441244
.connect(stakingProvider)
@@ -1247,7 +1247,7 @@ describe("TokenStaking", () => {
12471247
tokenStaking
12481248
.connect(stakingProvider)
12491249
.optOutDecreaseAuthorization(stakingProvider.address, 1)
1250-
).to.be.revertedWith("Opt-out is not available")
1250+
).to.be.revertedWith("Opt-out amount too high")
12511251
})
12521252
})
12531253

@@ -1373,7 +1373,7 @@ describe("TokenStaking", () => {
13731373
tokenStaking
13741374
.connect(stakingProvider)
13751375
.optOutDecreaseAuthorization(stakingProvider.address, 1)
1376-
).to.be.revertedWith("Opt-out is not available")
1376+
).to.be.revertedWith("Opt-out amount too high")
13771377
})
13781378
})
13791379
})
@@ -1404,7 +1404,7 @@ describe("TokenStaking", () => {
14041404

14051405
await tokenStaking
14061406
.connect(deployer)
1407-
["forceCapDecreaseAuthorization(address)"](stakingProvider.address)
1407+
["forceAuthorizationCap(address)"](stakingProvider.address)
14081408

14091409
await tokenStaking
14101410
.connect(stakingProvider)

0 commit comments

Comments
 (0)