@@ -11,7 +11,7 @@ use solana_program::{
1111use spl_associated_token_account:: get_associated_token_address;
1212
1313use crate :: {
14- get_seat_deposit_collector_address, get_seat_manager_address,
14+ get_authorized_delegate_pda , get_seat_deposit_collector_address, get_seat_manager_address,
1515 instruction:: SeatManagerInstruction ,
1616} ;
1717
@@ -319,3 +319,99 @@ pub fn create_confirm_renounce_seat_manager_authority_instruction(
319319 data : SeatManagerInstruction :: ConfirmRenounceSeatManagerAuthority . to_vec ( ) ,
320320 }
321321}
322+
323+ pub fn create_add_approved_evictor_instruction (
324+ authority : & Pubkey ,
325+ authorized_delegate : & Pubkey ,
326+ ) -> Instruction {
327+ let ( authorized_delegate_pda, _) = get_authorized_delegate_pda ( authority, authorized_delegate) ;
328+ Instruction {
329+ program_id : crate :: id ( ) ,
330+ accounts : vec ! [
331+ AccountMeta :: new( * authority, true ) ,
332+ AccountMeta :: new_readonly( * authorized_delegate, false ) ,
333+ AccountMeta :: new( authorized_delegate_pda, false ) ,
334+ ] ,
335+ data : SeatManagerInstruction :: AddApprovedEvictor . to_vec ( ) ,
336+ }
337+ }
338+
339+ pub fn create_remove_approved_evictor_instruction (
340+ authority : & Pubkey ,
341+ authorized_delegate : & Pubkey ,
342+ ) -> Instruction {
343+ let ( authorized_delegate_pda, _) = get_authorized_delegate_pda ( authority, authorized_delegate) ;
344+ Instruction {
345+ program_id : crate :: id ( ) ,
346+ accounts : vec ! [
347+ AccountMeta :: new( * authority, true ) ,
348+ AccountMeta :: new_readonly( * authorized_delegate, false ) ,
349+ AccountMeta :: new( authorized_delegate_pda, false ) ,
350+ ] ,
351+ data : SeatManagerInstruction :: RemoveApprovedEvictor . to_vec ( ) ,
352+ }
353+ }
354+
355+ pub fn create_evict_seat_with_authorized_delegate_instruction (
356+ market : & Pubkey ,
357+ base_mint : & Pubkey ,
358+ quote_mint : & Pubkey ,
359+ authorized_delegate : & Pubkey ,
360+ traders : Vec < EvictTraderAccountBackup > ,
361+ seat_manager_authority : & Pubkey ,
362+ ) -> Instruction {
363+ let ( base_vault, _) = get_vault_address ( market, base_mint) ;
364+ let ( quote_vault, _) = get_vault_address ( market, quote_mint) ;
365+ let ( seat_manager, _) = get_seat_manager_address ( market) ;
366+ let ( seat_deposit_collector, _) = get_seat_deposit_collector_address ( market) ;
367+
368+ let ( authorized_delegate_pda, _) =
369+ get_authorized_delegate_pda ( seat_manager_authority, authorized_delegate) ;
370+
371+ let mut accounts = vec ! [
372+ AccountMeta :: new_readonly( phoenix:: id( ) , false ) ,
373+ AccountMeta :: new_readonly( phoenix_log_authority:: id( ) , false ) ,
374+ AccountMeta :: new( * market, false ) ,
375+ AccountMeta :: new_readonly( seat_manager, false ) ,
376+ AccountMeta :: new( seat_deposit_collector, false ) ,
377+ AccountMeta :: new_readonly( * base_mint, false ) ,
378+ AccountMeta :: new_readonly( * quote_mint, false ) ,
379+ AccountMeta :: new( base_vault, false ) ,
380+ AccountMeta :: new( quote_vault, false ) ,
381+ AccountMeta :: new_readonly( spl_associated_token_account:: id( ) , false ) ,
382+ AccountMeta :: new_readonly( spl_token:: id( ) , false ) ,
383+ AccountMeta :: new_readonly( system_program:: id( ) , false ) ,
384+ AccountMeta :: new_readonly( * authorized_delegate, true ) ,
385+ AccountMeta :: new_readonly( authorized_delegate_pda, false ) ,
386+ ] ;
387+
388+ for trader_accounts in traders. iter ( ) {
389+ let base_account = get_associated_token_address ( & trader_accounts. trader_pubkey , base_mint) ;
390+ let quote_account =
391+ get_associated_token_address ( & trader_accounts. trader_pubkey , quote_mint) ;
392+ let ( seat, _) = get_seat_address ( market, & trader_accounts. trader_pubkey ) ;
393+ accounts. push ( AccountMeta :: new ( trader_accounts. trader_pubkey , false ) ) ;
394+ accounts. push ( AccountMeta :: new ( seat, false ) ) ;
395+ accounts. push ( AccountMeta :: new ( base_account, false ) ) ;
396+ accounts. push ( AccountMeta :: new ( quote_account, false ) ) ;
397+
398+ for backup_account in [
399+ trader_accounts. base_token_account_backup ,
400+ trader_accounts. quote_token_account_backup ,
401+ ]
402+ . iter ( )
403+ {
404+ if backup_account. is_some ( ) {
405+ accounts. push ( AccountMeta :: new ( backup_account. unwrap ( ) , false ) ) ;
406+ } else {
407+ accounts. push ( AccountMeta :: new_readonly ( Pubkey :: default ( ) , false ) ) ;
408+ }
409+ }
410+ }
411+
412+ Instruction {
413+ program_id : crate :: id ( ) ,
414+ accounts,
415+ data : SeatManagerInstruction :: EvictSeatWithAuthorizedDelegate . to_vec ( ) ,
416+ }
417+ }
0 commit comments