ETH Price: $1,908.90 (-5.92%)

Contract

0xf07ca0e66A798547E4CB3899EC592e1E99Ef6Cb3
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To

There are no matching entries

Please try again later

View more zero value Internal Transactions in Advanced View mode

Advanced mode:
Loading...
Loading

Similar Match Source Code
This contract matches the deployed Bytecode of the Source Code for Contract 0xa6CBCb55...73238653e
The constructor portion of the code might be different and could alter the actual behaviour of the contract

Contract Name:
Aggor_ETH_USD_1

Compiler Version
v0.8.16+commit.07a7930e

Optimization Enabled:
Yes with 10000 runs

Other Settings:
london EvmVersion
File 1 of 20 : Aggor.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;

import {Auth} from "chronicle-std/auth/Auth.sol";
import {IToll} from "chronicle-std/toll/IToll.sol";

import {IChronicle} from "chronicle-std/IChronicle.sol";
import {IChainlinkAggregatorV3} from
    "./interfaces/_external/IChainlinkAggregatorV3.sol";

import {IERC20} from "forge-std/interfaces/IERC20.sol";
import {IUniswapV3Pool} from
    "uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol";

import {IAggor} from "./IAggor.sol";

import {LibUniswapOracles} from "./libs/LibUniswapOracles.sol";
import {LibMedian} from "./libs/LibMedian.sol";

/**
 * @title Aggor
 * @custom:version v1.0.1
 *
 * @notice Oracle aggregator distributing trust among different oracle providers
 *
 * @dev While Chronicle oracles normally use the chronicle-std/Toll module for
 *      access controlling read functions, this implementation adopts a
 *      non-configurable, inlined approach. Two addresses are granted read access:
 *      the zero address and `_bud`, which are immutably set during deployment.
 *
 *      Nevertheless, the full IToll interface is implemented to ensure compatibility.
 *
 * @author Chronicle Labs, Inc
 * @custom:security-contact [email protected]
 */
contract Aggor is IAggor, IToll, Auth {
    using LibUniswapOracles for address;

    // -- Internal Constants --

    /// @dev The maximum number of decimals for Uniswap's base asset supported.
    uint internal constant _MAX_UNISWAP_BASE_DECIMALS = 38;

    /// @dev The decimals value used by Chronicle Protocol oracles.
    uint8 internal constant _DECIMALS_CHRONICLE = 18;

    // -- Immutable Configurations --

    // -- Chainlink Compatibility

    /// @inheritdoc IAggor
    uint8 public constant decimals = 8;

    // -- Toll

    /// @dev Bud is the only non-zero address being toll'ed.
    address internal immutable _bud;

    // -- Oracles

    /// @inheritdoc IAggor
    address public immutable chronicle;
    /// @inheritdoc IAggor
    address public immutable chainlink;

    // -- Twap

    /// @inheritdoc IAggor
    address public immutable uniswapPool;
    /// @inheritdoc IAggor
    address public immutable uniswapBaseToken;
    /// @inheritdoc IAggor
    address public immutable uniswapQuoteToken;
    /// @inheritdoc IAggor
    uint8 public immutable uniswapBaseTokenDecimals;
    /// @inheritdoc IAggor
    uint8 public immutable uniswapQuoteTokenDecimals;
    /// @inheritdoc IAggor
    uint32 public immutable uniswapLookback;

    // -- Mutable Configurations --

    /// @inheritdoc IAggor
    uint128 public agreementDistance;
    /// @inheritdoc IAggor
    uint32 public ageThreshold;

    // -- Modifier --

    modifier toll() {
        if (msg.sender != _bud && msg.sender != address(0)) {
            revert NotTolled(msg.sender);
        }
        _;
    }

    // -- Constructor --

    constructor(
        address initialAuthed,
        address bud_,
        address chronicle_,
        address chainlink_,
        address uniswapPool_,
        address uniswapBaseToken_,
        address uniswapQuoteToken_,
        uint8 uniswapBaseTokenDecimals_,
        uint8 uniswapQuoteTokenDecimals_,
        uint32 uniswapLookback_,
        uint128 agreementDistance_,
        uint32 ageThreshold_
    ) Auth(initialAuthed) {
        // Verify twap config arguments.
        _verifyTwapConfig(
            uniswapPool_,
            uniswapBaseToken_,
            uniswapQuoteToken_,
            uniswapBaseTokenDecimals_,
            uniswapQuoteTokenDecimals_,
            uniswapLookback_
        );

        // Set immutables.
        _bud = bud_;
        chronicle = chronicle_;
        chainlink = chainlink_;
        uniswapPool = uniswapPool_;
        uniswapBaseToken = uniswapBaseToken_;
        uniswapQuoteToken = uniswapQuoteToken_;
        uniswapBaseTokenDecimals = uniswapBaseTokenDecimals_;
        uniswapQuoteTokenDecimals = uniswapQuoteTokenDecimals_;
        uniswapLookback = uniswapLookback_;

        // Emit events indicating address(0) and _bud are tolled.
        // Note to use address(0) as caller to indicate address was toll'ed
        // during deployment.
        emit TollGranted(address(0), address(0));
        emit TollGranted(address(0), _bud);

        // Set configurations.
        _setAgreementDistance(agreementDistance_);
        _setAgeThreshold(ageThreshold_);
    }

    function _verifyTwapConfig(
        address uniswapPool_,
        address uniswapBaseToken_,
        address uniswapQuoteToken_,
        uint8 uniswapBaseTokenDecimals_,
        uint8 uniswapQuoteTokenDecimals_,
        uint32 uniswapLookback_
    ) internal view {
        require(uniswapPool_ != address(0), "Uniswap pool must not be zero");

        address token0 = IUniswapV3Pool(uniswapPool_).token0();
        address token1 = IUniswapV3Pool(uniswapPool_).token1();

        // Verify base and quote tokens.
        require(
            uniswapBaseToken_ != uniswapQuoteToken_,
            "Uniswap tokens must not be equal"
        );
        require(
            uniswapBaseToken_ == token0 || uniswapBaseToken_ == token1,
            "Uniswap base token mismatch"
        );
        require(
            uniswapQuoteToken_ == token0 || uniswapQuoteToken_ == token1,
            "Uniswap quote token mismatch"
        );

        // Verify token decimals.
        require(
            uniswapBaseTokenDecimals_ == IERC20(uniswapBaseToken_).decimals(),
            "Uniswap base token decimals mismatch"
        );
        require(
            uniswapBaseTokenDecimals_ <= _MAX_UNISWAP_BASE_DECIMALS,
            "Uniswap base token decimals too high"
        );
        require(
            uniswapQuoteTokenDecimals_ == IERC20(uniswapQuoteToken_).decimals(),
            "Uniswap quote token decimals mismatch"
        );

        // Verify TWAP is initialized.
        // Specifically, verify that the TWAP's oldest observation is older
        // then the uniswapLookback argument.
        uint32 oldestObservation = uniswapPool_.getOldestObservationSecondsAgo();
        require(
            oldestObservation > uniswapLookback_, "Uniswap lookback too high"
        );
    }

    // -- Read Functionality --

    /// @dev Returns Aggor's derived value, timestamp and status information.
    ///
    /// @dev Note that the value's age is always block.timestamp except if the
    ///      value itself is invalid.
    ///
    /// @return uint128 Aggor's current value.
    /// @return uint The value's age.
    /// @return Status The status information.
    function _read() internal view returns (uint128, uint, Status memory) {
        // Read Chronicle and Chainlink oracles.
        (bool okChr, uint128 valChr) = _readChronicle();
        (bool okChl, uint128 valChl) = _readChainlink();

        uint age = block.timestamp;

        if (okChr && okChl) {
            // If both oracles ok and in agreement distance, return their median.
            if (_inAgreementDistance(valChr, valChl)) {
                return (
                    LibMedian.median(valChr, valChl),
                    age,
                    Status({path: 2, goodOracleCtr: 2})
                );
            }

            // If both oracles ok but not in agreement distance, derive value
            // using TWAP as tie breaker.
            (bool okTwap, uint128 valTwap) = _readTwap();
            if (okTwap) {
                return (
                    LibMedian.median(valChr, valChl, valTwap),
                    age,
                    Status({path: 3, goodOracleCtr: 2})
                );
            }

            // Otherwise not possible to decide which oracle is ok.
        } else if (okChr) {
            // If only Chronicle ok, use Chronicle's value.
            return (valChr, age, Status({path: 4, goodOracleCtr: 1}));
        } else if (okChl) {
            // If only Chainlink ok, use Chainlink's value.
            return (valChl, age, Status({path: 4, goodOracleCtr: 1}));
        }

        // If no oracle ok use TWAP.
        (bool ok, uint128 twap) = _readTwap();
        if (ok) {
            return (twap, age, Status({path: 5, goodOracleCtr: 0}));
        }

        // Otherwise no value derivation possible.
        return (0, 0, Status({path: 6, goodOracleCtr: 0}));
    }

    /// @dev Reads the Chronicle oracle.
    ///
    /// @dev Note that while chronicle uses 18 decimals, the returned value is
    ///      already scaled to `decimals`.
    ///
    /// @return bool Whether oracle is ok.
    /// @return uint128 The oracle's val.
    function _readChronicle() internal view returns (bool, uint128) {
        // Note that Chronicle's `try...` functions revert iff the caller is not
        // toll'ed.
        try IChronicle(chronicle).tryReadWithAge() returns (
            bool ok, uint val, uint age
        ) {
            // assert(val <= type(uint128).max);
            // assert(!ok || val != 0); // ok -> val != 0
            // assert(age <= block.timestamp);

            // Fail if not ok or value stale.
            if (!ok || age + ageThreshold < block.timestamp) {
                return (false, 0);
            }

            // Scale value down from Chronicle decimals to Aggor decimals.
            // assert(_DECIMALS_CHRONICLES >= decimals).
            val /= 10 ** (_DECIMALS_CHRONICLE - decimals);

            return (true, uint128(val));
        } catch {
            // assert(!IToll(chronicle).tolled(address(this)));
            return (false, 0);
        }
    }

    /// @dev Reads the Chainlink oracle.
    ///
    /// @return bool Whether oracle is ok.
    /// @return uint128 The oracle's val.
    function _readChainlink() internal view returns (bool, uint128) {
        // !!! IMPORTANT WARNING !!!
        //
        // This function implementation MUST NOT be used when the Chainlink
        // oracle's implementation is behind a proxy!
        //
        // Otherwise a malicious contract update is possible via which every
        // read will fail. Note that this vulnerability _cannot_ be fixed via
        // using try-catch as of version 0.8.24. This is because the abi.decoding
        // of the return data is "outside" the try-block.
        //
        // The only way to fully protect against malicious contract updates is
        // via using a low-level staticcall with _manual_ returndata decoding!
        //
        // Note that the trust towards Chainlink not performing a malicious
        // contract update is different from the trust to not maliciously update
        // the oracle's configuration. While the latter can lead to invalid and
        // malicious price updates, the first may lead to a total
        // denial-of-service for protocols reading the proxy.

        try IChainlinkAggregatorV3(chainlink).latestRoundData() returns (
            uint80, /*roundId*/
            int answer,
            uint, /*startedAt*/
            uint updatedAt,
            uint80 /*answeredInRound*/
        ) {
            // Decide whether value is stale.
            // Unchecked to circumvent revert due to overflow. Overflow otherwise
            // no issue as updatedAt is solely controlled by Chainlink anyway.
            bool isStale;
            unchecked {
                isStale = updatedAt + ageThreshold < block.timestamp;
            }

            // Fail if answer stale or not in [1, type(uint128).max].
            if (
                isStale || answer <= 0 || uint(answer) > uint(type(uint128).max)
            ) {
                return (false, 0);
            }

            // Otherwise ok.
            return (true, uint128(uint(answer)));
        } catch {
            return (false, 0);
        }
    }

    /// @dev Reads the twap oracle.
    ///
    /// @return bool Whether twap is ok.
    /// @return uint128 The twap's val.
    function _readTwap() internal view returns (bool, uint128) {
        // Read twap.
        uint twap = uniswapPool.readOracle(
            uniswapBaseToken,
            uniswapQuoteToken,
            uniswapBaseTokenDecimals,
            uniswapLookback
        );

        if (uniswapQuoteTokenDecimals <= decimals) {
            // Scale up
            twap *= 10 ** (decimals - uniswapQuoteTokenDecimals);
        } else {
            // Scale down
            twap /= 10 ** (uniswapQuoteTokenDecimals - decimals);
        }

        if (twap <= type(uint128).max) {
            return (true, uint128(twap));
        } else {
            return (false, 0);
        }
    }

    // -- IChainlinkAggregatorV3

    /// @inheritdoc IAggor
    function latestRoundData()
        external
        view
        virtual
        toll
        returns (
            uint80 roundId,
            int answer,
            uint startedAt,
            uint updatedAt,
            uint80 answeredInRound
        )
    {
        (uint128 val, uint age, /*status*/ ) = _read();

        roundId = 1;
        answer = int(uint(val));
        startedAt = 0;
        updatedAt = age;
        answeredInRound = 1; // = roundId
    }

    /// @inheritdoc IAggor
    function latestAnswer() external view toll returns (int) {
        (uint128 val, /*age*/, /*status*/ ) = _read();

        return int(uint(val));
    }

    // -- IAggor

    /// @inheritdoc IAggor
    function readWithStatus()
        external
        view
        toll
        returns (uint, uint, Status memory)
    {
        return _read();
    }

    // -- Auth'ed Functionality --

    /// @inheritdoc IAggor
    function setAgreementDistance(uint128 agreementDistance_) external auth {
        _setAgreementDistance(agreementDistance_);
    }

    function _setAgreementDistance(uint128 agreementDistance_) internal {
        require(agreementDistance_ != 0);
        require(agreementDistance_ <= 1e18);

        if (agreementDistance != agreementDistance_) {
            emit AgreementDistanceUpdated(
                msg.sender, agreementDistance, agreementDistance_
            );
            agreementDistance = agreementDistance_;
        }
    }

    /// @inheritdoc IAggor
    function setAgeThreshold(uint32 ageThreshold_) external auth {
        _setAgeThreshold(ageThreshold_);
    }

    function _setAgeThreshold(uint32 ageThreshold_) internal {
        require(ageThreshold_ != 0);

        if (ageThreshold != ageThreshold_) {
            emit AcceptableAgeThresholdUpdated(
                msg.sender, ageThreshold, ageThreshold_
            );
            ageThreshold = ageThreshold_;
        }
    }

    // -- IToll Functionality --

    /// @inheritdoc IToll
    /// @dev Function is disabled!
    function kiss(address /*who*/ ) external view auth {
        revert();
    }

    /// @inheritdoc IToll
    /// @dev Function is disabled!
    function diss(address /*who*/ ) external view auth {
        revert();
    }

    /// @inheritdoc IToll
    function tolled(address who) public view returns (bool) {
        return who == _bud || who == address(0);
    }

    /// @inheritdoc IToll
    function tolled() external view returns (address[] memory) {
        address[] memory result = new address[](2);
        result[0] = address(0);
        result[1] = _bud;

        return result;
    }

    /// @inheritdoc IToll
    function bud(address who) external view returns (uint) {
        return tolled(who) ? 1 : 0;
    }

    // -- Internal Helpers --

    function _inAgreementDistance(uint128 a, uint128 b)
        internal
        view
        returns (bool)
    {
        if (a > b) {
            return uint(b) * 1e18 >= agreementDistance * uint(a);
        } else {
            return uint(a) * 1e18 >= agreementDistance * uint(b);
        }
    }
}

/**
 * @dev Contract overwrite to deploy contract instances with specific naming.
 *
 *      For more info, see docs/Deployment.md.
 */
contract Aggor_ETH_USD_1 is Aggor {
    constructor(
        address initialAuthed,
        address bud_,
        address chronicle_,
        address chainlink_,
        address uniswapPool_,
        address uniswapBaseToken_,
        address uniswapQuoteToken_,
        uint8 uniswapBaseDec_,
        uint8 uniswapQuoteDec_,
        uint32 uniswapLookback_,
        uint128 agreementDistance_,
        uint32 ageThreshold_
    )
        Aggor(
            initialAuthed,
            bud_,
            chronicle_,
            chainlink_,
            uniswapPool_,
            uniswapBaseToken_,
            uniswapQuoteToken_,
            uniswapBaseDec_,
            uniswapQuoteDec_,
            uniswapLookback_,
            agreementDistance_,
            ageThreshold_
        )
    {}
}

File 2 of 20 : Auth.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;

import {IAuth} from "./IAuth.sol";

/**
 * @title Auth Module
 *
 * @dev The `Auth` contract module provides a basic access control mechanism,
 *      where a set of addresses are granted access to protected functions.
 *      These addresses are said to be _auth'ed_.
 *
 *      Initially, the address given as constructor argument is the only address
 *      auth'ed. Through the `rely(address)` and `deny(address)` functions,
 *      auth'ed callers are able to grant/renounce auth to/from addresses.
 *
 *      This module is used through inheritance. It will make available the
 *      modifier `auth`, which can be applied to functions to restrict their
 *      use to only auth'ed callers.
 */
abstract contract Auth is IAuth {
    /// @dev Mapping storing whether address is auth'ed.
    /// @custom:invariant Image of mapping is {0, 1}.
    ///                     ∀x ∊ Address: _wards[x] ∊ {0, 1}
    /// @custom:invariant Only address given as constructor argument is authenticated after deployment.
    ///                     deploy(initialAuthed) → (∀x ∊ Address: _wards[x] == 1 → x == initialAuthed)
    /// @custom:invariant Only functions `rely` and `deny` may mutate the mapping's state.
    ///                     ∀x ∊ Address: preTx(_wards[x]) != postTx(_wards[x])
    ///                                     → (msg.sig == "rely" ∨ msg.sig == "deny")
    /// @custom:invariant Mapping's state may only be mutated by authenticated caller.
    ///                     ∀x ∊ Address: preTx(_wards[x]) != postTx(_wards[x]) → _wards[msg.sender] = 1
    mapping(address => uint) private _wards;

    /// @dev List of addresses possibly being auth'ed.
    /// @dev May contain duplicates.
    /// @dev May contain addresses not being auth'ed anymore.
    /// @custom:invariant Every address being auth'ed once is element of the list.
    ///                     ∀x ∊ Address: authed(x) -> x ∊ _wardsTouched
    address[] private _wardsTouched;

    /// @dev Ensures caller is auth'ed.
    modifier auth() {
        assembly ("memory-safe") {
            // Compute slot of _wards[msg.sender].
            mstore(0x00, caller())
            mstore(0x20, _wards.slot)
            let slot := keccak256(0x00, 0x40)

            // Revert if caller not auth'ed.
            let isAuthed := sload(slot)
            if iszero(isAuthed) {
                // Store selector of `NotAuthorized(address)`.
                mstore(0x00, 0x4a0bfec1)
                // Store msg.sender.
                mstore(0x20, caller())
                // Revert with (offset, size).
                revert(0x1c, 0x24)
            }
        }
        _;
    }

    constructor(address initialAuthed) {
        _wards[initialAuthed] = 1;
        _wardsTouched.push(initialAuthed);

        // Note to use address(0) as caller to indicate address was auth'ed
        // during deployment.
        emit AuthGranted(address(0), initialAuthed);
    }

    /// @inheritdoc IAuth
    function rely(address who) external auth {
        if (_wards[who] == 1) return;

        _wards[who] = 1;
        _wardsTouched.push(who);
        emit AuthGranted(msg.sender, who);
    }

    /// @inheritdoc IAuth
    function deny(address who) external auth {
        if (_wards[who] == 0) return;

        _wards[who] = 0;
        emit AuthRenounced(msg.sender, who);
    }

    /// @inheritdoc IAuth
    function authed(address who) public view returns (bool) {
        return _wards[who] == 1;
    }

    /// @inheritdoc IAuth
    /// @custom:invariant Only contains auth'ed addresses.
    ///                     ∀x ∊ authed(): _wards[x] == 1
    /// @custom:invariant Contains all auth'ed addresses.
    ///                     ∀x ∊ Address: _wards[x] == 1 → x ∊ authed()
    function authed() public view returns (address[] memory) {
        // Initiate array with upper limit length.
        address[] memory wardsList = new address[](_wardsTouched.length);

        // Iterate through all possible auth'ed addresses.
        uint ctr;
        for (uint i; i < wardsList.length; i++) {
            // Add address only if still auth'ed.
            if (_wards[_wardsTouched[i]] == 1) {
                wardsList[ctr++] = _wardsTouched[i];
            }
        }

        // Set length of array to number of auth'ed addresses actually included.
        assembly ("memory-safe") {
            mstore(wardsList, ctr)
        }

        return wardsList;
    }

    /// @inheritdoc IAuth
    function wards(address who) public view returns (uint) {
        return _wards[who];
    }
}

File 3 of 20 : IToll.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;

interface IToll {
    /// @notice Thrown by protected function if caller not tolled.
    /// @param caller The caller's address.
    error NotTolled(address caller);

    /// @notice Emitted when toll granted to address.
    /// @param caller The caller's address.
    /// @param who The address toll got granted to.
    event TollGranted(address indexed caller, address indexed who);

    /// @notice Emitted when toll renounced from address.
    /// @param caller The caller's address.
    /// @param who The address toll got renounced from.
    event TollRenounced(address indexed caller, address indexed who);

    /// @notice Grants address `who` toll.
    /// @dev Only callable by auth'ed address.
    /// @param who The address to grant toll.
    function kiss(address who) external;

    /// @notice Renounces address `who`'s toll.
    /// @dev Only callable by auth'ed address.
    /// @param who The address to renounce toll.
    function diss(address who) external;

    /// @notice Returns whether address `who` is tolled.
    /// @param who The address to check.
    /// @return True if `who` is tolled, false otherwise.
    function tolled(address who) external view returns (bool);

    /// @notice Returns full list of addresses tolled.
    /// @dev May contain duplicates.
    /// @return List of addresses tolled.
    function tolled() external view returns (address[] memory);

    /// @notice Returns whether address `who` is tolled.
    /// @custom:deprecated Use `tolled(address)(bool)` instead.
    /// @param who The address to check.
    /// @return 1 if `who` is tolled, 0 otherwise.
    function bud(address who) external view returns (uint);
}

File 4 of 20 : IChronicle.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;

/**
 * @title IChronicle
 *
 * @notice Interface for Chronicle Protocol's oracle products
 */
interface IChronicle {
    /// @notice Returns the oracle's identifier.
    /// @return wat The oracle's identifier.
    function wat() external view returns (bytes32 wat);

    /// @notice Returns the oracle's current value.
    /// @dev Reverts if no value set.
    /// @return value The oracle's current value.
    function read() external view returns (uint value);

    /// @notice Returns the oracle's current value and its age.
    /// @dev Reverts if no value set.
    /// @return value The oracle's current value.
    /// @return age The value's age.
    function readWithAge() external view returns (uint value, uint age);

    /// @notice Returns the oracle's current value.
    /// @return isValid True if value exists, false otherwise.
    /// @return value The oracle's current value if it exists, zero otherwise.
    function tryRead() external view returns (bool isValid, uint value);

    /// @notice Returns the oracle's current value and its age.
    /// @return isValid True if value exists, false otherwise.
    /// @return value The oracle's current value if it exists, zero otherwise.
    /// @return age The value's age if value exists, zero otherwise.
    function tryReadWithAge()
        external
        view
        returns (bool isValid, uint value, uint age);
}

File 5 of 20 : IChainlinkAggregatorV3.sol
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.0;

interface IChainlinkAggregatorV3 {
    function decimals() external view returns (uint8);

    function latestRoundData()
        external
        view
        returns (
            uint80 roundId,
            int answer,
            uint startedAt,
            uint updatedAt,
            uint80 answeredInRound
        );
}

File 6 of 20 : IERC20.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.2;

/// @dev Interface of the ERC20 standard as defined in the EIP.
/// @dev This includes the optional name, symbol, and decimals metadata.
interface IERC20 {
    /// @dev Emitted when `value` tokens are moved from one account (`from`) to another (`to`).
    event Transfer(address indexed from, address indexed to, uint256 value);

    /// @dev Emitted when the allowance of a `spender` for an `owner` is set, where `value`
    /// is the new allowance.
    event Approval(address indexed owner, address indexed spender, uint256 value);

    /// @notice Returns the amount of tokens in existence.
    function totalSupply() external view returns (uint256);

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

    /// @notice Moves `amount` tokens from the caller's account to `to`.
    function transfer(address to, uint256 amount) external returns (bool);

    /// @notice Returns the remaining number of tokens that `spender` is allowed
    /// to spend on behalf of `owner`
    function allowance(address owner, address spender) external view returns (uint256);

    /// @notice Sets `amount` as the allowance of `spender` over the caller's tokens.
    /// @dev Be aware of front-running risks: https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
    function approve(address spender, uint256 amount) external returns (bool);

    /// @notice Moves `amount` tokens from `from` to `to` using the allowance mechanism.
    /// `amount` is then deducted from the caller's allowance.
    function transferFrom(address from, address to, uint256 amount) external returns (bool);

    /// @notice Returns the name of the token.
    function name() external view returns (string memory);

    /// @notice Returns the symbol of the token.
    function symbol() external view returns (string memory);

    /// @notice Returns the decimals places of the token.
    function decimals() external view returns (uint8);
}

File 7 of 20 : IUniswapV3Pool.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

import './pool/IUniswapV3PoolImmutables.sol';
import './pool/IUniswapV3PoolState.sol';
import './pool/IUniswapV3PoolDerivedState.sol';
import './pool/IUniswapV3PoolActions.sol';
import './pool/IUniswapV3PoolOwnerActions.sol';
import './pool/IUniswapV3PoolEvents.sol';

/// @title The interface for a Uniswap V3 Pool
/// @notice A Uniswap pool facilitates swapping and automated market making between any two assets that strictly conform
/// to the ERC20 specification
/// @dev The pool interface is broken up into many smaller pieces
interface IUniswapV3Pool is
    IUniswapV3PoolImmutables,
    IUniswapV3PoolState,
    IUniswapV3PoolDerivedState,
    IUniswapV3PoolActions,
    IUniswapV3PoolOwnerActions,
    IUniswapV3PoolEvents
{

}

File 8 of 20 : IAggor.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;

interface IAggor {
    /// @notice Status encapsulates Aggor's value derivation path.
    /// @custom:field path The path identifier.
    /// @custom:field goodOracleCtr The number of oracles used to derive the
    ///                             value.
    struct Status {
        uint path;
        uint goodOracleCtr;
    }

    /// @notice Emitted when agreement distance is updated.
    /// @param caller The caller's address.
    /// @param oldAgreementDistance Old agreement distance
    /// @param newAgreementDistance New agreement distance
    event AgreementDistanceUpdated(
        address indexed caller,
        uint oldAgreementDistance,
        uint newAgreementDistance
    );

    /// @notice Emitted when age threshold updated.
    /// @param caller The caller's address.
    /// @param oldAgeThreshold Old age threshold.
    /// @param newAgeThreshold New age threshold.
    event AcceptableAgeThresholdUpdated(
        address indexed caller, uint oldAgeThreshold, uint newAgeThreshold
    );

    // -- Chainlink Compatibility --

    /// @notice Returns the number of decimals of the oracle's value.
    /// @return decimals The oracle value's number of decimals.
    function decimals() external view returns (uint8 decimals);

    /// @notice Returns the oracle's latest value.
    /// @dev Provides partial compatibility to Chainlink's
    ///      IAggregatorV3Interface.
    /// @return roundId 1.
    /// @return answer The oracle's latest value.
    /// @return startedAt 0.
    /// @return updatedAt The timestamp of oracle's latest update.
    /// @return answeredInRound 1.
    function latestRoundData()
        external
        view
        returns (
            uint80 roundId,
            int answer,
            uint startedAt,
            uint updatedAt,
            uint80 answeredInRound
        );

    /// @notice Returns the oracle's latest value.
    /// @custom:deprecated See https://docs.chain.link/data-feeds/api-reference/#latestanswer.
    /// @return answer The oracle's latest value.
    function latestAnswer() external view returns (int answer);

    // -- Other Read Functions --

    /// @notice Returns the oracle's latest value and status information.
    /// @return val The oracle's value.
    /// @return age The value's age.
    /// @return status The status information.
    function readWithStatus()
        external
        view
        returns (uint val, uint age, Status memory status);

    // -- Immutable Configurations --

    // -- Oracles

    /// @notice Returns the Chronicle oracle.
    /// @return chronicle The Chronicle oracle address.
    function chronicle() external view returns (address chronicle);

    /// @notice Returns the Chainlink oracle.
    /// @return chainlink The Chainlink oracle address.
    function chainlink() external view returns (address chainlink);

    // -- Uniswap TWAP

    /// @notice Returns the Uniswap pool used as twap.
    /// @return pool The Uniswap pool.
    function uniswapPool() external view returns (address pool);

    /// @notice Returns the Uniswap pool's base token.
    /// @return baseToken The Uniswap pool's base token.
    function uniswapBaseToken() external view returns (address baseToken);

    /// @notice Returns the Uniswap pool's quote token.
    /// @return quoteToken The Uniswap pool's quote token.
    function uniswapQuoteToken() external view returns (address quoteToken);

    /// @notice Returns the Uniswap pool's base token's decimals.
    /// @return baseTokenDecimals The Uniswap pool's base token's decimals.
    function uniswapBaseTokenDecimals()
        external
        view
        returns (uint8 baseTokenDecimals);

    /// @notice Returns the Uniswap pool's quote token's decimals.
    /// @return quoteTokenDecimals The Uniswap pool's quote token's decimals.
    function uniswapQuoteTokenDecimals()
        external
        view
        returns (uint8 quoteTokenDecimals);

    /// @notice Returns the time in seconds to use as lookback for Uniswap Twap
    ///         oracle.
    /// @return lookback The time in seconds to use as lookback.
    function uniswapLookback() external view returns (uint32 lookback);

    // -- Mutable Configurations --

    /// @notice Returns the agreement distance in WAD used to determine whether
    ///         a set of oracle values are in agreement.
    /// @dev Note that the agreement distance represents the allowed deviation,
    ///      eg an agreement distance of 0.95e18 implies a maximum allowed
    ///      deviation of 5%.
    /// @return agreementDistance The agreement distance.
    function agreementDistance()
        external
        view
        returns (uint128 agreementDistance);

    /// @notice The acceptable age of price that will be allowed.
    /// @return ageThreshold The time in seconds where a price is considered
    ///                      non-stale.
    function ageThreshold() external view returns (uint32 ageThreshold);

    // -- Auth'ed Functionality --

    /// @notice Sets the agreement distance.
    /// @dev Only callable by auth'ed addresses.
    function setAgreementDistance(uint128 agreementDistance) external;

    /// @notice Sets the age threshold.
    /// @dev Only callable by auth'ed addresses.
    function setAgeThreshold(uint32 ageThreshold) external;
}

File 9 of 20 : LibUniswapOracles.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;

import {OracleLibrary} from
    "uniswap/v3-periphery/contracts/libraries/OracleLibrary.sol";

/**
 * @title LibUniswapOracles
 *
 * @notice Library for Uniswap oracle related functionality.
 */
library LibUniswapOracles {
    using OracleLibrary for address;

    /// @dev Reads the TWAP derived price from given Uniswap pool `pool`.
    ///
    /// @dev The Uniswap pool address and pair addresses can be discovered at
    ///      https://app.uniswap.org/#/swap.
    ///
    /// @param pool The Uniswap pool that wil be observed.
    /// @param baseToken The base token for the pool, e.g. WETH in WETHUSDT.
    /// @param quoteToken The quote pair for the pool, e.g. USDT in WETHUSDT.
    /// @param baseDecimals The decimals of the base pair ERC-20 token.
    /// @param lookback The time in seconds to look back per TWAP.
    /// @return uint The Uniswap TWAP price for 1e`baseDecimals` base tokens denominated in
    ///              `quoteToken`.
    function readOracle(
        address pool,
        address baseToken,
        address quoteToken,
        uint8 baseDecimals,
        uint32 lookback
    ) internal view returns (uint) {
        (int24 tick,) = pool.consult(lookback);

        // Calculate exactly 1 unit of the base pair for quote.
        uint128 amt = uint128(10 ** baseDecimals);

        // Use Uniswap's periphery library to get quote.
        return OracleLibrary.getQuoteAtTick(tick, amt, baseToken, quoteToken);
    }

    /// @dev Returns the number of seconds ago of the oldest stored observations
    ///      for Uniswap pool `pool`.
    ///
    /// @param pool Address of Uniswap V3 pool that we want to observe.
    /// @return secondsAgo The number of seconds ago of the oldest observation
    ///                    stored for the pool.
    function getOldestObservationSecondsAgo(address pool)
        internal
        view
        returns (uint32)
    {
        return pool.getOldestObservationSecondsAgo();
    }
}

File 10 of 20 : LibMedian.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;

/**
 * @title LibMedian
 *
 * @notice Library to efficiently compute medians.
 */
library LibMedian {
    function median(uint128 a, uint128 b) internal pure returns (uint128) {
        // Note to cast arguments to uint to avoid overflow possibilites.
        uint sum;
        unchecked {
            sum = uint(a) + uint(b);
        }
        // assert(sum <= 2 * type(uint128).max);

        // Note that >> 1 equals a divison by 2.
        return uint128(sum >> 1);
    }

    function median(uint128 a, uint128 b, uint128 c)
        internal
        pure
        returns (uint128)
    {
        if (a < b) {
            if (b < c) {
                // a < b < c
                return b;
            } else {
                // a < b && c <= b
                return a > c ? a : c;
            }
        } else {
            if (a < c) {
                // b <= a < c
                return a;
            } else {
                // b <= a && c <= a
                return b > c ? b : c;
            }
        }
    }
}

File 11 of 20 : IAuth.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;

interface IAuth {
    /// @notice Thrown by protected function if caller not auth'ed.
    /// @param caller The caller's address.
    error NotAuthorized(address caller);

    /// @notice Emitted when auth granted to address.
    /// @param caller The caller's address.
    /// @param who The address auth got granted to.
    event AuthGranted(address indexed caller, address indexed who);

    /// @notice Emitted when auth renounced from address.
    /// @param caller The caller's address.
    /// @param who The address auth got renounced from.
    event AuthRenounced(address indexed caller, address indexed who);

    /// @notice Grants address `who` auth.
    /// @dev Only callable by auth'ed address.
    /// @param who The address to grant auth.
    function rely(address who) external;

    /// @notice Renounces address `who`'s auth.
    /// @dev Only callable by auth'ed address.
    /// @param who The address to renounce auth.
    function deny(address who) external;

    /// @notice Returns whether address `who` is auth'ed.
    /// @param who The address to check.
    /// @return True if `who` is auth'ed, false otherwise.
    function authed(address who) external view returns (bool);

    /// @notice Returns full list of addresses granted auth.
    /// @dev May contain duplicates.
    /// @return List of addresses granted auth.
    function authed() external view returns (address[] memory);

    /// @notice Returns whether address `who` is auth'ed.
    /// @custom:deprecated Use `authed(address)(bool)` instead.
    /// @param who The address to check.
    /// @return 1 if `who` is auth'ed, 0 otherwise.
    function wards(address who) external view returns (uint);
}

File 12 of 20 : IUniswapV3PoolImmutables.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Pool state that never changes
/// @notice These parameters are fixed for a pool forever, i.e., the methods will always return the same values
interface IUniswapV3PoolImmutables {
    /// @notice The contract that deployed the pool, which must adhere to the IUniswapV3Factory interface
    /// @return The contract address
    function factory() external view returns (address);

    /// @notice The first of the two tokens of the pool, sorted by address
    /// @return The token contract address
    function token0() external view returns (address);

    /// @notice The second of the two tokens of the pool, sorted by address
    /// @return The token contract address
    function token1() external view returns (address);

    /// @notice The pool's fee in hundredths of a bip, i.e. 1e-6
    /// @return The fee
    function fee() external view returns (uint24);

    /// @notice The pool tick spacing
    /// @dev Ticks can only be used at multiples of this value, minimum of 1 and always positive
    /// e.g.: a tickSpacing of 3 means ticks can be initialized every 3rd tick, i.e., ..., -6, -3, 0, 3, 6, ...
    /// This value is an int24 to avoid casting even though it is always positive.
    /// @return The tick spacing
    function tickSpacing() external view returns (int24);

    /// @notice The maximum amount of position liquidity that can use any tick in the range
    /// @dev This parameter is enforced per tick to prevent liquidity from overflowing a uint128 at any point, and
    /// also prevents out-of-range liquidity from being used to prevent adding in-range liquidity to a pool
    /// @return The max amount of liquidity per tick
    function maxLiquidityPerTick() external view returns (uint128);
}

File 13 of 20 : IUniswapV3PoolState.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Pool state that can change
/// @notice These methods compose the pool's state, and can change with any frequency including multiple times
/// per transaction
interface IUniswapV3PoolState {
    /// @notice The 0th storage slot in the pool stores many values, and is exposed as a single method to save gas
    /// when accessed externally.
    /// @return sqrtPriceX96 The current price of the pool as a sqrt(token1/token0) Q64.96 value
    /// tick The current tick of the pool, i.e. according to the last tick transition that was run.
    /// This value may not always be equal to SqrtTickMath.getTickAtSqrtRatio(sqrtPriceX96) if the price is on a tick
    /// boundary.
    /// observationIndex The index of the last oracle observation that was written,
    /// observationCardinality The current maximum number of observations stored in the pool,
    /// observationCardinalityNext The next maximum number of observations, to be updated when the observation.
    /// feeProtocol The protocol fee for both tokens of the pool.
    /// Encoded as two 4 bit values, where the protocol fee of token1 is shifted 4 bits and the protocol fee of token0
    /// is the lower 4 bits. Used as the denominator of a fraction of the swap fee, e.g. 4 means 1/4th of the swap fee.
    /// unlocked Whether the pool is currently locked to reentrancy
    function slot0()
        external
        view
        returns (
            uint160 sqrtPriceX96,
            int24 tick,
            uint16 observationIndex,
            uint16 observationCardinality,
            uint16 observationCardinalityNext,
            uint8 feeProtocol,
            bool unlocked
        );

    /// @notice The fee growth as a Q128.128 fees of token0 collected per unit of liquidity for the entire life of the pool
    /// @dev This value can overflow the uint256
    function feeGrowthGlobal0X128() external view returns (uint256);

    /// @notice The fee growth as a Q128.128 fees of token1 collected per unit of liquidity for the entire life of the pool
    /// @dev This value can overflow the uint256
    function feeGrowthGlobal1X128() external view returns (uint256);

    /// @notice The amounts of token0 and token1 that are owed to the protocol
    /// @dev Protocol fees will never exceed uint128 max in either token
    function protocolFees() external view returns (uint128 token0, uint128 token1);

    /// @notice The currently in range liquidity available to the pool
    /// @dev This value has no relationship to the total liquidity across all ticks
    function liquidity() external view returns (uint128);

    /// @notice Look up information about a specific tick in the pool
    /// @param tick The tick to look up
    /// @return liquidityGross the total amount of position liquidity that uses the pool either as tick lower or
    /// tick upper,
    /// liquidityNet how much liquidity changes when the pool price crosses the tick,
    /// feeGrowthOutside0X128 the fee growth on the other side of the tick from the current tick in token0,
    /// feeGrowthOutside1X128 the fee growth on the other side of the tick from the current tick in token1,
    /// tickCumulativeOutside the cumulative tick value on the other side of the tick from the current tick
    /// secondsPerLiquidityOutsideX128 the seconds spent per liquidity on the other side of the tick from the current tick,
    /// secondsOutside the seconds spent on the other side of the tick from the current tick,
    /// initialized Set to true if the tick is initialized, i.e. liquidityGross is greater than 0, otherwise equal to false.
    /// Outside values can only be used if the tick is initialized, i.e. if liquidityGross is greater than 0.
    /// In addition, these values are only relative and must be used only in comparison to previous snapshots for
    /// a specific position.
    function ticks(int24 tick)
        external
        view
        returns (
            uint128 liquidityGross,
            int128 liquidityNet,
            uint256 feeGrowthOutside0X128,
            uint256 feeGrowthOutside1X128,
            int56 tickCumulativeOutside,
            uint160 secondsPerLiquidityOutsideX128,
            uint32 secondsOutside,
            bool initialized
        );

    /// @notice Returns 256 packed tick initialized boolean values. See TickBitmap for more information
    function tickBitmap(int16 wordPosition) external view returns (uint256);

    /// @notice Returns the information about a position by the position's key
    /// @param key The position's key is a hash of a preimage composed by the owner, tickLower and tickUpper
    /// @return _liquidity The amount of liquidity in the position,
    /// Returns feeGrowthInside0LastX128 fee growth of token0 inside the tick range as of the last mint/burn/poke,
    /// Returns feeGrowthInside1LastX128 fee growth of token1 inside the tick range as of the last mint/burn/poke,
    /// Returns tokensOwed0 the computed amount of token0 owed to the position as of the last mint/burn/poke,
    /// Returns tokensOwed1 the computed amount of token1 owed to the position as of the last mint/burn/poke
    function positions(bytes32 key)
        external
        view
        returns (
            uint128 _liquidity,
            uint256 feeGrowthInside0LastX128,
            uint256 feeGrowthInside1LastX128,
            uint128 tokensOwed0,
            uint128 tokensOwed1
        );

    /// @notice Returns data about a specific observation index
    /// @param index The element of the observations array to fetch
    /// @dev You most likely want to use #observe() instead of this method to get an observation as of some amount of time
    /// ago, rather than at a specific index in the array.
    /// @return blockTimestamp The timestamp of the observation,
    /// Returns tickCumulative the tick multiplied by seconds elapsed for the life of the pool as of the observation timestamp,
    /// Returns secondsPerLiquidityCumulativeX128 the seconds per in range liquidity for the life of the pool as of the observation timestamp,
    /// Returns initialized whether the observation has been initialized and the values are safe to use
    function observations(uint256 index)
        external
        view
        returns (
            uint32 blockTimestamp,
            int56 tickCumulative,
            uint160 secondsPerLiquidityCumulativeX128,
            bool initialized
        );
}

File 14 of 20 : IUniswapV3PoolDerivedState.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Pool state that is not stored
/// @notice Contains view functions to provide information about the pool that is computed rather than stored on the
/// blockchain. The functions here may have variable gas costs.
interface IUniswapV3PoolDerivedState {
    /// @notice Returns the cumulative tick and liquidity as of each timestamp `secondsAgo` from the current block timestamp
    /// @dev To get a time weighted average tick or liquidity-in-range, you must call this with two values, one representing
    /// the beginning of the period and another for the end of the period. E.g., to get the last hour time-weighted average tick,
    /// you must call it with secondsAgos = [3600, 0].
    /// @dev The time weighted average tick represents the geometric time weighted average price of the pool, in
    /// log base sqrt(1.0001) of token1 / token0. The TickMath library can be used to go from a tick value to a ratio.
    /// @param secondsAgos From how long ago each cumulative tick and liquidity value should be returned
    /// @return tickCumulatives Cumulative tick values as of each `secondsAgos` from the current block timestamp
    /// @return secondsPerLiquidityCumulativeX128s Cumulative seconds per liquidity-in-range value as of each `secondsAgos` from the current block
    /// timestamp
    function observe(uint32[] calldata secondsAgos)
        external
        view
        returns (int56[] memory tickCumulatives, uint160[] memory secondsPerLiquidityCumulativeX128s);

    /// @notice Returns a snapshot of the tick cumulative, seconds per liquidity and seconds inside a tick range
    /// @dev Snapshots must only be compared to other snapshots, taken over a period for which a position existed.
    /// I.e., snapshots cannot be compared if a position is not held for the entire period between when the first
    /// snapshot is taken and the second snapshot is taken.
    /// @param tickLower The lower tick of the range
    /// @param tickUpper The upper tick of the range
    /// @return tickCumulativeInside The snapshot of the tick accumulator for the range
    /// @return secondsPerLiquidityInsideX128 The snapshot of seconds per liquidity for the range
    /// @return secondsInside The snapshot of seconds per liquidity for the range
    function snapshotCumulativesInside(int24 tickLower, int24 tickUpper)
        external
        view
        returns (
            int56 tickCumulativeInside,
            uint160 secondsPerLiquidityInsideX128,
            uint32 secondsInside
        );
}

File 15 of 20 : IUniswapV3PoolActions.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Permissionless pool actions
/// @notice Contains pool methods that can be called by anyone
interface IUniswapV3PoolActions {
    /// @notice Sets the initial price for the pool
    /// @dev Price is represented as a sqrt(amountToken1/amountToken0) Q64.96 value
    /// @param sqrtPriceX96 the initial sqrt price of the pool as a Q64.96
    function initialize(uint160 sqrtPriceX96) external;

    /// @notice Adds liquidity for the given recipient/tickLower/tickUpper position
    /// @dev The caller of this method receives a callback in the form of IUniswapV3MintCallback#uniswapV3MintCallback
    /// in which they must pay any token0 or token1 owed for the liquidity. The amount of token0/token1 due depends
    /// on tickLower, tickUpper, the amount of liquidity, and the current price.
    /// @param recipient The address for which the liquidity will be created
    /// @param tickLower The lower tick of the position in which to add liquidity
    /// @param tickUpper The upper tick of the position in which to add liquidity
    /// @param amount The amount of liquidity to mint
    /// @param data Any data that should be passed through to the callback
    /// @return amount0 The amount of token0 that was paid to mint the given amount of liquidity. Matches the value in the callback
    /// @return amount1 The amount of token1 that was paid to mint the given amount of liquidity. Matches the value in the callback
    function mint(
        address recipient,
        int24 tickLower,
        int24 tickUpper,
        uint128 amount,
        bytes calldata data
    ) external returns (uint256 amount0, uint256 amount1);

    /// @notice Collects tokens owed to a position
    /// @dev Does not recompute fees earned, which must be done either via mint or burn of any amount of liquidity.
    /// Collect must be called by the position owner. To withdraw only token0 or only token1, amount0Requested or
    /// amount1Requested may be set to zero. To withdraw all tokens owed, caller may pass any value greater than the
    /// actual tokens owed, e.g. type(uint128).max. Tokens owed may be from accumulated swap fees or burned liquidity.
    /// @param recipient The address which should receive the fees collected
    /// @param tickLower The lower tick of the position for which to collect fees
    /// @param tickUpper The upper tick of the position for which to collect fees
    /// @param amount0Requested How much token0 should be withdrawn from the fees owed
    /// @param amount1Requested How much token1 should be withdrawn from the fees owed
    /// @return amount0 The amount of fees collected in token0
    /// @return amount1 The amount of fees collected in token1
    function collect(
        address recipient,
        int24 tickLower,
        int24 tickUpper,
        uint128 amount0Requested,
        uint128 amount1Requested
    ) external returns (uint128 amount0, uint128 amount1);

    /// @notice Burn liquidity from the sender and account tokens owed for the liquidity to the position
    /// @dev Can be used to trigger a recalculation of fees owed to a position by calling with an amount of 0
    /// @dev Fees must be collected separately via a call to #collect
    /// @param tickLower The lower tick of the position for which to burn liquidity
    /// @param tickUpper The upper tick of the position for which to burn liquidity
    /// @param amount How much liquidity to burn
    /// @return amount0 The amount of token0 sent to the recipient
    /// @return amount1 The amount of token1 sent to the recipient
    function burn(
        int24 tickLower,
        int24 tickUpper,
        uint128 amount
    ) external returns (uint256 amount0, uint256 amount1);

    /// @notice Swap token0 for token1, or token1 for token0
    /// @dev The caller of this method receives a callback in the form of IUniswapV3SwapCallback#uniswapV3SwapCallback
    /// @param recipient The address to receive the output of the swap
    /// @param zeroForOne The direction of the swap, true for token0 to token1, false for token1 to token0
    /// @param amountSpecified The amount of the swap, which implicitly configures the swap as exact input (positive), or exact output (negative)
    /// @param sqrtPriceLimitX96 The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this
    /// value after the swap. If one for zero, the price cannot be greater than this value after the swap
    /// @param data Any data to be passed through to the callback
    /// @return amount0 The delta of the balance of token0 of the pool, exact when negative, minimum when positive
    /// @return amount1 The delta of the balance of token1 of the pool, exact when negative, minimum when positive
    function swap(
        address recipient,
        bool zeroForOne,
        int256 amountSpecified,
        uint160 sqrtPriceLimitX96,
        bytes calldata data
    ) external returns (int256 amount0, int256 amount1);

    /// @notice Receive token0 and/or token1 and pay it back, plus a fee, in the callback
    /// @dev The caller of this method receives a callback in the form of IUniswapV3FlashCallback#uniswapV3FlashCallback
    /// @dev Can be used to donate underlying tokens pro-rata to currently in-range liquidity providers by calling
    /// with 0 amount{0,1} and sending the donation amount(s) from the callback
    /// @param recipient The address which will receive the token0 and token1 amounts
    /// @param amount0 The amount of token0 to send
    /// @param amount1 The amount of token1 to send
    /// @param data Any data to be passed through to the callback
    function flash(
        address recipient,
        uint256 amount0,
        uint256 amount1,
        bytes calldata data
    ) external;

    /// @notice Increase the maximum number of price and liquidity observations that this pool will store
    /// @dev This method is no-op if the pool already has an observationCardinalityNext greater than or equal to
    /// the input observationCardinalityNext.
    /// @param observationCardinalityNext The desired minimum number of observations for the pool to store
    function increaseObservationCardinalityNext(uint16 observationCardinalityNext) external;
}

File 16 of 20 : IUniswapV3PoolOwnerActions.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Permissioned pool actions
/// @notice Contains pool methods that may only be called by the factory owner
interface IUniswapV3PoolOwnerActions {
    /// @notice Set the denominator of the protocol's % share of the fees
    /// @param feeProtocol0 new protocol fee for token0 of the pool
    /// @param feeProtocol1 new protocol fee for token1 of the pool
    function setFeeProtocol(uint8 feeProtocol0, uint8 feeProtocol1) external;

    /// @notice Collect the protocol fee accrued to the pool
    /// @param recipient The address to which collected protocol fees should be sent
    /// @param amount0Requested The maximum amount of token0 to send, can be 0 to collect fees in only token1
    /// @param amount1Requested The maximum amount of token1 to send, can be 0 to collect fees in only token0
    /// @return amount0 The protocol fee collected in token0
    /// @return amount1 The protocol fee collected in token1
    function collectProtocol(
        address recipient,
        uint128 amount0Requested,
        uint128 amount1Requested
    ) external returns (uint128 amount0, uint128 amount1);
}

File 17 of 20 : IUniswapV3PoolEvents.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Events emitted by a pool
/// @notice Contains all events emitted by the pool
interface IUniswapV3PoolEvents {
    /// @notice Emitted exactly once by a pool when #initialize is first called on the pool
    /// @dev Mint/Burn/Swap cannot be emitted by the pool before Initialize
    /// @param sqrtPriceX96 The initial sqrt price of the pool, as a Q64.96
    /// @param tick The initial tick of the pool, i.e. log base 1.0001 of the starting price of the pool
    event Initialize(uint160 sqrtPriceX96, int24 tick);

    /// @notice Emitted when liquidity is minted for a given position
    /// @param sender The address that minted the liquidity
    /// @param owner The owner of the position and recipient of any minted liquidity
    /// @param tickLower The lower tick of the position
    /// @param tickUpper The upper tick of the position
    /// @param amount The amount of liquidity minted to the position range
    /// @param amount0 How much token0 was required for the minted liquidity
    /// @param amount1 How much token1 was required for the minted liquidity
    event Mint(
        address sender,
        address indexed owner,
        int24 indexed tickLower,
        int24 indexed tickUpper,
        uint128 amount,
        uint256 amount0,
        uint256 amount1
    );

    /// @notice Emitted when fees are collected by the owner of a position
    /// @dev Collect events may be emitted with zero amount0 and amount1 when the caller chooses not to collect fees
    /// @param owner The owner of the position for which fees are collected
    /// @param tickLower The lower tick of the position
    /// @param tickUpper The upper tick of the position
    /// @param amount0 The amount of token0 fees collected
    /// @param amount1 The amount of token1 fees collected
    event Collect(
        address indexed owner,
        address recipient,
        int24 indexed tickLower,
        int24 indexed tickUpper,
        uint128 amount0,
        uint128 amount1
    );

    /// @notice Emitted when a position's liquidity is removed
    /// @dev Does not withdraw any fees earned by the liquidity position, which must be withdrawn via #collect
    /// @param owner The owner of the position for which liquidity is removed
    /// @param tickLower The lower tick of the position
    /// @param tickUpper The upper tick of the position
    /// @param amount The amount of liquidity to remove
    /// @param amount0 The amount of token0 withdrawn
    /// @param amount1 The amount of token1 withdrawn
    event Burn(
        address indexed owner,
        int24 indexed tickLower,
        int24 indexed tickUpper,
        uint128 amount,
        uint256 amount0,
        uint256 amount1
    );

    /// @notice Emitted by the pool for any swaps between token0 and token1
    /// @param sender The address that initiated the swap call, and that received the callback
    /// @param recipient The address that received the output of the swap
    /// @param amount0 The delta of the token0 balance of the pool
    /// @param amount1 The delta of the token1 balance of the pool
    /// @param sqrtPriceX96 The sqrt(price) of the pool after the swap, as a Q64.96
    /// @param liquidity The liquidity of the pool after the swap
    /// @param tick The log base 1.0001 of price of the pool after the swap
    event Swap(
        address indexed sender,
        address indexed recipient,
        int256 amount0,
        int256 amount1,
        uint160 sqrtPriceX96,
        uint128 liquidity,
        int24 tick
    );

    /// @notice Emitted by the pool for any flashes of token0/token1
    /// @param sender The address that initiated the swap call, and that received the callback
    /// @param recipient The address that received the tokens from flash
    /// @param amount0 The amount of token0 that was flashed
    /// @param amount1 The amount of token1 that was flashed
    /// @param paid0 The amount of token0 paid for the flash, which can exceed the amount0 plus the fee
    /// @param paid1 The amount of token1 paid for the flash, which can exceed the amount1 plus the fee
    event Flash(
        address indexed sender,
        address indexed recipient,
        uint256 amount0,
        uint256 amount1,
        uint256 paid0,
        uint256 paid1
    );

    /// @notice Emitted by the pool for increases to the number of observations that can be stored
    /// @dev observationCardinalityNext is not the observation cardinality until an observation is written at the index
    /// just before a mint/swap/burn.
    /// @param observationCardinalityNextOld The previous value of the next observation cardinality
    /// @param observationCardinalityNextNew The updated value of the next observation cardinality
    event IncreaseObservationCardinalityNext(
        uint16 observationCardinalityNextOld,
        uint16 observationCardinalityNextNew
    );

    /// @notice Emitted when the protocol fee is changed by the pool
    /// @param feeProtocol0Old The previous value of the token0 protocol fee
    /// @param feeProtocol1Old The previous value of the token1 protocol fee
    /// @param feeProtocol0New The updated value of the token0 protocol fee
    /// @param feeProtocol1New The updated value of the token1 protocol fee
    event SetFeeProtocol(uint8 feeProtocol0Old, uint8 feeProtocol1Old, uint8 feeProtocol0New, uint8 feeProtocol1New);

    /// @notice Emitted when the collected protocol fees are withdrawn by the factory owner
    /// @param sender The address that collects the protocol fees
    /// @param recipient The address that receives the collected protocol fees
    /// @param amount0 The amount of token0 protocol fees that is withdrawn
    /// @param amount0 The amount of token1 protocol fees that is withdrawn
    event CollectProtocol(address indexed sender, address indexed recipient, uint128 amount0, uint128 amount1);
}

File 18 of 20 : OracleLibrary.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0 <0.8.17;

import 'uniswap/v3-core/contracts/libraries/FullMath.sol';
import 'uniswap/v3-core/contracts/libraries/TickMath.sol';
import 'uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol';

/// @title Oracle library
/// @notice Provides functions to integrate with V3 pool oracle
library OracleLibrary {
    /// @notice Calculates time-weighted means of tick and liquidity for a given Uniswap V3 pool
    /// @param pool Address of the pool that we want to observe
    /// @param secondsAgo Number of seconds in the past from which to calculate the time-weighted means
    /// @return arithmeticMeanTick The arithmetic mean tick from (block.timestamp - secondsAgo) to block.timestamp
    /// @return harmonicMeanLiquidity The harmonic mean liquidity from (block.timestamp - secondsAgo) to block.timestamp
    function consult(address pool, uint32 secondsAgo)
        internal
        view
        returns (int24 arithmeticMeanTick, uint128 harmonicMeanLiquidity)
    {
        require(secondsAgo != 0, 'BP');

        uint32[] memory secondsAgos = new uint32[](2);
        secondsAgos[0] = secondsAgo;
        secondsAgos[1] = 0;

        (int56[] memory tickCumulatives, uint160[] memory secondsPerLiquidityCumulativeX128s) =
            IUniswapV3Pool(pool).observe(secondsAgos);

        int56 tickCumulativesDelta = tickCumulatives[1] - tickCumulatives[0];
        uint160 secondsPerLiquidityCumulativesDelta =
            secondsPerLiquidityCumulativeX128s[1] - secondsPerLiquidityCumulativeX128s[0];

        arithmeticMeanTick = int24(tickCumulativesDelta / int56(uint56(secondsAgo)));
        // Always round to negative infinity
        if (tickCumulativesDelta < 0 && (tickCumulativesDelta % int56(uint56(secondsAgo)) != 0)) arithmeticMeanTick--;

        // We are multiplying here instead of shifting to ensure that harmonicMeanLiquidity doesn't overflow uint128
        uint192 secondsAgoX160 = uint192(secondsAgo) * type(uint160).max;
        harmonicMeanLiquidity = uint128(secondsAgoX160 / (uint192(secondsPerLiquidityCumulativesDelta) << 32));
    }

    /// @notice Given a tick and a token amount, calculates the amount of token received in exchange
    /// @param tick Tick value used to calculate the quote
    /// @param baseAmount Amount of token to be converted
    /// @param baseToken Address of an ERC20 token contract used as the baseAmount denomination
    /// @param quoteToken Address of an ERC20 token contract used as the quoteAmount denomination
    /// @return quoteAmount Amount of quoteToken received for baseAmount of baseToken
    function getQuoteAtTick(
        int24 tick,
        uint128 baseAmount,
        address baseToken,
        address quoteToken
    ) internal pure returns (uint256 quoteAmount) {
        uint160 sqrtRatioX96 = TickMath.getSqrtRatioAtTick(tick);

        // Calculate quoteAmount with better precision if it doesn't overflow when multiplied by itself
        if (sqrtRatioX96 <= type(uint128).max) {
            uint256 ratioX192 = uint256(sqrtRatioX96) * sqrtRatioX96;
            quoteAmount = baseToken < quoteToken
                ? FullMath.mulDiv(ratioX192, baseAmount, 1 << 192)
                : FullMath.mulDiv(1 << 192, baseAmount, ratioX192);
        } else {
            uint256 ratioX128 = FullMath.mulDiv(sqrtRatioX96, sqrtRatioX96, 1 << 64);
            quoteAmount = baseToken < quoteToken
                ? FullMath.mulDiv(ratioX128, baseAmount, 1 << 128)
                : FullMath.mulDiv(1 << 128, baseAmount, ratioX128);
        }
    }

    /// @notice Given a pool, it returns the number of seconds ago of the oldest stored observation
    /// @param pool Address of Uniswap V3 pool that we want to observe
    /// @return secondsAgo The number of seconds ago of the oldest observation stored for the pool
    function getOldestObservationSecondsAgo(address pool) internal view returns (uint32 secondsAgo) {
        (, , uint16 observationIndex, uint16 observationCardinality, , , ) = IUniswapV3Pool(pool).slot0();
        require(observationCardinality > 0, 'NI');

        (uint32 observationTimestamp, , , bool initialized) =
            IUniswapV3Pool(pool).observations((observationIndex + 1) % observationCardinality);

        // The next index might not be initialized if the cardinality is in the process of increasing
        // In this case the oldest observation is always in index 0
        if (!initialized) {
            (observationTimestamp, , , ) = IUniswapV3Pool(pool).observations(0);
        }

        secondsAgo = uint32(block.timestamp) - observationTimestamp;
    }

    /// @notice Given a pool, it returns the tick value as of the start of the current block
    /// @param pool Address of Uniswap V3 pool
    /// @return The tick that the pool was in at the start of the current block
    function getBlockStartingTickAndLiquidity(address pool) internal view returns (int24, uint128) {
        (, int24 tick, uint16 observationIndex, uint16 observationCardinality, , , ) = IUniswapV3Pool(pool).slot0();

        // 2 observations are needed to reliably calculate the block starting tick
        require(observationCardinality > 1, 'NEO');

        // If the latest observation occurred in the past, then no tick-changing trades have happened in this block
        // therefore the tick in `slot0` is the same as at the beginning of the current block.
        // We don't need to check if this observation is initialized - it is guaranteed to be.
        (uint32 observationTimestamp, int56 tickCumulative, uint160 secondsPerLiquidityCumulativeX128, ) =
            IUniswapV3Pool(pool).observations(observationIndex);
        if (observationTimestamp != uint32(block.timestamp)) {
            return (tick, IUniswapV3Pool(pool).liquidity());
        }

        uint256 prevIndex = (uint256(observationIndex) + observationCardinality - 1) % observationCardinality;
        (
            uint32 prevObservationTimestamp,
            int56 prevTickCumulative,
            uint160 prevSecondsPerLiquidityCumulativeX128,
            bool prevInitialized
        ) = IUniswapV3Pool(pool).observations(prevIndex);

        require(prevInitialized, 'ONI');

        uint32 delta = observationTimestamp - prevObservationTimestamp;
        tick = int24((tickCumulative - prevTickCumulative) / int56(uint56(delta)));
        uint128 liquidity =
            uint128(
                (uint192(delta) * type(uint160).max) /
                    (uint192(secondsPerLiquidityCumulativeX128 - prevSecondsPerLiquidityCumulativeX128) << 32)
            );
        return (tick, liquidity);
    }

    /// @notice Information for calculating a weighted arithmetic mean tick
    struct WeightedTickData {
        int24 tick;
        uint128 weight;
    }

    /// @notice Given an array of ticks and weights, calculates the weighted arithmetic mean tick
    /// @param weightedTickData An array of ticks and weights
    /// @return weightedArithmeticMeanTick The weighted arithmetic mean tick
    /// @dev Each entry of `weightedTickData` should represents ticks from pools with the same underlying pool tokens. If they do not,
    /// extreme care must be taken to ensure that ticks are comparable (including decimal differences).
    /// @dev Note that the weighted arithmetic mean tick corresponds to the weighted geometric mean price.
    function getWeightedArithmeticMeanTick(WeightedTickData[] memory weightedTickData)
        internal
        pure
        returns (int24 weightedArithmeticMeanTick)
    {
        // Accumulates the sum of products between each tick and its weight
        int256 numerator;

        // Accumulates the sum of the weights
        uint256 denominator;

        // Products fit in 152 bits, so it would take an array of length ~2**104 to overflow this logic
        for (uint256 i; i < weightedTickData.length; i++) {
            numerator += weightedTickData[i].tick * int256(int128(weightedTickData[i].weight));
            denominator += weightedTickData[i].weight;
        }

        weightedArithmeticMeanTick = int24(numerator / int256(denominator));
        // Always round to negative infinity
        if (numerator < 0 && (numerator % int256(denominator) != 0)) weightedArithmeticMeanTick--;
    }

    /// @notice Returns the "synthetic" tick which represents the price of the first entry in `tokens` in terms of the last
    /// @dev Useful for calculating relative prices along routes.
    /// @dev There must be one tick for each pairwise set of tokens.
    /// @param tokens The token contract addresses
    /// @param ticks The ticks, representing the price of each token pair in `tokens`
    /// @return syntheticTick The synthetic tick, representing the relative price of the outermost tokens in `tokens`
    function getChainedPrice(address[] memory tokens, int24[] memory ticks)
        internal
        pure
        returns (int256 syntheticTick)
    {
        require(tokens.length - 1 == ticks.length, 'DL');
        for (uint256 i = 1; i <= ticks.length; i++) {
            // check the tokens for address sort order, then accumulate the
            // ticks into the running synthetic tick, ensuring that intermediate tokens "cancel out"
            tokens[i - 1] < tokens[i] ? syntheticTick += ticks[i - 1] : syntheticTick -= ticks[i - 1];
        }
    }
}

File 19 of 20 : FullMath.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.0 <0.8.17;

/// @title Contains 512-bit math functions
/// @notice Facilitates multiplication and division that can have overflow of an intermediate value without any loss of precision
/// @dev Handles "phantom overflow" i.e., allows multiplication and division where an intermediate value overflows 256 bits
library FullMath {
    /// @notice Calculates floor(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
    /// @param a The multiplicand
    /// @param b The multiplier
    /// @param denominator The divisor
    /// @return result The 256-bit result
    /// @dev Credit to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv
    function mulDiv(
        uint256 a,
        uint256 b,
        uint256 denominator
    ) internal pure returns (uint256 result) {
        // 512-bit multiply [prod1 prod0] = a * b
        // Compute the product mod 2**256 and mod 2**256 - 1
        // then use the Chinese Remainder Theorem to reconstruct
        // the 512 bit result. The result is stored in two 256
        // variables such that product = prod1 * 2**256 + prod0
        uint256 prod0; // Least significant 256 bits of the product
        uint256 prod1; // Most significant 256 bits of the product
        assembly {
            let mm := mulmod(a, b, not(0))
            prod0 := mul(a, b)
            prod1 := sub(sub(mm, prod0), lt(mm, prod0))
        }

        // Handle non-overflow cases, 256 by 256 division
        if (prod1 == 0) {
            require(denominator > 0);
            assembly {
                result := div(prod0, denominator)
            }
            return result;
        }

        // Make sure the result is less than 2**256.
        // Also prevents denominator == 0
        require(denominator > prod1);

        ///////////////////////////////////////////////
        // 512 by 256 division.
        ///////////////////////////////////////////////

        // Make division exact by subtracting the remainder from [prod1 prod0]
        // Compute remainder using mulmod
        uint256 remainder;
        assembly {
            remainder := mulmod(a, b, denominator)
        }
        // Subtract 256 bit number from 512 bit number
        assembly {
            prod1 := sub(prod1, gt(remainder, prod0))
            prod0 := sub(prod0, remainder)
        }

        // Factor powers of two out of denominator
        // Compute largest power of two divisor of denominator.
        // Always >= 1.
        uint256 twos = uint256(-int256(denominator) & int256(denominator));
        // Divide denominator by power of two
        assembly {
            denominator := div(denominator, twos)
        }

        // Divide [prod1 prod0] by the factors of two
        assembly {
            prod0 := div(prod0, twos)
        }
        // Shift in bits from prod1 into prod0. For this we need
        // to flip `twos` such that it is 2**256 / twos.
        // If twos is zero, then it becomes one
        assembly {
            twos := add(div(sub(0, twos), twos), 1)
        }
        prod0 |= prod1 * twos;

        // Invert denominator mod 2**256
        // Now that denominator is an odd number, it has an inverse
        // modulo 2**256 such that denominator * inv = 1 mod 2**256.
        // Compute the inverse by starting with a seed that is correct
        // correct for four bits. That is, denominator * inv = 1 mod 2**4
        uint256 inv = (3 * denominator) ^ 2;
        // Now use Newton-Raphson iteration to improve the precision.
        // Thanks to Hensel's lifting lemma, this also works in modular
        // arithmetic, doubling the correct bits in each step.
        inv *= 2 - denominator * inv; // inverse mod 2**8
        inv *= 2 - denominator * inv; // inverse mod 2**16
        inv *= 2 - denominator * inv; // inverse mod 2**32
        inv *= 2 - denominator * inv; // inverse mod 2**64
        inv *= 2 - denominator * inv; // inverse mod 2**128
        inv *= 2 - denominator * inv; // inverse mod 2**256

        // Because the division is now exact we can divide by multiplying
        // with the modular inverse of denominator. This will give us the
        // correct result modulo 2**256. Since the precoditions guarantee
        // that the outcome is less than 2**256, this is the final result.
        // We don't need to compute the high bits of the result and prod1
        // is no longer required.
        result = prod0 * inv;
        return result;
    }

    /// @notice Calculates ceil(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
    /// @param a The multiplicand
    /// @param b The multiplier
    /// @param denominator The divisor
    /// @return result The 256-bit result
    function mulDivRoundingUp(
        uint256 a,
        uint256 b,
        uint256 denominator
    ) internal pure returns (uint256 result) {
        result = mulDiv(a, b, denominator);
        if (mulmod(a, b, denominator) > 0) {
            require(result < type(uint256).max);
            result++;
        }
    }
}

File 20 of 20 : TickMath.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0 <0.8.17;

/// @title Math library for computing sqrt prices from ticks and vice versa
/// @notice Computes sqrt price for ticks of size 1.0001, i.e. sqrt(1.0001^tick) as fixed point Q64.96 numbers. Supports
/// prices between 2**-128 and 2**128
library TickMath {
    /// @dev The minimum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**-128
    int24 internal constant MIN_TICK = -887272;
    /// @dev The maximum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**128
    int24 internal constant MAX_TICK = -MIN_TICK;

    /// @dev The minimum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MIN_TICK)
    uint160 internal constant MIN_SQRT_RATIO = 4295128739;
    /// @dev The maximum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MAX_TICK)
    uint160 internal constant MAX_SQRT_RATIO = 1461446703485210103287273052203988822378723970342;

    /// @notice Calculates sqrt(1.0001^tick) * 2^96
    /// @dev Throws if |tick| > max tick
    /// @param tick The input tick for the above formula
    /// @return sqrtPriceX96 A Fixed point Q64.96 number representing the sqrt of the ratio of the two assets (token1/token0)
    /// at the given tick
    function getSqrtRatioAtTick(int24 tick) internal pure returns (uint160 sqrtPriceX96) {
        uint256 absTick = tick < 0 ? uint256(-int256(tick)) : uint256(int256(tick));
        require(absTick <= uint256(uint24(MAX_TICK)), 'T');

        uint256 ratio = absTick & 0x1 != 0 ? 0xfffcb933bd6fad37aa2d162d1a594001 : 0x100000000000000000000000000000000;
        if (absTick & 0x2 != 0) ratio = (ratio * 0xfff97272373d413259a46990580e213a) >> 128;
        if (absTick & 0x4 != 0) ratio = (ratio * 0xfff2e50f5f656932ef12357cf3c7fdcc) >> 128;
        if (absTick & 0x8 != 0) ratio = (ratio * 0xffe5caca7e10e4e61c3624eaa0941cd0) >> 128;
        if (absTick & 0x10 != 0) ratio = (ratio * 0xffcb9843d60f6159c9db58835c926644) >> 128;
        if (absTick & 0x20 != 0) ratio = (ratio * 0xff973b41fa98c081472e6896dfb254c0) >> 128;
        if (absTick & 0x40 != 0) ratio = (ratio * 0xff2ea16466c96a3843ec78b326b52861) >> 128;
        if (absTick & 0x80 != 0) ratio = (ratio * 0xfe5dee046a99a2a811c461f1969c3053) >> 128;
        if (absTick & 0x100 != 0) ratio = (ratio * 0xfcbe86c7900a88aedcffc83b479aa3a4) >> 128;
        if (absTick & 0x200 != 0) ratio = (ratio * 0xf987a7253ac413176f2b074cf7815e54) >> 128;
        if (absTick & 0x400 != 0) ratio = (ratio * 0xf3392b0822b70005940c7a398e4b70f3) >> 128;
        if (absTick & 0x800 != 0) ratio = (ratio * 0xe7159475a2c29b7443b29c7fa6e889d9) >> 128;
        if (absTick & 0x1000 != 0) ratio = (ratio * 0xd097f3bdfd2022b8845ad8f792aa5825) >> 128;
        if (absTick & 0x2000 != 0) ratio = (ratio * 0xa9f746462d870fdf8a65dc1f90e061e5) >> 128;
        if (absTick & 0x4000 != 0) ratio = (ratio * 0x70d869a156d2a1b890bb3df62baf32f7) >> 128;
        if (absTick & 0x8000 != 0) ratio = (ratio * 0x31be135f97d08fd981231505542fcfa6) >> 128;
        if (absTick & 0x10000 != 0) ratio = (ratio * 0x9aa508b5b7a84e1c677de54f3e99bc9) >> 128;
        if (absTick & 0x20000 != 0) ratio = (ratio * 0x5d6af8dedb81196699c329225ee604) >> 128;
        if (absTick & 0x40000 != 0) ratio = (ratio * 0x2216e584f5fa1ea926041bedfe98) >> 128;
        if (absTick & 0x80000 != 0) ratio = (ratio * 0x48a170391f7dc42444e8fa2) >> 128;

        if (tick > 0) ratio = type(uint256).max / ratio;

        // this divides by 1<<32 rounding up to go from a Q128.128 to a Q128.96.
        // we then downcast because we know the result always fits within 160 bits due to our tick input constraint
        // we round up in the division so getTickAtSqrtRatio of the output price is always consistent
        sqrtPriceX96 = uint160((ratio >> 32) + (ratio % (1 << 32) == 0 ? 0 : 1));
    }

    /// @notice Calculates the greatest tick value such that getRatioAtTick(tick) <= ratio
    /// @dev Throws in case sqrtPriceX96 < MIN_SQRT_RATIO, as MIN_SQRT_RATIO is the lowest value getRatioAtTick may
    /// ever return.
    /// @param sqrtPriceX96 The sqrt ratio for which to compute the tick as a Q64.96
    /// @return tick The greatest tick for which the ratio is less than or equal to the input ratio
    function getTickAtSqrtRatio(uint160 sqrtPriceX96) internal pure returns (int24 tick) {
        // second inequality must be < because the price can never reach the price at the max tick
        require(sqrtPriceX96 >= MIN_SQRT_RATIO && sqrtPriceX96 < MAX_SQRT_RATIO, 'R');
        uint256 ratio = uint256(sqrtPriceX96) << 32;

        uint256 r = ratio;
        uint256 msb = 0;

        assembly {
            let f := shl(7, gt(r, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))
            msb := or(msb, f)
            r := shr(f, r)
        }
        assembly {
            let f := shl(6, gt(r, 0xFFFFFFFFFFFFFFFF))
            msb := or(msb, f)
            r := shr(f, r)
        }
        assembly {
            let f := shl(5, gt(r, 0xFFFFFFFF))
            msb := or(msb, f)
            r := shr(f, r)
        }
        assembly {
            let f := shl(4, gt(r, 0xFFFF))
            msb := or(msb, f)
            r := shr(f, r)
        }
        assembly {
            let f := shl(3, gt(r, 0xFF))
            msb := or(msb, f)
            r := shr(f, r)
        }
        assembly {
            let f := shl(2, gt(r, 0xF))
            msb := or(msb, f)
            r := shr(f, r)
        }
        assembly {
            let f := shl(1, gt(r, 0x3))
            msb := or(msb, f)
            r := shr(f, r)
        }
        assembly {
            let f := gt(r, 0x1)
            msb := or(msb, f)
        }

        if (msb >= 128) r = ratio >> (msb - 127);
        else r = ratio << (127 - msb);

        int256 log_2 = (int256(msb) - 128) << 64;

        assembly {
            r := shr(127, mul(r, r))
            let f := shr(128, r)
            log_2 := or(log_2, shl(63, f))
            r := shr(f, r)
        }
        assembly {
            r := shr(127, mul(r, r))
            let f := shr(128, r)
            log_2 := or(log_2, shl(62, f))
            r := shr(f, r)
        }
        assembly {
            r := shr(127, mul(r, r))
            let f := shr(128, r)
            log_2 := or(log_2, shl(61, f))
            r := shr(f, r)
        }
        assembly {
            r := shr(127, mul(r, r))
            let f := shr(128, r)
            log_2 := or(log_2, shl(60, f))
            r := shr(f, r)
        }
        assembly {
            r := shr(127, mul(r, r))
            let f := shr(128, r)
            log_2 := or(log_2, shl(59, f))
            r := shr(f, r)
        }
        assembly {
            r := shr(127, mul(r, r))
            let f := shr(128, r)
            log_2 := or(log_2, shl(58, f))
            r := shr(f, r)
        }
        assembly {
            r := shr(127, mul(r, r))
            let f := shr(128, r)
            log_2 := or(log_2, shl(57, f))
            r := shr(f, r)
        }
        assembly {
            r := shr(127, mul(r, r))
            let f := shr(128, r)
            log_2 := or(log_2, shl(56, f))
            r := shr(f, r)
        }
        assembly {
            r := shr(127, mul(r, r))
            let f := shr(128, r)
            log_2 := or(log_2, shl(55, f))
            r := shr(f, r)
        }
        assembly {
            r := shr(127, mul(r, r))
            let f := shr(128, r)
            log_2 := or(log_2, shl(54, f))
            r := shr(f, r)
        }
        assembly {
            r := shr(127, mul(r, r))
            let f := shr(128, r)
            log_2 := or(log_2, shl(53, f))
            r := shr(f, r)
        }
        assembly {
            r := shr(127, mul(r, r))
            let f := shr(128, r)
            log_2 := or(log_2, shl(52, f))
            r := shr(f, r)
        }
        assembly {
            r := shr(127, mul(r, r))
            let f := shr(128, r)
            log_2 := or(log_2, shl(51, f))
            r := shr(f, r)
        }
        assembly {
            r := shr(127, mul(r, r))
            let f := shr(128, r)
            log_2 := or(log_2, shl(50, f))
        }

        int256 log_sqrt10001 = log_2 * 255738958999603826347141; // 128.128 number

        int24 tickLow = int24((log_sqrt10001 - 3402992956809132418596140100660247210) >> 128);
        int24 tickHi = int24((log_sqrt10001 + 291339464771989622907027621153398088495) >> 128);

        tick = tickLow == tickHi ? tickLow : getSqrtRatioAtTick(tickHi) <= sqrtPriceX96 ? tickHi : tickLow;
    }
}

Settings
{
  "remappings": [
    "ds-test/=lib/forge-std/lib/ds-test/src/",
    "forge-std/=lib/forge-std/src/",
    "chronicle-std/=lib/chronicle-std/src/",
    "solmate/=lib/solmate/src/",
    "uniswap/=lib/uniswap/"
  ],
  "optimizer": {
    "enabled": true,
    "runs": 10000
  },
  "metadata": {
    "useLiteralContent": false,
    "bytecodeHash": "ipfs"
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "evmVersion": "london",
  "viaIR": false,
  "libraries": {}
}

Contract Security Audit

Contract ABI

API
[{"inputs":[{"internalType":"address","name":"initialAuthed","type":"address"},{"internalType":"address","name":"bud_","type":"address"},{"internalType":"address","name":"chronicle_","type":"address"},{"internalType":"address","name":"chainlink_","type":"address"},{"internalType":"address","name":"uniswapPool_","type":"address"},{"internalType":"address","name":"uniswapBaseToken_","type":"address"},{"internalType":"address","name":"uniswapQuoteToken_","type":"address"},{"internalType":"uint8","name":"uniswapBaseDec_","type":"uint8"},{"internalType":"uint8","name":"uniswapQuoteDec_","type":"uint8"},{"internalType":"uint32","name":"uniswapLookback_","type":"uint32"},{"internalType":"uint128","name":"agreementDistance_","type":"uint128"},{"internalType":"uint32","name":"ageThreshold_","type":"uint32"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"caller","type":"address"}],"name":"NotAuthorized","type":"error"},{"inputs":[{"internalType":"address","name":"caller","type":"address"}],"name":"NotTolled","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":false,"internalType":"uint256","name":"oldAgeThreshold","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newAgeThreshold","type":"uint256"}],"name":"AcceptableAgeThresholdUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":false,"internalType":"uint256","name":"oldAgreementDistance","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newAgreementDistance","type":"uint256"}],"name":"AgreementDistanceUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":true,"internalType":"address","name":"who","type":"address"}],"name":"AuthGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":true,"internalType":"address","name":"who","type":"address"}],"name":"AuthRenounced","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":true,"internalType":"address","name":"who","type":"address"}],"name":"TollGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":true,"internalType":"address","name":"who","type":"address"}],"name":"TollRenounced","type":"event"},{"inputs":[],"name":"ageThreshold","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"agreementDistance","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"who","type":"address"}],"name":"authed","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"authed","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"who","type":"address"}],"name":"bud","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"chainlink","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"chronicle","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"who","type":"address"}],"name":"deny","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"diss","outputs":[],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"kiss","outputs":[],"stateMutability":"view","type":"function"},{"inputs":[],"name":"latestAnswer","outputs":[{"internalType":"int256","name":"","type":"int256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"latestRoundData","outputs":[{"internalType":"uint80","name":"roundId","type":"uint80"},{"internalType":"int256","name":"answer","type":"int256"},{"internalType":"uint256","name":"startedAt","type":"uint256"},{"internalType":"uint256","name":"updatedAt","type":"uint256"},{"internalType":"uint80","name":"answeredInRound","type":"uint80"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"readWithStatus","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"components":[{"internalType":"uint256","name":"path","type":"uint256"},{"internalType":"uint256","name":"goodOracleCtr","type":"uint256"}],"internalType":"struct IAggor.Status","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"who","type":"address"}],"name":"rely","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"ageThreshold_","type":"uint32"}],"name":"setAgeThreshold","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint128","name":"agreementDistance_","type":"uint128"}],"name":"setAgreementDistance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"who","type":"address"}],"name":"tolled","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tolled","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"uniswapBaseToken","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"uniswapBaseTokenDecimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"uniswapLookback","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"uniswapPool","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"uniswapQuoteToken","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"uniswapQuoteTokenDecimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"who","type":"address"}],"name":"wards","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]

Deployed Bytecode

0x608060405234801561001057600080fd5b50600436106101ae5760003560e01c80639954b0dc116100ee578063be3603d111610097578063d039730111610071578063d0397301146104a1578063d877e827146104ce578063f29c29c41461032d578063feaf968c1461050b57600080fd5b8063be3603d11461041d578063bf353dbb14610444578063c241afa61461047a57600080fd5b8063a34fa092116100c8578063a34fa092146103bc578063b99b67d8146103e3578063bdd3d825146103f657600080fd5b80639954b0dc1461037a5780639c3feeb7146103825780639c52a7f1146103a957600080fd5b80633bee58f91161015b57806351bfead31161013557806351bfead31461030657806365c4ce7a1461032d57806365fae35e1461034057806394ba52441461035357600080fd5b80633bee58f9146102ca5780634fce7a2a146102dd57806350d25bcd146102fe57600080fd5b80631c6578b71161018c5780631c6578b71461024f578063224242ca1461029b578063313ce567146102b057600080fd5b80630fce3415146101b35780631057f0d714610201578063112efd6414610216575b600080fd5b6101ec6101c136600461230d565b73ffffffffffffffffffffffffffffffffffffffff1660009081526020819052604090205460011490565b60405190151581526020015b60405180910390f35b61021461020f36600461233c565b61054a565b005b60025461023a90700100000000000000000000000000000000900463ffffffff1681565b60405163ffffffff90911681526020016101f8565b6102767f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc281565b60405173ffffffffffffffffffffffffffffffffffffffff90911681526020016101f8565b6102a3610580565b6040516101f89190612359565b6102b8600881565b60405160ff90911681526020016101f8565b6101ec6102d836600461230d565b6106d0565b6102f06102eb36600461230d565b610746565b6040519081526020016101f8565b6102f0610768565b6102b87f000000000000000000000000000000000000000000000000000000000000001281565b61021461033b36600461230d565b610811565b61021461034e36600461230d565b61083a565b61023a7f0000000000000000000000000000000000000000000000000000000000000e1081565b6102a361093a565b6102767f0000000000000000000000005f4ec3df9cbd43714fe2740f5e3616155c5b841981565b6102146103b736600461230d565b610a0c565b6102767f00000000000000000000000046ef0071b1e2ff6b42d36e5a177ea43ae5917f4e81565b6102146103f13660046123b3565b610ab3565b6102767f00000000000000000000000088e6a0c2ddd26feeb64f039a2c41296fcb3f564081565b6102767f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4881565b6102f061045236600461230d565b73ffffffffffffffffffffffffffffffffffffffff1660009081526020819052604090205490565b6102b87f000000000000000000000000000000000000000000000000000000000000000681565b6104a9610ae6565b60408051938452602080850193909352815190840152015160608201526080016101f8565b6002546104ea906fffffffffffffffffffffffffffffffff1681565b6040516fffffffffffffffffffffffffffffffff90911681526020016101f8565b610513610bab565b6040805169ffffffffffffffffffff968716815260208101959095528401929092526060830152909116608082015260a0016101f8565b3360005260006020526040600020805490508061057357634a0bfec1600052336020526024601cfd5b5061057d81610ed0565b50565b60015460609060009067ffffffffffffffff8111156105a1576105a16123e5565b6040519080825280602002602001820160405280156105ca578160200160208202803683370190505b5090506000805b82518110156106c857600080600183815481106105f0576105f0612414565b600091825260208083209091015473ffffffffffffffffffffffffffffffffffffffff1683528201929092526040019020546001036106b6576001818154811061063c5761063c612414565b60009182526020909120015473ffffffffffffffffffffffffffffffffffffffff16838361066981612472565b94508151811061067b5761067b612414565b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff16815250505b806106c081612472565b9150506105d1565b508152919050565b60007f0000000000000000000000008105f69d9c41644c6a0803fda7d03aa70996cfd973ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161480610740575073ffffffffffffffffffffffffffffffffffffffff8216155b92915050565b6000610751826106d0565b61075c57600061075f565b60015b60ff1692915050565b60003373ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000008105f69d9c41644c6a0803fda7d03aa70996cfd916148015906107af57503315155b156107ed576040517fd957b5950000000000000000000000000000000000000000000000000000000081523360048201526024015b60405180910390fd5b60006107f7610fab565b50506fffffffffffffffffffffffffffffffff1691505090565b336000526000602052604060002080549050806101ae57634a0bfec1600052336020526024601cfd5b3360005260006020526040600020805490508061086357634a0bfec1600052336020526024601cfd5b5073ffffffffffffffffffffffffffffffffffffffff811660009081526020819052604090205460011461057d5773ffffffffffffffffffffffffffffffffffffffff8116600081815260208190526040808220600190819055805480820182559083527fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf60180547fffffffffffffffffffffffff000000000000000000000000000000000000000016841790555133917fe31c10b0adbedd0c6e5d024286c6eeead7761e65a67608dcf0b67604c0da7e2f91a350565b6040805160028082526060808301845292600092919060208301908036833701905050905060008160008151811061097457610974612414565b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff16815250507f0000000000000000000000008105f69d9c41644c6a0803fda7d03aa70996cfd9816001815181106109e2576109e2612414565b73ffffffffffffffffffffffffffffffffffffffff90921660209283029190910190910152919050565b33600052600060205260406000208054905080610a3557634a0bfec1600052336020526024601cfd5b5073ffffffffffffffffffffffffffffffffffffffff81166000908152602081905260409020541561057d5773ffffffffffffffffffffffffffffffffffffffff81166000818152602081905260408082208290555133917f58466e5837b54e559819c9ba8a5d7c77c97c985d1aabf4bdc5f41069fa5d65a091a350565b33600052600060205260406000208054905080610adc57634a0bfec1600052336020526024601cfd5b5061057d81611151565b600080610b06604051806040016040528060008152602001600081525090565b3373ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000008105f69d9c41644c6a0803fda7d03aa70996cfd91614801590610b4b57503315155b15610b84576040517fd957b5950000000000000000000000000000000000000000000000000000000081523360048201526024016107e4565b610b8c610fab565b6fffffffffffffffffffffffffffffffff909216945092509050909192565b6000808080803373ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000008105f69d9c41644c6a0803fda7d03aa70996cfd91614801590610bf657503315155b15610c2f576040517fd957b5950000000000000000000000000000000000000000000000000000000081523360048201526024016107e4565b600080610c3a610fab565b506001996fffffffffffffffffffffffffffffffff909216985060009750955088945092505050565b60006107408273ffffffffffffffffffffffffffffffffffffffff165b60008060008373ffffffffffffffffffffffffffffffffffffffff16633850c7bd6040518163ffffffff1660e01b815260040160e060405180830381865afa158015610cd0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610cf491906124b3565b50505093509350505060008161ffff1611610d6b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600260248201527f4e4900000000000000000000000000000000000000000000000000000000000060448201526064016107e4565b60008073ffffffffffffffffffffffffffffffffffffffff861663252c09d784610d9687600161254d565b610da0919061259e565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e084901b16815261ffff9091166004820152602401608060405180830381865afa158015610df7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e1b91906125d1565b93505050915080610ebc576040517f252c09d70000000000000000000000000000000000000000000000000000000081526000600482015273ffffffffffffffffffffffffffffffffffffffff87169063252c09d790602401608060405180830381865afa158015610e91573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610eb591906125d1565b5091935050505b610ec68242612629565b9695505050505050565b8063ffffffff16600003610ee357600080fd5b60025463ffffffff828116700100000000000000000000000000000000909204161461057d576002546040805170010000000000000000000000000000000090920463ffffffff90811683528316602083015233917f44f313823a59f09741a0275504cb39ccb15ebaf9e8dc19004c35a45a43d2392b910160405180910390a26002805463ffffffff8316700100000000000000000000000000000000027fffffffffffffffffffffffff00000000ffffffffffffffffffffffffffffffff90911617905550565b600080610fcb604051806040016040528060008152602001600081525090565b600080610fd6611248565b91509150600080610fe5611370565b909250905042848015610ff55750825b15611095576110048483611493565b15611047576fffffffffffffffffffffffffffffffff8085169083160160011c604080518082019091526002808252602082015290999198509650945050505050565b600080611052611556565b91509150811561108e57611067868583611700565b604080518082019091526003815260026020820152909b939a509850919650505050505050565b50506110ea565b84156110c0576040805180820190915260048152600160208201529398909750929550919350505050565b82156110ea5760408051808201909152600481526001602082015291989097509095509350505050565b6000806110f5611556565b91509150811561112557604080518082019091526005815260006020820152909a92995097509095505050505050565b600080604051806040016040528060068152602001600081525099509950995050505050505050909192565b806fffffffffffffffffffffffffffffffff1660000361117057600080fd5b670de0b6b3a7640000816fffffffffffffffffffffffffffffffff16111561119757600080fd5b6002546fffffffffffffffffffffffffffffffff82811691161461057d57600254604080516fffffffffffffffffffffffffffffffff9283168152918316602083015233917ffa63998ff71da5ffa140f0e2fbf5749b05109b3232381b016c9c38bb5e1b385a910160405180910390a2600280546fffffffffffffffffffffffffffffffff83167fffffffffffffffffffffffffffffffff0000000000000000000000000000000090911617905550565b6000807f00000000000000000000000046ef0071b1e2ff6b42d36e5a177ea43ae5917f4e73ffffffffffffffffffffffffffffffffffffffff1663ceed3ef26040518163ffffffff1660e01b8152600401606060405180830381865afa9250505080156112f0575060408051601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01682019092526112ed91810190612646565b60015b6112fd5750600091829150565b8215806113305750600254429061132e90700100000000000000000000000000000000900463ffffffff168361267b565b105b15611342575060009485945092505050565b61134e6008601261268e565b61135990600a61278b565b611363908361279a565b6001969095509350505050565b6000807f0000000000000000000000005f4ec3df9cbd43714fe2740f5e3616155c5b841973ffffffffffffffffffffffffffffffffffffffff1663feaf968c6040518163ffffffff1660e01b815260040160a060405180830381865afa925050508015611418575060408051601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0168201909252611415918101906127c8565b60015b6114255750600091829150565b6002544270010000000000000000000000000000000090910463ffffffff168301108080611454575060008513155b8061146e57506fffffffffffffffffffffffffffffffff85115b15611483575060009788975095505050505050565b5060019793965092945050505050565b6000816fffffffffffffffffffffffffffffffff16836fffffffffffffffffffffffffffffffff161115611510576002546114e3906fffffffffffffffffffffffffffffffff8086169116612818565b6115076fffffffffffffffffffffffffffffffff8416670de0b6b3a7640000612818565b10159050610740565b600254611532906fffffffffffffffffffffffffffffffff8085169116612818565b6115076fffffffffffffffffffffffffffffffff8516670de0b6b3a7640000612818565b6000808061161d73ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000088e6a0c2ddd26feeb64f039a2c41296fcb3f5640167f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc27f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb487f00000000000000000000000000000000000000000000000000000000000000127f0000000000000000000000000000000000000000000000000000000000000e10611809565b905060087f000000000000000000000000000000000000000000000000000000000000000660ff1611611691576116757f0000000000000000000000000000000000000000000000000000000000000006600861268e565b61168090600a61278b565b61168a9082612818565b90506116d4565b6116bc60087f000000000000000000000000000000000000000000000000000000000000000661268e565b6116c790600a61278b565b6116d1908261279a565b90505b6fffffffffffffffffffffffffffffffff81116116f5576001939092509050565b506000928392509050565b6000826fffffffffffffffffffffffffffffffff16846fffffffffffffffffffffffffffffffff16101561179b57816fffffffffffffffffffffffffffffffff16836fffffffffffffffffffffffffffffffff161015611761575081611802565b816fffffffffffffffffffffffffffffffff16846fffffffffffffffffffffffffffffffff16116117925781611794565b835b9050611802565b816fffffffffffffffffffffffffffffffff16846fffffffffffffffffffffffffffffffff1610156117ce575082611802565b816fffffffffffffffffffffffffffffffff16836fffffffffffffffffffffffffffffffff16116117ff5781611794565b50815b9392505050565b60008061182c73ffffffffffffffffffffffffffffffffffffffff881684611856565b509050600061183c85600a61278b565b905061184a82828989611b1a565b98975050505050505050565b6000808263ffffffff166000036118c9576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600260248201527f425000000000000000000000000000000000000000000000000000000000000060448201526064016107e4565b60408051600280825260608201835260009260208301908036833701905050905083816000815181106118fe576118fe612414565b602002602001019063ffffffff16908163ffffffff168152505060008160018151811061192d5761192d612414565b602002602001019063ffffffff16908163ffffffff16815250506000808673ffffffffffffffffffffffffffffffffffffffff1663883bdbfd846040518263ffffffff1660e01b81526004016119839190612837565b600060405180830381865afa1580156119a0573d6000803e3d6000fd5b505050506040513d6000823e601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01682016040526119e6919081019061295c565b915091506000826000815181106119ff576119ff612414565b602002602001015183600181518110611a1a57611a1a612414565b6020026020010151611a2c9190612a1f565b9050600082600081518110611a4357611a43612414565b602002602001015183600181518110611a5e57611a5e612414565b6020026020010151611a709190612a64565b9050611a8263ffffffff891683612a91565b965060008260060b128015611aa85750611aa263ffffffff891683612ae7565b60060b15155b15611abb5786611ab781612b09565b9750505b6000611ae173ffffffffffffffffffffffffffffffffffffffff63ffffffff8b16612b48565b9050611b0b77ffffffffffffffffffffffffffffffffffffffff00000000602084901b1682612b88565b96505050505050509250929050565b600080611b2686611cf4565b90506fffffffffffffffffffffffffffffffff73ffffffffffffffffffffffffffffffffffffffff821611611c25576000611b7773ffffffffffffffffffffffffffffffffffffffff831680612818565b90508373ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff1610611be757611be27801000000000000000000000000000000000000000000000000876fffffffffffffffffffffffffffffffff1683612175565b611c1d565b611c1d81876fffffffffffffffffffffffffffffffff167801000000000000000000000000000000000000000000000000612175565b925050611ceb565b6000611c5173ffffffffffffffffffffffffffffffffffffffff83168068010000000000000000612175565b90508373ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff1610611cb957611cb4700100000000000000000000000000000000876fffffffffffffffffffffffffffffffff1683612175565b611ce7565b611ce781876fffffffffffffffffffffffffffffffff16700100000000000000000000000000000000612175565b9250505b50949350505050565b60008060008360020b12611d0b578260020b611d18565b8260020b611d1890612bbf565b9050611d437ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff27618612bf7565b62ffffff16811115611db1576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600160248201527f540000000000000000000000000000000000000000000000000000000000000060448201526064016107e4565b600081600116600003611dd557700100000000000000000000000000000000611de7565b6ffffcb933bd6fad37aa2d162d1a5940015b70ffffffffffffffffffffffffffffffffff1690506002821615611e26576080611e21826ffff97272373d413259a46990580e213a612818565b901c90505b6004821615611e50576080611e4b826ffff2e50f5f656932ef12357cf3c7fdcc612818565b901c90505b6008821615611e7a576080611e75826fffe5caca7e10e4e61c3624eaa0941cd0612818565b901c90505b6010821615611ea4576080611e9f826fffcb9843d60f6159c9db58835c926644612818565b901c90505b6020821615611ece576080611ec9826fff973b41fa98c081472e6896dfb254c0612818565b901c90505b6040821615611ef8576080611ef3826fff2ea16466c96a3843ec78b326b52861612818565b901c90505b6080821615611f22576080611f1d826ffe5dee046a99a2a811c461f1969c3053612818565b901c90505b610100821615611f4d576080611f48826ffcbe86c7900a88aedcffc83b479aa3a4612818565b901c90505b610200821615611f78576080611f73826ff987a7253ac413176f2b074cf7815e54612818565b901c90505b610400821615611fa3576080611f9e826ff3392b0822b70005940c7a398e4b70f3612818565b901c90505b610800821615611fce576080611fc9826fe7159475a2c29b7443b29c7fa6e889d9612818565b901c90505b611000821615611ff9576080611ff4826fd097f3bdfd2022b8845ad8f792aa5825612818565b901c90505b61200082161561202457608061201f826fa9f746462d870fdf8a65dc1f90e061e5612818565b901c90505b61400082161561204f57608061204a826f70d869a156d2a1b890bb3df62baf32f7612818565b901c90505b61800082161561207a576080612075826f31be135f97d08fd981231505542fcfa6612818565b901c90505b620100008216156120a65760806120a1826f09aa508b5b7a84e1c677de54f3e99bc9612818565b901c90505b620200008216156120d15760806120cc826e5d6af8dedb81196699c329225ee604612818565b901c90505b620400008216156120fb5760806120f6826d2216e584f5fa1ea926041bedfe98612818565b901c90505b6208000082161561212357608061211e826b048a170391f7dc42444e8fa2612818565b901c90505b60008460020b131561213e5761213b8160001961279a565b90505b61214d64010000000082612c35565b1561215957600161215c565b60005b61216d9060ff16602083901c61267b565b949350505050565b60008080600019858709858702925082811083820303915050806000036121ae57600084116121a357600080fd5b508290049050611802565b8084116121ba57600080fd5b6000848688098084039381119092039190506000856121d881612bbf565b169586900495938490049360008190030460010190506121f88184612818565b909317926000612209876003612818565b60021890506122188188612818565b612223906002612c49565b61222d9082612818565b90506122398188612818565b612244906002612c49565b61224e9082612818565b905061225a8188612818565b612265906002612c49565b61226f9082612818565b905061227b8188612818565b612286906002612c49565b6122909082612818565b905061229c8188612818565b6122a7906002612c49565b6122b19082612818565b90506122bd8188612818565b6122c8906002612c49565b6122d29082612818565b90506122de8186612818565b9998505050505050505050565b73ffffffffffffffffffffffffffffffffffffffff8116811461057d57600080fd5b60006020828403121561231f57600080fd5b8135611802816122eb565b63ffffffff8116811461057d57600080fd5b60006020828403121561234e57600080fd5b81356118028161232a565b6020808252825182820181905260009190848201906040850190845b818110156123a757835173ffffffffffffffffffffffffffffffffffffffff1683529284019291840191600101612375565b50909695505050505050565b6000602082840312156123c557600080fd5b81356fffffffffffffffffffffffffffffffff8116811461180257600080fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000600019820361248557612485612443565b5060010190565b805161ffff8116811461249e57600080fd5b919050565b8051801515811461249e57600080fd5b600080600080600080600060e0888a0312156124ce57600080fd5b87516124d9816122eb565b8097505060208801518060020b81146124f157600080fd5b95506124ff6040890161248c565b945061250d6060890161248c565b935061251b6080890161248c565b925060a088015160ff8116811461253157600080fd5b915061253f60c089016124a3565b905092959891949750929550565b61ffff81811683821601908082111561256857612568612443565b5092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b600061ffff808416806125b3576125b361256f565b92169190910692915050565b8051600681900b811461249e57600080fd5b600080600080608085870312156125e757600080fd5b84516125f28161232a565b9350612600602086016125bf565b92506040850151612610816122eb565b915061261e606086016124a3565b905092959194509250565b63ffffffff82811682821603908082111561256857612568612443565b60008060006060848603121561265b57600080fd5b612664846124a3565b925060208401519150604084015190509250925092565b8082018082111561074057610740612443565b60ff828116828216039081111561074057610740612443565b600181815b808511156126e25781600019048211156126c8576126c8612443565b808516156126d557918102915b93841c93908002906126ac565b509250929050565b6000826126f957506001610740565b8161270657506000610740565b816001811461271c576002811461272657612742565b6001915050610740565b60ff84111561273757612737612443565b50506001821b610740565b5060208310610133831016604e8410600b8410161715612765575081810a610740565b61276f83836126a7565b806000190482111561278357612783612443565b029392505050565b600061180260ff8416836126ea565b6000826127a9576127a961256f565b500490565b805169ffffffffffffffffffff8116811461249e57600080fd5b600080600080600060a086880312156127e057600080fd5b6127e9866127ae565b945060208601519350604086015192506060860151915061280c608087016127ae565b90509295509295909350565b600081600019048311821515161561283257612832612443565b500290565b6020808252825182820181905260009190848201906040850190845b818110156123a757835163ffffffff1683529284019291840191600101612853565b604051601f82017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016810167ffffffffffffffff811182821017156128bc576128bc6123e5565b604052919050565b600067ffffffffffffffff8211156128de576128de6123e5565b5060051b60200190565b600082601f8301126128f957600080fd5b8151602061290e612909836128c4565b612875565b82815260059290921b8401810191818101908684111561292d57600080fd5b8286015b84811015612951578051612944816122eb565b8352918301918301612931565b509695505050505050565b6000806040838503121561296f57600080fd5b825167ffffffffffffffff8082111561298757600080fd5b818501915085601f83011261299b57600080fd5b815160206129ab612909836128c4565b82815260059290921b840181019181810190898411156129ca57600080fd5b948201945b838610156129ef576129e0866125bf565b825294820194908201906129cf565b91880151919650909350505080821115612a0857600080fd5b50612a15858286016128e8565b9150509250929050565b600682810b9082900b037fffffffffffffffffffffffffffffffffffffffffffffffffff800000000000008112667fffffffffffff8213171561074057610740612443565b73ffffffffffffffffffffffffffffffffffffffff82811682821603908082111561256857612568612443565b60008160060b8360060b80612aa857612aa861256f565b60001981147fffffffffffffffffffffffffffffffffffffffffffffffffff8000000000000083141615612ade57612ade612443565b90059392505050565b60008260060b80612afa57612afa61256f565b808360060b0791505092915050565b60008160020b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8000008103612b3e57612b3e612443565b6000190192915050565b600077ffffffffffffffffffffffffffffffffffffffffffffffff80831681851681830481118215151615612b7f57612b7f612443565b02949350505050565b600077ffffffffffffffffffffffffffffffffffffffffffffffff80841680612bb357612bb361256f565b92169190910492915050565b60007f80000000000000000000000000000000000000000000000000000000000000008203612bf057612bf0612443565b5060000390565b60008160020b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8000008103612c2c57612c2c612443565b60000392915050565b600082612c4457612c4461256f565b500690565b818103818111156107405761074061244356fea2646970667358221220f3c0fb8670ebde54cfa6519211fa8788d75e2e7a7a58c09471b2dc32f85b77c664736f6c63430008100033

Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

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

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
Loading...
Loading
Loading...
Loading
Loading...
Loading

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.