diff --git a/README.md b/README.md index fc00366a..4cabd94b 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ All system contracts will be flattened and output into `${workspace}/contracts/f 3. Edit system contracts setting as needed. 4. Run `node scripts/generate-genesis.js` will generate genesis.json -## How to generate mainnet/testnet/QA/dev genesis file +## How to generate mainnet/testnet/dev genesis file ```shell poetry run python -m scripts.generate ${network} @@ -67,6 +67,8 @@ poetry run python -m scripts.generate ${network} Check the `genesis.json` file, and you can get the exact compiled bytecode for different network. (`poetry run python -m scripts.generate --help ` for more details) +You can refer to `generate:dev` in `package.json` for more details about how to custom params for local dev-net. + ## How to update contract interface for test ```shell script diff --git a/contracts/BC_fusion/BSCGovernor.sol b/contracts/BC_fusion/BSCGovernor.sol index 5612d183..88c9ec69 100644 --- a/contracts/BC_fusion/BSCGovernor.sol +++ b/contracts/BC_fusion/BSCGovernor.sol @@ -33,9 +33,9 @@ contract BSCGovernor is * INIT_VOTING_DELAY, INIT_VOTING_PERIOD and INIT_MIN_PERIOD_AFTER_QUORUM are default in number of blocks, not seconds */ uint256 private constant BLOCK_INTERVAL = 3 seconds; - uint256 private constant INIT_VOTING_DELAY = 24 hours / BLOCK_INTERVAL; - uint256 private constant INIT_VOTING_PERIOD = 14 days / BLOCK_INTERVAL; - uint256 private constant INIT_PROPOSAL_THRESHOLD = 100 ether; // = 100 BNB + uint256 private constant INIT_VOTING_DELAY = 0 hours / BLOCK_INTERVAL; + uint256 private constant INIT_VOTING_PERIOD = 7 days / BLOCK_INTERVAL; + uint256 private constant INIT_PROPOSAL_THRESHOLD = 200 ether; // = 200 BNB uint256 private constant INIT_QUORUM_NUMERATOR = 10; // for >= 10% // starting propose requires totalSupply of GovBNB >= 10000000 * 1e18 diff --git a/contracts/BC_fusion/TokenRecoverPortal.sol b/contracts/BC_fusion/TokenRecoverPortal.sol index 99419251..8e2f299f 100644 --- a/contracts/BC_fusion/TokenRecoverPortal.sol +++ b/contracts/BC_fusion/TokenRecoverPortal.sol @@ -22,7 +22,7 @@ contract TokenRecoverPortal is System, ReentrancyGuardUpgradeable { using Utils for bytes; /*----------------- constants -----------------*/ - string public constant SOURCE_CHAIN_ID = "Binance-Chain-Ganges"; + string public constant SOURCE_CHAIN_ID = "Binance-Chain-Tigris"; /*----------------- storage -----------------*/ address public approvalAddress; @@ -53,7 +53,7 @@ contract TokenRecoverPortal is System, ReentrancyGuardUpgradeable { _; } - modifier approverlAddressInit() { + modifier approvalAddressInit() { if (approvalAddress == address(0)) revert ApprovalAddressNotInitialize(); _; } @@ -128,7 +128,7 @@ contract TokenRecoverPortal is System, ReentrancyGuardUpgradeable { bytes calldata ownerSignature, bytes calldata approvalSignature, bytes32[] calldata merkleProof - ) external merkelRootReady approverlAddressInit whenNotPaused nonReentrant { + ) external merkelRootReady approvalAddressInit whenNotPaused nonReentrant { // Recover the owner address and check signature. bytes memory ownerAddr = _verifySecp256k1Sig(ownerPubKey, ownerSignature, _tmSignatureHash(tokenSymbol, amount, msg.sender)); diff --git a/contracts/BSCValidatorSet.sol b/contracts/BSCValidatorSet.sol index 4b9507a3..7a2e6a93 100644 --- a/contracts/BSCValidatorSet.sol +++ b/contracts/BSCValidatorSet.sol @@ -38,7 +38,7 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica uint256 public constant EXPIRE_TIME_SECOND_GAP = 1000; uint256 public constant MAX_NUM_OF_VALIDATORS = 100; - bytes public constant INIT_VALIDATORSET_BYTES = hex"f87680f873f871949fb29aac15b9a4b7f17c3385939b007540f4d791949fb29aac15b9a4b7f17c3385939b007540f4d791949fb29aac15b9a4b7f17c3385939b007540f4d79164b085e6972fc98cd3c81d64d40e325acfed44365b97a7567a27939c14dbc7512ddcf54cb1284eb637cfa308ae4e00cb5588"; + bytes public constant INIT_VALIDATORSET_BYTES = hex"f905ec80f905e8f846942a7cdd959bfe8d9487b2a43b33565295a698f7e294b6a7edd747c0554875d3fc531d19ba1497992c5e941ff80f3f7f110ffd8920a3ac38fdef318fe94a3f86048c27395000f846946488aa4d1955ee33403f8ccb1d4de5fb97c7ade294220f003d8bdfaadf52aa1e55ae4cc485e6794875941a87e90e440a39c99aa9cb5cea0ad6a3f0b2407b86048c27395000f846949ef9f4360c606c7ab4db26b016007d3ad0ab86a0946103af86a874b705854033438383c82575f25bc29418e2db06cbff3e3c5f856410a1838649e760175786048c27395000f84694ee01c3b1283aa067c58eab4709f85e99d46de5fe94ee4b9bfb1871c64e2bcabb1dc382dc8b7c4218a29415904ab26ab0e99d70b51c220ccdcccabee6e29786048c27395000f84694685b1ded8013785d6623cc18d214320b6bb6475994a20ef4e5e4e7e36258dbf51f4d905114cb1b34bc9413e39085dc88704f4394d35209a02b1a9520320c86048c27395000f8469478f3adfc719c99674c072166708589033e2d9afe9448a30d5eaa7b64492a160f139e2da2800ec3834e94055838358c29edf4dcc1ba1985ad58aedbb6be2b86048c27395000f84694c2be4ec20253b8642161bc3f444f53679c1f3d479466f50c616d737e60d7ca6311ff0d9c434197898a94d1d678a2506eeaa365056fe565df8bc8659f28b086048c27395000f846942f7be8361c80a4c1e7e9aaf001d0877f1cfde218945f93992ac37f3e61db2ef8a587a436a161fd210b94ecbc4fb1a97861344dad0867ca3cba2b860411f086048c27395000f84694ce2fd7544e0b2cc94692d4a704debef7bcb613289444abc67b4b2fba283c582387f54c9cba7c34bafa948acc2ab395ded08bb75ce85bf0f95ad2abc51ad586048c27395000f84694b8f7166496996a7da21cf1f1b04d9b3e26a3d077946770572763289aac606e4f327c2f6cc1aa3b3e3b94882d745ed97d4422ca8da1c22ec49d880c4c097286048c27395000f846942d4c407bbe49438ed859fe965b140dcf1aab71a9943ad0939e120f33518fbba04631afe7a3ed6327b194b2bbb170ca4e499a2b0f3cc85ebfa6e8c4dfcbea86048c27395000f846946bbad7cf34b5fa511d8e963dbba288b1960e75d694853b0f6c324d1f4e76c8266942337ac1b0af1a229442498946a51ca5924552ead6fc2af08b94fcba648601d1a94a2000f846944430b3230294d12c6ab2aac5c2cd68e80b16b581947b107f4976a252a6939b771202c28e64e03f52d694795811a7f214084116949fc4f53cedbf189eeab28601d1a94a2000f84694ea0a6e3c511bbd10f4519ece37dc24887e11b55d946811ca77acfb221a49393c193f3a22db829fcc8e9464feb7c04830dd9ace164fc5c52b3f5a29e5018a8601d1a94a2000f846947ae2f5b9e386cd1b50a4550696d957cb4900f03a94e83bcc5077e6b873995c24bac871b5ad856047e19464e48d4057a90b233e026c1041e6012ada897fe88601d1a94a2000f8469482012708dafc9e1b880fd083b32182b869be8e09948e5adc73a2d233a1b496ed3115464dd6c7b887509428b383d324bc9a37f4e276190796ba5a8947f5ed8601d1a94a2000f8469422b81f8e175ffde54d797fe11eb03f9e3bf75f1d94a1c3ef7ca38d8ba80cce3bfc53ebd2903ed21658942767f7447f7b9b70313d4147b795414aecea54718601d1a94a2000f8469468bf0b8b6fb4e317a0f9d6f03eaf8ce6675bc60d94675cfe570b7902623f47e7f59c9664b5f5065dcf94d84f0d2e50bcf00f2fc476e1c57f5ca2d57f625b8601d1a94a2000f846948c4d90829ce8f72d0163c1d5cf348a862d5506309485c42a7b34309bee2ed6a235f86d16f059deec5894cc2cedc53f0fa6d376336efb67e43d167169f3b78601d1a94a2000f8469435e7a025f4da968de7e4d7e4004197917f4070f194b1182abaeeb3b4d8eba7e6a4162eac7ace23d57394c4fd0d870da52e73de2dd8ded19fe3d26f43a1138601d1a94a2000f84694d6caa02bbebaebb5d7e581e4b66559e635f805ff94c07335cf083c1c46a487f0325769d88e163b653694efaff03b42e41f953a925fc43720e45fb61a19938601d1a94a2000"; uint32 public constant ERROR_UNKNOWN_PACKAGE_TYPE = 101; uint32 public constant ERROR_FAIL_CHECK_VALIDATORS = 102; diff --git a/contracts/TendermintLightClient.sol b/contracts/TendermintLightClient.sol index c4e7fbd1..566ddf0b 100644 --- a/contracts/TendermintLightClient.sol +++ b/contracts/TendermintLightClient.sol @@ -22,7 +22,7 @@ contract TendermintLightClient is ILightClient, System, IParamSubscriber{ uint64 public latestHeight; bytes32 public chainID; - bytes constant public INIT_CONSENSUS_STATE_BYTES = hex"42696e616e63652d436861696e2d4e696c650000000000000000000000000000000000000000000229eca254b3859bffefaf85f4c95da9fbd26527766b784272789c30ec56b380b6eb96442aaab207bc59978ba3dd477690f5c5872334fc39e627723daa97e441e88ba4515150ec3182bc82593df36f8abb25a619187fcfab7e552b94e64ed2deed000000e8d4a51000"; + bytes constant public INIT_CONSENSUS_STATE_BYTES = hex"42696e616e63652d436861696e2d5469677269730000000000000000000000000000000006915167cedaf7bbf7df47d932fdda630527ee648562cf3e52c5e5f46156a3a971a4ceb443c53a50d8653ef8cf1e5716da68120fb51b636dc6d111ec3277b098ecd42d49d3769d8a1f78b4c17a965f7a30d4181fabbd1f969f46d3c8e83b5ad4845421d8000000e8d4a510002ba4e81542f437b7ae1f8a35ddb233c789a8dc22734377d9b6d63af1ca403b61000000e8d4a51000df8da8c5abfdb38595391308bb71e5a1e0aabdc1d0cf38315d50d6be939b2606000000e8d4a51000b6619edca4143484800281d698b70c935e9152ad57b31d85c05f2f79f64b39f3000000e8d4a510009446d14ad86c8d2d74780b0847110001a1c2e252eedfea4753ebbbfce3a22f52000000e8d4a510000353c639f80cc8015944436dab1032245d44f912edc31ef668ff9f4a45cd0599000000e8d4a51000e81d3797e0544c3a718e1f05f0fb782212e248e784c1a851be87e77ae0db230e000000e8d4a510005e3fcda30bd19d45c4b73688da35e7da1fce7c6859b2c1f20ed5202d24144e3e000000e8d4a51000b06a59a2d75bf5d014fce7c999b5e71e7a960870f725847d4ba3235baeaa08ef000000e8d4a510000c910e2fe650e4e01406b3310b489fb60a84bc3ff5c5bee3a56d5898b6a8af32000000e8d4a5100071f2d7b8ec1c8b99a653429b0118cd201f794f409d0fea4d65b1b662f2b00063000000e8d4a51000"; uint256 constant public INIT_REWARD_FOR_VALIDATOR_SER_CHANGE = 1e16; uint256 public rewardForValidatorSetChange; diff --git a/genesis.json b/genesis.json index c21c0591..dd78e570 100644 --- a/genesis.json +++ b/genesis.json @@ -1,6 +1,6 @@ { "config": { - "chainId": 714, + "chainId": 56, "homesteadBlock": 0, "eip150Block": 0, "eip155Block": 0, diff --git a/scripts/generate.py b/scripts/generate.py index e423e86a..f92bac11 100644 --- a/scripts/generate.py +++ b/scripts/generate.py @@ -211,7 +211,10 @@ def generate_tendermint_light_client(init_consensus_state_bytes, init_reward_for ) -def generate_token_hub(max_gas_for_transfer_bnb, max_gas_for_calling_bep20, reward_upper_limit, init_minimum_relay_fee, lock_period_for_token_recover): +def generate_token_hub( + max_gas_for_transfer_bnb, max_gas_for_calling_bep20, reward_upper_limit, init_minimum_relay_fee, + lock_period_for_token_recover +): contract = "TokenHub.sol" backup_file( os.path.join(work_dir, "contracts", contract), os.path.join(work_dir, "contracts", contract[:-4] + ".bak") @@ -221,7 +224,9 @@ def generate_token_hub(max_gas_for_transfer_bnb, max_gas_for_calling_bep20, rewa replace_parameter(contract, "uint256 constant public MAX_GAS_FOR_CALLING_BEP20", f"{max_gas_for_calling_bep20}") replace_parameter(contract, "uint256 constant public REWARD_UPPER_LIMIT", f"{reward_upper_limit}") replace_parameter(contract, "uint256 constant public INIT_MINIMUM_RELAY_FEE", f"{init_minimum_relay_fee}") - replace_parameter(contract, "uint256 constant public LOCK_PERIOD_FOR_TOKEN_RECOVER", f"{lock_period_for_token_recover}") + replace_parameter( + contract, "uint256 constant public LOCK_PERIOD_FOR_TOKEN_RECOVER", f"{lock_period_for_token_recover}" + ) def generate_token_recover_portal(source_chain_id): @@ -256,7 +261,11 @@ def generate_validator_set(init_validatorset_bytes, init_burn_ratio, epoch): contract, r"currentValidatorSet\.push\(validatorSetPkg.validatorSet\[i\]\);", "\t\t\tvalidatorExtraSet[i].voteAddress=validatorSetPkg.voteAddrs[i];" ) - replace(contract, r"handleSynPackage\(uint8, bytes calldata msgBytes\) onlyInit onlyCrossChainContract initValidatorExtraSet", "handleSynPackage(uint8, bytes calldata msgBytes) onlyInit initValidatorExtraSet") + replace( + contract, + r"handleSynPackage\(uint8, bytes calldata msgBytes\) onlyInit onlyCrossChainContract initValidatorExtraSet", + "handleSynPackage(uint8, bytes calldata msgBytes) onlyInit initValidatorExtraSet" + ) def generate_gov_hub(): @@ -266,7 +275,10 @@ def generate_gov_hub(): ) if network == "dev": - replace(contract, r"handleSynPackage\(uint8, bytes calldata msgBytes\) external onlyCrossChainContract override", "handleSynPackage(uint8, bytes calldata msgBytes) external override") + replace( + contract, r"handleSynPackage\(uint8, bytes calldata msgBytes\) external onlyCrossChainContract override", + "handleSynPackage(uint8, bytes calldata msgBytes) external override" + ) def generate_genesis(): @@ -281,6 +293,7 @@ def mainnet(): chain_id = 56 hex_chain_id = convert_chain_id(chain_id) + # mainnet init data init_consensus_bytes = "42696e616e63652d436861696e2d5469677269730000000000000000000000000000000006915167cedaf7bbf7df47d932fdda630527ee648562cf3e52c5e5f46156a3a971a4ceb443c53a50d8653ef8cf1e5716da68120fb51b636dc6d111ec3277b098ecd42d49d3769d8a1f78b4c17a965f7a30d4181fabbd1f969f46d3c8e83b5ad4845421d8000000e8d4a510002ba4e81542f437b7ae1f8a35ddb233c789a8dc22734377d9b6d63af1ca403b61000000e8d4a51000df8da8c5abfdb38595391308bb71e5a1e0aabdc1d0cf38315d50d6be939b2606000000e8d4a51000b6619edca4143484800281d698b70c935e9152ad57b31d85c05f2f79f64b39f3000000e8d4a510009446d14ad86c8d2d74780b0847110001a1c2e252eedfea4753ebbbfce3a22f52000000e8d4a510000353c639f80cc8015944436dab1032245d44f912edc31ef668ff9f4a45cd0599000000e8d4a51000e81d3797e0544c3a718e1f05f0fb782212e248e784c1a851be87e77ae0db230e000000e8d4a510005e3fcda30bd19d45c4b73688da35e7da1fce7c6859b2c1f20ed5202d24144e3e000000e8d4a51000b06a59a2d75bf5d014fce7c999b5e71e7a960870f725847d4ba3235baeaa08ef000000e8d4a510000c910e2fe650e4e01406b3310b489fb60a84bc3ff5c5bee3a56d5898b6a8af32000000e8d4a5100071f2d7b8ec1c8b99a653429b0118cd201f794f409d0fea4d65b1b662f2b00063000000e8d4a51000" init_burn_ratio = "1000" init_validatorset_bytes = "f905ec80f905e8f846942a7cdd959bfe8d9487b2a43b33565295a698f7e294b6a7edd747c0554875d3fc531d19ba1497992c5e941ff80f3f7f110ffd8920a3ac38fdef318fe94a3f86048c27395000f846946488aa4d1955ee33403f8ccb1d4de5fb97c7ade294220f003d8bdfaadf52aa1e55ae4cc485e6794875941a87e90e440a39c99aa9cb5cea0ad6a3f0b2407b86048c27395000f846949ef9f4360c606c7ab4db26b016007d3ad0ab86a0946103af86a874b705854033438383c82575f25bc29418e2db06cbff3e3c5f856410a1838649e760175786048c27395000f84694ee01c3b1283aa067c58eab4709f85e99d46de5fe94ee4b9bfb1871c64e2bcabb1dc382dc8b7c4218a29415904ab26ab0e99d70b51c220ccdcccabee6e29786048c27395000f84694685b1ded8013785d6623cc18d214320b6bb6475994a20ef4e5e4e7e36258dbf51f4d905114cb1b34bc9413e39085dc88704f4394d35209a02b1a9520320c86048c27395000f8469478f3adfc719c99674c072166708589033e2d9afe9448a30d5eaa7b64492a160f139e2da2800ec3834e94055838358c29edf4dcc1ba1985ad58aedbb6be2b86048c27395000f84694c2be4ec20253b8642161bc3f444f53679c1f3d479466f50c616d737e60d7ca6311ff0d9c434197898a94d1d678a2506eeaa365056fe565df8bc8659f28b086048c27395000f846942f7be8361c80a4c1e7e9aaf001d0877f1cfde218945f93992ac37f3e61db2ef8a587a436a161fd210b94ecbc4fb1a97861344dad0867ca3cba2b860411f086048c27395000f84694ce2fd7544e0b2cc94692d4a704debef7bcb613289444abc67b4b2fba283c582387f54c9cba7c34bafa948acc2ab395ded08bb75ce85bf0f95ad2abc51ad586048c27395000f84694b8f7166496996a7da21cf1f1b04d9b3e26a3d077946770572763289aac606e4f327c2f6cc1aa3b3e3b94882d745ed97d4422ca8da1c22ec49d880c4c097286048c27395000f846942d4c407bbe49438ed859fe965b140dcf1aab71a9943ad0939e120f33518fbba04631afe7a3ed6327b194b2bbb170ca4e499a2b0f3cc85ebfa6e8c4dfcbea86048c27395000f846946bbad7cf34b5fa511d8e963dbba288b1960e75d694853b0f6c324d1f4e76c8266942337ac1b0af1a229442498946a51ca5924552ead6fc2af08b94fcba648601d1a94a2000f846944430b3230294d12c6ab2aac5c2cd68e80b16b581947b107f4976a252a6939b771202c28e64e03f52d694795811a7f214084116949fc4f53cedbf189eeab28601d1a94a2000f84694ea0a6e3c511bbd10f4519ece37dc24887e11b55d946811ca77acfb221a49393c193f3a22db829fcc8e9464feb7c04830dd9ace164fc5c52b3f5a29e5018a8601d1a94a2000f846947ae2f5b9e386cd1b50a4550696d957cb4900f03a94e83bcc5077e6b873995c24bac871b5ad856047e19464e48d4057a90b233e026c1041e6012ada897fe88601d1a94a2000f8469482012708dafc9e1b880fd083b32182b869be8e09948e5adc73a2d233a1b496ed3115464dd6c7b887509428b383d324bc9a37f4e276190796ba5a8947f5ed8601d1a94a2000f8469422b81f8e175ffde54d797fe11eb03f9e3bf75f1d94a1c3ef7ca38d8ba80cce3bfc53ebd2903ed21658942767f7447f7b9b70313d4147b795414aecea54718601d1a94a2000f8469468bf0b8b6fb4e317a0f9d6f03eaf8ce6675bc60d94675cfe570b7902623f47e7f59c9664b5f5065dcf94d84f0d2e50bcf00f2fc476e1c57f5ca2d57f625b8601d1a94a2000f846948c4d90829ce8f72d0163c1d5cf348a862d5506309485c42a7b34309bee2ed6a235f86d16f059deec5894cc2cedc53f0fa6d376336efb67e43d167169f3b78601d1a94a2000f8469435e7a025f4da968de7e4d7e4004197917f4070f194b1182abaeeb3b4d8eba7e6a4162eac7ace23d57394c4fd0d870da52e73de2dd8ded19fe3d26f43a1138601d1a94a2000f84694d6caa02bbebaebb5d7e581e4b66559e635f805ff94c07335cf083c1c46a487f0325769d88e163b653694efaff03b42e41f953a925fc43720e45fb61a19938601d1a94a2000" @@ -288,12 +301,52 @@ def mainnet(): whitelist_2 = "0x446AA6E0DC65690403dF3F127750da1322941F3e" source_chain_id = "Binance-Chain-Tigris" + # TODO: update the following parameters + init_bc_consensus_addresses = 'hex"00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000"' + init_bc_vote_addresses = 'hex"00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000"' + asset_protector = "address(0xdEaD)" + governor_protector = "address(0xdEaD)" + + epoch = "200" + misdemeanor_threshold = "50" + felony_threshold = "150" + init_felony_slash_scope = "86400" + breathe_block_interval = "1 days" + block_interval = "3 seconds" + unbond_period = "7 days" + downtime_jail_time = "2 days" + felony_jail_time = "30 days" + init_voting_delay = "0 hours / BLOCK_INTERVAL" + init_voting_period = "7 days / BLOCK_INTERVAL" + init_min_period_after_quorum = "uint64(1 days / BLOCK_INTERVAL)" + init_minimal_delay = "24 hours" + max_gas_for_transfer_bnb = "10000" + max_gas_for_calling_bep20 = "50000" + reward_upper_limit = "1e18" + init_minimum_relay_fee = "2e15" + lock_period_for_token_recover = "7 days" + generate_system() generate_cross_chain() + generate_system_reward() + generate_gov_hub() + generate_slash_indicator(misdemeanor_threshold, felony_threshold, init_felony_slash_scope) generate_relayer_hub(whitelist_1, whitelist_2) generate_tendermint_light_client(init_consensus_bytes) - generate_validator_set(init_burn_ratio, init_validatorset_bytes) + generate_validator_set(init_validatorset_bytes, init_burn_ratio, epoch) generate_token_recover_portal(source_chain_id) + generate_stake_hub( + breathe_block_interval, init_bc_consensus_addresses, init_bc_vote_addresses, unbond_period, downtime_jail_time, + felony_jail_time, asset_protector + ) + generate_governor( + block_interval, init_voting_delay, init_voting_period, init_min_period_after_quorum, governor_protector + ) + generate_timelock(init_minimal_delay) + generate_token_hub( + max_gas_for_transfer_bnb, max_gas_for_calling_bep20, reward_upper_limit, init_minimum_relay_fee, + lock_period_for_token_recover + ) generate_genesis() print("Generate genesis of mainnet successfully") @@ -306,6 +359,7 @@ def testnet(): chain_id = 97 hex_chain_id = convert_chain_id(chain_id) + # testnet init data init_consensus_bytes = "42696e616e63652d436861696e2d47616e67657300000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000aea1ac326886b992a991d21a6eb155f41b77867cbf659e78f31d89d8205122a84d1be64f0e9a466c2e66a53433928192783e29f8fa21beb2133499b5ef770f60000000e8d4a5100099308aa365c40554bc89982af505d85da95251445d5dd4a9bb37dd2584fd92d3000000e8d4a5100001776920ff0b0f38d78cf95c033c21adf7045785114e392a7544179652e0a612000000e8d4a51000" init_burn_ratio = "1000" init_validatorset_bytes = "f901a880f901a4f844941284214b9b9c85549ab3d2b972df0deef66ac2c9946ddf42a51534fc98d0c0a3b42c963cace8441ddf946ddf42a51534fc98d0c0a3b42c963cace8441ddf8410000000f84494a2959d3f95eae5dc7d70144ce1b73b403b7eb6e0948081ef03f1d9e0bb4a5bf38f16285c879299f07f948081ef03f1d9e0bb4a5bf38f16285c879299f07f8410000000f8449435552c16704d214347f29fa77f77da6d75d7c75294dc4973e838e3949c77aced16ac2315dc2d7ab11194dc4973e838e3949c77aced16ac2315dc2d7ab1118410000000f84494980a75ecd1309ea12fa2ed87a8744fbfc9b863d594cc6ac05c95a99c1f7b5f88de0e3486c82293b27094cc6ac05c95a99c1f7b5f88de0e3486c82293b2708410000000f84494f474cf03cceff28abc65c9cbae594f725c80e12d94e61a183325a18a173319dd8e19c8d069459e217594e61a183325a18a173319dd8e19c8d069459e21758410000000f84494b71b214cb885500844365e95cd9942c7276e7fd894d22ca3ba2141d23adab65ce4940eb7665ea2b6a794d22ca3ba2141d23adab65ce4940eb7665ea2b6a78410000000" @@ -313,44 +367,55 @@ def testnet(): whitelist_2 = "0x37B8516a0F88E65D677229b402ec6C1e0E333004" source_chain_id = "Binance-Chain-Ganges" - generate_system() - generate_cross_chain() - generate_relayer_hub(whitelist_1, whitelist_2) - generate_tendermint_light_client(init_consensus_bytes) - generate_validator_set(init_burn_ratio, init_validatorset_bytes) - generate_token_recover_portal(source_chain_id) - - generate_genesis() - print("Generate genesis of testnet successfully") - - -@main.command(help="Generate contracts for qa environment") -def qa( - whitelist_1: Annotated[ - str, typer.Option(help="whitelist relayer1's address")] = "0x88cb4D8F77742c24d647BEf8049D3f3C56067cDD", - whitelist_2: Annotated[ - str, typer.Option(help="whitelist relayer2's address")] = "0x42D596440775C90db8d9187b47650986E1063493", - source_chain_id: Annotated[ - str, typer.Option(help="source chain id of the token recover portal")] = "Binance-Chain-Ganges" -): - global network, chain_id, hex_chain_id - network = "qa" - chain_id = 714 - hex_chain_id = convert_chain_id(chain_id) - - init_consensus_bytes = "42696e616e63652d436861696e2d47616e67657300000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000aea1ac326886b992a991d21a6eb155f41b77867cbf659e78f31d89d8205122a84d1be64f0e9a466c2e66a53433928192783e29f8fa21beb2133499b5ef770f60000000e8d4a5100099308aa365c40554bc89982af505d85da95251445d5dd4a9bb37dd2584fd92d3000000e8d4a5100001776920ff0b0f38d78cf95c033c21adf7045785114e392a7544179652e0a612000000e8d4a51000" - init_burn_ratio = "1000" - init_validatorset_bytes = "f901a880f901a4f844941284214b9b9c85549ab3d2b972df0deef66ac2c9946ddf42a51534fc98d0c0a3b42c963cace8441ddf946ddf42a51534fc98d0c0a3b42c963cace8441ddf8410000000f84494a2959d3f95eae5dc7d70144ce1b73b403b7eb6e0948081ef03f1d9e0bb4a5bf38f16285c879299f07f948081ef03f1d9e0bb4a5bf38f16285c879299f07f8410000000f8449435552c16704d214347f29fa77f77da6d75d7c75294dc4973e838e3949c77aced16ac2315dc2d7ab11194dc4973e838e3949c77aced16ac2315dc2d7ab1118410000000f84494980a75ecd1309ea12fa2ed87a8744fbfc9b863d594cc6ac05c95a99c1f7b5f88de0e3486c82293b27094cc6ac05c95a99c1f7b5f88de0e3486c82293b2708410000000f84494f474cf03cceff28abc65c9cbae594f725c80e12d94e61a183325a18a173319dd8e19c8d069459e217594e61a183325a18a173319dd8e19c8d069459e21758410000000f84494b71b214cb885500844365e95cd9942c7276e7fd894d22ca3ba2141d23adab65ce4940eb7665ea2b6a794d22ca3ba2141d23adab65ce4940eb7665ea2b6a78410000000" + # TODO: update the following parameters + init_bc_consensus_addresses = 'hex"00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000"' + init_bc_vote_addresses = 'hex"00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000"' + asset_protector = "address(0xdEaD)" + governor_protector = "address(0xdEaD)" + + epoch = "200" + misdemeanor_threshold = "50" + felony_threshold = "150" + init_felony_slash_scope = "86400" + breathe_block_interval = "1 days" + block_interval = "3 seconds" + unbond_period = "7 days" + downtime_jail_time = "2 days" + felony_jail_time = "30 days" + init_voting_delay = "0 hours / BLOCK_INTERVAL" + init_voting_period = "7 days / BLOCK_INTERVAL" + init_min_period_after_quorum = "uint64(1 days / BLOCK_INTERVAL)" + init_minimal_delay = "24 hours" + max_gas_for_transfer_bnb = "10000" + max_gas_for_calling_bep20 = "50000" + reward_upper_limit = "1e18" + init_minimum_relay_fee = "2e15" + lock_period_for_token_recover = "7 days" generate_system() generate_cross_chain() + generate_system_reward() + generate_gov_hub() + generate_slash_indicator(misdemeanor_threshold, felony_threshold, init_felony_slash_scope) generate_relayer_hub(whitelist_1, whitelist_2) generate_tendermint_light_client(init_consensus_bytes) - generate_validator_set(init_burn_ratio, init_validatorset_bytes) + generate_validator_set(init_validatorset_bytes, init_burn_ratio, epoch) generate_token_recover_portal(source_chain_id) + generate_stake_hub( + breathe_block_interval, init_bc_consensus_addresses, init_bc_vote_addresses, unbond_period, downtime_jail_time, + felony_jail_time, asset_protector + ) + generate_governor( + block_interval, init_voting_delay, init_voting_period, init_min_period_after_quorum, governor_protector + ) + generate_timelock(init_minimal_delay) + generate_token_hub( + max_gas_for_transfer_bnb, max_gas_for_calling_bep20, reward_upper_limit, init_minimum_relay_fee, + lock_period_for_token_recover + ) generate_genesis() - print("Generate genesis of qa environment successfully") + print("Generate genesis of testnet successfully") @main.command(help="Generate contracts for dev environment") @@ -380,18 +445,19 @@ def dev( downtime_jail_time: Annotated[str, typer.Option(help="downtimeJailTime of StakeHub")] = "2 days", felony_jail_time: Annotated[str, typer.Option(help="felonyJailTime of StakeHub")] = "30 days", init_voting_delay: Annotated[str, - typer.Option(help="INIT_VOTING_DELAY of BSCGovernor")] = "24 hours / BLOCK_INTERVAL", + typer.Option(help="INIT_VOTING_DELAY of BSCGovernor")] = "0 hours / BLOCK_INTERVAL", init_voting_period: Annotated[str, - typer.Option(help="INIT_VOTING_PERIOD of BSCGovernor")] = "14 days / BLOCK_INTERVAL", + typer.Option(help="INIT_VOTING_PERIOD of BSCGovernor")] = "7 days / BLOCK_INTERVAL", init_min_period_after_quorum: Annotated[ str, typer.Option(help="INIT_MIN_PERIOD_AFTER_QUORUM of BSCGovernor")] = "uint64(1 days / BLOCK_INTERVAL)", governor_protector: Annotated[str, typer.Option(help="governorProtector of BSCGovernor")] = "address(0xdEaD)", init_minimal_delay: Annotated[str, typer.Option(help="INIT_MINIMAL_DELAY of BSCTimelock")] = "24 hours", - max_gas_for_transfer_bnb: Annotated[str, typer.Option(help="MAX_GAS_FOR_TRANSFER_BNB of TokenHub")] = "10000", - max_gas_for_calling_bep20: Annotated[str, typer.Option(help="MAX_GAS_FOR_CALLING_BEP20 of TokenHub")] = "50000", - reward_upper_limit: Annotated[str, typer.Option(help="REWARD_UPPER_LIMIT of TokenHub")] = "1e18", - init_minimum_relay_fee: Annotated[str, typer.Option(help="INIT_MINIMUM_RELAY_FEE of TokenHub")] = "2e15", - lock_period_for_token_recover: Annotated[str, typer.Option(help="LOCK_PERIOD_FOR_TOKEN_RECOVER of TokenHub")] = "7 days" + max_gas_for_transfer_bnb: Annotated[str, typer.Option(help="MAX_GAS_FOR_TRANSFER_BNB of TokenHub")] = "10000", + max_gas_for_calling_bep20: Annotated[str, typer.Option(help="MAX_GAS_FOR_CALLING_BEP20 of TokenHub")] = "50000", + reward_upper_limit: Annotated[str, typer.Option(help="REWARD_UPPER_LIMIT of TokenHub")] = "1e18", + init_minimum_relay_fee: Annotated[str, typer.Option(help="INIT_MINIMUM_RELAY_FEE of TokenHub")] = "2e15", + lock_period_for_token_recover: Annotated[str, + typer.Option(help="LOCK_PERIOD_FOR_TOKEN_RECOVER of TokenHub")] = "7 days" ): global network, chain_id, hex_chain_id network = "dev" @@ -430,7 +496,10 @@ def dev( block_interval, init_voting_delay, init_voting_period, init_min_period_after_quorum, governor_protector ) generate_timelock(init_minimal_delay) - generate_token_hub(max_gas_for_transfer_bnb, max_gas_for_calling_bep20, reward_upper_limit, init_minimum_relay_fee, lock_period_for_token_recover) + generate_token_hub( + max_gas_for_transfer_bnb, max_gas_for_calling_bep20, reward_upper_limit, init_minimum_relay_fee, + lock_period_for_token_recover + ) generate_genesis() print("Generate genesis of dev environment successfully") diff --git a/test/StakeHub.t.sol b/test/StakeHub.t.sol index c4473c06..7ef29448 100644 --- a/test/StakeHub.t.sol +++ b/test/StakeHub.t.sol @@ -44,6 +44,8 @@ contract StakeHubTest is Deployer { vm.prank(block.coinbase); vm.txGasPrice(0); stakeHub.initialize(); + vm.prank(block.coinbase); + governor.initialize(); } function testCreateValidator() public { @@ -590,6 +592,16 @@ contract StakeHubTest is Deployer { emit log_named_bytes("vote address bytes", vBz); } + function testVotingDelay() public { + uint256 votingDelay = governor.votingDelay(); + emit log_named_uint("voting delay", votingDelay); + + uint256 clock = governor.clock(); + emit log_named_uint("clock", clock); + + emit log_named_uint("block number", block.number); + } + function _createValidator(uint256 delegation) internal returns (address operatorAddress, address credit) { operatorAddress = _getNextUserAddress(); StakeHub.Commission memory commission = StakeHub.Commission({ rate: 10, maxRate: 100, maxChangeRate: 5 });