MCPcopy Create free account
hub / github.com/Bonfida/dex-v4 / process

Function process

program/src/processor/create_market.rs:112–209  ·  view source on GitHub ↗
(
    program_id: &Pubkey,
    accounts: &[AccountInfo],
    instruction_data: &[u8],
)

Source from the content-addressed store, hash-verified

110}
111
112pub(crate) fn process(
113 program_id: &Pubkey,
114 accounts: &[AccountInfo],
115 instruction_data: &[u8],
116) -> ProgramResult {
117 let accounts = Accounts::parse(program_id, accounts)?;
118
119 check_rent(&accounts)?;
120
121 let Params {
122 signer_nonce,
123 min_base_order_size,
124 tick_size,
125 base_currency_multiplier,
126 quote_currency_multiplier,
127 } = try_from_bytes(instruction_data).map_err(|_| ProgramError::InvalidInstructionData)?;
128
129 if base_currency_multiplier == &0 || quote_currency_multiplier == &0 || tick_size == &0 {
130 msg!("The currency multipliers and ticksize should be nonzero!");
131 return Err(ProgramError::InvalidArgument);
132 }
133
134 let market_signer = Pubkey::create_program_address(
135 &[&accounts.market.key.to_bytes(), &[*signer_nonce as u8]],
136 program_id,
137 )?;
138 let base_mint = check_vault_account_and_get_mint(accounts.base_vault, &market_signer)?;
139 let quote_mint = check_vault_account_and_get_mint(accounts.quote_vault, &market_signer)?;
140
141 #[cfg(not(feature = "disable-mpl-checks"))]
142 check_metadata_account(accounts.token_metadata, &base_mint)?;
143
144 let current_timestamp = Clock::get()?.unix_timestamp;
145 if accounts.market.data.borrow()[0] != AccountTag::Uninitialized as u8 {
146 // Checking the first byte is sufficient as there is a small number of AccountTags
147 msg!("The market account contains initialized state!");
148 return Err(ProgramError::InvalidArgument);
149 }
150
151 let mut market_state = DexState::get_unchecked(accounts.market);
152
153 let royalties_bps = if accounts.token_metadata.data_len() != 0 {
154 let metadata: Metadata = Metadata::from_account_info(accounts.token_metadata)?;
155 if let Some(creators) = &metadata.data.creators {
156 #[cfg(not(feature = "disable-mpl-checks"))]
157 verify_metadata(creators)?;
158 metadata.data.seller_fee_basis_points
159 } else {
160 0
161 }
162 } else {
163 0
164 };
165
166 *market_state = DexState {
167 tag: AccountTag::DexState as u64,
168 signer_nonce: *signer_nonce as u8,
169 base_mint,

Callers

nothing calls this directly

Calls 4

check_rentFunction · 0.85
check_metadata_accountFunction · 0.85
verify_metadataFunction · 0.85

Tested by

no test coverage detected