Polygon Sponsored slots available. Book your slot here!
Overview
POL Balance
0 POL
POL Value
$0.00More Info
Private Name Tags
ContractCreator
Loading...
Loading
Similar Match Source Code This contract matches the deployed Bytecode of the Source Code for Contract 0x7fAAdf5b...FF4716585 The constructor portion of the code might be different and could alter the actual behaviour of the contract
Contract Name:
TLSPolygonPriceOracle
Compiler Version
v0.8.23+commit.f704f362
Optimization Enabled:
Yes with 200 runs
Other Settings:
paris EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.23; import {IAggregator} from "src/price-oracles/interfaces/IAggregator.sol"; import {BaseChainlinkPriceOracle} from "src/price-oracles/chainlink/BaseChainlinkPriceOracle.sol"; contract TLSPolygonPriceOracle is BaseChainlinkPriceOracle { function _getSource(address currency) internal pure override returns (uint8 decimals, IAggregator.Aggregator[] memory aggregators) { if (currency == 0xfa68FB4628DFF1028CFEc22b4162FCcd0d45efb6) { // MATICX // https://polygonscan.com/address/0xfa68fb4628dff1028cfec22b4162fccd0d45efb6 decimals = 18; aggregators = new IAggregator.Aggregator[](1); // Deviation 0.5% | Heartbeat 3600s | Decimals 8 // https://polygonscan.com/address/0x5d37E4b374E6907de8Fc7fb33EE3b0af403C7403 aggregators[0] = IAggregator.Aggregator(1 hours, 0x5d37E4b374E6907de8Fc7fb33EE3b0af403C7403, 8); } else if (currency == 0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174) { // USDC (Stargate) // https://polygonscan.com/address/0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174 decimals = 6; aggregators = new IAggregator.Aggregator[](1); // Deviation 0% | Heartbeat 1200s | Decimals 8 // https://polygonscan.com/address/0xfE4A8cc5b5B2366C1B58Bea3858e81843581b2F7 aggregators[0] = IAggregator.Aggregator(20 minutes, 0xfE4A8cc5b5B2366C1B58Bea3858e81843581b2F7, 8); } } }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.23; interface IAggregator { struct Aggregator { uint256 staleAfter; address addr; uint8 decimals; } }
// SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.23; import {IPriceOracle} from "src/price-oracles/interfaces/IPriceOracle.sol"; import {IAggregator} from "src/price-oracles/interfaces/IAggregator.sol"; import {Currency} from "src/libraries/CurrencyLib.sol"; import {ChainlinkLib} from "src/price-oracles/libraries/ChainlinkLib.sol"; abstract contract BaseChainlinkPriceOracle is IPriceOracle { error UnsupportedCurrency(Currency); function prices(Currency currency0, Currency currency1, bytes calldata) external view override returns (uint256 currency0Price, uint256 currency1Price) { return (_getPrice(currency0), _getPrice(currency1)); } function _getPrice(Currency currency) internal view returns (uint256) { (uint8 decimals, IAggregator.Aggregator[] memory aggregators) = _getSource(Currency.unwrap(currency)); if (aggregators.length == 0) revert UnsupportedCurrency(currency); return ChainlinkLib.price(decimals, aggregators); } function _getSource(address currency) internal pure virtual returns (uint8 decimals, IAggregator.Aggregator[] memory aggregators); }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.23; import {Currency} from "../../libraries/CurrencyLib.sol"; /// @title PriceOracle interface /// @notice Returns prices of Index's constituents interface IPriceOracle { function prices(Currency currency0, Currency currency1, bytes calldata) external view returns (uint256, uint256); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.23; import {FixedPointMathLib} from "solmate/utils/FixedPointMathLib.sol"; import {IERC20, SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import {SafeCastLib} from "solmate/utils/SafeCastLib.sol"; import {a160u96} from "../utils/a160u96.sol"; type Currency is address; using {eq as ==, neq as !=} for Currency global; function eq(Currency currency, Currency other) pure returns (bool) { return Currency.unwrap(currency) == Currency.unwrap(other); } function neq(Currency currency, Currency other) pure returns (bool) { return !eq(currency, other); } /// @title CurrencyLibrary /// @dev This library allows for transferring and holding native tokens and ERC20 tokens /// @author Modified from Uniswap (https://github.com/Uniswap/v4-core/blob/main/src/types/Currency.sol) library CurrencyLib { using SafeERC20 for IERC20; using FixedPointMathLib for uint256; using CurrencyLib for Currency; /// @dev Currency wrapper for native currency Currency public constant NATIVE = Currency.wrap(address(0)); /// @notice Thrown when a native transfer fails error NativeTransferFailed(); /// @notice Thrown when an ERC20 transfer fails error ERC20TransferFailed(); /// @notice Thrown when deposit amount exceeds current balance error AmountExceedsBalance(); /// @notice Transfers currency /// @param currency Currency to transfer /// @param to Address of recipient /// @param amount Currency amount ot transfer function transfer(Currency currency, address to, uint256 amount) internal { if (amount == 0) return; // implementation from // https://github.com/transmissions11/solmate/blob/e8f96f25d48fe702117ce76c79228ca4f20206cb/src/utils/SafeTransferLib.sol bool success; if (currency.isNative()) { assembly { // Transfer the ETH and store if it succeeded or not. success := call(gas(), to, amount, 0, 0, 0, 0) } if (!success) revert NativeTransferFailed(); } else { assembly { // We'll write our calldata to this slot below, but restore it later. let freeMemoryPointer := mload(0x40) // Write the abi-encoded calldata into memory, beginning with the function selector. mstore(freeMemoryPointer, 0xa9059cbb00000000000000000000000000000000000000000000000000000000) mstore(add(freeMemoryPointer, 4), and(to, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "to" argument. mstore(add(freeMemoryPointer, 36), amount) // Append the "amount" argument. Masking not required as it's a full 32 byte type. success := and( // Set success to whether the call reverted, if not we check it either // returned exactly 1 (can't just be non-zero data), or had no return data. or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())), // We use 68 because that's the total length of our calldata (4 + 32 * 2) // Counterintuitively, this call() must be positioned after the or() in the // surrounding and() because and() evaluates its arguments from right to left. call(gas(), currency, 0, freeMemoryPointer, 68, 0, 32) ) } if (!success) revert ERC20TransferFailed(); } } /// @notice Approves currency /// @param currency Currency to approve /// @param spender Address of spender /// @param amount Currency amount to approve function approve(Currency currency, address spender, uint256 amount) internal { if (isNative(currency)) return; IERC20(Currency.unwrap(currency)).forceApprove(spender, amount); } /// @notice Deposits a specified amount of a given currency into the contract /// @dev Handles both native and ERC20 token deposits /// @param currency The currency to deposit /// @param amount The amount of currency to deposit /// @return deposited The actual amount deposited function selfDeposit(Currency currency, uint96 amount) internal returns (uint96 deposited) { if (currency.isNative()) { if (msg.value < amount) revert AmountExceedsBalance(); deposited = amount; } else { IERC20 token = IERC20(Currency.unwrap(currency)); uint256 _balance = token.balanceOf(address(this)); token.safeTransferFrom(msg.sender, address(this), amount); // safe cast, transferred amount is <= 2^96-1 deposited = SafeCastLib.safeCastTo96(token.balanceOf(address(this)) - _balance); } } /// @notice Withdraws a specified amount of a given currency to a specified address /// @param currency The currency and amount to withdraw (a160u96 format) /// @param kAmount The K amount to withdraw (in kind of currency) /// @param to The address to which the currency will be withdrawn /// @return amount The actual amount withdrawn function withdraw(a160u96 currency, uint256 kAmount, address to) internal returns (uint96 amount) { amount = uint96(kAmount.mulWadDown(currency.value())); if (to != address(this)) { currency.currency().transfer(to, amount); } } /// @notice Returns the balance of a given currency for a specific account /// @param currency The currency to check /// @param account The address of the account /// @return The balance of the specified currency for the given account function balanceOf(Currency currency, address account) internal view returns (uint256) { return currency.isNative() ? account.balance : IERC20(Currency.unwrap(currency)).balanceOf(account); } /// @notice Returns the balance of a given currency for this contract /// @param currency The currency to check /// @return The balance of the specified currency for this contract function balanceOfSelf(Currency currency) internal view returns (uint256) { return currency.isNative() ? address(this).balance : IERC20(Currency.unwrap(currency)).balanceOf(address(this)); } /// @notice Checks if the specified currency is the native currency /// @param currency The currency to check /// @return `true` if the specified currency is the native currency, `false` otherwise function isNative(Currency currency) internal pure returns (bool) { return currency == NATIVE; } }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.23; import {AggregatorV3Interface} from "chainlink/src/v0.8/interfaces/AggregatorV3Interface.sol"; import {FixedPointMathLib} from "solmate/utils/FixedPointMathLib.sol"; import {PriceLib} from "./PriceLib.sol"; import {IAggregator} from "../interfaces/IAggregator.sol"; library ChainlinkLib { using FixedPointMathLib for uint256; error RoundMismatch(); error StalePrice(); function price(uint8 decimals, IAggregator.Aggregator[] memory aggregators) internal view returns (uint256 price_) { IAggregator.Aggregator memory aggregator = aggregators[0]; price_ = PriceLib.Q128.mulDivDown( 10 ** (aggregator.decimals + decimals), _getChainlinkPrice(aggregator.addr, aggregator.staleAfter) * PriceLib.DECIMALS_MULTIPLIER ); uint256 aggregatorCount = aggregators.length; for (uint256 i = 1; i < aggregatorCount; ++i) { aggregator = aggregators[i]; price_ = price_.mulDivDown(10 ** aggregator.decimals, _getChainlinkPrice(aggregator.addr, aggregator.staleAfter)); } } function _getChainlinkPrice(address aggregator, uint256 staleAfter) private view returns (uint256) { (, int256 price_,, uint256 updatedAt,) = AggregatorV3Interface(aggregator).latestRoundData(); if (updatedAt == 0 || price_ < 1) revert RoundMismatch(); if (block.timestamp - updatedAt > staleAfter) revert StalePrice(); return uint256(price_); } }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity >=0.8.0; /// @notice Arithmetic library with operations for fixed-point numbers. /// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/FixedPointMathLib.sol) /// @author Inspired by USM (https://github.com/usmfum/USM/blob/master/contracts/WadMath.sol) library FixedPointMathLib { /*////////////////////////////////////////////////////////////// SIMPLIFIED FIXED POINT OPERATIONS //////////////////////////////////////////////////////////////*/ uint256 internal constant MAX_UINT256 = 2**256 - 1; uint256 internal constant WAD = 1e18; // The scalar of ETH and most ERC20s. function mulWadDown(uint256 x, uint256 y) internal pure returns (uint256) { return mulDivDown(x, y, WAD); // Equivalent to (x * y) / WAD rounded down. } function mulWadUp(uint256 x, uint256 y) internal pure returns (uint256) { return mulDivUp(x, y, WAD); // Equivalent to (x * y) / WAD rounded up. } function divWadDown(uint256 x, uint256 y) internal pure returns (uint256) { return mulDivDown(x, WAD, y); // Equivalent to (x * WAD) / y rounded down. } function divWadUp(uint256 x, uint256 y) internal pure returns (uint256) { return mulDivUp(x, WAD, y); // Equivalent to (x * WAD) / y rounded up. } /*////////////////////////////////////////////////////////////// LOW LEVEL FIXED POINT OPERATIONS //////////////////////////////////////////////////////////////*/ function mulDivDown( uint256 x, uint256 y, uint256 denominator ) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { // Equivalent to require(denominator != 0 && (y == 0 || x <= type(uint256).max / y)) if iszero(mul(denominator, iszero(mul(y, gt(x, div(MAX_UINT256, y)))))) { revert(0, 0) } // Divide x * y by the denominator. z := div(mul(x, y), denominator) } } function mulDivUp( uint256 x, uint256 y, uint256 denominator ) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { // Equivalent to require(denominator != 0 && (y == 0 || x <= type(uint256).max / y)) if iszero(mul(denominator, iszero(mul(y, gt(x, div(MAX_UINT256, y)))))) { revert(0, 0) } // If x * y modulo the denominator is strictly greater than 0, // 1 is added to round up the division of x * y by the denominator. z := add(gt(mod(mul(x, y), denominator), 0), div(mul(x, y), denominator)) } } function rpow( uint256 x, uint256 n, uint256 scalar ) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { switch x case 0 { switch n case 0 { // 0 ** 0 = 1 z := scalar } default { // 0 ** n = 0 z := 0 } } default { switch mod(n, 2) case 0 { // If n is even, store scalar in z for now. z := scalar } default { // If n is odd, store x in z for now. z := x } // Shifting right by 1 is like dividing by 2. let half := shr(1, scalar) for { // Shift n right by 1 before looping to halve it. n := shr(1, n) } n { // Shift n right by 1 each iteration to halve it. n := shr(1, n) } { // Revert immediately if x ** 2 would overflow. // Equivalent to iszero(eq(div(xx, x), x)) here. if shr(128, x) { revert(0, 0) } // Store x squared. let xx := mul(x, x) // Round to the nearest number. let xxRound := add(xx, half) // Revert if xx + half overflowed. if lt(xxRound, xx) { revert(0, 0) } // Set x to scaled xxRound. x := div(xxRound, scalar) // If n is even: if mod(n, 2) { // Compute z * x. let zx := mul(z, x) // If z * x overflowed: if iszero(eq(div(zx, x), z)) { // Revert if x is non-zero. if iszero(iszero(x)) { revert(0, 0) } } // Round to the nearest number. let zxRound := add(zx, half) // Revert if zx + half overflowed. if lt(zxRound, zx) { revert(0, 0) } // Return properly scaled zxRound. z := div(zxRound, scalar) } } } } } /*////////////////////////////////////////////////////////////// GENERAL NUMBER UTILITIES //////////////////////////////////////////////////////////////*/ function sqrt(uint256 x) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { let y := x // We start y at x, which will help us make our initial estimate. z := 181 // The "correct" value is 1, but this saves a multiplication later. // This segment is to get a reasonable initial estimate for the Babylonian method. With a bad // start, the correct # of bits increases ~linearly each iteration instead of ~quadratically. // We check y >= 2^(k + 8) but shift right by k bits // each branch to ensure that if x >= 256, then y >= 256. if iszero(lt(y, 0x10000000000000000000000000000000000)) { y := shr(128, y) z := shl(64, z) } if iszero(lt(y, 0x1000000000000000000)) { y := shr(64, y) z := shl(32, z) } if iszero(lt(y, 0x10000000000)) { y := shr(32, y) z := shl(16, z) } if iszero(lt(y, 0x1000000)) { y := shr(16, y) z := shl(8, z) } // Goal was to get z*z*y within a small factor of x. More iterations could // get y in a tighter range. Currently, we will have y in [256, 256*2^16). // We ensured y >= 256 so that the relative difference between y and y+1 is small. // That's not possible if x < 256 but we can just verify those cases exhaustively. // Now, z*z*y <= x < z*z*(y+1), and y <= 2^(16+8), and either y >= 256, or x < 256. // Correctness can be checked exhaustively for x < 256, so we assume y >= 256. // Then z*sqrt(y) is within sqrt(257)/sqrt(256) of sqrt(x), or about 20bps. // For s in the range [1/256, 256], the estimate f(s) = (181/1024) * (s+1) is in the range // (1/2.84 * sqrt(s), 2.84 * sqrt(s)), with largest error when s = 1 and when s = 256 or 1/256. // Since y is in [256, 256*2^16), let a = y/65536, so that a is in [1/256, 256). Then we can estimate // sqrt(y) using sqrt(65536) * 181/1024 * (a + 1) = 181/4 * (y + 65536)/65536 = 181 * (y + 65536)/2^18. // There is no overflow risk here since y < 2^136 after the first branch above. z := shr(18, mul(z, add(y, 65536))) // A mul() is saved from starting z at 181. // Given the worst case multiplicative error of 2.84 above, 7 iterations should be enough. z := shr(1, add(z, div(x, z))) z := shr(1, add(z, div(x, z))) z := shr(1, add(z, div(x, z))) z := shr(1, add(z, div(x, z))) z := shr(1, add(z, div(x, z))) z := shr(1, add(z, div(x, z))) z := shr(1, add(z, div(x, z))) // If x+1 is a perfect square, the Babylonian method cycles between // floor(sqrt(x)) and ceil(sqrt(x)). This statement ensures we return floor. // See: https://en.wikipedia.org/wiki/Integer_square_root#Using_only_integer_division // Since the ceil is rare, we save gas on the assignment and repeat division in the rare case. // If you don't care whether the floor or ceil square root is returned, you can remove this statement. z := sub(z, lt(div(x, z), z)) } } function unsafeMod(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { // Mod x by y. Note this will return // 0 instead of reverting if y is zero. z := mod(x, y) } } function unsafeDiv(uint256 x, uint256 y) internal pure returns (uint256 r) { /// @solidity memory-safe-assembly assembly { // Divide x by y. Note this will return // 0 instead of reverting if y is zero. r := div(x, y) } } function unsafeDivUp(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { // Add 1 to x * y if x % y > 0. Note this will // return 0 instead of reverting if y is zero. z := add(gt(mod(x, y), 0), div(x, y)) } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.3) (token/ERC20/utils/SafeERC20.sol) pragma solidity ^0.8.0; import "../IERC20.sol"; import "../extensions/IERC20Permit.sol"; import "../../../utils/Address.sol"; /** * @title SafeERC20 * @dev Wrappers around ERC20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20 { using Address for address; /** * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value, * non-reverting calls are assumed to be successful. */ function safeTransfer(IERC20 token, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } /** * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful. */ function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } /** * @dev Deprecated. This function has issues similar to the ones found in * {IERC20-approve}, and its usage is discouraged. * * Whenever possible, use {safeIncreaseAllowance} and * {safeDecreaseAllowance} instead. */ function safeApprove(IERC20 token, address spender, uint256 value) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' require( (value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } /** * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value, * non-reverting calls are assumed to be successful. */ function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 oldAllowance = token.allowance(address(this), spender); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value)); } /** * @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value, * non-reverting calls are assumed to be successful. */ function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal { unchecked { uint256 oldAllowance = token.allowance(address(this), spender); require(oldAllowance >= value, "SafeERC20: decreased allowance below zero"); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value)); } } /** * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value, * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval * to be set to zero before setting it to a non-zero value, such as USDT. */ function forceApprove(IERC20 token, address spender, uint256 value) internal { bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value); if (!_callOptionalReturnBool(token, approvalCall)) { _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0)); _callOptionalReturn(token, approvalCall); } } /** * @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`. * Revert on invalid signature. */ function safePermit( IERC20Permit token, address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) internal { uint256 nonceBefore = token.nonces(owner); token.permit(owner, spender, value, deadline, v, r, s); uint256 nonceAfter = token.nonces(owner); require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed"); } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */ function _callOptionalReturn(IERC20 token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that // the target address contains contract code and also asserts for success in the low-level call. bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed"); require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). * * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead. */ function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false // and not revert is the subcall reverts. (bool success, bytes memory returndata) = address(token).call(data); return success && (returndata.length == 0 || abi.decode(returndata, (bool))) && Address.isContract(address(token)); } }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity >=0.8.0; /// @notice Safe unsigned integer casting library that reverts on overflow. /// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/SafeCastLib.sol) /// @author Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/math/SafeCast.sol) library SafeCastLib { function safeCastTo248(uint256 x) internal pure returns (uint248 y) { require(x < 1 << 248); y = uint248(x); } function safeCastTo240(uint256 x) internal pure returns (uint240 y) { require(x < 1 << 240); y = uint240(x); } function safeCastTo232(uint256 x) internal pure returns (uint232 y) { require(x < 1 << 232); y = uint232(x); } function safeCastTo224(uint256 x) internal pure returns (uint224 y) { require(x < 1 << 224); y = uint224(x); } function safeCastTo216(uint256 x) internal pure returns (uint216 y) { require(x < 1 << 216); y = uint216(x); } function safeCastTo208(uint256 x) internal pure returns (uint208 y) { require(x < 1 << 208); y = uint208(x); } function safeCastTo200(uint256 x) internal pure returns (uint200 y) { require(x < 1 << 200); y = uint200(x); } function safeCastTo192(uint256 x) internal pure returns (uint192 y) { require(x < 1 << 192); y = uint192(x); } function safeCastTo184(uint256 x) internal pure returns (uint184 y) { require(x < 1 << 184); y = uint184(x); } function safeCastTo176(uint256 x) internal pure returns (uint176 y) { require(x < 1 << 176); y = uint176(x); } function safeCastTo168(uint256 x) internal pure returns (uint168 y) { require(x < 1 << 168); y = uint168(x); } function safeCastTo160(uint256 x) internal pure returns (uint160 y) { require(x < 1 << 160); y = uint160(x); } function safeCastTo152(uint256 x) internal pure returns (uint152 y) { require(x < 1 << 152); y = uint152(x); } function safeCastTo144(uint256 x) internal pure returns (uint144 y) { require(x < 1 << 144); y = uint144(x); } function safeCastTo136(uint256 x) internal pure returns (uint136 y) { require(x < 1 << 136); y = uint136(x); } function safeCastTo128(uint256 x) internal pure returns (uint128 y) { require(x < 1 << 128); y = uint128(x); } function safeCastTo120(uint256 x) internal pure returns (uint120 y) { require(x < 1 << 120); y = uint120(x); } function safeCastTo112(uint256 x) internal pure returns (uint112 y) { require(x < 1 << 112); y = uint112(x); } function safeCastTo104(uint256 x) internal pure returns (uint104 y) { require(x < 1 << 104); y = uint104(x); } function safeCastTo96(uint256 x) internal pure returns (uint96 y) { require(x < 1 << 96); y = uint96(x); } function safeCastTo88(uint256 x) internal pure returns (uint88 y) { require(x < 1 << 88); y = uint88(x); } function safeCastTo80(uint256 x) internal pure returns (uint80 y) { require(x < 1 << 80); y = uint80(x); } function safeCastTo72(uint256 x) internal pure returns (uint72 y) { require(x < 1 << 72); y = uint72(x); } function safeCastTo64(uint256 x) internal pure returns (uint64 y) { require(x < 1 << 64); y = uint64(x); } function safeCastTo56(uint256 x) internal pure returns (uint56 y) { require(x < 1 << 56); y = uint56(x); } function safeCastTo48(uint256 x) internal pure returns (uint48 y) { require(x < 1 << 48); y = uint48(x); } function safeCastTo40(uint256 x) internal pure returns (uint40 y) { require(x < 1 << 40); y = uint40(x); } function safeCastTo32(uint256 x) internal pure returns (uint32 y) { require(x < 1 << 32); y = uint32(x); } function safeCastTo24(uint256 x) internal pure returns (uint24 y) { require(x < 1 << 24); y = uint24(x); } function safeCastTo16(uint256 x) internal pure returns (uint16 y) { require(x < 1 << 16); y = uint16(x); } function safeCastTo8(uint256 x) internal pure returns (uint8 y) { require(x < 1 << 8); y = uint8(x); } }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.23; import {Currency} from "../libraries/CurrencyLib.sol"; type a160u96 is uint256; using {addr, unpack, unpackRaw, currency, value, eq as ==, neq as !=} for a160u96 global; error AddressMismatch(address, address); function neq(a160u96 a, a160u96 b) pure returns (bool) { return !eq(a, b); } function eq(a160u96 a, a160u96 b) pure returns (bool) { return a160u96.unwrap(a) == a160u96.unwrap(b); } function currency(a160u96 packed) pure returns (Currency) { return Currency.wrap(addr(packed)); } function addr(a160u96 packed) pure returns (address) { return address(uint160(a160u96.unwrap(packed))); } function value(a160u96 packed) pure returns (uint96) { return uint96(a160u96.unwrap(packed) >> 160); } function unpack(a160u96 packed) pure returns (Currency _curr, uint96 _value) { uint256 raw = a160u96.unwrap(packed); _curr = Currency.wrap(address(uint160(raw))); _value = uint96(raw >> 160); } function unpackRaw(a160u96 packed) pure returns (address _addr, uint96 _value) { uint256 raw = a160u96.unwrap(packed); _addr = address(uint160(raw)); _value = uint96(raw >> 160); } library A160U96Factory { function create(address _addr, uint96 _value) internal pure returns (a160u96) { return a160u96.wrap((uint256(_value) << 160) | uint256(uint160(_addr))); } function create(Currency _currency, uint96 _value) internal pure returns (a160u96) { return create(Currency.unwrap(_currency), _value); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; interface AggregatorV3Interface { function decimals() external view returns (uint8); function description() external view returns (string memory); function version() external view returns (uint256); function getRoundData( uint80 _roundId ) external view returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound); function latestRoundData() external view returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound); }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.23; import {FixedPointMathLib} from "solmate/utils/FixedPointMathLib.sol"; /// @title PriceLib /// @notice A library for handling fixed-point arithmetic for prices library PriceLib { using FixedPointMathLib for uint256; /// @dev 2**128 uint256 internal constant Q128 = 0x100000000000000000000000000000000; uint16 internal constant PRICE_ORACLE_DECIMALS = 18; uint256 internal constant DECIMALS_MULTIPLIER = 10 ** PRICE_ORACLE_DECIMALS; /// @notice Converts (down) an amount in base units to an amount in asset units based on a fixed-price value /// @param base The amount to convert in base units /// @param price The fixed-price value represented as a uint256 /// @return The equivalent amount in asset units function convertToAssetsDown(uint256 base, uint256 price) internal pure returns (uint256) { return base.mulDivDown(price, Q128); } /// @notice Converts (up) an amount in base units to an amount in asset units based on a fixed-price value /// @param base The amount to convert in base units /// @param price The fixed-price value represented as a uint256 /// @return The equivalent amount in asset units function convertToAssetsUp(uint256 base, uint256 price) internal pure returns (uint256) { return base.mulDivUp(price, Q128); } /// @notice Converts (down) an amount in asset units to an amount in base units based on a fixed-price value /// @param assets The amount to convert in asset units /// @param price The fixed-price value represented as a uint256 /// @return The equivalent amount in base units function convertToBaseDown(uint256 assets, uint256 price) internal pure returns (uint256) { return assets.mulDivDown(Q128, price); } /// @notice Converts (up) an amount in asset units to an amount in base units based on a fixed-price value /// @param assets The amount to convert in asset units /// @param price The fixed-price value represented as a uint256 /// @return The equivalent amount in base units function convertToBaseUp(uint256 assets, uint256 price) internal pure returns (uint256) { return assets.mulDivUp(Q128, price); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol) pragma solidity ^0.8.0; /** * @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 amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` 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 amount) 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 `amount` 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 amount) external returns (bool); /** * @dev Moves `amount` tokens from `from` to `to` using the * allowance mechanism. `amount` 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 amount) external returns (bool); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/extensions/IERC20Permit.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612]. * * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't * need to send a transaction, and thus is not required to hold Ether at all. */ interface IERC20Permit { /** * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens, * given ``owner``'s signed approval. * * IMPORTANT: The same issues {IERC20-approve} has related to transaction * ordering also apply here. * * Emits an {Approval} event. * * Requirements: * * - `spender` cannot be the zero address. * - `deadline` must be a timestamp in the future. * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner` * over the EIP712-formatted function arguments. * - the signature must use ``owner``'s current nonce (see {nonces}). * * For more information on the signature format, see the * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP * section]. */ function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) external; /** * @dev Returns the current nonce for `owner`. This value must be * included whenever a signature is generated for {permit}. * * Every successful call to {permit} increases ``owner``'s nonce by one. This * prevents a signature from being used multiple times. */ function nonces(address owner) external view returns (uint256); /** * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}. */ // solhint-disable-next-line func-name-mixedcase function DOMAIN_SEPARATOR() external view returns (bytes32); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * * Furthermore, `isContract` will also return true if the target contract within * the same transaction is already scheduled for destruction by `SELFDESTRUCT`, * which only has an effect at the end of a transaction. * ==== * * [IMPORTANT] * ==== * You shouldn't rely on `isContract` to protect against flash loan attacks! * * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract * constructor. * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize/address.code.length, which returns 0 // for contracts in construction, since the code is only stored at the end // of the constructor execution. return account.code.length > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract. * * _Available since v4.8._ */ function verifyCallResultFromTarget( address target, bool success, bytes memory returndata, string memory errorMessage ) internal view returns (bytes memory) { if (success) { if (returndata.length == 0) { // only check isContract if the call was successful and the return data is empty // otherwise we already know that it was a contract require(isContract(target), "Address: call to non-contract"); } return returndata; } else { _revert(returndata, errorMessage); } } /** * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason or using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { _revert(returndata, errorMessage); } } function _revert(bytes memory returndata, string memory errorMessage) private pure { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly /// @solidity memory-safe-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } }
{ "remappings": [ "@openzeppelin/contracts/=lib/phuture-v2-contracts/lib/@openzeppelin/contracts/", "chainlink/=lib/phuture-v2-contracts/lib/chainlink-brownie-contracts/contracts/", "forge-std/=lib/forge-std/src/", "layerzero/=lib/phuture-v2-contracts/lib/LayerZero/contracts/", "redstone/=lib/phuture-v2-contracts/lib/redstone-oracles-monorepo/packages/evm-connector/contracts/", "solmate/=lib/phuture-v2-contracts/lib/solmate/src/", "src/=lib/phuture-v2-contracts/src/", "sstore2/=lib/phuture-v2-contracts/lib/sstore2/contracts/", "@chainlink/=node_modules/@chainlink/", "@eth-optimism/=node_modules/@eth-optimism/", "@redstone-finance/=node_modules/@redstone-finance/", "LayerZero/=lib/phuture-v2-contracts/lib/LayerZero/contracts/", "chainlink-brownie-contracts/=lib/phuture-v2-contracts/lib/chainlink-brownie-contracts/contracts/src/v0.6/vendor/@arbitrum/nitro-contracts/src/", "ds-test/=lib/forge-std/lib/ds-test/src/", "erc4626-tests/=lib/phuture-v2-contracts/lib/@openzeppelin/lib/erc4626-tests/", "openzeppelin-contracts/=lib/phuture-v2-contracts/lib/openzeppelin-contracts/", "openzeppelin/=lib/phuture-v2-contracts/lib/@openzeppelin/contracts/", "phuture-v2-contracts/=lib/phuture-v2-contracts/src/", "redstone-oracles-monorepo/=lib/phuture-v2-contracts/lib/", "solady/=lib/phuture-v2-contracts/lib/solady/src/" ], "optimizer": { "enabled": true, "runs": 200, "details": { "constantOptimizer": true, "yul": true, "yulDetails": { "stackAllocation": true } } }, "metadata": { "useLiteralContent": false, "bytecodeHash": "none", "appendCBOR": false }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "evmVersion": "paris", "viaIR": true, "libraries": {} }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"inputs":[],"name":"RoundMismatch","type":"error"},{"inputs":[],"name":"StalePrice","type":"error"},{"inputs":[{"internalType":"Currency","name":"","type":"address"}],"name":"UnsupportedCurrency","type":"error"},{"inputs":[{"internalType":"Currency","name":"currency0","type":"address"},{"internalType":"Currency","name":"currency1","type":"address"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"prices","outputs":[{"internalType":"uint256","name":"currency0Price","type":"uint256"},{"internalType":"uint256","name":"currency1Price","type":"uint256"}],"stateMutability":"view","type":"function"}]
Deployed Bytecode
0x6080604052600436101561001257600080fd5b6000803560e01c63f792edbc1461002857600080fd5b346100b15760603660031901126100b157600435906001600160a01b039081831683036100b15760243591821682036100b15760443567ffffffffffffffff8082116100b457366023830112156100b45781600401359081116100b457369101602401116100b157506100a561009f6040936100b8565b916100b8565b82519182526020820152f35b80fd5b8280fd5b6001600160a01b039081166060600073fa68fb4628dff1028cfec22b4162fccd0d45efb6830361029857505060126100ee610340565b916040516100fb8161030e565b610e108152735d37e4b374e6907de8fc7fb33ee3b0af403c740360208201526008604082015261012a846103a5565b52610134836103a5565b505b82511561028057506000610149836103a5565b519360ff9460409360ff8060408401511691160160ff811161026c5761016e906103b2565b92610184602092846020820151169051906103f0565b93670de0b6b3a764000091828602928684048114871517156102585760001996838804600160801b118402150202156100b15750608097949392971b04958551936001956001975b8689106101df5750505050505050505090565b90919293949596979881518a101561024257848a60051b8301015161021a61020b8686840151166103b2565b918888820151169051906103f0565b90808904831181021582021561023d578a920204990197969594939291906101cc565b600080fd5b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b82526011600452602482fd5b634e487b7160e01b84526011600452602484fd5b60249060405190636ee9993b60e01b82526004820152fd5b9091732791bca1f2de4661ed88a30c99a7a9449aa8417481036101365791505060066102c2610340565b916040516102cf8161030e565b6104b0815273fe4a8cc5b5b2366c1b58bea3858e81843581b2f76020820152600860408201526102fe846103a5565b52610308836103a5565b50610136565b6060810190811067ffffffffffffffff82111761032a57604052565b634e487b7160e01b600052604160045260246000fd5b604090604051916040830183811067ffffffffffffffff82111761032a576040526001835282916000805b60208082101561039c578451602092916103848261030e565b8482528481830152848783015282890101520161036b565b50505091925050565b8051156102425760200190565b60ff16604d81116103c357600a0a90565b634e487b7160e01b600052601160045260246000fd5b519069ffffffffffffffffffff8216820361023d57565b604051633fabe5a360e21b8152919060a090839060049082906001600160a01b03165afa80156104f0576000928391610471575b5080158015610467575b6104555742034281116103c357116104435790565b604051630cd5fa0760e11b8152600490fd5b6040516302436fdf60e51b8152600490fd5b506001831261042e565b92905060a03d60a0116104e9575b601f8101601f1916840167ffffffffffffffff8111858210176104d55760a0918591604052810103126100b157506104b6826103d9565b5060208201516104cd6080606085015194016103d9565b509138610424565b634e487b7160e01b83526041600452602483fd5b503d61047f565b6040513d6000823e3d90fd
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 30 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|
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.