Address Details
contract

0x25741B41C48C6A9c09BbB3aB2eb0C4A6f5f41205

Contract Name
BasketService
Creator
0x07ff8b–54f774 at 0x30f420–18445f
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
9 Transactions
Transfers
2 Transfers
Gas Used
1,239,147
Last Balance Update
13679057
This contract has been partially 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-09-30T08:30:32.872642Z

contracts/BasketService.sol

// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0 <0.9.0;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.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, ReentrancyGuard {
    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(Nylon _nylon) {
        address _cUSD = 0x874069Fa1Eb16D44d622F2e0Ca25eeA172369bC1;
        address _cEUR = 0x10c892A6EC43a53E45D0B916B4b7D383B1b78C0F;

        // init of the 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 _evaluation()
        public
        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(ExchangeRateService _exchangeRateService)
        external
        onlyOwner
    {
        exchange = _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 nonReentrant 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 nonReentrant returns (bool) {
        require(
            nylon.balanceOf(_msgSender()) >= _amount,
            "Nylon balance of sender is insufficient!"
        );

        (uint256 cUSDAmount, uint256 cEURAmount) = exchange._nylonValue(
            _amount
        );

        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 (last updated v4.7.0) (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 Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

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

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        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/security/ReentrancyGuard.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol)

pragma solidity ^0.8.0;

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

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

    uint256 private _status;

    constructor() {
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        // On the first call to nonReentrant, _notEntered will be true
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

        // Any calls to nonReentrant after this point will fail
        _status = _ENTERED;

        _;

        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        _status = _NOT_ENTERED;
    }
}
          

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

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.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 `from` to `to`.
     *
     * 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/extensions/draft-IERC20Permit.sol

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

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 */
interface IERC20Permit {
    /**
     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
     * given ``owner``'s signed approval.
     *
     * IMPORTANT: The same issues {IERC20-approve} has related to transaction
     * ordering also apply here.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `deadline` must be a timestamp in the future.
     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
     * over the EIP712-formatted function arguments.
     * - the signature must use ``owner``'s current nonce (see {nonces}).
     *
     * For more information on the signature format, see the
     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
     * section].
     */
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;

    /**
     * @dev Returns the current nonce for `owner`. This value must be
     * included whenever a signature is generated for {permit}.
     *
     * Every successful call to {permit} increases ``owner``'s nonce by one. This
     * prevents a signature from being used multiple times.
     */
    function nonces(address owner) external view returns (uint256);

    /**
     * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
     */
    // solhint-disable-next-line func-name-mixedcase
    function DOMAIN_SEPARATOR() external view returns (bytes32);
}
          

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

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

pragma solidity ^0.8.0;

import "../IERC20.sol";
import "../extensions/draft-IERC20Permit.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));
        }
    }

    function safePermit(
        IERC20Permit token,
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal {
        uint256 nonceBefore = token.nonces(owner);
        token.permit(owner, spender, value, deadline, v, r, s);
        uint256 nonceAfter = token.nonces(owner);
        require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
    }

    /**
     * @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.7.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
                /// @solidity memory-safe-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/ExchangeRateService.sol

// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0 <0.9.0;

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

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

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

import "./BasketService.sol";

import "./Maths.sol";

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

contract ExchangeRateService {
    using SafeERC20 for IERC20;
    using Maths for uint256;

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

    // BasketService
    BasketService public immutable basket;

    // 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(BasketService _basketService, IWitnetPriceRouter _priceRouter) {
        address _cUSD = 0x874069Fa1Eb16D44d622F2e0Ca25eeA172369bC1;
        address _cEUR = 0x10c892A6EC43a53E45D0B916B4b7D383B1b78C0F;

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

        basket = _basketService;
        witnetPriceRouter = _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.floatingPointDivision(
            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 factor = Maths.factor;
        uint256 usdEurRate = _usdEurRate();

        (
            uint256 cEURBasketBalance,
            uint256 cUSDBasketBalance,
            uint256 nylonTtlSupply
        ) = basket._evaluation();

        if (nylonTtlSupply == 0) {
            uint256 squaredAmount = (_amount * _amount) / factor;

            (, , uint256 requestedAmount) = squaredAmount.floatingPointDivision(
                usdEurRate
            );

            cEURAmount = requestedAmount.squareRoot();
            cUSDAmount = (cEURAmount * usdEurRate) / factor;
        } else {
            (, , uint256 cUSDBasketValueInEUR) = cUSDBasketBalance
                .floatingPointDivision(usdEurRate);

            (, , uint256 nylonPercentage) = _amount.floatingPointDivision(
                nylonTtlSupply
            );

            uint256 addedValueInEUR = (nylonPercentage *
                (cUSDBasketValueInEUR + cEURBasketBalance)) / factor;

            cUSDAmount = (addedValueInEUR * usdEurRate) / 2 / factor;
            (, , cEURAmount) = addedValueInEUR.floatingPointDivision(
                2 * factor
            );
        }
    }
}
          

/contracts/Maths.sol

// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0 <0.9.0;

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

library Maths {
    using SafeMath for uint256;

    uint256 public constant factor = 10**18;

    modifier notNull(uint256 _value) {
        require(_value > 0, "Input parameter needs to be above 0.");
        _;
    }

    function floatingPointDivision(uint256 _numerator, uint256 _denominator)
        internal
        pure
        notNull(_denominator)
        returns (
            uint256 quotient,
            uint256 rest,
            uint256 result
        )
    {
        quotient = _numerator.div(_denominator);

        rest = ((_numerator * factor) / _denominator) % factor;

        bool rounding = 2 * ((_numerator * factor) % _denominator) >=
            _denominator;

        if (rounding) {
            rest += 1;
        }

        result = quotient.mul(factor) + rest;
    }

    function squareRoot(uint256 y) internal pure returns (uint256 z) {
        y = y * factor;
        if (y > 3) {
            z = y;
            uint256 x = y / 2 + 1;
            while (x < z) {
                z = x;
                x = (y / x + x) / 2;
            }
        }
    }
}
          

/contracts/Nylon.sol

// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0 <0.9.0;

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

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

Contract ABI

[{"type":"constructor","stateMutability":"nonpayable","inputs":[{"type":"address","name":"_nylon","internalType":"contract Nylon"}]},{"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":"view","outputs":[{"type":"uint256","name":"nylonTtlSupply","internalType":"uint256"},{"type":"uint256","name":"cUSDBasketBalance","internalType":"uint256"},{"type":"uint256","name":"cEURBasketBalance","internalType":"uint256"}],"name":"_evaluation","inputs":[]},{"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":"contract ExchangeRateService"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"transferOwnership","inputs":[{"type":"address","name":"newOwner","internalType":"address"}]}]
              

Contract Creation Code

Verify & Publish
0x60e06040523480156200001157600080fd5b5060405162001ebc38038062001ebc83398181016040528101906200003791906200027f565b620000576200004b6200013560201b60201c565b6200013d60201b60201c565b60018081905550600073874069fa1eb16d44d622f2e0ca25eea172369bc1905060007310c892a6ec43a53e45d0b916b4b7d383b1b78c0f90508273ffffffffffffffffffffffffffffffffffffffff1660c08173ffffffffffffffffffffffffffffffffffffffff16815250508173ffffffffffffffffffffffffffffffffffffffff1660808173ffffffffffffffffffffffffffffffffffffffff16815250508073ffffffffffffffffffffffffffffffffffffffff1660a08173ffffffffffffffffffffffffffffffffffffffff1681525050505050620002b1565b600033905090565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050816000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000620002338262000206565b9050919050565b6000620002478262000226565b9050919050565b62000259816200023a565b81146200026557600080fd5b50565b60008151905062000279816200024e565b92915050565b60006020828403121562000298576200029762000201565b5b6000620002a88482850162000268565b91505092915050565b60805160a05160c051611b9c620003206000396000818161055c015281816106b90152818161083d0152610a3f0152600081816103ba01528181610515015281816109410152610b73015260008181610306015281816104ba015281816108ef0152610ad00152611b9c6000f3fe608060405234801561001057600080fd5b50600436106100885760003560e01c8063bab92cfe1161005b578063bab92cfe14610115578063bc54082a14610131578063d2f7265a14610151578063f2fde38b1461016f57610088565b8063715018a61461008d5780638da5cb5b146100975780638e232b13146100b557806398d46a18146100e5575b600080fd5b61009561018b565b005b61009f61019f565b6040516100ac91906111e1565b60405180910390f35b6100cf60048036038101906100ca9190611237565b6101c8565b6040516100dc919061127f565b60405180910390f35b6100ff60048036038101906100fa9190611237565b610667565b60405161010c919061127f565b60405180910390f35b61012f600480360381019061012a91906112d8565b6109ec565b005b610139610a38565b60405161014893929190611314565b60405180910390f35b610159610c19565b60405161016691906113aa565b60405180910390f35b610189600480360381019061018491906113f1565b610c3f565b005b610193610cc2565b61019d6000610d40565b565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b600060026001540361020f576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016102069061147b565b60405180910390fd5b6002600181905550600080600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663850d352c856040518263ffffffff1660e01b8152600401610275919061149b565b6040805180830381865afa158015610291573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102b591906114cb565b9150915066038d7ea4c68000841015610303576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016102fa9061157d565b60405180910390fd5b817f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663dd62ed3e610348610e04565b610350610e0c565b6040518363ffffffff1660e01b815260040161036d92919061159d565b602060405180830381865afa15801561038a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103ae91906115c6565b101580156104655750807f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663dd62ed3e6103fc610e04565b610404610e0c565b6040518363ffffffff1660e01b815260040161042192919061159d565b602060405180830381865afa15801561043e573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061046291906115c6565b10155b6104a4576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161049b90611665565b60405180910390fd5b6104ff6104af610e04565b6104b7610e0c565b847f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff16610e14909392919063ffffffff16565b61055a61050a610e04565b610512610e0c565b837f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff16610e14909392919063ffffffff16565b7f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff166379fcd8ee61059e610e04565b866040518363ffffffff1660e01b81526004016105bc929190611685565b6020604051808303816000875af11580156105db573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105ff91906116da565b50610608610e04565b73ffffffffffffffffffffffffffffffffffffffff167f90cab3bd0141526014b849dbf2a318650b56a32a5b09f064d6abdcc87b8f6ffb8560405161064d919061149b565b60405180910390a260019250505060018081905550919050565b60006002600154036106ae576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016106a59061147b565b60405180910390fd5b6002600181905550817f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff166370a082316106fb610e04565b6040518263ffffffff1660e01b815260040161071791906111e1565b602060405180830381865afa158015610734573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061075891906115c6565b1015610799576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161079090611779565b60405180910390fd5b600080600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663850d352c856040518263ffffffff1660e01b81526004016107f7919061149b565b6040805180830381865afa158015610813573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061083791906114cb565b915091507f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff166315d0975c61087f610e04565b866040518363ffffffff1660e01b815260040161089d929190611685565b6020604051808303816000875af11580156108bc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108e091906116da565b506109336108ec610e04565b837f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff16610e9d9092919063ffffffff16565b61098561093e610e04565b827f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff16610e9d9092919063ffffffff16565b61098d610e04565b73ffffffffffffffffffffffffffffffffffffffff167f98046212e57d675c646c2d37a0cd2cf216e28cc8b671daed5741925eb9ae78dd856040516109d2919061149b565b60405180910390a260019250505060018081905550919050565b6109f4610cc2565b80600260006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b60008060007f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610aa8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610acc91906115c6565b92507f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff166370a08231610b12610e0c565b6040518263ffffffff1660e01b8152600401610b2e91906111e1565b602060405180830381865afa158015610b4b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b6f91906115c6565b91507f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff166370a08231610bb5610e0c565b6040518263ffffffff1660e01b8152600401610bd191906111e1565b602060405180830381865afa158015610bee573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c1291906115c6565b9050909192565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b610c47610cc2565b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1603610cb6576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610cad9061180b565b60405180910390fd5b610cbf81610d40565b50565b610cca610e04565b73ffffffffffffffffffffffffffffffffffffffff16610ce861019f565b73ffffffffffffffffffffffffffffffffffffffff1614610d3e576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610d3590611877565b60405180910390fd5b565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050816000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b600033905090565b600030905090565b610e97846323b872dd60e01b858585604051602401610e3593929190611897565b604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050610f23565b50505050565b610f1e8363a9059cbb60e01b8484604051602401610ebc929190611685565b604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050610f23565b505050565b6000610f85826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c65648152508573ffffffffffffffffffffffffffffffffffffffff16610fea9092919063ffffffff16565b9050600081511115610fe55780806020019051810190610fa591906116da565b610fe4576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610fdb90611940565b60405180910390fd5b5b505050565b6060610ff98484600085611002565b90509392505050565b606082471015611047576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161103e906119d2565b60405180910390fd5b61105085611116565b61108f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161108690611a3e565b60405180910390fd5b6000808673ffffffffffffffffffffffffffffffffffffffff1685876040516110b89190611ad8565b60006040518083038185875af1925050503d80600081146110f5576040519150601f19603f3d011682016040523d82523d6000602084013e6110fa565b606091505b509150915061110a828286611139565b92505050949350505050565b6000808273ffffffffffffffffffffffffffffffffffffffff163b119050919050565b6060831561114957829050611199565b60008351111561115c5782518084602001fd5b816040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016111909190611b44565b60405180910390fd5b9392505050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006111cb826111a0565b9050919050565b6111db816111c0565b82525050565b60006020820190506111f660008301846111d2565b92915050565b600080fd5b6000819050919050565b61121481611201565b811461121f57600080fd5b50565b6000813590506112318161120b565b92915050565b60006020828403121561124d5761124c6111fc565b5b600061125b84828501611222565b91505092915050565b60008115159050919050565b61127981611264565b82525050565b60006020820190506112946000830184611270565b92915050565b60006112a5826111c0565b9050919050565b6112b58161129a565b81146112c057600080fd5b50565b6000813590506112d2816112ac565b92915050565b6000602082840312156112ee576112ed6111fc565b5b60006112fc848285016112c3565b91505092915050565b61130e81611201565b82525050565b60006060820190506113296000830186611305565b6113366020830185611305565b6113436040830184611305565b949350505050565b6000819050919050565b600061137061136b611366846111a0565b61134b565b6111a0565b9050919050565b600061138282611355565b9050919050565b600061139482611377565b9050919050565b6113a481611389565b82525050565b60006020820190506113bf600083018461139b565b92915050565b6113ce816111c0565b81146113d957600080fd5b50565b6000813590506113eb816113c5565b92915050565b600060208284031215611407576114066111fc565b5b6000611415848285016113dc565b91505092915050565b600082825260208201905092915050565b7f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00600082015250565b6000611465601f8361141e565b91506114708261142f565b602082019050919050565b6000602082019050818103600083015261149481611458565b9050919050565b60006020820190506114b06000830184611305565b92915050565b6000815190506114c58161120b565b92915050565b600080604083850312156114e2576114e16111fc565b5b60006114f0858286016114b6565b9250506020611501858286016114b6565b9150509250929050565b7f45786368616e67656420616d6f756e74206e6565647320746f2062652061742060008201527f6c6561737420302e303031210000000000000000000000000000000000000000602082015250565b6000611567602c8361141e565b91506115728261150b565b604082019050919050565b600060208201905081810360008301526115968161155a565b9050919050565b60006040820190506115b260008301856111d2565b6115bf60208301846111d2565b9392505050565b6000602082840312156115dc576115db6111fc565b5b60006115ea848285016114b6565b91505092915050565b7f417070726f7665206355534420616e64206345555220746f6b656e732066697260008201527f7374210000000000000000000000000000000000000000000000000000000000602082015250565b600061164f60238361141e565b915061165a826115f3565b604082019050919050565b6000602082019050818103600083015261167e81611642565b9050919050565b600060408201905061169a60008301856111d2565b6116a76020830184611305565b9392505050565b6116b781611264565b81146116c257600080fd5b50565b6000815190506116d4816116ae565b92915050565b6000602082840312156116f0576116ef6111fc565b5b60006116fe848285016116c5565b91505092915050565b7f4e796c6f6e2062616c616e6365206f662073656e64657220697320696e73756660008201527f66696369656e7421000000000000000000000000000000000000000000000000602082015250565b600061176360288361141e565b915061176e82611707565b604082019050919050565b6000602082019050818103600083015261179281611756565b9050919050565b7f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160008201527f6464726573730000000000000000000000000000000000000000000000000000602082015250565b60006117f560268361141e565b915061180082611799565b604082019050919050565b60006020820190508181036000830152611824816117e8565b9050919050565b7f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572600082015250565b600061186160208361141e565b915061186c8261182b565b602082019050919050565b6000602082019050818103600083015261189081611854565b9050919050565b60006060820190506118ac60008301866111d2565b6118b960208301856111d2565b6118c66040830184611305565b949350505050565b7f5361666545524332303a204552433230206f7065726174696f6e20646964206e60008201527f6f74207375636365656400000000000000000000000000000000000000000000602082015250565b600061192a602a8361141e565b9150611935826118ce565b604082019050919050565b600060208201905081810360008301526119598161191d565b9050919050565b7f416464726573733a20696e73756666696369656e742062616c616e636520666f60008201527f722063616c6c0000000000000000000000000000000000000000000000000000602082015250565b60006119bc60268361141e565b91506119c782611960565b604082019050919050565b600060208201905081810360008301526119eb816119af565b9050919050565b7f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000600082015250565b6000611a28601d8361141e565b9150611a33826119f2565b602082019050919050565b60006020820190508181036000830152611a5781611a1b565b9050919050565b600081519050919050565b600081905092915050565b60005b83811015611a92578082015181840152602081019050611a77565b83811115611aa1576000848401525b50505050565b6000611ab282611a5e565b611abc8185611a69565b9350611acc818560208601611a74565b80840191505092915050565b6000611ae48284611aa7565b915081905092915050565b600081519050919050565b6000601f19601f8301169050919050565b6000611b1682611aef565b611b20818561141e565b9350611b30818560208601611a74565b611b3981611afa565b840191505092915050565b60006020820190508181036000830152611b5e8184611b0b565b90509291505056fea26469706673582212207b4b3056a7c26317217585a5080174991d63082a3ec8c2b915050d65ae0f74d764736f6c634300080d0033000000000000000000000000badb84cae2384440a8344176eecee4df22dd6cad

Deployed ByteCode

0x608060405234801561001057600080fd5b50600436106100885760003560e01c8063bab92cfe1161005b578063bab92cfe14610115578063bc54082a14610131578063d2f7265a14610151578063f2fde38b1461016f57610088565b8063715018a61461008d5780638da5cb5b146100975780638e232b13146100b557806398d46a18146100e5575b600080fd5b61009561018b565b005b61009f61019f565b6040516100ac91906111e1565b60405180910390f35b6100cf60048036038101906100ca9190611237565b6101c8565b6040516100dc919061127f565b60405180910390f35b6100ff60048036038101906100fa9190611237565b610667565b60405161010c919061127f565b60405180910390f35b61012f600480360381019061012a91906112d8565b6109ec565b005b610139610a38565b60405161014893929190611314565b60405180910390f35b610159610c19565b60405161016691906113aa565b60405180910390f35b610189600480360381019061018491906113f1565b610c3f565b005b610193610cc2565b61019d6000610d40565b565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b600060026001540361020f576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016102069061147b565b60405180910390fd5b6002600181905550600080600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663850d352c856040518263ffffffff1660e01b8152600401610275919061149b565b6040805180830381865afa158015610291573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102b591906114cb565b9150915066038d7ea4c68000841015610303576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016102fa9061157d565b60405180910390fd5b817f000000000000000000000000874069fa1eb16d44d622f2e0ca25eea172369bc173ffffffffffffffffffffffffffffffffffffffff1663dd62ed3e610348610e04565b610350610e0c565b6040518363ffffffff1660e01b815260040161036d92919061159d565b602060405180830381865afa15801561038a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103ae91906115c6565b101580156104655750807f00000000000000000000000010c892a6ec43a53e45d0b916b4b7d383b1b78c0f73ffffffffffffffffffffffffffffffffffffffff1663dd62ed3e6103fc610e04565b610404610e0c565b6040518363ffffffff1660e01b815260040161042192919061159d565b602060405180830381865afa15801561043e573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061046291906115c6565b10155b6104a4576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161049b90611665565b60405180910390fd5b6104ff6104af610e04565b6104b7610e0c565b847f000000000000000000000000874069fa1eb16d44d622f2e0ca25eea172369bc173ffffffffffffffffffffffffffffffffffffffff16610e14909392919063ffffffff16565b61055a61050a610e04565b610512610e0c565b837f00000000000000000000000010c892a6ec43a53e45d0b916b4b7d383b1b78c0f73ffffffffffffffffffffffffffffffffffffffff16610e14909392919063ffffffff16565b7f000000000000000000000000badb84cae2384440a8344176eecee4df22dd6cad73ffffffffffffffffffffffffffffffffffffffff166379fcd8ee61059e610e04565b866040518363ffffffff1660e01b81526004016105bc929190611685565b6020604051808303816000875af11580156105db573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105ff91906116da565b50610608610e04565b73ffffffffffffffffffffffffffffffffffffffff167f90cab3bd0141526014b849dbf2a318650b56a32a5b09f064d6abdcc87b8f6ffb8560405161064d919061149b565b60405180910390a260019250505060018081905550919050565b60006002600154036106ae576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016106a59061147b565b60405180910390fd5b6002600181905550817f000000000000000000000000badb84cae2384440a8344176eecee4df22dd6cad73ffffffffffffffffffffffffffffffffffffffff166370a082316106fb610e04565b6040518263ffffffff1660e01b815260040161071791906111e1565b602060405180830381865afa158015610734573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061075891906115c6565b1015610799576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161079090611779565b60405180910390fd5b600080600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663850d352c856040518263ffffffff1660e01b81526004016107f7919061149b565b6040805180830381865afa158015610813573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061083791906114cb565b915091507f000000000000000000000000badb84cae2384440a8344176eecee4df22dd6cad73ffffffffffffffffffffffffffffffffffffffff166315d0975c61087f610e04565b866040518363ffffffff1660e01b815260040161089d929190611685565b6020604051808303816000875af11580156108bc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108e091906116da565b506109336108ec610e04565b837f000000000000000000000000874069fa1eb16d44d622f2e0ca25eea172369bc173ffffffffffffffffffffffffffffffffffffffff16610e9d9092919063ffffffff16565b61098561093e610e04565b827f00000000000000000000000010c892a6ec43a53e45d0b916b4b7d383b1b78c0f73ffffffffffffffffffffffffffffffffffffffff16610e9d9092919063ffffffff16565b61098d610e04565b73ffffffffffffffffffffffffffffffffffffffff167f98046212e57d675c646c2d37a0cd2cf216e28cc8b671daed5741925eb9ae78dd856040516109d2919061149b565b60405180910390a260019250505060018081905550919050565b6109f4610cc2565b80600260006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b60008060007f000000000000000000000000badb84cae2384440a8344176eecee4df22dd6cad73ffffffffffffffffffffffffffffffffffffffff166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610aa8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610acc91906115c6565b92507f000000000000000000000000874069fa1eb16d44d622f2e0ca25eea172369bc173ffffffffffffffffffffffffffffffffffffffff166370a08231610b12610e0c565b6040518263ffffffff1660e01b8152600401610b2e91906111e1565b602060405180830381865afa158015610b4b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b6f91906115c6565b91507f00000000000000000000000010c892a6ec43a53e45d0b916b4b7d383b1b78c0f73ffffffffffffffffffffffffffffffffffffffff166370a08231610bb5610e0c565b6040518263ffffffff1660e01b8152600401610bd191906111e1565b602060405180830381865afa158015610bee573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c1291906115c6565b9050909192565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b610c47610cc2565b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1603610cb6576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610cad9061180b565b60405180910390fd5b610cbf81610d40565b50565b610cca610e04565b73ffffffffffffffffffffffffffffffffffffffff16610ce861019f565b73ffffffffffffffffffffffffffffffffffffffff1614610d3e576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610d3590611877565b60405180910390fd5b565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050816000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b600033905090565b600030905090565b610e97846323b872dd60e01b858585604051602401610e3593929190611897565b604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050610f23565b50505050565b610f1e8363a9059cbb60e01b8484604051602401610ebc929190611685565b604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050610f23565b505050565b6000610f85826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c65648152508573ffffffffffffffffffffffffffffffffffffffff16610fea9092919063ffffffff16565b9050600081511115610fe55780806020019051810190610fa591906116da565b610fe4576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610fdb90611940565b60405180910390fd5b5b505050565b6060610ff98484600085611002565b90509392505050565b606082471015611047576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161103e906119d2565b60405180910390fd5b61105085611116565b61108f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161108690611a3e565b60405180910390fd5b6000808673ffffffffffffffffffffffffffffffffffffffff1685876040516110b89190611ad8565b60006040518083038185875af1925050503d80600081146110f5576040519150601f19603f3d011682016040523d82523d6000602084013e6110fa565b606091505b509150915061110a828286611139565b92505050949350505050565b6000808273ffffffffffffffffffffffffffffffffffffffff163b119050919050565b6060831561114957829050611199565b60008351111561115c5782518084602001fd5b816040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016111909190611b44565b60405180910390fd5b9392505050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006111cb826111a0565b9050919050565b6111db816111c0565b82525050565b60006020820190506111f660008301846111d2565b92915050565b600080fd5b6000819050919050565b61121481611201565b811461121f57600080fd5b50565b6000813590506112318161120b565b92915050565b60006020828403121561124d5761124c6111fc565b5b600061125b84828501611222565b91505092915050565b60008115159050919050565b61127981611264565b82525050565b60006020820190506112946000830184611270565b92915050565b60006112a5826111c0565b9050919050565b6112b58161129a565b81146112c057600080fd5b50565b6000813590506112d2816112ac565b92915050565b6000602082840312156112ee576112ed6111fc565b5b60006112fc848285016112c3565b91505092915050565b61130e81611201565b82525050565b60006060820190506113296000830186611305565b6113366020830185611305565b6113436040830184611305565b949350505050565b6000819050919050565b600061137061136b611366846111a0565b61134b565b6111a0565b9050919050565b600061138282611355565b9050919050565b600061139482611377565b9050919050565b6113a481611389565b82525050565b60006020820190506113bf600083018461139b565b92915050565b6113ce816111c0565b81146113d957600080fd5b50565b6000813590506113eb816113c5565b92915050565b600060208284031215611407576114066111fc565b5b6000611415848285016113dc565b91505092915050565b600082825260208201905092915050565b7f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00600082015250565b6000611465601f8361141e565b91506114708261142f565b602082019050919050565b6000602082019050818103600083015261149481611458565b9050919050565b60006020820190506114b06000830184611305565b92915050565b6000815190506114c58161120b565b92915050565b600080604083850312156114e2576114e16111fc565b5b60006114f0858286016114b6565b9250506020611501858286016114b6565b9150509250929050565b7f45786368616e67656420616d6f756e74206e6565647320746f2062652061742060008201527f6c6561737420302e303031210000000000000000000000000000000000000000602082015250565b6000611567602c8361141e565b91506115728261150b565b604082019050919050565b600060208201905081810360008301526115968161155a565b9050919050565b60006040820190506115b260008301856111d2565b6115bf60208301846111d2565b9392505050565b6000602082840312156115dc576115db6111fc565b5b60006115ea848285016114b6565b91505092915050565b7f417070726f7665206355534420616e64206345555220746f6b656e732066697260008201527f7374210000000000000000000000000000000000000000000000000000000000602082015250565b600061164f60238361141e565b915061165a826115f3565b604082019050919050565b6000602082019050818103600083015261167e81611642565b9050919050565b600060408201905061169a60008301856111d2565b6116a76020830184611305565b9392505050565b6116b781611264565b81146116c257600080fd5b50565b6000815190506116d4816116ae565b92915050565b6000602082840312156116f0576116ef6111fc565b5b60006116fe848285016116c5565b91505092915050565b7f4e796c6f6e2062616c616e6365206f662073656e64657220697320696e73756660008201527f66696369656e7421000000000000000000000000000000000000000000000000602082015250565b600061176360288361141e565b915061176e82611707565b604082019050919050565b6000602082019050818103600083015261179281611756565b9050919050565b7f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160008201527f6464726573730000000000000000000000000000000000000000000000000000602082015250565b60006117f560268361141e565b915061180082611799565b604082019050919050565b60006020820190508181036000830152611824816117e8565b9050919050565b7f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572600082015250565b600061186160208361141e565b915061186c8261182b565b602082019050919050565b6000602082019050818103600083015261189081611854565b9050919050565b60006060820190506118ac60008301866111d2565b6118b960208301856111d2565b6118c66040830184611305565b949350505050565b7f5361666545524332303a204552433230206f7065726174696f6e20646964206e60008201527f6f74207375636365656400000000000000000000000000000000000000000000602082015250565b600061192a602a8361141e565b9150611935826118ce565b604082019050919050565b600060208201905081810360008301526119598161191d565b9050919050565b7f416464726573733a20696e73756666696369656e742062616c616e636520666f60008201527f722063616c6c0000000000000000000000000000000000000000000000000000602082015250565b60006119bc60268361141e565b91506119c782611960565b604082019050919050565b600060208201905081810360008301526119eb816119af565b9050919050565b7f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000600082015250565b6000611a28601d8361141e565b9150611a33826119f2565b602082019050919050565b60006020820190508181036000830152611a5781611a1b565b9050919050565b600081519050919050565b600081905092915050565b60005b83811015611a92578082015181840152602081019050611a77565b83811115611aa1576000848401525b50505050565b6000611ab282611a5e565b611abc8185611a69565b9350611acc818560208601611a74565b80840191505092915050565b6000611ae48284611aa7565b915081905092915050565b600081519050919050565b6000601f19601f8301169050919050565b6000611b1682611aef565b611b20818561141e565b9350611b30818560208601611a74565b611b3981611afa565b840191505092915050565b60006020820190508181036000830152611b5e8184611b0b565b90509291505056fea26469706673582212207b4b3056a7c26317217585a5080174991d63082a3ec8c2b915050d65ae0f74d764736f6c634300080d0033