ETH Price: $3,184.29 (+1.58%)
Gas: 17 Gwei

Contract

0x08f866c74205617B6F3903EF481798EcED10cDEC
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To
Accrue Fee202931672024-07-12 21:38:5925 hrs ago1720820339IN
Set: Streaming Fee Module
0 ETH0.000334623.14299066
Accrue Fee202802672024-07-11 2:25:592 days ago1720664759IN
Set: Streaming Fee Module
0 ETH0.000871993.88258454
Accrue Fee202802662024-07-11 2:25:472 days ago1720664747IN
Set: Streaming Fee Module
0 ETH0.000397233.99630507
Accrue Fee202713032024-07-09 20:24:234 days ago1720556663IN
Set: Streaming Fee Module
0 ETH0.000784554.69975836
Accrue Fee202594942024-07-08 4:45:475 days ago1720413947IN
Set: Streaming Fee Module
0 ETH0.000186811.75466851
Accrue Fee202578322024-07-07 23:11:356 days ago1720393895IN
Set: Streaming Fee Module
0 ETH0.000119572.5576795
Accrue Fee202578252024-07-07 23:10:116 days ago1720393811IN
Set: Streaming Fee Module
0 ETH0.000117732.51826536
Accrue Fee202516662024-07-07 2:31:356 days ago1720319495IN
Set: Streaming Fee Module
0 ETH0.000188181.55502908
Accrue Fee202350862024-07-04 18:58:359 days ago1720119515IN
Set: Streaming Fee Module
0 ETH0.001107638.61446798
Accrue Fee202317132024-07-04 7:39:359 days ago1720078775IN
Set: Streaming Fee Module
0 ETH0.000224554.8031946
Accrue Fee202027282024-06-30 6:31:5913 days ago1719729119IN
Set: Streaming Fee Module
0 ETH0.000268543.00499241
Accrue Fee201995352024-06-29 19:49:2314 days ago1719690563IN
Set: Streaming Fee Module
0 ETH0.000229092.5635296
Accrue Fee201993222024-06-29 19:06:4714 days ago1719688007IN
Set: Streaming Fee Module
0 ETH0.000271233.03502067
Accrue Fee201946522024-06-29 3:26:5914 days ago1719631619IN
Set: Streaming Fee Module
0 ETH0.000249332.79002769
Accrue Fee201668682024-06-25 6:20:2318 days ago1719296423IN
Set: Streaming Fee Module
0 ETH0.000320543.58682827
Accrue Fee201245692024-06-19 8:23:4724 days ago1718785427IN
Set: Streaming Fee Module
0 ETH0.000553916.19815016
Accrue Fee200169142024-06-04 7:17:5939 days ago1717485479IN
Set: Streaming Fee Module
0 ETH0.000606485.69642362
Accrue Fee199884272024-05-31 7:48:4743 days ago1717141727IN
Set: Streaming Fee Module
0 ETH0.000317466.79055149
Accrue Fee199883992024-05-31 7:43:1143 days ago1717141391IN
Set: Streaming Fee Module
0 ETH0.000323526.92020731
Accrue Fee199795612024-05-30 2:03:4744 days ago1717034627IN
Set: Streaming Fee Module
0 ETH0.000966549.07837446
Accrue Fee199537822024-05-26 11:33:3548 days ago1716723215IN
Set: Streaming Fee Module
0 ETH0.000221534.73852737
Accrue Fee198968992024-05-18 12:42:4756 days ago1716036167IN
Set: Streaming Fee Module
0 ETH0.000141283.02211173
Accrue Fee198717442024-05-15 0:18:2359 days ago1715732303IN
Set: Streaming Fee Module
0 ETH0.0005383.77205597
Accrue Fee198320122024-05-09 10:52:5965 days ago1715251979IN
Set: Streaming Fee Module
0 ETH0.000163623.5
Accrue Fee198143602024-05-06 23:36:1168 days ago1715038571IN
Set: Streaming Fee Module
0 ETH0.000336823.76899441
View all transactions

View more zero value Internal Transactions in Advanced View mode

Advanced mode:
Loading...
Loading

Similar Match Source Code
This contract matches the deployed Bytecode of the Source Code for Contract 0x3D8d14b7...005EB901B
The constructor portion of the code might be different and could alter the actual behaviour of the contract

Contract Name:
StreamingFeeModule

Compiler Version
v0.6.10+commit.00c0fcaf

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion, Apache-2.0 license

Contract Source Code (Solidity)

/**
 *Submitted for verification at Etherscan.io on 2020-09-08
*/

/**
 *Submitted for verification at Etherscan.io on 2020-09-08
*/

// Dependency file: @openzeppelin/contracts/utils/Address.sol



// 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);
            }
        }
    }
}

// Dependency file: @openzeppelin/contracts/token/ERC20/SafeERC20.sol



// pragma solidity ^0.6.0;

// import "./IERC20.sol";
// import "../../math/SafeMath.sol";
// import "../../utils/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");
        }
    }
}

// Dependency file: contracts/interfaces/IModule.sol

/*
    Copyright 2020 Set Labs Inc.

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.


*/
// pragma solidity 0.6.10;


/**
 * @title IModule
 * @author Set Protocol
 *
 * Interface for interacting with Modules.
 */
interface IModule {
    /**
     * Called by a SetToken to notify that this module was removed from the Set token. Any logic can be included
     * in case checks need to be made or state needs to be cleared.
     */
    function removeModule() external;
}
// Dependency file: contracts/lib/ExplicitERC20.sol

/*
    Copyright 2020 Set Labs Inc.

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.


*/

// pragma solidity 0.6.10;

// import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
// import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
// import { SafeMath } from "@openzeppelin/contracts/math/SafeMath.sol";

/**
 * @title ExplicitERC20
 * @author Set Protocol
 *
 * Utility functions for ERC20 transfers that require the explicit amount to be transferred.
 */
library ExplicitERC20 {
    using SafeMath for uint256;

    /**
     * When given allowance, transfers a token from the "_from" to the "_to" of quantity "_quantity".
     * Ensures that the recipient has received the correct quantity (ie no fees taken on transfer)
     *
     * @param _token           ERC20 token to approve
     * @param _from            The account to transfer tokens from
     * @param _to              The account to transfer tokens to
     * @param _quantity        The quantity to transfer
     */
    function transferFrom(
        IERC20 _token,
        address _from,
        address _to,
        uint256 _quantity
    )
        internal
    {
        // Call specified ERC20 contract to transfer tokens (via proxy).
        if (_quantity > 0) {
            uint256 existingBalance = _token.balanceOf(_to);

            SafeERC20.safeTransferFrom(
                _token,
                _from,
                _to,
                _quantity
            );

            uint256 newBalance = _token.balanceOf(_to);

            // Verify transfer quantity is reflected in balance
            require(
                newBalance == existingBalance.add(_quantity),
                "Invalid post transfer balance"
            );
        }
    }
}

// Dependency file: contracts/lib/PreciseUnitMath.sol

/*
    Copyright 2020 Set Labs Inc.

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.


*/

// pragma solidity 0.6.10;
// pragma experimental ABIEncoderV2;

// import { SafeMath } from "@openzeppelin/contracts/math/SafeMath.sol";
// import { SignedSafeMath } from "@openzeppelin/contracts/math/SignedSafeMath.sol";


/**
 * @title PreciseUnitMath
 * @author Set Protocol
 *
 * Arithmetic for fixed-point numbers with 18 decimals of precision. Some functions taken from
 * dYdX's BaseMath library.
 */
library PreciseUnitMath {
    using SafeMath for uint256;
    using SignedSafeMath for int256;

    // The number One in precise units.
    uint256 constant internal PRECISE_UNIT = 10 ** 18;
    int256 constant internal PRECISE_UNIT_INT = 10 ** 18;

    // Max unsigned integer value
    uint256 constant internal MAX_UINT_256 = type(uint256).max;
    // Max and min signed integer value
    int256 constant internal MAX_INT_256 = type(int256).max;
    int256 constant internal MIN_INT_256 = type(int256).min;

    /**
     * @dev Getter function since constants can't be read directly from libraries.
     */
    function preciseUnit() internal pure returns (uint256) {
        return PRECISE_UNIT;
    }

    /**
     * @dev Getter function since constants can't be read directly from libraries.
     */
    function preciseUnitInt() internal pure returns (int256) {
        return PRECISE_UNIT_INT;
    }

    /**
     * @dev Getter function since constants can't be read directly from libraries.
     */
    function maxUint256() internal pure returns (uint256) {
        return MAX_UINT_256;
    }

    /**
     * @dev Getter function since constants can't be read directly from libraries.
     */
    function maxInt256() internal pure returns (int256) {
        return MAX_INT_256;
    }

    /**
     * @dev Getter function since constants can't be read directly from libraries.
     */
    function minInt256() internal pure returns (int256) {
        return MIN_INT_256;
    }

    /**
     * @dev Multiplies value a by value b (result is rounded down). It's assumed that the value b is the significand
     * of a number with 18 decimals precision.
     */
    function preciseMul(uint256 a, uint256 b) internal pure returns (uint256) {
        return a.mul(b).div(PRECISE_UNIT);
    }

    /**
     * @dev Multiplies value a by value b (result is rounded towards zero). It's assumed that the value b is the
     * significand of a number with 18 decimals precision.
     */
    function preciseMul(int256 a, int256 b) internal pure returns (int256) {
        return a.mul(b).div(PRECISE_UNIT_INT);
    }

    /**
     * @dev Multiplies value a by value b (result is rounded up). It's assumed that the value b is the significand
     * of a number with 18 decimals precision.
     */
    function preciseMulCeil(uint256 a, uint256 b) internal pure returns (uint256) {
        if (a == 0 || b == 0) {
            return 0;
        }
        return a.mul(b).sub(1).div(PRECISE_UNIT).add(1);
    }

    /**
     * @dev Divides value a by value b (result is rounded down).
     */
    function preciseDiv(uint256 a, uint256 b) internal pure returns (uint256) {
        return a.mul(PRECISE_UNIT).div(b);
    }


    /**
     * @dev Divides value a by value b (result is rounded towards 0).
     */
    function preciseDiv(int256 a, int256 b) internal pure returns (int256) {
        return a.mul(PRECISE_UNIT_INT).div(b);
    }

    /**
     * @dev Divides value a by value b (result is rounded up or away from 0).
     */
    function preciseDivCeil(uint256 a, uint256 b) internal pure returns (uint256) {
        require(b != 0, "Cant divide by 0");

        return a > 0 ? a.mul(PRECISE_UNIT).sub(1).div(b).add(1) : 0;
    }

    /**
     * @dev Divides value a by value b (result is rounded down - positive numbers toward 0 and negative away from 0).
     */
    function divDown(int256 a, int256 b) internal pure returns (int256) {
        require(b != 0, "Cant divide by 0");
        require(a != MIN_INT_256 || b != -1, "Invalid input");

        int256 result = a.div(b);
        if (a ^ b < 0 && a % b != 0) {
            result = result.sub(1);
        }

        return result;
    }

    /**
     * @dev Multiplies value a by value b where rounding is towards the lesser number. 
     * (positive values are rounded towards zero and negative values are rounded away from 0). 
     */
    function conservativePreciseMul(int256 a, int256 b) internal pure returns (int256) {
        return divDown(a.mul(b), PRECISE_UNIT_INT);
    }

    /**
     * @dev Divides value a by value b where rounding is towards the lesser number. 
     * (positive values are rounded towards zero and negative values are rounded away from 0). 
     */
    function conservativePreciseDiv(int256 a, int256 b) internal pure returns (int256) {
        return divDown(a.mul(PRECISE_UNIT_INT), b);
    }
}
// Dependency file: contracts/protocol/lib/ModuleBase.sol

/*
    Copyright 2020 Set Labs Inc.

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.


*/

// pragma solidity 0.6.10;

// import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

// import { ExplicitERC20 } from "../../lib/ExplicitERC20.sol";
// import { IController } from "../../interfaces/IController.sol";
// import { IModule } from "../../interfaces/IModule.sol";
// import { ISetToken } from "../../interfaces/ISetToken.sol";

/**
 * @title ModuleBase
 * @author Set Protocol
 *
 * Abstract class that houses common Module-related state and functions.
 */
abstract contract ModuleBase is IModule {

    /* ============ State Variables ============ */

    // Address of the controller
    IController public controller;

    /* ============ Modifiers ============ */

    modifier onlySetManager(ISetToken _setToken, address _caller) {
        require(isSetManager(_setToken, _caller), "Must be the SetToken manager");
        _;
    }

    modifier onlyValidAndInitializedSet(ISetToken _setToken) {
        require(isSetValidAndInitialized(_setToken), "Must be a valid and initialized SetToken");
        _;
    }

    /**
     * Throws if the sender is not a SetToken's module or module not enabled
     */
    modifier onlyModule(ISetToken _setToken) {
        require(
            _setToken.moduleStates(msg.sender) == ISetToken.ModuleState.INITIALIZED,
            "Only the module can call"
        );

        require(
            controller.isModule(msg.sender),
            "Module must be enabled on controller"
        );
        _;
    }

    /**
     * Utilized during module initializations to check that the module is in pending state
     * and that the SetToken is valid
     */
    modifier onlyValidAndPendingSet(ISetToken _setToken) {
        require(controller.isSet(address(_setToken)), "Must be controller-enabled SetToken");
        require(isSetPendingInitialization(_setToken), "Must be pending initialization");        
        _;
    }

    /* ============ Constructor ============ */

    /**
     * Set state variables and map asset pairs to their oracles
     *
     * @param _controller             Address of controller contract
     */
    constructor(IController _controller) public {
        controller = _controller;
    }

    /* ============ Internal Functions ============ */

    /**
     * Transfers tokens from an address (that has set allowance on the module).
     *
     * @param  _token          The address of the ERC20 token
     * @param  _from           The address to transfer from
     * @param  _to             The address to transfer to
     * @param  _quantity       The number of tokens to transfer
     */
    function transferFrom(IERC20 _token, address _from, address _to, uint256 _quantity) internal {
        ExplicitERC20.transferFrom(_token, _from, _to, _quantity);
    }

    /**
     * Returns true if the module is in process of initialization on the SetToken
     */
    function isSetPendingInitialization(ISetToken _setToken) internal view returns(bool) {
        return _setToken.isPendingModule(address(this));
    }

    /**
     * Returns true if the address is the SetToken's manager
     */
    function isSetManager(ISetToken _setToken, address _toCheck) internal view returns(bool) {
        return _setToken.manager() == _toCheck;
    }

    /**
     * Returns true if SetToken must be enabled on the controller 
     * and module is registered on the SetToken
     */
    function isSetValidAndInitialized(ISetToken _setToken) internal view returns(bool) {
        return controller.isSet(address(_setToken)) &&
            _setToken.isInitializedModule(address(this));
    }
}
// Dependency file: @openzeppelin/contracts/token/ERC20/IERC20.sol



// 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);
}
// Dependency file: contracts/interfaces/ISetToken.sol

/*
    Copyright 2020 Set Labs Inc.

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.


*/
// pragma solidity 0.6.10;
// pragma experimental "ABIEncoderV2";

// import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

/**
 * @title ISetToken
 * @author Set Protocol
 *
 * Interface for operating with SetTokens.
 */
interface ISetToken is IERC20 {

    /* ============ Enums ============ */

    enum ModuleState {
        NONE,
        PENDING,
        INITIALIZED
    }

    /* ============ Structs ============ */
    /**
     * The base definition of a SetToken Position
     *
     * @param component           Address of token in the Position
     * @param module              If not in default state, the address of associated module
     * @param unit                Each unit is the # of components per 10^18 of a SetToken
     * @param positionState       Position ENUM. Default is 0; External is 1
     * @param data                Arbitrary data
     */
    struct Position {
        address component;
        address module;
        int256 unit;
        uint8 positionState;
        bytes data;
    }

    /**
     * A struct that stores a component's cash position details and external positions
     * This data structure allows O(1) access to a component's cash position units and 
     * virtual units.
     *
     * @param virtualUnit               Virtual value of a component's DEFAULT position. Stored as virtual for efficiency
     *                                  updating all units at once via the position multiplier. Virtual units are achieved
     *                                  by dividing a "real" value by the "positionMultiplier"
     * @param componentIndex            
     * @param externalPositionModules   List of external modules attached to each external position. Each module
     *                                  maps to an external position
     * @param externalPositions         Mapping of module => ExternalPosition struct for a given component
     */
    struct ComponentPosition {
      int256 virtualUnit;
      address[] externalPositionModules;
      mapping(address => ExternalPosition) externalPositions;
    }

    /**
     * A struct that stores a component's external position details including virtual unit and any
     * auxiliary data.
     *
     * @param virtualUnit       Virtual value of a component's EXTERNAL position.
     * @param data              Arbitrary data
     */
    struct ExternalPosition {
      int256 virtualUnit;
      bytes data;
    }


    /* ============ Functions ============ */
    
    function addComponent(address _component) external;
    function removeComponent(address _component) external;
    function editDefaultPositionUnit(address _component, int256 _realUnit) external;
    function addExternalPositionModule(address _component, address _positionModule) external;
    function removeExternalPositionModule(address _component, address _positionModule) external;
    function editExternalPositionUnit(address _component, address _positionModule, int256 _realUnit) external;
    function editExternalPositionData(address _component, address _positionModule, bytes calldata _data) external;

    function invoke(address _target, uint256 _value, bytes calldata _data) external returns(bytes memory);

    function editPositionMultiplier(int256 _newMultiplier) external;

    function mint(address _account, uint256 _quantity) external;
    function burn(address _account, uint256 _quantity) external;

    function lock() external;
    function unlock() external;

    function addModule(address _module) external;
    function removeModule(address _module) external;
    function initializeModule() external;

    function setManager(address _manager) external;

    function manager() external view returns (address);
    function moduleStates(address _module) external view returns (ModuleState);
    function getModules() external view returns (address[] memory);
    
    function getDefaultPositionRealUnit(address _component) external view returns(int256);
    function getExternalPositionRealUnit(address _component, address _positionModule) external view returns(int256);
    function getComponents() external view returns(address[] memory);
    function getExternalPositionModules(address _component) external view returns(address[] memory);
    function getExternalPositionData(address _component, address _positionModule) external view returns(bytes memory);
    function isExternalPositionModule(address _component, address _module) external view returns(bool);
    function isComponent(address _component) external view returns(bool);
    
    function positionMultiplier() external view returns (int256);
    function getPositions() external view returns (Position[] memory);
    function getTotalComponentRealUnits(address _component) external view returns(int256);

    function isInitializedModule(address _module) external view returns(bool);
    function isPendingModule(address _module) external view returns(bool);
    function isLocked() external view returns (bool);
}
// Dependency file: contracts/interfaces/IController.sol

/*
    Copyright 2020 Set Labs Inc.

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.


*/
// pragma solidity 0.6.10;

interface IController {
    function addSet(address _setToken) external;
    function getModuleFee(address _module, uint256 _feeType) external view returns(uint256);
    function resourceId(uint256 _id) external view returns(address);
    function feeRecipient() external view returns(address);
    function isModule(address _module) external view returns(bool);
    function isSet(address _setToken) external view returns(bool);
    function isSystemContract(address _contractAddress) external view returns (bool);
}
// Dependency file: @openzeppelin/contracts/math/SignedSafeMath.sol



// pragma solidity ^0.6.0;

/**
 * @title SignedSafeMath
 * @dev Signed math operations with safety checks that revert on error.
 */
library SignedSafeMath {
    int256 constant private _INT256_MIN = -2**255;

        /**
     * @dev Returns the multiplication of two signed integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `*` operator.
     *
     * Requirements:
     *
     * - Multiplication cannot overflow.
     */
    function mul(int256 a, int256 b) internal pure returns (int256) {
        // 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;
        }

        require(!(a == -1 && b == _INT256_MIN), "SignedSafeMath: multiplication overflow");

        int256 c = a * b;
        require(c / a == b, "SignedSafeMath: multiplication overflow");

        return c;
    }

    /**
     * @dev Returns the integer division of two signed 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(int256 a, int256 b) internal pure returns (int256) {
        require(b != 0, "SignedSafeMath: division by zero");
        require(!(b == -1 && a == _INT256_MIN), "SignedSafeMath: division overflow");

        int256 c = a / b;

        return c;
    }

    /**
     * @dev Returns the subtraction of two signed integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(int256 a, int256 b) internal pure returns (int256) {
        int256 c = a - b;
        require((b >= 0 && c <= a) || (b < 0 && c > a), "SignedSafeMath: subtraction overflow");

        return c;
    }

    /**
     * @dev Returns the addition of two signed integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `+` operator.
     *
     * Requirements:
     *
     * - Addition cannot overflow.
     */
    function add(int256 a, int256 b) internal pure returns (int256) {
        int256 c = a + b;
        require((b >= 0 && c >= a) || (b < 0 && c < a), "SignedSafeMath: addition overflow");

        return c;
    }
}

// Dependency file: @openzeppelin/contracts/math/SafeMath.sol



// 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;
    }
}

// Dependency file: @openzeppelin/contracts/utils/SafeCast.sol



// pragma solidity ^0.6.0;


/**
 * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow
 * checks.
 *
 * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
 * easily result in undesired exploitation or bugs, since developers usually
 * assume that overflows raise errors. `SafeCast` restores this intuition by
 * reverting the transaction when such an operation overflows.
 *
 * Using this library instead of the unchecked operations eliminates an entire
 * class of bugs, so it's recommended to use it always.
 *
 * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing
 * all math on `uint256` and `int256` and then downcasting.
 */
library SafeCast {

    /**
     * @dev Returns the downcasted uint128 from uint256, reverting on
     * overflow (when the input is greater than largest uint128).
     *
     * Counterpart to Solidity's `uint128` operator.
     *
     * Requirements:
     *
     * - input must fit into 128 bits
     */
    function toUint128(uint256 value) internal pure returns (uint128) {
        require(value < 2**128, "SafeCast: value doesn\'t fit in 128 bits");
        return uint128(value);
    }

    /**
     * @dev Returns the downcasted uint64 from uint256, reverting on
     * overflow (when the input is greater than largest uint64).
     *
     * Counterpart to Solidity's `uint64` operator.
     *
     * Requirements:
     *
     * - input must fit into 64 bits
     */
    function toUint64(uint256 value) internal pure returns (uint64) {
        require(value < 2**64, "SafeCast: value doesn\'t fit in 64 bits");
        return uint64(value);
    }

    /**
     * @dev Returns the downcasted uint32 from uint256, reverting on
     * overflow (when the input is greater than largest uint32).
     *
     * Counterpart to Solidity's `uint32` operator.
     *
     * Requirements:
     *
     * - input must fit into 32 bits
     */
    function toUint32(uint256 value) internal pure returns (uint32) {
        require(value < 2**32, "SafeCast: value doesn\'t fit in 32 bits");
        return uint32(value);
    }

    /**
     * @dev Returns the downcasted uint16 from uint256, reverting on
     * overflow (when the input is greater than largest uint16).
     *
     * Counterpart to Solidity's `uint16` operator.
     *
     * Requirements:
     *
     * - input must fit into 16 bits
     */
    function toUint16(uint256 value) internal pure returns (uint16) {
        require(value < 2**16, "SafeCast: value doesn\'t fit in 16 bits");
        return uint16(value);
    }

    /**
     * @dev Returns the downcasted uint8 from uint256, reverting on
     * overflow (when the input is greater than largest uint8).
     *
     * Counterpart to Solidity's `uint8` operator.
     *
     * Requirements:
     *
     * - input must fit into 8 bits.
     */
    function toUint8(uint256 value) internal pure returns (uint8) {
        require(value < 2**8, "SafeCast: value doesn\'t fit in 8 bits");
        return uint8(value);
    }

    /**
     * @dev Converts a signed int256 into an unsigned uint256.
     *
     * Requirements:
     *
     * - input must be greater than or equal to 0.
     */
    function toUint256(int256 value) internal pure returns (uint256) {
        require(value >= 0, "SafeCast: value must be positive");
        return uint256(value);
    }

    /**
     * @dev Returns the downcasted int128 from int256, reverting on
     * overflow (when the input is less than smallest int128 or
     * greater than largest int128).
     *
     * Counterpart to Solidity's `int128` operator.
     *
     * Requirements:
     *
     * - input must fit into 128 bits
     *
     * _Available since v3.1._
     */
    function toInt128(int256 value) internal pure returns (int128) {
        require(value >= -2**127 && value < 2**127, "SafeCast: value doesn\'t fit in 128 bits");
        return int128(value);
    }

    /**
     * @dev Returns the downcasted int64 from int256, reverting on
     * overflow (when the input is less than smallest int64 or
     * greater than largest int64).
     *
     * Counterpart to Solidity's `int64` operator.
     *
     * Requirements:
     *
     * - input must fit into 64 bits
     *
     * _Available since v3.1._
     */
    function toInt64(int256 value) internal pure returns (int64) {
        require(value >= -2**63 && value < 2**63, "SafeCast: value doesn\'t fit in 64 bits");
        return int64(value);
    }

    /**
     * @dev Returns the downcasted int32 from int256, reverting on
     * overflow (when the input is less than smallest int32 or
     * greater than largest int32).
     *
     * Counterpart to Solidity's `int32` operator.
     *
     * Requirements:
     *
     * - input must fit into 32 bits
     *
     * _Available since v3.1._
     */
    function toInt32(int256 value) internal pure returns (int32) {
        require(value >= -2**31 && value < 2**31, "SafeCast: value doesn\'t fit in 32 bits");
        return int32(value);
    }

    /**
     * @dev Returns the downcasted int16 from int256, reverting on
     * overflow (when the input is less than smallest int16 or
     * greater than largest int16).
     *
     * Counterpart to Solidity's `int16` operator.
     *
     * Requirements:
     *
     * - input must fit into 16 bits
     *
     * _Available since v3.1._
     */
    function toInt16(int256 value) internal pure returns (int16) {
        require(value >= -2**15 && value < 2**15, "SafeCast: value doesn\'t fit in 16 bits");
        return int16(value);
    }

    /**
     * @dev Returns the downcasted int8 from int256, reverting on
     * overflow (when the input is less than smallest int8 or
     * greater than largest int8).
     *
     * Counterpart to Solidity's `int8` operator.
     *
     * Requirements:
     *
     * - input must fit into 8 bits.
     *
     * _Available since v3.1._
     */
    function toInt8(int256 value) internal pure returns (int8) {
        require(value >= -2**7 && value < 2**7, "SafeCast: value doesn\'t fit in 8 bits");
        return int8(value);
    }

    /**
     * @dev Converts an unsigned uint256 into a signed int256.
     *
     * Requirements:
     *
     * - input must be less than or equal to maxInt256.
     */
    function toInt256(uint256 value) internal pure returns (int256) {
        require(value < 2**255, "SafeCast: value doesn't fit in an int256");
        return int256(value);
    }
}

// Dependency file: @openzeppelin/contracts/utils/ReentrancyGuard.sol



// pragma solidity ^0.6.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].
 */
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 () internal {
        _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 make 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;
    }
}

/*
    Copyright 2020 Set Labs Inc.

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.


*/

pragma solidity 0.6.10;
pragma experimental "ABIEncoderV2";

// import { ReentrancyGuard } from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
// import { SafeCast } from "@openzeppelin/contracts/utils/SafeCast.sol";
// import { SafeMath } from "@openzeppelin/contracts/math/SafeMath.sol";
// import { SignedSafeMath } from "@openzeppelin/contracts/math/SignedSafeMath.sol";

// import { IController } from "../../interfaces/IController.sol";
// import { ISetToken } from "../../interfaces/ISetToken.sol";
// import { ModuleBase } from "../lib/ModuleBase.sol";
// import { PreciseUnitMath } from "../../lib/PreciseUnitMath.sol";


/**
 * @title StreamingFeeModule
 * @author Set Protocol
 *
 * Smart contract that accrues streaming fees for Set managers. Streaming fees are denominated as percent
 * per year and realized as Set inflation rewarded to the manager.
 */
contract StreamingFeeModule is ModuleBase, ReentrancyGuard {
    using SafeMath for uint256;
    using PreciseUnitMath for uint256;
    using SafeCast for uint256;

    using SignedSafeMath for int256;
    using PreciseUnitMath for int256;
    using SafeCast for int256;


    /* ============ Structs ============ */

    struct FeeState {
        address feeRecipient;                   // Address to accrue fees to
        uint256 maxStreamingFeePercentage;      // Max streaming fee maanager commits to using (1% = 1e16, 100% = 1e18)
        uint256 streamingFeePercentage;         // Percent of Set accruing to manager annually (1% = 1e16, 100% = 1e18)
        uint256 lastStreamingFeeTimestamp;      // Timestamp last streaming fee was accrued
    }

    /* ============ Events ============ */

    event FeeActualized(address indexed _setToken, uint256 _managerFee, uint256 _protocolFee);
    event StreamingFeeUpdated(address indexed _setToken, uint256 _newStreamingFee);
    event FeeRecipientUpdated(address indexed _setToken, address _newFeeRecipient);

    /* ============ Constants ============ */

    uint256 private constant ONE_YEAR_IN_SECONDS = 365.25 days;
    uint256 private constant PROTOCOL_STREAMING_FEE_INDEX = 0;

    /* ============ State Variables ============ */

    mapping(ISetToken => FeeState) public feeStates;

    /* ============ Constructor ============ */

    constructor(IController _controller) public ModuleBase(_controller) {}

    /* ============ External Functions ============ */

    /*
     * Calculates total inflation percentage then mints new Sets to the fee recipient. Position units are
     * then adjusted down (in magnitude) in order to ensure full collateralization. Callable by anyone.
     *
     * @param _setToken       Address of SetToken
     */
    function accrueFee(ISetToken _setToken) public nonReentrant onlyValidAndInitializedSet(_setToken) {
        uint256 managerFee;
        uint256 protocolFee;

        if (_streamingFeePercentage(_setToken) > 0) {
            uint256 inflationFeePercentage = _calculateStreamingFee(_setToken);

            // Calculate incentiveFee inflation
            uint256 feeQuantity = _calculateStreamingFeeInflation(_setToken, inflationFeePercentage);

            // Mint new Sets to manager and protocol
            (
                managerFee,
                protocolFee
            ) = _mintManagerAndProtocolFee(_setToken, feeQuantity);

            _editPositionMultiplier(_setToken, inflationFeePercentage);
        }

        feeStates[_setToken].lastStreamingFeeTimestamp = block.timestamp;

        emit FeeActualized(address(_setToken), managerFee, protocolFee);
    }

    /**
     * SET MANAGER ONLY. Initialize module with SetToken and set the fee state for the SetToken. Passed
     * _settings will have lastStreamingFeeTimestamp over-written.
     *
     * @param _setToken                 Address of SetToken
     * @param _settings                 FeeState struct defining fee parameters
     */
    function initialize(
        ISetToken _setToken,
        FeeState memory _settings
    )
        external
        onlySetManager(_setToken, msg.sender)
        onlyValidAndPendingSet(_setToken)
    {
        require(_settings.feeRecipient != address(0), "Fee Recipient must be non-zero address.");
        require(_settings.maxStreamingFeePercentage < PreciseUnitMath.preciseUnit(), "Max fee must be < 100%.");
        require(_settings.streamingFeePercentage <= _settings.maxStreamingFeePercentage, "Fee must be <= max.");

        _settings.lastStreamingFeeTimestamp = block.timestamp;

        feeStates[_setToken] = _settings;
        _setToken.initializeModule();
    }

    /**
     * Removes this module from the SetToken, via call by the SetToken. Manager's feeState is deleted. Fees
     * are not accrued in case reason for removing module is related to fee accrual.
     */
    function removeModule() external override {
        delete feeStates[ISetToken(msg.sender)];
    }

    /*
     * Set new streaming fee. Fees accrue at current rate then new rate is set.
     * Fees are accrued to prevent the manager from unfairly accruing a larger percentage.
     *
     * @param _setToken       Address of SetToken
     * @param _newFee         New streaming fee 18 decimal precision
     */
    function updateStreamingFee(
        ISetToken _setToken,
        uint256 _newFee
    )
        external
        onlySetManager(_setToken, msg.sender)
        onlyValidAndInitializedSet(_setToken)
    {
        require(_newFee < _maxStreamingFeePercentage(_setToken), "Fee must be less than max");
        accrueFee(_setToken);

        feeStates[_setToken].streamingFeePercentage = _newFee;

        emit StreamingFeeUpdated(address(_setToken), _newFee);
    }

    /*
     * Set new fee recipient.
     *
     * @param _setToken             Address of SetToken
     * @param _newFeeRecipient      New fee recipient
     */
    function updateFeeRecipient(ISetToken _setToken, address _newFeeRecipient)
        external
        onlySetManager(_setToken, msg.sender)
        onlyValidAndInitializedSet(_setToken)
    {
        require(_newFeeRecipient != address(0), "Fee Recipient must be non-zero address.");

        feeStates[_setToken].feeRecipient = _newFeeRecipient;

        emit FeeRecipientUpdated(address(_setToken), _newFeeRecipient);
    }

    /*
     * Calculates total inflation percentage in order to accrue fees to manager.
     *
     * @param _setToken       Address of SetToken
     * @return  uint256       Percent inflation of supply
     */
    function getFee(ISetToken _setToken) external view returns (uint256) {
        return _calculateStreamingFee(_setToken);
    }

    /* ============ Internal Functions ============ */

    /**
     * Calculates streaming fee by multiplying streamingFeePercentage by the elapsed amount of time since the last fee
     * was collected divided by one year in seconds, since the fee is a yearly fee.
     *
     * @param  _setToken          Address of Set to have feeState updated
     * @return uint256            Streaming fee denominated in percentage of totalSupply
     */
    function _calculateStreamingFee(ISetToken _setToken) internal view returns(uint256) {
        uint256 timeSinceLastFee = block.timestamp.sub(_lastStreamingFeeTimestamp(_setToken));

        // Streaming fee is streaming fee times years since last fee
        return timeSinceLastFee.mul(_streamingFeePercentage(_setToken)).div(ONE_YEAR_IN_SECONDS);
    }

    /**
     * Returns the new incentive fee denominated in the number of SetTokens to mint. The calculation for the fee involves
     * implying mint quantity so that the feeRecipient owns the fee percentage of the entire supply of the Set.
     *
     * The formula to solve for fee is:
     * (feeQuantity / feeQuantity) + totalSupply = fee / scaleFactor
     *
     * The simplified formula utilized below is:
     * feeQuantity = fee * totalSupply / (scaleFactor - fee)
     *
     * @param   _setToken               SetToken instance
     * @param   _feePercentage          Fee levied to feeRecipient
     * @return  uint256                 New RebalancingSet issue quantity
     */
    function _calculateStreamingFeeInflation(
        ISetToken _setToken,
        uint256 _feePercentage
    )
        internal
        view
        returns (uint256)
    {
        uint256 totalSupply = _setToken.totalSupply();

        // fee * totalSupply
        uint256 a = _feePercentage.mul(totalSupply);

        // ScaleFactor (10e18) - fee
        uint256 b = PreciseUnitMath.preciseUnit().sub(_feePercentage);

        return a.div(b);
    }

    /**
     * Mints sets to both the manager and the protocol. Protocol takes a percentage fee of the total amount of Sets
     * minted to manager.
     *
     * @param   _setToken               SetToken instance
     * @param   _feeQuantity            Amount of Sets to be minted as fees
     * @return  uint256                 Amount of Sets accrued to manager as fee
     * @return  uint256                 Amount of Sets accrued to protocol as fee
     */
    function _mintManagerAndProtocolFee(ISetToken _setToken, uint256 _feeQuantity) internal returns (uint256, uint256) {
        address protocolFeeRecipient = controller.feeRecipient();
        uint256 protocolFee = controller.getModuleFee(address(this), PROTOCOL_STREAMING_FEE_INDEX);

        uint256 protocolFeeAmount = _feeQuantity.preciseMul(protocolFee);
        uint256 managerFeeAmount = _feeQuantity.sub(protocolFeeAmount);

        _setToken.mint(_feeRecipient(_setToken), managerFeeAmount);

        if (protocolFeeAmount > 0) {
            _setToken.mint(protocolFeeRecipient, protocolFeeAmount);
        }

        return (managerFeeAmount, protocolFeeAmount);
    }

    /**
     * Calculates new position multiplier according to following formula:
     *
     * newMultiplier = oldMultiplier * (1-inflationFee)
     *
     * This reduces position sizes to offset increase in supply due to fee collection.
     *
     * @param   _setToken               SetToken instance
     * @param   _inflationFee           Fee inflation rate
     */
    function _editPositionMultiplier(ISetToken _setToken, uint256 _inflationFee) internal {
        int256 currentMultipler = _setToken.positionMultiplier();
        int256 newMultiplier = currentMultipler.preciseMul(PreciseUnitMath.preciseUnit().sub(_inflationFee).toInt256());

        _setToken.editPositionMultiplier(newMultiplier);
    }

    function _feeRecipient(ISetToken _set) internal view returns (address) {
        return feeStates[_set].feeRecipient;
    }

    function _lastStreamingFeeTimestamp(ISetToken _set) internal view returns (uint256) {
        return feeStates[_set].lastStreamingFeeTimestamp;
    }

    function _maxStreamingFeePercentage(ISetToken _set) internal view returns (uint256) {
        return feeStates[_set].maxStreamingFeePercentage;
    }

    function _streamingFeePercentage(ISetToken _set) internal view returns (uint256) {
        return feeStates[_set].streamingFeePercentage;
    }
}

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"contract IController","name":"_controller","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_setToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"_managerFee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_protocolFee","type":"uint256"}],"name":"FeeActualized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_setToken","type":"address"},{"indexed":false,"internalType":"address","name":"_newFeeRecipient","type":"address"}],"name":"FeeRecipientUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_setToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"_newStreamingFee","type":"uint256"}],"name":"StreamingFeeUpdated","type":"event"},{"inputs":[{"internalType":"contract ISetToken","name":"_setToken","type":"address"}],"name":"accrueFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"controller","outputs":[{"internalType":"contract IController","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract ISetToken","name":"","type":"address"}],"name":"feeStates","outputs":[{"internalType":"address","name":"feeRecipient","type":"address"},{"internalType":"uint256","name":"maxStreamingFeePercentage","type":"uint256"},{"internalType":"uint256","name":"streamingFeePercentage","type":"uint256"},{"internalType":"uint256","name":"lastStreamingFeeTimestamp","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract ISetToken","name":"_setToken","type":"address"}],"name":"getFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract ISetToken","name":"_setToken","type":"address"},{"components":[{"internalType":"address","name":"feeRecipient","type":"address"},{"internalType":"uint256","name":"maxStreamingFeePercentage","type":"uint256"},{"internalType":"uint256","name":"streamingFeePercentage","type":"uint256"},{"internalType":"uint256","name":"lastStreamingFeeTimestamp","type":"uint256"}],"internalType":"struct StreamingFeeModule.FeeState","name":"_settings","type":"tuple"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"removeModule","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract ISetToken","name":"_setToken","type":"address"},{"internalType":"address","name":"_newFeeRecipient","type":"address"}],"name":"updateFeeRecipient","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract ISetToken","name":"_setToken","type":"address"},{"internalType":"uint256","name":"_newFee","type":"uint256"}],"name":"updateStreamingFee","outputs":[],"stateMutability":"nonpayable","type":"function"}]

Deployed Bytecode

0x608060405234801561001057600080fd5b50600436106100885760003560e01c80638e7bdd481161005b5780638e7bdd48146100d0578063b88c9148146100fc578063eb78e5ee1461011c578063f77c47911461012f57610088565b80632f3eec491461008d57806345cb3fde146100a25780635d98c373146100b5578063847ef08d146100c8575b600080fd5b6100a061009b366004610f9b565b610144565b005b6100a06100b036600461107e565b610249565b6100a06100c3366004610fb7565b610324565b6100a06103f8565b6100e36100de366004610f9b565b61042a565b6040516100f394939291906110ee565b60405180910390f35b61010f61010a366004610f9b565b61045d565b6040516100f39190611114565b6100a061012a366004610fef565b61046e565b61013761067b565b6040516100f391906110c1565b600260015414156101705760405162461bcd60e51b815260040161016790611491565b60405180910390fd5b60026001558061017f8161068a565b61019b5760405162461bcd60e51b8152600401610167906111a7565b60008060006101a98561078e565b11156101e65760006101ba856107ad565b905060006101c886836107ff565b90506101d486826108bf565b90945092506101e38683610ad9565b50505b6001600160a01b0384166000818152600260205260409081902042600390910155517faca81f8dfdb5e554ef873ba451d1ca28d6701b3d9c3ab5e56c699ae0b37bade19061023790859085906114c8565b60405180910390a25050600180555050565b81336102558282610bdb565b6102715760405162461bcd60e51b815260040161016790611425565b8361027b8161068a565b6102975760405162461bcd60e51b8152600401610167906111a7565b6102a085610c69565b84106102be5760405162461bcd60e51b815260040161016790611226565b6102c785610144565b6001600160a01b03851660008181526002602081905260409182902001869055517fa648920efd9baafceb9a4c0163ddc4d7c9df1d0f9a58f8e376bd0ec68e0f749890610315908790611114565b60405180910390a25050505050565b81336103308282610bdb565b61034c5760405162461bcd60e51b815260040161016790611425565b836103568161068a565b6103725760405162461bcd60e51b8152600401610167906111a7565b6001600160a01b0384166103985760405162461bcd60e51b815260040161016790611326565b6001600160a01b038581166000818152600260205260409081902080546001600160a01b0319169388169390931790925590517faaebcf1bfa00580e41d966056b48521fa9f202645c86d4ddf28113e617c1b1d3906103159087906110c1565b336000908152600260208190526040822080546001600160a01b03191681556001810183905590810182905560030155565b600260208190526000918252604090912080546001820154928201546003909201546001600160a01b0390911692919084565b6000610468826107ad565b92915050565b813361047a8282610bdb565b6104965760405162461bcd60e51b815260040161016790611425565b600054604051631d3af8fb60e21b815285916001600160a01b0316906374ebe3ec906104c69084906004016110c1565b60206040518083038186803b1580156104de57600080fd5b505afa1580156104f2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105169190610f7b565b6105325760405162461bcd60e51b8152600401610167906113e2565b61053b81610c87565b6105575760405162461bcd60e51b8152600401610167906111ef565b83516001600160a01b031661057e5760405162461bcd60e51b815260040161016790611326565b610586610cb6565b8460200151106105a85760405162461bcd60e51b815260040161016790611170565b8360200151846040015111156105d05760405162461bcd60e51b81526004016101679061136d565b42606085019081526001600160a01b0386811660008181526002602081815260408084208b5181546001600160a01b0319169716969096178655908a01516001860155808a015191850191909155935160039093019290925582516307ff078f60e11b815292519092630ffe0f1e92600480830193919282900301818387803b15801561065c57600080fd5b505af1158015610670573d6000803e3d6000fd5b505050505050505050565b6000546001600160a01b031681565b60008054604051631d3af8fb60e21b81526001600160a01b03909116906374ebe3ec906106bb9085906004016110c1565b60206040518083038186803b1580156106d357600080fd5b505afa1580156106e7573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061070b9190610f7b565b801561046857506040516335fc6c9f60e21b81526001600160a01b0383169063d7f1b27c9061073e9030906004016110c1565b60206040518083038186803b15801561075657600080fd5b505afa15801561076a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104689190610f7b565b6001600160a01b03166000908152600260208190526040909120015490565b6000806107c96107bc84610cc2565b429063ffffffff610ce016565b90506107f86301e187e06107ec6107df8661078e565b849063ffffffff610d2216565b9063ffffffff610d5c16565b9392505050565b600080836001600160a01b03166318160ddd6040518163ffffffff1660e01b815260040160206040518083038186803b15801561083b57600080fd5b505afa15801561084f573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061087391906110a9565b90506000610887848363ffffffff610d2216565b905060006108a385610897610cb6565b9063ffffffff610ce016565b90506108b5828263ffffffff610d5c16565b9695505050505050565b60008060008060009054906101000a90046001600160a01b03166001600160a01b031663469048406040518163ffffffff1660e01b815260040160206040518083038186803b15801561091157600080fd5b505afa158015610925573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109499190610f5f565b6000805460405163792aa04f60e01b815292935090916001600160a01b039091169063792aa04f9061098190309085906004016110d5565b60206040518083038186803b15801561099957600080fd5b505afa1580156109ad573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109d191906110a9565b905060006109e5868363ffffffff610d9e16565b905060006109f9878363ffffffff610ce016565b9050876001600160a01b03166340c10f19610a138a610dbc565b836040518363ffffffff1660e01b8152600401610a319291906110d5565b600060405180830381600087803b158015610a4b57600080fd5b505af1158015610a5f573d6000803e3d6000fd5b505050506000821115610acd576040516340c10f1960e01b81526001600160a01b038916906340c10f1990610a9a90879086906004016110d5565b600060405180830381600087803b158015610ab457600080fd5b505af1158015610ac8573d6000803e3d6000fd5b505050505b97909650945050505050565b6000826001600160a01b0316635230c3966040518163ffffffff1660e01b815260040160206040518083038186803b158015610b1457600080fd5b505afa158015610b28573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b4c91906110a9565b90506000610b74610b67610b6285610897610cb6565b610dda565b839063ffffffff610e0316565b60405163c2de0e9d60e01b81529091506001600160a01b0385169063c2de0e9d90610ba3908490600401611114565b600060405180830381600087803b158015610bbd57600080fd5b505af1158015610bd1573d6000803e3d6000fd5b5050505050505050565b6000816001600160a01b0316836001600160a01b031663481c6a756040518163ffffffff1660e01b815260040160206040518083038186803b158015610c2057600080fd5b505afa158015610c34573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c589190610f5f565b6001600160a01b0316149392505050565b6001600160a01b031660009081526002602052604090206001015490565b6040516353bae5f760e01b81526000906001600160a01b038316906353bae5f79061073e9030906004016110c1565b670de0b6b3a764000090565b6001600160a01b031660009081526002602052604090206003015490565b60006107f883836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250610e2d565b600082610d3157506000610468565b82820282848281610d3e57fe5b04146107f85760405162461bcd60e51b81526004016101679061129e565b60006107f883836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f000000000000815250610e59565b60006107f8670de0b6b3a76400006107ec858563ffffffff610d2216565b6001600160a01b039081166000908152600260205260409020541690565b6000600160ff1b8210610dff5760405162461bcd60e51b81526004016101679061139a565b5090565b60006107f8670de0b6b3a7640000610e21858563ffffffff610e9016565b9063ffffffff610efb16565b60008184841115610e515760405162461bcd60e51b8152600401610167919061111d565b505050900390565b60008183610e7a5760405162461bcd60e51b8152600401610167919061111d565b506000838581610e8657fe5b0495945050505050565b600082610e9f57506000610468565b82600019148015610eb35750600160ff1b82145b15610ed05760405162461bcd60e51b8152600401610167906112df565b82820282848281610edd57fe5b05146107f85760405162461bcd60e51b8152600401610167906112df565b600081610f1a5760405162461bcd60e51b81526004016101679061145c565b81600019148015610f2e5750600160ff1b83145b15610f4b5760405162461bcd60e51b81526004016101679061125d565b6000828481610f5657fe5b05949350505050565b600060208284031215610f70578081fd5b81516107f8816114d6565b600060208284031215610f8c578081fd5b815180151581146107f8578182fd5b600060208284031215610fac578081fd5b81356107f8816114d6565b60008060408385031215610fc9578081fd5b8235610fd4816114d6565b91506020830135610fe4816114d6565b809150509250929050565b60008082840360a0811215611002578283fd5b833561100d816114d6565b92506080601f1982011215611020578182fd5b506040516080810181811067ffffffffffffffff82111715611040578283fd5b6040526020840135611051816114d6565b80825250604084013560208201526060840135604082015260808401356060820152809150509250929050565b60008060408385031215611090578182fd5b823561109b816114d6565b946020939093013593505050565b6000602082840312156110ba578081fd5b5051919050565b6001600160a01b0391909116815260200190565b6001600160a01b03929092168252602082015260400190565b6001600160a01b0394909416845260208401929092526040830152606082015260800190565b90815260200190565b6000602080835283518082850152825b818110156111495785810183015185820160400152820161112d565b8181111561115a5783604083870101525b50601f01601f1916929092016040019392505050565b60208082526017908201527f4d617820666565206d757374206265203c20313030252e000000000000000000604082015260600190565b60208082526028908201527f4d75737420626520612076616c696420616e6420696e697469616c697a65642060408201526729b2ba2a37b5b2b760c11b606082015260800190565b6020808252601e908201527f4d7573742062652070656e64696e6720696e697469616c697a6174696f6e0000604082015260600190565b60208082526019908201527f466565206d757374206265206c657373207468616e206d617800000000000000604082015260600190565b60208082526021908201527f5369676e6564536166654d6174683a206469766973696f6e206f766572666c6f6040820152607760f81b606082015260800190565b60208082526021908201527f536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f6040820152607760f81b606082015260800190565b60208082526027908201527f5369676e6564536166654d6174683a206d756c7469706c69636174696f6e206f604082015266766572666c6f7760c81b606082015260800190565b60208082526027908201527f46656520526563697069656e74206d757374206265206e6f6e2d7a65726f206160408201526632323932b9b99760c91b606082015260800190565b6020808252601390820152722332b29036bab9ba103132901e1e9036b0bc1760691b604082015260600190565b60208082526028908201527f53616665436173743a2076616c756520646f65736e27742066697420696e2061604082015267371034b73a191a9b60c11b606082015260800190565b60208082526023908201527f4d75737420626520636f6e74726f6c6c65722d656e61626c656420536574546f60408201526235b2b760e91b606082015260800190565b6020808252601c908201527f4d7573742062652074686520536574546f6b656e206d616e6167657200000000604082015260600190565b6020808252818101527f5369676e6564536166654d6174683a206469766973696f6e206279207a65726f604082015260600190565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b918252602082015260400190565b6001600160a01b03811681146114eb57600080fd5b5056fea2646970667358221220ba7667045a62821576f45f97bfd8b1cc568441fd88b75e911a09cd56a86503c464736f6c634300060a0033

Deployed Bytecode Sourcemap

52724:10383:0:-:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;54583:894;;;;;;;;;:::i;:::-;;57165:475;;;;;;;;;:::i;57816:433::-;;;;;;;;;:::i;56738:100::-;;;:::i;54052:47::-;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;58474:128;;;;;;;;;:::i;:::-;;;;;;;;55826:691;;;;;;;;;:::i;20602:29::-;;;:::i;:::-;;;;;;;;54583:894;50257:1;50863:7;;:19;;50855:63;;;;-1:-1:-1;;;50855:63:0;;;;;;;;;;;;;;;;;50257:1;50996:7;:18;54670:9;20939:35:::1;54670:9:::0;20939:24:::1;:35::i;:::-;20931:88;;;;-1:-1:-1::0;;;20931:88:0::1;;;;;;;;;54692:18:::2;54721:19:::0;54794:1:::2;54757:34;54781:9;54757:23;:34::i;:::-;:38;54753:564;;;54812:30;54845:33;54868:9;54845:22;:33::i;:::-;54812:66;;54944:19;54966:66;54998:9;55009:22;54966:31;:66::i;:::-;54944:88;;55180:50;55207:9;55218:11;55180:26;:50::i;:::-;55103:127:::0;;-1:-1:-1;55103:127:0;-1:-1:-1;55247:58:0::2;55271:9:::0;55282:22;55247:23:::2;:58::i;:::-;54753:564;;;-1:-1:-1::0;;;;;55329:20:0;::::2;;::::0;;;:9:::2;:20;::::0;;;;;;55378:15:::2;55329:46;::::0;;::::2;:64:::0;55411:58;::::2;::::0;::::2;::::0;55445:10;;55457:11;;55411:58:::2;;;;;;;;;;-1:-1:-1::0;;50213:1:0;51175:22;;-1:-1:-1;;54583:894:0:o;57165:475::-;57298:9;57309:10;20770:32;20783:9;20794:7;20770:12;:32::i;:::-;20762:73;;;;-1:-1:-1;;;20762:73:0;;;;;;;;;57357:9:::1;20939:35;20964:9;20939:24;:35::i;:::-;20931:88;;;;-1:-1:-1::0;;;20931:88:0::1;;;;;;;;;57402:37:::2;57429:9;57402:26;:37::i;:::-;57392:7;:47;57384:85;;;;-1:-1:-1::0;;;57384:85:0::2;;;;;;;;;57480:20;57490:9;57480;:20::i;:::-;-1:-1:-1::0;;;;;57513:20:0;::::2;;::::0;;;:9:::2;:20;::::0;;;;;;;;:43:::2;:53:::0;;;57584:48;::::2;::::0;::::2;::::0;57559:7;;57584:48:::2;;;;;;;;;;20846:1:::1;57165:475:::0;;;;:::o;57816:433::-;57933:9;57944:10;20770:32;20783:9;20794:7;20770:12;:32::i;:::-;20762:73;;;;-1:-1:-1;;;20762:73:0;;;;;;;;;57992:9:::1;20939:35;20964:9;20939:24;:35::i;:::-;20931:88;;;;-1:-1:-1::0;;;20931:88:0::1;;;;;;;;;-1:-1:-1::0;;;;;58027:30:0;::::2;58019:82;;;;-1:-1:-1::0;;;58019:82:0::2;;;;;;;;;-1:-1:-1::0;;;;;58114:20:0;;::::2;;::::0;;;:9:::2;:20;::::0;;;;;;:52;;-1:-1:-1;;;;;;58114:52:0::2;::::0;;::::2;::::0;;;::::2;::::0;;;58184:57;;::::2;::::0;::::2;::::0;58114:52;;58184:57:::2;;56738:100:::0;56818:10;56798:32;;;;:9;:32;;;;;;;56791:39;;-1:-1:-1;;;;;;56791:39:0;;;;;;;;;;;;;;;;;;56738:100::o;54052:47::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;;;;54052:47:0;;;;;;;:::o;58474:128::-;58534:7;58561:33;58584:9;58561:22;:33::i;:::-;58554:40;58474:128;-1:-1:-1;;58474:128:0:o;55826:691::-;55961:9;55972:10;20770:32;20783:9;20794:7;20770:12;:32::i;:::-;20762:73;;;;-1:-1:-1;;;20762:73:0;;;;;;;;;21719:10:::1;::::0;:36:::1;::::0;-1:-1:-1;;;21719:36:0;;56016:9;;-1:-1:-1;;;;;21719:10:0::1;::::0;:16:::1;::::0;:36:::1;::::0;56016:9;;21719:36:::1;;;;;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;21711:84;;;;-1:-1:-1::0;;;21711:84:0::1;;;;;;;;;21814:37;21841:9;21814:26;:37::i;:::-;21806:80;;;;-1:-1:-1::0;;;21806:80:0::1;;;;;;;;;56051:22:::0;;-1:-1:-1;;;;;56051:36:0::2;56043:88;;;;-1:-1:-1::0;;;56043:88:0::2;;;;;;;;;56188:29;:27;:29::i;:::-;56150:9;:35;;;:67;56142:103;;;;-1:-1:-1::0;;;56142:103:0::2;;;;;;;;;56300:9;:35;;;56264:9;:32;;;:71;;56256:103;;;;-1:-1:-1::0;;;56256:103:0::2;;;;;;;;;56410:15;56372:35;::::0;::::2;:53:::0;;;-1:-1:-1;;;;;56438:20:0;;::::2;;::::0;;;:9:::2;:20;::::0;;;;;;;:32;;;;-1:-1:-1;;;;;;56438:32:0::2;::::0;::::2;::::0;;;::::2;::::0;;;;::::2;::::0;-1:-1:-1;56438:32:0;::::2;::::0;;;::::2;::::0;;;::::2;::::0;;;;;;::::2;::::0;;::::2;::::0;;;;56481:28;;-1:-1:-1;;;56481:28:0;;;;56438:20;;56481:26:::2;::::0;:28:::2;::::0;;::::2;::::0;56438:20;;56481:28;;;;;56438:20;;56481:28;::::2;;::::0;::::2;;;;::::0;::::2;;;;;;;;;;;;::::0;::::2;;;;;;;;;20846:1:::1;55826:691:::0;;;;:::o;20602:29::-;;;-1:-1:-1;;;;;20602:29:0;;:::o;23448:206::-;23525:4;23549:10;;:36;;-1:-1:-1;;;23549:36:0;;-1:-1:-1;;;;;23549:10:0;;;;:16;;:36;;23574:9;;23549:36;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:97;;;;-1:-1:-1;23602:44:0;;-1:-1:-1;;;23602:44:0;;-1:-1:-1;;;;;23602:29:0;;;;;:44;;23640:4;;23602:44;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;62959:145;-1:-1:-1;;;;;63058:15:0;63031:7;63058:15;;;:9;:15;;;;;;;;:38;;;62959:145::o;59064:359::-;59139:7;59159:24;59186:58;59206:37;59233:9;59206:26;:37::i;:::-;59186:15;;:58;:19;:58;:::i;:::-;59159:85;;59334:81;53913:11;59334:56;59355:34;59379:9;59355:23;:34::i;:::-;59334:16;;:56;:20;:56;:::i;:::-;:60;:81;:60;:81;:::i;:::-;59327:88;59064:359;-1:-1:-1;;;59064:359:0:o;60134:465::-;60295:7;60320:19;60342:9;-1:-1:-1;;;;;60342:21:0;;:23;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;60320:45;-1:-1:-1;60408:9:0;60420:31;:14;60320:45;60420:31;:18;:31;:::i;:::-;60408:43;;60502:9;60514:49;60548:14;60514:29;:27;:29::i;:::-;:33;:49;:33;:49;:::i;:::-;60502:61;-1:-1:-1;60583:8:0;:1;60502:61;60583:8;:5;:8;:::i;:::-;60576:15;60134:465;-1:-1:-1;;;;;;60134:465:0:o;61078:690::-;61175:7;61184;61204:28;61235:10;;;;;;;;;-1:-1:-1;;;;;61235:10:0;-1:-1:-1;;;;;61235:23:0;;:25;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;61271:19;61293:10;;:68;;-1:-1:-1;;;61293:68:0;;61204:56;;-1:-1:-1;61271:19:0;;-1:-1:-1;;;;;61293:10:0;;;;:23;;:68;;61325:4;;61271:19;;61293:68;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;61271:90;-1:-1:-1;61374:25:0;61402:36;:12;61271:90;61402:36;:23;:36;:::i;:::-;61374:64;-1:-1:-1;61449:24:0;61476:35;:12;61374:64;61476:35;:16;:35;:::i;:::-;61449:62;;61524:9;-1:-1:-1;;;;;61524:14:0;;61539:24;61553:9;61539:13;:24::i;:::-;61565:16;61524:58;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;61619:1;61599:17;:21;61595:109;;;61637:55;;-1:-1:-1;;;61637:55:0;;-1:-1:-1;;;;;61637:14:0;;;;;:55;;61652:20;;61674:17;;61637:55;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;61595:109;61724:16;61742:17;;-1:-1:-1;61078:690:0;-1:-1:-1;;;;;61078:690:0:o;62157:343::-;62254:23;62280:9;-1:-1:-1;;;;;62280:28:0;;:30;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;62254:56;;62321:20;62344:88;62372:59;:48;62406:13;62372:29;:27;:29::i;:48::-;:57;:59::i;:::-;62344:16;;:88;:27;:88;:::i;:::-;62445:47;;-1:-1:-1;;;62445:47:0;;62321:111;;-1:-1:-1;;;;;;62445:32:0;;;;;:47;;62321:111;;62445:47;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;62157:343;;;;:::o;23159:146::-;23242:4;23289:8;-1:-1:-1;;;;;23266:31:0;:9;-1:-1:-1;;;;;23266:17:0;;:19;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;;;;23266:31:0;;;23159:146;-1:-1:-1;;;23159:146:0:o;62800:151::-;-1:-1:-1;;;;;62902:15:0;62875:7;62902:15;;;:9;:15;;;;;:41;;;;62800:151::o;22920:::-;23023:40;;-1:-1:-1;;;23023:40:0;;22999:4;;-1:-1:-1;;;;;23023:25:0;;;;;:40;;23057:4;;23023:40;;;;15386:93;14941:8;15386:93;:::o;62641:151::-;-1:-1:-1;;;;;62743:15:0;62716:7;62743:15;;;:9;:15;;;;;:41;;;;62641:151::o;37726:136::-;37784:7;37811:43;37815:1;37818;37811:43;;;;;;;;;;;;;;;;;:3;:43::i;38616:471::-;38674:7;38919:6;38915:47;;-1:-1:-1;38949:1:0;38942:8;;38915:47;38986:5;;;38990:1;38986;:5;:1;39010:5;;;;;:10;39002:56;;;;-1:-1:-1;;;39002:56:0;;;;;;;;39563:132;39621:7;39648:39;39652:1;39655;39648:39;;;;;;;;;;;;;;;;;:3;:39::i;16480:126::-;16545:7;16572:26;14941:8;16572;:1;16578;16572:8;:5;:8;:::i;62508:125::-;-1:-1:-1;;;;;62597:15:0;;;62570:7;62597:15;;;:9;:15;;;;;:28;;;62508:125::o;48320:181::-;48376:6;-1:-1:-1;;;48403:5:0;:14;48395:67;;;;-1:-1:-1;;;48395:67:0;;;;;;;;;-1:-1:-1;48487:5:0;48320:181::o;16806:127::-;16869:6;16895:30;15000:8;16895;:1;16901;16895:8;:5;:8;:::i;:::-;:12;:30;:12;:30;:::i;38165:192::-;38251:7;38287:12;38279:6;;;;38271:29;;;;-1:-1:-1;;;38271:29:0;;;;;;;;;;-1:-1:-1;;;38323:5:0;;;38165:192::o;40191:278::-;40277:7;40312:12;40305:5;40297:28;;;;-1:-1:-1;;;40297:28:0;;;;;;;;;;;40336:9;40352:1;40348;:5;;;;;;;40191:278;-1:-1:-1;;;;;40191:278:0:o;34074:568::-;34130:6;34374;34370:47;;-1:-1:-1;34404:1:0;34397:8;;34370:47;34439:1;-1:-1:-1;;34439:7:0;:27;;;;;-1:-1:-1;;;34450:1:0;:16;34439:27;34437:30;34429:82;;;;-1:-1:-1;;;34429:82:0;;;;;;;;;34535:5;;;34539:1;34535;:5;:1;34559:5;;;;;:10;34551:62;;;;-1:-1:-1;;;34551:62:0;;;;;;;;35116:271;35172:6;35199;35191:51;;;;-1:-1:-1;;;35191:51:0;;;;;;;;;35263:1;-1:-1:-1;;35263:7:0;:27;;;;;-1:-1:-1;;;35274:1:0;:16;35263:27;35261:30;35253:76;;;;-1:-1:-1;;;35253:76:0;;;;;;;;;35342:8;35357:1;35353;:5;;;;;;;35116:271;-1:-1:-1;;;;35116:271:0:o;1880:263:-1:-;;1995:2;1983:9;1974:7;1970:23;1966:32;1963:2;;;-1:-1;;2001:12;1963:2;226:6;220:13;238:33;265:5;238:33;;2150:257;;2262:2;2250:9;2241:7;2237:23;2233:32;2230:2;;;-1:-1;;2268:12;2230:2;364:6;358:13;20911:5;19594:13;19587:21;20889:5;20886:32;20876:2;;-1:-1;;20922:12;2414:277;;2536:2;2524:9;2515:7;2511:23;2507:32;2504:2;;;-1:-1;;2542:12;2504:2;516:6;503:20;528:51;573:5;528:51;;2698:402;;;2837:2;2825:9;2816:7;2812:23;2808:32;2805:2;;;-1:-1;;2843:12;2805:2;516:6;503:20;528:51;573:5;528:51;;;2895:81;-1:-1;3013:2;3052:22;;72:20;97:33;72:20;97:33;;;3021:63;;;;2799:301;;;;;;3107:455;;;3260:9;3251:7;3247:23;3272:3;3247:23;3243:33;3240:2;;;-1:-1;;3279:12;3240:2;516:6;503:20;528:51;573:5;528:51;;;3331:81;-1:-1;886:4;-1:-1;;865:19;;861:30;858:2;;;-1:-1;;894:12;858:2;;18928;18922:9;886:4;18958:6;18954:17;19065:6;19053:10;19050:22;19029:18;19017:10;19014:34;19011:62;19008:2;;;-1:-1;;19076:12;19008:2;18928;19095:22;3449:2;3514:22;;72:20;97:33;72:20;97:33;;;1032:49;1014:16;1007:75;;18928:2;3518:9;1218:22;1669:20;3449:2;1183:5;1179:16;1172:75;1380:22;3518:9;1380:22;1669:20;18928:2;1345:5;1341:16;1334:75;886:4;3518:9;1545:22;1669:20;1380:22;1510:5;1506:16;1499:75;3457:89;;;;3234:328;;;;;;3569:402;;;3708:2;3696:9;3687:7;3683:23;3679:32;3676:2;;;-1:-1;;3714:12;3676:2;516:6;503:20;528:51;573:5;528:51;;;3766:81;3884:2;3923:22;;;;1669:20;;-1:-1;;;3670:301;3978:261;;4092:2;4080:9;4071:7;4067:23;4063:32;4060:2;;;-1:-1;;4098:12;4060:2;-1:-1;668:13;;4054:185;-1:-1;4054:185;10432:222;-1:-1;;;;;19876:54;;;;4587:37;;10559:2;10544:18;;10530:124;10661:333;-1:-1;;;;;19876:54;;;;4587:37;;10980:2;10965:18;;4878:36;10816:2;10801:18;;10787:207;11001:556;-1:-1;;;;;19876:54;;;;4587:37;;11377:2;11362:18;;4878:36;;;;11460:2;11445:18;;4878:36;11543:2;11528:18;;4878:36;11212:3;11197:19;;11183:374;11833:218;4878:36;;;11958:2;11943:18;;11929:122;12058:310;;12205:2;;12226:17;12219:47;5071:5;19217:12;19374:6;12205:2;12194:9;12190:18;19362:19;-1:-1;20397:101;20411:6;20408:1;20405:13;20397:101;;;20478:11;;;;;20472:18;20459:11;;;19402:14;20459:11;20452:39;20426:10;;20397:101;;;20513:6;20510:1;20507:13;20504:2;;;-1:-1;19402:14;20569:6;12194:9;20560:16;;20553:27;20504:2;-1:-1;865:19;20669:14;-1:-1;;20665:28;5229:39;;;;19402:14;5229:39;;12176:192;-1:-1;;;12176:192;12375:416;12575:2;12589:47;;;5505:2;12560:18;;;19362:19;5541:25;19402:14;;;5521:46;5586:12;;;12546:245;12798:416;12998:2;13012:47;;;5837:2;12983:18;;;19362:19;5873:34;19402:14;;;5853:55;-1:-1;;;5928:12;;;5921:32;5972:12;;;12969:245;13221:416;13421:2;13435:47;;;6223:2;13406:18;;;19362:19;6259:32;19402:14;;;6239:53;6311:12;;;13392:245;13644:416;13844:2;13858:47;;;6562:2;13829:18;;;19362:19;6598:27;19402:14;;;6578:48;6645:12;;;13815:245;14067:416;14267:2;14281:47;;;6896:2;14252:18;;;19362:19;6932:34;19402:14;;;6912:55;-1:-1;;;6987:12;;;6980:25;7024:12;;;14238:245;14490:416;14690:2;14704:47;;;7275:2;14675:18;;;19362:19;7311:34;19402:14;;;7291:55;-1:-1;;;7366:12;;;7359:25;7403:12;;;14661:245;14913:416;15113:2;15127:47;;;7654:2;15098:18;;;19362:19;7690:34;19402:14;;;7670:55;-1:-1;;;7745:12;;;7738:31;7788:12;;;15084:245;15336:416;15536:2;15550:47;;;8039:2;15521:18;;;19362:19;8075:34;19402:14;;;8055:55;-1:-1;;;8130:12;;;8123:31;8173:12;;;15507:245;15759:416;15959:2;15973:47;;;8424:2;15944:18;;;19362:19;-1:-1;;;19402:14;;;8440:42;8501:12;;;15930:245;16182:416;16382:2;16396:47;;;8752:2;16367:18;;;19362:19;8788:34;19402:14;;;8768:55;-1:-1;;;8843:12;;;8836:32;8887:12;;;16353:245;16605:416;16805:2;16819:47;;;9138:2;16790:18;;;19362:19;9174:34;19402:14;;;9154:55;-1:-1;;;9229:12;;;9222:27;9268:12;;;16776:245;17028:416;17228:2;17242:47;;;9519:2;17213:18;;;19362:19;9555:30;19402:14;;;9535:51;9605:12;;;17199:245;17451:416;17651:2;17665:47;;;17636:18;;;19362:19;9892:34;19402:14;;;9872:55;9946:12;;;17622:245;17874:416;18074:2;18088:47;;;10197:2;18059:18;;;19362:19;10233:33;19402:14;;;10213:54;10286:12;;;18045:245;18526:333;4878:36;;;18845:2;18830:18;;4878:36;18681:2;18666:18;;18652:207;20706:117;-1:-1;;;;;19876:54;;20765:35;;20755:2;;20814:1;;20804:12;20755:2;20749:74;

Swarm Source

ipfs://ba7667045a62821576f45f97bfd8b1cc568441fd88b75e911a09cd56a86503c4

Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

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

Validator Index Block Amount
View All Withdrawals

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

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