Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: PIP-42 change token to POL #4

Merged
merged 96 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
4432f9b
feat: transition to POL
ZeroEkkusu Apr 8, 2024
b6e19be
feat(ValidatorShare): add legacy support
ZeroEkkusu Apr 10, 2024
344af89
fix: remove `topUpForFee` and `claimFee` legacy
ZeroEkkusu Apr 11, 2024
e763e11
fix: add check in `_transferToken`
ZeroEkkusu Apr 11, 2024
9ddfb10
chore: add pr note
ZeroEkkusu May 20, 2024
0c3026a
init legacytoken, migration
ethyla May 22, 2024
7e1fd77
fix: transfer function overload
ethyla May 26, 2024
93cac41
fix: existing tests
ethyla May 29, 2024
9c1df0c
fix: revert formating in sol files
ethyla May 29, 2024
eafb462
fix: allow stakemanager tests to run independently
ethyla May 29, 2024
08895bc
fix: test preparation
ethyla Jun 7, 2024
bed9c42
fix: contracts
ethyla Jun 7, 2024
5c148f9
feat: tests for validatorshare
ethyla Jun 7, 2024
13668cf
feat: tests for legacy staking
ethyla Jun 7, 2024
499d887
fix: move storage to prevent conflicts
ethyla Jun 7, 2024
49e288f
fix: remove unused function
ethyla Jun 8, 2024
b5558ed
fix: move imports
ethyla Jun 8, 2024
21f849e
feat: allow legacy config in test deployments
ethyla Jun 10, 2024
8d64c6e
feat: add initLegacy function
ethyla Jun 10, 2024
2517086
fix: remove unused function
ethyla Jun 12, 2024
5287f4e
fix: remove legacy parameter at claimFee
ethyla Jun 13, 2024
8ee1f45
fix: remove superfluous init functionality
ethyla Jun 13, 2024
a85d63d
fix: typos
ethyla Jun 17, 2024
3652d8b
feat: disable slashing
ethyla Jun 19, 2024
3b60b23
feat: reduce codesize
ethyla Jun 19, 2024
2bce548
fix: tests
ethyla Jun 19, 2024
94fd55f
fix: rename Migration contract
ethyla Jun 20, 2024
b7568fd
fix: inline _claimFee
ethyla Jun 20, 2024
ab70c89
fix: remove unused code
ethyla Jun 20, 2024
a9990cb
fix: inline migrate functions again
ethyla Jun 20, 2024
36a6106
fix: remove all notes
ethyla Jun 20, 2024
2685727
fix: disable slashing tests
ethyla Jun 24, 2024
f8b9a0c
fix: error on multi event failure
ethyla Jun 24, 2024
260ccac
fix: properly pass return value
ethyla Jun 25, 2024
e2c430c
ci: skip forge tests if none
DhairyaSethi Jun 25, 2024
e250752
new: buyVoucherWithPermit
DhairyaSethi Jun 25, 2024
74ed770
test: setup erc20permit for tests
DhairyaSethi Jun 25, 2024
4042da2
chore: _getOrCachePolToken
DhairyaSethi Jun 25, 2024
b802ba6
chore: init pol token
DhairyaSethi Jun 26, 2024
48d200d
chore(validatorShare): disableInitializer
DhairyaSethi Jul 2, 2024
56e66bc
fix: solidity-rlp to 2.0.8 from floating
DhairyaSethi Jul 2, 2024
e76df27
chore(ci): run tests on feat/fix branches
DhairyaSethi Jul 2, 2024
1763f1e
test: buyVoucherWithPermit
DhairyaSethi Jul 2, 2024
f477976
Merge pull request #6 from 0xPolygon/feat/permit
ethyla Jul 2, 2024
544a986
feat: rename legacy to pol
ethyla Jul 7, 2024
55e25fa
fix: tests after rename
ethyla Jul 7, 2024
c22c9a2
fix: topup with pol
ethyla Jul 7, 2024
00ba7e4
feat: simple forktest
ethyla Jul 8, 2024
b3e78a5
prepare forkTest
simonDos Jul 12, 2024
4b864a4
fix tests
simonDos Jul 12, 2024
e7cd12a
work on ci
simonDos Jul 14, 2024
98515a0
generate interfaces before foundry tests
simonDos Jul 15, 2024
4a5dde1
fix interface generation script
simonDos Jul 15, 2024
8759b4f
wip: deployer
ethyla Jul 15, 2024
f5cd0a6
update foundry config
simonDos Jul 15, 2024
a5fd7d6
add UpgradeStakeManager_Sepolia script
simonDos Jul 15, 2024
972b8a0
feat: upgradeStakeManager script
simonDos Jul 15, 2024
855f45e
version 0.4.0
simonDos Jul 15, 2024
ef55dac
feat: upgradeDepositManager script (plasma bridge)
simonDos Jul 15, 2024
c4dedd3
deploy: upgrade impls on sepolia
simonDos Jul 15, 2024
d36f6ab
fix: upgradeDepositManager script
simonDos Jul 16, 2024
9ec1c71
feat: burn matic dynamically
simonDos Jul 22, 2024
558dc87
feat: add mainnet pol upgrade script
ethyla Jul 18, 2024
84e9129
feat: improve mainnet deploy script
ethyla Jul 22, 2024
4b2c7b4
feat: use deploy script in upgrade forktest
ethyla Jul 22, 2024
49bae81
fix: remove fun para
ethyla Jul 22, 2024
8575015
clean
ethyla Jul 22, 2024
4b5c80d
test: extend upgrade forktest
ethyla Jul 22, 2024
069c2be
clean: fmt
ethyla Jul 23, 2024
09e064c
fix: ci coverage
ethyla Jul 23, 2024
32af2e7
fix: ci foundry
ethyla Jul 23, 2024
0f8c9c5
fix: generate interfaces first
ethyla Jul 23, 2024
15435e8
fix: build in script
ethyla Jul 23, 2024
6422d25
fix: ci build
ethyla Jul 23, 2024
22030b4
ci: add token
ethyla Jul 23, 2024
8eb7e37
ci: don't run on non pull branches
ethyla Jul 24, 2024
f6cc0d8
fix: ci and time
ethyla Jul 24, 2024
39abd88
fix: claimfee now sends pol
ethyla Jul 25, 2024
4ba8945
fix: unstake active validators
DhairyaSethi Aug 13, 2024
4b18cbf
chore: rename to avoid collision with `_unstake(valId,exitEpoch,pol)`…
DhairyaSethi Aug 13, 2024
364a8c2
chore: run ci on feat/* pr
DhairyaSethi Aug 13, 2024
f62c3c4
fix: still sending amount on migrate matic
ethyla Aug 19, 2024
08e71ff
fix: make disable init clearer
ethyla Aug 19, 2024
b025f59
fix: print correct depositManagerImpl address
ethyla Aug 19, 2024
993fe48
fix: make init function ordering clearer
ethyla Aug 19, 2024
e33a4b2
fix: disable slashing on validatorshare
ethyla Aug 19, 2024
76632fb
fix: restore init behaiviour
ethyla Aug 19, 2024
be3df7f
fix: consistency in encodeCall
ethyla Aug 19, 2024
bce1353
test: non-idempotentcy of forceUnstake
DhairyaSethi Aug 20, 2024
bd17618
test: make robust
DhairyaSethi Aug 20, 2024
97cb2ef
fix: move check internally to cover for dethroneAndUnstake
DhairyaSethi Aug 20, 2024
f4a5924
feat: improve readme
ethyla Aug 20, 2024
f0bdac8
fix: wrong interface
ethyla Aug 20, 2024
c795e76
Merge pull request #9 from 0xPolygon/fix/forceUnstake
simonDos Aug 22, 2024
064df8a
Merge branch 'feat/pol' into fix/polUpgradeReview
simonDos Aug 22, 2024
753a269
Merge pull request #10 from 0xPolygon/fix/polUpgradeReview
simonDos Aug 22, 2024
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
10 changes: 6 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: CI

on:
push:
branches:
- main
branches: [main, dev]
pull_request:
branches: [main, dev, feat/*]

jobs:
build:
Expand Down Expand Up @@ -42,11 +42,13 @@ jobs:

- name: Run Forge build
run: |
npm run generate:interfaces
forge --version
forge build --sizes
id: build

- name: Run Forge tests
run: |
forge test -vvv
env:
INFURA_TOKEN: ${{ secrets.INFURA_TOKEN }}
run: forge test -vvv
id: test
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ contractAddresses.json


# ignore generated files
broadcast/*/*/dry-run
contracts/root/predicates/TransferWithSigUtils.sol
contracts/common/mixin/ChainIdMixin.sol
test/helpers/marketplaceUtils.js
cache_hardhat
forge-cache
scripts/helpers/interfaces
cache_hardhat/
forge-cache/


test-bor-docker/history
Expand Down
5 changes: 4 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@
url = https://github.com/0xPolygon/contract-deployer-template
[submodule "lib/storage-layout-checker"]
path = lib/storage-layout-checker
url = https://github.com/0xPolygon/storage-layout-checker
url = https://github.com/0xPolygon/storage-layout-checker
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
38 changes: 28 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@

Ethereum smart contracts that power the [Matic Network](https://polygon.technology/polygon-pos).

## Development
### Install dependencies with

```
npm install
```

### Setup
### Setup git hooks

```
pre-commit install
```

### Compile
### Prepare templates

```
npm run template:process -- --bor-chain-id 15001
Expand All @@ -27,7 +28,30 @@ bor-chain-id should be:
Mainnet = 137
TestnetV4 (Mumbai) = 80001

### Main chain and side chain
### Generate interfaces

```
npm run generate:interfaces
```

### Build

```
forge build
```

## Testing

### Run forge upgrade forktest

```
forge test
```

### Run unit tests


#### Main chain and side chain

- Main chain

Expand All @@ -51,20 +75,14 @@ npm run bor:stop
npm run bor:clean
```

### Run tests
#### Run tests

Run Hardhat test

```
npm test:hardhat
```

Run Foundry test

```
npm test:foundry
```

### Coverage

Run coverage with
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

112 changes: 112 additions & 0 deletions broadcast/UpgradeStakeManager_Sepolia.s.sol/11155111/run-latest.json

Large diffs are not rendered by default.

109 changes: 109 additions & 0 deletions contracts/common/misc/EIP712.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.5.17;

/*
meant for testing only, adapted from: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v5.0.2/contracts/utils/cryptography/EIP712.sol
modifications:
- removed `immutable` since was it introduced in solidity 0.6.5 but we have to adhere to 0.5.17
- added chainId method since block.chainid isn't available yet
- removed `_nameFallback` & `_versionFallback`
*/

contract EIP712 {
/* solhint-disable var-name-mixedcase */
// Cache the domain separator as an immutable value, but also store the chain id that it corresponds to, in order to
// invalidate the cached domain separator if the chain id changes.
bytes32 private _CACHED_DOMAIN_SEPARATOR;
uint256 private _CACHED_CHAIN_ID;

bytes32 private _HASHED_NAME;
bytes32 private _HASHED_VERSION;
bytes32 private _TYPE_HASH;

string private _VERSION;
/* solhint-enable var-name-mixedcase */

/**
* @dev Initializes the domain separator and parameter caches.
*
* The meaning of `name` and `version` is specified in
* https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP 712]:
*
* - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol.
* - `version`: the current major version of the signing domain.
*
* NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart
* contract upgrade].
*/
constructor(string memory name, string memory version) public {
bytes32 hashedName = keccak256(bytes(name));
bytes32 hashedVersion = keccak256(bytes(version));
bytes32 typeHash = keccak256(
"EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"
);
_HASHED_NAME = hashedName;
_HASHED_VERSION = hashedVersion;
_CACHED_CHAIN_ID = _chainId();
_CACHED_DOMAIN_SEPARATOR = _buildDomainSeparator(typeHash, hashedName, hashedVersion);
_TYPE_HASH = typeHash;
}

function version() external view returns (string memory) {
return _VERSION;
}

function _chainId() internal pure returns (uint chainId) {
assembly {
chainId := chainid()
}
}

/**
* @dev Returns the domain separator for the current chain.
*/
function _domainSeparatorV4() internal view returns (bytes32) {
if (_chainId() == _CACHED_CHAIN_ID) {
return _CACHED_DOMAIN_SEPARATOR;
} else {
return _buildDomainSeparator(_TYPE_HASH, _HASHED_NAME, _HASHED_VERSION);
}
}

function _buildDomainSeparator(
bytes32 typeHash,
bytes32 nameHash,
bytes32 versionHash
) private view returns (bytes32) {
return keccak256(abi.encode(typeHash, nameHash, versionHash, _chainId(), address(this)));
}

/**
* @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this
* function returns the hash of the fully encoded EIP712 message for this domain.
*
* This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example:
*
* ```solidity
* bytes32 digest = _hashTypedDataV4(keccak256(abi.encode(
* keccak256("Mail(address to,string contents)"),
* mailTo,
* keccak256(bytes(mailContents))
* )));
* address signer = ECDSA.recover(digest, signature);
* ```
*/
function _hashTypedDataV4(bytes32 structHash) internal view returns (bytes32) {
return _toTypedDataHash(_domainSeparatorV4(), structHash);
}

/**
* @dev Returns an Ethereum Signed Typed Data, created from a
* `domainSeparator` and a `structHash`. This produces hash corresponding
* to the one signed with the
* https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`]
* JSON-RPC method as part of EIP-712.
*/
function _toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash));
}
}
19 changes: 19 additions & 0 deletions contracts/common/misc/IERC20Permit.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.5.17;

interface IERC20Permit {
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;

function nonces(address owner) external view returns (uint256);

// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}
10 changes: 10 additions & 0 deletions contracts/common/misc/IPolygonMigration.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
pragma solidity 0.5.17;

interface IPolygonMigration {
event Migrated(address indexed account, uint256 amount);
event Unmigrated(address indexed account, address indexed recipient, uint256 amount);
event UnmigrationLockUpdated(bool lock);

function migrate(uint256 amount) external;
function unmigrate(uint256 amount) external;
}
80 changes: 80 additions & 0 deletions contracts/common/misc/ITimelock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.4;

// extracted using cast interface 0xCaf0aa768A3AE1297DF20072419Db8Bb8b5C8cEf

interface Timelock {
event CallExecuted(bytes32 indexed id, uint256 indexed index, address target, uint256 value, bytes data);
event CallScheduled(
bytes32 indexed id,
uint256 indexed index,
address target,
uint256 value,
bytes data,
bytes32 predecessor,
uint256 delay
);
event Cancelled(bytes32 indexed id);
event MinDelayChange(uint256 oldDuration, uint256 newDuration);
event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);
event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);

receive() external payable;

function DEFAULT_ADMIN_ROLE() external view returns (bytes32);
function EXECUTOR_ROLE() external view returns (bytes32);
function PROPOSER_ROLE() external view returns (bytes32);
function TIMELOCK_ADMIN_ROLE() external view returns (bytes32);
function cancel(bytes32 id) external;
function execute(address target, uint256 value, bytes memory data, bytes32 predecessor, bytes32 salt)
external
payable;
function executeBatch(
address[] memory targets,
uint256[] memory values,
bytes[] memory datas,
bytes32 predecessor,
bytes32 salt
) external payable;
function getMinDelay() external view returns (uint256 duration);
function getRoleAdmin(bytes32 role) external view returns (bytes32);
function getTimestamp(bytes32 id) external view returns (uint256 timestamp);
function grantRole(bytes32 role, address account) external;
function hasRole(bytes32 role, address account) external view returns (bool);
function hashOperation(address target, uint256 value, bytes memory data, bytes32 predecessor, bytes32 salt)
external
pure
returns (bytes32 hash);
function hashOperationBatch(
address[] memory targets,
uint256[] memory values,
bytes[] memory datas,
bytes32 predecessor,
bytes32 salt
) external pure returns (bytes32 hash);
function isOperation(bytes32 id) external view returns (bool pending);
function isOperationDone(bytes32 id) external view returns (bool done);
function isOperationPending(bytes32 id) external view returns (bool pending);
function isOperationReady(bytes32 id) external view returns (bool ready);
function renounceRole(bytes32 role, address account) external;
function revokeRole(bytes32 role, address account) external;
function schedule(
address target,
uint256 value,
bytes memory data,
bytes32 predecessor,
bytes32 salt,
uint256 delay
) external;
function scheduleBatch(
address[] memory targets,
uint256[] memory values,
bytes[] memory datas,
bytes32 predecessor,
bytes32 salt,
uint256 delay
) external;
function supportsInterface(bytes4 interfaceId) external view returns (bool);
function updateDelay(uint256 newDelay) external;
}
Loading