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.
This commit is contained in:
Andrea Franz 2026-04-07 09:31:32 +02:00 committed by r4bbit
parent 664fd849bd
commit 4419e1e9a0
6 changed files with 17 additions and 17 deletions

View File

@ -192,7 +192,7 @@
]
},
{
"name": "swap",
"name": "swap_exact_input",
"accounts": [
{
"name": "pool",

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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(),

View File

@ -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(),