/** * @name perps/perp-constants * @description Constants, discriminators, offsets, market maps, types, and helper functions * for Adrena perp account decoding and REST API access. * * @module perps/perp-constants */ import type { SapMcpContext } from '../../core/src/types.js'; /** Adrena program ID on Solana mainnet. Can be overridden by hosted env config. */ export declare const DEFAULT_ADRENA_PROGRAM_ID = "13gDzEXCdocbj8iAiqrScGo47NiSuYENGsRqi3SEAwet"; /** DexScreener REST API base URL (free, no API key). */ export declare const DEXSCREENER_API_URL = "https://api.dexscreener.com"; /** DeFiLlama REST API base URL (free, no API key). */ export declare const DEFILAMA_API_URL = "https://api.llama.fi"; /** Fetch timeout for external API calls (ms). */ export declare const FETCH_TIMEOUT_MS = 8000; /** Default number of volume profile buckets. */ export declare const DEFAULT_VP_BUCKETS = 20; /** Value area percentage for volume profile (70%). */ export declare const VALUE_AREA_PCT = 0.7; /** Pool account discriminator — sha256("account:Pool")[0..8]. */ export declare const DISC_POOL: Buffer; /** Custody account discriminator — sha256("account:Custody")[0..8]. */ export declare const DISC_CUSTODY: Buffer; /** Position account discriminator — sha256("account:Position")[0..8]. */ export declare const DISC_POSITION: Buffer; /** Adrena release/39 constants from the official ABI. */ export declare const ADRENA_USD_DECIMALS = 6; export declare const ADRENA_PRICE_DECIMALS = 10; export declare const ADRENA_BPS_DECIMALS = 4; /** Absolute offsets include the 8-byte Anchor account discriminator. */ export declare const ADRENA_CUSTODY_OFFSETS: { readonly allowTrade: 10; readonly allowSwap: 11; readonly decimals: 12; readonly pool: 16; readonly mint: 48; readonly tokenAccount: 80; readonly oracle: 112; readonly tradeOracle: 144; readonly maxInitialLeverage: 176; readonly maxLeverage: 180; readonly maxPositionLockedUsd: 184; readonly volumeOpenPositionUsd: 320; readonly tradeOiLongUsd: 360; readonly tradeOiShortUsd: 368; readonly assetsCollateral: 376; readonly assetsOwned: 384; readonly assetsLocked: 392; readonly longPositionsOpenCount: 400; readonly longPositionsSizeUsd: 408; readonly longPositionsBorrowSizeUsd: 416; readonly longPositionsLockedAmount: 424; readonly longPositionsCollateralUsd: 472; readonly shortPositionsOpenCount: 600; readonly shortPositionsSizeUsd: 608; readonly shortPositionsBorrowSizeUsd: 616; readonly shortPositionsLockedAmount: 624; readonly shortPositionsCollateralUsd: 672; readonly borrowRateCurrent: 800; readonly borrowRateLastUpdate: 808; readonly optimalUtilizationBps: 832; readonly virtualFundingMaxHourlyRate: 840; readonly virtualFundingMinTotalOiUsd: 848; readonly virtualFundingImbalanceSensitivityBps: 856; readonly virtualFundingCurrentLongToShort: 864; readonly virtualFundingLastUpdate: 872; readonly virtualFundingCumulativeLongToShort: 880; readonly virtualFundingCumulativeShortToLong: 896; readonly isSynthetic: 912; readonly version: 913; readonly oracleFeedId: 914; readonly tradeOracleFeedId: 915; }; export declare const ADRENA_POOL_OFFSETS: { readonly allowTrade: 12; readonly allowSwap: 13; readonly registeredCustodyCount: 15; readonly name: 16; readonly custodies: 48; readonly lpTokenPriceUsd: 328; readonly aumUsd: 448; }; export declare const ADRENA_POSITION_OWNER_MEMCMP_OFFSET = 16; export declare const ADRENA_POSITION_OFFSETS: { readonly side: 9; readonly owner: 16; readonly pool: 48; readonly custody: 80; readonly collateralCustody: 112; readonly openTime: 144; readonly updateTime: 152; readonly price: 160; readonly sizeUsd: 168; readonly borrowSizeUsd: 176; readonly collateralUsd: 184; readonly unrealizedInterestUsd: 192; readonly lockedAmount: 216; readonly collateralAmount: 224; readonly exitFeeUsd: 232; readonly liquidationFeeUsd: 240; readonly id: 248; readonly takeProfitLimitPrice: 256; readonly paidInterestUsd: 264; readonly stopLossLimitPrice: 272; readonly stopLossClosePositionPrice: 280; readonly unrealizedFundingPaidUsd: 328; readonly unrealizedFundingReceivedUsd: 336; }; export declare const ADRENA_MAINNET_POOLS: Record; export declare const ADRENA_MAINNET_MARKETS_BY_CUSTODY: Record; /** JSON Schema property definition for MCP tool input schemas. */ export interface JsonSchemaProperty { readonly type: string; readonly description: string; readonly enum?: readonly string[]; readonly items?: JsonSchemaProperty; readonly properties?: Record; readonly additionalProperties?: boolean; readonly minimum?: number; readonly maximum?: number; } /** Complete JSON Schema object for an MCP tool input. */ export interface JsonSchema { readonly type: 'object'; readonly properties: Record; readonly required?: readonly string[]; readonly additionalProperties?: boolean; } export interface DexScreenerPair { pairAddress?: string; baseToken?: { address?: string; symbol?: string; }; priceUsd?: string; priceChange?: Record; volume?: Record; liquidity?: { usd?: number; }; fdv?: number; info?: { imageUrl?: string; }; } export interface DefiLlamaProtocol { id?: string; name?: string; tvl?: number; chain?: string; change_1d?: number; change_7d?: number; marketcap?: number; } export interface PerpPosition { positionKey: string; market: string; side: 'long' | 'short'; size: number; collateral: number; entryPrice: number; markPrice: number; leverage: number; unrealizedPnl: number; liquidationPrice: number; } export interface OhlcCandle { timestamp: number; open: number; high: number; low: number; close: number; volume: number; } export interface VolumeProfileBucket { priceLow: number; priceHigh: number; volume: number; pctOfTotal: number; } export interface VolumeProfileResult { poc: number; vah: number; val: number; buckets: VolumeProfileBucket[]; } export interface LiquidationZone { positionKey: string; market: string; side: 'long' | 'short'; liquidationPrice: number; currentPrice: number; distanceToLiquidationPct: number; leverage: number; } export interface PerpsProviderConfig { marketsUrl?: string; positionsUrl?: string; builderUrl?: string; adrenaProgramId: string; apiKeyConfigured: boolean; timeoutMs: number; } export interface PerpMarketProviderRecord { symbol?: string; market?: string; custodyAddress?: string; poolAddress?: string; custodyMint?: string; markPrice?: number; fundingRate?: number; openInterestLong?: number; openInterestShort?: number; volume24h?: number; provider?: string; [key: string]: unknown; } export interface PerpMarketsProviderPayload { markets?: PerpMarketProviderRecord[]; data?: PerpMarketProviderRecord[]; source?: string; venue?: string; timestamp?: number; [key: string]: unknown; } export interface PerpBuilderProviderPayload { transactionBase64?: string; unsignedTransactionBase64?: string; transaction?: string; lastValidBlockHeight?: number; blockhash?: string; feePayer?: string; provider?: string; warnings?: unknown; [key: string]: unknown; } export interface DecodedAdrenaPool { poolAddress: string; name: string; type?: string; allowTrade: boolean; allowSwap: boolean; registeredCustodyCount: number; custodies: string[]; lpTokenPriceUsd: number; aumUsd: number; } export interface DecodedAdrenaCustody { symbol: string; market: string; custodyAddress: string; poolAddress: string; poolName?: string; poolType?: string; custodyMint: string; tokenAccount: string; oracle: string; tradeOracle: string; oracleFeedId: number; tradeOracleFeedId: number; decimals: number; allowTrade: boolean; allowSwap: boolean; isStable: boolean; isSynthetic: boolean; version: number; kind: 'collateral' | 'perp' | 'synthetic-perp' | 'unknown'; markPrice: number | null; markPriceSource: 'not_in_custody_account'; maxInitialLeverage: number; maxLeverage: number; maxPositionLockedUsd: number; openInterestLong: number; openInterestShort: number; openPositionsLong: number; openPositionsShort: number; borrowSizeLongUsd: number; borrowSizeShortUsd: number; collateralLongUsd: number; collateralShortUsd: number; lockedAmountLongRaw: string; lockedAmountShortRaw: string; tradeOiLongUsd: number; tradeOiShortUsd: number; cumulativeOpenPositionUsd: number; assetsRaw: { collateral: string; owned: string; locked: string; }; borrowRate: { currentRateRaw: string; lastUpdate: number; }; funding: { currentRateLongToShortRaw: string; lastUpdate: number; cumulativeLongToShortRaw: string; cumulativeShortToLongRaw: string; maxHourlyFundingRateRaw: string; minTotalOiUsd: number; imbalanceSensitivityBps: number; }; } export interface DecodedAdrenaPosition { positionKey: string; market: string; side: 'long' | 'short'; sideRaw: number; owner: string; poolAddress: string; custodyAddress: string; collateralCustodyAddress: string; openTime: number; updateTime: number; entryPrice: number; entryPriceRaw: string; size: number; collateral: number; borrowSizeUsd: number; leverage: number; unrealizedPnl: number; unrealizedInterestUsd: number; unrealizedFundingPaidUsd: number; unrealizedFundingReceivedUsd: number; lockedAmountRaw: string; collateralAmountRaw: string; liquidationPrice: number; takeProfitLimitPrice: number | null; stopLossLimitPrice: number | null; stopLossClosePositionPrice: number | null; id: string; } /** * @name timedFetch * @description Fetch JSON from a URL with an abort timeout. * * @param url — The URL to fetch. * @returns Parsed JSON response, or `null` on error/timeout. * * @internal */ export declare function timedFetch(url: string, options?: { method?: 'GET' | 'POST'; headers?: Record; body?: string; timeoutMs?: number; }): Promise; export declare function getPerpsConfig(context: SapMcpContext): PerpsProviderConfig; export declare function appendQuery(baseUrl: string, params: Record): string; export declare function perpsProviderHeaders(): Record; export declare function normalizePerpProviderMarkets(payload: unknown, marketFilter?: string): PerpMarketProviderRecord[]; //# sourceMappingURL=perp-constants.d.ts.map