@drift-labs/common
Version:
Common functions for Drift
95 lines (94 loc) • 3.88 kB
TypeScript
import { MarketType, PerpMarketConfig, SpotMarketConfig } from '@drift-labs/sdk';
import { MarketId } from './MarketId';
import { Opaque } from './utility';
/**
* MarketSymbol will uniquely identify a market
*/
export type MarketSymbol = Opaque<string, 'MarketSymbol'>;
/**
* MarketDisplaySymbol is the label for a market that we display to a user
*/
export type MarketDisplaySymbol = Opaque<string, 'MarketDisplaySymbol'>;
/**
* BaseAssetSymbol is the symbol for the underlying asset for a market
*/
export type BaseAssetSymbol = Opaque<string, 'BaseAssetSymbol'>;
/**
* BaseAssetDisplaySymbol is the label for the underlying asset for a market that we display to a user
*/
export type BaseAssetDisplaySymbol = Opaque<string, 'BaseAssetDisplaySymbol'>;
/**
* # Examples and explanations of the symbol types:
*
* ## MarketSymbol:
* These are basically just the raw symbols in the market configs.
* - 1KWEN-PERP
* - JitoSOL-3
* - PT-fragSOL-15JUN25-3
*
* ## MarketDisplaySymbol:
* This is the symbol we use to display the market to the user. For SPOT markets it should be the exact same as the BaseAssetDisplaySymbol, but for PERP markets they might be different which is why we have this separate type.
*
* - 1KWEN-PERP => 1KWEN-PERP
* - JitoSOL-3 => JitoSOL
* - PT-fragSOL-15JUN25-3 => PT-fragSOL-15JUN25
*
* ## BaseAssetDisplaySymbol:
* This is the symbol we use to communicate "what asset they are holding". For SPOT markets it should be the same as the MarketDisplaySymbol, but for PERP markets it may be different, for example we show open interest denominated in "1KWEN", while the market is "1KWEN-PERP".
*
* - 1KWEN-PERP => 1KWEN
* - JitoSOL-3 => JitoSOL
* - PT-fragSOL-15JUN25-3 => fragSOL
*
* ## BaseAssetSymbol:
* This is the symbol for the underlying asset for a market. I don't believe we will display this anywhere but we use these for example when looking up the market icon to use.
*
* - 1KWEN-PERP => WEN
* - JitoSOL-3 => JitoSOL
* - PT-fragSOL-15JUN25-3 => PT-fragSOL-15JUN25 (note: PT-fragSOL has an icon different to regular fragSOL, otherwise we would use 'fragSOL' for the base asset symbol)
*/
type UISymbols = {
marketSymbol: MarketSymbol;
marketDisplaySymbol: MarketDisplaySymbol;
baseAssetSymbol: BaseAssetSymbol;
baseAssetDisplaySymbol: BaseAssetDisplaySymbol;
};
export declare class UIMarket {
readonly marketIndex: number;
readonly marketType: MarketType;
static perpMarkets: PerpMarketConfig[];
static spotMarkets: SpotMarketConfig[];
private static cache;
readonly market: SpotMarketConfig | PerpMarketConfig;
readonly marketId: MarketId;
private _uiSymbols;
get uiSymbols(): UISymbols;
private set uiSymbols(value);
constructor(marketIndex: number, marketType: MarketType);
static setPerpMarkets(perpMarkets: PerpMarketConfig[]): void;
static setSpotMarkets(spotMarkets: SpotMarketConfig[]): void;
private static getOrCreate;
static createSpotMarket(marketIndex: number): UIMarket;
static createPerpMarket(marketIndex: number): UIMarket;
static fromMarketId(marketId: MarketId): UIMarket;
static checkIsPredictionMarket(marketConfig: PerpMarketConfig): boolean;
get isSpot(): boolean;
get isPerp(): boolean;
get marketTypeStr(): string;
get key(): import("./MarketId").MarketKey;
get marketName(): string;
get symbol(): string;
get isUsdcMarket(): boolean;
get isStableCoinMarket(): boolean;
get isPredictionMarket(): boolean;
get precision(): import("bn.js");
get precisionExp(): import("bn.js");
equals(other: UIMarket): boolean;
baseAssetSymbol(removePrefix?: boolean): string;
protected setUiSymbols(): void;
private getMarketSymbol;
private getMarketDisplaySymbol;
private getBaseAssetSymbol;
private getBaseAssetDisplaySymbol;
}
export {};