|
{
|
|
"language": "Solidity",
|
|
"sources": {
|
|
"contracts/staking/MasterChef.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\npragma solidity >=0.8.0;\n\nimport \"../tokens/HelixToken.sol\";\nimport \"../interfaces/IReferralRegister.sol\";\nimport \"../interfaces/IFeeMinter.sol\";\nimport \"../timelock/OwnableTimelockUpgradeable.sol\";\n\nimport \"@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol\";\nimport \"@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol\";\nimport \"@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol\";\nimport \"@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol\";\nimport \"@uniswap/lib/contracts/libraries/TransferHelper.sol\";\n\ncontract MasterChef is Initializable, PausableUpgradeable, OwnableUpgradeable, OwnableTimelockUpgradeable {\n // Info of each user.\n struct UserInfo {\n uint256 amount; // How many LP tokens the user has provided.\n uint256 rewardDebt; // Reward debt. See explanation below.\n //\n // We do some fancy math here. Basically, any point in time, the amount of HelixTokens\n // entitled to a user but is pending to be distributed is:\n //\n // pending reward = (user.amount * pool.accHelixTokenPerShare) - user.rewardDebt\n //\n // Whenever a user deposits or withdraws LP tokens to a pool. Here's what happens:\n // 1. The pool's `accHelixTokenPerShare` (and `lastRewardBlock`) gets updated.\n // 2. User receives the pending reward sent to his/her address.\n // 3. User's `amount` gets updated.\n // 4. User's `rewardDebt` gets updated.\n }\n // Info of each pool.\n struct PoolInfo {\n IERC20 lpToken; // Address of LP token contract.\n uint256 allocPoint; // How many allocation points assigned to this pool. HelixTokens to distribute per block.\n uint256 lastRewardBlock; // Last block number that HelixTokens distribution occurs.\n uint256 accHelixTokenPerShare; // Accumulated HelixTokens per share, times 1e12. See below.\n }\n\n // Used by bucket deposits and withdrawals to enable a caller to deposit lpTokens\n // and accrue yield into distinct, uniquely indentified \"buckets\" such that each\n // bucket can be interacted with individually and without affecting deposits and \n // yields in other buckets\n struct BucketInfo {\n uint256 amount; // How many LP tokens have been deposited into the bucket\n uint256 rewardDebt; // Reward debt. See explanation in UserInfo\n uint256 yield; // Accrued but unwithdrawn yield\n }\n \n // The HelixToken TOKEN!\n HelixToken public helixToken;\n\n // Called to get helix token to mint per block rates\n IFeeMinter public feeMinter;\n\n //Pools, Farms, Dev, Refs percent decimals\n uint256 public percentDec;\n\n //Pools and Farms percent from token per block\n uint256 public stakingPercent;\n\n //Developers percent from token per block\n uint256 public devPercent;\n\n // Dev address.\n address public devaddr;\n\n // Last block then develeper withdraw dev and ref fee\n uint256 public lastBlockDevWithdraw;\n\n // Bonus muliplier for early HelixToken makers.\n uint256 public BONUS_MULTIPLIER;\n\n // Referral Register contract\n IReferralRegister public refRegister;\n\n // Info of each pool.\n PoolInfo[] public poolInfo;\n\n // Total allocation poitns. Must be the sum of all allocation points in all pools.\n uint256 public totalAllocPoint;\n\n // The block number when HelixToken mining starts.\n uint256 public startBlock;\n\n // Deposited amount HelixToken in MasterChef\n uint256 public depositedHelix;\n\n // Maps poolId => depositorAddress => bucketId => BucketInfo\n // where the depositor is depositing funds into a uniquely identified deposit \"bucket\"\n // and where those funds are only accessible by the depositor\n // Used by the bucket deposit and withdraw functions\n mapping(uint256 => mapping(address => mapping(uint256 => BucketInfo))) public bucketInfo;\n\n // Info of each user that stakes LP tokens.\n mapping(uint256 => mapping(address => UserInfo)) public userInfo;\n\n // Maps a lpToken address to a poolId\n mapping(address => uint256) public poolIds;\n\n event Deposit(\n address indexed user, \n uint256 indexed pid, \n uint256 amount\n );\n\n event Withdraw(\n address indexed user, \n uint256 indexed pid, \n uint256 amount\n );\n\n event EmergencyWithdraw(\n address indexed user,\n uint256 indexed pid,\n uint256 amount\n );\n\n // Emitted when the owner adds a new LP Token to the pool\n event Added(uint256 indexed poolId, address indexed lpToken, bool withUpdate);\n\n // Emitted when the owner sets the pool alloc point\n event AllocPointSet(uint256 indexed poolId, uint256 allocPoint, bool withUpdate);\n\n // Emitted when the owner sets a new referral register contract\n event ReferralRegisterSet(address referralRegister);\n\n // Emitted when the pool is updated\n event PoolUpdated(uint256 indexed poolId);\n\n // Emitted when the owner sets a new dev address\n event DevAddressSet(address devAddress);\n\n // Emitted when the owner updates the helix per block rate\n event HelixPerBlockUpdated(uint256 rate);\n\n // Emitted when the feeMinter is set\n event SetFeeMinter(address indexed setter, address indexed feeMinter);\n \n // Emitted when a depositor deposits amount of lpToken into bucketId and stakes to poolId\n event BucketDeposit(\n address indexed depositor, \n uint256 indexed bucketId,\n uint256 poolId, \n uint256 amount\n );\n\n event BucketWithdraw(\n address indexed depositor, \n uint256 indexed bucketId,\n uint256 poolId, \n uint256 amount\n );\n\n event BucketWithdrawAmountTo(\n address indexed depositor, \n address indexed recipient,\n uint256 indexed bucketId,\n uint256 poolId, \n uint256 amount\n );\n\n event BucketWithdrawYieldTo(\n address indexed depositor, \n address indexed recipient,\n uint256 indexed bucketId,\n uint256 poolId, \n uint256 yield \n );\n\n event UpdateBucket(\n address indexed depositor,\n uint256 indexed bucketId,\n uint256 indexed poolId\n );\n\n modifier isNotHelixPoolId(uint256 poolId) {\n require(poolId != 0, \"MasterChef: invalid pool id\");\n _;\n }\n\n modifier isNotZeroAddress(address _address) {\n require(_address != address(0), \"MasterChef: zero address\");\n _;\n }\n\n function initialize(\n HelixToken _HelixToken,\n address _devaddr,\n address _feeMinter,\n uint256 _startBlock,\n uint256 _stakingPercent,\n uint256 _devPercent,\n IReferralRegister _referralRegister\n ) external initializer {\n __Ownable_init();\n __OwnableTimelock_init();\n helixToken = _HelixToken;\n devaddr = _devaddr;\n feeMinter = IFeeMinter(_feeMinter);\n startBlock = _startBlock != 0 ? _startBlock : block.number;\n stakingPercent = _stakingPercent;\n devPercent = _devPercent;\n lastBlockDevWithdraw = _startBlock != 0 ? _startBlock : block.number;\n refRegister = _referralRegister;\n \n // staking pool\n poolInfo.push(PoolInfo({\n lpToken: _HelixToken,\n allocPoint: 1000,\n lastRewardBlock: startBlock,\n accHelixTokenPerShare: 0\n }));\n poolIds[address(_HelixToken)] = 0;\n\n totalAllocPoint = 1000;\n percentDec = 1000000;\n BONUS_MULTIPLIER = 1;\n }\n\n function updateMultiplier(uint256 multiplierNumber) external onlyTimelock {\n BONUS_MULTIPLIER = multiplierNumber;\n }\n\n function poolLength() external view returns (uint256) {\n return poolInfo.length;\n }\n\n // Return the lpToken address associated with poolId _pid\n function getLpToken(uint256 _pid) external view returns(address) {\n return address(poolInfo[_pid].lpToken);\n }\n \n // Return the poolId associated with the lpToken address\n function getPoolId(address _lpToken) external view returns (uint256) {\n uint256 poolId = poolIds[_lpToken];\n if (poolId == 0) {\n require(_lpToken == address(helixToken), \"MasterChef: token not added\");\n }\n return poolId;\n }\n\n function withdrawDevAndRefFee() external {\n require(lastBlockDevWithdraw < block.number, \"MasterChef: wait for new block\");\n uint256 blockDelta = getMultiplier(lastBlockDevWithdraw, block.number);\n uint256 helixTokenReward = blockDelta * _getDevToMintPerBlock();\n lastBlockDevWithdraw = block.number;\n helixToken.mint(devaddr, helixTokenReward);\n }\n\n // Add a new lp to the pool. Can only be called by the owner.\n // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do.\n function add(uint256 _allocPoint, IERC20 _lpToken, bool _withUpdate) external onlyTimelock {\n if (_withUpdate) {\n massUpdatePools();\n }\n uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock;\n totalAllocPoint = totalAllocPoint + (_allocPoint);\n poolInfo.push(\n PoolInfo({\n lpToken: _lpToken,\n allocPoint: _allocPoint,\n lastRewardBlock: lastRewardBlock,\n accHelixTokenPerShare: 0\n })\n );\n\n uint256 poolId = poolInfo.length - 1;\n poolIds[address(_lpToken)] = poolId;\n\n emit Added(poolId, address(_lpToken), _withUpdate);\n }\n\n // Update the given pool's HelixToken allocation point. Can only be called by the owner.\n function set( uint256 _pid, uint256 _allocPoint, bool _withUpdate) external onlyTimelock {\n if (_withUpdate) {\n massUpdatePools();\n }\n totalAllocPoint = totalAllocPoint - (poolInfo[_pid].allocPoint) + (_allocPoint);\n poolInfo[_pid].allocPoint = _allocPoint;\n\n emit AllocPointSet(_pid, _allocPoint, _withUpdate);\n }\n\n /// Called by the owner to pause the contract\n function pause() external onlyOwner {\n _pause();\n }\n\n /// Called by the owner to unpause the contract\n function unpause() external onlyOwner {\n _unpause();\n }\n\n // Return reward multiplier over the given _from to _to block.\n function getMultiplier(uint256 _from, uint256 _to) public view returns (uint256) {\n return (_to - _from) * (BONUS_MULTIPLIER);\n }\n\n // Set ReferralRegister address\n function setReferralRegister(address _address) external onlyOwner {\n refRegister = IReferralRegister(_address);\n emit ReferralRegisterSet(_address);\n }\n\n // View function to see pending HelixTokens on frontend.\n function pendingHelixToken(uint256 _pid, address _user) external view returns (uint256){\n PoolInfo memory pool = poolInfo[_pid];\n UserInfo memory user = userInfo[_pid][_user];\n uint256 accHelixTokenPerShare = pool.accHelixTokenPerShare;\n uint256 lpSupply = pool.lpToken.balanceOf(address(this));\n if (_pid == 0){\n lpSupply = depositedHelix;\n }\n\n if (block.number > pool.lastRewardBlock && lpSupply != 0) {\n uint256 blockDelta = getMultiplier(pool.lastRewardBlock, block.number);\n uint256 toMintPerBlock = _getStakeToMintPerBlock();\n uint256 helixTokenReward = blockDelta * toMintPerBlock * (pool.allocPoint) / (totalAllocPoint);\n accHelixTokenPerShare = accHelixTokenPerShare + (helixTokenReward * (1e12) / (lpSupply));\n }\n\n uint256 pending = user.amount * (accHelixTokenPerShare) / (1e12) - (user.rewardDebt);\n return pending;\n }\n\n // Update reward vairables for all pools. Be careful of gas spending!\n function massUpdatePools() public {\n uint256 length = poolInfo.length;\n for (uint256 pid = 0; pid < length; ++pid) {\n updatePool(pid);\n }\n }\n\n // Update reward variables of the given pool to be up-to-date.\n function updatePool(uint256 _pid) public {\n PoolInfo storage pool = poolInfo[_pid];\n if (block.number <= pool.lastRewardBlock) {\n return;\n }\n uint256 lpSupply = pool.lpToken.balanceOf(address(this));\n if (_pid == 0){\n lpSupply = depositedHelix;\n }\n if (lpSupply <= 0) {\n pool.lastRewardBlock = block.number;\n return;\n }\n uint256 blockDelta = getMultiplier(pool.lastRewardBlock, block.number);\n uint256 toMintPerBlock = _getStakeToMintPerBlock();\n uint256 helixTokenReward = blockDelta * toMintPerBlock * pool.allocPoint / (totalAllocPoint);\n pool.accHelixTokenPerShare = pool.accHelixTokenPerShare + (helixTokenReward * (1e12) / (lpSupply));\n pool.lastRewardBlock = block.number;\n helixToken.mint(address(this), helixTokenReward);\n\n emit PoolUpdated(_pid);\n }\n\n // Deposit LP tokens to MasterChef for HelixToken allocation.\n function deposit(uint256 _pid, uint256 _amount) external whenNotPaused isNotHelixPoolId(_pid) {\n PoolInfo storage pool = poolInfo[_pid];\n UserInfo storage user = userInfo[_pid][msg.sender];\n\n updatePool(_pid);\n\n uint256 pending = user.amount * (pool.accHelixTokenPerShare) / (1e12) - (user.rewardDebt);\n user.amount = user.amount + (_amount);\n user.rewardDebt = user.amount * (pool.accHelixTokenPerShare) / (1e12);\n\n if (pending > 0) {\n refRegister.rewardStake(msg.sender, pending);\n safeHelixTokenTransfer(msg.sender, pending);\n }\n if (_amount > 0) {\n TransferHelper.safeTransferFrom(address(pool.lpToken), address(msg.sender), address(this), _amount);\n }\n\n emit Deposit(msg.sender, _pid, _amount);\n }\n\n // Withdraw LP tokens from MasterChef.\n function withdraw(uint256 _pid, uint256 _amount) external whenNotPaused isNotHelixPoolId(_pid) {\n PoolInfo storage pool = poolInfo[_pid];\n UserInfo storage user = userInfo[_pid][msg.sender];\n\n require(user.amount >= _amount, \"MasterChef: insufficient balance\");\n\n updatePool(_pid);\n\n uint256 pending = user.amount * (pool.accHelixTokenPerShare) / (1e12) - (user.rewardDebt);\n user.amount -= _amount;\n user.rewardDebt = user.amount * (pool.accHelixTokenPerShare) / (1e12);\n\n if (pending > 0) {\n refRegister.rewardStake(msg.sender, pending);\n safeHelixTokenTransfer(msg.sender, pending);\n }\n if (_amount > 0) {\n TransferHelper.safeTransfer(address(pool.lpToken), address(msg.sender), _amount);\n }\n\n emit Withdraw(msg.sender, _pid, _amount);\n }\n\n // Deposit _amount of lpToken into _bucketId and accrue yield by staking _amount to _poolId\n function bucketDeposit(\n uint256 _bucketId, // Unique bucket to deposit _amount into\n uint256 _poolId, // Pool to deposit _amount into\n uint256 _amount // Amount of lpToken being deposited\n ) \n external \n whenNotPaused\n isNotHelixPoolId(_poolId)\n {\n PoolInfo storage pool = poolInfo[_poolId];\n BucketInfo storage bucket = bucketInfo[_poolId][msg.sender][_bucketId];\n\n updatePool(_poolId);\n\n // If the bucket already has already accrued rewards, \n // increment the yield before resetting the rewardDebt\n if (bucket.amount > 0) {\n bucket.yield += bucket.amount * (pool.accHelixTokenPerShare) / (1e12) - (bucket.rewardDebt);\n }\n \n // Update the bucket amount and reset the rewardDebt\n bucket.amount += _amount;\n bucket.rewardDebt = bucket.amount * (pool.accHelixTokenPerShare) / (1e12);\n\n // Transfer amount of lpToken from caller to chef\n require(\n _amount <= pool.lpToken.allowance(msg.sender, address(this)), \n \"MasterChef: insufficient allowance\"\n );\n TransferHelper.safeTransferFrom(address(pool.lpToken), msg.sender, address(this), _amount);\n\n emit BucketDeposit(msg.sender, _bucketId, _poolId, _amount);\n }\n\n // Withdraw _amount of lpToken and all accrued yield from _bucketId and _poolId\n function bucketWithdraw(uint256 _bucketId, uint256 _poolId, uint256 _amount) external whenNotPaused isNotHelixPoolId(_poolId) {\n PoolInfo storage pool = poolInfo[_poolId];\n BucketInfo storage bucket = bucketInfo[_poolId][msg.sender][_bucketId];\n\n require(_amount <= bucket.amount, \"MasterChef: insufficient balance\");\n\n updatePool(_poolId);\n \n // Calculate the total yield to withdraw\n uint256 pending = bucket.amount * (pool.accHelixTokenPerShare) / (1e12) - (bucket.rewardDebt);\n uint256 yield = bucket.yield + pending;\n\n // Update the bucket state\n bucket.amount -= _amount;\n bucket.rewardDebt = bucket.amount * (pool.accHelixTokenPerShare) / (1e12);\n bucket.yield = 0;\n\n // Withdraw the yield and lpToken\n refRegister.rewardStake(msg.sender, yield);\n safeHelixTokenTransfer(msg.sender, yield);\n TransferHelper.safeTransfer(address(pool.lpToken), address(msg.sender), _amount);\n\n emit BucketWithdraw(msg.sender, _bucketId, _poolId, _amount);\n }\n\n // Withdraw _amount of lpToken from _bucketId and from _poolId\n // and send the withdrawn _amount to _recipient\n function bucketWithdrawAmountTo(\n address _recipient,\n uint256 _bucketId,\n uint256 _poolId, \n uint256 _amount\n ) \n external \n whenNotPaused\n isNotZeroAddress(_recipient)\n isNotHelixPoolId(_poolId)\n {\n PoolInfo storage pool = poolInfo[_poolId];\n\n BucketInfo storage bucket = bucketInfo[_poolId][msg.sender][_bucketId];\n require(\n _amount <= bucket.amount, \n \"MasterChef: insufficient balance\"\n );\n\n updatePool(_poolId);\n\n // Update the bucket state\n bucket.yield += bucket.amount * (pool.accHelixTokenPerShare) / (1e12) - (bucket.rewardDebt);\n bucket.amount -= _amount;\n bucket.rewardDebt = bucket.amount * (pool.accHelixTokenPerShare) / (1e12);\n\n // Transfer only lpToken to the recipient\n TransferHelper.safeTransfer(address(pool.lpToken), _recipient, _amount);\n\n emit BucketWithdrawAmountTo(msg.sender, _recipient, _bucketId, _poolId, _amount);\n }\n\n // Withdraw total yield in HelixToken from _bucketId and _poolId and send to _recipient\n function bucketWithdrawYieldTo(\n address _recipient,\n uint256 _bucketId,\n uint256 _poolId,\n uint256 _yield\n ) \n external \n whenNotPaused\n isNotZeroAddress(_recipient)\n isNotHelixPoolId(_poolId)\n {\n PoolInfo storage pool = poolInfo[_poolId];\n BucketInfo storage bucket = bucketInfo[_poolId][msg.sender][_bucketId];\n\n updatePool(_poolId);\n\n // Total yield is any pending yield plus any previously calculated yield\n uint256 pending = bucket.amount * (pool.accHelixTokenPerShare) / (1e12) - (bucket.rewardDebt);\n uint256 yield = bucket.yield + pending;\n\n require(\n _yield <= yield,\n \"MasterChef: insufficient balance\"\n );\n\n // Update bucket state\n bucket.rewardDebt = bucket.amount * (pool.accHelixTokenPerShare) / (1e12);\n yield -= _yield;\n\n refRegister.rewardStake(msg.sender, yield);\n safeHelixTokenTransfer(_recipient, _yield);\n\n emit BucketWithdrawYieldTo(msg.sender, _recipient, _bucketId, _poolId, _yield);\n }\n\n // Update _poolId and _bucketId yield and rewardDebt\n function updateBucket(uint256 _bucketId, uint256 _poolId) external isNotHelixPoolId(_poolId) {\n PoolInfo storage pool = poolInfo[_poolId];\n BucketInfo storage bucket = bucketInfo[_poolId][msg.sender][_bucketId];\n\n updatePool(_poolId);\n\n bucket.yield += bucket.amount * (pool.accHelixTokenPerShare) / (1e12) - (bucket.rewardDebt);\n bucket.rewardDebt = bucket.amount * (pool.accHelixTokenPerShare) / (1e12);\n\n emit UpdateBucket(msg.sender, _bucketId, _poolId);\n }\n\n function getBucketYield(uint256 _bucketId, uint256 _poolId) \n external \n view \n isNotHelixPoolId(_poolId)\n returns (uint256 yield) \n {\n BucketInfo memory bucket = bucketInfo[_poolId][msg.sender][_bucketId];\n yield = bucket.yield;\n }\n\n // Stake HelixToken tokens to MasterChef\n function enterStaking(uint256 _amount) external whenNotPaused {\n PoolInfo storage pool = poolInfo[0];\n UserInfo storage user = userInfo[0][msg.sender];\n\n updatePool(0);\n depositedHelix += _amount;\n\n uint256 pending = user.amount * (pool.accHelixTokenPerShare) / (1e12) - (user.rewardDebt);\n user.amount += _amount;\n user.rewardDebt = user.amount * (pool.accHelixTokenPerShare) / (1e12);\n \n if (pending > 0) {\n refRegister.rewardStake(msg.sender, pending);\n safeHelixTokenTransfer(msg.sender, pending);\n }\n if (_amount > 0) {\n TransferHelper.safeTransferFrom(address(pool.lpToken), address(msg.sender), address(this), _amount);\n }\n\n emit Deposit(msg.sender, 0, _amount);\n }\n\n // Withdraw HelixToken tokens from STAKING.\n function leaveStaking(uint256 _amount) external whenNotPaused {\n PoolInfo storage pool = poolInfo[0];\n UserInfo storage user = userInfo[0][msg.sender];\n\n updatePool(0);\n depositedHelix -= _amount;\n\n require(user.amount >= _amount, \"MasterChef: insufficient balance\");\n\n uint256 pending = user.amount * (pool.accHelixTokenPerShare) / (1e12) - (user.rewardDebt);\n user.amount -= _amount;\n user.rewardDebt = user.amount * (pool.accHelixTokenPerShare) / (1e12);\n\n if (pending > 0) {\n refRegister.rewardStake(msg.sender, pending);\n safeHelixTokenTransfer(msg.sender, pending);\n }\n if (_amount > 0) {\n TransferHelper.safeTransfer(address(pool.lpToken), address(msg.sender), _amount);\n }\n\n emit Withdraw(msg.sender, 0, _amount);\n }\n\n // Withdraw without caring about rewards. EMERGENCY ONLY.\n function emergencyWithdraw(uint256 _pid) external {\n PoolInfo memory pool = poolInfo[_pid];\n UserInfo storage user = userInfo[_pid][msg.sender];\n\n uint256 _amount = user.amount;\n user.amount = 0;\n user.rewardDebt = 0;\n\n TransferHelper.safeTransfer(address(pool.lpToken), address(msg.sender), _amount);\n\n emit EmergencyWithdraw(msg.sender, _pid, _amount);\n }\n\n /// Return the portion of toMintPerBlock assigned to staking and farms\n function getStakeToMintPerBlock() external view returns (uint256) {\n return _getStakeToMintPerBlock();\n }\n\n /// Return the portion of toMintPerBlock assigned to dev team\n function getDevToMintPerBlock() external view returns (uint256) {\n return _getDevToMintPerBlock();\n }\n\n /// Return the toMintPerBlock rate assigned to this contract by the feeMinter\n function getToMintPerBlock() external view returns (uint256) {\n return _getToMintPerBlock();\n }\n // Safe HelixToken transfer function, just in case if rounding error causes pool to not have enough HelixTokens.\n function safeHelixTokenTransfer(address _to, uint256 _amount) internal {\n uint256 helixTokenBal = helixToken.balanceOf(address(this));\n uint256 toTransfer = _amount > helixTokenBal ? helixTokenBal : _amount;\n require(helixToken.transfer(_to, toTransfer), \"MasterChef: transfer failed\");\n }\n\n function setDevAddress(address _devaddr) external onlyTimelock {\n devaddr = _devaddr;\n emit DevAddressSet(_devaddr);\n }\n\n function setFeeMinter(address _feeMinter) external onlyTimelock {\n feeMinter = IFeeMinter(_feeMinter);\n emit SetFeeMinter(msg.sender, _feeMinter);\n }\n\n // Return the portion of toMintPerBlock assigned to staking and farms\n function _getStakeToMintPerBlock() private view returns (uint256) {\n return _getToMintPerBlock() * stakingPercent / percentDec;\n }\n\n // Return the portion of toMintPerBlock assigned to dev team\n function _getDevToMintPerBlock() private view returns (uint256) {\n return _getToMintPerBlock() * devPercent / percentDec;\n }\n\n // Return the toMintPerBlock rate assigned to this contract by the feeMinter\n function _getToMintPerBlock() private view returns (uint256) {\n require(address(feeMinter) != address(0), \"MasterChef: fee minter unassigned\");\n return feeMinter.getToMintPerBlock(address(this));\n }\n\n function setDevAndStakingPercents(uint256 _devPercent, uint256 _stakingPercent) external onlyOwner {\n require(_stakingPercent + _devPercent == 1000000, \"MasterChef: invalid percents\");\n stakingPercent = _stakingPercent;\n devPercent = _devPercent;\n }\n}\n"
|
|
},
|
|
"contracts/tokens/HelixToken.sol": {
|
|
"content": "//SPDX-License-Identifier:MIT\npragma solidity >=0.8.0;\n\n// Copied and modified from YAM code:\n// https://github.com/yam-finance/yam-protocol/blob/master/contracts/token/YAMGovernanceStorage.sol\n// https://github.com/yam-finance/yam-protocol/blob/master/contracts/token/YAMGovernance.sol\n// Which is copied and modified from COMPOUND:\n// https://github.com/compound-finance/compound-protocol/blob/master/contracts/Governance/Comp.sol\n\nimport \"../libraries/ERC20.sol\";\nimport \"@openzeppelin/contracts/utils/structs/EnumerableSet.sol\";\n\n/// Geometry governance token\ncontract HelixToken is ERC20(\"Helix\", \"HELIX\") {\n using EnumerableSet for EnumerableSet.AddressSet;\n\n // @notice Checkpoint for marking number of votes from a given block\n struct Checkpoint {\n uint32 fromBlock;\n uint256 votes;\n }\n\n /// @notice The EIP-712 typehash for the contract's domain\n bytes32 public constant DOMAIN_TYPEHASH =\n keccak256(\n \"EIP712Domain(string name,uint256 chainId,address verifyingContract)\"\n );\n\n /// @notice The EIP-712 typehash for the delegation struct used by the contract\n bytes32 public constant DELEGATION_TYPEHASH =\n keccak256(\"Delegation(address delegatee,uint256 nonce,uint256 expiry)\");\n\n // Set of addresses which can mint HELIX\n EnumerableSet.AddressSet private _minters;\n \n /// @dev A record of each accounts delegate\n mapping(address => address) internal _delegates;\n\n /// @notice A record of votes checkpoints for each account, by index\n mapping(address => mapping(uint32 => Checkpoint)) public checkpoints;\n\n /// @notice The number of checkpoints for each account\n mapping(address => uint32) public numCheckpoints;\n\n /// @notice A record of states for signing / validating signatures\n mapping(address => uint256) public nonces;\n\n /// @notice An event that's emitted when an account changes its delegate\n event DelegateChanged(\n address indexed delegator,\n address indexed fromDelegate,\n address indexed toDelegate\n );\n\n /// @notice An event that's emitted when a delegate account's vote balance changes\n event DelegateVotesChanged(\n address indexed delegate,\n uint256 previousBalance,\n uint256 newBalance\n );\n\n modifier onlyMinter() {\n require(isMinter(msg.sender), \"Helix: not minter\");\n _;\n }\n\n modifier onlyValidAddress(address _address) {\n require(_address != address(0), \"Helix: zero address\");\n _;\n }\n\n /// @notice Creates _amount of token to _to.\n function mint(address _to, uint256 _amount)\n external \n onlyMinter\n returns (bool)\n {\n _mint(_to, _amount);\n _moveDelegates(address(0), _delegates[_to], _amount);\n return true;\n }\n\n /// @notice Destroys _amount tokens from _account reducing the total supply\n function burn(address _account, uint256 _amount) external onlyMinter {\n _burn(_account, _amount);\n }\n\n /// @notice Delegate votes from msg.sender to _delegatee\n /// @param _delegatee The address to delegate votes to\n function delegate(address _delegatee) external {\n return _delegate(msg.sender, _delegatee);\n }\n\n /**\n * @notice Delegates votes from signatory to `delegatee`\n * @param _delegatee The address to delegate votes to\n * @param _nonce The contract state required to match the signature\n * @param _expiry The time at which to expire the signature\n * @param _v The recovery byte of the signature\n * @param _r Half of the ECDSA signature pair\n * @param _s Half of the ECDSA signature pair\n */\n function delegateBySig(\n address _delegatee,\n uint256 _nonce,\n uint256 _expiry,\n uint8 _v,\n bytes32 _r,\n bytes32 _s\n ) external {\n bytes32 domainSeparator = keccak256(\n abi.encode(\n DOMAIN_TYPEHASH,\n keccak256(bytes(name())),\n _getChainId(),\n address(this)\n )\n );\n\n bytes32 structHash = keccak256(\n abi.encode(DELEGATION_TYPEHASH, _delegatee, _nonce, _expiry)\n );\n\n bytes32 digest = keccak256(\n abi.encodePacked(\"\\x19\\x01\", domainSeparator, structHash)\n );\n\n address signatory = ecrecover(digest, _v, _r, _s);\n\n require(signatory != address(0), \"Helix: invalid signature\");\n require(_nonce == nonces[signatory]++, \"Helix: invalid nonce\");\n require(block.timestamp <= _expiry, \"Helix: signature expired\");\n\n return _delegate(signatory, _delegatee);\n }\n\n /**\n * @dev used by owner to delete minter of token\n * @param _delMinter address of minter to be deleted.\n * @return true if successful.\n */\n function delMinter(address _delMinter) external onlyOwner onlyValidAddress(_delMinter) returns (bool) {\n return EnumerableSet.remove(_minters, _delMinter);\n }\n\n /// @notice Delegate votes from msg.sender to _delegatee\n /// @param _delegator The address to get delegatee for\n function delegates(address _delegator) external view returns (address) {\n return _delegates[_delegator];\n }\n\n /**\n * @notice Gets the current votes balance for `account`\n * @param _account The address to get votes balance\n * @return The number of current votes for `account`\n */\n function getCurrentVotes(address _account) external view returns (uint256) {\n uint32 nCheckpoints = numCheckpoints[_account];\n return\n nCheckpoints > 0 ? checkpoints[_account][nCheckpoints - 1].votes : 0;\n }\n\n /**\n * @notice Determine the prior number of votes for an account as of a block number\n * @dev Block number must be a finalized block or else this function will revert to prevent misinformation.\n * @param _account The address of the account to check\n * @param _blockNumber The block number to get the vote balance at\n * @return The number of votes the account had as of the given block\n */\n function getPriorVotes(address _account, uint256 _blockNumber)\n external\n view\n returns (uint256)\n {\n require(_blockNumber < block.number, \"Helix: invalid blockNumber\");\n\n uint32 nCheckpoints = numCheckpoints[_account];\n if (nCheckpoints == 0) {\n return 0;\n }\n\n // First check most recent balance\n if (checkpoints[_account][nCheckpoints - 1].fromBlock <= _blockNumber) {\n return checkpoints[_account][nCheckpoints - 1].votes;\n }\n\n // Next check implicit zero balance\n if (checkpoints[_account][0].fromBlock > _blockNumber) {\n return 0;\n }\n\n uint32 lower = 0;\n uint32 upper = nCheckpoints - 1;\n while (upper > lower) {\n uint32 center = upper - (upper - lower) / 2; // ceil, avoiding overflow\n Checkpoint memory cp = checkpoints[_account][center];\n if (cp.fromBlock == _blockNumber) {\n return cp.votes;\n } else if (cp.fromBlock < _blockNumber) {\n lower = center;\n } else {\n upper = center - 1;\n }\n }\n return checkpoints[_account][lower].votes;\n }\n\n /**\n * @dev used by get the minter at n location\n * @param _index index of address set\n * @return address of minter at index.\n */\n function getMinter(uint256 _index)\n external\n view\n onlyOwner\n returns (address)\n {\n require(_index <= getMinterLength() - 1, \"Helix: index out of bounds\");\n return EnumerableSet.at(_minters, _index);\n }\n\n /**\n * @dev used by owner to add minter of token\n * @param _addMinter address of minter to be added.\n * @return true if successful.\n */\n function addMinter(address _addMinter) public onlyOwner onlyValidAddress(_addMinter) returns (bool) {\n return EnumerableSet.add(_minters, _addMinter);\n }\n\n /// @dev used to get the number of minters for this token\n /// @return number of minters.\n function getMinterLength() public view returns (uint256) {\n return EnumerableSet.length(_minters);\n }\n\n /// @dev used to check if an address is a minter of token\n /// @return true or false based on minter status.\n function isMinter(address _account) public view returns (bool) {\n return EnumerableSet.contains(_minters, _account);\n }\n\n // internal function used delegate votes\n function _delegate(address _delegator, address _delegatee) internal {\n address currentDelegate = _delegates[_delegator];\n uint256 delegatorBalance = balanceOf(_delegator); // balance of underlying HELIXs (not scaled);\n _delegates[_delegator] = _delegatee;\n\n emit DelegateChanged(_delegator, currentDelegate, _delegatee);\n\n _moveDelegates(currentDelegate, _delegatee, delegatorBalance);\n }\n\n // send delegate votes from src to dst in amount\n function _moveDelegates(\n address _srcRep,\n address _dstRep,\n uint256 _amount\n ) internal {\n if (_srcRep != _dstRep && _amount > 0) {\n if (_srcRep != address(0)) {\n // decrease old representative\n uint32 srcRepNum = numCheckpoints[_srcRep];\n uint256 srcRepOld = srcRepNum > 0\n ? checkpoints[_srcRep][srcRepNum - 1].votes\n : 0;\n uint256 srcRepNew = srcRepOld - _amount;\n _writeCheckpoint(_srcRep, srcRepNum, srcRepOld, srcRepNew);\n }\n\n if (_dstRep != address(0)) {\n // increase new representative\n uint32 dstRepNum = numCheckpoints[_dstRep];\n uint256 dstRepOld = dstRepNum > 0\n ? checkpoints[_dstRep][dstRepNum - 1].votes\n : 0;\n uint256 dstRepNew = dstRepOld + _amount;\n _writeCheckpoint(_dstRep, dstRepNum, dstRepOld, dstRepNew);\n }\n }\n }\n\n function _writeCheckpoint(\n address _delegatee,\n uint32 _nCheckpoints,\n uint256 _oldVotes,\n uint256 _newVotes\n ) internal {\n uint32 blockNumber = _safe32(\n block.number,\n \"HELIX::_writeCheckpoint: block number exceeds 32 bits\"\n );\n\n if (\n _nCheckpoints > 0 &&\n checkpoints[_delegatee][_nCheckpoints - 1].fromBlock == blockNumber\n ) {\n checkpoints[_delegatee][_nCheckpoints - 1].votes = _newVotes;\n } else {\n checkpoints[_delegatee][_nCheckpoints] = Checkpoint(\n blockNumber,\n _newVotes\n );\n numCheckpoints[_delegatee] = _nCheckpoints + 1;\n }\n\n emit DelegateVotesChanged(_delegatee, _oldVotes, _newVotes);\n }\n\n // @dev used get current chain ID\n // @return id as a uint\n function _getChainId() internal view returns (uint256 id) {\n id = block.chainid;\n }\n\n /*\n * @dev Checks if value is 32 bits\n * @param _n value to be checked\n * @param _errorMessage error message to throw if fails\n * @return The number if valid.\n */\n function _safe32(uint256 _n, string memory _errorMessage)\n internal\n pure\n returns (uint32)\n {\n require(_n < 2**32, _errorMessage);\n return uint32(_n);\n }\n}\n"
|
|
},
|
|
"contracts/interfaces/IReferralRegister.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\npragma solidity >=0.8.0;\n\nimport \"./IHelixToken.sol\";\n\ninterface IReferralRegister {\n function toMintPerBlock() external view returns (uint256);\n function helixToken() external view returns (IHelixToken);\n function stakeRewardPercent() external view returns (uint256);\n function swapRewardPercent() external view returns (uint256);\n function lastMintBlock() external view returns (uint256);\n function referrers(address _referred) external view returns (address);\n function rewards(address _referrer) external view returns (uint256);\n\n function initialize(\n IHelixToken _helixToken, \n address _feeHandler,\n uint256 _stakeRewardPercent, \n uint256 _swapRewardPercent,\n uint256 _toMintPerBlock,\n uint256 _lastMintBlock\n ) external; \n\n function rewardStake(address _referred, uint256 _stakeAmount) external;\n function rewardSwap(address _referred, uint256 _swapAmount) external;\n function withdraw() external;\n function setToMintPerBlock(uint256 _toMintPerBlock) external;\n function setStakeRewardPercent(uint256 _stakeRewardPercent) external;\n function setSwapRewardPercent(uint256 _swapRewardPercent) external;\n function addReferrer(address _referrer) external;\n function removeReferrer() external;\n function update() external;\n function addRecorder(address _recorder) external returns (bool);\n function removeRecorder(address _recorder) external returns (bool);\n function setLastRewardBlock(uint256 _lastMintBlock) external;\n function pause() external;\n function unpause() external;\n function setFeeHandler(address _feeHandler) external;\n function setCollectorPercent(uint256 _collectorPercent) external;\n function getRecorder(uint256 _index) external view returns (address);\n function getRecorderLength() external view returns (uint256);\n function isRecorder(address _address) external view returns (bool);\n}\n"
|
|
},
|
|
"contracts/interfaces/IFeeMinter.sol": {
|
|
"content": "// SPDX-License-Identifer: MIT\npragma solidity >=0.8.0;\n\ninterface IFeeMinter {\n function totalToMintPerBlock() external view returns (uint256);\n function minters(uint256 index) external view returns (address);\n function setTotalToMintPerBlock(uint256 _totalToMintPerBlock) external;\n function setToMintPercents(address[] calldata _minters, uint256[] calldata _toMintPercents) external;\n function getToMintPerBlock(address _minter) external view returns (uint256);\n function getMinters() external view returns (address[] memory);\n function getToMintPercent(address _minter) external view returns (uint256);\n}\n"
|
|
},
|
|
"contracts/timelock/OwnableTimelockUpgradeable.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\npragma solidity >=0.8.0;\n\nimport \"@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol\";\nimport \"@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol\";\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract OwnableTimelockUpgradeable is Initializable, ContextUpgradeable {\n error CallerIsNotTimelockOwner();\n error ZeroTimelockAddress();\n\n address private _timelockOwner;\n\n event TimelockOwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n /**\n * @dev Initializes the contract setting the deployer as the initial owner.\n */\n function __OwnableTimelock_init() internal onlyInitializing {\n __OwnableTimelock_init_unchained();\n }\n\n function __OwnableTimelock_init_unchained() internal onlyInitializing {\n _transferTimelockOwnership(_msgSender());\n }\n\n /**\n * @dev Throws if called by any account other than the owner.\n */\n modifier onlyTimelock() {\n _checkTimelockOwner();\n _;\n }\n\n /**\n * @dev Returns the address of the current owner.\n */\n function timelockOwner() public view virtual returns (address) {\n return _timelockOwner;\n }\n\n /**\n * @dev Throws if the sender is not the owner.\n */\n function _checkTimelockOwner() internal view virtual {\n if (timelockOwner() != _msgSender()) revert CallerIsNotTimelockOwner();\n }\n\n /**\n * @dev Leaves the contract without owner. It will not be possible to call\n * `onlyOwner` functions anymore. Can only be called by the current owner.\n *\n * NOTE: Renouncing ownership will leave the contract without an owner,\n * thereby removing any functionality that is only available to the owner.\n */\n function renounceTimelockOwnership() public virtual onlyTimelock {\n _transferTimelockOwnership(address(0));\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Can only be called by the current owner.\n */\n function transferTimelockOwnership(address newOwner) public virtual onlyTimelock {\n if (newOwner == address(0)) revert ZeroTimelockAddress();\n _transferTimelockOwnership(newOwner);\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Internal function without access restriction.\n */\n function _transferTimelockOwnership(address newOwner) internal virtual {\n address oldOwner = _timelockOwner;\n _timelockOwner = newOwner;\n emit TimelockOwnershipTransferred(oldOwner, newOwner);\n }\n\n /**\n * @dev This empty reserved space is put in place to allow future versions to add new\n * variables without shifting down storage in the inheritance chain.\n * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n */\n uint256[49] private __gap;\n}\n"
|
|
},
|
|
"@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.6.0) (proxy/utils/Initializable.sol)\n\npragma solidity ^0.8.2;\n\nimport \"../../utils/AddressUpgradeable.sol\";\n\n/**\n * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed\n * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an\n * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer\n * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.\n *\n * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be\n * reused. This mechanism prevents re-execution of each \"step\" but allows the creation of new initialization steps in\n * case an upgrade adds a module that needs to be initialized.\n *\n * For example:\n *\n * [.hljs-theme-light.nopadding]\n * ```\n * contract MyToken is ERC20Upgradeable {\n * function initialize() initializer public {\n * __ERC20_init(\"MyToken\", \"MTK\");\n * }\n * }\n * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {\n * function initializeV2() reinitializer(2) public {\n * __ERC20Permit_init(\"MyToken\");\n * }\n * }\n * ```\n *\n * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as\n * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.\n *\n * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure\n * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.\n *\n * [CAUTION]\n * ====\n * Avoid leaving a contract uninitialized.\n *\n * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation\n * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke\n * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:\n *\n * [.hljs-theme-light.nopadding]\n * ```\n * /// @custom:oz-upgrades-unsafe-allow constructor\n * constructor() {\n * _disableInitializers();\n * }\n * ```\n * ====\n */\nabstract contract Initializable {\n /**\n * @dev Indicates that the contract has been initialized.\n * @custom:oz-retyped-from bool\n */\n uint8 private _initialized;\n\n /**\n * @dev Indicates that the contract is in the process of being initialized.\n */\n bool private _initializing;\n\n /**\n * @dev Triggered when the contract has been initialized or reinitialized.\n */\n event Initialized(uint8 version);\n\n /**\n * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,\n * `onlyInitializing` functions can be used to initialize parent contracts. Equivalent to `reinitializer(1)`.\n */\n modifier initializer() {\n bool isTopLevelCall = _setInitializedVersion(1);\n if (isTopLevelCall) {\n _initializing = true;\n }\n _;\n if (isTopLevelCall) {\n _initializing = false;\n emit Initialized(1);\n }\n }\n\n /**\n * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the\n * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be\n * used to initialize parent contracts.\n *\n * `initializer` is equivalent to `reinitializer(1)`, so a reinitializer may be used after the original\n * initialization step. This is essential to configure modules that are added through upgrades and that require\n * initialization.\n *\n * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in\n * a contract, executing them in the right order is up to the developer or operator.\n */\n modifier reinitializer(uint8 version) {\n bool isTopLevelCall = _setInitializedVersion(version);\n if (isTopLevelCall) {\n _initializing = true;\n }\n _;\n if (isTopLevelCall) {\n _initializing = false;\n emit Initialized(version);\n }\n }\n\n /**\n * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the\n * {initializer} and {reinitializer} modifiers, directly or indirectly.\n */\n modifier onlyInitializing() {\n require(_initializing, \"Initializable: contract is not initializing\");\n _;\n }\n\n /**\n * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.\n * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized\n * to any version. It is recommended to use this to lock implementation contracts that are designed to be called\n * through proxies.\n */\n function _disableInitializers() internal virtual {\n _setInitializedVersion(type(uint8).max);\n }\n\n function _setInitializedVersion(uint8 version) private returns (bool) {\n // If the contract is initializing we ignore whether _initialized is set in order to support multiple\n // inheritance patterns, but we only do this in the context of a constructor, and for the lowest level\n // of initializers, because in other contexts the contract may have been reentered.\n if (_initializing) {\n require(\n version == 1 && !AddressUpgradeable.isContract(address(this)),\n \"Initializable: contract is already initialized\"\n );\n return false;\n } else {\n require(_initialized < version, \"Initializable: contract is already initialized\");\n _initialized = version;\n return true;\n }\n }\n}\n"
|
|
},
|
|
"@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (security/Pausable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/ContextUpgradeable.sol\";\nimport \"../proxy/utils/Initializable.sol\";\n\n/**\n * @dev Contract module which allows children to implement an emergency stop\n * mechanism that can be triggered by an authorized account.\n *\n * This module is used through inheritance. It will make available the\n * modifiers `whenNotPaused` and `whenPaused`, which can be applied to\n * the functions of your contract. Note that they will not be pausable by\n * simply including this module, only once the modifiers are put in place.\n */\nabstract contract PausableUpgradeable is Initializable, ContextUpgradeable {\n /**\n * @dev Emitted when the pause is triggered by `account`.\n */\n event Paused(address account);\n\n /**\n * @dev Emitted when the pause is lifted by `account`.\n */\n event Unpaused(address account);\n\n bool private _paused;\n\n /**\n * @dev Initializes the contract in unpaused state.\n */\n function __Pausable_init() internal onlyInitializing {\n __Pausable_init_unchained();\n }\n\n function __Pausable_init_unchained() internal onlyInitializing {\n _paused = false;\n }\n\n /**\n * @dev Returns true if the contract is paused, and false otherwise.\n */\n function paused() public view virtual returns (bool) {\n return _paused;\n }\n\n /**\n * @dev Modifier to make a function callable only when the contract is not paused.\n *\n * Requirements:\n *\n * - The contract must not be paused.\n */\n modifier whenNotPaused() {\n require(!paused(), \"Pausable: paused\");\n _;\n }\n\n /**\n * @dev Modifier to make a function callable only when the contract is paused.\n *\n * Requirements:\n *\n * - The contract must be paused.\n */\n modifier whenPaused() {\n require(paused(), \"Pausable: not paused\");\n _;\n }\n\n /**\n * @dev Triggers stopped state.\n *\n * Requirements:\n *\n * - The contract must not be paused.\n */\n function _pause() internal virtual whenNotPaused {\n _paused = true;\n emit Paused(_msgSender());\n }\n\n /**\n * @dev Returns to normal state.\n *\n * Requirements:\n *\n * - The contract must be paused.\n */\n function _unpause() internal virtual whenPaused {\n _paused = false;\n emit Unpaused(_msgSender());\n }\n\n /**\n * @dev This empty reserved space is put in place to allow future versions to add new\n * variables without shifting down storage in the inheritance chain.\n * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n */\n uint256[49] private __gap;\n}\n"
|
|
},
|
|
"@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (access/Ownable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/ContextUpgradeable.sol\";\nimport \"../proxy/utils/Initializable.sol\";\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {\n address private _owner;\n\n event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n /**\n * @dev Initializes the contract setting the deployer as the initial owner.\n */\n function __Ownable_init() internal onlyInitializing {\n __Ownable_init_unchained();\n }\n\n function __Ownable_init_unchained() internal onlyInitializing {\n _transferOwnership(_msgSender());\n }\n\n /**\n * @dev Returns the address of the current owner.\n */\n function owner() public view virtual returns (address) {\n return _owner;\n }\n\n /**\n * @dev Throws if called by any account other than the owner.\n */\n modifier onlyOwner() {\n require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n _;\n }\n\n /**\n * @dev Leaves the contract without owner. It will not be possible to call\n * `onlyOwner` functions anymore. Can only be called by the current owner.\n *\n * NOTE: Renouncing ownership will leave the contract without an owner,\n * thereby removing any functionality that is only available to the owner.\n */\n function renounceOwnership() public virtual onlyOwner {\n _transferOwnership(address(0));\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Can only be called by the current owner.\n */\n function transferOwnership(address newOwner) public virtual onlyOwner {\n require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n _transferOwnership(newOwner);\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Internal function without access restriction.\n */\n function _transferOwnership(address newOwner) internal virtual {\n address oldOwner = _owner;\n _owner = newOwner;\n emit OwnershipTransferred(oldOwner, newOwner);\n }\n\n /**\n * @dev This empty reserved space is put in place to allow future versions to add new\n * variables without shifting down storage in the inheritance chain.\n * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n */\n uint256[49] private __gap;\n}\n"
|
|
},
|
|
"@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC20 standard as defined in the EIP.\n */\ninterface IERC20Upgradeable {\n /**\n * @dev Emitted when `value` tokens are moved from one account (`from`) to\n * another (`to`).\n *\n * Note that `value` may be zero.\n */\n event Transfer(address indexed from, address indexed to, uint256 value);\n\n /**\n * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n * a call to {approve}. `value` is the new allowance.\n */\n event Approval(address indexed owner, address indexed spender, uint256 value);\n\n /**\n * @dev Returns the amount of tokens in existence.\n */\n function totalSupply() external view returns (uint256);\n\n /**\n * @dev Returns the amount of tokens owned by `account`.\n */\n function balanceOf(address account) external view returns (uint256);\n\n /**\n * @dev Moves `amount` tokens from the caller's account to `to`.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transfer(address to, uint256 amount) external returns (bool);\n\n /**\n * @dev Returns the remaining number of tokens that `spender` will be\n * allowed to spend on behalf of `owner` through {transferFrom}. This is\n * zero by default.\n *\n * This value changes when {approve} or {transferFrom} are called.\n */\n function allowance(address owner, address spender) external view returns (uint256);\n\n /**\n * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * IMPORTANT: Beware that changing an allowance with this method brings the risk\n * that someone may use both the old and the new allowance by unfortunate\n * transaction ordering. One possible solution to mitigate this race\n * condition is to first reduce the spender's allowance to 0 and set the\n * desired value afterwards:\n * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n *\n * Emits an {Approval} event.\n */\n function approve(address spender, uint256 amount) external returns (bool);\n\n /**\n * @dev Moves `amount` tokens from `from` to `to` using the\n * allowance mechanism. `amount` is then deducted from the caller's\n * allowance.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transferFrom(\n address from,\n address to,\n uint256 amount\n ) external returns (bool);\n}\n"
|
|
},
|
|
"@uniswap/lib/contracts/libraries/TransferHelper.sol": {
|
|
"content": "pragma solidity >=0.6.0;\n\n// helper methods for interacting with ERC20 tokens and sending ETH that do not consistently return true/false\nlibrary TransferHelper {\n function safeApprove(address token, address to, uint value) internal {\n // bytes4(keccak256(bytes('approve(address,uint256)')));\n (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x095ea7b3, to, value));\n require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: APPROVE_FAILED');\n }\n\n function safeTransfer(address token, address to, uint value) internal {\n // bytes4(keccak256(bytes('transfer(address,uint256)')));\n (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0xa9059cbb, to, value));\n require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: TRANSFER_FAILED');\n }\n\n function safeTransferFrom(address token, address from, address to, uint value) internal {\n // bytes4(keccak256(bytes('transferFrom(address,address,uint256)')));\n (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x23b872dd, from, to, value));\n require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: TRANSFER_FROM_FAILED');\n }\n\n function safeTransferETH(address to, uint value) internal {\n (bool success,) = to.call{value:value}(new bytes(0));\n require(success, 'TransferHelper: ETH_TRANSFER_FAILED');\n }\n}\n"
|
|
},
|
|
"contracts/libraries/ERC20.sol": {
|
|
"content": "//SPDX-License-Identifier:MIT\npragma solidity >=0.8.0;\n\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\n\ncontract ERC20 is Context, Ownable, IERC20, IERC20Metadata {\n uint256 private constant _maxSupply = 1000000000 * 1e18; // 1B\n uint256 private constant _preMineSupply = 0;\n\n mapping(address => uint256) private _balances;\n\n mapping(address => mapping(address => uint256)) private _allowances;\n\n uint256 private _totalSupply;\n\n string private _name;\n string private _symbol;\n\n /**\n * @dev Sets the values for {name} and {symbol}, initializes {decimals} with\n * a default value of 18.\n *\n *\n * All three of these values are immutable: they can only be set once during\n * construction.\n */\n constructor(string memory tokenName, string memory tokenSymbol) {\n _name = tokenName;\n _symbol = tokenSymbol;\n\n _mint(msg.sender, _preMineSupply); // mint token to msg owner\n }\n\n /**\n * @dev Returns the bep token owner.\n */\n function getOwner() external view returns (address) {\n return owner();\n }\n\n /**\n * @dev Returns the token name.\n */\n function name() public view virtual override returns (string memory) {\n return _name;\n }\n\n /**\n * @dev Returns the token symbol.\n */\n function symbol() public view virtual override returns (string memory) {\n return _symbol;\n }\n\n /**\n * @dev Returns the number of decimals used to get its user representation.\n * For example, if `decimals` equals `2`, a balance of `505` tokens should\n * be displayed to a user as `5.05` (`505 / 10 ** 2`).\n *\n * Tokens usually opt for a value of 18, imitating the relationship between\n * Ether and Wei. This is the value {ERC20} uses, unless this function is\n * overridden;\n *\n * NOTE: This information is only used for _display_ purposes: it in\n * no way affects any of the arithmetic of the contract, including\n * {IERC20-balanceOf} and {IERC20-transfer}.\n */\n function decimals() public view virtual override returns (uint8) {\n return 18;\n }\n\n /**\n * @dev See {IERC20-totalSupply}.\n */\n function totalSupply() public view virtual override returns (uint256) {\n return _totalSupply;\n }\n\n /**\n * @dev See {IERC20-balanceOf}.\n */\n function balanceOf(address account)\n public\n view\n virtual\n override\n returns (uint256)\n {\n return _balances[account];\n }\n\n /**\n * @notice supply that was mented to the contract owner.\n */\n\n function preMineSupply() public pure returns (uint256) {\n return _preMineSupply;\n }\n\n /**\n * @notice max supply that can eer be minted.\n */\n function maxSupply() public pure returns (uint256) {\n return _maxSupply;\n }\n\n /**\n * @dev See {IERC20-transfer}.\n *\n * Requirements:\n *\n * - `recipient` cannot be the zero address.\n * - the caller must have a balance of at least `amount`.\n */\n function transfer(address recipient, uint256 amount)\n public\n virtual\n override\n returns (bool)\n {\n _transfer(_msgSender(), recipient, amount);\n return true;\n }\n\n /**\n * @dev See {IERC20-allowance}.\n */\n function allowance(address owner, address spender)\n public\n view\n virtual\n override\n returns (uint256)\n {\n return _allowances[owner][spender];\n }\n\n /**\n * @dev See {IERC20-approve}.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n */\n function approve(address spender, uint256 amount)\n public\n virtual\n override\n returns (bool)\n {\n _approve(_msgSender(), spender, amount);\n return true;\n }\n\n /**\n * @dev See {IERC20-transferFrom}.\n *\n * Emits an {Approval} event indicating the updated allowance. This is not\n * required by the EIP. See the note at the beginning of {ERC20};\n *\n * Requirements:\n * - `sender` and `recipient` cannot be the zero address.\n * - `sender` must have a balance of at least `amount`.\n * - the caller must have allowance for `sender`'s tokens of at least\n * `amount`.\n */\n function transferFrom(\n address sender,\n address recipient,\n uint256 amount\n ) public virtual override returns (bool) {\n _transfer(sender, recipient, amount);\n\n uint256 currentAllowance = _allowances[sender][_msgSender()];\n require(\n currentAllowance >= amount,\n \"ERC20: transfer amount exceeds allowance\"\n );\n unchecked {\n _approve(sender, _msgSender(), currentAllowance - amount);\n }\n return true;\n }\n\n /**\n * @dev Atomically increases the allowance granted to `spender` by the caller.\n *\n * This is an alternative to {approve} that can be used as a mitigation for\n * problems described in {ERC20-approve}.\n *\n * Emits an {Approval} event indicating the updated allowance.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n */\n function increaseAllowance(address spender, uint256 addedValue)\n public\n returns (bool)\n {\n _approve(\n _msgSender(),\n spender,\n _allowances[_msgSender()][spender] + addedValue\n );\n return true;\n }\n\n /**\n * @dev Atomically decreases the allowance granted to `spender` by the caller.\n *\n * This is an alternative to {approve} that can be used as a mitigation for\n * problems described in {ERC20-approve}.\n *\n * Emits an {Approval} event indicating the updated allowance.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n * - `spender` must have allowance for the caller of at least\n * `subtractedValue`.\n */\n function decreaseAllowance(address spender, uint256 subtractedValue)\n public\n returns (bool)\n {\n uint256 currentAllowance = _allowances[_msgSender()][spender];\n require(\n currentAllowance >= subtractedValue,\n \"ERC20: decreased allowance below zero\"\n );\n unchecked {\n _approve(_msgSender(), spender, currentAllowance - subtractedValue);\n }\n return true;\n }\n\n /**\n * @dev Moves tokens `amount` from `sender` to `recipient`.\n *\n * This is internal function is equivalent to {transfer}, and can be used to\n * e.g. implement automatic token fees, slashing mechanisms, etc.\n *\n * Emits a {Transfer} event.\n *\n * Requirements:\n *\n * - `sender` cannot be the zero address.\n * - `recipient` cannot be the zero address.\n * - `sender` must have a balance of at least `amount`.\n */\n function _transfer(\n address sender,\n address recipient,\n uint256 amount\n ) internal {\n require(sender != address(0), \"ERC20: transfer from the zero address\");\n require(recipient != address(0), \"ERC20: transfer to the zero address\");\n\n _balances[sender] -= amount;\n _balances[recipient] += amount;\n emit Transfer(sender, recipient, amount);\n }\n\n /** @dev Creates `amount` tokens and assigns them to `account`, increasing\n * the total supply.\n *\n * Emits a {Transfer} event with `from` set to the zero address.\n *\n * Requirements\n *\n * - `to` cannot be the zero address.\n */\n function _mint(address account, uint256 amount) internal virtual {\n require(account != address(0), \"ERC20: mint to the zero address\");\n if (amount + _totalSupply > _maxSupply) {\n revert();\n // return false;\n }\n\n _totalSupply += amount;\n _balances[account] += amount;\n emit Transfer(address(0), account, amount);\n }\n\n /**\n * @dev Destroys `amount` tokens from `account`, reducing the\n * total supply.\n *\n * Emits a {Transfer} event with `to` set to the zero address.\n *\n * Requirements\n *\n * - `account` cannot be the zero address.\n * - `account` must have at least `amount` tokens.\n */\n function _burn(address account, uint256 amount) internal virtual {\n require(account != address(0), \"ERC20: burn from the zero address\");\n\n _balances[account] -= amount;\n _totalSupply -= amount;\n emit Transfer(account, address(0), amount);\n }\n\n /**\n * @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.\n *\n * This is internal function is equivalent to `approve`, and can be used to\n * e.g. set automatic allowances for certain subsystems, etc.\n *\n * Emits an {Approval} event.\n *\n * Requirements:\n *\n * - `owner` cannot be the zero address.\n * - `spender` cannot be the zero address.\n */\n function _approve(\n address owner,\n address spender,\n uint256 amount\n ) internal virtual {\n require(owner != address(0), \"ERC20: approve from the zero address\");\n require(spender != address(0), \"ERC20: approve to the zero address\");\n\n _allowances[owner][spender] = amount;\n emit Approval(owner, spender, amount);\n }\n\n /**\n * @dev Destroys `amount` tokens from `account`.`amount` is then deducted\n * from the caller's allowance.\n *\n * See {_burn} and {_approve}.\n */\n function _burnFrom(address account, uint256 amount) internal virtual {\n _burn(account, amount);\n _approve(\n account,\n _msgSender(),\n _allowances[account][_msgSender()] - amount\n );\n }\n}\n"
|
|
},
|
|
"@openzeppelin/contracts/utils/structs/EnumerableSet.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.6.0) (utils/structs/EnumerableSet.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Library for managing\n * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive\n * types.\n *\n * Sets have the following properties:\n *\n * - Elements are added, removed, and checked for existence in constant time\n * (O(1)).\n * - Elements are enumerated in O(n). No guarantees are made on the ordering.\n *\n * ```\n * contract Example {\n * // Add the library methods\n * using EnumerableSet for EnumerableSet.AddressSet;\n *\n * // Declare a set state variable\n * EnumerableSet.AddressSet private mySet;\n * }\n * ```\n *\n * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)\n * and `uint256` (`UintSet`) are supported.\n */\nlibrary EnumerableSet {\n // To implement this library for multiple types with as little code\n // repetition as possible, we write it in terms of a generic Set type with\n // bytes32 values.\n // The Set implementation uses private functions, and user-facing\n // implementations (such as AddressSet) are just wrappers around the\n // underlying Set.\n // This means that we can only create new EnumerableSets for types that fit\n // in bytes32.\n\n struct Set {\n // Storage of set values\n bytes32[] _values;\n // Position of the value in the `values` array, plus 1 because index 0\n // means a value is not in the set.\n mapping(bytes32 => uint256) _indexes;\n }\n\n /**\n * @dev Add a value to a set. O(1).\n *\n * Returns true if the value was added to the set, that is if it was not\n * already present.\n */\n function _add(Set storage set, bytes32 value) private returns (bool) {\n if (!_contains(set, value)) {\n set._values.push(value);\n // The value is stored at length-1, but we add 1 to all indexes\n // and use 0 as a sentinel value\n set._indexes[value] = set._values.length;\n return true;\n } else {\n return false;\n }\n }\n\n /**\n * @dev Removes a value from a set. O(1).\n *\n * Returns true if the value was removed from the set, that is if it was\n * present.\n */\n function _remove(Set storage set, bytes32 value) private returns (bool) {\n // We read and store the value's index to prevent multiple reads from the same storage slot\n uint256 valueIndex = set._indexes[value];\n\n if (valueIndex != 0) {\n // Equivalent to contains(set, value)\n // To delete an element from the _values array in O(1), we swap the element to delete with the last one in\n // the array, and then remove the last element (sometimes called as 'swap and pop').\n // This modifies the order of the array, as noted in {at}.\n\n uint256 toDeleteIndex = valueIndex - 1;\n uint256 lastIndex = set._values.length - 1;\n\n if (lastIndex != toDeleteIndex) {\n bytes32 lastValue = set._values[lastIndex];\n\n // Move the last value to the index where the value to delete is\n set._values[toDeleteIndex] = lastValue;\n // Update the index for the moved value\n set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex\n }\n\n // Delete the slot where the moved value was stored\n set._values.pop();\n\n // Delete the index for the deleted slot\n delete set._indexes[value];\n\n return true;\n } else {\n return false;\n }\n }\n\n /**\n * @dev Returns true if the value is in the set. O(1).\n */\n function _contains(Set storage set, bytes32 value) private view returns (bool) {\n return set._indexes[value] != 0;\n }\n\n /**\n * @dev Returns the number of values on the set. O(1).\n */\n function _length(Set storage set) private view returns (uint256) {\n return set._values.length;\n }\n\n /**\n * @dev Returns the value stored at position `index` in the set. O(1).\n *\n * Note that there are no guarantees on the ordering of values inside the\n * array, and it may change when more values are added or removed.\n *\n * Requirements:\n *\n * - `index` must be strictly less than {length}.\n */\n function _at(Set storage set, uint256 index) private view returns (bytes32) {\n return set._values[index];\n }\n\n /**\n * @dev Return the entire set in an array\n *\n * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed\n * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that\n * this function has an unbounded cost, and using it as part of a state-changing function may render the function\n * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.\n */\n function _values(Set storage set) private view returns (bytes32[] memory) {\n return set._values;\n }\n\n // Bytes32Set\n\n struct Bytes32Set {\n Set _inner;\n }\n\n /**\n * @dev Add a value to a set. O(1).\n *\n * Returns true if the value was added to the set, that is if it was not\n * already present.\n */\n function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {\n return _add(set._inner, value);\n }\n\n /**\n * @dev Removes a value from a set. O(1).\n *\n * Returns true if the value was removed from the set, that is if it was\n * present.\n */\n function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {\n return _remove(set._inner, value);\n }\n\n /**\n * @dev Returns true if the value is in the set. O(1).\n */\n function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {\n return _contains(set._inner, value);\n }\n\n /**\n * @dev Returns the number of values in the set. O(1).\n */\n function length(Bytes32Set storage set) internal view returns (uint256) {\n return _length(set._inner);\n }\n\n /**\n * @dev Returns the value stored at position `index` in the set. O(1).\n *\n * Note that there are no guarantees on the ordering of values inside the\n * array, and it may change when more values are added or removed.\n *\n * Requirements:\n *\n * - `index` must be strictly less than {length}.\n */\n function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {\n return _at(set._inner, index);\n }\n\n /**\n * @dev Return the entire set in an array\n *\n * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed\n * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that\n * this function has an unbounded cost, and using it as part of a state-changing function may render the function\n * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.\n */\n function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {\n return _values(set._inner);\n }\n\n // AddressSet\n\n struct AddressSet {\n Set _inner;\n }\n\n /**\n * @dev Add a value to a set. O(1).\n *\n * Returns true if the value was added to the set, that is if it was not\n * already present.\n */\n function add(AddressSet storage set, address value) internal returns (bool) {\n return _add(set._inner, bytes32(uint256(uint160(value))));\n }\n\n /**\n * @dev Removes a value from a set. O(1).\n *\n * Returns true if the value was removed from the set, that is if it was\n * present.\n */\n function remove(AddressSet storage set, address value) internal returns (bool) {\n return _remove(set._inner, bytes32(uint256(uint160(value))));\n }\n\n /**\n * @dev Returns true if the value is in the set. O(1).\n */\n function contains(AddressSet storage set, address value) internal view returns (bool) {\n return _contains(set._inner, bytes32(uint256(uint160(value))));\n }\n\n /**\n * @dev Returns the number of values in the set. O(1).\n */\n function length(AddressSet storage set) internal view returns (uint256) {\n return _length(set._inner);\n }\n\n /**\n * @dev Returns the value stored at position `index` in the set. O(1).\n *\n * Note that there are no guarantees on the ordering of values inside the\n * array, and it may change when more values are added or removed.\n *\n * Requirements:\n *\n * - `index` must be strictly less than {length}.\n */\n function at(AddressSet storage set, uint256 index) internal view returns (address) {\n return address(uint160(uint256(_at(set._inner, index))));\n }\n\n /**\n * @dev Return the entire set in an array\n *\n * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed\n * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that\n * this function has an unbounded cost, and using it as part of a state-changing function may render the function\n * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.\n */\n function values(AddressSet storage set) internal view returns (address[] memory) {\n bytes32[] memory store = _values(set._inner);\n address[] memory result;\n\n assembly {\n result := store\n }\n\n return result;\n }\n\n // UintSet\n\n struct UintSet {\n Set _inner;\n }\n\n /**\n * @dev Add a value to a set. O(1).\n *\n * Returns true if the value was added to the set, that is if it was not\n * already present.\n */\n function add(UintSet storage set, uint256 value) internal returns (bool) {\n return _add(set._inner, bytes32(value));\n }\n\n /**\n * @dev Removes a value from a set. O(1).\n *\n * Returns true if the value was removed from the set, that is if it was\n * present.\n */\n function remove(UintSet storage set, uint256 value) internal returns (bool) {\n return _remove(set._inner, bytes32(value));\n }\n\n /**\n * @dev Returns true if the value is in the set. O(1).\n */\n function contains(UintSet storage set, uint256 value) internal view returns (bool) {\n return _contains(set._inner, bytes32(value));\n }\n\n /**\n * @dev Returns the number of values on the set. O(1).\n */\n function length(UintSet storage set) internal view returns (uint256) {\n return _length(set._inner);\n }\n\n /**\n * @dev Returns the value stored at position `index` in the set. O(1).\n *\n * Note that there are no guarantees on the ordering of values inside the\n * array, and it may change when more values are added or removed.\n *\n * Requirements:\n *\n * - `index` must be strictly less than {length}.\n */\n function at(UintSet storage set, uint256 index) internal view returns (uint256) {\n return uint256(_at(set._inner, index));\n }\n\n /**\n * @dev Return the entire set in an array\n *\n * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed\n * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that\n * this function has an unbounded cost, and using it as part of a state-changing function may render the function\n * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.\n */\n function values(UintSet storage set) internal view returns (uint256[] memory) {\n bytes32[] memory store = _values(set._inner);\n uint256[] memory result;\n\n assembly {\n result := store\n }\n\n return result;\n }\n}\n"
|
|
},
|
|
"@openzeppelin/contracts/access/Ownable.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (access/Ownable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/Context.sol\";\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract Ownable is Context {\n address private _owner;\n\n event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n /**\n * @dev Initializes the contract setting the deployer as the initial owner.\n */\n constructor() {\n _transferOwnership(_msgSender());\n }\n\n /**\n * @dev Returns the address of the current owner.\n */\n function owner() public view virtual returns (address) {\n return _owner;\n }\n\n /**\n * @dev Throws if called by any account other than the owner.\n */\n modifier onlyOwner() {\n require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n _;\n }\n\n /**\n * @dev Leaves the contract without owner. It will not be possible to call\n * `onlyOwner` functions anymore. Can only be called by the current owner.\n *\n * NOTE: Renouncing ownership will leave the contract without an owner,\n * thereby removing any functionality that is only available to the owner.\n */\n function renounceOwnership() public virtual onlyOwner {\n _transferOwnership(address(0));\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Can only be called by the current owner.\n */\n function transferOwnership(address newOwner) public virtual onlyOwner {\n require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n _transferOwnership(newOwner);\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Internal function without access restriction.\n */\n function _transferOwnership(address newOwner) internal virtual {\n address oldOwner = _owner;\n _owner = newOwner;\n emit OwnershipTransferred(oldOwner, newOwner);\n }\n}\n"
|
|
},
|
|
"@openzeppelin/contracts/token/ERC20/IERC20.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC20 standard as defined in the EIP.\n */\ninterface IERC20 {\n /**\n * @dev Emitted when `value` tokens are moved from one account (`from`) to\n * another (`to`).\n *\n * Note that `value` may be zero.\n */\n event Transfer(address indexed from, address indexed to, uint256 value);\n\n /**\n * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n * a call to {approve}. `value` is the new allowance.\n */\n event Approval(address indexed owner, address indexed spender, uint256 value);\n\n /**\n * @dev Returns the amount of tokens in existence.\n */\n function totalSupply() external view returns (uint256);\n\n /**\n * @dev Returns the amount of tokens owned by `account`.\n */\n function balanceOf(address account) external view returns (uint256);\n\n /**\n * @dev Moves `amount` tokens from the caller's account to `to`.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transfer(address to, uint256 amount) external returns (bool);\n\n /**\n * @dev Returns the remaining number of tokens that `spender` will be\n * allowed to spend on behalf of `owner` through {transferFrom}. This is\n * zero by default.\n *\n * This value changes when {approve} or {transferFrom} are called.\n */\n function allowance(address owner, address spender) external view returns (uint256);\n\n /**\n * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * IMPORTANT: Beware that changing an allowance with this method brings the risk\n * that someone may use both the old and the new allowance by unfortunate\n * transaction ordering. One possible solution to mitigate this race\n * condition is to first reduce the spender's allowance to 0 and set the\n * desired value afterwards:\n * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n *\n * Emits an {Approval} event.\n */\n function approve(address spender, uint256 amount) external returns (bool);\n\n /**\n * @dev Moves `amount` tokens from `from` to `to` using the\n * allowance mechanism. `amount` is then deducted from the caller's\n * allowance.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transferFrom(\n address from,\n address to,\n uint256 amount\n ) external returns (bool);\n}\n"
|
|
},
|
|
"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../IERC20.sol\";\n\n/**\n * @dev Interface for the optional metadata functions from the ERC20 standard.\n *\n * _Available since v4.1._\n */\ninterface IERC20Metadata is IERC20 {\n /**\n * @dev Returns the name of the token.\n */\n function name() external view returns (string memory);\n\n /**\n * @dev Returns the symbol of the token.\n */\n function symbol() external view returns (string memory);\n\n /**\n * @dev Returns the decimals places of the token.\n */\n function decimals() external view returns (uint8);\n}\n"
|
|
},
|
|
"@openzeppelin/contracts/utils/Context.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract Context {\n function _msgSender() internal view virtual returns (address) {\n return msg.sender;\n }\n\n function _msgData() internal view virtual returns (bytes calldata) {\n return msg.data;\n }\n}\n"
|
|
},
|
|
"contracts/interfaces/IHelixToken.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\npragma solidity >= 0.8.0;\n\ninterface IHelixToken {\n function mint(address to, uint256 amount) external returns(bool);\n function transfer(address recipient, uint256 amount) external returns(bool);\n function balanceOf(address account) external view returns (uint256);\n}\n"
|
|
},
|
|
"@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\npragma solidity ^0.8.0;\nimport \"../proxy/utils/Initializable.sol\";\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract ContextUpgradeable is Initializable {\n function __Context_init() internal onlyInitializing {\n }\n\n function __Context_init_unchained() internal onlyInitializing {\n }\n function _msgSender() internal view virtual returns (address) {\n return msg.sender;\n }\n\n function _msgData() internal view virtual returns (bytes calldata) {\n return msg.data;\n }\n\n /**\n * @dev This empty reserved space is put in place to allow future versions to add new\n * variables without shifting down storage in the inheritance chain.\n * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n */\n uint256[50] private __gap;\n}\n"
|
|
},
|
|
"@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.5.0) (utils/Address.sol)\n\npragma solidity ^0.8.1;\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary AddressUpgradeable {\n /**\n * @dev Returns true if `account` is a contract.\n *\n * [IMPORTANT]\n * ====\n * It is unsafe to assume that an address for which this function returns\n * false is an externally-owned account (EOA) and not a contract.\n *\n * Among others, `isContract` will return false for the following\n * types of addresses:\n *\n * - an externally-owned account\n * - a contract in construction\n * - an address where a contract will be created\n * - an address where a contract lived, but was destroyed\n * ====\n *\n * [IMPORTANT]\n * ====\n * You shouldn't rely on `isContract` to protect against flash loan attacks!\n *\n * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n * constructor.\n * ====\n */\n function isContract(address account) internal view returns (bool) {\n // This method relies on extcodesize/address.code.length, which returns 0\n // for contracts in construction, since the code is only stored at the end\n // of the constructor execution.\n\n return account.code.length > 0;\n }\n\n /**\n * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n * `recipient`, forwarding all available gas and reverting on errors.\n *\n * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n * of certain opcodes, possibly making contracts go over the 2300 gas limit\n * imposed by `transfer`, making them unable to receive funds via\n * `transfer`. {sendValue} removes this limitation.\n *\n * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n *\n * IMPORTANT: because control is transferred to `recipient`, care must be\n * taken to not create reentrancy vulnerabilities. Consider using\n * {ReentrancyGuard} or the\n * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n */\n function sendValue(address payable recipient, uint256 amount) internal {\n require(address(this).balance >= amount, \"Address: insufficient balance\");\n\n (bool success, ) = recipient.call{value: amount}(\"\");\n require(success, \"Address: unable to send value, recipient may have reverted\");\n }\n\n /**\n * @dev Performs a Solidity function call using a low level `call`. A\n * plain `call` is an unsafe replacement for a function call: use this\n * function instead.\n *\n * If `target` reverts with a revert reason, it is bubbled up by this\n * function (like regular Solidity function calls).\n *\n * Returns the raw returned data. To convert to the expected return value,\n * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n *\n * Requirements:\n *\n * - `target` must be a contract.\n * - calling `target` with `data` must not revert.\n *\n * _Available since v3.1._\n */\n function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionCall(target, data, \"Address: low-level call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n * `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal returns (bytes memory) {\n return functionCallWithValue(target, data, 0, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but also transferring `value` wei to `target`.\n *\n * Requirements:\n *\n * - the calling contract must have an ETH balance of at least `value`.\n * - the called Solidity function must be `payable`.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(\n address target,\n bytes memory data,\n uint256 value\n ) internal returns (bytes memory) {\n return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n * with `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(\n address target,\n bytes memory data,\n uint256 value,\n string memory errorMessage\n ) internal returns (bytes memory) {\n require(address(this).balance >= value, \"Address: insufficient balance for call\");\n require(isContract(target), \"Address: call to non-contract\");\n\n (bool success, bytes memory returndata) = target.call{value: value}(data);\n return verifyCallResult(success, returndata, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n return functionStaticCall(target, data, \"Address: low-level static call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal view returns (bytes memory) {\n require(isContract(target), \"Address: static call to non-contract\");\n\n (bool success, bytes memory returndata) = target.staticcall(data);\n return verifyCallResult(success, returndata, errorMessage);\n }\n\n /**\n * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the\n * revert reason using the provided one.\n *\n * _Available since v4.3._\n */\n function verifyCallResult(\n bool success,\n bytes memory returndata,\n string memory errorMessage\n ) internal pure returns (bytes memory) {\n if (success) {\n return returndata;\n } else {\n // Look for revert reason and bubble it up if present\n if (returndata.length > 0) {\n // The easiest way to bubble the revert reason is using memory via assembly\n\n assembly {\n let returndata_size := mload(returndata)\n revert(add(32, returndata), returndata_size)\n }\n } else {\n revert(errorMessage);\n }\n }\n }\n}\n"
|
|
}
|
|
},
|
|
"settings": {
|
|
"optimizer": {
|
|
"enabled": true,
|
|
"runs": 200
|
|
},
|
|
"outputSelection": {
|
|
"*": {
|
|
"*": [
|
|
"evm.bytecode",
|
|
"evm.deployedBytecode",
|
|
"devdoc",
|
|
"userdoc",
|
|
"metadata",
|
|
"abi"
|
|
]
|
|
}
|
|
},
|
|
"libraries": {}
|
|
}
|
|
} |