Kamino 백서

Kamino

원문

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

lation & setup](/docs/build/cli/installation-setup). ## Market lifecycle | Command | Purpose | Workflow page | | - | - | - | | `create-market` | Initialize a new `LendingMarket` account | [Create a market](/docs/curators/markets/creating-a-market) | | `update-lending-market-name` | Rename the market | [Market settings](/docs/curators/markets/market-settings) | | `update-lending-market-from-config` | Apply a full market config update from JSON | [Market settings](/docs/curators/markets/market-settings) | | `update-lending-market-owner` | Promote `lending_market_owner_cached` to active owner | [Transfer to multisig](/docs/curators/markets/transfer-to-multisig) | | `download-lending-market-config` | Export the current market config to JSON | [Market settings](/docs/curators/markets/market-settings) | | `download-lending-market-config-and-all-reserves-configs` | Export market + all reserves in one call | [Market settings](/docs/curators/markets/market-settings) | | `get-market-or-vault-admin-info` | Query admin metadata (owner, cached owner, council) | [Market settings](/docs/curators/markets/market-settings) | ## Reserve lifecycle | Command | Purpose | Workflow page | | - | - | - | | `add-asset-to-market` | Add a new reserve to the market with a config | [Add reserves](/docs/curators/markets/adding-reserves) | | `update-reserve-config` | Apply a full reserve config update from JSON | [Updating reserves](/docs/curators/markets/reserve-management) | | `update-reserve-config-debt-cap` | Focused update of just the borrow cap | [Updating reserves](/docs/curators/markets/reserve-management) | | `download-reserve-config` | Export the current reserve config to JSON | [Updating reserves](/docs/curators/markets/reserve-management) | | `simulate-reserve-apy` | Compute live supply and borrow APY for a reserve | [Read market data](/docs/curators/markets/market-data) | ## Oracles | Command | Purpose | Workflow page | | - | - | - | | `get-oracle-mappings` | List Scope oracle addresses for known mints | [Configure oracles](/docs/curators/markets/configuring-oracles) | ## Farms Farm initialization happens through the KFarms tooling and is bundled into `add-asset-to-market` for the initial setup. Read-side queries: | Command | Purpose | Workflow page | | - | - | - | | `get-reserve-farms-apy` | Reward APY for a reserve's collateral and debt farms | [Farms & rewards](/docs/curators/markets/farms-and-rewards) | For farm initialization, funding, and emission configuration, use the KFarms CLI and SDK. ## Execution modes Every command supports four `--mode` values: | Mode | What it does | | - | - | | `inspect` | Prints a Solana Explorer URL where you can simulate the transaction | | `simulate` | Runs simulation server-side and prints the result | | `execute` | Signs with the admin keypair and lands the transaction | | `multisig` | Outputs a base58-encoded transaction for submission to a Squads proposal | Multisig mode requires `--multisig <SQUADS_PUBKEY>` to identify the multisig the proposal targets. ## Network selection | Flag | Target | | - | - | | (none) | Mainnet (default) | | `--staging` | Staging program on Solana mainnet | | `--devnet` | Solana devnet | ## Vault commands The kamino-manager CLI also exposes a large set of vault-related commands (e.g., `create-vault`, `update-vault-config`, `update-vault-reserve-allocation`, etc.). These are documented under [Create a vault](/docs/curators/vaults/guides/create-a-vault) and the [Vault Operations CLI page](/docs/build/cli/vault-operations). ## Reference * [Market Operations CLI](/docs/build/cli/market-operations) — full flag detail for every command * [CLI installation & setup](/docs/build/cli/installation-setup) — `.env`, keypair, RPC * [Updating reserves](/docs/curators/markets/reserve-management) — the standard workflow * [Market settings](/docs/curators/markets/market-settings) — market-level workflow # Configure Oracles Source: https://kamino.com/docs/curators/markets/configuring-oracles Wire each reserve to a price feed with the right TWAP and staleness guards Every reserve needs a valid oracle. Oracle configuration lives inside the reserve config under `tokenInfo`. Reserves are priced through **Scope**, Kamino's price aggregator. ## How pricing works Scope combines provider feeds (**Chainlink** and **Pyth Pro**) into a single, manipulation-resistant chain of indices, and exposes [custom oracle types](/docs/curators/markets/scope-oracle-types) for fixed-income, pegged, multi-source, and LST assets. You wire a reserve to a Scope feed by setting `scopeConfiguration` in `tokenInfo`: the price chain, TWAP chain, and guards. For an asset that isn't in Scope yet, coordinate with the Kamino team to add it before listing. ## Required tokenInfo fields | Field | Type | What it does | | - | - | - | | `name` | string (≤32 bytes UTF-8) | Asset symbol | | `maxAgePriceSeconds` | u64 | Reject the spot price if older than this many seconds | | `maxAgeTwapSeconds` | u64 | Reject the TWAP if older than this many seconds. Required if TWAP is enabled | | `maxTwapDivergenceBps` | u64 | Maximum divergence between spot and TWAP in basis points. `0` disables the guard | | `heuristic` | `{ lower, upper, exp }` | Sanity bounds. Reject prices outside `[lower * 10^exp, upper * 10^exp]`. All zeros disables | | `blockPriceUsage` | `0` or `1` | If `1`, the reserve is configured but the program rejects any operation needing a price (emergency switch) | Plus the Scope feed: * `scopeConfiguration` — Scope feed pubkey + price chain + TWAP chain <Tabs> <Tab title="SDK"> ## Update oracle config via SDK The most direct path for changing just the Scope oracle on an existing reserve is `kaminoManager.updateReserveScopeOracleConfigurationIxs`. For broader reserve updates that include oracle changes, use `updateReserveIxs` with a full `ReserveConfig`. <Steps> <Step title="Initialize KaminoManager and fetch the reserve"> ```typescript theme={null} import { createSolanaRpc, createSolanaRpcSubscriptions, address, pipe, createTransactionMessage, setTransactionMessageFeePayerSigner, setTransactionMessageLifetimeUsingBlockhash, appendTransactionMessageInstructions, signTransactionMessageWithSigners, sendAndConfirmTransactionFactory, } from '@solana/kit'; import { KaminoManager, DEFAULT_RECENT_SLOT_DURATION_MS, PROGRAM_ID, MarketWithAddress, } from '@kamino-finance/klend-sdk'; import { LendingMarket, Reserve } from '@kamino-finance/klend-sdk/dist/@codegen/klend/accounts'; import { parseKeypairFile } from '@kamino-finance/klend-sdk/dist/utils/signer.js'; const adminSigner = await parseKeypairFile('/path/to/admin.json'); const rpc = createSolanaRpc('https://api.mainnet-beta.solana.com'); const rpcSubscriptions = createSolanaRpcSubscriptions('wss://api.mainnet-beta.solana.com'); const kaminoManager = new KaminoManager(rpc, DEFAULT_RECENT_SLOT_DURATION_MS, PROGRAM_ID); const marketAddress = address('<MARKET_ADDRESS>'); const reserveAddress = address('<RESERVE_ADDRESS>'); const market = await LendingMarket.fetch(rpc, marketAddress); if (!market) throw new Error('Market not found'); const marketWithAddress: MarketWithAddress = { address: marketAddress, state: market }; ``` </Step> <Step title="Update Scope oracle configuration"> ```typescript theme={null} const updateIxs = await kaminoManager.updateReserveScopeOracleConfigurationIxs( adminSigner, marketWithAddress, reserveAddress, { scopePriceConfigAddress: address('3NJYftD5sjVfxSnUdZ1wVML8f3aC6mp1CXCL6L7TnU8C'), scopeChain: [0, 65535, 65535, 65535], scopeTwapChain: [52, 65535, 65535, 65535], }, ); async function buildAndSendTx(ixs: any[]) { const { value: blockhash } = await rpc.getLatestBlockhash({ commitment: 'finalized' }).send(); const signed = await signTransactionMessageWithSigners( pipe( createTransactionMessage({ version: 0 }), (tx) => setTransactionMessageFeePayerSigner(adminSigner, tx), (tx) => setTransactionMessageLifetimeUsingBlockhash(blockhash, tx), (tx) => appendTransactionMessageInstructions(ixs, tx) ) ); await sendAndConfirmTransactionFactory({ rpc, rpcSubscriptions })(signed, { commitment: 'confirmed', }); } for (const { ixs } of updateIxs) { await buildAndSendTx(ixs); } ``` `65535` (`u16::MAX`) is the unused-slot sentinel. A single-hop Scope chain uses `[N, 65535, 65535, 65535]`. </Step> <Step title="Adjusting the TWAP / staleness guards"> To change the staleness and TWAP guards, fetch the reserve's full config, mutate the relevant `tokenInfo` fields, and apply via `updateReserveIxs`: ```typescript theme={null} const reserve = await Reserve.fetch(rpc, reserveAddress); if (!reserve) throw new Error('Reserve not found'); const newConfig = { ...reserve.config }; newConfig.tokenInfo = { ...reserve.config.tokenInfo, maxAgePriceSeconds: 120n, maxAgeTwapSeconds: 240n, maxTwapDivergenceBps: 4050n, }; const updateIxs = await kaminoManager.updateReserveIxs( adminSigner, marketWithAddress, reserveAddress, newConfig, ); for (const { ixs } of updateIxs) { await buildAndSendTx(ixs); } ``` </Step> </Steps> ### Looking up oracle IDs ```typescript theme={null} import { ScopeConfig } from '@kamino-finance/scope-sdk'; const scopeConfig = await ScopeConfig.fetch(rpc, address('<SCOPE_CONFIG_PUBKEY>')); // Inspect scopeConfig.tokensMetadata to find the index for your asset ``` Or call the kamino-manager CLI's `get-oracle-mappings` command (next tab) to retrieve the canonical IDs. </Tab> <Tab title="API"> <Info> **Oracle configuration is not available via the REST API.** The API serves read access to oracle-derived prices and reserve metrics; oracle configuration is an admin operation available through the **SDK** or **Kamino CLI**. </Info> To update a reserve's oracle config, use the **SDK** or **Kamino CLI** tabs. To read current price data via API, see the [API reference](/docs/build/api-reference/introduction). </Tab> <Tab title="Kamino CLI"> ## Configure oracles via CLI Oracle configuration sits inside the reserve config JSON under the `tokenInfo` key. Edit it like any other reserve field, then apply via `update-reserve-config`. For a focused command that only updates the Scope oracle, use the SDK (no dedicated CLI command exists). ### Find the right oracle IDs ```bash theme={null} yarn kamino-manager get-oracle-mappings ``` Returns the Scope feed pubkeys and indices that klend supports for known mints. Copy the IDs for your asset into the reserve config. If your asset isn't in `get-oracle-mappings`, coordinate with the Kamino team to add a Scope feed for it before listing. ### Scope configuration ```json theme={null} "tokenInfo": { "name": "USDC", "maxAgePriceSeconds": 120, "maxAgeTwapSeconds": 240, "maxTwapDivergenceBps": 4050, "scopeConfiguration": { "priceFeed": "3NJYftD5sjVfxSnUdZ1wVML8f3aC6mp1CXCL6L7TnU8C", "priceChain": [0, 65535, 65535, 65535], "twapChain": [52, 65535, 65535, 65535] } } ``` | Field | What it is | | - | - | | `priceFeed` | The Scope `OraclePrices` account pubkey | | `priceChain` | Up to four `u16` indices into the Scope feed; the first non-`65535` entry is the primary price | | `twapChain` | Same shape, for the TWAP indices | `65535` is the sentinel for "unused slot." A single-hop price uses `[N, 65535, 65535, 65535]`. ### Apply the update ```bash theme={null} # Download the current reserve config yarn kamino-manager download-reserve-config \ --reserve <RESERVE_ADDRESS> \ --output ./configs/<RESERVE>.json # Edit ./configs/<RESERVE>.json — update tokenInfo # Inspect the change yarn kamino-manager update-reserve-config \ --reserve <RESERVE_ADDRESS> \ --reserve-config-path ./configs/<RESERVE>.json \ --mode inspect # Apply yarn kamino-manager update-reserve-config \ --reserve <RESERVE_ADDRESS> \ --reserve-config-path ./configs/<RESERVE>.json \ --mode execute ``` </Tab> </Tabs> ## TWAP and staleness guards The two guards work together to reject manipulated or stale prices. | Guard | What it catches | | - | - | | `maxAgePriceSeconds` | Spot price older than this is rejected. Set to `120` for liquid assets, lower for high-stakes reserves | | `maxAgeTwapSeconds` | TWAP older than this is rejected. Typically 2–4× `maxAgePriceSeconds` | | `maxTwapDivergenceBps` | If spot deviates from TWAP by more than this, the price is rejected. Set to `4050` (≈40.5%) for volatile assets, lower for stables. `0` disables | If TWAP is enabled (`maxTwapDivergenceBps > 0`) the Scope feed must expose a TWAP chain. The on-chain validator returns `InvalidTwapConfig` if you enable the guard against a feed with no TWAP. ## Price heuristic The heuristic is an absolute price band: ```json theme={null} "heuristic": { "lower": 9, "upper": 11, "exp": 1 } ``` With `exp: 1`, the price is accepted only when `0.9 ≤ price ≤ 1.1`. Useful for stables you expect to peg. Set all zeros to disable. ## Block price usage (emergency) `blockPriceUsage: 1` is an emergency switch: the reserve is configured normally but the program refuses any operation that needs the price. Use it when you need to halt a reserve immediately while preparing a real config update. ## Choosing for new assets | Asset type | Recommended setup | | - | - | | Major stablecoins (USDC, USDT, USDS) | Scope, with a tight heuristic and TWAP guard | | Major liquid assets (SOL, BTC, ETH) | Scope | | LSTs (mSOL, jitoSOL, INF, etc.) | Scope (uses LST → SOL → USD chain) | | Pegged or fixed-income assets | Scope [custom oracle types](/docs/curators/markets/scope-oracle-types) (CappedFloored, DiscountToMaturity) | | Tokenized off-chain assets | Coordinate with the Kamino team to add to Scope | ## Reference * [Reserve config reference](/docs/curators/markets/reserve-parameters) — every `tokenInfo` field documented * [Oracle architecture overview](/docs/security/oracles) — Scope, price protection, manipulation resistance # Create a Market Source: https://kamino.com/docs/curators/markets/creating-a-market Initialize a new Kamino lending market A market is created by a single transaction. The transaction initializes a `LendingMarket` account on-chain with default settings and your wallet (or a multisig) as the owner. Reserves, oracles, and feature flags are configured in subsequent steps. The market is empty (no reserves) until you [add reserves](/docs/curators/markets/adding-reserves), and cannot accept deposits or borrows until at least one reserve is active. <Tabs> <Tab title="SDK"> ## Create a market via SDK Use `KaminoManager` from `@kamino-finance/klend-sdk` to build and submit the create-market instruction. <Steps> <Step title="Import dependencies"> ```typescript theme={null} import { createSolanaRpc, createSolanaRpcSubscriptions, pipe, createTransactionMessage, setTransactionMessageFeePayerSigner, setTransactionMessageLifetimeUsingBlockhash, appendTransactionMessageInstructions, signTransactionMessageWithSigners, sendAndConfirmTransactionFactory, } from '@solana/kit'; import { KaminoManager, DEFAULT_RECENT_SLOT_DURATION_MS, PROGRAM_ID, } from '@kamino-finance/klend-sdk'; import { parseKeypairFile } from '@kamino-finance/klend-sdk/dist/utils/signer.js'; ``` </Step> <Step title="Initialize KaminoManager"> ```typescript theme={null} const adminSigner = await parseKeypairFile('/path/to/admin.json'); const rpc = createSolanaRpc('https://api.mainnet-beta.solana.com'); const rpcSubscriptions = createSolanaRpcSubscriptions('wss://api.mainnet-beta.solana.com'); const kaminoManager = new KaminoManager(rpc, DEFAULT_RECENT_SLOT_DURATION_MS, PROGRAM_ID); ``` <Note> Use a private RPC endpoint for production. Public RPCs are rate-limited. </Note> </Step> <Step title="Build the create-market instructions"> ```typescript theme={null} const { market: marketSigner, ixs: createMarketIxs } = await kaminoManager.createMarketIxs({ admin: adminSigner, }); console.log('New market address:', marketSigner.address); ``` `createMarketIxs` returns: * `market`: a `TransactionSigner` for the market account; its `address` is the new market's pubkey * `ixs`: the instructions needed to create and initialize the market Save the `marketSigner.address` value — every subsequent operation references it. </Step> <Step title="Sign and send the transaction"> ```typescript theme={null} const { value: latestBlockhash } = await rpc .getLatestBlockhash({ commitment: 'finalized' }) .send(); const transactionMessage = pipe( createTransactionMessage({ version: 0 }), (tx) => setTransactionMessageFeePayerSigner(adminSigner, tx), (tx) => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, tx), (tx) => appendTransactionMessageInstructions(createMarketIxs, tx) ); const signedTransaction = await signTransactionMessageWithSigners(transactionMessage); await sendAndConfirmTransactionFactory({ rpc, rpcSubscriptions })(signedTransaction, { commitment: 'confirmed', }); console.log('Market created:', marketSigner.address); ``` The market signer (`marketSigner`) is automatically included as a signer because `KaminoManager.createMarketIxs` returns it as a `TransactionSigner`. </Step> </Steps> ### Targeting staging or devnet Pass the staging or devnet program ID when constructing `KaminoManager`: ```typescript theme={null} import { STAGING_PROGRAM_ID } from '@kamino-finance/klend-sdk'; const kaminoManager = new KaminoManager(rpc, DEFAULT_RECENT_SLOT_DURATION_MS, STAGING_PROGRAM_ID); ``` For devnet, point the RPC at `https://api.devnet.solana.com` and use the devnet program ID from your environment. ### Multisig from the start If you want the market owned by a multisig from inception, pass the multisig pubkey as a noop signer for `admin`: ```typescript theme={null} import { noopSigner, address } from '@kamino-finance/klend-sdk'; const multisigAdmin = noopSigner(address('<SQUADS_MULTISIG_PUBKEY>')); const { market, ixs } = await kaminoManager.createMarketIxs({ admin: multisigAdmin, }); // Don't sign and send. Instead, encode the transaction as base58 and submit it // as a Squads proposal. The multisig itself will sign and execute. ``` For most curators, the simpler path is to create under a hot wallet, add reserves, validate, then [transfer to a multisig](/docs/curators/markets/transfer-to-multisig). </Tab> <Tab title="API"> <Info> **Market creation is not available via the REST API.** The Kamino API supports reading market and reserve data and building user-facing deposit/borrow transactions. Market creation is an admin operation available through the **SDK** or **Kamino CLI**. </Info> To create a market programmatically, use the **SDK** or **Kamino CLI** tabs. For reading market data after creation, see [Read market data](/docs/curators/markets/market-data) and the [API reference](/docs/build/api-reference/introduction). </Tab> <Tab title="Kamino CLI"> ## Create a market via CLI A market is created by a single CLI call. The command initializes a `LendingMarket` account on-chain and prints the new market's address. <Note> Before running the command, complete the [CLI installation & setup](/docs/build/cli/installation-setup). The CLI requires `ADMIN`, `RPC`, `KLEND_PROGRAM_ID_MAINNET`, and `KLEND_PROGRAM_ID_STAGING` in `.env`. </Note> ### Command ```bash theme={null} yarn kamino-manager create-market --mode execute ``` That's it. The market is created against mainnet by default. Save the address from the output. ### Network selection | Flag | Target | Notes | | - | - | - | | (no flag) | Mainnet | Production deployment | | `--staging` | Staging program on Solana mainnet | Real prices, real oracles, isolated program ID | | `--devnet` | Solana devnet | Fully isolated sandbox | ### Execution modes Every CLI command supports four `--mode` values. Use them to validate before committing. | Mode | What it does | | -
프로젝트로 돌아가기