Address io1wnvqjc737tdc2d47yk5mvxxxa4azp52qv7u22z

Contract Overview

Balance:
0 IOTX

IOTX Value:
$ 0

Token:
Txn Hash
Block
From
To
Value [Txn Fee]
953c14ef888e9bdd2133582a4171727ece7b96a7c26590d0db4574e6e6887e91 29187994 2024-03-28 23:22:55 +0000 UTC 2 hours ago io1zcg6vwvt478ammp2252plr3gfvfu6xxvmpsg7n  IN    Contract: KnowFarm 0 IOTX 0.327028
de4b061ec5db5235cbdbc0a40b72d547ed0d6270c4cec0370f53f5dc0f6e5498 29187327 2024-03-28 22:27:20 +0000 UTC 3 hours ago io1jqlmnqguqe08p9hjk3szmyem4m3llsqljtaa97  IN    Contract: KnowFarm 0 IOTX 0.232396
237d5f0e90779bb6e0e6efde2f8785d5e84a4e35bd149e75b56876a00ed9a9b7 29181573 2024-03-28 14:25:20 +0000 UTC 11 hours ago io127exjwqphnkax9qzwkaemjxv8au6stetl0lv8a  IN    Contract: KnowFarm 0 IOTX 0.232396
e701e6f37f54b6a7b48d1c20176359080bfb58afb7ecc5132be2f8cb8b5d8d2c 29179016 2024-03-28 10:49:45 +0000 UTC 14 hours ago io1fdx9rqf253s43v9zk3u88putlhvg204vw0rlqg  IN    Contract: KnowFarm 0 IOTX 0.265648
57584d4a894386efc31c1ec9f87b620d0a41b3789b88292f6846ca622b4ff28d 29179013 2024-03-28 10:49:30 +0000 UTC 14 hours ago io1fdx9rqf253s43v9zk3u88putlhvg204vw0rlqg  IN    Contract: KnowFarm 0 IOTX 0.266596
acc4d7a4603242569e31dfffe55024694246db65a4e15bbaaf19b99c00576bc8 29174341 2024-03-28 04:18:40 +0000 UTC 21 hours ago io1fdx9rqf253s43v9zk3u88putlhvg204vw0rlqg  IN    Contract: KnowFarm 0 IOTX 0.327028
006bd223561e027ac4d1be8f6454346c6a6c638bd76bc733c5d454d1198c2954 29165082 2024-03-27 15:26:05 +0000 UTC one day ago io1pt6hxscvwwn6w7n29jtw5p6zpzfmapnxcr5dpl  IN    Contract: KnowFarm 0 IOTX 0.266596
0381b3bc66051ba4e23e4952b8aec176b33f26274285c6cb21a033838d6d7287 29159427 2024-03-27 07:34:50 +0000 UTC 2 days ago io1wsqj79279k346nuwjhhm0xrklzcsu2j5k4r8sh  IN    Contract: KnowFarm 0 IOTX 0.232396
58cec52307003b256d52c60beef232db251b7a012edcc7272d3d0ba6e6ee424b 29157265 2024-03-27 04:34:40 +0000 UTC 2 days ago io1ue5d4phj3720x6htrgslra0mm35pyvl9d3v06a  IN    Contract: KnowFarm 0 IOTX 0.116198
58818a21fae93a7d277738c116526d93e39f348ca5fb9039c06ce2944737e5ca 29156734 2024-03-27 03:50:25 +0000 UTC 2 days ago io1jqlmnqguqe08p9hjk3szmyem4m3llsqljtaa97  IN    Contract: KnowFarm 0 IOTX 0.284508
ca737feec994160f42c6f5d8338a23d25c199392fc6d3c9e95df2c2928af4343 29145242 2024-03-26 11:52:20 +0000 UTC 3 days ago io19e6cuhdv8zlqw3k767aq4d0v85yw6yy9v5jhlr  IN    Contract: KnowFarm 0 IOTX 0.232396
b0d591cc8c2fc146f9cffbd5704d80829976e2abcc25a94d3ea1ea22285e1598 29139163 2024-03-26 03:25:35 +0000 UTC 3 days ago io1jqlmnqguqe08p9hjk3szmyem4m3llsqljtaa97  IN    Contract: KnowFarm 0 IOTX 0.232396
4efce1174d25d77d73661c2756aa6e722c895fbd6c9428c02096d1f9a052ebff 29137975 2024-03-26 01:46:35 +0000 UTC 3 days ago io1kp2q36vrcdanz5n7l3wuurz7mrv675g7n8pqc0  IN    Contract: KnowFarm 0 IOTX 0.284508
e2a07073c8ecf8c4fbf2d1091879b2c4f6efdac1a4599d78a424d531deade22c 29129385 2024-03-25 13:50:45 +0000 UTC 3 days ago io19cqf9p04tftk4klpvpf9n4z3ynkluf03tfa7aa  IN    Contract: KnowFarm 0 IOTX 0.66412
40be9e51c68b94ac9b0e26988abbe68e21daf54826e5e175581e73b67e042fd4 29127268 2024-03-25 10:54:15 +0000 UTC 4 days ago io1k8kvqmz36ffrz32xt37zc2vnph287k28xkeskn  IN    Contract: KnowFarm 0 IOTX 0.300147
bb8da3c678bfa3a9861d21e3ddd0903cfdbcd184d29c7d8cd0438358ae73fbc0 29120612 2024-03-25 01:39:35 +0000 UTC 4 days ago io1k73gemevwq6kgzhuxgczxpvkzm2hmyzv90uj04  IN    Contract: KnowFarm 0 IOTX 0.232396
7906276043fdb815d0b68a41f441f2658f08bd8e078b06a57f3e9c97c6603ee4 29120311 2024-03-25 01:14:30 +0000 UTC 4 days ago io1wsqj79279k346nuwjhhm0xrklzcsu2j5k4r8sh  IN    Contract: KnowFarm 0 IOTX 0.232396
e7ff12920f6d792d97746c2ea2360c7a337e9cd3e180874954b434b5b257d028 29115743 2024-03-24 18:53:50 +0000 UTC 4 days ago io1aw7v6vhlja3qtjnlt2slgmhxx68gkms0a0c0ed  IN    Contract: KnowFarm 0 IOTX 0.327028
eba047c33ebe679bf495a7dd41307bd40c6b248d584d2828a3360421b2f6faf5 29115591 2024-03-24 18:41:10 +0000 UTC 4 days ago io1aw7v6vhlja3qtjnlt2slgmhxx68gkms0a0c0ed  IN    Contract: KnowFarm 0 IOTX 0.200652
b3db6dfcd221e2c8ef5cd5ad81315b1e6fc835a7f54065656a2f0407730d3ddf 29115584 2024-03-24 18:40:35 +0000 UTC 4 days ago io1aw7v6vhlja3qtjnlt2slgmhxx68gkms0a0c0ed  IN    Contract: KnowFarm 0 IOTX 0.19777
5af5a48a7b86305f6414fc4818431ff1c4910fefdee103d8351735fc7c0afb00 29111009 2024-03-24 12:19:20 +0000 UTC 5 days ago io1m9qhrhg93pl5nzj83fjt4cq3zs6a9nxlkmvv27  IN    Contract: KnowFarm 0 IOTX 0.266596
0e87f7f5960713bf533373c5b021f2d8db9e9150d098ecee414a82cc0ca486a2 29109914 2024-03-24 10:48:05 +0000 UTC 5 days ago io19e6cuhdv8zlqw3k767aq4d0v85yw6yy9v5jhlr  IN    Contract: KnowFarm 0 IOTX 0.232396
6770b039b069b13827148b2e8cffafe48a533cd0dd9283fe5f32859f87b7d4af 29103388 2024-03-24 01:44:15 +0000 UTC 5 days ago io10u8l4z2s4x2360gnu0240nqxdkng3a8wd2d8lu  IN    Contract: KnowFarm 0 IOTX 0.265648
b1f9c19bdadac9ab5741dcde88cfed71516d6deb8c163a7125c42c159a0aad2d 29103382 2024-03-24 01:43:45 +0000 UTC 5 days ago io10u8l4z2s4x2360gnu0240nqxdkng3a8wd2d8lu  IN    Contract: KnowFarm 0 IOTX 0.232396
65323fe5f9c08cd3e54599e7f50cbb0f4c5e5a0fe09b336ed29bd07b19a0a835 29101891 2024-03-23 23:39:30 +0000 UTC 5 days ago io1k8kvqmz36ffrz32xt37zc2vnph287k28xkeskn  IN    Contract: KnowFarm 0 IOTX 0.79677
Parent Txn Hash Block From To Value
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
KnowFarm

Compiler Version
v0.8.13+commit.abaa5c0e

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion, None license

Contract Source Code (Solidity)

// File: @openzeppelin/contracts/security/ReentrancyGuard.sol


// OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol)

pragma solidity ^0.8.0;

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
abstract contract ReentrancyGuard {
    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

    // The values being non-zero value makes deployment a bit more expensive,
    // but in exchange the refund on every call to nonReentrant will be lower in
    // amount. Since refunds are capped to a percentage of the total
    // transaction's gas, it is best to keep them low in cases like this one, to
    // increase the likelihood of the full refund coming into effect.
    uint256 private constant _NOT_ENTERED = 1;
    uint256 private constant _ENTERED = 2;

    uint256 private _status;

    constructor() {
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        // On the first call to nonReentrant, _notEntered will be true
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

        // Any calls to nonReentrant after this point will fail
        _status = _ENTERED;

        _;

        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        _status = _NOT_ENTERED;
    }
}

// File: @openzeppelin/contracts/utils/Address.sol


// OpenZeppelin Contracts (last updated v4.5.0) (utils/Address.sol)

pragma solidity ^0.8.1;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     * ====
     *
     * [IMPORTANT]
     * ====
     * You shouldn't rely on `isContract` to protect against flash loan attacks!
     *
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
     * constructor.
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize/address.code.length, which returns 0
        // for contracts in construction, since the code is only stored at the end
        // of the constructor execution.

        return account.code.length > 0;
    }

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        (bool success, ) = recipient.call{value: amount}("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCall(target, data, "Address: low-level call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        require(isContract(target), "Address: call to non-contract");

        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        require(isContract(target), "Address: static call to non-contract");

        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionDelegateCall(target, data, "Address: low-level delegate call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(isContract(target), "Address: delegate call to non-contract");

        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            // Look for revert reason and bubble it up if present
            if (returndata.length > 0) {
                // The easiest way to bubble the revert reason is using memory via assembly

                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}

// File: @openzeppelin/contracts/utils/math/SafeMath.sol


// OpenZeppelin Contracts (last updated v4.6.0) (utils/math/SafeMath.sol)

pragma solidity ^0.8.0;

// CAUTION
// This version of SafeMath should only be used with Solidity 0.8 or later,
// because it relies on the compiler's built in overflow checks.

/**
 * @dev Wrappers over Solidity's arithmetic operations.
 *
 * NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler
 * now has built in overflow checking.
 */
library SafeMath {
    /**
     * @dev Returns the addition of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            uint256 c = a + b;
            if (c < a) return (false, 0);
            return (true, c);
        }
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b > a) return (false, 0);
            return (true, a - b);
        }
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
            // benefit is lost if 'b' is also tested.
            // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
            if (a == 0) return (true, 0);
            uint256 c = a * b;
            if (c / a != b) return (false, 0);
            return (true, c);
        }
    }

    /**
     * @dev Returns the division of two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a / b);
        }
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a % b);
        }
    }

    /**
     * @dev Returns the addition of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `+` operator.
     *
     * Requirements:
     *
     * - Addition cannot overflow.
     */
    function add(uint256 a, uint256 b) internal pure returns (uint256) {
        return a + b;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting on
     * overflow (when the result is negative).
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(uint256 a, uint256 b) internal pure returns (uint256) {
        return a - b;
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `*` operator.
     *
     * Requirements:
     *
     * - Multiplication cannot overflow.
     */
    function mul(uint256 a, uint256 b) internal pure returns (uint256) {
        return a * b;
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator.
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(uint256 a, uint256 b) internal pure returns (uint256) {
        return a / b;
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting when dividing by zero.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(uint256 a, uint256 b) internal pure returns (uint256) {
        return a % b;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting with custom message on
     * overflow (when the result is negative).
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {trySub}.
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(
        uint256 a,
        uint256 b,
        string memory errorMessage
    ) internal pure returns (uint256) {
        unchecked {
            require(b <= a, errorMessage);
            return a - b;
        }
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting with custom message on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator. Note: this function uses a
     * `revert` opcode (which leaves remaining gas untouched) while Solidity
     * uses an invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(
        uint256 a,
        uint256 b,
        string memory errorMessage
    ) internal pure returns (uint256) {
        unchecked {
            require(b > 0, errorMessage);
            return a / b;
        }
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting with custom message when dividing by zero.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {tryMod}.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(
        uint256 a,
        uint256 b,
        string memory errorMessage
    ) internal pure returns (uint256) {
        unchecked {
            require(b > 0, errorMessage);
            return a % b;
        }
    }
}

// File: @openzeppelin/contracts/utils/Context.sol


// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }
}

// File: @openzeppelin/contracts/access/Ownable.sol


// OpenZeppelin Contracts v4.4.1 (access/Ownable.sol)

pragma solidity ^0.8.0;


/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * By default, the owner account will be the one that deploys the contract. This
 * can later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable is Context {
    address private _owner;

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

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    constructor() {
        _transferOwnership(_msgSender());
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
        _;
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions anymore. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby removing any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _transferOwnership(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}

// File: @openzeppelin/contracts/token/ERC20/IERC20.sol


// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);

    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the amount of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves `amount` tokens from the caller's account to `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, uint256 amount) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 amount) external returns (bool);

    /**
     * @dev Moves `amount` tokens from `from` to `to` using the
     * allowance mechanism. `amount` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(
        address from,
        address to,
        uint256 amount
    ) external returns (bool);
}

// File: @openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol


// OpenZeppelin Contracts v4.4.1 (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;



/**
 * @title SafeERC20
 * @dev Wrappers around ERC20 operations that throw on failure (when the token
 * contract returns false). Tokens that return no value (and instead revert or
 * throw on failure) are also supported, non-reverting calls are assumed to be
 * successful.
 * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
library SafeERC20 {
    using Address for address;

    function safeTransfer(
        IERC20 token,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
    }

    function safeTransferFrom(
        IERC20 token,
        address from,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
    }

    /**
     * @dev Deprecated. This function has issues similar to the ones found in
     * {IERC20-approve}, and its usage is discouraged.
     *
     * Whenever possible, use {safeIncreaseAllowance} and
     * {safeDecreaseAllowance} instead.
     */
    function safeApprove(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        // safeApprove should only be called when setting an initial allowance,
        // or when resetting it to zero. To increase and decrease it, use
        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
        require(
            (value == 0) || (token.allowance(address(this), spender) == 0),
            "SafeERC20: approve from non-zero to non-zero allowance"
        );
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
    }

    function safeIncreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        uint256 newAllowance = token.allowance(address(this), spender) + value;
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
    }

    function safeDecreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        unchecked {
            uint256 oldAllowance = token.allowance(address(this), spender);
            require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
            uint256 newAllowance = oldAllowance - value;
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
        }
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that
        // the target address contains contract code and also asserts for success in the low-level call.

        bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
        if (returndata.length > 0) {
            // Return data is optional
            require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
        }
    }
}

// File: @openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol


// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity ^0.8.0;


/**
 * @dev Interface for the optional metadata functions from the ERC20 standard.
 *
 * _Available since v4.1._
 */
interface IERC20Metadata is IERC20 {
    /**
     * @dev Returns the name of the token.
     */
    function name() external view returns (string memory);

    /**
     * @dev Returns the symbol of the token.
     */
    function symbol() external view returns (string memory);

    /**
     * @dev Returns the decimals places of the token.
     */
    function decimals() external view returns (uint8);
}

// File: @openzeppelin/contracts/token/ERC20/ERC20.sol


// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/ERC20.sol)

pragma solidity ^0.8.0;




/**
 * @dev Implementation of the {IERC20} interface.
 *
 * This implementation is agnostic to the way tokens are created. This means
 * that a supply mechanism has to be added in a derived contract using {_mint}.
 * For a generic mechanism see {ERC20PresetMinterPauser}.
 *
 * TIP: For a detailed writeup see our guide
 * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
 * to implement supply mechanisms].
 *
 * We have followed general OpenZeppelin Contracts guidelines: functions revert
 * instead returning `false` on failure. This behavior is nonetheless
 * conventional and does not conflict with the expectations of ERC20
 * applications.
 *
 * Additionally, an {Approval} event is emitted on calls to {transferFrom}.
 * This allows applications to reconstruct the allowance for all accounts just
 * by listening to said events. Other implementations of the EIP may not emit
 * these events, as it isn't required by the specification.
 *
 * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
 * functions have been added to mitigate the well-known issues around setting
 * allowances. See {IERC20-approve}.
 */
contract ERC20 is Context, IERC20, IERC20Metadata {
    mapping(address => uint256) private _balances;

    mapping(address => mapping(address => uint256)) private _allowances;

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;

    /**
     * @dev Sets the values for {name} and {symbol}.
     *
     * The default value of {decimals} is 18. To select a different value for
     * {decimals} you should overload it.
     *
     * All two of these values are immutable: they can only be set once during
     * construction.
     */
    constructor(string memory name_, string memory symbol_) {
        _name = name_;
        _symbol = symbol_;
    }

    /**
     * @dev Returns the name of the token.
     */
    function name() public view virtual override returns (string memory) {
        return _name;
    }

    /**
     * @dev Returns the symbol of the token, usually a shorter version of the
     * name.
     */
    function symbol() public view virtual override returns (string memory) {
        return _symbol;
    }

    /**
     * @dev Returns the number of decimals used to get its user representation.
     * For example, if `decimals` equals `2`, a balance of `505` tokens should
     * be displayed to a user as `5.05` (`505 / 10 ** 2`).
     *
     * Tokens usually opt for a value of 18, imitating the relationship between
     * Ether and Wei. This is the value {ERC20} uses, unless this function is
     * overridden;
     *
     * NOTE: This information is only used for _display_ purposes: it in
     * no way affects any of the arithmetic of the contract, including
     * {IERC20-balanceOf} and {IERC20-transfer}.
     */
    function decimals() public view virtual override returns (uint8) {
        return 18;
    }

    /**
     * @dev See {IERC20-totalSupply}.
     */
    function totalSupply() public view virtual override returns (uint256) {
        return _totalSupply;
    }

    /**
     * @dev See {IERC20-balanceOf}.
     */
    function balanceOf(address account) public view virtual override returns (uint256) {
        return _balances[account];
    }

    /**
     * @dev See {IERC20-transfer}.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - the caller must have a balance of at least `amount`.
     */
    function transfer(address to, uint256 amount) public virtual override returns (bool) {
        address owner = _msgSender();
        _transfer(owner, to, amount);
        return true;
    }

    /**
     * @dev See {IERC20-allowance}.
     */
    function allowance(address owner, address spender) public view virtual override returns (uint256) {
        return _allowances[owner][spender];
    }

    /**
     * @dev See {IERC20-approve}.
     *
     * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on
     * `transferFrom`. This is semantically equivalent to an infinite approval.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function approve(address spender, uint256 amount) public virtual override returns (bool) {
        address owner = _msgSender();
        _approve(owner, spender, amount);
        return true;
    }

    /**
     * @dev See {IERC20-transferFrom}.
     *
     * Emits an {Approval} event indicating the updated allowance. This is not
     * required by the EIP. See the note at the beginning of {ERC20}.
     *
     * NOTE: Does not update the allowance if the current allowance
     * is the maximum `uint256`.
     *
     * Requirements:
     *
     * - `from` and `to` cannot be the zero address.
     * - `from` must have a balance of at least `amount`.
     * - the caller must have allowance for ``from``'s tokens of at least
     * `amount`.
     */
    function transferFrom(
        address from,
        address to,
        uint256 amount
    ) public virtual override returns (bool) {
        address spender = _msgSender();
        _spendAllowance(from, spender, amount);
        _transfer(from, to, amount);
        return true;
    }

    /**
     * @dev Atomically increases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
        address owner = _msgSender();
        _approve(owner, spender, allowance(owner, spender) + addedValue);
        return true;
    }

    /**
     * @dev Atomically decreases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `spender` must have allowance for the caller of at least
     * `subtractedValue`.
     */
    function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
        address owner = _msgSender();
        uint256 currentAllowance = allowance(owner, spender);
        require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
        unchecked {
            _approve(owner, spender, currentAllowance - subtractedValue);
        }

        return true;
    }

    /**
     * @dev Moves `amount` of tokens from `sender` to `recipient`.
     *
     * This internal function is equivalent to {transfer}, and can be used to
     * e.g. implement automatic token fees, slashing mechanisms, etc.
     *
     * Emits a {Transfer} event.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `from` must have a balance of at least `amount`.
     */
    function _transfer(
        address from,
        address to,
        uint256 amount
    ) internal virtual {
        require(from != address(0), "ERC20: transfer from the zero address");
        require(to != address(0), "ERC20: transfer to the zero address");

        _beforeTokenTransfer(from, to, amount);

        uint256 fromBalance = _balances[from];
        require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
        unchecked {
            _balances[from] = fromBalance - amount;
        }
        _balances[to] += amount;

        emit Transfer(from, to, amount);

        _afterTokenTransfer(from, to, amount);
    }

    /** @dev Creates `amount` tokens and assigns them to `account`, increasing
     * the total supply.
     *
     * Emits a {Transfer} event with `from` set to the zero address.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     */
    function _mint(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: mint to the zero address");

        _beforeTokenTransfer(address(0), account, amount);

        _totalSupply += amount;
        _balances[account] += amount;
        emit Transfer(address(0), account, amount);

        _afterTokenTransfer(address(0), account, amount);
    }

    /**
     * @dev Destroys `amount` tokens from `account`, reducing the
     * total supply.
     *
     * Emits a {Transfer} event with `to` set to the zero address.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     * - `account` must have at least `amount` tokens.
     */
    function _burn(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: burn from the zero address");

        _beforeTokenTransfer(account, address(0), amount);

        uint256 accountBalance = _balances[account];
        require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
        unchecked {
            _balances[account] = accountBalance - amount;
        }
        _totalSupply -= amount;

        emit Transfer(account, address(0), amount);

        _afterTokenTransfer(account, address(0), amount);
    }

    /**
     * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
     *
     * This internal function is equivalent to `approve`, and can be used to
     * e.g. set automatic allowances for certain subsystems, etc.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `owner` cannot be the zero address.
     * - `spender` cannot be the zero address.
     */
    function _approve(
        address owner,
        address spender,
        uint256 amount
    ) internal virtual {
        require(owner != address(0), "ERC20: approve from the zero address");
        require(spender != address(0), "ERC20: approve to the zero address");

        _allowances[owner][spender] = amount;
        emit Approval(owner, spender, amount);
    }

    /**
     * @dev Updates `owner` s allowance for `spender` based on spent `amount`.
     *
     * Does not update the allowance amount in case of infinite allowance.
     * Revert if not enough allowance is available.
     *
     * Might emit an {Approval} event.
     */
    function _spendAllowance(
        address owner,
        address spender,
        uint256 amount
    ) internal virtual {
        uint256 currentAllowance = allowance(owner, spender);
        if (currentAllowance != type(uint256).max) {
            require(currentAllowance >= amount, "ERC20: insufficient allowance");
            unchecked {
                _approve(owner, spender, currentAllowance - amount);
            }
        }
    }

    /**
     * @dev Hook that is called before any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * will be transferred to `to`.
     * - when `from` is zero, `amount` tokens will be minted for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens will be burned.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _beforeTokenTransfer(
        address from,
        address to,
        uint256 amount
    ) internal virtual {}

    /**
     * @dev Hook that is called after any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * has been transferred to `to`.
     * - when `from` is zero, `amount` tokens have been minted for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens have been burned.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _afterTokenTransfer(
        address from,
        address to,
        uint256 amount
    ) internal virtual {}
}

// File: bsc_waibao/earnfarm/contracts/KnowFarm.sol



pragma solidity ^0.8.0;

// import "./helpers/ERC20.sol";
// import "./libraries/Address.sol";
// import "./libraries/SafeERC20.sol";
// import "./libraries/EnumerableSet.sol";
// import "./helpers/Ownable.sol";
// import "./helpers/ReentrancyGuard.sol";
// import "./interfaces/IWBNB.sol";







abstract contract RewardToken is ERC20 {
    function mint(address _to, uint256 _amount) public virtual;
}

contract KnowFarm is Ownable, ReentrancyGuard {
    using SafeMath for uint256;
    using SafeERC20 for IERC20;

    // Info of each user.
    struct UserInfo {
        uint256 shares; // How many LP tokens the user has provided.
        uint256 rewardDebt; // Reward debt. See explanation below.
    }

    struct PoolInfo {
        IERC20 want; // Address of the want token.
        uint256 allocPoint; // How many allocation points assigned to this pool. token to distribute per block.
        uint256 lastRewardBlock; // Last block number that token distribution occurs.
        uint256 accPerShare; // Accumulated token per share, times 1e12. See below.
        uint256 sharesTotal;
    }

    // token contract
    address public rewardTokenAddress; 
    uint256 public RewardMaxSupply = 10000000e18;
    uint256 public rewardPerBlock = 5787e14; // reward tokens created per block
    uint256 public startBlock = 0; // https://bscscan.com/block/countdown/10150000
    // https://testnet.bscscan.com/block/countdown/11890000

    PoolInfo public poolInfo; // Info of each pool.
    mapping(address => UserInfo) public userInfo; // Info of each user that stakes LP tokens.
    uint256 public totalAllocPoint = 100; // Total allocation points. Must be the sum of all allocation points in all pools.

    event Deposit(address indexed user, uint256 amount);
    event Withdraw(address indexed user, uint256 amount);
    event Claim(address indexed user, uint256 amount);
    event EmergencyWithdraw(address indexed user, uint256 amount);
        
    constructor(address want, uint256 allocPoint) public {
        poolInfo.want = IERC20(want);
        poolInfo.allocPoint = allocPoint;  
        poolInfo.lastRewardBlock = 0;      
        poolInfo.accPerShare = 0;
    }

    function setStartBlock(uint256 _startBlock) public onlyOwner {
        startBlock = _startBlock;
        poolInfo.lastRewardBlock = block.number > startBlock ? block.number : startBlock;      
    }

    function setRewardPerBlock(uint256 _rewardPerBlock) public onlyOwner {
        rewardPerBlock = _rewardPerBlock;
    }

    function setRewardTokenAddress(address _rewardTokenAddress) public onlyOwner {
        rewardTokenAddress = _rewardTokenAddress;
    }

    // Return reward multiplier over the given _from to _to block.
    function getMultiplier(uint256 _from, uint256 _to) public view returns (uint256) {
        if (IERC20(rewardTokenAddress).totalSupply() >= RewardMaxSupply) {
            return 0;
        }
        return _to.sub(_from);
    }

    function pendingReward(address _user) external view returns (uint256) {
        UserInfo storage user = userInfo[_user];
        uint256 accPerShare = poolInfo.accPerShare;
        if (block.number > poolInfo.lastRewardBlock && poolInfo.sharesTotal > 0) {
            uint256 multiplier = getMultiplier(poolInfo.lastRewardBlock, block.number);
            uint256 reward = multiplier.mul(rewardPerBlock).mul(poolInfo.allocPoint).div(totalAllocPoint);
            accPerShare = poolInfo.accPerShare.add(
                reward.mul(1e12).div(poolInfo.sharesTotal)
            );
        }
        return user.shares.mul(accPerShare).div(1e12).sub(user.rewardDebt);
    }

    // View function to see staked Want tokens on frontend.
    function stakedTokens(address _user) external view returns (uint256) {
        UserInfo storage user = userInfo[_user];
        return user.shares;
    }

    // Update reward variables for all pools. Be careful of gas spending!
    function massUpdatePools() public {
        updatePool();
    }

    // Update reward variables of the given pool to be up-to-date.
    function updatePool() public {
        if (block.number <= poolInfo.lastRewardBlock) {
            return;
        }
        uint256 sharesTotal = poolInfo.sharesTotal;
        if (sharesTotal == 0) {
            poolInfo.lastRewardBlock = block.number;
            return;
        }
        uint256 multiplier = getMultiplier(poolInfo.lastRewardBlock, block.number);
        if (multiplier <= 0) {
            return;
        }
        uint256 reward =
            multiplier.mul(rewardPerBlock).mul(poolInfo.allocPoint).div(
                totalAllocPoint
            );

        RewardToken(rewardTokenAddress).mint(address(this), reward);
        poolInfo.accPerShare = poolInfo.accPerShare.add(
            reward.mul(1e12).div(sharesTotal)
        );
        
        poolInfo.lastRewardBlock = block.number;
    }

    function deposit(uint256 _wantAmt) public payable nonReentrant {
        if(poolInfo.lastRewardBlock == 0) {
            poolInfo.lastRewardBlock = block.number;    
        }

        updatePool();
        UserInfo storage user = userInfo[msg.sender];
        if (user.shares > 0) {
            uint256 pending = user.shares.mul(poolInfo.accPerShare).div(1e12).sub(user.rewardDebt);
            if (pending > 0) {
                safeRewardTransfer(msg.sender, pending);
            }
        }

        if(_wantAmt > 0) {
            poolInfo.want.safeTransferFrom(address(msg.sender), address(this), _wantAmt);
            user.shares = user.shares.add(_wantAmt);
            poolInfo.sharesTotal = poolInfo.sharesTotal.add(_wantAmt);
        }

        user.rewardDebt = user.shares.mul(poolInfo.accPerShare).div(1e12);
        
        emit Deposit(msg.sender, _wantAmt);
    }

    // Withdraw LP tokens from boxfarm.
    function withdraw(uint256 _wantAmt) public nonReentrant {
        updatePool();

        UserInfo storage user = userInfo[msg.sender];
        require(user.shares > 0, "user.shares is 0");
        require(poolInfo.sharesTotal > 0, "sharesTotal is 0");
        
        uint256 pending = user.shares.mul(poolInfo.accPerShare).div(1e12).sub(user.rewardDebt);
        if (pending > 0) {
            safeRewardTransfer(msg.sender, pending);
        }
        
        // Withdraw want tokens
        uint256 amount = user.shares;
        if (_wantAmt > amount) {
            _wantAmt = amount;
        }
        if (_wantAmt > 0) {
            user.shares = user.shares.sub(_wantAmt);
            poolInfo.sharesTotal = poolInfo.sharesTotal.sub(_wantAmt);

            uint256 wantBal = IERC20(poolInfo.want).balanceOf(address(this));
            if (wantBal < _wantAmt) {
                _wantAmt = wantBal;
            }

            poolInfo.want.safeTransfer(address(msg.sender), _wantAmt);
        }

        user.rewardDebt = user.shares.mul(poolInfo.accPerShare).div(1e12);

        emit Withdraw(msg.sender, _wantAmt);
    }

    function claim() public nonReentrant {
        UserInfo storage user = userInfo[msg.sender];
        require(user.shares > 0, "user.shares is 0");
        require(poolInfo.sharesTotal > 0, "sharesTotal is 0");
        
        uint256 pending = user.shares.mul(poolInfo.accPerShare).div(1e12).sub(user.rewardDebt);
        if (pending > 0) {
            safeRewardTransfer(msg.sender, pending);
        }
        
        user.rewardDebt = user.shares.mul(poolInfo.accPerShare).div(1e12);

        emit Claim(msg.sender, pending);
    }

    // Withdraw without caring about rewards. EMERGENCY ONLY.
    function emergencyWithdraw() public nonReentrant {
        UserInfo storage user = userInfo[msg.sender];
        uint256 amount = user.shares;
        poolInfo.want.safeTransfer(address(msg.sender), amount);
        
        user.shares = 0;
        user.rewardDebt = 0;
        poolInfo.sharesTotal = poolInfo.sharesTotal.sub(amount);
        emit EmergencyWithdraw(msg.sender, amount);
    }

    function safeRewardTransfer(address _to, uint256 _rewardAmt) internal {
        uint256 rewardBal = IERC20(rewardTokenAddress).balanceOf(address(this));
        if (_rewardAmt > rewardBal) {
            IERC20(rewardTokenAddress).transfer(_to, rewardBal);
        } else {
            IERC20(rewardTokenAddress).transfer(_to, _rewardAmt);
        }
    }
}

Contract ABI

[{"inputs":[{"internalType":"address","name":"want","type":"address"},{"internalType":"uint256","name":"allocPoint","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Claim","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Deposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"EmergencyWithdraw","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Withdraw","type":"event"},{"inputs":[],"name":"RewardMaxSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"claim","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_wantAmt","type":"uint256"}],"name":"deposit","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"emergencyWithdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_from","type":"uint256"},{"internalType":"uint256","name":"_to","type":"uint256"}],"name":"getMultiplier","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"massUpdatePools","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_user","type":"address"}],"name":"pendingReward","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"poolInfo","outputs":[{"internalType":"contract IERC20","name":"want","type":"address"},{"internalType":"uint256","name":"allocPoint","type":"uint256"},{"internalType":"uint256","name":"lastRewardBlock","type":"uint256"},{"internalType":"uint256","name":"accPerShare","type":"uint256"},{"internalType":"uint256","name":"sharesTotal","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"rewardPerBlock","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rewardTokenAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_rewardPerBlock","type":"uint256"}],"name":"setRewardPerBlock","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_rewardTokenAddress","type":"address"}],"name":"setRewardTokenAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_startBlock","type":"uint256"}],"name":"setStartBlock","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_user","type":"address"}],"name":"stakedTokens","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"startBlock","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalAllocPoint","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":[],"name":"updatePool","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"userInfo","outputs":[{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"uint256","name":"rewardDebt","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_wantAmt","type":"uint256"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"}]

Contract Creation Code

6080604052600436106101355760003560e01c80638dbb1e3a116100ab578063d72b58a81161006f578063d72b58a81461039a578063db2e21bc146103b0578063e3161ddd146103c5578063f2fde38b146103da578063f35e4a6e146103fa578063f40f0f521461041a57600080fd5b80638dbb1e3a146102f15780639a6acf2014610311578063a5b39cfb14610331578063b6b55f2514610367578063bb872b4a1461037a57600080fd5b80634e71d92d116100fd5780634e71d92d1461021c5780635a2f3d0914610231578063630b5ba114610293578063715018a6146102a85780638ae39cac146102bd5780638da5cb5b146102d357600080fd5b8063125f9e331461013a57806317caf6f1146101775780631959a0021461019b5780632e1a7d4d146101e457806348cd4cb114610206575b600080fd5b34801561014657600080fd5b5060025461015a906001600160a01b031681565b6040516001600160a01b0390911681526020015b60405180910390f35b34801561018357600080fd5b5061018d600c5481565b60405190815260200161016e565b3480156101a757600080fd5b506101cf6101b636600461121d565b600b602052600090815260409020805460019091015482565b6040805192835260208301919091520161016e565b3480156101f057600080fd5b506102046101ff366004611246565b61043a565b005b34801561021257600080fd5b5061018d60055481565b34801561022857600080fd5b50610204610674565b34801561023d57600080fd5b50600654600754600854600954600a54610261946001600160a01b03169392919085565b604080516001600160a01b0390961686526020860194909452928401919091526060830152608082015260a00161016e565b34801561029f57600080fd5b506102046107ca565b3480156102b457600080fd5b506102046107d4565b3480156102c957600080fd5b5061018d60045481565b3480156102df57600080fd5b506000546001600160a01b031661015a565b3480156102fd57600080fd5b5061018d61030c36600461125f565b610808565b34801561031d57600080fd5b5061020461032c36600461121d565b61089a565b34801561033d57600080fd5b5061018d61034c36600461121d565b6001600160a01b03166000908152600b602052604090205490565b610204610375366004611246565b6108e6565b34801561038657600080fd5b50610204610395366004611246565b610a0a565b3480156103a657600080fd5b5061018d60035481565b3480156103bc57600080fd5b50610204610a39565b3480156103d157600080fd5b50610204610ada565b3480156103e657600080fd5b506102046103f536600461121d565b610bdc565b34801561040657600080fd5b50610204610415366004611246565b610c77565b34801561042657600080fd5b5061018d61043536600461121d565b610cbd565b6002600154036104655760405162461bcd60e51b815260040161045c90611281565b60405180910390fd5b6002600155610472610ada565b336000908152600b6020526040902080546104c25760405162461bcd60e51b815260206004820152601060248201526f0757365722e73686172657320697320360841b604482015260640161045c565b600a546105045760405162461bcd60e51b815260206004820152601060248201526f0736861726573546f74616c20697320360841b604482015260640161045c565b600061053f826001015461053964e8d4a510006105336006600301548760000154610d7a90919063ffffffff16565b90610d86565b90610d92565b90508015610551576105513382610d9e565b81548084111561055f578093505b83156106175782546105719085610d92565b8355600a546105809085610d92565b600a556006546040516370a0823160e01b81523060048201526000916001600160a01b0316906370a0823190602401602060405180830381865afa1580156105cc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105f091906112b8565b9050848110156105fe578094505b600654610615906001600160a01b03163387610ed1565b505b60095483546106309164e8d4a510009161053391610d7a565b600184015560405184815233907f884edad9ce6fa2440d8a54cc123490eb96d2768479d49ff9c7366125a94243649060200160405180910390a25050600180555050565b6002600154036106965760405162461bcd60e51b815260040161045c90611281565b6002600155336000908152600b6020526040902080546106eb5760405162461bcd60e51b815260206004820152601060248201526f0757365722e73686172657320697320360841b604482015260640161045c565b600a5461072d5760405162461bcd60e51b815260206004820152601060248201526f0736861726573546f74616c20697320360841b604482015260640161045c565b600061075c826001015461053964e8d4a510006105336006600301548760000154610d7a90919063ffffffff16565b9050801561076e5761076e3382610d9e565b60095482546107879164e8d4a510009161053391610d7a565b600183015560405181815233907f47cee97cb7acd717b3c0aa1435d004cd5b3c8c57d70dbceb4e4458bbd60e39d4906020015b60405180910390a2505060018055565b6107d2610ada565b565b6000546001600160a01b031633146107fe5760405162461bcd60e51b815260040161045c906112d1565b6107d26000610f34565b600354600254604080516318160ddd60e01b81529051600093926001600160a01b0316916318160ddd9160048083019260209291908290030181865afa158015610856573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061087a91906112b8565b1061088757506000610894565b6108918284610d92565b90505b92915050565b6000546001600160a01b031633146108c45760405162461bcd60e51b815260040161045c906112d1565b600280546001600160a01b0319166001600160a01b0392909216919091179055565b6002600154036109085760405162461bcd60e51b815260040161045c90611281565b600260015560085460000361091c57436008555b610924610ada565b336000908152600b6020526040902080541561097d576000610969826001015461053964e8d4a510006105336006600301548760000154610d7a90919063ffffffff16565b9050801561097b5761097b3382610d9e565b505b81156109ba5760065461099b906001600160a01b0316333085610f84565b80546109a79083610fbc565b8155600a546109b69083610fbc565b600a555b60095481546109d39164e8d4a510009161053391610d7a565b600182015560405182815233907fe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c906020016107ba565b6000546001600160a01b03163314610a345760405162461bcd60e51b815260040161045c906112d1565b600455565b600260015403610a5b5760405162461bcd60e51b815260040161045c90611281565b6002600155336000818152600b60205260409020805460065491929091610a8e916001600160a01b039091169083610ed1565b60008083556001830155600a54610aa59082610d92565b600a5560405181815233907f5fafa99d0643513820be26656b45130b01e1c03062e1266bf36f88cbd3bd9695906020016107ba565b6008544311610ae557565b600a546000819003610af8575043600855565b6000610b0960066002015443610808565b905060008111610b17575050565b6000610b43600c54610533600660010154610b3d60045487610d7a90919063ffffffff16565b90610d7a565b6002546040516340c10f1960e01b8152306004820152602481018390529192506001600160a01b0316906340c10f1990604401600060405180830381600087803b158015610b9057600080fd5b505af1158015610ba4573d6000803e3d6000fd5b50505050610bd0610bc78461053364e8d4a5100085610d7a90919063ffffffff16565b60095490610fbc565b60095550504360085550565b6000546001600160a01b03163314610c065760405162461bcd60e51b815260040161045c906112d1565b6001600160a01b038116610c6b5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b606482015260840161045c565b610c7481610f34565b50565b6000546001600160a01b03163314610ca15760405162461bcd60e51b815260040161045c906112d1565b6005819055438110610cb557600554610cb7565b435b60085550565b6001600160a01b0381166000908152600b6020526040812060095460085443118015610cea5750600a5415155b15610d4a576000610d0060066002015443610808565b90506000610d28600c54610533600660010154610b3d60045487610d7a90919063ffffffff16565b600a54909150610d4590610bc7906105338464e8d4a51000610d7a565b925050505b610d72826001015461053964e8d4a51000610533858760000154610d7a90919063ffffffff16565b949350505050565b6000610891828461131c565b6000610891828461133b565b6000610891828461135d565b6002546040516370a0823160e01b81523060048201526000916001600160a01b0316906370a0823190602401602060405180830381865afa158015610de7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e0b91906112b8565b905080821115610e935760025460405163a9059cbb60e01b81526001600160a01b038581166004830152602482018490529091169063a9059cbb906044015b6020604051808303816000875af1158015610e69573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e8d9190611374565b50505050565b60025460405163a9059cbb60e01b81526001600160a01b038581166004830152602482018590529091169063a9059cbb90604401610e4a565b505050565b6040516001600160a01b038316602482015260448101829052610ecc90849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152610fc8565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6040516001600160a01b0380851660248301528316604482015260648101829052610e8d9085906323b872dd60e01b90608401610efd565b60006108918284611396565b600061101d826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b031661109a9092919063ffffffff16565b805190915015610ecc578080602001905181019061103b9190611374565b610ecc5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b606482015260840161045c565b60606110a984846000856110b3565b90505b9392505050565b6060824710156111145760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b606482015260840161045c565b6001600160a01b0385163b61116b5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015260640161045c565b600080866001600160a01b0316858760405161118791906113da565b60006040518083038185875af1925050503d80600081146111c4576040519150601f19603f3d011682016040523d82523d6000602084013e6111c9565b606091505b50915091506111d98282866111e4565b979650505050505050565b606083156111f35750816110ac565b8251156112035782518084602001fd5b8160405162461bcd60e51b815260040161045c91906113f6565b60006020828403121561122f57600080fd5b81356001600160a01b03811681146110ac57600080fd5b60006020828403121561125857600080fd5b5035919050565b6000806040838503121561127257600080fd5b50508035926020909101359150565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b6000602082840312156112ca57600080fd5b5051919050565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b634e487b7160e01b600052601160045260246000fd5b600081600019048311821515161561133657611336611306565b500290565b60008261135857634e487b7160e01b600052601260045260246000fd5b500490565b60008282101561136f5761136f611306565b500390565b60006020828403121561138657600080fd5b815180151581146110ac57600080fd5b600082198211156113a9576113a9611306565b500190565b60005b838110156113c95781810151838201526020016113b1565b83811115610e8d5750506000910152565b600082516113ec8184602087016113ae565b9190910192915050565b60208152600082518060208401526114158160408501602087016113ae565b601f01601f1916919091016040019291505056fea2646970667358221220bee1945f050597a04463aba9d41afed0a1125e1510435fea74118c78e61ed31e64736f6c634300080d0033

Block Transaction Gas Used Reward
Age Block Fee Address BC Fee Address Voting Power Jailed Incoming
Block Uncle Number Difficulty Gas Used Reward
Loading
Loading
Make sure to use the "Vote Down" button for any spammy posts, and the "Vote Up" for interesting conversations.