Skip to content

Token Swap (Quasar): create the reserves at PDAs of the pool - #181

Merged
mikemaccana merged 1 commit into
mainfrom
claude/eager-edison-p09qzu
Oct 2, 2026
Merged

mikemaccana merged 1 commit into
mainfrom
claude/eager-edison-p09qzu

Conversation

@mikemaccana

Copy link
Copy Markdown
Collaborator

Follow-up to #180, which bound the Quasar token-swap's reserves to the pool with has_one.

What changed

pool_a and pool_b were 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 an init without address = X::seeds(..) is an account at a generated public key. Here there was no size reason.

  • New seeds markers PoolAPda ([b"pool_a", pool_config]) and PoolBPda ([b"pool_b", pool_config]) in lib.rs.
  • initialize_pool creates both reserves at those PDAs with init (was init(idempotent) at a client-chosen address). The generated instruction builder now derives them, so clients no longer pass them.
  • PoolConfig still records both addresses, and deposit_liquidity, withdraw_liquidity, swap_tokens and claim_admin_fees still check them with has_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.
  • Tests derive the reserves from the pool's address instead of using fixed addresses. initialize_pool_creates_pool_config_and_lp_mint now 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.
  • Both CHANGELOGs updated.

Testing

Run in finance/token-swap/quasar with the Quasar CLI at be60fca and Agave 3.1.14 (platform-tools v1.52), as .github/workflows/quasar.yml does:

  • quasar build: clean (binary 1.1 KB smaller).
  • cargo test: 21 passed.
  • cargo fmt --check and cargo 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

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
@mikemaccana
mikemaccana merged commit 414ad54 into main Oct 2, 2026
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant