From c2638fb7ec0ab687265c3e91abf1448cb464740d Mon Sep 17 00:00:00 2001 From: Ethan Date: Fri, 23 Aug 2024 19:38:16 +0800 Subject: [PATCH] feat: modify repo structure and rename BC_fusion/System.sol to SystemV2.sol (#588) * feat: modify repo structure and rename BC_fusion/System.sol to SystemV2.sol * feat: modify genesis generate script since repo structure changed * chores: modify lint cmt to fit repo structure changes * chores: lint contracts code * feat: add deprecated folder and move some contracts to it * fix: genesis generate script * fix: update foundry toolchain version * chores: lint contracts * feat: remove BC_fusion folder and move contracts to root dir * fix: genesis generate script * chores: modify fmt script * chores: modify foundry toolchain * feat: rename lib and interface folder * feat: remove unused BEP20Token.template * feat: remove unused mock --- contracts/{BC_fusion => }/BSCGovernor.sol | 8 +- contracts/{BC_fusion => }/BSCTimelock.sol | 6 +- contracts/BSCValidatorSet.sol | 28 +- contracts/GovHub.sol | 14 +- contracts/{BC_fusion => }/GovToken.sol | 6 +- contracts/SlashIndicator.sol | 26 +- contracts/{BC_fusion => }/StakeCredit.sol | 6 +- contracts/{BC_fusion => }/StakeHub.sol | 20 +- contracts/System.sol | 6 +- contracts/SystemReward.sol | 6 +- .../{BC_fusion/System.sol => SystemV2.sol} | 2 +- contracts/TokenHub.sol | 22 +- .../{BC_fusion => }/TokenRecoverPortal.sol | 10 +- contracts/bep20_template/BEP20Token.template | 593 ------------------ contracts/{ => deprecated}/CrossChain.sol | 24 +- contracts/{ => deprecated}/RelayerHub.sol | 12 +- .../{ => deprecated}/RelayerIncentivize.sol | 14 +- contracts/{ => deprecated}/Staking.sol | 26 +- .../TendermintLightClient.sol | 12 +- contracts/{ => deprecated}/TokenManager.sol | 18 +- .../BSCValidatorSetTool.sol | 4 +- .../{BC_fusion => }/extension/Protectable.sol | 0 .../interface/{ => 0.6.x}/IApplication.sol | 0 contracts/interface/{ => 0.6.x}/IBEP20.sol | 0 .../{ => 0.6.x}/IBSCValidatorSet.sol | 0 .../{ => 0.6.x}/IBSCValidatorSetV2.sol | 0 .../interface/{ => 0.6.x}/ICrossChain.sol | 0 .../interface/{ => 0.6.x}/ILightClient.sol | 0 .../{ => 0.6.x}/IParamSubscriber.sol | 0 .../interface/{ => 0.6.x}/IRelayerHub.sol | 0 .../{ => 0.6.x}/IRelayerIncentivize.sol | 0 .../interface/{ => 0.6.x}/ISlashIndicator.sol | 0 contracts/interface/{ => 0.6.x}/IStakeHub.sol | 0 contracts/interface/{ => 0.6.x}/IStaking.sol | 0 .../interface/{ => 0.6.x}/ISystemReward.sol | 0 contracts/interface/{ => 0.6.x}/ITokenHub.sol | 0 .../0.8.x}/IBSCValidatorSet.sol | 0 .../0.8.x}/ICrossChain.sol | 0 .../0.8.x}/IGovToken.sol | 0 .../0.8.x}/IStakeCredit.sol | 0 .../0.8.x}/IStakeHub.sol | 0 .../0.8.x}/ITokenHub.sol | 0 .../0.8.x}/ITokenRecoverPortal.sol | 0 contracts/lib/{ => 0.6.x}/BytesLib.sol | 0 contracts/lib/{ => 0.6.x}/BytesToTypes.sol | 0 contracts/lib/{ => 0.6.x}/CmnPkg.sol | 0 .../{bep20_template => lib/0.6.x}/LICENCE | 0 contracts/lib/{ => 0.6.x}/Memory.sol | 0 contracts/{ => lib/0.6.x}/MerkleProof.sol | 2 +- contracts/lib/{ => 0.6.x}/RLPDecode.sol | 0 contracts/lib/{ => 0.6.x}/RLPEncode.sol | 0 contracts/lib/{ => 0.6.x}/SafeMath.sol | 0 contracts/lib/{ => 0.6.x}/SizeOf.sol | 0 contracts/lib/{ => 0.6.x}/TypesToBytes.sol | 0 .../lib => lib/0.8.x}/RLPDecode.sol | 0 .../{BC_fusion/lib => lib/0.8.x}/Utils.sol | 0 contracts/lib/LICENCE | 22 - contracts/mock/MockTokenHub.sol | 66 -- package.json | 4 +- scripts/generate.py | 18 +- test/Governor.t.sol | 2 +- test/SlashIndicator.t.sol | 6 +- test/StakeHub.t.sol | 2 +- 63 files changed, 152 insertions(+), 833 deletions(-) rename contracts/{BC_fusion => }/BSCGovernor.sol (99%) rename contracts/{BC_fusion => }/BSCTimelock.sol (90%) rename contracts/{BC_fusion => }/GovToken.sol (98%) rename contracts/{BC_fusion => }/StakeCredit.sol (98%) rename contracts/{BC_fusion => }/StakeHub.sol (99%) rename contracts/{BC_fusion/System.sol => SystemV2.sol} (99%) rename contracts/{BC_fusion => }/TokenRecoverPortal.sol (97%) delete mode 100644 contracts/bep20_template/BEP20Token.template rename contracts/{ => deprecated}/CrossChain.sol (97%) rename contracts/{ => deprecated}/RelayerHub.sol (96%) rename contracts/{ => deprecated}/RelayerIncentivize.sol (97%) rename contracts/{ => deprecated}/Staking.sol (98%) rename contracts/{ => deprecated}/TendermintLightClient.sol (97%) rename contracts/{ => deprecated}/TokenManager.sol (98%) rename contracts/{tool => extension}/BSCValidatorSetTool.sol (98%) rename contracts/{BC_fusion => }/extension/Protectable.sol (100%) rename contracts/interface/{ => 0.6.x}/IApplication.sol (100%) rename contracts/interface/{ => 0.6.x}/IBEP20.sol (100%) rename contracts/interface/{ => 0.6.x}/IBSCValidatorSet.sol (100%) rename contracts/interface/{ => 0.6.x}/IBSCValidatorSetV2.sol (100%) rename contracts/interface/{ => 0.6.x}/ICrossChain.sol (100%) rename contracts/interface/{ => 0.6.x}/ILightClient.sol (100%) rename contracts/interface/{ => 0.6.x}/IParamSubscriber.sol (100%) rename contracts/interface/{ => 0.6.x}/IRelayerHub.sol (100%) rename contracts/interface/{ => 0.6.x}/IRelayerIncentivize.sol (100%) rename contracts/interface/{ => 0.6.x}/ISlashIndicator.sol (100%) rename contracts/interface/{ => 0.6.x}/IStakeHub.sol (100%) rename contracts/interface/{ => 0.6.x}/IStaking.sol (100%) rename contracts/interface/{ => 0.6.x}/ISystemReward.sol (100%) rename contracts/interface/{ => 0.6.x}/ITokenHub.sol (100%) rename contracts/{BC_fusion/interface => interface/0.8.x}/IBSCValidatorSet.sol (100%) rename contracts/{BC_fusion/interface => interface/0.8.x}/ICrossChain.sol (100%) rename contracts/{BC_fusion/interface => interface/0.8.x}/IGovToken.sol (100%) rename contracts/{BC_fusion/interface => interface/0.8.x}/IStakeCredit.sol (100%) rename contracts/{BC_fusion/interface => interface/0.8.x}/IStakeHub.sol (100%) rename contracts/{BC_fusion/interface => interface/0.8.x}/ITokenHub.sol (100%) rename contracts/{BC_fusion/interface => interface/0.8.x}/ITokenRecoverPortal.sol (100%) rename contracts/lib/{ => 0.6.x}/BytesLib.sol (100%) rename contracts/lib/{ => 0.6.x}/BytesToTypes.sol (100%) rename contracts/lib/{ => 0.6.x}/CmnPkg.sol (100%) rename contracts/{bep20_template => lib/0.6.x}/LICENCE (100%) rename contracts/lib/{ => 0.6.x}/Memory.sol (100%) rename contracts/{ => lib/0.6.x}/MerkleProof.sol (98%) rename contracts/lib/{ => 0.6.x}/RLPDecode.sol (100%) rename contracts/lib/{ => 0.6.x}/RLPEncode.sol (100%) rename contracts/lib/{ => 0.6.x}/SafeMath.sol (100%) rename contracts/lib/{ => 0.6.x}/SizeOf.sol (100%) rename contracts/lib/{ => 0.6.x}/TypesToBytes.sol (100%) rename contracts/{BC_fusion/lib => lib/0.8.x}/RLPDecode.sol (100%) rename contracts/{BC_fusion/lib => lib/0.8.x}/Utils.sol (100%) delete mode 100644 contracts/lib/LICENCE delete mode 100644 contracts/mock/MockTokenHub.sol diff --git a/contracts/BC_fusion/BSCGovernor.sol b/contracts/BSCGovernor.sol similarity index 99% rename from contracts/BC_fusion/BSCGovernor.sol rename to contracts/BSCGovernor.sol index be520d63..8eae46f7 100644 --- a/contracts/BC_fusion/BSCGovernor.sol +++ b/contracts/BSCGovernor.sol @@ -9,13 +9,13 @@ import "@openzeppelin/contracts-upgradeable/governance/extensions/GovernorTimelo import "@openzeppelin/contracts-upgradeable/governance/extensions/GovernorVotesQuorumFractionUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/governance/extensions/GovernorPreventLateQuorumUpgradeable.sol"; -import "./System.sol"; +import "./SystemV2.sol"; import "./extension/Protectable.sol"; -import "./lib/Utils.sol"; -import "./interface/IGovToken.sol"; +import "./lib/0.8.x/Utils.sol"; +import "./interface/0.8.x/IGovToken.sol"; contract BSCGovernor is - System, + SystemV2, Initializable, Protectable, GovernorUpgradeable, diff --git a/contracts/BC_fusion/BSCTimelock.sol b/contracts/BSCTimelock.sol similarity index 90% rename from contracts/BC_fusion/BSCTimelock.sol rename to contracts/BSCTimelock.sol index b01dfa3a..3049069b 100644 --- a/contracts/BC_fusion/BSCTimelock.sol +++ b/contracts/BSCTimelock.sol @@ -3,10 +3,10 @@ pragma solidity 0.8.17; import "@openzeppelin/contracts-upgradeable/governance/TimelockControllerUpgradeable.sol"; -import "./System.sol"; -import "./lib/Utils.sol"; +import "./SystemV2.sol"; +import "./lib/0.8.x/Utils.sol"; -contract BSCTimelock is System, Initializable, TimelockControllerUpgradeable { +contract BSCTimelock is SystemV2, Initializable, TimelockControllerUpgradeable { using Utils for bytes; using Utils for string; diff --git a/contracts/BSCValidatorSet.sol b/contracts/BSCValidatorSet.sol index fbc92601..07988d5f 100644 --- a/contracts/BSCValidatorSet.sol +++ b/contracts/BSCValidatorSet.sol @@ -2,20 +2,20 @@ pragma solidity 0.6.4; pragma experimental ABIEncoderV2; import "./System.sol"; -import "./lib/BytesLib.sol"; -import "./lib/BytesToTypes.sol"; -import "./lib/Memory.sol"; -import "./interface/ILightClient.sol"; -import "./interface/ISlashIndicator.sol"; -import "./interface/ITokenHub.sol"; -import "./interface/IRelayerHub.sol"; -import "./interface/IParamSubscriber.sol"; -import "./interface/IBSCValidatorSet.sol"; -import "./interface/IApplication.sol"; -import "./interface/IStakeHub.sol"; -import "./lib/SafeMath.sol"; -import "./lib/RLPDecode.sol"; -import "./lib/CmnPkg.sol"; +import "./lib/0.6.x/BytesLib.sol"; +import "./lib/0.6.x/BytesToTypes.sol"; +import "./lib/0.6.x/Memory.sol"; +import "./interface/0.6.x/ILightClient.sol"; +import "./interface/0.6.x/ISlashIndicator.sol"; +import "./interface/0.6.x/ITokenHub.sol"; +import "./interface/0.6.x/IRelayerHub.sol"; +import "./interface/0.6.x/IParamSubscriber.sol"; +import "./interface/0.6.x/IBSCValidatorSet.sol"; +import "./interface/0.6.x/IApplication.sol"; +import "./interface/0.6.x/IStakeHub.sol"; +import "./lib/0.6.x/SafeMath.sol"; +import "./lib/0.6.x/RLPDecode.sol"; +import "./lib/0.6.x/CmnPkg.sol"; interface ICrossChain { function registeredContractChannelMap(address, uint8) external view returns (bool); diff --git a/contracts/GovHub.sol b/contracts/GovHub.sol index 5223e552..7c50eef7 100644 --- a/contracts/GovHub.sol +++ b/contracts/GovHub.sol @@ -1,13 +1,13 @@ pragma solidity 0.6.4; import "./System.sol"; -import "./lib/BytesToTypes.sol"; -import "./lib/Memory.sol"; -import "./lib/BytesLib.sol"; -import "./interface/IParamSubscriber.sol"; -import "./interface/IApplication.sol"; -import "./lib/RLPDecode.sol"; -import "./lib/CmnPkg.sol"; +import "./lib/0.6.x/BytesToTypes.sol"; +import "./lib/0.6.x/Memory.sol"; +import "./lib/0.6.x/BytesLib.sol"; +import "./interface/0.6.x/IParamSubscriber.sol"; +import "./interface/0.6.x/IApplication.sol"; +import "./lib/0.6.x/RLPDecode.sol"; +import "./lib/0.6.x/CmnPkg.sol"; contract GovHub is System, IApplication { using RLPDecode for *; diff --git a/contracts/BC_fusion/GovToken.sol b/contracts/GovToken.sol similarity index 98% rename from contracts/BC_fusion/GovToken.sol rename to contracts/GovToken.sol index f0736b2c..05bbebce 100644 --- a/contracts/BC_fusion/GovToken.sol +++ b/contracts/GovToken.sol @@ -6,11 +6,11 @@ import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20Burnable import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20PermitUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20VotesUpgradeable.sol"; -import "./System.sol"; -import "./interface/IStakeCredit.sol"; +import "./SystemV2.sol"; +import "./interface/0.8.x/IStakeCredit.sol"; contract GovToken is - System, + SystemV2, Initializable, ERC20Upgradeable, ERC20BurnableUpgradeable, diff --git a/contracts/SlashIndicator.sol b/contracts/SlashIndicator.sol index 6b1d47f1..b1897f0d 100644 --- a/contracts/SlashIndicator.sol +++ b/contracts/SlashIndicator.sol @@ -2,19 +2,19 @@ pragma solidity 0.6.4; pragma experimental ABIEncoderV2; import "./System.sol"; -import "./lib/BytesToTypes.sol"; -import "./lib/TypesToBytes.sol"; -import "./lib/BytesLib.sol"; -import "./lib/Memory.sol"; -import "./interface/ISlashIndicator.sol"; -import "./interface/IApplication.sol"; -import "./interface/IBSCValidatorSet.sol"; -import "./interface/IParamSubscriber.sol"; -import "./interface/ICrossChain.sol"; -import "./interface/ISystemReward.sol"; -import "./interface/IStakeHub.sol"; -import "./lib/CmnPkg.sol"; -import "./lib/RLPEncode.sol"; +import "./lib/0.6.x/BytesToTypes.sol"; +import "./lib/0.6.x/TypesToBytes.sol"; +import "./lib/0.6.x/BytesLib.sol"; +import "./lib/0.6.x/Memory.sol"; +import "./interface/0.6.x/ISlashIndicator.sol"; +import "./interface/0.6.x/IApplication.sol"; +import "./interface/0.6.x/IBSCValidatorSet.sol"; +import "./interface/0.6.x/IParamSubscriber.sol"; +import "./interface/0.6.x/ICrossChain.sol"; +import "./interface/0.6.x/ISystemReward.sol"; +import "./interface/0.6.x/IStakeHub.sol"; +import "./lib/0.6.x/CmnPkg.sol"; +import "./lib/0.6.x/RLPEncode.sol"; contract SlashIndicator is ISlashIndicator, System, IParamSubscriber, IApplication { using RLPEncode for *; diff --git a/contracts/BC_fusion/StakeCredit.sol b/contracts/StakeCredit.sol similarity index 98% rename from contracts/BC_fusion/StakeCredit.sol rename to contracts/StakeCredit.sol index 5bd41923..b9c727b2 100644 --- a/contracts/BC_fusion/StakeCredit.sol +++ b/contracts/StakeCredit.sol @@ -6,10 +6,10 @@ import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol"; import "@openzeppelin/contracts-upgradeable/utils/CountersUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/utils/structs/DoubleEndedQueueUpgradeable.sol"; -import "./System.sol"; -import "./interface/IStakeHub.sol"; +import "./SystemV2.sol"; +import "./interface/0.8.x/IStakeHub.sol"; -contract StakeCredit is System, Initializable, ReentrancyGuardUpgradeable, ERC20Upgradeable { +contract StakeCredit is SystemV2, Initializable, ReentrancyGuardUpgradeable, ERC20Upgradeable { using CountersUpgradeable for CountersUpgradeable.Counter; using DoubleEndedQueueUpgradeable for DoubleEndedQueueUpgradeable.Bytes32Deque; diff --git a/contracts/BC_fusion/StakeHub.sol b/contracts/StakeHub.sol similarity index 99% rename from contracts/BC_fusion/StakeHub.sol rename to contracts/StakeHub.sol index 957e1856..9a873691 100644 --- a/contracts/BC_fusion/StakeHub.sol +++ b/contracts/StakeHub.sol @@ -5,17 +5,17 @@ import "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.so import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol"; import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; -import "./System.sol"; +import "./SystemV2.sol"; import "./extension/Protectable.sol"; -import "./interface/IBSCValidatorSet.sol"; -import "./interface/ICrossChain.sol"; -import "./interface/IGovToken.sol"; -import "./interface/IStakeCredit.sol"; -import "./interface/ITokenHub.sol"; -import "./lib/RLPDecode.sol"; -import "./lib/Utils.sol"; - -contract StakeHub is System, Initializable, Protectable { +import "./interface/0.8.x/IBSCValidatorSet.sol"; +import "./interface/0.8.x/ICrossChain.sol"; +import "./interface/0.8.x/IGovToken.sol"; +import "./interface/0.8.x/IStakeCredit.sol"; +import "./interface/0.8.x/ITokenHub.sol"; +import "./lib/0.8.x/RLPDecode.sol"; +import "./lib/0.8.x/Utils.sol"; + +contract StakeHub is SystemV2, Initializable, Protectable { using RLPDecode for *; using Utils for string; using Utils for bytes; diff --git a/contracts/System.sol b/contracts/System.sol index 45dfc87c..10eb27bc 100644 --- a/contracts/System.sol +++ b/contracts/System.sol @@ -1,8 +1,8 @@ pragma solidity 0.6.4; -import "./interface/ISystemReward.sol"; -import "./interface/IRelayerHub.sol"; -import "./interface/ILightClient.sol"; +import "./interface/0.6.x/ISystemReward.sol"; +import "./interface/0.6.x/IRelayerHub.sol"; +import "./interface/0.6.x/ILightClient.sol"; contract System { bool public alreadyInit; diff --git a/contracts/SystemReward.sol b/contracts/SystemReward.sol index 0998b0f4..fa5ad587 100644 --- a/contracts/SystemReward.sol +++ b/contracts/SystemReward.sol @@ -1,9 +1,9 @@ pragma solidity 0.6.4; import "./System.sol"; -import "./lib/Memory.sol"; -import "./interface/IParamSubscriber.sol"; -import "./interface/ISystemReward.sol"; +import "./lib/0.6.x/Memory.sol"; +import "./interface/0.6.x/IParamSubscriber.sol"; +import "./interface/0.6.x/ISystemReward.sol"; contract SystemReward is System, IParamSubscriber, ISystemReward { uint256 public constant MAX_REWARDS = 5e18; diff --git a/contracts/BC_fusion/System.sol b/contracts/SystemV2.sol similarity index 99% rename from contracts/BC_fusion/System.sol rename to contracts/SystemV2.sol index b08e2c81..d7520425 100644 --- a/contracts/BC_fusion/System.sol +++ b/contracts/SystemV2.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-or-later pragma solidity 0.8.17; -contract System { +contract SystemV2 { /*----------------- constants -----------------*/ uint8 public constant STAKING_CHANNELID = 0x08; uint8 public constant BC_FUSION_CHANNELID = 0x11; // new channel id for cross-chain redelegate from Beacon Chain to Smart Chain after Feynman upgrade diff --git a/contracts/TokenHub.sol b/contracts/TokenHub.sol index fc2902b9..79db085f 100644 --- a/contracts/TokenHub.sol +++ b/contracts/TokenHub.sol @@ -1,16 +1,16 @@ pragma solidity 0.6.4; -import "./interface/IBEP20.sol"; -import "./interface/ITokenHub.sol"; -import "./interface/IParamSubscriber.sol"; -import "./interface/IApplication.sol"; -import "./interface/ICrossChain.sol"; -import "./interface/ISystemReward.sol"; -import "./lib/SafeMath.sol"; -import "./lib/RLPEncode.sol"; -import "./lib/RLPDecode.sol"; -import "./lib/BytesToTypes.sol"; -import "./lib/Memory.sol"; +import "./interface/0.6.x/IBEP20.sol"; +import "./interface/0.6.x/ITokenHub.sol"; +import "./interface/0.6.x/IParamSubscriber.sol"; +import "./interface/0.6.x/IApplication.sol"; +import "./interface/0.6.x/ICrossChain.sol"; +import "./interface/0.6.x/ISystemReward.sol"; +import "./lib/0.6.x/SafeMath.sol"; +import "./lib/0.6.x/RLPEncode.sol"; +import "./lib/0.6.x/RLPDecode.sol"; +import "./lib/0.6.x/BytesToTypes.sol"; +import "./lib/0.6.x/Memory.sol"; import "./System.sol"; contract TokenHub is ITokenHub, System, IParamSubscriber, IApplication, ISystemReward { diff --git a/contracts/BC_fusion/TokenRecoverPortal.sol b/contracts/TokenRecoverPortal.sol similarity index 97% rename from contracts/BC_fusion/TokenRecoverPortal.sol rename to contracts/TokenRecoverPortal.sol index 44186cf4..0ca51e75 100644 --- a/contracts/BC_fusion/TokenRecoverPortal.sol +++ b/contracts/TokenRecoverPortal.sol @@ -5,11 +5,11 @@ import "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable. import "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol"; import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol"; -import "./System.sol"; +import "./SystemV2.sol"; import "./extension/Protectable.sol"; -import "./interface/ITokenHub.sol"; -import "./interface/ITokenRecoverPortal.sol"; -import "./lib/Utils.sol"; +import "./interface/0.8.x/ITokenHub.sol"; +import "./interface/0.8.x/ITokenRecoverPortal.sol"; +import "./lib/0.8.x/Utils.sol"; /** * @title TokenRecoverPortal is used to recover the token from BC users. @@ -18,7 +18,7 @@ import "./lib/Utils.sol"; * The BC users can recover the token from TokenHub after the merkle tree root is generated. * For more details, please refer to the BEP-299(https://github.com/bnb-chain/BEPs/pull/299). */ -contract TokenRecoverPortal is System, Initializable, ReentrancyGuardUpgradeable, Protectable { +contract TokenRecoverPortal is SystemV2, Initializable, ReentrancyGuardUpgradeable, Protectable { using Utils for string; using Utils for bytes; diff --git a/contracts/bep20_template/BEP20Token.template b/contracts/bep20_template/BEP20Token.template deleted file mode 100644 index 4a8a2b86..00000000 --- a/contracts/bep20_template/BEP20Token.template +++ /dev/null @@ -1,593 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity >0.4.0 <= 0.9.0; - -interface IBEP20 { - /** - * @dev Returns the amount of tokens in existence. - */ - function totalSupply() external view returns (uint256); - - /** - * @dev Returns the token decimals. - */ - function decimals() external view returns (uint8); - - /** - * @dev Returns the token symbol. - */ - function symbol() external view returns (string memory); - - /** - * @dev Returns the token name. - */ - function name() external view returns (string memory); - - /** - * @dev Returns the bep token owner. - */ - function getOwner() external view returns (address); - - /** - * @dev Returns the amount of tokens owned by `account`. - */ - function balanceOf(address account) external view returns (uint256); - - /** - * @dev Moves `amount` tokens from the caller's account to `recipient`. - * - * Returns a boolean value indicating whether the operation succeeded. - * - * Emits a {Transfer} event. - */ - function transfer(address recipient, uint256 amount) external returns (bool); - - /** - * @dev Returns the remaining number of tokens that `spender` will be - * allowed to spend on behalf of `owner` through {transferFrom}. This is - * zero by default. - * - * This value changes when {approve} or {transferFrom} are called. - */ - function allowance(address _owner, address spender) external view returns (uint256); - - /** - * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. - * - * Returns a boolean value indicating whether the operation succeeded. - * - * IMPORTANT: Beware that changing an allowance with this method brings the risk - * that someone may use both the old and the new allowance by unfortunate - * transaction ordering. One possible solution to mitigate this race - * condition is to first reduce the spender's allowance to 0 and set the - * desired value afterwards: - * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 - * - * Emits an {Approval} event. - */ - function approve(address spender, uint256 amount) external returns (bool); - - /** - * @dev Moves `amount` tokens from `sender` to `recipient` using the - * allowance mechanism. `amount` is then deducted from the caller's - * allowance. - * - * Returns a boolean value indicating whether the operation succeeded. - * - * Emits a {Transfer} event. - */ - function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); - - /** - * @dev Emitted when `value` tokens are moved from one account (`from`) to - * another (`to`). - * - * Note that `value` may be zero. - */ - event Transfer(address indexed from, address indexed to, uint256 value); - - /** - * @dev Emitted when the allowance of a `spender` for an `owner` is set by - * a call to {approve}. `value` is the new allowance. - */ - event Approval(address indexed owner, address indexed spender, uint256 value); -} - -/* - * @dev Provides information about the current execution context, including the - * sender of the transaction and its data. While these are generally available - * via msg.sender and msg.data, they should not be accessed in such a direct - * manner, since when dealing with GSN meta-transactions the account sending and - * paying for execution may not be the actual sender (as far as an application - * is concerned). - * - * This contract is only required for intermediate, library-like contracts. - */ -contract Context { - // Empty internal constructor, to prevent people from mistakenly deploying - // an instance of this contract, which should be used via inheritance. - constructor () { } - - function _msgSender() internal view returns (address) { - return msg.sender; - } - - function _msgData() internal view returns (bytes memory) { - this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 - return msg.data; - } -} - -/** - * @dev Wrappers over Solidity's arithmetic operations with added overflow - * checks. - * - * Arithmetic operations in Solidity wrap on overflow. This can easily result - * in bugs, because programmers usually assume that an overflow raises an - * error, which is the standard behavior in high level programming languages. - * `SafeMath` restores this intuition by reverting the transaction when an - * operation overflows. - * - * Using this library instead of the unchecked operations eliminates an entire - * class of bugs, so it's recommended to use it always. - */ -library SafeMath { - /** - * @dev Returns the addition of two unsigned integers, reverting on - * overflow. - * - * Counterpart to Solidity's `+` operator. - * - * Requirements: - * - Addition cannot overflow. - */ - function add(uint256 a, uint256 b) internal pure returns (uint256) { - uint256 c = a + b; - require(c >= a, "SafeMath: addition overflow"); - - return c; - } - - /** - * @dev Returns the subtraction of two unsigned integers, reverting on - * overflow (when the result is negative). - * - * Counterpart to Solidity's `-` operator. - * - * Requirements: - * - Subtraction cannot overflow. - */ - function sub(uint256 a, uint256 b) internal pure returns (uint256) { - return sub(a, b, "SafeMath: subtraction overflow"); - } - - /** - * @dev Returns the subtraction of two unsigned integers, reverting with custom message on - * overflow (when the result is negative). - * - * Counterpart to Solidity's `-` operator. - * - * Requirements: - * - Subtraction cannot overflow. - */ - function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { - require(b <= a, errorMessage); - uint256 c = a - b; - - return c; - } - - /** - * @dev Returns the multiplication of two unsigned integers, reverting on - * overflow. - * - * Counterpart to Solidity's `*` operator. - * - * Requirements: - * - Multiplication cannot overflow. - */ - function mul(uint256 a, uint256 b) internal pure returns (uint256) { - // Gas optimization: this is cheaper than requiring 'a' not being zero, but the - // benefit is lost if 'b' is also tested. - // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 - if (a == 0) { - return 0; - } - - uint256 c = a * b; - require(c / a == b, "SafeMath: multiplication overflow"); - - return c; - } - - /** - * @dev Returns the integer division of two unsigned integers. Reverts on - * division by zero. The result is rounded towards zero. - * - * Counterpart to Solidity's `/` operator. Note: this function uses a - * `revert` opcode (which leaves remaining gas untouched) while Solidity - * uses an invalid opcode to revert (consuming all remaining gas). - * - * Requirements: - * - The divisor cannot be zero. - */ - function div(uint256 a, uint256 b) internal pure returns (uint256) { - return div(a, b, "SafeMath: division by zero"); - } - - /** - * @dev Returns the integer division of two unsigned integers. Reverts with custom message on - * division by zero. The result is rounded towards zero. - * - * Counterpart to Solidity's `/` operator. Note: this function uses a - * `revert` opcode (which leaves remaining gas untouched) while Solidity - * uses an invalid opcode to revert (consuming all remaining gas). - * - * Requirements: - * - The divisor cannot be zero. - */ - function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { - // Solidity only automatically asserts when dividing by 0 - require(b > 0, errorMessage); - uint256 c = a / b; - // assert(a == b * c + a % b); // There is no case in which this doesn't hold - - return c; - } - - /** - * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), - * Reverts when dividing by zero. - * - * Counterpart to Solidity's `%` operator. This function uses a `revert` - * opcode (which leaves remaining gas untouched) while Solidity uses an - * invalid opcode to revert (consuming all remaining gas). - * - * Requirements: - * - The divisor cannot be zero. - */ - function mod(uint256 a, uint256 b) internal pure returns (uint256) { - return mod(a, b, "SafeMath: modulo by zero"); - } - - /** - * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), - * Reverts with custom message when dividing by zero. - * - * Counterpart to Solidity's `%` operator. This function uses a `revert` - * opcode (which leaves remaining gas untouched) while Solidity uses an - * invalid opcode to revert (consuming all remaining gas). - * - * Requirements: - * - The divisor cannot be zero. - */ - function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { - require(b != 0, errorMessage); - return a % b; - } -} - -/** - * @dev Contract module which provides a basic access control mechanism, where - * there is an account (an owner) that can be granted exclusive access to - * specific functions. - * - * By default, the owner account will be the one that deploys the contract. This - * can later be changed with {transferOwnership}. - * - * This module is used through inheritance. It will make available the modifier - * `onlyOwner`, which can be applied to your functions to restrict their use to - * the owner. - */ -contract Ownable is Context { - address private _owner; - - event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); - - /** - * @dev Initializes the contract setting the deployer as the initial owner. - */ - constructor () { - address msgSender = _msgSender(); - _owner = msgSender; - emit OwnershipTransferred(address(0), msgSender); - } - - /** - * @dev Returns the address of the current owner. - */ - function owner() public view returns (address) { - return _owner; - } - - /** - * @dev Throws if called by any account other than the owner. - */ - modifier onlyOwner() { - require(_owner == _msgSender(), "Ownable: caller is not the owner"); - _; - } - - /** - * @dev Leaves the contract without owner. It will not be possible to call - * `onlyOwner` functions anymore. Can only be called by the current owner. - * - * NOTE: Renouncing ownership will leave the contract without an owner, - * thereby removing any functionality that is only available to the owner. - */ - function renounceOwnership() public onlyOwner { - emit OwnershipTransferred(_owner, address(0)); - _owner = address(0); - } - - /** - * @dev Transfers ownership of the contract to a new account (`newOwner`). - * Can only be called by the current owner. - */ - function transferOwnership(address newOwner) public onlyOwner { - _transferOwnership(newOwner); - } - - /** - * @dev Transfers ownership of the contract to a new account (`newOwner`). - */ - function _transferOwnership(address newOwner) internal { - require(newOwner != address(0), "Ownable: new owner is the zero address"); - emit OwnershipTransferred(_owner, newOwner); - _owner = newOwner; - } -} - -contract BEP20Token is Context, IBEP20, Ownable { - using SafeMath for uint256; - - mapping (address => uint256) private _balances; - - mapping (address => mapping (address => uint256)) private _allowances; - - uint256 private _totalSupply; - uint8 private _decimals; - string private _symbol; - string private _name; - - constructor() public { - _name = "ABCToken"; - _symbol = "ABC"; - _decimals = 18; - _totalSupply = 1000000000000000; - _balances[msg.sender] = _totalSupply; - - emit Transfer(address(0), msg.sender, _totalSupply); - } - - /** - * @dev Returns the bep token owner. - */ - function getOwner() external view returns (address) { - return owner(); - } - - /** - * @dev Returns the token decimals. - */ - function decimals() external view returns (uint8) { - return _decimals; - } - - /** - * @dev Returns the token symbol. - */ - function symbol() external view returns (string memory) { - return _symbol; - } - - /** - * @dev Returns the token name. - */ - function name() external view returns (string memory) { - return _name; - } - - /** - * @dev See {BEP20-totalSupply}. - */ - function totalSupply() external view returns (uint256) { - return _totalSupply; - } - - /** - * @dev See {BEP20-balanceOf}. - */ - function balanceOf(address account) external view returns (uint256) { - return _balances[account]; - } - - /** - * @dev See {BEP20-transfer}. - * - * Requirements: - * - * - `recipient` cannot be the zero address. - * - the caller must have a balance of at least `amount`. - */ - function transfer(address recipient, uint256 amount) external returns (bool) { - _transfer(_msgSender(), recipient, amount); - return true; - } - - /** - * @dev See {BEP20-allowance}. - */ - function allowance(address owner, address spender) external view returns (uint256) { - return _allowances[owner][spender]; - } - - /** - * @dev See {BEP20-approve}. - * - * Requirements: - * - * - `spender` cannot be the zero address. - */ - function approve(address spender, uint256 amount) external returns (bool) { - _approve(_msgSender(), spender, amount); - return true; - } - - /** - * @dev See {BEP20-transferFrom}. - * - * Emits an {Approval} event indicating the updated allowance. This is not - * required by the EIP. See the note at the beginning of {BEP20}; - * - * Requirements: - * - `sender` and `recipient` cannot be the zero address. - * - `sender` must have a balance of at least `amount`. - * - the caller must have allowance for `sender`'s tokens of at least - * `amount`. - */ - function transferFrom(address sender, address recipient, uint256 amount) external returns (bool) { - _transfer(sender, recipient, amount); - _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "BEP20: transfer amount exceeds allowance")); - return true; - } - - /** - * @dev Atomically increases the allowance granted to `spender` by the caller. - * - * This is an alternative to {approve} that can be used as a mitigation for - * problems described in {BEP20-approve}. - * - * Emits an {Approval} event indicating the updated allowance. - * - * Requirements: - * - * - `spender` cannot be the zero address. - */ - function increaseAllowance(address spender, uint256 addedValue) public returns (bool) { - _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); - return true; - } - - /** - * @dev Atomically decreases the allowance granted to `spender` by the caller. - * - * This is an alternative to {approve} that can be used as a mitigation for - * problems described in {BEP20-approve}. - * - * Emits an {Approval} event indicating the updated allowance. - * - * Requirements: - * - * - `spender` cannot be the zero address. - * - `spender` must have allowance for the caller of at least - * `subtractedValue`. - */ - function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) { - _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "BEP20: decreased allowance below zero")); - return true; - } - - /** - * @dev Creates `amount` tokens and assigns them to `msg.sender`, increasing - * the total supply. - * - * Requirements - * - * - `msg.sender` must be the token owner - */ - function mint(uint256 amount) public onlyOwner returns (bool) { - _mint(_msgSender(), amount); - return true; - } - - /** - * @dev Moves tokens `amount` from `sender` to `recipient`. - * - * This is internal function is equivalent to {transfer}, and can be used to - * e.g. implement automatic token fees, slashing mechanisms, etc. - * - * Emits a {Transfer} event. - * - * Requirements: - * - * - `sender` cannot be the zero address. - * - `recipient` cannot be the zero address. - * - `sender` must have a balance of at least `amount`. - */ - function _transfer(address sender, address recipient, uint256 amount) internal { - require(sender != address(0), "BEP20: transfer from the zero address"); - require(recipient != address(0), "BEP20: transfer to the zero address"); - - _balances[sender] = _balances[sender].sub(amount, "BEP20: transfer amount exceeds balance"); - _balances[recipient] = _balances[recipient].add(amount); - emit Transfer(sender, recipient, amount); - } - - /** @dev Creates `amount` tokens and assigns them to `account`, increasing - * the total supply. - * - * Emits a {Transfer} event with `from` set to the zero address. - * - * Requirements - * - * - `to` cannot be the zero address. - */ - function _mint(address account, uint256 amount) internal { - require(account != address(0), "BEP20: mint to the zero address"); - - _totalSupply = _totalSupply.add(amount); - _balances[account] = _balances[account].add(amount); - emit Transfer(address(0), account, amount); - } - - /** - * @dev Destroys `amount` tokens from `account`, reducing the - * total supply. - * - * Emits a {Transfer} event with `to` set to the zero address. - * - * Requirements - * - * - `account` cannot be the zero address. - * - `account` must have at least `amount` tokens. - */ - function _burn(address account, uint256 amount) internal { - require(account != address(0), "BEP20: burn from the zero address"); - - _balances[account] = _balances[account].sub(amount, "BEP20: burn amount exceeds balance"); - _totalSupply = _totalSupply.sub(amount); - emit Transfer(account, address(0), amount); - } - - /** - * @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens. - * - * This is internal function is equivalent to `approve`, and can be used to - * e.g. set automatic allowances for certain subsystems, etc. - * - * Emits an {Approval} event. - * - * Requirements: - * - * - `owner` cannot be the zero address. - * - `spender` cannot be the zero address. - */ - function _approve(address owner, address spender, uint256 amount) internal { - require(owner != address(0), "BEP20: approve from the zero address"); - require(spender != address(0), "BEP20: approve to the zero address"); - - _allowances[owner][spender] = amount; - emit Approval(owner, spender, amount); - } - - /** - * @dev Destroys `amount` tokens from `account`.`amount` is then deducted - * from the caller's allowance. - * - * See {_burn} and {_approve}. - */ - function _burnFrom(address account, uint256 amount) internal { - _burn(account, amount); - _approve(account, _msgSender(), _allowances[account][_msgSender()].sub(amount, "BEP20: burn amount exceeds allowance")); - } -} diff --git a/contracts/CrossChain.sol b/contracts/deprecated/CrossChain.sol similarity index 97% rename from contracts/CrossChain.sol rename to contracts/deprecated/CrossChain.sol index a40d7f8e..2bbd0200 100644 --- a/contracts/CrossChain.sol +++ b/contracts/deprecated/CrossChain.sol @@ -1,17 +1,17 @@ pragma solidity 0.6.4; -import "./interface/IApplication.sol"; -import "./interface/ICrossChain.sol"; -import "./interface/ITokenHub.sol"; -import "./interface/ILightClient.sol"; -import "./interface/IRelayerIncentivize.sol"; -import "./interface/IRelayerHub.sol"; -import "./interface/IBSCValidatorSetV2.sol"; -import "./lib/Memory.sol"; -import "./lib/BytesToTypes.sol"; -import "./interface/IParamSubscriber.sol"; -import "./System.sol"; -import "./MerkleProof.sol"; +import "../interface/0.6.x/IApplication.sol"; +import "../interface/0.6.x/ICrossChain.sol"; +import "../interface/0.6.x/ITokenHub.sol"; +import "../interface/0.6.x/ILightClient.sol"; +import "../interface/0.6.x/IRelayerIncentivize.sol"; +import "../interface/0.6.x/IRelayerHub.sol"; +import "../interface/0.6.x/IBSCValidatorSetV2.sol"; +import "../lib/0.6.x/Memory.sol"; +import "../lib/0.6.x/BytesToTypes.sol"; +import "../interface/0.6.x/IParamSubscriber.sol"; +import "../System.sol"; +import "../lib/0.6.x/MerkleProof.sol"; contract CrossChain is System, ICrossChain, IParamSubscriber { // constant variables diff --git a/contracts/RelayerHub.sol b/contracts/deprecated/RelayerHub.sol similarity index 96% rename from contracts/RelayerHub.sol rename to contracts/deprecated/RelayerHub.sol index b9b1bcfd..a907fbd2 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/deprecated/RelayerHub.sol @@ -1,11 +1,11 @@ pragma solidity 0.6.4; -import "./lib/BytesToTypes.sol"; -import "./lib/Memory.sol"; -import "./interface/IRelayerHub.sol"; -import "./interface/IParamSubscriber.sol"; -import "./System.sol"; -import "./lib/SafeMath.sol"; +import "../lib/0.6.x/BytesToTypes.sol"; +import "../lib/0.6.x/Memory.sol"; +import "../interface/0.6.x/IRelayerHub.sol"; +import "../interface/0.6.x/IParamSubscriber.sol"; +import "../System.sol"; +import "../lib/0.6.x/SafeMath.sol"; contract RelayerHub is IRelayerHub, System, IParamSubscriber { using SafeMath for uint256; diff --git a/contracts/RelayerIncentivize.sol b/contracts/deprecated/RelayerIncentivize.sol similarity index 97% rename from contracts/RelayerIncentivize.sol rename to contracts/deprecated/RelayerIncentivize.sol index 16f2e5db..22ba9591 100644 --- a/contracts/RelayerIncentivize.sol +++ b/contracts/deprecated/RelayerIncentivize.sol @@ -1,12 +1,12 @@ pragma solidity 0.6.4; -import "./interface/IRelayerIncentivize.sol"; -import "./System.sol"; -import "./lib/SafeMath.sol"; -import "./lib/Memory.sol"; -import "./lib/BytesToTypes.sol"; -import "./interface/IParamSubscriber.sol"; -import "./interface/ISystemReward.sol"; +import "../interface/0.6.x/IRelayerIncentivize.sol"; +import "../System.sol"; +import "../lib/0.6.x/SafeMath.sol"; +import "../lib/0.6.x/Memory.sol"; +import "../lib/0.6.x/BytesToTypes.sol"; +import "../interface/0.6.x/IParamSubscriber.sol"; +import "../interface/0.6.x/ISystemReward.sol"; contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber { using SafeMath for uint256; diff --git a/contracts/Staking.sol b/contracts/deprecated/Staking.sol similarity index 98% rename from contracts/Staking.sol rename to contracts/deprecated/Staking.sol index 208b7ab3..b099f7ea 100644 --- a/contracts/Staking.sol +++ b/contracts/deprecated/Staking.sol @@ -1,18 +1,18 @@ pragma solidity 0.6.4; -import "./System.sol"; -import "./interface/IApplication.sol"; -import "./interface/ICrossChain.sol"; -import "./interface/IParamSubscriber.sol"; -import "./interface/IStaking.sol"; -import "./interface/ITokenHub.sol"; -import "./lib/BytesToTypes.sol"; -import "./lib/BytesLib.sol"; -import "./lib/CmnPkg.sol"; -import "./lib/Memory.sol"; -import "./lib/RLPEncode.sol"; -import "./lib/RLPDecode.sol"; -import "./lib/SafeMath.sol"; +import "../System.sol"; +import "../interface/0.6.x/IApplication.sol"; +import "../interface/0.6.x/ICrossChain.sol"; +import "../interface/0.6.x/IParamSubscriber.sol"; +import "../interface/0.6.x/IStaking.sol"; +import "../interface/0.6.x/ITokenHub.sol"; +import "../lib/0.6.x/BytesToTypes.sol"; +import "../lib/0.6.x/BytesLib.sol"; +import "../lib/0.6.x/CmnPkg.sol"; +import "../lib/0.6.x/Memory.sol"; +import "../lib/0.6.x/RLPEncode.sol"; +import "../lib/0.6.x/RLPDecode.sol"; +import "../lib/0.6.x/SafeMath.sol"; contract Staking is IStaking, System, IParamSubscriber, IApplication { using SafeMath for uint256; diff --git a/contracts/TendermintLightClient.sol b/contracts/deprecated/TendermintLightClient.sol similarity index 97% rename from contracts/TendermintLightClient.sol rename to contracts/deprecated/TendermintLightClient.sol index e0a1e01e..ad971bdf 100644 --- a/contracts/TendermintLightClient.sol +++ b/contracts/deprecated/TendermintLightClient.sol @@ -1,11 +1,11 @@ pragma solidity 0.6.4; -import "./lib/Memory.sol"; -import "./lib/BytesToTypes.sol"; -import "./interface/ILightClient.sol"; -import "./interface/ISystemReward.sol"; -import "./interface/IParamSubscriber.sol"; -import "./System.sol"; +import "../lib/0.6.x/Memory.sol"; +import "../lib/0.6.x/BytesToTypes.sol"; +import "../interface/0.6.x/ILightClient.sol"; +import "../interface/0.6.x/ISystemReward.sol"; +import "../interface/0.6.x/IParamSubscriber.sol"; +import "../System.sol"; contract TendermintLightClient is ILightClient, System, IParamSubscriber { struct ConsensusState { diff --git a/contracts/TokenManager.sol b/contracts/deprecated/TokenManager.sol similarity index 98% rename from contracts/TokenManager.sol rename to contracts/deprecated/TokenManager.sol index f5f8ca78..4e06cdde 100644 --- a/contracts/TokenManager.sol +++ b/contracts/deprecated/TokenManager.sol @@ -1,14 +1,14 @@ pragma solidity 0.6.4; -import "./interface/IBEP20.sol"; -import "./interface/ITokenHub.sol"; -import "./interface/IApplication.sol"; -import "./interface/ICrossChain.sol"; -import "./interface/IParamSubscriber.sol"; -import "./lib/SafeMath.sol"; -import "./lib/RLPEncode.sol"; -import "./lib/RLPDecode.sol"; -import "./System.sol"; +import "../interface/0.6.x/IBEP20.sol"; +import "../interface/0.6.x/ITokenHub.sol"; +import "../interface/0.6.x/IApplication.sol"; +import "../interface/0.6.x/ICrossChain.sol"; +import "../interface/0.6.x/IParamSubscriber.sol"; +import "../lib/0.6.x/SafeMath.sol"; +import "../lib/0.6.x/RLPEncode.sol"; +import "../lib/0.6.x/RLPDecode.sol"; +import "../System.sol"; contract TokenManager is System, IApplication, IParamSubscriber { using SafeMath for uint256; diff --git a/contracts/tool/BSCValidatorSetTool.sol b/contracts/extension/BSCValidatorSetTool.sol similarity index 98% rename from contracts/tool/BSCValidatorSetTool.sol rename to contracts/extension/BSCValidatorSetTool.sol index 12173b85..9341ee9d 100644 --- a/contracts/tool/BSCValidatorSetTool.sol +++ b/contracts/extension/BSCValidatorSetTool.sol @@ -1,7 +1,7 @@ pragma solidity 0.6.4; -import "../lib/RLPDecode.sol"; -import "../lib/Memory.sol"; +import "../lib/0.6.x/RLPDecode.sol"; +import "../lib/0.6.x/Memory.sol"; contract BSCValidatorSetTool { bytes public constant INIT_VALIDATORSET_BYTES = diff --git a/contracts/BC_fusion/extension/Protectable.sol b/contracts/extension/Protectable.sol similarity index 100% rename from contracts/BC_fusion/extension/Protectable.sol rename to contracts/extension/Protectable.sol diff --git a/contracts/interface/IApplication.sol b/contracts/interface/0.6.x/IApplication.sol similarity index 100% rename from contracts/interface/IApplication.sol rename to contracts/interface/0.6.x/IApplication.sol diff --git a/contracts/interface/IBEP20.sol b/contracts/interface/0.6.x/IBEP20.sol similarity index 100% rename from contracts/interface/IBEP20.sol rename to contracts/interface/0.6.x/IBEP20.sol diff --git a/contracts/interface/IBSCValidatorSet.sol b/contracts/interface/0.6.x/IBSCValidatorSet.sol similarity index 100% rename from contracts/interface/IBSCValidatorSet.sol rename to contracts/interface/0.6.x/IBSCValidatorSet.sol diff --git a/contracts/interface/IBSCValidatorSetV2.sol b/contracts/interface/0.6.x/IBSCValidatorSetV2.sol similarity index 100% rename from contracts/interface/IBSCValidatorSetV2.sol rename to contracts/interface/0.6.x/IBSCValidatorSetV2.sol diff --git a/contracts/interface/ICrossChain.sol b/contracts/interface/0.6.x/ICrossChain.sol similarity index 100% rename from contracts/interface/ICrossChain.sol rename to contracts/interface/0.6.x/ICrossChain.sol diff --git a/contracts/interface/ILightClient.sol b/contracts/interface/0.6.x/ILightClient.sol similarity index 100% rename from contracts/interface/ILightClient.sol rename to contracts/interface/0.6.x/ILightClient.sol diff --git a/contracts/interface/IParamSubscriber.sol b/contracts/interface/0.6.x/IParamSubscriber.sol similarity index 100% rename from contracts/interface/IParamSubscriber.sol rename to contracts/interface/0.6.x/IParamSubscriber.sol diff --git a/contracts/interface/IRelayerHub.sol b/contracts/interface/0.6.x/IRelayerHub.sol similarity index 100% rename from contracts/interface/IRelayerHub.sol rename to contracts/interface/0.6.x/IRelayerHub.sol diff --git a/contracts/interface/IRelayerIncentivize.sol b/contracts/interface/0.6.x/IRelayerIncentivize.sol similarity index 100% rename from contracts/interface/IRelayerIncentivize.sol rename to contracts/interface/0.6.x/IRelayerIncentivize.sol diff --git a/contracts/interface/ISlashIndicator.sol b/contracts/interface/0.6.x/ISlashIndicator.sol similarity index 100% rename from contracts/interface/ISlashIndicator.sol rename to contracts/interface/0.6.x/ISlashIndicator.sol diff --git a/contracts/interface/IStakeHub.sol b/contracts/interface/0.6.x/IStakeHub.sol similarity index 100% rename from contracts/interface/IStakeHub.sol rename to contracts/interface/0.6.x/IStakeHub.sol diff --git a/contracts/interface/IStaking.sol b/contracts/interface/0.6.x/IStaking.sol similarity index 100% rename from contracts/interface/IStaking.sol rename to contracts/interface/0.6.x/IStaking.sol diff --git a/contracts/interface/ISystemReward.sol b/contracts/interface/0.6.x/ISystemReward.sol similarity index 100% rename from contracts/interface/ISystemReward.sol rename to contracts/interface/0.6.x/ISystemReward.sol diff --git a/contracts/interface/ITokenHub.sol b/contracts/interface/0.6.x/ITokenHub.sol similarity index 100% rename from contracts/interface/ITokenHub.sol rename to contracts/interface/0.6.x/ITokenHub.sol diff --git a/contracts/BC_fusion/interface/IBSCValidatorSet.sol b/contracts/interface/0.8.x/IBSCValidatorSet.sol similarity index 100% rename from contracts/BC_fusion/interface/IBSCValidatorSet.sol rename to contracts/interface/0.8.x/IBSCValidatorSet.sol diff --git a/contracts/BC_fusion/interface/ICrossChain.sol b/contracts/interface/0.8.x/ICrossChain.sol similarity index 100% rename from contracts/BC_fusion/interface/ICrossChain.sol rename to contracts/interface/0.8.x/ICrossChain.sol diff --git a/contracts/BC_fusion/interface/IGovToken.sol b/contracts/interface/0.8.x/IGovToken.sol similarity index 100% rename from contracts/BC_fusion/interface/IGovToken.sol rename to contracts/interface/0.8.x/IGovToken.sol diff --git a/contracts/BC_fusion/interface/IStakeCredit.sol b/contracts/interface/0.8.x/IStakeCredit.sol similarity index 100% rename from contracts/BC_fusion/interface/IStakeCredit.sol rename to contracts/interface/0.8.x/IStakeCredit.sol diff --git a/contracts/BC_fusion/interface/IStakeHub.sol b/contracts/interface/0.8.x/IStakeHub.sol similarity index 100% rename from contracts/BC_fusion/interface/IStakeHub.sol rename to contracts/interface/0.8.x/IStakeHub.sol diff --git a/contracts/BC_fusion/interface/ITokenHub.sol b/contracts/interface/0.8.x/ITokenHub.sol similarity index 100% rename from contracts/BC_fusion/interface/ITokenHub.sol rename to contracts/interface/0.8.x/ITokenHub.sol diff --git a/contracts/BC_fusion/interface/ITokenRecoverPortal.sol b/contracts/interface/0.8.x/ITokenRecoverPortal.sol similarity index 100% rename from contracts/BC_fusion/interface/ITokenRecoverPortal.sol rename to contracts/interface/0.8.x/ITokenRecoverPortal.sol diff --git a/contracts/lib/BytesLib.sol b/contracts/lib/0.6.x/BytesLib.sol similarity index 100% rename from contracts/lib/BytesLib.sol rename to contracts/lib/0.6.x/BytesLib.sol diff --git a/contracts/lib/BytesToTypes.sol b/contracts/lib/0.6.x/BytesToTypes.sol similarity index 100% rename from contracts/lib/BytesToTypes.sol rename to contracts/lib/0.6.x/BytesToTypes.sol diff --git a/contracts/lib/CmnPkg.sol b/contracts/lib/0.6.x/CmnPkg.sol similarity index 100% rename from contracts/lib/CmnPkg.sol rename to contracts/lib/0.6.x/CmnPkg.sol diff --git a/contracts/bep20_template/LICENCE b/contracts/lib/0.6.x/LICENCE similarity index 100% rename from contracts/bep20_template/LICENCE rename to contracts/lib/0.6.x/LICENCE diff --git a/contracts/lib/Memory.sol b/contracts/lib/0.6.x/Memory.sol similarity index 100% rename from contracts/lib/Memory.sol rename to contracts/lib/0.6.x/Memory.sol diff --git a/contracts/MerkleProof.sol b/contracts/lib/0.6.x/MerkleProof.sol similarity index 98% rename from contracts/MerkleProof.sol rename to contracts/lib/0.6.x/MerkleProof.sol index 51bdd209..72a107f3 100644 --- a/contracts/MerkleProof.sol +++ b/contracts/lib/0.6.x/MerkleProof.sol @@ -1,6 +1,6 @@ pragma solidity 0.6.4; -import "./lib/Memory.sol"; +import "./Memory.sol"; library MerkleProof { function validateMerkleProof( diff --git a/contracts/lib/RLPDecode.sol b/contracts/lib/0.6.x/RLPDecode.sol similarity index 100% rename from contracts/lib/RLPDecode.sol rename to contracts/lib/0.6.x/RLPDecode.sol diff --git a/contracts/lib/RLPEncode.sol b/contracts/lib/0.6.x/RLPEncode.sol similarity index 100% rename from contracts/lib/RLPEncode.sol rename to contracts/lib/0.6.x/RLPEncode.sol diff --git a/contracts/lib/SafeMath.sol b/contracts/lib/0.6.x/SafeMath.sol similarity index 100% rename from contracts/lib/SafeMath.sol rename to contracts/lib/0.6.x/SafeMath.sol diff --git a/contracts/lib/SizeOf.sol b/contracts/lib/0.6.x/SizeOf.sol similarity index 100% rename from contracts/lib/SizeOf.sol rename to contracts/lib/0.6.x/SizeOf.sol diff --git a/contracts/lib/TypesToBytes.sol b/contracts/lib/0.6.x/TypesToBytes.sol similarity index 100% rename from contracts/lib/TypesToBytes.sol rename to contracts/lib/0.6.x/TypesToBytes.sol diff --git a/contracts/BC_fusion/lib/RLPDecode.sol b/contracts/lib/0.8.x/RLPDecode.sol similarity index 100% rename from contracts/BC_fusion/lib/RLPDecode.sol rename to contracts/lib/0.8.x/RLPDecode.sol diff --git a/contracts/BC_fusion/lib/Utils.sol b/contracts/lib/0.8.x/Utils.sol similarity index 100% rename from contracts/BC_fusion/lib/Utils.sol rename to contracts/lib/0.8.x/Utils.sol diff --git a/contracts/lib/LICENCE b/contracts/lib/LICENCE deleted file mode 100644 index 043e7ce8..00000000 --- a/contracts/lib/LICENCE +++ /dev/null @@ -1,22 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2016-2019 zOS Global Limited - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be included -in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/contracts/mock/MockTokenHub.sol b/contracts/mock/MockTokenHub.sol deleted file mode 100644 index 5754dccb..00000000 --- a/contracts/mock/MockTokenHub.sol +++ /dev/null @@ -1,66 +0,0 @@ -pragma solidity 0.6.4; - -import "../interface/ITokenHub.sol"; - -contract MockTokenHub is ITokenHub { - bool panicBatchTransferOut; - - bytes32 public constant BEP2_TOKEN_SYMBOL_FOR_BNB = - 0x424E420000000000000000000000000000000000000000000000000000000000; // "BNB" - - function getMiniRelayFee() external view override(ITokenHub) returns (uint256) { - return (1e16); - } - - function getContractAddrByBEP2Symbol(bytes32) external view override(ITokenHub) returns (address) { - return address(0x0); - } - - function getBep2SymbolByContractAddr(address) external view override(ITokenHub) returns (bytes32) { - return bytes32(0x0); - } - - function bindToken(bytes32 bep2Symbol, address contractAddr, uint256 decimals) external override(ITokenHub) { } - - function unbindToken(bytes32 bep2Symbol, address contractAddr) external override(ITokenHub) { } - - function recoverBCAsset(bytes32, address, uint256) external override(ITokenHub) { } - - function cancelTokenRecoverLock(bytes32, address) external override { - address TOKEN_RECOVER_PORTAL_ADDR = address(0x0000000000000000000000000000000000003000); - require(msg.sender == TOKEN_RECOVER_PORTAL_ADDR, "only token reover portal contract can call this function"); - } - - function transferOut(address, address, uint256, uint64) external payable override(ITokenHub) returns (bool) { - return true; - } - - /* solium-disable-next-line */ - function batchTransferOutBNB( - address[] calldata, - uint256[] calldata, - address[] calldata, - uint64 - ) external payable override(ITokenHub) returns (bool) { - require(!panicBatchTransferOut, "panic in batchTransferOut"); - return true; - } - - function setPanicBatchTransferOut(bool doPanic) external { - panicBatchTransferOut = doPanic; - } - - function withdrawStakingBNB(uint256 amount) external override returns (bool) { - address STAKING_CONTRACT_ADDR = address(0x0000000000000000000000000000000000002001); - require(msg.sender == STAKING_CONTRACT_ADDR, "only staking system contract can call this function"); - if (amount != 0) { - payable(STAKING_CONTRACT_ADDR).transfer(amount); - } - return true; - } - - function cancelTransferIn(address, address) external override { - address CROSS_CHAIN_CONTRACT_ADDR = address(0x0000000000000000000000000000000000002000); - require(msg.sender == CROSS_CHAIN_CONTRACT_ADDR, "only cross chain contract can call this function"); - } -} diff --git a/package.json b/package.json index a59595f0..deaac189 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,8 @@ "author": "", "license": "MIT", "scripts": { - "lint:check": "forge fmt ./contracts/BC_fusion --check", - "lint:write": "forge fmt ./contracts/BC_fusion", + "lint:check": "forge fmt ./contracts/BSCTimelock.sol ./contracts/GovToken.sol ./contracts/BSCGovernor.sol ./contracts/TokenRecoverPortal.sol ./contracts/StakeCredit.sol ./contracts/StakeHub.sol ./contracts/SystemV2.sol --check", + "lint:write": "forge fmt ./contracts/BSCTimelock.sol ./contracts/GovToken.sol ./contracts/BSCGovernor.sol ./contracts/TokenRecoverPortal.sol ./contracts/StakeCredit.sol ./contracts/StakeHub.sol ./contracts/SystemV2.sol ", "generate:mainnet": "poetry run python -m scripts.generate mainnet", "generate:testnet": "poetry run python -m scripts.generate testnet", "generate:dev": "poetry run python -m scripts.generate dev --epoch \"20\" --misdemeanor-threshold \"5\" --felony-threshold \"10\" --init-felony-slash-scope \"60\" --breathe-block-interval \"1 minutes\" --block-interval \"3 seconds\" --init-bc-consensus-addresses 'hex\"00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb9226600000000000000000000000070997970c51812dc3a010c7d01b50e0d17dc79c80000000000000000000000003c44cdddb6a900fa2b585dd299e03d12fa4293bc\"' --init-bc-vote-addresses 'hex\"00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000030b86b3146bdd2200b1dbdb1cea5e40d3451c028cbb4fb03b1826f7f2d82bee76bbd5cd68a74a16a7eceea093fd5826b9200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003087ce273bb9b51fd69e50de7a8d9a99cfb3b1a5c6a7b85f6673d137a5a2ce7df3d6ee4e6d579a142d58b0606c4a7a1c27000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000030a33ac14980d85c0d154c5909ebf7a11d455f54beb4d5d0dc1d8b3670b9c4a6b6c450ee3d623ecc48026f09ed1f0b5c1200000000000000000000000000000000\"' --stake-hub-protector \"0xdF87F0e2B8519Ea2DD4aBd8B639cdD628497eD25\" --unbond-period \"2 minutes\" --downtime-jail-time \"2 minutes\" --felony-jail-time \"3 minutes\" --init-voting-delay \"1 minutes / BLOCK_INTERVAL\" --init-voting-period \"2 minutes / BLOCK_INTERVAL\" --init-min-period-after-quorum \"uint64(1 minutes / BLOCK_INTERVAL)\" --governor-protector \"0xdF87F0e2B8519Ea2DD4aBd8B639cdD628497eD25\" --init-minimal-delay \"1 minutes\" --lock-period-for-token-recover \"1 minutes\"" diff --git a/scripts/generate.py b/scripts/generate.py index 0ea738d7..aab5f8c6 100644 --- a/scripts/generate.py +++ b/scripts/generate.py @@ -93,7 +93,7 @@ def generate_from_template(data, template_file, output_file): def generate_cross_chain(init_batch_size="50"): - contract = "CrossChain.sol" + contract = "deprecated/CrossChain.sol" backup_file( os.path.join(work_dir, "contracts", contract), os.path.join(work_dir, "contracts", contract[:-4] + ".bak") ) @@ -103,7 +103,7 @@ def generate_cross_chain(init_batch_size="50"): def generate_relayer_hub(whitelist_1, whitelist_2): - contract = "RelayerHub.sol" + contract = "deprecated/RelayerHub.sol" backup_file( os.path.join(work_dir, "contracts", contract), os.path.join(work_dir, "contracts", contract[:-4] + ".bak") ) @@ -134,7 +134,7 @@ def generate_stake_hub( breathe_block_interval, init_bc_consensus_addresses, init_bc_vote_addresses, max_elected_validators, unbond_period, downtime_jail_time, felony_jail_time, stake_hub_protector ): - contract = "BC_fusion/StakeHub.sol" + contract = "StakeHub.sol" backup_file( os.path.join(work_dir, "contracts", contract), os.path.join(work_dir, "contracts", contract[:-4] + ".bak") ) @@ -154,7 +154,7 @@ def generate_governor( block_interval, init_voting_delay, init_voting_period, init_proposal_threshold, init_quorum_numerator, propose_start_threshold, init_min_period_after_quorum, governor_protector ): - contract = "BC_fusion/BSCGovernor.sol" + contract = "BSCGovernor.sol" backup_file( os.path.join(work_dir, "contracts", contract), os.path.join(work_dir, "contracts", contract[:-4] + ".bak") ) @@ -174,7 +174,7 @@ def generate_governor( def generate_timelock(init_minimal_delay): - contract = "BC_fusion/BSCTimelock.sol" + contract = "BSCTimelock.sol" backup_file( os.path.join(work_dir, "contracts", contract), os.path.join(work_dir, "contracts", contract[:-4] + ".bak") ) @@ -204,7 +204,7 @@ def generate_system_reward(): def generate_tendermint_light_client(init_consensus_state_bytes, init_reward_for_validator_ser_change="1e16"): - contract = "TendermintLightClient.sol" + contract = "deprecated/TendermintLightClient.sol" backup_file( os.path.join(work_dir, "contracts", contract), os.path.join(work_dir, "contracts", contract[:-4] + ".bak") ) @@ -230,7 +230,7 @@ def generate_token_hub(lock_period_for_token_recover): def generate_token_recover_portal(source_chain_id, token_recover_portal_protector): - contract = "BC_fusion/TokenRecoverPortal.sol" + contract = "TokenRecoverPortal.sol" backup_file( os.path.join(work_dir, "contracts", contract), os.path.join(work_dir, "contracts", contract[:-4] + ".bak") ) @@ -515,7 +515,7 @@ def recover(): shutil.copyfile(os.path.join(contracts_dir, file), os.path.join(contracts_dir, c_file)) os.remove(os.path.join(contracts_dir, file)) - contracts_dir = os.path.join(contracts_dir, "BC_fusion") + contracts_dir = os.path.join(contracts_dir, "deprecated") for file in os.listdir(contracts_dir): if file.endswith(".bak"): c_file = file[:-4] + ".sol" @@ -573,7 +573,7 @@ def generate_validators( @main.command(help="Generate errors signature") -def generate_error_sig(dir_path: str = "./contracts/BC_fusion"): +def generate_error_sig(dir_path: str = "./contracts"): dir_path = os.path.join(work_dir, dir_path) annotation_prefix = " // @notice signature: " diff --git a/test/Governor.t.sol b/test/Governor.t.sol index 10f70e1c..8878a51e 100644 --- a/test/Governor.t.sol +++ b/test/Governor.t.sol @@ -94,7 +94,7 @@ contract GovernorTest is Deployer { "updateParam(string,bytes,address)", "votingDelay", abi.encodePacked(newVotingDelay), GOVERNOR_ADDR ); -// assertEq(governor.proposeStarted(), true, "propose should not start"); + // assertEq(governor.proposeStarted(), true, "propose should not start"); // mainnet totalSupply is already enough // // govBNB totalSupply not enough diff --git a/test/SlashIndicator.t.sol b/test/SlashIndicator.t.sol index 5d056061..3ebdcf74 100644 --- a/test/SlashIndicator.t.sol +++ b/test/SlashIndicator.t.sol @@ -139,10 +139,10 @@ contract SlashIndicatorTest is Deployer { vm.prank(validatorLast); // can not avoid downtime slash by reducing gasLimit vm.expectRevert(); - bscValidatorSet.exitMaintenance{gas: 550000 }(); + bscValidatorSet.exitMaintenance{ gas: 550000 }(); vm.prank(validatorLast); - bscValidatorSet.exitMaintenance{gas: 1000000 }(); + bscValidatorSet.exitMaintenance{ gas: 1000000 }(); } function testMaintenanceFix2() public { @@ -150,7 +150,7 @@ contract SlashIndicatorTest is Deployer { uint256 numOfMaintainingBefore = bscValidatorSet.numOfMaintaining(); assert(bscValidatorSet.isCurrentValidator(validatorLast)); - (uint256 misdemeanorThreshold, ) = slashIndicator.getSlashThresholds(); + (uint256 misdemeanorThreshold,) = slashIndicator.getSlashThresholds(); (, uint256 countBefore) = slashIndicator.getSlashIndicator(validatorLast); uint256 height = block.number; diff --git a/test/StakeHub.t.sol b/test/StakeHub.t.sol index 92d42b43..79c08d7e 100644 --- a/test/StakeHub.t.sol +++ b/test/StakeHub.t.sol @@ -786,7 +786,7 @@ contract StakeHubTest is Deployer { // edit vote address vm.warp(block.timestamp + 1 days); bytes memory newVoteAddress = - hex"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001234"; + hex"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001234"; bytes memory blsProof = new bytes(96); vm.expectEmit(true, false, false, true, address(stakeHub)); emit VoteAddressEdited(validator, newVoteAddress);