Source Code
Overview
ETH Balance
0 ETH
ETH Value
$0.00| Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
|---|---|---|---|---|---|---|---|---|---|
Cross-Chain Transactions
Loading...
Loading
Similar Match Source Code This contract matches the deployed Bytecode of the Source Code for Contract 0x41cBecc9...c6D5B9D70 The constructor portion of the code might be different and could alter the actual behaviour of the contract
Contract Name:
ChainlinkDecimalDownscaler
Compiler Version
v0.8.22+commit.4fc1097e
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT
/* ———————————————————————————————————————————————————————————————————————————————— *
* _____ ______ ______ __ __ __ __ ______ __ __ *
* /\ __-. /\__ _\ /\ == \ /\ \ /\ "-.\ \ /\ \ /\__ _\ /\ \_\ \ *
* \ \ \/\ \ \/_/\ \/ \ \ __< \ \ \ \ \ \-. \ \ \ \ \/_/\ \/ \ \____ \ *
* \ \____- \ \_\ \ \_\ \_\ \ \_\ \ \_\\"\_\ \ \_\ \ \_\ \/\_____\ *
* \/____/ \/_/ \/_/ /_/ \/_/ \/_/ \/_/ \/_/ \/_/ \/_____/ *
* *
* ————————————————————————————————— dtrinity.org ————————————————————————————————— *
* *
* ▲ *
* ▲ ▲ *
* *
* ———————————————————————————————————————————————————————————————————————————————— *
* dTRINITY Protocol: https://github.com/dtrinity *
* ———————————————————————————————————————————————————————————————————————————————— */
pragma solidity ^0.8.20;
import "../interface/chainlink/IAggregatorV3Interface.sol";
import "../interface/chainlink/IPriceFeedLegacy.sol";
/**
* @title ChainlinkDecimalDownscaler
* @notice Dedicated downscaler for Chainlink price feeds - reduces decimal precision
* @dev Implements both AggregatorV3Interface and IPriceFeedLegacy for backwards compatibility
* @dev This contract is optimized for gas efficiency by only supporting downscaling operations
*/
contract ChainlinkDecimalDownscaler is AggregatorV3Interface, IPriceFeedLegacy {
/// @notice Original Chainlink price feed
AggregatorV3Interface public immutable sourceFeed;
/// @notice Legacy interface for the source feed (if supported)
IPriceFeedLegacy private immutable sourceFeedLegacy;
/// @notice Original decimals from the source feed
uint8 public immutable sourceDecimals;
/// @notice Target decimals for price conversion
uint8 public immutable override decimals;
/// @notice Scaling factor to convert between source and target decimals
int256 private immutable scalingFactor;
/**
* @notice Error thrown when target decimals exceed source decimals
*/
error InvalidDecimalsUpscaleNotSupported();
/**
* @notice Constructor to initialize the downscaling decimal converter
* @param _sourceFeed Address of the source Chainlink price feed
* @param _targetDecimals Target decimal precision (must be less than or equal to source decimals)
*/
constructor(address _sourceFeed, uint8 _targetDecimals) {
sourceFeed = AggregatorV3Interface(_sourceFeed);
sourceFeedLegacy = IPriceFeedLegacy(_sourceFeed);
sourceDecimals = sourceFeed.decimals();
decimals = _targetDecimals;
// We only support downscaling (reducing precision), not upscaling
if (_targetDecimals > sourceDecimals) {
revert InvalidDecimalsUpscaleNotSupported();
}
// Calculate the scaling factor to convert from source to target decimals
// For downscaling, we divide by 10^(sourceDecimals - targetDecimals)
uint8 decimalDifference = sourceDecimals - _targetDecimals;
scalingFactor = int256(10 ** decimalDifference);
}
/**
* @notice Returns the description of the original feed
* @return Description string
*/
function description() external view override returns (string memory) {
return sourceFeed.description();
}
/**
* @notice Returns the version of the original feed
* @return Version number
*/
function version() external view override returns (uint256) {
return sourceFeed.version();
}
/**
* @notice Gets data for a specific round
* @param _roundId The round ID to retrieve data for
* @return roundId The round ID
* @return answer The price with adjusted decimals
* @return startedAt The timestamp when the round started
* @return updatedAt The timestamp when the round was updated
* @return answeredInRound The round in which the answer was computed
*/
function getRoundData(
uint80 _roundId
) external view override returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound) {
(roundId, answer, startedAt, updatedAt, answeredInRound) = sourceFeed.getRoundData(_roundId);
answer = answer / scalingFactor;
}
/**
* @notice Gets data for the latest round
* @return roundId The round ID
* @return answer The price with adjusted decimals
* @return startedAt The timestamp when the round started
* @return updatedAt The timestamp when the round was updated
* @return answeredInRound The round in which the answer was computed
*/
function latestRoundData()
external
view
override
returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound)
{
(roundId, answer, startedAt, updatedAt, answeredInRound) = sourceFeed.latestRoundData();
answer = answer / scalingFactor;
}
/**
* @notice Legacy function: Gets the number of latest round
* @return latestRound The number of the latest update round
*/
function latestRound() external view override returns (uint80) {
try sourceFeedLegacy.latestRound() returns (uint80 roundId) {
return roundId;
} catch {
// Fall back to getting it from latestRoundData if legacy interface not supported
(uint80 roundId, , , , ) = sourceFeed.latestRoundData();
return roundId;
}
}
/**
* @notice Legacy function: Gets the latest successfully reported value with adjusted decimals
* @return latestAnswer The latest successfully reported value with target decimals
*/
function latestAnswer() external view override returns (int256) {
try sourceFeedLegacy.latestAnswer() returns (int256 answer) {
return answer / scalingFactor;
} catch {
// Fall back to getting it from latestRoundData if legacy interface not supported
(, int256 answer, , , ) = sourceFeed.latestRoundData();
return answer / scalingFactor;
}
}
}// SPDX-License-Identifier: MIT
/* ———————————————————————————————————————————————————————————————————————————————— *
* _____ ______ ______ __ __ __ __ ______ __ __ *
* /\ __-. /\__ _\ /\ == \ /\ \ /\ "-.\ \ /\ \ /\__ _\ /\ \_\ \ *
* \ \ \/\ \ \/_/\ \/ \ \ __< \ \ \ \ \ \-. \ \ \ \ \/_/\ \/ \ \____ \ *
* \ \____- \ \_\ \ \_\ \_\ \ \_\ \ \_\\"\_\ \ \_\ \ \_\ \/\_____\ *
* \/____/ \/_/ \/_/ /_/ \/_/ \/_/ \/_/ \/_/ \/_/ \/_____/ *
* *
* ————————————————————————————————— dtrinity.org ————————————————————————————————— *
* *
* ▲ *
* ▲ ▲ *
* *
* ———————————————————————————————————————————————————————————————————————————————— *
* dTRINITY Protocol: https://github.com/dtrinity *
* ———————————————————————————————————————————————————————————————————————————————— */
pragma solidity ^0.8.20;
interface AggregatorV3Interface {
function decimals() external view returns (uint8);
function description() external view returns (string memory);
function version() external view returns (uint256);
// getRoundData and latestRoundData should both raise "No data present"
// if they do not have data to report, instead of returning unset values
// which could be misinterpreted as actual reported values.
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: MIT
/* ———————————————————————————————————————————————————————————————————————————————— *
* _____ ______ ______ __ __ __ __ ______ __ __ *
* /\ __-. /\__ _\ /\ == \ /\ \ /\ "-.\ \ /\ \ /\__ _\ /\ \_\ \ *
* \ \ \/\ \ \/_/\ \/ \ \ __< \ \ \ \ \ \-. \ \ \ \ \/_/\ \/ \ \____ \ *
* \ \____- \ \_\ \ \_\ \_\ \ \_\ \ \_\\"\_\ \ \_\ \ \_\ \/\_____\ *
* \/____/ \/_/ \/_/ /_/ \/_/ \/_/ \/_/ \/_/ \/_/ \/_____/ *
* *
* ————————————————————————————————— dtrinity.org ————————————————————————————————— *
* *
* ▲ *
* ▲ ▲ *
* *
* ———————————————————————————————————————————————————————————————————————————————— *
* dTRINITY Protocol: https://github.com/dtrinity *
* ———————————————————————————————————————————————————————————————————————————————— */
pragma solidity ^0.8.20;
/**
* @title IPriceFeedLegacy
* @notice Legacy Chainlink price feed interface for backwards compatibility
* @dev Some older Chainlink feeds may only support these legacy functions
*/
interface IPriceFeedLegacy {
/**
* @notice Get the number of the latest update round
* @return The number of the latest update round
*/
function latestRound() external view returns (uint80);
/**
* @notice Get the latest successfully reported value
* @return The latest successfully reported value
*/
function latestAnswer() external view returns (int256);
}{
"evmVersion": "paris",
"metadata": {
"bytecodeHash": "ipfs",
"useLiteralContent": true
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": [],
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"address","name":"_sourceFeed","type":"address"},{"internalType":"uint8","name":"_targetDecimals","type":"uint8"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"InvalidDecimalsUpscaleNotSupported","type":"error"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"description","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint80","name":"_roundId","type":"uint80"}],"name":"getRoundData","outputs":[{"internalType":"uint80","name":"roundId","type":"uint80"},{"internalType":"int256","name":"answer","type":"int256"},{"internalType":"uint256","name":"startedAt","type":"uint256"},{"internalType":"uint256","name":"updatedAt","type":"uint256"},{"internalType":"uint80","name":"answeredInRound","type":"uint80"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"latestAnswer","outputs":[{"internalType":"int256","name":"","type":"int256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"latestRound","outputs":[{"internalType":"uint80","name":"","type":"uint80"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"latestRoundData","outputs":[{"internalType":"uint80","name":"roundId","type":"uint80"},{"internalType":"int256","name":"answer","type":"int256"},{"internalType":"uint256","name":"startedAt","type":"uint256"},{"internalType":"uint256","name":"updatedAt","type":"uint256"},{"internalType":"uint80","name":"answeredInRound","type":"uint80"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"sourceDecimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"sourceFeed","outputs":[{"internalType":"contract AggregatorV3Interface","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"version","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]Contract Creation Code
0x6101206040523480156200001257600080fd5b5060405162000cdc38038062000cdc833981016040819052620000359162000123565b6001600160a01b038216608081905260a08190526040805163313ce56760e01b8152905163313ce567916004808201926020929091908290030181865afa15801562000085573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620000ab919062000168565b60ff90811660c081905290821660e08190521115620000dd5760405163f00f549960e01b815260040160405180910390fd5b60008160c051620000ef9190620001a3565b9050620000fe81600a620002c2565b6101005250620002d3915050565b805160ff811681146200011e57600080fd5b919050565b600080604083850312156200013757600080fd5b82516001600160a01b03811681146200014f57600080fd5b91506200015f602084016200010c565b90509250929050565b6000602082840312156200017b57600080fd5b62000186826200010c565b9392505050565b634e487b7160e01b600052601160045260246000fd5b60ff8281168282160390811115620001bf57620001bf6200018d565b92915050565b600181815b8085111562000206578160001904821115620001ea57620001ea6200018d565b80851615620001f857918102915b93841c9390800290620001ca565b509250929050565b6000826200021f57506001620001bf565b816200022e57506000620001bf565b8160018114620002475760028114620002525762000272565b6001915050620001bf565b60ff8411156200026657620002666200018d565b50506001821b620001bf565b5060208310610133831016604e8410600b841016171562000297575081810a620001bf565b620002a38383620001c5565b8060001904821115620002ba57620002ba6200018d565b029392505050565b60006200018660ff8416836200020e565b60805160a05160c05160e0516101005161097f6200035d600039600081816102f0015281816103250152818161061f01526106ea01526000609d015260006101ba0152600081816101e801526103d701526000818161017b015281816102680152818161034e01528181610457015281816104eb015281816105a30152610659015261097f6000f3fe608060405234801561001057600080fd5b50600436106100935760003560e01c80637284e416116100665780637284e416146101175780639a6fc8f51461012c578063a1a927b114610176578063be231cb3146101b5578063feaf968c146101dc57600080fd5b8063313ce5671461009857806350d25bcd146100d657806354fd4d50146100ec578063668a0f02146100f4575b600080fd5b6100bf7f000000000000000000000000000000000000000000000000000000000000000081565b60405160ff90911681526020015b60405180910390f35b6100de6101e4565b6040519081526020016100cd565b6100de61034a565b6100fc6103d3565b60405169ffffffffffffffffffff90911681526020016100cd565b61011f6104e7565b6040516100cd919061073c565b61013f61013a36600461078a565b61056f565b6040805169ffffffffffffffffffff968716815260208101959095528401929092526060830152909116608082015260a0016100cd565b61019d7f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b0390911681526020016100cd565b6100bf7f000000000000000000000000000000000000000000000000000000000000000081565b61013f61064f565b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166350d25bcd6040518163ffffffff1660e01b8152600401602060405180830381865afa925050508015610260575060408051601f3d908101601f1916820190925261025d918101906107ae565b60015b6103205760007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663feaf968c6040518163ffffffff1660e01b815260040160a060405180830381865afa1580156102c4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102e891906107c7565b5050509150507f00000000000000000000000000000000000000000000000000000000000000008161031a919061081f565b91505090565b61031a7f00000000000000000000000000000000000000000000000000000000000000008261081f565b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166354fd4d506040518163ffffffff1660e01b8152600401602060405180830381865afa1580156103aa573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103ce91906107ae565b905090565b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663668a0f026040518163ffffffff1660e01b8152600401602060405180830381865afa92505050801561044f575060408051601f3d908101601f1916820190925261044c91810190610869565b60015b6104e25760007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663feaf968c6040518163ffffffff1660e01b815260040160a060405180830381865afa1580156104b3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104d791906107c7565b509295945050505050565b919050565b60607f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316637284e4166040518163ffffffff1660e01b8152600401600060405180830381865afa158015610547573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526103ce919081019061089c565b604051639a6fc8f560e01b815269ffffffffffffffffffff8216600482015260009081908190819081906001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690639a6fc8f59060240160a060405180830381865afa1580156105ea573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061060e91906107c7565b9398509196509450925090506106447f00000000000000000000000000000000000000000000000000000000000000008561081f565b935091939590929450565b60008060008060007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663feaf968c6040518163ffffffff1660e01b815260040160a060405180830381865afa1580156106b5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106d991906107c7565b93985091965094509250905061070f7f00000000000000000000000000000000000000000000000000000000000000008561081f565b93509091929394565b60005b8381101561073357818101518382015260200161071b565b50506000910152565b602081526000825180602084015261075b816040850160208701610718565b601f01601f19169190910160400192915050565b69ffffffffffffffffffff8116811461078757600080fd5b50565b60006020828403121561079c57600080fd5b81356107a78161076f565b9392505050565b6000602082840312156107c057600080fd5b5051919050565b600080600080600060a086880312156107df57600080fd5b85516107ea8161076f565b8095505060208601519350604086015192506060860151915060808601516108118161076f565b809150509295509295909350565b60008261083c57634e487b7160e01b600052601260045260246000fd5b600160ff1b82146000198414161561086457634e487b7160e01b600052601160045260246000fd5b500590565b60006020828403121561087b57600080fd5b81516107a78161076f565b634e487b7160e01b600052604160045260246000fd5b6000602082840312156108ae57600080fd5b815167ffffffffffffffff808211156108c657600080fd5b818401915084601f8301126108da57600080fd5b8151818111156108ec576108ec610886565b604051601f8201601f19908116603f0116810190838211818310171561091457610914610886565b8160405282815287602084870101111561092d57600080fd5b61093e836020830160208801610718565b97965050505050505056fea264697066735822122085b293e5b660ecf3a7fb002f19a3d5c2bcf9fa7cebe1e16ad11cb193bbd8e90e64736f6c63430008160033000000000000000000000000951ed02c90a0185575dc82e94088b9d3016b72630000000000000000000000000000000000000000000000000000000000000008
Deployed Bytecode
0x608060405234801561001057600080fd5b50600436106100935760003560e01c80637284e416116100665780637284e416146101175780639a6fc8f51461012c578063a1a927b114610176578063be231cb3146101b5578063feaf968c146101dc57600080fd5b8063313ce5671461009857806350d25bcd146100d657806354fd4d50146100ec578063668a0f02146100f4575b600080fd5b6100bf7f000000000000000000000000000000000000000000000000000000000000000881565b60405160ff90911681526020015b60405180910390f35b6100de6101e4565b6040519081526020016100cd565b6100de61034a565b6100fc6103d3565b60405169ffffffffffffffffffff90911681526020016100cd565b61011f6104e7565b6040516100cd919061073c565b61013f61013a36600461078a565b61056f565b6040805169ffffffffffffffffffff968716815260208101959095528401929092526060830152909116608082015260a0016100cd565b61019d7f000000000000000000000000951ed02c90a0185575dc82e94088b9d3016b726381565b6040516001600160a01b0390911681526020016100cd565b6100bf7f000000000000000000000000000000000000000000000000000000000000000881565b61013f61064f565b60007f000000000000000000000000951ed02c90a0185575dc82e94088b9d3016b72636001600160a01b03166350d25bcd6040518163ffffffff1660e01b8152600401602060405180830381865afa925050508015610260575060408051601f3d908101601f1916820190925261025d918101906107ae565b60015b6103205760007f000000000000000000000000951ed02c90a0185575dc82e94088b9d3016b72636001600160a01b031663feaf968c6040518163ffffffff1660e01b815260040160a060405180830381865afa1580156102c4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102e891906107c7565b5050509150507f00000000000000000000000000000000000000000000000000000000000000018161031a919061081f565b91505090565b61031a7f00000000000000000000000000000000000000000000000000000000000000018261081f565b60007f000000000000000000000000951ed02c90a0185575dc82e94088b9d3016b72636001600160a01b03166354fd4d506040518163ffffffff1660e01b8152600401602060405180830381865afa1580156103aa573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103ce91906107ae565b905090565b60007f000000000000000000000000951ed02c90a0185575dc82e94088b9d3016b72636001600160a01b031663668a0f026040518163ffffffff1660e01b8152600401602060405180830381865afa92505050801561044f575060408051601f3d908101601f1916820190925261044c91810190610869565b60015b6104e25760007f000000000000000000000000951ed02c90a0185575dc82e94088b9d3016b72636001600160a01b031663feaf968c6040518163ffffffff1660e01b815260040160a060405180830381865afa1580156104b3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104d791906107c7565b509295945050505050565b919050565b60607f000000000000000000000000951ed02c90a0185575dc82e94088b9d3016b72636001600160a01b0316637284e4166040518163ffffffff1660e01b8152600401600060405180830381865afa158015610547573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526103ce919081019061089c565b604051639a6fc8f560e01b815269ffffffffffffffffffff8216600482015260009081908190819081906001600160a01b037f000000000000000000000000951ed02c90a0185575dc82e94088b9d3016b72631690639a6fc8f59060240160a060405180830381865afa1580156105ea573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061060e91906107c7565b9398509196509450925090506106447f00000000000000000000000000000000000000000000000000000000000000018561081f565b935091939590929450565b60008060008060007f000000000000000000000000951ed02c90a0185575dc82e94088b9d3016b72636001600160a01b031663feaf968c6040518163ffffffff1660e01b815260040160a060405180830381865afa1580156106b5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106d991906107c7565b93985091965094509250905061070f7f00000000000000000000000000000000000000000000000000000000000000018561081f565b93509091929394565b60005b8381101561073357818101518382015260200161071b565b50506000910152565b602081526000825180602084015261075b816040850160208701610718565b601f01601f19169190910160400192915050565b69ffffffffffffffffffff8116811461078757600080fd5b50565b60006020828403121561079c57600080fd5b81356107a78161076f565b9392505050565b6000602082840312156107c057600080fd5b5051919050565b600080600080600060a086880312156107df57600080fd5b85516107ea8161076f565b8095505060208601519350604086015192506060860151915060808601516108118161076f565b809150509295509295909350565b60008261083c57634e487b7160e01b600052601260045260246000fd5b600160ff1b82146000198414161561086457634e487b7160e01b600052601160045260246000fd5b500590565b60006020828403121561087b57600080fd5b81516107a78161076f565b634e487b7160e01b600052604160045260246000fd5b6000602082840312156108ae57600080fd5b815167ffffffffffffffff808211156108c657600080fd5b818401915084601f8301126108da57600080fd5b8151818111156108ec576108ec610886565b604051601f8201601f19908116603f0116810190838211818310171561091457610914610886565b8160405282815287602084870101111561092d57600080fd5b61093e836020830160208801610718565b97965050505050505056fea264697066735822122085b293e5b660ecf3a7fb002f19a3d5c2bcf9fa7cebe1e16ad11cb193bbd8e90e64736f6c63430008160033
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 34 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
Loading...
Loading
Loading...
Loading
Loading...
Loading
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.