From 4419e1e9a004524728f5a31ba898363759de7439 Mon Sep 17 00:00:00 2001 From: Andrea Franz Date: Tue, 7 Apr 2026 09:31:32 +0200 Subject: [PATCH] chore(amm)!: rename Swap instruction to SwapExactInput Renames the Swap instruction and its guest handler to SwapExactInput to distinguish it from the newly added SwapExactOutput, and to make the intent of each variant explicit at the call site. BREAKING CHANGE: the Swap instruction variant and swap() function are renamed to SwapExactInput and swap_exact_input(). Callers must update instruction construction and any IDL-generated bindings. --- amm/amm-idl.json | 2 +- amm/core/src/lib.rs | 2 +- amm/methods/guest/src/bin/amm.rs | 4 ++-- amm/src/swap.rs | 2 +- amm/src/tests.rs | 20 ++++++++++---------- integration_tests/tests/amm.rs | 4 ++-- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/amm/amm-idl.json b/amm/amm-idl.json index a1ef5f9..ad83555 100644 --- a/amm/amm-idl.json +++ b/amm/amm-idl.json @@ -192,7 +192,7 @@ ] }, { - "name": "swap", + "name": "swap_exact_input", "accounts": [ { "name": "pool", diff --git a/amm/core/src/lib.rs b/amm/core/src/lib.rs index a883ed1..b1d00f0 100644 --- a/amm/core/src/lib.rs +++ b/amm/core/src/lib.rs @@ -78,7 +78,7 @@ pub enum Instruction { /// - User Holding Account for Token A /// - User Holding Account for Token B Either User Holding Account for Token A or Token B is /// authorized. - Swap { + SwapExactInput { swap_amount_in: u128, min_amount_out: u128, token_definition_id_in: AccountId, diff --git a/amm/methods/guest/src/bin/amm.rs b/amm/methods/guest/src/bin/amm.rs index dd77dab..b1a1c67 100644 --- a/amm/methods/guest/src/bin/amm.rs +++ b/amm/methods/guest/src/bin/amm.rs @@ -107,7 +107,7 @@ mod amm { /// Swap some quantity of tokens while maintaining the pool constant product. #[instruction] - pub fn swap( + pub fn swap_exact_input( pool: AccountWithMetadata, vault_a: AccountWithMetadata, vault_b: AccountWithMetadata, @@ -117,7 +117,7 @@ mod amm { min_amount_out: u128, token_definition_id_in: AccountId, ) -> SpelResult { - let (post_states, chained_calls) = amm_program::swap::swap( + let (post_states, chained_calls) = amm_program::swap::swap_exact_input( pool, vault_a, vault_b, diff --git a/amm/src/swap.rs b/amm/src/swap.rs index 3aae808..9dae888 100644 --- a/amm/src/swap.rs +++ b/amm/src/swap.rs @@ -94,7 +94,7 @@ fn create_swap_post_states( #[expect(clippy::too_many_arguments, reason = "TODO: Fix later")] #[must_use] -pub fn swap( +pub fn swap_exact_input( pool: AccountWithMetadata, vault_a: AccountWithMetadata, vault_b: AccountWithMetadata, diff --git a/amm/src/tests.rs b/amm/src/tests.rs index 489f8a4..4d67f70 100644 --- a/amm/src/tests.rs +++ b/amm/src/tests.rs @@ -16,7 +16,7 @@ use crate::{ add::add_liquidity, new_definition::new_definition, remove::remove_liquidity, - swap::{swap, swap_exact_output}, + swap::{swap_exact_input, swap_exact_output}, sync::sync_reserves, }; @@ -2002,7 +2002,7 @@ fn test_call_new_definition_chained_call_successful() { #[should_panic(expected = "AccountId is not a token type for the pool")] #[test] fn test_call_swap_incorrect_token_type() { - let _post_states = swap( + let _post_states = swap_exact_input( AccountWithMetadataForTests::pool_definition_init(), AccountWithMetadataForTests::vault_a_init(), AccountWithMetadataForTests::vault_b_init(), @@ -2017,7 +2017,7 @@ fn test_call_swap_incorrect_token_type() { #[should_panic(expected = "Vault A was not provided")] #[test] fn test_call_swap_vault_a_omitted() { - let _post_states = swap( + let _post_states = swap_exact_input( AccountWithMetadataForTests::pool_definition_init(), AccountWithMetadataForTests::vault_a_with_wrong_id(), AccountWithMetadataForTests::vault_b_init(), @@ -2032,7 +2032,7 @@ fn test_call_swap_vault_a_omitted() { #[should_panic(expected = "Vault B was not provided")] #[test] fn test_call_swap_vault_b_omitted() { - let _post_states = swap( + let _post_states = swap_exact_input( AccountWithMetadataForTests::pool_definition_init(), AccountWithMetadataForTests::vault_a_init(), AccountWithMetadataForTests::vault_b_with_wrong_id(), @@ -2047,7 +2047,7 @@ fn test_call_swap_vault_b_omitted() { #[should_panic(expected = "Reserve for Token A exceeds vault balance")] #[test] fn test_call_swap_reserves_vault_mismatch_1() { - let _post_states = swap( + let _post_states = swap_exact_input( AccountWithMetadataForTests::pool_definition_init(), AccountWithMetadataForTests::vault_a_init_low(), AccountWithMetadataForTests::vault_b_init(), @@ -2062,7 +2062,7 @@ fn test_call_swap_reserves_vault_mismatch_1() { #[should_panic(expected = "Reserve for Token B exceeds vault balance")] #[test] fn test_call_swap_reserves_vault_mismatch_2() { - let _post_states = swap( + let _post_states = swap_exact_input( AccountWithMetadataForTests::pool_definition_init(), AccountWithMetadataForTests::vault_a_init(), AccountWithMetadataForTests::vault_b_init_low(), @@ -2077,7 +2077,7 @@ fn test_call_swap_reserves_vault_mismatch_2() { #[should_panic(expected = "Pool is inactive")] #[test] fn test_call_swap_ianctive() { - let _post_states = swap( + let _post_states = swap_exact_input( AccountWithMetadataForTests::pool_definition_inactive(), AccountWithMetadataForTests::vault_a_init(), AccountWithMetadataForTests::vault_b_init(), @@ -2092,7 +2092,7 @@ fn test_call_swap_ianctive() { #[should_panic(expected = "Withdraw amount is less than minimal amount out")] #[test] fn test_call_swap_below_min_out() { - let _post_states = swap( + let _post_states = swap_exact_input( AccountWithMetadataForTests::pool_definition_init(), AccountWithMetadataForTests::vault_a_init(), AccountWithMetadataForTests::vault_b_init(), @@ -2106,7 +2106,7 @@ fn test_call_swap_below_min_out() { #[test] fn test_call_swap_chained_call_successful_1() { - let (post_states, chained_calls) = swap( + let (post_states, chained_calls) = swap_exact_input( AccountWithMetadataForTests::pool_definition_init(), AccountWithMetadataForTests::vault_a_init(), AccountWithMetadataForTests::vault_b_init(), @@ -2138,7 +2138,7 @@ fn test_call_swap_chained_call_successful_1() { #[test] fn test_call_swap_chained_call_successful_2() { - let (post_states, chained_calls) = swap( + let (post_states, chained_calls) = swap_exact_input( AccountWithMetadataForTests::pool_definition_init(), AccountWithMetadataForTests::vault_a_init(), AccountWithMetadataForTests::vault_b_init(), diff --git a/integration_tests/tests/amm.rs b/integration_tests/tests/amm.rs index c4f050a..797b883 100644 --- a/integration_tests/tests/amm.rs +++ b/integration_tests/tests/amm.rs @@ -1295,7 +1295,7 @@ fn amm_add_liquidity() { fn amm_swap_b_to_a() { let mut state = state_for_amm_tests(); - let instruction = amm_core::Instruction::Swap { + let instruction = amm_core::Instruction::SwapExactInput { swap_amount_in: Balances::swap_amount_in(), min_amount_out: Balances::swap_min_out(), token_definition_id_in: Ids::token_b_definition(), @@ -1346,7 +1346,7 @@ fn amm_swap_b_to_a() { fn amm_swap_a_to_b() { let mut state = state_for_amm_tests(); - let instruction = amm_core::Instruction::Swap { + let instruction = amm_core::Instruction::SwapExactInput { swap_amount_in: Balances::swap_amount_in(), min_amount_out: Balances::swap_min_out(), token_definition_id_in: Ids::token_a_definition(),