2025-11-14 20:59:42 -05:00
|
|
|
use nssa_core::{
|
|
|
|
|
account::{Account, AccountId, AccountWithMetadata, Data},
|
2025-12-18 18:45:57 -05:00
|
|
|
program::{
|
|
|
|
|
AccountPostState, ChainedCall, PdaSeed, ProgramId, ProgramInput, read_nssa_inputs,
|
|
|
|
|
write_nssa_outputs_with_chained_call,
|
|
|
|
|
},
|
2025-11-14 20:59:42 -05:00
|
|
|
};
|
2026-01-22 20:48:05 -05:00
|
|
|
use amm_program::core::Instruction;
|
2025-11-14 20:59:42 -05:00
|
|
|
|
2025-11-25 23:06:47 -05:00
|
|
|
fn main() {
|
2025-12-18 18:45:57 -05:00
|
|
|
let (
|
|
|
|
|
ProgramInput {
|
|
|
|
|
pre_states,
|
|
|
|
|
instruction,
|
|
|
|
|
},
|
|
|
|
|
instruction_words,
|
|
|
|
|
) = read_nssa_inputs::<Instruction>();
|
|
|
|
|
|
2026-01-22 20:48:05 -05:00
|
|
|
let pre_states_clone = pre_states.clone();
|
2025-11-14 20:59:42 -05:00
|
|
|
|
2026-01-22 20:48:05 -05:00
|
|
|
let (post_states, chained_calls) = match instruction {
|
|
|
|
|
Intruction::NewAMM => {
|
2025-11-20 21:02:18 -05:00
|
|
|
|
2025-12-18 18:45:57 -05:00
|
|
|
}
|
2026-01-22 20:48:05 -05:00
|
|
|
Instruction::RemoveLiquidity{ remove_liquidity_amount, min_amount_to_remove_token_a, min_amount_to_remove_token_b } =>{
|
|
|
|
|
let [pool, vault_a, vault_b, pool_definition_lp, user_holding_a, user_holding_b, user_holding_lp] = pre_states
|
|
|
|
|
.try_into()
|
|
|
|
|
.expect("RemoveLiquidity instruction requires exactly seven accounts");
|
|
|
|
|
amm_program::remove::remove_liquidity(pool, vault_a, vault_b, pool_definition_lp, user_holding_a, user_holding_b, user_holding_lp, remove_liquidity_amount, min_amount_to_remove_token_a, min_amount_to_remove_token_b)
|
2025-12-18 18:45:57 -05:00
|
|
|
}
|
2026-01-22 20:48:05 -05:00
|
|
|
Instruction::AddLiquidity { min_amount_liquidity, max_amount_a, max_amount_b } => {
|
|
|
|
|
let [pool, vault_a, vault_b, pool_definition_lp, user_holding_a, user_holding_b, user_holding_lp] = pre_states
|
|
|
|
|
.try_into()
|
|
|
|
|
.expect("AddLiquidity instruction requires exactly seven accounts");
|
|
|
|
|
amm_program::add::add_liquidity(pool, vault_a, vault_b, pool_definition_lp, user_holding_a, user_holding_b, user_holding_lp, min_amount_liquidity, max_amount_a, max_amount_b)
|
2025-12-18 18:45:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-22 20:48:05 -05:00
|
|
|
write_nssa_outputs_with_chained_call(instruction_words, pre_states_clone, post_states, chained_calls);
|
|
|
|
|
}
|