From 51debb9de4f7c0730a185d6f5685839b587315ec Mon Sep 17 00:00:00 2001 From: r4bbit <445106+0x-r4bbit@users.noreply.github.com> Date: Sun, 28 Jun 2026 23:07:47 +0200 Subject: [PATCH] refactor(twap_oracle): match instruction function order to Instruction enum MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `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. --- artifacts/twap_oracle-idl.json | 58 +++++++++---------- .../methods/guest/src/bin/twap_oracle.rs | 56 +++++++++--------- 2 files changed, 57 insertions(+), 57 deletions(-) diff --git a/artifacts/twap_oracle-idl.json b/artifacts/twap_oracle-idl.json index ef80f01..a89e854 100644 --- a/artifacts/twap_oracle-idl.json +++ b/artifacts/twap_oracle-idl.json @@ -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": [ diff --git a/programs/twap_oracle/methods/guest/src/bin/twap_oracle.rs b/programs/twap_oracle/methods/guest/src/bin/twap_oracle.rs index c138c78..1cdfdef 100644 --- a/programs/twap_oracle/methods/guest/src/bin/twap_oracle.rs +++ b/programs/twap_oracle/methods/guest/src/bin/twap_oracle.rs @@ -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![])) - } }