Contract 0xa9cEf2Cc3FFBf79bE5Ec623195bb97d812D3291b

 

Contract Overview

Balance:
0 BNB

BNB Value:
$0.00

Token:
 
Txn Hash Method
Block
From
To
Value [Txn Fee]
0x8fce76b252e4a37ee9e6ef2ceba1b33a65720beed852b19da0b2112fde9f5d33Update72688842021-05-09 11:52:10165 days 14 hrs ago0xa3a502569bf1bfbf7b361964d61335a7530d39e8 IN  0xa9cef2cc3ffbf79be5ec623195bb97d812d3291b0 BNB0.000309045
0x2520fc267e395a82a11d4b91d47b285f01fe7cb2059091f067538cde2ba9e6d2Update72676982021-05-09 10:51:16165 days 15 hrs ago0xa3a502569bf1bfbf7b361964d61335a7530d39e8 IN  0xa9cef2cc3ffbf79be5ec623195bb97d812d3291b0 BNB0.000309045
0x7ab82c66dbad984cb5ffd649082fc5c28a0cc6ae238fb5a4c1248849dd4924c5Update72665362021-05-09 9:50:05165 days 16 hrs ago0xa3a502569bf1bfbf7b361964d61335a7530d39e8 IN  0xa9cef2cc3ffbf79be5ec623195bb97d812d3291b0 BNB0.000309045
0x74b9b288c622ac23bbddda4b51eea3fcd548a8771925641ba64a2ffd91887987Update72653622021-05-09 8:49:13165 days 17 hrs ago0xa3a502569bf1bfbf7b361964d61335a7530d39e8 IN  0xa9cef2cc3ffbf79be5ec623195bb97d812d3291b0 BNB0.000309045
0xc008948760469909fc3c18d458b65937ed1141cdf32577cd8110c6cff3345975Update72641832021-05-09 7:48:09165 days 18 hrs ago0xa3a502569bf1bfbf7b361964d61335a7530d39e8 IN  0xa9cef2cc3ffbf79be5ec623195bb97d812d3291b0 BNB0.000309045
0x60ffcec1c0e78a1689f639f8008d03e73f0dff0060f7eca3b14a6359c250438aUpdate72629892021-05-09 6:47:08165 days 19 hrs ago0xa3a502569bf1bfbf7b361964d61335a7530d39e8 IN  0xa9cef2cc3ffbf79be5ec623195bb97d812d3291b0 BNB0.000309045
0x99cba13ec5a256bbbdfa54e4f67f54bfcf72fce326bc36c5caf7b2e1e21ea4cfUpdate72617752021-05-09 5:46:10165 days 20 hrs ago0xa3a502569bf1bfbf7b361964d61335a7530d39e8 IN  0xa9cef2cc3ffbf79be5ec623195bb97d812d3291b0 BNB0.000309045
0xadf52e3d0a71df69586d604c4a74336545cd38d380d248bd0e2e657e020b8bfbUpdate72605862021-05-09 4:45:18165 days 21 hrs ago0xa3a502569bf1bfbf7b361964d61335a7530d39e8 IN  0xa9cef2cc3ffbf79be5ec623195bb97d812d3291b0 BNB0.000309045
0xa41ac269f9ba0b1273ce61632cff6ad96f2059c11a7f6070e5386dfd55c3bceaUpdate72595322021-05-09 3:44:05165 days 22 hrs ago0xa3a502569bf1bfbf7b361964d61335a7530d39e8 IN  0xa9cef2cc3ffbf79be5ec623195bb97d812d3291b0 BNB0.000309045
0xe8d70d670b12e737fd892feef87cb1eba94d75bc2e952efa13eb3baa2c460d7dUpdate72583582021-05-09 2:43:10165 days 23 hrs ago0xa3a502569bf1bfbf7b361964d61335a7530d39e8 IN  0xa9cef2cc3ffbf79be5ec623195bb97d812d3291b0 BNB0.000309045
0xe654358b3ebf20ab287953884a11935348db3f438843467b44e90beec49d3627Update72571512021-05-09 1:42:06166 days 43 mins ago0xa3a502569bf1bfbf7b361964d61335a7530d39e8 IN  0xa9cef2cc3ffbf79be5ec623195bb97d812d3291b0 BNB0.000309045
0x7be2982a36255b5174763c5780e3794a475df636c19d7b8261534bb0dfa0b5d4Update72560932021-05-09 0:41:08166 days 1 hr ago0xa3a502569bf1bfbf7b361964d61335a7530d39e8 IN  0xa9cef2cc3ffbf79be5ec623195bb97d812d3291b0 BNB0.000309045
0x9067d089e8e5a07f0a8eef235a95b945cd5aae05726d6bde102a7a545ae6de58Update72549032021-05-08 23:40:06166 days 2 hrs ago0xa3a502569bf1bfbf7b361964d61335a7530d39e8 IN  0xa9cef2cc3ffbf79be5ec623195bb97d812d3291b0 BNB0.000309045
0xf8a0532f5a42b084c2327f5367f89550edb347368099f042987e19a586148448Update72536892021-05-08 22:39:08166 days 3 hrs ago0xa3a502569bf1bfbf7b361964d61335a7530d39e8 IN  0xa9cef2cc3ffbf79be5ec623195bb97d812d3291b0 BNB0.000309045
0xe1f67ec4bd55f83b2a8a416d94867e87d30ed567ab35ffe551c70ef602942939Update72524912021-05-08 21:38:07166 days 4 hrs ago0xa3a502569bf1bfbf7b361964d61335a7530d39e8 IN  0xa9cef2cc3ffbf79be5ec623195bb97d812d3291b0 BNB0.00030571
0x53f394afccebf68342affa199cd6469f724fe9721c34680762ea3a17b340ae68Update72513102021-05-08 20:37:09166 days 5 hrs ago0xa3a502569bf1bfbf7b361964d61335a7530d39e8 IN  0xa9cef2cc3ffbf79be5ec623195bb97d812d3291b0 BNB0.000309045
0xe9240e139d8b299943b2ac9e59fe0e6afd4fbd007237f5671399294b3291a27dUpdate72501802021-05-08 19:36:09166 days 6 hrs ago0xa3a502569bf1bfbf7b361964d61335a7530d39e8 IN  0xa9cef2cc3ffbf79be5ec623195bb97d812d3291b0 BNB0.000309045
0x0cb92191e22daa53fe2226e89fecd7c914935c1cbd59b8076bbf6b225e45301bUpdate72489992021-05-08 18:35:06166 days 7 hrs ago0xa3a502569bf1bfbf7b361964d61335a7530d39e8 IN  0xa9cef2cc3ffbf79be5ec623195bb97d812d3291b0 BNB0.000309045
0xa4a2742b22b3c9496b3c78c3f9d92cd951814d9bd216d9f763d0fec8dd34067dUpdate72478662021-05-08 17:34:24166 days 8 hrs ago0xa3a502569bf1bfbf7b361964d61335a7530d39e8 IN  0xa9cef2cc3ffbf79be5ec623195bb97d812d3291b0 BNB0.000162925
0x01f0b50b266d35bfc5e4d5b60e32e506d44b6d8c25bd51e031f1939668ff4f5eUpdate72478662021-05-08 17:34:24166 days 8 hrs ago0xa3a502569bf1bfbf7b361964d61335a7530d39e8 IN  0xa9cef2cc3ffbf79be5ec623195bb97d812d3291b0 BNB0.000162925
0xe617b316af8b8ea1be167f97772f4ba0a217f997351d29f73369df3067dce976Update72478662021-05-08 17:34:24166 days 8 hrs ago0xa3a502569bf1bfbf7b361964d61335a7530d39e8 IN  0xa9cef2cc3ffbf79be5ec623195bb97d812d3291b0 BNB0.000309045
0x7b81f5f19863bfef3c5b692e82fb948b3040937e14f6b9d535efaa0a6c9e0ddfUpdate72467662021-05-08 16:30:32166 days 9 hrs ago0xa3a502569bf1bfbf7b361964d61335a7530d39e8 IN  0xa9cef2cc3ffbf79be5ec623195bb97d812d3291b0 BNB0.000309045
0x891a2f0d131f1510b13df20159fb8cb3430ee80905ada87fe27e2f01f746a128Update72455882021-05-08 15:27:47166 days 10 hrs ago0xa3a502569bf1bfbf7b361964d61335a7530d39e8 IN  0xa9cef2cc3ffbf79be5ec623195bb97d812d3291b0 BNB0.000309045
0x8145dafb8f0751705185f3c3e7da7d4ce7e46e909d7d78064af12c8cd007b8bfUpdate72444572021-05-08 14:25:24166 days 12 hrs ago0xa3a502569bf1bfbf7b361964d61335a7530d39e8 IN  0xa9cef2cc3ffbf79be5ec623195bb97d812d3291b0 BNB0.000162925
0xc79cf1c2429464aef1463aa41934de9725c2eb51029ef15389d991f16c20bce6Update72444512021-05-08 14:25:03166 days 12 hrs ago0xa3a502569bf1bfbf7b361964d61335a7530d39e8 IN  0xa9cef2cc3ffbf79be5ec623195bb97d812d3291b0 BNB0.000309045
[ Download CSV Export 
Parent Txn Hash Block From To Value
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
VSwapPairOracle

Compiler Version
v0.7.6+commit.7338295f

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion, MIT license

Contract Source Code (Solidity Standard Json-Input format)

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

pragma solidity >=0.6.0 <0.8.0;

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

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

pragma solidity >=0.6.0 <0.8.0;

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

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

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

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

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

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

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

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

pragma solidity >=0.6.0 <0.8.0;

/**
 * @dev Wrappers over Solidity's arithmetic operations with added overflow
 * checks.
 *
 * Arithmetic operations in Solidity wrap on overflow. This can easily result
 * in bugs, because programmers usually assume that an overflow raises an
 * error, which is the standard behavior in high level programming languages.
 * `SafeMath` restores this intuition by reverting the transaction when an
 * operation overflows.
 *
 * Using this library instead of the unchecked operations eliminates an entire
 * class of bugs, so it's recommended to use it always.
 */
library SafeMath {
    /**
     * @dev Returns the addition of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        uint256 c = a + b;
        if (c < a) return (false, 0);
        return (true, c);
    }

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

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

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

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

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

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

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

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

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

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

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

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

File 4 of 11 : Context.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

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

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

File 5 of 11 : Operator.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.7.6;

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

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

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

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

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

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

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

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

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

File 6 of 11 : IPairOracle.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.7.6;
pragma experimental ABIEncoderV2;

interface IPairOracle {
    function consult(address token, uint256 amountIn) external view returns (uint256 amountOut);

    function twap(uint256 amountIn) external view returns (uint256 amountOut);

    function update() external;
}

File 7 of 11 : IValueLiquidPair.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.7.6;
pragma experimental ABIEncoderV2;

interface IValueLiquidPair {
    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 (uint256);

    function price1CumulativeLast() external view returns (uint256);
}

File 8 of 11 : Babylonian.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.7.6;

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

File 9 of 11 : FixedPoint.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.7.6;

import "./Babylonian.sol";

// 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 {
        uint256 _x;
    }

    uint8 private constant RESOLUTION = 112;
    uint256 private constant Q112 = uint256(1) << RESOLUTION;
    uint256 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, uint256 y) internal pure returns (uq144x112 memory) {
        uint256 z;
        require(y == 0 || (z = uint256(self._x) * y) / y == uint256(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));
    }
}

File 10 of 11 : UQ112x112.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.7.6;

// a library for handling binary fixed point numbers (https://en.wikipedia.org/wiki/Q_(number_format))

// range: [0, 2**112 - 1]
// resolution: 1 / 2**112

library UQ112x112 {
    uint224 constant Q112 = 2**112;

    // encode a uint112 as a UQ112x112
    function encode(uint112 y) internal pure returns (uint224 z) {
        z = uint224(y) * Q112; // never overflows
    }

    // divide a UQ112x112 by a uint112, returning a UQ112x112
    function uqdiv(uint224 x, uint112 y) internal pure returns (uint224 z) {
        z = x / uint224(y);
    }
}

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

pragma solidity 0.7.6;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/math/SafeMath.sol";
import "../libs/FixedPoint.sol";
import "../libs/UQ112x112.sol";
import "../interfaces/IPairOracle.sol";
import "../interfaces/IValueLiquidPair.sol";
import "../Operator.sol";

contract VSwapPairOracle is Operator, IPairOracle {
    using FixedPoint for *;
    using SafeMath for uint256;

    uint256 public PERIOD = 600; // 1-hour TWAP (time-weighted average price)

    IValueLiquidPair public immutable pair;
    address public immutable token0;
    address public immutable token1;

    uint256 public price0CumulativeLast;
    uint256 public price1CumulativeLast;
    uint32 public blockTimestampLast;
    FixedPoint.uq112x112 public price0Average;
    FixedPoint.uq112x112 public price1Average;

    address public mainToken;

    constructor(address pairAddress, address _mainToken) {
        IValueLiquidPair _pair = IValueLiquidPair(pairAddress);
        pair = _pair;
        token0 = _pair.token0();
        token1 = _pair.token1();
        mainToken = _mainToken;
        price0CumulativeLast = _pair.price0CumulativeLast(); // Fetch the current accumulated price value (1 / 0)
        price1CumulativeLast = _pair.price1CumulativeLast(); // Fetch the current accumulated price value (0 / 1)
        uint112 reserve0;
        uint112 reserve1;
        (reserve0, reserve1, blockTimestampLast) = _pair.getReserves();
        require(reserve0 != 0 && reserve1 != 0, "vSwapPairOracle: NO_RESERVES"); // Ensure that there's liquidity in the pair
    }

    function setPeriod(uint256 _period) external onlyOperator {
        PERIOD = _period;
    }

    function update() external override {
        (uint256 price0Cumulative, uint256 price1Cumulative, uint32 blockTimestamp) = currentCumulativePrices(address(pair));
        uint32 timeElapsed = blockTimestamp - blockTimestampLast; // Overflow is desired

        // Ensure that at least one full period has passed since the last update
        require(timeElapsed >= PERIOD, "vSwapPairOracle: PERIOD_NOT_ELAPSED");

        // Overflow is desired, casting never truncates
        // Cumulative price is in (uq112x112 price * seconds) units so we simply wrap it after division by time elapsed
        price0Average = FixedPoint.uq112x112(uint224((price0Cumulative - price0CumulativeLast) / timeElapsed));
        price1Average = FixedPoint.uq112x112(uint224((price1Cumulative - price1CumulativeLast) / timeElapsed));
        price0CumulativeLast = price0Cumulative;
        price1CumulativeLast = price1Cumulative;
        blockTimestampLast = blockTimestamp;
    }

    // Note this will always return 0 before update has been called successfully for the first time.
    function consult(address token, uint256 amountIn) public view override returns (uint256 amountOut) {
        if (token == token0) {
            amountOut = price0Average.mul(amountIn).decode144();
        } else {
            require(token == token1, "vSwapPairOracle: INVALID_TOKEN");
            amountOut = price1Average.mul(amountIn).decode144();
        }
    }

    function twap(uint256 _amountIn) external view override returns (uint256) {
        return consult(mainToken, _amountIn);
    }

    function currentBlockTimestamp() internal view returns (uint32) {
        return uint32(block.timestamp);
    }

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

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

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

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"address","name":"pairAddress","type":"address"},{"internalType":"address","name":"_mainToken","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOperator","type":"address"},{"indexed":true,"internalType":"address","name":"newOperator","type":"address"}],"name":"OperatorTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[],"name":"PERIOD","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"blockTimestampLast","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amountIn","type":"uint256"}],"name":"consult","outputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isOperator","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"mainToken","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"operator","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pair","outputs":[{"internalType":"contract IValueLiquidPair","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"price0Average","outputs":[{"internalType":"uint224","name":"_x","type":"uint224"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"price0CumulativeLast","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"price1Average","outputs":[{"internalType":"uint224","name":"_x","type":"uint224"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"price1CumulativeLast","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_period","type":"uint256"}],"name":"setPeriod","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"token0","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"token1","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOperator_","type":"address"}],"name":"transferOperator","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amountIn","type":"uint256"}],"name":"twap","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"update","outputs":[],"stateMutability":"nonpayable","type":"function"}]

60e06040526102586002553480156200001757600080fd5b5060405162001468380380620014688339810160408190526200003a916200048f565b60006200004662000432565b600080546001600160a01b0319166001600160a01b0383169081178255604051929350917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908290a3506200009a62000432565b600180546001600160a01b0319166001600160a01b0392831617908190556040519116906000907f74da04524d50c64947f5dd5381ef1a4dca5cba8ed1d816243f9e48aa0b5617ed908290a36000829050806001600160a01b03166080816001600160a01b031660601b81525050806001600160a01b0316630dfe16816040518163ffffffff1660e01b815260040160206040518083038186803b1580156200014257600080fd5b505afa15801562000157573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200017d91906200046b565b6001600160a01b031660a0816001600160a01b031660601b81525050806001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b158015620001d357600080fd5b505afa158015620001e8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200020e91906200046b565b6001600160a01b031660c0816001600160a01b031660601b8152505081600860006101000a8154816001600160a01b0302191690836001600160a01b03160217905550806001600160a01b0316635909c0d56040518163ffffffff1660e01b815260040160206040518083038186803b1580156200028b57600080fd5b505afa158015620002a0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620002c691906200051a565b600381905550806001600160a01b0316635a3d54936040518163ffffffff1660e01b815260040160206040518083038186803b1580156200030657600080fd5b505afa1580156200031b573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200034191906200051a565b600481905550600080826001600160a01b0316630902f1ac6040518163ffffffff1660e01b815260040160606040518083038186803b1580156200038457600080fd5b505afa15801562000399573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620003bf9190620004c6565b6005805463ffffffff191663ffffffff9290921691909117905590925090506001600160701b03821615801590620003ff57506001600160701b03811615155b620004275760405162461bcd60e51b81526004016200041e9062000533565b60405180910390fd5b50505050506200056a565b3390565b80516001600160a01b03811681146200044e57600080fd5b919050565b80516001600160701b03811681146200044e57600080fd5b6000602082840312156200047d578081fd5b620004888262000436565b9392505050565b60008060408385031215620004a2578081fd5b620004ad8362000436565b9150620004bd6020840162000436565b90509250929050565b600080600060608486031215620004db578081fd5b620004e68462000453565b9250620004f66020850162000453565b9150604084015163ffffffff811681146200050f578182fd5b809150509250925092565b6000602082840312156200052c578081fd5b5051919050565b6020808252601c908201527f7653776170506169724f7261636c653a204e4f5f524553455256455300000000604082015260600190565b60805160601c60a05160601c60c05160601c610eb4620005b4600039806103c052806106fd525080610256528061034a5250806105a852806106c75280610a555250610eb46000f3fe608060405234801561001057600080fd5b506004361061012c5760003560e01c80636c1b80e3116100ad578063a8aa1b3111610071578063a8aa1b3114610214578063b4d1d7951461021c578063c5700a0214610224578063d21220a714610239578063f2fde38b146102415761012c565b80636c1b80e3146101e1578063715018a6146101f45780638da5cb5b146101fc578063a2e6204514610204578063a6bb45391461020c5761012c565b80634456eda2116100f45780634456eda21461019f578063570ca735146101b45780635909c0d5146101bc5780635a3d5493146101c45780635e6aaf2c146101cc5761012c565b80630dfe1681146101315780630f3a9f651461014f57806329605e77146101645780633ddac953146101775780633fc15f1514610197575b600080fd5b610139610254565b6040516101469190610d1d565b60405180910390f35b61016261015d366004610ced565b610278565b005b610162610172366004610c55565b6102c6565b61018a610185366004610c76565b610346565b6040516101469190610dca565b610139610451565b6101a7610460565b6040516101469190610d31565b610139610486565b61018a610495565b61018a61049b565b6101d46104a1565b6040516101469190610db6565b61018a6101ef366004610ced565b6104b0565b6101626104d1565b61013961058f565b61016261059e565b6101d46106b6565b6101396106c5565b61018a6106e9565b61022c6106ef565b6040516101469190610dd3565b6101396106fb565b61016261024f366004610c55565b61071f565b7f000000000000000000000000000000000000000000000000000000000000000081565b6001546001600160a01b031633146102c15760405162461bcd60e51b8152600401808060200182810382526024815260200180610e386024913960400191505060405180910390fd5b600255565b6102ce610833565b6001600160a01b03166102df61058f565b6001600160a01b03161461033a576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b61034381610837565b50565b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316836001600160a01b031614156103be5760408051602081019091526006546001600160e01b031681526103ae906103a990846108d4565b610952565b6001600160901b0316905061044b565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316836001600160a01b0316146104185760405162461bcd60e51b815260040161040f90610d3c565b60405180910390fd5b60408051602081019091526007546001600160e01b0316815261043f906103a990846108d4565b6001600160901b031690505b92915050565b6008546001600160a01b031681565b6001546000906001600160a01b0316610477610833565b6001600160a01b031614905090565b6001546001600160a01b031690565b60035481565b60045481565b6007546001600160e01b031681565b6008546000906104c9906001600160a01b031683610346565b90505b919050565b6104d9610833565b6001600160a01b03166104ea61058f565b6001600160a01b031614610545576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b600080546040516001600160a01b03909116907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600080546001600160a01b0319169055565b6000546001600160a01b031690565b60008060006105cc7f0000000000000000000000000000000000000000000000000000000000000000610959565b600554600254939650919450925063ffffffff90811683039190821610156106065760405162461bcd60e51b815260040161040f90610d73565b60405180602001604052808263ffffffff1660035487038161062457fe5b046001600160e01b039081169091529051600680546001600160e01b031916919092161790556040805160208101909152600454819063ffffffff84169086038161066b57fe5b046001600160e01b039081169091529051600780546001600160e01b03191691909216179055506003929092556004556005805463ffffffff191663ffffffff909216919091179055565b6006546001600160e01b031681565b7f000000000000000000000000000000000000000000000000000000000000000081565b60025481565b60055463ffffffff1681565b7f000000000000000000000000000000000000000000000000000000000000000081565b610727610833565b6001600160a01b031661073861058f565b6001600160a01b031614610793576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6001600160a01b0381166107d85760405162461bcd60e51b8152600401808060200182810382526026815260200180610de56026913960400191505060405180910390fd5b600080546040516001600160a01b03808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a3600080546001600160a01b0319166001600160a01b0392909216919091179055565b3390565b6001600160a01b03811661087c5760405162461bcd60e51b815260040180806020018281038252602d815260200180610e0b602d913960400191505060405180910390fd5b6040516001600160a01b038216906000907f74da04524d50c64947f5dd5381ef1a4dca5cba8ed1d816243f9e48aa0b5617ed908290a3600180546001600160a01b0319166001600160a01b0392909216919091179055565b6108dc610c02565b600082158061090257505082516001600160e01b0316828102908382816108ff57fe5b04145b61093d5760405162461bcd60e51b8152600401808060200182810382526023815260200180610e5c6023913960400191505060405180910390fd5b60408051602081019091529081529392505050565b5160701c90565b6000806000610966610b4e565b9050836001600160a01b0316635909c0d56040518163ffffffff1660e01b815260040160206040518083038186803b1580156109a157600080fd5b505afa1580156109b5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109d99190610d05565b9250836001600160a01b0316635a3d54936040518163ffffffff1660e01b815260040160206040518083038186803b158015610a1457600080fd5b505afa158015610a28573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a4c9190610d05565b915060008060007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316630902f1ac6040518163ffffffff1660e01b815260040160606040518083038186803b158015610aac57600080fd5b505afa158015610ac0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ae49190610c9f565b9250925092508363ffffffff168163ffffffff1614610b445780840363ffffffff8116610b118486610b52565b516001600160e01b031602969096019563ffffffff8116610b328585610b52565b516001600160e01b0316029590950194505b5050509193909250565b4290565b610b5a610c15565b6000826001600160701b031611610bb8576040805162461bcd60e51b815260206004820152601760248201527f4669786564506f696e743a204449565f42595f5a45524f000000000000000000604482015290519081900360640190fd5b6040805160208101909152806001600160701b0384166dffffffffffffffffffffffffffff60701b607087901b1681610bed57fe5b046001600160e01b0316815250905092915050565b6040518060200160405280600081525090565b60408051602081019091526000815290565b80356001600160a01b03811681146104cc57600080fd5b80516001600160701b03811681146104cc57600080fd5b600060208284031215610c66578081fd5b610c6f82610c27565b9392505050565b60008060408385031215610c88578081fd5b610c9183610c27565b946020939093013593505050565b600080600060608486031215610cb3578081fd5b610cbc84610c3e565b9250610cca60208501610c3e565b9150604084015163ffffffff81168114610ce2578182fd5b809150509250925092565b600060208284031215610cfe578081fd5b5035919050565b600060208284031215610d16578081fd5b5051919050565b6001600160a01b0391909116815260200190565b901515815260200190565b6020808252601e908201527f7653776170506169724f7261636c653a20494e56414c49445f544f4b454e0000604082015260600190565b60208082526023908201527f7653776170506169724f7261636c653a20504552494f445f4e4f545f454c415060408201526214d15160ea1b606082015260800190565b6001600160e01b0391909116815260200190565b90815260200190565b63ffffffff9190911681526020019056fe4f776e61626c653a206e6577206f776e657220697320746865207a65726f20616464726573736f70657261746f723a207a65726f206164647265737320676976656e20666f72206e6577206f70657261746f726f70657261746f723a2063616c6c6572206973206e6f7420746865206f70657261746f724669786564506f696e743a204d554c5449504c49434154494f4e5f4f564552464c4f57a264697066735822122053cf65b43d7ec0a279420f2c47c1f831bc210ac11a409888ad3fe9b3a8c8446f64736f6c63430007060033000000000000000000000000408aa94ede4c1bdc3295c2ff6a82233823c2bcbe00000000000000000000000034ea3f7162e6f6ed16bd171267ec180fd5c848da

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

000000000000000000000000408aa94ede4c1bdc3295c2ff6a82233823c2bcbe00000000000000000000000034ea3f7162e6f6ed16bd171267ec180fd5c848da

-----Decoded View---------------
Arg [0] : pairAddress (address): 0x408aa94ede4c1bdc3295c2ff6a82233823c2bcbe
Arg [1] : _mainToken (address): 0x34ea3f7162e6f6ed16bd171267ec180fd5c848da

-----Encoded View---------------
2 Constructor Arguments found :
Arg [0] : 000000000000000000000000408aa94ede4c1bdc3295c2ff6a82233823c2bcbe
Arg [1] : 00000000000000000000000034ea3f7162e6f6ed16bd171267ec180fd5c848da


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