@kamino-finance/scope-sdk
Version:
Scope Oracle SDK
107 lines • 5.21 kB
TypeScript
import { Address, GetAccountInfoApi, IAccountMeta, IInstruction, Rpc, SolanaRpcApiMainnet, TransactionSigner } from '@solana/kit';
import Decimal from 'decimal.js';
import { Configuration, OracleMappings, OraclePrices } from './@codegen/scope/accounts';
import { OracleTypeKind } from './@codegen/scope/types';
import { FeedParam, PricesParam } from './model';
export type ScopeDatedPrice = {
price: Decimal;
timestamp: Decimal;
};
export declare class Scope {
private readonly _rpc;
private readonly _config;
/**
* Create a new instance of the Scope SDK class.
* @param cluster Name of the Solana cluster
* @param rpc Connection to the Solana rpc
*/
constructor(cluster: 'localnet' | 'devnet' | 'mainnet-beta', rpc: Rpc<SolanaRpcApiMainnet>);
private static priceToDecimal;
/**
* Get the deserialised OraclePrices account for a given feed
* @param feed - either the feed PDA seed or the configuration account address
* @returns OraclePrices
*/
getOraclePrices(feed?: PricesParam): Promise<OraclePrices>;
/**
* Get the deserialised OraclePrices accounts for a given `OraclePrices` account pubkeys
* Optimised to filter duplicate keys from the network request but returns the same size response as requested in the same order
* @throws Error if any of the accounts cannot be fetched
* @param prices - public keys of the `OraclePrices` accounts
* @returns [Address, OraclePrices][]
*/
getMultipleOraclePrices(prices: Address[]): Promise<[Address, OraclePrices][]>;
/**
* Get the deserialised Configuration account for a given feed
* @param feedParam - either the feed PDA seed or the configuration account address
* @returns [configuration account address, deserialised configuration]
*/
getFeedConfiguration(feedParam?: FeedParam): Promise<[Address, Configuration]>;
/**
* Get the deserialised OracleMappings account for a given feed
* @param feed - either the feed PDA seed or the configuration account address
* @returns OracleMappings
*/
getOracleMappings(feed: FeedParam): Promise<OracleMappings>;
/**
* Get the deserialized OracleMappings account for a given feed and config
* @param feed - either the feed PDA seed or the configuration account address
* @param config - the configuration account address
* @param configAccount - the deserialized configuration account
* @returns OracleMappings
*/
getOracleMappingsFromConfig(feed: FeedParam, config: Address, configAccount: Configuration): Promise<OracleMappings>;
/**
* Get the price of a token from a chain of token prices
* @param chain
* @param prices
*/
static getPriceFromScopeChain(chain: Array<number>, prices: OraclePrices): ScopeDatedPrice;
/**
* Verify if the scope chain is valid
* @param chain
*/
static isScopeChainValid(chain: Array<number>): boolean;
/**
* Get the price of a token from a chain of token prices
* @param chain
* @param oraclePrices
*/
getPriceFromChain(chain: Array<number>, oraclePrices?: OraclePrices): Promise<ScopeDatedPrice>;
/**
* Create a new scope price feed
* @param admin
* @param feed
*/
initialise(admin: TransactionSigner, feed: string): Promise<[
IInstruction[],
TransactionSigner[],
{
configuration: Address;
oracleMappings: Address;
oraclePrices: Address;
oracleTwaps: Address;
}
]>;
/**
* Update the price mapping of a token
* @param admin
* @param feed
* @param index
* @param oracleType
* @param mapping
* @param twapEnabled
* @param twapSource
* @param refPriceIndex
* @param genericData
*/
updateFeedMapping(admin: TransactionSigner, feed: string, index: number, oracleType: OracleTypeKind, mapping: Address, twapEnabled?: boolean, twapSource?: number, refPriceIndex?: number, genericData?: Array<number>): Promise<IInstruction>;
refreshPriceList(feed: FeedParam, tokens: number[]): Promise<IInstruction>;
refreshPriceListIx(feed: FeedParam, tokens: number[]): Promise<IInstruction<string, readonly (IAccountMeta<string> | import("@solana/kit").IAccountLookupMeta<string, string>)[]>>;
refreshPriceListIxWithAccounts(tokens: number[], configAccount: Configuration, mappings: OracleMappings): Promise<IInstruction<string, readonly (IAccountMeta<string> | import("@solana/kit").IAccountLookupMeta<string, string>)[]>>;
static getRefreshAccounts(connection: Rpc<GetAccountInfoApi>, configAccount: Configuration, kaminoProgramId: Address, mappings: OracleMappings, token: number): Promise<IAccountMeta[]>;
static getJlpRefreshAccounts(rpc: Rpc<GetAccountInfoApi>, configAccount: Configuration, mappings: OracleMappings, token: number, fetchingMechanism: 'compute' | 'scope'): Promise<IAccountMeta[]>;
static getKTokenRefreshAccounts(connection: Rpc<GetAccountInfoApi>, kaminoProgramId: Address, mappings: OracleMappings, token: number): Promise<IAccountMeta[]>;
}
export default Scope;
//# sourceMappingURL=Scope.d.ts.map