diff --git a/.babelrc b/.babelrc deleted file mode 100644 index 002b4aa0d..000000000 --- a/.babelrc +++ /dev/null @@ -1,3 +0,0 @@ -{ - "presets": ["env"] -} diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 5b8c7643d..000000000 --- a/.editorconfig +++ /dev/null @@ -1,14 +0,0 @@ -root = true - -[*] -indent_style = space -indent_size = 2 -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true -max_line_length = 80 - -[*.md] -trim_trailing_whitespace = false -max_line_length = 80 diff --git a/.env.example b/.env.example new file mode 100644 index 000000000..10eb025f4 --- /dev/null +++ b/.env.example @@ -0,0 +1,4 @@ +INFURA_TOKEN="909b972ab2ff3afb8b0f8f6a9667test" +BOR_CHAIN_URL="http://localhost:9545" +ENV="local" +MNEMONIC_DEV="poly radar mass judge dismiss just intact mind resemble fringe diary casino" \ No newline at end of file diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 11a03cb0a..000000000 --- a/.eslintrc.js +++ /dev/null @@ -1,17 +0,0 @@ -module.exports = { - parser: 'babel-eslint', - extends: 'standard', - env: { - node: true, - es6: true, - mocha: true - }, - rules: { - 'space-before-function-paren': ['error', 'never'] - }, - globals: { - contract: true, - web3: true, - assert: true - } -} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9dd55761a..6d92583ea 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,7 +2,7 @@ name: CI on: push: - branches: + branches: - main pull_request: @@ -10,22 +10,43 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Setup Node.js environment - uses: actions/setup-node@v2-beta - with: - node-version: '10.x' - registry-url: 'https://registry.npmjs.org' - - name: Cache npm dependencies - uses: actions/cache@v1 - with: - path: ~/.npm - key: ${{ runner.OS }}-npm-cache-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.OS }}-npm-cache- - - name: Install npm dependencies - run: npm install - - name: Process templates - run: npm run template:process - - name: Run tests - run: npm run test:ci + - uses: actions/checkout@v4 + + - name: Setup Node.js environment + uses: actions/setup-node@v4 + with: + node-version: "20.x" + registry-url: "https://registry.npmjs.org" + + - name: Cache npm dependencies + uses: actions/cache@v4 + with: + path: ~/.npm + key: ${{ runner.OS }}-npm-cache-${{ hashFiles('./package-lock.json') }} + restore-keys: | + ${{ runner.OS }}-npm-cache- + + - name: Install npm dependencies + run: npm install + + - name: Process templates + run: npm run template:process + + - name: Run Coverage and Hardhat tests + run: npm run test:ci + + - name: Install Foundry + uses: foundry-rs/foundry-toolchain@v1 + with: + version: nightly + + - name: Run Forge build + run: | + forge --version + forge build --sizes + id: build + + - name: Run Forge tests + run: | + forge test -vvv + id: test diff --git a/.gitignore b/.gitignore index 12942d270..11887e4e4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,22 +1,26 @@ node_modules -build +artifacts +out contractAddresses.json +.vscode + # 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 +cache_hardhat +forge-cache + -test-blockchain/geth -test-blockchain/history -test-blockchain/data +test-bor-docker/history +test-bor-docker/data *.pid *.log .DS_Store +.vscode *.env coverage/ diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 000000000..3b1310061 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,12 @@ +[submodule "lib/solady"] + path = lib/solady + url = https://github.com/vectorized/solady +[submodule "lib/deployment-log-generator"] + path = lib/deployment-log-generator + url = https://github.com/0xPolygon/deployment-log-generator +[submodule "lib/contract-deployer-template"] + path = lib/contract-deployer-template + 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 \ No newline at end of file diff --git a/.nvmrc b/.nvmrc index 68d8f15e2..1cc433a12 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -11.1.0 +20.6.0 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..e44295d8e --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,30 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: mixed-line-ending + args: ["--fix=lf"] + description: Forces to replace line ending by the UNIX 'lf' character. + exclude: "^docs/autogen" + - repo: local + hooks: + - id: format + name: Format solidity code + description: Format solidity code with `forge fmt` + language: system + entry: forge fmt + exclude: "^lib/" + pass_filenames: true + - id: doc + name: Generate documentation + description: Generate docs with `forge doc` + language: system + # generates docs and unstages files if only the commit hash changed within the file, this way only when the documentation is updated, the documentation needs to be regenerated and only the changed files are pushed + entry: "scripts/util/doc_gen.sh" + pass_filenames: false + - repo: https://github.com/pre-commit/mirrors-prettier + rev: "v3.0.3" + hooks: + - id: prettier + name: Format non solidity files with prettier + exclude: "^docs/autogen" diff --git a/.prettierrc b/.prettierrc index cac10ecf9..155c7a32b 100644 --- a/.prettierrc +++ b/.prettierrc @@ -10,6 +10,16 @@ "bracketSpacing": false, "explicitTypes": "always" } + }, + { + "files": "*.js", + "options": { + "semi": false, + "singleQuote": true, + "tabWidth": 2, + "printWidth": 120, + "trailingComma": "none" + } } ] } diff --git a/.solcover.cjs b/.solcover.cjs new file mode 100644 index 000000000..e7c498688 --- /dev/null +++ b/.solcover.cjs @@ -0,0 +1,7 @@ +module.exports = { + mocha: { + grep: "@skip-on-coverage", // Find everything with this tag + invert: true, // Run the grep's inverse set. + }, + compileCommand: "npx hardhat compile", +}; diff --git a/.solcover.js b/.solcover.js deleted file mode 100644 index 171479a54..000000000 --- a/.solcover.js +++ /dev/null @@ -1,14 +0,0 @@ -module.exports = { - mocha: { - grep: "@skip-on-coverage", // Find everything with this tag - invert: true // Run the grep's inverse set. - }, - providerOptions: { - // port: 8545, - mnemonic: "clock radar mass judge dismiss just intact mind resemble fringe diary casino", - gasLimit: 9007199254740991, - gasPrice: 0, - allowUnlimitedContractSize: true - }, - compileCommand: 'npm run truffle:compile' -}; diff --git a/.soliumrc.json b/.soliumrc.json index 03d5f6097..264b4a602 100644 --- a/.soliumrc.json +++ b/.soliumrc.json @@ -14,7 +14,7 @@ "no-unused-vars": 1, "quotes": 1, "error-reason": 0, - "indentation": ["error", 2], + "indentation": ["error", 4], "arg-overflow": ["error", 8], "whitespace": 1, "deprecated-suicide": 1, diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 000000000..d1eb1dcc4 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,177 @@ +# Contributing + +- [Install](#install) +- [Pre-commit Hooks](#pre-commit-hooks) +- [Branching](#branching) + - [Main](#main) + - [Staging](#staging) + - [Dev](#dev) + - [Feature](#feature) + - [Fix](#fix) +- [Code Practices](#code-practices) + - [Code Style](#code-style) + - [Interfaces](#interfaces) + - [NatSpec \& Comments](#natspec--comments) +- [Versioning](#versioning) +- [Testing](#testing) + - [Deployer Template](#deployer-template) +- [Deployment](#deployment) + - [Deployer Template](#deployer-template-1) + - [Deployment](#deployment-1) + - [Deployment Info Generation](#deployment-info-generation) +- [Deployer Template Script](#deployer-template-script) +- [Releases](#releases) + +## Install + +Follow these steps to set up your local environment for development: + +- [Install foundry](https://book.getfoundry.sh/getting-started/installation) +- Install dependencies: `forge install` +- [Install pre-commit](https://pre-commit.com/#installation) +- Install pre commit hooks: `pre-commit install` + +## Pre-commit Hooks + +Follow the [installation steps](#install) to enable pre-commit hooks. To ensure consistency in our formatting `pre-commit` is used to check whether code was formatted properly and the documentation is up to date. Whenever a commit does not meet the checks implemented by pre-commit, the commit will fail and the pre-commit checks will modify the files to make the commits pass. Include these changes in your commit for the next commit attempt to succeed. On pull requests the CI checks whether all pre-commit hooks were run correctly. +This repo includes the following pre-commit hooks that are defined in the `.pre-commit-config.yaml`: + +- `mixed-line-ending`: This hook ensures that all files have the same line endings (LF). +- `format`: This hook uses `forge fmt` to format all Solidity files. +- `doc`: This hook uses `forge doc` to automatically generate documentation for all Solidity files whenever the NatSpec documentation changes. The `script/util/doc_gen.sh` script is used to generate documentation. Forge updates the commit hash in the documentation automatically. To only generate new documentation when the documentation has actually changed, the script checks whether more than just the hash has changed in the documentation and discard all changes if only the hash has changed. +- `prettier`: All remaining files are formatted using prettier. + +## Branching + +This section outlines the branching strategy of this repo. + +### Main + +The main branch is supposed to reflect the deployed state on all networks. Any pull requests into this branch MUST come from the staging branch. The main branch is protected and requires a separate code review by the security team. Whenever the main branch is updated, a new release is created with the latest version. For more information on versioning, check [here](#versioning). + +### Staging + +The staging branch reflects new code complete deployments or upgrades containing fixes and/or features. Any pull requests into this branch MUST come from the dev branch. The staging branch is used for security audits and deployments. Once the deployment is complete and deployment log files are generated, the branch can be merged into main. For more information on the deployment and log file generation check [here](#deployment--versioning). + +### Dev + +This is the active development branch. All pull requests into this branch MUST come from fix or feature branches. Upon code completion this branch is merged into staging for auditing and deployment. + +### Feature + +Any new feature should be developed on a separate branch. The naming convention for these branches is `feat/*`. Once the feature is complete, a pull request into the dev branch can be created. + +### Fix + +Any bug fixes should be developed on a separate branch. The naming convention for these branches is `fix/*`. Once the fix is complete, a pull request into the dev branch can be created. + +## Code Practices + +### Code Style + +The repo follows the official [Solidity Style Guide](https://docs.soliditylang.org/en/latest/style-guide.html). In addition to that, this repo also borrows the following rules from [OpenZeppelin](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/GUIDELINES.md#solidity-conventions): + +- Internal or private state variables or functions should have an underscore prefix. + + ```solidity + contract TestContract { + uint256 private _privateVar; + uint256 internal _internalVar; + function _testInternal() internal { ... } + function _testPrivate() private { ... } + } + ``` + +- Events should generally be emitted immediately after the state change that they + represent, and should be named in the past tense. Some exceptions may be made for gas + efficiency if the result doesn't affect observable ordering of events. + + ```solidity + function _burn(address who, uint256 value) internal { + super._burn(who, value); + emit TokensBurned(who, value); + } + ``` + +- Interface names should have a capital I prefix. + + ```solidity + interface IERC777 { + ``` + +- Contracts not intended to be used standalone should be marked abstract + so they are required to be inherited to other contracts. + + ```solidity + abstract contract AccessControl is ..., { + ``` + +- Unchecked arithmetic blocks should contain comments explaining why overflow is guaranteed not to happen. If the reason is immediately apparent from the line above the unchecked block, the comment may be omitted. + +### Interfaces + +Every contract MUST implement their corresponding interface that includes all externally callable functions, errors and events. + +### NatSpec & Comments + +Interfaces should be the entrypoint for all contracts. When exploring the a contract within the repository, the interface MUST contain all relevant information to understand the functionality of the contract in the form of NatSpec comments. This includes all externally callable functions, errors and events. The NatSpec documentation MUST be added to the functions, errors and events within the interface. This allows a reader to understand the functionality of a function before moving on to the implementation. The implementing functions MUST point to the NatSpec documentation in the interface using `@inheritdoc`. Internal and private functions shouldn't have NatSpec documentation except for `@dev` comments, whenever more context is needed. Additional comments within a function should only be used to give more context to more complex operations, otherwise the code should be kept readable and self-explanatory. + +## Versioning + +This repo utilizes [semantic versioning](https://semver.org/) for smart contracts. An `IVersioned` interface is included in the [interfaces directory](src/interface/IVersioned.sol) exposing a unified versioning interface for all contracts. This version MUST be included in all contracts, whether they are upgradeable or not, to be able to easily match deployed versions. For example, in the case of a non-upgradeable contract one version could be deployed to a network and later a new version might be deployed to another network. The exposed `version()` function is also used by the [Deployment Log Generator](https://github.com/0xPolygon/deployment-log-generator#readme) to extract information about the version. + +Whenever contracts are modified, only the version of the changed contracts should be updated. Unmodified contracts should remain on the version of their last change. + +## Testing + +### Deployer Template + +This repo provides a deployer template library for consistency between scripts and unit tests. For more information on how to use the template, check [here](https://github.com/0xPolygon/contract-deployer-template#readme). + +## Deployment + +This repo utilizes versioned deployments. Any changes to a contract should update the version of this specific contract. A script is provided that extracts deployment information from the `run-latest.json` file within the `broadcast` directory generated while the forge script runs. From this information a JSON and markdown file is generated containing various information about the deployment itself as well as past deployments. + +### Deployer Template + +This repo provides a deployer template library for consistency between scripts and unit tests. For more information on how to use the template, check [here](https://github.com/0xPolygon/contract-deployer-template#readme). + +### Deployment + +This repo set up the following RPCs in the `foundry.toml` file: + +- mainnet: Ethereum Mainnet +- goerli: Ethereum Goerli +- sepolia: Ethereum Sepolia +- polygon_pos: Polygon PoS +- mumbai: Polygon Mumbai +- polygon_zkevm: Polygon zkEVM +- polygon_zkevm_testnet: Polygon zkEVM Testnet + +To deploy the contracts, provide the `--broadcast` flag to the forge script command. Should the etherscan verification time out, it can be picked up again by replacing the `--broadcast` flag with `--resume`. +Deploy the contracts to one of the predefined networks by providing the according key with the `--rpc-url` flag. Most of the predefined networks require the `INFURA_KEY` environment variable to be set in the `.env` file. +Including the `--verify` flag will verify deployed contracts on Etherscan. Define the appropriate environment variable for the Etherscan api key in the `.env` file. + +```shell +forge script script/Deploy.s.sol --broadcast --rpc-url --verify +``` + +## Releases + +Releases should be created whenever the code on the main branch is updated to reflect a deployment or an upgrade on a network. The release should be named after the version of the contracts deployed or upgraded. +The release should include the following: + +- In case of a MAJOR version + - changelog + - summary of breaking changes + - summary of new features + - summary of fixes +- In case of a MINOR version + - changelog + - summary of new features + - summary of fixes +- In case of a PATCH version + - changelog + - summary of fixes +- Deployment information (can be copied from the generated log files) + - Addresses of the deployed contracts diff --git a/README.md b/README.md index 4364c147d..b2047add1 100644 --- a/README.md +++ b/README.md @@ -10,50 +10,65 @@ Ethereum smart contracts that power the [Matic Network](https://polygon.technolo npm install ``` -### Compile - -bor-chain-id for Mainnet = 137 -bor-chain-id for TestnetV4 (Mumbai) = 80001 +### Setup ``` -npm run template:process -- --bor-chain-id -npm run truffle:compile +pre-commit install ``` -### Start main chain and side chain - -- Start Main chain +### Compile ``` -npm run testrpc +npm run template:process -- --bor-chain-id 15001 ``` +bor-chain-id should be: +**local: 15001** +Mainnet = 137 +TestnetV4 (Mumbai) = 80001 + +### Main chain and side chain + +- Main chain + +All tests are run against a fork of mainnet using Hardhat's forking functionality. No need to run any local chain! + - Start Matic side chain. Requires docker. ``` npm run bor:simulate ``` -- If you ran a bor instance before, a dead docker container might still be lying around, clean it with +- Stop with + +``` +npm run bor:stop +``` + +- If you want a clean chain, this also deletes your /data folder containing the chain state. ``` npm run bor:clean ``` -- Run a bor (our matic chain node) instance. +### Run tests + +Run Hardhat test -### Deploy Contracts +``` +npm test:hardhat +``` -- For local development +Run Foundry test ``` -npm run truffle:migrate +npm test:foundry ``` -- For a properly initialized set of contracts, follow the instructions [here](./deploy-migrations/README.md). +### Coverage -### Run tests +Run coverage with ``` -npm test +npm run coverage ``` diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 000000000..53191aeb9 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,22 @@ +# Polygon Technology Security Information + +## Link to vulnerability disclosure details (Bug Bounty). + +- Websites and Applications: https://hackerone.com/polygon-technology +- Smart Contracts: https://immunefi.com/bounty/polygon + +## Languages that our team speaks and understands. + +Preferred-Languages: en + +## Security-related job openings at Polygon. + +https://polygon.technology/careers + +## Polygon security contact details. + +security@polygon.technology + +## The URL for accessing the security.txt file. + +Canonical: https://polygon.technology/security.txt diff --git a/contracts/Migrations.sol b/contracts/Migrations.sol deleted file mode 100644 index d542e7fd0..000000000 --- a/contracts/Migrations.sol +++ /dev/null @@ -1,23 +0,0 @@ -pragma solidity ^0.5.2; - -contract Migrations { - address public owner; - uint256 public last_completed_migration; - - modifier restricted() { - if (msg.sender == owner) _; - } - - constructor() public { - owner = msg.sender; - } - - function setCompleted(uint256 completed) public restricted { - last_completed_migration = completed; - } - - function upgrade(address new_address) public restricted { - Migrations upgraded = Migrations(new_address); - upgraded.setCompleted(last_completed_migration); - } -} diff --git a/contracts/child/misc/Marketplace.sol b/contracts/child/misc/Marketplace.sol deleted file mode 100644 index e27c5e9a0..000000000 --- a/contracts/child/misc/Marketplace.sol +++ /dev/null @@ -1,66 +0,0 @@ -pragma solidity ^0.5.2; - -interface MarketplaceToken { - function transferWithSig( - bytes calldata sig, - uint256 tokenIdOrAmount, - bytes32 data, - uint256 expiration, - address to - ) external returns (address); -} - -contract Marketplace { - struct Order { - address token; - bytes sig; - uint256 tokenIdOrAmount; - } - - function executeOrder( - bytes memory data1, - bytes memory data2, - bytes32 orderId, - uint256 expiration, - address taker - ) public { - Order memory order1 = decode(data1); - Order memory order2 = decode(data2); - - // Transferring order1.token tokens from tradeParticipant1 to address2 - address tradeParticipant1 = MarketplaceToken(order1.token) - .transferWithSig( - order1.sig, - order1.tokenIdOrAmount, - keccak256( - abi.encodePacked(orderId, order2.token, order2.tokenIdOrAmount) - ), - expiration, - taker - ); - - // Transferring token2 from tradeParticipant2 to tradeParticipant1 - address tradeParticipant2 = MarketplaceToken(order2.token) - .transferWithSig( - order2.sig, - order2.tokenIdOrAmount, - keccak256( - abi.encodePacked(orderId, order1.token, order1.tokenIdOrAmount) - ), - expiration, - tradeParticipant1 - ); - require(taker == tradeParticipant2, "Orders are not complimentary"); - } - - function decode(bytes memory data) - internal - pure - returns (Order memory order) - { - (order.token, order.sig, order.tokenIdOrAmount) = abi.decode( - data, - (address, bytes, uint256) - ); - } -} diff --git a/contracts/child/misc/ParentTokenMock.sol b/contracts/child/misc/ParentTokenMock.sol deleted file mode 100644 index ed0a83759..000000000 --- a/contracts/child/misc/ParentTokenMock.sol +++ /dev/null @@ -1,21 +0,0 @@ -pragma solidity ^0.5.2; - -import "openzeppelin-solidity/contracts/ownership/Ownable.sol"; - -import "./IParentToken.sol"; -// demo token parent contract - -contract ParentTokenMock is IParentToken, Ownable { - mapping(address => bool) isAllowed; - function beforeTransfer(address sender, address to, uint256 value) - external - returns (bool) - { - return isAllowed[sender]; - } - - function updatePermission(address user) public onlyOwner { - require(user != address(0x0)); - isAllowed[user] = !isAllowed[user]; - } -} diff --git a/contracts/common/tokens/ERC20NonTransferable.sol b/contracts/common/tokens/ERC20NonTransferable.sol deleted file mode 100644 index ab5167fe9..000000000 --- a/contracts/common/tokens/ERC20NonTransferable.sol +++ /dev/null @@ -1,13 +0,0 @@ -pragma solidity ^0.5.2; - -import {ERC20} from "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol"; - -contract ERC20NonTransferable is ERC20 { - function _transfer( - address from, - address to, - uint256 value - ) internal { - revert("Disabled"); - } -} diff --git a/contracts/root/depositManager/DepositManager.sol b/contracts/root/depositManager/DepositManager.sol index b3be23ad2..0cf6ac2b1 100644 --- a/contracts/root/depositManager/DepositManager.sol +++ b/contracts/root/depositManager/DepositManager.sol @@ -14,13 +14,20 @@ import {StateSender} from "../stateSyncer/StateSender.sol"; import {GovernanceLockable} from "../../common/mixin/GovernanceLockable.sol"; import {RootChain} from "../RootChain.sol"; +interface IPolygonMigration { + function migrate(uint256 amount) external; +} + contract DepositManager is DepositManagerStorage, IDepositManager, ERC721Holder { using SafeMath for uint256; using SafeERC20 for IERC20; modifier isTokenMapped(address _token) { - require(registry.isTokenMapped(_token), "TOKEN_NOT_SUPPORTED"); + require( + registry.isTokenMapped(_token), + "TOKEN_NOT_SUPPORTED" + ); _; } @@ -36,25 +43,49 @@ contract DepositManager is DepositManagerStorage, IDepositManager, ERC721Holder depositEther(); } + // new: governance function to migrate MATIC to POL + function migrateMatic(uint256 _amount) external onlyGovernance { + _migrateMatic(_amount); + } + + function _migrateMatic(uint256 _amount) private { + IERC20 matic = IERC20(registry.contractMap(keccak256("matic"))); + address polygonMigration = registry.contractMap(keccak256("polygonMigration")); + + // check that _amount is not too high + require(matic.balanceOf(address(this)) >= _amount, "amount exceeds this contract's MATIC balance"); + + // approve + matic.approve(polygonMigration, _amount); + + // call migrate function + IPolygonMigration(polygonMigration).migrate(_amount); + } + function updateMaxErc20Deposit(uint256 maxDepositAmount) public onlyGovernance { require(maxDepositAmount != 0); emit MaxErc20DepositUpdate(maxErc20Deposit, maxDepositAmount); maxErc20Deposit = maxDepositAmount; } - function transferAssets( - address _token, - address _user, - uint256 _amountOrNFTId - ) external isPredicateAuthorized { + function transferAssets(address _token, address _user, uint256 _amountOrNFTId) external isPredicateAuthorized { address wethToken = registry.getWethTokenAddress(); + if (registry.isERC721(_token)) { IERC721(_token).transferFrom(address(this), _user, _amountOrNFTId); } else if (_token == wethToken) { WETH t = WETH(_token); t.withdraw(_amountOrNFTId, _user); } else { - require(IERC20(_token).transfer(_user, _amountOrNFTId), "TRANSFER_FAILED"); + // new: pay out POL when MATIC is withdrawn + if (_token == registry.contractMap(keccak256("matic"))) { + require( + IERC20(registry.contractMap(keccak256("pol"))).transfer(_user, _amountOrNFTId), + "TRANSFER_FAILED" + ); + } else { + require(IERC20(_token).transfer(_user, _amountOrNFTId), "TRANSFER_FAILED"); + } } } @@ -104,21 +135,14 @@ contract DepositManager is DepositManagerStorage, IDepositManager, ERC721Holder stateSender = StateSender(_stateSender); } - function depositERC20ForUser( - address _token, - address _user, - uint256 _amount - ) public { + function depositERC20ForUser(address _token, address _user, uint256 _amount) public { require(_amount <= maxErc20Deposit, "exceed maximum deposit amount"); IERC20(_token).safeTransferFrom(msg.sender, address(this), _amount); + _safeCreateDepositBlock(_user, _token, _amount); } - function depositERC721ForUser( - address _token, - address _user, - uint256 _tokenId - ) public { + function depositERC721ForUser(address _token, address _user, uint256 _tokenId) public { require(registry.isTokenMappedAndIsErc721(_token), "not erc721"); _safeTransferERC721(msg.sender, _token, _tokenId); @@ -138,20 +162,21 @@ contract DepositManager is DepositManagerStorage, IDepositManager, ERC721Holder address _token, uint256 _amountOrToken ) internal onlyWhenUnlocked isTokenMapped(_token) { - _createDepositBlock( - _user, - _token, - _amountOrToken, - rootChain.updateDepositId(1) /* returns _depositId */ - ); + _createDepositBlock(_user, _token, _amountOrToken, rootChain.updateDepositId(1)); // returns _depositId } - function _createDepositBlock( - address _user, - address _token, - uint256 _amountOrToken, - uint256 _depositId - ) internal { + function _createDepositBlock(address _user, address _token, uint256 _amountOrToken, uint256 _depositId) internal { + address matic = registry.contractMap(keccak256("matic")); + + // new: auto-migrate MATIC to POL + if (_token == matic) { + _migrateMatic(_amountOrToken); + } + // new: bridge POL as MATIC, child chain behaviour does not change + else if (_token == registry.contractMap(keccak256("pol"))) { + _token = matic; + } + deposits[_depositId] = DepositBlock(keccak256(abi.encodePacked(_user, _token, _amountOrToken)), now); stateSender.syncState(childChain, abi.encode(_user, _token, _amountOrToken, _depositId)); emit NewDepositBlock(_user, _token, _amountOrToken, _depositId); diff --git a/contracts/root/predicates/MarketplacePredicate.sol b/contracts/root/predicates/MarketplacePredicate.sol deleted file mode 100644 index d412420a0..000000000 --- a/contracts/root/predicates/MarketplacePredicate.sol +++ /dev/null @@ -1,467 +0,0 @@ -pragma solidity ^0.5.2; - -import {BytesLib} from "../../common/lib/BytesLib.sol"; -import {Common} from "../../common/lib/Common.sol"; -import {ECVerify} from "../../common/lib/ECVerify.sol"; -import {Math} from "openzeppelin-solidity/contracts/math/Math.sol"; -import {RLPEncode} from "../../common/lib/RLPEncode.sol"; -import {RLPReader} from "solidity-rlp/contracts/RLPReader.sol"; -import {SafeMath} from "openzeppelin-solidity/contracts/math/SafeMath.sol"; - -import {IPredicate, PredicateUtils} from "./IPredicate.sol"; -import {IRootChain} from "../IRootChain.sol"; -import {IWithdrawManager} from "../withdrawManager/IWithdrawManager.sol"; -import {Registry} from "../../common/Registry.sol"; -import {TransferWithSigUtils} from "./TransferWithSigUtils.sol"; - -contract MarketplacePredicate is PredicateUtils { - using RLPReader for bytes; - using RLPReader for RLPReader.RLPItem; - using SafeMath for uint256; - - // 0xe660b9e4 = keccak256('executeOrder(bytes,bytes,bytes32,uint256,address)').slice(0, 4) - bytes4 constant EXECUTE_ORDER_FUNC_SIG = 0xe660b9e4; - - Registry public registry; - IRootChain public rootChain; - - struct ExecuteOrderData { - bytes data1; - bytes data2; - bytes32 orderId; - uint256 expiration; - address taker; - } - - struct Order { - address token; - bytes sig; - uint256 amount; - } - - struct ExitTxData { - // token1 and amount1 correspond to what the utxoOwner (tradeParticipant) signed over - uint256 amount1; - uint256 amount2; - address token1; - address token2; - address counterParty; - bytes32 txHash; - uint256 expiration; - } - - struct ReferenceTxData { - uint256 closingBalance; - uint256 age; - address childToken; - address rootToken; - } - - constructor(address _rootChain, address _withdrawManager, address _registry) - public - { - withdrawManager = IWithdrawManager(_withdrawManager); - rootChain = IRootChain(_rootChain); - registry = Registry(_registry); - } - - /** - * @notice Start an exit from in-flight marketplace tx - * @param data RLP encoded array of input utxos - * data[n] ( 1 < n <= 3) is abi encoded as (predicateAddress, RLP encoded reference tx) - * data[n][1] is RLP encoded reference tx that encodes the following fields - * headerNumber Header block number of which the reference tx was a part of - * blockProof Proof that the block header (in the child chain) is a leaf in the submitted merkle root - * blockNumber Block number of which the reference tx is a part of - * blockTime Reference tx block time - * blocktxRoot Transactions root of block - * blockReceiptsRoot Receipts root of block - * receipt Receipt of the reference transaction - * receiptProof Merkle proof of the reference receipt - * branchMask Merkle proof branchMask for the receipt - * logIndex Log Index to read from the receipt - * data[2] is the child token that the user wishes to start an exit for - * @param exitTx Signed (marketplace.executeOrder) exit transaction - */ - function startExit(bytes calldata data, bytes calldata exitTx) - external - payable - isBondProvided - { - RLPReader.RLPItem[] memory referenceTx = data.toRlpItem().toList(); - (address predicate, bytes memory preState) = abi.decode( - referenceTx[0].toBytes(), - (address, bytes) - ); - require( - uint8(registry.predicates(predicate)) != 0, - "Not a valid predicate" - ); - ExitTxData memory exitTxData = processExitTx(exitTx, msg.sender); - require( - exitTxData.expiration > rootChain.getLastChildBlock(), - "The inflight exit is not valid, because the marketplace order has expired" - ); - - // process the first input, which is the proof-of-exitor's funds for token t1 which exitor transferred to counterparty as part of the marketplace tx - ReferenceTxData memory reference1 = processLogTransferReceipt( - predicate, - preState, - msg.sender, - true, /* verifyInclusionInCheckpoint */ - false /* isChallenge */ - ); - - validateTokenBalance( - reference1.childToken, - exitTxData.token1, - reference1.closingBalance, - exitTxData.amount1 - ); - - // process the second input, which is the proof-of-counterparty's funds for token t2 which the counterparty transferred to exitor as part of the marketplace tx - (predicate, preState) = abi.decode( - referenceTx[1].toBytes(), - (address, bytes) - ); - require( - uint8(registry.predicates(predicate)) != 0, - "Not a valid predicate" - ); - ReferenceTxData memory reference2 = processLogTransferReceipt( - predicate, - preState, - exitTxData.counterParty, - true, /*verifyInclusionInCheckpoint*/ - false /* isChallenge */ - ); - validateTokenBalance( - reference2.childToken, - exitTxData.token2, - reference2.closingBalance, - exitTxData.amount2 - ); - - // The last element in referenceTx array refers to the child token being exited - address exitChildToken = address( - RLPReader.toUint(referenceTx[referenceTx.length - 1]) - ); - ReferenceTxData memory reference3; - // referenceTx.length == 4 means the exitor sent along another input UTXO for token t2 - // This will be used to exit with the pre-existing balance for token t2 on the chain - // @todo This part is untested - if (referenceTx.length == 4) { - (predicate, preState) = abi.decode( - referenceTx[3].toBytes(), - (address, bytes) - ); - reference3 = processLogTransferReceipt( - predicate, - preState, - msg.sender, - true, /* verifyInclusionInCheckpoint */ - false /* isChallenge */ - ); - require( - reference2.childToken == reference3.childToken, - "Child token doesnt match" - ); - } - - sendBond(); // send BOND_AMOUNT to withdrawManager - - // uint256 ageOfYoungestInput = ; - // exitId is the age of the youngest input + a reserved last bit - uint256 exitId = Math.max( - Math.max(reference1.age, reference2.age), - reference3.age - ) << - 1; - if (exitChildToken == reference1.childToken) { - withdrawManager.addExitToQueue( - msg.sender, - exitChildToken, - reference1.rootToken, - reference1.closingBalance.sub(exitTxData.amount1), - exitTxData.txHash, - false, /* isRegularExit */ - exitId - ); - } else if (exitChildToken == reference2.childToken) { - withdrawManager.addExitToQueue( - msg.sender, - exitChildToken, - reference2.rootToken, - exitTxData.amount2.add(reference3.closingBalance), - exitTxData.txHash, - false, /* isRegularExit */ - exitId - ); - } - // @todo Support batch - withdrawManager.addInput( - exitId, - reference1.age, /* age of input */ - msg.sender, /* party whom this utxo belongs to */ - reference1.rootToken - ); - withdrawManager.addInput( - exitId, - reference2.age, - exitTxData.counterParty, - reference2.rootToken - ); - // If exitor did not have pre=exiting balance on the chain for token t2 - // In that case, the following input acts as a "dummy" input UTXO to challenge token t2 spends by the exitor - withdrawManager.addInput(exitId, 0, msg.sender, reference3.rootToken); - } - - /** - * @notice Verify the deprecation of a state update - * @param exit ABI encoded PlasmaExit data - * @param inputUtxo ABI encoded Input UTXO data - * @param challengeData RLP encoded data of the challenge reference tx that encodes the following fields - * headerNumber Header block number of which the reference tx was a part of - * blockProof Proof that the block header (in the child chain) is a leaf in the submitted merkle root - * blockNumber Block number of which the reference tx is a part of - * blockTime Reference tx block time - * blocktxRoot Transactions root of block - * blockReceiptsRoot Receipts root of block - * receipt Receipt of the reference transaction - * receiptProof Merkle proof of the reference receipt - * branchMask Merkle proof branchMask for the receipt - * logIndex Log Index to read from the receipt - * tx Challenge transaction - * txProof Merkle proof of the challenge tx - * @return Whether or not the state is deprecated - */ - function verifyDeprecation( - bytes calldata exit, - bytes calldata inputUtxo, - bytes calldata challengeData - ) external view returns (bool) { - PlasmaExit memory _exit = decodeExit(exit); - (uint256 age, address utxoOwner, address predicate, address childToken) = decodeInputUtxo( - inputUtxo - ); - - RLPReader.RLPItem[] memory _challengeData = challengeData - .toRlpItem() - .toList(); - ExitTxData memory challengeTxData = processExitTx( - _challengeData[10].toBytes(), - utxoOwner - ); - - // receipt alone is not enough for a challenge. It is required to check that the challenge tx was included as well - // Challenge will be considered successful if a more recent LogTransfer event is found - // Interestingly, that will be determined by erc20/721 predicate - ReferenceTxData memory referenceTxData = processLogTransferReceipt( - predicate, - challengeData, - utxoOwner, - true, /* verifyInclusionInCheckpoint */ - true /* isChallenge */ - ); - - // this assertion is required only for erc721 because the spend should correspond to the same NFT - if (registry.predicates(predicate) == Registry.Type.ERC721) { - require( - referenceTxData.closingBalance == _exit.receiptAmountOrNFTId && - challengeTxData.amount1 == _exit.receiptAmountOrNFTId, - "LogTransferReceipt, challengeTx NFT and challenged utxo NFT do not match" - ); - } - // assert transferWithSig was still valid when it was included in the child chain - require( - getChildBlockNumberFromAge(referenceTxData.age) <= - challengeTxData.expiration, - "The marketplace order was expired when it was included" - ); - require( - referenceTxData.childToken == childToken && - challengeTxData.token1 == childToken, - "LogTransferReceipt, challengeTx token and challenged utxo token do not match" - ); - require( - challengeTxData.txHash != _exit.txHash, - "Cannot challenge with the exit tx" - ); - require( - referenceTxData.age > age, - "Age of challenge log in the receipt needs to be more recent than Utxo being challenged" - ); - return true; - } - - function getChildBlockNumberFromAge(uint256 age) - internal - pure - returns (uint256) - { - // age is represented as (getExitableAt(createdAt) << 127) | (blockNumber << 32) | branchMask.toRlpItem().toUint(); - return (age << 129) >> 161; - } - - function validateTokenBalance( - address childToken, - address _childToken, - uint256 closingBalance, - uint256 amount - ) internal view { - require(childToken == _childToken, "Child tokens do not match"); - if (registry.isChildTokenErc721(childToken)) { - require( - closingBalance == amount, - "Same erc721 token was not referenced" - ); - } else { - require( - closingBalance >= amount, - "Exiting with more tokens than referenced" - ); - } - } - - function processLogTransferReceipt( - address predicate, - bytes memory preState, - address participant, - bool verifyInclusionInCheckpoint, - bool isChallenge - ) internal view returns (ReferenceTxData memory _referenceTx) { - bytes memory _preState = IPredicate(predicate).interpretStateUpdate( - abi.encode( - preState, - participant, - verifyInclusionInCheckpoint, - isChallenge - ) - ); - ( - _referenceTx.closingBalance, - _referenceTx.age, - _referenceTx.childToken, - _referenceTx.rootToken - ) = abi.decode(_preState, (uint256, uint256, address, address)); - } - - function processExitTx(bytes memory exitTx, address tradeParticipant) - internal - pure - returns (ExitTxData memory txData) - { - RLPReader.RLPItem[] memory txList = exitTx.toRlpItem().toList(); - require(txList.length == 9, "MALFORMED_WITHDRAW_TX"); - address marketplaceContract = RLPReader.toAddress(txList[3]); // "to" field in tx - (bytes4 funcSig, ExecuteOrderData memory executeOrder) = decodeExecuteOrder( - RLPReader.toBytes(txList[5]) - ); - require( - funcSig == EXECUTE_ORDER_FUNC_SIG, - "Not executeOrder transaction" - ); - txData = verifySignatures( - executeOrder, - marketplaceContract, - tradeParticipant - ); - (, txData.txHash) = getAddressFromTx(txList); - } - - function verifySignatures( - ExecuteOrderData memory executeOrder, - address marketplaceContract, - address tradeParticipant - ) internal pure returns (ExitTxData memory) { - Order memory order1 = decodeOrder(executeOrder.data1); - Order memory order2 = decodeOrder(executeOrder.data2); - bytes32 dataHash = TransferWithSigUtils.getTokenTransferOrderHash( - order1.token, // used to evaluate EIP712_DOMAIN_HASH - marketplaceContract, // spender - order1.amount, - keccak256( - abi.encodePacked( - executeOrder.orderId, - order2.token, - order2.amount - ) - ), - executeOrder.expiration - ); - // Cannot check for deactivated sigs here on the root chain - address tradeParticipant1 = ECVerify.ecrecovery(dataHash, order1.sig); - dataHash = TransferWithSigUtils.getTokenTransferOrderHash( - order2.token, // used to evaluate EIP712_DOMAIN_HASH - marketplaceContract, // spender - order2.amount, - keccak256( - abi.encodePacked( - executeOrder.orderId, - order1.token, - order1.amount - ) - ), - executeOrder.expiration - ); - // Cannot check for deactivated sigs here on the root chain - address tradeParticipant2 = ECVerify.ecrecovery(dataHash, order2.sig); - require( - executeOrder.taker == tradeParticipant2, - "Orders are not complimentary" - ); - // token1 and amount1 in ExitTxData should correspond to what the tradeParticipant signed over (spent in the trade) - if (tradeParticipant1 == tradeParticipant) { - return - ExitTxData( - order1.amount, - order2.amount, - order1.token, - order2.token, - tradeParticipant2, - bytes32(0), - executeOrder.expiration - ); - } else if (tradeParticipant2 == tradeParticipant) { - return - ExitTxData( - order2.amount, - order1.amount, - order2.token, - order1.token, - tradeParticipant1, - bytes32(0), - executeOrder.expiration - ); - } - revert("Provided tx doesnt concern the exitor (tradeParticipant)"); - } - - function decodeExecuteOrder(bytes memory orderData) - internal - pure - returns (bytes4 funcSig, ExecuteOrderData memory order) - { - funcSig = BytesLib.toBytes4(BytesLib.slice(orderData, 0, 4)); - // 32 + 32 bytes of some (yet to figure out) offset - order.orderId = bytes32(BytesLib.toUint(orderData, 68)); - order.expiration = BytesLib.toUint(orderData, 100); - order.taker = address(BytesLib.toUint(orderData, 132)); - uint256 length = BytesLib.toUint(orderData, 164); - order.data1 = BytesLib.slice(orderData, 196, length); - uint256 offset = 196 + length; - length = BytesLib.toUint(orderData, offset); - order.data2 = BytesLib.slice(orderData, offset + 32, length); - } - - function decodeOrder(bytes memory data) - internal - pure - returns (Order memory order) - { - (order.token, order.sig, order.amount) = abi.decode( - data, - (address, bytes, uint256) - ); - } -} diff --git a/contracts/root/predicates/TransferWithSigPredicate.sol b/contracts/root/predicates/TransferWithSigPredicate.sol deleted file mode 100644 index 168228b06..000000000 --- a/contracts/root/predicates/TransferWithSigPredicate.sol +++ /dev/null @@ -1,377 +0,0 @@ -pragma solidity ^0.5.2; - -import {Math} from "openzeppelin-solidity/contracts/math/Math.sol"; -import {RLPReader} from "solidity-rlp/contracts/RLPReader.sol"; -import {SafeMath} from "openzeppelin-solidity/contracts/math/SafeMath.sol"; - -import {BytesLib} from "../../common/lib/BytesLib.sol"; -import {ECVerify} from "../../common/lib/ECVerify.sol"; - -import {IPredicate, PredicateUtils} from "./IPredicate.sol"; -import {IRootChain} from "../IRootChain.sol"; -import {IWithdrawManager} from "../withdrawManager/IWithdrawManager.sol"; -import {Registry} from "../../common/Registry.sol"; -import {TransferWithSigUtils} from "./TransferWithSigUtils.sol"; - -contract TransferWithSigPredicate is PredicateUtils { - using RLPReader for bytes; - using RLPReader for RLPReader.RLPItem; - using SafeMath for uint256; - - // 0xe660b9e4 = keccak256('transferWithSig(bytes,uint256,bytes32,uint256,address)').slice(0, 4) - bytes4 constant TRANSFER_WITH_SIG_FUNC_SIG = 0x19d27d9c; - - Registry public registry; - IRootChain public rootChain; - - struct ReferenceTxData { - uint256 closingBalance; - uint256 age; - address childToken; - address rootToken; - } - - struct ExitTxData { - uint256 amountOrToken; - bytes32 txHash; - address childToken; - address signer; - } - - constructor(address _rootChain, address _withdrawManager, address _registry) - public - { - withdrawManager = IWithdrawManager(_withdrawManager); - rootChain = IRootChain(_rootChain); - registry = Registry(_registry); - } - - /** - * @notice Start an exit from in-flight transferWithSig tx while referencing the exitor's pre-existing balance on the chain for the token - * @param data RLP encoded array of 1 input utxo (data format is to keep it consistent with other startExit methods) - * data[0] should be the exitor's proof-of-funds and encodes the following fields - * headerNumber Header block number of which the reference tx was a part of - * blockProof Proof that the block header (in the child chain) is a leaf in the submitted merkle root - * blockNumber Block number of which the reference tx is a part of - * blockTime Reference tx block time - * blocktxRoot Transactions root of block - * blockReceiptsRoot Receipts root of block - * receipt Receipt of the reference transaction - * receiptProof Merkle proof of the reference receipt - * branchMask Merkle proof branchMask for the receipt - * logIndex Log Index to read from the receipt - * @param exitTx ERC20 transfer executed using a transferWithSig - */ - function startExitForOutgoingErc20Transfer( - bytes calldata data, - bytes calldata exitTx - ) external payable isBondProvided { - RLPReader.RLPItem[] memory referenceTx = data.toRlpItem().toList(); - bytes memory preState = referenceTx[0].toBytes(); - (ExitTxData memory exitTxData, uint256 expiration) = processExitTx( - exitTx - ); - require( - expiration > rootChain.getLastChildBlock(), - "The inflight exit is not valid, because the transfer sig has expired" - ); - require( - exitTxData.signer == msg.sender, - "Should be an outgoing transfer" - ); - address erc20Predicate = registry.erc20Predicate(); - ReferenceTxData memory referenceTxData = processLogTransferReceipt( - erc20Predicate, - preState, - msg.sender, - true, /* verifyInclusionInCheckpoint */ - false /* isChallenge */ - ); - require( - exitTxData.childToken == referenceTxData.childToken, - "Reference and exit tx do not correspond to the same child token" - ); - // The closing balance of the referenced tx should be >= exit amount in exitTx - require( - referenceTxData.closingBalance >= exitTxData.amountOrToken, - "Exiting with more tokens than referenced" - ); - - sendBond(); // send BOND_AMOUNT to withdrawManager - - // last bit is to differentiate whether the sender or receiver of the in-flight tx is starting an exit - uint256 exitId = referenceTxData.age << 1; - exitId |= 1; // since msg.sender == exitTxData.signer - withdrawManager.addExitToQueue( - msg.sender, - referenceTxData.childToken, - referenceTxData.rootToken, - referenceTxData.closingBalance.sub(exitTxData.amountOrToken), - exitTxData.txHash, - false, /* isRegularExit */ - exitId - ); - withdrawManager.addInput( - exitId, - referenceTxData.age, - msg.sender, - referenceTxData.rootToken - ); - } - - /** - * @notice Start an exit from in-flight transferWithSig tx while also referencing the exitor's pre-existing balance on the chain for the token - * @param data RLP encoded array of 2 input utxos - * data[0] should be the counterparty's proof-of-funds - * data[1] should be the exitor's proof-of-funds - * data[n] encodes the following fields - * headerNumber Header block number of which the reference tx was a part of - * blockProof Proof that the block header (in the child chain) is a leaf in the submitted merkle root - * blockNumber Block number of which the reference tx is a part of - * blockTime Reference tx block time - * blocktxRoot Transactions root of block - * blockReceiptsRoot Receipts root of block - * receipt Receipt of the reference transaction - * receiptProof Merkle proof of the reference receipt - * branchMask Merkle proof branchMask for the receipt - * logIndex Log Index to read from the receipt - * @param exitTx ERC20 transfer executed using a transferWithSig - */ - function startExitForIncomingErc20Transfer( - bytes calldata data, - bytes calldata exitTx - ) external payable isBondProvided { - RLPReader.RLPItem[] memory referenceTx = data.toRlpItem().toList(); - bytes memory preState = referenceTx[0].toBytes(); - (ExitTxData memory exitTxData, uint256 expiration) = processExitTx( - exitTx - ); - require( - expiration > rootChain.getLastChildBlock(), - "The inflight exit is not valid, because the transfer sig has expired" - ); - require( - exitTxData.signer != msg.sender, - "Should be an incoming transfer" - ); - address erc20Predicate = registry.erc20Predicate(); - // Process the receipt (i.e. proof-of-funds of the counterparty) of the referenced tx - ReferenceTxData memory referenceTxData = processLogTransferReceipt( - erc20Predicate, - preState, - exitTxData.signer, - true, /* verifyInclusionInCheckpoint */ - false /* isChallenge */ - ); - require( - exitTxData.childToken == referenceTxData.childToken, - "Reference and exit tx do not correspond to the same child token" - ); - // The closing balance of the referenced tx should be >= exit amount in exitTx - require( - referenceTxData.closingBalance >= exitTxData.amountOrToken, - "Exiting with more tokens than referenced" - ); - - // referenceTx.length == 2 means the exitor sent along another input UTXO to the exit tx - // This will be used to exit with the exitor's pre-existing balance on the chain for the token - ReferenceTxData memory _referenceTxData; - if (referenceTx.length > 1) { - preState = referenceTx[1].toBytes(); - _referenceTxData = processLogTransferReceipt( - erc20Predicate, - preState, - msg.sender, - true, /* verifyInclusionInCheckpoint */ - false /* isChallenge */ - ); - require( - _referenceTxData.childToken == referenceTxData.childToken, - "child tokens in the referenced txs do not match" - ); - require( - _referenceTxData.rootToken == referenceTxData.rootToken, - "root tokens in the referenced txs do not match" - ); - } - - sendBond(); // send BOND_AMOUNT to withdrawManager - - // last bit is to differentiate whether the sender or receiver of the in-flight tx is starting an exit - uint256 exitId = Math.max(referenceTxData.age, _referenceTxData.age) << - 1; - withdrawManager.addExitToQueue( - msg.sender, - referenceTxData.childToken, - referenceTxData.rootToken, - exitTxData.amountOrToken.add(_referenceTxData.closingBalance), - exitTxData.txHash, - false, /* isRegularExit */ - exitId - ); - withdrawManager.addInput( - exitId, - referenceTxData.age, - exitTxData.signer, - referenceTxData.rootToken - ); - // Even if referenceTx.length == 1, the following input acts as a "dummy" input UTXO to challenge token spends by the exitor - withdrawManager.addInput( - exitId, - _referenceTxData.age, - msg.sender, - referenceTxData.rootToken - ); - } - - /** - * @notice Verify the deprecation of a state update - * @param exit ABI encoded PlasmaExit data - * @param inputUtxo ABI encoded Input UTXO data - * @param challengeData RLP encoded data of the challenge reference tx that encodes the following fields - * headerNumber Header block number of which the reference tx was a part of - * blockProof Proof that the block header (in the child chain) is a leaf in the submitted merkle root - * blockNumber Block number of which the reference tx is a part of - * blockTime Reference tx block time - * blocktxRoot Transactions root of block - * blockReceiptsRoot Receipts root of block - * receipt Receipt of the reference transaction - * receiptProof Merkle proof of the reference receipt - * branchMask Merkle proof branchMask for the receipt - * logIndex Log Index to read from the receipt - * tx Challenge transaction - * txProof Merkle proof of the challenge tx - * @return Whether or not the state is deprecated - */ - function verifyDeprecation( - bytes calldata exit, - bytes calldata inputUtxo, - bytes calldata challengeData - ) external view returns (bool) { - PlasmaExit memory _exit = decodeExit(exit); - (uint256 age, address utxoOwner, address predicate, address childToken) = decodeInputUtxo( - inputUtxo - ); - - RLPReader.RLPItem[] memory _challengeData = challengeData - .toRlpItem() - .toList(); - (ExitTxData memory challengeTxData, uint256 expiration) = processExitTx( - _challengeData[10].toBytes() - ); - require( - challengeTxData.signer == utxoOwner, - "utxoOwner is not transferWithSig signer" - ); - // receipt alone is not enough for a challenge. It is required to check that the challenge tx was included as well - // Challenge will be considered successful if a more recent LogTransfer event is found - // Interestingly, that will be determined by erc20/721 predicate - ReferenceTxData memory referenceTxData = processLogTransferReceipt( - predicate, - challengeData, - utxoOwner, - true, /* verifyInclusionInCheckpoint */ - true /* isChallenge */ - ); - // this assertion is required only for erc721 because the spend should correspond to the same NFT - if (registry.predicates(predicate) == Registry.Type.ERC721) { - require( - referenceTxData.closingBalance == _exit.receiptAmountOrNFTId && - challengeTxData.amountOrToken == _exit.receiptAmountOrNFTId, - "LogTransferReceipt, challengeTx NFT and challenged utxo NFT do not match" - ); - } - // assert transferWithSig was still valid when it was included in the child chain - require( - getChildBlockNumberFromAge(referenceTxData.age) <= expiration, - "The transferWithSig order expired when it was included" - ); - require( - referenceTxData.childToken == childToken && - challengeTxData.childToken == childToken, - "LogTransferReceipt, challengeTx token and challenged utxo token do not match" - ); - require( - challengeTxData.txHash != _exit.txHash, - "Cannot challenge with the exit tx" - ); - require( - referenceTxData.age > age, - "Age of challenge log in the receipt needs to be more recent than Utxo being challenged" - ); - return true; - } - - function getChildBlockNumberFromAge(uint256 age) - internal - pure - returns (uint256) - { - // age is represented as (getExitableAt(createdAt) << 127) | (blockNumber << 32) | branchMask.toRlpItem().toUint(); - return (age << 129) >> 161; - } - - function processLogTransferReceipt( - address predicate, - bytes memory preState, - address participant, - bool verifyInclusionInCheckpoint, - bool isChallenge - ) internal view returns (ReferenceTxData memory _referenceTx) { - bytes memory _preState = IPredicate(predicate).interpretStateUpdate( - abi.encode( - preState, - participant, - verifyInclusionInCheckpoint, - isChallenge - ) - ); - ( - _referenceTx.closingBalance, - _referenceTx.age, - _referenceTx.childToken, - _referenceTx.rootToken - ) = abi.decode(_preState, (uint256, uint256, address, address)); - } - - /** - * @notice Process the challenge transaction - * @param exitTx Challenge transaction - * @return ExitTxData Parsed challenge transaction data - */ - function processExitTx(bytes memory exitTx) - internal - pure - returns (ExitTxData memory txData, uint256 expiration) - { - RLPReader.RLPItem[] memory txList = exitTx.toRlpItem().toList(); - require(txList.length == 9, "MALFORMED_TX"); - txData.childToken = RLPReader.toAddress(txList[3]); // corresponds to "to" field in tx - address spender; - // Signer of this tx is supposed to be the authorized spender - (spender, txData.txHash) = getAddressFromTx(txList); - - bytes memory txPayload = RLPReader.toBytes(txList[5]); - bytes4 funcSig = BytesLib.toBytes4(BytesLib.slice(txPayload, 0, 4)); - require( - funcSig == TRANSFER_WITH_SIG_FUNC_SIG, - "Not transferWithSig transaction" - ); - // 32 bytes offset - txData.amountOrToken = BytesLib.toUint(txPayload, 36); - bytes32 data = bytes32(BytesLib.toUint(txPayload, 68)); - expiration = BytesLib.toUint(txPayload, 100); - // address to = address(BytesLib.toUint(txPayload, 132)); - uint256 siglength = BytesLib.toUint(txPayload, 164); - bytes memory sig = BytesLib.slice(txPayload, 196, siglength); - bytes32 dataHash = TransferWithSigUtils.getTokenTransferOrderHash( - txData.childToken, - spender, - txData.amountOrToken, - data, - expiration - ); - // The signer of the transfer order is the "real signer" of the exit tx - txData.signer = ECVerify.ecrecovery(dataHash, sig); - } -} diff --git a/contracts/root/predicates/TransferWithSigUtils.sol.template b/contracts/root/predicates/TransferWithSigUtils.sol.template deleted file mode 100644 index 4e081b866..000000000 --- a/contracts/root/predicates/TransferWithSigUtils.sol.template +++ /dev/null @@ -1,62 +0,0 @@ -pragma solidity ^0.5.2; - - -library TransferWithSigUtils { - function getTokenTransferOrderHash(address token, address spender, uint256 amount, bytes32 data, uint256 expiration) - public - pure - returns (bytes32 orderHash) - { - orderHash = hashEIP712Message(token, hashTokenTransferOrder(spender, amount, data, expiration)); - } - - function hashTokenTransferOrder(address spender, uint256 amount, bytes32 data, uint256 expiration) - internal - pure - returns (bytes32 result) - { - string memory EIP712_TOKEN_TRANSFER_ORDER_SCHEMA = "TokenTransferOrder(address spender,uint256 tokenIdOrAmount,bytes32 data,uint256 expiration)"; - bytes32 EIP712_TOKEN_TRANSFER_ORDER_SCHEMA_HASH = keccak256(abi.encodePacked(EIP712_TOKEN_TRANSFER_ORDER_SCHEMA)); - bytes32 schemaHash = EIP712_TOKEN_TRANSFER_ORDER_SCHEMA_HASH; - assembly { - // Load free memory pointer - let memPtr := mload(64) - mstore(memPtr, schemaHash) // hash of schema - mstore(add(memPtr, 32), and(spender, 0xffffffffffffffffffffffffffffffffffffffff)) // spender - mstore(add(memPtr, 64), amount) // amount - mstore(add(memPtr, 96), data) // hash of data - mstore(add(memPtr, 128), expiration) // expiration - // Compute hash - result := keccak256(memPtr, 160) - } - } - - function hashEIP712Message(address token, bytes32 hashStruct) - internal - pure - returns (bytes32 result) - { - string memory EIP712_DOMAIN_SCHEMA = "EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"; - 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 }}; - bytes32 EIP712_DOMAIN_HASH = keccak256(abi.encode( - EIP712_DOMAIN_SCHEMA_HASH, - keccak256(bytes(EIP712_DOMAIN_NAME)), - keccak256(bytes(EIP712_DOMAIN_VERSION)), - EIP712_DOMAIN_CHAINID, - token - )); - bytes32 domainHash = EIP712_DOMAIN_HASH; - assembly { - // Load free memory pointer - let memPtr := mload(64) - mstore(memPtr, 0x1901000000000000000000000000000000000000000000000000000000000000) // EIP191 header - mstore(add(memPtr, 2), domainHash) // EIP712 domain hash - mstore(add(memPtr, 34), hashStruct) // Hash of struct - // Compute hash - result := keccak256(memPtr, 66) - } - } -} diff --git a/contracts/test/MarketplacePredicateTest.sol b/contracts/test/MarketplacePredicateTest.sol deleted file mode 100644 index 770094b24..000000000 --- a/contracts/test/MarketplacePredicateTest.sol +++ /dev/null @@ -1,73 +0,0 @@ -pragma solidity ^0.5.2; - -import {RLPReader} from "solidity-rlp/contracts/RLPReader.sol"; - -import { - MarketplacePredicate -} from "../root/predicates/MarketplacePredicate.sol"; -import {ERC20Predicate} from "../root/predicates/ERC20Predicate.sol"; - -contract MarketplacePredicateTest is MarketplacePredicate { - constructor() - public - MarketplacePredicate(address(0x0), address(0x0), address(0x0)) - {} - - function processLogTransferReceiptTest( - address predicate, - bytes memory data, - address participant - ) public view returns (bytes memory b) { - ReferenceTxData memory _referenceTx = super.processLogTransferReceipt( - predicate, - data, - participant, - false, - false - ); - b = abi.encode( - _referenceTx.closingBalance, - _referenceTx.age, - _referenceTx.childToken, - _referenceTx.rootToken - ); - } - - function processExitTx(bytes memory exitTx) - public - view - returns (bytes memory b) - { - ExitTxData memory txData = super.processExitTx(exitTx, msg.sender); - b = abi.encode( - txData.amount1, - txData.amount2, - txData.token1, - txData.token2, - txData.counterParty - ); - } - - function testGetAddressFromTx(bytes memory exitTx) - public - pure - returns (address signer, bytes32 txHash) - { - RLPReader.RLPItem[] memory txList = exitTx.toRlpItem().toList(); - (signer, txHash) = getAddressFromTx(txList); - } - - function decodeExitTx(bytes memory exitTx) - internal - pure - returns (ExitTxData memory txData) - { - ( - txData.amount1, - txData.amount2, - txData.token1, - txData.token2, - txData.counterParty - ) = abi.decode(exitTx, (uint256, uint256, address, address, address)); - } -} diff --git a/contracts/test/PolygonMigrationTest.sol b/contracts/test/PolygonMigrationTest.sol new file mode 100644 index 000000000..6089be8ce --- /dev/null +++ b/contracts/test/PolygonMigrationTest.sol @@ -0,0 +1,34 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.5.2; + +import {IERC20} from "openzeppelin-solidity/contracts/token/ERC20/IERC20.sol"; +import {SafeERC20} from "openzeppelin-solidity/contracts/token/ERC20/SafeERC20.sol"; + +// this impl was shortened for testing purposes +// full impl at https://github.com/0xPolygon/indicia/blob/main/src/PolygonMigration.sol +contract PolygonMigrationTest { + using SafeERC20 for IERC20; + + event Migrated(address indexed account, uint256 amount); + + IERC20 public polygon; + IERC20 public matic; + + function setTokenAddresses(address matic_, address polygon_) external { + if (matic_ == address(0)) revert(); + matic = IERC20(matic_); + + if (polygon_ == address(0)) revert(); + polygon = IERC20(polygon_); + } + + /// @notice This function allows for migrating MATIC tokens to POL tokens + /// @dev The function does not do any validation since the migration is a one-way process + /// @param amount Amount of MATIC to migrate + function migrate(uint256 amount) external { + emit Migrated(msg.sender, amount); + + matic.safeTransferFrom(msg.sender, address(this), amount); + polygon.safeTransfer(msg.sender, amount); + } +} diff --git a/debug.sh b/debug.sh deleted file mode 100644 index ecb3edf1d..000000000 --- a/debug.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env sh - -cd test-blockchain -bash clean.sh -bash start.sh diff --git a/deploy-migrations/1_initial_migration.js b/deploy-migrations/1_initial_migration.js deleted file mode 100644 index 1eb6f9daf..000000000 --- a/deploy-migrations/1_initial_migration.js +++ /dev/null @@ -1,5 +0,0 @@ -var Migrations = artifacts.require('./Migrations.sol') - -module.exports = function(deployer) { - deployer.deploy(Migrations) -} diff --git a/deploy-migrations/2_deploy_root_contracts.js b/deploy-migrations/2_deploy_root_contracts.js deleted file mode 100644 index 52f15d801..000000000 --- a/deploy-migrations/2_deploy_root_contracts.js +++ /dev/null @@ -1,245 +0,0 @@ -const bluebird = require('bluebird') - -const utils = require('./utils') - -const SafeMath = artifacts.require( - 'SafeMath' -) -const RLPReader = artifacts.require('solidity-rlp/contracts/RLPReader.sol') - -const BytesLib = artifacts.require('BytesLib') -const Common = artifacts.require('Common') -const ECVerify = artifacts.require('ECVerify') -const Merkle = artifacts.require('Merkle') -const MerklePatriciaProof = artifacts.require('MerklePatriciaProof') -const PriorityQueue = artifacts.require('PriorityQueue') -const RLPEncode = artifacts.require('RLPEncode') -const TransferWithSigUtils = artifacts.require('TransferWithSigUtils') - -const Registry = artifacts.require('Registry') -const RootChain = artifacts.require('RootChain') -const Governance = artifacts.require('Governance') -const GovernanceProxy = artifacts.require('GovernanceProxy') -const RootChainProxy = artifacts.require('RootChainProxy') -const DepositManager = artifacts.require('DepositManager') -const DepositManagerProxy = artifacts.require('DepositManagerProxy') -const WithdrawManager = artifacts.require('WithdrawManager') -const WithdrawManagerProxy = artifacts.require('WithdrawManagerProxy') -const StateSender = artifacts.require('StateSender') -const StakeManager = artifacts.require('StakeManager') -const ValidatorShare = artifacts.require('ValidatorShare') -const SlashingManager = artifacts.require('SlashingManager') -const StakeManagerProxy = artifacts.require('StakeManagerProxy') -const StakingInfo = artifacts.require('StakingInfo') -const StakingNFT = artifacts.require('StakingNFT') -const ValidatorShareFactory = artifacts.require('ValidatorShareFactory') -const ERC20Predicate = artifacts.require('ERC20Predicate') -const ERC721Predicate = artifacts.require('ERC721Predicate') -const MintableERC721Predicate = artifacts.require('MintableERC721Predicate') -const MarketplacePredicate = artifacts.require('MarketplacePredicate') -const TransferWithSigPredicate = artifacts.require('TransferWithSigPredicate') -const ExitNFT = artifacts.require('ExitNFT') - -// tokens -const MaticWeth = artifacts.require('MaticWETH') -const TestToken = artifacts.require('TestToken') -const RootERC721 = artifacts.require('RootERC721') - -const libDeps = [ - { - lib: BytesLib, - contracts: [ - WithdrawManager, - ERC20Predicate, - ERC721Predicate, - MintableERC721Predicate - ] - }, - { - lib: Common, - contracts: [ - WithdrawManager, - ERC20Predicate, - ERC721Predicate, - MintableERC721Predicate, - MarketplacePredicate, - TransferWithSigPredicate - ] - }, - { - lib: ECVerify, - contracts: [ - StakeManager, - SlashingManager, - MarketplacePredicate, - TransferWithSigPredicate - ] - }, - { - lib: Merkle, - contracts: [WithdrawManager, ERC20Predicate, ERC721Predicate, StakeManager, MintableERC721Predicate] - }, - { - lib: MerklePatriciaProof, - contracts: [WithdrawManager, ERC20Predicate, ERC721Predicate, MintableERC721Predicate] - }, - { - lib: PriorityQueue, - contracts: [WithdrawManager] - }, - { - lib: RLPEncode, - contracts: [ - WithdrawManager, - ERC20Predicate, - ERC721Predicate, - MarketplacePredicate - ] - }, - { - lib: RLPReader, - contracts: [ - RootChain, - StakeManager, - ERC20Predicate, - ERC721Predicate, - MintableERC721Predicate, - MarketplacePredicate, - TransferWithSigPredicate - ] - }, - { - lib: SafeMath, - contracts: [ - RootChain, - ERC20Predicate, - StakeManager, - SlashingManager, - StateSender, - StakingInfo - ] - }, - { - lib: TransferWithSigUtils, - contracts: [MarketplacePredicate, TransferWithSigPredicate] - } -] - -module.exports = async function(deployer) { - if (!process.env.HEIMDALL_ID) { - throw new Error('Please export HEIMDALL_ID environment variable') - } - - deployer.then(async () => { - console.log('linking libs...') - await bluebird.map(libDeps, async e => { - await deployer.deploy(e.lib) - deployer.link(e.lib, e.contracts) - }) - - console.log('deploying contracts...') - await deployer.deploy(Governance) - await deployer.deploy(GovernanceProxy, Governance.address) - await deployer.deploy(Registry, GovernanceProxy.address) - - await deployer.deploy(RootChain) - await deployer.deploy(RootChainProxy, RootChain.address, Registry.address, process.env.HEIMDALL_ID) - - await deployer.deploy(ValidatorShareFactory) - await deployer.deploy(StakingInfo, Registry.address) - await deployer.deploy(StakingNFT, 'Matic Validator', 'MV') - - console.log('deploying tokens...') - await deployer.deploy(MaticWeth) - await deployer.deploy(TestToken, 'MATIC', 'MATIC') - const testToken = await TestToken.new('Test ERC20', 'TST20') - await deployer.deploy(RootERC721, 'Test ERC721', 'TST721') - - const stakeManager = await deployer.deploy(StakeManager) - const proxy = await deployer.deploy(StakeManagerProxy, '0x0000000000000000000000000000000000000000') - await proxy.updateAndCall(StakeManager.address, stakeManager.contract.methods.initialize(Registry.address, RootChainProxy.address, TestToken.address, StakingNFT.address, StakingInfo.address, ValidatorShareFactory.address, GovernanceProxy.address).encodeABI()) - - await deployer.deploy(SlashingManager, Registry.address, StakingInfo.address, process.env.HEIMDALL_ID) - await deployer.deploy(ValidatorShare, Registry.address, 0/** dummy id */, StakingInfo.address, StakeManagerProxy.address) - await deployer.deploy(StateSender) - - await deployer.deploy(DepositManager) - await deployer.deploy( - DepositManagerProxy, - DepositManager.address, - Registry.address, - RootChainProxy.address, - GovernanceProxy.address - ) - - await deployer.deploy(WithdrawManager) - await deployer.deploy(ExitNFT, Registry.address) - await deployer.deploy( - WithdrawManagerProxy, - WithdrawManager.address, - Registry.address, - RootChainProxy.address, - ExitNFT.address - ) - - console.log('deploying predicates...') - await deployer.deploy( - ERC20Predicate, - WithdrawManagerProxy.address, - DepositManagerProxy.address, - Registry.address - ) - await deployer.deploy( - ERC721Predicate, - WithdrawManagerProxy.address, - DepositManagerProxy.address - ) - await deployer.deploy( - MarketplacePredicate, - RootChainProxy.address, - WithdrawManagerProxy.address, - Registry.address - ) - await deployer.deploy( - TransferWithSigPredicate, - RootChainProxy.address, - WithdrawManagerProxy.address, - Registry.address - ) - - console.log('writing contract addresses to file...') - const contractAddresses = { - root: { - Registry: Registry.address, - RootChain: RootChain.address, - Governance: Governance.address, - GovernanceProxy: GovernanceProxy.address, - RootChainProxy: RootChainProxy.address, - DepositManager: DepositManager.address, - DepositManagerProxy: DepositManagerProxy.address, - WithdrawManager: WithdrawManager.address, - WithdrawManagerProxy: WithdrawManagerProxy.address, - StakeManager: StakeManager.address, - StakeManagerProxy: StakeManagerProxy.address, - ValidatorShare: ValidatorShare.address, - SlashingManager: SlashingManager.address, - StakingInfo: StakingInfo.address, - ExitNFT: ExitNFT.address, - StateSender: StateSender.address, - predicates: { - ERC20Predicate: ERC20Predicate.address, - ERC721Predicate: ERC721Predicate.address, - MarketplacePredicate: MarketplacePredicate.address, - TransferWithSigPredicate: TransferWithSigPredicate.address - }, - tokens: { - MaticWeth: MaticWeth.address, - MaticToken: TestToken.address, - TestToken: testToken.address, - RootERC721: RootERC721.address - } - } - } - utils.writeContractAddresses(contractAddresses) - }) -} diff --git a/deploy-migrations/3_initialize_state.js b/deploy-migrations/3_initialize_state.js deleted file mode 100644 index b578e0b90..000000000 --- a/deploy-migrations/3_initialize_state.js +++ /dev/null @@ -1,120 +0,0 @@ -const ethUtils = require('ethereumjs-util') -const bluebird = require('bluebird') - -const Registry = artifacts.require('Registry') -const DepositManagerProxy = artifacts.require('DepositManagerProxy') -const StateSender = artifacts.require('StateSender') -const WithdrawManagerProxy = artifacts.require('WithdrawManagerProxy') -const StakeManagerProxy = artifacts.require('StakeManagerProxy') -const SlashingManager = artifacts.require('SlashingManager') -const ERC20Predicate = artifacts.require('ERC20Predicate') -const ERC721Predicate = artifacts.require('ERC721Predicate') -const MarketplacePredicate = artifacts.require('MarketplacePredicate') -const TransferWithSigPredicate = artifacts.require('TransferWithSigPredicate') -const MaticWeth = artifacts.require('MaticWETH') -const Governance = artifacts.require('Governance') -const EventsHubProxy = artifacts.require('EventsHubProxy') - -async function updateContractMap(governance, registry, nameHash, value) { - return governance.update( - registry.address, - registry.contract.methods.updateContractMap(nameHash, value).encodeABI() - ) -} - -module.exports = async function(deployer) { - deployer.then(async() => { - await bluebird - .all([ - Governance.deployed(), - Registry.deployed(), - DepositManagerProxy.deployed(), - StateSender.deployed(), - WithdrawManagerProxy.deployed(), - StakeManagerProxy.deployed(), - SlashingManager.deployed(), - ERC20Predicate.deployed(), - ERC721Predicate.deployed(), - MarketplacePredicate.deployed(), - TransferWithSigPredicate.deployed(), - EventsHubProxy.deployed() - ]) - .spread(async function( - governance, - registry, - depositManagerProxy, - stateSender, - withdrawManagerProxy, - stakeManagerProxy, - slashingManager, - ERC20Predicate, - ERC721Predicate, - MarketplacePredicate, - TransferWithSigPredicate, - EventsHubProxy - ) { - await updateContractMap( - governance, - registry, - ethUtils.keccak256('depositManager'), - depositManagerProxy.address - ) - await updateContractMap( - governance, - registry, - ethUtils.keccak256('withdrawManager'), - withdrawManagerProxy.address - ) - await updateContractMap( - governance, - registry, - ethUtils.keccak256('stakeManager'), - stakeManagerProxy.address - ) - await updateContractMap( - governance, - registry, - ethUtils.keccak256('slashingManager'), - slashingManager.address - ) - await updateContractMap( - governance, - registry, - ethUtils.keccak256('stateSender'), - stateSender.address - ) - await updateContractMap( - governance, - registry, - ethUtils.keccak256('wethToken'), - MaticWeth.address - ) - await updateContractMap( - governance, - registry, - ethUtils.keccak256('eventsHub'), - EventsHubProxy.address - ) - - // whitelist predicates - await governance.update( - registry.address, - registry.contract.methods.addErc20Predicate(ERC20Predicate.address).encodeABI() - ) - - await governance.update( - registry.address, - registry.contract.methods.addErc721Predicate(ERC721Predicate.address).encodeABI() - ) - - await governance.update( - registry.address, - registry.contract.methods.addPredicate(MarketplacePredicate.address, 3).encodeABI() - ) - await governance.update( - registry.address, - registry.contract.methods.addPredicate(TransferWithSigPredicate.address, 3).encodeABI() - ) - }) - }) -} diff --git a/deploy-migrations/4_deploy_child_contracts.js b/deploy-migrations/4_deploy_child_contracts.js deleted file mode 100644 index 7194ea664..000000000 --- a/deploy-migrations/4_deploy_child_contracts.js +++ /dev/null @@ -1,64 +0,0 @@ -const utils = require('./utils') - -const SafeMath = artifacts.require( - 'openzeppelin-solidity/contracts/math/SafeMath.sol' -) -const ChildChain = artifacts.require('ChildChain') -const MRC20 = artifacts.require('MRC20') - -module.exports = async function(deployer, network, accounts) { - deployer.then(async() => { - await deployer.deploy(SafeMath) - await deployer.link(SafeMath, [ChildChain]) - await deployer.deploy(ChildChain) - - const childChain = await ChildChain.deployed() - const contractAddresses = utils.getContractAddresses() - - let MaticWeth = await childChain.addToken( - accounts[0], - contractAddresses.root.tokens.MaticWeth, - 'ETH on Matic', - 'ETH', - 18, - false // _isERC721 - ) - - let TestToken = await childChain.addToken( - accounts[0], - contractAddresses.root.tokens.TestToken, - 'Test Token', - 'TST', - 18, - false // _isERC721 - ) - - let RootERC721 = await childChain.addToken( - accounts[0], - contractAddresses.root.tokens.RootERC721, - 'Test ERC721', - 'TST721', - 0, - true // _isERC721 - ) - - const maticToken = await MRC20.at('0x0000000000000000000000000000000000001010') - const maticOwner = await maticToken.owner() - if (maticOwner === '0x0000000000000000000000000000000000000000') { - // matic contract at 0x1010 can only be initialized once, after the bor image starts to run - await maticToken.initialize(ChildChain.address, contractAddresses.root.tokens.MaticToken) - } - await childChain.mapToken(contractAddresses.root.tokens.MaticToken, '0x0000000000000000000000000000000000001010', false) - - contractAddresses.child = { - ChildChain: ChildChain.address, - tokens: { - MaticWeth: MaticWeth.logs.find(log => log.event === 'NewToken').args.token, - MaticToken: '0x0000000000000000000000000000000000001010', - TestToken: TestToken.logs.find(log => log.event === 'NewToken').args.token, - RootERC721: RootERC721.logs.find(log => log.event === 'NewToken').args.token - } - } - utils.writeContractAddresses(contractAddresses) - }) -} diff --git a/deploy-migrations/5_sync_child_state_to_root.js b/deploy-migrations/5_sync_child_state_to_root.js deleted file mode 100644 index 38dcf657e..000000000 --- a/deploy-migrations/5_sync_child_state_to_root.js +++ /dev/null @@ -1,73 +0,0 @@ -const ethUtils = require('ethereumjs-util') -const utils = require('./utils') - -const Registry = artifacts.require('Registry') -const Governance = artifacts.require('Governance') -const StateSender = artifacts.require('StateSender') -const DepositManager = artifacts.require('DepositManager') - -module.exports = async function(deployer, network, accounts) { - deployer.then(async() => { - const contractAddresses = utils.getContractAddresses() - const registry = await Registry.at(contractAddresses.root.Registry) - const governance = await Governance.at(contractAddresses.root.GovernanceProxy) - const tasks = [] - - tasks.push(governance.update( - contractAddresses.root.Registry, - registry.contract.methods.mapToken( - contractAddresses.root.tokens.MaticWeth, - contractAddresses.child.tokens.MaticWeth, - false /* isERC721 */ - ).encodeABI() - )) - await delay(5) - - tasks.push(governance.update( - contractAddresses.root.Registry, - registry.contract.methods.mapToken( - contractAddresses.root.tokens.MaticToken, - contractAddresses.child.tokens.MaticToken, - false /* isERC721 */ - ).encodeABI() - )) - await delay(5) - - tasks.push(governance.update( - contractAddresses.root.Registry, - registry.contract.methods.mapToken( - contractAddresses.root.tokens.TestToken, - contractAddresses.child.tokens.TestToken, - false /* isERC721 */ - ).encodeABI() - )) - await delay(5) - - tasks.push(governance.update( - contractAddresses.root.Registry, - registry.contract.methods.mapToken( - contractAddresses.root.tokens.RootERC721, - contractAddresses.child.tokens.RootERC721, - true /* isERC721 */ - ).encodeABI() - )) - await delay(5) - - tasks.push(governance.update( - contractAddresses.root.Registry, - registry.contract.methods.updateContractMap( - ethUtils.keccak256('childChain'), - contractAddresses.child.ChildChain - ).encodeABI() - )) - await Promise.all(tasks) - - await (await StateSender.at(contractAddresses.root.StateSender)).register(contractAddresses.root.DepositManagerProxy, contractAddresses.child.ChildChain) - let depositManager = await DepositManager.at(contractAddresses.root.DepositManagerProxy) - await depositManager.updateChildChainAndStateSender() - }) -} - -function delay(s) { - return new Promise(resolve => setTimeout(resolve, s * 1000)); -} diff --git a/deploy-migrations/README.md b/deploy-migrations/README.md deleted file mode 100644 index 4dd155f4d..000000000 --- a/deploy-migrations/README.md +++ /dev/null @@ -1,76 +0,0 @@ -# Deploy Contracts - -### :one: We have some network configrations available. - -| Network Name | URL | Network ID | -| ------------ | :-------------------------------------: | ---------: | -| ropsten | https://ropsten.infura.io/v3/${API_KEY} | 3 | -| mainnet | https://mainnet.infura.io/v3/${API_KEY} | 1 | -| development | http://localhost:9545 | \* | -| bor | http://localhost:8545 | \* | - -Feel free to add your own. Update the chain url in `networks.matic` key in [truffle-config.js](../truffle-config.js). - -### :two: Export variables - -``` -// (Optional) Only if you are using ethereum testnets -export API_KEY= - -// For `developement` networks you can use the mnemonic present in package.json -export MNEMONIC= - -export HEIMDALL_ID=<> -e.g. export HEIMDALL_ID="heimdall-P5rXwg" -``` - -### :three: Choose Bor Chain Id - -``` -npm run template:process -- --bor-chain-id -for instance, npm run template:process -- --bor-chain-id 80001 -``` - -### :four: Compile contracts - -``` -npm run truffle:compile -``` - -### :five: Deploy contracts - -We need to deploy our set of contracts on 2 chains: - -- Base Chain: Ideally a higher security EVM chain which can be used for dispute resolution. For testing ganache or any other EVM chain should work. -- Child Chain: EVM compatible chain to work as our sidechain. For testing note that using `ganache` for child-chain is not recommended, instead invoking `npm run bor:simulate` would be better. - -``` - -// Root contracts are deployed on base chain -npm run truffle:migrate -- --reset --to 4 --network - -// Contracts like ChildERC20Token are deployed on child chain aka BOR chain -// NOTE: You need to deploy or simulate BOR before running the below command -npm run truffle:migrate -- --reset -f 5 --to 5 --network - - -// Contracts deployed on BOR are mapped to the registry contract deployed on-chain -npm run truffle:migrate -- -f 6 --to 6 --network -``` - -Post successfull deployment all contract addresses will be written to a `contractAddresses.json` file. - -> Check account that you are deploying from has ether for the network you are deploying on. - -### :six: Stake to become a validator - -``` -// (Optional) Export mnemonic or the private key (without the 0x prefix) -// This account needs to have test token -export MNEMONIC=<> - -// (Optional) Infura PROJECT ID, if required -export API_KEY= - -npm run truffle exec scripts/stake.js -- --network <# tokens to stake> -``` diff --git a/deploy-migrations/utils.js b/deploy-migrations/utils.js deleted file mode 100644 index 6457f02c7..000000000 --- a/deploy-migrations/utils.js +++ /dev/null @@ -1,12 +0,0 @@ -const fs = require('fs') - -export function getContractAddresses() { - return JSON.parse(fs.readFileSync(`${process.cwd()}/contractAddresses.json`).toString()) -} - -export function writeContractAddresses(contractAddresses) { - fs.writeFileSync( - `${process.cwd()}/contractAddresses.json`, - JSON.stringify(contractAddresses, null, 2) // Indent 2 spaces - ) -} diff --git a/docs/autogen/.gitignore b/docs/autogen/.gitignore new file mode 100644 index 000000000..4e42a1bcd --- /dev/null +++ b/docs/autogen/.gitignore @@ -0,0 +1 @@ +book/ \ No newline at end of file diff --git a/docs/autogen/book.css b/docs/autogen/book.css new file mode 100644 index 000000000..b5ce903f9 --- /dev/null +++ b/docs/autogen/book.css @@ -0,0 +1,13 @@ +table { + margin: 0 auto; + border-collapse: collapse; + width: 100%; +} + +table td:first-child { + width: 15%; +} + +table td:nth-child(2) { + width: 25%; +} \ No newline at end of file diff --git a/docs/autogen/book.toml b/docs/autogen/book.toml new file mode 100644 index 000000000..f63044be2 --- /dev/null +++ b/docs/autogen/book.toml @@ -0,0 +1,12 @@ +[book] +src = "src" +title = "" + +[output.html] +no-section-label = true +additional-js = ["solidity.min.js"] +additional-css = ["book.css"] +git-repository-url = "https://github.com/maticnetwork/contracts" + +[output.html.fold] +enable = true diff --git a/docs/autogen/solidity.min.js b/docs/autogen/solidity.min.js new file mode 100644 index 000000000..192493291 --- /dev/null +++ b/docs/autogen/solidity.min.js @@ -0,0 +1,74 @@ +hljs.registerLanguage("solidity",(()=>{"use strict";function e(){try{return!0 +}catch(e){return!1}} +var a=/-?(\b0[xX]([a-fA-F0-9]_?)*[a-fA-F0-9]|(\b[1-9](_?\d)*(\.((\d_?)*\d)?)?|\.\d(_?\d)*)([eE][-+]?\d(_?\d)*)?|\b0)(?!\w|\$)/ +;e()&&(a=a.source.replace(/\\b/g,"(?{ +var a=r(e),o=l(e),c=/[A-Za-z_$][A-Za-z_$0-9.]*/,d=e.inherit(e.TITLE_MODE,{ +begin:/[A-Za-z$_][0-9A-Za-z$_]*/,lexemes:c,keywords:n}),u={className:"params", +begin:/\(/,end:/\)/,excludeBegin:!0,excludeEnd:!0,lexemes:c,keywords:n, +contains:[e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,a,o,s]},_={ +className:"operator",begin:/:=|->/};return{keywords:n,lexemes:c, +contains:[a,o,i,t,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,s,_,{ +className:"function",lexemes:c,beginKeywords:"function",end:"{",excludeEnd:!0, +contains:[d,u,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,_]}]}}, +solAposStringMode:r,solQuoteStringMode:l,HEX_APOS_STRING_MODE:i, +HEX_QUOTE_STRING_MODE:t,SOL_NUMBER:s,isNegativeLookbehindAvailable:e} +;const{baseAssembly:c,solAposStringMode:d,solQuoteStringMode:u,HEX_APOS_STRING_MODE:_,HEX_QUOTE_STRING_MODE:m,SOL_NUMBER:b,isNegativeLookbehindAvailable:E}=o +;return e=>{for(var a=d(e),s=u(e),n=[],i=0;i<32;i++)n[i]=i+1 +;var t=n.map((e=>8*e)),r=[];for(i=0;i<=80;i++)r[i]=i +;var l=n.map((e=>"bytes"+e)).join(" ")+" ",o=t.map((e=>"uint"+e)).join(" ")+" ",g=t.map((e=>"int"+e)).join(" ")+" ",M=[].concat.apply([],t.map((e=>r.map((a=>e+"x"+a))))),p={ +keyword:"var bool string int uint "+g+o+"byte bytes "+l+"fixed ufixed "+M.map((e=>"fixed"+e)).join(" ")+" "+M.map((e=>"ufixed"+e)).join(" ")+" enum struct mapping address new delete if else for while continue break return throw emit try catch revert unchecked _ function modifier event constructor fallback receive error virtual override constant immutable anonymous indexed storage memory calldata external public internal payable pure view private returns import from as using pragma contract interface library is abstract type assembly", +literal:"true false wei gwei szabo finney ether seconds minutes hours days weeks years", +built_in:"self this super selfdestruct suicide now msg block tx abi blockhash gasleft assert require Error Panic sha3 sha256 keccak256 ripemd160 ecrecover addmod mulmod log0 log1 log2 log3 log4" +},O={className:"operator",begin:/[+\-!~*\/%<>&^|=]/ +},C=/[A-Za-z_$][A-Za-z_$0-9]*/,N={className:"params",begin:/\(/,end:/\)/, +excludeBegin:!0,excludeEnd:!0,lexemes:C,keywords:p, +contains:[e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,a,s,b,"self"]},f={ +begin:/\.\s*/,end:/[^A-Za-z0-9$_\.]/,excludeBegin:!0,excludeEnd:!0,keywords:{ +built_in:"gas value selector address length push pop send transfer call callcode delegatecall staticcall balance code codehash wrap unwrap name creationCode runtimeCode interfaceId min max" +},relevance:2},y=e.inherit(e.TITLE_MODE,{begin:/[A-Za-z$_][0-9A-Za-z$_]*/, +lexemes:C,keywords:p}),w={className:"built_in", +begin:(E()?"(?`|`bool`|Returns success of function call.| + + +## Events +### Deposit + +```solidity +event Deposit(address indexed token, address indexed from, uint256 amount, uint256 input1, uint256 output1); +``` + +### Withdraw + +```solidity +event Withdraw(address indexed token, address indexed from, uint256 amount, uint256 input1, uint256 output1); +``` + +### LogTransfer + +```solidity +event LogTransfer( + address indexed token, address indexed from, address indexed to, uint256 amount, uint256 input1, uint256 input2, uint256 output1, uint256 output2 +); +``` + diff --git a/docs/autogen/src/contracts/child/BaseERC20NoSig.sol/contract.BaseERC20NoSig.md b/docs/autogen/src/contracts/child/BaseERC20NoSig.sol/contract.BaseERC20NoSig.md new file mode 100644 index 000000000..956e26ca3 --- /dev/null +++ b/docs/autogen/src/contracts/child/BaseERC20NoSig.sol/contract.BaseERC20NoSig.md @@ -0,0 +1,78 @@ +# BaseERC20NoSig +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/child/BaseERC20NoSig.sol) + +**Inherits:** +[ChildToken](/contracts/child/ChildToken.sol/contract.ChildToken.md) + + +## Functions +### constructor + + +```solidity +constructor() public; +``` + +### transferWithSig + + +```solidity +function transferWithSig(bytes calldata sig, uint256 amount, bytes32 data, uint256 expiration, address to) external returns (address from); +``` + +### balanceOf + + +```solidity +function balanceOf(address account) external view returns (uint256); +``` + +### _transfer + + +```solidity +function _transfer(address sender, address recipient, uint256 amount) internal; +``` + +### _transferFrom + + +```solidity +function _transferFrom(address from, address to, uint256 value) internal returns (bool); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`from`|`address`|Address from where tokens are withdrawn.| +|`to`|`address`|Address to where tokens are sent.| +|`value`|`uint256`|Number of tokens to transfer.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bool`|Returns success of function call.| + + +## Events +### Deposit + +```solidity +event Deposit(address indexed token, address indexed from, uint256 amount, uint256 input1, uint256 output1); +``` + +### Withdraw + +```solidity +event Withdraw(address indexed token, address indexed from, uint256 amount, uint256 input1, uint256 output1); +``` + +### LogTransfer + +```solidity +event LogTransfer( + address indexed token, address indexed from, address indexed to, uint256 amount, uint256 input1, uint256 input2, uint256 output1, uint256 output2 +); +``` + diff --git a/docs/autogen/src/contracts/child/ChildChain.sol/contract.ChildChain.md b/docs/autogen/src/contracts/child/ChildChain.sol/contract.ChildChain.md new file mode 100644 index 000000000..732c5a6df --- /dev/null +++ b/docs/autogen/src/contracts/child/ChildChain.sol/contract.ChildChain.md @@ -0,0 +1,101 @@ +# ChildChain +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/child/ChildChain.sol) + +**Inherits:** +Ownable, [StateSyncerVerifier](/contracts/child/bor/StateSyncerVerifier.sol/contract.StateSyncerVerifier.md), [StateReceiver](/contracts/child/bor/StateReceiver.sol/interface.StateReceiver.md) + + +## State Variables +### tokens + +```solidity +mapping(address => address) public tokens; +``` + + +### isERC721 + +```solidity +mapping(address => bool) public isERC721; +``` + + +### deposits + +```solidity +mapping(uint256 => bool) public deposits; +``` + + +### withdraws + +```solidity +mapping(uint256 => bool) public withdraws; +``` + + +## Functions +### constructor + + +```solidity +constructor() public; +``` + +### onStateReceive + + +```solidity +function onStateReceive(uint256, bytes calldata data) external onlyStateSyncer; +``` + +### addToken + + +```solidity +function addToken(address _owner, address _rootToken, string memory _name, string memory _symbol, uint8 _decimals, bool _isERC721) + public + onlyOwner + returns (address token); +``` + +### mapToken + + +```solidity +function mapToken(address rootToken, address token, bool isErc721) public onlyOwner; +``` + +### withdrawTokens + + +```solidity +function withdrawTokens(address rootToken, address user, uint256 amountOrTokenId, uint256 withdrawCount) public onlyOwner; +``` + +### depositTokens + + +```solidity +function depositTokens(address rootToken, address user, uint256 amountOrTokenId, uint256 depositId) internal; +``` + +## Events +### NewToken + +```solidity +event NewToken(address indexed rootToken, address indexed token, uint8 _decimals); +``` + +### TokenDeposited + +```solidity +event TokenDeposited(address indexed rootToken, address indexed childToken, address indexed user, uint256 amount, uint256 depositCount); +``` + +### TokenWithdrawn + +```solidity +event TokenWithdrawn(address indexed rootToken, address indexed childToken, address indexed user, uint256 amount, uint256 withrawCount); +``` + diff --git a/docs/autogen/src/contracts/child/ChildERC20.sol/contract.ChildERC20.md b/docs/autogen/src/contracts/child/ChildERC20.sol/contract.ChildERC20.md new file mode 100644 index 000000000..bc46a7ed3 --- /dev/null +++ b/docs/autogen/src/contracts/child/ChildERC20.sol/contract.ChildERC20.md @@ -0,0 +1,103 @@ +# ChildERC20 +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/child/ChildERC20.sol) + +**Inherits:** +[BaseERC20](/contracts/child/BaseERC20.sol/contract.BaseERC20.md), ERC20, [ERC20Detailed](/contracts/child/ERC20Detailed.sol/contract.ERC20Detailed.md), [StateSyncerVerifier](/contracts/child/bor/StateSyncerVerifier.sol/contract.StateSyncerVerifier.md), [StateReceiver](/contracts/child/bor/StateReceiver.sol/interface.StateReceiver.md) + + +## Functions +### constructor + + +```solidity +constructor(address, address _token, string memory _name, string memory _symbol, uint8 _decimals) public ERC20Detailed(_name, _symbol, _decimals); +``` + +### deposit + +Deposit tokens + + +```solidity +function deposit(address user, uint256 amount) public onlyChildChain; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`user`|`address`|address for address| +|`amount`|`uint256`|token balance| + + +### withdraw + +Withdraw tokens + + +```solidity +function withdraw(uint256 amount) public payable; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`amount`|`uint256`|tokens| + + +### onStateReceive + + +```solidity +function onStateReceive(uint256, bytes calldata data) external onlyStateSyncer; +``` + +### _withdraw + + +```solidity +function _withdraw(address user, uint256 amount) internal; +``` + +### transfer + +*Function that is called when a user or another contract wants to transfer funds.* + + +```solidity +function transfer(address to, uint256 value) public returns (bool); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`to`|`address`|Address of token receiver.| +|`value`|`uint256`|Number of tokens to transfer.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bool`|Returns success of function call.| + + +### allowance + + +```solidity +function allowance(address, address) public view returns (uint256); +``` + +### approve + + +```solidity +function approve(address, uint256) public returns (bool); +``` + +### transferFrom + + +```solidity +function transferFrom(address, address, uint256) public returns (bool); +``` + diff --git a/docs/autogen/src/contracts/child/ChildERC721.sol/contract.ChildERC721.md b/docs/autogen/src/contracts/child/ChildERC721.sol/contract.ChildERC721.md new file mode 100644 index 000000000..afa0fac82 --- /dev/null +++ b/docs/autogen/src/contracts/child/ChildERC721.sol/contract.ChildERC721.md @@ -0,0 +1,123 @@ +# ChildERC721 +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/child/ChildERC721.sol) + +**Inherits:** +[ChildToken](/contracts/child/ChildToken.sol/contract.ChildToken.md), ERC721Full, [StateSyncerVerifier](/contracts/child/bor/StateSyncerVerifier.sol/contract.StateSyncerVerifier.md), [StateReceiver](/contracts/child/bor/StateReceiver.sol/interface.StateReceiver.md) + + +## Functions +### constructor + + +```solidity +constructor(address, address _token, string memory name, string memory symbol) public ERC721Full(name, symbol); +``` + +### transferWithSig + + +```solidity +function transferWithSig(bytes calldata sig, uint256 tokenId, bytes32 data, uint256 expiration, address to) external returns (address); +``` + +### approve + + +```solidity +function approve(address to, uint256 tokenId) public; +``` + +### getApproved + + +```solidity +function getApproved(uint256 tokenId) public view returns (address operator); +``` + +### setApprovalForAll + + +```solidity +function setApprovalForAll(address operator, bool _approved) public; +``` + +### isApprovedForAll + + +```solidity +function isApprovedForAll(address owner, address operator) public view returns (bool); +``` + +### deposit + +Deposit tokens + + +```solidity +function deposit(address user, uint256 tokenId) public onlyChildChain; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`user`|`address`|address for deposit| +|`tokenId`|`uint256`|tokenId to mint to user's account| + + +### withdraw + +Withdraw tokens + + +```solidity +function withdraw(uint256 tokenId) public payable; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`tokenId`|`uint256`|tokenId of the token to be withdrawn| + + +### onStateReceive + + +```solidity +function onStateReceive(uint256, bytes calldata data) external onlyStateSyncer; +``` + +### transferFrom + +*Overriding the inherited method so that it emits LogTransfer* + + +```solidity +function transferFrom(address from, address to, uint256 tokenId) public; +``` + +### _transferFrom + + +```solidity +function _transferFrom(address from, address to, uint256 tokenId) internal; +``` + +## Events +### Deposit + +```solidity +event Deposit(address indexed token, address indexed from, uint256 tokenId); +``` + +### Withdraw + +```solidity +event Withdraw(address indexed token, address indexed from, uint256 tokenId); +``` + +### LogTransfer + +```solidity +event LogTransfer(address indexed token, address indexed from, address indexed to, uint256 tokenId); +``` + diff --git a/docs/autogen/src/contracts/child/ChildERC721Mintable.sol/contract.ChildERC721Mintable.md b/docs/autogen/src/contracts/child/ChildERC721Mintable.sol/contract.ChildERC721Mintable.md new file mode 100644 index 000000000..19a2a70f0 --- /dev/null +++ b/docs/autogen/src/contracts/child/ChildERC721Mintable.sol/contract.ChildERC721Mintable.md @@ -0,0 +1,15 @@ +# ChildERC721Mintable +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/child/ChildERC721Mintable.sol) + +**Inherits:** +[ChildERC721](/contracts/child/ChildERC721.sol/contract.ChildERC721.md), ERC721Mintable, ERC721MetadataMintable + + +## Functions +### constructor + + +```solidity +constructor(address rootToken, string memory name, string memory symbol) public ChildERC721(msg.sender, rootToken, name, symbol); +``` + diff --git a/docs/autogen/src/contracts/child/ChildToken.sol/contract.ChildToken.md b/docs/autogen/src/contracts/child/ChildToken.sol/contract.ChildToken.md new file mode 100644 index 000000000..93ca7ecb9 --- /dev/null +++ b/docs/autogen/src/contracts/child/ChildToken.sol/contract.ChildToken.md @@ -0,0 +1,100 @@ +# ChildToken +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/child/ChildToken.sol) + +**Inherits:** +Ownable, [LibTokenTransferOrder](/contracts/child/misc/LibTokenTransferOrder.sol/contract.LibTokenTransferOrder.md) + + +## State Variables +### token + +```solidity +address public token; +``` + + +### childChain + +```solidity +address public childChain; +``` + + +### parent + +```solidity +address public parent; +``` + + +### disabledHashes + +```solidity +mapping(bytes32 => bool) public disabledHashes; +``` + + +## Functions +### onlyChildChain + + +```solidity +modifier onlyChildChain(); +``` + +### deposit + + +```solidity +function deposit(address user, uint256 amountOrTokenId) public; +``` + +### withdraw + + +```solidity +function withdraw(uint256 amountOrTokenId) public payable; +``` + +### ecrecovery + + +```solidity +function ecrecovery(bytes32 hash, bytes memory sig) public pure returns (address result); +``` + +### changeChildChain + + +```solidity +function changeChildChain(address newAddress) public onlyOwner; +``` + +### setParent + + +```solidity +function setParent(address newAddress) public onlyOwner; +``` + +## Events +### LogFeeTransfer + +```solidity +event LogFeeTransfer( + address indexed token, address indexed from, address indexed to, uint256 amount, uint256 input1, uint256 input2, uint256 output1, uint256 output2 +); +``` + +### ChildChainChanged + +```solidity +event ChildChainChanged(address indexed previousAddress, address indexed newAddress); +``` + +### ParentChanged + +```solidity +event ParentChanged(address indexed previousAddress, address indexed newAddress); +``` + diff --git a/docs/autogen/src/contracts/child/ERC20Detailed.sol/contract.ERC20Detailed.md b/docs/autogen/src/contracts/child/ERC20Detailed.sol/contract.ERC20Detailed.md new file mode 100644 index 000000000..4ac1cc461 --- /dev/null +++ b/docs/autogen/src/contracts/child/ERC20Detailed.sol/contract.ERC20Detailed.md @@ -0,0 +1,77 @@ +# ERC20Detailed +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/child/ERC20Detailed.sol) + +*The decimals are only for visualization purposes. +All the operations are done using the smallest and indivisible token unit, +just as on Ethereum all the operations are done in wei.* + + +## State Variables +### _name + +```solidity +string internal _name; +``` + + +### _symbol + +```solidity +string internal _symbol; +``` + + +### _decimals + +```solidity +uint8 internal _decimals; +``` + + +## Functions +### constructor + + +```solidity +constructor(string memory name, string memory symbol, uint8 decimals) public; +``` + +### name + + +```solidity +function name() public view returns (string memory); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`string`|the name of the token.| + + +### symbol + + +```solidity +function symbol() public view returns (string memory); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`string`|the symbol of the token.| + + +### decimals + + +```solidity +function decimals() public view returns (uint8); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint8`|the number of decimals of the token.| + + diff --git a/docs/autogen/src/contracts/child/MRC20.sol/contract.MRC20.md b/docs/autogen/src/contracts/child/MRC20.sol/contract.MRC20.md new file mode 100644 index 000000000..af3f28220 --- /dev/null +++ b/docs/autogen/src/contracts/child/MRC20.sol/contract.MRC20.md @@ -0,0 +1,143 @@ +# MRC20 +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/child/MRC20.sol) + +**Inherits:** +[BaseERC20NoSig](/contracts/child/BaseERC20NoSig.sol/contract.BaseERC20NoSig.md) + +This contract is an ECR20 like wrapper over native ether (matic token) transfers on the matic chain + +*ERC20 methods have been made payable while keeping their method signature same as other ChildERC20s on Matic* + + +## State Variables +### currentSupply + +```solidity +uint256 public currentSupply = 0; +``` + + +### DECIMALS + +```solidity +uint8 private constant DECIMALS = 18; +``` + + +### isInitialized + +```solidity +bool isInitialized; +``` + + +## Functions +### constructor + + +```solidity +constructor() public; +``` + +### initialize + + +```solidity +function initialize(address _childChain, address _token) public; +``` + +### setParent + + +```solidity +function setParent(address) public; +``` + +### deposit + + +```solidity +function deposit(address user, uint256 amount) public onlyOwner; +``` + +### withdraw + + +```solidity +function withdraw(uint256 amount) public payable; +``` + +### name + + +```solidity +function name() public pure returns (string memory); +``` + +### symbol + + +```solidity +function symbol() public pure returns (string memory); +``` + +### decimals + + +```solidity +function decimals() public pure returns (uint8); +``` + +### totalSupply + + +```solidity +function totalSupply() public view returns (uint256); +``` + +### balanceOf + + +```solidity +function balanceOf(address account) public view returns (uint256); +``` + +### transfer + +*Function that is called when a user or another contract wants to transfer funds.* + + +```solidity +function transfer(address to, uint256 value) public payable returns (bool); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`to`|`address`|Address of token receiver.| +|`value`|`uint256`|Number of tokens to transfer.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bool`|Returns success of function call.| + + +### _transfer + +*_transfer is invoked by _transferFrom method that is inherited from BaseERC20. +This enables us to transfer MaticEth between users while keeping the interface same as that of an ERC20 Token.* + + +```solidity +function _transfer(address sender, address recipient, uint256 amount) internal; +``` + +## Events +### Transfer + +```solidity +event Transfer(address indexed from, address indexed to, uint256 value); +``` + diff --git a/docs/autogen/src/contracts/child/README.md b/docs/autogen/src/contracts/child/README.md new file mode 100644 index 000000000..f7cb9ca56 --- /dev/null +++ b/docs/autogen/src/contracts/child/README.md @@ -0,0 +1,15 @@ + + +# Contents +- [bor](/contracts/child/bor) +- [misc](/contracts/child/misc) +- [proxifiedChildToken](/contracts/child/proxifiedChildToken) +- [BaseERC20](BaseERC20.sol/contract.BaseERC20.md) +- [BaseERC20NoSig](BaseERC20NoSig.sol/contract.BaseERC20NoSig.md) +- [ChildChain](ChildChain.sol/contract.ChildChain.md) +- [ChildERC20](ChildERC20.sol/contract.ChildERC20.md) +- [ChildERC721](ChildERC721.sol/contract.ChildERC721.md) +- [ChildERC721Mintable](ChildERC721Mintable.sol/contract.ChildERC721Mintable.md) +- [ChildToken](ChildToken.sol/contract.ChildToken.md) +- [ERC20Detailed](ERC20Detailed.sol/contract.ERC20Detailed.md) +- [MRC20](MRC20.sol/contract.MRC20.md) diff --git a/docs/autogen/src/contracts/child/bor/README.md b/docs/autogen/src/contracts/child/bor/README.md new file mode 100644 index 000000000..4cb245c9c --- /dev/null +++ b/docs/autogen/src/contracts/child/bor/README.md @@ -0,0 +1,5 @@ + + +# Contents +- [StateReceiver](StateReceiver.sol/interface.StateReceiver.md) +- [StateSyncerVerifier](StateSyncerVerifier.sol/contract.StateSyncerVerifier.md) diff --git a/docs/autogen/src/contracts/child/bor/StateReceiver.sol/interface.StateReceiver.md b/docs/autogen/src/contracts/child/bor/StateReceiver.sol/interface.StateReceiver.md new file mode 100644 index 000000000..058d6b4a2 --- /dev/null +++ b/docs/autogen/src/contracts/child/bor/StateReceiver.sol/interface.StateReceiver.md @@ -0,0 +1,12 @@ +# StateReceiver +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/child/bor/StateReceiver.sol) + + +## Functions +### onStateReceive + + +```solidity +function onStateReceive(uint256 id, bytes calldata data) external; +``` + diff --git a/docs/autogen/src/contracts/child/bor/StateSyncerVerifier.sol/contract.StateSyncerVerifier.md b/docs/autogen/src/contracts/child/bor/StateSyncerVerifier.sol/contract.StateSyncerVerifier.md new file mode 100644 index 000000000..85dd484e4 --- /dev/null +++ b/docs/autogen/src/contracts/child/bor/StateSyncerVerifier.sol/contract.StateSyncerVerifier.md @@ -0,0 +1,56 @@ +# StateSyncerVerifier +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/child/bor/StateSyncerVerifier.sol) + +**Inherits:** +Ownable + + +## State Variables +### stateSyncer + +```solidity +address public stateSyncer; +``` + + +## Functions +### onlyStateSyncer + +*Throws if called by any account other than state syncer* + + +```solidity +modifier onlyStateSyncer(); +``` + +### constructor + + +```solidity +constructor() public; +``` + +### isOnlyStateSyncerContract + +*Returns true if the caller is the state syncer contract +TODO: replace onlyOwner ownership with 0x1000 for validator majority* + + +```solidity +function isOnlyStateSyncerContract() public view returns (bool); +``` + +### changeStateSyncerAddress + + +```solidity +function changeStateSyncerAddress(address newAddress) public onlyOwner; +``` + +## Events +### StateSyncerAddressChanged + +```solidity +event StateSyncerAddressChanged(address indexed previousAddress, address indexed newAddress); +``` + diff --git a/docs/autogen/src/contracts/child/misc/EIP712.sol/contract.LibEIP712Domain.md b/docs/autogen/src/contracts/child/misc/EIP712.sol/contract.LibEIP712Domain.md new file mode 100644 index 000000000..58f06933d --- /dev/null +++ b/docs/autogen/src/contracts/child/misc/EIP712.sol/contract.LibEIP712Domain.md @@ -0,0 +1,79 @@ +# LibEIP712Domain +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/child/misc/EIP712.sol) + +**Inherits:** +[ChainIdMixin](/contracts/common/mixin/ChainIdMixin.sol/contract.ChainIdMixin.md) + + +## State Variables +### EIP712_DOMAIN_SCHEMA + +```solidity +string internal constant EIP712_DOMAIN_SCHEMA = "EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"; +``` + + +### EIP712_DOMAIN_SCHEMA_HASH + +```solidity +bytes32 public constant EIP712_DOMAIN_SCHEMA_HASH = keccak256(abi.encodePacked(EIP712_DOMAIN_SCHEMA)); +``` + + +### EIP712_DOMAIN_NAME + +```solidity +string internal constant EIP712_DOMAIN_NAME = "Matic Network"; +``` + + +### EIP712_DOMAIN_VERSION + +```solidity +string internal constant EIP712_DOMAIN_VERSION = "1"; +``` + + +### EIP712_DOMAIN_CHAINID + +```solidity +uint256 internal constant EIP712_DOMAIN_CHAINID = CHAINID; +``` + + +### EIP712_DOMAIN_HASH + +```solidity +bytes32 public EIP712_DOMAIN_HASH; +``` + + +## Functions +### constructor + + +```solidity +constructor() public; +``` + +### hashEIP712Message + + +```solidity +function hashEIP712Message(bytes32 hashStruct) internal view returns (bytes32 result); +``` + +### hashEIP712MessageWithAddress + + +```solidity +function hashEIP712MessageWithAddress(bytes32 hashStruct, address add) internal view returns (bytes32 result); +``` + +### _hashEIP712Message + + +```solidity +function _hashEIP712Message(bytes32 hashStruct, bytes32 domainHash) internal pure returns (bytes32 result); +``` + diff --git a/docs/autogen/src/contracts/child/misc/IParentToken.sol/interface.IParentToken.md b/docs/autogen/src/contracts/child/misc/IParentToken.sol/interface.IParentToken.md new file mode 100644 index 000000000..ebead334a --- /dev/null +++ b/docs/autogen/src/contracts/child/misc/IParentToken.sol/interface.IParentToken.md @@ -0,0 +1,12 @@ +# IParentToken +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/child/misc/IParentToken.sol) + + +## Functions +### beforeTransfer + + +```solidity +function beforeTransfer(address sender, address to, uint256 value) external returns (bool); +``` + diff --git a/docs/autogen/src/contracts/child/misc/LibTokenTransferOrder.sol/contract.LibTokenTransferOrder.md b/docs/autogen/src/contracts/child/misc/LibTokenTransferOrder.sol/contract.LibTokenTransferOrder.md new file mode 100644 index 000000000..9af86b96c --- /dev/null +++ b/docs/autogen/src/contracts/child/misc/LibTokenTransferOrder.sol/contract.LibTokenTransferOrder.md @@ -0,0 +1,49 @@ +# LibTokenTransferOrder +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/child/misc/LibTokenTransferOrder.sol) + +**Inherits:** +[LibEIP712Domain](/contracts/child/misc/EIP712.sol/contract.LibEIP712Domain.md) + + +## State Variables +### EIP712_TOKEN_TRANSFER_ORDER_SCHEMA + +```solidity +string internal constant EIP712_TOKEN_TRANSFER_ORDER_SCHEMA = "TokenTransferOrder(address spender,uint256 tokenIdOrAmount,bytes32 data,uint256 expiration)"; +``` + + +### EIP712_TOKEN_TRANSFER_ORDER_SCHEMA_HASH + +```solidity +bytes32 public constant EIP712_TOKEN_TRANSFER_ORDER_SCHEMA_HASH = keccak256(abi.encodePacked(EIP712_TOKEN_TRANSFER_ORDER_SCHEMA)); +``` + + +## Functions +### getTokenTransferOrderHash + + +```solidity +function getTokenTransferOrderHash(address spender, uint256 tokenIdOrAmount, bytes32 data, uint256 expiration) public view returns (bytes32 orderHash); +``` + +### hashTokenTransferOrder + + +```solidity +function hashTokenTransferOrder(address spender, uint256 tokenIdOrAmount, bytes32 data, uint256 expiration) internal pure returns (bytes32 result); +``` + +## Structs +### TokenTransferOrder + +```solidity +struct TokenTransferOrder { + address spender; + uint256 tokenIdOrAmount; + bytes32 data; + uint256 expiration; +} +``` + diff --git a/docs/autogen/src/contracts/child/misc/Marketplace.sol/contract.Marketplace.md b/docs/autogen/src/contracts/child/misc/Marketplace.sol/contract.Marketplace.md new file mode 100644 index 000000000..e2993e8a6 --- /dev/null +++ b/docs/autogen/src/contracts/child/misc/Marketplace.sol/contract.Marketplace.md @@ -0,0 +1,30 @@ +# Marketplace +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/child/misc/Marketplace.sol) + + +## Functions +### executeOrder + + +```solidity +function executeOrder(bytes memory data1, bytes memory data2, bytes32 orderId, uint256 expiration, address taker) public; +``` + +### decode + + +```solidity +function decode(bytes memory data) internal pure returns (Order memory order); +``` + +## Structs +### Order + +```solidity +struct Order { + address token; + bytes sig; + uint256 tokenIdOrAmount; +} +``` + diff --git a/docs/autogen/src/contracts/child/misc/Marketplace.sol/interface.MarketplaceToken.md b/docs/autogen/src/contracts/child/misc/Marketplace.sol/interface.MarketplaceToken.md new file mode 100644 index 000000000..7b788b98b --- /dev/null +++ b/docs/autogen/src/contracts/child/misc/Marketplace.sol/interface.MarketplaceToken.md @@ -0,0 +1,12 @@ +# MarketplaceToken +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/child/misc/Marketplace.sol) + + +## Functions +### transferWithSig + + +```solidity +function transferWithSig(bytes calldata sig, uint256 tokenIdOrAmount, bytes32 data, uint256 expiration, address to) external returns (address); +``` + diff --git a/docs/autogen/src/contracts/child/misc/ParentTokenMock.sol/contract.ParentTokenMock.md b/docs/autogen/src/contracts/child/misc/ParentTokenMock.sol/contract.ParentTokenMock.md new file mode 100644 index 000000000..ac082eb5a --- /dev/null +++ b/docs/autogen/src/contracts/child/misc/ParentTokenMock.sol/contract.ParentTokenMock.md @@ -0,0 +1,30 @@ +# ParentTokenMock +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/child/misc/ParentTokenMock.sol) + +**Inherits:** +[IParentToken](/contracts/child/misc/IParentToken.sol/interface.IParentToken.md), Ownable + + +## State Variables +### isAllowed + +```solidity +mapping(address => bool) isAllowed; +``` + + +## Functions +### beforeTransfer + + +```solidity +function beforeTransfer(address sender, address to, uint256 value) external returns (bool); +``` + +### updatePermission + + +```solidity +function updatePermission(address user) public onlyOwner; +``` + diff --git a/docs/autogen/src/contracts/child/misc/README.md b/docs/autogen/src/contracts/child/misc/README.md new file mode 100644 index 000000000..c34221495 --- /dev/null +++ b/docs/autogen/src/contracts/child/misc/README.md @@ -0,0 +1,9 @@ + + +# Contents +- [LibEIP712Domain](EIP712.sol/contract.LibEIP712Domain.md) +- [IParentToken](IParentToken.sol/interface.IParentToken.md) +- [LibTokenTransferOrder](LibTokenTransferOrder.sol/contract.LibTokenTransferOrder.md) +- [MarketplaceToken](Marketplace.sol/interface.MarketplaceToken.md) +- [Marketplace](Marketplace.sol/contract.Marketplace.md) +- [ParentTokenMock](ParentTokenMock.sol/contract.ParentTokenMock.md) diff --git a/docs/autogen/src/contracts/child/proxifiedChildToken/ChildERC20Proxified.sol/contract.ChildERC20Proxified.md b/docs/autogen/src/contracts/child/proxifiedChildToken/ChildERC20Proxified.sol/contract.ChildERC20Proxified.md new file mode 100644 index 000000000..af5bb5eb6 --- /dev/null +++ b/docs/autogen/src/contracts/child/proxifiedChildToken/ChildERC20Proxified.sol/contract.ChildERC20Proxified.md @@ -0,0 +1,29 @@ +# ChildERC20Proxified +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/child/proxifiedChildToken/ChildERC20Proxified.sol) + +**Inherits:** +[ChildERC20](/contracts/child/ChildERC20.sol/contract.ChildERC20.md), [Initializable](/contracts/common/mixin/Initializable.sol/contract.Initializable.md) + + +## Functions +### constructor + + +```solidity +constructor() public ChildERC20(address(0x1), address(0x1), "", "", 18); +``` + +### initialize + + +```solidity +function initialize(address _token, string calldata name, string calldata symbol, uint8 decimals) external initializer; +``` + +### isOwner + + +```solidity +function isOwner() public view returns (bool); +``` + diff --git a/docs/autogen/src/contracts/child/proxifiedChildToken/ChildERC721Proxified.sol/contract.ChildERC721Proxified.md b/docs/autogen/src/contracts/child/proxifiedChildToken/ChildERC721Proxified.sol/contract.ChildERC721Proxified.md new file mode 100644 index 000000000..ddb9d3fde --- /dev/null +++ b/docs/autogen/src/contracts/child/proxifiedChildToken/ChildERC721Proxified.sol/contract.ChildERC721Proxified.md @@ -0,0 +1,44 @@ +# ChildERC721Proxified +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/child/proxifiedChildToken/ChildERC721Proxified.sol) + +**Inherits:** +[ChildERC721](/contracts/child/ChildERC721.sol/contract.ChildERC721.md), [Initializable](/contracts/common/mixin/Initializable.sol/contract.Initializable.md) + + +## State Variables +### name + +```solidity +string public name; +``` + + +### symbol + +```solidity +string public symbol; +``` + + +## Functions +### constructor + + +```solidity +constructor() public ChildERC721(address(0x1), address(0x1), "", ""); +``` + +### initialize + + +```solidity +function initialize(address _token, string calldata _name, string calldata _symbol) external initializer; +``` + +### isOwner + + +```solidity +function isOwner() public view returns (bool); +``` + diff --git a/docs/autogen/src/contracts/child/proxifiedChildToken/ChildTokenProxy.sol/contract.ChildTokenProxy.md b/docs/autogen/src/contracts/child/proxifiedChildToken/ChildTokenProxy.sol/contract.ChildTokenProxy.md new file mode 100644 index 000000000..4554a9066 --- /dev/null +++ b/docs/autogen/src/contracts/child/proxifiedChildToken/ChildTokenProxy.sol/contract.ChildTokenProxy.md @@ -0,0 +1,15 @@ +# ChildTokenProxy +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/child/proxifiedChildToken/ChildTokenProxy.sol) + +**Inherits:** +[UpgradableProxy](/contracts/common/misc/UpgradableProxy.sol/contract.UpgradableProxy.md) + + +## Functions +### constructor + + +```solidity +constructor(address _proxyTo) public UpgradableProxy(_proxyTo); +``` + diff --git a/docs/autogen/src/contracts/child/proxifiedChildToken/README.md b/docs/autogen/src/contracts/child/proxifiedChildToken/README.md new file mode 100644 index 000000000..bc029d2fb --- /dev/null +++ b/docs/autogen/src/contracts/child/proxifiedChildToken/README.md @@ -0,0 +1,6 @@ + + +# Contents +- [ChildERC20Proxified](ChildERC20Proxified.sol/contract.ChildERC20Proxified.md) +- [ChildERC721Proxified](ChildERC721Proxified.sol/contract.ChildERC721Proxified.md) +- [ChildTokenProxy](ChildTokenProxy.sol/contract.ChildTokenProxy.md) diff --git a/docs/autogen/src/contracts/common/README.md b/docs/autogen/src/contracts/common/README.md new file mode 100644 index 000000000..2718b510a --- /dev/null +++ b/docs/autogen/src/contracts/common/README.md @@ -0,0 +1,10 @@ + + +# Contents +- [gnosis](/contracts/common/gnosis) +- [governance](/contracts/common/governance) +- [lib](/contracts/common/lib) +- [misc](/contracts/common/misc) +- [mixin](/contracts/common/mixin) +- [tokens](/contracts/common/tokens) +- [Registry](Registry.sol/contract.Registry.md) diff --git a/docs/autogen/src/contracts/common/Registry.sol/contract.Registry.md b/docs/autogen/src/contracts/common/Registry.sol/contract.Registry.md new file mode 100644 index 000000000..6cd9a805a --- /dev/null +++ b/docs/autogen/src/contracts/common/Registry.sol/contract.Registry.md @@ -0,0 +1,315 @@ +# Registry +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/common/Registry.sol) + +**Inherits:** +[Governable](/contracts/common/governance/Governable.sol/contract.Governable.md) + + +## State Variables +### WETH_TOKEN + +```solidity +bytes32 private constant WETH_TOKEN = keccak256("wethToken"); +``` + + +### DEPOSIT_MANAGER + +```solidity +bytes32 private constant DEPOSIT_MANAGER = keccak256("depositManager"); +``` + + +### STAKE_MANAGER + +```solidity +bytes32 private constant STAKE_MANAGER = keccak256("stakeManager"); +``` + + +### VALIDATOR_SHARE + +```solidity +bytes32 private constant VALIDATOR_SHARE = keccak256("validatorShare"); +``` + + +### WITHDRAW_MANAGER + +```solidity +bytes32 private constant WITHDRAW_MANAGER = keccak256("withdrawManager"); +``` + + +### CHILD_CHAIN + +```solidity +bytes32 private constant CHILD_CHAIN = keccak256("childChain"); +``` + + +### STATE_SENDER + +```solidity +bytes32 private constant STATE_SENDER = keccak256("stateSender"); +``` + + +### SLASHING_MANAGER + +```solidity +bytes32 private constant SLASHING_MANAGER = keccak256("slashingManager"); +``` + + +### erc20Predicate + +```solidity +address public erc20Predicate; +``` + + +### erc721Predicate + +```solidity +address public erc721Predicate; +``` + + +### contractMap + +```solidity +mapping(bytes32 => address) public contractMap; +``` + + +### rootToChildToken + +```solidity +mapping(address => address) public rootToChildToken; +``` + + +### childToRootToken + +```solidity +mapping(address => address) public childToRootToken; +``` + + +### proofValidatorContracts + +```solidity +mapping(address => bool) public proofValidatorContracts; +``` + + +### isERC721 + +```solidity +mapping(address => bool) public isERC721; +``` + + +### predicates + +```solidity +mapping(address => Predicate) public predicates; +``` + + +## Functions +### constructor + + +```solidity +constructor(address _governance) public Governable(_governance); +``` + +### updateContractMap + + +```solidity +function updateContractMap(bytes32 _key, address _address) external onlyGovernance; +``` + +### mapToken + +*Map root token to child token* + + +```solidity +function mapToken(address _rootToken, address _childToken, bool _isERC721) external onlyGovernance; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`_rootToken`|`address`|Token address on the root chain| +|`_childToken`|`address`|Token address on the child chain| +|`_isERC721`|`bool`|Is the token being mapped ERC721| + + +### addErc20Predicate + + +```solidity +function addErc20Predicate(address predicate) public onlyGovernance; +``` + +### addErc721Predicate + + +```solidity +function addErc721Predicate(address predicate) public onlyGovernance; +``` + +### addPredicate + + +```solidity +function addPredicate(address predicate, Type _type) public onlyGovernance; +``` + +### removePredicate + + +```solidity +function removePredicate(address predicate) public onlyGovernance; +``` + +### getValidatorShareAddress + + +```solidity +function getValidatorShareAddress() public view returns (address); +``` + +### getWethTokenAddress + + +```solidity +function getWethTokenAddress() public view returns (address); +``` + +### getDepositManagerAddress + + +```solidity +function getDepositManagerAddress() public view returns (address); +``` + +### getStakeManagerAddress + + +```solidity +function getStakeManagerAddress() public view returns (address); +``` + +### getSlashingManagerAddress + + +```solidity +function getSlashingManagerAddress() public view returns (address); +``` + +### getWithdrawManagerAddress + + +```solidity +function getWithdrawManagerAddress() public view returns (address); +``` + +### getChildChainAndStateSender + + +```solidity +function getChildChainAndStateSender() public view returns (address, address); +``` + +### isTokenMapped + + +```solidity +function isTokenMapped(address _token) public view returns (bool); +``` + +### isTokenMappedAndIsErc721 + + +```solidity +function isTokenMappedAndIsErc721(address _token) public view returns (bool); +``` + +### isTokenMappedAndGetPredicate + + +```solidity +function isTokenMappedAndGetPredicate(address _token) public view returns (address); +``` + +### isChildTokenErc721 + + +```solidity +function isChildTokenErc721(address childToken) public view returns (bool); +``` + +## Events +### TokenMapped + +```solidity +event TokenMapped(address indexed rootToken, address indexed childToken); +``` + +### ProofValidatorAdded + +```solidity +event ProofValidatorAdded(address indexed validator, address indexed from); +``` + +### ProofValidatorRemoved + +```solidity +event ProofValidatorRemoved(address indexed validator, address indexed from); +``` + +### PredicateAdded + +```solidity +event PredicateAdded(address indexed predicate, address indexed from); +``` + +### PredicateRemoved + +```solidity +event PredicateRemoved(address indexed predicate, address indexed from); +``` + +### ContractMapUpdated + +```solidity +event ContractMapUpdated(bytes32 indexed key, address indexed previousContract, address indexed newContract); +``` + +## Structs +### Predicate + +```solidity +struct Predicate { + Type _type; +} +``` + +## Enums +### Type + +```solidity +enum Type { + Invalid, + ERC20, + ERC721, + Custom +} +``` + diff --git a/docs/autogen/src/contracts/common/gnosis/GnosisSafe.sol/contract.Enum.md b/docs/autogen/src/contracts/common/gnosis/GnosisSafe.sol/contract.Enum.md new file mode 100644 index 000000000..6b6a15272 --- /dev/null +++ b/docs/autogen/src/contracts/common/gnosis/GnosisSafe.sol/contract.Enum.md @@ -0,0 +1,17 @@ +# Enum +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/common/gnosis/GnosisSafe.sol) + +**Author:** +Richard Meissner - + + +## Enums +### Operation + +```solidity +enum Operation { + Call, + DelegateCall +} +``` + diff --git a/docs/autogen/src/contracts/common/gnosis/GnosisSafe.sol/contract.Executor.md b/docs/autogen/src/contracts/common/gnosis/GnosisSafe.sol/contract.Executor.md new file mode 100644 index 000000000..67df4fb9f --- /dev/null +++ b/docs/autogen/src/contracts/common/gnosis/GnosisSafe.sol/contract.Executor.md @@ -0,0 +1,29 @@ +# Executor +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/common/gnosis/GnosisSafe.sol) + +**Author:** +Richard Meissner - + + +## Functions +### execute + + +```solidity +function execute(address to, uint256 value, bytes memory data, Enum.Operation operation, uint256 txGas) internal returns (bool success); +``` + +### executeCall + + +```solidity +function executeCall(address to, uint256 value, bytes memory data, uint256 txGas) internal returns (bool success); +``` + +### executeDelegateCall + + +```solidity +function executeDelegateCall(address to, bytes memory data, uint256 txGas) internal returns (bool success); +``` + diff --git a/docs/autogen/src/contracts/common/gnosis/GnosisSafe.sol/contract.FallbackManager.md b/docs/autogen/src/contracts/common/gnosis/GnosisSafe.sol/contract.FallbackManager.md new file mode 100644 index 000000000..2739306f8 --- /dev/null +++ b/docs/autogen/src/contracts/common/gnosis/GnosisSafe.sol/contract.FallbackManager.md @@ -0,0 +1,50 @@ +# FallbackManager +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/common/gnosis/GnosisSafe.sol) + +**Inherits:** +[SelfAuthorized](/contracts/common/gnosis/GnosisSafe.sol/contract.SelfAuthorized.md) + +**Author:** +Richard Meissner - + + +## State Variables +### FALLBACK_HANDLER_STORAGE_SLOT + +```solidity +bytes32 internal constant FALLBACK_HANDLER_STORAGE_SLOT = 0x6c9a6c4a39284e37ed1cf53d337577d14212a4870fb976a4366c693b939918d5; +``` + + +## Functions +### internalSetFallbackHandler + + +```solidity +function internalSetFallbackHandler(address handler) internal; +``` + +### setFallbackHandler + +*Allows to add a contract to handle fallback calls. +Only fallback calls without value and with data will be forwarded. +This can only be done via a Safe transaction.* + + +```solidity +function setFallbackHandler(address handler) public authorized; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`handler`|`address`|contract to handle fallbacks calls.| + + +### function + + +```solidity +function() external payable; +``` + diff --git a/docs/autogen/src/contracts/common/gnosis/GnosisSafe.sol/contract.GnosisSafe.md b/docs/autogen/src/contracts/common/gnosis/GnosisSafe.sol/contract.GnosisSafe.md new file mode 100644 index 000000000..852089ae3 --- /dev/null +++ b/docs/autogen/src/contracts/common/gnosis/GnosisSafe.sol/contract.GnosisSafe.md @@ -0,0 +1,389 @@ +# GnosisSafe +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/common/gnosis/GnosisSafe.sol) + +**Inherits:** +[MasterCopy](/contracts/common/gnosis/GnosisSafe.sol/contract.MasterCopy.md), [ModuleManager](/contracts/common/gnosis/GnosisSafe.sol/contract.ModuleManager.md), [OwnerManager](/contracts/common/gnosis/GnosisSafe.sol/contract.OwnerManager.md), [SignatureDecoder](/contracts/common/gnosis/GnosisSafe.sol/contract.SignatureDecoder.md), [SecuredTokenTransfer](/contracts/common/gnosis/GnosisSafe.sol/contract.SecuredTokenTransfer.md), [ISignatureValidatorConstants](/contracts/common/gnosis/GnosisSafe.sol/contract.ISignatureValidatorConstants.md), [FallbackManager](/contracts/common/gnosis/GnosisSafe.sol/contract.FallbackManager.md) + +**Authors:** +Stefan George - , Richard Meissner - , Ricardo Guilherme Schmidt - (Status Research & Development GmbH) - Gas Token Payment + + +## State Variables +### NAME + +```solidity +string public constant NAME = "Gnosis Safe"; +``` + + +### VERSION + +```solidity +string public constant VERSION = "1.1.1"; +``` + + +### DOMAIN_SEPARATOR_TYPEHASH + +```solidity +bytes32 private constant DOMAIN_SEPARATOR_TYPEHASH = 0x035aff83d86937d35b32e04f0ddc6ff469290eef2f1b692d8a815c89404d4749; +``` + + +### SAFE_TX_TYPEHASH + +```solidity +bytes32 private constant SAFE_TX_TYPEHASH = 0xbb8310d486368db6bd6f849402fdd73ad53d316b5a4b2644ad6efe0f941286d8; +``` + + +### SAFE_MSG_TYPEHASH + +```solidity +bytes32 private constant SAFE_MSG_TYPEHASH = 0x60b3cbf8b4a223d68d641b3b6ddf9a298e7f33710cf3d3a9d1146b5a6150fbca; +``` + + +### nonce + +```solidity +uint256 public nonce; +``` + + +### domainSeparator + +```solidity +bytes32 public domainSeparator; +``` + + +### signedMessages + +```solidity +mapping(bytes32 => uint256) public signedMessages; +``` + + +### approvedHashes + +```solidity +mapping(address => mapping(bytes32 => uint256)) public approvedHashes; +``` + + +## Functions +### constructor + + +```solidity +constructor() public; +``` + +### setup + +*Setup function sets initial storage of contract.* + + +```solidity +function setup( + address[] calldata _owners, + uint256 _threshold, + address to, + bytes calldata data, + address fallbackHandler, + address paymentToken, + uint256 payment, + address payable paymentReceiver +) external; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`_owners`|`address[]`|List of Safe owners.| +|`_threshold`|`uint256`|Number of required confirmations for a Safe transaction.| +|`to`|`address`|Contract address for optional delegate call.| +|`data`|`bytes`|Data payload for optional delegate call.| +|`fallbackHandler`|`address`|Handler for fallback calls to this contract| +|`paymentToken`|`address`|Token that should be used for the payment (0 is ETH)| +|`payment`|`uint256`|Value that should be paid| +|`paymentReceiver`|`address payable`|Adddress that should receive the payment (or 0 if tx.origin)| + + +### execTransaction + +*Allows to execute a Safe transaction confirmed by required number of owners and then pays the account that submitted the transaction. +Note: The fees are always transfered, even if the user transaction fails.* + + +```solidity +function execTransaction( + address to, + uint256 value, + bytes calldata data, + Enum.Operation operation, + uint256 safeTxGas, + uint256 baseGas, + uint256 gasPrice, + address gasToken, + address payable refundReceiver, + bytes calldata signatures +) external returns (bool success); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`to`|`address`|Destination address of Safe transaction.| +|`value`|`uint256`|Ether value of Safe transaction.| +|`data`|`bytes`|Data payload of Safe transaction.| +|`operation`|`Enum.Operation`|Operation type of Safe transaction.| +|`safeTxGas`|`uint256`|Gas that should be used for the Safe transaction.| +|`baseGas`|`uint256`|Gas costs for that are indipendent of the transaction execution(e.g. base transaction fee, signature check, payment of the refund)| +|`gasPrice`|`uint256`|Gas price that should be used for the payment calculation.| +|`gasToken`|`address`|Token address (or 0 if ETH) that is used for the payment.| +|`refundReceiver`|`address payable`|Address of receiver of gas payment (or 0 if tx.origin).| +|`signatures`|`bytes`|Packed signature data ({bytes32 r}{bytes32 s}{uint8 v})| + + +### handlePayment + + +```solidity +function handlePayment(uint256 gasUsed, uint256 baseGas, uint256 gasPrice, address gasToken, address payable refundReceiver) + private + returns (uint256 payment); +``` + +### checkSignatures + +*Checks whether the signature provided is valid for the provided data, hash. Will revert otherwise.* + + +```solidity +function checkSignatures(bytes32 dataHash, bytes memory data, bytes memory signatures, bool consumeHash) internal; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`dataHash`|`bytes32`|Hash of the data (could be either a message hash or transaction hash)| +|`data`|`bytes`|That should be signed (this is passed to an external validator contract)| +|`signatures`|`bytes`|Signature data that should be verified. Can be ECDSA signature, contract signature (EIP-1271) or approved hash.| +|`consumeHash`|`bool`|Indicates that in case of an approved hash the storage can be freed to save gas| + + +### requiredTxGas + +*Allows to estimate a Safe transaction. +This method is only meant for estimation purpose, therefore two different protection mechanism against execution in a transaction have been made: +1.) The method can only be called from the safe itself +2.) The response is returned with a revert +When estimating set `from` to the address of the safe. +Since the `estimateGas` function includes refunds, call this method to get an estimated of the costs that are deducted from the safe with `execTransaction`* + + +```solidity +function requiredTxGas(address to, uint256 value, bytes calldata data, Enum.Operation operation) external authorized returns (uint256); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`to`|`address`|Destination address of Safe transaction.| +|`value`|`uint256`|Ether value of Safe transaction.| +|`data`|`bytes`|Data payload of Safe transaction.| +|`operation`|`Enum.Operation`|Operation type of Safe transaction.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|Estimate without refunds and overhead fees (base transaction and payload data gas costs).| + + +### approveHash + +*Marks a hash as approved. This can be used to validate a hash that is used by a signature.* + + +```solidity +function approveHash(bytes32 hashToApprove) external; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`hashToApprove`|`bytes32`|The hash that should be marked as approved for signatures that are verified by this contract.| + + +### signMessage + +*Marks a message as signed* + + +```solidity +function signMessage(bytes calldata _data) external authorized; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`_data`|`bytes`|Arbitrary length data that should be marked as signed on the behalf of address(this)| + + +### isValidSignature + +Implementation of ISignatureValidator (see `interfaces/ISignatureValidator.sol`) + +*Should return whether the signature provided is valid for the provided data. +The save does not implement the interface since `checkSignatures` is not a view method. +The method will not perform any state changes (see parameters of `checkSignatures`)* + + +```solidity +function isValidSignature(bytes calldata _data, bytes calldata _signature) external returns (bytes4); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`_data`|`bytes`|Arbitrary length data signed on the behalf of address(this)| +|`_signature`|`bytes`|Signature byte array associated with _data| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bytes4`|a bool upon valid or invalid signature with corresponding _data| + + +### getMessageHash + +*Returns hash of a message that can be signed by owners.* + + +```solidity +function getMessageHash(bytes memory message) public view returns (bytes32); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`message`|`bytes`|Message that should be hashed| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bytes32`|Message hash.| + + +### encodeTransactionData + +*Returns the bytes that are hashed to be signed by owners.* + + +```solidity +function encodeTransactionData( + address to, + uint256 value, + bytes memory data, + Enum.Operation operation, + uint256 safeTxGas, + uint256 baseGas, + uint256 gasPrice, + address gasToken, + address refundReceiver, + uint256 _nonce +) public view returns (bytes memory); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`to`|`address`|Destination address.| +|`value`|`uint256`|Ether value.| +|`data`|`bytes`|Data payload.| +|`operation`|`Enum.Operation`|Operation type.| +|`safeTxGas`|`uint256`|Fas that should be used for the safe transaction.| +|`baseGas`|`uint256`|Gas costs for data used to trigger the safe transaction.| +|`gasPrice`|`uint256`|Maximum gas price that should be used for this transaction.| +|`gasToken`|`address`|Token address (or 0 if ETH) that is used for the payment.| +|`refundReceiver`|`address`|Address of receiver of gas payment (or 0 if tx.origin).| +|`_nonce`|`uint256`|Transaction nonce.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bytes`|Transaction hash bytes.| + + +### getTransactionHash + +*Returns hash to be signed by owners.* + + +```solidity +function getTransactionHash( + address to, + uint256 value, + bytes memory data, + Enum.Operation operation, + uint256 safeTxGas, + uint256 baseGas, + uint256 gasPrice, + address gasToken, + address refundReceiver, + uint256 _nonce +) public view returns (bytes32); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`to`|`address`|Destination address.| +|`value`|`uint256`|Ether value.| +|`data`|`bytes`|Data payload.| +|`operation`|`Enum.Operation`|Operation type.| +|`safeTxGas`|`uint256`|Fas that should be used for the safe transaction.| +|`baseGas`|`uint256`|Gas costs for data used to trigger the safe transaction.| +|`gasPrice`|`uint256`|Maximum gas price that should be used for this transaction.| +|`gasToken`|`address`|Token address (or 0 if ETH) that is used for the payment.| +|`refundReceiver`|`address`|Address of receiver of gas payment (or 0 if tx.origin).| +|`_nonce`|`uint256`|Transaction nonce.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bytes32`|Transaction hash.| + + +## Events +### ApproveHash + +```solidity +event ApproveHash(bytes32 indexed approvedHash, address indexed owner); +``` + +### SignMsg + +```solidity +event SignMsg(bytes32 indexed msgHash); +``` + +### ExecutionFailure + +```solidity +event ExecutionFailure(bytes32 txHash, uint256 payment); +``` + +### ExecutionSuccess + +```solidity +event ExecutionSuccess(bytes32 txHash, uint256 payment); +``` + diff --git a/docs/autogen/src/contracts/common/gnosis/GnosisSafe.sol/contract.ISignatureValidator.md b/docs/autogen/src/contracts/common/gnosis/GnosisSafe.sol/contract.ISignatureValidator.md new file mode 100644 index 000000000..a141e5195 --- /dev/null +++ b/docs/autogen/src/contracts/common/gnosis/GnosisSafe.sol/contract.ISignatureValidator.md @@ -0,0 +1,24 @@ +# ISignatureValidator +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/common/gnosis/GnosisSafe.sol) + +**Inherits:** +[ISignatureValidatorConstants](/contracts/common/gnosis/GnosisSafe.sol/contract.ISignatureValidatorConstants.md) + + +## Functions +### isValidSignature + +*Should return whether the signature provided is valid for the provided data* + + +```solidity +function isValidSignature(bytes memory _data, bytes memory _signature) public view returns (bytes4); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`_data`|`bytes`|Arbitrary length data signed on the behalf of address(this)| +|`_signature`|`bytes`|Signature byte array associated with _data MUST return the bytes4 magic value 0x20c13b0b when function passes. MUST NOT modify state (using STATICCALL for solc < 0.5, view modifier for solc > 0.5) MUST allow external calls| + + diff --git a/docs/autogen/src/contracts/common/gnosis/GnosisSafe.sol/contract.ISignatureValidatorConstants.md b/docs/autogen/src/contracts/common/gnosis/GnosisSafe.sol/contract.ISignatureValidatorConstants.md new file mode 100644 index 000000000..5e2a6d68b --- /dev/null +++ b/docs/autogen/src/contracts/common/gnosis/GnosisSafe.sol/contract.ISignatureValidatorConstants.md @@ -0,0 +1,12 @@ +# ISignatureValidatorConstants +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/common/gnosis/GnosisSafe.sol) + + +## State Variables +### EIP1271_MAGIC_VALUE + +```solidity +bytes4 internal constant EIP1271_MAGIC_VALUE = 0x20c13b0b; +``` + + diff --git a/docs/autogen/src/contracts/common/gnosis/GnosisSafe.sol/contract.MasterCopy.md b/docs/autogen/src/contracts/common/gnosis/GnosisSafe.sol/contract.MasterCopy.md new file mode 100644 index 000000000..57e2230e6 --- /dev/null +++ b/docs/autogen/src/contracts/common/gnosis/GnosisSafe.sol/contract.MasterCopy.md @@ -0,0 +1,41 @@ +# MasterCopy +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/common/gnosis/GnosisSafe.sol) + +**Inherits:** +[SelfAuthorized](/contracts/common/gnosis/GnosisSafe.sol/contract.SelfAuthorized.md) + +**Author:** +Richard Meissner - + + +## State Variables +### masterCopy + +```solidity +address private masterCopy; +``` + + +## Functions +### changeMasterCopy + +*Allows to upgrade the contract. This can only be done via a Safe transaction.* + + +```solidity +function changeMasterCopy(address _masterCopy) public authorized; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`_masterCopy`|`address`|New contract address.| + + +## Events +### ChangedMasterCopy + +```solidity +event ChangedMasterCopy(address masterCopy); +``` + diff --git a/docs/autogen/src/contracts/common/gnosis/GnosisSafe.sol/contract.Module.md b/docs/autogen/src/contracts/common/gnosis/GnosisSafe.sol/contract.Module.md new file mode 100644 index 000000000..4d65d7ca1 --- /dev/null +++ b/docs/autogen/src/contracts/common/gnosis/GnosisSafe.sol/contract.Module.md @@ -0,0 +1,33 @@ +# Module +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/common/gnosis/GnosisSafe.sol) + +**Inherits:** +[MasterCopy](/contracts/common/gnosis/GnosisSafe.sol/contract.MasterCopy.md) + +**Authors:** +Stefan George - , Richard Meissner - + + +## State Variables +### manager + +```solidity +ModuleManager public manager; +``` + + +## Functions +### authorized + + +```solidity +modifier authorized(); +``` + +### setManager + + +```solidity +function setManager() internal; +``` + diff --git a/docs/autogen/src/contracts/common/gnosis/GnosisSafe.sol/contract.ModuleManager.md b/docs/autogen/src/contracts/common/gnosis/GnosisSafe.sol/contract.ModuleManager.md new file mode 100644 index 000000000..0e9c75792 --- /dev/null +++ b/docs/autogen/src/contracts/common/gnosis/GnosisSafe.sol/contract.ModuleManager.md @@ -0,0 +1,167 @@ +# ModuleManager +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/common/gnosis/GnosisSafe.sol) + +**Inherits:** +[SelfAuthorized](/contracts/common/gnosis/GnosisSafe.sol/contract.SelfAuthorized.md), [Executor](/contracts/common/gnosis/GnosisSafe.sol/contract.Executor.md) + +**Authors:** +Stefan George - , Richard Meissner - + + +## State Variables +### SENTINEL_MODULES + +```solidity +address internal constant SENTINEL_MODULES = address(0x1); +``` + + +### modules + +```solidity +mapping(address => address) internal modules; +``` + + +## Functions +### setupModules + + +```solidity +function setupModules(address to, bytes memory data) internal; +``` + +### enableModule + +*Allows to add a module to the whitelist. +This can only be done via a Safe transaction.* + + +```solidity +function enableModule(Module module) public authorized; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`module`|`Module`|Module to be whitelisted.| + + +### disableModule + +*Allows to remove a module from the whitelist. +This can only be done via a Safe transaction.* + + +```solidity +function disableModule(Module prevModule, Module module) public authorized; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`prevModule`|`Module`|Module that pointed to the module to be removed in the linked list| +|`module`|`Module`|Module to be removed.| + + +### execTransactionFromModule + +*Allows a Module to execute a Safe transaction without any further confirmations.* + + +```solidity +function execTransactionFromModule(address to, uint256 value, bytes memory data, Enum.Operation operation) public returns (bool success); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`to`|`address`|Destination address of module transaction.| +|`value`|`uint256`|Ether value of module transaction.| +|`data`|`bytes`|Data payload of module transaction.| +|`operation`|`Enum.Operation`|Operation type of module transaction.| + + +### execTransactionFromModuleReturnData + +*Allows a Module to execute a Safe transaction without any further confirmations and return data* + + +```solidity +function execTransactionFromModuleReturnData(address to, uint256 value, bytes memory data, Enum.Operation operation) + public + returns (bool success, bytes memory returnData); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`to`|`address`|Destination address of module transaction.| +|`value`|`uint256`|Ether value of module transaction.| +|`data`|`bytes`|Data payload of module transaction.| +|`operation`|`Enum.Operation`|Operation type of module transaction.| + + +### getModules + +*Returns array of first 10 modules.* + + +```solidity +function getModules() public view returns (address[] memory); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`address[]`|Array of modules.| + + +### getModulesPaginated + +*Returns array of modules.* + + +```solidity +function getModulesPaginated(address start, uint256 pageSize) public view returns (address[] memory array, address next); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`start`|`address`|Start of the page.| +|`pageSize`|`uint256`|Maximum number of modules that should be returned.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`array`|`address[]`|Array of modules.| +|`next`|`address`|| + + +## Events +### EnabledModule + +```solidity +event EnabledModule(Module module); +``` + +### DisabledModule + +```solidity +event DisabledModule(Module module); +``` + +### ExecutionFromModuleSuccess + +```solidity +event ExecutionFromModuleSuccess(address indexed module); +``` + +### ExecutionFromModuleFailure + +```solidity +event ExecutionFromModuleFailure(address indexed module); +``` + diff --git a/docs/autogen/src/contracts/common/gnosis/GnosisSafe.sol/contract.OwnerManager.md b/docs/autogen/src/contracts/common/gnosis/GnosisSafe.sol/contract.OwnerManager.md new file mode 100644 index 000000000..e400ff3f4 --- /dev/null +++ b/docs/autogen/src/contracts/common/gnosis/GnosisSafe.sol/contract.OwnerManager.md @@ -0,0 +1,173 @@ +# OwnerManager +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/common/gnosis/GnosisSafe.sol) + +**Inherits:** +[SelfAuthorized](/contracts/common/gnosis/GnosisSafe.sol/contract.SelfAuthorized.md) + +**Authors:** +Stefan George - , Richard Meissner - + + +## State Variables +### SENTINEL_OWNERS + +```solidity +address internal constant SENTINEL_OWNERS = address(0x1); +``` + + +### owners + +```solidity +mapping(address => address) internal owners; +``` + + +### ownerCount + +```solidity +uint256 ownerCount; +``` + + +### threshold + +```solidity +uint256 internal threshold; +``` + + +## Functions +### setupOwners + +*Setup function sets initial storage of contract.* + + +```solidity +function setupOwners(address[] memory _owners, uint256 _threshold) internal; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`_owners`|`address[]`|List of Safe owners.| +|`_threshold`|`uint256`|Number of required confirmations for a Safe transaction.| + + +### addOwnerWithThreshold + +*Allows to add a new owner to the Safe and update the threshold at the same time. +This can only be done via a Safe transaction.* + + +```solidity +function addOwnerWithThreshold(address owner, uint256 _threshold) public authorized; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`owner`|`address`|New owner address.| +|`_threshold`|`uint256`|New threshold.| + + +### removeOwner + +*Allows to remove an owner from the Safe and update the threshold at the same time. +This can only be done via a Safe transaction.* + + +```solidity +function removeOwner(address prevOwner, address owner, uint256 _threshold) public authorized; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`prevOwner`|`address`|Owner that pointed to the owner to be removed in the linked list| +|`owner`|`address`|Owner address to be removed.| +|`_threshold`|`uint256`|New threshold.| + + +### swapOwner + +*Allows to swap/replace an owner from the Safe with another address. +This can only be done via a Safe transaction.* + + +```solidity +function swapOwner(address prevOwner, address oldOwner, address newOwner) public authorized; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`prevOwner`|`address`|Owner that pointed to the owner to be replaced in the linked list| +|`oldOwner`|`address`|Owner address to be replaced.| +|`newOwner`|`address`|New owner address.| + + +### changeThreshold + +*Allows to update the number of required confirmations by Safe owners. +This can only be done via a Safe transaction.* + + +```solidity +function changeThreshold(uint256 _threshold) public authorized; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`_threshold`|`uint256`|New threshold.| + + +### getThreshold + + +```solidity +function getThreshold() public view returns (uint256); +``` + +### isOwner + + +```solidity +function isOwner(address owner) public view returns (bool); +``` + +### getOwners + +*Returns array of owners.* + + +```solidity +function getOwners() public view returns (address[] memory); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`address[]`|Array of Safe owners.| + + +## Events +### AddedOwner + +```solidity +event AddedOwner(address owner); +``` + +### RemovedOwner + +```solidity +event RemovedOwner(address owner); +``` + +### ChangedThreshold + +```solidity +event ChangedThreshold(uint256 threshold); +``` + diff --git a/docs/autogen/src/contracts/common/gnosis/GnosisSafe.sol/contract.SecuredTokenTransfer.md b/docs/autogen/src/contracts/common/gnosis/GnosisSafe.sol/contract.SecuredTokenTransfer.md new file mode 100644 index 000000000..35acc70b3 --- /dev/null +++ b/docs/autogen/src/contracts/common/gnosis/GnosisSafe.sol/contract.SecuredTokenTransfer.md @@ -0,0 +1,25 @@ +# SecuredTokenTransfer +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/common/gnosis/GnosisSafe.sol) + +**Author:** +Richard Meissner - + + +## Functions +### transferToken + +*Transfers a token and returns if it was a success* + + +```solidity +function transferToken(address token, address receiver, uint256 amount) internal returns (bool transferred); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`token`|`address`|Token that should be transferred| +|`receiver`|`address`|Receiver to whom the token should be transferred| +|`amount`|`uint256`|The amount of tokens that should be transferred| + + diff --git a/docs/autogen/src/contracts/common/gnosis/GnosisSafe.sol/contract.SelfAuthorized.md b/docs/autogen/src/contracts/common/gnosis/GnosisSafe.sol/contract.SelfAuthorized.md new file mode 100644 index 000000000..211082c6a --- /dev/null +++ b/docs/autogen/src/contracts/common/gnosis/GnosisSafe.sol/contract.SelfAuthorized.md @@ -0,0 +1,17 @@ +# SelfAuthorized +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/common/gnosis/GnosisSafe.sol) + +**Author:** +Richard Meissner - + +Submitted for verification at Etherscan.io on 2019-12-26 + + +## Functions +### authorized + + +```solidity +modifier authorized(); +``` + diff --git a/docs/autogen/src/contracts/common/gnosis/GnosisSafe.sol/contract.SignatureDecoder.md b/docs/autogen/src/contracts/common/gnosis/GnosisSafe.sol/contract.SignatureDecoder.md new file mode 100644 index 000000000..9e5d38585 --- /dev/null +++ b/docs/autogen/src/contracts/common/gnosis/GnosisSafe.sol/contract.SignatureDecoder.md @@ -0,0 +1,43 @@ +# SignatureDecoder +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/common/gnosis/GnosisSafe.sol) + +**Authors:** +Ricardo Guilherme Schmidt (Status Research & Development GmbH), Richard Meissner - + + +## Functions +### recoverKey + +*Recovers address who signed the message* + + +```solidity +function recoverKey(bytes32 messageHash, bytes memory messageSignature, uint256 pos) internal pure returns (address); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`messageHash`|`bytes32`|operation ethereum signed message hash| +|`messageSignature`|`bytes`|message `txHash` signature| +|`pos`|`uint256`|which signature to read| + + +### signatureSplit + +Make sure to peform a bounds check for @param pos, to avoid out of bounds access on @param signatures + +*divides bytes signature into `uint8 v, bytes32 r, bytes32 s`.* + + +```solidity +function signatureSplit(bytes memory signatures, uint256 pos) internal pure returns (uint8 v, bytes32 r, bytes32 s); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`signatures`|`bytes`|concatenated rsv signatures| +|`pos`|`uint256`|which signature to read. A prior bounds check of this parameter should be performed, to avoid out of bounds access| + + diff --git a/docs/autogen/src/contracts/common/gnosis/GnosisSafe.sol/library.SafeMath.md b/docs/autogen/src/contracts/common/gnosis/GnosisSafe.sol/library.SafeMath.md new file mode 100644 index 000000000..7020b0cec --- /dev/null +++ b/docs/autogen/src/contracts/common/gnosis/GnosisSafe.sol/library.SafeMath.md @@ -0,0 +1,54 @@ +# SafeMath +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/common/gnosis/GnosisSafe.sol) + +*Math operations with safety checks that revert on error +TODO: remove once open zeppelin update to solc 0.5.0* + + +## Functions +### mul + +*Multiplies two numbers, reverts on overflow.* + + +```solidity +function mul(uint256 a, uint256 b) internal pure returns (uint256); +``` + +### div + +*Integer division of two numbers truncating the quotient, reverts on division by zero.* + + +```solidity +function div(uint256 a, uint256 b) internal pure returns (uint256); +``` + +### sub + +*Subtracts two numbers, reverts on overflow (i.e. if subtrahend is greater than minuend).* + + +```solidity +function sub(uint256 a, uint256 b) internal pure returns (uint256); +``` + +### add + +*Adds two numbers, reverts on overflow.* + + +```solidity +function add(uint256 a, uint256 b) internal pure returns (uint256); +``` + +### mod + +*Divides two numbers and returns the remainder (unsigned integer modulo), +reverts when dividing by zero.* + + +```solidity +function mod(uint256 a, uint256 b) internal pure returns (uint256); +``` + diff --git a/docs/autogen/src/contracts/common/gnosis/GnosisSafeProxy.sol/contract.GnosisSafeProxy.md b/docs/autogen/src/contracts/common/gnosis/GnosisSafeProxy.sol/contract.GnosisSafeProxy.md new file mode 100644 index 000000000..4e00c9429 --- /dev/null +++ b/docs/autogen/src/contracts/common/gnosis/GnosisSafeProxy.sol/contract.GnosisSafeProxy.md @@ -0,0 +1,42 @@ +# GnosisSafeProxy +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/common/gnosis/GnosisSafeProxy.sol) + +**Authors:** +Stefan George - , Richard Meissner - + +Submitted for verification at Etherscan.io on 2020-01-13 + + +## State Variables +### masterCopy + +```solidity +address internal masterCopy; +``` + + +## Functions +### constructor + +*Constructor function sets address of master copy contract.* + + +```solidity +constructor(address _masterCopy) public; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`_masterCopy`|`address`|Master copy address.| + + +### function + +*Fallback function forwards all transactions and returns all received return data.* + + +```solidity +function() external payable; +``` + diff --git a/docs/autogen/src/contracts/common/gnosis/README.md b/docs/autogen/src/contracts/common/gnosis/README.md new file mode 100644 index 000000000..85c40d6eb --- /dev/null +++ b/docs/autogen/src/contracts/common/gnosis/README.md @@ -0,0 +1,18 @@ + + +# Contents +- [SelfAuthorized](GnosisSafe.sol/contract.SelfAuthorized.md) +- [MasterCopy](GnosisSafe.sol/contract.MasterCopy.md) +- [Module](GnosisSafe.sol/contract.Module.md) +- [Enum](GnosisSafe.sol/contract.Enum.md) +- [Executor](GnosisSafe.sol/contract.Executor.md) +- [SecuredTokenTransfer](GnosisSafe.sol/contract.SecuredTokenTransfer.md) +- [ModuleManager](GnosisSafe.sol/contract.ModuleManager.md) +- [OwnerManager](GnosisSafe.sol/contract.OwnerManager.md) +- [FallbackManager](GnosisSafe.sol/contract.FallbackManager.md) +- [SignatureDecoder](GnosisSafe.sol/contract.SignatureDecoder.md) +- [ISignatureValidatorConstants](GnosisSafe.sol/contract.ISignatureValidatorConstants.md) +- [ISignatureValidator](GnosisSafe.sol/contract.ISignatureValidator.md) +- [SafeMath](GnosisSafe.sol/library.SafeMath.md) +- [GnosisSafe](GnosisSafe.sol/contract.GnosisSafe.md) +- [GnosisSafeProxy](GnosisSafeProxy.sol/contract.GnosisSafeProxy.md) diff --git a/docs/autogen/src/contracts/common/governance/Governable.sol/contract.Governable.md b/docs/autogen/src/contracts/common/governance/Governable.sol/contract.Governable.md new file mode 100644 index 000000000..3285bb046 --- /dev/null +++ b/docs/autogen/src/contracts/common/governance/Governable.sol/contract.Governable.md @@ -0,0 +1,34 @@ +# Governable +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/common/governance/Governable.sol) + + +## State Variables +### governance + +```solidity +IGovernance public governance; +``` + + +## Functions +### constructor + + +```solidity +constructor(address _governance) public; +``` + +### onlyGovernance + + +```solidity +modifier onlyGovernance(); +``` + +### _assertGovernance + + +```solidity +function _assertGovernance() private view; +``` + diff --git a/docs/autogen/src/contracts/common/governance/Governance.sol/contract.Governance.md b/docs/autogen/src/contracts/common/governance/Governance.sol/contract.Governance.md new file mode 100644 index 000000000..a27f013fe --- /dev/null +++ b/docs/autogen/src/contracts/common/governance/Governance.sol/contract.Governance.md @@ -0,0 +1,15 @@ +# Governance +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/common/governance/Governance.sol) + +**Inherits:** +[ProxyStorage](/contracts/common/misc/ProxyStorage.sol/contract.ProxyStorage.md), [IGovernance](/contracts/common/governance/IGovernance.sol/interface.IGovernance.md) + + +## Functions +### update + + +```solidity +function update(address target, bytes memory data) public onlyOwner; +``` + diff --git a/docs/autogen/src/contracts/common/governance/GovernanceProxy.sol/contract.GovernanceProxy.md b/docs/autogen/src/contracts/common/governance/GovernanceProxy.sol/contract.GovernanceProxy.md new file mode 100644 index 000000000..8fcbc2504 --- /dev/null +++ b/docs/autogen/src/contracts/common/governance/GovernanceProxy.sol/contract.GovernanceProxy.md @@ -0,0 +1,15 @@ +# GovernanceProxy +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/common/governance/GovernanceProxy.sol) + +**Inherits:** +[Proxy](/contracts/common/misc/Proxy.sol/contract.Proxy.md) + + +## Functions +### constructor + + +```solidity +constructor(address _proxyTo) public Proxy(_proxyTo); +``` + diff --git a/docs/autogen/src/contracts/common/governance/IGovernance.sol/interface.IGovernance.md b/docs/autogen/src/contracts/common/governance/IGovernance.sol/interface.IGovernance.md new file mode 100644 index 000000000..a5f0d3959 --- /dev/null +++ b/docs/autogen/src/contracts/common/governance/IGovernance.sol/interface.IGovernance.md @@ -0,0 +1,12 @@ +# IGovernance +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/common/governance/IGovernance.sol) + + +## Functions +### update + + +```solidity +function update(address target, bytes calldata data) external; +``` + diff --git a/docs/autogen/src/contracts/common/governance/README.md b/docs/autogen/src/contracts/common/governance/README.md new file mode 100644 index 000000000..4ef85a41e --- /dev/null +++ b/docs/autogen/src/contracts/common/governance/README.md @@ -0,0 +1,7 @@ + + +# Contents +- [Governable](Governable.sol/contract.Governable.md) +- [Governance](Governance.sol/contract.Governance.md) +- [GovernanceProxy](GovernanceProxy.sol/contract.GovernanceProxy.md) +- [IGovernance](IGovernance.sol/interface.IGovernance.md) diff --git a/docs/autogen/src/contracts/common/lib/BytesLib.sol/library.BytesLib.md b/docs/autogen/src/contracts/common/lib/BytesLib.sol/library.BytesLib.md new file mode 100644 index 000000000..8558a8798 --- /dev/null +++ b/docs/autogen/src/contracts/common/lib/BytesLib.sol/library.BytesLib.md @@ -0,0 +1,68 @@ +# BytesLib +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/common/lib/BytesLib.sol) + + +## Functions +### concat + + +```solidity +function concat(bytes memory _preBytes, bytes memory _postBytes) internal pure returns (bytes memory); +``` + +### slice + + +```solidity +function slice(bytes memory _bytes, uint256 _start, uint256 _length) internal pure returns (bytes memory); +``` + +### leftPad + + +```solidity +function leftPad(bytes memory _bytes) internal pure returns (bytes memory); +``` + +### toBytes32 + + +```solidity +function toBytes32(bytes memory b) internal pure returns (bytes32); +``` + +### toBytes4 + + +```solidity +function toBytes4(bytes memory b) internal pure returns (bytes4 result); +``` + +### fromBytes32 + + +```solidity +function fromBytes32(bytes32 x) internal pure returns (bytes memory); +``` + +### fromUint + + +```solidity +function fromUint(uint256 _num) internal pure returns (bytes memory _ret); +``` + +### toUint + + +```solidity +function toUint(bytes memory _bytes, uint256 _start) internal pure returns (uint256); +``` + +### toAddress + + +```solidity +function toAddress(bytes memory _bytes, uint256 _start) internal pure returns (address); +``` + diff --git a/docs/autogen/src/contracts/common/lib/Common.sol/library.Common.md b/docs/autogen/src/contracts/common/lib/Common.sol/library.Common.md new file mode 100644 index 000000000..1a9ccfa6f --- /dev/null +++ b/docs/autogen/src/contracts/common/lib/Common.sol/library.Common.md @@ -0,0 +1,33 @@ +# Common +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/common/lib/Common.sol) + + +## Functions +### getV + + +```solidity +function getV(bytes memory v, uint16 chainId) public pure returns (uint8); +``` + +### isContract + + +```solidity +function isContract(address _addr) public view returns (bool); +``` + +### toUint8 + + +```solidity +function toUint8(bytes memory _arg) public pure returns (uint8); +``` + +### toUint16 + + +```solidity +function toUint16(bytes memory _arg) public pure returns (uint16); +``` + diff --git a/docs/autogen/src/contracts/common/lib/ECVerify.sol/library.ECVerify.md b/docs/autogen/src/contracts/common/lib/ECVerify.sol/library.ECVerify.md new file mode 100644 index 000000000..1286ec280 --- /dev/null +++ b/docs/autogen/src/contracts/common/lib/ECVerify.sol/library.ECVerify.md @@ -0,0 +1,33 @@ +# ECVerify +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/common/lib/ECVerify.sol) + + +## Functions +### ecrecovery + + +```solidity +function ecrecovery(bytes32 hash, uint256[3] memory sig) internal pure returns (address); +``` + +### ecrecovery + + +```solidity +function ecrecovery(bytes32 hash, bytes memory sig) internal pure returns (address); +``` + +### ecrecovery + + +```solidity +function ecrecovery(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address); +``` + +### ecverify + + +```solidity +function ecverify(bytes32 hash, bytes memory sig, address signer) internal pure returns (bool); +``` + diff --git a/docs/autogen/src/contracts/common/lib/ExitPayloadReader.sol/library.ExitPayloadReader.md b/docs/autogen/src/contracts/common/lib/ExitPayloadReader.sol/library.ExitPayloadReader.md new file mode 100644 index 000000000..5034d56a4 --- /dev/null +++ b/docs/autogen/src/contracts/common/lib/ExitPayloadReader.sol/library.ExitPayloadReader.md @@ -0,0 +1,203 @@ +# ExitPayloadReader +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/common/lib/ExitPayloadReader.sol) + + +## State Variables +### WORD_SIZE + +```solidity +uint8 constant WORD_SIZE = 32; +``` + + +## Functions +### toExitPayload + + +```solidity +function toExitPayload(bytes memory data) internal pure returns (ExitPayload memory); +``` + +### copy + + +```solidity +function copy(uint256 src, uint256 dest, uint256 len) private pure; +``` + +### getHeaderNumber + + +```solidity +function getHeaderNumber(ExitPayload memory payload) internal pure returns (uint256); +``` + +### getBlockProof + + +```solidity +function getBlockProof(ExitPayload memory payload) internal pure returns (bytes memory); +``` + +### getBlockNumber + + +```solidity +function getBlockNumber(ExitPayload memory payload) internal pure returns (uint256); +``` + +### getBlockTime + + +```solidity +function getBlockTime(ExitPayload memory payload) internal pure returns (uint256); +``` + +### getTxRoot + + +```solidity +function getTxRoot(ExitPayload memory payload) internal pure returns (bytes32); +``` + +### getReceiptRoot + + +```solidity +function getReceiptRoot(ExitPayload memory payload) internal pure returns (bytes32); +``` + +### getReceipt + + +```solidity +function getReceipt(ExitPayload memory payload) internal pure returns (Receipt memory receipt); +``` + +### getReceiptProof + + +```solidity +function getReceiptProof(ExitPayload memory payload) internal pure returns (bytes memory); +``` + +### getBranchMaskAsBytes + + +```solidity +function getBranchMaskAsBytes(ExitPayload memory payload) internal pure returns (bytes memory); +``` + +### getBranchMaskAsUint + + +```solidity +function getBranchMaskAsUint(ExitPayload memory payload) internal pure returns (uint256); +``` + +### getReceiptLogIndex + + +```solidity +function getReceiptLogIndex(ExitPayload memory payload) internal pure returns (uint256); +``` + +### getTx + + +```solidity +function getTx(ExitPayload memory payload) internal pure returns (bytes memory); +``` + +### getTxProof + + +```solidity +function getTxProof(ExitPayload memory payload) internal pure returns (bytes memory); +``` + +### toBytes + + +```solidity +function toBytes(Receipt memory receipt) internal pure returns (bytes memory); +``` + +### getLog + + +```solidity +function getLog(Receipt memory receipt) internal pure returns (Log memory); +``` + +### getEmitter + + +```solidity +function getEmitter(Log memory log) internal pure returns (address); +``` + +### getTopics + + +```solidity +function getTopics(Log memory log) internal pure returns (LogTopics memory); +``` + +### getData + + +```solidity +function getData(Log memory log) internal pure returns (bytes memory); +``` + +### toRlpBytes + + +```solidity +function toRlpBytes(Log memory log) internal pure returns (bytes memory); +``` + +### getField + + +```solidity +function getField(LogTopics memory topics, uint256 index) internal pure returns (RLPReader.RLPItem memory); +``` + +## Structs +### ExitPayload + +```solidity +struct ExitPayload { + RLPReader.RLPItem[] data; +} +``` + +### Receipt + +```solidity +struct Receipt { + RLPReader.RLPItem[] data; + bytes raw; + uint256 logIndex; +} +``` + +### Log + +```solidity +struct Log { + RLPReader.RLPItem data; + RLPReader.RLPItem[] list; +} +``` + +### LogTopics + +```solidity +struct LogTopics { + RLPReader.RLPItem[] data; +} +``` + diff --git a/docs/autogen/src/contracts/common/lib/Merkle.sol/library.Merkle.md b/docs/autogen/src/contracts/common/lib/Merkle.sol/library.Merkle.md new file mode 100644 index 000000000..96c1ee4c0 --- /dev/null +++ b/docs/autogen/src/contracts/common/lib/Merkle.sol/library.Merkle.md @@ -0,0 +1,12 @@ +# Merkle +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/common/lib/Merkle.sol) + + +## Functions +### checkMembership + + +```solidity +function checkMembership(bytes32 leaf, uint256 index, bytes32 rootHash, bytes memory proof) internal pure returns (bool); +``` + diff --git a/docs/autogen/src/contracts/common/lib/MerklePatriciaProof.sol/library.MerklePatriciaProof.md b/docs/autogen/src/contracts/common/lib/MerklePatriciaProof.sol/library.MerklePatriciaProof.md new file mode 100644 index 000000000..4904ef0ab --- /dev/null +++ b/docs/autogen/src/contracts/common/lib/MerklePatriciaProof.sol/library.MerklePatriciaProof.md @@ -0,0 +1,33 @@ +# MerklePatriciaProof +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/common/lib/MerklePatriciaProof.sol) + + +## Functions +### verify + + +```solidity +function verify(bytes memory value, bytes memory encodedPath, bytes memory rlpParentNodes, bytes32 root) internal pure returns (bool); +``` + +### _nibblesToTraverse + + +```solidity +function _nibblesToTraverse(bytes memory encodedPartialPath, bytes memory path, uint256 pathPtr) private pure returns (uint256); +``` + +### _getNibbleArray + + +```solidity +function _getNibbleArray(bytes memory b) private pure returns (bytes memory); +``` + +### _getNthNibbleOfBytes + + +```solidity +function _getNthNibbleOfBytes(uint256 n, bytes memory str) private pure returns (bytes1); +``` + diff --git a/docs/autogen/src/contracts/common/lib/PriorityQueue.sol/contract.PriorityQueue.md b/docs/autogen/src/contracts/common/lib/PriorityQueue.sol/contract.PriorityQueue.md new file mode 100644 index 000000000..740006ad4 --- /dev/null +++ b/docs/autogen/src/contracts/common/lib/PriorityQueue.sol/contract.PriorityQueue.md @@ -0,0 +1,141 @@ +# PriorityQueue +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/common/lib/PriorityQueue.sol) + +**Inherits:** +Ownable + +*A priority queue implementation.* + + +## State Variables +### heapList + +```solidity +uint256[] heapList; +``` + + +### currentSize + +```solidity +uint256 public currentSize; +``` + + +## Functions +### constructor + + +```solidity +constructor() public; +``` + +### insert + +*Inserts an element into the priority queue.* + + +```solidity +function insert(uint256 _priority, uint256 _value) public onlyOwner; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`_priority`|`uint256`|Priority to insert.| +|`_value`|`uint256`|Some additional value.| + + +### getMin + +*Returns the top element of the heap.* + + +```solidity +function getMin() public view returns (uint256, uint256); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|The smallest element in the priority queue.| +|``|`uint256`|| + + +### delMin + +*Deletes the top element of the heap and shifts everything up.* + + +```solidity +function delMin() public onlyOwner returns (uint256, uint256); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|The smallest element in the priorty queue.| +|``|`uint256`|| + + +### _minChild + +*Determines the minimum child of a given node in the tree.* + + +```solidity +function _minChild(uint256 _index) private view returns (uint256); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`_index`|`uint256`|Index of the node in the tree.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|The smallest child node.| + + +### _percUp + +*Bubbles the element at some index up.* + + +```solidity +function _percUp(uint256 _index) private; +``` + +### _percDown + +*Bubbles the element at some index down.* + + +```solidity +function _percDown(uint256 _index) private; +``` + +### _splitElement + +*Split an element into its priority and value.* + + +```solidity +function _splitElement(uint256 _element) private pure returns (uint256, uint256); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`_element`|`uint256`|Element to decode.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|A tuple containing the priority and value.| +|``|`uint256`|| + + diff --git a/docs/autogen/src/contracts/common/lib/README.md b/docs/autogen/src/contracts/common/lib/README.md new file mode 100644 index 000000000..57470311d --- /dev/null +++ b/docs/autogen/src/contracts/common/lib/README.md @@ -0,0 +1,11 @@ + + +# Contents +- [BytesLib](BytesLib.sol/library.BytesLib.md) +- [Common](Common.sol/library.Common.md) +- [ECVerify](ECVerify.sol/library.ECVerify.md) +- [ExitPayloadReader](ExitPayloadReader.sol/library.ExitPayloadReader.md) +- [Merkle](Merkle.sol/library.Merkle.md) +- [MerklePatriciaProof](MerklePatriciaProof.sol/library.MerklePatriciaProof.md) +- [PriorityQueue](PriorityQueue.sol/contract.PriorityQueue.md) +- [RLPEncode](RLPEncode.sol/library.RLPEncode.md) diff --git a/docs/autogen/src/contracts/common/lib/RLPEncode.sol/library.RLPEncode.md b/docs/autogen/src/contracts/common/lib/RLPEncode.sol/library.RLPEncode.md new file mode 100644 index 000000000..8950ab226 --- /dev/null +++ b/docs/autogen/src/contracts/common/lib/RLPEncode.sol/library.RLPEncode.md @@ -0,0 +1,33 @@ +# RLPEncode +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/common/lib/RLPEncode.sol) + + +## Functions +### encodeItem + + +```solidity +function encodeItem(bytes memory self) internal pure returns (bytes memory); +``` + +### encodeList + + +```solidity +function encodeList(bytes[] memory self) internal pure returns (bytes memory); +``` + +### encodeLength + + +```solidity +function encodeLength(uint256 L, uint256 offset) internal pure returns (bytes memory); +``` + +### getLengthBytes + + +```solidity +function getLengthBytes(uint256 x) internal pure returns (bytes memory b); +``` + diff --git a/docs/autogen/src/contracts/common/misc/ContractReceiver.sol/contract.ContractReceiver.md b/docs/autogen/src/contracts/common/misc/ContractReceiver.sol/contract.ContractReceiver.md new file mode 100644 index 000000000..8016e784f --- /dev/null +++ b/docs/autogen/src/contracts/common/misc/ContractReceiver.sol/contract.ContractReceiver.md @@ -0,0 +1,22 @@ +# ContractReceiver +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/common/misc/ContractReceiver.sol) + + +## Functions +### tokenFallback + +*Function that is called when a user or another contract wants to transfer funds.* + + +```solidity +function tokenFallback(address _from, uint256 _value, bytes memory _data) public; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`_from`|`address`|Transaction initiator, analogue of msg.sender| +|`_value`|`uint256`|Number of tokens to transfer.| +|`_data`|`bytes`|Data containig a function signature and/or parameters| + + diff --git a/docs/autogen/src/contracts/common/misc/DelegateProxy.sol/contract.DelegateProxy.md b/docs/autogen/src/contracts/common/misc/DelegateProxy.sol/contract.DelegateProxy.md new file mode 100644 index 000000000..6044db6aa --- /dev/null +++ b/docs/autogen/src/contracts/common/misc/DelegateProxy.sol/contract.DelegateProxy.md @@ -0,0 +1,22 @@ +# DelegateProxy +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/common/misc/DelegateProxy.sol) + +**Inherits:** +[ERCProxy](/contracts/common/misc/ERCProxy.sol/interface.ERCProxy.md), [DelegateProxyForwarder](/contracts/common/misc/DelegateProxyForwarder.sol/contract.DelegateProxyForwarder.md) + + +## Functions +### proxyType + + +```solidity +function proxyType() external pure returns (uint256 proxyTypeId); +``` + +### implementation + + +```solidity +function implementation() external view returns (address); +``` + diff --git a/docs/autogen/src/contracts/common/misc/DelegateProxyForwarder.sol/contract.DelegateProxyForwarder.md b/docs/autogen/src/contracts/common/misc/DelegateProxyForwarder.sol/contract.DelegateProxyForwarder.md new file mode 100644 index 000000000..7f317b0a4 --- /dev/null +++ b/docs/autogen/src/contracts/common/misc/DelegateProxyForwarder.sol/contract.DelegateProxyForwarder.md @@ -0,0 +1,19 @@ +# DelegateProxyForwarder +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/common/misc/DelegateProxyForwarder.sol) + + +## Functions +### delegatedFwd + + +```solidity +function delegatedFwd(address _dst, bytes memory _calldata) internal; +``` + +### isContract + + +```solidity +function isContract(address _target) internal view returns (bool); +``` + diff --git a/docs/autogen/src/contracts/common/misc/DrainStakeManager.sol/contract.DrainStakeManager.md b/docs/autogen/src/contracts/common/misc/DrainStakeManager.sol/contract.DrainStakeManager.md new file mode 100644 index 000000000..2113802d6 --- /dev/null +++ b/docs/autogen/src/contracts/common/misc/DrainStakeManager.sol/contract.DrainStakeManager.md @@ -0,0 +1,36 @@ +# DrainStakeManager +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/common/misc/DrainStakeManager.sol) + +**Inherits:** +[StakeManagerStorage](/contracts/staking/stakeManager/StakeManagerStorage.sol/contract.StakeManagerStorage.md), [Initializable](/contracts/common/mixin/Initializable.sol/contract.Initializable.md) + + +## Functions +### constructor + + +```solidity +constructor() public GovernanceLockable(address(0x0)); +``` + +### drain + + +```solidity +function drain(address destination, uint256 amount) external onlyOwner; +``` + +### drainValidatorShares + + +```solidity +function drainValidatorShares(uint256 validatorId, address _token, address payable destination, uint256 amount) external onlyOwner; +``` + +### isOwner + + +```solidity +function isOwner() public view returns (bool); +``` + diff --git a/docs/autogen/src/contracts/common/misc/Drainable.sol/contract.Drainable.md b/docs/autogen/src/contracts/common/misc/Drainable.sol/contract.Drainable.md new file mode 100644 index 000000000..645349f36 --- /dev/null +++ b/docs/autogen/src/contracts/common/misc/Drainable.sol/contract.Drainable.md @@ -0,0 +1,36 @@ +# Drainable +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/common/misc/Drainable.sol) + +**Inherits:** +[DepositManagerStorage](/contracts/root/depositManager/DepositManagerStorage.sol/contract.DepositManagerStorage.md) + + +## Functions +### constructor + + +```solidity +constructor() public GovernanceLockable(address(0x0)); +``` + +### drainErc20 + + +```solidity +function drainErc20(address[] calldata tokens, uint256[] calldata values, address destination) external onlyGovernance; +``` + +### drainErc721 + + +```solidity +function drainErc721(address[] calldata tokens, uint256[] calldata values, address destination) external onlyGovernance; +``` + +### drainEther + + +```solidity +function drainEther(uint256 amount, address payable destination) external onlyGovernance; +``` + diff --git a/docs/autogen/src/contracts/common/misc/ERCProxy.sol/interface.ERCProxy.md b/docs/autogen/src/contracts/common/misc/ERCProxy.sol/interface.ERCProxy.md new file mode 100644 index 000000000..a14b05c63 --- /dev/null +++ b/docs/autogen/src/contracts/common/misc/ERCProxy.sol/interface.ERCProxy.md @@ -0,0 +1,19 @@ +# ERCProxy +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/common/misc/ERCProxy.sol) + + +## Functions +### proxyType + + +```solidity +function proxyType() external pure returns (uint256 proxyTypeId); +``` + +### implementation + + +```solidity +function implementation() external view returns (address codeAddr); +``` + diff --git a/docs/autogen/src/contracts/common/misc/Proxy.sol/contract.Proxy.md b/docs/autogen/src/contracts/common/misc/Proxy.sol/contract.Proxy.md new file mode 100644 index 000000000..aaaa6571a --- /dev/null +++ b/docs/autogen/src/contracts/common/misc/Proxy.sol/contract.Proxy.md @@ -0,0 +1,56 @@ +# Proxy +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/common/misc/Proxy.sol) + +**Inherits:** +[ProxyStorage](/contracts/common/misc/ProxyStorage.sol/contract.ProxyStorage.md), [DelegateProxy](/contracts/common/misc/DelegateProxy.sol/contract.DelegateProxy.md) + + +## Functions +### constructor + + +```solidity +constructor(address _proxyTo) public; +``` + +### function + + +```solidity +function() external payable; +``` + +### implementation + + +```solidity +function implementation() external view returns (address); +``` + +### updateImplementation + + +```solidity +function updateImplementation(address _newProxyTo) public onlyOwner; +``` + +### isContract + + +```solidity +function isContract(address _target) internal view returns (bool); +``` + +## Events +### ProxyUpdated + +```solidity +event ProxyUpdated(address indexed _new, address indexed _old); +``` + +### OwnerUpdate + +```solidity +event OwnerUpdate(address _prevOwner, address _newOwner); +``` + diff --git a/docs/autogen/src/contracts/common/misc/ProxyStorage.sol/contract.ProxyStorage.md b/docs/autogen/src/contracts/common/misc/ProxyStorage.sol/contract.ProxyStorage.md new file mode 100644 index 000000000..66dd8bc01 --- /dev/null +++ b/docs/autogen/src/contracts/common/misc/ProxyStorage.sol/contract.ProxyStorage.md @@ -0,0 +1,15 @@ +# ProxyStorage +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/common/misc/ProxyStorage.sol) + +**Inherits:** +Ownable + + +## State Variables +### proxyTo + +```solidity +address internal proxyTo; +``` + + diff --git a/docs/autogen/src/contracts/common/misc/README.md b/docs/autogen/src/contracts/common/misc/README.md new file mode 100644 index 000000000..4e0e42bc2 --- /dev/null +++ b/docs/autogen/src/contracts/common/misc/README.md @@ -0,0 +1,12 @@ + + +# Contents +- [ContractReceiver](ContractReceiver.sol/contract.ContractReceiver.md) +- [DelegateProxy](DelegateProxy.sol/contract.DelegateProxy.md) +- [DelegateProxyForwarder](DelegateProxyForwarder.sol/contract.DelegateProxyForwarder.md) +- [DrainStakeManager](DrainStakeManager.sol/contract.DrainStakeManager.md) +- [Drainable](Drainable.sol/contract.Drainable.md) +- [ERCProxy](ERCProxy.sol/interface.ERCProxy.md) +- [Proxy](Proxy.sol/contract.Proxy.md) +- [ProxyStorage](ProxyStorage.sol/contract.ProxyStorage.md) +- [UpgradableProxy](UpgradableProxy.sol/contract.UpgradableProxy.md) diff --git a/docs/autogen/src/contracts/common/misc/UpgradableProxy.sol/contract.UpgradableProxy.md b/docs/autogen/src/contracts/common/misc/UpgradableProxy.sol/contract.UpgradableProxy.md new file mode 100644 index 000000000..f90c42977 --- /dev/null +++ b/docs/autogen/src/contracts/common/misc/UpgradableProxy.sol/contract.UpgradableProxy.md @@ -0,0 +1,120 @@ +# UpgradableProxy +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/common/misc/UpgradableProxy.sol) + +**Inherits:** +[DelegateProxy](/contracts/common/misc/DelegateProxy.sol/contract.DelegateProxy.md) + + +## State Variables +### IMPLEMENTATION_SLOT + +```solidity +bytes32 constant IMPLEMENTATION_SLOT = keccak256("matic.network.proxy.implementation"); +``` + + +### OWNER_SLOT + +```solidity +bytes32 constant OWNER_SLOT = keccak256("matic.network.proxy.owner"); +``` + + +## Functions +### constructor + + +```solidity +constructor(address _proxyTo) public; +``` + +### function + + +```solidity +function() external payable; +``` + +### onlyProxyOwner + + +```solidity +modifier onlyProxyOwner(); +``` + +### owner + + +```solidity +function owner() external view returns (address); +``` + +### loadOwner + + +```solidity +function loadOwner() internal view returns (address); +``` + +### implementation + + +```solidity +function implementation() external view returns (address); +``` + +### loadImplementation + + +```solidity +function loadImplementation() internal view returns (address); +``` + +### transferOwnership + + +```solidity +function transferOwnership(address newOwner) public onlyProxyOwner; +``` + +### setOwner + + +```solidity +function setOwner(address newOwner) private; +``` + +### updateImplementation + + +```solidity +function updateImplementation(address _newProxyTo) public onlyProxyOwner; +``` + +### updateAndCall + + +```solidity +function updateAndCall(address _newProxyTo, bytes memory data) public payable onlyProxyOwner; +``` + +### setImplementation + + +```solidity +function setImplementation(address _newProxyTo) private; +``` + +## Events +### ProxyUpdated + +```solidity +event ProxyUpdated(address indexed _new, address indexed _old); +``` + +### OwnerUpdate + +```solidity +event OwnerUpdate(address _new, address _old); +``` + diff --git a/docs/autogen/src/contracts/common/mixin/ChainIdMixin.sol/contract.ChainIdMixin.md b/docs/autogen/src/contracts/common/mixin/ChainIdMixin.sol/contract.ChainIdMixin.md new file mode 100644 index 000000000..da58bee9e --- /dev/null +++ b/docs/autogen/src/contracts/common/mixin/ChainIdMixin.sol/contract.ChainIdMixin.md @@ -0,0 +1,19 @@ +# ChainIdMixin +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/common/mixin/ChainIdMixin.sol) + + +## State Variables +### networkId + +```solidity +bytes public constant networkId = hex"3A99"; +``` + + +### CHAINID + +```solidity +uint256 public constant CHAINID = 15_001; +``` + + diff --git a/docs/autogen/src/contracts/common/mixin/GovernanceLockable.sol/contract.GovernanceLockable.md b/docs/autogen/src/contracts/common/mixin/GovernanceLockable.sol/contract.GovernanceLockable.md new file mode 100644 index 000000000..48f91f5f4 --- /dev/null +++ b/docs/autogen/src/contracts/common/mixin/GovernanceLockable.sol/contract.GovernanceLockable.md @@ -0,0 +1,29 @@ +# GovernanceLockable +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/common/mixin/GovernanceLockable.sol) + +**Inherits:** +[Lockable](/contracts/common/mixin/Lockable.sol/contract.Lockable.md), [Governable](/contracts/common/governance/Governable.sol/contract.Governable.md) + + +## Functions +### constructor + + +```solidity +constructor(address governance) public Governable(governance); +``` + +### lock + + +```solidity +function lock() public onlyGovernance; +``` + +### unlock + + +```solidity +function unlock() public onlyGovernance; +``` + diff --git a/docs/autogen/src/contracts/common/mixin/Initializable.sol/contract.Initializable.md b/docs/autogen/src/contracts/common/mixin/Initializable.sol/contract.Initializable.md new file mode 100644 index 000000000..140e86a9d --- /dev/null +++ b/docs/autogen/src/contracts/common/mixin/Initializable.sol/contract.Initializable.md @@ -0,0 +1,20 @@ +# Initializable +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/common/mixin/Initializable.sol) + + +## State Variables +### inited + +```solidity +bool inited = false; +``` + + +## Functions +### initializer + + +```solidity +modifier initializer(); +``` + diff --git a/docs/autogen/src/contracts/common/mixin/Lockable.sol/contract.Lockable.md b/docs/autogen/src/contracts/common/mixin/Lockable.sol/contract.Lockable.md new file mode 100644 index 000000000..f4c6d58da --- /dev/null +++ b/docs/autogen/src/contracts/common/mixin/Lockable.sol/contract.Lockable.md @@ -0,0 +1,41 @@ +# Lockable +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/common/mixin/Lockable.sol) + + +## State Variables +### locked + +```solidity +bool public locked; +``` + + +## Functions +### onlyWhenUnlocked + + +```solidity +modifier onlyWhenUnlocked(); +``` + +### _assertUnlocked + + +```solidity +function _assertUnlocked() private view; +``` + +### lock + + +```solidity +function lock() public; +``` + +### unlock + + +```solidity +function unlock() public; +``` + diff --git a/docs/autogen/src/contracts/common/mixin/OwnableLockable.sol/contract.OwnableLockable.md b/docs/autogen/src/contracts/common/mixin/OwnableLockable.sol/contract.OwnableLockable.md new file mode 100644 index 000000000..29cb693d9 --- /dev/null +++ b/docs/autogen/src/contracts/common/mixin/OwnableLockable.sol/contract.OwnableLockable.md @@ -0,0 +1,22 @@ +# OwnableLockable +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/common/mixin/OwnableLockable.sol) + +**Inherits:** +[Lockable](/contracts/common/mixin/Lockable.sol/contract.Lockable.md), Ownable + + +## Functions +### lock + + +```solidity +function lock() public onlyOwner; +``` + +### unlock + + +```solidity +function unlock() public onlyOwner; +``` + diff --git a/docs/autogen/src/contracts/common/mixin/README.md b/docs/autogen/src/contracts/common/mixin/README.md new file mode 100644 index 000000000..7fd484c06 --- /dev/null +++ b/docs/autogen/src/contracts/common/mixin/README.md @@ -0,0 +1,9 @@ + + +# Contents +- [ChainIdMixin](ChainIdMixin.sol/contract.ChainIdMixin.md) +- [GovernanceLockable](GovernanceLockable.sol/contract.GovernanceLockable.md) +- [Initializable](Initializable.sol/contract.Initializable.md) +- [Lockable](Lockable.sol/contract.Lockable.md) +- [OwnableLockable](OwnableLockable.sol/contract.OwnableLockable.md) +- [RootChainable](RootChainable.sol/contract.RootChainable.md) diff --git a/docs/autogen/src/contracts/common/mixin/RootChainable.sol/contract.RootChainable.md b/docs/autogen/src/contracts/common/mixin/RootChainable.sol/contract.RootChainable.md new file mode 100644 index 000000000..112807408 --- /dev/null +++ b/docs/autogen/src/contracts/common/mixin/RootChainable.sol/contract.RootChainable.md @@ -0,0 +1,45 @@ +# RootChainable +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/common/mixin/RootChainable.sol) + +**Inherits:** +Ownable + + +## State Variables +### rootChain + +```solidity +address public rootChain; +``` + + +## Functions +### onlyRootChain + + +```solidity +modifier onlyRootChain(); +``` + +### changeRootChain + +*Allows the current owner to change root chain address.* + + +```solidity +function changeRootChain(address newRootChain) public onlyOwner; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`newRootChain`|`address`|The address to new rootchain.| + + +## Events +### RootChainChanged + +```solidity +event RootChainChanged(address indexed previousRootChain, address indexed newRootChain); +``` + diff --git a/docs/autogen/src/contracts/common/tokens/ERC20NonTradable.sol/contract.ERC20NonTradable.md b/docs/autogen/src/contracts/common/tokens/ERC20NonTradable.sol/contract.ERC20NonTradable.md new file mode 100644 index 000000000..96a2bc0e8 --- /dev/null +++ b/docs/autogen/src/contracts/common/tokens/ERC20NonTradable.sol/contract.ERC20NonTradable.md @@ -0,0 +1,15 @@ +# ERC20NonTradable +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/common/tokens/ERC20NonTradable.sol) + +**Inherits:** +ERC20 + + +## Functions +### _approve + + +```solidity +function _approve(address owner, address spender, uint256 value) internal; +``` + diff --git a/docs/autogen/src/contracts/common/tokens/ERC20NonTransferable.sol/contract.ERC20NonTransferable.md b/docs/autogen/src/contracts/common/tokens/ERC20NonTransferable.sol/contract.ERC20NonTransferable.md new file mode 100644 index 000000000..078810768 --- /dev/null +++ b/docs/autogen/src/contracts/common/tokens/ERC20NonTransferable.sol/contract.ERC20NonTransferable.md @@ -0,0 +1,15 @@ +# ERC20NonTransferable +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/common/tokens/ERC20NonTransferable.sol) + +**Inherits:** +ERC20 + + +## Functions +### _transfer + + +```solidity +function _transfer(address from, address to, uint256 value) internal; +``` + diff --git a/docs/autogen/src/contracts/common/tokens/ERC721PlasmaMintable.sol/contract.ERC721PlasmaMintable.md b/docs/autogen/src/contracts/common/tokens/ERC721PlasmaMintable.sol/contract.ERC721PlasmaMintable.md new file mode 100644 index 000000000..3d83e71bd --- /dev/null +++ b/docs/autogen/src/contracts/common/tokens/ERC721PlasmaMintable.sol/contract.ERC721PlasmaMintable.md @@ -0,0 +1,36 @@ +# ERC721PlasmaMintable +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/common/tokens/ERC721PlasmaMintable.sol) + +**Inherits:** +ERC721Mintable, ERC721MetadataMintable + + +## Functions +### constructor + + +```solidity +constructor(string memory name, string memory symbol) public ERC721Metadata(name, symbol); +``` + +### exists + +*Returns whether the specified token exists* + + +```solidity +function exists(uint256 tokenId) public view returns (bool); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`tokenId`|`uint256`|uint256 ID of the token to query the existence of| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bool`|bool whether the token exists| + + diff --git a/docs/autogen/src/contracts/common/tokens/MaticWETH.sol/contract.MaticWETH.md b/docs/autogen/src/contracts/common/tokens/MaticWETH.sol/contract.MaticWETH.md new file mode 100644 index 000000000..1f76cdf5d --- /dev/null +++ b/docs/autogen/src/contracts/common/tokens/MaticWETH.sol/contract.MaticWETH.md @@ -0,0 +1,51 @@ +# MaticWETH +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/common/tokens/MaticWETH.sol) + +**Inherits:** +[WETH](/contracts/common/tokens/WETH.sol/contract.WETH.md) + + +## State Variables +### name + +```solidity +string public name = "Wrapped Ether"; +``` + + +### symbol + +```solidity +string public symbol = "WETH"; +``` + + +### decimals + +```solidity +uint8 public decimals = 18; +``` + + +## Functions +### deposit + + +```solidity +function deposit() public payable; +``` + +### withdraw + + +```solidity +function withdraw(uint256 wad) public; +``` + +### withdraw + + +```solidity +function withdraw(uint256 wad, address user) public; +``` + diff --git a/docs/autogen/src/contracts/common/tokens/POLTokenMock.sol/contract.POLTokenMock.md b/docs/autogen/src/contracts/common/tokens/POLTokenMock.sol/contract.POLTokenMock.md new file mode 100644 index 000000000..1bd56d609 --- /dev/null +++ b/docs/autogen/src/contracts/common/tokens/POLTokenMock.sol/contract.POLTokenMock.md @@ -0,0 +1,68 @@ +# POLTokenMock +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/common/tokens/POLTokenMock.sol) + +**Inherits:** +ERC20Mintable + + +## State Variables +### name + +```solidity +string public name; +``` + + +### symbol + +```solidity +string public symbol; +``` + + +### decimals + +```solidity +uint8 public decimals = 18; +``` + + +## Functions +### constructor + + +```solidity +constructor(string memory _name, string memory _symbol) public; +``` + +### safeTransfer + + +```solidity +function safeTransfer(IERC20 token, address to, uint256 value) public; +``` + +### safeTransferFrom + + +```solidity +function safeTransferFrom(IERC20 token, address from, address to, uint256 value) public; +``` + +### callOptionalReturn + +*Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement +on the return value: the return value is optional (but if data is returned, it must equal true).* + + +```solidity +function callOptionalReturn(IERC20 token, bytes memory data) private; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`token`|`IERC20`|The token targeted by the call.| +|`data`|`bytes`|The call data (encoded using abi.encode or one of its variants).| + + diff --git a/docs/autogen/src/contracts/common/tokens/README.md b/docs/autogen/src/contracts/common/tokens/README.md new file mode 100644 index 000000000..5c3db7ef0 --- /dev/null +++ b/docs/autogen/src/contracts/common/tokens/README.md @@ -0,0 +1,11 @@ + + +# Contents +- [ERC20NonTradable](ERC20NonTradable.sol/contract.ERC20NonTradable.md) +- [ERC20NonTransferable](ERC20NonTransferable.sol/contract.ERC20NonTransferable.md) +- [ERC721PlasmaMintable](ERC721PlasmaMintable.sol/contract.ERC721PlasmaMintable.md) +- [MaticWETH](MaticWETH.sol/contract.MaticWETH.md) +- [POLTokenMock](POLTokenMock.sol/contract.POLTokenMock.md) +- [RootERC721](RootERC721.sol/contract.RootERC721.md) +- [TestToken](TestToken.sol/contract.TestToken.md) +- [WETH](WETH.sol/contract.WETH.md) diff --git a/docs/autogen/src/contracts/common/tokens/RootERC721.sol/contract.RootERC721.md b/docs/autogen/src/contracts/common/tokens/RootERC721.sol/contract.RootERC721.md new file mode 100644 index 000000000..31a866f3d --- /dev/null +++ b/docs/autogen/src/contracts/common/tokens/RootERC721.sol/contract.RootERC721.md @@ -0,0 +1,22 @@ +# RootERC721 +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/common/tokens/RootERC721.sol) + +**Inherits:** +ERC721Full + + +## Functions +### constructor + + +```solidity +constructor(string memory name, string memory symbol) public ERC721Full(name, symbol); +``` + +### mint + + +```solidity +function mint(uint256 tokenId) public; +``` + diff --git a/docs/autogen/src/contracts/common/tokens/TestToken.sol/contract.TestToken.md b/docs/autogen/src/contracts/common/tokens/TestToken.sol/contract.TestToken.md new file mode 100644 index 000000000..301ef5e06 --- /dev/null +++ b/docs/autogen/src/contracts/common/tokens/TestToken.sol/contract.TestToken.md @@ -0,0 +1,37 @@ +# TestToken +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/common/tokens/TestToken.sol) + +**Inherits:** +ERC20Mintable + + +## State Variables +### name + +```solidity +string public name; +``` + + +### symbol + +```solidity +string public symbol; +``` + + +### decimals + +```solidity +uint8 public decimals = 18; +``` + + +## Functions +### constructor + + +```solidity +constructor(string memory _name, string memory _symbol) public; +``` + diff --git a/docs/autogen/src/contracts/common/tokens/WETH.sol/contract.WETH.md b/docs/autogen/src/contracts/common/tokens/WETH.sol/contract.WETH.md new file mode 100644 index 000000000..9cc992d1c --- /dev/null +++ b/docs/autogen/src/contracts/common/tokens/WETH.sol/contract.WETH.md @@ -0,0 +1,42 @@ +# WETH +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/common/tokens/WETH.sol) + +**Inherits:** +ERC20 + + +## Functions +### deposit + + +```solidity +function deposit() public payable; +``` + +### withdraw + + +```solidity +function withdraw(uint256 wad) public; +``` + +### withdraw + + +```solidity +function withdraw(uint256 wad, address user) public; +``` + +## Events +### Deposit + +```solidity +event Deposit(address indexed dst, uint256 wad); +``` + +### Withdrawal + +```solidity +event Withdrawal(address indexed src, uint256 wad); +``` + diff --git a/docs/autogen/src/contracts/root/IRootChain.sol/interface.IRootChain.md b/docs/autogen/src/contracts/root/IRootChain.sol/interface.IRootChain.md new file mode 100644 index 000000000..342270311 --- /dev/null +++ b/docs/autogen/src/contracts/root/IRootChain.sol/interface.IRootChain.md @@ -0,0 +1,40 @@ +# IRootChain +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/root/IRootChain.sol) + + +## Functions +### slash + + +```solidity +function slash() external; +``` + +### submitHeaderBlock + + +```solidity +function submitHeaderBlock(bytes calldata data, bytes calldata sigs) external; +``` + +### submitCheckpoint + + +```solidity +function submitCheckpoint(bytes calldata data, uint256[3][] calldata sigs) external; +``` + +### getLastChildBlock + + +```solidity +function getLastChildBlock() external view returns (uint256); +``` + +### currentHeaderBlock + + +```solidity +function currentHeaderBlock() external view returns (uint256); +``` + diff --git a/docs/autogen/src/contracts/root/README.md b/docs/autogen/src/contracts/root/README.md new file mode 100644 index 000000000..212e4eca6 --- /dev/null +++ b/docs/autogen/src/contracts/root/README.md @@ -0,0 +1,12 @@ + + +# Contents +- [depositManager](/contracts/root/depositManager) +- [predicates](/contracts/root/predicates) +- [stateSyncer](/contracts/root/stateSyncer) +- [withdrawManager](/contracts/root/withdrawManager) +- [IRootChain](IRootChain.sol/interface.IRootChain.md) +- [RootChain](RootChain.sol/contract.RootChain.md) +- [RootChainProxy](RootChainProxy.sol/contract.RootChainProxy.md) +- [RootChainHeader](RootChainStorage.sol/contract.RootChainHeader.md) +- [RootChainStorage](RootChainStorage.sol/contract.RootChainStorage.md) diff --git a/docs/autogen/src/contracts/root/RootChain.sol/contract.RootChain.md b/docs/autogen/src/contracts/root/RootChain.sol/contract.RootChain.md new file mode 100644 index 000000000..2d51a2ff9 --- /dev/null +++ b/docs/autogen/src/contracts/root/RootChain.sol/contract.RootChain.md @@ -0,0 +1,82 @@ +# RootChain +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/root/RootChain.sol) + +**Inherits:** +[RootChainStorage](/contracts/root/RootChainStorage.sol/contract.RootChainStorage.md), [IRootChain](/contracts/root/IRootChain.sol/interface.IRootChain.md) + + +## Functions +### onlyDepositManager + + +```solidity +modifier onlyDepositManager(); +``` + +### submitHeaderBlock + + +```solidity +function submitHeaderBlock(bytes calldata data, bytes calldata sigs) external; +``` + +### submitCheckpoint + + +```solidity +function submitCheckpoint(bytes calldata data, uint256[3][] calldata sigs) external; +``` + +### updateDepositId + +prefix 01 to data +01 represents positive vote on data and 00 is negative vote +malicious validator can try to send 2/3 on negative vote so 01 is appended + + +```solidity +function updateDepositId(uint256 numDeposits) external onlyDepositManager returns (uint256 depositId); +``` + +### getLastChildBlock + + +```solidity +function getLastChildBlock() external view returns (uint256); +``` + +### slash + + +```solidity +function slash() external; +``` + +### currentHeaderBlock + + +```solidity +function currentHeaderBlock() public view returns (uint256); +``` + +### _buildHeaderBlock + + +```solidity +function _buildHeaderBlock(address proposer, uint256 start, uint256 end, bytes32 rootHash) private returns (bool); +``` + +### setNextHeaderBlock + + +```solidity +function setNextHeaderBlock(uint256 _value) public onlyOwner; +``` + +### setHeimdallId + + +```solidity +function setHeimdallId(string memory _heimdallId) public onlyOwner; +``` + diff --git a/docs/autogen/src/contracts/root/RootChainProxy.sol/contract.RootChainProxy.md b/docs/autogen/src/contracts/root/RootChainProxy.sol/contract.RootChainProxy.md new file mode 100644 index 000000000..c94b541fb --- /dev/null +++ b/docs/autogen/src/contracts/root/RootChainProxy.sol/contract.RootChainProxy.md @@ -0,0 +1,15 @@ +# RootChainProxy +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/root/RootChainProxy.sol) + +**Inherits:** +[Proxy](/contracts/common/misc/Proxy.sol/contract.Proxy.md), [RootChainStorage](/contracts/root/RootChainStorage.sol/contract.RootChainStorage.md) + + +## Functions +### constructor + + +```solidity +constructor(address _proxyTo, address _registry, string memory _heimdallId) public Proxy(_proxyTo); +``` + diff --git a/docs/autogen/src/contracts/root/RootChainStorage.sol/contract.RootChainHeader.md b/docs/autogen/src/contracts/root/RootChainStorage.sol/contract.RootChainHeader.md new file mode 100644 index 000000000..7300eea8a --- /dev/null +++ b/docs/autogen/src/contracts/root/RootChainStorage.sol/contract.RootChainHeader.md @@ -0,0 +1,30 @@ +# RootChainHeader +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/root/RootChainStorage.sol) + + +## Events +### NewHeaderBlock + +```solidity +event NewHeaderBlock(address indexed proposer, uint256 indexed headerBlockId, uint256 indexed reward, uint256 start, uint256 end, bytes32 root); +``` + +### ResetHeaderBlock + +```solidity +event ResetHeaderBlock(address indexed proposer, uint256 indexed headerBlockId); +``` + +## Structs +### HeaderBlock + +```solidity +struct HeaderBlock { + bytes32 root; + uint256 start; + uint256 end; + uint256 createdAt; + address proposer; +} +``` + diff --git a/docs/autogen/src/contracts/root/RootChainStorage.sol/contract.RootChainStorage.md b/docs/autogen/src/contracts/root/RootChainStorage.sol/contract.RootChainStorage.md new file mode 100644 index 000000000..a85e443d1 --- /dev/null +++ b/docs/autogen/src/contracts/root/RootChainStorage.sol/contract.RootChainStorage.md @@ -0,0 +1,57 @@ +# RootChainStorage +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/root/RootChainStorage.sol) + +**Inherits:** +[ProxyStorage](/contracts/common/misc/ProxyStorage.sol/contract.ProxyStorage.md), [RootChainHeader](/contracts/root/RootChainStorage.sol/contract.RootChainHeader.md), [ChainIdMixin](/contracts/common/mixin/ChainIdMixin.sol/contract.ChainIdMixin.md) + + +## State Variables +### heimdallId + +```solidity +bytes32 public heimdallId; +``` + + +### VOTE_TYPE + +```solidity +uint8 public constant VOTE_TYPE = 2; +``` + + +### MAX_DEPOSITS + +```solidity +uint16 internal constant MAX_DEPOSITS = 10_000; +``` + + +### _nextHeaderBlock + +```solidity +uint256 public _nextHeaderBlock = MAX_DEPOSITS; +``` + + +### _blockDepositId + +```solidity +uint256 internal _blockDepositId = 1; +``` + + +### headerBlocks + +```solidity +mapping(uint256 => HeaderBlock) public headerBlocks; +``` + + +### registry + +```solidity +Registry internal registry; +``` + + diff --git a/docs/autogen/src/contracts/root/depositManager/DepositManager.sol/contract.DepositManager.md b/docs/autogen/src/contracts/root/depositManager/DepositManager.sol/contract.DepositManager.md new file mode 100644 index 000000000..1403e171b --- /dev/null +++ b/docs/autogen/src/contracts/root/depositManager/DepositManager.sol/contract.DepositManager.md @@ -0,0 +1,143 @@ +# DepositManager +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/root/depositManager/DepositManager.sol) + +**Inherits:** +[DepositManagerStorage](/contracts/root/depositManager/DepositManagerStorage.sol/contract.DepositManagerStorage.md), [IDepositManager](/contracts/root/depositManager/IDepositManager.sol/interface.IDepositManager.md), ERC721Holder + + +## Functions +### isTokenMapped + + +```solidity +modifier isTokenMapped(address _token); +``` + +### isPredicateAuthorized + + +```solidity +modifier isPredicateAuthorized(); +``` + +### constructor + + +```solidity +constructor() public GovernanceLockable(address(0x0)); +``` + +### function + + +```solidity +function() external payable; +``` + +### migrateMatic + + +```solidity +function migrateMatic(uint256 _amount) external onlyGovernance; +``` + +### _migrateMatic + + +```solidity +function _migrateMatic(uint256 _amount) private; +``` + +### updateMaxErc20Deposit + + +```solidity +function updateMaxErc20Deposit(uint256 maxDepositAmount) public onlyGovernance; +``` + +### transferAssets + + +```solidity +function transferAssets(address _token, address _user, uint256 _amountOrNFTId) external isPredicateAuthorized; +``` + +### depositERC20 + + +```solidity +function depositERC20(address _token, uint256 _amount) external; +``` + +### depositERC721 + + +```solidity +function depositERC721(address _token, uint256 _tokenId) external; +``` + +### depositBulk + + +```solidity +function depositBulk(address[] calldata _tokens, uint256[] calldata _amountOrTokens, address _user) external onlyWhenUnlocked; +``` + +### updateChildChainAndStateSender + +*Caches childChain and stateSender (frequently used variables) from registry* + + +```solidity +function updateChildChainAndStateSender() public; +``` + +### depositERC20ForUser + + +```solidity +function depositERC20ForUser(address _token, address _user, uint256 _amount) public; +``` + +### depositERC721ForUser + + +```solidity +function depositERC721ForUser(address _token, address _user, uint256 _tokenId) public; +``` + +### depositEther + + +```solidity +function depositEther() public payable; +``` + +### _safeCreateDepositBlock + + +```solidity +function _safeCreateDepositBlock(address _user, address _token, uint256 _amountOrToken) internal onlyWhenUnlocked isTokenMapped(_token); +``` + +### _createDepositBlock + + +```solidity +function _createDepositBlock(address _user, address _token, uint256 _amountOrToken, uint256 _depositId) internal; +``` + +### updateRootChain + + +```solidity +function updateRootChain(address _rootChain) public onlyOwner; +``` + +### _safeTransferERC721 + + +```solidity +function _safeTransferERC721(address _user, address _token, uint256 _tokenId) private; +``` + diff --git a/docs/autogen/src/contracts/root/depositManager/DepositManager.sol/interface.IPolygonMigration.md b/docs/autogen/src/contracts/root/depositManager/DepositManager.sol/interface.IPolygonMigration.md new file mode 100644 index 000000000..e172965f8 --- /dev/null +++ b/docs/autogen/src/contracts/root/depositManager/DepositManager.sol/interface.IPolygonMigration.md @@ -0,0 +1,12 @@ +# IPolygonMigration +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/root/depositManager/DepositManager.sol) + + +## Functions +### migrate + + +```solidity +function migrate(uint256 amount) external; +``` + diff --git a/docs/autogen/src/contracts/root/depositManager/DepositManagerProxy.sol/contract.DepositManagerProxy.md b/docs/autogen/src/contracts/root/depositManager/DepositManagerProxy.sol/contract.DepositManagerProxy.md new file mode 100644 index 000000000..c1d092829 --- /dev/null +++ b/docs/autogen/src/contracts/root/depositManager/DepositManagerProxy.sol/contract.DepositManagerProxy.md @@ -0,0 +1,15 @@ +# DepositManagerProxy +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/root/depositManager/DepositManagerProxy.sol) + +**Inherits:** +[Proxy](/contracts/common/misc/Proxy.sol/contract.Proxy.md), [DepositManagerStorage](/contracts/root/depositManager/DepositManagerStorage.sol/contract.DepositManagerStorage.md) + + +## Functions +### constructor + + +```solidity +constructor(address _proxyTo, address _registry, address _rootChain, address _governance) public Proxy(_proxyTo) GovernanceLockable(_governance); +``` + diff --git a/docs/autogen/src/contracts/root/depositManager/DepositManagerStorage.sol/contract.DepositManagerHeader.md b/docs/autogen/src/contracts/root/depositManager/DepositManagerStorage.sol/contract.DepositManagerHeader.md new file mode 100644 index 000000000..e64e0ee48 --- /dev/null +++ b/docs/autogen/src/contracts/root/depositManager/DepositManagerStorage.sol/contract.DepositManagerHeader.md @@ -0,0 +1,27 @@ +# DepositManagerHeader +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/root/depositManager/DepositManagerStorage.sol) + + +## Events +### NewDepositBlock + +```solidity +event NewDepositBlock(address indexed owner, address indexed token, uint256 amountOrNFTId, uint256 depositBlockId); +``` + +### MaxErc20DepositUpdate + +```solidity +event MaxErc20DepositUpdate(uint256 indexed oldLimit, uint256 indexed newLimit); +``` + +## Structs +### DepositBlock + +```solidity +struct DepositBlock { + bytes32 depositHash; + uint256 createdAt; +} +``` + diff --git a/docs/autogen/src/contracts/root/depositManager/DepositManagerStorage.sol/contract.DepositManagerStorage.md b/docs/autogen/src/contracts/root/depositManager/DepositManagerStorage.sol/contract.DepositManagerStorage.md new file mode 100644 index 000000000..041d9d52e --- /dev/null +++ b/docs/autogen/src/contracts/root/depositManager/DepositManagerStorage.sol/contract.DepositManagerStorage.md @@ -0,0 +1,50 @@ +# DepositManagerStorage +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/root/depositManager/DepositManagerStorage.sol) + +**Inherits:** +[ProxyStorage](/contracts/common/misc/ProxyStorage.sol/contract.ProxyStorage.md), [GovernanceLockable](/contracts/common/mixin/GovernanceLockable.sol/contract.GovernanceLockable.md), [DepositManagerHeader](/contracts/root/depositManager/DepositManagerStorage.sol/contract.DepositManagerHeader.md) + + +## State Variables +### registry + +```solidity +Registry public registry; +``` + + +### rootChain + +```solidity +RootChain public rootChain; +``` + + +### stateSender + +```solidity +StateSender public stateSender; +``` + + +### deposits + +```solidity +mapping(uint256 => DepositBlock) public deposits; +``` + + +### childChain + +```solidity +address public childChain; +``` + + +### maxErc20Deposit + +```solidity +uint256 public maxErc20Deposit = 100 * (10 ** 18); +``` + + diff --git a/docs/autogen/src/contracts/root/depositManager/IDepositManager.sol/interface.IDepositManager.md b/docs/autogen/src/contracts/root/depositManager/IDepositManager.sol/interface.IDepositManager.md new file mode 100644 index 000000000..ba3cce569 --- /dev/null +++ b/docs/autogen/src/contracts/root/depositManager/IDepositManager.sol/interface.IDepositManager.md @@ -0,0 +1,33 @@ +# IDepositManager +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/root/depositManager/IDepositManager.sol) + + +## Functions +### depositEther + + +```solidity +function depositEther() external payable; +``` + +### transferAssets + + +```solidity +function transferAssets(address _token, address _user, uint256 _amountOrNFTId) external; +``` + +### depositERC20 + + +```solidity +function depositERC20(address _token, uint256 _amount) external; +``` + +### depositERC721 + + +```solidity +function depositERC721(address _token, uint256 _tokenId) external; +``` + diff --git a/docs/autogen/src/contracts/root/depositManager/README.md b/docs/autogen/src/contracts/root/depositManager/README.md new file mode 100644 index 000000000..4f2574f83 --- /dev/null +++ b/docs/autogen/src/contracts/root/depositManager/README.md @@ -0,0 +1,9 @@ + + +# Contents +- [IPolygonMigration](DepositManager.sol/interface.IPolygonMigration.md) +- [DepositManager](DepositManager.sol/contract.DepositManager.md) +- [DepositManagerProxy](DepositManagerProxy.sol/contract.DepositManagerProxy.md) +- [DepositManagerHeader](DepositManagerStorage.sol/contract.DepositManagerHeader.md) +- [DepositManagerStorage](DepositManagerStorage.sol/contract.DepositManagerStorage.md) +- [IDepositManager](IDepositManager.sol/interface.IDepositManager.md) diff --git a/docs/autogen/src/contracts/root/predicates/ERC20Predicate.sol/contract.ERC20Predicate.md b/docs/autogen/src/contracts/root/predicates/ERC20Predicate.sol/contract.ERC20Predicate.md new file mode 100644 index 000000000..86e1d2f64 --- /dev/null +++ b/docs/autogen/src/contracts/root/predicates/ERC20Predicate.sol/contract.ERC20Predicate.md @@ -0,0 +1,302 @@ +# ERC20Predicate +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/root/predicates/ERC20Predicate.sol) + +**Inherits:** +[IErcPredicate](/contracts/root/predicates/IPredicate.sol/contract.IErcPredicate.md) + + +## State Variables +### DEPOSIT_EVENT_SIG + +```solidity +bytes32 constant DEPOSIT_EVENT_SIG = 0x4e2ca0515ed1aef1395f66b5303bb5d6f1bf9d61a353fa53f73f8ac9973fa9f6; +``` + + +### WITHDRAW_EVENT_SIG + +```solidity +bytes32 constant WITHDRAW_EVENT_SIG = 0xebff2602b3f468259e1e99f613fed6691f3a6526effe6ef3e768ba7ae7a36c4f; +``` + + +### LOG_TRANSFER_EVENT_SIG + +```solidity +bytes32 constant LOG_TRANSFER_EVENT_SIG = 0xe6497e3ee548a3372136af2fcb0696db31fc6cf20260707645068bd3fe97f3c4; +``` + + +### LOG_FEE_TRANSFER_EVENT_SIG + +```solidity +bytes32 constant LOG_FEE_TRANSFER_EVENT_SIG = 0x4dfe1bbbcf077ddc3e01291eea2d5c70c2b422b415d95645b9adcfd678cb1d63; +``` + + +### WITHDRAW_FUNC_SIG + +```solidity +bytes4 constant WITHDRAW_FUNC_SIG = 0x2e1a7d4d; +``` + + +### TRANSFER_FUNC_SIG + +```solidity +bytes4 constant TRANSFER_FUNC_SIG = 0xa9059cbb; +``` + + +### registry + +```solidity +Registry registry; +``` + + +## Functions +### constructor + + +```solidity +constructor(address _withdrawManager, address _depositManager, address _registry) public IErcPredicate(_withdrawManager, _depositManager); +``` + +### startExitWithBurntTokens + + +```solidity +function startExitWithBurntTokens(bytes calldata data) external; +``` + +### startExitForOutgoingErc20Transfer + +Start an exit by referencing the preceding (reference) transaction + + +```solidity +function startExitForOutgoingErc20Transfer(bytes calldata data, bytes calldata exitTx) external payable isBondProvided returns (address, uint256); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`data`|`bytes`|RLP encoded data of the reference tx (proof-of-funds of exitor) that encodes the following fields headerNumber Header block number of which the reference tx was a part of blockProof Proof that the block header (in the child chain) is a leaf in the submitted merkle root blockNumber Block number of which the reference tx is a part of blockTime Reference tx block time blocktxRoot Transactions root of block blockReceiptsRoot Receipts root of block receipt Receipt of the reference transaction receiptProof Merkle proof of the reference receipt branchMask Merkle proof branchMask for the receipt logIndex Log Index to read from the receipt| +|`exitTx`|`bytes`|Signed exit transaction (outgoing transfer or burn)| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`address`|address rootToken that the exit corresponds to| +|``|`uint256`|uint256 exitAmount| + + +### startExitForIncomingErc20Transfer + +Start an exit by referencing the preceding (reference) transaction + + +```solidity +function startExitForIncomingErc20Transfer(bytes calldata data, bytes calldata exitTx) external payable isBondProvided returns (address, uint256); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`data`|`bytes`|RLP encoded data of the reference tx(s) that encodes the following fields for each tx headerNumber Header block number of which the reference tx was a part of blockProof Proof that the block header (in the child chain) is a leaf in the submitted merkle root blockNumber Block number of which the reference tx is a part of blockTime Reference tx block time blocktxRoot Transactions root of block blockReceiptsRoot Receipts root of block receipt Receipt of the reference transaction receiptProof Merkle proof of the reference receipt branchMask Merkle proof branchMask for the receipt logIndex Log Index to read from the receipt| +|`exitTx`|`bytes`|Signed exit transaction (incoming transfer)| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`address`|address rootToken that the exit corresponds to| +|``|`uint256`|uint256 exitAmount| + + +### verifyDeprecation + +Verify the deprecation of a state update + + +```solidity +function verifyDeprecation(bytes calldata exit, bytes calldata inputUtxo, bytes calldata challengeData) external returns (bool); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`exit`|`bytes`|ABI encoded PlasmaExit data| +|`inputUtxo`|`bytes`|ABI encoded Input UTXO data| +|`challengeData`|`bytes`|RLP encoded data of the challenge reference tx that encodes the following fields headerNumber Header block number of which the reference tx was a part of blockProof Proof that the block header (in the child chain) is a leaf in the submitted merkle root blockNumber Block number of which the reference tx is a part of blockTime Reference tx block time blocktxRoot Transactions root of block blockReceiptsRoot Receipts root of block receipt Receipt of the reference transaction receiptProof Merkle proof of the reference receipt branchMask Merkle proof branchMask for the receipt logIndex Log Index to read from the receipt tx Challenge transaction txProof Merkle proof of the challenge tx| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bool`|Whether or not the state is deprecated| + + +### interpretStateUpdate + +Parse a ERC20 LogTransfer event in the receipt + + +```solidity +function interpretStateUpdate(bytes calldata state) external view returns (bytes memory); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`state`|`bytes`|abi encoded (data, participant, verifyInclusion) data is RLP encoded reference tx receipt that encodes the following fields headerNumber Header block number of which the reference tx was a part of blockProof Proof that the block header (in the child chain) is a leaf in the submitted merkle root blockNumber Block number of which the reference tx is a part of blockTime Reference tx block time blocktxRoot Transactions root of block blockReceiptsRoot Receipts root of block receipt Receipt of the reference transaction receiptProof Merkle proof of the reference receipt branchMask Merkle proof branchMask for the receipt logIndex Log Index to read from the receipt tx Challenge transaction txProof Merkle proof of the challenge tx| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bytes`|abi encoded (closingBalance, ageOfUtxo, childToken, rootToken)| + + +### processReferenceTx + +*Process the reference tx to start a MoreVP style exit* + + +```solidity +function processReferenceTx(bytes memory receipt, uint256 logIndex, address participant, bool isChallenge) + internal + view + returns (ReferenceTxData memory data); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`receipt`|`bytes`|Receipt of the reference transaction| +|`logIndex`|`uint256`|Log Index to read from the receipt| +|`participant`|`address`|Either of exitor or a counterparty depending on the type of exit| +|`isChallenge`|`bool`|Whether it is a challenge or start exit operation| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`data`|`ReferenceTxData`|ReferenceTxData Parsed reference tx data| + + +### validateSequential + + +```solidity +function validateSequential(ExitTxData memory exitTxData, ReferenceTxData memory referenceTxData) internal pure returns (uint256 exitAmount); +``` + +### processChallenge + + +```solidity +function processChallenge(RLPReader.RLPItem[] memory inputItems, address participant) internal pure; +``` + +### processStateUpdate + +Parse the state update and check if this predicate recognizes it + + +```solidity +function processStateUpdate(RLPReader.RLPItem[] memory inputItems, bytes memory logData, address participant) + internal + pure + returns (uint256 closingBalance, uint256 oIndex); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`inputItems`|`RLPReader.RLPItem[]`|inputItems[i] refers to i-th (0-based) topic in the topics array in the log| +|`logData`|`bytes`|Data field (unindexed params) in the log| +|`participant`|`address`|| + + +### processExitTx + +Process the transaction to start a MoreVP style exit from + + +```solidity +function processExitTx(bytes memory exitTx) internal view returns (ExitTxData memory txData); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`exitTx`|`bytes`|Signed exit transaction| + + +### processChallengeTx + +Process the challenge transaction + + +```solidity +function processChallengeTx(bytes memory exitTx) internal pure returns (ExitTxData memory txData); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`exitTx`|`bytes`|Challenge transaction| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`txData`|`ExitTxData`|ExitTxData Parsed challenge transaction data| + + +### processExitTxSender + +*Processes transaction from the "signer / sender" perspective* + + +```solidity +function processExitTxSender(bytes memory txData) internal pure returns (uint256 amount, ExitType exitType); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`txData`|`bytes`|Transaction input data| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`amount`|`uint256`|exitAmount Number of tokens burnt or sent| +|`exitType`|`ExitType`|burnt Whether the tokens were burnt| + + +### processExitTxCounterparty + +*Processes transaction from the "receiver" perspective* + + +```solidity +function processExitTxCounterparty(bytes memory txData) internal view returns (uint256 exitAmount); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`txData`|`bytes`|Transaction input data| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`exitAmount`|`uint256`|Number of tokens received| + + diff --git a/docs/autogen/src/contracts/root/predicates/ERC20PredicateBurnOnly.sol/contract.ERC20PredicateBurnOnly.md b/docs/autogen/src/contracts/root/predicates/ERC20PredicateBurnOnly.sol/contract.ERC20PredicateBurnOnly.md new file mode 100644 index 000000000..4005b926f --- /dev/null +++ b/docs/autogen/src/contracts/root/predicates/ERC20PredicateBurnOnly.sol/contract.ERC20PredicateBurnOnly.md @@ -0,0 +1,44 @@ +# ERC20PredicateBurnOnly +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/root/predicates/ERC20PredicateBurnOnly.sol) + +**Inherits:** +[IErcPredicate](/contracts/root/predicates/IPredicate.sol/contract.IErcPredicate.md) + + +## State Variables +### WITHDRAW_EVENT_SIG + +```solidity +bytes32 constant WITHDRAW_EVENT_SIG = 0xebff2602b3f468259e1e99f613fed6691f3a6526effe6ef3e768ba7ae7a36c4f; +``` + + +## Functions +### constructor + + +```solidity +constructor(address _withdrawManager, address _depositManager) public IErcPredicate(_withdrawManager, _depositManager); +``` + +### startExitWithBurntTokens + + +```solidity +function startExitWithBurntTokens(bytes calldata data) external; +``` + +### verifyDeprecation + + +```solidity +function verifyDeprecation(bytes calldata exit, bytes calldata inputUtxo, bytes calldata challengeData) external returns (bool); +``` + +### interpretStateUpdate + + +```solidity +function interpretStateUpdate(bytes calldata state) external view returns (bytes memory); +``` + diff --git a/docs/autogen/src/contracts/root/predicates/ERC721Predicate.sol/contract.ERC721Predicate.md b/docs/autogen/src/contracts/root/predicates/ERC721Predicate.sol/contract.ERC721Predicate.md new file mode 100644 index 000000000..73fda7d43 --- /dev/null +++ b/docs/autogen/src/contracts/root/predicates/ERC721Predicate.sol/contract.ERC721Predicate.md @@ -0,0 +1,215 @@ +# ERC721Predicate +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/root/predicates/ERC721Predicate.sol) + +**Inherits:** +[IErcPredicate](/contracts/root/predicates/IPredicate.sol/contract.IErcPredicate.md) + + +## State Variables +### DEPOSIT_EVENT_SIG + +```solidity +bytes32 constant DEPOSIT_EVENT_SIG = 0x5548c837ab068cf56a2c2479df0882a4922fd203edb7517321831d95078c5f62; +``` + + +### WITHDRAW_EVENT_SIG + +```solidity +bytes32 constant WITHDRAW_EVENT_SIG = 0x9b1bfa7fa9ee420a16e124f794c35ac9f90472acc99140eb2f6447c714cad8eb; +``` + + +### E721_LOG_TRANSFER_EVENT_SIG + +```solidity +bytes32 constant E721_LOG_TRANSFER_EVENT_SIG = 0x6eabe333476233fd382224f233210cb808a7bc4c4de64f9d76628bf63c677b1a; +``` + + +### WITHDRAW_FUNC_SIG + +```solidity +bytes4 constant WITHDRAW_FUNC_SIG = 0x2e1a7d4d; +``` + + +### TRANSFER_FROM_FUNC_SIG + +```solidity +bytes4 constant TRANSFER_FROM_FUNC_SIG = 0x23b872dd; +``` + + +## Functions +### constructor + + +```solidity +constructor(address _withdrawManager, address _depositManager) public IErcPredicate(_withdrawManager, _depositManager); +``` + +### verifyDeprecation + +Verify the deprecation of a state update + + +```solidity +function verifyDeprecation(bytes calldata exit, bytes calldata inputUtxo, bytes calldata challengeData) external returns (bool); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`exit`|`bytes`|ABI encoded PlasmaExit data| +|`inputUtxo`|`bytes`|ABI encoded Input UTXO data| +|`challengeData`|`bytes`|RLP encoded data of the challenge reference tx that encodes the following fields headerNumber Header block number of which the reference tx was a part of blockProof Proof that the block header (in the child chain) is a leaf in the submitted merkle root blockNumber Block number of which the reference tx is a part of blockTime Reference tx block time blocktxRoot Transactions root of block blockReceiptsRoot Receipts root of block receipt Receipt of the reference transaction receiptProof Merkle proof of the reference receipt branchMask Merkle proof branchMask for the receipt logIndex Log Index to read from the receipt tx Challenge transaction txProof Merkle proof of the challenge tx| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bool`|Whether or not the state is deprecated| + + +### interpretStateUpdate + + +```solidity +function interpretStateUpdate(bytes calldata state) external view returns (bytes memory b); +``` + +### startExitWithBurntTokens + + +```solidity +function startExitWithBurntTokens(bytes memory data) public returns (bytes memory); +``` + +### startExit + +Start an exit by referencing the preceding (reference) transaction + + +```solidity +function startExit(bytes memory data, bytes memory exitTx) public payable isBondProvided returns (bytes memory); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`data`|`bytes`|RLP encoded data of the reference tx(s) that encodes the following fields for each tx headerNumber Header block number of which the reference tx was a part of blockProof Proof that the block header (in the child chain) is a leaf in the submitted merkle root blockNumber Block number of which the reference tx is a part of blockTime Reference tx block time blocktxRoot Transactions root of block blockReceiptsRoot Receipts root of block receipt Receipt of the reference transaction receiptProof Merkle proof of the reference receipt branchMask Merkle proof branchMask for the receipt logIndex Log Index to read from the receipt| +|`exitTx`|`bytes`|Signed exit transaction| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bytes`|abi encoded bytes array that encodes the following fields address rootToken: Token that the exit corresponds to uint256 tokenId: TokenId being exited address childToken: Child token that the exit corresponds to uint256 exitId| + + +### processReferenceTx + +Process the reference tx to start a MoreVP style exit + + +```solidity +function processReferenceTx(bytes memory receipt, uint256 logIndex, address participant, address childToken, uint256 tokenId, bool isChallenge) + internal + pure + returns (address rootToken, uint256 oIndex); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`receipt`|`bytes`|Receipt of the reference transaction| +|`logIndex`|`uint256`|Log Index to read from the receipt| +|`participant`|`address`|Either of exitor or a counterparty depending on the type of exit| +|`childToken`|`address`|| +|`tokenId`|`uint256`|| +|`isChallenge`|`bool`|| + + +### processStateUpdate + +Parse the state update and check if this predicate recognizes it + + +```solidity +function processStateUpdate(RLPReader.RLPItem[] memory inputItems, address participant) internal pure returns (uint256 oIndex); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`inputItems`|`RLPReader.RLPItem[]`|inputItems[i] refers to i-th (0-based) topic in the topics array in the log| +|`participant`|`address`|| + + +### processChallenge + +Parse the state update and check if this predicate recognizes it + + +```solidity +function processChallenge(RLPReader.RLPItem[] memory inputItems, address participant) internal pure; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`inputItems`|`RLPReader.RLPItem[]`|inputItems[i] refers to i-th (0-based) topic in the topics array in the log| +|`participant`|`address`|| + + +### processExitTx + +Process the transaction to start a MoreVP style exit from + + +```solidity +function processExitTx(bytes memory exitTx) internal view returns (ExitTxData memory txData); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`exitTx`|`bytes`|Signed exit transaction| + + +### processChallengeTx + +Process the challenge transaction + + +```solidity +function processChallengeTx(bytes memory challengeTx) internal pure returns (ExitTxData memory txData); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`challengeTx`|`bytes`|Challenge transaction| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`txData`|`ExitTxData`|ExitTxData Parsed challenge transaction data| + + +### processExitTxSender + + +```solidity +function processExitTxSender(bytes memory txData) internal pure returns (uint256 tokenId, ExitType exitType); +``` + +### processExitTxCounterparty + + +```solidity +function processExitTxCounterparty(bytes memory txData) internal view returns (uint256 tokenId); +``` + diff --git a/docs/autogen/src/contracts/root/predicates/ERC721PredicateBurnOnly.sol/contract.ERC721PredicateBurnOnly.md b/docs/autogen/src/contracts/root/predicates/ERC721PredicateBurnOnly.sol/contract.ERC721PredicateBurnOnly.md new file mode 100644 index 000000000..2057ffb68 --- /dev/null +++ b/docs/autogen/src/contracts/root/predicates/ERC721PredicateBurnOnly.sol/contract.ERC721PredicateBurnOnly.md @@ -0,0 +1,44 @@ +# ERC721PredicateBurnOnly +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/root/predicates/ERC721PredicateBurnOnly.sol) + +**Inherits:** +[IErcPredicate](/contracts/root/predicates/IPredicate.sol/contract.IErcPredicate.md) + + +## State Variables +### WITHDRAW_EVENT_SIG + +```solidity +bytes32 constant WITHDRAW_EVENT_SIG = 0x9b1bfa7fa9ee420a16e124f794c35ac9f90472acc99140eb2f6447c714cad8eb; +``` + + +## Functions +### constructor + + +```solidity +constructor(address _withdrawManager, address _depositManager) public IErcPredicate(_withdrawManager, _depositManager); +``` + +### verifyDeprecation + + +```solidity +function verifyDeprecation(bytes calldata exit, bytes calldata inputUtxo, bytes calldata challengeData) external returns (bool); +``` + +### interpretStateUpdate + + +```solidity +function interpretStateUpdate(bytes calldata state) external view returns (bytes memory b); +``` + +### startExitWithBurntTokens + + +```solidity +function startExitWithBurntTokens(bytes memory data) public returns (bytes memory); +``` + diff --git a/docs/autogen/src/contracts/root/predicates/IPredicate.sol/contract.IErcPredicate.md b/docs/autogen/src/contracts/root/predicates/IPredicate.sol/contract.IErcPredicate.md new file mode 100644 index 000000000..86a12e275 --- /dev/null +++ b/docs/autogen/src/contracts/root/predicates/IPredicate.sol/contract.IErcPredicate.md @@ -0,0 +1,59 @@ +# IErcPredicate +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/root/predicates/IPredicate.sol) + +**Inherits:** +[IPredicate](/contracts/root/predicates/IPredicate.sol/interface.IPredicate.md), [PredicateUtils](/contracts/root/predicates/IPredicate.sol/contract.PredicateUtils.md) + + +## State Variables +### MAX_LOGS + +```solidity +uint256 internal constant MAX_LOGS = 10; +``` + + +## Functions +### constructor + + +```solidity +constructor(address _withdrawManager, address _depositManager) public; +``` + +## Structs +### ExitTxData + +```solidity +struct ExitTxData { + uint256 amountOrToken; + bytes32 txHash; + address childToken; + address signer; + ExitType exitType; +} +``` + +### ReferenceTxData + +```solidity +struct ReferenceTxData { + uint256 closingBalance; + uint256 age; + address childToken; + address rootToken; +} +``` + +## Enums +### ExitType + +```solidity +enum ExitType { + Invalid, + OutgoingTransfer, + IncomingTransfer, + Burnt +} +``` + diff --git a/docs/autogen/src/contracts/root/predicates/IPredicate.sol/contract.PredicateUtils.md b/docs/autogen/src/contracts/root/predicates/IPredicate.sol/contract.PredicateUtils.md new file mode 100644 index 000000000..ca1d8bd33 --- /dev/null +++ b/docs/autogen/src/contracts/root/predicates/IPredicate.sol/contract.PredicateUtils.md @@ -0,0 +1,86 @@ +# PredicateUtils +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/root/predicates/IPredicate.sol) + +**Inherits:** +[ExitsDataStructure](/contracts/root/withdrawManager/WithdrawManagerStorage.sol/contract.ExitsDataStructure.md), [ChainIdMixin](/contracts/common/mixin/ChainIdMixin.sol/contract.ChainIdMixin.md) + + +## State Variables +### BOND_AMOUNT + +```solidity +uint256 private constant BOND_AMOUNT = 10 ** 17; +``` + + +### withdrawManager + +```solidity +IWithdrawManager internal withdrawManager; +``` + + +### depositManager + +```solidity +IDepositManager internal depositManager; +``` + + +## Functions +### onlyWithdrawManager + + +```solidity +modifier onlyWithdrawManager(); +``` + +### isBondProvided + + +```solidity +modifier isBondProvided(); +``` + +### onFinalizeExit + + +```solidity +function onFinalizeExit(bytes calldata data) external onlyWithdrawManager; +``` + +### sendBond + + +```solidity +function sendBond() internal; +``` + +### getAddressFromTx + + +```solidity +function getAddressFromTx(RLPReader.RLPItem[] memory txList) internal pure returns (address signer, bytes32 txHash); +``` + +### decodeExit + + +```solidity +function decodeExit(bytes memory data) internal pure returns (PlasmaExit memory); +``` + +### decodeExitForProcessExit + + +```solidity +function decodeExitForProcessExit(bytes memory data) internal pure returns (uint256 exitId, address token, address exitor, uint256 tokenId); +``` + +### decodeInputUtxo + + +```solidity +function decodeInputUtxo(bytes memory data) internal pure returns (uint256 age, address signer, address predicate, address token); +``` + diff --git a/docs/autogen/src/contracts/root/predicates/IPredicate.sol/interface.IPredicate.md b/docs/autogen/src/contracts/root/predicates/IPredicate.sol/interface.IPredicate.md new file mode 100644 index 000000000..01c5149ca --- /dev/null +++ b/docs/autogen/src/contracts/root/predicates/IPredicate.sol/interface.IPredicate.md @@ -0,0 +1,42 @@ +# IPredicate +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/root/predicates/IPredicate.sol) + + +## Functions +### verifyDeprecation + +Verify the deprecation of a state update + + +```solidity +function verifyDeprecation(bytes calldata exit, bytes calldata inputUtxo, bytes calldata challengeData) external returns (bool); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`exit`|`bytes`|ABI encoded PlasmaExit data| +|`inputUtxo`|`bytes`|ABI encoded Input UTXO data| +|`challengeData`|`bytes`|RLP encoded data of the challenge reference tx that encodes the following fields headerNumber Header block number of which the reference tx was a part of blockProof Proof that the block header (in the child chain) is a leaf in the submitted merkle root blockNumber Block number of which the reference tx is a part of blockTime Reference tx block time blocktxRoot Transactions root of block blockReceiptsRoot Receipts root of block receipt Receipt of the reference transaction receiptProof Merkle proof of the reference receipt branchMask Merkle proof branchMask for the receipt logIndex Log Index to read from the receipt tx Challenge transaction txProof Merkle proof of the challenge tx| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bool`|Whether or not the state is deprecated| + + +### interpretStateUpdate + + +```solidity +function interpretStateUpdate(bytes calldata state) external view returns (bytes memory); +``` + +### onFinalizeExit + + +```solidity +function onFinalizeExit(bytes calldata data) external; +``` + diff --git a/docs/autogen/src/contracts/root/predicates/MarketplacePredicate.sol/contract.MarketplacePredicate.md b/docs/autogen/src/contracts/root/predicates/MarketplacePredicate.sol/contract.MarketplacePredicate.md new file mode 100644 index 000000000..186130a94 --- /dev/null +++ b/docs/autogen/src/contracts/root/predicates/MarketplacePredicate.sol/contract.MarketplacePredicate.md @@ -0,0 +1,179 @@ +# MarketplacePredicate +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/root/predicates/MarketplacePredicate.sol) + +**Inherits:** +[PredicateUtils](/contracts/root/predicates/IPredicate.sol/contract.PredicateUtils.md) + + +## State Variables +### EXECUTE_ORDER_FUNC_SIG + +```solidity +bytes4 constant EXECUTE_ORDER_FUNC_SIG = 0xe660b9e4; +``` + + +### registry + +```solidity +Registry public registry; +``` + + +### rootChain + +```solidity +IRootChain public rootChain; +``` + + +## Functions +### constructor + + +```solidity +constructor(address _rootChain, address _withdrawManager, address _registry) public; +``` + +### startExit + +Start an exit from in-flight marketplace tx + + +```solidity +function startExit(bytes calldata data, bytes calldata exitTx) external payable isBondProvided; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`data`|`bytes`|RLP encoded array of input utxos data[n] ( 1 < n <= 3) is abi encoded as (predicateAddress, RLP encoded reference tx) data[n][1] is RLP encoded reference tx that encodes the following fields headerNumber Header block number of which the reference tx was a part of blockProof Proof that the block header (in the child chain) is a leaf in the submitted merkle root blockNumber Block number of which the reference tx is a part of blockTime Reference tx block time blocktxRoot Transactions root of block blockReceiptsRoot Receipts root of block receipt Receipt of the reference transaction receiptProof Merkle proof of the reference receipt branchMask Merkle proof branchMask for the receipt logIndex Log Index to read from the receipt data[2] is the child token that the user wishes to start an exit for| +|`exitTx`|`bytes`| Signed (marketplace.executeOrder) exit transaction| + + +### verifyDeprecation + +Verify the deprecation of a state update + + +```solidity +function verifyDeprecation(bytes calldata exit, bytes calldata inputUtxo, bytes calldata challengeData) external view returns (bool); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`exit`|`bytes`|ABI encoded PlasmaExit data| +|`inputUtxo`|`bytes`|ABI encoded Input UTXO data| +|`challengeData`|`bytes`|RLP encoded data of the challenge reference tx that encodes the following fields headerNumber Header block number of which the reference tx was a part of blockProof Proof that the block header (in the child chain) is a leaf in the submitted merkle root blockNumber Block number of which the reference tx is a part of blockTime Reference tx block time blocktxRoot Transactions root of block blockReceiptsRoot Receipts root of block receipt Receipt of the reference transaction receiptProof Merkle proof of the reference receipt branchMask Merkle proof branchMask for the receipt logIndex Log Index to read from the receipt tx Challenge transaction txProof Merkle proof of the challenge tx| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bool`|Whether or not the state is deprecated| + + +### getChildBlockNumberFromAge + + +```solidity +function getChildBlockNumberFromAge(uint256 age) internal pure returns (uint256); +``` + +### validateTokenBalance + + +```solidity +function validateTokenBalance(address childToken, address _childToken, uint256 closingBalance, uint256 amount) internal view; +``` + +### processLogTransferReceipt + + +```solidity +function processLogTransferReceipt(address predicate, bytes memory preState, address participant, bool verifyInclusionInCheckpoint, bool isChallenge) + internal + view + returns (ReferenceTxData memory _referenceTx); +``` + +### processExitTx + + +```solidity +function processExitTx(bytes memory exitTx, address tradeParticipant) internal pure returns (ExitTxData memory txData); +``` + +### verifySignatures + + +```solidity +function verifySignatures(ExecuteOrderData memory executeOrder, address marketplaceContract, address tradeParticipant) + internal + pure + returns (ExitTxData memory); +``` + +### decodeExecuteOrder + + +```solidity +function decodeExecuteOrder(bytes memory orderData) internal pure returns (bytes4 funcSig, ExecuteOrderData memory order); +``` + +### decodeOrder + + +```solidity +function decodeOrder(bytes memory data) internal pure returns (Order memory order); +``` + +## Structs +### ExecuteOrderData + +```solidity +struct ExecuteOrderData { + bytes data1; + bytes data2; + bytes32 orderId; + uint256 expiration; + address taker; +} +``` + +### Order + +```solidity +struct Order { + address token; + bytes sig; + uint256 amount; +} +``` + +### ExitTxData + +```solidity +struct ExitTxData { + uint256 amount1; + uint256 amount2; + address token1; + address token2; + address counterParty; + bytes32 txHash; + uint256 expiration; +} +``` + +### ReferenceTxData + +```solidity +struct ReferenceTxData { + uint256 closingBalance; + uint256 age; + address childToken; + address rootToken; +} +``` + diff --git a/docs/autogen/src/contracts/root/predicates/MintableERC721Predicate.sol/contract.MintableERC721Predicate.md b/docs/autogen/src/contracts/root/predicates/MintableERC721Predicate.sol/contract.MintableERC721Predicate.md new file mode 100644 index 000000000..99a702877 --- /dev/null +++ b/docs/autogen/src/contracts/root/predicates/MintableERC721Predicate.sol/contract.MintableERC721Predicate.md @@ -0,0 +1,135 @@ +# MintableERC721Predicate +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/root/predicates/MintableERC721Predicate.sol) + +**Inherits:** +[ERC721Predicate](/contracts/root/predicates/ERC721Predicate.sol/contract.ERC721Predicate.md) + + +## State Variables +### exitToMintableTokenInfo + +```solidity +mapping(uint256 => MintableTokenInfo) public exitToMintableTokenInfo; +``` + + +## Functions +### constructor + + +```solidity +constructor(address _withdrawManager, address _depositManager) public ERC721Predicate(_withdrawManager, _depositManager); +``` + +### startExitForMintableBurntToken + +Start an exit for a token that was minted and burnt on the side chain + + +```solidity +function startExitForMintableBurntToken(bytes calldata data, bytes calldata mintTx) external; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`data`|`bytes`|RLP encoded data of the burn tx| +|`mintTx`|`bytes`|Signed mint transaction| + + +### startExitForMintableToken + +Start a MoreVP style exit for a token that was minted on the side chain + + +```solidity +function startExitForMintableToken(bytes calldata data, bytes calldata mintTx, bytes calldata exitTx) external payable; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`data`|`bytes`|RLP encoded data of the burn tx| +|`mintTx`|`bytes`|Signed mint transaction| +|`exitTx`|`bytes`|| + + +### startExitForMetadataMintableBurntToken + +Start an exit for a token with metadata that was minted and burnt on the side chain + + +```solidity +function startExitForMetadataMintableBurntToken(bytes calldata data, bytes calldata mintTx) external; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`data`|`bytes`|RLP encoded data of the burn tx| +|`mintTx`|`bytes`|Signed mint transaction| + + +### startExitForMetadataMintableToken + +Start a MoreVP style exit for a token with metadata that was minted on the side chain + + +```solidity +function startExitForMetadataMintableToken(bytes calldata data, bytes calldata mintTx, bytes calldata exitTx) external payable; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`data`|`bytes`|RLP encoded data of the burn tx| +|`mintTx`|`bytes`|Signed mint transaction| +|`exitTx`|`bytes`|Signed exit transaction| + + +### onFinalizeExit + + +```solidity +function onFinalizeExit(bytes calldata data) external onlyWithdrawManager; +``` + +### processMint + + +```solidity +function processMint(bytes memory mintTx, address rootToken, uint256 tokenId, address childToken, uint256 exitId) internal; +``` + +### _processRawMint + + +```solidity +function _processRawMint(bytes memory txData, uint256 tokenId) internal pure; +``` + +### processMintWithTokenURI + + +```solidity +function processMintWithTokenURI(bytes memory mintTx, address rootToken, uint256 tokenId, address childToken, uint256 exitId) internal; +``` + +### _processRawMintWithTokenURI + + +```solidity +function _processRawMintWithTokenURI(bytes memory txData, uint256 tokenId) internal pure returns (string memory uri); +``` + +## Structs +### MintableTokenInfo + +```solidity +struct MintableTokenInfo { + string uri; + address minter; + bool isVanillaMint; +} +``` + diff --git a/docs/autogen/src/contracts/root/predicates/README.md b/docs/autogen/src/contracts/root/predicates/README.md new file mode 100644 index 000000000..87cec9a7c --- /dev/null +++ b/docs/autogen/src/contracts/root/predicates/README.md @@ -0,0 +1,14 @@ + + +# Contents +- [ERC20Predicate](ERC20Predicate.sol/contract.ERC20Predicate.md) +- [ERC20PredicateBurnOnly](ERC20PredicateBurnOnly.sol/contract.ERC20PredicateBurnOnly.md) +- [ERC721Predicate](ERC721Predicate.sol/contract.ERC721Predicate.md) +- [ERC721PredicateBurnOnly](ERC721PredicateBurnOnly.sol/contract.ERC721PredicateBurnOnly.md) +- [IPredicate](IPredicate.sol/interface.IPredicate.md) +- [PredicateUtils](IPredicate.sol/contract.PredicateUtils.md) +- [IErcPredicate](IPredicate.sol/contract.IErcPredicate.md) +- [MarketplacePredicate](MarketplacePredicate.sol/contract.MarketplacePredicate.md) +- [MintableERC721Predicate](MintableERC721Predicate.sol/contract.MintableERC721Predicate.md) +- [TransferWithSigPredicate](TransferWithSigPredicate.sol/contract.TransferWithSigPredicate.md) +- [TransferWithSigUtils](TransferWithSigUtils.sol/library.TransferWithSigUtils.md) diff --git a/docs/autogen/src/contracts/root/predicates/TransferWithSigPredicate.sol/contract.TransferWithSigPredicate.md b/docs/autogen/src/contracts/root/predicates/TransferWithSigPredicate.sol/contract.TransferWithSigPredicate.md new file mode 100644 index 000000000..980124247 --- /dev/null +++ b/docs/autogen/src/contracts/root/predicates/TransferWithSigPredicate.sol/contract.TransferWithSigPredicate.md @@ -0,0 +1,154 @@ +# TransferWithSigPredicate +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/root/predicates/TransferWithSigPredicate.sol) + +**Inherits:** +[PredicateUtils](/contracts/root/predicates/IPredicate.sol/contract.PredicateUtils.md) + + +## State Variables +### TRANSFER_WITH_SIG_FUNC_SIG + +```solidity +bytes4 constant TRANSFER_WITH_SIG_FUNC_SIG = 0x19d27d9c; +``` + + +### registry + +```solidity +Registry public registry; +``` + + +### rootChain + +```solidity +IRootChain public rootChain; +``` + + +## Functions +### constructor + + +```solidity +constructor(address _rootChain, address _withdrawManager, address _registry) public; +``` + +### startExitForOutgoingErc20Transfer + +Start an exit from in-flight transferWithSig tx while referencing the exitor's pre-existing balance on the chain for the token + + +```solidity +function startExitForOutgoingErc20Transfer(bytes calldata data, bytes calldata exitTx) external payable isBondProvided; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`data`|`bytes`|RLP encoded array of 1 input utxo (data format is to keep it consistent with other startExit methods) data[0] should be the exitor's proof-of-funds and encodes the following fields headerNumber Header block number of which the reference tx was a part of blockProof Proof that the block header (in the child chain) is a leaf in the submitted merkle root blockNumber Block number of which the reference tx is a part of blockTime Reference tx block time blocktxRoot Transactions root of block blockReceiptsRoot Receipts root of block receipt Receipt of the reference transaction receiptProof Merkle proof of the reference receipt branchMask Merkle proof branchMask for the receipt logIndex Log Index to read from the receipt| +|`exitTx`|`bytes`|ERC20 transfer executed using a transferWithSig| + + +### startExitForIncomingErc20Transfer + +Start an exit from in-flight transferWithSig tx while also referencing the exitor's pre-existing balance on the chain for the token + + +```solidity +function startExitForIncomingErc20Transfer(bytes calldata data, bytes calldata exitTx) external payable isBondProvided; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`data`|`bytes`|RLP encoded array of 2 input utxos data[0] should be the counterparty's proof-of-funds data[1] should be the exitor's proof-of-funds data[n] encodes the following fields headerNumber Header block number of which the reference tx was a part of blockProof Proof that the block header (in the child chain) is a leaf in the submitted merkle root blockNumber Block number of which the reference tx is a part of blockTime Reference tx block time blocktxRoot Transactions root of block blockReceiptsRoot Receipts root of block receipt Receipt of the reference transaction receiptProof Merkle proof of the reference receipt branchMask Merkle proof branchMask for the receipt logIndex Log Index to read from the receipt| +|`exitTx`|`bytes`|ERC20 transfer executed using a transferWithSig| + + +### verifyDeprecation + +Verify the deprecation of a state update + + +```solidity +function verifyDeprecation(bytes calldata exit, bytes calldata inputUtxo, bytes calldata challengeData) external view returns (bool); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`exit`|`bytes`|ABI encoded PlasmaExit data| +|`inputUtxo`|`bytes`|ABI encoded Input UTXO data| +|`challengeData`|`bytes`|RLP encoded data of the challenge reference tx that encodes the following fields headerNumber Header block number of which the reference tx was a part of blockProof Proof that the block header (in the child chain) is a leaf in the submitted merkle root blockNumber Block number of which the reference tx is a part of blockTime Reference tx block time blocktxRoot Transactions root of block blockReceiptsRoot Receipts root of block receipt Receipt of the reference transaction receiptProof Merkle proof of the reference receipt branchMask Merkle proof branchMask for the receipt logIndex Log Index to read from the receipt tx Challenge transaction txProof Merkle proof of the challenge tx| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bool`|Whether or not the state is deprecated| + + +### getChildBlockNumberFromAge + + +```solidity +function getChildBlockNumberFromAge(uint256 age) internal pure returns (uint256); +``` + +### processLogTransferReceipt + + +```solidity +function processLogTransferReceipt(address predicate, bytes memory preState, address participant, bool verifyInclusionInCheckpoint, bool isChallenge) + internal + view + returns (ReferenceTxData memory _referenceTx); +``` + +### processExitTx + +Process the challenge transaction + + +```solidity +function processExitTx(bytes memory exitTx) internal pure returns (ExitTxData memory txData, uint256 expiration); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`exitTx`|`bytes`|Challenge transaction| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`txData`|`ExitTxData`|ExitTxData Parsed challenge transaction data| +|`expiration`|`uint256`|| + + +## Structs +### ReferenceTxData + +```solidity +struct ReferenceTxData { + uint256 closingBalance; + uint256 age; + address childToken; + address rootToken; +} +``` + +### ExitTxData + +```solidity +struct ExitTxData { + uint256 amountOrToken; + bytes32 txHash; + address childToken; + address signer; +} +``` + diff --git a/docs/autogen/src/contracts/root/predicates/TransferWithSigUtils.sol/library.TransferWithSigUtils.md b/docs/autogen/src/contracts/root/predicates/TransferWithSigUtils.sol/library.TransferWithSigUtils.md new file mode 100644 index 000000000..1b7eb8992 --- /dev/null +++ b/docs/autogen/src/contracts/root/predicates/TransferWithSigUtils.sol/library.TransferWithSigUtils.md @@ -0,0 +1,26 @@ +# TransferWithSigUtils +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/root/predicates/TransferWithSigUtils.sol) + + +## Functions +### getTokenTransferOrderHash + + +```solidity +function getTokenTransferOrderHash(address token, address spender, uint256 amount, bytes32 data, uint256 expiration) public pure returns (bytes32 orderHash); +``` + +### hashTokenTransferOrder + + +```solidity +function hashTokenTransferOrder(address spender, uint256 amount, bytes32 data, uint256 expiration) internal pure returns (bytes32 result); +``` + +### hashEIP712Message + + +```solidity +function hashEIP712Message(address token, bytes32 hashStruct) internal pure returns (bytes32 result); +``` + diff --git a/docs/autogen/src/contracts/root/stateSyncer/README.md b/docs/autogen/src/contracts/root/stateSyncer/README.md new file mode 100644 index 000000000..fedaaa0ed --- /dev/null +++ b/docs/autogen/src/contracts/root/stateSyncer/README.md @@ -0,0 +1,4 @@ + + +# Contents +- [StateSender](StateSender.sol/contract.StateSender.md) diff --git a/docs/autogen/src/contracts/root/stateSyncer/StateSender.sol/contract.StateSender.md b/docs/autogen/src/contracts/root/stateSyncer/StateSender.sol/contract.StateSender.md new file mode 100644 index 000000000..cbac4f8d8 --- /dev/null +++ b/docs/autogen/src/contracts/root/stateSyncer/StateSender.sol/contract.StateSender.md @@ -0,0 +1,63 @@ +# StateSender +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/root/stateSyncer/StateSender.sol) + +**Inherits:** +Ownable + + +## State Variables +### counter + +```solidity +uint256 public counter; +``` + + +### registrations + +```solidity +mapping(address => address) public registrations; +``` + + +## Functions +### onlyRegistered + + +```solidity +modifier onlyRegistered(address receiver); +``` + +### syncState + + +```solidity +function syncState(address receiver, bytes calldata data) external onlyRegistered(receiver); +``` + +### register + + +```solidity +function register(address sender, address receiver) public; +``` + +## Events +### NewRegistration + +```solidity +event NewRegistration(address indexed user, address indexed sender, address indexed receiver); +``` + +### RegistrationUpdated + +```solidity +event RegistrationUpdated(address indexed user, address indexed sender, address indexed receiver); +``` + +### StateSynced + +```solidity +event StateSynced(uint256 indexed id, address indexed contractAddress, bytes data); +``` + diff --git a/docs/autogen/src/contracts/root/withdrawManager/ExitNFT.sol/contract.ExitNFT.md b/docs/autogen/src/contracts/root/withdrawManager/ExitNFT.sol/contract.ExitNFT.md new file mode 100644 index 000000000..c01476b48 --- /dev/null +++ b/docs/autogen/src/contracts/root/withdrawManager/ExitNFT.sol/contract.ExitNFT.md @@ -0,0 +1,51 @@ +# ExitNFT +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/root/withdrawManager/ExitNFT.sol) + +**Inherits:** +ERC721 + + +## State Variables +### registry + +```solidity +Registry internal registry; +``` + + +## Functions +### onlyWithdrawManager + + +```solidity +modifier onlyWithdrawManager(); +``` + +### constructor + + +```solidity +constructor(address _registry) public; +``` + +### mint + + +```solidity +function mint(address _owner, uint256 _tokenId) external onlyWithdrawManager; +``` + +### burn + + +```solidity +function burn(uint256 _tokenId) external onlyWithdrawManager; +``` + +### exists + + +```solidity +function exists(uint256 tokenId) public view returns (bool); +``` + diff --git a/docs/autogen/src/contracts/root/withdrawManager/IWithdrawManager.sol/contract.IWithdrawManager.md b/docs/autogen/src/contracts/root/withdrawManager/IWithdrawManager.sol/contract.IWithdrawManager.md new file mode 100644 index 000000000..43cb154ee --- /dev/null +++ b/docs/autogen/src/contracts/root/withdrawManager/IWithdrawManager.sol/contract.IWithdrawManager.md @@ -0,0 +1,48 @@ +# IWithdrawManager +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/root/withdrawManager/IWithdrawManager.sol) + + +## Functions +### createExitQueue + + +```solidity +function createExitQueue(address token) external; +``` + +### verifyInclusion + + +```solidity +function verifyInclusion(bytes calldata data, uint8 offset, bool verifyTxInclusion) external view returns (uint256 age); +``` + +### addExitToQueue + + +```solidity +function addExitToQueue( + address exitor, + address childToken, + address rootToken, + uint256 exitAmountOrTokenId, + bytes32 txHash, + bool isRegularExit, + uint256 priority +) external; +``` + +### addInput + + +```solidity +function addInput(uint256 exitId, uint256 age, address utxoOwner, address token) external; +``` + +### challengeExit + + +```solidity +function challengeExit(uint256 exitId, uint256 inputId, bytes calldata challengeData, address adjudicatorPredicate) external; +``` + diff --git a/docs/autogen/src/contracts/root/withdrawManager/README.md b/docs/autogen/src/contracts/root/withdrawManager/README.md new file mode 100644 index 000000000..cb629c15c --- /dev/null +++ b/docs/autogen/src/contracts/root/withdrawManager/README.md @@ -0,0 +1,10 @@ + + +# Contents +- [ExitNFT](ExitNFT.sol/contract.ExitNFT.md) +- [IWithdrawManager](IWithdrawManager.sol/contract.IWithdrawManager.md) +- [WithdrawManager](WithdrawManager.sol/contract.WithdrawManager.md) +- [WithdrawManagerProxy](WithdrawManagerProxy.sol/contract.WithdrawManagerProxy.md) +- [ExitsDataStructure](WithdrawManagerStorage.sol/contract.ExitsDataStructure.md) +- [WithdrawManagerHeader](WithdrawManagerStorage.sol/contract.WithdrawManagerHeader.md) +- [WithdrawManagerStorage](WithdrawManagerStorage.sol/contract.WithdrawManagerStorage.md) diff --git a/docs/autogen/src/contracts/root/withdrawManager/WithdrawManager.sol/contract.WithdrawManager.md b/docs/autogen/src/contracts/root/withdrawManager/WithdrawManager.sol/contract.WithdrawManager.md new file mode 100644 index 000000000..8c7976c23 --- /dev/null +++ b/docs/autogen/src/contracts/root/withdrawManager/WithdrawManager.sol/contract.WithdrawManager.md @@ -0,0 +1,224 @@ +# WithdrawManager +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/root/withdrawManager/WithdrawManager.sol) + +**Inherits:** +[WithdrawManagerStorage](/contracts/root/withdrawManager/WithdrawManagerStorage.sol/contract.WithdrawManagerStorage.md), [IWithdrawManager](/contracts/root/withdrawManager/IWithdrawManager.sol/contract.IWithdrawManager.md) + + +## Functions +### isBondProvided + + +```solidity +modifier isBondProvided(); +``` + +### isPredicateAuthorized + + +```solidity +modifier isPredicateAuthorized(); +``` + +### checkPredicateAndTokenMapping + + +```solidity +modifier checkPredicateAndTokenMapping(address rootToken); +``` + +### function + +*Receive bond for bonded exits* + + +```solidity +function() external payable; +``` + +### createExitQueue + + +```solidity +function createExitQueue(address token) external; +``` + +### verifyInclusion + +*Verify the inclusion of the receipt in the checkpoint* + + +```solidity +function verifyInclusion(bytes calldata data, uint8 offset, bool verifyTxInclusion) external view returns (uint256); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`data`|`bytes`|RLP encoded data of the reference tx(s) that encodes the following fields for each tx headerNumber Header block number of which the reference tx was a part of blockProof Proof that the block header (in the child chain) is a leaf in the submitted merkle root blockNumber Block number of which the reference tx is a part of blockTime Reference tx block time blocktxRoot Transactions root of block blockReceiptsRoot Receipts root of block receipt Receipt of the reference transaction receiptProof Merkle proof of the reference receipt branchMask Merkle proof branchMask for the receipt logIndex Log Index to read from the receipt| +|`offset`|`uint8`|offset in the data array| +|`verifyTxInclusion`|`bool`|Whether to also verify the inclusion of the raw tx in the txRoot| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|ageOfInput Measure of the position of the receipt and the log in the child chain| + + +### startExitWithDepositedTokens + + +```solidity +function startExitWithDepositedTokens(uint256 depositId, address token, uint256 amountOrToken) external payable isBondProvided; +``` + +### addExitToQueue + + +```solidity +function addExitToQueue( + address exitor, + address childToken, + address rootToken, + uint256 exitAmountOrTokenId, + bytes32 txHash, + bool isRegularExit, + uint256 priority +) external checkPredicateAndTokenMapping(rootToken); +``` + +### challengeExit + + +```solidity +function challengeExit(uint256 exitId, uint256 inputId, bytes calldata challengeData, address adjudicatorPredicate) external; +``` + +### processExits + + +```solidity +function processExits(address _token) public; +``` + +### processExitsBatch + + +```solidity +function processExitsBatch(address[] calldata _tokens) external; +``` + +### addInput + +*Add a state update (UTXO style input) to an exit* + + +```solidity +function addInput(uint256 exitId, uint256 age, address utxoOwner, address token) external isPredicateAuthorized; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`exitId`|`uint256`|Exit ID| +|`age`|`uint256`|age of the UTXO style input| +|`utxoOwner`|`address`|User for whom the input acts as a proof-of-funds (alternate expression) User who could have potentially spent this UTXO| +|`token`|`address`|Token (Think of it like Utxo color)| + + +### _addInput + + +```solidity +function _addInput(uint256 exitId, uint256 age, address utxoOwner, address predicate, address token) internal; +``` + +### encodeExit + + +```solidity +function encodeExit(PlasmaExit storage exit) internal view returns (bytes memory); +``` + +### encodeExitForProcessExit + + +```solidity +function encodeExitForProcessExit(uint256 exitId) internal view returns (bytes memory); +``` + +### encodeInputUtxo + + +```solidity +function encodeInputUtxo(uint256 age, Input storage input) internal view returns (bytes memory); +``` + +### _addExitToQueue + + +```solidity +function _addExitToQueue(address exitor, address rootToken, uint256 exitAmountOrTokenId, bytes32 txHash, bool isRegularExit, uint256 exitId, address predicate) + internal; +``` + +### checkBlockMembershipInCheckpoint + + +```solidity +function checkBlockMembershipInCheckpoint( + uint256 blockNumber, + uint256 blockTime, + bytes32 txRoot, + bytes32 receiptRoot, + uint256 headerNumber, + bytes memory blockProof +) internal view returns (uint256); +``` + +### getKey + + +```solidity +function getKey(address token, address exitor, uint256 amountOrToken) internal view returns (bytes32 key); +``` + +### getDepositManager + + +```solidity +function getDepositManager() internal view returns (DepositManager); +``` + +### getExitableAt + + +```solidity +function getExitableAt(uint256 createdAt) internal view returns (uint256); +``` + +### updateExitPeriod + + +```solidity +function updateExitPeriod(uint256 halfExitPeriod) public onlyOwner; +``` + +## Structs +### VerifyInclusionVars +During coverage tests verifyInclusion fails co compile with "stack too deep" error. + + +```solidity +struct VerifyInclusionVars { + uint256 headerNumber; + uint256 blockNumber; + uint256 createdAt; + uint256 branchMask; + bytes32 txRoot; + bytes32 receiptRoot; + bytes branchMaskBytes; +} +``` + diff --git a/docs/autogen/src/contracts/root/withdrawManager/WithdrawManagerProxy.sol/contract.WithdrawManagerProxy.md b/docs/autogen/src/contracts/root/withdrawManager/WithdrawManagerProxy.sol/contract.WithdrawManagerProxy.md new file mode 100644 index 000000000..cf78de951 --- /dev/null +++ b/docs/autogen/src/contracts/root/withdrawManager/WithdrawManagerProxy.sol/contract.WithdrawManagerProxy.md @@ -0,0 +1,15 @@ +# WithdrawManagerProxy +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/root/withdrawManager/WithdrawManagerProxy.sol) + +**Inherits:** +[Proxy](/contracts/common/misc/Proxy.sol/contract.Proxy.md), [WithdrawManagerStorage](/contracts/root/withdrawManager/WithdrawManagerStorage.sol/contract.WithdrawManagerStorage.md) + + +## Functions +### constructor + + +```solidity +constructor(address _proxyTo, address _registry, address _rootChain, address _exitNft) public Proxy(_proxyTo); +``` + diff --git a/docs/autogen/src/contracts/root/withdrawManager/WithdrawManagerStorage.sol/contract.ExitsDataStructure.md b/docs/autogen/src/contracts/root/withdrawManager/WithdrawManagerStorage.sol/contract.ExitsDataStructure.md new file mode 100644 index 000000000..46c48c955 --- /dev/null +++ b/docs/autogen/src/contracts/root/withdrawManager/WithdrawManagerStorage.sol/contract.ExitsDataStructure.md @@ -0,0 +1,29 @@ +# ExitsDataStructure +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/root/withdrawManager/WithdrawManagerStorage.sol) + + +## Structs +### Input + +```solidity +struct Input { + address utxoOwner; + address predicate; + address token; +} +``` + +### PlasmaExit + +```solidity +struct PlasmaExit { + uint256 receiptAmountOrNFTId; + bytes32 txHash; + address owner; + address token; + bool isRegularExit; + address predicate; + mapping(uint256 => Input) inputs; +} +``` + diff --git a/docs/autogen/src/contracts/root/withdrawManager/WithdrawManagerStorage.sol/contract.WithdrawManagerHeader.md b/docs/autogen/src/contracts/root/withdrawManager/WithdrawManagerStorage.sol/contract.WithdrawManagerHeader.md new file mode 100644 index 000000000..d654f3eac --- /dev/null +++ b/docs/autogen/src/contracts/root/withdrawManager/WithdrawManagerStorage.sol/contract.WithdrawManagerHeader.md @@ -0,0 +1,38 @@ +# WithdrawManagerHeader +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/root/withdrawManager/WithdrawManagerStorage.sol) + +**Inherits:** +[ExitsDataStructure](/contracts/root/withdrawManager/WithdrawManagerStorage.sol/contract.ExitsDataStructure.md) + + +## Events +### Withdraw + +```solidity +event Withdraw(uint256 indexed exitId, address indexed user, address indexed token, uint256 amount); +``` + +### ExitStarted + +```solidity +event ExitStarted(address indexed exitor, uint256 indexed exitId, address indexed token, uint256 amount, bool isRegularExit); +``` + +### ExitUpdated + +```solidity +event ExitUpdated(uint256 indexed exitId, uint256 indexed age, address signer); +``` + +### ExitPeriodUpdate + +```solidity +event ExitPeriodUpdate(uint256 indexed oldExitPeriod, uint256 indexed newExitPeriod); +``` + +### ExitCancelled + +```solidity +event ExitCancelled(uint256 indexed exitId); +``` + diff --git a/docs/autogen/src/contracts/root/withdrawManager/WithdrawManagerStorage.sol/contract.WithdrawManagerStorage.md b/docs/autogen/src/contracts/root/withdrawManager/WithdrawManagerStorage.sol/contract.WithdrawManagerStorage.md new file mode 100644 index 000000000..e56601edb --- /dev/null +++ b/docs/autogen/src/contracts/root/withdrawManager/WithdrawManagerStorage.sol/contract.WithdrawManagerStorage.md @@ -0,0 +1,85 @@ +# WithdrawManagerStorage +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/root/withdrawManager/WithdrawManagerStorage.sol) + +**Inherits:** +[ProxyStorage](/contracts/common/misc/ProxyStorage.sol/contract.ProxyStorage.md), [WithdrawManagerHeader](/contracts/root/withdrawManager/WithdrawManagerStorage.sol/contract.WithdrawManagerHeader.md) + + +## State Variables +### HALF_EXIT_PERIOD + +```solidity +uint256 public HALF_EXIT_PERIOD = 302_400; +``` + + +### BOND_AMOUNT + +```solidity +uint256 internal constant BOND_AMOUNT = 10 ** 17; +``` + + +### registry + +```solidity +Registry internal registry; +``` + + +### rootChain + +```solidity +RootChain internal rootChain; +``` + + +### isKnownExit + +```solidity +mapping(uint128 => bool) isKnownExit; +``` + + +### exits + +```solidity +mapping(uint256 => PlasmaExit) public exits; +``` + + +### ownerExits + +```solidity +mapping(bytes32 => uint256) public ownerExits; +``` + + +### exitsQueues + +```solidity +mapping(address => address) public exitsQueues; +``` + + +### exitNft + +```solidity +ExitNFT public exitNft; +``` + + +### ON_FINALIZE_GAS_LIMIT + +```solidity +uint32 public ON_FINALIZE_GAS_LIMIT = 300_000; +``` + + +### exitWindow + +```solidity +uint256 public exitWindow; +``` + + diff --git a/docs/autogen/src/contracts/staking/EventsHub.sol/contract.EventsHub.md b/docs/autogen/src/contracts/staking/EventsHub.sol/contract.EventsHub.md new file mode 100644 index 000000000..9fdfad88d --- /dev/null +++ b/docs/autogen/src/contracts/staking/EventsHub.sol/contract.EventsHub.md @@ -0,0 +1,103 @@ +# EventsHub +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/staking/EventsHub.sol) + +**Inherits:** +[Initializable](/contracts/common/mixin/Initializable.sol/contract.Initializable.md) + + +## State Variables +### registry + +```solidity +Registry public registry; +``` + + +## Functions +### onlyValidatorContract + + +```solidity +modifier onlyValidatorContract(uint256 validatorId); +``` + +### onlyStakeManager + + +```solidity +modifier onlyStakeManager(); +``` + +### initialize + + +```solidity +function initialize(Registry _registry) external initializer; +``` + +### logShareBurnedWithId + + +```solidity +function logShareBurnedWithId(uint256 validatorId, address user, uint256 amount, uint256 tokens, uint256 nonce) public onlyValidatorContract(validatorId); +``` + +### logDelegatorUnstakedWithId + + +```solidity +function logDelegatorUnstakedWithId(uint256 validatorId, address user, uint256 amount, uint256 nonce) public onlyValidatorContract(validatorId); +``` + +### logRewardParams + + +```solidity +function logRewardParams(uint256 rewardDecreasePerCheckpoint, uint256 maxRewardedCheckpoints, uint256 checkpointRewardDelta) public onlyStakeManager; +``` + +### logUpdateCommissionRate + + +```solidity +function logUpdateCommissionRate(uint256 validatorId, uint256 newCommissionRate, uint256 oldCommissionRate) public onlyStakeManager; +``` + +### logSharesTransfer + + +```solidity +function logSharesTransfer(uint256 validatorId, address from, address to, uint256 value) public onlyValidatorContract(validatorId); +``` + +## Events +### ShareBurnedWithId + +```solidity +event ShareBurnedWithId(uint256 indexed validatorId, address indexed user, uint256 indexed amount, uint256 tokens, uint256 nonce); +``` + +### DelegatorUnstakeWithId + +```solidity +event DelegatorUnstakeWithId(uint256 indexed validatorId, address indexed user, uint256 amount, uint256 nonce); +``` + +### RewardParams + +```solidity +event RewardParams(uint256 rewardDecreasePerCheckpoint, uint256 maxRewardedCheckpoints, uint256 checkpointRewardDelta); +``` + +### UpdateCommissionRate + +```solidity +event UpdateCommissionRate(uint256 indexed validatorId, uint256 indexed newCommissionRate, uint256 indexed oldCommissionRate); +``` + +### SharesTransfer + +```solidity +event SharesTransfer(uint256 indexed validatorId, address indexed from, address indexed to, uint256 value); +``` + diff --git a/docs/autogen/src/contracts/staking/EventsHub.sol/contract.IStakeManagerEventsHub.md b/docs/autogen/src/contracts/staking/EventsHub.sol/contract.IStakeManagerEventsHub.md new file mode 100644 index 000000000..ea2fe04f3 --- /dev/null +++ b/docs/autogen/src/contracts/staking/EventsHub.sol/contract.IStakeManagerEventsHub.md @@ -0,0 +1,27 @@ +# IStakeManagerEventsHub +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/staking/EventsHub.sol) + + +## State Variables +### validators + +```solidity +mapping(uint256 => Validator) public validators; +``` + + +## Structs +### Validator + +```solidity +struct Validator { + uint256 amount; + uint256 reward; + uint256 activationEpoch; + uint256 deactivationEpoch; + uint256 jailTime; + address signer; + address contractAddress; +} +``` + diff --git a/docs/autogen/src/contracts/staking/EventsHubProxy.sol/contract.EventsHubProxy.md b/docs/autogen/src/contracts/staking/EventsHubProxy.sol/contract.EventsHubProxy.md new file mode 100644 index 000000000..3fcde677d --- /dev/null +++ b/docs/autogen/src/contracts/staking/EventsHubProxy.sol/contract.EventsHubProxy.md @@ -0,0 +1,15 @@ +# EventsHubProxy +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/staking/EventsHubProxy.sol) + +**Inherits:** +[UpgradableProxy](/contracts/common/misc/UpgradableProxy.sol/contract.UpgradableProxy.md) + + +## Functions +### constructor + + +```solidity +constructor(address _proxyTo) public UpgradableProxy(_proxyTo); +``` + diff --git a/docs/autogen/src/contracts/staking/README.md b/docs/autogen/src/contracts/staking/README.md new file mode 100644 index 000000000..ae4f565e7 --- /dev/null +++ b/docs/autogen/src/contracts/staking/README.md @@ -0,0 +1,11 @@ + + +# Contents +- [slashing](/contracts/staking/slashing) +- [stakeManager](/contracts/staking/stakeManager) +- [validatorShare](/contracts/staking/validatorShare) +- [IStakeManagerEventsHub](EventsHub.sol/contract.IStakeManagerEventsHub.md) +- [EventsHub](EventsHub.sol/contract.EventsHub.md) +- [EventsHubProxy](EventsHubProxy.sol/contract.EventsHubProxy.md) +- [IStakeManagerLocal](StakingInfo.sol/contract.IStakeManagerLocal.md) +- [StakingInfo](StakingInfo.sol/contract.StakingInfo.md) diff --git a/docs/autogen/src/contracts/staking/StakingInfo.sol/contract.IStakeManagerLocal.md b/docs/autogen/src/contracts/staking/StakingInfo.sol/contract.IStakeManagerLocal.md new file mode 100644 index 000000000..97a0b6606 --- /dev/null +++ b/docs/autogen/src/contracts/staking/StakingInfo.sol/contract.IStakeManagerLocal.md @@ -0,0 +1,83 @@ +# IStakeManagerLocal +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/staking/StakingInfo.sol) + + +## State Variables +### validators + +```solidity +mapping(uint256 => Validator) public validators; +``` + + +### accountStateRoot + +```solidity +bytes32 public accountStateRoot; +``` + + +### activeAmount + +```solidity +uint256 public activeAmount; +``` + + +### validatorRewards + +```solidity +uint256 public validatorRewards; +``` + + +## Functions +### currentValidatorSetTotalStake + + +```solidity +function currentValidatorSetTotalStake() public view returns (uint256); +``` + +### signerToValidator + + +```solidity +function signerToValidator(address validatorAddress) public view returns (uint256); +``` + +### isValidator + + +```solidity +function isValidator(uint256 validatorId) public view returns (bool); +``` + +## Structs +### Validator + +```solidity +struct Validator { + uint256 amount; + uint256 reward; + uint256 activationEpoch; + uint256 deactivationEpoch; + uint256 jailTime; + address signer; + address contractAddress; + Status status; +} +``` + +## Enums +### Status + +```solidity +enum Status { + Inactive, + Active, + Locked, + Unstaked +} +``` + diff --git a/docs/autogen/src/contracts/staking/StakingInfo.sol/contract.StakingInfo.md b/docs/autogen/src/contracts/staking/StakingInfo.sol/contract.StakingInfo.md new file mode 100644 index 000000000..087e045c8 --- /dev/null +++ b/docs/autogen/src/contracts/staking/StakingInfo.sol/contract.StakingInfo.md @@ -0,0 +1,472 @@ +# StakingInfo +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/staking/StakingInfo.sol) + +**Inherits:** +Ownable + + +## State Variables +### validatorNonce + +```solidity +mapping(uint256 => uint256) public validatorNonce; +``` + + +### registry + +```solidity +Registry public registry; +``` + + +## Functions +### onlyValidatorContract + + +```solidity +modifier onlyValidatorContract(uint256 validatorId); +``` + +### StakeManagerOrValidatorContract + + +```solidity +modifier StakeManagerOrValidatorContract(uint256 validatorId); +``` + +### onlyStakeManager + + +```solidity +modifier onlyStakeManager(); +``` + +### onlySlashingManager + + +```solidity +modifier onlySlashingManager(); +``` + +### constructor + + +```solidity +constructor(address _registry) public; +``` + +### updateNonce + + +```solidity +function updateNonce(uint256[] calldata validatorIds, uint256[] calldata nonces) external onlyOwner; +``` + +### logStaked + + +```solidity +function logStaked(address signer, bytes memory signerPubkey, uint256 validatorId, uint256 activationEpoch, uint256 amount, uint256 total) + public + onlyStakeManager; +``` + +### logUnstaked + + +```solidity +function logUnstaked(address user, uint256 validatorId, uint256 amount, uint256 total) public onlyStakeManager; +``` + +### logUnstakeInit + + +```solidity +function logUnstakeInit(address user, uint256 validatorId, uint256 deactivationEpoch, uint256 amount) public onlyStakeManager; +``` + +### logSignerChange + + +```solidity +function logSignerChange(uint256 validatorId, address oldSigner, address newSigner, bytes memory signerPubkey) public onlyStakeManager; +``` + +### logRestaked + + +```solidity +function logRestaked(uint256 validatorId, uint256 amount, uint256 total) public onlyStakeManager; +``` + +### logJailed + + +```solidity +function logJailed(uint256 validatorId, uint256 exitEpoch, address signer) public onlyStakeManager; +``` + +### logUnjailed + + +```solidity +function logUnjailed(uint256 validatorId, address signer) public onlyStakeManager; +``` + +### logSlashed + + +```solidity +function logSlashed(uint256 nonce, uint256 amount) public onlySlashingManager; +``` + +### logThresholdChange + + +```solidity +function logThresholdChange(uint256 newThreshold, uint256 oldThreshold) public onlyStakeManager; +``` + +### logDynastyValueChange + + +```solidity +function logDynastyValueChange(uint256 newDynasty, uint256 oldDynasty) public onlyStakeManager; +``` + +### logProposerBonusChange + + +```solidity +function logProposerBonusChange(uint256 newProposerBonus, uint256 oldProposerBonus) public onlyStakeManager; +``` + +### logRewardUpdate + + +```solidity +function logRewardUpdate(uint256 newReward, uint256 oldReward) public onlyStakeManager; +``` + +### logStakeUpdate + + +```solidity +function logStakeUpdate(uint256 validatorId) public StakeManagerOrValidatorContract(validatorId); +``` + +### logClaimRewards + + +```solidity +function logClaimRewards(uint256 validatorId, uint256 amount, uint256 totalAmount) public onlyStakeManager; +``` + +### logStartAuction + + +```solidity +function logStartAuction(uint256 validatorId, uint256 amount, uint256 auctionAmount) public onlyStakeManager; +``` + +### logConfirmAuction + + +```solidity +function logConfirmAuction(uint256 newValidatorId, uint256 oldValidatorId, uint256 amount) public onlyStakeManager; +``` + +### logTopUpFee + + +```solidity +function logTopUpFee(address user, uint256 fee) public onlyStakeManager; +``` + +### logClaimFee + + +```solidity +function logClaimFee(address user, uint256 fee) public onlyStakeManager; +``` + +### getStakerDetails + + +```solidity +function getStakerDetails(uint256 validatorId) + public + view + returns (uint256 amount, uint256 reward, uint256 activationEpoch, uint256 deactivationEpoch, address signer, uint256 _status); +``` + +### totalValidatorStake + + +```solidity +function totalValidatorStake(uint256 validatorId) public view returns (uint256 validatorStake); +``` + +### getAccountStateRoot + + +```solidity +function getAccountStateRoot() public view returns (bytes32 accountStateRoot); +``` + +### getValidatorContractAddress + + +```solidity +function getValidatorContractAddress(uint256 validatorId) public view returns (address ValidatorContract); +``` + +### logShareMinted + + +```solidity +function logShareMinted(uint256 validatorId, address user, uint256 amount, uint256 tokens) public onlyValidatorContract(validatorId); +``` + +### logShareBurned + + +```solidity +function logShareBurned(uint256 validatorId, address user, uint256 amount, uint256 tokens) public onlyValidatorContract(validatorId); +``` + +### logDelegatorClaimRewards + + +```solidity +function logDelegatorClaimRewards(uint256 validatorId, address user, uint256 rewards) public onlyValidatorContract(validatorId); +``` + +### logDelegatorRestaked + + +```solidity +function logDelegatorRestaked(uint256 validatorId, address user, uint256 totalStaked) public onlyValidatorContract(validatorId); +``` + +### logDelegatorUnstaked + + +```solidity +function logDelegatorUnstaked(uint256 validatorId, address user, uint256 amount) public onlyValidatorContract(validatorId); +``` + +### logUpdateCommissionRate + + +```solidity +function logUpdateCommissionRate(uint256 validatorId, uint256 newCommissionRate, uint256 oldCommissionRate) public onlyValidatorContract(validatorId); +``` + +## Events +### Staked +*Emitted when validator stakes in '_stakeFor()' in StakeManager.* + + +```solidity +event Staked( + address indexed signer, uint256 indexed validatorId, uint256 nonce, uint256 indexed activationEpoch, uint256 amount, uint256 total, bytes signerPubkey +); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`signer`|`address`|validator address.| +|`validatorId`|`uint256`|unique integer to identify a validator.| +|`nonce`|`uint256`|to synchronize the events in heimdal.| +|`activationEpoch`|`uint256`|validator's first epoch as proposer.| +|`amount`|`uint256`|staking amount.| +|`total`|`uint256`|total staking amount.| +|`signerPubkey`|`bytes`|public key of the validator| + +### Unstaked +*Emitted when validator unstakes in 'unstakeClaim()'* + + +```solidity +event Unstaked(address indexed user, uint256 indexed validatorId, uint256 amount, uint256 total); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`user`|`address`|address of the validator.| +|`validatorId`|`uint256`|unique integer to identify a validator.| +|`amount`|`uint256`|staking amount.| +|`total`|`uint256`|total staking amount.| + +### UnstakeInit +*Emitted when validator unstakes in '_unstake()'.* + + +```solidity +event UnstakeInit(address indexed user, uint256 indexed validatorId, uint256 nonce, uint256 deactivationEpoch, uint256 indexed amount); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`user`|`address`|address of the validator.| +|`validatorId`|`uint256`|unique integer to identify a validator.| +|`nonce`|`uint256`|to synchronize the events in heimdal.| +|`deactivationEpoch`|`uint256`|last epoch for validator.| +|`amount`|`uint256`|staking amount.| + +### SignerChange +*Emitted when the validator public key is updated in 'updateSigner()'.* + + +```solidity +event SignerChange(uint256 indexed validatorId, uint256 nonce, address indexed oldSigner, address indexed newSigner, bytes signerPubkey); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`validatorId`|`uint256`|unique integer to identify a validator.| +|`nonce`|`uint256`|to synchronize the events in heimdal.| +|`oldSigner`|`address`|old address of the validator.| +|`newSigner`|`address`|new address of the validator.| +|`signerPubkey`|`bytes`|public key of the validator.| + +### Restaked + +```solidity +event Restaked(uint256 indexed validatorId, uint256 amount, uint256 total); +``` + +### Jailed + +```solidity +event Jailed(uint256 indexed validatorId, uint256 indexed exitEpoch, address indexed signer); +``` + +### UnJailed + +```solidity +event UnJailed(uint256 indexed validatorId, address indexed signer); +``` + +### Slashed + +```solidity +event Slashed(uint256 indexed nonce, uint256 indexed amount); +``` + +### ThresholdChange + +```solidity +event ThresholdChange(uint256 newThreshold, uint256 oldThreshold); +``` + +### DynastyValueChange + +```solidity +event DynastyValueChange(uint256 newDynasty, uint256 oldDynasty); +``` + +### ProposerBonusChange + +```solidity +event ProposerBonusChange(uint256 newProposerBonus, uint256 oldProposerBonus); +``` + +### RewardUpdate + +```solidity +event RewardUpdate(uint256 newReward, uint256 oldReward); +``` + +### StakeUpdate +*Emitted when validator confirms the auction bid and at the time of restaking in confirmAuctionBid() and restake().* + + +```solidity +event StakeUpdate(uint256 indexed validatorId, uint256 indexed nonce, uint256 indexed newAmount); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`validatorId`|`uint256`|unique integer to identify a validator.| +|`nonce`|`uint256`|to synchronize the events in heimdal.| +|`newAmount`|`uint256`|the updated stake amount.| + +### ClaimRewards + +```solidity +event ClaimRewards(uint256 indexed validatorId, uint256 indexed amount, uint256 indexed totalAmount); +``` + +### StartAuction + +```solidity +event StartAuction(uint256 indexed validatorId, uint256 indexed amount, uint256 indexed auctionAmount); +``` + +### ConfirmAuction + +```solidity +event ConfirmAuction(uint256 indexed newValidatorId, uint256 indexed oldValidatorId, uint256 indexed amount); +``` + +### TopUpFee + +```solidity +event TopUpFee(address indexed user, uint256 indexed fee); +``` + +### ClaimFee + +```solidity +event ClaimFee(address indexed user, uint256 indexed fee); +``` + +### ShareMinted + +```solidity +event ShareMinted(uint256 indexed validatorId, address indexed user, uint256 indexed amount, uint256 tokens); +``` + +### ShareBurned + +```solidity +event ShareBurned(uint256 indexed validatorId, address indexed user, uint256 indexed amount, uint256 tokens); +``` + +### DelegatorClaimedRewards + +```solidity +event DelegatorClaimedRewards(uint256 indexed validatorId, address indexed user, uint256 indexed rewards); +``` + +### DelegatorRestaked + +```solidity +event DelegatorRestaked(uint256 indexed validatorId, address indexed user, uint256 indexed totalStaked); +``` + +### DelegatorUnstaked + +```solidity +event DelegatorUnstaked(uint256 indexed validatorId, address indexed user, uint256 amount); +``` + +### UpdateCommissionRate + +```solidity +event UpdateCommissionRate(uint256 indexed validatorId, uint256 indexed newCommissionRate, uint256 indexed oldCommissionRate); +``` + diff --git a/docs/autogen/src/contracts/staking/slashing/ISlashingManager.sol/contract.ISlashingManager.md b/docs/autogen/src/contracts/staking/slashing/ISlashingManager.sol/contract.ISlashingManager.md new file mode 100644 index 000000000..be43a1213 --- /dev/null +++ b/docs/autogen/src/contracts/staking/slashing/ISlashingManager.sol/contract.ISlashingManager.md @@ -0,0 +1,61 @@ +# ISlashingManager +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/staking/slashing/ISlashingManager.sol) + + +## State Variables +### heimdallId + +```solidity +bytes32 public heimdallId; +``` + + +### VOTE_TYPE + +```solidity +uint8 public constant VOTE_TYPE = 2; +``` + + +### reportRate + +```solidity +uint256 public reportRate = 5; +``` + + +### proposerRate + +```solidity +uint256 public proposerRate = 50; +``` + + +### jailCheckpoints + +```solidity +uint256 public jailCheckpoints = 5; +``` + + +### slashingNonce + +```solidity +uint256 public slashingNonce; +``` + + +### registry + +```solidity +Registry public registry; +``` + + +### logger + +```solidity +StakingInfo public logger; +``` + + diff --git a/docs/autogen/src/contracts/staking/slashing/README.md b/docs/autogen/src/contracts/staking/slashing/README.md new file mode 100644 index 000000000..4d4d6aed3 --- /dev/null +++ b/docs/autogen/src/contracts/staking/slashing/README.md @@ -0,0 +1,5 @@ + + +# Contents +- [ISlashingManager](ISlashingManager.sol/contract.ISlashingManager.md) +- [SlashingManager](SlashingManager.sol/contract.SlashingManager.md) diff --git a/docs/autogen/src/contracts/staking/slashing/SlashingManager.sol/contract.SlashingManager.md b/docs/autogen/src/contracts/staking/slashing/SlashingManager.sol/contract.SlashingManager.md new file mode 100644 index 000000000..70685c893 --- /dev/null +++ b/docs/autogen/src/contracts/staking/slashing/SlashingManager.sol/contract.SlashingManager.md @@ -0,0 +1,64 @@ +# SlashingManager +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/staking/slashing/SlashingManager.sol) + +**Inherits:** +[ISlashingManager](/contracts/staking/slashing/ISlashingManager.sol/contract.ISlashingManager.md), Ownable + + +## Functions +### onlyStakeManager + + +```solidity +modifier onlyStakeManager(); +``` + +### constructor + + +```solidity +constructor(address _registry, address _logger, string memory _heimdallId) public; +``` + +### updateSlashedAmounts + + +```solidity +function updateSlashedAmounts(bytes memory data, bytes memory sigs) public; +``` + +### verifyConsensus + + +```solidity +function verifyConsensus(bytes32 voteHash, bytes memory sigs) public view returns (bool); +``` + +### updateReportRate + + +```solidity +function updateReportRate(uint256 newReportRate) public onlyOwner; +``` + +### updateProposerRate + + +```solidity +function updateProposerRate(uint256 newProposerRate) public onlyOwner; +``` + +### setHeimdallId + + +```solidity +function setHeimdallId(string memory _heimdallId) public onlyOwner; +``` + +### drainTokens + + +```solidity +function drainTokens(uint256 value, address token, address destination) external onlyOwner; +``` + diff --git a/docs/autogen/src/contracts/staking/stakeManager/IStakeManager.sol/contract.IStakeManager.md b/docs/autogen/src/contracts/staking/stakeManager/IStakeManager.sol/contract.IStakeManager.md new file mode 100644 index 000000000..171dcb456 --- /dev/null +++ b/docs/autogen/src/contracts/staking/stakeManager/IStakeManager.sol/contract.IStakeManager.md @@ -0,0 +1,152 @@ +# IStakeManager +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/staking/stakeManager/IStakeManager.sol) + + +## Functions +### startAuction + + +```solidity +function startAuction(uint256 validatorId, uint256 amount, bool acceptDelegation, bytes calldata signerPubkey) external; +``` + +### confirmAuctionBid + + +```solidity +function confirmAuctionBid(uint256 validatorId, uint256 heimdallFee) external; +``` + +### transferFunds + + +```solidity +function transferFunds(uint256 validatorId, uint256 amount, address delegator) external returns (bool); +``` + +### delegationDeposit + + +```solidity +function delegationDeposit(uint256 validatorId, uint256 amount, address delegator) external returns (bool); +``` + +### unstake + + +```solidity +function unstake(uint256 validatorId) external; +``` + +### totalStakedFor + + +```solidity +function totalStakedFor(address addr) external view returns (uint256); +``` + +### stakeFor + + +```solidity +function stakeFor(address user, uint256 amount, uint256 heimdallFee, bool acceptDelegation, bytes memory signerPubkey) public; +``` + +### checkSignatures + + +```solidity +function checkSignatures(uint256 blockInterval, bytes32 voteHash, bytes32 stateRoot, address proposer, uint256[3][] calldata sigs) external returns (uint256); +``` + +### updateValidatorState + + +```solidity +function updateValidatorState(uint256 validatorId, int256 amount) public; +``` + +### ownerOf + + +```solidity +function ownerOf(uint256 tokenId) public view returns (address); +``` + +### slash + + +```solidity +function slash(bytes calldata slashingInfoList) external returns (uint256); +``` + +### validatorStake + + +```solidity +function validatorStake(uint256 validatorId) public view returns (uint256); +``` + +### epoch + + +```solidity +function epoch() public view returns (uint256); +``` + +### getRegistry + + +```solidity +function getRegistry() public view returns (address); +``` + +### withdrawalDelay + + +```solidity +function withdrawalDelay() public view returns (uint256); +``` + +### delegatedAmount + + +```solidity +function delegatedAmount(uint256 validatorId) public view returns (uint256); +``` + +### decreaseValidatorDelegatedAmount + + +```solidity +function decreaseValidatorDelegatedAmount(uint256 validatorId, uint256 amount) public; +``` + +### withdrawDelegatorsReward + + +```solidity +function withdrawDelegatorsReward(uint256 validatorId) public returns (uint256); +``` + +### delegatorsReward + + +```solidity +function delegatorsReward(uint256 validatorId) public view returns (uint256); +``` + +### dethroneAndStake + + +```solidity +function dethroneAndStake( + address auctionUser, + uint256 heimdallFee, + uint256 validatorId, + uint256 auctionAmount, + bool acceptDelegation, + bytes calldata signerPubkey +) external; +``` + diff --git a/docs/autogen/src/contracts/staking/stakeManager/README.md b/docs/autogen/src/contracts/staking/stakeManager/README.md new file mode 100644 index 000000000..98be2db3f --- /dev/null +++ b/docs/autogen/src/contracts/staking/stakeManager/README.md @@ -0,0 +1,10 @@ + + +# Contents +- [IStakeManager](IStakeManager.sol/contract.IStakeManager.md) +- [StakeManager](StakeManager.sol/contract.StakeManager.md) +- [StakeManagerExtension](StakeManagerExtension.sol/contract.StakeManagerExtension.md) +- [StakeManagerProxy](StakeManagerProxy.sol/contract.StakeManagerProxy.md) +- [StakeManagerStorage](StakeManagerStorage.sol/contract.StakeManagerStorage.md) +- [StakeManagerStorageExtension](StakeManagerStorageExtension.sol/contract.StakeManagerStorageExtension.md) +- [StakingNFT](StakingNFT.sol/contract.StakingNFT.md) diff --git a/docs/autogen/src/contracts/staking/stakeManager/StakeManager.sol/contract.StakeManager.md b/docs/autogen/src/contracts/staking/stakeManager/StakeManager.sol/contract.StakeManager.md new file mode 100644 index 000000000..e0018517d --- /dev/null +++ b/docs/autogen/src/contracts/staking/stakeManager/StakeManager.sol/contract.StakeManager.md @@ -0,0 +1,698 @@ +# StakeManager +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/staking/stakeManager/StakeManager.sol) + +**Inherits:** +[StakeManagerStorage](/contracts/staking/stakeManager/StakeManagerStorage.sol/contract.StakeManagerStorage.md), [Initializable](/contracts/common/mixin/Initializable.sol/contract.Initializable.md), [IStakeManager](/contracts/staking/stakeManager/IStakeManager.sol/contract.IStakeManager.md), [DelegateProxyForwarder](/contracts/common/misc/DelegateProxyForwarder.sol/contract.DelegateProxyForwarder.md), [StakeManagerStorageExtension](/contracts/staking/stakeManager/StakeManagerStorageExtension.sol/contract.StakeManagerStorageExtension.md) + + +## Functions +### onlyStaker + + +```solidity +modifier onlyStaker(uint256 validatorId); +``` + +### _assertStaker + + +```solidity +function _assertStaker(uint256 validatorId) private view; +``` + +### onlyDelegation + + +```solidity +modifier onlyDelegation(uint256 validatorId); +``` + +### _assertDelegation + + +```solidity +function _assertDelegation(uint256 validatorId) private view; +``` + +### constructor + + +```solidity +constructor() public GovernanceLockable(address(0x0)) initializer; +``` + +### initialize + + +```solidity +function initialize( + address _registry, + address _rootchain, + address _token, + address _NFTContract, + address _stakingLogger, + address _validatorShareFactory, + address _governance, + address _owner, + address _extensionCode +) external initializer; +``` + +### isOwner + + +```solidity +function isOwner() public view returns (bool); +``` + +### getRegistry + +Public View Methods + + +```solidity +function getRegistry() public view returns (address); +``` + +### ownerOf + +*Owner of validator slot NFT* + + +```solidity +function ownerOf(uint256 tokenId) public view returns (address); +``` + +### epoch + + +```solidity +function epoch() public view returns (uint256); +``` + +### withdrawalDelay + + +```solidity +function withdrawalDelay() public view returns (uint256); +``` + +### validatorStake + + +```solidity +function validatorStake(uint256 validatorId) public view returns (uint256); +``` + +### getValidatorId + + +```solidity +function getValidatorId(address user) public view returns (uint256); +``` + +### delegatedAmount + + +```solidity +function delegatedAmount(uint256 validatorId) public view returns (uint256); +``` + +### delegatorsReward + + +```solidity +function delegatorsReward(uint256 validatorId) public view returns (uint256); +``` + +### validatorReward + + +```solidity +function validatorReward(uint256 validatorId) public view returns (uint256); +``` + +### currentValidatorSetSize + + +```solidity +function currentValidatorSetSize() public view returns (uint256); +``` + +### currentValidatorSetTotalStake + + +```solidity +function currentValidatorSetTotalStake() public view returns (uint256); +``` + +### getValidatorContract + + +```solidity +function getValidatorContract(uint256 validatorId) public view returns (address); +``` + +### isValidator + + +```solidity +function isValidator(uint256 validatorId) public view returns (bool); +``` + +### setDelegationEnabled + +Governance Methods + + +```solidity +function setDelegationEnabled(bool enabled) public onlyGovernance; +``` + +### forceUnstake + + +```solidity +function forceUnstake(uint256 validatorId) external onlyGovernance; +``` + +### setCurrentEpoch + + +```solidity +function setCurrentEpoch(uint256 _currentEpoch) external onlyGovernance; +``` + +### setStakingToken + + +```solidity +function setStakingToken(address _token) public onlyGovernance; +``` + +### updateValidatorThreshold + +*Change the number of validators required to allow a passed header root* + + +```solidity +function updateValidatorThreshold(uint256 newThreshold) public onlyGovernance; +``` + +### updateCheckPointBlockInterval + + +```solidity +function updateCheckPointBlockInterval(uint256 _blocks) public onlyGovernance; +``` + +### updateCheckpointReward + + +```solidity +function updateCheckpointReward(uint256 newReward) public onlyGovernance; +``` + +### updateCheckpointRewardParams + + +```solidity +function updateCheckpointRewardParams(uint256 _rewardDecreasePerCheckpoint, uint256 _maxRewardedCheckpoints, uint256 _checkpointRewardDelta) + public + onlyGovernance; +``` + +### migrateValidatorsData + + +```solidity +function migrateValidatorsData(uint256 validatorIdFrom, uint256 validatorIdTo) public onlyOwner; +``` + +### insertSigners + + +```solidity +function insertSigners(address[] memory _signers) public onlyOwner; +``` + +### updateValidatorContractAddress + +*Users must exit before this update or all funds may get lost* + + +```solidity +function updateValidatorContractAddress(uint256 validatorId, address newContractAddress) public onlyGovernance; +``` + +### updateDynastyValue + + +```solidity +function updateDynastyValue(uint256 newDynasty) public onlyGovernance; +``` + +### stopAuctions + + +```solidity +function stopAuctions(uint256 forNCheckpoints) public onlyGovernance; +``` + +### updateProposerBonus + + +```solidity +function updateProposerBonus(uint256 newProposerBonus) public onlyGovernance; +``` + +### updateSignerUpdateLimit + + +```solidity +function updateSignerUpdateLimit(uint256 _limit) public onlyGovernance; +``` + +### updateMinAmounts + + +```solidity +function updateMinAmounts(uint256 _minDeposit, uint256 _minHeimdallFee) public onlyGovernance; +``` + +### drainValidatorShares + + +```solidity +function drainValidatorShares(uint256 validatorId, address tokenAddr, address payable destination, uint256 amount) external onlyGovernance; +``` + +### drain + + +```solidity +function drain(address destination, uint256 amount) external onlyGovernance; +``` + +### reinitialize + + +```solidity +function reinitialize(address _NFTContract, address _stakingLogger, address _validatorShareFactory, address _extensionCode) external onlyGovernance; +``` + +### topUpForFee + +Public Methods + + +```solidity +function topUpForFee(address user, uint256 heimdallFee) public onlyWhenUnlocked; +``` + +### claimFee + + +```solidity +function claimFee(uint256 accumFeeAmount, uint256 index, bytes memory proof) public; +``` + +### totalStakedFor + + +```solidity +function totalStakedFor(address user) external view returns (uint256); +``` + +### startAuction + + +```solidity +function startAuction(uint256 validatorId, uint256 amount, bool _acceptDelegation, bytes calldata _signerPubkey) external onlyWhenUnlocked; +``` + +### confirmAuctionBid + + +```solidity +function confirmAuctionBid(uint256 validatorId, uint256 heimdallFee) external onlyWhenUnlocked; +``` + +### dethroneAndStake + + +```solidity +function dethroneAndStake( + address auctionUser, + uint256 heimdallFee, + uint256 validatorId, + uint256 auctionAmount, + bool acceptDelegation, + bytes calldata signerPubkey +) external; +``` + +### unstake + + +```solidity +function unstake(uint256 validatorId) external onlyStaker(validatorId); +``` + +### transferFunds + + +```solidity +function transferFunds(uint256 validatorId, uint256 amount, address delegator) external returns (bool); +``` + +### delegationDeposit + + +```solidity +function delegationDeposit(uint256 validatorId, uint256 amount, address delegator) external onlyDelegation(validatorId) returns (bool); +``` + +### stakeFor + + +```solidity +function stakeFor(address user, uint256 amount, uint256 heimdallFee, bool acceptDelegation, bytes memory signerPubkey) public onlyWhenUnlocked; +``` + +### unstakeClaim + + +```solidity +function unstakeClaim(uint256 validatorId) public onlyStaker(validatorId); +``` + +### restake + + +```solidity +function restake(uint256 validatorId, uint256 amount, bool stakeRewards) public onlyWhenUnlocked onlyStaker(validatorId); +``` + +### withdrawRewards + + +```solidity +function withdrawRewards(uint256 validatorId) public onlyStaker(validatorId); +``` + +### migrateDelegation + + +```solidity +function migrateDelegation(uint256 fromValidatorId, uint256 toValidatorId, uint256 amount) public; +``` + +### updateValidatorState + + +```solidity +function updateValidatorState(uint256 validatorId, int256 amount) public onlyDelegation(validatorId); +``` + +### increaseValidatorDelegatedAmount + + +```solidity +function increaseValidatorDelegatedAmount(uint256 validatorId, uint256 amount) private; +``` + +### decreaseValidatorDelegatedAmount + + +```solidity +function decreaseValidatorDelegatedAmount(uint256 validatorId, uint256 amount) public onlyDelegation(validatorId); +``` + +### updateSigner + + +```solidity +function updateSigner(uint256 validatorId, bytes memory signerPubkey) public onlyStaker(validatorId); +``` + +### checkSignatures + + +```solidity +function checkSignatures(uint256 blockInterval, bytes32 voteHash, bytes32 stateRoot, address proposer, uint256[3][] calldata sigs) + external + onlyRootChain + returns (uint256); +``` + +### updateCommissionRate + + +```solidity +function updateCommissionRate(uint256 validatorId, uint256 newCommissionRate) external onlyStaker(validatorId); +``` + +### withdrawDelegatorsReward + + +```solidity +function withdrawDelegatorsReward(uint256 validatorId) public onlyDelegation(validatorId) returns (uint256); +``` + +### slash + + +```solidity +function slash(bytes calldata _slashingInfoList) external returns (uint256); +``` + +### unjail + + +```solidity +function unjail(uint256 validatorId) public onlyStaker(validatorId); +``` + +### updateTimeline + + +```solidity +function updateTimeline(int256 amount, int256 stakerCount, uint256 targetEpoch) internal; +``` + +### updateValidatorDelegation + + +```solidity +function updateValidatorDelegation(bool delegation) external; +``` + +### _getAndAssertSigner + +Private Methods + + +```solidity +function _getAndAssertSigner(bytes memory pub) private view returns (address); +``` + +### _isValidator + + +```solidity +function _isValidator(Status status, uint256 amount, uint256 deactivationEpoch, uint256 _currentEpoch) private pure returns (bool); +``` + +### _fillUnsignedValidators + + +```solidity +function _fillUnsignedValidators(UnsignedValidatorsContext memory context, address signer) private view returns (UnsignedValidatorsContext memory); +``` + +### _calculateCheckpointReward + + +```solidity +function _calculateCheckpointReward(uint256 blockInterval, uint256 signedStakePower, uint256 currentTotalStake) internal returns (uint256); +``` + +### _increaseRewardAndAssertConsensus + + +```solidity +function _increaseRewardAndAssertConsensus( + uint256 blockInterval, + address proposer, + uint256 signedStakePower, + bytes32 stateRoot, + uint256[] memory unsignedValidators, + uint256 totalUnsignedValidators, + uint256[] memory deactivatedValidators, + uint256 totalDeactivatedValidators +) private returns (uint256); +``` + +### _updateValidatorsRewards + + +```solidity +function _updateValidatorsRewards(uint256[] memory unsignedValidators, uint256 totalUnsignedValidators, uint256 newRewardPerStake) private; +``` + +### _updateRewardsAndCommit + + +```solidity +function _updateRewardsAndCommit(uint256 validatorId, uint256 currentRewardPerStake, uint256 newRewardPerStake) private; +``` + +### _updateRewards + + +```solidity +function _updateRewards(uint256 validatorId) private; +``` + +### _getEligibleValidatorReward + + +```solidity +function _getEligibleValidatorReward(uint256 validatorId, uint256 validatorStakePower, uint256 currentRewardPerStake, uint256 initialRewardPerStake) + private + pure + returns (uint256); +``` + +### _increaseValidatorReward + + +```solidity +function _increaseValidatorReward(uint256 validatorId, uint256 reward) private; +``` + +### _increaseValidatorRewardWithDelegation + + +```solidity +function _increaseValidatorRewardWithDelegation(uint256 validatorId, uint256 validatorsStake, uint256 delegatedAmount, uint256 reward) private; +``` + +### _getValidatorAndDelegationReward + + +```solidity +function _getValidatorAndDelegationReward(uint256 validatorId, uint256 validatorsStake, uint256 reward, uint256 combinedStakePower) + internal + view + returns (uint256, uint256); +``` + +### _evaluateValidatorAndDelegationReward + + +```solidity +function _evaluateValidatorAndDelegationReward(uint256 validatorId) private view returns (uint256 validatorReward, uint256 delegatorsReward); +``` + +### _jail + + +```solidity +function _jail(uint256 validatorId, uint256 jailCheckpoints) internal returns (uint256); +``` + +### _stakeFor + + +```solidity +function _stakeFor(address user, uint256 amount, bool acceptDelegation, bytes memory signerPubkey) internal returns (uint256); +``` + +### _unstake + + +```solidity +function _unstake(uint256 validatorId, uint256 exitEpoch) internal; +``` + +### _finalizeCommit + + +```solidity +function _finalizeCommit() internal; +``` + +### _liquidateRewards + + +```solidity +function _liquidateRewards(uint256 validatorId, address validatorUser) private; +``` + +### _transferToken + + +```solidity +function _transferToken(address destination, uint256 amount) private; +``` + +### _transferTokenFrom + + +```solidity +function _transferTokenFrom(address from, address destination, uint256 amount) private; +``` + +### _transferAndTopUp + + +```solidity +function _transferAndTopUp(address user, address from, uint256 fee, uint256 additionalAmount) private; +``` + +### _claimFee + + +```solidity +function _claimFee(address user, uint256 amount) private; +``` + +### _insertSigner + + +```solidity +function _insertSigner(address newSigner) internal; +``` + +### _removeSigner + + +```solidity +function _removeSigner(address signerToDelete) internal; +``` + +## Structs +### UnsignedValidatorsContext + +```solidity +struct UnsignedValidatorsContext { + uint256 unsignedValidatorIndex; + uint256 validatorIndex; + uint256[] unsignedValidators; + address[] validators; + uint256 totalValidators; +} +``` + +### UnstakedValidatorsContext + +```solidity +struct UnstakedValidatorsContext { + uint256 deactivationEpoch; + uint256[] deactivatedValidators; + uint256 validatorIndex; +} +``` + diff --git a/docs/autogen/src/contracts/staking/stakeManager/StakeManagerExtension.sol/contract.StakeManagerExtension.md b/docs/autogen/src/contracts/staking/stakeManager/StakeManagerExtension.sol/contract.StakeManagerExtension.md new file mode 100644 index 000000000..6fa134d86 --- /dev/null +++ b/docs/autogen/src/contracts/staking/stakeManager/StakeManagerExtension.sol/contract.StakeManagerExtension.md @@ -0,0 +1,57 @@ +# StakeManagerExtension +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/staking/stakeManager/StakeManagerExtension.sol) + +**Inherits:** +[StakeManagerStorage](/contracts/staking/stakeManager/StakeManagerStorage.sol/contract.StakeManagerStorage.md), [Initializable](/contracts/common/mixin/Initializable.sol/contract.Initializable.md), [StakeManagerStorageExtension](/contracts/staking/stakeManager/StakeManagerStorageExtension.sol/contract.StakeManagerStorageExtension.md) + + +## Functions +### constructor + + +```solidity +constructor() public GovernanceLockable(address(0x0)); +``` + +### startAuction + + +```solidity +function startAuction(uint256 validatorId, uint256 amount, bool _acceptDelegation, bytes calldata _signerPubkey) external; +``` + +### confirmAuctionBid + + +```solidity +function confirmAuctionBid(uint256 validatorId, uint256 heimdallFee, IStakeManager stakeManager) external; +``` + +### migrateValidatorsData + + +```solidity +function migrateValidatorsData(uint256 validatorIdFrom, uint256 validatorIdTo) external; +``` + +### updateCheckpointRewardParams + + +```solidity +function updateCheckpointRewardParams(uint256 _rewardDecreasePerCheckpoint, uint256 _maxRewardedCheckpoints, uint256 _checkpointRewardDelta) external; +``` + +### updateCommissionRate + + +```solidity +function updateCommissionRate(uint256 validatorId, uint256 newCommissionRate) external; +``` + +### _getOrCacheEventsHub + + +```solidity +function _getOrCacheEventsHub() private returns (EventsHub); +``` + diff --git a/docs/autogen/src/contracts/staking/stakeManager/StakeManagerProxy.sol/contract.StakeManagerProxy.md b/docs/autogen/src/contracts/staking/stakeManager/StakeManagerProxy.sol/contract.StakeManagerProxy.md new file mode 100644 index 000000000..e140b12a6 --- /dev/null +++ b/docs/autogen/src/contracts/staking/stakeManager/StakeManagerProxy.sol/contract.StakeManagerProxy.md @@ -0,0 +1,15 @@ +# StakeManagerProxy +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/staking/stakeManager/StakeManagerProxy.sol) + +**Inherits:** +[UpgradableProxy](/contracts/common/misc/UpgradableProxy.sol/contract.UpgradableProxy.md) + + +## Functions +### constructor + + +```solidity +constructor(address _proxyTo) public UpgradableProxy(_proxyTo); +``` + diff --git a/docs/autogen/src/contracts/staking/stakeManager/StakeManagerStorage.sol/contract.StakeManagerStorage.md b/docs/autogen/src/contracts/staking/stakeManager/StakeManagerStorage.sol/contract.StakeManagerStorage.md new file mode 100644 index 000000000..f707a0b41 --- /dev/null +++ b/docs/autogen/src/contracts/staking/stakeManager/StakeManagerStorage.sol/contract.StakeManagerStorage.md @@ -0,0 +1,323 @@ +# StakeManagerStorage +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/staking/stakeManager/StakeManagerStorage.sol) + +**Inherits:** +[GovernanceLockable](/contracts/common/mixin/GovernanceLockable.sol/contract.GovernanceLockable.md), [RootChainable](/contracts/common/mixin/RootChainable.sol/contract.RootChainable.md) + + +## State Variables +### MAX_COMMISION_RATE + +```solidity +uint256 constant MAX_COMMISION_RATE = 100; +``` + + +### MAX_PROPOSER_BONUS + +```solidity +uint256 constant MAX_PROPOSER_BONUS = 100; +``` + + +### REWARD_PRECISION + +```solidity +uint256 constant REWARD_PRECISION = 10 ** 25; +``` + + +### INCORRECT_VALIDATOR_ID + +```solidity +uint256 internal constant INCORRECT_VALIDATOR_ID = 2 ** 256 - 1; +``` + + +### INITIALIZED_AMOUNT + +```solidity +uint256 internal constant INITIALIZED_AMOUNT = 1; +``` + + +### token + +```solidity +IERC20 public token; +``` + + +### registry + +```solidity +address public registry; +``` + + +### logger + +```solidity +StakingInfo public logger; +``` + + +### NFTContract + +```solidity +StakingNFT public NFTContract; +``` + + +### validatorShareFactory + +```solidity +ValidatorShareFactory public validatorShareFactory; +``` + + +### WITHDRAWAL_DELAY + +```solidity +uint256 public WITHDRAWAL_DELAY; +``` + + +### currentEpoch + +```solidity +uint256 public currentEpoch; +``` + + +### dynasty + +```solidity +uint256 public dynasty; +``` + + +### CHECKPOINT_REWARD + +```solidity +uint256 public CHECKPOINT_REWARD; +``` + + +### minDeposit + +```solidity +uint256 public minDeposit; +``` + + +### minHeimdallFee + +```solidity +uint256 public minHeimdallFee; +``` + + +### checkPointBlockInterval + +```solidity +uint256 public checkPointBlockInterval; +``` + + +### signerUpdateLimit + +```solidity +uint256 public signerUpdateLimit; +``` + + +### validatorThreshold + +```solidity +uint256 public validatorThreshold; +``` + + +### totalStaked + +```solidity +uint256 public totalStaked; +``` + + +### NFTCounter + +```solidity +uint256 public NFTCounter; +``` + + +### totalRewards + +```solidity +uint256 public totalRewards; +``` + + +### totalRewardsLiquidated + +```solidity +uint256 public totalRewardsLiquidated; +``` + + +### auctionPeriod + +```solidity +uint256 public auctionPeriod; +``` + + +### proposerBonus + +```solidity +uint256 public proposerBonus; +``` + + +### accountStateRoot + +```solidity +bytes32 public accountStateRoot; +``` + + +### replacementCoolDown + +```solidity +uint256 public replacementCoolDown; +``` + + +### delegationEnabled + +```solidity +bool public delegationEnabled; +``` + + +### validators + +```solidity +mapping(uint256 => Validator) public validators; +``` + + +### signerToValidator + +```solidity +mapping(address => uint256) public signerToValidator; +``` + + +### validatorState + +```solidity +State public validatorState; +``` + + +### validatorStateChanges + +```solidity +mapping(uint256 => StateChange) public validatorStateChanges; +``` + + +### userFeeExit + +```solidity +mapping(address => uint256) public userFeeExit; +``` + + +### validatorAuction + +```solidity +mapping(uint256 => Auction) public validatorAuction; +``` + + +### latestSignerUpdateEpoch + +```solidity +mapping(uint256 => uint256) public latestSignerUpdateEpoch; +``` + + +### totalHeimdallFee + +```solidity +uint256 public totalHeimdallFee; +``` + + +## Structs +### Auction + +```solidity +struct Auction { + uint256 amount; + uint256 startEpoch; + address user; + bool acceptDelegation; + bytes signerPubkey; +} +``` + +### State + +```solidity +struct State { + uint256 amount; + uint256 stakerCount; +} +``` + +### StateChange + +```solidity +struct StateChange { + int256 amount; + int256 stakerCount; +} +``` + +### Validator + +```solidity +struct Validator { + uint256 amount; + uint256 reward; + uint256 activationEpoch; + uint256 deactivationEpoch; + uint256 jailTime; + address signer; + address contractAddress; + Status status; + uint256 commissionRate; + uint256 lastCommissionUpdate; + uint256 delegatorsReward; + uint256 delegatedAmount; + uint256 initialRewardPerStake; +} +``` + +## Enums +### Status + +```solidity +enum Status { + Inactive, + Active, + Locked, + Unstaked +} +``` + diff --git a/docs/autogen/src/contracts/staking/stakeManager/StakeManagerStorageExtension.sol/contract.StakeManagerStorageExtension.md b/docs/autogen/src/contracts/staking/stakeManager/StakeManagerStorageExtension.sol/contract.StakeManagerStorageExtension.md new file mode 100644 index 000000000..971571627 --- /dev/null +++ b/docs/autogen/src/contracts/staking/stakeManager/StakeManagerStorageExtension.sol/contract.StakeManagerStorageExtension.md @@ -0,0 +1,68 @@ +# StakeManagerStorageExtension +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/staking/stakeManager/StakeManagerStorageExtension.sol) + + +## State Variables +### eventsHub + +```solidity +address public eventsHub; +``` + + +### rewardPerStake + +```solidity +uint256 public rewardPerStake; +``` + + +### extensionCode + +```solidity +address public extensionCode; +``` + + +### signers + +```solidity +address[] public signers; +``` + + +### CHK_REWARD_PRECISION + +```solidity +uint256 constant CHK_REWARD_PRECISION = 100; +``` + + +### prevBlockInterval + +```solidity +uint256 public prevBlockInterval; +``` + + +### rewardDecreasePerCheckpoint + +```solidity +uint256 public rewardDecreasePerCheckpoint; +``` + + +### maxRewardedCheckpoints + +```solidity +uint256 public maxRewardedCheckpoints; +``` + + +### checkpointRewardDelta + +```solidity +uint256 public checkpointRewardDelta; +``` + + diff --git a/docs/autogen/src/contracts/staking/stakeManager/StakingNFT.sol/contract.StakingNFT.md b/docs/autogen/src/contracts/staking/stakeManager/StakingNFT.sol/contract.StakingNFT.md new file mode 100644 index 000000000..56c859569 --- /dev/null +++ b/docs/autogen/src/contracts/staking/stakeManager/StakingNFT.sol/contract.StakingNFT.md @@ -0,0 +1,36 @@ +# StakingNFT +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/staking/stakeManager/StakingNFT.sol) + +**Inherits:** +ERC721Full, Ownable + + +## Functions +### constructor + + +```solidity +constructor(string memory name, string memory symbol) public ERC721Full(name, symbol); +``` + +### mint + + +```solidity +function mint(address to, uint256 tokenId) public onlyOwner; +``` + +### burn + + +```solidity +function burn(uint256 tokenId) public onlyOwner; +``` + +### _transferFrom + + +```solidity +function _transferFrom(address from, address to, uint256 tokenId) internal; +``` + diff --git a/docs/autogen/src/contracts/staking/validatorShare/IValidatorShare.sol/contract.IValidatorShare.md b/docs/autogen/src/contracts/staking/validatorShare/IValidatorShare.sol/contract.IValidatorShare.md new file mode 100644 index 000000000..7a7167794 --- /dev/null +++ b/docs/autogen/src/contracts/staking/validatorShare/IValidatorShare.sol/contract.IValidatorShare.md @@ -0,0 +1,89 @@ +# IValidatorShare +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/staking/validatorShare/IValidatorShare.sol) + + +## Functions +### withdrawRewards + + +```solidity +function withdrawRewards() public; +``` + +### unstakeClaimTokens + + +```solidity +function unstakeClaimTokens() public; +``` + +### getLiquidRewards + + +```solidity +function getLiquidRewards(address user) public view returns (uint256); +``` + +### owner + + +```solidity +function owner() public view returns (address); +``` + +### restake + + +```solidity +function restake() public returns (uint256, uint256); +``` + +### unlock + + +```solidity +function unlock() external; +``` + +### lock + + +```solidity +function lock() external; +``` + +### drain + + +```solidity +function drain(address token, address payable destination, uint256 amount) external; +``` + +### slash + + +```solidity +function slash(uint256 valPow, uint256 delegatedAmount, uint256 totalAmountToSlash) external returns (uint256); +``` + +### updateDelegation + + +```solidity +function updateDelegation(bool delegation) external; +``` + +### migrateOut + + +```solidity +function migrateOut(address user, uint256 amount) external; +``` + +### migrateIn + + +```solidity +function migrateIn(address user, uint256 amount) external; +``` + diff --git a/docs/autogen/src/contracts/staking/validatorShare/README.md b/docs/autogen/src/contracts/staking/validatorShare/README.md new file mode 100644 index 000000000..ede1bc4c3 --- /dev/null +++ b/docs/autogen/src/contracts/staking/validatorShare/README.md @@ -0,0 +1,7 @@ + + +# Contents +- [IValidatorShare](IValidatorShare.sol/contract.IValidatorShare.md) +- [ValidatorShare](ValidatorShare.sol/contract.ValidatorShare.md) +- [ValidatorShareFactory](ValidatorShareFactory.sol/contract.ValidatorShareFactory.md) +- [ValidatorShareProxy](ValidatorShareProxy.sol/contract.ValidatorShareProxy.md) diff --git a/docs/autogen/src/contracts/staking/validatorShare/ValidatorShare.sol/contract.ValidatorShare.md b/docs/autogen/src/contracts/staking/validatorShare/ValidatorShare.sol/contract.ValidatorShare.md new file mode 100644 index 000000000..bb28a887f --- /dev/null +++ b/docs/autogen/src/contracts/staking/validatorShare/ValidatorShare.sol/contract.ValidatorShare.md @@ -0,0 +1,384 @@ +# ValidatorShare +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/staking/validatorShare/ValidatorShare.sol) + +**Inherits:** +[IValidatorShare](/contracts/staking/validatorShare/IValidatorShare.sol/contract.IValidatorShare.md), [ERC20NonTradable](/contracts/common/tokens/ERC20NonTradable.sol/contract.ERC20NonTradable.md), [OwnableLockable](/contracts/common/mixin/OwnableLockable.sol/contract.OwnableLockable.md), [Initializable](/contracts/common/mixin/Initializable.sol/contract.Initializable.md) + + +## State Variables +### EXCHANGE_RATE_PRECISION + +```solidity +uint256 constant EXCHANGE_RATE_PRECISION = 100; +``` + + +### EXCHANGE_RATE_HIGH_PRECISION + +```solidity +uint256 constant EXCHANGE_RATE_HIGH_PRECISION = 10 ** 29; +``` + + +### MAX_COMMISION_RATE + +```solidity +uint256 constant MAX_COMMISION_RATE = 100; +``` + + +### REWARD_PRECISION + +```solidity +uint256 constant REWARD_PRECISION = 10 ** 25; +``` + + +### stakingLogger + +```solidity +StakingInfo public stakingLogger; +``` + + +### stakeManager + +```solidity +IStakeManager public stakeManager; +``` + + +### validatorId + +```solidity +uint256 public validatorId; +``` + + +### validatorRewards_deprecated + +```solidity +uint256 public validatorRewards_deprecated; +``` + + +### commissionRate_deprecated + +```solidity +uint256 public commissionRate_deprecated; +``` + + +### lastCommissionUpdate_deprecated + +```solidity +uint256 public lastCommissionUpdate_deprecated; +``` + + +### minAmount + +```solidity +uint256 public minAmount; +``` + + +### totalStake_deprecated + +```solidity +uint256 public totalStake_deprecated; +``` + + +### rewardPerShare + +```solidity +uint256 public rewardPerShare; +``` + + +### activeAmount + +```solidity +uint256 public activeAmount; +``` + + +### delegation + +```solidity +bool public delegation; +``` + + +### withdrawPool + +```solidity +uint256 public withdrawPool; +``` + + +### withdrawShares + +```solidity +uint256 public withdrawShares; +``` + + +### amountStaked_deprecated + +```solidity +mapping(address => uint256) amountStaked_deprecated; +``` + + +### unbonds + +```solidity +mapping(address => DelegatorUnbond) public unbonds; +``` + + +### initalRewardPerShare + +```solidity +mapping(address => uint256) public initalRewardPerShare; +``` + + +### unbondNonces + +```solidity +mapping(address => uint256) public unbondNonces; +``` + + +### unbonds_new + +```solidity +mapping(address => mapping(uint256 => DelegatorUnbond)) public unbonds_new; +``` + + +### eventsHub + +```solidity +EventsHub public eventsHub; +``` + + +## Functions +### initialize + + +```solidity +function initialize(uint256 _validatorId, address _stakingLogger, address _stakeManager) external initializer; +``` + +### exchangeRate + +Public View Methods + + +```solidity +function exchangeRate() public view returns (uint256); +``` + +### getTotalStake + + +```solidity +function getTotalStake(address user) public view returns (uint256, uint256); +``` + +### withdrawExchangeRate + + +```solidity +function withdrawExchangeRate() public view returns (uint256); +``` + +### getLiquidRewards + + +```solidity +function getLiquidRewards(address user) public view returns (uint256); +``` + +### getRewardPerShare + + +```solidity +function getRewardPerShare() public view returns (uint256); +``` + +### buyVoucher + +Public Methods + + +```solidity +function buyVoucher(uint256 _amount, uint256 _minSharesToMint) public returns (uint256 amountToDeposit); +``` + +### restake + + +```solidity +function restake() public returns (uint256, uint256); +``` + +### sellVoucher + + +```solidity +function sellVoucher(uint256 claimAmount, uint256 maximumSharesToBurn) public; +``` + +### withdrawRewards + + +```solidity +function withdrawRewards() public; +``` + +### migrateOut + + +```solidity +function migrateOut(address user, uint256 amount) external onlyOwner; +``` + +### migrateIn + + +```solidity +function migrateIn(address user, uint256 amount) external onlyOwner; +``` + +### unstakeClaimTokens + + +```solidity +function unstakeClaimTokens() public; +``` + +### slash + + +```solidity +function slash(uint256 validatorStake, uint256 delegatedAmount, uint256 totalAmountToSlash) external onlyOwner returns (uint256); +``` + +### updateDelegation + + +```solidity +function updateDelegation(bool _delegation) external onlyOwner; +``` + +### drain + + +```solidity +function drain(address token, address payable destination, uint256 amount) external onlyOwner; +``` + +### sellVoucher_new + +New shares exit API + + +```solidity +function sellVoucher_new(uint256 claimAmount, uint256 maximumSharesToBurn) public; +``` + +### unstakeClaimTokens_new + + +```solidity +function unstakeClaimTokens_new(uint256 unbondNonce) public; +``` + +### _getOrCacheEventsHub + +Private Methods + + +```solidity +function _getOrCacheEventsHub() private returns (EventsHub); +``` + +### _sellVoucher + + +```solidity +function _sellVoucher(uint256 claimAmount, uint256 maximumSharesToBurn) private returns (uint256, uint256); +``` + +### _unstakeClaimTokens + + +```solidity +function _unstakeClaimTokens(DelegatorUnbond memory unbond) private returns (uint256); +``` + +### _getRatePrecision + + +```solidity +function _getRatePrecision() private view returns (uint256); +``` + +### _calculateRewardPerShareWithRewards + + +```solidity +function _calculateRewardPerShareWithRewards(uint256 accumulatedReward) private view returns (uint256); +``` + +### _calculateReward + + +```solidity +function _calculateReward(address user, uint256 _rewardPerShare) private view returns (uint256); +``` + +### _withdrawReward + + +```solidity +function _withdrawReward(address user) private returns (uint256); +``` + +### _withdrawAndTransferReward + + +```solidity +function _withdrawAndTransferReward(address user) private returns (uint256); +``` + +### _buyShares + + +```solidity +function _buyShares(uint256 _amount, uint256 _minSharesToMint, address user) private onlyWhenUnlocked returns (uint256); +``` + +### _transfer + + +```solidity +function _transfer(address from, address to, uint256 value) internal; +``` + +## Structs +### DelegatorUnbond + +```solidity +struct DelegatorUnbond { + uint256 shares; + uint256 withdrawEpoch; +} +``` + diff --git a/docs/autogen/src/contracts/staking/validatorShare/ValidatorShareFactory.sol/contract.ValidatorShareFactory.md b/docs/autogen/src/contracts/staking/validatorShare/ValidatorShareFactory.sol/contract.ValidatorShareFactory.md new file mode 100644 index 000000000..fd57ab320 --- /dev/null +++ b/docs/autogen/src/contracts/staking/validatorShare/ValidatorShareFactory.sol/contract.ValidatorShareFactory.md @@ -0,0 +1,14 @@ +# ValidatorShareFactory +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/staking/validatorShare/ValidatorShareFactory.sol) + + +## Functions +### create + +- factory to create new validatorShare contracts + + +```solidity +function create(uint256 validatorId, address loggerAddress, address registry) public returns (address); +``` + diff --git a/docs/autogen/src/contracts/staking/validatorShare/ValidatorShareProxy.sol/contract.ValidatorShareProxy.md b/docs/autogen/src/contracts/staking/validatorShare/ValidatorShareProxy.sol/contract.ValidatorShareProxy.md new file mode 100644 index 000000000..71aa467de --- /dev/null +++ b/docs/autogen/src/contracts/staking/validatorShare/ValidatorShareProxy.sol/contract.ValidatorShareProxy.md @@ -0,0 +1,22 @@ +# ValidatorShareProxy +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/staking/validatorShare/ValidatorShareProxy.sol) + +**Inherits:** +[UpgradableProxy](/contracts/common/misc/UpgradableProxy.sol/contract.UpgradableProxy.md) + + +## Functions +### constructor + + +```solidity +constructor(address _registry) public UpgradableProxy(_registry); +``` + +### loadImplementation + + +```solidity +function loadImplementation() internal view returns (address); +``` + diff --git a/docs/autogen/src/contracts/test/ContractActor.sol/contract.ContractWitRevertingFallback.md b/docs/autogen/src/contracts/test/ContractActor.sol/contract.ContractWitRevertingFallback.md new file mode 100644 index 000000000..93f81dac9 --- /dev/null +++ b/docs/autogen/src/contracts/test/ContractActor.sol/contract.ContractWitRevertingFallback.md @@ -0,0 +1,26 @@ +# ContractWitRevertingFallback +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/test/ContractActor.sol) + + +## Functions +### deposit + + +```solidity +function deposit(address depositManager, address token, uint256 amount) public; +``` + +### startExitWithDepositedTokens + + +```solidity +function startExitWithDepositedTokens(address payable withdrawManager, uint256 depositId, address token, uint256 amountOrToken) public payable; +``` + +### function + + +```solidity +function() external payable; +``` + diff --git a/docs/autogen/src/contracts/test/ContractActor.sol/contract.ContractWithFallback.md b/docs/autogen/src/contracts/test/ContractActor.sol/contract.ContractWithFallback.md new file mode 100644 index 000000000..8fdecc630 --- /dev/null +++ b/docs/autogen/src/contracts/test/ContractActor.sol/contract.ContractWithFallback.md @@ -0,0 +1,26 @@ +# ContractWithFallback +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/test/ContractActor.sol) + + +## Functions +### deposit + + +```solidity +function deposit(address depositManager, address token, uint256 amount) public; +``` + +### startExitWithDepositedTokens + + +```solidity +function startExitWithDepositedTokens(address payable withdrawManager, uint256 depositId, address token, uint256 amountOrToken) public payable; +``` + +### function + + +```solidity +function() external payable; +``` + diff --git a/docs/autogen/src/contracts/test/ContractActor.sol/contract.ContractWithoutFallback.md b/docs/autogen/src/contracts/test/ContractActor.sol/contract.ContractWithoutFallback.md new file mode 100644 index 000000000..b1c50b2e8 --- /dev/null +++ b/docs/autogen/src/contracts/test/ContractActor.sol/contract.ContractWithoutFallback.md @@ -0,0 +1,19 @@ +# ContractWithoutFallback +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/test/ContractActor.sol) + + +## Functions +### deposit + + +```solidity +function deposit(address depositManager, address token, uint256 amount) public; +``` + +### startExitWithDepositedTokens + + +```solidity +function startExitWithDepositedTokens(address payable withdrawManager, uint256 depositId, address token, uint256 amountOrToken) public payable; +``` + diff --git a/docs/autogen/src/contracts/test/GovernanceLockableTest.sol/contract.GovernanceLockableTest.md b/docs/autogen/src/contracts/test/GovernanceLockableTest.sol/contract.GovernanceLockableTest.md new file mode 100644 index 000000000..3d1b00449 --- /dev/null +++ b/docs/autogen/src/contracts/test/GovernanceLockableTest.sol/contract.GovernanceLockableTest.md @@ -0,0 +1,15 @@ +# GovernanceLockableTest +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/test/GovernanceLockableTest.sol) + +**Inherits:** +[GovernanceLockable](/contracts/common/mixin/GovernanceLockable.sol/contract.GovernanceLockable.md) + + +## Functions +### constructor + + +```solidity +constructor(address governance) public GovernanceLockable(governance); +``` + diff --git a/docs/autogen/src/contracts/test/MarketplacePredicateTest.sol/contract.MarketplacePredicateTest.md b/docs/autogen/src/contracts/test/MarketplacePredicateTest.sol/contract.MarketplacePredicateTest.md new file mode 100644 index 000000000..3d2c8cafc --- /dev/null +++ b/docs/autogen/src/contracts/test/MarketplacePredicateTest.sol/contract.MarketplacePredicateTest.md @@ -0,0 +1,43 @@ +# MarketplacePredicateTest +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/test/MarketplacePredicateTest.sol) + +**Inherits:** +[MarketplacePredicate](/contracts/root/predicates/MarketplacePredicate.sol/contract.MarketplacePredicate.md) + + +## Functions +### constructor + + +```solidity +constructor() public MarketplacePredicate(address(0x0), address(0x0), address(0x0)); +``` + +### processLogTransferReceiptTest + + +```solidity +function processLogTransferReceiptTest(address predicate, bytes memory data, address participant) public view returns (bytes memory b); +``` + +### processExitTx + + +```solidity +function processExitTx(bytes memory exitTx) public view returns (bytes memory b); +``` + +### testGetAddressFromTx + + +```solidity +function testGetAddressFromTx(bytes memory exitTx) public pure returns (address signer, bytes32 txHash); +``` + +### decodeExitTx + + +```solidity +function decodeExitTx(bytes memory exitTx) internal pure returns (ExitTxData memory txData); +``` + diff --git a/docs/autogen/src/contracts/test/PolygonMigrationTest.sol/contract.PolygonMigrationTest.md b/docs/autogen/src/contracts/test/PolygonMigrationTest.sol/contract.PolygonMigrationTest.md new file mode 100644 index 000000000..e58f7cef9 --- /dev/null +++ b/docs/autogen/src/contracts/test/PolygonMigrationTest.sol/contract.PolygonMigrationTest.md @@ -0,0 +1,51 @@ +# PolygonMigrationTest +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/test/PolygonMigrationTest.sol) + + +## State Variables +### polygon + +```solidity +IERC20 public polygon; +``` + + +### matic + +```solidity +IERC20 public matic; +``` + + +## Functions +### setTokenAddresses + + +```solidity +function setTokenAddresses(address matic_, address polygon_) external; +``` + +### migrate + +This function allows for migrating MATIC tokens to POL tokens + +*The function does not do any validation since the migration is a one-way process* + + +```solidity +function migrate(uint256 amount) external; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`amount`|`uint256`|Amount of MATIC to migrate| + + +## Events +### Migrated + +```solidity +event Migrated(address indexed account, uint256 amount); +``` + diff --git a/docs/autogen/src/contracts/test/Proxy/ProxyTestImpl.sol/contract.ProxyTestImpl.md b/docs/autogen/src/contracts/test/Proxy/ProxyTestImpl.sol/contract.ProxyTestImpl.md new file mode 100644 index 000000000..ce276e241 --- /dev/null +++ b/docs/autogen/src/contracts/test/Proxy/ProxyTestImpl.sol/contract.ProxyTestImpl.md @@ -0,0 +1,44 @@ +# ProxyTestImpl +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/test/Proxy/ProxyTestImpl.sol) + +**Inherits:** +[Initializable](/contracts/common/mixin/Initializable.sol/contract.Initializable.md) + + +## State Variables +### a + +```solidity +uint256 public a = 1; +``` + + +### b + +```solidity +uint256 public b = 2; +``` + + +### ctorInit + +```solidity +uint256 public ctorInit; +``` + + +## Functions +### constructor + + +```solidity +constructor() public; +``` + +### init + + +```solidity +function init() public initializer; +``` + diff --git a/docs/autogen/src/contracts/test/Proxy/ProxyTestImplStorageLayoutChange.sol/contract.ProxyTestImplStorageLayoutChange.md b/docs/autogen/src/contracts/test/Proxy/ProxyTestImplStorageLayoutChange.sol/contract.ProxyTestImplStorageLayoutChange.md new file mode 100644 index 000000000..aa12a36fb --- /dev/null +++ b/docs/autogen/src/contracts/test/Proxy/ProxyTestImplStorageLayoutChange.sol/contract.ProxyTestImplStorageLayoutChange.md @@ -0,0 +1,22 @@ +# ProxyTestImplStorageLayoutChange +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/test/Proxy/ProxyTestImplStorageLayoutChange.sol) + +**Inherits:** +[Initializable](/contracts/common/mixin/Initializable.sol/contract.Initializable.md) + + +## State Variables +### b + +```solidity +uint256 public b; +``` + + +### a + +```solidity +uint256 public a; +``` + + diff --git a/docs/autogen/src/contracts/test/Proxy/README.md b/docs/autogen/src/contracts/test/Proxy/README.md new file mode 100644 index 000000000..37c1893c8 --- /dev/null +++ b/docs/autogen/src/contracts/test/Proxy/README.md @@ -0,0 +1,5 @@ + + +# Contents +- [ProxyTestImpl](ProxyTestImpl.sol/contract.ProxyTestImpl.md) +- [ProxyTestImplStorageLayoutChange](ProxyTestImplStorageLayoutChange.sol/contract.ProxyTestImplStorageLayoutChange.md) diff --git a/docs/autogen/src/contracts/test/README.md b/docs/autogen/src/contracts/test/README.md new file mode 100644 index 000000000..992c35b5e --- /dev/null +++ b/docs/autogen/src/contracts/test/README.md @@ -0,0 +1,14 @@ + + +# Contents +- [Proxy](/contracts/test/Proxy) +- [ContractWithFallback](ContractActor.sol/contract.ContractWithFallback.md) +- [ContractWithoutFallback](ContractActor.sol/contract.ContractWithoutFallback.md) +- [ContractWitRevertingFallback](ContractActor.sol/contract.ContractWitRevertingFallback.md) +- [GovernanceLockableTest](GovernanceLockableTest.sol/contract.GovernanceLockableTest.md) +- [MarketplacePredicateTest](MarketplacePredicateTest.sol/contract.MarketplacePredicateTest.md) +- [PolygonMigrationTest](PolygonMigrationTest.sol/contract.PolygonMigrationTest.md) +- [StakeManagerTest](StakeManagerTest.sol/contract.StakeManagerTest.md) +- [StakeManagerTestable](StakeManagerTestable.sol/contract.StakeManagerTestable.md) +- [TestMRC20](TestMaticChildERC20.sol/contract.TestMRC20.md) +- [ValidatorShareTest](ValidatorShareTest.sol/contract.ValidatorShareTest.md) diff --git a/docs/autogen/src/contracts/test/StakeManagerTest.sol/contract.StakeManagerTest.md b/docs/autogen/src/contracts/test/StakeManagerTest.sol/contract.StakeManagerTest.md new file mode 100644 index 000000000..d91ae84a5 --- /dev/null +++ b/docs/autogen/src/contracts/test/StakeManagerTest.sol/contract.StakeManagerTest.md @@ -0,0 +1,18 @@ +# StakeManagerTest +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/test/StakeManagerTest.sol) + +**Inherits:** +[StakeManager](/contracts/staking/stakeManager/StakeManager.sol/contract.StakeManager.md) + + +## Functions +### checkSignatures + + +```solidity +function checkSignatures(uint256 blockInterval, bytes32 voteHash, bytes32 stateRoot, address proposer, uint256[3][] calldata sigs) + external + onlyRootChain + returns (uint256); +``` + diff --git a/docs/autogen/src/contracts/test/StakeManagerTestable.sol/contract.StakeManagerTestable.md b/docs/autogen/src/contracts/test/StakeManagerTestable.sol/contract.StakeManagerTestable.md new file mode 100644 index 000000000..65c3bf8fe --- /dev/null +++ b/docs/autogen/src/contracts/test/StakeManagerTestable.sol/contract.StakeManagerTestable.md @@ -0,0 +1,36 @@ +# StakeManagerTestable +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/test/StakeManagerTestable.sol) + +**Inherits:** +[StakeManager](/contracts/staking/stakeManager/StakeManager.sol/contract.StakeManager.md) + + +## Functions +### advanceEpoch + + +```solidity +function advanceEpoch(uint256 delta) public; +``` + +### testLockShareContract + + +```solidity +function testLockShareContract(uint256 validatorId, bool lock) public; +``` + +### forceFinalizeCommit + + +```solidity +function forceFinalizeCommit() public; +``` + +### resetSignerUsed + + +```solidity +function resetSignerUsed(address signer) public; +``` + diff --git a/docs/autogen/src/contracts/test/TestMaticChildERC20.sol/contract.TestMRC20.md b/docs/autogen/src/contracts/test/TestMaticChildERC20.sol/contract.TestMRC20.md new file mode 100644 index 000000000..81134ef73 --- /dev/null +++ b/docs/autogen/src/contracts/test/TestMaticChildERC20.sol/contract.TestMRC20.md @@ -0,0 +1,15 @@ +# TestMRC20 +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/test/TestMaticChildERC20.sol) + +**Inherits:** +[MRC20](/contracts/child/MRC20.sol/contract.MRC20.md) + + +## Functions +### function + + +```solidity +function() external payable; +``` + diff --git a/docs/autogen/src/contracts/test/ValidatorShareTest.sol/contract.ValidatorShareTest.md b/docs/autogen/src/contracts/test/ValidatorShareTest.sol/contract.ValidatorShareTest.md new file mode 100644 index 000000000..a24b1282f --- /dev/null +++ b/docs/autogen/src/contracts/test/ValidatorShareTest.sol/contract.ValidatorShareTest.md @@ -0,0 +1,15 @@ +# ValidatorShareTest +[Git Source](https://github.com/maticnetwork/contracts/blob/155f729fd8db0676297384375468d4d45b8aa44e/contracts/test/ValidatorShareTest.sol) + +**Inherits:** +[ValidatorShare](/contracts/staking/validatorShare/ValidatorShare.sol/contract.ValidatorShare.md) + + +## Functions +### amountStaked + + +```solidity +function amountStaked(address user) public view returns (uint256); +``` + diff --git a/foundry.toml b/foundry.toml new file mode 100644 index 000000000..e0a6f2d57 --- /dev/null +++ b/foundry.toml @@ -0,0 +1,53 @@ +[profile.default] +src = 'contracts' +out = 'out' +libs = ['node_modules'] +match-path = 'test/foundry' +optimizer = true +optimizer_runs = 200 +via_ir = true +cache_path = 'forge-cache' +verbosity = 2 +solc_version = '0.5.17' +ffi = true + +remappings = [ + "openzeppelin-solidity/=node_modules/openzeppelin-solidity/", + "solidity-rlp/=node_modules/solidity-rlp/" +] + +[invariant] +fail_on_revert = false +call_override = false +dictionary_weight = 80 +include_storage = true +include_push_bytes = true + +[profile.intense.fuzz] +runs = 10000 +max_test_rejects = 999999 + +[fmt] +line_length = 160 +number_underscore = "thousands" + +[rpc_endpoints] +anvil = "http://127.0.0.1:8545" +mainnet = "https://mainnet.infura.io/v3/${INFURA_KEY}" +goerli = "https://goerli.infura.io/v3/${INFURA_KEY}" +sepolia = "https://sepolia.infura.io/v3/${INFURA_KEY}" +polygon_pos = "https://polygon-mainnet.infura.io/v3/${INFURA_KEY}" +mumbai = "https://polygon-mumbai.infura.io/v3/${INFURA_KEY}" +polygon_zkevm = "https://zkevm-rpc.com" +polygon_zkevm_testnet = "https://rpc.public.zkevm-test.net" + +[etherscan] +mainnet = { key = "${ETHERSCAN_API_KEY}" } +goerli = { key = "${ETHERSCAN_API_KEY}" } +sepolia = { key = "${ETHERSCAN_API_KEY}" } +polygon_pos = { key = "${POLYGONSCAN_API_KEY}" } +mumbai = { key = "${POLYGONSCAN_API_KEY}" } +polygon_zkevm = { key = "${POLYGONSCAN_ZKEVM_API_KEY}" } +polygon_zkevm_testnet = { key = "${POLYGONSCAN_ZKEVM_API_KEY}" } + +# See more config options https://github.com/foundry-rs/foundry/tree/master/config \ No newline at end of file diff --git a/hardhat.config.cjs b/hardhat.config.cjs new file mode 100644 index 000000000..ae9d72bd2 --- /dev/null +++ b/hardhat.config.cjs @@ -0,0 +1,94 @@ +require("@nomicfoundation/hardhat-toolbox"); +require("@nomiclabs/hardhat-web3"); +const task = require("hardhat/config").task; +require("dotenv").config(); + +const importToml = require("import-toml"); +const foundryConfig = importToml.sync("foundry.toml"); + +const baseConfig = { + defaultNetwork: "hardhat", + networks: { + hardhat: { + forking: { + url: `https://mainnet.infura.io/v3/${process.env.INFURA_TOKEN}`, + blockNumber: 18364580, + }, + // set this here because it is the limit of the bor testchain + // and we can only set this once for all hardhat tests + blockGasLimit: 20000000, + allowUnlimitedContractSize: true, + accounts: { + mnemonic: + "clock radar mass judge dismiss just intact mind resemble fringe diary casino", + }, + }, + }, + solidity: { + version: foundryConfig.profile.default.solc_version, + settings: { + optimizer: { + enabled: true, + runs: foundryConfig.profile.default.optimizer_runs, + }, + }, + }, + paths: { + sources: "./contracts", + cache: "./cache_hardhat", + tests: "./test", + }, +}; + +const networks = () => { + if (process.env.ENV === "dev") { + return { + ...baseConfig.networks, + sepolia: { + url: "https://sepolia.infura.io/v3/" + process.env.INFURA_TOKEN, + accounts: { + mnemonic: process.env.MNEMONIC_DEV, + }, + }, + }; + } else if (process.env.ENV === "prod") { + return { + ...baseConfig.networks, + mainnet: { + url: "https://mainnet.infura.io/v3/" + process.env.INFURA_TOKEN, + accounts: [process.env.PK_MAINNET], + }, + }; + } else if (process.env.LOCAL_NETWORK) { + console.log("using local hardhat network"); + return { + hardhat: { + blockGasLimit: 20000000, + allowUnlimitedContractSize: true, + accounts: { + mnemonic: + "clock radar mass judge dismiss just intact mind resemble fringe diary casino", + }, + }, + }; + } + return baseConfig.networks; +}; + +const config = { + ...baseConfig, + networks: networks(), + etherscan: !process.env.ETHERSCAN_TOKEN + ? {} + : { apiKey: process.env.ETHERSCAN_TOKEN }, +}; + +task("accounts", "Prints the list of accounts", async (_, hre) => { + const accounts = await hre.ethers.getSigners(); + + for (const account of accounts) { + console.log(await account.address); + } +}); + +module.exports = config; diff --git a/migrations/1_initial_migration.js b/migrations/1_initial_migration.js deleted file mode 100644 index 1eb6f9daf..000000000 --- a/migrations/1_initial_migration.js +++ /dev/null @@ -1,5 +0,0 @@ -var Migrations = artifacts.require('./Migrations.sol') - -module.exports = function(deployer) { - deployer.deploy(Migrations) -} diff --git a/migrations/2_deploy_root_contracts.js b/migrations/2_deploy_root_contracts.js deleted file mode 100644 index bad2271c7..000000000 --- a/migrations/2_deploy_root_contracts.js +++ /dev/null @@ -1,308 +0,0 @@ -// Deploy minimal number of contracts to link the libraries with the contracts -const utils = require('./utils') - -const bluebird = require('bluebird') - -const SafeMath = artifacts.require( - 'openzeppelin-solidity/contracts/math/SafeMath.sol' -) - -const RLPReader = artifacts.require('solidity-rlp/contracts/RLPReader.sol') - -const BytesLib = artifacts.require('BytesLib') -const Common = artifacts.require('Common') -const ECVerify = artifacts.require('ECVerify') -const Merkle = artifacts.require('Merkle') -const MerklePatriciaProof = artifacts.require('MerklePatriciaProof') -const PriorityQueue = artifacts.require('PriorityQueue') -const RLPEncode = artifacts.require('RLPEncode') - -const Registry = artifacts.require('Registry') -const Governance = artifacts.require('Governance') -const GovernanceProxy = artifacts.require('GovernanceProxy') -const RootChain = artifacts.require('RootChain') -const RootChainProxy = artifacts.require('RootChainProxy') -const DepositManager = artifacts.require('DepositManager') -const DepositManagerProxy = artifacts.require('DepositManagerProxy') -const WithdrawManager = artifacts.require('WithdrawManager') -const WithdrawManagerProxy = artifacts.require('WithdrawManagerProxy') -const StateSender = artifacts.require('StateSender') -const StakeManager = artifacts.require('StakeManager') -const StakeManagerProxy = artifacts.require('StakeManagerProxy') -const SlashingManager = artifacts.require('SlashingManager') -const StakingInfo = artifacts.require('StakingInfo') -const StakingNFT = artifacts.require('StakingNFT') -const ValidatorShareFactory = artifacts.require('ValidatorShareFactory') -const ValidatorShare = artifacts.require('ValidatorShare') -const ERC20Predicate = artifacts.require('ERC20Predicate') -const ERC721Predicate = artifacts.require('ERC721Predicate') -const MintableERC721Predicate = artifacts.require('MintableERC721Predicate') -const Marketplace = artifacts.require('Marketplace') -const MarketplacePredicate = artifacts.require('MarketplacePredicate') -const MarketplacePredicateTest = artifacts.require('MarketplacePredicateTest') -const TransferWithSigPredicate = artifacts.require('TransferWithSigPredicate') -const TransferWithSigUtils = artifacts.require('TransferWithSigUtils') - -const StakeManagerTestable = artifacts.require('StakeManagerTestable') -const StakeManagerTest = artifacts.require('StakeManagerTest') - -const ExitNFT = artifacts.require('ExitNFT') -const MaticWeth = artifacts.require('MaticWETH') -const TestToken = artifacts.require('TestToken') -const RootERC721 = artifacts.require('RootERC721') - -const StakeManagerExtension = artifacts.require('StakeManagerExtension') -const EventsHub = artifacts.require('EventsHub') -const EventsHubProxy = artifacts.require('EventsHubProxy') - -const ZeroAddress = '0x0000000000000000000000000000000000000000'; - -const libDeps = [ - { - lib: BytesLib, - contracts: [WithdrawManager, ERC20Predicate, ERC721Predicate, MintableERC721Predicate] - }, - { - lib: Common, - contracts: [ - WithdrawManager, - ERC20Predicate, - ERC721Predicate, - MintableERC721Predicate, - MarketplacePredicate, - MarketplacePredicateTest, - TransferWithSigPredicate - ] - }, - { - lib: ECVerify, - contracts: [ - StakeManager, - SlashingManager, - StakeManagerTestable, - MarketplacePredicate, - MarketplacePredicateTest, - TransferWithSigPredicate - ] - }, - { - lib: Merkle, - contracts: [ - WithdrawManager, - ERC20Predicate, - ERC721Predicate, - MintableERC721Predicate, - StakeManager, - StakeManagerTestable, - StakeManagerTest - ] - }, - { - lib: MerklePatriciaProof, - contracts: [WithdrawManager, ERC20Predicate, ERC721Predicate, MintableERC721Predicate] - }, - { - lib: PriorityQueue, - contracts: [WithdrawManager] - }, - { - lib: RLPEncode, - contracts: [ - WithdrawManager, - ERC20Predicate, - ERC721Predicate, - MintableERC721Predicate, - MarketplacePredicate, - MarketplacePredicateTest - ] - }, - { - lib: RLPReader, - contracts: [ - RootChain, - StakeManager, - ERC20Predicate, - ERC721Predicate, - MintableERC721Predicate, - MarketplacePredicate, - MarketplacePredicateTest - ] - }, - { - lib: SafeMath, - contracts: [ - RootChain, - ERC20Predicate, - ERC721Predicate, - MintableERC721Predicate, - MarketplacePredicate, - MarketplacePredicateTest, - TransferWithSigPredicate, - StakeManager, - SlashingManager, - StakingInfo, - StateSender, - StakeManagerExtension - ] - }, - { - lib: SafeMath, - contracts: [RootChain, ERC20Predicate] - }, - { - lib: TransferWithSigUtils, - contracts: [ - TransferWithSigPredicate, - MarketplacePredicate, - MarketplacePredicateTest - ] - } -] - -module.exports = async function(deployer, network, accounts) { - if (!process.env.HEIMDALL_ID) { - console.log('HEIMDALL_ID is not set; defaulting to heimdall-P5rXwg') - process.env.HEIMDALL_ID = 'heimdall-P5rXwg' - } - - deployer.then(async() => { - await bluebird.map(libDeps, async e => { - await deployer.deploy(e.lib) - deployer.link(e.lib, e.contracts) - }) - - await deployer.deploy(Governance) - await deployer.deploy(GovernanceProxy, Governance.address) - await deployer.deploy(Registry, GovernanceProxy.address) - await deployer.deploy(ValidatorShareFactory) - await deployer.deploy(ValidatorShare) - const maticToken = await deployer.deploy(TestToken, 'MATIC', 'MATIC') - await deployer.deploy(TestToken, 'Test ERC20', 'TEST20') - await deployer.deploy(RootERC721, 'Test ERC721', 'TST721') - await deployer.deploy(StakingInfo, Registry.address) - await deployer.deploy(StakingNFT, 'Matic Validator', 'MV') - - await deployer.deploy(RootChain) - await deployer.deploy(RootChainProxy, RootChain.address, Registry.address, process.env.HEIMDALL_ID) - await deployer.deploy(StateSender) - await deployer.deploy(StakeManagerTestable) - await deployer.deploy(StakeManagerTest) - - await deployer.deploy(DepositManager) - await deployer.deploy( - DepositManagerProxy, - DepositManager.address, - Registry.address, - RootChainProxy.address, - GovernanceProxy.address - ) - - await deployer.deploy(ExitNFT, Registry.address) - await deployer.deploy(WithdrawManager) - await deployer.deploy( - WithdrawManagerProxy, - WithdrawManager.address, - Registry.address, - RootChainProxy.address, - ExitNFT.address - ) - - { - let eventsHubImpl = await deployer.deploy(EventsHub) - let proxy = await deployer.deploy(EventsHubProxy, ZeroAddress) - await proxy.updateAndCall(eventsHubImpl.address, eventsHubImpl.contract.methods.initialize( - Registry.address - ).encodeABI()) - } - - const stakeManager = await deployer.deploy(StakeManager) - const stakeMangerProxy = await deployer.deploy(StakeManagerProxy, ZeroAddress) - const auctionImpl = await deployer.deploy(StakeManagerExtension) - await stakeMangerProxy.updateAndCall( - StakeManager.address, - stakeManager.contract.methods.initialize( - Registry.address, - RootChainProxy.address, - maticToken.address, - StakingNFT.address, - StakingInfo.address, - ValidatorShareFactory.address, - GovernanceProxy.address, - accounts[0], - auctionImpl.address - ).encodeABI() - ) - - await deployer.deploy(SlashingManager, Registry.address, StakingInfo.address, process.env.HEIMDALL_ID) - let stakingNFT = await StakingNFT.deployed() - await stakingNFT.transferOwnership(StakeManagerProxy.address) - - await deployer.deploy(MaticWeth) - - await Promise.all([ - deployer.deploy( - ERC20Predicate, - WithdrawManagerProxy.address, - DepositManagerProxy.address, - Registry.address - ), - deployer.deploy( - ERC721Predicate, - WithdrawManagerProxy.address, - DepositManagerProxy.address - ), - deployer.deploy( - MintableERC721Predicate, - WithdrawManagerProxy.address, - DepositManagerProxy.address - ), - deployer.deploy(Marketplace), - deployer.deploy(MarketplacePredicateTest), - deployer.deploy( - MarketplacePredicate, - RootChain.address, - WithdrawManagerProxy.address, - Registry.address - ), - deployer.deploy( - TransferWithSigPredicate, - RootChain.address, - WithdrawManagerProxy.address, - Registry.address - ) - ]) - - const contractAddresses = { - root: { - Registry: Registry.address, - RootChain: RootChain.address, - GovernanceProxy: GovernanceProxy.address, - RootChainProxy: RootChainProxy.address, - DepositManager: DepositManager.address, - DepositManagerProxy: DepositManagerProxy.address, - WithdrawManager: WithdrawManager.address, - WithdrawManagerProxy: WithdrawManagerProxy.address, - StakeManager: StakeManager.address, - StakeManagerProxy: StakeManagerProxy.address, - SlashingManager: SlashingManager.address, - StakingInfo: StakingInfo.address, - ExitNFT: ExitNFT.address, - StateSender: StateSender.address, - predicates: { - ERC20Predicate: ERC20Predicate.address, - ERC721Predicate: ERC721Predicate.address, - MarketplacePredicate: MarketplacePredicate.address, - TransferWithSigPredicate: TransferWithSigPredicate.address - }, - tokens: { - MaticToken: maticToken.address, - MaticWeth: MaticWeth.address, - TestToken: TestToken.address, - RootERC721: RootERC721.address - } - } - } - - utils.writeContractAddresses(contractAddresses) - }) -} diff --git a/migrations/3_drain_stake_manager.js b/migrations/3_drain_stake_manager.js deleted file mode 100644 index 66d348c83..000000000 --- a/migrations/3_drain_stake_manager.js +++ /dev/null @@ -1,7 +0,0 @@ -const DrainStakeManager = artifacts.require('DrainStakeManager') - -module.exports = async function(deployer) { - deployer.then(async() => { - await deployer.deploy(DrainStakeManager) - }) -} diff --git a/migrations/4_initialize_state.js b/migrations/4_initialize_state.js deleted file mode 100644 index 7535a1eda..000000000 --- a/migrations/4_initialize_state.js +++ /dev/null @@ -1,130 +0,0 @@ -const ethUtils = require('ethereumjs-util') -const bluebird = require('bluebird') -const utils = require('./utils') -const Registry = artifacts.require('Registry') -const ValidatorShare = artifacts.require('ValidatorShare') -const DepositManagerProxy = artifacts.require('DepositManagerProxy') -const StateSender = artifacts.require('StateSender') -const WithdrawManagerProxy = artifacts.require('WithdrawManagerProxy') -const StakeManagerProxy = artifacts.require('StakeManagerProxy') -const SlashingManager = artifacts.require('SlashingManager') -const ERC20Predicate = artifacts.require('ERC20Predicate') -const ERC721Predicate = artifacts.require('ERC721Predicate') -const MarketplacePredicate = artifacts.require('MarketplacePredicate') -const TransferWithSigPredicate = artifacts.require('TransferWithSigPredicate') -const MaticWeth = artifacts.require('MaticWETH') -const Governance = artifacts.require('Governance') -const EventsHubProxy = artifacts.require('EventsHubProxy') - -async function updateContractMap(governance, registry, nameHash, value) { - return governance.update( - registry.address, - registry.contract.methods.updateContractMap(nameHash, value).encodeABI() - ) -} - -module.exports = async function(deployer) { - deployer.then(async() => { - const contractAddresses = utils.getContractAddresses() - const governance = await Governance.at(contractAddresses.root.GovernanceProxy) - - await bluebird - .all([ - Registry.deployed(), - ValidatorShare.deployed(), - DepositManagerProxy.deployed(), - StateSender.deployed(), - WithdrawManagerProxy.deployed(), - StakeManagerProxy.deployed(), - SlashingManager.deployed(), - ERC20Predicate.deployed(), - ERC721Predicate.deployed(), - MarketplacePredicate.deployed(), - TransferWithSigPredicate.deployed(), - EventsHubProxy.deployed() - ]) - .spread(async function( - registry, - validatorShare, - depositManagerProxy, - stateSender, - withdrawManagerProxy, - stakeManagerProxy, - slashingManager, - ERC20Predicate, - ERC721Predicate, - MarketplacePredicate, - TransferWithSigPredicate, - EventsHubProxy - ) { - await updateContractMap( - governance, - registry, - ethUtils.keccak256('validatorShare'), - validatorShare.address - ) - await updateContractMap( - governance, - registry, - ethUtils.keccak256('depositManager'), - depositManagerProxy.address - ) - await updateContractMap( - governance, - registry, - ethUtils.keccak256('withdrawManager'), - withdrawManagerProxy.address - ) - await updateContractMap( - governance, - registry, - ethUtils.keccak256('stakeManager'), - stakeManagerProxy.address - ) - await updateContractMap( - governance, - registry, - ethUtils.keccak256('slashingManager'), - slashingManager.address - ) - await updateContractMap( - governance, - registry, - ethUtils.keccak256('stateSender'), - stateSender.address - ) - await updateContractMap( - governance, - registry, - ethUtils.keccak256('wethToken'), - MaticWeth.address - ) - await updateContractMap( - governance, - registry, - ethUtils.keccak256('eventsHub'), - EventsHubProxy.address - ) - - // whitelist predicates - await governance.update( - registry.address, - registry.contract.methods.addErc20Predicate(ERC20Predicate.address).encodeABI() - ) - - await governance.update( - registry.address, - registry.contract.methods.addErc721Predicate(ERC721Predicate.address).encodeABI() - ) - - await governance.update( - registry.address, - registry.contract.methods.addPredicate(MarketplacePredicate.address, 3).encodeABI() - ) - await governance.update( - registry.address, - registry.contract.methods.addPredicate(TransferWithSigPredicate.address, 3).encodeABI() - ) - }) - }) -} diff --git a/migrations/5_deploy_child_contracts.js b/migrations/5_deploy_child_contracts.js deleted file mode 100644 index a634357be..000000000 --- a/migrations/5_deploy_child_contracts.js +++ /dev/null @@ -1,70 +0,0 @@ -const utils = require('./utils') - -const SafeMath = artifacts.require( - 'openzeppelin-solidity/contracts/math/SafeMath.sol' -) -const ChildChain = artifacts.require('ChildChain') -const MRC20 = artifacts.require('MRC20') - -module.exports = async function(deployer, network, accounts) { - if (deployer.network !== 'bor') { - return - } - - console.log(deployer.network); - - deployer.then(async() => { - await deployer.deploy(SafeMath) - await deployer.link(SafeMath, [ChildChain]) - await deployer.deploy(ChildChain) - - const childChain = await ChildChain.deployed() - const contractAddresses = utils.getContractAddresses() - - let MaticWeth = await childChain.addToken( - accounts[0], - contractAddresses.root.tokens.MaticWeth, - 'ETH on Matic', - 'ETH', - 18, - false // _isERC721 - ) - - let TestToken = await childChain.addToken( - accounts[0], - contractAddresses.root.tokens.TestToken, - 'Test Token', - 'TST', - 18, - false // _isERC721 - ) - - let RootERC721 = await childChain.addToken( - accounts[0], - contractAddresses.root.tokens.RootERC721, - 'Test ERC721', - 'TST721', - 0, - true // _isERC721 - ) - - const maticToken = await MRC20.at('0x0000000000000000000000000000000000001010') - const maticOwner = await maticToken.owner() - if (maticOwner === '0x0000000000000000000000000000000000000000') { - // matic contract at 0x1010 can only be initialized once, after the bor image starts to run - await maticToken.initialize(ChildChain.address, contractAddresses.root.tokens.MaticToken) - } - await childChain.mapToken(contractAddresses.root.tokens.MaticToken, '0x0000000000000000000000000000000000001010', false) - - contractAddresses.child = { - ChildChain: ChildChain.address, - tokens: { - MaticWeth: MaticWeth.logs.find(log => log.event === 'NewToken').args.token, - MaticToken: '0x0000000000000000000000000000000000001010', - TestToken: TestToken.logs.find(log => log.event === 'NewToken').args.token, - RootERC721: RootERC721.logs.find(log => log.event === 'NewToken').args.token - } - } - utils.writeContractAddresses(contractAddresses) - }) -} diff --git a/migrations/6_sync_child_state_to_root.js b/migrations/6_sync_child_state_to_root.js deleted file mode 100644 index 0b8b17b7b..000000000 --- a/migrations/6_sync_child_state_to_root.js +++ /dev/null @@ -1,69 +0,0 @@ -const ethUtils = require('ethereumjs-util') -const utils = require('./utils') - -const Registry = artifacts.require('Registry') -const Governance = artifacts.require('Governance') -const StateSender = artifacts.require('StateSender') -const DepositManager = artifacts.require('DepositManager') - -module.exports = async function(deployer, network, accounts) { - deployer.then(async() => { - const contractAddresses = utils.getContractAddresses() - - if (!contractAddresses.child) { - return - } - - const registry = await Registry.at(contractAddresses.root.Registry) - const governance = await Governance.at(contractAddresses.root.GovernanceProxy) - - await governance.update( - registry.address, - registry.contract.methods.mapToken( - contractAddresses.root.tokens.MaticWeth, - contractAddresses.child.tokens.MaticWeth, - false /* isERC721 */ - ).encodeABI() - ) - - await governance.update( - registry.address, - registry.contract.methods.mapToken( - contractAddresses.root.tokens.MaticToken, - contractAddresses.child.tokens.MaticToken, - false /* isERC721 */ - ).encodeABI() - ) - - await governance.update( - registry.address, - registry.contract.methods.mapToken( - contractAddresses.root.tokens.TestToken, - contractAddresses.child.tokens.TestToken, - false /* isERC721 */ - ).encodeABI() - ) - - await governance.update( - registry.address, - registry.contract.methods.mapToken( - contractAddresses.root.tokens.RootERC721, - contractAddresses.child.tokens.RootERC721, - true /* isERC721 */ - ).encodeABI() - ) - - await governance.update( - registry.address, - registry.contract.methods.updateContractMap( - ethUtils.keccak256('childChain'), - contractAddresses.child.ChildChain - ).encodeABI() - ) - - const stateSenderContract = await StateSender.at(contractAddresses.root.StateSender) - await stateSenderContract.register(contractAddresses.root.DepositManagerProxy, contractAddresses.child.ChildChain) - let depositManager = await DepositManager.at(contractAddresses.root.DepositManagerProxy) - await depositManager.updateChildChainAndStateSender() - }) -} diff --git a/migrations/utils.js b/migrations/utils.js deleted file mode 100644 index 6457f02c7..000000000 --- a/migrations/utils.js +++ /dev/null @@ -1,12 +0,0 @@ -const fs = require('fs') - -export function getContractAddresses() { - return JSON.parse(fs.readFileSync(`${process.cwd()}/contractAddresses.json`).toString()) -} - -export function writeContractAddresses(contractAddresses) { - fs.writeFileSync( - `${process.cwd()}/contractAddresses.json`, - JSON.stringify(contractAddresses, null, 2) // Indent 2 spaces - ) -} diff --git a/moonwalker-migrations/1_queueJobs.js b/moonwalker-migrations/1_queueJobs.js deleted file mode 100644 index b53fb77bb..000000000 --- a/moonwalker-migrations/1_queueJobs.js +++ /dev/null @@ -1,73 +0,0 @@ -const EthDeployer = require('moonwalker').default - -let id = 0 - -async function deploy() { - if (!process.env.HEIMDALL_ID) { - throw new Error('Please export HEIMDALL_ID environment variable') - } - if (!process.env.MATIC_NAME) { - throw new Error('Please export MATIC_NAME environment variable') - } - - const qClient = await EthDeployer.getQueue() - const deployer = new EthDeployer.Sender(qClient) - - // Libs - await deployer.deploy(transformArtifact('BytesLib')) - await deployer.deploy(transformArtifact('Common')) - await deployer.deploy(transformArtifact('ECVerify')) - await deployer.deploy(transformArtifact('Merkle')) - await deployer.deploy(transformArtifact('MerklePatriciaProof')) - await deployer.deploy(transformArtifact('PriorityQueue')) - await deployer.deploy(transformArtifact('RLPEncode')) - await deployer.deploy(transformArtifact('RLPReader')) - await deployer.deploy(transformArtifact('SafeMath')) - - // contracts, id = 9 - await deployer.deploy(transformArtifact('Governance')) - await deployer.deploy(transformArtifact('GovernanceProxy', ['Governance'])) - await deployer.deploy(transformArtifact('Registry', ['GovernanceProxy'])) - await deployer.deploy(transformArtifact('RootChain')) - await deployer.deploy(transformArtifact('RootChainProxy', [ - 'RootChain', - 'Registry', - { value: process.env.HEIMDALL_ID } - ])) - - await deployer.deploy(transformArtifact('ValidatorShareFactory')) - await deployer.deploy(transformArtifact('StakingInfo', ['Registry'])) - await deployer.deploy(transformArtifact('StakingNFT', [{ value: 'Matic Validator' }, { value: 'MV' }])) - - await deployer.deploy(transformArtifact('TestToken', [{ value: process.env.MATIC_NAME }, { value: process.env.MATIC_NAME }])) - await deployer.deploy(transformArtifact('TestToken', [{ value: `ERC20-${process.env.MATIC_NAME}` }, { value: `ERC20-${process.env.MATIC_NAME}` }])) - await deployer.deploy(transformArtifact('RootERC721', [{ value: `ERC721-${process.env.MATIC_NAME}` }, { value: `ERC721-${process.env.MATIC_NAME}` }])) - await deployer.deploy(transformArtifact('MaticWETH')) - - await deployer.deploy(transformArtifact('StakeManager')) - await deployer.deploy(transformArtifact('StakeManagerProxy', ['StakeManager'])) - await deployer.deploy(transformArtifact('SlashingManager', ['Registry', 'StakingInfo', { value: process.env.HEIMDALL_ID }])) - await deployer.deploy(transformArtifact('ValidatorShare', ['Registry', { value: '0' }, 'StakingNFT', 'StakeManagerProxy'])) - - await deployer.deploy(transformArtifact('StateSender')) - await deployer.deploy(transformArtifact('DepositManager')) - await deployer.deploy(transformArtifact('DepositManagerProxy', ['DepositManager', 'Registry', 'RootChainProxy', 'GovernanceProxy'])) - - await deployer.deploy(transformArtifact('WithdrawManager')) - await deployer.deploy(transformArtifact('ExitNFT', ['Registry'])) - await deployer.deploy(transformArtifact('WithdrawManagerProxy', ['WithdrawManager', 'Registry', 'RootChainProxy', 'ExitNFT'])) - await deployer.deploy(transformArtifact('ERC20PredicateBurnOnly', ['WithdrawManagerProxy', 'DepositManagerProxy', 'Registry'])) - await deployer.deploy(transformArtifact('ERC721PredicateBurnOnly', ['WithdrawManagerProxy', 'DepositManagerProxy'])) -} - -function transformArtifact(contract, args = []) { - const res = { - contract, // abi - args, - id: id++, - type: 'deploy' - } - return JSON.stringify(res) -} - -deploy().then() diff --git a/moonwalker-migrations/2_queueJobs.js b/moonwalker-migrations/2_queueJobs.js deleted file mode 100644 index 111cf8d78..000000000 --- a/moonwalker-migrations/2_queueJobs.js +++ /dev/null @@ -1,221 +0,0 @@ -const fs = require('fs') - -const Registry = artifacts.require('Registry') - -const ethUtils = require('ethereumjs-util') -const EthDeployer = require('moonwalker').default - -let id = 33 // THIS SHOULD BE NUMBER OF JOBS PROCESSED IN THE PREVIOUS SCRIPT - -async function deploy() { - const qClient = await EthDeployer.getQueue() - const deployer = new EthDeployer.Sender(qClient) - - // just need this for encodeABI() - const registry = await Registry.new('0x0000000000000000000000000000000000000000') - - await deployer.deploy( - tx('Governance', 'update', - [ - 'Registry', - { - value: - registry.contract.methods.updateContractMap( - ethUtils.bufferToHex(ethUtils.keccak256('depositManager')), - getAddressForContract('DepositManagerProxy') - ).encodeABI() - } - ], - 'GovernanceProxy' - ) - ) - - await deployer.deploy( - tx('Governance', 'update', - [ - 'Registry', - { - value: - registry.contract.methods.updateContractMap( - ethUtils.bufferToHex(ethUtils.keccak256('withdrawManager')), - getAddressForContract('WithdrawManagerProxy') - ).encodeABI() - } - ], - 'GovernanceProxy' - ) - ) - - await deployer.deploy( - tx('Governance', 'update', - [ - 'Registry', - { - value: - registry.contract.methods.updateContractMap( - ethUtils.bufferToHex(ethUtils.keccak256('slashingManager')), - getAddressForContract('SlashingManager') - ).encodeABI() - } - ], - 'GovernanceProxy' - ) - ) - - await deployer.deploy( - tx('Governance', 'update', - [ - 'Registry', - { - value: - registry.contract.methods.updateContractMap( - ethUtils.bufferToHex(ethUtils.keccak256('stakeManager')), - getAddressForContract('StakeManagerProxy') - ).encodeABI() - } - ], - 'GovernanceProxy' - ) - ) - await deployer.deploy( - tx('Governance', 'update', - [ - 'Registry', - { - value: - registry.contract.methods.updateContractMap( - ethUtils.bufferToHex(ethUtils.keccak256('validatorShare')), - getAddressForContract('ValidatorShare') - ).encodeABI() - } - ], - 'GovernanceProxy' - ) - ) - - - await deployer.deploy( - tx('Governance', 'update', - [ - 'Registry', - { - value: - registry.contract.methods.updateContractMap( - ethUtils.bufferToHex(ethUtils.keccak256('stateSender')), - getAddressForContract('StateSender') - ).encodeABI() - }, - ], - 'GovernanceProxy' - ) - ) - - await deployer.deploy( - tx('Governance', 'update', - [ - 'Registry', - { - value: - registry.contract.methods.updateContractMap( - ethUtils.bufferToHex(ethUtils.keccak256('wethToken')), - getAddressForContract('MaticWETH') - ).encodeABI() - }, - ], - 'GovernanceProxy' - ) - ) - - await deployer.deploy( - tx('Governance', 'update', - [ - 'Registry', - { - value: - registry.contract.methods.addErc20Predicate( - getAddressForContract('ERC20Predicate') - ).encodeABI() - }, - ], - 'GovernanceProxy' - ) - ) - - await deployer.deploy( - tx('Governance', 'update', - [ - 'Registry', - { - value: - registry.contract.methods.addErc721Predicate( - getAddressForContract('ERC721Predicate') - ).encodeABI() - }, - ], - 'GovernanceProxy' - ) - ) - - await deployer.deploy(tx('StakingNFT', 'transferOwnership', ['StakeManagerProxy'])) - await deployer.deploy(tx('StakeManager', 'initialize', [ - 'Registry', - 'RootChainProxy', - 'TestToken', - 'StakingNFT', - 'StakingInfo', - 'ValidatorShareFactory', - 'GovernanceProxy', - { value: process.env.FROM } // owner - ], - 'StakeManagerProxy' -)) -} - -function tx(contract, method, args, addressArtifact) { - return JSON.stringify({ - contract, // abi - addressArtifact, // allowed to be undefined - method, - args, - id: id++, - type: 'transaction' - }) -} - -function getStatus() { - let status = {} - const statusFile = `${process.cwd()}/build/status.json` - if (fs.existsSync(statusFile)) { - try { - status = JSON.parse(fs.readFileSync(statusFile).toString()) - } catch (e) { - console.log(e) - } - } - return status -} - -function getAddressForContract(contract) { - const status = getStatus() - for (let i = 0; i < Object.keys(status).length; i++) { - if (status[i].contract === contract) return status[i].address - } - throw new Error(`${contract} not found in status file`) -} - -function wait(ms) { - return new Promise((resolve, reject) => { - setTimeout(function() { resolve() }, ms); - }) -} - -module.exports = async function(callback) { - try { - await deploy() - await wait(3000) // otherwise the tasks are not queued - } catch (e) { - // truffle exec