percli_program/instructions/
deposit.rs1use anchor_lang::prelude::*;
2
3use crate::error::{from_risk_error, PercolatorError};
4use crate::state::{engine_from_account_data, MARKET_ACCOUNT_SIZE};
5
6#[derive(Accounts)]
7pub struct Deposit<'info> {
8 #[account(mut)]
9 pub user: Signer<'info>,
10
11 #[account(
13 mut,
14 constraint = market.data_len() == MARKET_ACCOUNT_SIZE @ PercolatorError::AccountNotFound,
15 )]
16 pub market: UncheckedAccount<'info>,
17
18 pub system_program: Program<'info, System>,
19}
20
21pub fn handler(ctx: Context<Deposit>, account_idx: u16, amount: u128) -> Result<()> {
22 let market = &ctx.accounts.market;
23 let mut data = market.try_borrow_mut_data()?;
24
25 require!(&data[0..8] == b"percmrkt", PercolatorError::AccountNotFound);
27
28 let engine = engine_from_account_data(&mut data);
29 let oracle_price = engine.last_oracle_price;
30 let clock = Clock::get()?;
31
32 engine
33 .deposit(account_idx, amount, oracle_price, clock.slot)
34 .map_err(from_risk_error)?;
35
36 Ok(())
39}