Kamino 백서

Kamino

원문

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 75쪽 중 65쪽

erage is a softer alternative to immediate liquidation. When a position crosses an unhealthy threshold, the curator (or an off-chain bot) marks it for deleveraging: the borrower receives a grace period to self-deleverage, and only after the grace period elapses does liquidation become available — at a ramped bonus that grows over time. This is a niche feature most curators leave disabled. Standard [Liquidations](/docs/curators/markets/liquidations) (immediate, threshold-triggered) are sufficient for most markets. Enable auto-deleverage when you specifically want a borrower-friendly margin-call window before liquidations open up. ## When this is useful | Curator profile | Recommendation | | - | - | | Public market with retail borrowers | Optional. The grace period is borrower-friendly but adds operational complexity | | Institutional / fixed-term market | Skip. Institutional borrowers prefer immediate, predictable liquidation behavior | | Stable-only / eMode-heavy market | Skip. Correlated-asset liquidations are small and fast | | Newly-listed volatile asset | Optional. If enabled, use a shorter `margin_call_period` (e.g., 4 hours) | ## Market-level enablement | Field | What it does | | - | - | | `autodeleverage_enabled` | Master switch. `1` enables auto-deleverage on the market | | `individual_autodeleverage_margin_call_period_secs` | Default grace period (seconds) between when a position is margin-called and when liquidation opens up. `86400` = 24 hours | | `insolvency_risk_unhealthy_ltv_pct` | LTV at which a position is considered to be in insolvency risk territory and may be marked for auto-deleverage. Default `100` | ## Reserve-level config | Field | What it does | | - | - | | `autodeleverage_enabled` | Per-reserve enablement. Both market and reserve must be `1` for auto-deleverage to apply to positions involving this reserve | | `deleveraging_margin_call_period_secs` | Per-reserve override for the margin-call period. `0` falls back to the market-level value | | `deleveraging_threshold_decrease_bps_per_day` | The position's effective liquidation threshold drops by this many bps per day after margin call. Allows liquidators in over time | | `deleveraging_bonus_increase_bps_per_day` | Liquidator bonus rises by this many bps per day after margin call. Compounds the incentive over time | | `min_deleveraging_bonus_bps` | Floor on the deleveraging-specific bonus | <Tabs> <Tab title="SDK"> ## Configure auto-deleverage via SDK Auto-deleverage is enabled through standard market and reserve config updates. ### Enable on the market ```typescript theme={null} import { KaminoManager, DEFAULT_RECENT_SLOT_DURATION_MS, PROGRAM_ID, MarketWithAddress, } from '@kamino-finance/klend-sdk'; import { LendingMarket } from '@kamino-finance/klend-sdk/dist/@codegen/klend/accounts'; import { address } from '@solana/kit'; const kaminoManager = new KaminoManager(rpc, DEFAULT_RECENT_SLOT_DURATION_MS, PROGRAM_ID); const marketState = await LendingMarket.fetch(rpc, marketAddress); if (!marketState) throw new Error('Market not found'); const marketWithAddress: MarketWithAddress = { address: marketAddress, state: marketState }; const newLendingMarket = { ...marketState }; newLendingMarket.autodeleverageEnabled = 1; newLendingMarket.individualAutodeleverageMarginCallPeriodSecs = 86_400n; // 24 hours newLendingMarket.insolvencyRiskUnhealthyLtvPct = 100; const ixs = kaminoManager.updateLendingMarketIxs(adminSigner, marketWithAddress, newLendingMarket); // submit each ix in order ``` ### Enable on a reserve ```typescript theme={null} import { Reserve } from '@kamino-finance/klend-sdk/dist/@codegen/klend/accounts'; const reserve = await Reserve.fetch(rpc, reserveAddress); if (!reserve) throw new Error('Reserve not found'); const newConfig = { ...reserve.config }; newConfig.autodeleverageEnabled = 1; newConfig.deleveragingMarginCallPeriodSecs = 0n; // 0 = use market default newConfig.deleveragingThresholdDecreaseBpsPerDay = 24n; // 0.24% per day newConfig.deleveragingBonusIncreaseBpsPerDay = 100n; // 1% per day newConfig.minDeleveragingBonusBps = 0; const updateIxs = await kaminoManager.updateReserveIxs( adminSigner, marketWithAddress, reserveAddress, newConfig, ); // submit each chunk in order ``` ### Marking a position for deleveraging The `markObligationForDeleveraging` instruction is exposed via the SDK codegen. An off-chain monitor (or any wallet) can submit it once a position breaches `insolvency_risk_unhealthy_ltv_pct`. ```typescript theme={null} import { markObligationForDeleveraging } from '@kamino-finance/klend-sdk/dist/@codegen/klend/instructions'; import { PROGRAM_ID } from '@kamino-finance/klend-sdk'; // Build args and accounts per the instruction's signature, then: const ix = markObligationForDeleveraging(args, accounts, PROGRAM_ID); // Sign with the marker's wallet and submit ``` For full args / accounts shapes, see `klend-sdk/src/@codegen/klend/instructions/markObligationForDeleveraging.ts`. </Tab> <Tab title="API"> <Info> **Configuring auto-deleverage is not available via the REST API.** The flags live on `LendingMarket` and `ReserveConfig` and are flipped through the **SDK** or **Kamino CLI**. The `markObligationForDeleveraging` instruction is a permissionless on-chain call; off-chain monitors typically submit it directly. </Info> To monitor positions that have entered or are eligible for the auto-deleverage state, query the on-chain obligation accounts directly. See [Read market data](/docs/curators/markets/market-data). </Tab> <Tab title="Kamino CLI"> ## Configure auto-deleverage via CLI Both the market-level and reserve-level fields are part of the standard config schemas. Apply via `update-lending-market-from-config` and `update-reserve-config`. ### Market-level ```bash theme={null} yarn kamino-manager download-lending-market-config \ --lending-market <MARKET_ADDRESS> # Edit ./configs/<MARKET>/market-<MARKET>.json — set: # "autodeleverage_enabled": 1 # "individual_autodeleverage_margin_call_period_secs": 86400 # "insolvency_risk_unhealthy_ltv_pct": 100 yarn kamino-manager update-lending-market-from-config \ --lending-market <MARKET_ADDRESS> \ --lending-market-config-path ./configs/<MARKET>/market-<MARKET>.json \ --mode multisig \ --multisig <SQUADS_MULTISIG_PUBKEY> ``` ### Reserve-level ```bash theme={null} yarn kamino-manager download-reserve-config \ --reserve <RESERVE_ADDRESS> \ --output ./configs/<RESERVE>.json # Edit ./configs/<RESERVE>.json — set: # "autodeleverage_enabled": 1 # "deleveraging_margin_call_period_secs": 0 # "deleveraging_threshold_decrease_bps_per_day": 24 # "deleveraging_bonus_increase_bps_per_day": 100 # "min_deleveraging_bonus_bps": 0 yarn kamino-manager update-reserve-config \ --reserve <RESERVE_ADDRESS> \ --reserve-config-path ./configs/<RESERVE>.json \ --mode multisig \ --multisig <SQUADS_MULTISIG_PUBKEY> ``` </Tab> </Tabs> ## The lifecycle When a position's LTV crosses `insolvency_risk_unhealthy_ltv_pct`, an off-chain monitor (anyone, typically a bot) calls `mark-obligation-for-deleveraging`. The position is now margin-called and the program records a timestamp. Standard liquidation is gated by the auto-deleverage state from this point forward. For `deleveraging_margin_call_period_secs` (or the market default if the reserve doesn't override), the borrower has a grace window to repay or add collateral. Once grace ends, the deleveraging state begins to ramp: the effective liquidation threshold drops by `deleveraging_threshold_decrease_bps_per_day` and the liquidator bonus rises by `deleveraging_bonus_increase_bps_per_day`. Each elapsed day makes the position progressively easier to liquidate and progressively more profitable to clear, until a liquidator finally executes. ## Tuning the ramp Two reserve-level fields shape how aggressively the deleveraging state ramps after grace ends. | Field | Higher value means | | - | - | | `deleveraging_threshold_decrease_bps_per_day` | Liquidation threshold drops faster, opening up the position to liquidators sooner | | `deleveraging_bonus_increase_bps_per_day` | Liquidator bonus grows faster, paying executors more for clearing the position | Reference settings: | Risk profile | threshold\_decrease | bonus\_increase | margin\_call\_period | | - | - | - | - | | Borrower-friendly | 12 bps/day | 50 bps/day | 48 hours | | Standard | 24 bps/day | 100 bps/day | 24 hours | | Aggressive (volatile asset) | 50 bps/day | 200 bps/day | 4 hours | ## Off-chain infrastructure Auto-deleverage is useful in proportion to the off-chain monitoring around it. A typical setup: * **Position monitor**: an off-chain service watches `insolvency_risk_unhealthy_ltv_pct` breaches and submits `mark-obligation-for-deleveraging` * **Borrower notification**: when a position is marked, notify the borrower (email / push / wallet message) so they can react inside the grace window * **Liquidator coordination**: standard liquidator infrastructure picks up margin-called positions once the grace window expires For curator markets, you either rely on Kamino's existing infrastructure (for whitelisted markets) or run your own. ## Reference * [Liquidations](/docs/curators/markets/liquidations) — base liquidation mechanics * [Reserve config reference](/docs/curators/markets/reserve-parameters) — `autodeleverage_enabled`, `deleveraging_*` fields * [Market config reference](/docs/curators/markets/market-config-reference) — `autodeleverage_enabled`, `individual_autodeleverage_margin_call_period_secs`, `insolvency_risk_unhealthy_ltv_pct` # Borrow Orders Source: https://kamino.com/docs/curators/markets/borrow-orders Peer-to-peer fixed-rate matching between borrowers and lenders Borrow orders let a borrower place a limit-style order specifying the rate they're willing to pay, the term, and the size — lenders then fill it directly, bypassing the IR curve. They are most useful on fixed-term reserves where pricing is set by direct counterparty matching. When a borrow order is filled, the matched debt is locked in at the agreed rate for the agreed term. The fill creates a normal fixed-term position; from that point forward, the position behaves like any other fixed-term borrow on the reserve. ## Market-level enablement | Field | What it does | | - | - | | `borrow_order_creation_enabled` | If `1`, borrowers can place new orders | | `borrow_order_execution_enabled` | If `1`, lenders can fill placed orders | | `min_borrow_order_fill_value` | Minimum USD value (scaled fraction) for any single fill. Applies both at order placement and on partial fills | A typical `min_borrow_order_fill_value` is large enough to make fills economically meaningful (e.g., \$50–\$1,000 equivalent). Set it to filter out dust orders that would crowd the orderbook. <Tabs> <Tab title="SDK"> ## Enable borrow orders via SDK Curator-side: flip the market flags via `updateLendingMarketIxs`. End-user-side: place orders via the `setBorrowOrder` instruction; lenders fill via `fillBorrowOrder`. ### Curator: enable on the market ```typescript theme={null} import { KaminoManager, DEFAULT_RECENT_SLOT_DURATION_MS, PROGRAM_ID, MarketWithAddress, } from '@kamino-finance/klend-sdk'; import { LendingMarket } from '@kamino-finance/klend-sdk/dist/@codegen/klend/accounts'; import { address } from '@solana/kit'; const kaminoManager = new KaminoManager(rpc, DEFAULT_RECENT_SLOT_DURATION_MS, PROGRAM_ID); const marketState = await LendingMarket.fetch(rpc, marketAddress); if (!marketState) throw new Error('Market not found'); const marketWithAddress: MarketWithAddress = { address: marketAddress, state: marketState }; const newLendingMarket = { ...marketState }; newLendingMarket.borrowOrderCreationEnabled = 1; newLendingMarket.borrowOrderExecutionEnabled = 1; newLendingMarket.minBorrowOrderFillValue = 50_000n; // adjust per asset const ixs = kaminoManager.updateLendingMarketIxs(adminSigner, marketWithAddress, newLendingMarket); // submit each ix in order ``` ### Borrower: place an order The SDK exposes the raw `setBorrowOrder` instruction builder via the codegen module. Build the instruction with the order parameters and submit it from the borrower's wallet. ```typescript theme={null} import { setBorrowOrder } from '@kamino-finance/klend-sdk/dist/@codegen/klend/instructions'; // Build args and accounts per the instruction's signature, then: const ix = setBorrowOrder(args, accounts, PROGRAM_ID); // Sign with the borrower's wallet and submit ``` ### Lender: fill an order ```typescript theme={null} import { fillBorrowOrder } from '@kamino-finance/klend-sdk/dist/@codegen/klend/instructions'; const ix = fillBorrowOrder(args, accounts, PROGRAM_ID); // Sign with the lender's wallet and submit ``` For full args / accounts shapes, see the auto-generated source at `klend-sdk/src/@codegen/klend/instructions/setBorrowOrder.ts` and `fillBorrowOrder.ts`. </Tab> <Tab title="API"> <Info> **Configuring borrow orders is not available via the REST API.** The curator-side flags live on `LendingMarket` and are flipped through the **SDK** or **Kamino CLI**. User-facing order creation and filling happen on-chain via the program's instructions. </Info> To configure borrow orders, use the **SDK** or **Kamino CLI** tabs. Live order data may be surfaced through Kamino's indexer / API for whitelisted markets. For non-whitelisted curator markets, run your own indexer. </Tab> <Tab title="Kamino CLI"> ## Enable borrow orders via CLI ```bash theme={null} # 1. Download yarn kamino-manager download-lending-market-config \ --lending-market <MARKET_ADDRESS> # 2. Edit ./configs/<MARKET>/market-<MARKET>.json — set: # "borrow_order_creation_enabled": 1 # "borrow_order_execution_enabled": 1 # "min_borrow_order_fill_value": "<scaled fraction>" # 3. Inspect yarn kamino-manager update-lending-market-from-config \ --lending-market <MARKET_ADDRESS> \ --lending-market-config-path ./configs/<MARKET>/market-<MARKET>.json \ --mode inspect # 4. Apply yarn kamino-manager update-lending-market-from-config \ --lending-market <MARKET_ADDRESS> \ --lending-market-config-path ./configs/<MARKET>/market-<MARKET>.json \ --mode multisig \ --multisig <SQUADS_MULTISIG_PUBKEY> ``` User-side order creation and filling are not currently exposed through the kamino-manager CLI; users place orders via the Kamino webapp or via SDK-built transactions. </Tab> </Tabs> ## The order itself A borrow order is stored on the borrower's obligation account. Each order specifies: | Field | What it does | | - | - | | `remaining_debt_amount` | The principal still seeking a fill. Decreases as partial fills happen | | `max_borrow_rate_bps` | The highest interest rate (bps) the borrower will accept. A lender can fill at any rate ≤ this value | | `min_debt_term_seconds` | The minimum term (seconds) the borrower will accept. Lenders' fills must use a fixed-term reserve with `debt_term_seconds >= min_debt_term_seconds` | | `fillable_until_timestamp` | Order expires after this timestamp | | `enable_auto_rollover_on_filled_borrows` | If `1`, filled borrows from this order auto-roll on maturity (subject to market-level rollover settings) | **Hard limit**: each obligation can hold **one open borrow order at a time**. This is a deliberate business-logic constraint enforced by the program; it keeps the orderbook clean and the matching logic simple. ## The matching flow The borrower calls `set-borrow-order` on their obligation, specifying the parameters above. At this stage no target reserve is named: the order is a pure expression of "what I'm willing to take" — max rate, min term, expiry, size. A lender (or filler bot, or vault) finds the order, picks a fixed-term reserve whose `debt_term_seconds` and current borrow rate sit inside the order's `min_debt_term_seconds` and `max_borrow_rate_bps` bounds, and calls `fill-borrow-order` referencing the borrower's obligation, the chosen reserve, and the amount to fill. The program verifies expiry, term, rate, and fill-size constraints; on success, principal flows from the reserve to the borrower's debt position with the matched fixed term. The order's `remaining_debt_amount` decreases by the filled size. When it reaches zero, the order closes. The borrower can also cancel the order at any time, and the order is automatically void after `fillable_until_timestamp` passes. ## Three liquidity flows that fill orders | Flow | Source of liquidity | | - | - | | **Repaid liquidity matching** | Repayments into a fixed-term reserve free up liquidity. Bots monitor and fill outstanding borrow orders against that reserve | | **Vault-driven fills** | A Kamino vault sitting on top can route deposits into a fixed-term reserve to fill matching orders, capturing the rate as yield for the vault's depositors | | **Direct seeding** | A privileged lender deposits directly into a fixed-term reserve. The deposit sits as available liquidity until a borrow order fills it | ## Cancelling an order A borrower can cancel their open order at any time (subject to no in-flight partial fill). Cancellation closes the order without affecting the borrows that have already been filled — those positions persist as normal fixed-term debt. ## Interaction with obligation ownership transfer When a borrower has an open borrow order, transferring obligation ownership has a constraint: the order's debt destination is tied to the original owner's authority. If the new owner accepts the obligation while an order is open, the order becomes unfillable. **Recommended flow**: cancel any open borrow orders before initiating an obligation transfer. See [Obligation ownership transfer](/docs/curators/markets/obligation-ownership-transfer). ## Off-chain infrastructure Borrow orders are useful in proportion to the off-chain matching infrastructure around them. A typical setup: * **Order indexer**: an off-chain service watches `set-borrow-order` events and maintains an orderbook view per reserve * **Filler bot**: a service that detects fillable orders and submits `fill-borrow-order` transactions * **UI**: the borrower's UI shows the orderbook and lets them place / cancel orders Curators running their own market typically rely on Kamino's existing infrastructure (for whitelisted markets) or build their own around the on-chain primitives. ## Common errors | Error | Cause | | - | - | | `BorrowOrderCreationDisabled` | `borrow_order_creation_enabled = 0`. Enable | | `BorrowOrderExecutionDisabled` | `borrow_order_execution_enabled = 0`. Enable | | `BorrowOrderAlreadyExists` | The obligation already has an open order. Cancel the existing one first | | `BorrowOrderFillValueTooSmall` | Fill amount is below `min_borrow_order_fill_value` | | `BorrowOrderExpired` | `now > fillable_until_timestamp`. Borrower must place a new order | | `BorrowOrderTermNotAcceptable` | Lender's chosen reserve has `debt_term_seconds < order.min_debt_term_seconds` | | `BorrowOrderRateNotAcceptable` | Fill rate exceeds `max_borrow_rate_bps` | ## Reference * [Market config reference](/docs/curators/markets/market-config-reference) — `borrow_order_*` flags and `min_borrow_order_fill_value` * [Fixed rate reserves](/docs/curators/markets/fixed-rate-reserves) — the underlying lending mechanics * [Obligation ownership transfer](/docs/curators/markets/obligation-ownership-transfer) — interaction with open orders # CLI Command Index Source: https://kamino.com/docs/curators/markets/cli-command-index Quick lookup of every market-related kamino-manager CLI command A flat reference of every `kamino-manager` command that touches a market or its reserves. Each row links to the workflow page that uses it. For full flag detail on any command, see the [Market Operations CLI page](/docs/build/cli/market-operations). For installation and `.env` setup, see [CLI instal
프로젝트로 돌아가기