diff --git a/finance/betting-market/anchor/README.md b/finance/betting-market/anchor/README.md index 63202fbb4..127b39f06 100644 --- a/finance/betting-market/anchor/README.md +++ b/finance/betting-market/anchor/README.md @@ -75,7 +75,7 @@ division floors each share, leaving at most a few minor units of dust in the vau - `initialize_config` - anyone (the signer becomes admin). One-time setup: sets admin, stake token, fee, fee recipient. -- `create_event` - admin. Opens a market and creates its vault. +- `initialize_event` - admin. Opens a market and creates its vault. - `add_outcome` - admin. Adds a possible result. Only before any bet is placed. - `place_bet` - bettor. Stakes tokens on one outcome; updates the pools and adds the Bet to the user's index (rejected with `TooManyBets` if all `MAX_BETS_PER_USER` slots hold open positions). @@ -121,7 +121,7 @@ anchor test ### How does a prediction market work on Solana? -This example uses the parimutuel (pooled) model: an admin opens an event with `create_event` and `add_outcome`, and bettors stake tokens on an outcome with `place_bet`. Every stake goes into one pool; after `settle_event` names the winning outcome, winners call `claim_winnings` to split the losing stakes, minus a protocol fee, in proportion to their own stake. +This example uses the parimutuel (pooled) model: an admin opens an event with `initialize_event` and `add_outcome`, and bettors stake tokens on an outcome with `place_bet`. Every stake goes into one pool; after `settle_event` names the winning outcome, winners call `claim_winnings` to split the losing stakes, minus a protocol fee, in proportion to their own stake. ### How are the odds set? diff --git a/finance/betting-market/anchor/programs/betting-market/src/instructions/create_event.rs b/finance/betting-market/anchor/programs/betting-market/src/instructions/initialize_event.rs similarity index 93% rename from finance/betting-market/anchor/programs/betting-market/src/instructions/create_event.rs rename to finance/betting-market/anchor/programs/betting-market/src/instructions/initialize_event.rs index 1ea59b71c..1e90e885a 100644 --- a/finance/betting-market/anchor/programs/betting-market/src/instructions/create_event.rs +++ b/finance/betting-market/anchor/programs/betting-market/src/instructions/initialize_event.rs @@ -10,7 +10,7 @@ pub const MAX_DESCRIPTION_LEN: usize = 200; #[derive(Accounts)] #[instruction(event_id: u64)] -pub struct CreateEventAccountConstraints<'info> { +pub struct InitializeEventAccountConstraints<'info> { #[account(mut)] pub admin: Signer<'info>, @@ -50,8 +50,8 @@ pub struct CreateEventAccountConstraints<'info> { pub system_program: Program<'info, System>, } -pub fn handle_create_event( - context: Context, +pub fn handle_initialize_event( + context: Context, event_id: u64, description: String, ) -> Result<()> { diff --git a/finance/betting-market/anchor/programs/betting-market/src/instructions/mod.rs b/finance/betting-market/anchor/programs/betting-market/src/instructions/mod.rs index 47ba46009..29a4a92a8 100644 --- a/finance/betting-market/anchor/programs/betting-market/src/instructions/mod.rs +++ b/finance/betting-market/anchor/programs/betting-market/src/instructions/mod.rs @@ -3,7 +3,7 @@ pub mod cancel_event; pub mod claim_refund; pub mod claim_winnings; pub mod close_losing_bet; -pub mod create_event; +pub mod initialize_event; pub mod initialize_config; pub mod place_bet; pub mod settle_event; @@ -14,7 +14,7 @@ pub use cancel_event::*; pub use claim_refund::*; pub use claim_winnings::*; pub use close_losing_bet::*; -pub use create_event::*; +pub use initialize_event::*; pub use initialize_config::*; pub use place_bet::*; pub use settle_event::*; diff --git a/finance/betting-market/anchor/programs/betting-market/src/lib.rs b/finance/betting-market/anchor/programs/betting-market/src/lib.rs index c38cdaaf2..731546e4c 100644 --- a/finance/betting-market/anchor/programs/betting-market/src/lib.rs +++ b/finance/betting-market/anchor/programs/betting-market/src/lib.rs @@ -24,12 +24,12 @@ pub mod betting_market { } // Admin opens a new market and creates its pool vault. - pub fn create_event( - context: Context, + pub fn initialize_event( + context: Context, event_id: u64, description: String, ) -> Result<()> { - instructions::create_event::handle_create_event(context, event_id, description) + instructions::initialize_event::handle_initialize_event(context, event_id, description) } // Admin adds a possible result. Only allowed before betting starts. diff --git a/finance/betting-market/anchor/programs/betting-market/tests/test_betting_market.rs b/finance/betting-market/anchor/programs/betting-market/tests/test_betting_market.rs index e47d0644e..8390c93f0 100644 --- a/finance/betting-market/anchor/programs/betting-market/tests/test_betting_market.rs +++ b/finance/betting-market/anchor/programs/betting-market/tests/test_betting_market.rs @@ -122,16 +122,16 @@ fn initialize_config_ix(admin: Pubkey, mint: Pubkey, fee_recipient: Pubkey) -> I ) } -fn create_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 { let event = event_pda(event_id); Instruction::new_with_bytes( betting_market::id(), - &betting_market::instruction::CreateEvent { + &betting_market::instruction::InitializeEvent { event_id, description: description.to_string(), } .data(), - betting_market::accounts::CreateEventAccountConstraints { + betting_market::accounts::InitializeEventAccountConstraints { admin, config: config_pda(), token_mint: mint, @@ -348,7 +348,7 @@ fn test_full_lifecycle() { send_transaction_from_instructions( &mut market.svm, vec![ - create_event_ix(admin, mint, event_id, "Will it rain tomorrow?"), + initialize_event_ix(admin, mint, event_id, "Will it rain tomorrow?"), add_outcome_ix(admin, event_id, 0, "Yes"), add_outcome_ix(admin, event_id, 1, "No"), ], @@ -456,7 +456,7 @@ fn test_full_lifecycle() { } #[test] -fn test_only_admin_can_create_event() { +fn test_only_admin_can_initialize_event() { let mut market = setup(); init_config(&mut market); @@ -464,7 +464,7 @@ fn test_only_admin_can_create_event() { let mallory = create_wallet(&mut market.svm, 10_000_000_000).unwrap(); let result = send_transaction_from_instructions( &mut market.svm, - vec![create_event_ix(mallory.pubkey(), mint, 7, "Unauthorized event")], + vec![initialize_event_ix(mallory.pubkey(), mint, 7, "Unauthorized event")], &[&mallory], &mallory.pubkey(), ); @@ -486,7 +486,7 @@ fn test_cannot_bet_after_settle() { send_transaction_from_instructions( &mut market.svm, vec![ - create_event_ix(admin, mint, event_id, "Coin flip"), + initialize_event_ix(admin, mint, event_id, "Coin flip"), add_outcome_ix(admin, event_id, 0, "Heads"), add_outcome_ix(admin, event_id, 1, "Tails"), ], @@ -533,7 +533,7 @@ fn test_double_claim_fails() { send_transaction_from_instructions( &mut market.svm, vec![ - create_event_ix(admin, mint, event_id, "Match winner"), + initialize_event_ix(admin, mint, event_id, "Match winner"), add_outcome_ix(admin, event_id, 0, "Home"), add_outcome_ix(admin, event_id, 1, "Away"), ], @@ -595,7 +595,7 @@ fn test_settle_outcome_without_bets_fails() { send_transaction_from_instructions( &mut market.svm, vec![ - create_event_ix(admin, mint, event_id, "Two horse race"), + initialize_event_ix(admin, mint, event_id, "Two horse race"), add_outcome_ix(admin, event_id, 0, "Horse A"), add_outcome_ix(admin, event_id, 1, "Horse B"), ], @@ -634,7 +634,7 @@ fn test_cancel_and_refund() { send_transaction_from_instructions( &mut market.svm, vec![ - create_event_ix(admin, mint, event_id, "Voided event"), + initialize_event_ix(admin, mint, event_id, "Voided event"), add_outcome_ix(admin, event_id, 0, "A"), add_outcome_ix(admin, event_id, 1, "B"), ], @@ -709,7 +709,7 @@ fn test_close_losing_bet_only_after_settle_and_only_for_losers() { send_transaction_from_instructions( &mut market.svm, vec![ - create_event_ix(admin, mint, event_id, "Derby winner"), + initialize_event_ix(admin, mint, event_id, "Derby winner"), add_outcome_ix(admin, event_id, 0, "Red"), add_outcome_ix(admin, event_id, 1, "Blue"), ], @@ -793,7 +793,7 @@ fn test_closing_a_bet_frees_a_slot_for_a_new_bet() { send_transaction_from_instructions( &mut market.svm, - vec![create_event_ix(admin, mint, full_event_id, "Wide field")], + vec![initialize_event_ix(admin, mint, full_event_id, "Wide field")], &[&market.admin], &admin, ) @@ -810,7 +810,7 @@ fn test_closing_a_bet_frees_a_slot_for_a_new_bet() { send_transaction_from_instructions( &mut market.svm, vec![ - create_event_ix(admin, mint, second_event_id, "Second market"), + initialize_event_ix(admin, mint, second_event_id, "Second market"), add_outcome_ix(admin, second_event_id, 0, "Yes"), add_outcome_ix(admin, second_event_id, 1, "No"), ], diff --git a/finance/betting-market/quasar/README.md b/finance/betting-market/quasar/README.md index 0cb993b60..7e82be0b2 100644 --- a/finance/betting-market/quasar/README.md +++ b/finance/betting-market/quasar/README.md @@ -19,7 +19,7 @@ the other side of your bet. Everyone's stake goes into one pool, and when the result is known the winners divide the pool. - The **admin** (whoever ran `initialize_config`) opens an event with - `create_event`, then lists each possible result with `add_outcome`. Outcomes + `initialize_event`, then lists each possible result with `add_outcome`. Outcomes can only be added before the first bet, so the field of choices can't change under bettors who have already staked. - A **bettor** stakes the market's token on one outcome with `place_bet`. The diff --git a/finance/betting-market/quasar/src/instructions/create_event.rs b/finance/betting-market/quasar/src/instructions/initialize_event.rs similarity index 92% rename from finance/betting-market/quasar/src/instructions/create_event.rs rename to finance/betting-market/quasar/src/instructions/initialize_event.rs index fd5dc8ee4..6c2d3d791 100644 --- a/finance/betting-market/quasar/src/instructions/create_event.rs +++ b/finance/betting-market/quasar/src/instructions/initialize_event.rs @@ -8,7 +8,7 @@ use crate::state::{ #[derive(Accounts)] #[instruction(event_id: u64)] -pub struct CreateEventAccountConstraints { +pub struct InitializeEventAccountConstraints { #[account(mut)] pub admin: Signer, @@ -41,11 +41,11 @@ pub struct CreateEventAccountConstraints { } #[inline(always)] -pub fn handle_create_event( - accounts: &mut CreateEventAccountConstraints, +pub fn handle_initialize_event( + accounts: &mut InitializeEventAccountConstraints, event_id: u64, description: &str, - bumps: &CreateEventAccountConstraintsBumps, + bumps: &InitializeEventAccountConstraintsBumps, ) -> Result<(), ProgramError> { let description_bytes = description.as_bytes(); require!( diff --git a/finance/betting-market/quasar/src/instructions/mod.rs b/finance/betting-market/quasar/src/instructions/mod.rs index 47ba46009..29a4a92a8 100644 --- a/finance/betting-market/quasar/src/instructions/mod.rs +++ b/finance/betting-market/quasar/src/instructions/mod.rs @@ -3,7 +3,7 @@ pub mod cancel_event; pub mod claim_refund; pub mod claim_winnings; pub mod close_losing_bet; -pub mod create_event; +pub mod initialize_event; pub mod initialize_config; pub mod place_bet; pub mod settle_event; @@ -14,7 +14,7 @@ pub use cancel_event::*; pub use claim_refund::*; pub use claim_winnings::*; pub use close_losing_bet::*; -pub use create_event::*; +pub use initialize_event::*; pub use initialize_config::*; pub use place_bet::*; pub use settle_event::*; diff --git a/finance/betting-market/quasar/src/lib.rs b/finance/betting-market/quasar/src/lib.rs index e1fa486da..ca5187921 100644 --- a/finance/betting-market/quasar/src/lib.rs +++ b/finance/betting-market/quasar/src/lib.rs @@ -40,12 +40,12 @@ mod quasar_betting_market { /// Admin opens a new market and creates its pool vault. #[instruction(discriminator = 1)] - pub fn create_event( - ctx: Ctx, + pub fn initialize_event( + ctx: Ctx, event_id: u64, description: String<200>, ) -> Result<(), ProgramError> { - instructions::create_event::handle_create_event( + instructions::initialize_event::handle_initialize_event( &mut ctx.accounts, event_id, description, diff --git a/finance/betting-market/quasar/src/tests.rs b/finance/betting-market/quasar/src/tests.rs index 63af50b14..a706b499a 100644 --- a/finance/betting-market/quasar/src/tests.rs +++ b/finance/betting-market/quasar/src/tests.rs @@ -6,7 +6,7 @@ use { crate::{ cpi::{ AddOutcomeInstruction, CancelEventInstruction, ClaimRefundInstruction, - ClaimWinningsInstruction, CloseLosingBetInstruction, CreateEventInstruction, + ClaimWinningsInstruction, CloseLosingBetInstruction, InitializeEventInstruction, InitializeConfigInstruction, PlaceBetInstruction, SettleEventInstruction, }, state::{Bet, Config, Event, EventStatus, EventVaultPda, Outcome, User}, @@ -94,7 +94,7 @@ fn full_lifecycle_settles_and_pays_the_winner(test: &mut Test) { const FEE: u64 = 1; // floor(100 * 100 / 10000) = 1 const PAYOUT_B: u64 = STAKE_B + 99; // stake + winnings(99) - test.send(CreateEventInstruction { + test.send(InitializeEventInstruction { admin: ADMIN, token_mint: TOKEN_MINT, event_id: EVENT_ID, @@ -198,7 +198,7 @@ fn cancelled_event_refunds_the_exact_stake(test: &mut Test) { const STAKE: u64 = 250; - test.send(CreateEventInstruction { + test.send(InitializeEventInstruction { admin: ADMIN, token_mint: TOKEN_MINT, event_id: EVENT_ID, @@ -247,11 +247,11 @@ fn cancelled_event_refunds_the_exact_stake(test: &mut Test) { /// Only the config admin may open an event. #[quasar_test] -fn create_event_rejects_a_non_admin_signer(test: &mut Test) { +fn initialize_event_rejects_a_non_admin_signer(test: &mut Test) { base_world(test); test.add(Wallet::new().at(ATTACKER)); - test.send(CreateEventInstruction { + test.send(InitializeEventInstruction { admin: ATTACKER, token_mint: TOKEN_MINT, event_id: EVENT_ID, diff --git a/finance/lending/anchor/README.md b/finance/lending/anchor/README.md index b499d81ef..8b46c6c38 100644 --- a/finance/lending/anchor/README.md +++ b/finance/lending/anchor/README.md @@ -145,10 +145,10 @@ deposits or a borrower's collateral: there is no admin escape hatch over user fu ### Instruction handlers -Admin: `init_lending_market`, `init_reserve`, `update_reserve_config`, `set_price`, +Admin: `initialize_lending_market`, `initialize_reserve`, `update_reserve_config`, `set_price`, `collect_protocol_fees`. Supply side: `refresh_reserve`, `deposit_reserve_liquidity`, -`redeem_reserve_collateral`. Borrow side: `init_obligation`, `refresh_obligation`, +`redeem_reserve_collateral`. Borrow side: `initialize_obligation`, `refresh_obligation`, `deposit_obligation_collateral`, `withdraw_obligation_collateral`, `borrow_obligation_liquidity`, `repay_obligation_liquidity`, `liquidate_obligation`. diff --git a/finance/lending/anchor/programs/lending/src/instructions/admin/init_lending_market.rs b/finance/lending/anchor/programs/lending/src/instructions/admin/initialize_lending_market.rs similarity index 89% rename from finance/lending/anchor/programs/lending/src/instructions/admin/init_lending_market.rs rename to finance/lending/anchor/programs/lending/src/instructions/admin/initialize_lending_market.rs index 377b7fbc6..2e6d478cc 100644 --- a/finance/lending/anchor/programs/lending/src/instructions/admin/init_lending_market.rs +++ b/finance/lending/anchor/programs/lending/src/instructions/admin/initialize_lending_market.rs @@ -4,8 +4,8 @@ use anchor_spl::token_interface::Mint; use crate::constants::LENDING_MARKET_SEED; use crate::state::LendingMarket; -pub fn handle_init_lending_market( - context: Context, +pub fn handle_initialize_lending_market( + context: Context, market_id: u64, ) -> Result<()> { let market = &mut context.accounts.lending_market; @@ -18,7 +18,7 @@ pub fn handle_init_lending_market( #[derive(Accounts)] #[instruction(market_id: u64)] -pub struct InitLendingMarket<'info> { +pub struct InitializeLendingMarket<'info> { // Seeded by `market_id` alone — the market is not identified by any // individual's address. `owner` is stored as a field and used only for // authorization (`has_one = owner`) on admin instructions. diff --git a/finance/lending/anchor/programs/lending/src/instructions/admin/init_reserve.rs b/finance/lending/anchor/programs/lending/src/instructions/admin/initialize_reserve.rs similarity index 94% rename from finance/lending/anchor/programs/lending/src/instructions/admin/init_reserve.rs rename to finance/lending/anchor/programs/lending/src/instructions/admin/initialize_reserve.rs index 0a975f9a3..0ebd91f67 100644 --- a/finance/lending/anchor/programs/lending/src/instructions/admin/init_reserve.rs +++ b/finance/lending/anchor/programs/lending/src/instructions/admin/initialize_reserve.rs @@ -6,7 +6,7 @@ use crate::constants::{ }; use crate::state::{LendingMarket, PriceFeed, Reserve, ReserveConfig}; -pub fn handle_init_reserve(context: Context, config: ReserveConfig) -> Result<()> { +pub fn handle_initialize_reserve(context: Context, config: ReserveConfig) -> Result<()> { config.validate()?; let reserve = &mut context.accounts.reserve; @@ -28,7 +28,7 @@ pub fn handle_init_reserve(context: Context, config: ReserveConfig) } #[derive(Accounts)] -pub struct InitReserve<'info> { +pub struct InitializeReserve<'info> { // The reserve PDA below is seeded by this market's address, so the market is // pinned by that seed; we only need to prove the signer owns it. #[account(has_one = owner)] diff --git a/finance/lending/anchor/programs/lending/src/instructions/admin/mod.rs b/finance/lending/anchor/programs/lending/src/instructions/admin/mod.rs index ee52c93c2..2aa254adc 100644 --- a/finance/lending/anchor/programs/lending/src/instructions/admin/mod.rs +++ b/finance/lending/anchor/programs/lending/src/instructions/admin/mod.rs @@ -1,11 +1,11 @@ pub mod collect_protocol_fees; -pub mod init_lending_market; -pub mod init_reserve; +pub mod initialize_lending_market; +pub mod initialize_reserve; pub mod set_price; pub mod update_reserve_config; pub use collect_protocol_fees::*; -pub use init_lending_market::*; -pub use init_reserve::*; +pub use initialize_lending_market::*; +pub use initialize_reserve::*; pub use set_price::*; pub use update_reserve_config::*; diff --git a/finance/lending/anchor/programs/lending/src/instructions/init_obligation.rs b/finance/lending/anchor/programs/lending/src/instructions/initialize_obligation.rs similarity index 90% rename from finance/lending/anchor/programs/lending/src/instructions/init_obligation.rs rename to finance/lending/anchor/programs/lending/src/instructions/initialize_obligation.rs index 07b5d5233..c7a761354 100644 --- a/finance/lending/anchor/programs/lending/src/instructions/init_obligation.rs +++ b/finance/lending/anchor/programs/lending/src/instructions/initialize_obligation.rs @@ -3,7 +3,7 @@ use anchor_lang::prelude::*; use crate::constants::OBLIGATION_SEED; use crate::state::{LendingMarket, Obligation}; -pub fn handle_init_obligation(context: Context) -> Result<()> { +pub fn handle_initialize_obligation(context: Context) -> Result<()> { let obligation = &mut context.accounts.obligation; obligation.lending_market = context.accounts.lending_market.key(); obligation.owner = context.accounts.owner.key(); @@ -21,7 +21,7 @@ pub fn handle_init_obligation(context: Context) -> Result<()> { } #[derive(Accounts)] -pub struct InitObligation<'info> { +pub struct InitializeObligation<'info> { pub lending_market: Account<'info, LendingMarket>, #[account( diff --git a/finance/lending/anchor/programs/lending/src/instructions/mod.rs b/finance/lending/anchor/programs/lending/src/instructions/mod.rs index a19052008..a12366989 100644 --- a/finance/lending/anchor/programs/lending/src/instructions/mod.rs +++ b/finance/lending/anchor/programs/lending/src/instructions/mod.rs @@ -2,7 +2,7 @@ pub mod admin; pub mod borrow_obligation_liquidity; pub mod deposit_obligation_collateral; pub mod deposit_reserve_liquidity; -pub mod init_obligation; +pub mod initialize_obligation; pub mod liquidate_obligation; pub mod redeem_reserve_collateral; pub mod refresh_obligation; @@ -14,7 +14,7 @@ pub use admin::*; pub use borrow_obligation_liquidity::*; pub use deposit_obligation_collateral::*; pub use deposit_reserve_liquidity::*; -pub use init_obligation::*; +pub use initialize_obligation::*; pub use liquidate_obligation::*; pub use redeem_reserve_collateral::*; pub use refresh_obligation::*; diff --git a/finance/lending/anchor/programs/lending/src/lib.rs b/finance/lending/anchor/programs/lending/src/lib.rs index ca848d0b9..462b3be7f 100644 --- a/finance/lending/anchor/programs/lending/src/lib.rs +++ b/finance/lending/anchor/programs/lending/src/lib.rs @@ -15,15 +15,15 @@ declare_id!("4bvT6A8S7ZVL6bSvK2KoL2nQ4F5H6AF9133kCYbMJj1t"); pub mod lending { use super::*; - pub fn init_lending_market( - context: Context, + pub fn initialize_lending_market( + context: Context, market_id: u64, ) -> Result<()> { - instructions::handle_init_lending_market(context, market_id) + instructions::handle_initialize_lending_market(context, market_id) } - pub fn init_reserve(context: Context, config: ReserveConfig) -> Result<()> { - instructions::handle_init_reserve(context, config) + pub fn initialize_reserve(context: Context, config: ReserveConfig) -> Result<()> { + instructions::handle_initialize_reserve(context, config) } pub fn update_reserve_config( @@ -63,8 +63,8 @@ pub mod lending { instructions::handle_redeem_reserve_collateral(context, share_amount) } - pub fn init_obligation(context: Context) -> Result<()> { - instructions::handle_init_obligation(context) + pub fn initialize_obligation(context: Context) -> Result<()> { + instructions::handle_initialize_obligation(context) } pub fn refresh_obligation(context: Context) -> Result<()> { diff --git a/finance/lending/anchor/programs/lending/tests/common/mod.rs b/finance/lending/anchor/programs/lending/tests/common/mod.rs index fd2e6a6d1..b51bacdbb 100644 --- a/finance/lending/anchor/programs/lending/tests/common/mod.rs +++ b/finance/lending/anchor/programs/lending/tests/common/mod.rs @@ -103,14 +103,14 @@ impl Env { let instruction = Instruction { program_id: lending::id(), - accounts: lending::accounts::InitLendingMarket { + accounts: lending::accounts::InitializeLendingMarket { lending_market: market, owner: owner.pubkey(), quote_currency_mint: quote_mint, system_program: system_program::id(), } .to_account_metas(None), - data: lending::instruction::InitLendingMarket { market_id }.data(), + data: lending::instruction::InitializeLendingMarket { market_id }.data(), }; send(&mut svm, vec![instruction], &[&owner], &owner.pubkey()).unwrap(); @@ -132,14 +132,14 @@ impl Env { let market = pda(&[LENDING_MARKET_SEED, &market_id.to_le_bytes()]); let instruction = Instruction { program_id: lending::id(), - accounts: lending::accounts::InitLendingMarket { + accounts: lending::accounts::InitializeLendingMarket { lending_market: market, owner: market_owner.pubkey(), quote_currency_mint: quote_mint, system_program: system_program::id(), } .to_account_metas(None), - data: lending::instruction::InitLendingMarket { market_id }.data(), + data: lending::instruction::InitializeLendingMarket { market_id }.data(), }; send(&mut self.svm, vec![instruction], &[market_owner], &market_owner.pubkey()).unwrap(); market @@ -167,7 +167,7 @@ impl Env { let instruction = Instruction { program_id: lending::id(), - accounts: lending::accounts::InitReserve { + accounts: lending::accounts::InitializeReserve { lending_market: market, owner: market_owner.pubkey(), reserve, @@ -179,7 +179,7 @@ impl Env { system_program: system_program::id(), } .to_account_metas(None), - data: lending::instruction::InitReserve { config }.data(), + data: lending::instruction::InitializeReserve { config }.data(), }; send(&mut self.svm, vec![instruction], &[market_owner], &market_owner.pubkey()).unwrap(); @@ -369,18 +369,18 @@ impl Env { send(&mut self.svm, vec![refresh, redeem], &[user], &user.pubkey()) } - pub fn init_obligation(&mut self, user: &Keypair) -> Pubkey { + pub fn initialize_obligation(&mut self, user: &Keypair) -> Pubkey { let obligation = pda(&[OBLIGATION_SEED, self.market.as_ref(), user.pubkey().as_ref()]); let instruction = Instruction { program_id: lending::id(), - accounts: lending::accounts::InitObligation { + accounts: lending::accounts::InitializeObligation { lending_market: self.market, obligation, owner: user.pubkey(), system_program: system_program::id(), } .to_account_metas(None), - data: lending::instruction::InitObligation {}.data(), + data: lending::instruction::InitializeObligation {}.data(), }; send(&mut self.svm, vec![instruction], &[user], &user.pubkey()).unwrap(); obligation diff --git a/finance/lending/anchor/programs/lending/tests/test_borrow_repay.rs b/finance/lending/anchor/programs/lending/tests/test_borrow_repay.rs index 6e5214237..4b430e9fa 100644 --- a/finance/lending/anchor/programs/lending/tests/test_borrow_repay.rs +++ b/finance/lending/anchor/programs/lending/tests/test_borrow_repay.rs @@ -21,7 +21,7 @@ fn setup() -> (Env, ReserveHandle, ReserveHandle, Keypair, anchor_lang::prelude: env.fund(&borrower, collateral.mint, 1_000_000_000); env.fund(&borrower, borrow.mint, 0); // create the borrowed-token account env.supply(&borrower, &collateral, 1_000_000_000); - let obligation = env.init_obligation(&borrower); + let obligation = env.initialize_obligation(&borrower); env.post_collateral(&borrower, obligation, &collateral, 1_000_000_000); (env, collateral, borrow, borrower, obligation) diff --git a/finance/lending/anchor/programs/lending/tests/test_interest.rs b/finance/lending/anchor/programs/lending/tests/test_interest.rs index a9c21c9b3..34315d9e8 100644 --- a/finance/lending/anchor/programs/lending/tests/test_interest.rs +++ b/finance/lending/anchor/programs/lending/tests/test_interest.rs @@ -24,7 +24,7 @@ fn interest_accrues_on_borrows_over_time() { env.fund(&borrower, collateral.mint, 1_000_000_000); env.fund(&borrower, borrow.mint, 0); env.supply(&borrower, &collateral, 1_000_000_000); - let obligation = env.init_obligation(&borrower); + let obligation = env.initialize_obligation(&borrower); env.post_collateral(&borrower, obligation, &collateral, 1_000_000_000); env.try_borrow(&borrower, obligation, &[&collateral], &[], &borrow, 500_000_000) .unwrap(); @@ -78,7 +78,7 @@ fn protocol_fees_accrue_and_owner_can_collect() { env.fund(&borrower, collateral.mint, 1_000_000_000); env.fund(&borrower, borrow.mint, 0); env.supply(&borrower, &collateral, 1_000_000_000); - let obligation = env.init_obligation(&borrower); + let obligation = env.initialize_obligation(&borrower); env.post_collateral(&borrower, obligation, &collateral, 1_000_000_000); env.try_borrow(&borrower, obligation, &[&collateral], &[], &borrow, 500_000_000) .unwrap(); diff --git a/finance/lending/anchor/programs/lending/tests/test_liquidation.rs b/finance/lending/anchor/programs/lending/tests/test_liquidation.rs index 57c99e8a0..2024369d0 100644 --- a/finance/lending/anchor/programs/lending/tests/test_liquidation.rs +++ b/finance/lending/anchor/programs/lending/tests/test_liquidation.rs @@ -26,7 +26,7 @@ fn setup() -> ( env.fund(&borrower, collateral.mint, 1_000_000_000); env.fund(&borrower, borrow.mint, 0); env.supply(&borrower, &collateral, 1_000_000_000); - let obligation = env.init_obligation(&borrower); + let obligation = env.initialize_obligation(&borrower); env.post_collateral(&borrower, obligation, &collateral, 1_000_000_000); env.try_borrow(&borrower, obligation, &[&collateral], &[], &borrow, 700_000_000) .unwrap(); diff --git a/finance/lending/anchor/programs/lending/tests/test_rounding.rs b/finance/lending/anchor/programs/lending/tests/test_rounding.rs index 054f2966f..55e0bd1ce 100644 --- a/finance/lending/anchor/programs/lending/tests/test_rounding.rs +++ b/finance/lending/anchor/programs/lending/tests/test_rounding.rs @@ -20,7 +20,7 @@ fn deposit_that_would_mint_zero_shares_is_rejected() { env.fund(&borrower, collateral.mint, 1_000_000_000); env.fund(&borrower, borrow.mint, 0); env.supply(&borrower, &collateral, 1_000_000_000); - let obligation = env.init_obligation(&borrower); + let obligation = env.initialize_obligation(&borrower); env.post_collateral(&borrower, obligation, &collateral, 1_000_000_000); env.try_borrow(&borrower, obligation, &[&collateral], &[], &borrow, 500_000_000) .unwrap(); @@ -70,7 +70,7 @@ fn withdraw_at_health_boundary_then_one_more_unit_fails() { env.fund(&borrower, collateral.mint, 1_000_000_000); env.fund(&borrower, borrow.mint, 0); env.supply(&borrower, &collateral, 1_000_000_000); - let obligation = env.init_obligation(&borrower); + let obligation = env.initialize_obligation(&borrower); env.post_collateral(&borrower, obligation, &collateral, 1_000_000_000); // Borrow $600 against $1000 collateral (75% LTV => $750 power). diff --git a/finance/lending/anchor/programs/lending/tests/test_security.rs b/finance/lending/anchor/programs/lending/tests/test_security.rs index a6f1c2199..d928d7e09 100644 --- a/finance/lending/anchor/programs/lending/tests/test_security.rs +++ b/finance/lending/anchor/programs/lending/tests/test_security.rs @@ -24,7 +24,7 @@ fn cross_market_reserve_is_rejected() { let borrower = env.create_user(); env.fund(&borrower, collateral.mint, 1_000_000_000); env.supply(&borrower, &collateral, 1_000_000_000); - let obligation = env.init_obligation(&borrower); + let obligation = env.initialize_obligation(&borrower); // Posting collateral via the second market's reserve must fail before any // token movement. diff --git a/finance/lending/quasar/README.md b/finance/lending/quasar/README.md index 3ce9ba14e..35d960fad 100644 --- a/finance/lending/quasar/README.md +++ b/finance/lending/quasar/README.md @@ -65,9 +65,9 @@ Everything else mirrors the Anchor version. ### Instruction handlers (numeric discriminators) -`init_lending_market` (0), `init_reserve` (1), `set_price` (2), +`initialize_lending_market` (0), `initialize_reserve` (1), `set_price` (2), `deposit_reserve_liquidity` (3), `redeem_reserve_collateral` (4), -`init_obligation` (5), `deposit_obligation_collateral` (6), +`initialize_obligation` (5), `deposit_obligation_collateral` (6), `withdraw_obligation_collateral` (7), `borrow_obligation_liquidity` (8), `repay_obligation_liquidity` (9), `liquidate_obligation` (10), `collect_protocol_fees` (11). diff --git a/finance/lending/quasar/src/constants.rs b/finance/lending/quasar/src/constants.rs index 67d37b8fe..3e88cb5f7 100644 --- a/finance/lending/quasar/src/constants.rs +++ b/finance/lending/quasar/src/constants.rs @@ -20,10 +20,10 @@ pub const SLOTS_PER_YEAR: u128 = 78_840_000; /// Reject a price feed older than this many slots (~10s at 2.5 slots/s). pub const MAX_PRICE_STALENESS_SLOTS: u64 = 25; -/// SPL token account size, for the rent-exempt vault created in `init_reserve`. +/// SPL token account size, for the rent-exempt vault created in `initialize_reserve`. pub const TOKEN_ACCOUNT_SPACE: u64 = 165; -/// SPL mint size, for the rent-exempt share mint created in `init_reserve`. +/// SPL mint size, for the rent-exempt share mint created in `initialize_reserve`. pub const MINT_SPACE: u64 = 82; // PDA seeds for the `Seed::from(...)` signer arrays in the CPI-signing handlers. diff --git a/finance/lending/quasar/src/instructions/admin.rs b/finance/lending/quasar/src/instructions/admin.rs index d9dfca49b..3b9ffb0e5 100644 --- a/finance/lending/quasar/src/instructions/admin.rs +++ b/finance/lending/quasar/src/instructions/admin.rs @@ -15,12 +15,12 @@ use { }; // --------------------------------------------------------------------------- -// init_lending_market +// initialize_lending_market // --------------------------------------------------------------------------- #[derive(Accounts)] #[instruction(market_id: u64)] -pub struct InitLendingMarket { +pub struct InitializeLendingMarket { #[account(mut)] pub owner: Signer, // Seeded by `market_id` alone — owner is stored for auth, not in the address. @@ -30,9 +30,9 @@ pub struct InitLendingMarket { pub system_program: Program, } -impl InitLendingMarket { +impl InitializeLendingMarket { #[inline(always)] - pub fn run(&mut self, market_id: u64, bumps: &InitLendingMarketBumps) -> Result<(), ProgramError> { + pub fn run(&mut self, market_id: u64, bumps: &InitializeLendingMarketBumps) -> Result<(), ProgramError> { self.lending_market.set_inner(LendingMarketInner { owner: *self.owner.address(), market_id, @@ -44,11 +44,11 @@ impl InitLendingMarket { } // --------------------------------------------------------------------------- -// init_reserve +// initialize_reserve // --------------------------------------------------------------------------- #[derive(Accounts)] -pub struct InitReserve { +pub struct InitializeReserve { #[account(mut)] pub owner: Signer, #[account(has_one(owner))] @@ -69,7 +69,7 @@ pub struct InitReserve { pub system_program: Program, } -impl InitReserve { +impl InitializeReserve { #[inline(always)] #[allow(clippy::too_many_arguments)] pub fn run( @@ -83,7 +83,7 @@ impl InitReserve { min_borrow_rate_bps: u16, optimal_borrow_rate_bps: u16, max_borrow_rate_bps: u16, - bumps: &InitReserveBumps, + bumps: &InitializeReserveBumps, ) -> Result<(), ProgramError> { validate_config( loan_to_value_bps, diff --git a/finance/lending/quasar/src/instructions/position.rs b/finance/lending/quasar/src/instructions/position.rs index 3c790b142..46d94f928 100644 --- a/finance/lending/quasar/src/instructions/position.rs +++ b/finance/lending/quasar/src/instructions/position.rs @@ -27,11 +27,11 @@ macro_rules! obligation_seeds { } // --------------------------------------------------------------------------- -// init_obligation +// initialize_obligation // --------------------------------------------------------------------------- #[derive(Accounts)] -pub struct InitObligation { +pub struct InitializeObligation { #[account(mut)] pub owner: Signer, pub lending_market: Account, @@ -40,9 +40,9 @@ pub struct InitObligation { pub system_program: Program, } -impl InitObligation { +impl InitializeObligation { #[inline(always)] - pub fn run(&mut self, bumps: &InitObligationBumps) -> Result<(), ProgramError> { + pub fn run(&mut self, bumps: &InitializeObligationBumps) -> Result<(), ProgramError> { self.obligation.set_inner(ObligationInner { lending_market: *self.lending_market.address(), owner: *self.owner.address(), diff --git a/finance/lending/quasar/src/lib.rs b/finance/lending/quasar/src/lib.rs index 4c2abaa25..519522808 100644 --- a/finance/lending/quasar/src/lib.rs +++ b/finance/lending/quasar/src/lib.rs @@ -34,8 +34,8 @@ mod quasar_lending { use super::*; #[instruction(discriminator = 0)] - pub fn init_lending_market( - ctx: Ctx, + pub fn initialize_lending_market( + ctx: Ctx, market_id: u64, ) -> Result<(), ProgramError> { ctx.accounts.run(market_id, &ctx.bumps) @@ -43,8 +43,8 @@ mod quasar_lending { #[instruction(discriminator = 1)] #[allow(clippy::too_many_arguments)] - pub fn init_reserve( - ctx: Ctx, + pub fn initialize_reserve( + ctx: Ctx, loan_to_value_bps: u16, liquidation_threshold_bps: u16, liquidation_bonus_bps: u16, @@ -95,7 +95,7 @@ mod quasar_lending { } #[instruction(discriminator = 5)] - pub fn init_obligation(ctx: Ctx) -> Result<(), ProgramError> { + pub fn initialize_obligation(ctx: Ctx) -> Result<(), ProgramError> { ctx.accounts.run(&ctx.bumps) } diff --git a/finance/lending/quasar/src/tests.rs b/finance/lending/quasar/src/tests.rs index 7bfb985f2..41de2e43f 100644 --- a/finance/lending/quasar/src/tests.rs +++ b/finance/lending/quasar/src/tests.rs @@ -7,8 +7,8 @@ use { crate::{ cpi::{ BorrowObligationLiquidityInstruction, DepositObligationCollateralInstruction, - DepositReserveLiquidityInstruction, InitLendingMarketInstruction, - InitObligationInstruction, InitReserveInstruction, LiquidateObligationInstruction, + DepositReserveLiquidityInstruction, InitializeLendingMarketInstruction, + InitializeObligationInstruction, InitializeReserveInstruction, LiquidateObligationInstruction, RedeemReserveCollateralInstruction, RepayObligationLiquidityInstruction, SetPriceInstruction, }, @@ -133,10 +133,10 @@ fn set_price(test: &mut Test, w: &Pdas, the_mint: Pubkey, mantissa: i128) { .succeeds(); } -fn init_reserve(test: &mut Test, w: &Pdas, the_mint: Pubkey) { +fn initialize_reserve(test: &mut Test, w: &Pdas, the_mint: Pubkey) { // 75% LTV, 80% liquidation threshold, 5% bonus, 50% close factor, 10% // reserve factor, kink 80%, 2% / 20% / 150% APR curve. - test.send(InitReserveInstruction { + test.send(InitializeReserveInstruction { owner: OWNER, lending_market: w.market, liquidity_mint: the_mint, @@ -154,7 +154,7 @@ fn init_reserve(test: &mut Test, w: &Pdas, the_mint: Pubkey) { } fn setup_markets(test: &mut Test, w: &Pdas) { - test.send(InitLendingMarketInstruction { + test.send(InitializeLendingMarketInstruction { owner: OWNER, quote_mint: QUOTE_MINT, market_id: MARKET_ID, @@ -162,8 +162,8 @@ fn setup_markets(test: &mut Test, w: &Pdas) { .succeeds(); set_price(test, w, COLLATERAL_MINT, dollars(1)); set_price(test, w, BORROW_MINT, dollars(1)); - init_reserve(test, w, COLLATERAL_MINT); - init_reserve(test, w, BORROW_MINT); + initialize_reserve(test, w, COLLATERAL_MINT); + initialize_reserve(test, w, BORROW_MINT); } fn deposit_borrow_side(test: &mut Test, w: &Pdas, amount: u64) -> Outcome { @@ -255,7 +255,7 @@ fn bootstrap_position(test: &mut Test, w: &Pdas) { setup_markets(test, w); deposit_borrow_side(test, w, 1_000 * UNIT).succeeds(); deposit_collateral_side(test, w, 1_000 * UNIT).succeeds(); - test.send(InitObligationInstruction { + test.send(InitializeObligationInstruction { owner: BORROWER, lending_market: w.market, }) @@ -542,7 +542,7 @@ mod slot_warp { self.run(data, metas).assert_success(); } - fn init_reserve( + fn initialize_reserve( &mut self, the_mint: Pubkey, reserve: Pubkey, @@ -575,14 +575,14 @@ mod slot_warp { self.init_market(); self.set_price(COLLATERAL_MINT, self.collateral_price, dollars(1)); self.set_price(BORROW_MINT, self.borrow_price, dollars(1)); - self.init_reserve( + self.initialize_reserve( COLLATERAL_MINT, self.collateral_reserve, self.collateral_vault, self.collateral_share_mint, self.collateral_price, ); - self.init_reserve( + self.initialize_reserve( BORROW_MINT, self.borrow_reserve, self.borrow_vault, @@ -639,7 +639,7 @@ mod slot_warp { self.run(data, metas) } - fn init_obligation(&mut self) { + fn initialize_obligation(&mut self) { let metas = vec![ meta(BORROWER, true, true), meta(self.market, false, false), @@ -711,7 +711,7 @@ mod slot_warp { 1_000 * UNIT, ) .assert_success(); - self.init_obligation(); + self.initialize_obligation(); self.post_collateral(1_000 * UNIT).assert_success(); } diff --git a/finance/order-book/anchor/README.md b/finance/order-book/anchor/README.md index 4b02f583b..867333433 100644 --- a/finance/order-book/anchor/README.md +++ b/finance/order-book/anchor/README.md @@ -217,7 +217,7 @@ Maria's wallet signs. Five accounts are created: ### Step 2 - Alice, Bob, and Carol register as traders -**Instruction: `create_market_user`** (called once by each trader) +**Instruction: `initialize_market_user`** (called once by each trader) Each call creates one `MarketUser` PDA - a per-(trader, market) account that tracks their open orders and any tokens owed to them: @@ -494,7 +494,7 @@ The program has six instruction handlers. The order a user encounters them is: 1. `initialize_market` (market operator - once) -2. `create_market_user` (every user, once per market) +2. `initialize_market_user` (every user, once per market) 3. `place_order` (a user - as many times as they want) 4. `cancel_order` (a user - to remove a resting order) 5. `settle_funds` (a user - to collect winnings) @@ -558,7 +558,7 @@ addresses are chosen by the caller (typically fresh keypairs) and captured on the market's state so later instruction handlers can validate them. -### 3.2 `create_market_user` +### 3.2 `initialize_market_user` **Who calls it:** every user, exactly once per market they want to trade on. @@ -1119,7 +1119,7 @@ Cast: **Maria** (market authority + Alice/Bob's broker), **Alice** 1. `initialize_market` - Maria runs it. Rent for five accounts comes out of her wallet. Market is now `is_active`. -2. `create_market_user` - Alice and Bob each run it once. +2. `initialize_market_user` - Alice and Bob each run it once. 3. Alice posts an ask: `place_order(Ask, 1000, 5)`, no remaining_accounts (empty book). - Lock: `alice_base_account --[5 base]--> base_vault`. @@ -1183,7 +1183,7 @@ Cast: Alice (ask maker), Bob (bid maker, then remainder rests), Carol (new taker). 1. `initialize_market` by Maria (same config). -2. `create_market_user` × 3. +2. `initialize_market_user` × 3. 3. Alice posts `Ask, 1000, 3`. Locks 3 base. 4. Bob posts `Bid, 1100, 10` with Alice's pair as a maker. - Lock: `10 * 1100 = 11_000 quote` from Bob to quote_vault. @@ -1245,7 +1245,7 @@ Cast: Alice (ask maker), Bob (bid maker, then remainder rests), Carol Cast: Alice (bid maker), nobody else. -1. `initialize_market`, `create_market_user(Alice)`. +1. `initialize_market`, `initialize_market_user(Alice)`. 2. Alice posts `Bid, 900, 10` - rests on an empty book. - Lock: 9000 quote from Alice to quote_vault. - No fills. `alice.open_orders = [1]`. `bids = [(1, 900)]`. @@ -1420,7 +1420,7 @@ test authority_can_withdraw_fees_after_match ... ok test cancel_and_settle_bid_refunds_full_quote ... ok test cancel_ask_credits_unsettled_base ... ok test cancel_order_rejects_non_owner ... ok -test create_market_user_tracks_market_and_owner ... ok +test initialize_market_user_tracks_market_and_owner ... ok test fee_vault_receives_exactly_bps_of_taker_gross ... ok test initialize_market_rejects_oversized_fee ... ok test initialize_market_rejects_zero_tick_size ... ok @@ -1446,7 +1446,7 @@ test taker_partially_fills_resting_order_rest_stays_on_book ... ok **Setup / happy path (pre-matching):** - `initialize_market_sets_market_and_order_book`: PDA creation, vault setup, initial field values -- `create_market_user_tracks_market_and_owner`: Per-user PDA derivation and zero-initialised counters +- `initialize_market_user_tracks_market_and_owner`: Per-user PDA derivation and zero-initialised counters - `place_bid_locks_quote_in_vault`: Fund lock on bid - `place_ask_locks_base_in_vault`: Fund lock on ask - `settle_funds_moves_unsettled_base_to_user`: Vault → user ATA transfer via market PDA signer @@ -1589,7 +1589,7 @@ finance/order-book/anchor/ │ ├── instructions/ │ │ ├── mod.rs │ │ ├── initialize_market.rs - │ │ ├── create_market_user.rs + │ │ ├── initialize_market_user.rs │ │ ├── place_order.rs (matching engine lives here) │ │ ├── cancel_order.rs │ │ ├── settle_funds.rs diff --git a/finance/order-book/anchor/programs/order-book/src/instructions/create_market_user.rs b/finance/order-book/anchor/programs/order-book/src/instructions/initialize_market_user.rs similarity index 83% rename from finance/order-book/anchor/programs/order-book/src/instructions/create_market_user.rs rename to finance/order-book/anchor/programs/order-book/src/instructions/initialize_market_user.rs index 11fcf3168..25b885c37 100644 --- a/finance/order-book/anchor/programs/order-book/src/instructions/create_market_user.rs +++ b/finance/order-book/anchor/programs/order-book/src/instructions/initialize_market_user.rs @@ -2,7 +2,7 @@ use anchor_lang::prelude::*; use crate::state::{Market, MarketUser, MARKET_USER_SEED}; -pub fn handle_create_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(); @@ -15,7 +15,7 @@ pub fn handle_create_market_user(context: Context { +pub struct InitializeMarketUserAccountConstraints<'info> { #[account( init, payer = owner, diff --git a/finance/order-book/anchor/programs/order-book/src/instructions/mod.rs b/finance/order-book/anchor/programs/order-book/src/instructions/mod.rs index aa1118af4..1ed385342 100644 --- a/finance/order-book/anchor/programs/order-book/src/instructions/mod.rs +++ b/finance/order-book/anchor/programs/order-book/src/instructions/mod.rs @@ -1,13 +1,13 @@ pub mod admin; pub mod cancel_order; -pub mod create_market_user; +pub mod initialize_market_user; pub mod initialize_market; pub mod place_order; pub mod settle_funds; pub use admin::*; pub use cancel_order::*; -pub use create_market_user::*; +pub use initialize_market_user::*; pub use initialize_market::*; pub use place_order::*; pub use settle_funds::*; diff --git a/finance/order-book/anchor/programs/order-book/src/lib.rs b/finance/order-book/anchor/programs/order-book/src/lib.rs index c15831855..edb913309 100644 --- a/finance/order-book/anchor/programs/order-book/src/lib.rs +++ b/finance/order-book/anchor/programs/order-book/src/lib.rs @@ -35,8 +35,8 @@ pub mod order_book { /// Create a per-user, per-market account that tracks a user's open orders /// and unsettled balances. - pub fn create_market_user(context: Context) -> Result<()> { - instructions::create_market_user::handle_create_market_user(context) + pub fn initialize_market_user(context: Context) -> Result<()> { + instructions::initialize_market_user::handle_initialize_market_user(context) } /// Place a bid or ask. Locks the required funds (quote for bids, base diff --git a/finance/order-book/anchor/programs/order-book/tests/test_order_book.rs b/finance/order-book/anchor/programs/order-book/tests/test_order_book.rs index 00daf4c21..0d25dbb54 100644 --- a/finance/order-book/anchor/programs/order-book/tests/test_order_book.rs +++ b/finance/order-book/anchor/programs/order-book/tests/test_order_book.rs @@ -289,12 +289,12 @@ fn build_initialize_market_ix( ) } -fn build_create_market_user_ix(sc: &Scenario, owner: &Pubkey) -> Instruction { +fn build_initialize_market_user_ix(sc: &Scenario, owner: &Pubkey) -> Instruction { let market_user = market_user_pda(&sc.program_id, &sc.market, owner); Instruction::new_with_bytes( sc.program_id, - &order_book::instruction::CreateMarketUser {}.data(), - order_book::accounts::CreateMarketUserAccountConstraints { + &order_book::instruction::InitializeMarketUser {}.data(), + order_book::accounts::InitializeMarketUserAccountConstraints { market_user, market: sc.market, owner: *owner, @@ -477,7 +477,7 @@ fn initialize_market_and_users(sc: &mut Scenario) { ) .unwrap(); - let buyer_ix = build_create_market_user_ix(sc, &sc.buyer.pubkey()); + let buyer_ix = build_initialize_market_user_ix(sc, &sc.buyer.pubkey()); send_transaction_from_instructions( &mut sc.svm, vec![buyer_ix], @@ -486,7 +486,7 @@ fn initialize_market_and_users(sc: &mut Scenario) { ) .unwrap(); - let seller_ix = build_create_market_user_ix(sc, &sc.seller.pubkey()); + let seller_ix = build_initialize_market_user_ix(sc, &sc.seller.pubkey()); send_transaction_from_instructions( &mut sc.svm, vec![seller_ix], @@ -549,7 +549,7 @@ fn initialize_market_sets_market_and_order_book() { } #[test] -fn create_market_user_tracks_market_and_owner() { +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()); @@ -568,7 +568,7 @@ fn create_market_user_tracks_market_and_owner() { ) .unwrap(); - let create_ix = build_create_market_user_ix(&sc, &sc.buyer.pubkey()); + let create_ix = build_initialize_market_user_ix(&sc, &sc.buyer.pubkey()); send_transaction_from_instructions( &mut sc.svm, vec![create_ix], @@ -716,7 +716,7 @@ fn place_order_rejects_unaligned_tick() { ) .unwrap(); - let create_ix = build_create_market_user_ix(&sc, &sc.buyer.pubkey()); + let create_ix = build_initialize_market_user_ix(&sc, &sc.buyer.pubkey()); send_transaction_from_instructions( &mut sc.svm, vec![create_ix], @@ -773,7 +773,7 @@ fn place_order_rejects_below_min_order_size() { ) .unwrap(); - let create_ix = build_create_market_user_ix(&sc, &sc.seller.pubkey()); + let create_ix = build_initialize_market_user_ix(&sc, &sc.seller.pubkey()); send_transaction_from_instructions( &mut sc.svm, vec![create_ix], @@ -1695,7 +1695,7 @@ fn resting_orders_at_same_price_fill_by_time_priority() { ) .unwrap(); let second_seller_market_user = market_user_pda(&sc.program_id, &sc.market, &second_seller.pubkey()); - let __ix1 = build_create_market_user_ix(&sc, &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(); diff --git a/finance/order-book/quasar/README.md b/finance/order-book/quasar/README.md index 1aec23272..2e6432958 100644 --- a/finance/order-book/quasar/README.md +++ b/finance/order-book/quasar/README.md @@ -62,7 +62,7 @@ NVDAx (9 decimals) / USDC (6 decimals): `base_lot_size = 1000`, `quote_lot_size ## Instruction lifecycle - `initialize_market`: Create the `Market` PDA, the two vaults, and the fee vault; initialize the pre-created order-book account. -- `create_market_user`: Create a caller's `MarketUser` for a market. +- `initialize_market_user`: Create a caller's `MarketUser` for a market. - `place_order`: Lock funds, cross the opposing side in price-time priority, credit fills to maker/taker `unsettled_*`, route the taker fee, and rest any remainder. - `cancel_order`: Credit an open order's locked remainder back to the owner's `unsettled_*` and remove it from the book. - `settle_funds`: Move a user's `unsettled_*` balances out of the vaults into their token accounts. diff --git a/finance/order-book/quasar/src/instructions/create_market_user.rs b/finance/order-book/quasar/src/instructions/initialize_market_user.rs similarity index 80% rename from finance/order-book/quasar/src/instructions/create_market_user.rs rename to finance/order-book/quasar/src/instructions/initialize_market_user.rs index 7d298b654..e3d7f93a3 100644 --- a/finance/order-book/quasar/src/instructions/create_market_user.rs +++ b/finance/order-book/quasar/src/instructions/initialize_market_user.rs @@ -3,7 +3,7 @@ use quasar_lang::prelude::*; use crate::state::{Market, MarketUser, MarketUserInner, OPEN_ORDERS_BYTES}; #[derive(Accounts)] -pub struct CreateMarketUserAccountConstraints { +pub struct InitializeMarketUserAccountConstraints { #[account(mut)] pub owner: Signer, @@ -21,9 +21,9 @@ pub struct CreateMarketUserAccountConstraints { } #[inline(always)] -pub fn handle_create_market_user( - accounts: &mut CreateMarketUserAccountConstraints, - bumps: &CreateMarketUserAccountConstraintsBumps, +pub fn handle_initialize_market_user( + accounts: &mut InitializeMarketUserAccountConstraints, + bumps: &InitializeMarketUserAccountConstraintsBumps, ) -> Result<(), ProgramError> { accounts.market_user.set_inner(MarketUserInner { market: *accounts.market.address(), diff --git a/finance/order-book/quasar/src/instructions/mod.rs b/finance/order-book/quasar/src/instructions/mod.rs index aa1118af4..1ed385342 100644 --- a/finance/order-book/quasar/src/instructions/mod.rs +++ b/finance/order-book/quasar/src/instructions/mod.rs @@ -1,13 +1,13 @@ pub mod admin; pub mod cancel_order; -pub mod create_market_user; +pub mod initialize_market_user; pub mod initialize_market; pub mod place_order; pub mod settle_funds; pub use admin::*; pub use cancel_order::*; -pub use create_market_user::*; +pub use initialize_market_user::*; pub use initialize_market::*; pub use place_order::*; pub use settle_funds::*; diff --git a/finance/order-book/quasar/src/lib.rs b/finance/order-book/quasar/src/lib.rs index 2935c9a1f..ae178de93 100644 --- a/finance/order-book/quasar/src/lib.rs +++ b/finance/order-book/quasar/src/lib.rs @@ -48,10 +48,10 @@ mod quasar_order_book { /// Create a per-user, per-market account tracking a user's open orders and /// unsettled balances. #[instruction(discriminator = 1)] - pub fn create_market_user( - ctx: Ctx, + pub fn initialize_market_user( + ctx: Ctx, ) -> Result<(), ProgramError> { - instructions::create_market_user::handle_create_market_user(&mut ctx.accounts, &ctx.bumps) + instructions::initialize_market_user::handle_initialize_market_user(&mut ctx.accounts, &ctx.bumps) } /// Place a bid or ask (`side`: 0 = Bid, 1 = Ask). Locks the required funds, diff --git a/finance/order-book/quasar/src/tests.rs b/finance/order-book/quasar/src/tests.rs index 05b1cbd43..97ba85ae8 100644 --- a/finance/order-book/quasar/src/tests.rs +++ b/finance/order-book/quasar/src/tests.rs @@ -6,7 +6,7 @@ use { crate::{ cpi::{ - CancelOrderInstruction, CreateMarketUserInstruction, InitializeMarketInstruction, + CancelOrderInstruction, InitializeMarketUserInstruction, InitializeMarketInstruction, PlaceOrderInstruction, SettleFundsInstruction, WithdrawFeesInstruction, }, errors::OrderBookError, @@ -90,9 +90,9 @@ fn init_market(test: &mut Test) -> Pubkey { test.derive_pda(Market::seeds(&BASE_MINT, "E_MINT)) } -fn create_market_user(test: &mut Test, market: Pubkey, owner: Pubkey) -> Pubkey { +fn initialize_market_user(test: &mut Test, market: Pubkey, owner: Pubkey) -> Pubkey { test.add(Wallet::new().at(owner)); - test.send(CreateMarketUserInstruction { owner, market }).succeeds(); + test.send(InitializeMarketUserInstruction { owner, market }).succeeds(); test.derive_pda(MarketUser::seeds(&market, &owner)) } @@ -181,9 +181,9 @@ fn initialize_market_stamps_market_and_order_book(test: &mut Test) { } #[quasar_test] -fn create_market_user_starts_with_empty_balances(test: &mut Test) { +fn initialize_market_user_starts_with_empty_balances(test: &mut Test) { let market = init_market(test); - let market_user = create_market_user(test, market, MAKER); + let market_user = initialize_market_user(test, market, MAKER); let state = test.read::(market_user); assert_eq!(state.market, market, "market"); @@ -200,8 +200,8 @@ fn create_market_user_starts_with_empty_balances(test: &mut Test) { #[quasar_test] fn place_match_settle_withdraw_moves_tokens_and_fees(test: &mut Test) { let market = init_market(test); - let maker_market_user = create_market_user(test, market, MAKER); - let taker_market_user = create_market_user(test, market, TAKER); + let maker_market_user = initialize_market_user(test, market, MAKER); + let taker_market_user = initialize_market_user(test, market, TAKER); // Maker sells 5 base lots (locks 5 * 1000 = 5000 raw base); taker buys 5 // lots at 100 (locks 100 * 5 * 1 = 500 raw quote). @@ -291,7 +291,7 @@ fn place_match_settle_withdraw_moves_tokens_and_fees(test: &mut Test) { #[quasar_test] fn cancel_order_credits_the_locked_base_back(test: &mut Test) { let market = init_market(test); - let maker_market_user = create_market_user(test, market, MAKER); + let maker_market_user = initialize_market_user(test, market, MAKER); const PRICE: u64 = 100; const QUANTITY: u64 = 5; diff --git a/finance/token-fundraiser/anchor/README.md b/finance/token-fundraiser/anchor/README.md index 3b1c5a2cb..a51071b74 100644 --- a/finance/token-fundraiser/anchor/README.md +++ b/finance/token-fundraiser/anchor/README.md @@ -77,7 +77,7 @@ All balance arithmetic uses `checked_*` operations and returns `FundraiserError: ### `initialize` -[`programs/fundraiser/src/instructions/initialize.rs`](programs/fundraiser/src/instructions/initialize.rs), account constraints `InitializeAccountConstraints`. +[`programs/fundraiser/src/instructions/initialize.rs`](programs/fundraiser/src/instructions/initialize.rs), account constraints `InitializeFundraiserAccountConstraints`. The maker signs and pays for two new accounts: diff --git a/finance/token-fundraiser/anchor/programs/fundraiser/src/instructions/initialize.rs b/finance/token-fundraiser/anchor/programs/fundraiser/src/instructions/initialize_fundraiser.rs similarity index 90% rename from finance/token-fundraiser/anchor/programs/fundraiser/src/instructions/initialize.rs rename to finance/token-fundraiser/anchor/programs/fundraiser/src/instructions/initialize_fundraiser.rs index 63d126d2f..b105d17a5 100644 --- a/finance/token-fundraiser/anchor/programs/fundraiser/src/instructions/initialize.rs +++ b/finance/token-fundraiser/anchor/programs/fundraiser/src/instructions/initialize_fundraiser.rs @@ -7,7 +7,7 @@ use anchor_spl::{ use crate::{state::Fundraiser, FundraiserError, MIN_AMOUNT_TO_RAISE}; #[derive(Accounts)] -pub struct InitializeAccountConstraints<'info> { +pub struct InitializeFundraiserAccountConstraints<'info> { #[account(mut)] pub maker: Signer<'info>, @@ -38,11 +38,11 @@ pub struct InitializeAccountConstraints<'info> { pub associated_token_program: Program<'info, AssociatedToken>, } -pub fn handle_initialize( - accounts: &mut InitializeAccountConstraints, +pub fn handle_initialize_fundraiser( + accounts: &mut InitializeFundraiserAccountConstraints, amount: u64, duration: u16, - bumps: &InitializeAccountConstraintsBumps, + bumps: &InitializeFundraiserAccountConstraintsBumps, ) -> Result<()> { // The target must be at least MIN_AMOUNT_TO_RAISE major units, expressed // in minor units: MIN_AMOUNT_TO_RAISE * 10^decimals. diff --git a/finance/token-fundraiser/anchor/programs/fundraiser/src/instructions/mod.rs b/finance/token-fundraiser/anchor/programs/fundraiser/src/instructions/mod.rs index 829e48468..7ae564501 100644 --- a/finance/token-fundraiser/anchor/programs/fundraiser/src/instructions/mod.rs +++ b/finance/token-fundraiser/anchor/programs/fundraiser/src/instructions/mod.rs @@ -1,10 +1,10 @@ -pub mod initialize; +pub mod initialize_fundraiser; pub mod contribute; pub mod checker; pub mod refund; pub mod close; -pub use initialize::*; +pub use initialize_fundraiser::*; pub use contribute::*; pub use checker::*; pub use refund::*; diff --git a/finance/token-fundraiser/anchor/programs/fundraiser/src/lib.rs b/finance/token-fundraiser/anchor/programs/fundraiser/src/lib.rs index 0ef1eb836..ccbee926a 100644 --- a/finance/token-fundraiser/anchor/programs/fundraiser/src/lib.rs +++ b/finance/token-fundraiser/anchor/programs/fundraiser/src/lib.rs @@ -15,12 +15,12 @@ use instructions::*; pub mod fundraiser { use super::*; - pub fn initialize( - mut context: Context, + pub fn initialize_fundraiser( + mut context: Context, amount: u64, duration: u16, ) -> Result<()> { - handle_initialize(&mut context.accounts, amount, duration, &context.bumps)?; + handle_initialize_fundraiser(&mut context.accounts, amount, duration, &context.bumps)?; Ok(()) } diff --git a/finance/token-fundraiser/anchor/programs/fundraiser/tests/test_fundraiser.rs b/finance/token-fundraiser/anchor/programs/fundraiser/tests/test_fundraiser.rs index dcb5d95c8..c32e479e0 100644 --- a/finance/token-fundraiser/anchor/programs/fundraiser/tests/test_fundraiser.rs +++ b/finance/token-fundraiser/anchor/programs/fundraiser/tests/test_fundraiser.rs @@ -126,8 +126,8 @@ fn full_setup() -> FundraiserSetup { fn initialize_fundraiser(setup: &mut FundraiserSetup, amount: u64, duration: u16) { let initialize_instruction = Instruction::new_with_bytes( setup.program_id, - &fundraiser::instruction::Initialize { amount, duration }.data(), - fundraiser::accounts::InitializeAccountConstraints { + &fundraiser::instruction::InitializeFundraiser { amount, duration }.data(), + fundraiser::accounts::InitializeFundraiserAccountConstraints { maker: setup.maker.pubkey(), mint_to_raise: setup.mint, fundraiser: setup.fundraiser_pda, @@ -290,12 +290,12 @@ fn test_initialize_below_minimum_target_fails() { let below_minimum_target = 3 * ONE_TOKEN - 1; let initialize_instruction = Instruction::new_with_bytes( setup.program_id, - &fundraiser::instruction::Initialize { + &fundraiser::instruction::InitializeFundraiser { amount: below_minimum_target, duration: DURATION_DAYS, } .data(), - fundraiser::accounts::InitializeAccountConstraints { + fundraiser::accounts::InitializeFundraiserAccountConstraints { maker: setup.maker.pubkey(), mint_to_raise: setup.mint, fundraiser: setup.fundraiser_pda, diff --git a/finance/token-fundraiser/quasar/src/instructions/initialize.rs b/finance/token-fundraiser/quasar/src/instructions/initialize_fundraiser.rs similarity index 90% rename from finance/token-fundraiser/quasar/src/instructions/initialize.rs rename to finance/token-fundraiser/quasar/src/instructions/initialize_fundraiser.rs index 5e3a49fcb..9ac241f0e 100644 --- a/finance/token-fundraiser/quasar/src/instructions/initialize.rs +++ b/finance/token-fundraiser/quasar/src/instructions/initialize_fundraiser.rs @@ -8,7 +8,7 @@ use { }; #[derive(Accounts)] -pub struct InitializeAccountConstraints { +pub struct InitializeFundraiserAccountConstraints { #[account(mut)] pub maker: Signer, @@ -33,8 +33,8 @@ pub struct InitializeAccountConstraints { } #[inline(always)] -pub fn handle_initialize( - accounts: &mut InitializeAccountConstraints, +pub fn handle_initialize_fundraiser( + accounts: &mut InitializeFundraiserAccountConstraints, amount_to_raise: u64, duration: u16, bump: u8, diff --git a/finance/token-fundraiser/quasar/src/instructions/mod.rs b/finance/token-fundraiser/quasar/src/instructions/mod.rs index 7398d31c0..1567cbd71 100644 --- a/finance/token-fundraiser/quasar/src/instructions/mod.rs +++ b/finance/token-fundraiser/quasar/src/instructions/mod.rs @@ -1,5 +1,5 @@ -pub mod initialize; -pub use initialize::*; +pub mod initialize_fundraiser; +pub use initialize_fundraiser::*; pub mod contribute; pub use contribute::*; diff --git a/finance/token-fundraiser/quasar/src/lib.rs b/finance/token-fundraiser/quasar/src/lib.rs index 630876cdd..87862e5cb 100644 --- a/finance/token-fundraiser/quasar/src/lib.rs +++ b/finance/token-fundraiser/quasar/src/lib.rs @@ -20,12 +20,12 @@ mod quasar_token_fundraiser { /// Create a new fundraiser with a target amount and duration. #[instruction(discriminator = 0)] - pub fn initialize( - ctx: Ctx, + pub fn initialize_fundraiser( + ctx: Ctx, amount_to_raise: u64, duration: u16, ) -> Result<(), ProgramError> { - instructions::handle_initialize(&mut ctx.accounts, amount_to_raise, duration, ctx.bumps.fundraiser) + instructions::handle_initialize_fundraiser(&mut ctx.accounts, amount_to_raise, duration, ctx.bumps.fundraiser) } /// Contribute tokens to the fundraiser while its window is open. Creates diff --git a/finance/token-fundraiser/quasar/src/tests.rs b/finance/token-fundraiser/quasar/src/tests.rs index 176b75120..f9ca64be4 100644 --- a/finance/token-fundraiser/quasar/src/tests.rs +++ b/finance/token-fundraiser/quasar/src/tests.rs @@ -5,7 +5,7 @@ use { crate::{ cpi::{ - CheckContributionsInstruction, ContributeInstruction, InitializeInstruction, + CheckContributionsInstruction, ContributeInstruction, InitializeFundraiserInstruction, RefundInstruction, }, error::FundraiserError, @@ -56,8 +56,8 @@ fn base_world(test: &mut Test) { test.warp_to_timestamp(START_TIME); } -fn initialize(test: &mut Test, amount_to_raise: u64, duration: u16) -> Outcome { - test.send(InitializeInstruction { +fn initialize_fundraiser(test: &mut Test, amount_to_raise: u64, duration: u16) -> Outcome { + test.send(InitializeFundraiserInstruction { maker: MAKER, mint_to_raise: MINT, vault: VAULT, @@ -69,7 +69,7 @@ fn initialize(test: &mut Test, amount_to_raise: u64, duration: u16) -> Outcome { /// A world with an initialized fundraiser and a funded contributor. fn initialized_world(test: &mut Test) -> Pubkey { base_world(test); - initialize(test, TARGET_AMOUNT, DURATION_DAYS).succeeds(); + initialize_fundraiser(test, TARGET_AMOUNT, DURATION_DAYS).succeeds(); test.add(Wallet::new().at(CONTRIBUTOR)); test.add( TokenAccount::new(MINT, CONTRIBUTOR) @@ -112,7 +112,7 @@ fn check_contributions(test: &mut Test) -> Outcome { #[quasar_test] fn initialize_records_state_and_clock_time(test: &mut Test) { base_world(test); - initialize(test, TARGET_AMOUNT, DURATION_DAYS) + initialize_fundraiser(test, TARGET_AMOUNT, DURATION_DAYS) .succeeds() .has_tokens(VAULT, 0); @@ -131,13 +131,13 @@ fn initialize_records_state_and_clock_time(test: &mut Test) { #[quasar_test] fn initialize_rejects_zero_amount(test: &mut Test) { base_world(test); - initialize(test, 0, DURATION_DAYS).fails_with(FundraiserError::InvalidAmount); + initialize_fundraiser(test, 0, DURATION_DAYS).fails_with(FundraiserError::InvalidAmount); } #[quasar_test] fn initialize_rejects_zero_duration(test: &mut Test) { base_world(test); - initialize(test, TARGET_AMOUNT, 0).fails_with(FundraiserError::InvalidDuration); + initialize_fundraiser(test, TARGET_AMOUNT, 0).fails_with(FundraiserError::InvalidDuration); } #[quasar_test] diff --git a/finance/token-swap/README.md b/finance/token-swap/README.md index caa7c22da..b833026bf 100644 --- a/finance/token-swap/README.md +++ b/finance/token-swap/README.md @@ -57,8 +57,8 @@ programs/token-swap/src/ ├── errors.rs ├── instructions │ ├── claim_admin_fees.rs -│ ├── create_config.rs -│ ├── create_pool.rs +│ ├── initialize_config.rs +│ ├── initialize_pool.rs │ ├── deposit_liquidity.rs │ ├── mod.rs │ ├── swap_tokens.rs @@ -96,11 +96,11 @@ The admin's fees are tracked as *virtual* claims on the existing `pool_a` / `poo ## Instruction handlers -### `create_config` +### `initialize_config` Initializes the singleton `Config` account with the supplied `admin`, `fee`, and `admin_share_bps`. The `Config` PDA is derived from the fixed seed `[b"config"]`, so this can only succeed once per deployed program. Enforces `fee < 10000` and `admin_share_bps < 10000`. -### `create_pool` +### `initialize_pool` Initializes a `PoolConfig` account, an LP mint (`liquidity_provider_mint`), and the two pool reserve token accounts (`pool_a`, `pool_b`) owned by `pool_authority`. Enforces `mint_a < mint_b` for canonical pool addressing. @@ -156,7 +156,7 @@ A worked example, end to end, using this program. The example uses three tokens: **Cast:** -- **Alice** - AMM operator. Deploys and runs the exchange. Earns a slice of every trading fee via the admin protocol-fee mechanism; also earns LP [yield](https://www.investopedia.com/terms/y/yield.asp) on her own initial deposits. Wants real usage so fee income compounds. She calls `create_config` to fix the trading fee at 0.3% and sets `admin_share_bps = 1667` so she earns ~1/6 of every trading fee (LPs keep the other ~5/6). She seeds both the NVDAx/USDC pool and the TSLAx/USDC pool herself (eating the locked `MINIMUM_LIQUIDITY` cost) so users have something to trade from day one. +- **Alice** - AMM operator. Deploys and runs the exchange. Earns a slice of every trading fee via the admin protocol-fee mechanism; also earns LP [yield](https://www.investopedia.com/terms/y/yield.asp) on her own initial deposits. Wants real usage so fee income compounds. She calls `initialize_config` to fix the trading fee at 0.3% and sets `admin_share_bps = 1667` so she earns ~1/6 of every trading fee (LPs keep the other ~5/6). She seeds both the NVDAx/USDC pool and the TSLAx/USDC pool herself (eating the locked `MINIMUM_LIQUIDITY` cost) so users have something to trade from day one. - **Bob** - yield farmer / [liquidity provider](https://www.investopedia.com/terms/l/liquidity-provider.asp). Has idle capital (NVDAx and USDC) earning nothing. Wants to earn [passive income](https://www.investopedia.com/terms/p/passiveincome.asp) from the swap fees the pool collects, without actively trading. - **Carol** - retail trader. Holds USDC and has a bullish [thesis](https://www.investopedia.com/terms/i/investmentthesis.asp) on NVIDIA: she believes NVDAx will appreciate. She wants to swap USDC for NVDAx quickly, without a centralised exchange account. She also later buys TSLAx on the TSLAx/USDC pool. - **Dave** - [arbitrageur](https://www.investopedia.com/terms/a/arbitrage.asp). Profits by trading the gap between the pool's mid-price and the offchain market price. Side effect: his trades drag the pool price back toward fair value. @@ -165,8 +165,8 @@ A worked example, end to end, using this program. The example uses three tokens: The singleton `Config` account is set once per deployed program. Every pool inherits its `fee` and `admin_share_bps`. -- **Handler:** `create_config` -- **Accounts (`CreateConfigAccounts`):** +- **Handler:** `initialize_config` +- **Accounts (`InitializeConfigAccounts`):** - `config` (PDA, created) - seeds `[b"config"]`; stores `admin`, `fee`, `admin_share_bps`, `bump` - `admin` = Alice - `payer` = Alice @@ -177,8 +177,8 @@ The singleton `Config` account is set once per deployed program. Every pool inhe ### Step 2 - Alice creates the NVDAx/USDC pool -- **Handler:** `create_pool` -- **Accounts (`CreatePoolAccounts`):** +- **Handler:** `initialize_pool` +- **Accounts (`InitializePoolAccounts`):** - `config` - Alice's `Config` - `pool_config` (PDA, created) - seeds `[config, mint_a, mint_b]`; stores `config`, `mint_a`, `mint_b`, `bump` - `pool_authority` (PDA) - signs for the pool reserves @@ -195,8 +195,8 @@ NVDAx/USDC pool exists; reserves are empty. No one can swap yet. Alice immediately creates a second pool for TSLAx (Tesla xStock, ~180 USDC each). The handler and account shape are identical to Step 2; only the mints differ. -- **Handler:** `create_pool` -- **Accounts (`CreatePoolAccounts`):** +- **Handler:** `initialize_pool` +- **Accounts (`InitializePoolAccounts`):** - `config` - Alice's `Config` (same singleton) - `pool_config` (PDA, created) - seeds `[config, mint_a, mint_b]`; stores `config`, `mint_a` = TSLAx mint, `mint_b` = USDC mint, `bump` - `pool_authority` (PDA) - signs for this pool's reserves @@ -368,14 +368,14 @@ He receives his proportional share of the **effective reserves** (`pool_X.amount ### Recap -- **Alice** calls `create_config` → `create_pool` (NVDAx/USDC) → `create_pool` (TSLAx/USDC) → `deposit_liquidity` on NVDAx/USDC → `deposit_liquidity` on TSLAx/USDC (admin, pool creator, initial LP on both pools) +- **Alice** calls `initialize_config` → `initialize_pool` (NVDAx/USDC) → `initialize_pool` (TSLAx/USDC) → `deposit_liquidity` on NVDAx/USDC → `deposit_liquidity` on TSLAx/USDC (admin, pool creator, initial LP on both pools) - **Bob** calls `deposit_liquidity` on NVDAx/USDC (LP / yield farmer) - **Carol** calls `swap_tokens` with `input_is_token_a = false` on NVDAx/USDC (buys NVDAx with USDC), then calls `swap_tokens` with `input_is_token_a = false` on TSLAx/USDC (buys TSLAx with USDC) - **Dave** calls `swap_tokens` with `input_is_token_a = true` on NVDAx/USDC (arbitrageur, restores the mid-price to ~5.00) - **Alice** calls `claim_admin_fees` on NVDAx/USDC, then `claim_admin_fees` on TSLAx/USDC (sweeps her accumulated fee slices from both pools) - **Bob** later calls `withdraw_liquidity` on NVDAx/USDC (exits with his fee income) -What makes this work: `x × y = K` on the effective reserves keeps the pool solvent on every swap without anyone quoting prices. LPs are paid in growing effective reserves (their share of the fee, parameterised by `Config.fee` and `Config.admin_share_bps`); the admin earns the other share, accumulated lazily and swept on demand; profit-chasing arbitrageurs incidentally keep the mid-price honest; traders get instant fills against a passive counterparty (the pool). The same `create_pool` handler and the same `swap_tokens` handler work identically for both the NVDAx/USDC and TSLAx/USDC pools - only the mint accounts differ. +What makes this work: `x × y = K` on the effective reserves keeps the pool solvent on every swap without anyone quoting prices. LPs are paid in growing effective reserves (their share of the fee, parameterised by `Config.fee` and `Config.admin_share_bps`); the admin earns the other share, accumulated lazily and swept on demand; profit-chasing arbitrageurs incidentally keep the mid-price honest; traders get instant fills against a passive counterparty (the pool). The same `initialize_pool` handler and the same `swap_tokens` handler work identically for both the NVDAx/USDC and TSLAx/USDC pools - only the mint accounts differ. ## Tests diff --git a/finance/token-swap/anchor/README.md b/finance/token-swap/anchor/README.md index 55e1f30bb..c06fd0289 100644 --- a/finance/token-swap/anchor/README.md +++ b/finance/token-swap/anchor/README.md @@ -38,7 +38,7 @@ Read the program `programs/` source and `Anchor.toml` for deployed program IDs. ### How does an AMM work on Solana? -An automated market maker replaces the order book with a liquidity pool: anyone can create a pool with `create_pool`, fund it with `deposit_liquidity`, and trade against it with `swap_tokens`. Prices come from the constant-product invariant on the pool's balances, and liquidity providers earn a share of trading fees. Solana exchanges like Raydium and Orca use this design. +An automated market maker replaces the order book with a liquidity pool: anyone can create a pool with `initialize_pool`, fund it with `deposit_liquidity`, and trade against it with `swap_tokens`. Prices come from the constant-product invariant on the pool's balances, and liquidity providers earn a share of trading fees. Solana exchanges like Raydium and Orca use this design. ### How is slippage handled? diff --git a/finance/token-swap/anchor/programs/token-swap/src/errors.rs b/finance/token-swap/anchor/programs/token-swap/src/errors.rs index 1228181d9..887ee82a5 100644 --- a/finance/token-swap/anchor/programs/token-swap/src/errors.rs +++ b/finance/token-swap/anchor/programs/token-swap/src/errors.rs @@ -5,7 +5,7 @@ pub enum AmmError { #[msg("Invalid fee value")] InvalidFee, - // Returned when `create_config` is called with `admin_share_bps >= 10_000`. + // Returned when `initialize_config` is called with `admin_share_bps >= 10_000`. // The admin share is a basis-points fraction of the trading fee, so values // at or above 10_000 are nonsensical (the admin can't take more than the // whole fee). @@ -72,7 +72,7 @@ pub enum AmmError { #[msg("Math overflow")] MathOverflow, - // Returned by `create_pool` when `mint_a >= mint_b`. Requiring a strict + // Returned by `initialize_pool` when `mint_a >= mint_b`. Requiring a strict // ascending order ensures each (mint_a, mint_b) pair has exactly one // canonical pool PDA - without it, a (X, Y) pool and a (Y, X) pool would // both be valid, fragmenting liquidity. diff --git a/finance/token-swap/anchor/programs/token-swap/src/instructions/create_config.rs b/finance/token-swap/anchor/programs/token-swap/src/instructions/initialize_config.rs similarity index 89% rename from finance/token-swap/anchor/programs/token-swap/src/instructions/create_config.rs rename to finance/token-swap/anchor/programs/token-swap/src/instructions/initialize_config.rs index 8673b2a90..b5739d3e5 100644 --- a/finance/token-swap/anchor/programs/token-swap/src/instructions/create_config.rs +++ b/finance/token-swap/anchor/programs/token-swap/src/instructions/initialize_config.rs @@ -6,8 +6,8 @@ use crate::{ state::Config, }; -pub fn handle_create_config( - context: Context, +pub fn handle_initialize_config( + context: Context, fee: u16, admin_share_bps: u16, ) -> Result<()> { @@ -23,7 +23,7 @@ pub fn handle_create_config( #[derive(Accounts)] #[instruction(fee: u16, admin_share_bps: u16)] -pub struct CreateConfigAccountConstraints<'info> { +pub struct InitializeConfigAccountConstraints<'info> { #[account( init, payer = payer, diff --git a/finance/token-swap/anchor/programs/token-swap/src/instructions/create_pool.rs b/finance/token-swap/anchor/programs/token-swap/src/instructions/initialize_pool.rs similarity index 94% rename from finance/token-swap/anchor/programs/token-swap/src/instructions/create_pool.rs rename to finance/token-swap/anchor/programs/token-swap/src/instructions/initialize_pool.rs index a35db330f..4a869c743 100644 --- a/finance/token-swap/anchor/programs/token-swap/src/instructions/create_pool.rs +++ b/finance/token-swap/anchor/programs/token-swap/src/instructions/initialize_pool.rs @@ -10,7 +10,7 @@ use crate::{ state::{Config, PoolConfig}, }; -pub fn handle_create_pool(context: Context) -> Result<()> { +pub fn handle_initialize_pool(context: Context) -> Result<()> { let bump = context.bumps.pool_config; let pool_config = &mut context.accounts.pool_config; pool_config.config = context.accounts.config.key(); @@ -22,7 +22,7 @@ pub fn handle_create_pool(context: Context) -> Res } #[derive(Accounts)] -pub struct CreatePoolAccountConstraints<'info> { +pub struct InitializePoolAccountConstraints<'info> { #[account( seeds = [CONFIG_SEED], bump, diff --git a/finance/token-swap/anchor/programs/token-swap/src/instructions/mod.rs b/finance/token-swap/anchor/programs/token-swap/src/instructions/mod.rs index 74505d5e7..fd4e825c8 100644 --- a/finance/token-swap/anchor/programs/token-swap/src/instructions/mod.rs +++ b/finance/token-swap/anchor/programs/token-swap/src/instructions/mod.rs @@ -1,13 +1,13 @@ mod admin; -mod create_config; -mod create_pool; +mod initialize_config; +mod initialize_pool; mod deposit_liquidity; mod swap_tokens; mod withdraw_liquidity; pub use admin::*; -pub use create_config::*; -pub use create_pool::*; +pub use initialize_config::*; +pub use initialize_pool::*; pub use deposit_liquidity::*; pub use swap_tokens::*; pub use withdraw_liquidity::*; diff --git a/finance/token-swap/anchor/programs/token-swap/src/lib.rs b/finance/token-swap/anchor/programs/token-swap/src/lib.rs index 2f5d10ce4..780516598 100644 --- a/finance/token-swap/anchor/programs/token-swap/src/lib.rs +++ b/finance/token-swap/anchor/programs/token-swap/src/lib.rs @@ -12,16 +12,16 @@ pub mod swap_example { pub use super::instructions::*; use super::*; - pub fn create_config( - context: Context, + pub fn initialize_config( + context: Context, fee: u16, admin_share_bps: u16, ) -> Result<()> { - instructions::handle_create_config(context, fee, admin_share_bps) + instructions::handle_initialize_config(context, fee, admin_share_bps) } - pub fn create_pool(context: Context) -> Result<()> { - instructions::handle_create_pool(context) + pub fn initialize_pool(context: Context) -> Result<()> { + instructions::handle_initialize_pool(context) } pub fn deposit_liquidity( diff --git a/finance/token-swap/anchor/programs/token-swap/src/state/config.rs b/finance/token-swap/anchor/programs/token-swap/src/state/config.rs index 6272ecdac..ff005d9d0 100644 --- a/finance/token-swap/anchor/programs/token-swap/src/state/config.rs +++ b/finance/token-swap/anchor/programs/token-swap/src/state/config.rs @@ -25,7 +25,7 @@ pub struct Config { /// reserves and grows the LP-claimable balance). /// /// Modelled on Uniswap V2 / Raydium: the AMM operator takes a slice of - /// every fee, LPs keep the rest. Set in `create_config`; fixed for the + /// every fee, LPs keep the rest. Set in `initialize_config`; fixed for the /// lifetime of the program. Must be `< 10_000`. pub admin_share_bps: u16, diff --git a/finance/token-swap/anchor/programs/token-swap/tests/test_swap.rs b/finance/token-swap/anchor/programs/token-swap/tests/test_swap.rs index 531b109bd..14820efa3 100644 --- a/finance/token-swap/anchor/programs/token-swap/tests/test_swap.rs +++ b/finance/token-swap/anchor/programs/token-swap/tests/test_swap.rs @@ -125,10 +125,10 @@ fn full_setup() -> TestSetup { mint_tokens_to_token_account(&mut svm, &mint_b, &holder_account_b, minted_amount, &admin).unwrap(); // Create AMM - let create_config_ix = Instruction::new_with_bytes( + let initialize_config_ix = Instruction::new_with_bytes( program_id, - &swap_example::instruction::CreateConfig { fee, admin_share_bps }.data(), - swap_example::accounts::CreateConfigAccountConstraints { + &swap_example::instruction::InitializeConfig { fee, admin_share_bps }.data(), + swap_example::accounts::InitializeConfigAccountConstraints { config: config_key, admin: admin.pubkey(), payer: payer.pubkey(), @@ -138,17 +138,17 @@ fn full_setup() -> TestSetup { ); send_transaction_from_instructions( &mut svm, - vec![create_config_ix], + vec![initialize_config_ix], &[&payer], &payer.pubkey(), ) .unwrap(); // Create Pool - let create_pool_ix = Instruction::new_with_bytes( + let initialize_pool_ix = Instruction::new_with_bytes( program_id, - &swap_example::instruction::CreatePool {}.data(), - swap_example::accounts::CreatePoolAccountConstraints { + &swap_example::instruction::InitializePool {}.data(), + swap_example::accounts::InitializePoolAccountConstraints { config: config_key, pool_config: pool_config_key, pool_authority, @@ -166,7 +166,7 @@ fn full_setup() -> TestSetup { ); send_transaction_from_instructions( &mut svm, - vec![create_pool_ix], + vec![initialize_pool_ix], &[&payer], &payer.pubkey(), ) @@ -192,7 +192,7 @@ fn full_setup() -> TestSetup { } #[test] -fn test_create_config() { +fn test_initialize_config() { let (mut svm, program_id, payer) = setup(); let fee: u16 = 500; let admin_share_bps: u16 = 1667; @@ -200,10 +200,10 @@ fn test_create_config() { let (config_key, _) = Pubkey::find_program_address(&[b"config"], &program_id); - let create_config_ix = Instruction::new_with_bytes( + let initialize_config_ix = Instruction::new_with_bytes( program_id, - &swap_example::instruction::CreateConfig { fee, admin_share_bps }.data(), - swap_example::accounts::CreateConfigAccountConstraints { + &swap_example::instruction::InitializeConfig { fee, admin_share_bps }.data(), + swap_example::accounts::InitializeConfigAccountConstraints { config: config_key, admin: admin.pubkey(), payer: payer.pubkey(), @@ -214,7 +214,7 @@ fn test_create_config() { send_transaction_from_instructions( &mut svm, - vec![create_config_ix], + vec![initialize_config_ix], &[&payer], &payer.pubkey(), ) diff --git a/finance/token-swap/kani-proofs/src/lib.rs b/finance/token-swap/kani-proofs/src/lib.rs index 8f6101f43..97f889086 100644 --- a/finance/token-swap/kani-proofs/src/lib.rs +++ b/finance/token-swap/kani-proofs/src/lib.rs @@ -29,7 +29,7 @@ pub const MINIMUM_LIQUIDITY: u128 = 100; /// `handle_swap_tokens`. Returns `None` on the same overflow paths the program /// maps to `AmmError::MathOverflow`. /// -/// `fee_bps` and `admin_share_bps` are validated `< 10_000` in `create_config`. +/// `fee_bps` and `admin_share_bps` are validated `< 10_000` in `initialize_config`. pub fn fee_split(input_amount: u64, fee_bps: u16, admin_share_bps: u16) -> Option<(u64, u64, u64)> { let fee_amount = (input_amount as u128) .checked_mul(fee_bps as u128)? @@ -60,7 +60,7 @@ fn proof_fee_split_bounds() { // fee fractions `fee_bps` / `admin_share_bps` remain fully symbolic over // their entire valid range, so the rounding behaviour is covered exactly. kani::assume(input <= 4095); - // create_config enforces both `< 10_000`. + // initialize_config enforces both `< 10_000`. kani::assume((fee_bps as u128) < BASIS_POINTS_DIVISOR); kani::assume((admin_share_bps as u128) < BASIS_POINTS_DIVISOR); diff --git a/finance/token-swap/quasar/src/error.rs b/finance/token-swap/quasar/src/error.rs index 3f713d5cf..ddc971324 100644 --- a/finance/token-swap/quasar/src/error.rs +++ b/finance/token-swap/quasar/src/error.rs @@ -2,13 +2,13 @@ use quasar_lang::prelude::*; #[error_code] pub enum AmmError { - /// `create_config` was called with `fee >= 10_000` basis points (a fee of + /// `initialize_config` was called with `fee >= 10_000` basis points (a fee of /// 100% or more would consume the whole input). // 6000 is the conventional Anchor-compatible starting offset for // program-specific error codes (Quasar's #[error_code] starts at 0 // unless told otherwise; framework errors occupy 3000+). InvalidFee = 6000, - /// `create_config` was called with `admin_share_bps >= 10_000`. The admin + /// `initialize_config` was called with `admin_share_bps >= 10_000`. The admin /// share is a basis-points fraction of the trading fee, so the admin /// cannot take more than the whole fee. AdminShareTooHigh, diff --git a/finance/token-swap/quasar/src/instructions/create_config.rs b/finance/token-swap/quasar/src/instructions/initialize_config.rs similarity index 90% rename from finance/token-swap/quasar/src/instructions/create_config.rs rename to finance/token-swap/quasar/src/instructions/initialize_config.rs index b986ff1c0..2b7dc768b 100644 --- a/finance/token-swap/quasar/src/instructions/create_config.rs +++ b/finance/token-swap/quasar/src/instructions/initialize_config.rs @@ -7,7 +7,7 @@ use { /// at the fixed seed `b"config"`. There is no `id` parameter - calling this /// twice for the same program will fail because the account already exists. #[derive(Accounts)] -pub struct CreateConfigAccountConstraints { +pub struct InitializeConfigAccountConstraints { #[account(mut, init, payer = payer, address = ConfigPda::seeds())] pub config: Account, /// Admin authority for the AMM. @@ -18,8 +18,8 @@ pub struct CreateConfigAccountConstraints { } #[inline(always)] -pub fn handle_create_config( - accounts: &mut CreateConfigAccountConstraints, +pub fn handle_initialize_config( + accounts: &mut InitializeConfigAccountConstraints, fee: u16, admin_share_bps: u16, ) -> Result<(), ProgramError> { diff --git a/finance/token-swap/quasar/src/instructions/create_pool.rs b/finance/token-swap/quasar/src/instructions/initialize_pool.rs similarity index 94% rename from finance/token-swap/quasar/src/instructions/create_pool.rs rename to finance/token-swap/quasar/src/instructions/initialize_pool.rs index 5f1d90424..41f495b8a 100644 --- a/finance/token-swap/quasar/src/instructions/create_pool.rs +++ b/finance/token-swap/quasar/src/instructions/initialize_pool.rs @@ -16,7 +16,7 @@ use { /// onchain addresses than the Anchor sibling because `#[derive(Seeds)]` /// emits the literal prefix first. Internally consistent within this program. #[derive(Accounts)] -pub struct CreatePoolAccountConstraints { +pub struct InitializePoolAccountConstraints { #[account(address = ConfigPda::seeds())] pub config: Account, #[account( @@ -66,7 +66,7 @@ pub struct CreatePoolAccountConstraints { } #[inline(always)] -pub fn handle_create_pool(accounts: &mut CreatePoolAccountConstraints) -> Result<(), ProgramError> { +pub fn handle_initialize_pool(accounts: &mut InitializePoolAccountConstraints) -> Result<(), ProgramError> { accounts.pool_config.set_inner(PoolConfigInner { config: *accounts.config.address(), mint_a: *accounts.mint_a.address(), diff --git a/finance/token-swap/quasar/src/instructions/mod.rs b/finance/token-swap/quasar/src/instructions/mod.rs index c0a9ab8cd..8e143cedb 100644 --- a/finance/token-swap/quasar/src/instructions/mod.rs +++ b/finance/token-swap/quasar/src/instructions/mod.rs @@ -1,13 +1,13 @@ mod claim_admin_fees; -mod create_config; -mod create_pool; +mod initialize_config; +mod initialize_pool; mod deposit_liquidity; mod swap_tokens; mod withdraw_liquidity; pub use claim_admin_fees::*; -pub use create_config::*; -pub use create_pool::*; +pub use initialize_config::*; +pub use initialize_pool::*; pub use deposit_liquidity::*; pub use swap_tokens::*; pub use withdraw_liquidity::*; diff --git a/finance/token-swap/quasar/src/lib.rs b/finance/token-swap/quasar/src/lib.rs index 197d63bf6..4760b2ed3 100644 --- a/finance/token-swap/quasar/src/lib.rs +++ b/finance/token-swap/quasar/src/lib.rs @@ -58,9 +58,9 @@ pub struct LiquidityMintPda; /// Simple constant-product AMM (token swap). /// /// Six instructions: -/// 1. `create_config` - initialise the singleton AMM config (admin, fee, +/// 1. `initialize_config` - initialise the singleton AMM config (admin, fee, /// admin share) -/// 2. `create_pool` - create a liquidity pool for a token pair +/// 2. `initialize_pool` - create a liquidity pool for a token pair /// 3. `deposit_liquidity` - add liquidity and receive LP tokens /// 4. `withdraw_liquidity` - burn LP tokens and receive pool tokens /// 5. `swap_tokens` - swap one token for another @@ -70,17 +70,17 @@ mod quasar_token_swap { use super::*; #[instruction(discriminator = 0)] - pub fn create_config( - ctx: Ctx, + pub fn initialize_config( + ctx: Ctx, fee: u16, admin_share_bps: u16, ) -> Result<(), ProgramError> { - instructions::handle_create_config(&mut ctx.accounts, fee, admin_share_bps) + instructions::handle_initialize_config(&mut ctx.accounts, fee, admin_share_bps) } #[instruction(discriminator = 1)] - pub fn create_pool(ctx: Ctx) -> Result<(), ProgramError> { - instructions::handle_create_pool(&mut ctx.accounts) + pub fn initialize_pool(ctx: Ctx) -> Result<(), ProgramError> { + instructions::handle_initialize_pool(&mut ctx.accounts) } #[instruction(discriminator = 2)] diff --git a/finance/token-swap/quasar/src/tests.rs b/finance/token-swap/quasar/src/tests.rs index 317f1fe4f..bf53e3396 100644 --- a/finance/token-swap/quasar/src/tests.rs +++ b/finance/token-swap/quasar/src/tests.rs @@ -5,7 +5,7 @@ use { crate::{ cpi::{ - ClaimAdminFeesInstruction, CreateConfigInstruction, CreatePoolInstruction, + ClaimAdminFeesInstruction, InitializeConfigInstruction, InitializePoolInstruction, DepositLiquidityInstruction, SwapTokensInstruction, WithdrawLiquidityInstruction, }, error::AmmError, @@ -38,7 +38,7 @@ fn expected_swap_output(input: u64, fee_bps: u64, pool_in: u64, pool_out: u64) - mul_div(taxed_input, pool_out, divisor) } -/// Trading fee passed to `create_config`, in basis points. +/// Trading fee passed to `initialize_config`, in basis points. const POOL_FEE_BPS: u64 = 30; /// Admin's share of the trading fee, in basis points. const ADMIN_SHARE_BPS: u16 = 1_667; @@ -78,9 +78,9 @@ struct PoolEnv { lp_mint: Pubkey, } -fn create_config(test: &mut Test, fee: u16, admin_share_bps: u16) -> Outcome { +fn initialize_config(test: &mut Test, fee: u16, admin_share_bps: u16) -> Outcome { test.add(Wallet::new().at(PAYER)); - test.send(CreateConfigInstruction { + test.send(InitializeConfigInstruction { admin: ADMIN, payer: PAYER, fee, @@ -90,16 +90,16 @@ fn create_config(test: &mut Test, fee: u16, admin_share_bps: u16) -> Outcome { /// Creates config + two mints + pool. fn setup_pool(test: &mut Test) -> PoolEnv { - create_config(test, POOL_FEE_BPS as u16, ADMIN_SHARE_BPS).succeeds(); + initialize_config(test, POOL_FEE_BPS as u16, ADMIN_SHARE_BPS).succeeds(); // Pre-populate mint accounts (no onchain minting needed for tests). test.add(Mint::new(PAYER).at(MINT_A).decimals(6)); test.add(Mint::new(PAYER).at(MINT_B).decimals(6)); - // create_pool: the pool_config, pool authority, and LP-mint PDAs are + // initialize_pool: the pool_config, pool authority, and LP-mint PDAs are // derived by the builder; pool_a/pool_b are non-PDA token accounts the // program creates at the given addresses. - test.send(CreatePoolInstruction { + test.send(InitializePoolInstruction { mint_a: MINT_A, mint_b: MINT_B, pool_a: POOL_A, @@ -195,11 +195,11 @@ fn claim_fees(test: &mut Test, admin: Pubkey, admin_token_a: Pubkey, admin_token }) } -// ─── create_config ─────────────────────────────────────────────────────────── +// ─── initialize_config ─────────────────────────────────────────────────────────── #[quasar_test] -fn create_config_records_admin_and_fees(test: &mut Test) { - create_config(test, 30, 1_667).succeeds(); +fn initialize_config_records_admin_and_fees(test: &mut Test) { + initialize_config(test, 30, 1_667).succeeds(); let config = test.derive_pda(ConfigPda::seeds()); let state = test.read::(config); @@ -209,32 +209,32 @@ fn create_config_records_admin_and_fees(test: &mut Test) { } #[quasar_test] -fn create_config_rejects_invalid_fee(test: &mut Test) { +fn initialize_config_rejects_invalid_fee(test: &mut Test) { // fee >= 10_000 → invalid. - let outcome = create_config(test, 10_000, 1_667); + let outcome = initialize_config(test, 10_000, 1_667); assert!( outcome.is_err(), - "create_config should have failed with invalid fee" + "initialize_config should have failed with invalid fee" ); } #[quasar_test] -fn create_config_rejects_invalid_admin_share(test: &mut Test) { +fn initialize_config_rejects_invalid_admin_share(test: &mut Test) { // admin_share_bps >= 10_000 → invalid. - let outcome = create_config(test, 30, 10_000); + let outcome = initialize_config(test, 30, 10_000); assert!( outcome.is_err(), - "create_config should have failed with admin_share_bps >= 10000" + "initialize_config should have failed with admin_share_bps >= 10000" ); } -// ─── create_pool ───────────────────────────────────────────────────────────── +// ─── initialize_pool ───────────────────────────────────────────────────────────── #[quasar_test] -fn create_pool_creates_pool_config_and_lp_mint(test: &mut Test) { +fn initialize_pool_creates_pool_config_and_lp_mint(test: &mut Test) { let env = setup_pool(test); // The pool_config PDA must now exist and be owned by our program. - let pc = test.account(env.pool_config).expect("pool_config missing after create_pool"); + let pc = test.account(env.pool_config).expect("pool_config missing after initialize_pool"); assert_eq!(pc.owner, test.program_id()); // LP mint PDA must be a valid SPL mint (82 bytes, owned by token program). let lp = test.account(env.lp_mint).expect("lp_mint missing");