Skip to content

Commit f5ebe0e

Browse files
author
Edward (OpenClaw)
committed
docs(asset-leasing): convert markdown tables to bullet lists
Converts all 6 markdown tables in defi/asset-leasing/anchor/README.md to bullet lists (parameter-values example, state/data accounts, token vaults, user accounts, error catalogue, test matrix). Tables don't render cleanly on viewers narrower or wider than ~76 chars (mobile, terminal, narrow editor split); bullet lists work everywhere. No information lost; wider account tables rewritten as natural prose rather than mechanical column-by-column key/value bullets.
1 parent 53c7937 commit f5ebe0e

1 file changed

Lines changed: 47 additions & 59 deletions

File tree

defi/asset-leasing/anchor/README.md

Lines changed: 47 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,13 @@ Bob wants short exposure to NVIDIA without using a perpetual future.
114114
Alice lists the lease (assume USDC is 6-decimal, xNVDA is also
115115
6-decimal for round numbers):
116116

117-
| Parameter | Value | Notes |
118-
|---|---|---|
119-
| `leased_amount` | `100_000_000` (100 xNVDA) | |
120-
| `required_collateral_amount` | `22_000_000_000` (22 000 USDC) | ~122% LTV at the spot price |
121-
| `lease_fee_per_second` | `456` (USDC base units / s) | ≈ 8% APR on 18 000 USDC notional |
122-
| `duration_seconds` | `2_592_000` | 30 days |
123-
| `maintenance_margin_basis_points` | `11_000` | 110% |
124-
| `liquidation_bounty_basis_points` | `100` | 1% of post-fee collateral |
125-
| `feed_id` | Pyth xNVDA/USD feed id | ([Pyth feed registry](https://www.pyth.network/price-feeds)) |
117+
- **`leased_amount`**: `100_000_000` (100 xNVDA)
118+
- **`required_collateral_amount`**: `22_000_000_000` (22 000 USDC) - ~122% LTV at the spot price
119+
- **`lease_fee_per_second`**: `456` (USDC base units / s) - ≈ 8% APR on 18 000 USDC notional
120+
- **`duration_seconds`**: `2_592_000` - 30 days
121+
- **`maintenance_margin_basis_points`**: `11_000` - 110%
122+
- **`liquidation_bounty_basis_points`**: `100` - 1% of post-fee collateral
123+
- **`feed_id`**: Pyth xNVDA/USD feed id ([Pyth feed registry](https://www.pyth.network/price-feeds))
126124

127125
Bob calls `take_lease`, posts 22 000 USDC, receives 100 xNVDA, and
128126
sells the 100 xNVDA on Jupiter for ~18 000 USDC at the spot price.
@@ -183,31 +181,25 @@ are created on `create_lease` and destroyed on `return_lease` /
183181

184182
### State / data accounts
185183

186-
| Account | program-derived address? | Seeds | Kind | Authority | Holds |
187-
|---|---|---|---|---|---|
188-
| `Lease` | yes | `["lease", holder, lease_id]` | data | program | all the lease parameters and current lifecycle state (see below) |
184+
- **`Lease`** - program-derived address with seeds `["lease", holder, lease_id]`. Data account owned by the program, holding all the lease parameters and current lifecycle state (see below).
189185

190186
### Token vaults
191187

192-
| Account | program-derived address? | Seeds | Kind | Authority | Holds |
193-
|---|---|---|---|---|---|
194-
| `leased_vault` | yes | `["leased_vault", lease]` | token account | itself (program-derived address-signed) | `leased_amount` while `Listed`; 0 while `Active` (short seller has the tokens); full amount again briefly inside `return_lease` |
195-
| `collateral_vault` | yes | `["collateral_vault", lease]` | token account | itself (program-derived address-signed) | 0 while `Listed`; `collateral_amount` while `Active`, decreasing as lease fee streams out and increasing on `top_up_collateral` |
188+
- **`leased_vault`** - program-derived address with seeds `["leased_vault", lease]`. Token account whose authority is itself (program-derived-address-signed). Holds `leased_amount` while `Listed`; `0` while `Active` (the short seller has the tokens); full amount again briefly inside `return_lease`.
189+
- **`collateral_vault`** - program-derived address with seeds `["collateral_vault", lease]`. Token account whose authority is itself (program-derived-address-signed). Holds `0` while `Listed`; `collateral_amount` while `Active`, decreasing as lease fee streams out and increasing on `top_up_collateral`.
196190

197191
### User accounts passed in
198192

199-
| Account | Owner | Purpose |
200-
|---|---|---|
201-
| `holder` wallet | user | `create_lease` signer, receives the lease fee and final recovery |
202-
| `short_seller` wallet | user | `take_lease` / `top_up_collateral` / `return_lease` signer |
203-
| `keeper` wallet | user | `liquidate` signer, receives the bounty |
204-
| `payer` wallet | user | `pay_lease_fee` signer (can be anyone, not just the short seller) |
205-
| `holder_leased_account` | token account | holder's [associated token account](https://solana.com/docs/terminology) for the leased mint; source on `create_lease`, destination on `return_lease` / `close_expired` |
206-
| `holder_collateral_account` | token account | holder's associated token account for the collateral mint; destination for the lease fee and liquidation proceeds |
207-
| `short_seller_leased_account` | token account | short seller's associated token account for the leased mint; destination on `take_lease`, source on `return_lease` |
208-
| `short_seller_collateral_account` | token account | short seller's associated token account for the collateral mint; source on `take_lease` / `top_up_collateral`, destination for collateral refund on `return_lease` |
209-
| `keeper_collateral_account` | token account | keeper's associated token account for the collateral mint; receives the liquidation bounty |
210-
| `price_update` | Pyth Receiver program | `PriceUpdateV2` account for the feed the lease is pinned to |
193+
- **`holder` wallet** (user-owned) - `create_lease` signer, receives the lease fee and final recovery.
194+
- **`short_seller` wallet** (user-owned) - `take_lease` / `top_up_collateral` / `return_lease` signer.
195+
- **`keeper` wallet** (user-owned) - `liquidate` signer, receives the bounty.
196+
- **`payer` wallet** (user-owned) - `pay_lease_fee` signer (can be anyone, not just the short seller).
197+
- **`holder_leased_account`** - holder's [associated token account](https://solana.com/docs/terminology) for the leased mint; source on `create_lease`, destination on `return_lease` / `close_expired`.
198+
- **`holder_collateral_account`** - holder's associated token account for the collateral mint; destination for the lease fee and liquidation proceeds.
199+
- **`short_seller_leased_account`** - short seller's associated token account for the leased mint; destination on `take_lease`, source on `return_lease`.
200+
- **`short_seller_collateral_account`** - short seller's associated token account for the collateral mint; source on `take_lease` / `top_up_collateral`, destination for collateral refund on `return_lease`.
201+
- **`keeper_collateral_account`** - keeper's associated token account for the collateral mint; receives the liquidation bounty.
202+
- **`price_update`** - `PriceUpdateV2` account owned by the Pyth Receiver program, for the feed the lease is pinned to.
211203

212204
### Fields on `Lease`
213205

@@ -743,24 +735,22 @@ All of the following come from [`errors.rs`](programs/asset-leasing/src/errors.r
743735
and are enforced by either an Anchor constraint or a `require!` in the
744736
handler:
745737

746-
| Error | When |
747-
|---|---|
748-
| `InvalidLeaseStatus` | Action tried against a lease in the wrong state (e.g. `take_lease` on a lease that is already `Active`) |
749-
| `InvalidDuration` | `duration_seconds <= 0` on `create_lease` |
750-
| `InvalidLeasedAmount` | `leased_amount == 0` on `create_lease` |
751-
| `InvalidCollateralAmount` | `required_collateral_amount == 0` on `create_lease`; `amount == 0` on `top_up_collateral` |
752-
| `InvalidLeaseFeePerSecond` | `lease_fee_per_second == 0` on `create_lease` |
753-
| `InvalidMaintenanceMargin` | `maintenance_margin_basis_points == 0` or `> 50_000` on `create_lease` |
754-
| `InvalidLiquidationBounty` | `liquidation_bounty_basis_points > 2_000` on `create_lease` |
755-
| `LeaseExpired` | Reserved; not currently used (lease fee accrual naturally caps at `end_timestamp`) |
756-
| `LeaseNotExpired` | `close_expired` called on an `Active` lease before `end_timestamp` |
757-
| `PositionHealthy` | `liquidate` called on a lease that passes the maintenance-margin check |
758-
| `StalePrice` | Pyth price update older than 60 s, or has a future `publish_time`, or fails discriminator / length check |
759-
| `NonPositivePrice` | Pyth price is `<= 0` |
760-
| `MathOverflow` | Any of the `checked_*` arithmetic returned `None` |
761-
| `Unauthorised` | Lease-modifying handler called by someone who is not the registered short seller (`top_up_collateral`, `return_lease`) |
762-
| `LeasedMintEqualsCollateralMint` | `create_lease` called with the same mint for both sides |
763-
| `PriceFeedMismatch` | `liquidate` called with a Pyth update whose `feed_id` does not match `lease.feed_id` |
738+
- **`InvalidLeaseStatus`** - action tried against a lease in the wrong state (e.g. `take_lease` on a lease that is already `Active`).
739+
- **`InvalidDuration`** - `duration_seconds <= 0` on `create_lease`.
740+
- **`InvalidLeasedAmount`** - `leased_amount == 0` on `create_lease`.
741+
- **`InvalidCollateralAmount`** - `required_collateral_amount == 0` on `create_lease`; `amount == 0` on `top_up_collateral`.
742+
- **`InvalidLeaseFeePerSecond`** - `lease_fee_per_second == 0` on `create_lease`.
743+
- **`InvalidMaintenanceMargin`** - `maintenance_margin_basis_points == 0` or `> 50_000` on `create_lease`.
744+
- **`InvalidLiquidationBounty`** - `liquidation_bounty_basis_points > 2_000` on `create_lease`.
745+
- **`LeaseExpired`** - reserved; not currently used (lease fee accrual naturally caps at `end_timestamp`).
746+
- **`LeaseNotExpired`** - `close_expired` called on an `Active` lease before `end_timestamp`.
747+
- **`PositionHealthy`** - `liquidate` called on a lease that passes the maintenance-margin check.
748+
- **`StalePrice`** - Pyth price update older than 60 s, or has a future `publish_time`, or fails discriminator / length check.
749+
- **`NonPositivePrice`** - Pyth price is `<= 0`.
750+
- **`MathOverflow`** - any of the `checked_*` arithmetic returned `None`.
751+
- **`Unauthorised`** - lease-modifying handler called by someone who is not the registered short seller (`top_up_collateral`, `return_lease`).
752+
- **`LeasedMintEqualsCollateralMint`** - `create_lease` called with the same mint for both sides.
753+
- **`PriceFeedMismatch`** - `liquidate` called with a Pyth update whose `feed_id` does not match `lease.feed_id`.
764754

765755
### 4.2 Guarded design choices worth knowing
766756

@@ -897,19 +887,17 @@ test top_up_collateral_increases_vault_balance ... ok
897887

898888
### What each test exercises
899889

900-
| Test | Exercises |
901-
|---|---|
902-
| `create_lease_locks_tokens_and_lists` | Holder funds vault, `Lease` created, collateral vault empty |
903-
| `create_lease_rejects_same_mint_for_leased_and_collateral` | Guard against `leased_mint == collateral_mint` |
904-
| `take_lease_posts_collateral_and_delivers_tokens` | Collateral deposit + leased-token payout in one instruction |
905-
| `pay_lease_fee_streams_collateral_by_elapsed_time` | Lease fee math: `elapsed * lease_fee_per_second`, lease fee transferred to holder |
906-
| `top_up_collateral_increases_vault_balance` | Collateral balance after `top_up` equals deposit + top-up |
907-
| `return_lease_refunds_unused_collateral` | Happy path round-trip - leased tokens returned, residual collateral refunded, accounts closed |
908-
| `liquidate_seizes_collateral_on_price_drop` | Price-induced underwater position → lease fee + bounty + holder share paid, accounts closed |
909-
| `liquidate_rejects_healthy_position` | Program refuses to liquidate a position that passes the margin check |
910-
| `liquidate_rejects_mismatched_price_feed` | Program refuses a `PriceUpdateV2` whose `feed_id``lease.feed_id` |
911-
| `close_expired_reclaims_collateral_after_end_timestamp` | Default path - holder seizes the collateral |
912-
| `close_expired_cancels_listed_lease` | Holder-initiated cancel of an unrented lease |
890+
- **`create_lease_locks_tokens_and_lists`** - holder funds vault, `Lease` created, collateral vault empty.
891+
- **`create_lease_rejects_same_mint_for_leased_and_collateral`** - guard against `leased_mint == collateral_mint`.
892+
- **`take_lease_posts_collateral_and_delivers_tokens`** - collateral deposit + leased-token payout in one instruction.
893+
- **`pay_lease_fee_streams_collateral_by_elapsed_time`** - lease fee math: `elapsed * lease_fee_per_second`, lease fee transferred to holder.
894+
- **`top_up_collateral_increases_vault_balance`** - collateral balance after `top_up` equals deposit + top-up.
895+
- **`return_lease_refunds_unused_collateral`** - happy path round-trip; leased tokens returned, residual collateral refunded, accounts closed.
896+
- **`liquidate_seizes_collateral_on_price_drop`** - price-induced underwater position; lease fee + bounty + holder share paid, accounts closed.
897+
- **`liquidate_rejects_healthy_position`** - program refuses to liquidate a position that passes the margin check.
898+
- **`liquidate_rejects_mismatched_price_feed`** - program refuses a `PriceUpdateV2` whose `feed_id` does not match `lease.feed_id`.
899+
- **`close_expired_reclaims_collateral_after_end_timestamp`** - default path; holder seizes the collateral.
900+
- **`close_expired_cancels_listed_lease`** - holder-initiated cancel of an unrented lease.
913901

914902
### Note on CI
915903

0 commit comments

Comments
 (0)