ETH Price: $2,254.25 (+6.44%)

Contract

0x15BF96b00b0cCba940c56c54289167544180f7F9
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

More Info

Private Name Tags

TokenTracker

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To

There are no matching entries

Please try again later

View more zero value Internal Transactions in Advanced View mode

Advanced mode:
Loading...
Loading
Loading...
Loading
Cross-Chain Transactions

Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
TToken_V2

Compiler Version
v0.8.3+commit.8d00100c

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion, MIT license
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

// Contracts
import { TToken_V1 } from "./TToken_V1.sol";
import { CONTROLLER } from "./data.sol";
import { ITTokenStrategy } from "./strategies/ITTokenStrategy.sol";

// Libraries
import {
    SafeERC20
} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

/**
 * @notice This contract represents a lending pool for an asset within Teller protocol.
 * @author [email protected]
 */
contract TToken_V2 is TToken_V1 {
    /**
     * @notice Called by the Teller Diamond contract when a loan has been taken out and requires funds.
     * @param recipient The account to send the funds to.
     * @param amount Funds requested to fulfil the loan.
     */
    function fundLoan(address recipient, uint256 amount)
        external
        override
        authorized(CONTROLLER, _msgSender())
    {
        // Call the strategy to ensure there is enough available funds to fund the loan
        _delegateStrategy(
            abi.encodeWithSelector(ITTokenStrategy.withdraw.selector, amount)
        );

        // Increase total borrowed amount
        s().totalBorrowed += amount;

        // Transfer tokens to recipient
        SafeERC20.safeTransfer(s().underlying, recipient, amount);
    }
}

File 2 of 27 : Initializable.sol
// SPDX-License-Identifier: MIT

// solhint-disable-next-line compiler-version
pragma solidity ^0.8.0;

/**
 * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
 * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an
 * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
 * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
 *
 * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
 * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
 *
 * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
 * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
 */
abstract contract Initializable {

    /**
     * @dev Indicates that the contract has been initialized.
     */
    bool private _initialized;

    /**
     * @dev Indicates that the contract is in the process of being initialized.
     */
    bool private _initializing;

    /**
     * @dev Modifier to protect an initializer function from being invoked twice.
     */
    modifier initializer() {
        require(_initializing || !_initialized, "Initializable: contract is already initialized");

        bool isTopLevelCall = !_initializing;
        if (isTopLevelCall) {
            _initializing = true;
            _initialized = true;
        }

        _;

        if (isTopLevelCall) {
            _initializing = false;
        }
    }
}

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "./IERC20Upgradeable.sol";
import "./extensions/IERC20MetadataUpgradeable.sol";
import "../../utils/ContextUpgradeable.sol";
import "../../proxy/utils/Initializable.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 ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable, IERC20MetadataUpgradeable {
    mapping (address => uint256) private _balances;

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

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;

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

    function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer {
        _name = name_;
        _symbol = symbol_;
    }

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

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

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

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

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

    /**
     * @dev See {IERC20-transfer}.
     *
     * Requirements:
     *
     * - `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);

        uint256 currentAllowance = _allowances[sender][_msgSender()];
        require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance");
        _approve(sender, _msgSender(), currentAllowance - amount);

        return true;
    }

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

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

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

        uint256 senderBalance = _balances[sender];
        require(senderBalance >= amount, "ERC20: transfer amount exceeds balance");
        _balances[sender] = senderBalance - amount;
        _balances[recipient] += 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 += amount;
        _balances[account] += 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);

        uint256 accountBalance = _balances[account];
        require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
        _balances[account] = accountBalance - amount;
        _totalSupply -= 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 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 { }
    uint256[45] private __gap;
}

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20Upgradeable {
    /**
     * @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);
}

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "../IERC20Upgradeable.sol";

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

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

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

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;
import "../proxy/utils/Initializable.sol";

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

    function __Context_init_unchained() internal initializer {
    }
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

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

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "./IERC20.sol";
import "./extensions/IERC20Metadata.sol";
import "../../utils/Context.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, IERC20Metadata {
    mapping (address => uint256) private _balances;

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

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;

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

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

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

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

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

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

    /**
     * @dev See {IERC20-transfer}.
     *
     * Requirements:
     *
     * - `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);

        uint256 currentAllowance = _allowances[sender][_msgSender()];
        require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance");
        _approve(sender, _msgSender(), currentAllowance - amount);

        return true;
    }

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

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

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

        uint256 senderBalance = _balances[sender];
        require(senderBalance >= amount, "ERC20: transfer amount exceeds balance");
        _balances[sender] = senderBalance - amount;
        _balances[recipient] += 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 += amount;
        _balances[account] += 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);

        uint256 accountBalance = _balances[account];
        require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
        _balances[account] = accountBalance - amount;
        _totalSupply -= 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 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 { }
}

// SPDX-License-Identifier: MIT

pragma solidity ^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);
}

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "../IERC20.sol";

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

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

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

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "../IERC20.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 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) + value;
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
    }

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

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

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

// SPDX-License-Identifier: MIT

pragma solidity ^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);
            }
        }
    }
}

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

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

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

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "./IERC165.sol";

/**
 * @dev Library used to query support of an interface declared via {IERC165}.
 *
 * Note that these functions return the actual result of the query: they do not
 * `revert` if an interface is not supported. It is up to the caller to decide
 * what to do in these cases.
 */
library ERC165Checker {
    // As per the EIP-165 spec, no interface should ever match 0xffffffff
    bytes4 private constant _INTERFACE_ID_INVALID = 0xffffffff;

    /**
     * @dev Returns true if `account` supports the {IERC165} interface,
     */
    function supportsERC165(address account) internal view returns (bool) {
        // Any contract that implements ERC165 must explicitly indicate support of
        // InterfaceId_ERC165 and explicitly indicate non-support of InterfaceId_Invalid
        return _supportsERC165Interface(account, type(IERC165).interfaceId) &&
            !_supportsERC165Interface(account, _INTERFACE_ID_INVALID);
    }

    /**
     * @dev Returns true if `account` supports the interface defined by
     * `interfaceId`. Support for {IERC165} itself is queried automatically.
     *
     * See {IERC165-supportsInterface}.
     */
    function supportsInterface(address account, bytes4 interfaceId) internal view returns (bool) {
        // query support of both ERC165 as per the spec and support of _interfaceId
        return supportsERC165(account) &&
            _supportsERC165Interface(account, interfaceId);
    }

    /**
     * @dev Returns a boolean array where each value corresponds to the
     * interfaces passed in and whether they're supported or not. This allows
     * you to batch check interfaces for a contract where your expectation
     * is that some interfaces may not be supported.
     *
     * See {IERC165-supportsInterface}.
     *
     * _Available since v3.4._
     */
    function getSupportedInterfaces(address account, bytes4[] memory interfaceIds) internal view returns (bool[] memory) {
        // an array of booleans corresponding to interfaceIds and whether they're supported or not
        bool[] memory interfaceIdsSupported = new bool[](interfaceIds.length);

        // query support of ERC165 itself
        if (supportsERC165(account)) {
            // query support of each interface in interfaceIds
            for (uint256 i = 0; i < interfaceIds.length; i++) {
                interfaceIdsSupported[i] = _supportsERC165Interface(account, interfaceIds[i]);
            }
        }

        return interfaceIdsSupported;
    }

    /**
     * @dev Returns true if `account` supports all the interfaces defined in
     * `interfaceIds`. Support for {IERC165} itself is queried automatically.
     *
     * Batch-querying can lead to gas savings by skipping repeated checks for
     * {IERC165} support.
     *
     * See {IERC165-supportsInterface}.
     */
    function supportsAllInterfaces(address account, bytes4[] memory interfaceIds) internal view returns (bool) {
        // query support of ERC165 itself
        if (!supportsERC165(account)) {
            return false;
        }

        // query support of each interface in _interfaceIds
        for (uint256 i = 0; i < interfaceIds.length; i++) {
            if (!_supportsERC165Interface(account, interfaceIds[i])) {
                return false;
            }
        }

        // all interfaces supported
        return true;
    }

    /**
     * @notice Query if a contract implements an interface, does not check ERC165 support
     * @param account The address of the contract to query for support of an interface
     * @param interfaceId The interface identifier, as specified in ERC-165
     * @return true if the contract at account indicates support of the interface with
     * identifier interfaceId, false otherwise
     * @dev Assumes that account contains a contract that supports ERC165, otherwise
     * the behavior of this method is undefined. This precondition can be checked
     * with {supportsERC165}.
     * Interface identification is specified in ERC-165.
     */
    function _supportsERC165Interface(address account, bytes4 interfaceId) private view returns (bool) {
        bytes memory encodedParams = abi.encodeWithSelector(IERC165(account).supportsInterface.selector, interfaceId);
        (bool success, bytes memory result) = account.staticcall{ gas: 30000 }(encodedParams);
        if (result.length < 32) return false;
        return success && abi.decode(result, (bool));
    }
}

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[EIP].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165 {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow
 * checks.
 *
 * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
 * easily result in undesired exploitation or bugs, since developers usually
 * assume that overflows raise errors. `SafeCast` restores this intuition by
 * reverting the transaction when such an operation overflows.
 *
 * Using this library instead of the unchecked operations eliminates an entire
 * class of bugs, so it's recommended to use it always.
 *
 * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing
 * all math on `uint256` and `int256` and then downcasting.
 */
library SafeCast {
    /**
     * @dev Returns the downcasted uint128 from uint256, reverting on
     * overflow (when the input is greater than largest uint128).
     *
     * Counterpart to Solidity's `uint128` operator.
     *
     * Requirements:
     *
     * - input must fit into 128 bits
     */
    function toUint128(uint256 value) internal pure returns (uint128) {
        require(value < 2**128, "SafeCast: value doesn\'t fit in 128 bits");
        return uint128(value);
    }

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

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

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

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

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

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

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

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

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

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

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

File 16 of 27 : ReentryMods.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import { AccessControlStorageLib, AccessControlStorage } from "../storage.sol";

abstract contract ReentryMods {
    modifier nonReentry(bytes32 id) {
        AccessControlStorage storage s = AccessControlStorageLib.store();
        require(!s.entered[id], "AccessControl: reentered");
        s.entered[id] = true;
        _;
        s.entered[id] = false;
    }
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import { RolesMods } from "./RolesMods.sol";
import { RolesLib } from "./RolesLib.sol";
import { ADMIN } from "../../../shared/roles.sol";

contract RolesFacet is RolesMods {
    /**
     * @notice Checks if an account has a specific role.
     * @param role Encoding of the role to check.
     * @param account Address to check the {role} for.
     */
    function hasRole(bytes32 role, address account)
        external
        view
        returns (bool)
    {
        return RolesLib.hasRole(role, account);
    }

    /**
     * @notice Grants an account a new role.
     * @param role Encoding of the role to give.
     * @param account Address to give the {role} to.
     *
     * Requirements:
     *  - Sender must be role admin.
     */
    function grantRole(bytes32 role, address account)
        external
        authorized(ADMIN, msg.sender)
    {
        RolesLib.grantRole(role, account);
    }

    /**
     * @notice Removes a role from an account.
     * @param role Encoding of the role to remove.
     * @param account Address to remove the {role} from.
     *
     * Requirements:
     *  - Sender must be role admin.
     */
    function revokeRole(bytes32 role, address account)
        external
        authorized(ADMIN, msg.sender)
    {
        RolesLib.revokeRole(role, account);
    }

    /**
     * @notice Removes a role from the sender.
     * @param role Encoding of the role to remove.
     */
    function renounceRole(bytes32 role) external {
        RolesLib.revokeRole(role, msg.sender);
    }
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import { AccessControlStorageLib, AccessControlStorage } from "../storage.sol";

library RolesLib {
    function s() private pure returns (AccessControlStorage storage) {
        return AccessControlStorageLib.store();
    }

    /**
     * @dev Emitted when `account` is granted `role`.
     */
    event RoleGranted(
        bytes32 indexed role,
        address indexed account,
        address indexed sender
    );

    /**
     * @dev Emitted when `account` is revoked `role`.
     */
    event RoleRevoked(
        bytes32 indexed role,
        address indexed account,
        address indexed sender
    );

    /**
     * @notice Checks if an account has a specific role.
     */
    function hasRole(bytes32 role, address account)
        internal
        view
        returns (bool)
    {
        return s().roles[role][account];
    }

    /**
     * @dev Gives an account a new role.
     * @dev Should only use when circumventing admin checking.
     * @dev If account already has the role, no event is emitted.
     * @param role Encoding of the role to give.
     * @param account Address to give the {role} to.
     */
    function grantRole(bytes32 role, address account) internal {
        if (hasRole(role, account)) return;
        s().roles[role][account] = true;
        emit RoleGranted(role, account, msg.sender);
    }

    /**
     * @dev Removes a role from an account.
     * @dev Should only use when circumventing admin checking.
     * @dev If account does not already have the role, no event is emitted.
     * @param role Encoding of the role to remove.
     * @param account Address to remove the {role} from.
     */
    function revokeRole(bytes32 role, address account) internal {
        if (!hasRole(role, account)) return;
        s().roles[role][account] = false;
        emit RoleRevoked(role, account, msg.sender);
    }
}

File 19 of 27 : RolesMods.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

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

abstract contract RolesMods {
    /**
     * @notice Requires that the {account} has {role}
     * @param role Encoding of the role to check.
     * @param account Address to check the {role} for.
     */
    modifier authorized(bytes32 role, address account) {
        require(
            RolesLib.hasRole(role, account),
            "AccessControl: not authorized"
        );
        _;
    }
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

struct AccessControlStorage {
    mapping(bytes32 => mapping(address => bool)) roles;
    mapping(address => address) owners;
    mapping(bytes32 => bool) entered;
}

bytes32 constant ACCESS_CONTROL_POS = keccak256(
    "teller.access_control.storage"
);

library AccessControlStorageLib {
    function store() internal pure returns (AccessControlStorage storage s) {
        bytes32 pos = ACCESS_CONTROL_POS;
        assembly {
            s.slot := pos
        }
    }
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

// Contracts
import {
    ERC20Upgradeable
} from "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {
    RolesFacet
} from "../../contexts2/access-control/roles/RolesFacet.sol";

/**
 * @notice This contract acts as an interface for the Teller token (TToken).
 *
 * @author [email protected]
 */
abstract contract ITToken is ERC20Upgradeable, RolesFacet {
    /**
     * @notice This event is emitted when a user deposits tokens into the pool.
     */
    event Mint(
        address indexed sender,
        uint256 tTokenAmount,
        uint256 underlyingAmount
    );

    /**
     * @notice This event is emitted when a user withdraws tokens from the pool.
     */
    event Redeem(
        address indexed sender,
        uint256 tTokenAmount,
        uint256 underlyingAmount
    );

    /**
     * @notice This event is emitted when a loan has been taken out through the Teller Diamond.
     * @param recipient The address receiving the borrowed funds.
     * @param totalBorrowed The total amount being loaned out by the tToken.
     */
    event LoanFunded(address indexed recipient, uint256 totalBorrowed);

    /**
     * @notice This event is emitted when a loan has been repaid through the Teller Diamond.
     * @param sender The address making the payment to the tToken.
     * @param principlePayment The amount paid back towards the principle loaned out by the tToken.
     * @param interestPayment The amount paid back towards the interest owed to the tToken.
     */
    event LoanPaymentMade(
        address indexed sender,
        uint256 principlePayment,
        uint256 interestPayment
    );

    /**
     * @notice This event is emitted when a new investment management strategy has been set for a Teller token.
     * @param strategyAddress The address of the new strategy set for managing the underlying assets held by the tToken.
     * @param sender The address of the sender setting the token strategy.
     */
    event StrategySet(address strategyAddress, address indexed sender);

    /**
     * @notice This event is emitted when the platform restriction is switched
     * @param restriction Boolean representing the state of the restriction
     * @param investmentManager address of the investment manager flipping the switch
     */
    event PlatformRestricted(
        bool restriction,
        address indexed investmentManager
    );

    /**
     * @notice The token that is the underlying asset for this Teller token.
     * @return ERC20 token
     */
    function underlying() external view virtual returns (ERC20);

    /**
     * @notice The balance of an {account} denoted in underlying value.
     * @param account Address to calculate the underlying balance.
     * @return balance_ the balance of the account
     */
    function balanceOfUnderlying(address account)
        external
        virtual
        returns (uint256 balance_);

    /**
     * @notice It calculates the current exchange rate for a whole Teller Token based off the underlying token balance.
     * @return rate_ The current exchange rate.
     */
    function exchangeRate() external virtual returns (uint256 rate_);

    /**
     * @notice It calculates the total supply of the underlying asset.
     * @return totalSupply_ the total supply denoted in the underlying asset.
     */
    function totalUnderlyingSupply()
        external
        virtual
        returns (uint256 totalSupply_);

    /**
     * @notice It calculates the market state values across a given market.
     * @notice Returns values that represent the global state across the market.
     * @return totalSupplied Total amount of the underlying asset supplied.
     * @return totalBorrowed Total amount borrowed through loans.
     * @return totalRepaid The total amount repaid till the current timestamp.
     * @return totalInterestRepaid The total amount interest repaid till the current timestamp.
     * @return totalOnLoan Total amount currently deployed in loans.
     */
    function getMarketState()
        external
        virtual
        returns (
            uint256 totalSupplied,
            uint256 totalBorrowed,
            uint256 totalRepaid,
            uint256 totalInterestRepaid,
            uint256 totalOnLoan
        );

    /**
     * @notice Calculates the current Total Value Locked, denoted in the underlying asset, in the Teller Token pool.
     * @return tvl_ The value locked in the pool.
     *
     * Note: This value includes the amount that is on loan (including ones that were sent to EOAs).
     */
    function currentTVL() external virtual returns (uint256 tvl_);

    /**
     * @notice It validates whether supply to debt (StD) ratio is valid including the loan amount.
     * @param newLoanAmount the new loan amount to consider the StD ratio.
     * @return ratio_ The debt ratio for lending pool.
     */
    function debtRatioFor(uint256 newLoanAmount)
        external
        virtual
        returns (uint16 ratio_);

    /**
     * @notice Called by the Teller Diamond contract when a loan has been taken out and requires funds.
     * @param recipient The account to send the funds to.
     * @param amount Funds requested to fulfill the loan.
     */
    function fundLoan(address recipient, uint256 amount) external virtual;

    /**
     * @notice Called by the Teller Diamond contract when a loan has been repaid.
     * @param amount Funds deposited back into the pool to repay the principal amount of a loan.
     * @param interestAmount Interest value paid into the pool from a loan.
     */
    function repayLoan(uint256 amount, uint256 interestAmount) external virtual;

    /**
     * @notice Increase account supply of specified token amount.
     * @param amount The amount of underlying tokens to use to mint.
     * @return mintAmount_ the amount minted of the specified token
     */
    function mint(uint256 amount)
        external
        virtual
        returns (uint256 mintAmount_);

    /**
     * @notice Redeem supplied Teller tokens for underlying value.
     * @param amount The amount of Teller tokens to redeem.
     */
    function redeem(uint256 amount) external virtual;

    /**
     * @notice Redeem supplied underlying value.
     * @param amount The amount of underlying tokens to redeem.
     */
    function redeemUnderlying(uint256 amount) external virtual;

    /**
     * @notice Rebalances the funds controlled by Teller Token according to the current strategy.
     *
     * See {TTokenStrategy}.
     */
    function rebalance() external virtual;

    /**
     * @notice Sets a new strategy to use for balancing funds.
     * @param strategy Address to the new strategy contract. Must implement the {ITTokenStrategy} interface.
     * @param initData Optional data to initialize the strategy.
     *
     * Requirements:
     *  - Sender must have ADMIN role
     */
    function setStrategy(address strategy, bytes calldata initData)
        external
        virtual;

    /**
     * @notice Gets the strategy used for balancing funds.
     * @return address of the strategy contract
     */
    function getStrategy() external view virtual returns (address);

    /**
     * @notice Sets the restricted state of the platform.
     * @param state boolean value that resembles the platform's state
     */
    function restrict(bool state) external virtual;

    /**
     * @notice it initializes the Teller Token
     * @param admin address of the admin to the respective Teller Token
     * @param underlying address of the ERC20 token
     */
    function initialize(address admin, address underlying) external virtual;
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

// Contracts
import { CONTROLLER, ADMIN, EXCHANGE_RATE_FACTOR } from "./data.sol";
import { ITTokenStrategy } from "./strategies/ITTokenStrategy.sol";
import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";

// Utils
import { Address } from "@openzeppelin/contracts/utils/Address.sol";

// Interfaces
import { ITToken } from "./ITToken.sol";

// Libraries
import {
    SafeERC20
} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {
    ERC165Checker
} from "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
import { RolesLib } from "../../contexts2/access-control/roles/RolesLib.sol";
import {
    ReentryMods
} from "../../contexts2/access-control/reentry/ReentryMods.sol";
import { NumbersLib } from "../../shared/libraries/NumbersLib.sol";

// Storage
import "./token-storage.sol" as Storage;

/**
 * @notice This contract represents a lending pool for an asset within Teller protocol.
 * @author [email protected]
 */
contract TToken_V1 is ITToken, ReentryMods {
    function() pure returns (Storage.Store storage) internal constant s =
        Storage.store;

    /* Modifiers */

    /**
     * @notice Checks if the LP is restricted or the message sender has the CONTROLLER role.
     *
     * The LP being restricted means that only the Teller protocol may
     *  lend/borrow funds.
     */
    modifier notRestricted {
        require(
            !s().restricted || RolesLib.hasRole(CONTROLLER, _msgSender()),
            "Teller: platform restricted"
        );
        _;
    }

    /* Public Functions */

    /**
     * @notice it returns the decimal places of the respective TToken
     * @return decimals of the token
     */
    function decimals() public view override returns (uint8) {
        return s().decimals;
    }

    /**
     * @notice The token that is the underlying asset for this Teller token.
     * @return ERC20 token that is the underlying asset
     */
    function underlying() public view override returns (ERC20) {
        return s().underlying;
    }

    /**
     * @notice The balance of an {account} denoted in underlying value.
     * @param account Address to calculate the underlying balance.
     * @return balance_ the balance of the account
     */
    function balanceOfUnderlying(address account)
        public
        override
        returns (uint256)
    {
        return _valueInUnderlying(balanceOf(account), exchangeRate());
    }

    /**
     * @notice It calculates the current scaled exchange rate for a whole Teller Token based of the underlying token balance.
     * @return rate_ The current exchange rate, scaled by the EXCHANGE_RATE_FACTOR.
     */
    function exchangeRate() public override returns (uint256 rate_) {
        if (totalSupply() == 0) {
            return EXCHANGE_RATE_FACTOR;
        }

        rate_ = (currentTVL() * EXCHANGE_RATE_FACTOR) / totalSupply();
    }

    /**
     * @notice It calculates the total supply of the underlying asset.
     * @return totalSupply_ the total supply denoted in the underlying asset.
     */
    function totalUnderlyingSupply() public override returns (uint256) {
        bytes memory data =
            _delegateStrategy(
                abi.encodeWithSelector(
                    ITTokenStrategy.totalUnderlyingSupply.selector
                )
            );
        return abi.decode(data, (uint256));
    }

    /**
     * @notice It calculates the market state values across a given market.
     * @notice Returns values that represent the global state across the market.
     * @return totalSupplied Total amount of the underlying asset supplied.
     * @return totalBorrowed Total amount borrowed through loans.
     * @return totalRepaid The total amount repaid till the current timestamp.
     * @return totalInterestRepaid The total amount interest repaid till the current timestamp.
     * @return totalOnLoan Total amount currently deployed in loans.
     */
    function getMarketState()
        external
        override
        returns (
            uint256 totalSupplied,
            uint256 totalBorrowed,
            uint256 totalRepaid,
            uint256 totalInterestRepaid,
            uint256 totalOnLoan
        )
    {
        totalSupplied = totalUnderlyingSupply();
        totalBorrowed = s().totalBorrowed;
        totalRepaid = s().totalRepaid;
        totalInterestRepaid = s().totalInterestRepaid;
        totalOnLoan = totalBorrowed - totalRepaid;
    }

    /**
     * @notice Calculates the current Total Value Locked, denoted in the underlying asset, in the Teller Token pool.
     * @return tvl_ The value locked in the pool.
     *
     * Note: This value includes the amount that is on loan (including ones that were sent to EOAs).
     */
    function currentTVL() public override returns (uint256 tvl_) {
        tvl_ += totalUnderlyingSupply();
        tvl_ += s().totalBorrowed;
        tvl_ -= s().totalRepaid;
    }

    /**
     * @notice It validates whether supply to debt (StD) ratio is valid including the loan amount.
     * @param newLoanAmount the new loan amount to consider the StD ratio.
     * @return ratio_ The debt ratio for lending pool.
     */
    function debtRatioFor(uint256 newLoanAmount)
        external
        override
        returns (uint16 ratio_)
    {
        uint256 onLoan = s().totalBorrowed - s().totalRepaid;
        uint256 supplied = totalUnderlyingSupply() + onLoan;
        if (supplied > 0) {
            ratio_ = NumbersLib.ratioOf(onLoan + newLoanAmount, supplied);
        }
    }

    /**
     * @notice Called by the Teller Diamond contract when a loan has been taken out and requires funds.
     * @param recipient The account to send the funds to.
     * @param amount Funds requested to fulfil the loan.
     */
    function fundLoan(address recipient, uint256 amount)
        external
        virtual
        override
        authorized(CONTROLLER, _msgSender())
    {
        // If TToken is not holding enough funds to cover the loan, call the strategy to try to withdraw
        uint256 balance = s().underlying.balanceOf(address(this));
        if (balance < amount) {
            _delegateStrategy(
                abi.encodeWithSelector(
                    ITTokenStrategy.withdraw.selector,
                    amount - balance
                )
            );
        }

        // Increase total borrowed amount
        s().totalBorrowed += amount;

        // Transfer tokens to recipient
        SafeERC20.safeTransfer(s().underlying, recipient, amount);
        emit LoanFunded(recipient, amount);
    }

    /**
     * @notice Called by the Teller Diamond contract when a loan has been repaid.
     * @param amount Funds deposited back into the pool to repay the principal amount of a loan.
     * @param interestAmount Interest value paid into the pool from a loan.
     */
    function repayLoan(uint256 amount, uint256 interestAmount)
        external
        override
        authorized(CONTROLLER, _msgSender())
    {
        s().totalRepaid += amount;
        s().totalInterestRepaid += interestAmount;
        emit LoanPaymentMade(_msgSender(), amount, interestAmount);
    }

    /**
     * @dev The tToken contract needs to have been granted sufficient allowance to transfer the amount being used to mint.
     * @notice Deposit underlying token amount into LP and mint tokens.
     * @param amount The amount of underlying tokens to use to mint.
     * @return Amount of TTokens minted.
     */
    function mint(uint256 amount)
        external
        override
        notRestricted
        nonReentry(keccak256("MINT"))
        returns (uint256)
    {
        require(amount > 0, "Teller: cannot mint 0");
        require(
            amount <= s().underlying.balanceOf(_msgSender()),
            "Teller: insufficient underlying"
        );

        // Calculate amount of tokens to mint
        uint256 mintAmount = _valueOfUnderlying(amount, exchangeRate());

        require(mintAmount > 0, "Teller: amount to be minted cannot be 0");

        // Transfer tokens from lender
        SafeERC20.safeTransferFrom(
            s().underlying,
            _msgSender(),
            address(this),
            amount
        );

        // Mint Teller token value of underlying
        _mint(_msgSender(), mintAmount);

        emit Mint(_msgSender(), mintAmount, amount);

        return mintAmount;
    }

    /**
     * @notice Redeem supplied Teller tokens for underlying value.
     * @param amount The amount of Teller tokens to redeem.
     */
    function redeem(uint256 amount)
        external
        override
        nonReentry(keccak256("REDEEM"))
    {
        require(amount > 0, "Teller: cannot withdraw 0");
        require(
            amount <= balanceOf(_msgSender()),
            "Teller: redeem amount exceeds balance"
        );

        // Accrue interest and calculate exchange rate
        uint256 underlyingAmount = _valueInUnderlying(amount, exchangeRate());
        require(
            underlyingAmount > 0,
            "Teller: underlying teller token value to be redeemed cannot be 0"
        );

        require(
            underlyingAmount <= totalUnderlyingSupply(),
            "Teller: redeem ttoken lp not enough supply"
        );

        // Burn Teller Tokens and transfer underlying
        _redeem(amount, underlyingAmount);
    }

    /**
     * @notice Redeem supplied underlying value.
     * @param amount The amount of underlying tokens to redeem.
     */
    function redeemUnderlying(uint256 amount)
        external
        override
        nonReentry(keccak256("REDEEM"))
    {
        require(amount > 0, "Teller: cannot withdraw 0");
        require(
            amount <= totalUnderlyingSupply(),
            "Teller: redeem ttoken lp not enough supply"
        );

        // Accrue interest and calculate exchange rate
        uint256 rate = exchangeRate();
        uint256 tokenValue = _valueOfUnderlying(amount, rate) + 1;

        // Make sure sender has adequate balance
        require(
            tokenValue <= balanceOf(_msgSender()),
            "Teller: redeem amount exceeds balance"
        );

        // Burn Teller Tokens and transfer underlying
        _redeem(tokenValue, amount);
    }

    /**
     * @dev Redeem an {amount} of Teller Tokens and transfers {underlyingAmount} to the caller.
     * @param amount Total amount of Teller Tokens to burn.
     * @param underlyingAmount Total amount of underlying asset tokens to transfer to caller.
     *
     * This function should only be called by {redeem} and {redeemUnderlying} after the exchange
     * rate and both token values have been calculated to use.
     */
    function _redeem(uint256 amount, uint256 underlyingAmount) internal {
        // Burn Teller tokens
        _burn(_msgSender(), amount);

        // Make sure enough funds are available to redeem
        _delegateStrategy(
            abi.encodeWithSelector(
                ITTokenStrategy.withdraw.selector,
                underlyingAmount
            )
        );

        // Transfer funds back to lender
        SafeERC20.safeTransfer(s().underlying, _msgSender(), underlyingAmount);

        emit Redeem(_msgSender(), amount, underlyingAmount);
    }

    /**
     * @notice Rebalances the funds controlled by Teller Token according to the current strategy.
     *
     * See {TTokenStrategy}.
     */
    function rebalance() public override {
        _delegateStrategy(
            abi.encodeWithSelector(ITTokenStrategy.rebalance.selector)
        );
    }

    /**
     * @notice Sets or updates a strategy to use for balancing funds.
     * @param strategy Address to the new strategy contract. Must implement the {ITTokenStrategy} interface.
     * @param initData Optional data to initialize the strategy.
     *
     * Requirements:
     *  - Sender must have ADMIN role
     */
    function setStrategy(address strategy, bytes calldata initData)
        external
        override
        authorized(ADMIN, _msgSender())
    {
        require(
            ERC165Checker.supportsInterface(
                strategy,
                type(ITTokenStrategy).interfaceId
            ),
            "Teller: strategy does not support ITTokenStrategy"
        );
        s().strategy = strategy;
        if (initData.length > 0) {
            _delegateStrategy(initData);
        }
        emit StrategySet(strategy, _msgSender());
    }

    /**
     * @notice Gets the strategy used for balancing funds.
     * @return address of the strategy contract
     */
    function getStrategy() external view override returns (address) {
        return s().strategy;
    }

    /**
     * @notice Sets the restricted state of the tToken.
     * @param state boolean value that resembles the platform's state
     */
    function restrict(bool state)
        public
        override
        authorized(ADMIN, _msgSender())
    {
        s().restricted = state;
        emit PlatformRestricted(state, _msgSender());
    }

    /**
     * @notice it initializes the Teller Token
     * @param admin address of the admin to the respective Teller Token
     * @param underlying address of the ERC20 token
     *
     * Requirements:
     *  - Underlying token must implement `name`, `symbol` and `decimals`
     */
    function initialize(address admin, address underlying)
        external
        override
        initializer
    {
        require(
            Address.isContract(msg.sender),
            "Teller: controller not contract"
        );
        require(
            Address.isContract(underlying),
            "Teller: underlying token not contract"
        );

        RolesLib.grantRole(CONTROLLER, msg.sender);
        RolesLib.grantRole(ADMIN, admin);

        s().underlying = ERC20(underlying);
        __ERC20_init(
            string(abi.encodePacked("Teller ", s().underlying.name())),
            string(abi.encodePacked("t", s().underlying.symbol()))
        );
        s().decimals = s().underlying.decimals();
        // Platform restricted by default
        s().restricted = true;
    }

    /**
     * @notice it retrieves the value of the underlying token
     * @param amount the amount of tokens to calculate the value of
     * @param rate the exchangeRate() to divide with the amount * exchange_rate_factor
     * @return value_ the underlying value of the token amount
     */
    function _valueOfUnderlying(uint256 amount, uint256 rate)
        internal
        pure
        returns (uint256 value_)
    {
        value_ = (amount * EXCHANGE_RATE_FACTOR) / rate;
    }

    /**
     * @notice it retrieves the value in the underlying tokens
     *
     */
    function _valueInUnderlying(uint256 amount, uint256 rate)
        internal
        pure
        returns (uint256 value_)
    {
        value_ = (amount * (rate)) / EXCHANGE_RATE_FACTOR;
    }

    /**
     * @notice Delegates data to call on the strategy contract.
     * @param callData Data to call the strategy contract with.
     *
     */
    function _delegateStrategy(bytes memory callData)
        internal
        returns (bytes memory)
    {
        return Address.functionDelegateCall(s().strategy, callData);
    }
}

File 23 of 27 : data.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

// Role ID used to pull funds for the asset it manages (i.e. TellerDiamond)
bytes32 constant CONTROLLER = keccak256("CONTROLLER");
// Role ID used to for accounts to call special methods that modify its state
bytes32 constant ADMIN = keccak256("ADMIN");

uint256 constant EXCHANGE_RATE_FACTOR = 1e18;

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface ITTokenStrategy {
    /**
     * @notice This event is emitted when the underlying assets are rebalanced as directed by the set investment strategy.
     * @param strategyName The name of the strategy being rebalanced - example: "CompoundStrategy_1"
     * @param sender The address of the sender rebalancing the token strategy.
     */
    event StrategyRebalanced(
        string indexed strategyName,
        address indexed sender
    );

    /**
     * @notice This event is emitted when the underlying assets are rebalanced as directed by the set investment strategy.
     * @param strategyName The name of the strategy being rebalanced - example: "CompoundStrategy_1"
     * @param investmentAsset The address of the investible asset / protocol being used to leverage the underlying assets.
     * @param sender The address of the sender rebalancing the token strategy.
     */
    event StrategyInitialized(
        string indexed strategyName,
        address investmentAsset,
        address indexed sender
    );

    /**
     * @notice it returns the total supply of an underlying asset in a Teller token.
     * @return uint256 the underlying supply
     */
    function totalUnderlyingSupply() external returns (uint256);

    /**
     * @notice it rebalances the underlying asset held by the Teller Token.
     */
    function rebalance() external;

    /**
     * @notice it withdraws amount of tokens in a pool
     * @param amount amount to withdraw
     */

    function withdraw(uint256 amount) external;
}

File 25 of 27 : token-storage.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

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

struct Store {
    // The underlying asset of the tToken
    ERC20 underlying;
    // The address of the investment strategy contract managing the underlying assets
    address strategy;
    // The total amount of the underlying asset currently out in disbursed loans
    uint256 totalBorrowed;
    // The total amount of the underlying asset currently repaid from disbursed loans
    uint256 totalRepaid;
    // The total amount of the underlying asset currently repaid in the form of interest owed from disbursed loans
    uint256 totalInterestRepaid;
    // The decimals of the underlying ERC20 asset
    uint8 decimals;
    // The status of token investment restriction
    bool restricted;
}

bytes32 constant POSITION = keccak256("ttoken.storage.position");

/**
 * @notice it saves the Store struct in a hashed slot
 */
function store() pure returns (Store storage s_) {
    bytes32 position = POSITION;
    assembly {
        s_.slot := position
    }
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

// Libraries
import { SafeCast } from "@openzeppelin/contracts/utils/math/SafeCast.sol";

/**
 * @dev Utility library for uint256 numbers
 *
 * @author [email protected]
 */
library NumbersLib {
    /**
     * @dev It represents 100% with 2 decimal places.
     */
    uint256 internal constant ONE_HUNDRED_PERCENT = 10000;

    /**
     * @notice Returns a percentage value of a number.
     * @param self The number to get a percentage of.
     * @param percentage The percentage value to calculate with 2 decimal places (10000 = 100%).
     */
    function percent(uint256 self, uint16 percentage)
        internal
        pure
        returns (uint256)
    {
        return (self * uint256(percentage)) / ONE_HUNDRED_PERCENT;
    }

    function percent(int256 self, uint256 percentage)
        internal
        pure
        returns (int256)
    {
        return (self * int256(percentage)) / int256(ONE_HUNDRED_PERCENT);
    }

    /**
     * @notice it returns the absolute number of a specified parameter
     * @param self the number to be returned in it's absolute
     * @return the absolute number
     */
    function abs(int256 self) internal pure returns (uint256) {
        return self >= 0 ? uint256(self) : uint256(-1 * self);
    }

    /**
     * @notice Returns a ratio percentage of {num1} to {num2}.
     * @param num1 The number used to get the ratio for.
     * @param num2 The number used to get the ratio from.
     * @return Ratio percentage with 2 decimal places (10000 = 100%).
     */
    function ratioOf(uint256 num1, uint256 num2)
        internal
        pure
        returns (uint16)
    {
        return
            num2 == 0
                ? 0
                : SafeCast.toUint16((num1 * ONE_HUNDRED_PERCENT) / num2);
    }
}

File 27 of 27 : roles.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

/**
 * @dev the roles for the user to assign, revoke and check in functions
 */
bytes32 constant ADMIN = keccak256("ADMIN");
bytes32 constant PAUSER = keccak256("PAUSER");
bytes32 constant AUTHORIZED = keccak256("AUTHORIZED");

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

API
[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"recipient","type":"address"},{"indexed":false,"internalType":"uint256","name":"totalBorrowed","type":"uint256"}],"name":"LoanFunded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"principlePayment","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"interestPayment","type":"uint256"}],"name":"LoanPaymentMade","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"tTokenAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"underlyingAmount","type":"uint256"}],"name":"Mint","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"restriction","type":"bool"},{"indexed":true,"internalType":"address","name":"investmentManager","type":"address"}],"name":"PlatformRestricted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"tTokenAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"underlyingAmount","type":"uint256"}],"name":"Redeem","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"strategyAddress","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"StrategySet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOfUnderlying","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"currentTVL","outputs":[{"internalType":"uint256","name":"tvl_","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newLoanAmount","type":"uint256"}],"name":"debtRatioFor","outputs":[{"internalType":"uint16","name":"ratio_","type":"uint16"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"exchangeRate","outputs":[{"internalType":"uint256","name":"rate_","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"fundLoan","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getMarketState","outputs":[{"internalType":"uint256","name":"totalSupplied","type":"uint256"},{"internalType":"uint256","name":"totalBorrowed","type":"uint256"},{"internalType":"uint256","name":"totalRepaid","type":"uint256"},{"internalType":"uint256","name":"totalInterestRepaid","type":"uint256"},{"internalType":"uint256","name":"totalOnLoan","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getStrategy","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"grantRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"hasRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"admin","type":"address"},{"internalType":"address","name":"underlying","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"mint","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rebalance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"redeem","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"redeemUnderlying","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"renounceRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"interestAmount","type":"uint256"}],"name":"repayLoan","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"state","type":"bool"}],"name":"restrict","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"strategy","type":"address"},{"internalType":"bytes","name":"initData","type":"bytes"}],"name":"setStrategy","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalUnderlyingSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"underlying","outputs":[{"internalType":"contract ERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"}]

608060405234801561001057600080fd5b50612d69806100206000396000f3fe608060405234801561001057600080fd5b50600436106101f05760003560e01c80638a700b531161010f578063be71e66c116100a2578063db006a7511610071578063db006a751461042e578063dd62ed3e14610441578063e920b1e11461047a578063ecfd35191461048d576101f0565b8063be71e66c146103c5578063d547741f146103d8578063d8165743146103eb578063d8774d991461041b576101f0565b8063a0712d68116100de578063a0712d6814610384578063a457c2d714610397578063a9059cbb146103aa578063a95411e0146103bd576101f0565b80638a700b53146103435780638bb9c5bf1461035657806391d148541461036957806395d89b411461037c576101f0565b806339509351116101875780636f307dc3116101565780636f307dc3146102f757806370a08231146102ff5780637d7c2a1c14610328578063852a12e314610330576101f0565b806339509351146102b65780633af9e669146102c95780633ba0b9a9146102dc578063485cc955146102e4576101f0565b806318160ddd116101c357806318160ddd1461026c57806323b872dd146102745780632f2ff15d14610287578063313ce5671461029c576101f0565b806306fdde03146101f557806307da060314610213578063095ea7b314610233578063143a08d414610256575b600080fd5b6101fd6104b3565b60405161020a9190612a1f565b60405180910390f35b61021b610546565b6040516001600160a01b03909116815260200161020a565b610246610241366004612818565b610562565b604051901515815260200161020a565b61025e610579565b60405190815260200161020a565b60355461025e565b61024661028236600461275f565b6105cc565b61029a610295366004612891565b610684565b005b6102a46106ca565b60405160ff909116815260200161020a565b6102466102c4366004612818565b6106e0565b61025e6102d7366004612713565b610717565b61025e610749565b61029a6102f236600461272d565b610794565b61021b610b1a565b61025e61030d366004612713565b6001600160a01b031660009081526033602052604090205490565b61029a610b33565b61029a61033e366004612879565b610b68565b61029a610351366004612969565b610d02565b61029a610364366004612879565b610dba565b610246610377366004612891565b610dc4565b6101fd610dd0565b61025e610392366004612879565b610ddf565b6102466103a5366004612818565b61112f565b6102466103b8366004612818565b6111ca565b61025e6111d7565b61029a6103d336600461279a565b61121b565b61029a6103e6366004612891565b61137f565b6103f36113bf565b604080519586526020860194909452928401919091526060830152608082015260a00161020a565b61029a610429366004612841565b61140e565b61029a61043c366004612879565b6114b6565b61025e61044f36600461272d565b6001600160a01b03918216600090815260346020908152604080832093909416825291909152205490565b61029a610488366004612818565b6116b2565b6104a061049b366004612879565b611778565b60405161ffff909116815260200161020a565b6060603680546104c290612c37565b80601f01602080910402602001604051908101604052809291908181526020018280546104ee90612c37565b801561053b5780601f106105105761010080835404028352916020019161053b565b820191906000526020600020905b81548152906001019060200180831161051e57829003601f168201915b505050505090505b90565b60006105506117d9565b600101546001600160a01b0316905090565b600061056f3384846117fd565b5060015b92915050565b6040805160048152602481019091526020810180516001600160e01b031663050e823560e21b17905260009081906105b090611922565b9050808060200190518101906105c69190612951565b91505090565b60006105d9848484611942565b6001600160a01b0384166000908152603460209081526040808320338452909152902054828110156106635760405162461bcd60e51b815260206004820152602860248201527f45524332303a207472616e7366657220616d6f756e74206578636565647320616044820152676c6c6f77616e636560c01b60648201526084015b60405180910390fd5b61067785336106728685612bf4565b6117fd565b60019150505b9392505050565b600080516020612cf48339815191523361069e8282611b1a565b6106ba5760405162461bcd60e51b815260040161065a90612a52565b6106c48484611b4e565b50505050565b60006106d46117d9565b6005015460ff16905090565b3360008181526034602090815260408083206001600160a01b0387168452909152812054909161056f918590610672908690612b9d565b6001600160a01b0381166000908152603360205260408120546107419061073c610749565b611bcc565b90505b919050565b600061075460355490565b6107675750670de0b6b3a7640000610543565b603554670de0b6b3a764000061077b6111d7565b6107859190612bd5565b61078f9190612bb5565b905090565b600054610100900460ff16806107ad575060005460ff16155b6107c95760405162461bcd60e51b815260040161065a90612ace565b600054610100900460ff161580156107eb576000805461ffff19166101011790555b333b6108395760405162461bcd60e51b815260206004820152601f60248201527f54656c6c65723a20636f6e74726f6c6c6572206e6f7420636f6e747261637400604482015260640161065a565b813b6108955760405162461bcd60e51b815260206004820152602560248201527f54656c6c65723a20756e6465726c79696e6720746f6b656e206e6f7420636f6e6044820152641d1c9858dd60da1b606482015260840161065a565b6108ad600080516020612cad83398151915233611b4e565b6108c5600080516020612cf483398151915284611b4e565b816108ce6117d9565b80546001600160a01b0319166001600160a01b0392909216919091179055610a406108f76117d9565b54604080516306fdde0360e01b815290516001600160a01b03909216916306fdde0391600480820192600092909190829003018186803b15801561093a57600080fd5b505afa15801561094e573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261097691908101906128b3565b60405160200161098691906129c7565b60405160208183030381529060405261099d6117d9565b54604080516395d89b4160e01b815290516001600160a01b03909216916395d89b4191600480820192600092909190829003018186803b1580156109e057600080fd5b505afa1580156109f4573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610a1c91908101906128b3565b604051602001610a2c91906129f6565b604051602081830303815290604052611beb565b610a486117d9565b546040805163313ce56760e01b815290516001600160a01b039092169163313ce56791600480820192602092909190829003018186803b158015610a8b57600080fd5b505afa158015610a9f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ac3919061298a565b610acb6117d9565b600501805460ff191660ff929092169190911790556001610aea6117d9565b60050180549115156101000261ff00199092169190911790558015610b15576000805461ff00191690555b505050565b6000610b246117d9565b546001600160a01b0316905090565b6040805160048152602481019091526020810180516001600160e01b0316631f5f0a8760e21b179052610b6590611922565b50565b7feba135a74248c737f901cbd8d0f53e729a3f212e734748c2e0d8d39096125e5c60008190527f7b305b6be5f275f648d05716597c483d754c2a242bd605feba3c64fb853605366020527fd51fad483e9bd4fa5dd43c95a6dde60b73fec1248ce54775bb96529d1141aa1b54600080516020612d148339815191529060ff1615610c045760405162461bcd60e51b815260040161065a90612b66565b60008281526002820160205260409020805460ff1916600117905582610c685760405162461bcd60e51b8152602060048201526019602482015278054656c6c65723a2063616e6e6f74207769746864726177203603c1b604482015260640161065a565b610c70610579565b831115610c8f5760405162461bcd60e51b815260040161065a90612b1c565b6000610c99610749565b90506000610ca78583611c6a565b610cb2906001612b9d565b9050610cbd3361030d565b811115610cdc5760405162461bcd60e51b815260040161065a90612a89565b610ce68186611c7f565b5050600091825260020160205260409020805460ff1916905550565b600080516020612cad83398151915233610d1c8282611b1a565b610d385760405162461bcd60e51b815260040161065a90612a52565b83610d416117d9565b6003016000828254610d539190612b9d565b90915550839050610d626117d9565b6004016000828254610d749190612b9d565b9091555050604080518581526020810185905233917fc091ac0b81e7f83b1bd632697aab4fe32a683168ca5ca7ad8075b49c3e669c4a910160405180910390a250505050565b610b658133611d04565b600061067d8383611b1a565b6060603780546104c290612c37565b6000610de96117d9565b60050154610100900460ff161580610e145750610e14600080516020612cad83398151915233611b1a565b610e605760405162461bcd60e51b815260206004820152601b60248201527f54656c6c65723a20706c6174666f726d20726573747269637465640000000000604482015260640161065a565b7ffdf81848136595c31bb5f76217767372bc4bf906663038eb38381131ea27ecba60008190527f7b305b6be5f275f648d05716597c483d754c2a242bd605feba3c64fb853605366020527fa8b4b8db2d6e615394be6b6e7c62c4b724469d7ac9026422a171f9c66a50d83f54600080516020612d148339815191529060ff1615610efc5760405162461bcd60e51b815260040161065a90612b66565b60008281526002820160205260409020805460ff1916600117905583610f5c5760405162461bcd60e51b8152602060048201526015602482015274054656c6c65723a2063616e6e6f74206d696e74203605c1b604482015260640161065a565b610f646117d9565b546001600160a01b03166370a08231336040516001600160e01b031960e084901b1681526001600160a01b03909116600482015260240160206040518083038186803b158015610fb357600080fd5b505afa158015610fc7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610feb9190612951565b84111561103a5760405162461bcd60e51b815260206004820152601f60248201527f54656c6c65723a20696e73756666696369656e7420756e6465726c79696e6700604482015260640161065a565b600061104d85611048610749565b611c6a565b9050600081116110af5760405162461bcd60e51b815260206004820152602760248201527f54656c6c65723a20616d6f756e7420746f206265206d696e7465642063616e6e60448201526606f7420626520360cc1b606482015260840161065a565b6110cc6110ba6117d9565b546001600160a01b0316333088611d80565b6110d63382611deb565b604080518281526020810187905233917f4c209b5fc8ad50758f13e2e1088ba56a560dff690a1c6fef26394f4c03821c4f910160405180910390a29250600091825260020160205260409020805460ff19169055919050565b3360009081526034602090815260408083206001600160a01b0386168452909152812054828110156111b15760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b606482015260840161065a565b6111c033856106728685612bf4565b5060019392505050565b600061056f338484611942565b60006111e1610579565b6111eb9082612b9d565b90506111f56117d9565b600201546112039082612b9d565b905061120d6117d9565b6003015461078f9082612bf4565b600080516020612cf4833981519152336112358282611b1a565b6112515760405162461bcd60e51b815260040161065a90612a52565b6112628563475c5f8560e01b611eca565b6112c85760405162461bcd60e51b815260206004820152603160248201527f54656c6c65723a20737472617465677920646f6573206e6f7420737570706f7260448201527074204954546f6b656e537472617465677960781b606482015260840161065a565b846112d16117d9565b60010180546001600160a01b0319166001600160a01b039290921691909117905582156113395761133784848080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525061192292505050565b505b604080516001600160a01b0387168152905133917f7a587acd0fd101cfe7d6d98bad768e91209a7ae91e55c3702570425bf0eae9bc919081900360200190a25050505050565b600080516020612cf4833981519152336113998282611b1a565b6113b55760405162461bcd60e51b815260040161065a90612a52565b6106c48484611d04565b60008060008060006113cf610579565b94506113d96117d9565b6002015493506113e76117d9565b6003015492506113f56117d9565b6004015491506114058385612bf4565b90509091929394565b600080516020612cf4833981519152336114288282611b1a565b6114445760405162461bcd60e51b815260040161065a90612a52565b8261144d6117d9565b60050180549115156101000261ff001990921691909117905561146d3390565b6001600160a01b03167f9a8a686aa374e3c964e707566deb1d0ef1fda94567495b4767063063de913ff5846040516114a9911515815260200190565b60405180910390a2505050565b7feba135a74248c737f901cbd8d0f53e729a3f212e734748c2e0d8d39096125e5c60008190527f7b305b6be5f275f648d05716597c483d754c2a242bd605feba3c64fb853605366020527fd51fad483e9bd4fa5dd43c95a6dde60b73fec1248ce54775bb96529d1141aa1b54600080516020612d148339815191529060ff16156115525760405162461bcd60e51b815260040161065a90612b66565b60008281526002820160205260409020805460ff19166001179055826115b65760405162461bcd60e51b8152602060048201526019602482015278054656c6c65723a2063616e6e6f74207769746864726177203603c1b604482015260640161065a565b6115bf3361030d565b8311156115de5760405162461bcd60e51b815260040161065a90612a89565b60006115ec8461073c610749565b905060008111611666576040805162461bcd60e51b81526020600482015260248101919091527f54656c6c65723a20756e6465726c79696e672074656c6c657220746f6b656e2060448201527f76616c756520746f2062652072656465656d65642063616e6e6f742062652030606482015260840161065a565b61166e610579565b81111561168d5760405162461bcd60e51b815260040161065a90612b1c565b6116978482611c7f565b50600091825260020160205260409020805460ff1916905550565b600080516020612cad833981519152336116cc8282611b1a565b6116e85760405162461bcd60e51b815260040161065a90612a52565b6040516024810184905261173a90632e1a7d4d60e01b906044015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152611922565b50826117446117d9565b60020160008282546117569190612b9d565b909155506106c490506117676117d9565b546001600160a01b03168585611ee6565b6000806117836117d9565b6003015461178f6117d9565b6002015461179d9190612bf4565b90506000816117aa610579565b6117b49190612b9d565b905080156117d2576117cf6117c98584612b9d565b82611f16565b92505b5050919050565b7ff72b349e2c69862bdc86afd2a363bf16c24bd97d10f7ac9d49f7e2eedebba2b490565b6001600160a01b03831661185f5760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b606482015260840161065a565b6001600160a01b0382166118c05760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b606482015260840161065a565b6001600160a01b0383811660008181526034602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92591015b60405180910390a3505050565b606061074161192f6117d9565b600101546001600160a01b031683611f4b565b6001600160a01b0383166119a65760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b606482015260840161065a565b6001600160a01b038216611a085760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b606482015260840161065a565b6001600160a01b03831660009081526033602052604090205481811015611a805760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b606482015260840161065a565b611a8a8282612bf4565b6001600160a01b038086166000908152603360205260408082209390935590851681529081208054849290611ac0908490612b9d565b92505081905550826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef84604051611b0c91815260200190565b60405180910390a350505050565b6000611b24611f70565b6000938452602090815260408085206001600160a01b039490941685529290525090205460ff1690565b611b588282611b1a565b15611b6257611bc8565b6001611b6c611f70565b6000848152602091825260408082206001600160a01b0386168084529352808220805460ff1916941515949094179093559151339285917f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d9190a45b5050565b6000670de0b6b3a7640000611be18385612bd5565b61067d9190612bb5565b600054610100900460ff1680611c04575060005460ff16155b611c205760405162461bcd60e51b815260040161065a90612ace565b600054610100900460ff16158015611c42576000805461ffff19166101011790555b611c4a611f86565b611c548383611ff1565b8015610b15576000805461ff0019169055505050565b600081611be1670de0b6b3a764000085612bd5565b611c893383612086565b60405160248101829052611ca890632e1a7d4d60e01b90604401611703565b50611cc5611cb46117d9565b546001600160a01b03163383611ee6565b604080518381526020810183905233917fe5b754fb1abb7f01b499791d0b820ae3b6af3424ac1c59768edb53f4ec31a929910160405180910390a25050565b611d0e8282611b1a565b611d1757611bc8565b6000611d21611f70565b6000848152602091825260408082206001600160a01b0386168084529352808220805460ff1916941515949094179093559151339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b6040516001600160a01b03808516602483015283166044820152606481018290526106c49085906323b872dd60e01b906084015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b0319909316929092179091526121d5565b6001600160a01b038216611e415760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604482015260640161065a565b8060356000828254611e539190612b9d565b90915550506001600160a01b03821660009081526033602052604081208054839290611e80908490612b9d565b90915550506040518181526001600160a01b038316906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a35050565b6000611ed5836122a7565b801561067d575061067d83836122da565b6040516001600160a01b038316602482015260448101829052610b1590849063a9059cbb60e01b90606401611db4565b60008115611f4257611f3d82611f2e61271086612bd5565b611f389190612bb5565b6123c3565b61067d565b50600092915050565b606061067d8383604051806060016040528060278152602001612ccd6027913961242a565b6000600080516020612d1483398151915261078f565b600054610100900460ff1680611f9f575060005460ff16155b611fbb5760405162461bcd60e51b815260040161065a90612ace565b600054610100900460ff16158015611fdd576000805461ffff19166101011790555b8015610b65576000805461ff001916905550565b600054610100900460ff168061200a575060005460ff16155b6120265760405162461bcd60e51b815260040161065a90612ace565b600054610100900460ff16158015612048576000805461ffff19166101011790555b825161205b90603690602086019061266c565b50815161206f90603790602085019061266c565b508015610b15576000805461ff0019169055505050565b6001600160a01b0382166120e65760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b606482015260840161065a565b6001600160a01b0382166000908152603360205260409020548181101561215a5760405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e604482015261636560f01b606482015260840161065a565b6121648282612bf4565b6001600160a01b03841660009081526033602052604081209190915560358054849290612192908490612bf4565b90915550506040518281526000906001600160a01b038516907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef90602001611915565b600061222a826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166124f49092919063ffffffff16565b805190915015610b155780806020019051810190612248919061285d565b610b155760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b606482015260840161065a565b60006122ba826301ffc9a760e01b6122da565b801561074157506122d3826001600160e01b03196122da565b1592915050565b604080516001600160e01b0319831660248083019190915282518083039091018152604490910182526020810180516001600160e01b03166301ffc9a760e01b179052905160009190829081906001600160a01b03871690617530906123419086906129ab565b6000604051808303818686fa925050503d806000811461237d576040519150601f19603f3d011682016040523d82523d6000602084013e612382565b606091505b509150915060208151101561239d5760009350505050610573565b8180156123b95750808060200190518101906123b9919061285d565b9695505050505050565b60006201000082106124265760405162461bcd60e51b815260206004820152602660248201527f53616665436173743a2076616c756520646f65736e27742066697420696e203160448201526536206269747360d01b606482015260840161065a565b5090565b6060833b6124895760405162461bcd60e51b815260206004820152602660248201527f416464726573733a2064656c65676174652063616c6c20746f206e6f6e2d636f6044820152651b9d1c9858dd60d21b606482015260840161065a565b600080856001600160a01b0316856040516124a491906129ab565b600060405180830381855af49150503d80600081146124df576040519150601f19603f3d011682016040523d82523d6000602084013e6124e4565b606091505b50915091506123b982828661250b565b60606125038484600085612544565b949350505050565b6060831561251a57508161067d565b82511561252a5782518084602001fd5b8160405162461bcd60e51b815260040161065a9190612a1f565b6060824710156125a55760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b606482015260840161065a565b843b6125f35760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015260640161065a565b600080866001600160a01b0316858760405161260f91906129ab565b60006040518083038185875af1925050503d806000811461264c576040519150601f19603f3d011682016040523d82523d6000602084013e612651565b606091505b509150915061266182828661250b565b979650505050505050565b82805461267890612c37565b90600052602060002090601f01602090048101928261269a57600085556126e0565b82601f106126b357805160ff19168380011785556126e0565b828001600101855582156126e0579182015b828111156126e05782518255916020019190600101906126c5565b506124269291505b8082111561242657600081556001016126e8565b80356001600160a01b038116811461074457600080fd5b600060208284031215612724578081fd5b61067d826126fc565b6000806040838503121561273f578081fd5b612748836126fc565b9150612756602084016126fc565b90509250929050565b600080600060608486031215612773578081fd5b61277c846126fc565b925061278a602085016126fc565b9150604084013590509250925092565b6000806000604084860312156127ae578283fd5b6127b7846126fc565b9250602084013567ffffffffffffffff808211156127d3578384fd5b818601915086601f8301126127e6578384fd5b8135818111156127f4578485fd5b876020828501011115612805578485fd5b6020830194508093505050509250925092565b6000806040838503121561282a578182fd5b612833836126fc565b946020939093013593505050565b600060208284031215612852578081fd5b813561067d81612c9e565b60006020828403121561286e578081fd5b815161067d81612c9e565b60006020828403121561288a578081fd5b5035919050565b600080604083850312156128a3578182fd5b82359150612756602084016126fc565b6000602082840312156128c4578081fd5b815167ffffffffffffffff808211156128db578283fd5b818401915084601f8301126128ee578283fd5b81518181111561290057612900612c88565b604051601f8201601f19908116603f0116810190838211818310171561292857612928612c88565b81604052828152876020848701011115612940578586fd5b612661836020830160208801612c0b565b600060208284031215612962578081fd5b5051919050565b6000806040838503121561297b578182fd5b50508035926020909101359150565b60006020828403121561299b578081fd5b815160ff8116811461067d578182fd5b600082516129bd818460208701612c0b565b9190910192915050565b60006602a32b63632b9160cd1b825282516129e9816007850160208701612c0b565b9190910160070192915050565b6000601d60fa1b82528251612a12816001850160208701612c0b565b9190910160010192915050565b6000602082528251806020840152612a3e816040850160208701612c0b565b601f01601f19169190910160400192915050565b6020808252601d908201527f416363657373436f6e74726f6c3a206e6f7420617574686f72697a6564000000604082015260600190565b60208082526025908201527f54656c6c65723a2072656465656d20616d6f756e7420657863656564732062616040820152646c616e636560d81b606082015260800190565b6020808252602e908201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160408201526d191e481a5b9a5d1a585b1a5e995960921b606082015260800190565b6020808252602a908201527f54656c6c65723a2072656465656d2074746f6b656e206c70206e6f7420656e6f60408201526975676820737570706c7960b01b606082015260800190565b60208082526018908201527f416363657373436f6e74726f6c3a207265656e74657265640000000000000000604082015260600190565b60008219821115612bb057612bb0612c72565b500190565b600082612bd057634e487b7160e01b81526012600452602481fd5b500490565b6000816000190483118215151615612bef57612bef612c72565b500290565b600082821015612c0657612c06612c72565b500390565b60005b83811015612c26578181015183820152602001612c0e565b838111156106c45750506000910152565b600181811c90821680612c4b57607f821691505b60208210811415612c6c57634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052604160045260246000fd5b8015158114610b6557600080fdfe70546d1c92f8c2132ae23a23f5177aa8526356051c7510df99f50e012d221529416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564df8b4c520ffe197c5343c6f5aec59570151ef9a492f2c624fd45ddde6135ec427b305b6be5f275f648d05716597c483d754c2a242bd605feba3c64fb85360534a2646970667358221220b09a90bc661fa01672b3292fd4d777f6dabf002386935b8598c22fd89920097c64736f6c63430008030033

Deployed Bytecode

0x608060405234801561001057600080fd5b50600436106101f05760003560e01c80638a700b531161010f578063be71e66c116100a2578063db006a7511610071578063db006a751461042e578063dd62ed3e14610441578063e920b1e11461047a578063ecfd35191461048d576101f0565b8063be71e66c146103c5578063d547741f146103d8578063d8165743146103eb578063d8774d991461041b576101f0565b8063a0712d68116100de578063a0712d6814610384578063a457c2d714610397578063a9059cbb146103aa578063a95411e0146103bd576101f0565b80638a700b53146103435780638bb9c5bf1461035657806391d148541461036957806395d89b411461037c576101f0565b806339509351116101875780636f307dc3116101565780636f307dc3146102f757806370a08231146102ff5780637d7c2a1c14610328578063852a12e314610330576101f0565b806339509351146102b65780633af9e669146102c95780633ba0b9a9146102dc578063485cc955146102e4576101f0565b806318160ddd116101c357806318160ddd1461026c57806323b872dd146102745780632f2ff15d14610287578063313ce5671461029c576101f0565b806306fdde03146101f557806307da060314610213578063095ea7b314610233578063143a08d414610256575b600080fd5b6101fd6104b3565b60405161020a9190612a1f565b60405180910390f35b61021b610546565b6040516001600160a01b03909116815260200161020a565b610246610241366004612818565b610562565b604051901515815260200161020a565b61025e610579565b60405190815260200161020a565b60355461025e565b61024661028236600461275f565b6105cc565b61029a610295366004612891565b610684565b005b6102a46106ca565b60405160ff909116815260200161020a565b6102466102c4366004612818565b6106e0565b61025e6102d7366004612713565b610717565b61025e610749565b61029a6102f236600461272d565b610794565b61021b610b1a565b61025e61030d366004612713565b6001600160a01b031660009081526033602052604090205490565b61029a610b33565b61029a61033e366004612879565b610b68565b61029a610351366004612969565b610d02565b61029a610364366004612879565b610dba565b610246610377366004612891565b610dc4565b6101fd610dd0565b61025e610392366004612879565b610ddf565b6102466103a5366004612818565b61112f565b6102466103b8366004612818565b6111ca565b61025e6111d7565b61029a6103d336600461279a565b61121b565b61029a6103e6366004612891565b61137f565b6103f36113bf565b604080519586526020860194909452928401919091526060830152608082015260a00161020a565b61029a610429366004612841565b61140e565b61029a61043c366004612879565b6114b6565b61025e61044f36600461272d565b6001600160a01b03918216600090815260346020908152604080832093909416825291909152205490565b61029a610488366004612818565b6116b2565b6104a061049b366004612879565b611778565b60405161ffff909116815260200161020a565b6060603680546104c290612c37565b80601f01602080910402602001604051908101604052809291908181526020018280546104ee90612c37565b801561053b5780601f106105105761010080835404028352916020019161053b565b820191906000526020600020905b81548152906001019060200180831161051e57829003601f168201915b505050505090505b90565b60006105506117d9565b600101546001600160a01b0316905090565b600061056f3384846117fd565b5060015b92915050565b6040805160048152602481019091526020810180516001600160e01b031663050e823560e21b17905260009081906105b090611922565b9050808060200190518101906105c69190612951565b91505090565b60006105d9848484611942565b6001600160a01b0384166000908152603460209081526040808320338452909152902054828110156106635760405162461bcd60e51b815260206004820152602860248201527f45524332303a207472616e7366657220616d6f756e74206578636565647320616044820152676c6c6f77616e636560c01b60648201526084015b60405180910390fd5b61067785336106728685612bf4565b6117fd565b60019150505b9392505050565b600080516020612cf48339815191523361069e8282611b1a565b6106ba5760405162461bcd60e51b815260040161065a90612a52565b6106c48484611b4e565b50505050565b60006106d46117d9565b6005015460ff16905090565b3360008181526034602090815260408083206001600160a01b0387168452909152812054909161056f918590610672908690612b9d565b6001600160a01b0381166000908152603360205260408120546107419061073c610749565b611bcc565b90505b919050565b600061075460355490565b6107675750670de0b6b3a7640000610543565b603554670de0b6b3a764000061077b6111d7565b6107859190612bd5565b61078f9190612bb5565b905090565b600054610100900460ff16806107ad575060005460ff16155b6107c95760405162461bcd60e51b815260040161065a90612ace565b600054610100900460ff161580156107eb576000805461ffff19166101011790555b333b6108395760405162461bcd60e51b815260206004820152601f60248201527f54656c6c65723a20636f6e74726f6c6c6572206e6f7420636f6e747261637400604482015260640161065a565b813b6108955760405162461bcd60e51b815260206004820152602560248201527f54656c6c65723a20756e6465726c79696e6720746f6b656e206e6f7420636f6e6044820152641d1c9858dd60da1b606482015260840161065a565b6108ad600080516020612cad83398151915233611b4e565b6108c5600080516020612cf483398151915284611b4e565b816108ce6117d9565b80546001600160a01b0319166001600160a01b0392909216919091179055610a406108f76117d9565b54604080516306fdde0360e01b815290516001600160a01b03909216916306fdde0391600480820192600092909190829003018186803b15801561093a57600080fd5b505afa15801561094e573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261097691908101906128b3565b60405160200161098691906129c7565b60405160208183030381529060405261099d6117d9565b54604080516395d89b4160e01b815290516001600160a01b03909216916395d89b4191600480820192600092909190829003018186803b1580156109e057600080fd5b505afa1580156109f4573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610a1c91908101906128b3565b604051602001610a2c91906129f6565b604051602081830303815290604052611beb565b610a486117d9565b546040805163313ce56760e01b815290516001600160a01b039092169163313ce56791600480820192602092909190829003018186803b158015610a8b57600080fd5b505afa158015610a9f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ac3919061298a565b610acb6117d9565b600501805460ff191660ff929092169190911790556001610aea6117d9565b60050180549115156101000261ff00199092169190911790558015610b15576000805461ff00191690555b505050565b6000610b246117d9565b546001600160a01b0316905090565b6040805160048152602481019091526020810180516001600160e01b0316631f5f0a8760e21b179052610b6590611922565b50565b7feba135a74248c737f901cbd8d0f53e729a3f212e734748c2e0d8d39096125e5c60008190527f7b305b6be5f275f648d05716597c483d754c2a242bd605feba3c64fb853605366020527fd51fad483e9bd4fa5dd43c95a6dde60b73fec1248ce54775bb96529d1141aa1b54600080516020612d148339815191529060ff1615610c045760405162461bcd60e51b815260040161065a90612b66565b60008281526002820160205260409020805460ff1916600117905582610c685760405162461bcd60e51b8152602060048201526019602482015278054656c6c65723a2063616e6e6f74207769746864726177203603c1b604482015260640161065a565b610c70610579565b831115610c8f5760405162461bcd60e51b815260040161065a90612b1c565b6000610c99610749565b90506000610ca78583611c6a565b610cb2906001612b9d565b9050610cbd3361030d565b811115610cdc5760405162461bcd60e51b815260040161065a90612a89565b610ce68186611c7f565b5050600091825260020160205260409020805460ff1916905550565b600080516020612cad83398151915233610d1c8282611b1a565b610d385760405162461bcd60e51b815260040161065a90612a52565b83610d416117d9565b6003016000828254610d539190612b9d565b90915550839050610d626117d9565b6004016000828254610d749190612b9d565b9091555050604080518581526020810185905233917fc091ac0b81e7f83b1bd632697aab4fe32a683168ca5ca7ad8075b49c3e669c4a910160405180910390a250505050565b610b658133611d04565b600061067d8383611b1a565b6060603780546104c290612c37565b6000610de96117d9565b60050154610100900460ff161580610e145750610e14600080516020612cad83398151915233611b1a565b610e605760405162461bcd60e51b815260206004820152601b60248201527f54656c6c65723a20706c6174666f726d20726573747269637465640000000000604482015260640161065a565b7ffdf81848136595c31bb5f76217767372bc4bf906663038eb38381131ea27ecba60008190527f7b305b6be5f275f648d05716597c483d754c2a242bd605feba3c64fb853605366020527fa8b4b8db2d6e615394be6b6e7c62c4b724469d7ac9026422a171f9c66a50d83f54600080516020612d148339815191529060ff1615610efc5760405162461bcd60e51b815260040161065a90612b66565b60008281526002820160205260409020805460ff1916600117905583610f5c5760405162461bcd60e51b8152602060048201526015602482015274054656c6c65723a2063616e6e6f74206d696e74203605c1b604482015260640161065a565b610f646117d9565b546001600160a01b03166370a08231336040516001600160e01b031960e084901b1681526001600160a01b03909116600482015260240160206040518083038186803b158015610fb357600080fd5b505afa158015610fc7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610feb9190612951565b84111561103a5760405162461bcd60e51b815260206004820152601f60248201527f54656c6c65723a20696e73756666696369656e7420756e6465726c79696e6700604482015260640161065a565b600061104d85611048610749565b611c6a565b9050600081116110af5760405162461bcd60e51b815260206004820152602760248201527f54656c6c65723a20616d6f756e7420746f206265206d696e7465642063616e6e60448201526606f7420626520360cc1b606482015260840161065a565b6110cc6110ba6117d9565b546001600160a01b0316333088611d80565b6110d63382611deb565b604080518281526020810187905233917f4c209b5fc8ad50758f13e2e1088ba56a560dff690a1c6fef26394f4c03821c4f910160405180910390a29250600091825260020160205260409020805460ff19169055919050565b3360009081526034602090815260408083206001600160a01b0386168452909152812054828110156111b15760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b606482015260840161065a565b6111c033856106728685612bf4565b5060019392505050565b600061056f338484611942565b60006111e1610579565b6111eb9082612b9d565b90506111f56117d9565b600201546112039082612b9d565b905061120d6117d9565b6003015461078f9082612bf4565b600080516020612cf4833981519152336112358282611b1a565b6112515760405162461bcd60e51b815260040161065a90612a52565b6112628563475c5f8560e01b611eca565b6112c85760405162461bcd60e51b815260206004820152603160248201527f54656c6c65723a20737472617465677920646f6573206e6f7420737570706f7260448201527074204954546f6b656e537472617465677960781b606482015260840161065a565b846112d16117d9565b60010180546001600160a01b0319166001600160a01b039290921691909117905582156113395761133784848080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525061192292505050565b505b604080516001600160a01b0387168152905133917f7a587acd0fd101cfe7d6d98bad768e91209a7ae91e55c3702570425bf0eae9bc919081900360200190a25050505050565b600080516020612cf4833981519152336113998282611b1a565b6113b55760405162461bcd60e51b815260040161065a90612a52565b6106c48484611d04565b60008060008060006113cf610579565b94506113d96117d9565b6002015493506113e76117d9565b6003015492506113f56117d9565b6004015491506114058385612bf4565b90509091929394565b600080516020612cf4833981519152336114288282611b1a565b6114445760405162461bcd60e51b815260040161065a90612a52565b8261144d6117d9565b60050180549115156101000261ff001990921691909117905561146d3390565b6001600160a01b03167f9a8a686aa374e3c964e707566deb1d0ef1fda94567495b4767063063de913ff5846040516114a9911515815260200190565b60405180910390a2505050565b7feba135a74248c737f901cbd8d0f53e729a3f212e734748c2e0d8d39096125e5c60008190527f7b305b6be5f275f648d05716597c483d754c2a242bd605feba3c64fb853605366020527fd51fad483e9bd4fa5dd43c95a6dde60b73fec1248ce54775bb96529d1141aa1b54600080516020612d148339815191529060ff16156115525760405162461bcd60e51b815260040161065a90612b66565b60008281526002820160205260409020805460ff19166001179055826115b65760405162461bcd60e51b8152602060048201526019602482015278054656c6c65723a2063616e6e6f74207769746864726177203603c1b604482015260640161065a565b6115bf3361030d565b8311156115de5760405162461bcd60e51b815260040161065a90612a89565b60006115ec8461073c610749565b905060008111611666576040805162461bcd60e51b81526020600482015260248101919091527f54656c6c65723a20756e6465726c79696e672074656c6c657220746f6b656e2060448201527f76616c756520746f2062652072656465656d65642063616e6e6f742062652030606482015260840161065a565b61166e610579565b81111561168d5760405162461bcd60e51b815260040161065a90612b1c565b6116978482611c7f565b50600091825260020160205260409020805460ff1916905550565b600080516020612cad833981519152336116cc8282611b1a565b6116e85760405162461bcd60e51b815260040161065a90612a52565b6040516024810184905261173a90632e1a7d4d60e01b906044015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152611922565b50826117446117d9565b60020160008282546117569190612b9d565b909155506106c490506117676117d9565b546001600160a01b03168585611ee6565b6000806117836117d9565b6003015461178f6117d9565b6002015461179d9190612bf4565b90506000816117aa610579565b6117b49190612b9d565b905080156117d2576117cf6117c98584612b9d565b82611f16565b92505b5050919050565b7ff72b349e2c69862bdc86afd2a363bf16c24bd97d10f7ac9d49f7e2eedebba2b490565b6001600160a01b03831661185f5760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b606482015260840161065a565b6001600160a01b0382166118c05760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b606482015260840161065a565b6001600160a01b0383811660008181526034602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92591015b60405180910390a3505050565b606061074161192f6117d9565b600101546001600160a01b031683611f4b565b6001600160a01b0383166119a65760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b606482015260840161065a565b6001600160a01b038216611a085760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b606482015260840161065a565b6001600160a01b03831660009081526033602052604090205481811015611a805760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b606482015260840161065a565b611a8a8282612bf4565b6001600160a01b038086166000908152603360205260408082209390935590851681529081208054849290611ac0908490612b9d565b92505081905550826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef84604051611b0c91815260200190565b60405180910390a350505050565b6000611b24611f70565b6000938452602090815260408085206001600160a01b039490941685529290525090205460ff1690565b611b588282611b1a565b15611b6257611bc8565b6001611b6c611f70565b6000848152602091825260408082206001600160a01b0386168084529352808220805460ff1916941515949094179093559151339285917f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d9190a45b5050565b6000670de0b6b3a7640000611be18385612bd5565b61067d9190612bb5565b600054610100900460ff1680611c04575060005460ff16155b611c205760405162461bcd60e51b815260040161065a90612ace565b600054610100900460ff16158015611c42576000805461ffff19166101011790555b611c4a611f86565b611c548383611ff1565b8015610b15576000805461ff0019169055505050565b600081611be1670de0b6b3a764000085612bd5565b611c893383612086565b60405160248101829052611ca890632e1a7d4d60e01b90604401611703565b50611cc5611cb46117d9565b546001600160a01b03163383611ee6565b604080518381526020810183905233917fe5b754fb1abb7f01b499791d0b820ae3b6af3424ac1c59768edb53f4ec31a929910160405180910390a25050565b611d0e8282611b1a565b611d1757611bc8565b6000611d21611f70565b6000848152602091825260408082206001600160a01b0386168084529352808220805460ff1916941515949094179093559151339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b6040516001600160a01b03808516602483015283166044820152606481018290526106c49085906323b872dd60e01b906084015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b0319909316929092179091526121d5565b6001600160a01b038216611e415760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604482015260640161065a565b8060356000828254611e539190612b9d565b90915550506001600160a01b03821660009081526033602052604081208054839290611e80908490612b9d565b90915550506040518181526001600160a01b038316906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a35050565b6000611ed5836122a7565b801561067d575061067d83836122da565b6040516001600160a01b038316602482015260448101829052610b1590849063a9059cbb60e01b90606401611db4565b60008115611f4257611f3d82611f2e61271086612bd5565b611f389190612bb5565b6123c3565b61067d565b50600092915050565b606061067d8383604051806060016040528060278152602001612ccd6027913961242a565b6000600080516020612d1483398151915261078f565b600054610100900460ff1680611f9f575060005460ff16155b611fbb5760405162461bcd60e51b815260040161065a90612ace565b600054610100900460ff16158015611fdd576000805461ffff19166101011790555b8015610b65576000805461ff001916905550565b600054610100900460ff168061200a575060005460ff16155b6120265760405162461bcd60e51b815260040161065a90612ace565b600054610100900460ff16158015612048576000805461ffff19166101011790555b825161205b90603690602086019061266c565b50815161206f90603790602085019061266c565b508015610b15576000805461ff0019169055505050565b6001600160a01b0382166120e65760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b606482015260840161065a565b6001600160a01b0382166000908152603360205260409020548181101561215a5760405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e604482015261636560f01b606482015260840161065a565b6121648282612bf4565b6001600160a01b03841660009081526033602052604081209190915560358054849290612192908490612bf4565b90915550506040518281526000906001600160a01b038516907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef90602001611915565b600061222a826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166124f49092919063ffffffff16565b805190915015610b155780806020019051810190612248919061285d565b610b155760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b606482015260840161065a565b60006122ba826301ffc9a760e01b6122da565b801561074157506122d3826001600160e01b03196122da565b1592915050565b604080516001600160e01b0319831660248083019190915282518083039091018152604490910182526020810180516001600160e01b03166301ffc9a760e01b179052905160009190829081906001600160a01b03871690617530906123419086906129ab565b6000604051808303818686fa925050503d806000811461237d576040519150601f19603f3d011682016040523d82523d6000602084013e612382565b606091505b509150915060208151101561239d5760009350505050610573565b8180156123b95750808060200190518101906123b9919061285d565b9695505050505050565b60006201000082106124265760405162461bcd60e51b815260206004820152602660248201527f53616665436173743a2076616c756520646f65736e27742066697420696e203160448201526536206269747360d01b606482015260840161065a565b5090565b6060833b6124895760405162461bcd60e51b815260206004820152602660248201527f416464726573733a2064656c65676174652063616c6c20746f206e6f6e2d636f6044820152651b9d1c9858dd60d21b606482015260840161065a565b600080856001600160a01b0316856040516124a491906129ab565b600060405180830381855af49150503d80600081146124df576040519150601f19603f3d011682016040523d82523d6000602084013e6124e4565b606091505b50915091506123b982828661250b565b60606125038484600085612544565b949350505050565b6060831561251a57508161067d565b82511561252a5782518084602001fd5b8160405162461bcd60e51b815260040161065a9190612a1f565b6060824710156125a55760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b606482015260840161065a565b843b6125f35760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015260640161065a565b600080866001600160a01b0316858760405161260f91906129ab565b60006040518083038185875af1925050503d806000811461264c576040519150601f19603f3d011682016040523d82523d6000602084013e612651565b606091505b509150915061266182828661250b565b979650505050505050565b82805461267890612c37565b90600052602060002090601f01602090048101928261269a57600085556126e0565b82601f106126b357805160ff19168380011785556126e0565b828001600101855582156126e0579182015b828111156126e05782518255916020019190600101906126c5565b506124269291505b8082111561242657600081556001016126e8565b80356001600160a01b038116811461074457600080fd5b600060208284031215612724578081fd5b61067d826126fc565b6000806040838503121561273f578081fd5b612748836126fc565b9150612756602084016126fc565b90509250929050565b600080600060608486031215612773578081fd5b61277c846126fc565b925061278a602085016126fc565b9150604084013590509250925092565b6000806000604084860312156127ae578283fd5b6127b7846126fc565b9250602084013567ffffffffffffffff808211156127d3578384fd5b818601915086601f8301126127e6578384fd5b8135818111156127f4578485fd5b876020828501011115612805578485fd5b6020830194508093505050509250925092565b6000806040838503121561282a578182fd5b612833836126fc565b946020939093013593505050565b600060208284031215612852578081fd5b813561067d81612c9e565b60006020828403121561286e578081fd5b815161067d81612c9e565b60006020828403121561288a578081fd5b5035919050565b600080604083850312156128a3578182fd5b82359150612756602084016126fc565b6000602082840312156128c4578081fd5b815167ffffffffffffffff808211156128db578283fd5b818401915084601f8301126128ee578283fd5b81518181111561290057612900612c88565b604051601f8201601f19908116603f0116810190838211818310171561292857612928612c88565b81604052828152876020848701011115612940578586fd5b612661836020830160208801612c0b565b600060208284031215612962578081fd5b5051919050565b6000806040838503121561297b578182fd5b50508035926020909101359150565b60006020828403121561299b578081fd5b815160ff8116811461067d578182fd5b600082516129bd818460208701612c0b565b9190910192915050565b60006602a32b63632b9160cd1b825282516129e9816007850160208701612c0b565b9190910160070192915050565b6000601d60fa1b82528251612a12816001850160208701612c0b565b9190910160010192915050565b6000602082528251806020840152612a3e816040850160208701612c0b565b601f01601f19169190910160400192915050565b6020808252601d908201527f416363657373436f6e74726f6c3a206e6f7420617574686f72697a6564000000604082015260600190565b60208082526025908201527f54656c6c65723a2072656465656d20616d6f756e7420657863656564732062616040820152646c616e636560d81b606082015260800190565b6020808252602e908201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160408201526d191e481a5b9a5d1a585b1a5e995960921b606082015260800190565b6020808252602a908201527f54656c6c65723a2072656465656d2074746f6b656e206c70206e6f7420656e6f60408201526975676820737570706c7960b01b606082015260800190565b60208082526018908201527f416363657373436f6e74726f6c3a207265656e74657265640000000000000000604082015260600190565b60008219821115612bb057612bb0612c72565b500190565b600082612bd057634e487b7160e01b81526012600452602481fd5b500490565b6000816000190483118215151615612bef57612bef612c72565b500290565b600082821015612c0657612c06612c72565b500390565b60005b83811015612c26578181015183820152602001612c0e565b838111156106c45750506000910152565b600181811c90821680612c4b57607f821691505b60208210811415612c6c57634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052604160045260246000fd5b8015158114610b6557600080fdfe70546d1c92f8c2132ae23a23f5177aa8526356051c7510df99f50e012d221529416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564df8b4c520ffe197c5343c6f5aec59570151ef9a492f2c624fd45ddde6135ec427b305b6be5f275f648d05716597c483d754c2a242bd605feba3c64fb85360534a2646970667358221220b09a90bc661fa01672b3292fd4d777f6dabf002386935b8598c22fd89920097c64736f6c63430008030033

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

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