feat(defi): add asset-leasing example (Anchor + Quasar)#39
Open
mikemaccana wants to merge 2 commits into
Open
Conversation
ae9250a to
f332fcf
Compare
Adds a new defi/asset-leasing example demonstrating onchain securities lending — the same primitive that underpins TradFi stock-loan desks — with two full implementations: **Anchor** (defi/asset-leasing/anchor/) - Seven instruction handlers covering the complete bilateral lease lifecycle: create_lease → take_lease → pay_lease_fee / top_up_collateral → return_lease / liquidate / close_expired. - PDA-backed leased and collateral vaults; per-second fee accrual via last_paid_timestamp; Pyth PriceUpdateV2 staleness + feed-id guard on liquidation; Token-2022 compatible via TokenInterface. - LiteSVM integration test suite (11 tests) covering every handler, error path, and branch scenario. **Quasar port** (defi/asset-leasing/quasar/) - Same seven handlers, same Lease state layout (byte-for-byte compatible with the Anchor version), same PDA seed conventions. - Differs from the Anchor version in: one-byte explicit discriminators, no init_if_needed ATA creation, classic Token only (not Token-2022), one active lease per holder (no lease_id in PDA seed). **README** (defi/asset-leasing/anchor/README.md) - Explains the securities-lending model for readers unfamiliar with finance; Investopedia links on every financial term at first mention. - Program flow section with three named participants: Alice (holder, earns yield on idle inventory), Bob (short seller, bearish thesis on NVIDIA), and Carol (keeper bot, earns liquidation bounty). Uses USDC and NVDAx as primary example tokens; TSLAx noted as a parallel case. - Each lifecycle step lists the instruction handler called and every account that changes, with before/after values in table form. - Complete lifecycle reference with exact numbers that match the LiteSVM tests one-to-one. - Bilateral vs pooled lending comparison. - Safety and edge-case section covering all error variants and deliberate design trade-offs. https://claude.ai/code/session_01Etk82ApiAusLAUezvmzVts
f332fcf to
f93f93d
Compare
mikejhale
approved these changes
Jun 2, 2026
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.
Summary
Adds a new
defi/asset-leasingexample demonstrating onchain securities lending — the same bilateral deal structure used by TradFi stock-loan desks — with two full implementations.Anchor (
defi/asset-leasing/anchor/)Seven instruction handlers covering the complete bilateral lease lifecycle:
create_lease→take_lease→pay_lease_fee/top_up_collateral→return_lease/liquidate/close_expiredlast_paid_timestampPriceUpdateV2staleness + feed-id pinning guard on liquidationTokenInterfaceQuasar port (
defi/asset-leasing/quasar/)Same seven handlers, same
Leasestate layout (byte-for-byte compatible with the Anchor version), same PDA seed conventions. Differences: one-byte explicit discriminators, noinit_if_neededATA creation, classic Token only, one active lease per holder.README (
defi/asset-leasing/anchor/README.md)Test plan
cargo check --libindefi/asset-leasing/anchor/programs/asset-leasing(verified clean locally)anchor build && anchor testin the Anchor workspacecargo testin the Quasar workspacehttps://claude.ai/code/session_01Etk82ApiAusLAUezvmzVts