Skip to content

Commit

Permalink
Merge pull request #4 from 0xPolygon/feat/pol
Browse files Browse the repository at this point in the history
feat: PIP-42 change token to POL
  • Loading branch information
simonDos authored Aug 22, 2024
2 parents 383f0a6 + 753a269 commit 4857f3f
Show file tree
Hide file tree
Showing 47 changed files with 5,047 additions and 537 deletions.
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

0 comments on commit 4857f3f

Please sign in to comment.