Contract
0xCC54299Fc291B261B2bF5552E7F0E5d2F8613E8C
3
Contract Overview
Balance:
0 xDAI
xDAI Value:
$0.00
My Name Tag:
Not Available, login to update
Txn Hash | Method |
Block
|
From
|
To
|
Value | [Txn Fee] | |||
---|---|---|---|---|---|---|---|---|---|
0x7cfe05dcb8707449d09f3076d8ec31b383cd6970f2ccc99a43012e71fddbaf8e | 0x60c03461 | 27313349 | 63 days 22 hrs ago | 0x56e44874f624ebde6efcc783efd685f0fbdc6dcf | IN | Create: UniswapV2LikeOracle | 0 xDAI | 0.000397375002 |
[ Download CSV Export ]
Contract Source Code Verified (Exact Match)
Contract Name:
UniswapV2LikeOracle
Compiler Version
v0.8.19+commit.7dd6d404
Optimization Enabled:
Yes with 1000000 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.6.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.8.0) (utils/math/Math.sol) pragma solidity ^0.8.0; /** * @dev Standard math utilities missing in the Solidity language. */ library Math { enum Rounding { Down, // Toward negative infinity Up, // Toward infinity Zero // Toward zero } /** * @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 up instead * of rounding down. */ function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) { // (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; // Least significant 256 bits of the product uint256 prod1; // Most significant 256 bits of the product assembly { let mm := mulmod(x, y, not(0)) prod0 := mul(x, y) prod1 := sub(sub(mm, prod0), lt(mm, prod0)) } // Handle non-overflow cases, 256 by 256 division. if (prod1 == 0) { return prod0 / denominator; } // 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]. 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. // Does not overflow because the denominator cannot be zero at this stage in the function. uint256 twos = denominator & (~denominator + 1); 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 (rounding == Rounding.Up && 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 down. * * 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 + (rounding == Rounding.Up && result * result < a ? 1 : 0); } } /** * @dev Return the log in base 2, rounded down, of a positive value. * 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 + (rounding == Rounding.Up && 1 << result < value ? 1 : 0); } } /** * @dev Return the log in base 10, rounded down, of a positive value. * 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 + (rounding == Rounding.Up && 10**result < value ? 1 : 0); } } /** * @dev Return the log in base 256, rounded down, of a positive value. * 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 10, 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 + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0); } } }
// SPDX-License-Identifier: MIT pragma solidity 0.8.19; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; interface IOracle { error ConnectorShouldBeNone(); error PoolNotFound(); error PoolWithConnectorNotFound(); function getRate(IERC20 srcToken, IERC20 dstToken, IERC20 connector) external view returns (uint256 rate, uint256 weight); }
// SPDX-License-Identifier: UNLICENSED pragma solidity 0.8.19; interface IUniswapV2Pair { function getReserves() external view returns (uint112 _reserve0, uint112 _reserve1, uint32 _blockTimestampLast); }
// SPDX-License-Identifier: MIT pragma solidity 0.8.19; library Sqrt { function sqrt(uint y) internal pure returns (uint z) { unchecked { if (y > 3) { z = y; uint x = y / 2 + 1; while (x < z) { z = x; x = (y / x + x) / 2; } } else if (y != 0) { z = 1; } } } }
// SPDX-License-Identifier: MIT pragma solidity 0.8.19; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/utils/math/Math.sol"; import "../interfaces/IOracle.sol"; import "../libraries/Sqrt.sol"; abstract contract OracleBase is IOracle { using Sqrt for uint256; IERC20 private constant _NONE = IERC20(0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF); function getRate(IERC20 srcToken, IERC20 dstToken, IERC20 connector) external view override returns (uint256 rate, uint256 weight) { uint256 balance0; uint256 balance1; if (connector == _NONE) { (balance0, balance1) = _getBalances(srcToken, dstToken); weight = (balance0 * balance1).sqrt(); } else { uint256 balanceConnector0; uint256 balanceConnector1; (balance0, balanceConnector0) = _getBalances(srcToken, connector); (balanceConnector1, balance1) = _getBalances(connector, dstToken); if (balanceConnector0 > balanceConnector1) { balance0 = balance0 * balanceConnector1 / balanceConnector0; } else { balance1 = balance1 * balanceConnector0 / balanceConnector1; } weight = Math.min(balance0 * balanceConnector0, balance1 * balanceConnector1).sqrt(); } rate = balance1 * 1e18 / balance0; } function _getBalances(IERC20 srcToken, IERC20 dstToken) internal view virtual returns (uint256 srcBalance, uint256 dstBalance); }
// SPDX-License-Identifier: MIT pragma solidity 0.8.19; import "./OracleBase.sol"; import "../interfaces/IUniswapV2Pair.sol"; contract UniswapV2LikeOracle is OracleBase { address public immutable factory; bytes32 public immutable initcodeHash; constructor(address _factory, bytes32 _initcodeHash) { factory = _factory; initcodeHash = _initcodeHash; } // calculates the CREATE2 address for a pair without making any external calls function _pairFor(IERC20 tokenA, IERC20 tokenB) private view returns (address pair) { pair = address(uint160(uint256(keccak256(abi.encodePacked( hex"ff", factory, keccak256(abi.encodePacked(tokenA, tokenB)), initcodeHash ))))); } function _getBalances(IERC20 srcToken, IERC20 dstToken) internal view override returns (uint256 srcBalance, uint256 dstBalance) { (IERC20 token0, IERC20 token1) = srcToken < dstToken ? (srcToken, dstToken) : (dstToken, srcToken); (uint256 reserve0, uint256 reserve1,) = IUniswapV2Pair(_pairFor(token0, token1)).getReserves(); (srcBalance, dstBalance) = srcToken == token0 ? (reserve0, reserve1) : (reserve1, reserve0); } }
{ "optimizer": { "enabled": true, "runs": 1000000 }, "viaIR": true, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "metadata": { "useLiteralContent": true }, "libraries": {} }
[{"inputs":[{"internalType":"address","name":"_factory","type":"address"},{"internalType":"bytes32","name":"_initcodeHash","type":"bytes32"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"ConnectorShouldBeNone","type":"error"},{"inputs":[],"name":"PoolNotFound","type":"error"},{"inputs":[],"name":"PoolWithConnectorNotFound","type":"error"},{"inputs":[],"name":"factory","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"srcToken","type":"address"},{"internalType":"contract IERC20","name":"dstToken","type":"address"},{"internalType":"contract IERC20","name":"connector","type":"address"}],"name":"getRate","outputs":[{"internalType":"uint256","name":"rate","type":"uint256"},{"internalType":"uint256","name":"weight","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"initcodeHash","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"}]
Contract Creation Code
60c03461008857601f6106e038819003918201601f19168301916001600160401b0383118484101761008d578084926040948552833981010312610088578051906001600160a01b038216820361008857602001519060805260a05260405161063c90816100a4823960805181818160880152610430015260a05181818160e5015261045e0152f35b600080fd5b634e487b7160e01b600052604160045260246000fdfe6080604052600436101561001257600080fd5b6000803560e01c806314999e79146101085780635a4fb9a8146100af5763c45a01551461003e57600080fd5b346100ac57807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100ac57602060405173ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000168152f35b80fd5b50346100ac57807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100ac5760206040517f00000000000000000000000000000000000000000000000000000000000000008152f35b50346100ac5760607ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100ac576004359073ffffffffffffffffffffffffffffffffffffffff808316830361029557602435908082168203610291576044359080821680830361028d57036101fd5750610185919261037d565b90919061019a6101958285610299565b610314565b915b670de0b6b3a7640000918281029281840414901517156101d057506040926101c3916102db565b9082519182526020820152f35b807f4e487b7100000000000000000000000000000000000000000000000000000000602492526011600452fd5b61020a816102149561037d565b949092839261037d565b92909183838711156102695750509061024e61024761023f8761023a8561025c97610299565b6102db565b965b87610299565b9184610299565b808210156102625750610314565b9161019c565b9050610314565b86945083925061028761025c9461023a61024e949961024794610299565b94610241565b8480fd5b8280fd5b5080fd5b818102929181159184041417156102ac57565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b81156102e5570490565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b906000600383111561035057508160018082811c01915b84831061033757505050565b919350908361034681836102db565b01821c919061032b565b9161035757565b60019150565b51906dffffffffffffffffffffffffffff8216820361037857565b600080fd5b73ffffffffffffffffffffffffffffffffffffffff9080821690838316808310156105fa575092915b60405160208101907fffffffffffffffffffffffffffffffffffffffff000000000000000000000000806060968189891b168552871b1660348301526028825285820167ffffffffffffffff93838210858311176105cb57816040528351902060808401927fff0000000000000000000000000000000000000000000000000000000000000084527f0000000000000000000000000000000000000000000000000000000000000000891b16608185015260958401527f000000000000000000000000000000000000000000000000000000000000000060b58401526055815260e0830191818310858411176105cb576004838781938b9583604052519020167f0902f1ac0000000000000000000000000000000000000000000000000000000082525afa9586156105bf576000938497610505575b505050506dffffffffffffffffffffffffffff80911693169316146000146105015791565b9091565b908092939750903d83116105b7575b601f82017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016880160e0019081118482101761058a57604052860186900312610295576105609061035d565b90610120610571610100870161035d565b95015163ffffffff8116036100ac5750388080806104dc565b6024857f4e487b710000000000000000000000000000000000000000000000000000000081526041600452fd5b3d9150610514565b6040513d6000823e3d90fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b919350509180916103a656fea264697066735822122026a14000208a54a53f7951ac28ec0c51de6d27fbf6f18b416230d72f20ab594564736f6c63430008130033000000000000000000000000a818b4f111ccac7aa31d0bcc0806d64f2e0737d73f88503e8580ab941773b59034fb4b2a63e86dbc031b3633a925533ad3ed2b93
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
000000000000000000000000a818b4f111ccac7aa31d0bcc0806d64f2e0737d73f88503e8580ab941773b59034fb4b2a63e86dbc031b3633a925533ad3ed2b93
-----Decoded View---------------
Arg [0] : _factory (address): 0xa818b4f111ccac7aa31d0bcc0806d64f2e0737d7
Arg [1] : _initcodeHash (bytes32): 0x3f88503e8580ab941773b59034fb4b2a63e86dbc031b3633a925533ad3ed2b93
-----Encoded View---------------
2 Constructor Arguments found :
Arg [0] : 000000000000000000000000a818b4f111ccac7aa31d0bcc0806d64f2e0737d7
Arg [1] : 3f88503e8580ab941773b59034fb4b2a63e86dbc031b3633a925533ad3ed2b93
Age | Block | Fee Address | BC Fee Address | Voting Power | Jailed | Incoming |
---|
Make sure to use the "Vote Down" button for any spammy posts, and the "Vote Up" for interesting conversations.