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)
Implement the
publish_priceinstruction. Computes the TWAP over a requested window from two Observation Account snapshots and writes the result to the Price Account.This will need #117
publishing a price based on a shorter window than requested
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)