Lending: remove individual addresses from market and price-feed seeds#73
Merged
Conversation
A market keyed on the owner's address can only ever exist once per owner, which contradicts the multi-market isolation the program is meant to support, and is inconsistent with the repo's own convention (the order-book Market is seeded by its mint pair, not by an admin's address). LendingMarket is now seeded by a unique market_id (a client-chosen Pubkey, like token-swap's Amm); owner is a stored field and admin handlers authorize with has_one = owner. Reserves, obligations, and vaults already key off the market account address, so they're unchanged. Mirrored into the Quasar port (market_id passed as a reference account) and the test harnesses; READMEs/CHANGELOGs updated. https://claude.ai/code/session_01RwE8f8ahP5S6SDNTsXmpj9
Replaces the Pubkey market_id with a per-owner u64 index: the market PDA is now seeded by (owner, market_id), e.g. "owner's market 0". An integer is more readable than an opaque pubkey and needs no keypair; scoping it under the owner keeps each owner's index space collision-free without a global registry (a bare global integer would invite the same first-come land-grab the oracle fix removed). Applied to Anchor and Quasar (Quasar takes market_id as an instruction-data u64 seed, dropping the reference account), with test harnesses, READMEs, and CHANGELOGs updated. https://claude.ai/code/session_01RwE8f8ahP5S6SDNTsXmpj9
Markets and admin structs shouldn't be identified by a person's address. - LendingMarket is now seeded by ["lending_market", market_id] — a u64 index, no owner in the seed. owner remains a stored field and authorizes admin instructions via has_one = owner. - PriceFeed is now seeded by ["price_feed", market, mint] — scoped to a market, not to an individual. set_price requires the market's owner to sign, so prices can't be squatted, a reserve binds to its own market's feed, and isolated markets can price the same asset independently. Applied to both Anchor and Quasar, with test harnesses, READMEs, and CHANGELOGs updated. Anchor 22 tests + Quasar 6 tests pass; IDL build verified. https://claude.ai/code/session_01RwE8f8ahP5S6SDNTsXmpj9
The Solana skill's naming rule is to avoid abbreviations and use full words. Two Quasar comments shortened 'liquidation threshold' to 'liq threshold'; the Anchor side already spells it out. Align them. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RwE8f8ahP5S6SDNTsXmpj9
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 the merged lending example (#44). Markets and admin structs shouldn't be identified by an individual's address — this removes people's pubkeys from the PDA seeds.
Changes
LendingMarketis now seeded by["lending_market", market_id]— au64index, no owner in the seed.ownerstays a stored field and authorizes admin instructions viahas_one = owner. One owner can run several independent, risk-isolated markets (0, 1, 2 …).PriceFeedis now seeded by["price_feed", market, mint]— scoped to a market, not to any individual.set_pricerequires the market'sownerto sign, so prices can't be squatted, a reserve binds to its own market's feed, and isolated markets can price the same asset independently. (In production the feed is an external Switchboard account with no program seeds.)Scope
Applied to both the Anchor and Quasar programs, with test harnesses, READMEs, and CHANGELOGs updated.
Tests
Anchor: 22 tests pass (
cargo test); IDL build verified. Quasar: 6 tests pass. Build withanchor build/cargo-build-sbffirst so tests can load the.so.https://claude.ai/code/session_01RwE8f8ahP5S6SDNTsXmpj9
Generated by Claude Code