chore(programs/amm): rename Swap to SwapExactInput

This commit is contained in:
Andrea Franz 2026-04-02 09:28:33 +02:00 committed by r4bbit
parent 9a6ec0018b
commit 7d75eb2d59
8 changed files with 25 additions and 25 deletions

Binary file not shown.

View File

@ -223,7 +223,7 @@ async fn amm_public() -> Result<()> {
// Make swap // Make swap
let subcommand = AmmProgramAgnosticSubcommand::Swap { let subcommand = AmmProgramAgnosticSubcommand::SwapExactInput {
user_holding_a: format_public_account_id(recipient_account_id_1), user_holding_a: format_public_account_id(recipient_account_id_1),
user_holding_b: format_public_account_id(recipient_account_id_2), user_holding_b: format_public_account_id(recipient_account_id_2),
amount_in: 2, amount_in: 2,
@ -266,7 +266,7 @@ async fn amm_public() -> Result<()> {
// Make swap // Make swap
let subcommand = AmmProgramAgnosticSubcommand::Swap { let subcommand = AmmProgramAgnosticSubcommand::SwapExactInput {
user_holding_a: format_public_account_id(recipient_account_id_1), user_holding_a: format_public_account_id(recipient_account_id_1),
user_holding_b: format_public_account_id(recipient_account_id_2), user_holding_b: format_public_account_id(recipient_account_id_2),
amount_in: 2, amount_in: 2,

View File

@ -112,15 +112,15 @@ fn main() {
min_amount_to_remove_token_b, min_amount_to_remove_token_b,
) )
} }
Instruction::Swap { Instruction::SwapExactInput {
swap_amount_in, swap_amount_in,
min_amount_out, min_amount_out,
token_definition_id_in, token_definition_id_in,
} => { } => {
let [pool, vault_a, vault_b, user_holding_a, user_holding_b] = pre_states let [pool, vault_a, vault_b, user_holding_a, user_holding_b] = pre_states
.try_into() .try_into()
.expect("Swap instruction requires exactly five accounts"); .expect("SwapExactInput instruction requires exactly five accounts");
amm_program::swap::swap( amm_program::swap::swap_exact_input(
pool, pool,
vault_a, vault_a,
vault_b, vault_b,

View File

@ -68,7 +68,7 @@ pub enum Instruction {
/// - User Holding Account for Token A /// - User Holding Account for Token A
/// - User Holding Account for Token B Either User Holding Account for Token A or Token B is /// - User Holding Account for Token B Either User Holding Account for Token A or Token B is
/// authorized. /// authorized.
Swap { SwapExactInput {
swap_amount_in: u128, swap_amount_in: u128,
min_amount_out: u128, min_amount_out: u128,
token_definition_id_in: AccountId, token_definition_id_in: AccountId,

View File

@ -94,7 +94,7 @@ fn create_swap_post_states(
#[expect(clippy::too_many_arguments, reason = "TODO: Fix later")] #[expect(clippy::too_many_arguments, reason = "TODO: Fix later")]
#[must_use] #[must_use]
pub fn swap( pub fn swap_exact_input(
pool: AccountWithMetadata, pool: AccountWithMetadata,
vault_a: AccountWithMetadata, vault_a: AccountWithMetadata,
vault_b: AccountWithMetadata, vault_b: AccountWithMetadata,

View File

@ -17,7 +17,7 @@ use crate::{
add::add_liquidity, add::add_liquidity,
new_definition::new_definition, new_definition::new_definition,
remove::remove_liquidity, remove::remove_liquidity,
swap::{swap, swap_exact_output}, swap::{swap_exact_input, swap_exact_output},
}; };
const TOKEN_PROGRAM_ID: ProgramId = [15; 8]; const TOKEN_PROGRAM_ID: ProgramId = [15; 8];
@ -2523,7 +2523,7 @@ fn call_new_definition_chained_call_successful() {
#[should_panic(expected = "AccountId is not a token type for the pool")] #[should_panic(expected = "AccountId is not a token type for the pool")]
#[test] #[test]
fn call_swap_incorrect_token_type() { fn call_swap_incorrect_token_type() {
let _post_states = swap( let _post_states = swap_exact_input(
AccountWithMetadataForTests::pool_definition_init(), AccountWithMetadataForTests::pool_definition_init(),
AccountWithMetadataForTests::vault_a_init(), AccountWithMetadataForTests::vault_a_init(),
AccountWithMetadataForTests::vault_b_init(), AccountWithMetadataForTests::vault_b_init(),
@ -2538,7 +2538,7 @@ fn call_swap_incorrect_token_type() {
#[should_panic(expected = "Vault A was not provided")] #[should_panic(expected = "Vault A was not provided")]
#[test] #[test]
fn call_swap_vault_a_omitted() { fn call_swap_vault_a_omitted() {
let _post_states = swap( let _post_states = swap_exact_input(
AccountWithMetadataForTests::pool_definition_init(), AccountWithMetadataForTests::pool_definition_init(),
AccountWithMetadataForTests::vault_a_with_wrong_id(), AccountWithMetadataForTests::vault_a_with_wrong_id(),
AccountWithMetadataForTests::vault_b_init(), AccountWithMetadataForTests::vault_b_init(),
@ -2553,7 +2553,7 @@ fn call_swap_vault_a_omitted() {
#[should_panic(expected = "Vault B was not provided")] #[should_panic(expected = "Vault B was not provided")]
#[test] #[test]
fn call_swap_vault_b_omitted() { fn call_swap_vault_b_omitted() {
let _post_states = swap( let _post_states = swap_exact_input(
AccountWithMetadataForTests::pool_definition_init(), AccountWithMetadataForTests::pool_definition_init(),
AccountWithMetadataForTests::vault_a_init(), AccountWithMetadataForTests::vault_a_init(),
AccountWithMetadataForTests::vault_b_with_wrong_id(), AccountWithMetadataForTests::vault_b_with_wrong_id(),
@ -2568,7 +2568,7 @@ fn call_swap_vault_b_omitted() {
#[should_panic(expected = "Reserve for Token A exceeds vault balance")] #[should_panic(expected = "Reserve for Token A exceeds vault balance")]
#[test] #[test]
fn call_swap_reserves_vault_mismatch_1() { fn call_swap_reserves_vault_mismatch_1() {
let _post_states = swap( let _post_states = swap_exact_input(
AccountWithMetadataForTests::pool_definition_init(), AccountWithMetadataForTests::pool_definition_init(),
AccountWithMetadataForTests::vault_a_init_low(), AccountWithMetadataForTests::vault_a_init_low(),
AccountWithMetadataForTests::vault_b_init(), AccountWithMetadataForTests::vault_b_init(),
@ -2583,7 +2583,7 @@ fn call_swap_reserves_vault_mismatch_1() {
#[should_panic(expected = "Reserve for Token B exceeds vault balance")] #[should_panic(expected = "Reserve for Token B exceeds vault balance")]
#[test] #[test]
fn call_swap_reserves_vault_mismatch_2() { fn call_swap_reserves_vault_mismatch_2() {
let _post_states = swap( let _post_states = swap_exact_input(
AccountWithMetadataForTests::pool_definition_init(), AccountWithMetadataForTests::pool_definition_init(),
AccountWithMetadataForTests::vault_a_init(), AccountWithMetadataForTests::vault_a_init(),
AccountWithMetadataForTests::vault_b_init_low(), AccountWithMetadataForTests::vault_b_init_low(),
@ -2598,7 +2598,7 @@ fn call_swap_reserves_vault_mismatch_2() {
#[should_panic(expected = "Pool is inactive")] #[should_panic(expected = "Pool is inactive")]
#[test] #[test]
fn call_swap_ianctive() { fn call_swap_ianctive() {
let _post_states = swap( let _post_states = swap_exact_input(
AccountWithMetadataForTests::pool_definition_inactive(), AccountWithMetadataForTests::pool_definition_inactive(),
AccountWithMetadataForTests::vault_a_init(), AccountWithMetadataForTests::vault_a_init(),
AccountWithMetadataForTests::vault_b_init(), AccountWithMetadataForTests::vault_b_init(),
@ -2613,7 +2613,7 @@ fn call_swap_ianctive() {
#[should_panic(expected = "Withdraw amount is less than minimal amount out")] #[should_panic(expected = "Withdraw amount is less than minimal amount out")]
#[test] #[test]
fn call_swap_below_min_out() { fn call_swap_below_min_out() {
let _post_states = swap( let _post_states = swap_exact_input(
AccountWithMetadataForTests::pool_definition_init(), AccountWithMetadataForTests::pool_definition_init(),
AccountWithMetadataForTests::vault_a_init(), AccountWithMetadataForTests::vault_a_init(),
AccountWithMetadataForTests::vault_b_init(), AccountWithMetadataForTests::vault_b_init(),
@ -2627,7 +2627,7 @@ fn call_swap_below_min_out() {
#[test] #[test]
fn call_swap_chained_call_successful_1() { fn 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::pool_definition_init(),
AccountWithMetadataForTests::vault_a_init(), AccountWithMetadataForTests::vault_a_init(),
AccountWithMetadataForTests::vault_b_init(), AccountWithMetadataForTests::vault_b_init(),
@ -2659,7 +2659,7 @@ fn call_swap_chained_call_successful_1() {
#[test] #[test]
fn call_swap_chained_call_successful_2() { fn 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::pool_definition_init(),
AccountWithMetadataForTests::vault_a_init(), AccountWithMetadataForTests::vault_a_init(),
AccountWithMetadataForTests::vault_b_init(), AccountWithMetadataForTests::vault_b_init(),
@ -3462,7 +3462,7 @@ fn simple_amm_add() {
fn simple_amm_swap_1() { fn simple_amm_swap_1() {
let mut state = state_for_amm_tests(); let mut state = state_for_amm_tests();
let instruction = amm_core::Instruction::Swap { let instruction = amm_core::Instruction::SwapExactInput {
swap_amount_in: BalanceForExeTests::swap_amount_in(), swap_amount_in: BalanceForExeTests::swap_amount_in(),
min_amount_out: BalanceForExeTests::swap_min_amount_out(), min_amount_out: BalanceForExeTests::swap_min_amount_out(),
token_definition_id_in: IdForExeTests::token_b_definition_id(), token_definition_id_in: IdForExeTests::token_b_definition_id(),
@ -3513,7 +3513,7 @@ fn simple_amm_swap_1() {
fn simple_amm_swap_2() { fn simple_amm_swap_2() {
let mut state = state_for_amm_tests(); let mut state = state_for_amm_tests();
let instruction = amm_core::Instruction::Swap { let instruction = amm_core::Instruction::SwapExactInput {
swap_amount_in: BalanceForExeTests::swap_amount_in(), swap_amount_in: BalanceForExeTests::swap_amount_in(),
min_amount_out: BalanceForExeTests::swap_min_amount_out(), min_amount_out: BalanceForExeTests::swap_min_amount_out(),
token_definition_id_in: IdForExeTests::token_a_definition_id(), token_definition_id_in: IdForExeTests::token_a_definition_id(),

View File

@ -32,12 +32,12 @@ pub enum AmmProgramAgnosticSubcommand {
#[arg(long)] #[arg(long)]
balance_b: u128, balance_b: u128,
}, },
/// Swap. /// Swap specifying exact input amount.
/// ///
/// The account associated with swapping token must be owned. /// The account associated with swapping token must be owned.
/// ///
/// Only public execution allowed. /// Only public execution allowed.
Swap { SwapExactInput {
/// `user_holding_a` - valid 32 byte base58 string with privacy prefix. /// `user_holding_a` - valid 32 byte base58 string with privacy prefix.
#[arg(long)] #[arg(long)]
user_holding_a: String, user_holding_a: String,
@ -170,7 +170,7 @@ impl WalletSubcommand for AmmProgramAgnosticSubcommand {
} }
} }
} }
Self::Swap { Self::SwapExactInput {
user_holding_a, user_holding_a,
user_holding_b, user_holding_b,
amount_in, amount_in,
@ -188,7 +188,7 @@ impl WalletSubcommand for AmmProgramAgnosticSubcommand {
match (user_holding_a_privacy, user_holding_b_privacy) { match (user_holding_a_privacy, user_holding_b_privacy) {
(AccountPrivacyKind::Public, AccountPrivacyKind::Public) => { (AccountPrivacyKind::Public, AccountPrivacyKind::Public) => {
Amm(wallet_core) Amm(wallet_core)
.send_swap( .send_swap_exact_input(
user_holding_a, user_holding_a,
user_holding_b, user_holding_b,
amount_in, amount_in,

View File

@ -121,7 +121,7 @@ impl Amm<'_> {
.await?) .await?)
} }
pub async fn send_swap( pub async fn send_swap_exact_input(
&self, &self,
user_holding_a: AccountId, user_holding_a: AccountId,
user_holding_b: AccountId, user_holding_b: AccountId,
@ -129,7 +129,7 @@ impl Amm<'_> {
min_amount_out: u128, min_amount_out: u128,
token_definition_id_in: AccountId, token_definition_id_in: AccountId,
) -> Result<HashType, ExecutionFailureKind> { ) -> Result<HashType, ExecutionFailureKind> {
let instruction = amm_core::Instruction::Swap { let instruction = amm_core::Instruction::SwapExactInput {
swap_amount_in, swap_amount_in,
min_amount_out, min_amount_out,
token_definition_id_in, token_definition_id_in,