Skip to content

Commit 9041a3b

Browse files
authored
Merge branch 'main' into add-codeowners
2 parents 9051968 + 0de3da5 commit 9041a3b

File tree

11 files changed

+1053
-227
lines changed

11 files changed

+1053
-227
lines changed

.github/workflows/contracts.yaml

Lines changed: 98 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,25 @@ on:
77
branches:
88
- main
99
pull_request:
10+
# We intend to use `workflow dispatch` in two different situations/paths:
11+
# 1. If a workflow will be manually dspatched from branch named
12+
# `dapp-development`, workflow will deploy the contracts on the selected
13+
# testnet and publish them to NPM registry with `dapp-dev-<environment>`
14+
# suffix and `dapp-development-<environment>` tag. Such packages are meant
15+
# to be used locally by the team developing Threshold Token dApp and may
16+
# contain contracts that have different values from the ones used on
17+
# mainnet.
18+
# 2. If a workflow will be manually dspatched from a branch which name is not
19+
# `dapp-development`, the workflow will deploy the contracts on the
20+
# selected testnet and publish them to NPM registry with `<environment>`
21+
# suffix and tag. Such packages will be used later to deploy public
22+
# Threshold Token dApp on a testnet, with contracts resembling those used
23+
# on mainnet.
1024
workflow_dispatch:
1125
inputs:
1226
environment:
13-
description: "Environment for workflow execution"
27+
description: "Environment (network) for workflow execution, e.g. `goerli`"
1428
required: false
15-
default: "dev"
1629
upstream_builds:
1730
description: "Upstream builds"
1831
required: false
@@ -27,7 +40,7 @@ jobs:
2740
outputs:
2841
system-tests: ${{ steps.filter.outputs.system-tests }}
2942
steps:
30-
- uses: actions/checkout@v2
43+
- uses: actions/checkout@v3
3144
if: github.event_name == 'pull_request'
3245

3346
- uses: dorny/paths-filter@v2
@@ -42,9 +55,9 @@ jobs:
4255
contracts-build-and-test:
4356
runs-on: ubuntu-latest
4457
steps:
45-
- uses: actions/checkout@v2
58+
- uses: actions/checkout@v3
4659

47-
- uses: actions/setup-node@v2
60+
- uses: actions/setup-node@v3
4861
with:
4962
node-version: "14.x"
5063
cache: "yarn"
@@ -56,16 +69,19 @@ jobs:
5669
run: yarn build
5770

5871
- name: Run tests
72+
if: github.ref != 'refs/heads/dapp-development'
5973
run: yarn test
6074

6175
contracts-system-tests:
6276
needs: contracts-detect-changes
63-
if: needs.contracts-detect-changes.outputs.system-tests == 'true'
77+
if: |
78+
needs.contracts-detect-changes.outputs.system-tests == 'true'
79+
&& github.ref != 'refs/heads/dapp-development'
6480
runs-on: ubuntu-latest
6581
steps:
66-
- uses: actions/checkout@v2
82+
- uses: actions/checkout@v3
6783

68-
- uses: actions/setup-node@v2
84+
- uses: actions/setup-node@v3
6985
with:
7086
node-version: "14.x"
7187
cache: "yarn"
@@ -84,9 +100,9 @@ jobs:
84100
contracts-deployment-dry-run:
85101
runs-on: ubuntu-latest
86102
steps:
87-
- uses: actions/checkout@v2
103+
- uses: actions/checkout@v3
88104

89-
- uses: actions/setup-node@v2
105+
- uses: actions/setup-node@v3
90106
with:
91107
node-version: "14.x"
92108
cache: "yarn"
@@ -99,12 +115,14 @@ jobs:
99115

100116
contracts-deployment-testnet:
101117
needs: [contracts-build-and-test]
102-
if: github.event_name == 'workflow_dispatch'
118+
if: |
119+
github.event_name == 'workflow_dispatch'
120+
&& github.ref != 'refs/heads/dapp-development'
103121
runs-on: ubuntu-latest
104122
steps:
105-
- uses: actions/checkout@v2
123+
- uses: actions/checkout@v3
106124

107-
- uses: actions/setup-node@v2
125+
- uses: actions/setup-node@v3
108126
with:
109127
node-version: "14.x"
110128
cache: "yarn"
@@ -154,7 +172,7 @@ jobs:
154172
version: ${{ steps.npm-version-bump.outputs.version }}
155173

156174
- name: Upload files needed for etherscan verification
157-
uses: actions/upload-artifact@v2
175+
uses: actions/upload-artifact@v3
158176
with:
159177
name: Artifacts for etherscan verifcation
160178
path: |
@@ -166,14 +184,14 @@ jobs:
166184
needs: [contracts-deployment-testnet]
167185
runs-on: ubuntu-latest
168186
steps:
169-
- uses: actions/checkout@v2
187+
- uses: actions/checkout@v3
170188

171189
- name: Download files needed for etherscan verification
172-
uses: actions/download-artifact@v2
190+
uses: actions/download-artifact@v3
173191
with:
174192
name: Artifacts for etherscan verifcation
175193

176-
- uses: actions/setup-node@v2
194+
- uses: actions/setup-node@v3
177195
with:
178196
node-version: "14.x"
179197
cache: "yarn"
@@ -196,20 +214,80 @@ jobs:
196214
yarn run hardhat --network ${{ github.event.inputs.environment }} \
197215
etherscan-verify --license GPL-3.0 --force-license
198216
217+
# This job is responsible for publishing packages from `dapp-development`
218+
# branch, which are slightly modified to help with the process of testing some
219+
# features on the Threshold Token dApp. The job starts only if workflow gets
220+
# triggered by the `workflow_dispatch` event on the branch `dapp-development`.
221+
contracts-dapp-development-deployment-testnet:
222+
needs: [contracts-build-and-test]
223+
if: |
224+
github.event_name == 'workflow_dispatch'
225+
&& github.ref == 'refs/heads/dapp-development'
226+
runs-on: ubuntu-latest
227+
steps:
228+
- uses: actions/checkout@v3
229+
230+
- uses: actions/setup-node@v3
231+
with:
232+
node-version: "14.x"
233+
cache: "yarn"
234+
registry-url: "https://registry.npmjs.org"
235+
236+
- name: Install dependencies
237+
run: yarn install --frozen-lockfile
238+
239+
- name: Resolve latest contracts
240+
run: yarn upgrade @keep-network/keep-core@${{ github.event.inputs.environment }}
241+
242+
- name: Deploy contracts
243+
env:
244+
CHAIN_API_URL: ${{ secrets.GOERLI_ETH_HOSTNAME_HTTP }}
245+
CONTRACT_OWNER_ACCOUNT_PRIVATE_KEY: ${{ secrets.DAPP_DEV_GOERLI_ETH_CONTRACT_OWNER_PRIVATE_KEY }}
246+
KEEP_CONTRACT_OWNER_ACCOUNT_PRIVATE_KEY: ${{ secrets.GOERLI_KEEP_ETH_CONTRACT_OWNER_PRIVATE_KEY }}
247+
run: yarn deploy --network ${{ github.event.inputs.environment }}
248+
249+
- name: Bump up package version
250+
id: npm-version-bump
251+
uses: keep-network/npm-version-bump@v2
252+
with:
253+
environment: dapp-dev-${{ github.event.inputs.environment }}
254+
branch: ${{ github.ref }}
255+
commit: ${{ github.sha }}
256+
257+
- name: Publish to npm
258+
env:
259+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
260+
run: |
261+
npm publish --access=public \
262+
--network=${{ github.event.inputs.environment }} \
263+
--tag dapp-development-${{ github.event.inputs.environment }}
264+
265+
- name: Notify CI about completion of the workflow
266+
uses: keep-network/ci/actions/notify-workflow-completed@v2
267+
env:
268+
GITHUB_TOKEN: ${{ secrets.CI_GITHUB_TOKEN }}
269+
with:
270+
module: "github.com/threshold-network/solidity-contracts"
271+
url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
272+
environment: ${{ github.event.inputs.environment }}
273+
upstream_builds: ${{ github.event.inputs.upstream_builds }}
274+
upstream_ref: dapp-development
275+
version: ${{ steps.npm-version-bump.outputs.version }}
276+
199277
contracts-slither:
200278
runs-on: ubuntu-latest
201279
if: |
202280
github.event_name != 'workflow_dispatch'
203281
&& github.event_name != 'schedule'
204282
steps:
205-
- uses: actions/checkout@v2
283+
- uses: actions/checkout@v3
206284

207-
- uses: actions/setup-node@v2
285+
- uses: actions/setup-node@v3
208286
with:
209287
node-version: "14"
210288
cache: "yarn"
211289

212-
- uses: actions/setup-python@v2
290+
- uses: actions/setup-python@v4
213291
with:
214292
python-version: 3.8.5
215293

.github/workflows/format.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ jobs:
1111
code-lint-and-format:
1212
runs-on: ubuntu-latest
1313
steps:
14-
- uses: actions/checkout@v2
14+
- uses: actions/checkout@v3
1515

16-
- uses: actions/setup-node@v2
16+
- uses: actions/setup-node@v3
1717
with:
1818
node-version: "14"
1919
cache: "yarn"

.github/workflows/npm.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ jobs:
1616
npm-compile-publish-contracts:
1717
runs-on: ubuntu-latest
1818
steps:
19-
- uses: actions/checkout@v2
19+
- uses: actions/checkout@v3
2020

21-
- uses: actions/setup-node@v2
21+
- uses: actions/setup-node@v3
2222
with:
2323
node-version: "14.x"
2424
registry-url: "https://registry.npmjs.org"

contracts/staking/IApplication.sol

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ interface IApplication {
4848
/// pending decrease and respond to the staking contract with
4949
/// `approveAuthorizationDecrease` at its discretion. It may
5050
/// happen right away but it also may happen several months later.
51+
/// If there is already a pending authorization decrease request
52+
/// for the application, and the application does not agree for
53+
/// overwriting it, the function should revert.
5154
function authorizationDecreaseRequested(
5255
address stakingProvider,
5356
uint96 fromAmount,

contracts/staking/IStaking.sol

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ interface IStaking {
7070
address authorizer
7171
) external;
7272

73-
/// @notice Refresh Keep stake owner. Can be called only by the old owner.
73+
/// @notice Refresh Keep stake owner. Can be called only by the old owner
74+
/// or their staking provider.
7475
/// @dev The staking provider in T staking contract is the legacy KEEP
7576
/// staking contract operator.
7677
function refreshKeepStakeOwner(address stakingProvider) external;
@@ -109,7 +110,9 @@ interface IStaking {
109110
/// it happens depends on the application. Can only be called by the
110111
/// given staking provider’s authorizer. Overwrites pending
111112
/// authorization decrease for the given staking provider and
112-
/// application.
113+
/// application if the application agrees for that. If the
114+
/// application does not agree for overwriting, the function
115+
/// reverts.
113116
/// @dev Calls `authorizationDecreaseRequested(address stakingProvider, uint256 amount)`
114117
/// on the given application. See `IApplication`.
115118
function requestAuthorizationDecrease(
@@ -180,7 +183,6 @@ interface IStaking {
180183
//
181184

182185
/// @notice Increases the amount of the stake for the given staking provider.
183-
/// Can be called only by the owner or the staking provider.
184186
/// @dev The sender of this transaction needs to have the amount approved to
185187
/// transfer to the staking contract.
186188
function topUp(address stakingProvider, uint96 amount) external;

contracts/staking/KeepStake.sol

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@ interface IManagedGrant {
2828
/// KEEP stakers to use their stakes in T network and weights them based
2929
/// on KEEP<>T token ratio. KEEP stake owner is cached in T staking
3030
/// contract and used to restrict access to all functions only owner or
31-
/// operator should call. To cache KEEP staking contract in T staking
32-
/// contract, it fitst needs to resolve the owner. Resolving liquid
33-
/// KEEP stake owner is easy. Resolving token grant stake owner is
34-
/// complicated and not possible to do on-chain from a contract external
35-
/// to KEEP TokenStaking contract. Keep TokenStaking knows the grant ID
36-
/// but does not expose it externally.
31+
/// operator should call. To cache KEEP stake owner in T staking
32+
/// contract, T staking contract first needs to resolve the owner.
33+
///
34+
/// Resolving liquid KEEP stake owner is easy. Resolving token grant
35+
/// stake owner is complicated and not possible to do on-chain from
36+
/// a contract external to KEEP TokenStaking contract. Keep TokenStaking
37+
/// knows the grant ID but does not expose it externally.
3738
///
3839
/// KeepStake contract addresses this problem by exposing
3940
/// operator-owner mappings snapshotted off-chain based on events and

contracts/staking/TokenStaking.sol

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,10 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
283283
createdAt == 0 && stakingProviderStruct.owner == address(0),
284284
"Provider is already in use"
285285
);
286-
require(amount > minTStakeAmount, "Amount is less than minimum");
286+
require(
287+
amount > 0 && amount >= minTStakeAmount,
288+
"Amount is less than minimum"
289+
);
287290
stakingProviderStruct.owner = msg.sender;
288291
stakingProviderStruct.authorizer = authorizer;
289292
stakingProviderStruct.beneficiary = beneficiary;
@@ -397,17 +400,18 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
397400
);
398401
}
399402

400-
/// @notice Refresh Keep stake owner. Can be called only by the old owner.
403+
/// @notice Refresh Keep stake owner. Can be called only by the old owner
404+
/// or their staking provider.
401405
/// @dev The staking provider in T staking contract is the legacy KEEP
402406
/// staking contract operator.
403-
function refreshKeepStakeOwner(address stakingProvider) external override {
407+
function refreshKeepStakeOwner(address stakingProvider)
408+
external
409+
override
410+
onlyOwnerOrStakingProvider(stakingProvider)
411+
{
404412
StakingProviderInfo storage stakingProviderStruct = stakingProviders[
405413
stakingProvider
406414
];
407-
require(
408-
stakingProviderStruct.owner == msg.sender,
409-
"Caller is not owner"
410-
);
411415
address newOwner = keepStake.resolveOwner(stakingProvider);
412416

413417
emit OwnerRefreshed(
@@ -713,14 +717,13 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
713717
//
714718

715719
/// @notice Increases the amount of the stake for the given staking provider.
716-
/// Can be called only by the owner or the staking provider.
717720
/// @dev The sender of this transaction needs to have the amount approved to
718721
/// transfer to the staking contract.
719-
function topUp(address stakingProvider, uint96 amount)
720-
external
721-
override
722-
onlyOwnerOrStakingProvider(stakingProvider)
723-
{
722+
function topUp(address stakingProvider, uint96 amount) external override {
723+
require(
724+
stakingProviders[stakingProvider].owner != address(0),
725+
"Nothing to top-up"
726+
);
724727
require(amount > 0, "Parameters must be specified");
725728
StakingProviderInfo storage stakingProviderStruct = stakingProviders[
726729
stakingProvider
@@ -1281,7 +1284,9 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
12811284
/// it happens depends on the application. Can only be called by the
12821285
/// given staking provider’s authorizer. Overwrites pending
12831286
/// authorization decrease for the given staking provider and
1284-
/// application.
1287+
/// application if the application agrees for that. If the
1288+
/// application does not agree for overwriting, the function
1289+
/// reverts.
12851290
/// @dev Calls `authorizationDecreaseRequested` callback on the given
12861291
/// application. See `IApplication`.
12871292
function requestAuthorizationDecrease(

docs/rfc-1-staking-contract.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,11 +389,11 @@ protect against DoSing slashing queue. Can only be called by the governance.
389389

390390
=== Stake top-up
391391

392-
==== `topUp(address stakingProvider, uint96 amount) external onlyOwnerOrStakingProvider(stakingProvider)`
392+
==== `topUp(address stakingProvider, uint96 amount) external`
393393

394394
Increases the amount of the stake for the given staking provider. The sender of this
395395
transaction needs to have the amount approved to transfer to the staking
396-
contract. Can be called only by the owner or staking provider.
396+
contract.
397397

398398
==== `topUpKeep(address stakingProvider) external onlyOwnerOrStakingProvider(stakingProvider)`
399399

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@
4545
"eslint": "^7.27.0",
4646
"eslint-config-keep": "github:keep-network/eslint-config-keep#0c27ade",
4747
"ethereum-waffle": "^3.4.0",
48-
"ethers": "^5.4.1",
49-
"hardhat": "^2.6.8",
50-
"hardhat-contract-sizer": "^2.1.1",
51-
"hardhat-deploy": "^0.9.4",
52-
"hardhat-gas-reporter": "^1.0.4",
48+
"ethers": "^5.5.3",
49+
"hardhat": "^2.8.3",
50+
"hardhat-contract-sizer": "^2.5.0",
51+
"hardhat-deploy": "^0.9.27",
52+
"hardhat-gas-reporter": "^1.0.6",
5353
"prettier": "^2.3.2",
5454
"prettier-plugin-sh": "^0.7.1",
5555
"prettier-plugin-solidity": "^1.0.0-beta.14 ",

0 commit comments

Comments
 (0)