Token Swap (Quasar): create the reserves at PDAs of the pool - #181
Merged
Merged
Conversation
pool_a and pool_b were token accounts at addresses the client chose, which the companion AI plugin's PDA rule counts as a finding: a client could only find a pool's reserves by reading PoolConfig. They now live at [b"pool_a", pool_config] and [b"pool_b", pool_config] (PoolAPda, PoolBPda), created with init, as the order book's Quasar version does for its vaults. PoolConfig still records both addresses and every handler still checks them with has_one, so the substitution tests are unchanged. The tests derive the reserves instead of using fixed addresses, and initialize_pool's instruction builder now derives them too. Claude-Session: https://claude.ai/code/session_01BvopS6WYzsT9Qf32NTu29V
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #180, which bound the Quasar token-swap's reserves to the pool with
has_one.What changed
pool_aandpool_bwere token accounts at addresses the client chose. The companion AI plugin's PDA Management rule (skills/solana/RUST.md) counts that as a finding: every account a program creates lives at a PDA unless size stops it, and aninitwithoutaddress = X::seeds(..)is an account at a generated public key. Here there was no size reason.PoolAPda([b"pool_a", pool_config]) andPoolBPda([b"pool_b", pool_config]) inlib.rs.initialize_poolcreates both reserves at those PDAs withinit(wasinit(idempotent)at a client-chosen address). The generated instruction builder now derives them, so clients no longer pass them.PoolConfigstill records both addresses, anddeposit_liquidity,withdraw_liquidity,swap_tokensandclaim_admin_feesstill check them withhas_one, which is the pattern the order book's Quasar version uses for its vaults.PoolConfig's layout is unchanged from Bind pool reserves to PoolConfig and validate them in handlers #180.initialize_pool_creates_pool_config_and_lp_mintnow finds them at the PDAs, and every deposit, swap and withdraw test passing shows the recorded addresses match the PDAs. The substitution tests from Bind pool reserves to PoolConfig and validate them in handlers #180 are unchanged.Testing
Run in
finance/token-swap/quasarwith the Quasar CLI atbe60fcaand Agave 3.1.14 (platform-tools v1.52), as.github/workflows/quasar.ymldoes:quasar build: clean (binary 1.1 KB smaller).cargo test: 21 passed.cargo fmt --checkandcargo clippy -- -D warnings -A clippy::diverging_sub_expression(also with--all-targets): clean.🤖 Generated with Claude Code
https://claude.ai/code/session_01BvopS6WYzsT9Qf32NTu29V
Generated by Claude Code