Blockchain / Global / Address

Contract

0x672C9E64950f70dc7Ea851267Fe4Db67F7f1d1F6

Balance
0 SOMI
Transactions sent
1
Type
Contract · 940 bytes of code

StaticPriceProvider Verified

Compiler
solc 0.8.28+commit.7893614a
Language
Solidity
Optimization
Yes, 200 runs
EVM version
paris
License
—
Verified
2026-10-12

contracts/PFP/StaticPriceProvider.sol

and 3 more files

Solidity
// SPDX-License-Identifier: Unlicensed
pragma solidity ^0.8.28;

import "@openzeppelin/contracts/access/Ownable.sol";
import "./IPriceProvider.sol";

/**
 * @title Static Price Provider
 * @notice A simple implementation of IPriceProvider that uses a static price
 * @dev This implementation allows for a static price with some validation logic
 */
contract StaticPriceProvider is IPriceProvider, Ownable {
  // The static price in wei
  uint256 private _price;

  // Maximum allowed price age in seconds
  uint256 public constant MAX_PRICE_AGE = 1 hours;

  // Maximum allowed price deviation percentage (in basis points, 100 = 1%)
  uint256 public constant MAX_PRICE_DEVIATION_BPS = 200; // 2%

  // Events
  event PriceUpdated(uint256 oldPrice, uint256 newPrice);

  // Custom errors
  error InvalidPrice();

  /**
   * @notice Initializes the Static Price Provider contract
   * @param initialPrice The initial price in wei
   */
  constructor(uint256 initialPrice) Ownable(msg.sender) {
    if (initialPrice == 0) revert InvalidPrice();
    _price = initialPrice;
  }

  /**
   * @notice Returns the current price in native tokens
   * @return The current price in wei
   */
  function currentPrice() external view override returns (uint256) {
    return _price;
  }

  /**
   * @notice Validates if a given price is still valid for minting
   * @param price The price to validate
   * @return True if the price is valid, false otherwise
   */
  function isPriceValid(uint256 price) external override returns (bool) {
    // Check if the price is within the allowed deviation range
    uint256 currentPriceValue = _price;
    uint256 maxDeviation = (currentPriceValue * MAX_PRICE_DEVIATION_BPS) /
      10000;

    bool isValid = (price >= currentPriceValue - maxDeviation &&
      price <= currentPriceValue + maxDeviation);

    return isValid;
  }

  /**
   * @notice Updates the static price
   * @param newPrice The new price in wei
   * @dev Only the owner can call this function
   */
  function setPrice(uint256 newPrice) external onlyOwner {
    if (newPrice == 0) revert InvalidPrice();

    uint256 oldPrice = _price;
    _price = newPrice;

    emit PriceUpdated(oldPrice, newPrice);
  }
}

Other files

  • @openzeppelin/contracts/access/Ownable.sol
    // 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);
        }
    }
    
  • @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;
        }
    }
    
  • contracts/PFP/IPriceProvider.sol
    // SPDX-License-Identifier: Unlicensed
    pragma solidity ^0.8.28;
    
    /**
     * @title Price Provider Interface
     * @notice Interface for contracts that provide pricing information for minting
     * @dev Implementations should handle price calculations and validations
     */
    interface IPriceProvider {
        /**
         * @notice Returns the current price in native tokens
         * @return The current price in wei
         * @dev This is a view function that returns the current price
         */
        function currentPrice() external view returns (uint256);
        
        /**
         * @notice Validates if a given price is still valid for minting
         * @param price The price to validate
         * @return True if the price is valid, false otherwise
         * @dev This is not a view function as it may update state to track price fluctuations
         */
        function isPriceValid(uint256 price) external returns (bool);
    }
ABI · 14 entries
json
[
  {
    "type": "constructor",
    "inputs": [
      {
        "name": "initialPrice",
        "type": "uint256",
        "internalType": "uint256"
      }
    ],
    "stateMutability": "nonpayable"
  },
  {
    "name": "InvalidPrice",
    "type": "error",
    "inputs": []
  },
  {
    "name": "OwnableInvalidOwner",
    "type": "error",
    "inputs": [
      {
        "name": "owner",
        "type": "address",
        "internalType": "address"
      }
    ]
  },
  {
    "name": "OwnableUnauthorizedAccount",
    "type": "error",
    "inputs": [
      {
        "name": "account",
        "type": "address",
        "internalType": "address"
      }
    ]
  },
  {
    "name": "OwnershipTransferred",
    "type": "event",
    "inputs": [
      {
        "name": "previousOwner",
        "type": "address",
        "indexed": true,
        "internalType": "address"
      },
      {
        "name": "newOwner",
        "type": "address",
        "indexed": true,
        "internalType": "address"
      }
    ],
    "anonymous": false
  },
  {
    "name": "PriceUpdated",
    "type": "event",
    "inputs": [
      {
        "name": "oldPrice",
        "type": "uint256",
        "indexed": false,
        "internalType": "uint256"
      },
      {
        "name": "newPrice",
        "type": "uint256",
        "indexed": false,
        "internalType": "uint256"
      }
    ],
    "anonymous": false
  },
  {
    "name": "MAX_PRICE_AGE",
    "type": "function",
    "inputs": [],
    "outputs": [
      {
        "name": "",
        "type": "uint256",
        "internalType": "uint256"
      }
    ],
    "stateMutability": "view"
  },
  {
    "name": "MAX_PRICE_DEVIATION_BPS",
    "type": "function",
    "inputs": [],
    "outputs": [
      {
        "name": "",
        "type": "uint256",
        "internalType": "uint256"
      }
    ],
    "stateMutability": "view"
  },
  {
    "name": "currentPrice",
    "type": "function",
    "inputs": [],
    "outputs": [
      {
        "name": "",
        "type": "uint256",
        "internalType": "uint256"
      }
    ],
    "stateMutability": "view"
  },
  {
    "name": "isPriceValid",
    "type": "function",
    "inputs": [
      {
        "name": "price",
        "type": "uint256",
        "internalType": "uint256"
      }
    ],
    "outputs": [
      {
        "name": "",
        "type": "bool",
        "internalType": "bool"
      }
    ],
    "stateMutability": "nonpayable"
  },
  {
    "name": "owner",
    "type": "function",
    "inputs": [],
    "outputs": [
      {
        "name": "",
        "type": "address",
        "internalType": "address"
      }
    ],
    "stateMutability": "view"
  },
  {
    "name": "renounceOwnership",
    "type": "function",
    "inputs": [],
    "outputs": [],
    "stateMutability": "nonpayable"
  },
  {
    "name": "setPrice",
    "type": "function",
    "inputs": [
      {
        "name": "newPrice",
        "type": "uint256",
        "internalType": "uint256"
      }
    ],
    "outputs": [],
    "stateMutability": "nonpayable"
  },
  {
    "name": "transferOwnership",
    "type": "function",
    "inputs": [
      {
        "name": "newOwner",
        "type": "address",
        "internalType": "address"
      }
    ],
    "outputs": [],
    "stateMutability": "nonpayable"
  }
]

Send feedback

Agents: POST the same to /api/feedback.