OracleAdapter

Description:

Multi-signature wallet contract requiring multiple confirmations for transaction execution.

Blockchain: Ethereum

Source Code: View Code On The Blockchain

Solidity Source Code:

{{
  "language": "Solidity",
  "sources": {
    "src/OracleAdapter.sol": {
      "content": "// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.29;

import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { AggregatorV3Interface } from "@chainlink-contracts-0.8.0/src/v0.8/interfaces/AggregatorV3Interface.sol";

import { IOracleAdapter } from "src/interfaces/IOracleAdapter.sol";
import { Constants } from "src/lib/Constants.sol";
import { Errors } from "src/lib/Errors.sol";

/// @title The OracleAdapter SC that manages price feeds for tokens
/// @notice This contract allows the owner to set price feeds for various tokens and retrieve their prices in USD
contract OracleAdapter is IOracleAdapter, Ownable {
    /// @notice The minimum interval in seconds between manual updates in the OracleAdapter SC (e.g., 4200 for 1h10m)
    uint256 public manualUpdateInterval = 4200;

    /// @notice The mapping of token addresses to their corresponding Chainlink price feeds
    /// @dev This mapping is used to get the price of the token in USD, schema: token => Chainlink feed
    mapping(address => address) public priceFeeds;

    /// @notice The mapping of token addresses to their heartbeat threshold in seconds
    /// @dev The heartbeat is used to ensure that the price feed is still active and has been updated recently
    mapping(address => uint256) public heartbeats;

    /// @notice The mapping stores manually pushed prices for a specific token (scaled to 18 decimals)
    /// @dev This allows the owner to set a price for a token that may not have an active price feed
    mapping(address => uint256) public manualPrices;

    /// @notice The timestamp of last manual price update
    /// @dev This is used to enforce a cooldown period between manual updates
    mapping(address => uint256) public manualLastUpdated;

    /// @dev Constructor that initializes the contract with the owner's address
    /// @param _owner The address of the owner who will have permission to set price feeds and manual prices
    constructor(address _owner) Ownable(_owner) { }

    /// @inheritdoc IOracleAdapter
    function setPriceFeeds(address[] calldata tokens, address[] calldata feeds, uint256[] calldata heartbeat)
        external
        onlyOwner
    {
        require(tokens.length == feeds.length && tokens.length == heartbeat.length, Errors.LengthMismatch());
        for (uint256 i; i < tokens.length; i++) {
            address token = tokens[i];

            require(token != address(0) && feeds[i] != address(0), Errors.ZeroAddress());
            require(heartbeat[i] != 0, Errors.ZeroAmount());

            priceFeeds[token] = feeds[i];
            heartbeats[token] = heartbeat[i];
        }

        emit PriceFeedSet(tokens, feeds, heartbeat);
    }

    /// @inheritdoc IOracleAdapter
    function setManualPrice(address token, uint256 price) external onlyOwner {
        require(token != address(0), Errors.ZeroAddress());
        require(price != 0, Errors.ZeroAmount());

        uint256 lastUpdated = manualLastUpdated[token];
        require(block.timestamp >= lastUpdated + manualUpdateInterval, Errors.EarlyManualUpdate());

        manualPrices[token] = price;
        manualLastUpdated[token] = block.timestamp;

        emit ManualPriceUpdated(token, price, block.timestamp);
    }

    /// @inheritdoc IOracleAdapter
    function setManualUpdateInterval(uint256 interval) external onlyOwner {
        require(interval != 0, Errors.ZeroAmount());
        manualUpdateInterval = interval;
        emit ManualUpdateIntervalSet(interval, _msgSender());
    }

    /// @inheritdoc IOracleAdapter
    function getPriceInUSD(address token) external view returns (uint256 price) {
        if (token == Constants.USDC || token == Constants.USDT) return 1 ether;

        address feed = priceFeeds[token];
        if (feed != address(0)) {
            (, int256 answer,, uint256 updatedAt,) = AggregatorV3Interface(feed).latestRoundData();
            require(answer > 0, Errors.ZeroAmount());
            require(block.timestamp - updatedAt <= heartbeats[token], Errors.StalePriceFeed());

            uint8 feedDecimals = AggregatorV3Interface(feed).decimals();
            if (feedDecimals <= 18) price = uint256(answer) * (10 ** (18 - feedDecimals));
            else price = uint256(answer) / (10 ** (feedDecimals - 18));
        } else {
            require(manualPrices[token] != 0, Errors.ZeroAmount());
            require(block.timestamp - manualLastUpdated[token] <= manualUpdateInterval, Errors.StaleManualPrice());
            price = manualPrices[token];
        }
    }
}
"
    },
    "dependencies/@openzeppelin-contracts-5.4.0/access/Ownable.sol": {
      "content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)

pragma solidity ^0.8.20;

import {Context} from "../utils/Context.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * The initial owner is set to the address provided by the deployer. This can
 * later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable is Context {
    address private _owner;

    /**
     * @dev The caller account is not authorized to perform an operation.
     */
    error OwnableUnauthorizedAccount(address account);

    /**
     * @dev The owner is not a valid owner account. (eg. `address(0)`)
     */
    error OwnableInvalidOwner(address owner);

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the address provided by the deployer as the initial owner.
     */
    constructor(address initialOwner) {
        if (initialOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(initialOwner);
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        if (owner() != _msgSender()) {
            revert OwnableUnauthorizedAccount(_msgSender());
        }
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby disabling any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _transferOwnership(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        if (newOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}
"
    },
    "dependencies/@chainlink-contracts-0.8.0/src/v0.8/interfaces/AggregatorV3Interface.sol": {
      "content": "// 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);
}
"
    },
    "src/interfaces/IOracleAdapter.sol": {
      "content": "// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.29;

/// @title The IOracleAdapter interface
/// @notice The interface for the OracleAdapter contract that manages price feeds for tokens
/// @dev This interface allows the owner to set price feeds and retrieve token prices in USD
interface IOracleAdapter {
    /// @dev The event is triggered whenever a price feed is set for a token
    /// @param token The array of the token addresses for which the price feed is set
    /// @param feed The array of the Chainlink price feed addresses for the token
    /// @param heartbeat The array of the heartbeats threshold in seconds for the price feed
    event PriceFeedSet(address[] token, address[] feed, uint256[] heartbeat);

    /// @dev The event is triggered whenever a manual price is set for a token
    /// @param token The address of the token for which the manual price is set
    /// @param price The price of the token in USD, scaled to 18 decimals
    /// @param lastUpdated The timestamp of the last manual price update
    event ManualPriceUpdated(address indexed token, uint256 price, uint256 lastUpdated);

    /// @dev The event is triggered whenever the manual update interval is set
    /// @param newInterval The new manual update interval in seconds
    /// @param admin The address of the admin who performed the update
    event ManualUpdateIntervalSet(uint256 newInterval, address indexed admin);

    /// @notice Sets the price feeds for the specific tokens that are used to get their prices in USD
    /// @param tokens The array of token addresses for which the price feeds are being set
    /// @param feeds The array of Chainlink price feed addresses corresponding to the tokens
    /// @param heartbeat The array of heartbeat thresholds in seconds for each price feed
    function setPriceFeeds(address[] calldata tokens, address[] calldata feeds, uint256[] calldata heartbeat)
        external;

    /// @notice Sets a manual price for a specific token
    /// @dev This function allows the owner to set a price for a token that may not have an active price feed
    /// @param token The address of the token for which the manual price is being set
    /// @param price The price of the token in USD, scaled to 18 decimals
    function setManualPrice(address token, uint256 price) external;

    /// @notice Sets the minimum interval between manual price updates for all tokens
    /// @dev This function allows the owner to set a cooldown period between manual updates
    /// @param interval The new manual update interval in seconds
    function setManualUpdateInterval(uint256 interval) external;

    /// @notice Retrieves the price of a specific token in USD using its Chainlink price feed
    /// @dev This function fetches the latest price from the Chainlink price feed and scales it to 18 decimals
    /// @param token The address of the token for which the price is being retrieved
    /// @return price The price of the token in USD, scaled to 18 decimals
    function getPriceInUSD(address token) external view returns (uint256 price);
}
"
    },
    "src/lib/Constants.sol": {
      "content": "// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.29;

/// @title Constants library
/// @notice This library contains constants for the core SCs
library Constants {
    /// @dev The maximum number of rounds allowed in the ICO sale
    uint256 public constant MAX_ROUNDS = 10;

    /// @notice The constant defining the hard cap in USD (normalized to 18 decimals)
    uint256 public constant HARD_CAP_USD = 5_565_000 * 1 ether;

    /// @notice The constant defining the maximum USD amount per wallet (normalized to 18 decimals)
    uint256 public constant MAX_USD_PER_WALLET = 50_000 * 1 ether;

    /// @dev The maximum referral percentage (10%)
    uint256 internal constant MAX_REFERRAL_PERCENTAGE = 1_000;
    /// @dev The divisor (10_000 - 100%) to calculate the percentage
    uint16 internal constant BASIS_FEE_DIVISOR = 10_000;

    /// @dev The typehash for the PurchaseDetails structure used in EIP-712 signatures
    bytes32 internal constant _REFERRAL_TYPEHASH = keccak256(
        "PurchaseDetails(bytes32 refCode,uint8 refType,address buyer,address asset,uint256 amount,uint256 roundId,uint256 nonce,uint256 deadline)"
    );

    /// @dev The address of the USDC token on Ethereum mainnet
    address internal constant USDC = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;
    /// @dev The address of the USDT token on Ethereum mainnet
    address internal constant USDT = 0xdAC17F958D2ee523a2206206994597C13D831ec7;
    /// @dev The address of the WETH token on Ethereum mainnet
    address internal constant WETH = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
}
"
    },
    "src/lib/Errors.sol": {
      "content": "// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.29;

/// @title Errors Library
/// @notice This library contains custom error definitions for the core SCs
library Errors {
    /// @dev The custom error for zero address inputs
    error ZeroAddress();
    /// @dev The custom error for input zero amount re purchase params
    error ZeroAmount();
    /// @dev The custom error for minimum amount violations
    error UnderMin();
    /// @dev The custom error for maximum amount violations - e.g. cap reached
    error CapReached();
    /// @dev The custom error for maximum amount violations - e.g. max allocation exceeded
    error HardCapExceeded();
    /// @dev The custom error for maximum wallet cap violations - e.g. max allocation per wallet exceeded
    error WalletCapExceeded();
    /// @dev The custom error for insufficient balance cases
    error InsufficientBalance();
    /// @dev The custom error for different lengths of arrays when they are expected to be the same
    error LengthMismatch();
    /// @dev The custom error for cases when the boolean indicator already set to expected value
    error IndicatorAlreadySet();
    /// @dev The custom error for early manual price updates
    error EarlyManualUpdate();
    /// @dev The custom error for stale manual price updates
    error StaleManualPrice();
    /// @dev The custom error for stale price feed updates
    error StalePriceFeed();
    /// @dev The custom error for incorrect timeframe inputs
    error InvalidTimeframe();
    /// @dev The custom error for invalid buyer bonus inputs
    error InvalidBuyerBonus();
    /// @dev The custom error for cases when the current round is active
    error ActiveRoundExists();
    /// @dev The custom error for cases when the current round is not active
    error InactiveRound();
    /// @dev The custom error for cases when the provided asset is not accepted for payment
    error NotAcceptedAsset();
    /// @dev The custom error for cases when the sale has not already been finalized
    error SaleNotFinished();
    /// @dev The custom error for cases when the sale has already been finalized
    error SaleAlreadyFinalized();
    /// @dev The custom error for cases when there are ongoing sale rounds
    error OngoingSaleRounds();
    /// @dev The custom error for cases when the provided referral type is invalid
    error InvalidReferralType();
    /// @dev The custom error for cases when the provided referral code is invalid
    error InvalidReferralCode();
    /// @dev The custom error for cases when the provided referral percentage is invalid
    error InvalidReferralPercentage();
    /// @dev The custom error for cases when the signature's deadline has expired
    error ExpiredSignature();
    /// @dev The custom error for cases when the signature is invalid
    error InvalidSignature();
    /// @dev The custom error for cases when the nonce does not match the expected value
    error NonceMismatch();
    /// @dev The custom error for cases when the buyer address does not match the caller's address
    error NotBuyer();
}
"
    },
    "dependencies/@openzeppelin-contracts-5.4.0/utils/Context.sol": {
      "content": "// 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;
    }
}
"
    }
  },
  "settings": {
    "remappings": [
      "@chainlink-contracts-0.8.0/=dependencies/@chainlink-contracts-0.8.0/",
      "@openzeppelin/contracts/=dependencies/@openzeppelin-contracts-5.4.0/",
      "forge-std/=dependencies/forge-std-1.10.0/src/",
      "@openzeppelin-contracts-5.4.0/=dependencies/@openzeppelin-contracts-5.4.0/",
      "erc4626-tests/=dependencies/openzeppelin-contracts/lib/erc4626-tests/",
      "forge-std-1.10.0/=dependencies/forge-std-1.10.0/src/",
      "halmos-cheatcodes/=dependencies/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
      "openzeppelin-contracts/=dependencies/openzeppelin-contracts/"
    ],
    "optimizer": {
      "enabled": true,
      "runs": 200
    },
    "metadata": {
      "useLiteralContent": false,
      "bytecodeHash": "none",
      "appendCBOR": true
    },
    "outputSelection": {
      "*": {
        "*": [
          "evm.bytecode",
          "evm.deployedBytecode",
          "devdoc",
          "userdoc",
          "metadata",
          "abi"
        ]
      }
    },
    "evmVersion": "cancun",
    "viaIR": true
  }
}}

Tags:
Multisig, Multi-Signature, Factory, Oracle|addr:0x9019d8fe45533a5ecfe5e43914651f805150fe30|verified:true|block:23732071|tx:0xac00d75cc38aefe0895509d8f4dda1b094784851645c9d4268000c429dbb1c14|first_check:1762347067

Submitted on: 2025-11-05 13:51:09

Comments

Log in to comment.

No comments yet.