Verified contractExactMIT
CustomAggregatorV3CompatibleFeedAdjusted
Address0x4c825154d02eafab7f3c779d96c279bcdb9fcf6f
- Balance
0 ETH
- Transactions
1
- Compiler
solc 0.8.9
- Same code
11 more contracts
Details
- Compiler
- solc 0.8.9+commit.e5eed63a
- Language
- solidity
- Optimization
- Yes, 200 runs
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 24,798,798
- Creation transaction
- 0x5c62a3e86e…1e6df2bb28
contracts/feeds/CustomAggregatorV3CompatibleFeedAdjusted.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.9;
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
/**
* @title CustomAggregatorV3CompatibleFeedAdjusted
* @notice AggregatorV3 compatible proxy-feed that adjusts the price
* of an underlying chainlink compatible feed by a given signed percentage.
* Positive adjustmentPercentage raises the reported price.
* Negative adjustmentPercentage lowers the reported price.
* @author RedDuck Software
*/
contract CustomAggregatorV3CompatibleFeedAdjusted is AggregatorV3Interface {
/**
* @notice the underlying chainlink compatible feed
*/
AggregatorV3Interface public immutable underlyingFeed;
/**
* @notice the adjustment percentage (signed).
* Expressed in 10 ** decimals() precision.
* Example: 10 ** decimals() = 1%, -(10 ** decimals()) = -1%
* Positive values raise the reported price.
* Negative values lower the reported price.
*/
int256 public immutable adjustmentPercentage;
/**
* @notice constructor
* @param _underlyingFeed the underlying chainlink compatible feed
* @param _adjustmentPercentage signed adjustment percentage in 10 ** decimals() precision
*/
constructor(address _underlyingFeed, int256 _adjustmentPercentage) {
require(_underlyingFeed != address(0), "CAA: !underlying feed");
underlyingFeed = AggregatorV3Interface(_underlyingFeed);
int256 maxPct = int256(100 * (10**decimals()));
require(
_adjustmentPercentage >= -maxPct && _adjustmentPercentage <= maxPct,
"CAA: invalid adjustment"
);
adjustmentPercentage = _adjustmentPercentage;
}
/**
* @inheritdoc AggregatorV3Interface
*/
function latestRoundData()
external
view
returns (
uint80 roundId,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound
)
{
(
roundId,
answer,
startedAt,
updatedAt,
answeredInRound
) = underlyingFeed.latestRoundData();
answer = _calculateAdjustedAnswer(answer);
}
/**
* @inheritdoc AggregatorV3Interface
*/
function version() external view returns (uint256) {
return underlyingFeed.version();
}
/**
* @inheritdoc AggregatorV3Interface
*/
function getRoundData(uint80 _roundId)
public
view
returns (
uint80 roundId,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound
)
{
(
roundId,
answer,
startedAt,
updatedAt,
answeredInRound
) = underlyingFeed.getRoundData(_roundId);
answer = _calculateAdjustedAnswer(answer);
}
/**
* @inheritdoc AggregatorV3Interface
*/
function decimals() public view returns (uint8) {
return underlyingFeed.decimals();
}
/**
* @inheritdoc AggregatorV3Interface
*/
function description() public view returns (string memory) {
if (adjustmentPercentage == 0) return underlyingFeed.description();
string memory suffix = adjustmentPercentage > 0
? " PriceRaised"
: " PriceLowered";
return string(abi.encodePacked(underlyingFeed.description(), suffix));
}
/**
* @dev calculates the adjusted answer
* @param _answer the answer to adjust
* @return the adjusted answer
*/
function _calculateAdjustedAnswer(int256 _answer)
internal
view
returns (int256)
{
require(_answer >= 0, "CAA: !_answer");
int256 adjustment = (_answer * adjustmentPercentage) /
int256(100 * 10**decimals());
return _answer + adjustment;
}
}
@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol
// 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
);
}
Compiler settingsShow
{
"metadata": {
"useLiteralContent": true
},
"optimizer": {
"runs": 200,
"enabled": true
}
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.