mirror of
https://github.com/logos-blockchain/lez-programs.git
synced 2026-06-10 10:19:26 +00:00
Adds the CreatePriceObservations instruction to the TWAP oracle program. The instruction initialises a PriceObservations PDA for a given price source account and time window, writing the initial tick and timestamp as the first entry. Key design decisions: - Per-window accounts: each (price_source, window_duration) pair maps to a distinct PriceObservations PDA. The window duration is baked into the PDA seed so a single price source can support multiple TWAP windows (24h, 7d, 30d) at independent sampling rates without sharing a buffer. - window_duration not stored on struct: it is implicit in the PDA address. Any reader that located the account already knows the window duration used to derive it. Storing it would be redundant. - Authorization is implicit: the PriceObservations PDA is derived from the price source account ID, so is_authorized = true on the price source proves the caller controls it without a redundant authority field. - Impersonation is prevented by the PDA check: passing a controlled price source with a victim's observations account ID fails immediately because the computed PDA (from the attacker's source) does not match. Closes #126
123 lines
2.4 KiB
JSON
123 lines
2.4 KiB
JSON
{
|
|
"version": "0.1.0",
|
|
"name": "twap_oracle",
|
|
"instructions": [
|
|
{
|
|
"name": "create_price_observations",
|
|
"accounts": [
|
|
{
|
|
"name": "price_observations",
|
|
"writable": false,
|
|
"signer": false,
|
|
"init": false
|
|
},
|
|
{
|
|
"name": "price_source",
|
|
"writable": false,
|
|
"signer": false,
|
|
"init": false
|
|
},
|
|
{
|
|
"name": "clock",
|
|
"writable": false,
|
|
"signer": false,
|
|
"init": false
|
|
}
|
|
],
|
|
"args": [
|
|
{
|
|
"name": "initial_tick",
|
|
"type": "i32"
|
|
},
|
|
{
|
|
"name": "window_duration",
|
|
"type": "u64"
|
|
}
|
|
]
|
|
}
|
|
],
|
|
"accounts": [
|
|
{
|
|
"name": "PriceObservations",
|
|
"type": {
|
|
"kind": "struct",
|
|
"fields": [
|
|
{
|
|
"name": "price_source_id",
|
|
"type": "account_id"
|
|
},
|
|
{
|
|
"name": "write_index",
|
|
"type": "u32"
|
|
},
|
|
{
|
|
"name": "total_entries",
|
|
"type": "u64"
|
|
},
|
|
{
|
|
"name": "last_recorded_tick",
|
|
"type": "i32"
|
|
},
|
|
{
|
|
"name": "entries",
|
|
"type": {
|
|
"vec": {
|
|
"defined": "ObservationEntry"
|
|
}
|
|
}
|
|
}
|
|
]
|
|
}
|
|
},
|
|
{
|
|
"name": "OraclePriceAccount",
|
|
"type": {
|
|
"kind": "struct",
|
|
"fields": [
|
|
{
|
|
"name": "base_asset",
|
|
"type": "account_id"
|
|
},
|
|
{
|
|
"name": "quote_asset",
|
|
"type": "account_id"
|
|
},
|
|
{
|
|
"name": "price",
|
|
"type": "u128"
|
|
},
|
|
{
|
|
"name": "timestamp",
|
|
"type": "u64"
|
|
},
|
|
{
|
|
"name": "source_id",
|
|
"type": "string"
|
|
},
|
|
{
|
|
"name": "confidence_interval",
|
|
"type": "u128"
|
|
}
|
|
]
|
|
}
|
|
}
|
|
],
|
|
"types": [
|
|
{
|
|
"name": "ObservationEntry",
|
|
"kind": "struct",
|
|
"fields": [
|
|
{
|
|
"name": "timestamp",
|
|
"type": "u64"
|
|
},
|
|
{
|
|
"name": "tick_cumulative",
|
|
"type": "i64"
|
|
}
|
|
]
|
|
}
|
|
],
|
|
"instruction_type": "twap_oracle_core::Instruction"
|
|
}
|