Contract Overview
Balance:
0 ETH
ETH Value:
$0.00
My Name Tag:
Not Available
Txn Hash | Method |
Block
|
From
|
To
|
Value | [Txn Fee] | |||
---|---|---|---|---|---|---|---|---|---|
0x539bc4b4212f695d6763604c602b95ffc34cc02f92552309908790762dda8dc7 | 0x60806040 | 20743718 | 171 days 9 hrs ago | 0xb02ce74cf2eb42c5f3bc54074127322b77c29cdd | IN | Create: AtlasMineStakerUpgradeable | 0 ETH | 0.009639108594 ETH |
[ Download CSV Export ]
Latest 25 internal transaction
[ Download CSV Export ]
Contract Name:
AtlasMineStakerUpgradeable
Compiler Version
v0.8.11+commit.d7f03943
Optimization Enabled:
Yes with 200 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT pragma solidity ^0.8.10; import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol"; import "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol"; import "@openzeppelin/contracts-upgradeable/token/ERC1155/IERC1155Upgradeable.sol"; import "@openzeppelin/contracts-upgradeable/token/ERC1155/utils/ERC1155HolderUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/token/ERC721/IERC721Upgradeable.sol"; import "@openzeppelin/contracts-upgradeable/token/ERC721/utils/ERC721HolderUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; import "@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/utils/math/SafeCastUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/utils/structs/EnumerableSetUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; import "treasure-staking/contracts/AtlasMine.sol"; import "./interfaces/IAtlasMineStaker.sol"; /** * @title AtlasMineStaker * @author kvk0x * * Dragon of the Magic Dragon DAO - A Tempting Offer. * * Staking pool contract for the Bridgeworld Atlas Mine. * Wraps existing staking with a defined 'lock time' per contract. * * Better than solo staking since a designated 'hoard' can also * deposit Treasures and Legions for staking boosts. Anyone can * enjoy the power of the guild's hoard and maximize their * Atlas Mine yield. * */ contract AtlasMineStakerUpgradeable is IAtlasMineStaker, Initializable, OwnableUpgradeable, ERC1155HolderUpgradeable, ERC721HolderUpgradeable, ReentrancyGuardUpgradeable { using SafeERC20Upgradeable for IERC20Upgradeable; using AddressUpgradeable for address; using SafeCastUpgradeable for uint256; using SafeCastUpgradeable for int256; using EnumerableSetUpgradeable for EnumerableSetUpgradeable.UintSet; // ============================================ STATE ============================================== // ============= Global Immutable State ============== /// @notice MAGIC token /// @dev functionally immutable IERC20Upgradeable public magic; /// @notice The AtlasMine /// @dev functionally immutable AtlasMine public mine; /// @notice The defined lock cycle for the contract /// @dev functionally immutable AtlasMine.Lock public lock; /// @notice The defined lock time for the contract /// @dev functionally immutable uint256 public locktime; // ============= Global Staking State ============== uint256 public constant ONE = 1e30; /// @notice Whether new stakes will get staked on the contract as scheduled. For emergencies bool public schedulePaused; /// @notice Deposited, but unstaked tokens, keyed by the day number since epoch /// @notice DEPRECATED ON UPGRADE mapping(uint256 => uint256) public pendingStakes; /// @notice Last time pending stakes were deposited uint256 public lastStakeTimestamp; /// @notice The minimum amount of time between atlas mine stakes uint256 public minimumStakingWait; /// @notice The total amount of staked token uint256 public totalStaked; /// @notice All stakes currently active Stake[] public stakes; /// @notice Deposit ID of last stake. Also tracked in atlas mine uint256 public lastDepositId; /// @notice Total MAGIC rewards earned by staking. uint256 public override totalRewardsEarned; /// @notice Rewards accumulated per share uint256 public accRewardsPerShare; // ============= User Staking State ============== /// @notice Each user stake, keyed by user address => deposit ID mapping(address => mapping(uint256 => UserStake)) public userStake; /// @notice All deposit IDs for a user, enumerated mapping(address => EnumerableSetUpgradeable.UintSet) private allUserDepositIds; /// @notice The current ID of the user's last deposited stake mapping(address => uint256) public currentId; // ============= NFT Boosting State ============== /// @notice Holder of treasures and legions mapping(address => bool) private hoards; /// @notice Legions staked by hoard users mapping(uint256 => address) public legionsStaked; /// @notice Treasures staked by hoard users mapping(uint256 => mapping(address => uint256)) public treasuresStaked; // ============= Operator State ============== /// @notice Fee to contract operator. Only assessed on rewards. uint256 public fee; /// @notice Amount of fees reserved for withdrawal by the operator. uint256 public feeReserve; /// @notice Max fee the owner can ever take - 30% uint256 public constant MAX_FEE = 30_00; uint256 public constant FEE_DENOMINATOR = 10_000; // =========================================== // ============== Post Upgrade =============== // =========================================== /// @notice deposited but unstaked uint256 public unstakedDeposits; /// @notice Intra-tx buffer for pending payouts uint256 public tokenBuffer; /// @notice Whether the deposit accounting reset has been called (upgrade #2) bool private _resetCalled; /// @notice The next stake index with an active deposit uint256 public nextActiveStake; /// @notice The defined accrual windows in terms of UTC hours. /// Must be an even-length array of increasing order uint256[] public accrualWindows; /// @notice Whether the accRewardsPerShare reset has been called (upgrade #3) bool private _rewardsResetCalled; /// @notice Whether the accRewardsPerShare reset has been called (upgrade #3) uint256 private accrueIncentiveBps; // ========================================== INITIALIZER =========================================== /** * @dev Prevents malicious initializations of base implementation by * setting contract to initialized on deployment. */ /// @custom:oz-upgrades-unsafe-allow constructor constructor() initializer {} /** * @param _magic The MAGIC token address. * @param _mine The AtlasMine contract. * @param _lock The locking strategy of the staking pool. * Maps to a timelock for AtlasMine deposits. */ function initialize( IERC20Upgradeable _magic, AtlasMine _mine, AtlasMine.Lock _lock ) external initializer { require(address(_magic) != address(0), "Invalid magic token address"); require(address(_mine) != address(0), "Invalid mine contract address"); __ERC1155Holder_init(); __ERC721Holder_init(); __Ownable_init(); __ReentrancyGuard_init(); magic = _magic; mine = _mine; /// @notice each staker cycles its locks for a predefined amount. New /// lock cycle, new contract. lock = _lock; (, uint256 _locktime) = mine.getLockBoost(lock); locktime = _locktime; lastStakeTimestamp = block.timestamp; minimumStakingWait = 12 hours; // Approve the mine magic.approve(address(mine), type(uint256).max); _approveNFTs(); } // ======================================== USER OPERATIONS ======================================== /** * @notice Make a new deposit into the Staker. The Staker will collect * the tokens, to be later staked in atlas mine by the owner, * according to the stake/unlock schedule. * @dev Specified amount of token must be approved by the caller. * * @param _amount The amount of tokens to deposit. */ function deposit(uint256 _amount) public virtual override nonReentrant whenNotAccruing { require(!schedulePaused, "new staking paused"); require(_amount > 0, "Deposit amount 0"); // Add user stake uint256 newDepositId = ++currentId[msg.sender]; allUserDepositIds[msg.sender].add(newDepositId); UserStake storage s = userStake[msg.sender][newDepositId]; s.amount = _amount; s.unlockAt = block.timestamp + locktime + 1 days; s.rewardDebt = _accumulatedRewards(s.amount); // Update global accounting totalStaked += _amount; unstakedDeposits += _amount; // Collect tokens magic.safeTransferFrom(msg.sender, address(this), _amount); // MAGIC tokens sit in contract. Added to pending stakes emit UserDeposit(msg.sender, _amount); } /** * @notice Withdraw a deposit from the Staker contract. Calculates * pro rata share of accumulated MAGIC and distributes any * earned rewards in addition to original deposit. * There must be enough unlocked tokens to withdraw. * * @param depositId The ID of the deposit to withdraw from. * @param _amount The amount to withdraw. * */ function withdraw(uint256 depositId, uint256 _amount) public virtual override nonReentrant whenNotAccruing { UserStake storage s = userStake[msg.sender][depositId]; require(s.amount > 0, "No deposit"); require(block.timestamp >= s.unlockAt, "Deposit locked"); magic.safeTransfer(msg.sender, _withdraw(s, depositId, _amount)); } /** * @notice Withdraw all eligible deposits from the staker contract. * Will skip any deposits not yet unlocked. Will also * distribute rewards for all stakes via 'withdraw'. * */ function withdrawAll() public virtual nonReentrant whenNotAccruing usesBuffer { uint256[] memory depositIds = allUserDepositIds[msg.sender].values(); uint256 numDeposits = depositIds.length; for (uint256 i = 0; i < numDeposits; i++) { UserStake storage s = userStake[msg.sender][depositIds[i]]; if (s.amount > 0 && s.unlockAt > 0 && s.unlockAt <= block.timestamp) { tokenBuffer += _withdraw(s, depositIds[i], type(uint256).max); } } uint256 payout = tokenBuffer; tokenBuffer = 0; magic.safeTransfer(msg.sender, payout); } /** * @dev Logic for withdrawing a deposit. Calculates pro rata share of * accumulated MAGIC and distributes any earned rewards in addition * to original deposit. * * @dev An _amount argument larger than the total deposit amount will * withdraw the entire deposit. * * @param s The UserStake struct to withdraw from. * @param depositId The ID of the deposit to withdraw from (for event). * @param _amount The amount to withdraw. */ function _withdraw( UserStake storage s, uint256 depositId, uint256 _amount ) internal returns (uint256 payout) { require(_amount > 0, "Withdraw amount 0"); if (_amount > s.amount) { _amount = s.amount; } // Update user accounting int256 accumulatedRewards = _accumulatedRewards(s.amount); uint256 reward; if (s.rewardDebt < accumulatedRewards) { // Reduce by 1 wei to work around off-by-one error in atlas mine reward = (accumulatedRewards - s.rewardDebt - 1).toUint256(); } payout = _amount + reward; s.amount -= _amount; s.rewardDebt = _accumulatedRewards(s.amount); // Update global accounting totalStaked -= _amount; // If we need to unstake, unstake until we have enough uint256 totalUsableMagic = _totalUsableMagic(); if (payout > totalUsableMagic) { _unstakeToTarget(payout - totalUsableMagic); } // Decrement unstakedDeposits based on how much we are withdrawing // If we are withdrawing more than is currently unstaked, set it to 0 if (_amount >= unstakedDeposits) { unstakedDeposits = 0; } else { unstakedDeposits -= _amount; } emit UserWithdraw(msg.sender, depositId, _amount, reward); } /** * @notice Claim rewards, unstaking if necessary. Will fail if there * are not enough tokens in the contract to claim rewards. * @dev Reverts if deposit amount is 0, since rewards are auto-harvested * on withdrawal, there should be no unclaimed rewards on fully * withdrawn deposits. * * @param depositId The ID of the deposit to claim rewards from. * */ function claim(uint256 depositId) public virtual override nonReentrant whenNotAccruing { UserStake storage s = userStake[msg.sender][depositId]; require(s.amount > 0, "No deposit"); magic.safeTransfer(msg.sender, _claim(s, depositId)); } /** * @notice Claim all possible rewards from the staker contract. * Will apply to both locked and unlocked deposits. * */ function claimAll() public virtual nonReentrant usesBuffer whenNotAccruing { uint256[] memory depositIds = allUserDepositIds[msg.sender].values(); uint256 numDeposits = depositIds.length; for (uint256 i = 0; i < numDeposits; i++) { UserStake storage s = userStake[msg.sender][depositIds[i]]; if (s.amount > 0) { tokenBuffer += _claim(s, depositIds[i]); } } uint256 reward = tokenBuffer; tokenBuffer = 0; magic.safeTransfer(msg.sender, reward); } /** * @dev Logic for claiming rewards on a deposit. Calculates pro rata share of * accumulated MAGIC and distributed any earned rewards in addition * to original deposit. * * @param s The UserStake struct to claim from. * @param depositId The ID of the deposit to claim from (for event). */ function _claim(UserStake storage s, uint256 depositId) internal returns (uint256 reward) { // Update accounting int256 accumulatedRewards = _accumulatedRewards(s.amount); if (s.rewardDebt < accumulatedRewards) { // Reduce by 1 wei to work around off-by-one error in atlas mine reward = (accumulatedRewards - s.rewardDebt - 1).toUint256(); } s.rewardDebt = accumulatedRewards; // Unstake if we need to to ensure we can withdraw uint256 totalUsableMagic = _totalUsableMagic(); if (reward > totalUsableMagic) { _unstakeToTarget(reward - totalUsableMagic); } require(reward <= _totalUsableMagic(), "Not enough rewards to claim"); emit UserClaim(msg.sender, depositId, reward); } /** * @notice Works similarly to withdraw, but does not attempt to claim rewards. * Used in case there is an issue with rewards calculation either here or * in the Atlas Mine. emergencyUnstakeAllFromMine should be called before this, * since it does not attempt to unstake. * */ function withdrawEmergency() public virtual override nonReentrant { require(schedulePaused, "Not in emergency state"); uint256 totalStake; uint256[] memory depositIds = allUserDepositIds[msg.sender].values(); uint256 numDeposits = depositIds.length; for (uint256 i = 0; i < numDeposits; i++) { UserStake storage s = userStake[msg.sender][depositIds[i]]; totalStake += s.amount; s.amount = 0; } require(totalStake <= _totalUsableMagic(), "Not enough unstaked"); totalStaked -= totalStake; magic.safeTransfer(msg.sender, totalStake); emit UserWithdraw(msg.sender, 0, totalStake, 0); } /** * @notice Stake any pending stakes before the current day. Callable * by anybody. Any pending stakes will unlock according * to the time this method is called, and the contract's defined * lock time. */ function stakeScheduled() public virtual override { require(!schedulePaused, "new staking paused"); require(block.timestamp - lastStakeTimestamp >= minimumStakingWait, "not enough time since last stake"); lastStakeTimestamp = block.timestamp; uint256 unlockAt = block.timestamp + locktime; uint256 amountToStake = unstakedDeposits; unstakedDeposits = 0; _stakeInMine(amountToStake); emit MineStake(amountToStake, unlockAt); } /** * @notice Harvest rewards for a subset of deposit IDs, and accrue harvested * rewards to users. The contract keeps track of the offset to ensure * that only chunk size needs to be specified and rewards are not redundantly * harvested during the same accrual period. * * @param depositIds The deposit IDs to harvest rewards from. */ function accrue(uint256[] calldata depositIds) public virtual override whenAccruing { require(depositIds.length != 0, "Must accrue nonzero deposits"); uint256 accrueIncentive = _updateRewards(depositIds); if (accrueIncentive > 0) { magic.transfer(msg.sender, accrueIncentive); } } // ======================================= HOARD OPERATIONS ======================================== /** * @notice Stake a Treasure owned by the hoard into the Atlas Mine. * Staked treasures will boost all user deposits. * @dev Any treasure must be approved for withdrawal by the caller. * * @param _tokenId The tokenId of the specified treasure. * @param _amount The amount of treasures to stake. */ function stakeTreasure(uint256 _tokenId, uint256 _amount) external override onlyHoard { address treasureAddr = mine.treasure(); require(IERC1155Upgradeable(treasureAddr).balanceOf(msg.sender, _tokenId) >= _amount, "Not enough treasures"); treasuresStaked[_tokenId][msg.sender] += _amount; // First withdraw and approve IERC1155Upgradeable(treasureAddr).safeTransferFrom(msg.sender, address(this), _tokenId, _amount, bytes("")); mine.stakeTreasure(_tokenId, _amount); uint256 boost = mine.boosts(address(this)); emit StakeNFT(msg.sender, treasureAddr, _tokenId, _amount, boost); } /** * @notice Unstake a Treasure from the Atlas Mine and return it to the hoard. * * @param _tokenId The tokenId of the specified treasure. * @param _amount The amount of treasures to stake. */ function unstakeTreasure(uint256 _tokenId, uint256 _amount) external override onlyHoard { require(treasuresStaked[_tokenId][msg.sender] >= _amount, "Not enough treasures"); treasuresStaked[_tokenId][msg.sender] -= _amount; address treasureAddr = mine.treasure(); mine.unstakeTreasure(_tokenId, _amount); uint256 boost = mine.boosts(address(this)); // Distribute to hoard IERC1155Upgradeable(treasureAddr).safeTransferFrom(address(this), msg.sender, _tokenId, _amount, bytes("")); emit UnstakeNFT(msg.sender, treasureAddr, _tokenId, _amount, boost); } /** * @notice Stake a Legion owned by the hoard into the Atlas Mine. * Staked legions will boost all user deposits. * @dev Any legion be approved for withdrawal by the caller. * * @param _tokenId The tokenId of the specified legion. */ function stakeLegion(uint256 _tokenId) external override onlyHoard { address legionAddr = mine.legion(); require(IERC721Upgradeable(legionAddr).ownerOf(_tokenId) == msg.sender, "Not owner of legion"); legionsStaked[_tokenId] = msg.sender; IERC721Upgradeable(legionAddr).safeTransferFrom(msg.sender, address(this), _tokenId); mine.stakeLegion(_tokenId); uint256 boost = mine.boosts(address(this)); emit StakeNFT(msg.sender, legionAddr, _tokenId, 1, boost); } /** * @notice Unstake a Legion from the Atlas Mine and return it to the hoard. * * @param _tokenId The tokenId of the specified legion. */ function unstakeLegion(uint256 _tokenId) external override onlyHoard { require(legionsStaked[_tokenId] == msg.sender, "Not staker of legion"); address legionAddr = mine.legion(); delete legionsStaked[_tokenId]; mine.unstakeLegion(_tokenId); uint256 boost = mine.boosts(address(this)); // Distribute to hoard IERC721Upgradeable(legionAddr).safeTransferFrom(address(this), msg.sender, _tokenId); emit UnstakeNFT(msg.sender, legionAddr, _tokenId, 1, boost); } // ======================================= OWNER OPERATIONS ======================================= /** * @notice Unstake everything eligible for unstaking from Atlas Mine. * Callable by owner. Should only be used in case of emergency * or migration to a new contract, or if there is a need to service * an unexpectedly large amount of withdrawals. * * If unlockAll is set to true in the Atlas Mine, this can withdraw * all stake. */ function unstakeAllFromMine() external override onlyOwner { uint256 totalStakes = stakes.length; for (uint256 i = nextActiveStake; i < totalStakes; i++) { Stake memory s = stakes[i]; if (s.unlockAt > block.timestamp) { // This stake is not unlocked - stop looking break; } // Withdraw position (does not harvest) mine.withdrawPosition(s.depositId, s.amount); } // Only check for removal after, so we don't mutate while looping _removeZeroStakes(); } /** * @notice Let owner unstake a specified amount as needed to make sure the contract is funded. * Can be used to facilitate expected future withdrawals. * * @param target The amount of tokens to reclaim from the mine. */ function unstakeToTarget(uint256 target) external override onlyOwner { _unstakeToTarget(target); } /** * @notice Works similarly to unstakeAllFromMine, but does not harvest * rewards. Used for getting out original stake emergencies. * Requires emergency flag - schedulePaused to be set. Does NOT * take a fee on rewards. * * Requires that everything gets withdrawn to make sure it is only * used in emergency. If not the case, reverts. */ function emergencyUnstakeAllFromMine() external override onlyOwner { require(schedulePaused, "Not in emergency state"); // Unstake everything eligible mine.withdrawAll(); _removeZeroStakes(); } /** * @notice Change the fee taken by the operator. Can never be more than * MAX_FEE. Fees only assessed on rewards. * * @param _fee The fee, expressed in bps. */ function setFee(uint256 _fee) external override onlyOwner { require(_fee <= MAX_FEE, "Invalid fee"); fee = _fee; emit SetFee(fee); } /** * @notice Change the designated hoard, the address where treasures and * legions are held. Staked NFTs can only be * withdrawn to the current hoard address, regardless of which * address the hoard was set to when it was staked. * * @param _hoard The new hoard address. * @param isSet Whether to enable or disable the hoard address. */ function setHoard(address _hoard, bool isSet) external override onlyOwner { require(_hoard != address(0), "Invalid hoard"); hoards[_hoard] = isSet; } /** * @notice Approve treasures and legions for withdrawal from the atlas mine. * Called on startup, and should be called again in case contract * addresses for treasures and legions ever change. * */ function approveNFTs() public override onlyOwner { _approveNFTs(); } /** * @notice Revokes approvals for the Atlas Mine. Should only be used * in case of emergency, blocking further staking, or an Atlas * Mine exploit. * */ function revokeNFTApprovals() public override onlyOwner { address treasureAddr = mine.treasure(); IERC1155Upgradeable(treasureAddr).setApprovalForAll(address(mine), false); address legionAddr = mine.legion(); IERC721Upgradeable(legionAddr).setApprovalForAll(address(mine), false); } /** * @notice Withdraw any accumulated reward fees to the contract owner. */ function withdrawFees() external virtual override onlyOwner { uint256 amount = feeReserve; feeReserve = 0; magic.safeTransfer(msg.sender, amount); } /** * @notice Set the minimum amount of time needed to wait between stakes. * Default 12 hours. Can be adjusted to be longer (if incremental * stakes are too small or we are staking too often) or shorter * if too much unstaked deposit is building up. * * @param wait The minimum amount of time to wait in between stakes. */ function setMinimumStakingWait(uint256 wait) external override onlyOwner { require(wait >= 3 hours, "Minimum interval 3 hours"); minimumStakingWait = wait; emit SetMinimumStakingWait(wait); } /** * @notice EMERGENCY ONLY - toggle pausing new scheduled stakes. * If on, users can deposit, but stakes won't go to Atlas Mine. * Can be used in case of Atlas Mine issues or forced migration * to new contract. */ function toggleSchedulePause(bool paused) external virtual override onlyOwner { schedulePaused = paused; emit StakingPauseToggle(paused); } /** * @notice Used to set windows during which accrual happens, and new deposits/withdrawls * are paused. * * @param windows The list of hourly windows in pairs of tuples, e.g. [0, 1, 12, 13] */ function setAccrualWindows(uint256[] calldata windows) external override onlyOwner { require(windows.length % 2 == 0, "Invalid window length"); require(windows.length < 5, "Too many windows"); for (uint256 i = 0; i < windows.length; i++) { // Must be 0-23, and monotonically increasing if (i < windows.length - 1) { require(windows[i] < 24, "Invalid window value"); } else { // Allow 24 as an ending value require(windows[i] < 25, "Invalid window value"); } if (i > 0) { require(windows[i] > windows[i - 1], "Invalid window ordering"); } } accrualWindows = windows; emit SetAccrualWindows(windows); } /** * @notice Must be used when upgrading to a new contract to set aside rewards for those * who have deposited. * * @dev Cannot be used in normal operation, will only be called once after the * initial reward accrual post-upgrade. * * * @param _amountToReserve The amount of rewards to reserve. */ function reserveWithdrawerRewards(uint256 _amountToReserve) external onlyOwner { require(!_rewardsResetCalled, "reset already called"); _rewardsResetCalled = true; feeReserve += _amountToReserve; totalRewardsEarned -= _amountToReserve; accRewardsPerShare -= (_amountToReserve * ONE) / totalStaked; } /** * @notice Used to set a reward for calling accrue and helping the mine harvest. * * @param _reward The new accrual reward, in bps. */ function setAccrueIncentive(uint256 _reward) external onlyOwner { require(_reward <= 500, "reward too high"); accrueIncentiveBps = _reward; emit SetAccrualIncentive(_reward); } // ======================================== VIEW FUNCTIONS ========================================= /** * @notice Returns all magic either unstaked, staked, or pending rewards in Atlas Mine. * Best proxy for TVL. * * @return total The total amount of MAGIC in the staker. */ function totalMagic() external view override returns (uint256) { return _totalControlledMagic() + mine.pendingRewardsAll(address(this)); } /** * @notice Returns all magic that has been deposited, but not staked, and is eligible * to be staked (deposit time < current day). * * @return total The total amount of MAGIC available to stake. */ function totalPendingStake() external view override returns (uint256) { return unstakedDeposits; } /** * @notice Returns all magic that has been deposited, but not staked, and is eligible * to be staked (deposit time < current day). * * @return total The total amount of MAGIC that can be withdrawn. */ function totalWithdrawableMagic() external view override returns (uint256) { uint256 totalPendingRewards; // AtlasMine attempts to divide by 0 if there are no deposits try mine.pendingRewardsAll(address(this)) returns (uint256 _pending) { totalPendingRewards = _pending; } catch Panic(uint256) { totalPendingRewards = 0; } uint256 vestedPrincipal; uint256 totalStakes = stakes.length; for (uint256 i = nextActiveStake; i < totalStakes; i++) { vestedPrincipal += mine.calcualteVestedPrincipal(address(this), stakes[i].depositId); } return _totalUsableMagic() + totalPendingRewards + vestedPrincipal; } /** * @notice Returns the details of a user stake. * * @return userStake The details of a user stake. */ function getUserStake(address user, uint256 depositId) external view override returns (UserStake memory) { return userStake[user][depositId]; } /** * @notice Returns the total amount staked by a user. * * @return totalStake The total amount of MAGIC staked by a user. */ function userTotalStake(address user) external view override returns (uint256 totalStake) { uint256[] memory depositIds = allUserDepositIds[user].values(); uint256 numDeposits = depositIds.length; for (uint256 i = 0; i < numDeposits; i++) { UserStake storage s = userStake[user][depositIds[i]]; totalStake += s.amount; } } /** * @notice Returns the pending, claimable rewards for a deposit. * @dev This does not update rewards, so out of date if rewards not recently updated. * Needed to maintain 'view' function type. * * @param user The user to check rewards for. * @param depositId The specific deposit to check rewards for. * * @return reward The total amount of MAGIC reward pending. */ function pendingRewards(address user, uint256 depositId) public view override returns (uint256 reward) { UserStake storage s = userStake[user][depositId]; if (s.amount == 0) return 0; int256 accumulatedRewards = _accumulatedRewards(s.amount); if (accumulatedRewards <= s.rewardDebt) { return 0; } // Reduce by 1 wei to work around off-by-one error in atlas mine reward = (accumulatedRewards - s.rewardDebt - 1).toUint256(); } /** * @notice Returns the pending, claimable rewards for all of a user's deposits. * @dev This does not update rewards, so out of date if rewards not recently updated. * Needed to maintain 'view' function type. * * @param user The user to check rewards for. * * @return reward The total amount of MAGIC reward pending. */ function pendingRewardsAll(address user) external view override returns (uint256 reward) { uint256[] memory depositIds = allUserDepositIds[user].values(); uint256 numDeposits = depositIds.length; for (uint256 i = 0; i < numDeposits; i++) { UserStake storage s = userStake[user][depositIds[i]]; if (s.amount > 0) { reward += pendingRewards(user, depositIds[i]); } } } // ============================================ HELPERS ============================================ /** * @dev Approve treasures and legions for withdrawal from the atlas mine. */ function _approveNFTs() internal { address treasureAddr = mine.treasure(); IERC1155Upgradeable(treasureAddr).setApprovalForAll(address(mine), true); address legionAddr = mine.legion(); IERC721Upgradeable(legionAddr).setApprovalForAll(address(mine), true); } /** * @dev Stake tokens held by staker in the Atlas Mine, according to * the predefined lock value. Schedules for staking will be managed by a queue. * * @param _amount Number of tokens to stake */ function _stakeInMine(uint256 _amount) internal { require(_amount <= _totalUsableMagic(), "Not enough funds"); uint256 depositId = ++lastDepositId; uint256 unlockAt = block.timestamp + locktime; stakes.push(Stake({ amount: _amount, unlockAt: unlockAt, depositId: depositId })); mine.deposit(_amount, lock); } /** * @dev Unstakes until we have enough unstaked tokens to meet a specific target. * Used to make sure we can service withdrawals. * * @param target The amount of tokens we want to have unstaked. */ function _unstakeToTarget(uint256 target) internal { uint256 unstaked = 0; uint256 totalStakes = stakes.length; for (uint256 i = nextActiveStake; i < totalStakes; i++) { Stake memory s = stakes[i]; if (s.unlockAt > block.timestamp && !mine.unlockAll()) { // This stake is not unlocked - stop looking break; } // Withdraw position - auto-harvest uint256 preclaimBalance = _totalUsableMagic(); uint256 targetLeft = target - unstaked; uint256 amount = targetLeft > s.amount ? s.amount : targetLeft; // Do not harvest rewards - if this is running, we've already // harvested in the same fn call mine.withdrawPosition(s.depositId, amount); uint256 postclaimBalance = _totalUsableMagic(); // Increment amount unstaked unstaked += postclaimBalance - preclaimBalance; if (unstaked >= target) { // We unstaked enough break; } } require(unstaked >= target, "Cannot unstake enough"); require(_totalUsableMagic() >= target, "Not enough in contract after unstaking"); // Only check for removal after, so we don't mutate while looping _removeZeroStakes(); } /** * @dev Harvest rewards from the AtlasMine and send them back to * this contract. Cannot harvest entire set of positions due to * gas limits, so positions need to be specified. * * @param depositIds The deposits to harvest rewards for. * * @return earned The amount of rewards earned for depositors, minus the fee. * @return feeEearned The amount of fees earned for the contract operator. */ function _harvestMine(uint256[] memory depositIds) internal returns ( uint256, uint256, uint256 ) { uint256 preclaimBalance = magic.balanceOf(address(this)); uint256 numDeposits = depositIds.length; for (uint256 i = 0; i < numDeposits; i++) { // Might fail because of reward debt calculation try mine.harvestPosition(depositIds[i]) {} catch { // SafeCast error } } uint256 postclaimBalance = magic.balanceOf(address(this)); uint256 earned = postclaimBalance - preclaimBalance; // Reserve the 'fee' amount of what is earned uint256 feeEarned = (earned * fee) / FEE_DENOMINATOR; feeReserve += feeEarned; uint256 accrueIncentive = (earned * accrueIncentiveBps) / FEE_DENOMINATOR; earned -= (feeEarned + accrueIncentive); emit MineHarvest(earned, feeEarned, depositIds); return (earned, feeEarned, accrueIncentive); } /** * @dev Harvest rewards from the mine so that stakers can claim. * Recalculate how many rewards are distributed to each share. * * @param depositIds The deposits to harvest rewards for. */ function _updateRewards(uint256[] memory depositIds) internal returns (uint256) { if (totalStaked == 0) return 0; (uint256 newRewards, , uint256 accrueIncentive) = _harvestMine(depositIds); totalRewardsEarned += newRewards; accRewardsPerShare += (newRewards * ONE) / totalStaked; return accrueIncentive; } /** * @dev After mutating a stake (by withdrawing fully or partially), * get updated data from the staking contract, and update the stake amounts * * @param stakeIndex The index of the stake in the Stakes storage array. * * @return amount The current, updated amount of the stake. */ function _updateStakeDepositAmount(uint256 stakeIndex) internal returns (uint256) { Stake storage s = stakes[stakeIndex]; (, uint256 depositAmount, , , , , ) = mine.userInfo(address(this), s.depositId); s.amount = depositAmount; return s.amount; } /** * @dev Find stakes with zero deposit amount and remove them from tracking. * Starts from the last fully withdrawn stake, and keeps counting until * we find a non-zero stake. * */ function _removeZeroStakes() internal { uint256 totalStakes = stakes.length; for (uint256 i = nextActiveStake; i < totalStakes; i++) { _updateStakeDepositAmount(i); Stake memory s = stakes[i]; if (s.amount != 0) { // No more zero stakes - can break nextActiveStake = i; break; } } } /** * @dev Calculate total amount of MAGIC usable by the contract. * 'Usable' means available for either withdrawal or re-staking. * Counts unstaked magic less fee reserve. * * @return amount The amount of usable MAGIC. */ function _totalUsableMagic() internal view returns (uint256) { // Current magic held in contract uint256 unstaked = magic.balanceOf(address(this)); return unstaked - feeReserve - tokenBuffer; } /** * @dev Calculate total amount of MAGIC under control of the contract. * Counts staked and unstaked MAGIC. Does _not_ count accumulated * but unclaimed rewards. * * @return amount The total amount of MAGIC under control of the contract. */ function _totalControlledMagic() internal view returns (uint256) { // Current magic staked in mine uint256 staked = 0; uint256 totalStakes = stakes.length; for (uint256 i = nextActiveStake; i < totalStakes; i++) { staked += stakes[i].amount; } return staked + _totalUsableMagic(); } /** * @dev Determine if the current block timestamp falls in an accrual window. * During accrual windows deposits/withdraws/claims are enabled, and reward * updating is enabled. * * @return inWindow Whether the current time falls in an accrual window. */ function _isAccrualWindow() internal view returns (bool inWindow) { require(accrualWindows.length > 0, "Accrual windows not set"); /// time elapsed in day / hours uint256 currentHour = (block.timestamp % 86_400) / 3_600; for (uint256 i = 0; i < accrualWindows.length - 1; i += 2) { if (currentHour >= accrualWindows[i] && currentHour < accrualWindows[i + 1]) { inWindow = true; break; } } } /** * @dev Calculate the current accumulated rewards for a given amount of stake. * Reduces the awards by 1 wei due to an off-by-one issue in the atlas mine. * * @param stakeAmount The amount of stake to accumulate rewards for. */ function _accumulatedRewards(uint256 stakeAmount) internal view returns (int256) { return ((stakeAmount * accRewardsPerShare) / ONE).toInt256(); } /** * @dev For methods only callable by the hoard - Treasure staking/unstaking. */ modifier onlyHoard() { require(hoards[msg.sender], "Not hoard"); _; } /** * @dev For methods that access the token buffer - make sure it is cleared. */ modifier usesBuffer() { _; require(tokenBuffer == 0, "Buffer not clear"); } /** * @dev For methods that affect staking, when an accrual window is not active. */ modifier whenNotAccruing() { require(!_isAccrualWindow(), "In accrual window"); _; } /** * @dev For methods accrue rewards, when staking is not active. */ modifier whenAccruing() { require(_isAccrualWindow(), "Not accruing"); _; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/IERC20.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20Upgradeable { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `to`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address to, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `from` to `to` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 amount ) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC20/utils/SafeERC20.sol) pragma solidity ^0.8.0; import "../IERC20Upgradeable.sol"; import "../../../utils/AddressUpgradeable.sol"; /** * @title SafeERC20 * @dev Wrappers around ERC20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20Upgradeable { using AddressUpgradeable for address; function safeTransfer( IERC20Upgradeable token, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom( IERC20Upgradeable token, address from, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } /** * @dev Deprecated. This function has issues similar to the ones found in * {IERC20-approve}, and its usage is discouraged. * * Whenever possible, use {safeIncreaseAllowance} and * {safeDecreaseAllowance} instead. */ function safeApprove( IERC20Upgradeable token, address spender, uint256 value ) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' require( (value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function safeIncreaseAllowance( IERC20Upgradeable token, address spender, uint256 value ) internal { uint256 newAllowance = token.allowance(address(this), spender) + value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } function safeDecreaseAllowance( IERC20Upgradeable token, address spender, uint256 value ) internal { unchecked { uint256 oldAllowance = token.allowance(address(this), spender); require(oldAllowance >= value, "SafeERC20: decreased allowance below zero"); uint256 newAllowance = oldAllowance - value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */ function _callOptionalReturn(IERC20Upgradeable token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that // the target address contains contract code and also asserts for success in the low-level call. bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed"); if (returndata.length > 0) { // Return data is optional require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC1155/IERC1155.sol) pragma solidity ^0.8.0; import "../../utils/introspection/IERC165Upgradeable.sol"; /** * @dev Required interface of an ERC1155 compliant contract, as defined in the * https://eips.ethereum.org/EIPS/eip-1155[EIP]. * * _Available since v3.1._ */ interface IERC1155Upgradeable is IERC165Upgradeable { /** * @dev Emitted when `value` tokens of token type `id` are transferred from `from` to `to` by `operator`. */ event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value); /** * @dev Equivalent to multiple {TransferSingle} events, where `operator`, `from` and `to` are the same for all * transfers. */ event TransferBatch( address indexed operator, address indexed from, address indexed to, uint256[] ids, uint256[] values ); /** * @dev Emitted when `account` grants or revokes permission to `operator` to transfer their tokens, according to * `approved`. */ event ApprovalForAll(address indexed account, address indexed operator, bool approved); /** * @dev Emitted when the URI for token type `id` changes to `value`, if it is a non-programmatic URI. * * If an {URI} event was emitted for `id`, the standard * https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[guarantees] that `value` will equal the value * returned by {IERC1155MetadataURI-uri}. */ event URI(string value, uint256 indexed id); /** * @dev Returns the amount of tokens of token type `id` owned by `account`. * * Requirements: * * - `account` cannot be the zero address. */ function balanceOf(address account, uint256 id) external view returns (uint256); /** * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {balanceOf}. * * Requirements: * * - `accounts` and `ids` must have the same length. */ function balanceOfBatch(address[] calldata accounts, uint256[] calldata ids) external view returns (uint256[] memory); /** * @dev Grants or revokes permission to `operator` to transfer the caller's tokens, according to `approved`, * * Emits an {ApprovalForAll} event. * * Requirements: * * - `operator` cannot be the caller. */ function setApprovalForAll(address operator, bool approved) external; /** * @dev Returns true if `operator` is approved to transfer ``account``'s tokens. * * See {setApprovalForAll}. */ function isApprovedForAll(address account, address operator) external view returns (bool); /** * @dev Transfers `amount` tokens of token type `id` from `from` to `to`. * * Emits a {TransferSingle} event. * * Requirements: * * - `to` cannot be the zero address. * - If the caller is not `from`, it must be have been approved to spend ``from``'s tokens via {setApprovalForAll}. * - `from` must have a balance of tokens of type `id` of at least `amount`. * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the * acceptance magic value. */ function safeTransferFrom( address from, address to, uint256 id, uint256 amount, bytes calldata data ) external; /** * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}. * * Emits a {TransferBatch} event. * * Requirements: * * - `ids` and `amounts` must have the same length. * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the * acceptance magic value. */ function safeBatchTransferFrom( address from, address to, uint256[] calldata ids, uint256[] calldata amounts, bytes calldata data ) external; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (token/ERC1155/utils/ERC1155Holder.sol) pragma solidity ^0.8.0; import "./ERC1155ReceiverUpgradeable.sol"; import "../../../proxy/utils/Initializable.sol"; /** * Simple implementation of `ERC1155Receiver` that will allow a contract to hold ERC1155 tokens. * * IMPORTANT: When inheriting this contract, you must include a way to use the received tokens, otherwise they will be * stuck. * * @dev _Available since v3.1._ */ contract ERC1155HolderUpgradeable is Initializable, ERC1155ReceiverUpgradeable { function __ERC1155Holder_init() internal onlyInitializing { } function __ERC1155Holder_init_unchained() internal onlyInitializing { } function onERC1155Received( address, address, uint256, uint256, bytes memory ) public virtual override returns (bytes4) { return this.onERC1155Received.selector; } function onERC1155BatchReceived( address, address, uint256[] memory, uint256[] memory, bytes memory ) public virtual override returns (bytes4) { return this.onERC1155BatchReceived.selector; } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[50] private __gap; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721.sol) pragma solidity ^0.8.0; import "../../utils/introspection/IERC165Upgradeable.sol"; /** * @dev Required interface of an ERC721 compliant contract. */ interface IERC721Upgradeable is IERC165Upgradeable { /** * @dev Emitted when `tokenId` token is transferred from `from` to `to`. */ event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token. */ event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets. */ event ApprovalForAll(address indexed owner, address indexed operator, bool approved); /** * @dev Returns the number of tokens in ``owner``'s account. */ function balanceOf(address owner) external view returns (uint256 balance); /** * @dev Returns the owner of the `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function ownerOf(uint256 tokenId) external view returns (address owner); /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Transfers `tokenId` token from `from` to `to`. * * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Gives permission to `to` to transfer `tokenId` token to another account. * The approval is cleared when the token is transferred. * * Only a single account can be approved at a time, so approving the zero address clears previous approvals. * * Requirements: * * - The caller must own the token or be an approved operator. * - `tokenId` must exist. * * Emits an {Approval} event. */ function approve(address to, uint256 tokenId) external; /** * @dev Returns the account approved for `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function getApproved(uint256 tokenId) external view returns (address operator); /** * @dev Approve or remove `operator` as an operator for the caller. * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. * * Requirements: * * - The `operator` cannot be the caller. * * Emits an {ApprovalForAll} event. */ function setApprovalForAll(address operator, bool _approved) external; /** * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. * * See {setApprovalForAll} */ function isApprovedForAll(address owner, address operator) external view returns (bool); /** * @dev Safely transfers `tokenId` token from `from` to `to`. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes calldata data ) external; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC721/utils/ERC721Holder.sol) pragma solidity ^0.8.0; import "../IERC721ReceiverUpgradeable.sol"; import "../../../proxy/utils/Initializable.sol"; /** * @dev Implementation of the {IERC721Receiver} interface. * * Accepts all token transfers. * Make sure the contract is able to use its token with {IERC721-safeTransferFrom}, {IERC721-approve} or {IERC721-setApprovalForAll}. */ contract ERC721HolderUpgradeable is Initializable, IERC721ReceiverUpgradeable { function __ERC721Holder_init() internal onlyInitializing { } function __ERC721Holder_init_unchained() internal onlyInitializing { } /** * @dev See {IERC721Receiver-onERC721Received}. * * Always returns `IERC721Receiver.onERC721Received.selector`. */ function onERC721Received( address, address, uint256, bytes memory ) public virtual override returns (bytes4) { return this.onERC721Received.selector; } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[50] private __gap; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (proxy/utils/Initializable.sol) pragma solidity ^0.8.0; import "../../utils/AddressUpgradeable.sol"; /** * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. * * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}. * * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. * * [CAUTION] * ==== * Avoid leaving a contract uninitialized. * * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation * contract, which may impact the proxy. To initialize the implementation contract, you can either invoke the * initializer manually, or you can include a constructor to automatically mark it as initialized when it is deployed: * * [.hljs-theme-light.nopadding] * ``` * /// @custom:oz-upgrades-unsafe-allow constructor * constructor() initializer {} * ``` * ==== */ abstract contract Initializable { /** * @dev Indicates that the contract has been initialized. */ bool private _initialized; /** * @dev Indicates that the contract is in the process of being initialized. */ bool private _initializing; /** * @dev Modifier to protect an initializer function from being invoked twice. */ modifier initializer() { // If the contract is initializing we ignore whether _initialized is set in order to support multiple // inheritance patterns, but we only do this in the context of a constructor, because in other contexts the // contract may have been reentered. require(_initializing ? _isConstructor() : !_initialized, "Initializable: contract is already initialized"); bool isTopLevelCall = !_initializing; if (isTopLevelCall) { _initializing = true; _initialized = true; } _; if (isTopLevelCall) { _initializing = false; } } /** * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the * {initializer} modifier, directly or indirectly. */ modifier onlyInitializing() { require(_initializing, "Initializable: contract is not initializing"); _; } function _isConstructor() private view returns (bool) { return !AddressUpgradeable.isContract(address(this)); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @dev Collection of functions related to the address type */ library AddressUpgradeable { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== * * [IMPORTANT] * ==== * You shouldn't rely on `isContract` to protect against flash loan attacks! * * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract * constructor. * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize/address.code.length, which returns 0 // for contracts in construction, since the code is only stored at the end // of the constructor execution. return account.code.length > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/math/SafeCast.sol) pragma solidity ^0.8.0; /** * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow * checks. * * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can * easily result in undesired exploitation or bugs, since developers usually * assume that overflows raise errors. `SafeCast` restores this intuition by * reverting the transaction when such an operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. * * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing * all math on `uint256` and `int256` and then downcasting. */ library SafeCastUpgradeable { /** * @dev Returns the downcasted uint224 from uint256, reverting on * overflow (when the input is greater than largest uint224). * * Counterpart to Solidity's `uint224` operator. * * Requirements: * * - input must fit into 224 bits */ function toUint224(uint256 value) internal pure returns (uint224) { require(value <= type(uint224).max, "SafeCast: value doesn't fit in 224 bits"); return uint224(value); } /** * @dev Returns the downcasted uint128 from uint256, reverting on * overflow (when the input is greater than largest uint128). * * Counterpart to Solidity's `uint128` operator. * * Requirements: * * - input must fit into 128 bits */ function toUint128(uint256 value) internal pure returns (uint128) { require(value <= type(uint128).max, "SafeCast: value doesn't fit in 128 bits"); return uint128(value); } /** * @dev Returns the downcasted uint96 from uint256, reverting on * overflow (when the input is greater than largest uint96). * * Counterpart to Solidity's `uint96` operator. * * Requirements: * * - input must fit into 96 bits */ function toUint96(uint256 value) internal pure returns (uint96) { require(value <= type(uint96).max, "SafeCast: value doesn't fit in 96 bits"); return uint96(value); } /** * @dev Returns the downcasted uint64 from uint256, reverting on * overflow (when the input is greater than largest uint64). * * Counterpart to Solidity's `uint64` operator. * * Requirements: * * - input must fit into 64 bits */ function toUint64(uint256 value) internal pure returns (uint64) { require(value <= type(uint64).max, "SafeCast: value doesn't fit in 64 bits"); return uint64(value); } /** * @dev Returns the downcasted uint32 from uint256, reverting on * overflow (when the input is greater than largest uint32). * * Counterpart to Solidity's `uint32` operator. * * Requirements: * * - input must fit into 32 bits */ function toUint32(uint256 value) internal pure returns (uint32) { require(value <= type(uint32).max, "SafeCast: value doesn't fit in 32 bits"); return uint32(value); } /** * @dev Returns the downcasted uint16 from uint256, reverting on * overflow (when the input is greater than largest uint16). * * Counterpart to Solidity's `uint16` operator. * * Requirements: * * - input must fit into 16 bits */ function toUint16(uint256 value) internal pure returns (uint16) { require(value <= type(uint16).max, "SafeCast: value doesn't fit in 16 bits"); return uint16(value); } /** * @dev Returns the downcasted uint8 from uint256, reverting on * overflow (when the input is greater than largest uint8). * * Counterpart to Solidity's `uint8` operator. * * Requirements: * * - input must fit into 8 bits. */ function toUint8(uint256 value) internal pure returns (uint8) { require(value <= type(uint8).max, "SafeCast: value doesn't fit in 8 bits"); return uint8(value); } /** * @dev Converts a signed int256 into an unsigned uint256. * * Requirements: * * - input must be greater than or equal to 0. */ function toUint256(int256 value) internal pure returns (uint256) { require(value >= 0, "SafeCast: value must be positive"); return uint256(value); } /** * @dev Returns the downcasted int128 from int256, reverting on * overflow (when the input is less than smallest int128 or * greater than largest int128). * * Counterpart to Solidity's `int128` operator. * * Requirements: * * - input must fit into 128 bits * * _Available since v3.1._ */ function toInt128(int256 value) internal pure returns (int128) { require(value >= type(int128).min && value <= type(int128).max, "SafeCast: value doesn't fit in 128 bits"); return int128(value); } /** * @dev Returns the downcasted int64 from int256, reverting on * overflow (when the input is less than smallest int64 or * greater than largest int64). * * Counterpart to Solidity's `int64` operator. * * Requirements: * * - input must fit into 64 bits * * _Available since v3.1._ */ function toInt64(int256 value) internal pure returns (int64) { require(value >= type(int64).min && value <= type(int64).max, "SafeCast: value doesn't fit in 64 bits"); return int64(value); } /** * @dev Returns the downcasted int32 from int256, reverting on * overflow (when the input is less than smallest int32 or * greater than largest int32). * * Counterpart to Solidity's `int32` operator. * * Requirements: * * - input must fit into 32 bits * * _Available since v3.1._ */ function toInt32(int256 value) internal pure returns (int32) { require(value >= type(int32).min && value <= type(int32).max, "SafeCast: value doesn't fit in 32 bits"); return int32(value); } /** * @dev Returns the downcasted int16 from int256, reverting on * overflow (when the input is less than smallest int16 or * greater than largest int16). * * Counterpart to Solidity's `int16` operator. * * Requirements: * * - input must fit into 16 bits * * _Available since v3.1._ */ function toInt16(int256 value) internal pure returns (int16) { require(value >= type(int16).min && value <= type(int16).max, "SafeCast: value doesn't fit in 16 bits"); return int16(value); } /** * @dev Returns the downcasted int8 from int256, reverting on * overflow (when the input is less than smallest int8 or * greater than largest int8). * * Counterpart to Solidity's `int8` operator. * * Requirements: * * - input must fit into 8 bits. * * _Available since v3.1._ */ function toInt8(int256 value) internal pure returns (int8) { require(value >= type(int8).min && value <= type(int8).max, "SafeCast: value doesn't fit in 8 bits"); return int8(value); } /** * @dev Converts an unsigned uint256 into a signed int256. * * Requirements: * * - input must be less than or equal to maxInt256. */ function toInt256(uint256 value) internal pure returns (int256) { // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive require(value <= uint256(type(int256).max), "SafeCast: value doesn't fit in an int256"); return int256(value); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/structs/EnumerableSet.sol) pragma solidity ^0.8.0; /** * @dev Library for managing * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive * types. * * Sets have the following properties: * * - Elements are added, removed, and checked for existence in constant time * (O(1)). * - Elements are enumerated in O(n). No guarantees are made on the ordering. * * ``` * contract Example { * // Add the library methods * using EnumerableSet for EnumerableSet.AddressSet; * * // Declare a set state variable * EnumerableSet.AddressSet private mySet; * } * ``` * * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`) * and `uint256` (`UintSet`) are supported. */ library EnumerableSetUpgradeable { // To implement this library for multiple types with as little code // repetition as possible, we write it in terms of a generic Set type with // bytes32 values. // The Set implementation uses private functions, and user-facing // implementations (such as AddressSet) are just wrappers around the // underlying Set. // This means that we can only create new EnumerableSets for types that fit // in bytes32. struct Set { // Storage of set values bytes32[] _values; // Position of the value in the `values` array, plus 1 because index 0 // means a value is not in the set. mapping(bytes32 => uint256) _indexes; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function _add(Set storage set, bytes32 value) private returns (bool) { if (!_contains(set, value)) { set._values.push(value); // The value is stored at length-1, but we add 1 to all indexes // and use 0 as a sentinel value set._indexes[value] = set._values.length; return true; } else { return false; } } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function _remove(Set storage set, bytes32 value) private returns (bool) { // We read and store the value's index to prevent multiple reads from the same storage slot uint256 valueIndex = set._indexes[value]; if (valueIndex != 0) { // Equivalent to contains(set, value) // To delete an element from the _values array in O(1), we swap the element to delete with the last one in // the array, and then remove the last element (sometimes called as 'swap and pop'). // This modifies the order of the array, as noted in {at}. uint256 toDeleteIndex = valueIndex - 1; uint256 lastIndex = set._values.length - 1; if (lastIndex != toDeleteIndex) { bytes32 lastvalue = set._values[lastIndex]; // Move the last value to the index where the value to delete is set._values[toDeleteIndex] = lastvalue; // Update the index for the moved value set._indexes[lastvalue] = valueIndex; // Replace lastvalue's index to valueIndex } // Delete the slot where the moved value was stored set._values.pop(); // Delete the index for the deleted slot delete set._indexes[value]; return true; } else { return false; } } /** * @dev Returns true if the value is in the set. O(1). */ function _contains(Set storage set, bytes32 value) private view returns (bool) { return set._indexes[value] != 0; } /** * @dev Returns the number of values on the set. O(1). */ function _length(Set storage set) private view returns (uint256) { return set._values.length; } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function _at(Set storage set, uint256 index) private view returns (bytes32) { return set._values[index]; } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function _values(Set storage set) private view returns (bytes32[] memory) { return set._values; } // Bytes32Set struct Bytes32Set { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(Bytes32Set storage set, bytes32 value) internal returns (bool) { return _add(set._inner, value); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) { return _remove(set._inner, value); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) { return _contains(set._inner, value); } /** * @dev Returns the number of values in the set. O(1). */ function length(Bytes32Set storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) { return _at(set._inner, index); } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function values(Bytes32Set storage set) internal view returns (bytes32[] memory) { return _values(set._inner); } // AddressSet struct AddressSet { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(AddressSet storage set, address value) internal returns (bool) { return _add(set._inner, bytes32(uint256(uint160(value)))); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(AddressSet storage set, address value) internal returns (bool) { return _remove(set._inner, bytes32(uint256(uint160(value)))); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(AddressSet storage set, address value) internal view returns (bool) { return _contains(set._inner, bytes32(uint256(uint160(value)))); } /** * @dev Returns the number of values in the set. O(1). */ function length(AddressSet storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(AddressSet storage set, uint256 index) internal view returns (address) { return address(uint160(uint256(_at(set._inner, index)))); } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function values(AddressSet storage set) internal view returns (address[] memory) { bytes32[] memory store = _values(set._inner); address[] memory result; assembly { result := store } return result; } // UintSet struct UintSet { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(UintSet storage set, uint256 value) internal returns (bool) { return _add(set._inner, bytes32(value)); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(UintSet storage set, uint256 value) internal returns (bool) { return _remove(set._inner, bytes32(value)); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(UintSet storage set, uint256 value) internal view returns (bool) { return _contains(set._inner, bytes32(value)); } /** * @dev Returns the number of values on the set. O(1). */ function length(UintSet storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(UintSet storage set, uint256 index) internal view returns (uint256) { return uint256(_at(set._inner, index)); } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function values(UintSet storage set) internal view returns (uint256[] memory) { bytes32[] memory store = _values(set._inner); uint256[] memory result; assembly { result := store } return result; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol) pragma solidity ^0.8.0; import "../proxy/utils/Initializable.sol"; /** * @dev Contract module that helps prevent reentrant calls to a function. * * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier * available, which can be applied to functions to make sure there are no nested * (reentrant) calls to them. * * Note that because there is a single `nonReentrant` guard, functions marked as * `nonReentrant` may not call one another. This can be worked around by making * those functions `private`, and then adding `external` `nonReentrant` entry * points to them. * * TIP: If you would like to learn more about reentrancy and alternative ways * to protect against it, check out our blog post * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul]. */ abstract contract ReentrancyGuardUpgradeable is Initializable { // Booleans are more expensive than uint256 or any type that takes up a full // word because each write operation emits an extra SLOAD to first read the // slot's contents, replace the bits taken up by the boolean, and then write // back. This is the compiler's defense against contract upgrades and // pointer aliasing, and it cannot be disabled. // The values being non-zero value makes deployment a bit more expensive, // but in exchange the refund on every call to nonReentrant will be lower in // amount. Since refunds are capped to a percentage of the total // transaction's gas, it is best to keep them low in cases like this one, to // increase the likelihood of the full refund coming into effect. uint256 private constant _NOT_ENTERED = 1; uint256 private constant _ENTERED = 2; uint256 private _status; function __ReentrancyGuard_init() internal onlyInitializing { __ReentrancyGuard_init_unchained(); } function __ReentrancyGuard_init_unchained() internal onlyInitializing { _status = _NOT_ENTERED; } /** * @dev Prevents a contract from calling itself, directly or indirectly. * Calling a `nonReentrant` function from another `nonReentrant` * function is not supported. It is possible to prevent this from happening * by making the `nonReentrant` function external, and making it call a * `private` function that does the actual work. */ modifier nonReentrant() { // On the first call to nonReentrant, _notEntered will be true require(_status != _ENTERED, "ReentrancyGuard: reentrant call"); // Any calls to nonReentrant after this point will fail _status = _ENTERED; _; // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) _status = _NOT_ENTERED; } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[49] private __gap; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/Ownable.sol) pragma solidity ^0.8.0; import "../utils/ContextUpgradeable.sol"; import "../proxy/utils/Initializable.sol"; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ function __Ownable_init() internal onlyInitializing { __Ownable_init_unchained(); } function __Ownable_init_unchained() internal onlyInitializing { _transferOwnership(_msgSender()); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _transferOwnership(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Internal function without access restriction. */ function _transferOwnership(address newOwner) internal virtual { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[49] private __gap; }
// SPDX-License-Identifier: MIT pragma solidity 0.8.11; import '@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol'; import '@openzeppelin/contracts-upgradeable/token/ERC721/IERC721Upgradeable.sol'; import '@openzeppelin/contracts-upgradeable/token/ERC1155/IERC1155Upgradeable.sol'; import '@openzeppelin/contracts-upgradeable/utils/structs/EnumerableSetUpgradeable.sol'; import '@openzeppelin/contracts-upgradeable/utils/math/SafeCastUpgradeable.sol'; import '@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol'; import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; import '@openzeppelin/contracts-upgradeable/access/AccessControlEnumerableUpgradeable.sol'; import '@openzeppelin/contracts-upgradeable/token/ERC1155/utils/ERC1155HolderUpgradeable.sol'; import './interfaces/IMasterOfCoin.sol'; import './interfaces/ILegionMetadataStore.sol'; contract AtlasMine is Initializable, AccessControlEnumerableUpgradeable, ERC1155HolderUpgradeable { using EnumerableSetUpgradeable for EnumerableSetUpgradeable.AddressSet; using EnumerableSetUpgradeable for EnumerableSetUpgradeable.UintSet; using SafeERC20Upgradeable for IERC20Upgradeable; using SafeCastUpgradeable for uint256; using SafeCastUpgradeable for int256; enum Lock { twoWeeks, oneMonth, threeMonths, sixMonths, twelveMonths } struct UserInfo { uint256 originalDepositAmount; uint256 depositAmount; uint256 lpAmount; uint256 lockedUntil; uint256 vestingLastUpdate; int256 rewardDebt; Lock lock; } bytes32 public constant ATLAS_MINE_ADMIN_ROLE = keccak256("ATLAS_MINE_ADMIN_ROLE"); uint256 public constant DAY = 1 days; uint256 public constant ONE_WEEK = 7 days; uint256 public constant TWO_WEEKS = ONE_WEEK * 2; uint256 public constant ONE_MONTH = 30 days; uint256 public constant THREE_MONTHS = ONE_MONTH * 3; uint256 public constant SIX_MONTHS = ONE_MONTH * 6; uint256 public constant TWELVE_MONTHS = 365 days; uint256 public constant ONE = 1e18; // Magic token addr IERC20Upgradeable public magic; IMasterOfCoin public masterOfCoin; bool public unlockAll; uint256 public totalRewardsEarned; uint256 public totalUndistributedRewards; uint256 public accMagicPerShare; uint256 public totalLpToken; uint256 public magicTotalDeposits; uint256 public utilizationOverride; EnumerableSetUpgradeable.AddressSet private excludedAddresses; address public legionMetadataStore; address public treasure; address public legion; // user => staked 1/1 mapping(address => bool) public isLegion1_1Staked; uint256[][] public legionBoostMatrix; /// @notice user => depositId => UserInfo mapping (address => mapping (uint256 => UserInfo)) public userInfo; /// @notice user => depositId[] mapping (address => EnumerableSetUpgradeable.UintSet) private allUserDepositIds; /// @notice user => deposit index mapping (address => uint256) public currentId; // user => tokenIds mapping (address => EnumerableSetUpgradeable.UintSet) private legionStaked; // user => tokenId => amount mapping (address => mapping(uint256 => uint256)) public treasureStaked; // user => total amount staked mapping (address => uint256) public treasureStakedAmount; // user => boost mapping (address => uint256) public boosts; event Staked(address nft, uint256 tokenId, uint256 amount, uint256 currentBoost); event Unstaked(address nft, uint256 tokenId, uint256 amount, uint256 currentBoost); event Deposit(address indexed user, uint256 indexed index, uint256 amount, Lock lock); event Withdraw(address indexed user, uint256 indexed index, uint256 amount); event UndistributedRewardsWithdraw(address indexed to, uint256 amount); event Harvest(address indexed user, uint256 indexed index, uint256 amount); event LogUpdateRewards(uint256 distributedRewards, uint256 undistributedRewards, uint256 lpSupply, uint256 accMagicPerShare); event UtilizationRate(uint256 util); modifier updateRewards() { uint256 lpSupply = totalLpToken; if (lpSupply > 0) { (uint256 distributedRewards, uint256 undistributedRewards) = getRealMagicReward(masterOfCoin.requestRewards()); totalRewardsEarned += distributedRewards; totalUndistributedRewards += undistributedRewards; accMagicPerShare += distributedRewards * ONE / lpSupply; emit LogUpdateRewards(distributedRewards, undistributedRewards, lpSupply, accMagicPerShare); } uint256 util = utilization(); emit UtilizationRate(util); _; } function init(address _magic, address _masterOfCoin) external initializer { magic = IERC20Upgradeable(_magic); masterOfCoin = IMasterOfCoin(_masterOfCoin); _setRoleAdmin(ATLAS_MINE_ADMIN_ROLE, ATLAS_MINE_ADMIN_ROLE); _grantRole(ATLAS_MINE_ADMIN_ROLE, msg.sender); // array follows values from ILegionMetadataStore.LegionGeneration and ILegionMetadataStore.LegionRarity legionBoostMatrix = [ // GENESIS // LEGENDARY,RARE,SPECIAL,UNCOMMON,COMMON,RECRUIT [uint256(600e16), uint256(200e16), uint256(75e16), uint256(100e16), uint256(50e16), uint256(0)], // AUXILIARY // LEGENDARY,RARE,SPECIAL,UNCOMMON,COMMON,RECRUIT [uint256(0), uint256(25e16), uint256(0), uint256(10e16), uint256(5e16), uint256(0)], // RECRUIT // LEGENDARY,RARE,SPECIAL,UNCOMMON,COMMON,RECRUIT [uint256(0), uint256(0), uint256(0), uint256(0), uint256(0), uint256(0)] ]; __AccessControlEnumerable_init(); __ERC1155Holder_init(); } function supportsInterface(bytes4 interfaceId) public view virtual override(ERC1155ReceiverUpgradeable, AccessControlEnumerableUpgradeable) returns (bool) { return super.supportsInterface(interfaceId); } function getStakedLegions(address _user) external view virtual returns (uint256[] memory) { return legionStaked[_user].values(); } function getUserBoost(address _user) external view virtual returns (uint256) { return boosts[_user]; } function getLegionBoostMatrix() external view virtual returns (uint256[][] memory) { return legionBoostMatrix; } function getLegionBoost(uint256 _legionGeneration, uint256 _legionRarity) public view virtual returns (uint256) { if (_legionGeneration < legionBoostMatrix.length && _legionRarity < legionBoostMatrix[_legionGeneration].length) { return legionBoostMatrix[_legionGeneration][_legionRarity]; } return 0; } function utilization() public view virtual returns (uint256 util) { if (utilizationOverride > 0) return utilizationOverride; uint256 circulatingSupply = magic.totalSupply(); uint256 len = excludedAddresses.length(); for (uint256 i = 0; i < len; i++) { circulatingSupply -= magic.balanceOf(excludedAddresses.at(i)); } uint256 rewardsAmount = magic.balanceOf(address(this)) - magicTotalDeposits; circulatingSupply -= rewardsAmount; if (circulatingSupply != 0) { util = magicTotalDeposits * ONE / circulatingSupply; } } function getRealMagicReward(uint256 _magicReward) public view virtual returns (uint256 distributedRewards, uint256 undistributedRewards) { uint256 util = utilization(); if (util < 3e17) { distributedRewards = 0; } else if (util < 4e17) { // >30% // 50% distributedRewards = _magicReward * 5 / 10; } else if (util < 5e17) { // >40% // 60% distributedRewards = _magicReward * 6 / 10; } else if (util < 6e17) { // >50% // 80% distributedRewards = _magicReward * 8 / 10; } else { // >60% // 100% distributedRewards = _magicReward; } undistributedRewards = _magicReward - distributedRewards; } function getAllUserDepositIds(address _user) public view virtual returns (uint256[] memory) { return allUserDepositIds[_user].values(); } function getExcludedAddresses() public view virtual returns (address[] memory) { return excludedAddresses.values(); } function getLockBoost(Lock _lock) public pure virtual returns (uint256 boost, uint256 timelock) { if (_lock == Lock.twoWeeks) { // 10% return (10e16, TWO_WEEKS); } else if (_lock == Lock.oneMonth) { // 25% return (25e16, ONE_MONTH); } else if (_lock == Lock.threeMonths) { // 80% return (80e16, THREE_MONTHS); } else if (_lock == Lock.sixMonths) { // 180% return (180e16, SIX_MONTHS); } else if (_lock == Lock.twelveMonths) { // 400% return (400e16, TWELVE_MONTHS); } else { revert("Invalid lock value"); } } function getVestingTime(Lock _lock) public pure virtual returns (uint256 vestingTime) { if (_lock == Lock.twoWeeks) { vestingTime = 0; } else if (_lock == Lock.oneMonth) { vestingTime = 7 days; } else if (_lock == Lock.threeMonths) { vestingTime = 14 days; } else if (_lock == Lock.sixMonths) { vestingTime = 30 days; } else if (_lock == Lock.twelveMonths) { vestingTime = 45 days; } } function calcualteVestedPrincipal(address _user, uint256 _depositId) public view virtual returns (uint256 amount) { UserInfo storage user = userInfo[_user][_depositId]; Lock _lock = user.lock; uint256 vestingEnd = user.lockedUntil + getVestingTime(_lock); uint256 vestingBegin = user.lockedUntil; if (block.timestamp >= vestingEnd || unlockAll) { amount = user.originalDepositAmount; } else if (block.timestamp > user.vestingLastUpdate) { amount = user.originalDepositAmount * (block.timestamp - user.vestingLastUpdate) / (vestingEnd - vestingBegin); } } function pendingRewardsPosition(address _user, uint256 _depositId) public view virtual returns (uint256 pending) { UserInfo storage user = userInfo[_user][_depositId]; uint256 _accMagicPerShare = accMagicPerShare; uint256 lpSupply = totalLpToken; (uint256 distributedRewards,) = getRealMagicReward(masterOfCoin.getPendingRewards(address(this))); _accMagicPerShare += distributedRewards * ONE / lpSupply; pending = ((user.lpAmount * _accMagicPerShare / ONE).toInt256() - user.rewardDebt).toUint256(); } function pendingRewardsAll(address _user) external view virtual returns (uint256 pending) { uint256 len = allUserDepositIds[_user].length(); for (uint256 i = 0; i < len; i++) { uint256 depositId = allUserDepositIds[_user].at(i); pending += pendingRewardsPosition(_user, depositId); } } function deposit(uint256 _amount, Lock _lock) public virtual updateRewards { (UserInfo storage user, uint256 depositId) = _addDeposit(msg.sender); (uint256 lockBoost, uint256 timelock) = getLockBoost(_lock); uint256 nftBoost = boosts[msg.sender]; uint256 lpAmount = _amount + _amount * (lockBoost + nftBoost) / ONE; magicTotalDeposits += _amount; totalLpToken += lpAmount; user.originalDepositAmount = _amount; user.depositAmount = _amount; user.lpAmount = lpAmount; user.lockedUntil = block.timestamp + timelock; user.vestingLastUpdate = user.lockedUntil; user.rewardDebt = (lpAmount * accMagicPerShare / ONE).toInt256(); user.lock = _lock; magic.safeTransferFrom(msg.sender, address(this), _amount); emit Deposit(msg.sender, depositId, _amount, _lock); } function withdrawPosition(uint256 _depositId, uint256 _amount) public virtual updateRewards returns (bool) { UserInfo storage user = userInfo[msg.sender][_depositId]; uint256 depositAmount = user.depositAmount; if (depositAmount == 0) return false; if (_amount > depositAmount) { _amount = depositAmount; } // anyone can withdraw if kill swith was used if (!unlockAll) { require(block.timestamp >= user.lockedUntil, "Position is still locked"); uint256 vestedAmount = _vestedPrincipal(msg.sender, _depositId); if (_amount > vestedAmount) { _amount = vestedAmount; } } // Effects uint256 ratio = _amount * ONE / depositAmount; uint256 lpAmount = user.lpAmount * ratio / ONE; totalLpToken -= lpAmount; magicTotalDeposits -= _amount; user.depositAmount -= _amount; user.lpAmount -= lpAmount; user.rewardDebt -= (lpAmount * accMagicPerShare / ONE).toInt256(); // Interactions magic.safeTransfer(msg.sender, _amount); emit Withdraw(msg.sender, _depositId, _amount); return true; } function withdrawAll() public virtual { uint256[] memory depositIds = allUserDepositIds[msg.sender].values(); for (uint256 i = 0; i < depositIds.length; i++) { withdrawPosition(depositIds[i], type(uint256).max); } } function harvestPosition(uint256 _depositId) public virtual updateRewards { UserInfo storage user = userInfo[msg.sender][_depositId]; int256 accumulatedMagic = (user.lpAmount * accMagicPerShare / ONE).toInt256(); uint256 _pendingMagic = (accumulatedMagic - user.rewardDebt).toUint256(); // Effects user.rewardDebt = accumulatedMagic; if (user.depositAmount == 0 && user.lpAmount == 0) { _removeDeposit(msg.sender, _depositId); } // Interactions if (_pendingMagic != 0) { magic.safeTransfer(msg.sender, _pendingMagic); } emit Harvest(msg.sender, _depositId, _pendingMagic); require(magic.balanceOf(address(this)) >= magicTotalDeposits, "Run on banks"); } function harvestAll() public virtual { uint256[] memory depositIds = allUserDepositIds[msg.sender].values(); for (uint256 i = 0; i < depositIds.length; i++) { harvestPosition(depositIds[i]); } } function withdrawAndHarvestPosition(uint256 _depositId, uint256 _amount) public virtual { withdrawPosition(_depositId, _amount); harvestPosition(_depositId); } function withdrawAndHarvestAll() public virtual { uint256[] memory depositIds = allUserDepositIds[msg.sender].values(); for (uint256 i = 0; i < depositIds.length; i++) { withdrawAndHarvestPosition(depositIds[i], type(uint256).max); } } function stakeTreasure(uint256 _tokenId, uint256 _amount) external virtual updateRewards { require(treasure != address(0), "Cannot stake Treasure"); require(_amount > 0, "Amount is 0"); treasureStaked[msg.sender][_tokenId] += _amount; treasureStakedAmount[msg.sender] += _amount; require(treasureStakedAmount[msg.sender] <= 20, "Max 20 treasures per wallet"); uint256 boost = getNftBoost(treasure, _tokenId, _amount); boosts[msg.sender] += boost; _recalculateLpAmount(msg.sender); IERC1155Upgradeable(treasure).safeTransferFrom(msg.sender, address(this), _tokenId, _amount, bytes("")); emit Staked(treasure, _tokenId, _amount, boosts[msg.sender]); } function unstakeTreasure(uint256 _tokenId, uint256 _amount) external virtual updateRewards { require(treasure != address(0), "Cannot stake Treasure"); require(_amount > 0, "Amount is 0"); require(treasureStaked[msg.sender][_tokenId] >= _amount, "Withdraw amount too big"); treasureStaked[msg.sender][_tokenId] -= _amount; treasureStakedAmount[msg.sender] -= _amount; uint256 boost = getNftBoost(treasure, _tokenId, _amount); boosts[msg.sender] -= boost; _recalculateLpAmount(msg.sender); IERC1155Upgradeable(treasure).safeTransferFrom(address(this), msg.sender, _tokenId, _amount, bytes("")); emit Unstaked(treasure, _tokenId, _amount, boosts[msg.sender]); } function stakeLegion(uint256 _tokenId) external virtual updateRewards { require(legion != address(0), "Cannot stake Legion"); require(legionStaked[msg.sender].add(_tokenId), "NFT already staked"); require(legionStaked[msg.sender].length() <= 3, "Max 3 legions per wallet"); if (isLegion1_1(_tokenId)) { require(!isLegion1_1Staked[msg.sender], "Max 1 1/1 legion per wallet"); isLegion1_1Staked[msg.sender] = true; } uint256 boost = getNftBoost(legion, _tokenId, 1); boosts[msg.sender] += boost; _recalculateLpAmount(msg.sender); IERC721Upgradeable(legion).transferFrom(msg.sender, address(this), _tokenId); emit Staked(legion, _tokenId, 1, boosts[msg.sender]); } function unstakeLegion(uint256 _tokenId) external virtual updateRewards { require(legionStaked[msg.sender].remove(_tokenId), "NFT is not staked"); if (isLegion1_1(_tokenId)) { isLegion1_1Staked[msg.sender] = false; } uint256 boost = getNftBoost(legion, _tokenId, 1); boosts[msg.sender] -= boost; _recalculateLpAmount(msg.sender); IERC721Upgradeable(legion).transferFrom(address(this), msg.sender, _tokenId); emit Unstaked(legion, _tokenId, 1, boosts[msg.sender]); } function isLegion1_1(uint256 _tokenId) public view virtual returns (bool) { try ILegionMetadataStore(legionMetadataStore).metadataForLegion(_tokenId) returns (ILegionMetadataStore.LegionMetadata memory metadata) { return metadata.legionGeneration == ILegionMetadataStore.LegionGeneration.GENESIS && metadata.legionRarity == ILegionMetadataStore.LegionRarity.LEGENDARY; } catch Error(string memory /*reason*/) { return false; } catch Panic(uint256) { return false; } catch (bytes memory /*lowLevelData*/) { return false; } } function getNftBoost(address _nft, uint256 _tokenId, uint256 _amount) public view virtual returns (uint256) { if (_nft == treasure) { return getTreasureBoost(_tokenId, _amount); } else if (_nft == legion) { try ILegionMetadataStore(legionMetadataStore).metadataForLegion(_tokenId) returns (ILegionMetadataStore.LegionMetadata memory metadata) { return getLegionBoost(uint256(metadata.legionGeneration), uint256(metadata.legionRarity)); } catch Error(string memory /*reason*/) { return 0; } catch Panic(uint256) { return 0; } catch (bytes memory /*lowLevelData*/) { return 0; } } return 0; } function _recalculateLpAmount(address _user) internal virtual { uint256 nftBoost = boosts[_user]; uint256[] memory depositIds = allUserDepositIds[_user].values(); for (uint256 i = 0; i < depositIds.length; i++) { uint256 depositId = depositIds[i]; UserInfo storage user = userInfo[_user][depositId]; (uint256 lockBoost,) = getLockBoost(user.lock); uint256 _amount = user.depositAmount; uint256 newlLpAmount = _amount + _amount * (lockBoost + nftBoost) / ONE; uint256 oldLpAmount = user.lpAmount; if (newlLpAmount > oldLpAmount) { uint256 lpDiff = newlLpAmount - oldLpAmount; user.rewardDebt += (lpDiff * accMagicPerShare / ONE).toInt256(); totalLpToken += lpDiff; user.lpAmount += lpDiff; } else if (newlLpAmount < oldLpAmount) { uint256 lpDiff = oldLpAmount - newlLpAmount; user.rewardDebt -= (lpDiff * accMagicPerShare / ONE).toInt256(); totalLpToken -= lpDiff; user.lpAmount -= lpDiff; } } } function addExcludedAddress(address _exclude) external virtual onlyRole(ATLAS_MINE_ADMIN_ROLE) updateRewards { require(excludedAddresses.add(_exclude), "Address already excluded"); } function removeExcludedAddress(address _excluded) external virtual onlyRole(ATLAS_MINE_ADMIN_ROLE) updateRewards { require(excludedAddresses.remove(_excluded), "Address is not excluded"); } function setUtilizationOverride(uint256 _utilizationOverride) external virtual onlyRole(ATLAS_MINE_ADMIN_ROLE) updateRewards { utilizationOverride = _utilizationOverride; } function setMagicToken(address _magic) external virtual onlyRole(ATLAS_MINE_ADMIN_ROLE) { magic = IERC20Upgradeable(_magic); } function setTreasure(address _treasure) external virtual onlyRole(ATLAS_MINE_ADMIN_ROLE) { treasure = _treasure; } function setLegion(address _legion) external virtual onlyRole(ATLAS_MINE_ADMIN_ROLE) { legion = _legion; } function setLegionMetadataStore(address _legionMetadataStore) external virtual onlyRole(ATLAS_MINE_ADMIN_ROLE) { legionMetadataStore = _legionMetadataStore; } function setLegionBoostMatrix(uint256[][] memory _legionBoostMatrix) external virtual onlyRole(ATLAS_MINE_ADMIN_ROLE) { legionBoostMatrix = _legionBoostMatrix; } /// @notice EMERGENCY ONLY function toggleUnlockAll() external virtual onlyRole(ATLAS_MINE_ADMIN_ROLE) updateRewards { unlockAll = unlockAll ? false : true; } function withdrawUndistributedRewards(address _to) external virtual onlyRole(ATLAS_MINE_ADMIN_ROLE) updateRewards { uint256 _totalUndistributedRewards = totalUndistributedRewards; totalUndistributedRewards = 0; magic.safeTransfer(_to, _totalUndistributedRewards); emit UndistributedRewardsWithdraw(_to, _totalUndistributedRewards); } function getTreasureBoost(uint256 _tokenId, uint256 _amount) public pure virtual returns (uint256 boost) { if (_tokenId == 39) { // Ancient Relic 8% boost = 75e15; } else if (_tokenId == 46) { // Bag of Rare Mushrooms 6.2% boost = 62e15; } else if (_tokenId == 47) { // Bait for Monsters 7.3% boost = 73e15; } else if (_tokenId == 48) { // Beetle-wing 0.8% boost = 8e15; } else if (_tokenId == 49) { // Blue Rupee 1.5% boost = 15e15; } else if (_tokenId == 51) { // Bottomless Elixir 7.6% boost = 76e15; } else if (_tokenId == 52) { // Cap of Invisibility 7.6% boost = 76e15; } else if (_tokenId == 53) { // Carriage 6.1% boost = 61e15; } else if (_tokenId == 54) { // Castle 7.3% boost = 71e15; } else if (_tokenId == 68) { // Common Bead 5.6% boost = 56e15; } else if (_tokenId == 69) { // Common Feather 3.4% boost = 34e15; } else if (_tokenId == 71) { // Common Relic 2.2% boost = 22e15; } else if (_tokenId == 72) { // Cow 5.8% boost = 58e15; } else if (_tokenId == 73) { // Diamond 0.8% boost = 8e15; } else if (_tokenId == 74) { // Divine Hourglass 6.3% boost = 63e15; } else if (_tokenId == 75) { // Divine Mask 5.7% boost = 57e15; } else if (_tokenId == 76) { // Donkey 1.2% boost = 12e15; } else if (_tokenId == 77) { // Dragon Tail 0.8% boost = 8e15; } else if (_tokenId == 79) { // Emerald 0.8% boost = 8e15; } else if (_tokenId == 82) { // Favor from the Gods 5.6% boost = 56e15; } else if (_tokenId == 91) { // Framed Butterfly 5.8% boost = 58e15; } else if (_tokenId == 92) { // Gold Coin 0.8% boost = 8e15; } else if (_tokenId == 93) { // Grain 3.2% boost = 32e15; } else if (_tokenId == 94) { // Green Rupee 3.3% boost = 33e15; } else if (_tokenId == 95) { // Grin 15.7% boost = 157e15; } else if (_tokenId == 96) { // Half-Penny 0.8% boost = 8e15; } else if (_tokenId == 97) { // Honeycomb 15.8% boost = 158e15; } else if (_tokenId == 98) { // Immovable Stone 7.2% boost = 72e15; } else if (_tokenId == 99) { // Ivory Breastpin 6.4% boost = 64e15; } else if (_tokenId == 100) { // Jar of Fairies 5.3% boost = 53e15; } else if (_tokenId == 103) { // Lumber 3% boost = 30e15; } else if (_tokenId == 104) { // Military Stipend 6.2% boost = 62e15; } else if (_tokenId == 105) { // Mollusk Shell 6.7% boost = 67e15; } else if (_tokenId == 114) { // Ox 1.6% boost = 16e15; } else if (_tokenId == 115) { // Pearl 0.8% boost = 8e15; } else if (_tokenId == 116) { // Pot of Gold 5.8% boost = 58e15; } else if (_tokenId == 117) { // Quarter-Penny 0.8% boost = 8e15; } else if (_tokenId == 132) { // Red Feather 6.4% boost = 64e15; } else if (_tokenId == 133) { // Red Rupee 0.8% boost = 8e15; } else if (_tokenId == 141) { // Score of Ivory 6% boost = 60e15; } else if (_tokenId == 151) { // Silver Coin 0.8% boost = 8e15; } else if (_tokenId == 152) { // Small Bird 6% boost = 60e15; } else if (_tokenId == 153) { // Snow White Feather 6.4% boost = 64e15; } else if (_tokenId == 161) { // Thread of Divine Silk 7.3% boost = 73e15; } else if (_tokenId == 162) { // Unbreakable Pocketwatch 5.9% boost = 59e15; } else if (_tokenId == 164) { // Witches Broom 5.1% boost = 51e15; } boost = boost * _amount; } function _vestedPrincipal(address _user, uint256 _depositId) internal virtual returns (uint256 amount) { amount = calcualteVestedPrincipal(_user, _depositId); UserInfo storage user = userInfo[_user][_depositId]; user.vestingLastUpdate = block.timestamp; } function _addDeposit(address _user) internal virtual returns (UserInfo storage user, uint256 newDepositId) { // start depositId from 1 newDepositId = ++currentId[_user]; allUserDepositIds[_user].add(newDepositId); user = userInfo[_user][newDepositId]; } function _removeDeposit(address _user, uint256 _depositId) internal virtual { require(allUserDepositIds[_user].remove(_depositId), 'depositId !exists'); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.10; interface IAtlasMineStaker { // ============= Events ============== event UserDeposit(address indexed user, uint256 amount); event UserWithdraw(address indexed user, uint256 indexed depositId, uint256 amount, uint256 reward); event UserClaim(address indexed user, uint256 indexed depositId, uint256 reward); event MineStake(uint256 currentDepositId, uint256 unlockTime); event MineHarvest(uint256 earned, uint256 feeEarned, uint256[] depositIds); event StakeNFT(address indexed user, address indexed nft, uint256 tokenId, uint256 amount, uint256 currentBoost); event UnstakeNFT(address indexed user, address indexed nft, uint256 tokenId, uint256 amount, uint256 currentBoost); event SetFee(uint256 fee); event StakingPauseToggle(bool paused); event SetMinimumStakingWait(uint256 wait); event SetAccrualWindows(uint256[] windows); event SetAccrualIncentive(uint256 reward); // ================= Data Types ================== struct Stake { uint256 amount; uint256 unlockAt; uint256 depositId; } struct UserStake { uint256 amount; uint256 unlockAt; int256 rewardDebt; } // =============== View Functions ================ function getUserStake(address user, uint256 depositId) external returns (UserStake memory); function userTotalStake(address user) external returns (uint256); function pendingRewards(address user, uint256 depositId) external returns (uint256); function pendingRewardsAll(address user) external returns (uint256); function totalMagic() external returns (uint256); function totalPendingStake() external returns (uint256); function totalWithdrawableMagic() external returns (uint256); function totalRewardsEarned() external returns (uint256); // ============= Staking Operations ============== function deposit(uint256 _amount) external; function withdraw(uint256 depositId, uint256 amount) external; function withdrawAll() external; function claim(uint256 depositId) external; function claimAll() external; function withdrawEmergency() external; function stakeScheduled() external; function accrue(uint256[] calldata depositIds) external; // ============= Hoard Operations ============== function stakeTreasure(uint256 _tokenId, uint256 _amount) external; function unstakeTreasure(uint256 _tokenId, uint256 _amount) external; function stakeLegion(uint256 _tokenId) external; function unstakeLegion(uint256 _tokenId) external; // ============= Owner Operations ============== function unstakeAllFromMine() external; function unstakeToTarget(uint256 target) external; function emergencyUnstakeAllFromMine() external; function setFee(uint256 _fee) external; function setHoard(address _hoard, bool isSet) external; function approveNFTs() external; function revokeNFTApprovals() external; function setMinimumStakingWait(uint256 wait) external; function toggleSchedulePause(bool paused) external; function withdrawFees() external; function setAccrualWindows(uint256[] calldata windows) external; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165Upgradeable { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC1155/utils/ERC1155Receiver.sol) pragma solidity ^0.8.0; import "../IERC1155ReceiverUpgradeable.sol"; import "../../../utils/introspection/ERC165Upgradeable.sol"; import "../../../proxy/utils/Initializable.sol"; /** * @dev _Available since v3.1._ */ abstract contract ERC1155ReceiverUpgradeable is Initializable, ERC165Upgradeable, IERC1155ReceiverUpgradeable { function __ERC1155Receiver_init() internal onlyInitializing { } function __ERC1155Receiver_init_unchained() internal onlyInitializing { } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165Upgradeable, IERC165Upgradeable) returns (bool) { return interfaceId == type(IERC1155ReceiverUpgradeable).interfaceId || super.supportsInterface(interfaceId); } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[50] private __gap; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (token/ERC1155/IERC1155Receiver.sol) pragma solidity ^0.8.0; import "../../utils/introspection/IERC165Upgradeable.sol"; /** * @dev _Available since v3.1._ */ interface IERC1155ReceiverUpgradeable is IERC165Upgradeable { /** * @dev Handles the receipt of a single ERC1155 token type. This function is * called at the end of a `safeTransferFrom` after the balance has been updated. * * NOTE: To accept the transfer, this must return * `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` * (i.e. 0xf23a6e61, or its own function selector). * * @param operator The address which initiated the transfer (i.e. msg.sender) * @param from The address which previously owned the token * @param id The ID of the token being transferred * @param value The amount of tokens being transferred * @param data Additional data with no specified format * @return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` if transfer is allowed */ function onERC1155Received( address operator, address from, uint256 id, uint256 value, bytes calldata data ) external returns (bytes4); /** * @dev Handles the receipt of a multiple ERC1155 token types. This function * is called at the end of a `safeBatchTransferFrom` after the balances have * been updated. * * NOTE: To accept the transfer(s), this must return * `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` * (i.e. 0xbc197c81, or its own function selector). * * @param operator The address which initiated the batch transfer (i.e. msg.sender) * @param from The address which previously owned the token * @param ids An array containing ids of each token being transferred (order and length must match values array) * @param values An array containing amounts of each token being transferred (order and length must match ids array) * @param data Additional data with no specified format * @return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` if transfer is allowed */ function onERC1155BatchReceived( address operator, address from, uint256[] calldata ids, uint256[] calldata values, bytes calldata data ) external returns (bytes4); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol) pragma solidity ^0.8.0; import "./IERC165Upgradeable.sol"; import "../../proxy/utils/Initializable.sol"; /** * @dev Implementation of the {IERC165} interface. * * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check * for the additional interface id that will be supported. For example: * * ```solidity * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); * } * ``` * * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation. */ abstract contract ERC165Upgradeable is Initializable, IERC165Upgradeable { function __ERC165_init() internal onlyInitializing { } function __ERC165_init_unchained() internal onlyInitializing { } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IERC165Upgradeable).interfaceId; } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[50] private __gap; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721Receiver.sol) pragma solidity ^0.8.0; /** * @title ERC721 token receiver interface * @dev Interface for any contract that wants to support safeTransfers * from ERC721 asset contracts. */ interface IERC721ReceiverUpgradeable { /** * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom} * by `operator` from `from`, this function is called. * * It must return its Solidity selector to confirm the token transfer. * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted. * * The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`. */ function onERC721Received( address operator, address from, uint256 tokenId, bytes calldata data ) external returns (bytes4); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) pragma solidity ^0.8.0; import "../proxy/utils/Initializable.sol"; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract ContextUpgradeable is Initializable { function __Context_init() internal onlyInitializing { } function __Context_init_unchained() internal onlyInitializing { } function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[50] private __gap; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (access/AccessControlEnumerable.sol) pragma solidity ^0.8.0; import "./IAccessControlEnumerableUpgradeable.sol"; import "./AccessControlUpgradeable.sol"; import "../utils/structs/EnumerableSetUpgradeable.sol"; import "../proxy/utils/Initializable.sol"; /** * @dev Extension of {AccessControl} that allows enumerating the members of each role. */ abstract contract AccessControlEnumerableUpgradeable is Initializable, IAccessControlEnumerableUpgradeable, AccessControlUpgradeable { function __AccessControlEnumerable_init() internal onlyInitializing { } function __AccessControlEnumerable_init_unchained() internal onlyInitializing { } using EnumerableSetUpgradeable for EnumerableSetUpgradeable.AddressSet; mapping(bytes32 => EnumerableSetUpgradeable.AddressSet) private _roleMembers; /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IAccessControlEnumerableUpgradeable).interfaceId || super.supportsInterface(interfaceId); } /** * @dev Returns one of the accounts that have `role`. `index` must be a * value between 0 and {getRoleMemberCount}, non-inclusive. * * Role bearers are not sorted in any particular way, and their ordering may * change at any point. * * WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure * you perform all queries on the same block. See the following * https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post] * for more information. */ function getRoleMember(bytes32 role, uint256 index) public view virtual override returns (address) { return _roleMembers[role].at(index); } /** * @dev Returns the number of accounts that have `role`. Can be used * together with {getRoleMember} to enumerate all bearers of a role. */ function getRoleMemberCount(bytes32 role) public view virtual override returns (uint256) { return _roleMembers[role].length(); } /** * @dev Overload {_grantRole} to track enumerable memberships */ function _grantRole(bytes32 role, address account) internal virtual override { super._grantRole(role, account); _roleMembers[role].add(account); } /** * @dev Overload {_revokeRole} to track enumerable memberships */ function _revokeRole(bytes32 role, address account) internal virtual override { super._revokeRole(role, account); _roleMembers[role].remove(account); } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[49] private __gap; }
// SPDX-License-Identifier: MIT pragma solidity 0.8.11; interface IMasterOfCoin { struct CoinStream { uint256 totalRewards; uint256 startTimestamp; uint256 endTimestamp; uint256 lastRewardTimestamp; uint256 ratePerSecond; uint256 paid; } function requestRewards() external returns (uint256 rewardsPaid); function grantTokenToStream(address _stream, uint256 _amount) external; function getStreams() external view returns (address[] memory); function getStreamConfig(address _stream) external view returns (CoinStream memory); function getGlobalRatePerSecond() external view returns (uint256 globalRatePerSecond); function getRatePerSecond(address _stream) external view returns (uint256 ratePerSecond); function getPendingRewards(address _stream) external view returns (uint256 pendingRewards); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.11; interface ILegionMetadataStore { struct LegionMetadata { LegionGeneration legionGeneration; LegionClass legionClass; LegionRarity legionRarity; uint8 questLevel; uint8 craftLevel; uint8[6] constellationRanks; } enum Constellation { FIRE, EARTH, WIND, WATER, LIGHT, DARK } enum LegionRarity { LEGENDARY, RARE, SPECIAL, UNCOMMON, COMMON, RECRUIT } enum LegionClass { RECRUIT, SIEGE, FIGHTER, ASSASSIN, RANGED, SPELLCASTER, RIVERMAN, NUMERAIRE, ALL_CLASS, ORIGIN } enum LegionGeneration { GENESIS, AUXILIARY, RECRUIT } // Sets the intial metadata for a token id. // Admin only. function setInitialMetadataForLegion(address _owner, uint256 _tokenId, LegionGeneration _generation, LegionClass _class, LegionRarity _rarity) external; // Increases the quest level by one. It is up to the calling contract to regulate the max quest level. No validation. // Admin only. function increaseQuestLevel(uint256 _tokenId) external; // Increases the craft level by one. It is up to the calling contract to regulate the max craft level. No validation. // Admin only. function increaseCraftLevel(uint256 _tokenId) external; // Increases the rank of the given constellation to the given number. It is up to the calling contract to regulate the max constellation rank. No validation. // Admin only. function increaseConstellationRank(uint256 _tokenId, Constellation _constellation, uint8 _to) external; // Returns the metadata for the given legion. function metadataForLegion(uint256 _tokenId) external view returns(LegionMetadata memory); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/IAccessControlEnumerable.sol) pragma solidity ^0.8.0; import "./IAccessControlUpgradeable.sol"; /** * @dev External interface of AccessControlEnumerable declared to support ERC165 detection. */ interface IAccessControlEnumerableUpgradeable is IAccessControlUpgradeable { /** * @dev Returns one of the accounts that have `role`. `index` must be a * value between 0 and {getRoleMemberCount}, non-inclusive. * * Role bearers are not sorted in any particular way, and their ordering may * change at any point. * * WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure * you perform all queries on the same block. See the following * https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post] * for more information. */ function getRoleMember(bytes32 role, uint256 index) external view returns (address); /** * @dev Returns the number of accounts that have `role`. Can be used * together with {getRoleMember} to enumerate all bearers of a role. */ function getRoleMemberCount(bytes32 role) external view returns (uint256); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (access/AccessControl.sol) pragma solidity ^0.8.0; import "./IAccessControlUpgradeable.sol"; import "../utils/ContextUpgradeable.sol"; import "../utils/StringsUpgradeable.sol"; import "../utils/introspection/ERC165Upgradeable.sol"; import "../proxy/utils/Initializable.sol"; /** * @dev Contract module that allows children to implement role-based access * control mechanisms. This is a lightweight version that doesn't allow enumerating role * members except through off-chain means by accessing the contract event logs. Some * applications may benefit from on-chain enumerability, for those cases see * {AccessControlEnumerable}. * * Roles are referred to by their `bytes32` identifier. These should be exposed * in the external API and be unique. The best way to achieve this is by * using `public constant` hash digests: * * ``` * bytes32 public constant MY_ROLE = keccak256("MY_ROLE"); * ``` * * Roles can be used to represent a set of permissions. To restrict access to a * function call, use {hasRole}: * * ``` * function foo() public { * require(hasRole(MY_ROLE, msg.sender)); * ... * } * ``` * * Roles can be granted and revoked dynamically via the {grantRole} and * {revokeRole} functions. Each role has an associated admin role, and only * accounts that have a role's admin role can call {grantRole} and {revokeRole}. * * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means * that only accounts with this role will be able to grant or revoke other * roles. More complex role relationships can be created by using * {_setRoleAdmin}. * * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to * grant and revoke this role. Extra precautions should be taken to secure * accounts that have been granted it. */ abstract contract AccessControlUpgradeable is Initializable, ContextUpgradeable, IAccessControlUpgradeable, ERC165Upgradeable { function __AccessControl_init() internal onlyInitializing { } function __AccessControl_init_unchained() internal onlyInitializing { } struct RoleData { mapping(address => bool) members; bytes32 adminRole; } mapping(bytes32 => RoleData) private _roles; bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00; /** * @dev Modifier that checks that an account has a specific role. Reverts * with a standardized message including the required role. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ * * _Available since v4.1._ */ modifier onlyRole(bytes32 role) { _checkRole(role, _msgSender()); _; } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IAccessControlUpgradeable).interfaceId || super.supportsInterface(interfaceId); } /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole(bytes32 role, address account) public view virtual override returns (bool) { return _roles[role].members[account]; } /** * @dev Revert with a standard message if `account` is missing `role`. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ */ function _checkRole(bytes32 role, address account) internal view virtual { if (!hasRole(role, account)) { revert( string( abi.encodePacked( "AccessControl: account ", StringsUpgradeable.toHexString(uint160(account), 20), " is missing role ", StringsUpgradeable.toHexString(uint256(role), 32) ) ) ); } } /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) { return _roles[role].adminRole; } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) { _grantRole(role, account); } /** * @dev Revokes `role` from `account`. * * If `account` had been granted `role`, emits a {RoleRevoked} event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) { _revokeRole(role, account); } /** * @dev Revokes `role` from the calling account. * * Roles are often managed via {grantRole} and {revokeRole}: this function's * purpose is to provide a mechanism for accounts to lose their privileges * if they are compromised (such as when a trusted device is misplaced). * * If the calling account had been revoked `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `account`. */ function renounceRole(bytes32 role, address account) public virtual override { require(account == _msgSender(), "AccessControl: can only renounce roles for self"); _revokeRole(role, account); } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. Note that unlike {grantRole}, this function doesn't perform any * checks on the calling account. * * [WARNING] * ==== * This function should only be called from the constructor when setting * up the initial roles for the system. * * Using this function in any other way is effectively circumventing the admin * system imposed by {AccessControl}. * ==== * * NOTE: This function is deprecated in favor of {_grantRole}. */ function _setupRole(bytes32 role, address account) internal virtual { _grantRole(role, account); } /** * @dev Sets `adminRole` as ``role``'s admin role. * * Emits a {RoleAdminChanged} event. */ function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual { bytes32 previousAdminRole = getRoleAdmin(role); _roles[role].adminRole = adminRole; emit RoleAdminChanged(role, previousAdminRole, adminRole); } /** * @dev Grants `role` to `account`. * * Internal function without access restriction. */ function _grantRole(bytes32 role, address account) internal virtual { if (!hasRole(role, account)) { _roles[role].members[account] = true; emit RoleGranted(role, account, _msgSender()); } } /** * @dev Revokes `role` from `account`. * * Internal function without access restriction. */ function _revokeRole(bytes32 role, address account) internal virtual { if (hasRole(role, account)) { _roles[role].members[account] = false; emit RoleRevoked(role, account, _msgSender()); } } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[49] private __gap; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol) pragma solidity ^0.8.0; /** * @dev External interface of AccessControl declared to support ERC165 detection. */ interface IAccessControlUpgradeable { /** * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole` * * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite * {RoleAdminChanged} not being emitted signaling this. * * _Available since v3.1._ */ event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole); /** * @dev Emitted when `account` is granted `role`. * * `sender` is the account that originated the contract call, an admin role * bearer except when using {AccessControl-_setupRole}. */ event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender); /** * @dev Emitted when `account` is revoked `role`. * * `sender` is the account that originated the contract call: * - if using `revokeRole`, it is the admin role bearer * - if using `renounceRole`, it is the role bearer (i.e. `account`) */ event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender); /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole(bytes32 role, address account) external view returns (bool); /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {AccessControl-_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) external view returns (bytes32); /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function grantRole(bytes32 role, address account) external; /** * @dev Revokes `role` from `account`. * * If `account` had been granted `role`, emits a {RoleRevoked} event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function revokeRole(bytes32 role, address account) external; /** * @dev Revokes `role` from the calling account. * * Roles are often managed via {grantRole} and {revokeRole}: this function's * purpose is to provide a mechanism for accounts to lose their privileges * if they are compromised (such as when a trusted device is misplaced). * * If the calling account had been granted `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `account`. */ function renounceRole(bytes32 role, address account) external; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Strings.sol) pragma solidity ^0.8.0; /** * @dev String operations. */ library StringsUpgradeable { bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef"; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT licence // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { if (value == 0) { return "0x00"; } uint256 temp = value; uint256 length = 0; while (temp != 0) { length++; temp >>= 8; } return toHexString(value, length); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _HEX_SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } }
{ "metadata": { "bytecodeHash": "none" }, "optimizer": { "enabled": true, "runs": 200 }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "libraries": {} }
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"earned","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"feeEarned","type":"uint256"},{"indexed":false,"internalType":"uint256[]","name":"depositIds","type":"uint256[]"}],"name":"MineHarvest","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"currentDepositId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"unlockTime","type":"uint256"}],"name":"MineStake","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"reward","type":"uint256"}],"name":"SetAccrualIncentive","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256[]","name":"windows","type":"uint256[]"}],"name":"SetAccrualWindows","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"fee","type":"uint256"}],"name":"SetFee","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"wait","type":"uint256"}],"name":"SetMinimumStakingWait","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"address","name":"nft","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"currentBoost","type":"uint256"}],"name":"StakeNFT","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"paused","type":"bool"}],"name":"StakingPauseToggle","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"address","name":"nft","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"currentBoost","type":"uint256"}],"name":"UnstakeNFT","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"uint256","name":"depositId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"reward","type":"uint256"}],"name":"UserClaim","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"UserDeposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"uint256","name":"depositId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"reward","type":"uint256"}],"name":"UserWithdraw","type":"event"},{"inputs":[],"name":"FEE_DENOMINATOR","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_FEE","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ONE","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"accRewardsPerShare","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"accrualWindows","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"depositIds","type":"uint256[]"}],"name":"accrue","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"approveNFTs","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"depositId","type":"uint256"}],"name":"claim","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"claimAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"currentId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"deposit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"emergencyUnstakeAllFromMine","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"fee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"feeReserve","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"uint256","name":"depositId","type":"uint256"}],"name":"getUserStake","outputs":[{"components":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"unlockAt","type":"uint256"},{"internalType":"int256","name":"rewardDebt","type":"int256"}],"internalType":"struct IAtlasMineStaker.UserStake","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC20Upgradeable","name":"_magic","type":"address"},{"internalType":"contract AtlasMine","name":"_mine","type":"address"},{"internalType":"enum AtlasMine.Lock","name":"_lock","type":"uint8"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"lastDepositId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lastStakeTimestamp","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"legionsStaked","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lock","outputs":[{"internalType":"enum AtlasMine.Lock","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"locktime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"magic","outputs":[{"internalType":"contract IERC20Upgradeable","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"mine","outputs":[{"internalType":"contract AtlasMine","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"minimumStakingWait","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"nextActiveStake","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256[]","name":"","type":"uint256[]"},{"internalType":"uint256[]","name":"","type":"uint256[]"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"onERC1155BatchReceived","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"onERC1155Received","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"onERC721Received","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"uint256","name":"depositId","type":"uint256"}],"name":"pendingRewards","outputs":[{"internalType":"uint256","name":"reward","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"pendingRewardsAll","outputs":[{"internalType":"uint256","name":"reward","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"pendingStakes","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amountToReserve","type":"uint256"}],"name":"reserveWithdrawerRewards","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"revokeNFTApprovals","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"schedulePaused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"windows","type":"uint256[]"}],"name":"setAccrualWindows","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_reward","type":"uint256"}],"name":"setAccrueIncentive","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_fee","type":"uint256"}],"name":"setFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_hoard","type":"address"},{"internalType":"bool","name":"isSet","type":"bool"}],"name":"setHoard","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"wait","type":"uint256"}],"name":"setMinimumStakingWait","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"stakeLegion","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"stakeScheduled","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"stakeTreasure","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"stakes","outputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"unlockAt","type":"uint256"},{"internalType":"uint256","name":"depositId","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bool","name":"paused","type":"bool"}],"name":"toggleSchedulePause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"tokenBuffer","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalMagic","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalPendingStake","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalRewardsEarned","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalStaked","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalWithdrawableMagic","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"address","name":"","type":"address"}],"name":"treasuresStaked","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"unstakeAllFromMine","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"unstakeLegion","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"target","type":"uint256"}],"name":"unstakeToTarget","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"unstakeTreasure","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"unstakedDeposits","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"userStake","outputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"unlockAt","type":"uint256"},{"internalType":"int256","name":"rewardDebt","type":"int256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"userTotalStake","outputs":[{"internalType":"uint256","name":"totalStake","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"depositId","type":"uint256"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"withdrawAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"withdrawEmergency","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"withdrawFees","outputs":[],"stateMutability":"nonpayable","type":"function"}]
Contract Creation Code
60806040523480156200001157600080fd5b50600054610100900460ff166200002f5760005460ff161562000039565b62000039620000de565b620000a15760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b606482015260840160405180910390fd5b600054610100900460ff16158015620000c4576000805461ffff19166101011790555b8015620000d7576000805461ff00191690555b506200010b565b6000620000f630620000fc60201b620033831760201c565b15905090565b6001600160a01b03163b151590565b6151b3806200011b6000396000f3fe608060405234801561001057600080fd5b50600436106103e65760003560e01c8063853828b61161020a578063c6e0c6f311610125578063e2a2189a116100b8578063f23a6e6111610087578063f23a6e6114610889578063f2fde38b146108a8578063f523f33d146108bb578063f83d08ba146108ce578063fbefccfc146108f057600080fd5b8063e2a2189a14610836578063e55b7e7314610849578063f0f9e97514610875578063f15576a61461087f57600080fd5b8063d73792a9116100f4578063d73792a914610811578063ddca3f431461081a578063dfce204a14610824578063e25788691461082e57600080fd5b8063c6e0c6f3146107b8578063cec695fa146107c1578063d1058e59146107f6578063d5a44f86146107fe57600080fd5b8063adc43af21161019d578063bc197c811161016c578063bc197c8114610768578063c218b3c114610787578063c2ee3a081461079a578063c515a87a146107ae57600080fd5b8063adc43af214610723578063b2f2b8b214610744578063b6b55f251461074c578063bc063e1a1461075f57600080fd5b80638decd389116101d95780638decd389146106e1578063968f6ca3146106f457806399f4b251146106fc578063a7ff2aaf1461071057600080fd5b8063853828b6146106ad57806389232a00146106b55780638b7e9367146106c85780638da5cb5b146106d057600080fd5b8063476343ee1161030557806361c533b411610298578063715018a611610267578063715018a614610674578063789ff0e11461067c5780637cbaccd5146106865780637fba3f0114610690578063817b1cd2146106a357600080fd5b806361c533b414610631578063678887961461063b57806369fe0e2d1461064e5780636f3d3a961461066157600080fd5b806359fe213b116102d457806359fe213b146105e55780635b91c512146105f85780635ebbd9f51461060b5780636099ecb21461061e57600080fd5b8063476343ee146105b657806348cbdee7146105be5780634e3c0770146105c85780635760215c146105d257600080fd5b80632bf968531161037d5780633bc031471161034c5780633bc03147146105805780634146a073146105885780634305443d14610590578063441a3e70146105a357600080fd5b80632bf96853146104da578063379607f5146104ed578063389077e5146105005780633937ea4f1461052a57600080fd5b806317640841116103b9578063176408411461048e57806320dbbee4146104a357806321d8309b146104ab5780632299b8fa146104b957600080fd5b806301ffc9a7146103eb5780630d8546461461041357806310f811a81461043f578063150b7a0214610457575b600080fd5b6103fe6103f9366004614808565b6108f8565b60405190151581526020015b60405180910390f35b61015f54610427906001600160a01b031681565b6040516001600160a01b03909116815260200161040a565b6104496101685481565b60405190815260200161040a565b6104756104653660046148fe565b630a85bd0160e11b949350505050565b6040516001600160e01b0319909116815260200161040a565b6104a161049c36600461496a565b61092f565b005b6104a1610c5d565b610162546103fe9060ff1681565b6104496104c736600461498c565b61016d6020526000908152604090205481565b6104a16104e836600461496a565b610e47565b6104a16104fb3660046149a9565b61110c565b61042761050e3660046149a9565b61016f602052600090815260409020546001600160a01b031681565b6105656105383660046149c2565b61016b60209081526000928352604080842090915290825290208054600182015460029092015490919083565b6040805193845260208401929092529082015260600161040a565b6104a16111dd565b6104a1611315565b61044961059e3660046149a9565b6114e4565b6104a16105b136600461496a565b611506565b6104a161160a565b6104496101735481565b6104496101745481565b6104a16105e03660046149a9565b611656565b6104496105f336600461498c565b61170f565b61044961060636600461498c565b6117e2565b6104a16106193660046149a9565b611883565b61044961062c3660046149c2565b6118b6565b6104496101615481565b6104a16106493660046149a9565b61193e565b6104a161065c3660046149a9565b611c48565b6104a161066f3660046149a9565b611ce7565b6104a1611dde565b6104496101725481565b61044961016a5481565b6104a161069e3660046149fc565b611e14565b6104496101665481565b6104a1611e80565b6104a16106c3366004614a26565b612028565b610449612324565b6033546001600160a01b0316610427565b6104a16106ef366004614a71565b6124d7565b6104a1612761565b61016054610427906001600160a01b031681565b6104a161071e366004614ae6565b612848565b6104496107313660046149a9565b6101636020526000908152604090205481565b6104a16128e4565b6104a161075a3660046149a9565b612916565b610449610bb881565b610475610776366004614b94565b63bc197c8160e01b95945050505050565b6104a1610795366004614a71565b612b0d565b6104496c0c9f2c9cd04674edea4000000081565b6104496101765481565b61017354610449565b6107d46107cf3660046149c2565b612c5e565b604080518251815260208084015190820152918101519082015260600161040a565b6104a1612cd1565b61056561080c3660046149a9565b612de2565b61044961271081565b6104496101715481565b6104496101655481565b6104a1612e16565b6104a16108443660046149a9565b612f23565b610449610857366004614c42565b61017060209081526000928352604080842090915290825290205481565b6104496101645481565b6104496101695481565b610475610897366004614c67565b63f23a6e6160e01b95945050505050565b6104a16108b636600461498c565b6131c2565b6104a16108c93660046149a9565b61325a565b610160546108e390600160a01b900460ff1681565b60405161040a9190614d08565b6104496132fe565b60006001600160e01b03198216630271189760e51b148061092957506301ffc9a760e01b6001600160e01b03198316145b92915050565b33600090815261016e602052604090205460ff166109685760405162461bcd60e51b815260040161095f90614d16565b60405180910390fd5b61016054604080516372907e3f60e11b815290516000926001600160a01b03169163e520fc7e9160048083019260209291908290030181865afa1580156109b3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109d79190614d39565b604051627eeac760e11b81523360048201526024810185905290915082906001600160a01b0383169062fdd58e90604401602060405180830381865afa158015610a25573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a499190614d56565b1015610a8e5760405162461bcd60e51b81526020600482015260146024820152734e6f7420656e6f7567682074726561737572657360601b604482015260640161095f565b60008381526101706020908152604080832033845290915281208054849290610ab8908490614d85565b909155505060408051602081018252600081529051637921219560e11b81526001600160a01b0383169163f242432a91610afd91339130918991899190600401614df5565b600060405180830381600087803b158015610b1757600080fd5b505af1158015610b2b573d6000803e3d6000fd5b505061016054604051631764084160e01b815260048101879052602481018690526001600160a01b03909116925063176408419150604401600060405180830381600087803b158015610b7d57600080fd5b505af1158015610b91573d6000803e3d6000fd5b505061016054604051637ed5e4c360e11b8152306004820152600093506001600160a01b03909116915063fdabc98690602401602060405180830381865afa158015610be1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c059190614d56565b60408051868152602081018690529081018290529091506001600160a01b0383169033907f445021060a8a0b3b37d1550cc97c32b6c43b4f5b93643c954bd0d92323dadd49906060015b60405180910390a350505050565b6033546001600160a01b03163314610c875760405162461bcd60e51b815260040161095f90614e2f565b61016054604080516372907e3f60e11b815290516000926001600160a01b03169163e520fc7e9160048083019260209291908290030181865afa158015610cd2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610cf69190614d39565b6101605460405163a22cb46560e01b81526001600160a01b0391821660048201526000602482015291925082169063a22cb46590604401600060405180830381600087803b158015610d4757600080fd5b505af1158015610d5b573d6000803e3d6000fd5b50505050600061016060009054906101000a90046001600160a01b03166001600160a01b031663675857eb6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610db5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610dd99190614d39565b6101605460405163a22cb46560e01b81526001600160a01b0391821660048201526000602482015291925082169063a22cb465906044015b600060405180830381600087803b158015610e2b57600080fd5b505af1158015610e3f573d6000803e3d6000fd5b505050505050565b33600090815261016e602052604090205460ff16610e775760405162461bcd60e51b815260040161095f90614d16565b600082815261017060209081526040808320338452909152902054811115610ed85760405162461bcd60e51b81526020600482015260146024820152734e6f7420656e6f7567682074726561737572657360601b604482015260640161095f565b60008281526101706020908152604080832033845290915281208054839290610f02908490614e64565b909155505061016054604080516372907e3f60e11b815290516000926001600160a01b03169163e520fc7e9160048083019260209291908290030181865afa158015610f52573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f769190614d39565b61016054604051632bf9685360e01b815260048101869052602481018590529192506001600160a01b031690632bf9685390604401600060405180830381600087803b158015610fc557600080fd5b505af1158015610fd9573d6000803e3d6000fd5b505061016054604051637ed5e4c360e11b8152306004820152600093506001600160a01b03909116915063fdabc98690602401602060405180830381865afa158015611029573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061104d9190614d56565b60408051602081018252600081529051637921219560e11b81529192506001600160a01b0384169163f242432a9161108f91309133918a918a91600401614df5565b600060405180830381600087803b1580156110a957600080fd5b505af11580156110bd573d6000803e3d6000fd5b505060408051878152602081018790529081018490526001600160a01b03851692503391507f629771fb40d78403cabd62586e2e57799a03937a15bde2af3fe5cdff8811aa0290606001610c4f565b600261012d5414156111305760405162461bcd60e51b815260040161095f90614e7b565b600261012d5561113e613392565b1561115b5760405162461bcd60e51b815260040161095f90614eb2565b33600090815261016b60209081526040808320848452909152902080546111b15760405162461bcd60e51b815260206004820152600a602482015269139bc819195c1bdcda5d60b21b604482015260640161095f565b6111d3336111bf8385613497565b61015f546001600160a01b03169190613590565b5050600161012d55565b6033546001600160a01b031633146112075760405162461bcd60e51b815260040161095f90614e2f565b61016754610176545b81811015611309576000610167828154811061122e5761122e614edd565b6000918252602091829020604080516060810182526003909302909101805483526001810154938301849052600201549082015291504210156112715750611309565b610160546040808301518351915163d82b99d760e01b81526001600160a01b039093169263d82b99d7926112b19291600401918252602082015260400190565b6020604051808303816000875af11580156112d0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112f49190614ef3565b5050808061130190614f10565b915050611210565b506113126135f3565b50565b600261012d5414156113395760405162461bcd60e51b815260040161095f90614e7b565b600261012d556101625460ff1661138b5760405162461bcd60e51b81526020600482015260166024820152754e6f7420696e20656d657267656e637920737461746560501b604482015260640161095f565b33600090815261016c6020526040812081906113a690613680565b805190915060005b8181101561141d5733600090815261016b60205260408120845182908690859081106113dc576113dc614edd565b6020026020010151815260200190815260200160002090508060000154856114049190614d85565b600090915593508061141581614f10565b9150506113ae565b50611426613694565b83111561146b5760405162461bcd60e51b8152602060048201526013602482015272139bdd08195b9bdd59da081d5b9cdd185ad959606a1b604482015260640161095f565b82610166600082825461147e9190614e64565b909155505061015f5461149b906001600160a01b03163385613590565b604080518481526000602082018190529133917f5706e30facf103fa63b976a5142c96bb88e65a98f82412f1ddbef60ba7169557910160405180910390a35050600161012d5550565b61017781815481106114f557600080fd5b600091825260209091200154905081565b600261012d54141561152a5760405162461bcd60e51b815260040161095f90614e7b565b600261012d55611538613392565b156115555760405162461bcd60e51b815260040161095f90614eb2565b33600090815261016b60209081526040808320858452909152902080546115ab5760405162461bcd60e51b815260206004820152600a602482015269139bc819195c1bdcda5d60b21b604482015260640161095f565b80600101544210156115f05760405162461bcd60e51b815260206004820152600e60248201526d11195c1bdcda5d081b1bd8dad95960921b604482015260640161095f565b6115ff336111bf83868661372b565b5050600161012d5550565b6033546001600160a01b031633146116345760405162461bcd60e51b815260040161095f90614e2f565b6101728054600090915561015f54611312906001600160a01b03163383613590565b6033546001600160a01b031633146116805760405162461bcd60e51b815260040161095f90614e2f565b612a308110156116d25760405162461bcd60e51b815260206004820152601860248201527f4d696e696d756d20696e74657276616c203320686f7572730000000000000000604482015260640161095f565b6101658190556040518181527f3628c455eddf4b14c33ab0c7b1e76947f8f9243c3607c8a8d636f2bfc6c64f7c906020015b60405180910390a150565b6001600160a01b038116600090815261016c60205260408120819061173390613680565b805190915060005b818110156117da576001600160a01b038516600090815261016b602052604081208451829086908590811061177257611772614edd565b6020026020010151815260200190815260200160002090506000816000015411156117c7576117ba868584815181106117ad576117ad614edd565b60200260200101516118b6565b6117c49086614d85565b94505b50806117d281614f10565b91505061173b565b505050919050565b6001600160a01b038116600090815261016c60205260408120819061180690613680565b805190915060005b818110156117da576001600160a01b038516600090815261016b602052604081208451829086908590811061184557611845614edd565b60200260200101518152602001908152602001600020905080600001548561186d9190614d85565b945050808061187b90614f10565b91505061180e565b6033546001600160a01b031633146118ad5760405162461bcd60e51b815260040161095f90614e2f565b6113128161389c565b6001600160a01b038216600090815261016b60209081526040808320848452909152812080546118ea576000915050610929565b60006118f98260000154613b3c565b90508160020154811361191157600092505050610929565b61193560018360020154836119269190614f2b565b6119309190614f2b565b613b6d565b95945050505050565b33600090815261016e602052604090205460ff1661196e5760405162461bcd60e51b815260040161095f90614d16565b610160546040805163675857eb60e01b815290516000926001600160a01b03169163675857eb9160048083019260209291908290030181865afa1580156119b9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119dd9190614d39565b6040516331a9108f60e11b81526004810184905290915033906001600160a01b03831690636352211e90602401602060405180830381865afa158015611a27573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a4b9190614d39565b6001600160a01b031614611a975760405162461bcd60e51b81526020600482015260136024820152722737ba1037bbb732b91037b3103632b3b4b7b760691b604482015260640161095f565b600082815261016f60205260409081902080546001600160a01b031916339081179091559051632142170760e11b81526004810191909152306024820152604481018390526001600160a01b038216906342842e0e90606401600060405180830381600087803b158015611b0a57600080fd5b505af1158015611b1e573d6000803e3d6000fd5b5050610160546040516333c443cb60e11b8152600481018690526001600160a01b03909116925063678887969150602401600060405180830381600087803b158015611b6957600080fd5b505af1158015611b7d573d6000803e3d6000fd5b505061016054604051637ed5e4c360e11b8152306004820152600093506001600160a01b03909116915063fdabc98690602401602060405180830381865afa158015611bcd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611bf19190614d56565b60408051858152600160208201529081018290529091506001600160a01b0383169033907f445021060a8a0b3b37d1550cc97c32b6c43b4f5b93643c954bd0d92323dadd49906060015b60405180910390a3505050565b6033546001600160a01b03163314611c725760405162461bcd60e51b815260040161095f90614e2f565b610bb8811115611cb25760405162461bcd60e51b815260206004820152600b60248201526a496e76616c69642066656560a81b604482015260640161095f565b6101718190556040518181527e172ddfc5ae88d08b3de01a5a187667c37a5a53989e8c175055cb6c993792a790602001611704565b6033546001600160a01b03163314611d115760405162461bcd60e51b815260040161095f90614e2f565b6101785460ff1615611d5c5760405162461bcd60e51b81526020600482015260146024820152731c995cd95d08185b1c9958591e4818d85b1b195960621b604482015260640161095f565b610178805460ff191660011790556101728054829190600090611d80908490614d85565b92505081905550806101696000828254611d9a9190614e64565b909155505061016654611dba6c0c9f2c9cd04674edea4000000083614f6a565b611dc49190614f9f565b61016a6000828254611dd69190614e64565b909155505050565b6033546001600160a01b03163314611e085760405162461bcd60e51b815260040161095f90614e2f565b611e126000613bc3565b565b6033546001600160a01b03163314611e3e5760405162461bcd60e51b815260040161095f90614e2f565b610162805460ff19168215159081179091556040519081527fd91a3caa631863cc5c7546306076bad138b7817bceff3bed5640e149b356b79b90602001611704565b600261012d541415611ea45760405162461bcd60e51b815260040161095f90614e7b565b600261012d55611eb2613392565b15611ecf5760405162461bcd60e51b815260040161095f90614eb2565b33600090815261016c60205260408120611ee890613680565b805190915060005b81811015611fb45733600090815261016b6020526040812084518290869085908110611f1e57611f1e614edd565b60200260200101518152602001908152602001600020905060008160000154118015611f4e575060008160010154115b8015611f5e575042816001015411155b15611fa157611f8981858481518110611f7957611f79614edd565b602002602001015160001961372b565b6101746000828254611f9b9190614d85565b90915550505b5080611fac81614f10565b915050611ef0565b506101748054600090915561015f54611fd7906001600160a01b03163383613590565b505050610174546000146120205760405162461bcd60e51b815260206004820152601060248201526f213ab33332b9103737ba1031b632b0b960811b604482015260640161095f565b600161012d55565b600054610100900460ff166120435760005460ff1615612047565b303b155b6120aa5760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b606482015260840161095f565b600054610100900460ff161580156120cc576000805461ffff19166101011790555b6001600160a01b0384166121225760405162461bcd60e51b815260206004820152601b60248201527f496e76616c6964206d6167696320746f6b656e20616464726573730000000000604482015260640161095f565b6001600160a01b0383166121785760405162461bcd60e51b815260206004820152601d60248201527f496e76616c6964206d696e6520636f6e74726163742061646472657373000000604482015260640161095f565b612180613c15565b612188613c15565b612190613c3c565b612198613c6b565b61015f80546001600160a01b038087166001600160a01b031992831617909255610160805492861691831682178155849290916001600160a81b031990911617600160a01b8360048111156121ef576121ef614cd0565b021790555061016054604051630293519f60e21b81526000916001600160a01b03811691630a4d467c9161223191600160a01b90910460ff1690600401614d08565b6040805180830381865afa15801561224d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122719190614fb3565b610161819055426101645561a8c06101655561015f546101605460405163095ea7b360e01b81526001600160a01b039182166004820152600019602482015292945016915063095ea7b3906044016020604051808303816000875af11580156122de573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123029190614ef3565b5061230b613c9a565b50801561231e576000805461ff00191690555b50505050565b610160546040516359fe213b60e01b815230600482015260009182916001600160a01b03909116906359fe213b90602401602060405180830381865afa92505050801561238e575060408051601f3d908101601f1916820190925261238b91810190614d56565b60015b6123cc5761239a614fd7565b634e487b7114156123c2576123ad614ff3565b906123b857506123c2565b60009150506123cf565b3d6000803e3d6000fd5b90505b6101675461017654600091905b818110156124b0576101605461016780546001600160a01b0390921691636902bd109130918590811061241157612411614edd565b60009182526020909120600260039092020101546040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526024820152604401602060405180830381865afa15801561246e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124929190614d56565b61249c9084614d85565b9250806124a881614f10565b9150506123dc565b5081836124bb613694565b6124c59190614d85565b6124cf9190614d85565b935050505090565b6033546001600160a01b031633146125015760405162461bcd60e51b815260040161095f90614e2f565b61250c600282615013565b156125515760405162461bcd60e51b8152602060048201526015602482015274092dcecc2d8d2c840eed2dcc8deee40d8cadccee8d605b1b604482015260640161095f565b600581106125945760405162461bcd60e51b815260206004820152601060248201526f546f6f206d616e792077696e646f777360801b604482015260640161095f565b60005b81811015612715576125aa600183614e64565b8110156126155760188383838181106125c5576125c5614edd565b90506020020135106126105760405162461bcd60e51b8152602060048201526014602482015273496e76616c69642077696e646f772076616c756560601b604482015260640161095f565b612674565b601983838381811061262957612629614edd565b90506020020135106126745760405162461bcd60e51b8152602060048201526014602482015273496e76616c69642077696e646f772076616c756560601b604482015260640161095f565b8015612703578282612687600184614e64565b81811061269657612696614edd565b905060200201358383838181106126af576126af614edd565b90506020020135116127035760405162461bcd60e51b815260206004820152601760248201527f496e76616c69642077696e646f77206f72646572696e67000000000000000000604482015260640161095f565b8061270d81614f10565b915050612597565b5061272361017783836147b1565b507ff4723bfb452649bf3bd2d8e53208ac54815257e595b007790cc84b03c22c53508282604051612755929190615027565b60405180910390a15050565b6033546001600160a01b0316331461278b5760405162461bcd60e51b815260040161095f90614e2f565b6101625460ff166127d75760405162461bcd60e51b81526020600482015260166024820152754e6f7420696e20656d657267656e637920737461746560501b604482015260640161095f565b61016060009054906101000a90046001600160a01b03166001600160a01b031663853828b66040518163ffffffff1660e01b8152600401600060405180830381600087803b15801561282857600080fd5b505af115801561283c573d6000803e3d6000fd5b50505050611e126135f3565b6033546001600160a01b031633146128725760405162461bcd60e51b815260040161095f90614e2f565b6001600160a01b0382166128b85760405162461bcd60e51b815260206004820152600d60248201526c125b9d985b1a59081a1bd85c99609a1b604482015260640161095f565b6001600160a01b0391909116600090815261016e60205260409020805460ff1916911515919091179055565b6033546001600160a01b0316331461290e5760405162461bcd60e51b815260040161095f90614e2f565b611e12613c9a565b600261012d54141561293a5760405162461bcd60e51b815260040161095f90614e7b565b600261012d55612948613392565b156129655760405162461bcd60e51b815260040161095f90614eb2565b6101625460ff16156129ae5760405162461bcd60e51b81526020600482015260126024820152711b995dc81cdd185ada5b99c81c185d5cd95960721b604482015260640161095f565b600081116129f15760405162461bcd60e51b815260206004820152601060248201526f04465706f73697420616d6f756e7420360841b604482015260640161095f565b33600090815261016d6020526040812080548290612a0e90614f10565b918290555033600090815261016c60205260409020909150612a309082613e28565b5033600090815261016b60209081526040808320848452909152902082815561016154612a5d9042614d85565b612a6a9062015180614d85565b60018201558054612a7a90613b3c565b8160020181905550826101666000828254612a959190614d85565b92505081905550826101736000828254612aaf9190614d85565b909155505061015f54612acd906001600160a01b0316333086613e34565b60405183815233907f35db3d768e685509e031bae369804ca7dc6656af739e079f1d3312cadc7b19d89060200160405180910390a25050600161012d5550565b612b15613392565b612b505760405162461bcd60e51b815260206004820152600c60248201526b4e6f74206163637275696e6760a01b604482015260640161095f565b80612b9d5760405162461bcd60e51b815260206004820152601c60248201527f4d75737420616363727565206e6f6e7a65726f206465706f7369747300000000604482015260640161095f565b6000612bdb838380806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250613e6c92505050565b90508015612c595761015f5460405163a9059cbb60e01b8152336004820152602481018390526001600160a01b039091169063a9059cbb906044016020604051808303816000875af1158015612c35573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061231e9190614ef3565b505050565b612c8260405180606001604052806000815260200160008152602001600081525090565b506001600160a01b038216600090815261016b60209081526040808320848452825291829020825160608101845281548152600182015492810192909252600201549181019190915292915050565b600261012d541415612cf55760405162461bcd60e51b815260040161095f90614e7b565b600261012d55612d03613392565b15612d205760405162461bcd60e51b815260040161095f90614eb2565b33600090815261016c60205260408120612d3990613680565b805190915060005b81811015611fb45733600090815261016b6020526040812084518290869085908110612d6f57612d6f614edd565b602002602001015181526020019081526020016000209050600081600001541115612dcf57612db781858481518110612daa57612daa614edd565b6020026020010151613497565b6101746000828254612dc99190614d85565b90915550505b5080612dda81614f10565b915050612d41565b6101678181548110612df357600080fd5b600091825260209091206003909102018054600182015460029092015490925083565b6101625460ff1615612e5f5760405162461bcd60e51b81526020600482015260126024820152711b995dc81cdd185ada5b99c81c185d5cd95960721b604482015260640161095f565b6101655461016454612e719042614e64565b1015612ebf5760405162461bcd60e51b815260206004820181905260248201527f6e6f7420656e6f7567682074696d652073696e6365206c617374207374616b65604482015260640161095f565b4261016481905561016154600091612ed79190614d85565b61017380546000909155909150612eed81613eef565b60408051828152602081018490527f1574edda62d23715732e791bbaf4cfd037f78184fc43f42e78e1614930388b109101612755565b33600090815261016e602052604090205460ff16612f535760405162461bcd60e51b815260040161095f90614d16565b600081815261016f60205260409020546001600160a01b03163314612fb15760405162461bcd60e51b81526020600482015260146024820152732737ba1039ba30b5b2b91037b3103632b3b4b7b760611b604482015260640161095f565b610160546040805163675857eb60e01b815290516000926001600160a01b03169163675857eb9160048083019260209291908290030181865afa158015612ffc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130209190614d39565b600083815261016f60205260409081902080546001600160a01b03191690556101605490516371510c4d60e11b8152600481018590529192506001600160a01b03169063e2a2189a90602401600060405180830381600087803b15801561308657600080fd5b505af115801561309a573d6000803e3d6000fd5b505061016054604051637ed5e4c360e11b8152306004820152600093506001600160a01b03909116915063fdabc98690602401602060405180830381865afa1580156130ea573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061310e9190614d56565b604051632142170760e11b8152306004820152336024820152604481018590529091506001600160a01b038316906342842e0e90606401600060405180830381600087803b15801561315f57600080fd5b505af1158015613173573d6000803e3d6000fd5b505060408051868152600160208201529081018490526001600160a01b03851692503391507f629771fb40d78403cabd62586e2e57799a03937a15bde2af3fe5cdff8811aa0290606001611c3b565b6033546001600160a01b031633146131ec5760405162461bcd60e51b815260040161095f90614e2f565b6001600160a01b0381166132515760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b606482015260840161095f565b61131281613bc3565b6033546001600160a01b031633146132845760405162461bcd60e51b815260040161095f90614e2f565b6101f48111156132c85760405162461bcd60e51b815260206004820152600f60248201526e0e4caeec2e4c840e8dede40d0d2ced608b1b604482015260640161095f565b6101798190556040518181527fecc09c6a12e1d01477ee096e22b5f6f13480b121aad909968bd5d03cbc40509390602001611704565b610160546040516359fe213b60e01b81523060048201526000916001600160a01b0316906359fe213b90602401602060405180830381865afa158015613348573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061336c9190614d56565b61337461407b565b61337e9190614d85565b905090565b6001600160a01b03163b151590565b610177546000906133e55760405162461bcd60e51b815260206004820152601760248201527f4163637275616c2077696e646f7773206e6f7420736574000000000000000000604482015260640161095f565b6000610e106133f76201518042615013565b6134019190614f9f565b905060005b6101775461341690600190614e64565b81101561349257610177818154811061343157613431614edd565b906000526020600020015482101580156134725750610177613454826001614d85565b8154811061346457613464614edd565b906000526020600020015482105b156134805760019250505090565b61348b600282614d85565b9050613406565b505090565b6000806134a78460000154613b3c565b905080846002015412156134cd576134ca60018560020154836119269190614f2b565b91505b6002840181905560006134de613694565b9050808311156134fa576134fa6134f58285614e64565b61389c565b613502613694565b8311156135515760405162461bcd60e51b815260206004820152601b60248201527f4e6f7420656e6f756768207265776172647320746f20636c61696d0000000000604482015260640161095f565b604051838152849033907f347aec929f7bd3fbac6ab8f822dc6af14749962fdaa65e37888c0c3bc3ee22759060200160405180910390a3505092915050565b6040516001600160a01b038316602482015260448101829052612c5990849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b0319909316929092179091526140f0565b61016754610176545b8181101561367c5761360d816141c2565b506000610167828154811061362457613624614edd565b60009182526020918290206040805160608101825260039093029091018054808452600182015494840194909452600201549082015291501561366957506101765550565b508061367481614f10565b9150506135fc565b5050565b6060600061368d83614277565b9392505050565b61015f546040516370a0823160e01b815230600482015260009182916001600160a01b03909116906370a0823190602401602060405180830381865afa1580156136e2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906137069190614d56565b905061017454610172548261371b9190614e64565b6137259190614e64565b91505090565b60008082116137705760405162461bcd60e51b81526020600482015260116024820152700576974686472617720616d6f756e74203607c1b604482015260640161095f565b835482111561377e57835491505b600061378d8560000154613b3c565b9050600081866002015412156137b5576137b260018760020154846119269190614f2b565b90505b6137bf8185614d85565b9250838660000160008282546137d59190614e64565b909155505085546137e590613b3c565b86600201819055508361016660008282546138009190614e64565b9091555060009050613810613694565b905080841115613827576138276134f58286614e64565b61017354851061383c57600061017355613855565b84610173600082825461384f9190614e64565b90915550505b6040805186815260208101849052879133917f5706e30facf103fa63b976a5142c96bb88e65a98f82412f1ddbef60ba7169557910160405180910390a35050509392505050565b6101675461017654600091905b81811015613a8557600061016782815481106138c7576138c7614edd565b60009182526020918290206040805160608101825260039093029091018054835260018101549383018490526002015490820152915042108015613980575061016060009054906101000a90046001600160a01b03166001600160a01b031663cd24b0a36040518163ffffffff1660e01b8152600401602060405180830381865afa15801561395a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061397e9190614ef3565b155b1561398b5750613a85565b6000613995613694565b905060006139a38688614e64565b90506000836000015182116139b857816139bb565b83515b61016054604086810151905163d82b99d760e01b81526004810191909152602481018390529192506001600160a01b03169063d82b99d7906044016020604051808303816000875af1158015613a15573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613a399190614ef3565b506000613a44613694565b9050613a508482614e64565b613a5a9089614d85565b9750888810613a6d575050505050613a85565b50505050508080613a7d90614f10565b9150506138a9565b5082821015613ace5760405162461bcd60e51b8152602060048201526015602482015274086c2dcdcdee840eadce6e8c2d6ca40cadcdeeaced605b1b604482015260640161095f565b82613ad7613694565b1015613b345760405162461bcd60e51b815260206004820152602660248201527f4e6f7420656e6f75676820696e20636f6e747261637420616674657220756e7360448201526574616b696e6760d01b606482015260840161095f565b612c596135f3565b60006109296c0c9f2c9cd04674edea4000000061016a5484613b5e9190614f6a565b613b689190614f9f565b6142d3565b600080821215613bbf5760405162461bcd60e51b815260206004820181905260248201527f53616665436173743a2076616c7565206d75737420626520706f736974697665604482015260640161095f565b5090565b603380546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b600054610100900460ff16611e125760405162461bcd60e51b815260040161095f90615063565b600054610100900460ff16613c635760405162461bcd60e51b815260040161095f90615063565b611e1261433d565b600054610100900460ff16613c925760405162461bcd60e51b815260040161095f90615063565b611e1261436d565b61016054604080516372907e3f60e11b815290516000926001600160a01b03169163e520fc7e9160048083019260209291908290030181865afa158015613ce5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613d099190614d39565b6101605460405163a22cb46560e01b81526001600160a01b0391821660048201526001602482015291925082169063a22cb46590604401600060405180830381600087803b158015613d5a57600080fd5b505af1158015613d6e573d6000803e3d6000fd5b50505050600061016060009054906101000a90046001600160a01b03166001600160a01b031663675857eb6040518163ffffffff1660e01b8152600401602060405180830381865afa158015613dc8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613dec9190614d39565b6101605460405163a22cb46560e01b81526001600160a01b0391821660048201526001602482015291925082169063a22cb46590604401610e11565b600061368d8383614394565b6040516001600160a01b038085166024830152831660448201526064810182905261231e9085906323b872dd60e01b906084016135bc565b60006101665460001415613e8257506000919050565b600080613e8e846143e3565b9250509150816101696000828254613ea69190614d85565b909155505061016654613ec66c0c9f2c9cd04674edea4000000084614f6a565b613ed09190614f9f565b61016a6000828254613ee29190614d85565b9091555090949350505050565b613ef7613694565b811115613f395760405162461bcd60e51b815260206004820152601060248201526f4e6f7420656e6f7567682066756e647360801b604482015260640161095f565b600061016860008154613f4b90614f10565b919050819055905060006101615442613f649190614d85565b6040805160608101825285815260208101838152818301868152610167805460018101825560009190915292517f025f925b23c02f7114773957b1a876f2af957c14a29118dc622648c445020dcf60039094029384015590517f025f925b23c02f7114773957b1a876f2af957c14a29118dc622648c445020dd0830155517f025f925b23c02f7114773957b1a876f2af957c14a29118dc622648c445020dd19091015561016054905163654cfdff60e01b81529192506001600160a01b0381169163654cfdff91614044918791600160a01b900460ff16906004016150ae565b600060405180830381600087803b15801561405e57600080fd5b505af1158015614072573d6000803e3d6000fd5b50505050505050565b610167546101765460009182915b818110156140d65761016781815481106140a5576140a5614edd565b906000526020600020906003020160000154836140c29190614d85565b9250806140ce81614f10565b915050614089565b506140df613694565b6140e99083614d85565b9250505090565b6000614145826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166146309092919063ffffffff16565b805190915015612c5957808060200190518101906141639190614ef3565b612c595760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b606482015260840161095f565b60008061016783815481106141d9576141d9614edd565b600091825260208220610160546003929092020160028101546040516321ce919d60e01b815230600482015260248101919091529093506001600160a01b03909116906321ce919d9060440160e060405180830381865afa158015614242573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061426691906150c2565b505050948290555095945050505050565b6060816000018054806020026020016040519081016040528092919081815260200182805480156142c757602002820191906000526020600020905b8154815260200190600101908083116142b3575b50505050509050919050565b60006001600160ff1b03821115613bbf5760405162461bcd60e51b815260206004820152602860248201527f53616665436173743a2076616c756520646f65736e27742066697420696e2061604482015267371034b73a191a9b60c11b606482015260840161095f565b600054610100900460ff166143645760405162461bcd60e51b815260040161095f90615063565b611e1233613bc3565b600054610100900460ff166120205760405162461bcd60e51b815260040161095f90615063565b60008181526001830160205260408120546143db57508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155610929565b506000610929565b61015f546040516370a0823160e01b81523060048201526000918291829182916001600160a01b03909116906370a0823190602401602060405180830381865afa158015614435573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906144599190614d56565b855190915060005b818110156144f7576101605487516001600160a01b03909116906320f8e94e9089908490811061449357614493614edd565b60200260200101516040518263ffffffff1660e01b81526004016144b991815260200190565b600060405180830381600087803b1580156144d357600080fd5b505af19250505080156144e4575060015b50806144ef81614f10565b915050614461565b5061015f546040516370a0823160e01b81523060048201526000916001600160a01b0316906370a0823190602401602060405180830381865afa158015614542573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906145669190614d56565b905060006145748483614e64565b90506000612710610171548361458a9190614f6a565b6145949190614f9f565b90508061017260008282546145a99190614d85565b909155505061017954600090612710906145c39085614f6a565b6145cd9190614f9f565b90506145d98183614d85565b6145e39084614e64565b92507f30e1355d232e2cba291ab6e15c0600347591e3b175ec0b6c2a91240ff12a4de983838c60405161461893929190615122565b60405180910390a19199909850909650945050505050565b606061463f8484600085614647565b949350505050565b6060824710156146a85760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b606482015260840161095f565b6001600160a01b0385163b6146ff5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015260640161095f565b600080866001600160a01b0316858760405161471b9190615177565b60006040518083038185875af1925050503d8060008114614758576040519150601f19603f3d011682016040523d82523d6000602084013e61475d565b606091505b509150915061476d828286614778565b979650505050505050565b6060831561478757508161368d565b8251156147975782518084602001fd5b8160405162461bcd60e51b815260040161095f9190615193565b8280548282559060005260206000209081019282156147ec579160200282015b828111156147ec5782358255916020019190600101906147d1565b50613bbf9291505b80821115613bbf57600081556001016147f4565b60006020828403121561481a57600080fd5b81356001600160e01b03198116811461368d57600080fd5b6001600160a01b038116811461131257600080fd5b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff8111828210171561488657614886614847565b604052919050565b600082601f83011261489f57600080fd5b813567ffffffffffffffff8111156148b9576148b9614847565b6148cc601f8201601f191660200161485d565b8181528460208386010111156148e157600080fd5b816020850160208301376000918101602001919091529392505050565b6000806000806080858703121561491457600080fd5b843561491f81614832565b9350602085013561492f81614832565b925060408501359150606085013567ffffffffffffffff81111561495257600080fd5b61495e8782880161488e565b91505092959194509250565b6000806040838503121561497d57600080fd5b50508035926020909101359150565b60006020828403121561499e57600080fd5b813561368d81614832565b6000602082840312156149bb57600080fd5b5035919050565b600080604083850312156149d557600080fd5b82356149e081614832565b946020939093013593505050565b801515811461131257600080fd5b600060208284031215614a0e57600080fd5b813561368d816149ee565b6005811061131257600080fd5b600080600060608486031215614a3b57600080fd5b8335614a4681614832565b92506020840135614a5681614832565b91506040840135614a6681614a19565b809150509250925092565b60008060208385031215614a8457600080fd5b823567ffffffffffffffff80821115614a9c57600080fd5b818501915085601f830112614ab057600080fd5b813581811115614abf57600080fd5b8660208260051b8501011115614ad457600080fd5b60209290920196919550909350505050565b60008060408385031215614af957600080fd5b8235614b0481614832565b91506020830135614b14816149ee565b809150509250929050565b600082601f830112614b3057600080fd5b8135602067ffffffffffffffff821115614b4c57614b4c614847565b8160051b614b5b82820161485d565b9283528481018201928281019087851115614b7557600080fd5b83870192505b8483101561476d57823582529183019190830190614b7b565b600080600080600060a08688031215614bac57600080fd5b8535614bb781614832565b94506020860135614bc781614832565b9350604086013567ffffffffffffffff80821115614be457600080fd5b614bf089838a01614b1f565b94506060880135915080821115614c0657600080fd5b614c1289838a01614b1f565b93506080880135915080821115614c2857600080fd5b50614c358882890161488e565b9150509295509295909350565b60008060408385031215614c5557600080fd5b823591506020830135614b1481614832565b600080600080600060a08688031215614c7f57600080fd5b8535614c8a81614832565b94506020860135614c9a81614832565b93506040860135925060608601359150608086013567ffffffffffffffff811115614cc457600080fd5b614c358882890161488e565b634e487b7160e01b600052602160045260246000fd5b60058110614d0457634e487b7160e01b600052602160045260246000fd5b9052565b602081016109298284614ce6565b602080825260099082015268139bdd081a1bd85c9960ba1b604082015260600190565b600060208284031215614d4b57600080fd5b815161368d81614832565b600060208284031215614d6857600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b60008219821115614d9857614d98614d6f565b500190565b60005b83811015614db8578181015183820152602001614da0565b8381111561231e5750506000910152565b60008151808452614de1816020860160208601614d9d565b601f01601f19169290920160200192915050565b6001600160a01b03868116825285166020820152604081018490526060810183905260a06080820181905260009061476d90830184614dc9565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b600082821015614e7657614e76614d6f565b500390565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b602080825260119082015270496e206163637275616c2077696e646f7760781b604082015260600190565b634e487b7160e01b600052603260045260246000fd5b600060208284031215614f0557600080fd5b815161368d816149ee565b6000600019821415614f2457614f24614d6f565b5060010190565b60008083128015600160ff1b850184121615614f4957614f49614d6f565b6001600160ff1b0384018313811615614f6457614f64614d6f565b50500390565b6000816000190483118215151615614f8457614f84614d6f565b500290565b634e487b7160e01b600052601260045260246000fd5b600082614fae57614fae614f89565b500490565b60008060408385031215614fc657600080fd5b505080516020909101519092909150565b600060033d1115614ff05760046000803e5060005160e01c5b90565b60008060233d111561500f576020600460003e50506000516001905b9091565b60008261502257615022614f89565b500690565b6020808252810182905260006001600160fb1b0383111561504757600080fd5b8260051b80856040850137600092016040019182525092915050565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b8281526040810161368d6020830184614ce6565b600080600080600080600060e0888a0312156150dd57600080fd5b875196506020880151955060408801519450606088015193506080880151925060a0880151915060c088015161511281614a19565b8091505092959891949750929550565b6000606082018583526020858185015260606040850152818551808452608086019150828701935060005b818110156151695784518352938301939183019160010161514d565b509098975050505050505050565b60008251615189818460208701614d9d565b9190910192915050565b60208152600061368d6020830184614dc956fea164736f6c634300080b000a
Age | Block | Fee Address | BC Fee Address | Voting Power | Jailed | Incoming |
---|
Make sure to use the "Vote Down" button for any spammy posts, and the "Vote Up" for interesting conversations.