Skip to content

Commit 38269e0

Browse files
Fix pinocchio::msg macro and unused Cargo.toml key
1 parent f10aadd commit 38269e0

8 files changed

Lines changed: 80 additions & 132 deletions

File tree

Cargo.lock

Lines changed: 24 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,3 @@ overflow-checks = true
4343
lto = "fat"
4444
codegen-units = 1
4545
opt-level = 3
46-
solana-address = { path = "./patched/solana-address" }

src/instruction.rs

Lines changed: 12 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,8 @@ impl<'a> TryFrom<&'a [AccountView]> for InitializeMarketAccounts<'a> {
6969
}
7070

7171
// 2. Extract by index - named vars for readability
72-
let [
73-
payer,
74-
market,
75-
base_vault,
76-
quote_vault,
77-
base_mint,
78-
quote_mint,
79-
system_program,
80-
token_program,
81-
associated_token_program,
82-
rent_sysvar,
83-
] = accounts
72+
let [payer, market, base_vault, quote_vault, base_mint, quote_mint, system_program, token_program, associated_token_program, rent_sysvar] =
73+
accounts
8474
else {
8575
return Err(FluxDexError::InvalidArgument);
8676
};
@@ -151,26 +141,13 @@ impl<'a> TryFrom<&'a [AccountView]> for PlaceOrderAccounts<'a> {
151141
Some(&accounts[12])
152142
} else {
153143
if accounts.len() != 12 {
154-
pinocchio::msg!("Invalid account length");
155144
return Err(FluxDexError::InvalidAccountCount);
156145
}
157146
None
158147
};
159148

160-
let [
161-
trader,
162-
market,
163-
order,
164-
trader_base_ata,
165-
trader_quote_ata,
166-
base_vault,
167-
quote_vault,
168-
base_mint,
169-
quote_mint,
170-
system_program,
171-
token_program,
172-
oracle_price,
173-
] = &accounts[..12]
149+
let [trader, market, order, trader_base_ata, trader_quote_ata, base_vault, quote_vault, base_mint, quote_mint, system_program, token_program, oracle_price] =
150+
&accounts[..12]
174151
else {
175152
return Err(FluxDexError::InvalidArgument);
176153
};
@@ -241,18 +218,8 @@ impl<'a> TryFrom<&'a [AccountView]> for CancelOrderAccounts<'a> {
241218
return Err(FluxDexError::InvalidAccountCount);
242219
}
243220

244-
let [
245-
trader,
246-
market,
247-
order,
248-
trader_base_ata,
249-
trader_quote_ata,
250-
base_vault,
251-
quote_vault,
252-
base_mint,
253-
quote_mint,
254-
token_program,
255-
] = accounts
221+
let [trader, market, order, trader_base_ata, trader_quote_ata, base_vault, quote_vault, base_mint, quote_mint, token_program] =
222+
accounts
256223
else {
257224
return Err(FluxDexError::InvalidArgument);
258225
};
@@ -320,16 +287,8 @@ impl<'a> TryFrom<&'a [AccountView]> for MatchOrdersAccounts<'a> {
320287
return Err(FluxDexError::InvalidAccountCount);
321288
}
322289

323-
let [
324-
crank_authority,
325-
market,
326-
orderbook,
327-
base_vault,
328-
quote_vault,
329-
buyer_order,
330-
seller_order,
331-
oracle_price,
332-
] = accounts
290+
let [crank_authority, market, orderbook, base_vault, quote_vault, buyer_order, seller_order, oracle_price] =
291+
accounts
333292
else {
334293
return Err(FluxDexError::InvalidArgument);
335294
};
@@ -393,17 +352,8 @@ impl<'a> TryFrom<&'a [AccountView]> for SettleTradeAccounts<'a> {
393352
return Err(FluxDexError::InvalidAccountCount);
394353
}
395354

396-
let [
397-
crank_authority,
398-
market,
399-
base_vault,
400-
quote_vault,
401-
buyer_token_account,
402-
seller_token_account,
403-
base_mint,
404-
quote_mint,
405-
token_program,
406-
] = accounts
355+
let [crank_authority, market, base_vault, quote_vault, buyer_token_account, seller_token_account, base_mint, quote_mint, token_program] =
356+
accounts
407357
else {
408358
return Err(FluxDexError::InvalidArgument);
409359
};
@@ -554,18 +504,8 @@ impl<'a> TryFrom<&'a [AccountView]> for DelegateOrderbookAccounts<'a> {
554504
return Err(FluxDexError::InvalidAccountCount);
555505
}
556506

557-
let [
558-
authority,
559-
market,
560-
orderbook,
561-
buffer,
562-
delegation_record,
563-
delegation_metadata,
564-
delegation_program,
565-
system_program,
566-
rent_sysvar,
567-
self_program,
568-
] = accounts
507+
let [authority, market, orderbook, buffer, delegation_record, delegation_metadata, delegation_program, system_program, rent_sysvar, self_program] =
508+
accounts
569509
else {
570510
return Err(FluxDexError::InvalidArgument);
571511
};

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#![deny(clippy::unwrap_used)]
22

3-
use pinocchio::{AccountView, Address, ProgramResult, entrypoint};
3+
use pinocchio::{entrypoint, AccountView, Address, ProgramResult};
44

55
pub mod error;
66
pub mod instruction;
7-
pub mod oracle;
87
pub mod magicblock;
8+
pub mod oracle;
99
pub mod pmm;
1010
pub mod processor;
1111
pub mod state;

src/magicblock.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use pinocchio::cpi::{Seed, Signer, invoke_signed};
1+
use pinocchio::cpi::{invoke_signed, Seed, Signer};
22
use pinocchio::instruction::{InstructionAccount, InstructionView};
3-
use pinocchio::sysvars::Sysvar;
43
use pinocchio::sysvars::rent::Rent;
4+
use pinocchio::sysvars::Sysvar;
55
use pinocchio::{AccountView, Address, ProgramResult};
66

77
/// MagicBlock Delegation Program ID (`DELeGGvXpWV2fqJUhqcF5ZSYMS4JTLjteaAMARRSaeSh`)

src/oracle.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/// Pyth Price Feed Oracle Validation Module
22
/// Validates SOL/USDC price feed from Pyth for on-chain order validation
3-
43
use pinocchio::AccountView;
54

65
/// Maximum acceptable confidence interval ratio: 5%
@@ -18,11 +17,11 @@ pub const PYTH_PRICE_TYPE: u8 = 3;
1817
/// Result of oracle price validation
1918
#[derive(Debug, Clone, Copy)]
2019
pub struct OraclePriceData {
21-
pub price: u64, // Price in quote currency (e.g., cents for USD)
22-
pub confidence: u64, // Standard deviation confidence interval
23-
pub publish_time: i64, // Unix timestamp when published
24-
pub exponent: i32, // Exponent for fixed-point representation
25-
pub is_valid: bool, // Whether price passed validation checks
20+
pub price: u64, // Price in quote currency (e.g., cents for USD)
21+
pub confidence: u64, // Standard deviation confidence interval
22+
pub publish_time: i64, // Unix timestamp when published
23+
pub exponent: i32, // Exponent for fixed-point representation
24+
pub is_valid: bool, // Whether price passed validation checks
2625
}
2726

2827
/// Validate Pyth price feed account
@@ -62,14 +61,13 @@ pub fn validate_pyth_price(
6261
// Parse price feed structure
6362
// For simplicity, we read the price components from known offsets
6463
// This is a simplified validation - production should use pyth-sdk
65-
64+
6665
// Offset 32: price (i64, little-endian)
6766
if data.len() < 40 {
6867
return None;
6968
}
7069
let price_bytes = [
71-
data[32], data[33], data[34], data[35],
72-
data[36], data[37], data[38], data[39],
70+
data[32], data[33], data[34], data[35], data[36], data[37], data[38], data[39],
7371
];
7472
let price = i64::from_le_bytes(price_bytes) as u64;
7573

@@ -78,8 +76,7 @@ pub fn validate_pyth_price(
7876
return None;
7977
}
8078
let confidence_bytes = [
81-
data[40], data[41], data[42], data[43],
82-
data[44], data[45], data[46], data[47],
79+
data[40], data[41], data[42], data[43], data[44], data[45], data[46], data[47],
8380
];
8481
let confidence = u64::from_le_bytes(confidence_bytes);
8582

@@ -88,8 +85,7 @@ pub fn validate_pyth_price(
8885
return None;
8986
}
9087
let publish_time_bytes = [
91-
data[48], data[49], data[50], data[51],
92-
data[52], data[53], data[54], data[55],
88+
data[48], data[49], data[50], data[51], data[52], data[53], data[54], data[55],
9389
];
9490
let publish_time = i64::from_le_bytes(publish_time_bytes);
9591

@@ -102,7 +98,7 @@ pub fn validate_pyth_price(
10298

10399
// Validate confidence ratio: conf / price < 5%
104100
let confidence_ratio = if price > 0 {
105-
(confidence * 10000) / price // basis points
101+
(confidence * 10000) / price // basis points
106102
} else {
107103
10000 // invalid if price is 0
108104
};

0 commit comments

Comments
 (0)