MockStorkOracle
Inherits: IStorkOracle, Initializable, AccessControlUpgradeable, PausableUpgradeable
Title: MockStorkOracle
Author: Quantillon Labs
Mock oracle that implements IStorkOracle interface but uses mock data
Used for localhost testing - provides same interface as StorkOracle
Constants
EMERGENCY_ROLE
bytes32 public constant EMERGENCY_ROLE = keccak256("EMERGENCY_ROLE")
ORACLE_MANAGER_ROLE
bytes32 public constant ORACLE_MANAGER_ROLE = keccak256("ORACLE_MANAGER_ROLE")
MIN_EUR_USD_PRICE
uint256 public constant MIN_EUR_USD_PRICE = 0.5e18
MAX_EUR_USD_PRICE
uint256 public constant MAX_EUR_USD_PRICE = 2.0e18
MIN_USDC_USD_PRICE
uint256 public constant MIN_USDC_USD_PRICE = 0.95e18
MAX_USDC_USD_PRICE
uint256 public constant MAX_USDC_USD_PRICE = 1.05e18
MAX_PRICE_DEVIATION
uint256 public constant MAX_PRICE_DEVIATION = 500
MIN_BLOCKS_BETWEEN_UPDATES
uint256 public constant MIN_BLOCKS_BETWEEN_UPDATES = 1
State Variables
treasury
address public treasury
originalAdmin
address private originalAdmin
lastValidEurUsdPrice
uint256 public lastValidEurUsdPrice
lastValidUsdcUsdPrice
uint256 public lastValidUsdcUsdPrice
lastPriceUpdateBlock
uint256 public lastPriceUpdateBlock
circuitBreakerTriggered
bool public circuitBreakerTriggered
devModeEnabled
bool public devModeEnabled
Functions
constructor
Note: oz-upgrades-unsafe-allow: constructor
constructor() ;
initialize
Initializes the mock oracle
function initialize(
address admin,
address _storkFeedAddress,
bytes32 _eurUsdFeedId,
bytes32 _usdcUsdFeedId,
address _treasury
) external initializer;
Parameters
| Name | Type | Description |
|---|---|---|
admin | address | Admin address |
_storkFeedAddress | address | Mock Stork feed address (unused, kept for interface compatibility) |
_eurUsdFeedId | bytes32 | Mock EUR/USD feed ID (unused, kept for interface compatibility) |
_usdcUsdFeedId | bytes32 | Mock USDC/USD feed ID (unused, kept for interface compatibility) |
_treasury | address | Treasury address |
getEurUsdPrice
Gets the current EUR/USD price with validation
function getEurUsdPrice() external view override returns (uint256 price, bool isValid);
Returns
| Name | Type | Description |
|---|---|---|
price | uint256 | EUR/USD price in 18 decimals |
isValid | bool | True if price is valid and fresh |
getUsdcUsdPrice
Gets the current USDC/USD price with validation
function getUsdcUsdPrice() external view override returns (uint256 price, bool isValid);
Returns
| Name | Type | Description |
|---|---|---|
price | uint256 | USDC/USD price in 18 decimals |
isValid | bool | True if price is valid and fresh |
updateTreasury
Updates treasury address
function updateTreasury(address _treasury) external onlyRole(DEFAULT_ADMIN_ROLE);
Parameters
| Name | Type | Description |
|---|---|---|
_treasury | address | New treasury address |
unpause
Unpauses the contract
function unpause() external onlyRole(EMERGENCY_ROLE);
recoverETH
Recovers ETH sent to the contract
Only sends ETH to the original admin address to prevent arbitrary sends
function recoverETH() external onlyRole(DEFAULT_ADMIN_ROLE);
resetCircuitBreaker
Resets the circuit breaker
function resetCircuitBreaker() external onlyRole(EMERGENCY_ROLE);
triggerCircuitBreaker
Triggers the circuit breaker
function triggerCircuitBreaker() external onlyRole(EMERGENCY_ROLE);
pause
Pauses the contract
function pause() external onlyRole(EMERGENCY_ROLE);
receive
receive() external payable;
getOracleHealth
Mock implementation of getOracleHealth
function getOracleHealth() external view override returns (bool isHealthy, bool eurUsdFresh, bool usdcUsdFresh);
getEurUsdDetails
Mock implementation of getEurUsdDetails
function getEurUsdDetails()
external
view
override
returns (uint256 currentPrice, uint256 lastValidPrice, uint256 lastUpdate, bool isStale, bool withinBounds);
getOracleConfig
Mock implementation of getOracleConfig
function getOracleConfig()
external
view
override
returns (
uint256 minPrice,
uint256 maxPrice,
uint256 maxStaleness,
uint256 usdcTolerance,
bool circuitBreakerActive
);
getPriceFeedAddresses
Mock implementation of getPriceFeedAddresses
function getPriceFeedAddresses()
external
view
override
returns (address eurUsdFeedAddress, address usdcUsdFeedAddress, uint8 eurUsdDecimals, uint8 usdcUsdDecimals);
checkPriceFeedConnectivity
Mock implementation of checkPriceFeedConnectivity
function checkPriceFeedConnectivity()
external
view
override
returns (bool eurUsdConnected, bool usdcUsdConnected, uint80 eurUsdLatestRound, uint80 usdcUsdLatestRound);
updatePriceBounds
Mock implementation of updatePriceBounds
function updatePriceBounds(uint256 _minPrice, uint256 _maxPrice) external override onlyRole(ORACLE_MANAGER_ROLE);
updateUsdcTolerance
Mock implementation of updateUsdcTolerance
function updateUsdcTolerance(uint256 newToleranceBps) external override onlyRole(ORACLE_MANAGER_ROLE);
updatePriceFeeds
Mock implementation of updatePriceFeeds
function updatePriceFeeds(address _storkFeedAddress, bytes32 _eurUsdFeedId, bytes32 _usdcUsdFeedId)
external
view
override
onlyRole(ORACLE_MANAGER_ROLE);
recoverToken
Mock implementation of recoverToken
function recoverToken(address token, uint256 amount) external view override onlyRole(DEFAULT_ADMIN_ROLE);
setPrice
Set the EUR/USD price for testing purposes
Only available in mock oracle for testing
function setPrice(uint256 _price) external onlyRole(DEFAULT_ADMIN_ROLE);
Parameters
| Name | Type | Description |
|---|---|---|
_price | uint256 | The new EUR/USD price in 18 decimals |
setUsdcUsdPrice
Set the USDC/USD price for testing purposes
Only available in mock oracle for testing
function setUsdcUsdPrice(uint256 _price) external onlyRole(DEFAULT_ADMIN_ROLE);
Parameters
| Name | Type | Description |
|---|---|---|
_price | uint256 | The new USDC/USD price in 18 decimals |
setPrices
Set both EUR/USD and USDC/USD prices for testing purposes
Only available in mock oracle for testing
function setPrices(uint256 _eurUsdPrice, uint256 _usdcUsdPrice) external onlyRole(DEFAULT_ADMIN_ROLE);
Parameters
| Name | Type | Description |
|---|---|---|
_eurUsdPrice | uint256 | The new EUR/USD price in 18 decimals |
_usdcUsdPrice | uint256 | The new USDC/USD price in 18 decimals |
setDevMode
Toggles dev mode to disable spread deviation checks
DEV ONLY: When enabled, price deviation checks are skipped for testing
function setDevMode(bool enabled) external onlyRole(DEFAULT_ADMIN_ROLE);
Parameters
| Name | Type | Description |
|---|---|---|
enabled | bool | True to enable dev mode, false to disable |
Events
PriceDeviationDetected
event PriceDeviationDetected(uint256 newPrice, uint256 lastPrice, uint256 deviationBps, uint256 blockNumber);
CircuitBreakerTriggered
event CircuitBreakerTriggered(uint256 blockNumber, string reason);
CircuitBreakerReset
event CircuitBreakerReset(uint256 blockNumber);
ETHRecovered
event ETHRecovered(address indexed treasury, uint256 amount);
DevModeToggled
event DevModeToggled(bool enabled, address indexed caller);