Verified contractPartialMIT
ChainlinkOracleWrapper
Address0x97b3063c007066ce89130fe99065e1e245e5f5ea
- Balance
0 ETH
- Transactions
1
- Compiler
solc 0.8.28
- Same code
Only this contract
Details
- Compiler
- solc 0.8.28+commit.7893614a
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- prague
- License
- MIT
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,479,584
- Creation transaction
- 0xee799c21fe…3f8b761a0c
- Libraries
- node_modules/@shift-defi/core/contracts/libraries/Common.sol:Common0x5d87…d9303a
10 files
- node_modules/@shift-defi/core/contracts/priceOracles/ChainlinkOracleWrapper.solmain4.15 KB
- node_modules/@openzeppelin/contracts/access/AccessControl.sol7.05 KB
- node_modules/@openzeppelin/contracts/access/IAccessControl.sol3.34 KB
- node_modules/@openzeppelin/contracts/utils/Context.sol963 B
- node_modules/@openzeppelin/contracts/utils/introspection/ERC165.sol912 B
- node_modules/@openzeppelin/contracts/utils/introspection/IERC165.sol870 B
- node_modules/@shift-defi/core/contracts/dependencies/interfaces/chainlink/AggregatorV3Interface.sol870 B
- node_modules/@shift-defi/core/contracts/interfaces/IChainlinkOracleWrapper.sol2.15 KB
- node_modules/@shift-defi/core/contracts/interfaces/IPriceOracle.sol555 B
- node_modules/@shift-defi/core/contracts/libraries/Errors.sol1.21 KB
node_modules/@shift-defi/core/contracts/priceOracles/ChainlinkOracleWrapper.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol";
import {AggregatorV3Interface} from "../dependencies/interfaces/chainlink/AggregatorV3Interface.sol";
import {IChainlinkOracleWrapper} from "../interfaces/IChainlinkOracleWrapper.sol";
import {IPriceOracle} from "../interfaces/IPriceOracle.sol";
import {Errors} from "../libraries/Errors.sol";
contract ChainlinkOracleWrapper is AccessControl, IPriceOracle, IChainlinkOracleWrapper {
bytes32 private constant ORACLE_MANAGER_ROLE = keccak256("ORACLE_MANAGER_ROLE");
uint256 public defaultPriceFeedStalenessThreshold;
mapping(address => uint256) public priceFeedStalenessThreshold;
mapping(address => address) public tokenToChainlinkFeed;
constructor(
address defaultAdmin,
address oracleManager,
uint256 _defaultPriceFeedStalenessThreshold
) AccessControl() {
require(defaultAdmin != address(0), Errors.ZeroAddress());
require(oracleManager != address(0), Errors.ZeroAddress());
_grantRole(DEFAULT_ADMIN_ROLE, defaultAdmin);
_grantRole(ORACLE_MANAGER_ROLE, oracleManager);
_setDefaultPriceFeedStalenessThreshold(_defaultPriceFeedStalenessThreshold);
}
/// @inheritdoc IChainlinkOracleWrapper
function setChainlinkFeed(address token, address feed) external onlyRole(ORACLE_MANAGER_ROLE) {
require(token != address(0), Errors.ZeroAddress());
require(feed != address(0), Errors.ZeroAddress());
_getAndValidateLatestRoundData(token, feed);
tokenToChainlinkFeed[token] = feed;
emit ChainlinkFeedSet(token, feed);
}
/// @inheritdoc IChainlinkOracleWrapper
function setPriceFeedStalenessThreshold(address token, uint256 threshold) external onlyRole(ORACLE_MANAGER_ROLE) {
_setPriceFeedStalenessThreshold(token, threshold);
}
/// @inheritdoc IChainlinkOracleWrapper
function setDefaultPriceFeedStalenessThreshold(uint256 threshold) external onlyRole(ORACLE_MANAGER_ROLE) {
_setDefaultPriceFeedStalenessThreshold(threshold);
}
function _setPriceFeedStalenessThreshold(address token, uint256 threshold) internal {
require(token != address(0), Errors.ZeroAddress());
require(threshold > 0, ZeroStalenessThreshold());
uint256 previousThreshold = priceFeedStalenessThreshold[token];
priceFeedStalenessThreshold[token] = threshold;
emit PriceFeedStalenessThresholdUpdated(token, previousThreshold, threshold);
}
function _setDefaultPriceFeedStalenessThreshold(uint256 threshold) internal {
require(threshold > 0, ZeroStalenessThreshold());
uint256 previousThreshold = defaultPriceFeedStalenessThreshold;
defaultPriceFeedStalenessThreshold = threshold;
emit DefaultPriceFeedStalenessThresholdUpdated(previousThreshold, threshold);
}
/// @inheritdoc IPriceOracle
function getPrice(address token) external view returns (uint256, uint8) {
require(token != address(0), Errors.ZeroAddress());
address chainlinkFeed = tokenToChainlinkFeed[token];
require(chainlinkFeed != address(0), ChainlinkFeedNotFound(token));
uint256 price = _getAndValidateLatestRoundData(token, chainlinkFeed);
return (price, AggregatorV3Interface(chainlinkFeed).decimals());
}
function decimals() external pure returns (uint8) {
revert Errors.NotImplemented();
}
function _getAndValidateLatestRoundData(address token, address feed) internal view returns (uint256) {
(, int256 price, , uint256 updatedAt, ) = AggregatorV3Interface(feed).latestRoundData();
require(price > 0, ZeroPrice(token));
uint256 stalenessThreshold = priceFeedStalenessThreshold[token];
stalenessThreshold = stalenessThreshold == 0 ? defaultPriceFeedStalenessThreshold : stalenessThreshold;
require(
block.timestamp - updatedAt <= stalenessThreshold,
StalePriceFeed(token, updatedAt, stalenessThreshold)
);
return uint256(price);
}
}
node_modules/@openzeppelin/contracts/access/AccessControl.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/AccessControl.sol)
pragma solidity ^0.8.20;
import {IAccessControl} from "./IAccessControl.sol";
import {Context} from "../utils/Context.sol";
import {ERC165} from "../utils/introspection/ERC165.sol";
/**
* @dev Contract module that allows children to implement role-based access
* control mechanisms. This is a lightweight version that doesn't allow enumerating role
* members except through off-chain means by accessing the contract event logs. Some
* applications may benefit from on-chain enumerability, for those cases see
* {AccessControlEnumerable}.
*
* Roles are referred to by their `bytes32` identifier. These should be exposed
* in the external API and be unique. The best way to achieve this is by
* using `public constant` hash digests:
*
* ```solidity
* bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
* ```
*
* Roles can be used to represent a set of permissions. To restrict access to a
* function call, use {hasRole}:
*
* ```solidity
* function foo() public {
* require(hasRole(MY_ROLE, msg.sender));
* ...
* }
* ```
*
* Roles can be granted and revoked dynamically via the {grantRole} and
* {revokeRole} functions. Each role has an associated admin role, and only
* accounts that have a role's admin role can call {grantRole} and {revokeRole}.
*
* By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
* that only accounts with this role will be able to grant or revoke other
* roles. More complex role relationships can be created by using
* {_setRoleAdmin}.
*
* WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
* grant and revoke this role. Extra precautions should be taken to secure
* accounts that have been granted it. We recommend using {AccessControlDefaultAdminRules}
* to enforce additional security measures for this role.
*/
abstract contract AccessControl is Context, IAccessControl, ERC165 {
struct RoleData {
mapping(address account => bool) hasRole;
bytes32 adminRole;
}
mapping(bytes32 role => RoleData) private _roles;
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
/**
* @dev Modifier that checks that an account has a specific role. Reverts
* with an {AccessControlUnauthorizedAccount} error including the required role.
*/
modifier onlyRole(bytes32 role) {
_checkRole(role);
_;
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) public view virtual returns (bool) {
return _roles[role].hasRole[account];
}
/**
* @dev Reverts with an {AccessControlUnauthorizedAccount} error if `_msgSender()`
* is missing `role`. Overriding this function changes the behavior of the {onlyRole} modifier.
*/
function _checkRole(bytes32 role) internal view virtual {
_checkRole(role, _msgSender());
}
/**
* @dev Reverts with an {AccessControlUnauthorizedAccount} error if `account`
* is missing `role`.
*/
function _checkRole(bytes32 role, address account) internal view virtual {
if (!hasRole(role, account)) {
revert AccessControlUnauthorizedAccount(account, role);
}
}
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) public view virtual returns (bytes32) {
return _roles[role].adminRole;
}
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*
* May emit a {RoleGranted} event.
*/
function grantRole(bytes32 role, address account) public virtual onlyRole(getRoleAdmin(role)) {
_grantRole(role, account);
}
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*
* May emit a {RoleRevoked} event.
*/
function revokeRole(bytes32 role, address account) public virtual onlyRole(getRoleAdmin(role)) {
_revokeRole(role, account);
}
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been revoked `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `callerConfirmation`.
*
* May emit a {RoleRevoked} event.
*/
function renounceRole(bytes32 role, address callerConfirmation) public virtual {
if (callerConfirmation != _msgSender()) {
revert AccessControlBadConfirmation();
}
_revokeRole(role, callerConfirmation);
}
/**
* @dev Sets `adminRole` as ``role``'s admin role.
*
* Emits a {RoleAdminChanged} event.
*/
function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
bytes32 previousAdminRole = getRoleAdmin(role);
_roles[role].adminRole = adminRole;
emit RoleAdminChanged(role, previousAdminRole, adminRole);
}
/**
* @dev Attempts to grant `role` to `account` and returns a boolean indicating if `role` was granted.
*
* Internal function without access restriction.
*
* May emit a {RoleGranted} event.
*/
function _grantRole(bytes32 role, address account) internal virtual returns (bool) {
if (!hasRole(role, account)) {
_roles[role].hasRole[account] = true;
emit RoleGranted(role, account, _msgSender());
return true;
} else {
return false;
}
}
/**
* @dev Attempts to revoke `role` to `account` and returns a boolean indicating if `role` was revoked.
*
* Internal function without access restriction.
*
* May emit a {RoleRevoked} event.
*/
function _revokeRole(bytes32 role, address account) internal virtual returns (bool) {
if (hasRole(role, account)) {
_roles[role].hasRole[account] = false;
emit RoleRevoked(role, account, _msgSender());
return true;
} else {
return false;
}
}
}
node_modules/@openzeppelin/contracts/access/IAccessControl.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (access/IAccessControl.sol)
pragma solidity ^0.8.20;
/**
* @dev External interface of AccessControl declared to support ERC-165 detection.
*/
interface IAccessControl {
/**
* @dev The `account` is missing a role.
*/
error AccessControlUnauthorizedAccount(address account, bytes32 neededRole);
/**
* @dev The caller of a function is not the expected one.
*
* NOTE: Don't confuse with {AccessControlUnauthorizedAccount}.
*/
error AccessControlBadConfirmation();
/**
* @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
*
* `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
* {RoleAdminChanged} not being emitted signaling this.
*/
event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);
/**
* @dev Emitted when `account` is granted `role`.
*
* `sender` is the account that originated the contract call. This account bears the admin role (for the granted role).
* Expected in cases where the role was granted using the internal {AccessControl-_grantRole}.
*/
event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Emitted when `account` is revoked `role`.
*
* `sender` is the account that originated the contract call:
* - if using `revokeRole`, it is the admin role bearer
* - if using `renounceRole`, it is the role bearer (i.e. `account`)
*/
event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) external view returns (bool);
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {AccessControl-_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) external view returns (bytes32);
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function grantRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function revokeRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been granted `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `callerConfirmation`.
*/
function renounceRole(bytes32 role, address callerConfirmation) external;
}
node_modules/@openzeppelin/contracts/utils/Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
node_modules/@openzeppelin/contracts/utils/introspection/ERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/ERC165.sol)
pragma solidity ^0.8.20;
import {IERC165} from "./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC-165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
node_modules/@openzeppelin/contracts/utils/introspection/IERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/IERC165.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[ERC].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
node_modules/@shift-defi/core/contracts/dependencies/interfaces/chainlink/AggregatorV3Interface.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
// Imported from https://github.com/smartcontractkit/chainlink/blob/e8490e910274279a2c394ba37eb328943322ac6b/contracts/src/v0.8/shared/interfaces/AggregatorV3Interface.sol
// solhint-disable-next-line interface-starts-with-i
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);
}
node_modules/@shift-defi/core/contracts/interfaces/IChainlinkOracleWrapper.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
interface IChainlinkOracleWrapper {
// ---- Events ----
event ChainlinkFeedSet(address indexed token, address indexed feed);
event PriceFeedStalenessThresholdUpdated(address indexed token, uint256 previousThreshold, uint256 newThreshold);
event DefaultPriceFeedStalenessThresholdUpdated(uint256 previousThreshold, uint256 newThreshold);
// ---- Errors ----
error ChainlinkFeedNotFound(address token);
error ZeroPrice(address token);
error ZeroStalenessThreshold();
error StalePriceFeed(address token, uint256 updatedAt, uint256 threshold);
// ---- Functions ----
/**
* @notice Returns the Chainlink feed address for a token.
* @param token The address of the token
* @return The address of the Chainlink price feed
*/
function tokenToChainlinkFeed(address token) external view returns (address);
/**
* @notice Returns the maximum age (in seconds) a price update may have before it is considered stale.
*/
function priceFeedStalenessThreshold(address token) external view returns (uint256);
/**
* @notice Sets the Chainlink feed address for a token.
* @dev Can only be called by accounts with ORACLE_MANAGER_ROLE.
* @param token The address of the token
* @param feed The address of the Chainlink price feed
*/
function setChainlinkFeed(address token, address feed) external;
/**
* @notice Sets the maximum age a Chainlink price update may have before it is considered stale.
* @dev Can only be called by accounts with ORACLE_MANAGER_ROLE.
* @param token The address of the token
* @param threshold Maximum age in seconds
*/
function setPriceFeedStalenessThreshold(address token, uint256 threshold) external;
/**
* @notice Sets the default maximum age a Chainlink price update may have before it is considered stale.
* @dev Can only be called by accounts with ORACLE_MANAGER_ROLE.
* @param threshold Maximum age in seconds
*/
function setDefaultPriceFeedStalenessThreshold(uint256 threshold) external;
}
node_modules/@shift-defi/core/contracts/interfaces/IPriceOracle.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
interface IPriceOracle {
// ---- Functions ----
/**
* @notice Gets the price of a token.
* @param token The address of the token
* @return The price of the token
* @return The number of decimals for the price
*/
function getPrice(address token) external view returns (uint256, uint8);
/**
* @notice Returns the number of decimals used for prices.
* @return The number of decimals
*/
function decimals() external view returns (uint8);
}
node_modules/@shift-defi/core/contracts/libraries/Errors.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
library Errors {
// -- Access Control Errors --
error Unauthorized();
// -- State Errors --
error AlreadyBlacklisted();
error AlreadyWhitelisted();
error NotImplemented();
error TokenAlreadySet(address value);
error AlreadySet();
// -- Input Validation Errors --
error ArrayLengthMismatch();
error InvalidArrayLength();
error IncorrectAmount();
error IncorrectContainerStatus();
error ZeroAddress();
error ZeroAmount();
error ZeroArrayLength();
error IncorrectContainerType(address container, uint8 expected, uint8 received);
error DuplicatingAddressInArray(address entry);
error IncorrectChainId(uint256 chainId);
error SettingSameBooleanValue();
error SettingSameValue();
// -- Business Logic Errors --
error ReshufflingModeEnabled();
error ReshufflingModeDisabled();
error ReshufflingGatewayNotSet();
error NotEnoughNativeToken(uint256 value, uint256 balance);
error NotEnoughTokens(address token, uint256 amount, uint256 balance);
error SwapFailed(address tokenIn, address tokenOut, uint256 amountIn, uint256 minAmountOut);
}
Compiler settingsShow
{
"viaIR": false,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"libraries": {
"node_modules/@shift-defi/core/contracts/libraries/Common.sol": {
"Common": "0x5D872D5E5a80c44Ef27001A738D1e317fFD9303A"
}
},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "prague",
"remappings": [
"@shift-defi/core/=node_modules/@shift-defi/core/contracts/",
"@shift-defi/strategies/=node_modules/@shift-defi/strategies/",
"@openzeppelin/contracts/=node_modules/@openzeppelin/contracts/",
"@openzeppelin/contracts-upgradeable/=node_modules/@openzeppelin/contracts-upgradeable/",
"contracts/=node_modules/@shift-defi/strategies/contracts/",
"forge-std/=lib/forge-std/src/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.