mirror of
https://github.com/logos-blockchain/lez-programs.git
synced 2026-07-03 05:29:50 +00:00
refactor(twap_oracle): match instruction function order to Instruction enum
`idl-gen` emits IDL instructions in source order, and `spel` uses each instruction's IDL position as its serde variant index. When the `#[instruction]` function order diverges from the `twap_oracle_core::Instruction` enum order, spel addresses the wrong instruction. Move `update_current_tick` ahead of the TWAP-computation instruction so the function order in twap_oracle.rs lines up with the enum variant order, and regenerate artifacts/twap_oracle-idl.json to match. No behavioral change — the instruction bodies are unchanged, only reordered.
This commit is contained in:
parent
4cd7c074f1
commit
51debb9de4
@ -105,6 +105,35 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "update_current_tick",
|
||||
"accounts": [
|
||||
{
|
||||
"name": "current_tick_account",
|
||||
"writable": true,
|
||||
"signer": false,
|
||||
"init": false
|
||||
},
|
||||
{
|
||||
"name": "price_source",
|
||||
"writable": false,
|
||||
"signer": true,
|
||||
"init": false
|
||||
},
|
||||
{
|
||||
"name": "clock",
|
||||
"writable": false,
|
||||
"signer": false,
|
||||
"init": false
|
||||
}
|
||||
],
|
||||
"args": [
|
||||
{
|
||||
"name": "price",
|
||||
"type": "u128"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "publish_price",
|
||||
"accounts": [
|
||||
@ -176,35 +205,6 @@
|
||||
"type": "u64"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "update_current_tick",
|
||||
"accounts": [
|
||||
{
|
||||
"name": "current_tick_account",
|
||||
"writable": true,
|
||||
"signer": false,
|
||||
"init": false
|
||||
},
|
||||
{
|
||||
"name": "price_source",
|
||||
"writable": false,
|
||||
"signer": true,
|
||||
"init": false
|
||||
},
|
||||
{
|
||||
"name": "clock",
|
||||
"writable": false,
|
||||
"signer": false,
|
||||
"init": false
|
||||
}
|
||||
],
|
||||
"args": [
|
||||
{
|
||||
"name": "price",
|
||||
"type": "u128"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"accounts": [
|
||||
|
||||
@ -111,6 +111,34 @@ mod twap_oracle {
|
||||
Ok(spel_framework::SpelOutput::execute(post_states, vec![]))
|
||||
}
|
||||
|
||||
/// Updates the tick stored in an existing current tick account.
|
||||
///
|
||||
/// Expected accounts:
|
||||
/// 1. `current_tick_account` — initialized PDA owned by this oracle program.
|
||||
/// 2. `price_source` — account the caller controls (proven via `is_authorized = true`).
|
||||
/// 3. `clock` — read-only LEZ clock account.
|
||||
///
|
||||
/// `price` is a `Q64.64` spot price; the oracle converts it to a tick.
|
||||
#[instruction]
|
||||
pub fn update_current_tick(
|
||||
ctx: ProgramContext,
|
||||
#[account(mut)]
|
||||
current_tick_account: AccountWithMetadata,
|
||||
#[account(signer)]
|
||||
price_source: AccountWithMetadata,
|
||||
clock: AccountWithMetadata,
|
||||
price: u128,
|
||||
) -> SpelResult {
|
||||
let post_states = twap_oracle_program::update_current_tick::update_current_tick(
|
||||
current_tick_account,
|
||||
price_source,
|
||||
clock,
|
||||
price,
|
||||
ctx.self_program_id,
|
||||
);
|
||||
Ok(spel_framework::SpelOutput::execute(post_states, vec![]))
|
||||
}
|
||||
|
||||
/// Computes the TWAP from the price observations ring buffer (extrapolated to `now` using the
|
||||
/// current tick) and writes it to the price account.
|
||||
///
|
||||
@ -169,32 +197,4 @@ mod twap_oracle {
|
||||
);
|
||||
Ok(spel_framework::SpelOutput::execute(post_states, vec![]))
|
||||
}
|
||||
|
||||
/// Updates the tick stored in an existing current tick account.
|
||||
///
|
||||
/// Expected accounts:
|
||||
/// 1. `current_tick_account` — initialized PDA owned by this oracle program.
|
||||
/// 2. `price_source` — account the caller controls (proven via `is_authorized = true`).
|
||||
/// 3. `clock` — read-only LEZ clock account.
|
||||
///
|
||||
/// `price` is a `Q64.64` spot price; the oracle converts it to a tick.
|
||||
#[instruction]
|
||||
pub fn update_current_tick(
|
||||
ctx: ProgramContext,
|
||||
#[account(mut)]
|
||||
current_tick_account: AccountWithMetadata,
|
||||
#[account(signer)]
|
||||
price_source: AccountWithMetadata,
|
||||
clock: AccountWithMetadata,
|
||||
price: u128,
|
||||
) -> SpelResult {
|
||||
let post_states = twap_oracle_program::update_current_tick::update_current_tick(
|
||||
current_tick_account,
|
||||
price_source,
|
||||
clock,
|
||||
price,
|
||||
ctx.self_program_id,
|
||||
);
|
||||
Ok(spel_framework::SpelOutput::execute(post_states, vec![]))
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user