Skip to content

Implement price publishing #118

@0x-r4bbit

Description

@0x-r4bbit

Implement the publish_price instruction. Computes the TWAP over a requested window from two Observation Account snapshots and writes the result to the Price Account.

twap_tick = (tick_cumulative[t2] - tick_cumulative[t1]) / (t2 - t1)
price = 1.0001 ^ twap_tick

This will need #117

  • Callable by anyone
  • t2 is always the most recent observation, t1 is the snapshot closest to now - window_length
  • Rejects zero and negative prices before writing to the Price Account
  • If the ring buffer does not contain a snapshot old enough to satisfy the requested window, the instruction returns an error rather than
    publishing a price based on a shorter window than requested
  • The window length is a parameter — different consumers can request different windows. This means multiple Price Accounts can exist for
    the same (base_asset, quote_asset) pair, one per window length. The Price Account PDA is derived from (oracle_program_id, base_asset,
    quote_asset, window_length, source_id)

Metadata

Metadata

Assignees

No one assigned

    Type

    No fields configured for Task.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions