feat(programs/amm): add swap exact output functionality

This commit is contained in:
Andrea Franz
2026-04-02 16:10:12 +02:00
committed by r4bbit
parent 3e24ae2736
commit 9a6ec0018b
6 changed files with 810 additions and 78 deletions
+20 -1
View File
@@ -119,7 +119,7 @@ fn main() {
} => {
let [pool, vault_a, vault_b, user_holding_a, user_holding_b] = pre_states
.try_into()
.expect("Transfer instruction requires exactly five accounts");
.expect("Swap instruction requires exactly five accounts");
amm_program::swap::swap(
pool,
vault_a,
@@ -131,6 +131,25 @@ fn main() {
token_definition_id_in,
)
}
Instruction::SwapExactOutput {
exact_amount_out,
max_amount_in,
token_definition_id_in,
} => {
let [pool, vault_a, vault_b, user_holding_a, user_holding_b] = pre_states
.try_into()
.expect("SwapExactOutput instruction requires exactly five accounts");
amm_program::swap::swap_exact_output(
pool,
vault_a,
vault_b,
user_holding_a,
user_holding_b,
exact_amount_out,
max_amount_in,
token_definition_id_in,
)
}
};
ProgramOutput::new(instruction_words, pre_states_clone, post_states)