After reading: How to investigate access violation errors, I feel like this error is different from a variety of reasons:
- I'm modifying an existing (working) Anchor project, and strictly using less memory, therefore I find it unlikely that it is a stack overflow issue.
How might I debug this issue?
Is there anyway to get a line number when Solana is throwing this error?
The code for my program:
pub fn taker<'info>( ctx: Context<'_, '_, '_, 'info, Taker<'info>>, price: u64, amount: u64, is_bid: bool, market_index: u16, pos_limit: i64) -> Result<()> { let taker = ctx.accounts.user.load()?; let (base_init, _) = taker .get_perp_position(market_index) .map_or((0, 0), |p| (p.base_asset_amount, p.quote_asset_amount)); drop(taker); if is_bid && base_init + amount as i64 > pos_limit { return Err(ErrorCode::PosLimitBreached.into()) } if !is_bid && -base_init + amount as i64 > pos_limit { return Err(ErrorCode::PosLimitBreached.into()) } let order_params = OrderParams { order_type: OrderType::Limit, market_type: MarketType::Perp, direction: if is_bid { PositionDirection::Long } else { PositionDirection::Short }, user_order_id: 0, base_asset_amount: amount, price: price, market_index, reduce_only: false, post_only: PostOnlyParam::None, immediate_or_cancel: true, max_ts: None, trigger_price: None, trigger_condition: OrderTriggerCondition::Above, oracle_price_offset: None, auction_duration: None, auction_start_price: None, auction_end_price: None, }; place_and_take(&ctx, order_params)?; let taker = ctx.accounts.user.load()?; let (base_end, _) = taker .get_perp_position(order_params.market_index) .map_or((0, 0), |p| (p.base_asset_amount, p.quote_asset_amount)); if base_end == base_init { return Err(ErrorCode::NoFill.into()); } Ok(())}
This is a modified version of the original contract here:https://github.com/drift-labs/jit-proxy/blob/master/programs/jit-proxy/src/instructions/arb_perp.rs
I've modified this existing (deployed) contract that seems to work, so I assume I must've messed up somewhere. I'm still learning Rust, so would like to learn how to I can debug these issues in the future.
Any assistance would be greatly appreciated.