bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 75쪽 중 37쪽
onfig] = await scope.getSingleFeedConfiguration({
config: SCOPE_MAINNET_HUBBLE_FEED.configuration,
});
console.log('Config account:', configAddress);
console.log({
admin: config.admin.toString(),
adminCached: config.adminCached.toString(),
oraclePrices: config.oraclePrices.toString(),
oracleMappings: config.oracleMappings.toString(),
tokensMetadata: config.tokensMetadata.toString(),
oracleTwaps: config.oracleTwaps.toString(),
});
```
<a href="https://github.com/Kamino-Finance/scope-sdk">
<Icon icon="github" />
<span>View Code</span>
</a>
<Note>
List every feed on the Scope program with `scope.getAllConfigurations()`.
</Note>
### Chain Metadata (what backs a price)
`getChainMetadata` returns one entry per hop of a scope chain, telling you which provider serves the price and which oracle type produces it (one of about 40 kinds, including `PythPull`, `ScopeTwap`, `SplStake`, `DiscountToMaturity`, `MostRecentOf`, and `CappedFloored`).
```typescript icon="typescript" chainMetadata theme={null}
import { createSolanaRpc } from '@solana/kit';
import { Scope, SCOPE_MAINNET_HUBBLE_FEED } from '@kamino-finance/scope-sdk';
const RPC_ENDPOINT = 'https://api.mainnet-beta.solana.com';
const CHAIN = [0, 65535, 65535, 65535]; // SOL/USD, single-hop
const rpc = createSolanaRpc(RPC_ENDPOINT);
const scope = new Scope('mainnet-beta', rpc);
const metadata = await scope.getChainMetadata(
{ config: SCOPE_MAINNET_HUBBLE_FEED.configuration },
CHAIN,
);
metadata.forEach((m, hop) => {
console.log(`hop ${hop}: ${m.name} (${m.simpleName})`);
console.log(` provider: ${m.provider} | oracleType: ${m.oracleType}`);
console.log(` nestedOracles: ${JSON.stringify(m.nestedOracles)}`);
});
```
<Note>
The oracle type is chosen by the feed admin at config time (`updateFeedMapping`). This call only inspects what is already set. For the curator-facing configuration side, see [Scope Oracle Types](/docs/curators/markets/scope-oracle-types).
</Note>
### Oracle Mappings (raw per-slot wiring)
`getOracleMappings` returns the raw per-slot wiring behind every price in the feed. Where `getChainMetadata` humanizes one chain's hops, the mappings expose every slot: the source account Scope reads, the oracle type discriminant, TWAP smoothing config, and the Reference Price Check slot.
```typescript icon="typescript" oracleMappings theme={null}
import { createSolanaRpc } from '@solana/kit';
import { Scope, SCOPE_MAINNET_HUBBLE_FEED } from '@kamino-finance/scope-sdk';
const RPC_ENDPOINT = 'https://api.mainnet-beta.solana.com';
const NONE = 65535;
const rpc = createSolanaRpc(RPC_ENDPOINT);
const scope = new Scope('mainnet-beta', rpc);
const m = await scope.getOracleMappings({
config: SCOPE_MAINNET_HUBBLE_FEED.configuration,
});
// First 6 slots.
m.priceInfoAccounts.slice(0, 6).forEach((acct, slot) => {
console.log({
slot,
source: acct.toString(),
oracleType: m.priceTypes[slot],
twapEnabled: m.twapEnabled[slot] === 1,
refPriceSlot: m.refPrice[slot] === NONE ? 'none' : m.refPrice[slot],
});
});
```
<Note>
`65535` is the unset sentinel throughout. `refPrice` is the slot an incoming price is sanity-checked against, the Reference Price Check feature described in [Scope Oracle Types](/docs/curators/markets/scope-oracle-types).
</Note>
## Additional Resources
<CardGroup>
<Card title="SDK Repository" icon="github" href="https://github.com/Kamino-Finance/scope-sdk" />
<Card title="Scope Oracle Types" icon="sliders" href="/docs/curators/markets/scope-oracle-types" />
</CardGroup>
# Prices
Source: https://kamino.com/docs/build/developers/oracle/data/prices
Read Scope oracle prices on-chain via the SDK or off-chain via REST
## Reading Scope Prices
Scope serves prices two ways. On-chain, the `OraclePrices` account holds a fixed 512-slot array of dated prices and the SDK reads it directly. Off-chain, the Kamino REST endpoint serves the same prices pre-aggregated and keyed by mint, with no RPC or SDK required.
### Read All Prices
<Tabs>
<Tab title="TypeScript">
Direct on-chain read of every populated slot in a feed.
```typescript theme={null}
import { createSolanaRpc } from '@solana/kit';
import { Scope, SCOPE_MAINNET_HUBBLE_FEED } from '@kamino-finance/scope-sdk';
import Decimal from 'decimal.js';
const RPC_ENDPOINT = 'https://api.mainnet-beta.solana.com';
const rpc = createSolanaRpc(RPC_ENDPOINT);
const scope = new Scope('mainnet-beta', rpc);
const oraclePrices = await scope.getSingleOraclePrices({
config: SCOPE_MAINNET_HUBBLE_FEED.configuration,
});
// Fixed-size array; a slot is unset when its price value is 0.
const populated = oraclePrices.prices
.map((p, index) => ({ index, p }))
.filter(({ p }) => p.price.value.toString() !== '0');
console.log(`Feed ${SCOPE_MAINNET_HUBBLE_FEED.oraclePrices}: ${populated.length} populated of ${oraclePrices.prices.length}`);
populated.slice(0, 10).forEach(({ index, p }) => {
const price = new Decimal(p.price.value.toString()).div(new Decimal(10).pow(Number(p.price.exp)));
const updated = new Date(Number(p.unixTimestamp) * 1000).toISOString();
console.log(` [${index}] ${price.toString()} (updated ${updated})`);
});
```
<a href="https://github.com/Kamino-Finance/scope-sdk">
<Icon icon="github" />
<span>View Code</span>
</a>
A price is `value / 10^exp`; freshness comes from `lastUpdatedSlot` and `unixTimestamp` on the same dated price. `getSingleOraclePrices` accepts the feed by its configuration account, its `OraclePrices` pubkey, or its PDA seed.
</Tab>
<Tab title="API">
The same prices, pre-aggregated and keyed by mint. No RPC required.
```typescript theme={null}
const API = 'https://api.kamino.finance/oracles/prices?source=scope';
type ScopePrice = { mint: string; name: string; price: string; timestamp: number; maxAgeInSeconds: number };
const rows: ScopePrice[] = await (await fetch(API)).json();
console.log(`Scope prices: ${rows.length}`);
rows.slice(0, 10).forEach((r) => console.log(` ${r.name}: ${r.price} (${r.mint})`));
```
</Tab>
</Tabs>
### Get a Single Token Price
<Tabs>
<Tab title="TypeScript">
A token's USD price is resolved by a "scope chain": up to 4 slot indices, padded with `65535`. One index means a direct price; several means a derived price (for example TOKEN/SOL then SOL/USD).
```typescript theme={null}
import { createSolanaRpc } from '@solana/kit';
import { Scope, SCOPE_MAINNET_HUBBLE_FEED } from '@kamino-finance/scope-sdk';
const RPC_ENDPOINT = 'https://api.mainnet-beta.solana.com';
const CHAIN = [0, 65535, 65535, 65535]; // SOL/USD, slot 0, single-hop
const rpc = createSolanaRpc(RPC_ENDPOINT);
const scope = new Scope('mainnet-beta', rpc);
const oraclePrices = await scope.getSingleOraclePrices({
config: SCOPE_MAINNET_HUBBLE_FEED.configuration,
});
if (!Scope.isScopeChainValid(CHAIN)) console.log('Chain is not valid:', CHAIN);
const { price, timestamp } = await scope.getPriceFromChain(CHAIN, oraclePrices);
const ageSec = Math.floor(Date.now() / 1000) - timestamp.toNumber();
console.log(`Price: ${price.toString()}`);
console.log(`Updated: ${new Date(timestamp.toNumber() * 1000).toISOString()} (${ageSec}s ago)`);
```
<a href="https://github.com/Kamino-Finance/scope-sdk">
<Icon icon="github" />
<span>View Code</span>
</a>
The calling program supplies the scope chain. A klend reserve, for example, stores it on its token config; Scope just resolves it against the feed's price list. Sentinel slots (`65535`) are skipped.
</Tab>
<Tab title="API">
Filter the price list by mint. No scope chain to walk.
```typescript theme={null}
const SOL_MINT = 'So11111111111111111111111111111111111111112';
const API = 'https://api.kamino.finance/prices?source=scope';
type Price = { usdPrice: string; token: string; mint: string };
const rows: Price[] = await (await fetch(API)).json();
const sol = rows.find((r) => r.mint === SOL_MINT);
if (!sol) console.log('Mint not found in price list:', SOL_MINT);
console.log(`${sol.token}: $${sol.usdPrice}`);
```
</Tab>
</Tabs>
### Get Token Price History
Past prices for a single token, keyed by mint or symbol. API only, with no on-chain equivalent: the `OraclePrices` account holds only the current value per slot, so history is served off-chain.
```typescript theme={null}
const USDC_MINT = 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v';
const API = `https://api.kamino.finance/prices/history?token=${USDC_MINT}&frequency=day&start=2026-06-01T00:00:00Z&end=2026-06-10T00:00:00Z`;
// Each point is a [usdPrice, unixSeconds] pair, ordered oldest to newest.
type PricePoint = [price: string, timestamp: number];
const points: PricePoint[] = await (await fetch(API)).json();
console.log(`History points: ${points.length}`);
points.slice(0, 5).forEach(([price, ts]) =>
console.log(` ${new Date(ts * 1000).toISOString()}: $${price}`),
);
```
`frequency` is `minute`, `hour`, or `day`; omit `start`/`end` and the endpoint returns a default recent window (about the last day) at the chosen frequency. See the [Get token price history](/docs/build/api-reference/oracle/token-prices-history) reference for the full parameter list.
## Types
<Tabs>
<Tab title="ScopeDatedPrice">
Returned by `getPriceFromChain`. A resolved price plus its freshness.
```typescript theme={null}
type ScopeDatedPrice = {
price: Decimal;
timestamp: BN;
};
```
</Tab>
<Tab title="OraclePrices">
The on-chain account holding 512 dated prices.
```typescript theme={null}
type OraclePrices = {
prices: DatedPrice[]; // length 512
};
type DatedPrice = {
price: { value: BN; exp: BN };
lastUpdatedSlot: BN;
unixTimestamp: BN;
};
```
</Tab>
</Tabs>
## Additional Resources
<CardGroup>
<Card title="API Examples" icon="book" href="https://api-docs.kamino.com/" />
<Card title="SDK Repository" icon="github" href="https://github.com/Kamino-Finance/scope-sdk" />
</CardGroup>
# Refresh Prices
Source: https://kamino.com/docs/build/developers/oracle/operations/refresh
Build and send the permissionless Scope refresh instruction for one or more price slots
## Refresh Prices
Scope prices are pushed on-chain by permissionless "crank" transactions: anyone can sign and send a refresh, no admin authority required. The Scope SDK builds one instruction that refreshes the specified token slots for a feed. This is the instruction Multiply and flash-loan flows bundle in front of a leverage operation so reserves read fresh prices.
<Steps>
<Step>
### Import Dependencies
Import the Scope SDK plus the Solana Kit transaction-building helpers and a keypair loader.
```typescript theme={null}
import {
createSolanaRpc,
createSolanaRpcSubscriptions,
pipe,
createTransactionMessage,
setTransactionMessageFeePayerSigner,
setTransactionMessageLifetimeUsingBlockhash,
appendTransactionMessageInstructions,
signTransactionMessageWithSigners,
getSignatureFromTransaction,
assertIsTransactionWithinSizeLimit,
sendAndConfirmTransactionFactory,
} from "@solana/kit";
import { parseKeypairFile } from "@kamino-finance/klend-sdk/dist/utils/signer";
import { Scope, SCOPE_MAINNET_HUBBLE_FEED } from "@kamino-finance/scope-sdk";
```
</Step>
<Step>
### Configure Constants and Initialize Scope
Set the keypair path, RPC endpoints, and the slot indices to refresh.
```typescript theme={null}
const KEYPAIR_FILE = "/path/to/your/keypair.json";
const RPC_ENDPOINT = "https://api.mainnet-beta.solana.com";
const WS_ENDPOINT = "wss://api.mainnet-beta.solana.com";
// Slot indices to refresh (e.g. SOL, ETH, BTC on the Hubble feed).
const TOKENS = [0, 1, 2];
const signer = await parseKeypairFile(KEYPAIR_FILE);
const rpc = createSolanaRpc(RPC_ENDPOINT);
const rpcSubscriptions = createSolanaRpcSubscriptions(WS_ENDPOINT);
const scope = new Scope("mainnet-beta", rpc);
```
</Step>
<Step>
### Build the Refresh Instruction
`refreshPriceListIx` returns one instruction that refreshes the listed slots, or `null` if there is nothing to refresh.
```typescript theme={null}
const ix = await scope.refreshPriceListIx(
{ config: SCOPE_MAINNET_HUBBLE_FEED.configuration },
TOKENS,
);
if (!ix) console.log(`Nothing to refresh for tokens [${TOKENS}]`);
console.log(`Built refresh ix: program ${ix.programAddress}, ${ix.accounts?.length ?? 0} accounts`);
```
<Note>
The refresh is permissionless: any wallet can pay fees and send it. The Scope program writes the new dated prices to the feed's `OraclePrices` account.
</Note>
</Step>
<Step>
### Build, Sign, and Send Transaction
Compose the v0 transaction, sign, verify it fits the size limit, then send and confirm.
```typescript theme={null}
const { value: blockhash } = await rpc
.getLatestBlockhash({ commitment: "finalized" })
.send();
const transactionMessage = pipe(
createTransactionMessage({ version: 0 }),
(m) => setTransactionMessageFeePayerSigner(signer, m),
(m) => setTransactionMessageLifetimeUsingBlockhash(blockhash, m),
(m) => appendTransactionMessageInstructions([ix], m),
);
const signedTransaction = await signTransactionMessageWithSigners(transactionMessage);
assertIsTransactionWithinSizeLimit(signedTransaction);
const signature = getSignatureFromTransaction(signedTransaction);
await sendAndConfirmTransactionFactory({ rpc, rpcSubscriptions })(signedTransaction, {
commitment: "confirmed",
skipPreflight: true,
});
console.log("Refresh successful! Signature:", signature);
```
<Check>
The refresh is complete. The targeted slots now have fresh prices and timestamps on-chain.
</Check>
</Step>
</Steps>
#### Full Code Example
```typescript expandable theme={null}
import {
createSolanaRpc,
createSolanaRpcSubscriptions,
pipe,
createTransactionMessage,
setTransactionMessageFeePayerSigner,
setTransactionMessageLifetimeUsingBlockhash,
appendTransactionMessageInstructions,
signTransactionMessageWithSigners,
getSignatureFromTransaction,
assertIsTransactionWithinSizeLimit,
sendAndConfirmTransactionFactory,
} from "@solana/kit";
import { parseKeypairFile } from "@kamino-finance/klend-sdk/dist/utils/signer";
import { Scope, SCOPE_MAINNET_HUBBLE_FEED } from "@kamino-finance/scope-sdk";
const KEYPAIR_FILE = "/path/to/your/keypair.json";
const RPC_ENDPOINT = "https://api.mainnet-beta.solana.com";
const WS_ENDPOINT = "wss://api.mainnet-beta.solana.com";
const TOKENS = [0, 1, 2];
const signer = await parseKeypairFile(KEYPAIR_FILE);
const rpc = createSolanaRpc(RPC_ENDPOINT);
const rpcSubscriptions = createSolanaRpcSubscriptions(WS_ENDPOINT);
const scope = new Scope("mainnet-beta", rpc);
const ix = await scope.refreshPriceListIx(
{ config: SCOPE_MAINNET_HUBBLE_FEED.configuration },
TOKENS,
);
if (!ix) console.log(`Nothing to refresh for tokens [${TOKENS}]`);
const { value: blockhash } = await rpc
.getLatestBlockhash({ commitment: "finalized" })
.send();
const transactionMessage = pipe(
createTransactionMessage({ version: 0 }),
(m) => setTransactionMessageFeePayerSigner(signer, m),
(m) => setTransactionMessageLifetimeUsingBlockhash(blockhash, m),
(m) => appendTransactionMessageInstructions([ix], m),
);
const signedTransaction = await signTransactionMessageWithSigners(transactionMessage);
assertIsTransactionWithinSizeLimit(signedTransaction);
const signature = getSignatureFromTransaction(signedTransaction);
await sendAndConfirmTransactionFactory({ rpc, rpcSubscriptions })(signedTransaction, {
commitment: "confirmed",
skipPreflight: true,
});
console.log("Refresh successful! Signature:", signature);
```
# Oracle
Source: https://kamino.com/docs/build/developers/oracle/overview
Build with Scope, Kamino's on-chain oracle aggregator: read prices, inspect feed wiring, and refresh price slots
## Overview
Scope is Kamino's oracle aggregation framework for on-chain pricing. The Scope TypeScript SDK and REST endpoints provide direct access to price data, feed configuration, and refresh instructions. In leverage and flash-loan flows, price refreshes are commonly included before execution so reserves and strategies read the latest market data.
<Note>
A Scope feed is a fixed-size account: each `OraclePrices` account holds 512 slots, and a token's USD price is resolved through a "scope chain" of up to 4 slot indices (padded with the sentinel `65535`). For the configuration side, read [Configure oracles](/docs/curators/markets/configuring-oracles) and [Scope oracle types](/docs/curators/markets/scope-oracle-types).
</Note>
## Key Components of Oracle Integration
<CardGroup>
<Card title="Prices" icon="dollar-sign">
Read every populated slot in a feed, or resolve a single token via its scope chain.
</Card>
<Card title="Feed Internals" icon="database">
Inspect a feed's configuration, per-hop chain metadata, and per-slot oracle mappings.
</Card>
<Card title="Refresh" icon="rotate">
Build the permissionless refresh instruction that pushes fresh prices on-chain.
</Card>
</CardGroup>
## Integration Options
<CardGroup>
<Card title="Scope TypeScript SDK" icon="code">
On-chain reads against the Scope program plus the refresh-instruction builder. TypeScript only.
</Card>
<Card title="REST API" icon="globe">
Off-chain aggregated Scope prices keyed by mint. Language-agnostic, no RPC required.
</Card>
</CardGroup>
### Read all prices
<Tabs>
<Tab title="TypeScript">
```typescript theme={null}
import { createSolanaRpc } from '@solana/kit';
import { Scope, SCOPE_MAINNET_HUBBLE_FEED } from '@kamino-finance/scope-sdk';
import Decimal from 'decimal.js';
const rpc = createSolanaRpc('https://api.mainnet-beta.solana.com');
const scope = new Scope('mainnet-beta', rpc);
const oraclePrices = await scope.getSingleOraclePrices({
config: SCOPE_MAINNET_HUBBLE_FEED.configuration,
});
const populated = oraclePrices.prices
.map((p, index) => ({ index, p }))
.filter(({ p }) => p.price.value.toString() !== '0');
console.log(`${populated.length} populated of ${oraclePrices.prices.length} slots`);
populated.slice(0, 5).forEach(({ index, p }) => {
const price = new Decimal(p.price.value.toString()).div(new Decimal(10).pow(Number(p.price.exp)));
console.log(` [${index}] ${price.toString()}`);
});
```
<a href="https://github.com/Kamino-Finance/scope-sdk">
<Icon icon="github" />
<span>View Code</span>
</a>
</Tab>
</Tabs>
### Get a single token price
<Tabs>
<Tab title="TypeScript">
```typescript theme={null}
import { createSolanaRpc } from '@solana/kit';
import { Scope, SCOPE_MAINNET_HUBBLE_FEED } from '@kamino-finance/scope-sdk';
const rpc = createSolanaRpc('https://api.mainnet-beta.solana.com');
const scope = new Scope('mainnet-beta', rpc);
// SOL/USD lives at slot 0 of the Hubble feed. Single-hop chain padded with 65535.
const CHAIN = [0, 65535, 65535, 65535];
const oraclePrices = await scope.getSingleOraclePrices({
config: SCOPE_MAINNET_HUBBLE_FEED.configuration,
});
const { price, timestamp } = await scope.getPriceFromChain(CHAIN, oraclePrices);
console.log(`Price: ${price.toString()} (updated ${new Date(timestamp.toNumber() * 1000).toISOString()})`);
```
<a href="https://github.com/Kamino-Finance/scope-sdk">
<Icon icon="github" />
<span>View Code</span>
</a>
</Tab>
</Tabs>
## What's Covered
<CardGroup>
<Card title="Prices" icon="dollar-sign" href="/docs/build/developers/oracle/data/prices">
Read every populated slot in a feed, or resolve a single token via its scope chain. SDK plus REST.
</Card>
<Card title="Feed Internals" icon="database" href="/docs/build/developers/oracle/data/feeds">
Feed configuration, per-hop chain metadata, and per-slot oracle mappings.
</Card>
<Card title="Refresh Prices" icon="rotate" href="/docs/build/developers/oracle/operations/refresh">
Build and send the permissionless refresh instruction for one or more slots.
</Card>
</CardGroup>
## Relevant Links
<CardGroup>
<Card title="NPM SDK package" icon="npm" href="https://www.npmjs.com/package/@kamino-finance/scope-sdk">
Install the Scope TypeScript SDK to read feeds and build refresh instruc프로젝트로 돌아가기