Contract 0x734fce17e8A6cCb4a86666214CB040632f92e866

Txn Hash Method
Block
From
To
Value [Txn Fee]
0x67507140af63c2b921ba119a62ce849e2246750713b1214a4ec10ad646608ce6Update119405752022-03-10 17:34:25560 days 21 hrs agoHakuSwap: Deployer IN  0x734fce17e8a6ccb4a86666214cb040632f92e8660 AVAX0.003191579412 29.663172788
0xd73add2204f204d2b0fb2777cc6f083363d499f74058b4468173881a34cbf0c1Update119405752022-03-10 17:34:25560 days 21 hrs agoHakuSwap: Deployer IN  0x734fce17e8a6ccb4a86666214cb040632f92e8660 AVAX0.00162812878 28.921888305
0x9461f498f3758c3e8bbd8cda7b04aaa6dd25af08d6385da6529ba18cb6a4e2a0Update119405572022-03-10 17:33:49560 days 21 hrs agoHakuSwap: Deployer IN  0x734fce17e8a6ccb4a86666214cb040632f92e8660 AVAX0.001653728917 29.376646136
0xff3d536ed94d8adc453890134cc38b7e6cd466bfcf9e7bbf1e2bcbbf66f28bb7Update119405502022-03-10 17:33:35560 days 21 hrs agoHakuSwap: Deployer IN  0x734fce17e8a6ccb4a86666214cb040632f92e8660 AVAX0.00169241167 30.063802012
0x0f8a401f949c0d00bcc0889ae576933a05fafc20f19d14136aaf12956a169032Update119405382022-03-10 17:33:11560 days 21 hrs agoHakuSwap: Deployer IN  0x734fce17e8a6ccb4a86666214cb040632f92e8660 AVAX0.00171065173 30.387816295
0x3fb3259c553d7916814e545c55e6571a3edcb2a8b6888f215accb244365a6d56Update119405252022-03-10 17:32:45560 days 21 hrs agoHakuSwap: Deployer IN  0x734fce17e8a6ccb4a86666214cb040632f92e8660 AVAX0.001766457982 31.379151992
0x105156f7ddc2d53006d8618780c02d99ed0ec95dbd8acc335153d4fa09197ebdUpdate119405172022-03-10 17:32:29560 days 21 hrs agoHakuSwap: Deployer IN  0x734fce17e8a6ccb4a86666214cb040632f92e8660 AVAX0.001803604249 32.03901391
0xfeec8f7ddea6de995c880d72cd8e339bc9e0f39a2fba82e887c0f8d0f6d0c67bUpdate119405082022-03-10 17:32:11560 days 21 hrs agoHakuSwap: Deployer IN  0x734fce17e8a6ccb4a86666214cb040632f92e8660 AVAX0.00180695594 32.098552959
0xafc45574b0fbc730f2034ef8eec849efaf9e37f4322171c0dfee6539549b127eUpdate119404862022-03-10 17:31:28560 days 21 hrs agoHakuSwap: Deployer IN  0x734fce17e8a6ccb4a86666214cb040632f92e8660 AVAX0.001965216898 34.90988203
0xaedba68bd409efd47e7c8d2879b63a93de46f0f349dbd3b312cff74cb1b81241Update119404782022-03-10 17:31:12560 days 21 hrs agoHakuSwap: Deployer IN  0x734fce17e8a6ccb4a86666214cb040632f92e8660 AVAX0.00196742644 34.949132071
0x0e340e33b9cfa708806df152da5096b2da814b5257ca094bf8ebad46bf9f399aUpdate119404782022-03-10 17:31:12560 days 21 hrs agoHakuSwap: Deployer IN  0x734fce17e8a6ccb4a86666214cb040632f92e8660 AVAX0.001935090311 34.374716864
0xc08424b03da52e5c8204904833c9fee8b8cfa468376d613b9bc3eac32725a670Update119404782022-03-10 17:31:12560 days 21 hrs agoHakuSwap: Deployer IN  0x734fce17e8a6ccb4a86666214cb040632f92e8660 AVAX0.001910115719 33.931071159
0x001b354d9e388f8b4c9dd3c51b6d1d0fea64cab3af1fb61e8cbc7daaa7e6ebbcUpdate119404782022-03-10 17:31:12560 days 21 hrs agoHakuSwap: Deployer IN  0x734fce17e8a6ccb4a86666214cb040632f92e8660 AVAX0.001063800685 33.73503792
0x968408049661708367d365d25f9411f09d47aeb82ce48fb25b9851f4a66fb76cUpdate119404782022-03-10 17:31:12560 days 21 hrs agoHakuSwap: Deployer IN  0x734fce17e8a6ccb4a86666214cb040632f92e8660 AVAX0.001892735527 33.622331473
0x8820722ae380497472cbf8b488d23ff70e261ab68ecc2e2216be8bba95f94138Update119404782022-03-10 17:31:12560 days 21 hrs agoHakuSwap: Deployer IN  0x734fce17e8a6ccb4a86666214cb040632f92e8660 AVAX0.001858291982 33.010480371
0x10157553808715b4b12afc895b1e922bc252722376d2354252fe59bd8dc140b0Update119404782022-03-10 17:31:12560 days 21 hrs agoHakuSwap: Deployer IN  0x734fce17e8a6ccb4a86666214cb040632f92e8660 AVAX0.001861799273 33.072783478
0x084210ef24473bff7c65d81457525261bdc02a7a5ad926fc77478d72e9c39a17Update119404782022-03-10 17:31:12560 days 21 hrs agoHakuSwap: Deployer IN  0x734fce17e8a6ccb4a86666214cb040632f92e8660 AVAX0.001855193739 32.955443563
0xa67d33c253ef9abc8bcf08909719fd4fadabce2941be28fdea5d63624fa8451bUpdate110777562022-02-18 11:19:48581 days 3 hrs agoHakuSwap: Deployer IN  0x734fce17e8a6ccb4a86666214cb040632f92e8660 AVAX0.00268985 25
0xee68f814f4fd9d76f46d2a000ef0be68c340e8e55695ddbf5f0856dbccd851b0Update106608962022-02-08 18:32:20590 days 20 hrs agoHakuSwap: Deployer IN  0x734fce17e8a6ccb4a86666214cb040632f92e8660 AVAX0.002759885241 25.650921442
0xc09850ed03a5720787d05a4bcc8ab1cb296b0d55a0d7013bf9ed3e81fe9afb01Update106600982022-02-08 18:06:19590 days 20 hrs agoHakuSwap: Deployer IN  0x734fce17e8a6ccb4a86666214cb040632f92e8660 AVAX0.0028147 50
0x0ae12a6093f78a1f8ec1e80aef2e86cd64a6cd941039cc6cba31b996c1bf4dbcUpdate106583272022-02-08 17:08:22590 days 21 hrs agoHakuSwap: Deployer IN  0x734fce17e8a6ccb4a86666214cb040632f92e8660 AVAX0.002740465709 25.470432451
0xc55ef877bd95c7c1439f79f6425d8bbde020314b9d86bf531bcefe204a633de1Update106551182022-02-08 15:21:12590 days 23 hrs agoHakuSwap: Deployer IN  0x734fce17e8a6ccb4a86666214cb040632f92e8660 AVAX0.00140735 25
0x3bb47e295a83074470b620d66ea699a55d2684b30067514c57a9dda292af909cUpdate106551102022-02-08 15:20:56590 days 23 hrs agoHakuSwap: Deployer IN  0x734fce17e8a6ccb4a86666214cb040632f92e8660 AVAX0.00144339478 25.640295239
0xb66567e738bdc0fece7afae679d1eb51cfde07143aae11d040584574c2cbcf9eUpdate106551102022-02-08 15:20:56590 days 23 hrs agoHakuSwap: Deployer IN  0x734fce17e8a6ccb4a86666214cb040632f92e8660 AVAX0.001426486939 25.339946337
0x0a83a7560a2219da0902e95e0cae63e2d887daf609670c6183c66519efe70e32Update106551102022-02-08 15:20:56590 days 23 hrs agoHakuSwap: Deployer IN  0x734fce17e8a6ccb4a86666214cb040632f92e8660 AVAX0.00140735 25
[ Download CSV Export 
Parent Txn Hash Block From To Value
Index Block
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
Oracle

Compiler Version
v0.6.12+commit.27d51765

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion, MIT license

Contract Source Code (Solidity)

/**
 *Submitted for verification at snowtrace.io on 2022-01-14
*/

// File: contracts/interfaces/IHakuswapFactory.sol

// SPDX-License-Identifier: MIT

pragma solidity >=0.5.0;

interface IHakuswapFactory {
    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 expectPairFor(address token0, address token1) external view returns (address);
    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;
}

// File: contracts/interfaces/IHakuswapPair.sol


pragma solidity >=0.5.0;

interface IHakuswapPair {
    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;
}

// File: contracts/libraries/SafeMath.sol


pragma solidity >=0.4.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, 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.
     */
    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.
     */
    function div(
        uint256 a,
        uint256 b,
        string memory errorMessage
    ) internal pure returns (uint256) {
        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.
     */
    function mod(
        uint256 a,
        uint256 b,
        string memory errorMessage
    ) internal pure returns (uint256) {
        require(b != 0, errorMessage);
        return a % b;
    }

    function min(uint256 x, uint256 y) internal pure returns (uint256 z) {
        z = x < y ? x : y;
    }

    // babylonian method (https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method)
    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;
        }
    }
}

// File: contracts/libraries/HakuswapLibrary.sol


pragma solidity >=0.5.0;




library HakuswapLibrary {
    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, 'HakuswapLibrary: IDENTICAL_ADDRESSES');
        (token0, token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);
        require(token0 != address(0), 'HakuswapLibrary: 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'f0a389c88c385a3fa20755278000aabbe86028f1b77659475569f3575b2aebe3' // 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);
        pairFor(factory, tokenA, tokenB);
        (uint reserve0, uint reserve1,) = IHakuswapPair(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, 'HakuswapLibrary: INSUFFICIENT_AMOUNT');
        require(reserveA > 0 && reserveB > 0, 'HakuswapLibrary: INSUFFICIENT_LIQUIDITY');
        amountB = amountA.mul(reserveB) / reserveA;
    }

    // given an input amount of an asset and pair reserves, returns the maximum output amount of the other asset
    function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) internal pure returns (uint amountOut) {
        require(amountIn > 0, 'HakuswapLibrary: INSUFFICIENT_INPUT_AMOUNT');
        require(reserveIn > 0 && reserveOut > 0, 'HakuswapLibrary: INSUFFICIENT_LIQUIDITY');
        uint amountInWithFee = amountIn.mul(998);
        uint numerator = amountInWithFee.mul(reserveOut);
        uint denominator = reserveIn.mul(1000).add(amountInWithFee);
        amountOut = numerator / denominator;
    }

    // given an output amount of an asset and pair reserves, returns a required input amount of the other asset
    function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) internal pure returns (uint amountIn) {
        require(amountOut > 0, 'HakuswapLibrary: INSUFFICIENT_OUTPUT_AMOUNT');
        require(reserveIn > 0 && reserveOut > 0, 'HakuswapLibrary: INSUFFICIENT_LIQUIDITY');
        uint numerator = reserveIn.mul(amountOut).mul(1000);
        uint denominator = reserveOut.sub(amountOut).mul(998);
        amountIn = (numerator / denominator).add(2);
    }

    // performs chained getAmountOut calculations on any number of pairs
    function getAmountsOut(address factory, uint amountIn, address[] memory path) internal view returns (uint[] memory amounts) {
        require(path.length >= 2, 'HakuswapLibrary: INVALID_PATH');
        amounts = new uint[](path.length);
        amounts[0] = amountIn;
        for (uint i; i < path.length - 1; i++) {
            (uint reserveIn, uint reserveOut) = getReserves(factory, path[i], path[i + 1]);
            amounts[i + 1] = getAmountOut(amounts[i], reserveIn, reserveOut);
        }
    }

    // performs chained getAmountIn calculations on any number of pairs
    function getAmountsIn(address factory, uint amountOut, address[] memory path) internal view returns (uint[] memory amounts) {
        require(path.length >= 2, 'HakuswapLibrary: INVALID_PATH');
        amounts = new uint[](path.length);
        amounts[amounts.length - 1] = amountOut;
        for (uint i = path.length - 1; i > 0; i--) {
            (uint reserveIn, uint reserveOut) = getReserves(factory, path[i - 1], path[i]);
            amounts[i - 1] = getAmountIn(amounts[i], reserveIn, reserveOut);
        }
    }
}

// File: contracts/farm/Oracle.sol


pragma solidity >=0.6.6;




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;

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

library HakuswapOracleLibrary {
    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 = IHakuswapPair(pair).price0CumulativeLast();
        price1Cumulative = IHakuswapPair(pair).price1CumulativeLast();

        // if time has elapsed since the last update on the pair, mock the accumulated price values
        (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast) = IHakuswapPair(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;
        }
    }
}

contract Oracle {
    using FixedPoint for *;
    using SafeMath for uint;

    struct Observation {
        uint timestamp;
        uint price0Cumulative;
        uint price1Cumulative;
    }

    address public immutable factory;
    uint public constant CYCLE = 30 minutes;

    // mapping from pair address to a list of price observations of that pair
    mapping(address => Observation) public pairObservations;

    constructor(address factory_) public {
        factory = factory_;
    }


    function update(address tokenA, address tokenB) external {
        if (IHakuswapFactory(factory).getPair(tokenA, tokenB) == address(0)) {
            return;
        }
        address pair = IHakuswapFactory(factory).expectPairFor(tokenA, tokenB);

        Observation storage observation = pairObservations[pair];
        uint timeElapsed = block.timestamp - observation.timestamp;
        require(timeElapsed >= CYCLE, 'MDEXOracle: PERIOD_NOT_ELAPSED');
        (uint price0Cumulative, uint price1Cumulative,) = HakuswapOracleLibrary.currentCumulativePrices(pair);
        observation.timestamp = block.timestamp;
        observation.price0Cumulative = price0Cumulative;
        observation.price1Cumulative = price1Cumulative;
    }


    function computeAmountOut(
        uint priceCumulativeStart, uint priceCumulativeEnd,
        uint timeElapsed, uint amountIn
    ) private pure returns (uint amountOut) {
        // overflow is desired.
        FixedPoint.uq112x112 memory priceAverage = FixedPoint.uq112x112(
            uint224((priceCumulativeEnd - priceCumulativeStart) / timeElapsed)
        );
        amountOut = priceAverage.mul(amountIn).decode144();
    }


    function consult(address tokenIn, uint amountIn, address tokenOut) external view returns (uint amountOut) {
        address pair = IHakuswapFactory(factory).expectPairFor(tokenIn, tokenOut);
        Observation storage observation = pairObservations[pair];
        uint timeElapsed = block.timestamp - observation.timestamp;
        (uint price0Cumulative, uint price1Cumulative,) = HakuswapOracleLibrary.currentCumulativePrices(pair);
        (address token0,) = HakuswapLibrary.sortTokens(tokenIn, tokenOut);

        if (token0 == tokenIn) {
            return computeAmountOut(observation.price0Cumulative, price0Cumulative, timeElapsed, amountIn);
        } else {
            return computeAmountOut(observation.price1Cumulative, price1Cumulative, timeElapsed, amountIn);
        }
    }
}

Contract ABI

[{"inputs":[{"internalType":"address","name":"factory_","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"CYCLE","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"tokenIn","type":"address"},{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"address","name":"tokenOut","type":"address"}],"name":"consult","outputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"factory","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"pairObservations","outputs":[{"internalType":"uint256","name":"timestamp","type":"uint256"},{"internalType":"uint256","name":"price0Cumulative","type":"uint256"},{"internalType":"uint256","name":"price1Cumulative","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"tokenA","type":"address"},{"internalType":"address","name":"tokenB","type":"address"}],"name":"update","outputs":[],"stateMutability":"nonpayable","type":"function"}]

60a060405234801561001057600080fd5b50604051610a2b380380610a2b8339818101604052602081101561003357600080fd5b5051606081901b6001600160601b0319166080526001600160a01b03166109b56100766000398061016a52806102a752806102f6528061038052506109b56000f3fe608060405234801561001057600080fd5b50600436106100575760003560e01c8063402e1abf1461005c5780638c86f1e4146100a05780639e8d48d0146100e8578063c45a0155146100f0578063c640752d14610114575b600080fd5b6100826004803603602081101561007257600080fd5b50356001600160a01b0316610144565b60408051938452602084019290925282820152519081900360600190f35b6100d6600480360360608110156100b657600080fd5b506001600160a01b03813581169160208101359160409091013516610165565b60408051918252519081900360200190f35b6100d661029f565b6100f86102a5565b604080516001600160a01b039092168252519081900360200190f35b6101426004803603604081101561012a57600080fd5b506001600160a01b03813581169160200135166102c9565b005b60006020819052908152604090208054600182015460029092015490919083565b6000807f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166368942ce486856040518363ffffffff1660e01b815260040180836001600160a01b03168152602001826001600160a01b031681526020019250505060206040518083038186803b1580156101e657600080fd5b505afa1580156101fa573d6000803e3d6000fd5b505050506040513d602081101561021057600080fd5b50516001600160a01b03811660009081526020819052604081208054929350914203908061023d856104c9565b5091509150600061024e8a89610698565b509050896001600160a01b0316816001600160a01b031614156102885761027b856001015484868c610776565b9650505050505050610298565b61027b856002015483868c610776565b9392505050565b61070881565b7f000000000000000000000000000000000000000000000000000000000000000081565b6040805163e6a4390560e01b81526001600160a01b038481166004830152838116602483015291516000927f0000000000000000000000000000000000000000000000000000000000000000169163e6a43905916044808301926020929190829003018186803b15801561033c57600080fd5b505afa158015610350573d6000803e3d6000fd5b505050506040513d602081101561036657600080fd5b50516001600160a01b0316141561037c576104c5565b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166368942ce484846040518363ffffffff1660e01b815260040180836001600160a01b03168152602001826001600160a01b031681526020019250505060206040518083038186803b1580156103fc57600080fd5b505afa158015610410573d6000803e3d6000fd5b505050506040513d602081101561042657600080fd5b50516001600160a01b0381166000908152602081905260409020805491925090420361070881101561049f576040805162461bcd60e51b815260206004820152601e60248201527f4d4445584f7261636c653a20504552494f445f4e4f545f454c41505345440000604482015290519081900360640190fd5b6000806104ab856104c9565b504286556001860191909155600290940193909355505050505b5050565b60008060006104d66107d4565b9050836001600160a01b0316635909c0d56040518163ffffffff1660e01b815260040160206040518083038186803b15801561051157600080fd5b505afa158015610525573d6000803e3d6000fd5b505050506040513d602081101561053b57600080fd5b505160408051635a3d549360e01b815290519194506001600160a01b03861691635a3d549391600480820192602092909190829003018186803b15801561058157600080fd5b505afa158015610595573d6000803e3d6000fd5b505050506040513d60208110156105ab57600080fd5b505160408051630240bc6b60e21b81529051919350600091829182916001600160a01b03891691630902f1ac916004808301926060929190829003018186803b1580156105f757600080fd5b505afa15801561060b573d6000803e3d6000fd5b505050506040513d606081101561062157600080fd5b5080516020820151604090920151909450909250905063ffffffff8082169085161461068e5780840363ffffffff811661065b84866107de565b516001600160e01b031602969096019563ffffffff811661067c85856107de565b516001600160e01b0316029590950194505b5050509193909250565b600080826001600160a01b0316846001600160a01b031614156106ec5760405162461bcd60e51b81526004018080602001828103825260248152602001806109396024913960400191505060405180910390fd5b826001600160a01b0316846001600160a01b03161061070c57828461070f565b83835b90925090506001600160a01b03821661076f576040805162461bcd60e51b815260206004820152601d60248201527f48616b75737761704c6962726172793a205a45524f5f41444452455353000000604482015290519081900360640190fd5b9250929050565b6000610780610913565b6040518060200160405280858888038161079657fe5b046001600160e01b0316905290506107b66107b1828561088e565b61090c565b71ffffffffffffffffffffffffffffffffffff169695505050505050565b63ffffffff421690565b6107e6610913565b6000826001600160701b031611610844576040805162461bcd60e51b815260206004820152601760248201527f4669786564506f696e743a204449565f42595f5a45524f000000000000000000604482015290519081900360640190fd5b6040805160208101909152806001600160701b0384166dffffffffffffffffffffffffffff60701b607087901b168161087957fe5b046001600160e01b0316815250905092915050565b610896610925565b60008215806108bc57505082516001600160e01b0316828102908382816108b957fe5b04145b6108f75760405162461bcd60e51b815260040180806020018281038252602381526020018061095d6023913960400191505060405180910390fd5b60408051602081019091529081529392505050565b5160701c90565b60408051602081019091526000815290565b604051806020016040528060008152509056fe48616b75737761704c6962726172793a204944454e544943414c5f4144445245535345534669786564506f696e743a204d554c5449504c49434154494f4e5f4f564552464c4f57a26469706673582212205ec5cd3d9e5559f8f41c8e989ed238d51d735cb0cf8ff4a5b5e8567a5fb2eb6164736f6c634300060c00330000000000000000000000002db46feb38c57a6621bca4d97820e1fc1de40f41

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

0000000000000000000000002db46feb38c57a6621bca4d97820e1fc1de40f41

-----Decoded View---------------
Arg [0] : factory_ (address): 0x2db46feb38c57a6621bca4d97820e1fc1de40f41

-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 0000000000000000000000002db46feb38c57a6621bca4d97820e1fc1de40f41


Deployed ByteCode Sourcemap

17599:2540:0:-:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;17973:55;;;;;;;;;;;;;;;;-1:-1:-1;17973:55:0;-1:-1:-1;;;;;17973:55:0;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;19331:805;;;;;;;;;;;;;;;;-1:-1:-1;;;;;;19331:805:0;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;17846:39;;;:::i;17807:32::-;;;:::i;:::-;;;;-1:-1:-1;;;;;17807:32:0;;;;;;;;;;;;;;18121:748;;;;;;;;;;;;;;;;-1:-1:-1;;;;;;18121:748:0;;;;;;;;;;:::i;:::-;;17973:55;;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;19331:805::-;19421:14;19448:12;19480:7;-1:-1:-1;;;;;19463:39:0;;19503:7;19512:8;19463:58;;;;;;;;;;;;;-1:-1:-1;;;;;19463:58:0;;;;;;-1:-1:-1;;;;;19463:58:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;19463:58:0;-1:-1:-1;;;;;19566:22:0;;19532:31;19566:22;;;19463:58;19566:22;;;;;;19636:21;;19463:58;;-1:-1:-1;19566:22:0;19618:15;:39;;19532:31;19718:51;19463:58;19718:45;:51::i;:::-;19668:101;;;;;19781:14;19800:45;19827:7;19836:8;19800:26;:45::i;:::-;19780:65;;;19872:7;-1:-1:-1;;;;;19862:17:0;:6;-1:-1:-1;;;;;19862:17:0;;19858:271;;;19903:87;19920:11;:28;;;19950:16;19968:11;19981:8;19903:16;:87::i;:::-;19896:94;;;;;;;;;;19858:271;20030:87;20047:11;:28;;;20077:16;20095:11;20108:8;20030:16;:87::i;19331:805::-;;;;;;:::o;17846:39::-;17875:10;17846:39;:::o;17807:32::-;;;:::o;18121:748::-;18193:49;;;-1:-1:-1;;;18193:49:0;;-1:-1:-1;;;;;18193:49:0;;;;;;;;;;;;;;;;18254:1;;18210:7;18193:33;;;;:49;;;;;;;;;;;;;;:33;:49;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;18193:49:0;-1:-1:-1;;;;;18193:63:0;;18189:102;;;18273:7;;18189:102;18301:12;18333:7;-1:-1:-1;;;;;18316:39:0;;18356:6;18364;18316:55;;;;;;;;;;;;;-1:-1:-1;;;;;18316:55:0;;;;;;-1:-1:-1;;;;;18316:55:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;18316:55:0;-1:-1:-1;;;;;18418:22:0;;18384:31;18418:22;;;18316:55;18418:22;;;;;;18488:21;;18316:55;;-1:-1:-1;18418:22:0;18470:15;:39;17875:10;18528:20;;;18520:63;;;;;-1:-1:-1;;;18520:63:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;18595:21;18618;18644:51;18690:4;18644:45;:51::i;:::-;-1:-1:-1;18730:15:0;18706:39;;18756:28;;;:47;;;;18814:28;;;;:47;;;;-1:-1:-1;;;;18121:748:0;;;:::o;16537:1055::-;16623:21;16646;16669;16720:23;:21;:23::i;:::-;16703:40;;16787:4;-1:-1:-1;;;;;16773:40:0;;:42;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;16773:42:0;16845;;;-1:-1:-1;;;16845:42:0;;;;16773;;-1:-1:-1;;;;;;16845:40:0;;;;;:42;;;;;16773;;16845;;;;;;;;:40;:42;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;16845:42:0;17067:33;;;-1:-1:-1;;;17067:33:0;;;;16845:42;;-1:-1:-1;17002:16:0;;;;;;-1:-1:-1;;;;;17067:31:0;;;;;:33;;;;;;;;;;;;;;:31;:33;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;17067:33:0;;;;;;;;;;;;;-1:-1:-1;17067:33:0;;-1:-1:-1;17067:33:0;-1:-1:-1;17115:36:0;;;;;;;;17111:474;;17237:35;;;17383:62;;;17388:39;17408:8;17418;17388:19;:39::i;:::-;:42;-1:-1:-1;;;;;17383:48:0;:62;17363:82;;;;;17511:62;;;17516:39;17536:8;17546;17516:19;:39::i;:::-;:42;-1:-1:-1;;;;;17511:48:0;:62;17491:82;;;;;-1:-1:-1;17111:474:0;16537:1055;;;;;;;;:::o;9663:347::-;9738:14;9754;9799:6;-1:-1:-1;;;;;9789:16:0;:6;-1:-1:-1;;;;;9789:16:0;;;9781:65;;;;-1:-1:-1;;;9781:65:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;9885:6;-1:-1:-1;;;;;9876:15:0;:6;-1:-1:-1;;;;;9876:15:0;;:53;;9914:6;9922;9876:53;;;9895:6;9903;9876:53;9857:72;;-1:-1:-1;9857:72:0;-1:-1:-1;;;;;;9948:20:0;;9940:62;;;;;-1:-1:-1;;;9940:62:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;9663:347;;;;;:::o;18879:442::-;19037:14;19097:40;;:::i;:::-;19140:112;;;;;;;;19229:11;19205:20;19184:18;:41;19183:57;;;;;;-1:-1:-1;;;;;19140:112:0;;;19097:155;-1:-1:-1;19275:38:0;:26;19097:155;19292:8;19275:16;:26::i;:::-;:36;:38::i;:::-;19263:50;;;18879:442;-1:-1:-1;;;;;;18879:442:0:o;16308:123::-;16397:25;:15;:25;;16308:123::o;15445:246::-;15526:16;;:::i;:::-;15577:1;15563:11;-1:-1:-1;;;;;15563:15:0;;15555:51;;;;;-1:-1:-1;;;15555:51:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;15624:59;;;;;;;;;;-1:-1:-1;;;;;15634:48:0;;-1:-1:-1;;;14307:3:0;15635:32;;;;15634:48;;;;;;-1:-1:-1;;;;;15624:59:0;;;;15617:66;;15445:246;;;;:::o;15036:253::-;15103:16;;:::i;:::-;15132:6;15157;;;:54;;-1:-1:-1;;15203:7:0;;-1:-1:-1;;;;;15198:13:0;15172:17;;;;15193:1;15172:17;15193:1;15167:27;;;;;:44;15157:54;15149:102;;;;-1:-1:-1;;;15149:102:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;15269:12;;;;;;;;;;;;;15036:253;-1:-1:-1;;;15036:253:0:o;15990:130::-;16090:7;14307:3;16090:21;;15990:130::o;-1:-1:-1:-;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;;;;;:::o

Swarm Source

ipfs://5ec5cd3d9e5559f8f41c8e989ed238d51d735cb0cf8ff4a5b5e8567a5fb2eb61
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.