Skip to content

Commit 5fb485e

Browse files
vzotovacygnusvmichalinacienciala
committed
Apply suggestions from code review
Co-authored-by: David Núñez <[email protected]> Co-authored-by: Michalina <[email protected]>
1 parent b181f2a commit 5fb485e

File tree

8 files changed

+35
-40
lines changed

8 files changed

+35
-40
lines changed

.github/workflows/contracts.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,6 @@ jobs:
115115
- name: Install dependencies
116116
run: yarn install --frozen-lockfile
117117

118-
- name: Resolve latest contracts
119-
run: yarn upgrade @keep-network/keep-core@${{ github.event.inputs.environment }}
120-
121118
- name: Configure tenderly
122119
env:
123120
TENDERLY_TOKEN: ${{ secrets.TENDERLY_TOKEN }}
@@ -197,7 +194,6 @@ jobs:
197194
# `etherscan-verify` plugins tries to verify them, which is not desired.
198195
- name: Prepare for verification on Etherscan
199196
run: |
200-
rm -rf ./node_modules/@keep-network/keep-core
201197
rm -rf ./external/npm
202198
203199
- name: Verify contracts on Etherscan
@@ -240,9 +236,6 @@ jobs:
240236
- name: Install dependencies
241237
run: yarn install --frozen-lockfile
242238

243-
- name: Resolve latest contracts
244-
run: yarn upgrade @keep-network/keep-core@${{ github.event.inputs.environment }}
245-
246239
- name: Deploy contracts
247240
env:
248241
# Using fake ternary expressions to decide which credentials to use,

.github/workflows/npm.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ jobs:
2727
registry-url: "https://registry.npmjs.org"
2828
cache: "yarn"
2929

30-
- name: Resolve latest contracts
31-
run: |
32-
yarn upgrade --exact \
33-
@keep-network/keep-core
34-
3530
# Deploy contracts to a local network to generate deployment artifacts that
3631
# are required by dashboard compilation.
3732
- name: Deploy contracts

contracts/staking/IStaking.sol

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,10 @@ interface IStaking {
168168
//
169169
//
170170

171-
/// @notice Reduces the liquid T stake amount by the provided amount and
171+
/// @notice Reduces the T stake amount by the provided amount and
172172
/// withdraws T to the owner. Reverts if there is at least one
173-
/// authorization higher than the remaining liquid T stake or
174-
/// if the unstake amount is higher than the liquid T stake amount.
173+
/// authorization higher than the remaining T stake or
174+
/// if the unstake amount is higher than the T stake amount.
175175
/// Can be called only by the delegation owner or the staking
176176
/// provider.
177177
function unstakeT(address stakingProvider, uint96 amount) external;
@@ -232,7 +232,10 @@ interface IStaking {
232232
returns (uint96);
233233

234234
/// @notice Returns staked amount of T for the specified staking provider.
235-
function tStake(address stakingProvider) external view returns (uint96);
235+
function stakeAmount(address stakingProvider)
236+
external
237+
view
238+
returns (uint96);
236239

237240
/// @notice Returns start staking timestamp.
238241
/// @dev This value is set at most once.

contracts/staking/TokenStaking.sol

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
2828
import "@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol";
2929

3030
/// @notice TokenStaking is the main staking contract of the Threshold Network.
31-
/// Additionally, it serves as application manager for the apps
32-
/// that run on the Threshold Network.
31+
/// It serves as application manager for the apps that run on
32+
/// the Threshold Network.
3333
/// @dev TokenStaking is upgradeable, using OpenZeppelin's Upgradeability
3434
/// framework. As such, it is required to satisfy OZ's guidelines, like
3535
/// restrictions on constructors, immutable variables, base contracts and
@@ -39,6 +39,13 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
3939
using PercentUtils for uint256;
4040
using SafeCastUpgradeable for uint256;
4141

42+
// enum is used for Staked event to have backward compatibility
43+
enum StakeType {
44+
NU,
45+
KEEP,
46+
T
47+
}
48+
4249
enum ApplicationStatus {
4350
NOT_APPROVED,
4451
APPROVED,
@@ -47,9 +54,9 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
4754
}
4855

4956
struct StakingProviderInfo {
50-
uint96 legacyNuInTStake;
57+
uint96 nuInTStake;
5158
address owner;
52-
uint96 legacyKeepInTStake;
59+
uint96 keepInTStake;
5360
address payable beneficiary;
5461
uint96 tStake;
5562
address authorizer;
@@ -101,6 +108,7 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
101108
uint256 public slashingQueueIndex;
102109

103110
event Staked(
111+
StakeType indexed stakeType,
104112
address indexed owner,
105113
address indexed stakingProvider,
106114
address beneficiary,
@@ -263,6 +271,7 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
263271
increaseStakeCheckpoint(stakingProvider, amount);
264272

265273
emit Staked(
274+
StakeType.T,
266275
msg.sender,
267276
stakingProvider,
268277
beneficiary,
@@ -641,10 +650,10 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
641650
//
642651
//
643652

644-
/// @notice Reduces the liquid T stake amount by the provided amount and
653+
/// @notice Reduces the T stake amount by the provided amount and
645654
/// withdraws T to the owner. Reverts if there is at least one
646-
/// authorization higher than the remaining liquid T stake or
647-
/// if the unstake amount is higher than the liquid T stake amount.
655+
/// authorization higher than the remaining T stake or
656+
/// if the unstake amount is higher than the T stake amount.
648657
/// Can be called only by the delegation owner or the staking
649658
/// provider.
650659
function unstakeT(address stakingProvider, uint96 amount)
@@ -814,7 +823,7 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
814823
}
815824

816825
/// @notice Returns staked amount of T for the specified staking provider.
817-
function tStake(address stakingProvider)
826+
function stakeAmount(address stakingProvider)
818827
external
819828
view
820829
override

docs/rfc-1-staking-contract.adoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,9 @@ will be added to already authorized applications.
296296

297297
==== `unstakeT(address stakingProvider, uint96 amount) external onlyOwnerOrStakingProvider(stakingProvider)`
298298

299-
Reduces the liquid T stake amount by `amount` and withdraws `amount` of T
299+
Reduces the T stake amount by `amount` and withdraws `amount` of T
300300
to the owner. Reverts if there is at least one authorization higher than the
301-
remaining liquid T stake or if the `amount` is higher than the liquid T stake amount.
301+
remaining T stake or if the `amount` is higher than the T stake amount.
302302
Can be called only by the owner or the staking provider.
303303

304304
=== Keeping information in sync
@@ -342,7 +342,7 @@ each affected application.
342342

343343
Returns the authorized stake amount of the staking provider for the application.
344344

345-
==== `tStake(address stakingProvider) external view returns (uint96)`
345+
==== `stakeAmount(address stakingProvider) external view returns (uint96)`
346346

347347
Returns staked amount of T for the specified staking provider.
348348

package.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,8 @@
5858
"typescript": "^4.4.4"
5959
},
6060
"dependencies": {
61-
"@keep-network/keep-core": ">1.8.1-dev <1.8.1-goerli",
6261
"@openzeppelin/contracts": "~4.5.0",
6362
"@openzeppelin/contracts-upgradeable": "~4.5.2",
6463
"@thesis/solidity-contracts": "github:thesis/solidity-contracts#4985bcf"
65-
},
66-
"peerDependencies": {
67-
"@keep-network/keep-core": ">1.8.1-dev <1.8.1-goerli"
6864
}
6965
}

test/staking/TokenStaking.test.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ const { to1e18 } = helpers.number
66

77
const { AddressZero, Zero } = ethers.constants
88

9+
const StakeTypes = {
10+
NU: 0,
11+
KEEP: 1,
12+
T: 2,
13+
}
14+
915
const ApplicationStatus = {
1016
NOT_APPROVED: 0,
1117
APPROVED: 1,
@@ -288,6 +294,7 @@ describe("TokenStaking", () => {
288294
await expect(tx)
289295
.to.emit(tokenStaking, "Staked")
290296
.withArgs(
297+
StakeTypes.T,
291298
staker.address,
292299
stakingProvider.address,
293300
beneficiary.address,
@@ -3520,7 +3527,7 @@ describe("TokenStaking", () => {
35203527
})
35213528

35223529
async function assertStake(address, expectedTStake) {
3523-
expect(await tokenStaking.tStake(address), "invalid tStake").to.equal(
3530+
expect(await tokenStaking.stakeAmount(address), "invalid tStake").to.equal(
35243531
expectedTStake
35253532
)
35263533
}

yarn.lock

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,14 +1269,6 @@
12691269
resolved "https://registry.yarnpkg.com/@keep-network/hardhat-helpers/-/hardhat-helpers-0.6.0-pre.8.tgz#6e0722889a0132dabed5182fb32f6424ff4a77d0"
12701270
integrity sha512-51oLHceBubutBYxfVk2pLjgyhvpcDC1ahKM3V9lOiTa9lbWyY18Dza7rnM9V04kq+8DbweQRM0M9/f+K26nl9g==
12711271

1272-
"@keep-network/keep-core@>1.8.1-dev <1.8.1-goerli":
1273-
version "1.8.1-dev.0"
1274-
resolved "https://registry.yarnpkg.com/@keep-network/keep-core/-/keep-core-1.8.1-dev.0.tgz#d95864b25800214de43d8840376a68336cb12055"
1275-
integrity sha512-gFXkgN4PYOYCZ14AskL7fZHEFW5mu3BDd+TJKBuKZc1q9CgRMOK+dxpJnSctxmSH1tV+Ln9v9yqlSkfPCoiBHw==
1276-
dependencies:
1277-
"@openzeppelin/upgrades" "^2.7.2"
1278-
openzeppelin-solidity "2.4.0"
1279-
12801272
"@keep-network/prettier-config-keep@github:keep-network/prettier-config-keep":
12811273
version "0.0.1"
12821274
resolved "https://codeload.github.com/keep-network/prettier-config-keep/tar.gz/a1a333e7ac49928a0f6ed39421906dd1e46ab0f3"

0 commit comments

Comments
 (0)