@@ -9,7 +9,8 @@ use solana_program::{
99} ;
1010
1111use crate :: {
12- DelegateCpiArgs , ScheduleCommitCpiArgs , ScheduleCommitInstruction ,
12+ BookUpdate , DelegateCpiArgs , ScheduleCommitCpiArgs ,
13+ ScheduleCommitInstruction ,
1314} ;
1415
1516pub fn init_account_instruction (
@@ -30,6 +31,45 @@ pub fn init_account_instruction(
3031 )
3132}
3233
34+ pub fn init_order_book_instruction (
35+ payer : Pubkey ,
36+ order_book : Pubkey ,
37+ ) -> Instruction {
38+ let program_id = crate :: id ( ) ;
39+ let account_metas = vec ! [
40+ AccountMeta :: new( payer, true ) ,
41+ AccountMeta :: new( order_book, false ) ,
42+ //AccountMeta::new_readonly(system_program::id(), false),
43+ AccountMeta :: new_readonly( system_program:: id( ) , false ) ,
44+ ] ;
45+
46+ Instruction :: new_with_borsh (
47+ program_id,
48+ & ScheduleCommitInstruction :: InitOrderBook ,
49+ account_metas,
50+ )
51+ }
52+
53+ pub fn grow_order_book_instruction (
54+ payer : Pubkey ,
55+ order_book : Pubkey ,
56+ additional_space : u64 ,
57+ ) -> Instruction {
58+ let program_id = crate :: id ( ) ;
59+ let account_metas = vec ! [
60+ AccountMeta :: new( payer, true ) ,
61+ AccountMeta :: new( order_book, false ) ,
62+ //AccountMeta::new_readonly(system_program::id(), false),
63+ AccountMeta :: new_readonly( system_program:: id( ) , false ) ,
64+ ] ;
65+
66+ Instruction :: new_with_borsh (
67+ program_id,
68+ & ScheduleCommitInstruction :: GrowOrderBook ( additional_space) ,
69+ account_metas,
70+ )
71+ }
72+
3373pub fn init_payer_escrow ( payer : Pubkey ) -> [ Instruction ; 2 ] {
3474 let top_up_ix = dlp:: instruction_builder:: top_up_ephemeral_balance (
3575 payer,
@@ -53,9 +93,13 @@ pub fn init_payer_escrow(payer: Pubkey) -> [Instruction; 2] {
5393 [ top_up_ix, delegate_ix]
5494}
5595
56- pub fn delegate_account_cpi_instruction ( player : Pubkey ) -> Instruction {
96+ pub fn delegate_account_cpi_instruction (
97+ player : Pubkey ,
98+ user_seed : & [ u8 ] ,
99+ ) -> Instruction {
57100 let program_id = crate :: id ( ) ;
58- let ( pda, _) = pda_and_bump ( & player) ;
101+ let ( pda, _) =
102+ Pubkey :: find_program_address ( & [ user_seed, player. as_ref ( ) ] , & crate :: ID ) ;
59103
60104 let args = DelegateCpiArgs {
61105 valid_until : i64:: MAX ,
@@ -78,7 +122,11 @@ pub fn delegate_account_cpi_instruction(player: Pubkey) -> Instruction {
78122
79123 Instruction :: new_with_borsh (
80124 program_id,
81- & ScheduleCommitInstruction :: DelegateCpi ( args) ,
125+ & if user_seed == b"magic_schedule_commit" {
126+ ScheduleCommitInstruction :: DelegateCpi ( args)
127+ } else {
128+ ScheduleCommitInstruction :: DelegateOrderBook ( args)
129+ } ,
82130 account_metas,
83131 )
84132}
@@ -114,6 +162,45 @@ pub fn schedule_commit_cpi_instruction(
114162 )
115163}
116164
165+ pub fn update_order_book_instruction (
166+ payer : Pubkey ,
167+ order_book : Pubkey ,
168+ update : BookUpdate ,
169+ ) -> Instruction {
170+ let program_id = crate :: id ( ) ;
171+ let account_metas = vec ! [
172+ AccountMeta :: new( payer, true ) ,
173+ AccountMeta :: new( order_book, false ) ,
174+ ] ;
175+
176+ Instruction :: new_with_borsh (
177+ program_id,
178+ & ScheduleCommitInstruction :: UpdateOrderBook ( update) ,
179+ account_metas,
180+ )
181+ }
182+
183+ pub fn schedule_commit_diff_instruction_for_order_book (
184+ payer : Pubkey ,
185+ order_book : Pubkey ,
186+ magic_program_id : Pubkey ,
187+ magic_context_id : Pubkey ,
188+ ) -> Instruction {
189+ let program_id = crate :: id ( ) ;
190+ let account_metas = vec ! [
191+ AccountMeta :: new( payer, true ) ,
192+ AccountMeta :: new( order_book, false ) ,
193+ AccountMeta :: new( magic_context_id, false ) ,
194+ AccountMeta :: new_readonly( magic_program_id, false ) ,
195+ ] ;
196+
197+ Instruction :: new_with_borsh (
198+ program_id,
199+ & ScheduleCommitInstruction :: ScheduleCommitForOrderBook ,
200+ account_metas,
201+ )
202+ }
203+
117204pub fn schedule_commit_with_payer_cpi_instruction (
118205 payer : Pubkey ,
119206 magic_program_id : Pubkey ,
0 commit comments