UNPKG

@shogun-sdk/money-legos

Version:

Shogun Money Legos: clients and types for quotes, memes, prices, balances, fees, validations, etc.

657 lines (579 loc) 12.3 kB
export type Tif = 'Alo' | 'Ioc' | 'Gtc'; export type TriggerType = 'tp' | 'sl'; export type LimitOrder = { tif: Tif }; export type TriggerOrder = { triggerPx: string | number; isMarket: boolean; tpsl: TriggerType }; export type Grouping = 'na' | 'normalTpsl' | 'positionTpsl'; export type OrderType = { limit?: LimitOrder; trigger?: TriggerOrder }; export type Cloid = string; export type OidOrCloid = number | Cloid; export interface HyperliquidOrder extends BaseOrder { orders?: undefined; coin: string; is_buy: boolean; sz: number; limit_px: number; order_type: OrderType; reduce_only: boolean; cloid?: Cloid; } export type OrderRequest = HyperliquidOrder | MultiOrder; interface BaseOrder { vaultAddress?: string; grouping?: Grouping; builder?: Builder; } interface MultiOrder extends BaseOrder { orders: HyperliquidOrder[]; } export interface Builder { address: string; fee: number; } export interface AllMids { [coin: string]: string; } export type PerpMeta = { universe: { name: string; szDecimals: number; maxLeverage: number; onlyIsolated?: boolean; }[]; }; export interface ClearinghouseState { assetPositions: { position: { coin: string; cumFunding: { allTime: string; sinceChange: string; sinceOpen: string; }; entryPx: string; leverage: { rawUsd: string; type: string; value: number; }; liquidationPx: string; marginUsed: string; maxLeverage: number; positionValue: string; returnOnEquity: string; szi: string; unrealizedPnl: string; }; type: string; }[]; crossMaintenanceMarginUsed: string; crossMarginSummary: { accountValue: string; totalMarginUsed: string; totalNtlPos: string; totalRawUsd: string; }; marginSummary: { accountValue: string; totalMarginUsed: string; totalNtlPos: string; totalRawUsd: string; }; time: number; withdrawable: string; } export type UserFills = { closedPnl: string; coin: string; crossed: boolean; dir: string; hash: string; oid: number; px: string; side: string; startPosition: string; sz: string; time: number; }[]; export interface OrderResponse { status: string; response: { type: string; data: { statuses: Array<{ resting?: { oid: number }; filled?: { oid: number; totalSz: string; avgPx: string; }; }>; }; }; } export interface Leverage { type: 'cross' | 'isolated'; value: number; rawUsd?: string; } export interface SpotClearinghouseState { balances: { coin: string; hold: string; total: string; }[]; } export type FrontendOpenOrders = { coin: string; isPositionTpsl: boolean; isTrigger: boolean; limitPx: string; oid: number; orderType: string; origSz: string; reduceOnly: boolean; side: string; sz: string; timestamp: number; triggerCondition: string; triggerPx: string; }[]; export interface UserRateLimit { [key: string]: any; } export interface OrderStatus { [key: string]: any; } export interface L2Book { levels: [ { px: string; sz: string; n: number; }[], { px: string; sz: string; n: number; }[], ]; } export type CandleSnapshot = { T: number; c: string; h: string; i: string; l: string; n: number; o: string; s: string; t: number; v: string; }[]; export type AssetCtx = { dayBaseVlm: string; dayNtlVlm: string; funding: string; impactPxs: [string, string]; markPx: string; midPx: string; openInterest: string; oraclePx: string; premium: string; prevDayPx: string; }; export type PerpMetaAndAssetCtxs = [PerpMeta, AssetCtx[]]; export interface UserFundingDelta { coin: string; fundingRate: string; szi: string; type: 'funding'; usdc: string; } export interface UserFundingEntry { delta: UserFundingDelta; hash: string; time: number; } export type UserFunding = UserFundingEntry[]; export interface UserNonFundingLedgerDelta { coin: string; type: 'deposit' | 'withdraw' | 'transfer' | 'liquidation'; usdc: string; } export interface UserNonFundingLedgerEntry { delta: UserNonFundingLedgerDelta; hash: string; time: number; } export type UserNonFundingLedgerUpdates = UserNonFundingLedgerEntry[]; export interface FundingHistoryEntry { coin: string; fundingRate: string; premium: string; time: number; } export type FundingHistory = FundingHistoryEntry[]; export interface SpotToken { name: string; szDecimals: number; weiDecimals: number; index: number; tokenId: string; isCanonical: boolean; } export interface SpotMarket { name: string; tokens: [number, number]; // Indices of base and quote tokens index: number; isCanonical: boolean; } export type SpotMeta = { tokens: SpotToken[]; universe: SpotMarket[]; }; export type SpotAssetCtx = { circulatingSupply: string; coin: string; dayBaseVlm: string; dayNtlVlm: string; markPx: string; midPx: string; prevDayPx: string; totalSupply: string; }; export type SpotMetaAndAssetCtxs = [SpotMeta, SpotAssetCtx[]]; export interface UserOpenOrder { coin: string; limitPx: string; oid: number; side: string; sz: string; timestamp: number; } export type UserOpenOrders = UserOpenOrder[]; export interface OrderWire { a: number; b: boolean; p: string; s: string; r: boolean; t: OrderType; c?: string; } export interface CancelOrderRequest { coin: string; o: number; } export type CancelOrderRequests = { a: number; o: number; }[]; export interface CancelByCloidRequest { coin: string; cloid: Cloid; } export interface ModifyRequest { oid: OidOrCloid; order: OrderRequest; } export interface ModifyWire { oid: number; order: OrderWire; } export interface ScheduleCancelAction { type: 'scheduleCancel'; time?: number | null; } export interface Signature { r: string; s: string; v: number; } export interface Notification { notification: string; user: string; } // As flexible as possible export interface WebData2 { [key: string]: any; } export interface Candle { t: number; // open time T: number; // close time s: string; // symbol i: string; // interval o: string; // open c: string; // close h: string; // high l: string; // low v: string; // volume n: number; // number of trades coin: string; interval: string; } export interface TwapOrder { coin: string; is_buy: boolean; sz: number; reduce_only: boolean; minutes: number; randomize: boolean; } export interface TwapCancelRequest { coin: string; twap_id: number; } export interface TwapOrderResponse { status: string; response: { type: string; data: { status: { running: { twapId: number; }; }; }; }; } export interface TwapCancelResponse { status: string; response: { type: string; data: { status: string; }; }; } export interface PredictedFunding { fundingRate: string; nextFundingTime: number; } export interface VenueFunding { [venue: string]: PredictedFunding; } export interface PredictedFundings { [coin: string]: VenueFunding[]; } export interface TokenDetails { name: string; maxSupply: string; totalSupply: string; circulatingSupply: string; szDecimals: number; weiDecimals: number; midPx: string; markPx: string; prevDayPx: string; genesis: { userBalances: [string, string][]; existingTokenBalances: [number, string][]; }; deployer: string; deployGas: string; deployTime: string; seededUsdc: string; nonCirculatingUserBalances: string[]; futureEmissions: string; } export interface SpotDeployState { states: { token: number; spec: { name: string; szDecimals: number; weiDecimals: number; }; fullName: string; spots: number[]; maxSupply: number; hyperliquidityGenesisBalance: string; totalGenesisBalanceWei: string; userGenesisBalances: [string, string][]; existingTokenGenesisBalances: [number, string][]; }[]; gasAuction: { startTimeSeconds: number; durationSeconds: number; startGas: string; currentGas: string | null; endGas: string; }; } export interface SubAccount { name: string; subAccountUser: string; master: string; clearinghouseState: ClearinghouseState; spotState: { balances: { coin: string; token: number; total: string; hold: string; entryNtl: string; }[]; }; } export interface PortfolioPeriodData { accountValueHistory: [number, string][]; pnlHistory: [number, string][]; vlm: string; } export interface VaultFollower { user: string; vaultEquity: string; pnl: string; allTimePnl: string; daysFollowing: number; vaultEntryTime: number; lockupUntil: number; } export interface VaultDetails { name: string; vaultAddress: string; leader: string; description: string; portfolio: [string, PortfolioPeriodData][]; apr: number; followerState: any; leaderFraction: number; leaderCommission: number; followers: VaultFollower[]; maxDistributable: number; maxWithdrawable: number; isClosed: boolean; relationship: { type: string; data: { childAddresses: string[]; }; }; allowDeposits: boolean; alwaysCloseOnWithdraw: boolean; } export interface VaultEquity { vaultAddress: string; equity: string; } export interface HistoricalOrder { order: { coin: string; side: string; limitPx: string; sz: string; oid: number; timestamp: number; triggerCondition: string; isTrigger: boolean; triggerPx: string; children: any[]; isPositionTpsl: boolean; reduceOnly: boolean; orderType: string; origSz: string; tif: string; cloid: string | null; }; status: 'filled' | 'open' | 'canceled' | 'triggered' | 'rejected' | 'marginCanceled'; statusTimestamp: number; } export interface TwapSliceFill { fill: { closedPnl: string; coin: string; crossed: boolean; dir: string; hash: string; oid: number; px: string; side: string; startPosition: string; sz: string; time: number; fee: string; feeToken: string; tid: number; }; twapId: number; } export interface ApproveAgentRequest { agentAddress: string; agentName?: string; } export interface ApproveBuilderFeeRequest { maxFeeRate: string; builder: string; } export interface Delegation { validator: string; amount: string; lockedUntilTimestamp: number; } export interface DelegatorSummary { delegated: string; undelegated: string; totalPendingWithdrawal: string; nPendingWithdrawals: number; } export interface DelegatorHistoryEntry { time: number; hash: string; delta: { delegate: { validator: string; amount: string; isUndelegate: boolean; }; }; } export interface DelegatorReward { time: number; source: string; totalAmount: string; } export type PerpsAtOpenInterestCap = string[]; export type UserRole = 'missing' | 'user' | 'agent' | 'vault' | 'subAccount'; export type AccountValueHistoryEntry = { timestamp: number; value: string; }; export type PnlHistoryEntry = { timestamp: number; pnl: string; }; export type TimePeriodData = { accountValueHistory: AccountValueHistoryEntry[]; pnlHistory: PnlHistoryEntry[]; vlm: string; }; export type Portfolio = { day: TimePeriodData; week: TimePeriodData; month: TimePeriodData; allTime: TimePeriodData; perpDay: TimePeriodData; perpWeek: TimePeriodData; perpMonth: TimePeriodData; perpAllTime: TimePeriodData; }; export type FunctionResult<T> = { success: true; data: T } | { success: false; error?: string }; export interface batchedDepositWithPermitPayload { user: string; usd: bigint; deadline: bigint; signature: (string | 27 | 28)[]; } export interface batchedDepositWithPermitPayloadDto { user: string; usd: string; deadline: string; signature: string; } export type PermitPayload = { owner: `0x${string}`; spender: `0x${string}`; value: bigint; nonce: bigint; deadline: bigint; };