Skip to content

Commit aa57067

Browse files
authored
feat: Ticket 4.2 Pyth Oracle Integration (on-chain) (#66)
- Dynamic Pyth V2 price offset (48 + num x 96) - works on real feeds - Optional oracle in MatchOrdersAccounts - backward-compatible - Oracle price + timestamp cached to Market account - PMM effective price with clamped inventory skew [-100%%, +100%%] - 3 integration tests + 9 unit tests for oracle validation - Zero new crate deps, zero [patch] sections, zero clippy warnings
1 parent be6ca8d commit aa57067

5 files changed

Lines changed: 843 additions & 21 deletions

File tree

src/instruction.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -305,15 +305,22 @@ pub struct MatchOrdersAccounts<'a> {
305305
pub quote_vault: &'a AccountView,
306306
pub buyer_order: &'a AccountView,
307307
pub seller_order: &'a AccountView,
308+
pub oracle_price: Option<&'a AccountView>,
308309
}
309310

310311
impl<'a> TryFrom<&'a [AccountView]> for MatchOrdersAccounts<'a> {
311312
type Error = FluxDexError;
312313

313314
fn try_from(accounts: &'a [AccountView]) -> Result<Self, Self::Error> {
314-
if accounts.len() != 7 {
315-
return Err(FluxDexError::InvalidAccountCount);
316-
}
315+
// Accept 7 accounts (no oracle) or 8 accounts (with oracle).
316+
let oracle_price = if accounts.len() == 8 {
317+
Some(&accounts[7])
318+
} else {
319+
if accounts.len() != 7 {
320+
return Err(FluxDexError::InvalidAccountCount);
321+
}
322+
None
323+
};
317324

318325
let [
319326
crank_authority,
@@ -323,7 +330,7 @@ impl<'a> TryFrom<&'a [AccountView]> for MatchOrdersAccounts<'a> {
323330
quote_vault,
324331
buyer_order,
325332
seller_order,
326-
] = accounts
333+
] = &accounts[..7]
327334
else {
328335
return Err(FluxDexError::InvalidArgument);
329336
};
@@ -362,6 +369,7 @@ impl<'a> TryFrom<&'a [AccountView]> for MatchOrdersAccounts<'a> {
362369
quote_vault,
363370
buyer_order,
364371
seller_order,
372+
oracle_price,
365373
})
366374
}
367375
}

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use pinocchio::{AccountView, Address, ProgramResult, entrypoint};
55
pub mod error;
66
pub mod instruction;
77
pub mod magicblock;
8+
pub mod oracle;
89
pub mod pmm;
910
pub mod processor;
1011
pub mod state;

0 commit comments

Comments
 (0)