ETH Price: $3,321.74 (+1.55%)
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To
Setup116483302021-01-13 18:30:061479 days ago1610562606IN
0x22d1EFAE...514D57DE9
0 ETH0.1279394550

Latest 25 internal transactions (View All)

Advanced mode:
Parent Transaction Hash Block
From
To
205902202024-08-23 8:50:35161 days ago1724403035
0x22d1EFAE...514D57DE9
0 ETH
205902202024-08-23 8:50:35161 days ago1724403035
0x22d1EFAE...514D57DE9
0 ETH
205902202024-08-23 8:50:35161 days ago1724403035
0x22d1EFAE...514D57DE9
0 ETH
205902202024-08-23 8:50:35161 days ago1724403035
0x22d1EFAE...514D57DE9
0 ETH
205902202024-08-23 8:50:35161 days ago1724403035
0x22d1EFAE...514D57DE9
0 ETH
205902202024-08-23 8:50:35161 days ago1724403035
0x22d1EFAE...514D57DE9
0 ETH
158728282022-11-01 4:32:11822 days ago1667277131
0x22d1EFAE...514D57DE9
0 ETH
158728282022-11-01 4:32:11822 days ago1667277131
0x22d1EFAE...514D57DE9
0 ETH
158728282022-11-01 4:32:11822 days ago1667277131
0x22d1EFAE...514D57DE9
0 ETH
158728282022-11-01 4:32:11822 days ago1667277131
0x22d1EFAE...514D57DE9
0 ETH
158728282022-11-01 4:32:11822 days ago1667277131
0x22d1EFAE...514D57DE9
0 ETH
158728282022-11-01 4:32:11822 days ago1667277131
0x22d1EFAE...514D57DE9
0 ETH
158720862022-11-01 2:01:47822 days ago1667268107
0x22d1EFAE...514D57DE9
0 ETH
158720862022-11-01 2:01:47822 days ago1667268107
0x22d1EFAE...514D57DE9
0 ETH
158720862022-11-01 2:01:47822 days ago1667268107
0x22d1EFAE...514D57DE9
0 ETH
158720862022-11-01 2:01:47822 days ago1667268107
0x22d1EFAE...514D57DE9
0 ETH
158720862022-11-01 2:01:47822 days ago1667268107
0x22d1EFAE...514D57DE9
0 ETH
158720862022-11-01 2:01:47822 days ago1667268107
0x22d1EFAE...514D57DE9
0 ETH
158713762022-10-31 23:39:11823 days ago1667259551
0x22d1EFAE...514D57DE9
0 ETH
158713762022-10-31 23:39:11823 days ago1667259551
0x22d1EFAE...514D57DE9
0 ETH
158713762022-10-31 23:39:11823 days ago1667259551
0x22d1EFAE...514D57DE9
0 ETH
158713762022-10-31 23:39:11823 days ago1667259551
0x22d1EFAE...514D57DE9
0 ETH
158713762022-10-31 23:39:11823 days ago1667259551
0x22d1EFAE...514D57DE9
0 ETH
158713762022-10-31 23:39:11823 days ago1667259551
0x22d1EFAE...514D57DE9
0 ETH
158706282022-10-31 21:08:47823 days ago1667250527
0x22d1EFAE...514D57DE9
0 ETH
View All Internal Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
Oracle

Compiler Version
v0.5.17+commit.d19bba13

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion

Contract Source Code (Solidity)

/**
 *Submitted for verification at Etherscan.io on 2021-01-13
*/

pragma solidity ^0.5.17;
pragma experimental ABIEncoderV2;


interface IUniswapV2Factory {
    event PairCreated(address indexed token0, address indexed token1, address pair, uint);

    function feeTo() external view returns (address);
    function feeToSetter() external view returns (address);

    function getPair(address tokenA, address tokenB) external view returns (address pair);
    function allPairs(uint) external view returns (address pair);
    function allPairsLength() external view returns (uint);

    function createPair(address tokenA, address tokenB) external returns (address pair);

    function setFeeTo(address) external;
    function setFeeToSetter(address) external;
}

interface IUniswapV2Pair {
    event Approval(address indexed owner, address indexed spender, uint value);
    event Transfer(address indexed from, address indexed to, uint value);

    function name() external pure returns (string memory);
    function symbol() external pure returns (string memory);
    function decimals() external pure returns (uint8);
    function totalSupply() external view returns (uint);
    function balanceOf(address owner) external view returns (uint);
    function allowance(address owner, address spender) external view returns (uint);

    function approve(address spender, uint value) external returns (bool);
    function transfer(address to, uint value) external returns (bool);
    function transferFrom(address from, address to, uint value) external returns (bool);

    function DOMAIN_SEPARATOR() external view returns (bytes32);
    function PERMIT_TYPEHASH() external pure returns (bytes32);
    function nonces(address owner) external view returns (uint);

    function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;

    event Mint(address indexed sender, uint amount0, uint amount1);
    event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);
    event Swap(
        address indexed sender,
        uint amount0In,
        uint amount1In,
        uint amount0Out,
        uint amount1Out,
        address indexed to
    );
    event Sync(uint112 reserve0, uint112 reserve1);

    function MINIMUM_LIQUIDITY() external pure returns (uint);
    function factory() external view returns (address);
    function token0() external view returns (address);
    function token1() external view returns (address);
    function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
    function price0CumulativeLast() external view returns (uint);
    function price1CumulativeLast() external view returns (uint);
    function kLast() external view returns (uint);

    function mint(address to) external returns (uint liquidity);
    function burn(address to) external returns (uint amount0, uint amount1);
    function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
    function skim(address to) external;
    function sync() external;

    function initialize(address, address) external;
}

// computes square roots using the babylonian method
// https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method
library Babylonian {
    function sqrt(uint y) internal pure returns (uint z) {
        if (y > 3) {
            z = y;
            uint x = y / 2 + 1;
            while (x < z) {
                z = x;
                x = (y / x + x) / 2;
            }
        } else if (y != 0) {
            z = 1;
        }
        // else z = 0
    }
}

// a library for handling binary fixed point numbers (https://en.wikipedia.org/wiki/Q_(number_format))
library FixedPoint {
    // range: [0, 2**112 - 1]
    // resolution: 1 / 2**112
    struct uq112x112 {
        uint224 _x;
    }

    // range: [0, 2**144 - 1]
    // resolution: 1 / 2**112
    struct uq144x112 {
        uint _x;
    }

    uint8 private constant RESOLUTION = 112;
    uint private constant Q112 = uint(1) << RESOLUTION;
    uint private constant Q224 = Q112 << RESOLUTION;

    // encode a uint112 as a UQ112x112
    function encode(uint112 x) internal pure returns (uq112x112 memory) {
        return uq112x112(uint224(x) << RESOLUTION);
    }

    // encodes a uint144 as a UQ144x112
    function encode144(uint144 x) internal pure returns (uq144x112 memory) {
        return uq144x112(uint256(x) << RESOLUTION);
    }

    // divide a UQ112x112 by a uint112, returning a UQ112x112
    function div(uq112x112 memory self, uint112 x) internal pure returns (uq112x112 memory) {
        require(x != 0, 'FixedPoint: DIV_BY_ZERO');
        return uq112x112(self._x / uint224(x));
    }

    // multiply a UQ112x112 by a uint, returning a UQ144x112
    // reverts on overflow
    function mul(uq112x112 memory self, uint y) internal pure returns (uq144x112 memory) {
        uint z;
        require(y == 0 || (z = uint(self._x) * y) / y == uint(self._x), "FixedPoint: MULTIPLICATION_OVERFLOW");
        return uq144x112(z);
    }

    // returns a UQ112x112 which represents the ratio of the numerator to the denominator
    // equivalent to encode(numerator).div(denominator)
    function fraction(uint112 numerator, uint112 denominator) internal pure returns (uq112x112 memory) {
        require(denominator > 0, "FixedPoint: DIV_BY_ZERO");
        return uq112x112((uint224(numerator) << RESOLUTION) / denominator);
    }

    // decode a UQ112x112 into a uint112 by truncating after the radix point
    function decode(uq112x112 memory self) internal pure returns (uint112) {
        return uint112(self._x >> RESOLUTION);
    }

    // decode a UQ144x112 into a uint144 by truncating after the radix point
    function decode144(uq144x112 memory self) internal pure returns (uint144) {
        return uint144(self._x >> RESOLUTION);
    }

    // take the reciprocal of a UQ112x112
    function reciprocal(uq112x112 memory self) internal pure returns (uq112x112 memory) {
        require(self._x != 0, 'FixedPoint: ZERO_RECIPROCAL');
        return uq112x112(uint224(Q224 / self._x));
    }

    // square root of a UQ112x112
    function sqrt(uq112x112 memory self) internal pure returns (uq112x112 memory) {
        return uq112x112(uint224(Babylonian.sqrt(uint256(self._x)) << 56));
    }
}

// library with helper methods for oracles that are concerned with computing average prices
library UniswapV2OracleLibrary {
    using FixedPoint for *;

    // helper function that returns the current block timestamp within the range of uint32, i.e. [0, 2**32 - 1]
    function currentBlockTimestamp() internal view returns (uint32) {
        return uint32(block.timestamp % 2 ** 32);
    }

    // produces the cumulative price using counterfactuals to save gas and avoid a call to sync.
    function currentCumulativePrices(address pair)
    internal
    view
    returns (uint price0Cumulative, uint price1Cumulative, uint32 blockTimestamp) {
        blockTimestamp = currentBlockTimestamp();
        price0Cumulative = IUniswapV2Pair(pair).price0CumulativeLast();
        price1Cumulative = IUniswapV2Pair(pair).price1CumulativeLast();

        // if time has elapsed since the last update on the pair, mock the accumulated price values
        (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast) = IUniswapV2Pair(pair).getReserves();
        if (blockTimestampLast != blockTimestamp) {
            // subtraction overflow is desired
            uint32 timeElapsed = blockTimestamp - blockTimestampLast;
            // addition overflow is desired
            // counterfactual
            price0Cumulative += uint(FixedPoint.fraction(reserve1, reserve0)._x) * timeElapsed;
            // counterfactual
            price1Cumulative += uint(FixedPoint.fraction(reserve0, reserve1)._x) * timeElapsed;
        }
    }
}

/**
 * @dev Wrappers over Solidity's arithmetic operations with added overflow
 * checks.
 *
 * Arithmetic operations in Solidity wrap on overflow. This can easily result
 * in bugs, because programmers usually assume that an overflow raises an
 * error, which is the standard behavior in high level programming languages.
 * `SafeMath` restores this intuition by reverting the transaction when an
 * operation overflows.
 *
 * Using this library instead of the unchecked operations eliminates an entire
 * class of bugs, so it's recommended to use it always.
 */
library SafeMath {
    /**
     * @dev Returns the addition of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `+` operator.
     *
     * Requirements:
     * - Addition cannot overflow.
     */
    function add(uint256 a, uint256 b) internal pure returns (uint256) {
        uint256 c = a + b;
        require(c >= a, "SafeMath: addition overflow");

        return c;
    }

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

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting with custom message on
     * overflow (when the result is negative).
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     * - Subtraction cannot overflow.
     *
     * _Available since v2.4.0._
     */
    function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        require(b <= a, errorMessage);
        uint256 c = a - b;

        return c;
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `*` operator.
     *
     * Requirements:
     * - Multiplication cannot overflow.
     */
    function mul(uint256 a, uint256 b) internal pure returns (uint256) {
        // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
        // benefit is lost if 'b' is also tested.
        // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
        if (a == 0) {
            return 0;
        }

        uint256 c = a * b;
        require(c / a == b, "SafeMath: multiplication overflow");

        return c;
    }

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

    /**
     * @dev Returns the integer division of two unsigned integers. Reverts with custom message on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator. Note: this function uses a
     * `revert` opcode (which leaves remaining gas untouched) while Solidity
     * uses an invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     * - The divisor cannot be zero.
     *
     * _Available since v2.4.0._
     */
    function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        // Solidity only automatically asserts when dividing by 0
        require(b > 0, errorMessage);
        uint256 c = a / b;
        // assert(a == b * c + a % b); // There is no case in which this doesn't hold

        return c;
    }

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

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * Reverts with custom message when dividing by zero.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     * - The divisor cannot be zero.
     *
     * _Available since v2.4.0._
     */
    function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        require(b != 0, errorMessage);
        return a % b;
    }
}

library UniswapV2Library {
    using SafeMath for uint;

    // returns sorted token addresses, used to handle return values from pairs sorted in this order
    function sortTokens(address tokenA, address tokenB) internal pure returns (address token0, address token1) {
        require(tokenA != tokenB, 'UniswapV2Library: IDENTICAL_ADDRESSES');
        (token0, token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);
        require(token0 != address(0), 'UniswapV2Library: ZERO_ADDRESS');
    }

    // calculates the CREATE2 address for a pair without making any external calls
    function pairFor(address factory, address tokenA, address tokenB) internal pure returns (address pair) {
        (address token0, address token1) = sortTokens(tokenA, tokenB);
        pair = address(uint(keccak256(abi.encodePacked(
                hex'ff',
                factory,
                keccak256(abi.encodePacked(token0, token1)),
                hex'96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f' // init code hash
            ))));
    }

    // fetches and sorts the reserves for a pair
    function getReserves(address factory, address tokenA, address tokenB) internal view returns (uint reserveA, uint reserveB) {
        (address token0,) = sortTokens(tokenA, tokenB);
        (uint reserve0, uint reserve1,) = IUniswapV2Pair(pairFor(factory, tokenA, tokenB)).getReserves();
        (reserveA, reserveB) = tokenA == token0 ? (reserve0, reserve1) : (reserve1, reserve0);
    }

    // given some amount of an asset and pair reserves, returns an equivalent amount of the other asset
    function quote(uint amountA, uint reserveA, uint reserveB) internal pure returns (uint amountB) {
        require(amountA > 0, 'UniswapV2Library: INSUFFICIENT_AMOUNT');
        require(reserveA > 0 && reserveB > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY');
        amountB = amountA.mul(reserveB) / reserveA;
    }
}

/*
    Copyright 2019 dYdX Trading Inc.

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

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

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
*/
/**
 * @title Require
 * @author dYdX
 *
 * Stringifies parameters to pretty-print revert messages. Costs more gas than regular require()
 */
library Require {

    // ============ Constants ============

    uint256 constant ASCII_ZERO = 48; // '0'
    uint256 constant ASCII_RELATIVE_ZERO = 87; // 'a' - 10
    uint256 constant ASCII_LOWER_EX = 120; // 'x'
    bytes2 constant COLON = 0x3a20; // ': '
    bytes2 constant COMMA = 0x2c20; // ', '
    bytes2 constant LPAREN = 0x203c; // ' <'
    byte constant RPAREN = 0x3e; // '>'
    uint256 constant FOUR_BIT_MASK = 0xf;

    // ============ Library Functions ============

    function that(
        bool must,
        bytes32 file,
        bytes32 reason
    )
    internal
    pure
    {
        if (!must) {
            revert(
                string(
                    abi.encodePacked(
                        stringifyTruncated(file),
                        COLON,
                        stringifyTruncated(reason)
                    )
                )
            );
        }
    }

    function that(
        bool must,
        bytes32 file,
        bytes32 reason,
        uint256 payloadA
    )
    internal
    pure
    {
        if (!must) {
            revert(
                string(
                    abi.encodePacked(
                        stringifyTruncated(file),
                        COLON,
                        stringifyTruncated(reason),
                        LPAREN,
                        stringify(payloadA),
                        RPAREN
                    )
                )
            );
        }
    }

    function that(
        bool must,
        bytes32 file,
        bytes32 reason,
        uint256 payloadA,
        uint256 payloadB
    )
    internal
    pure
    {
        if (!must) {
            revert(
                string(
                    abi.encodePacked(
                        stringifyTruncated(file),
                        COLON,
                        stringifyTruncated(reason),
                        LPAREN,
                        stringify(payloadA),
                        COMMA,
                        stringify(payloadB),
                        RPAREN
                    )
                )
            );
        }
    }

    function that(
        bool must,
        bytes32 file,
        bytes32 reason,
        address payloadA
    )
    internal
    pure
    {
        if (!must) {
            revert(
                string(
                    abi.encodePacked(
                        stringifyTruncated(file),
                        COLON,
                        stringifyTruncated(reason),
                        LPAREN,
                        stringify(payloadA),
                        RPAREN
                    )
                )
            );
        }
    }

    function that(
        bool must,
        bytes32 file,
        bytes32 reason,
        address payloadA,
        uint256 payloadB
    )
    internal
    pure
    {
        if (!must) {
            revert(
                string(
                    abi.encodePacked(
                        stringifyTruncated(file),
                        COLON,
                        stringifyTruncated(reason),
                        LPAREN,
                        stringify(payloadA),
                        COMMA,
                        stringify(payloadB),
                        RPAREN
                    )
                )
            );
        }
    }

    function that(
        bool must,
        bytes32 file,
        bytes32 reason,
        address payloadA,
        uint256 payloadB,
        uint256 payloadC
    )
    internal
    pure
    {
        if (!must) {
            revert(
                string(
                    abi.encodePacked(
                        stringifyTruncated(file),
                        COLON,
                        stringifyTruncated(reason),
                        LPAREN,
                        stringify(payloadA),
                        COMMA,
                        stringify(payloadB),
                        COMMA,
                        stringify(payloadC),
                        RPAREN
                    )
                )
            );
        }
    }

    function that(
        bool must,
        bytes32 file,
        bytes32 reason,
        bytes32 payloadA
    )
    internal
    pure
    {
        if (!must) {
            revert(
                string(
                    abi.encodePacked(
                        stringifyTruncated(file),
                        COLON,
                        stringifyTruncated(reason),
                        LPAREN,
                        stringify(payloadA),
                        RPAREN
                    )
                )
            );
        }
    }

    function that(
        bool must,
        bytes32 file,
        bytes32 reason,
        bytes32 payloadA,
        uint256 payloadB,
        uint256 payloadC
    )
    internal
    pure
    {
        if (!must) {
            revert(
                string(
                    abi.encodePacked(
                        stringifyTruncated(file),
                        COLON,
                        stringifyTruncated(reason),
                        LPAREN,
                        stringify(payloadA),
                        COMMA,
                        stringify(payloadB),
                        COMMA,
                        stringify(payloadC),
                        RPAREN
                    )
                )
            );
        }
    }

    // ============ Private Functions ============

    function stringifyTruncated(
        bytes32 input
    )
    private
    pure
    returns (bytes memory)
    {
        // put the input bytes into the result
        bytes memory result = abi.encodePacked(input);

        // determine the length of the input by finding the location of the last non-zero byte
        for (uint256 i = 32; i > 0; ) {
            // reverse-for-loops with unsigned integer
            /* solium-disable-next-line security/no-modify-for-iter-var */
            i--;

            // find the last non-zero byte in order to determine the length
            if (result[i] != 0) {
                uint256 length = i + 1;

                /* solium-disable-next-line security/no-inline-assembly */
                assembly {
                    mstore(result, length) // r.length = length;
                }

                return result;
            }
        }

        // all bytes are zero
        return new bytes(0);
    }

    function stringify(
        uint256 input
    )
    private
    pure
    returns (bytes memory)
    {
        if (input == 0) {
            return "0";
        }

        // get the final string length
        uint256 j = input;
        uint256 length;
        while (j != 0) {
            length++;
            j /= 10;
        }

        // allocate the string
        bytes memory bstr = new bytes(length);

        // populate the string starting with the least-significant character
        j = input;
        for (uint256 i = length; i > 0; ) {
            // reverse-for-loops with unsigned integer
            /* solium-disable-next-line security/no-modify-for-iter-var */
            i--;

            // take last decimal digit
            bstr[i] = byte(uint8(ASCII_ZERO + (j % 10)));

            // remove the last decimal digit
            j /= 10;
        }

        return bstr;
    }

    function stringify(
        address input
    )
    private
    pure
    returns (bytes memory)
    {
        uint256 z = uint256(input);

        // addresses are "0x" followed by 20 bytes of data which take up 2 characters each
        bytes memory result = new bytes(42);

        // populate the result with "0x"
        result[0] = byte(uint8(ASCII_ZERO));
        result[1] = byte(uint8(ASCII_LOWER_EX));

        // for each byte (starting from the lowest byte), populate the result with two characters
        for (uint256 i = 0; i < 20; i++) {
            // each byte takes two characters
            uint256 shift = i * 2;

            // populate the least-significant character
            result[41 - shift] = char(z & FOUR_BIT_MASK);
            z = z >> 4;

            // populate the most-significant character
            result[40 - shift] = char(z & FOUR_BIT_MASK);
            z = z >> 4;
        }

        return result;
    }

    function stringify(
        bytes32 input
    )
    private
    pure
    returns (bytes memory)
    {
        uint256 z = uint256(input);

        // bytes32 are "0x" followed by 32 bytes of data which take up 2 characters each
        bytes memory result = new bytes(66);

        // populate the result with "0x"
        result[0] = byte(uint8(ASCII_ZERO));
        result[1] = byte(uint8(ASCII_LOWER_EX));

        // for each byte (starting from the lowest byte), populate the result with two characters
        for (uint256 i = 0; i < 32; i++) {
            // each byte takes two characters
            uint256 shift = i * 2;

            // populate the least-significant character
            result[65 - shift] = char(z & FOUR_BIT_MASK);
            z = z >> 4;

            // populate the most-significant character
            result[64 - shift] = char(z & FOUR_BIT_MASK);
            z = z >> 4;
        }

        return result;
    }

    function char(
        uint256 input
    )
    private
    pure
    returns (byte)
    {
        // return ASCII digit (0-9)
        if (input < 10) {
            return byte(uint8(input + ASCII_ZERO));
        }

        // return ASCII letter (a-f)
        return byte(uint8(input + ASCII_RELATIVE_ZERO));
    }
}

/*
    Copyright 2019 dYdX Trading Inc.
    Copyright 2020 VTD team, based on the works of Dynamic Dollar Devs and Empty Set Squad

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

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

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
*/
/**
 * @title Decimal
 * @author dYdX
 *
 * Library that defines a fixed-point number with 18 decimal places.
 */
library Decimal {
    using SafeMath for uint256;

    // ============ Constants ============

    uint256 constant BASE = 10**18;

    // ============ Structs ============


    struct D256 {
        uint256 value;
    }

    // ============ Static Functions ============

    function zero()
    internal
    pure
    returns (D256 memory)
    {
        return D256({ value: 0 });
    }

    function one()
    internal
    pure
    returns (D256 memory)
    {
        return D256({ value: BASE });
    }

    function from(
        uint256 a
    )
    internal
    pure
    returns (D256 memory)
    {
        return D256({ value: a.mul(BASE) });
    }

    function ratio(
        uint256 a,
        uint256 b
    )
    internal
    pure
    returns (D256 memory)
    {
        return D256({ value: getPartial(a, BASE, b) });
    }

    // ============ Self Functions ============

    function add(
        D256 memory self,
        uint256 b
    )
    internal
    pure
    returns (D256 memory)
    {
        return D256({ value: self.value.add(b.mul(BASE)) });
    }

    function sub(
        D256 memory self,
        uint256 b
    )
    internal
    pure
    returns (D256 memory)
    {
        return D256({ value: self.value.sub(b.mul(BASE)) });
    }

    function sub(
        D256 memory self,
        uint256 b,
        string memory reason
    )
    internal
    pure
    returns (D256 memory)
    {
        return D256({ value: self.value.sub(b.mul(BASE), reason) });
    }

    function mul(
        D256 memory self,
        uint256 b
    )
    internal
    pure
    returns (D256 memory)
    {
        return D256({ value: self.value.mul(b) });
    }

    function div(
        D256 memory self,
        uint256 b
    )
    internal
    pure
    returns (D256 memory)
    {
        return D256({ value: self.value.div(b) });
    }

    function pow(
        D256 memory self,
        uint256 b
    )
    internal
    pure
    returns (D256 memory)
    {
        if (b == 0) {
            return from(1);
        }

        D256 memory temp = D256({ value: self.value });
        for (uint256 i = 1; i < b; i++) {
            temp = mul(temp, self);
        }

        return temp;
    }

    function add(
        D256 memory self,
        D256 memory b
    )
    internal
    pure
    returns (D256 memory)
    {
        return D256({ value: self.value.add(b.value) });
    }

    function sub(
        D256 memory self,
        D256 memory b
    )
    internal
    pure
    returns (D256 memory)
    {
        return D256({ value: self.value.sub(b.value) });
    }

    function sub(
        D256 memory self,
        D256 memory b,
        string memory reason
    )
    internal
    pure
    returns (D256 memory)
    {
        return D256({ value: self.value.sub(b.value, reason) });
    }

    function mul(
        D256 memory self,
        D256 memory b
    )
    internal
    pure
    returns (D256 memory)
    {
        return D256({ value: getPartial(self.value, b.value, BASE) });
    }

    function div(
        D256 memory self,
        D256 memory b
    )
    internal
    pure
    returns (D256 memory)
    {
        return D256({ value: getPartial(self.value, BASE, b.value) });
    }

    function equals(D256 memory self, D256 memory b) internal pure returns (bool) {
        return self.value == b.value;
    }

    function greaterThan(D256 memory self, D256 memory b) internal pure returns (bool) {
        return compareTo(self, b) == 2;
    }

    function lessThan(D256 memory self, D256 memory b) internal pure returns (bool) {
        return compareTo(self, b) == 0;
    }

    function greaterThanOrEqualTo(D256 memory self, D256 memory b) internal pure returns (bool) {
        return compareTo(self, b) > 0;
    }

    function lessThanOrEqualTo(D256 memory self, D256 memory b) internal pure returns (bool) {
        return compareTo(self, b) < 2;
    }

    function isZero(D256 memory self) internal pure returns (bool) {
        return self.value == 0;
    }

    function asUint256(D256 memory self) internal pure returns (uint256) {
        return self.value.div(BASE);
    }

    // ============ Core Methods ============

    function getPartial(
        uint256 target,
        uint256 numerator,
        uint256 denominator
    )
    private
    pure
    returns (uint256)
    {
        return target.mul(numerator).div(denominator);
    }

    function compareTo(
        D256 memory a,
        D256 memory b
    )
    private
    pure
    returns (uint256)
    {
        if (a.value == b.value) {
            return 1;
        }
        return a.value > b.value ? 2 : 0;
    }
}

/*
    Copyright 2020 VTD team, based on the works of Dynamic Dollar Devs and Empty Set Squad

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

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

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
*/
contract IOracle {
    function setup() public;
    function capture() public returns (Decimal.D256 memory, bool);
    function pair() external view returns (address);
    function getLastVtdReserve() public view returns (uint256); 
    function getLastPrice() public view returns (Decimal.D256 memory, bool);
}

/**
 * @dev Interface of the ERC20 standard as defined in the EIP. Does not include
 * the optional functions; to access them see {ERC20Detailed}.
 */
interface IERC20 {
    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

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

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

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

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

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

    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

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

/*
    Copyright 2020 VTD team, based on the works of Dynamic Dollar Devs and Empty Set Squad

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

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

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
*/
contract IPeggedToken is IERC20 {
    function decimals() public view returns (uint8);
}

/*
    Copyright 2020 VTD team, based on the works of Dynamic Dollar Devs and Empty Set Squad

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

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

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
*/
library Constants {
    /* Chain */
    uint256 private constant CHAIN_ID = 1; // Mainnet

    /* Bootstrapping */
    uint256 private constant BOOTSTRAPPING_PERIOD = 36; // 36 epochs IMPORTANT
    uint256 private constant BOOTSTRAPPING_PERIOD_PHASE1 = 0; // set to 0
    uint256 private constant BOOTSTRAPPING_PRICE = 196e16; // 1.96 pegged token (targeting 8% inflation)

    /* Oracle */
    //IMPORTANT 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 deprecated
    address private constant USDC = address(0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48); 
    uint256 private constant ORACLE_RESERVE_MINIMUM = 1e9; // 1,000 pegged token, 1e9 IMPORTANT

    /* Bonding */
    uint256 private constant INITIAL_STAKE_MULTIPLE = 1e6; // 100 VTD -> 100M VTDD

    /* Epoch */
    uint256 private constant EPOCH_START = 1609405200;
    uint256 private constant EPOCH_BASE = 7200; //two hours IMPORTANT
    uint256 private constant EPOCH_GROWTH_CONSTANT = 12000; //1 hour
    uint256 private constant P1_EPOCH_BASE = 300; // IMPORTANT
    uint256 private constant P1_EPOCH_GROWTH_CONSTANT = 12000; // IMPORTANT 12000
    uint256 private constant ADVANCE_LOTTERY_TIME = 91; // deprecated

    /* Governance */
    uint256 private constant GOVERNANCE_PERIOD = 8; // 1 dayish governance period IMPORTANT
    uint256 private constant GOVERNANCE_QUORUM = 20e16; // 20%
    uint256 private constant GOVERNANCE_SUPER_MAJORITY = 51e16; // 51%
    uint256 private constant GOVERNANCE_FASTTRACK_PERIOD = 3; // 3 epochs
    uint256 private constant GOVERNANCE_EMERGENCY_DELAY = 14400; // 4 hours in case multi-lp has a critical bug

    /* DAO */
    uint256 private constant ADVANCE_INCENTIVE = 50e18; // 50 VTD IMPORTANT
    uint256 private constant ADVANCE_INCENTIVE_BOOTSTRAP = 50e18; // 50 VTD deprecated
    uint256 private constant DAO_EXIT_LOCKUP_EPOCHS = 18; // 18 epoch fluid IMPORTANT

    /* Pool */
    uint256 private constant POOL_EXIT_LOCKUP_EPOCHS = 9; // 9 epoch fluid IMPORTANT

    /* Market */
    uint256 private constant COUPON_EXPIRATION = 180; //30 days
    uint256 private constant DEBT_RATIO_CAP = 35e16; // 35%
    uint256 private constant INITIAL_COUPON_REDEMPTION_PENALTY = 50e16; // 50%
    uint256 private constant COUPON_REDEMPTION_PENALTY_DECAY = 3600; // 1 hour

    /* Regulator */
    uint256 private constant SUPPLY_CHANGE_LIMIT = 10e16; // 10%
    uint256 private constant EPOCH_GROWTH_BETA = 90e16; // 90%
    uint256 private constant ORACLE_POOL_RATIO = 40; // 40% IMPORTANT Increased to 40% for 2 pools

    // Pegs
    uint256 private constant USDC_START = 240;
    uint256 private constant USDT_START = 120;
    uint256 private constant WBTC_START = 180;

    // IMPORTANT, double check addresses
    address private constant USDC_POOL = address(0xBD2F0Cd039E0BFcf88901C98c0bFAc5ab27566e3);
    address private constant USDT_POOL = address(0x6950929E1379E64DE376e56068103d145B81dC6A); 
    address private constant WETH_POOL = address(0x7a6fbec053D5475B2eb732239F794131cBFc172B); 
    address private constant WBTC_POOL = address(0x7023A104906Fc120b662ADE8Aeede41ba57F59e7); 
    address private constant DSD_POOL = address(0x623EA23a36bF98a065701B08Be1Ad17246d0E337);

    address private constant USDC_ORACLE = address(0xd51efebF258e2119Cc8a71A1c4406ec5BFD608Bc);
    address private constant USDT_ORACLE = address(0x16148886CEFF9baD1042a59Cd3E85Ac66f54D639); 
    address private constant WETH_ORACLE = address(0x7a6fbec053D5475B2eb732239F794131cBFc172B); 
    address private constant WBTC_ORACLE = address(0x7023A104906Fc120b662ADE8Aeede41ba57F59e7); 
    address private constant DSD_ORACLE = address(0x368897f053e9838db281751B722e7F6969802B31);

    /**
     * Getters
     */
    function getEpochStart() internal pure returns (uint256) {
        return EPOCH_START;
    }

    function getP1EpochBase() internal pure returns (uint256) {
        return P1_EPOCH_BASE;
    }

    function getP1EpochGrowthConstant() internal pure returns (uint256) {
        return P1_EPOCH_GROWTH_CONSTANT;
    }

    function getEpochBase() internal pure returns (uint256) {
        return EPOCH_BASE;
    }

    function getEpochGrowthConstant() internal pure returns (uint256) {
        return EPOCH_GROWTH_CONSTANT;
    }

    function getOracleReserveMinimum() internal pure returns (uint256) {
        return ORACLE_RESERVE_MINIMUM;
    }

    function getInitialStakeMultiple() internal pure returns (uint256) {
        return INITIAL_STAKE_MULTIPLE;
    }

    function getAdvanceLotteryTime() internal pure returns (uint256){
        return ADVANCE_LOTTERY_TIME;
    }

    function getBootstrappingPeriod() internal pure returns (uint256) {
        return BOOTSTRAPPING_PERIOD;
    }

    function getPhaseOnePeriod() internal pure returns (uint256) {
        return BOOTSTRAPPING_PERIOD_PHASE1;
    }

    function getBootstrappingPrice() internal pure returns (Decimal.D256 memory) {
        return Decimal.D256({value: BOOTSTRAPPING_PRICE});
    }

    function getGovernancePeriod() internal pure returns (uint256) {
        return GOVERNANCE_PERIOD;
    }

     function getFastTrackPeriod() internal pure returns (uint256) {
        return GOVERNANCE_FASTTRACK_PERIOD;
    }

    function getGovernanceQuorum() internal pure returns (Decimal.D256 memory) {
        return Decimal.D256({value: GOVERNANCE_QUORUM});
    }

    function getGovernanceSuperMajority() internal pure returns (Decimal.D256 memory) {
        return Decimal.D256({value: GOVERNANCE_SUPER_MAJORITY});
    }

    function getGovernanceEmergencyDelay() internal pure returns (uint256) {
        return GOVERNANCE_EMERGENCY_DELAY;
    }

    function getAdvanceIncentive() internal pure returns (uint256) {
        return ADVANCE_INCENTIVE;
    }

    function getAdvanceIncentiveBootstrap() internal pure returns (uint256) {
        return ADVANCE_INCENTIVE_BOOTSTRAP;
    }

    function getDAOExitLockupEpochs() internal pure returns (uint256) {
        return DAO_EXIT_LOCKUP_EPOCHS;
    }

    function getPoolExitLockupEpochs() internal pure returns (uint256) {
        return POOL_EXIT_LOCKUP_EPOCHS;
    }

    function getCouponExpiration() internal pure returns (uint256) {
        return COUPON_EXPIRATION;
    }

    function getDebtRatioCap() internal pure returns (Decimal.D256 memory) {
        return Decimal.D256({value: DEBT_RATIO_CAP});
    }
    
    function getInitialCouponRedemptionPenalty() internal pure returns (Decimal.D256 memory) {
        return Decimal.D256({value: INITIAL_COUPON_REDEMPTION_PENALTY});
    }

    function getCouponRedemptionPenaltyDecay() internal pure returns (uint256) {
        return COUPON_REDEMPTION_PENALTY_DECAY;
    }

    function getSupplyChangeLimit() internal pure returns (Decimal.D256 memory) {
        return Decimal.D256({value: SUPPLY_CHANGE_LIMIT});
    }

    function getEpochGrowthBeta() internal pure returns (Decimal.D256 memory) {
        return Decimal.D256({value: EPOCH_GROWTH_BETA});
    }

    function getOraclePoolRatio() internal pure returns (uint256) {
        return ORACLE_POOL_RATIO;
    }

    function getChainId() internal pure returns (uint256) {
        return CHAIN_ID;
    }

    function getWbtcStart() internal pure returns (uint256) {
        return WBTC_START;
    }

    function getUsdtStart() internal pure returns (uint256) {
        return USDT_START;
    }

    function getUsdcStart() internal pure returns (uint256) {
        return USDC_START;
    }

// pools
    function getUsdcPool() internal pure returns (address) {
        return USDC_POOL;
    }

    function getUsdtPool() internal pure returns (address) {
        return USDT_POOL;
    }

    function getEthPool() internal pure returns (address) {
        return WETH_POOL;
    }

    function getWbtcPool() internal pure returns (address) {
        return WBTC_POOL;
    }

    function getDsdPool() internal pure returns (address) {
        return DSD_POOL;
    }

// oracles
    function getUsdcOracle() internal pure returns (IOracle) {
        return IOracle(USDC_ORACLE);
    }

    function getUsdtOracle() internal pure returns (IOracle) {
        return IOracle(USDT_ORACLE);
    }

    function getEthOracle() internal pure returns (IOracle) {
        return IOracle(WETH_ORACLE);
    }

    function getWbtcOracle() internal pure returns (IOracle) {
        return IOracle(WBTC_ORACLE);
    }

    function getDsdOracle() internal pure returns (IOracle) {
        return IOracle(DSD_ORACLE);
    }
}

/*
    Copyright 2020 VTD team, based on the works of Dynamic Dollar Devs and Empty Set Squad

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

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

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
*/
contract Oracle is IOracle {
    using SafeMath for uint256;
    using Decimal for Decimal.D256;

    bytes32 private constant FILE = "Oracle";
    address private constant UNISWAP_FACTORY = address(0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f);

    address internal _dao;
    address internal _dollar;
    address internal _peg;
    uint internal _pegDecimalFactor;

    bool internal _initialized;
    IUniswapV2Pair internal _pair;
    uint256 internal _index;
    uint256 internal _cumulative;
    uint32 internal _timestamp;
    uint256 internal _lastPrice;

    uint256 internal _reserve;
    uint256 internal _vtdReserve;

    bool internal _isValid;

    constructor (address dollar, address peg, uint256 decimalMultiplier) public {
        _dao = msg.sender;
        _dollar = dollar;
        _peg = peg;
        _pegDecimalFactor = decimalMultiplier;
    }

    function setup() public onlyDao {
        // IMPORTANT, DAO has to be the DAO, only use msg.sender if deploying from the proxy contract
        _dao = address(0x530608409991C36Ba922B69623BEc57e22B8d331);
        _pair = IUniswapV2Pair(IUniswapV2Factory(UNISWAP_FACTORY).createPair(_dollar, peggedToken()));
        // IMPORTANT, for migrating dsd oracle
        // _pair = IUniswapV2Pair(address(0x2008dDa1Ad792b156599cE55D12Eb82808C80f01));

        (address token0, address token1) = (_pair.token0(), _pair.token1());
        _index = _dollar == token0 ? 0 : 1;

        Require.that(
            _index == 0 || _dollar == token1,
            FILE,
            "Døllar not found"
        );
    }

    /**
     * Trades/Liquidity: (1) Initializes reserve and blockTimestampLast (can calculate a price)
     *                   (2) Has non-zero cumulative prices
     *
     * Steps: (1) Captures a reference blockTimestampLast
     *        (2) First reported value
     */
    function capture() public onlyDao returns (Decimal.D256 memory, bool) {
        if (_initialized) {
            return updateOracle();
        } else {
            initializeOracle();
            _isValid = false;
            return (Decimal.one(), _isValid);
        }
    }

    // Remove debugging function

    function getDecimalFactor() public view returns (uint256) {
        return _pegDecimalFactor;
    }

    function initializeOracle() private {
        IUniswapV2Pair pair = _pair;
        uint256 priceCumulative = _index == 0 ?
            pair.price0CumulativeLast() :
            pair.price1CumulativeLast();
        (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast) = pair.getReserves();
        if(reserve0 != 0 && reserve1 != 0 && blockTimestampLast != 0) {
            _cumulative = priceCumulative;
            _timestamp = blockTimestampLast;
            _initialized = true;
            _reserve = _index == 0 ? reserve1 : reserve0; // get counter's reserve
            _vtdReserve =_index == 0 ? reserve0 : reserve1;
        }
    }

    function updateOracle() private returns (Decimal.D256 memory, bool) {
        Decimal.D256 memory price = updatePrice();
        uint256 lastReserve = updateReserve();
        // bool isBlacklisted = IUSDC(usdc()).isBlacklisted(address(_pair));

        bool valid = true;
        if (lastReserve < Constants.getOracleReserveMinimum()) {
            valid = false;
        }
        if (_reserve < Constants.getOracleReserveMinimum()) {
            valid = false;
        }
        // if (isBlacklisted) {
        //     valid = false;
        // }

        _isValid = valid;
        return (price, valid);
    }

    function updatePrice() private returns (Decimal.D256 memory) {
        (uint256 price0Cumulative, uint256 price1Cumulative, uint32 blockTimestamp) =
        UniswapV2OracleLibrary.currentCumulativePrices(address(_pair));
        uint32 timeElapsed = blockTimestamp - _timestamp; // overflow is desired
        uint256 priceCumulative = _index == 0 ? price0Cumulative : price1Cumulative;
        Decimal.D256 memory price = Decimal.ratio((priceCumulative - _cumulative) / timeElapsed, 2**112);

        _timestamp = blockTimestamp;
        _cumulative = priceCumulative;

        //IMPORTANT this need to be based upon decimal precision of the pegged token
        Decimal.D256 memory lastPrice = price.mul(_pegDecimalFactor);
        _lastPrice = lastPrice.value;
        return lastPrice;
    }

    function getLastPrice() public view returns (Decimal.D256 memory, bool) {
        return (Decimal.D256({value: _lastPrice}), _isValid);
    }

    function updateReserve() private returns (uint256) {
        uint256 lastReserve = _reserve;
        (uint112 reserve0, uint112 reserve1,) = _pair.getReserves();
        _reserve = _index == 0 ? reserve1 : reserve0; // get counter's reserve
        _vtdReserve = _index == 0 ? reserve0 : reserve1;

        return lastReserve;
    }


    function getLastVtdReserve() public view returns (uint256) {
        return _vtdReserve;
    }

    function isOracleValid() public view returns (bool) {
        return _isValid;
    }

    function peggedToken() internal view returns (address) {
        return _peg;
    }

    function pair() external view returns (address) {
        return address(_pair);
    }

    function reserve() external view returns (uint256) {
        return _reserve;
    }

    modifier onlyDao() {
        Require.that(
            msg.sender == _dao,
            FILE,
            "Not dao"
        );

        _;
    }
}

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"address","name":"dollar","type":"address"},{"internalType":"address","name":"peg","type":"address"},{"internalType":"uint256","name":"decimalMultiplier","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"constant":false,"inputs":[],"name":"capture","outputs":[{"components":[{"internalType":"uint256","name":"value","type":"uint256"}],"internalType":"struct Decimal.D256","name":"","type":"tuple"},{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"getDecimalFactor","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getLastPrice","outputs":[{"components":[{"internalType":"uint256","name":"value","type":"uint256"}],"internalType":"struct Decimal.D256","name":"","type":"tuple"},{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getLastVtdReserve","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"isOracleValid","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"pair","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"reserve","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"setup","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}]

60806040523480156200001157600080fd5b506040516200126638038062001266833981016040819052620000349162000098565b600080546001600160a01b03199081163317909155600180546001600160a01b03958616908316179055600280549390941692169190911790915560035562000126565b8051620000858162000101565b92915050565b805162000085816200011b565b600080600060608486031215620000ae57600080fd5b6000620000bc868662000078565b9350506020620000cf8682870162000078565b9250506040620000e2868287016200008b565b9150509250925092565b60006001600160a01b03821662000085565b90565b6200010c81620000ec565b81146200011857600080fd5b50565b6200010c81620000fe565b61113080620001366000396000f3fe608060405234801561001057600080fd5b50600436106100885760003560e01c8063ba0bba401161005b578063ba0bba40146100dd578063cd3293de146100e7578063d4a3e9d7146100ef578063d8cf24fd1461010557610088565b806307e19fe81461008d57806335aaf1ec146100ab578063361394e1146100b3578063a8aa1b31146100c8575b600080fd5b61009561010d565b6040516100a29190611029565b60405180910390f35b610095610113565b6100bb610119565b6040516100a29190610fcf565b6100d0610122565b6040516100a29190610fa6565b6100e5610136565b005b6100956103cd565b6100f76103d3565b6040516100a292919061100e565b6100f761044e565b60035490565b600a5490565b600b5460ff1690565b60045461010090046001600160a01b031690565b600054610162906001600160a01b03163314654f7261636c6560d01b664e6f742064616f60c81b610471565b600080546001600160a01b03191673530608409991c36ba922b69623bec57e22b8d331179055600154735c69bee701ef814a2b6a3edd4b1652cb9cc5aa6f9063c9c65396906001600160a01b03166101b86104d4565b6040518363ffffffff1660e01b81526004016101d5929190610fb4565b602060405180830381600087803b1580156101ef57600080fd5b505af1158015610203573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506102279190810190610d97565b600460016101000a8154816001600160a01b0302191690836001600160a01b03160217905550600080600460019054906101000a90046001600160a01b03166001600160a01b0316630dfe16816040518163ffffffff1660e01b815260040160206040518083038186803b15801561029e57600080fd5b505afa1580156102b2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506102d69190810190610d97565b600460019054906101000a90046001600160a01b03166001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b15801561032457600080fd5b505afa158015610338573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061035c9190810190610d97565b60015491935091506001600160a01b0380841691161461037d576001610380565b60005b60ff1660058190556103c99015806103a557506001546001600160a01b038381169116145b654f7261636c6560d01b701130ee1b1b185c881b9bdd08199bdd5b99607a1b610471565b5050565b60095490565b6103db610d46565b60008054610408906001600160a01b03163314654f7261636c6560d01b664e6f742064616f60c81b610471565b60045460ff16156104245761041b6104e3565b9150915061044a565b61042c61054e565b600b805460ff1916905561043e610770565b600b5490925060ff1690505b9091565b610456610d46565b5060408051602081019091526008548152600b5460ff169091565b826104cf5761047f82610792565b6101d160f51b61048e83610792565b6040516020016104a093929190610f75565b60408051601f198184030181529082905262461bcd60e51b82526104c691600401610fdd565b60405180910390fd5b505050565b6002546001600160a01b031690565b6104eb610d46565b60006104f5610d46565b6104fd610814565b905060006105096108da565b905060016105156109b2565b821015610520575060005b6105286109b2565b6009541015610535575060005b600b805460ff1916821515179055919491935090915050565b6004546005546101009091046001600160a01b031690600090156105e257816001600160a01b0316635a3d54936040518163ffffffff1660e01b815260040160206040518083038186803b1580156105a557600080fd5b505afa1580156105b9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506105dd9190810190610e0a565b610653565b816001600160a01b0316635909c0d56040518163ffffffff1660e01b815260040160206040518083038186803b15801561061b57600080fd5b505afa15801561062f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506106539190810190610e0a565b90506000806000846001600160a01b0316630902f1ac6040518163ffffffff1660e01b815260040160606040518083038186803b15801561069357600080fd5b505afa1580156106a7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506106cb9190810190610dbd565b925092509250826001600160701b03166000141580156106f357506001600160701b03821615155b8015610704575063ffffffff811615155b156107695760068490556007805463ffffffff191663ffffffff83161790556004805460ff191660011790556005541561073e5782610740565b815b6001600160701b03166009556005541561075a578161075c565b825b6001600160701b0316600a555b5050505050565b610778610d46565b506040805160208101909152670de0b6b3a7640000815290565b606080826040516020016107a69190610f60565b60408051601f19818403018152919052905060205b80156107fb578151600019909101908290829081106107d657fe5b01602001516001600160f81b031916156107f6576001018152905061080f565b6107bb565b505060408051600081526020810190915290505b919050565b61081c610d46565b600080600061083f600460019054906101000a90046001600160a01b03166109ba565b600754600554939650919450925063ffffffff16820390600090156108645783610866565b845b9050610870610d46565b6108918363ffffffff1660065484038161088657fe5b04600160701b610b8f565b6007805463ffffffff191663ffffffff8716179055600683905590506108b5610d46565b6003546108c990839063ffffffff610bc016565b805160085597505050505050505090565b6000806009549050600080600460019054906101000a90046001600160a01b03166001600160a01b0316630902f1ac6040518163ffffffff1660e01b815260040160606040518083038186803b15801561093357600080fd5b505afa158015610947573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061096b9190810190610dbd565b50915091506005546000146109805781610982565b805b6001600160701b03166009556005541561099c578061099e565b815b6001600160701b0316600a55509091505090565b633b9aca0090565b60008060006109c7610be7565b9050836001600160a01b0316635909c0d56040518163ffffffff1660e01b815260040160206040518083038186803b158015610a0257600080fd5b505afa158015610a16573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250610a3a9190810190610e0a565b9250836001600160a01b0316635a3d54936040518163ffffffff1660e01b815260040160206040518083038186803b158015610a7557600080fd5b505afa158015610a89573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250610aad9190810190610e0a565b91506000806000866001600160a01b0316630902f1ac6040518163ffffffff1660e01b815260040160606040518083038186803b158015610aed57600080fd5b505afa158015610b01573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250610b259190810190610dbd565b9250925092508363ffffffff168163ffffffff1614610b855780840363ffffffff8116610b528486610bf1565b516001600160e01b031602969096019563ffffffff8116610b738585610bf1565b516001600160e01b0316029590950194505b5050509193909250565b610b97610d46565b6040518060200160405280610bb585670de0b6b3a764000086610c6c565b905290505b92915050565b610bc8610d46565b604080516020810190915283518190610bb5908563ffffffff610c9816565b63ffffffff421690565b610bf9610d59565b6000826001600160701b031611610c225760405162461bcd60e51b81526004016104c690610ffe565b6040805160208101909152806001600160701b0384166dffffffffffffffffffffffffffff60701b607087901b1681610c5757fe5b046001600160e01b0316815250905092915050565b6000610c8e82610c82868663ffffffff610c9816565b9063ffffffff610cd216565b90505b9392505050565b600082610ca757506000610bba565b82820282848281610cb457fe5b0414610c915760405162461bcd60e51b81526004016104c690610fee565b6000610c9183836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f00000000000081525060008183610d305760405162461bcd60e51b81526004016104c69190610fdd565b506000838581610d3c57fe5b0495945050505050565b6040518060200160405280600081525090565b60408051602081019091526000815290565b8051610bba816110bb565b8051610bba816110d2565b8051610bba816110db565b8051610bba816110e4565b600060208284031215610da957600080fd5b6000610db58484610d6b565b949350505050565b600080600060608486031215610dd257600080fd5b6000610dde8686610d76565b9350506020610def86828701610d76565b9250506040610e0086828701610d8c565b9150509250925092565b600060208284031215610e1c57600080fd5b6000610db58484610d81565b610e3181611044565b82525050565b610e318161104f565b610e31610e4c82611054565b611061565b610e31610e4c82611061565b6000610e6882611037565b610e72818561080f565b9350610e82818560208601611085565b9290920192915050565b6000610e9782611037565b610ea1818561103b565b9350610eb1818560208601611085565b610eba816110b1565b9093019392505050565b6000610ed160218361103b565b7f536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f8152607760f81b602082015260400192915050565b6000610f1460178361103b565b7f4669786564506f696e743a204449565f42595f5a45524f000000000000000000815260200192915050565b80516020830190610f518482610f57565b50505050565b610e3181611061565b6000610f6c8284610e51565b50602001919050565b6000610f818286610e5d565b9150610f8d8285610e40565b600282019150610f9d8284610e5d565b95945050505050565b60208101610bba8284610e28565b60408101610fc28285610e28565b610c916020830184610e28565b60208101610bba8284610e37565b60208082528101610c918184610e8c565b60208082528101610bba81610ec4565b60208082528101610bba81610f07565b6040810161101c8285610f40565b610c916020830184610e37565b60208101610bba8284610f57565b5190565b90815260200190565b6000610bba82611070565b151590565b6001600160f01b03191690565b90565b6001600160701b031690565b6001600160a01b031690565b63ffffffff1690565b60005b838110156110a0578181015183820152602001611088565b83811115610f515750506000910152565b601f01601f191690565b6110c481611044565b81146110cf57600080fd5b50565b6110c481611064565b6110c481611061565b6110c48161107c56fea365627a7a72315820d239a8c4d50b8e741c73603e0c06cefec816578ceb48574381c381871c757e666c6578706572696d656e74616cf564736f6c63430005110040000000000000000000000000f0e3543744afced8042131582f2a19b6aeb82794000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000001

Deployed Bytecode

0x608060405234801561001057600080fd5b50600436106100885760003560e01c8063ba0bba401161005b578063ba0bba40146100dd578063cd3293de146100e7578063d4a3e9d7146100ef578063d8cf24fd1461010557610088565b806307e19fe81461008d57806335aaf1ec146100ab578063361394e1146100b3578063a8aa1b31146100c8575b600080fd5b61009561010d565b6040516100a29190611029565b60405180910390f35b610095610113565b6100bb610119565b6040516100a29190610fcf565b6100d0610122565b6040516100a29190610fa6565b6100e5610136565b005b6100956103cd565b6100f76103d3565b6040516100a292919061100e565b6100f761044e565b60035490565b600a5490565b600b5460ff1690565b60045461010090046001600160a01b031690565b600054610162906001600160a01b03163314654f7261636c6560d01b664e6f742064616f60c81b610471565b600080546001600160a01b03191673530608409991c36ba922b69623bec57e22b8d331179055600154735c69bee701ef814a2b6a3edd4b1652cb9cc5aa6f9063c9c65396906001600160a01b03166101b86104d4565b6040518363ffffffff1660e01b81526004016101d5929190610fb4565b602060405180830381600087803b1580156101ef57600080fd5b505af1158015610203573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506102279190810190610d97565b600460016101000a8154816001600160a01b0302191690836001600160a01b03160217905550600080600460019054906101000a90046001600160a01b03166001600160a01b0316630dfe16816040518163ffffffff1660e01b815260040160206040518083038186803b15801561029e57600080fd5b505afa1580156102b2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506102d69190810190610d97565b600460019054906101000a90046001600160a01b03166001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b15801561032457600080fd5b505afa158015610338573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061035c9190810190610d97565b60015491935091506001600160a01b0380841691161461037d576001610380565b60005b60ff1660058190556103c99015806103a557506001546001600160a01b038381169116145b654f7261636c6560d01b701130ee1b1b185c881b9bdd08199bdd5b99607a1b610471565b5050565b60095490565b6103db610d46565b60008054610408906001600160a01b03163314654f7261636c6560d01b664e6f742064616f60c81b610471565b60045460ff16156104245761041b6104e3565b9150915061044a565b61042c61054e565b600b805460ff1916905561043e610770565b600b5490925060ff1690505b9091565b610456610d46565b5060408051602081019091526008548152600b5460ff169091565b826104cf5761047f82610792565b6101d160f51b61048e83610792565b6040516020016104a093929190610f75565b60408051601f198184030181529082905262461bcd60e51b82526104c691600401610fdd565b60405180910390fd5b505050565b6002546001600160a01b031690565b6104eb610d46565b60006104f5610d46565b6104fd610814565b905060006105096108da565b905060016105156109b2565b821015610520575060005b6105286109b2565b6009541015610535575060005b600b805460ff1916821515179055919491935090915050565b6004546005546101009091046001600160a01b031690600090156105e257816001600160a01b0316635a3d54936040518163ffffffff1660e01b815260040160206040518083038186803b1580156105a557600080fd5b505afa1580156105b9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506105dd9190810190610e0a565b610653565b816001600160a01b0316635909c0d56040518163ffffffff1660e01b815260040160206040518083038186803b15801561061b57600080fd5b505afa15801561062f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506106539190810190610e0a565b90506000806000846001600160a01b0316630902f1ac6040518163ffffffff1660e01b815260040160606040518083038186803b15801561069357600080fd5b505afa1580156106a7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506106cb9190810190610dbd565b925092509250826001600160701b03166000141580156106f357506001600160701b03821615155b8015610704575063ffffffff811615155b156107695760068490556007805463ffffffff191663ffffffff83161790556004805460ff191660011790556005541561073e5782610740565b815b6001600160701b03166009556005541561075a578161075c565b825b6001600160701b0316600a555b5050505050565b610778610d46565b506040805160208101909152670de0b6b3a7640000815290565b606080826040516020016107a69190610f60565b60408051601f19818403018152919052905060205b80156107fb578151600019909101908290829081106107d657fe5b01602001516001600160f81b031916156107f6576001018152905061080f565b6107bb565b505060408051600081526020810190915290505b919050565b61081c610d46565b600080600061083f600460019054906101000a90046001600160a01b03166109ba565b600754600554939650919450925063ffffffff16820390600090156108645783610866565b845b9050610870610d46565b6108918363ffffffff1660065484038161088657fe5b04600160701b610b8f565b6007805463ffffffff191663ffffffff8716179055600683905590506108b5610d46565b6003546108c990839063ffffffff610bc016565b805160085597505050505050505090565b6000806009549050600080600460019054906101000a90046001600160a01b03166001600160a01b0316630902f1ac6040518163ffffffff1660e01b815260040160606040518083038186803b15801561093357600080fd5b505afa158015610947573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061096b9190810190610dbd565b50915091506005546000146109805781610982565b805b6001600160701b03166009556005541561099c578061099e565b815b6001600160701b0316600a55509091505090565b633b9aca0090565b60008060006109c7610be7565b9050836001600160a01b0316635909c0d56040518163ffffffff1660e01b815260040160206040518083038186803b158015610a0257600080fd5b505afa158015610a16573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250610a3a9190810190610e0a565b9250836001600160a01b0316635a3d54936040518163ffffffff1660e01b815260040160206040518083038186803b158015610a7557600080fd5b505afa158015610a89573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250610aad9190810190610e0a565b91506000806000866001600160a01b0316630902f1ac6040518163ffffffff1660e01b815260040160606040518083038186803b158015610aed57600080fd5b505afa158015610b01573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250610b259190810190610dbd565b9250925092508363ffffffff168163ffffffff1614610b855780840363ffffffff8116610b528486610bf1565b516001600160e01b031602969096019563ffffffff8116610b738585610bf1565b516001600160e01b0316029590950194505b5050509193909250565b610b97610d46565b6040518060200160405280610bb585670de0b6b3a764000086610c6c565b905290505b92915050565b610bc8610d46565b604080516020810190915283518190610bb5908563ffffffff610c9816565b63ffffffff421690565b610bf9610d59565b6000826001600160701b031611610c225760405162461bcd60e51b81526004016104c690610ffe565b6040805160208101909152806001600160701b0384166dffffffffffffffffffffffffffff60701b607087901b1681610c5757fe5b046001600160e01b0316815250905092915050565b6000610c8e82610c82868663ffffffff610c9816565b9063ffffffff610cd216565b90505b9392505050565b600082610ca757506000610bba565b82820282848281610cb457fe5b0414610c915760405162461bcd60e51b81526004016104c690610fee565b6000610c9183836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f00000000000081525060008183610d305760405162461bcd60e51b81526004016104c69190610fdd565b506000838581610d3c57fe5b0495945050505050565b6040518060200160405280600081525090565b60408051602081019091526000815290565b8051610bba816110bb565b8051610bba816110d2565b8051610bba816110db565b8051610bba816110e4565b600060208284031215610da957600080fd5b6000610db58484610d6b565b949350505050565b600080600060608486031215610dd257600080fd5b6000610dde8686610d76565b9350506020610def86828701610d76565b9250506040610e0086828701610d8c565b9150509250925092565b600060208284031215610e1c57600080fd5b6000610db58484610d81565b610e3181611044565b82525050565b610e318161104f565b610e31610e4c82611054565b611061565b610e31610e4c82611061565b6000610e6882611037565b610e72818561080f565b9350610e82818560208601611085565b9290920192915050565b6000610e9782611037565b610ea1818561103b565b9350610eb1818560208601611085565b610eba816110b1565b9093019392505050565b6000610ed160218361103b565b7f536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f8152607760f81b602082015260400192915050565b6000610f1460178361103b565b7f4669786564506f696e743a204449565f42595f5a45524f000000000000000000815260200192915050565b80516020830190610f518482610f57565b50505050565b610e3181611061565b6000610f6c8284610e51565b50602001919050565b6000610f818286610e5d565b9150610f8d8285610e40565b600282019150610f9d8284610e5d565b95945050505050565b60208101610bba8284610e28565b60408101610fc28285610e28565b610c916020830184610e28565b60208101610bba8284610e37565b60208082528101610c918184610e8c565b60208082528101610bba81610ec4565b60208082528101610bba81610f07565b6040810161101c8285610f40565b610c916020830184610e37565b60208101610bba8284610f57565b5190565b90815260200190565b6000610bba82611070565b151590565b6001600160f01b03191690565b90565b6001600160701b031690565b6001600160a01b031690565b63ffffffff1690565b60005b838110156110a0578181015183820152602001611088565b83811115610f515750506000910152565b601f01601f191690565b6110c481611044565b81146110cf57600080fd5b50565b6110c481611064565b6110c481611061565b6110c48161107c56fea365627a7a72315820d239a8c4d50b8e741c73603e0c06cefec816578ceb48574381c381871c757e666c6578706572696d656e74616cf564736f6c63430005110040

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

000000000000000000000000f0e3543744afced8042131582f2a19b6aeb82794000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000001

-----Decoded View---------------
Arg [0] : dollar (address): 0xf0E3543744AFcEd8042131582f2A19b6AEb82794
Arg [1] : peg (address): 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2
Arg [2] : decimalMultiplier (uint256): 1

-----Encoded View---------------
3 Constructor Arguments found :
Arg [0] : 000000000000000000000000f0e3543744afced8042131582f2a19b6aeb82794
Arg [1] : 000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
Arg [2] : 0000000000000000000000000000000000000000000000000000000000000001


Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

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

Validator Index Block Amount
View All Withdrawals

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

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