Overview
S Balance
S Value
$0.00More Info
Private Name Tags
ContractCreator
Loading...
Loading
Contract Name:
UsdcQuoteV3
Compiler Version
v0.8.20+commit.a1b79de6
Optimization Enabled:
Yes with 200 runs
Other Settings:
paris EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT pragma solidity ^0.8.20; import "@uniswap/v3-core/contracts/libraries/FullMath.sol"; /// @notice Minimal interface for a Uniswap V3 pool (to access slot0) interface IUniswapV3Pool { function safelyGetStateOfAMM() external view returns ( uint160 sqrtPrice, // The current sqrt(price) as a Q64.96 value int24 tick, uint16 lastFee, uint8 pluginConfig, uint128 activeLiquidity, uint24 nextTick, uint24 previousTick ); } /// @title USDC Quote for a Specific Uniswap V3 Pool /// @notice Returns the USDC price (scaled to 18 decimals) of 1 token, /// assuming a pool where token0 is USDC and token1 is the token of interest. /// The pool is hardcoded as well as the token addresses. contract UsdcQuoteV3 { // Hardcoded addresses address public constant POOL_ADDRESS = 0x467865E7Ce29E7ED8f362D51Fd7141117B234b44; // token0 is USDC address public constant USDC = 0x29219dd400f2Bf60E5a23d13Be72B486D4038894; // token1 is the token to be priced (assumed to have 18 decimals) address public constant TOKEN = 0xA04BC7140c26fc9BB1F36B1A604C7A5a88fb0E70; // Constant representing 2^192 used for fixed‑point math uint256 public constant Q192 = 2**192; function getSqrtPrice() public view returns (uint256 price) { IUniswapV3Pool pool = IUniswapV3Pool(POOL_ADDRESS); (uint160 sqrtPrice,,,,,,) = pool.safelyGetStateOfAMM(); price = sqrtPrice; } /** * @notice Returns the USDC price (scaled to 18 decimals) for exactly 1 TOKEN. * * The pool’s slot0 stores sqrtPriceX96, where: * price_raw = (sqrtPriceX96)^2 / 2^192, * which is token1 per token0 (i.e. TOKEN per USDC). * To get USDC per TOKEN, we take the inverse: * price = 2^192 / (sqrtPriceX96)^2. * * Since USDC has 6 decimals and we want an 18‑decimal result, we multiply by 1e12. * * @return amount18 The USDC amount (scaled to 18 decimals) per 1 TOKEN. */ function getLatestPrice(address token) external view returns (uint256 amount18) { uint256 sqrtPrice = getSqrtPrice(); uint256 numerator1 = uint256(sqrtPrice) * uint256(sqrtPrice); amount18 = FullMath.mulDiv(1 << 192, 1e18, numerator1 * 10**6); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /// @title Contains 512-bit math functions /// @notice Facilitates multiplication and division that can have overflow of an intermediate value without any loss of precision /// @dev Handles "phantom overflow" i.e., allows multiplication and division where an intermediate value overflows 256 bits library FullMath { /// @notice Calculates floor(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0 /// @param a The multiplicand /// @param b The multiplier /// @param denominator The divisor /// @return result The 256-bit result /// @dev Credit to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv function mulDiv( uint256 a, uint256 b, uint256 denominator ) internal pure returns (uint256 result) { unchecked { // 512-bit multiply [prod1 prod0] = a * b // Compute the product mod 2**256 and mod 2**256 - 1 // then use the Chinese Remainder Theorem to reconstruct // the 512 bit result. The result is stored in two 256 // variables such that product = prod1 * 2**256 + prod0 uint256 prod0; // Least significant 256 bits of the product uint256 prod1; // Most significant 256 bits of the product assembly { let mm := mulmod(a, b, not(0)) prod0 := mul(a, b) prod1 := sub(sub(mm, prod0), lt(mm, prod0)) } // Handle non-overflow cases, 256 by 256 division if (prod1 == 0) { require(denominator > 0); assembly { result := div(prod0, denominator) } return result; } // Make sure the result is less than 2**256. // Also prevents denominator == 0 require(denominator > prod1); /////////////////////////////////////////////// // 512 by 256 division. /////////////////////////////////////////////// // Make division exact by subtracting the remainder from [prod1 prod0] // Compute remainder using mulmod uint256 remainder; assembly { remainder := mulmod(a, b, denominator) } // Subtract 256 bit number from 512 bit number assembly { prod1 := sub(prod1, gt(remainder, prod0)) prod0 := sub(prod0, remainder) } // Factor powers of two out of denominator // Compute largest power of two divisor of denominator. // Always >= 1. uint256 twos = (0 - denominator) & denominator; // Divide denominator by power of two assembly { denominator := div(denominator, twos) } // Divide [prod1 prod0] by the factors of two assembly { prod0 := div(prod0, twos) } // Shift in bits from prod1 into prod0. For this we need // to flip `twos` such that it is 2**256 / twos. // If twos is zero, then it becomes one assembly { twos := add(div(sub(0, twos), twos), 1) } prod0 |= prod1 * twos; // Invert denominator mod 2**256 // Now that denominator is an odd number, it has an inverse // modulo 2**256 such that denominator * inv = 1 mod 2**256. // Compute the inverse by starting with a seed that is correct // correct for four bits. That is, denominator * inv = 1 mod 2**4 uint256 inv = (3 * denominator) ^ 2; // Now use Newton-Raphson iteration to improve the precision. // Thanks to Hensel's lifting lemma, this also works in modular // arithmetic, doubling the correct bits in each step. inv *= 2 - denominator * inv; // inverse mod 2**8 inv *= 2 - denominator * inv; // inverse mod 2**16 inv *= 2 - denominator * inv; // inverse mod 2**32 inv *= 2 - denominator * inv; // inverse mod 2**64 inv *= 2 - denominator * inv; // inverse mod 2**128 inv *= 2 - denominator * inv; // inverse mod 2**256 // Because the division is now exact we can divide by multiplying // with the modular inverse of denominator. This will give us the // correct result modulo 2**256. Since the precoditions guarantee // that the outcome is less than 2**256, this is the final result. // We don't need to compute the high bits of the result and prod1 // is no longer required. result = prod0 * inv; return result; } } /// @notice Calculates ceil(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0 /// @param a The multiplicand /// @param b The multiplier /// @param denominator The divisor /// @return result The 256-bit result function mulDivRoundingUp( uint256 a, uint256 b, uint256 denominator ) internal pure returns (uint256 result) { unchecked { result = mulDiv(a, b, denominator); if (mulmod(a, b, denominator) > 0) { require(result < type(uint256).max); result++; } } } }
{ "optimizer": { "enabled": true, "runs": 200 }, "evmVersion": "paris", "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "libraries": {} }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[],"name":"POOL_ADDRESS","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"Q192","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"TOKEN","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"USDC","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"getLatestPrice","outputs":[{"internalType":"uint256","name":"amount18","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getSqrtPrice","outputs":[{"internalType":"uint256","name":"price","type":"uint256"}],"stateMutability":"view","type":"function"}]
Contract Creation Code
608060405234801561001057600080fd5b5061040b806100206000396000f3fe608060405234801561001057600080fd5b50600436106100625760003560e01c8063138c49d31461006757806316345f181461008557806382bfefc81461009857806386e6862d146100cb57806389a30271146100d3578063fe94df88146100ee575b600080fd5b610072600160c01b81565b6040519081526020015b60405180910390f35b6100726100933660046102b0565b610109565b6100b373a04bc7140c26fc9bb1f36b1a604c7a5a88fb0e7081565b6040516001600160a01b03909116815260200161007c565b61007261014f565b6100b37329219dd400f2bf60e5a23d13be72b486d403889481565b6100b373467865e7ce29e7ed8f362d51fd7141117b234b4481565b60008061011461014f565b9050600061012282806102cd565b9050610147600160c01b670de0b6b3a764000061014284620f42406102cd565b6101e5565b949350505050565b60008073467865e7ce29e7ed8f362d51fd7141117b234b4490506000816001600160a01b03166397ce1c516040518163ffffffff1660e01b815260040160e060405180830381865afa1580156101a9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101cd9190610330565b50506001600160a01b03909416979650505050505050565b600080806000198587098587029250828110838203039150508060000361021e576000841161021357600080fd5b508290049050610291565b80841161022a57600080fd5b6000848688096000868103871696879004966002600389028118808a02820302808a02820302808a02820302808a02820302808a02820302808a02909103029181900381900460010186841190950394909402919094039290920491909117919091029150505b9392505050565b6001600160a01b03811681146102ad57600080fd5b50565b6000602082840312156102c257600080fd5b813561029181610298565b80820281158282048414176102f257634e487b7160e01b600052601160045260246000fd5b92915050565b80516fffffffffffffffffffffffffffffffff8116811461031857600080fd5b919050565b805162ffffff8116811461031857600080fd5b600080600080600080600060e0888a03121561034b57600080fd5b875161035681610298565b8097505060208801518060020b811461036e57600080fd5b604089015190965061ffff8116811461038657600080fd5b606089015190955060ff8116811461039d57600080fd5b93506103ab608089016102f8565b92506103b960a0890161031d565b91506103c760c0890161031d565b90509295989194975092955056fea264697066735822122022f6fef6bfdbfd715ff0ea0d95e53f349ab2c5a8a0f573207f58ca4aca64b3c364736f6c63430008140033
Deployed Bytecode
0x608060405234801561001057600080fd5b50600436106100625760003560e01c8063138c49d31461006757806316345f181461008557806382bfefc81461009857806386e6862d146100cb57806389a30271146100d3578063fe94df88146100ee575b600080fd5b610072600160c01b81565b6040519081526020015b60405180910390f35b6100726100933660046102b0565b610109565b6100b373a04bc7140c26fc9bb1f36b1a604c7a5a88fb0e7081565b6040516001600160a01b03909116815260200161007c565b61007261014f565b6100b37329219dd400f2bf60e5a23d13be72b486d403889481565b6100b373467865e7ce29e7ed8f362d51fd7141117b234b4481565b60008061011461014f565b9050600061012282806102cd565b9050610147600160c01b670de0b6b3a764000061014284620f42406102cd565b6101e5565b949350505050565b60008073467865e7ce29e7ed8f362d51fd7141117b234b4490506000816001600160a01b03166397ce1c516040518163ffffffff1660e01b815260040160e060405180830381865afa1580156101a9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101cd9190610330565b50506001600160a01b03909416979650505050505050565b600080806000198587098587029250828110838203039150508060000361021e576000841161021357600080fd5b508290049050610291565b80841161022a57600080fd5b6000848688096000868103871696879004966002600389028118808a02820302808a02820302808a02820302808a02820302808a02820302808a02909103029181900381900460010186841190950394909402919094039290920491909117919091029150505b9392505050565b6001600160a01b03811681146102ad57600080fd5b50565b6000602082840312156102c257600080fd5b813561029181610298565b80820281158282048414176102f257634e487b7160e01b600052601160045260246000fd5b92915050565b80516fffffffffffffffffffffffffffffffff8116811461031857600080fd5b919050565b805162ffffff8116811461031857600080fd5b600080600080600080600060e0888a03121561034b57600080fd5b875161035681610298565b8097505060208801518060020b811461036e57600080fd5b604089015190965061ffff8116811461038657600080fd5b606089015190955060ff8116811461039d57600080fd5b93506103ab608089016102f8565b92506103b960a0890161031d565b91506103c760c0890161031d565b90509295989194975092955056fea264697066735822122022f6fef6bfdbfd715ff0ea0d95e53f349ab2c5a8a0f573207f58ca4aca64b3c364736f6c63430008140033
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 31 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.