├── README.md ├── tree ├── SafeMath.sol ├── Ownable.sol ├── SafeBEP20.sol ├── Address.sol ├── BEP20.sol ├── Context.sol ├── IBEP20.sol ├── TreeDefiToken.sol └── MasterChef.sol ├── seed ├── Context.sol ├── Ownable.sol ├── IBEP20.sol ├── SafeBEP20.sol ├── SafeMath.sol ├── Address.sol ├── Bep20.sol └── TreeDefiSEED.sol ├── nft ├── Trade.sol └── Treedefi.sol ├── masterchef └── MasterChef.sol ├── paymentGateway └── paymentGateway.sol └── lauch-pool └── Launchpool.sol /README.md: -------------------------------------------------------------------------------- 1 | Treedefi Contracts 2 | 3 | - Seed folder contains contracts for the $SEED 4 | - Tree folder contains contract for the $TREE 5 | - NFT folder contains contracts for NFTrees (nft.treedefi.com) tradable with NFT 6 | -------------------------------------------------------------------------------- /tree/SafeMath.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity >=0.6.0 <0.8.0; 4 | 5 | /** 6 | * @dev Wrappers over Solidity's arithmetic operations with added overflow 7 | * checks. 8 | * 9 | * Arithmetic operations in Solidity wrap on overflow. This can easily result 10 | * in bugs, because programmers usually assume that an overflow raises an 11 | * error, which is the standard behavior in high level programming languages. 12 | * `SafeMath` restores this intuition by reverting the transaction when an 13 | * operation overflows. -------------------------------------------------------------------------------- /seed/Context.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity >=0.6.0 <0.8.0; 4 | 5 | /* 6 | * @dev Provides information about the current execution context, including the 7 | * sender of the transaction and its data. While these are generally available 8 | * via msg.sender and msg.data, they should not be accessed in such a direct 9 | * manner, since when dealing with GSN meta-transactions the account sending and 10 | * paying for execution may not be the actual sender (as far as an application 11 | * is concerned). 12 | * 13 | * This contract is only required for intermediate, library-like contracts. 14 | */ 15 | abstract contract Context { 16 | function _msgSender() internal view virtual returns (address payable) { 17 | return msg.sender; 18 | } 19 | 20 | function _msgData() internal view virtual returns (bytes memory) { 21 | this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 22 | return msg.data; 23 | } 24 | } -------------------------------------------------------------------------------- /seed/Ownable.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity >=0.6.0 <0.8.0; 4 | 5 | import "./Context.sol"; 6 | /** 7 | * @dev Contract module which provides a basic access control mechanism, where 8 | * there is an account (an owner) that can be granted exclusive access to 9 | * specific functions. 10 | * 11 | * By default, the owner account will be the one that deploys the contract. This 12 | * can later be changed with {transferOwnership}. 13 | * 14 | * This module is used through inheritance. It will make available the modifier 15 | * `onlyOwner`, which can be applied to your functions to restrict their use to 16 | * the owner. 17 | */ 18 | abstract contract Ownable is Context { 19 | address private _owner; 20 | 21 | event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); 22 | 23 | /** 24 | * @dev Initializes the contract setting the deployer as the initial owner. 25 | */ 26 | constructor () internal { 27 | address msgSender = _msgSender(); 28 | _owner = msgSender; 29 | emit OwnershipTransferred(address(0), msgSender); 30 | } 31 | 32 | /** 33 | * @dev Returns the address of the current owner. 34 | */ 35 | function owner() public view returns (address) { 36 | return _owner; 37 | } 38 | 39 | /** 40 | * @dev Throws if called by any account other than the owner. 41 | */ 42 | modifier onlyOwner() { 43 | require(_owner == _msgSender(), "Ownable: caller is not the owner"); 44 | _; 45 | } 46 | 47 | /** 48 | * @dev Leaves the contract without owner. It will not be possible to call 49 | * `onlyOwner` functions anymore. Can only be called by the current owner. 50 | * 51 | * NOTE: Renouncing ownership will leave the contract without an owner, 52 | * thereby removing any functionality that is only available to the owner. 53 | */ 54 | function renounceOwnership() public virtual onlyOwner { 55 | emit OwnershipTransferred(_owner, address(0)); 56 | _owner = address(0); 57 | } 58 | 59 | /** 60 | * @dev Transfers ownership of the contract to a new account (`newOwner`). 61 | * Can only be called by the current owner. 62 | */ 63 | function transferOwnership(address newOwner) public virtual onlyOwner { 64 | require(newOwner != address(0), "Ownable: new owner is the zero address"); 65 | emit OwnershipTransferred(_owner, newOwner); 66 | _owner = newOwner; 67 | } 68 | } -------------------------------------------------------------------------------- /tree/Ownable.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity >=0.6.0 <0.8.0; 4 | 5 | import "./Context.sol"; 6 | /** 7 | * @dev Contract module which provides a basic access control mechanism, where 8 | * there is an account (an owner) that can be granted exclusive access to 9 | * specific functions. 10 | * 11 | * By default, the owner account will be the one that deploys the contract. This 12 | * can later be changed with {transferOwnership}. 13 | * 14 | * This module is used through inheritance. It will make available the modifier 15 | * `onlyOwner`, which can be applied to your functions to restrict their use to 16 | * the owner. 17 | */ 18 | abstract contract Ownable is Context { 19 | address private _owner; 20 | 21 | event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); 22 | 23 | /** 24 | * @dev Initializes the contract setting the deployer as the initial owner. 25 | */ 26 | constructor () internal { 27 | address msgSender = _msgSender(); 28 | _owner = msgSender; 29 | emit OwnershipTransferred(address(0), msgSender); 30 | } 31 | 32 | /** 33 | * @dev Returns the address of the current owner. 34 | */ 35 | function owner() public view returns (address) { 36 | return _owner; 37 | } 38 | 39 | /** 40 | * @dev Throws if called by any account other than the owner. 41 | */ 42 | modifier onlyOwner() { 43 | require(_owner == _msgSender(), "Ownable: caller is not the owner"); 44 | _; 45 | } 46 | 47 | /** 48 | * @dev Leaves the contract without owner. It will not be possible to call 49 | * `onlyOwner` functions anymore. Can only be called by the current owner. 50 | * 51 | * NOTE: Renouncing ownership will leave the contract without an owner, 52 | * thereby removing any functionality that is only available to the owner. 53 | */ 54 | function renounceOwnership() public virtual onlyOwner { 55 | emit OwnershipTransferred(_owner, address(0)); 56 | _owner = address(0); 57 | } 58 | 59 | /** 60 | * @dev Transfers ownership of the contract to a new account (`newOwner`). 61 | * Can only be called by the current owner. 62 | */ 63 | function transferOwnership(address newOwner) public virtual onlyOwner { 64 | require(newOwner != address(0), "Ownable: new owner is the zero address"); 65 | emit OwnershipTransferred(_owner, newOwner); 66 | _owner = newOwner; 67 | } 68 | } -------------------------------------------------------------------------------- /seed/IBEP20.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity >=0.6.4; 4 | 5 | interface IBEP20 { 6 | /** 7 | * @dev Returns the amount of tokens in existence. 8 | */ 9 | function totalSupply() external view returns (uint256); 10 | 11 | /** 12 | * @dev Returns the token decimals. 13 | */ 14 | function decimals() external view returns (uint8); 15 | 16 | /** 17 | * @dev Returns the token symbol. 18 | */ 19 | function symbol() external view returns (string memory); 20 | 21 | /** 22 | * @dev Returns the token name. 23 | */ 24 | function name() external view returns (string memory); 25 | 26 | /** 27 | * @dev Returns the bep token owner. 28 | */ 29 | function getOwner() external view returns (address); 30 | 31 | /** 32 | * @dev Returns the amount of tokens owned by `account`. 33 | */ 34 | function balanceOf(address account) external view returns (uint256); 35 | 36 | /** 37 | * @dev Moves `amount` tokens from the caller's account to `recipient`. 38 | * 39 | * Returns a boolean value indicating whether the operation succeeded. 40 | * 41 | * Emits a {Transfer} event. 42 | */ 43 | function transfer(address recipient, uint256 amount) external returns (bool); 44 | 45 | /** 46 | * @dev Returns the remaining number of tokens that `spender` will be 47 | * allowed to spend on behalf of `owner` through {transferFrom}. This is 48 | * zero by default. 49 | * 50 | * This value changes when {approve} or {transferFrom} are called. 51 | */ 52 | function allowance(address _owner, address spender) external view returns (uint256); 53 | 54 | /** 55 | * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. 56 | * 57 | * Returns a boolean value indicating whether the operation succeeded. 58 | * 59 | * IMPORTANT: Beware that changing an allowance with this method brings the risk 60 | * that someone may use both the old and the new allowance by unfortunate 61 | * transaction ordering. One possible solution to mitigate this race 62 | * condition is to first reduce the spender's allowance to 0 and set the 63 | * desired value afterwards: 64 | * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 65 | * 66 | * Emits an {Approval} event. 67 | */ 68 | function approve(address spender, uint256 amount) external returns (bool); 69 | 70 | /** 71 | * @dev Moves `amount` tokens from `sender` to `recipient` using the 72 | * allowance mechanism. `amount` is then deducted from the caller's 73 | * allowance. 74 | * 75 | * Returns a boolean value indicating whether the operation succeeded. 76 | * 77 | * Emits a {Transfer} event. 78 | */ 79 | function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); 80 | 81 | /** 82 | * @dev Emitted when `value` tokens are moved from one account (`from`) to 83 | * another (`to`). 84 | * 85 | * Note that `value` may be zero. 86 | */ 87 | event Transfer(address indexed from, address indexed to, uint256 value); 88 | 89 | /** 90 | * @dev Emitted when the allowance of a `spender` for an `owner` is set by 91 | * a call to {approve}. `value` is the new allowance. 92 | */ 93 | event Approval(address indexed owner, address indexed spender, uint256 value); 94 | } -------------------------------------------------------------------------------- /seed/SafeBEP20.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity >=0.6.0 <0.8.0; 4 | 5 | import "./IBEP20.sol"; 6 | import "./SafeMath.sol"; 7 | import "./Address.sol"; 8 | 9 | /** 10 | * @title SafeBEP20 11 | * @dev Wrappers around BEP20 operations that throw on failure (when the token 12 | * contract returns false). Tokens that return no value (and instead revert or 13 | * throw on failure) are also supported, non-reverting calls are assumed to be 14 | * successful. 15 | * To use this library you can add a `using SafeBEP20 for IBEP20;` statement to your contract, 16 | * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. 17 | */ 18 | library SafeBEP20 { 19 | using SafeMath for uint256; 20 | using Address for address; 21 | 22 | function safeTransfer(IBEP20 token, address to, uint256 value) internal { 23 | _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); 24 | } 25 | 26 | function safeTransferFrom(IBEP20 token, address from, address to, uint256 value) internal { 27 | _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); 28 | } 29 | 30 | /** 31 | * @dev Deprecated. This function has issues similar to the ones found in 32 | * {IBEP20-approve}, and its usage is discouraged. 33 | * 34 | * Whenever possible, use {safeIncreaseAllowance} and 35 | * {safeDecreaseAllowance} instead. 36 | */ 37 | function safeApprove(IBEP20 token, address spender, uint256 value) internal { 38 | // safeApprove should only be called when setting an initial allowance, 39 | // or when resetting it to zero. To increase and decrease it, use 40 | // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' 41 | // solhint-disable-next-line max-line-length 42 | require((value == 0) || (token.allowance(address(this), spender) == 0), 43 | "SafeBEP20: approve from non-zero to non-zero allowance" 44 | ); 45 | _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); 46 | } 47 | 48 | function safeIncreaseAllowance(IBEP20 token, address spender, uint256 value) internal { 49 | uint256 newAllowance = token.allowance(address(this), spender).add(value); 50 | _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); 51 | } 52 | 53 | function safeDecreaseAllowance(IBEP20 token, address spender, uint256 value) internal { 54 | uint256 newAllowance = token.allowance(address(this), spender).sub(value, "SafeBEP20: decreased allowance below zero"); 55 | _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); 56 | } 57 | 58 | /** 59 | * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement 60 | * on the return value: the return value is optional (but if data is returned, it must not be false). 61 | * @param token The token targeted by the call. 62 | * @param data The call data (encoded using abi.encode or one of its variants). 63 | */ 64 | function _callOptionalReturn(IBEP20 token, bytes memory data) private { 65 | // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since 66 | // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that 67 | // the target address contains contract code and also asserts for success in the low-level call. 68 | 69 | bytes memory returndata = address(token).functionCall(data, "SafeBEP20: low-level call failed"); 70 | if (returndata.length > 0) { // Return data is optional 71 | // solhint-disable-next-line max-line-length 72 | require(abi.decode(returndata, (bool)), "SafeBEP20: BEP20 operation did not succeed"); 73 | } 74 | } 75 | } -------------------------------------------------------------------------------- /tree/SafeBEP20.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity >=0.6.0 <0.8.0; 4 | 5 | import "./IBEP20.sol"; 6 | import "./SafeMath.sol"; 7 | import "./Address.sol"; 8 | 9 | /** 10 | * @title SafeBEP20 11 | * @dev Wrappers around BEP20 operations that throw on failure (when the token 12 | * contract returns false). Tokens that return no value (and instead revert or 13 | * throw on failure) are also supported, non-reverting calls are assumed to be 14 | * successful. 15 | * To use this library you can add a `using SafeBEP20 for IBEP20;` statement to your contract, 16 | * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. 17 | */ 18 | library SafeBEP20 { 19 | using SafeMath for uint256; 20 | using Address for address; 21 | 22 | function safeTransfer(IBEP20 token, address to, uint256 value) internal { 23 | _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); 24 | } 25 | 26 | function safeTransferFrom(IBEP20 token, address from, address to, uint256 value) internal { 27 | _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); 28 | } 29 | 30 | /** 31 | * @dev Deprecated. This function has issues similar to the ones found in 32 | * {IBEP20-approve}, and its usage is discouraged. 33 | * 34 | * Whenever possible, use {safeIncreaseAllowance} and 35 | * {safeDecreaseAllowance} instead. 36 | */ 37 | function safeApprove(IBEP20 token, address spender, uint256 value) internal { 38 | // safeApprove should only be called when setting an initial allowance, 39 | // or when resetting it to zero. To increase and decrease it, use 40 | // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' 41 | // solhint-disable-next-line max-line-length 42 | require((value == 0) || (token.allowance(address(this), spender) == 0), 43 | "SafeBEP20: approve from non-zero to non-zero allowance" 44 | ); 45 | _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); 46 | } 47 | 48 | function safeIncreaseAllowance(IBEP20 token, address spender, uint256 value) internal { 49 | uint256 newAllowance = token.allowance(address(this), spender).add(value); 50 | _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); 51 | } 52 | 53 | function safeDecreaseAllowance(IBEP20 token, address spender, uint256 value) internal { 54 | uint256 newAllowance = token.allowance(address(this), spender).sub(value, "SafeBEP20: decreased allowance below zero"); 55 | _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); 56 | } 57 | 58 | /** 59 | * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement 60 | * on the return value: the return value is optional (but if data is returned, it must not be false). 61 | * @param token The token targeted by the call. 62 | * @param data The call data (encoded using abi.encode or one of its variants). 63 | */ 64 | function _callOptionalReturn(IBEP20 token, bytes memory data) private { 65 | // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since 66 | // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that 67 | // the target address contains contract code and also asserts for success in the low-level call. 68 | 69 | bytes memory returndata = address(token).functionCall(data, "SafeBEP20: low-level call failed"); 70 | if (returndata.length > 0) { // Return data is optional 71 | // solhint-disable-next-line max-line-length 72 | require(abi.decode(returndata, (bool)), "SafeBEP20: BEP20 operation did not succeed"); 73 | } 74 | } 75 | } -------------------------------------------------------------------------------- /nft/Trade.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.16; 2 | 3 | import "./Treedefi.sol"; 4 | 5 | interface ISeedToken { 6 | 7 | function transferFrom( 8 | address _from, 9 | address _to, 10 | uint256 _value 11 | ) external returns (bool success); 12 | 13 | function balanceOf( 14 | address _owner 15 | ) external returns (uint256); 16 | 17 | function allowance( 18 | address _owner, 19 | address _spender 20 | ) external returns (uint256); 21 | 22 | } 23 | 24 | contract Trade { 25 | 26 | using SafeMath for uint256; 27 | 28 | Treedefi public tree; 29 | ISeedToken public SEED_CONTRACT; 30 | 31 | mapping(uint => Wood) public treeList; 32 | 33 | address private _manager; 34 | address private _burnAddress = 0x000000000000000000000000000000000000dEaD; 35 | 36 | struct Wood { 37 | bool forSell; 38 | uint256 price; 39 | uint256 burnPercentage; 40 | } 41 | 42 | event Purchase( 43 | address indexed _from, 44 | address indexed _to, 45 | uint256 indexed _id, 46 | uint256 _value 47 | ); 48 | 49 | event Listing( 50 | address indexed _owner, 51 | uint256 indexed _id, 52 | uint256 _value, 53 | uint256 _burnPercentage 54 | ); 55 | 56 | constructor(Treedefi _tree, address _seedToken) public { 57 | tree = _tree; 58 | SEED_CONTRACT = ISeedToken(_seedToken); 59 | _manager = tree.getOwner(); 60 | } 61 | 62 | /** @dev List Treedefi Forest NFT for sell at specific price 63 | *@param _id unsigned integer defines tokenID to list for sell 64 | *@param _price unsigned integer defines sell price in SEED for the tokenID 65 | */ 66 | function listTree(uint256 _id, uint256 _price, uint256 _burnPercent) public { 67 | 68 | address _owner = tree.ownerOf(_id); 69 | address _approved = tree.getApproved(_id); 70 | 71 | require( 72 | address(this) == _approved, 73 | " Treedefi: Contract is not approved to manage token of this ID " 74 | ); 75 | 76 | require( 77 | msg.sender == _owner, 78 | " Treedefi: Only owner of token can list the token for sell " 79 | ); 80 | 81 | uint256 _burnP = (msg.sender == _manager)?_burnPercent:0; 82 | 83 | treeList[_id] = Wood(true, _price, _burnP); 84 | 85 | emit Listing(_owner, _id, _price, _burnP); 86 | 87 | } 88 | 89 | /** @dev Buy Treedefi Forest NFT for listed price 90 | *@param _id unsigned integer defines tokenID to buy 91 | *@param _value unsigned integer defines value of SEED tokens to buy NFT 92 | */ 93 | function buyTree(uint256 _id, uint256 _value) public { 94 | 95 | address _approved = tree.getApproved(_id); 96 | 97 | require( 98 | address(this) == _approved, 99 | " Treedefi: Contract is not approved to manage token of this ID " 100 | ); 101 | 102 | require( 103 | treeList[_id].forSell, 104 | " Treedefi: Token of this ID is not for sell " 105 | ); 106 | 107 | require( 108 | treeList[_id].price <= _value, 109 | " Treedefi: Provided value is less than listed price " 110 | ); 111 | 112 | require( 113 | SEED_CONTRACT.balanceOf(msg.sender) >= _value, 114 | " SEED : Buyer doesn't have enough balance to purchase token " 115 | ); 116 | 117 | require( 118 | SEED_CONTRACT.allowance(msg.sender, address(this)) >= _value, 119 | " SEED : Contract is not approved to spend tokens of user " 120 | ); 121 | 122 | address _owner = tree.ownerOf(_id); 123 | 124 | if(treeList[_id].burnPercentage == 0){ 125 | 126 | SEED_CONTRACT.transferFrom(msg.sender, _owner, _value); 127 | 128 | } else { 129 | 130 | uint256 _burnValue = _value.mul(treeList[_id].burnPercentage).div(100); 131 | uint256 _transferValue = _value.sub(_burnValue); 132 | SEED_CONTRACT.transferFrom(msg.sender, _burnAddress, _burnValue); 133 | SEED_CONTRACT.transferFrom(msg.sender, _owner, _transferValue); 134 | 135 | } 136 | 137 | tree.transferFrom(_owner, msg.sender, _id); 138 | 139 | treeList[_id] = Wood(false, 0, 0); 140 | 141 | emit Purchase(_owner, msg.sender, _id, _value); 142 | 143 | } 144 | 145 | } -------------------------------------------------------------------------------- /nft/Treedefi.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | pragma experimental ABIEncoderV2; 3 | 4 | import "./BEP721Full.sol"; 5 | 6 | contract Treedefi is BEP721Full { 7 | 8 | mapping(string => bool) public _isExists; 9 | mapping(uint => Tree) public _treeData; 10 | address private _owner; 11 | uint private _treeCount; 12 | 13 | /* baseURI for sending json metadata 14 | "https://afternoon-everglades-95748.herokuapp.com/api/nfts/id/" 15 | */ 16 | string private _baseURI; 17 | 18 | struct Tree { 19 | string name; 20 | string scientificName; 21 | string dateOfBirth; 22 | string country; 23 | string placeOfBirth; 24 | string placeOfResidence; 25 | string longitude; 26 | string latitude; 27 | string treeId; 28 | string url; 29 | string ImgURL; 30 | } 31 | 32 | constructor(string memory _URI, address _own) BEP721Full("Treedefi Forest", "FOREST") public { 33 | _owner = _own; 34 | _baseURI = _URI; 35 | } 36 | 37 | /** 38 | * @dev Returns the address of treedefi owner. 39 | */ 40 | function getOwner() external view returns (address) { 41 | return _owner; 42 | } 43 | 44 | /** 45 | * @dev Returns an URI for a given token ID. 46 | * Throws if the token ID does not exist. May return an empty string. 47 | * @param tokenId uint256 ID of the token to query 48 | */ 49 | function tokenURI(uint256 tokenId) external view returns (string memory) { 50 | require( 51 | _exists(tokenId), 52 | " BEP721Metadata: URI query for nonexistent token " 53 | ); 54 | 55 | string memory _id = toString(tokenId); 56 | 57 | string memory _tokenURI = concat(_baseURI, _id); 58 | 59 | return _tokenURI; 60 | 61 | } 62 | 63 | /** 64 | * @notice Change baseURI for tokenURI JSON metadata 65 | * @param _URI string baseURI to change 66 | */ 67 | function setBaseURI(string memory _URI) public { 68 | require( 69 | msg.sender == _owner, 70 | " Treedefi: Only Owner can set baseURI " 71 | ); 72 | 73 | _baseURI = _URI; 74 | 75 | } 76 | 77 | /** @dev Mint NFT and assign it to `owner`, increasing 78 | * the total supply. 79 | *@param _tree struct of value defining tree 80 | */ 81 | function mint(Tree memory _tree) public { 82 | 83 | require( 84 | msg.sender == _owner, 85 | " Treedefi: Only Owner can mint the tokens " 86 | ); 87 | 88 | require( 89 | ! _isExists[_tree.treeId], 90 | " Treedefi: token with similar tree ID already exists " 91 | ); 92 | 93 | 94 | _treeCount++; 95 | 96 | _mint(msg.sender, _treeCount); 97 | 98 | _isExists[_tree.treeId] = true; 99 | 100 | _treeData[_treeCount] = _tree; 101 | 102 | } 103 | 104 | 105 | /** 106 | * To String 107 | * 108 | * Converts an unsigned integer to the ASCII string equivalent value 109 | * 110 | * @param _base The unsigned integer to be converted to a string 111 | * @return string The resulting ASCII string value 112 | */ 113 | function toString(uint _base) 114 | internal 115 | pure 116 | returns (string memory) { 117 | bytes memory _tmp = new bytes(32); 118 | uint i; 119 | for(i = 0;_base > 0;i++) { 120 | _tmp[i] = byte(uint8((_base % 10) + 48)); 121 | _base /= 10; 122 | } 123 | bytes memory _real = new bytes(i--); 124 | for(uint j = 0; j < _real.length; j++) { 125 | _real[j] = _tmp[i--]; 126 | } 127 | return string(_real); 128 | } 129 | 130 | 131 | /** 132 | * Appends two strings together and returns a new value 133 | * 134 | * @param _base When being used for a data type this is the extended object 135 | * otherwise this is the string which will be the concatenated 136 | * prefix 137 | * @param _value The value to be the concatenated suffix 138 | * @return string The resulting string from combinging the base and value 139 | */ 140 | function concat(string memory _base, string memory _value) 141 | internal 142 | pure 143 | returns (string memory) { 144 | bytes memory _baseBytes = bytes(_base); 145 | bytes memory _valueBytes = bytes(_value); 146 | 147 | assert(_valueBytes.length > 0); 148 | 149 | string memory _tmpValue = new string(_baseBytes.length + 150 | _valueBytes.length); 151 | bytes memory _newValue = bytes(_tmpValue); 152 | 153 | uint i; 154 | uint j; 155 | 156 | for (i = 0; i < _baseBytes.length; i++) { 157 | _newValue[j++] = _baseBytes[i]; 158 | } 159 | 160 | for (i = 0; i < _valueBytes.length; i++) { 161 | _newValue[j++] = _valueBytes[i]; 162 | } 163 | 164 | return string(_newValue); 165 | } 166 | 167 | } -------------------------------------------------------------------------------- /seed/SafeMath.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity >=0.6.0 <0.8.0; 4 | 5 | /** 6 | * @dev Wrappers over Solidity's arithmetic operations with added overflow 7 | * checks. 8 | * 9 | * Arithmetic operations in Solidity wrap on overflow. This can easily result 10 | * in bugs, because programmers usually assume that an overflow raises an 11 | * error, which is the standard behavior in high level programming languages. 12 | * `SafeMath` restores this intuition by reverting the transaction when an 13 | * operation overflows. 14 | * 15 | * Using this library instead of the unchecked operations eliminates an entire 16 | * class of bugs, so it's recommended to use it always. 17 | */ 18 | library SafeMath { 19 | /** 20 | * @dev Returns the addition of two unsigned integers, reverting on 21 | * overflow. 22 | * 23 | * Counterpart to Solidity's `+` operator. 24 | * 25 | * Requirements: 26 | * 27 | * - Addition cannot overflow. 28 | */ 29 | function add(uint256 a, uint256 b) internal pure returns (uint256) { 30 | uint256 c = a + b; 31 | require(c >= a, "SafeMath: addition overflow"); 32 | 33 | return c; 34 | } 35 | 36 | /** 37 | * @dev Returns the subtraction of two unsigned integers, reverting on 38 | * overflow (when the result is negative). 39 | * 40 | * Counterpart to Solidity's `-` operator. 41 | * 42 | * Requirements: 43 | * 44 | * - Subtraction cannot overflow. 45 | */ 46 | function sub(uint256 a, uint256 b) internal pure returns (uint256) { 47 | return sub(a, b, "SafeMath: subtraction overflow"); 48 | } 49 | 50 | /** 51 | * @dev Returns the subtraction of two unsigned integers, reverting with custom message on 52 | * overflow (when the result is negative). 53 | * 54 | * Counterpart to Solidity's `-` operator. 55 | * 56 | * Requirements: 57 | * 58 | * - Subtraction cannot overflow. 59 | */ 60 | function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { 61 | require(b <= a, errorMessage); 62 | uint256 c = a - b; 63 | 64 | return c; 65 | } 66 | 67 | /** 68 | * @dev Returns the multiplication of two unsigned integers, reverting on 69 | * overflow. 70 | * 71 | * Counterpart to Solidity's `*` operator. 72 | * 73 | * Requirements: 74 | * 75 | * - Multiplication cannot overflow. 76 | */ 77 | function mul(uint256 a, uint256 b) internal pure returns (uint256) { 78 | // Gas optimization: this is cheaper than requiring 'a' not being zero, but the 79 | // benefit is lost if 'b' is also tested. 80 | // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 81 | if (a == 0) { 82 | return 0; 83 | } 84 | 85 | uint256 c = a * b; 86 | require(c / a == b, "SafeMath: multiplication overflow"); 87 | 88 | return c; 89 | } 90 | 91 | /** 92 | * @dev Returns the integer division of two unsigned integers. Reverts on 93 | * division by zero. The result is rounded towards zero. 94 | * 95 | * Counterpart to Solidity's `/` operator. Note: this function uses a 96 | * `revert` opcode (which leaves remaining gas untouched) while Solidity 97 | * uses an invalid opcode to revert (consuming all remaining gas). 98 | * 99 | * Requirements: 100 | * 101 | * - The divisor cannot be zero. 102 | */ 103 | function div(uint256 a, uint256 b) internal pure returns (uint256) { 104 | return div(a, b, "SafeMath: division by zero"); 105 | } 106 | 107 | /** 108 | * @dev Returns the integer division of two unsigned integers. Reverts with custom message on 109 | * division by zero. The result is rounded towards zero. 110 | * 111 | * Counterpart to Solidity's `/` operator. Note: this function uses a 112 | * `revert` opcode (which leaves remaining gas untouched) while Solidity 113 | * uses an invalid opcode to revert (consuming all remaining gas). 114 | * 115 | * Requirements: 116 | * 117 | * - The divisor cannot be zero. 118 | */ 119 | function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { 120 | require(b > 0, errorMessage); 121 | uint256 c = a / b; 122 | // assert(a == b * c + a % b); // There is no case in which this doesn't hold 123 | 124 | return c; 125 | } 126 | 127 | /** 128 | * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), 129 | * Reverts when dividing by zero. 130 | * 131 | * Counterpart to Solidity's `%` operator. This function uses a `revert` 132 | * opcode (which leaves remaining gas untouched) while Solidity uses an 133 | * invalid opcode to revert (consuming all remaining gas). 134 | * 135 | * Requirements: 136 | * 137 | * - The divisor cannot be zero. 138 | */ 139 | function mod(uint256 a, uint256 b) internal pure returns (uint256) { 140 | return mod(a, b, "SafeMath: modulo by zero"); 141 | } 142 | 143 | /** 144 | * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), 145 | * Reverts with custom message when dividing by zero. 146 | * 147 | * Counterpart to Solidity's `%` operator. This function uses a `revert` 148 | * opcode (which leaves remaining gas untouched) while Solidity uses an 149 | * invalid opcode to revert (consuming all remaining gas). 150 | * 151 | * Requirements: 152 | * 153 | * - The divisor cannot be zero. 154 | */ 155 | function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { 156 | require(b != 0, errorMessage); 157 | return a % b; 158 | } 159 | } -------------------------------------------------------------------------------- /seed/Address.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity >=0.6.2 <0.8.0; 4 | 5 | /** 6 | * @dev Collection of functions related to the address type 7 | */ 8 | library Address { 9 | /** 10 | * @dev Returns true if `account` is a contract. 11 | * 12 | * [IMPORTANT] 13 | * ==== 14 | * It is unsafe to assume that an address for which this function returns 15 | * false is an externally-owned account (EOA) and not a contract. 16 | * 17 | * Among others, `isContract` will return false for the following 18 | * types of addresses: 19 | * 20 | * - an externally-owned account 21 | * - a contract in construction 22 | * - an address where a contract will be created 23 | * - an address where a contract lived, but was destroyed 24 | * ==== 25 | */ 26 | function isContract(address account) internal view returns (bool) { 27 | // This method relies on extcodesize, which returns 0 for contracts in 28 | // construction, since the code is only stored at the end of the 29 | // constructor execution. 30 | 31 | uint256 size; 32 | // solhint-disable-next-line no-inline-assembly 33 | assembly { size := extcodesize(account) } 34 | return size > 0; 35 | } 36 | 37 | /** 38 | * @dev Replacement for Solidity's `transfer`: sends `amount` wei to 39 | * `recipient`, forwarding all available gas and reverting on errors. 40 | * 41 | * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost 42 | * of certain opcodes, possibly making contracts go over the 2300 gas limit 43 | * imposed by `transfer`, making them unable to receive funds via 44 | * `transfer`. {sendValue} removes this limitation. 45 | * 46 | * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. 47 | * 48 | * IMPORTANT: because control is transferred to `recipient`, care must be 49 | * taken to not create reentrancy vulnerabilities. Consider using 50 | * {ReentrancyGuard} or the 51 | * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. 52 | */ 53 | function sendValue(address payable recipient, uint256 amount) internal { 54 | require(address(this).balance >= amount, "Address: insufficient balance"); 55 | 56 | // solhint-disable-next-line avoid-low-level-calls, avoid-call-value 57 | (bool success, ) = recipient.call{ value: amount }(""); 58 | require(success, "Address: unable to send value, recipient may have reverted"); 59 | } 60 | 61 | /** 62 | * @dev Performs a Solidity function call using a low level `call`. A 63 | * plain`call` is an unsafe replacement for a function call: use this 64 | * function instead. 65 | * 66 | * If `target` reverts with a revert reason, it is bubbled up by this 67 | * function (like regular Solidity function calls). 68 | * 69 | * Returns the raw returned data. To convert to the expected return value, 70 | * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. 71 | * 72 | * Requirements: 73 | * 74 | * - `target` must be a contract. 75 | * - calling `target` with `data` must not revert. 76 | * 77 | * _Available since v3.1._ 78 | */ 79 | function functionCall(address target, bytes memory data) internal returns (bytes memory) { 80 | return functionCall(target, data, "Address: low-level call failed"); 81 | } 82 | 83 | /** 84 | * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with 85 | * `errorMessage` as a fallback revert reason when `target` reverts. 86 | * 87 | * _Available since v3.1._ 88 | */ 89 | function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { 90 | return functionCallWithValue(target, data, 0, errorMessage); 91 | } 92 | 93 | /** 94 | * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], 95 | * but also transferring `value` wei to `target`. 96 | * 97 | * Requirements: 98 | * 99 | * - the calling contract must have an ETH balance of at least `value`. 100 | * - the called Solidity function must be `payable`. 101 | * 102 | * _Available since v3.1._ 103 | */ 104 | function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { 105 | return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); 106 | } 107 | 108 | /** 109 | * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but 110 | * with `errorMessage` as a fallback revert reason when `target` reverts. 111 | * 112 | * _Available since v3.1._ 113 | */ 114 | function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { 115 | require(address(this).balance >= value, "Address: insufficient balance for call"); 116 | require(isContract(target), "Address: call to non-contract"); 117 | 118 | // solhint-disable-next-line avoid-low-level-calls 119 | (bool success, bytes memory returndata) = target.call{ value: value }(data); 120 | return _verifyCallResult(success, returndata, errorMessage); 121 | } 122 | 123 | /** 124 | * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], 125 | * but performing a static call. 126 | * 127 | * _Available since v3.3._ 128 | */ 129 | function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { 130 | return functionStaticCall(target, data, "Address: low-level static call failed"); 131 | } 132 | 133 | /** 134 | * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], 135 | * but performing a static call. 136 | * 137 | * _Available since v3.3._ 138 | */ 139 | function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) { 140 | require(isContract(target), "Address: static call to non-contract"); 141 | 142 | // solhint-disable-next-line avoid-low-level-calls 143 | (bool success, bytes memory returndata) = target.staticcall(data); 144 | return _verifyCallResult(success, returndata, errorMessage); 145 | } 146 | 147 | function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) { 148 | if (success) { 149 | return returndata; 150 | } else { 151 | // Look for revert reason and bubble it up if present 152 | if (returndata.length > 0) { 153 | // The easiest way to bubble the revert reason is using memory via assembly 154 | 155 | // solhint-disable-next-line no-inline-assembly 156 | assembly { 157 | let returndata_size := mload(returndata) 158 | revert(add(32, returndata), returndata_size) 159 | } 160 | } else { 161 | revert(errorMessage); 162 | } 163 | } 164 | } 165 | } -------------------------------------------------------------------------------- /tree/Address.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity >=0.6.2 <0.8.0; 4 | 5 | /** 6 | * @dev Collection of functions related to the address type 7 | */ 8 | library Address { 9 | /** 10 | * @dev Returns true if `account` is a contract. 11 | * 12 | * [IMPORTANT] 13 | * ==== 14 | * It is unsafe to assume that an address for which this function returns 15 | * false is an externally-owned account (EOA) and not a contract. 16 | * 17 | * Among others, `isContract` will return false for the following 18 | * types of addresses: 19 | * 20 | * - an externally-owned account 21 | * - a contract in construction 22 | * - an address where a contract will be created 23 | * - an address where a contract lived, but was destroyed 24 | * ==== 25 | */ 26 | function isContract(address account) internal view returns (bool) { 27 | // This method relies on extcodesize, which returns 0 for contracts in 28 | // construction, since the code is only stored at the end of the 29 | // constructor execution. 30 | 31 | uint256 size; 32 | // solhint-disable-next-line no-inline-assembly 33 | assembly { size := extcodesize(account) } 34 | return size > 0; 35 | } 36 | 37 | /** 38 | * @dev Replacement for Solidity's `transfer`: sends `amount` wei to 39 | * `recipient`, forwarding all available gas and reverting on errors. 40 | * 41 | * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost 42 | * of certain opcodes, possibly making contracts go over the 2300 gas limit 43 | * imposed by `transfer`, making them unable to receive funds via 44 | * `transfer`. {sendValue} removes this limitation. 45 | * 46 | * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. 47 | * 48 | * IMPORTANT: because control is transferred to `recipient`, care must be 49 | * taken to not create reentrancy vulnerabilities. Consider using 50 | * {ReentrancyGuard} or the 51 | * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. 52 | */ 53 | function sendValue(address payable recipient, uint256 amount) internal { 54 | require(address(this).balance >= amount, "Address: insufficient balance"); 55 | 56 | // solhint-disable-next-line avoid-low-level-calls, avoid-call-value 57 | (bool success, ) = recipient.call{ value: amount }(""); 58 | require(success, "Address: unable to send value, recipient may have reverted"); 59 | } 60 | 61 | /** 62 | * @dev Performs a Solidity function call using a low level `call`. A 63 | * plain`call` is an unsafe replacement for a function call: use this 64 | * function instead. 65 | * 66 | * If `target` reverts with a revert reason, it is bubbled up by this 67 | * function (like regular Solidity function calls). 68 | * 69 | * Returns the raw returned data. To convert to the expected return value, 70 | * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. 71 | * 72 | * Requirements: 73 | * 74 | * - `target` must be a contract. 75 | * - calling `target` with `data` must not revert. 76 | * 77 | * _Available since v3.1._ 78 | */ 79 | function functionCall(address target, bytes memory data) internal returns (bytes memory) { 80 | return functionCall(target, data, "Address: low-level call failed"); 81 | } 82 | 83 | /** 84 | * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with 85 | * `errorMessage` as a fallback revert reason when `target` reverts. 86 | * 87 | * _Available since v3.1._ 88 | */ 89 | function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { 90 | return functionCallWithValue(target, data, 0, errorMessage); 91 | } 92 | 93 | /** 94 | * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], 95 | * but also transferring `value` wei to `target`. 96 | * 97 | * Requirements: 98 | * 99 | * - the calling contract must have an ETH balance of at least `value`. 100 | * - the called Solidity function must be `payable`. 101 | * 102 | * _Available since v3.1._ 103 | */ 104 | function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { 105 | return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); 106 | } 107 | 108 | /** 109 | * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but 110 | * with `errorMessage` as a fallback revert reason when `target` reverts. 111 | * 112 | * _Available since v3.1._ 113 | */ 114 | function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { 115 | require(address(this).balance >= value, "Address: insufficient balance for call"); 116 | require(isContract(target), "Address: call to non-contract"); 117 | 118 | // solhint-disable-next-line avoid-low-level-calls 119 | (bool success, bytes memory returndata) = target.call{ value: value }(data); 120 | return _verifyCallResult(success, returndata, errorMessage); 121 | } 122 | 123 | /** 124 | * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], 125 | * but performing a static call. 126 | * 127 | * _Available since v3.3._ 128 | */ 129 | function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { 130 | return functionStaticCall(target, data, "Address: low-level static call failed"); 131 | } 132 | 133 | /** 134 | * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], 135 | * but performing a static call. 136 | * 137 | * _Available since v3.3._ 138 | */ 139 | function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) { 140 | require(isContract(target), "Address: static call to non-contract"); 141 | 142 | // solhint-disable-next-line avoid-low-level-calls 143 | (bool success, bytes memory returndata) = target.staticcall(data); 144 | return _verifyCallResult(success, returndata, errorMessage); 145 | } 146 | 147 | function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) { 148 | if (success) { 149 | return returndata; 150 | } else { 151 | // Look for revert reason and bubble it up if present 152 | if (returndata.length > 0) { 153 | // The easiest way to bubble the revert reason is using memory via assembly 154 | 155 | // solhint-disable-next-line no-inline-assembly 156 | assembly { 157 | let returndata_size := mload(returndata) 158 | revert(add(32, returndata), returndata_size) 159 | } 160 | } else { 161 | revert(errorMessage); 162 | } 163 | } 164 | } 165 | } -------------------------------------------------------------------------------- /seed/Bep20.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity >=0.4.0; 4 | 5 | import './Ownable.sol'; 6 | import './Context.sol'; 7 | import './IBEP20.sol'; 8 | import './SafeMath.sol'; 9 | 10 | /** 11 | * @dev Implementation of the {IBEP20} interface. 12 | * 13 | * This implementation is agnostic to the way tokens are created. This means 14 | * that a supply mechanism has to be added in a derived contract using {_mint}. 15 | * For a generic mechanism see {BEP20PresetMinterPauser}. 16 | * 17 | * TIP: For a detailed writeup see our guide 18 | * https://forum.zeppelin.solutions/t/how-to-implement-BEP20-supply-mechanisms/226[How 19 | * to implement supply mechanisms]. 20 | * 21 | * We have followed general OpenZeppelin guidelines: functions revert instead 22 | * of returning `false` on failure. This behavior is nonetheless conventional 23 | * and does not conflict with the expectations of BEP20 applications. 24 | * 25 | * Additionally, an {Approval} event is emitted on calls to {transferFrom}. 26 | * This allows applications to reconstruct the allowance for all accounts just 27 | * by listening to said events. Other implementations of the EIP may not emit 28 | * these events, as it isn't required by the specification. 29 | * 30 | * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} 31 | * functions have been added to mitigate the well-known issues around setting 32 | * allowances. See {IBEP20-approve}. 33 | */ 34 | contract BEP20 is Context, IBEP20, Ownable { 35 | using SafeMath for uint256; 36 | 37 | mapping(address => uint256) private _balances; 38 | 39 | mapping(address => mapping(address => uint256)) private _allowances; 40 | 41 | uint256 private _totalSupply; 42 | 43 | string private _name; 44 | string private _symbol; 45 | uint8 private _decimals; 46 | 47 | /** 48 | * @dev Sets the values for {name} and {symbol}, initializes {decimals} with 49 | * a default value of 18. 50 | * 51 | * To select a different value for {decimals}, use {_setupDecimals}. 52 | * 53 | * All three of these values are immutable: they can only be set once during 54 | * construction. 55 | */ 56 | constructor(string memory name, string memory symbol) public { 57 | _name = name; 58 | _symbol = symbol; 59 | _decimals = 18; 60 | } 61 | 62 | /** 63 | * @dev Returns the bep token owner. 64 | */ 65 | function getOwner() external override view returns (address) { 66 | return owner(); 67 | } 68 | 69 | /** 70 | * @dev Returns the name of the token. 71 | */ 72 | function name() public override view returns (string memory) { 73 | return _name; 74 | } 75 | 76 | /** 77 | * @dev Returns the symbol of the token, usually a shorter version of the 78 | * name. 79 | */ 80 | function symbol() public override view returns (string memory) { 81 | return _symbol; 82 | } 83 | 84 | /** 85 | * @dev Returns the number of decimals used to get its user representation. 86 | */ 87 | function decimals() public override view returns (uint8) { 88 | return _decimals; 89 | } 90 | 91 | /** 92 | * @dev See {BEP20-totalSupply}. 93 | */ 94 | function totalSupply() public override view returns (uint256) { 95 | return _totalSupply; 96 | } 97 | 98 | /** 99 | * @dev See {BEP20-balanceOf}. 100 | */ 101 | function balanceOf(address account) public override view returns (uint256) { 102 | return _balances[account]; 103 | } 104 | 105 | /** 106 | * @dev See {BEP20-transfer}. 107 | * 108 | * Requirements: 109 | * 110 | * - `recipient` cannot be the zero address. 111 | * - the caller must have a balance of at least `amount`. 112 | */ 113 | function transfer(address recipient, uint256 amount) public override returns (bool) { 114 | _transfer(_msgSender(), recipient, amount); 115 | return true; 116 | } 117 | 118 | /** 119 | * @dev See {BEP20-allowance}. 120 | */ 121 | function allowance(address owner, address spender) public override view returns (uint256) { 122 | return _allowances[owner][spender]; 123 | } 124 | 125 | /** 126 | * @dev See {BEP20-approve}. 127 | * 128 | * Requirements: 129 | * 130 | * - `spender` cannot be the zero address. 131 | */ 132 | function approve(address spender, uint256 amount) public override returns (bool) { 133 | _approve(_msgSender(), spender, amount); 134 | return true; 135 | } 136 | 137 | /** 138 | * @dev See {BEP20-transferFrom}. 139 | * 140 | * Emits an {Approval} event indicating the updated allowance. This is not 141 | * required by the EIP. See the note at the beginning of {BEP20}; 142 | * 143 | * Requirements: 144 | * - `sender` and `recipient` cannot be the zero address. 145 | * - `sender` must have a balance of at least `amount`. 146 | * - the caller must have allowance for `sender`'s tokens of at least 147 | * `amount`. 148 | */ 149 | function transferFrom (address sender, address recipient, uint256 amount) public override returns (bool) { 150 | _transfer(sender, recipient, amount); 151 | _approve( 152 | sender, 153 | _msgSender(), 154 | _allowances[sender][_msgSender()].sub(amount, 'BEP20: transfer amount exceeds allowance') 155 | ); 156 | return true; 157 | } 158 | 159 | /** 160 | * @dev Atomically increases the allowance granted to `spender` by the caller. 161 | * 162 | * This is an alternative to {approve} that can be used as a mitigation for 163 | * problems described in {BEP20-approve}. 164 | * 165 | * Emits an {Approval} event indicating the updated allowance. 166 | * 167 | * Requirements: 168 | * 169 | * - `spender` cannot be the zero address. 170 | */ 171 | function increaseAllowance(address spender, uint256 addedValue) public returns (bool) { 172 | _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); 173 | return true; 174 | } 175 | 176 | /** 177 | * @dev Atomically decreases the allowance granted to `spender` by the caller. 178 | * 179 | * This is an alternative to {approve} that can be used as a mitigation for 180 | * problems described in {BEP20-approve}. 181 | * 182 | * Emits an {Approval} event indicating the updated allowance. 183 | * 184 | * Requirements: 185 | * 186 | * - `spender` cannot be the zero address. 187 | * - `spender` must have allowance for the caller of at least 188 | * `subtractedValue`. 189 | */ 190 | function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) { 191 | _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, 'BEP20: decreased allowance below zero')); 192 | return true; 193 | } 194 | 195 | /** 196 | * @dev Creates `amount` tokens and assigns them to `msg.sender`, increasing 197 | * the total supply. 198 | * 199 | * Requirements 200 | * 201 | * - `msg.sender` must be the token owner 202 | */ 203 | function mint(uint256 amount) public onlyOwner returns (bool) { 204 | _mint(_msgSender(), amount); 205 | return true; 206 | } 207 | 208 | /** 209 | * @dev Moves tokens `amount` from `sender` to `recipient`. 210 | * 211 | * This is internal function is equivalent to {transfer}, and can be used to 212 | * e.g. implement automatic token fees, slashing mechanisms, etc. 213 | * 214 | * Emits a {Transfer} event. 215 | * 216 | * Requirements: 217 | * 218 | * - `sender` cannot be the zero address. 219 | * - `recipient` cannot be the zero address. 220 | * - `sender` must have a balance of at least `amount`. 221 | */ 222 | function _transfer (address sender, address recipient, uint256 amount) internal { 223 | require(sender != address(0), 'BEP20: transfer from the zero address'); 224 | require(recipient != address(0), 'BEP20: transfer to the zero address'); 225 | 226 | _balances[sender] = _balances[sender].sub(amount, 'BEP20: transfer amount exceeds balance'); 227 | _balances[recipient] = _balances[recipient].add(amount); 228 | emit Transfer(sender, recipient, amount); 229 | } 230 | 231 | /** @dev Creates `amount` tokens and assigns them to `account`, increasing 232 | * the total supply. 233 | * 234 | * Emits a {Transfer} event with `from` set to the zero address. 235 | * 236 | * Requirements 237 | * 238 | * - `to` cannot be the zero address. 239 | */ 240 | function _mint(address account, uint256 amount) internal { 241 | require(account != address(0), 'BEP20: mint to the zero address'); 242 | 243 | _totalSupply = _totalSupply.add(amount); 244 | _balances[account] = _balances[account].add(amount); 245 | emit Transfer(address(0), account, amount); 246 | } 247 | 248 | /** 249 | * @dev Destroys `amount` tokens from `account`, reducing the 250 | * total supply. 251 | * 252 | * Emits a {Transfer} event with `to` set to the zero address. 253 | * 254 | * Requirements 255 | * 256 | * - `account` cannot be the zero address. 257 | * - `account` must have at least `amount` tokens. 258 | */ 259 | function _burn(address account, uint256 amount) internal { 260 | require(account != address(0), 'BEP20: burn from the zero address'); 261 | 262 | _balances[account] = _balances[account].sub(amount, 'BEP20: burn amount exceeds balance'); 263 | _totalSupply = _totalSupply.sub(amount); 264 | emit Transfer(account, address(0), amount); 265 | } 266 | 267 | /** 268 | * @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens. 269 | * 270 | * This is internal function is equivalent to `approve`, and can be used to 271 | * e.g. set automatic allowances for certain subsystems, etc. 272 | * 273 | * Emits an {Approval} event. 274 | * 275 | * Requirements: 276 | * 277 | * - `owner` cannot be the zero address. 278 | * - `spender` cannot be the zero address. 279 | */ 280 | function _approve (address owner, address spender, uint256 amount) internal { 281 | require(owner != address(0), 'BEP20: approve from the zero address'); 282 | require(spender != address(0), 'BEP20: approve to the zero address'); 283 | 284 | _allowances[owner][spender] = amount; 285 | emit Approval(owner, spender, amount); 286 | } 287 | 288 | /** 289 | * @dev Destroys `amount` tokens from `account`.`amount` is then deducted 290 | * from the caller's allowance. 291 | * 292 | * See {_burn} and {_approve}. 293 | */ 294 | function _burnFrom(address account, uint256 amount) internal { 295 | _burn(account, amount); 296 | _approve(account, _msgSender(), _allowances[account][_msgSender()].sub(amount, 'BEP20: burn amount exceeds allowance')); 297 | } 298 | } -------------------------------------------------------------------------------- /tree/BEP20.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity >=0.4.0; 4 | 5 | import './Ownable.sol'; 6 | import './Context.sol'; 7 | import './IBEP20.sol'; 8 | import './SafeMath.sol'; 9 | 10 | /** 11 | * @dev Implementation of the {IBEP20} interface. 12 | * 13 | * This implementation is agnostic to the way tokens are created. This means 14 | * that a supply mechanism has to be added in a derived contract using {_mint}. 15 | * For a generic mechanism see {BEP20PresetMinterPauser}. 16 | * 17 | * TIP: For a detailed writeup see our guide 18 | * https://forum.zeppelin.solutions/t/how-to-implement-BEP20-supply-mechanisms/226[How 19 | * to implement supply mechanisms]. 20 | * 21 | * We have followed general OpenZeppelin guidelines: functions revert instead 22 | * of returning `false` on failure. This behavior is nonetheless conventional 23 | * and does not conflict with the expectations of BEP20 applications. 24 | * 25 | * Additionally, an {Approval} event is emitted on calls to {transferFrom}. 26 | * This allows applications to reconstruct the allowance for all accounts just 27 | * by listening to said events. Other implementations of the EIP may not emit 28 | * these events, as it isn't required by the specification. 29 | * 30 | * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} 31 | * functions have been added to mitigate the well-known issues around setting 32 | * allowances. See {IBEP20-approve}. 33 | */ 34 | contract BEP20 is Context, IBEP20, Ownable { 35 | using SafeMath for uint256; 36 | 37 | mapping(address => uint256) private _balances; 38 | 39 | mapping(address => mapping(address => uint256)) private _allowances; 40 | 41 | uint256 private _totalSupply; 42 | 43 | string private _name; 44 | string private _symbol; 45 | uint8 private _decimals; 46 | 47 | /** 48 | * @dev Sets the values for {name} and {symbol}, initializes {decimals} with 49 | * a default value of 18. 50 | * 51 | * To select a different value for {decimals}, use {_setupDecimals}. 52 | * 53 | * All three of these values are immutable: they can only be set once during 54 | * construction. 55 | */ 56 | constructor(string memory name, string memory symbol) public { 57 | _name = name; 58 | _symbol = symbol; 59 | _decimals = 18; 60 | } 61 | 62 | /** 63 | * @dev Returns the bep token owner. 64 | */ 65 | function getOwner() external override view returns (address) { 66 | return owner(); 67 | } 68 | 69 | /** 70 | * @dev Returns the name of the token. 71 | */ 72 | function name() public override view returns (string memory) { 73 | return _name; 74 | } 75 | 76 | /** 77 | * @dev Returns the symbol of the token, usually a shorter version of the 78 | * name. 79 | */ 80 | function symbol() public override view returns (string memory) { 81 | return _symbol; 82 | } 83 | 84 | /** 85 | * @dev Returns the number of decimals used to get its user representation. 86 | */ 87 | function decimals() public override view returns (uint8) { 88 | return _decimals; 89 | } 90 | 91 | /** 92 | * @dev See {BEP20-totalSupply}. 93 | */ 94 | function totalSupply() public override view returns (uint256) { 95 | return _totalSupply; 96 | } 97 | 98 | /** 99 | * @dev See {BEP20-balanceOf}. 100 | */ 101 | function balanceOf(address account) public override view returns (uint256) { 102 | return _balances[account]; 103 | } 104 | 105 | /** 106 | * @dev See {BEP20-transfer}. 107 | * 108 | * Requirements: 109 | * 110 | * - `recipient` cannot be the zero address. 111 | * - the caller must have a balance of at least `amount`. 112 | */ 113 | function transfer(address recipient, uint256 amount) public override returns (bool) { 114 | _transfer(_msgSender(), recipient, amount); 115 | return true; 116 | } 117 | 118 | /** 119 | * @dev See {BEP20-allowance}. 120 | */ 121 | function allowance(address owner, address spender) public override view returns (uint256) { 122 | return _allowances[owner][spender]; 123 | } 124 | 125 | /** 126 | * @dev See {BEP20-approve}. 127 | * 128 | * Requirements: 129 | * 130 | * - `spender` cannot be the zero address. 131 | */ 132 | function approve(address spender, uint256 amount) public override returns (bool) { 133 | _approve(_msgSender(), spender, amount); 134 | return true; 135 | } 136 | 137 | /** 138 | * @dev See {BEP20-transferFrom}. 139 | * 140 | * Emits an {Approval} event indicating the updated allowance. This is not 141 | * required by the EIP. See the note at the beginning of {BEP20}; 142 | * 143 | * Requirements: 144 | * - `sender` and `recipient` cannot be the zero address. 145 | * - `sender` must have a balance of at least `amount`. 146 | * - the caller must have allowance for `sender`'s tokens of at least 147 | * `amount`. 148 | */ 149 | function transferFrom (address sender, address recipient, uint256 amount) public override returns (bool) { 150 | _transfer(sender, recipient, amount); 151 | _approve( 152 | sender, 153 | _msgSender(), 154 | _allowances[sender][_msgSender()].sub(amount, 'BEP20: transfer amount exceeds allowance') 155 | ); 156 | return true; 157 | } 158 | 159 | /** 160 | * @dev Atomically increases the allowance granted to `spender` by the caller. 161 | * 162 | * This is an alternative to {approve} that can be used as a mitigation for 163 | * problems described in {BEP20-approve}. 164 | * 165 | * Emits an {Approval} event indicating the updated allowance. 166 | * 167 | * Requirements: 168 | * 169 | * - `spender` cannot be the zero address. 170 | */ 171 | function increaseAllowance(address spender, uint256 addedValue) public returns (bool) { 172 | _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); 173 | return true; 174 | } 175 | 176 | /** 177 | * @dev Atomically decreases the allowance granted to `spender` by the caller. 178 | * 179 | * This is an alternative to {approve} that can be used as a mitigation for 180 | * problems described in {BEP20-approve}. 181 | * 182 | * Emits an {Approval} event indicating the updated allowance. 183 | * 184 | * Requirements: 185 | * 186 | * - `spender` cannot be the zero address. 187 | * - `spender` must have allowance for the caller of at least 188 | * `subtractedValue`. 189 | */ 190 | function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) { 191 | _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, 'BEP20: decreased allowance below zero')); 192 | return true; 193 | } 194 | 195 | /** 196 | * @dev Creates `amount` tokens and assigns them to `msg.sender`, increasing 197 | * the total supply. 198 | * 199 | * Requirements 200 | * 201 | * - `msg.sender` must be the token owner 202 | */ 203 | function mint(uint256 amount) public onlyOwner returns (bool) { 204 | _mint(_msgSender(), amount); 205 | return true; 206 | } 207 | 208 | /** 209 | * @dev Moves tokens `amount` from `sender` to `recipient`. 210 | * 211 | * This is internal function is equivalent to {transfer}, and can be used to 212 | * e.g. implement automatic token fees, slashing mechanisms, etc. 213 | * 214 | * Emits a {Transfer} event. 215 | * 216 | * Requirements: 217 | * 218 | * - `sender` cannot be the zero address. 219 | * - `recipient` cannot be the zero address. 220 | * - `sender` must have a balance of at least `amount`. 221 | */ 222 | function _transfer (address sender, address recipient, uint256 amount) internal { 223 | require(sender != address(0), 'BEP20: transfer from the zero address'); 224 | require(recipient != address(0), 'BEP20: transfer to the zero address'); 225 | 226 | _balances[sender] = _balances[sender].sub(amount, 'BEP20: transfer amount exceeds balance'); 227 | _balances[recipient] = _balances[recipient].add(amount); 228 | emit Transfer(sender, recipient, amount); 229 | } 230 | 231 | /** @dev Creates `amount` tokens and assigns them to `account`, increasing 232 | * the total supply. 233 | * 234 | * Emits a {Transfer} event with `from` set to the zero address. 235 | * 236 | * Requirements 237 | * 238 | * - `to` cannot be the zero address. 239 | */ 240 | function _mint(address account, uint256 amount) internal { 241 | require(account != address(0), 'BEP20: mint to the zero address'); 242 | 243 | _totalSupply = _totalSupply.add(amount); 244 | _balances[account] = _balances[account].add(amount); 245 | emit Transfer(address(0), account, amount); 246 | } 247 | 248 | /** 249 | * @dev Destroys `amount` tokens from `account`, reducing the 250 | * total supply. 251 | * 252 | * Emits a {Transfer} event with `to` set to the zero address. 253 | * 254 | * Requirements 255 | * 256 | * - `account` cannot be the zero address. 257 | * - `account` must have at least `amount` tokens. 258 | */ 259 | function _burn(address account, uint256 amount) internal { 260 | require(account != address(0), 'BEP20: burn from the zero address'); 261 | 262 | _balances[account] = _balances[account].sub(amount, 'BEP20: burn amount exceeds balance'); 263 | _totalSupply = _totalSupply.sub(amount); 264 | emit Transfer(account, address(0), amount); 265 | } 266 | 267 | /** 268 | * @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens. 269 | * 270 | * This is internal function is equivalent to `approve`, and can be used to 271 | * e.g. set automatic allowances for certain subsystems, etc. 272 | * 273 | * Emits an {Approval} event. 274 | * 275 | * Requirements: 276 | * 277 | * - `owner` cannot be the zero address. 278 | * - `spender` cannot be the zero address. 279 | */ 280 | function _approve (address owner, address spender, uint256 amount) internal { 281 | require(owner != address(0), 'BEP20: approve from the zero address'); 282 | require(spender != address(0), 'BEP20: approve to the zero address'); 283 | 284 | _allowances[owner][spender] = amount; 285 | emit Approval(owner, spender, amount); 286 | } 287 | 288 | /** 289 | * @dev Destroys `amount` tokens from `account`.`amount` is then deducted 290 | * from the caller's allowance. 291 | * 292 | * See {_burn} and {_approve}. 293 | */ 294 | function _burnFrom(address account, uint256 amount) internal { 295 | _burn(account, amount); 296 | _approve(account, _msgSender(), _allowances[account][_msgSender()].sub(amount, 'BEP20: burn amount exceeds allowance')); 297 | } 298 | } -------------------------------------------------------------------------------- /tree/Context.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity >=0.4.0; 4 | 5 | import './Ownable.sol'; 6 | import './Context.sol'; 7 | import './IBEP20.sol'; 8 | import './SafeMath.sol'; 9 | 10 | /** 11 | * @dev Implementation of the {IBEP20} interface. 12 | * 13 | * This implementation is agnostic to the way tokens are created. This means 14 | * that a supply mechanism has to be added in a derived contract using {_mint}. 15 | * For a generic mechanism see {BEP20PresetMinterPauser}. 16 | * 17 | * TIP: For a detailed writeup see our guide 18 | * https://forum.zeppelin.solutions/t/how-to-implement-BEP20-supply-mechanisms/226[How 19 | * to implement supply mechanisms]. 20 | * 21 | * We have followed general OpenZeppelin guidelines: functions revert instead 22 | * of returning `false` on failure. This behavior is nonetheless conventional 23 | * and does not conflict with the expectations of BEP20 applications. 24 | * 25 | * Additionally, an {Approval} event is emitted on calls to {transferFrom}. 26 | * This allows applications to reconstruct the allowance for all accounts just 27 | * by listening to said events. Other implementations of the EIP may not emit 28 | * these events, as it isn't required by the specification. 29 | * 30 | * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} 31 | * functions have been added to mitigate the well-known issues around setting 32 | * allowances. See {IBEP20-approve}. 33 | */ 34 | contract BEP20 is Context, IBEP20, Ownable { 35 | using SafeMath for uint256; 36 | 37 | mapping(address => uint256) private _balances; 38 | 39 | mapping(address => mapping(address => uint256)) private _allowances; 40 | 41 | uint256 private _totalSupply; 42 | 43 | string private _name; 44 | string private _symbol; 45 | uint8 private _decimals; 46 | 47 | /** 48 | * @dev Sets the values for {name} and {symbol}, initializes {decimals} with 49 | * a default value of 18. 50 | * 51 | * To select a different value for {decimals}, use {_setupDecimals}. 52 | * 53 | * All three of these values are immutable: they can only be set once during 54 | * construction. 55 | */ 56 | constructor(string memory name, string memory symbol) public { 57 | _name = name; 58 | _symbol = symbol; 59 | _decimals = 18; 60 | } 61 | 62 | /** 63 | * @dev Returns the bep token owner. 64 | */ 65 | function getOwner() external override view returns (address) { 66 | return owner(); 67 | } 68 | 69 | /** 70 | * @dev Returns the name of the token. 71 | */ 72 | function name() public override view returns (string memory) { 73 | return _name; 74 | } 75 | 76 | /** 77 | * @dev Returns the symbol of the token, usually a shorter version of the 78 | * name. 79 | */ 80 | function symbol() public override view returns (string memory) { 81 | return _symbol; 82 | } 83 | 84 | /** 85 | * @dev Returns the number of decimals used to get its user representation. 86 | */ 87 | function decimals() public override view returns (uint8) { 88 | return _decimals; 89 | } 90 | 91 | /** 92 | * @dev See {BEP20-totalSupply}. 93 | */ 94 | function totalSupply() public override view returns (uint256) { 95 | return _totalSupply; 96 | } 97 | 98 | /** 99 | * @dev See {BEP20-balanceOf}. 100 | */ 101 | function balanceOf(address account) public override view returns (uint256) { 102 | return _balances[account]; 103 | } 104 | 105 | /** 106 | * @dev See {BEP20-transfer}. 107 | * 108 | * Requirements: 109 | * 110 | * - `recipient` cannot be the zero address. 111 | * - the caller must have a balance of at least `amount`. 112 | */ 113 | function transfer(address recipient, uint256 amount) public override returns (bool) { 114 | _transfer(_msgSender(), recipient, amount); 115 | return true; 116 | } 117 | 118 | /** 119 | * @dev See {BEP20-allowance}. 120 | */ 121 | function allowance(address owner, address spender) public override view returns (uint256) { 122 | return _allowances[owner][spender]; 123 | } 124 | 125 | /** 126 | * @dev See {BEP20-approve}. 127 | * 128 | * Requirements: 129 | * 130 | * - `spender` cannot be the zero address. 131 | */ 132 | function approve(address spender, uint256 amount) public override returns (bool) { 133 | _approve(_msgSender(), spender, amount); 134 | return true; 135 | } 136 | 137 | /** 138 | * @dev See {BEP20-transferFrom}. 139 | * 140 | * Emits an {Approval} event indicating the updated allowance. This is not 141 | * required by the EIP. See the note at the beginning of {BEP20}; 142 | * 143 | * Requirements: 144 | * - `sender` and `recipient` cannot be the zero address. 145 | * - `sender` must have a balance of at least `amount`. 146 | * - the caller must have allowance for `sender`'s tokens of at least 147 | * `amount`. 148 | */ 149 | function transferFrom (address sender, address recipient, uint256 amount) public override returns (bool) { 150 | _transfer(sender, recipient, amount); 151 | _approve( 152 | sender, 153 | _msgSender(), 154 | _allowances[sender][_msgSender()].sub(amount, 'BEP20: transfer amount exceeds allowance') 155 | ); 156 | return true; 157 | } 158 | 159 | /** 160 | * @dev Atomically increases the allowance granted to `spender` by the caller. 161 | * 162 | * This is an alternative to {approve} that can be used as a mitigation for 163 | * problems described in {BEP20-approve}. 164 | * 165 | * Emits an {Approval} event indicating the updated allowance. 166 | * 167 | * Requirements: 168 | * 169 | * - `spender` cannot be the zero address. 170 | */ 171 | function increaseAllowance(address spender, uint256 addedValue) public returns (bool) { 172 | _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); 173 | return true; 174 | } 175 | 176 | /** 177 | * @dev Atomically decreases the allowance granted to `spender` by the caller. 178 | * 179 | * This is an alternative to {approve} that can be used as a mitigation for 180 | * problems described in {BEP20-approve}. 181 | * 182 | * Emits an {Approval} event indicating the updated allowance. 183 | * 184 | * Requirements: 185 | * 186 | * - `spender` cannot be the zero address. 187 | * - `spender` must have allowance for the caller of at least 188 | * `subtractedValue`. 189 | */ 190 | function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) { 191 | _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, 'BEP20: decreased allowance below zero')); 192 | return true; 193 | } 194 | 195 | /** 196 | * @dev Creates `amount` tokens and assigns them to `msg.sender`, increasing 197 | * the total supply. 198 | * 199 | * Requirements 200 | * 201 | * - `msg.sender` must be the token owner 202 | */ 203 | function mint(uint256 amount) public onlyOwner returns (bool) { 204 | _mint(_msgSender(), amount); 205 | return true; 206 | } 207 | 208 | /** 209 | * @dev Moves tokens `amount` from `sender` to `recipient`. 210 | * 211 | * This is internal function is equivalent to {transfer}, and can be used to 212 | * e.g. implement automatic token fees, slashing mechanisms, etc. 213 | * 214 | * Emits a {Transfer} event. 215 | * 216 | * Requirements: 217 | * 218 | * - `sender` cannot be the zero address. 219 | * - `recipient` cannot be the zero address. 220 | * - `sender` must have a balance of at least `amount`. 221 | */ 222 | function _transfer (address sender, address recipient, uint256 amount) internal { 223 | require(sender != address(0), 'BEP20: transfer from the zero address'); 224 | require(recipient != address(0), 'BEP20: transfer to the zero address'); 225 | 226 | _balances[sender] = _balances[sender].sub(amount, 'BEP20: transfer amount exceeds balance'); 227 | _balances[recipient] = _balances[recipient].add(amount); 228 | emit Transfer(sender, recipient, amount); 229 | } 230 | 231 | /** @dev Creates `amount` tokens and assigns them to `account`, increasing 232 | * the total supply. 233 | * 234 | * Emits a {Transfer} event with `from` set to the zero address. 235 | * 236 | * Requirements 237 | * 238 | * - `to` cannot be the zero address. 239 | */ 240 | function _mint(address account, uint256 amount) internal { 241 | require(account != address(0), 'BEP20: mint to the zero address'); 242 | 243 | _totalSupply = _totalSupply.add(amount); 244 | _balances[account] = _balances[account].add(amount); 245 | emit Transfer(address(0), account, amount); 246 | } 247 | 248 | /** 249 | * @dev Destroys `amount` tokens from `account`, reducing the 250 | * total supply. 251 | * 252 | * Emits a {Transfer} event with `to` set to the zero address. 253 | * 254 | * Requirements 255 | * 256 | * - `account` cannot be the zero address. 257 | * - `account` must have at least `amount` tokens. 258 | */ 259 | function _burn(address account, uint256 amount) internal { 260 | require(account != address(0), 'BEP20: burn from the zero address'); 261 | 262 | _balances[account] = _balances[account].sub(amount, 'BEP20: burn amount exceeds balance'); 263 | _totalSupply = _totalSupply.sub(amount); 264 | emit Transfer(account, address(0), amount); 265 | } 266 | 267 | /** 268 | * @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens. 269 | * 270 | * This is internal function is equivalent to `approve`, and can be used to 271 | * e.g. set automatic allowances for certain subsystems, etc. 272 | * 273 | * Emits an {Approval} event. 274 | * 275 | * Requirements: 276 | * 277 | * - `owner` cannot be the zero address. 278 | * - `spender` cannot be the zero address. 279 | */ 280 | function _approve (address owner, address spender, uint256 amount) internal { 281 | require(owner != address(0), 'BEP20: approve from the zero address'); 282 | require(spender != address(0), 'BEP20: approve to the zero address'); 283 | 284 | _allowances[owner][spender] = amount; 285 | emit Approval(owner, spender, amount); 286 | } 287 | 288 | /** 289 | * @dev Destroys `amount` tokens from `account`.`amount` is then deducted 290 | * from the caller's allowance. 291 | * 292 | * See {_burn} and {_approve}. 293 | */ 294 | function _burnFrom(address account, uint256 amount) internal { 295 | _burn(account, amount); 296 | _approve(account, _msgSender(), _allowances[account][_msgSender()].sub(amount, 'BEP20: burn amount exceeds allowance')); 297 | } 298 | } -------------------------------------------------------------------------------- /tree/IBEP20.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity >=0.4.0; 4 | 5 | import './Ownable.sol'; 6 | import './Context.sol'; 7 | import './IBEP20.sol'; 8 | import './SafeMath.sol'; 9 | 10 | /** 11 | * @dev Implementation of the {IBEP20} interface. 12 | * 13 | * This implementation is agnostic to the way tokens are created. This means 14 | * that a supply mechanism has to be added in a derived contract using {_mint}. 15 | * For a generic mechanism see {BEP20PresetMinterPauser}. 16 | * 17 | * TIP: For a detailed writeup see our guide 18 | * https://forum.zeppelin.solutions/t/how-to-implement-BEP20-supply-mechanisms/226[How 19 | * to implement supply mechanisms]. 20 | * 21 | * We have followed general OpenZeppelin guidelines: functions revert instead 22 | * of returning `false` on failure. This behavior is nonetheless conventional 23 | * and does not conflict with the expectations of BEP20 applications. 24 | * 25 | * Additionally, an {Approval} event is emitted on calls to {transferFrom}. 26 | * This allows applications to reconstruct the allowance for all accounts just 27 | * by listening to said events. Other implementations of the EIP may not emit 28 | * these events, as it isn't required by the specification. 29 | * 30 | * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} 31 | * functions have been added to mitigate the well-known issues around setting 32 | * allowances. See {IBEP20-approve}. 33 | */ 34 | contract BEP20 is Context, IBEP20, Ownable { 35 | using SafeMath for uint256; 36 | 37 | mapping(address => uint256) private _balances; 38 | 39 | mapping(address => mapping(address => uint256)) private _allowances; 40 | 41 | uint256 private _totalSupply; 42 | 43 | string private _name; 44 | string private _symbol; 45 | uint8 private _decimals; 46 | 47 | /** 48 | * @dev Sets the values for {name} and {symbol}, initializes {decimals} with 49 | * a default value of 18. 50 | * 51 | * To select a different value for {decimals}, use {_setupDecimals}. 52 | * 53 | * All three of these values are immutable: they can only be set once during 54 | * construction. 55 | */ 56 | constructor(string memory name, string memory symbol) public { 57 | _name = name; 58 | _symbol = symbol; 59 | _decimals = 18; 60 | } 61 | 62 | /** 63 | * @dev Returns the bep token owner. 64 | */ 65 | function getOwner() external override view returns (address) { 66 | return owner(); 67 | } 68 | 69 | /** 70 | * @dev Returns the name of the token. 71 | */ 72 | function name() public override view returns (string memory) { 73 | return _name; 74 | } 75 | 76 | /** 77 | * @dev Returns the symbol of the token, usually a shorter version of the 78 | * name. 79 | */ 80 | function symbol() public override view returns (string memory) { 81 | return _symbol; 82 | } 83 | 84 | /** 85 | * @dev Returns the number of decimals used to get its user representation. 86 | */ 87 | function decimals() public override view returns (uint8) { 88 | return _decimals; 89 | } 90 | 91 | /** 92 | * @dev See {BEP20-totalSupply}. 93 | */ 94 | function totalSupply() public override view returns (uint256) { 95 | return _totalSupply; 96 | } 97 | 98 | /** 99 | * @dev See {BEP20-balanceOf}. 100 | */ 101 | function balanceOf(address account) public override view returns (uint256) { 102 | return _balances[account]; 103 | } 104 | 105 | /** 106 | * @dev See {BEP20-transfer}. 107 | * 108 | * Requirements: 109 | * 110 | * - `recipient` cannot be the zero address. 111 | * - the caller must have a balance of at least `amount`. 112 | */ 113 | function transfer(address recipient, uint256 amount) public override returns (bool) { 114 | _transfer(_msgSender(), recipient, amount); 115 | return true; 116 | } 117 | 118 | /** 119 | * @dev See {BEP20-allowance}. 120 | */ 121 | function allowance(address owner, address spender) public override view returns (uint256) { 122 | return _allowances[owner][spender]; 123 | } 124 | 125 | /** 126 | * @dev See {BEP20-approve}. 127 | * 128 | * Requirements: 129 | * 130 | * - `spender` cannot be the zero address. 131 | */ 132 | function approve(address spender, uint256 amount) public override returns (bool) { 133 | _approve(_msgSender(), spender, amount); 134 | return true; 135 | } 136 | 137 | /** 138 | * @dev See {BEP20-transferFrom}. 139 | * 140 | * Emits an {Approval} event indicating the updated allowance. This is not 141 | * required by the EIP. See the note at the beginning of {BEP20}; 142 | * 143 | * Requirements: 144 | * - `sender` and `recipient` cannot be the zero address. 145 | * - `sender` must have a balance of at least `amount`. 146 | * - the caller must have allowance for `sender`'s tokens of at least 147 | * `amount`. 148 | */ 149 | function transferFrom (address sender, address recipient, uint256 amount) public override returns (bool) { 150 | _transfer(sender, recipient, amount); 151 | _approve( 152 | sender, 153 | _msgSender(), 154 | _allowances[sender][_msgSender()].sub(amount, 'BEP20: transfer amount exceeds allowance') 155 | ); 156 | return true; 157 | } 158 | 159 | /** 160 | * @dev Atomically increases the allowance granted to `spender` by the caller. 161 | * 162 | * This is an alternative to {approve} that can be used as a mitigation for 163 | * problems described in {BEP20-approve}. 164 | * 165 | * Emits an {Approval} event indicating the updated allowance. 166 | * 167 | * Requirements: 168 | * 169 | * - `spender` cannot be the zero address. 170 | */ 171 | function increaseAllowance(address spender, uint256 addedValue) public returns (bool) { 172 | _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); 173 | return true; 174 | } 175 | 176 | /** 177 | * @dev Atomically decreases the allowance granted to `spender` by the caller. 178 | * 179 | * This is an alternative to {approve} that can be used as a mitigation for 180 | * problems described in {BEP20-approve}. 181 | * 182 | * Emits an {Approval} event indicating the updated allowance. 183 | * 184 | * Requirements: 185 | * 186 | * - `spender` cannot be the zero address. 187 | * - `spender` must have allowance for the caller of at least 188 | * `subtractedValue`. 189 | */ 190 | function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) { 191 | _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, 'BEP20: decreased allowance below zero')); 192 | return true; 193 | } 194 | 195 | /** 196 | * @dev Creates `amount` tokens and assigns them to `msg.sender`, increasing 197 | * the total supply. 198 | * 199 | * Requirements 200 | * 201 | * - `msg.sender` must be the token owner 202 | */ 203 | function mint(uint256 amount) public onlyOwner returns (bool) { 204 | _mint(_msgSender(), amount); 205 | return true; 206 | } 207 | 208 | /** 209 | * @dev Moves tokens `amount` from `sender` to `recipient`. 210 | * 211 | * This is internal function is equivalent to {transfer}, and can be used to 212 | * e.g. implement automatic token fees, slashing mechanisms, etc. 213 | * 214 | * Emits a {Transfer} event. 215 | * 216 | * Requirements: 217 | * 218 | * - `sender` cannot be the zero address. 219 | * - `recipient` cannot be the zero address. 220 | * - `sender` must have a balance of at least `amount`. 221 | */ 222 | function _transfer (address sender, address recipient, uint256 amount) internal { 223 | require(sender != address(0), 'BEP20: transfer from the zero address'); 224 | require(recipient != address(0), 'BEP20: transfer to the zero address'); 225 | 226 | _balances[sender] = _balances[sender].sub(amount, 'BEP20: transfer amount exceeds balance'); 227 | _balances[recipient] = _balances[recipient].add(amount); 228 | emit Transfer(sender, recipient, amount); 229 | } 230 | 231 | /** @dev Creates `amount` tokens and assigns them to `account`, increasing 232 | * the total supply. 233 | * 234 | * Emits a {Transfer} event with `from` set to the zero address. 235 | * 236 | * Requirements 237 | * 238 | * - `to` cannot be the zero address. 239 | */ 240 | function _mint(address account, uint256 amount) internal { 241 | require(account != address(0), 'BEP20: mint to the zero address'); 242 | 243 | _totalSupply = _totalSupply.add(amount); 244 | _balances[account] = _balances[account].add(amount); 245 | emit Transfer(address(0), account, amount); 246 | } 247 | 248 | /** 249 | * @dev Destroys `amount` tokens from `account`, reducing the 250 | * total supply. 251 | * 252 | * Emits a {Transfer} event with `to` set to the zero address. 253 | * 254 | * Requirements 255 | * 256 | * - `account` cannot be the zero address. 257 | * - `account` must have at least `amount` tokens. 258 | */ 259 | function _burn(address account, uint256 amount) internal { 260 | require(account != address(0), 'BEP20: burn from the zero address'); 261 | 262 | _balances[account] = _balances[account].sub(amount, 'BEP20: burn amount exceeds balance'); 263 | _totalSupply = _totalSupply.sub(amount); 264 | emit Transfer(account, address(0), amount); 265 | } 266 | 267 | /** 268 | * @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens. 269 | * 270 | * This is internal function is equivalent to `approve`, and can be used to 271 | * e.g. set automatic allowances for certain subsystems, etc. 272 | * 273 | * Emits an {Approval} event. 274 | * 275 | * Requirements: 276 | * 277 | * - `owner` cannot be the zero address. 278 | * - `spender` cannot be the zero address. 279 | */ 280 | function _approve (address owner, address spender, uint256 amount) internal { 281 | require(owner != address(0), 'BEP20: approve from the zero address'); 282 | require(spender != address(0), 'BEP20: approve to the zero address'); 283 | 284 | _allowances[owner][spender] = amount; 285 | emit Approval(owner, spender, amount); 286 | } 287 | 288 | /** 289 | * @dev Destroys `amount` tokens from `account`.`amount` is then deducted 290 | * from the caller's allowance. 291 | * 292 | * See {_burn} and {_approve}. 293 | */ 294 | function _burnFrom(address account, uint256 amount) internal { 295 | _burn(account, amount); 296 | _approve(account, _msgSender(), _allowances[account][_msgSender()].sub(amount, 'BEP20: burn amount exceeds allowance')); 297 | } 298 | } -------------------------------------------------------------------------------- /tree/TreeDefiToken.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | import "./BEP20.sol"; 4 | 5 | pragma solidity 0.6.12; 6 | 7 | /** 8 | * @title Roles 9 | * @dev Library for managing addresses assigned to a Role. 10 | */ 11 | library Roles { 12 | struct Role { 13 | mapping (address => bool) bearer; 14 | } 15 | 16 | /** 17 | * @dev Give an account access to this role. 18 | */ 19 | function add(Role storage role, address account) internal { 20 | require(!has(role, account), "Roles: account already has role"); 21 | role.bearer[account] = true; 22 | } 23 | 24 | /** 25 | * @dev Remove an account's access to this role. 26 | */ 27 | function remove(Role storage role, address account) internal { 28 | require(has(role, account), "Roles: account does not have role"); 29 | role.bearer[account] = false; 30 | } 31 | 32 | /** 33 | * @dev Check if an account has this role. 34 | * @return bool 35 | */ 36 | function has(Role storage role, address account) internal view returns (bool) { 37 | require(account != address(0), "Roles: account is the zero address"); 38 | return role.bearer[account]; 39 | } 40 | } 41 | 42 | 43 | pragma solidity 0.6.12; 44 | 45 | contract MinterRole { 46 | using Roles for Roles.Role; 47 | 48 | event MinterAdded(address indexed account); 49 | event MinterRemoved(address indexed account); 50 | 51 | Roles.Role private _minters; 52 | 53 | constructor () internal { 54 | _addMinter(msg.sender); 55 | } 56 | 57 | modifier onlyMinter() { 58 | require(isMinter(msg.sender), "MinterRole: caller does not have the Minter role"); 59 | _; 60 | } 61 | 62 | function isMinter(address account) public view returns (bool) { 63 | return _minters.has(account); 64 | } 65 | 66 | function addMinter(address account) public onlyMinter { 67 | _addMinter(account); 68 | } 69 | 70 | function removeMinter(address account) public onlyMinter { 71 | _removeMinter(account); 72 | } 73 | 74 | function renounceMinter() public { 75 | _removeMinter(msg.sender); 76 | } 77 | 78 | function _addMinter(address account) internal { 79 | _minters.add(account); 80 | emit MinterAdded(account); 81 | } 82 | 83 | function _removeMinter(address account) internal { 84 | _minters.remove(account); 85 | emit MinterRemoved(account); 86 | } 87 | } 88 | 89 | 90 | pragma solidity 0.6.12; 91 | 92 | // TreeToken with Governance. 93 | contract TreeToken is BEP20('TreeDefi Token', 'TREE'), MinterRole { 94 | /// @notice Creates `_amount` token to `_to`. Must only be called by the owner (MasterChef). 95 | function mint(address _to, uint256 _amount) public onlyMinter { 96 | _mint(_to, _amount); 97 | _moveDelegates(address(0), _delegates[_to], _amount); 98 | } 99 | 100 | function burn(uint256 value) public onlyOwner { 101 | require(value != 0, "TREE::burn: burn value should not be zero"); 102 | uint totalSupply = totalSupply(); 103 | require(value <= totalSupply); 104 | 105 | _burn(msg.sender, value); 106 | } 107 | 108 | // Copied and modified from YAM code: 109 | // https://github.com/yam-finance/yam-protocol/blob/master/contracts/token/YAMGovernanceStorage.sol 110 | // https://github.com/yam-finance/yam-protocol/blob/master/contracts/token/YAMGovernance.sol 111 | // Which is copied and modified from COMPOUND: 112 | // https://github.com/compound-finance/compound-protocol/blob/master/contracts/Governance/Comp.sol 113 | 114 | mapping (address => address) internal _delegates; 115 | 116 | /// @notice A checkpoint for marking number of votes from a given block 117 | struct Checkpoint { 118 | uint32 fromBlock; 119 | uint256 votes; 120 | } 121 | 122 | /// @notice A record of votes checkpoints for each account, by index 123 | mapping (address => mapping (uint32 => Checkpoint)) public checkpoints; 124 | 125 | /// @notice The number of checkpoints for each account 126 | mapping (address => uint32) public numCheckpoints; 127 | 128 | /// @notice The EIP-712 typehash for the contract's domain 129 | bytes32 public constant DOMAIN_TYPEHASH = keccak256("EIP712Domain(string name,uint256 chainId,address verifyingContract)"); 130 | 131 | /// @notice The EIP-712 typehash for the delegation struct used by the contract 132 | bytes32 public constant DELEGATION_TYPEHASH = keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)"); 133 | 134 | /// @notice A record of states for signing / validating signatures 135 | mapping (address => uint) public nonces; 136 | 137 | /// @notice An event thats emitted when an account changes its delegate 138 | event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate); 139 | 140 | /// @notice An event thats emitted when a delegate account's vote balance changes 141 | event DelegateVotesChanged(address indexed delegate, uint previousBalance, uint newBalance); 142 | 143 | /** 144 | * @notice Delegate votes from `msg.sender` to `delegatee` 145 | * @param delegator The address to get delegatee for 146 | */ 147 | function delegates(address delegator) 148 | external 149 | view 150 | returns (address) 151 | { 152 | return _delegates[delegator]; 153 | } 154 | 155 | /** 156 | * @notice Delegate votes from `msg.sender` to `delegatee` 157 | * @param delegatee The address to delegate votes to 158 | */ 159 | function delegate(address delegatee) external { 160 | return _delegate(msg.sender, delegatee); 161 | } 162 | 163 | /** 164 | * @notice Delegates votes from signatory to `delegatee` 165 | * @param delegatee The address to delegate votes to 166 | * @param nonce The contract state required to match the signature 167 | * @param expiry The time at which to expire the signature 168 | * @param v The recovery byte of the signature 169 | * @param r Half of the ECDSA signature pair 170 | * @param s Half of the ECDSA signature pair 171 | */ 172 | function delegateBySig( 173 | address delegatee, 174 | uint nonce, 175 | uint expiry, 176 | uint8 v, 177 | bytes32 r, 178 | bytes32 s 179 | ) 180 | external 181 | { 182 | bytes32 domainSeparator = keccak256( 183 | abi.encode( 184 | DOMAIN_TYPEHASH, 185 | keccak256(bytes(name())), 186 | getChainId(), 187 | address(this) 188 | ) 189 | ); 190 | 191 | bytes32 structHash = keccak256( 192 | abi.encode( 193 | DELEGATION_TYPEHASH, 194 | delegatee, 195 | nonce, 196 | expiry 197 | ) 198 | ); 199 | 200 | bytes32 digest = keccak256( 201 | abi.encodePacked( 202 | "\x19\x01", 203 | domainSeparator, 204 | structHash 205 | ) 206 | ); 207 | 208 | address signatory = ecrecover(digest, v, r, s); 209 | require(signatory != address(0), "TREE::delegateBySig: invalid signature"); 210 | require(nonce == nonces[signatory]++, "TREE::delegateBySig: invalid nonce"); 211 | require(now <= expiry, "TREE::delegateBySig: signature expired"); 212 | return _delegate(signatory, delegatee); 213 | } 214 | 215 | /** 216 | * @notice Gets the current votes balance for `account` 217 | * @param account The address to get votes balance 218 | * @return The number of current votes for `account` 219 | */ 220 | function getCurrentVotes(address account) 221 | external 222 | view 223 | returns (uint256) 224 | { 225 | uint32 nCheckpoints = numCheckpoints[account]; 226 | return nCheckpoints > 0 ? checkpoints[account][nCheckpoints - 1].votes : 0; 227 | } 228 | 229 | /** 230 | * @notice Determine the prior number of votes for an account as of a block number 231 | * @dev Block number must be a finalized block or else this function will revert to prevent misinformation. 232 | * @param account The address of the account to check 233 | * @param blockNumber The block number to get the vote balance at 234 | * @return The number of votes the account had as of the given block 235 | */ 236 | function getPriorVotes(address account, uint blockNumber) 237 | external 238 | view 239 | returns (uint256) 240 | { 241 | require(blockNumber < block.number, "TREE::getPriorVotes: not yet determined"); 242 | 243 | uint32 nCheckpoints = numCheckpoints[account]; 244 | if (nCheckpoints == 0) { 245 | return 0; 246 | } 247 | 248 | // First check most recent balance 249 | if (checkpoints[account][nCheckpoints - 1].fromBlock <= blockNumber) { 250 | return checkpoints[account][nCheckpoints - 1].votes; 251 | } 252 | 253 | // Next check implicit zero balance 254 | if (checkpoints[account][0].fromBlock > blockNumber) { 255 | return 0; 256 | } 257 | 258 | uint32 lower = 0; 259 | uint32 upper = nCheckpoints - 1; 260 | while (upper > lower) { 261 | uint32 center = upper - (upper - lower) / 2; // ceil, avoiding overflow 262 | Checkpoint memory cp = checkpoints[account][center]; 263 | if (cp.fromBlock == blockNumber) { 264 | return cp.votes; 265 | } else if (cp.fromBlock < blockNumber) { 266 | lower = center; 267 | } else { 268 | upper = center - 1; 269 | } 270 | } 271 | return checkpoints[account][lower].votes; 272 | } 273 | 274 | function _delegate(address delegator, address delegatee) 275 | internal 276 | { 277 | address currentDelegate = _delegates[delegator]; 278 | uint256 delegatorBalance = balanceOf(delegator); // balance of underlying TREEs (not scaled); 279 | _delegates[delegator] = delegatee; 280 | 281 | emit DelegateChanged(delegator, currentDelegate, delegatee); 282 | 283 | _moveDelegates(currentDelegate, delegatee, delegatorBalance); 284 | } 285 | 286 | function _moveDelegates(address srcRep, address dstRep, uint256 amount) internal { 287 | if (srcRep != dstRep && amount > 0) { 288 | if (srcRep != address(0)) { 289 | // decrease old representative 290 | uint32 srcRepNum = numCheckpoints[srcRep]; 291 | uint256 srcRepOld = srcRepNum > 0 ? checkpoints[srcRep][srcRepNum - 1].votes : 0; 292 | uint256 srcRepNew = srcRepOld.sub(amount); 293 | _writeCheckpoint(srcRep, srcRepNum, srcRepOld, srcRepNew); 294 | } 295 | 296 | if (dstRep != address(0)) { 297 | // increase new representative 298 | uint32 dstRepNum = numCheckpoints[dstRep]; 299 | uint256 dstRepOld = dstRepNum > 0 ? checkpoints[dstRep][dstRepNum - 1].votes : 0; 300 | uint256 dstRepNew = dstRepOld.add(amount); 301 | _writeCheckpoint(dstRep, dstRepNum, dstRepOld, dstRepNew); 302 | } 303 | } 304 | } 305 | 306 | function _writeCheckpoint( 307 | address delegatee, 308 | uint32 nCheckpoints, 309 | uint256 oldVotes, 310 | uint256 newVotes 311 | ) 312 | internal 313 | { 314 | uint32 blockNumber = safe32(block.number, "TREE::_writeCheckpoint: block number exceeds 32 bits"); 315 | 316 | if (nCheckpoints > 0 && checkpoints[delegatee][nCheckpoints - 1].fromBlock == blockNumber) { 317 | checkpoints[delegatee][nCheckpoints - 1].votes = newVotes; 318 | } else { 319 | checkpoints[delegatee][nCheckpoints] = Checkpoint(blockNumber, newVotes); 320 | numCheckpoints[delegatee] = nCheckpoints + 1; 321 | } 322 | 323 | emit DelegateVotesChanged(delegatee, oldVotes, newVotes); 324 | } 325 | 326 | function safe32(uint n, string memory errorMessage) internal pure returns (uint32) { 327 | require(n < 2**32, errorMessage); 328 | return uint32(n); 329 | } 330 | 331 | function getChainId() internal pure returns (uint) { 332 | uint256 chainId; 333 | assembly { chainId := chainid() } 334 | return chainId; 335 | } 336 | } -------------------------------------------------------------------------------- /seed/TreeDefiSEED.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | import "./BEP20.sol"; 4 | 5 | pragma solidity 0.6.12; 6 | 7 | /** 8 | * @title Roles 9 | * @dev Library for managing addresses assigned to a Role. 10 | */ 11 | library Roles { 12 | struct Role { 13 | mapping (address => bool) bearer; 14 | } 15 | 16 | /** 17 | * @dev Give an account access to this role. 18 | */ 19 | function add(Role storage role, address account) internal { 20 | require(!has(role, account), "Roles: account already has role"); 21 | role.bearer[account] = true; 22 | } 23 | 24 | /** 25 | * @dev Remove an account's access to this role. 26 | */ 27 | function remove(Role storage role, address account) internal { 28 | require(has(role, account), "Roles: account does not have role"); 29 | role.bearer[account] = false; 30 | } 31 | 32 | /** 33 | * @dev Check if an account has this role. 34 | * @return bool 35 | */ 36 | function has(Role storage role, address account) internal view returns (bool) { 37 | require(account != address(0), "Roles: account is the zero address"); 38 | return role.bearer[account]; 39 | } 40 | } 41 | 42 | 43 | pragma solidity 0.6.12; 44 | 45 | contract MinterRole { 46 | using Roles for Roles.Role; 47 | 48 | event MinterAdded(address indexed account); 49 | event MinterRemoved(address indexed account); 50 | 51 | Roles.Role private _minters; 52 | 53 | constructor () internal { 54 | _addMinter(msg.sender); 55 | } 56 | 57 | modifier onlyMinter() { 58 | require(isMinter(msg.sender), "MinterRole: caller does not have the Minter role"); 59 | _; 60 | } 61 | 62 | function isMinter(address account) public view returns (bool) { 63 | return _minters.has(account); 64 | } 65 | 66 | function addMinter(address account) public onlyMinter { 67 | _addMinter(account); 68 | } 69 | 70 | function removeMinter(address account) public onlyMinter { 71 | _removeMinter(account); 72 | } 73 | 74 | function renounceMinter() public { 75 | _removeMinter(msg.sender); 76 | } 77 | 78 | function _addMinter(address account) internal { 79 | _minters.add(account); 80 | emit MinterAdded(account); 81 | } 82 | 83 | function _removeMinter(address account) internal { 84 | _minters.remove(account); 85 | emit MinterRemoved(account); 86 | } 87 | } 88 | 89 | 90 | pragma solidity 0.6.12; 91 | 92 | // TreeToken SEED with Governance. 93 | contract TreeToken is BEP20('TreeDefi Token', 'SEED'), MinterRole { 94 | /// @notice Creates `_amount` token to `_to`. Must only be called by the owner (MasterChef). 95 | function mint(address _to, uint256 _amount) public onlyMinter { 96 | _mint(_to, _amount); 97 | _moveDelegates(address(0), _delegates[_to], _amount); 98 | } 99 | 100 | function burn(uint256 value) public onlyOwner { 101 | require(value != 0, "SEED::burn: burn value should not be zero"); 102 | uint totalSupply = totalSupply(); 103 | require(value <= totalSupply); 104 | 105 | _burn(msg.sender, value); 106 | } 107 | 108 | // Copied and modified from YAM code: 109 | // https://github.com/yam-finance/yam-protocol/blob/master/contracts/token/YAMGovernanceStorage.sol 110 | // https://github.com/yam-finance/yam-protocol/blob/master/contracts/token/YAMGovernance.sol 111 | // Which is copied and modified from COMPOUND: 112 | // https://github.com/compound-finance/compound-protocol/blob/master/contracts/Governance/Comp.sol 113 | 114 | mapping (address => address) internal _delegates; 115 | 116 | /// @notice A checkpoint for marking number of votes from a given block 117 | struct Checkpoint { 118 | uint32 fromBlock; 119 | uint256 votes; 120 | } 121 | 122 | /// @notice A record of votes checkpoints for each account, by index 123 | mapping (address => mapping (uint32 => Checkpoint)) public checkpoints; 124 | 125 | /// @notice The number of checkpoints for each account 126 | mapping (address => uint32) public numCheckpoints; 127 | 128 | /// @notice The EIP-712 typehash for the contract's domain 129 | bytes32 public constant DOMAIN_TYPEHASH = keccak256("EIP712Domain(string name,uint256 chainId,address verifyingContract)"); 130 | 131 | /// @notice The EIP-712 typehash for the delegation struct used by the contract 132 | bytes32 public constant DELEGATION_TYPEHASH = keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)"); 133 | 134 | /// @notice A record of states for signing / validating signatures 135 | mapping (address => uint) public nonces; 136 | 137 | /// @notice An event thats emitted when an account changes its delegate 138 | event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate); 139 | 140 | /// @notice An event thats emitted when a delegate account's vote balance changes 141 | event DelegateVotesChanged(address indexed delegate, uint previousBalance, uint newBalance); 142 | 143 | /** 144 | * @notice Delegate votes from `msg.sender` to `delegatee` 145 | * @param delegator The address to get delegatee for 146 | */ 147 | function delegates(address delegator) 148 | external 149 | view 150 | returns (address) 151 | { 152 | return _delegates[delegator]; 153 | } 154 | 155 | /** 156 | * @notice Delegate votes from `msg.sender` to `delegatee` 157 | * @param delegatee The address to delegate votes to 158 | */ 159 | function delegate(address delegatee) external { 160 | return _delegate(msg.sender, delegatee); 161 | } 162 | 163 | /** 164 | * @notice Delegates votes from signatory to `delegatee` 165 | * @param delegatee The address to delegate votes to 166 | * @param nonce The contract state required to match the signature 167 | * @param expiry The time at which to expire the signature 168 | * @param v The recovery byte of the signature 169 | * @param r Half of the ECDSA signature pair 170 | * @param s Half of the ECDSA signature pair 171 | */ 172 | function delegateBySig( 173 | address delegatee, 174 | uint nonce, 175 | uint expiry, 176 | uint8 v, 177 | bytes32 r, 178 | bytes32 s 179 | ) 180 | external 181 | { 182 | bytes32 domainSeparator = keccak256( 183 | abi.encode( 184 | DOMAIN_TYPEHASH, 185 | keccak256(bytes(name())), 186 | getChainId(), 187 | address(this) 188 | ) 189 | ); 190 | 191 | bytes32 structHash = keccak256( 192 | abi.encode( 193 | DELEGATION_TYPEHASH, 194 | delegatee, 195 | nonce, 196 | expiry 197 | ) 198 | ); 199 | 200 | bytes32 digest = keccak256( 201 | abi.encodePacked( 202 | "\x19\x01", 203 | domainSeparator, 204 | structHash 205 | ) 206 | ); 207 | 208 | address signatory = ecrecover(digest, v, r, s); 209 | require(signatory != address(0), "SEED::delegateBySig: invalid signature"); 210 | require(nonce == nonces[signatory]++, "SEED::delegateBySig: invalid nonce"); 211 | require(now <= expiry, "SEED::delegateBySig: signature expired"); 212 | return _delegate(signatory, delegatee); 213 | } 214 | 215 | /** 216 | * @notice Gets the current votes balance for `account` 217 | * @param account The address to get votes balance 218 | * @return The number of current votes for `account` 219 | */ 220 | function getCurrentVotes(address account) 221 | external 222 | view 223 | returns (uint256) 224 | { 225 | uint32 nCheckpoints = numCheckpoints[account]; 226 | return nCheckpoints > 0 ? checkpoints[account][nCheckpoints - 1].votes : 0; 227 | } 228 | 229 | /** 230 | * @notice Determine the prior number of votes for an account as of a block number 231 | * @dev Block number must be a finalized block or else this function will revert to prevent misinformation. 232 | * @param account The address of the account to check 233 | * @param blockNumber The block number to get the vote balance at 234 | * @return The number of votes the account had as of the given block 235 | */ 236 | function getPriorVotes(address account, uint blockNumber) 237 | external 238 | view 239 | returns (uint256) 240 | { 241 | require(blockNumber < block.number, "SEED::getPriorVotes: not yet determined"); 242 | 243 | uint32 nCheckpoints = numCheckpoints[account]; 244 | if (nCheckpoints == 0) { 245 | return 0; 246 | } 247 | 248 | // First check most recent balance 249 | if (checkpoints[account][nCheckpoints - 1].fromBlock <= blockNumber) { 250 | return checkpoints[account][nCheckpoints - 1].votes; 251 | } 252 | 253 | // Next check implicit zero balance 254 | if (checkpoints[account][0].fromBlock > blockNumber) { 255 | return 0; 256 | } 257 | 258 | uint32 lower = 0; 259 | uint32 upper = nCheckpoints - 1; 260 | while (upper > lower) { 261 | uint32 center = upper - (upper - lower) / 2; // ceil, avoiding overflow 262 | Checkpoint memory cp = checkpoints[account][center]; 263 | if (cp.fromBlock == blockNumber) { 264 | return cp.votes; 265 | } else if (cp.fromBlock < blockNumber) { 266 | lower = center; 267 | } else { 268 | upper = center - 1; 269 | } 270 | } 271 | return checkpoints[account][lower].votes; 272 | } 273 | 274 | function _delegate(address delegator, address delegatee) 275 | internal 276 | { 277 | address currentDelegate = _delegates[delegator]; 278 | uint256 delegatorBalance = balanceOf(delegator); // balance of underlying SEEDs (not scaled); 279 | _delegates[delegator] = delegatee; 280 | 281 | emit DelegateChanged(delegator, currentDelegate, delegatee); 282 | 283 | _moveDelegates(currentDelegate, delegatee, delegatorBalance); 284 | } 285 | 286 | function _moveDelegates(address srcRep, address dstRep, uint256 amount) internal { 287 | if (srcRep != dstRep && amount > 0) { 288 | if (srcRep != address(0)) { 289 | // decrease old representative 290 | uint32 srcRepNum = numCheckpoints[srcRep]; 291 | uint256 srcRepOld = srcRepNum > 0 ? checkpoints[srcRep][srcRepNum - 1].votes : 0; 292 | uint256 srcRepNew = srcRepOld.sub(amount); 293 | _writeCheckpoint(srcRep, srcRepNum, srcRepOld, srcRepNew); 294 | } 295 | 296 | if (dstRep != address(0)) { 297 | // increase new representative 298 | uint32 dstRepNum = numCheckpoints[dstRep]; 299 | uint256 dstRepOld = dstRepNum > 0 ? checkpoints[dstRep][dstRepNum - 1].votes : 0; 300 | uint256 dstRepNew = dstRepOld.add(amount); 301 | _writeCheckpoint(dstRep, dstRepNum, dstRepOld, dstRepNew); 302 | } 303 | } 304 | } 305 | 306 | function _writeCheckpoint( 307 | address delegatee, 308 | uint32 nCheckpoints, 309 | uint256 oldVotes, 310 | uint256 newVotes 311 | ) 312 | internal 313 | { 314 | uint32 blockNumber = safe32(block.number, "SEED::_writeCheckpoint: block number exceeds 32 bits"); 315 | 316 | if (nCheckpoints > 0 && checkpoints[delegatee][nCheckpoints - 1].fromBlock == blockNumber) { 317 | checkpoints[delegatee][nCheckpoints - 1].votes = newVotes; 318 | } else { 319 | checkpoints[delegatee][nCheckpoints] = Checkpoint(blockNumber, newVotes); 320 | numCheckpoints[delegatee] = nCheckpoints + 1; 321 | } 322 | 323 | emit DelegateVotesChanged(delegatee, oldVotes, newVotes); 324 | } 325 | 326 | function safe32(uint n, string memory errorMessage) internal pure returns (uint32) { 327 | require(n < 2**32, errorMessage); 328 | return uint32(n); 329 | } 330 | 331 | function getChainId() internal pure returns (uint) { 332 | uint256 chainId; 333 | assembly { chainId := chainid() } 334 | return chainId; 335 | } 336 | } -------------------------------------------------------------------------------- /tree/MasterChef.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity 0.6.12; 4 | 5 | import "./SafeMath.sol"; 6 | import "./IBEP20.sol"; 7 | import "./SafeBEP20.sol"; 8 | import "./Ownable.sol"; 9 | import "./TreeDefiToken.sol"; 10 | 11 | // MasterChef is the master of Tree. He can make Tree and he is a fair guy. 12 | // 13 | // Note that it's ownable and the owner wields tremendous power. The ownership 14 | // will be transferred to a governance smart contract once TREE is sufficiently 15 | // distributed and the community can show to govern itself. 16 | // 17 | // Have fun reading it. Hopefully it's bug-free. God bless. 18 | contract MasterChef is Ownable { 19 | using SafeMath for uint256; 20 | using SafeBEP20 for IBEP20; 21 | 22 | // Info of each user. 23 | struct UserInfo { 24 | uint256 amount; // How many LP tokens the user has provided. 25 | uint256 rewardDebt; // Reward debt. See explanation below. 26 | // 27 | // We do some fancy math here. Basically, any point in time, the amount of TREEs 28 | // entitled to a user but is pending to be distributed is: 29 | // 30 | // pending reward = (user.amount * pool.accTreePerShare) - user.rewardDebt 31 | // 32 | // Whenever a user deposits or withdraws LP tokens to a pool. Here's what happens: 33 | // 1. The pool's `accTreePerShare` (and `lastRewardBlock`) gets updated. 34 | // 2. User receives the pending reward sent to his/her address. 35 | // 3. User's `amount` gets updated. 36 | // 4. User's `rewardDebt` gets updated. 37 | } 38 | 39 | // Info of each pool. 40 | struct PoolInfo { 41 | IBEP20 lpToken; // Address of LP token contract. 42 | uint256 allocPoint; // How many allocation points assigned to this pool. TREEs to distribute per block. 43 | uint256 lastRewardBlock; // Last block number that TREEs distribution occurs. 44 | uint256 accTreePerShare; // Accumulated TREEs per share, times 1e12. See below. 45 | uint16 depositFeeBP; // Deposit fee in basis points 46 | } 47 | 48 | // The TREE TOKEN! 49 | TreeToken public tree; 50 | // Dev address. 51 | address public devaddr; 52 | // TREE tokens created per block. 53 | uint256 public treePerBlock; 54 | uint256 public startTime; 55 | // Bonus muliplier for early tree makers. 56 | uint256 public constant BONUS_MULTIPLIER = 1; 57 | // Deposit Fee addresses 58 | address public feeDonationAddress; 59 | address public feeBuybackAddress; 60 | address public feeDevAddress; 61 | 62 | // Info of each pool. 63 | PoolInfo[] public poolInfo; 64 | // Info of each user that stakes LP tokens. 65 | mapping (uint256 => mapping (address => UserInfo)) public userInfo; 66 | // Total allocation points. Must be the sum of all allocation points in all pools. 67 | uint256 public totalAllocPoint = 0; 68 | // The block number when TREE mining starts. 69 | uint256 public startBlock; 70 | 71 | event Deposit(address indexed user, uint256 indexed pid, uint256 amount); 72 | event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); 73 | event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); 74 | 75 | constructor( 76 | TreeToken _tree, 77 | uint256 _treePerBlock, 78 | uint256 _startBlock 79 | ) public { 80 | tree = _tree; 81 | treePerBlock = _treePerBlock; 82 | startBlock = _startBlock; 83 | devaddr = 0xb2F903e79d05600AC6BCD604e4Ac68a8717d1fD7; // 5% Treasury Wallet 84 | feeDonationAddress = 0x14f375Ba23F52a93CB768e80F0ECA123650C22D9; // 1/3 deposit fee to donation vault 85 | feeBuybackAddress = 0x32232a427A70f8C9019156c12Da9B3c392e07c1D; // 1/3 deposit fee to buyback 86 | feeDevAddress = 0xdB67A848e237E4855b1BE722b16b7eD956a7210d; // 1/3 deposit fee to devs 87 | startTime = now; 88 | } 89 | 90 | function poolLength() external view returns (uint256) { 91 | return poolInfo.length; 92 | } 93 | 94 | // Add a new lp to the pool. Can only be called by the owner. 95 | // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. 96 | function add(uint256 _allocPoint, IBEP20 _lpToken, uint16 _depositFeeBP, bool _withUpdate) public onlyOwner { 97 | require(_depositFeeBP <= 10000, "add: invalid deposit fee basis points"); 98 | if (_withUpdate) { 99 | massUpdatePools(); 100 | } 101 | uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; 102 | totalAllocPoint = totalAllocPoint.add(_allocPoint); 103 | poolInfo.push(PoolInfo({ 104 | lpToken: _lpToken, 105 | allocPoint: _allocPoint, 106 | lastRewardBlock: lastRewardBlock, 107 | accTreePerShare: 0, 108 | depositFeeBP: _depositFeeBP 109 | })); 110 | } 111 | 112 | // Update the given pool's TREE allocation point and deposit fee. Can only be called by the owner. 113 | function set(uint256 _pid, uint256 _allocPoint, uint16 _depositFeeBP, bool _withUpdate) public onlyOwner { 114 | require(_depositFeeBP <= 10000, "set: invalid deposit fee basis points"); 115 | if (_withUpdate) { 116 | massUpdatePools(); 117 | } 118 | totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); 119 | poolInfo[_pid].allocPoint = _allocPoint; 120 | poolInfo[_pid].depositFeeBP = _depositFeeBP; 121 | } 122 | 123 | // Return reward multiplier over the given _from to _to block. 124 | function getMultiplier(uint256 _from, uint256 _to) public view returns (uint256) { 125 | return _to.sub(_from).mul(BONUS_MULTIPLIER); 126 | } 127 | 128 | // View function to see pending TREEs on frontend. 129 | function pendingTree(uint256 _pid, address _user) external view returns (uint256) { 130 | PoolInfo storage pool = poolInfo[_pid]; 131 | UserInfo storage user = userInfo[_pid][_user]; 132 | uint256 accTreePerShare = pool.accTreePerShare; 133 | uint256 lpSupply = pool.lpToken.balanceOf(address(this)); 134 | // Deflactionary System -2% minted token every week 135 | if (block.number > pool.lastRewardBlock && lpSupply != 0) { 136 | uint256 multiplier = getMultiplier(pool.lastRewardBlock, block.number); 137 | 138 | uint256 calcTreePerBlock = 0; 139 | uint256 i = 0; 140 | uint256 calcTime = startTime; 141 | 142 | for (calcTime; calcTime < now; calcTreePerBlock++) { 143 | calcTime = calcTime + 1 weeks; 144 | } 145 | 146 | for (i = 0; i < calcTreePerBlock; i++) { 147 | calcTreePerBlock = treePerBlock.div(50).mul(49); 148 | } 149 | 150 | uint256 treeReward = multiplier.mul(calcTreePerBlock).mul(pool.allocPoint).div(totalAllocPoint); 151 | 152 | accTreePerShare = accTreePerShare.add(treeReward.mul(1e12).div(lpSupply)); 153 | } 154 | return user.amount.mul(accTreePerShare).div(1e12).sub(user.rewardDebt); 155 | } 156 | 157 | // Update reward variables for all pools. Be careful of gas spending! 158 | function massUpdatePools() public { 159 | uint256 length = poolInfo.length; 160 | for (uint256 pid = 0; pid < length; ++pid) { 161 | updatePool(pid); 162 | } 163 | } 164 | 165 | // Update reward variables of the given pool to be up-to-date. 166 | function updatePool(uint256 _pid) public { 167 | PoolInfo storage pool = poolInfo[_pid]; 168 | if (block.number <= pool.lastRewardBlock) { 169 | return; 170 | } 171 | uint256 lpSupply = pool.lpToken.balanceOf(address(this)); 172 | if (lpSupply == 0 || pool.allocPoint == 0) { 173 | pool.lastRewardBlock = block.number; 174 | return; 175 | } 176 | uint256 multiplier = getMultiplier(pool.lastRewardBlock, block.number); 177 | uint256 calcTreePerBlock = 0; 178 | uint256 i = 0; 179 | uint256 calcTime = startTime; 180 | 181 | for (calcTime; calcTime < now; calcTreePerBlock++) { 182 | calcTime = calcTime + 1 weeks; 183 | } 184 | 185 | for (i = 0; i < calcTreePerBlock; i++) { 186 | calcTreePerBlock = treePerBlock.div(50).mul(49); 187 | } 188 | 189 | uint256 treeReward = multiplier.mul(calcTreePerBlock).mul(pool.allocPoint).div(totalAllocPoint); 190 | 191 | tree.mint(devaddr, treeReward.div(20)); 192 | tree.mint(address(this), treeReward.div(100).mul(95)); 193 | pool.accTreePerShare = pool.accTreePerShare.add(treeReward.mul(1e12).div(lpSupply)); 194 | pool.lastRewardBlock = block.number; 195 | } 196 | 197 | // Deposit LP tokens to MasterChef for TREE allocation. 198 | function deposit(uint256 _pid, uint256 _amount) public { 199 | PoolInfo storage pool = poolInfo[_pid]; 200 | UserInfo storage user = userInfo[_pid][msg.sender]; 201 | updatePool(_pid); 202 | if (user.amount > 0) { 203 | uint256 pending = user.amount.mul(pool.accTreePerShare).div(1e12).sub(user.rewardDebt); 204 | if(pending > 0) { 205 | safeTreeTransfer(msg.sender, pending); 206 | } 207 | } 208 | if(_amount > 0) { 209 | pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amount); 210 | if(pool.depositFeeBP > 0){ 211 | uint256 depositFee = _amount.mul(pool.depositFeeBP).div(10000); 212 | pool.lpToken.safeTransfer(feeDonationAddress, depositFee.div(3)); 213 | pool.lpToken.safeTransfer(feeBuybackAddress, depositFee.div(3)); 214 | pool.lpToken.safeTransfer(feeDevAddress, depositFee.div(3)); 215 | user.amount = user.amount.add(_amount).sub(depositFee); 216 | }else{ 217 | user.amount = user.amount.add(_amount); 218 | } 219 | } 220 | user.rewardDebt = user.amount.mul(pool.accTreePerShare).div(1e12); 221 | emit Deposit(msg.sender, _pid, _amount); 222 | } 223 | 224 | // Withdraw LP tokens from MasterChef. 225 | function withdraw(uint256 _pid, uint256 _amount) public { 226 | PoolInfo storage pool = poolInfo[_pid]; 227 | UserInfo storage user = userInfo[_pid][msg.sender]; 228 | require(user.amount >= _amount, "withdraw: not good"); 229 | updatePool(_pid); 230 | uint256 pending = user.amount.mul(pool.accTreePerShare).div(1e12).sub(user.rewardDebt); 231 | if(pending > 0) { 232 | safeTreeTransfer(msg.sender, pending); 233 | } 234 | if(_amount > 0) { 235 | user.amount = user.amount.sub(_amount); 236 | pool.lpToken.safeTransfer(address(msg.sender), _amount); 237 | } 238 | user.rewardDebt = user.amount.mul(pool.accTreePerShare).div(1e12); 239 | emit Withdraw(msg.sender, _pid, _amount); 240 | } 241 | 242 | // Withdraw without caring about rewards. EMERGENCY ONLY. 243 | function emergencyWithdraw(uint256 _pid) public { 244 | PoolInfo storage pool = poolInfo[_pid]; 245 | UserInfo storage user = userInfo[_pid][msg.sender]; 246 | uint256 amount = user.amount; 247 | user.amount = 0; 248 | user.rewardDebt = 0; 249 | pool.lpToken.safeTransfer(address(msg.sender), amount); 250 | emit EmergencyWithdraw(msg.sender, _pid, amount); 251 | } 252 | 253 | // Safe tree transfer function, just in case if rounding error causes pool to not have enough TREEs. 254 | function safeTreeTransfer(address _to, uint256 _amount) internal { 255 | uint256 treeBal = tree.balanceOf(address(this)); 256 | if (_amount > treeBal) { 257 | tree.transfer(_to, treeBal); 258 | } else { 259 | tree.transfer(_to, _amount); 260 | } 261 | } 262 | 263 | // Update dev address by the previous dev. 264 | function dev(address _devaddr) public { 265 | require(msg.sender == devaddr, "dev: wut?"); 266 | devaddr = _devaddr; 267 | } 268 | 269 | function setFeeDonationAddress(address _feeAddress) public{ 270 | require(msg.sender == feeDonationAddress, "setFeeAddress: FORBIDDEN"); 271 | feeDonationAddress = _feeAddress; 272 | } 273 | 274 | function setFeeBuybackAddress(address _feeAddress) public{ 275 | require(msg.sender == feeBuybackAddress, "setFeeAddress: FORBIDDEN"); 276 | feeBuybackAddress = _feeAddress; 277 | } 278 | 279 | function setFeeDevAddress(address _feeAddress) public{ 280 | require(msg.sender == feeDevAddress, "setFeeAddress: FORBIDDEN"); 281 | feeDevAddress = _feeAddress; 282 | } 283 | 284 | //Pancake has to add hidden dummy pools inorder to alter the emission, here we make it simple and transparent to all. 285 | function updateEmissionRate(uint256 _treePerBlock) public onlyOwner { 286 | massUpdatePools(); 287 | treePerBlock = _treePerBlock; 288 | } 289 | } -------------------------------------------------------------------------------- /masterchef/MasterChef.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity 0.6.12; 4 | 5 | import "./SafeMath.sol"; 6 | import "./IBEP20.sol"; 7 | import "./SafeBEP20.sol"; 8 | import "./Ownable.sol"; 9 | import "./TreeDefiSEED.sol"; 10 | 11 | // MasterChef is the master of Tree. He can make Tree and he is a fair guy. 12 | // 13 | // Note that it's ownable and the owner wields tremendous power. The ownership 14 | // will be transferred to a governance smart contract once TREE is sufficiently 15 | // distributed and the community can show to govern itself. 16 | // 17 | // Have fun reading it. Hopefully it's bug-free. God bless. 18 | contract MasterChef is Ownable { 19 | using SafeMath for uint256; 20 | using SafeBEP20 for IBEP20; 21 | 22 | // Info of each user. 23 | struct UserInfo { 24 | uint256 amount; // How many LP tokens the user has provided. 25 | uint256 rewardDebt; // Reward debt. See explanation below. 26 | // 27 | // We do some fancy math here. Basically, any point in time, the amount of TREEs 28 | // entitled to a user but is pending to be distributed is: 29 | // 30 | // pending reward = (user.amount * pool.accTreePerShare) - user.rewardDebt 31 | // 32 | // Whenever a user deposits or withdraws LP tokens to a pool. Here's what happens: 33 | // 1. The pool's `accTreePerShare` (and `lastRewardBlock`) gets updated. 34 | // 2. User receives the pending reward sent to his/her address. 35 | // 3. User's `amount` gets updated. 36 | // 4. User's `rewardDebt` gets updated. 37 | } 38 | 39 | // Info of each pool. 40 | struct PoolInfo { 41 | IBEP20 lpToken; // Address of LP token contract. 42 | uint256 allocPoint; // How many allocation points assigned to this pool. TREEs to distribute per block. 43 | uint256 lastRewardBlock; // Last block number that TREEs distribution occurs. 44 | uint256 accTreePerShare; // Accumulated TREEs per share, times 1e12. See below. 45 | uint16 depositFeeBP; // Deposit fee in basis points 46 | } 47 | 48 | // The TREE TOKEN! 49 | TreeToken public immutable tree; 50 | // Dev address. 51 | address public devaddr; 52 | // TREE tokens created per block. 53 | uint256 public treePerBlock; 54 | uint256 public immutable startTime; 55 | // Bonus muliplier for early tree makers. 56 | 57 | // Deposit Fee addresses 58 | address public feeDonationAddress; 59 | address public feeBuybackAddress; 60 | address public feeDevAddress; 61 | 62 | // Info of each pool. 63 | PoolInfo[] public poolInfo; 64 | // Info of each user that stakes LP tokens. 65 | mapping (uint256 => mapping (address => UserInfo)) public userInfo; 66 | 67 | mapping (uint256 => uint256) internal lpTokenAmount; 68 | 69 | // Total allocation points. Must be the sum of all allocation points in all pools. 70 | uint256 public totalAllocPoint = 0; 71 | // The block number when TREE mining starts. 72 | uint256 public immutable startBlock; 73 | uint16 public harvestFee = 5; 74 | uint256 constant weekInSeconds = 604800; 75 | bool internal locked; 76 | 77 | event Deposit(address indexed user, uint256 indexed pid, uint256 amount); 78 | event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); 79 | event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); 80 | event SetDev(address indexed user, address newDevAddress); 81 | event SetFeeDonationAddress(address indexed user, address newFeeDonationAddress); 82 | event SetFeeBuybackAddress(address indexed user, address newFeeBuybackAddress); 83 | event SetFeeDevAddress(address indexed user, address newFeeDevAddress); 84 | event UpdateEmissionRate(address indexed user, uint256 oldEmissionRate, uint256 newEmissionRate); 85 | event SetHarvestFee(address indexed user, uint256 oldHarvestFee, uint256 newHarvestFee); 86 | 87 | modifier validatePoolByPid(uint256 _pid) { 88 | require( 89 | _pid < poolLength(), 90 | 'MasterChef: Pool Doesnot exist' 91 | ); 92 | _; 93 | } 94 | 95 | modifier noReentrant() { 96 | require(!locked, "No re-entrancy"); 97 | locked = true; 98 | _; 99 | locked = false; 100 | } 101 | 102 | constructor( 103 | TreeToken _tree, 104 | uint256 _treePerBlock, 105 | uint256 _startBlock 106 | ) public { 107 | tree = _tree; 108 | treePerBlock = _treePerBlock; 109 | startBlock = _startBlock; 110 | devaddr = 0xb2F903e79d05600AC6BCD604e4Ac68a8717d1fD7; 111 | feeDonationAddress = 0x14f375Ba23F52a93CB768e80F0ECA123650C22D9; 112 | feeBuybackAddress = 0x32232a427A70f8C9019156c12Da9B3c392e07c1D; 113 | feeDevAddress = 0xdB67A848e237E4855b1BE722b16b7eD956a7210d; 114 | startTime = now; 115 | } 116 | 117 | function poolLength() public view returns (uint256) { 118 | return poolInfo.length; 119 | } 120 | 121 | // Add a new lp to the pool. Can only be called by the owner. 122 | // Onwer can add multiple pool with LP token. 123 | function add( 124 | uint256 _allocPoint, 125 | IBEP20 _lpToken, 126 | uint16 _depositFeeBP, 127 | bool _withUpdate 128 | ) 129 | external 130 | onlyOwner 131 | { 132 | require(_depositFeeBP <= 10000, "add: invalid deposit fee basis points"); 133 | if (_withUpdate) { 134 | massUpdatePools(); 135 | } 136 | uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; 137 | totalAllocPoint = totalAllocPoint.add(_allocPoint); 138 | poolInfo.push(PoolInfo({ 139 | lpToken: _lpToken, 140 | allocPoint: _allocPoint, 141 | lastRewardBlock: lastRewardBlock, 142 | accTreePerShare: 0, 143 | depositFeeBP: _depositFeeBP 144 | })); 145 | } 146 | 147 | // Update the given pool's TREE allocation point and deposit fee. Can only be called by the owner. 148 | function set( 149 | uint256 _pid, 150 | uint256 _allocPoint, 151 | uint16 _depositFeeBP, 152 | bool _withUpdate 153 | ) 154 | external 155 | onlyOwner 156 | validatePoolByPid(_pid) 157 | { 158 | require(_depositFeeBP <= 10000, "set: invalid deposit fee basis points"); 159 | if (_withUpdate) { 160 | massUpdatePools(); 161 | } 162 | totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); 163 | poolInfo[_pid].allocPoint = _allocPoint; 164 | poolInfo[_pid].depositFeeBP = _depositFeeBP; 165 | } 166 | 167 | // Return reward multiplier over the given _from to _to block. 168 | function getMultiplier( 169 | uint256 _from, 170 | uint256 _to 171 | ) 172 | public pure 173 | returns (uint256) 174 | { 175 | return _to.sub(_from); 176 | // return _to.sub(_from).mul(BONUS_MULTIPLIER); 177 | } 178 | 179 | // View function to see pending TREEs on frontend. 180 | function pendingTree( 181 | uint256 _pid, 182 | address _user 183 | ) 184 | external view 185 | validatePoolByPid(_pid) 186 | returns (uint256) 187 | { 188 | PoolInfo storage pool = poolInfo[_pid]; 189 | UserInfo storage user = userInfo[_pid][_user]; 190 | uint256 accTreePerShare = pool.accTreePerShare; 191 | uint256 lpSupply = lpTokenAmount[_pid]; 192 | if (block.number > pool.lastRewardBlock && lpSupply != 0) { 193 | uint256 multiplier = getMultiplier(pool.lastRewardBlock, block.number); 194 | 195 | uint16 i; 196 | uint256 calcblocks = treePerBlock; 197 | uint256 duration = now - startTime; 198 | uint256 mulNum = duration.div(weekInSeconds); 199 | 200 | for (i = 1; i < mulNum; i++) { 201 | calcblocks = calcblocks.mul(98).div(100); 202 | } 203 | 204 | uint256 treeReward = multiplier.mul(calcblocks).mul(pool.allocPoint).div(totalAllocPoint); 205 | 206 | accTreePerShare = accTreePerShare.add(treeReward.mul(1e12).div(lpSupply)); 207 | } 208 | return user.amount.mul(accTreePerShare).div(1e12).sub(user.rewardDebt); 209 | } 210 | 211 | // Update reward variables for all pools. Be careful of gas spending! 212 | function massUpdatePools() 213 | public 214 | { 215 | uint256 length = poolLength(); 216 | for (uint256 pid = 0; pid < length; ++pid) { 217 | updatePool(pid); 218 | } 219 | } 220 | 221 | // Update reward variables of the given pool to be up-to-date. 222 | function updatePool( 223 | uint256 _pid 224 | ) 225 | public 226 | validatePoolByPid(_pid) 227 | { 228 | PoolInfo storage pool = poolInfo[_pid]; 229 | if (block.number <= pool.lastRewardBlock) { 230 | return; 231 | } 232 | uint256 lpSupply = lpTokenAmount[_pid]; 233 | if (lpSupply == 0 || pool.allocPoint == 0) { 234 | pool.lastRewardBlock = block.number; 235 | return; 236 | } 237 | uint256 multiplier = getMultiplier(pool.lastRewardBlock, block.number); 238 | 239 | uint16 i; 240 | uint256 calcblocks = treePerBlock; 241 | uint256 duration = now - startTime; 242 | uint256 mulNum = duration.div(weekInSeconds); 243 | 244 | for (i = 1; i < mulNum; i++) { 245 | calcblocks = calcblocks.mul(98).div(100); 246 | } 247 | 248 | uint256 treeReward = multiplier.mul(calcblocks).mul(pool.allocPoint).div(totalAllocPoint); 249 | 250 | if(_pid == 3) { 251 | tree.mint(devaddr, treeReward); 252 | tree.burn(treeReward.mul(harvestFee).div(100)); 253 | } else { 254 | tree.mint(devaddr, treeReward.div(20)); 255 | tree.mint(address(this), treeReward.mul(95).div(100)); 256 | } 257 | 258 | pool.accTreePerShare = pool.accTreePerShare.add(treeReward.mul(1e12).div(lpSupply)); 259 | pool.lastRewardBlock = block.number; 260 | } 261 | 262 | // Deposit LP tokens to MasterChef for TREE allocation. 263 | function deposit( 264 | uint256 _pid, 265 | uint256 _amount 266 | ) 267 | external 268 | noReentrant 269 | validatePoolByPid(_pid) 270 | { 271 | PoolInfo storage pool = poolInfo[_pid]; 272 | UserInfo storage user = userInfo[_pid][msg.sender]; 273 | updatePool(_pid); 274 | if (user.amount > 0) { 275 | uint256 pending = user.amount.mul(pool.accTreePerShare).div(1e12).sub(user.rewardDebt); 276 | if(pending > 0) { 277 | safeTreeTransfer(msg.sender, pending); 278 | } 279 | } 280 | if(_amount > 0) { 281 | pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amount); 282 | if(pool.depositFeeBP > 0){ 283 | uint256 depositFee = _amount.mul(pool.depositFeeBP).div(10000); 284 | uint256 depositFee13 = depositFee.div(3); 285 | pool.lpToken.safeTransfer(feeDonationAddress, depositFee13); 286 | pool.lpToken.safeTransfer(feeBuybackAddress, depositFee13); 287 | pool.lpToken.safeTransfer(feeDevAddress, depositFee.sub(depositFee13).sub(depositFee13)); 288 | user.amount = user.amount.add(_amount).sub(depositFee); 289 | }else{ 290 | user.amount = user.amount.add(_amount); 291 | } 292 | lpTokenAmount[_pid] += user.amount; 293 | } 294 | user.rewardDebt = user.amount.mul(pool.accTreePerShare).div(1e12); 295 | emit Deposit(msg.sender, _pid, _amount); 296 | } 297 | 298 | // Withdraw LP tokens from MasterChef. 299 | function withdraw( 300 | uint256 _pid, 301 | uint256 _amount 302 | ) 303 | external 304 | validatePoolByPid(_pid) 305 | { 306 | PoolInfo storage pool = poolInfo[_pid]; 307 | UserInfo storage user = userInfo[_pid][msg.sender]; 308 | require(user.amount >= _amount, "withdraw: not good"); 309 | updatePool(_pid); 310 | uint256 pending = user.amount.mul(pool.accTreePerShare).div(1e12).sub(user.rewardDebt); 311 | if(pending > 0) { 312 | safeTreeTransfer(msg.sender, pending); 313 | } 314 | if(_amount > 0) { 315 | user.amount = user.amount.sub(_amount); 316 | pool.lpToken.safeTransfer(address(msg.sender), _amount); 317 | lpTokenAmount[_pid] -= _amount; 318 | } 319 | user.rewardDebt = user.amount.mul(pool.accTreePerShare).div(1e12); 320 | emit Withdraw(msg.sender, _pid, _amount); 321 | } 322 | 323 | // Withdraw without caring about rewards. EMERGENCY ONLY. 324 | function emergencyWithdraw( 325 | uint256 _pid 326 | ) 327 | external 328 | validatePoolByPid(_pid) 329 | { 330 | PoolInfo storage pool = poolInfo[_pid]; 331 | UserInfo storage user = userInfo[_pid][msg.sender]; 332 | uint256 amount = user.amount; 333 | user.amount = 0; 334 | user.rewardDebt = 0; 335 | pool.lpToken.safeTransfer(address(msg.sender), amount); 336 | lpTokenAmount[_pid] -= amount; 337 | emit EmergencyWithdraw(msg.sender, _pid, amount); 338 | } 339 | 340 | // Safe tree transfer function, just in case if rounding error causes pool to not have enough TREEs. 341 | function safeTreeTransfer( 342 | address _to, 343 | uint256 _amount 344 | ) 345 | internal 346 | { 347 | uint256 treeBal = tree.balanceOf(address(this)); 348 | bool transferSuccess = false; 349 | if (_amount > treeBal) { 350 | transferSuccess = tree.transfer(_to, treeBal); 351 | } else { 352 | transferSuccess = tree.transfer(_to, _amount); 353 | } 354 | 355 | require( 356 | transferSuccess == true, 357 | 'safeTreeTransfer: transfer failed' 358 | ); 359 | } 360 | 361 | // Update dev address by the previous dev. 362 | function dev( 363 | address _devaddr 364 | ) 365 | external 366 | { 367 | require(msg.sender == devaddr, "dev: wut?"); 368 | 369 | emit SetDev(devaddr, _devaddr); 370 | devaddr = _devaddr; 371 | } 372 | 373 | function setFeeDonationAddress( 374 | address _feeAddress 375 | ) 376 | external 377 | { 378 | require(msg.sender == feeDonationAddress, "setFeeAddress: FORBIDDEN"); 379 | 380 | emit SetFeeDonationAddress(feeDonationAddress, _feeAddress); 381 | feeDonationAddress = _feeAddress; 382 | } 383 | 384 | function setFeeBuybackAddress( 385 | address _feeAddress 386 | ) 387 | external 388 | { 389 | require(msg.sender == feeBuybackAddress, "setFeeAddress: FORBIDDEN"); 390 | 391 | emit SetFeeBuybackAddress(feeBuybackAddress, _feeAddress); 392 | feeBuybackAddress = _feeAddress; 393 | } 394 | 395 | function setFeeDevAddress( 396 | address _feeAddress 397 | ) 398 | external 399 | { 400 | require(msg.sender == feeDevAddress, "setFeeAddress: FORBIDDEN"); 401 | 402 | emit SetFeeDevAddress(feeDevAddress, _feeAddress); 403 | feeDevAddress = _feeAddress; 404 | } 405 | 406 | //Pancake has to add hidden dummy pools inorder to alter the emission, here we make it simple and transparent to all. 407 | function updateEmissionRate( 408 | uint256 _treePerBlock 409 | ) 410 | external 411 | onlyOwner 412 | { 413 | massUpdatePools(); 414 | 415 | emit UpdateEmissionRate(msg.sender, treePerBlock, _treePerBlock); 416 | treePerBlock = _treePerBlock; 417 | } 418 | 419 | function setHarvestFee( 420 | uint16 _harvestFee 421 | ) 422 | external 423 | onlyOwner 424 | { 425 | require(_harvestFee < 95, "set: invalid harvest fee basis points"); 426 | require(block.number > startBlock, "not started"); 427 | 428 | emit SetHarvestFee(msg.sender, harvestFee, _harvestFee); 429 | harvestFee = _harvestFee; 430 | } 431 | 432 | function getHarvestFee() 433 | public view 434 | returns (uint16) 435 | { 436 | return harvestFee; 437 | } 438 | 439 | function getCurrentPerBlock() 440 | public view 441 | returns (uint256) 442 | { 443 | uint16 i; 444 | uint256 calcblocks = treePerBlock; 445 | uint256 duration = now - startTime; 446 | uint256 mulNum = duration.div(weekInSeconds); 447 | 448 | for (i = 1; i < mulNum; i++) { 449 | calcblocks = calcblocks.mul(98).div(100); 450 | } 451 | 452 | return calcblocks; 453 | } 454 | } 455 | -------------------------------------------------------------------------------- /paymentGateway/paymentGateway.sol: -------------------------------------------------------------------------------- 1 | //SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | interface IBEP20 { 5 | function totalSupply() external view returns (uint256); 6 | 7 | function decimals() external view returns (uint8); 8 | 9 | function symbol() external view returns (string memory); 10 | 11 | function name() external view returns (string memory); 12 | 13 | function getOwner() external view returns (address); 14 | 15 | function balanceOf(address account) external view returns (uint256); 16 | 17 | function transfer(address recipient, uint256 amount) external returns (bool); 18 | 19 | function allowance(address _owner, address spender) external view returns (uint256); 20 | 21 | function approve(address spender, uint256 amount) external returns (bool); 22 | 23 | function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); 24 | } 25 | 26 | /** 27 | * @dev Wrappers over Solidity's arithmetic operations with added overflow 28 | * checks. 29 | * 30 | * Arithmetic operations in Solidity wrap on overflow. This can easily result 31 | * in bugs, because programmers usually assume that an overflow raises an 32 | * error, which is the standard behavior in high level programming languages. 33 | * `SafeMath` restores this intuition by reverting the transaction when an 34 | * operation overflows. 35 | * 36 | * Using this library instead of the unchecked operations eliminates an entire 37 | * class of bugs, so it's recommended to use it always. 38 | */ 39 | library SafeMath { 40 | /** 41 | * @dev Returns the addition of two unsigned integers, reverting on 42 | * overflow. 43 | * 44 | * Counterpart to Solidity's `+` operator. 45 | * 46 | * Requirements: 47 | * 48 | * - Addition cannot overflow. 49 | */ 50 | function add(uint256 a, uint256 b) internal pure returns (uint256) { 51 | uint256 c = a + b; 52 | require(c >= a, "SafeMath: addition overflow"); 53 | 54 | return c; 55 | } 56 | 57 | /** 58 | * @dev Returns the subtraction of two unsigned integers, reverting on 59 | * overflow (when the result is negative). 60 | * 61 | * Counterpart to Solidity's `-` operator. 62 | * 63 | * Requirements: 64 | * 65 | * - Subtraction cannot overflow. 66 | */ 67 | function sub(uint256 a, uint256 b) internal pure returns (uint256) { 68 | return sub(a, b, "SafeMath: subtraction overflow"); 69 | } 70 | 71 | /** 72 | * @dev Returns the subtraction of two unsigned integers, reverting with custom message on 73 | * overflow (when the result is negative). 74 | * 75 | * Counterpart to Solidity's `-` operator. 76 | * 77 | * Requirements: 78 | * 79 | * - Subtraction cannot overflow. 80 | */ 81 | function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { 82 | require(b <= a, errorMessage); 83 | uint256 c = a - b; 84 | 85 | return c; 86 | } 87 | 88 | /** 89 | * @dev Returns the multiplication of two unsigned integers, reverting on 90 | * overflow. 91 | * 92 | * Counterpart to Solidity's `*` operator. 93 | * 94 | * Requirements: 95 | * 96 | * - Multiplication cannot overflow. 97 | */ 98 | function mul(uint256 a, uint256 b) internal pure returns (uint256) { 99 | // Gas optimization: this is cheaper than requiring 'a' not being zero, but the 100 | // benefit is lost if 'b' is also tested. 101 | // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 102 | if (a == 0) { 103 | return 0; 104 | } 105 | 106 | uint256 c = a * b; 107 | require(c / a == b, "SafeMath: multiplication overflow"); 108 | 109 | return c; 110 | } 111 | 112 | /** 113 | * @dev Returns the integer division of two unsigned integers. Reverts on 114 | * division by zero. The result is rounded towards zero. 115 | * 116 | * Counterpart to Solidity's `/` operator. Note: this function uses a 117 | * `revert` opcode (which leaves remaining gas untouched) while Solidity 118 | * uses an invalid opcode to revert (consuming all remaining gas). 119 | * 120 | * Requirements: 121 | * 122 | * - The divisor cannot be zero. 123 | */ 124 | function div(uint256 a, uint256 b) internal pure returns (uint256) { 125 | return div(a, b, "SafeMath: division by zero"); 126 | } 127 | 128 | /** 129 | * @dev Returns the integer division of two unsigned integers. Reverts with custom message on 130 | * division by zero. The result is rounded towards zero. 131 | * 132 | * Counterpart to Solidity's `/` operator. Note: this function uses a 133 | * `revert` opcode (which leaves remaining gas untouched) while Solidity 134 | * uses an invalid opcode to revert (consuming all remaining gas). 135 | * 136 | * Requirements: 137 | * 138 | * - The divisor cannot be zero. 139 | */ 140 | function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { 141 | require(b > 0, errorMessage); 142 | uint256 c = a / b; 143 | // assert(a == b * c + a % b); // There is no case in which this doesn't hold 144 | 145 | return c; 146 | } 147 | 148 | /** 149 | * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), 150 | * Reverts when dividing by zero. 151 | * 152 | * Counterpart to Solidity's `%` operator. This function uses a `revert` 153 | * opcode (which leaves remaining gas untouched) while Solidity uses an 154 | * invalid opcode to revert (consuming all remaining gas). 155 | * 156 | * Requirements: 157 | * 158 | * - The divisor cannot be zero. 159 | */ 160 | function mod(uint256 a, uint256 b) internal pure returns (uint256) { 161 | return mod(a, b, "SafeMath: modulo by zero"); 162 | } 163 | 164 | /** 165 | * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), 166 | * Reverts with custom message when dividing by zero. 167 | * 168 | * Counterpart to Solidity's `%` operator. This function uses a `revert` 169 | * opcode (which leaves remaining gas untouched) while Solidity uses an 170 | * invalid opcode to revert (consuming all remaining gas). 171 | * 172 | * Requirements: 173 | * 174 | * - The divisor cannot be zero. 175 | */ 176 | function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { 177 | require(b != 0, errorMessage); 178 | return a % b; 179 | } 180 | } 181 | 182 | /* 183 | * @dev Provides information about the current execution context, including the 184 | * sender of the transaction and its data. While these are generally available 185 | * via msg.sender and msg.data, they should not be accessed in such a direct 186 | * manner, since when dealing with GSN meta-transactions the account sending and 187 | * paying for execution may not be the actual sender (as far as an application 188 | * is concerned). 189 | * 190 | * This contract is only required for intermediate, library-like contracts. 191 | */ 192 | abstract contract Context { 193 | // Empty internal constructor, to prevent people from mistakenly deploying 194 | // an instance of this contract, which should be used via inheritance. 195 | constructor() {} 196 | 197 | function _msgSender() internal view returns (address) { 198 | return msg.sender; 199 | } 200 | 201 | function _msgData() internal view returns (bytes memory) { 202 | this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 203 | return msg.data; 204 | } 205 | } 206 | 207 | /** 208 | * @dev Contract module which provides a basic access control mechanism, where 209 | * there is an account (an owner) that can be granted exclusive access to 210 | * specific functions. 211 | * 212 | * By default, the owner account will be the one that deploys the contract. This 213 | * can later be changed with {transferOwnership}. 214 | * 215 | * This module is used through inheritance. It will make available the modifier 216 | * `onlyOwner`, which can be applied to your functions to restrict their use to 217 | * the owner. 218 | */ 219 | abstract contract Ownable is Context { 220 | address private _owner; 221 | 222 | event OwnershipTransferred( 223 | address indexed previousOwner, 224 | address indexed newOwner 225 | ); 226 | 227 | /** 228 | * @dev Initializes the contract setting the deployer as the initial owner. 229 | */ 230 | constructor() { 231 | address msgSender = _msgSender(); 232 | _owner = msgSender; 233 | emit OwnershipTransferred(address(0), msgSender); 234 | } 235 | 236 | /** 237 | * @dev Returns the address of the current owner. 238 | */ 239 | function owner() public view returns (address) { 240 | return _owner; 241 | } 242 | 243 | /** 244 | * @dev Throws if called by any account other than the owner. 245 | */ 246 | modifier onlyOwner() { 247 | require(_owner == _msgSender(), "Ownable: caller is not the owner"); 248 | _; 249 | } 250 | 251 | /** 252 | * @dev Leaves the contract without owner. It will not be possible to call 253 | * `onlyOwner` functions anymore. Can only be called by the current owner. 254 | * 255 | * NOTE: Renouncing ownership will leave the contract without an owner, 256 | * thereby removing any functionality that is only available to the owner. 257 | */ 258 | function renounceOwnership() public onlyOwner { 259 | emit OwnershipTransferred(_owner, address(0)); 260 | _owner = address(0); 261 | } 262 | 263 | /** 264 | * @dev Transfers ownership of the contract to a new account (`newOwner`). 265 | * Can only be called by the current owner. 266 | */ 267 | function transferOwnership(address newOwner) public onlyOwner { 268 | _transferOwnership(newOwner); 269 | } 270 | 271 | /** 272 | * @dev Transfers ownership of the contract to a new account (`newOwner`). 273 | */ 274 | function _transferOwnership(address newOwner) internal { 275 | require( 276 | newOwner != address(0), 277 | "Ownable: new owner is the zero address" 278 | ); 279 | emit OwnershipTransferred(_owner, newOwner); 280 | _owner = newOwner; 281 | } 282 | } 283 | 284 | /** 285 | * @title Pausable 286 | * @dev Base contract which allows children to implement an emergency stop mechanism. 287 | */ 288 | contract Pausable is Ownable { 289 | event Pause(); 290 | event Unpause(); 291 | 292 | bool public paused = false; 293 | 294 | 295 | /** 296 | * @dev Modifier to make a function callable only when the contract is not paused. 297 | */ 298 | modifier whenNotPaused() { 299 | require(!paused); 300 | _; 301 | } 302 | 303 | /** 304 | * @dev Modifier to make a function callable only when the contract is paused. 305 | */ 306 | modifier whenPaused() { 307 | require(paused); 308 | _; 309 | } 310 | 311 | /** 312 | * @dev called by the owner to pause, triggers stopped state 313 | */ 314 | function pause() onlyOwner whenNotPaused public { 315 | paused = true; 316 | emit Pause(); 317 | } 318 | 319 | /** 320 | * @dev called by the owner to unpause, returns to normal state 321 | */ 322 | function unpause() onlyOwner whenPaused public { 323 | paused = false; 324 | emit Unpause(); 325 | } 326 | } 327 | 328 | 329 | contract PaymentGateway is Pausable { 330 | 331 | using SafeMath for uint256; 332 | 333 | struct TransctionInfo { 334 | bytes16 txId; 335 | address userAddress; 336 | uint256 amount; 337 | uint256 timeStamp; 338 | } 339 | 340 | address public fruitTokenAddress = address(0x28557dfC9cc3D2c53B6bAF81467A62b754B2a84a); 341 | address public burnAddress = address(0x000000000000000000000000000000000000dEaD); 342 | IBEP20 private FRUIT_TOKEN = IBEP20(fruitTokenAddress); 343 | 344 | uint256 public totalTxCount; 345 | mapping(address => uint256) public userTxCount; 346 | mapping(bytes16 => TransctionInfo) private txDetails; 347 | mapping(address => bytes16[]) private userTxDetails; 348 | 349 | event TranscationExecuted(address indexed user, bytes16 txID, uint256 amount, uint256 timestamp); 350 | event FruitTokenAddressUpdated(address indexed user, address oldTokenAddress, address newTokenAddress); 351 | 352 | constructor(IBEP20 _fruitToken) { 353 | fruitTokenAddress = address(_fruitToken); 354 | FRUIT_TOKEN = IBEP20(fruitTokenAddress); 355 | } 356 | 357 | function toBytes16( 358 | uint256 x 359 | ) 360 | internal 361 | pure 362 | returns (bytes16 b) 363 | { 364 | return bytes16(bytes32(x)); 365 | } 366 | 367 | function generateID( 368 | address x, 369 | uint256 y, 370 | bytes1 z 371 | ) 372 | internal 373 | pure 374 | returns (bytes16 b) 375 | { 376 | b = toBytes16( 377 | uint256( 378 | keccak256( 379 | abi.encodePacked(x, y, z) 380 | ) 381 | ) 382 | ); 383 | } 384 | 385 | function generateTxID( 386 | address _userAddress 387 | ) 388 | internal 389 | view 390 | returns (bytes16 stakeID) 391 | { 392 | return generateID(_userAddress, userTxCount[_userAddress], 0x01); 393 | } 394 | 395 | function getTxDetailById( 396 | bytes16 _txNumber 397 | ) 398 | public 399 | view 400 | returns (TransctionInfo memory) 401 | { 402 | return txDetails[_txNumber]; 403 | } 404 | 405 | function transactionPagination( 406 | address _userAddress, 407 | uint256 _offset, 408 | uint256 _length 409 | ) 410 | external 411 | view 412 | returns (bytes16[] memory _txIds) 413 | { 414 | uint256 start = _offset > 0 && 415 | userTxCount[_userAddress] > _offset ? 416 | userTxCount[_userAddress] - _offset : userTxCount[_userAddress]; 417 | 418 | uint256 finish = _length > 0 && 419 | start > _length ? 420 | start - _length : 0; 421 | 422 | _txIds = new bytes16[](start - finish); 423 | uint256 i; 424 | for (uint256 _txIndex = start; _txIndex > finish; _txIndex--) { 425 | bytes16 _txID = generateID(_userAddress, _txIndex - 1, 0x01); 426 | _txIds[i] = _txID; i++; 427 | } 428 | } 429 | 430 | function getUserTxCount( 431 | address _userAddress 432 | ) 433 | public 434 | view 435 | returns (uint256) 436 | { 437 | return userTxCount[_userAddress]; 438 | } 439 | 440 | function getUserAllTxDetails( 441 | address _userAddress 442 | ) 443 | public 444 | view 445 | returns (uint256, bytes16 [] memory) 446 | { 447 | return (userTxCount[_userAddress], userTxDetails[_userAddress]); 448 | } 449 | 450 | function updateFruitTokenAddress( 451 | address _tokenAddress 452 | ) 453 | external 454 | onlyOwner 455 | { 456 | require( 457 | _tokenAddress != address(0x0), 458 | 'PaymentGateway: Invalid _token Address' 459 | ); 460 | 461 | emit FruitTokenAddressUpdated(_msgSender(), fruitTokenAddress, _tokenAddress); 462 | fruitTokenAddress = address(_tokenAddress); 463 | FRUIT_TOKEN = IBEP20(fruitTokenAddress); 464 | } 465 | 466 | function submitTransaction( 467 | uint256 _amount 468 | ) 469 | external 470 | whenNotPaused 471 | returns (bytes16 txNumber) 472 | { 473 | require( 474 | _amount > 0, 475 | 'PaymentGateway: Tanscation amount should be non-zero' 476 | ); 477 | 478 | require ( 479 | FRUIT_TOKEN.balanceOf(_msgSender()) >= _amount, 480 | 'PaymentGateway: User wallet doenot have enough balance' 481 | ); 482 | 483 | require ( 484 | FRUIT_TOKEN.transferFrom(_msgSender(), address(this), _amount), 485 | 'PaymentGateway: TransferFrom failed' 486 | ); 487 | 488 | txNumber = generateTxID(_msgSender()); 489 | txDetails[txNumber].txId = txNumber; 490 | txDetails[txNumber].userAddress = _msgSender(); 491 | txDetails[txNumber].amount = _amount; 492 | txDetails[txNumber].timeStamp = block.timestamp; 493 | 494 | userTxDetails[_msgSender()].push(txNumber); 495 | 496 | FRUIT_TOKEN.transfer(burnAddress, _amount); 497 | 498 | totalTxCount++; 499 | userTxCount[_msgSender()]++; 500 | 501 | emit TranscationExecuted(_msgSender(), txNumber, _amount, block.timestamp); 502 | } 503 | } 504 | -------------------------------------------------------------------------------- /lauch-pool/Launchpool.sol: -------------------------------------------------------------------------------- 1 | /** 2 | *Submitted for verification at BscScan.com on 2021-10-25 3 | */ 4 | 5 | // 6 | // _{\ _{\{\/}/}/}__ 7 | // {/{/\}{/{/\}(\}{/\} _ 8 | // {/{/\}{/{/\}(_)\}{/{/\} _ 9 | // {\{/(\}\}{/{/\}\}{/){/\}\} /\} 10 | // {/{/(_)/}{\{/)\}{\(_){/}/}/}/} 11 | // _{\{/{/{\{/{/(_)/}/}/}{\(/}/}/} 12 | // {/{/{\{\{\(/}{\{\/}/}{\}(_){\/}\} 13 | // _{\{/{\{/(_)\}/}{/{/{/\}\})\}{/\} 14 | // {/{/{\{\(/}{/{\{\{\/})/}{\(_)/}/}\} 15 | // {\{\/}(_){\{\{\/}/}(_){\/}{\/}/})/} 16 | // {/{\{\/}{/{\{\{\/}/}{\{\/}/}\}(_) 17 | // {/{\{\/}{/){\{\{\/}/}{\{\(/}/}\}/} 18 | // {/{\{\/}(_){\{\{\(/}/}{\(_)/}/}\} 19 | // {/({/{\{/{\{\/}(_){\/}/}\}/}(\} 20 | // (_){/{\/}{\{\/}/}{\{\)/}/}(_) 21 | // {/{/{\{\/}{/{\{\{\(_)/} 22 | // {/{\{\{\/}/}{\{\\}/} 23 | // {){/ {\/}{\/} \}\} 24 | // (_) \.-'.-/ 25 | // __...--- |'-.-'| --...__ 26 | // _...--" .-' |'-.-'| ' -. ""--..__ 27 | // -" ' . . ' |.'-._| ' . . ' 28 | // . '- ' .--' | '-.'| . ' . ' 29 | // ' .. |'-_.-| 30 | // . ' . _.-|-._ -|-._ . ' . 31 | // .' |'- .-| '. 32 | // ..-' ' . '. `-._.-` .' ' - . 33 | // .-' ' '-._______.-' ' . 34 | // . ~, 35 | // . . |\ . ' '-. 36 | // ___________/ \____________ 37 | // / Treedefi is the first eco \ 38 | // | friendly project on the | 39 | // | BSC! treedefi.com | 40 | // \___________________________/ 41 | // 42 | // SPDX-License-Identifier: MIT 43 | 44 | // File: @pancakeswap/pancake-swap-lib/contracts/math/SafeMath.sol 45 | 46 | 47 | pragma solidity >=0.4.0; 48 | 49 | /** 50 | * @dev Wrappers over Solidity's arithmetic operations with added overflow 51 | * checks. 52 | * 53 | * Arithmetic operations in Solidity wrap on overflow. This can easily result 54 | * in bugs, because programmers usually assume that an overflow raises an 55 | * error, which is the standard behavior in high level programming languages. 56 | * `SafeMath` restores this intuition by reverting the transaction when an 57 | * operation overflows. 58 | * 59 | * Using this library instead of the unchecked operations eliminates an entire 60 | * class of bugs, so it's recommended to use it always. 61 | */ 62 | library SafeMath { 63 | /** 64 | * @dev Returns the addition of two unsigned integers, reverting on 65 | * overflow. 66 | * 67 | * Counterpart to Solidity's `+` operator. 68 | * 69 | * Requirements: 70 | * 71 | * - Addition cannot overflow. 72 | */ 73 | function add(uint256 a, uint256 b) internal pure returns (uint256) { 74 | uint256 c = a + b; 75 | require(c >= a, 'SafeMath: addition overflow'); 76 | 77 | return c; 78 | } 79 | 80 | /** 81 | * @dev Returns the subtraction of two unsigned integers, reverting on 82 | * overflow (when the result is negative). 83 | * 84 | * Counterpart to Solidity's `-` operator. 85 | * 86 | * Requirements: 87 | * 88 | * - Subtraction cannot overflow. 89 | */ 90 | function sub(uint256 a, uint256 b) internal pure returns (uint256) { 91 | return sub(a, b, 'SafeMath: subtraction overflow'); 92 | } 93 | 94 | /** 95 | * @dev Returns the subtraction of two unsigned integers, reverting with custom message on 96 | * overflow (when the result is negative). 97 | * 98 | * Counterpart to Solidity's `-` operator. 99 | * 100 | * Requirements: 101 | * 102 | * - Subtraction cannot overflow. 103 | */ 104 | function sub( 105 | uint256 a, 106 | uint256 b, 107 | string memory errorMessage 108 | ) internal pure returns (uint256) { 109 | require(b <= a, errorMessage); 110 | uint256 c = a - b; 111 | 112 | return c; 113 | } 114 | 115 | /** 116 | * @dev Returns the multiplication of two unsigned integers, reverting on 117 | * overflow. 118 | * 119 | * Counterpart to Solidity's `*` operator. 120 | * 121 | * Requirements: 122 | * 123 | * - Multiplication cannot overflow. 124 | */ 125 | function mul(uint256 a, uint256 b) internal pure returns (uint256) { 126 | // Gas optimization: this is cheaper than requiring 'a' not being zero, but the 127 | // benefit is lost if 'b' is also tested. 128 | // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 129 | if (a == 0) { 130 | return 0; 131 | } 132 | 133 | uint256 c = a * b; 134 | require(c / a == b, 'SafeMath: multiplication overflow'); 135 | 136 | return c; 137 | } 138 | 139 | /** 140 | * @dev Returns the integer division of two unsigned integers. Reverts on 141 | * division by zero. The result is rounded towards zero. 142 | * 143 | * Counterpart to Solidity's `/` operator. Note: this function uses a 144 | * `revert` opcode (which leaves remaining gas untouched) while Solidity 145 | * uses an invalid opcode to revert (consuming all remaining gas). 146 | * 147 | * Requirements: 148 | * 149 | * - The divisor cannot be zero. 150 | */ 151 | function div(uint256 a, uint256 b) internal pure returns (uint256) { 152 | return div(a, b, 'SafeMath: division by zero'); 153 | } 154 | 155 | /** 156 | * @dev Returns the integer division of two unsigned integers. Reverts with custom message on 157 | * division by zero. The result is rounded towards zero. 158 | * 159 | * Counterpart to Solidity's `/` operator. Note: this function uses a 160 | * `revert` opcode (which leaves remaining gas untouched) while Solidity 161 | * uses an invalid opcode to revert (consuming all remaining gas). 162 | * 163 | * Requirements: 164 | * 165 | * - The divisor cannot be zero. 166 | */ 167 | function div( 168 | uint256 a, 169 | uint256 b, 170 | string memory errorMessage 171 | ) internal pure returns (uint256) { 172 | require(b > 0, errorMessage); 173 | uint256 c = a / b; 174 | // assert(a == b * c + a % b); // There is no case in which this doesn't hold 175 | 176 | return c; 177 | } 178 | 179 | /** 180 | * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), 181 | * Reverts when dividing by zero. 182 | * 183 | * Counterpart to Solidity's `%` operator. This function uses a `revert` 184 | * opcode (which leaves remaining gas untouched) while Solidity uses an 185 | * invalid opcode to revert (consuming all remaining gas). 186 | * 187 | * Requirements: 188 | * 189 | * - The divisor cannot be zero. 190 | */ 191 | function mod(uint256 a, uint256 b) internal pure returns (uint256) { 192 | return mod(a, b, 'SafeMath: modulo by zero'); 193 | } 194 | 195 | /** 196 | * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), 197 | * Reverts with custom message when dividing by zero. 198 | * 199 | * Counterpart to Solidity's `%` operator. This function uses a `revert` 200 | * opcode (which leaves remaining gas untouched) while Solidity uses an 201 | * invalid opcode to revert (consuming all remaining gas). 202 | * 203 | * Requirements: 204 | * 205 | * - The divisor cannot be zero. 206 | */ 207 | function mod( 208 | uint256 a, 209 | uint256 b, 210 | string memory errorMessage 211 | ) internal pure returns (uint256) { 212 | require(b != 0, errorMessage); 213 | return a % b; 214 | } 215 | 216 | function min(uint256 x, uint256 y) internal pure returns (uint256 z) { 217 | z = x < y ? x : y; 218 | } 219 | 220 | // babylonian method (https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method) 221 | function sqrt(uint256 y) internal pure returns (uint256 z) { 222 | if (y > 3) { 223 | z = y; 224 | uint256 x = y / 2 + 1; 225 | while (x < z) { 226 | z = x; 227 | x = (y / x + x) / 2; 228 | } 229 | } else if (y != 0) { 230 | z = 1; 231 | } 232 | } 233 | } 234 | 235 | // File: @pancakeswap/pancake-swap-lib/contracts/token/BEP20/IBEP20.sol 236 | 237 | 238 | pragma solidity >=0.4.0; 239 | 240 | interface IBEP20 { 241 | /** 242 | * @dev Returns the amount of tokens in existence. 243 | */ 244 | function totalSupply() external view returns (uint256); 245 | 246 | /** 247 | * @dev Returns the token decimals. 248 | */ 249 | function decimals() external view returns (uint8); 250 | 251 | /** 252 | * @dev Returns the token symbol. 253 | */ 254 | function symbol() external view returns (string memory); 255 | 256 | /** 257 | * @dev Returns the token name. 258 | */ 259 | function name() external view returns (string memory); 260 | 261 | /** 262 | * @dev Returns the bep token owner. 263 | */ 264 | function getOwner() external view returns (address); 265 | 266 | /** 267 | * @dev Returns the amount of tokens owned by `account`. 268 | */ 269 | function balanceOf(address account) external view returns (uint256); 270 | 271 | /** 272 | * @dev Moves `amount` tokens from the caller's account to `recipient`. 273 | * 274 | * Returns a boolean value indicating whether the operation succeeded. 275 | * 276 | * Emits a {Transfer} event. 277 | */ 278 | function transfer(address recipient, uint256 amount) external returns (bool); 279 | 280 | /** 281 | * @dev Returns the remaining number of tokens that `spender` will be 282 | * allowed to spend on behalf of `owner` through {transferFrom}. This is 283 | * zero by default. 284 | * 285 | * This value changes when {approve} or {transferFrom} are called. 286 | */ 287 | function allowance(address _owner, address spender) external view returns (uint256); 288 | 289 | /** 290 | * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. 291 | * 292 | * Returns a boolean value indicating whether the operation succeeded. 293 | * 294 | * IMPORTANT: Beware that changing an allowance with this method brings the risk 295 | * that someone may use both the old and the new allowance by unfortunate 296 | * transaction ordering. One possible solution to mitigate this race 297 | * condition is to first reduce the spender's allowance to 0 and set the 298 | * desired value afterwards: 299 | * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 300 | * 301 | * Emits an {Approval} event. 302 | */ 303 | function approve(address spender, uint256 amount) external returns (bool); 304 | 305 | /** 306 | * @dev Moves `amount` tokens from `sender` to `recipient` using the 307 | * allowance mechanism. `amount` is then deducted from the caller's 308 | * allowance. 309 | * 310 | * Returns a boolean value indicating whether the operation succeeded. 311 | * 312 | * Emits a {Transfer} event. 313 | */ 314 | function transferFrom( 315 | address sender, 316 | address recipient, 317 | uint256 amount 318 | ) external returns (bool); 319 | 320 | /** 321 | * @dev Emitted when `value` tokens are moved from one account (`from`) to 322 | * another (`to`). 323 | * 324 | * Note that `value` may be zero. 325 | */ 326 | event Transfer(address indexed from, address indexed to, uint256 value); 327 | 328 | /** 329 | * @dev Emitted when the allowance of a `spender` for an `owner` is set by 330 | * a call to {approve}. `value` is the new allowance. 331 | */ 332 | event Approval(address indexed owner, address indexed spender, uint256 value); 333 | } 334 | 335 | // File: @pancakeswap/pancake-swap-lib/contracts/utils/Address.sol 336 | 337 | 338 | pragma solidity ^0.6.2; 339 | 340 | /** 341 | * @dev Collection of functions related to the address type 342 | */ 343 | library Address { 344 | /** 345 | * @dev Returns true if `account` is a contract. 346 | * 347 | * [IMPORTANT] 348 | * ==== 349 | * It is unsafe to assume that an address for which this function returns 350 | * false is an externally-owned account (EOA) and not a contract. 351 | * 352 | * Among others, `isContract` will return false for the following 353 | * types of addresses: 354 | * 355 | * - an externally-owned account 356 | * - a contract in construction 357 | * - an address where a contract will be created 358 | * - an address where a contract lived, but was destroyed 359 | * ==== 360 | */ 361 | function isContract(address account) internal view returns (bool) { 362 | // According to EIP-1052, 0x0 is the value returned for not-yet created accounts 363 | // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned 364 | // for accounts without code, i.e. `keccak256('')` 365 | bytes32 codehash; 366 | bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; 367 | // solhint-disable-next-line no-inline-assembly 368 | assembly { 369 | codehash := extcodehash(account) 370 | } 371 | return (codehash != accountHash && codehash != 0x0); 372 | } 373 | 374 | /** 375 | * @dev Replacement for Solidity's `transfer`: sends `amount` wei to 376 | * `recipient`, forwarding all available gas and reverting on errors. 377 | * 378 | * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost 379 | * of certain opcodes, possibly making contracts go over the 2300 gas limit 380 | * imposed by `transfer`, making them unable to receive funds via 381 | * `transfer`. {sendValue} removes this limitation. 382 | * 383 | * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. 384 | * 385 | * IMPORTANT: because control is transferred to `recipient`, care must be 386 | * taken to not create reentrancy vulnerabilities. Consider using 387 | * {ReentrancyGuard} or the 388 | * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. 389 | */ 390 | function sendValue(address payable recipient, uint256 amount) internal { 391 | require(address(this).balance >= amount, 'Address: insufficient balance'); 392 | 393 | // solhint-disable-next-line avoid-low-level-calls, avoid-call-value 394 | (bool success, ) = recipient.call{value: amount}(''); 395 | require(success, 'Address: unable to send value, recipient may have reverted'); 396 | } 397 | 398 | /** 399 | * @dev Performs a Solidity function call using a low level `call`. A 400 | * plain`call` is an unsafe replacement for a function call: use this 401 | * function instead. 402 | * 403 | * If `target` reverts with a revert reason, it is bubbled up by this 404 | * function (like regular Solidity function calls). 405 | * 406 | * Returns the raw returned data. To convert to the expected return value, 407 | * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. 408 | * 409 | * Requirements: 410 | * 411 | * - `target` must be a contract. 412 | * - calling `target` with `data` must not revert. 413 | * 414 | * _Available since v3.1._ 415 | */ 416 | function functionCall(address target, bytes memory data) internal returns (bytes memory) { 417 | return functionCall(target, data, 'Address: low-level call failed'); 418 | } 419 | 420 | /** 421 | * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with 422 | * `errorMessage` as a fallback revert reason when `target` reverts. 423 | * 424 | * _Available since v3.1._ 425 | */ 426 | function functionCall( 427 | address target, 428 | bytes memory data, 429 | string memory errorMessage 430 | ) internal returns (bytes memory) { 431 | return _functionCallWithValue(target, data, 0, errorMessage); 432 | } 433 | 434 | /** 435 | * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], 436 | * but also transferring `value` wei to `target`. 437 | * 438 | * Requirements: 439 | * 440 | * - the calling contract must have an ETH balance of at least `value`. 441 | * - the called Solidity function must be `payable`. 442 | * 443 | * _Available since v3.1._ 444 | */ 445 | function functionCallWithValue( 446 | address target, 447 | bytes memory data, 448 | uint256 value 449 | ) internal returns (bytes memory) { 450 | return functionCallWithValue(target, data, value, 'Address: low-level call with value failed'); 451 | } 452 | 453 | /** 454 | * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but 455 | * with `errorMessage` as a fallback revert reason when `target` reverts. 456 | * 457 | * _Available since v3.1._ 458 | */ 459 | function functionCallWithValue( 460 | address target, 461 | bytes memory data, 462 | uint256 value, 463 | string memory errorMessage 464 | ) internal returns (bytes memory) { 465 | require(address(this).balance >= value, 'Address: insufficient balance for call'); 466 | return _functionCallWithValue(target, data, value, errorMessage); 467 | } 468 | 469 | function _functionCallWithValue( 470 | address target, 471 | bytes memory data, 472 | uint256 weiValue, 473 | string memory errorMessage 474 | ) private returns (bytes memory) { 475 | require(isContract(target), 'Address: call to non-contract'); 476 | 477 | // solhint-disable-next-line avoid-low-level-calls 478 | (bool success, bytes memory returndata) = target.call{value: weiValue}(data); 479 | if (success) { 480 | return returndata; 481 | } else { 482 | // Look for revert reason and bubble it up if present 483 | if (returndata.length > 0) { 484 | // The easiest way to bubble the revert reason is using memory via assembly 485 | 486 | // solhint-disable-next-line no-inline-assembly 487 | assembly { 488 | let returndata_size := mload(returndata) 489 | revert(add(32, returndata), returndata_size) 490 | } 491 | } else { 492 | revert(errorMessage); 493 | } 494 | } 495 | } 496 | } 497 | 498 | // File: @pancakeswap/pancake-swap-lib/contracts/token/BEP20/SafeBEP20.sol 499 | 500 | 501 | pragma solidity ^0.6.0; 502 | 503 | 504 | 505 | 506 | /** 507 | * @title SafeBEP20 508 | * @dev Wrappers around BEP20 operations that throw on failure (when the token 509 | * contract returns false). Tokens that return no value (and instead revert or 510 | * throw on failure) are also supported, non-reverting calls are assumed to be 511 | * successful. 512 | * To use this library you can add a `using SafeBEP20 for IBEP20;` statement to your contract, 513 | * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. 514 | */ 515 | library SafeBEP20 { 516 | using SafeMath for uint256; 517 | using Address for address; 518 | 519 | function safeTransfer( 520 | IBEP20 token, 521 | address to, 522 | uint256 value 523 | ) internal { 524 | _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); 525 | } 526 | 527 | function safeTransferFrom( 528 | IBEP20 token, 529 | address from, 530 | address to, 531 | uint256 value 532 | ) internal { 533 | _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); 534 | } 535 | 536 | /** 537 | * @dev Deprecated. This function has issues similar to the ones found in 538 | * {IBEP20-approve}, and its usage is discouraged. 539 | * 540 | * Whenever possible, use {safeIncreaseAllowance} and 541 | * {safeDecreaseAllowance} instead. 542 | */ 543 | function safeApprove( 544 | IBEP20 token, 545 | address spender, 546 | uint256 value 547 | ) internal { 548 | // safeApprove should only be called when setting an initial allowance, 549 | // or when resetting it to zero. To increase and decrease it, use 550 | // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' 551 | // solhint-disable-next-line max-line-length 552 | require( 553 | (value == 0) || (token.allowance(address(this), spender) == 0), 554 | 'SafeBEP20: approve from non-zero to non-zero allowance' 555 | ); 556 | _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); 557 | } 558 | 559 | function safeIncreaseAllowance( 560 | IBEP20 token, 561 | address spender, 562 | uint256 value 563 | ) internal { 564 | uint256 newAllowance = token.allowance(address(this), spender).add(value); 565 | _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); 566 | } 567 | 568 | function safeDecreaseAllowance( 569 | IBEP20 token, 570 | address spender, 571 | uint256 value 572 | ) internal { 573 | uint256 newAllowance = token.allowance(address(this), spender).sub( 574 | value, 575 | 'SafeBEP20: decreased allowance below zero' 576 | ); 577 | _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); 578 | } 579 | 580 | /** 581 | * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement 582 | * on the return value: the return value is optional (but if data is returned, it must not be false). 583 | * @param token The token targeted by the call. 584 | * @param data The call data (encoded using abi.encode or one of its variants). 585 | */ 586 | function _callOptionalReturn(IBEP20 token, bytes memory data) private { 587 | // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since 588 | // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that 589 | // the target address contains contract code and also asserts for success in the low-level call. 590 | 591 | bytes memory returndata = address(token).functionCall(data, 'SafeBEP20: low-level call failed'); 592 | if (returndata.length > 0) { 593 | // Return data is optional 594 | // solhint-disable-next-line max-line-length 595 | require(abi.decode(returndata, (bool)), 'SafeBEP20: BEP20 operation did not succeed'); 596 | } 597 | } 598 | } 599 | 600 | // File: @pancakeswap/pancake-swap-lib/contracts/GSN/Context.sol 601 | 602 | 603 | pragma solidity >=0.4.0; 604 | 605 | /* 606 | * @dev Provides information about the current execution context, including the 607 | * sender of the transaction and its data. While these are generally available 608 | * via msg.sender and msg.data, they should not be accessed in such a direct 609 | * manner, since when dealing with GSN meta-transactions the account sending and 610 | * paying for execution may not be the actual sender (as far as an application 611 | * is concerned). 612 | * 613 | * This contract is only required for intermediate, library-like contracts. 614 | */ 615 | contract Context { 616 | // Empty internal constructor, to prevent people from mistakenly deploying 617 | // an instance of this contract, which should be used via inheritance. 618 | constructor() internal {} 619 | 620 | function _msgSender() internal view returns (address payable) { 621 | return msg.sender; 622 | } 623 | 624 | function _msgData() internal view returns (bytes memory) { 625 | this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 626 | return msg.data; 627 | } 628 | } 629 | 630 | // File: @pancakeswap/pancake-swap-lib/contracts/access/Ownable.sol 631 | 632 | 633 | pragma solidity >=0.4.0; 634 | 635 | 636 | /** 637 | * @dev Contract module which provides a basic access control mechanism, where 638 | * there is an account (an owner) that can be granted exclusive access to 639 | * specific functions. 640 | * 641 | * By default, the owner account will be the one that deploys the contract. This 642 | * can later be changed with {transferOwnership}. 643 | * 644 | * This module is used through inheritance. It will make available the modifier 645 | * `onlyOwner`, which can be applied to your functions to restrict their use to 646 | * the owner. 647 | */ 648 | contract Ownable is Context { 649 | address private _owner; 650 | 651 | event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); 652 | 653 | /** 654 | * @dev Initializes the contract setting the deployer as the initial owner. 655 | */ 656 | constructor() internal { 657 | address msgSender = _msgSender(); 658 | _owner = msgSender; 659 | emit OwnershipTransferred(address(0), msgSender); 660 | } 661 | 662 | /** 663 | * @dev Returns the address of the current owner. 664 | */ 665 | function owner() public view returns (address) { 666 | return _owner; 667 | } 668 | 669 | /** 670 | * @dev Throws if called by any account other than the owner. 671 | */ 672 | modifier onlyOwner() { 673 | require(_owner == _msgSender(), 'Ownable: caller is not the owner'); 674 | _; 675 | } 676 | 677 | /** 678 | * @dev Leaves the contract without owner. It will not be possible to call 679 | * `onlyOwner` functions anymore. Can only be called by the current owner. 680 | * 681 | * NOTE: Renouncing ownership will leave the contract without an owner, 682 | * thereby removing any functionality that is only available to the owner. 683 | */ 684 | function renounceOwnership() public onlyOwner { 685 | emit OwnershipTransferred(_owner, address(0)); 686 | _owner = address(0); 687 | } 688 | 689 | /** 690 | * @dev Transfers ownership of the contract to a new account (`newOwner`). 691 | * Can only be called by the current owner. 692 | */ 693 | function transferOwnership(address newOwner) public onlyOwner { 694 | _transferOwnership(newOwner); 695 | } 696 | 697 | /** 698 | * @dev Transfers ownership of the contract to a new account (`newOwner`). 699 | */ 700 | function _transferOwnership(address newOwner) internal { 701 | require(newOwner != address(0), 'Ownable: new owner is the zero address'); 702 | emit OwnershipTransferred(_owner, newOwner); 703 | _owner = newOwner; 704 | } 705 | } 706 | 707 | pragma solidity >=0.4.0; 708 | 709 | /** 710 | * @title TokenRecover 711 | * @dev Allow to recover any BEP20 sent into the contract for error 712 | */ 713 | contract TokenRecover is Ownable { 714 | 715 | /** 716 | * @dev Remember that only owner can call so be careful when use on contracts generated from other contracts. 717 | * @param tokenAddress The token contract address 718 | * @param tokenAmount Number of tokens to be sent 719 | */ 720 | function recoverBEP20(address tokenAddress, uint256 tokenAmount) public onlyOwner { 721 | IBEP20(tokenAddress).transfer(owner(), tokenAmount); 722 | } 723 | } 724 | 725 | // File: contracts/TreePool.sol 726 | 727 | pragma solidity 0.6.12; 728 | 729 | 730 | 731 | 732 | contract TreePool is TokenRecover { 733 | using SafeMath for uint256; 734 | using SafeBEP20 for IBEP20; 735 | 736 | // Info of each user. 737 | struct UserInfo { 738 | uint256 amount; // How many LP tokens the user has provided. 739 | uint256 rewardDebt; // Reward debt. See explanation below. 740 | } 741 | 742 | // Info of each pool. 743 | struct PoolInfo { 744 | IBEP20 lpToken; // Address of LP token contract. 745 | uint256 allocPoint; // How many allocation points assigned to this pool. CAKEs to distribute per block. 746 | uint256 lastRewardBlock; // Last block number that CAKEs distribution occurs. 747 | uint256 accCakePerShare; // Accumulated CAKEs per share, times 1e12. See below. 748 | } 749 | 750 | // The CAKE TOKEN! 751 | IBEP20 public syrup; 752 | IBEP20 public rewardToken; 753 | 754 | // CAKE tokens created per block. 755 | uint256 public rewardPerBlock; 756 | 757 | // Info of each pool. 758 | PoolInfo[] public poolInfo; 759 | // Info of each user that stakes LP tokens. 760 | mapping (address => UserInfo) public userInfo; 761 | // Total allocation poitns. Must be the sum of all allocation points in all pools. 762 | uint256 private totalAllocPoint = 0; 763 | // The block number when CAKE mining starts. 764 | uint256 public startBlock; 765 | // The block number when CAKE mining ends. 766 | uint256 public bonusEndBlock; 767 | 768 | uint256 public withdrawFeeRate = 0; 769 | address public treasuryAddress = address(0xdead); 770 | 771 | 772 | event Deposit(address indexed user, uint256 amount); 773 | event Withdraw(address indexed user, uint256 amount); 774 | event WithdrawFee(address indexed user, uint256 amount); 775 | event EmergencyWithdraw(address indexed user, uint256 amount); 776 | 777 | IBEP20 stakeToken; 778 | 779 | constructor( 780 | IBEP20 _stakeToken, 781 | IBEP20 _rewardToken, 782 | uint256 _rewardPerBlock, 783 | uint256 _startBlock, 784 | uint256 _bonusEndBlock 785 | ) public { 786 | rewardToken = _rewardToken; 787 | rewardPerBlock = _rewardPerBlock; 788 | startBlock = _startBlock; 789 | bonusEndBlock = _bonusEndBlock; 790 | stakeToken = _stakeToken; 791 | 792 | totalAllocPoint = 1000; 793 | 794 | // staking pool 795 | poolInfo.push(PoolInfo({ 796 | lpToken: _stakeToken, 797 | allocPoint: totalAllocPoint, 798 | lastRewardBlock: startBlock, 799 | accCakePerShare: 0 800 | })); 801 | 802 | } 803 | 804 | function stopReward() public onlyOwner { 805 | bonusEndBlock = block.number; 806 | } 807 | 808 | 809 | // Return reward multiplier over the given _from to _to block. 810 | function getMultiplier(uint256 _from, uint256 _to) public view returns (uint256) { 811 | if (_to <= bonusEndBlock) { 812 | return _to.sub(_from); 813 | } else if (_from >= bonusEndBlock) { 814 | return 0; 815 | } else { 816 | return bonusEndBlock.sub(_from); 817 | } 818 | } 819 | 820 | // View function to see pending Reward on frontend. 821 | function pendingReward(address _user) external view returns (uint256) { 822 | PoolInfo storage pool = poolInfo[0]; 823 | UserInfo storage user = userInfo[_user]; 824 | uint256 accCakePerShare = pool.accCakePerShare; 825 | uint256 lpSupply = pool.lpToken.balanceOf(address(this)); 826 | if (block.number > pool.lastRewardBlock && lpSupply != 0) { 827 | uint256 multiplier = getMultiplier(pool.lastRewardBlock, block.number); 828 | uint256 cakeReward = multiplier.mul(rewardPerBlock).mul(pool.allocPoint).div(totalAllocPoint); 829 | accCakePerShare = accCakePerShare.add(cakeReward.mul(1e12).div(lpSupply)); 830 | } 831 | return user.amount.mul(accCakePerShare).div(1e12).sub(user.rewardDebt); 832 | } 833 | 834 | // Update reward variables of the given pool to be up-to-date. 835 | function updatePool(uint256 _pid) public { 836 | PoolInfo storage pool = poolInfo[_pid]; 837 | if (block.number <= pool.lastRewardBlock) { 838 | return; 839 | } 840 | uint256 lpSupply = pool.lpToken.balanceOf(address(this)); 841 | if (lpSupply == 0) { 842 | pool.lastRewardBlock = block.number; 843 | return; 844 | } 845 | uint256 multiplier = getMultiplier(pool.lastRewardBlock, block.number); 846 | uint256 cakeReward = multiplier.mul(rewardPerBlock).mul(pool.allocPoint).div(totalAllocPoint); 847 | pool.accCakePerShare = pool.accCakePerShare.add(cakeReward.mul(1e12).div(lpSupply)); 848 | pool.lastRewardBlock = block.number; 849 | } 850 | 851 | // Update reward variables for all pools. Be careful of gas spending! 852 | function massUpdatePools() public { 853 | uint256 length = poolInfo.length; 854 | for (uint256 pid = 0; pid < length; ++pid) { 855 | updatePool(pid); 856 | } 857 | } 858 | 859 | 860 | // Stake SYRUP tokens to SmartChef 861 | function deposit(uint256 _amount) public { 862 | PoolInfo storage pool = poolInfo[0]; 863 | UserInfo storage user = userInfo[msg.sender]; 864 | 865 | updatePool(0); 866 | if (user.amount > 0) { 867 | uint256 pending = user.amount.mul(pool.accCakePerShare).div(1e12).sub(user.rewardDebt); 868 | if(pending > 0) { 869 | rewardToken.safeTransfer(address(msg.sender), pending); 870 | } 871 | } 872 | if(_amount > 0) { 873 | pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amount); 874 | user.amount = user.amount.add(_amount); 875 | } 876 | user.rewardDebt = user.amount.mul(pool.accCakePerShare).div(1e12); 877 | 878 | emit Deposit(msg.sender, _amount); 879 | } 880 | 881 | // Withdraw SYRUP tokens from STAKING. 882 | function withdraw(uint256 _amount) public { 883 | PoolInfo storage pool = poolInfo[0]; 884 | UserInfo storage user = userInfo[msg.sender]; 885 | require(user.amount >= _amount, "withdraw: not good"); 886 | updatePool(0); 887 | uint256 pending = user.amount.mul(pool.accCakePerShare).div(1e12).sub(user.rewardDebt); 888 | if(pending > 0) { 889 | rewardToken.safeTransfer(address(msg.sender), pending); 890 | } 891 | if(_amount > 0) { 892 | user.amount = user.amount.sub(_amount); 893 | 894 | if(withdrawFeeRate>0) 895 | { 896 | uint256 withdrawFeeAmount = _amount.mul(withdrawFeeRate).div(1000); 897 | _amount = _amount.sub(withdrawFeeAmount); 898 | pool.lpToken.safeTransfer(treasuryAddress, withdrawFeeAmount); 899 | 900 | emit WithdrawFee(treasuryAddress, withdrawFeeAmount); 901 | } 902 | 903 | pool.lpToken.safeTransfer(address(msg.sender), _amount); 904 | } 905 | user.rewardDebt = user.amount.mul(pool.accCakePerShare).div(1e12); 906 | 907 | emit Withdraw(msg.sender, _amount); 908 | } 909 | 910 | // Withdraw without caring about rewards. EMERGENCY ONLY. 911 | function emergencyWithdraw() public { 912 | PoolInfo storage pool = poolInfo[0]; 913 | UserInfo storage user = userInfo[msg.sender]; 914 | uint256 _amount = user.amount; 915 | 916 | if(withdrawFeeRate>0) 917 | { 918 | uint256 withdrawFeeAmount = _amount.mul(withdrawFeeRate).div(1000); 919 | _amount = _amount.sub(withdrawFeeAmount); 920 | pool.lpToken.safeTransfer(treasuryAddress, withdrawFeeAmount); 921 | 922 | emit WithdrawFee(treasuryAddress, withdrawFeeAmount); 923 | } 924 | 925 | pool.lpToken.safeTransfer(address(msg.sender), _amount); 926 | user.amount = 0; 927 | user.rewardDebt = 0; 928 | emit EmergencyWithdraw(msg.sender,_amount); 929 | } 930 | 931 | // Withdraw reward. EMERGENCY ONLY. 932 | function emergencyRewardWithdraw(uint256 _amount) public onlyOwner { 933 | require(_amount < rewardToken.balanceOf(address(this)), 'not enough token'); 934 | rewardToken.safeTransfer(address(msg.sender), _amount); 935 | } 936 | 937 | // Add a function to update rewardPerBlock. Can only be called by the owner. 938 | function updateRewardPerBlock(uint256 _rewardPerBlock) public onlyOwner { 939 | rewardPerBlock = _rewardPerBlock; 940 | //Automatically updatePool 0 941 | updatePool(0); 942 | } 943 | 944 | // Add a function to update lastRewardBlock. Can only be called by the owner. 945 | function updateLastRewardBlock(uint256 _bonusEndBlock) public onlyOwner { 946 | poolInfo[0].lastRewardBlock = _bonusEndBlock; 947 | } 948 | 949 | // Add a function to update bonusEndBlock. Can only be called by the owner. 950 | function updateRewardEndBlock(uint256 _bonusEndBlock) public onlyOwner { 951 | bonusEndBlock = _bonusEndBlock; 952 | } 953 | 954 | // Add a function to update startBlock. Can only be called by the owner. 955 | function updateStartBlock(uint256 _startBlock) public onlyOwner { 956 | //Can only be updated if the original startBlock is not minted 957 | require(block.number <= poolInfo[0].lastRewardBlock, "updateStartBlock: startblock already minted"); 958 | poolInfo[0].lastRewardBlock = _startBlock; 959 | startBlock = _startBlock; 960 | } 961 | 962 | } 963 | --------------------------------------------------------------------------------