Address Details
contract

0x4C301d7E8b766276C361e80B273080561546FF02

Contract Name
BasketService
Creator
0x07ff8b–54f774 at 0xe06454–36ef5d
Balance
0 CELO ( )
Locked CELO Balance
0.00 CELO
Voting CELO Balance
0.00 CELO
Pending Unlocked Gold
0.00 CELO
Tokens
Fetching tokens...
Transactions
851 Transactions
Transfers
280 Transfers
Gas Used
99,812,618
Last Balance Update
14529616
This contract has been verified via Sourcify. View contract in Sourcify repository
Contract name:
BasketService




Optimization enabled
false
Compiler version
v0.8.13+commit.abaa5c0e




EVM Version
london




Verified at
2022-08-22T12:36:54.311683Z

contracts/v5/BasketService.sol

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

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "./ExchangeRateService.sol";
import "./Nylon.sol";

/**
 * @dev Implementation of the basket service smart contract.
 *
 * The {BaskeService} smart contract receives cryptocurrencies and in exchange will trigger
 * the minting process of Nylon. The value of a Nylon is determined by the value of
 * the cryptocurrencies held by the contract.
 *
 * It inherits from the Ownable interfaces of the openzeppelin contracts collection.
 *
 * Ownable means that someone "owns" the BasketService. This may be a person or an other smart
 * contract.
 *
 * NOTE: For now, the basket service can only hold cUSD and cEUR.
 */
contract BasketService is Ownable {
    using SafeERC20 for IERC20;
    using SafeERC20 for Nylon;

    // ERC20-tokens: cUSD and cEUR
    IERC20 private immutable cUSD;
    IERC20 private immutable cEUR;

    // the Nylon
    Nylon private immutable nylon;

    // the exchange rate service
    ExchangeRateService public exchange;

    /**
     * @dev The {NylonTransferred} event is emitted once Nylon are minted.
     */
    event NylonTransferred(address indexed _to, uint256 _amount);

    /**
     * @dev The {NylonRemoved} event is emitted once Nylon are burnt.
     */
    event NylonRemoved(address indexed _from, uint256 _amount);

    /**
     * @dev Constructor of the basket service.
     *
     * Requirements:
     * - the address of the Nylon.
     */
    constructor(address _nylon) {
        address _cUSD = 0x874069Fa1Eb16D44d622F2e0Ca25eeA172369bC1;
        address _cEUR = 0x10c892A6EC43a53E45D0B916B4b7D383B1b78C0F;

        // init of the Nylon
        nylon = Nylon(_nylon);
        // erc20-token cUSD (https://alfajores-blockscout.celo-testnet.org/token/0x874069Fa1Eb16D44d622F2e0Ca25eeA172369bC1)
        cUSD = IERC20(_cUSD);
        // erc20-token cEUR (https://alfajores-blockscout.celo-testnet.org/token/0x10c892A6EC43a53E45D0B916B4b7D383B1b78C0F)
        cEUR = IERC20(_cEUR);
    }

    /**
     * @dev The objective of the function is to improve legibility.
     * It returns the address of the basket service.
     *
     * {_basket} is only used for internal purposes.
     */
    function _basket() internal view virtual returns (address) {
        return address(this);
    }

    /**
     * @dev  {_basketEvaluation} returns a number of variables needed for the computation of {sellNylon}.
     *
     * Returns:
     * - `nylonTtlSupply`, total supply of Nylon in circulation
     * - `cUSDBasketBalance`, cUSD balance of the basket
     * - `cEURBasketBalance`, cEUR balance of the basket
     */
    function _basketEvaluation()
        internal
        view
        virtual
        returns (
            uint256 nylonTtlSupply,
            uint256 cUSDBasketBalance,
            uint256 cEURBasketBalance
        )
    {
        nylonTtlSupply = nylon.totalSupply();

        cUSDBasketBalance = cUSD.balanceOf(_basket());
        cEURBasketBalance = cEUR.balanceOf(_basket());
    }

    /**
     * @dev  Setter function for the external exchange rate service.
     *
     * Requirements:
     * - the address of the exchange rate service.
     *
     * NOTE: This function is only callable by the owner.
     */
    function setExchangeRateService(address _exchangeRateService)
        external
        onlyOwner
    {
        exchange = ExchangeRateService(_exchangeRateService);
    }

    /**
     * @dev Nylon can be bought by x-amount. These nylon are directly minted to
     * the sender address.
     *
     * Prerequisites:
     * - allowance of the cUSD must match the current Nylon value returned by the exchange rate service.
     * - allowance of the cEUR must match the current Nylon value returned by the exchange rate service.
     *
     * Requirements:
     * - '_amount', requested amount of Nylon (must be at least 0.001).
     */
    function buyNylon(uint256 _amount) external returns (bool) {
        (uint256 cUSDAmount, uint256 cEURAmount) = exchange._nylonValue(
            _amount
        );

        require(
            _amount >= 10**15,
            "Exchanged amount needs to be at least 0.001!"
        );
        require(
            cUSD.allowance(_msgSender(), _basket()) >= cUSDAmount &&
                cEUR.allowance(_msgSender(), _basket()) >= cEURAmount,
            "Approve cUSD and cEUR tokens first!"
        );

        cUSD.safeTransferFrom(_msgSender(), _basket(), cUSDAmount);
        cEUR.safeTransferFrom(_msgSender(), _basket(), cEURAmount);

        nylon.increaseSupply(_msgSender(), _amount);

        emit NylonTransferred(_msgSender(), _amount);

        return true;
    }

    /**
     * @dev Nylon can be sold by x-amount. These nylon are directly burnt from
     * the sender address.
     *
     * Prerequisites:
     * - Nylon balance must be equal or above the desired sold amount.
     *
     * Requirements:
     * - '_amount', requested amount of Nylon (must be at least 0.001).
     */
    function sellNylon(uint256 _amount) external returns (bool) {
        require(
            nylon.balanceOf(_msgSender()) >= _amount,
            "Nylon balance of sender is insufficient!"
        );

        (
            uint256 nylonTtlSupply,
            uint256 cUSDBasketBalance,
            uint256 cEURBasketBalance
        ) = _basketEvaluation();

        uint256 cUSDAmount = SafeMath.div(
            cUSDBasketBalance * _amount,
            nylonTtlSupply
        );

        uint256 cEURAmount = SafeMath.div(
            cEURBasketBalance * _amount,
            nylonTtlSupply
        );

        nylon.decreaseSupply(_msgSender(), _amount);

        cUSD.safeTransfer(_msgSender(), cUSDAmount);
        cEUR.safeTransfer(_msgSender(), cEURAmount);

        emit NylonRemoved(_msgSender(), _amount);

        return true;
    }
}
        

/_openzeppelin/contracts/access/Ownable.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/Ownable.sol)

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

/_openzeppelin/contracts/token/ERC20/ERC20.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/ERC20.sol)

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 Contracts guidelines: functions revert
 * instead returning `false` on failure. This behavior is nonetheless
 * conventional and does not conflict with the expectations of ERC20
 * applications.
 *
 * Additionally, an {Approval} event is emitted on calls to {transferFrom}.
 * This allows applications to reconstruct the allowance for all accounts just
 * by listening to said events. Other implementations of the EIP may not emit
 * these events, as it isn't required by the specification.
 *
 * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
 * functions have been added to mitigate the well-known issues around setting
 * allowances. See {IERC20-approve}.
 */
contract ERC20 is Context, IERC20, IERC20Metadata {
    mapping(address => uint256) private _balances;

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

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;

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

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

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

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

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

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

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

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

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

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

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

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

        return true;
    }

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

        _beforeTokenTransfer(from, to, amount);

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

        emit Transfer(from, to, amount);

        _afterTokenTransfer(from, to, amount);
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

/_openzeppelin/contracts/token/ERC20/IERC20.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

/_openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)

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

/_openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/utils/SafeERC20.sol)

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'
        require(
            (value == 0) || (token.allowance(address(this), spender) == 0),
            "SafeERC20: approve from non-zero to non-zero allowance"
        );
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
    }

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

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

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

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

/_openzeppelin/contracts/utils/Address.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (utils/Address.sol)

pragma solidity ^0.8.1;

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

        return account.code.length > 0;
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

/_openzeppelin/contracts/utils/Context.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;

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

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

/_openzeppelin/contracts/utils/math/SafeMath.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (utils/math/SafeMath.sol)

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

/ado-contracts/contracts/interfaces/IERC2362.sol

// SPDX-License-Identifier: MIT

pragma solidity >=0.5.0 <0.9.0;

/**
* @dev EIP2362 Interface for pull oracles
* https://github.com/adoracles/EIPs/blob/erc-2362/EIPS/eip-2362.md
*/
interface IERC2362
{
	/**
	 * @dev Exposed function pertaining to EIP standards
	 * @param _id bytes32 ID of the query
	 * @return int,uint,uint returns the value, timestamp, and status code of query
	 */
	function valueFor(bytes32 _id) external view returns(int256,uint256,uint256);
}
          

/contracts/PriceChecker.sol

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

import "@openzeppelin/contracts/utils/math/SafeMath.sol";

/**
 * @dev Implementation of the PriceChecker library
 *
 * The library offers additional functionality to run computations, not befitting any
 * specific smart contracts.
 *
 * It currently only supports the {valueOf} function.
 */
library PriceChecker {
    using SafeMath for uint256;

    modifier notNull(uint256 _value, string memory _parameterName) {
        require(
            _value > 0,
            string.concat(_parameterName, " needs to be above 0!")
        );
        _;
    }

    /**
     * @dev Evaluates the value of a coin by a given Witnet price feed.
     *
     * Solidity doesn't support floats. The {valueOf} offers a solution to the problem by
     * determining a quotient and a rest, which are then added to form a result.
     * The 18 last digits represent the rest and everything above is equal to the quotient.
     *
     * For example, `2.513` would be `2513000000000000000`.
     *
     * The Witnet price feed service returns a value where the last 6 digits represent the
     * rest (precision of 6 decimals). Thus, the function must normalise the returned price
     * by a factor of 12 to ensure correct computations.
     * See {https://docs.witnet.io/smart-contracts/witnet-data-feeds/using-witnet-data-feeds}
     * for more information.
     *
     * Requirements:
     *
     * - `price`, returned by the Witnet oracle price feed service.
     *
     * Returns:
     * - `quotient`
     * - `rest`
     * - `result`
     */
    function valueOf(uint256 _amount, uint256 _price)
        internal
        pure
        notNull(_price, "Price")
        returns (
            uint256 quotient,
            uint256 rest,
            uint256 result
        )
    {
        uint256 factor = 10**18;
        uint256 normalisedPrice = SafeMath.mul(_price, 10**12);

        quotient = _amount.div(normalisedPrice);
        rest = ((_amount * factor) / normalisedPrice) % factor;

        bool rounding = 2 * ((_amount * factor) % normalisedPrice) >= normalisedPrice;

                if (rounding) {
            rest += 1;
        }
        result = quotient.mul(factor) + rest;
    }

    /**
     * @dev Evaluates the percentage value of a coin by a given amount.
     *
     * Solidity doesn't support floats. The {percentageValue} offers a solution to the problem by
     * determining a percentage by a given factor. The input amount is then multiplied by the
     * percentage and followed by a division of the same factor.
     *
     * For example, if there are `2` tokens and the amount equals `2*10**18` on the exchange then the
     * percentage would be `50000000000000000` (or 5*10*17) and the result would be `1*10*18`.
     *
     * Requirements:
     *
     * - `tokensOnExchange`, found on the exchange service.
     *
     * Returns:
     * - `result`
     */
    function percentageValue(uint256 _amount, uint256 _tokensOnExchange)
        internal
        pure
        notNull(_tokensOnExchange, "Amount of tokens")
        returns (uint256 result)
    {
        uint256 factor = 10**18;
        uint256 percentage = factor.div(_tokensOnExchange);

        result = SafeMath.div(_amount.mul(percentage), factor);
    }

    /**
     * @dev Evaluates the exchange rate of two variables.
     *
     * Solidity doesn't support floats. The {evaluateRate} function uses a factor of 10**6 for
     * its computation.
     * NOTE: The factor is the same as the one used by the Witnet price feed service.
     * The {evaluateRate} may be used in cominbation with {valueOf}.
     *
     * Requirements:
     *
     * - `from`, first parameter (e.g. an exchange rate)
     * - `to`, second parameter (e.g. an exchange rate)
     *
     * Example: CELO/EUR 1:1 (-> first parameter) and CELO/USD 2:1 (-> second parameter) will
     * have as a result USD/EUR = 2:1
     *
     * Returns:
     * - `result`
     */
    function evaluateRate(uint256 _from, uint256 _to)
        internal
        pure
        notNull(_from, "Exchange rate from")
        notNull(_to, "Exchange rate to")
        returns (uint256 result)
    {
        uint256 factor = 10**6;

        uint256 from = _from.mul(factor);

        result = from.div(_to);
    }

    function evaluatePrice(
        uint256 _a,
        uint256 _b,
        uint256 _ttlSupply
    )
        internal
        pure
        notNull(_ttlSupply, "Total supply")
        returns (uint256 result)
    {
        uint256 factor = 10**18;

        uint256 value = factor.mul(_a.add(_b));
        result = value.div(_ttlSupply);
    }
}
          

/contracts/v5/ExchangeRateService.sol

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

import "witnet-solidity-bridge/contracts/interfaces/IWitnetPriceRouter.sol";
import "witnet-solidity-bridge/contracts/interfaces/IWitnetPriceFeed.sol";

import "@openzeppelin/contracts/utils/math/SafeMath.sol";

import "../PriceChecker.sol";

/**
 * @dev Implementation of the exchange rate service smart contract.
 */

contract ExchangeRateService {
    using PriceChecker for uint256;

    // IWitnetPriceRouter
    // see {https://docs.witnet.io/smart-contracts/witnet-data-feeds/addresses/celo}
    IWitnetPriceRouter public immutable witnetPriceRouter;

    // IWitnetPriceFeeds: CELO/USD and CELO/EUR
    IWitnetPriceFeed private celoUsd;
    IWitnetPriceFeed private celoEur;

    /**
     * @dev Constructor of the exchange service.
     * The Witnet price router and the required price feeds are initialized.
     *
     * Requirements:
     * - the address of the price router.
     */
    constructor(address _priceRouter) {
        witnetPriceRouter = IWitnetPriceRouter(_priceRouter);

        // price feeds (https://docs.witnet.io/smart-contracts/witnet-data-feeds/price-feeds-registry)
        celoUsd = addPriceFeed(0x9ed884be);
        celoEur = addPriceFeed(0x21a79821);
    }

    /**
     * @dev Helper function which allows to get a price feed corresponding to the erc2362 id.
     *
     * Requirements:
     * - the erc2362 id of the price feed, see {https://docs.witnet.io/smart-contracts/witnet-data-feeds/addresses/celo}.
     */
    function addPriceFeed(bytes4 _erc2362id)
        internal
        view
        virtual
        returns (IWitnetPriceFeed priceFeed)
    {
        IERC165 erc165 = witnetPriceRouter.getPriceFeed(bytes4(_erc2362id));

        require(
            address(erc165) != address(0),
            "Failed to add price feed. Price feed address is invalid!"
        );

        priceFeed = IWitnetPriceFeed(address(erc165));
    }

    /**
     * @dev Evaluates the current exchange rate of the cUSD to the cEUR by dividing
     * the CELO/EUR-price with the CELO/USD-price.
     *
     * Returns:
     * - `usdEurRate`, exchange rate of USD/EUR
     */
    function _usdEurRate() public view returns (uint256 usdEurRate) {
        uint256 celoEurLastPrice = uint256(celoEur.lastPrice());
        uint256 celoUsdLastPrice = uint256(celoUsd.lastPrice());

        usdEurRate = celoEurLastPrice.evaluateRate(celoUsdLastPrice);
    }

    /**
     * @dev Evaluates the value of x-amount of Nylon.
     *
     * Requirements:
     * - '_amount', requested amount of Nylon.

     * Returns:
     * - `cUSDAmount`, amount of cUSD needed for x-amount of Nylon
     * - `cEURAmount`, amount of cEUR needed for x-amount of Nylon
     */
    function _nylonValue(uint256 _amount)
        public
        view
        returns (uint256 cUSDAmount, uint256 cEURAmount)
    {
        uint256 usdEurRate = _usdEurRate();

        uint256 factor = 10**6;

        uint256 divisor = usdEurRate + factor;

        (, , uint256 cUSDPerUnit) = factor.valueOf(divisor);
        (, , uint256 cEURPerUnit) = usdEurRate.valueOf(divisor);

        cUSDAmount = SafeMath.mul(_amount, cUSDPerUnit) / factor;
        cEURAmount = SafeMath.mul(_amount, cEURPerUnit) / factor;
    }
}
          

/contracts/v5/Nylon.sol

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

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

/**
 * @dev Implementation of the Nylon ERC20 Token.
 *
 * It inherits from the ERC20 and Ownable interface of the openzeppelin
 * contracts collection.
 *
 * Ownable means that someone "owns" the Nylon. This may be a person or an other smart
 * contract.
 */
contract Nylon is ERC20, Ownable {
    /**
     * Token-name: Nylon
     * Token-symbol: nylon
     */
    constructor() ERC20("Nylon", "nylon") {}

    /**
     * @dev Nylon can be increased by x-amount.
     *
     * {increaseSupply} is only callable by the the contract owner.
     *
     * Requirements:
     *
     * - `_to`, address to which the Nylon are minted.
     * - `_amount`, amount of Nylon minted.
     *
     * NOTE: To ensure that this function cannot be called by a person, the ownership
     * should be transferred to the address of an other contract.
     * See {BasketService}.
     */
    function increaseSupply(address _to, uint256 _amount)
        external
        onlyOwner
        returns (bool)
    {
        _mint(_to, _amount);
        return true;
    }

    /**
     * @dev Nylon can be decreased by x-amount.
     *
     * {decreaseSupply} is only callable by the the contract owner.
     *
     * Requirements:
     *
     * - `_from`, address from which the Nylon are burnt.
     * - `_amount`, amount of Nylon burnt.
     *
     * NOTE: To ensure that this function cannot be called by a person, the ownership
     * should be transferred to the address of an other contract.
     * See {BasketService}.
     */
    function decreaseSupply(address _from, uint256 _amount)
        external
        onlyOwner
        returns (bool)
    {
        _burn(_from, _amount);
        return true;
    }
}
          

/witnet-solidity-bridge/contracts/WitnetRequestBoard.sol

// SPDX-License-Identifier: MIT

pragma solidity >=0.7.0 <0.9.0;
pragma experimental ABIEncoderV2;

import "./interfaces/IWitnetRequestBoardEvents.sol";
import "./interfaces/IWitnetRequestBoardReporter.sol";
import "./interfaces/IWitnetRequestBoardRequestor.sol";
import "./interfaces/IWitnetRequestBoardView.sol";
import "./interfaces/IWitnetRequestParser.sol";

/// @title Witnet Request Board functionality base contract.
/// @author The Witnet Foundation.
abstract contract WitnetRequestBoard is
    IWitnetRequestBoardEvents,
    IWitnetRequestBoardReporter,
    IWitnetRequestBoardRequestor,
    IWitnetRequestBoardView,
    IWitnetRequestParser
{
    receive() external payable {
        revert("WitnetRequestBoard: no transfers accepted");
    }
}
          

/witnet-solidity-bridge/contracts/interfaces/IERC165.sol

// SPDX-License-Identifier: MIT

pragma solidity >=0.7.0 <0.9.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);
}
          

/witnet-solidity-bridge/contracts/interfaces/IWitnetPriceFeed.sol

// SPDX-License-Identifier: MIT
pragma solidity >=0.7.0 <0.9.0;
pragma experimental ABIEncoderV2;

import "../WitnetRequestBoard.sol";

/// @title The Witnet Price Feed basic interface.
/// @dev Guides implementation of active price feed polling contracts.
/// @author The Witnet Foundation.

interface IWitnetPriceFeed {

    /// Signals that a new price update request is being posted to the Witnet Request Board
    event PriceFeeding(address indexed from, uint256 queryId, uint256 extraFee);

    /// Estimates minimum fee amount in native currency to be paid when 
    /// requesting a new price update.
    /// @dev Actual fee depends on the gas price of the `requestUpdate()` transaction.
    /// @param _gasPrice Gas price expected to be paid when calling `requestUpdate()`
    function estimateUpdateFee(uint256 _gasPrice) external view returns (uint256);

    /// Returns result of the last valid price update request successfully solved by the Witnet oracle.
    function lastPrice() external view returns (int256);

    /// Returns the EVM-timestamp when last valid price was reported back from the Witnet oracle.
    function lastTimestamp() external view returns (uint256);    

    /// Returns tuple containing last valid price and timestamp, as well as status code of latest update
    /// request that got posted to the Witnet Request Board.
    /// @return _lastPrice Last valid price reported back from the Witnet oracle.
    /// @return _lastTimestamp EVM-timestamp of the last valid price.
    /// @return _lastDrTxHash Hash of the Witnet Data Request that solved the last valid price.
    /// @return _latestUpdateStatus Status code of the latest update request.
    function lastValue() external view returns (
        int _lastPrice,
        uint _lastTimestamp,
        bytes32 _lastDrTxHash,
        uint _latestUpdateStatus
    );

    /// Returns identifier of the latest update request posted to the Witnet Request Board.
    function latestQueryId() external view returns (uint256);

    /// Returns hash of the Witnet Data Request that solved the latest update request.
    /// @dev Returning 0 while the latest update request remains unsolved.
    function latestUpdateDrTxHash() external view returns (bytes32);

    /// Returns error message of latest update request posted to the Witnet Request Board.
    /// @dev Returning empty string if the latest update request remains unsolved, or
    /// @dev if it was succesfully solved with no errors.
    function latestUpdateErrorMessage() external view returns (string memory);

    /// Returns status code of latest update request posted to the Witnet Request Board:
    /// @dev Status codes:
    /// @dev   - 200: update request was succesfully solved with no errors
    /// @dev   - 400: update request was solved with errors
    /// @dev   - 404: update request was not solved yet 
    function latestUpdateStatus() external view returns (uint256);

    /// Returns `true` if latest update request posted to the Witnet Request Board 
    /// has not been solved yet by the Witnet oracle.
    function pendingUpdate() external view returns (bool);

    /// Posts a new price update request to the Witnet Request Board. Requires payment of a fee
    /// that depends on the value of `tx.gasprice`. See `estimateUpdateFee(uint256)`.
    /// @dev If previous update request was not solved yet, calling this method again allows
    /// @dev upgrading the update fee if called with a higher `tx.gasprice` value.
    function requestUpdate() external payable;

    /// Tells whether this contract implements the interface defined by `interfaceId`. 
    /// @dev See the corresponding https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
    /// @dev to learn more about how these ids are created.
    function supportsInterface(bytes4) external view returns (bool);
}
          

/witnet-solidity-bridge/contracts/interfaces/IWitnetPriceRouter.sol

// SPDX-License-Identifier: MIT
pragma solidity >=0.7.0 <0.9.0;
pragma experimental ABIEncoderV2;

import "ado-contracts/contracts/interfaces/IERC2362.sol";
import "./IERC165.sol";

/// @title The Witnet Price Router basic interface.
/// @dev Guides implementation of price feeds aggregation contracts.
/// @author The Witnet Foundation.
abstract contract IWitnetPriceRouter
    is
        IERC2362 
{
    /// Emitted everytime a currency pair is attached to a new price feed contract
    /// @dev See https://github.com/adoracles/ADOIPs/blob/main/adoip-0010.md 
    /// @dev to learn how these ids are created.
    event CurrencyPairSet(bytes32 indexed erc2362ID, IERC165 pricefeed);

    /// Helper pure function: returns hash of the provided ERC2362-compliant currency pair caption (aka ID).
    function currencyPairId(string memory) external pure virtual returns (bytes32);

    /// Returns the ERC-165-compliant price feed contract currently serving 
    /// updates on the given currency pair.
    function getPriceFeed(bytes32 _erc2362id) external view virtual returns (IERC165);

    /// Returns human-readable ERC2362-based caption of the currency pair being
    /// served by the given price feed contract address. 
    /// @dev Should fail if the given price feed contract address is not currently
    /// @dev registered in the router.
    function getPriceFeedCaption(IERC165) external view virtual returns (string memory);

    /// Returns human-readable caption of the ERC2362-based currency pair identifier, if known.
    function lookupERC2362ID(bytes32 _erc2362id) external view virtual returns (string memory);

    /// Register a price feed contract that will serve updates for the given currency pair.
    /// @dev Setting zero address to a currency pair implies that it will not be served any longer.
    /// @dev Otherwise, should fail if the price feed contract does not support the `IWitnetPriceFeed` interface,
    /// @dev or if given price feed is already serving another currency pair (within this WitnetPriceRouter instance).
    function setPriceFeed(
            IERC165 _pricefeed,
            uint256 _decimals,
            string calldata _base,
            string calldata _quote
        )
        external virtual;

    /// Returns list of known currency pairs IDs.
    function supportedCurrencyPairs() external view virtual returns (bytes32[] memory);

    /// Returns `true` if given pair is currently being served by a compliant price feed contract.
    function supportsCurrencyPair(bytes32 _erc2362id) external view virtual returns (bool);

    /// Returns `true` if given price feed contract is currently serving updates to any known currency pair. 
    function supportsPriceFeed(IERC165 _priceFeed) external view virtual returns (bool);
}
          

/witnet-solidity-bridge/contracts/interfaces/IWitnetRequest.sol

// SPDX-License-Identifier: MIT

pragma solidity >=0.7.0 <0.9.0;

/// @title The Witnet Data Request basic interface.
/// @author The Witnet Foundation.
interface IWitnetRequest {
    /// A `IWitnetRequest` is constructed around a `bytes` value containing 
    /// a well-formed Witnet Data Request using Protocol Buffers.
    function bytecode() external view returns (bytes memory);

    /// Returns SHA256 hash of Witnet Data Request as CBOR-encoded bytes.
    function hash() external view returns (bytes32);
}
          

/witnet-solidity-bridge/contracts/interfaces/IWitnetRequestBoardEvents.sol

// SPDX-License-Identifier: MIT

pragma solidity >=0.7.0 <0.9.0;

/// @title Witnet Request Board emitting events interface.
/// @author The Witnet Foundation.
interface IWitnetRequestBoardEvents {
    /// Emitted when a Witnet Data Request is posted to the WRB.
    event PostedRequest(uint256 queryId, address from);

    /// Emitted when a Witnet-solved result is reported to the WRB.
    event PostedResult(uint256 queryId, address from);

    /// Emitted when all data related to given query is deleted from the WRB.
    event DeletedQuery(uint256 queryId, address from);
}
          

/witnet-solidity-bridge/contracts/interfaces/IWitnetRequestBoardReporter.sol

// SPDX-License-Identifier: MIT

pragma solidity >=0.7.0 <0.9.0;

/// @title The Witnet Request Board Reporter interface.
/// @author The Witnet Foundation.
interface IWitnetRequestBoardReporter {
    /// Reports the Witnet-provided result to a previously posted request. 
    /// @dev Will assume `block.timestamp` as the timestamp at which the request was solved.
    /// @dev Fails if:
    /// @dev - the `_queryId` is not in 'Posted' status.
    /// @dev - provided `_drTxHash` is zero;
    /// @dev - length of provided `_result` is zero.
    /// @param _queryId The unique identifier of the data request.
    /// @param _drTxHash The hash of the solving tally transaction in Witnet.
    /// @param _result The result itself as bytes.
    function reportResult(uint256 _queryId, bytes32 _drTxHash, bytes calldata _result) external;

    /// Reports the Witnet-provided result to a previously posted request.
    /// @dev Fails if:
    /// @dev - called from unauthorized address;
    /// @dev - the `_queryId` is not in 'Posted' status.
    /// @dev - provided `_drTxHash` is zero;
    /// @dev - length of provided `_result` is zero.
    /// @param _queryId The unique query identifier
    /// @param _timestamp The timestamp of the solving tally transaction in Witnet.
    /// @param _drTxHash The hash of the solving tally transaction in Witnet.
    /// @param _result The result itself as bytes.
    function reportResult(uint256 _queryId, uint256 _timestamp, bytes32 _drTxHash, bytes calldata _result) external;
}
          

/witnet-solidity-bridge/contracts/interfaces/IWitnetRequestBoardRequestor.sol

// SPDX-License-Identifier: MIT

pragma solidity >=0.7.0 <0.9.0;
pragma experimental ABIEncoderV2;

import "../libs/Witnet.sol";

/// @title Witnet Requestor Interface
/// @notice It defines how to interact with the Witnet Request Board in order to:
///   - request the execution of Witnet Radon scripts (data request);
///   - upgrade the resolution reward of any previously posted request, in case gas price raises in mainnet;
///   - read the result of any previously posted request, eventually reported by the Witnet DON.
///   - remove from storage all data related to past and solved data requests, and results.
/// @author The Witnet Foundation.
interface IWitnetRequestBoardRequestor {
    /// Retrieves a copy of all Witnet-provided data related to a previously posted request, removing the whole query from the WRB storage.
    /// @dev Fails if the `_queryId` is not in 'Reported' status, or called from an address different to
    /// @dev the one that actually posted the given request.
    /// @param _queryId The unique query identifier.
    function deleteQuery(uint256 _queryId) external returns (Witnet.Response memory);

    /// Requests the execution of the given Witnet Data Request in expectation that it will be relayed and solved by the Witnet DON.
    /// A reward amount is escrowed by the Witnet Request Board that will be transferred to the reporter who relays back the Witnet-provided 
    /// result to this request.
    /// @dev Fails if:
    /// @dev - provided reward is too low.
    /// @dev - provided script is zero address.
    /// @dev - provided script bytecode is empty.
    /// @param _addr The address of the IWitnetRequest contract that can provide the actual Data Request bytecode.
    /// @return _queryId An unique query identifier.
    function postRequest(IWitnetRequest _addr) external payable returns (uint256 _queryId);

    /// Increments the reward of a previously posted request by adding the transaction value to it.
    /// @dev Updates request `gasPrice` in case this method is called with a higher 
    /// @dev gas price value than the one used in previous calls to `postRequest` or
    /// @dev `upgradeReward`. 
    /// @dev Fails if the `_queryId` is not in 'Posted' status.
    /// @dev Fails also in case the request `gasPrice` is increased, and the new 
    /// @dev reward value gets below new recalculated threshold. 
    /// @param _queryId The unique query identifier.
    function upgradeReward(uint256 _queryId) external payable;
}
          

/witnet-solidity-bridge/contracts/interfaces/IWitnetRequestBoardView.sol

// SPDX-License-Identifier: MIT

pragma solidity >=0.7.0 <0.9.0;
pragma experimental ABIEncoderV2;

import "../libs/Witnet.sol";

/// @title Witnet Request Board info interface.
/// @author The Witnet Foundation.
interface IWitnetRequestBoardView {
    /// Estimates the amount of reward we need to insert for a given gas price.
    /// @param _gasPrice The gas price for which we need to calculate the rewards.
    function estimateReward(uint256 _gasPrice) external view returns (uint256);

    /// Returns next query id to be generated by the Witnet Request Board.
    function getNextQueryId() external view returns (uint256);

    /// Gets the whole Query data contents, if any, no matter its current status.
    function getQueryData(uint256 _queryId) external view returns (Witnet.Query memory);

    /// Gets current status of given query.
    function getQueryStatus(uint256 _queryId) external view returns (Witnet.QueryStatus);

    /// Retrieves the whole Request record posted to the Witnet Request Board.
    /// @dev Fails if the `_queryId` is not valid or, if it has already been reported
    /// @dev or deleted.
    /// @param _queryId The unique identifier of a previously posted query.
    function readRequest(uint256 _queryId) external view returns (Witnet.Request memory);

    /// Retrieves the serialized bytecode of a previously posted Witnet Data Request.
    /// @dev Fails if the `_queryId` is not valid, or if the related script bytecode 
    /// @dev got changed after being posted. Returns empty array once it gets reported, 
    /// @dev or deleted.
    /// @param _queryId The unique query identifier.
    function readRequestBytecode(uint256 _queryId) external view returns (bytes memory);

    /// Retrieves the gas price that any assigned reporter will have to pay when reporting 
    /// result to a previously posted Witnet data request.
    /// @dev Fails if the `_queryId` is not valid or, if it has already been 
    /// @dev reported, or deleted. 
    /// @param _queryId The unique query identifie
    function readRequestGasPrice(uint256 _queryId) external view returns (uint256);

    /// Retrieves the reward currently set for the referred query.
    /// @dev Fails if the `_queryId` is not valid or, if it has already been 
    /// @dev reported, or deleted. 
    /// @param _queryId The unique query identifier.
    function readRequestReward(uint256 _queryId) external view returns (uint256);

    /// Retrieves the whole `Witnet.Response` record referred to a previously posted Witnet Data Request.
    /// @dev Fails if the `_queryId` is not in 'Reported' status.
    /// @param _queryId The unique query identifier.
    function readResponse(uint256 _queryId) external view returns (Witnet.Response memory);

    /// Retrieves the hash of the Witnet transaction hash that actually solved the referred query.
    /// @dev Fails if the `_queryId` is not in 'Reported' status.
    /// @param _queryId The unique query identifier.
    function readResponseDrTxHash(uint256 _queryId) external view returns (bytes32);    

    /// Retrieves the address that reported the result to a previously-posted request.
    /// @dev Fails if the `_queryId` is not in 'Reported' status.
    /// @param _queryId The unique query identifier.
    function readResponseReporter(uint256 _queryId) external view returns (address);

    /// Retrieves the Witnet-provided CBOR-bytes result of a previously posted request.
    /// @dev Fails if the `_queryId` is not in 'Reported' status.
    /// @param _queryId The unique query identifier.
    function readResponseResult(uint256 _queryId) external view returns (Witnet.Result memory);

    /// Retrieves the timestamp in which the result to the referred query was solved by the Witnet DON.
    /// @dev Fails if the `_queryId` is not in 'Reported' status.
    /// @param _queryId The unique query identifier.
    function readResponseTimestamp(uint256 _queryId) external view returns (uint256);
}
          

/witnet-solidity-bridge/contracts/interfaces/IWitnetRequestParser.sol

// SPDX-License-Identifier: MIT

pragma solidity >=0.7.0 <0.9.0;
pragma experimental ABIEncoderV2;

import "../libs/Witnet.sol";

/// @title The Witnet interface for decoding Witnet-provided request to Data Requests.
/// This interface exposes functions to check for the success/failure of
/// a Witnet-provided result, as well as to parse and convert result into
/// Solidity types suitable to the application level. 
/// @author The Witnet Foundation.
interface IWitnetRequestParser {

    /// Decode raw CBOR bytes into a Witnet.Result instance.
    /// @param _cborBytes Raw bytes representing a CBOR-encoded value.
    /// @return A `Witnet.Result` instance.
    function resultFromCborBytes(bytes memory _cborBytes) external pure returns (Witnet.Result memory);

    /// Decode a CBOR value into a Witnet.Result instance.
    /// @param _cborValue An instance of `Witnet.CBOR`.
    /// @return A `Witnet.Result` instance.
    function resultFromCborValue(Witnet.CBOR memory _cborValue) external pure returns (Witnet.Result memory);

    /// Tell if a Witnet.Result is successful.
    /// @param _result An instance of Witnet.Result.
    /// @return `true` if successful, `false` if errored.
    function isOk(Witnet.Result memory _result) external pure returns (bool);

    /// Tell if a Witnet.Result is errored.
    /// @param _result An instance of Witnet.Result.
    /// @return `true` if errored, `false` if successful.
    function isError(Witnet.Result memory _result) external pure returns (bool);

    /// Decode a bytes value from a Witnet.Result as a `bytes` value.
    /// @param _result An instance of Witnet.Result.
    /// @return The `bytes` decoded from the Witnet.Result.
    function asBytes(Witnet.Result memory _result) external pure returns (bytes memory);

    /// Decode a bytes value from a Witnet.Result as a `bytes32` value.
    /// @param _result An instance of Witnet.Result.
    /// @return The `bytes32` decoded from the Witnet.Result.
    function asBytes32(Witnet.Result memory _result) external pure returns (bytes32);

    /// Decode an error code from a Witnet.Result as a member of `Witnet.ErrorCodes`.
    /// @param _result An instance of `Witnet.Result`.
    /// @return The `CBORValue.Error memory` decoded from the Witnet.Result.
    function asErrorCode(Witnet.Result memory _result) external pure returns (Witnet.ErrorCodes);


    /// Generate a suitable error message for a member of `Witnet.ErrorCodes` and its corresponding arguments.
    /// @dev WARN: Note that client contracts should wrap this function into a try-catch foreseing potential errors generated in this function
    /// @param _result An instance of `Witnet.Result`.
    /// @return A tuple containing the `CBORValue.Error memory` decoded from the `Witnet.Result`, plus a loggable error message.
    function asErrorMessage(Witnet.Result memory _result) external pure returns (Witnet.ErrorCodes, string memory);

    /// Decode a raw error from a `Witnet.Result` as a `uint64[]`.
    /// @param _result An instance of `Witnet.Result`.
    /// @return The `uint64[]` raw error as decoded from the `Witnet.Result`.
    function asRawError(Witnet.Result memory _result) external pure returns(uint64[] memory);

    /// Decode a boolean value from a Witnet.Result as an `bool` value.
    /// @param _result An instance of Witnet.Result.
    /// @return The `bool` decoded from the Witnet.Result.
    function asBool(Witnet.Result memory _result) external pure returns (bool);

    /// Decode a fixed16 (half-precision) numeric value from a Witnet.Result as an `int32` value.
    /// @dev Due to the lack of support for floating or fixed point arithmetic in the EVM, this method offsets all values.
    /// by 5 decimal orders so as to get a fixed precision of 5 decimal positions, which should be OK for most `fixed16`.
    /// use cases. In other words, the output of this method is 10,000 times the actual value, encoded into an `int32`.
    /// @param _result An instance of Witnet.Result.
    /// @return The `int128` decoded from the Witnet.Result.
    function asFixed16(Witnet.Result memory _result) external pure returns (int32);

    /// Decode an array of fixed16 values from a Witnet.Result as an `int128[]` value.
    /// @param _result An instance of Witnet.Result.
    /// @return The `int128[]` decoded from the Witnet.Result.
    function asFixed16Array(Witnet.Result memory _result) external pure returns (int32[] memory);

    /// Decode a integer numeric value from a Witnet.Result as an `int128` value.
    /// @param _result An instance of Witnet.Result.
    /// @return The `int128` decoded from the Witnet.Result.
    function asInt128(Witnet.Result memory _result) external pure returns (int128);

    /// Decode an array of integer numeric values from a Witnet.Result as an `int128[]` value.
    /// @param _result An instance of Witnet.Result.
    /// @return The `int128[]` decoded from the Witnet.Result.
    function asInt128Array(Witnet.Result memory _result) external pure returns (int128[] memory);

    /// Decode a string value from a Witnet.Result as a `string` value.
    /// @param _result An instance of Witnet.Result.
    /// @return The `string` decoded from the Witnet.Result.
    function asString(Witnet.Result memory _result) external pure returns (string memory);

    /// Decode an array of string values from a Witnet.Result as a `string[]` value.
    /// @param _result An instance of Witnet.Result.
    /// @return The `string[]` decoded from the Witnet.Result.
    function asStringArray(Witnet.Result memory _result) external pure returns (string[] memory);

    /// Decode a natural numeric value from a Witnet.Result as a `uint64` value.
    /// @param _result An instance of Witnet.Result.
    /// @return The `uint64` decoded from the Witnet.Result.
    function asUint64(Witnet.Result memory _result) external pure returns(uint64);

    /// Decode an array of natural numeric values from a Witnet.Result as a `uint64[]` value.
    /// @param _result An instance of Witnet.Result.
    /// @return The `uint64[]` decoded from the Witnet.Result.
    function asUint64Array(Witnet.Result memory _result) external pure returns (uint64[] memory);

}
          

/witnet-solidity-bridge/contracts/libs/Witnet.sol

// SPDX-License-Identifier: MIT

pragma solidity >=0.7.0 <0.9.0;
pragma experimental ABIEncoderV2;

import "../interfaces/IWitnetRequest.sol";

library Witnet {

    /// @notice Witnet function that computes the hash of a CBOR-encoded Data Request.
    /// @param _bytecode CBOR-encoded RADON.
    function hash(bytes memory _bytecode) internal pure returns (bytes32) {
        return sha256(_bytecode);
    }

    /// Struct containing both request and response data related to every query posted to the Witnet Request Board
    struct Query {
        Request request;
        Response response;
        address from;      // Address from which the request was posted.
    }

    /// Possible status of a Witnet query.
    enum QueryStatus {
        Unknown,
        Posted,
        Reported,
        Deleted
    }

    /// Data kept in EVM-storage for every Request posted to the Witnet Request Board.
    struct Request {
        IWitnetRequest addr;    // The contract containing the Data Request which execution has been requested.
        address requester;      // Address from which the request was posted.
        bytes32 hash;           // Hash of the Data Request whose execution has been requested.
        uint256 gasprice;       // Minimum gas price the DR resolver should pay on the solving tx.
        uint256 reward;         // Escrowed reward to be paid to the DR resolver.
    }

    /// Data kept in EVM-storage containing Witnet-provided response metadata and result.
    struct Response {
        address reporter;       // Address from which the result was reported.
        uint256 timestamp;      // Timestamp of the Witnet-provided result.
        bytes32 drTxHash;       // Hash of the Witnet transaction that solved the queried Data Request.
        bytes   cborBytes;      // Witnet-provided result CBOR-bytes to the queried Data Request.
    }

    /// Data struct containing the Witnet-provided result to a Data Request.
    struct Result {
        bool success;           // Flag stating whether the request could get solved successfully, or not.
        CBOR value;             // Resulting value, in CBOR-serialized bytes.
    }

    /// Data struct following the RFC-7049 standard: Concise Binary Object Representation.
    struct CBOR {
        Buffer buffer;
        uint8 initialByte;
        uint8 majorType;
        uint8 additionalInformation;
        uint64 len;
        uint64 tag;
    }

    /// Iterable bytes buffer.
    struct Buffer {
        bytes data;
        uint32 cursor;
    }

    /// Witnet error codes table.
    enum ErrorCodes {
        // 0x00: Unknown error. Something went really bad!
        Unknown,
        // Script format errors
        /// 0x01: At least one of the source scripts is not a valid CBOR-encoded value.
        SourceScriptNotCBOR,
        /// 0x02: The CBOR value decoded from a source script is not an Array.
        SourceScriptNotArray,
        /// 0x03: The Array value decoded form a source script is not a valid Data Request.
        SourceScriptNotRADON,
        /// Unallocated
        ScriptFormat0x04,
        ScriptFormat0x05,
        ScriptFormat0x06,
        ScriptFormat0x07,
        ScriptFormat0x08,
        ScriptFormat0x09,
        ScriptFormat0x0A,
        ScriptFormat0x0B,
        ScriptFormat0x0C,
        ScriptFormat0x0D,
        ScriptFormat0x0E,
        ScriptFormat0x0F,
        // Complexity errors
        /// 0x10: The request contains too many sources.
        RequestTooManySources,
        /// 0x11: The script contains too many calls.
        ScriptTooManyCalls,
        /// Unallocated
        Complexity0x12,
        Complexity0x13,
        Complexity0x14,
        Complexity0x15,
        Complexity0x16,
        Complexity0x17,
        Complexity0x18,
        Complexity0x19,
        Complexity0x1A,
        Complexity0x1B,
        Complexity0x1C,
        Complexity0x1D,
        Complexity0x1E,
        Complexity0x1F,
        // Operator errors
        /// 0x20: The operator does not exist.
        UnsupportedOperator,
        /// Unallocated
        Operator0x21,
        Operator0x22,
        Operator0x23,
        Operator0x24,
        Operator0x25,
        Operator0x26,
        Operator0x27,
        Operator0x28,
        Operator0x29,
        Operator0x2A,
        Operator0x2B,
        Operator0x2C,
        Operator0x2D,
        Operator0x2E,
        Operator0x2F,
        // Retrieval-specific errors
        /// 0x30: At least one of the sources could not be retrieved, but returned HTTP error.
        HTTP,
        /// 0x31: Retrieval of at least one of the sources timed out.
        RetrievalTimeout,
        /// Unallocated
        Retrieval0x32,
        Retrieval0x33,
        Retrieval0x34,
        Retrieval0x35,
        Retrieval0x36,
        Retrieval0x37,
        Retrieval0x38,
        Retrieval0x39,
        Retrieval0x3A,
        Retrieval0x3B,
        Retrieval0x3C,
        Retrieval0x3D,
        Retrieval0x3E,
        Retrieval0x3F,
        // Math errors
        /// 0x40: Math operator caused an underflow.
        Underflow,
        /// 0x41: Math operator caused an overflow.
        Overflow,
        /// 0x42: Tried to divide by zero.
        DivisionByZero,
        /// Unallocated
        Math0x43,
        Math0x44,
        Math0x45,
        Math0x46,
        Math0x47,
        Math0x48,
        Math0x49,
        Math0x4A,
        Math0x4B,
        Math0x4C,
        Math0x4D,
        Math0x4E,
        Math0x4F,
        // Other errors
        /// 0x50: Received zero reveals
        NoReveals,
        /// 0x51: Insufficient consensus in tally precondition clause
        InsufficientConsensus,
        /// 0x52: Received zero commits
        InsufficientCommits,
        /// 0x53: Generic error during tally execution
        TallyExecution,
        /// Unallocated
        OtherError0x54,
        OtherError0x55,
        OtherError0x56,
        OtherError0x57,
        OtherError0x58,
        OtherError0x59,
        OtherError0x5A,
        OtherError0x5B,
        OtherError0x5C,
        OtherError0x5D,
        OtherError0x5E,
        OtherError0x5F,
        /// 0x60: Invalid reveal serialization (malformed reveals are converted to this value)
        MalformedReveal,
        /// Unallocated
        OtherError0x61,
        OtherError0x62,
        OtherError0x63,
        OtherError0x64,
        OtherError0x65,
        OtherError0x66,
        OtherError0x67,
        OtherError0x68,
        OtherError0x69,
        OtherError0x6A,
        OtherError0x6B,
        OtherError0x6C,
        OtherError0x6D,
        OtherError0x6E,
        OtherError0x6F,
        // Access errors
        /// 0x70: Tried to access a value from an index using an index that is out of bounds
        ArrayIndexOutOfBounds,
        /// 0x71: Tried to access a value from a map using a key that does not exist
        MapKeyNotFound,
        /// Unallocated
        OtherError0x72,
        OtherError0x73,
        OtherError0x74,
        OtherError0x75,
        OtherError0x76,
        OtherError0x77,
        OtherError0x78,
        OtherError0x79,
        OtherError0x7A,
        OtherError0x7B,
        OtherError0x7C,
        OtherError0x7D,
        OtherError0x7E,
        OtherError0x7F,
        OtherError0x80,
        OtherError0x81,
        OtherError0x82,
        OtherError0x83,
        OtherError0x84,
        OtherError0x85,
        OtherError0x86,
        OtherError0x87,
        OtherError0x88,
        OtherError0x89,
        OtherError0x8A,
        OtherError0x8B,
        OtherError0x8C,
        OtherError0x8D,
        OtherError0x8E,
        OtherError0x8F,
        OtherError0x90,
        OtherError0x91,
        OtherError0x92,
        OtherError0x93,
        OtherError0x94,
        OtherError0x95,
        OtherError0x96,
        OtherError0x97,
        OtherError0x98,
        OtherError0x99,
        OtherError0x9A,
        OtherError0x9B,
        OtherError0x9C,
        OtherError0x9D,
        OtherError0x9E,
        OtherError0x9F,
        OtherError0xA0,
        OtherError0xA1,
        OtherError0xA2,
        OtherError0xA3,
        OtherError0xA4,
        OtherError0xA5,
        OtherError0xA6,
        OtherError0xA7,
        OtherError0xA8,
        OtherError0xA9,
        OtherError0xAA,
        OtherError0xAB,
        OtherError0xAC,
        OtherError0xAD,
        OtherError0xAE,
        OtherError0xAF,
        OtherError0xB0,
        OtherError0xB1,
        OtherError0xB2,
        OtherError0xB3,
        OtherError0xB4,
        OtherError0xB5,
        OtherError0xB6,
        OtherError0xB7,
        OtherError0xB8,
        OtherError0xB9,
        OtherError0xBA,
        OtherError0xBB,
        OtherError0xBC,
        OtherError0xBD,
        OtherError0xBE,
        OtherError0xBF,
        OtherError0xC0,
        OtherError0xC1,
        OtherError0xC2,
        OtherError0xC3,
        OtherError0xC4,
        OtherError0xC5,
        OtherError0xC6,
        OtherError0xC7,
        OtherError0xC8,
        OtherError0xC9,
        OtherError0xCA,
        OtherError0xCB,
        OtherError0xCC,
        OtherError0xCD,
        OtherError0xCE,
        OtherError0xCF,
        OtherError0xD0,
        OtherError0xD1,
        OtherError0xD2,
        OtherError0xD3,
        OtherError0xD4,
        OtherError0xD5,
        OtherError0xD6,
        OtherError0xD7,
        OtherError0xD8,
        OtherError0xD9,
        OtherError0xDA,
        OtherError0xDB,
        OtherError0xDC,
        OtherError0xDD,
        OtherError0xDE,
        OtherError0xDF,
        // Bridge errors: errors that only belong in inter-client communication
        /// 0xE0: Requests that cannot be parsed must always get this error as their result.
        /// However, this is not a valid result in a Tally transaction, because invalid requests
        /// are never included into blocks and therefore never get a Tally in response.
        BridgeMalformedRequest,
        /// 0xE1: Witnesses exceeds 100
        BridgePoorIncentives,
        /// 0xE2: The request is rejected on the grounds that it may cause the submitter to spend or stake an
        /// amount of value that is unjustifiably high when compared with the reward they will be getting
        BridgeOversizedResult,
        /// Unallocated
        OtherError0xE3,
        OtherError0xE4,
        OtherError0xE5,
        OtherError0xE6,
        OtherError0xE7,
        OtherError0xE8,
        OtherError0xE9,
        OtherError0xEA,
        OtherError0xEB,
        OtherError0xEC,
        OtherError0xED,
        OtherError0xEE,
        OtherError0xEF,
        OtherError0xF0,
        OtherError0xF1,
        OtherError0xF2,
        OtherError0xF3,
        OtherError0xF4,
        OtherError0xF5,
        OtherError0xF6,
        OtherError0xF7,
        OtherError0xF8,
        OtherError0xF9,
        OtherError0xFA,
        OtherError0xFB,
        OtherError0xFC,
        OtherError0xFD,
        OtherError0xFE,
        // This should not exist:
        /// 0xFF: Some tally error is not intercepted but should
        UnhandledIntercept
    }
}
          

Contract ABI

[{"type":"constructor","stateMutability":"nonpayable","inputs":[{"type":"address","name":"_nylon","internalType":"address"}]},{"type":"event","name":"NylonRemoved","inputs":[{"type":"address","name":"_from","internalType":"address","indexed":true},{"type":"uint256","name":"_amount","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"NylonTransferred","inputs":[{"type":"address","name":"_to","internalType":"address","indexed":true},{"type":"uint256","name":"_amount","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"OwnershipTransferred","inputs":[{"type":"address","name":"previousOwner","internalType":"address","indexed":true},{"type":"address","name":"newOwner","internalType":"address","indexed":true}],"anonymous":false},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"buyNylon","inputs":[{"type":"uint256","name":"_amount","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"contract ExchangeRateService"}],"name":"exchange","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"owner","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"renounceOwnership","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"sellNylon","inputs":[{"type":"uint256","name":"_amount","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setExchangeRateService","inputs":[{"type":"address","name":"_exchangeRateService","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"transferOwnership","inputs":[{"type":"address","name":"newOwner","internalType":"address"}]}]
              

Contract Creation Code

0x60e06040523480156200001157600080fd5b5060405162001e4338038062001e43833981810160405281019062000037919062000264565b620000576200004b6200012e60201b60201c565b6200013660201b60201c565b600073874069fa1eb16d44d622f2e0ca25eea172369bc1905060007310c892a6ec43a53e45d0b916b4b7d383b1b78c0f90508273ffffffffffffffffffffffffffffffffffffffff1660c08173ffffffffffffffffffffffffffffffffffffffff16815250508173ffffffffffffffffffffffffffffffffffffffff1660808173ffffffffffffffffffffffffffffffffffffffff16815250508073ffffffffffffffffffffffffffffffffffffffff1660a08173ffffffffffffffffffffffffffffffffffffffff168152505050505062000296565b600033905090565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050816000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006200022c82620001ff565b9050919050565b6200023e816200021f565b81146200024a57600080fd5b50565b6000815190506200025e8162000233565b92915050565b6000602082840312156200027d576200027c620001fa565b5b60006200028d848285016200024d565b91505092915050565b60805160a05160c051611b3e620003056000396000818161055801528181610661015281816107880152610c740152600081816103b6015281816105110152818161088c0152610da8015260008181610302015281816104b60152818161083a0152610d050152611b3e6000f3fe608060405234801561001057600080fd5b506004361061007d5760003560e01c806398d46a181161005b57806398d46a18146100da578063bab92cfe1461010a578063d2f7265a14610126578063f2fde38b146101445761007d565b8063715018a6146100825780638da5cb5b1461008c5780638e232b13146100aa575b600080fd5b61008a610160565b005b6100946101e8565b6040516100a191906111a8565b60405180910390f35b6100c460048036038101906100bf91906111fe565b610211565b6040516100d19190611246565b60405180910390f35b6100f460048036038101906100ef91906111fe565b61065c565b6040516101019190611246565b60405180910390f35b610124600480360381019061011f919061128d565b610933565b005b61012e6109f3565b60405161013b9190611319565b60405180910390f35b61015e6004803603810190610159919061128d565b610a19565b005b610168610b10565b73ffffffffffffffffffffffffffffffffffffffff166101866101e8565b73ffffffffffffffffffffffffffffffffffffffff16146101dc576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016101d390611391565b60405180910390fd5b6101e66000610b18565b565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b6000806000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663850d352c856040518263ffffffff1660e01b815260040161027191906113c0565b6040805180830381865afa15801561028d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102b191906113f0565b9150915066038d7ea4c680008410156102ff576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016102f6906114a2565b60405180910390fd5b817f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663dd62ed3e610344610b10565b61034c610bdc565b6040518363ffffffff1660e01b81526004016103699291906114c2565b602060405180830381865afa158015610386573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103aa91906114eb565b101580156104615750807f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663dd62ed3e6103f8610b10565b610400610bdc565b6040518363ffffffff1660e01b815260040161041d9291906114c2565b602060405180830381865afa15801561043a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061045e91906114eb565b10155b6104a0576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016104979061158a565b60405180910390fd5b6104fb6104ab610b10565b6104b3610bdc565b847f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff16610be4909392919063ffffffff16565b610556610506610b10565b61050e610bdc565b837f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff16610be4909392919063ffffffff16565b7f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff166379fcd8ee61059a610b10565b866040518363ffffffff1660e01b81526004016105b89291906115aa565b6020604051808303816000875af11580156105d7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105fb91906115ff565b50610604610b10565b73ffffffffffffffffffffffffffffffffffffffff167f90cab3bd0141526014b849dbf2a318650b56a32a5b09f064d6abdcc87b8f6ffb8560405161064991906113c0565b60405180910390a2600192505050919050565b6000817f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff166370a082316106a3610b10565b6040518263ffffffff1660e01b81526004016106bf91906111a8565b602060405180830381865afa1580156106dc573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061070091906114eb565b1015610741576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016107389061169e565b60405180910390fd5b600080600061074e610c6d565b925092509250600061076b868461076591906116ed565b85610e4e565b90506000610784878461077e91906116ed565b86610e4e565b90507f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff166315d0975c6107ca610b10565b896040518363ffffffff1660e01b81526004016107e89291906115aa565b6020604051808303816000875af1158015610807573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061082b91906115ff565b5061087e610837610b10565b837f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff16610e649092919063ffffffff16565b6108d0610889610b10565b827f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff16610e649092919063ffffffff16565b6108d8610b10565b73ffffffffffffffffffffffffffffffffffffffff167f98046212e57d675c646c2d37a0cd2cf216e28cc8b671daed5741925eb9ae78dd8860405161091d91906113c0565b60405180910390a2600195505050505050919050565b61093b610b10565b73ffffffffffffffffffffffffffffffffffffffff166109596101e8565b73ffffffffffffffffffffffffffffffffffffffff16146109af576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109a690611391565b60405180910390fd5b80600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b610a21610b10565b73ffffffffffffffffffffffffffffffffffffffff16610a3f6101e8565b73ffffffffffffffffffffffffffffffffffffffff1614610a95576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a8c90611391565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1603610b04576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610afb906117b9565b60405180910390fd5b610b0d81610b18565b50565b600033905090565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050816000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b600030905090565b610c67846323b872dd60e01b858585604051602401610c05939291906117d9565b604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050610eea565b50505050565b60008060007f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610cdd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d0191906114eb565b92507f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff166370a08231610d47610bdc565b6040518263ffffffff1660e01b8152600401610d6391906111a8565b602060405180830381865afa158015610d80573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610da491906114eb565b91507f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff166370a08231610dea610bdc565b6040518263ffffffff1660e01b8152600401610e0691906111a8565b602060405180830381865afa158015610e23573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e4791906114eb565b9050909192565b60008183610e5c919061183f565b905092915050565b610ee58363a9059cbb60e01b8484604051602401610e839291906115aa565b604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050610eea565b505050565b6000610f4c826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c65648152508573ffffffffffffffffffffffffffffffffffffffff16610fb19092919063ffffffff16565b9050600081511115610fac5780806020019051810190610f6c91906115ff565b610fab576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610fa2906118e2565b60405180910390fd5b5b505050565b6060610fc08484600085610fc9565b90509392505050565b60608247101561100e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161100590611974565b60405180910390fd5b611017856110dd565b611056576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161104d906119e0565b60405180910390fd5b6000808673ffffffffffffffffffffffffffffffffffffffff16858760405161107f9190611a7a565b60006040518083038185875af1925050503d80600081146110bc576040519150601f19603f3d011682016040523d82523d6000602084013e6110c1565b606091505b50915091506110d1828286611100565b92505050949350505050565b6000808273ffffffffffffffffffffffffffffffffffffffff163b119050919050565b6060831561111057829050611160565b6000835111156111235782518084602001fd5b816040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016111579190611ae6565b60405180910390fd5b9392505050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061119282611167565b9050919050565b6111a281611187565b82525050565b60006020820190506111bd6000830184611199565b92915050565b600080fd5b6000819050919050565b6111db816111c8565b81146111e657600080fd5b50565b6000813590506111f8816111d2565b92915050565b600060208284031215611214576112136111c3565b5b6000611222848285016111e9565b91505092915050565b60008115159050919050565b6112408161122b565b82525050565b600060208201905061125b6000830184611237565b92915050565b61126a81611187565b811461127557600080fd5b50565b60008135905061128781611261565b92915050565b6000602082840312156112a3576112a26111c3565b5b60006112b184828501611278565b91505092915050565b6000819050919050565b60006112df6112da6112d584611167565b6112ba565b611167565b9050919050565b60006112f1826112c4565b9050919050565b6000611303826112e6565b9050919050565b611313816112f8565b82525050565b600060208201905061132e600083018461130a565b92915050565b600082825260208201905092915050565b7f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572600082015250565b600061137b602083611334565b915061138682611345565b602082019050919050565b600060208201905081810360008301526113aa8161136e565b9050919050565b6113ba816111c8565b82525050565b60006020820190506113d560008301846113b1565b92915050565b6000815190506113ea816111d2565b92915050565b60008060408385031215611407576114066111c3565b5b6000611415858286016113db565b9250506020611426858286016113db565b9150509250929050565b7f45786368616e67656420616d6f756e74206e6565647320746f2062652061742060008201527f6c6561737420302e303031210000000000000000000000000000000000000000602082015250565b600061148c602c83611334565b915061149782611430565b604082019050919050565b600060208201905081810360008301526114bb8161147f565b9050919050565b60006040820190506114d76000830185611199565b6114e46020830184611199565b9392505050565b600060208284031215611501576115006111c3565b5b600061150f848285016113db565b91505092915050565b7f417070726f7665206355534420616e64206345555220746f6b656e732066697260008201527f7374210000000000000000000000000000000000000000000000000000000000602082015250565b6000611574602383611334565b915061157f82611518565b604082019050919050565b600060208201905081810360008301526115a381611567565b9050919050565b60006040820190506115bf6000830185611199565b6115cc60208301846113b1565b9392505050565b6115dc8161122b565b81146115e757600080fd5b50565b6000815190506115f9816115d3565b92915050565b600060208284031215611615576116146111c3565b5b6000611623848285016115ea565b91505092915050565b7f4e796c6f6e2062616c616e6365206f662073656e64657220697320696e73756660008201527f66696369656e7421000000000000000000000000000000000000000000000000602082015250565b6000611688602883611334565b91506116938261162c565b604082019050919050565b600060208201905081810360008301526116b78161167b565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b60006116f8826111c8565b9150611703836111c8565b9250817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff048311821515161561173c5761173b6116be565b5b828202905092915050565b7f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160008201527f6464726573730000000000000000000000000000000000000000000000000000602082015250565b60006117a3602683611334565b91506117ae82611747565b604082019050919050565b600060208201905081810360008301526117d281611796565b9050919050565b60006060820190506117ee6000830186611199565b6117fb6020830185611199565b61180860408301846113b1565b949350505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b600061184a826111c8565b9150611855836111c8565b92508261186557611864611810565b5b828204905092915050565b7f5361666545524332303a204552433230206f7065726174696f6e20646964206e60008201527f6f74207375636365656400000000000000000000000000000000000000000000602082015250565b60006118cc602a83611334565b91506118d782611870565b604082019050919050565b600060208201905081810360008301526118fb816118bf565b9050919050565b7f416464726573733a20696e73756666696369656e742062616c616e636520666f60008201527f722063616c6c0000000000000000000000000000000000000000000000000000602082015250565b600061195e602683611334565b915061196982611902565b604082019050919050565b6000602082019050818103600083015261198d81611951565b9050919050565b7f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000600082015250565b60006119ca601d83611334565b91506119d582611994565b602082019050919050565b600060208201905081810360008301526119f9816119bd565b9050919050565b600081519050919050565b600081905092915050565b60005b83811015611a34578082015181840152602081019050611a19565b83811115611a43576000848401525b50505050565b6000611a5482611a00565b611a5e8185611a0b565b9350611a6e818560208601611a16565b80840191505092915050565b6000611a868284611a49565b915081905092915050565b600081519050919050565b6000601f19601f8301169050919050565b6000611ab882611a91565b611ac28185611334565b9350611ad2818560208601611a16565b611adb81611a9c565b840191505092915050565b60006020820190508181036000830152611b008184611aad565b90509291505056fea26469706673582212201226050ce70b317d5c59956db400ad1cbb788c2c0c4070c7fee4c4833d58142f64736f6c634300080d0033000000000000000000000000b66675243a92b4734c47ae1aa3e0f23f4112733c

Deployed ByteCode

0x608060405234801561001057600080fd5b506004361061007d5760003560e01c806398d46a181161005b57806398d46a18146100da578063bab92cfe1461010a578063d2f7265a14610126578063f2fde38b146101445761007d565b8063715018a6146100825780638da5cb5b1461008c5780638e232b13146100aa575b600080fd5b61008a610160565b005b6100946101e8565b6040516100a191906111a8565b60405180910390f35b6100c460048036038101906100bf91906111fe565b610211565b6040516100d19190611246565b60405180910390f35b6100f460048036038101906100ef91906111fe565b61065c565b6040516101019190611246565b60405180910390f35b610124600480360381019061011f919061128d565b610933565b005b61012e6109f3565b60405161013b9190611319565b60405180910390f35b61015e6004803603810190610159919061128d565b610a19565b005b610168610b10565b73ffffffffffffffffffffffffffffffffffffffff166101866101e8565b73ffffffffffffffffffffffffffffffffffffffff16146101dc576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016101d390611391565b60405180910390fd5b6101e66000610b18565b565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b6000806000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663850d352c856040518263ffffffff1660e01b815260040161027191906113c0565b6040805180830381865afa15801561028d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102b191906113f0565b9150915066038d7ea4c680008410156102ff576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016102f6906114a2565b60405180910390fd5b817f000000000000000000000000874069fa1eb16d44d622f2e0ca25eea172369bc173ffffffffffffffffffffffffffffffffffffffff1663dd62ed3e610344610b10565b61034c610bdc565b6040518363ffffffff1660e01b81526004016103699291906114c2565b602060405180830381865afa158015610386573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103aa91906114eb565b101580156104615750807f00000000000000000000000010c892a6ec43a53e45d0b916b4b7d383b1b78c0f73ffffffffffffffffffffffffffffffffffffffff1663dd62ed3e6103f8610b10565b610400610bdc565b6040518363ffffffff1660e01b815260040161041d9291906114c2565b602060405180830381865afa15801561043a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061045e91906114eb565b10155b6104a0576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016104979061158a565b60405180910390fd5b6104fb6104ab610b10565b6104b3610bdc565b847f000000000000000000000000874069fa1eb16d44d622f2e0ca25eea172369bc173ffffffffffffffffffffffffffffffffffffffff16610be4909392919063ffffffff16565b610556610506610b10565b61050e610bdc565b837f00000000000000000000000010c892a6ec43a53e45d0b916b4b7d383b1b78c0f73ffffffffffffffffffffffffffffffffffffffff16610be4909392919063ffffffff16565b7f000000000000000000000000b66675243a92b4734c47ae1aa3e0f23f4112733c73ffffffffffffffffffffffffffffffffffffffff166379fcd8ee61059a610b10565b866040518363ffffffff1660e01b81526004016105b89291906115aa565b6020604051808303816000875af11580156105d7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105fb91906115ff565b50610604610b10565b73ffffffffffffffffffffffffffffffffffffffff167f90cab3bd0141526014b849dbf2a318650b56a32a5b09f064d6abdcc87b8f6ffb8560405161064991906113c0565b60405180910390a2600192505050919050565b6000817f000000000000000000000000b66675243a92b4734c47ae1aa3e0f23f4112733c73ffffffffffffffffffffffffffffffffffffffff166370a082316106a3610b10565b6040518263ffffffff1660e01b81526004016106bf91906111a8565b602060405180830381865afa1580156106dc573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061070091906114eb565b1015610741576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016107389061169e565b60405180910390fd5b600080600061074e610c6d565b925092509250600061076b868461076591906116ed565b85610e4e565b90506000610784878461077e91906116ed565b86610e4e565b90507f000000000000000000000000b66675243a92b4734c47ae1aa3e0f23f4112733c73ffffffffffffffffffffffffffffffffffffffff166315d0975c6107ca610b10565b896040518363ffffffff1660e01b81526004016107e89291906115aa565b6020604051808303816000875af1158015610807573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061082b91906115ff565b5061087e610837610b10565b837f000000000000000000000000874069fa1eb16d44d622f2e0ca25eea172369bc173ffffffffffffffffffffffffffffffffffffffff16610e649092919063ffffffff16565b6108d0610889610b10565b827f00000000000000000000000010c892a6ec43a53e45d0b916b4b7d383b1b78c0f73ffffffffffffffffffffffffffffffffffffffff16610e649092919063ffffffff16565b6108d8610b10565b73ffffffffffffffffffffffffffffffffffffffff167f98046212e57d675c646c2d37a0cd2cf216e28cc8b671daed5741925eb9ae78dd8860405161091d91906113c0565b60405180910390a2600195505050505050919050565b61093b610b10565b73ffffffffffffffffffffffffffffffffffffffff166109596101e8565b73ffffffffffffffffffffffffffffffffffffffff16146109af576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109a690611391565b60405180910390fd5b80600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b610a21610b10565b73ffffffffffffffffffffffffffffffffffffffff16610a3f6101e8565b73ffffffffffffffffffffffffffffffffffffffff1614610a95576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a8c90611391565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1603610b04576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610afb906117b9565b60405180910390fd5b610b0d81610b18565b50565b600033905090565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050816000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b600030905090565b610c67846323b872dd60e01b858585604051602401610c05939291906117d9565b604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050610eea565b50505050565b60008060007f000000000000000000000000b66675243a92b4734c47ae1aa3e0f23f4112733c73ffffffffffffffffffffffffffffffffffffffff166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610cdd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d0191906114eb565b92507f000000000000000000000000874069fa1eb16d44d622f2e0ca25eea172369bc173ffffffffffffffffffffffffffffffffffffffff166370a08231610d47610bdc565b6040518263ffffffff1660e01b8152600401610d6391906111a8565b602060405180830381865afa158015610d80573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610da491906114eb565b91507f00000000000000000000000010c892a6ec43a53e45d0b916b4b7d383b1b78c0f73ffffffffffffffffffffffffffffffffffffffff166370a08231610dea610bdc565b6040518263ffffffff1660e01b8152600401610e0691906111a8565b602060405180830381865afa158015610e23573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e4791906114eb565b9050909192565b60008183610e5c919061183f565b905092915050565b610ee58363a9059cbb60e01b8484604051602401610e839291906115aa565b604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050610eea565b505050565b6000610f4c826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c65648152508573ffffffffffffffffffffffffffffffffffffffff16610fb19092919063ffffffff16565b9050600081511115610fac5780806020019051810190610f6c91906115ff565b610fab576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610fa2906118e2565b60405180910390fd5b5b505050565b6060610fc08484600085610fc9565b90509392505050565b60608247101561100e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161100590611974565b60405180910390fd5b611017856110dd565b611056576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161104d906119e0565b60405180910390fd5b6000808673ffffffffffffffffffffffffffffffffffffffff16858760405161107f9190611a7a565b60006040518083038185875af1925050503d80600081146110bc576040519150601f19603f3d011682016040523d82523d6000602084013e6110c1565b606091505b50915091506110d1828286611100565b92505050949350505050565b6000808273ffffffffffffffffffffffffffffffffffffffff163b119050919050565b6060831561111057829050611160565b6000835111156111235782518084602001fd5b816040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016111579190611ae6565b60405180910390fd5b9392505050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061119282611167565b9050919050565b6111a281611187565b82525050565b60006020820190506111bd6000830184611199565b92915050565b600080fd5b6000819050919050565b6111db816111c8565b81146111e657600080fd5b50565b6000813590506111f8816111d2565b92915050565b600060208284031215611214576112136111c3565b5b6000611222848285016111e9565b91505092915050565b60008115159050919050565b6112408161122b565b82525050565b600060208201905061125b6000830184611237565b92915050565b61126a81611187565b811461127557600080fd5b50565b60008135905061128781611261565b92915050565b6000602082840312156112a3576112a26111c3565b5b60006112b184828501611278565b91505092915050565b6000819050919050565b60006112df6112da6112d584611167565b6112ba565b611167565b9050919050565b60006112f1826112c4565b9050919050565b6000611303826112e6565b9050919050565b611313816112f8565b82525050565b600060208201905061132e600083018461130a565b92915050565b600082825260208201905092915050565b7f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572600082015250565b600061137b602083611334565b915061138682611345565b602082019050919050565b600060208201905081810360008301526113aa8161136e565b9050919050565b6113ba816111c8565b82525050565b60006020820190506113d560008301846113b1565b92915050565b6000815190506113ea816111d2565b92915050565b60008060408385031215611407576114066111c3565b5b6000611415858286016113db565b9250506020611426858286016113db565b9150509250929050565b7f45786368616e67656420616d6f756e74206e6565647320746f2062652061742060008201527f6c6561737420302e303031210000000000000000000000000000000000000000602082015250565b600061148c602c83611334565b915061149782611430565b604082019050919050565b600060208201905081810360008301526114bb8161147f565b9050919050565b60006040820190506114d76000830185611199565b6114e46020830184611199565b9392505050565b600060208284031215611501576115006111c3565b5b600061150f848285016113db565b91505092915050565b7f417070726f7665206355534420616e64206345555220746f6b656e732066697260008201527f7374210000000000000000000000000000000000000000000000000000000000602082015250565b6000611574602383611334565b915061157f82611518565b604082019050919050565b600060208201905081810360008301526115a381611567565b9050919050565b60006040820190506115bf6000830185611199565b6115cc60208301846113b1565b9392505050565b6115dc8161122b565b81146115e757600080fd5b50565b6000815190506115f9816115d3565b92915050565b600060208284031215611615576116146111c3565b5b6000611623848285016115ea565b91505092915050565b7f4e796c6f6e2062616c616e6365206f662073656e64657220697320696e73756660008201527f66696369656e7421000000000000000000000000000000000000000000000000602082015250565b6000611688602883611334565b91506116938261162c565b604082019050919050565b600060208201905081810360008301526116b78161167b565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b60006116f8826111c8565b9150611703836111c8565b9250817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff048311821515161561173c5761173b6116be565b5b828202905092915050565b7f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160008201527f6464726573730000000000000000000000000000000000000000000000000000602082015250565b60006117a3602683611334565b91506117ae82611747565b604082019050919050565b600060208201905081810360008301526117d281611796565b9050919050565b60006060820190506117ee6000830186611199565b6117fb6020830185611199565b61180860408301846113b1565b949350505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b600061184a826111c8565b9150611855836111c8565b92508261186557611864611810565b5b828204905092915050565b7f5361666545524332303a204552433230206f7065726174696f6e20646964206e60008201527f6f74207375636365656400000000000000000000000000000000000000000000602082015250565b60006118cc602a83611334565b91506118d782611870565b604082019050919050565b600060208201905081810360008301526118fb816118bf565b9050919050565b7f416464726573733a20696e73756666696369656e742062616c616e636520666f60008201527f722063616c6c0000000000000000000000000000000000000000000000000000602082015250565b600061195e602683611334565b915061196982611902565b604082019050919050565b6000602082019050818103600083015261198d81611951565b9050919050565b7f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000600082015250565b60006119ca601d83611334565b91506119d582611994565b602082019050919050565b600060208201905081810360008301526119f9816119bd565b9050919050565b600081519050919050565b600081905092915050565b60005b83811015611a34578082015181840152602081019050611a19565b83811115611a43576000848401525b50505050565b6000611a5482611a00565b611a5e8185611a0b565b9350611a6e818560208601611a16565b80840191505092915050565b6000611a868284611a49565b915081905092915050565b600081519050919050565b6000601f19601f8301169050919050565b6000611ab882611a91565b611ac28185611334565b9350611ad2818560208601611a16565b611adb81611a9c565b840191505092915050565b60006020820190508181036000830152611b008184611aad565b90509291505056fea26469706673582212201226050ce70b317d5c59956db400ad1cbb788c2c0c4070c7fee4c4833d58142f64736f6c634300080d0033