Discover more of SonicScan Block Explorer's tools and services in one place.
Contract Source Code:
File 1 of 1 : OffchainOracle
// SPDX-License-Identifier: No pragma solidity 0.7.6; interface IERC20 { function totalSupply() external view returns (uint256); function balanceOf(address account) external view returns (uint256); function transfer(address recipient, uint256 amount) external returns (bool); function allowance(address owner, address spender) external view returns (uint256); function approve(address spender, uint256 amount) external returns (bool); function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); event Transfer(address indexed from, address indexed to, uint256 value); event Approval(address indexed owner, address indexed spender, uint256 value); } interface IERC20Metadata is IERC20 { function name() external view returns (string memory); function symbol() external view returns (string memory); function decimals() external view returns (uint8); } // For Solidly v3 interface ISolidlyV3Pool { function slot0() external view returns (uint160 sqrtPriceX96, int24, uint24, bool); function token0() external view returns (address); function token1() external view returns (address); } contract OffchainOracle { function getRate(address tokenFrom, address tokenTo, address poolAddress, uint8 ver) external view returns (uint256 rate, uint8 decimalsFrom, uint8 decimalsTo) { // version = 3 : Solidly v3 if(ver == 3) { address token0 = ISolidlyV3Pool(poolAddress).token0(); address token1 = ISolidlyV3Pool(poolAddress).token1(); (uint256 sqrtPriceX96,,,) = ISolidlyV3Pool(poolAddress).slot0(); if(token0 == tokenFrom) { decimalsFrom = IERC20Metadata(token0).decimals(); decimalsTo = IERC20Metadata(token1).decimals(); rate = (((1e18 * sqrtPriceX96) >> 96) * sqrtPriceX96) >> 96; } else { decimalsFrom = IERC20Metadata(token1).decimals(); decimalsTo = IERC20Metadata(token0).decimals(); rate = (1e18 << 192) / sqrtPriceX96 / sqrtPriceX96; } } } }
Please enter a contract address above to load the contract details and source code.
Please DO NOT store any passwords or private keys here. A private note (up to 100 characters) can be saved and is useful for transaction tracking.
This website uses cookies to improve your experience. By continuing to use this website, you agree to its Terms and Privacy Policy.