├── architects └── images │ ├── 3_tx_verification.png │ └── 4_fraud_tx_verification.png ├── grant.json ├── test ├── utils │ ├── README.md │ ├── data │ │ ├── period.json │ │ ├── asset.json │ │ ├── bond.json │ │ ├── relayerFee.json │ │ └── checkTransferTx.json │ └── utils.js ├── dispute-manager │ ├── utils.js │ ├── README.md │ └── data │ │ ├── blockHeader.json │ │ ├── checkTransferTx.json │ │ └── tx.json └── integration │ └── README.md ├── .gitignore ├── .prettierrc ├── .solhint.json ├── contracts ├── bond-manager │ └── IBondManager.sol ├── bridge-dispute-manager │ ├── DecoderHelper.sol │ ├── DisputeHelper.sol │ ├── utils │ │ ├── SolRLPDecoder.sol │ │ └── RLPEncode.sol │ └── IBridgeDisputeManager.sol ├── test │ ├── TestToken.sol │ ├── TestDisputeManager.sol │ ├── TestContractCall.sol │ └── TestCheckpointManager.sol ├── diamond │ ├── interfaces │ │ ├── IERC165.sol │ │ ├── IDiamond.sol │ │ ├── IERC173.sol │ │ ├── IDiamondCut.sol │ │ └── IDiamondLoupe.sol │ ├── facets │ │ ├── OwnershipFacet.sol │ │ ├── Test2Facet.sol │ │ ├── DiamondCutFacet.sol │ │ └── Test1Facet.sol │ ├── upgradeInitializers │ │ ├── DiamondMultiInit.sol │ │ └── DiamondInit.sol │ └── Diamond.sol ├── polygon │ ├── fx-portal │ │ └── contracts │ │ │ ├── lib │ │ │ ├── ERC1155Receiver.sol │ │ │ ├── IERC1155MetadataURI.sol │ │ │ ├── ERC1155Holder.sol │ │ │ ├── IERC721Metadata.sol │ │ │ ├── IERC165.sol │ │ │ ├── IERC721Receiver.sol │ │ │ ├── Context.sol │ │ │ ├── ERC165.sol │ │ │ ├── Merkle.sol │ │ │ ├── Create2.sol │ │ │ ├── Strings.sol │ │ │ ├── Ownable.sol │ │ │ ├── IERC1155Receiver.sol │ │ │ ├── IERC20.sol │ │ │ └── IERC1155.sol │ │ │ ├── tokens │ │ │ ├── IFxERC20.sol │ │ │ ├── IFxERC721.sol │ │ │ ├── IFxERC1155.sol │ │ │ ├── FxERC721.sol │ │ │ ├── FxERC20.sol │ │ │ └── FxERC1155.sol │ │ │ ├── examples │ │ │ ├── state-transfer │ │ │ │ ├── FxStateRootTunnel.sol │ │ │ │ └── FxStateChildTunnel.sol │ │ │ ├── erc20-transfer │ │ │ │ └── FxERC20RootTunnel.sol │ │ │ ├── mintable-erc20-transfer │ │ │ │ └── FxMintableERC20RootTunnel.sol │ │ │ └── erc721-transfer │ │ │ │ └── FxERC721RootTunnel.sol │ │ │ ├── FxRoot.sol │ │ │ ├── FxChild.sol │ │ │ └── tunnel │ │ │ └── FxBaseChildTunnel.sol │ ├── PolygonPheasantNetworkBridgeChild.sol │ ├── checkpoint-manager │ │ ├── PolygonChildCheckpointManager.sol │ │ └── PolygonRootCheckpointManager.sol │ └── Helper.sol ├── libraries │ ├── constants │ │ └── Lib_DefaultValues.sol │ ├── types │ │ └── Types.sol │ └── bridge │ │ └── Lib_BridgeUtils.sol └── L2 │ ├── checkpoint-manager │ ├── ArbitrumChildCheckpointManager.sol │ ├── OptimismChildCheckpointManager.sol │ ├── CoreChildCheckpointManager.sol │ ├── OptimismRootCheckpointManager.sol │ └── ArbitrumRootCheckpointManager.sol │ ├── IPheasantNetworkParameters.sol │ ├── ParameterHelper.sol │ └── Helper.sol ├── scripts ├── interactWithChain.js ├── testFunctionCall.js ├── relayerFee.js ├── createMultipleUpwardTrades.js ├── managerSetting.js ├── deployLibrary.js ├── networkSetting.js ├── admin.js ├── testDispute.js ├── createManyNewTrade.js ├── createMultipleNewTrades.js ├── newCreateUpwardTrade.js ├── bondManager.js ├── newTrade.js ├── libraries │ └── diamond.js ├── relayerBond.js ├── deployBondManager.js ├── testCall.js ├── blockhashOperation.js ├── deployDiamond.js └── deploy.js ├── LICENSE ├── utils ├── getBlockTimeAve.js └── contractAddresses.sample.json ├── package.json └── README.md /architects/images/3_tx_verification.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pheasant-Network/contracts/HEAD/architects/images/3_tx_verification.png -------------------------------------------------------------------------------- /grant.json: -------------------------------------------------------------------------------- 1 | { 2 | "opRetro": { 3 | "projectId": "0x2d5167181143298e3d002d318d8b1d2917b8c3205a5634549c95cab0ff32cbdf" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /architects/images/4_fraud_tx_verification.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pheasant-Network/contracts/HEAD/architects/images/4_fraud_tx_verification.png -------------------------------------------------------------------------------- /test/utils/README.md: -------------------------------------------------------------------------------- 1 | 2 | ## trade.json 3 | 4 | 【slash】 5 | - 16 6 | - status : 0 7 | - 17 8 | - status : 2 9 | - 18 10 | - status : 3 11 | -------------------------------------------------------------------------------- /test/utils/data/period.json: -------------------------------------------------------------------------------- 1 | { 2 | "0": { 3 | "high" : 1001, 4 | "medium" : 1001, 5 | "low" : 1001, 6 | "gasPriceThresholdHigh" : 0, 7 | "gasPriceThresholdLow" : 0 8 | } 9 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | .DS_Store 3 | node_modules 4 | index.mjs 5 | .env 6 | *.swp 7 | coverage 8 | coverage.json 9 | typechain 10 | 11 | #Hardhat files 12 | cache 13 | artifacts 14 | cache-zk 15 | artifacts-zk 16 | 17 | contractAddresses.json 18 | log.json -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true, 3 | "trailingComma": "all", 4 | "overrides": [ 5 | { 6 | "files": "*.sol", 7 | "options": { 8 | "singleQuote": false, 9 | "printWidth": 120, 10 | "explicitTypes": "always" 11 | } 12 | } 13 | ] 14 | } -------------------------------------------------------------------------------- /.solhint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "solhint:recommended", 3 | "plugins": [ 4 | "prettier" 5 | ], 6 | "rules": { 7 | "prettier/prettier": "error", 8 | "avoid-suicide": "error", 9 | "avoid-sha3": "warn", 10 | "compiler-version": ["error","0.8.9"] 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /test/utils/data/asset.json: -------------------------------------------------------------------------------- 1 | { 2 | "0": { 3 | "asset": 1000 4 | }, 5 | "1": { 6 | "asset": 100000000000000 7 | }, 8 | "2": { 9 | "asset": 1000000000000000 10 | }, 11 | "3": { 12 | "asset": 99999999999999 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /contracts/bond-manager/IBondManager.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity 0.8.18; 3 | /** 4 | * @title IBridgeDisputeManager 5 | */ 6 | 7 | interface IBondManager { 8 | function getBond(uint8 _tokenIndex) external view returns (uint256); 9 | function slash(uint8 _tokenIndex, uint256 _amount) external payable; 10 | } -------------------------------------------------------------------------------- /test/utils/data/bond.json: -------------------------------------------------------------------------------- 1 | { 2 | "0": { 3 | "bond": 300000000000000 4 | }, 5 | "1": { 6 | "bond": 100000000000000 7 | }, 8 | "2": { 9 | "bond": 200000020000000 10 | }, 11 | "3": { 12 | "bond": 200000020000000 13 | }, 14 | "4": { 15 | "bond": "2500000000000000000" 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /contracts/bridge-dispute-manager/DecoderHelper.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity 0.8.18; 3 | pragma experimental ABIEncoderV2; 4 | import "./utils/SolRLPDecoder.sol"; 5 | 6 | contract DecoderHelper { 7 | 8 | function decode(bytes calldata input) public pure returns (bytes[] memory) { 9 | return SolRLPDecoder.decode(input); 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /test/utils/data/relayerFee.json: -------------------------------------------------------------------------------- 1 | { 2 | "0": { 3 | "high" : 1000, 4 | "medium" : 1000, 5 | "low" : 1000, 6 | "gasPriceThresholdHigh" : 0, 7 | "gasPriceThresholdLow" : 0 8 | }, 9 | "1": { 10 | "high" : 1001, 11 | "medium" : 1001, 12 | "low" : 1001, 13 | "gasPriceThresholdHigh" : 0, 14 | "gasPriceThresholdLow" : 0 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /contracts/test/TestToken.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity 0.8.18; 3 | import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; 4 | 5 | contract TestToken is ERC20 { 6 | constructor(address owner) ERC20("TestToken", "TST") { 7 | _mint(owner, 1000000000000000000000000000); 8 | //_mint(address(0xE202B444Db397F53AE05149fE2843D7841A2dCBE), 100000000000000000000000000); 9 | //_mint(address(0xb0E426B1A0B8BA474Dc5c8F6493B3E63D7121626), 100000000000000000000000000); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /contracts/diamond/interfaces/IERC165.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | interface IERC165 { 5 | /// @notice Query if a contract implements an interface 6 | /// @param interfaceId The interface identifier, as specified in ERC-165 7 | /// @dev Interface identification is specified in ERC-165. This function 8 | /// uses less than 30,000 gas. 9 | /// @return `true` if the contract implements `interfaceID` and 10 | /// `interfaceID` is not 0xffffffff, `false` otherwise 11 | function supportsInterface(bytes4 interfaceId) external view returns (bool); 12 | } 13 | -------------------------------------------------------------------------------- /contracts/polygon/fx-portal/contracts/lib/ERC1155Receiver.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "./IERC1155Receiver.sol"; 6 | import "./ERC165.sol"; 7 | 8 | /** 9 | * @dev _Available since v3.1._ 10 | */ 11 | abstract contract ERC1155Receiver is ERC165, IERC1155Receiver { 12 | /** 13 | * @dev See {IERC165-supportsInterface}. 14 | */ 15 | function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) { 16 | return interfaceId == type(IERC1155Receiver).interfaceId || super.supportsInterface(interfaceId); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /contracts/polygon/fx-portal/contracts/tokens/IFxERC20.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | import {IERC20} from "../lib/IERC20.sol"; 5 | 6 | interface IFxERC20 is IERC20 { 7 | function fxManager() external returns (address); 8 | 9 | function connectedToken() external returns (address); 10 | 11 | function initialize( 12 | address _fxManager, 13 | address _connectedToken, 14 | string memory _name, 15 | string memory _symbol, 16 | uint8 _decimals 17 | ) external; 18 | 19 | function mint(address user, uint256 amount) external; 20 | 21 | function burn(address user, uint256 amount) external; 22 | } 23 | -------------------------------------------------------------------------------- /contracts/polygon/fx-portal/contracts/tokens/IFxERC721.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | import {IERC721} from "../lib/IERC721.sol"; 5 | 6 | interface IFxERC721 is IERC721 { 7 | function fxManager() external returns (address); 8 | 9 | function connectedToken() external returns (address); 10 | 11 | function initialize( 12 | address _fxManager, 13 | address _connectedToken, 14 | string memory _name, 15 | string memory _symbol 16 | ) external; 17 | 18 | function mint( 19 | address user, 20 | uint256 tokenId, 21 | bytes memory _data 22 | ) external; 23 | 24 | function burn(uint256 tokenId) external; 25 | } 26 | -------------------------------------------------------------------------------- /contracts/polygon/fx-portal/contracts/examples/state-transfer/FxStateRootTunnel.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | import {FxBaseRootTunnel} from "../../tunnel/FxBaseRootTunnel.sol"; 5 | 6 | /** 7 | * @title FxStateRootTunnel 8 | */ 9 | contract FxStateRootTunnel is FxBaseRootTunnel { 10 | bytes public latestData; 11 | 12 | constructor(address _checkpointManager, address _fxRoot) FxBaseRootTunnel(_checkpointManager, _fxRoot) {} 13 | 14 | function _processMessageFromChild(bytes memory data) internal override { 15 | latestData = data; 16 | } 17 | 18 | function sendMessageToChild(bytes memory message) public { 19 | _sendMessageToChild(message); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /contracts/polygon/fx-portal/contracts/lib/IERC1155MetadataURI.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "./IERC1155.sol"; 6 | 7 | /** 8 | * @dev Interface of the optional ERC1155MetadataExtension interface, as defined 9 | * in the https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[EIP]. 10 | * 11 | * _Available since v3.1._ 12 | */ 13 | interface IERC1155MetadataURI is IERC1155 { 14 | /** 15 | * @dev Returns the URI for token type `id`. 16 | * 17 | * If the `\{id\}` substring is present in the URI, it must be replaced by 18 | * clients with the actual token type ID. 19 | */ 20 | function uri(uint256 id) external view returns (string memory); 21 | } 22 | -------------------------------------------------------------------------------- /contracts/diamond/interfaces/IDiamond.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | /******************************************************************************\ 5 | * Author: Nick Mudge (https://twitter.com/mudgen) 6 | * EIP-2535 Diamonds: https://eips.ethereum.org/EIPS/eip-2535 7 | /******************************************************************************/ 8 | 9 | interface IDiamond { 10 | enum FacetCutAction {Add, Replace, Remove} 11 | // Add=0, Replace=1, Remove=2 12 | 13 | struct FacetCut { 14 | address facetAddress; 15 | FacetCutAction action; 16 | bytes4[] functionSelectors; 17 | } 18 | 19 | event DiamondCut(FacetCut[] _diamondCut, address _init, bytes _calldata); 20 | } -------------------------------------------------------------------------------- /contracts/bridge-dispute-manager/DisputeHelper.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity 0.8.18; 3 | import "./BridgeDisputeManager.sol"; 4 | 5 | contract DisputeHelper is BridgeDisputeManager { 6 | constructor(address _checkPointManager) BridgeDisputeManager(_checkPointManager) {} 7 | 8 | function helperBufferToNibble(bytes memory buffer) public pure returns(uint8[] memory){ 9 | return super.bufferToNibble(buffer); 10 | } 11 | 12 | function helperComposeTx(bytes[] memory item) public pure returns(bytes memory){ 13 | return super.composeTx(item); 14 | } 15 | 16 | function helperRlpEncode(bytes[] memory item, bool isTxEncode) public pure returns(bytes memory){ 17 | return super.rlpEncode(item, isTxEncode); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /contracts/polygon/fx-portal/contracts/lib/ERC1155Holder.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "./ERC1155Receiver.sol"; 6 | 7 | /** 8 | * @dev _Available since v3.1._ 9 | */ 10 | contract ERC1155Holder is ERC1155Receiver { 11 | function onERC1155Received( 12 | address, 13 | address, 14 | uint256, 15 | uint256, 16 | bytes memory 17 | ) public virtual override returns (bytes4) { 18 | return this.onERC1155Received.selector; 19 | } 20 | 21 | function onERC1155BatchReceived( 22 | address, 23 | address, 24 | uint256[] memory, 25 | uint256[] memory, 26 | bytes memory 27 | ) public virtual override returns (bytes4) { 28 | return this.onERC1155BatchReceived.selector; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /contracts/polygon/fx-portal/contracts/lib/IERC721Metadata.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "./IERC721.sol"; 6 | 7 | /** 8 | * @title ERC-721 Non-Fungible Token Standard, optional metadata extension 9 | * @dev See https://eips.ethereum.org/EIPS/eip-721 10 | */ 11 | interface IERC721Metadata is IERC721 { 12 | /** 13 | * @dev Returns the token collection name. 14 | */ 15 | function name() external view returns (string memory); 16 | 17 | /** 18 | * @dev Returns the token collection symbol. 19 | */ 20 | function symbol() external view returns (string memory); 21 | 22 | /** 23 | * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token. 24 | */ 25 | function tokenURI(uint256 tokenId) external view returns (string memory); 26 | } 27 | -------------------------------------------------------------------------------- /contracts/diamond/facets/OwnershipFacet.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // This file is a modified version of RLPEncode.sol: 3 | // https://github.com/mudgen/diamond-1-hardhat/tree/10a001c8f0d9e8b71e7e2fd8b5829da8a18f9a57/contracts 4 | // 5 | // MODIFICATIONS 6 | // 1. Chenged solidity version to 0.8.18 from ^0.8.0 7 | 8 | pragma solidity 0.8.18; 9 | 10 | import { LibDiamond } from "../libraries/LibDiamond.sol"; 11 | import { IERC173 } from "../interfaces/IERC173.sol"; 12 | 13 | contract OwnershipFacet is IERC173 { 14 | function transferOwnership(address _newOwner) external override { 15 | LibDiamond.enforceIsContractOwner(); 16 | LibDiamond.setContractOwner(_newOwner); 17 | } 18 | 19 | function owner() external override view returns (address owner_) { 20 | owner_ = LibDiamond.contractOwner(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /contracts/diamond/interfaces/IERC173.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | /// @title ERC-173 Contract Ownership Standard 5 | /// Note: the ERC-165 identifier for this interface is 0x7f5828d0 6 | /* is ERC165 */ 7 | interface IERC173 { 8 | /// @dev This emits when ownership of a contract changes. 9 | event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); 10 | 11 | /// @notice Get the address of the owner 12 | /// @return owner_ The address of the owner. 13 | function owner() external view returns (address owner_); 14 | 15 | /// @notice Set the address of the new owner of the contract 16 | /// @dev Set _newOwner to address(0) to renounce any ownership. 17 | /// @param _newOwner The address of the new owner of the contract 18 | function transferOwnership(address _newOwner) external; 19 | } 20 | -------------------------------------------------------------------------------- /contracts/libraries/constants/Lib_DefaultValues.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity 0.8.18; 3 | 4 | /** 5 | * @title Lib_DefaultValues 6 | */ 7 | 8 | library Lib_DefaultValues { 9 | uint8 constant ETH_TOKEN_INDEX = 0; 10 | uint256 constant ETH_NETWORK_CODE = 1001; 11 | 12 | uint8 constant STATUS_START = 0; 13 | uint8 constant STATUS_PAID = 2; 14 | uint8 constant STATUS_DISPUTE = 3; 15 | uint8 constant STATUS_SLASHED = 4; 16 | uint8 constant STATUS_PROVED = 5; 17 | uint8 constant STATUS_SLASH_COMPLETED = 6; 18 | uint8 constant STATUS_CANCEL = 99; 19 | 20 | bytes constant TRANSFER_METHOD_ID = bytes(hex"a9059cbb"); 21 | 22 | uint256 constant CANCELABLE_PERIOD = 2 hours; 23 | uint256 constant UPWARD_SLASH_START = 30 minutes; 24 | uint256 constant SLASHABLE_PERIOD = 14 days; 25 | uint256 constant UPDATE_PERIOD = 3 hours; 26 | 27 | uint256 constant BLOCKHEADER_TIMESTAMP_INDEX = 11; 28 | } -------------------------------------------------------------------------------- /contracts/polygon/fx-portal/contracts/lib/IERC165.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | /** 6 | * @dev Interface of the ERC165 standard, as defined in the 7 | * https://eips.ethereum.org/EIPS/eip-165[EIP]. 8 | * 9 | * Implementers can declare support of contract interfaces, which can then be 10 | * queried by others ({ERC165Checker}). 11 | * 12 | * For an implementation, see {ERC165}. 13 | */ 14 | interface IERC165 { 15 | /** 16 | * @dev Returns true if this contract implements the interface defined by 17 | * `interfaceId`. See the corresponding 18 | * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] 19 | * to learn more about how these ids are created. 20 | * 21 | * This function call must use less than 30 000 gas. 22 | */ 23 | function supportsInterface(bytes4 interfaceId) external view returns (bool); 24 | } 25 | -------------------------------------------------------------------------------- /scripts/interactWithChain.js: -------------------------------------------------------------------------------- 1 | const hre = require("hardhat"); 2 | const BN = require('bn.js'); 3 | const tradeThreshold = "100000000000000000"; 4 | const tradeMinimumAmount = "5000000000000000"; 5 | const utils = require('../utils/index'); 6 | const { ethers } = require("ethers"); 7 | require('dotenv').config({ path: '../.env' }); 8 | 9 | async function main() { 10 | let contractAddressObj = utils.getContractAddresses() 11 | const accounts = await hre.ethers.getSigners(); 12 | console.log("Network name =", hre.network.name); 13 | const tokenAddressList = []; 14 | 15 | const balance = await hre.ethers.provider.getBalance(accounts[0].address) 16 | console.log(balance) 17 | } 18 | 19 | // We recommend this pattern to be able to use async/await everywhere 20 | // and properly handle errors. 21 | main() 22 | .then(() => process.exit(0)) 23 | .catch((error) => { 24 | console.error(error); 25 | process.exit(1); 26 | }); 27 | -------------------------------------------------------------------------------- /contracts/test/TestDisputeManager.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity 0.8.18; 3 | 4 | import { Types } from "../libraries/types/Types.sol"; 5 | 6 | contract TestDisputeManager { 7 | 8 | function checkEvidenceExceptBlockHash( 9 | bool _isNativeTokenCheck, 10 | uint256 _tradeAmount, 11 | uint256 _networkCheckCode, 12 | address _receiver, 13 | address _tokenAddress, 14 | Types.Evidence calldata _evidence 15 | ) public view returns (bool) { 16 | return true; 17 | } 18 | 19 | 20 | function verifyBlockHash(bytes32 _blockHash, uint256 _destCode, uint256 _blockNumber) external view returns (bool) { 21 | return true; 22 | } 23 | 24 | function recoverAddress(bytes[] calldata txRaw) public pure returns(address) { 25 | address hardhatDefaultAddress = 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266; 26 | return hardhatDefaultAddress; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /contracts/polygon/fx-portal/contracts/examples/state-transfer/FxStateChildTunnel.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | import {FxBaseChildTunnel} from "../../tunnel/FxBaseChildTunnel.sol"; 5 | 6 | /** 7 | * @title FxStateChildTunnel 8 | */ 9 | contract FxStateChildTunnel is FxBaseChildTunnel { 10 | uint256 public latestStateId; 11 | address public latestRootMessageSender; 12 | bytes public latestData; 13 | 14 | constructor(address _fxChild) FxBaseChildTunnel(_fxChild) {} 15 | 16 | function _processMessageFromRoot( 17 | uint256 stateId, 18 | address sender, 19 | bytes memory data 20 | ) internal override validateSender(sender) { 21 | latestStateId = stateId; 22 | latestRootMessageSender = sender; 23 | latestData = data; 24 | } 25 | 26 | function sendMessageToRoot(bytes memory message) public { 27 | _sendMessageToRoot(message); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /contracts/bridge-dispute-manager/utils/SolRLPDecoder.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity 0.8.18; 3 | pragma abicoder v2; 4 | import "./RLPReader.sol"; 5 | 6 | library SolRLPDecoder { 7 | using RLPReader for RLPReader.RLPItem; 8 | using RLPReader for bytes; 9 | 10 | function decode(bytes calldata input) public pure returns (bytes[] memory) { 11 | RLPReader.RLPItem memory item = input.toRlpItem(); 12 | 13 | if (RLPReader.isList(item)) { 14 | RLPReader.RLPItem[] memory list = item.toList(); 15 | uint256 listLength = list.length; 16 | bytes[] memory data = new bytes[](listLength); 17 | for (uint256 i = 0; i < listLength; i++) { 18 | data[i] = list[i].toBytes(); 19 | } 20 | return data; 21 | } else { 22 | bytes[] memory data = new bytes[](1); 23 | data[0] = item.toBytes(); 24 | return data; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /test/dispute-manager/utils.js: -------------------------------------------------------------------------------- 1 | const testTransferTx = require('./data/checkTransferTx.json'); 2 | const testTx = require('./data/tx.json'); 3 | const testBlockHeader = require('./data/blockHeader.json'); 4 | const testProof = require('./data/proof.json'); 5 | const testEvidence = require('./data/exceptionEvidence.json'); 6 | const testReceipt = require('./data/receipt.json'); 7 | 8 | class TestData { 9 | constructor(_accounts) { 10 | this.accounts = _accounts; 11 | } 12 | 13 | getTransferTxData(index) { 14 | return testTransferTx[index]; 15 | } 16 | getTxData(index) { 17 | return testTx[index]; 18 | } 19 | 20 | getBlockHeaderData(index) { 21 | return testBlockHeader[index]; 22 | } 23 | 24 | getProofData(index) { 25 | return testProof[index]; 26 | } 27 | 28 | getEvidence(index) { 29 | return testEvidence[index]; 30 | } 31 | 32 | getReceiptData(index) { 33 | return testReceipt[index]; 34 | } 35 | } 36 | 37 | exports.TestData = TestData; 38 | -------------------------------------------------------------------------------- /contracts/polygon/fx-portal/contracts/lib/IERC721Receiver.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | /** 6 | * @title ERC721 token receiver interface 7 | * @dev Interface for any contract that wants to support safeTransfers 8 | * from ERC721 asset contracts. 9 | */ 10 | interface IERC721Receiver { 11 | /** 12 | * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom} 13 | * by `operator` from `from`, this function is called. 14 | * 15 | * It must return its Solidity selector to confirm the token transfer. 16 | * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted. 17 | * 18 | * The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`. 19 | */ 20 | function onERC721Received( 21 | address operator, 22 | address from, 23 | uint256 tokenId, 24 | bytes calldata data 25 | ) external returns (bytes4); 26 | } 27 | -------------------------------------------------------------------------------- /contracts/polygon/fx-portal/contracts/lib/Context.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | /* 6 | * @dev Provides information about the current execution context, including the 7 | * sender of the transaction and its data. While these are generally available 8 | * via msg.sender and msg.data, they should not be accessed in such a direct 9 | * manner, since when dealing with meta-transactions the account sending and 10 | * paying for execution may not be the actual sender (as far as an application 11 | * is concerned). 12 | * 13 | * This contract is only required for intermediate, library-like contracts. 14 | */ 15 | abstract contract Context { 16 | function _msgSender() internal view virtual returns (address) { 17 | return msg.sender; 18 | } 19 | 20 | function _msgData() internal view virtual returns (bytes calldata) { 21 | this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 22 | return msg.data; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /contracts/polygon/fx-portal/contracts/lib/ERC165.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "./IERC165.sol"; 6 | 7 | /** 8 | * @dev Implementation of the {IERC165} interface. 9 | * 10 | * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check 11 | * for the additional interface id that will be supported. For example: 12 | * 13 | * ```solidity 14 | * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { 15 | * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); 16 | * } 17 | * ``` 18 | * 19 | * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation. 20 | */ 21 | abstract contract ERC165 is IERC165 { 22 | /** 23 | * @dev See {IERC165-supportsInterface}. 24 | */ 25 | function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { 26 | return interfaceId == type(IERC165).interfaceId; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /contracts/polygon/fx-portal/contracts/tokens/IFxERC1155.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | import {IERC1155} from "../lib/IERC1155.sol"; 5 | 6 | interface IFxERC1155 is IERC1155 { 7 | function fxManager() external returns (address); 8 | 9 | function initialize( 10 | address fxManager_, 11 | address connectedToken_, 12 | string memory uri_ 13 | ) external; 14 | 15 | function connectedToken() external returns (address); 16 | 17 | function mint( 18 | address user, 19 | uint256 id, 20 | uint256 amount, 21 | bytes memory data 22 | ) external; 23 | 24 | function mintBatch( 25 | address user, 26 | uint256[] memory ids, 27 | uint256[] memory amounts, 28 | bytes memory data 29 | ) external; 30 | 31 | function burn( 32 | address user, 33 | uint256 id, 34 | uint256 amount 35 | ) external; 36 | 37 | function burnBatch( 38 | address user, 39 | uint256[] memory ids, 40 | uint256[] memory amounts 41 | ) external; 42 | } 43 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Pheasant Network 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /contracts/diamond/interfaces/IDiamondCut.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | /******************************************************************************\ 5 | * Author: Nick Mudge (https://twitter.com/mudgen) 6 | * EIP-2535 Diamonds: https://eips.ethereum.org/EIPS/eip-2535 7 | /******************************************************************************/ 8 | 9 | import { IDiamond } from "./IDiamond.sol"; 10 | 11 | interface IDiamondCut is IDiamond { 12 | 13 | /// @notice Add/replace/remove any number of functions and optionally execute 14 | /// a function with delegatecall 15 | /// @param _diamondCut Contains the facet addresses and function selectors 16 | /// @param _init The address of the contract or facet to execute _calldata 17 | /// @param _calldata A function call, including function selector and arguments 18 | /// _calldata is executed with delegatecall on _init 19 | function diamondCut( 20 | FacetCut[] calldata _diamondCut, 21 | address _init, 22 | bytes calldata _calldata 23 | ) external; 24 | } 25 | -------------------------------------------------------------------------------- /contracts/polygon/fx-portal/contracts/lib/Merkle.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | library Merkle { 5 | function checkMembership( 6 | bytes32 leaf, 7 | uint256 index, 8 | bytes32 rootHash, 9 | bytes memory proof 10 | ) internal pure returns (bool) { 11 | require(proof.length % 32 == 0, "Invalid proof length"); 12 | uint256 proofHeight = proof.length / 32; 13 | // Proof of size n means, height of the tree is n+1. 14 | // In a tree of height n+1, max #leafs possible is 2 ^ n 15 | require(index < 2**proofHeight, "Leaf index is too big"); 16 | 17 | bytes32 proofElement; 18 | bytes32 computedHash = leaf; 19 | for (uint256 i = 32; i <= proof.length; i += 32) { 20 | assembly { 21 | proofElement := mload(add(proof, i)) 22 | } 23 | 24 | if (index % 2 == 0) { 25 | computedHash = keccak256(abi.encodePacked(computedHash, proofElement)); 26 | } else { 27 | computedHash = keccak256(abi.encodePacked(proofElement, computedHash)); 28 | } 29 | 30 | index = index / 2; 31 | } 32 | return computedHash == rootHash; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /contracts/polygon/fx-portal/contracts/FxRoot.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // This file is a modified version of RLPEncode.sol: 3 | // https://github.com/0xPolygon/fx-portal/tree/99cbdc89eec0674f7c8b6d3549acb148812f9285/contracts 4 | // 5 | // MODIFICATIONS 6 | // 1. Chenged solidity version to 0.8.18 from ^0.8.0 7 | 8 | pragma solidity 0.8.18; 9 | 10 | interface IStateSender { 11 | function syncState(address receiver, bytes calldata data) external; 12 | } 13 | 14 | interface IFxStateSender { 15 | function sendMessageToChild(address _receiver, bytes calldata _data) external; 16 | } 17 | 18 | /** 19 | * @title FxRoot root contract for fx-portal 20 | */ 21 | contract FxRoot is IFxStateSender { 22 | IStateSender public stateSender; 23 | address public fxChild; 24 | 25 | constructor(address _stateSender) { 26 | stateSender = IStateSender(_stateSender); 27 | } 28 | 29 | function setFxChild(address _fxChild) public { 30 | require(fxChild == address(0x0)); 31 | fxChild = _fxChild; 32 | } 33 | 34 | function sendMessageToChild(address _receiver, bytes calldata _data) public override { 35 | bytes memory data = abi.encode(msg.sender, _receiver, _data); 36 | stateSender.syncState(fxChild, data); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /contracts/diamond/facets/Test2Facet.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // This file is a modified version of RLPEncode.sol: 3 | // https://github.com/mudgen/diamond-1-hardhat/tree/10a001c8f0d9e8b71e7e2fd8b5829da8a18f9a57/contracts 4 | // 5 | // MODIFICATIONS 6 | // 1. Chenged solidity version to 0.8.18 from ^0.8.0 7 | 8 | pragma solidity 0.8.18; 9 | 10 | contract Test2Facet { 11 | function test2Func1() external {} 12 | 13 | function test2Func2() external {} 14 | 15 | function test2Func3() external {} 16 | 17 | function test2Func4() external {} 18 | 19 | function test2Func5() external {} 20 | 21 | function test2Func6() external {} 22 | 23 | function test2Func7() external {} 24 | 25 | function test2Func8() external {} 26 | 27 | function test2Func9() external {} 28 | 29 | function test2Func10() external {} 30 | 31 | function test2Func11() external {} 32 | 33 | function test2Func12() external {} 34 | 35 | function test2Func13() external {} 36 | 37 | function test2Func14() external {} 38 | 39 | function test2Func15() external {} 40 | 41 | function test2Func16() external {} 42 | 43 | function test2Func17() external {} 44 | 45 | function test2Func18() external {} 46 | 47 | function test2Func19() external {} 48 | 49 | function test2Func20() external {} 50 | } 51 | -------------------------------------------------------------------------------- /scripts/testFunctionCall.js: -------------------------------------------------------------------------------- 1 | require('dotenv').config({ path: '../.env' }); 2 | const utils = require('../utils/index') 3 | 4 | const contractAddressObj = utils.getContractAddresses() 5 | 6 | const main = async () => { 7 | 8 | const contractAddress = contractAddressObj[hre.network.name].PheasantNetworkBridgeChild; 9 | 10 | let response 11 | let pheasantNetworkBridgeChild; 12 | 13 | // set contract instance 14 | if ( 15 | hre.network.name == "mumbai" || hre.network.name == "polygon" 16 | ) { 17 | // set bridge contract instance 18 | pheasantNetworkBridgeChild = await hre.ethers.getContractAt( 19 | "contracts/polygon/PheasantNetworkBridgeChild.sol:PheasantNetworkBridgeChild", 20 | contractAddress 21 | ); 22 | } else { // for EVM equivalent L2. ex, Optimism, Arbitrum, scroll 23 | // set bridge contract instance 24 | pheasantNetworkBridgeChild = await hre.ethers.getContractAt( 25 | "contracts/L2/PheasantNetworkBridgeChild.sol:PheasantNetworkBridgeChild", 26 | contractAddress 27 | ); 28 | } 29 | 30 | // Change function name that you want to call 31 | response = await pheasantNetworkBridgeChild.getTrade("", 0); 32 | 33 | console.log(response); 34 | } 35 | 36 | main() 37 | .then(() => process.exit(0)) 38 | .catch((error) => { 39 | console.error(error); 40 | process.exit(1); 41 | }); 42 | 43 | -------------------------------------------------------------------------------- /contracts/L2/checkpoint-manager/ArbitrumChildCheckpointManager.sol: -------------------------------------------------------------------------------- 1 | //SPDX-License-Identifier: MIT 2 | pragma solidity 0.8.18; 3 | 4 | import "./CoreChildCheckpointManager.sol"; 5 | import "@arbitrum/nitro-contracts/src/libraries/AddressAliasHelper.sol"; 6 | 7 | contract ArbitrumChildCheckpointManager is CoreChildCheckpointManager { 8 | constructor (address _rootCheckpointManager, address _newOwner) CoreChildCheckpointManager(_rootCheckpointManager, _newOwner) {} 9 | 10 | function _processMessageFromRoot( 11 | bytes memory data 12 | ) external validateSender(msg.sender) { 13 | // decode incoming data 14 | (bytes32 syncType, bytes memory syncData) = abi.decode(data, (bytes32, bytes)); 15 | 16 | if (syncType == RECEIVE_BLOCK_INFO) { 17 | (uint256 destCode, uint256 blockNumber, bytes32 blockHash) = abi.decode(syncData, (uint256, uint256, bytes32)); 18 | require(blockHash != bytes32(0), "ArbitrumChildCheckpointManager: INVALID_BLOCKHASH"); 19 | blockHashs[destCode][blockNumber] = blockHash; 20 | } else { 21 | revert("ArbitrumChildCheckpointManager: INVALID_SYNC_TYPE"); 22 | } 23 | } 24 | 25 | modifier validateSender(address _sender) { 26 | require(_sender == AddressAliasHelper.applyL1ToL2Alias(rootCheckpointManager), "ArbitrumInboxContract: INVALID_SENDER_FROM_ROOT"); 27 | _; 28 | } 29 | } -------------------------------------------------------------------------------- /contracts/L2/IPheasantNetworkParameters.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity 0.8.18; 3 | 4 | import { Types } from "../libraries/types/Types.sol"; 5 | 6 | interface IPheasantNetworkParameters { 7 | function networkCode() external view returns (uint256); 8 | function relayer() external view returns (address); 9 | function withdrawalBlockPeriod() external view returns (uint256); 10 | function tradableBondRatio() external view returns (uint256); 11 | function defencePeriod() external view returns (uint256); 12 | function disputablePeriod() external view returns (uint256); 13 | function withdrawalPeriod() external view returns (uint256); 14 | function tokenAddress(uint256 _networkCode, uint8 _tokenTypeIndex) external view returns (address); 15 | function tradeThreshold(uint8 _tokenTypeIndex) external view returns(uint256); 16 | function tradeMinimumAmount(uint8 _tokenTypeIndex) external view returns (uint256); 17 | function availableNetwork(uint256 _networkCode) external view returns (uint256); 18 | function slashableNetwork(uint256 _networkCode) external view returns (uint256); 19 | function nativeIsNotETH(uint256 _destCode) external view returns (uint256); 20 | function disputeDepositAmount(uint8 _tokenTypeIndex) external view returns (uint256); 21 | function getRelayerFee(uint8 _tokenTypeIndex) external view returns (uint256); 22 | function getRequiredBondAmount(uint256 _amount) external view returns (uint256); 23 | } -------------------------------------------------------------------------------- /scripts/relayerFee.js: -------------------------------------------------------------------------------- 1 | require('dotenv').config({ path: '../.env' }); 2 | const readlineSync = require('readline-sync'); 3 | const utils = require('../utils/index'); 4 | 5 | const contractAddressObj = utils.getContractAddresses(); 6 | 7 | const main = async () => { 8 | const accounts = await ethers.getSigners(); 9 | 10 | const contractAddress = contractAddressObj[hre.network.name].PheasantNetworkBridgeChild; 11 | 12 | // set contract instance 13 | if ( 14 | hre.network.name == "mumbai" || hre.network.name == "polygon" 15 | ) { 16 | // set bridge contract instance 17 | pheasantNetworkBridgeChild = await hre.ethers.getContractAt( 18 | "contracts/polygon/PheasantNetworkBridgeChild.sol:PheasantNetworkBridgeChild", 19 | contractAddress 20 | ); 21 | } else { // for EVM equivalent L2. ex, Optimism, Arbitrum, scroll 22 | // set bridge contract instance 23 | pheasantNetworkBridgeChild = await hre.ethers.getContractAt( 24 | "contracts/L2/PheasantNetworkBridgeChild.sol:PheasantNetworkBridgeChild", 25 | contractAddress 26 | ); 27 | } 28 | 29 | // ask network 30 | const amount = readlineSync.question("Input the relayer fee amount : "); 31 | 32 | if(!isNaN(amount)) { 33 | let response = await pheasantNetworkBridgeChild.setNextFeeSetting([0, 0, 0, 0, 0]); 34 | console.log(response); 35 | } 36 | } 37 | 38 | main() 39 | .then(() => process.exit(0)) 40 | .catch((error) => { 41 | console.error(error); 42 | process.exit(1); 43 | }); 44 | 45 | -------------------------------------------------------------------------------- /utils/getBlockTimeAve.js: -------------------------------------------------------------------------------- 1 | const Web3 = require('web3'); 2 | require('dotenv').config({ path: '../.env' }); 3 | 4 | const networkList = [ 5 | "mainnet", 6 | "goerli", 7 | "mumbai", 8 | "polygon", 9 | "optimism", 10 | "optimismGoerli", 11 | "arbitrum", 12 | "arbitrumGoerli", 13 | "scrollTestnet", 14 | "zkSyncTestnet", 15 | "baseGoerli", 16 | "polygonZkEvmGoerli", 17 | "lineaGoerli", 18 | "taikoTestnet", 19 | "sepolia" 20 | ]; 21 | 22 | const utils = require('./index'); 23 | 24 | const main = async () => { 25 | for (let i = 0; i < networkList.length; i++) { 26 | console.log(`===== network: ${networkList[i]} =====`); 27 | const network = await utils.getNetwork(networkList[i]); 28 | const web3 = new Web3(network.provider); 29 | const latestBlock = await web3.eth.getBlock('latest'); 30 | let blockTimeAve = 0; 31 | if (latestBlock.number > 1000000) { 32 | const millionPassedBlock = await web3.eth.getBlock(latestBlock.number - 1000000); 33 | blockTimeAve = (latestBlock.timestamp - millionPassedBlock.timestamp) / 1000000; 34 | console.log(`blockTimeAve: ${blockTimeAve} in 1000000 blocks`); 35 | } else { 36 | const hundredThousandPassedBlock = await web3.eth.getBlock(latestBlock.number - 100000); 37 | blockTimeAve = (latestBlock.timestamp - hundredThousandPassedBlock.timestamp) / 100000; 38 | console.log(`blockTimeAve: ${blockTimeAve} in 100000 blocks`); 39 | } 40 | console.log("============================="); 41 | } 42 | } 43 | 44 | main(); -------------------------------------------------------------------------------- /contracts/polygon/fx-portal/contracts/FxChild.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // This file is a modified version of RLPEncode.sol: 3 | // https://github.com/0xPolygon/fx-portal/tree/99cbdc89eec0674f7c8b6d3549acb148812f9285/contracts 4 | // 5 | // MODIFICATIONS 6 | // 1. Chenged solidity version to 0.8.18 from ^0.8.0 7 | 8 | pragma solidity 0.8.18; 9 | 10 | // IStateReceiver represents interface to receive state 11 | interface IStateReceiver { 12 | function onStateReceive(uint256 stateId, bytes calldata data) external; 13 | } 14 | 15 | // IFxMessageProcessor represents interface to process message 16 | interface IFxMessageProcessor { 17 | function processMessageFromRoot( 18 | uint256 stateId, 19 | address rootMessageSender, 20 | bytes calldata data 21 | ) external; 22 | } 23 | 24 | /** 25 | * @title FxChild child contract for state receiver 26 | */ 27 | contract FxChild is IStateReceiver { 28 | address public fxRoot; 29 | 30 | event NewFxMessage(address rootMessageSender, address receiver, bytes data); 31 | 32 | function setFxRoot(address _fxRoot) external { 33 | require(fxRoot == address(0x0)); 34 | fxRoot = _fxRoot; 35 | } 36 | 37 | function onStateReceive(uint256 stateId, bytes calldata _data) external override { 38 | require(msg.sender == address(0x0000000000000000000000000000000000001001), "Invalid sender"); 39 | (address rootMessageSender, address receiver, bytes memory data) = abi.decode(_data, (address, address, bytes)); 40 | emit NewFxMessage(rootMessageSender, receiver, data); 41 | IFxMessageProcessor(receiver).processMessageFromRoot(stateId, rootMessageSender, data); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /contracts/polygon/fx-portal/contracts/lib/Create2.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | // Create2 adds common methods for minimal proxy with create2 5 | abstract contract Create2 { 6 | // creates clone using minimal proxy 7 | function createClone(bytes32 _salt, address _target) internal returns (address _result) { 8 | bytes20 _targetBytes = bytes20(_target); 9 | 10 | assembly { 11 | let clone := mload(0x40) 12 | mstore(clone, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000) 13 | mstore(add(clone, 0x14), _targetBytes) 14 | mstore(add(clone, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000) 15 | _result := create2(0, clone, 0x37, _salt) 16 | } 17 | 18 | require(_result != address(0), "Create2: Failed on minimal deploy"); 19 | } 20 | 21 | // get minimal proxy creation code 22 | function minimalProxyCreationCode(address logic) internal pure returns (bytes memory) { 23 | bytes10 creation = 0x3d602d80600a3d3981f3; 24 | bytes10 prefix = 0x363d3d373d3d3d363d73; 25 | bytes20 targetBytes = bytes20(logic); 26 | bytes15 suffix = 0x5af43d82803e903d91602b57fd5bf3; 27 | return abi.encodePacked(creation, prefix, targetBytes, suffix); 28 | } 29 | 30 | // get computed create2 address 31 | function computedCreate2Address( 32 | bytes32 salt, 33 | bytes32 bytecodeHash, 34 | address deployer 35 | ) public pure returns (address) { 36 | bytes32 _data = keccak256(abi.encodePacked(bytes1(0xff), deployer, salt, bytecodeHash)); 37 | return address(uint160(uint256(_data))); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /contracts/diamond/facets/DiamondCutFacet.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // This file is a modified version of RLPEncode.sol: 3 | // https://github.com/mudgen/diamond-1-hardhat/tree/10a001c8f0d9e8b71e7e2fd8b5829da8a18f9a57/contracts 4 | // 5 | // MODIFICATIONS 6 | // 1. Chenged solidity version to 0.8.18 from ^0.8.0 7 | 8 | pragma solidity 0.8.18; 9 | 10 | /******************************************************************************\ 11 | * Author: Nick Mudge (https://twitter.com/mudgen) 12 | * EIP-2535 Diamonds: https://eips.ethereum.org/EIPS/eip-2535 13 | /******************************************************************************/ 14 | 15 | import { IDiamondCut } from "../interfaces/IDiamondCut.sol"; 16 | import { LibDiamond } from "../libraries/LibDiamond.sol"; 17 | 18 | // Remember to add the loupe functions from DiamondLoupeFacet to the diamond. 19 | // The loupe functions are required by the EIP2535 Diamonds standard 20 | 21 | contract DiamondCutFacet is IDiamondCut { 22 | /// @notice Add/replace/remove any number of functions and optionally execute 23 | /// a function with delegatecall 24 | /// @param _diamondCut Contains the facet addresses and function selectors 25 | /// @param _init The address of the contract or facet to execute _calldata 26 | /// @param _calldata A function call, including function selector and arguments 27 | /// _calldata is executed with delegatecall on _init 28 | function diamondCut( 29 | FacetCut[] calldata _diamondCut, 30 | address _init, 31 | bytes calldata _calldata 32 | ) external override { 33 | LibDiamond.enforceIsContractOwner(); 34 | LibDiamond.diamondCut(_diamondCut, _init, _calldata); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /contracts/diamond/interfaces/IDiamondLoupe.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | /******************************************************************************\ 5 | * Author: Nick Mudge (https://twitter.com/mudgen) 6 | * EIP-2535 Diamonds: https://eips.ethereum.org/EIPS/eip-2535 7 | /******************************************************************************/ 8 | 9 | // A loupe is a small magnifying glass used to look at diamonds. 10 | // These functions look at diamonds 11 | interface IDiamondLoupe { 12 | /// These functions are expected to be called frequently 13 | /// by tools. 14 | 15 | struct Facet { 16 | address facetAddress; 17 | bytes4[] functionSelectors; 18 | } 19 | 20 | /// @notice Gets all facet addresses and their four byte function selectors. 21 | /// @return facets_ Facet 22 | function facets() external view returns (Facet[] memory facets_); 23 | 24 | /// @notice Gets all the function selectors supported by a specific facet. 25 | /// @param _facet The facet address. 26 | /// @return facetFunctionSelectors_ 27 | function facetFunctionSelectors(address _facet) external view returns (bytes4[] memory facetFunctionSelectors_); 28 | 29 | /// @notice Get all the facet addresses used by a diamond. 30 | /// @return facetAddresses_ 31 | function facetAddresses() external view returns (address[] memory facetAddresses_); 32 | 33 | /// @notice Gets the facet that supports the given selector. 34 | /// @dev If facet is not found return address(0). 35 | /// @param _functionSelector The function selector. 36 | /// @return facetAddress_ The facet address. 37 | function facetAddress(bytes4 _functionSelector) external view returns (address facetAddress_); 38 | } 39 | -------------------------------------------------------------------------------- /contracts/L2/checkpoint-manager/OptimismChildCheckpointManager.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity 0.8.18; 3 | 4 | import "./CoreChildCheckpointManager.sol"; 5 | import { ICrossDomainMessenger } from "@eth-optimism/contracts/libraries/bridge/ICrossDomainMessenger.sol"; 6 | 7 | contract OptimismChildCheckpointManager is CoreChildCheckpointManager { 8 | 9 | address public l2CrossDomainMessenger; 10 | 11 | constructor (address _rootCheckpointManager, address _newOwner, address _l2CrossDomainMessenger) CoreChildCheckpointManager(_rootCheckpointManager, _newOwner) { 12 | require(_l2CrossDomainMessenger != address(0x0), "OptimismChildCheckpointManager: INVALID_L2_CROSS_DOMAIN_MESSENGER"); 13 | l2CrossDomainMessenger = _l2CrossDomainMessenger; 14 | } 15 | 16 | function _processMessageFromRoot( 17 | bytes memory data 18 | ) external validateSender() { 19 | // decode incoming data 20 | (bytes32 syncType, bytes memory syncData) = abi.decode(data, (bytes32, bytes)); 21 | 22 | if (syncType == RECEIVE_BLOCK_INFO) { 23 | (uint256 destCode, uint256 blockNumber, bytes32 blockHash) = abi.decode(syncData, (uint256, uint256, bytes32)); 24 | require(blockHash != bytes32(0), "OptimismChildCheckpointManager: INVALID_BLOCKHASH"); 25 | blockHashs[destCode][blockNumber] = blockHash; 26 | } else { 27 | revert("CrossDomainMessage: INVALID_SYNC_TYPE"); 28 | } 29 | } 30 | 31 | modifier validateSender() { 32 | require( 33 | msg.sender == l2CrossDomainMessenger 34 | && ICrossDomainMessenger(l2CrossDomainMessenger).xDomainMessageSender() == rootCheckpointManager, 35 | "CrossDomainMessage: INVALID_SENDER_FROM_ROOT" 36 | ); 37 | _; 38 | } 39 | } -------------------------------------------------------------------------------- /test/dispute-manager/README.md: -------------------------------------------------------------------------------- 1 | # test data 2 | 3 | ## checkTransferTx.json 4 | 5 | - 3 6 | - txhash : 0xdb67b178670687b919f0a70d497f953be2b4597b01d875eb6e1d1bf02a3cfbee 7 | - chain : goerli 8 | - tokenaddress : 0x1535F5EC4Dad68c5Aab692B61AB78375F36CdF93 9 | - method : ERC20 transfer() 10 | - to : 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 11 | - amount : 10000000000000000000000 12 | - 4 13 | - txhash : 0x7b384f9a9a9d5a1614a025f187354faf19018fbe2fc4faea8002b5f66453a700 14 | - chain : goerli 15 | - to : 0x6d29fc79eab50b1ab0c8550ec2952896abcf0472 16 | - amount : 1000000000001001 17 | - 5 18 | - txhash : 0x2112350834f38ba4974e3b50c86202d83efe42c85c3ef60066e8ae9dca5e10d7 19 | - chain : goerli 20 | - tokenaddress : 0x1535F5EC4Dad68c5Aab692B61AB78375F36CdF93 21 | - method : ERC20 approve() 22 | - to : 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 23 | - amount : 10000000000000000000000 24 | - 6 25 | - txhash : 0xa18a5b03e37803f7498a789fdbdd18ee2303bccd1cef76250bd4ffa94fd7857a 26 | - chain : goerli 27 | - tokenaddress : 0x1535F5EC4Dad68c5Aab692B61AB78375F36CdF93 28 | - method : ERC20 transfer() 29 | - to : 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 30 | - amount : 100000000000001001 31 | 32 | 33 | ## receipt 34 | - 0 35 | - txhash : 0xdb67b178670687b919f0a70d497f953be2b4597b01d875eb6e1d1bf02a3cfbee 36 | - chain : goerli 37 | - tokenaddress : 0x1535F5EC4Dad68c5Aab692B61AB78375F36CdF93 38 | - method : ERC20 transfer() 39 | - to : 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 40 | - amount : 10000000000000000000000 41 | - 1 42 | - txhash : 0xcbf4c2e63b800032585145be98e2084fc8c5190a14b110f7caadaadaaad212b5 43 | - chain : goerli 44 | - tokenaddress : 0x1535F5EC4Dad68c5Aab692B61AB78375F36CdF93 45 | - method : ERC20 transfer() → fail 46 | - to : 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 47 | - amount : 9994000*10e18 -------------------------------------------------------------------------------- /scripts/createMultipleUpwardTrades.js: -------------------------------------------------------------------------------- 1 | require('dotenv').config({ path: '../.env' }); 2 | const readlineSync = require('readline-sync'); 3 | 4 | const main = async () => { 5 | 6 | let amount = readlineSync.question("Input the trade amount in wei: "); 7 | let networkCode; 8 | const network = readlineSync.question("Which network do you want to send?[p/o/a/s/z/b/pz/l/sn]"); 9 | if (network == "p") { 10 | networkCode = 1002; 11 | } else if (network == "o") { 12 | networkCode = 1003; 13 | } else if (network == "a") { 14 | networkCode = 1004; 15 | } else if (network == "s") { 16 | networkCode = 1005; 17 | } else if (network == "z") { 18 | networkCode = 1006; 19 | } else if (network == "b") { 20 | networkCode = 1007; 21 | } else if (network == "pz") { 22 | networkCode = 1008; 23 | } else if (network == "l") { 24 | networkCode = 1009; 25 | } else if (network == "sn") { 26 | networkCode = 1011; 27 | } 28 | if (amount < 10000) { 29 | console.log("Pls set more than 9999 wei!"); 30 | } else { 31 | amount = await ethers.BigNumber.from(amount); 32 | amount = amount.add(await ethers.BigNumber.from(networkCode)); 33 | console.log("Trading amount=", amount); 34 | const tradeNum = readlineSync.question("How many trades do you want to create : "); 35 | const accounts = await ethers.getSigners(); 36 | 37 | // Pls change destination address that you prefer! 38 | const destAddress = accounts[0].address; 39 | 40 | for (let i = 0; i < tradeNum; i++) { 41 | response = await accounts[0].sendTransaction({ 42 | to: destAddress, 43 | value: amount, 44 | }); 45 | console.log(response); 46 | } 47 | 48 | } 49 | } 50 | 51 | main() 52 | .then(() => process.exit(0)) 53 | .catch((error) => { 54 | console.error(error); 55 | process.exit(1); 56 | }); 57 | -------------------------------------------------------------------------------- /contracts/polygon/PolygonPheasantNetworkBridgeChild.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity 0.8.18; 3 | 4 | import "../L2/PheasantNetworkBridgeChild.sol"; 5 | import "solmate/src/utils/SafeTransferLib.sol"; 6 | import "solmate/src/tokens/ERC20.sol"; 7 | 8 | /** 9 | * @title PolygonPheasantNetworkBridgeChild 10 | * @dev PolygonPheasantNetworkBridgeChild is core contract inherited from PheasantNetworkBridgeChild for polygon. 11 | * It executes and manages bridge transaction. 12 | */ 13 | contract PolygonPheasantNetworkBridgeChild is PheasantNetworkBridgeChild { 14 | 15 | constructor( 16 | address _params, 17 | address _disputeManager, 18 | address _bondManager, 19 | address _newOwner 20 | ) PheasantNetworkBridgeChild( 21 | _params, 22 | _disputeManager, 23 | _bondManager, 24 | _newOwner 25 | ) {} 26 | 27 | function tokenValidation(uint256 _amount) internal override {} 28 | 29 | function tokenReceive(uint8 _tokenTypeIndex, uint256 _amount) internal override(PheasantNetworkBridgeChild) { 30 | token = ERC20(params.tokenAddress(params.networkCode(), _tokenTypeIndex)); 31 | SafeTransferLib.safeTransferFrom(token, msg.sender, address(this), _amount); 32 | } 33 | 34 | function tokenTransfer(uint8 _tokenTypeIndex, address _to, uint256 _amount) internal override(PheasantNetworkBridgeChild) { 35 | token = ERC20(params.tokenAddress(params.networkCode(), _tokenTypeIndex)); 36 | SafeTransferLib.safeTransfer(token, _to, _amount); 37 | } 38 | 39 | function tokenTransferFrom(uint8 _tokenTypeIndex, address _to, uint256 _amount) internal override(PheasantNetworkBridgeChild) { 40 | token = ERC20(params.tokenAddress(params.networkCode(), _tokenTypeIndex)); 41 | SafeTransferLib.safeTransferFrom(token, msg.sender, _to, _amount); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /contracts/L2/checkpoint-manager/CoreChildCheckpointManager.sol: -------------------------------------------------------------------------------- 1 | //SPDX-License-Identifier: MIT 2 | pragma solidity 0.8.18; 3 | 4 | import "solmate/src/auth/Owned.sol"; 5 | 6 | contract CoreChildCheckpointManager is Owned { 7 | 8 | address public rootCheckpointManager; 9 | bytes32 constant RECEIVE_BLOCK_INFO = keccak256("ReceiveBlockInfo"); 10 | uint256 constant UPDATE_PERIOD = 3 hours; 11 | 12 | mapping(uint256 => mapping(uint256 => bytes32)) internal blockHashs; 13 | 14 | struct RootCheckpointManagerUpdate { 15 | uint64 executeAfter; 16 | address newRootCheckpointManager; 17 | } 18 | RootCheckpointManagerUpdate public rootCheckpointManagerUpdate; 19 | 20 | constructor( 21 | address _rootCheckpointManager, 22 | address _newOwner 23 | ) Owned(_newOwner) { 24 | require(_rootCheckpointManager != address(0x0), "CoreChildCheckpointManager: INVALID_ROOT_CHECKPOINT_MANAGER"); 25 | rootCheckpointManager = _rootCheckpointManager; 26 | } 27 | 28 | function getBlockHash(uint256 _destCode, uint256 _blockNumber) external view returns (bytes32) { 29 | return blockHashs[_destCode][_blockNumber]; 30 | } 31 | 32 | function executeRootCheckpointManagerUpdate(address _newRootCheckpointManager) external onlyOwner { 33 | require(_newRootCheckpointManager != address(0x0), "CoreChildCheckpointManager: INVALID_ROOT_CHECKPOINT_MANAGER"); 34 | rootCheckpointManagerUpdate = RootCheckpointManagerUpdate(uint64(block.timestamp + UPDATE_PERIOD), _newRootCheckpointManager); 35 | } 36 | 37 | function finalizeUpdateRootCheckpointManager() external { 38 | require(uint64(block.timestamp) > rootCheckpointManagerUpdate.executeAfter && rootCheckpointManagerUpdate.executeAfter != 0, "Ongoing update period"); 39 | rootCheckpointManager = rootCheckpointManagerUpdate.newRootCheckpointManager; 40 | delete rootCheckpointManagerUpdate; 41 | } 42 | } -------------------------------------------------------------------------------- /contracts/polygon/fx-portal/contracts/tokens/FxERC721.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | import {ERC721} from "../lib/ERC721.sol"; 5 | import {IFxERC721} from "./IFxERC721.sol"; 6 | 7 | /** 8 | * @title FxERC20 represents fx erc20 9 | */ 10 | contract FxERC721 is IFxERC721, ERC721 { 11 | address internal _fxManager; 12 | address internal _connectedToken; 13 | 14 | function initialize( 15 | address fxManager_, 16 | address connectedToken_, 17 | string memory name_, 18 | string memory symbol_ 19 | ) public override { 20 | require(_fxManager == address(0x0) && _connectedToken == address(0x0), "Token is already initialized"); 21 | _fxManager = fxManager_; 22 | _connectedToken = connectedToken_; 23 | 24 | // setup meta data 25 | setupMetaData(name_, symbol_); 26 | } 27 | 28 | // fxManager returns fx manager 29 | function fxManager() public view override returns (address) { 30 | return _fxManager; 31 | } 32 | 33 | // connectedToken returns root token 34 | function connectedToken() public view override returns (address) { 35 | return _connectedToken; 36 | } 37 | 38 | // setup name, symbol and decimals 39 | function setupMetaData(string memory _name, string memory _symbol) public { 40 | require(msg.sender == _fxManager, "Invalid sender"); 41 | _setupMetaData(_name, _symbol); 42 | } 43 | 44 | function mint( 45 | address user, 46 | uint256 tokenId, 47 | bytes memory _data 48 | ) public override { 49 | require(msg.sender == _fxManager, "Invalid sender"); 50 | _safeMint(user, tokenId, _data); 51 | } 52 | 53 | function burn(uint256 tokenId) public override { 54 | require(msg.sender == _fxManager, "Invalid sender"); 55 | _burn(tokenId); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /contracts/polygon/fx-portal/contracts/tokens/FxERC20.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | import {ERC20} from "../lib/ERC20.sol"; 5 | import {IFxERC20} from "./IFxERC20.sol"; 6 | 7 | /** 8 | * @title FxERC20 represents fx erc20 9 | */ 10 | contract FxERC20 is IFxERC20, ERC20 { 11 | address internal _fxManager; 12 | address internal _connectedToken; 13 | 14 | function initialize( 15 | address fxManager_, 16 | address connectedToken_, 17 | string memory name_, 18 | string memory symbol_, 19 | uint8 decimals_ 20 | ) public override { 21 | require(_fxManager == address(0x0) && _connectedToken == address(0x0), "Token is already initialized"); 22 | _fxManager = fxManager_; 23 | _connectedToken = connectedToken_; 24 | 25 | // setup meta data 26 | setupMetaData(name_, symbol_, decimals_); 27 | } 28 | 29 | // fxManager rturns fx manager 30 | function fxManager() public view override returns (address) { 31 | return _fxManager; 32 | } 33 | 34 | // connectedToken returns root token 35 | function connectedToken() public view override returns (address) { 36 | return _connectedToken; 37 | } 38 | 39 | // setup name, symbol and decimals 40 | function setupMetaData( 41 | string memory _name, 42 | string memory _symbol, 43 | uint8 _decimals 44 | ) public { 45 | require(msg.sender == _fxManager, "Invalid sender"); 46 | _setupMetaData(_name, _symbol, _decimals); 47 | } 48 | 49 | function mint(address user, uint256 amount) public override { 50 | require(msg.sender == _fxManager, "Invalid sender"); 51 | _mint(user, amount); 52 | } 53 | 54 | function burn(address user, uint256 amount) public override { 55 | require(msg.sender == _fxManager, "Invalid sender"); 56 | _burn(user, amount); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "contracts", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "", 6 | "scripts": { 7 | "lint": "solhint 'contracts/**/*.sol'", 8 | "lint:fix": "prettier --write 'contracts/**/*.sol'", 9 | "setEnv:local": "bash ../script/setEnv.sh local", 10 | "switchNetwork": "bash ../script/switchEnvNetwork.sh", 11 | "setCheckpointManager": "node ./scripts/setCheckpointManager.js" 12 | }, 13 | "author": "", 14 | "license": "MIT", 15 | "dependencies": { 16 | "@arbitrum/nitro-contracts": "^1.0.2", 17 | "@chainlink/contracts": "^0.4.0", 18 | "@ethereumjs/tx": "^3.5.0", 19 | "@matterlabs/hardhat-zksync-deploy": "^0.6.3", 20 | "@matterlabs/hardhat-zksync-solc": "^0.4.0", 21 | "@matterlabs/hardhat-zksync-verify": "^0.1.8", 22 | "@openzeppelin/contracts": "^4.4.2", 23 | "bn.js": "^5.2.0", 24 | "dotenv": "^10.0.0", 25 | "ethereum-proof": "^1.0.12", 26 | "ethereumjs-util": "^7.1.4", 27 | "fs": "^0.0.1-security", 28 | "hardhat-contract-sizer": "^2.6.1", 29 | "merkle-patricia-tree": "^4.2.2", 30 | "readline": "^1.3.0", 31 | "readline-sync": "^1.4.10", 32 | "rlp": "^2.2.7", 33 | "solidity-bytes-utils": "^0.8.0", 34 | "solidity-coverage": "^0.7.21", 35 | "solmate": "^6.1.0", 36 | "web3": "^1.7.5" 37 | }, 38 | "devDependencies": { 39 | "@nomicfoundation/hardhat-chai-matchers": "^1.0.6", 40 | "@nomicfoundation/hardhat-network-helpers": "^1.0.7", 41 | "@nomiclabs/hardhat-ethers": "^2.0.6", 42 | "@nomiclabs/hardhat-waffle": "^2.0.3", 43 | "@openzeppelin/test-helpers": "^0.5.15", 44 | "chai": "^4.3.6", 45 | "ethereum-waffle": "^3.4.4", 46 | "ethers": "^5.7.2", 47 | "hardhat": "^2.13.0", 48 | "hardhat-gas-reporter": "^1.0.8", 49 | "prettier": "^2.6.2", 50 | "prettier-plugin-solidity": "^1.0.0-beta.19", 51 | "solhint": "^3.3.7", 52 | "solhint-plugin-prettier": "^0.0.5" 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /contracts/diamond/upgradeInitializers/DiamondMultiInit.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // This file is a modified version of RLPEncode.sol: 3 | // https://github.com/mudgen/diamond-1-hardhat/tree/10a001c8f0d9e8b71e7e2fd8b5829da8a18f9a57/contracts 4 | // 5 | // MODIFICATIONS 6 | // 1. Chenged solidity version to 0.8.18 from ^0.8.0 7 | 8 | pragma solidity 0.8.18; 9 | 10 | /******************************************************************************\ 11 | * Author: Nick Mudge (https://twitter.com/mudgen) 12 | * EIP-2535 Diamonds: https://eips.ethereum.org/EIPS/eip-2535 13 | * 14 | * Implementation of a diamond. 15 | /******************************************************************************/ 16 | 17 | import { LibDiamond } from "../libraries/LibDiamond.sol"; 18 | 19 | error AddressAndCalldataLengthDoNotMatch(uint256 _addressesLength, uint256 _calldataLength); 20 | 21 | 22 | // This Solidity library is deployed because it contains an external function. 23 | // This is deployed as a Solidity library instead of as regular contract because deployed Solidity libraries 24 | // cannot be deleted. If this was a contract then someone could call multiInit directly on the contract 25 | // with a regular external function call in order to delegatecall (via LibDiamond.initializeDiamondCut) 26 | // to a function that executes self destruct. 27 | 28 | library DiamondMultiInit { 29 | 30 | // This function is provided in the third parameter of the `diamondCut` function. 31 | // The `diamondCut` function executes this function to execute multiple initializer functions for a single upgrade. 32 | 33 | function multiInit(address[] calldata _addresses, bytes[] calldata _calldata) external { 34 | if(_addresses.length != _calldata.length) { 35 | revert AddressAndCalldataLengthDoNotMatch(_addresses.length, _calldata.length); 36 | } 37 | for(uint i; i < _addresses.length; i++) { 38 | LibDiamond.initializeDiamondCut(_addresses[i], _calldata[i]); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /scripts/managerSetting.js: -------------------------------------------------------------------------------- 1 | require('dotenv').config({ path: '../.env' }); 2 | const { Signer } = require('ethers'); 3 | const readlineSync = require('readline-sync'); 4 | const utils = require('../utils/index') 5 | 6 | let contractAddressObj = utils.getContractAddresses() 7 | 8 | const main = async () => { 9 | const accounts = await ethers.getSigners(); 10 | 11 | let pheasantNetworkBridgeChild; 12 | let response; 13 | 14 | if ( 15 | hre.network.name == "mumbai" || hre.network.name == "polygon" 16 | ) { 17 | const address = contractAddressObj[hre.network.name].PheasantNetworkBridgeChild; 18 | console.log("address", address); 19 | pheasantNetworkBridgeChild = await hre.ethers.getContractAt( 20 | "contracts/polygon/PolygonPheasantNetworkBridgeChild.sol:PolygonPheasantNetworkBridgeChild", 21 | address 22 | ); 23 | } else { 24 | const address = contractAddressObj[hre.network.name].PheasantNetworkBridgeChild; 25 | pheasantNetworkBridgeChild = await hre.ethers.getContractAt( 26 | "contracts/L2/PheasantNetworkBridgeChild.sol:PheasantNetworkBridgeChild", 27 | address 28 | ); 29 | } 30 | 31 | let operation = readlineSync.question("Execute, finalize, remaining time, or check address? [e/f/t/c]"); 32 | if (operation == "e") { 33 | // const bridgeDisputeManager = contractAddressObj[hre.network.name].BridgeDisputeManager; 34 | const bondManager = contractAddressObj[hre.network.name].BondManager; 35 | response = await pheasantNetworkBridgeChild.executeManagerUpdate( 36 | 1, 37 | bondManager 38 | ); 39 | console.log(response); 40 | } else if (operation == "f") { 41 | response = await pheasantNetworkBridgeChild.finalizeManagerUpdate(); 42 | console.log(response); 43 | } else if (operation == "t") { 44 | response = await pheasantNetworkBridgeChild.managerUpdate(); 45 | console.log(response); 46 | } else { 47 | console.log("Wrong operation!"); 48 | } 49 | 50 | } 51 | 52 | main() 53 | .then(() => process.exit(0)) 54 | .catch((error) => { 55 | console.error(error); 56 | process.exit(1); 57 | }); -------------------------------------------------------------------------------- /scripts/deployLibrary.js: -------------------------------------------------------------------------------- 1 | // We require the Hardhat Runtime Environment explicitly here. This is optional 2 | // but useful for running the script in a standalone fashion through `node