├── .gitignore ├── README.md ├── contracts ├── Migrations.sol ├── Timelock.sol ├── protocol │ ├── Cash.sol │ ├── CheckToken.sol │ ├── DAOTreasury.sol │ ├── DevShare.sol │ ├── ForkToken.sol │ ├── IDFO.sol │ ├── LPLock.sol │ ├── apis │ │ └── uniswap │ │ │ ├── IUniswapV2Router02.sol │ │ │ ├── README │ │ │ ├── UniswapV2Library.sol │ │ │ └── UniswapV2Router02.sol │ ├── interfaces │ │ ├── IFairLaunch.sol │ │ ├── IForkFarmLaunch.sol │ │ └── IWETH.sol │ └── mock │ │ ├── MockDai.sol │ │ ├── MockERC20.sol │ │ └── MockWBNB.sol └── utils │ └── SafeToken.sol ├── migrations ├── 01_initial_migration.js ├── 02_pancakeswap_initial.js ├── 03_deploy_pancakeswap.js ├── 04_deploy_token.js ├── 09_deploy_timelock.js ├── 11_deploy_farm.js ├── 12_add_pool_to_farm.js ├── 13_seed_check_liquidity.js ├── 15_add_cash_pool.js ├── 16_transfer_check_ownership_chef.js ├── 99_generate_deployment.js ├── conf.js ├── known-contracts.js └── s_deploy_fork.js ├── package.json ├── scripts └── sedding_on_fork_wbnb_lp.js ├── test ├── .gitkeep ├── DAO.test.js ├── fairLaunch.test.js ├── forkFarm.test.js ├── forkFarmLaunch.test.js ├── ibnb_and_ibusd.test.js ├── pancake.test.js └── utils │ └── time.js ├── truffle-config.js └── verify.sh /.gitignore: -------------------------------------------------------------------------------- 1 | logs/ 2 | npm-debug.log 3 | yarn-error.log 4 | node_modules/ 5 | package-lock.json 6 | yarn.lock 7 | .idea/ 8 | run/ 9 | .DS_Store 10 | *.sw* 11 | *.un~ 12 | typings/ 13 | .nyc_output/ 14 | build/ 15 | file/ 16 | .secret 17 | script/ 18 | contracts/test 19 | document 20 | design 21 | env.json -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Fork Contract 2 | 3 | **A defi factory on Binance Smart Chain that produces defi-project in a yield farming way** 4 | 5 | ## Usage 6 | 7 | ``` 8 | yarn 9 | ``` 10 | 11 | ## License 12 | 13 | [MIT License](https://opensource.org/licenses/MIT) -------------------------------------------------------------------------------- /contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require( 10 | msg.sender == owner, 11 | "This function is restricted to the contract's owner" 12 | ); 13 | _; 14 | } 15 | 16 | function setCompleted(uint completed) public restricted { 17 | last_completed_migration = completed; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /contracts/Timelock.sol: -------------------------------------------------------------------------------- 1 | // COPIED FROM https://github.com/compound-finance/compound-protocol/blob/master/contracts/Governance/GovernorAlpha.sol 2 | // Copyright 2020 Compound Labs, Inc. 3 | // Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 4 | // 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 5 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 6 | // 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 7 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 8 | // 9 | // Ctrl+f for XXX to see all the modifications. 10 | 11 | // XXX: pragma solidity ^0.5.16; 12 | pragma solidity 0.6.6; 13 | 14 | import "@openzeppelin/contracts/math/SafeMath.sol"; 15 | 16 | contract Timelock { 17 | using SafeMath for uint; 18 | 19 | event NewAdmin(address indexed newAdmin); 20 | event NewPendingAdmin(address indexed newPendingAdmin); 21 | event NewDelay(uint indexed newDelay); 22 | event CancelTransaction(bytes32 indexed txHash, address indexed target, uint value, string signature, bytes data, uint eta); 23 | event ExecuteTransaction(bytes32 indexed txHash, address indexed target, uint value, string signature, bytes data, uint eta); 24 | event QueueTransaction(bytes32 indexed txHash, address indexed target, uint value, string signature, bytes data, uint eta); 25 | 26 | uint public constant GRACE_PERIOD = 14 days; 27 | uint public constant MINIMUM_DELAY = 1 days; 28 | uint public constant MAXIMUM_DELAY = 30 days; 29 | 30 | address public admin; 31 | address public pendingAdmin; 32 | uint public delay; 33 | bool public admin_initialized; 34 | 35 | mapping (bytes32 => bool) public queuedTransactions; 36 | 37 | // delay_ in seconds 38 | constructor(address admin_, uint delay_) public { 39 | require(delay_ >= MINIMUM_DELAY, "Timelock::constructor: Delay must exceed minimum delay."); 40 | require(delay_ <= MAXIMUM_DELAY, "Timelock::constructor: Delay must not exceed maximum delay."); 41 | 42 | admin = admin_; 43 | delay = delay_; 44 | admin_initialized = false; 45 | } 46 | 47 | // XXX: function() external payable { } 48 | receive() external payable { } 49 | 50 | function setDelay(uint delay_) public { 51 | require(msg.sender == address(this), "Timelock::setDelay: Call must come from Timelock."); 52 | require(delay_ >= MINIMUM_DELAY, "Timelock::setDelay: Delay must exceed minimum delay."); 53 | require(delay_ <= MAXIMUM_DELAY, "Timelock::setDelay: Delay must not exceed maximum delay."); 54 | delay = delay_; 55 | 56 | emit NewDelay(delay); 57 | } 58 | 59 | function acceptAdmin() public { 60 | require(msg.sender == pendingAdmin, "Timelock::acceptAdmin: Call must come from pendingAdmin."); 61 | admin = msg.sender; 62 | pendingAdmin = address(0); 63 | 64 | emit NewAdmin(admin); 65 | } 66 | 67 | function setPendingAdmin(address pendingAdmin_) public { 68 | // allows one time setting of admin for deployment purposes 69 | if (admin_initialized) { 70 | require(msg.sender == address(this), "Timelock::setPendingAdmin: Call must come from Timelock."); 71 | } else { 72 | require(msg.sender == admin, "Timelock::setPendingAdmin: First call must come from admin."); 73 | admin_initialized = true; 74 | } 75 | pendingAdmin = pendingAdmin_; 76 | 77 | emit NewPendingAdmin(pendingAdmin); 78 | } 79 | 80 | function queueTransaction(address target, uint value, string memory signature, bytes memory data, uint eta) public returns (bytes32) { 81 | require(msg.sender == admin, "Timelock::queueTransaction: Call must come from admin."); 82 | require(eta >= getBlockTimestamp().add(delay), "Timelock::queueTransaction: Estimated execution block must satisfy delay."); 83 | 84 | bytes32 txHash = keccak256(abi.encode(target, value, signature, data, eta)); 85 | queuedTransactions[txHash] = true; 86 | 87 | emit QueueTransaction(txHash, target, value, signature, data, eta); 88 | return txHash; 89 | } 90 | 91 | function cancelTransaction(address target, uint value, string memory signature, bytes memory data, uint eta) public { 92 | require(msg.sender == admin, "Timelock::cancelTransaction: Call must come from admin."); 93 | 94 | bytes32 txHash = keccak256(abi.encode(target, value, signature, data, eta)); 95 | queuedTransactions[txHash] = false; 96 | 97 | emit CancelTransaction(txHash, target, value, signature, data, eta); 98 | } 99 | 100 | function _getRevertMsg(bytes memory _returnData) internal pure returns (string memory) { 101 | // If the _res length is less than 68, then the transaction failed silently (without a revert message) 102 | if (_returnData.length < 68) return "Transaction reverted silently"; 103 | 104 | assembly { 105 | // Slice the sighash. 106 | _returnData := add(_returnData, 0x04) 107 | } 108 | return abi.decode(_returnData, (string)); // All that remains is the revert string 109 | } 110 | 111 | function executeTransaction( 112 | address target, 113 | uint value, 114 | string memory signature, 115 | bytes memory data, 116 | uint eta 117 | ) public payable returns (bytes memory) { 118 | require(msg.sender == admin, "Timelock::executeTransaction: Call must come from admin."); 119 | 120 | bytes32 txHash = keccak256(abi.encode(target, value, signature, data, eta)); 121 | require(queuedTransactions[txHash], "Timelock::executeTransaction: Transaction hasn't been queued."); 122 | require(getBlockTimestamp() >= eta, "Timelock::executeTransaction: Transaction hasn't surpassed time lock."); 123 | require(getBlockTimestamp() <= eta.add(GRACE_PERIOD), "Timelock::executeTransaction: Transaction is stale."); 124 | 125 | queuedTransactions[txHash] = false; 126 | 127 | bytes memory callData; 128 | 129 | if (bytes(signature).length == 0) { 130 | callData = data; 131 | } else { 132 | callData = abi.encodePacked(bytes4(keccak256(bytes(signature))), data); 133 | } 134 | 135 | // solium-disable-next-line security/no-call-value 136 | (bool success, bytes memory returnData) = target.call{value: value}(callData); 137 | require(success, _getRevertMsg(returnData)); 138 | 139 | emit ExecuteTransaction(txHash, target, value, signature, data, eta); 140 | 141 | return returnData; 142 | } 143 | 144 | function getBlockTimestamp() internal view returns (uint) { 145 | // solium-disable-next-line security/no-block-members 146 | return block.timestamp; 147 | } 148 | } -------------------------------------------------------------------------------- /contracts/protocol/Cash.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.6.6; 2 | 3 | import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; 4 | import "@openzeppelin/contracts/access/Ownable.sol"; 5 | import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; 6 | 7 | 8 | contract Cash is Ownable { 9 | using SafeMath for uint256; 10 | using SafeERC20 for IERC20; 11 | 12 | // Info of cash-pool 13 | struct CashPoolInfo { 14 | uint256 cashTotal; 15 | address cashToken; 16 | address stakeToken; 17 | uint256 stakeTotal; 18 | uint256 stakeMax; 19 | // uint256 stakeMin; 20 | uint256 startTime; 21 | uint256 endTime; 22 | bool isLimit; 23 | uint256 projectId; 24 | } 25 | 26 | struct CashUserInfo { 27 | uint256 total; 28 | uint256 amount; 29 | uint256 burn; 30 | } 31 | // Info of each pool. 32 | CashPoolInfo[] public cashPoolInfo; 33 | // Info of each user that stakes Staking tokens. 34 | mapping(uint256 => mapping(address => CashUserInfo)) public cashUserInfo; 35 | 36 | address public constant burnAddress = 0x000000000000000000000000000000000000dEaD; 37 | 38 | event DepositCheckToCashPool(address indexed user, uint256 indexed pid, uint256 amount); 39 | event CashedCheck(address indexed user, uint256 indexed pid, uint256 amount, uint256 pending); 40 | 41 | function addCashPool( 42 | uint256 _cashTotal, 43 | address _cashToken, 44 | address _stakeToken, 45 | uint256 _stakeMax, 46 | // uint256 _stakeMin, 47 | uint256 _startTime, 48 | uint256 _endTime, 49 | bool _isLimit, 50 | uint256 _projectId 51 | ) public onlyOwner { 52 | require(_cashToken != address(0), "add: not cashToken addr"); 53 | require(_endTime > _startTime, "endTime < startTime"); 54 | cashPoolInfo.push( 55 | CashPoolInfo({ 56 | cashTotal: _cashTotal, 57 | cashToken: _cashToken, 58 | stakeToken: _stakeToken, 59 | startTime: _startTime, 60 | endTime: _endTime, 61 | projectId: _projectId, 62 | stakeTotal: 0, 63 | stakeMax: _stakeMax, 64 | // stakeMin: _stakeMin, 65 | isLimit: _isLimit 66 | }) 67 | ); 68 | } 69 | 70 | function cashPoolLength() external view returns (uint256) { 71 | return cashPoolInfo.length; 72 | } 73 | // Deposit CHECK-TOKEN to CashPool for FPT allocation. 74 | function depositCheckToCashPool(uint256 _pid, uint256 _amount) public { 75 | CashPoolInfo storage pool = cashPoolInfo[_pid]; 76 | CashUserInfo storage user = cashUserInfo[_pid][msg.sender]; 77 | require(block.timestamp >= pool.startTime && block.timestamp <= pool.endTime, "The cash-out activity did not start"); 78 | if (pool.isLimit) { 79 | require(pool.stakeTotal.add(_amount) <= pool.stakeMax, "must less than stakeMax"); 80 | } 81 | IERC20(pool.stakeToken).safeTransferFrom(address(msg.sender), address(this), _amount); 82 | user.amount = user.amount.add(_amount); 83 | user.total = user.total.add(_amount); 84 | pool.stakeTotal = pool.stakeTotal.add(_amount); 85 | emit DepositCheckToCashPool(msg.sender, _pid, _amount); 86 | } 87 | 88 | function cashCheck(uint256 _pid) public { 89 | CashPoolInfo storage pool = cashPoolInfo[_pid]; 90 | CashUserInfo storage user = cashUserInfo[_pid][msg.sender]; 91 | require(block.timestamp > pool.endTime, "The cash-out activity did not start"); 92 | if (pool.isLimit) { 93 | // require(pool.stakeTotal >= pool.stakeMin, "must more than stakeMin"); 94 | } 95 | require(user.amount > 0, "nothing to cash"); 96 | uint256 pending = pool.cashTotal.mul(user.amount).div(pool.stakeTotal); 97 | IERC20 cashToken = IERC20(pool.cashToken); 98 | IERC20 stakeToken = IERC20(pool.stakeToken); 99 | require(pending <= cashToken.balanceOf(address(this)), "wtf not enough cashToken"); 100 | require(user.amount <= stakeToken.balanceOf(address(this)), "wtf not enough stakeToken-token to burn"); 101 | // stakeToken.burn(address(this), user.amount); 102 | uint256 amount = user.amount; 103 | user.burn = user.amount; 104 | user.amount = 0; 105 | stakeToken.safeTransfer(burnAddress, amount); 106 | cashToken.safeTransfer(address(msg.sender), pending); 107 | emit CashedCheck(msg.sender, _pid, amount, pending); 108 | 109 | } 110 | 111 | function pendingClaim(uint256 _pid, address _user) public view returns(uint256) { 112 | CashPoolInfo storage pool = cashPoolInfo[_pid]; 113 | CashUserInfo storage user = cashUserInfo[_pid][_user]; 114 | if (pool.stakeTotal == 0) return 0; 115 | if (block.timestamp < pool.endTime) return 0; 116 | uint256 pending = pool.cashTotal.mul(user.amount).div(pool.stakeTotal); 117 | return pending; 118 | } 119 | function mayClaim(uint256 _pid, address _user) public view returns(uint256) { 120 | CashPoolInfo storage pool = cashPoolInfo[_pid]; 121 | CashUserInfo storage user = cashUserInfo[_pid][_user]; 122 | if (pool.stakeTotal == 0) return 0; 123 | uint256 pending = pool.cashTotal.mul(user.amount).div(pool.stakeTotal); 124 | return pending; 125 | } 126 | } -------------------------------------------------------------------------------- /contracts/protocol/CheckToken.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.6.6; 2 | 3 | import "@openzeppelin/contracts/access/Ownable.sol"; 4 | import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; 5 | import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; 6 | 7 | // CheckToken 8 | contract CheckToken is ERC20("Check Token", "CHECK"), Ownable { 9 | uint256 private _totalLock; 10 | 11 | uint256 public startReleaseBlock; 12 | uint256 public endReleaseBlock; 13 | 14 | mapping(address => uint256) private _locks; 15 | mapping(address => uint256) private _lastUnlockBlock; 16 | 17 | event Lock(address indexed to, uint256 value); 18 | 19 | constructor(uint256 _startReleaseBlock, uint256 _endReleaseBlock) public { 20 | require(_endReleaseBlock > _startReleaseBlock, "endReleaseBlock < startReleaseBlock"); 21 | _setupDecimals(18); 22 | // maunalMint 50k for seeding liquidity 23 | mint(msg.sender, 50000e18); 24 | startReleaseBlock = _startReleaseBlock; 25 | endReleaseBlock = _endReleaseBlock; 26 | } 27 | 28 | function setReleaseBlock(uint256 _startReleaseBlock, uint256 _endReleaseBlock) public onlyOwner { 29 | require(_endReleaseBlock > _startReleaseBlock, "endReleaseBlock < startReleaseBlock"); 30 | startReleaseBlock = _startReleaseBlock; 31 | endReleaseBlock = _endReleaseBlock; 32 | } 33 | 34 | function unlockedSupply() public view returns (uint256) { 35 | return totalSupply().sub(totalLock()); 36 | } 37 | 38 | function totalLock() public view returns (uint256) { 39 | return _totalLock; 40 | } 41 | 42 | function mint(address _to, uint256 _amount) public onlyOwner { 43 | _mint(_to, _amount); 44 | } 45 | 46 | function burn(address _account, uint256 _amount) public onlyOwner { 47 | _burn(_account, _amount); 48 | } 49 | 50 | function totalBalanceOf(address _account) public view returns (uint256) { 51 | return _locks[_account].add(balanceOf(_account)); 52 | } 53 | 54 | function lockOf(address _account) public view returns (uint256) { 55 | return _locks[_account]; 56 | } 57 | 58 | function lastUnlockBlock(address _account) public view returns (uint256) { 59 | return _lastUnlockBlock[_account]; 60 | } 61 | 62 | function lock(address _account, uint256 _amount) public onlyOwner { 63 | require(_account != address(0), "no lock to address(0)"); 64 | require(_amount <= balanceOf(_account), "no lock over balance"); 65 | 66 | _transfer(_account, address(this), _amount); 67 | 68 | _locks[_account] = _locks[_account].add(_amount); 69 | _totalLock = _totalLock.add(_amount); 70 | 71 | if (_lastUnlockBlock[_account] < startReleaseBlock) { 72 | _lastUnlockBlock[_account] = startReleaseBlock; 73 | } 74 | 75 | emit Lock(_account, _amount); 76 | } 77 | 78 | function canUnlockAmount(address _account) public view returns (uint256) { 79 | // When block number less than startReleaseBlock, no FORKs can be unlocked 80 | if (block.number < startReleaseBlock) { 81 | return 0; 82 | } 83 | // When block number more than endReleaseBlock, all locked FORKs can be unlocked 84 | else if (block.number >= endReleaseBlock) { 85 | return _locks[_account]; 86 | } 87 | // When block number is more than startReleaseBlock but less than endReleaseBlock, 88 | // some FORKs can be released 89 | else 90 | { 91 | uint256 releasedBlock = block.number.sub(_lastUnlockBlock[_account]); 92 | uint256 blockLeft = endReleaseBlock.sub(_lastUnlockBlock[_account]); 93 | return _locks[_account].mul(releasedBlock).div(blockLeft); 94 | } 95 | } 96 | 97 | function unlock() public { 98 | require(_locks[msg.sender] > 0, "no locked FORKs"); 99 | 100 | uint256 amount = canUnlockAmount(msg.sender); 101 | 102 | _transfer(address(this), msg.sender, amount); 103 | _locks[msg.sender] = _locks[msg.sender].sub(amount); 104 | _lastUnlockBlock[msg.sender] = block.number; 105 | _totalLock = _totalLock.sub(amount); 106 | } 107 | 108 | // @dev move CHECKs with its locked funds and balance to another account 109 | function transferAll(address _to) public { 110 | _locks[_to] = _locks[_to].add(_locks[msg.sender]); 111 | 112 | if (_lastUnlockBlock[_to] < startReleaseBlock) { 113 | _lastUnlockBlock[_to] = startReleaseBlock; 114 | } 115 | 116 | if (_lastUnlockBlock[_to] < _lastUnlockBlock[msg.sender]) { 117 | _lastUnlockBlock[_to] = _lastUnlockBlock[msg.sender]; 118 | } 119 | 120 | _locks[msg.sender] = 0; 121 | _lastUnlockBlock[msg.sender] = 0; 122 | 123 | _transfer(msg.sender, _to, balanceOf(msg.sender)); 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /contracts/protocol/DAOTreasury.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.6.6; 2 | 3 | import "@openzeppelin/contracts/access/Ownable.sol"; 4 | import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; 5 | import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; 6 | 7 | contract DAOTreasury is Ownable { 8 | using SafeMath for uint256; 9 | using SafeERC20 for IERC20; 10 | 11 | string public constant name = "Fork Finance DAO Treasury"; 12 | 13 | IERC20 public fork; 14 | 15 | constructor(address _fork) public { 16 | fork = IERC20(_fork); 17 | } 18 | 19 | function transferForkTo( 20 | address _to, 21 | uint256 _amount 22 | ) public onlyOwner { 23 | fork.safeTransfer(_to, _amount); 24 | } 25 | 26 | function transferAnyTo( 27 | address _token, 28 | address _to, 29 | uint256 _amount 30 | ) public onlyOwner { 31 | IERC20(_token).safeTransfer(_to, _amount); 32 | } 33 | } -------------------------------------------------------------------------------- /contracts/protocol/DevShare.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.6.6; 2 | 3 | import "@openzeppelin/contracts/access/Ownable.sol"; 4 | import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; 5 | import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; 6 | 7 | contract DevShare is Ownable { 8 | using SafeMath for uint256; 9 | using SafeERC20 for IERC20; 10 | 11 | string public constant name = "Fork Finance Dev Share"; 12 | 13 | IERC20 public fork; 14 | 15 | uint256 public startReleaseBlock; 16 | uint256 public endReleaseBlock; 17 | uint256 public lastUnlockBlock; 18 | 19 | constructor(address _fork, uint256 _startReleaseBlock, uint256 _endReleaseBlock) public { 20 | require(_endReleaseBlock > _startReleaseBlock, "endReleaseBlock < startReleaseBlock"); 21 | fork = IERC20(_fork); 22 | startReleaseBlock = _startReleaseBlock; 23 | endReleaseBlock = _endReleaseBlock; 24 | lastUnlockBlock = _startReleaseBlock; 25 | } 26 | 27 | function canUnlockAmount() public view returns (uint256) { 28 | uint256 bal = fork.balanceOf(address(this)); 29 | // When block number less than startReleaseBlock, no FORKs can be unlocked 30 | if (block.number < startReleaseBlock) { 31 | return 0; 32 | } 33 | // When block number more than endReleaseBlock, all locked FORKs can be unlocked 34 | else if (block.number >= endReleaseBlock) { 35 | return bal; 36 | } 37 | // When block number is more than startReleaseBlock but less than endReleaseBlock, 38 | // some FORKs can be released 39 | else 40 | { 41 | uint256 releasedBlock = block.number.sub(lastUnlockBlock); 42 | uint256 blockLeft = endReleaseBlock.sub(lastUnlockBlock); 43 | return bal.mul(releasedBlock).div(blockLeft); 44 | } 45 | } 46 | 47 | function unlock(address _to) public onlyOwner { 48 | uint256 bal = fork.balanceOf(address(this)); 49 | require(bal > 0, "no locked FORKs"); 50 | 51 | uint256 amount = canUnlockAmount(); 52 | require(bal >= amount, "wtf not enough fork"); 53 | 54 | fork.safeTransfer(_to, amount); 55 | lastUnlockBlock = block.number; 56 | } 57 | } -------------------------------------------------------------------------------- /contracts/protocol/ForkToken.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.6.6; 2 | 3 | import "@openzeppelin/contracts/access/Ownable.sol"; 4 | import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; 5 | import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; 6 | 7 | // ForkToken with Governance. 8 | contract ForkToken is ERC20("ForkToken", "FORK"), Ownable { 9 | uint256 private constant _cap = 18800000e18; 10 | uint256 private _totalLock; 11 | 12 | uint256 public constant manualMintLimit = 800000e18; 13 | uint256 public manualMinted = 0; 14 | 15 | constructor() public { 16 | _setupDecimals(18); 17 | } 18 | 19 | function cap() public view returns (uint256) { 20 | return _cap; 21 | } 22 | 23 | function manualMint(address _to, uint256 _amount) public onlyOwner { 24 | require(manualMinted <= manualMintLimit, "mint limit exceeded"); 25 | manualMinted.add(_amount); 26 | mint(_to, _amount); 27 | _moveDelegates(address(0), _delegates[_to], _amount); 28 | } 29 | 30 | function mint(address _to, uint256 _amount) public onlyOwner { 31 | require(totalSupply().add(_amount) <= cap(), "cap exceeded"); 32 | _mint(_to, _amount); 33 | _moveDelegates(address(0), _delegates[_to], _amount); 34 | } 35 | 36 | function burn(address _account, uint256 _amount) public onlyOwner { 37 | _burn(_account, _amount); 38 | _moveDelegates(_delegates[_account], address(0), _amount); 39 | } 40 | 41 | function transfer(address recipient, uint256 amount) public virtual override returns (bool) { 42 | _transfer(_msgSender(), recipient, amount); 43 | _moveDelegates(_delegates[msg.sender], _delegates[recipient], amount); 44 | return true; 45 | } 46 | 47 | function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { 48 | _transfer(sender, recipient, amount); 49 | _approve(sender, _msgSender(), allowance(sender, _msgSender()).sub(amount, "ERC20: transfer amount exceeds allowance")); 50 | _moveDelegates(_delegates[sender], _delegates[recipient], amount); 51 | return true; 52 | } 53 | 54 | // Copied and modified from YAM code: 55 | // https://github.com/yam-finance/yam-protocol/blob/master/contracts/token/YAMGovernanceStorage.sol 56 | // https://github.com/yam-finance/yam-protocol/blob/master/contracts/token/YAMGovernance.sol 57 | // Which is copied and modified from COMPOUND: 58 | // https://github.com/compound-finance/compound-protocol/blob/master/contracts/Governance/Comp.sol 59 | 60 | /// @notice A record of each accounts delegate 61 | mapping(address => address) internal _delegates; 62 | 63 | /// @notice A checkpoint for marking number of votes from a given block 64 | struct Checkpoint { 65 | uint32 fromBlock; 66 | uint256 votes; 67 | } 68 | 69 | /// @notice A record of votes checkpoints for each account, by index 70 | mapping(address => mapping(uint32 => Checkpoint)) public checkpoints; 71 | 72 | /// @notice The number of checkpoints for each account 73 | mapping(address => uint32) public numCheckpoints; 74 | 75 | /// @notice The EIP-712 typehash for the contract's domain 76 | bytes32 public constant DOMAIN_TYPEHASH = keccak256( 77 | "EIP712Domain(string name,uint256 chainId,address verifyingContract)" 78 | ); 79 | 80 | /// @notice The EIP-712 typehash for the delegation struct used by the contract 81 | bytes32 public constant DELEGATION_TYPEHASH = keccak256( 82 | "Delegation(address delegatee,uint256 nonce,uint256 expiry)" 83 | ); 84 | 85 | /// @notice A record of states for signing / validating signatures 86 | mapping(address => uint256) public nonces; 87 | 88 | /// @notice An event thats emitted when an account changes its delegate 89 | event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate); 90 | 91 | /// @notice An event thats emitted when a delegate account's vote balance changes 92 | event DelegateVotesChanged(address indexed delegate, uint256 previousBalance, uint256 newBalance); 93 | 94 | /** 95 | * @notice Delegate votes from `msg.sender` to `delegatee` 96 | * @param delegator The address to get delegatee for 97 | */ 98 | function delegates(address delegator) external view returns (address) { 99 | return _delegates[delegator]; 100 | } 101 | 102 | /** 103 | * @notice Delegate votes from `msg.sender` to `delegatee` 104 | * @param delegatee The address to delegate votes to 105 | */ 106 | function delegate(address delegatee) external { 107 | return _delegate(msg.sender, delegatee); 108 | } 109 | 110 | /** 111 | * @notice Delegates votes from signatory to `delegatee` 112 | * @param delegatee The address to delegate votes to 113 | * @param nonce The contract state required to match the signature 114 | * @param expiry The time at which to expire the signature 115 | * @param v The recovery byte of the signature 116 | * @param r Half of the ECDSA signature pair 117 | * @param s Half of the ECDSA signature pair 118 | */ 119 | function delegateBySig( 120 | address delegatee, 121 | uint256 nonce, 122 | uint256 expiry, 123 | uint8 v, 124 | bytes32 r, 125 | bytes32 s 126 | ) external { 127 | bytes32 domainSeparator = keccak256( 128 | abi.encode(DOMAIN_TYPEHASH, keccak256(bytes(name())), getChainId(), address(this)) 129 | ); 130 | 131 | bytes32 structHash = keccak256(abi.encode(DELEGATION_TYPEHASH, delegatee, nonce, expiry)); 132 | 133 | bytes32 digest = keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash)); 134 | 135 | address signatory = ecrecover(digest, v, r, s); 136 | require(signatory != address(0), "FORK::delegateBySig: invalid signature"); 137 | require(nonce == nonces[signatory]++, "FORK::delegateBySig: invalid nonce"); 138 | require(now <= expiry, "FORK::delegateBySig: signature expired"); 139 | return _delegate(signatory, delegatee); 140 | } 141 | 142 | /** 143 | * @notice Gets the current votes balance for `account` 144 | * @param account The address to get votes balance 145 | * @return The number of current votes for `account` 146 | */ 147 | function getCurrentVotes(address account) external view returns (uint256) { 148 | uint32 nCheckpoints = numCheckpoints[account]; 149 | return nCheckpoints > 0 ? checkpoints[account][nCheckpoints - 1].votes : 0; 150 | } 151 | 152 | /** 153 | * @notice Determine the prior number of votes for an account as of a block number 154 | * @dev Block number must be a finalized block or else this function will revert to prevent misinformation. 155 | * @param account The address of the account to check 156 | * @param blockNumber The block number to get the vote balance at 157 | * @return The number of votes the account had as of the given block 158 | */ 159 | function getPriorVotes(address account, uint256 blockNumber) external view returns (uint256) { 160 | require(blockNumber < block.number, "FORK::getPriorVotes: not yet determined"); 161 | 162 | uint32 nCheckpoints = numCheckpoints[account]; 163 | if (nCheckpoints == 0) { 164 | return 0; 165 | } 166 | 167 | // First check most recent balance 168 | if (checkpoints[account][nCheckpoints - 1].fromBlock <= blockNumber) { 169 | return checkpoints[account][nCheckpoints - 1].votes; 170 | } 171 | 172 | // Next check implicit zero balance 173 | if (checkpoints[account][0].fromBlock > blockNumber) { 174 | return 0; 175 | } 176 | 177 | uint32 lower = 0; 178 | uint32 upper = nCheckpoints - 1; 179 | while (upper > lower) { 180 | uint32 center = upper - (upper - lower) / 2; // ceil, avoiding overflow 181 | Checkpoint memory cp = checkpoints[account][center]; 182 | if (cp.fromBlock == blockNumber) { 183 | return cp.votes; 184 | } else if (cp.fromBlock < blockNumber) { 185 | lower = center; 186 | } else { 187 | upper = center - 1; 188 | } 189 | } 190 | return checkpoints[account][lower].votes; 191 | } 192 | 193 | function _delegate(address delegator, address delegatee) internal { 194 | address currentDelegate = _delegates[delegator]; 195 | uint256 delegatorBalance = balanceOf(delegator); // balance of underlying FORKs (not scaled); 196 | _delegates[delegator] = delegatee; 197 | 198 | emit DelegateChanged(delegator, currentDelegate, delegatee); 199 | 200 | _moveDelegates(currentDelegate, delegatee, delegatorBalance); 201 | } 202 | 203 | function _moveDelegates( 204 | address srcRep, 205 | address dstRep, 206 | uint256 amount 207 | ) internal { 208 | if (srcRep != dstRep && amount > 0) { 209 | if (srcRep != address(0)) { 210 | // decrease old representative 211 | uint32 srcRepNum = numCheckpoints[srcRep]; 212 | uint256 srcRepOld = srcRepNum > 0 ? checkpoints[srcRep][srcRepNum - 1].votes : 0; 213 | uint256 srcRepNew = srcRepOld.sub(amount); 214 | _writeCheckpoint(srcRep, srcRepNum, srcRepOld, srcRepNew); 215 | } 216 | 217 | if (dstRep != address(0)) { 218 | // increase new representative 219 | uint32 dstRepNum = numCheckpoints[dstRep]; 220 | uint256 dstRepOld = dstRepNum > 0 ? checkpoints[dstRep][dstRepNum - 1].votes : 0; 221 | uint256 dstRepNew = dstRepOld.add(amount); 222 | _writeCheckpoint(dstRep, dstRepNum, dstRepOld, dstRepNew); 223 | } 224 | } 225 | } 226 | 227 | function _writeCheckpoint( 228 | address delegatee, 229 | uint32 nCheckpoints, 230 | uint256 oldVotes, 231 | uint256 newVotes 232 | ) internal { 233 | uint32 blockNumber = safe32(block.number, "FORK::_writeCheckpoint: block number exceeds 32 bits"); 234 | 235 | if (nCheckpoints > 0 && checkpoints[delegatee][nCheckpoints - 1].fromBlock == blockNumber) { 236 | checkpoints[delegatee][nCheckpoints - 1].votes = newVotes; 237 | } else { 238 | checkpoints[delegatee][nCheckpoints] = Checkpoint(blockNumber, newVotes); 239 | numCheckpoints[delegatee] = nCheckpoints + 1; 240 | } 241 | 242 | emit DelegateVotesChanged(delegatee, oldVotes, newVotes); 243 | } 244 | 245 | function safe32(uint256 n, string memory errorMessage) internal pure returns (uint32) { 246 | require(n < 2**32, errorMessage); 247 | return uint32(n); 248 | } 249 | 250 | function getChainId() internal pure returns (uint256) { 251 | uint256 chainId; 252 | assembly { 253 | chainId := chainid() 254 | } 255 | return chainId; 256 | } 257 | } 258 | -------------------------------------------------------------------------------- /contracts/protocol/IDFO.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.6.6; 2 | 3 | import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; 4 | import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; 5 | 6 | import "./CheckToken.sol"; 7 | 8 | // ForkLaunch is a smart contract for distributing CHECK by asking user to stake the FORK token. 9 | contract IDFO is Ownable { 10 | using SafeMath for uint256; 11 | using SafeERC20 for IERC20; 12 | using SafeERC20 for CheckToken; 13 | 14 | // Info of each user. 15 | struct UserInfo { 16 | uint256 amount; // How many Staking tokens the user has provided. 17 | uint256 rewardDebt; // Reward debt. See explanation below. 18 | uint256 bonusDebt; // Last block that user exec something to the pool. 19 | // 20 | // We do some fancy math here. Basically, any point in time, the amount of CHECKs 21 | // entitled to a user but is pending to be distributed is: 22 | // 23 | // pending reward = (user.amount * pool.accCheckPerShare) - user.rewardDebt 24 | // 25 | // Whenever a user deposits or withdraws Staking tokens to a pool. Here's what happens: 26 | // 1. The pool's `accCheckPerShare` (and `lastRewardBlock`) gets updated. 27 | // 2. User receives the pending reward sent to his/her address. 28 | // 3. User's `amount` gets updated. 29 | // 4. User's `rewardDebt` gets updated. 30 | } 31 | 32 | // Info of each pool. 33 | struct PoolInfo { 34 | address stakeToken; // Address of Staking token contract. 35 | uint256 allocPoint; // How many allocation points assigned to this pool. CHECKs to distribute per block. 36 | uint256 lastRewardBlock; // Last block number that CHECKs distribution occurs. 37 | uint256 accCheckPerShare; // Accumulated CHECKs per share, times 1e12. See below. 38 | uint256 projectId; 39 | uint256 lpSupply; 40 | uint256 accCheckPerShareTilBonusEnd; // Accumated CHECKs per share until Bonus End. 41 | } 42 | 43 | // The Check TOKEN! 44 | CheckToken public check; 45 | // Dev address. 46 | address public devaddr; 47 | // CHECK tokens created per block. 48 | uint256 public checkPerBlock; 49 | // muliplier 50 | uint256 public BONUS_MULTIPLIER = 1; 51 | // Block number when bonus CHECK period ends. 52 | uint256 public bonusEndBlock; 53 | // Bonus lock-up in BPS 54 | uint256 public bonusLockUpBps; 55 | 56 | // Info of each pool. 57 | PoolInfo[] public poolInfo; 58 | // Info of each user that stakes Staking tokens. 59 | mapping(uint256 => mapping(address => UserInfo)) public userInfo; 60 | // Total allocation points. Must be the sum of all allocation points in all pools. 61 | uint256 public totalAllocPoint = 0; 62 | // The block number when CHECK mining starts. 63 | uint256 public startBlock; 64 | 65 | event Deposit(address indexed user, uint256 indexed pid, uint256 amount); 66 | event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); 67 | event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); 68 | event DepositCheckToCashPool(address indexed user, uint256 indexed pid, uint256 amount); 69 | event CashedCheck(address indexed user, uint256 indexed pid, uint256 amount, uint256 pending); 70 | 71 | constructor( 72 | CheckToken _check, 73 | address _devaddr, 74 | uint256 _checkPerBlock, 75 | uint256 _startBlock, 76 | uint256 _bonusLockupBps, 77 | uint256 _bonusEndBlock 78 | ) public { 79 | BONUS_MULTIPLIER = 0; 80 | totalAllocPoint = 0; 81 | check = _check; 82 | devaddr = _devaddr; 83 | checkPerBlock = _checkPerBlock; 84 | bonusLockUpBps = _bonusLockupBps; 85 | bonusEndBlock = _bonusEndBlock; 86 | startBlock = _startBlock; 87 | } 88 | 89 | /** 90 | * setting 91 | */ 92 | 93 | // Update dev address by the previous dev. 94 | function setDev(address _devaddr) public { 95 | require(msg.sender == devaddr, "dev: wut?"); 96 | devaddr = _devaddr; 97 | } 98 | 99 | function updateCheckPerBlock(uint256 _checkPerBlock) public onlyOwner { 100 | checkPerBlock = _checkPerBlock; 101 | } 102 | 103 | // Set Bonus params. bonus will start to accu on the next block that this function executed 104 | // See the calculation and counting in test file. 105 | function setBonus( 106 | uint256 _bonusMultiplier, 107 | uint256 _bonusEndBlock, 108 | uint256 _bonusLockUpBps 109 | ) public onlyOwner { 110 | require(_bonusEndBlock > block.number, "setBonus: bad bonusEndBlock"); 111 | require(_bonusMultiplier > 1, "setBonus: bad bonusMultiplier"); 112 | BONUS_MULTIPLIER = _bonusMultiplier; 113 | bonusEndBlock = _bonusEndBlock; 114 | bonusLockUpBps = _bonusLockUpBps; 115 | } 116 | 117 | function updatePoolPorjectId(uint256 _pid, uint256 _projectId) public onlyOwner { 118 | poolInfo[_pid].projectId = _projectId; 119 | } 120 | 121 | function poolLength() external view returns (uint256) { 122 | return poolInfo.length; 123 | } 124 | 125 | // Add a new lp to the pool. Can only be called by the owner. 126 | function add( 127 | uint256 _projectId, 128 | uint256 _allocPoint, 129 | address _stakeToken, 130 | bool _withUpdate 131 | ) public onlyOwner { 132 | if (_withUpdate) { 133 | massUpdatePools(); 134 | } 135 | require(_stakeToken != address(0), "add: not stakeToken addr"); 136 | // check exisit 137 | require(!isDuplicatedPool(_projectId, _stakeToken), "add: stakeToken dup"); 138 | 139 | uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; 140 | totalAllocPoint = totalAllocPoint.add(_allocPoint); 141 | poolInfo.push( 142 | PoolInfo({ 143 | projectId: _projectId, 144 | stakeToken: _stakeToken, 145 | allocPoint: _allocPoint, 146 | lastRewardBlock: lastRewardBlock, 147 | accCheckPerShare: 0, 148 | accCheckPerShareTilBonusEnd: 0, 149 | lpSupply: 0 150 | }) 151 | ); 152 | } 153 | 154 | // Update the given pool's CHECK allocation point. Can only be called by the owner. 155 | function set(uint256 _pid, uint256 _allocPoint, bool _withUpdate) public onlyOwner { 156 | if (_withUpdate) { 157 | massUpdatePools(); 158 | } 159 | uint256 prevAllocPoint = poolInfo[_pid].allocPoint; 160 | poolInfo[_pid].allocPoint = _allocPoint; 161 | if (prevAllocPoint != _allocPoint) { 162 | totalAllocPoint = totalAllocPoint.sub(prevAllocPoint).add(_allocPoint); 163 | } 164 | } 165 | 166 | // Return reward multiplier over the given _from to _to block. 167 | function getMultiplier(uint256 _lastRewardBlock, uint256 _currentBlock) public view returns (uint256) { 168 | if (_currentBlock <= bonusEndBlock) { 169 | return _currentBlock.sub(_lastRewardBlock).mul(BONUS_MULTIPLIER); 170 | } 171 | if (_lastRewardBlock >= bonusEndBlock) { 172 | return _currentBlock.sub(_lastRewardBlock); 173 | } 174 | // This is the case where bonusEndBlock is in the middle of _lastRewardBlock and _currentBlock block. 175 | return bonusEndBlock.sub(_lastRewardBlock).mul(BONUS_MULTIPLIER).add(_currentBlock.sub(bonusEndBlock)); 176 | } 177 | 178 | /** 179 | * core 180 | */ 181 | 182 | function isDuplicatedPool(uint256 _projectId, address _stakeToken) public view returns (bool) { 183 | uint256 length = poolInfo.length; 184 | for (uint256 _pid = 0; _pid < length; _pid++) { 185 | if( poolInfo[_pid].projectId == _projectId && poolInfo[_pid].stakeToken == _stakeToken) return true; 186 | } 187 | return false; 188 | } 189 | 190 | 191 | // View function to see pending CHECKs on frontend. 192 | function pendingCheck(uint256 _pid, address _user) external view returns (uint256) { 193 | PoolInfo storage pool = poolInfo[_pid]; 194 | UserInfo storage user = userInfo[_pid][_user]; 195 | uint256 accCheckPerShare = pool.accCheckPerShare; 196 | uint256 lpSupply = pool.lpSupply; 197 | if (block.number > pool.lastRewardBlock && lpSupply != 0) { 198 | uint256 multiplier = getMultiplier(pool.lastRewardBlock, block.number); 199 | uint256 checkReward = multiplier.mul(checkPerBlock).mul(pool.allocPoint).div(totalAllocPoint); 200 | accCheckPerShare = accCheckPerShare.add(checkReward.mul(1e12).div(lpSupply)); 201 | } 202 | return user.amount.mul(accCheckPerShare).div(1e12).sub(user.rewardDebt); 203 | } 204 | 205 | // Update reward vairables for all pools. Be careful of gas spending! 206 | function massUpdatePools() public { 207 | uint256 length = poolInfo.length; 208 | for (uint256 pid = 0; pid < length; ++pid) { 209 | updatePool(pid); 210 | } 211 | } 212 | 213 | // Update reward variables of the given pool to be up-to-date. 214 | function updatePool(uint256 _pid) public { 215 | PoolInfo storage pool = poolInfo[_pid]; 216 | if (block.number <= pool.lastRewardBlock) { 217 | return; 218 | } 219 | uint256 lpSupply = pool.lpSupply; 220 | if (lpSupply == 0) { 221 | pool.lastRewardBlock = block.number; 222 | return; 223 | } 224 | uint256 multiplier = getMultiplier(pool.lastRewardBlock, block.number); 225 | uint256 checkReward = multiplier.mul(checkPerBlock).mul(pool.allocPoint).div(totalAllocPoint); 226 | check.mint(devaddr, checkReward.div(10)); 227 | check.mint(address(this), checkReward); 228 | pool.accCheckPerShare = pool.accCheckPerShare.add(checkReward.mul(1e12).div(lpSupply)); 229 | // update accCheckPerShareTilBonusEnd 230 | if (block.number <= bonusEndBlock) { 231 | check.lock(devaddr, checkReward.div(10).mul(bonusLockUpBps).div(10000)); 232 | pool.accCheckPerShareTilBonusEnd = pool.accCheckPerShare; 233 | } 234 | if(block.number > bonusEndBlock && pool.lastRewardBlock < bonusEndBlock) { 235 | uint256 checkBonusPortion = bonusEndBlock.sub(pool.lastRewardBlock).mul(BONUS_MULTIPLIER).mul(checkPerBlock).mul(pool.allocPoint).div(totalAllocPoint); 236 | check.lock(devaddr, checkBonusPortion.div(10).mul(bonusLockUpBps).div(10000)); 237 | pool.accCheckPerShareTilBonusEnd = pool.accCheckPerShareTilBonusEnd.add(checkBonusPortion.mul(1e12).div(lpSupply)); 238 | } 239 | pool.lastRewardBlock = block.number; 240 | } 241 | 242 | // Deposit Staking tokens to FairLaunchToken for CHECK allocation. 243 | function deposit(uint256 _pid, uint256 _amount) public { 244 | require(_pid < poolInfo.length, 'pool is not existed'); 245 | PoolInfo storage pool = poolInfo[_pid]; 246 | UserInfo storage user = userInfo[_pid][msg.sender]; 247 | updatePool(_pid); 248 | if (user.amount > 0) _harvest(_pid); 249 | IERC20(pool.stakeToken).safeTransferFrom(address(msg.sender), address(this), _amount); 250 | user.amount = user.amount.add(_amount); 251 | user.rewardDebt = user.amount.mul(pool.accCheckPerShare).div(1e12); 252 | user.bonusDebt = user.amount.mul(pool.accCheckPerShareTilBonusEnd).div(1e12); 253 | pool.lpSupply = pool.lpSupply.add(_amount); 254 | emit Deposit(msg.sender, _pid, _amount); 255 | } 256 | 257 | // Withdraw Staking tokens from FairLaunchToken. 258 | function withdraw(uint256 _pid, uint256 _amount) public { 259 | _withdraw(_pid, _amount); 260 | } 261 | 262 | function withdrawAll(uint256 _pid) public { 263 | _withdraw(_pid, userInfo[_pid][msg.sender].amount); 264 | } 265 | 266 | function _withdraw(uint256 _pid, uint256 _amount) internal { 267 | PoolInfo storage pool = poolInfo[_pid]; 268 | UserInfo storage user = userInfo[_pid][msg.sender]; 269 | require(user.amount >= _amount, "withdraw: not good"); 270 | updatePool(_pid); 271 | _harvest(_pid); 272 | user.amount = user.amount.sub(_amount); 273 | user.rewardDebt = user.amount.mul(pool.accCheckPerShare).div(1e12); 274 | user.bonusDebt = user.amount.mul(pool.accCheckPerShareTilBonusEnd).div(1e12); 275 | pool.lpSupply = pool.lpSupply.sub(_amount); 276 | if (pool.stakeToken != address(0)) { 277 | IERC20(pool.stakeToken).safeTransfer(address(msg.sender), _amount); 278 | } 279 | emit Withdraw(msg.sender, _pid, _amount); 280 | } 281 | 282 | // Harvest CHECKs earn from the pool. 283 | function harvest(uint256 _pid) public { 284 | PoolInfo storage pool = poolInfo[_pid]; 285 | UserInfo storage user = userInfo[_pid][msg.sender]; 286 | updatePool(_pid); 287 | _harvest(_pid); 288 | user.rewardDebt = user.amount.mul(pool.accCheckPerShare).div(1e12); 289 | user.bonusDebt = user.amount.mul(pool.accCheckPerShareTilBonusEnd).div(1e12); 290 | } 291 | 292 | function _harvest(uint256 _pid) internal { 293 | PoolInfo storage pool = poolInfo[_pid]; 294 | UserInfo storage user = userInfo[_pid][msg.sender]; 295 | require(user.amount > 0, "nothing to harvest"); 296 | uint256 pending = user.amount.mul(pool.accCheckPerShare).div(1e12).sub(user.rewardDebt); 297 | require(pending <= check.balanceOf(address(this)), "wtf not enough check"); 298 | uint256 bonus = user.amount.mul(pool.accCheckPerShareTilBonusEnd).div(1e12).sub(user.bonusDebt); 299 | _safeCheckTransfer(msg.sender, pending); 300 | check.lock(msg.sender, bonus.mul(bonusLockUpBps).div(10000)); 301 | } 302 | 303 | // Withdraw without caring about rewards. EMERGENCY ONLY. 304 | function emergencyWithdraw(uint256 _pid) public { 305 | PoolInfo storage pool = poolInfo[_pid]; 306 | UserInfo storage user = userInfo[_pid][msg.sender]; 307 | IERC20(pool.stakeToken).safeTransfer(address(msg.sender), user.amount); 308 | user.amount = 0; 309 | user.rewardDebt = 0; 310 | emit EmergencyWithdraw(msg.sender, _pid, user.amount); 311 | } 312 | 313 | // Safe check transfer function, just in case if rounding error causes pool to not have enough CHECKs. 314 | function _safeCheckTransfer(address _to, uint256 _amount) internal { 315 | uint256 checkBal = check.balanceOf(address(this)); 316 | if (_amount > checkBal) { 317 | check.transfer(_to, checkBal); 318 | } else { 319 | check.transfer(_to, _amount); 320 | } 321 | } 322 | } 323 | -------------------------------------------------------------------------------- /contracts/protocol/LPLock.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.6.6; 2 | 3 | import "@openzeppelin/contracts/access/Ownable.sol"; 4 | import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; 5 | import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; 6 | 7 | contract LPLock is Ownable { 8 | using SafeMath for uint256; 9 | using SafeERC20 for IERC20; 10 | 11 | string public constant name = "Fork Finance LP Lock"; 12 | 13 | uint256 public createdAt; 14 | uint256 public lockTime; 15 | 16 | constructor(uint256 _lockTime) public { 17 | lockTime = _lockTime; 18 | createdAt = block.timestamp; 19 | } 20 | 21 | // locked 3*30day 22 | modifier checkLock() { 23 | uint256 unlockAt = createdAt.add(lockTime); 24 | require(block.timestamp>=unlockAt, "locking"); 25 | _; 26 | } 27 | 28 | function transferAnyTo( 29 | address _token, 30 | address _to, 31 | uint256 _amount 32 | ) public onlyOwner checkLock { 33 | IERC20(_token).safeTransfer(_to, _amount); 34 | } 35 | } -------------------------------------------------------------------------------- /contracts/protocol/apis/uniswap/IUniswapV2Router02.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.0; 2 | 3 | interface IUniswapV2Router02 { 4 | function factory() external pure returns (address); 5 | 6 | function WETH() external pure returns (address); 7 | 8 | function addLiquidity( 9 | address tokenA, 10 | address tokenB, 11 | uint256 amountADesired, 12 | uint256 amountBDesired, 13 | uint256 amountAMin, 14 | uint256 amountBMin, 15 | address to, 16 | uint256 deadline 17 | ) 18 | external 19 | returns ( 20 | uint256 amountA, 21 | uint256 amountB, 22 | uint256 liquidity 23 | ); 24 | 25 | function addLiquidityETH( 26 | address token, 27 | uint256 amountTokenDesired, 28 | uint256 amountTokenMin, 29 | uint256 amountETHMin, 30 | address to, 31 | uint256 deadline 32 | ) 33 | external 34 | payable 35 | returns ( 36 | uint256 amountToken, 37 | uint256 amountETH, 38 | uint256 liquidity 39 | ); 40 | 41 | function removeLiquidity( 42 | address tokenA, 43 | address tokenB, 44 | uint256 liquidity, 45 | uint256 amountAMin, 46 | uint256 amountBMin, 47 | address to, 48 | uint256 deadline 49 | ) external returns (uint256 amountA, uint256 amountB); 50 | 51 | function removeLiquidityETH( 52 | address token, 53 | uint256 liquidity, 54 | uint256 amountTokenMin, 55 | uint256 amountETHMin, 56 | address to, 57 | uint256 deadline 58 | ) external returns (uint256 amountToken, uint256 amountETH); 59 | 60 | function removeLiquidityWithPermit( 61 | address tokenA, 62 | address tokenB, 63 | uint256 liquidity, 64 | uint256 amountAMin, 65 | uint256 amountBMin, 66 | address to, 67 | uint256 deadline, 68 | bool approveMax, 69 | uint8 v, 70 | bytes32 r, 71 | bytes32 s 72 | ) external returns (uint256 amountA, uint256 amountB); 73 | 74 | function removeLiquidityETHWithPermit( 75 | address token, 76 | uint256 liquidity, 77 | uint256 amountTokenMin, 78 | uint256 amountETHMin, 79 | address to, 80 | uint256 deadline, 81 | bool approveMax, 82 | uint8 v, 83 | bytes32 r, 84 | bytes32 s 85 | ) external returns (uint256 amountToken, uint256 amountETH); 86 | 87 | function swapExactTokensForTokens( 88 | uint256 amountIn, 89 | uint256 amountOutMin, 90 | address[] calldata path, 91 | address to, 92 | uint256 deadline 93 | ) external returns (uint256[] memory amounts); 94 | 95 | function swapTokensForExactTokens( 96 | uint256 amountOut, 97 | uint256 amountInMax, 98 | address[] calldata path, 99 | address to, 100 | uint256 deadline 101 | ) external returns (uint256[] memory amounts); 102 | 103 | function swapExactETHForTokens( 104 | uint256 amountOutMin, 105 | address[] calldata path, 106 | address to, 107 | uint256 deadline 108 | ) external payable returns (uint256[] memory amounts); 109 | 110 | function swapTokensForExactETH( 111 | uint256 amountOut, 112 | uint256 amountInMax, 113 | address[] calldata path, 114 | address to, 115 | uint256 deadline 116 | ) external returns (uint256[] memory amounts); 117 | 118 | function swapExactTokensForETH( 119 | uint256 amountIn, 120 | uint256 amountOutMin, 121 | address[] calldata path, 122 | address to, 123 | uint256 deadline 124 | ) external returns (uint256[] memory amounts); 125 | 126 | function swapETHForExactTokens( 127 | uint256 amountOut, 128 | address[] calldata path, 129 | address to, 130 | uint256 deadline 131 | ) external payable returns (uint256[] memory amounts); 132 | 133 | function quote( 134 | uint256 amountA, 135 | uint256 reserveA, 136 | uint256 reserveB 137 | ) external pure returns (uint256 amountB); 138 | 139 | function getAmountOut( 140 | uint256 amountIn, 141 | uint256 reserveIn, 142 | uint256 reserveOut 143 | ) external pure returns (uint256 amountOut); 144 | 145 | function getAmountIn( 146 | uint256 amountOut, 147 | uint256 reserveIn, 148 | uint256 reserveOut 149 | ) external pure returns (uint256 amountIn); 150 | 151 | function getAmountsOut(uint256 amountIn, address[] calldata path) 152 | external 153 | view 154 | returns (uint256[] memory amounts); 155 | 156 | function getAmountsIn(uint256 amountOut, address[] calldata path) 157 | external 158 | view 159 | returns (uint256[] memory amounts); 160 | 161 | function removeLiquidityETHSupportingFeeOnTransferTokens( 162 | address token, 163 | uint256 liquidity, 164 | uint256 amountTokenMin, 165 | uint256 amountETHMin, 166 | address to, 167 | uint256 deadline 168 | ) external returns (uint256 amountETH); 169 | 170 | function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( 171 | address token, 172 | uint256 liquidity, 173 | uint256 amountTokenMin, 174 | uint256 amountETHMin, 175 | address to, 176 | uint256 deadline, 177 | bool approveMax, 178 | uint8 v, 179 | bytes32 r, 180 | bytes32 s 181 | ) external returns (uint256 amountETH); 182 | 183 | function swapExactTokensForTokensSupportingFeeOnTransferTokens( 184 | uint256 amountIn, 185 | uint256 amountOutMin, 186 | address[] calldata path, 187 | address to, 188 | uint256 deadline 189 | ) external; 190 | 191 | function swapExactETHForTokensSupportingFeeOnTransferTokens( 192 | uint256 amountOutMin, 193 | address[] calldata path, 194 | address to, 195 | uint256 deadline 196 | ) external payable; 197 | 198 | function swapExactTokensForETHSupportingFeeOnTransferTokens( 199 | uint256 amountIn, 200 | uint256 amountOutMin, 201 | address[] calldata path, 202 | address to, 203 | uint256 deadline 204 | ) external; 205 | } 206 | -------------------------------------------------------------------------------- /contracts/protocol/apis/uniswap/README: -------------------------------------------------------------------------------- 1 | Uniswap code from https://github.com/Uniswap/uniswap-lib and https://github.com/Uniswap/uniswap-v2-periphery with some nontrivial modifications. 2 | -------------------------------------------------------------------------------- /contracts/protocol/apis/uniswap/UniswapV2Library.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.0; 2 | 3 | import "@openzeppelin/contracts/math/SafeMath.sol"; 4 | 5 | import "@uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol"; 6 | import "@uniswap/v2-core/contracts/interfaces/IUniswapV2Factory.sol"; 7 | 8 | library UniswapV2Library { 9 | using SafeMath for uint256; 10 | 11 | // returns sorted token addresses, used to handle return values from pairs sorted in this order 12 | function sortTokens(address tokenA, address tokenB) internal pure returns (address token0, address token1) { 13 | require(tokenA != tokenB, "UniswapV2Library: IDENTICAL_ADDRESSES"); 14 | (token0, token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA); 15 | require(token0 != address(0), "UniswapV2Library: ZERO_ADDRESS"); 16 | } 17 | 18 | // calculates the CREATE2 address for a pair without making any external calls 19 | function pairFor( 20 | address factory, 21 | address tokenA, 22 | address tokenB 23 | ) internal view returns (address pair) { 24 | return IUniswapV2Factory(factory).getPair(tokenA, tokenB); // For easy testing 25 | // (address token0, address token1) = sortTokens(tokenA, tokenB); 26 | // pair = address( 27 | // uint256( 28 | // keccak256( 29 | // abi.encodePacked( 30 | // hex'ff', 31 | // factory, 32 | // keccak256(abi.encodePacked(token0, token1)), 33 | // hex'fc4928e335b531bb85a6d9454f46863f9d6101351e3e8b84620b1806d4a3fcb3' // init code hash 34 | // ) 35 | // ) 36 | // ) 37 | // ); 38 | } 39 | 40 | // fetches and sorts the reserves for a pair 41 | function getReserves( 42 | address factory, 43 | address tokenA, 44 | address tokenB 45 | ) internal view returns (uint256 reserveA, uint256 reserveB) { 46 | (address token0, ) = sortTokens(tokenA, tokenB); 47 | (uint256 reserve0, uint256 reserve1, ) = IUniswapV2Pair(pairFor(factory, tokenA, tokenB)).getReserves(); 48 | (reserveA, reserveB) = tokenA == token0 ? (reserve0, reserve1) : (reserve1, reserve0); 49 | } 50 | 51 | // given some amount of an asset and pair reserves, returns an equivalent amount of the other asset 52 | function quote( 53 | uint256 amountA, 54 | uint256 reserveA, 55 | uint256 reserveB 56 | ) internal pure returns (uint256 amountB) { 57 | require(amountA > 0, "UniswapV2Library: INSUFFICIENT_AMOUNT"); 58 | require(reserveA > 0 && reserveB > 0, "UniswapV2Library: INSUFFICIENT_LIQUIDITY"); 59 | amountB = amountA.mul(reserveB) / reserveA; 60 | } 61 | 62 | // given an input amount of an asset and pair reserves, returns the maximum output amount of the other asset 63 | function getAmountOut( 64 | uint256 amountIn, 65 | uint256 reserveIn, 66 | uint256 reserveOut 67 | ) internal pure returns (uint256 amountOut) { 68 | require(amountIn > 0, "UniswapV2Library: INSUFFICIENT_INPUT_AMOUNT"); 69 | require(reserveIn > 0 && reserveOut > 0, "UniswapV2Library: INSUFFICIENT_LIQUIDITY"); 70 | uint256 amountInWithFee = amountIn.mul(997); 71 | uint256 numerator = amountInWithFee.mul(reserveOut); 72 | uint256 denominator = reserveIn.mul(1000).add(amountInWithFee); 73 | amountOut = numerator / denominator; 74 | } 75 | 76 | // given an output amount of an asset and pair reserves, returns a required input amount of the other asset 77 | function getAmountIn( 78 | uint256 amountOut, 79 | uint256 reserveIn, 80 | uint256 reserveOut 81 | ) internal pure returns (uint256 amountIn) { 82 | require(amountOut > 0, "UniswapV2Library: INSUFFICIENT_OUTPUT_AMOUNT"); 83 | require(reserveIn > 0 && reserveOut > 0, "UniswapV2Library: INSUFFICIENT_LIQUIDITY"); 84 | uint256 numerator = reserveIn.mul(amountOut).mul(1000); 85 | uint256 denominator = reserveOut.sub(amountOut).mul(997); 86 | amountIn = (numerator / denominator).add(1); 87 | } 88 | 89 | // performs chained getAmountOut calculations on any number of pairs 90 | function getAmountsOut( 91 | address factory, 92 | uint256 amountIn, 93 | address[] memory path 94 | ) internal view returns (uint256[] memory amounts) { 95 | require(path.length >= 2, "UniswapV2Library: INVALID_PATH"); 96 | amounts = new uint256[](path.length); 97 | amounts[0] = amountIn; 98 | for (uint256 i; i < path.length - 1; i++) { 99 | (uint256 reserveIn, uint256 reserveOut) = getReserves(factory, path[i], path[i + 1]); 100 | amounts[i + 1] = getAmountOut(amounts[i], reserveIn, reserveOut); 101 | } 102 | } 103 | 104 | // performs chained getAmountIn calculations on any number of pairs 105 | function getAmountsIn( 106 | address factory, 107 | uint256 amountOut, 108 | address[] memory path 109 | ) internal view returns (uint256[] memory amounts) { 110 | require(path.length >= 2, "UniswapV2Library: INVALID_PATH"); 111 | amounts = new uint256[](path.length); 112 | amounts[amounts.length - 1] = amountOut; 113 | for (uint256 i = path.length - 1; i > 0; i--) { 114 | (uint256 reserveIn, uint256 reserveOut) = getReserves(factory, path[i - 1], path[i]); 115 | amounts[i - 1] = getAmountIn(amounts[i], reserveIn, reserveOut); 116 | } 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /contracts/protocol/apis/uniswap/UniswapV2Router02.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.6.6; 2 | 3 | import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; 4 | 5 | import "@uniswap/v2-core/contracts/interfaces/IUniswapV2Factory.sol"; 6 | 7 | import "../../interfaces/IWETH.sol"; 8 | import "./UniswapV2Library.sol"; 9 | import "./IUniswapV2Router02.sol"; 10 | import "../../../utils/SafeToken.sol"; 11 | 12 | contract UniswapV2Router02 is IUniswapV2Router02 { 13 | using SafeMath for uint256; 14 | 15 | address override public factory; 16 | address override public WETH; 17 | 18 | modifier ensure(uint256 deadline) { 19 | require(deadline >= block.timestamp, "UniswapV2Router: EXPIRED"); 20 | _; 21 | } 22 | 23 | constructor(address _factory, address _WETH) public { 24 | factory = _factory; 25 | WETH = _WETH; 26 | } 27 | 28 | receive() external payable { 29 | assert(msg.sender == WETH); // only accept ETH via fallback from the WETH contract 30 | } 31 | 32 | // **** ADD LIQUIDITY **** 33 | function _addLiquidity( 34 | address tokenA, 35 | address tokenB, 36 | uint256 amountADesired, 37 | uint256 amountBDesired, 38 | uint256 amountAMin, 39 | uint256 amountBMin 40 | ) internal returns (uint256 amountA, uint256 amountB) { 41 | // create the pair if it doesn't exist yet 42 | if (IUniswapV2Factory(factory).getPair(tokenA, tokenB) == address(0)) { 43 | IUniswapV2Factory(factory).createPair(tokenA, tokenB); 44 | } 45 | (uint reserveA, uint reserveB) = UniswapV2Library.getReserves(factory, tokenA, tokenB); 46 | if (reserveA == 0 && reserveB == 0) { 47 | (amountA, amountB) = (amountADesired, amountBDesired); 48 | } else { 49 | uint amountBOptimal = UniswapV2Library.quote(amountADesired, reserveA, reserveB); 50 | if (amountBOptimal <= amountBDesired) { 51 | require(amountBOptimal >= amountBMin, 'UniswapV2Router: INSUFFICIENT_B_AMOUNT'); 52 | (amountA, amountB) = (amountADesired, amountBOptimal); 53 | } else { 54 | uint amountAOptimal = UniswapV2Library.quote(amountBDesired, reserveB, reserveA); 55 | assert(amountAOptimal <= amountADesired); 56 | require(amountAOptimal >= amountAMin, 'UniswapV2Router: INSUFFICIENT_A_AMOUNT'); 57 | (amountA, amountB) = (amountAOptimal, amountBDesired); 58 | } 59 | } 60 | } 61 | function addLiquidity( 62 | address tokenA, 63 | address tokenB, 64 | uint256 amountADesired, 65 | uint256 amountBDesired, 66 | uint256 amountAMin, 67 | uint256 amountBMin, 68 | address to, 69 | uint256 deadline 70 | ) external override ensure(deadline) returns (uint256 amountA, uint256 amountB, uint256 liquidity) { 71 | (amountA, amountB) = _addLiquidity(tokenA, tokenB, amountADesired, amountBDesired, amountAMin, amountBMin); 72 | address pair = UniswapV2Library.pairFor(factory, tokenA, tokenB); 73 | SafeToken.safeTransferFrom(tokenA, msg.sender, pair, amountA); 74 | SafeToken.safeTransferFrom(tokenB, msg.sender, pair, amountB); 75 | liquidity = IUniswapV2Pair(pair).mint(to); 76 | } 77 | 78 | function addLiquidityETH( 79 | address token, 80 | uint256 amountTokenDesired, 81 | uint256 amountTokenMin, 82 | uint256 amountETHMin, 83 | address to, 84 | uint256 deadline 85 | ) external override payable ensure(deadline) returns (uint256 amountToken, uint256 amountETH, uint256 liquidity) { 86 | (amountToken, amountETH) = _addLiquidity( 87 | token, 88 | WETH, 89 | amountTokenDesired, 90 | msg.value, 91 | amountTokenMin, 92 | amountETHMin 93 | ); 94 | address pair = UniswapV2Library.pairFor(factory, token, WETH); 95 | SafeToken.safeTransferFrom(token, msg.sender, pair, amountToken); 96 | IWETH(WETH).deposit{value: amountETH}(); 97 | assert(IWETH(WETH).transfer(pair, amountETH)); 98 | liquidity = IUniswapV2Pair(pair).mint(to); 99 | // refund dust eth, if any 100 | if (msg.value > amountETH) SafeToken.safeTransferETH(msg.sender, msg.value - amountETH); 101 | } 102 | 103 | // **** REMOVE LIQUIDITY **** 104 | function removeLiquidity( 105 | address tokenA, 106 | address tokenB, 107 | uint256 liquidity, 108 | uint256 amountAMin, 109 | uint256 amountBMin, 110 | address to, 111 | uint256 deadline 112 | ) public override ensure(deadline) returns (uint256 amountA, uint256 amountB) { 113 | address pair = UniswapV2Library.pairFor(factory, tokenA, tokenB); 114 | IUniswapV2Pair(pair).transferFrom(msg.sender, pair, liquidity); // send liquidity to pair 115 | (uint amount0, uint amount1) = IUniswapV2Pair(pair).burn(to); 116 | (address token0,) = UniswapV2Library.sortTokens(tokenA, tokenB); 117 | (amountA, amountB) = tokenA == token0 ? (amount0, amount1) : (amount1, amount0); 118 | require(amountA >= amountAMin, 'UniswapV2Router: INSUFFICIENT_A_AMOUNT'); 119 | require(amountB >= amountBMin, 'UniswapV2Router: INSUFFICIENT_B_AMOUNT'); 120 | } 121 | 122 | function removeLiquidityETH( 123 | address token, 124 | uint256 liquidity, 125 | uint256 amountTokenMin, 126 | uint256 amountETHMin, 127 | address to, 128 | uint256 deadline 129 | ) public override ensure(deadline) returns (uint256 amountToken, uint256 amountETH) { 130 | (amountToken, amountETH) = removeLiquidity( 131 | token, 132 | WETH, 133 | liquidity, 134 | amountTokenMin, 135 | amountETHMin, 136 | address(this), 137 | deadline 138 | ); 139 | SafeToken.safeTransfer(token, to, amountToken); 140 | IWETH(WETH).withdraw(amountETH); 141 | SafeToken.safeTransferETH(to, amountETH); 142 | } 143 | 144 | function removeLiquidityWithPermit( 145 | address tokenA, 146 | address tokenB, 147 | uint256 liquidity, 148 | uint256 amountAMin, 149 | uint256 amountBMin, 150 | address to, 151 | uint256 deadline, 152 | bool approveMax, uint8 v, bytes32 r, bytes32 s 153 | ) external override returns (uint256 amountA, uint256 amountB) { 154 | address pair = UniswapV2Library.pairFor(factory, tokenA, tokenB); 155 | uint value = approveMax ? uint(-1) : liquidity; 156 | IUniswapV2Pair(pair).permit(msg.sender, address(this), value, deadline, v, r, s); 157 | (amountA, amountB) = removeLiquidity(tokenA, tokenB, liquidity, amountAMin, amountBMin, to, deadline); 158 | } 159 | 160 | function removeLiquidityETHWithPermit( 161 | address token, 162 | uint256 liquidity, 163 | uint256 amountTokenMin, 164 | uint256 amountETHMin, 165 | address to, 166 | uint256 deadline, 167 | bool approveMax, uint8 v, bytes32 r, bytes32 s 168 | ) external override returns (uint256 amountToken, uint256 amountETH) { 169 | address pair = UniswapV2Library.pairFor(factory, token, WETH); 170 | uint value = approveMax ? uint(-1) : liquidity; 171 | IUniswapV2Pair(pair).permit(msg.sender, address(this), value, deadline, v, r, s); 172 | (amountToken, amountETH) = removeLiquidityETH(token, liquidity, amountTokenMin, amountETHMin, to, deadline); 173 | } 174 | 175 | // **** REMOVE LIQUIDITY (supporting fee-on-transfer tokens) **** 176 | function removeLiquidityETHSupportingFeeOnTransferTokens( 177 | address token, 178 | uint256 liquidity, 179 | uint256 amountTokenMin, 180 | uint256 amountETHMin, 181 | address to, 182 | uint256 deadline 183 | ) public override ensure(deadline) returns (uint256 amountETH) { 184 | (, amountETH) = removeLiquidity( 185 | token, 186 | WETH, 187 | liquidity, 188 | amountTokenMin, 189 | amountETHMin, 190 | address(this), 191 | deadline 192 | ); 193 | SafeToken.safeTransfer(token, to, IERC20(token).balanceOf(address(this))); 194 | IWETH(WETH).withdraw(amountETH); 195 | SafeToken.safeTransferETH(to, amountETH); 196 | } 197 | 198 | function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( 199 | address token, 200 | uint256 liquidity, 201 | uint256 amountTokenMin, 202 | uint256 amountETHMin, 203 | address to, 204 | uint256 deadline, 205 | bool approveMax, uint8 v, bytes32 r, bytes32 s 206 | ) external override returns (uint256 amountETH) { 207 | address pair = UniswapV2Library.pairFor(factory, token, WETH); 208 | uint value = approveMax ? uint(-1) : liquidity; 209 | IUniswapV2Pair(pair).permit(msg.sender, address(this), value, deadline, v, r, s); 210 | amountETH = removeLiquidityETHSupportingFeeOnTransferTokens( 211 | token, liquidity, amountTokenMin, amountETHMin, to, deadline 212 | ); 213 | } 214 | 215 | // **** SWAP **** 216 | // requires the initial amount to have already been sent to the first pair 217 | function _swap(uint256[] memory amounts, address[] memory path, address _to) internal { 218 | for (uint i; i < path.length - 1; i++) { 219 | (address input, address output) = (path[i], path[i + 1]); 220 | (address token0,) = UniswapV2Library.sortTokens(input, output); 221 | uint amountOut = amounts[i + 1]; 222 | (uint amount0Out, uint amount1Out) = input == token0 ? (uint(0), amountOut) : (amountOut, uint(0)); 223 | address to = i < path.length - 2 ? UniswapV2Library.pairFor(factory, output, path[i + 2]) : _to; 224 | IUniswapV2Pair(UniswapV2Library.pairFor(factory, input, output)).swap( 225 | amount0Out, amount1Out, to, new bytes(0) 226 | ); 227 | } 228 | } 229 | function swapExactTokensForTokens( 230 | uint256 amountIn, 231 | uint256 amountOutMin, 232 | address[] calldata path, 233 | address to, 234 | uint256 deadline 235 | ) external override ensure(deadline) returns (uint256[] memory amounts) { 236 | amounts = UniswapV2Library.getAmountsOut(factory, amountIn, path); 237 | require(amounts[amounts.length - 1] >= amountOutMin, 'UniswapV2Router: INSUFFICIENT_OUTPUT_AMOUNT'); 238 | SafeToken.safeTransferFrom( 239 | path[0], msg.sender, UniswapV2Library.pairFor(factory, path[0], path[1]), amounts[0] 240 | ); 241 | _swap(amounts, path, to); 242 | } 243 | 244 | function swapTokensForExactTokens( 245 | uint amountOut, 246 | uint amountInMax, 247 | address[] calldata path, 248 | address to, 249 | uint deadline 250 | ) external override ensure(deadline) returns (uint[] memory amounts) { 251 | amounts = UniswapV2Library.getAmountsIn(factory, amountOut, path); 252 | require(amounts[0] <= amountInMax, 'UniswapV2Router: EXCESSIVE_INPUT_AMOUNT'); 253 | SafeToken.safeTransferFrom( 254 | path[0], msg.sender, UniswapV2Library.pairFor(factory, path[0], path[1]), amounts[0] 255 | ); 256 | _swap(amounts, path, to); 257 | } 258 | 259 | function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) 260 | external 261 | override 262 | payable 263 | ensure(deadline) 264 | returns (uint[] memory amounts) 265 | { 266 | require(path[0] == WETH, 'UniswapV2Router: INVALID_PATH'); 267 | amounts = UniswapV2Library.getAmountsOut(factory, msg.value, path); 268 | require(amounts[amounts.length - 1] >= amountOutMin, 'UniswapV2Router: INSUFFICIENT_OUTPUT_AMOUNT'); 269 | IWETH(WETH).deposit{value: amounts[0]}(); 270 | assert(IWETH(WETH).transfer(UniswapV2Library.pairFor(factory, path[0], path[1]), amounts[0])); 271 | _swap(amounts, path, to); 272 | } 273 | 274 | function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) 275 | external 276 | override 277 | ensure(deadline) 278 | returns (uint[] memory amounts) 279 | { 280 | require(path[path.length - 1] == WETH, 'UniswapV2Router: INVALID_PATH'); 281 | amounts = UniswapV2Library.getAmountsIn(factory, amountOut, path); 282 | require(amounts[0] <= amountInMax, 'UniswapV2Router: EXCESSIVE_INPUT_AMOUNT'); 283 | SafeToken.safeTransferFrom( 284 | path[0], msg.sender, UniswapV2Library.pairFor(factory, path[0], path[1]), amounts[0] 285 | ); 286 | _swap(amounts, path, address(this)); 287 | IWETH(WETH).withdraw(amounts[amounts.length - 1]); 288 | SafeToken.safeTransferETH(to, amounts[amounts.length - 1]); 289 | } 290 | 291 | function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) 292 | external 293 | override 294 | ensure(deadline) 295 | returns (uint[] memory amounts) 296 | { 297 | require(path[path.length - 1] == WETH, 'UniswapV2Router: INVALID_PATH'); 298 | amounts = UniswapV2Library.getAmountsOut(factory, amountIn, path); 299 | require(amounts[amounts.length - 1] >= amountOutMin, 'UniswapV2Router: INSUFFICIENT_OUTPUT_AMOUNT'); 300 | SafeToken.safeTransferFrom( 301 | path[0], msg.sender, UniswapV2Library.pairFor(factory, path[0], path[1]), amounts[0] 302 | ); 303 | _swap(amounts, path, address(this)); 304 | IWETH(WETH).withdraw(amounts[amounts.length - 1]); 305 | SafeToken.safeTransferETH(to, amounts[amounts.length - 1]); 306 | } 307 | 308 | function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) 309 | external 310 | override 311 | payable 312 | ensure(deadline) 313 | returns (uint[] memory amounts) 314 | { 315 | require(path[0] == WETH, 'UniswapV2Router: INVALID_PATH'); 316 | amounts = UniswapV2Library.getAmountsIn(factory, amountOut, path); 317 | require(amounts[0] <= msg.value, 'UniswapV2Router: EXCESSIVE_INPUT_AMOUNT'); 318 | IWETH(WETH).deposit{value: amounts[0]}(); 319 | assert(IWETH(WETH).transfer(UniswapV2Library.pairFor(factory, path[0], path[1]), amounts[0])); 320 | _swap(amounts, path, to); 321 | // refund dust eth, if any 322 | if (msg.value > amounts[0]) SafeToken.safeTransferETH(msg.sender, msg.value - amounts[0]); 323 | } 324 | 325 | // **** SWAP (supporting fee-on-transfer tokens) **** 326 | // requires the initial amount to have already been sent to the first pair 327 | function _swapSupportingFeeOnTransferTokens(address[] memory path, address _to) internal { 328 | for (uint i; i < path.length - 1; i++) { 329 | (address input, address output) = (path[i], path[i + 1]); 330 | (address token0,) = UniswapV2Library.sortTokens(input, output); 331 | IUniswapV2Pair pair = IUniswapV2Pair(UniswapV2Library.pairFor(factory, input, output)); 332 | uint amountInput; 333 | uint amountOutput; 334 | { // scope to avoid stack too deep errors 335 | (uint reserve0, uint reserve1,) = pair.getReserves(); 336 | (uint reserveInput, uint reserveOutput) = input == token0 ? (reserve0, reserve1) : (reserve1, reserve0); 337 | amountInput = IERC20(input).balanceOf(address(pair)).sub(reserveInput); 338 | amountOutput = UniswapV2Library.getAmountOut(amountInput, reserveInput, reserveOutput); 339 | } 340 | (uint amount0Out, uint amount1Out) = input == token0 ? (uint(0), amountOutput) : (amountOutput, uint(0)); 341 | address to = i < path.length - 2 ? UniswapV2Library.pairFor(factory, output, path[i + 2]) : _to; 342 | pair.swap(amount0Out, amount1Out, to, new bytes(0)); 343 | } 344 | } 345 | 346 | function swapExactTokensForTokensSupportingFeeOnTransferTokens( 347 | uint amountIn, 348 | uint amountOutMin, 349 | address[] calldata path, 350 | address to, 351 | uint deadline 352 | ) external override ensure(deadline) { 353 | SafeToken.safeTransferFrom( 354 | path[0], msg.sender, UniswapV2Library.pairFor(factory, path[0], path[1]), amountIn 355 | ); 356 | uint balanceBefore = IERC20(path[path.length - 1]).balanceOf(to); 357 | _swapSupportingFeeOnTransferTokens(path, to); 358 | require( 359 | IERC20(path[path.length - 1]).balanceOf(to).sub(balanceBefore) >= amountOutMin, 360 | 'UniswapV2Router: INSUFFICIENT_OUTPUT_AMOUNT' 361 | ); 362 | } 363 | 364 | function swapExactETHForTokensSupportingFeeOnTransferTokens( 365 | uint amountOutMin, 366 | address[] calldata path, 367 | address to, 368 | uint deadline 369 | ) 370 | external 371 | override 372 | payable 373 | ensure(deadline) 374 | { 375 | require(path[0] == WETH, 'UniswapV2Router: INVALID_PATH'); 376 | uint amountIn = msg.value; 377 | IWETH(WETH).deposit{value: amountIn}(); 378 | assert(IWETH(WETH).transfer(UniswapV2Library.pairFor(factory, path[0], path[1]), amountIn)); 379 | uint balanceBefore = IERC20(path[path.length - 1]).balanceOf(to); 380 | _swapSupportingFeeOnTransferTokens(path, to); 381 | require( 382 | IERC20(path[path.length - 1]).balanceOf(to).sub(balanceBefore) >= amountOutMin, 383 | 'UniswapV2Router: INSUFFICIENT_OUTPUT_AMOUNT' 384 | ); 385 | } 386 | 387 | function swapExactTokensForETHSupportingFeeOnTransferTokens( 388 | uint amountIn, 389 | uint amountOutMin, 390 | address[] calldata path, 391 | address to, 392 | uint deadline 393 | ) 394 | external 395 | override 396 | ensure(deadline) 397 | { 398 | require(path[path.length - 1] == WETH, 'UniswapV2Router: INVALID_PATH'); 399 | SafeToken.safeTransferFrom( 400 | path[0], msg.sender, UniswapV2Library.pairFor(factory, path[0], path[1]), amountIn 401 | ); 402 | _swapSupportingFeeOnTransferTokens(path, address(this)); 403 | uint amountOut = IERC20(WETH).balanceOf(address(this)); 404 | require(amountOut >= amountOutMin, 'UniswapV2Router: INSUFFICIENT_OUTPUT_AMOUNT'); 405 | IWETH(WETH).withdraw(amountOut); 406 | SafeToken.safeTransferETH(to, amountOut); 407 | } 408 | 409 | // **** LIBRARY FUNCTIONS **** 410 | function quote(uint amountA, uint reserveA, uint reserveB) public override pure returns (uint amountB) { 411 | return UniswapV2Library.quote(amountA, reserveA, reserveB); 412 | } 413 | 414 | function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) 415 | public 416 | override 417 | pure 418 | returns (uint amountOut) 419 | { 420 | return UniswapV2Library.getAmountOut(amountIn, reserveIn, reserveOut); 421 | } 422 | 423 | function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) 424 | public 425 | override 426 | pure 427 | returns (uint amountIn) 428 | { 429 | return UniswapV2Library.getAmountIn(amountOut, reserveIn, reserveOut); 430 | } 431 | 432 | function getAmountsOut(uint amountIn, address[] memory path) 433 | public 434 | override 435 | view 436 | returns (uint[] memory amounts) 437 | { 438 | return UniswapV2Library.getAmountsOut(factory, amountIn, path); 439 | } 440 | 441 | function getAmountsIn(uint amountOut, address[] memory path) 442 | public 443 | override 444 | view 445 | returns (uint[] memory amounts) 446 | { 447 | return UniswapV2Library.getAmountsIn(factory, amountOut, path); 448 | } 449 | } 450 | -------------------------------------------------------------------------------- /contracts/protocol/interfaces/IFairLaunch.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.6.6; 2 | 3 | interface IFairLaunch { 4 | function poolLength() external view returns (uint256); 5 | 6 | function addPool( 7 | uint256 _allocPoint, 8 | address _stakeToken, 9 | bool _withUpdate 10 | ) external; 11 | 12 | function setPool( 13 | uint256 _pid, 14 | uint256 _allocPoint, 15 | bool _withUpdate 16 | ) external; 17 | 18 | function pendingFork(uint256 _pid, address _user) external view returns (uint256); 19 | 20 | function updatePool(uint256 _pid) external; 21 | 22 | function deposit(uint256 _pid, uint256 _amount) external; 23 | 24 | function withdraw(uint256 _pid, uint256 _amount) external; 25 | 26 | function withdrawAll(uint256 _pid) external; 27 | 28 | function harvest(uint256 _pid) external; 29 | } -------------------------------------------------------------------------------- /contracts/protocol/interfaces/IForkFarmLaunch.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.6.6; 2 | 3 | interface IForkFarmLaunch { 4 | function poolLength() external view returns (uint256); 5 | 6 | function setProjectIsImpEnd(uint256 _projectId, bool _isImpEnd) external; 7 | 8 | function setBonus( 9 | uint256 _projectId, 10 | uint256 _bonusMultiplier, 11 | uint256 _bonusEndBlock, 12 | uint256 _bonusLockUpBps 13 | ) external; 14 | 15 | function setProject( 16 | uint256 _projectId, 17 | string calldata _name, 18 | uint256 _pubStartBlock, 19 | uint256 _lauStartBlock, 20 | uint256 _impStartBlock 21 | ) external; 22 | 23 | function addProject( 24 | string calldata _name, 25 | uint256 _pubStartBlock, 26 | uint256 _lauStartBlock, 27 | uint256 _impStartBlock, 28 | uint256 _bonusMultiplier, 29 | uint256 _bonusEndBlock, 30 | uint256 _bonusLockUpBps 31 | ) external; 32 | 33 | function addPool( 34 | uint256 _projectId, 35 | uint256 _allocPoint, 36 | address _stakeToken, 37 | bool _withUpdate 38 | ) external; 39 | 40 | function setPool( 41 | uint256 _pid, 42 | uint256 _allocPoint, 43 | bool _withUpdate 44 | ) external; 45 | 46 | function addCashPool( 47 | uint256 _cashTotal, 48 | address _cashToken, 49 | uint256 _startBlock, 50 | uint256 _endBlock 51 | ) external; 52 | 53 | function setCashPool( 54 | uint256 _pid, 55 | uint256 _cashTotal, 56 | address _cashToken, 57 | uint256 _startBlock, 58 | uint256 _endBlock 59 | ) external; 60 | 61 | function pendingCheck(uint256 _pid, address _user) external view returns (uint256); 62 | 63 | function updatePool(uint256 _pid) external; 64 | 65 | function deposit(address _for, uint256 _pid, uint256 _amount) external; 66 | 67 | function withdraw(address _for, uint256 _pid, uint256 _amount) external; 68 | 69 | function withdrawAll(address _for, uint256 _pid) external; 70 | 71 | function harvest(uint256 _pid) external; 72 | 73 | function depositCheckToCashPool(address _for, uint256 _pid, uint256 _amount) external; 74 | 75 | function cashCheck(uint256 _pid) external; 76 | } -------------------------------------------------------------------------------- /contracts/protocol/interfaces/IWETH.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.0; 2 | 3 | interface IWETH { 4 | function deposit() external payable; 5 | function transfer(address to, uint256 value) external returns (bool); 6 | function withdraw(uint256) external; 7 | } 8 | -------------------------------------------------------------------------------- /contracts/protocol/mock/MockDai.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.6.0; 2 | 3 | import '@openzeppelin/contracts/token/ERC20/ERC20Burnable.sol'; 4 | import "@openzeppelin/contracts/access/Ownable.sol"; 5 | 6 | contract MockDai is ERC20Burnable, Ownable { 7 | 8 | constructor() public ERC20('DAI', 'DAI') { 9 | _mint(msg.sender, 10000000 * 10**18); 10 | } 11 | 12 | /** 13 | * @notice Ownable mints dino cash to a recipient 14 | * @param recipient_ The address of recipient 15 | * @param amount_ The amount of dino cash to mint to 16 | * @return whether the process has been done 17 | */ 18 | function mint(address recipient_, uint256 amount_) 19 | public 20 | onlyOwner 21 | returns (bool) 22 | { 23 | uint256 balanceBefore = balanceOf(recipient_); 24 | _mint(recipient_, amount_); 25 | uint256 balanceAfter = balanceOf(recipient_); 26 | 27 | return balanceAfter > balanceBefore; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /contracts/protocol/mock/MockERC20.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.6.0; 2 | 3 | import '@openzeppelin/contracts/token/ERC20/ERC20Burnable.sol'; 4 | import "@openzeppelin/contracts/access/Ownable.sol"; 5 | 6 | contract MockERC20 is ERC20Burnable, Ownable { 7 | 8 | constructor(string memory _name, string memory _symbol, uint256 _totalSupply) ERC20(_name, _symbol) public { 9 | _mint(msg.sender, _totalSupply); 10 | } 11 | 12 | /** 13 | * @notice Ownable mints dino cash to a recipient 14 | * @param recipient_ The address of recipient 15 | * @param amount_ The amount of dino cash to mint to 16 | * @return whether the process has been done 17 | */ 18 | function mint(address recipient_, uint256 amount_) 19 | public 20 | onlyOwner 21 | returns (bool) 22 | { 23 | uint256 balanceBefore = balanceOf(recipient_); 24 | _mint(recipient_, amount_); 25 | uint256 balanceAfter = balanceOf(recipient_); 26 | 27 | return balanceAfter > balanceBefore; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /contracts/protocol/mock/MockWBNB.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.6.6; 2 | 3 | import "../interfaces/IWETH.sol"; 4 | 5 | // Copyright (C) 2015, 2016, 2017 Dapphub 6 | 7 | // This program is free software: you can redistribute it and/or modify 8 | // it under the terms of the GNU General Public License as published by 9 | // the Free Software Foundation, either version 3 of the License, or 10 | // (at your option) any later version. 11 | 12 | // This program is distributed in the hope that it will be useful, 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | // GNU General Public License for more details. 16 | 17 | // You should have received a copy of the GNU General Public License 18 | // along with this program. If not, see . 19 | 20 | // pragma solidity ^0.4.18; 21 | 22 | contract MockWBNB is IWETH { 23 | string public name = "Wrapped BNB"; 24 | string public symbol = "WBNB"; 25 | uint8 public decimals = 18; 26 | 27 | event Approval(address indexed src, address indexed guy, uint256 wad); 28 | event Transfer(address indexed src, address indexed dst, uint256 wad); 29 | event Deposit(address indexed dst, uint256 wad); 30 | event Withdrawal(address indexed src, uint256 wad); 31 | 32 | mapping(address => uint256) public balanceOf; 33 | mapping(address => mapping(address => uint256)) public allowance; 34 | 35 | receive() external payable { 36 | deposit(); 37 | } 38 | 39 | function deposit() override public payable { 40 | balanceOf[msg.sender] += msg.value; 41 | emit Deposit(msg.sender, msg.value); 42 | } 43 | 44 | function withdraw(uint256 wad) override public { 45 | require(balanceOf[msg.sender] >= wad); 46 | balanceOf[msg.sender] -= wad; 47 | msg.sender.transfer(wad); 48 | emit Withdrawal(msg.sender, wad); 49 | } 50 | 51 | // For testing purpose only 52 | function mint(address guy, uint256 wad) public { 53 | balanceOf[guy] += wad; 54 | } 55 | 56 | function totalSupply() public view returns (uint256) { 57 | return address(this).balance; 58 | } 59 | 60 | function approve(address guy, uint256 wad) public returns (bool) { 61 | allowance[msg.sender][guy] = wad; 62 | emit Approval(msg.sender, guy, wad); 63 | return true; 64 | } 65 | 66 | function transfer(address dst, uint256 wad) override public returns (bool) { 67 | return transferFrom(msg.sender, dst, wad); 68 | } 69 | 70 | function transferFrom( 71 | address src, 72 | address dst, 73 | uint256 wad 74 | ) public returns (bool) { 75 | require(balanceOf[src] >= wad); 76 | 77 | if (src != msg.sender && allowance[src][msg.sender] != uint256(-1)) { 78 | require(allowance[src][msg.sender] >= wad); 79 | allowance[src][msg.sender] -= wad; 80 | } 81 | 82 | balanceOf[src] -= wad; 83 | balanceOf[dst] += wad; 84 | 85 | emit Transfer(src, dst, wad); 86 | 87 | return true; 88 | } 89 | } 90 | 91 | /* 92 | GNU GENERAL PUBLIC LICENSE 93 | Version 3, 29 June 2007 94 | 95 | Copyright (C) 2007 Free Software Foundation, Inc. 96 | Everyone is permitted to copy and distribute verbatim copies 97 | of this license document, but changing it is not allowed. 98 | 99 | Preamble 100 | 101 | The GNU General Public License is a free, copyleft license for 102 | software and other kinds of works. 103 | 104 | The licenses for most software and other practical works are designed 105 | to take away your freedom to share and change the works. By contrast, 106 | the GNU General Public License is intended to guarantee your freedom to 107 | share and change all versions of a program--to make sure it remains free 108 | software for all its users. We, the Free Software Foundation, use the 109 | GNU General Public License for most of our software; it applies also to 110 | any other work released this way by its authors. You can apply it to 111 | your programs, too. 112 | 113 | When we speak of free software, we are referring to freedom, not 114 | price. Our General Public Licenses are designed to make sure that you 115 | have the freedom to distribute copies of free software (and charge for 116 | them if you wish), that you receive source code or can get it if you 117 | want it, that you can change the software or use pieces of it in new 118 | free programs, and that you know you can do these things. 119 | 120 | To protect your rights, we need to prevent others from denying you 121 | these rights or asking you to surrender the rights. Therefore, you have 122 | certain responsibilities if you distribute copies of the software, or if 123 | you modify it: responsibilities to respect the freedom of others. 124 | 125 | For example, if you distribute copies of such a program, whether 126 | gratis or for a fee, you must pass on to the recipients the same 127 | freedoms that you received. You must make sure that they, too, receive 128 | or can get the source code. And you must show them these terms so they 129 | know their rights. 130 | 131 | Developers that use the GNU GPL protect your rights with two steps: 132 | (1) assert copyright on the software, and (2) offer you this License 133 | giving you legal permission to copy, distribute and/or modify it. 134 | 135 | For the developers' and authors' protection, the GPL clearly explains 136 | that there is no warranty for this free software. For both users' and 137 | authors' sake, the GPL requires that modified versions be marked as 138 | changed, so that their problems will not be attributed erroneously to 139 | authors of previous versions. 140 | 141 | Some devices are designed to deny users access to install or run 142 | modified versions of the software inside them, although the manufacturer 143 | can do so. This is fundamentally incompatible with the aim of 144 | protecting users' freedom to change the software. The systematic 145 | pattern of such abuse occurs in the area of products for individuals to 146 | use, which is precisely where it is most unacceptable. Therefore, we 147 | have designed this version of the GPL to prohibit the practice for those 148 | products. If such problems arise substantially in other domains, we 149 | stand ready to extend this provision to those domains in future versions 150 | of the GPL, as needed to protect the freedom of users. 151 | 152 | Finally, every program is threatened constantly by software patents. 153 | States should not allow patents to restrict development and use of 154 | software on general-purpose computers, but in those that do, we wish to 155 | avoid the special danger that patents applied to a free program could 156 | make it effectively proprietary. To prevent this, the GPL assures that 157 | patents cannot be used to render the program non-free. 158 | 159 | The precise terms and conditions for copying, distribution and 160 | modification follow. 161 | 162 | TERMS AND CONDITIONS 163 | 164 | 0. Definitions. 165 | 166 | "This License" refers to version 3 of the GNU General Public License. 167 | 168 | "Copyright" also means copyright-like laws that apply to other kinds of 169 | works, such as semiconductor masks. 170 | 171 | "The Program" refers to any copyrightable work licensed under this 172 | License. Each licensee is addressed as "you". "Licensees" and 173 | "recipients" may be individuals or organizations. 174 | 175 | To "modify" a work means to copy from or adapt all or part of the work 176 | in a fashion requiring copyright permission, other than the making of an 177 | exact copy. The resulting work is called a "modified version" of the 178 | earlier work or a work "based on" the earlier work. 179 | 180 | A "covered work" means either the unmodified Program or a work based 181 | on the Program. 182 | 183 | To "propagate" a work means to do anything with it that, without 184 | permission, would make you directly or secondarily liable for 185 | infringement under applicable copyright law, except executing it on a 186 | computer or modifying a private copy. Propagation includes copying, 187 | distribution (with or without modification), making available to the 188 | public, and in some countries other activities as well. 189 | 190 | To "convey" a work means any kind of propagation that enables other 191 | parties to make or receive copies. Mere interaction with a user through 192 | a computer network, with no transfer of a copy, is not conveying. 193 | 194 | An interactive user interface displays "Appropriate Legal Notices" 195 | to the extent that it includes a convenient and prominently visible 196 | feature that (1) displays an appropriate copyright notice, and (2) 197 | tells the user that there is no warranty for the work (except to the 198 | extent that warranties are provided), that licensees may convey the 199 | work under this License, and how to view a copy of this License. If 200 | the interface presents a list of user commands or options, such as a 201 | menu, a prominent item in the list meets this criterion. 202 | 203 | 1. Source Code. 204 | 205 | The "source code" for a work means the preferred form of the work 206 | for making modifications to it. "Object code" means any non-source 207 | form of a work. 208 | 209 | A "Standard Interface" means an interface that either is an official 210 | standard defined by a recognized standards body, or, in the case of 211 | interfaces specified for a particular programming language, one that 212 | is widely used among developers working in that language. 213 | 214 | The "System Libraries" of an executable work include anything, other 215 | than the work as a whole, that (a) is included in the normal form of 216 | packaging a Major Component, but which is not part of that Major 217 | Component, and (b) serves only to enable use of the work with that 218 | Major Component, or to implement a Standard Interface for which an 219 | implementation is available to the public in source code form. A 220 | "Major Component", in this context, means a major essential component 221 | (kernel, window system, and so on) of the specific operating system 222 | (if any) on which the executable work runs, or a compiler used to 223 | produce the work, or an object code interpreter used to run it. 224 | 225 | The "Corresponding Source" for a work in object code form means all 226 | the source code needed to generate, install, and (for an executable 227 | work) run the object code and to modify the work, including scripts to 228 | control those activities. However, it does not include the work's 229 | System Libraries, or general-purpose tools or generally available free 230 | programs which are used unmodified in performing those activities but 231 | which are not part of the work. For example, Corresponding Source 232 | includes interface definition files associated with source files for 233 | the work, and the source code for shared libraries and dynamically 234 | linked subprograms that the work is specifically designed to require, 235 | such as by intimate data communication or control flow between those 236 | subprograms and other parts of the work. 237 | 238 | The Corresponding Source need not include anything that users 239 | can regenerate automatically from other parts of the Corresponding 240 | Source. 241 | 242 | The Corresponding Source for a work in source code form is that 243 | same work. 244 | 245 | 2. Basic Permissions. 246 | 247 | All rights granted under this License are granted for the term of 248 | copyright on the Program, and are irrevocable provided the stated 249 | conditions are met. This License explicitly affirms your unlimited 250 | permission to run the unmodified Program. The output from running a 251 | covered work is covered by this License only if the output, given its 252 | content, constitutes a covered work. This License acknowledges your 253 | rights of fair use or other equivalent, as provided by copyright law. 254 | 255 | You may make, run and propagate covered works that you do not 256 | convey, without conditions so long as your license otherwise remains 257 | in force. You may convey covered works to others for the sole purpose 258 | of having them make modifications exclusively for you, or provide you 259 | with facilities for running those works, provided that you comply with 260 | the terms of this License in conveying all material for which you do 261 | not control copyright. Those thus making or running the covered works 262 | for you must do so exclusively on your behalf, under your direction 263 | and control, on terms that prohibit them from making any copies of 264 | your copyrighted material outside their relationship with you. 265 | 266 | Conveying under any other circumstances is permitted solely under 267 | the conditions stated below. Sublicensing is not allowed; section 10 268 | makes it unnecessary. 269 | 270 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 271 | 272 | No covered work shall be deemed part of an effective technological 273 | measure under any applicable law fulfilling obligations under article 274 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 275 | similar laws prohibiting or restricting circumvention of such 276 | measures. 277 | 278 | When you convey a covered work, you waive any legal power to forbid 279 | circumvention of technological measures to the extent such circumvention 280 | is effected by exercising rights under this License with respect to 281 | the covered work, and you disclaim any intention to limit operation or 282 | modification of the work as a means of enforcing, against the work's 283 | users, your or third parties' legal rights to forbid circumvention of 284 | technological measures. 285 | 286 | 4. Conveying Verbatim Copies. 287 | 288 | You may convey verbatim copies of the Program's source code as you 289 | receive it, in any medium, provided that you conspicuously and 290 | appropriately publish on each copy an appropriate copyright notice; 291 | keep intact all notices stating that this License and any 292 | non-permissive terms added in accord with section 7 apply to the code; 293 | keep intact all notices of the absence of any warranty; and give all 294 | recipients a copy of this License along with the Program. 295 | 296 | You may charge any price or no price for each copy that you convey, 297 | and you may offer support or warranty protection for a fee. 298 | 299 | 5. Conveying Modified Source Versions. 300 | 301 | You may convey a work based on the Program, or the modifications to 302 | produce it from the Program, in the form of source code under the 303 | terms of section 4, provided that you also meet all of these conditions: 304 | 305 | a) The work must carry prominent notices stating that you modified 306 | it, and giving a relevant date. 307 | 308 | b) The work must carry prominent notices stating that it is 309 | released under this License and any conditions added under section 310 | 7. This requirement modifies the requirement in section 4 to 311 | "keep intact all notices". 312 | 313 | c) You must license the entire work, as a whole, under this 314 | License to anyone who comes into possession of a copy. This 315 | License will therefore apply, along with any applicable section 7 316 | additional terms, to the whole of the work, and all its parts, 317 | regardless of how they are packaged. This License gives no 318 | permission to license the work in any other way, but it does not 319 | invalidate such permission if you have separately received it. 320 | 321 | d) If the work has interactive user interfaces, each must display 322 | Appropriate Legal Notices; however, if the Program has interactive 323 | interfaces that do not display Appropriate Legal Notices, your 324 | work need not make them do so. 325 | 326 | A compilation of a covered work with other separate and independent 327 | works, which are not by their nature extensions of the covered work, 328 | and which are not combined with it such as to form a larger program, 329 | in or on a volume of a storage or distribution medium, is called an 330 | "aggregate" if the compilation and its resulting copyright are not 331 | used to limit the access or legal rights of the compilation's users 332 | beyond what the individual works permit. Inclusion of a covered work 333 | in an aggregate does not cause this License to apply to the other 334 | parts of the aggregate. 335 | 336 | 6. Conveying Non-Source Forms. 337 | 338 | You may convey a covered work in object code form under the terms 339 | of sections 4 and 5, provided that you also convey the 340 | machine-readable Corresponding Source under the terms of this License, 341 | in one of these ways: 342 | 343 | a) Convey the object code in, or embodied in, a physical product 344 | (including a physical distribution medium), accompanied by the 345 | Corresponding Source fixed on a durable physical medium 346 | customarily used for software interchange. 347 | 348 | b) Convey the object code in, or embodied in, a physical product 349 | (including a physical distribution medium), accompanied by a 350 | written offer, valid for at least three years and valid for as 351 | long as you offer spare parts or customer support for that product 352 | model, to give anyone who possesses the object code either (1) a 353 | copy of the Corresponding Source for all the software in the 354 | product that is covered by this License, on a durable physical 355 | medium customarily used for software interchange, for a price no 356 | more than your reasonable cost of physically performing this 357 | conveying of source, or (2) access to copy the 358 | Corresponding Source from a network server at no charge. 359 | 360 | c) Convey individual copies of the object code with a copy of the 361 | written offer to provide the Corresponding Source. This 362 | alternative is allowed only occasionally and noncommercially, and 363 | only if you received the object code with such an offer, in accord 364 | with subsection 6b. 365 | 366 | d) Convey the object code by offering access from a designated 367 | place (gratis or for a charge), and offer equivalent access to the 368 | Corresponding Source in the same way through the same place at no 369 | further charge. You need not require recipients to copy the 370 | Corresponding Source along with the object code. If the place to 371 | copy the object code is a network server, the Corresponding Source 372 | may be on a different server (operated by you or a third party) 373 | that supports equivalent copying facilities, provided you maintain 374 | clear directions next to the object code saying where to find the 375 | Corresponding Source. Regardless of what server hosts the 376 | Corresponding Source, you remain obligated to ensure that it is 377 | available for as long as needed to satisfy these requirements. 378 | 379 | e) Convey the object code using peer-to-peer transmission, provided 380 | you inform other peers where the object code and Corresponding 381 | Source of the work are being offered to the general public at no 382 | charge under subsection 6d. 383 | 384 | A separable portion of the object code, whose source code is excluded 385 | from the Corresponding Source as a System Library, need not be 386 | included in conveying the object code work. 387 | 388 | A "User Product" is either (1) a "consumer product", which means any 389 | tangible personal property which is normally used for personal, family, 390 | or household purposes, or (2) anything designed or sold for incorporation 391 | into a dwelling. In determining whether a product is a consumer product, 392 | doubtful cases shall be resolved in favor of coverage. For a particular 393 | product received by a particular user, "normally used" refers to a 394 | typical or common use of that class of product, regardless of the status 395 | of the particular user or of the way in which the particular user 396 | actually uses, or expects or is expected to use, the product. A product 397 | is a consumer product regardless of whether the product has substantial 398 | commercial, industrial or non-consumer uses, unless such uses represent 399 | the only significant mode of use of the product. 400 | 401 | "Installation Information" for a User Product means any methods, 402 | procedures, authorization keys, or other information required to install 403 | and execute modified versions of a covered work in that User Product from 404 | a modified version of its Corresponding Source. The information must 405 | suffice to ensure that the continued functioning of the modified object 406 | code is in no case prevented or interfered with solely because 407 | modification has been made. 408 | 409 | If you convey an object code work under this section in, or with, or 410 | specifically for use in, a User Product, and the conveying occurs as 411 | part of a transaction in which the right of possession and use of the 412 | User Product is transferred to the recipient in perpetuity or for a 413 | fixed term (regardless of how the transaction is characterized), the 414 | Corresponding Source conveyed under this section must be accompanied 415 | by the Installation Information. But this requirement does not apply 416 | if neither you nor any third party retains the ability to install 417 | modified object code on the User Product (for example, the work has 418 | been installed in ROM). 419 | 420 | The requirement to provide Installation Information does not include a 421 | requirement to continue to provide support service, warranty, or updates 422 | for a work that has been modified or installed by the recipient, or for 423 | the User Product in which it has been modified or installed. Access to a 424 | network may be denied when the modification itself materially and 425 | adversely affects the operation of the network or violates the rules and 426 | protocols for communication across the network. 427 | 428 | Corresponding Source conveyed, and Installation Information provided, 429 | in accord with this section must be in a format that is publicly 430 | documented (and with an implementation available to the public in 431 | source code form), and must require no special password or key for 432 | unpacking, reading or copying. 433 | 434 | 7. Additional Terms. 435 | 436 | "Additional permissions" are terms that supplement the terms of this 437 | License by making exceptions from one or more of its conditions. 438 | Additional permissions that are applicable to the entire Program shall 439 | be treated as though they were included in this License, to the extent 440 | that they are valid under applicable law. If additional permissions 441 | apply only to part of the Program, that part may be used separately 442 | under those permissions, but the entire Program remains governed by 443 | this License without regard to the additional permissions. 444 | 445 | When you convey a copy of a covered work, you may at your option 446 | remove any additional permissions from that copy, or from any part of 447 | it. (Additional permissions may be written to require their own 448 | removal in certain cases when you modify the work.) You may place 449 | additional permissions on material, added by you to a covered work, 450 | for which you have or can give appropriate copyright permission. 451 | 452 | Notwithstanding any other provision of this License, for material you 453 | add to a covered work, you may (if authorized by the copyright holders of 454 | that material) supplement the terms of this License with terms: 455 | 456 | a) Disclaiming warranty or limiting liability differently from the 457 | terms of sections 15 and 16 of this License; or 458 | 459 | b) Requiring preservation of specified reasonable legal notices or 460 | author attributions in that material or in the Appropriate Legal 461 | Notices displayed by works containing it; or 462 | 463 | c) Prohibiting misrepresentation of the origin of that material, or 464 | requiring that modified versions of such material be marked in 465 | reasonable ways as different from the original version; or 466 | 467 | d) Limiting the use for publicity purposes of names of licensors or 468 | authors of the material; or 469 | 470 | e) Declining to grant rights under trademark law for use of some 471 | trade names, trademarks, or service marks; or 472 | 473 | f) Requiring indemnification of licensors and authors of that 474 | material by anyone who conveys the material (or modified versions of 475 | it) with contractual assumptions of liability to the recipient, for 476 | any liability that these contractual assumptions directly impose on 477 | those licensors and authors. 478 | 479 | All other non-permissive additional terms are considered "further 480 | restrictions" within the meaning of section 10. If the Program as you 481 | received it, or any part of it, contains a notice stating that it is 482 | governed by this License along with a term that is a further 483 | restriction, you may remove that term. If a license document contains 484 | a further restriction but permits relicensing or conveying under this 485 | License, you may add to a covered work material governed by the terms 486 | of that license document, provided that the further restriction does 487 | not survive such relicensing or conveying. 488 | 489 | If you add terms to a covered work in accord with this section, you 490 | must place, in the relevant source files, a statement of the 491 | additional terms that apply to those files, or a notice indicating 492 | where to find the applicable terms. 493 | 494 | Additional terms, permissive or non-permissive, may be stated in the 495 | form of a separately written license, or stated as exceptions; 496 | the above requirements apply either way. 497 | 498 | 8. Termination. 499 | 500 | You may not propagate or modify a covered work except as expressly 501 | provided under this License. Any attempt otherwise to propagate or 502 | modify it is void, and will automatically terminate your rights under 503 | this License (including any patent licenses granted under the third 504 | paragraph of section 11). 505 | 506 | However, if you cease all violation of this License, then your 507 | license from a particular copyright holder is reinstated (a) 508 | provisionally, unless and until the copyright holder explicitly and 509 | finally terminates your license, and (b) permanently, if the copyright 510 | holder fails to notify you of the violation by some reasonable means 511 | prior to 60 days after the cessation. 512 | 513 | Moreover, your license from a particular copyright holder is 514 | reinstated permanently if the copyright holder notifies you of the 515 | violation by some reasonable means, this is the first time you have 516 | received notice of violation of this License (for any work) from that 517 | copyright holder, and you cure the violation prior to 30 days after 518 | your receipt of the notice. 519 | 520 | Termination of your rights under this section does not terminate the 521 | licenses of parties who have received copies or rights from you under 522 | this License. If your rights have been terminated and not permanently 523 | reinstated, you do not qualify to receive new licenses for the same 524 | material under section 10. 525 | 526 | 9. Acceptance Not Required for Having Copies. 527 | 528 | You are not required to accept this License in order to receive or 529 | run a copy of the Program. Ancillary propagation of a covered work 530 | occurring solely as a consequence of using peer-to-peer transmission 531 | to receive a copy likewise does not require acceptance. However, 532 | nothing other than this License grants you permission to propagate or 533 | modify any covered work. These actions infringe copyright if you do 534 | not accept this License. Therefore, by modifying or propagating a 535 | covered work, you indicate your acceptance of this License to do so. 536 | 537 | 10. Automatic Licensing of Downstream Recipients. 538 | 539 | Each time you convey a covered work, the recipient automatically 540 | receives a license from the original licensors, to run, modify and 541 | propagate that work, subject to this License. You are not responsible 542 | for enforcing compliance by third parties with this License. 543 | 544 | An "entity transaction" is a transaction transferring control of an 545 | organization, or substantially all assets of one, or subdividing an 546 | organization, or merging organizations. If propagation of a covered 547 | work results from an entity transaction, each party to that 548 | transaction who receives a copy of the work also receives whatever 549 | licenses to the work the party's predecessor in interest had or could 550 | give under the previous paragraph, plus a right to possession of the 551 | Corresponding Source of the work from the predecessor in interest, if 552 | the predecessor has it or can get it with reasonable efforts. 553 | 554 | You may not impose any further restrictions on the exercise of the 555 | rights granted or affirmed under this License. For example, you may 556 | not impose a license fee, royalty, or other charge for exercise of 557 | rights granted under this License, and you may not initiate litigation 558 | (including a cross-claim or counterclaim in a lawsuit) alleging that 559 | any patent claim is infringed by making, using, selling, offering for 560 | sale, or importing the Program or any portion of it. 561 | 562 | 11. Patents. 563 | 564 | A "contributor" is a copyright holder who authorizes use under this 565 | License of the Program or a work on which the Program is based. The 566 | work thus licensed is called the contributor's "contributor version". 567 | 568 | A contributor's "essential patent claims" are all patent claims 569 | owned or controlled by the contributor, whether already acquired or 570 | hereafter acquired, that would be infringed by some manner, permitted 571 | by this License, of making, using, or selling its contributor version, 572 | but do not include claims that would be infringed only as a 573 | consequence of further modification of the contributor version. For 574 | purposes of this definition, "control" includes the right to grant 575 | patent sublicenses in a manner consistent with the requirements of 576 | this License. 577 | 578 | Each contributor grants you a non-exclusive, worldwide, royalty-free 579 | patent license under the contributor's essential patent claims, to 580 | make, use, sell, offer for sale, import and otherwise run, modify and 581 | propagate the contents of its contributor version. 582 | 583 | In the following three paragraphs, a "patent license" is any express 584 | agreement or commitment, however denominated, not to enforce a patent 585 | (such as an express permission to practice a patent or covenant not to 586 | sue for patent infringement). To "grant" such a patent license to a 587 | party means to make such an agreement or commitment not to enforce a 588 | patent against the party. 589 | 590 | If you convey a covered work, knowingly relying on a patent license, 591 | and the Corresponding Source of the work is not available for anyone 592 | to copy, free of charge and under the terms of this License, through a 593 | publicly available network server or other readily accessible means, 594 | then you must either (1) cause the Corresponding Source to be so 595 | available, or (2) arrange to deprive yourself of the benefit of the 596 | patent license for this particular work, or (3) arrange, in a manner 597 | consistent with the requirements of this License, to extend the patent 598 | license to downstream recipients. "Knowingly relying" means you have 599 | actual knowledge that, but for the patent license, your conveying the 600 | covered work in a country, or your recipient's use of the covered work 601 | in a country, would infringe one or more identifiable patents in that 602 | country that you have reason to believe are valid. 603 | 604 | If, pursuant to or in connection with a single transaction or 605 | arrangement, you convey, or propagate by procuring conveyance of, a 606 | covered work, and grant a patent license to some of the parties 607 | receiving the covered work authorizing them to use, propagate, modify 608 | or convey a specific copy of the covered work, then the patent license 609 | you grant is automatically extended to all recipients of the covered 610 | work and works based on it. 611 | 612 | A patent license is "discriminatory" if it does not include within 613 | the scope of its coverage, prohibits the exercise of, or is 614 | conditioned on the non-exercise of one or more of the rights that are 615 | specifically granted under this License. You may not convey a covered 616 | work if you are a party to an arrangement with a third party that is 617 | in the business of distributing software, under which you make payment 618 | to the third party based on the extent of your activity of conveying 619 | the work, and under which the third party grants, to any of the 620 | parties who would receive the covered work from you, a discriminatory 621 | patent license (a) in connection with copies of the covered work 622 | conveyed by you (or copies made from those copies), or (b) primarily 623 | for and in connection with specific products or compilations that 624 | contain the covered work, unless you entered into that arrangement, 625 | or that patent license was granted, prior to 28 March 2007. 626 | 627 | Nothing in this License shall be construed as excluding or limiting 628 | any implied license or other defenses to infringement that may 629 | otherwise be available to you under applicable patent law. 630 | 631 | 12. No Surrender of Others' Freedom. 632 | 633 | If conditions are imposed on you (whether by court order, agreement or 634 | otherwise) that contradict the conditions of this License, they do not 635 | excuse you from the conditions of this License. If you cannot convey a 636 | covered work so as to satisfy simultaneously your obligations under this 637 | License and any other pertinent obligations, then as a consequence you may 638 | not convey it at all. For example, if you agree to terms that obligate you 639 | to collect a royalty for further conveying from those to whom you convey 640 | the Program, the only way you could satisfy both those terms and this 641 | License would be to refrain entirely from conveying the Program. 642 | 643 | 13. Use with the GNU Affero General Public License. 644 | 645 | Notwithstanding any other provision of this License, you have 646 | permission to link or combine any covered work with a work licensed 647 | under version 3 of the GNU Affero General Public License into a single 648 | combined work, and to convey the resulting work. The terms of this 649 | License will continue to apply to the part which is the covered work, 650 | but the special requirements of the GNU Affero General Public License, 651 | section 13, concerning interaction through a network will apply to the 652 | combination as such. 653 | 654 | 14. Revised Versions of this License. 655 | 656 | The Free Software Foundation may publish revised and/or new versions of 657 | the GNU General Public License from time to time. Such new versions will 658 | be similar in spirit to the present version, but may differ in detail to 659 | address new problems or concerns. 660 | 661 | Each version is given a distinguishing version number. If the 662 | Program specifies that a certain numbered version of the GNU General 663 | Public License "or any later version" applies to it, you have the 664 | option of following the terms and conditions either of that numbered 665 | version or of any later version published by the Free Software 666 | Foundation. If the Program does not specify a version number of the 667 | GNU General Public License, you may choose any version ever published 668 | by the Free Software Foundation. 669 | 670 | If the Program specifies that a proxy can decide which future 671 | versions of the GNU General Public License can be used, that proxy's 672 | public statement of acceptance of a version permanently authorizes you 673 | to choose that version for the Program. 674 | 675 | Later license versions may give you additional or different 676 | permissions. However, no additional obligations are imposed on any 677 | author or copyright holder as a result of your choosing to follow a 678 | later version. 679 | 680 | 15. Disclaimer of Warranty. 681 | 682 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 683 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 684 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 685 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 686 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 687 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 688 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 689 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 690 | 691 | 16. Limitation of Liability. 692 | 693 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 694 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 695 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 696 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 697 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 698 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 699 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 700 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 701 | SUCH DAMAGES. 702 | 703 | 17. Interpretation of Sections 15 and 16. 704 | 705 | If the disclaimer of warranty and limitation of liability provided 706 | above cannot be given local legal effect according to their terms, 707 | reviewing courts shall apply local law that most closely approximates 708 | an absolute waiver of all civil liability in connection with the 709 | Program, unless a warranty or assumption of liability accompanies a 710 | copy of the Program in return for a fee. 711 | 712 | END OF TERMS AND CONDITIONS 713 | 714 | How to Apply These Terms to Your New Programs 715 | 716 | If you develop a new program, and you want it to be of the greatest 717 | possible use to the public, the best way to achieve this is to make it 718 | free software which everyone can redistribute and change under these terms. 719 | 720 | To do so, attach the following notices to the program. It is safest 721 | to attach them to the start of each source file to most effectively 722 | state the exclusion of warranty; and each file should have at least 723 | the "copyright" line and a pointer to where the full notice is found. 724 | 725 | 726 | Copyright (C) 727 | 728 | This program is free software: you can redistribute it and/or modify 729 | it under the terms of the GNU General Public License as published by 730 | the Free Software Foundation, either version 3 of the License, or 731 | (at your option) any later version. 732 | 733 | This program is distributed in the hope that it will be useful, 734 | but WITHOUT ANY WARRANTY; without even the implied warranty of 735 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 736 | GNU General Public License for more details. 737 | 738 | You should have received a copy of the GNU General Public License 739 | along with this program. If not, see . 740 | 741 | Also add information on how to contact you by electronic and paper mail. 742 | 743 | If the program does terminal interaction, make it output a short 744 | notice like this when it starts in an interactive mode: 745 | 746 | Copyright (C) 747 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 748 | This is free software, and you are welcome to redistribute it 749 | under certain conditions; type `show c' for details. 750 | 751 | The hypothetical commands `show w' and `show c' should show the appropriate 752 | parts of the General Public License. Of course, your program's commands 753 | might be different; for a GUI interface, you would use an "about box". 754 | 755 | You should also get your employer (if you work as a programmer) or school, 756 | if any, to sign a "copyright disclaimer" for the program, if necessary. 757 | For more information on this, and how to apply and follow the GNU GPL, see 758 | . 759 | 760 | The GNU General Public License does not permit incorporating your program 761 | into proprietary programs. If your program is a subroutine library, you 762 | may consider it more useful to permit linking proprietary applications with 763 | the library. If this is what you want to do, use the GNU Lesser General 764 | Public License instead of this License. But first, please read 765 | . 766 | 767 | */ 768 | -------------------------------------------------------------------------------- /contracts/utils/SafeToken.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.6.6; 2 | 3 | interface ERC20Interface { 4 | function balanceOf(address user) external view returns (uint256); 5 | } 6 | 7 | library SafeToken { 8 | function myBalance(address token) internal view returns (uint256) { 9 | return ERC20Interface(token).balanceOf(address(this)); 10 | } 11 | 12 | function balanceOf(address token, address user) internal view returns (uint256) { 13 | return ERC20Interface(token).balanceOf(user); 14 | } 15 | 16 | function safeApprove(address token, address to, uint256 value) internal { 17 | // bytes4(keccak256(bytes('approve(address,uint256)'))); 18 | (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x095ea7b3, to, value)); 19 | require(success && (data.length == 0 || abi.decode(data, (bool))), "!safeApprove"); 20 | } 21 | 22 | function safeTransfer(address token, address to, uint256 value) internal { 23 | // bytes4(keccak256(bytes('transfer(address,uint256)'))); 24 | (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0xa9059cbb, to, value)); 25 | require(success && (data.length == 0 || abi.decode(data, (bool))), "!safeTransfer"); 26 | } 27 | 28 | function safeTransferFrom(address token, address from, address to, uint256 value) internal { 29 | // bytes4(keccak256(bytes('transferFrom(address,address,uint256)'))); 30 | (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x23b872dd, from, to, value)); 31 | require(success && (data.length == 0 || abi.decode(data, (bool))), "!safeTransferFrom"); 32 | } 33 | 34 | function safeTransferETH(address to, uint256 value) internal { 35 | // solhint-disable-next-line no-call-value 36 | (bool success, ) = to.call{value: value}(new bytes(0)); 37 | require(success, "!safeTransferETH"); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /migrations/01_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require("Migrations"); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /migrations/02_pancakeswap_initial.js: -------------------------------------------------------------------------------- 1 | const Artifactor = require('@truffle/artifactor'); 2 | const artifactor = new Artifactor(`${__dirname}/../build/contracts`); 3 | 4 | const InitialArtifacts = { 5 | UniswapV2Factory: require('@uniswap/v2-core/build/UniswapV2Factory.json'), 6 | // UniswapV2Router02: require('@uniswap/v2-periphery/build/UniswapV2Router02.json'), 7 | UniswapV2Pair: require('@uniswap/v2-core/build/UniswapV2Pair.json'), 8 | }; 9 | 10 | module.exports = async function (deployer) { 11 | for await ([contractName, legacyArtifact] of Object.entries(InitialArtifacts)) { 12 | await artifactor.save({ 13 | contractName, 14 | ...legacyArtifact, 15 | }); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /migrations/03_deploy_pancakeswap.js: -------------------------------------------------------------------------------- 1 | const UniswapV2Factory = artifacts.require('UniswapV2Factory'); 2 | const UniswapV2Router02 = artifacts.require('UniswapV2Router02'); 3 | const MockWBNB = artifacts.require('MockWBNB'); 4 | const IWBNB = artifacts.require('IWETH'); 5 | const knownContracts = require('./known-contracts.js'); 6 | 7 | module.exports = async (deployer, network, accounts) => { 8 | if (network != 'mainnet') { 9 | let wbnb; 10 | if (!knownContracts.WBNB[network] ) { 11 | await deployer.deploy(MockWBNB); 12 | wbnb = await MockWBNB.deployed(); 13 | } else { 14 | wbnb = await IWBNB.at(knownContracts.WBNB[network]); 15 | } 16 | if (!knownContracts.UniswapV2Router02[network]) { 17 | console.log('Deploying pancakeswap on '+network+' network.'); 18 | await deployer.deploy(UniswapV2Factory, accounts[0]); 19 | const uniswapFactory = await UniswapV2Factory.deployed(); 20 | await deployer.deploy(UniswapV2Router02, uniswapFactory.address, wbnb.address); 21 | } 22 | } 23 | 24 | }; -------------------------------------------------------------------------------- /migrations/04_deploy_token.js: -------------------------------------------------------------------------------- 1 | // ============ Contracts ============ 2 | 3 | const knownContracts = require('./known-contracts'); 4 | // Token 5 | // deployed first 6 | const ForkToken = artifacts.require('ForkToken'); 7 | const CheckToken = artifacts.require('CheckToken'); 8 | const iBNB = artifacts.require('iBNB'); 9 | const iBUSD = artifacts.require('iBUSD'); 10 | const MockWBNB = artifacts.require('MockWBNB'); 11 | const MockDai = artifacts.require('MockDai'); 12 | const IWBNB = artifacts.require('IWETH'); 13 | 14 | const WNativeRelayer = artifacts.require('WNativeRelayer'); 15 | 16 | const conf = require("./conf"); 17 | 18 | // ============ Main Migration ============ 19 | 20 | const migration = async (deployer, network, accounts) => { 21 | await Promise.all([deployToken(deployer, network, accounts)]) 22 | } 23 | 24 | module.exports = migration 25 | 26 | // ============ Deploy Functions ============ 27 | 28 | async function deployToken(deployer, network, accounts) { 29 | const startReleaseBlock = conf.startReleaseBlock[network]; 30 | const endReleaseBlock = conf.endReleaseBlock[network]; 31 | if (network == 'develop') { 32 | await deployer.deploy(ForkToken, startReleaseBlock, endReleaseBlock); 33 | } 34 | await deployer.deploy(CheckToken, startReleaseBlock, endReleaseBlock); 35 | 36 | if (network !== 'mainnet') { 37 | // await deployer.deploy(MockDai); 38 | } 39 | 40 | // const dai = network === 'mainnet' ? await IERC20.at(knownContracts.DAI[network]) : await MockDai.deployed(); 41 | // const wbnb = network === 'mainnet' ? await IWBNB.at(knownContracts.WBNB[network]) : await MockWBNB.deployed(); 42 | 43 | // await deployer.deploy(WNativeRelayer, wbnb.address); 44 | 45 | // wNativeRelayer = await WNativeRelayer.deployed(); 46 | 47 | // await deployer.deploy(iBNB, wbnb.address, wNativeRelayer.address); 48 | // await deployer.deploy(iBUSD, dai.address); 49 | 50 | // ibnb = await iBNB.deployed(); 51 | 52 | // set whitelistedCallers 53 | // await wNativeRelayer.setCallerOk([ibnb.address], true); 54 | } 55 | -------------------------------------------------------------------------------- /migrations/09_deploy_timelock.js: -------------------------------------------------------------------------------- 1 | const Timelock = artifacts.require("Timelock"); 2 | const knownContracts = require('./known-contracts.js'); 3 | 4 | const DAY = 86400; 5 | 6 | module.exports = async (deployer, network, accounts) => { 7 | // return; 8 | 9 | if (!knownContracts.Timelock[network]) { 10 | await deployer.deploy(Timelock, accounts[0], 1 * DAY); 11 | } 12 | 13 | }; -------------------------------------------------------------------------------- /migrations/11_deploy_farm.js: -------------------------------------------------------------------------------- 1 | const ForkToken = artifacts.require('ForkToken'); 2 | const CheckToken = artifacts.require('CheckToken'); 3 | const MockWBNB = artifacts.require('MockWBNB'); 4 | const MockDai = artifacts.require('MockDai'); 5 | 6 | const IDFO = artifacts.require("IDFO"); 7 | 8 | const conf = require("./conf"); 9 | const knownContracts = require('./known-contracts.js'); 10 | 11 | // const {ALPACA_REWARD_PER_BLOCK, START_BLOCK} = require('./pool'); 12 | 13 | module.exports = async (deployer, network, accounts) => { 14 | // return; 15 | const CHECK_REWARD_PER_BLOCK = web3.utils.toWei(conf.CHECK_REWARD_PER_BLOCK_ETHER[network], 'ether'); 16 | const CHECK_START_BLOCK = conf.CHECK_START_BLOCK[network]; 17 | const BONUS_MULTIPLIER = conf.CHECK_BONUS_MULTIPLIER[network]; 18 | const BONUS_END_BLOCK = conf.CHECK_BONUS_END_BLOCK[network]; 19 | const BONUS_LOCK_BPS = conf.CHECK_BONUS_LOCK_BPS[network]; 20 | 21 | const checkToken = knownContracts.CHECK[network] ? await CheckToken.at(knownContracts.CHECK[network]) : await CheckToken.deployed(); 22 | 23 | console.log(">> 1. Deploying IDFO"); 24 | await deployer.deploy(IDFO, checkToken.address, accounts[0], CHECK_REWARD_PER_BLOCK, CHECK_START_BLOCK, 0, 0); 25 | console.log("✅ Done"); 26 | 27 | const farm = await IDFO.deployed(); 28 | 29 | console.log(`>> 1.1 Set IDFO bonus to BONUS_MULTIPLIER: "${BONUS_MULTIPLIER}", BONUS_END_BLOCK: "${BONUS_END_BLOCK}", LOCK_BPS: ${BONUS_LOCK_BPS}`) 30 | await farm.setBonus(BONUS_MULTIPLIER, BONUS_END_BLOCK, BONUS_LOCK_BPS) 31 | console.log("✅ Done"); 32 | }; -------------------------------------------------------------------------------- /migrations/12_add_pool_to_farm.js: -------------------------------------------------------------------------------- 1 | const knownContracts = require('./known-contracts'); 2 | 3 | const ForkToken = artifacts.require('ForkToken'); 4 | const CheckToken = artifacts.require('CheckToken'); 5 | const MockWBNB = artifacts.require('MockWBNB'); 6 | const MockDai = artifacts.require('MockDai'); 7 | const IERC20 = artifacts.require('IERC20'); 8 | const IWBNB = artifacts.require('IWETH'); 9 | 10 | const ForkFarmLaunch = artifacts.require("IDFO"); 11 | 12 | const UniswapV2Factory = artifacts.require('UniswapV2Factory'); 13 | const UniswapV2Router02 = artifacts.require('UniswapV2Router02'); 14 | 15 | // const {ALPACA_REWARD_PER_BLOCK, START_BLOCK} = require('./pool'); 16 | 17 | module.exports = async (deployer, network, accounts) => { 18 | const uniswapRouter = knownContracts.UniswapV2Router02[network] ? await UniswapV2Router02.at(knownContracts.UniswapV2Router02[network]) : await UniswapV2Router02.deployed(); 19 | const uniswapFactory = knownContracts.UniswapV2Factory[network] ? await UniswapV2Factory.at(knownContracts.UniswapV2Factory[network]) : await UniswapV2Factory.deployed(); 20 | 21 | const dai = knownContracts.DAI[network] ? await IERC20.at(knownContracts.DAI[network]) : await MockDai.deployed(); 22 | const wbnb = knownContracts.WBNB[network] ? await IWBNB.at(knownContracts.WBNB[network]) : await MockWBNB.deployed(); 23 | 24 | const checkToken = knownContracts.CHECK[network] ? await CheckToken.at(knownContracts.CHECK[network]) : await CheckToken.deployed(); 25 | const forkToken = knownContracts.FORK[network] ? await ForkToken.at(knownContracts.FORK[network]) : await ForkToken.deployed(); 26 | 27 | let check_wbnb_pair, check_busd_pair; 28 | check_wbnb_pair = await uniswapFactory.getPair(checkToken.address, wbnb.address); 29 | if (check_wbnb_pair == '0x0000000000000000000000000000000000000000') { 30 | await uniswapFactory.createPair(checkToken.address, wbnb.address); 31 | check_wbnb_pair = await uniswapFactory.getPair(checkToken.address, wbnb.address); 32 | } 33 | 34 | check_busd_pair = await uniswapFactory.getPair(checkToken.address, dai.address); 35 | if (check_busd_pair == '0x0000000000000000000000000000000000000000') { 36 | await uniswapFactory.createPair(checkToken.address, dai.address); 37 | check_busd_pair = await uniswapFactory.getPair(checkToken.address, dai.address); 38 | } 39 | 40 | let fork_wbnb_pair, fork_busd_pair; 41 | fork_wbnb_pair = await uniswapFactory.getPair(forkToken.address, wbnb.address); 42 | if (fork_wbnb_pair == '0x0000000000000000000000000000000000000000') { 43 | await uniswapFactory.createPair(forkToken.address, wbnb.address); 44 | fork_wbnb_pair = await uniswapFactory.getPair(forkToken.address, wbnb.address); 45 | } 46 | 47 | fork_busd_pair = await uniswapFactory.getPair(forkToken.address, dai.address); 48 | if (fork_busd_pair == '0x0000000000000000000000000000000000000000') { 49 | await uniswapFactory.createPair(forkToken.address, dai.address); 50 | fork_busd_pair = await uniswapFactory.getPair(forkToken.address, dai.address); 51 | } 52 | 53 | const pools = [{ 54 | alloc_point: '1000', 55 | staking_token_addr: fork_wbnb_pair, 56 | staking_token_name: 'FORK-WBNB-LP' 57 | }, 58 | // { 59 | // alloc_point: '900', 60 | // staking_token_addr: fork_busd_pair, 61 | // staking_token_name: 'FORK-BUSD-LP' 62 | // }, 63 | { 64 | alloc_point: '100', 65 | staking_token_addr: forkToken.address, 66 | staking_token_name: 'FORK' 67 | }, 68 | { 69 | alloc_point: '1000', 70 | staking_token_addr: check_wbnb_pair, 71 | staking_token_name: 'CHECK-WBNB-LP' 72 | }, 73 | // { 74 | // alloc_point: '900', 75 | // staking_token_addr: check_busd_pair, 76 | // staking_token_name: 'CHECK-BUSD-LP' 77 | // }, 78 | { 79 | alloc_point: '100', 80 | staking_token_addr: checkToken.address, 81 | staking_token_name: 'CHECK' 82 | }, 83 | { 84 | alloc_point: '50', 85 | staking_token_addr: dai.address, 86 | staking_token_name: 'BUSD' 87 | } 88 | ]; 89 | forkFarm = await ForkFarmLaunch.deployed(); 90 | // updateMultiplier 91 | for (let i in pools) { 92 | let p = pools[i]; 93 | await forkFarm.add(0, p.alloc_point, p.staking_token_addr, false); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /migrations/13_seed_check_liquidity.js: -------------------------------------------------------------------------------- 1 | const CheckToken = artifacts.require('CheckToken'); 2 | const MockWBNB = artifacts.require('MockWBNB'); 3 | const MockDai = artifacts.require('MockDai'); 4 | const IERC20 = artifacts.require('IERC20'); 5 | const IWBNB = artifacts.require('IWETH'); 6 | 7 | const UniswapV2Factory = artifacts.require('UniswapV2Factory'); 8 | const UniswapV2Router02 = artifacts.require('UniswapV2Router02'); 9 | const knownContracts = require('./known-contracts.js'); 10 | 11 | module.exports = async (deployer, network, accounts) => { 12 | const { toWei } = web3.utils; 13 | const uniswapRouter = knownContracts.UniswapV2Router02[network] ? await UniswapV2Router02.at(knownContracts.UniswapV2Router02[network]) : await UniswapV2Router02.deployed(); 14 | const uniswapFactory = knownContracts.UniswapV2Factory[network] ? await UniswapV2Factory.at(knownContracts.UniswapV2Factory[network]) : await UniswapV2Factory.deployed(); 15 | const dai = knownContracts.DAI[network] ? await MockDai.at(knownContracts.DAI[network]) : await MockDai.deployed(); 16 | const wbnb = knownContracts.WBNB[network] ? await IWBNB.at(knownContracts.WBNB[network]) : await MockWBNB.deployed(); 17 | const checkToken = knownContracts.CHECK[network] ? await CheckToken.at(knownContracts.CHECK[network]) : await CheckToken.deployed(); 18 | 19 | let check_wbnb_pair; 20 | 21 | const amount = toWei('250000', 'ether'); 22 | const amountMin = toWei('250000', 'ether'); 23 | let amountETHMin; 24 | if (network == 'mainnet') { 25 | amountETHMin = toWei('5', 'ether'); 26 | } else { 27 | amountETHMin = toWei('2', 'ether'); 28 | } 29 | await Promise.all([ 30 | approveIfNot(checkToken, accounts[0], uniswapRouter.address, amount), 31 | ]); 32 | 33 | await uniswapRouter.addLiquidityETH( 34 | checkToken.address, amount, amountMin, amountETHMin, accounts[0], deadline(), {from: accounts[0], value: amountETHMin}, 35 | ); 36 | 37 | // BUSD 38 | // 4800 39 | // if (network != 'mainnet') { 40 | // await dai.mint(accounts[0], toWei('4800'), {from: accounts[0]}); 41 | // } 42 | // const amountBUSD = toWei('4800', 'ether'); 43 | // const amountBUSDMin = toWei('4800', 'ether'); 44 | // await Promise.all([ 45 | // approveIfNot(checkToken, accounts[0], uniswapRouter.address, amount), 46 | // approveIfNot(dai, accounts[0], uniswapRouter.address, amount), 47 | // ]); 48 | // await uniswapRouter.addLiquidity( 49 | // checkToken.address, dai.address, amount, amountBUSD, amountMin, amountBUSDMin, accounts[0], deadline(), 50 | // ); 51 | 52 | // 0x000000000000000000000000000000000000dEaD 53 | check_wbnb_pair = await uniswapFactory.getPair(checkToken.address, wbnb.address); 54 | const lp1 = await IERC20.at(check_wbnb_pair); 55 | let bal_lp1 = await lp1.balanceOf(accounts[0]); 56 | console.log('addLiquidity:', bal_lp1.toString()); 57 | const burnAddr = '0x000000000000000000000000000000000000dEaD'; 58 | if (bal_lp1>0) { 59 | if (network != 'mainnet') { 60 | bal_lp1 = toWei('1', 'ether'); 61 | } 62 | await lp1.transfer(burnAddr, bal_lp1, {from: accounts[0]}); 63 | } 64 | console.log('after burn:', (await lp1.balanceOf(accounts[0])).toString()); 65 | }; 66 | 67 | async function approveIfNot(token, owner, spender, amount) { 68 | const allowance = await token.allowance(owner, spender); 69 | if (web3.utils.toBN(allowance).gte(web3.utils.toBN(amount))) { 70 | return; 71 | } 72 | await token.approve(spender, amount); 73 | } 74 | 75 | function deadline() { 76 | // 30 minutes 77 | return Math.floor(new Date().getTime() / 1000) + 1800; 78 | } 79 | -------------------------------------------------------------------------------- /migrations/15_add_cash_pool.js: -------------------------------------------------------------------------------- 1 | const knownContracts = require('./known-contracts'); 2 | 3 | const ForkToken = artifacts.require('ForkToken'); 4 | const CheckToken = artifacts.require('CheckToken'); 5 | const MockWBNB = artifacts.require('MockWBNB'); 6 | const MockDai = artifacts.require('MockDai'); 7 | const IERC20 = artifacts.require('IERC20'); 8 | const IWBNB = artifacts.require('IWETH'); 9 | 10 | const ForkFarmLaunch = artifacts.require("IDFO"); 11 | 12 | const UniswapV2Factory = artifacts.require('UniswapV2Factory'); 13 | const UniswapV2Router02 = artifacts.require('UniswapV2Router02'); 14 | 15 | // const {ALPACA_REWARD_PER_BLOCK, START_BLOCK} = require('./pool'); 16 | 17 | module.exports = async (deployer, network, accounts) => { 18 | const checkToken = knownContracts.CHECK[network] ? await CheckToken.at(knownContracts.CHECK[network]) : await CheckToken.deployed(); 19 | const forkToken = knownContracts.FORK[network] ? await ForkToken.at(knownContracts.FORK[network]) : await ForkToken.deployed(); 20 | 21 | const pools = [ 22 | { 23 | total: web3.utils.toWei('10000', 'ether'), 24 | token: forkToken.address, 25 | startTime: parseInt((new Date("2021-04-20 12:00:00 UTC")).getTime()/1000), 26 | endTime: parseInt((new Date("2021-04-21 12:00:00 UTC")).getTime()/1000), 27 | projectId: 0 28 | }, 29 | { 30 | total: web3.utils.toWei('20000', 'ether'), 31 | token: forkToken.address, 32 | startTime: parseInt((new Date("2021-04-18 12:00:00 UTC")).getTime()/1000), 33 | endTime: parseInt((new Date("2021-04-19 12:00:00 UTC")).getTime()/1000), 34 | projectId: 0 35 | }, 36 | { 37 | total: web3.utils.toWei('30000', 'ether'), 38 | token: forkToken.address, 39 | startTime: parseInt((new Date("2021-04-19 12:00:00 UTC")).getTime()/1000), 40 | endTime: parseInt((new Date("2021-04-20 12:00:00 UTC")).getTime()/1000), 41 | projectId: 0 42 | }, 43 | { 44 | total: web3.utils.toWei('40000', 'ether'), 45 | token: forkToken.address, 46 | startTime: parseInt((new Date("2021-04-20 12:00:00 UTC")).getTime()/1000), 47 | endTime: parseInt((new Date("2021-04-24 12:00:00 UTC")).getTime()/1000), 48 | projectId: 0 49 | } 50 | ]; 51 | forkFarm = await ForkFarmLaunch.deployed(); 52 | // updateMultiplier 53 | for (let i in pools) { 54 | let p = pools[i]; 55 | await forkFarm.addCashPool(p.total, p.token, p.startTime, p.endTime, p.projectId); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /migrations/16_transfer_check_ownership_chef.js: -------------------------------------------------------------------------------- 1 | const CheckToken = artifacts.require('CheckToken'); 2 | const Timelock = artifacts.require("Timelock"); 3 | 4 | const ForkFarmLaunch = artifacts.require("IDFO"); 5 | 6 | const conf = require("./conf"); 7 | const knownContracts = require('./known-contracts.js'); 8 | 9 | // const {ALPACA_REWARD_PER_BLOCK, START_BLOCK} = require('./pool'); 10 | 11 | module.exports = async (deployer, network, accounts) => { 12 | const forkFarmLaunch = await ForkFarmLaunch.deployed(); 13 | const checkToken = knownContracts.CHECK[network] ? await CheckToken.at(knownContracts.CHECK[network]) : await CheckToken.deployed(); 14 | await checkToken.transferOwnership(forkFarmLaunch.address); 15 | 16 | const timelock = knownContracts.Timelock[network] ? await Timelock.at(knownContracts.Timelock[network]) : await Timelock.deployed(); 17 | 18 | // await forkFarmLaunch.transferOwnership(timelock.address); 19 | } -------------------------------------------------------------------------------- /migrations/99_generate_deployment.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs'); 2 | const path = require('path'); 3 | const util = require('util'); 4 | const writeFile = util.promisify(fs.writeFile); 5 | 6 | const knownContracts = require('./known-contracts'); 7 | 8 | const ForkToken = artifacts.require('ForkToken'); 9 | const CheckToken = artifacts.require('CheckToken'); 10 | const MockWBNB = artifacts.require('MockWBNB'); 11 | const MockDai = artifacts.require('MockDai'); 12 | const ERC20 = artifacts.require('ERC20'); 13 | const IERC20 = artifacts.require('IERC20'); 14 | const IWBNB = artifacts.require('IWETH'); 15 | 16 | const FairLaunch = artifacts.require("FairLaunch"); 17 | const ForkFarmLaunch = artifacts.require("IDFO"); 18 | const IFairLaunch = artifacts.require("IFairLaunch"); 19 | const IForkFarmLaunch = artifacts.require("IForkFarmLaunch"); 20 | 21 | const UniswapV2Factory = artifacts.require('UniswapV2Factory'); 22 | const UniswapV2Router02 = artifacts.require('UniswapV2Router02'); 23 | 24 | // const {ALPACA_REWARD_PER_BLOCK, START_BLOCK} = require('./pool'); 25 | 26 | module.exports = async (deployer, network, accounts) => { 27 | // return; 28 | let deployments; 29 | console.log(">> Creating the deployment file"); 30 | const uniswapRouter = knownContracts.UniswapV2Router02[network] ? await UniswapV2Router02.at(knownContracts.UniswapV2Router02[network]) : await UniswapV2Router02.deployed(); 31 | const uniswapFactory = knownContracts.UniswapV2Factory[network] ? await UniswapV2Factory.at(knownContracts.UniswapV2Factory[network]) : await UniswapV2Factory.deployed(); 32 | const dai = knownContracts.DAI[network] ? await IERC20.at(knownContracts.DAI[network]) : await MockDai.deployed(); 33 | const wbnb = knownContracts.WBNB[network] ? await IWBNB.at(knownContracts.WBNB[network]) : await MockWBNB.deployed(); 34 | // const fairLaunch = await FairLaunch.deployed(); 35 | const forkFarmLaunch = await ForkFarmLaunch.deployed(); 36 | 37 | deployments = { 38 | // FairLaunch: { 39 | // address: fairLaunch.address, 40 | // pools: await getFairLaunchPools(fairLaunch) 41 | // }, 42 | ForkFarmLaunch: { 43 | address: forkFarmLaunch.address, 44 | pools: await getForkFarmLaunchPools(forkFarmLaunch) 45 | }, 46 | Exchanges: { 47 | Pancakeswap: { 48 | UniswapV2Factory: uniswapFactory.address, 49 | UniswapV2Router02: uniswapRouter.address 50 | } 51 | }, 52 | Tokens: { 53 | WBNB: wbnb.address, 54 | BUSD: dai.address, 55 | FORK: ForkToken.address, 56 | CHECK: CheckToken.address, 57 | } 58 | }; 59 | 60 | 61 | const deploymentPath = path.resolve(__dirname, `../build/deployments.${network}.json`); 62 | await writeFile(deploymentPath, JSON.stringify(deployments, null, 2)); 63 | 64 | console.log(`Exported deployments into ${deploymentPath}`); 65 | 66 | let contracts = [CheckToken, ForkToken, IERC20, IFairLaunch, IForkFarmLaunch, MockDai, MockWBNB, UniswapV2Factory, UniswapV2Router02]; 67 | 68 | const abiPath = path.resolve(__dirname, `../build/abis/${network}`); 69 | 70 | for (let c of contracts) { 71 | let abiFile = `${abiPath}/${c.contractName}.json`; 72 | await writeFile(abiFile, JSON.stringify(c.abi, null, 2)); 73 | console.log(`Exported ${c.contractName}‘s abi into ${abiFile}`); 74 | } 75 | 76 | } 77 | 78 | 79 | const getFairLaunchPools = async (fairLaunch) => { 80 | let pools = []; 81 | const length = await fairLaunch.poolLength(); 82 | for (let pid = 0; pid < length; pid++) { 83 | let poolInfo = await fairLaunch.poolInfo(pid); 84 | let token = await ERC20.at(poolInfo.stakeToken); 85 | let stakeToken = await token.symbol(); 86 | pools.push({ 87 | id: pid, 88 | stakingToken: stakeToken, 89 | address: poolInfo.stakeToken, 90 | allocPoint: poolInfo.allocPoint.toString() 91 | }); 92 | } 93 | return pools; 94 | } 95 | 96 | const getForkFarmLaunchPools = async (fairLaunch) => { 97 | let pools = []; 98 | const length = await fairLaunch.poolLength(); 99 | for (let pid = 0; pid < length; pid++) { 100 | let poolInfo = await fairLaunch.poolInfo(pid); 101 | let token = await ERC20.at(poolInfo.stakeToken); 102 | let stakeToken = await token.symbol(); 103 | console.log('allocPoint', poolInfo.allocPoint.toString()) 104 | pools.push({ 105 | id: pid, 106 | projectId: poolInfo.projectId, 107 | stakingToken: stakeToken, 108 | address: poolInfo.stakeToken, 109 | allocPoint: poolInfo.allocPoint.toString(), 110 | }); 111 | } 112 | return pools; 113 | } 114 | 115 | -------------------------------------------------------------------------------- /migrations/conf.js: -------------------------------------------------------------------------------- 1 | const DAY = 60*60*24; 2 | const WEEK = DAY*7; 3 | 4 | 5 | module.exports = { 6 | START_BLOCK: { 7 | develop: 0, 8 | ganache: 0, 9 | testnet: 7762143, 10 | mainnet: 5258000 11 | }, 12 | BONUS_END_BLOCK: { 13 | develop: 1000, 14 | ganache: 1000, 15 | testnet: 7762143 + 2*WEEK/3, 16 | mainnet: 0 17 | }, 18 | BONUS_LOCK_BPS: { 19 | develop: 7000, 20 | ganache: 7000, 21 | testnet: 7000, 22 | mainnet: 7000 23 | }, 24 | BONUS_MULTIPLIER:{ 25 | develop: 7, 26 | ganache: 7, 27 | testnet: 7, 28 | mainnet: 8 29 | }, 30 | FORK_REWARD_PER_BLOCK_ETHER: { 31 | develop: '2', 32 | ganache: '2', 33 | testnet: '2', 34 | mainnet: '2', 35 | }, 36 | CHECK_REWARD_PER_BLOCK_ETHER: { 37 | develop: '20', 38 | ganache: '20', 39 | testnet: '20', 40 | mainnet: '20', 41 | }, 42 | startReleaseBlock: { 43 | develop: 0, 44 | ganache: 0, 45 | testnet: 7762143 + 30*DAY/3, 46 | mainnet: 0, 47 | }, 48 | endReleaseBlock: { 49 | develop: 10, 50 | ganache: 10, 51 | testnet: 7762143 + 37*DAY/3, 52 | mainnet: 0, 53 | }, 54 | CHECK_START_BLOCK: { 55 | develop: 0, 56 | ganache: 0, 57 | testnet: 7774736, 58 | mainnet: 0, 59 | }, 60 | CHECK_BONUS_END_BLOCK: { 61 | develop: 1000, 62 | ganache: 1000, 63 | testnet: 7762143 + 2*WEEK/3, 64 | mainnet: 0 65 | }, 66 | CHECK_BONUS_LOCK_BPS: { 67 | develop: 7000, 68 | ganache: 7000, 69 | testnet: 7000, 70 | mainnet: 7000 71 | }, 72 | CHECK_BONUS_MULTIPLIER:{ 73 | develop: 8, 74 | ganache: 8, 75 | testnet: 8, 76 | mainnet: 8 77 | }, 78 | } 79 | -------------------------------------------------------------------------------- /migrations/known-contracts.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | // BUSD 3 | DAI: { 4 | develop: '', 5 | ganache: '', 6 | testnet: '0x97CD44c56Cd8CF914B32eDfc2A7FdC537f20C21e', 7 | mainnet: '0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56' 8 | }, 9 | WBNB: { 10 | develop: '', 11 | ganache: '', 12 | testnet: '0x81D71b7e8366A5E3dbf4E9AD431997cEbe9088D8', 13 | mainnet: '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c' 14 | }, 15 | UniswapV2Factory: { 16 | develop: '', 17 | ganache: '', 18 | testnet: '0x6b0f1af62b1bf419C83BF660603C59F3a951592A', 19 | mainnet: '0xBCfCcbde45cE874adCB698cC183deBcF17952812', 20 | }, 21 | UniswapV2Router02: { 22 | develop: '', 23 | ganache: '', 24 | testnet: '0x799df6358883742b576757457008d76813707aA2', 25 | mainnet: '0x05fF2B0DB69458A0750badebc4f9e13aDd608C7F' 26 | }, 27 | Timelock: { 28 | develop: '', 29 | ganache: '', 30 | testnet: '0xc848ac01fAA15A1Dc24b60c07Ff00037aDFb55F6', 31 | mainnet: '0xec4aB53bfC3BBA5b2379Dafb00312a3C607F0029' 32 | }, 33 | FORK: { 34 | develop: '', 35 | ganache: '', 36 | testnet: '0xa3fd694c5cB6233beE7aCad94Cb11C57F157324A', 37 | mainnet: '0xa9044F45039B798D21E02CB77F396A2d387cACdD' 38 | }, 39 | CHECK: { 40 | develop: '', 41 | ganache: '', 42 | testnet: '', 43 | mainnet: '' 44 | } 45 | } -------------------------------------------------------------------------------- /migrations/s_deploy_fork.js: -------------------------------------------------------------------------------- 1 | // ============ Contracts ============ 2 | 3 | const knownContracts = require('./known-contracts'); 4 | // Token 5 | // deployed first 6 | const ForkToken = artifacts.require('ForkToken'); 7 | 8 | const conf = require("./conf"); 9 | 10 | // ============ Main Migration ============ 11 | 12 | const migration = async (deployer, network, accounts) => { 13 | await Promise.all([deployToken(deployer, network, accounts)]) 14 | } 15 | 16 | module.exports = migration 17 | 18 | // ============ Deploy Functions ============ 19 | 20 | async function deployToken(deployer, network, accounts) { 21 | if (!knownContracts.FORK[network] ) { 22 | const startReleaseBlock = conf.startReleaseBlock[network]; 23 | const endReleaseBlock = conf.endReleaseBlock[network]; 24 | 25 | await deployer.deploy(ForkToken, startReleaseBlock, endReleaseBlock); 26 | const fork = await ForkToken.deployed(); 27 | console.log(`fork address:${fork.address}`) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@fork-finance/fork-contract", 3 | "version": "1.0.0", 4 | "devDependencies": { 5 | "@ethersproject/address": "^5.0.0-beta", 6 | "@ethersproject/contracts": "^5.0.0-beta", 7 | "@ethersproject/networks": "^5.0.0-beta", 8 | "@ethersproject/providers": "^5.0.0-beta", 9 | "@ethersproject/solidity": "^5.0.0-beta", 10 | "@openzeppelin/truffle-upgrades": "^1.5.0", 11 | "@truffle/artifactor": "^4.0.84", 12 | "@truffle/contract": "^4.3.9", 13 | "@truffle/hdwallet-provider": "1.2.2", 14 | "@uniswap/sdk": "^3.0.3", 15 | "@uniswap/v2-periphery": "^1.1.0-beta.0", 16 | "truffle-assertions": "^0.9.1", 17 | "truffle-plugin-verify": "^0.5.6" 18 | }, 19 | "dependencies": { 20 | "@openzeppelin/contracts": "^3.4.0", 21 | "@openzeppelin/contracts-ethereum-package": "^3.0.0", 22 | "@uniswap/v2-core": "^1.0.1" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /scripts/sedding_on_fork_wbnb_lp.js: -------------------------------------------------------------------------------- 1 | const ForkToken = artifacts.require("ForkToken"); 2 | 3 | const exec = function (callback) { 4 | console.log(callback) 5 | }; 6 | 7 | module.exports = exec; 8 | -------------------------------------------------------------------------------- /test/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fork-finance/fork-contract/7ae7371cb2de666b29a137585f5112f2ab48c8be/test/.gitkeep -------------------------------------------------------------------------------- /test/DAO.test.js: -------------------------------------------------------------------------------- 1 | const truffleAssert = require('truffle-assertions'); 2 | 3 | const DAOTreasury = artifacts.require('DAOTreasury'); 4 | const ForkToken = artifacts.require('ForkToken'); 5 | const DevShare = artifacts.require('DevShare'); 6 | const Timelock = artifacts.require('Timelock'); 7 | const {increaseTime,decreaseTime,latest} = require('./utils/time'); 8 | const {BN, expectRevert, time } = require('@openzeppelin/test-helpers'); 9 | 10 | contract('ForkFarmLaunch', async (accounts) => { 11 | let dev, alice, bob, minter; 12 | const { toWei } = web3.utils; 13 | const { fromWei } = web3.utils; 14 | const DAY = 60*60*24; 15 | 16 | beforeEach(async () => { 17 | // swapRouter = await UniswapV2Router02.deployed(); 18 | // swapFactory = await UniswapV2Factory.deployed(); 19 | // tokens 20 | 21 | // users 22 | [dev, alice, bob, dev, minter] = accounts; 23 | 24 | this.fork = await ForkToken.new(0, 1, {from: dev}); 25 | this.devShare = await DevShare.new(this.fork.address, 100, 300, {from: dev}); 26 | this.dao = await DAOTreasury.new(this.fork.address, {from: dev}); 27 | this.timelock = await Timelock.new(dev, DAY); 28 | // this.devShare.transferOwnership(this.timelock.address); 29 | await this.dao.transferOwnership(this.timelock.address, {from: dev}); 30 | await this.fork.mint(this.dao.address,'5000', {from: dev}); 31 | await this.fork.mint(this.devShare.address,'1000', {from: dev}); 32 | }) 33 | describe('when using DevShare', ()=>{ 34 | it("should release", async() => { 35 | assert.equal((await this.devShare.canUnlockAmount()).toString(), '0'); 36 | await this.devShare.unlock(alice, {from: dev}); 37 | assert.equal((await this.fork.balanceOf(alice)).toString(), '0'); 38 | await time.advanceBlockTo('120'); 39 | // assert.equal((await this.devShare.canUnlockAmount()).toString(), '200', 'err1'); 40 | // await this.devShare.unlock(alice, {from: dev}); 41 | // assert.equal((await this.fork.balanceOf(alice)).toString(), '200', 'err2'); 42 | await time.advanceBlockTo('300'); 43 | assert.equal((await this.devShare.canUnlockAmount()).toString(), '1000'); 44 | await this.devShare.unlock(alice, {from: dev}); 45 | assert.equal((await this.fork.balanceOf(alice)).toString(), '1000'); 46 | }) 47 | }) 48 | describe('when using dao', ()=> { 49 | it("should transferForkTo with timelock", async()=>{ 50 | 51 | const EXACT_ETA = (await latest()) + 60*60*24+1; 52 | const SIZE = '2000'; 53 | const signature = `transferForkTo(address,uint256)`; 54 | await this.timelock.queueTransaction( 55 | this.dao.address, 56 | 0, 57 | signature, 58 | web3.eth.abi.encodeParameters(['address', 'uint256'],[alice, SIZE]), 59 | EXACT_ETA, 60 | {from: dev} 61 | ); 62 | await increaseTime(24 * 60 * 60+10); 63 | await this.timelock.executeTransaction( 64 | this.dao.address, 65 | 0, 66 | signature, 67 | web3.eth.abi.encodeParameters(['address', 'uint256'],[alice, SIZE]), 68 | EXACT_ETA, 69 | {from: dev} 70 | ); 71 | assert.equal(await this.fork.balanceOf(this.dao.address), '3000'); 72 | assert.equal(await this.fork.balanceOf(alice), '2000'); 73 | }) 74 | }) 75 | }); -------------------------------------------------------------------------------- /test/fairLaunch.test.js: -------------------------------------------------------------------------------- 1 | const truffleAssert = require('truffle-assertions'); 2 | 3 | const ForkToken = artifacts.require('ForkToken'); 4 | const iBNB = artifacts.require('iBNB'); 5 | const iBUSD = artifacts.require('iBUSD'); 6 | const MockWBNB = artifacts.require('MockWBNB'); 7 | const MockDai = artifacts.require('MockDai'); 8 | const MockERC20 = artifacts.require('MockERC20'); 9 | const FairLaunch = artifacts.require("FairLaunch"); 10 | 11 | const UniswapV2Factory = artifacts.require('UniswapV2Factory'); 12 | const UniswapV2Router02 = artifacts.require('UniswapV2Router02'); 13 | 14 | contract('FairLaunch', async (accounts) => { 15 | const FORK_REWARD_PER_BLOCK = web3.utils.toWei('5000', 'ether'); 16 | const BONUS_LOCK_BPS = '7000'; 17 | 18 | let deployer, alice, bob, dev; 19 | const { toWei } = web3.utils; 20 | const { fromWei } = web3.utils; 21 | 22 | let fork, dai, wbnb, ibusd, ibnb, xxx; 23 | let fork_addr, dai_addr, wbnb_addr, ibusd_addr, ibnb_addr, xxx_addr; 24 | 25 | let fairLaunch; 26 | let swapRouter, swapFactory; 27 | let stakingTokens = []; 28 | 29 | beforeEach(async () => { 30 | // pancake-swap 31 | swapRouter = await UniswapV2Router02.deployed(); 32 | swapFactory = await UniswapV2Factory.deployed(); 33 | // tokens 34 | forkToken = await ForkToken.new(132, 137); 35 | 36 | // dai = await MockDai.new(); 37 | // wbnb = await MockWBNB.new(); 38 | // ibusd = await iBUSD.new(dai.address); 39 | // ibnb = await iBNB.new(wbnb.address); 40 | // xxx = await MockERC20.new('xxx', 'xxx'); 41 | 42 | // users 43 | [deployer, alice, bob, dev] = accounts; 44 | // FairLaunch 45 | fairLaunch = await FairLaunch.new(forkToken.address, deployer, FORK_REWARD_PER_BLOCK, 0, BONUS_LOCK_BPS, 0); 46 | await forkToken.transferOwnership(fairLaunch.address); 47 | // pools 48 | for (let i = 0; i < 4; i++) { 49 | const mockERC20 = await MockERC20.new(`STOKEN${i}`, `STOKEN${i}`); 50 | stakingTokens.push(mockERC20); 51 | } 52 | // stakingTokens = [dai, ibusd, ibnb]; 53 | }) 54 | 55 | describe('when adjust params', () => { 56 | it('should add new pool', async () => { 57 | for (let i = 0; i < stakingTokens.length; i++) { 58 | await fairLaunch.addPool(1, stakingTokens[i].address, false, {from: deployer}); 59 | } 60 | assert.equal(stakingTokens.length, (await fairLaunch.poolLength())); 61 | }); 62 | 63 | it('should revert when the stakeToken is already added to the pool', async () => { 64 | for (let i = 0; i < stakingTokens.length; i++) { 65 | await fairLaunch.addPool(1, stakingTokens[i].address, false); 66 | } 67 | assert.equal(stakingTokens.length, (await fairLaunch.poolLength())); 68 | await truffleAssert.reverts(fairLaunch.addPool(1, stakingTokens[0].address, false), "add: stakeToken dup") 69 | }); 70 | }); 71 | 72 | describe('when use pool', () => { 73 | it('should revert when there is nothing to be harvested', async() => { 74 | await fairLaunch.addPool(1, stakingTokens[0].address, false); 75 | await truffleAssert.reverts(fairLaunch.harvest(0), "nothing to harvest"); 76 | }); 77 | 78 | it('should revert when that pool is not existed', async() => { 79 | await truffleAssert.reverts(fairLaunch.deposit(77, toWei('100', 'ether')), "pool is not existed"); 80 | }); 81 | 82 | // it('should revert when withdrawer is not a funder', async () => { 83 | // // 1. Mint STOKEN0 for staking 84 | // await stakingTokens[0].mint(alice, toWei('400', 'ether'), {from: deployer}); 85 | 86 | // // 2. Add STOKEN0 to the fairLaunch pool 87 | // await fairLaunch.addPool(1, stakingTokens[0].address, false, {from: deployer}); 88 | 89 | // // 3. Deposit STOKEN0 to the STOKEN0 pool 90 | // await stakingTokens[0].approve(fairLaunch.address, etherToWei('100'), {from: alice}); 91 | // await fairLaunch.deposit(bob, 0, etherToWei('100'), {from: alice}); 92 | 93 | // // 4. Bob try to withdraw from the pool 94 | // // Bob shuoldn't do that, he can get yield but not the underlaying 95 | // await truffleAssert.reverts(fairLaunch.withdrawAll(bob, 0, {from: bob}), "only funder"); 96 | // }); 97 | 98 | // it('should revert when 2 accounts try to fund the same user', async () => { 99 | // // 1. Mint STOKEN0 for staking 100 | // await stakingTokens[0].mint(alice, etherToWei('400'), {from: deployer}); 101 | // await stakingTokens[0].mint(deployer, etherToWei('100'), {from: deployer}); 102 | 103 | // // 2. Add STOKEN0 to the fairLaunch pool 104 | // await fairLaunch.addPool(1, stakingTokens[0].address, false, {from: deployer}); 105 | 106 | // // 3. Deposit STOKEN0 to the STOKEN0 pool 107 | // await stakingTokens[0].approve(fairLaunch.address, etherToWei('100'), {from: alice}); 108 | // await fairLaunch.deposit(bob, 0, etherToWei('100'), {from: alice}); 109 | 110 | // // 4. Dev try to deposit to the pool on the bahalf of Bob 111 | // // Dev should get revert tx as this will fuck up the tracking 112 | // await stakingTokens[0].approve(fairLaunch.address, etherToWei("100"), {from: deployer}); 113 | // await truffleAssert.reverts(fairLaunch.deposit(bob, 0, etherToWei('1'), {from: deployer}), 'bad sof'); 114 | // }); 115 | 116 | // it('should harvest yield from the position opened by funder', async () => { 117 | // // 1. Mint STOKEN0 for staking 118 | // await stakingTokens[0].mint(alice, toWei('400'), {from: deployer}); 119 | 120 | // // 2. Add STOKEN0 to the STOKEN0 pool 121 | // await fairLaunch.addPool(1, stakingTokens[0].address, false); 122 | 123 | // // 3. Desposit STOKEN0 to the STOKEN0 pool 124 | // await stakingTokens[0].approve(fairLaunch.address, toWei('100'), {from: alice}); 125 | // await fairLaunch.deposit(bob, 0, etherToWei('100'), {from: alice}); 126 | 127 | // // 4. Move 1 Block so there is some pending 128 | // await fairLaunch.massUpdatePools({from: deployer}); 129 | // assert.equal(etherToWei('5000'), (await fairLaunch.pendingFork(0, bob, {from: bob})).toString()); 130 | 131 | // // 5. Harvest all yield 132 | // await fairLaunch.harvest(0, {from: bob}); 133 | 134 | // assert.equal(etherToWei('10000'), (await forkToken.balanceOf(bob)).toString()); 135 | // }); 136 | 137 | it('should distribute rewards according to the alloc point', async() => { 138 | // 1. Mint STOKEN0 and STOKEN1 for staking 139 | await stakingTokens[0].mint(alice, etherToWei('100'), {from: deployer}); 140 | await stakingTokens[1].mint(alice, etherToWei('50'), {from: deployer}); 141 | 142 | // 2. Add STOKEN0 to the fairLaunch pool 143 | await fairLaunch.addPool(50, stakingTokens[0].address, false, {from: deployer}); 144 | await fairLaunch.addPool(50, stakingTokens[1].address, false, {from: deployer}); 145 | 146 | // 3. Deposit STOKEN0 to the STOKEN0 pool 147 | await stakingTokens[0].approve(fairLaunch.address, etherToWei('100'), {from: alice}); 148 | await fairLaunch.deposit(0, etherToWei('100'), {from: alice}); 149 | 150 | // 4. Desposit STOKEN1 to the STOKEN1 pool 151 | await stakingTokens[1].approve(fairLaunch.address, etherToWei('50'), {from: alice}); 152 | await fairLaunch.deposit(1, etherToWei('50'), {from: alice}); 153 | 154 | // 5. Move 1 Block so there is some pending 155 | await fairLaunch.massUpdatePools({from: deployer}); 156 | 157 | assert.equal(etherToWei('7500'), (await fairLaunch.pendingFork(0, alice, {from: alice})).toString()); 158 | assert.equal(etherToWei('2500'), (await fairLaunch.pendingFork(1, alice, {from: alice})).toString()); 159 | 160 | // 6. Harvest all yield 161 | await fairLaunch.harvest(0, {from: alice}); 162 | await fairLaunch.harvest(1, {from: alice}); 163 | 164 | assert.equal(etherToWei('17500'), (await forkToken.balanceOf(alice)).toString()); 165 | }) 166 | 167 | }); 168 | }); 169 | 170 | const etherToWei = (ether) => { 171 | return web3.utils.toWei(ether, 'ether'); 172 | } 173 | 174 | -------------------------------------------------------------------------------- /test/forkFarm.test.js: -------------------------------------------------------------------------------- 1 | const {BN, expectRevert, time } = require('@openzeppelin/test-helpers'); 2 | const truffleAssert = require('truffle-assertions'); 3 | 4 | const CheckToken = artifacts.require('CheckToken'); 5 | const ForkToken = artifacts.require('ForkToken'); 6 | const MockERC20 = artifacts.require('MockERC20'); 7 | const ForkFarmLaunch = artifacts.require("IDFO"); 8 | 9 | const UniswapV2Factory = artifacts.require('UniswapV2Factory'); 10 | const UniswapV2Router02 = artifacts.require('UniswapV2Router02'); 11 | 12 | contract('ForkFarmLaunch', async (accounts) => { 13 | const CHECK_REWARD_PER_BLOCK = web3.utils.toWei('1000', 'ether'); 14 | let dev, alice, bob, minter; 15 | const { toWei } = web3.utils; 16 | const { fromWei } = web3.utils; 17 | 18 | beforeEach(async () => { 19 | // swapRouter = await UniswapV2Router02.deployed(); 20 | // swapFactory = await UniswapV2Factory.deployed(); 21 | // tokens 22 | 23 | // users 24 | [dev, alice, bob, dev, minter] = accounts; 25 | 26 | this.check = await CheckToken.new(1000, 1100, {from: minter}); 27 | this.lp1 = await MockERC20.new('LPToken', 'LP1', '1000000', { from: minter }); 28 | this.lp2 = await MockERC20.new('LPToken', 'LP2', '1000000', { from: minter }); 29 | this.lp3 = await MockERC20.new('LPToken', 'LP3', '1000000', { from: minter }); 30 | this.lp4 = await MockERC20.new('LPToken', 'LP4', '1000000', { from: minter }); 31 | this.chef = await ForkFarmLaunch.new(this.check.address, dev, '1000', '100', 7000, 0, { from: minter }); 32 | await this.check.transferOwnership(this.chef.address, { from: minter }); 33 | 34 | await this.lp1.transfer(bob, '2000', { from: minter }); 35 | await this.lp2.transfer(bob, '2000', { from: minter }); 36 | await this.lp3.transfer(bob, '2000', { from: minter }); 37 | await this.lp4.transfer(bob, '2000', { from: minter }); 38 | 39 | await this.lp1.transfer(alice, '2000', { from: minter }); 40 | await this.lp2.transfer(alice, '2000', { from: minter }); 41 | await this.lp3.transfer(alice, '2000', { from: minter }); 42 | await this.lp4.transfer(alice, '2000', { from: minter }); 43 | 44 | }) 45 | it('real case', async () => { 46 | await this.chef.add(0, '100', this.lp1.address, true, { from: minter }); 47 | await this.chef.add(0, '100', this.lp2.address, true, { from: minter }); 48 | await this.chef.add(0, '100', this.lp3.address, true, { from: minter }); 49 | await this.chef.add(0, '100', this.lp4.address, true, { from: minter }); 50 | 51 | await this.chef.add(1, '400', this.lp1.address, true, { from: minter }); 52 | await this.chef.add(1, '400', this.lp2.address, true, { from: minter }); 53 | await this.chef.add(1, '400', this.lp3.address, true, { from: minter }); 54 | await this.chef.add(1, '400', this.lp4.address, true, { from: minter }); 55 | 56 | assert.equal((await this.chef.poolLength()).toString(), "8"); 57 | 58 | await time.advanceBlockTo('170'); 59 | await this.lp1.approve(this.chef.address, '1000', { from: alice }); 60 | assert.equal((await this.check.balanceOf(alice)).toString(), '0'); 61 | await this.chef.deposit(0, '20', { from: alice }); 62 | await this.chef.withdraw(0, '20', { from: alice }); 63 | assert.equal((await this.check.balanceOf(alice)).toString(), 1000*100/(2000)); 64 | }) 65 | 66 | it('deposit/withdraw', async () => { 67 | await this.chef.add(0, '1000', this.lp1.address, true, { from: minter }); 68 | await this.chef.add(0, '1000', this.lp2.address, true, { from: minter }); 69 | await this.chef.add(0, '1000', this.lp3.address, true, { from: minter }); 70 | await this.chef.add(0, '1000', this.lp4.address, true, { from: minter }); 71 | 72 | await this.lp2.approve(this.chef.address, '100', { from: alice }); 73 | await this.chef.deposit(1, '20', { from: alice }); 74 | await this.chef.deposit(1, '0', { from: alice }); 75 | await this.chef.deposit(1, '40', { from: alice }); 76 | await this.chef.deposit(1, '0', { from: alice }); 77 | assert.equal((await this.lp2.balanceOf(alice)).toString(), '1940'); 78 | await this.chef.withdraw(1, '10', { from: alice }); 79 | assert.equal((await this.lp2.balanceOf(alice)).toString(), '1950'); 80 | assert.equal((await this.check.balanceOf(alice)).toString(), '999'); 81 | assert.equal((await this.check.balanceOf(dev)).toString(), '100'); 82 | 83 | await this.lp2.approve(this.chef.address, '100', { from: bob }); 84 | assert.equal((await this.lp2.balanceOf(bob)).toString(), '2000'); 85 | await this.chef.deposit(1, '50', { from: bob }); 86 | assert.equal((await this.lp2.balanceOf(bob)).toString(), '1950'); 87 | await this.chef.deposit(1, '0', { from: bob }); 88 | assert.equal((await this.check.balanceOf(bob)).toString(), '125'); 89 | await this.chef.emergencyWithdraw(1, { from: bob }); 90 | assert.equal((await this.lp2.balanceOf(bob)).toString(), '2000'); 91 | }) 92 | 93 | it('deposit/withdraw', async () => { 94 | await this.chef.setBonus(8, (await time.latestBlock()).add(new BN('500')).toString(), 7000, {from: minter}); 95 | await this.chef.add(0, '1000', this.lp1.address, true, { from: minter }); 96 | await this.chef.add(0, '1000', this.lp2.address, true, { from: minter }); 97 | await this.chef.add(0, '1000', this.lp3.address, true, { from: minter }); 98 | await this.chef.add(0, '1000', this.lp4.address, true, { from: minter }); 99 | 100 | await this.lp2.approve(this.chef.address, '100', { from: alice }); 101 | await this.chef.deposit(1, '20', { from: alice }); 102 | await this.chef.deposit(1, '0', { from: alice }); //250 103 | await this.chef.deposit(1, '40', { from: alice }); //250 104 | await this.chef.deposit(1, '0', { from: alice }); //250 105 | assert.equal((await this.lp2.balanceOf(alice)).toString(), '1940'); 106 | await this.chef.withdraw(1, '10', { from: alice }); //250 107 | assert.equal((await this.lp2.balanceOf(alice)).toString(), '1950'); 108 | assert.equal((await this.check.balanceOf(alice)).toString(), 1000*8*0.3+''); 109 | assert.equal((await this.check.lockOf(alice)).toString(), 1000*8*0.7+''); 110 | assert.equal((await this.check.balanceOf(dev)).toString(), 100*8*0.3+''); 111 | assert.equal((await this.check.lockOf(dev)).toString(), 100*8*0.7+''); 112 | 113 | // await this.lp2.approve(this.chef.address, '100', { from: bob }); 114 | // assert.equal((await this.lp2.balanceOf(bob)).toString(), '2000'); 115 | // await this.chef.deposit(1, '50', { from: bob }); 116 | // assert.equal((await this.lp2.balanceOf(bob)).toString(), '1950'); 117 | // await this.chef.deposit(1, '0', { from: bob }); 118 | // assert.equal((await this.check.balanceOf(bob)).toString(), '125'); 119 | // await this.chef.emergencyWithdraw(1, { from: bob }); 120 | // assert.equal((await this.lp2.balanceOf(bob)).toString(), '2000'); 121 | }) 122 | 123 | it('depositCheckToCash/cash', async () => { 124 | await this.chef.setBonus(8, (await time.latestBlock()).add(new BN('500')).toString(), 7000, {from: minter}); 125 | await this.chef.add(0, '1000', this.lp1.address, true, { from: minter }); 126 | await this.chef.add(0, '1000', this.lp2.address, true, { from: minter }); 127 | await this.chef.add(0, '1000', this.lp3.address, true, { from: minter }); 128 | await this.chef.add(0, '1000', this.lp4.address, true, { from: minter }); 129 | 130 | await this.lp2.approve(this.chef.address, '100', { from: alice }); 131 | await this.chef.deposit(1, '20', { from: alice }); 132 | await this.chef.withdraw(1, '20', { from: alice }); //600 133 | assert.equal((await this.check.balanceOf(alice)).toString(), '600'); 134 | 135 | this.fork = await MockERC20.new('ForkToken', 'FORK', '1000000', { from: minter }); 136 | 137 | await this.fork.transfer(this.chef.address, '1000', {from: minter}); 138 | 139 | await this.chef.addCashPool('520', this.fork.address, (await time.latest()).sub(time.duration.seconds('100')).toString(), (await time.latest()).add(time.duration.seconds('58')).toString(), 0, {from: minter}); 140 | await this.chef.addCashPool('480', this.fork.address, (await time.latest()).add(time.duration.seconds('60')).toString(), (await time.latest()).add(time.duration.seconds('119')).toString(), 0, {from: minter}); 141 | 142 | await this.check.approve(this.chef.address, '100', { from: alice}); 143 | await this.chef.depositCheckToCashPool(0, 100, {from: alice}); 144 | assert.equal((await this.check.balanceOf(alice)).toString(), '500'); 145 | assert.equal((await this.check.balanceOf(this.chef.address)).toString(), '100'); 146 | await time.increase(time.duration.seconds('59')); 147 | await this.chef.cashCheck(0, {from: alice}); 148 | assert.equal((await this.fork.balanceOf(alice)).toString(), '520'); 149 | assert.equal((await this.check.balanceOf(this.chef.address)).toString(), '0'); 150 | 151 | }); 152 | 153 | 154 | 155 | // it('update multiplier', async () => { 156 | // await this.chef.add(0, '1000', this.check.address, true, { from: minter }); 157 | // await this.chef.add(0, '1000', this.lp2.address, true, { from: minter }); 158 | // await this.chef.add(0, '1000', this.lp3.address, true, { from: minter }); 159 | // await this.chef.add(0, '1000', this.lp4.address, true, { from: minter }); 160 | 161 | // await this.lp2.approve(this.chef.address, '100', { from: alice }); 162 | // await this.lp2.approve(this.chef.address, '100', { from: bob }); 163 | // await this.chef.deposit(1, '100', { from: alice }); 164 | // await this.chef.deposit(1, '100', { from: bob }); // 250 165 | // await this.chef.deposit(1, '0', { from: alice }); // 125 125 166 | // await this.chef.deposit(1, '0', { from: bob }); // 125 125 167 | 168 | // await this.check.approve(this.chef.address, '100', { from: alice }); 169 | // await this.check.approve(this.chef.address, '100', { from: bob }); 170 | // await this.chef.deposit(0, '50', { from: alice }); 171 | // await this.chef.deposit(0, '100', { from: bob }); // 250 172 | 173 | // await this.chef.updateMultiplier('0', { from: minter }); 174 | 175 | // await this.chef.deposit(0, '0', { from: alice }); 176 | // await this.chef.deposit(0, '0', { from: bob }); 177 | // await this.chef.deposit(1, '0', { from: alice }); 178 | // await this.chef.deposit(1, '0', { from: bob }); 179 | 180 | // assert.equal((await this.check.balanceOf(alice)).toString(), toWei('750', 'ether')-50, 'err1'); 181 | // assert.equal((await this.check.balanceOf(bob)).toString(), toWei('250', 'ether')-100, 'err2'); 182 | 183 | // await time.advanceBlockTo('265'); 184 | 185 | // await this.chef.deposit(0, '0', { from: alice }); 186 | // await this.chef.deposit(0, '0', { from: bob }); 187 | // await this.chef.deposit(1, '0', { from: alice }); 188 | // await this.chef.deposit(1, '0', { from: bob }); 189 | 190 | // assert.equal((await this.check.balanceOf(alice)).toString(), toWei('750', 'ether')-50, 'err3'); 191 | // assert.equal((await this.check.balanceOf(bob)).toString(), toWei('250', 'ether')-100, 'err4'); 192 | 193 | // await this.chef.withdraw(0, '50', { from: alice }); 194 | // await this.chef.withdraw(0, '100', { from: bob }); 195 | // await this.chef.withdraw(1, '100', { from: alice }); 196 | // await this.chef.withdraw(1, '100', { from: bob }); 197 | 198 | // }); 199 | 200 | it('should allow dev and only dev to update dev', async () => { 201 | assert.equal((await this.chef.devaddr()).valueOf(), dev); 202 | await expectRevert(this.chef.setDev(bob, { from: bob }), 'dev: wut?'); 203 | await this.chef.setDev(bob, { from: dev }); 204 | assert.equal((await this.chef.devaddr()).valueOf(), bob); 205 | await this.chef.setDev(alice, { from: bob }); 206 | assert.equal((await this.chef.devaddr()).valueOf(), alice); 207 | }) 208 | }); -------------------------------------------------------------------------------- /test/forkFarmLaunch.test.js: -------------------------------------------------------------------------------- 1 | const truffleAssert = require('truffle-assertions'); 2 | 3 | const CheckToken = artifacts.require('CheckToken'); 4 | const ForkToken = artifacts.require('ForkToken'); 5 | const MockERC20 = artifacts.require('MockERC20'); 6 | const ForkFarmLaunch = artifacts.require("ForkFarmLaunch"); 7 | 8 | const UniswapV2Factory = artifacts.require('UniswapV2Factory'); 9 | const UniswapV2Router02 = artifacts.require('UniswapV2Router02'); 10 | 11 | contract('ForkFarmLaunch', async (accounts) => { 12 | const CHECK_REWARD_PER_BLOCK = web3.utils.toWei('5000', 'ether'); 13 | let deployer, alice, bob, dev; 14 | const { toWei } = web3.utils; 15 | const { fromWei } = web3.utils; 16 | 17 | beforeEach(async () => { 18 | // pancake-swap 19 | swapRouter = await UniswapV2Router02.deployed(); 20 | swapFactory = await UniswapV2Factory.deployed(); 21 | // tokens 22 | check = await CheckToken.new(); 23 | fork = await ForkToken.new(); 24 | 25 | // users 26 | [deployer, alice, bob, dev] = accounts; 27 | // forkFarmLaunch 28 | forkFarmLaunch = await ForkFarmLaunch.new(check.address, deployer, CHECK_REWARD_PER_BLOCK); 29 | await check.transferOwnership(forkFarmLaunch.address); 30 | // TODO 31 | 32 | }) 33 | }); -------------------------------------------------------------------------------- /test/ibnb_and_ibusd.test.js: -------------------------------------------------------------------------------- 1 | const truffleAssert = require('truffle-assertions'); 2 | 3 | const ForkToken = artifacts.require('ForkToken'); 4 | const iBNB = artifacts.require('iBNB'); 5 | const iBUSD = artifacts.require('iBUSD'); 6 | const MockWBNB = artifacts.require('MockWBNB'); 7 | const MockDai = artifacts.require('MockDai'); 8 | const WNativeRelayer = artifacts.require('WNativeRelayer'); 9 | 10 | 11 | // deposit withdraw 12 | contract('iBUSD and iBNB', async (accounts) => { 13 | let deployer, alice, bob, dev; 14 | const { toWei } = web3.utils; 15 | const { fromWei } = web3.utils; 16 | 17 | let dai, wbnb, ibusd, ibnb, xxx; 18 | 19 | beforeEach(async () => { 20 | // tokens 21 | dai = await MockDai.new(); 22 | wbnb = await MockWBNB.new(); 23 | ibusd = await iBUSD.new(dai.address); 24 | wNativeRelayer = await WNativeRelayer.new(wbnb.address); 25 | ibnb = await iBNB.new(wbnb.address, wNativeRelayer.address); 26 | // set whitelistedCallers 27 | await wNativeRelayer.setCallerOk([ibnb.address], true); 28 | // users 29 | [deployer, alice, bob, dev] = accounts; 30 | }); 31 | 32 | describe('when use iBUSD', () => { 33 | it('shold deposit dai to get iBUSD', async () => { 34 | // 1. Mint dai for depositing 35 | await dai.mint(alice, toWei('100', 'ether'), {from: deployer}); 36 | // 2. Deposit 37 | await dai.approve(ibusd.address, toWei('80', 'ether'), {from: alice}); 38 | await ibusd.deposit(toWei('80', 'ether'), {from: alice}); 39 | 40 | assert.equal(toWei('20', 'ether'), (await dai.balanceOf(alice)).toString()); 41 | assert.equal(toWei('80', 'ether'), (await ibusd.balanceOf(alice)).toString()); 42 | assert.equal(toWei('80', 'ether'), (await dai.balanceOf(ibusd.address)).toString()); 43 | }); 44 | 45 | it('shold withdraw iBUSD to get dai', async () => { 46 | // 1. Mint dai for depositing 47 | await dai.mint(alice, toWei('100', 'ether'), {from: deployer}); 48 | // 2. Deposit 49 | await dai.approve(ibusd.address, toWei('100', 'ether'), {from: alice}); 50 | await ibusd.deposit(toWei('100', 'ether'), {from: alice}); 51 | // 4. Withdraw 52 | await ibusd.withdraw(toWei('60', 'ether'), {from: alice}); 53 | 54 | assert.equal(toWei('60', 'ether'), (await dai.balanceOf(alice)).toString()); 55 | assert.equal(toWei('40', 'ether'), (await ibusd.balanceOf(alice)).toString()); 56 | assert.equal(toWei('40', 'ether'), (await dai.balanceOf(ibusd.address)).toString()); 57 | }); 58 | 59 | it('shold revert when deposit amount is more than banlance', async () => { 60 | // 1. Mint dai for depositing 61 | await dai.mint(alice, toWei('100', 'ether'), {from: deployer}); 62 | // 2. Deposit dai to get iBUSD 63 | await dai.approve(ibusd.address, toWei('500', 'ether'), {from: alice}); 64 | await truffleAssert.fails(ibusd.deposit(toWei('500', 'ether'), {from: alice})); 65 | }); 66 | 67 | it('shold revert when withdrawal amount is greater than deposit', async () => { 68 | // 1. Mint dai for depositing 69 | await dai.mint(alice, toWei('100', 'ether'), {from: deployer}); 70 | // 2. Deposit dai to get iBUSD 71 | await dai.approve(ibusd.address, toWei('100', 'ether'), {from: alice}); 72 | await ibusd.deposit(toWei('100', 'ether'), {from: alice}); 73 | 74 | await truffleAssert.fails(ibusd.withdraw(toWei('500', 'ether'), {from: alice})); 75 | }); 76 | }); 77 | 78 | describe('when use iBNB', () => { 79 | it('shold revert when deposit amount is not equal value', async () => { 80 | // 1. Deposit 81 | await truffleAssert.fails(ibnb.deposit(toWei('80', 'ether'), {from: alice, value: toWei('10', 'ether')}), null, "amount != msg.value"); 82 | }); 83 | it('shold deposit bnb to get iBNB', async () => { 84 | // 1. Deposit 85 | await ibnb.deposit(toWei('2', 'ether'), {from: alice, value: toWei('2', 'ether')}); 86 | 87 | assert.equal(toWei('2', 'ether'), (await ibnb.balanceOf(alice)).toString()); 88 | assert.equal(toWei('2', 'ether'), (await wbnb.balanceOf(ibnb.address)).toString()); 89 | }); 90 | 91 | it('shold withdraw from wbnb to get bnb', async () => { 92 | // 1. Deposit 93 | await wbnb.deposit({from: bob, value: toWei('3', 'ether')}); 94 | assert.equal(toWei('3', 'ether'), (await wbnb.balanceOf(bob)).toString()); 95 | // 2. Withdraw 96 | await wbnb.withdraw(toWei('1', 'ether'), {from: bob}); 97 | assert.equal(toWei('2', 'ether'), (await wbnb.balanceOf(bob)).toString()); 98 | }); 99 | 100 | it('shold withdraw iBNB to get bnb', async () => { 101 | // 1. Deposit 102 | await ibnb.deposit(toWei('8', 'ether'), {from: alice, value: toWei('8', 'ether')}); 103 | // 2. Withdraw 104 | await ibnb.withdraw(toWei('6', 'ether'), {from: alice}); 105 | 106 | assert.equal(toWei('2', 'ether'), (await ibnb.balanceOf(alice)).toString()); 107 | assert.equal(toWei('2', 'ether'), (await wbnb.balanceOf(ibnb.address)).toString()); 108 | }); 109 | 110 | it('shold revert when deposit amount is more than banlance', async () => { 111 | await truffleAssert.fails(ibnb.deposit(toWei('500', 'ether'), {from: alice, value: toWei('500', 'ether')})); 112 | }); 113 | 114 | it('shold revert when withdrawal amount is greater than deposit', async () => { 115 | await ibnb.deposit(toWei('5', 'ether'), {from: alice, value: toWei('5', 'ether')}); 116 | 117 | await truffleAssert.fails(ibnb.withdraw(toWei('500', 'ether'), {from: alice})); 118 | }); 119 | }); 120 | 121 | }); -------------------------------------------------------------------------------- /test/pancake.test.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fork-finance/fork-contract/7ae7371cb2de666b29a137585f5112f2ab48c8be/test/pancake.test.js -------------------------------------------------------------------------------- /test/utils/time.js: -------------------------------------------------------------------------------- 1 | const increaseTime = (addSeconds) => { 2 | const id = Date.now(); 3 | 4 | return new Promise((resolve, reject) => { 5 | web3.currentProvider.send({ 6 | jsonrpc: '2.0', 7 | method: 'evm_increaseTime', 8 | params: [addSeconds], 9 | id, 10 | }, (err1) => { 11 | if (err1) return reject(err1); 12 | 13 | web3.currentProvider.send({ 14 | jsonrpc: '2.0', 15 | method: 'evm_mine', 16 | id: id + 1, 17 | }, (err2, res) => (err2 ? reject(err2) : resolve(res))); 18 | }); 19 | }); 20 | } 21 | 22 | const decreaseTime = (addSeconds) => { 23 | const id = Date.now(); 24 | 25 | return new Promise((resolve, reject) => { 26 | web3.currentProvider.send({ 27 | jsonrpc: '2.0', 28 | method: 'evm_decreaseTime', 29 | params: [addSeconds], 30 | id, 31 | }, (err1) => { 32 | if (err1) return reject(err1); 33 | 34 | web3.currentProvider.send({ 35 | jsonrpc: '2.0', 36 | method: 'evm_mine', 37 | id: id + 1, 38 | }, (err2, res) => (err2 ? reject(err2) : resolve(res))); 39 | }); 40 | }); 41 | } 42 | 43 | const latest = async() => { 44 | let b = await web3.eth.getBlock('latest'); 45 | return b.timestamp; 46 | } 47 | 48 | module.exports = { 49 | increaseTime, decreaseTime,latest 50 | } 51 | 52 | -------------------------------------------------------------------------------- /truffle-config.js: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Use this file to configure your truffle project. It's seeded with some 4 | * common settings for different networks and features like migrations, 5 | * compilation and testing. Uncomment the ones you need or modify 6 | * them to suit your project as necessary. 7 | * 8 | * More information about configuration can be found at: 9 | * 10 | * trufflesuite.com/docs/advanced/configuration 11 | * 12 | * To deploy via Infura you'll need a wallet provider (like @truffle/hdwallet-provider) 13 | * to sign your transactions before they're sent to a remote public node. Infura accounts 14 | * are available for free at: infura.io/register. 15 | * 16 | * You'll also need a mnemonic - the twelve word phrase the wallet uses to generate 17 | * public/private key pairs. If you're publishing your code to GitHub make sure you load this 18 | * phrase from a file you've .gitignored so it doesn't accidentally become public. 19 | * 20 | */ 21 | 22 | const HDWalletProvider = require('@truffle/hdwallet-provider'); 23 | const fs = require('fs'); 24 | // const mnemonic = fs.readFileSync("../demo/.secret").toString().trim(); 25 | const mnemonic = fs.readFileSync("./.secret").toString().trim(); 26 | const {BSCSCANAPIKEY} = require('./env.json'); 27 | 28 | module.exports = { 29 | plugins: [ 30 | 'truffle-plugin-verify' 31 | ], 32 | api_keys: { 33 | bscscan: BSCSCANAPIKEY 34 | }, 35 | /** 36 | * Networks define how you connect to your ethereum client and let you set the 37 | * defaults web3 uses to send transactions. If you don't specify one truffle 38 | * will spin up a development blockchain for you on port 9545 when you 39 | * run `develop` or `test`. You can ask a truffle command to use a specific 40 | * network from the command line, e.g 41 | * 42 | * $ truffle test --network 43 | */ 44 | 45 | networks: { 46 | development: { 47 | host: '127.0.0.1', // Localhost (default: none) 48 | port: 8545, // Standard Ethereum port (default: none) 49 | network_id: '57777', 50 | }, 51 | 52 | ganache: { 53 | host: "127.0.0.1", // Localhost (default: none) 54 | port: 7545, // Standard Ethereum port (default: none) 55 | network_id: "5777", // Any network (default: none) 56 | }, 57 | 58 | testnet: { 59 | provider: () => new HDWalletProvider(mnemonic, `https://data-seed-prebsc-1-s1.binance.org:8545`), 60 | network_id: 97, 61 | confirmations: 10, 62 | timeoutBlocks: 200, 63 | skipDryRun: true 64 | }, 65 | mainnet: { 66 | provider: () => new HDWalletProvider(mnemonic, `https://bsc-dataseed1.binance.org`), 67 | network_id: 56, 68 | confirmations: 10, 69 | timeoutBlocks: 200, 70 | skipDryRun: true 71 | }, 72 | goerli: { 73 | provider: () => new HDWalletProvider(mnemonic, `wss://goerli.infura.io/ws/v3/30ed079d0921439598b010df473a4f1e`), 74 | network_id: 5, 75 | // confirmations: 10, 76 | // timeoutBlocks: 200, 77 | // skipDryRun: true 78 | }, 79 | ethmainnet:{ 80 | provider: () => new HDWalletProvider(mnemonic, `wss://mainnet.infura.io/ws/v3/30ed079d0921439598b010df473a4f1e`), 81 | network_id: 1, 82 | confirmations: 10, 83 | timeoutBlocks: 200, 84 | skipDryRun: true 85 | }, 86 | // Useful for testing. The `development` name is special - truffle uses it by default 87 | // if it's defined here and no other network is specified at the command line. 88 | // You should run a client (like ganache-cli, geth or parity) in a separate terminal 89 | // tab if you use this network and you must also set the `host`, `port` and `network_id` 90 | // options below to some value. 91 | // 92 | // development: { 93 | // host: "127.0.0.1", // Localhost (default: none) 94 | // port: 8545, // Standard Ethereum port (default: none) 95 | // network_id: "*", // Any network (default: none) 96 | // }, 97 | // Another network with more advanced options... 98 | // advanced: { 99 | // port: 8777, // Custom port 100 | // network_id: 1342, // Custom network 101 | // gas: 8500000, // Gas sent with each transaction (default: ~6700000) 102 | // gasPrice: 20000000000, // 20 gwei (in wei) (default: 100 gwei) 103 | // from:
, // Account to send txs from (default: accounts[0]) 104 | // websocket: true // Enable EventEmitter interface for web3 (default: false) 105 | // }, 106 | // Useful for deploying to a public network. 107 | // NB: It's important to wrap the provider as a function. 108 | // ropsten: { 109 | // provider: () => new HDWalletProvider(mnemonic, `https://ropsten.infura.io/v3/YOUR-PROJECT-ID`), 110 | // network_id: 3, // Ropsten's id 111 | // gas: 5500000, // Ropsten has a lower block limit than mainnet 112 | // confirmations: 2, // # of confs to wait between deployments. (default: 0) 113 | // timeoutBlocks: 200, // # of blocks before a deployment times out (minimum/default: 50) 114 | // skipDryRun: true // Skip dry run before migrations? (default: false for public nets ) 115 | // }, 116 | // Useful for private networks 117 | // private: { 118 | // provider: () => new HDWalletProvider(mnemonic, `https://network.io`), 119 | // network_id: 2111, // This network is yours, in the cloud. 120 | // production: true // Treats this network as if it was a public net. (default: false) 121 | // } 122 | }, 123 | 124 | // Set default mocha options here, use special reporters etc. 125 | mocha: { 126 | // timeout: 100000 127 | }, 128 | 129 | // Configure your compilers 130 | compilers: { 131 | solc: { 132 | version: "0.6.6", // Fetch exact version from solc-bin (default: truffle's version) 133 | // docker: true, // Use "0.5.1" you've installed locally with docker (default: false) 134 | settings: { 135 | optimizer: { 136 | enabled: true, 137 | runs: 1, 138 | }, 139 | evmVersion: "istanbul", 140 | outputSelection: { 141 | "*": { 142 | "": [ 143 | "ast" 144 | ], 145 | "*": [ 146 | "evm.bytecode.object", 147 | "evm.deployedBytecode.object", 148 | "abi", 149 | "evm.bytecode.sourceMap", 150 | "evm.deployedBytecode.sourceMap", 151 | "metadata" 152 | ] 153 | } 154 | }, 155 | }, 156 | } 157 | } 158 | }; 159 | -------------------------------------------------------------------------------- /verify.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | contracts=(CheckToken 4 | ForkToken 5 | IDFO 6 | MockDai 7 | MockWBNB 8 | UniswapV2Factory 9 | UniswapV2Router02) 10 | 11 | function verify() { 12 | network=$1 13 | echo "----------------------------------------------------------" 14 | for c in ${contracts[@]} ; do 15 | echo "Executing command: truffle run verify ${c} --network ${network}" 16 | truffle run verify ${c} --network ${network} 17 | done 18 | echo "----------------------------------------------------------" 19 | } 20 | 21 | if [ -n "$1" ]; then 22 | verify $1 23 | else 24 | exit 0 25 | fi 26 | --------------------------------------------------------------------------------