ETH Price: $3,503.65 (-1.33%)

Contract

0x981Bd9F77c8AAFC14EBC86769503f86A3CC29aF5
 

Overview

ETH Balance

0 ETH

ETH Value

$0.00

Sponsored

Transaction Hash
Method
Block
From
To
Value
Get Result134470902022-06-29 9:57:20722 days ago1656496640IN
0x981Bd9F7...A3CC29aF5
0 ETH0.000000060.001
Get Result134470662022-06-29 9:56:16722 days ago1656496576IN
0x981Bd9F7...A3CC29aF5
0 ETH0.000000060.001
Get Result134469802022-06-29 9:53:37722 days ago1656496417IN
0x981Bd9F7...A3CC29aF5
0 ETH0.000000060.001
Get Result134456022022-06-29 9:31:46722 days ago1656495106IN
0x981Bd9F7...A3CC29aF5
0 ETH0.000000060.001
0x6080604072232012022-05-06 14:19:15776 days ago1651846755IN
 Create: TarotPriceOracle
0 ETH0.00000050.001

Latest 25 internal transactions (View All)

Advanced mode:
Parent Transaction Hash Block From To Value
1070868472023-07-19 13:14:31337 days ago1689772471
0x981Bd9F7...A3CC29aF5
0 ETH
1070868472023-07-19 13:14:31337 days ago1689772471
0x981Bd9F7...A3CC29aF5
0 ETH
1070868472023-07-19 13:14:31337 days ago1689772471
0x981Bd9F7...A3CC29aF5
0 ETH
1070868472023-07-19 13:14:31337 days ago1689772471
0x981Bd9F7...A3CC29aF5
0 ETH
1070868472023-07-19 13:14:31337 days ago1689772471
0x981Bd9F7...A3CC29aF5
0 ETH
1070868472023-07-19 13:14:31337 days ago1689772471
0x981Bd9F7...A3CC29aF5
0 ETH
1070868472023-07-19 13:14:31337 days ago1689772471
0x981Bd9F7...A3CC29aF5
0 ETH
1070868472023-07-19 13:14:31337 days ago1689772471
0x981Bd9F7...A3CC29aF5
0 ETH
1070868472023-07-19 13:14:31337 days ago1689772471
0x981Bd9F7...A3CC29aF5
0 ETH
1070868472023-07-19 13:14:31337 days ago1689772471
0x981Bd9F7...A3CC29aF5
0 ETH
1070868472023-07-19 13:14:31337 days ago1689772471
0x981Bd9F7...A3CC29aF5
0 ETH
1070868472023-07-19 13:14:31337 days ago1689772471
0x981Bd9F7...A3CC29aF5
0 ETH
1070868472023-07-19 13:14:31337 days ago1689772471
0x981Bd9F7...A3CC29aF5
0 ETH
1070868472023-07-19 13:14:31337 days ago1689772471
0x981Bd9F7...A3CC29aF5
0 ETH
1070868472023-07-19 13:14:31337 days ago1689772471
0x981Bd9F7...A3CC29aF5
0 ETH
1070868472023-07-19 13:14:31337 days ago1689772471
0x981Bd9F7...A3CC29aF5
0 ETH
1070868472023-07-19 13:14:31337 days ago1689772471
0x981Bd9F7...A3CC29aF5
0 ETH
1070868472023-07-19 13:14:31337 days ago1689772471
0x981Bd9F7...A3CC29aF5
0 ETH
1070868472023-07-19 13:14:31337 days ago1689772471
0x981Bd9F7...A3CC29aF5
0 ETH
1070867932023-07-19 13:12:43337 days ago1689772363
0x981Bd9F7...A3CC29aF5
0 ETH
1070867932023-07-19 13:12:43337 days ago1689772363
0x981Bd9F7...A3CC29aF5
0 ETH
1070867932023-07-19 13:12:43337 days ago1689772363
0x981Bd9F7...A3CC29aF5
0 ETH
1070867932023-07-19 13:12:43337 days ago1689772363
0x981Bd9F7...A3CC29aF5
0 ETH
1070867932023-07-19 13:12:43337 days ago1689772363
0x981Bd9F7...A3CC29aF5
0 ETH
1070867932023-07-19 13:12:43337 days ago1689772363
0x981Bd9F7...A3CC29aF5
0 ETH
View All Internal Transactions

Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
TarotPriceOracle

Compiler Version
v0.5.16+commit.9c3226ce

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion
File 1 of 4 : TarotPriceOracle.sol
pragma solidity =0.5.16;

import "./libraries/UQ112x112.sol";
import "./interfaces/IUniswapV2Pair.sol";
import "./interfaces/ITarotPriceOracle.sol";

contract TarotPriceOracle is ITarotPriceOracle {
    using UQ112x112 for uint224;

    uint32 public constant MIN_T = 1200;

    struct Pair {
        uint256 priceCumulativeSlotA;
        uint256 priceCumulativeSlotB;
        uint32 lastUpdateSlotA;
        uint32 lastUpdateSlotB;
        bool latestIsSlotA;
        bool initialized;
    }
    mapping(address => Pair) public getPair;

    event PriceUpdate(
        address indexed pair,
        uint256 priceCumulative,
        uint32 blockTimestamp,
        bool latestIsSlotA
    );

    function toUint224(uint256 input) internal pure returns (uint224) {
        require(input <= uint224(-1), "TarotPriceOracle: UINT224_OVERFLOW");
        return uint224(input);
    }

    function getPriceCumulativeCurrent(address uniswapV2Pair)
        internal
        view
        returns (uint256 priceCumulative)
    {
        priceCumulative = IUniswapV2Pair(uniswapV2Pair).price0CumulativeLast();
        (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast) =
            IUniswapV2Pair(uniswapV2Pair).getReserves();
        uint224 priceLatest = UQ112x112.encode(reserve1).uqdiv(reserve0);
        uint32 timeElapsed = getBlockTimestamp() - blockTimestampLast; // overflow is desired
        // * never overflows, and + overflow is desired
        priceCumulative += uint256(priceLatest) * timeElapsed;
    }

    function initialize(address uniswapV2Pair) external {
        Pair storage pairStorage = getPair[uniswapV2Pair];
        require(
            !pairStorage.initialized,
            "TarotPriceOracle: ALREADY_INITIALIZED"
        );

        uint256 priceCumulativeCurrent =
            getPriceCumulativeCurrent(uniswapV2Pair);
        uint32 blockTimestamp = getBlockTimestamp();
        pairStorage.priceCumulativeSlotA = priceCumulativeCurrent;
        pairStorage.priceCumulativeSlotB = priceCumulativeCurrent;
        pairStorage.lastUpdateSlotA = blockTimestamp;
        pairStorage.lastUpdateSlotB = blockTimestamp;
        pairStorage.latestIsSlotA = true;
        pairStorage.initialized = true;
        emit PriceUpdate(
            uniswapV2Pair,
            priceCumulativeCurrent,
            blockTimestamp,
            true
        );
    }

    function getResult(address uniswapV2Pair)
        external
        returns (uint224 price, uint32 T)
    {
        Pair memory pair = getPair[uniswapV2Pair];
        require(pair.initialized, "TarotPriceOracle: NOT_INITIALIZED");
        Pair storage pairStorage = getPair[uniswapV2Pair];

        uint32 blockTimestamp = getBlockTimestamp();
        uint32 lastUpdateTimestamp =
            pair.latestIsSlotA ? pair.lastUpdateSlotA : pair.lastUpdateSlotB;
        uint256 priceCumulativeCurrent =
            getPriceCumulativeCurrent(uniswapV2Pair);
        uint256 priceCumulativeLast;

        if (blockTimestamp - lastUpdateTimestamp >= MIN_T) {
            // update price
            priceCumulativeLast = pair.latestIsSlotA
                ? pair.priceCumulativeSlotA
                : pair.priceCumulativeSlotB;
            if (pair.latestIsSlotA) {
                pairStorage.priceCumulativeSlotB = priceCumulativeCurrent;
                pairStorage.lastUpdateSlotB = blockTimestamp;
            } else {
                pairStorage.priceCumulativeSlotA = priceCumulativeCurrent;
                pairStorage.lastUpdateSlotA = blockTimestamp;
            }
            pairStorage.latestIsSlotA = !pair.latestIsSlotA;
            emit PriceUpdate(
                uniswapV2Pair,
                priceCumulativeCurrent,
                blockTimestamp,
                !pair.latestIsSlotA
            );
        } else {
            // don't update; return price using previous priceCumulative
            lastUpdateTimestamp = pair.latestIsSlotA
                ? pair.lastUpdateSlotB
                : pair.lastUpdateSlotA;
            priceCumulativeLast = pair.latestIsSlotA
                ? pair.priceCumulativeSlotB
                : pair.priceCumulativeSlotA;
        }

        T = blockTimestamp - lastUpdateTimestamp; // overflow is desired
        require(T >= MIN_T, "TarotPriceOracle: NOT_READY"); //reverts only if the pair has just been initialized
        // / is safe, and - overflow is desired
        price = toUint224((priceCumulativeCurrent - priceCumulativeLast) / T);
    }

    /*** Utilities ***/

    function getBlockTimestamp() public view returns (uint32) {
        return uint32(block.timestamp % 2**32);
    }
}

File 2 of 4 : UQ112x112.sol
pragma solidity =0.5.16;

// 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 3 of 4 : IUniswapV2Pair.sol
pragma solidity =0.5.16;

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

    function name() external view returns (string memory);

    function symbol() external view returns (string memory);

    function decimals() external view returns (uint8);

    function totalSupply() external view returns (uint256);

    function balanceOf(address owner) external view returns (uint256);

    function allowance(address owner, address spender)
        external
        view
        returns (uint256);

    function approve(address spender, uint256 value) external returns (bool);

    function transfer(address to, uint256 value) external returns (bool);

    function transferFrom(
        address from,
        address to,
        uint256 value
    ) external returns (bool);

    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 4 of 4 : ITarotPriceOracle.sol
pragma solidity =0.5.16;

interface ITarotPriceOracle {
    event PriceUpdate(
        address indexed pair,
        uint256 priceCumulative,
        uint32 blockTimestamp,
        bool latestIsSlotA
    );

    function MIN_T() external pure returns (uint32);

    function getPair(address uniswapV2Pair)
        external
        view
        returns (
            uint256 priceCumulativeSlotA,
            uint256 priceCumulativeSlotB,
            uint32 lastUpdateSlotA,
            uint32 lastUpdateSlotB,
            bool latestIsSlotA,
            bool initialized
        );

    function initialize(address uniswapV2Pair) external;

    function getResult(address uniswapV2Pair)
        external
        returns (uint224 price, uint32 T);

    function getBlockTimestamp() external view returns (uint32);
}

Settings
{
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "libraries": {}
}

Contract Security Audit

Contract ABI

[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"pair","type":"address"},{"indexed":false,"internalType":"uint256","name":"priceCumulative","type":"uint256"},{"indexed":false,"internalType":"uint32","name":"blockTimestamp","type":"uint32"},{"indexed":false,"internalType":"bool","name":"latestIsSlotA","type":"bool"}],"name":"PriceUpdate","type":"event"},{"constant":true,"inputs":[],"name":"MIN_T","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getBlockTimestamp","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"getPair","outputs":[{"internalType":"uint256","name":"priceCumulativeSlotA","type":"uint256"},{"internalType":"uint256","name":"priceCumulativeSlotB","type":"uint256"},{"internalType":"uint32","name":"lastUpdateSlotA","type":"uint32"},{"internalType":"uint32","name":"lastUpdateSlotB","type":"uint32"},{"internalType":"bool","name":"latestIsSlotA","type":"bool"},{"internalType":"bool","name":"initialized","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"uniswapV2Pair","type":"address"}],"name":"getResult","outputs":[{"internalType":"uint224","name":"price","type":"uint224"},{"internalType":"uint32","name":"T","type":"uint32"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"uniswapV2Pair","type":"address"}],"name":"initialize","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}]

608060405234801561001057600080fd5b50610843806100206000396000f3fe608060405234801561001057600080fd5b50600436106100575760003560e01c80631a788a021461005c578063446a37e0146100c0578063796b89b91461010e578063c4d66de81461012f578063f51b553114610157575b600080fd5b6100826004803603602081101561007257600080fd5b50356001600160a01b031661015f565b60408051968752602087019590955263ffffffff938416868601529190921660608501529015156080840152151560a0830152519081900360c00190f35b6100e6600480360360208110156100d657600080fd5b50356001600160a01b03166101a9565b604080516001600160e01b03909316835263ffffffff90911660208301528051918290030190f35b61011661046a565b6040805163ffffffff9092168252519081900360200190f35b6101556004803603602081101561014557600080fd5b50356001600160a01b0316610474565b005b6101166105a3565b60006020819052908152604090208054600182015460029092015490919063ffffffff8082169164010000000081049091169060ff600160401b8204811691600160481b90041686565b6000806101b4610771565b506001600160a01b03831660009081526020818152604091829020825160c081018452815481526001820154928101929092526002015463ffffffff808216938301939093526401000000008104909216606082015260ff600160401b8304811615156080830152600160481b909204909116151560a0820181905261026b5760405162461bcd60e51b81526004018080602001828103825260218152602001806107ee6021913960400191505060405180910390fd5b6001600160a01b03841660009081526020819052604081209061028c61046a565b9050600083608001516102a35783606001516102a9565b83604001515b905060006102b6886105a9565b905060006104b083850363ffffffff16106103ad5785608001516102de5785602001516102e1565b85515b905085608001511561031b576001850182905560028501805467ffffffff00000000191664010000000063ffffffff871602179055610336565b81855560028501805463ffffffff191663ffffffff86161790555b6080860151600286018054600160401b921592830260ff60401b199091161790556040805184815263ffffffff8716602082015280820192909252516001600160a01b038b16917fc58c63744da19faddae8e37958053493f49d71b8f78d4facf6002cd1c2618fcf919081900360600190a26103e1565b85608001516103c05785604001516103c6565b85606001515b925085608001516103d85785516103de565b85602001515b90505b82840396506104b063ffffffff88161015610443576040805162461bcd60e51b815260206004820152601b60248201527f5461726f7450726963654f7261636c653a204e4f545f52454144590000000000604482015290519081900360640190fd5b61045d8763ffffffff168284038161045757fe5b046106ee565b9750505050505050915091565b63ffffffff421690565b6001600160a01b03811660009081526020819052604090206002810154600160481b900460ff16156104d75760405162461bcd60e51b81526004018080602001828103825260258152602001806107a76025913960400191505060405180910390fd5b60006104e2836105a9565b905060006104ee61046a565b8284556001808501849055600285018054600160481b600160401b63ffffffff1990921663ffffffff861690811767ffffffff00000000191664010000000082021760ff60401b19169290921769ff0000000000000000001916179091556040805186815260208101929092528181019290925290519192506001600160a01b038616917fc58c63744da19faddae8e37958053493f49d71b8f78d4facf6002cd1c2618fcf916060908290030190a250505050565b6104b081565b6000816001600160a01b0316635909c0d56040518163ffffffff1660e01b815260040160206040518083038186803b1580156105e457600080fd5b505afa1580156105f8573d6000803e3d6000fd5b505050506040513d602081101561060e57600080fd5b505160408051630240bc6b60e21b81529051919250600091829182916001600160a01b03871691630902f1ac916004808301926060929190829003018186803b15801561065a57600080fd5b505afa15801561066e573d6000803e3d6000fd5b505050506040513d606081101561068457600080fd5b5080516020820151604090920151909450909250905060006106be846106a98561073a565b6001600160e01b03169063ffffffff61074c16565b90506000826106cb61046a565b0390508063ffffffff16826001600160e01b031602860195505050505050919050565b60006001600160e01b038211156107365760405162461bcd60e51b81526004018080602001828103825260228152602001806107cc6022913960400191505060405180910390fd5b5090565b6001600160701b0316600160701b0290565b60006001600160701b0382166001600160e01b0384168161076957fe5b049392505050565b6040805160c081018252600080825260208201819052918101829052606081018290526080810182905260a08101919091529056fe5461726f7450726963654f7261636c653a20414c52454144595f494e495449414c495a45445461726f7450726963654f7261636c653a2055494e543232345f4f564552464c4f575461726f7450726963654f7261636c653a204e4f545f494e495449414c495a4544a265627a7a7231582062e16c5583a534a1fb33d119b88916877bd42c3e1389bb2e8dedf71193a281a164736f6c63430005100032

Deployed Bytecode

0x608060405234801561001057600080fd5b50600436106100575760003560e01c80631a788a021461005c578063446a37e0146100c0578063796b89b91461010e578063c4d66de81461012f578063f51b553114610157575b600080fd5b6100826004803603602081101561007257600080fd5b50356001600160a01b031661015f565b60408051968752602087019590955263ffffffff938416868601529190921660608501529015156080840152151560a0830152519081900360c00190f35b6100e6600480360360208110156100d657600080fd5b50356001600160a01b03166101a9565b604080516001600160e01b03909316835263ffffffff90911660208301528051918290030190f35b61011661046a565b6040805163ffffffff9092168252519081900360200190f35b6101556004803603602081101561014557600080fd5b50356001600160a01b0316610474565b005b6101166105a3565b60006020819052908152604090208054600182015460029092015490919063ffffffff8082169164010000000081049091169060ff600160401b8204811691600160481b90041686565b6000806101b4610771565b506001600160a01b03831660009081526020818152604091829020825160c081018452815481526001820154928101929092526002015463ffffffff808216938301939093526401000000008104909216606082015260ff600160401b8304811615156080830152600160481b909204909116151560a0820181905261026b5760405162461bcd60e51b81526004018080602001828103825260218152602001806107ee6021913960400191505060405180910390fd5b6001600160a01b03841660009081526020819052604081209061028c61046a565b9050600083608001516102a35783606001516102a9565b83604001515b905060006102b6886105a9565b905060006104b083850363ffffffff16106103ad5785608001516102de5785602001516102e1565b85515b905085608001511561031b576001850182905560028501805467ffffffff00000000191664010000000063ffffffff871602179055610336565b81855560028501805463ffffffff191663ffffffff86161790555b6080860151600286018054600160401b921592830260ff60401b199091161790556040805184815263ffffffff8716602082015280820192909252516001600160a01b038b16917fc58c63744da19faddae8e37958053493f49d71b8f78d4facf6002cd1c2618fcf919081900360600190a26103e1565b85608001516103c05785604001516103c6565b85606001515b925085608001516103d85785516103de565b85602001515b90505b82840396506104b063ffffffff88161015610443576040805162461bcd60e51b815260206004820152601b60248201527f5461726f7450726963654f7261636c653a204e4f545f52454144590000000000604482015290519081900360640190fd5b61045d8763ffffffff168284038161045757fe5b046106ee565b9750505050505050915091565b63ffffffff421690565b6001600160a01b03811660009081526020819052604090206002810154600160481b900460ff16156104d75760405162461bcd60e51b81526004018080602001828103825260258152602001806107a76025913960400191505060405180910390fd5b60006104e2836105a9565b905060006104ee61046a565b8284556001808501849055600285018054600160481b600160401b63ffffffff1990921663ffffffff861690811767ffffffff00000000191664010000000082021760ff60401b19169290921769ff0000000000000000001916179091556040805186815260208101929092528181019290925290519192506001600160a01b038616917fc58c63744da19faddae8e37958053493f49d71b8f78d4facf6002cd1c2618fcf916060908290030190a250505050565b6104b081565b6000816001600160a01b0316635909c0d56040518163ffffffff1660e01b815260040160206040518083038186803b1580156105e457600080fd5b505afa1580156105f8573d6000803e3d6000fd5b505050506040513d602081101561060e57600080fd5b505160408051630240bc6b60e21b81529051919250600091829182916001600160a01b03871691630902f1ac916004808301926060929190829003018186803b15801561065a57600080fd5b505afa15801561066e573d6000803e3d6000fd5b505050506040513d606081101561068457600080fd5b5080516020820151604090920151909450909250905060006106be846106a98561073a565b6001600160e01b03169063ffffffff61074c16565b90506000826106cb61046a565b0390508063ffffffff16826001600160e01b031602860195505050505050919050565b60006001600160e01b038211156107365760405162461bcd60e51b81526004018080602001828103825260228152602001806107cc6022913960400191505060405180910390fd5b5090565b6001600160701b0316600160701b0290565b60006001600160701b0382166001600160e01b0384168161076957fe5b049392505050565b6040805160c081018252600080825260208201819052918101829052606081018290526080810182905260a08101919091529056fe5461726f7450726963654f7261636c653a20414c52454144595f494e495449414c495a45445461726f7450726963654f7261636c653a2055494e543232345f4f564552464c4f575461726f7450726963654f7261636c653a204e4f545f494e495449414c495a4544a265627a7a7231582062e16c5583a534a1fb33d119b88916877bd42c3e1389bb2e8dedf71193a281a164736f6c63430005100032

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
[ Download: CSV Export  ]
[ 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.