From c3356d36703d19674414e4c61f3c970c78cc5790 Mon Sep 17 00:00:00 2001 From: Mike MacCana Date: Wed, 23 Sep 2026 16:21:13 +0000 Subject: [PATCH] Anchor v1: run rustfmt over every anchor-v1 crate The anchor-v1 crates are absent from the root Cargo workspace (they share package names with their anchor/ siblings), so the Rustfmt CI job never sees them and they had drifted from rustfmt's output. This runs `cargo fmt --all` inside each anchor-v1 project. Formatting only; no code changes. The TypeScript in these projects was already Biome-clean. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01W8VGVdmt1NegpG1Bwjr9nK --- .../favorites/tests/test_favorites.rs | 6 +- .../programs/pythexample/tests/test_pyth.rs | 7 +- .../cnft-burn/src/instructions/burn_cnft.rs | 2 +- .../anchor-v1/programs/cnft-burn/src/lib.rs | 9 +- .../programs/cnft-vault/tests/test_vault.rs | 22 +- .../src/instructions/add_outcome.rs | 5 +- .../betting-market/src/instructions/mod.rs | 4 +- .../src/instructions/settle_event.rs | 3 +- .../betting-market/src/instructions/shared.rs | 7 +- .../programs/betting-market/src/lib.rs | 10 +- .../tests/test_betting_market.rs | 400 +++++++++++++-- .../escrow/src/instructions/take_offer.rs | 4 +- .../anchor-v1/programs/escrow/src/lib.rs | 5 +- .../programs/escrow/tests/test_escrow.rs | 3 +- .../programs/order-book/src/errors.rs | 4 +- .../src/instructions/cancel_order.rs | 4 +- .../instructions/initialize_market_user.rs | 4 +- .../order-book/src/instructions/mod.rs | 4 +- .../src/instructions/place_order.rs | 12 +- .../anchor-v1/programs/order-book/src/lib.rs | 4 +- .../programs/order-book/src/state/mod.rs | 4 +- .../programs/order-book/src/state/order.rs | 4 +- .../order-book/src/state/order_book.rs | 5 +- .../order-book/src/state/slab/nodes.rs | 14 +- .../order-book/src/state/slab/ordertree.rs | 6 +- .../order-book/tests/test_order_book.rs | 474 +++++++++++------- .../programs/fundraiser/src/constants.rs | 2 +- .../fundraiser/src/instructions/checker.rs | 7 +- .../fundraiser/src/instructions/close.rs | 7 +- .../fundraiser/src/instructions/mod.rs | 14 +- .../fundraiser/src/instructions/refund.rs | 13 +- .../fundraiser/src/state/contributor.rs | 2 +- .../fundraiser/src/state/fundraiser.rs | 2 +- .../programs/fundraiser/src/state/mod.rs | 4 +- .../fundraiser/tests/test_fundraiser.rs | 48 +- .../create-token/tests/test_create_token.rs | 10 +- .../src/instructions/transfer_tokens.rs | 4 +- .../tests/test_external_delegate.rs | 33 +- .../nft-minter/tests/test_nft_minter.rs | 4 +- .../src/instructions/verify_collection.rs | 56 +-- .../anchor-v1/programs/mint-nft/src/lib.rs | 8 +- .../mint-nft/tests/test_nft_operations.rs | 21 +- .../token-minter/src/instructions/mint.rs | 5 +- .../programs/token-minter/src/lib.rs | 5 +- .../token-minter/tests/test_pda_mint.rs | 28 +- .../basics/src/instructions/create_token.rs | 5 +- .../anchor-v1/programs/basics/src/lib.rs | 14 +- .../programs/basics/tests/test_basics.rs | 22 +- .../cpi-guard/tests/test_cpi_guard.rs | 44 +- .../src/instructions/initialize.rs | 15 +- .../tests/test_default_account_state.rs | 41 +- .../group/anchor-v1/programs/group/src/lib.rs | 4 +- .../programs/group/tests/test_group.rs | 3 +- .../programs/immutable-owner/src/lib.rs | 4 +- .../tests/test_immutable_owner.rs | 17 +- .../src/instructions/initialize.rs | 8 +- .../src/instructions/update_rate.rs | 4 +- .../tests/test_interest_bearing.rs | 13 +- .../src/instructions/initialize.rs | 4 +- .../memo-transfer/tests/test_memo_transfer.rs | 67 ++- .../metadata/src/instructions/initialize.rs | 5 +- .../metadata/src/instructions/remove_key.rs | 5 +- .../metadata/src/instructions/update_field.rs | 5 +- .../anchor-v1/programs/metadata/src/lib.rs | 10 +- .../src/instructions/initialize.rs | 3 +- .../tests/test_mint_close_authority.rs | 34 +- .../src/instructions/chop_tree.rs | 6 +- .../programs/extension_nft/src/lib.rs | 11 +- .../extension_nft/tests/test_extension_nft.rs | 5 +- .../programs/non-transferable/src/lib.rs | 6 +- .../tests/test_non_transferable.rs | 31 +- .../tests/test_permanent_delegate.rs | 41 +- .../transfer-fee/src/instructions/harvest.rs | 4 +- .../src/instructions/initialize.rs | 11 +- .../transfer-fee/src/instructions/transfer.rs | 5 +- .../transfer-fee/tests/test_transfer_fee.rs | 48 +- .../initialize_extra_account_meta_list.rs | 18 +- .../programs/transfer-hook/src/lib.rs | 16 +- .../transfer-hook/tests/test_transfer_hook.rs | 48 +- .../anchor-v1/programs/abl-token/src/lib.rs | 15 +- .../anchor-v1/programs/abl-token/src/utils.rs | 3 +- .../abl-token/tests/test_abl_token.rs | 22 +- .../initialize_extra_account_meta_list.rs | 18 +- .../programs/transfer-hook/src/lib.rs | 13 +- .../tests/test_transfer_hook_counter.rs | 48 +- .../src/instructions/initialize.rs | 3 +- .../initialize_extra_account_meta_list.rs | 12 +- .../programs/transfer-hook/src/lib.rs | 13 +- .../transfer-hook/tests/test_transfer_hook.rs | 52 +- .../initialize_extra_account_meta_list.rs | 9 +- .../src/instructions/transfer_hook.rs | 11 +- .../programs/transfer-hook/src/lib.rs | 5 +- .../transfer-hook/tests/test_transfer_hook.rs | 14 +- .../src/instructions/configure_admin.rs | 42 +- .../initialise_extra_account_metas_list.rs | 94 ++-- .../src/instructions/switch.rs | 19 +- .../src/instructions/transfer_hook.rs | 34 +- .../programs/transfer-switch/src/lib.rs | 5 +- .../tests/test_transfer_switch.rs | 63 +-- .../src/instructions/add_to_whitelist.rs | 3 +- .../initialize_extra_account_meta_list.rs | 12 +- .../programs/transfer-hook/src/lib.rs | 16 +- .../transfer-hook/tests/test_transfer_hook.rs | 49 +- .../token-minter/src/instructions/mint.rs | 5 +- .../programs/token-minter/src/lib.rs | 5 +- .../token-minter/tests/test_token_minter.rs | 19 +- .../transfer-tokens/src/instructions/mint.rs | 5 +- .../programs/transfer-tokens/src/lib.rs | 5 +- .../tests/test_transfer_tokens.rs | 24 +- 109 files changed, 1522 insertions(+), 992 deletions(-) diff --git a/basics/favorites/anchor-v1/programs/favorites/tests/test_favorites.rs b/basics/favorites/anchor-v1/programs/favorites/tests/test_favorites.rs index 6f217c0df..9f7a8b37d 100644 --- a/basics/favorites/anchor-v1/programs/favorites/tests/test_favorites.rs +++ b/basics/favorites/anchor-v1/programs/favorites/tests/test_favorites.rs @@ -33,13 +33,11 @@ fn read_favorites(svm: &LiteSVM, pda: &Pubkey) -> FavoritesData { offset += color_len; // Vec hobbies (4-byte vec length + each string) - let hobbies_count = - u32::from_le_bytes(data[offset..offset + 4].try_into().unwrap()) as usize; + let hobbies_count = u32::from_le_bytes(data[offset..offset + 4].try_into().unwrap()) as usize; offset += 4; let mut hobbies = Vec::with_capacity(hobbies_count); for _ in 0..hobbies_count { - let hobby_len = - u32::from_le_bytes(data[offset..offset + 4].try_into().unwrap()) as usize; + let hobby_len = u32::from_le_bytes(data[offset..offset + 4].try_into().unwrap()) as usize; offset += 4; let hobby = String::from_utf8(data[offset..offset + hobby_len].to_vec()).unwrap(); offset += hobby_len; diff --git a/basics/pyth/anchor-v1/programs/pythexample/tests/test_pyth.rs b/basics/pyth/anchor-v1/programs/pythexample/tests/test_pyth.rs index 5071866a4..d8c932a8c 100644 --- a/basics/pyth/anchor-v1/programs/pythexample/tests/test_pyth.rs +++ b/basics/pyth/anchor-v1/programs/pythexample/tests/test_pyth.rs @@ -111,9 +111,12 @@ fn setup_with_price_account( (svm, payer, price_update_key) } -fn read_price_instruction(price_update: anchor_lang::solana_program::pubkey::Pubkey) -> Instruction { +fn read_price_instruction( + price_update: anchor_lang::solana_program::pubkey::Pubkey, +) -> Instruction { let ix_data = pythexample::instruction::ReadPrice {}.data(); - let accounts = pythexample::accounts::ReadPriceAccountConstraints { price_update }.to_account_metas(None); + let accounts = + pythexample::accounts::ReadPriceAccountConstraints { price_update }.to_account_metas(None); Instruction::new_with_bytes(pythexample::id(), &ix_data, accounts) } diff --git a/compression/cnft-burn/anchor-v1/programs/cnft-burn/src/instructions/burn_cnft.rs b/compression/cnft-burn/anchor-v1/programs/cnft-burn/src/instructions/burn_cnft.rs index 595a81da9..c1df746fb 100644 --- a/compression/cnft-burn/anchor-v1/programs/cnft-burn/src/instructions/burn_cnft.rs +++ b/compression/cnft-burn/anchor-v1/programs/cnft-burn/src/instructions/burn_cnft.rs @@ -5,7 +5,7 @@ use anchor_lang::solana_program::{ }; use borsh::BorshSerialize; -use crate::{MPL_BUBBLEGUM_ID, SPLCompression}; +use crate::{SPLCompression, MPL_BUBBLEGUM_ID}; /// Burn instruction discriminator from mpl-bubblegum const BURN_DISCRIMINATOR: [u8; 8] = [116, 110, 29, 56, 107, 219, 42, 93]; diff --git a/compression/cnft-burn/anchor-v1/programs/cnft-burn/src/lib.rs b/compression/cnft-burn/anchor-v1/programs/cnft-burn/src/lib.rs index 7bd40193c..587d616c3 100644 --- a/compression/cnft-burn/anchor-v1/programs/cnft-burn/src/lib.rs +++ b/compression/cnft-burn/anchor-v1/programs/cnft-burn/src/lib.rs @@ -38,6 +38,13 @@ pub mod cnft_burn { nonce: u64, index: u32, ) -> Result<()> { - instructions::burn_cnft::handle_burn_cnft(context, root, data_hash, creator_hash, nonce, index) + instructions::burn_cnft::handle_burn_cnft( + context, + root, + data_hash, + creator_hash, + nonce, + index, + ) } } diff --git a/compression/cnft-vault/anchor-v1/programs/cnft-vault/tests/test_vault.rs b/compression/cnft-vault/anchor-v1/programs/cnft-vault/tests/test_vault.rs index 9e0df7d91..a57f22791 100644 --- a/compression/cnft-vault/anchor-v1/programs/cnft-vault/tests/test_vault.rs +++ b/compression/cnft-vault/anchor-v1/programs/cnft-vault/tests/test_vault.rs @@ -476,11 +476,7 @@ fn create_tree_with_vault_cnft(context: &mut VaultTestContext) -> TreeWithVaultC let proof = [empty_node(0), empty_node(1), empty_node(2)]; // Read the current root from the onchain tree account. - let tree_data = context - .svm - .get_account(&merkle_tree.pubkey()) - .unwrap() - .data; + let tree_data = context.svm.get_account(&merkle_tree.pubkey()).unwrap().data; let root = read_current_root(&tree_data); TreeWithVaultCnft { @@ -608,12 +604,8 @@ fn test_withdraw_cnft_by_authority() { let recipient = Keypair::new(); let authority = context.authority.insecure_clone(); - let withdraw_ix = build_withdraw_cnft_instruction( - &context, - authority.pubkey(), - &tree, - recipient.pubkey(), - ); + let withdraw_ix = + build_withdraw_cnft_instruction(&context, authority.pubkey(), &tree, recipient.pubkey()); // The stored authority signs, so the withdraw succeeds (the vault PDA // signs the Bubblegum CPI via invoke_signed inside the program). @@ -692,12 +684,8 @@ fn test_withdraw_two_cnfts_by_authority() { // Both trees' roots moved, so both cNFTs left the vault: replaying the // single-tree withdraw against either tree with the cached roots fails. - let replay1 = build_withdraw_cnft_instruction( - &context, - authority.pubkey(), - &tree1, - recipient.pubkey(), - ); + let replay1 = + build_withdraw_cnft_instruction(&context, authority.pubkey(), &tree1, recipient.pubkey()); let replay = send(&mut context.svm, vec![replay1], &authority, &[&authority]); assert!( replay.is_err(), diff --git a/finance/betting-market/anchor-v1/programs/betting-market/src/instructions/add_outcome.rs b/finance/betting-market/anchor-v1/programs/betting-market/src/instructions/add_outcome.rs index 94d5a66ed..29d3b1111 100644 --- a/finance/betting-market/anchor-v1/programs/betting-market/src/instructions/add_outcome.rs +++ b/finance/betting-market/anchor-v1/programs/betting-market/src/instructions/add_outcome.rs @@ -35,7 +35,10 @@ pub struct AddOutcomeAccountConstraints<'info> { pub system_program: Program<'info, System>, } -pub fn handle_add_outcome(context: Context, label: String) -> Result<()> { +pub fn handle_add_outcome( + context: Context, + label: String, +) -> Result<()> { require!(label.len() <= MAX_LABEL_LEN, BettingError::LabelTooLong); // Outcomes can only be added to a draft. Once `open_betting` runs, the // field of choices is final before the first bet can land. diff --git a/finance/betting-market/anchor-v1/programs/betting-market/src/instructions/mod.rs b/finance/betting-market/anchor-v1/programs/betting-market/src/instructions/mod.rs index cf46f83f9..b86c58955 100644 --- a/finance/betting-market/anchor-v1/programs/betting-market/src/instructions/mod.rs +++ b/finance/betting-market/anchor-v1/programs/betting-market/src/instructions/mod.rs @@ -3,9 +3,9 @@ pub mod cancel_event; pub mod claim_refund; pub mod claim_winnings; pub mod close_losing_bet; +pub mod initialize_config; pub mod initialize_event; pub mod open_betting; -pub mod initialize_config; pub mod place_bet; pub mod settle_event; pub mod shared; @@ -15,9 +15,9 @@ pub use cancel_event::*; pub use claim_refund::*; pub use claim_winnings::*; pub use close_losing_bet::*; +pub use initialize_config::*; pub use initialize_event::*; pub use open_betting::*; -pub use initialize_config::*; pub use place_bet::*; pub use settle_event::*; pub use shared::*; diff --git a/finance/betting-market/anchor-v1/programs/betting-market/src/instructions/settle_event.rs b/finance/betting-market/anchor-v1/programs/betting-market/src/instructions/settle_event.rs index 4e2ed16e4..154fd09b9 100644 --- a/finance/betting-market/anchor-v1/programs/betting-market/src/instructions/settle_event.rs +++ b/finance/betting-market/anchor-v1/programs/betting-market/src/instructions/settle_event.rs @@ -93,7 +93,8 @@ pub fn handle_settle_event( // Winners always get their own stake back; the fee is only ever charged on // the losing side, so a winner can never receive less than they staked. - let fee = (losing_pool as u128 * context.accounts.event.fee_bps as u128 / BPS_DENOMINATOR) as u64; + let fee = + (losing_pool as u128 * context.accounts.event.fee_bps as u128 / BPS_DENOMINATOR) as u64; let distributable_losing_pool = losing_pool - fee; if fee > 0 { diff --git a/finance/betting-market/anchor-v1/programs/betting-market/src/instructions/shared.rs b/finance/betting-market/anchor-v1/programs/betting-market/src/instructions/shared.rs index 8a6668912..be66d24ad 100644 --- a/finance/betting-market/anchor-v1/programs/betting-market/src/instructions/shared.rs +++ b/finance/betting-market/anchor-v1/programs/betting-market/src/instructions/shared.rs @@ -46,10 +46,7 @@ pub fn transfer_tokens_from_vault<'info>( to: to.to_account_info(), authority: event.clone(), }; - let cpi_context = CpiContext::new_with_signer( - token_program.key(), - transfer_accounts, - &signer_seeds, - ); + let cpi_context = + CpiContext::new_with_signer(token_program.key(), transfer_accounts, &signer_seeds); transfer_checked(cpi_context, amount, mint.decimals) } diff --git a/finance/betting-market/anchor-v1/programs/betting-market/src/lib.rs b/finance/betting-market/anchor-v1/programs/betting-market/src/lib.rs index 9a346137e..db1a41ff0 100644 --- a/finance/betting-market/anchor-v1/programs/betting-market/src/lib.rs +++ b/finance/betting-market/anchor-v1/programs/betting-market/src/lib.rs @@ -45,7 +45,10 @@ pub mod betting_market { } // Admin adds a possible result. Only allowed while the event is a draft. - pub fn add_outcome(context: Context, label: String) -> Result<()> { + pub fn add_outcome( + context: Context, + label: String, + ) -> Result<()> { instructions::add_outcome::handle_add_outcome(context, label) } @@ -63,7 +66,10 @@ pub mod betting_market { // Admin resolves the market once betting has closed: takes the fee from the losing pool and records // the figures winners need to claim their share. - pub fn settle_event(context: Context, winning_outcome_index: u8) -> Result<()> { + pub fn settle_event( + context: Context, + winning_outcome_index: u8, + ) -> Result<()> { instructions::settle_event::handle_settle_event(context, winning_outcome_index) } diff --git a/finance/betting-market/anchor-v1/programs/betting-market/tests/test_betting_market.rs b/finance/betting-market/anchor-v1/programs/betting-market/tests/test_betting_market.rs index 62efaf525..7317ee3c3 100644 --- a/finance/betting-market/anchor-v1/programs/betting-market/tests/test_betting_market.rs +++ b/finance/betting-market/anchor-v1/programs/betting-market/tests/test_betting_market.rs @@ -9,8 +9,8 @@ use { solana_keypair::Keypair, solana_kite::{ create_associated_token_account, create_token_mint, create_wallet, - get_token_account_balance, mint_tokens_to_token_account, send_transaction_from_instructions, - SolanaKiteError, + get_token_account_balance, mint_tokens_to_token_account, + send_transaction_from_instructions, SolanaKiteError, }, solana_signer::Signer, }; @@ -53,12 +53,19 @@ fn event_pda(event_id: u64) -> Pubkey { } fn outcome_pda(event: &Pubkey, index: u8) -> Pubkey { - Pubkey::find_program_address(&[b"outcome", event.as_ref(), &[index]], &betting_market::id()).0 + Pubkey::find_program_address( + &[b"outcome", event.as_ref(), &[index]], + &betting_market::id(), + ) + .0 } fn bet_pda(outcome: &Pubkey, bettor: &Pubkey) -> Pubkey { - Pubkey::find_program_address(&[b"bet", outcome.as_ref(), bettor.as_ref()], &betting_market::id()) - .0 + Pubkey::find_program_address( + &[b"bet", outcome.as_ref(), bettor.as_ref()], + &betting_market::id(), + ) + .0 } fn user_pda(bettor: &Pubkey) -> Pubkey { @@ -79,7 +86,8 @@ fn setup() -> Market { let mut svm = LiteSVM::new(); warp_to(&mut svm, START_TIME); let program_bytes = include_bytes!("../../../target/deploy/betting_market.so"); - svm.add_program(betting_market::id(), program_bytes).unwrap(); + svm.add_program(betting_market::id(), program_bytes) + .unwrap(); let admin = create_wallet(&mut svm, 100_000_000_000).unwrap(); let mint = create_token_mint(&mut svm, &admin, DECIMALS, None).unwrap(); @@ -152,7 +160,12 @@ fn initialize_config_ix(admin: Pubkey, mint: Pubkey, fee_recipient: Pubkey) -> I ) } -fn initialize_event_ix(admin: Pubkey, mint: Pubkey, event_id: u64, description: &str) -> Instruction { +fn initialize_event_ix( + admin: Pubkey, + mint: Pubkey, + event_id: u64, + description: &str, +) -> Instruction { initialize_event_closing_at_ix(admin, mint, event_id, description, BETTING_CLOSES_AT) } @@ -414,21 +427,42 @@ fn test_full_lifecycle() { send_transaction_from_instructions( &mut market.svm, - vec![place_bet_ix(mint, &alice.pubkey(), &alice_ata, event_id, 0, 100)], + vec![place_bet_ix( + mint, + &alice.pubkey(), + &alice_ata, + event_id, + 0, + 100, + )], &[&alice], &alice.pubkey(), ) .unwrap(); send_transaction_from_instructions( &mut market.svm, - vec![place_bet_ix(mint, &bob.pubkey(), &bob_ata, event_id, 0, 300)], + vec![place_bet_ix( + mint, + &bob.pubkey(), + &bob_ata, + event_id, + 0, + 300, + )], &[&bob], &bob.pubkey(), ) .unwrap(); send_transaction_from_instructions( &mut market.svm, - vec![place_bet_ix(mint, &carol.pubkey(), &carol_ata, event_id, 1, 200)], + vec![place_bet_ix( + mint, + &carol.pubkey(), + &carol_ata, + event_id, + 1, + 200, + )], &[&carol], &carol.pubkey(), ) @@ -439,7 +473,10 @@ fn test_full_lifecycle() { assert_eq!(get_token_account_balance(&market.svm, &vault).unwrap(), 600); assert_eq!( read_user_bets(&market, &alice.pubkey()), - vec![bet_pda(&outcome_pda(&event_pda(event_id), 0), &alice.pubkey())] + vec![bet_pda( + &outcome_pda(&event_pda(event_id), 0), + &alice.pubkey() + )] ); // Settle to "Yes" (index 0). Losing pool 200, fee = 2% = 4, distributable = 196. @@ -449,7 +486,14 @@ fn test_full_lifecycle() { warp_to(&mut market.svm, BETTING_CLOSES_AT); send_transaction_from_instructions( &mut market.svm, - vec![settle_event_ix(admin, mint, fee_recipient, fee_recipient_ata, event_id, 0)], + vec![settle_event_ix( + admin, + mint, + fee_recipient, + fee_recipient_ata, + event_id, + 0, + )], &[&market.admin], &admin, ) @@ -462,14 +506,26 @@ fn test_full_lifecycle() { // Alice: 100 + 100*196/400 = 149. Bob: 300 + 300*196/400 = 447. send_transaction_from_instructions( &mut market.svm, - vec![claim_winnings_ix(mint, &alice.pubkey(), &alice_ata, event_id, 0)], + vec![claim_winnings_ix( + mint, + &alice.pubkey(), + &alice_ata, + event_id, + 0, + )], &[&alice], &alice.pubkey(), ) .unwrap(); send_transaction_from_instructions( &mut market.svm, - vec![claim_winnings_ix(mint, &bob.pubkey(), &bob_ata, event_id, 0)], + vec![claim_winnings_ix( + mint, + &bob.pubkey(), + &bob_ata, + event_id, + 0, + )], &[&bob], &bob.pubkey(), ) @@ -493,11 +549,20 @@ fn test_full_lifecycle() { // Carol bet the losing outcome, so she has nothing to claim. let carol_claim = send_transaction_from_instructions( &mut market.svm, - vec![claim_winnings_ix(mint, &carol.pubkey(), &carol_ata, event_id, 1)], + vec![claim_winnings_ix( + mint, + &carol.pubkey(), + &carol_ata, + event_id, + 1, + )], &[&carol], &carol.pubkey(), ); - assert!(carol_claim.is_err(), "loser must not be able to claim winnings"); + assert!( + carol_claim.is_err(), + "loser must not be able to claim winnings" + ); // Her losing position stays in the index until she closes it. let carol_bet = bet_pda(&outcome_pda(&event_pda(event_id), 1), &carol.pubkey()); @@ -521,7 +586,12 @@ fn test_only_admin_can_initialize_event() { let mallory = create_wallet(&mut market.svm, 10_000_000_000).unwrap(); let result = send_transaction_from_instructions( &mut market.svm, - vec![initialize_event_ix(mallory.pubkey(), mint, 7, "Unauthorized event")], + vec![initialize_event_ix( + mallory.pubkey(), + mint, + 7, + "Unauthorized event", + )], &[&mallory], &mallory.pubkey(), ); @@ -554,7 +624,14 @@ fn test_cannot_bet_after_settle() { .unwrap(); send_transaction_from_instructions( &mut market.svm, - vec![place_bet_ix(mint, &alice.pubkey(), &alice_ata, event_id, 0, 100)], + vec![place_bet_ix( + mint, + &alice.pubkey(), + &alice_ata, + event_id, + 0, + 100, + )], &[&alice], &alice.pubkey(), ) @@ -563,7 +640,14 @@ fn test_cannot_bet_after_settle() { warp_to(&mut market.svm, BETTING_CLOSES_AT); send_transaction_from_instructions( &mut market.svm, - vec![settle_event_ix(admin, mint, fee_recipient, fee_recipient_ata, event_id, 0)], + vec![settle_event_ix( + admin, + mint, + fee_recipient, + fee_recipient_ata, + event_id, + 0, + )], &[&market.admin], &admin, ) @@ -571,7 +655,14 @@ fn test_cannot_bet_after_settle() { let late_bet = send_transaction_from_instructions( &mut market.svm, - vec![place_bet_ix(mint, &bob.pubkey(), &bob_ata, event_id, 1, 100)], + vec![place_bet_ix( + mint, + &bob.pubkey(), + &bob_ata, + event_id, + 1, + 100, + )], &[&bob], &bob.pubkey(), ); @@ -604,14 +695,28 @@ fn test_double_claim_fails() { .unwrap(); send_transaction_from_instructions( &mut market.svm, - vec![place_bet_ix(mint, &alice.pubkey(), &alice_ata, event_id, 0, 100)], + vec![place_bet_ix( + mint, + &alice.pubkey(), + &alice_ata, + event_id, + 0, + 100, + )], &[&alice], &alice.pubkey(), ) .unwrap(); send_transaction_from_instructions( &mut market.svm, - vec![place_bet_ix(mint, &carol.pubkey(), &carol_ata, event_id, 1, 100)], + vec![place_bet_ix( + mint, + &carol.pubkey(), + &carol_ata, + event_id, + 1, + 100, + )], &[&carol], &carol.pubkey(), ) @@ -620,7 +725,14 @@ fn test_double_claim_fails() { warp_to(&mut market.svm, BETTING_CLOSES_AT); send_transaction_from_instructions( &mut market.svm, - vec![settle_event_ix(admin, mint, fee_recipient, fee_recipient_ata, event_id, 0)], + vec![settle_event_ix( + admin, + mint, + fee_recipient, + fee_recipient_ata, + event_id, + 0, + )], &[&market.admin], &admin, ) @@ -628,7 +740,13 @@ fn test_double_claim_fails() { send_transaction_from_instructions( &mut market.svm, - vec![claim_winnings_ix(mint, &alice.pubkey(), &alice_ata, event_id, 0)], + vec![claim_winnings_ix( + mint, + &alice.pubkey(), + &alice_ata, + event_id, + 0, + )], &[&alice], &alice.pubkey(), ) @@ -637,7 +755,13 @@ fn test_double_claim_fails() { market.svm.expire_blockhash(); let second = send_transaction_from_instructions( &mut market.svm, - vec![claim_winnings_ix(mint, &alice.pubkey(), &alice_ata, event_id, 0)], + vec![claim_winnings_ix( + mint, + &alice.pubkey(), + &alice_ata, + event_id, + 0, + )], &[&alice], &alice.pubkey(), ); @@ -670,7 +794,14 @@ fn test_settle_outcome_without_bets_fails() { // Everyone bets Horse A; Horse B has no bets. send_transaction_from_instructions( &mut market.svm, - vec![place_bet_ix(mint, &alice.pubkey(), &alice_ata, event_id, 0, 100)], + vec![place_bet_ix( + mint, + &alice.pubkey(), + &alice_ata, + event_id, + 0, + 100, + )], &[&alice], &alice.pubkey(), ) @@ -680,7 +811,14 @@ fn test_settle_outcome_without_bets_fails() { warp_to(&mut market.svm, BETTING_CLOSES_AT); let result = send_transaction_from_instructions( &mut market.svm, - vec![settle_event_ix(admin, mint, fee_recipient, fee_recipient_ata, event_id, 1)], + vec![settle_event_ix( + admin, + mint, + fee_recipient, + fee_recipient_ata, + event_id, + 1, + )], &[&market.admin], &admin, ); @@ -711,14 +849,28 @@ fn test_cancel_and_refund() { .unwrap(); send_transaction_from_instructions( &mut market.svm, - vec![place_bet_ix(mint, &alice.pubkey(), &alice_ata, event_id, 0, 250)], + vec![place_bet_ix( + mint, + &alice.pubkey(), + &alice_ata, + event_id, + 0, + 250, + )], &[&alice], &alice.pubkey(), ) .unwrap(); send_transaction_from_instructions( &mut market.svm, - vec![place_bet_ix(mint, &carol.pubkey(), &carol_ata, event_id, 1, 750)], + vec![place_bet_ix( + mint, + &carol.pubkey(), + &carol_ata, + event_id, + 1, + 750, + )], &[&carol], &carol.pubkey(), ) @@ -737,7 +889,13 @@ fn test_cancel_and_refund() { send_transaction_from_instructions( &mut market.svm, - vec![claim_refund_ix(mint, &alice.pubkey(), &alice_ata, event_id, 0)], + vec![claim_refund_ix( + mint, + &alice.pubkey(), + &alice_ata, + event_id, + 0, + )], &[&alice], &alice.pubkey(), ) @@ -748,15 +906,27 @@ fn test_cancel_and_refund() { send_transaction_from_instructions( &mut market.svm, - vec![claim_refund_ix(mint, &carol.pubkey(), &carol_ata, event_id, 1)], + vec![claim_refund_ix( + mint, + &carol.pubkey(), + &carol_ata, + event_id, + 1, + )], &[&carol], &carol.pubkey(), ) .unwrap(); // Both bettors made whole; no fee on a cancelled event. - assert_eq!(get_token_account_balance(&market.svm, &alice_ata).unwrap(), 1_000); - assert_eq!(get_token_account_balance(&market.svm, &carol_ata).unwrap(), 1_000); + assert_eq!( + get_token_account_balance(&market.svm, &alice_ata).unwrap(), + 1_000 + ); + assert_eq!( + get_token_account_balance(&market.svm, &carol_ata).unwrap(), + 1_000 + ); let vault = derive_ata(&event_pda(event_id), &mint); assert_eq!(get_token_account_balance(&market.svm, &vault).unwrap(), 0); } @@ -787,14 +957,28 @@ fn test_close_losing_bet_only_after_settle_and_only_for_losers() { .unwrap(); send_transaction_from_instructions( &mut market.svm, - vec![place_bet_ix(mint, &alice.pubkey(), &alice_ata, event_id, 0, 100)], + vec![place_bet_ix( + mint, + &alice.pubkey(), + &alice_ata, + event_id, + 0, + 100, + )], &[&alice], &alice.pubkey(), ) .unwrap(); send_transaction_from_instructions( &mut market.svm, - vec![place_bet_ix(mint, &carol.pubkey(), &carol_ata, event_id, 1, 100)], + vec![place_bet_ix( + mint, + &carol.pubkey(), + &carol_ata, + event_id, + 1, + 100, + )], &[&carol], &carol.pubkey(), ) @@ -807,13 +991,23 @@ fn test_close_losing_bet_only_after_settle_and_only_for_losers() { &[&carol], &carol.pubkey(), ); - assert!(premature_close.is_err(), "closing before settlement must fail"); + assert!( + premature_close.is_err(), + "closing before settlement must fail" + ); // Betting has closed, so the event can be settled. warp_to(&mut market.svm, BETTING_CLOSES_AT); send_transaction_from_instructions( &mut market.svm, - vec![settle_event_ix(admin, mint, fee_recipient, fee_recipient_ata, event_id, 0)], + vec![settle_event_ix( + admin, + mint, + fee_recipient, + fee_recipient_ata, + event_id, + 0, + )], &[&market.admin], &admin, ) @@ -826,7 +1020,10 @@ fn test_close_losing_bet_only_after_settle_and_only_for_losers() { &[&alice], &alice.pubkey(), ); - assert!(winner_close.is_err(), "a winning bet must not be closed as losing"); + assert!( + winner_close.is_err(), + "a winning bet must not be closed as losing" + ); let alice_bet = bet_pda(&outcome_pda(&event_pda(event_id), 0), &alice.pubkey()); assert_eq!(read_user_bets(&market, &alice.pubkey()), vec![alice_bet]); @@ -863,7 +1060,12 @@ fn test_closing_a_bet_frees_a_slot_for_a_new_bet() { send_transaction_from_instructions( &mut market.svm, - vec![initialize_event_ix(admin, mint, full_event_id, "Wide field")], + vec![initialize_event_ix( + admin, + mint, + full_event_id, + "Wide field", + )], &[&market.admin], &admin, ) @@ -871,7 +1073,12 @@ fn test_closing_a_bet_frees_a_slot_for_a_new_bet() { for index in 0..outcome_count { send_transaction_from_instructions( &mut market.svm, - vec![add_outcome_ix(admin, full_event_id, index, &format!("Runner {index}"))], + vec![add_outcome_ix( + admin, + full_event_id, + index, + &format!("Runner {index}"), + )], &[&market.admin], &admin, ) @@ -901,13 +1108,23 @@ fn test_closing_a_bet_frees_a_slot_for_a_new_bet() { for index in 0..MAX_BETS_PER_USER as u8 { send_transaction_from_instructions( &mut market.svm, - vec![place_bet_ix(mint, &alice.pubkey(), &alice_ata, full_event_id, index, STAKE)], + vec![place_bet_ix( + mint, + &alice.pubkey(), + &alice_ata, + full_event_id, + index, + STAKE, + )], &[&alice], &alice.pubkey(), ) .unwrap(); } - assert_eq!(read_user_bets(&market, &alice.pubkey()).len(), MAX_BETS_PER_USER); + assert_eq!( + read_user_bets(&market, &alice.pubkey()).len(), + MAX_BETS_PER_USER + ); // With the index full, any new position is rejected - on this event or another. let one_too_many = send_transaction_from_instructions( @@ -923,14 +1140,27 @@ fn test_closing_a_bet_frees_a_slot_for_a_new_bet() { &[&alice], &alice.pubkey(), ); - assert!(one_too_many.is_err(), "a full index must reject a new position"); + assert!( + one_too_many.is_err(), + "a full index must reject a new position" + ); let other_market_bet = send_transaction_from_instructions( &mut market.svm, - vec![place_bet_ix(mint, &alice.pubkey(), &alice_ata, second_event_id, 0, STAKE)], + vec![place_bet_ix( + mint, + &alice.pubkey(), + &alice_ata, + second_event_id, + 0, + STAKE, + )], &[&alice], &alice.pubkey(), ); - assert!(other_market_bet.is_err(), "a full index must reject bets on any market"); + assert!( + other_market_bet.is_err(), + "a full index must reject bets on any market" + ); // Unwind one position: cancel the event and refund the first bet. send_transaction_from_instructions( @@ -942,7 +1172,13 @@ fn test_closing_a_bet_frees_a_slot_for_a_new_bet() { .unwrap(); send_transaction_from_instructions( &mut market.svm, - vec![claim_refund_ix(mint, &alice.pubkey(), &alice_ata, full_event_id, 0)], + vec![claim_refund_ix( + mint, + &alice.pubkey(), + &alice_ata, + full_event_id, + 0, + )], &[&alice], &alice.pubkey(), ) @@ -960,15 +1196,28 @@ fn test_closing_a_bet_frees_a_slot_for_a_new_bet() { market.svm.expire_blockhash(); send_transaction_from_instructions( &mut market.svm, - vec![place_bet_ix(mint, &alice.pubkey(), &alice_ata, second_event_id, 0, STAKE)], + vec![place_bet_ix( + mint, + &alice.pubkey(), + &alice_ata, + second_event_id, + 0, + STAKE, + )], &[&alice], &alice.pubkey(), ) .unwrap(); let final_bets = read_user_bets(&market, &alice.pubkey()); assert_eq!(final_bets.len(), MAX_BETS_PER_USER); - let new_bet = bet_pda(&outcome_pda(&event_pda(second_event_id), 0), &alice.pubkey()); - assert!(final_bets.contains(&new_bet), "the new position must appear in the index"); + let new_bet = bet_pda( + &outcome_pda(&event_pda(second_event_id), 0), + &alice.pubkey(), + ); + assert!( + final_bets.contains(&new_bet), + "the new position must appear in the index" + ); } // The outcome list is final once betting opens, and nobody can bet before it @@ -997,7 +1246,14 @@ fn test_outcomes_lock_when_betting_opens() { // The draft has one outcome and no bettor can touch it yet. let early_bet = send_transaction_from_instructions( &mut market.svm, - vec![place_bet_ix(mint, &alice.pubkey(), &alice_ata, event_id, 0, 100)], + vec![place_bet_ix( + mint, + &alice.pubkey(), + &alice_ata, + event_id, + 0, + 100, + )], &[&alice], &alice.pubkey(), ); @@ -1111,7 +1367,14 @@ fn test_betting_closes_at_close_time() { warp_to(&mut market.svm, BETTING_CLOSES_AT - 1); send_transaction_from_instructions( &mut market.svm, - vec![place_bet_ix(mint, &alice.pubkey(), &alice_ata, event_id, 0, 100)], + vec![place_bet_ix( + mint, + &alice.pubkey(), + &alice_ata, + event_id, + 0, + 100, + )], &[&alice], &alice.pubkey(), ) @@ -1120,7 +1383,14 @@ fn test_betting_closes_at_close_time() { // ...and the admin cannot settle yet. let early_settle = send_transaction_from_instructions( &mut market.svm, - vec![settle_event_ix(admin, mint, fee_recipient, fee_recipient_ata, event_id, 0)], + vec![settle_event_ix( + admin, + mint, + fee_recipient, + fee_recipient_ata, + event_id, + 0, + )], &[&market.admin], &admin, ); @@ -1130,7 +1400,14 @@ fn test_betting_closes_at_close_time() { warp_to(&mut market.svm, BETTING_CLOSES_AT); let late_bet = send_transaction_from_instructions( &mut market.svm, - vec![place_bet_ix(mint, &carol.pubkey(), &carol_ata, event_id, 1, 100)], + vec![place_bet_ix( + mint, + &carol.pubkey(), + &carol_ata, + event_id, + 1, + 100, + )], &[&carol], &carol.pubkey(), ); @@ -1138,7 +1415,14 @@ fn test_betting_closes_at_close_time() { send_transaction_from_instructions( &mut market.svm, - vec![settle_event_ix(admin, mint, fee_recipient, fee_recipient_ata, event_id, 0)], + vec![settle_event_ix( + admin, + mint, + fee_recipient, + fee_recipient_ata, + event_id, + 0, + )], &[&market.admin], &admin, ) @@ -1154,7 +1438,13 @@ fn test_close_time_must_be_in_the_future() { let result = send_transaction_from_instructions( &mut market.svm, - vec![initialize_event_closing_at_ix(admin, mint, 12, "Already over", START_TIME)], + vec![initialize_event_closing_at_ix( + admin, + mint, + 12, + "Already over", + START_TIME, + )], &[&market.admin], &admin, ); diff --git a/finance/escrow/anchor-v1/programs/escrow/src/instructions/take_offer.rs b/finance/escrow/anchor-v1/programs/escrow/src/instructions/take_offer.rs index a8edc1a13..207398606 100644 --- a/finance/escrow/anchor-v1/programs/escrow/src/instructions/take_offer.rs +++ b/finance/escrow/anchor-v1/programs/escrow/src/instructions/take_offer.rs @@ -85,7 +85,9 @@ pub fn handle_send_wanted_tokens_to_maker( ) } -pub fn handle_withdraw_and_close_vault(context: Context) -> Result<()> { +pub fn handle_withdraw_and_close_vault( + context: Context, +) -> Result<()> { let maker_key = context.accounts.maker.key(); let id_bytes = context.accounts.offer.id.to_le_bytes(); let bump = [context.accounts.offer.bump]; diff --git a/finance/escrow/anchor-v1/programs/escrow/src/lib.rs b/finance/escrow/anchor-v1/programs/escrow/src/lib.rs index fd8307da2..8fdc1c556 100644 --- a/finance/escrow/anchor-v1/programs/escrow/src/lib.rs +++ b/finance/escrow/anchor-v1/programs/escrow/src/lib.rs @@ -19,7 +19,10 @@ pub mod escrow { token_a_offered_amount: u64, token_b_wanted_amount: u64, ) -> Result<()> { - instructions::make_offer::handle_send_offered_tokens_to_vault(&context, token_a_offered_amount)?; + instructions::make_offer::handle_send_offered_tokens_to_vault( + &context, + token_a_offered_amount, + )?; instructions::make_offer::handle_save_offer(context, id, token_b_wanted_amount) } diff --git a/finance/escrow/anchor-v1/programs/escrow/tests/test_escrow.rs b/finance/escrow/anchor-v1/programs/escrow/tests/test_escrow.rs index db586e808..1adf2d112 100644 --- a/finance/escrow/anchor-v1/programs/escrow/tests/test_escrow.rs +++ b/finance/escrow/anchor-v1/programs/escrow/tests/test_escrow.rs @@ -7,7 +7,8 @@ use { solana_keypair::Keypair, solana_kite::{ create_associated_token_account, create_token_mint, create_wallet, - get_token_account_balance, mint_tokens_to_token_account, send_transaction_from_instructions, + get_token_account_balance, mint_tokens_to_token_account, + send_transaction_from_instructions, }, solana_signer::Signer, }; diff --git a/finance/order-book/anchor-v1/programs/order-book/src/errors.rs b/finance/order-book/anchor-v1/programs/order-book/src/errors.rs index 71c558856..294a644ec 100644 --- a/finance/order-book/anchor-v1/programs/order-book/src/errors.rs +++ b/finance/order-book/anchor-v1/programs/order-book/src/errors.rs @@ -71,7 +71,9 @@ pub enum ErrorCode { #[msg("Order book account does not match the market's order book")] InvalidOrderBook, - #[msg("Book side is full: pass the worst resting order and its owner's MarketUser to evict it")] + #[msg( + "Book side is full: pass the worst resting order and its owner's MarketUser to evict it" + )] MissingEvictedAccounts, #[msg("Evicted order provided is not the worst resting order on the full side")] diff --git a/finance/order-book/anchor-v1/programs/order-book/src/instructions/cancel_order.rs b/finance/order-book/anchor-v1/programs/order-book/src/instructions/cancel_order.rs index e5ea54a84..46df2dc96 100644 --- a/finance/order-book/anchor-v1/programs/order-book/src/instructions/cancel_order.rs +++ b/finance/order-book/anchor-v1/programs/order-book/src/instructions/cancel_order.rs @@ -2,8 +2,8 @@ use anchor_lang::prelude::*; use crate::errors::ErrorCode; use crate::state::{ - credit_unfilled_lock, remove_open_order, Market, Order, OrderBook, OrderStatus, MarketUser, - ORDER_SEED, MARKET_USER_SEED, + credit_unfilled_lock, remove_open_order, Market, MarketUser, Order, OrderBook, OrderStatus, + MARKET_USER_SEED, ORDER_SEED, }; pub fn handle_cancel_order(context: Context) -> Result<()> { diff --git a/finance/order-book/anchor-v1/programs/order-book/src/instructions/initialize_market_user.rs b/finance/order-book/anchor-v1/programs/order-book/src/instructions/initialize_market_user.rs index 25b885c37..fc815c70f 100644 --- a/finance/order-book/anchor-v1/programs/order-book/src/instructions/initialize_market_user.rs +++ b/finance/order-book/anchor-v1/programs/order-book/src/instructions/initialize_market_user.rs @@ -2,7 +2,9 @@ use anchor_lang::prelude::*; use crate::state::{Market, MarketUser, MARKET_USER_SEED}; -pub fn handle_initialize_market_user(context: Context) -> Result<()> { +pub fn handle_initialize_market_user( + context: Context, +) -> Result<()> { let market_user = &mut context.accounts.market_user; market_user.market = context.accounts.market.key(); market_user.owner = context.accounts.owner.key(); diff --git a/finance/order-book/anchor-v1/programs/order-book/src/instructions/mod.rs b/finance/order-book/anchor-v1/programs/order-book/src/instructions/mod.rs index 1ed385342..5fc5f626c 100644 --- a/finance/order-book/anchor-v1/programs/order-book/src/instructions/mod.rs +++ b/finance/order-book/anchor-v1/programs/order-book/src/instructions/mod.rs @@ -1,13 +1,13 @@ pub mod admin; pub mod cancel_order; -pub mod initialize_market_user; pub mod initialize_market; +pub mod initialize_market_user; pub mod place_order; pub mod settle_funds; pub use admin::*; pub use cancel_order::*; -pub use initialize_market_user::*; pub use initialize_market::*; +pub use initialize_market_user::*; pub use place_order::*; pub use settle_funds::*; diff --git a/finance/order-book/anchor-v1/programs/order-book/src/instructions/place_order.rs b/finance/order-book/anchor-v1/programs/order-book/src/instructions/place_order.rs index 91d44256e..a5a29ca38 100644 --- a/finance/order-book/anchor-v1/programs/order-book/src/instructions/place_order.rs +++ b/finance/order-book/anchor-v1/programs/order-book/src/instructions/place_order.rs @@ -5,8 +5,8 @@ use anchor_spl::token_interface::{ use crate::errors::ErrorCode; use crate::state::{ - add_open_order, credit_unfilled_lock, plan_fills, remove_open_order, Market, Order, OrderBook, - OrderSide, OrderStatus, MarketUser, MARKET_SEED, ORDER_SEED, MARKET_USER_SEED, + add_open_order, credit_unfilled_lock, plan_fills, remove_open_order, Market, MarketUser, Order, + OrderBook, OrderSide, OrderStatus, MARKET_SEED, MARKET_USER_SEED, ORDER_SEED, }; // Mirror of MarketUser.open_orders max_len. Kept as a constant so the @@ -308,8 +308,7 @@ pub fn handle_place_order<'info>( .checked_add(fill.fill_quantity) .ok_or(ErrorCode::NumericalOverflow)?; - let maker_fully_filled = - maker_order.filled_quantity >= maker_order.original_quantity; + let maker_fully_filled = maker_order.filled_quantity >= maker_order.original_quantity; maker_order.status = if maker_fully_filled { OrderStatus::Filled } else { @@ -465,10 +464,7 @@ pub fn handle_place_order<'info>( let mut order_book = order_book_loader.load_mut()?; let id = order_book.allocate_order_id()?; if taker_remaining > 0 { - require!( - !order_book.is_side_full(side), - ErrorCode::OrderBookFull - ); + require!(!order_book.is_side_full(side), ErrorCode::OrderBookFull); order_book.place_resting( side, price, diff --git a/finance/order-book/anchor-v1/programs/order-book/src/lib.rs b/finance/order-book/anchor-v1/programs/order-book/src/lib.rs index edb913309..e16ad393c 100644 --- a/finance/order-book/anchor-v1/programs/order-book/src/lib.rs +++ b/finance/order-book/anchor-v1/programs/order-book/src/lib.rs @@ -35,7 +35,9 @@ pub mod order_book { /// Create a per-user, per-market account that tracks a user's open orders /// and unsettled balances. - pub fn initialize_market_user(context: Context) -> Result<()> { + pub fn initialize_market_user( + context: Context, + ) -> Result<()> { instructions::initialize_market_user::handle_initialize_market_user(context) } diff --git a/finance/order-book/anchor-v1/programs/order-book/src/state/mod.rs b/finance/order-book/anchor-v1/programs/order-book/src/state/mod.rs index b1c058ee8..3dd3bd3dd 100644 --- a/finance/order-book/anchor-v1/programs/order-book/src/state/mod.rs +++ b/finance/order-book/anchor-v1/programs/order-book/src/state/mod.rs @@ -1,12 +1,12 @@ pub mod market; +pub mod market_user; pub mod matching; pub mod order; pub mod order_book; pub mod slab; -pub mod market_user; pub use market::*; +pub use market_user::*; pub use matching::*; pub use order::*; pub use order_book::*; -pub use market_user::*; diff --git a/finance/order-book/anchor-v1/programs/order-book/src/state/order.rs b/finance/order-book/anchor-v1/programs/order-book/src/state/order.rs index 24e4d264e..2603ff651 100644 --- a/finance/order-book/anchor-v1/programs/order-book/src/state/order.rs +++ b/finance/order-book/anchor-v1/programs/order-book/src/state/order.rs @@ -41,5 +41,7 @@ pub struct Order { } pub fn remaining_quantity(order: &Order) -> u64 { - order.original_quantity.saturating_sub(order.filled_quantity) + order + .original_quantity + .saturating_sub(order.filled_quantity) } diff --git a/finance/order-book/anchor-v1/programs/order-book/src/state/order_book.rs b/finance/order-book/anchor-v1/programs/order-book/src/state/order_book.rs index 7f8893131..eb2542811 100644 --- a/finance/order-book/anchor-v1/programs/order-book/src/state/order_book.rs +++ b/finance/order-book/anchor-v1/programs/order-book/src/state/order_book.rs @@ -60,7 +60,10 @@ pub const ORDER_BOOK_ACCOUNT_SIZE: usize = 8 + std::mem::size_of::(); // + 8 (next_order_id) + 1 (bump) + 7 (pad) + 2 * (12 + 88*1024) // = 64 + 2 * 90124 = 180312 bytes for the struct itself. const _: () = { - assert!(std::mem::size_of::() == 32 + 8 + 8 + 8 + 1 + 7 + 2 * (1 + 3 + 4 + 4 + 4 + NODE_SIZE * MAX_TREE_NODES)); + assert!( + std::mem::size_of::() + == 32 + 8 + 8 + 8 + 1 + 7 + 2 * (1 + 3 + 4 + 4 + 4 + NODE_SIZE * MAX_TREE_NODES) + ); }; /// A compact view of one resting order for the matching engine. Returned diff --git a/finance/order-book/anchor-v1/programs/order-book/src/state/slab/nodes.rs b/finance/order-book/anchor-v1/programs/order-book/src/state/slab/nodes.rs index 2067f6eed..046e20012 100644 --- a/finance/order-book/anchor-v1/programs/order-book/src/state/slab/nodes.rs +++ b/finance/order-book/anchor-v1/programs/order-book/src/state/slab/nodes.rs @@ -64,7 +64,11 @@ impl NodeTag { /// largest key first; inverting seq_num makes the earlier order's seq_num /// the larger one at any given price.) pub fn new_node_key(side: OrderSide, price_data: u64, seq_num: u64) -> u128 { - let seq_num = if side == OrderSide::Bid { !seq_num } else { seq_num }; + let seq_num = if side == OrderSide::Bid { + !seq_num + } else { + seq_num + }; ((price_data as u128) << 64) | (seq_num as u128) } @@ -186,13 +190,7 @@ const_assert_eq!(size_of::(), NODE_SIZE); const_assert_eq!(size_of::() % 8, 0); impl LeafNode { - pub fn new( - key: u128, - owner: Pubkey, - quantity: u64, - order_id: u64, - timestamp: i64, - ) -> Self { + pub fn new(key: u128, owner: Pubkey, quantity: u64, order_id: u64, timestamp: i64) -> Self { Self { tag: NodeTag::LeafNode as u8, padding: [0; 7], diff --git a/finance/order-book/anchor-v1/programs/order-book/src/state/slab/ordertree.rs b/finance/order-book/anchor-v1/programs/order-book/src/state/slab/ordertree.rs index 6d86ab87a..2c126d46e 100644 --- a/finance/order-book/anchor-v1/programs/order-book/src/state/slab/ordertree.rs +++ b/finance/order-book/anchor-v1/programs/order-book/src/state/slab/ordertree.rs @@ -145,7 +145,11 @@ impl OrderTreeNodes { } /// Look up a leaf by its full 128-bit key. - pub fn find_by_key(&self, root: &OrderTreeRoot, search_key: u128) -> Option<(NodeHandle, &LeafNode)> { + pub fn find_by_key( + &self, + root: &OrderTreeRoot, + search_key: u128, + ) -> Option<(NodeHandle, &LeafNode)> { let mut handle = root.node()?; loop { let node = self.node(handle)?; diff --git a/finance/order-book/anchor-v1/programs/order-book/tests/test_order_book.rs b/finance/order-book/anchor-v1/programs/order-book/tests/test_order_book.rs index 7ca39bbca..e9296ddf3 100644 --- a/finance/order-book/anchor-v1/programs/order-book/tests/test_order_book.rs +++ b/finance/order-book/anchor-v1/programs/order-book/tests/test_order_book.rs @@ -245,10 +245,7 @@ fn full_setup() -> Scenario { /// /// Rent is whatever LiteSVM's bank quotes for that size at the current /// rent rate; we use `minimum_balance` so the account is rent-exempt. -fn build_create_order_book_account_ix( - sc: &Scenario, - payer: &Pubkey, -) -> Instruction { +fn build_create_order_book_account_ix(sc: &Scenario, payer: &Pubkey) -> Instruction { // LiteSVM uses the default rent schedule; minimum_balance() on the // 180 KB account is around 1.25 SOL - well within the 100 SOL we fund // the test payer with in `full_setup`. @@ -388,8 +385,7 @@ fn build_place_order_with_makers_ix( for (maker_order_id, maker_market_user) in maker_pairs { let maker_order = order_pda(&sc.program_id, &sc.market, *maker_order_id); - ix.accounts - .push(AccountMeta::new(maker_order, false)); + ix.accounts.push(AccountMeta::new(maker_order, false)); ix.accounts .push(AccountMeta::new(*maker_market_user, false)); } @@ -397,10 +393,7 @@ fn build_place_order_with_makers_ix( ix } -fn build_withdraw_fees_ix( - sc: &Scenario, - authority_quote_account: Pubkey, -) -> Instruction { +fn build_withdraw_fees_ix(sc: &Scenario, authority_quote_account: Pubkey) -> Instruction { Instruction::new_with_bytes( sc.program_id, &order_book::instruction::WithdrawFees {}.data(), @@ -471,7 +464,14 @@ fn initialize_market_and_users(sc: &mut Scenario) { // program, zero-initialized) before initialize_market's `#[account(zero)]` // check passes. let create_ix = build_create_order_book_account_ix(sc, &sc.authority.pubkey()); - let init_ix = build_initialize_market_ix(sc, FEE_BASIS_POINTS, TICK_SIZE, BASE_LOT_SIZE, QUOTE_LOT_SIZE, MIN_ORDER_SIZE); + let init_ix = build_initialize_market_ix( + sc, + FEE_BASIS_POINTS, + TICK_SIZE, + BASE_LOT_SIZE, + QUOTE_LOT_SIZE, + MIN_ORDER_SIZE, + ); send_transaction_from_instructions( &mut sc.svm, vec![create_ix, init_ix], @@ -508,7 +508,14 @@ fn initialize_market_sets_market_and_order_book() { let mut sc = full_setup(); let create_ix = build_create_order_book_account_ix(&sc, &sc.authority.pubkey()); - let ix = build_initialize_market_ix(&sc, FEE_BASIS_POINTS, TICK_SIZE, BASE_LOT_SIZE, QUOTE_LOT_SIZE, MIN_ORDER_SIZE); + let ix = build_initialize_market_ix( + &sc, + FEE_BASIS_POINTS, + TICK_SIZE, + BASE_LOT_SIZE, + QUOTE_LOT_SIZE, + MIN_ORDER_SIZE, + ); send_transaction_from_instructions( &mut sc.svm, vec![create_ix, ix], @@ -550,7 +557,14 @@ fn initialize_market_user_tracks_market_and_owner() { let mut sc = full_setup(); let create_ix = build_create_order_book_account_ix(&sc, &sc.authority.pubkey()); - let init_ix = build_initialize_market_ix(&sc, FEE_BASIS_POINTS, TICK_SIZE, BASE_LOT_SIZE, QUOTE_LOT_SIZE, MIN_ORDER_SIZE); + let init_ix = build_initialize_market_ix( + &sc, + FEE_BASIS_POINTS, + TICK_SIZE, + BASE_LOT_SIZE, + QUOTE_LOT_SIZE, + MIN_ORDER_SIZE, + ); send_transaction_from_instructions( &mut sc.svm, vec![create_ix, init_ix], @@ -674,12 +688,8 @@ fn place_order_rejects_zero_price() { 0, BID_QUANTITY, ); - let result = send_transaction_from_instructions( - &mut sc.svm, - vec![ix], - &[&sc.buyer], - &sc.buyer.pubkey(), - ); + let result = + send_transaction_from_instructions(&mut sc.svm, vec![ix], &[&sc.buyer], &sc.buyer.pubkey()); assert!(result.is_err(), "order at price 0 must be rejected"); } @@ -691,8 +701,14 @@ fn place_order_rejects_unaligned_tick() { // price and see the tick check fire. let unusual_tick_size: u64 = 50; let create_ix = build_create_order_book_account_ix(&sc, &sc.authority.pubkey()); - let init_ix = - build_initialize_market_ix(&sc, FEE_BASIS_POINTS, unusual_tick_size, BASE_LOT_SIZE, QUOTE_LOT_SIZE, MIN_ORDER_SIZE); + let init_ix = build_initialize_market_ix( + &sc, + FEE_BASIS_POINTS, + unusual_tick_size, + BASE_LOT_SIZE, + QUOTE_LOT_SIZE, + MIN_ORDER_SIZE, + ); send_transaction_from_instructions( &mut sc.svm, vec![create_ix, init_ix], @@ -723,12 +739,8 @@ fn place_order_rejects_unaligned_tick() { unaligned_price, BID_QUANTITY, ); - let result = send_transaction_from_instructions( - &mut sc.svm, - vec![ix], - &[&sc.buyer], - &sc.buyer.pubkey(), - ); + let result = + send_transaction_from_instructions(&mut sc.svm, vec![ix], &[&sc.buyer], &sc.buyer.pubkey()); assert!( result.is_err(), "unaligned price must be rejected by tick check" @@ -742,8 +754,14 @@ fn place_order_rejects_below_min_order_size() { // Force a higher min_order_size so we can place an order below it. let elevated_min_order_size: u64 = 10; let create_ix = build_create_order_book_account_ix(&sc, &sc.authority.pubkey()); - let init_ix = - build_initialize_market_ix(&sc, FEE_BASIS_POINTS, TICK_SIZE, BASE_LOT_SIZE, QUOTE_LOT_SIZE, elevated_min_order_size); + let init_ix = build_initialize_market_ix( + &sc, + FEE_BASIS_POINTS, + TICK_SIZE, + BASE_LOT_SIZE, + QUOTE_LOT_SIZE, + elevated_min_order_size, + ); send_transaction_from_instructions( &mut sc.svm, vec![create_ix, init_ix], @@ -959,12 +977,8 @@ fn cancel_and_settle_bid_refunds_full_quote() { BID_PRICE, BID_QUANTITY, ); - let cancel_ix = build_cancel_order_ix( - &sc, - &sc.buyer.pubkey(), - sc.buyer_market_user, - bid_order_id, - ); + let cancel_ix = + build_cancel_order_ix(&sc, &sc.buyer.pubkey(), sc.buyer_market_user, bid_order_id); let settle_ix = build_settle_funds_ix( &sc, &sc.buyer.pubkey(), @@ -1019,12 +1033,8 @@ fn settle_funds_rejects_fee_vault_substituted_for_quote_vault() { BID_PRICE, BID_QUANTITY, ); - let cancel_ix = build_cancel_order_ix( - &sc, - &sc.buyer.pubkey(), - sc.buyer_market_user, - bid_order_id, - ); + let cancel_ix = + build_cancel_order_ix(&sc, &sc.buyer.pubkey(), sc.buyer_market_user, bid_order_id); send_transaction_from_instructions( &mut sc.svm, vec![place_ix, cancel_ix], @@ -1074,7 +1084,14 @@ fn initialize_market_rejects_zero_tick_size() { let zero_tick_size: u64 = 0; let create_ix = build_create_order_book_account_ix(&sc, &sc.authority.pubkey()); - let ix = build_initialize_market_ix(&sc, FEE_BASIS_POINTS, zero_tick_size, BASE_LOT_SIZE, QUOTE_LOT_SIZE, MIN_ORDER_SIZE); + let ix = build_initialize_market_ix( + &sc, + FEE_BASIS_POINTS, + zero_tick_size, + BASE_LOT_SIZE, + QUOTE_LOT_SIZE, + MIN_ORDER_SIZE, + ); let result = send_transaction_from_instructions( &mut sc.svm, vec![create_ix, ix], @@ -1089,7 +1106,14 @@ fn initialize_market_rejects_zero_base_lot_size() { let mut sc = full_setup(); let create_ix = build_create_order_book_account_ix(&sc, &sc.authority.pubkey()); - let ix = build_initialize_market_ix(&sc, FEE_BASIS_POINTS, TICK_SIZE, 0, QUOTE_LOT_SIZE, MIN_ORDER_SIZE); + let ix = build_initialize_market_ix( + &sc, + FEE_BASIS_POINTS, + TICK_SIZE, + 0, + QUOTE_LOT_SIZE, + MIN_ORDER_SIZE, + ); let result = send_transaction_from_instructions( &mut sc.svm, vec![create_ix, ix], @@ -1104,7 +1128,14 @@ fn initialize_market_rejects_zero_quote_lot_size() { let mut sc = full_setup(); let create_ix = build_create_order_book_account_ix(&sc, &sc.authority.pubkey()); - let ix = build_initialize_market_ix(&sc, FEE_BASIS_POINTS, TICK_SIZE, BASE_LOT_SIZE, 0, MIN_ORDER_SIZE); + let ix = build_initialize_market_ix( + &sc, + FEE_BASIS_POINTS, + TICK_SIZE, + BASE_LOT_SIZE, + 0, + MIN_ORDER_SIZE, + ); let result = send_transaction_from_instructions( &mut sc.svm, vec![create_ix, ix], @@ -1403,13 +1434,8 @@ fn taker_partially_fills_resting_order_rest_stays_on_book() { TAKER_BID_QUANTITY, &[(MAKER_ASK_ID, sc.seller_market_user)], ); - send_transaction_from_instructions( - &mut sc.svm, - vec![bid_ix], - &[&sc.buyer], - &sc.buyer.pubkey(), - ) - .unwrap(); + send_transaction_from_instructions(&mut sc.svm, vec![bid_ix], &[&sc.buyer], &sc.buyer.pubkey()) + .unwrap(); // Maker order: still PartiallyFilled, filled_quantity == TAKER_BID_QUANTITY. let maker_order = order_pda(&sc.program_id, &sc.market, MAKER_ASK_ID); @@ -1478,13 +1504,8 @@ fn taker_partially_filled_remainder_rests_on_book() { TAKER_BID_QUANTITY, &[(MAKER_ASK_ID, sc.seller_market_user)], ); - send_transaction_from_instructions( - &mut sc.svm, - vec![bid_ix], - &[&sc.buyer], - &sc.buyer.pubkey(), - ) - .unwrap(); + send_transaction_from_instructions(&mut sc.svm, vec![bid_ix], &[&sc.buyer], &sc.buyer.pubkey()) + .unwrap(); // Maker ask is fully filled. let maker_order = order_pda(&sc.program_id, &sc.market, MAKER_ASK_ID); @@ -1595,8 +1616,14 @@ fn taker_crosses_multiple_resting_orders_best_price_first() { // Both resting asks are fully filled. let order_one = order_pda(&sc.program_id, &sc.market, BEST_ASK_ID); let order_two = order_pda(&sc.program_id, &sc.market, SECOND_ASK_ID); - assert_eq!(read_order_fill_and_status(&sc.svm, &order_one).1, ORDER_STATUS_FILLED); - assert_eq!(read_order_fill_and_status(&sc.svm, &order_two).1, ORDER_STATUS_FILLED); + assert_eq!( + read_order_fill_and_status(&sc.svm, &order_one).1, + ORDER_STATUS_FILLED + ); + assert_eq!( + read_order_fill_and_status(&sc.svm, &order_two).1, + ORDER_STATUS_FILLED + ); // Taker got TAKER_BID_QUANTITY lots = TAKER_BID_QUANTITY * BASE_LOT_SIZE raw base tokens. let (buyer_base, buyer_quote_rebate) = read_user_unsettled(&sc.svm, &sc.buyer_market_user); @@ -1604,7 +1631,8 @@ fn taker_crosses_multiple_resting_orders_best_price_first() { // Price-improvement rebate: taker locked at 1000/unit but 30 units // filled at 900. Rebate = (1000 - 900) * 30 * quote_lot_size. - const PRICE_IMPROVEMENT_REBATE: u64 = (TAKER_BID_PRICE - BEST_ASK_PRICE) * BEST_ASK_QUANTITY * QUOTE_LOT_SIZE; + const PRICE_IMPROVEMENT_REBATE: u64 = + (TAKER_BID_PRICE - BEST_ASK_PRICE) * BEST_ASK_QUANTITY * QUOTE_LOT_SIZE; assert_eq!(buyer_quote_rebate, PRICE_IMPROVEMENT_REBATE); // Seller's net unsettled_quote = sum of (fill_price * fill_qty * quote_lot_size - fee). @@ -1649,10 +1677,16 @@ fn resting_orders_at_same_price_fill_by_time_priority() { &sc.authority, ) .unwrap(); - let second_seller_market_user = market_user_pda(&sc.program_id, &sc.market, &second_seller.pubkey()); + let second_seller_market_user = + market_user_pda(&sc.program_id, &sc.market, &second_seller.pubkey()); let __ix1 = build_initialize_market_user_ix(&sc, &second_seller.pubkey()); - send_transaction_from_instructions(&mut sc.svm, vec![__ix1], &[&second_seller], - &second_seller.pubkey()).unwrap(); + send_transaction_from_instructions( + &mut sc.svm, + vec![__ix1], + &[&second_seller], + &second_seller.pubkey(), + ) + .unwrap(); const FIRST_ASK_ID: u64 = 1; const SECOND_ASK_ID: u64 = 2; @@ -1661,32 +1695,42 @@ fn resting_orders_at_same_price_fill_by_time_priority() { // Seller 1 first in. let __ix2 = build_place_order_ix( - &sc, - &sc.seller, - sc.seller_market_user, - sc.seller_base_ata, - sc.seller_quote_ata, - order_book::state::OrderSide::Ask, - FIRST_ASK_ID, - ASK_PRICE_SHARED, - ASK_QUANTITY_EACH, - ); - send_transaction_from_instructions(&mut sc.svm, vec![__ix2], &[&sc.seller], - &sc.seller.pubkey()).unwrap(); + &sc, + &sc.seller, + sc.seller_market_user, + sc.seller_base_ata, + sc.seller_quote_ata, + order_book::state::OrderSide::Ask, + FIRST_ASK_ID, + ASK_PRICE_SHARED, + ASK_QUANTITY_EACH, + ); + send_transaction_from_instructions( + &mut sc.svm, + vec![__ix2], + &[&sc.seller], + &sc.seller.pubkey(), + ) + .unwrap(); // Seller 2 second in at the same price. let __ix3 = build_place_order_ix( - &sc, - &second_seller, - second_seller_market_user, - second_seller_base_ata, - second_seller_quote_ata, - order_book::state::OrderSide::Ask, - SECOND_ASK_ID, - ASK_PRICE_SHARED, - ASK_QUANTITY_EACH, - ); - send_transaction_from_instructions(&mut sc.svm, vec![__ix3], &[&second_seller], - &second_seller.pubkey()).unwrap(); + &sc, + &second_seller, + second_seller_market_user, + second_seller_base_ata, + second_seller_quote_ata, + order_book::state::OrderSide::Ask, + SECOND_ASK_ID, + ASK_PRICE_SHARED, + ASK_QUANTITY_EACH, + ); + send_transaction_from_instructions( + &mut sc.svm, + vec![__ix3], + &[&second_seller], + &second_seller.pubkey(), + ) + .unwrap(); // Taker bid buys only enough to cross seller 1's ask. const TAKER_BID_ID: u64 = 3; @@ -1713,8 +1757,14 @@ fn resting_orders_at_same_price_fill_by_time_priority() { // Time priority: seller 1 filled, seller 2 still open. let order_one = order_pda(&sc.program_id, &sc.market, FIRST_ASK_ID); let order_two = order_pda(&sc.program_id, &sc.market, SECOND_ASK_ID); - assert_eq!(read_order_fill_and_status(&sc.svm, &order_one).1, ORDER_STATUS_FILLED); - assert_eq!(read_order_fill_and_status(&sc.svm, &order_two).1, ORDER_STATUS_OPEN); + assert_eq!( + read_order_fill_and_status(&sc.svm, &order_one).1, + ORDER_STATUS_FILLED + ); + assert_eq!( + read_order_fill_and_status(&sc.svm, &order_two).1, + ORDER_STATUS_OPEN + ); } #[test] @@ -1731,18 +1781,23 @@ fn taker_bid_gets_price_improvement_from_resting_ask() { // Maker ask. let __ix4 = build_place_order_ix( - &sc, - &sc.seller, - sc.seller_market_user, - sc.seller_base_ata, - sc.seller_quote_ata, - order_book::state::OrderSide::Ask, - MAKER_ASK_ID, - MAKER_ASK_PRICE, - QUANTITY, - ); - send_transaction_from_instructions(&mut sc.svm, vec![__ix4], &[&sc.seller], - &sc.seller.pubkey()).unwrap(); + &sc, + &sc.seller, + sc.seller_market_user, + sc.seller_base_ata, + sc.seller_quote_ata, + order_book::state::OrderSide::Ask, + MAKER_ASK_ID, + MAKER_ASK_PRICE, + QUANTITY, + ); + send_transaction_from_instructions( + &mut sc.svm, + vec![__ix4], + &[&sc.seller], + &sc.seller.pubkey(), + ) + .unwrap(); // Taker bid - limit 1000. const TAKER_BID_ID: u64 = 2; @@ -1810,8 +1865,13 @@ fn fee_rounds_up_when_gross_is_not_a_bps_multiple() { PRICE, QUANTITY, ); - send_transaction_from_instructions(&mut sc.svm, vec![maker_ix], &[&sc.seller], - &sc.seller.pubkey()).unwrap(); + send_transaction_from_instructions( + &mut sc.svm, + vec![maker_ix], + &[&sc.seller], + &sc.seller.pubkey(), + ) + .unwrap(); const TAKER_BID_ID: u64 = 2; let taker_ix = build_place_order_with_makers_ix( @@ -1826,8 +1886,13 @@ fn fee_rounds_up_when_gross_is_not_a_bps_multiple() { QUANTITY, &[(MAKER_ASK_ID, sc.seller_market_user)], ); - send_transaction_from_instructions(&mut sc.svm, vec![taker_ix], &[&sc.buyer], - &sc.buyer.pubkey()).unwrap(); + send_transaction_from_instructions( + &mut sc.svm, + vec![taker_ix], + &[&sc.buyer], + &sc.buyer.pubkey(), + ) + .unwrap(); assert_eq!( get_token_account_balance(&sc.svm, &sc.fee_vault).unwrap(), @@ -1852,34 +1917,39 @@ fn fee_vault_receives_exactly_bps_of_taker_gross() { const EXPECTED_FEE: u64 = fee_ceil(GROSS); let __ix5 = build_place_order_ix( - &sc, - &sc.seller, - sc.seller_market_user, - sc.seller_base_ata, - sc.seller_quote_ata, - order_book::state::OrderSide::Ask, - MAKER_ASK_ID, - PRICE, - QUANTITY, - ); - send_transaction_from_instructions(&mut sc.svm, vec![__ix5], &[&sc.seller], - &sc.seller.pubkey()).unwrap(); + &sc, + &sc.seller, + sc.seller_market_user, + sc.seller_base_ata, + sc.seller_quote_ata, + order_book::state::OrderSide::Ask, + MAKER_ASK_ID, + PRICE, + QUANTITY, + ); + send_transaction_from_instructions( + &mut sc.svm, + vec![__ix5], + &[&sc.seller], + &sc.seller.pubkey(), + ) + .unwrap(); const TAKER_BID_ID: u64 = 2; let __ix6 = build_place_order_with_makers_ix( - &sc, - &sc.buyer, - sc.buyer_market_user, - sc.buyer_base_ata, - sc.buyer_quote_ata, - order_book::state::OrderSide::Bid, - TAKER_BID_ID, - PRICE, - QUANTITY, - &[(MAKER_ASK_ID, sc.seller_market_user)], + &sc, + &sc.buyer, + sc.buyer_market_user, + sc.buyer_base_ata, + sc.buyer_quote_ata, + order_book::state::OrderSide::Bid, + TAKER_BID_ID, + PRICE, + QUANTITY, + &[(MAKER_ASK_ID, sc.seller_market_user)], ); - send_transaction_from_instructions(&mut sc.svm, vec![__ix6], &[&sc.buyer], &sc.buyer.pubkey()).unwrap(); - + send_transaction_from_instructions(&mut sc.svm, vec![__ix6], &[&sc.buyer], &sc.buyer.pubkey()) + .unwrap(); assert_eq!( get_token_account_balance(&sc.svm, &sc.fee_vault).unwrap(), @@ -1909,34 +1979,39 @@ fn authority_can_withdraw_fees_after_match() { const EXPECTED_FEE: u64 = fee_ceil(GROSS); let __ix7 = build_place_order_ix( - &sc, - &sc.seller, - sc.seller_market_user, - sc.seller_base_ata, - sc.seller_quote_ata, - order_book::state::OrderSide::Ask, - MAKER_ASK_ID, - PRICE, - QUANTITY, - ); - send_transaction_from_instructions(&mut sc.svm, vec![__ix7], &[&sc.seller], - &sc.seller.pubkey()).unwrap(); + &sc, + &sc.seller, + sc.seller_market_user, + sc.seller_base_ata, + sc.seller_quote_ata, + order_book::state::OrderSide::Ask, + MAKER_ASK_ID, + PRICE, + QUANTITY, + ); + send_transaction_from_instructions( + &mut sc.svm, + vec![__ix7], + &[&sc.seller], + &sc.seller.pubkey(), + ) + .unwrap(); const TAKER_BID_ID: u64 = 2; let __ix8 = build_place_order_with_makers_ix( - &sc, - &sc.buyer, - sc.buyer_market_user, - sc.buyer_base_ata, - sc.buyer_quote_ata, - order_book::state::OrderSide::Bid, - TAKER_BID_ID, - PRICE, - QUANTITY, - &[(MAKER_ASK_ID, sc.seller_market_user)], + &sc, + &sc.buyer, + sc.buyer_market_user, + sc.buyer_base_ata, + sc.buyer_quote_ata, + order_book::state::OrderSide::Bid, + TAKER_BID_ID, + PRICE, + QUANTITY, + &[(MAKER_ASK_ID, sc.seller_market_user)], ); - send_transaction_from_instructions(&mut sc.svm, vec![__ix8], &[&sc.buyer], &sc.buyer.pubkey()).unwrap(); - + send_transaction_from_instructions(&mut sc.svm, vec![__ix8], &[&sc.buyer], &sc.buyer.pubkey()) + .unwrap(); assert_eq!( get_token_account_balance(&sc.svm, &sc.fee_vault).unwrap(), @@ -1980,53 +2055,63 @@ fn settle_funds_after_match_pays_out_both_unsettled_balances() { // Maker posts and taker crosses. let __ix9 = build_place_order_ix( - &sc, - &sc.seller, - sc.seller_market_user, - sc.seller_base_ata, - sc.seller_quote_ata, - order_book::state::OrderSide::Ask, - MAKER_ASK_ID, - PRICE, - QUANTITY, - ); - send_transaction_from_instructions(&mut sc.svm, vec![__ix9], &[&sc.seller], - &sc.seller.pubkey()).unwrap(); + &sc, + &sc.seller, + sc.seller_market_user, + sc.seller_base_ata, + sc.seller_quote_ata, + order_book::state::OrderSide::Ask, + MAKER_ASK_ID, + PRICE, + QUANTITY, + ); + send_transaction_from_instructions( + &mut sc.svm, + vec![__ix9], + &[&sc.seller], + &sc.seller.pubkey(), + ) + .unwrap(); const TAKER_BID_ID: u64 = 2; let __ix10 = build_place_order_with_makers_ix( - &sc, - &sc.buyer, - sc.buyer_market_user, - sc.buyer_base_ata, - sc.buyer_quote_ata, - order_book::state::OrderSide::Bid, - TAKER_BID_ID, - PRICE, - QUANTITY, - &[(MAKER_ASK_ID, sc.seller_market_user)], + &sc, + &sc.buyer, + sc.buyer_market_user, + sc.buyer_base_ata, + sc.buyer_quote_ata, + order_book::state::OrderSide::Bid, + TAKER_BID_ID, + PRICE, + QUANTITY, + &[(MAKER_ASK_ID, sc.seller_market_user)], ); - send_transaction_from_instructions(&mut sc.svm, vec![__ix10], &[&sc.buyer], &sc.buyer.pubkey()).unwrap(); - + send_transaction_from_instructions(&mut sc.svm, vec![__ix10], &[&sc.buyer], &sc.buyer.pubkey()) + .unwrap(); // Settle both sides. let __ix11 = build_settle_funds_ix( - &sc, - &sc.buyer.pubkey(), - sc.buyer_market_user, - sc.buyer_base_ata, - sc.buyer_quote_ata, - ); - send_transaction_from_instructions(&mut sc.svm, vec![__ix11], &[&sc.buyer], - &sc.buyer.pubkey()).unwrap(); + &sc, + &sc.buyer.pubkey(), + sc.buyer_market_user, + sc.buyer_base_ata, + sc.buyer_quote_ata, + ); + send_transaction_from_instructions(&mut sc.svm, vec![__ix11], &[&sc.buyer], &sc.buyer.pubkey()) + .unwrap(); let __ix12 = build_settle_funds_ix( - &sc, - &sc.seller.pubkey(), - sc.seller_market_user, - sc.seller_base_ata, - sc.seller_quote_ata, - ); - send_transaction_from_instructions(&mut sc.svm, vec![__ix12], &[&sc.seller], - &sc.seller.pubkey()).unwrap(); + &sc, + &sc.seller.pubkey(), + sc.seller_market_user, + sc.seller_base_ata, + sc.seller_quote_ata, + ); + send_transaction_from_instructions( + &mut sc.svm, + vec![__ix12], + &[&sc.seller], + &sc.seller.pubkey(), + ) + .unwrap(); // Buyer should now hold `QUANTITY` lots of extra base tokens // (QUANTITY * BASE_LOT_SIZE raw minor units) and have paid the gross @@ -2053,7 +2138,6 @@ fn settle_funds_after_match_pays_out_both_unsettled_balances() { ); } - // --------------------------------------------------------------------------- // Worst-case tree depth // diff --git a/finance/token-fundraiser/anchor-v1/programs/fundraiser/src/constants.rs b/finance/token-fundraiser/anchor-v1/programs/fundraiser/src/constants.rs index fc0697b02..2af19dd91 100644 --- a/finance/token-fundraiser/anchor-v1/programs/fundraiser/src/constants.rs +++ b/finance/token-fundraiser/anchor-v1/programs/fundraiser/src/constants.rs @@ -1,4 +1,4 @@ pub const MIN_AMOUNT_TO_RAISE: u64 = 3; pub const SECONDS_TO_DAYS: i64 = 86400; pub const MAX_CONTRIBUTION_PERCENTAGE: u64 = 10; -pub const PERCENTAGE_SCALER: u64 = 100; \ No newline at end of file +pub const PERCENTAGE_SCALER: u64 = 100; diff --git a/finance/token-fundraiser/anchor-v1/programs/fundraiser/src/instructions/checker.rs b/finance/token-fundraiser/anchor-v1/programs/fundraiser/src/instructions/checker.rs index 333bae498..8eec93b13 100644 --- a/finance/token-fundraiser/anchor-v1/programs/fundraiser/src/instructions/checker.rs +++ b/finance/token-fundraiser/anchor-v1/programs/fundraiser/src/instructions/checker.rs @@ -90,11 +90,8 @@ pub fn handle_check_contributions( destination: accounts.maker.to_account_info(), authority: accounts.fundraiser.to_account_info(), }; - let close_context = CpiContext::new_with_signer( - accounts.token_program.key(), - close_accounts, - &signer_seeds, - ); + let close_context = + CpiContext::new_with_signer(accounts.token_program.key(), close_accounts, &signer_seeds); close_account(close_context)?; Ok(()) diff --git a/finance/token-fundraiser/anchor-v1/programs/fundraiser/src/instructions/close.rs b/finance/token-fundraiser/anchor-v1/programs/fundraiser/src/instructions/close.rs index c888cbc26..5bd758fa1 100644 --- a/finance/token-fundraiser/anchor-v1/programs/fundraiser/src/instructions/close.rs +++ b/finance/token-fundraiser/anchor-v1/programs/fundraiser/src/instructions/close.rs @@ -120,11 +120,8 @@ pub fn handle_close_fundraiser(accounts: &mut CloseFundraiserAccountConstraints) destination: accounts.maker.to_account_info(), authority: accounts.fundraiser.to_account_info(), }; - let close_context = CpiContext::new_with_signer( - accounts.token_program.key(), - close_accounts, - &signer_seeds, - ); + let close_context = + CpiContext::new_with_signer(accounts.token_program.key(), close_accounts, &signer_seeds); close_account(close_context)?; Ok(()) diff --git a/finance/token-fundraiser/anchor-v1/programs/fundraiser/src/instructions/mod.rs b/finance/token-fundraiser/anchor-v1/programs/fundraiser/src/instructions/mod.rs index 55a06bbb0..b188ee75d 100644 --- a/finance/token-fundraiser/anchor-v1/programs/fundraiser/src/instructions/mod.rs +++ b/finance/token-fundraiser/anchor-v1/programs/fundraiser/src/instructions/mod.rs @@ -1,13 +1,13 @@ -pub mod initialize_fundraiser; -pub mod contribute; pub mod checker; -pub mod refund; pub mod close; pub mod close_contributor; +pub mod contribute; +pub mod initialize_fundraiser; +pub mod refund; -pub use initialize_fundraiser::*; -pub use contribute::*; pub use checker::*; -pub use refund::*; pub use close::*; -pub use close_contributor::*; \ No newline at end of file +pub use close_contributor::*; +pub use contribute::*; +pub use initialize_fundraiser::*; +pub use refund::*; diff --git a/finance/token-fundraiser/anchor-v1/programs/fundraiser/src/instructions/refund.rs b/finance/token-fundraiser/anchor-v1/programs/fundraiser/src/instructions/refund.rs index 61fb2babe..a58e33dd2 100644 --- a/finance/token-fundraiser/anchor-v1/programs/fundraiser/src/instructions/refund.rs +++ b/finance/token-fundraiser/anchor-v1/programs/fundraiser/src/instructions/refund.rs @@ -98,16 +98,9 @@ pub fn handle_refund(accounts: &mut RefundAccountConstraints) -> Result<()> { accounts.maker.to_account_info().key.as_ref(), &[accounts.fundraiser.bump], ]]; - let cpi_context = CpiContext::new_with_signer( - accounts.token_program.key(), - cpi_accounts, - &signer_seeds, - ); - transfer_checked( - cpi_context, - refund_amount, - accounts.mint_to_raise.decimals, - )?; + let cpi_context = + CpiContext::new_with_signer(accounts.token_program.key(), cpi_accounts, &signer_seeds); + transfer_checked(cpi_context, refund_amount, accounts.mint_to_raise.decimals)?; Ok(()) } diff --git a/finance/token-fundraiser/anchor-v1/programs/fundraiser/src/state/contributor.rs b/finance/token-fundraiser/anchor-v1/programs/fundraiser/src/state/contributor.rs index 33b0c00e4..1fa309b19 100644 --- a/finance/token-fundraiser/anchor-v1/programs/fundraiser/src/state/contributor.rs +++ b/finance/token-fundraiser/anchor-v1/programs/fundraiser/src/state/contributor.rs @@ -6,4 +6,4 @@ pub struct Contributor { pub amount: u64, /// Canonical bump for this PDA. pub bump: u8, -} \ No newline at end of file +} diff --git a/finance/token-fundraiser/anchor-v1/programs/fundraiser/src/state/fundraiser.rs b/finance/token-fundraiser/anchor-v1/programs/fundraiser/src/state/fundraiser.rs index cab7d1c60..ceaf9c2ed 100644 --- a/finance/token-fundraiser/anchor-v1/programs/fundraiser/src/state/fundraiser.rs +++ b/finance/token-fundraiser/anchor-v1/programs/fundraiser/src/state/fundraiser.rs @@ -10,4 +10,4 @@ pub struct Fundraiser { pub time_started: i64, pub duration: u16, pub bump: u8, -} \ No newline at end of file +} diff --git a/finance/token-fundraiser/anchor-v1/programs/fundraiser/src/state/mod.rs b/finance/token-fundraiser/anchor-v1/programs/fundraiser/src/state/mod.rs index 3e6b07fdb..d4c1b8235 100644 --- a/finance/token-fundraiser/anchor-v1/programs/fundraiser/src/state/mod.rs +++ b/finance/token-fundraiser/anchor-v1/programs/fundraiser/src/state/mod.rs @@ -1,5 +1,5 @@ -pub mod fundraiser; pub mod contributor; +pub mod fundraiser; +pub use contributor::*; pub use fundraiser::*; -pub use contributor::*; \ No newline at end of file diff --git a/finance/token-fundraiser/anchor-v1/programs/fundraiser/tests/test_fundraiser.rs b/finance/token-fundraiser/anchor-v1/programs/fundraiser/tests/test_fundraiser.rs index 12068ddfe..023266289 100644 --- a/finance/token-fundraiser/anchor-v1/programs/fundraiser/tests/test_fundraiser.rs +++ b/finance/token-fundraiser/anchor-v1/programs/fundraiser/tests/test_fundraiser.rs @@ -9,7 +9,8 @@ use { solana_keypair::Keypair, solana_kite::{ create_associated_token_account, create_token_mint, create_wallet, - get_token_account_balance, mint_tokens_to_token_account, send_transaction_from_instructions, + get_token_account_balance, mint_tokens_to_token_account, + send_transaction_from_instructions, }, solana_signer::Signer, }; @@ -296,7 +297,10 @@ fn test_initialize_fundraiser() { assert_eq!(fundraiser_state.current_amount, 0); assert_eq!(fundraiser_state.duration, DURATION_DAYS); - assert_eq!(get_token_account_balance(&setup.svm, &setup.vault).unwrap(), 0); + assert_eq!( + get_token_account_balance(&setup.svm, &setup.vault).unwrap(), + 0 + ); } #[test] @@ -329,7 +333,10 @@ fn test_initialize_below_minimum_target_fails() { &[&setup.maker], &setup.maker.pubkey(), ); - assert!(result.is_err(), "Target below 3 major units must be rejected"); + assert!( + result.is_err(), + "Target below 3 major units must be rejected" + ); assert!( setup.svm.get_account(&setup.fundraiser_pda).is_none(), "Fundraiser account must not exist after a failed initialize" @@ -404,7 +411,10 @@ fn test_contribute_after_deadline_fails() { ); assert!(result.is_err(), "Contributing after the deadline must fail"); - assert_eq!(get_token_account_balance(&setup.svm, &setup.vault).unwrap(), 0); + assert_eq!( + get_token_account_balance(&setup.svm, &setup.vault).unwrap(), + 0 + ); assert_eq!( get_token_account_balance(&setup.svm, &contributor_ata).unwrap(), CONTRIBUTOR_STARTING_BALANCE @@ -436,7 +446,10 @@ fn test_contribute_below_one_major_unit_fails() { result.is_err(), "Contributions below one major unit must fail" ); - assert_eq!(get_token_account_balance(&setup.svm, &setup.vault).unwrap(), 0); + assert_eq!( + get_token_account_balance(&setup.svm, &setup.vault).unwrap(), + 0 + ); } #[test] @@ -525,7 +538,10 @@ fn test_refund_after_deadline_target_not_met_succeeds() { ) .unwrap(); - assert_eq!(get_token_account_balance(&setup.svm, &setup.vault).unwrap(), 0); + assert_eq!( + get_token_account_balance(&setup.svm, &setup.vault).unwrap(), + 0 + ); assert_eq!( get_token_account_balance(&setup.svm, &contributor_ata).unwrap(), CONTRIBUTOR_STARTING_BALANCE @@ -672,7 +688,10 @@ fn test_contribute_above_cap_fails() { result.is_err(), "A single contribution above the 10% cap must fail" ); - assert_eq!(get_token_account_balance(&setup.svm, &setup.vault).unwrap(), 0); + assert_eq!( + get_token_account_balance(&setup.svm, &setup.vault).unwrap(), + 0 + ); } #[test] @@ -797,7 +816,10 @@ fn test_close_fundraiser_after_failed_raise_allows_a_new_raise() { let fundraiser_state = read_fundraiser_state(&setup.svm, &setup.fundraiser_pda); assert_eq!(fundraiser_state.current_amount, 0); assert_eq!(fundraiser_state.amount_to_raise, AMOUNT_TO_RAISE); - assert_eq!(get_token_account_balance(&setup.svm, &setup.vault).unwrap(), 0); + assert_eq!( + get_token_account_balance(&setup.svm, &setup.vault).unwrap(), + 0 + ); } #[test] @@ -922,8 +944,14 @@ fn test_close_fundraiser_sweeps_direct_donations_to_maker() { // accounting; on close they go to the maker instead of being burned // with the account. let donation = 5 * ONE_TOKEN; - mint_tokens_to_token_account(&mut setup.svm, &setup.mint, &setup.vault, donation, &setup.payer) - .unwrap(); + mint_tokens_to_token_account( + &mut setup.svm, + &setup.mint, + &setup.vault, + donation, + &setup.payer, + ) + .unwrap(); warp_days_forward(&mut setup.svm, DURATION_DAYS as i64 + 1); diff --git a/tokens/create-token/anchor-v1/programs/create-token/tests/test_create_token.rs b/tokens/create-token/anchor-v1/programs/create-token/tests/test_create_token.rs index 11e7bf7a0..4f393daa9 100644 --- a/tokens/create-token/anchor-v1/programs/create-token/tests/test_create_token.rs +++ b/tokens/create-token/anchor-v1/programs/create-token/tests/test_create_token.rs @@ -90,7 +90,10 @@ fn test_create_spl_token() { let mint_account = svm .get_account(&mint_keypair.pubkey()) .expect("Mint account should exist"); - assert!(!mint_account.data.is_empty(), "Mint account should have data"); + assert!( + !mint_account.data.is_empty(), + "Mint account should have data" + ); // Verify the metadata account was created let meta_account = svm @@ -141,5 +144,8 @@ fn test_create_nft() { let mint_account = svm .get_account(&mint_keypair.pubkey()) .expect("Mint account should exist"); - assert!(!mint_account.data.is_empty(), "Mint account should have data"); + assert!( + !mint_account.data.is_empty(), + "Mint account should have data" + ); } diff --git a/tokens/external-delegate-token-master/anchor-v1/programs/external-delegate-token-master/src/instructions/transfer_tokens.rs b/tokens/external-delegate-token-master/anchor-v1/programs/external-delegate-token-master/src/instructions/transfer_tokens.rs index 4ab2c8631..6eaa70a60 100644 --- a/tokens/external-delegate-token-master/anchor-v1/programs/external-delegate-token-master/src/instructions/transfer_tokens.rs +++ b/tokens/external-delegate-token-master/anchor-v1/programs/external-delegate-token-master/src/instructions/transfer_tokens.rs @@ -3,7 +3,9 @@ use anchor_spl::token_interface::{ transfer_checked, Mint, TokenAccount, TokenInterface, TransferChecked, }; -use crate::{build_transfer_authorization_message, verify_ethereum_signature, ErrorCode, UserAccount}; +use crate::{ + build_transfer_authorization_message, verify_ethereum_signature, ErrorCode, UserAccount, +}; #[derive(Accounts)] pub struct TransferTokensAccountConstraints<'info> { diff --git a/tokens/external-delegate-token-master/anchor-v1/programs/external-delegate-token-master/tests/test_external_delegate.rs b/tokens/external-delegate-token-master/anchor-v1/programs/external-delegate-token-master/tests/test_external_delegate.rs index 4b6d73bdc..900aa1af6 100644 --- a/tokens/external-delegate-token-master/anchor-v1/programs/external-delegate-token-master/tests/test_external_delegate.rs +++ b/tokens/external-delegate-token-master/anchor-v1/programs/external-delegate-token-master/tests/test_external_delegate.rs @@ -9,7 +9,8 @@ use { solana_keypair::Keypair, solana_kite::{ create_associated_token_account, create_token_mint, create_wallet, - get_token_account_balance, mint_tokens_to_token_account, send_transaction_from_instructions, + get_token_account_balance, mint_tokens_to_token_account, + send_transaction_from_instructions, }, solana_signer::Signer, }; @@ -185,8 +186,14 @@ fn setup_transfer_fixture() -> TransferFixture { let mint = create_token_mint(&mut svm, &authority, MINT_DECIMALS, None).unwrap(); let user_pda_token_account = create_associated_token_account(&mut svm, &user_pda, &mint, &authority).unwrap(); - mint_tokens_to_token_account(&mut svm, &mint, &user_pda_token_account, MINT_AMOUNT, &authority) - .unwrap(); + mint_tokens_to_token_account( + &mut svm, + &mint, + &user_pda_token_account, + MINT_AMOUNT, + &authority, + ) + .unwrap(); let recipient = Keypair::new(); let recipient_token_account = @@ -295,7 +302,10 @@ fn test_transfer_tokens_with_valid_signature_moves_tokens_and_increments_nonce() get_token_account_balance(&fixture.svm, &fixture.user_pda_token_account).unwrap(), MINT_AMOUNT - TRANSFER_AMOUNT ); - assert_eq!(read_user_account(&fixture.svm, &fixture.user_account).nonce, 1); + assert_eq!( + read_user_account(&fixture.svm, &fixture.user_account).nonce, + 1 + ); } #[test] @@ -336,14 +346,20 @@ fn test_transfer_tokens_replayed_signature_fails() { &[&fixture.authority], &authority_pubkey, ); - assert!(replay_result.is_err(), "replayed signature must be rejected"); + assert!( + replay_result.is_err(), + "replayed signature must be rejected" + ); // Exactly one transfer happened. assert_eq!( get_token_account_balance(&fixture.svm, &fixture.recipient_token_account).unwrap(), TRANSFER_AMOUNT ); - assert_eq!(read_user_account(&fixture.svm, &fixture.user_account).nonce, 1); + assert_eq!( + read_user_account(&fixture.svm, &fixture.user_account).nonce, + 1 + ); } #[test] @@ -383,7 +399,10 @@ fn test_transfer_tokens_signature_over_different_amount_fails() { get_token_account_balance(&fixture.svm, &fixture.recipient_token_account).unwrap(), 0 ); - assert_eq!(read_user_account(&fixture.svm, &fixture.user_account).nonce, 0); + assert_eq!( + read_user_account(&fixture.svm, &fixture.user_account).nonce, + 0 + ); } #[test] diff --git a/tokens/nft-minter/anchor-v1/programs/nft-minter/tests/test_nft_minter.rs b/tokens/nft-minter/anchor-v1/programs/nft-minter/tests/test_nft_minter.rs index 733c91afe..9dabc4c89 100644 --- a/tokens/nft-minter/anchor-v1/programs/nft-minter/tests/test_nft_minter.rs +++ b/tokens/nft-minter/anchor-v1/programs/nft-minter/tests/test_nft_minter.rs @@ -5,9 +5,7 @@ use { }, litesvm::LiteSVM, solana_keypair::Keypair, - solana_kite::{ - create_wallet, get_token_account_balance, send_transaction_from_instructions, - }, + solana_kite::{create_wallet, get_token_account_balance, send_transaction_from_instructions}, solana_signer::Signer, }; diff --git a/tokens/nft-operations/anchor-v1/programs/mint-nft/src/instructions/verify_collection.rs b/tokens/nft-operations/anchor-v1/programs/mint-nft/src/instructions/verify_collection.rs index 4748ec254..9346f941c 100644 --- a/tokens/nft-operations/anchor-v1/programs/mint-nft/src/instructions/verify_collection.rs +++ b/tokens/nft-operations/anchor-v1/programs/mint-nft/src/instructions/verify_collection.rs @@ -1,19 +1,13 @@ use anchor_lang::prelude::*; use anchor_spl::metadata::mpl_token_metadata::instructions::{ - VerifyCollectionV1Cpi, - VerifyCollectionV1CpiAccounts, -}; -use anchor_spl::metadata::{ - MasterEditionAccount, - MetadataAccount, -}; -use anchor_spl::{ - token::Mint, - metadata::Metadata, + VerifyCollectionV1Cpi, VerifyCollectionV1CpiAccounts, }; +use anchor_spl::metadata::{MasterEditionAccount, MetadataAccount}; +use anchor_spl::{metadata::Metadata, token::Mint}; // In Anchor 1.0, sysvar::instructions::ID moved - use the well-known address directly -const INSTRUCTIONS_SYSVAR_ID: Pubkey = anchor_lang::solana_program::pubkey::pubkey!("Sysvar1nstructions1111111111111111111111111"); +const INSTRUCTIONS_SYSVAR_ID: Pubkey = + anchor_lang::solana_program::pubkey::pubkey!("Sysvar1nstructions1111111111111111111111111"); #[derive(Accounts)] pub struct VerifyCollectionMintAccountConstraints<'info> { @@ -42,23 +36,20 @@ pub fn handle_verify_collection( accounts: &mut VerifyCollectionMintAccountConstraints, bumps: &VerifyCollectionMintAccountConstraintsBumps, ) -> Result<()> { - let metadata = &accounts.metadata.to_account_info(); - let authority = &accounts.mint_authority.to_account_info(); - let collection_mint = &accounts.collection_mint.to_account_info(); - let collection_metadata = &accounts.collection_metadata.to_account_info(); - let collection_master_edition = &accounts.collection_master_edition.to_account_info(); - let system_program = &accounts.system_program.to_account_info(); - let sysvar_instructions = &accounts.sysvar_instruction.to_account_info(); - let spl_metadata_program = &accounts.token_metadata_program.to_account_info(); + let metadata = &accounts.metadata.to_account_info(); + let authority = &accounts.mint_authority.to_account_info(); + let collection_mint = &accounts.collection_mint.to_account_info(); + let collection_metadata = &accounts.collection_metadata.to_account_info(); + let collection_master_edition = &accounts.collection_master_edition.to_account_info(); + let system_program = &accounts.system_program.to_account_info(); + let sysvar_instructions = &accounts.sysvar_instruction.to_account_info(); + let spl_metadata_program = &accounts.token_metadata_program.to_account_info(); - let seeds = &[ - &b"authority"[..], - &[bumps.mint_authority] - ]; - let signer_seeds = &[&seeds[..]]; + let seeds = &[&b"authority"[..], &[bumps.mint_authority]]; + let signer_seeds = &[&seeds[..]]; - let verify_collection = VerifyCollectionV1Cpi::new( - spl_metadata_program, + let verify_collection = VerifyCollectionV1Cpi::new( + spl_metadata_program, VerifyCollectionV1CpiAccounts { authority, delegate_record: None, @@ -68,10 +59,11 @@ pub fn handle_verify_collection( collection_master_edition: Some(collection_master_edition), system_program, sysvar_instructions, - }); - verify_collection.invoke_signed(signer_seeds)?; + }, + ); + verify_collection.invoke_signed(signer_seeds)?; - msg!("Collection Verified!"); - - Ok(()) - } + msg!("Collection Verified!"); + + Ok(()) +} diff --git a/tokens/nft-operations/anchor-v1/programs/mint-nft/src/lib.rs b/tokens/nft-operations/anchor-v1/programs/mint-nft/src/lib.rs index 2e1c3eac5..0ede1f392 100644 --- a/tokens/nft-operations/anchor-v1/programs/mint-nft/src/lib.rs +++ b/tokens/nft-operations/anchor-v1/programs/mint-nft/src/lib.rs @@ -35,7 +35,13 @@ pub mod mint_nft { symbol: String, uri: String, ) -> Result<()> { - instructions::mint_nft::handle_mint_nft(&mut context.accounts, &context.bumps, name, symbol, uri) + instructions::mint_nft::handle_mint_nft( + &mut context.accounts, + &context.bumps, + name, + symbol, + uri, + ) } /// Verify an NFT as a member of the collection. diff --git a/tokens/nft-operations/anchor-v1/programs/mint-nft/tests/test_nft_operations.rs b/tokens/nft-operations/anchor-v1/programs/mint-nft/tests/test_nft_operations.rs index 93bb7e51c..249860449 100644 --- a/tokens/nft-operations/anchor-v1/programs/mint-nft/tests/test_nft_operations.rs +++ b/tokens/nft-operations/anchor-v1/programs/mint-nft/tests/test_nft_operations.rs @@ -5,9 +5,7 @@ use { }, litesvm::LiteSVM, solana_keypair::Keypair, - solana_kite::{ - create_wallet, get_token_account_balance, send_transaction_from_instructions, - }, + solana_kite::{create_wallet, get_token_account_balance, send_transaction_from_instructions}, solana_signer::Signer, }; @@ -70,7 +68,9 @@ fn derive_edition_pda(mint: &Pubkey) -> Pubkey { /// caller-supplied metadata strings landed in the Metaplex metadata account /// without fully deserializing the Metaplex layout. fn contains_bytes(haystack: &[u8], needle: &[u8]) -> bool { - haystack.windows(needle.len()).any(|window| window == needle) + haystack + .windows(needle.len()) + .any(|window| window == needle) } fn setup() -> (LiteSVM, Pubkey, Keypair) { @@ -137,9 +137,7 @@ fn test_create_collection() { assert!(!mint_account.data.is_empty()); // Verify metadata exists and carries the caller-supplied name - let meta_account = svm - .get_account(&metadata) - .expect("Metadata should exist"); + let meta_account = svm.get_account(&metadata).expect("Metadata should exist"); assert!(!meta_account.data.is_empty()); assert!( contains_bytes(&meta_account.data, b"Example Collection"), @@ -356,13 +354,8 @@ fn test_verify_collection() { .to_account_metas(None), ); - send_transaction_from_instructions( - &mut svm, - vec![verify_ix], - &[&payer], - &payer.pubkey(), - ) - .unwrap(); + send_transaction_from_instructions(&mut svm, vec![verify_ix], &[&payer], &payer.pubkey()) + .unwrap(); // Verify the metadata still exists after verification let nft_meta = svm diff --git a/tokens/pda-mint-authority/anchor-v1/programs/token-minter/src/instructions/mint.rs b/tokens/pda-mint-authority/anchor-v1/programs/token-minter/src/instructions/mint.rs index eedae32c9..eef568695 100644 --- a/tokens/pda-mint-authority/anchor-v1/programs/token-minter/src/instructions/mint.rs +++ b/tokens/pda-mint-authority/anchor-v1/programs/token-minter/src/instructions/mint.rs @@ -40,10 +40,7 @@ pub struct MintTokenAccountConstraints<'info> { /// `amount` is in minor units (the raw integer the token program operates /// on). Clients convert from major units, e.g. 1 token with 9 decimals is /// `1 * 10u64.pow(9)` minor units. -pub fn handle_mint_token( - context: Context, - amount: u64, -) -> Result<()> { +pub fn handle_mint_token(context: Context, amount: u64) -> Result<()> { msg!("Minting token to associated token account..."); msg!("Mint: {}", &context.accounts.mint_account.key()); msg!( diff --git a/tokens/pda-mint-authority/anchor-v1/programs/token-minter/src/lib.rs b/tokens/pda-mint-authority/anchor-v1/programs/token-minter/src/lib.rs index fb5ba6795..7410f3977 100644 --- a/tokens/pda-mint-authority/anchor-v1/programs/token-minter/src/lib.rs +++ b/tokens/pda-mint-authority/anchor-v1/programs/token-minter/src/lib.rs @@ -18,10 +18,7 @@ pub mod token_minter { } /// Mint `amount` minor units of the token to the payer. - pub fn mint_token( - context: Context, - amount: u64, - ) -> Result<()> { + pub fn mint_token(context: Context, amount: u64) -> Result<()> { mint::handle_mint_token(context, amount) } } diff --git a/tokens/pda-mint-authority/anchor-v1/programs/token-minter/tests/test_pda_mint.rs b/tokens/pda-mint-authority/anchor-v1/programs/token-minter/tests/test_pda_mint.rs index f451e5a09..4503a8385 100644 --- a/tokens/pda-mint-authority/anchor-v1/programs/token-minter/tests/test_pda_mint.rs +++ b/tokens/pda-mint-authority/anchor-v1/programs/token-minter/tests/test_pda_mint.rs @@ -5,9 +5,7 @@ use { }, litesvm::LiteSVM, solana_keypair::Keypair, - solana_kite::{ - create_wallet, get_token_account_balance, send_transaction_from_instructions, - }, + solana_kite::{create_wallet, get_token_account_balance, send_transaction_from_instructions}, solana_signer::Signer, }; @@ -56,11 +54,7 @@ fn derive_metadata_pda(mint: &Pubkey) -> Pubkey { fn derive_ata(wallet: &Pubkey, mint: &Pubkey) -> Pubkey { let (ata, _bump) = Pubkey::find_program_address( - &[ - wallet.as_ref(), - token_program_id().as_ref(), - mint.as_ref(), - ], + &[wallet.as_ref(), token_program_id().as_ref(), mint.as_ref()], &associated_token_program_id(), ); ata @@ -109,13 +103,8 @@ fn test_create_token_and_mint() { } .to_account_metas(None), ); - send_transaction_from_instructions( - &mut svm, - vec![create_ix], - &[&payer], - &payer.pubkey(), - ) - .unwrap(); + send_transaction_from_instructions(&mut svm, vec![create_ix], &[&payer], &payer.pubkey()) + .unwrap(); // Verify mint created let mint_account = svm.get_account(&mint_pda).expect("Mint PDA should exist"); @@ -147,13 +136,8 @@ fn test_create_token_and_mint() { } .to_account_metas(None), ); - send_transaction_from_instructions( - &mut svm, - vec![mint_ix], - &[&payer], - &payer.pubkey(), - ) - .unwrap(); + send_transaction_from_instructions(&mut svm, vec![mint_ix], &[&payer], &payer.pubkey()) + .unwrap(); // Verify 100 tokens minted (in minor units) let balance = get_token_account_balance(&svm, &ata).unwrap(); diff --git a/tokens/token-extensions/basics/anchor-v1/programs/basics/src/instructions/create_token.rs b/tokens/token-extensions/basics/anchor-v1/programs/basics/src/instructions/create_token.rs index bc08105ad..5e1169580 100644 --- a/tokens/token-extensions/basics/anchor-v1/programs/basics/src/instructions/create_token.rs +++ b/tokens/token-extensions/basics/anchor-v1/programs/basics/src/instructions/create_token.rs @@ -19,7 +19,10 @@ pub struct CreateTokenAccountConstraints<'info> { pub token_program: Interface<'info, TokenInterface>, } -pub fn handler(_context: Context, _token_name: String) -> Result<()> { +pub fn handler( + _context: Context, + _token_name: String, +) -> Result<()> { msg!("Create Token"); Ok(()) } diff --git a/tokens/token-extensions/basics/anchor-v1/programs/basics/src/lib.rs b/tokens/token-extensions/basics/anchor-v1/programs/basics/src/lib.rs index 0eb3bbf0b..f22e72f8c 100644 --- a/tokens/token-extensions/basics/anchor-v1/programs/basics/src/lib.rs +++ b/tokens/token-extensions/basics/anchor-v1/programs/basics/src/lib.rs @@ -10,11 +10,16 @@ pub mod anchor { use super::*; - pub fn create_token(context: Context, token_name: String) -> Result<()> { + pub fn create_token( + context: Context, + token_name: String, + ) -> Result<()> { instructions::create_token::handler(context, token_name) } - pub fn create_token_account(context: Context) -> Result<()> { + pub fn create_token_account( + context: Context, + ) -> Result<()> { instructions::create_token_account::handler(context) } @@ -24,7 +29,10 @@ pub mod anchor { instructions::create_associated_token_account::handler(context) } - pub fn transfer_token(context: Context, amount: u64) -> Result<()> { + pub fn transfer_token( + context: Context, + amount: u64, + ) -> Result<()> { instructions::transfer_token::handler(context, amount) } diff --git a/tokens/token-extensions/basics/anchor-v1/programs/basics/tests/test_basics.rs b/tokens/token-extensions/basics/anchor-v1/programs/basics/tests/test_basics.rs index 21b5218c8..3ad62418b 100644 --- a/tokens/token-extensions/basics/anchor-v1/programs/basics/tests/test_basics.rs +++ b/tokens/token-extensions/basics/anchor-v1/programs/basics/tests/test_basics.rs @@ -4,13 +4,11 @@ use { InstructionData, ToAccountMetas, }, litesvm::LiteSVM, + solana_keypair::Keypair, solana_kite::{ assert_token_account_balance, create_wallet, send_transaction_from_instructions, - token_extensions::{ - get_token_extensions_account_address, TOKEN_EXTENSIONS_PROGRAM_ID, - }, + token_extensions::{get_token_extensions_account_address, TOKEN_EXTENSIONS_PROGRAM_ID}, }, - solana_keypair::Keypair, solana_signer::Signer, }; @@ -63,7 +61,8 @@ fn test_create_token_and_mint_and_transfer() { .to_account_metas(None), ); - send_transaction_from_instructions(&mut svm, vec![create_token_ix], &[&payer], &payer.pubkey()).unwrap(); + send_transaction_from_instructions(&mut svm, vec![create_token_ix], &[&payer], &payer.pubkey()) + .unwrap(); // Verify mint account exists let mint_account = svm.get_account(&mint).expect("Mint account should exist"); @@ -88,12 +87,11 @@ fn test_create_token_and_mint_and_transfer() { .to_account_metas(None), ); - send_transaction_from_instructions(&mut svm, vec![create_ata_ix], &[&payer], &payer.pubkey()).unwrap(); + send_transaction_from_instructions(&mut svm, vec![create_ata_ix], &[&payer], &payer.pubkey()) + .unwrap(); // Verify ATA exists - let ata_account = svm - .get_account(&payer_ata) - .expect("Payer ATA should exist"); + let ata_account = svm.get_account(&payer_ata).expect("Payer ATA should exist"); assert!(!ata_account.data.is_empty(), "ATA should have data"); svm.expire_blockhash(); @@ -116,7 +114,8 @@ fn test_create_token_and_mint_and_transfer() { .to_account_metas(None), ); - send_transaction_from_instructions(&mut svm, vec![mint_token_ix], &[&payer], &payer.pubkey()).unwrap(); + send_transaction_from_instructions(&mut svm, vec![mint_token_ix], &[&payer], &payer.pubkey()) + .unwrap(); assert_token_account_balance( &svm, @@ -152,7 +151,8 @@ fn test_create_token_and_mint_and_transfer() { .to_account_metas(None), ); - send_transaction_from_instructions(&mut svm, vec![transfer_ix], &[&payer], &payer.pubkey()).unwrap(); + send_transaction_from_instructions(&mut svm, vec![transfer_ix], &[&payer], &payer.pubkey()) + .unwrap(); assert_token_account_balance( &svm, diff --git a/tokens/token-extensions/cpi-guard/anchor-v1/programs/cpi-guard/tests/test_cpi_guard.rs b/tokens/token-extensions/cpi-guard/anchor-v1/programs/cpi-guard/tests/test_cpi_guard.rs index 6f2145cc8..28a46ccf3 100644 --- a/tokens/token-extensions/cpi-guard/anchor-v1/programs/cpi-guard/tests/test_cpi_guard.rs +++ b/tokens/token-extensions/cpi-guard/anchor-v1/programs/cpi-guard/tests/test_cpi_guard.rs @@ -8,6 +8,7 @@ use { InstructionData, ToAccountMetas, }, litesvm::LiteSVM, + solana_keypair::Keypair, solana_kite::{ assert_token_account_balance, create_wallet, send_transaction_from_instructions, token_extensions::{ @@ -15,7 +16,6 @@ use { TOKEN_EXTENSIONS_PROGRAM_ID, }, }, - solana_keypair::Keypair, solana_signer::Signer, }; @@ -125,7 +125,13 @@ fn test_cpi_guard_prevents_transfer_then_allows_after_disable() { &mint, &payer.pubkey(), ); - send_transaction_from_instructions(&mut svm, token_ixs, &[&payer, &token_keypair], &payer.pubkey()).unwrap(); + send_transaction_from_instructions( + &mut svm, + token_ixs, + &[&payer, &token_keypair], + &payer.pubkey(), + ) + .unwrap(); svm.expire_blockhash(); // Step 3: Reallocate to add CPI Guard extension space @@ -136,27 +142,23 @@ fn test_cpi_guard_prevents_transfer_then_allows_after_disable() { &payer.pubkey(), &[cpi_guard_extension_type], ); - send_transaction_from_instructions(&mut svm, vec![reallocate_ix], &[&payer], &payer.pubkey()).unwrap(); + send_transaction_from_instructions(&mut svm, vec![reallocate_ix], &[&payer], &payer.pubkey()) + .unwrap(); svm.expire_blockhash(); // Step 4: Enable CPI Guard let enable_ix = enable_cpi_guard_instruction(&token_keypair.pubkey(), &payer.pubkey()); - send_transaction_from_instructions(&mut svm, vec![enable_ix], &[&payer], &payer.pubkey()).unwrap(); + send_transaction_from_instructions(&mut svm, vec![enable_ix], &[&payer], &payer.pubkey()) + .unwrap(); svm.expire_blockhash(); // Step 5: Mint 1 token to the token account - mint_tokens_to_token_extensions_account( - &mut svm, - &mint, - &token_keypair.pubkey(), - 1, - &payer, - ).unwrap(); + mint_tokens_to_token_extensions_account(&mut svm, &mint, &token_keypair.pubkey(), 1, &payer) + .unwrap(); svm.expire_blockhash(); // Step 6: Try CPI transfer - should fail because CPI Guard is enabled - let (recipient_token_account, _bump) = - Pubkey::find_program_address(&[b"pda"], &program_id); + let (recipient_token_account, _bump) = Pubkey::find_program_address(&[b"pda"], &program_id); let transfer_ix = Instruction::new_with_bytes( program_id, @@ -172,7 +174,8 @@ fn test_cpi_guard_prevents_transfer_then_allows_after_disable() { .to_account_metas(None), ); - let result = send_transaction_from_instructions(&mut svm, vec![transfer_ix], &[&payer], &payer.pubkey()); + let result = + send_transaction_from_instructions(&mut svm, vec![transfer_ix], &[&payer], &payer.pubkey()); assert!( result.is_err(), "Transfer should fail when CPI Guard is enabled" @@ -181,7 +184,8 @@ fn test_cpi_guard_prevents_transfer_then_allows_after_disable() { // Step 7: Disable CPI Guard let disable_ix = disable_cpi_guard_instruction(&token_keypair.pubkey(), &payer.pubkey()); - send_transaction_from_instructions(&mut svm, vec![disable_ix], &[&payer], &payer.pubkey()).unwrap(); + send_transaction_from_instructions(&mut svm, vec![disable_ix], &[&payer], &payer.pubkey()) + .unwrap(); svm.expire_blockhash(); // Step 8: Transfer should now succeed @@ -199,7 +203,13 @@ fn test_cpi_guard_prevents_transfer_then_allows_after_disable() { .to_account_metas(None), ); - send_transaction_from_instructions(&mut svm, vec![transfer_ix2], &[&payer], &payer.pubkey()).unwrap(); + send_transaction_from_instructions(&mut svm, vec![transfer_ix2], &[&payer], &payer.pubkey()) + .unwrap(); - assert_token_account_balance(&svm, &recipient_token_account, 1, "Recipient should have 1 token"); + assert_token_account_balance( + &svm, + &recipient_token_account, + 1, + "Recipient should have 1 token", + ); } diff --git a/tokens/token-extensions/default-account-state/anchor-v1/programs/default-account-state/src/instructions/initialize.rs b/tokens/token-extensions/default-account-state/anchor-v1/programs/default-account-state/src/instructions/initialize.rs index 939241aba..5ad5c086d 100644 --- a/tokens/token-extensions/default-account-state/anchor-v1/programs/default-account-state/src/instructions/initialize.rs +++ b/tokens/token-extensions/default-account-state/anchor-v1/programs/default-account-state/src/instructions/initialize.rs @@ -6,9 +6,7 @@ use anchor_spl::{ spl_token_2022::{extension::ExtensionType, pod::PodMint, state::AccountState}, InitializeMint2, }, - token_interface::{ - default_account_state_initialize, DefaultAccountStateInitialize, Token2022, - }, + token_interface::{default_account_state_initialize, DefaultAccountStateInitialize, Token2022}, }; #[derive(Accounts)] @@ -26,9 +24,8 @@ pub struct InitializeAccountConstraints<'info> { // We can manually create and initialize the mint account via CPIs in the instruction handler pub fn handler(context: Context) -> Result<()> { // Calculate space required for mint and extension data - let mint_size = ExtensionType::try_calculate_account_len::(&[ - ExtensionType::DefaultAccountState, - ])?; + let mint_size = + ExtensionType::try_calculate_account_len::(&[ExtensionType::DefaultAccountState])?; // Calculate minimum lamports required for size of mint account with extensions let lamports = (Rent::get()?).minimum_balance(mint_size); @@ -42,8 +39,8 @@ pub fn handler(context: Context) -> Result<()> { to: context.accounts.mint_account.to_account_info(), }, ), - lamports, // Lamports - mint_size as u64, // Space + lamports, // Lamports + mint_size as u64, // Space &context.accounts.token_program.key(), // Owner Program )?; @@ -68,7 +65,7 @@ pub fn handler(context: Context) -> Result<()> { mint: context.accounts.mint_account.to_account_info(), }, ), - 2, // decimals + 2, // decimals &context.accounts.payer.key(), // mint authority Some(&context.accounts.payer.key()), // freeze authority )?; diff --git a/tokens/token-extensions/default-account-state/anchor-v1/programs/default-account-state/tests/test_default_account_state.rs b/tokens/token-extensions/default-account-state/anchor-v1/programs/default-account-state/tests/test_default_account_state.rs index c23a86ef3..72265cf5c 100644 --- a/tokens/token-extensions/default-account-state/anchor-v1/programs/default-account-state/tests/test_default_account_state.rs +++ b/tokens/token-extensions/default-account-state/anchor-v1/programs/default-account-state/tests/test_default_account_state.rs @@ -8,13 +8,11 @@ use { InstructionData, ToAccountMetas, }, litesvm::LiteSVM, + solana_keypair::Keypair, solana_kite::{ assert_token_account_balance, create_wallet, send_transaction_from_instructions, - token_extensions::{ - mint_tokens_to_token_extensions_account, TOKEN_EXTENSIONS_PROGRAM_ID, - }, + token_extensions::{mint_tokens_to_token_extensions_account, TOKEN_EXTENSIONS_PROGRAM_ID}, }, - solana_keypair::Keypair, solana_signer::Signer, }; @@ -77,7 +75,13 @@ fn test_default_account_state() { } .to_account_metas(None), ); - send_transaction_from_instructions(&mut svm, vec![initialize_ix], &[&payer, &mint_keypair], &payer.pubkey()).unwrap(); + send_transaction_from_instructions( + &mut svm, + vec![initialize_ix], + &[&payer, &mint_keypair], + &payer.pubkey(), + ) + .unwrap(); svm.expire_blockhash(); // Verify mint exists @@ -92,7 +96,13 @@ fn test_default_account_state() { &mint_keypair.pubkey(), &payer.pubkey(), ); - send_transaction_from_instructions(&mut svm, create_token1_ixs, &[&payer, &token1], &payer.pubkey()).unwrap(); + send_transaction_from_instructions( + &mut svm, + create_token1_ixs, + &[&payer, &token1], + &payer.pubkey(), + ) + .unwrap(); svm.expire_blockhash(); // Verify token account state is frozen (byte 108 = account state: 0=uninitialized, 1=initialized, 2=frozen) @@ -110,10 +120,7 @@ fn test_default_account_state() { 1, &payer, ); - assert!( - result.is_err(), - "Minting to a frozen account should fail" - ); + assert!(result.is_err(), "Minting to a frozen account should fail"); svm.expire_blockhash(); // Step 4: Update default state to Initialized @@ -131,7 +138,8 @@ fn test_default_account_state() { } .to_account_metas(None), ); - send_transaction_from_instructions(&mut svm, vec![update_ix], &[&payer], &payer.pubkey()).unwrap(); + send_transaction_from_instructions(&mut svm, vec![update_ix], &[&payer], &payer.pubkey()) + .unwrap(); svm.expire_blockhash(); // Step 5: Create a new token account - should be initialized (not frozen) now @@ -142,7 +150,13 @@ fn test_default_account_state() { &mint_keypair.pubkey(), &payer.pubkey(), ); - send_transaction_from_instructions(&mut svm, create_token2_ixs, &[&payer, &token2], &payer.pubkey()).unwrap(); + send_transaction_from_instructions( + &mut svm, + create_token2_ixs, + &[&payer, &token2], + &payer.pubkey(), + ) + .unwrap(); svm.expire_blockhash(); // Verify token2 is initialized (not frozen) @@ -159,7 +173,8 @@ fn test_default_account_state() { &token2.pubkey(), 1, &payer, - ).unwrap(); + ) + .unwrap(); assert_token_account_balance(&svm, &token2.pubkey(), 1, "Should have minted 1 token"); } diff --git a/tokens/token-extensions/group/anchor-v1/programs/group/src/lib.rs b/tokens/token-extensions/group/anchor-v1/programs/group/src/lib.rs index 4c2219231..f7da38581 100644 --- a/tokens/token-extensions/group/anchor-v1/programs/group/src/lib.rs +++ b/tokens/token-extensions/group/anchor-v1/programs/group/src/lib.rs @@ -10,7 +10,9 @@ pub mod group { use super::*; - pub fn test_initialize_group(context: Context) -> Result<()> { + pub fn test_initialize_group( + context: Context, + ) -> Result<()> { instructions::test_initialize_group::handler(context) } } diff --git a/tokens/token-extensions/group/anchor-v1/programs/group/tests/test_group.rs b/tokens/token-extensions/group/anchor-v1/programs/group/tests/test_group.rs index 331ca1fb3..114d7a443 100644 --- a/tokens/token-extensions/group/anchor-v1/programs/group/tests/test_group.rs +++ b/tokens/token-extensions/group/anchor-v1/programs/group/tests/test_group.rs @@ -36,7 +36,8 @@ fn test_initialize_group() { .to_account_metas(None), ); - send_transaction_from_instructions(&mut svm, vec![instruction], &[&payer], &payer.pubkey()).unwrap(); + send_transaction_from_instructions(&mut svm, vec![instruction], &[&payer], &payer.pubkey()) + .unwrap(); // Verify mint was created with group pointer extension let mint_data = svm diff --git a/tokens/token-extensions/immutable-owner/anchor-v1/programs/immutable-owner/src/lib.rs b/tokens/token-extensions/immutable-owner/anchor-v1/programs/immutable-owner/src/lib.rs index e21a5e718..a79f5ffbd 100644 --- a/tokens/token-extensions/immutable-owner/anchor-v1/programs/immutable-owner/src/lib.rs +++ b/tokens/token-extensions/immutable-owner/anchor-v1/programs/immutable-owner/src/lib.rs @@ -35,8 +35,8 @@ pub mod immutable_owner { to: context.accounts.token_account.to_account_info(), }, ), - lamports, // Lamports - token_account_size as u64, // Space + lamports, // Lamports + token_account_size as u64, // Space &context.accounts.token_program.key(), // Owner Program )?; diff --git a/tokens/token-extensions/immutable-owner/anchor-v1/programs/immutable-owner/tests/test_immutable_owner.rs b/tokens/token-extensions/immutable-owner/anchor-v1/programs/immutable-owner/tests/test_immutable_owner.rs index 90710e4c9..dd5ad978c 100644 --- a/tokens/token-extensions/immutable-owner/anchor-v1/programs/immutable-owner/tests/test_immutable_owner.rs +++ b/tokens/token-extensions/immutable-owner/anchor-v1/programs/immutable-owner/tests/test_immutable_owner.rs @@ -8,11 +8,11 @@ use { InstructionData, ToAccountMetas, }, litesvm::LiteSVM, + solana_keypair::Keypair, solana_kite::{ create_wallet, send_transaction_from_instructions, token_extensions::{create_token_extensions_mint, TOKEN_EXTENSIONS_PROGRAM_ID}, }, - solana_keypair::Keypair, solana_signer::Signer, }; @@ -77,7 +77,13 @@ fn test_create_token_account_with_immutable_owner() { } .to_account_metas(None), ); - send_transaction_from_instructions(&mut svm, vec![initialize_ix], &[&payer, &token_keypair], &payer.pubkey()).unwrap(); + send_transaction_from_instructions( + &mut svm, + vec![initialize_ix], + &[&payer, &token_keypair], + &payer.pubkey(), + ) + .unwrap(); svm.expire_blockhash(); // Verify token account was created @@ -98,7 +104,12 @@ fn test_create_token_account_with_immutable_owner() { Some(&new_owner.pubkey()), 2, // AuthorityType::AccountOwner ); - let result = send_transaction_from_instructions(&mut svm, vec![set_authority_ix], &[&payer], &payer.pubkey()); + let result = send_transaction_from_instructions( + &mut svm, + vec![set_authority_ix], + &[&payer], + &payer.pubkey(), + ); assert!( result.is_err(), "Setting a new owner should fail due to ImmutableOwner extension" diff --git a/tokens/token-extensions/interest-bearing/anchor-v1/programs/interest-bearing/src/instructions/initialize.rs b/tokens/token-extensions/interest-bearing/anchor-v1/programs/interest-bearing/src/instructions/initialize.rs index 717638d8d..369cc22ed 100644 --- a/tokens/token-extensions/interest-bearing/anchor-v1/programs/interest-bearing/src/instructions/initialize.rs +++ b/tokens/token-extensions/interest-bearing/anchor-v1/programs/interest-bearing/src/instructions/initialize.rs @@ -1,12 +1,12 @@ use anchor_lang::prelude::*; use anchor_lang::system_program::{create_account, CreateAccount}; use anchor_spl::{ + token_2022::spl_token_2022::extension::interest_bearing_mint::InterestBearingConfig, token_2022::{ initialize_mint2, spl_token_2022::{extension::ExtensionType, pod::PodMint}, InitializeMint2, }, - token_2022::spl_token_2022::extension::interest_bearing_mint::InterestBearingConfig, token_interface::{ get_mint_extension_data, interest_bearing_mint_initialize, InterestBearingMintInitialize, Token2022, @@ -44,8 +44,8 @@ pub fn handler(context: Context, rate: i16) -> Res to: context.accounts.mint_account.to_account_info(), }, ), - lamports, // Lamports - mint_size as u64, // Space + lamports, // Lamports + mint_size as u64, // Space &context.accounts.token_program.key(), // Owner Program )?; @@ -71,7 +71,7 @@ pub fn handler(context: Context, rate: i16) -> Res mint: context.accounts.mint_account.to_account_info(), }, ), - 2, // decimals + 2, // decimals &context.accounts.payer.key(), // mint authority Some(&context.accounts.payer.key()), // freeze authority )?; diff --git a/tokens/token-extensions/interest-bearing/anchor-v1/programs/interest-bearing/src/instructions/update_rate.rs b/tokens/token-extensions/interest-bearing/anchor-v1/programs/interest-bearing/src/instructions/update_rate.rs index 3f8da4f0f..e660c79af 100644 --- a/tokens/token-extensions/interest-bearing/anchor-v1/programs/interest-bearing/src/instructions/update_rate.rs +++ b/tokens/token-extensions/interest-bearing/anchor-v1/programs/interest-bearing/src/instructions/update_rate.rs @@ -1,8 +1,8 @@ use anchor_lang::prelude::*; use anchor_spl::token_2022::spl_token_2022::extension::interest_bearing_mint::InterestBearingConfig; use anchor_spl::token_interface::{ - get_mint_extension_data, interest_bearing_mint_update_rate, InterestBearingMintUpdateRate, Mint, - Token2022, + get_mint_extension_data, interest_bearing_mint_update_rate, InterestBearingMintUpdateRate, + Mint, Token2022, }; use crate::check_rate_authority; diff --git a/tokens/token-extensions/interest-bearing/anchor-v1/programs/interest-bearing/tests/test_interest_bearing.rs b/tokens/token-extensions/interest-bearing/anchor-v1/programs/interest-bearing/tests/test_interest_bearing.rs index c9954bccb..59fee9f80 100644 --- a/tokens/token-extensions/interest-bearing/anchor-v1/programs/interest-bearing/tests/test_interest_bearing.rs +++ b/tokens/token-extensions/interest-bearing/anchor-v1/programs/interest-bearing/tests/test_interest_bearing.rs @@ -4,11 +4,11 @@ use { InstructionData, ToAccountMetas, }, litesvm::LiteSVM, + solana_keypair::Keypair, solana_kite::{ create_wallet, send_transaction_from_instructions, token_extensions::TOKEN_EXTENSIONS_PROGRAM_ID, }, - solana_keypair::Keypair, solana_signer::Signer, }; @@ -40,7 +40,13 @@ fn test_initialize_and_update_rate() { } .to_account_metas(None), ); - send_transaction_from_instructions(&mut svm, vec![initialize_ix], &[&payer, &mint_keypair], &payer.pubkey()).unwrap(); + send_transaction_from_instructions( + &mut svm, + vec![initialize_ix], + &[&payer, &mint_keypair], + &payer.pubkey(), + ) + .unwrap(); // Verify mint account exists let mint_account = svm @@ -62,7 +68,8 @@ fn test_initialize_and_update_rate() { } .to_account_metas(None), ); - send_transaction_from_instructions(&mut svm, vec![update_rate_ix], &[&payer], &payer.pubkey()).unwrap(); + send_transaction_from_instructions(&mut svm, vec![update_rate_ix], &[&payer], &payer.pubkey()) + .unwrap(); // Verify mint still exists after rate update let mint_account = svm diff --git a/tokens/token-extensions/memo-transfer/anchor-v1/programs/memo-transfer/src/instructions/initialize.rs b/tokens/token-extensions/memo-transfer/anchor-v1/programs/memo-transfer/src/instructions/initialize.rs index b465e5423..4948e02d5 100644 --- a/tokens/token-extensions/memo-transfer/anchor-v1/programs/memo-transfer/src/instructions/initialize.rs +++ b/tokens/token-extensions/memo-transfer/anchor-v1/programs/memo-transfer/src/instructions/initialize.rs @@ -38,8 +38,8 @@ pub fn handler(context: Context) -> Result<()> { to: context.accounts.token_account.to_account_info(), }, ), - lamports, // Lamports - token_account_size as u64, // Space + lamports, // Lamports + token_account_size as u64, // Space &context.accounts.token_program.key(), // Owner Program )?; diff --git a/tokens/token-extensions/memo-transfer/anchor-v1/programs/memo-transfer/tests/test_memo_transfer.rs b/tokens/token-extensions/memo-transfer/anchor-v1/programs/memo-transfer/tests/test_memo_transfer.rs index e410f2347..c611a9da1 100644 --- a/tokens/token-extensions/memo-transfer/anchor-v1/programs/memo-transfer/tests/test_memo_transfer.rs +++ b/tokens/token-extensions/memo-transfer/anchor-v1/programs/memo-transfer/tests/test_memo_transfer.rs @@ -8,6 +8,7 @@ use { InstructionData, ToAccountMetas, }, litesvm::LiteSVM, + solana_keypair::Keypair, solana_kite::{ assert_token_account_balance, create_wallet, send_transaction_from_instructions, token_extensions::{ @@ -15,7 +16,6 @@ use { TOKEN_EXTENSIONS_PROGRAM_ID, }, }, - solana_keypair::Keypair, solana_signer::Signer, }; @@ -128,7 +128,13 @@ fn test_memo_transfer() { } .to_account_metas(None), ); - send_transaction_from_instructions(&mut svm, vec![initialize_ix], &[&payer, &token_keypair], &payer.pubkey()).unwrap(); + send_transaction_from_instructions( + &mut svm, + vec![initialize_ix], + &[&payer, &token_keypair], + &payer.pubkey(), + ) + .unwrap(); // Verify token account exists let token_account = svm @@ -149,16 +155,17 @@ fn test_memo_transfer() { &mint, &payer.pubkey(), ); - send_transaction_from_instructions(&mut svm, create_source_ixs, &[&payer, &source_keypair], &payer.pubkey()).unwrap(); + send_transaction_from_instructions( + &mut svm, + create_source_ixs, + &[&payer, &source_keypair], + &payer.pubkey(), + ) + .unwrap(); svm.expire_blockhash(); - mint_tokens_to_token_extensions_account( - &mut svm, - &mint, - &source_keypair.pubkey(), - 100, - &payer, - ).unwrap(); + mint_tokens_to_token_extensions_account(&mut svm, &mint, &source_keypair.pubkey(), 100, &payer) + .unwrap(); svm.expire_blockhash(); // Step 4: Transfer without memo - should fail @@ -168,11 +175,9 @@ fn test_memo_transfer() { &payer.pubkey(), 1, ); - let result = send_transaction_from_instructions(&mut svm, vec![transfer_ix], &[&payer], &payer.pubkey()); - assert!( - result.is_err(), - "Transfer without memo should fail" - ); + let result = + send_transaction_from_instructions(&mut svm, vec![transfer_ix], &[&payer], &payer.pubkey()); + assert!(result.is_err(), "Transfer without memo should fail"); svm.expire_blockhash(); // Step 5: Transfer with memo - should succeed @@ -183,10 +188,21 @@ fn test_memo_transfer() { &payer.pubkey(), 1, ); - send_transaction_from_instructions(&mut svm, vec![memo_ix, transfer_ix], &[&payer], &payer.pubkey()).unwrap(); + send_transaction_from_instructions( + &mut svm, + vec![memo_ix, transfer_ix], + &[&payer], + &payer.pubkey(), + ) + .unwrap(); svm.expire_blockhash(); - assert_token_account_balance(&svm, &token_keypair.pubkey(), 1, "Should have 1 token after transfer with memo"); + assert_token_account_balance( + &svm, + &token_keypair.pubkey(), + 1, + "Should have 1 token after transfer with memo", + ); // Step 6: Disable RequiredMemo extension let disable_ix = Instruction::new_with_bytes( @@ -199,7 +215,8 @@ fn test_memo_transfer() { } .to_account_metas(None), ); - send_transaction_from_instructions(&mut svm, vec![disable_ix], &[&payer], &payer.pubkey()).unwrap(); + send_transaction_from_instructions(&mut svm, vec![disable_ix], &[&payer], &payer.pubkey()) + .unwrap(); svm.expire_blockhash(); // Step 7: Transfer without memo should now succeed (memo disabled) @@ -210,7 +227,13 @@ fn test_memo_transfer() { &mint, &payer.pubkey(), ); - send_transaction_from_instructions(&mut svm, create_source2_ixs, &[&payer, &source2_keypair], &payer.pubkey()).unwrap(); + send_transaction_from_instructions( + &mut svm, + create_source2_ixs, + &[&payer, &source2_keypair], + &payer.pubkey(), + ) + .unwrap(); svm.expire_blockhash(); mint_tokens_to_token_extensions_account( @@ -219,7 +242,8 @@ fn test_memo_transfer() { &source2_keypair.pubkey(), 100, &payer, - ).unwrap(); + ) + .unwrap(); svm.expire_blockhash(); let transfer_ix2 = transfer_instruction( @@ -228,7 +252,8 @@ fn test_memo_transfer() { &payer.pubkey(), 1, ); - send_transaction_from_instructions(&mut svm, vec![transfer_ix2], &[&payer], &payer.pubkey()).unwrap(); + send_transaction_from_instructions(&mut svm, vec![transfer_ix2], &[&payer], &payer.pubkey()) + .unwrap(); assert_token_account_balance( &svm, diff --git a/tokens/token-extensions/metadata/anchor-v1/programs/metadata/src/instructions/initialize.rs b/tokens/token-extensions/metadata/anchor-v1/programs/metadata/src/instructions/initialize.rs index 740b61bae..e2e549654 100644 --- a/tokens/token-extensions/metadata/anchor-v1/programs/metadata/src/instructions/initialize.rs +++ b/tokens/token-extensions/metadata/anchor-v1/programs/metadata/src/instructions/initialize.rs @@ -24,7 +24,10 @@ pub struct InitializeAccountConstraints<'info> { pub system_program: Program<'info, System>, } -pub fn process_initialize(context: Context, args: TokenMetadataArgs) -> Result<()> { +pub fn process_initialize( + context: Context, + args: TokenMetadataArgs, +) -> Result<()> { let TokenMetadataArgs { name, symbol, uri } = args; // Define token metadata diff --git a/tokens/token-extensions/metadata/anchor-v1/programs/metadata/src/instructions/remove_key.rs b/tokens/token-extensions/metadata/anchor-v1/programs/metadata/src/instructions/remove_key.rs index 0114a4b26..08b94420d 100644 --- a/tokens/token-extensions/metadata/anchor-v1/programs/metadata/src/instructions/remove_key.rs +++ b/tokens/token-extensions/metadata/anchor-v1/programs/metadata/src/instructions/remove_key.rs @@ -19,7 +19,10 @@ pub struct RemoveKeyAccountConstraints<'info> { // Invoke the remove_key instruction from spl_token_metadata_interface directly // There is not an anchor CpiContext for this instruction -pub fn process_remove_key(context: Context, key: String) -> Result<()> { +pub fn process_remove_key( + context: Context, + key: String, +) -> Result<()> { invoke( &remove_key( &context.accounts.token_program.key(), // token program id diff --git a/tokens/token-extensions/metadata/anchor-v1/programs/metadata/src/instructions/update_field.rs b/tokens/token-extensions/metadata/anchor-v1/programs/metadata/src/instructions/update_field.rs index 754fb8091..bf5ac40e4 100644 --- a/tokens/token-extensions/metadata/anchor-v1/programs/metadata/src/instructions/update_field.rs +++ b/tokens/token-extensions/metadata/anchor-v1/programs/metadata/src/instructions/update_field.rs @@ -23,7 +23,10 @@ pub struct UpdateFieldAccountConstraints<'info> { pub system_program: Program<'info, System>, } -pub fn process_update_field(context: Context, args: UpdateFieldArgs) -> Result<()> { +pub fn process_update_field( + context: Context, + args: UpdateFieldArgs, +) -> Result<()> { let UpdateFieldArgs { field, value } = args; // Convert to Field type from spl_token_metadata_interface diff --git a/tokens/token-extensions/metadata/anchor-v1/programs/metadata/src/lib.rs b/tokens/token-extensions/metadata/anchor-v1/programs/metadata/src/lib.rs index e086f704c..a01edd7ef 100644 --- a/tokens/token-extensions/metadata/anchor-v1/programs/metadata/src/lib.rs +++ b/tokens/token-extensions/metadata/anchor-v1/programs/metadata/src/lib.rs @@ -11,11 +11,17 @@ declare_id!("BJHEDXSQfD9kBFvhw8ZCGmPFRihzvbMoxoHUKpXdpn4D"); pub mod metadata { use super::*; - pub fn initialize(context: Context, args: TokenMetadataArgs) -> Result<()> { + pub fn initialize( + context: Context, + args: TokenMetadataArgs, + ) -> Result<()> { process_initialize(context, args) } - pub fn update_field(context: Context, args: UpdateFieldArgs) -> Result<()> { + pub fn update_field( + context: Context, + args: UpdateFieldArgs, + ) -> Result<()> { process_update_field(context, args) } diff --git a/tokens/token-extensions/mint-close-authority/anchor-v1/programs/mint-close-authority/src/instructions/initialize.rs b/tokens/token-extensions/mint-close-authority/anchor-v1/programs/mint-close-authority/src/instructions/initialize.rs index ba2f2a47a..0994cfbf3 100644 --- a/tokens/token-extensions/mint-close-authority/anchor-v1/programs/mint-close-authority/src/instructions/initialize.rs +++ b/tokens/token-extensions/mint-close-authority/anchor-v1/programs/mint-close-authority/src/instructions/initialize.rs @@ -3,8 +3,7 @@ use anchor_spl::token_interface::{ spl_pod::optional_keys::OptionalNonZeroPubkey, spl_token_2022::{ extension::{ - mint_close_authority::MintCloseAuthority, BaseStateWithExtensions, - StateWithExtensions, + mint_close_authority::MintCloseAuthority, BaseStateWithExtensions, StateWithExtensions, }, state::Mint as MintState, }, diff --git a/tokens/token-extensions/mint-close-authority/anchor-v1/programs/mint-close-authority/tests/test_mint_close_authority.rs b/tokens/token-extensions/mint-close-authority/anchor-v1/programs/mint-close-authority/tests/test_mint_close_authority.rs index 156c92040..81e724d01 100644 --- a/tokens/token-extensions/mint-close-authority/anchor-v1/programs/mint-close-authority/tests/test_mint_close_authority.rs +++ b/tokens/token-extensions/mint-close-authority/anchor-v1/programs/mint-close-authority/tests/test_mint_close_authority.rs @@ -4,11 +4,11 @@ use { InstructionData, ToAccountMetas, }, litesvm::LiteSVM, + solana_keypair::Keypair, solana_kite::{ create_wallet, send_transaction_from_instructions, token_extensions::TOKEN_EXTENSIONS_PROGRAM_ID, }, - solana_keypair::Keypair, solana_signer::Signer, }; @@ -40,7 +40,13 @@ fn test_create_and_close_mint() { } .to_account_metas(None), ); - send_transaction_from_instructions(&mut svm, vec![initialize_ix], &[&payer, &mint_keypair], &payer.pubkey()).unwrap(); + send_transaction_from_instructions( + &mut svm, + vec![initialize_ix], + &[&payer, &mint_keypair], + &payer.pubkey(), + ) + .unwrap(); // Verify mint exists let mint_account = svm @@ -61,14 +67,12 @@ fn test_create_and_close_mint() { } .to_account_metas(None), ); - send_transaction_from_instructions(&mut svm, vec![close_ix], &[&payer], &payer.pubkey()).unwrap(); + send_transaction_from_instructions(&mut svm, vec![close_ix], &[&payer], &payer.pubkey()) + .unwrap(); // Verify mint no longer exists (lamports returned to authority) let mint_account = svm.get_account(&mint_keypair.pubkey()); - assert!( - mint_account.is_none(), - "Mint account should be closed" - ); + assert!(mint_account.is_none(), "Mint account should be closed"); svm.expire_blockhash(); @@ -84,7 +88,13 @@ fn test_create_and_close_mint() { } .to_account_metas(None), ); - send_transaction_from_instructions(&mut svm, vec![initialize_ix2], &[&payer, &mint_keypair], &payer.pubkey()).unwrap(); + send_transaction_from_instructions( + &mut svm, + vec![initialize_ix2], + &[&payer, &mint_keypair], + &payer.pubkey(), + ) + .unwrap(); // Verify mint exists again let mint_account = svm @@ -105,10 +115,7 @@ fn test_create_and_close_mint() { mint_keypair.pubkey(), false, ), - anchor_lang::solana_program::instruction::AccountMeta::new( - payer.pubkey(), - false, - ), + anchor_lang::solana_program::instruction::AccountMeta::new(payer.pubkey(), false), anchor_lang::solana_program::instruction::AccountMeta::new_readonly( payer.pubkey(), true, @@ -116,7 +123,8 @@ fn test_create_and_close_mint() { ], data: vec![9], // CloseAccount }; - send_transaction_from_instructions(&mut svm, vec![close_direct_ix], &[&payer], &payer.pubkey()).unwrap(); + send_transaction_from_instructions(&mut svm, vec![close_direct_ix], &[&payer], &payer.pubkey()) + .unwrap(); // Verify mint is closed again let mint_account = svm.get_account(&mint_keypair.pubkey()); diff --git a/tokens/token-extensions/nft-meta-data-pointer/anchor-example/anchor-v1/programs/extension_nft/src/instructions/chop_tree.rs b/tokens/token-extensions/nft-meta-data-pointer/anchor-example/anchor-v1/programs/extension_nft/src/instructions/chop_tree.rs index 597f9f0c6..0fca0fc7d 100644 --- a/tokens/token-extensions/nft-meta-data-pointer/anchor-example/anchor-v1/programs/extension_nft/src/instructions/chop_tree.rs +++ b/tokens/token-extensions/nft-meta-data-pointer/anchor-example/anchor-v1/programs/extension_nft/src/instructions/chop_tree.rs @@ -7,7 +7,11 @@ use anchor_spl::token_2022_extensions::spl_token_metadata_interface; use anchor_spl::token_interface::{spl_token_2022, Token2022}; use session_keys::{Session, SessionToken}; -pub fn chop_tree(context: Context, counter: u16, amount: u64) -> Result<()> { +pub fn chop_tree( + context: Context, + counter: u16, + amount: u64, +) -> Result<()> { // Save game_data bump on first creation (init_if_needed). See init_player.rs // for the same pattern. let game_data_bump = context.bumps.game_data; diff --git a/tokens/token-extensions/nft-meta-data-pointer/anchor-example/anchor-v1/programs/extension_nft/src/lib.rs b/tokens/token-extensions/nft-meta-data-pointer/anchor-example/anchor-v1/programs/extension_nft/src/lib.rs index 6d513f1bc..67293f356 100644 --- a/tokens/token-extensions/nft-meta-data-pointer/anchor-example/anchor-v1/programs/extension_nft/src/lib.rs +++ b/tokens/token-extensions/nft-meta-data-pointer/anchor-example/anchor-v1/programs/extension_nft/src/lib.rs @@ -24,7 +24,10 @@ declare_id!("9aZZ7TJ2fQZxY8hMtWXywp5y6BgqC4N2BPcr9FDT47sW"); pub mod extension_nft { use super::*; - pub fn init_player(context: Context, _level_seed: String) -> Result<()> { + pub fn init_player( + context: Context, + _level_seed: String, + ) -> Result<()> { init_player::handle_init_player(context) } @@ -39,7 +42,11 @@ pub mod extension_nft { ctx.accounts.player.authority.key() == ctx.accounts.signer.key(), GameErrorCode::WrongAuthority )] - pub fn chop_tree(ctx: Context, _level_seed: String, counter: u16) -> Result<()> { + pub fn chop_tree( + ctx: Context, + _level_seed: String, + counter: u16, + ) -> Result<()> { chop_tree::chop_tree(ctx, counter, 1) } diff --git a/tokens/token-extensions/nft-meta-data-pointer/anchor-example/anchor-v1/programs/extension_nft/tests/test_extension_nft.rs b/tokens/token-extensions/nft-meta-data-pointer/anchor-example/anchor-v1/programs/extension_nft/tests/test_extension_nft.rs index 74a58e906..ef982a143 100644 --- a/tokens/token-extensions/nft-meta-data-pointer/anchor-example/anchor-v1/programs/extension_nft/tests/test_extension_nft.rs +++ b/tokens/token-extensions/nft-meta-data-pointer/anchor-example/anchor-v1/programs/extension_nft/tests/test_extension_nft.rs @@ -207,7 +207,10 @@ fn test_init_player_mint_and_chop() { // The associated token account should exist and hold the single NFT. let ata = associated_token_address(&signer, &mint.pubkey()); let ata_account = svm.get_account(&ata).expect("ATA created"); - assert_eq!(ata_account.owner, TOKEN_2022_ID, "ATA owned by Token Extensions"); + assert_eq!( + ata_account.owner, TOKEN_2022_ID, + "ATA owned by Token Extensions" + ); // 3. chop_tree - needs the existing mint so it can push the new wood total // into the NFT metadata. Signed by the player's main wallet (no session). diff --git a/tokens/token-extensions/non-transferable/anchor-v1/programs/non-transferable/src/lib.rs b/tokens/token-extensions/non-transferable/anchor-v1/programs/non-transferable/src/lib.rs index 6e3447b08..0d6e59d9f 100644 --- a/tokens/token-extensions/non-transferable/anchor-v1/programs/non-transferable/src/lib.rs +++ b/tokens/token-extensions/non-transferable/anchor-v1/programs/non-transferable/src/lib.rs @@ -34,8 +34,8 @@ pub mod non_transferable { to: context.accounts.mint_account.to_account_info(), }, ), - lamports, // Lamports - mint_size as u64, // Space + lamports, // Lamports + mint_size as u64, // Space &context.accounts.token_program.key(), // Owner Program )?; @@ -57,7 +57,7 @@ pub mod non_transferable { mint: context.accounts.mint_account.to_account_info(), }, ), - 2, // decimals + 2, // decimals &context.accounts.payer.key(), // mint authority Some(&context.accounts.payer.key()), // freeze authority )?; diff --git a/tokens/token-extensions/non-transferable/anchor-v1/programs/non-transferable/tests/test_non_transferable.rs b/tokens/token-extensions/non-transferable/anchor-v1/programs/non-transferable/tests/test_non_transferable.rs index 65f05d6a1..3a67f7412 100644 --- a/tokens/token-extensions/non-transferable/anchor-v1/programs/non-transferable/tests/test_non_transferable.rs +++ b/tokens/token-extensions/non-transferable/anchor-v1/programs/non-transferable/tests/test_non_transferable.rs @@ -1,13 +1,10 @@ use { anchor_lang::{ - solana_program::{ - instruction::Instruction, - pubkey::Pubkey, - system_program, - }, + solana_program::{instruction::Instruction, pubkey::Pubkey, system_program}, InstructionData, ToAccountMetas, }, litesvm::LiteSVM, + solana_keypair::Keypair, solana_kite::{ create_wallet, send_transaction_from_instructions, token_extensions::{ @@ -16,7 +13,6 @@ use { TOKEN_EXTENSIONS_PROGRAM_ID, }, }, - solana_keypair::Keypair, solana_signer::Signer, }; @@ -48,7 +44,13 @@ fn test_create_non_transferable_mint_and_attempt_transfer() { } .to_account_metas(None), ); - send_transaction_from_instructions(&mut svm, vec![initialize_ix], &[&payer, &mint_keypair], &payer.pubkey()).unwrap(); + send_transaction_from_instructions( + &mut svm, + vec![initialize_ix], + &[&payer, &mint_keypair], + &payer.pubkey(), + ) + .unwrap(); svm.expire_blockhash(); // Verify mint account was created and has extension data @@ -63,12 +65,9 @@ fn test_create_non_transferable_mint_and_attempt_transfer() { // Step 2: Create ATAs for sender and recipient let recipient = Keypair::new(); - let source_ata = create_token_extensions_account( - &mut svm, - &payer.pubkey(), - &mint_keypair.pubkey(), - &payer, - ).unwrap(); + let source_ata = + create_token_extensions_account(&mut svm, &payer.pubkey(), &mint_keypair.pubkey(), &payer) + .unwrap(); svm.expire_blockhash(); let dest_ata = create_token_extensions_account( @@ -76,7 +75,8 @@ fn test_create_non_transferable_mint_and_attempt_transfer() { &recipient.pubkey(), &mint_keypair.pubkey(), &payer, - ).unwrap(); + ) + .unwrap(); svm.expire_blockhash(); // Step 3: Mint 1 token to sender @@ -86,7 +86,8 @@ fn test_create_non_transferable_mint_and_attempt_transfer() { &source_ata, 1, &payer, - ).unwrap(); + ) + .unwrap(); svm.expire_blockhash(); // Step 4: Attempt transfer - should fail because mint is NonTransferable diff --git a/tokens/token-extensions/permanent-delegate/anchor-v1/programs/permanent-delegate/tests/test_permanent_delegate.rs b/tokens/token-extensions/permanent-delegate/anchor-v1/programs/permanent-delegate/tests/test_permanent_delegate.rs index 034ac53f7..20d0f8acb 100644 --- a/tokens/token-extensions/permanent-delegate/anchor-v1/programs/permanent-delegate/tests/test_permanent_delegate.rs +++ b/tokens/token-extensions/permanent-delegate/anchor-v1/programs/permanent-delegate/tests/test_permanent_delegate.rs @@ -8,13 +8,11 @@ use { InstructionData, ToAccountMetas, }, litesvm::LiteSVM, + solana_keypair::Keypair, solana_kite::{ assert_token_account_balance, create_wallet, send_transaction_from_instructions, - token_extensions::{ - mint_tokens_to_token_extensions_account, TOKEN_EXTENSIONS_PROGRAM_ID, - }, + token_extensions::{mint_tokens_to_token_extensions_account, TOKEN_EXTENSIONS_PROGRAM_ID}, }, - solana_keypair::Keypair, solana_signer::Signer, }; @@ -40,7 +38,11 @@ fn create_token_account_instructions( let space: u64 = 200; let lamports: u64 = 3_000_000; let create_account_ix = anchor_lang::solana_program::system_instruction::create_account( - payer, account, lamports, space, &TOKEN_EXTENSIONS_PROGRAM_ID, + payer, + account, + lamports, + space, + &TOKEN_EXTENSIONS_PROGRAM_ID, ); // InitializeAccount3 (instruction 18): [18, owner(32)] let mut init_data = vec![18u8]; @@ -95,7 +97,13 @@ fn test_create_mint_with_permanent_delegate_and_burn() { } .to_account_metas(None), ); - send_transaction_from_instructions(&mut svm, vec![initialize_ix], &[&payer, &mint_keypair], &payer.pubkey()).unwrap(); + send_transaction_from_instructions( + &mut svm, + vec![initialize_ix], + &[&payer, &mint_keypair], + &payer.pubkey(), + ) + .unwrap(); svm.expire_blockhash(); // Step 2: Create a token account owned by a random keypair @@ -107,7 +115,13 @@ fn test_create_mint_with_permanent_delegate_and_burn() { &mint_keypair.pubkey(), &random_owner.pubkey(), ); - send_transaction_from_instructions(&mut svm, create_ata_ixs, &[&payer, &token_account], &payer.pubkey()).unwrap(); + send_transaction_from_instructions( + &mut svm, + create_ata_ixs, + &[&payer, &token_account], + &payer.pubkey(), + ) + .unwrap(); svm.expire_blockhash(); // Step 3: Mint 100 tokens to the token account @@ -117,7 +131,8 @@ fn test_create_mint_with_permanent_delegate_and_burn() { &token_account.pubkey(), 100, &payer, - ).unwrap(); + ) + .unwrap(); svm.expire_blockhash(); // Step 4: Burn all 100 tokens using the permanent delegate (payer) @@ -128,7 +143,13 @@ fn test_create_mint_with_permanent_delegate_and_burn() { 100, 2, // decimals ); - send_transaction_from_instructions(&mut svm, vec![burn_ix], &[&payer], &payer.pubkey()).unwrap(); + send_transaction_from_instructions(&mut svm, vec![burn_ix], &[&payer], &payer.pubkey()) + .unwrap(); - assert_token_account_balance(&svm, &token_account.pubkey(), 0, "Token account balance should be 0 after burn"); + assert_token_account_balance( + &svm, + &token_account.pubkey(), + 0, + "Token account balance should be 0 after burn", + ); } diff --git a/tokens/token-extensions/transfer-fee/anchor-v1/programs/transfer-fee/src/instructions/harvest.rs b/tokens/token-extensions/transfer-fee/anchor-v1/programs/transfer-fee/src/instructions/harvest.rs index 870e29474..e5de196bf 100644 --- a/tokens/token-extensions/transfer-fee/anchor-v1/programs/transfer-fee/src/instructions/harvest.rs +++ b/tokens/token-extensions/transfer-fee/anchor-v1/programs/transfer-fee/src/instructions/harvest.rs @@ -12,7 +12,9 @@ pub struct HarvestAccountConstraints<'info> { // transfer fees are stored directly on the recipient token account and must be "harvested" // "harvesting" transfers fees accumulated on token accounts to the mint account -pub fn process_harvest<'info>(context: Context<'info, HarvestAccountConstraints<'info>>) -> Result<()> { +pub fn process_harvest<'info>( + context: Context<'info, HarvestAccountConstraints<'info>>, +) -> Result<()> { // Using remaining accounts to allow for passing in an unknown number of token accounts to harvest from // Check that remaining accounts are token accounts for the mint to harvest to let sources = context diff --git a/tokens/token-extensions/transfer-fee/anchor-v1/programs/transfer-fee/src/instructions/initialize.rs b/tokens/token-extensions/transfer-fee/anchor-v1/programs/transfer-fee/src/instructions/initialize.rs index 1ce456378..67106bd71 100644 --- a/tokens/token-extensions/transfer-fee/anchor-v1/programs/transfer-fee/src/instructions/initialize.rs +++ b/tokens/token-extensions/transfer-fee/anchor-v1/programs/transfer-fee/src/instructions/initialize.rs @@ -53,8 +53,8 @@ pub fn handle_process_initialize( to: context.accounts.mint_account.to_account_info(), }, ), - lamports, // Lamports - mint_size as u64, // Space + lamports, // Lamports + mint_size as u64, // Space &context.accounts.token_program.key(), // Owner Program )?; @@ -70,8 +70,8 @@ pub fn handle_process_initialize( ), Some(&context.accounts.payer.key()), // transfer fee config authority (update fee) Some(&context.accounts.payer.key()), // withdraw authority (withdraw fees) - transfer_fee_basis_points, // transfer fee basis points (% fee per transfer) - maximum_fee, // maximum fee (maximum units of token per transfer) + transfer_fee_basis_points, // transfer fee basis points (% fee per transfer) + maximum_fee, // maximum fee (maximum units of token per transfer) )?; // Initialize the standard mint account data @@ -82,7 +82,7 @@ pub fn handle_process_initialize( mint: context.accounts.mint_account.to_account_info(), }, ), - 2, // decimals + 2, // decimals &context.accounts.payer.key(), // mint authority Some(&context.accounts.payer.key()), // freeze authority )?; @@ -111,4 +111,3 @@ pub fn handle_check_mint_data(accounts: &InitializeAccountConstraints) -> Result msg!("{:?}", extension_data); Ok(()) } - diff --git a/tokens/token-extensions/transfer-fee/anchor-v1/programs/transfer-fee/src/instructions/transfer.rs b/tokens/token-extensions/transfer-fee/anchor-v1/programs/transfer-fee/src/instructions/transfer.rs index 20846e2e7..a0c359cf0 100644 --- a/tokens/token-extensions/transfer-fee/anchor-v1/programs/transfer-fee/src/instructions/transfer.rs +++ b/tokens/token-extensions/transfer-fee/anchor-v1/programs/transfer-fee/src/instructions/transfer.rs @@ -43,7 +43,10 @@ pub struct TransferAccountConstraints<'info> { // transfer fees are automatically deducted from the transfer amount // recipients receives (transfer amount - fees) // transfer fees are stored directly on the recipient token account and must be "harvested" -pub fn handle_process_transfer(context: Context, amount: u64) -> Result<()> { +pub fn handle_process_transfer( + context: Context, + amount: u64, +) -> Result<()> { // read mint account extension data let mint = &context.accounts.mint_account.to_account_info(); let mint_data = mint.data.borrow(); diff --git a/tokens/token-extensions/transfer-fee/anchor-v1/programs/transfer-fee/tests/test_transfer_fee.rs b/tokens/token-extensions/transfer-fee/anchor-v1/programs/transfer-fee/tests/test_transfer_fee.rs index 087f1ae6d..2d7de4cbd 100644 --- a/tokens/token-extensions/transfer-fee/anchor-v1/programs/transfer-fee/tests/test_transfer_fee.rs +++ b/tokens/token-extensions/transfer-fee/anchor-v1/programs/transfer-fee/tests/test_transfer_fee.rs @@ -8,6 +8,7 @@ use { InstructionData, ToAccountMetas, }, litesvm::LiteSVM, + solana_keypair::Keypair, solana_kite::{ create_wallet, send_transaction_from_instructions, token_extensions::{ @@ -15,7 +16,6 @@ use { mint_tokens_to_token_extensions_account, TOKEN_EXTENSIONS_PROGRAM_ID, }, }, - solana_keypair::Keypair, solana_signer::Signer, }; @@ -44,7 +44,8 @@ fn test_transfer_fee_full_flow() { let ata_program = associated_token_program_id(); let sender_ata = get_token_extensions_account_address(&payer.pubkey(), &mint_keypair.pubkey()); - let recipient_ata = get_token_extensions_account_address(&recipient.pubkey(), &mint_keypair.pubkey()); + let recipient_ata = + get_token_extensions_account_address(&recipient.pubkey(), &mint_keypair.pubkey()); // Step 1: Create mint with transfer fee (100 basis points = 1%, max fee = 1) let initialize_ix = Instruction::new_with_bytes( @@ -62,16 +63,18 @@ fn test_transfer_fee_full_flow() { } .to_account_metas(None), ); - send_transaction_from_instructions(&mut svm, vec![initialize_ix], &[&payer, &mint_keypair], &payer.pubkey()).unwrap(); + send_transaction_from_instructions( + &mut svm, + vec![initialize_ix], + &[&payer, &mint_keypair], + &payer.pubkey(), + ) + .unwrap(); svm.expire_blockhash(); // Step 2: Create sender ATA and mint 300 tokens - create_token_extensions_account( - &mut svm, - &payer.pubkey(), - &mint_keypair.pubkey(), - &payer, - ).unwrap(); + create_token_extensions_account(&mut svm, &payer.pubkey(), &mint_keypair.pubkey(), &payer) + .unwrap(); svm.expire_blockhash(); mint_tokens_to_token_extensions_account( @@ -80,7 +83,8 @@ fn test_transfer_fee_full_flow() { &sender_ata, 300, &payer, - ).unwrap(); + ) + .unwrap(); svm.expire_blockhash(); // Step 3: Transfer 100 tokens (fee = min(1% * 100 = 1, max_fee = 1) = 1) @@ -99,7 +103,8 @@ fn test_transfer_fee_full_flow() { } .to_account_metas(None), ); - send_transaction_from_instructions(&mut svm, vec![transfer_ix], &[&payer], &payer.pubkey()).unwrap(); + send_transaction_from_instructions(&mut svm, vec![transfer_ix], &[&payer], &payer.pubkey()) + .unwrap(); svm.expire_blockhash(); // Step 4: Transfer 200 tokens (fee = min(1% * 200 = 2, max_fee = 1) = 1, capped by maximumFee) @@ -118,14 +123,13 @@ fn test_transfer_fee_full_flow() { } .to_account_metas(None), ); - send_transaction_from_instructions(&mut svm, vec![transfer_ix2], &[&payer], &payer.pubkey()).unwrap(); + send_transaction_from_instructions(&mut svm, vec![transfer_ix2], &[&payer], &payer.pubkey()) + .unwrap(); svm.expire_blockhash(); // Step 5: Harvest transfer fees from recipient token account to mint - let harvest_ix = Instruction::new_with_bytes( - program_id, - &transfer_fee::instruction::Harvest {}.data(), - { + let harvest_ix = + Instruction::new_with_bytes(program_id, &transfer_fee::instruction::Harvest {}.data(), { let mut metas = transfer_fee::accounts::HarvestAccountConstraints { mint_account: mint_keypair.pubkey(), token_program: TOKEN_EXTENSIONS_PROGRAM_ID, @@ -133,9 +137,9 @@ fn test_transfer_fee_full_flow() { .to_account_metas(None); metas.push(AccountMeta::new(recipient_ata, false)); metas - }, - ); - send_transaction_from_instructions(&mut svm, vec![harvest_ix], &[&payer], &payer.pubkey()).unwrap(); + }); + send_transaction_from_instructions(&mut svm, vec![harvest_ix], &[&payer], &payer.pubkey()) + .unwrap(); svm.expire_blockhash(); // Step 6: Withdraw harvested fees from mint to sender's token account @@ -150,7 +154,8 @@ fn test_transfer_fee_full_flow() { } .to_account_metas(None), ); - send_transaction_from_instructions(&mut svm, vec![withdraw_ix], &[&payer], &payer.pubkey()).unwrap(); + send_transaction_from_instructions(&mut svm, vec![withdraw_ix], &[&payer], &payer.pubkey()) + .unwrap(); svm.expire_blockhash(); // Step 7: Update transfer fee to 0 @@ -168,5 +173,6 @@ fn test_transfer_fee_full_flow() { } .to_account_metas(None), ); - send_transaction_from_instructions(&mut svm, vec![update_fee_ix], &[&payer], &payer.pubkey()).unwrap(); + send_transaction_from_instructions(&mut svm, vec![update_fee_ix], &[&payer], &payer.pubkey()) + .unwrap(); } diff --git a/tokens/token-extensions/transfer-hook/account-data-as-seed/anchor-v1/programs/transfer-hook/src/instructions/initialize_extra_account_meta_list.rs b/tokens/token-extensions/transfer-hook/account-data-as-seed/anchor-v1/programs/transfer-hook/src/instructions/initialize_extra_account_meta_list.rs index 34c854ce9..94f9947ab 100644 --- a/tokens/token-extensions/transfer-hook/account-data-as-seed/anchor-v1/programs/transfer-hook/src/instructions/initialize_extra_account_meta_list.rs +++ b/tokens/token-extensions/transfer-hook/account-data-as-seed/anchor-v1/programs/transfer-hook/src/instructions/initialize_extra_account_meta_list.rs @@ -1,9 +1,5 @@ use anchor_lang::prelude::*; -use anchor_spl::{ - associated_token::AssociatedToken, - token_2022::Token2022, - token_interface::Mint, -}; +use anchor_spl::{associated_token::AssociatedToken, token_2022::Token2022, token_interface::Mint}; use spl_tlv_account_resolution::state::ExtraAccountMetaList; use spl_transfer_hook_interface::instruction::ExecuteInstruction; @@ -34,16 +30,22 @@ pub struct InitializeExtraAccountMetaListAccountConstraints<'info> { pub system_program: Program<'info, System>, } -pub fn handler(mut context: Context) -> Result<()> { +pub fn handler( + mut context: Context, +) -> Result<()> { let extra_account_metas = handle_extra_account_metas()?; // initialize ExtraAccountMetaList account with extra accounts // .map_err() needed because spl-tlv-account-resolution uses solana-program-error 2.x // while anchor-lang 1.0 uses 3.x - structurally identical but different semver types ExtraAccountMetaList::init::( - &mut context.accounts.extra_account_meta_list.try_borrow_mut_data()?, + &mut context + .accounts + .extra_account_meta_list + .try_borrow_mut_data()?, &extra_account_metas, - ).map_err(|_| ProgramError::InvalidAccountData)?; + ) + .map_err(|_| ProgramError::InvalidAccountData)?; context.accounts.counter_account.bump = context.bumps.counter_account; diff --git a/tokens/token-extensions/transfer-hook/account-data-as-seed/anchor-v1/programs/transfer-hook/src/lib.rs b/tokens/token-extensions/transfer-hook/account-data-as-seed/anchor-v1/programs/transfer-hook/src/lib.rs index f064e424e..c0b6f0ec0 100644 --- a/tokens/token-extensions/transfer-hook/account-data-as-seed/anchor-v1/programs/transfer-hook/src/lib.rs +++ b/tokens/token-extensions/transfer-hook/account-data-as-seed/anchor-v1/programs/transfer-hook/src/lib.rs @@ -3,13 +3,12 @@ use std::cell::RefMut; use anchor_lang::prelude::*; use anchor_spl::token_2022::spl_token_2022::{ extension::{ - transfer_hook::TransferHookAccount, BaseStateWithExtensionsMut, - PodStateWithExtensionsMut, + transfer_hook::TransferHookAccount, BaseStateWithExtensionsMut, PodStateWithExtensionsMut, }, pod::PodAccount, }; -use spl_tlv_account_resolution::{account::ExtraAccountMeta, seeds::Seed}; use spl_discriminator::SplDiscriminate; +use spl_tlv_account_resolution::{account::ExtraAccountMeta, seeds::Seed}; use spl_transfer_hook_interface::instruction::{ ExecuteInstruction, InitializeExtraAccountMetaListInstruction, }; @@ -41,7 +40,10 @@ pub mod transfer_hook { } #[instruction(discriminator = ExecuteInstruction::SPL_DISCRIMINATOR_SLICE)] - pub fn transfer_hook(context: Context, amount: u64) -> Result<()> { + pub fn transfer_hook( + context: Context, + amount: u64, + ) -> Result<()> { instructions::transfer_hook::handler(context, amount) } } @@ -53,7 +55,8 @@ pub fn check_is_transferring(context: &Context) // while anchor-lang 1.0 uses 3.x - structurally identical but different semver types let mut account = PodStateWithExtensionsMut::::unpack(*account_data_ref) .map_err(|_| ProgramError::InvalidAccountData)?; - let account_extension = account.get_extension_mut::() + let account_extension = account + .get_extension_mut::() .map_err(|_| ProgramError::InvalidAccountData)?; if !bool::from(account_extension.transferring) { @@ -80,7 +83,8 @@ pub fn handle_extra_account_metas() -> Result> { ], false, // is_signer true, // is_writable - ).map_err(|_| ProgramError::InvalidArgument)?]) + ) + .map_err(|_| ProgramError::InvalidArgument)?]) } /// Returns the count of extra account metas (avoids the error conversion issue in #[account] attributes) diff --git a/tokens/token-extensions/transfer-hook/account-data-as-seed/anchor-v1/programs/transfer-hook/tests/test_transfer_hook.rs b/tokens/token-extensions/transfer-hook/account-data-as-seed/anchor-v1/programs/transfer-hook/tests/test_transfer_hook.rs index 12d34a3ca..39de57ed7 100644 --- a/tokens/token-extensions/transfer-hook/account-data-as-seed/anchor-v1/programs/transfer-hook/tests/test_transfer_hook.rs +++ b/tokens/token-extensions/transfer-hook/account-data-as-seed/anchor-v1/programs/transfer-hook/tests/test_transfer_hook.rs @@ -1,14 +1,11 @@ use { anchor_lang::{ - solana_program::{ - instruction::Instruction, - pubkey::Pubkey, - system_program, - }, + solana_program::{instruction::Instruction, pubkey::Pubkey, system_program}, InstructionData, ToAccountMetas, }, borsh::BorshDeserialize, litesvm::LiteSVM, + solana_keypair::Keypair, solana_kite::{ create_wallet, send_transaction_from_instructions, token_extensions::{ @@ -18,7 +15,6 @@ use { }, transfer_hook::{build_hook_accounts, get_hook_accounts_address, HookAccount}, }, - solana_keypair::Keypair, solana_signer::Signer, }; @@ -77,34 +73,19 @@ fn test_transfer_hook_account_data_as_seed() { .unwrap(); svm.expire_blockhash(); - let extra_account_meta_list = - get_hook_accounts_address(&mint, &program_id); + let extra_account_meta_list = get_hook_accounts_address(&mint, &program_id); // Step 2: Create token accounts and mint tokens let amount: u64 = 100 * 10u64.pow(decimals as u32); - let source_ata = create_token_extensions_account( - &mut svm, - &payer.pubkey(), - &mint, - &payer, - ).unwrap(); + let source_ata = + create_token_extensions_account(&mut svm, &payer.pubkey(), &mint, &payer).unwrap(); svm.expire_blockhash(); - let dest_ata = create_token_extensions_account( - &mut svm, - &recipient.pubkey(), - &mint, - &payer, - ).unwrap(); + let dest_ata = + create_token_extensions_account(&mut svm, &recipient.pubkey(), &mint, &payer).unwrap(); svm.expire_blockhash(); - mint_tokens_to_token_extensions_account( - &mut svm, - &mint, - &source_ata, - amount, - &payer, - ).unwrap(); + mint_tokens_to_token_extensions_account(&mut svm, &mint, &source_ata, amount, &payer).unwrap(); svm.expire_blockhash(); // Step 3: Initialize ExtraAccountMetaList (also creates counter PDA) @@ -122,7 +103,8 @@ fn test_transfer_hook_account_data_as_seed() { } .to_account_metas(None), ); - send_transaction_from_instructions(&mut svm, vec![init_extra_ix], &[&payer], &payer.pubkey()).unwrap(); + send_transaction_from_instructions(&mut svm, vec![init_extra_ix], &[&payer], &payer.pubkey()) + .unwrap(); svm.expire_blockhash(); // Step 4: Transfer with hook @@ -145,7 +127,8 @@ fn test_transfer_hook_account_data_as_seed() { transfer_amount, decimals, &extra_accounts, - ).unwrap(); + ) + .unwrap(); svm.expire_blockhash(); // The hook writes the incremented count back, so it survives the transfer. @@ -166,7 +149,12 @@ fn test_transfer_hook_account_data_as_seed() { } .to_account_metas(None), ); - let result = send_transaction_from_instructions(&mut svm, vec![direct_hook_ix], &[&payer], &payer.pubkey()); + let result = send_transaction_from_instructions( + &mut svm, + vec![direct_hook_ix], + &[&payer], + &payer.pubkey(), + ); assert!( result.is_err(), "Calling transfer_hook directly should fail because token is not transferring" diff --git a/tokens/token-extensions/transfer-hook/allow-block-list-token/anchor-v1/programs/abl-token/src/lib.rs b/tokens/token-extensions/transfer-hook/allow-block-list-token/anchor-v1/programs/abl-token/src/lib.rs index 517ef28d2..827666cb0 100644 --- a/tokens/token-extensions/transfer-hook/allow-block-list-token/anchor-v1/programs/abl-token/src/lib.rs +++ b/tokens/token-extensions/transfer-hook/allow-block-list-token/anchor-v1/programs/abl-token/src/lib.rs @@ -20,7 +20,10 @@ pub mod abl_token { use super::*; - pub fn init_mint(context: Context, args: InitMintArgs) -> Result<()> { + pub fn init_mint( + context: Context, + args: InitMintArgs, + ) -> Result<()> { context.accounts.init_mint(args) } @@ -37,7 +40,10 @@ pub mod abl_token { context.accounts.tx_hook(amount) } - pub fn init_wallet(context: Context, args: InitWalletArgs) -> Result<()> { + pub fn init_wallet( + context: Context, + args: InitWalletArgs, + ) -> Result<()> { let bump = context.bumps.ab_wallet; context.accounts.init_wallet(args, bump) } @@ -46,7 +52,10 @@ pub mod abl_token { context.accounts.remove_wallet() } - pub fn change_mode(context: Context, args: ChangeModeArgs) -> Result<()> { + pub fn change_mode( + context: Context, + args: ChangeModeArgs, + ) -> Result<()> { context.accounts.change_mode(args) } } diff --git a/tokens/token-extensions/transfer-hook/allow-block-list-token/anchor-v1/programs/abl-token/src/utils.rs b/tokens/token-extensions/transfer-hook/allow-block-list-token/anchor-v1/programs/abl-token/src/utils.rs index 7ffc952ad..cd51f2db6 100644 --- a/tokens/token-extensions/transfer-hook/allow-block-list-token/anchor-v1/programs/abl-token/src/utils.rs +++ b/tokens/token-extensions/transfer-hook/allow-block-list-token/anchor-v1/programs/abl-token/src/utils.rs @@ -26,6 +26,7 @@ pub fn get_extra_account_metas() -> Result> { ], false, false, - ).map_err(|_| ProgramError::InvalidArgument)?, // [2] destination token account + ) + .map_err(|_| ProgramError::InvalidArgument)?, // [2] destination token account ]) } diff --git a/tokens/token-extensions/transfer-hook/allow-block-list-token/anchor-v1/programs/abl-token/tests/test_abl_token.rs b/tokens/token-extensions/transfer-hook/allow-block-list-token/anchor-v1/programs/abl-token/tests/test_abl_token.rs index ccc5712cd..d63851fa5 100644 --- a/tokens/token-extensions/transfer-hook/allow-block-list-token/anchor-v1/programs/abl-token/tests/test_abl_token.rs +++ b/tokens/token-extensions/transfer-hook/allow-block-list-token/anchor-v1/programs/abl-token/tests/test_abl_token.rs @@ -1,18 +1,14 @@ use { anchor_lang::{ - solana_program::{ - instruction::Instruction, - pubkey::Pubkey, - system_program, - }, + solana_program::{instruction::Instruction, pubkey::Pubkey, system_program}, InstructionData, ToAccountMetas, }, litesvm::LiteSVM, + solana_keypair::Keypair, solana_kite::{ create_wallet, send_transaction_from_instructions, token_extensions::TOKEN_EXTENSIONS_PROGRAM_ID, }, - solana_keypair::Keypair, solana_signer::Signer, }; @@ -33,8 +29,7 @@ fn test_init_config_and_init_mint() { let mint_keypair = Keypair::new(); // Derive PDAs - let (config_pda, _) = - Pubkey::find_program_address(&[b"config"], &program_id); + let (config_pda, _) = Pubkey::find_program_address(&[b"config"], &program_id); let (extra_account_meta_list, _) = Pubkey::find_program_address( &[b"extra-account-metas", mint_keypair.pubkey().as_ref()], &program_id, @@ -51,7 +46,8 @@ fn test_init_config_and_init_mint() { } .to_account_metas(None), ); - send_transaction_from_instructions(&mut svm, vec![init_config_ix], &[&payer], &payer.pubkey()).unwrap(); + send_transaction_from_instructions(&mut svm, vec![init_config_ix], &[&payer], &payer.pubkey()) + .unwrap(); svm.expire_blockhash(); // Step 2: Initialize mint with transfer hook and metadata @@ -82,5 +78,11 @@ fn test_init_config_and_init_mint() { } .to_account_metas(None), ); - send_transaction_from_instructions(&mut svm, vec![init_mint_ix], &[&payer, &mint_keypair], &payer.pubkey()).unwrap(); + send_transaction_from_instructions( + &mut svm, + vec![init_mint_ix], + &[&payer, &mint_keypair], + &payer.pubkey(), + ) + .unwrap(); } diff --git a/tokens/token-extensions/transfer-hook/counter/anchor-v1/programs/transfer-hook/src/instructions/initialize_extra_account_meta_list.rs b/tokens/token-extensions/transfer-hook/counter/anchor-v1/programs/transfer-hook/src/instructions/initialize_extra_account_meta_list.rs index 7aef4af81..4a8b062c1 100644 --- a/tokens/token-extensions/transfer-hook/counter/anchor-v1/programs/transfer-hook/src/instructions/initialize_extra_account_meta_list.rs +++ b/tokens/token-extensions/transfer-hook/counter/anchor-v1/programs/transfer-hook/src/instructions/initialize_extra_account_meta_list.rs @@ -1,9 +1,5 @@ use anchor_lang::prelude::*; -use anchor_spl::{ - associated_token::AssociatedToken, - token_2022::Token2022, - token_interface::Mint, -}; +use anchor_spl::{associated_token::AssociatedToken, token_2022::Token2022, token_interface::Mint}; use spl_tlv_account_resolution::state::ExtraAccountMetaList; use spl_transfer_hook_interface::instruction::ExecuteInstruction; @@ -34,16 +30,22 @@ pub struct InitializeExtraAccountMetaListAccountConstraints<'info> { pub system_program: Program<'info, System>, } -pub fn handler(mut context: Context) -> Result<()> { +pub fn handler( + mut context: Context, +) -> Result<()> { let extra_account_metas = handle_extra_account_metas()?; // initialize ExtraAccountMetaList account with extra accounts // .map_err() needed because spl-tlv-account-resolution uses solana-program-error 2.x // while anchor-lang 1.0 uses 3.x - structurally identical but different semver types ExtraAccountMetaList::init::( - &mut context.accounts.extra_account_meta_list.try_borrow_mut_data()?, + &mut context + .accounts + .extra_account_meta_list + .try_borrow_mut_data()?, &extra_account_metas, - ).map_err(|_| ProgramError::InvalidAccountData)?; + ) + .map_err(|_| ProgramError::InvalidAccountData)?; context.accounts.counter_account.bump = context.bumps.counter_account; diff --git a/tokens/token-extensions/transfer-hook/counter/anchor-v1/programs/transfer-hook/src/lib.rs b/tokens/token-extensions/transfer-hook/counter/anchor-v1/programs/transfer-hook/src/lib.rs index 5d18c72fe..bdd2ff6a8 100644 --- a/tokens/token-extensions/transfer-hook/counter/anchor-v1/programs/transfer-hook/src/lib.rs +++ b/tokens/token-extensions/transfer-hook/counter/anchor-v1/programs/transfer-hook/src/lib.rs @@ -3,13 +3,12 @@ use std::cell::RefMut; use anchor_lang::prelude::*; use anchor_spl::token_2022::spl_token_2022::{ extension::{ - transfer_hook::TransferHookAccount, BaseStateWithExtensionsMut, - PodStateWithExtensionsMut, + transfer_hook::TransferHookAccount, BaseStateWithExtensionsMut, PodStateWithExtensionsMut, }, pod::PodAccount, }; -use spl_tlv_account_resolution::{account::ExtraAccountMeta, seeds::Seed}; use spl_discriminator::SplDiscriminate; +use spl_tlv_account_resolution::{account::ExtraAccountMeta, seeds::Seed}; use spl_transfer_hook_interface::instruction::{ ExecuteInstruction, InitializeExtraAccountMetaListInstruction, }; @@ -41,7 +40,10 @@ pub mod transfer_hook { } #[instruction(discriminator = ExecuteInstruction::SPL_DISCRIMINATOR_SLICE)] - pub fn transfer_hook(context: Context, amount: u64) -> Result<()> { + pub fn transfer_hook( + context: Context, + amount: u64, + ) -> Result<()> { instructions::transfer_hook::handler(context, amount) } } @@ -69,7 +71,8 @@ pub fn handle_extra_account_metas() -> Result> { }], false, // is_signer true, // is_writable - ).map_err(|_| ProgramError::InvalidArgument)?]) + ) + .map_err(|_| ProgramError::InvalidArgument)?]) } /// Returns the count of extra account metas (avoids the error conversion issue in #[account] attributes) diff --git a/tokens/token-extensions/transfer-hook/counter/anchor-v1/programs/transfer-hook/tests/test_transfer_hook_counter.rs b/tokens/token-extensions/transfer-hook/counter/anchor-v1/programs/transfer-hook/tests/test_transfer_hook_counter.rs index 5dc54feba..a09de2069 100644 --- a/tokens/token-extensions/transfer-hook/counter/anchor-v1/programs/transfer-hook/tests/test_transfer_hook_counter.rs +++ b/tokens/token-extensions/transfer-hook/counter/anchor-v1/programs/transfer-hook/tests/test_transfer_hook_counter.rs @@ -1,14 +1,11 @@ use { anchor_lang::{ - solana_program::{ - instruction::Instruction, - pubkey::Pubkey, - system_program, - }, + solana_program::{instruction::Instruction, pubkey::Pubkey, system_program}, InstructionData, ToAccountMetas, }, borsh::BorshDeserialize, litesvm::LiteSVM, + solana_keypair::Keypair, solana_kite::{ create_wallet, send_transaction_from_instructions, token_extensions::{ @@ -18,7 +15,6 @@ use { }, transfer_hook::{build_hook_accounts, get_hook_accounts_address, HookAccount}, }, - solana_keypair::Keypair, solana_signer::Signer, }; @@ -75,36 +71,21 @@ fn test_transfer_hook_counter() { .unwrap(); svm.expire_blockhash(); - let extra_account_meta_list = - get_hook_accounts_address(&mint, &program_id); + let extra_account_meta_list = get_hook_accounts_address(&mint, &program_id); // Step 2: Create token accounts and mint tokens let recipient = Keypair::new(); let amount: u64 = 100 * 10u64.pow(decimals as u32); - let source_ata = create_token_extensions_account( - &mut svm, - &payer.pubkey(), - &mint, - &payer, - ).unwrap(); + let source_ata = + create_token_extensions_account(&mut svm, &payer.pubkey(), &mint, &payer).unwrap(); svm.expire_blockhash(); - let dest_ata = create_token_extensions_account( - &mut svm, - &recipient.pubkey(), - &mint, - &payer, - ).unwrap(); + let dest_ata = + create_token_extensions_account(&mut svm, &recipient.pubkey(), &mint, &payer).unwrap(); svm.expire_blockhash(); - mint_tokens_to_token_extensions_account( - &mut svm, - &mint, - &source_ata, - amount, - &payer, - ).unwrap(); + mint_tokens_to_token_extensions_account(&mut svm, &mint, &source_ata, amount, &payer).unwrap(); svm.expire_blockhash(); // Step 3: Initialize ExtraAccountMetaList (also creates counter PDA) @@ -122,7 +103,8 @@ fn test_transfer_hook_counter() { } .to_account_metas(None), ); - send_transaction_from_instructions(&mut svm, vec![init_extra_ix], &[&payer], &payer.pubkey()).unwrap(); + send_transaction_from_instructions(&mut svm, vec![init_extra_ix], &[&payer], &payer.pubkey()) + .unwrap(); svm.expire_blockhash(); // Step 4: Transfer with hook (this triggers the counter increment) @@ -145,7 +127,8 @@ fn test_transfer_hook_counter() { transfer_amount, decimals, &extra_accounts, - ).unwrap(); + ) + .unwrap(); svm.expire_blockhash(); // The hook writes the incremented count back, so it survives the transfer. @@ -166,7 +149,12 @@ fn test_transfer_hook_counter() { } .to_account_metas(None), ); - let result = send_transaction_from_instructions(&mut svm, vec![direct_hook_ix], &[&payer], &payer.pubkey()); + let result = send_transaction_from_instructions( + &mut svm, + vec![direct_hook_ix], + &[&payer], + &payer.pubkey(), + ); assert!( result.is_err(), "Calling transfer_hook directly should fail because token is not transferring" diff --git a/tokens/token-extensions/transfer-hook/hello-world/anchor-v1/programs/transfer-hook/src/instructions/initialize.rs b/tokens/token-extensions/transfer-hook/hello-world/anchor-v1/programs/transfer-hook/src/instructions/initialize.rs index 7cc60c7bf..109b6fb59 100644 --- a/tokens/token-extensions/transfer-hook/hello-world/anchor-v1/programs/transfer-hook/src/instructions/initialize.rs +++ b/tokens/token-extensions/transfer-hook/hello-world/anchor-v1/programs/transfer-hook/src/instructions/initialize.rs @@ -44,7 +44,8 @@ fn handle_check_mint_data(accounts: &mut InitializeAccountConstraints) -> Result // while anchor-lang 1.0 uses 3.x - structurally identical but different semver types let mint_with_extension = StateWithExtensions::::unpack(&mint_data) .map_err(|_| ProgramError::InvalidAccountData)?; - let extension_data = mint_with_extension.get_extension::() + let extension_data = mint_with_extension + .get_extension::() .map_err(|_| ProgramError::InvalidAccountData)?; assert_eq!( diff --git a/tokens/token-extensions/transfer-hook/hello-world/anchor-v1/programs/transfer-hook/src/instructions/initialize_extra_account_meta_list.rs b/tokens/token-extensions/transfer-hook/hello-world/anchor-v1/programs/transfer-hook/src/instructions/initialize_extra_account_meta_list.rs index 5a858e593..099c140cb 100644 --- a/tokens/token-extensions/transfer-hook/hello-world/anchor-v1/programs/transfer-hook/src/instructions/initialize_extra_account_meta_list.rs +++ b/tokens/token-extensions/transfer-hook/hello-world/anchor-v1/programs/transfer-hook/src/instructions/initialize_extra_account_meta_list.rs @@ -31,16 +31,22 @@ pub struct InitializeExtraAccountMetaListAccountConstraints<'info> { pub system_program: Program<'info, System>, } -pub fn handler(mut context: Context) -> Result<()> { +pub fn handler( + mut context: Context, +) -> Result<()> { let extra_account_metas = handle_extra_account_metas()?; // initialize ExtraAccountMetaList account with extra accounts // .map_err() needed because spl-tlv-account-resolution uses solana-program-error 2.x // while anchor-lang 1.0 uses 3.x - structurally identical but different semver types ExtraAccountMetaList::init::( - &mut context.accounts.extra_account_meta_list.try_borrow_mut_data()?, + &mut context + .accounts + .extra_account_meta_list + .try_borrow_mut_data()?, &extra_account_metas, - ).map_err(|_| ProgramError::InvalidAccountData)?; + ) + .map_err(|_| ProgramError::InvalidAccountData)?; Ok(()) } diff --git a/tokens/token-extensions/transfer-hook/hello-world/anchor-v1/programs/transfer-hook/src/lib.rs b/tokens/token-extensions/transfer-hook/hello-world/anchor-v1/programs/transfer-hook/src/lib.rs index 9ef5d2be4..21f9fbdaa 100644 --- a/tokens/token-extensions/transfer-hook/hello-world/anchor-v1/programs/transfer-hook/src/lib.rs +++ b/tokens/token-extensions/transfer-hook/hello-world/anchor-v1/programs/transfer-hook/src/lib.rs @@ -3,13 +3,12 @@ use std::cell::RefMut; use anchor_lang::prelude::*; use anchor_spl::token_2022::spl_token_2022::{ extension::{ - transfer_hook::TransferHookAccount, BaseStateWithExtensionsMut, - PodStateWithExtensionsMut, + transfer_hook::TransferHookAccount, BaseStateWithExtensionsMut, PodStateWithExtensionsMut, }, pod::PodAccount, }; -use spl_tlv_account_resolution::account::ExtraAccountMeta; use spl_discriminator::SplDiscriminate; +use spl_tlv_account_resolution::account::ExtraAccountMeta; use spl_transfer_hook_interface::instruction::{ ExecuteInstruction, InitializeExtraAccountMetaListInstruction, }; @@ -41,7 +40,10 @@ pub mod transfer_hook { } #[instruction(discriminator = ExecuteInstruction::SPL_DISCRIMINATOR_SLICE)] - pub fn transfer_hook(context: Context, amount: u64) -> Result<()> { + pub fn transfer_hook( + context: Context, + amount: u64, + ) -> Result<()> { instructions::transfer_hook::handler(context, amount) } } @@ -53,7 +55,8 @@ pub fn check_is_transferring(context: &Context) // while anchor-lang 1.0 uses 3.x - structurally identical but different semver types let mut account = PodStateWithExtensionsMut::::unpack(*account_data_ref) .map_err(|_| ProgramError::InvalidAccountData)?; - let account_extension = account.get_extension_mut::() + let account_extension = account + .get_extension_mut::() .map_err(|_| ProgramError::InvalidAccountData)?; if !bool::from(account_extension.transferring) { diff --git a/tokens/token-extensions/transfer-hook/hello-world/anchor-v1/programs/transfer-hook/tests/test_transfer_hook.rs b/tokens/token-extensions/transfer-hook/hello-world/anchor-v1/programs/transfer-hook/tests/test_transfer_hook.rs index 7471118f0..99a5a2e8a 100644 --- a/tokens/token-extensions/transfer-hook/hello-world/anchor-v1/programs/transfer-hook/tests/test_transfer_hook.rs +++ b/tokens/token-extensions/transfer-hook/hello-world/anchor-v1/programs/transfer-hook/tests/test_transfer_hook.rs @@ -1,13 +1,10 @@ use { anchor_lang::{ - solana_program::{ - instruction::Instruction, - pubkey::Pubkey, - system_program, - }, + solana_program::{instruction::Instruction, pubkey::Pubkey, system_program}, InstructionData, ToAccountMetas, }, litesvm::LiteSVM, + solana_keypair::Keypair, solana_kite::{ create_wallet, send_transaction_from_instructions, token_extensions::{ @@ -17,7 +14,6 @@ use { }, transfer_hook::{build_hook_accounts, get_hook_accounts_address}, }, - solana_keypair::Keypair, solana_signer::Signer, }; @@ -47,18 +43,14 @@ fn test_transfer_hook_hello_world() { let decimals: u8 = 2; // ExtraAccountMetaList PDA - let extra_account_meta_list = - get_hook_accounts_address(&mint_keypair.pubkey(), &program_id); + let extra_account_meta_list = get_hook_accounts_address(&mint_keypair.pubkey(), &program_id); // Step 1: Create mint with transfer hook extension pointing to our program // (uses the program's own Initialize instruction, not kite, since it sets up // the mint with the program as the hook authority) let initialize_ix = Instruction::new_with_bytes( program_id, - &transfer_hook::instruction::Initialize { - decimals, - } - .data(), + &transfer_hook::instruction::Initialize { decimals }.data(), transfer_hook::accounts::InitializeAccountConstraints { payer: payer.pubkey(), mint_account: mint_keypair.pubkey(), @@ -67,17 +59,20 @@ fn test_transfer_hook_hello_world() { } .to_account_metas(None), ); - send_transaction_from_instructions(&mut svm, vec![initialize_ix], &[&payer, &mint_keypair], &payer.pubkey()).unwrap(); + send_transaction_from_instructions( + &mut svm, + vec![initialize_ix], + &[&payer, &mint_keypair], + &payer.pubkey(), + ) + .unwrap(); svm.expire_blockhash(); // Step 2: Create token accounts and mint tokens let amount: u64 = 100 * 10u64.pow(decimals as u32); - let source_ata = create_token_extensions_account( - &mut svm, - &payer.pubkey(), - &mint_keypair.pubkey(), - &payer, - ).unwrap(); + let source_ata = + create_token_extensions_account(&mut svm, &payer.pubkey(), &mint_keypair.pubkey(), &payer) + .unwrap(); svm.expire_blockhash(); let dest_ata = create_token_extensions_account( @@ -85,7 +80,8 @@ fn test_transfer_hook_hello_world() { &recipient.pubkey(), &mint_keypair.pubkey(), &payer, - ).unwrap(); + ) + .unwrap(); svm.expire_blockhash(); mint_tokens_to_token_extensions_account( @@ -94,7 +90,8 @@ fn test_transfer_hook_hello_world() { &source_ata, amount, &payer, - ).unwrap(); + ) + .unwrap(); svm.expire_blockhash(); // Step 3: Create ExtraAccountMetaList account @@ -111,7 +108,8 @@ fn test_transfer_hook_hello_world() { } .to_account_metas(None), ); - send_transaction_from_instructions(&mut svm, vec![init_extra_ix], &[&payer], &payer.pubkey()).unwrap(); + send_transaction_from_instructions(&mut svm, vec![init_extra_ix], &[&payer], &payer.pubkey()) + .unwrap(); svm.expire_blockhash(); // Step 4: Transfer with transfer hook @@ -130,7 +128,8 @@ fn test_transfer_hook_hello_world() { transfer_amount, decimals, &extra_accounts, - ).unwrap(); + ) + .unwrap(); svm.expire_blockhash(); // Step 5: Try calling transfer_hook directly (should fail - not transferring) @@ -146,7 +145,12 @@ fn test_transfer_hook_hello_world() { } .to_account_metas(None), ); - let result = send_transaction_from_instructions(&mut svm, vec![direct_hook_ix], &[&payer], &payer.pubkey()); + let result = send_transaction_from_instructions( + &mut svm, + vec![direct_hook_ix], + &[&payer], + &payer.pubkey(), + ); assert!( result.is_err(), "Calling transfer_hook directly should fail because token is not transferring" diff --git a/tokens/token-extensions/transfer-hook/transfer-cost/anchor-v1/programs/transfer-hook/src/instructions/initialize_extra_account_meta_list.rs b/tokens/token-extensions/transfer-hook/transfer-cost/anchor-v1/programs/transfer-hook/src/instructions/initialize_extra_account_meta_list.rs index d19d662fe..a120cfc89 100644 --- a/tokens/token-extensions/transfer-hook/transfer-cost/anchor-v1/programs/transfer-hook/src/instructions/initialize_extra_account_meta_list.rs +++ b/tokens/token-extensions/transfer-hook/transfer-cost/anchor-v1/programs/transfer-hook/src/instructions/initialize_extra_account_meta_list.rs @@ -28,12 +28,17 @@ pub struct InitializeExtraAccountMetaListAccountConstraints<'info> { pub system_program: Program<'info, System>, } -pub fn handler(mut context: Context) -> Result<()> { +pub fn handler( + mut context: Context, +) -> Result<()> { let extra_account_metas = handle_extra_account_metas()?; // initialize ExtraAccountMetaList account with extra accounts ExtraAccountMetaList::init::( - &mut context.accounts.extra_account_meta_list.try_borrow_mut_data()?, + &mut context + .accounts + .extra_account_meta_list + .try_borrow_mut_data()?, &extra_account_metas, ) .map_err(|_| ProgramError::InvalidAccountData)?; diff --git a/tokens/token-extensions/transfer-hook/transfer-cost/anchor-v1/programs/transfer-hook/src/instructions/transfer_hook.rs b/tokens/token-extensions/transfer-hook/transfer-cost/anchor-v1/programs/transfer-hook/src/instructions/transfer_hook.rs index c7f5b9ec1..7a687b65f 100644 --- a/tokens/token-extensions/transfer-hook/transfer-cost/anchor-v1/programs/transfer-hook/src/instructions/transfer_hook.rs +++ b/tokens/token-extensions/transfer-hook/transfer-cost/anchor-v1/programs/transfer-hook/src/instructions/transfer_hook.rs @@ -74,7 +74,11 @@ pub fn handler(context: Context, amount: u64) -> ); msg!( "Is destination mint {0}", - context.accounts.destination_token.to_account_info().is_writable + context + .accounts + .destination_token + .to_account_info() + .is_writable ); msg!( "Is source mint {0}", @@ -91,7 +95,10 @@ pub fn handler(context: Context, amount: u64) -> TransferChecked { from: context.accounts.sender_wsol_token_account.to_account_info(), mint: context.accounts.wsol_mint.to_account_info(), - to: context.accounts.delegate_wsol_token_account.to_account_info(), + to: context + .accounts + .delegate_wsol_token_account + .to_account_info(), authority: context.accounts.delegate.to_account_info(), }, ) diff --git a/tokens/token-extensions/transfer-hook/transfer-cost/anchor-v1/programs/transfer-hook/src/lib.rs b/tokens/token-extensions/transfer-hook/transfer-cost/anchor-v1/programs/transfer-hook/src/lib.rs index 7c17b8ecb..f7d87ba27 100644 --- a/tokens/token-extensions/transfer-hook/transfer-cost/anchor-v1/programs/transfer-hook/src/lib.rs +++ b/tokens/token-extensions/transfer-hook/transfer-cost/anchor-v1/programs/transfer-hook/src/lib.rs @@ -48,7 +48,10 @@ pub mod transfer_hook { } #[instruction(discriminator = ExecuteInstruction::SPL_DISCRIMINATOR_SLICE)] - pub fn transfer_hook(context: Context, amount: u64) -> Result<()> { + pub fn transfer_hook( + context: Context, + amount: u64, + ) -> Result<()> { instructions::transfer_hook::handler(context, amount) } } diff --git a/tokens/token-extensions/transfer-hook/transfer-cost/anchor-v1/programs/transfer-hook/tests/test_transfer_hook.rs b/tokens/token-extensions/transfer-hook/transfer-cost/anchor-v1/programs/transfer-hook/tests/test_transfer_hook.rs index 3912dd921..04128be8f 100644 --- a/tokens/token-extensions/transfer-hook/transfer-cost/anchor-v1/programs/transfer-hook/tests/test_transfer_hook.rs +++ b/tokens/token-extensions/transfer-hook/transfer-cost/anchor-v1/programs/transfer-hook/tests/test_transfer_hook.rs @@ -1,13 +1,10 @@ use { anchor_lang::{ - solana_program::{ - instruction::Instruction, - pubkey::Pubkey, - system_program, - }, + solana_program::{instruction::Instruction, pubkey::Pubkey, system_program}, InstructionData, ToAccountMetas, }, litesvm::LiteSVM, + solana_keypair::Keypair, solana_kite::{ create_wallet, send_transaction_from_instructions, token_extensions::{ @@ -15,7 +12,6 @@ use { }, transfer_hook::get_hook_accounts_address, }, - solana_keypair::Keypair, solana_signer::Signer, }; @@ -49,8 +45,7 @@ fn test_initialize_extra_account_meta_list() { svm.expire_blockhash(); // PDAs - let extra_account_meta_list = - get_hook_accounts_address(&mint, &program_id); + let extra_account_meta_list = get_hook_accounts_address(&mint, &program_id); let (counter_pda, _) = Pubkey::find_program_address(&[b"counter"], &program_id); // Step 2: Initialize ExtraAccountMetaList (also creates counter PDA) @@ -66,7 +61,8 @@ fn test_initialize_extra_account_meta_list() { } .to_account_metas(None), ); - send_transaction_from_instructions(&mut svm, vec![init_extra_ix], &[&payer], &payer.pubkey()).unwrap(); + send_transaction_from_instructions(&mut svm, vec![init_extra_ix], &[&payer], &payer.pubkey()) + .unwrap(); // Verify the ExtraAccountMetaList account was created let account = svm.get_account(&extra_account_meta_list); diff --git a/tokens/token-extensions/transfer-hook/transfer-switch/anchor-v1/programs/transfer-switch/src/instructions/configure_admin.rs b/tokens/token-extensions/transfer-hook/transfer-switch/anchor-v1/programs/transfer-switch/src/instructions/configure_admin.rs index b9fc5800e..35b7c82b7 100644 --- a/tokens/token-extensions/transfer-hook/transfer-switch/anchor-v1/programs/transfer-switch/src/instructions/configure_admin.rs +++ b/tokens/token-extensions/transfer-hook/transfer-switch/anchor-v1/programs/transfer-switch/src/instructions/configure_admin.rs @@ -23,27 +23,29 @@ pub struct ConfigureAdminAccountConstraints<'info> { } pub fn handle_is_admin(accounts: &mut ConfigureAdminAccountConstraints) -> Result<()> { - // check if we are not creating the account for the first time, - // ensure it's the admin that is making the change + // check if we are not creating the account for the first time, + // ensure it's the admin that is making the change + // + if accounts.admin_config.is_initialised { + // make sure it's the admin // - if accounts.admin_config.is_initialised { - // make sure it's the admin - // - require_keys_eq!(accounts.admin.key(), accounts.admin_config.admin,); + require_keys_eq!(accounts.admin.key(), accounts.admin_config.admin,); - // make sure the admin is not reentering their key - // - require_keys_neq!(accounts.admin.key(), accounts.new_admin.key()); - } - Ok(()) - } - -pub fn handle_configure_admin(accounts: &mut ConfigureAdminAccountConstraints, bump: u8) -> Result<()> { - accounts.admin_config.set_inner(AdminConfig { - admin: accounts.new_admin.key(), // set the admin pubkey that can switch transfers on/off - is_initialised: true, // let us know an admin has been set - bump, // canonical bump for the admin-config PDA - }); - Ok(()) + // make sure the admin is not reentering their key + // + require_keys_neq!(accounts.admin.key(), accounts.new_admin.key()); } + Ok(()) +} +pub fn handle_configure_admin( + accounts: &mut ConfigureAdminAccountConstraints, + bump: u8, +) -> Result<()> { + accounts.admin_config.set_inner(AdminConfig { + admin: accounts.new_admin.key(), // set the admin pubkey that can switch transfers on/off + is_initialised: true, // let us know an admin has been set + bump, // canonical bump for the admin-config PDA + }); + Ok(()) +} diff --git a/tokens/token-extensions/transfer-hook/transfer-switch/anchor-v1/programs/transfer-switch/src/instructions/initialise_extra_account_metas_list.rs b/tokens/token-extensions/transfer-hook/transfer-switch/anchor-v1/programs/transfer-switch/src/instructions/initialise_extra_account_metas_list.rs index e97028e60..3513ed785 100644 --- a/tokens/token-extensions/transfer-hook/transfer-switch/anchor-v1/programs/transfer-switch/src/instructions/initialise_extra_account_metas_list.rs +++ b/tokens/token-extensions/transfer-hook/transfer-switch/anchor-v1/programs/transfer-switch/src/instructions/initialise_extra_account_metas_list.rs @@ -29,54 +29,58 @@ pub struct InitializeExtraAccountMetasAccountConstraints<'info> { pub system_program: Program<'info, System>, } -pub fn handle_initialize_extra_account_metas_list(accounts: &mut InitializeExtraAccountMetasAccountConstraints, bumps: InitializeExtraAccountMetasAccountConstraintsBumps) -> Result<()> { - // .map_err() needed because spl-tlv-account-resolution uses solana-program-error 2.x - // while anchor-lang 1.0 uses 3.x - structurally identical but different semver types - let account_metas = vec![ - // 5 - wallet (sender) config account - ExtraAccountMeta::new_with_seeds( - &[ - Seed::AccountKey { index: 3 }, // sender index - ], - false, // is_signer - false, // is_writable - ).map_err(|_| ProgramError::InvalidArgument)?, - ]; +pub fn handle_initialize_extra_account_metas_list( + accounts: &mut InitializeExtraAccountMetasAccountConstraints, + bumps: InitializeExtraAccountMetasAccountConstraintsBumps, +) -> Result<()> { + // .map_err() needed because spl-tlv-account-resolution uses solana-program-error 2.x + // while anchor-lang 1.0 uses 3.x - structurally identical but different semver types + let account_metas = vec![ + // 5 - wallet (sender) config account + ExtraAccountMeta::new_with_seeds( + &[ + Seed::AccountKey { index: 3 }, // sender index + ], + false, // is_signer + false, // is_writable + ) + .map_err(|_| ProgramError::InvalidArgument)?, + ]; - // calculate account size - // unwrap is safe for known-good input (count of metas we just created) - let account_size = ExtraAccountMetaList::size_of(account_metas.len()).unwrap() as u64; + // calculate account size + // unwrap is safe for known-good input (count of metas we just created) + let account_size = ExtraAccountMetaList::size_of(account_metas.len()).unwrap() as u64; - // calculate minimum required lamports - let lamports = Rent::get()?.minimum_balance(account_size as usize); + // calculate minimum required lamports + let lamports = Rent::get()?.minimum_balance(account_size as usize); - let mint = accounts.token_mint.key(); - let signer_seeds: &[&[&[u8]]] = &[&[ - b"extra-account-metas", - mint.as_ref(), - &[bumps.extra_account_metas_list], - ]]; + let mint = accounts.token_mint.key(); + let signer_seeds: &[&[&[u8]]] = &[&[ + b"extra-account-metas", + mint.as_ref(), + &[bumps.extra_account_metas_list], + ]]; - create_account( - CpiContext::new( - accounts.system_program.key(), - CreateAccount { - from: accounts.payer.to_account_info(), - to: accounts.extra_account_metas_list.to_account_info(), - }, - ) - .with_signer(signer_seeds), - lamports, - account_size, - &crate::ID, - )?; + create_account( + CpiContext::new( + accounts.system_program.key(), + CreateAccount { + from: accounts.payer.to_account_info(), + to: accounts.extra_account_metas_list.to_account_info(), + }, + ) + .with_signer(signer_seeds), + lamports, + account_size, + &crate::ID, + )?; - // Initialize the account data to store the list of ExtraAccountMetas - ExtraAccountMetaList::init::( - &mut accounts.extra_account_metas_list.try_borrow_mut_data()?, - &account_metas, - ).map_err(|_| ProgramError::InvalidAccountData)?; - - Ok(()) - } + // Initialize the account data to store the list of ExtraAccountMetas + ExtraAccountMetaList::init::( + &mut accounts.extra_account_metas_list.try_borrow_mut_data()?, + &account_metas, + ) + .map_err(|_| ProgramError::InvalidAccountData)?; + Ok(()) +} diff --git a/tokens/token-extensions/transfer-hook/transfer-switch/anchor-v1/programs/transfer-switch/src/instructions/switch.rs b/tokens/token-extensions/transfer-hook/transfer-switch/anchor-v1/programs/transfer-switch/src/instructions/switch.rs index f33d67d3b..a9ba1e9d4 100644 --- a/tokens/token-extensions/transfer-hook/transfer-switch/anchor-v1/programs/transfer-switch/src/instructions/switch.rs +++ b/tokens/token-extensions/transfer-hook/transfer-switch/anchor-v1/programs/transfer-switch/src/instructions/switch.rs @@ -35,15 +35,15 @@ pub struct SwitchAccountConstraints<'info> { } pub fn handle_switch(accounts: &mut SwitchAccountConstraints, on: bool, bump: u8) -> Result<()> { - // toggle switch on/off for the given wallet - // - accounts.wallet_switch.set_inner(TransferSwitch { - wallet: accounts.wallet.key(), - on, - bump, // canonical bump for this wallet's PDA - }); - Ok(()) - } + // toggle switch on/off for the given wallet + // + accounts.wallet_switch.set_inner(TransferSwitch { + wallet: accounts.wallet.key(), + on, + bump, // canonical bump for this wallet's PDA + }); + Ok(()) +} // admin_config is validated via `seeds=[b"admin-config"], bump` - Anchor // re-derives it and fails if it doesn't match, so storing AdminConfig.bump @@ -51,4 +51,3 @@ pub fn handle_switch(accounts: &mut SwitchAccountConstraints, on: bool, bump: u8 // bump field on AdminConfig is still populated on creation to satisfy the // 'every PDA struct stores its bump' rule and save derivation cost in any // future call sites). - diff --git a/tokens/token-extensions/transfer-hook/transfer-switch/anchor-v1/programs/transfer-switch/src/instructions/transfer_hook.rs b/tokens/token-extensions/transfer-hook/transfer-switch/anchor-v1/programs/transfer-switch/src/instructions/transfer_hook.rs index c35671596..75434d2e1 100644 --- a/tokens/token-extensions/transfer-hook/transfer-switch/anchor-v1/programs/transfer-switch/src/instructions/transfer_hook.rs +++ b/tokens/token-extensions/transfer-hook/transfer-switch/anchor-v1/programs/transfer-switch/src/instructions/transfer_hook.rs @@ -47,26 +47,26 @@ pub struct TransferHookAccountConstraints<'info> { } pub fn handle_assert_switch_is_on(accounts: &mut TransferHookAccountConstraints) -> Result<()> { - if !accounts.wallet_switch.on { - return err!(TransferError::SwitchNotOn); - } - Ok(()) + if !accounts.wallet_switch.on { + return err!(TransferError::SwitchNotOn); } + Ok(()) +} pub fn handle_assert_is_transferring(accounts: &mut TransferHookAccountConstraints) -> Result<()> { - let source_token_info = accounts.source_token_account.to_account_info(); - let mut account_data_ref = source_token_info.try_borrow_mut_data()?; - // .map_err() needed because spl-token-2022 uses solana-program-error 2.x - // while anchor-lang 1.0 uses 3.x - structurally identical but different semver types - let mut account = PodStateWithExtensionsMut::::unpack(*account_data_ref) - .map_err(|_| ProgramError::InvalidAccountData)?; - let account_extension = account.get_extension_mut::() - .map_err(|_| ProgramError::InvalidAccountData)?; - - if !bool::from(account_extension.transferring) { - return err!(TransferError::IsNotCurrentlyTransferring); - } + let source_token_info = accounts.source_token_account.to_account_info(); + let mut account_data_ref = source_token_info.try_borrow_mut_data()?; + // .map_err() needed because spl-token-2022 uses solana-program-error 2.x + // while anchor-lang 1.0 uses 3.x - structurally identical but different semver types + let mut account = PodStateWithExtensionsMut::::unpack(*account_data_ref) + .map_err(|_| ProgramError::InvalidAccountData)?; + let account_extension = account + .get_extension_mut::() + .map_err(|_| ProgramError::InvalidAccountData)?; - Ok(()) + if !bool::from(account_extension.transferring) { + return err!(TransferError::IsNotCurrentlyTransferring); } + Ok(()) +} diff --git a/tokens/token-extensions/transfer-hook/transfer-switch/anchor-v1/programs/transfer-switch/src/lib.rs b/tokens/token-extensions/transfer-hook/transfer-switch/anchor-v1/programs/transfer-switch/src/lib.rs index c392c703c..c4d52f5a9 100644 --- a/tokens/token-extensions/transfer-hook/transfer-switch/anchor-v1/programs/transfer-switch/src/lib.rs +++ b/tokens/token-extensions/transfer-hook/transfer-switch/anchor-v1/programs/transfer-switch/src/lib.rs @@ -34,7 +34,10 @@ pub mod transfer_switch { } #[instruction(discriminator = ExecuteInstruction::SPL_DISCRIMINATOR_SLICE)] - pub fn transfer_hook(mut context: Context, _amount: u64) -> Result<()> { + pub fn transfer_hook( + mut context: Context, + _amount: u64, + ) -> Result<()> { handle_assert_is_transferring(&mut context.accounts)?; handle_assert_switch_is_on(&mut context.accounts) } diff --git a/tokens/token-extensions/transfer-hook/transfer-switch/anchor-v1/programs/transfer-switch/tests/test_transfer_switch.rs b/tokens/token-extensions/transfer-hook/transfer-switch/anchor-v1/programs/transfer-switch/tests/test_transfer_switch.rs index 5696596ed..3c3de0d08 100644 --- a/tokens/token-extensions/transfer-hook/transfer-switch/anchor-v1/programs/transfer-switch/tests/test_transfer_switch.rs +++ b/tokens/token-extensions/transfer-hook/transfer-switch/anchor-v1/programs/transfer-switch/tests/test_transfer_switch.rs @@ -1,13 +1,10 @@ use { anchor_lang::{ - solana_program::{ - instruction::Instruction, - pubkey::Pubkey, - system_program, - }, + solana_program::{instruction::Instruction, pubkey::Pubkey, system_program}, InstructionData, ToAccountMetas, }, litesvm::LiteSVM, + solana_keypair::Keypair, solana_kite::{ create_wallet, send_transaction_from_instructions, token_extensions::{ @@ -17,7 +14,6 @@ use { }, transfer_hook::{build_hook_accounts, get_hook_accounts_address, HookAccount}, }, - solana_keypair::Keypair, solana_signer::Signer, }; @@ -41,8 +37,7 @@ fn test_transfer_switch() { // Derive PDAs let (admin_config, _) = Pubkey::find_program_address(&[b"admin-config"], &program_id); - let (sender_switch, _) = - Pubkey::find_program_address(&[sender.pubkey().as_ref()], &program_id); + let (sender_switch, _) = Pubkey::find_program_address(&[sender.pubkey().as_ref()], &program_id); // Step 1: Create mint with TransferHook extension let mint = create_token_extensions_mint( @@ -57,34 +52,19 @@ fn test_transfer_switch() { .unwrap(); svm.expire_blockhash(); - let extra_account_meta_list = - get_hook_accounts_address(&mint, &program_id); + let extra_account_meta_list = get_hook_accounts_address(&mint, &program_id); // Step 2: Create token accounts and mint tokens let amount: u64 = 100 * 10u64.pow(decimals as u32); - let source_ata = create_token_extensions_account( - &mut svm, - &sender.pubkey(), - &mint, - &payer, - ).unwrap(); + let source_ata = + create_token_extensions_account(&mut svm, &sender.pubkey(), &mint, &payer).unwrap(); svm.expire_blockhash(); - let dest_ata = create_token_extensions_account( - &mut svm, - &recipient.pubkey(), - &mint, - &payer, - ).unwrap(); + let dest_ata = + create_token_extensions_account(&mut svm, &recipient.pubkey(), &mint, &payer).unwrap(); svm.expire_blockhash(); - mint_tokens_to_token_extensions_account( - &mut svm, - &mint, - &source_ata, - amount, - &payer, - ).unwrap(); + mint_tokens_to_token_extensions_account(&mut svm, &mint, &source_ata, amount, &payer).unwrap(); svm.expire_blockhash(); // Step 3: Configure admin @@ -99,7 +79,13 @@ fn test_transfer_switch() { } .to_account_metas(None), ); - send_transaction_from_instructions(&mut svm, vec![configure_admin_ix], &[&payer], &payer.pubkey()).unwrap(); + send_transaction_from_instructions( + &mut svm, + vec![configure_admin_ix], + &[&payer], + &payer.pubkey(), + ) + .unwrap(); svm.expire_blockhash(); // Step 4: Initialize extra account metas list @@ -114,7 +100,8 @@ fn test_transfer_switch() { } .to_account_metas(None), ); - send_transaction_from_instructions(&mut svm, vec![init_extra_ix], &[&payer], &payer.pubkey()).unwrap(); + send_transaction_from_instructions(&mut svm, vec![init_extra_ix], &[&payer], &payer.pubkey()) + .unwrap(); svm.expire_blockhash(); // Step 5: Turn transfers OFF for sender @@ -130,7 +117,8 @@ fn test_transfer_switch() { } .to_account_metas(None), ); - send_transaction_from_instructions(&mut svm, vec![switch_off_ix], &[&payer], &payer.pubkey()).unwrap(); + send_transaction_from_instructions(&mut svm, vec![switch_off_ix], &[&payer], &payer.pubkey()) + .unwrap(); svm.expire_blockhash(); // Step 6: Try transfer - should FAIL (switch is off) @@ -154,10 +142,7 @@ fn test_transfer_switch() { decimals, &extra_accounts, ); - assert!( - result.is_err(), - "Transfer should fail when switch is off" - ); + assert!(result.is_err(), "Transfer should fail when switch is off"); svm.expire_blockhash(); // Step 7: Turn transfers ON for sender @@ -173,7 +158,8 @@ fn test_transfer_switch() { } .to_account_metas(None), ); - send_transaction_from_instructions(&mut svm, vec![switch_on_ix], &[&payer], &payer.pubkey()).unwrap(); + send_transaction_from_instructions(&mut svm, vec![switch_on_ix], &[&payer], &payer.pubkey()) + .unwrap(); svm.expire_blockhash(); // Step 8: Transfer - should SUCCEED (switch is on) @@ -186,5 +172,6 @@ fn test_transfer_switch() { transfer_amount, decimals, &extra_accounts, - ).unwrap(); + ) + .unwrap(); } diff --git a/tokens/token-extensions/transfer-hook/whitelist/anchor-v1/programs/transfer-hook/src/instructions/add_to_whitelist.rs b/tokens/token-extensions/transfer-hook/whitelist/anchor-v1/programs/transfer-hook/src/instructions/add_to_whitelist.rs index 86e100ef5..40e4b72b1 100644 --- a/tokens/token-extensions/transfer-hook/whitelist/anchor-v1/programs/transfer-hook/src/instructions/add_to_whitelist.rs +++ b/tokens/token-extensions/transfer-hook/whitelist/anchor-v1/programs/transfer-hook/src/instructions/add_to_whitelist.rs @@ -22,7 +22,8 @@ pub fn handler(context: Context) -> Result<()> panic!("Only the authority can add to the white list!"); } - context.accounts + context + .accounts .white_list .white_list .push(context.accounts.new_account.key()); diff --git a/tokens/token-extensions/transfer-hook/whitelist/anchor-v1/programs/transfer-hook/src/instructions/initialize_extra_account_meta_list.rs b/tokens/token-extensions/transfer-hook/whitelist/anchor-v1/programs/transfer-hook/src/instructions/initialize_extra_account_meta_list.rs index a8c5f6def..ed20fbb39 100644 --- a/tokens/token-extensions/transfer-hook/whitelist/anchor-v1/programs/transfer-hook/src/instructions/initialize_extra_account_meta_list.rs +++ b/tokens/token-extensions/transfer-hook/whitelist/anchor-v1/programs/transfer-hook/src/instructions/initialize_extra_account_meta_list.rs @@ -28,7 +28,9 @@ pub struct InitializeExtraAccountMetaListAccountConstraints<'info> { pub white_list: Account<'info, WhiteList>, } -pub fn handler(mut context: Context) -> Result<()> { +pub fn handler( + mut context: Context, +) -> Result<()> { // set authority field on white_list account as payer address context.accounts.white_list.authority = context.accounts.payer.key(); context.accounts.white_list.bump = context.bumps.white_list; @@ -39,8 +41,12 @@ pub fn handler(mut context: Context( - &mut context.accounts.extra_account_meta_list.try_borrow_mut_data()?, + &mut context + .accounts + .extra_account_meta_list + .try_borrow_mut_data()?, &extra_account_metas, - ).map_err(|_| ProgramError::InvalidAccountData)?; + ) + .map_err(|_| ProgramError::InvalidAccountData)?; Ok(()) } diff --git a/tokens/token-extensions/transfer-hook/whitelist/anchor-v1/programs/transfer-hook/src/lib.rs b/tokens/token-extensions/transfer-hook/whitelist/anchor-v1/programs/transfer-hook/src/lib.rs index 08089435b..c3c652dc0 100644 --- a/tokens/token-extensions/transfer-hook/whitelist/anchor-v1/programs/transfer-hook/src/lib.rs +++ b/tokens/token-extensions/transfer-hook/whitelist/anchor-v1/programs/transfer-hook/src/lib.rs @@ -3,13 +3,12 @@ use std::cell::RefMut; use anchor_lang::prelude::*; use anchor_spl::token_2022::spl_token_2022::{ extension::{ - transfer_hook::TransferHookAccount, BaseStateWithExtensionsMut, - PodStateWithExtensionsMut, + transfer_hook::TransferHookAccount, BaseStateWithExtensionsMut, PodStateWithExtensionsMut, }, pod::PodAccount, }; -use spl_tlv_account_resolution::{account::ExtraAccountMeta, seeds::Seed}; use spl_discriminator::SplDiscriminate; +use spl_tlv_account_resolution::{account::ExtraAccountMeta, seeds::Seed}; use spl_transfer_hook_interface::instruction::{ ExecuteInstruction, InitializeExtraAccountMetaListInstruction, }; @@ -37,7 +36,10 @@ pub mod transfer_hook { } #[instruction(discriminator = ExecuteInstruction::SPL_DISCRIMINATOR_SLICE)] - pub fn transfer_hook(context: Context, amount: u64) -> Result<()> { + pub fn transfer_hook( + context: Context, + amount: u64, + ) -> Result<()> { instructions::transfer_hook::handler(context, amount) } @@ -53,7 +55,8 @@ pub fn check_is_transferring(context: &Context) // while anchor-lang 1.0 uses 3.x - structurally identical but different semver types let mut account = PodStateWithExtensionsMut::::unpack(*account_data_ref) .map_err(|_| ProgramError::InvalidAccountData)?; - let account_extension = account.get_extension_mut::() + let account_extension = account + .get_extension_mut::() .map_err(|_| ProgramError::InvalidAccountData)?; if !bool::from(account_extension.transferring) { @@ -73,7 +76,8 @@ pub fn handle_extra_account_metas() -> Result> { }], false, // is_signer true, // is_writable - ).map_err(|_| ProgramError::InvalidArgument)?]) + ) + .map_err(|_| ProgramError::InvalidArgument)?]) } /// Returns the count of extra account metas (avoids the error conversion issue in #[account] attributes) diff --git a/tokens/token-extensions/transfer-hook/whitelist/anchor-v1/programs/transfer-hook/tests/test_transfer_hook.rs b/tokens/token-extensions/transfer-hook/whitelist/anchor-v1/programs/transfer-hook/tests/test_transfer_hook.rs index 8911293e8..14ddbfdb8 100644 --- a/tokens/token-extensions/transfer-hook/whitelist/anchor-v1/programs/transfer-hook/tests/test_transfer_hook.rs +++ b/tokens/token-extensions/transfer-hook/whitelist/anchor-v1/programs/transfer-hook/tests/test_transfer_hook.rs @@ -1,13 +1,10 @@ use { anchor_lang::{ - solana_program::{ - instruction::Instruction, - pubkey::Pubkey, - system_program, - }, + solana_program::{instruction::Instruction, pubkey::Pubkey, system_program}, InstructionData, ToAccountMetas, }, litesvm::LiteSVM, + solana_keypair::Keypair, solana_kite::{ create_wallet, send_transaction_from_instructions, token_extensions::{ @@ -17,7 +14,6 @@ use { }, transfer_hook::{build_hook_accounts, get_hook_accounts_address, HookAccount}, }, - solana_keypair::Keypair, solana_signer::Signer, }; @@ -54,34 +50,19 @@ fn test_whitelist_transfer_hook() { .unwrap(); svm.expire_blockhash(); - let extra_account_meta_list = - get_hook_accounts_address(&mint, &program_id); + let extra_account_meta_list = get_hook_accounts_address(&mint, &program_id); // Step 2: Create token accounts and mint tokens let amount: u64 = 100 * 10u64.pow(decimals as u32); - let source_ata = create_token_extensions_account( - &mut svm, - &payer.pubkey(), - &mint, - &payer, - ).unwrap(); + let source_ata = + create_token_extensions_account(&mut svm, &payer.pubkey(), &mint, &payer).unwrap(); svm.expire_blockhash(); - let dest_ata = create_token_extensions_account( - &mut svm, - &recipient.pubkey(), - &mint, - &payer, - ).unwrap(); + let dest_ata = + create_token_extensions_account(&mut svm, &recipient.pubkey(), &mint, &payer).unwrap(); svm.expire_blockhash(); - mint_tokens_to_token_extensions_account( - &mut svm, - &mint, - &source_ata, - amount, - &payer, - ).unwrap(); + mint_tokens_to_token_extensions_account(&mut svm, &mint, &source_ata, amount, &payer).unwrap(); svm.expire_blockhash(); // Step 3: Initialize ExtraAccountMetaList (also creates whitelist) @@ -97,7 +78,8 @@ fn test_whitelist_transfer_hook() { } .to_account_metas(None), ); - send_transaction_from_instructions(&mut svm, vec![init_extra_ix], &[&payer], &payer.pubkey()).unwrap(); + send_transaction_from_instructions(&mut svm, vec![init_extra_ix], &[&payer], &payer.pubkey()) + .unwrap(); svm.expire_blockhash(); // Step 4: Add destination token account to whitelist @@ -111,7 +93,13 @@ fn test_whitelist_transfer_hook() { } .to_account_metas(None), ); - send_transaction_from_instructions(&mut svm, vec![add_to_whitelist_ix], &[&payer], &payer.pubkey()).unwrap(); + send_transaction_from_instructions( + &mut svm, + vec![add_to_whitelist_ix], + &[&payer], + &payer.pubkey(), + ) + .unwrap(); svm.expire_blockhash(); // Step 5: Transfer - should succeed (destination is whitelisted) @@ -134,5 +122,6 @@ fn test_whitelist_transfer_hook() { transfer_amount, decimals, &extra_accounts, - ).unwrap(); + ) + .unwrap(); } diff --git a/tokens/token-minter/anchor-v1/programs/token-minter/src/instructions/mint.rs b/tokens/token-minter/anchor-v1/programs/token-minter/src/instructions/mint.rs index 7d731da01..540b87f42 100644 --- a/tokens/token-minter/anchor-v1/programs/token-minter/src/instructions/mint.rs +++ b/tokens/token-minter/anchor-v1/programs/token-minter/src/instructions/mint.rs @@ -34,10 +34,7 @@ pub struct MintTokenAccountConstraints<'info> { /// `amount` is in minor units (the raw integer the token program operates /// on). Clients convert from major units, e.g. 1 token with 9 decimals is /// `1 * 10u64.pow(9)` minor units. -pub fn handle_mint_token( - context: Context, - amount: u64, -) -> Result<()> { +pub fn handle_mint_token(context: Context, amount: u64) -> Result<()> { msg!("Minting tokens to associated token account..."); msg!("Mint: {}", &context.accounts.mint_account.key()); msg!( diff --git a/tokens/token-minter/anchor-v1/programs/token-minter/src/lib.rs b/tokens/token-minter/anchor-v1/programs/token-minter/src/lib.rs index 8033bddbb..a10cfc24f 100644 --- a/tokens/token-minter/anchor-v1/programs/token-minter/src/lib.rs +++ b/tokens/token-minter/anchor-v1/programs/token-minter/src/lib.rs @@ -19,10 +19,7 @@ pub mod token_minter { } /// Mint `amount` minor units of the token to the recipient. - pub fn mint_token( - context: Context, - amount: u64, - ) -> Result<()> { + pub fn mint_token(context: Context, amount: u64) -> Result<()> { mint::handle_mint_token(context, amount) } } diff --git a/tokens/token-minter/anchor-v1/programs/token-minter/tests/test_token_minter.rs b/tokens/token-minter/anchor-v1/programs/token-minter/tests/test_token_minter.rs index 487a185f3..4d213c9fb 100644 --- a/tokens/token-minter/anchor-v1/programs/token-minter/tests/test_token_minter.rs +++ b/tokens/token-minter/anchor-v1/programs/token-minter/tests/test_token_minter.rs @@ -5,9 +5,7 @@ use { }, litesvm::LiteSVM, solana_keypair::Keypair, - solana_kite::{ - create_wallet, get_token_account_balance, send_transaction_from_instructions, - }, + solana_kite::{create_wallet, get_token_account_balance, send_transaction_from_instructions}, solana_signer::Signer, }; @@ -56,11 +54,7 @@ fn derive_metadata_pda(mint: &Pubkey) -> Pubkey { fn derive_ata(wallet: &Pubkey, mint: &Pubkey) -> Pubkey { let (ata, _bump) = Pubkey::find_program_address( - &[ - wallet.as_ref(), - token_program_id().as_ref(), - mint.as_ref(), - ], + &[wallet.as_ref(), token_program_id().as_ref(), mint.as_ref()], &associated_token_program_id(), ); ata @@ -182,13 +176,8 @@ fn test_create_and_mint_tokens() { } .to_account_metas(None), ); - send_transaction_from_instructions( - &mut svm, - vec![mint_ix], - &[&payer], - &payer.pubkey(), - ) - .unwrap(); + send_transaction_from_instructions(&mut svm, vec![mint_ix], &[&payer], &payer.pubkey()) + .unwrap(); // Verify 100 tokens minted (in minor units) let balance = get_token_account_balance(&svm, &ata).unwrap(); diff --git a/tokens/transfer-tokens/anchor-v1/programs/transfer-tokens/src/instructions/mint.rs b/tokens/transfer-tokens/anchor-v1/programs/transfer-tokens/src/instructions/mint.rs index f57df043a..dedadfef3 100644 --- a/tokens/transfer-tokens/anchor-v1/programs/transfer-tokens/src/instructions/mint.rs +++ b/tokens/transfer-tokens/anchor-v1/programs/transfer-tokens/src/instructions/mint.rs @@ -35,10 +35,7 @@ pub struct MintTokenAccountConstraints<'info> { /// `amount` is in minor units (the raw integer the token program operates /// on). Clients convert from major units, e.g. 1 token with 9 decimals is /// `1 * 10u64.pow(9)` minor units. -pub fn handle_mint_token( - context: Context, - amount: u64, -) -> Result<()> { +pub fn handle_mint_token(context: Context, amount: u64) -> Result<()> { msg!("Minting tokens to associated token account..."); msg!("Mint: {}", &context.accounts.mint_account.key()); msg!( diff --git a/tokens/transfer-tokens/anchor-v1/programs/transfer-tokens/src/lib.rs b/tokens/transfer-tokens/anchor-v1/programs/transfer-tokens/src/lib.rs index 3d008421e..0a54c7663 100644 --- a/tokens/transfer-tokens/anchor-v1/programs/transfer-tokens/src/lib.rs +++ b/tokens/transfer-tokens/anchor-v1/programs/transfer-tokens/src/lib.rs @@ -20,10 +20,7 @@ pub mod transfer_tokens { } /// Mint `amount` minor units of the token to the recipient. - pub fn mint_token( - context: Context, - amount: u64, - ) -> Result<()> { + pub fn mint_token(context: Context, amount: u64) -> Result<()> { mint::handle_mint_token(context, amount) } diff --git a/tokens/transfer-tokens/anchor-v1/programs/transfer-tokens/tests/test_transfer_tokens.rs b/tokens/transfer-tokens/anchor-v1/programs/transfer-tokens/tests/test_transfer_tokens.rs index bf0052e93..34479b943 100644 --- a/tokens/transfer-tokens/anchor-v1/programs/transfer-tokens/tests/test_transfer_tokens.rs +++ b/tokens/transfer-tokens/anchor-v1/programs/transfer-tokens/tests/test_transfer_tokens.rs @@ -54,11 +54,7 @@ fn derive_metadata_pda(mint: &Pubkey) -> Pubkey { fn derive_ata(wallet: &Pubkey, mint: &Pubkey) -> Pubkey { let (ata, _bump) = Pubkey::find_program_address( - &[ - wallet.as_ref(), - token_program_id().as_ref(), - mint.as_ref(), - ], + &[wallet.as_ref(), token_program_id().as_ref(), mint.as_ref()], &associated_token_program_id(), ); ata @@ -140,13 +136,8 @@ fn test_create_mint_and_transfer() { } .to_account_metas(None), ); - send_transaction_from_instructions( - &mut svm, - vec![mint_ix], - &[&payer], - &payer.pubkey(), - ) - .unwrap(); + send_transaction_from_instructions(&mut svm, vec![mint_ix], &[&payer], &payer.pubkey()) + .unwrap(); // Verify 100 tokens minted (in minor units) assert_eq!( @@ -177,13 +168,8 @@ fn test_create_mint_and_transfer() { } .to_account_metas(None), ); - send_transaction_from_instructions( - &mut svm, - vec![transfer_ix], - &[&payer], - &payer.pubkey(), - ) - .unwrap(); + send_transaction_from_instructions(&mut svm, vec![transfer_ix], &[&payer], &payer.pubkey()) + .unwrap(); // Verify: sender 50 tokens, recipient 50 tokens (in minor units) assert_eq!(