Maintenance in progress, block data might not be up to date

Contract 0x70AbDB857e191B1033b6C67274681c816F3343bf

 

Contract Overview

Balance:
0 BNB

BNB Value:
$0.00

Token:
 
Txn Hash Method
Block
From
To
Value [Txn Fee]
0xec43011fa79477cca004cea166a4389f9c11cfb8232c4846d612e41740359a63Set Foundry Fund74659482021-05-16 18:06:50158 days 9 hrs ago0x62ca555de2d65f8e9d45a9b3d5c1b92ac1a64ecc IN  0x70abdb857e191b1033b6c67274681c816f3343bf0 BNB0.00014303
0xf886781599d2bec5568aec39f59d2546940fd9ad0556e1a077941d6b0f1edcbcAllocate Seignio...74600032021-05-16 13:01:10158 days 14 hrs ago0xa3a502569bf1bfbf7b361964d61335a7530d39e8 IN  0x70abdb857e191b1033b6c67274681c816f3343bf0 BNB0.009040755
0x7954d9e8f81dedafb2538ad395c64c0a57d363af60967e0ba4c523e34a08e83eAllocate Seignio...74457322021-05-16 1:00:11159 days 2 hrs ago0xa3a502569bf1bfbf7b361964d61335a7530d39e8 IN  0x70abdb857e191b1033b6c67274681c816f3343bf0 BNB0.009040755
0xc5a5acf1081e8353d90a652eae278a2871319f4645ccdb6e4e0a75c33957a69cRebalance74350732021-05-15 16:03:25159 days 11 hrs agoIron Finance: Deployer IN  0x70abdb857e191b1033b6c67274681c816f3343bf0 BNB0.002420955
0x3336aadd52a913862f35e26bea1ce0012945c2fdba273cc3a7202bcf81995ce3Rebalance74350722021-05-15 16:03:22159 days 11 hrs agoIron Finance: Deployer IN  0x70abdb857e191b1033b6c67274681c816f3343bf0 BNB0.002705485
0x7756a1d4c6e313e179ae4d6822e5bc8403b3d8151e1995fdfdf09c8d96f630e5Rebalance74350702021-05-15 16:03:16159 days 11 hrs agoIron Finance: Deployer IN  0x70abdb857e191b1033b6c67274681c816f3343bf0 BNB0.00227047
0x5156a622dce9f0c7ad7c44e05d0a45b41603833a7105d0dccb33ab495e893ac4Rebalance74329852021-05-15 14:17:15159 days 13 hrs agoIron Finance: Deployer IN  0x70abdb857e191b1033b6c67274681c816f3343bf0 BNB0.003147985
0xad2f71f0823eca07359e1d8477021d48deb9768e1652cadb82c7f09dc52b24ceRebalance74329342021-05-15 14:14:42159 days 13 hrs agoIron Finance: Deployer IN  0x70abdb857e191b1033b6c67274681c816f3343bf0 BNB0.00322224
0xb1a677e3f2cad78f796c7775710fb80660edf16e9e2a6f6a047493c2e0ce1f46Rebalance74328572021-05-15 14:10:51159 days 13 hrs agoIron Finance: Deployer IN  0x70abdb857e191b1033b6c67274681c816f3343bf0 BNB0.003263105
0x5d5ef52ae051e67b0488e7b40a8035f1cd7cc36019298a98df7d55a298784691Allocate Seignio...74314702021-05-15 13:01:19159 days 14 hrs ago0xa3a502569bf1bfbf7b361964d61335a7530d39e8 IN  0x70abdb857e191b1033b6c67274681c816f3343bf0 BNB0.009040755
0xf631f0caa187a71e91b1c90a1f567f6a9fec6120baf2357b714a3a9b2cca6731Allocate Seignio...74177442021-05-15 1:01:16160 days 2 hrs ago0xa3a502569bf1bfbf7b361964d61335a7530d39e8 IN  0x70abdb857e191b1033b6c67274681c816f3343bf0 BNB0.009040755
0xc01e4df406c8bbb8f5a4147bd974573219748b193776941becbd05099c64d9d1Allocate Seignio...74035412021-05-14 13:01:17160 days 14 hrs ago0xa3a502569bf1bfbf7b361964d61335a7530d39e8 IN  0x70abdb857e191b1033b6c67274681c816f3343bf0 BNB0.009040755
0x77fd47cd289ee5a6763b0d52a2e438035ddd6e35368147e3934e06d1d2c5f3fdAllocate Seignio...73892912021-05-14 1:01:23161 days 2 hrs ago0xa3a502569bf1bfbf7b361964d61335a7530d39e8 IN  0x70abdb857e191b1033b6c67274681c816f3343bf0 BNB0.009040755
0x2566bec9856e74b334163efac88bded0a12e863290b724f7f343842f3c79da2eAllocate Seignio...73750412021-05-13 13:01:21161 days 14 hrs ago0xa3a502569bf1bfbf7b361964d61335a7530d39e8 IN  0x70abdb857e191b1033b6c67274681c816f3343bf0 BNB0.009040755
0x4fbe14da350443bfc0660bac8f2c5fcbd9a012136e421570cac88cc60c4158b8Allocate Seignio...73609732021-05-13 1:01:23162 days 2 hrs ago0xa3a502569bf1bfbf7b361964d61335a7530d39e8 IN  0x70abdb857e191b1033b6c67274681c816f3343bf0 BNB0.009040755
0x28fcc66325f49453ed5fa628471da98d5b50a5f2d3119974f9ed5fc89eee3787Allocate Seignio...73473232021-05-12 13:01:23162 days 14 hrs ago0xa3a502569bf1bfbf7b361964d61335a7530d39e8 IN  0x70abdb857e191b1033b6c67274681c816f3343bf0 BNB0.009040755
0x0cf735f049d7efa1b7b7c491e25efa5248d7678f8b3c62a8a34960fd91edbbd9Allocate Seignio...73345302021-05-12 1:01:13163 days 2 hrs ago0xa3a502569bf1bfbf7b361964d61335a7530d39e8 IN  0x70abdb857e191b1033b6c67274681c816f3343bf0 BNB0.009490755
0x04bd2b61aa05ff97175f1d9fcae98b36640f6ee4d5fd960f8e17b9466ce34699Add Pool73287252021-05-11 19:38:59163 days 7 hrs ago0x62ca555de2d65f8e9d45a9b3d5c1b92ac1a64ecc IN  0x70abdb857e191b1033b6c67274681c816f3343bf0 BNB0.001013012
0x7681b51b6bcbeea6766b8d2c36886085fd5c17706dafccdf733711edf408a6a3Add Pool73287202021-05-11 19:38:43163 days 7 hrs ago0x62ca555de2d65f8e9d45a9b3d5c1b92ac1a64ecc IN  0x70abdb857e191b1033b6c67274681c816f3343bf0 BNB0.001013012
0x812dbc1695afdc8d51c83dfdeff7ac54090ead9653c8f919ee6bd88efc0879a8Transfer Operato...73287122021-05-11 19:38:17163 days 7 hrs ago0x62ca555de2d65f8e9d45a9b3d5c1b92ac1a64ecc IN  0x70abdb857e191b1033b6c67274681c816f3343bf0 BNB0.00042259
0x505b562d19189996a177a3b7d96f6de08cfde54cc0c653124e3f83bb1e28263cAllocate Seignio...73212252021-05-11 13:01:28163 days 14 hrs ago0xa3a502569bf1bfbf7b361964d61335a7530d39e8 IN  0x70abdb857e191b1033b6c67274681c816f3343bf0 BNB0.003404412
0xde921b473a6032764c163cda93c25303394d408f9ec1012323e523e830381e52Allocate Seignio...73093002021-05-11 1:12:53164 days 2 hrs ago0xa3a502569bf1bfbf7b361964d61335a7530d39e8 IN  0x70abdb857e191b1033b6c67274681c816f3343bf0 BNB0.003404412
0x8ff899171d7cff18675314963aff69be282633b81c52d8433f8f15b4cf15a969Allocate Seignio...72974402021-05-10 13:03:09164 days 14 hrs ago0xa3a502569bf1bfbf7b361964d61335a7530d39e8 IN  0x70abdb857e191b1033b6c67274681c816f3343bf0 BNB0.002647876
0xd31b5311b6a72ff2253c53ad8eb5f086c03796907c8f2bf23206cb1fc3839efbAllocate Seignio...72839062021-05-10 1:02:09165 days 2 hrs ago0xa3a502569bf1bfbf7b361964d61335a7530d39e8 IN  0x70abdb857e191b1033b6c67274681c816f3343bf0 BNB0.00189134
0xd03b8345e938f85cf17c8af4e95582180a2992249a4ce893fd801e296a85bd81Allocate Seignio...72701982021-05-09 13:01:28165 days 14 hrs ago0xa3a502569bf1bfbf7b361964d61335a7530d39e8 IN  0x70abdb857e191b1033b6c67274681c816f3343bf0 BNB0.00139117
[ Download CSV Export 
Parent Txn Hash Block From To Value
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
Treasury

Compiler Version
v0.7.6+commit.7338295f

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion, MIT license

Contract Source Code (Solidity Standard Json-Input format)

File 1 of 23 : Context.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

import "../utils/Context.sol";

File 2 of 23 : Ownable.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

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

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

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    constructor () internal {
        address msgSender = _msgSender();
        _owner = msgSender;
        emit OwnershipTransferred(address(0), msgSender);
    }

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

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

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

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

File 3 of 23 : SafeMath.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.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, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        uint256 c = a + b;
        if (c < a) return (false, 0);
        return (true, c);
    }

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

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

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

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

    /**
     * @dev Returns the addition of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `+` operator.
     *
     * Requirements:
     *
     * - Addition cannot overflow.
     */
    function add(uint256 a, uint256 b) internal pure returns (uint256) {
        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) {
        require(b <= a, "SafeMath: subtraction overflow");
        return a - b;
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `*` operator.
     *
     * Requirements:
     *
     * - Multiplication cannot overflow.
     */
    function mul(uint256 a, uint256 b) internal pure returns (uint256) {
        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, reverting 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) {
        require(b > 0, "SafeMath: division by zero");
        return a / b;
    }

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

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

    /**
     * @dev Returns the integer division of two unsigned integers, reverting with custom message on
     * division by zero. The result is rounded towards zero.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {tryDiv}.
     *
     * 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);
        return a / b;
    }

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

File 4 of 23 : ERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

import "../../utils/Context.sol";
import "./IERC20.sol";
import "../../math/SafeMath.sol";

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

    mapping (address => uint256) private _balances;

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

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;
    uint8 private _decimals;

    /**
     * @dev Sets the values for {name} and {symbol}, initializes {decimals} with
     * a default value of 18.
     *
     * To select a different value for {decimals}, use {_setupDecimals}.
     *
     * All three of these values are immutable: they can only be set once during
     * construction.
     */
    constructor (string memory name_, string memory symbol_) public {
        _name = name_;
        _symbol = symbol_;
        _decimals = 18;
    }

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

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

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

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

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

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

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

    /**
     * @dev See {IERC20-approve}.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function approve(address spender, uint256 amount) public virtual override returns (bool) {
        _approve(_msgSender(), spender, amount);
        return true;
    }

    /**
     * @dev See {IERC20-transferFrom}.
     *
     * Emits an {Approval} event indicating the updated allowance. This is not
     * required by the EIP. See the note at the beginning of {ERC20}.
     *
     * Requirements:
     *
     * - `sender` and `recipient` cannot be the zero address.
     * - `sender` must have a balance of at least `amount`.
     * - the caller must have allowance for ``sender``'s tokens of at least
     * `amount`.
     */
    function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
        _transfer(sender, recipient, amount);
        _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
        return true;
    }

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

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

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

        _beforeTokenTransfer(sender, recipient, amount);

        _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
        _balances[recipient] = _balances[recipient].add(amount);
        emit Transfer(sender, recipient, amount);
    }

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

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

        _totalSupply = _totalSupply.add(amount);
        _balances[account] = _balances[account].add(amount);
        emit Transfer(address(0), account, amount);
    }

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

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

        _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
        _totalSupply = _totalSupply.sub(amount);
        emit Transfer(account, address(0), amount);
    }

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

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

    /**
     * @dev Sets {decimals} to a value other than the default one of 18.
     *
     * WARNING: This function should only be called from the constructor. Most
     * applications that interact with token contracts will not expect
     * {decimals} to ever change, and may work incorrectly if it does.
     */
    function _setupDecimals(uint8 decimals_) internal virtual {
        _decimals = decimals_;
    }

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

File 5 of 23 : IERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.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);
}

File 6 of 23 : SafeERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.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");
        }
    }
}

File 7 of 23 : Address.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.2 <0.8.0;

/**
 * @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) {
        // This method relies on extcodesize, which returns 0 for contracts in
        // construction, since the code is only stored at the end of the
        // constructor execution.

        uint256 size;
        // solhint-disable-next-line no-inline-assembly
        assembly { size := extcodesize(account) }
        return size > 0;
    }

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

        // 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");
        require(isContract(target), "Address: call to non-contract");

        // solhint-disable-next-line avoid-low-level-calls
        (bool success, bytes memory returndata) = target.call{ value: value }(data);
        return _verifyCallResult(success, returndata, errorMessage);
    }

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

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

        // solhint-disable-next-line avoid-low-level-calls
        (bool success, bytes memory returndata) = target.staticcall(data);
        return _verifyCallResult(success, returndata, errorMessage);
    }

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

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

        // solhint-disable-next-line avoid-low-level-calls
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return _verifyCallResult(success, returndata, errorMessage);
    }

    function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) {
        if (success) {
            return returndata;
        } else {
            // Look for revert reason and bubble it up if present
            if (returndata.length > 0) {
                // The easiest way to bubble the revert reason is using memory via assembly

                // solhint-disable-next-line no-inline-assembly
                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}

File 8 of 23 : Context.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

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

    function _msgData() internal view virtual returns (bytes memory) {
        this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
        return msg.data;
    }
}

File 9 of 23 : ReentrancyGuard.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

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

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

    uint256 private _status;

    constructor () 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;
    }
}

File 10 of 23 : Operator.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.7.6;

import "@openzeppelin/contracts/GSN/Context.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

abstract contract Operator is Context, Ownable {
    address private _operator;

    event OperatorTransferred(address indexed previousOperator, address indexed newOperator);

    constructor() {
        _operator = _msgSender();
        emit OperatorTransferred(address(0), _operator);
    }

    function operator() public view returns (address) {
        return _operator;
    }

    modifier onlyOperator() {
        require(_operator == msg.sender, "operator: caller is not the operator");
        _;
    }

    function isOperator() public view returns (bool) {
        return _msgSender() == _operator;
    }

    function transferOperator(address newOperator_) public onlyOwner {
        _transferOperator(newOperator_);
    }

    function _transferOperator(address newOperator_) internal {
        require(newOperator_ != address(0), "operator: zero address given for new operator");
        emit OperatorTransferred(address(0), newOperator_);
        _operator = newOperator_;
    }
}

File 11 of 23 : Pool.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.7.6;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";

import "./interfaces/IDiamond.sol";
import "./interfaces/IDToken.sol";
import "./interfaces/ITreasury.sol";
import "./interfaces/IOracle.sol";
import "./interfaces/IPool.sol";
import "./Operator.sol";

contract Pool is Operator, ReentrancyGuard, IPool {
    using SafeMath for uint256;
    using SafeERC20 for ERC20;

    /* ========== STATE VARIABLES ========== */

    address public immutable override collateral;
    address public immutable override dToken;
    address public override diamond;
    address public oracleDiamond;
    address public oracleDToken;
    address public treasury;

    mapping(address => uint256) public redeem_diamond_balances;
    mapping(address => uint256) public redeem_collateral_balances;

    uint256 public override unclaimed_pool_collateral;
    uint256 public override unclaimed_pool_diamond;

    mapping(address => uint256) public last_redeemed;

    // Constants for various precisions
    uint256 private constant PRICE_PRECISION = 1e6;

    // Number of decimals needed to get to 18
    uint256 private immutable missing_decimals;

    // Pool_ceiling is the total units of collateral that a pool contract can hold
    uint256 public pool_ceiling = 0;

    // Number of blocks to wait before being able to collectRedemption()
    uint256 public redemption_delay = 1;

    // AccessControl state variables
    bool public mint_paused = false;
    bool public redeem_paused = false;
    bool public migrated = false;

    // Collateral ratio
    uint256 public last_refresh_cr_timestamp;
    uint256 public target_collateral_ratio = 1000000;
    uint256 public effective_collateral_ratio = 1000000;
    bool public target_collateral_ratio_paused = false;
    bool public effective_collateral_ratio_paused = false;
    uint256 public refresh_cooldown;
    uint256 public ratio_step;
    uint256 public price_target;
    uint256 public price_band;
    uint256 private constant COLLATERAL_RATIO_PRECISION = 1e6;
    uint256 private constant COLLATERAL_RATIO_MAX = 1e6;

    // fee
    uint256 public redemption_fee;
    uint256 public minting_fee;

    /* ========== MODIFIERS ========== */

    modifier notMigrated() {
        require(!migrated, "migrated");
        _;
    }

    /* ========== CONSTRUCTOR ========== */

    constructor(
        address _dToken,
        address _diamond,
        address _collateral,
        uint256 _pool_ceiling,
        address _treasury
    ) {
        dToken = _dToken;
        diamond = _diamond;
        collateral = _collateral;
        treasury = _treasury;
        pool_ceiling = _pool_ceiling;
        missing_decimals = uint256(18).sub(ERC20(_collateral).decimals());
        ratio_step = 2500;
        refresh_cooldown = 3600;
        price_target = 1000000; // match exactly 100%
        price_band = 1500; // 0.5% of diff
        redemption_fee = 3000;
        minting_fee = 1000;
    }

    /* ========== VIEWS ========== */

    function collateralReserve() public view returns (address) {
        return ITreasury(treasury).collateralReserve();
    }

    function globalCollateralBalance() public view returns (uint256) {
        return ITreasury(treasury).globalCollateralValue(collateral);
    }

    function collateralBalance() public view override returns (uint256) {
        return (ERC20(collateral).balanceOf(collateralReserve()).sub(unclaimed_pool_collateral)).mul(10**missing_decimals);
    }

    function info()
        external
        view
        override
        returns (
            uint256,
            uint256,
            uint256,
            uint256,
            uint256,
            uint256,
            bool,
            bool,
            address,
            address,
            string memory,
            string memory,
            uint256,
            uint256
        )
    {
        return (pool_ceiling, collateralBalance(), unclaimed_pool_collateral, unclaimed_pool_diamond, minting_fee, redemption_fee, mint_paused, redeem_paused, collateral, dToken, ERC20(collateral).symbol(), ERC20(dToken).symbol(), target_collateral_ratio, effective_collateral_ratio);
    }

    function diamondToCollateralPrice() public view override returns (uint256) {
        return IOracle(oracleDiamond).consult();
    }

    function dTokenToCollateralPrice() public view override returns (uint256) {
        return IOracle(oracleDToken).consult();
    }

    function calcEffectiveCollateralRatio() public view returns (uint256) {
        if (effective_collateral_ratio_paused) {
            return target_collateral_ratio;
        }
        uint256 total_collateral = globalCollateralBalance();
        uint256 total_supply_dToken = IERC20(dToken).totalSupply();
        uint256 ecr = total_collateral.mul(PRICE_PRECISION).div(total_supply_dToken);
        if (ecr > COLLATERAL_RATIO_MAX) {
            return COLLATERAL_RATIO_MAX;
        }
        return ecr;
    }

    /* ========== PUBLIC FUNCTIONS ========== */

    function mint(
        uint256 _collateral_amount,
        uint256 _diamond_amount,
        uint256 _dtoken_out_min
    ) external override notMigrated {
        require(!mint_paused, "Minting is paused");
        require(collateralBalance().add(_collateral_amount) <= pool_ceiling, "Pool ceiling was reached");

        uint256 _diamond_relative_price = diamondToCollateralPrice();
        uint256 _total_value = 0;
        uint256 _required_diamond_amount = 0;
        if (target_collateral_ratio > 0) {
            _total_value = _collateral_amount.mul(10**missing_decimals).mul(COLLATERAL_RATIO_PRECISION).div(target_collateral_ratio);
            if (target_collateral_ratio < COLLATERAL_RATIO_MAX) {
                _required_diamond_amount = _total_value.sub(_collateral_amount).mul(PRICE_PRECISION).div(_diamond_relative_price);
            }
        } else {
            _total_value = _diamond_amount.mul(_diamond_relative_price).div(PRICE_PRECISION);
            _required_diamond_amount = _diamond_amount;
        }
        uint256 _actual_output_amount = _total_value.sub((_total_value.mul(minting_fee)).div(PRICE_PRECISION));
        require(_dtoken_out_min <= _actual_output_amount, ">slippage");

        if (_required_diamond_amount > 0) {
            require(_required_diamond_amount <= _diamond_amount, "<shareBalance");
            IDiamond(diamond).poolBurnFrom(msg.sender, _required_diamond_amount);
        }
        if (_collateral_amount > 0) {
            _transferCollateralToReserve(msg.sender, _collateral_amount);
        }
        IDToken(dToken).poolMint(msg.sender, _actual_output_amount);
    }

    function redeem(
        uint256 _dToken_amount,
        uint256 _diamond_out_min,
        uint256 _collateral_out_min
    ) external notMigrated {
        require(!redeem_paused, "Redeeming is paused");
        uint256 _diamond_relative_price = diamondToCollateralPrice();
        uint256 _dtoken_amount_post_fee = _dToken_amount.sub((_dToken_amount.mul(redemption_fee)).div(PRICE_PRECISION));
        uint256 _collateral_output_amount = 0;
        uint256 _diamond_output_amount = 0;

        if (effective_collateral_ratio < COLLATERAL_RATIO_MAX) {
            uint256 _diamond_output_value = _dtoken_amount_post_fee.sub(_dtoken_amount_post_fee.mul(effective_collateral_ratio).div(PRICE_PRECISION));
            _diamond_output_amount = _diamond_output_value.mul(PRICE_PRECISION).div(_diamond_relative_price);
        }

        if (effective_collateral_ratio > 0) {
            _collateral_output_amount = _dtoken_amount_post_fee.div(10**missing_decimals).mul(effective_collateral_ratio).div(PRICE_PRECISION);
        }

        if (_collateral_output_amount > 0) {
            redeem_collateral_balances[msg.sender] = redeem_collateral_balances[msg.sender].add(_collateral_output_amount);
            unclaimed_pool_collateral = unclaimed_pool_collateral.add(_collateral_output_amount);
        }

        if (_diamond_output_amount > 0) {
            redeem_diamond_balances[msg.sender] = redeem_diamond_balances[msg.sender].add(_diamond_output_amount);
            unclaimed_pool_diamond = unclaimed_pool_diamond.add(_diamond_output_amount);
        }

        last_redeemed[msg.sender] = block.number;

        // Check if collateral balance meets and meet output expectation
        require(ERC20(collateral).balanceOf(collateralReserve()) >= unclaimed_pool_collateral, "<collateralBalance");
        require(_collateral_out_min <= _collateral_output_amount && _diamond_out_min <= _diamond_output_amount, ">slippage");

        // Move all external functions to the end
        IDToken(dToken).poolBurnFrom(msg.sender, _dToken_amount);
        if (_diamond_output_amount > 0) {
            _mintDiamondToCollateralReserve(_diamond_output_amount);
        }
    }

    function collectRedemption() external {
        // Redeem and Collect cannot happen in the same transaction to avoid flash loan attack
        require((last_redeemed[msg.sender].add(redemption_delay)) <= block.number, "<redemption_delay");

        bool _send_diamond = false;
        bool _send_collateral = false;
        uint256 _share_amount;
        uint256 _collateral_amount;

        if (redeem_diamond_balances[msg.sender] > 0) {
            _share_amount = redeem_diamond_balances[msg.sender];
            redeem_diamond_balances[msg.sender] = 0;
            unclaimed_pool_diamond = unclaimed_pool_diamond.sub(_share_amount);
            _send_diamond = true;
        }

        if (redeem_collateral_balances[msg.sender] > 0) {
            _collateral_amount = redeem_collateral_balances[msg.sender];
            redeem_collateral_balances[msg.sender] = 0;
            unclaimed_pool_collateral = unclaimed_pool_collateral.sub(_collateral_amount);
            _send_collateral = true;
        }

        if (_send_diamond) {
            _requestTransferDiamond(msg.sender, _share_amount);
        }

        if (_send_collateral) {
            _requestTransferCollateral(msg.sender, _collateral_amount);
        }
    }

    function refreshCollateralRatio() public {
        require(!target_collateral_ratio_paused, "Target Collateral Ratio has been paused");
        require(block.timestamp - last_refresh_cr_timestamp >= refresh_cooldown, "Must wait for the refresh cooldown since last refresh");

        uint256 current_dtoken_price = dTokenToCollateralPrice();

        if (current_dtoken_price > price_target.add(price_band)) {
            if (target_collateral_ratio <= ratio_step) {
                target_collateral_ratio = 0;
            } else {
                target_collateral_ratio = target_collateral_ratio.sub(ratio_step);
            }
        } else if (current_dtoken_price < price_target.sub(price_band)) {
            if (target_collateral_ratio.add(ratio_step) >= COLLATERAL_RATIO_MAX) {
                target_collateral_ratio = COLLATERAL_RATIO_MAX;
            } else {
                target_collateral_ratio = target_collateral_ratio.add(ratio_step);
            }
        }

        // If using ECR, then calcECR. If not, update ECR = TCR
        if (!effective_collateral_ratio_paused) {
            effective_collateral_ratio = calcEffectiveCollateralRatio();
        } else {
            effective_collateral_ratio = target_collateral_ratio;
        }

        last_refresh_cr_timestamp = block.timestamp;
    }

    /* ========== INTERNAL FUNCTIONS ========== */

    function _transferCollateralToReserve(address _sender, uint256 _amount) internal {
        address _reserve = collateralReserve();
        require(_reserve != address(0), "Invalid reserve address");
        ERC20(collateral).safeTransferFrom(_sender, _reserve, _amount);
    }

    function _mintDiamondToCollateralReserve(uint256 _amount) internal {
        address _reserve = collateralReserve();
        require(_reserve != address(0), "Invalid reserve address");
        IDiamond(diamond).poolMint(_reserve, _amount);
    }

    function _requestTransferCollateral(address _receiver, uint256 _amount) internal {
        ITreasury(treasury).requestTransfer(collateral, _receiver, _amount);
    }

    function _requestTransferDiamond(address _receiver, uint256 _amount) internal {
        ITreasury(treasury).requestTransfer(diamond, _receiver, _amount);
    }

    /* ========== RESTRICTED FUNCTIONS ========== */

    function setOracleDToken(address _oracleDToken) public onlyOperator {
        oracleDToken = _oracleDToken;
    }

    function setOracleDiamond(address _oracleDiamond) public onlyOperator {
        oracleDiamond = _oracleDiamond;
    }

    function resetCollateralRatios(uint256 _tcr, uint256 _ecr) external onlyOperator {
        target_collateral_ratio = _tcr;
        effective_collateral_ratio = _ecr;
    }

    function toggleMinting() external onlyOperator {
        mint_paused = !mint_paused;
    }

    function toggleRedeeming() external onlyOperator {
        redeem_paused = !redeem_paused;
    }

    function setPoolCeiling(uint256 _pool_ceiling) external onlyOperator {
        pool_ceiling = _pool_ceiling;
    }

    function setRedemptionDelay(uint256 _redemption_delay) external onlyOperator {
        redemption_delay = _redemption_delay;
    }

    function setRedemptionFee(uint256 _redemption_fee) public onlyOperator {
        redemption_fee = _redemption_fee;
        emit RedemptionFeeChanged(redemption_fee);
    }

    function setMintingFee(uint256 _minting_fee) public onlyOperator {
        minting_fee = _minting_fee;
        emit MintingFeeChanged(minting_fee);
    }

    function setRatioStep(uint256 _ratio_step) public onlyOperator {
        ratio_step = _ratio_step;
        emit RatioStepChanged(ratio_step);
    }

    function setPriceTarget(uint256 _price_target) public onlyOperator {
        price_target = _price_target;
    }

    function setRefreshCooldown(uint256 _refresh_cooldown) public onlyOperator {
        refresh_cooldown = _refresh_cooldown;
    }

    function setPriceBand(uint256 _price_band) external onlyOperator {
        require(_price_band > 0, "Invalid Price Band");
        price_band = _price_band;
        emit PriceBandChanged(price_band);
    }

    function toggleCollateralRatio() public onlyOperator {
        target_collateral_ratio_paused = !target_collateral_ratio_paused;
    }

    function toggleEffectiveCollateralRatio() public onlyOperator {
        effective_collateral_ratio_paused = !effective_collateral_ratio_paused;
    }

    function setDiamondAddress(address _diamond) public onlyOperator {
        require(_diamond != address(0), "invalidAddress");
        diamond = _diamond;
        emit DiamondAddressChanged(_diamond);
    }

    function setTreasury(address _treasury) public onlyOperator {
        require(_treasury != address(0), "invalidAddress");
        treasury = _treasury;
        emit TreasuryChanged(treasury);
    }

    /* =============== EVENTS ==================== */

    event TreasuryChanged(address indexed newTreasury);
    event DiamondAddressChanged(address indexed newDiamondAddress);
    event PriceBandChanged(uint256 newPriceBand);
    event MintingFeeChanged(uint256 newPriceBand);
    event RedemptionFeeChanged(uint256 newPriceBand);
    event RatioStepChanged(uint256 newPriceBand);
}

File 12 of 23 : Treasury.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.7.6;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import "./interfaces/ITreasury.sol";
import "./interfaces/IFoundry.sol";
import "./interfaces/ICollateralReserve.sol";
import "./interfaces/IFoundryFund.sol";
import "./interfaces/IFoundryController.sol";
import "./interfaces/IVaultProxy.sol";
import "./interfaces/ITreasuryPolicy.sol";
import "./Pool.sol";
import "./Operator.sol";

contract Treasury is Operator, ITreasury, ReentrancyGuard {
    using SafeMath for uint256;
    using SafeERC20 for IERC20;

    // pools
    address[] public pools_array;
    mapping(address => bool) public pools;

    // addresses
    address public override collateralReserve;
    address public vaultProxy;
    address public vaultAdmin;
    address public treasuryPolicy;
    address public foundryFund;
    address public foundryController;

    // mines
    uint256 public override epoch;
    uint256 public epochLength;
    uint256 public lastEpochTimestamp;
    bool public epochInitialized;
    uint256 public epochStartTime;

    // constants
    uint256 public constant RATIO_PRECISION = 1e6;

    /* ========== MODIFIERS ========== */

    modifier checkEpoch {
        uint256 _nextEpochPoint = nextEpochTimestamp();
        require(block.timestamp >= _nextEpochPoint, "Treasury: not opened yet");
        _;
        lastEpochTimestamp = _nextEpochPoint;
        epoch = epoch.add(1);
    }

    modifier onlyPools {
        require(isPool(msg.sender), "Only pools can use this function");
        _;
    }

    modifier onlyVaultAdmin() {
        require(vaultAdmin == msg.sender, "!vaultAdmin");
        _;
    }

    /* ========== CONSTRUCTOR ========== */

    constructor(
        address _collateralReserve,
        address _foundryFund,
        address _treasuryPolicy,
        address _vaultProxy
    ) {
        collateralReserve = _collateralReserve;
        foundryFund = _foundryFund;
        treasuryPolicy = _treasuryPolicy;
        vaultProxy = _vaultProxy;
    }

    /* ========== VIEWS ========== */

    function isPool(address _address) public view override returns (bool) {
        return pools[_address];
    }

    function isMintingPool(address _poolAddress, address _dToken) public view override returns (bool) {
        bool existed = isPool(_poolAddress);
        if (!existed) {
            return false;
        }
        address poolDToken = IPool(_poolAddress).dToken();
        if (poolDToken != _dToken) {
            return false;
        }
        return true;
    }

    function utilizationRatio(address _foundry) external view override returns (uint256) {
        (address _collateral, uint256 _allocation) = IFoundryController(foundryController).getFoundryByAddress(_foundry);
        uint256 _fundBalance = IFoundryFund(foundryFund).fundBalance(_collateral);
        if (_collateral == address(0) || _fundBalance == 0) {
            return 0;
        }
        return _allocation.mul(RATIO_PRECISION).div(_fundBalance);
    }

    function nextEpochTimestamp() public view override returns (uint256) {
        return lastEpochTimestamp.add(epochLength);
    }

    function epochInfo()
        external
        view
        override
        returns (
            uint256,
            uint256,
            uint256
        )
    {
        return (epoch, nextEpochTimestamp(), epochLength);
    }

    // Iterate through all pools and calculate all value of collateral in all pools globally
    function globalCollateralValue(address _asset) public view override returns (uint256) {
        (address _pool, , , ) = ITreasuryPolicy(treasuryPolicy).getPolicy(_asset);
        uint256 _collateralReserveBalance = IERC20(_asset).balanceOf(collateralReserve);
        uint256 _unclaimedCollateralBalance = Pool(_pool).unclaimed_pool_collateral();
        uint256 _vaultBalance = IVaultProxy(vaultProxy).vaultBalance(_asset);
        return _vaultBalance.add(_collateralReserveBalance).sub(_unclaimedCollateralBalance);
    }

    // check if collateral reserve is above threshold
    function calcCollateralReserveRatio(address _asset) public view returns (uint256) {
        (address _pool, , , ) = ITreasuryPolicy(treasuryPolicy).getPolicy(_asset);
        uint256 _poolCollateralBalance = Pool(_pool).collateralBalance();
        uint256 _totalCollateralBalance = globalCollateralValue(_asset);
        if (_totalCollateralBalance == 0) {
            return 0;
        }
        return _poolCollateralBalance.mul(RATIO_PRECISION).div(_totalCollateralBalance);
    }

    // check if collateral reserve is above threshold
    function isAboveThreshold(address _asset) public view returns (bool) {
        (, , uint256 _threshold, ) = ITreasuryPolicy(treasuryPolicy).getPolicy(_asset);
        uint256 _ratio = calcCollateralReserveRatio(_asset);
        return _ratio >= _threshold;
    }

    /* ========== PUBLIC FUNCTIONS ========== */

    function allocateSeigniorage() external nonReentrant checkEpoch {
        require(foundryController != address(0), "noFoundryController");
        IFoundryController _foundryController = IFoundryController(foundryController);
        uint256 _foundries_length = _foundryController.getFoundriesLength();
        for (uint256 index = 0; index < _foundries_length; index++) {
            allocateSingleFoundry(index);
        }
    }

    /* ========== VAULT FUNCTIONS =============== */

    function rebalance(address _asset) public onlyVaultAdmin nonReentrant {
        require(vaultProxy != address(0), "Vault does not exist");
        (, uint256 _profit) = IVaultProxy(vaultProxy).harvest(_asset);
        if (_profit > 0) {
            distributeProfit(_asset, _profit);
        }
        enterVault(_asset);
    }

    function checkThreshold(address _asset) external onlyVaultAdmin {
        if (!isAboveThreshold(_asset)) {
            rebalance(_asset);
        }
    }

    /* -========= INTERNAL FUNCTIONS ============ */

    function distributeProfit(address _asset, uint256 _profitAmount) internal {
        require(_asset != address(0), "Invalid asset");
        require(treasuryPolicy != address(0), "No treasury policy");
        require(_profitAmount > 0, "Zero amount profit");
        (, , , uint256 _profitSharingRatio) = ITreasuryPolicy(treasuryPolicy).getPolicy(_asset);
        uint256 _foundryFundAlloc = _profitAmount.mul(_profitSharingRatio).div(RATIO_PRECISION);
        uint256 _poolAlloc = _profitAmount.sub(_foundryFundAlloc);
        require(foundryFund != address(0), "No foundry fund");
        require(collateralReserve != address(0), "No collateral reserve");
        IERC20(_asset).safeTransfer(foundryFund, _foundryFundAlloc);
        IERC20(_asset).safeTransfer(collateralReserve, _poolAlloc);
    }

    function enterVault(address _collateral) internal {
        require(collateralReserve != address(0), "No collateral reserve");
        require(treasuryPolicy != address(0), "No treasury policy");

        IERC20 _token = IERC20(_collateral);

        // 1. move all collateral from treasury back to collateral reserve
        _token.safeTransfer(collateralReserve, _token.balanceOf(address(this)));

        (address _pool, uint256 _utilizationRatio, , ) = ITreasuryPolicy(treasuryPolicy).getPolicy(_collateral);

        // 2. now pools should contain all collaterals. we will calc how much to use
        uint256 _poolCollateralBalance = Pool(_pool).collateralBalance();
        uint256 _investmentAmount = _utilizationRatio.mul(_poolCollateralBalance).div(RATIO_PRECISION);
        if (_investmentAmount > 0) {
            ICollateralReserve(collateralReserve).transferTo(_collateral, address(this), _investmentAmount);
            _token.safeApprove(vaultProxy, 0);
            _token.safeApprove(vaultProxy, _investmentAmount);
            IVaultProxy(vaultProxy).enter(_collateral, _investmentAmount);
        }
    }

    function allocateSingleFoundry(uint256 _foundryId) internal {
        IFoundryController _foundryController = IFoundryController(foundryController);
        (address _foundry, address _collateral, uint256 _allocation) = _foundryController.getFoundry(_foundryId);
        if (_foundry == address(0) || _collateral == address(0)) {
            return;
        }
        IFoundryFund _fund = IFoundryFund(foundryFund);
        uint256 _fundBalance = _fund.fundBalance(_collateral);
        if (_allocation > 0 && _fundBalance >= _allocation) {
            IFoundry(_foundry).allocateSeigniorage(_allocation);
            _fund.transferTo(_collateral, _foundry, _allocation);
        }
    }

    /* ========== RESTRICTED FUNCTIONS ========== */

    function requestTransfer(
        address _token,
        address _receiver,
        uint256 _amount
    ) external override onlyPools {
        ICollateralReserve(collateralReserve).transferTo(_token, _receiver, _amount);
    }

    function initializeEpoch(
        uint256 _startEpoch,
        uint256 _startTime,
        uint256 _epochLength
    ) external onlyOperator {
        require(_startTime > block.timestamp, "startTimeInThePast");
        epoch = _startEpoch;
        epochStartTime = _startTime;
        epochLength = _epochLength;
        lastEpochTimestamp = _startTime.sub(_epochLength);
        epochInitialized = true;
    }

    // Add new Pool
    function addPool(address pool_address) public onlyOperator {
        require(!isPool(pool_address), "poolExisted");
        pools[pool_address] = true;
        pools_array.push(pool_address);
        emit PoolAdded(pool_address);
    }

    // Remove a pool
    function removePool(address pool_address) public onlyOperator {
        require(pools[pool_address], "!pool");
        // Delete from the mapping
        delete pools[pool_address];
        // 'Delete' from the array without leaving a hole
        for (uint256 i = 0; i < pools_array.length; i++) {
            if (pools_array[i] == pool_address) {
                pools_array[i] = pools_array[pools_array.length - 1];
                break;
            }
        }
        pools_array.pop();
        emit PoolRemoved(pool_address);
    }

    function setEpochDuration(uint256 duration) public onlyOperator {
        epochLength = duration;
    }

    function setVaultProxy(address _vaultProxy) external onlyOperator {
        require(_vaultProxy != address(0), "invalidAddress");
        vaultProxy = _vaultProxy;
    }

    function setVaultAdmin(address _vaultAdmin) external onlyOperator {
        require(_vaultAdmin != address(0), "invalidAddress");
        vaultAdmin = _vaultAdmin;
    }

    function setCollateralReserve(address _collateralReserve) external onlyOperator {
        require(_collateralReserve != address(0), "invalidAddress");
        collateralReserve = _collateralReserve;
        emit CollateralReserveChanged(collateralReserve);
    }

    function setTreasuryPolicy(address _treasuryPolicy) external onlyOperator {
        require(_treasuryPolicy != address(0), "invalidAddress");
        treasuryPolicy = _treasuryPolicy;
    }

    function setFoundryFund(address _foundryFund) external onlyOperator {
        require(_foundryFund != address(0), "invalidAddress");
        foundryFund = _foundryFund;
    }

    function setFoundryController(address _foundryController) external onlyOperator {
        require(_foundryController != address(0), "invalidAddress");
        foundryController = _foundryController;
    }
}

File 13 of 23 : ICollateralReserve.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.7.6;
pragma experimental ABIEncoderV2;

interface ICollateralReserve {
    function transferTo(
        address _token,
        address _receiver,
        uint256 _amount
    ) external;
}

File 14 of 23 : IDToken.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.7.6;
pragma experimental ABIEncoderV2;

interface IDToken {
    function poolBurnFrom(address _address, uint256 _amount) external;

    function poolMint(address _address, uint256 m_amount) external;
}

File 15 of 23 : IDiamond.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.7.6;
pragma experimental ABIEncoderV2;

interface IDiamond {
    function poolBurnFrom(address _address, uint256 _amount) external;

    function poolMint(address _address, uint256 m_amount) external;
}

File 16 of 23 : IFoundry.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.7.6;

interface IFoundry {
    function balanceOf(address _director) external view returns (uint256);

    function earned(address _director) external view returns (uint256);

    function canWithdraw(address _director) external view returns (bool);

    function canClaimReward(address _director) external view returns (bool);

    function epoch() external view returns (uint256);

    function nextEpochPoint() external view returns (uint256);

    function getDollarPrice() external view returns (uint256);

    function setOperator(address _operator) external;

    function setLockUp(uint256 _withdrawLockupEpochs, uint256 _rewardLockupEpochs) external;

    function stake(uint256 _amount) external;

    function withdraw(uint256 _amount) external;

    function exit() external;

    function claimReward() external;

    function allocateSeigniorage(uint256 _amount) external;
}

File 17 of 23 : IFoundryController.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.7.6;
pragma experimental ABIEncoderV2;

interface IFoundryController {
    function getFoundriesLength() external view returns (uint256);

    function getFoundry(uint256 _foundryId)
        external
        view
        returns (
            address _foundry,
            address _collateral,
            uint256 _allocation
        );

    function getFoundryByAddress(address _foundryAddress) external view returns (address _collateral, uint256 _allocation);
}

File 18 of 23 : IFoundryFund.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.7.6;
pragma experimental ABIEncoderV2;

interface IFoundryFund {
    function transferTo(
        address _token,
        address _receiver,
        uint256 _amount
    ) external;

    function fundBalance(address _token) external view returns (uint256);
}

File 19 of 23 : IOracle.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.7.6;
pragma experimental ABIEncoderV2;

interface IOracle {
    function consult() external view returns (uint256);
}

File 20 of 23 : IPool.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.7.6;
pragma experimental ABIEncoderV2;

interface IPool {
    function diamond() external view returns (address);

    function dToken() external view returns (address);

    function collateral() external view returns (address);

    function collateralBalance() external view returns (uint256);

    function diamondToCollateralPrice() external view returns (uint256);

    function dTokenToCollateralPrice() external view returns (uint256);

    function unclaimed_pool_collateral() external view returns (uint256);

    function unclaimed_pool_diamond() external view returns (uint256);

    function info()
        external
        view
        returns (
            uint256 pool_ceiling,
            uint256 collateral_balance,
            uint256 _unclaimed_pool_collateral,
            uint256 _unclaimed_pool_diamond,
            uint256 minting_fee,
            uint256 redemption_fee,
            bool mint_paused,
            bool redeem_paused,
            address _collateral,
            address d_token,
            string memory collateral_symbol,
            string memory d_token_symbol,
            uint256 target_collateral_ratio,
            uint256 effective_collateral_ratio
        );

    function mint(
        uint256 _collateral_amount,
        uint256 _diamond_amount,
        uint256 _dtoken_out_min
    ) external;
}

File 21 of 23 : ITreasury.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.7.6;
pragma experimental ABIEncoderV2;

interface ITreasury {
    function collateralReserve() external view returns (address);

    function isPool(address _address) external view returns (bool);

    function isMintingPool(address _poolAddress, address _dToken) external view returns (bool);

    function epoch() external view returns (uint256);

    function nextEpochTimestamp() external view returns (uint256);

    function epochInfo()
        external
        view
        returns (
            uint256 _epoch,
            uint256 lastEpochTimestamp,
            uint256 epochDuration
        );

    function utilizationRatio(address foundry) external view returns (uint256);

    function globalCollateralValue(address _collateral) external view returns (uint256);

    function requestTransfer(
        address token,
        address receiver,
        uint256 amount
    ) external;

    event PoolAdded(address pool);
    event PoolRemoved(address pool);
    event EpochDurationChanged(uint256 epochDuration);
    event FoundryAdded(address foundry, address pool);
    event FoundryRemoved(address foundry, address pool);
    event UtilizationRatioChanged(address pool, uint256 ratio);
    event CollateralReserveChanged(address collateralReserve);
}

File 22 of 23 : ITreasuryPolicy.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.7.6;
pragma experimental ABIEncoderV2;

interface ITreasuryPolicy {
    function getPolicy(address _asset)
        external
        view
        returns (
            address _pool,
            uint256 _utilizationRatio,
            uint256 _resevedThreshold,
            uint256 _profitSharingRatio
        );
}

File 23 of 23 : IVaultProxy.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.7.6;
pragma experimental ABIEncoderV2;

interface IVaultProxy {
    function vaultBalance(address _token) external view returns (uint256);

    function enter(address _token, uint256 _amount) external;

    function harvest(address _token) external returns (uint256 _capital, uint256 _profit);
}

Settings
{
  "evmVersion": "istanbul",
  "libraries": {},
  "metadata": {
    "bytecodeHash": "ipfs",
    "useLiteralContent": true
  },
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "remappings": [],
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "abi"
      ]
    }
  }
}

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"address","name":"_collateralReserve","type":"address"},{"internalType":"address","name":"_foundryFund","type":"address"},{"internalType":"address","name":"_treasuryPolicy","type":"address"},{"internalType":"address","name":"_vaultProxy","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"collateralReserve","type":"address"}],"name":"CollateralReserveChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"epochDuration","type":"uint256"}],"name":"EpochDurationChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"foundry","type":"address"},{"indexed":false,"internalType":"address","name":"pool","type":"address"}],"name":"FoundryAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"foundry","type":"address"},{"indexed":false,"internalType":"address","name":"pool","type":"address"}],"name":"FoundryRemoved","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOperator","type":"address"},{"indexed":true,"internalType":"address","name":"newOperator","type":"address"}],"name":"OperatorTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"pool","type":"address"}],"name":"PoolAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"pool","type":"address"}],"name":"PoolRemoved","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"pool","type":"address"},{"indexed":false,"internalType":"uint256","name":"ratio","type":"uint256"}],"name":"UtilizationRatioChanged","type":"event"},{"inputs":[],"name":"RATIO_PRECISION","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"pool_address","type":"address"}],"name":"addPool","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"allocateSeigniorage","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"}],"name":"calcCollateralReserveRatio","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"}],"name":"checkThreshold","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"collateralReserve","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"epoch","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"epochInfo","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"epochInitialized","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"epochLength","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"epochStartTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"foundryController","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"foundryFund","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"}],"name":"globalCollateralValue","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_startEpoch","type":"uint256"},{"internalType":"uint256","name":"_startTime","type":"uint256"},{"internalType":"uint256","name":"_epochLength","type":"uint256"}],"name":"initializeEpoch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"}],"name":"isAboveThreshold","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_poolAddress","type":"address"},{"internalType":"address","name":"_dToken","type":"address"}],"name":"isMintingPool","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isOperator","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"}],"name":"isPool","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lastEpochTimestamp","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"nextEpochTimestamp","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"operator","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"pools","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"pools_array","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"}],"name":"rebalance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"pool_address","type":"address"}],"name":"removePool","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_token","type":"address"},{"internalType":"address","name":"_receiver","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"requestTransfer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_collateralReserve","type":"address"}],"name":"setCollateralReserve","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"duration","type":"uint256"}],"name":"setEpochDuration","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_foundryController","type":"address"}],"name":"setFoundryController","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_foundryFund","type":"address"}],"name":"setFoundryFund","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_treasuryPolicy","type":"address"}],"name":"setTreasuryPolicy","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_vaultAdmin","type":"address"}],"name":"setVaultAdmin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_vaultProxy","type":"address"}],"name":"setVaultProxy","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOperator_","type":"address"}],"name":"transferOperator","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"treasuryPolicy","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_foundry","type":"address"}],"name":"utilizationRatio","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"vaultAdmin","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"vaultProxy","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"}]

60806040523480156200001157600080fd5b5060405162002e8438038062002e8483398101604081905262000034916200015a565b60006200004062000139565b600080546001600160a01b0319166001600160a01b0383169081178255604051929350917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908290a3506200009462000139565b600180546001600160a01b0319166001600160a01b0392831617908190556040519116906000907f74da04524d50c64947f5dd5381ef1a4dca5cba8ed1d816243f9e48aa0b5617ed908290a36001600255600580546001600160a01b039586166001600160a01b0319918216179091556009805494861694821694909417909355600880549285169284169290921790915560068054919093169116179055620001b6565b3390565b80516001600160a01b03811681146200015557600080fd5b919050565b6000806000806080858703121562000170578384fd5b6200017b856200013d565b93506200018b602086016200013d565b92506200019b604086016200013d565b9150620001ab606086016200013d565b905092959194509250565b612cbe80620001c66000396000f3fe608060405234801561001057600080fd5b506004361061025e5760003560e01c8063715018a611610146578063b6e8e6d7116100c3578063e0fa5c4311610087578063e0fa5c43146104a0578063e5284467146104b3578063e7f6f225146104c6578063f2fde38b146104ce578063f60ca641146104e1578063f64fc647146104e95761025e565b8063b6e8e6d714610457578063c0baeadb1461045f578063c3d32edc14610472578063d32867d014610485578063d914cd4b1461048d5761025e565b80639b27920c1161010a5780639b27920c14610403578063a08f334a14610416578063a4063dbc1461041e578063a4293ead14610431578063b55aecf0146104445761025e565b8063715018a6146103d0578063893a5372146103d85780638da5cb5b146103e05780638dd20d28146103e8578063900cf0cf146103fb5761025e565b80633e0ca9aa116101df578063570ca735116101a3578063570ca7351461038a57806357d775f8146103925780635b16ebb71461039a5780635b756179146103ad5780635f67f5bb146103b5578063679e8c04146103bd5761025e565b80633e0ca9aa1461033f5780634456eda2146103475780634591b3741461035c578063465b0c411461036f578063531448d5146103775761025e565b806329605e771161022657806329605e77146102eb57806330024dfe146102fe57806331fd50ab14610311578063397bfe55146103195780633b7d09461461032c5761025e565b80630988db4c146102635780631189ebea146102785780631f1b8a8c146102a15780632187d400146102b857806321c28191146102d8575b600080fd5b6102766102713660046126a4565b6104f1565b005b61028b610286366004612801565b61058b565b604051610298919061287f565b60405180910390f35b6102a96105b5565b60405161029893929190612b3f565b6102cb6102c63660046126a4565b6105d3565b6040516102989190612b36565b6102766102e63660046126a4565b6107ff565b6102766102f93660046126a4565b610953565b61027661030c366004612801565b6109d3565b61028b610a21565b6102766103273660046126a4565b610a30565b61027661033a3660046126a4565b610ac1565b61028b610c7b565b61034f610c8a565b60405161029891906128d0565b61034f61036a3660046126a4565b610cb0565b61028b610d51565b6102766103853660046126a4565b610d60565b61028b610df1565b6102cb610e00565b61034f6103a83660046126a4565b610e06565b610276610e24565b61028b610f94565b6102cb6103cb3660046126a4565b610fa3565b6102766110e0565b61028b61119e565b61028b6111ad565b6102cb6103f63660046126a4565b6111bc565b6102cb6112f0565b6102766104113660046126a4565b6112f6565b61034f611336565b61034f61042c3660046126a4565b61133f565b61027661043f366004612714565b611354565b6102766104523660046126a4565b6113e4565b6102cb611475565b61027661046d3660046126a4565b611493565b61034f6104803660046126dc565b611553565b6102cb611616565b61027661049b3660046126a4565b61161d565b6102766104ae366004612854565b611723565b6102766104c13660046126a4565b6117b9565b61028b61184a565b6102766104dc3660046126a4565b611859565b6102cb61196d565b6102cb611973565b6001546001600160a01b0316331461053a5760405162461bcd60e51b8152600401808060200182810382526024815260200180612c056024913960400191505060405180910390fd5b6001600160a01b0381166105695760405162461bcd60e51b815260040161056090612a17565b60405180910390fd5b600780546001600160a01b0319166001600160a01b0392909216919091179055565b6003818154811061059b57600080fd5b6000918252602090912001546001600160a01b0316905081565b6000806000600b546105c5611475565b600c54925092509250909192565b600854604051631bc8ee3560e11b815260009182916001600160a01b0390911690633791dc6a9061060890869060040161287f565b60806040518083038186803b15801561062057600080fd5b505afa158015610634573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061065891906127c3565b50506005546040516370a0823160e01b81529293506000926001600160a01b0380881693506370a08231926106929291169060040161287f565b60206040518083038186803b1580156106aa57600080fd5b505afa1580156106be573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106e29190612819565b90506000826001600160a01b031663ff626c5f6040518163ffffffff1660e01b815260040160206040518083038186803b15801561071f57600080fd5b505afa158015610733573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107579190612819565b600654604051637687f20b60e11b81529192506000916001600160a01b039091169063ed0fe4169061078d90899060040161287f565b60206040518083038186803b1580156107a557600080fd5b505afa1580156107b9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107dd9190612819565b90506107f3826107ed8386611979565b906119da565b9450505050505b919050565b6007546001600160a01b031633146108295760405162461bcd60e51b815260040161056090612910565b600280541415610880576040805162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015290519081900360640190fd5b600280556006546001600160a01b03166108ac5760405162461bcd60e51b815260040161056090612b08565b60065460405163072e008f60e11b81526000916001600160a01b031690630e5c011e906108dd90859060040161287f565b6040805180830381600087803b1580156108f657600080fd5b505af115801561090a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061092e9190612831565b9150508015610941576109418282611a37565b61094a82611be3565b50506001600255565b61095b611ef0565b6001600160a01b031661096c6111ad565b6001600160a01b0316146109c7576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6109d081611ef4565b50565b6001546001600160a01b03163314610a1c5760405162461bcd60e51b8152600401808060200182810382526024815260200180612c056024913960400191505060405180910390fd5b600c55565b6009546001600160a01b031681565b6001546001600160a01b03163314610a795760405162461bcd60e51b8152600401808060200182810382526024815260200180612c056024913960400191505060405180910390fd5b6001600160a01b038116610a9f5760405162461bcd60e51b815260040161056090612a17565b600680546001600160a01b0319166001600160a01b0392909216919091179055565b6001546001600160a01b03163314610b0a5760405162461bcd60e51b8152600401808060200182810382526024815260200180612c056024913960400191505060405180910390fd5b6001600160a01b03811660009081526004602052604090205460ff16610b425760405162461bcd60e51b815260040161056090612ae9565b6001600160a01b0381166000908152600460205260408120805460ff191690555b600354811015610c1257816001600160a01b031660038281548110610b8457fe5b6000918252602090912001546001600160a01b03161415610c0a57600380546000198101908110610bb157fe5b600091825260209091200154600380546001600160a01b039092169183908110610bd757fe5b9060005260206000200160006101000a8154816001600160a01b0302191690836001600160a01b03160217905550610c12565b600101610b63565b506003805480610c1e57fe5b600082815260209020810160001990810180546001600160a01b03191690550190556040517f4106dfdaa577573db51c0ca93f766dbedfa0758faa2e7f5bcdb7c142be803c3f90610c7090839061287f565b60405180910390a150565b6008546001600160a01b031681565b6001546000906001600160a01b0316610ca1611ef0565b6001600160a01b031614905090565b600854604051631bc8ee3560e11b815260009182916001600160a01b0390911690633791dc6a90610ce590869060040161287f565b60806040518083038186803b158015610cfd57600080fd5b505afa158015610d11573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d3591906127c3565b50925050506000610d4584610fa3565b91909110159392505050565b6005546001600160a01b031681565b6001546001600160a01b03163314610da95760405162461bcd60e51b8152600401808060200182810382526024815260200180612c056024913960400191505060405180910390fd5b6001600160a01b038116610dcf5760405162461bcd60e51b815260040161056090612a17565b600980546001600160a01b0319166001600160a01b0392909216919091179055565b6001546001600160a01b031690565b600c5481565b6001600160a01b031660009081526004602052604090205460ff1690565b600280541415610e7b576040805162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015290519081900360640190fd5b600280556000610e89611475565b905080421015610eab5760405162461bcd60e51b8152600401610560906129b4565b600a546001600160a01b0316610ed35760405162461bcd60e51b815260040161056090612abc565b600a5460408051630b7832c760e01b815290516001600160a01b03909216916000918391630b7832c791600480820192602092909190829003018186803b158015610f1d57600080fd5b505afa158015610f31573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f559190612819565b905060005b81811015610f7357610f6b81611f91565b600101610f5a565b505050600d819055600b54610f89906001611979565b600b55506001600255565b600a546001600160a01b031681565b600854604051631bc8ee3560e11b815260009182916001600160a01b0390911690633791dc6a90610fd890869060040161287f565b60806040518083038186803b158015610ff057600080fd5b505afa158015611004573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061102891906127c3565b50505090506000816001600160a01b031663c98c05b76040518163ffffffff1660e01b815260040160206040518083038186803b15801561106857600080fd5b505afa15801561107c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110a09190612819565b905060006110ad856105d3565b9050806110c057600093505050506107fa565b6110d7816110d184620f42406121b1565b9061220a565b95945050505050565b6110e8611ef0565b6001600160a01b03166110f96111ad565b6001600160a01b031614611154576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b600080546040516001600160a01b03909116907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600080546001600160a01b0319169055565b6006546001600160a01b031681565b6000546001600160a01b031690565b600a5460405163725335b560e01b8152600091829182916001600160a01b03169063725335b5906111f190879060040161287f565b604080518083038186803b15801561120857600080fd5b505afa15801561121c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112409190612796565b600954604051630ad5a86560e01b81529294509092506000916001600160a01b0390911690630ad5a8659061127990869060040161287f565b60206040518083038186803b15801561129157600080fd5b505afa1580156112a5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112c99190612819565b90506001600160a01b03831615806112df575080155b156110c057600093505050506107fa565b600b5481565b6007546001600160a01b031633146113205760405162461bcd60e51b815260040161056090612910565b61132981610cb0565b6109d0576109d0816107ff565b600e5460ff1681565b60046020526000908152604090205460ff1681565b61135d33610e06565b6113795760405162461bcd60e51b8152600401610560906128db565b6005546040516352f950a960e11b81526001600160a01b039091169063a5f2a152906113ad90869086908690600401612893565b600060405180830381600087803b1580156113c757600080fd5b505af11580156113db573d6000803e3d6000fd5b50505050505050565b6001546001600160a01b0316331461142d5760405162461bcd60e51b8152600401808060200182810382526024815260200180612c056024913960400191505060405180910390fd5b6001600160a01b0381166114535760405162461bcd60e51b815260040161056090612a17565b600880546001600160a01b0319166001600160a01b0392909216919091179055565b600061148e600c54600d5461197990919063ffffffff16565b905090565b6001546001600160a01b031633146114dc5760405162461bcd60e51b8152600401808060200182810382526024815260200180612c056024913960400191505060405180910390fd5b6001600160a01b0381166115025760405162461bcd60e51b815260040161056090612a17565b600580546001600160a01b0319166001600160a01b0383811691909117918290556040517f772f91e876512fdd1953eea96acac7c8bafca35c31196d54d5277eb5b3052a2092610c7092169061287f565b60008061155f84610e06565b905080611570576000915050611610565b6000846001600160a01b031663d9d7858a6040518163ffffffff1660e01b815260040160206040518083038186803b1580156115ab57600080fd5b505afa1580156115bf573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115e391906126c0565b9050836001600160a01b0316816001600160a01b03161461160957600092505050611610565b6001925050505b92915050565b620f424081565b6001546001600160a01b031633146116665760405162461bcd60e51b8152600401808060200182810382526024815260200180612c056024913960400191505060405180910390fd5b61166f81610e06565b1561168c5760405162461bcd60e51b815260040161056090612a6b565b6001600160a01b038116600081815260046020526040808220805460ff191660019081179091556003805491820181559092527fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b90910180546001600160a01b031916909217909155517f73cca62ab1b520c9715bf4e6c71e3e518c754e7148f65102f43289a7df0efea690610c7090839061287f565b6001546001600160a01b0316331461176c5760405162461bcd60e51b8152600401808060200182810382526024815260200180612c056024913960400191505060405180910390fd5b42821161178b5760405162461bcd60e51b8152600401610560906129eb565b600b839055600f829055600c8190556117a482826119da565b600d555050600e805460ff1916600117905550565b6001546001600160a01b031633146118025760405162461bcd60e51b8152600401808060200182810382526024815260200180612c056024913960400191505060405180910390fd5b6001600160a01b0381166118285760405162461bcd60e51b815260040161056090612a17565b600a80546001600160a01b0319166001600160a01b0392909216919091179055565b6007546001600160a01b031681565b611861611ef0565b6001600160a01b03166118726111ad565b6001600160a01b0316146118cd576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6001600160a01b0381166119125760405162461bcd60e51b8152600401808060200182810382526026815260200180612b6b6026913960400191505060405180910390fd5b600080546040516001600160a01b03808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a3600080546001600160a01b0319166001600160a01b0392909216919091179055565b600f5481565b600d5481565b6000828201838110156119d3576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b9392505050565b600082821115611a31576040805162461bcd60e51b815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b50900390565b6001600160a01b038216611a5d5760405162461bcd60e51b815260040161056090612935565b6008546001600160a01b0316611a855760405162461bcd60e51b815260040161056090612a3f565b60008111611aa55760405162461bcd60e51b815260040161056090612a90565b600854604051631bc8ee3560e11b81526000916001600160a01b031690633791dc6a90611ad690869060040161287f565b60806040518083038186803b158015611aee57600080fd5b505afa158015611b02573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b2691906127c3565b93505050506000611b47620f42406110d184866121b190919063ffffffff16565b90506000611b5584836119da565b6009549091506001600160a01b0316611b805760405162461bcd60e51b81526004016105609061295c565b6005546001600160a01b0316611ba85760405162461bcd60e51b815260040161056090612985565b600954611bc2906001600160a01b03878116911684612271565b600554611bdc906001600160a01b03878116911683612271565b5050505050565b6005546001600160a01b0316611c0b5760405162461bcd60e51b815260040161056090612985565b6008546001600160a01b0316611c335760405162461bcd60e51b815260040161056090612a3f565b6005546040516370a0823160e01b81528291611ccd916001600160a01b03918216918416906370a0823190611c6c90309060040161287f565b60206040518083038186803b158015611c8457600080fd5b505afa158015611c98573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611cbc9190612819565b6001600160a01b0384169190612271565b600854604051631bc8ee3560e11b815260009182916001600160a01b0390911690633791dc6a90611d0290879060040161287f565b60806040518083038186803b158015611d1a57600080fd5b505afa158015611d2e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d5291906127c3565b5050915091506000826001600160a01b031663c98c05b76040518163ffffffff1660e01b815260040160206040518083038186803b158015611d9357600080fd5b505afa158015611da7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611dcb9190612819565b90506000611de0620f42406110d185856121b1565b90508015611ee8576005546040516352f950a960e11b81526001600160a01b039091169063a5f2a15290611e1c90899030908690600401612893565b600060405180830381600087803b158015611e3657600080fd5b505af1158015611e4a573d6000803e3d6000fd5b5050600654611e6992506001600160a01b0388811692501660006122c8565b600654611e83906001600160a01b038781169116836122c8565b600654604051637e348b7d60e01b81526001600160a01b0390911690637e348b7d90611eb590899085906004016128b7565b600060405180830381600087803b158015611ecf57600080fd5b505af1158015611ee3573d6000803e3d6000fd5b505050505b505050505050565b3390565b6001600160a01b038116611f395760405162461bcd60e51b815260040180806020018281038252602d815260200180612bb7602d913960400191505060405180910390fd5b6040516001600160a01b038216906000907f74da04524d50c64947f5dd5381ef1a4dca5cba8ed1d816243f9e48aa0b5617ed908290a3600180546001600160a01b0319166001600160a01b0392909216919091179055565b600a5460405163306d744d60e01b81526001600160a01b039091169060009081908190849063306d744d90611fca908890600401612b36565b60606040518083038186803b158015611fe257600080fd5b505afa158015611ff6573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061201a9190612754565b919450925090506001600160a01b038316158061203e57506001600160a01b038216155b1561204c57505050506109d0565b600954604051630ad5a86560e01b81526001600160a01b03909116906000908290630ad5a8659061208190879060040161287f565b60206040518083038186803b15801561209957600080fd5b505afa1580156120ad573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120d19190612819565b90506000831180156120e35750828110155b156113db576040516397ffe1d760e01b81526001600160a01b038616906397ffe1d790612114908690600401612b36565b600060405180830381600087803b15801561212e57600080fd5b505af1158015612142573d6000803e3d6000fd5b50506040516352f950a960e11b81526001600160a01b038516925063a5f2a152915061217690879089908890600401612893565b600060405180830381600087803b15801561219057600080fd5b505af11580156121a4573d6000803e3d6000fd5b5050505050505050505050565b6000826121c057506000611610565b828202828482816121cd57fe5b04146119d35760405162461bcd60e51b8152600401808060200182810382526021815260200180612be46021913960400191505060405180910390fd5b6000808211612260576040805162461bcd60e51b815260206004820152601a60248201527f536166654d6174683a206469766973696f6e206279207a65726f000000000000604482015290519081900360640190fd5b81838161226957fe5b049392505050565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b1790526122c39084906123d7565b505050565b80158061234e575060408051636eb1769f60e11b81523060048201526001600160a01b03848116602483015291519185169163dd62ed3e91604480820192602092909190829003018186803b15801561232057600080fd5b505afa158015612334573d6000803e3d6000fd5b505050506040513d602081101561234a57600080fd5b5051155b6123895760405162461bcd60e51b8152600401808060200182810382526036815260200180612c536036913960400191505060405180910390fd5b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663095ea7b360e01b1790526122c39084905b600061242c826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166124889092919063ffffffff16565b8051909150156122c35780806020019051602081101561244b57600080fd5b50516122c35760405162461bcd60e51b815260040180806020018281038252602a815260200180612c29602a913960400191505060405180910390fd5b6060612497848460008561249f565b949350505050565b6060824710156124e05760405162461bcd60e51b8152600401808060200182810382526026815260200180612b916026913960400191505060405180910390fd5b6124e9856125fa565b61253a576040805162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015290519081900360640190fd5b600080866001600160a01b031685876040518082805190602001908083835b602083106125785780518252601f199092019160209182019101612559565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d80600081146125da576040519150601f19603f3d011682016040523d82523d6000602084013e6125df565b606091505b50915091506125ef828286612600565b979650505050505050565b3b151590565b6060831561260f5750816119d3565b82511561261f5782518084602001fd5b8160405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015612669578181015183820152602001612651565b50505050905090810190601f1680156126965780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b6000602082840312156126b5578081fd5b81356119d381612b55565b6000602082840312156126d1578081fd5b81516119d381612b55565b600080604083850312156126ee578081fd5b82356126f981612b55565b9150602083013561270981612b55565b809150509250929050565b600080600060608486031215612728578081fd5b833561273381612b55565b9250602084013561274381612b55565b929592945050506040919091013590565b600080600060608486031215612768578283fd5b835161277381612b55565b602085015190935061278481612b55565b80925050604084015190509250925092565b600080604083850312156127a8578182fd5b82516127b381612b55565b6020939093015192949293505050565b600080600080608085870312156127d8578081fd5b84516127e381612b55565b60208601516040870151606090970151919890975090945092505050565b600060208284031215612812578081fd5b5035919050565b60006020828403121561282a578081fd5b5051919050565b60008060408385031215612843578182fd5b505080516020909101519092909150565b600080600060608486031215612868578283fd5b505081359360208301359350604090920135919050565b6001600160a01b0391909116815260200190565b6001600160a01b039384168152919092166020820152604081019190915260600190565b6001600160a01b03929092168252602082015260400190565b901515815260200190565b6020808252818101527f4f6e6c7920706f6f6c732063616e2075736520746869732066756e6374696f6e604082015260600190565b6020808252600b908201526a10bb30bab63a20b236b4b760a91b604082015260600190565b6020808252600d908201526c125b9d985b1a5908185cdcd95d609a1b604082015260600190565b6020808252600f908201526e139bc8199bdd5b991c9e48199d5b99608a1b604082015260600190565b6020808252601590820152744e6f20636f6c6c61746572616c207265736572766560581b604082015260600190565b60208082526018908201527f54726561737572793a206e6f74206f70656e6564207965740000000000000000604082015260600190565b6020808252601290820152711cdd185c9d151a5b59525b951a1954185cdd60721b604082015260600190565b6020808252600e908201526d696e76616c69644164647265737360901b604082015260600190565b6020808252601290820152714e6f20747265617375727920706f6c69637960701b604082015260600190565b6020808252600b908201526a1c1bdbdb115e1a5cdd195960aa1b604082015260600190565b60208082526012908201527116995c9bc8185b5bdd5b9d081c1c9bd99a5d60721b604082015260600190565b6020808252601390820152723737a337bab732393ca1b7b73a3937b63632b960691b604082015260600190565b602080825260059082015264085c1bdbdb60da1b604082015260600190565b60208082526014908201527315985d5b1d08191bd95cc81b9bdd08195e1a5cdd60621b604082015260600190565b90815260200190565b9283526020830191909152604082015260600190565b6001600160a01b03811681146109d057600080fdfe4f776e61626c653a206e6577206f776e657220697320746865207a65726f2061646472657373416464726573733a20696e73756666696369656e742062616c616e636520666f722063616c6c6f70657261746f723a207a65726f206164647265737320676976656e20666f72206e6577206f70657261746f72536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f776f70657261746f723a2063616c6c6572206973206e6f7420746865206f70657261746f725361666545524332303a204552433230206f7065726174696f6e20646964206e6f7420737563636565645361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f20746f206e6f6e2d7a65726f20616c6c6f77616e6365a2646970667358221220d76d56891ccf5ba8b825d56d5675ed8894daa44bfdedb30ccf3a56811cb481fd64736f6c6343000706003300000000000000000000000069d61bbad2d94b7f37bac32151096e5f65a372d40000000000000000000000003b8aa4c66e9c0ae40ef84fa4a949d170ca047b2b00000000000000000000000029a8828e132dfc5d35e654fa320029eefd8d300f000000000000000000000000c9bd1338eeeddd82268d8387c11105711b252efa

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

00000000000000000000000069d61bbad2d94b7f37bac32151096e5f65a372d40000000000000000000000003b8aa4c66e9c0ae40ef84fa4a949d170ca047b2b00000000000000000000000029a8828e132dfc5d35e654fa320029eefd8d300f000000000000000000000000c9bd1338eeeddd82268d8387c11105711b252efa

-----Decoded View---------------
Arg [0] : _collateralReserve (address): 0x69d61bbad2d94b7f37bac32151096e5f65a372d4
Arg [1] : _foundryFund (address): 0x3b8aa4c66e9c0ae40ef84fa4a949d170ca047b2b
Arg [2] : _treasuryPolicy (address): 0x29a8828e132dfc5d35e654fa320029eefd8d300f
Arg [3] : _vaultProxy (address): 0xc9bd1338eeeddd82268d8387c11105711b252efa

-----Encoded View---------------
4 Constructor Arguments found :
Arg [0] : 00000000000000000000000069d61bbad2d94b7f37bac32151096e5f65a372d4
Arg [1] : 0000000000000000000000003b8aa4c66e9c0ae40ef84fa4a949d170ca047b2b
Arg [2] : 00000000000000000000000029a8828e132dfc5d35e654fa320029eefd8d300f
Arg [3] : 000000000000000000000000c9bd1338eeeddd82268d8387c11105711b252efa


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