cargo fmt and clippy

This commit is contained in:
jonesmarvin8 2025-12-23 17:31:03 -05:00
parent 56151e9d3d
commit c25e93edd5
3 changed files with 32 additions and 36 deletions

View File

@ -9,7 +9,7 @@ borsh.workspace = true
serde = { workspace = true } serde = { workspace = true }
thiserror.workspace = true thiserror.workspace = true
chacha20 = { version = "0.9", default-features = false } chacha20 = { version = "0.9", default-features = false }
bytemuck = { workspace = true, optional = true } bytemuck.workspace = true
k256 = { workspace = true, optional = true } k256 = { workspace = true, optional = true }
base58 = { workspace = true, optional = true } base58 = { workspace = true, optional = true }
anyhow = { workspace = true, optional = true } anyhow = { workspace = true, optional = true }

View File

@ -264,7 +264,6 @@ impl V02State {
#[cfg(test)] #[cfg(test)]
pub mod tests { pub mod tests {
use std::collections::HashMap; use std::collections::HashMap;
use nssa_core::{ use nssa_core::{
@ -284,7 +283,8 @@ pub mod tests {
message::Message, message::Message,
witness_set::WitnessSet, witness_set::WitnessSet,
}, },
program::Program, public_transaction, program::Program,
public_transaction,
signature::PrivateKey, signature::PrivateKey,
state::MAX_NUMBER_CHAINED_CALLS, state::MAX_NUMBER_CHAINED_CALLS,
}; };

View File

@ -203,7 +203,7 @@ impl TokenHolding {
fn new(definition_id: &AccountId) -> Self { fn new(definition_id: &AccountId) -> Self {
Self { Self {
account_type: TOKEN_HOLDING_TYPE, account_type: TOKEN_HOLDING_TYPE,
definition_id: definition_id.clone(), definition_id: *definition_id,
balance: 0, balance: 0,
} }
} }
@ -392,9 +392,9 @@ fn compute_pool_pda_seed(
.value() .value()
.cmp(definition_token_b_id.value()) .cmp(definition_token_b_id.value())
{ {
std::cmp::Ordering::Less => (definition_token_b_id.clone(), definition_token_a_id.clone()), std::cmp::Ordering::Less => (definition_token_b_id, definition_token_a_id),
std::cmp::Ordering::Greater => { std::cmp::Ordering::Greater => {
(definition_token_a_id.clone(), definition_token_b_id.clone()) (definition_token_a_id, definition_token_b_id)
} }
std::cmp::Ordering::Equal => panic!("Definitions match"), std::cmp::Ordering::Equal => panic!("Definitions match"),
}; };
@ -535,9 +535,9 @@ fn new_definition(
if pool.account_id if pool.account_id
!= compute_pool_pda( != compute_pool_pda(
amm_program_id.clone(), amm_program_id,
definition_token_a_id.clone(), definition_token_a_id,
definition_token_b_id.clone(), definition_token_b_id,
) )
{ {
panic!("Pool Definition Account ID does not match PDA"); panic!("Pool Definition Account ID does not match PDA");
@ -545,22 +545,22 @@ fn new_definition(
if vault_a.account_id if vault_a.account_id
!= compute_vault_pda( != compute_vault_pda(
amm_program_id.clone(), amm_program_id,
pool.account_id.clone(), pool.account_id,
definition_token_a_id.clone(), definition_token_a_id,
) )
|| vault_b.account_id || vault_b.account_id
!= compute_vault_pda( != compute_vault_pda(
amm_program_id.clone(), amm_program_id,
pool.account_id.clone(), pool.account_id,
definition_token_b_id.clone(), definition_token_b_id,
) )
{ {
panic!("Vault ID does not match PDA"); panic!("Vault ID does not match PDA");
} }
if pool_lp.account_id if pool_lp.account_id
!= compute_liquidity_token_pda(amm_program_id.clone(), pool.account_id.clone()) != compute_liquidity_token_pda(amm_program_id, pool.account_id)
{ {
panic!("Liquidity pool Token Definition Account ID does not match PDA"); panic!("Liquidity pool Token Definition Account ID does not match PDA");
} }
@ -584,12 +584,12 @@ fn new_definition(
let pool_post_definition = PoolDefinition { let pool_post_definition = PoolDefinition {
definition_token_a_id, definition_token_a_id,
definition_token_b_id, definition_token_b_id,
vault_a_id: vault_a.account_id.clone(), vault_a_id: vault_a.account_id,
vault_b_id: vault_b.account_id.clone(), vault_b_id: vault_b.account_id,
liquidity_pool_id: pool_lp.account_id.clone(), liquidity_pool_id: pool_lp.account_id,
liquidity_pool_supply: amount_a.clone(), liquidity_pool_supply: amount_a,
reserve_a: amount_a.clone(), reserve_a: amount_a,
reserve_b: amount_b.clone(), reserve_b: amount_b,
fees: 0u128, //TODO: we assume all fees are 0 for now. fees: 0u128, //TODO: we assume all fees are 0 for now.
active: true, active: true,
}; };
@ -646,7 +646,7 @@ fn new_definition(
program_id: token_program_id, program_id: token_program_id,
instruction_data, instruction_data,
pre_states: vec![pool_lp_auth.clone(), user_holding_lp.clone()], pre_states: vec![pool_lp_auth.clone(), user_holding_lp.clone()],
pda_seeds: vec![compute_liquidity_token_pda_seed(pool.account_id.clone())], pda_seeds: vec![compute_liquidity_token_pda_seed(pool.account_id)],
}; };
chained_calls.push(call_token_lp); chained_calls.push(call_token_lp);
@ -728,7 +728,7 @@ fn swap(
amounts[0], amounts[0],
amounts[1], amounts[1],
&[pool_def_data.reserve_a, pool_def_data.reserve_b], &[pool_def_data.reserve_a, pool_def_data.reserve_b],
pool.account_id.clone(), pool.account_id,
); );
(chained_calls, [deposit_a, 0], [0, withdraw_b]) (chained_calls, [deposit_a, 0], [0, withdraw_b])
@ -741,7 +741,7 @@ fn swap(
amounts[0], amounts[0],
amounts[1], amounts[1],
&[pool_def_data.reserve_b, pool_def_data.reserve_a], &[pool_def_data.reserve_b, pool_def_data.reserve_a],
pool.account_id.clone(), pool.account_id,
); );
(chained_calls, [0, withdraw_a], [deposit_b, 0]) (chained_calls, [0, withdraw_a], [deposit_b, 0])
@ -962,7 +962,7 @@ fn add_liquidity(
pool_definition_lp_auth.clone(), pool_definition_lp_auth.clone(),
user_holding_lp.clone(), user_holding_lp.clone(),
delta_lp, delta_lp,
vec![compute_liquidity_token_pda_seed(pool.account_id.clone())], vec![compute_liquidity_token_pda_seed(pool.account_id)],
); );
chained_call.push(call_token_lp); chained_call.push(call_token_lp);
@ -1069,11 +1069,7 @@ fn remove_liquidity(
let delta_lp: u128 = let delta_lp: u128 =
(pool_def_data.liquidity_pool_supply * amount_lp) / pool_def_data.liquidity_pool_supply; (pool_def_data.liquidity_pool_supply * amount_lp) / pool_def_data.liquidity_pool_supply;
let active: bool = if pool_def_data.liquidity_pool_supply - delta_lp == 0 { let active: bool = pool_def_data.liquidity_pool_supply - delta_lp != 0;
false
} else {
true
};
// 5. Update pool account // 5. Update pool account
let mut pool_post = pool.account.clone(); let mut pool_post = pool.account.clone();
@ -1096,8 +1092,8 @@ fn remove_liquidity(
user_holding_a.clone(), user_holding_a.clone(),
withdraw_amount_a, withdraw_amount_a,
vec![compute_vault_pda_seed( vec![compute_vault_pda_seed(
pool.account_id.clone(), pool.account_id,
pool_def_data.definition_token_a_id.clone(), pool_def_data.definition_token_a_id,
)], )],
); );
//Chaincall for Token B withdraw //Chaincall for Token B withdraw
@ -1107,8 +1103,8 @@ fn remove_liquidity(
user_holding_b.clone(), user_holding_b.clone(),
withdraw_amount_b, withdraw_amount_b,
vec![compute_vault_pda_seed( vec![compute_vault_pda_seed(
pool.account_id.clone(), pool.account_id,
pool_def_data.definition_token_b_id.clone(), pool_def_data.definition_token_b_id,
)], )],
); );
//Chaincall for LP adjustment //Chaincall for LP adjustment
@ -1119,7 +1115,7 @@ fn remove_liquidity(
pool_definition_lp_auth.clone(), pool_definition_lp_auth.clone(),
user_holding_lp.clone(), user_holding_lp.clone(),
delta_lp, delta_lp,
vec![compute_liquidity_token_pda_seed(pool.account_id.clone())], vec![compute_liquidity_token_pda_seed(pool.account_id)],
); );
chained_calls.push(call_token_lp); chained_calls.push(call_token_lp);