账户
0xd2...c065
0xd2...c065

0xd2...c065

$500
此合同的源代码已经过验证!
合同元数据
编译器
0.6.2+commit.bacdbe57
语言
Solidity
合同源代码
文件 1 的 15:Address.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.6.2;

/**
 * @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
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // According to EIP-1052, 0x0 is the value returned for not-yet created accounts
        // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
        // for accounts without code, i.e. `keccak256('')`
        bytes32 codehash;
        bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
        // solhint-disable-next-line no-inline-assembly
        assembly { codehash := extcodehash(account) }
        return (codehash != accountHash && codehash != 0x0);
    }

    /**
     * @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");

        // solhint-disable-next-line avoid-low-level-calls, avoid-call-value
        (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");
        return _functionCallWithValue(target, data, value, errorMessage);
    }

    function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {
        require(isContract(target), "Address: call to non-contract");

        // solhint-disable-next-line avoid-low-level-calls
        (bool success, bytes memory returndata) = target.call{ value: weiValue }(data);
        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

                // solhint-disable-next-line no-inline-assembly
                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}
合同源代码
文件 2 的 15:BytesLib.sol
// SPDX-License-Identifier: MIT

/*
 * @title Solidity Bytes Arrays Utils
 * @author Gonçalo Sá <goncalo.sa@consensys.net>
 *
 * @dev Bytes tightly packed arrays utility library for ethereum contracts written in Solidity.
 *      The library lets you concatenate, slice and type cast bytes arrays both in memory and storage.
 */
pragma solidity ^0.6.0;


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)
    {
        require(_bytes.length >= (_start + _length), "Read out of bounds");

        bytes memory tempBytes;

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

                // The first word of the slice result is potentially a partial
                // word read from the original array. To read it, we calculate
                // the length of that partial word and start copying that many
                // bytes into the array. The first word we copy will start with
                // data we don't care about, but the last `lengthmod` bytes will
                // land at the beginning of the contents of the new array. When
                // we're done copying, we overwrite the full first word with
                // the actual length of the slice.
                let lengthmod := and(_length, 31)

                // The multiplication in the next line is necessary
                // because when slicing multiples of 32 bytes (lengthmod == 0)
                // the following copy loop was copying the origin's length
                // and then ending prematurely not copying everything it should.
                let mc := add(add(tempBytes, lengthmod), mul(0x20, iszero(lengthmod)))
                let end := add(mc, _length)

                for {
                    // The multiplication in the next line has the same exact purpose
                    // as the one above.
                    let cc := add(add(add(_bytes, lengthmod), mul(0x20, iszero(lengthmod))), _start)
                } lt(mc, end) {
                    mc := add(mc, 0x20)
                    cc := add(cc, 0x20)
                } {
                    mstore(mc, mload(cc))
                }

                mstore(tempBytes, _length)

                //update free-memory pointer
                //allocating the array padded to 32 bytes like the compiler does now
                mstore(0x40, and(add(mc, 31), not(31)))
            }
            //if we want a zero-length slice let's just return a zero-length array
            default {
                tempBytes := mload(0x40)

                mstore(0x40, add(tempBytes, 0x20))
            }
        }

        return tempBytes;
    }

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

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

        return tempAddress;
    }

    function toUint8(bytes memory _bytes, uint256 _start) internal pure returns (uint8) {
        require(_bytes.length >= (_start + 1), "Read out of bounds");
        uint8 tempUint;

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

        return tempUint;
    }

    function toUint16(bytes memory _bytes, uint256 _start) internal pure returns (uint16) {
        require(_bytes.length >= (_start + 2), "Read out of bounds");
        uint16 tempUint;

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

        return tempUint;
    }

    function toUint32(bytes memory _bytes, uint256 _start) internal pure returns (uint32) {
        require(_bytes.length >= (_start + 4), "Read out of bounds");
        uint32 tempUint;

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

        return tempUint;
    }

    function toUint64(bytes memory _bytes, uint256 _start) internal pure returns (uint64) {
        require(_bytes.length >= (_start + 8), "Read out of bounds");
        uint64 tempUint;

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

        return tempUint;
    }

    function toUint96(bytes memory _bytes, uint256 _start) internal pure returns (uint96) {
        require(_bytes.length >= (_start + 12), "Read out of bounds");
        uint96 tempUint;

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

        return tempUint;
    }

    function toUint128(bytes memory _bytes, uint256 _start) internal pure returns (uint128) {
        require(_bytes.length >= (_start + 16), "Read out of bounds");
        uint128 tempUint;

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

        return tempUint;
    }

    function toUint256(bytes memory _bytes, uint256 _start) internal pure returns (uint256) {
        require(_bytes.length >= (_start + 32), "Read out of bounds");
        uint256 tempUint;

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

        return tempUint;
    }

    function toBytes32(bytes memory _bytes, uint256 _start) internal pure returns (bytes32) {
        require(_bytes.length >= (_start + 32), "Read out of bounds");
        bytes32 tempBytes32;

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

        return tempBytes32;
    }

    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(uint256(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(uint256(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;
    }
}
合同源代码
文件 3 的 15:Common.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0;

contract Common {
    // configs
    bytes32 internal EMPTY_BYTES32;
    uint256 internal constant PERCENT_BASE = 1000;
    uint256 internal constant ROOT_ID = 6666;
    uint256 internal constant MAX_LEVEL_DEEP = 7;
    uint256 internal constant BLOCK_PER_ROUND = 5760;
    uint256 internal constant DELAY_ROUND = 10;
    uint256 internal constant ROUND_ALLOW_PREORDER = 15;
    uint256 internal constant NEWBIE_BLOCKS = 160;
    uint256 internal constant ROUND_PREORDER_LIMIT_PERCENT = 700;

    // error codes
    string constant ERROR_HELPING_FUND_NOT_ENOUGH = "1"; // helpingFund not enough
    string constant ERROR_DEFI_IS_BANKRUPT = "2"; // defi is bankrupt
    string constant ERROR_ACCOUNT_IS_DISABLED = "3"; // account is disabled
    string constant ERROR_UNINVESTABLE = "4"; // The investable quota is full
    string constant ERROR_INVALID_STATUS = "5"; // invalid status
    string constant ERROR_INVALID_INVITE_CODE = "6"; // invalid inviteCode
    string constant ERROR_REFERRER_NOT_FOUND = "7"; // Referrer not found
    string constant ERROR_USER_ALREADY_REGISTED = "8"; // user already registed
    string constant ERROR_USER_IS_NOT_REGISTED = "9"; // user is not registed
    string constant ERROR_USER_HAS_NOT_INVESTED = "10"; // User has not invested
    string constant ERROR_ROUND_IS_NOT_OVER = "11"; // Round is not over
    string constant ERROR_TRY_AGAIN_IN_A_DAY = "12"; // Try again in a day
    string constant ERROR_USER_ACTIVATED = "13"; // User activated
    string constant ERROR_USER_IS_NOT_ACTIVATED = "14"; // User is not activated
    string constant ERROR_USER_INVESTED = "15"; // User invested
    string constant ERROR_INVESTMENT_GEAR_IS_INCORRECT = "16"; // Investment gear is incorrect
    string constant ERROR_USER_IS_NOT_NODE = "17"; // user is not node
    string constant ERROR_USER_IS_NOT_SUPER_NODE = "18"; // user is not super node
    string constant ERROR_NO_MORE_BONUS = "19"; // no more bonus
    string constant ERROR_ALREADY_CLAIMED = "20"; // already claimed
    string constant ERROR_NOT_IN_LAST100 = "21"; // not in last 100 users
    string constant ERROR_NO_ORIGINAL_ACCOUNT_QUOTA = "22"; // no original account quota
    string constant ERROR_ETH_NOT_ENOUGH = "23"; // ETH not enough
    string constant ERROR_TOKEN_NOT_ENOUGH = "24"; // Token not enough
    string constant ERROR_UNMATCHED_PAYMENT_ACTION = "25"; // Unmatched payment action

    enum EventAction {
        Unknown,
        PurchaseOriginalAccount,
        UserActive,
        UserInvestment,
        ReferralUserInvestment,
        ClaimROI,
        ClaimCompensation,
        ClaimNodeBonus,
        ClaimSuperNodeBonus,
        ClaimLast100Bonus
    }

    event UserRegister(
        uint256 indexed eventID,
        uint256 indexed userID,
        uint256 blockNumber,
        uint256 referralUserID,
        address userAddr
    );

    event UserActive(
        uint256 indexed eventID,
        uint256 indexed userID,
        uint256 blockNumber,
        uint256[MAX_LEVEL_DEEP + 1] referrers,
        uint256[MAX_LEVEL_DEEP + 1] tokenAmts,
        uint256[MAX_LEVEL_DEEP + 1] usdAmts,
        bytes32 inviteCode
    );

    event Billing(
        uint256 indexed eventID,
        uint256 indexed userID,
        uint256 blockNumber,
        EventAction action,
        uint256 extData,
        uint256 extData1,
        uint256 extData2,
        uint256 tokenAmt,
        uint256 usdAmt,
        uint256 feeUSD
    );

    event UserData(
        uint256 indexed eventID,
        uint256 indexed userID,
        uint256 blockNumber,
        EventAction action,
        uint256 fromUserID,
        uint256 extData,
        bool[2] userBoolArray,
        uint256[21] userUint256Array
    );

    event RoundData(
        uint256 indexed eventID,
        uint256 indexed roundID,
        uint256 blockNumber,
        uint256[4] roundUint256Vars
    );
}
合同源代码
文件 4 的 15:DeFiCommon.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0;

import "./Common.sol";


contract DeFiCommon is Common {
    event Error(string reason, uint256 extData, uint256 blockNumber);
}
合同源代码
文件 5 的 15:DeFiLogic.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0;

import "./IDeFi.sol";
import "./IDeFiLogic.sol";
import "./ILast100Logic.sol";
import "./IDeFiStorage.sol";
import "./IGlobalLogic.sol";
import "./IUpgradable.sol";
import "./Common.sol";
import "./DeFiCommon.sol";
import "./SafeMath.sol";
import "./SafeERC20.sol";
import "./BytesLib.sol";

contract DeFiLogic is Common, DeFiCommon, IUpgradable, IDeFiLogic {
    using SafeERC20 for IERC20;
    using SafeMath for uint256;
    using BytesLib for bytes;

    uint256 private constant ACTIVE_FEE = 5e5;
    uint256 private constant ACTION_ACTIVE = 1001;
    uint256 private constant AVAILABLE_BRING_OUT_PERCENT = 500;
    uint256 private constant OriginalAccountPrice = 1e18;
    uint256 private constant OriginalAccountPriceGrow = 1e17;
    uint256 private constant OriginalAccountNewOpenQuota = 10;
    uint256 private constant OriginalAccountNewOpenQuotaDelayDays = 30;

    IDeFiStorage _fs;
    IGlobalLogic _gl;
    IDeFi _df;
    mapping(uint256 => uint256) private _quotas;

    modifier ensureStatus(IDeFiStorage.GlobalStatus requireStatus) {
        IDeFiStorage.GlobalStatus status = _fs.getGlobalStatus();
        require(
            status == requireStatus ||
                (requireStatus == IDeFiStorage.GlobalStatus.Pending &&
                    (status == IDeFiStorage.GlobalStatus.Pending ||
                        status == IDeFiStorage.GlobalStatus.Started)),
            ERROR_INVALID_STATUS
        );
        _;
    }

    /// internal functions
    function onTokenReceived(
        address token,
        address,
        address msgSender,
        address,
        uint256 amount,
        bytes memory userData,
        bytes memory
    ) public override onlyInternal {
        // check token
        assert(token == _fs.getToken());
        if (msgSender == address(0)) return; // mint
        // convert userData to uint256;
        uint256 userDataUint256;
        if (userData.length > 0) {
            userDataUint256 = userData.toUint256(0);
        }
        uint256 usdAmt = _fs.T2U(amount);

        if (ACTION_ACTIVE == userDataUint256) {
            assert(usdAmt == ACTIVE_FEE);
            activation(msgSender, amount, usdAmt);
            return;
        } else if (userDataUint256 > 0) {
            uint256 gear = _fs.getInvestGear(usdAmt);
            if (gear > 0) {
                invest(msgSender, userDataUint256, amount, usdAmt, gear);
                return;
            }
            revert(ERROR_UNMATCHED_PAYMENT_ACTION);
        }
    }

    function getOriginalAccountQuota()
        public
        override
        view
        returns (
            uint256,
            uint256,
            uint256
        )
    {
        uint256[3] memory globalBlocks = _fs.getGlobalBlocks();
        uint256 rounds = block.number <= globalBlocks[0]
            ? 0
            : block.number.sub(globalBlocks[0]).div(
                BLOCK_PER_ROUND * OriginalAccountNewOpenQuotaDelayDays
            );
        return (
            OriginalAccountPrice.add(rounds.mul(OriginalAccountPriceGrow)),
            OriginalAccountNewOpenQuota > _quotas[rounds]
                ? OriginalAccountNewOpenQuota.sub(_quotas[rounds])
                : 0,
            rounds
        );
    }

    function register(
        address msgSender,
        uint256 msgValue,
        bytes32 inviteCode,
        bool purchaseOriginAccount
    )
        public
        override
        onlyInternal
        ensureStatus(IDeFiStorage.GlobalStatus.Pending)
    {
        require(_fs.getIDByAddr(msgSender) == 0, ERROR_USER_ALREADY_REGISTED);
        uint256 userID = _fs.issueUserID(msgSender);
        uint256[21] memory userUint256Array;

        if (!purchaseOriginAccount) {
            require(inviteCode != EMPTY_BYTES32, ERROR_INVALID_INVITE_CODE);
            uint256 fatherID = _fs.getIDByInviteCode(inviteCode);
            require(fatherID != 0, ERROR_REFERRER_NOT_FOUND);
            bool[2] memory userBoolArray;
            userUint256Array[1] = fatherID; // bind referrer
            _fs.setUser(userID, userBoolArray, userUint256Array);
            emit UserRegister(
                _fs.issueEventIndex(),
                userID,
                block.number,
                fatherID,
                msgSender
            );
        } else {
            (
                uint256 price,
                uint256 quota,
                uint256 rounds
            ) = getOriginalAccountQuota();
            require(quota > 0, ERROR_NO_ORIGINAL_ACCOUNT_QUOTA);
            _quotas[rounds]++;
            require(price <= msgValue, ERROR_ETH_NOT_ENOUGH);
            userUint256Array[1] = ROOT_ID; // bind referrer
            emit UserRegister(
                _fs.issueEventIndex(),
                userID,
                block.number,
                ROOT_ID,
                msgSender
            );

            uint256 _stackTooDeep_msgValue = msgValue;
            emit Billing(
                _fs.issueEventIndex(),
                userID,
                block.number,
                EventAction.PurchaseOriginalAccount,
                0,
                0,
                0,
                0,
                _stackTooDeep_msgValue,
                0
            );
            _df.sendETH(_fs.getPlatformAddress(), _stackTooDeep_msgValue);
        }

        // issue new inviteCode
        bytes32 newInviteCode = _gl.generateInviteCode(userID);
        _fs.setUserInviteCode(userID, newInviteCode);
        // set user level
        userUint256Array[0]++;
        bool[2] memory userBoolArray;
        _fs.setUser(userID, userBoolArray, userUint256Array);
        uint256[MAX_LEVEL_DEEP + 1] memory empty;
        emit UserActive(
            _fs.issueEventIndex(),
            userID,
            block.number,
            empty,
            empty,
            empty,
            newInviteCode
        );
    }

    function claimROI(address msgSender)
        public
        override
        onlyInternal
        ensureStatus(IDeFiStorage.GlobalStatus.Started)
    {
        _gl.internalSplitPool();
        uint256 userID = _fs.getIDByAddr(msgSender);
        require(userID > 0, ERROR_USER_IS_NOT_REGISTED);
        (
            bool[2] memory userBoolArray,
            uint256[21] memory userUint256Array
        ) = _fs.getUser(userID);
        require(userUint256Array[6] > 0, ERROR_USER_HAS_NOT_INVESTED);
        require(
            block.number.sub(BLOCK_PER_ROUND * DELAY_ROUND) >
                userUint256Array[6],
            ERROR_ROUND_IS_NOT_OVER
        );
        if (
            userUint256Array[5] > 0 &&
            userUint256Array[5].add(BLOCK_PER_ROUND) > block.number
        ) revert(ERROR_TRY_AGAIN_IN_A_DAY);

        uint256 income = _fs.getLevelConfig(
            userUint256Array[3],
            IDeFiStorage.ConfigType.StaticIncomeAmt
        );
        income = income.add(userUint256Array[7]); // add dynamicIncome bringOut
        uint256 allAmt = income.add(
            _fs.getLevelConfig(
                userUint256Array[3],
                IDeFiStorage.ConfigType.InvestAmt
            )
        );
        uint256 allToken = _fs.U2T(allAmt);

        uint256 distPool;
        uint256[5] memory pools = _fs.getDeFiAccounts();
        if (pools[distPool] < allToken) {
            if (userUint256Array[4] >= 3) distPool = 1;
            else if (userUint256Array[5].add(BLOCK_PER_ROUND) <= block.number) {
                userUint256Array[4]++;
                userUint256Array[5] = block.number;
                _fs.setUser(userID, userBoolArray, userUint256Array);
                emit Error(
                    ERROR_HELPING_FUND_NOT_ENOUGH,
                    userUint256Array[4],
                    block.number
                );
                return;
            }
        }
        if (pools[distPool] < allToken) {
            // DeFi broken
            uint256[3] memory globalBlocks = _fs.getGlobalBlocks();
            globalBlocks[1] = block.number;
            _fs.setGlobalBlocks(globalBlocks);
            emit Error(ERROR_DEFI_IS_BANKRUPT, globalBlocks[1], block.number);
            return;
        }

        uint256 fee = allAmt.per(
            PERCENT_BASE,
            _fs.getLevelConfig(
                userUint256Array[3],
                IDeFiStorage.ConfigType.ClaimFeePercent
            )
        );
        uint256 distAmt = allAmt.sub(fee);
        uint256 distTokenAmt = _fs.U2T(distAmt);
        pools[distPool] = pools[distPool].sub(allToken);
        _df.sendToken(_fs.getPlatformAddress(), allToken.sub(distTokenAmt));
        _fs.setDeFiAccounts(pools);

        address _stackTooDeep_msgSender = msgSender;
        uint256 _stackTooDeep_userID2 = userID;
        // update user info
        (
            uint256 investGear,
            uint256 roundBringOut,
            uint256 roundID
        ) = _clearUserInvestmentInfo(userUint256Array, income);

        bool[2] memory _stackTooDeep_userBoolArray2 = userBoolArray;
        uint256[21] memory _stackTooDeep_userUint256Array2 = userUint256Array;
        uint256 _stackTooDeep_distTokenAmt = distTokenAmt;
        uint256 _stackTooDeep_distAmt = distAmt;
        _fs.setUser(
            _stackTooDeep_userID2,
            _stackTooDeep_userBoolArray2,
            _stackTooDeep_userUint256Array2
        );
        _df.sendToken(_stackTooDeep_msgSender, _stackTooDeep_distTokenAmt);

        uint256 _stackTooDeep_fee = fee;
        emit Billing(
            _fs.issueEventIndex(),
            _stackTooDeep_userID2,
            block.number,
            EventAction.ClaimROI,
            roundID,
            investGear,
            roundBringOut,
            _stackTooDeep_distTokenAmt,
            _stackTooDeep_distAmt,
            _stackTooDeep_fee
        );
        emit UserData(
            _fs.issueEventIndex(),
            _stackTooDeep_userID2,
            block.number,
            EventAction.ClaimROI,
            _stackTooDeep_userID2,
            0,
            _stackTooDeep_userBoolArray2,
            _stackTooDeep_userUint256Array2
        );
    }

    function deposit(
        address,
        uint256 poolID,
        uint256 tokenAmt
    ) public override onlyInternal {
        uint256[5] memory pools = _fs.getDeFiAccounts();
        pools[poolID] = pools[poolID].add(tokenAmt);
        _fs.setDeFiAccounts(pools);
    }

    /// private functions
    function activation(
        address msgSender,
        uint256 tokenAmt,
        uint256 usdAmt
    ) private ensureStatus(IDeFiStorage.GlobalStatus.Pending) {
        uint256 userID = _fs.getIDByAddr(msgSender);
        require(userID > 0, ERROR_USER_IS_NOT_REGISTED);
        require(
            _fs.getInviteCodeByID(userID) == EMPTY_BYTES32,
            ERROR_USER_ACTIVATED
        );
        // set inviteCode
        bytes32 inviteCode = _gl.generateInviteCode(userID);
        _fs.setUserInviteCode(userID, inviteCode);
        // set user level
        (
            bool[2] memory userBoolArray,
            uint256[21] memory userUint256Array
        ) = _fs.getUser(userID);
        userUint256Array[0]++;
        _fs.setUser(userID, userBoolArray, userUint256Array);
        // dispatch activation bonus
        emit Billing(
            _fs.issueEventIndex(),
            userID,
            block.number,
            EventAction.UserActive,
            0,
            0,
            0,
            tokenAmt,
            usdAmt,
            0
        );
        uint256 balance = tokenAmt;
        uint256 usdBalance = ACTIVE_FEE;
        uint256 splitedAmt = tokenAmt.div(10);
        uint256 splitedUsdAmt = usdBalance.div(10);
        uint256[MAX_LEVEL_DEEP] memory fathers = _fs.getUserFatherIDs(userID);
        address[MAX_LEVEL_DEEP] memory fatherAddrs = _fs.getUserFatherAddrs(
            userID
        );
        uint256[MAX_LEVEL_DEEP + 1] memory referrers;
        uint256[MAX_LEVEL_DEEP + 1] memory usdAmts;
        uint256[MAX_LEVEL_DEEP + 1] memory tokenAmts;
        bool isBreak;
        for (uint256 i = 0; i <= MAX_LEVEL_DEEP && !isBreak; i++) {
            referrers[i] = (i == MAX_LEVEL_DEEP || fathers[i] == 0)
                ? ROOT_ID
                : fathers[i];
            if (referrers[i] == ROOT_ID) {
                usdAmts[i] = usdBalance;
                tokenAmts[i] = balance;
                isBreak = true;
            } else if (i == 0) {
                tokenAmts[i] = splitedAmt.mul(3);
                usdAmts[i] = splitedUsdAmt.mul(3);
            } else {
                tokenAmts[i] = splitedAmt;
                usdAmts[i] = splitedUsdAmt;
            }
            if (
                referrers[i] != ROOT_ID &&
                i != MAX_LEVEL_DEEP &&
                fatherAddrs[i] == address(0)
            ) {
                continue;
            }
            balance = balance.sub(tokenAmts[i]);
            usdBalance = usdBalance.sub(usdAmts[i]);
            _df.sendToken(
                referrers[i] == ROOT_ID
                    ? _fs.getPlatformAddress()
                    : fatherAddrs[i],
                tokenAmts[i]
            );
        }
        bytes32 _stackTooDeep_inviteCode2 = inviteCode;
        emit UserActive(
            _fs.issueEventIndex(),
            userID,
            block.number,
            referrers,
            tokenAmts,
            usdAmts,
            _stackTooDeep_inviteCode2
        );
    }

    function invest(
        address msgSender,
        uint256 roundID,
        uint256 tokenAmt,
        uint256 usdAmt,
        uint256 gear
    ) private ensureStatus(IDeFiStorage.GlobalStatus.Started) {
        uint256 userID = _fs.getIDByAddr(msgSender);
        require(userID > 0, ERROR_USER_IS_NOT_REGISTED);
        require(
            userID == ROOT_ID || _fs.getInviteCodeByID(userID) != EMPTY_BYTES32,
            ERROR_USER_IS_NOT_ACTIVATED
        );
        _gl.checkDeactiveReferrals(userID);
        (
            bool[2] memory userBoolArray,
            uint256[21] memory userUint256Array
        ) = _fs.getUser(userID);
        require(userUint256Array[6] == 0, ERROR_USER_INVESTED);
        require(
            userUint256Array[0] >= gear && userUint256Array[3] <= gear,
            ERROR_INVESTMENT_GEAR_IS_INCORRECT
        );

        bool isNewUser = userUint256Array[3] == 0;

        if (
            !_gl.checkUserAlive(
                userID,
                userUint256Array[6],
                userUint256Array[2],
                msgSender
            )
        ) {
            emit Error(ERROR_ACCOUNT_IS_DISABLED, userID, block.number);
            _df.sendToken(msgSender, tokenAmt);
            return;
        }
        updateUserInfo(
            userID,
            userUint256Array,
            isNewUser,
            roundID,
            gear,
            tokenAmt,
            usdAmt
        );

        _fs.setUser(userID, userBoolArray, userUint256Array);

        uint256[5] memory selfInvestCount;
        if (gear <= userUint256Array[0] && userUint256Array[0] < 5) {
            selfInvestCount = _fs.getSelfInvestCount(userID);
            selfInvestCount[gear - 1] = selfInvestCount[gear - 1].add(1);
            _fs.setSelfInvestCount(userID, selfInvestCount);
        }
        if (userID != ROOT_ID) _fs.pushToInvestQueue(userID);

        _fs.effectReferrals(userID, roundID, usdAmt, isNewUser);
    }

    function updateUserInfo(
        uint256 userID,
        uint256[21] memory userUint256Array,
        bool isNewUser,
        uint256 roundID,
        uint256 gear,
        uint256 tokenAmt,
        uint256 usdAmt
    ) private {
        // chech round available and update round info
        if (
            !_fs.checkRoundAvailableAndUpdate(
                isNewUser,
                roundID,
                usdAmt,
                tokenAmt
            )
        ) revert(ERROR_UNINVESTABLE);
        // update user info
        userUint256Array[2] = block.number; // lastActiveBlock
        userUint256Array[3] = gear; // maxInvestGear
        userUint256Array[6] = roundID; // investRound
        userUint256Array[9] = userUint256Array[9].add(usdAmt); // personalPerformance
        userUint256Array[7] = usdAmt.per(
            PERCENT_BASE,
            AVAILABLE_BRING_OUT_PERCENT
        ); // available bring out
        if (userUint256Array[7] > userUint256Array[8]) {
            userUint256Array[7] = userUint256Array[8];
        }
        userUint256Array[7] = userUint256Array[7].div(1e6).mul(1e6);
        emit Billing(
            _fs.issueEventIndex(),
            userID,
            block.number,
            EventAction.UserInvestment,
            roundID,
            userUint256Array[3],
            userUint256Array[7],
            tokenAmt,
            usdAmt,
            0
        );
    }

    function _clearUserInvestmentInfo(
        uint256[21] memory userUint256Array,
        uint256 income
    )
        private
        view
        returns (
            uint256 investGear,
            uint256 roundBringOut,
            uint256 roundID
        )
    {
        investGear = userUint256Array[3];
        roundBringOut = userUint256Array[7];
        userUint256Array[2] = block.number; // lastActiveBlock
        userUint256Array[4] = 0; // claimRetryCount
        userUint256Array[5] = 0; // claimRetryBlock
        roundID = userUint256Array[6];
        userUint256Array[6] = 0; // investRound
        userUint256Array[8] = userUint256Array[8].sub(userUint256Array[7]); // dynamic return balance
        userUint256Array[7] = 0; // bringOut
        userUint256Array[16] = userUint256Array[16].add(income); // invest return
    }

    /// implements functions
    function changeDependentContractAddress() public override {
        _gl = IGlobalLogic(master.getLatestAddress("GL"));
        _fs = IDeFiStorage(master.getLatestAddress("FS"));
        _df = IDeFi(master.getLatestAddress("DF"));
    }
}
合同源代码
文件 6 的 15:IDeFi.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0;

interface IDeFi {
    function sendToken(address to, uint256 amt) external;

    function sendETH(address payable to, uint256 amt) external;
}
合同源代码
文件 7 的 15:IDeFiLogic.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0;

interface IDeFiLogic {
    function onTokenReceived(
        address token,
        address operator,
        address msgSender,
        address to,
        uint256 amount,
        bytes calldata userData,
        bytes calldata operatorData
    ) external;

    function getOriginalAccountQuota()
        external
        view
        returns (
            uint256,
            uint256,
            uint256
        );

    function register(
        address msgSender,
        uint256 msgValue,
        bytes32 inviteCode,
        bool purchaseOriginAccount
    ) external;

    function claimROI(address msgSender) external;

    function deposit(
        address msgSender,
        uint256 poolID,
        uint256 tokenAmt
    ) external;
}
合同源代码
文件 8 的 15:IDeFiStorage.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0;

interface IDeFiStorage {
    enum ConfigType {
        InvestAmt,
        StaticIncomeAmt,
        DynamicIncomePercent,
        ClaimFeePercent,
        UpgradeRequiredInviteValidPlayerCount,
        UpgradeRequiredMarketPerformance,
        UpgradeRequiredSelfInvestCount
    }
    enum InvestType {Newbie, Open, PreOrder}
    enum GlobalStatus {Pending, Started, Bankruptcy, Ended}
    event GlobalBlocks(uint256 indexed eventID, uint256[3] blocks);

    // public
    function getCurrentRoundID(bool enableCurrentBlock)
        external
        view
        returns (uint256);

    function getAvailableRoundID(bool isNewUser, bool enableCurrentBlock)
        external
        view
        returns (uint256 id, InvestType investType);

    function getInvestGear(uint256 usdAmt) external view returns (uint256);

    function U2T(uint256 usdAmt) external view returns (uint256);

    function U2E(uint256 usdAmt) external view returns (uint256);

    function T2U(uint256 tokenAmt) external view returns (uint256);

    function E2U(uint256 etherAmt) external view returns (uint256);

    function T2E(uint256 tokenAmt) external view returns (uint256);

    function E2T(uint256 etherAmt) external view returns (uint256);

    function getGlobalStatus() external view returns (GlobalStatus);

    function last100() external view returns (uint256[100] memory);

    function getGlobalBlocks() external view returns (uint256[3] memory);

    function getDeFiAccounts() external view returns (uint256[5] memory);

    function getPoolSplitStats() external view returns (uint256[3] memory);

    function getPoolSplitPercent(uint256 roundID) external view returns (uint256[6] memory splitPrcent, uint256[2] memory nodeCount);

    // internal
    function isLast100AndLabel(uint256 userID) external returns (bool);

    function increaseRoundData(
        uint256 roundID,
        uint256 dataID,
        uint256 num
    ) external;

    function getNodePerformance(
        uint256 roundID,
        uint256 nodeID,
        bool isSuperNode
    ) external view returns (uint256);

    function increaseUserData(
        uint256 userID,
        uint256 dataID,
        uint256 num,
        bool isSub,
        bool isSet
    ) external;

    function checkRoundAvailableAndUpdate(
        bool isNewUser,
        uint256 roundID,
        uint256 usdAmt,
        uint256 tokenAmt
    ) external returns (bool success);

    function increaseDeFiAccount(
        uint256 accountID,
        uint256 num,
        bool isSub
    ) external returns (bool);

    function getUser(uint256 userID)
        external
        view
        returns (
            bool[2] memory userBoolArray,
            uint256[21] memory userUint256Array
        );

    function getUserUint256Data(uint256 userID, uint256 dataID)
        external
        view
        returns (uint256);

    function setDeFiAccounts(uint256[5] calldata data) external;

    function splitDone() external;

    function getSelfInvestCount(uint256 userID)
        external
        view
        returns (uint256[5] memory selfInvestCount);

    function setSelfInvestCount(
        uint256 userID,
        uint256[5] calldata selfInvestCount
    ) external;

    function pushToInvestQueue(uint256 userID) external;

    function effectReferrals(
        uint256 userID,
        uint256 roundID,
        uint256 usdAmt,
        bool isNewUser
    ) external;

    function getLevelConfig(uint256 level, ConfigType configType)
        external
        view
        returns (uint256);

    function getUserFatherIDs(uint256 userID)
        external
        view
        returns (uint256[7] memory fathers);

    function getUserFatherActiveInfo(uint256 userID)
        external
        view
        returns (
            uint256[7] memory fathers,
            uint256[7] memory roundID,
            uint256[7] memory lastActive,
            address[7] memory addrs
        );

    function getUserFatherAddrs(uint256 userID)
        external
        view
        returns (address[7] memory fathers);

    function setGlobalBlocks(uint256[3] calldata blocks) external;

    function getGlobalNodeCount(uint256 roundID)
        external
        view
        returns (uint256[2] memory nodeCount);

    function getToken() external view returns (address);

    function setToken(address token) external;

    function getPlatformAddress() external view returns (address payable);

    function setPlatformAddress(address payable platformAddress) external;

    function getIDByAddr(address addr) external view returns (uint256);

    function getAddrByID(uint256 id) external view returns (address);

    function setUserAddr(uint256 id, address addr) external;

    function getIDByInviteCode(bytes32 inviteCode)
        external
        view
        returns (uint256);

    function getInviteCodeByID(uint256 id) external view returns (bytes32);

    function setUserInviteCode(uint256 id, bytes32 inviteCode) external;

    function issueUserID(address addr) external returns (uint256);

    function issueEventIndex() external returns (uint256);

    function setUser(
        uint256 userID,
        bool[2] calldata userBoolArry,
        uint256[21] calldata userUint256Array
    ) external;

    function deactivateUser(uint256 id) external;

    function getRound(uint256 roundID)
        external
        view
        returns (uint256[4] memory roundUint256Vars);

    function setRound(uint256 roundID, uint256[4] calldata roundUint256Vars)
        external;

    function setE2U(uint256 e2u) external;

    function setT2U(uint256 t2u) external;

    function setRoundLimit(uint256[] calldata roundID, uint256[] calldata limit)
        external;
}
合同源代码
文件 9 的 15:IERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.6.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @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 `recipient`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address recipient, 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 `sender` to `recipient` 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 sender, address recipient, uint256 amount) external returns (bool);

    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);
}
合同源代码
文件 10 的 15:IGlobalLogic.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0;

interface IGlobalLogic {
    function checkUserAlive(
        uint256 userID,
        uint256 roundID,
        uint256 lastActiveBlock,
        address userAddr
    ) external returns (bool);

    function checkDeactiveReferrals(uint256 userID) external;

    function generateInviteCode(uint256 id) external view returns (bytes32);

    function internalSplitPool() external;
}
合同源代码
文件 11 的 15:ILast100Logic.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0;

interface ILast100Logic {
    function checkUserAvailable(address payable from)
        external
        returns (uint256);

    function internalExchange() external;
}
合同源代码
文件 12 的 15:IMaster.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0;

interface IMaster {
    function isOwner(address _addr) external view returns (bool);

    function payableOwner() external view returns (address payable);

    function isInternal(address _addr) external view returns (bool);

    function getLatestAddress(bytes2 _contractName)
        external
        view
        returns (address contractAddress);
}
合同源代码
文件 13 的 15:IUpgradable.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0;

import "./IMaster.sol";
import "./Address.sol";

abstract contract IUpgradable {
    IMaster public master;

    modifier onlyInternal {
        assert(master.isInternal(msg.sender));
        _;
    }

    modifier onlyOwner {
        assert(master.isOwner(msg.sender));
        _;
    }

    modifier onlyMaster {
        assert(address(master) == msg.sender);
        _;
    }

    /**
     * @dev IUpgradable Interface to update dependent contract address
     */
    function changeDependentContractAddress() public virtual;

    /**
     * @dev change master address
     * @param addr is the new address
     */
    function changeMasterAddress(address addr) public {
        assert(Address.isContract(addr));
        assert(address(master) == address(0) || address(master) == msg.sender);
        master = IMaster(addr);
    }
}
合同源代码
文件 14 的 15:SafeERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.6.0;

import "./IERC20.sol";
import "./SafeMath.sol";
import "./Address.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC20 operations that throw on failure (when the token
 * contract returns false). Tokens that return no value (and instead revert or
 * throw on failure) are also supported, non-reverting calls are assumed to be
 * successful.
 * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
library SafeERC20 {
    using SafeMath for uint256;
    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'
        // solhint-disable-next-line max-line-length
        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).add(value);
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
    }

    function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 newAllowance = token.allowance(address(this), spender).sub(value, "SafeERC20: decreased allowance below zero");
        _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
            // solhint-disable-next-line max-line-length
            require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
        }
    }
}
合同源代码
文件 15 的 15:SafeMath.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.6.0;

/**
 * @dev Wrappers over Solidity's arithmetic operations with added overflow
 * checks.
 *
 * Arithmetic operations in Solidity wrap on overflow. This can easily result
 * in bugs, because programmers usually assume that an overflow raises an
 * error, which is the standard behavior in high level programming languages.
 * `SafeMath` restores this intuition by reverting the transaction when an
 * operation overflows.
 *
 * Using this library instead of the unchecked operations eliminates an entire
 * class of bugs, so it's recommended to use it always.
 */
library SafeMath {
    /**
     * @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) {
        uint256 c = a + b;
        require(c >= a, "SafeMath: addition overflow");

        return c;
    }

    /**
     * @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 sub(a, b, "SafeMath: subtraction overflow");
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting with custom message on
     * overflow (when the result is negative).
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        require(b <= a, errorMessage);
        uint256 c = a - b;

        return c;
    }

    /**
     * @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) {
        // 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 0;
        }

        uint256 c = a * b;
        require(c / a == b, "SafeMath: multiplication overflow");

        return c;
    }

    /**
     * @dev Returns the integer division of two unsigned integers. Reverts 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) internal pure returns (uint256) {
        return div(a, b, "SafeMath: division by zero");
    }

    /**
     * @dev Returns the integer division of two unsigned integers. Reverts 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) {
        require(b > 0, errorMessage);
        uint256 c = a / b;
        // assert(a == b * c + a % b); // There is no case in which this doesn't hold

        return c;
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * Reverts 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 mod(a, b, "SafeMath: modulo by zero");
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * Reverts with custom message 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, string memory errorMessage) internal pure returns (uint256) {
        require(b != 0, errorMessage);
        return a % b;
    }

    function per(uint256 a, uint256 base, uint256 percent) internal pure returns (uint256) {
        return div(mul(a,percent),base);
    }
}
设置
{
  "compilationTarget": {
    "localhost/DeFiLogic.sol": "DeFiLogic"
  },
  "evmVersion": "istanbul",
  "libraries": {},
  "metadata": {
    "bytecodeHash": "ipfs"
  },
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "remappings": []
}
ABI
[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"eventID","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"userID","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"blockNumber","type":"uint256"},{"indexed":false,"internalType":"enum Common.EventAction","name":"action","type":"uint8"},{"indexed":false,"internalType":"uint256","name":"extData","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"extData1","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"extData2","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"tokenAmt","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"usdAmt","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"feeUSD","type":"uint256"}],"name":"Billing","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"string","name":"reason","type":"string"},{"indexed":false,"internalType":"uint256","name":"extData","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"blockNumber","type":"uint256"}],"name":"Error","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"eventID","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"roundID","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"blockNumber","type":"uint256"},{"indexed":false,"internalType":"uint256[4]","name":"roundUint256Vars","type":"uint256[4]"}],"name":"RoundData","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"eventID","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"userID","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"blockNumber","type":"uint256"},{"indexed":false,"internalType":"uint256[8]","name":"referrers","type":"uint256[8]"},{"indexed":false,"internalType":"uint256[8]","name":"tokenAmts","type":"uint256[8]"},{"indexed":false,"internalType":"uint256[8]","name":"usdAmts","type":"uint256[8]"},{"indexed":false,"internalType":"bytes32","name":"inviteCode","type":"bytes32"}],"name":"UserActive","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"eventID","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"userID","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"blockNumber","type":"uint256"},{"indexed":false,"internalType":"enum Common.EventAction","name":"action","type":"uint8"},{"indexed":false,"internalType":"uint256","name":"fromUserID","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"extData","type":"uint256"},{"indexed":false,"internalType":"bool[2]","name":"userBoolArray","type":"bool[2]"},{"indexed":false,"internalType":"uint256[21]","name":"userUint256Array","type":"uint256[21]"}],"name":"UserData","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"eventID","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"userID","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"blockNumber","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"referralUserID","type":"uint256"},{"indexed":false,"internalType":"address","name":"userAddr","type":"address"}],"name":"UserRegister","type":"event"},{"inputs":[],"name":"changeDependentContractAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"changeMasterAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"msgSender","type":"address"}],"name":"claimROI","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"poolID","type":"uint256"},{"internalType":"uint256","name":"tokenAmt","type":"uint256"}],"name":"deposit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getOriginalAccountQuota","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"master","outputs":[{"internalType":"contract IMaster","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"msgSender","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes","name":"userData","type":"bytes"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"onTokenReceived","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"msgSender","type":"address"},{"internalType":"uint256","name":"msgValue","type":"uint256"},{"internalType":"bytes32","name":"inviteCode","type":"bytes32"},{"internalType":"bool","name":"purchaseOriginAccount","type":"bool"}],"name":"register","outputs":[],"stateMutability":"nonpayable","type":"function"}]