carbon_openbook_v2_decoder/instructions/
mod.rs

1use crate::PROGRAM_ID;
2
3use super::OpenbookV2Decoder;
4pub mod cancel_all_and_place_orders;
5pub mod cancel_all_orders;
6pub mod cancel_order;
7pub mod cancel_order_by_client_order_id;
8pub mod close_market;
9pub mod close_open_orders_account;
10pub mod close_open_orders_indexer;
11pub mod consume_events;
12pub mod consume_given_events;
13pub mod create_market;
14pub mod create_open_orders_account;
15pub mod create_open_orders_indexer;
16pub mod deposit;
17pub mod deposit_log_event;
18pub mod edit_order;
19pub mod edit_order_pegged;
20pub mod fill_log_event;
21pub mod market_meta_data_log_event;
22pub mod open_orders_position_log_event;
23pub mod place_order;
24pub mod place_order_pegged;
25pub mod place_orders;
26pub mod place_take_order;
27pub mod prune_orders;
28pub mod refill;
29pub mod set_delegate;
30pub mod set_delegate_log_event;
31pub mod set_market_expired;
32pub mod settle_funds;
33pub mod settle_funds_expired;
34pub mod settle_funds_log_event;
35pub mod stub_oracle_close;
36pub mod stub_oracle_create;
37pub mod stub_oracle_set;
38pub mod sweep_fees;
39pub mod sweep_fees_log_event;
40pub mod total_order_fill_event;
41
42#[derive(
43    carbon_core::InstructionType, serde::Serialize, serde::Deserialize, PartialEq, Debug, Clone,
44)]
45pub enum OpenbookV2Instruction {
46    CreateMarket(create_market::CreateMarket),
47    CloseMarket(close_market::CloseMarket),
48    CreateOpenOrdersIndexer(create_open_orders_indexer::CreateOpenOrdersIndexer),
49    CloseOpenOrdersIndexer(close_open_orders_indexer::CloseOpenOrdersIndexer),
50    CreateOpenOrdersAccount(create_open_orders_account::CreateOpenOrdersAccount),
51    CloseOpenOrdersAccount(close_open_orders_account::CloseOpenOrdersAccount),
52    PlaceOrder(place_order::PlaceOrder),
53    EditOrder(edit_order::EditOrder),
54    EditOrderPegged(edit_order_pegged::EditOrderPegged),
55    PlaceOrders(place_orders::PlaceOrders),
56    CancelAllAndPlaceOrders(cancel_all_and_place_orders::CancelAllAndPlaceOrders),
57    PlaceOrderPegged(place_order_pegged::PlaceOrderPegged),
58    PlaceTakeOrder(place_take_order::PlaceTakeOrder),
59    ConsumeEvents(consume_events::ConsumeEvents),
60    ConsumeGivenEvents(consume_given_events::ConsumeGivenEvents),
61    CancelOrder(cancel_order::CancelOrder),
62    CancelOrderByClientOrderId(cancel_order_by_client_order_id::CancelOrderByClientOrderId),
63    CancelAllOrders(cancel_all_orders::CancelAllOrders),
64    Deposit(deposit::Deposit),
65    Refill(refill::Refill),
66    SettleFunds(settle_funds::SettleFunds),
67    SettleFundsExpired(settle_funds_expired::SettleFundsExpired),
68    SweepFees(sweep_fees::SweepFees),
69    SetDelegate(set_delegate::SetDelegate),
70    SetMarketExpired(set_market_expired::SetMarketExpired),
71    PruneOrders(prune_orders::PruneOrders),
72    StubOracleCreate(stub_oracle_create::StubOracleCreate),
73    StubOracleClose(stub_oracle_close::StubOracleClose),
74    StubOracleSet(stub_oracle_set::StubOracleSet),
75    DepositLogEvent(deposit_log_event::DepositLogEvent),
76    FillLogEvent(fill_log_event::FillLogEvent),
77    MarketMetaDataLogEvent(market_meta_data_log_event::MarketMetaDataLogEvent),
78    TotalOrderFillEvent(total_order_fill_event::TotalOrderFillEvent),
79    SetDelegateLogEvent(set_delegate_log_event::SetDelegateLogEvent),
80    SettleFundsLogEvent(settle_funds_log_event::SettleFundsLogEvent),
81    SweepFeesLogEvent(sweep_fees_log_event::SweepFeesLogEvent),
82    OpenOrdersPositionLogEvent(open_orders_position_log_event::OpenOrdersPositionLogEvent),
83}
84
85impl carbon_core::instruction::InstructionDecoder<'_> for OpenbookV2Decoder {
86    type InstructionType = OpenbookV2Instruction;
87
88    fn decode_instruction(
89        &self,
90        instruction: &solana_instruction::Instruction,
91    ) -> Option<carbon_core::instruction::DecodedInstruction<Self::InstructionType>> {
92        if !instruction.program_id.eq(&PROGRAM_ID) {
93            return None;
94        }
95
96        carbon_core::try_decode_instructions!(instruction,
97            OpenbookV2Instruction::CreateMarket => create_market::CreateMarket,
98            OpenbookV2Instruction::CloseMarket => close_market::CloseMarket,
99            OpenbookV2Instruction::CreateOpenOrdersIndexer => create_open_orders_indexer::CreateOpenOrdersIndexer,
100            OpenbookV2Instruction::CloseOpenOrdersIndexer => close_open_orders_indexer::CloseOpenOrdersIndexer,
101            OpenbookV2Instruction::CreateOpenOrdersAccount => create_open_orders_account::CreateOpenOrdersAccount,
102            OpenbookV2Instruction::CloseOpenOrdersAccount => close_open_orders_account::CloseOpenOrdersAccount,
103            OpenbookV2Instruction::PlaceOrder => place_order::PlaceOrder,
104            OpenbookV2Instruction::EditOrder => edit_order::EditOrder,
105            OpenbookV2Instruction::EditOrderPegged => edit_order_pegged::EditOrderPegged,
106            OpenbookV2Instruction::PlaceOrders => place_orders::PlaceOrders,
107            OpenbookV2Instruction::CancelAllAndPlaceOrders => cancel_all_and_place_orders::CancelAllAndPlaceOrders,
108            OpenbookV2Instruction::PlaceOrderPegged => place_order_pegged::PlaceOrderPegged,
109            OpenbookV2Instruction::PlaceTakeOrder => place_take_order::PlaceTakeOrder,
110            OpenbookV2Instruction::ConsumeEvents => consume_events::ConsumeEvents,
111            OpenbookV2Instruction::ConsumeGivenEvents => consume_given_events::ConsumeGivenEvents,
112            OpenbookV2Instruction::CancelOrder => cancel_order::CancelOrder,
113            OpenbookV2Instruction::CancelOrderByClientOrderId => cancel_order_by_client_order_id::CancelOrderByClientOrderId,
114            OpenbookV2Instruction::CancelAllOrders => cancel_all_orders::CancelAllOrders,
115            OpenbookV2Instruction::Deposit => deposit::Deposit,
116            OpenbookV2Instruction::Refill => refill::Refill,
117            OpenbookV2Instruction::SettleFunds => settle_funds::SettleFunds,
118            OpenbookV2Instruction::SettleFundsExpired => settle_funds_expired::SettleFundsExpired,
119            OpenbookV2Instruction::SweepFees => sweep_fees::SweepFees,
120            OpenbookV2Instruction::SetDelegate => set_delegate::SetDelegate,
121            OpenbookV2Instruction::SetMarketExpired => set_market_expired::SetMarketExpired,
122            OpenbookV2Instruction::PruneOrders => prune_orders::PruneOrders,
123            OpenbookV2Instruction::StubOracleCreate => stub_oracle_create::StubOracleCreate,
124            OpenbookV2Instruction::StubOracleClose => stub_oracle_close::StubOracleClose,
125            OpenbookV2Instruction::StubOracleSet => stub_oracle_set::StubOracleSet,
126            OpenbookV2Instruction::DepositLogEvent => deposit_log_event::DepositLogEvent,
127            OpenbookV2Instruction::FillLogEvent => fill_log_event::FillLogEvent,
128            OpenbookV2Instruction::MarketMetaDataLogEvent => market_meta_data_log_event::MarketMetaDataLogEvent,
129            OpenbookV2Instruction::TotalOrderFillEvent => total_order_fill_event::TotalOrderFillEvent,
130            OpenbookV2Instruction::SetDelegateLogEvent => set_delegate_log_event::SetDelegateLogEvent,
131            OpenbookV2Instruction::SettleFundsLogEvent => settle_funds_log_event::SettleFundsLogEvent,
132            OpenbookV2Instruction::SweepFeesLogEvent => sweep_fees_log_event::SweepFeesLogEvent,
133            OpenbookV2Instruction::OpenOrdersPositionLogEvent => open_orders_position_log_event::OpenOrdersPositionLogEvent,
134        )
135    }
136}