ETH Price: $2,626.57 (+1.14%)

Contract

0xee319C50a873493d220e11946655270244D8e164
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Token Holdings

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To
Exit148220962022-05-22 7:26:00880 days ago1653204360IN
0xee319C50...244D8e164
0 ETH0.0011922613.11725289
Get Reward148220932022-05-22 7:25:02880 days ago1653204302IN
0xee319C50...244D8e164
0 ETH0.0009353911.3516905
Exit148175612022-05-21 13:37:38880 days ago1653140258IN
0xee319C50...244D8e164
0 ETH0.0014806212.5910875
Exit148150422022-05-21 3:49:42881 days ago1653104982IN
0xee319C50...244D8e164
0 ETH0.0013204513.13975286
Stake148102592022-05-20 9:20:34882 days ago1653038434IN
0xee319C50...244D8e164
0 ETH0.0018085914.39335432
Exit148078662022-05-19 23:51:12882 days ago1653004272IN
0xee319C50...244D8e164
0 ETH0.0040650940.45150743
Stake148078512022-05-19 23:48:12882 days ago1653004092IN
0xee319C50...244D8e164
0 ETH0.0030128123.97461824
Exit148078332022-05-19 23:43:32882 days ago1653003812IN
0xee319C50...244D8e164
0 ETH0.0020630120.52896554
Stake148077892022-05-19 23:33:38882 days ago1653003218IN
0xee319C50...244D8e164
0 ETH0.0054156543.09525091
Stake148077802022-05-19 23:32:33882 days ago1653003153IN
0xee319C50...244D8e164
0 ETH0.0066978846.91481138
Stake148075802022-05-19 22:45:48882 days ago1653000348IN
0xee319C50...244D8e164
0 ETH0.0040519329.66102757
Notify Reward Am...148075592022-05-19 22:39:07882 days ago1652999947IN
0xee319C50...244D8e164
0 ETH0.0014237217.92159315
Set Reward Distr...148075582022-05-19 22:38:50882 days ago1652999930IN
0xee319C50...244D8e164
0 ETH0.0008750118.84023707
0x60e06040148075552022-05-19 22:38:18882 days ago1652999898IN
 Create: ERC20StakingPool
0 ETH0.0250312918.11050888

View more zero value Internal Transactions in Advanced View mode

Advanced mode:
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
ERC20StakingPool

Compiler Version
v0.8.13+commit.abaa5c0e

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion
File 1 of 12 : ERC20StakingPool.sol
// SPDX-License-Identifier: AGPL-3.0

pragma solidity ^0.8.4;

import {ERC20} from "lib/solmate/src/tokens/ERC20.sol";
import {SafeTransferLib} from "lib/solmate/src/utils/SafeTransferLib.sol";

import {Ownable} from "./lib/Ownable.sol";
import {FullMath} from "./lib/FullMath.sol";
import {Multicall} from "./lib/Multicall.sol";
import {SelfPermit} from "./lib/SelfPermit.sol";

/// @title ERC20StakingPool
/// @author zefram.eth
/// @notice A modern, gas optimized staking pool contract for rewarding ERC20 stakers
/// with ERC20 tokens periodically and continuously
contract ERC20StakingPool is Ownable, Multicall, SelfPermit {
    /// -----------------------------------------------------------------------
    /// Library usage
    /// -----------------------------------------------------------------------

    using SafeTransferLib for ERC20;

    /// -----------------------------------------------------------------------
    /// Errors
    /// -----------------------------------------------------------------------

    error Error_ZeroOwner();
    error Error_AlreadyInitialized();
    error Error_NotRewardDistributor();
    error Error_AmountTooLarge();

    /// -----------------------------------------------------------------------
    /// Events
    /// -----------------------------------------------------------------------

    event RewardAdded(uint256 reward);
    event Staked(address indexed user, uint256 amount);
    event Withdrawn(address indexed user, uint256 amount);
    event RewardPaid(address indexed user, uint256 reward);

    /// -----------------------------------------------------------------------
    /// Constants
    /// -----------------------------------------------------------------------

    uint256 internal constant PRECISION = 1e30;

    /// -----------------------------------------------------------------------
    /// Storage variables
    /// -----------------------------------------------------------------------

    /// @notice The last Unix timestamp (in seconds) when rewardPerTokenStored was updated
    uint64 public lastUpdateTime;
    /// @notice The Unix timestamp (in seconds) at which the current reward period ends
    uint64 public periodFinish;

    /// @notice The per-second rate at which rewardPerToken increases
    uint256 public rewardRate;
    /// @notice The last stored rewardPerToken value
    uint256 public rewardPerTokenStored;
    /// @notice The total tokens staked in the pool
    uint256 public totalSupply;

    /// @notice Tracks if an address can call notifyReward()
    mapping(address => bool) public isRewardDistributor;

    /// @notice The time this account started staking
    mapping(address => uint256) public startedStaking;
    /// @notice The amount of tokens staked by an account
    mapping(address => uint256) public balanceOf;
    /// @notice The rewardPerToken value when an account last staked/withdrew/withdrew rewards
    mapping(address => uint256) public userRewardPerTokenPaid;
    /// @notice The earned() value when an account last staked/withdrew/withdrew rewards
    mapping(address => uint256) public rewards;

    /// -----------------------------------------------------------------------
    /// Immutable parameters
    /// -----------------------------------------------------------------------

    /// @notice The token being rewarded to stakers
    ERC20 public immutable rewardToken;

    /// @notice The token being staked in the pool
    ERC20 public immutable stakeToken;

    /// @notice The length of each reward period, in seconds
    uint64 public immutable duration;

    /// -----------------------------------------------------------------------
    /// Initialization
    /// -----------------------------------------------------------------------

    /// @notice Initializes the contract
    /// @param _rewardToken The token to be rewarded to stakers
    /// @param _stakeToken The token to be staked by stakers
    /// @param _duration The duration of the staking
    constructor(
        ERC20 _rewardToken,
        ERC20 _stakeToken,
        uint64 _duration
    ) {
        rewardToken =_rewardToken;
        stakeToken = _stakeToken;
        duration = _duration;
        _transferOwnership(msg.sender);
    }

    /// -----------------------------------------------------------------------
    /// User actions
    /// -----------------------------------------------------------------------

    /// @notice Stakes tokens in the pool to earn rewards
    /// @param amount The amount of tokens to stake
    function stake(uint256 amount) external {
        /// -----------------------------------------------------------------------
        /// Validation
        /// -----------------------------------------------------------------------

        if (amount == 0) {
            return;
        }

        /// -----------------------------------------------------------------------
        /// Storage loads
        /// -----------------------------------------------------------------------

        uint256 accountBalance = balanceOf[msg.sender];
        uint64 lastTimeRewardApplicable_ = lastTimeRewardApplicable();
        uint256 totalSupply_ = totalSupply;
        uint256 rewardPerToken_ = _rewardPerToken(
            totalSupply_,
            lastTimeRewardApplicable_,
            rewardRate
        );

        /// -----------------------------------------------------------------------
        /// State updates
        /// -----------------------------------------------------------------------

        // accrue rewards
        rewardPerTokenStored = rewardPerToken_;
        lastUpdateTime = lastTimeRewardApplicable_;
        rewards[msg.sender] = _earned(
            msg.sender,
            accountBalance,
            rewardPerToken_,
            rewards[msg.sender]
        );
        userRewardPerTokenPaid[msg.sender] = rewardPerToken_;

        // stake
        totalSupply = totalSupply_ + amount;
        balanceOf[msg.sender] = accountBalance + amount;
        startedStaking[msg.sender] = block.timestamp;

        /// -----------------------------------------------------------------------
        /// Effects
        /// -----------------------------------------------------------------------

        stakeToken.safeTransferFrom(msg.sender, address(this), amount);

        emit Staked(msg.sender, amount);
    }

    /// @notice Withdraws staked tokens from the pool
    /// @param amount The amount of tokens to withdraw
    function withdraw(uint256 amount) external {
        /// -----------------------------------------------------------------------
        /// Validation
        /// -----------------------------------------------------------------------

        if (amount == 0) {
            return;
        }

        /// -----------------------------------------------------------------------
        /// Storage loads
        /// -----------------------------------------------------------------------

        uint256 accountBalance = balanceOf[msg.sender];
        uint64 lastTimeRewardApplicable_ = lastTimeRewardApplicable();
        uint256 totalSupply_ = totalSupply;
        uint256 rewardPerToken_ = _rewardPerToken(
            totalSupply_,
            lastTimeRewardApplicable_,
            rewardRate
        );

        /// -----------------------------------------------------------------------
        /// State updates
        /// -----------------------------------------------------------------------

        // accrue rewards
        rewardPerTokenStored = rewardPerToken_;
        lastUpdateTime = lastTimeRewardApplicable_;
        rewards[msg.sender] = _earned(
            msg.sender,
            accountBalance,
            rewardPerToken_,
            rewards[msg.sender]
        );
        userRewardPerTokenPaid[msg.sender] = rewardPerToken_;

        // withdraw stake
        balanceOf[msg.sender] = accountBalance - amount;
        // total supply has 1:1 relationship with staked amounts
        // so can't ever underflow
        unchecked {
            totalSupply = totalSupply_ - amount;
        }

        /// -----------------------------------------------------------------------
        /// Effects
        /// -----------------------------------------------------------------------

        stakeToken.safeTransfer(msg.sender, amount);

        emit Withdrawn(msg.sender, amount);
    }

    /// @notice Withdraws all staked tokens and earned rewards
    function exit() external {
        /// -----------------------------------------------------------------------
        /// Validation
        /// -----------------------------------------------------------------------

        uint256 accountBalance = balanceOf[msg.sender];

        /// -----------------------------------------------------------------------
        /// Storage loads
        /// -----------------------------------------------------------------------

        uint64 lastTimeRewardApplicable_ = lastTimeRewardApplicable();
        uint256 totalSupply_ = totalSupply;
        uint256 rewardPerToken_ = _rewardPerToken(
            totalSupply_,
            lastTimeRewardApplicable_,
            rewardRate
        );

        /// -----------------------------------------------------------------------
        /// State updates
        /// -----------------------------------------------------------------------

        // give rewards
        uint256 reward = _earned(
            msg.sender,
            accountBalance,
            rewardPerToken_,
            rewards[msg.sender]
        );
        if (reward > 0) {
            rewards[msg.sender] = 0;
        }

        // accrue rewards
        rewardPerTokenStored = rewardPerToken_;
        lastUpdateTime = lastTimeRewardApplicable_;
        userRewardPerTokenPaid[msg.sender] = rewardPerToken_;

        // withdraw stake
        balanceOf[msg.sender] = 0;
        // total supply has 1:1 relationship with staked amounts
        // so can't ever underflow
        unchecked {
            totalSupply = totalSupply_ - accountBalance;
        }

        /// -----------------------------------------------------------------------
        /// Effects
        /// -----------------------------------------------------------------------

        // transfer stake
        stakeToken.safeTransfer(msg.sender, accountBalance);
        emit Withdrawn(msg.sender, accountBalance);

        // transfer rewards
        if (reward > 0) {
            rewardToken.safeTransfer(msg.sender, reward);
            emit RewardPaid(msg.sender, reward);
        }
    }

    /// @notice Withdraws all earned rewards
    function getReward() external {
        /// -----------------------------------------------------------------------
        /// Storage loads
        /// -----------------------------------------------------------------------

        uint256 accountBalance = balanceOf[msg.sender];
        uint64 lastTimeRewardApplicable_ = lastTimeRewardApplicable();
        uint256 totalSupply_ = totalSupply;
        uint256 rewardPerToken_ = _rewardPerToken(
            totalSupply_,
            lastTimeRewardApplicable_,
            rewardRate
        );

        /// -----------------------------------------------------------------------
        /// State updates
        /// -----------------------------------------------------------------------

        uint256 reward = _earned(
            msg.sender,
            accountBalance,
            rewardPerToken_,
            rewards[msg.sender]
        );

        // accrue rewards
        rewardPerTokenStored = rewardPerToken_;
        lastUpdateTime = lastTimeRewardApplicable_;
        userRewardPerTokenPaid[msg.sender] = rewardPerToken_;

        // withdraw rewards
        if (reward > 0) {
            rewards[msg.sender] = 0;

            /// -----------------------------------------------------------------------
            /// Effects
            /// -----------------------------------------------------------------------

            rewardToken.safeTransfer(msg.sender, reward);
            emit RewardPaid(msg.sender, reward);
        }
    }

    /// -----------------------------------------------------------------------
    /// Getters
    /// -----------------------------------------------------------------------

    /// @notice The latest time at which stakers are earning rewards.
    function lastTimeRewardApplicable() public view returns (uint64) {
        return
            block.timestamp < periodFinish
                ? uint64(block.timestamp)
                : periodFinish;
    }

    /// @notice The amount of reward tokens each staked token has earned so far
    function rewardPerToken() external view returns (uint256) {
        return
            _rewardPerToken(
                totalSupply,
                lastTimeRewardApplicable(),
                rewardRate
            );
    }

    /// @notice The amount of reward tokens an account has accrued so far. Does not
    /// include already withdrawn rewards.
    function earned(address account) external view returns (uint256) {
        return
            _earned(
                account,
                balanceOf[account],
                _rewardPerToken(
                    totalSupply,
                    lastTimeRewardApplicable(),
                    rewardRate
                ),
                rewards[account]
            );
    }

    /// -----------------------------------------------------------------------
    /// Owner actions
    /// -----------------------------------------------------------------------

    /// @notice Lets a reward distributor start a new reward period. The reward tokens must have already
    /// been transferred to this contract before calling this function. If it is called
    /// when a reward period is still active, a new reward period will begin from the time
    /// of calling this function, using the leftover rewards from the old reward period plus
    /// the newly sent rewards as the reward.
    /// @dev If the reward amount will cause an overflow when computing rewardPerToken, then
    /// this function will revert.
    /// @param reward The amount of reward tokens to use in the new reward period.
    function notifyRewardAmount(uint256 reward) external {
        /// -----------------------------------------------------------------------
        /// Validation
        /// -----------------------------------------------------------------------

        if (reward == 0) {
            return;
        }
        if (!isRewardDistributor[msg.sender]) {
            revert Error_NotRewardDistributor();
        }

        /// -----------------------------------------------------------------------
        /// Storage loads
        /// -----------------------------------------------------------------------

        uint256 rewardRate_ = rewardRate;
        uint64 periodFinish_ = periodFinish;
        uint64 lastTimeRewardApplicable_ = block.timestamp < periodFinish_
            ? uint64(block.timestamp)
            : periodFinish_;
        uint64 DURATION_ = duration;
        uint256 totalSupply_ = totalSupply;

        /// -----------------------------------------------------------------------
        /// State updates
        /// -----------------------------------------------------------------------

        // accrue rewards
        rewardPerTokenStored = _rewardPerToken(
            totalSupply_,
            lastTimeRewardApplicable_,
            rewardRate_
        );
        lastUpdateTime = lastTimeRewardApplicable_;

        // record new reward
        uint256 newRewardRate;
        if (block.timestamp >= periodFinish_) {
            newRewardRate = reward / DURATION_;
        } else {
            uint256 remaining = periodFinish_ - block.timestamp;
            uint256 leftover = remaining * rewardRate_;
            newRewardRate = (reward + leftover) / DURATION_;
        }
        // prevent overflow when computing rewardPerToken
        if (newRewardRate >= ((type(uint256).max / PRECISION) / DURATION_)) {
            revert Error_AmountTooLarge();
        }
        rewardRate = newRewardRate;
        lastUpdateTime = uint64(block.timestamp);
        periodFinish = uint64(block.timestamp + DURATION_);

        emit RewardAdded(reward);
    }

    /// @notice Lets the owner add/remove accounts from the list of reward distributors.
    /// Reward distributors can call notifyRewardAmount()
    /// @param rewardDistributor The account to add/remove
    /// @param isRewardDistributor_ True to add the account, false to remove the account
    function setRewardDistributor(
        address rewardDistributor,
        bool isRewardDistributor_
    ) external onlyOwner {
        isRewardDistributor[rewardDistributor] = isRewardDistributor_;
    }

    /// -----------------------------------------------------------------------
    /// Internal functions
    /// -----------------------------------------------------------------------

    function _earned(
        address account,
        uint256 accountBalance,
        uint256 rewardPerToken_,
        uint256 accountRewards
    ) internal view returns (uint256) {
        return
            FullMath.mulDiv(
                accountBalance,
                rewardPerToken_ - userRewardPerTokenPaid[account],
                PRECISION
            ) + accountRewards;
    }

    function _rewardPerToken(
        uint256 totalSupply_,
        uint256 lastTimeRewardApplicable_,
        uint256 rewardRate_
    ) internal view returns (uint256) {
        if (totalSupply_ == 0) {
            return rewardPerTokenStored;
        }
        return
            rewardPerTokenStored +
            FullMath.mulDiv(
                (lastTimeRewardApplicable_ - lastUpdateTime) * PRECISION,
                rewardRate_,
                totalSupply_
            );
    }
}

File 2 of 12 : ERC20.sol
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;

/// @notice Modern and gas efficient ERC20 + EIP-2612 implementation.
/// @author Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/tokens/ERC20.sol)
/// @author Modified from Uniswap (https://github.com/Uniswap/uniswap-v2-core/blob/master/contracts/UniswapV2ERC20.sol)
/// @dev Do not manually set balances without updating totalSupply, as the sum of all user balances must not exceed it.
abstract contract ERC20 {
    /*//////////////////////////////////////////////////////////////
                                 EVENTS
    //////////////////////////////////////////////////////////////*/

    event Transfer(address indexed from, address indexed to, uint256 amount);

    event Approval(address indexed owner, address indexed spender, uint256 amount);

    /*//////////////////////////////////////////////////////////////
                            METADATA STORAGE
    //////////////////////////////////////////////////////////////*/

    string public name;

    string public symbol;

    uint8 public immutable decimals;

    /*//////////////////////////////////////////////////////////////
                              ERC20 STORAGE
    //////////////////////////////////////////////////////////////*/

    uint256 public totalSupply;

    mapping(address => uint256) public balanceOf;

    mapping(address => mapping(address => uint256)) public allowance;

    /*//////////////////////////////////////////////////////////////
                            EIP-2612 STORAGE
    //////////////////////////////////////////////////////////////*/

    uint256 internal immutable INITIAL_CHAIN_ID;

    bytes32 internal immutable INITIAL_DOMAIN_SEPARATOR;

    mapping(address => uint256) public nonces;

    /*//////////////////////////////////////////////////////////////
                               CONSTRUCTOR
    //////////////////////////////////////////////////////////////*/

    constructor(
        string memory _name,
        string memory _symbol,
        uint8 _decimals
    ) {
        name = _name;
        symbol = _symbol;
        decimals = _decimals;

        INITIAL_CHAIN_ID = block.chainid;
        INITIAL_DOMAIN_SEPARATOR = computeDomainSeparator();
    }

    /*//////////////////////////////////////////////////////////////
                               ERC20 LOGIC
    //////////////////////////////////////////////////////////////*/

    function approve(address spender, uint256 amount) public virtual returns (bool) {
        allowance[msg.sender][spender] = amount;

        emit Approval(msg.sender, spender, amount);

        return true;
    }

    function transfer(address to, uint256 amount) public virtual returns (bool) {
        balanceOf[msg.sender] -= amount;

        // Cannot overflow because the sum of all user
        // balances can't exceed the max uint256 value.
        unchecked {
            balanceOf[to] += amount;
        }

        emit Transfer(msg.sender, to, amount);

        return true;
    }

    function transferFrom(
        address from,
        address to,
        uint256 amount
    ) public virtual returns (bool) {
        uint256 allowed = allowance[from][msg.sender]; // Saves gas for limited approvals.

        if (allowed != type(uint256).max) allowance[from][msg.sender] = allowed - amount;

        balanceOf[from] -= amount;

        // Cannot overflow because the sum of all user
        // balances can't exceed the max uint256 value.
        unchecked {
            balanceOf[to] += amount;
        }

        emit Transfer(from, to, amount);

        return true;
    }

    /*//////////////////////////////////////////////////////////////
                             EIP-2612 LOGIC
    //////////////////////////////////////////////////////////////*/

    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) public virtual {
        require(deadline >= block.timestamp, "PERMIT_DEADLINE_EXPIRED");

        // Unchecked because the only math done is incrementing
        // the owner's nonce which cannot realistically overflow.
        unchecked {
            address recoveredAddress = ecrecover(
                keccak256(
                    abi.encodePacked(
                        "\x19\x01",
                        DOMAIN_SEPARATOR(),
                        keccak256(
                            abi.encode(
                                keccak256(
                                    "Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"
                                ),
                                owner,
                                spender,
                                value,
                                nonces[owner]++,
                                deadline
                            )
                        )
                    )
                ),
                v,
                r,
                s
            );

            require(recoveredAddress != address(0) && recoveredAddress == owner, "INVALID_SIGNER");

            allowance[recoveredAddress][spender] = value;
        }

        emit Approval(owner, spender, value);
    }

    function DOMAIN_SEPARATOR() public view virtual returns (bytes32) {
        return block.chainid == INITIAL_CHAIN_ID ? INITIAL_DOMAIN_SEPARATOR : computeDomainSeparator();
    }

    function computeDomainSeparator() internal view virtual returns (bytes32) {
        return
            keccak256(
                abi.encode(
                    keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
                    keccak256(bytes(name)),
                    keccak256("1"),
                    block.chainid,
                    address(this)
                )
            );
    }

    /*//////////////////////////////////////////////////////////////
                        INTERNAL MINT/BURN LOGIC
    //////////////////////////////////////////////////////////////*/

    function _mint(address to, uint256 amount) internal virtual {
        totalSupply += amount;

        // Cannot overflow because the sum of all user
        // balances can't exceed the max uint256 value.
        unchecked {
            balanceOf[to] += amount;
        }

        emit Transfer(address(0), to, amount);
    }

    function _burn(address from, uint256 amount) internal virtual {
        balanceOf[from] -= amount;

        // Cannot underflow because a user's balance
        // will never be larger than the total supply.
        unchecked {
            totalSupply -= amount;
        }

        emit Transfer(from, address(0), amount);
    }
}

File 3 of 12 : SafeTransferLib.sol
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;

import {ERC20} from "../tokens/ERC20.sol";

/// @notice Safe ETH and ERC20 transfer library that gracefully handles missing return values.
/// @author Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/utils/SafeTransferLib.sol)
/// @dev Use with caution! Some functions in this library knowingly create dirty bits at the destination of the free memory pointer.
/// @dev Note that none of the functions in this library check that a token has code at all! That responsibility is delegated to the caller.
library SafeTransferLib {
    event Debug(bool one, bool two, uint256 retsize);

    /*//////////////////////////////////////////////////////////////
                             ETH OPERATIONS
    //////////////////////////////////////////////////////////////*/

    function safeTransferETH(address to, uint256 amount) internal {
        bool success;

        assembly {
            // Transfer the ETH and store if it succeeded or not.
            success := call(gas(), to, amount, 0, 0, 0, 0)
        }

        require(success, "ETH_TRANSFER_FAILED");
    }

    /*//////////////////////////////////////////////////////////////
                            ERC20 OPERATIONS
    //////////////////////////////////////////////////////////////*/

    function safeTransferFrom(
        ERC20 token,
        address from,
        address to,
        uint256 amount
    ) internal {
        bool success;

        assembly {
            // Get a pointer to some free memory.
            let freeMemoryPointer := mload(0x40)

            // Write the abi-encoded calldata into memory, beginning with the function selector.
            mstore(freeMemoryPointer, 0x23b872dd00000000000000000000000000000000000000000000000000000000)
            mstore(add(freeMemoryPointer, 4), from) // Append the "from" argument.
            mstore(add(freeMemoryPointer, 36), to) // Append the "to" argument.
            mstore(add(freeMemoryPointer, 68), amount) // Append the "amount" argument.

            success := and(
                // Set success to whether the call reverted, if not we check it either
                // returned exactly 1 (can't just be non-zero data), or had no return data.
                or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())),
                // We use 100 because the length of our calldata totals up like so: 4 + 32 * 3.
                // We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
                // Counterintuitively, this call must be positioned second to the or() call in the
                // surrounding and() call or else returndatasize() will be zero during the computation.
                call(gas(), token, 0, freeMemoryPointer, 100, 0, 32)
            )
        }

        require(success, "TRANSFER_FROM_FAILED");
    }

    function safeTransfer(
        ERC20 token,
        address to,
        uint256 amount
    ) internal {
        bool success;

        assembly {
            // Get a pointer to some free memory.
            let freeMemoryPointer := mload(0x40)

            // Write the abi-encoded calldata into memory, beginning with the function selector.
            mstore(freeMemoryPointer, 0xa9059cbb00000000000000000000000000000000000000000000000000000000)
            mstore(add(freeMemoryPointer, 4), to) // Append the "to" argument.
            mstore(add(freeMemoryPointer, 36), amount) // Append the "amount" argument.

            success := and(
                // Set success to whether the call reverted, if not we check it either
                // returned exactly 1 (can't just be non-zero data), or had no return data.
                or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())),
                // We use 68 because the length of our calldata totals up like so: 4 + 32 * 2.
                // We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
                // Counterintuitively, this call must be positioned second to the or() call in the
                // surrounding and() call or else returndatasize() will be zero during the computation.
                call(gas(), token, 0, freeMemoryPointer, 68, 0, 32)
            )
        }

        require(success, "TRANSFER_FAILED");
    }

    function safeApprove(
        ERC20 token,
        address to,
        uint256 amount
    ) internal {
        bool success;

        assembly {
            // Get a pointer to some free memory.
            let freeMemoryPointer := mload(0x40)

            // Write the abi-encoded calldata into memory, beginning with the function selector.
            mstore(freeMemoryPointer, 0x095ea7b300000000000000000000000000000000000000000000000000000000)
            mstore(add(freeMemoryPointer, 4), to) // Append the "to" argument.
            mstore(add(freeMemoryPointer, 36), amount) // Append the "amount" argument.

            success := and(
                // Set success to whether the call reverted, if not we check it either
                // returned exactly 1 (can't just be non-zero data), or had no return data.
                or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())),
                // We use 68 because the length of our calldata totals up like so: 4 + 32 * 2.
                // We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
                // Counterintuitively, this call must be positioned second to the or() call in the
                // surrounding and() call or else returndatasize() will be zero during the computation.
                call(gas(), token, 0, freeMemoryPointer, 68, 0, 32)
            )
        }

        require(success, "APPROVE_FAILED");
    }
}

File 4 of 12 : Ownable.sol
// SPDX-License-Identifier: AGPL-3.0

pragma solidity ^0.8.4;

abstract contract Ownable {
    error Ownable_NotOwner();
    error Ownable_NewOwnerZeroAddress();

    address private _owner;

    event OwnershipTransferred(
        address indexed previousOwner,
        address indexed newOwner
    );

    /// @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() {
        if (owner() != msg.sender) revert Ownable_NotOwner();
        _;
    }

    /// @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 {
        if (newOwner == address(0)) revert Ownable_NewOwnerZeroAddress();
        _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);
    }
}

File 5 of 12 : FullMath.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;

/// @title Contains 512-bit math functions
/// @notice Facilitates multiplication and division that can have overflow of an intermediate value without any loss of precision
/// @dev Handles "phantom overflow" i.e., allows multiplication and division where an intermediate value overflows 256 bits
library FullMath {
    /// @notice Calculates floor(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
    /// @param a The multiplicand
    /// @param b The multiplier
    /// @param denominator The divisor
    /// @return result The 256-bit result
    /// @dev Credit to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv
    function mulDiv(
        uint256 a,
        uint256 b,
        uint256 denominator
    ) internal pure returns (uint256 result) {
        unchecked {
            // 512-bit multiply [prod1 prod0] = a * b
            // Compute the product mod 2**256 and mod 2**256 - 1
            // then use the Chinese Remainder Theorem to reconstruct
            // the 512 bit result. The result is stored in two 256
            // variables such that product = prod1 * 2**256 + prod0
            uint256 prod0; // Least significant 256 bits of the product
            uint256 prod1; // Most significant 256 bits of the product
            assembly {
                let mm := mulmod(a, b, not(0))
                prod0 := mul(a, b)
                prod1 := sub(sub(mm, prod0), lt(mm, prod0))
            }

            // Handle non-overflow cases, 256 by 256 division
            if (prod1 == 0) {
                require(denominator > 0);
                assembly {
                    result := div(prod0, denominator)
                }
                return result;
            }

            // Make sure the result is less than 2**256.
            // Also prevents denominator == 0
            require(denominator > prod1);

            ///////////////////////////////////////////////
            // 512 by 256 division.
            ///////////////////////////////////////////////

            // Make division exact by subtracting the remainder from [prod1 prod0]
            // Compute remainder using mulmod
            uint256 remainder;
            assembly {
                remainder := mulmod(a, b, denominator)
            }
            // Subtract 256 bit number from 512 bit number
            assembly {
                prod1 := sub(prod1, gt(remainder, prod0))
                prod0 := sub(prod0, remainder)
            }

            // Factor powers of two out of denominator
            // Compute largest power of two divisor of denominator.
            // Always >= 1.
            uint256 twos = (type(uint256).max - denominator + 1) & denominator;
            // Divide denominator by power of two
            assembly {
                denominator := div(denominator, twos)
            }

            // Divide [prod1 prod0] by the factors of two
            assembly {
                prod0 := div(prod0, twos)
            }
            // Shift in bits from prod1 into prod0. For this we need
            // to flip `twos` such that it is 2**256 / twos.
            // If twos is zero, then it becomes one
            assembly {
                twos := add(div(sub(0, twos), twos), 1)
            }
            prod0 |= prod1 * twos;

            // Invert denominator mod 2**256
            // Now that denominator is an odd number, it has an inverse
            // modulo 2**256 such that denominator * inv = 1 mod 2**256.
            // Compute the inverse by starting with a seed that is correct
            // correct for four bits. That is, denominator * inv = 1 mod 2**4
            uint256 inv = (3 * denominator) ^ 2;
            // Now use Newton-Raphson iteration to improve the precision.
            // Thanks to Hensel's lifting lemma, this also works in modular
            // arithmetic, doubling the correct bits in each step.
            inv *= 2 - denominator * inv; // inverse mod 2**8
            inv *= 2 - denominator * inv; // inverse mod 2**16
            inv *= 2 - denominator * inv; // inverse mod 2**32
            inv *= 2 - denominator * inv; // inverse mod 2**64
            inv *= 2 - denominator * inv; // inverse mod 2**128
            inv *= 2 - denominator * inv; // inverse mod 2**256

            // Because the division is now exact we can divide by multiplying
            // with the modular inverse of denominator. This will give us the
            // correct result modulo 2**256. Since the precoditions guarantee
            // that the outcome is less than 2**256, this is the final result.
            // We don't need to compute the high bits of the result and prod1
            // is no longer required.
            result = prod0 * inv;
            return result;
        }
    }

    /// @notice Calculates ceil(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
    /// @param a The multiplicand
    /// @param b The multiplier
    /// @param denominator The divisor
    /// @return result The 256-bit result
    function mulDivRoundingUp(
        uint256 a,
        uint256 b,
        uint256 denominator
    ) internal pure returns (uint256 result) {
        result = mulDiv(a, b, denominator);
        unchecked {
            if (mulmod(a, b, denominator) > 0) {
                require(result < type(uint256).max);
                result++;
            }
        }
    }
}

File 6 of 12 : Multicall.sol
// SPDX-License-Identifier: AGPL-3.0
pragma solidity ^0.8.4;

/// @title Multicall
/// @notice Enables calling multiple methods in a single call to the contract
abstract contract Multicall {
    function multicall(bytes[] calldata data)
        external
        payable
        returns (bytes[] memory results)
    {
        results = new bytes[](data.length);
        for (uint256 i = 0; i < data.length; i++) {
            (bool success, bytes memory result) = address(this).delegatecall(
                data[i]
            );

            if (!success) {
                // Next 5 lines from https://ethereum.stackexchange.com/a/83577
                if (result.length < 68) revert();
                assembly {
                    result := add(result, 0x04)
                }
                revert(abi.decode(result, (string)));
            }

            results[i] = result;
        }
    }
}

File 7 of 12 : SelfPermit.sol
// SPDX-License-Identifier: AGPL-3.0
pragma solidity >=0.5.0;

import {ERC20} from "lib/solmate/src/tokens/ERC20.sol";

/// @title Self Permit
/// @notice Functionality to call permit on any EIP-2612-compliant token for use in the route
/// @dev These functions are expected to be embedded in multicalls to allow EOAs to approve a contract and call a function
/// that requires an approval in a single transaction.
abstract contract SelfPermit {
    function selfPermit(
        ERC20 token,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) public payable {
        token.permit(msg.sender, address(this), value, deadline, v, r, s);
    }

    function selfPermitIfNecessary(
        ERC20 token,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external payable {
        if (token.allowance(msg.sender, address(this)) < value)
            selfPermit(token, value, deadline, v, r, s);
    }
}

File 8 of 12 : LunacyDAO.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;

import {ERC20} from "lib/solmate/src/tokens/ERC20.sol";

import {TerraClaimable} from "./TerraClaimable.sol";

contract LunacyDAO is ERC20, TerraClaimable {
    address immutable minter;

    mapping(string => bool) public hasClaimed;

    mapping(address => uint256) public leftToClaim;
    mapping(address => uint256) public initiallyClaimed;

    bool public claiming;

    error Unauthorized();
    error ClaimingNotEnabled();
    error TooEarlyToClaimRemainder();
    error NothingLeftToClaim();
    error AlreadyClaimed();
    error CannotClaim();

    event Claim(address indexed to, uint256 amount);

    constructor(address _minter) ERC20("LunacyDAO", "LUNAC", 18) {
        minter = _minter;

        _mint(msg.sender, 420_000_000_000e18);
    }

    function enableClaiming() external {
        if (msg.sender != minter) revert Unauthorized();
        claiming = true;
    }

    function claim(
        uint256 amount,
        bytes memory _minterSignature,
        bytes memory _terraSignature,
        bytes memory _terraPubKey
    ) external {
        if (!claiming) revert ClaimingNotEnabled();
        string memory terraAddress = addressFromPublicKey(_terraPubKey);

        if (hasClaimed[terraAddress]) revert AlreadyClaimed();
        if (!canClaim(_terraSignature, _terraPubKey)) revert CannotClaim();

        bytes32 hashedMessage = sha256(abi.encodePacked(msg.sender, amount, terraAddress));
        (uint8 v, bytes32 r, bytes32 s) = splitSignature(_minterSignature);
        address recoveredAddress = ecrecover(hashedMessage, v, r, s);

        if (recoveredAddress == address(0)) revert InvalidSignature();
        if (recoveredAddress != minter) revert InvalidAddress();

        uint256 mintAmount = (amount * 33) / 100;
        hasClaimed[terraAddress] = true;
        leftToClaim[msg.sender] = amount - mintAmount;
        initiallyClaimed[msg.sender] = block.timestamp;
        _mint(msg.sender, mintAmount);

        emit Claim(msg.sender, mintAmount);
    }

    function claimRemainder() external {
        uint256 mintAmount = leftToClaim[msg.sender];
        if (mintAmount == 0) revert NothingLeftToClaim();
        if (block.timestamp - initiallyClaimed[msg.sender] < 7 days) revert TooEarlyToClaimRemainder();

        leftToClaim[msg.sender] = 0;
        _mint(msg.sender, mintAmount);

        emit Claim(msg.sender, mintAmount);
    }
}

File 9 of 12 : TerraClaimable.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;

import {Bech32} from "./lib/Bech32.sol";
import {EllipticCurve} from "./lib/Secp256k1.sol";

contract TerraClaimable {
    error InvalidSignatureLength();
    error InvalidSignature();
    error InvalidAddress();

    function canClaim(bytes memory _signature, bytes memory _compPubKey) public view returns (bool) {
        bytes32 hashedAddress = sha256(abi.encodePacked(msg.sender));

        (uint8 v, bytes32 r, bytes32 s) = splitSignature(_signature);

        address recoveredAddress = ecrecover(hashedAddress, v, r, s);
        if (recoveredAddress == address(0)) revert InvalidSignature();

        bytes memory _pubKey = decompressPubKey(_compPubKey);

        address computedAddress = address(uint160(uint256(keccak256(_pubKey))));

        if (recoveredAddress != computedAddress) revert InvalidAddress();

        return true;
    }

    function convertToArray(bytes memory _data) internal pure returns (uint256[] memory output) {
        output = new uint256[](_data.length);
        for (uint256 i = 0; i < _data.length; i++) {
            output[i] = uint256(uint8(_data[i]));
        }
    }

    function addressFromPublicKey(bytes memory _compPubKey) public pure returns (string memory result) {
        bytes memory pubKeyHash = abi.encodePacked(ripemd160(abi.encodePacked(sha256(abi.encodePacked(_compPubKey)))));

        uint256[] memory pubKeyNumbers = convertToArray(pubKeyHash);
        uint256[] memory pubKey5BitBase = Bech32.convert(pubKeyNumbers, 8, 5);

        result = string.concat("terra1", string(Bech32.encode(convertToArray(bytes("terra")), pubKey5BitBase)));
    }

    function splitSignature(bytes memory _sig)
        internal
        pure
        returns (
            uint8 v,
            bytes32 r,
            bytes32 s
        )
    {
        if (_sig.length != 65) revert InvalidSignatureLength();

        assembly {
            // first 32 bytes, after the length prefix
            r := mload(add(_sig, 32))
            // second 32 bytes
            s := mload(add(_sig, 64))
            // final byte (first byte of the next 32 bytes)
            v := byte(0, mload(add(_sig, 96)))
        }
    }

    function decompressPubKey(bytes memory _compPubKey) internal pure returns (bytes memory pubKey) {
        uint8 prefix;
        uint256 x;

        assembly {
            prefix := byte(0, mload(add(_compPubKey, 32)))
            x := mload(add(_compPubKey, 33))
        }

        uint256 y = EllipticCurve.deriveY(prefix, x);

        pubKey = bytes.concat(bytes32(x), bytes32(y));
    }
}

File 10 of 12 : Bech32.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.5.15;

import {BytesLib} from "./BytesLib.sol";

/** @author https://github.com/gregdhill **/

library Bech32 {
    using BytesLib for bytes;

    bytes constant CHARSET = "qpzry9x8gf2tvdw0s3jn54khce6mua7l";

    function polymod(uint256[] memory values) internal pure returns (uint256) {
        uint32[5] memory GENERATOR = [0x3b6a57b2, 0x26508e6d, 0x1ea119fa, 0x3d4233dd, 0x2a1462b3];
        uint256 chk = 1;
        for (uint256 p = 0; p < values.length; p++) {
            uint256 top = chk >> 25;
            chk = ((chk & 0x1ffffff) << 5) ^ values[p];
            for (uint256 i = 0; i < 5; i++) {
                if ((top >> i) & 1 == 1) {
                    chk ^= GENERATOR[i];
                }
            }
        }
        return chk;
    }

    function hrpExpand(uint256[] memory hrp) internal pure returns (uint256[] memory) {
        uint256[] memory ret = new uint256[](hrp.length + hrp.length + 1);
        for (uint256 p = 0; p < hrp.length; p++) {
            ret[p] = hrp[p] >> 5;
        }
        ret[hrp.length] = 0;
        for (uint256 p = 0; p < hrp.length; p++) {
            ret[p + hrp.length + 1] = hrp[p] & 31;
        }
        return ret;
    }

    function concat(uint256[] memory left, uint256[] memory right) internal pure returns (uint256[] memory) {
        uint256[] memory ret = new uint256[](left.length + right.length);

        uint256 i = 0;
        for (; i < left.length; i++) {
            ret[i] = left[i];
        }

        uint256 j = 0;
        while (j < right.length) {
            ret[i++] = right[j++];
        }

        return ret;
    }

    function extend(
        uint256[] memory array,
        uint256 val,
        uint256 num
    ) internal pure returns (uint256[] memory) {
        uint256[] memory ret = new uint256[](array.length + num);

        uint256 i = 0;
        for (; i < array.length; i++) {
            ret[i] = array[i];
        }

        uint256 j = 0;
        while (j < num) {
            ret[i++] = val;
            j++;
        }

        return ret;
    }

    function createChecksum(uint256[] memory hrp, uint256[] memory data) internal pure returns (uint256[] memory) {
        uint256[] memory values = extend(concat(hrpExpand(hrp), data), 0, 6);
        uint256 mod = polymod(values) ^ 1;
        uint256[] memory ret = new uint256[](6);
        for (uint256 p = 0; p < 6; p++) {
            ret[p] = (mod >> (5 * (5 - p))) & 31;
        }
        return ret;
    }

    function encode(uint256[] memory hrp, uint256[] memory data) internal pure returns (bytes memory) {
        uint256[] memory combined = concat(data, createChecksum(hrp, data));

        bytes memory ret = new bytes(combined.length);
        for (uint256 p = 0; p < combined.length; p++) {
            ret[p] = CHARSET[combined[p]];
        }

        return ret;
    }

    function convert(
        uint256[] memory data,
        uint256 inBits,
        uint256 outBits
    ) internal pure returns (uint256[] memory) {
        uint256 value = 0;
        uint256 bits = 0;
        uint256 maxV = (1 << outBits) - 1;

        uint256[] memory ret = new uint256[](32);
        uint256 j = 0;
        for (uint256 i = 0; i < data.length; ++i) {
            value = (value << inBits) | data[i];
            bits += inBits;

            while (bits >= outBits) {
                bits -= outBits;
                ret[j] = (value >> bits) & maxV;
                j += 1;
            }
        }

        return ret;
    }
}

File 11 of 12 : Secp256k1.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;

/** @author https://github.com/witnet/elliptic-curve-solidity **/

library EllipticCurve {
    // Pre-computed constant for 2 ** 255
    uint256 private constant U255_MAX_PLUS_1 =
        57896044618658097711785492504343953926634992332820282019728792003956564819968;

    uint256 public constant AA = 0;
    uint256 public constant BB = 7;
    uint256 public constant PP = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F;

    /// @dev Modular exponentiation, b^e % _PP.
    /// Source: https://github.com/androlo/standard-contracts/blob/master/contracts/src/crypto/ECCMath.sol
    /// @param _base base
    /// @param _exp exponent
    /// @return r such that r = b**e (mod _PP)
    function expMod(
        uint256 _base,
        uint256 _exp
    ) internal pure returns (uint256) {
        require(PP != 0, "Modulus is zero");

        if (_base == 0) return 0;
        if (_exp == 0) return 1;

        uint256 r = 1;
        uint256 bit = U255_MAX_PLUS_1;
        assembly {
            for {

            } gt(bit, 0) {

            } {
                r := mulmod(mulmod(r, r, PP), exp(_base, iszero(iszero(and(_exp, bit)))), PP)
                r := mulmod(mulmod(r, r, PP), exp(_base, iszero(iszero(and(_exp, div(bit, 2))))), PP)
                r := mulmod(mulmod(r, r, PP), exp(_base, iszero(iszero(and(_exp, div(bit, 4))))), PP)
                r := mulmod(mulmod(r, r, PP), exp(_base, iszero(iszero(and(_exp, div(bit, 8))))), PP)
                bit := div(bit, 16)
            }
        }

        return r;
    }

    /// @dev Derives the y coordinate from a compressed-format point x [[SEC-1]](https://www.secg.org/SEC1-Ver-1.0.pdf).
    /// @param _prefix parity byte (0x02 even, 0x03 odd)
    /// @param _x coordinate x
    /// @return y coordinate y
    function deriveY(uint8 _prefix, uint256 _x) internal pure returns (uint256) {
        require(_prefix == 0x02 || _prefix == 0x03, "Invalid compressed EC point prefix");

        // x^3 + ax + b
        uint256 y2 = addmod(mulmod(_x, mulmod(_x, _x, PP), PP), addmod(mulmod(_x, AA, PP), BB, PP), PP);
        y2 = expMod(y2, (PP + 1) / 4);
        // uint256 cmp = yBit ^ y_ & 1;
        uint256 y = (y2 + _prefix) % 2 == 0 ? y2 : PP - y2;

        return y;
    }
}

File 12 of 12 : BytesLib.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.5.10;

/*

https://github.com/GNSPS/solidity-bytes-utils/

This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to <https://unlicense.org>
*/

/** @title BytesLib **/
/** @author https://github.com/GNSPS **/

library BytesLib {
    function concat(bytes memory _preBytes, bytes memory _postBytes) internal pure returns (bytes memory) {
        bytes memory tempBytes;

        assembly {
            // Get a location of some free memory and store it in tempBytes as
            // Solidity does for memory variables.
            tempBytes := mload(0x40)

            // Store the length of the first bytes array at the beginning of
            // the memory for tempBytes.
            let length := mload(_preBytes)
            mstore(tempBytes, length)

            // Maintain a memory counter for the current write location in the
            // temp bytes array by adding the 32 bytes for the array length to
            // the starting location.
            let mc := add(tempBytes, 0x20)
            // Stop copying when the memory counter reaches the length of the
            // first bytes array.
            let end := add(mc, length)

            for {
                // Initialize a copy counter to the start of the _preBytes data,
                // 32 bytes into its memory.
                let cc := add(_preBytes, 0x20)
            } lt(mc, end) {
                // Increase both counters by 32 bytes each iteration.
                mc := add(mc, 0x20)
                cc := add(cc, 0x20)
            } {
                // Write the _preBytes data into the tempBytes memory 32 bytes
                // at a time.
                mstore(mc, mload(cc))
            }

            // Add the length of _postBytes to the current length of tempBytes
            // and store it as the new length in the first 32 bytes of the
            // tempBytes memory.
            length := mload(_postBytes)
            mstore(tempBytes, add(length, mload(tempBytes)))

            // Move the memory counter back from a multiple of 0x20 to the
            // actual end of the _preBytes data.
            mc := end
            // Stop copying when the memory counter reaches the new combined
            // length of the arrays.
            end := add(mc, length)

            for {
                let cc := add(_postBytes, 0x20)
            } lt(mc, end) {
                mc := add(mc, 0x20)
                cc := add(cc, 0x20)
            } {
                mstore(mc, mload(cc))
            }

            // Update the free-memory pointer by padding our last write location
            // to 32 bytes: add 31 bytes to the end of tempBytes to move to the
            // next 32 byte block, then round down to the nearest multiple of
            // 32. If the sum of the length of the two arrays is zero then add
            // one before rounding down to leave a blank 32 bytes (the length block with 0).
            mstore(
                0x40,
                and(
                    add(add(end, iszero(add(length, mload(_preBytes)))), 31),
                    not(31) // Round down to the nearest 32 bytes.
                )
            )
        }

        return tempBytes;
    }

    function concatStorage(bytes storage _preBytes, bytes memory _postBytes) internal {
        assembly {
            // Read the first 32 bytes of _preBytes storage, which is the length
            // of the array. (We don't need to use the offset into the slot
            // because arrays use the entire slot.)
            let fslot := sload(_preBytes.slot)
            // Arrays of 31 bytes or less have an even value in their slot,
            // while longer arrays have an odd value. The actual length is
            // the slot divided by two for odd values, and the lowest order
            // byte divided by two for even values.
            // If the slot is even, bitwise and the slot with 255 and divide by
            // two to get the length. If the slot is odd, bitwise and the slot
            // with -1 and divide by two.
            let slength := div(and(fslot, sub(mul(0x100, iszero(and(fslot, 1))), 1)), 2)
            let mlength := mload(_postBytes)
            let newlength := add(slength, mlength)
            // slength can contain both the length and contents of the array
            // if length < 32 bytes so let's prepare for that
            // v. http://solidity.readthedocs.io/en/latest/miscellaneous.html#layout-of-state-variables-in-storage
            switch add(lt(slength, 32), lt(newlength, 32))
            case 2 {
                // Since the new array still fits in the slot, we just need to
                // update the contents of the slot.
                // uint256(bytes_storage) = uint256(bytes_storage) + uint256(bytes_memory) + new_length
                sstore(
                    _preBytes.slot,
                    // all the modifications to the slot are inside this
                    // next block
                    add(
                        // we can just add to the slot contents because the
                        // bytes we want to change are the LSBs
                        fslot,
                        add(
                            mul(
                                div(
                                    // load the bytes from memory
                                    mload(add(_postBytes, 0x20)),
                                    // zero all bytes to the right
                                    exp(0x100, sub(32, mlength))
                                ),
                                // and now shift left the number of bytes to
                                // leave space for the length in the slot
                                exp(0x100, sub(32, newlength))
                            ),
                            // increase length by the double of the memory
                            // bytes length
                            mul(mlength, 2)
                        )
                    )
                )
            }
            case 1 {
                // The stored value fits in the slot, but the combined value
                // will exceed it.
                // get the keccak hash to get the contents of the array
                mstore(0x0, _preBytes.slot)
                let sc := add(keccak256(0x0, 0x20), div(slength, 32))

                // save new length
                sstore(_preBytes.slot, add(mul(newlength, 2), 1))

                // The contents of the _postBytes array start 32 bytes into
                // the structure. Our first read should obtain the `submod`
                // bytes that can fit into the unused space in the last word
                // of the stored array. To get this, we read 32 bytes starting
                // from `submod`, so the data we read overlaps with the array
                // contents by `submod` bytes. Masking the lowest-order
                // `submod` bytes allows us to add that value directly to the
                // stored value.

                let submod := sub(32, slength)
                let mc := add(_postBytes, submod)
                let end := add(_postBytes, mlength)
                let mask := sub(exp(0x100, submod), 1)

                sstore(
                    sc,
                    add(
                        and(fslot, 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00),
                        and(mload(mc), mask)
                    )
                )

                for {
                    mc := add(mc, 0x20)
                    sc := add(sc, 1)
                } lt(mc, end) {
                    sc := add(sc, 1)
                    mc := add(mc, 0x20)
                } {
                    sstore(sc, mload(mc))
                }

                mask := exp(0x100, sub(mc, end))

                sstore(sc, mul(div(mload(mc), mask), mask))
            }
            default {
                // get the keccak hash to get the contents of the array
                mstore(0x0, _preBytes.slot)
                // Start copying to the last used word of the stored array.
                let sc := add(keccak256(0x0, 0x20), div(slength, 32))

                // save new length
                sstore(_preBytes.slot, add(mul(newlength, 2), 1))

                // Copy over the first `submod` bytes of the new data as in
                // case 1 above.
                let slengthmod := mod(slength, 32)
                let mlengthmod := mod(mlength, 32)
                let submod := sub(32, slengthmod)
                let mc := add(_postBytes, submod)
                let end := add(_postBytes, mlength)
                let mask := sub(exp(0x100, submod), 1)

                sstore(sc, add(sload(sc), and(mload(mc), mask)))

                for {
                    sc := add(sc, 1)
                    mc := add(mc, 0x20)
                } lt(mc, end) {
                    sc := add(sc, 1)
                    mc := add(mc, 0x20)
                } {
                    sstore(sc, mload(mc))
                }

                mask := exp(0x100, sub(mc, end))

                sstore(sc, mul(div(mload(mc), mask), mask))
            }
        }
    }

    function slice(
        bytes memory _bytes,
        uint256 _start,
        uint256 _length
    ) internal pure returns (bytes memory res) {
        if (_length == 0) {
            return hex"";
        }
        uint256 _end = _start + _length;
        require(_end > _start && _bytes.length >= _end, "Slice out of bounds");

        assembly {
            // Alloc bytes array with additional 32 bytes afterspace and assign it's size
            res := mload(0x40)
            mstore(0x40, add(add(res, 64), _length))
            mstore(res, _length)

            // Compute distance between source and destination pointers
            let diff := sub(res, add(_bytes, _start))

            for {
                let src := add(add(_bytes, 32), _start)
                let end := add(src, _length)
            } lt(src, end) {
                src := add(src, 32)
            } {
                mstore(add(src, diff), mload(src))
            }
        }
    }

    function toAddress(bytes memory _bytes, uint256 _start) internal pure returns (address) {
        uint256 _totalLen = _start + 20;
        require(_totalLen > _start && _bytes.length >= _totalLen, "Address conversion out of bounds.");
        address tempAddress;

        assembly {
            tempAddress := div(mload(add(add(_bytes, 0x20), _start)), 0x1000000000000000000000000)
        }

        return tempAddress;
    }

    function toUint(bytes memory _bytes, uint256 _start) internal pure returns (uint256) {
        uint256 _totalLen = _start + 32;
        require(_totalLen > _start && _bytes.length >= _totalLen, "Uint conversion out of bounds.");
        uint256 tempUint;

        assembly {
            tempUint := mload(add(add(_bytes, 0x20), _start))
        }

        return tempUint;
    }

    function equal(bytes memory _preBytes, bytes memory _postBytes) internal pure returns (bool) {
        bool success = true;

        assembly {
            let length := mload(_preBytes)

            // if lengths don't match the arrays are not equal
            switch eq(length, mload(_postBytes))
            case 1 {
                // cb is a circuit breaker in the for loop since there's
                //  no said feature for inline assembly loops
                // cb = 1 - don't breaker
                // cb = 0 - break
                let cb := 1

                let mc := add(_preBytes, 0x20)
                let end := add(mc, length)

                for {
                    let cc := add(_postBytes, 0x20)
                    // the next line is the loop condition:
                    // while(uint(mc < end) + cb == 2)
                } eq(add(lt(mc, end), cb), 2) {
                    mc := add(mc, 0x20)
                    cc := add(cc, 0x20)
                } {
                    // if any of these checks fails then arrays are not equal
                    if iszero(eq(mload(mc), mload(cc))) {
                        // unsuccess:
                        success := 0
                        cb := 0
                    }
                }
            }
            default {
                // unsuccess:
                success := 0
            }
        }

        return success;
    }

    function equalStorage(bytes storage _preBytes, bytes memory _postBytes) internal view returns (bool) {
        bool success = true;

        assembly {
            // we know _preBytes_offset is 0
            let fslot := sload(_preBytes.slot)
            // Decode the length of the stored array like in concatStorage().
            let slength := div(and(fslot, sub(mul(0x100, iszero(and(fslot, 1))), 1)), 2)
            let mlength := mload(_postBytes)

            // if lengths don't match the arrays are not equal
            switch eq(slength, mlength)
            case 1 {
                // slength can contain both the length and contents of the array
                // if length < 32 bytes so let's prepare for that
                // v. http://solidity.readthedocs.io/en/latest/miscellaneous.html#layout-of-state-variables-in-storage
                if iszero(iszero(slength)) {
                    switch lt(slength, 32)
                    case 1 {
                        // blank the last byte which is the length
                        fslot := mul(div(fslot, 0x100), 0x100)

                        if iszero(eq(fslot, mload(add(_postBytes, 0x20)))) {
                            // unsuccess:
                            success := 0
                        }
                    }
                    default {
                        // cb is a circuit breaker in the for loop since there's
                        //  no said feature for inline assembly loops
                        // cb = 1 - don't breaker
                        // cb = 0 - break
                        let cb := 1

                        // get the keccak hash to get the contents of the array
                        mstore(0x0, _preBytes.slot)
                        let sc := keccak256(0x0, 0x20)

                        let mc := add(_postBytes, 0x20)
                        let end := add(mc, mlength)

                        // the next line is the loop condition:
                        // while(uint(mc < end) + cb == 2)
                        for {

                        } eq(add(lt(mc, end), cb), 2) {
                            sc := add(sc, 1)
                            mc := add(mc, 0x20)
                        } {
                            if iszero(eq(sload(sc), mload(mc))) {
                                // unsuccess:
                                success := 0
                                cb := 0
                            }
                        }
                    }
                }
            }
            default {
                // unsuccess:
                success := 0
            }
        }

        return success;
    }

    function toBytes32(bytes memory _source) internal pure returns (bytes32 result) {
        if (_source.length == 0) {
            return 0x0;
        }

        assembly {
            result := mload(add(_source, 32))
        }
    }

    function keccak256Slice(
        bytes memory _bytes,
        uint256 _start,
        uint256 _length
    ) internal pure returns (bytes32 result) {
        uint256 _end = _start + _length;
        require(_end > _start && _bytes.length >= _end, "Slice out of bounds");

        assembly {
            result := keccak256(add(add(_bytes, 32), _start), _length)
        }
    }
}

Settings
{
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "libraries": {}
}

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"contract ERC20","name":"_rewardToken","type":"address"},{"internalType":"contract ERC20","name":"_stakeToken","type":"address"},{"internalType":"uint64","name":"_duration","type":"uint64"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"Error_AlreadyInitialized","type":"error"},{"inputs":[],"name":"Error_AmountTooLarge","type":"error"},{"inputs":[],"name":"Error_NotRewardDistributor","type":"error"},{"inputs":[],"name":"Error_ZeroOwner","type":"error"},{"inputs":[],"name":"Ownable_NewOwnerZeroAddress","type":"error"},{"inputs":[],"name":"Ownable_NotOwner","type":"error"},{"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":"RewardAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"reward","type":"uint256"}],"name":"RewardPaid","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Staked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Withdrawn","type":"event"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"duration","outputs":[{"internalType":"uint64","name":"","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"earned","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"exit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getReward","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"isRewardDistributor","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lastTimeRewardApplicable","outputs":[{"internalType":"uint64","name":"","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lastUpdateTime","outputs":[{"internalType":"uint64","name":"","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes[]","name":"data","type":"bytes[]"}],"name":"multicall","outputs":[{"internalType":"bytes[]","name":"results","type":"bytes[]"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"reward","type":"uint256"}],"name":"notifyRewardAmount","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"periodFinish","outputs":[{"internalType":"uint64","name":"","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rewardPerToken","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rewardPerTokenStored","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rewardRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rewardToken","outputs":[{"internalType":"contract ERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"rewards","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract ERC20","name":"token","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"selfPermit","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"contract ERC20","name":"token","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"selfPermitIfNecessary","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"rewardDistributor","type":"address"},{"internalType":"bool","name":"isRewardDistributor_","type":"bool"}],"name":"setRewardDistributor","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"stake","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"stakeToken","outputs":[{"internalType":"contract ERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"startedStaking","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","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":"address","name":"","type":"address"}],"name":"userRewardPerTokenPaid","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"}]

60e06040523480156200001157600080fd5b5060405162001917380380620019178339810160408190526200003491620000d5565b6001600160a01b03808416608052821660a0526001600160401b03811660c0526200005f3362000068565b5050506200012f565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b80516001600160a01b0381168114620000d057600080fd5b919050565b600080600060608486031215620000eb57600080fd5b620000f684620000b8565b92506200010660208501620000b8565b60408501519092506001600160401b03811681146200012457600080fd5b809150509250925092565b60805160a05160c05161178e6200018960003960008181610212015261077d01526000818161030b015281816106ae01528181610bc60152610ef5015260008181610554015281816109e30152610f64015261178e6000f3fe60806040526004361061019b5760003560e01c806380faa57d116100ec578063cd3daf9d1161008a578063ebe2b12b11610064578063ebe2b12b146104ef578063f2fde38b1461050f578063f3995c671461052f578063f7c618c11461054257600080fd5b8063cd3daf9d146104af578063df136d65146104c4578063e9fad8ee146104da57600080fd5b8063a694fc3a116100c6578063a694fc3a14610435578063ac9650d814610455578063c2e3140a14610475578063c8f33c911461048857600080fd5b806380faa57d146103d55780638b876347146103ea5780638da5cb5b1461041757600080fd5b80633c6b16ab1161015957806370a082311161013357806370a08231146103455780637b0a47ee146103725780637fe1ba631461038857806380e59f8d146103b557600080fd5b80633c6b16ab146102c45780633d18b912146102e457806351ed6a30146102f957600080fd5b80628cc262146101a05780630700037d146101d35780630fb5a6b41461020057806316ed85251461024c57806318160ddd1461028c5780632e1a7d4d146102a2575b600080fd5b3480156101ac57600080fd5b506101c06101bb366004611354565b610576565b6040519081526020015b60405180910390f35b3480156101df57600080fd5b506101c06101ee366004611354565b60096020526000908152604090205481565b34801561020c57600080fd5b506102347f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160401b0390911681526020016101ca565b34801561025857600080fd5b5061027c610267366004611354565b60056020526000908152604090205460ff1681565b60405190151581526020016101ca565b34801561029857600080fd5b506101c060045481565b3480156102ae57600080fd5b506102c26102bd366004611371565b6105d9565b005b3480156102d057600080fd5b506102c26102df366004611371565b61071a565b3480156102f057600080fd5b506102c2610930565b34801561030557600080fd5b5061032d7f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b0390911681526020016101ca565b34801561035157600080fd5b506101c0610360366004611354565b60076020526000908152604090205481565b34801561037e57600080fd5b506101c060025481565b34801561039457600080fd5b506101c06103a3366004611354565b60066020526000908152604090205481565b3480156103c157600080fd5b506102c26103d036600461138a565b610a4b565b3480156103e157600080fd5b50610234610ab0565b3480156103f657600080fd5b506101c0610405366004611354565b60086020526000908152604090205481565b34801561042357600080fd5b506000546001600160a01b031661032d565b34801561044157600080fd5b506102c2610450366004611371565b610adc565b6104686104633660046113c8565b610c28565b6040516101ca9190611494565b6102c26104833660046114f6565b610d88565b34801561049457600080fd5b5060005461023490600160a01b90046001600160401b031681565b3480156104bb57600080fd5b506101c0610e14565b3480156104d057600080fd5b506101c060035481565b3480156104e657600080fd5b506102c2610e24565b3480156104fb57600080fd5b50600154610234906001600160401b031681565b34801561051b57600080fd5b506102c261052a366004611354565b610f8b565b6102c261053d3660046114f6565b610ff8565b34801561054e57600080fd5b5061032d7f000000000000000000000000000000000000000000000000000000000000000081565b6001600160a01b0381166000908152600760205260408120546004546105d39184916105b5906105a4610ab0565b6001600160401b0316600254611084565b6001600160a01b0386166000908152600960205260409020546110ef565b92915050565b806000036105e45750565b33600090815260076020526040812054906105fd610ab0565b905060006004549050600061061e82846001600160401b0316600254611084565b60038190556000805467ffffffffffffffff60a01b1916600160a01b6001600160401b0387160217815533808252600960205260409091205491925061066791869084906110ef565b33600090815260096020908152604080832093909355600890522081905561068f858561156e565b336000818152600760205260409020919091558583036004556106dd907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169087611140565b60405185815233907f7084f5476618d8e60b11ef0d7d3f06914655adb8793e28ff7f018d4c76d505d5906020015b60405180910390a25050505050565b806000036107255750565b3360009081526005602052604090205460ff166107555760405163434e91f160e01b815260040160405180910390fd5b6002546001546001600160401b031660004282116107735781610775565b425b6004549091507f0000000000000000000000000000000000000000000000000000000000000000906107b1816001600160401b03851687611084565b600355600080546001600160401b03808616600160a01b0267ffffffffffffffff60a01b1990921691909117825585164210610801576107fa6001600160401b03841688611585565b9050610849565b6000610816426001600160401b03881661156e565b9050600061082488836115a7565b90506001600160401b03851661083a828b6115c6565b6108449190611585565b925050505b6001600160401b03831661086c6c0c9f2c9cd04674edea40000000600019611585565b6108769190611585565b8110610895576040516398bb2e4560e01b815260040160405180910390fd5b6002819055600080546001600160401b0342818116600160a01b0267ffffffffffffffff60a01b19909316929092179092556108d3918516906115c6565b6001805467ffffffffffffffff19166001600160401b03929092169190911790556040518781527fde88a922e0d3b88b24e9623efeb464919c6bf9f66857a65e2bfcf2ce87a9433d9060200160405180910390a150505050505050565b3360009081526007602052604081205490610949610ab0565b905060006004549050600061096a82846001600160401b0316600254611084565b336000818152600960205260408120549293509161098c9190879085906110ef565b60038390556000805467ffffffffffffffff60a01b1916600160a01b6001600160401b0388160217815533815260086020526040902083905590508015610a445733600081815260096020526040812055610a12907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169083611140565b60405181815233907fe2403640ba68fed3a2f88b7557551d1993f84b99bb10ff833f0cf8db0c5e04869060200161070b565b5050505050565b33610a5e6000546001600160a01b031690565b6001600160a01b031614610a8557604051635eee3ad160e01b815260040160405180910390fd5b6001600160a01b03919091166000908152600560205260409020805460ff1916911515919091179055565b6001546000906001600160401b03164210610ad557506001546001600160401b031690565b425b905090565b80600003610ae75750565b3360009081526007602052604081205490610b00610ab0565b9050600060045490506000610b2182846001600160401b0316600254611084565b60038190556000805467ffffffffffffffff60a01b1916600160a01b6001600160401b03871602178155338082526009602052604090912054919250610b6a91869084906110ef565b336000908152600960209081526040808320939093556008905220819055610b9285836115c6565b600455610b9f85856115c6565b336000818152600760209081526040808320949094556006905291909120429055610bf6907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169030886111be565b60405185815233907f9e71bc8eea02a63969f509818f2dafb9254532904319f9dbda79b67bd34a5f3d9060200161070b565b6060816001600160401b03811115610c4257610c426115de565b604051908082528060200260200182016040528015610c7557816020015b6060815260200190600190039081610c605790505b50905060005b82811015610d815760008030868685818110610c9957610c996115f4565b9050602002810190610cab919061160a565b604051610cb9929190611657565b600060405180830381855af49150503d8060008114610cf4576040519150601f19603f3d011682016040523d82523d6000602084013e610cf9565b606091505b509150915081610d4e57604481511015610d1257600080fd5b60048101905080806020019051810190610d2c9190611667565b60405162461bcd60e51b8152600401610d459190611713565b60405180910390fd5b80848481518110610d6157610d616115f4565b602002602001018190525050508080610d7990611726565b915050610c7b565b5092915050565b604051636eb1769f60e11b815233600482015230602482015285906001600160a01b0388169063dd62ed3e90604401602060405180830381865afa158015610dd4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610df8919061173f565b1015610e0c57610e0c868686868686610ff8565b505050505050565b6000610ad76004546105a4610ab0565b3360009081526007602052604081205490610e3d610ab0565b9050600060045490506000610e5e82846001600160401b0316600254611084565b3360008181526009602052604081205492935091610e809190879085906110ef565b90508015610e9957336000908152600960205260408120555b60038290556000805467ffffffffffffffff60a01b1916600160a01b6001600160401b03871602178155338082526008602090815260408084208690556007909152822091909155858403600455610f1c906001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169087611140565b60405185815233907f7084f5476618d8e60b11ef0d7d3f06914655adb8793e28ff7f018d4c76d505d59060200160405180910390a28015610a4457610a126001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000163383611140565b33610f9e6000546001600160a01b031690565b6001600160a01b031614610fc557604051635eee3ad160e01b815260040160405180910390fd5b6001600160a01b038116610fec57604051633b7c6c7f60e21b815260040160405180910390fd5b610ff581611241565b50565b60405163d505accf60e01b8152336004820152306024820152604481018690526064810185905260ff8416608482015260a4810183905260c481018290526001600160a01b0387169063d505accf9060e401600060405180830381600087803b15801561106457600080fd5b505af1158015611078573d6000803e3d6000fd5b50505050505050505050565b60008360000361109757506003546110e8565b6000546110d8906c0c9f2c9cd04674edea40000000906110c790600160a01b90046001600160401b03168661156e565b6110d191906115a7565b8386611291565b6003546110e591906115c6565b90505b9392505050565b6001600160a01b038416600090815260086020526040812054829061112d90869061111a908761156e565b6c0c9f2c9cd04674edea40000000611291565b61113791906115c6565b95945050505050565b600060405163a9059cbb60e01b8152836004820152826024820152602060006044836000895af13d15601f3d11600160005114161716915050806111b85760405162461bcd60e51b815260206004820152600f60248201526e1514905394d1915497d19052531151608a1b6044820152606401610d45565b50505050565b60006040516323b872dd60e01b81528460048201528360248201528260448201526020600060648360008a5af13d15601f3d1160016000511416171691505080610a445760405162461bcd60e51b81526020600482015260146024820152731514905394d1915497d19493d357d1905253115160621b6044820152606401610d45565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b60008080600019858709858702925082811083820303915050806000036112ca57600084116112bf57600080fd5b5082900490506110e8565b8084116112d657600080fd5b60008486880960026001871981018816978890046003810283188082028403028082028403028082028403028082028403028082028403029081029092039091026000889003889004909101858311909403939093029303949094049190911702949350505050565b6001600160a01b0381168114610ff557600080fd5b60006020828403121561136657600080fd5b81356110e88161133f565b60006020828403121561138357600080fd5b5035919050565b6000806040838503121561139d57600080fd5b82356113a88161133f565b9150602083013580151581146113bd57600080fd5b809150509250929050565b600080602083850312156113db57600080fd5b82356001600160401b03808211156113f257600080fd5b818501915085601f83011261140657600080fd5b81358181111561141557600080fd5b8660208260051b850101111561142a57600080fd5b60209290920196919550909350505050565b60005b8381101561145757818101518382015260200161143f565b838111156111b85750506000910152565b6000815180845261148081602086016020860161143c565b601f01601f19169290920160200192915050565b6000602080830181845280855180835260408601915060408160051b870101925083870160005b828110156114e957603f198886030184526114d7858351611468565b945092850192908501906001016114bb565b5092979650505050505050565b60008060008060008060c0878903121561150f57600080fd5b863561151a8161133f565b95506020870135945060408701359350606087013560ff8116811461153e57600080fd5b9598949750929560808101359460a0909101359350915050565b634e487b7160e01b600052601160045260246000fd5b60008282101561158057611580611558565b500390565b6000826115a257634e487b7160e01b600052601260045260246000fd5b500490565b60008160001904831182151516156115c1576115c1611558565b500290565b600082198211156115d9576115d9611558565b500190565b634e487b7160e01b600052604160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b6000808335601e1984360301811261162157600080fd5b8301803591506001600160401b0382111561163b57600080fd5b60200191503681900382131561165057600080fd5b9250929050565b8183823760009101908152919050565b60006020828403121561167957600080fd5b81516001600160401b038082111561169057600080fd5b818401915084601f8301126116a457600080fd5b8151818111156116b6576116b66115de565b604051601f8201601f19908116603f011681019083821181831017156116de576116de6115de565b816040528281528760208487010111156116f757600080fd5b61170883602083016020880161143c565b979650505050505050565b6020815260006110e86020830184611468565b60006001820161173857611738611558565b5060010190565b60006020828403121561175157600080fd5b505191905056fea2646970667358221220cac6cff8ee7fb088ce161a60102bc5852f36a741443f635d00d3a903180fac9c64736f6c634300080d003300000000000000000000000032bc49b6c3183437d3e2eaac357415d067e420510000000000000000000000007d5fc209409919574a8a34a75a09262fe49547040000000000000000000000000000000000000000000000000000000001e13380

Deployed Bytecode

0x60806040526004361061019b5760003560e01c806380faa57d116100ec578063cd3daf9d1161008a578063ebe2b12b11610064578063ebe2b12b146104ef578063f2fde38b1461050f578063f3995c671461052f578063f7c618c11461054257600080fd5b8063cd3daf9d146104af578063df136d65146104c4578063e9fad8ee146104da57600080fd5b8063a694fc3a116100c6578063a694fc3a14610435578063ac9650d814610455578063c2e3140a14610475578063c8f33c911461048857600080fd5b806380faa57d146103d55780638b876347146103ea5780638da5cb5b1461041757600080fd5b80633c6b16ab1161015957806370a082311161013357806370a08231146103455780637b0a47ee146103725780637fe1ba631461038857806380e59f8d146103b557600080fd5b80633c6b16ab146102c45780633d18b912146102e457806351ed6a30146102f957600080fd5b80628cc262146101a05780630700037d146101d35780630fb5a6b41461020057806316ed85251461024c57806318160ddd1461028c5780632e1a7d4d146102a2575b600080fd5b3480156101ac57600080fd5b506101c06101bb366004611354565b610576565b6040519081526020015b60405180910390f35b3480156101df57600080fd5b506101c06101ee366004611354565b60096020526000908152604090205481565b34801561020c57600080fd5b506102347f0000000000000000000000000000000000000000000000000000000001e1338081565b6040516001600160401b0390911681526020016101ca565b34801561025857600080fd5b5061027c610267366004611354565b60056020526000908152604090205460ff1681565b60405190151581526020016101ca565b34801561029857600080fd5b506101c060045481565b3480156102ae57600080fd5b506102c26102bd366004611371565b6105d9565b005b3480156102d057600080fd5b506102c26102df366004611371565b61071a565b3480156102f057600080fd5b506102c2610930565b34801561030557600080fd5b5061032d7f0000000000000000000000007d5fc209409919574a8a34a75a09262fe495470481565b6040516001600160a01b0390911681526020016101ca565b34801561035157600080fd5b506101c0610360366004611354565b60076020526000908152604090205481565b34801561037e57600080fd5b506101c060025481565b34801561039457600080fd5b506101c06103a3366004611354565b60066020526000908152604090205481565b3480156103c157600080fd5b506102c26103d036600461138a565b610a4b565b3480156103e157600080fd5b50610234610ab0565b3480156103f657600080fd5b506101c0610405366004611354565b60086020526000908152604090205481565b34801561042357600080fd5b506000546001600160a01b031661032d565b34801561044157600080fd5b506102c2610450366004611371565b610adc565b6104686104633660046113c8565b610c28565b6040516101ca9190611494565b6102c26104833660046114f6565b610d88565b34801561049457600080fd5b5060005461023490600160a01b90046001600160401b031681565b3480156104bb57600080fd5b506101c0610e14565b3480156104d057600080fd5b506101c060035481565b3480156104e657600080fd5b506102c2610e24565b3480156104fb57600080fd5b50600154610234906001600160401b031681565b34801561051b57600080fd5b506102c261052a366004611354565b610f8b565b6102c261053d3660046114f6565b610ff8565b34801561054e57600080fd5b5061032d7f00000000000000000000000032bc49b6c3183437d3e2eaac357415d067e4205181565b6001600160a01b0381166000908152600760205260408120546004546105d39184916105b5906105a4610ab0565b6001600160401b0316600254611084565b6001600160a01b0386166000908152600960205260409020546110ef565b92915050565b806000036105e45750565b33600090815260076020526040812054906105fd610ab0565b905060006004549050600061061e82846001600160401b0316600254611084565b60038190556000805467ffffffffffffffff60a01b1916600160a01b6001600160401b0387160217815533808252600960205260409091205491925061066791869084906110ef565b33600090815260096020908152604080832093909355600890522081905561068f858561156e565b336000818152600760205260409020919091558583036004556106dd907f0000000000000000000000007d5fc209409919574a8a34a75a09262fe49547046001600160a01b03169087611140565b60405185815233907f7084f5476618d8e60b11ef0d7d3f06914655adb8793e28ff7f018d4c76d505d5906020015b60405180910390a25050505050565b806000036107255750565b3360009081526005602052604090205460ff166107555760405163434e91f160e01b815260040160405180910390fd5b6002546001546001600160401b031660004282116107735781610775565b425b6004549091507f0000000000000000000000000000000000000000000000000000000001e13380906107b1816001600160401b03851687611084565b600355600080546001600160401b03808616600160a01b0267ffffffffffffffff60a01b1990921691909117825585164210610801576107fa6001600160401b03841688611585565b9050610849565b6000610816426001600160401b03881661156e565b9050600061082488836115a7565b90506001600160401b03851661083a828b6115c6565b6108449190611585565b925050505b6001600160401b03831661086c6c0c9f2c9cd04674edea40000000600019611585565b6108769190611585565b8110610895576040516398bb2e4560e01b815260040160405180910390fd5b6002819055600080546001600160401b0342818116600160a01b0267ffffffffffffffff60a01b19909316929092179092556108d3918516906115c6565b6001805467ffffffffffffffff19166001600160401b03929092169190911790556040518781527fde88a922e0d3b88b24e9623efeb464919c6bf9f66857a65e2bfcf2ce87a9433d9060200160405180910390a150505050505050565b3360009081526007602052604081205490610949610ab0565b905060006004549050600061096a82846001600160401b0316600254611084565b336000818152600960205260408120549293509161098c9190879085906110ef565b60038390556000805467ffffffffffffffff60a01b1916600160a01b6001600160401b0388160217815533815260086020526040902083905590508015610a445733600081815260096020526040812055610a12907f00000000000000000000000032bc49b6c3183437d3e2eaac357415d067e420516001600160a01b03169083611140565b60405181815233907fe2403640ba68fed3a2f88b7557551d1993f84b99bb10ff833f0cf8db0c5e04869060200161070b565b5050505050565b33610a5e6000546001600160a01b031690565b6001600160a01b031614610a8557604051635eee3ad160e01b815260040160405180910390fd5b6001600160a01b03919091166000908152600560205260409020805460ff1916911515919091179055565b6001546000906001600160401b03164210610ad557506001546001600160401b031690565b425b905090565b80600003610ae75750565b3360009081526007602052604081205490610b00610ab0565b9050600060045490506000610b2182846001600160401b0316600254611084565b60038190556000805467ffffffffffffffff60a01b1916600160a01b6001600160401b03871602178155338082526009602052604090912054919250610b6a91869084906110ef565b336000908152600960209081526040808320939093556008905220819055610b9285836115c6565b600455610b9f85856115c6565b336000818152600760209081526040808320949094556006905291909120429055610bf6907f0000000000000000000000007d5fc209409919574a8a34a75a09262fe49547046001600160a01b03169030886111be565b60405185815233907f9e71bc8eea02a63969f509818f2dafb9254532904319f9dbda79b67bd34a5f3d9060200161070b565b6060816001600160401b03811115610c4257610c426115de565b604051908082528060200260200182016040528015610c7557816020015b6060815260200190600190039081610c605790505b50905060005b82811015610d815760008030868685818110610c9957610c996115f4565b9050602002810190610cab919061160a565b604051610cb9929190611657565b600060405180830381855af49150503d8060008114610cf4576040519150601f19603f3d011682016040523d82523d6000602084013e610cf9565b606091505b509150915081610d4e57604481511015610d1257600080fd5b60048101905080806020019051810190610d2c9190611667565b60405162461bcd60e51b8152600401610d459190611713565b60405180910390fd5b80848481518110610d6157610d616115f4565b602002602001018190525050508080610d7990611726565b915050610c7b565b5092915050565b604051636eb1769f60e11b815233600482015230602482015285906001600160a01b0388169063dd62ed3e90604401602060405180830381865afa158015610dd4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610df8919061173f565b1015610e0c57610e0c868686868686610ff8565b505050505050565b6000610ad76004546105a4610ab0565b3360009081526007602052604081205490610e3d610ab0565b9050600060045490506000610e5e82846001600160401b0316600254611084565b3360008181526009602052604081205492935091610e809190879085906110ef565b90508015610e9957336000908152600960205260408120555b60038290556000805467ffffffffffffffff60a01b1916600160a01b6001600160401b03871602178155338082526008602090815260408084208690556007909152822091909155858403600455610f1c906001600160a01b037f0000000000000000000000007d5fc209409919574a8a34a75a09262fe4954704169087611140565b60405185815233907f7084f5476618d8e60b11ef0d7d3f06914655adb8793e28ff7f018d4c76d505d59060200160405180910390a28015610a4457610a126001600160a01b037f00000000000000000000000032bc49b6c3183437d3e2eaac357415d067e42051163383611140565b33610f9e6000546001600160a01b031690565b6001600160a01b031614610fc557604051635eee3ad160e01b815260040160405180910390fd5b6001600160a01b038116610fec57604051633b7c6c7f60e21b815260040160405180910390fd5b610ff581611241565b50565b60405163d505accf60e01b8152336004820152306024820152604481018690526064810185905260ff8416608482015260a4810183905260c481018290526001600160a01b0387169063d505accf9060e401600060405180830381600087803b15801561106457600080fd5b505af1158015611078573d6000803e3d6000fd5b50505050505050505050565b60008360000361109757506003546110e8565b6000546110d8906c0c9f2c9cd04674edea40000000906110c790600160a01b90046001600160401b03168661156e565b6110d191906115a7565b8386611291565b6003546110e591906115c6565b90505b9392505050565b6001600160a01b038416600090815260086020526040812054829061112d90869061111a908761156e565b6c0c9f2c9cd04674edea40000000611291565b61113791906115c6565b95945050505050565b600060405163a9059cbb60e01b8152836004820152826024820152602060006044836000895af13d15601f3d11600160005114161716915050806111b85760405162461bcd60e51b815260206004820152600f60248201526e1514905394d1915497d19052531151608a1b6044820152606401610d45565b50505050565b60006040516323b872dd60e01b81528460048201528360248201528260448201526020600060648360008a5af13d15601f3d1160016000511416171691505080610a445760405162461bcd60e51b81526020600482015260146024820152731514905394d1915497d19493d357d1905253115160621b6044820152606401610d45565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b60008080600019858709858702925082811083820303915050806000036112ca57600084116112bf57600080fd5b5082900490506110e8565b8084116112d657600080fd5b60008486880960026001871981018816978890046003810283188082028403028082028403028082028403028082028403028082028403029081029092039091026000889003889004909101858311909403939093029303949094049190911702949350505050565b6001600160a01b0381168114610ff557600080fd5b60006020828403121561136657600080fd5b81356110e88161133f565b60006020828403121561138357600080fd5b5035919050565b6000806040838503121561139d57600080fd5b82356113a88161133f565b9150602083013580151581146113bd57600080fd5b809150509250929050565b600080602083850312156113db57600080fd5b82356001600160401b03808211156113f257600080fd5b818501915085601f83011261140657600080fd5b81358181111561141557600080fd5b8660208260051b850101111561142a57600080fd5b60209290920196919550909350505050565b60005b8381101561145757818101518382015260200161143f565b838111156111b85750506000910152565b6000815180845261148081602086016020860161143c565b601f01601f19169290920160200192915050565b6000602080830181845280855180835260408601915060408160051b870101925083870160005b828110156114e957603f198886030184526114d7858351611468565b945092850192908501906001016114bb565b5092979650505050505050565b60008060008060008060c0878903121561150f57600080fd5b863561151a8161133f565b95506020870135945060408701359350606087013560ff8116811461153e57600080fd5b9598949750929560808101359460a0909101359350915050565b634e487b7160e01b600052601160045260246000fd5b60008282101561158057611580611558565b500390565b6000826115a257634e487b7160e01b600052601260045260246000fd5b500490565b60008160001904831182151516156115c1576115c1611558565b500290565b600082198211156115d9576115d9611558565b500190565b634e487b7160e01b600052604160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b6000808335601e1984360301811261162157600080fd5b8301803591506001600160401b0382111561163b57600080fd5b60200191503681900382131561165057600080fd5b9250929050565b8183823760009101908152919050565b60006020828403121561167957600080fd5b81516001600160401b038082111561169057600080fd5b818401915084601f8301126116a457600080fd5b8151818111156116b6576116b66115de565b604051601f8201601f19908116603f011681019083821181831017156116de576116de6115de565b816040528281528760208487010111156116f757600080fd5b61170883602083016020880161143c565b979650505050505050565b6020815260006110e86020830184611468565b60006001820161173857611738611558565b5060010190565b60006020828403121561175157600080fd5b505191905056fea2646970667358221220cac6cff8ee7fb088ce161a60102bc5852f36a741443f635d00d3a903180fac9c64736f6c634300080d0033

Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)

00000000000000000000000032bc49b6c3183437d3e2eaac357415d067e420510000000000000000000000007d5fc209409919574a8a34a75a09262fe49547040000000000000000000000000000000000000000000000000000000001e13380

-----Decoded View---------------
Arg [0] : _rewardToken (address): 0x32BC49b6c3183437D3e2EAac357415D067E42051
Arg [1] : _stakeToken (address): 0x7d5Fc209409919574A8a34A75A09262fe4954704
Arg [2] : _duration (uint64): 31536000

-----Encoded View---------------
3 Constructor Arguments found :
Arg [0] : 00000000000000000000000032bc49b6c3183437d3e2eaac357415d067e42051
Arg [1] : 0000000000000000000000007d5fc209409919574a8a34a75a09262fe4954704
Arg [2] : 0000000000000000000000000000000000000000000000000000000001e13380


Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading
Loading...
Loading

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
Loading...
Loading
[ Download: CSV Export  ]

A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.