ETH Price: $1,588.23 (-0.83%)
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To
Transfer Ownersh...205633392024-08-19 14:42:11241 days ago1724078531IN
0xC6f3405c...D1d56Ee05
0 ETH0.00017263.61571726

Latest 12 internal transactions

Advanced mode:
Parent Transaction Hash Method Block
From
To
Update Price Fee...214085882024-12-15 14:42:59123 days ago1734273779
0xC6f3405c...D1d56Ee05
2 wei
Update Price214085882024-12-15 14:42:59123 days ago1734273779
0xC6f3405c...D1d56Ee05
2 wei
Update Price Fee...214085402024-12-15 14:33:11123 days ago1734273191
0xC6f3405c...D1d56Ee05
2 wei
Update Price214085402024-12-15 14:33:11123 days ago1734273191
0xC6f3405c...D1d56Ee05
2 wei
Update Price Fee...209917722024-10-18 10:12:35182 days ago1729246355
0xC6f3405c...D1d56Ee05
2 wei
Update Price209917722024-10-18 10:12:35182 days ago1729246355
0xC6f3405c...D1d56Ee05
2 wei
Update Price Fee...209874442024-10-17 19:42:23182 days ago1729194143
0xC6f3405c...D1d56Ee05
2 wei
Update Price209874442024-10-17 19:42:23182 days ago1729194143
0xC6f3405c...D1d56Ee05
2 wei
Update Price Fee...209874182024-10-17 19:36:59182 days ago1729193819
0xC6f3405c...D1d56Ee05
2 wei
Update Price209874182024-10-17 19:36:59182 days ago1729193819
0xC6f3405c...D1d56Ee05
2 wei
Update Price Fee...209801612024-10-16 19:17:47183 days ago1729106267
0xC6f3405c...D1d56Ee05
2 wei
Update Price209801612024-10-16 19:17:47183 days ago1729106267
0xC6f3405c...D1d56Ee05
2 wei
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
PythPriceOracle

Compiler Version
v0.8.25+commit.b61c2a91

Optimization Enabled:
Yes with 999999 runs

Other Settings:
paris EvmVersion
File 1 of 15 : PythPriceOracle.sol
// SPDX-License-Identifier: ISC
pragma solidity 0.8.25;

import "@openzeppelin/contracts/access/Ownable2Step.sol";
import "@openzeppelin/contracts/utils/math/Math.sol";
import "@pythnetwork/pyth-sdk-solidity/IPyth.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import "@openzeppelin/contracts/utils/introspection/ERC165.sol";
import "./interfaces/IPriceOracle.sol";
import "./Pricing.sol";
import "./Refundable.sol";

/**
 * @title Pyth implementation of IPriceOracle, acting as an adapter to allow LetterOfCredit and other contracts that use
 * IPriceOracle to integrate with Pyth.
 *
 * @custom:security-contact [email protected]
 */
contract PythPriceOracle is Ownable2Step, IPriceOracle, ERC165, Refundable {
    /***************
     * ERROR TYPES *
     ***************/

    error RelatedArraysLengthMismatch(uint256 _firstLength, uint256 _secondLength);
    error InvalidOraclePrice(address _tokenAddress, int64 _price, uint64 _conf);
    error InsufficientFee(uint256 _got, uint256 _need);
    error UnsupportedTokenAddress(address _tokenAddress);

    /******************
     * CONTRACT STATE *
     ******************/

    IPyth public immutable pythContract;
    /// The token address => `TokenInfo` map containing Pyth Price Feed ID and other information for the token.
    mapping(address => TokenInfo) public addressToTokenInfo;

    /**********
     * EVENTS *
     **********/

    event PriceFeedUpdated(address _tokenAddress, bytes32 _oldPriceFeedId, bytes32 _newPriceFeedId);

    /***********
     * STRUCTS *
     ***********/

    struct TokenInfo {
        bytes32 priceFeedId;
        uint8 decimals;
    }

    /*************
     * FUNCTIONS *
     *************/

    constructor(
        IPyth _pythContractAddress,
        address[] memory _tokenAddresses,
        bytes32[] memory _priceFeedIds
    ) Ownable(msg.sender) {
        pythContract = _pythContractAddress;

        _upsertPriceFeedIdsAsOwner(_tokenAddresses, _priceFeedIds);
    }

    /****************
     * IPriceOracle *
     ****************/

    /**
     * @notice Gets the existing price to trade the provided input token for the provided output token. Note: this
     * function takes the ERC-20 decimals of the tokens into account such that the price is the amount of the output
     * token that one would receive in exchange for 1 unit of the input token.
     * For example, if 1 WBTC = 16.32 WETH, 1e8 = 16.32e18, 1 = 16.32e18/1e8 = 163200000000
     * so 1 "satoshi" of WBTC is worth 163200000000 "wei" of WETH.
     *
     * @dev The price is pieced together from the <inputToken>/USD and <outputToken>/USD prices fetched from Pyth. For
     * more information, see Pyth Price Feeds here: https://pyth.network/developers/price-feed-ids.
     *
     *  Example:
     *      input (WETH): price: 158946315000; exponent: -8, decimals: 18
     *      output (USDC): price: 100000000; exponent: -8, decimals: 6
     *      WETH -> USDC should be 1589.46315000, scaled to account for decimals
     *
     * Generic calculation:
     * outputPerUnitInputPrice = inputPrice * 10**inputExponent * 10**outputDecimals / (outputPrice * 10**outputExponent * 10**inputDecimals)
     * Note: we'll account for precision below.
     *
     * WETH -> USDC example:
     *      outputPerUnitInputPrice = inputPrice * 10**inputExponent * 10**outputDecimals / (outputPrice * 10**outputExponent * 10**inputDecimals)
     *                              = 158946315000 * 10**-8 * 10**6 / (100000000 * 10**-8 * 10**18)
     *                              = 158946315000 * 10**6 / (100000000 * 10**18)
     *                              = 158946315000 / (100000000 * 10**12)
     *                              = 0.00000000158946315
     * Sanity Check:
     *                        1 wei = 0.00000000158946315 USDC
     *                        1 wei = 0.00000000000000158946315 USD (USDC / 10**6 = USD)
     *                        1 ETH = 0.00000000000000158946315 USD * 10**18
     *                        1 ETH = 1589.46315 USD
     *
     * Accounting for precision in integer math:
     *      How do we guarantee a minimum of X digits of precision in our price?
     *          outputPerUnitInputPrice = inputPrice * 10**inputExponent * 10**outputDecimals / (outputPrice * 10**outputExponent * 10**inputDecimals)
     *          Represented as separate price and exponent:
     *              price = inputPrice / outputPrice;
     *              exponent = inputExponent + outputDecimals - outputExponent - inputDecimals
     *
     *          pricePrecisionDecimals = log10(inputPrice) - log10(outputPrice)
     *          precisionBufferExponent = (pricePrecisionDecimals < X) ? (X - pricePrecisionDecimals) : 0
     *          price = 10**precisionBufferExponent * inputPrice / outputPrice
     *          exponent = inputExponent + outputDecimals - outputExponent - inputDecimals - precisionBufferExponent
     *
     * @dev It is assumed that the caller of this contract validates the timestamp of the returned `_price` for its uses.
     *
     * @inheritdoc IPriceOracle
     */
    function getPrice(
        address _inputTokenAddress,
        address _outputTokenAddress
    ) external view returns (Pricing.OraclePrice memory _price) {
        TokenInfo memory inputTokenInfo = _fetchAndValidateTokenInfo(_inputTokenAddress);
        TokenInfo memory outputTokenInfo = _fetchAndValidateTokenInfo(_outputTokenAddress);

        // NB: getPriceUnsafe because callers of this function do their own recency checks.
        // Get token USD prices & ensure positive
        PythStructs.Price memory inputUsdPrice = pythContract.getPriceUnsafe(inputTokenInfo.priceFeedId);
        if (inputUsdPrice.price <= 0 || inputUsdPrice.conf >= uint64(inputUsdPrice.price))
            revert InvalidOraclePrice(_inputTokenAddress, inputUsdPrice.price, inputUsdPrice.conf);

        PythStructs.Price memory outputUsdPrice = pythContract.getPriceUnsafe(outputTokenInfo.priceFeedId);
        if (outputUsdPrice.price <= 0 || outputUsdPrice.conf >= uint64(outputUsdPrice.price))
            revert InvalidOraclePrice(_outputTokenAddress, outputUsdPrice.price, outputUsdPrice.conf);

        // pricePrecisionDecimals = log10(inputPrice) - log10(outputPrice)
        int256 pricePrecisionDecimals = int256(Math.log10(uint256(int256(inputUsdPrice.price)))) -
            int256(Math.log10(uint256(int256(outputUsdPrice.price))));

        // Require at least MAX(outputTokenDecimals, 18) digits of precision (18 is arbitrary at the moment but is thought to be good enough).
        int256 requiredDigitsOfPrecision;
        if (outputTokenInfo.decimals < 18) {
            requiredDigitsOfPrecision = 18;
        } else {
            requiredDigitsOfPrecision = int256(uint256(outputTokenInfo.decimals));
        }
        int256 precisionBufferExponent = requiredDigitsOfPrecision - pricePrecisionDecimals;
        if (precisionBufferExponent < 0) {
            precisionBufferExponent = 0;
        }

        // price = 10**precisionBufferExponent * inputPrice / outputPrice
        _price.price =
            (10 ** uint256(precisionBufferExponent) * uint256(uint64(inputUsdPrice.price))) /
            uint256(uint64(outputUsdPrice.price));

        // exponent = inputExponent + outputDecimals - outputExponent - inputDecimals - precisionBufferExponent
        _price.exponent =
            inputUsdPrice.expo +
            int32(uint32(outputTokenInfo.decimals)) -
            outputUsdPrice.expo -
            int32(uint32(inputTokenInfo.decimals)) -
            int32(precisionBufferExponent);

        if (inputUsdPrice.publishTime < outputUsdPrice.publishTime) {
            _price.publishTime = inputUsdPrice.publishTime;
        } else {
            _price.publishTime = outputUsdPrice.publishTime;
        }
    }

    /*
     * @inheritdoc IPriceOracle
     */
    function updatePrice(
        address _inputTokenAddress,
        address _outputTokenAddress,
        bytes calldata _oracleData
    ) external payable refundExcess returns (Pricing.OraclePrice memory) {
        _fetchAndValidateTokenInfo(_inputTokenAddress);
        _fetchAndValidateTokenInfo(_outputTokenAddress);

        bytes[] memory updateData = abi.decode(_oracleData, (bytes[]));

        uint256 fee = pythContract.getUpdateFee(updateData);
        if (msg.value < fee) revert InsufficientFee(msg.value, fee);

        pythContract.updatePriceFeeds{value: fee}(updateData);

        return this.getPrice(_inputTokenAddress, _outputTokenAddress);
    }

    /*
     * @inheritdoc IPriceOracle
     */
    function getUpdateFee(bytes calldata _oracleData) external view returns (uint256) {
        bytes[] memory updateData = abi.decode(_oracleData, (bytes[]));
        return pythContract.getUpdateFee(updateData);
    }

    /***********
     * ERC-165 *
     ***********/

    /**
     * Indicates support for IERC165 and IPriceOracle.
     * @inheritdoc IERC165
     */
    function supportsInterface(bytes4 interfaceID) public view override returns (bool) {
        return interfaceID == type(IPriceOracle).interfaceId || super.supportsInterface(interfaceID);
    }

    /**
     * Fetches token info for the provided token address, if it exists in the `addressToTokenInfo` storage field. If it
     * does not exist, this will revert with an UnsupportedTokenAddress error.
     * @param _address The address of the token to fetch.
     * @return _tokenInfo The resulting `TokenInfo` object on successful fetch.
     */
    function _fetchAndValidateTokenInfo(address _address) private view returns (TokenInfo memory _tokenInfo) {
        _tokenInfo = addressToTokenInfo[_address];
        if (_tokenInfo.priceFeedId == bytes32(0)) revert UnsupportedTokenAddress(_address);
    }

    /**
     * Upserts the TokenInfo associated with the provided token addresses in contract storage.
     * @param _tokenAddresses The addresses of the tokens to upsert. Note: indexes in this array correspond 1:1 with indexes in the `_priceFeedIds` array.
     * @param _priceFeedIds The price feed ID of the token associated with the corresponding index of the `_tokenAddresses` array.
     */
    function upsertPriceFeedIds(address[] memory _tokenAddresses, bytes32[] memory _priceFeedIds) external onlyOwner {
        _upsertPriceFeedIdsAsOwner(_tokenAddresses, _priceFeedIds);
    }

    /**
     * Upserts the TokenInfo associated with the provided token addresses in contract storage.
     * @dev This function does no authorization, instead assuming that authorization has been done by the caller of this function.
     * @param _tokenAddresses The addresses of the tokens to upsert. Note: indexes in this array correspond 1:1 with indexes in the `_priceFeedIds` array.
     * @param _priceFeedIds The price feed ID of the token associated with the corresponding index of the `_tokenAddresses` array.
     */
    function _upsertPriceFeedIdsAsOwner(address[] memory _tokenAddresses, bytes32[] memory _priceFeedIds) private {
        if (_tokenAddresses.length != _priceFeedIds.length)
            revert RelatedArraysLengthMismatch(_tokenAddresses.length, _priceFeedIds.length);

        for (uint256 i = 0; i < _tokenAddresses.length; i++) {
            TokenInfo storage tokenInfo = addressToTokenInfo[_tokenAddresses[i]];
            bytes32 oldPriceFeedId = tokenInfo.priceFeedId;
            tokenInfo.priceFeedId = _priceFeedIds[i];
            if (_priceFeedIds[i] == bytes32(0)) {
                tokenInfo.decimals = 0;
            } else {
                uint8 decimals = IERC20Metadata(_tokenAddresses[i]).decimals();
                tokenInfo.decimals = decimals;
            }
            emit PriceFeedUpdated(_tokenAddresses[i], oldPriceFeedId, _priceFeedIds[i]);
        }
    }
}

File 2 of 15 : Ownable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)

pragma solidity ^0.8.20;

import {Context} from "../utils/Context.sol";

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

    /**
     * @dev The caller account is not authorized to perform an operation.
     */
    error OwnableUnauthorizedAccount(address account);

    /**
     * @dev The owner is not a valid owner account. (eg. `address(0)`)
     */
    error OwnableInvalidOwner(address owner);

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

    /**
     * @dev Initializes the contract setting the address provided by the deployer as the initial owner.
     */
    constructor(address initialOwner) {
        if (initialOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(initialOwner);
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

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

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        if (owner() != _msgSender()) {
            revert OwnableUnauthorizedAccount(_msgSender());
        }
    }

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

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        if (newOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}

File 3 of 15 : Ownable2Step.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable2Step.sol)

pragma solidity ^0.8.20;

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

/**
 * @dev Contract module which provides access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * The initial owner is specified at deployment time in the constructor for `Ownable`. This
 * can later be changed with {transferOwnership} and {acceptOwnership}.
 *
 * This module is used through inheritance. It will make available all functions
 * from parent (Ownable).
 */
abstract contract Ownable2Step is Ownable {
    address private _pendingOwner;

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

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

    /**
     * @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual override onlyOwner {
        _pendingOwner = newOwner;
        emit OwnershipTransferStarted(owner(), newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual override {
        delete _pendingOwner;
        super._transferOwnership(newOwner);
    }

    /**
     * @dev The new owner accepts the ownership transfer.
     */
    function acceptOwnership() public virtual {
        address sender = _msgSender();
        if (pendingOwner() != sender) {
            revert OwnableUnauthorizedAccount(sender);
        }
        _transferOwnership(sender);
    }
}

File 4 of 15 : IERC20Metadata.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity ^0.8.20;

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

/**
 * @dev Interface for the optional metadata functions from the ERC20 standard.
 */
interface IERC20Metadata is IERC20 {
    /**
     * @dev Returns the name of the token.
     */
    function name() external view returns (string memory);

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

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

File 5 of 15 : IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

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

    /**
     * @dev Returns the value of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

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

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

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

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

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

File 6 of 15 : Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)

pragma solidity ^0.8.20;

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

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }

    function _contextSuffixLength() internal view virtual returns (uint256) {
        return 0;
    }
}

File 7 of 15 : ERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/ERC165.sol)

pragma solidity ^0.8.20;

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

/**
 * @dev Implementation of the {IERC165} interface.
 *
 * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
 * for the additional interface id that will be supported. For example:
 *
 * ```solidity
 * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
 *     return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
 * }
 * ```
 */
abstract contract ERC165 is IERC165 {
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
        return interfaceId == type(IERC165).interfaceId;
    }
}

File 8 of 15 : IERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/IERC165.sol)

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[EIP].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165 {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}

File 9 of 15 : Math.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/Math.sol)

pragma solidity ^0.8.20;

/**
 * @dev Standard math utilities missing in the Solidity language.
 */
library Math {
    /**
     * @dev Muldiv operation overflow.
     */
    error MathOverflowedMulDiv();

    enum Rounding {
        Floor, // Toward negative infinity
        Ceil, // Toward positive infinity
        Trunc, // Toward zero
        Expand // Away from zero
    }

    /**
     * @dev Returns the addition of two unsigned integers, with an overflow flag.
     */
    function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            uint256 c = a + b;
            if (c < a) return (false, 0);
            return (true, c);
        }
    }

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

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

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

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

    /**
     * @dev Returns the largest of two numbers.
     */
    function max(uint256 a, uint256 b) internal pure returns (uint256) {
        return a > b ? a : b;
    }

    /**
     * @dev Returns the smallest of two numbers.
     */
    function min(uint256 a, uint256 b) internal pure returns (uint256) {
        return a < b ? a : b;
    }

    /**
     * @dev Returns the average of two numbers. The result is rounded towards
     * zero.
     */
    function average(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b) / 2 can overflow.
        return (a & b) + (a ^ b) / 2;
    }

    /**
     * @dev Returns the ceiling of the division of two numbers.
     *
     * This differs from standard division with `/` in that it rounds towards infinity instead
     * of rounding towards zero.
     */
    function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
        if (b == 0) {
            // Guarantee the same behavior as in a regular Solidity division.
            return a / b;
        }

        // (a + b - 1) / b can overflow on addition, so we distribute.
        return a == 0 ? 0 : (a - 1) / b + 1;
    }

    /**
     * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or
     * denominator == 0.
     * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) with further edits by
     * Uniswap Labs also under MIT license.
     */
    function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
        unchecked {
            // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
            // 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 = x * y; // Least significant 256 bits of the product
            uint256 prod1; // Most significant 256 bits of the product
            assembly {
                let mm := mulmod(x, y, not(0))
                prod1 := sub(sub(mm, prod0), lt(mm, prod0))
            }

            // Handle non-overflow cases, 256 by 256 division.
            if (prod1 == 0) {
                // Solidity will revert if denominator == 0, unlike the div opcode on its own.
                // The surrounding unchecked block does not change this fact.
                // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
                return prod0 / denominator;
            }

            // Make sure the result is less than 2^256. Also prevents denominator == 0.
            if (denominator <= prod1) {
                revert MathOverflowedMulDiv();
            }

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

            // Make division exact by subtracting the remainder from [prod1 prod0].
            uint256 remainder;
            assembly {
                // Compute remainder using mulmod.
                remainder := mulmod(x, y, denominator)

                // Subtract 256 bit number from 512 bit number.
                prod1 := sub(prod1, gt(remainder, prod0))
                prod0 := sub(prod0, remainder)
            }

            // Factor powers of two out of denominator and compute largest power of two divisor of denominator.
            // Always >= 1. See https://cs.stackexchange.com/q/138556/92363.

            uint256 twos = denominator & (0 - denominator);
            assembly {
                // Divide denominator by twos.
                denominator := div(denominator, twos)

                // Divide [prod1 prod0] by twos.
                prod0 := div(prod0, twos)

                // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
                twos := add(div(sub(0, twos), twos), 1)
            }

            // Shift in bits from prod1 into prod0.
            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 for
            // four bits. That is, denominator * inv = 1 mod 2^4.
            uint256 inverse = (3 * denominator) ^ 2;

            // Use the 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.
            inverse *= 2 - denominator * inverse; // inverse mod 2^8
            inverse *= 2 - denominator * inverse; // inverse mod 2^16
            inverse *= 2 - denominator * inverse; // inverse mod 2^32
            inverse *= 2 - denominator * inverse; // inverse mod 2^64
            inverse *= 2 - denominator * inverse; // inverse mod 2^128
            inverse *= 2 - denominator * inverse; // 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 preconditions 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 * inverse;
            return result;
        }
    }

    /**
     * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
     */
    function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
        uint256 result = mulDiv(x, y, denominator);
        if (unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0) {
            result += 1;
        }
        return result;
    }

    /**
     * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded
     * towards zero.
     *
     * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
     */
    function sqrt(uint256 a) internal pure returns (uint256) {
        if (a == 0) {
            return 0;
        }

        // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
        //
        // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
        // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
        //
        // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
        // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
        // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
        //
        // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
        uint256 result = 1 << (log2(a) >> 1);

        // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
        // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
        // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
        // into the expected uint128 result.
        unchecked {
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            return min(result, a / result);
        }
    }

    /**
     * @notice Calculates sqrt(a), following the selected rounding direction.
     */
    function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = sqrt(a);
            return result + (unsignedRoundsUp(rounding) && result * result < a ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 2 of a positive value rounded towards zero.
     * Returns 0 if given 0.
     */
    function log2(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 128;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 64;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 32;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 16;
            }
            if (value >> 8 > 0) {
                value >>= 8;
                result += 8;
            }
            if (value >> 4 > 0) {
                value >>= 4;
                result += 4;
            }
            if (value >> 2 > 0) {
                value >>= 2;
                result += 2;
            }
            if (value >> 1 > 0) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 2, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log2(value);
            return result + (unsignedRoundsUp(rounding) && 1 << result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 10 of a positive value rounded towards zero.
     * Returns 0 if given 0.
     */
    function log10(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >= 10 ** 64) {
                value /= 10 ** 64;
                result += 64;
            }
            if (value >= 10 ** 32) {
                value /= 10 ** 32;
                result += 32;
            }
            if (value >= 10 ** 16) {
                value /= 10 ** 16;
                result += 16;
            }
            if (value >= 10 ** 8) {
                value /= 10 ** 8;
                result += 8;
            }
            if (value >= 10 ** 4) {
                value /= 10 ** 4;
                result += 4;
            }
            if (value >= 10 ** 2) {
                value /= 10 ** 2;
                result += 2;
            }
            if (value >= 10 ** 1) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 10, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log10(value);
            return result + (unsignedRoundsUp(rounding) && 10 ** result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 256 of a positive value rounded towards zero.
     * Returns 0 if given 0.
     *
     * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
     */
    function log256(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 16;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 8;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 4;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 2;
            }
            if (value >> 8 > 0) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 256, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log256(value);
            return result + (unsignedRoundsUp(rounding) && 1 << (result << 3) < value ? 1 : 0);
        }
    }

    /**
     * @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.
     */
    function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {
        return uint8(rounding) % 2 == 1;
    }
}

File 10 of 15 : IPyth.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;

import "./PythStructs.sol";
import "./IPythEvents.sol";

/// @title Consume prices from the Pyth Network (https://pyth.network/).
/// @dev Please refer to the guidance at https://docs.pyth.network/documentation/pythnet-price-feeds/best-practices for how to consume prices safely.
/// @author Pyth Data Association
interface IPyth is IPythEvents {
    /// @notice Returns the period (in seconds) that a price feed is considered valid since its publish time
    function getValidTimePeriod() external view returns (uint validTimePeriod);

    /// @notice Returns the price and confidence interval.
    /// @dev Reverts if the price has not been updated within the last `getValidTimePeriod()` seconds.
    /// @param id The Pyth Price Feed ID of which to fetch the price and confidence interval.
    /// @return price - please read the documentation of PythStructs.Price to understand how to use this safely.
    function getPrice(
        bytes32 id
    ) external view returns (PythStructs.Price memory price);

    /// @notice Returns the exponentially-weighted moving average price and confidence interval.
    /// @dev Reverts if the EMA price is not available.
    /// @param id The Pyth Price Feed ID of which to fetch the EMA price and confidence interval.
    /// @return price - please read the documentation of PythStructs.Price to understand how to use this safely.
    function getEmaPrice(
        bytes32 id
    ) external view returns (PythStructs.Price memory price);

    /// @notice Returns the price of a price feed without any sanity checks.
    /// @dev This function returns the most recent price update in this contract without any recency checks.
    /// This function is unsafe as the returned price update may be arbitrarily far in the past.
    ///
    /// Users of this function should check the `publishTime` in the price to ensure that the returned price is
    /// sufficiently recent for their application. If you are considering using this function, it may be
    /// safer / easier to use either `getPrice` or `getPriceNoOlderThan`.
    /// @return price - please read the documentation of PythStructs.Price to understand how to use this safely.
    function getPriceUnsafe(
        bytes32 id
    ) external view returns (PythStructs.Price memory price);

    /// @notice Returns the price that is no older than `age` seconds of the current time.
    /// @dev This function is a sanity-checked version of `getPriceUnsafe` which is useful in
    /// applications that require a sufficiently-recent price. Reverts if the price wasn't updated sufficiently
    /// recently.
    /// @return price - please read the documentation of PythStructs.Price to understand how to use this safely.
    function getPriceNoOlderThan(
        bytes32 id,
        uint age
    ) external view returns (PythStructs.Price memory price);

    /// @notice Returns the exponentially-weighted moving average price of a price feed without any sanity checks.
    /// @dev This function returns the same price as `getEmaPrice` in the case where the price is available.
    /// However, if the price is not recent this function returns the latest available price.
    ///
    /// The returned price can be from arbitrarily far in the past; this function makes no guarantees that
    /// the returned price is recent or useful for any particular application.
    ///
    /// Users of this function should check the `publishTime` in the price to ensure that the returned price is
    /// sufficiently recent for their application. If you are considering using this function, it may be
    /// safer / easier to use either `getEmaPrice` or `getEmaPriceNoOlderThan`.
    /// @return price - please read the documentation of PythStructs.Price to understand how to use this safely.
    function getEmaPriceUnsafe(
        bytes32 id
    ) external view returns (PythStructs.Price memory price);

    /// @notice Returns the exponentially-weighted moving average price that is no older than `age` seconds
    /// of the current time.
    /// @dev This function is a sanity-checked version of `getEmaPriceUnsafe` which is useful in
    /// applications that require a sufficiently-recent price. Reverts if the price wasn't updated sufficiently
    /// recently.
    /// @return price - please read the documentation of PythStructs.Price to understand how to use this safely.
    function getEmaPriceNoOlderThan(
        bytes32 id,
        uint age
    ) external view returns (PythStructs.Price memory price);

    /// @notice Update price feeds with given update messages.
    /// This method requires the caller to pay a fee in wei; the required fee can be computed by calling
    /// `getUpdateFee` with the length of the `updateData` array.
    /// Prices will be updated if they are more recent than the current stored prices.
    /// The call will succeed even if the update is not the most recent.
    /// @dev Reverts if the transferred fee is not sufficient or the updateData is invalid.
    /// @param updateData Array of price update data.
    function updatePriceFeeds(bytes[] calldata updateData) external payable;

    /// @notice Wrapper around updatePriceFeeds that rejects fast if a price update is not necessary. A price update is
    /// necessary if the current on-chain publishTime is older than the given publishTime. It relies solely on the
    /// given `publishTimes` for the price feeds and does not read the actual price update publish time within `updateData`.
    ///
    /// This method requires the caller to pay a fee in wei; the required fee can be computed by calling
    /// `getUpdateFee` with the length of the `updateData` array.
    ///
    /// `priceIds` and `publishTimes` are two arrays with the same size that correspond to senders known publishTime
    /// of each priceId when calling this method. If all of price feeds within `priceIds` have updated and have
    /// a newer or equal publish time than the given publish time, it will reject the transaction to save gas.
    /// Otherwise, it calls updatePriceFeeds method to update the prices.
    ///
    /// @dev Reverts if update is not needed or the transferred fee is not sufficient or the updateData is invalid.
    /// @param updateData Array of price update data.
    /// @param priceIds Array of price ids.
    /// @param publishTimes Array of publishTimes. `publishTimes[i]` corresponds to known `publishTime` of `priceIds[i]`
    function updatePriceFeedsIfNecessary(
        bytes[] calldata updateData,
        bytes32[] calldata priceIds,
        uint64[] calldata publishTimes
    ) external payable;

    /// @notice Returns the required fee to update an array of price updates.
    /// @param updateData Array of price update data.
    /// @return feeAmount The required fee in Wei.
    function getUpdateFee(
        bytes[] calldata updateData
    ) external view returns (uint feeAmount);

    /// @notice Parse `updateData` and return price feeds of the given `priceIds` if they are all published
    /// within `minPublishTime` and `maxPublishTime`.
    ///
    /// You can use this method if you want to use a Pyth price at a fixed time and not the most recent price;
    /// otherwise, please consider using `updatePriceFeeds`. This method may store the price updates on-chain, if they
    /// are more recent than the current stored prices.
    ///
    /// This method requires the caller to pay a fee in wei; the required fee can be computed by calling
    /// `getUpdateFee` with the length of the `updateData` array.
    ///
    ///
    /// @dev Reverts if the transferred fee is not sufficient or the updateData is invalid or there is
    /// no update for any of the given `priceIds` within the given time range.
    /// @param updateData Array of price update data.
    /// @param priceIds Array of price ids.
    /// @param minPublishTime minimum acceptable publishTime for the given `priceIds`.
    /// @param maxPublishTime maximum acceptable publishTime for the given `priceIds`.
    /// @return priceFeeds Array of the price feeds corresponding to the given `priceIds` (with the same order).
    function parsePriceFeedUpdates(
        bytes[] calldata updateData,
        bytes32[] calldata priceIds,
        uint64 minPublishTime,
        uint64 maxPublishTime
    ) external payable returns (PythStructs.PriceFeed[] memory priceFeeds);

    /// @notice Similar to `parsePriceFeedUpdates` but ensures the updates returned are
    /// the first updates published in minPublishTime. That is, if there are multiple updates for a given timestamp,
    /// this method will return the first update. This method may store the price updates on-chain, if they
    /// are more recent than the current stored prices.
    ///
    ///
    /// @dev Reverts if the transferred fee is not sufficient or the updateData is invalid or there is
    /// no update for any of the given `priceIds` within the given time range and uniqueness condition.
    /// @param updateData Array of price update data.
    /// @param priceIds Array of price ids.
    /// @param minPublishTime minimum acceptable publishTime for the given `priceIds`.
    /// @param maxPublishTime maximum acceptable publishTime for the given `priceIds`.
    /// @return priceFeeds Array of the price feeds corresponding to the given `priceIds` (with the same order).
    function parsePriceFeedUpdatesUnique(
        bytes[] calldata updateData,
        bytes32[] calldata priceIds,
        uint64 minPublishTime,
        uint64 maxPublishTime
    ) external payable returns (PythStructs.PriceFeed[] memory priceFeeds);
}

File 11 of 15 : IPythEvents.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;

/// @title IPythEvents contains the events that Pyth contract emits.
/// @dev This interface can be used for listening to the updates for off-chain and testing purposes.
interface IPythEvents {
    /// @dev Emitted when the price feed with `id` has received a fresh update.
    /// @param id The Pyth Price Feed ID.
    /// @param publishTime Publish time of the given price update.
    /// @param price Price of the given price update.
    /// @param conf Confidence interval of the given price update.
    event PriceFeedUpdate(
        bytes32 indexed id,
        uint64 publishTime,
        int64 price,
        uint64 conf
    );

    /// @dev Emitted when a batch price update is processed successfully.
    /// @param chainId ID of the source chain that the batch price update comes from.
    /// @param sequenceNumber Sequence number of the batch price update.
    event BatchPriceFeedUpdate(uint16 chainId, uint64 sequenceNumber);
}

File 12 of 15 : PythStructs.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;

contract PythStructs {
    // A price with a degree of uncertainty, represented as a price +- a confidence interval.
    //
    // The confidence interval roughly corresponds to the standard error of a normal distribution.
    // Both the price and confidence are stored in a fixed-point numeric representation,
    // `x * (10^expo)`, where `expo` is the exponent.
    //
    // Please refer to the documentation at https://docs.pyth.network/documentation/pythnet-price-feeds/best-practices for how
    // to how this price safely.
    struct Price {
        // Price
        int64 price;
        // Confidence interval around the price
        uint64 conf;
        // Price exponent
        int32 expo;
        // Unix timestamp describing when the price was published
        uint publishTime;
    }

    // PriceFeed represents a current aggregate price from pyth publisher feeds.
    struct PriceFeed {
        // The price ID.
        bytes32 id;
        // Latest available price
        Price price;
        // Latest available exponentially-weighted moving average price
        Price emaPrice;
    }
}

File 13 of 15 : IPriceOracle.sol
// SPDX-License-Identifier: ISC
pragma solidity 0.8.25;

import "../Pricing.sol";

/**
 * @title Defines the interface that PriceOracles must implement to be used within the LOC ecosystem.
 */
interface IPriceOracle {
    /**
     * @notice Gets the existing price to trade the provided input token for the provided output token.
     * @param _inputTokenAddress The address of the token to be [hypothetically] sent in a trade.
     * @param _outputTokenAddress The address of the token to be [hypothetically] received in a trade.
     * @return _price The `OraclePrice` for the specified trading pair.
     */
    function getPrice(
        address _inputTokenAddress,
        address _outputTokenAddress
    ) external returns (Pricing.OraclePrice memory _price);

    /*
     * @notice Pushes an oracle price update to the oracle update logic for a trading pair, returning updated price.
     * @dev Under the hood, return price should come from `getPrice(...)` to ensure that this returned price _always_
     * matches the price that a caller would get by immediately calling `getPrice(...)` after update.
     * @dev If the update is invalid or does not work for some reason, the transaction should revert, except in the case
     * in which a newer price already exists. In that case, the update should succeed as a no-op.
     * @param _inputTokenAddress The address of the token to be [hypothetically] sent in a trade.
     * @param _outputTokenAddress The address of the token to be [hypothetically] received in a trade.
     * @param _oracleData The oracle price data necessary for the implementation to verify content and update price.
     * @return _price The updated price set by the `_oracleData`.
     */
    function updatePrice(
        address _inputTokenAddress,
        address _outputTokenAddress,
        bytes calldata _oracleData
    ) external payable returns (Pricing.OraclePrice memory _price);

    /**
     * @notice Gets the fee required to use the provided `_oracleData` in a call to `updatePrice`.
     * @param _oracleData The oracle data bytes that may be passed to updatePrice.
     * @return _feeAmount The fee that must be passed as msg.value to `updatePrice` to submit the provided oracle data.
     */
    function getUpdateFee(bytes calldata _oracleData) external view returns (uint256 _feeAmount);
}

File 14 of 15 : Pricing.sol
// SPDX-License-Identifier: ISC
pragma solidity 0.8.25;

/**
 * @title Library with often used math-related helper functions related to the Anvil protocol.
 *
 * @custom:security-contact [email protected]
 */
library Pricing {
    error CastOverflow(uint256 input);

    /// Example: human-readable price is 25000, {price: 25, exponent: 3, ...}
    /// Example: human-readable price is 0.00004, {price: 4, exponent: -5, ...}
    struct OraclePrice {
        // Price
        uint256 price;
        // The exchange rate may be a decimal, but it will always be represented as a uint256.
        // The price should be multiplied by 10**exponent to get the proper scale.
        int32 exponent;
        // Unix timestamp describing when the price was published
        uint256 publishTime;
    }

    /**
     * @notice Calculates the collateral factor implied by the provided amounts of collateral and credited tokens.
     * @param _collateralTokenAmount The amount of the collateral token.
     * @param _creditedTokenAmount The amount of the credited token.
     * @param _price The price of the market in which the collateral is the input token and credited is the output token.
     * @return The calculated collateral factor in basis points.
     */
    function collateralFactorInBasisPoints(
        uint256 _collateralTokenAmount,
        uint256 _creditedTokenAmount,
        OraclePrice memory _price
    ) internal pure returns (uint16) {
        uint256 collateralInCredited = collateralAmountInCreditedToken(_collateralTokenAmount, _price);
        // Don't divide by 0
        if (collateralInCredited == 0) {
            return 0;
        }
        return uint16((_creditedTokenAmount * 10_000) / collateralInCredited);
    }

    /**
     * @notice Calculates the amount of the credited token the provided collateral would yield, given the provided price.
     * @param _collateralTokenAmount The amount of the collateral token.
     * @param _price The price of the market in which the collateral is the input token and credited is the output token.
     * @return _creditedTokenAmount The calculated amount of the credited token.
     */
    function collateralAmountInCreditedToken(
        uint256 _collateralTokenAmount,
        OraclePrice memory _price
    ) internal pure returns (uint256) {
        if (_price.exponent < 0) {
            return (_collateralTokenAmount * _price.price) / (10 ** uint256(int256(-1 * _price.exponent)));
        } else {
            return _collateralTokenAmount * _price.price * (10 ** uint256(int256(_price.exponent)));
        }
    }

    /**
     * @notice Calculates the provided percentage of the provided amount.
     * @param _amount The base amount for which the percentage will be calculated.
     * @param _percentageBasisPoints The percentage, represented in basis points. For example, 10_000 is 100%.
     * @return The resulting percentage.
     */
    function percentageOf(uint256 _amount, uint256 _percentageBasisPoints) internal pure returns (uint256) {
        return (_amount * _percentageBasisPoints) / 10_000;
    }

    /**
     * @notice Gets the result of the provided amount being increased by a relative fee.
     * @dev This is the exact reverse of the `amountBeforeFee` function. Please note that calling one
     * and then the other is not guaranteed to produce the starting value due to integer math.
     * @param _amount The amount, to which the fee will be added.
     * @param _feeBasisPoints The relative basis points value that amount should be increased by.
     * @return The resulting amount with the relative fee applied.
     */
    function amountWithFee(uint256 _amount, uint16 _feeBasisPoints) internal pure returns (uint256) {
        return _amount + percentageOf(_amount, uint256(_feeBasisPoints));
    }

    /**
     * @notice Given an amount with a relative fee baked in, returns the amount before the fee was added.
     * @dev This is the exact reverse of the `amountWithFee` function. Please note that calling one
     * and then the other is not guaranteed to produce the starting value due to integer math.
     * @param _amountWithFee The amount that includes the provided fee in its value.
     * @param _feeBasisPoints The basis points value of the fee baked into the provided amount.
     * @return The value of _amountWithFee before the _feeBasisPoints was added to it.
     */
    function amountBeforeFee(uint256 _amountWithFee, uint16 _feeBasisPoints) internal pure returns (uint256) {
        return (_amountWithFee * 10_000) / (10_000 + _feeBasisPoints);
    }

    /**
     * @dev Calculates the amount that is proportional to the provided fraction, given the denominator of the amount.
     * For instance if a1/a2 = b1/b2, then b1 = calculateProportionOfTotal(a1, a2, b2).
     * @param _aPortion The numerator of the reference proportion used to calculate the other numerator.
     * @param _aTotal The numerator of the reference proportion used to calculate the other numerator.
     * @param _bTotal The denominator for which we are calculating the numerator such that aPortion/aTotal = bPortion/bTotal.
     * @param _bPortion The numerator that is an equal proportion of _bTotal that _aPortion is to _aTotal.
     */
    function calculateProportionOfTotal(
        uint256 _aPortion,
        uint256 _aTotal,
        uint256 _bTotal
    ) internal pure returns (uint256 _bPortion) {
        if (_aTotal == 0) return 0;

        // NB: It is a conscious choice to not catch overflows before they happen. This means that callers need to
        // handle possible overflow reverts, but it saves gas for the great majority of cases.

        // _bPortion / _bTotal = _aPortion / _aTotal;
        // _bPortion = _bTotal * _aPortion / _aTotal
        _bPortion = (_bTotal * _aPortion) / _aTotal;
    }

    /**
     * @dev Safely casts the provided uint256 to an int256, reverting with CastOverflow on overflow.
     * @param _input The input uint256 to cast.
     * @return The safely casted uint256.
     */
    function safeCastToInt256(uint256 _input) internal pure returns (int256) {
        if (_input > uint256(type(int256).max)) {
            revert CastOverflow(_input);
        }
        return int256(_input);
    }
}

File 15 of 15 : Refundable.sol
// SPDX-License-Identifier: ISC
pragma solidity 0.8.25;

/**
 * @title Base contract that can be extended to pull in `refundExcess` modifier, which ensures that the ETH balance of a
 * contract is not increased as a result of a function call.
 *
 * @custom:security-contact [email protected]
 */
abstract contract Refundable {
    /**
     * @dev refunds excess ETH to the caller after an operation such that the contract's ETH balance cannot be increased
     * as a result of the operation.
     */
    modifier refundExcess() {
        uint256 startingBalance = address(this).balance;

        _;

        uint256 expectedEndingBalance = startingBalance - msg.value;
        if (address(this).balance > expectedEndingBalance) {
            payable(msg.sender).transfer(address(this).balance - expectedEndingBalance);
        }
    }
}

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

Contract Security Audit

Contract ABI

API
[{"inputs":[{"internalType":"contract IPyth","name":"_pythContractAddress","type":"address"},{"internalType":"address[]","name":"_tokenAddresses","type":"address[]"},{"internalType":"bytes32[]","name":"_priceFeedIds","type":"bytes32[]"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"uint256","name":"_got","type":"uint256"},{"internalType":"uint256","name":"_need","type":"uint256"}],"name":"InsufficientFee","type":"error"},{"inputs":[{"internalType":"address","name":"_tokenAddress","type":"address"},{"internalType":"int64","name":"_price","type":"int64"},{"internalType":"uint64","name":"_conf","type":"uint64"}],"name":"InvalidOraclePrice","type":"error"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"OwnableInvalidOwner","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"OwnableUnauthorizedAccount","type":"error"},{"inputs":[{"internalType":"uint256","name":"_firstLength","type":"uint256"},{"internalType":"uint256","name":"_secondLength","type":"uint256"}],"name":"RelatedArraysLengthMismatch","type":"error"},{"inputs":[{"internalType":"address","name":"_tokenAddress","type":"address"}],"name":"UnsupportedTokenAddress","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferStarted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_tokenAddress","type":"address"},{"indexed":false,"internalType":"bytes32","name":"_oldPriceFeedId","type":"bytes32"},{"indexed":false,"internalType":"bytes32","name":"_newPriceFeedId","type":"bytes32"}],"name":"PriceFeedUpdated","type":"event"},{"inputs":[],"name":"acceptOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"addressToTokenInfo","outputs":[{"internalType":"bytes32","name":"priceFeedId","type":"bytes32"},{"internalType":"uint8","name":"decimals","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_inputTokenAddress","type":"address"},{"internalType":"address","name":"_outputTokenAddress","type":"address"}],"name":"getPrice","outputs":[{"components":[{"internalType":"uint256","name":"price","type":"uint256"},{"internalType":"int32","name":"exponent","type":"int32"},{"internalType":"uint256","name":"publishTime","type":"uint256"}],"internalType":"struct Pricing.OraclePrice","name":"_price","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"_oracleData","type":"bytes"}],"name":"getUpdateFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pendingOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pythContract","outputs":[{"internalType":"contract IPyth","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceID","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_inputTokenAddress","type":"address"},{"internalType":"address","name":"_outputTokenAddress","type":"address"},{"internalType":"bytes","name":"_oracleData","type":"bytes"}],"name":"updatePrice","outputs":[{"components":[{"internalType":"uint256","name":"price","type":"uint256"},{"internalType":"int32","name":"exponent","type":"int32"},{"internalType":"uint256","name":"publishTime","type":"uint256"}],"internalType":"struct Pricing.OraclePrice","name":"","type":"tuple"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address[]","name":"_tokenAddresses","type":"address[]"},{"internalType":"bytes32[]","name":"_priceFeedIds","type":"bytes32[]"}],"name":"upsertPriceFeedIds","outputs":[],"stateMutability":"nonpayable","type":"function"}]

60a060405234801561001057600080fd5b5060405161204638038061204683398101604081905261002f916103d8565b338061005657604051631e4fbdf760e01b8152600060048201526024015b60405180910390fd5b61005f8161007f565b506001600160a01b038316608052610077828261009b565b5050506104f0565b600180546001600160a01b03191690556100988161029b565b50565b80518251146100ca57815181516040516337f0621f60e01b81526004810192909252602482015260440161004d565b60005b8251811015610296576000600260008584815181106100ee576100ee6104b0565b60200260200101516001600160a01b03166001600160a01b031681526020019081526020016000209050600081600001549050838381518110610133576101336104b0565b602002602001015182600001819055506000801b848481518110610159576101596104b0565b6020026020010151036101775760018201805460ff1916905561020c565b600085848151811061018b5761018b6104b0565b60200260200101516001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa1580156101d0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101f491906104c6565b60018401805460ff191660ff92909216919091179055505b7fc8760fcaa0fd40811ccad1388a75f1f4b5b65c15ecd17f4ed68465c34c801bb085848151811061023f5761023f6104b0565b60200260200101518286868151811061025a5761025a6104b0565b602090810291909101810151604080516001600160a01b0390951685529184019290925282015260600160405180910390a150506001016100cd565b505050565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6001600160a01b038116811461009857600080fd5b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b038111828210171561033e5761033e610300565b604052919050565b60006001600160401b0382111561035f5761035f610300565b5060051b60200190565b600082601f83011261037a57600080fd5b8151602061038f61038a83610346565b610316565b8083825260208201915060208460051b8701019350868411156103b157600080fd5b602086015b848110156103cd57805183529183019183016103b6565b509695505050505050565b6000806000606084860312156103ed57600080fd5b83516103f8816102eb565b602085810151919450906001600160401b038082111561041757600080fd5b818701915087601f83011261042b57600080fd5b815161043961038a82610346565b81815260059190911b8301840190848101908a83111561045857600080fd5b938501935b8285101561047f578451610470816102eb565b8252938501939085019061045d565b60408a0151909750945050508083111561049857600080fd5b50506104a686828701610369565b9150509250925092565b634e487b7160e01b600052603260045260246000fd5b6000602082840312156104d857600080fd5b815160ff811681146104e957600080fd5b9392505050565b608051611b1861052e600039600081816101db015281816103d801528181610573015281816106da0152818161096e0152610a880152611b186000f3fe6080604052600436106100c75760003560e01c80638a32ada011610074578063b37b32711161004e578063b37b327114610292578063e30c3978146102a5578063f2fde38b146102d057600080fd5b80638a32ada0146101c95780638da5cb5b14610222578063ac41865a1461024d57600080fd5b80636b4eb621116100a55780636b4eb6211461017d578063715018a61461019f57806379ba5097146101b457600080fd5b806301ffc9a7146100cc578063238e0a8a14610101578063452a94b01461012f575b600080fd5b3480156100d857600080fd5b506100ec6100e736600461119e565b6102f0565b60405190151581526020015b60405180910390f35b34801561010d57600080fd5b5061012161011c366004611230565b610389565b6040519081526020016100f8565b34801561013b57600080fd5b5061016661014a366004611296565b6002602052600090815260409020805460019091015460ff1682565b6040805192835260ff9091166020830152016100f8565b34801561018957600080fd5b5061019d6101983660046113c2565b610456565b005b3480156101ab57600080fd5b5061019d61046c565b3480156101c057600080fd5b5061019d610480565b3480156101d557600080fd5b506101fd7f000000000000000000000000000000000000000000000000000000000000000081565b60405173ffffffffffffffffffffffffffffffffffffffff90911681526020016100f8565b34801561022e57600080fd5b5060005473ffffffffffffffffffffffffffffffffffffffff166101fd565b34801561025957600080fd5b5061026d610268366004611482565b6104fc565b604080518251815260208084015160030b9082015291810151908201526060016100f8565b61026d6102a03660046114b5565b61091e565b3480156102b157600080fd5b5060015473ffffffffffffffffffffffffffffffffffffffff166101fd565b3480156102dc57600080fd5b5061019d6102eb366004611296565b610be4565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f3cb4bea100000000000000000000000000000000000000000000000000000000148061038357507f01ffc9a7000000000000000000000000000000000000000000000000000000007fffffffff000000000000000000000000000000000000000000000000000000008316145b92915050565b60008061039883850185611516565b6040517fd47eed4500000000000000000000000000000000000000000000000000000000815290915073ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000169063d47eed459061040d90849060040161163c565b602060405180830381865afa15801561042a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061044e919061170a565b949350505050565b61045e610c94565b6104688282610ce7565b5050565b610474610c94565b61047e6000610f70565b565b600154339073ffffffffffffffffffffffffffffffffffffffff1681146104f0576040517f118cdaa700000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff821660048201526024015b60405180910390fd5b6104f981610f70565b50565b610523604051806060016040528060008152602001600060030b8152602001600081525090565b600061052e84610fa1565b9050600061053b84610fa1565b82516040517f96834ad300000000000000000000000000000000000000000000000000000000815260048101919091529091506000907f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff16906396834ad390602401608060405180830381865afa1580156105cf573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105f39190611735565b90506000816000015160070b1315806106285750806000015167ffffffffffffffff16816020015167ffffffffffffffff1610155b1561069857805160208201516040517f9ff8574000000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8916600482015260079290920b602483015267ffffffffffffffff1660448201526064016104e7565b81516040517f96834ad300000000000000000000000000000000000000000000000000000000815260009173ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016916396834ad3916107119160040190815260200190565b608060405180830381865afa15801561072e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107529190611735565b90506000816000015160070b1315806107875750806000015167ffffffffffffffff16816020015167ffffffffffffffff1610155b156107f757805160208201516040517f9ff8574000000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8916600482015260079290920b602483015267ffffffffffffffff1660448201526064016104e7565b6000610809826000015160070b611047565b83516108179060070b611047565b61082191906117f3565b905060006012856020015160ff16101561083d57506012610847565b50602084015160ff165b600061085383836117f3565b90506000811215610862575060005b8351855167ffffffffffffffff918216911661087f83600a61193a565b6108899190611946565b610893919061195d565b88600001818152505080876020015160ff168560400151886020015160ff1688604001516108c19190611998565b6108cb91906119da565b6108d591906119da565b6108df91906119da565b60030b60208901526060808501519086015110156109065760608501516040890152610911565b606084015160408901525b5050505050505092915050565b610945604051806060016040528060008152602001600060030b8152602001600081525090565b4761094f86610fa1565b5061095985610fa1565b50600061096884860186611516565b905060007f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663d47eed45836040518263ffffffff1660e01b81526004016109c5919061163c565b602060405180830381865afa1580156109e2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a06919061170a565b905080341015610a4b576040517fa458261b000000000000000000000000000000000000000000000000000000008152346004820152602481018290526044016104e7565b6040517fef9e5e2800000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000169063ef9e5e28908390610abf90869060040161163c565b6000604051808303818588803b158015610ad857600080fd5b505af1158015610aec573d6000803e3d6000fd5b50506040517fac41865a00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff808d1660048301528b16602482015230935063ac41865a92506044019050606060405180830381865afa158015610b64573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b889190611a1c565b935050506000610b983483611a7d565b905080471115610bda57336108fc610bb08347611a7d565b6040518115909202916000818181858888f19350505050158015610bd8573d6000803e3d6000fd5b505b5050949350505050565b610bec610c94565b6001805473ffffffffffffffffffffffffffffffffffffffff83167fffffffffffffffffffffffff00000000000000000000000000000000000000009091168117909155610c4f60005473ffffffffffffffffffffffffffffffffffffffff1690565b73ffffffffffffffffffffffffffffffffffffffff167f38d16b8cac22d99fc7c124b9cd0de2d3fa1faef420bfe791d8c362d765e2270060405160405180910390a350565b60005473ffffffffffffffffffffffffffffffffffffffff16331461047e576040517f118cdaa70000000000000000000000000000000000000000000000000000000081523360048201526024016104e7565b8051825114610d2f57815181516040517f37f0621f000000000000000000000000000000000000000000000000000000008152600481019290925260248201526044016104e7565b60005b8251811015610f6b57600060026000858481518110610d5357610d53611a90565b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000209050600081600001549050838381518110610db257610db2611a90565b602002602001015182600001819055506000801b848481518110610dd857610dd8611a90565b602002602001015103610e14576001820180547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00169055610ed4565b6000858481518110610e2857610e28611a90565b602002602001015173ffffffffffffffffffffffffffffffffffffffff1663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015610e7a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e9e9190611abf565b6001840180547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001660ff92909216919091179055505b7fc8760fcaa0fd40811ccad1388a75f1f4b5b65c15ecd17f4ed68465c34c801bb0858481518110610f0757610f07611a90565b602002602001015182868681518110610f2257610f22611a90565b6020908102919091018101516040805173ffffffffffffffffffffffffffffffffffffffff90951685529184019290925282015260600160405180910390a15050600101610d32565b505050565b600180547fffffffffffffffffffffffff00000000000000000000000000000000000000001690556104f981611129565b6040805180820182526000808252602091820181905273ffffffffffffffffffffffffffffffffffffffff84168152600282528290208251808401909352805480845260019091015460ff1691830191909152611042576040517f7bc70f0300000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff831660048201526024016104e7565b919050565b6000807a184f03e93ff9f4daa797ed6e38ed64bf6a1f0100000000000000008310611090577a184f03e93ff9f4daa797ed6e38ed64bf6a1f010000000000000000830492506040015b6d04ee2d6d415b85acef810000000083106110bc576d04ee2d6d415b85acef8100000000830492506020015b662386f26fc1000083106110da57662386f26fc10000830492506010015b6305f5e10083106110f2576305f5e100830492506008015b612710831061110657612710830492506004015b60648310611118576064830492506002015b600a83106103835760010192915050565b6000805473ffffffffffffffffffffffffffffffffffffffff8381167fffffffffffffffffffffffff0000000000000000000000000000000000000000831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6000602082840312156111b057600080fd5b81357fffffffff00000000000000000000000000000000000000000000000000000000811681146111e057600080fd5b9392505050565b60008083601f8401126111f957600080fd5b50813567ffffffffffffffff81111561121157600080fd5b60208301915083602082850101111561122957600080fd5b9250929050565b6000806020838503121561124357600080fd5b823567ffffffffffffffff81111561125a57600080fd5b611266858286016111e7565b90969095509350505050565b803573ffffffffffffffffffffffffffffffffffffffff8116811461104257600080fd5b6000602082840312156112a857600080fd5b6111e082611272565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b604051601f82017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016810167ffffffffffffffff81118282101715611327576113276112b1565b604052919050565b600067ffffffffffffffff821115611349576113496112b1565b5060051b60200190565b600082601f83011261136457600080fd5b813560206113796113748361132f565b6112e0565b8083825260208201915060208460051b87010193508684111561139b57600080fd5b602086015b848110156113b757803583529183019183016113a0565b509695505050505050565b600080604083850312156113d557600080fd5b823567ffffffffffffffff808211156113ed57600080fd5b818501915085601f83011261140157600080fd5b813560206114116113748361132f565b82815260059290921b8401810191818101908984111561143057600080fd5b948201945b838610156114555761144686611272565b82529482019490820190611435565b9650508601359250508082111561146b57600080fd5b5061147885828601611353565b9150509250929050565b6000806040838503121561149557600080fd5b61149e83611272565b91506114ac60208401611272565b90509250929050565b600080600080606085870312156114cb57600080fd5b6114d485611272565b93506114e260208601611272565b9250604085013567ffffffffffffffff8111156114fe57600080fd5b61150a878288016111e7565b95989497509550505050565b6000602080838503121561152957600080fd5b823567ffffffffffffffff8082111561154157600080fd5b8185019150601f86601f84011261155757600080fd5b82356115656113748261132f565b81815260059190911b8401850190858101908983111561158457600080fd5b8686015b8381101561162e578035868111156115a05760008081fd5b8701603f81018c136115b25760008081fd5b888101356040888211156115c8576115c86112b1565b6115f78b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08a850116016112e0565b8281528e8284860101111561160c5760008081fd5b828285018d83013760009281018c019290925250845250918701918701611588565b509998505050505050505050565b6000602080830181845280855180835260408601915060408160051b87010192508387016000805b838110156116fc577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc089870301855282518051808852835b818110156116b7578281018a01518982018b0152890161169c565b508781018901849052601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016909601870195509386019391860191600101611664565b509398975050505050505050565b60006020828403121561171c57600080fd5b5051919050565b8051600381900b811461104257600080fd5b60006080828403121561174757600080fd5b6040516080810167ffffffffffffffff828210818311171561176b5761176b6112b1565b81604052845191508160070b821461178257600080fd5b908252602084015190808216821461179957600080fd5b5060208201526117ab60408401611723565b6040820152606083015160608201528091505092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b8181036000831280158383131683831282161715611813576118136117c4565b5092915050565b600181815b8085111561187357817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff04821115611859576118596117c4565b8085161561186657918102915b93841c939080029061181f565b509250929050565b60008261188a57506001610383565b8161189757506000610383565b81600181146118ad57600281146118b7576118d3565b6001915050610383565b60ff8411156118c8576118c86117c4565b50506001821b610383565b5060208310610133831016604e8410600b84101617156118f6575081810a610383565b611900838361181a565b807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff04821115611932576119326117c4565b029392505050565b60006111e0838361187b565b8082028115828204841417610383576103836117c4565b600082611993577f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b500490565b600381810b9083900b01637fffffff81137fffffffffffffffffffffffffffffffffffffffffffffffffffffffff8000000082121715610383576103836117c4565b600382810b9082900b037fffffffffffffffffffffffffffffffffffffffffffffffffffffffff800000008112637fffffff82131715610383576103836117c4565b600060608284031215611a2e57600080fd5b6040516060810181811067ffffffffffffffff82111715611a5157611a516112b1565b60405282518152611a6460208401611723565b6020820152604083015160408201528091505092915050565b81810381811115610383576103836117c4565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b600060208284031215611ad157600080fd5b815160ff811681146111e057600080fdfea264697066735822122028a86cbf55d1d146444152f359efd65dbf36b496b3194d13263e6d39206de68864736f6c634300081900330000000000000000000000004305fb66699c3b2702d4d05cf36551390a4c69c60000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

Deployed Bytecode

0x6080604052600436106100c75760003560e01c80638a32ada011610074578063b37b32711161004e578063b37b327114610292578063e30c3978146102a5578063f2fde38b146102d057600080fd5b80638a32ada0146101c95780638da5cb5b14610222578063ac41865a1461024d57600080fd5b80636b4eb621116100a55780636b4eb6211461017d578063715018a61461019f57806379ba5097146101b457600080fd5b806301ffc9a7146100cc578063238e0a8a14610101578063452a94b01461012f575b600080fd5b3480156100d857600080fd5b506100ec6100e736600461119e565b6102f0565b60405190151581526020015b60405180910390f35b34801561010d57600080fd5b5061012161011c366004611230565b610389565b6040519081526020016100f8565b34801561013b57600080fd5b5061016661014a366004611296565b6002602052600090815260409020805460019091015460ff1682565b6040805192835260ff9091166020830152016100f8565b34801561018957600080fd5b5061019d6101983660046113c2565b610456565b005b3480156101ab57600080fd5b5061019d61046c565b3480156101c057600080fd5b5061019d610480565b3480156101d557600080fd5b506101fd7f0000000000000000000000004305fb66699c3b2702d4d05cf36551390a4c69c681565b60405173ffffffffffffffffffffffffffffffffffffffff90911681526020016100f8565b34801561022e57600080fd5b5060005473ffffffffffffffffffffffffffffffffffffffff166101fd565b34801561025957600080fd5b5061026d610268366004611482565b6104fc565b604080518251815260208084015160030b9082015291810151908201526060016100f8565b61026d6102a03660046114b5565b61091e565b3480156102b157600080fd5b5060015473ffffffffffffffffffffffffffffffffffffffff166101fd565b3480156102dc57600080fd5b5061019d6102eb366004611296565b610be4565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f3cb4bea100000000000000000000000000000000000000000000000000000000148061038357507f01ffc9a7000000000000000000000000000000000000000000000000000000007fffffffff000000000000000000000000000000000000000000000000000000008316145b92915050565b60008061039883850185611516565b6040517fd47eed4500000000000000000000000000000000000000000000000000000000815290915073ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000004305fb66699c3b2702d4d05cf36551390a4c69c6169063d47eed459061040d90849060040161163c565b602060405180830381865afa15801561042a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061044e919061170a565b949350505050565b61045e610c94565b6104688282610ce7565b5050565b610474610c94565b61047e6000610f70565b565b600154339073ffffffffffffffffffffffffffffffffffffffff1681146104f0576040517f118cdaa700000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff821660048201526024015b60405180910390fd5b6104f981610f70565b50565b610523604051806060016040528060008152602001600060030b8152602001600081525090565b600061052e84610fa1565b9050600061053b84610fa1565b82516040517f96834ad300000000000000000000000000000000000000000000000000000000815260048101919091529091506000907f0000000000000000000000004305fb66699c3b2702d4d05cf36551390a4c69c673ffffffffffffffffffffffffffffffffffffffff16906396834ad390602401608060405180830381865afa1580156105cf573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105f39190611735565b90506000816000015160070b1315806106285750806000015167ffffffffffffffff16816020015167ffffffffffffffff1610155b1561069857805160208201516040517f9ff8574000000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8916600482015260079290920b602483015267ffffffffffffffff1660448201526064016104e7565b81516040517f96834ad300000000000000000000000000000000000000000000000000000000815260009173ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000004305fb66699c3b2702d4d05cf36551390a4c69c616916396834ad3916107119160040190815260200190565b608060405180830381865afa15801561072e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107529190611735565b90506000816000015160070b1315806107875750806000015167ffffffffffffffff16816020015167ffffffffffffffff1610155b156107f757805160208201516040517f9ff8574000000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8916600482015260079290920b602483015267ffffffffffffffff1660448201526064016104e7565b6000610809826000015160070b611047565b83516108179060070b611047565b61082191906117f3565b905060006012856020015160ff16101561083d57506012610847565b50602084015160ff165b600061085383836117f3565b90506000811215610862575060005b8351855167ffffffffffffffff918216911661087f83600a61193a565b6108899190611946565b610893919061195d565b88600001818152505080876020015160ff168560400151886020015160ff1688604001516108c19190611998565b6108cb91906119da565b6108d591906119da565b6108df91906119da565b60030b60208901526060808501519086015110156109065760608501516040890152610911565b606084015160408901525b5050505050505092915050565b610945604051806060016040528060008152602001600060030b8152602001600081525090565b4761094f86610fa1565b5061095985610fa1565b50600061096884860186611516565b905060007f0000000000000000000000004305fb66699c3b2702d4d05cf36551390a4c69c673ffffffffffffffffffffffffffffffffffffffff1663d47eed45836040518263ffffffff1660e01b81526004016109c5919061163c565b602060405180830381865afa1580156109e2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a06919061170a565b905080341015610a4b576040517fa458261b000000000000000000000000000000000000000000000000000000008152346004820152602481018290526044016104e7565b6040517fef9e5e2800000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000004305fb66699c3b2702d4d05cf36551390a4c69c6169063ef9e5e28908390610abf90869060040161163c565b6000604051808303818588803b158015610ad857600080fd5b505af1158015610aec573d6000803e3d6000fd5b50506040517fac41865a00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff808d1660048301528b16602482015230935063ac41865a92506044019050606060405180830381865afa158015610b64573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b889190611a1c565b935050506000610b983483611a7d565b905080471115610bda57336108fc610bb08347611a7d565b6040518115909202916000818181858888f19350505050158015610bd8573d6000803e3d6000fd5b505b5050949350505050565b610bec610c94565b6001805473ffffffffffffffffffffffffffffffffffffffff83167fffffffffffffffffffffffff00000000000000000000000000000000000000009091168117909155610c4f60005473ffffffffffffffffffffffffffffffffffffffff1690565b73ffffffffffffffffffffffffffffffffffffffff167f38d16b8cac22d99fc7c124b9cd0de2d3fa1faef420bfe791d8c362d765e2270060405160405180910390a350565b60005473ffffffffffffffffffffffffffffffffffffffff16331461047e576040517f118cdaa70000000000000000000000000000000000000000000000000000000081523360048201526024016104e7565b8051825114610d2f57815181516040517f37f0621f000000000000000000000000000000000000000000000000000000008152600481019290925260248201526044016104e7565b60005b8251811015610f6b57600060026000858481518110610d5357610d53611a90565b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000209050600081600001549050838381518110610db257610db2611a90565b602002602001015182600001819055506000801b848481518110610dd857610dd8611a90565b602002602001015103610e14576001820180547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00169055610ed4565b6000858481518110610e2857610e28611a90565b602002602001015173ffffffffffffffffffffffffffffffffffffffff1663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015610e7a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e9e9190611abf565b6001840180547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001660ff92909216919091179055505b7fc8760fcaa0fd40811ccad1388a75f1f4b5b65c15ecd17f4ed68465c34c801bb0858481518110610f0757610f07611a90565b602002602001015182868681518110610f2257610f22611a90565b6020908102919091018101516040805173ffffffffffffffffffffffffffffffffffffffff90951685529184019290925282015260600160405180910390a15050600101610d32565b505050565b600180547fffffffffffffffffffffffff00000000000000000000000000000000000000001690556104f981611129565b6040805180820182526000808252602091820181905273ffffffffffffffffffffffffffffffffffffffff84168152600282528290208251808401909352805480845260019091015460ff1691830191909152611042576040517f7bc70f0300000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff831660048201526024016104e7565b919050565b6000807a184f03e93ff9f4daa797ed6e38ed64bf6a1f0100000000000000008310611090577a184f03e93ff9f4daa797ed6e38ed64bf6a1f010000000000000000830492506040015b6d04ee2d6d415b85acef810000000083106110bc576d04ee2d6d415b85acef8100000000830492506020015b662386f26fc1000083106110da57662386f26fc10000830492506010015b6305f5e10083106110f2576305f5e100830492506008015b612710831061110657612710830492506004015b60648310611118576064830492506002015b600a83106103835760010192915050565b6000805473ffffffffffffffffffffffffffffffffffffffff8381167fffffffffffffffffffffffff0000000000000000000000000000000000000000831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6000602082840312156111b057600080fd5b81357fffffffff00000000000000000000000000000000000000000000000000000000811681146111e057600080fd5b9392505050565b60008083601f8401126111f957600080fd5b50813567ffffffffffffffff81111561121157600080fd5b60208301915083602082850101111561122957600080fd5b9250929050565b6000806020838503121561124357600080fd5b823567ffffffffffffffff81111561125a57600080fd5b611266858286016111e7565b90969095509350505050565b803573ffffffffffffffffffffffffffffffffffffffff8116811461104257600080fd5b6000602082840312156112a857600080fd5b6111e082611272565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b604051601f82017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016810167ffffffffffffffff81118282101715611327576113276112b1565b604052919050565b600067ffffffffffffffff821115611349576113496112b1565b5060051b60200190565b600082601f83011261136457600080fd5b813560206113796113748361132f565b6112e0565b8083825260208201915060208460051b87010193508684111561139b57600080fd5b602086015b848110156113b757803583529183019183016113a0565b509695505050505050565b600080604083850312156113d557600080fd5b823567ffffffffffffffff808211156113ed57600080fd5b818501915085601f83011261140157600080fd5b813560206114116113748361132f565b82815260059290921b8401810191818101908984111561143057600080fd5b948201945b838610156114555761144686611272565b82529482019490820190611435565b9650508601359250508082111561146b57600080fd5b5061147885828601611353565b9150509250929050565b6000806040838503121561149557600080fd5b61149e83611272565b91506114ac60208401611272565b90509250929050565b600080600080606085870312156114cb57600080fd5b6114d485611272565b93506114e260208601611272565b9250604085013567ffffffffffffffff8111156114fe57600080fd5b61150a878288016111e7565b95989497509550505050565b6000602080838503121561152957600080fd5b823567ffffffffffffffff8082111561154157600080fd5b8185019150601f86601f84011261155757600080fd5b82356115656113748261132f565b81815260059190911b8401850190858101908983111561158457600080fd5b8686015b8381101561162e578035868111156115a05760008081fd5b8701603f81018c136115b25760008081fd5b888101356040888211156115c8576115c86112b1565b6115f78b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08a850116016112e0565b8281528e8284860101111561160c5760008081fd5b828285018d83013760009281018c019290925250845250918701918701611588565b509998505050505050505050565b6000602080830181845280855180835260408601915060408160051b87010192508387016000805b838110156116fc577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc089870301855282518051808852835b818110156116b7578281018a01518982018b0152890161169c565b508781018901849052601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016909601870195509386019391860191600101611664565b509398975050505050505050565b60006020828403121561171c57600080fd5b5051919050565b8051600381900b811461104257600080fd5b60006080828403121561174757600080fd5b6040516080810167ffffffffffffffff828210818311171561176b5761176b6112b1565b81604052845191508160070b821461178257600080fd5b908252602084015190808216821461179957600080fd5b5060208201526117ab60408401611723565b6040820152606083015160608201528091505092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b8181036000831280158383131683831282161715611813576118136117c4565b5092915050565b600181815b8085111561187357817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff04821115611859576118596117c4565b8085161561186657918102915b93841c939080029061181f565b509250929050565b60008261188a57506001610383565b8161189757506000610383565b81600181146118ad57600281146118b7576118d3565b6001915050610383565b60ff8411156118c8576118c86117c4565b50506001821b610383565b5060208310610133831016604e8410600b84101617156118f6575081810a610383565b611900838361181a565b807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff04821115611932576119326117c4565b029392505050565b60006111e0838361187b565b8082028115828204841417610383576103836117c4565b600082611993577f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b500490565b600381810b9083900b01637fffffff81137fffffffffffffffffffffffffffffffffffffffffffffffffffffffff8000000082121715610383576103836117c4565b600382810b9082900b037fffffffffffffffffffffffffffffffffffffffffffffffffffffffff800000008112637fffffff82131715610383576103836117c4565b600060608284031215611a2e57600080fd5b6040516060810181811067ffffffffffffffff82111715611a5157611a516112b1565b60405282518152611a6460208401611723565b6020820152604083015160408201528091505092915050565b81810381811115610383576103836117c4565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b600060208284031215611ad157600080fd5b815160ff811681146111e057600080fdfea264697066735822122028a86cbf55d1d146444152f359efd65dbf36b496b3194d13263e6d39206de68864736f6c63430008190033

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

0000000000000000000000004305fb66699c3b2702d4d05cf36551390a4c69c60000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

-----Decoded View---------------
Arg [0] : _pythContractAddress (address): 0x4305FB66699C3B2702D4d05CF36551390A4c69C6

-----Encoded View---------------
5 Constructor Arguments found :
Arg [0] : 0000000000000000000000004305fb66699c3b2702d4d05cf36551390a4c69c6
Arg [1] : 0000000000000000000000000000000000000000000000000000000000000060
Arg [2] : 0000000000000000000000000000000000000000000000000000000000000080
Arg [3] : 0000000000000000000000000000000000000000000000000000000000000000
Arg [4] : 0000000000000000000000000000000000000000000000000000000000000000


Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

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

Validator Index Block Amount
View All Withdrawals

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

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