StorkPrices

📄 View Source Code

Overview

StorkPrices integrates Stork Network's decentralized oracle infrastructure for reliable asset pricing. It leverages Stork's temporal data system with nanosecond-precision timestamps and pre-normalized 18-decimal values.

Key Capabilities:

  • Temporal Pricing: Nanosecond-precision timestamps for accurate staleness checks

  • Pre-Normalized Values: Native 18-decimal format eliminates conversion needs

  • Pull-Based Updates: On-demand price updates with automatic fee handling

  • Batch Operations: Update multiple feeds in single transaction for gas efficiency

The module implements direct integration with Stork V1 API, automatic fee calculation and payment, time-locked feed management, and support for up to 20 simultaneous price updates.

Architecture & Dependencies

StorkPrices is built using a modular architecture with direct Stork Network integration:

Core Module Dependencies

  • LocalGov: Provides governance functionality with access control

  • Addys: Address resolution for protocol contracts

  • PriceSourceData: Asset registration and pause state management

  • TimeLock: Time-locked changes for feed management

External Integration

  • Stork Network: Direct integration with Stork oracle contracts

  • Pull Oracle Model: Off-chain data brought on-chain as needed

  • V1 API: Uses Stork's first version temporal API

Module Initialization

Immutable Configuration

Data Structures

TemporalNumericValue Struct

Stork's price data format:

StorkFeedConfig Struct

Configuration for each asset's price feed:

PendingStorkFeed Struct

Tracks pending feed changes:

State Variables

Feed Configuration

  • feedConfig: HashMap[address, StorkFeedConfig] - Maps assets to Stork feed configurations

  • pendingUpdates: HashMap[address, PendingStorkFeed] - Pending changes

Constants

  • MAX_PRICE_UPDATES: constant(uint256) = 20 - Maximum batch updates

Inherited State

From modules:

  • Governance state (LocalGov)

  • Pause state and asset registry (PriceSourceData)

  • TimeLock configuration

System Architecture Diagram

Constructor

__init__

Initializes StorkPrices with governance settings and Stork Network address.

Parameters

Name
Type
Description

_ripeHq

address

RipeHq contract for protocol integration

_tempGov

address

Initial temporary governance address

_stork

address

Stork Network contract address

_minPriceChangeTimeLock

uint256

Minimum timelock for feed changes

_maxPriceChangeTimeLock

uint256

Maximum timelock for feed changes

Deployment Requirements

  • Stork Network address must not be empty

  • Contract requires ETH balance for update fees

Example Usage

Core Price Functions

getPrice

Retrieves the current price for an asset from Stork Network.

Parameters

Name
Type
Description

_asset

address

Asset to get price for

_staleTime

uint256

Maximum age for price data in seconds. The caller is responsible for providing this value. A value of 0 disables the staleness check for this call.

_priceDesk

address

Not used in Stork implementation

Returns

Type
Description

uint256

Quantized price value (0 if invalid)

Process Flow

  1. Feed Lookup: Gets Stork feed ID for asset

  2. Temporal Query: Calls getTemporalNumericValueUnsafeV1

  3. Validation: Checks quantizedValue != 0

  4. Time Conversion: Nanoseconds to seconds

  5. Staleness Check: Compare with block timestamp

Example Usage

getPriceAndHasFeed

Returns price and feed existence status.

Returns

Type
Description

uint256

Current price (0 if no feed)

bool

True if feed exists

Price Update Functions

updateStorkPrice

Brings fresh price data on-chain for configured feeds.

Parameters

Name
Type
Description

_payload

Bytes[2048]

Signed price update from Stork

Returns

Type
Description

bool

True if update successful

Process

  1. Fee Query: Gets required fee from Stork

  2. Balance Check: Ensures sufficient ETH

  3. Update Call: Submits payload with fee

  4. Event Logging: Records update details

Example Usage

updateManyStorkPrices

Updates multiple price feeds efficiently.

Parameters

Name
Type
Description

_payloads

DynArray[Bytes[2048], MAX_PRICE_UPDATES]

Up to 20 updates

Returns

Type
Description

uint256

Number of successful updates

Processes updates sequentially, stopping on first failure.

Feed Management Functions

addNewPriceFeed

Initiates addition of a new Stork price feed.

Parameters

Name
Type
Description

_asset

address

Asset to add price feed for

_feedId

bytes32

Stork Network feed identifier

_staleTime

uint256

Maximum age for price data in seconds (0 uses MissionControl default)

Access

Only callable by governance

Validation

  • Asset must not have existing feed

  • Feed must return valid temporal data

  • Asset address must be valid

Events Emitted

  • NewStorkFeedPending - Contains feed ID and timelock details

confirmNewPriceFeed

Confirms pending feed addition after timelock.

Process Flow

  1. Re-validation: Ensures feed still valid

  2. Timelock Check: Verifies time elapsed

  3. Configuration Save: Stores feed mapping

  4. Asset Registration: Adds to PriceSourceData

Events Emitted

  • NewStorkFeedAdded - Confirms feed activation

updatePriceFeed

Updates existing feed to new Stork feed ID.

Similar timelock process as additions.

disablePriceFeed

Removes a price feed from the system.

Also requires time-locked confirmation.

ETH Balance Management

recoverEthBalance

Withdraws ETH from contract.

Parameters

Name
Type
Description

_recipient

address

Address to receive ETH

Access

Only callable by governance

Used to recover excess ETH from update fees.

Temporal Data Handling

Timestamp Conversion

Stork uses nanosecond precision:

Benefits:

  • Microsecond accuracy for HFT

  • Precise event ordering

  • Institutional compatibility

Staleness Validation

Uses publish time for accurate staleness checks.

Validation Functions

isValidNewFeed

Validates new feed configuration.

Validation Checks

  1. No Existing Feed: Asset must be new

  2. Valid Address: Non-empty asset

  3. Feed Exists: Returns temporal data

  4. Has Timestamp: timestampNs != 0

isValidUpdateFeed

Additional checks for updates:

  • New feed must differ from current

  • Asset must have existing feed

isValidDisablePriceFeed

Ensures:

  • Feed exists for asset

  • Asset registered in PriceSourceData

Events

Feed Management Events

  • NewStorkFeedPending - New feed initiated

  • NewStorkFeedAdded - Feed confirmed

  • NewStorkFeedCancelled - Addition cancelled

  • StorkFeedUpdatePending - Update initiated

  • StorkFeedUpdated - Update confirmed

  • StorkFeedUpdateCancelled - Update cancelled

  • DisableStorkFeedPending - Removal initiated

  • StorkFeedDisabled - Feed removed

  • DisableStorkFeedCancelled - Removal cancelled

Operational Events

  • StorkPriceUpdated - Price update submitted

  • EthRecoveredFromStork - ETH withdrawn

All events include addresses, feed IDs, and action details.

Security Considerations

Access Control

  • Governance Only: Feed management restricted

  • Public Updates: Anyone can update (pays fee)

  • Time-locked Changes: Prevents hasty decisions

Data Integrity

  • Temporal Validation: Timestamp verification

  • Zero Value Check: Rejects invalid prices

  • Signature Verification: Handled by Stork

  • Gas Efficiency: Unsafe methods for views

Integration Safety

  • Simple Decimals: No conversion needed

  • Fee Management: Automatic calculation

  • Balance Protection: Checks before updates

  • Batch Limits: Maximum 20 updates

Common Integration Patterns

Automated Updates

Batch Processing

Feed Migration

Advantages of Stork Integration

Simplified Decimals

  • All values in 18 decimals

  • No conversion logic needed

  • Reduced complexity and gas costs

Nanosecond Precision

  • Ideal for high-frequency trading

  • Accurate event sequencing

  • Professional-grade timestamps

Efficient Updates

  • Pull-based model saves gas

  • Batch updates reduce costs

  • Pay only for what you use

Last updated