Skip to content

Commit fe15646

Browse files
committed
feat(processor): implement Ticket 1.5 — instruction dispatcher + processor stubs
1 parent bd0fa3d commit fe15646

2 files changed

Lines changed: 112 additions & 5 deletions

File tree

src/lib.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,27 @@ use pinocchio::{AccountView, Address, ProgramResult, entrypoint};
55
pub mod error;
66
pub mod instruction;
77
pub mod pmm;
8+
pub mod processor;
89
pub mod state;
910

11+
use instruction::*;
12+
1013
entrypoint!(process_instruction);
1114

1215
pub fn process_instruction(
13-
_program_id: &Address,
14-
_accounts: &mut [AccountView],
15-
_instruction_data: &[u8],
16+
program_id: &Address,
17+
accounts: &mut [AccountView],
18+
instruction_data: &[u8],
1619
) -> ProgramResult {
17-
// TODO: Implement instruction dispatch in Ticket 1.5
18-
Err(pinocchio::error::ProgramError::InvalidInstructionData)
20+
match instruction_data.first() {
21+
Some(&INIT_MARKET) => processor::initialize_market(program_id, accounts, &instruction_data[1..]),
22+
Some(&PLACE_ORDER) => processor::place_order(program_id, accounts, &instruction_data[1..]),
23+
Some(&CANCEL_ORDER) => processor::cancel_order(program_id, accounts, &instruction_data[1..]),
24+
Some(&DELEGATE_ORDERBOOK) => processor::delegate_orderbook(program_id, accounts, &instruction_data[1..]),
25+
Some(&UNDELEGATE_ORDERBOOK) => processor::undelegate_orderbook(program_id, accounts, &instruction_data[1..]),
26+
Some(&UPDATE_ORDERBOOK) => processor::update_orderbook(program_id, accounts, &instruction_data[1..]),
27+
Some(&MATCH_ORDERS) => processor::match_orders(program_id, accounts, &instruction_data[1..]),
28+
Some(&SETTLE_TRADE) => processor::settle_trade(program_id, accounts, &instruction_data[1..]),
29+
_ => Err(pinocchio::error::ProgramError::InvalidInstructionData),
30+
}
1931
}

src/processor.rs

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// ============================================================
2+
// Module: processor
3+
// Handler stubs for all 8 FluxDEX instructions.
4+
// Ticket 2.x replaces each stub with full implementation.
5+
// ============================================================
6+
7+
use pinocchio::{AccountView, Address, ProgramResult};
8+
9+
/// Initialize a new market. (TDD §5, ticket 2.1)
10+
/// Account context: InitializeMarketAccounts (10 accounts)
11+
/// Args: InitializeMarketArgs
12+
pub fn initialize_market(
13+
_program_id: &Address,
14+
_accounts: &mut [AccountView],
15+
_instruction_data: &[u8],
16+
) -> ProgramResult {
17+
Ok(())
18+
}
19+
20+
/// Place a new order on the CLOB or PMM. (TDD §5, ticket 2.2)
21+
/// Account context: PlaceOrderAccounts (9 accounts)
22+
/// Args: PlaceOrderArgs
23+
pub fn place_order(
24+
_program_id: &Address,
25+
_accounts: &mut [AccountView],
26+
_instruction_data: &[u8],
27+
) -> ProgramResult {
28+
Ok(())
29+
}
30+
31+
/// Cancel an open order. (TDD §5, ticket 2.3)
32+
/// Account context: CancelOrderAccounts (8 accounts)
33+
/// Args: CancelOrderArgs
34+
pub fn cancel_order(
35+
_program_id: &Address,
36+
_accounts: &mut [AccountView],
37+
_instruction_data: &[u8],
38+
) -> ProgramResult {
39+
Ok(())
40+
}
41+
42+
/// Delegate the orderbook to a session key.(TDD §5, ticket 2.4)
43+
/// Account context: Market + signer
44+
/// Args: none
45+
pub fn delegate_orderbook(
46+
_program_id: &Address,
47+
_accounts: &mut [AccountView],
48+
_instruction_data: &[u8],
49+
) -> ProgramResult {
50+
Ok(())
51+
}
52+
53+
/// Undelegate the orderbook. (TDD §5, ticket 2.5)
54+
/// Account context: Market + signer
55+
/// Args: none
56+
pub fn undelegate_orderbook(
57+
_program_id: &Address,
58+
_accounts: &mut [AccountView],
59+
_instruction_data: &[u8],
60+
) -> ProgramResult {
61+
Ok(())
62+
}
63+
64+
/// Update the orderbook (diff from session).(TDD §5, ticket 2.6)
65+
/// Account context: Market + Orderbook
66+
/// Args: none
67+
pub fn update_orderbook(
68+
_program_id: &Address,
69+
_accounts: &mut [AccountView],
70+
_instruction_data: &[u8],
71+
) -> ProgramResult {
72+
Ok(())
73+
}
74+
75+
/// Match two orders on the orderbook. (TDD §5, ticket 2.7)
76+
/// Account context: MatchOrdersAccounts (7 accounts)
77+
/// Args: MatchOrdersArgs
78+
pub fn match_orders(
79+
_program_id: &Address,
80+
_accounts: &mut [AccountView],
81+
_instruction_data: &[u8],
82+
) -> ProgramResult {
83+
Ok(())
84+
}
85+
86+
/// Settle a filled trade. (TDD §5, ticket 2.8)
87+
/// Account context: SettleTradeAccounts (7 accounts)
88+
/// Args: SettleTradeArgs
89+
pub fn settle_trade(
90+
_program_id: &Address,
91+
_accounts: &mut [AccountView],
92+
_instruction_data: &[u8],
93+
) -> ProgramResult {
94+
Ok(())
95+
}

0 commit comments

Comments
 (0)