-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add get seat manager info * add psm claim and evict seat * add doc comments to claim and evict * update versions for SDK and PSM * check for market authority managed by PSM in get seat manager info * increment version
- Loading branch information
1 parent
c2ca8ab
commit 2c94ce1
Showing
8 changed files
with
185 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use ellipsis_client::EllipsisClient; | ||
use phoenix_sdk::utils::create_claim_seat_ix_if_needed; | ||
use solana_sdk::{pubkey::Pubkey, signer::Signer}; | ||
|
||
pub async fn process_claim_seat( | ||
client: &EllipsisClient, | ||
market_pubkey: &Pubkey, | ||
) -> anyhow::Result<()> { | ||
let claim_seat_ix = | ||
create_claim_seat_ix_if_needed(client, market_pubkey, &client.payer.pubkey()).await?; | ||
println!("Claiming seat for pubkey: {}", client.payer.pubkey()); | ||
|
||
if !claim_seat_ix.is_empty() { | ||
let tx = client.sign_send_instructions(claim_seat_ix, vec![]).await?; | ||
println!("Claim seat transaction: {}", tx); | ||
} else { | ||
println!("Seat already created for pubkey: {}", client.payer.pubkey()); | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use std::mem::size_of; | ||
|
||
use ellipsis_client::EllipsisClient; | ||
use phoenix::program::MarketHeader; | ||
use phoenix_sdk::utils::get_evictable_trader_ix; | ||
use phoenix_seat_manager::instruction_builders::{ | ||
create_evict_seat_instruction, EvictTraderAccountBackup, | ||
}; | ||
use solana_sdk::pubkey::Pubkey; | ||
|
||
pub async fn process_evict_seat( | ||
client: &EllipsisClient, | ||
market_pubkey: &Pubkey, | ||
trader_to_evict: &Option<Pubkey>, | ||
) -> anyhow::Result<()> { | ||
let market_bytes = client.get_account_data(market_pubkey).await?; | ||
let (header_bytes, _market_bytes) = market_bytes.split_at(size_of::<MarketHeader>()); | ||
let market_header = bytemuck::try_from_bytes::<MarketHeader>(header_bytes) | ||
.map_err(|e| anyhow::anyhow!("Error deserializing market header. Error: {:?}", e))?; | ||
|
||
let maybe_evict_trader_ix = if let Some(trader_pubkey) = trader_to_evict { | ||
let evict_trader_state = EvictTraderAccountBackup { | ||
trader_pubkey: *trader_pubkey, | ||
base_token_account_backup: None, | ||
quote_token_account_backup: None, | ||
}; | ||
Some(create_evict_seat_instruction( | ||
market_pubkey, | ||
&market_header.base_params.mint_key, | ||
&market_header.quote_params.mint_key, | ||
trader_pubkey, | ||
vec![evict_trader_state], | ||
)) | ||
} else { | ||
get_evictable_trader_ix(client, market_pubkey).await? | ||
}; | ||
|
||
if let Some(evict_trader_ix) = maybe_evict_trader_ix { | ||
println!("Evicting trader: {}", evict_trader_ix.accounts[13].pubkey); | ||
let tx = client | ||
.sign_send_instructions(vec![evict_trader_ix], vec![]) | ||
.await?; | ||
println!("Evict trader tx: {}", tx); | ||
} else { | ||
println!("Cannot evict a trader when the market's trader state is not full."); | ||
return Ok(()); | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use std::mem::size_of; | ||
|
||
use ellipsis_client::EllipsisClient; | ||
use phoenix::program::MarketHeader; | ||
use phoenix_seat_manager::{get_seat_manager_address, seat_manager::SeatManager}; | ||
use solana_sdk::pubkey::Pubkey; | ||
|
||
use crate::helpers::market_helpers::get_seat_manager_data_with_market; | ||
|
||
pub async fn process_get_seat_manager_info( | ||
client: &EllipsisClient, | ||
market_pubkey: &Pubkey, | ||
) -> anyhow::Result<()> { | ||
let seat_manager_address = get_seat_manager_address(market_pubkey).0; | ||
let market_data = client.get_account_data(market_pubkey).await?; | ||
let market_header = | ||
bytemuck::from_bytes::<MarketHeader>(market_data.split_at(size_of::<MarketHeader>()).0); | ||
if market_header.authority != seat_manager_address { | ||
println!( | ||
"Authority for Market {} is not the seat manager.", | ||
market_pubkey | ||
); | ||
println!("Market authority: {}", market_header.authority); | ||
println!("Seat manager address: {}", seat_manager_address); | ||
return Ok(()); | ||
} | ||
let seat_manager_info = get_seat_manager_data_with_market(client, market_pubkey).await?; | ||
print_seat_manager_struct(&seat_manager_info, &seat_manager_address); | ||
Ok(()) | ||
} | ||
|
||
pub fn print_seat_manager_struct(seat_manager: &SeatManager, seat_manager_pubkey: &Pubkey) { | ||
println!("Seat Manager Address: {}", seat_manager_pubkey); | ||
println!("SM Market: {}", seat_manager.market); | ||
println!("SM Authority: {}", seat_manager.authority); | ||
println!("SM Successor: {}", seat_manager.successor); | ||
println!( | ||
"Number of designated market makers: {}", | ||
seat_manager.num_makers | ||
); | ||
|
||
let dmms: Vec<&Pubkey> = seat_manager | ||
.designated_market_makers | ||
.iter() | ||
.filter(|&&dmm| dmm != Pubkey::default()) | ||
.collect(); | ||
if !dmms.is_empty() { | ||
println!("DMMs: {:?}", dmms); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters