dloom_flow/amm/instructions/
open_position.rs

1// FILE: programs/dloom_flow/src/instructions/open_amm_position.rs
2use crate::{
3    amm::{
4        state::{AmmPool, AmmPosition, FeePreference}, 
5    },
6};
7use anchor_lang::prelude::*;
8
9pub fn handle_open_amm_position(
10    ctx: Context<OpenAmmPosition>,
11    fee_preference: FeePreference,
12) -> Result<()> {
13    let position = &mut ctx.accounts.amm_position;
14    position.pool = ctx.accounts.amm_pool.key();
15    position.owner = ctx.accounts.owner.key();
16    position.lp_token_amount = 0;
17    position.fee_growth_snapshot_a = 0;
18    position.fee_growth_snapshot_b = 0;
19    position.fee_preference = fee_preference;
20
21    Ok(())
22}
23
24#[derive(Accounts)]
25pub struct OpenAmmPosition<'info> {
26    #[account(mut)]
27    pub owner: Signer<'info>,
28
29    #[account(
30        seeds = [b"amm_pool", amm_pool.token_a_mint.as_ref(), amm_pool.token_b_mint.as_ref()],
31        bump = amm_pool.bump
32    )]
33    pub amm_pool: Box<Account<'info, AmmPool>>,
34
35    #[account(
36        init,
37        payer = owner,
38        space = 8 + 32 + 32 + 8 + 16 + 16 + 1 + 16, // Extra space for new field and padding
39        seeds = [b"amm_position", owner.key().as_ref(), amm_pool.key().as_ref()],
40        bump
41    )]
42    pub amm_position: Box<Account<'info, AmmPosition>>,
43
44    pub system_program: Program<'info, System>,
45}