Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

Contracts management #391

Open
wants to merge 58 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
4add333
config
zorancuc Aug 27, 2021
1c0d7cd
upd: ignore debug files
Sep 27, 2021
a5be80c
remove package lock
zorancuc Sep 29, 2021
bd0a228
update gitignore add artifacts
zorancuc Sep 29, 2021
5ab43b1
remove artifacts
zorancuc Sep 29, 2021
dbc4b68
Merge remote-tracking branch 'origin/migrate_hardhat' into migrate_ha…
Oct 13, 2021
2e426b3
chg: test with hardhat
Oct 20, 2021
dbfb1bd
upd: run tests with hardhat
Oct 21, 2021
b16b1c4
refactor: delete old tests
Oct 21, 2021
e20573f
chg: add typescript support
Oct 21, 2021
f4b2a6f
new: typechain
Oct 21, 2021
eb2fbd1
WIP: verify bytecode and storage
Nov 11, 2021
e8403f9
chg: add ValidatorShare deployment
Nov 12, 2021
f4f035c
misc: remove commented code
Nov 15, 2021
2604580
chg: move to yarn. Generate governance command.
Nov 15, 2021
8623e38
chg: generate typechain bindings after installation
Nov 15, 2021
cc27c7f
chg: StakeManager migration
Nov 16, 2021
029d738
upd: remove moonwalker
Nov 16, 2021
586e7b8
upd: translate truffle migrations to the hardhat
Nov 17, 2021
c9bb160
fix: tests
Nov 19, 2021
c9b6686
misc: clean up
Nov 19, 2021
73dfcbb
new: simple preprocessor for solidity files
Nov 19, 2021
5263b92
upd: old files written with #if..#endif
Nov 19, 2021
a39f48f
chg: remove Migrations.sol
Nov 29, 2021
7546c5a
chg: remove legacy script
Nov 29, 2021
14c2436
upd: improve storage verification report
Nov 29, 2021
825d7ff
upd: use yarn and storage verification in CI
Nov 29, 2021
4d3ba66
upd: package information
Nov 29, 2021
15c5184
upd: readme, package license
Nov 29, 2021
a7ae727
upd: more proxies migrations
Nov 30, 2021
148034a
upd: deploy predicates
Dec 1, 2021
29d07b3
upd: CI in PRs
Dec 1, 2021
20ce00b
upd: remove line breaks
Dec 1, 2021
f435f4f
fix: CI config
Dec 1, 2021
69bc69e
fix: config
Dec 1, 2021
c5bbac7
fix: CI config
Dec 1, 2021
bc1ba97
fix: CI config
Dec 1, 2021
e937ac0
fix: use node 14 for CI
Dec 1, 2021
e2eaa04
fix: typechain initial generation
Dec 1, 2021
49121c3
fix: add nunjucks for process templates
Dec 1, 2021
e202162
fix: do not process directories
Dec 1, 2021
eb604a0
fix: extract base type for storage slot
Dec 2, 2021
d756b8b
upd: 1st release types
Dec 2, 2021
88da230
new: StakeManagerExtension migration
Dec 3, 2021
bfc4abb
upd: return back extracting base type of the storage slot
Dec 3, 2021
0adfddb
upd: improve #if #endif blocks to allow multi network conditions
Dec 3, 2021
177e870
fix: tests
Dec 3, 2021
2a586cb
fix: tests
imyourm8 Dec 14, 2021
b9274ae
fix: tests
imyourm8 Dec 14, 2021
f7ab8d8
fix: use child network for testing
imyourm8 Dec 14, 2021
48f2288
fix: do not subtract delegation from timeline if validator is unstaked
Jan 17, 2022
fc58f80
new
Jan 17, 2022
2dd5fe5
chg
Jan 17, 2022
8c9ad51
stuff
Jan 20, 2022
746dfd6
chg
Jan 21, 2022
afd6c6e
Merge branch 'ddsb' into contracts-management
Jan 26, 2022
ff6873a
fix: verify deployed contract automatically
Jan 26, 2022
f9a349d
new: second release
Jan 26, 2022
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
20 changes: 12 additions & 8 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
module.exports = {
parser: 'babel-eslint',
extends: 'standard',
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2020, // Allows for the parsing of modern ECMAScript features
sourceType: 'module' // Allows for the use of imports
},
extends: [
'standard',
'plugin:@typescript-eslint/recommended'
],
env: {
node: true,
es6: true,
mocha: true
},
rules: {
'space-before-function-paren': ['error', 'never']
},
globals: {
contract: true,
web3: true,
assert: true
'space-before-function-paren': ['error', 'never'],
quotes: ['error', 'single'],
semi: ['error', 'never']
}
}
28 changes: 18 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ on:
branches:
- main
pull_request:

branches:
- main
jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -14,18 +15,25 @@ jobs:
- name: Setup Node.js environment
uses: actions/setup-node@v2-beta
with:
node-version: '10.x'
node-version: '14.x'
registry-url: 'https://registry.npmjs.org'
- name: Cache npm dependencies
- name: Install yarn
run: npm install -g yarn
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- name: Cache dependencies
uses: actions/cache@v1
with:
path: ~/.npm
key: ${{ runner.OS }}-npm-cache-${{ hashFiles('**/package-lock.json') }}
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.OS }}-npm-cache-
- name: Install npm dependencies
run: npm install
${{ runner.os }}-yarn-
- name: Install dependencies
run: yarn --prefer-offline
- name: Process templates
run: npm run template:process
run: yarn template:process
- name: Verify contracts storage
run: yarn verify:ci
- name: Run tests
run: npm run test:ci
run: yarn test:ci
13 changes: 11 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
node_modules
build
contractAddresses.json
artifacts

# ignore generated files
contracts/root/predicates/TransferWithSigUtils.sol
contracts/common/mixin/ChainIdMixin.sol
test-blockchain/genesis.json
test-blockchain/start.sh
test/helpers/marketplaceUtils.js
Expand All @@ -22,3 +21,13 @@ test-blockchain/data
coverage/

coverage.json

*.dbg.json

cache/

debug.json

typechain/

contracts-out/
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
11.1.0
14.17.4
34 changes: 20 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,48 @@
# Matic contracts
# Polygon contracts

![Build Status](https://github.com/maticnetwork/contracts/workflows/CI/badge.svg)

Ethereum smart contracts that power the [Matic Network](https://matic.network).
Ethereum smart contracts that power [Polygon sidechain](https://polygon.technology).

### Prerequesties

Yarn and Node 14

### Install dependencies with

```
npm install
yarn
```

### Compile
### Preprocess templates for local BOR

bor-chain-id for Mainnet = 137
bor-chain-id for TestnetV4 (Mumbai) = 80001
bor-chain-id for Testnet (Mumbai) = 15001

For local development you should go with 15001 chain id

```
npm run template:process -- --bor-chain-id <bor-chain-id>
npm run truffle:compile
```

### Start main chain and side chain
### Start root chain and child chain

- Start Main chain
- Start Root chain

```
npm run testrpc
yarn testrpc
```

- Start Matic side chain. Requires docker.

```
npm run bor:simulate
yarn bor:simulate
```

- If you ran a bor instance before, a dead docker container might still be lying around, clean it with

```
npm run bor:clean
yarn bor:clean
```

- Run a bor (our matic chain node) instance.
Expand All @@ -47,13 +52,14 @@ npm run bor:clean
- For local development

```
npm run truffle:migrate
yarn deploy:all --network root --child-url CHILD_URL
```

- For a properly initialized set of contracts, follow the instructions [here](./deploy-migrations/README.md).
By default child url is http://localhost:8545


### Run tests

```
npm test
yarn test
```
23 changes: 0 additions & 23 deletions contracts/Migrations.sol

This file was deleted.

13 changes: 13 additions & 0 deletions contracts/common/mixin/ChainIdMixin.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
pragma solidity ^0.5.2;

contract ChainIdMixin {
#if mainnet root
bytes constant public networkId = hex"89";
uint256 constant public CHAINID = 137;
#endif

#if goerli child
bytes constant public networkId = hex"3A99";
uint256 constant public CHAINID = 15001;
#endif
}
6 changes: 0 additions & 6 deletions contracts/common/mixin/ChainIdMixin.sol.template

This file was deleted.

2 changes: 1 addition & 1 deletion contracts/root/RootChainProxy.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pragma solidity ^0.5.2;

import {RootChainStorage} from "./RootChainStorage.sol";
import {RootChainStorage} from "./RootChainStorage.sol";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added trailing whitespace?

import {Proxy} from "../common/misc/Proxy.sol";
import {Registry} from "../common/Registry.sol";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ library TransferWithSigUtils {
bytes32 EIP712_DOMAIN_SCHEMA_HASH = keccak256(abi.encodePacked(EIP712_DOMAIN_SCHEMA));
string memory EIP712_DOMAIN_NAME = "Matic Network";
string memory EIP712_DOMAIN_VERSION = "1";
uint256 EIP712_DOMAIN_CHAINID = {{ borChainId }};
#if mainnet root
uint256 EIP712_DOMAIN_CHAINID = 137;
#endif
#if goerli child
uint256 EIP712_DOMAIN_CHAINID = 15001;
#endif
bytes32 EIP712_DOMAIN_HASH = keccak256(abi.encode(
EIP712_DOMAIN_SCHEMA_HASH,
keccak256(bytes(EIP712_DOMAIN_NAME)),
Expand Down
21 changes: 14 additions & 7 deletions contracts/staking/stakeManager/StakeManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,14 @@ contract StakeManager is
require(delegationEnabled, "Delegation is disabled");
}

updateTimeline(amount, 0, 0);
uint256 deactivationEpoch = validators[validatorId].deactivationEpoch;

if (deactivationEpoch == 0) { // modify timeline only if validator didn't unstake
updateTimeline(amount, 0, 0);
} else if (deactivationEpoch > currentEpoch) { // validator just unstaked, need to wait till next checkpoint
revert("unstaking");
}


if (amount >= 0) {
increaseValidatorDelegatedAmount(validatorId, uint256(amount));
Expand All @@ -560,11 +567,16 @@ contract StakeManager is
address currentSigner = validators[validatorId].signer;
// update signer event
logger.logSignerChange(validatorId, currentSigner, signer, signerPubkey);

if (validators[validatorId].deactivationEpoch == 0) {
// didn't unstake, swap signer in the list
_removeSigner(currentSigner);
_insertSigner(signer);
}

signerToValidator[currentSigner] = INCORRECT_VALIDATOR_ID;
signerToValidator[signer] = validatorId;
validators[validatorId].signer = signer;
_updateSigner(currentSigner, signer);

// reset update time to current time
latestSignerUpdateEpoch[validatorId] = _currentEpoch;
Expand Down Expand Up @@ -1195,11 +1207,6 @@ contract StakeManager is
}
}

function _updateSigner(address prevSigner, address newSigner) internal {
_removeSigner(prevSigner);
_insertSigner(newSigner);
}

function _removeSigner(address signerToDelete) internal {
uint256 totalSigners = signers.length;
address swapSigner = signers[totalSigners - 1];
Expand Down
8 changes: 8 additions & 0 deletions contracts/staking/validatorShare/ValidatorShare.sol
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,17 @@ contract ValidatorShare is IValidatorShare, ERC20NonTradable, OwnableLockable, I

function _getRatePrecision() private view returns (uint256) {
// if foundation validator, use old precision
#if mainnet root
if (validatorId < 8) {
return EXCHANGE_RATE_PRECISION;
}
#endif

#if goerli
if (validatorId < 9) {
return EXCHANGE_RATE_PRECISION;
}
#endif

return EXCHANGE_RATE_HIGH_PRECISION;
}
Expand Down
4 changes: 3 additions & 1 deletion contracts/test/StakeManagerTestable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { IValidatorShare } from "../staking/validatorShare/IValidatorShare.sol";

contract StakeManagerTestable is StakeManager {
function advanceEpoch(uint256 delta) public {
currentEpoch = currentEpoch.add(delta);
for (uint256 i = 0; i < delta; ++i) {
_finalizeCommit();
}
}

function testLockShareContract(uint256 validatorId, bool lock) public {
Expand Down
5 changes: 0 additions & 5 deletions debug.sh

This file was deleted.

5 changes: 0 additions & 5 deletions deploy-migrations/1_initial_migration.js

This file was deleted.

Loading