percli_chain/commands/
deploy.rs1use anyhow::{bail, Result};
2use solana_sdk::pubkey::Pubkey;
3
4use crate::config::ChainConfig;
5use crate::ix::{self, InitializeMarketArgs, RiskParamsInput};
6use crate::rpc::ChainRpc;
7
8pub fn run(
9 config: &ChainConfig,
10 mint: &Pubkey,
11 oracle: &Pubkey,
12 matcher: &Pubkey,
13 init_oracle_price: u64,
14) -> Result<()> {
15 let rpc = ChainRpc::new(&config.rpc_url);
16 let (market_pda, _bump) = config.market_pda();
17 let (vault_pda, _) = config.vault_pda();
18
19 if rpc.account_exists(&market_pda)? {
20 bail!("Market already exists at {market_pda}");
21 }
22
23 let slot = rpc.get_slot()?;
24
25 let params = RiskParamsInput {
27 warmup_period_slots: 0,
28 maintenance_margin_bps: 500,
29 initial_margin_bps: 1000,
30 trading_fee_bps: 10,
31 max_accounts: 4096,
32 new_account_fee: 0,
33 maintenance_fee_per_slot: 0,
34 max_crank_staleness_slots: 100,
35 liquidation_fee_bps: 50,
36 liquidation_fee_cap: 1_000_000,
37 min_liquidation_abs: 100,
38 min_initial_deposit: 1000,
39 min_nonzero_mm_req: 100,
40 min_nonzero_im_req: 200,
41 insurance_floor: 0,
42 };
43
44 let args = InitializeMarketArgs {
45 init_slot: slot,
46 init_oracle_price,
47 params,
48 };
49
50 let ix = ix::initialize_market_ix(
51 &config.program_id,
52 &market_pda,
53 &config.authority(),
54 mint,
55 &vault_pda,
56 oracle,
57 matcher,
58 &spl_token::id(),
59 args,
60 );
61
62 println!("Deploying market...");
63 println!(" Authority: {}", config.authority());
64 println!(" Market PDA: {market_pda}");
65 println!(" Vault PDA: {vault_pda}");
66 println!(" Mint: {mint}");
67 println!(" Oracle: {oracle}");
68 println!(" Matcher: {matcher}");
69 println!(" RPC: {}", config.rpc_url);
70
71 let sig = rpc.send_tx(&[ix], &config.keypair)?;
72 println!(" Tx: {sig}");
73 println!("Market deployed.");
74
75 Ok(())
76}