@drift-labs/common 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/clients/swiftClient.d.ts +5 -1
- package/lib/clients/swiftClient.js +17 -7
- package/lib/clients/swiftClient.js.map +1 -1
- package/lib/clients/tvFeed.d.ts +3 -1
- package/lib/clients/tvFeed.js +27 -13
- package/lib/clients/tvFeed.js.map +1 -1
- package/lib/common-ui-utils/commonUiUtils.d.ts +7 -0
- package/lib/common-ui-utils/market.d.ts +6 -1
- package/lib/common-ui-utils/market.js +46 -0
- package/lib/common-ui-utils/market.js.map +1 -1
- package/lib/common-ui-utils/order.d.ts +8 -1
- package/lib/common-ui-utils/order.js +39 -0
- package/lib/common-ui-utils/order.js.map +1 -1
- package/lib/common-ui-utils/user.js +1 -0
- package/lib/common-ui-utils/user.js.map +1 -1
- package/lib/constants/markets.d.ts +1 -0
- package/lib/constants/markets.js +2 -1
- package/lib/constants/markets.js.map +1 -1
- package/lib/drift/Drift/clients/AuthorityDrift/DriftOperations/index.d.ts +1 -6
- package/lib/drift/Drift/clients/AuthorityDrift/DriftOperations/index.js +17 -28
- package/lib/drift/Drift/clients/AuthorityDrift/DriftOperations/index.js.map +1 -1
- package/lib/drift/Drift/clients/AuthorityDrift/DriftOperations/types.d.ts +6 -2
- package/lib/drift/Drift/clients/AuthorityDrift/DriftOperations/types.js.map +1 -1
- package/lib/drift/Drift/clients/AuthorityDrift/index.d.ts +1 -2
- package/lib/drift/Drift/clients/AuthorityDrift/index.js.map +1 -1
- package/lib/drift/Drift/clients/CentralServerDrift.d.ts +10 -5
- package/lib/drift/Drift/clients/CentralServerDrift.js +5 -48
- package/lib/drift/Drift/clients/CentralServerDrift.js.map +1 -1
- package/lib/drift/Drift/constants/errors.d.ts +9 -1
- package/lib/drift/Drift/constants/errors.js +13 -2
- package/lib/drift/Drift/constants/errors.js.map +1 -1
- package/lib/drift/Drift/data/PollingDlob.d.ts +0 -20
- package/lib/drift/Drift/data/PollingDlob.js +2 -78
- package/lib/drift/Drift/data/PollingDlob.js.map +1 -1
- package/lib/drift/base/actions/perp/settlePnl.d.ts +3 -3
- package/lib/drift/base/actions/perp/settlePnl.js +3 -3
- package/lib/drift/base/actions/perp/settlePnl.js.map +1 -1
- package/lib/drift/base/actions/spot/index.d.ts +0 -1
- package/lib/drift/base/actions/spot/index.js +0 -1
- package/lib/drift/base/actions/spot/index.js.map +1 -1
- package/lib/drift/base/actions/trade/openPerpOrder/dlobServer/index.d.ts +81 -0
- package/lib/drift/base/actions/trade/openPerpOrder/dlobServer/index.js +255 -0
- package/lib/drift/base/actions/trade/openPerpOrder/dlobServer/index.js.map +1 -0
- package/lib/drift/base/actions/trade/openPerpOrder/index.d.ts +2 -0
- package/lib/drift/base/actions/trade/openPerpOrder/index.js +2 -0
- package/lib/drift/base/actions/trade/openPerpOrder/index.js.map +1 -1
- package/lib/drift/base/actions/trade/openPerpOrder/openPerpMarketOrder/index.d.ts +53 -43
- package/lib/drift/base/actions/trade/openPerpOrder/openPerpMarketOrder/index.js +180 -201
- package/lib/drift/base/actions/trade/openPerpOrder/openPerpMarketOrder/index.js.map +1 -1
- package/lib/drift/base/actions/trade/openPerpOrder/openPerpNonMarketOrder/index.d.ts +37 -9
- package/lib/drift/base/actions/trade/openPerpOrder/openPerpNonMarketOrder/index.js +194 -83
- package/lib/drift/base/actions/trade/openPerpOrder/openPerpNonMarketOrder/index.js.map +1 -1
- package/lib/drift/base/actions/trade/openPerpOrder/openSwiftOrder/index.d.ts +40 -27
- package/lib/drift/base/actions/trade/openPerpOrder/openSwiftOrder/index.js +111 -32
- package/lib/drift/base/actions/trade/openPerpOrder/openSwiftOrder/index.js.map +1 -1
- package/lib/drift/base/actions/trade/openPerpOrder/types.d.ts +64 -0
- package/lib/drift/base/actions/trade/openPerpOrder/types.js +3 -0
- package/lib/drift/base/actions/trade/openPerpOrder/types.js.map +1 -0
- package/lib/drift/base/actions/user/create.js +9 -3
- package/lib/drift/base/actions/user/create.js.map +1 -1
- package/lib/drift/cli.js +114 -71
- package/lib/drift/cli.js.map +1 -1
- package/lib/drift/index.d.ts +1 -0
- package/lib/drift/index.js +1 -0
- package/lib/drift/index.js.map +1 -1
- package/lib/drift/utils/auctionParamsResponseMapper.d.ts +25 -23
- package/lib/drift/utils/auctionParamsResponseMapper.js +4 -6
- package/lib/drift/utils/auctionParamsResponseMapper.js.map +1 -1
- package/lib/drift/utils/index.d.ts +1 -1
- package/lib/drift/utils/index.js +1 -4
- package/lib/drift/utils/index.js.map +1 -1
- package/lib/drift/utils/orderParams.d.ts +3 -28
- package/lib/drift/utils/orderParams.js +9 -1
- package/lib/drift/utils/orderParams.js.map +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -1
- package/lib/types/user.d.ts +1 -0
- package/lib/types/user.js.map +1 -1
- package/lib/utils/fetch.d.ts +1 -0
- package/lib/utils/fetch.js +11 -0
- package/lib/utils/fetch.js.map +1 -0
- package/lib/utils/orderbook/index.d.ts +18 -0
- package/lib/utils/orderbook/index.js +68 -1
- package/lib/utils/orderbook/index.js.map +1 -1
- package/lib/utils/priceImpact.d.ts +14 -0
- package/lib/utils/priceImpact.js +71 -0
- package/lib/utils/priceImpact.js.map +1 -0
- package/package.json +1 -1
- package/lib/drift/base/actions/spot/borrow.d.ts +0 -1
- package/lib/drift/base/actions/spot/borrow.js +0 -8
- package/lib/drift/base/actions/spot/borrow.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../src/drift/Drift/clients/AuthorityDrift/DriftOperations/types.ts"],"names":[],"mappings":"","sourcesContent":["import {\n\tBigNum,\n\tPositionDirection,\n\tPostOnlyParams,\n\tQuoteResponse,\n} from '@drift-labs/sdk';\nimport {
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../src/drift/Drift/clients/AuthorityDrift/DriftOperations/types.ts"],"names":[],"mappings":"","sourcesContent":["import {\n\tBigNum,\n\tPositionDirection,\n\tPostOnlyParams,\n\tQuoteResponse,\n} from '@drift-labs/sdk';\nimport { OptionalAuctionParamsRequestInputs } from '../../../../base/actions/trade/openPerpOrder/dlobServer';\nimport { SwiftOrderOptions } from '../../../../base/actions/trade/openPerpOrder/openSwiftOrder';\n\n/**\n * Interface for deposit operation parameters.\n */\nexport interface DepositParams {\n\tsubAccountId: number;\n\tamount: BigNum;\n\tspotMarketIndex: number;\n\tisMaxBorrowRepayment?: boolean;\n}\n\n/**\n * Interface for withdraw operation parameters.\n */\nexport interface WithdrawParams {\n\tsubAccountId: number;\n\tamount: BigNum;\n\tspotMarketIndex: number;\n\tisBorrow?: boolean;\n\tisMax?: boolean;\n}\n\n/**\n * Interface for create user and deposit operation parameters.\n */\nexport interface CreateUserAndDepositParams {\n\tdepositAmount: BigNum;\n\tdepositSpotMarketIndex: number;\n\tnewAccountName?: string;\n\tmaxLeverage?: number;\n\tpoolId?: number;\n\tsubAccountId?: number;\n\treferrerName?: string;\n}\n\n/**\n * Interface for perp market order parameters.\n */\nexport type PerpOrderParams = {\n\tsubAccountId: number;\n\tmarketIndex: number;\n\tdirection: PositionDirection;\n\tassetType: 'base' | 'quote';\n\tsize: BigNum;\n\treduceOnly?: boolean;\n\tpostOnly?: PostOnlyParams;\n\tisMaxLeverage?: boolean;\n\torderConfig:\n\t\t| {\n\t\t\t\torderType: 'market';\n\t\t\t\tdisableSwift?: boolean;\n\t\t\t\toptionalAuctionParamsInputs?: OptionalAuctionParamsRequestInputs;\n\t\t\t\tpostOnly?: never;\n\t\t\t\tbracketOrders?: {\n\t\t\t\t\ttakeProfitPrice?: BigNum;\n\t\t\t\t\tstopLossPrice?: BigNum;\n\t\t\t\t};\n\t\t\t\tswiftOptions?: Omit<SwiftOrderOptions, 'wallet' | 'swiftServerUrl'>;\n\t\t }\n\t\t| {\n\t\t\t\torderType: 'limit';\n\t\t\t\tlimitPrice: BigNum;\n\t\t\t\tdisableSwift?: boolean;\n\t\t\t\tbracketOrders?: {\n\t\t\t\t\ttakeProfitPrice?: BigNum;\n\t\t\t\t\tstopLossPrice?: BigNum;\n\t\t\t\t};\n\t\t\t\tswiftOptions?: Omit<SwiftOrderOptions, 'wallet' | 'swiftServerUrl'>;\n\t\t }\n\t\t| {\n\t\t\t\torderType: 'takeProfit' | 'stopLoss';\n\t\t\t\ttriggerPrice: BigNum;\n\t\t\t\tlimitPrice?: BigNum;\n\t\t }\n\t\t| {\n\t\t\t\torderType: 'oracleLimit';\n\t\t\t\toraclePriceOffset: BigNum;\n\t\t };\n};\n\n/**\n * Interface for swap operation parameters.\n */\nexport interface SwapParams {\n\tfromMarketIndex: number;\n\ttoMarketIndex: number;\n\tamount: BigNum;\n\tsubAccountId: number;\n\tjupiterQuote?: QuoteResponse;\n}\n\n/**\n * Interface for settle account P&Ls.\n */\nexport interface SettleAccountPnlParams {\n\tsubAccountId: number;\n}\n\nexport interface CancelOrdersParams {\n\tsubAccountId: number;\n\torderIds: number[];\n}\n"]}
|
|
@@ -10,7 +10,6 @@ import { EnhancedAccountData, UserAccountLookup } from '../../stores/UserAccount
|
|
|
10
10
|
import { PriorityFeeSubscriberConfig } from '@drift-labs/sdk';
|
|
11
11
|
import { CreateUserAndDepositParams, DepositParams, WithdrawParams, PerpOrderParams, SwapParams, SettleAccountPnlParams, CancelOrdersParams } from './DriftOperations/types';
|
|
12
12
|
import { L2WithOracleAndMarketData } from '../../../../utils/orderbook';
|
|
13
|
-
import { SwiftOrderResult } from '../../../base/actions/trade/openPerpOrder/openSwiftOrder';
|
|
14
13
|
import { OrderbookGrouping } from '../../../../utils/dlob-server/DlobServerWebsocketUtils';
|
|
15
14
|
export interface AuthorityDriftConfig {
|
|
16
15
|
solanaRpcEndpoint: string;
|
|
@@ -205,7 +204,7 @@ export declare class AuthorityDrift {
|
|
|
205
204
|
* @param params - Parameters for the perp order
|
|
206
205
|
* @returns Promise resolving to the transaction signature
|
|
207
206
|
*/
|
|
208
|
-
openPerpOrder(params: PerpOrderParams): Promise<TransactionSignature |
|
|
207
|
+
openPerpOrder(params: PerpOrderParams): Promise<TransactionSignature | void>;
|
|
209
208
|
/**
|
|
210
209
|
* Executes a swap between two spot markets.
|
|
211
210
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/drift/Drift/clients/AuthorityDrift/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yCAkByB;AACzB,6CAA8E;AAC9E,6EAA4E;AAC5E,+CAQyB;AACzB,6CAA6C;AAC7C,+DAAkE;AAClE,wDAIgC;AAChC,2EAAwE;AACxE,gEAA8E;AAC9E,oEAGuC;AACvC,uEAAoE;AAEpE,oEAIuC;AACvC,6CAA+C;AAC/C,yDAA2D;AAC3D,yCAIyB;AACzB,+DAA4D;AAC5D,uDAAoD;AAUpD,+CAAgD;AAEhD,mDAAuD;AACvD,yDAGmC;AAInC;;;;;;;GAOG;AACH,SAAS,eAAe,CACvB,OAAY,EACZ,YAAoB,EACpB,UAA8B;IAE9B,MAAM,cAAc,GAAG,UAAU,CAAC,KAAK,CAAC;IAExC,UAAU,CAAC,KAAK,GAAG,UAAgC,GAAG,IAAW;QAChE,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;YACxB,MAAM,IAAI,sBAAa,CAAC,YAAY,CAAC,CAAC;QACvC,CAAC;QACD,OAAO,cAAc,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACzC,CAAC,CAAC;IAEF,OAAO,UAAU,CAAC;AACnB,CAAC;AAiBD;;;;;GAKG;AACH,MAAa,cAAc;IAqG1B;;;;;;;OAOG;IACH,YAAY,MAA4B;;QA5FxC;;WAEG;QACK,4BAAuB,GAAwB,IAAI,CAAC;QAE5D;;WAEG;QACK,0BAAqB,GAAwB,IAAI,CAAC;QA2C1D;;;WAGG;QACO,kBAAa,GAAY,KAAK,CAAC;QAEzC;;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;IAED;;;;;OAKG;IACI,KAAK,CAAC,YAAY,CACxB,MAA0B;QAE1B,OAAO,IAAI,CAAC,eAAe,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;IAClD,CAAC;CACD;AA5tBD,wCA4tBC;AA3Da;IADZ,eAAe;;;;mDAKf","sourcesContent":["import {\n\tCustomizedCadenceBulkAccountLoader,\n\tDelistedMarketSetting,\n\tDRIFT_PROGRAM_ID,\n\tDriftClient,\n\tDriftClientConfig,\n\tDriftEnv,\n\tgetMarketsAndOraclesForSubscription,\n\tIWallet,\n\tMarketType,\n\tPerpMarketConfig,\n\tPerpMarkets,\n\tQuoteResponse,\n\tSpotMarketConfig,\n\tSpotMarkets,\n\tSwapMode,\n\tUser,\n\tWhileValidTxSender,\n} from '@drift-labs/sdk';\nimport { Connection, PublicKey, TransactionSignature } from '@solana/web3.js';\nimport { COMMON_UI_UTILS } from '../../../../common-ui-utils/commonUiUtils';\nimport {\n\tDEFAULT_ACCOUNT_LOADER_COMMITMENT,\n\tDEFAULT_ACCOUNT_LOADER_POLLING_FREQUENCY_MS,\n\tDEFAULT_TX_SENDER_CONFIRMATION_STRATEGY,\n\tDEFAULT_TX_SENDER_RETRY_INTERVAL,\n\tDELISTED_MARKET_STATUSES,\n\tHIGH_ACTIVITY_MARKET_ACCOUNTS,\n\tPollingCategory,\n} from '../../constants';\nimport { MarketId } from '../../../../types';\nimport { MARKET_UTILS } from '../../../../common-ui-utils/market';\nimport {\n\tPOLLING_DEPTHS,\n\tPOLLING_INTERVALS,\n\tPollingDlob,\n} from '../../data/PollingDlob';\nimport { EnvironmentConstants } from '../../../../EnvironmentConstants';\nimport { MarkPriceLookup, MarkPriceCache } from '../../stores/MarkPriceCache';\nimport {\n\tOraclePriceLookup,\n\tOraclePriceCache,\n} from '../../stores/OraclePriceCache';\nimport { DriftL2OrderbookManager } from './DriftL2OrderbookManager';\nimport { Subscription } from 'rxjs';\nimport {\n\tEnhancedAccountData,\n\tUserAccountCache,\n\tUserAccountLookup,\n} from '../../stores/UserAccountCache';\nimport { ENUM_UTILS } from '../../../../utils';\nimport { checkGeoBlock } from '../../../../utils/geoblock';\nimport {\n\tPriorityFeeSubscriber,\n\tPriorityFeeSubscriberConfig,\n\tPriorityFeeMethod,\n} from '@drift-labs/sdk';\nimport { SubscriptionManager } from './SubscriptionManager';\nimport { DriftOperations } from './DriftOperations';\nimport {\n\tCreateUserAndDepositParams,\n\tDepositParams,\n\tWithdrawParams,\n\tPerpOrderParams,\n\tSwapParams,\n\tSettleAccountPnlParams,\n\tCancelOrdersParams,\n} from './DriftOperations/types';\nimport { Initialize } from '../../../../Config';\nimport { L2WithOracleAndMarketData } from '../../../../utils/orderbook';\nimport { GeoBlockError } from '../../constants/errors';\nimport {\n\tDEFAULT_ORDERBOOK_GROUPING,\n\tDEFAULT_ORDERBOOK_SUBSCRIPTION_CONFIG,\n} from '../../constants/orderbook';\nimport { SwiftOrderResult } from '../../../base/actions/trade/openPerpOrder/openSwiftOrder';\nimport { OrderbookGrouping } from '../../../../utils/dlob-server/DlobServerWebsocketUtils';\n\n/**\n * Decorator that prevents method execution if the user is geographically blocked.\n * Throws a GeoBlockError if the user is blocked.\n *\n * @param target - The class prototype\n * @param propertyName - The method name\n * @param descriptor - The method descriptor\n */\nfunction enforceGeoBlock(\n\t_target: any,\n\tpropertyName: string,\n\tdescriptor: PropertyDescriptor\n): PropertyDescriptor {\n\tconst originalMethod = descriptor.value;\n\n\tdescriptor.value = function (this: AuthorityDrift, ...args: any[]) {\n\t\tif (this._isGeoBlocked) {\n\t\t\tthrow new GeoBlockError(propertyName);\n\t\t}\n\t\treturn originalMethod.apply(this, args);\n\t};\n\n\treturn descriptor;\n}\n\nexport interface AuthorityDriftConfig {\n\tsolanaRpcEndpoint: string;\n\tdriftEnv: DriftEnv;\n\twallet?: IWallet;\n\tdriftDlobServerHttpUrl?: string;\n\ttradableMarkets?: MarketId[];\n\tselectedTradeMarket?: MarketId;\n\tadditionalDriftClientConfig?: Partial<Omit<DriftClientConfig, 'env'>>;\n\tpriorityFeeSubscriberConfig?: Partial<PriorityFeeSubscriberConfig>;\n\torderbookConfig?: {\n\t\tdlobWebSocketUrl?: string;\n\t\torderbookGrouping?: OrderbookGrouping;\n\t};\n}\n\n/**\n * A Drift client that is used to subscribe to all accounts for a given authority.\n *\n * This is useful for applications that want to subscribe to all user accounts for a given authority,\n * such as a UI to trade on Drift or a wallet application that allows trading on Drift.\n */\nexport class AuthorityDrift {\n\t/**\n\t * Handles all Drift program interactions e.g. trading, read account details, etc.\n\t */\n\tprivate _driftClient!: DriftClient;\n\n\t/**\n\t * Handles bulk account loading from the RPC.\n\t */\n\tprivate accountLoader!: CustomizedCadenceBulkAccountLoader;\n\n\t/**\n\t * Handles polling the DLOB server for mark price and oracle price data for markets.\n\t * It is also the fallback source for orderbook data, if the websocket DLOB subscriber is unavailable.\n\t */\n\tprivate _pollingDlob!: PollingDlob;\n\n\t/**\n\t * Subscription to the polling DLOB data.\n\t */\n\tprivate pollingDlobSubscription: Subscription | null = null;\n\n\t/**\n\t * Subscription to the orderbook data.\n\t */\n\tprivate orderbookSubscription: Subscription | null = null;\n\n\t/**\n\t * Handles all trading operations including deposits, withdrawals, and position management.\n\t */\n\tprivate driftOperations!: DriftOperations;\n\n\t/**\n\t * Manages all subscription operations including user accounts, market subscriptions, and polling optimization.\n\t */\n\tprivate subscriptionManager!: SubscriptionManager;\n\n\t/**\n\t * Stores the fetched mark prices for all tradable markets.\n\t * Mark price sources includes:\n\t * - Websocket DLOB subscriber (active market, derived when fetching orderbook data)\n\t * - Polling DLOB server (all non-active markets)\n\t */\n\tprivate _markPriceCache!: MarkPriceCache;\n\n\t/**\n\t * Stores the fetched oracle prices for all tradable markets.\n\t * Oracle price sources includes:\n\t * - DriftClient oracle account subscriptions\n\t * - Polling DLOB server (all non-active markets)\n\t */\n\tprivate _oraclePriceCache!: OraclePriceCache;\n\n\t/**\n\t * Stores the fetched user account data for all user accounts.\n\t */\n\tprivate _userAccountCache!: UserAccountCache;\n\n\t/**\n\t * Manages real-time orderbook subscriptions via websocket.\n\t */\n\tprivate _orderbookManager!: DriftL2OrderbookManager;\n\n\t/**\n\t * Handles priority fee tracking and calculation for optimized transaction costs.\n\t */\n\tprivate priorityFeeSubscriber!: PriorityFeeSubscriber;\n\n\t/**\n\t * Stores whether the user is geographically blocked from using the service.\n\t * This is checked during subscription and cached for decorator use.\n\t */\n\tprotected _isGeoBlocked: boolean = false;\n\n\t/**\n\t * The selected trade market to use for the drift client. This is used to subscribe to the market account,\n\t * oracle data and mark price more frequently compared to the other markets.\n\t *\n\t * Example usage:\n\t * - When the UI wants to display the orderbook of this market.\n\t * - When the user is interacting with the trade form to trade on this market.\n\t */\n\tprivate selectedTradeMarket: MarketId | null = null;\n\n\t/**\n\t * The markets that are tradable through this client. This affects oracle price, mark price and market account subscriptions.\n\t */\n\tprivate _tradableMarkets: MarketId[] = [];\n\n\tprivate _spotMarketConfigs: SpotMarketConfig[] = [];\n\tprivate _perpMarketConfigs: PerpMarketConfig[] = [];\n\n\t/**\n\t * The public endpoints that can be used to retrieve Drift data / interact with the Drift program.\n\t */\n\tprivate _driftEndpoints: {\n\t\tdlobServerHttpUrl: string;\n\t\tswiftServerUrl: string;\n\t\torderbookWebsocketUrl: string;\n\t};\n\n\t/**\n\t * @param solanaRpcEndpoint - The Solana RPC endpoint to use for reading RPC data.\n\t * @param driftEnv - The drift environment to use for the drift client.\n\t * @param authority - The authority (wallet) whose user accounts to subscribe to.\n\t * @param tradableMarkets - The markets that are tradable through this client.\n\t * @param selectedTradeMarket - The active trade market to use for the drift client. This is used to subscribe to the market account, oracle data and mark price more frequently compared to the other markets.\n\t * @param additionalDriftClientConfig - Additional DriftClient config to use for the DriftClient.\n\t */\n\tconstructor(config: AuthorityDriftConfig) {\n\t\t// set up tradable markets\n\t\tthis.selectedTradeMarket = config.selectedTradeMarket ?? null;\n\n\t\tconst perpTradableMarkets = PerpMarkets[config.driftEnv].map(\n\t\t\t(marketConfig) => MarketId.createPerpMarket(marketConfig.marketIndex)\n\t\t);\n\t\tconst spotTradableMarkets = SpotMarkets[config.driftEnv].map(\n\t\t\t(marketConfig) => MarketId.createSpotMarket(marketConfig.marketIndex)\n\t\t);\n\n\t\tthis._tradableMarkets = config.tradableMarkets ?? [\n\t\t\t...perpTradableMarkets,\n\t\t\t...spotTradableMarkets,\n\t\t];\n\t\tthis._spotMarketConfigs = spotTradableMarkets.map((market) =>\n\t\t\tMARKET_UTILS.getMarketConfig(\n\t\t\t\tconfig.driftEnv,\n\t\t\t\tMarketType.SPOT,\n\t\t\t\tmarket.marketIndex\n\t\t\t)\n\t\t);\n\t\tthis._perpMarketConfigs = perpTradableMarkets.map((market) =>\n\t\t\tMARKET_UTILS.getMarketConfig(\n\t\t\t\tconfig.driftEnv,\n\t\t\t\tMarketType.PERP,\n\t\t\t\tmarket.marketIndex\n\t\t\t)\n\t\t);\n\n\t\t// set up Drift endpoints\n\t\tconst driftDlobServerHttpUrlToUse =\n\t\t\tconfig.driftDlobServerHttpUrl ??\n\t\t\tEnvironmentConstants.dlobServerHttpUrl[\n\t\t\t\tconfig.driftEnv === 'devnet' ? 'dev' : 'mainnet'\n\t\t\t];\n\t\tconst swiftServerUrlToUse =\n\t\t\tEnvironmentConstants.swiftServerUrl[\n\t\t\t\tconfig.driftEnv === 'devnet' ? 'staging' : 'mainnet'\n\t\t\t];\n\t\tconst orderbookWebsocketUrlToUse =\n\t\t\tconfig.orderbookConfig?.dlobWebSocketUrl ??\n\t\t\tEnvironmentConstants.dlobServerWsUrl[\n\t\t\t\tconfig.driftEnv === 'devnet' ? 'dev' : 'mainnet'\n\t\t\t];\n\t\tthis._driftEndpoints = {\n\t\t\tdlobServerHttpUrl: driftDlobServerHttpUrlToUse,\n\t\t\tswiftServerUrl: swiftServerUrlToUse,\n\t\t\torderbookWebsocketUrl: orderbookWebsocketUrlToUse,\n\t\t};\n\n\t\t// we set this up because SerializableTypes\n\t\tInitialize(config.driftEnv);\n\n\t\t// set up clients and stores\n\t\tconst driftClient = this.setupDriftClient(config);\n\t\tthis.initializePollingDlob(driftDlobServerHttpUrlToUse);\n\t\tthis.initializeStores(driftClient);\n\t\tthis.initializeOrderbookManager(\n\t\t\torderbookWebsocketUrlToUse,\n\t\t\tconfig.orderbookConfig?.orderbookGrouping\n\t\t);\n\t\tthis.initializePriorityFeeSubscriber(config.priorityFeeSubscriberConfig);\n\t\tthis.initializeManagers(driftDlobServerHttpUrlToUse, swiftServerUrlToUse);\n\t}\n\n\tpublic get driftClient(): DriftClient {\n\t\treturn this._driftClient;\n\t}\n\n\tpublic get authority(): PublicKey {\n\t\treturn this._driftClient.wallet.publicKey;\n\t}\n\n\tpublic get pollingDlob(): PollingDlob {\n\t\treturn this._pollingDlob;\n\t}\n\n\tpublic get oraclePriceCache(): OraclePriceLookup {\n\t\treturn this._oraclePriceCache.store;\n\t}\n\n\tpublic get markPriceCache(): MarkPriceLookup {\n\t\treturn this._markPriceCache.store;\n\t}\n\n\tpublic get userAccountCache(): UserAccountLookup {\n\t\treturn this._userAccountCache.store;\n\t}\n\n\tpublic get orderbookCache(): L2WithOracleAndMarketData | null {\n\t\treturn this._orderbookManager.store;\n\t}\n\n\tpublic get orderbookManager(): DriftL2OrderbookManager {\n\t\treturn this._orderbookManager;\n\t}\n\n\tpublic get tradableMarkets(): MarketId[] {\n\t\treturn this._tradableMarkets;\n\t}\n\n\t/**\n\t * Gets the current geoblock status of the user.\n\t *\n\t * @returns True if the user is geographically blocked, false otherwise\n\t */\n\tpublic get isGeoBlocked(): boolean {\n\t\treturn this._isGeoBlocked;\n\t}\n\n\t/**\n\t * The public endpoints that can be used to retrieve Drift data / interact with the Drift program.\n\t */\n\tpublic get driftEndpoints(): {\n\t\tdlobServerHttpUrl: string;\n\t\tswiftServerUrl: string;\n\t} {\n\t\treturn this._driftEndpoints;\n\t}\n\n\tprivate set tradableMarkets(tradableMarkets: MarketId[]) {\n\t\tthis._tradableMarkets = tradableMarkets;\n\t\tthis._spotMarketConfigs = tradableMarkets\n\t\t\t.filter((market) => !market.isPerp)\n\t\t\t.map((market) =>\n\t\t\t\tMARKET_UTILS.getMarketConfig(\n\t\t\t\t\tthis._driftClient.env,\n\t\t\t\t\tMarketType.SPOT,\n\t\t\t\t\tmarket.marketIndex\n\t\t\t\t)\n\t\t\t);\n\t\tthis._perpMarketConfigs = tradableMarkets\n\t\t\t.filter((market) => market.isPerp)\n\t\t\t.map((market) =>\n\t\t\t\tMARKET_UTILS.getMarketConfig(\n\t\t\t\t\tthis._driftClient.env,\n\t\t\t\t\tMarketType.PERP,\n\t\t\t\t\tmarket.marketIndex\n\t\t\t\t)\n\t\t\t);\n\t}\n\n\tpublic get spotMarketConfigs(): SpotMarketConfig[] {\n\t\treturn this._spotMarketConfigs;\n\t}\n\n\tpublic get perpMarketConfigs(): PerpMarketConfig[] {\n\t\treturn this._perpMarketConfigs;\n\t}\n\n\tprivate initializeStores(driftClient: DriftClient) {\n\t\tthis._markPriceCache = new MarkPriceCache();\n\t\tthis._oraclePriceCache = new OraclePriceCache();\n\t\tthis._userAccountCache = new UserAccountCache(\n\t\t\tdriftClient,\n\t\t\tthis._oraclePriceCache,\n\t\t\tthis._markPriceCache\n\t\t);\n\t}\n\n\tprivate initializeOrderbookManager(\n\t\torderbookWebsocketUrl: string,\n\t\torderbookGrouping: OrderbookGrouping = DEFAULT_ORDERBOOK_GROUPING\n\t) {\n\t\tthis._orderbookManager = new DriftL2OrderbookManager({\n\t\t\twsUrl: orderbookWebsocketUrl,\n\t\t\tsubscriptionConfig: this.selectedTradeMarket\n\t\t\t\t? {\n\t\t\t\t\t\t...DEFAULT_ORDERBOOK_SUBSCRIPTION_CONFIG,\n\t\t\t\t\t\tgrouping: orderbookGrouping,\n\t\t\t\t\t\tmarketId: this.selectedTradeMarket,\n\t\t\t\t }\n\t\t\t\t: undefined,\n\t\t});\n\t}\n\n\tprivate initializePollingDlob(driftDlobServerHttpUrl: string) {\n\t\tthis._pollingDlob = new PollingDlob({\n\t\t\tdriftDlobServerHttpUrl: driftDlobServerHttpUrl,\n\t\t});\n\t}\n\n\tprivate initializePriorityFeeSubscriber(\n\t\tconfig?: Partial<PriorityFeeSubscriberConfig>\n\t) {\n\t\t// Convert tradable markets to DriftMarketInfo format for priority fee subscriber\n\t\tconst driftMarkets = this._tradableMarkets.map((market) => ({\n\t\t\tmarketType: market.marketTypeStr,\n\t\t\tmarketIndex: market.marketIndex,\n\t\t}));\n\n\t\tconst priorityFeeConfig: PriorityFeeSubscriberConfig = {\n\t\t\tconnection: this.driftClient.connection,\n\t\t\tpriorityFeeMethod: PriorityFeeMethod.SOLANA,\n\t\t\tdriftMarkets,\n\t\t\taddresses: HIGH_ACTIVITY_MARKET_ACCOUNTS,\n\t\t\t...config,\n\t\t};\n\n\t\tthis.priorityFeeSubscriber = new PriorityFeeSubscriber(priorityFeeConfig);\n\t}\n\n\tprivate setupDriftClient(\n\t\tconfig: Omit<AuthorityDriftConfig, 'onUserAccountUpdate'>\n\t) {\n\t\tconst driftEnv = config.driftEnv;\n\n\t\tconst connection = new Connection(config.solanaRpcEndpoint);\n\t\tconst driftProgramID = new PublicKey(DRIFT_PROGRAM_ID);\n\t\tconst accountLoader = new CustomizedCadenceBulkAccountLoader(\n\t\t\tconnection,\n\t\t\tDEFAULT_ACCOUNT_LOADER_COMMITMENT,\n\t\t\tDEFAULT_ACCOUNT_LOADER_POLLING_FREQUENCY_MS\n\t\t);\n\t\tthis.accountLoader = accountLoader;\n\n\t\tconst wallet = config.wallet ?? COMMON_UI_UTILS.createPlaceholderIWallet();\n\t\tconst skipInitialUsersLoad = !config.wallet;\n\n\t\tconst perpMarkets =\n\t\t\tconfig.tradableMarkets\n\t\t\t\t?.filter((market) => market.isPerp)\n\t\t\t\t.map((market) =>\n\t\t\t\t\tMARKET_UTILS.getMarketConfig(\n\t\t\t\t\t\tdriftEnv,\n\t\t\t\t\t\tMarketType.PERP,\n\t\t\t\t\t\tmarket.marketIndex\n\t\t\t\t\t)\n\t\t\t\t) ?? PerpMarkets[driftEnv];\n\t\tconst spotMarkets =\n\t\t\tconfig.tradableMarkets\n\t\t\t\t?.filter((market) => !market.isPerp)\n\t\t\t\t.map((market) =>\n\t\t\t\t\tMARKET_UTILS.getMarketConfig(\n\t\t\t\t\t\tdriftEnv,\n\t\t\t\t\t\tMarketType.SPOT,\n\t\t\t\t\t\tmarket.marketIndex\n\t\t\t\t\t)\n\t\t\t\t) ?? SpotMarkets[driftEnv];\n\t\tconst { perpMarketIndexes, spotMarketIndexes, oracleInfos } =\n\t\t\tgetMarketsAndOraclesForSubscription(driftEnv, perpMarkets, spotMarkets);\n\n\t\tconst driftClientConfig: DriftClientConfig = {\n\t\t\tenv: driftEnv,\n\t\t\tconnection,\n\t\t\twallet,\n\t\t\tprogramID: driftProgramID,\n\t\t\tenableMetricsEvents: false,\n\t\t\taccountSubscription: {\n\t\t\t\ttype: 'polling',\n\t\t\t\taccountLoader,\n\t\t\t},\n\t\t\tuserStats: true,\n\t\t\tincludeDelegates: true,\n\t\t\tskipLoadUsers: skipInitialUsersLoad,\n\t\t\tdelistedMarketSetting: DelistedMarketSetting.Unsubscribe,\n\t\t\tperpMarketIndexes,\n\t\t\tspotMarketIndexes,\n\t\t\toracleInfos,\n\t\t\t...config.additionalDriftClientConfig,\n\t\t};\n\t\tthis._driftClient = new DriftClient(driftClientConfig);\n\n\t\tconst txSender = new WhileValidTxSender({\n\t\t\tconnection,\n\t\t\twallet,\n\t\t\tadditionalConnections: [],\n\t\t\tadditionalTxSenderCallbacks: [],\n\t\t\ttxHandler: this._driftClient.txHandler,\n\t\t\tconfirmationStrategy: DEFAULT_TX_SENDER_CONFIRMATION_STRATEGY,\n\t\t\tretrySleep: DEFAULT_TX_SENDER_RETRY_INTERVAL,\n\t\t});\n\n\t\tthis._driftClient.txSender = txSender;\n\n\t\treturn this._driftClient;\n\t}\n\n\tprivate setupOrderbookManager() {\n\t\tthis.orderbookSubscription = this._orderbookManager.onUpdate(\n\t\t\t(orderbookData) => {\n\t\t\t\tconst marketKey = new MarketId(\n\t\t\t\t\torderbookData.marketIndex,\n\t\t\t\t\tENUM_UTILS.toObj(orderbookData.marketType as string) as MarketType\n\t\t\t\t).key;\n\n\t\t\t\tconst markPrice = orderbookData.markPrice;\n\n\t\t\t\tthis._markPriceCache.updateMarkPrices({\n\t\t\t\t\tmarketKey,\n\t\t\t\t\tmarkPrice,\n\t\t\t\t\tbestAsk: orderbookData.bestAskPrice,\n\t\t\t\t\tbestBid: orderbookData.bestBidPrice,\n\t\t\t\t\tlastUpdateSlot: orderbookData.slot ?? 0,\n\t\t\t\t});\n\n\t\t\t\tthis._oraclePriceCache.updateOraclePrices({\n\t\t\t\t\t...orderbookData.oracleData,\n\t\t\t\t\tmarketKey,\n\t\t\t\t});\n\t\t\t}\n\t\t);\n\t}\n\n\tprivate setupPollingDlob() {\n\t\t// DriftL2OrderbookManager will handle the fetching of data for the selected trade market through websocket\n\n\t\tthis._pollingDlob.addInterval(\n\t\t\tPollingCategory.USER_INVOLVED,\n\t\t\tPOLLING_INTERVALS.BACKGROUND_DEEP,\n\t\t\tPOLLING_DEPTHS.DEEP\n\t\t); // markets that the user is involved in\n\t\tthis._pollingDlob.addInterval(\n\t\t\tPollingCategory.USER_NOT_INVOLVED,\n\t\t\tPOLLING_INTERVALS.BACKGROUND_SHALLOW,\n\t\t\tPOLLING_DEPTHS.SHALLOW\n\t\t); // markets that the user is not involved in\n\n\t\t// add all markets to the user-not-involved interval first, until user-involved markets are known\n\t\tthis._pollingDlob.addMarketsToInterval(\n\t\t\tPollingCategory.USER_NOT_INVOLVED,\n\t\t\tthis._tradableMarkets.map((market) => market.key)\n\t\t);\n\n\t\tthis.pollingDlobSubscription = this._pollingDlob\n\t\t\t.onData()\n\t\t\t.subscribe((data) => {\n\t\t\t\tconst updatedMarkPrices = data.map((marketData) => {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tmarketKey: marketData.marketId.key,\n\t\t\t\t\t\tmarkPrice: marketData.data.markPrice,\n\t\t\t\t\t\tbestBid: marketData.data.bestBidPrice,\n\t\t\t\t\t\tbestAsk: marketData.data.bestAskPrice,\n\t\t\t\t\t\tlastUpdateSlot: marketData.data.slot ?? 0,\n\t\t\t\t\t};\n\t\t\t\t});\n\t\t\t\tconst updatedOraclePrices = data.map((marketData) => {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tmarketKey: marketData.marketId.key,\n\t\t\t\t\t\t...marketData.data.oracleData,\n\t\t\t\t\t};\n\t\t\t\t});\n\n\t\t\t\tthis._markPriceCache.updateMarkPrices(...updatedMarkPrices);\n\t\t\t\tthis._oraclePriceCache.updateOraclePrices(...updatedOraclePrices);\n\t\t\t});\n\t}\n\n\tprivate initializeManagers(\n\t\tdlobServerHttpUrl: string,\n\t\tswiftServerUrl: string\n\t) {\n\t\t// Initialize trading operations\n\t\tthis.driftOperations = new DriftOperations(\n\t\t\tthis._driftClient,\n\t\t\t() => this._userAccountCache,\n\t\t\tdlobServerHttpUrl,\n\t\t\tswiftServerUrl,\n\t\t\t() => this.priorityFeeSubscriber.getCustomStrategyResult()\n\t\t);\n\n\t\t// Initialize subscription manager with all subscription and market operations\n\t\tthis.subscriptionManager = new SubscriptionManager(\n\t\t\tthis._driftClient,\n\t\t\tthis.accountLoader,\n\t\t\tthis._pollingDlob,\n\t\t\tthis._orderbookManager,\n\t\t\tthis._userAccountCache,\n\t\t\tthis._tradableMarkets,\n\t\t\tthis.selectedTradeMarket\n\t\t);\n\t}\n\n\tprivate unsubscribeFromPollingDlob() {\n\t\tthis.pollingDlobSubscription?.unsubscribe();\n\t\tthis.pollingDlobSubscription = null;\n\n\t\tthis._pollingDlob.stop();\n\t}\n\n\tprivate unsubscribeFromOrderbook() {\n\t\tthis.orderbookSubscription?.unsubscribe();\n\t\tthis.orderbookSubscription = null;\n\n\t\tthis._orderbookManager.unsubscribe();\n\t}\n\n\tpublic async subscribe() {\n\t\tconst handleGeoBlock = async () => {\n\t\t\ttry {\n\t\t\t\tthis._isGeoBlocked = (await checkGeoBlock()) ?? false;\n\t\t\t} catch (error) {\n\t\t\t\tconsole.warn('Failed to check geoblock status:', error);\n\t\t\t\tthis._isGeoBlocked = false; // Default to not blocked if check fails\n\t\t\t}\n\t\t};\n\n\t\t// async logic that doesn't require DriftClient to be subscribed\n\t\tconst handleGeoBlockPromise = handleGeoBlock();\n\t\tconst pollingDlobStartPromise = this._pollingDlob.start();\n\t\tconst priorityFeeSubscribePromise = this.priorityFeeSubscriber.subscribe();\n\t\tconst orderbookSubscribePromise = this._orderbookManager.subscribe();\n\n\t\tawait this._driftClient.subscribe();\n\n\t\t// filter out markets that are delisted\n\t\tconst actualTradableMarkets = this._tradableMarkets.filter((market) => {\n\t\t\tconst marketAccount = market.isPerp\n\t\t\t\t? this._driftClient.getPerpMarketAccount(market.marketIndex)\n\t\t\t\t: this._driftClient.getSpotMarketAccount(market.marketIndex);\n\n\t\t\tif (\n\t\t\t\t!marketAccount ||\n\t\t\t\tDELISTED_MARKET_STATUSES.some((marketStatus) =>\n\t\t\t\t\tENUM_UTILS.match(marketAccount.status, marketStatus)\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\treturn true;\n\t\t});\n\n\t\tthis._tradableMarkets = actualTradableMarkets;\n\t\tthis.subscriptionManager.updateTradableMarkets(actualTradableMarkets);\n\t\tthis.setupPollingDlob();\n\t\tthis.setupOrderbookManager();\n\n\t\tconst subscribeToNonWhitelistedButUserInvolvedMarketsPromise =\n\t\t\tthis.subscriptionManager.subscribeToNonWhitelistedButUserInvolvedMarkets(\n\t\t\t\tthis._driftClient.getUsers()\n\t\t\t);\n\n\t\tawait Promise.all([\n\t\t\tpollingDlobStartPromise,\n\t\t\tsubscribeToNonWhitelistedButUserInvolvedMarketsPromise,\n\t\t\tpriorityFeeSubscribePromise,\n\t\t\thandleGeoBlockPromise,\n\t\t\torderbookSubscribePromise,\n\t\t]);\n\n\t\tthis.subscriptionManager.subscribeToAllUsersUpdates();\n\n\t\t// TODO: subscribe to oracle price updates from drift client?\n\t}\n\n\tpublic async unsubscribe() {\n\t\tthis.unsubscribeFromPollingDlob();\n\t\tthis.unsubscribeFromOrderbook();\n\t\tthis._userAccountCache.destroy();\n\t\tthis._markPriceCache.destroy();\n\t\tthis._orderbookManager.destroy();\n\n\t\tconst driftClientUnsubscribePromise = this._driftClient.unsubscribe();\n\t\tconst priorityFeeUnsubscribePromise =\n\t\t\tthis.priorityFeeSubscriber.unsubscribe();\n\n\t\tawait Promise.all(\n\t\t\t[driftClientUnsubscribePromise, priorityFeeUnsubscribePromise].filter(\n\t\t\t\tBoolean\n\t\t\t)\n\t\t);\n\n\t\tthis.pollingDlobSubscription = null;\n\t}\n\n\tpublic onOraclePricesUpdate(\n\t\tcallback: (oraclePrice: OraclePriceLookup) => void\n\t) {\n\t\treturn this._oraclePriceCache.onUpdate(callback);\n\t}\n\n\tpublic onMarkPricesUpdate(callback: (markPrice: MarkPriceLookup) => void) {\n\t\treturn this._markPriceCache.onUpdate(callback);\n\t}\n\n\tpublic onUserAccountUpdate(\n\t\tcallback: (userAccount: EnhancedAccountData) => void\n\t) {\n\t\treturn this._userAccountCache.onUpdate(callback);\n\t}\n\n\tpublic onOrderbookUpdate(\n\t\tcallback: (orderbook: L2WithOracleAndMarketData) => void\n\t) {\n\t\treturn this._orderbookManager.onUpdate(callback);\n\t}\n\n\t/**\n\t * Updates the authority (wallet) for the drift client and reestablishes subscriptions.\n\t *\n\t * @param wallet - The new wallet to use as authority\n\t * @param activeSubAccountId - Optional subaccount ID to switch to after wallet update\n\t */\n\tpublic async updateAuthority(wallet: IWallet, activeSubAccountId?: number) {\n\t\treturn this.subscriptionManager.updateAuthority(wallet, activeSubAccountId);\n\t}\n\n\t/**\n\t * Updates the selected trade market and optimizes subscription polling.\n\t *\n\t * @param newSelectedTradeMarket - The new market to prioritize for trading\n\t */\n\tpublic updateSelectedTradeMarket(newSelectedTradeMarket: MarketId | null) {\n\t\tconst isNewSelectedTradeMarket =\n\t\t\t!!newSelectedTradeMarket !== !!this.selectedTradeMarket || // only one of them is null\n\t\t\t(!!newSelectedTradeMarket && // or both are not null and are different\n\t\t\t\t!!this.selectedTradeMarket &&\n\t\t\t\t!this.selectedTradeMarket.equals(newSelectedTradeMarket));\n\n\t\tif (!isNewSelectedTradeMarket) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Update the local reference\n\t\tthis.selectedTradeMarket = newSelectedTradeMarket;\n\n\t\t// Delegate to subscription manager for all polling optimization\n\t\tthis.subscriptionManager.updateSelectedTradeMarket(newSelectedTradeMarket);\n\t}\n\n\t/**\n\t * Creates a new user account and deposits initial collateral.\n\t *\n\t * @param params - Parameters for creating user and depositing collateral\n\t * @returns Promise resolving to transaction signature and user account public key\n\t */\n\tpublic async createUserAndDeposit(\n\t\tparams: CreateUserAndDepositParams\n\t): Promise<{\n\t\ttxSig: TransactionSignature;\n\t\tuser: User;\n\t}> {\n\t\treturn this.driftOperations.createUserAndDeposit(params);\n\t}\n\n\t/**\n\t * Deposits collateral into a user's spot market position.\n\t *\n\t * @param params - Parameters for the deposit operation\n\t * @returns Promise resolving to the transaction signature\n\t */\n\tpublic async deposit(params: DepositParams): Promise<TransactionSignature> {\n\t\treturn this.driftOperations.deposit(params);\n\t}\n\n\t/**\n\t * Withdraws collateral from a user's spot market position.\n\t *\n\t * @param params - Parameters for the withdrawal operation\n\t * @returns Promise resolving to the transaction signature\n\t */\n\tpublic async withdraw(params: WithdrawParams): Promise<TransactionSignature> {\n\t\treturn this.driftOperations.withdraw(params);\n\t}\n\n\t/**\n\t * Opens a perpetual market order.\n\t *\n\t * @param params - Parameters for the perp order\n\t * @returns Promise resolving to the transaction signature\n\t */\n\t@enforceGeoBlock\n\tpublic async openPerpOrder(\n\t\tparams: PerpOrderParams\n\t): Promise<TransactionSignature | SwiftOrderResult> {\n\t\treturn this.driftOperations.openPerpOrder(params);\n\t}\n\n\t/**\n\t * Executes a swap between two spot markets.\n\t *\n\t * @param params - Parameters for the swap operation\n\t * @returns Promise resolving to the transaction signature\n\t */\n\tpublic async swap(params: SwapParams): Promise<TransactionSignature> {\n\t\treturn this.driftOperations.swap(params);\n\t}\n\n\tpublic async getSwapQuote(\n\t\tparams: Omit<SwapParams, 'jupiterQuote'> & {\n\t\t\tslippageBps?: number;\n\t\t\tswapMode?: SwapMode;\n\t\t\tonlyDirectRoutes?: boolean;\n\t\t}\n\t): Promise<QuoteResponse> {\n\t\treturn this.driftOperations.getSwapQuote(params);\n\t}\n\n\t/**\n\t * Settles profit and loss for a perpetual position.\n\t *\n\t * @param params - Parameters for the settle PnL operation\n\t * @returns Promise resolving to the transaction signature\n\t */\n\tpublic async settleAccountPnl(\n\t\tparams: SettleAccountPnlParams\n\t): Promise<TransactionSignature> {\n\t\treturn this.driftOperations.settleAccountPnl(params);\n\t}\n\n\t/**\n\t * Deletes a user account from the Drift protocol.\n\t *\n\t * @param subAccountId - The ID of the sub-account to delete\n\t * @returns Promise resolving to the transaction signature of the deletion\n\t */\n\tpublic async deleteUser(subAccountId: number): Promise<TransactionSignature> {\n\t\treturn this.driftOperations.deleteUser(subAccountId);\n\t}\n\n\t/**\n\t * Cancels a list of open orders.\n\t *\n\t * @param params - See `CancelOrdersParams`\n\t * @returns Promise resolving to the transaction signature of the cancellation\n\t */\n\tpublic async cancelOrders(\n\t\tparams: CancelOrdersParams\n\t): Promise<TransactionSignature> {\n\t\treturn this.driftOperations.cancelOrders(params);\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/drift/Drift/clients/AuthorityDrift/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yCAkByB;AACzB,6CAA8E;AAC9E,6EAA4E;AAC5E,+CAQyB;AACzB,6CAA6C;AAC7C,+DAAkE;AAClE,wDAIgC;AAChC,2EAAwE;AACxE,gEAA8E;AAC9E,oEAGuC;AACvC,uEAAoE;AAEpE,oEAIuC;AACvC,6CAA+C;AAC/C,yDAA2D;AAC3D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C,eAAe,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC9C,CAAC;IAED;;;;;OAKG;IAEU,AAAN,KAAK,CAAC,aAAa,CACzB,MAAuB;QAEvB,OAAO,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;IACnD,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,IAAI,CAAC,MAAkB;QACnC,OAAO,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC1C,CAAC;IAEM,KAAK,CAAC,YAAY,CACxB,MAIC;QAED,OAAO,IAAI,CAAC,eAAe,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;IAClD,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,gBAAgB,CAC5B,MAA8B;QAE9B,OAAO,IAAI,CAAC,eAAe,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC;IACtD,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,UAAU,CAAC,YAAoB;QAC3C,OAAO,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;IACtD,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,YAAY,CACxB,MAA0B;QAE1B,OAAO,IAAI,CAAC,eAAe,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;IAClD,CAAC;CACD;AA5tBD,wCA4tBC;AA3Da;IADZ,eAAe;;;;mDAKf","sourcesContent":["import {\n\tCustomizedCadenceBulkAccountLoader,\n\tDelistedMarketSetting,\n\tDRIFT_PROGRAM_ID,\n\tDriftClient,\n\tDriftClientConfig,\n\tDriftEnv,\n\tgetMarketsAndOraclesForSubscription,\n\tIWallet,\n\tMarketType,\n\tPerpMarketConfig,\n\tPerpMarkets,\n\tQuoteResponse,\n\tSpotMarketConfig,\n\tSpotMarkets,\n\tSwapMode,\n\tUser,\n\tWhileValidTxSender,\n} from '@drift-labs/sdk';\nimport { Connection, PublicKey, TransactionSignature } from '@solana/web3.js';\nimport { COMMON_UI_UTILS } from '../../../../common-ui-utils/commonUiUtils';\nimport {\n\tDEFAULT_ACCOUNT_LOADER_COMMITMENT,\n\tDEFAULT_ACCOUNT_LOADER_POLLING_FREQUENCY_MS,\n\tDEFAULT_TX_SENDER_CONFIRMATION_STRATEGY,\n\tDEFAULT_TX_SENDER_RETRY_INTERVAL,\n\tDELISTED_MARKET_STATUSES,\n\tHIGH_ACTIVITY_MARKET_ACCOUNTS,\n\tPollingCategory,\n} from '../../constants';\nimport { MarketId } from '../../../../types';\nimport { MARKET_UTILS } from '../../../../common-ui-utils/market';\nimport {\n\tPOLLING_DEPTHS,\n\tPOLLING_INTERVALS,\n\tPollingDlob,\n} from '../../data/PollingDlob';\nimport { EnvironmentConstants } from '../../../../EnvironmentConstants';\nimport { MarkPriceLookup, MarkPriceCache } from '../../stores/MarkPriceCache';\nimport {\n\tOraclePriceLookup,\n\tOraclePriceCache,\n} from '../../stores/OraclePriceCache';\nimport { DriftL2OrderbookManager } from './DriftL2OrderbookManager';\nimport { Subscription } from 'rxjs';\nimport {\n\tEnhancedAccountData,\n\tUserAccountCache,\n\tUserAccountLookup,\n} from '../../stores/UserAccountCache';\nimport { ENUM_UTILS } from '../../../../utils';\nimport { checkGeoBlock } from '../../../../utils/geoblock';\nimport {\n\tPriorityFeeSubscriber,\n\tPriorityFeeSubscriberConfig,\n\tPriorityFeeMethod,\n} from '@drift-labs/sdk';\nimport { SubscriptionManager } from './SubscriptionManager';\nimport { DriftOperations } from './DriftOperations';\nimport {\n\tCreateUserAndDepositParams,\n\tDepositParams,\n\tWithdrawParams,\n\tPerpOrderParams,\n\tSwapParams,\n\tSettleAccountPnlParams,\n\tCancelOrdersParams,\n} from './DriftOperations/types';\nimport { Initialize } from '../../../../Config';\nimport { L2WithOracleAndMarketData } from '../../../../utils/orderbook';\nimport { GeoBlockError } from '../../constants/errors';\nimport {\n\tDEFAULT_ORDERBOOK_GROUPING,\n\tDEFAULT_ORDERBOOK_SUBSCRIPTION_CONFIG,\n} from '../../constants/orderbook';\nimport { OrderbookGrouping } from '../../../../utils/dlob-server/DlobServerWebsocketUtils';\n\n/**\n * Decorator that prevents method execution if the user is geographically blocked.\n * Throws a GeoBlockError if the user is blocked.\n *\n * @param target - The class prototype\n * @param propertyName - The method name\n * @param descriptor - The method descriptor\n */\nfunction enforceGeoBlock(\n\t_target: any,\n\tpropertyName: string,\n\tdescriptor: PropertyDescriptor\n): PropertyDescriptor {\n\tconst originalMethod = descriptor.value;\n\n\tdescriptor.value = function (this: AuthorityDrift, ...args: any[]) {\n\t\tif (this._isGeoBlocked) {\n\t\t\tthrow new GeoBlockError(propertyName);\n\t\t}\n\t\treturn originalMethod.apply(this, args);\n\t};\n\n\treturn descriptor;\n}\n\nexport interface AuthorityDriftConfig {\n\tsolanaRpcEndpoint: string;\n\tdriftEnv: DriftEnv;\n\twallet?: IWallet;\n\tdriftDlobServerHttpUrl?: string;\n\ttradableMarkets?: MarketId[];\n\tselectedTradeMarket?: MarketId;\n\tadditionalDriftClientConfig?: Partial<Omit<DriftClientConfig, 'env'>>;\n\tpriorityFeeSubscriberConfig?: Partial<PriorityFeeSubscriberConfig>;\n\torderbookConfig?: {\n\t\tdlobWebSocketUrl?: string;\n\t\torderbookGrouping?: OrderbookGrouping;\n\t};\n}\n\n/**\n * A Drift client that is used to subscribe to all accounts for a given authority.\n *\n * This is useful for applications that want to subscribe to all user accounts for a given authority,\n * such as a UI to trade on Drift or a wallet application that allows trading on Drift.\n */\nexport class AuthorityDrift {\n\t/**\n\t * Handles all Drift program interactions e.g. trading, read account details, etc.\n\t */\n\tprivate _driftClient!: DriftClient;\n\n\t/**\n\t * Handles bulk account loading from the RPC.\n\t */\n\tprivate accountLoader!: CustomizedCadenceBulkAccountLoader;\n\n\t/**\n\t * Handles polling the DLOB server for mark price and oracle price data for markets.\n\t * It is also the fallback source for orderbook data, if the websocket DLOB subscriber is unavailable.\n\t */\n\tprivate _pollingDlob!: PollingDlob;\n\n\t/**\n\t * Subscription to the polling DLOB data.\n\t */\n\tprivate pollingDlobSubscription: Subscription | null = null;\n\n\t/**\n\t * Subscription to the orderbook data.\n\t */\n\tprivate orderbookSubscription: Subscription | null = null;\n\n\t/**\n\t * Handles all trading operations including deposits, withdrawals, and position management.\n\t */\n\tprivate driftOperations!: DriftOperations;\n\n\t/**\n\t * Manages all subscription operations including user accounts, market subscriptions, and polling optimization.\n\t */\n\tprivate subscriptionManager!: SubscriptionManager;\n\n\t/**\n\t * Stores the fetched mark prices for all tradable markets.\n\t * Mark price sources includes:\n\t * - Websocket DLOB subscriber (active market, derived when fetching orderbook data)\n\t * - Polling DLOB server (all non-active markets)\n\t */\n\tprivate _markPriceCache!: MarkPriceCache;\n\n\t/**\n\t * Stores the fetched oracle prices for all tradable markets.\n\t * Oracle price sources includes:\n\t * - DriftClient oracle account subscriptions\n\t * - Polling DLOB server (all non-active markets)\n\t */\n\tprivate _oraclePriceCache!: OraclePriceCache;\n\n\t/**\n\t * Stores the fetched user account data for all user accounts.\n\t */\n\tprivate _userAccountCache!: UserAccountCache;\n\n\t/**\n\t * Manages real-time orderbook subscriptions via websocket.\n\t */\n\tprivate _orderbookManager!: DriftL2OrderbookManager;\n\n\t/**\n\t * Handles priority fee tracking and calculation for optimized transaction costs.\n\t */\n\tprivate priorityFeeSubscriber!: PriorityFeeSubscriber;\n\n\t/**\n\t * Stores whether the user is geographically blocked from using the service.\n\t * This is checked during subscription and cached for decorator use.\n\t */\n\tprotected _isGeoBlocked: boolean = false;\n\n\t/**\n\t * The selected trade market to use for the drift client. This is used to subscribe to the market account,\n\t * oracle data and mark price more frequently compared to the other markets.\n\t *\n\t * Example usage:\n\t * - When the UI wants to display the orderbook of this market.\n\t * - When the user is interacting with the trade form to trade on this market.\n\t */\n\tprivate selectedTradeMarket: MarketId | null = null;\n\n\t/**\n\t * The markets that are tradable through this client. This affects oracle price, mark price and market account subscriptions.\n\t */\n\tprivate _tradableMarkets: MarketId[] = [];\n\n\tprivate _spotMarketConfigs: SpotMarketConfig[] = [];\n\tprivate _perpMarketConfigs: PerpMarketConfig[] = [];\n\n\t/**\n\t * The public endpoints that can be used to retrieve Drift data / interact with the Drift program.\n\t */\n\tprivate _driftEndpoints: {\n\t\tdlobServerHttpUrl: string;\n\t\tswiftServerUrl: string;\n\t\torderbookWebsocketUrl: string;\n\t};\n\n\t/**\n\t * @param solanaRpcEndpoint - The Solana RPC endpoint to use for reading RPC data.\n\t * @param driftEnv - The drift environment to use for the drift client.\n\t * @param authority - The authority (wallet) whose user accounts to subscribe to.\n\t * @param tradableMarkets - The markets that are tradable through this client.\n\t * @param selectedTradeMarket - The active trade market to use for the drift client. This is used to subscribe to the market account, oracle data and mark price more frequently compared to the other markets.\n\t * @param additionalDriftClientConfig - Additional DriftClient config to use for the DriftClient.\n\t */\n\tconstructor(config: AuthorityDriftConfig) {\n\t\t// set up tradable markets\n\t\tthis.selectedTradeMarket = config.selectedTradeMarket ?? null;\n\n\t\tconst perpTradableMarkets = PerpMarkets[config.driftEnv].map(\n\t\t\t(marketConfig) => MarketId.createPerpMarket(marketConfig.marketIndex)\n\t\t);\n\t\tconst spotTradableMarkets = SpotMarkets[config.driftEnv].map(\n\t\t\t(marketConfig) => MarketId.createSpotMarket(marketConfig.marketIndex)\n\t\t);\n\n\t\tthis._tradableMarkets = config.tradableMarkets ?? [\n\t\t\t...perpTradableMarkets,\n\t\t\t...spotTradableMarkets,\n\t\t];\n\t\tthis._spotMarketConfigs = spotTradableMarkets.map((market) =>\n\t\t\tMARKET_UTILS.getMarketConfig(\n\t\t\t\tconfig.driftEnv,\n\t\t\t\tMarketType.SPOT,\n\t\t\t\tmarket.marketIndex\n\t\t\t)\n\t\t);\n\t\tthis._perpMarketConfigs = perpTradableMarkets.map((market) =>\n\t\t\tMARKET_UTILS.getMarketConfig(\n\t\t\t\tconfig.driftEnv,\n\t\t\t\tMarketType.PERP,\n\t\t\t\tmarket.marketIndex\n\t\t\t)\n\t\t);\n\n\t\t// set up Drift endpoints\n\t\tconst driftDlobServerHttpUrlToUse =\n\t\t\tconfig.driftDlobServerHttpUrl ??\n\t\t\tEnvironmentConstants.dlobServerHttpUrl[\n\t\t\t\tconfig.driftEnv === 'devnet' ? 'dev' : 'mainnet'\n\t\t\t];\n\t\tconst swiftServerUrlToUse =\n\t\t\tEnvironmentConstants.swiftServerUrl[\n\t\t\t\tconfig.driftEnv === 'devnet' ? 'staging' : 'mainnet'\n\t\t\t];\n\t\tconst orderbookWebsocketUrlToUse =\n\t\t\tconfig.orderbookConfig?.dlobWebSocketUrl ??\n\t\t\tEnvironmentConstants.dlobServerWsUrl[\n\t\t\t\tconfig.driftEnv === 'devnet' ? 'dev' : 'mainnet'\n\t\t\t];\n\t\tthis._driftEndpoints = {\n\t\t\tdlobServerHttpUrl: driftDlobServerHttpUrlToUse,\n\t\t\tswiftServerUrl: swiftServerUrlToUse,\n\t\t\torderbookWebsocketUrl: orderbookWebsocketUrlToUse,\n\t\t};\n\n\t\t// we set this up because SerializableTypes\n\t\tInitialize(config.driftEnv);\n\n\t\t// set up clients and stores\n\t\tconst driftClient = this.setupDriftClient(config);\n\t\tthis.initializePollingDlob(driftDlobServerHttpUrlToUse);\n\t\tthis.initializeStores(driftClient);\n\t\tthis.initializeOrderbookManager(\n\t\t\torderbookWebsocketUrlToUse,\n\t\t\tconfig.orderbookConfig?.orderbookGrouping\n\t\t);\n\t\tthis.initializePriorityFeeSubscriber(config.priorityFeeSubscriberConfig);\n\t\tthis.initializeManagers(driftDlobServerHttpUrlToUse, swiftServerUrlToUse);\n\t}\n\n\tpublic get driftClient(): DriftClient {\n\t\treturn this._driftClient;\n\t}\n\n\tpublic get authority(): PublicKey {\n\t\treturn this._driftClient.wallet.publicKey;\n\t}\n\n\tpublic get pollingDlob(): PollingDlob {\n\t\treturn this._pollingDlob;\n\t}\n\n\tpublic get oraclePriceCache(): OraclePriceLookup {\n\t\treturn this._oraclePriceCache.store;\n\t}\n\n\tpublic get markPriceCache(): MarkPriceLookup {\n\t\treturn this._markPriceCache.store;\n\t}\n\n\tpublic get userAccountCache(): UserAccountLookup {\n\t\treturn this._userAccountCache.store;\n\t}\n\n\tpublic get orderbookCache(): L2WithOracleAndMarketData | null {\n\t\treturn this._orderbookManager.store;\n\t}\n\n\tpublic get orderbookManager(): DriftL2OrderbookManager {\n\t\treturn this._orderbookManager;\n\t}\n\n\tpublic get tradableMarkets(): MarketId[] {\n\t\treturn this._tradableMarkets;\n\t}\n\n\t/**\n\t * Gets the current geoblock status of the user.\n\t *\n\t * @returns True if the user is geographically blocked, false otherwise\n\t */\n\tpublic get isGeoBlocked(): boolean {\n\t\treturn this._isGeoBlocked;\n\t}\n\n\t/**\n\t * The public endpoints that can be used to retrieve Drift data / interact with the Drift program.\n\t */\n\tpublic get driftEndpoints(): {\n\t\tdlobServerHttpUrl: string;\n\t\tswiftServerUrl: string;\n\t} {\n\t\treturn this._driftEndpoints;\n\t}\n\n\tprivate set tradableMarkets(tradableMarkets: MarketId[]) {\n\t\tthis._tradableMarkets = tradableMarkets;\n\t\tthis._spotMarketConfigs = tradableMarkets\n\t\t\t.filter((market) => !market.isPerp)\n\t\t\t.map((market) =>\n\t\t\t\tMARKET_UTILS.getMarketConfig(\n\t\t\t\t\tthis._driftClient.env,\n\t\t\t\t\tMarketType.SPOT,\n\t\t\t\t\tmarket.marketIndex\n\t\t\t\t)\n\t\t\t);\n\t\tthis._perpMarketConfigs = tradableMarkets\n\t\t\t.filter((market) => market.isPerp)\n\t\t\t.map((market) =>\n\t\t\t\tMARKET_UTILS.getMarketConfig(\n\t\t\t\t\tthis._driftClient.env,\n\t\t\t\t\tMarketType.PERP,\n\t\t\t\t\tmarket.marketIndex\n\t\t\t\t)\n\t\t\t);\n\t}\n\n\tpublic get spotMarketConfigs(): SpotMarketConfig[] {\n\t\treturn this._spotMarketConfigs;\n\t}\n\n\tpublic get perpMarketConfigs(): PerpMarketConfig[] {\n\t\treturn this._perpMarketConfigs;\n\t}\n\n\tprivate initializeStores(driftClient: DriftClient) {\n\t\tthis._markPriceCache = new MarkPriceCache();\n\t\tthis._oraclePriceCache = new OraclePriceCache();\n\t\tthis._userAccountCache = new UserAccountCache(\n\t\t\tdriftClient,\n\t\t\tthis._oraclePriceCache,\n\t\t\tthis._markPriceCache\n\t\t);\n\t}\n\n\tprivate initializeOrderbookManager(\n\t\torderbookWebsocketUrl: string,\n\t\torderbookGrouping: OrderbookGrouping = DEFAULT_ORDERBOOK_GROUPING\n\t) {\n\t\tthis._orderbookManager = new DriftL2OrderbookManager({\n\t\t\twsUrl: orderbookWebsocketUrl,\n\t\t\tsubscriptionConfig: this.selectedTradeMarket\n\t\t\t\t? {\n\t\t\t\t\t\t...DEFAULT_ORDERBOOK_SUBSCRIPTION_CONFIG,\n\t\t\t\t\t\tgrouping: orderbookGrouping,\n\t\t\t\t\t\tmarketId: this.selectedTradeMarket,\n\t\t\t\t }\n\t\t\t\t: undefined,\n\t\t});\n\t}\n\n\tprivate initializePollingDlob(driftDlobServerHttpUrl: string) {\n\t\tthis._pollingDlob = new PollingDlob({\n\t\t\tdriftDlobServerHttpUrl: driftDlobServerHttpUrl,\n\t\t});\n\t}\n\n\tprivate initializePriorityFeeSubscriber(\n\t\tconfig?: Partial<PriorityFeeSubscriberConfig>\n\t) {\n\t\t// Convert tradable markets to DriftMarketInfo format for priority fee subscriber\n\t\tconst driftMarkets = this._tradableMarkets.map((market) => ({\n\t\t\tmarketType: market.marketTypeStr,\n\t\t\tmarketIndex: market.marketIndex,\n\t\t}));\n\n\t\tconst priorityFeeConfig: PriorityFeeSubscriberConfig = {\n\t\t\tconnection: this.driftClient.connection,\n\t\t\tpriorityFeeMethod: PriorityFeeMethod.SOLANA,\n\t\t\tdriftMarkets,\n\t\t\taddresses: HIGH_ACTIVITY_MARKET_ACCOUNTS,\n\t\t\t...config,\n\t\t};\n\n\t\tthis.priorityFeeSubscriber = new PriorityFeeSubscriber(priorityFeeConfig);\n\t}\n\n\tprivate setupDriftClient(\n\t\tconfig: Omit<AuthorityDriftConfig, 'onUserAccountUpdate'>\n\t) {\n\t\tconst driftEnv = config.driftEnv;\n\n\t\tconst connection = new Connection(config.solanaRpcEndpoint);\n\t\tconst driftProgramID = new PublicKey(DRIFT_PROGRAM_ID);\n\t\tconst accountLoader = new CustomizedCadenceBulkAccountLoader(\n\t\t\tconnection,\n\t\t\tDEFAULT_ACCOUNT_LOADER_COMMITMENT,\n\t\t\tDEFAULT_ACCOUNT_LOADER_POLLING_FREQUENCY_MS\n\t\t);\n\t\tthis.accountLoader = accountLoader;\n\n\t\tconst wallet = config.wallet ?? COMMON_UI_UTILS.createPlaceholderIWallet();\n\t\tconst skipInitialUsersLoad = !config.wallet;\n\n\t\tconst perpMarkets =\n\t\t\tconfig.tradableMarkets\n\t\t\t\t?.filter((market) => market.isPerp)\n\t\t\t\t.map((market) =>\n\t\t\t\t\tMARKET_UTILS.getMarketConfig(\n\t\t\t\t\t\tdriftEnv,\n\t\t\t\t\t\tMarketType.PERP,\n\t\t\t\t\t\tmarket.marketIndex\n\t\t\t\t\t)\n\t\t\t\t) ?? PerpMarkets[driftEnv];\n\t\tconst spotMarkets =\n\t\t\tconfig.tradableMarkets\n\t\t\t\t?.filter((market) => !market.isPerp)\n\t\t\t\t.map((market) =>\n\t\t\t\t\tMARKET_UTILS.getMarketConfig(\n\t\t\t\t\t\tdriftEnv,\n\t\t\t\t\t\tMarketType.SPOT,\n\t\t\t\t\t\tmarket.marketIndex\n\t\t\t\t\t)\n\t\t\t\t) ?? SpotMarkets[driftEnv];\n\t\tconst { perpMarketIndexes, spotMarketIndexes, oracleInfos } =\n\t\t\tgetMarketsAndOraclesForSubscription(driftEnv, perpMarkets, spotMarkets);\n\n\t\tconst driftClientConfig: DriftClientConfig = {\n\t\t\tenv: driftEnv,\n\t\t\tconnection,\n\t\t\twallet,\n\t\t\tprogramID: driftProgramID,\n\t\t\tenableMetricsEvents: false,\n\t\t\taccountSubscription: {\n\t\t\t\ttype: 'polling',\n\t\t\t\taccountLoader,\n\t\t\t},\n\t\t\tuserStats: true,\n\t\t\tincludeDelegates: true,\n\t\t\tskipLoadUsers: skipInitialUsersLoad,\n\t\t\tdelistedMarketSetting: DelistedMarketSetting.Unsubscribe,\n\t\t\tperpMarketIndexes,\n\t\t\tspotMarketIndexes,\n\t\t\toracleInfos,\n\t\t\t...config.additionalDriftClientConfig,\n\t\t};\n\t\tthis._driftClient = new DriftClient(driftClientConfig);\n\n\t\tconst txSender = new WhileValidTxSender({\n\t\t\tconnection,\n\t\t\twallet,\n\t\t\tadditionalConnections: [],\n\t\t\tadditionalTxSenderCallbacks: [],\n\t\t\ttxHandler: this._driftClient.txHandler,\n\t\t\tconfirmationStrategy: DEFAULT_TX_SENDER_CONFIRMATION_STRATEGY,\n\t\t\tretrySleep: DEFAULT_TX_SENDER_RETRY_INTERVAL,\n\t\t});\n\n\t\tthis._driftClient.txSender = txSender;\n\n\t\treturn this._driftClient;\n\t}\n\n\tprivate setupOrderbookManager() {\n\t\tthis.orderbookSubscription = this._orderbookManager.onUpdate(\n\t\t\t(orderbookData) => {\n\t\t\t\tconst marketKey = new MarketId(\n\t\t\t\t\torderbookData.marketIndex,\n\t\t\t\t\tENUM_UTILS.toObj(orderbookData.marketType as string) as MarketType\n\t\t\t\t).key;\n\n\t\t\t\tconst markPrice = orderbookData.markPrice;\n\n\t\t\t\tthis._markPriceCache.updateMarkPrices({\n\t\t\t\t\tmarketKey,\n\t\t\t\t\tmarkPrice,\n\t\t\t\t\tbestAsk: orderbookData.bestAskPrice,\n\t\t\t\t\tbestBid: orderbookData.bestBidPrice,\n\t\t\t\t\tlastUpdateSlot: orderbookData.slot ?? 0,\n\t\t\t\t});\n\n\t\t\t\tthis._oraclePriceCache.updateOraclePrices({\n\t\t\t\t\t...orderbookData.oracleData,\n\t\t\t\t\tmarketKey,\n\t\t\t\t});\n\t\t\t}\n\t\t);\n\t}\n\n\tprivate setupPollingDlob() {\n\t\t// DriftL2OrderbookManager will handle the fetching of data for the selected trade market through websocket\n\n\t\tthis._pollingDlob.addInterval(\n\t\t\tPollingCategory.USER_INVOLVED,\n\t\t\tPOLLING_INTERVALS.BACKGROUND_DEEP,\n\t\t\tPOLLING_DEPTHS.DEEP\n\t\t); // markets that the user is involved in\n\t\tthis._pollingDlob.addInterval(\n\t\t\tPollingCategory.USER_NOT_INVOLVED,\n\t\t\tPOLLING_INTERVALS.BACKGROUND_SHALLOW,\n\t\t\tPOLLING_DEPTHS.SHALLOW\n\t\t); // markets that the user is not involved in\n\n\t\t// add all markets to the user-not-involved interval first, until user-involved markets are known\n\t\tthis._pollingDlob.addMarketsToInterval(\n\t\t\tPollingCategory.USER_NOT_INVOLVED,\n\t\t\tthis._tradableMarkets.map((market) => market.key)\n\t\t);\n\n\t\tthis.pollingDlobSubscription = this._pollingDlob\n\t\t\t.onData()\n\t\t\t.subscribe((data) => {\n\t\t\t\tconst updatedMarkPrices = data.map((marketData) => {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tmarketKey: marketData.marketId.key,\n\t\t\t\t\t\tmarkPrice: marketData.data.markPrice,\n\t\t\t\t\t\tbestBid: marketData.data.bestBidPrice,\n\t\t\t\t\t\tbestAsk: marketData.data.bestAskPrice,\n\t\t\t\t\t\tlastUpdateSlot: marketData.data.slot ?? 0,\n\t\t\t\t\t};\n\t\t\t\t});\n\t\t\t\tconst updatedOraclePrices = data.map((marketData) => {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tmarketKey: marketData.marketId.key,\n\t\t\t\t\t\t...marketData.data.oracleData,\n\t\t\t\t\t};\n\t\t\t\t});\n\n\t\t\t\tthis._markPriceCache.updateMarkPrices(...updatedMarkPrices);\n\t\t\t\tthis._oraclePriceCache.updateOraclePrices(...updatedOraclePrices);\n\t\t\t});\n\t}\n\n\tprivate initializeManagers(\n\t\tdlobServerHttpUrl: string,\n\t\tswiftServerUrl: string\n\t) {\n\t\t// Initialize trading operations\n\t\tthis.driftOperations = new DriftOperations(\n\t\t\tthis._driftClient,\n\t\t\t() => this._userAccountCache,\n\t\t\tdlobServerHttpUrl,\n\t\t\tswiftServerUrl,\n\t\t\t() => this.priorityFeeSubscriber.getCustomStrategyResult()\n\t\t);\n\n\t\t// Initialize subscription manager with all subscription and market operations\n\t\tthis.subscriptionManager = new SubscriptionManager(\n\t\t\tthis._driftClient,\n\t\t\tthis.accountLoader,\n\t\t\tthis._pollingDlob,\n\t\t\tthis._orderbookManager,\n\t\t\tthis._userAccountCache,\n\t\t\tthis._tradableMarkets,\n\t\t\tthis.selectedTradeMarket\n\t\t);\n\t}\n\n\tprivate unsubscribeFromPollingDlob() {\n\t\tthis.pollingDlobSubscription?.unsubscribe();\n\t\tthis.pollingDlobSubscription = null;\n\n\t\tthis._pollingDlob.stop();\n\t}\n\n\tprivate unsubscribeFromOrderbook() {\n\t\tthis.orderbookSubscription?.unsubscribe();\n\t\tthis.orderbookSubscription = null;\n\n\t\tthis._orderbookManager.unsubscribe();\n\t}\n\n\tpublic async subscribe() {\n\t\tconst handleGeoBlock = async () => {\n\t\t\ttry {\n\t\t\t\tthis._isGeoBlocked = (await checkGeoBlock()) ?? false;\n\t\t\t} catch (error) {\n\t\t\t\tconsole.warn('Failed to check geoblock status:', error);\n\t\t\t\tthis._isGeoBlocked = false; // Default to not blocked if check fails\n\t\t\t}\n\t\t};\n\n\t\t// async logic that doesn't require DriftClient to be subscribed\n\t\tconst handleGeoBlockPromise = handleGeoBlock();\n\t\tconst pollingDlobStartPromise = this._pollingDlob.start();\n\t\tconst priorityFeeSubscribePromise = this.priorityFeeSubscriber.subscribe();\n\t\tconst orderbookSubscribePromise = this._orderbookManager.subscribe();\n\n\t\tawait this._driftClient.subscribe();\n\n\t\t// filter out markets that are delisted\n\t\tconst actualTradableMarkets = this._tradableMarkets.filter((market) => {\n\t\t\tconst marketAccount = market.isPerp\n\t\t\t\t? this._driftClient.getPerpMarketAccount(market.marketIndex)\n\t\t\t\t: this._driftClient.getSpotMarketAccount(market.marketIndex);\n\n\t\t\tif (\n\t\t\t\t!marketAccount ||\n\t\t\t\tDELISTED_MARKET_STATUSES.some((marketStatus) =>\n\t\t\t\t\tENUM_UTILS.match(marketAccount.status, marketStatus)\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\treturn true;\n\t\t});\n\n\t\tthis._tradableMarkets = actualTradableMarkets;\n\t\tthis.subscriptionManager.updateTradableMarkets(actualTradableMarkets);\n\t\tthis.setupPollingDlob();\n\t\tthis.setupOrderbookManager();\n\n\t\tconst subscribeToNonWhitelistedButUserInvolvedMarketsPromise =\n\t\t\tthis.subscriptionManager.subscribeToNonWhitelistedButUserInvolvedMarkets(\n\t\t\t\tthis._driftClient.getUsers()\n\t\t\t);\n\n\t\tawait Promise.all([\n\t\t\tpollingDlobStartPromise,\n\t\t\tsubscribeToNonWhitelistedButUserInvolvedMarketsPromise,\n\t\t\tpriorityFeeSubscribePromise,\n\t\t\thandleGeoBlockPromise,\n\t\t\torderbookSubscribePromise,\n\t\t]);\n\n\t\tthis.subscriptionManager.subscribeToAllUsersUpdates();\n\n\t\t// TODO: subscribe to oracle price updates from drift client?\n\t}\n\n\tpublic async unsubscribe() {\n\t\tthis.unsubscribeFromPollingDlob();\n\t\tthis.unsubscribeFromOrderbook();\n\t\tthis._userAccountCache.destroy();\n\t\tthis._markPriceCache.destroy();\n\t\tthis._orderbookManager.destroy();\n\n\t\tconst driftClientUnsubscribePromise = this._driftClient.unsubscribe();\n\t\tconst priorityFeeUnsubscribePromise =\n\t\t\tthis.priorityFeeSubscriber.unsubscribe();\n\n\t\tawait Promise.all(\n\t\t\t[driftClientUnsubscribePromise, priorityFeeUnsubscribePromise].filter(\n\t\t\t\tBoolean\n\t\t\t)\n\t\t);\n\n\t\tthis.pollingDlobSubscription = null;\n\t}\n\n\tpublic onOraclePricesUpdate(\n\t\tcallback: (oraclePrice: OraclePriceLookup) => void\n\t) {\n\t\treturn this._oraclePriceCache.onUpdate(callback);\n\t}\n\n\tpublic onMarkPricesUpdate(callback: (markPrice: MarkPriceLookup) => void) {\n\t\treturn this._markPriceCache.onUpdate(callback);\n\t}\n\n\tpublic onUserAccountUpdate(\n\t\tcallback: (userAccount: EnhancedAccountData) => void\n\t) {\n\t\treturn this._userAccountCache.onUpdate(callback);\n\t}\n\n\tpublic onOrderbookUpdate(\n\t\tcallback: (orderbook: L2WithOracleAndMarketData) => void\n\t) {\n\t\treturn this._orderbookManager.onUpdate(callback);\n\t}\n\n\t/**\n\t * Updates the authority (wallet) for the drift client and reestablishes subscriptions.\n\t *\n\t * @param wallet - The new wallet to use as authority\n\t * @param activeSubAccountId - Optional subaccount ID to switch to after wallet update\n\t */\n\tpublic async updateAuthority(wallet: IWallet, activeSubAccountId?: number) {\n\t\treturn this.subscriptionManager.updateAuthority(wallet, activeSubAccountId);\n\t}\n\n\t/**\n\t * Updates the selected trade market and optimizes subscription polling.\n\t *\n\t * @param newSelectedTradeMarket - The new market to prioritize for trading\n\t */\n\tpublic updateSelectedTradeMarket(newSelectedTradeMarket: MarketId | null) {\n\t\tconst isNewSelectedTradeMarket =\n\t\t\t!!newSelectedTradeMarket !== !!this.selectedTradeMarket || // only one of them is null\n\t\t\t(!!newSelectedTradeMarket && // or both are not null and are different\n\t\t\t\t!!this.selectedTradeMarket &&\n\t\t\t\t!this.selectedTradeMarket.equals(newSelectedTradeMarket));\n\n\t\tif (!isNewSelectedTradeMarket) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Update the local reference\n\t\tthis.selectedTradeMarket = newSelectedTradeMarket;\n\n\t\t// Delegate to subscription manager for all polling optimization\n\t\tthis.subscriptionManager.updateSelectedTradeMarket(newSelectedTradeMarket);\n\t}\n\n\t/**\n\t * Creates a new user account and deposits initial collateral.\n\t *\n\t * @param params - Parameters for creating user and depositing collateral\n\t * @returns Promise resolving to transaction signature and user account public key\n\t */\n\tpublic async createUserAndDeposit(\n\t\tparams: CreateUserAndDepositParams\n\t): Promise<{\n\t\ttxSig: TransactionSignature;\n\t\tuser: User;\n\t}> {\n\t\treturn this.driftOperations.createUserAndDeposit(params);\n\t}\n\n\t/**\n\t * Deposits collateral into a user's spot market position.\n\t *\n\t * @param params - Parameters for the deposit operation\n\t * @returns Promise resolving to the transaction signature\n\t */\n\tpublic async deposit(params: DepositParams): Promise<TransactionSignature> {\n\t\treturn this.driftOperations.deposit(params);\n\t}\n\n\t/**\n\t * Withdraws collateral from a user's spot market position.\n\t *\n\t * @param params - Parameters for the withdrawal operation\n\t * @returns Promise resolving to the transaction signature\n\t */\n\tpublic async withdraw(params: WithdrawParams): Promise<TransactionSignature> {\n\t\treturn this.driftOperations.withdraw(params);\n\t}\n\n\t/**\n\t * Opens a perpetual market order.\n\t *\n\t * @param params - Parameters for the perp order\n\t * @returns Promise resolving to the transaction signature\n\t */\n\t@enforceGeoBlock\n\tpublic async openPerpOrder(\n\t\tparams: PerpOrderParams\n\t): Promise<TransactionSignature | void> {\n\t\treturn this.driftOperations.openPerpOrder(params);\n\t}\n\n\t/**\n\t * Executes a swap between two spot markets.\n\t *\n\t * @param params - Parameters for the swap operation\n\t * @returns Promise resolving to the transaction signature\n\t */\n\tpublic async swap(params: SwapParams): Promise<TransactionSignature> {\n\t\treturn this.driftOperations.swap(params);\n\t}\n\n\tpublic async getSwapQuote(\n\t\tparams: Omit<SwapParams, 'jupiterQuote'> & {\n\t\t\tslippageBps?: number;\n\t\t\tswapMode?: SwapMode;\n\t\t\tonlyDirectRoutes?: boolean;\n\t\t}\n\t): Promise<QuoteResponse> {\n\t\treturn this.driftOperations.getSwapQuote(params);\n\t}\n\n\t/**\n\t * Settles profit and loss for a perpetual position.\n\t *\n\t * @param params - Parameters for the settle PnL operation\n\t * @returns Promise resolving to the transaction signature\n\t */\n\tpublic async settleAccountPnl(\n\t\tparams: SettleAccountPnlParams\n\t): Promise<TransactionSignature> {\n\t\treturn this.driftOperations.settleAccountPnl(params);\n\t}\n\n\t/**\n\t * Deletes a user account from the Drift protocol.\n\t *\n\t * @param subAccountId - The ID of the sub-account to delete\n\t * @returns Promise resolving to the transaction signature of the deletion\n\t */\n\tpublic async deleteUser(subAccountId: number): Promise<TransactionSignature> {\n\t\treturn this.driftOperations.deleteUser(subAccountId);\n\t}\n\n\t/**\n\t * Cancels a list of open orders.\n\t *\n\t * @param params - See `CancelOrdersParams`\n\t * @returns Promise resolving to the transaction signature of the cancellation\n\t */\n\tpublic async cancelOrders(\n\t\tparams: CancelOrdersParams\n\t): Promise<TransactionSignature> {\n\t\treturn this.driftOperations.cancelOrders(params);\n\t}\n}\n"]}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { BN, DriftClientConfig, DriftEnv, MarketType, OrderTriggerCondition, PositionDirection,
|
|
1
|
+
import { BN, DriftClientConfig, DriftEnv, MarketType, OrderTriggerCondition, PositionDirection, PublicKey, QuoteResponse, SwapMode } from '@drift-labs/sdk';
|
|
2
2
|
import { Transaction, VersionedTransaction } from '@solana/web3.js';
|
|
3
3
|
import { MarketId } from '../../../types';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { OpenPerpMarketOrderParams } from '../../base/actions/trade/openPerpOrder/openPerpMarketOrder';
|
|
5
|
+
import { OpenPerpNonMarketOrderParams } from '../../base/actions/trade/openPerpOrder/openPerpNonMarketOrder';
|
|
6
|
+
import { TxnOrSwiftResult, WithTxnParams } from '../../base/actions/trade/openPerpOrder/types';
|
|
6
7
|
/**
|
|
7
8
|
* A Drift client that fetches user data on-demand, while market data is continuously subscribed to.
|
|
8
9
|
*
|
|
@@ -46,11 +47,15 @@ export declare class CentralServerDrift {
|
|
|
46
47
|
}): Promise<VersionedTransaction | Transaction>;
|
|
47
48
|
getSettleFundingTxn(userAccountPublicKey: PublicKey): Promise<VersionedTransaction | Transaction>;
|
|
48
49
|
getSettlePnlTxn(userAccountPublicKey: PublicKey, marketIndexes: number[]): Promise<VersionedTransaction | Transaction>;
|
|
49
|
-
getOpenPerpMarketOrderTxn(userAccountPublicKey
|
|
50
|
+
getOpenPerpMarketOrderTxn<T extends boolean>({ userAccountPublicKey, ...rest }: WithTxnParams<Omit<OpenPerpMarketOrderParams<T>, 'driftClient' | 'user'>> & {
|
|
51
|
+
userAccountPublicKey: PublicKey;
|
|
52
|
+
}): Promise<TxnOrSwiftResult<T>>;
|
|
50
53
|
/**
|
|
51
54
|
* Create a perp non-market order with amount and asset type
|
|
52
55
|
*/
|
|
53
|
-
getOpenPerpNonMarketOrderTxn(userAccountPublicKey
|
|
56
|
+
getOpenPerpNonMarketOrderTxn({ userAccountPublicKey, ...rest }: WithTxnParams<Omit<OpenPerpNonMarketOrderParams, 'driftClient' | 'user'>> & {
|
|
57
|
+
userAccountPublicKey: PublicKey;
|
|
58
|
+
}): Promise<VersionedTransaction | Transaction | void>;
|
|
54
59
|
/**
|
|
55
60
|
* Create a transaction to edit an existing order
|
|
56
61
|
*/
|
|
@@ -178,20 +178,12 @@ class CentralServerDrift {
|
|
|
178
178
|
return settlePnlTxn;
|
|
179
179
|
});
|
|
180
180
|
}
|
|
181
|
-
async getOpenPerpMarketOrderTxn(userAccountPublicKey,
|
|
181
|
+
async getOpenPerpMarketOrderTxn({ userAccountPublicKey, ...rest }) {
|
|
182
182
|
return this.driftClientContextWrapper(userAccountPublicKey, async (user) => {
|
|
183
|
-
const openPerpMarketOrderTxn = await (0, openPerpMarketOrder_1.
|
|
183
|
+
const openPerpMarketOrderTxn = await (0, openPerpMarketOrder_1.createOpenPerpMarketOrder)({
|
|
184
|
+
...rest,
|
|
184
185
|
driftClient: this.driftClient,
|
|
185
186
|
user,
|
|
186
|
-
assetType,
|
|
187
|
-
marketIndex,
|
|
188
|
-
direction,
|
|
189
|
-
amount,
|
|
190
|
-
dlobServerHttpUrl,
|
|
191
|
-
auctionParamsOptions,
|
|
192
|
-
useSwift,
|
|
193
|
-
swiftOptions,
|
|
194
|
-
marketType,
|
|
195
187
|
});
|
|
196
188
|
return openPerpMarketOrderTxn;
|
|
197
189
|
});
|
|
@@ -199,47 +191,12 @@ class CentralServerDrift {
|
|
|
199
191
|
/**
|
|
200
192
|
* Create a perp non-market order with amount and asset type
|
|
201
193
|
*/
|
|
202
|
-
async getOpenPerpNonMarketOrderTxn(userAccountPublicKey,
|
|
203
|
-
let orderConfig;
|
|
204
|
-
switch (orderType) {
|
|
205
|
-
case 'limit':
|
|
206
|
-
orderConfig = {
|
|
207
|
-
orderType,
|
|
208
|
-
limitPrice,
|
|
209
|
-
};
|
|
210
|
-
break;
|
|
211
|
-
case 'takeProfit':
|
|
212
|
-
case 'stopLoss':
|
|
213
|
-
orderConfig = {
|
|
214
|
-
orderType,
|
|
215
|
-
triggerPrice,
|
|
216
|
-
limitPrice,
|
|
217
|
-
};
|
|
218
|
-
break;
|
|
219
|
-
case 'oracleLimit':
|
|
220
|
-
orderConfig = {
|
|
221
|
-
orderType,
|
|
222
|
-
oraclePriceOffset,
|
|
223
|
-
};
|
|
224
|
-
break;
|
|
225
|
-
default: {
|
|
226
|
-
const _exhaustiveCheck = orderType;
|
|
227
|
-
throw new Error(`Unsupported order type: ${_exhaustiveCheck}`);
|
|
228
|
-
}
|
|
229
|
-
}
|
|
194
|
+
async getOpenPerpNonMarketOrderTxn({ userAccountPublicKey, ...rest }) {
|
|
230
195
|
return this.driftClientContextWrapper(userAccountPublicKey, async (user) => {
|
|
231
196
|
const openPerpNonMarketOrderTxn = await (0, openPerpNonMarketOrder_1.createOpenPerpNonMarketOrderTxn)({
|
|
197
|
+
...rest,
|
|
232
198
|
driftClient: this.driftClient,
|
|
233
199
|
user,
|
|
234
|
-
marketIndex,
|
|
235
|
-
direction,
|
|
236
|
-
amount,
|
|
237
|
-
assetType,
|
|
238
|
-
orderConfig,
|
|
239
|
-
reduceOnly,
|
|
240
|
-
postOnly,
|
|
241
|
-
useSwift,
|
|
242
|
-
swiftOptions,
|
|
243
200
|
});
|
|
244
201
|
return openPerpNonMarketOrderTxn;
|
|
245
202
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CentralServerDrift.js","sourceRoot":"","sources":["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;iBACpD,CAAC,CAAC;YACJ,CAAC;YAED,MAAM,OAAO,GAAG,MAAM,IAAA,oBAAa,EAAC;gBACnC,WAAW,EAAE,IAAI,CAAC,WAAW;gBAC7B,aAAa;gBACb,IAAI;gBACJ,mBAAmB,EAAE,eAAe;gBACpC,iBAAiB,EAAE,aAAa;gBAChC,MAAM;gBACN,KAAK;gBACL,QAAQ,EAAE;oBACT,wBAAwB,EAAE,IAAI;oBAC9B,4BAA4B,EAAE,GAAG;iBACjC;aACD,CAAC,CAAC;YAEH,OAAO,OAAO,CAAC;QAChB,CAAC,CACD,CAAC;IACH,CAAC;IAEM,KAAK,CAAC,qBAAqB,CAAC,EAAsC;QACxE,OAAO,IAAI,CAAC,WAAW,CAAC,eAAe,CAAC,EAAE,EAAE,SAAS,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;IACzE,CAAC;CACD;AArgBD,gDAqgBC","sourcesContent":["import {\n\tBigNum,\n\tBN,\n\tCustomizedCadenceBulkAccountLoader,\n\tDelistedMarketSetting,\n\tDevnetPerpMarkets,\n\tDevnetSpotMarkets,\n\tDRIFT_PROGRAM_ID,\n\tDriftClient,\n\tDriftClientConfig,\n\tDriftEnv,\n\tJupiterClient,\n\tMainnetPerpMarkets,\n\tMainnetSpotMarkets,\n\tMarketType,\n\tOrderTriggerCondition,\n\tPerpMarketConfig,\n\tPositionDirection,\n\tPostOnlyParams,\n\tPublicKey,\n\tQuoteResponse,\n\tSpotMarketConfig,\n\tSwapMode,\n\tUser,\n\tWhileValidTxSender,\n} from '@drift-labs/sdk';\nimport { Connection, Transaction, VersionedTransaction } from '@solana/web3.js';\nimport { COMMON_UI_UTILS } from '../../../common-ui-utils/commonUiUtils';\nimport {\n\tDEFAULT_ACCOUNT_LOADER_COMMITMENT,\n\tDEFAULT_ACCOUNT_LOADER_POLLING_FREQUENCY_MS,\n\tDEFAULT_TX_SENDER_CONFIRMATION_STRATEGY,\n\tDEFAULT_TX_SENDER_RETRY_INTERVAL,\n} from '../constants';\nimport { MarketId } from '../../../types';\nimport { createDepositTxn } from '../../base/actions/spot/deposit';\nimport { createWithdrawTxn } from '../../base/actions/spot/withdraw';\nimport { createSettleFundingTxn } from '../../base/actions/perp/settleFunding';\nimport { createSettlePnlTxn } from '../../base/actions/perp/settlePnl';\nimport {\n\tcreateOpenPerpMarketOrderTxn,\n\tAuctionParamsRequestOptions,\n} from '../../base/actions/trade/openPerpOrder/openPerpMarketOrder';\nimport { createOpenPerpNonMarketOrderTxn } from '../../base/actions/trade/openPerpOrder/openPerpNonMarketOrder';\nimport { createEditOrderTxn } from '../../base/actions/trade/editOrder';\nimport { createCancelOrdersTxn } from '../../base/actions/trade/cancelOrder';\nimport { createSwapTxn } from '../../base/actions/trade/swap';\nimport { NonMarketOrderParamsConfig } from '../../utils/orderParams';\nimport {\n\tSwiftOrderResult,\n\tSwiftOrderOptions,\n} from '../../base/actions/trade/openPerpOrder/openSwiftOrder';\n\n/**\n * A Drift client that fetches user data on-demand, while market data is continuously subscribed to.\n *\n * This is useful for an API server that fetches user data on-demand, and return transaction messages specific to a given user\n */\nexport class CentralServerDrift {\n\tprivate driftClient: DriftClient;\n\tprivate _perpMarketConfigs: PerpMarketConfig[];\n\tprivate spotMarketConfigs: SpotMarketConfig[];\n\n\t/**\n\t * @param solanaRpcEndpoint - The Solana RPC endpoint to use for reading RPC data.\n\t * @param driftEnv - The drift environment to use for the drift client.\n\t * @param activeTradeMarket - The active trade market to use for the drift client. This is used to subscribe to the market account, oracle data and mark price more frequently compared to the other markets.\n\t * @param additionalDriftClientConfig - Additional DriftClient config to use for the DriftClient.\n\t */\n\tconstructor(config: {\n\t\tsolanaRpcEndpoint: string;\n\t\tdriftEnv: DriftEnv;\n\t\tadditionalDriftClientConfig?: Partial<Omit<DriftClientConfig, 'env'>>;\n\t\tactiveTradeMarket?: MarketId;\n\t\tmarketsToSubscribe?: MarketId[];\n\t}) {\n\t\tconst driftEnv = config.driftEnv;\n\n\t\tconst connection = new Connection(config.solanaRpcEndpoint);\n\t\tconst driftProgramID = new PublicKey(DRIFT_PROGRAM_ID);\n\t\tconst accountLoader = new CustomizedCadenceBulkAccountLoader(\n\t\t\tconnection,\n\t\t\tDEFAULT_ACCOUNT_LOADER_COMMITMENT,\n\t\t\tDEFAULT_ACCOUNT_LOADER_POLLING_FREQUENCY_MS\n\t\t);\n\n\t\tconst wallet = COMMON_UI_UTILS.createPlaceholderIWallet(); // use random wallet to initialize a central-server instance\n\n\t\tconst driftClientConfig: DriftClientConfig = {\n\t\t\tenv: driftEnv,\n\t\t\tconnection,\n\t\t\twallet,\n\t\t\tprogramID: driftProgramID,\n\t\t\tenableMetricsEvents: false,\n\t\t\taccountSubscription: {\n\t\t\t\ttype: 'polling',\n\t\t\t\taccountLoader,\n\t\t\t},\n\t\t\tuserStats: false,\n\t\t\tincludeDelegates: false,\n\t\t\tskipLoadUsers: true,\n\t\t\tdelistedMarketSetting: DelistedMarketSetting.Unsubscribe,\n\t\t\t...config.additionalDriftClientConfig,\n\t\t};\n\t\tthis.driftClient = new DriftClient(driftClientConfig);\n\n\t\tconst txSender = new WhileValidTxSender({\n\t\t\tconnection,\n\t\t\twallet,\n\t\t\tadditionalConnections: [],\n\t\t\tadditionalTxSenderCallbacks: [],\n\t\t\ttxHandler: this.driftClient.txHandler,\n\t\t\tconfirmationStrategy: DEFAULT_TX_SENDER_CONFIRMATION_STRATEGY,\n\t\t\tretrySleep: DEFAULT_TX_SENDER_RETRY_INTERVAL,\n\t\t});\n\n\t\tthis.driftClient.txSender = txSender;\n\t\tthis._perpMarketConfigs =\n\t\t\tdriftEnv === 'devnet' ? DevnetPerpMarkets : MainnetPerpMarkets;\n\t\tthis.spotMarketConfigs =\n\t\t\tdriftEnv === 'devnet' ? DevnetSpotMarkets : MainnetSpotMarkets;\n\t}\n\n\tpublic async subscribe() {\n\t\tawait this.driftClient.subscribe();\n\t}\n\n\t/**\n\t * Manages DriftClient state for transaction creation with proper setup and cleanup.\n\t * This abstraction handles:\n\t * - User creation and subscription\n\t * - Authority management\n\t * - Wallet replacement for correct transaction signing\n\t * - Cleanup and state restoration\n\t *\n\t * @param userAccountPublicKey - The user account public key\n\t * @param operation - The transaction creation operation to execute\n\t * @returns The result of the operation\n\t */\n\tprivate async driftClientContextWrapper<T>(\n\t\tuserAccountPublicKey: PublicKey,\n\t\toperation: (user: User) => Promise<T>\n\t): Promise<T> {\n\t\tconst user = new User({\n\t\t\tdriftClient: this.driftClient,\n\t\t\tuserAccountPublicKey,\n\t\t});\n\n\t\t// Store original state\n\t\tconst originalWallet = this.driftClient.wallet;\n\t\tconst originalAuthority = this.driftClient.authority;\n\n\t\ttry {\n\t\t\t// Setup: Subscribe to user and configure DriftClient\n\t\t\tawait user.subscribe();\n\n\t\t\tconst authority = user.getUserAccount().authority;\n\t\t\tthis.driftClient.authority = authority;\n\n\t\t\tconst success = await this.driftClient.addUser(\n\t\t\t\tuser.getUserAccount().subAccountId,\n\t\t\t\tauthority\n\t\t\t);\n\n\t\t\tif (!success) {\n\t\t\t\tthrow new Error('Failed to add user to DriftClient');\n\t\t\t}\n\n\t\t\t// Replace wallet with user's authority to ensure correct transaction signing\n\t\t\t// This is necessary because DriftClient adds wallet.publicKey to instructions\n\t\t\tconst userWallet = {\n\t\t\t\tpublicKey: authority,\n\t\t\t\tsignTransaction: () =>\n\t\t\t\t\tPromise.reject(\n\t\t\t\t\t\t'This is a placeholder - do not sign with this wallet'\n\t\t\t\t\t),\n\t\t\t\tsignAllTransactions: () =>\n\t\t\t\t\tPromise.reject(\n\t\t\t\t\t\t'This is a placeholder - do not sign with this wallet'\n\t\t\t\t\t),\n\t\t\t};\n\n\t\t\t// Update wallet in all places that reference it\n\t\t\tthis.driftClient.wallet = userWallet;\n\t\t\t//@ts-ignore\n\t\t\tthis.driftClient.provider.wallet = userWallet;\n\t\t\tthis.driftClient.txHandler.updateWallet(userWallet);\n\n\t\t\t// Execute the operation\n\t\t\tconst result = await operation(user);\n\n\t\t\treturn result;\n\t\t} finally {\n\t\t\t// Cleanup: Always restore original state and unsubscribe\n\t\t\tthis.driftClient.wallet = originalWallet;\n\t\t\tthis.driftClient.txHandler.updateWallet(originalWallet);\n\t\t\tthis.driftClient.authority = originalAuthority;\n\n\t\t\ttry {\n\t\t\t\tawait user.unsubscribe();\n\t\t\t\tthis.driftClient.users.clear();\n\t\t\t} catch (cleanupError) {\n\t\t\t\tconsole.warn('Error during cleanup:', cleanupError);\n\t\t\t\t// Don't throw cleanup errors, but log them\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic async getDepositTxn(\n\t\tuserAccountPublicKey: PublicKey,\n\t\tamount: BN,\n\t\tspotMarketIndex: number\n\t): Promise<VersionedTransaction | Transaction> {\n\t\treturn this.driftClientContextWrapper(\n\t\t\tuserAccountPublicKey,\n\t\t\tasync (user) => {\n\t\t\t\tconst spotMarketConfig = this.spotMarketConfigs.find(\n\t\t\t\t\t(market) => market.marketIndex === spotMarketIndex\n\t\t\t\t);\n\n\t\t\t\tif (!spotMarketConfig) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Spot market config not found for index ${spotMarketIndex}`\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tconst depositTxn = await createDepositTxn({\n\t\t\t\t\tdriftClient: this.driftClient,\n\t\t\t\t\tuser,\n\t\t\t\t\tamount: BigNum.from(amount, spotMarketConfig.precisionExp),\n\t\t\t\t\tspotMarketConfig,\n\t\t\t\t});\n\n\t\t\t\treturn depositTxn;\n\t\t\t}\n\t\t);\n\t}\n\n\tpublic async getWithdrawTxn(\n\t\tuserAccountPublicKey: PublicKey,\n\t\tamount: BN,\n\t\tspotMarketIndex: number,\n\t\toptions?: {\n\t\t\tisBorrow?: boolean;\n\t\t\tisMax?: boolean;\n\t\t}\n\t): Promise<VersionedTransaction | Transaction> {\n\t\treturn this.driftClientContextWrapper(\n\t\t\tuserAccountPublicKey,\n\t\t\tasync (user) => {\n\t\t\t\tconst spotMarketConfig = this.spotMarketConfigs.find(\n\t\t\t\t\t(market) => market.marketIndex === spotMarketIndex\n\t\t\t\t);\n\n\t\t\t\tif (!spotMarketConfig) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Spot market config not found for index ${spotMarketIndex}`\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tconst withdrawTxn = await createWithdrawTxn({\n\t\t\t\t\tdriftClient: this.driftClient,\n\t\t\t\t\tuser,\n\t\t\t\t\tamount: BigNum.from(amount, spotMarketConfig.precisionExp),\n\t\t\t\t\tspotMarketConfig,\n\t\t\t\t\tisBorrow: options?.isBorrow,\n\t\t\t\t\tisMax: options?.isMax,\n\t\t\t\t});\n\n\t\t\t\treturn withdrawTxn;\n\t\t\t}\n\t\t);\n\t}\n\n\tpublic async getSettleFundingTxn(\n\t\tuserAccountPublicKey: PublicKey\n\t): Promise<VersionedTransaction | Transaction> {\n\t\treturn this.driftClientContextWrapper(\n\t\t\tuserAccountPublicKey,\n\t\t\tasync (user) => {\n\t\t\t\tconst settleFundingTxn = await createSettleFundingTxn({\n\t\t\t\t\tdriftClient: this.driftClient,\n\t\t\t\t\tuser,\n\t\t\t\t});\n\n\t\t\t\treturn settleFundingTxn;\n\t\t\t}\n\t\t);\n\t}\n\n\tpublic async getSettlePnlTxn(\n\t\tuserAccountPublicKey: PublicKey,\n\t\tmarketIndexes: number[]\n\t): Promise<VersionedTransaction | Transaction> {\n\t\treturn this.driftClientContextWrapper(\n\t\t\tuserAccountPublicKey,\n\t\t\tasync (user) => {\n\t\t\t\tconst settlePnlTxn = await createSettlePnlTxn({\n\t\t\t\t\tdriftClient: this.driftClient,\n\t\t\t\t\tuser,\n\t\t\t\t\tmarketIndexes,\n\t\t\t\t});\n\n\t\t\t\treturn settlePnlTxn;\n\t\t\t}\n\t\t);\n\t}\n\n\tpublic async getOpenPerpMarketOrderTxn(\n\t\tuserAccountPublicKey: PublicKey,\n\t\tassetType: 'base' | 'quote',\n\t\tmarketIndex: number,\n\t\tdirection: PositionDirection,\n\t\tamount: BN,\n\t\tdlobServerHttpUrl: string,\n\t\tauctionParamsOptions?: AuctionParamsRequestOptions,\n\t\tuseSwift?: boolean,\n\t\tswiftOptions?: SwiftOrderOptions,\n\t\tmarketType?: MarketType\n\t): Promise<VersionedTransaction | Transaction | SwiftOrderResult> {\n\t\treturn this.driftClientContextWrapper(\n\t\t\tuserAccountPublicKey,\n\t\t\tasync (user) => {\n\t\t\t\tconst openPerpMarketOrderTxn = await createOpenPerpMarketOrderTxn({\n\t\t\t\t\tdriftClient: this.driftClient,\n\t\t\t\t\tuser,\n\t\t\t\t\tassetType,\n\t\t\t\t\tmarketIndex,\n\t\t\t\t\tdirection,\n\t\t\t\t\tamount,\n\t\t\t\t\tdlobServerHttpUrl,\n\t\t\t\t\tauctionParamsOptions,\n\t\t\t\t\tuseSwift,\n\t\t\t\t\tswiftOptions,\n\t\t\t\t\tmarketType,\n\t\t\t\t});\n\n\t\t\t\treturn openPerpMarketOrderTxn;\n\t\t\t}\n\t\t);\n\t}\n\n\t/**\n\t * Create a perp non-market order with amount and asset type\n\t */\n\tpublic async getOpenPerpNonMarketOrderTxn(\n\t\tuserAccountPublicKey: PublicKey,\n\t\tmarketIndex: number,\n\t\tdirection: PositionDirection,\n\t\tamount: BN,\n\t\tassetType: 'base' | 'quote',\n\t\tlimitPrice?: BN,\n\t\ttriggerPrice?: BN,\n\t\torderType?: 'limit' | 'takeProfit' | 'stopLoss' | 'oracleLimit',\n\t\treduceOnly?: boolean,\n\t\tpostOnly?: PostOnlyParams,\n\t\tuseSwift?: boolean,\n\t\tswiftOptions?: SwiftOrderOptions,\n\t\toraclePriceOffset?: BN\n\t): Promise<VersionedTransaction | Transaction | SwiftOrderResult> {\n\t\tlet orderConfig: NonMarketOrderParamsConfig['orderConfig'];\n\n\t\tswitch (orderType) {\n\t\t\tcase 'limit':\n\t\t\t\torderConfig = {\n\t\t\t\t\torderType,\n\t\t\t\t\tlimitPrice,\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\tcase 'takeProfit':\n\t\t\tcase 'stopLoss':\n\t\t\t\torderConfig = {\n\t\t\t\t\torderType,\n\t\t\t\t\ttriggerPrice,\n\t\t\t\t\tlimitPrice,\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\tcase 'oracleLimit':\n\t\t\t\torderConfig = {\n\t\t\t\t\torderType,\n\t\t\t\t\toraclePriceOffset,\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\tdefault: {\n\t\t\t\tconst _exhaustiveCheck: never = orderType;\n\t\t\t\tthrow new Error(`Unsupported order type: ${_exhaustiveCheck}`);\n\t\t\t}\n\t\t}\n\n\t\treturn this.driftClientContextWrapper(\n\t\t\tuserAccountPublicKey,\n\t\t\tasync (user) => {\n\t\t\t\tconst openPerpNonMarketOrderTxn = await createOpenPerpNonMarketOrderTxn(\n\t\t\t\t\t{\n\t\t\t\t\t\tdriftClient: this.driftClient,\n\t\t\t\t\t\tuser,\n\t\t\t\t\t\tmarketIndex,\n\t\t\t\t\t\tdirection,\n\t\t\t\t\t\tamount,\n\t\t\t\t\t\tassetType,\n\t\t\t\t\t\torderConfig,\n\t\t\t\t\t\treduceOnly,\n\t\t\t\t\t\tpostOnly,\n\t\t\t\t\t\tuseSwift,\n\t\t\t\t\t\tswiftOptions,\n\t\t\t\t\t}\n\t\t\t\t);\n\n\t\t\t\treturn openPerpNonMarketOrderTxn;\n\t\t\t}\n\t\t);\n\t}\n\n\t/**\n\t * Create a transaction to edit an existing order\n\t */\n\tpublic async getEditOrderTxn(\n\t\tuserAccountPublicKey: PublicKey,\n\t\torderId: number,\n\t\teditOrderParams: {\n\t\t\tnewDirection?: PositionDirection;\n\t\t\tnewBaseAmount?: BN;\n\t\t\tnewLimitPrice?: BN;\n\t\t\tnewOraclePriceOffset?: number;\n\t\t\tnewTriggerPrice?: BN;\n\t\t\tnewTriggerCondition?: OrderTriggerCondition;\n\t\t\tauctionDuration?: number;\n\t\t\tauctionStartPrice?: BN;\n\t\t\tauctionEndPrice?: BN;\n\t\t\treduceOnly?: boolean;\n\t\t\tpostOnly?: boolean;\n\t\t\tbitFlags?: number;\n\t\t\tmaxTs?: BN;\n\t\t\tpolicy?: number;\n\t\t}\n\t): Promise<VersionedTransaction | Transaction> {\n\t\treturn this.driftClientContextWrapper(\n\t\t\tuserAccountPublicKey,\n\t\t\tasync (user) => {\n\t\t\t\tconst editOrderTxn = await createEditOrderTxn(\n\t\t\t\t\tthis.driftClient,\n\t\t\t\t\tuser,\n\t\t\t\t\torderId,\n\t\t\t\t\teditOrderParams\n\t\t\t\t);\n\n\t\t\t\treturn editOrderTxn;\n\t\t\t}\n\t\t);\n\t}\n\n\t/**\n\t * Create a transaction to cancel specific orders by their IDs\n\t */\n\tpublic async getCancelOrdersTxn(\n\t\tuserAccountPublicKey: PublicKey,\n\t\torderIds: number[]\n\t): Promise<VersionedTransaction | Transaction> {\n\t\treturn this.driftClientContextWrapper(\n\t\t\tuserAccountPublicKey,\n\t\t\tasync (user) => {\n\t\t\t\tconst cancelOrdersTxn = await createCancelOrdersTxn(\n\t\t\t\t\tthis.driftClient,\n\t\t\t\t\tuser,\n\t\t\t\t\torderIds\n\t\t\t\t);\n\n\t\t\t\treturn cancelOrdersTxn;\n\t\t\t}\n\t\t);\n\t}\n\n\t/**\n\t * Create a transaction to cancel all orders for a user\n\t */\n\tpublic async getCancelAllOrdersTxn(\n\t\tuserAccountPublicKey: PublicKey,\n\t\tmarketType?: MarketType,\n\t\tmarketIndex?: number,\n\t\tdirection?: PositionDirection\n\t): Promise<VersionedTransaction | Transaction> {\n\t\treturn this.driftClientContextWrapper(\n\t\t\tuserAccountPublicKey,\n\t\t\tasync (user) => {\n\t\t\t\tconst ix = await this.driftClient.getCancelOrdersIx(\n\t\t\t\t\tmarketType ?? null,\n\t\t\t\t\tmarketIndex ?? null,\n\t\t\t\t\tdirection ?? null,\n\t\t\t\t\tuser.getUserAccount().subAccountId\n\t\t\t\t);\n\n\t\t\t\tconst cancelAllOrdersTxn = await this.driftClient.buildTransaction(ix);\n\n\t\t\t\treturn cancelAllOrdersTxn;\n\t\t\t}\n\t\t);\n\t}\n\n\t/**\n\t * Create a swap transaction between two spot markets using Jupiter\n\t */\n\tpublic async getSwapTxn(\n\t\tuserAccountPublicKey: PublicKey,\n\t\tfromMarketIndex: number,\n\t\ttoMarketIndex: number,\n\t\tamount: BN,\n\t\toptions?: {\n\t\t\tslippageBps?: number;\n\t\t\tswapMode?: SwapMode;\n\t\t\tonlyDirectRoutes?: boolean;\n\t\t\tquote?: QuoteResponse;\n\t\t}\n\t): Promise<VersionedTransaction | Transaction> {\n\t\treturn this.driftClientContextWrapper(\n\t\t\tuserAccountPublicKey,\n\t\t\tasync (user) => {\n\t\t\t\tconst fromSpotMarketConfig = this.spotMarketConfigs.find(\n\t\t\t\t\t(market) => market.marketIndex === fromMarketIndex\n\t\t\t\t);\n\t\t\t\tconst toSpotMarketConfig = this.spotMarketConfigs.find(\n\t\t\t\t\t(market) => market.marketIndex === toMarketIndex\n\t\t\t\t);\n\n\t\t\t\tif (!fromSpotMarketConfig) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`From spot market config not found for index ${fromMarketIndex}`\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tif (!toSpotMarketConfig) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`To spot market config not found for index ${toMarketIndex}`\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\t// Initialize Jupiter client\n\t\t\t\tconst jupiterClient = new JupiterClient({\n\t\t\t\t\tconnection: this.driftClient.connection,\n\t\t\t\t});\n\n\t\t\t\t// Get quote if not provided\n\t\t\t\tlet quote = options?.quote;\n\t\t\t\tif (!quote) {\n\t\t\t\t\tquote = await jupiterClient.getQuote({\n\t\t\t\t\t\tinputMint: fromSpotMarketConfig.mint,\n\t\t\t\t\t\toutputMint: toSpotMarketConfig.mint,\n\t\t\t\t\t\tamount,\n\t\t\t\t\t\tslippageBps: options?.slippageBps ?? 10, // Default 0.1%\n\t\t\t\t\t\tswapMode: options?.swapMode ?? 'ExactIn',\n\t\t\t\t\t\tonlyDirectRoutes: options?.onlyDirectRoutes ?? false,\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tconst swapTxn = await createSwapTxn({\n\t\t\t\t\tdriftClient: this.driftClient,\n\t\t\t\t\tjupiterClient,\n\t\t\t\t\tuser,\n\t\t\t\t\tswapFromMarketIndex: fromMarketIndex,\n\t\t\t\t\tswapToMarketIndex: toMarketIndex,\n\t\t\t\t\tamount,\n\t\t\t\t\tquote,\n\t\t\t\t\ttxParams: {\n\t\t\t\t\t\tuseSimulatedComputeUnits: true,\n\t\t\t\t\t\tcomputeUnitsBufferMultiplier: 1.5,\n\t\t\t\t\t},\n\t\t\t\t});\n\n\t\t\t\treturn swapTxn;\n\t\t\t}\n\t\t);\n\t}\n\n\tpublic async sendSignedTransaction(tx: VersionedTransaction | Transaction) {\n\t\treturn this.driftClient.sendTransaction(tx, undefined, undefined, true);\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"CentralServerDrift.js","sourceRoot":"","sources":["../../../../src/drift/Drift/clients/CentralServerDrift.ts"],"names":[],"mappings":";;;AAAA,yCAwByB;AACzB,6CAAgF;AAChF,0EAAyE;AACzE,4CAKsB;AAEtB,6DAAmE;AACnE,+DAAqE;AACrE,yEAA+E;AAC/E,iEAAuE;AACvE,oGAGoE;AACpE,0GAGuE;AACvE,kEAAwE;AACxE,sEAA6E;AAC7E,wDAA8D;AAM9D;;;;GAIG;AACH,MAAa,kBAAkB;IAK9B;;;;;OAKG;IACH,YAAY,MAMX;QACA,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;QAEjC,MAAM,UAAU,GAAG,IAAI,oBAAU,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC;QAC5D,MAAM,cAAc,GAAG,IAAI,eAAS,CAAC,sBAAgB,CAAC,CAAC;QACvD,MAAM,aAAa,GAAG,IAAI,wCAAkC,CAC3D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E;oBACT,wBAAwB,EAAE,IAAI;oBAC9B,4BAA4B,EAAE,GAAG;iBACjC;aACD,CAAC,CAAC;YAEH,OAAO,OAAO,CAAC;QAChB,CAAC,CACD,CAAC;IACH,CAAC;IAEM,KAAK,CAAC,qBAAqB,CAAC,EAAsC;QACxE,OAAO,IAAI,CAAC,WAAW,CAAC,eAAe,CAAC,EAAE,EAAE,SAAS,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;IACzE,CAAC;CACD;AA5cD,gDA4cC","sourcesContent":["import {\n\tBigNum,\n\tBN,\n\tCustomizedCadenceBulkAccountLoader,\n\tDelistedMarketSetting,\n\tDevnetPerpMarkets,\n\tDevnetSpotMarkets,\n\tDRIFT_PROGRAM_ID,\n\tDriftClient,\n\tDriftClientConfig,\n\tDriftEnv,\n\tJupiterClient,\n\tMainnetPerpMarkets,\n\tMainnetSpotMarkets,\n\tMarketType,\n\tOrderTriggerCondition,\n\tPerpMarketConfig,\n\tPositionDirection,\n\tPublicKey,\n\tQuoteResponse,\n\tSpotMarketConfig,\n\tSwapMode,\n\tUser,\n\tWhileValidTxSender,\n} from '@drift-labs/sdk';\nimport { Connection, Transaction, VersionedTransaction } from '@solana/web3.js';\nimport { COMMON_UI_UTILS } from '../../../common-ui-utils/commonUiUtils';\nimport {\n\tDEFAULT_ACCOUNT_LOADER_COMMITMENT,\n\tDEFAULT_ACCOUNT_LOADER_POLLING_FREQUENCY_MS,\n\tDEFAULT_TX_SENDER_CONFIRMATION_STRATEGY,\n\tDEFAULT_TX_SENDER_RETRY_INTERVAL,\n} from '../constants';\nimport { MarketId } from '../../../types';\nimport { createDepositTxn } from '../../base/actions/spot/deposit';\nimport { createWithdrawTxn } from '../../base/actions/spot/withdraw';\nimport { createSettleFundingTxn } from '../../base/actions/perp/settleFunding';\nimport { createSettlePnlTxn } from '../../base/actions/perp/settlePnl';\nimport {\n\tcreateOpenPerpMarketOrder,\n\tOpenPerpMarketOrderParams,\n} from '../../base/actions/trade/openPerpOrder/openPerpMarketOrder';\nimport {\n\tcreateOpenPerpNonMarketOrderTxn,\n\tOpenPerpNonMarketOrderParams,\n} from '../../base/actions/trade/openPerpOrder/openPerpNonMarketOrder';\nimport { createEditOrderTxn } from '../../base/actions/trade/editOrder';\nimport { createCancelOrdersTxn } from '../../base/actions/trade/cancelOrder';\nimport { createSwapTxn } from '../../base/actions/trade/swap';\nimport {\n\tTxnOrSwiftResult,\n\tWithTxnParams,\n} from '../../base/actions/trade/openPerpOrder/types';\n\n/**\n * A Drift client that fetches user data on-demand, while market data is continuously subscribed to.\n *\n * This is useful for an API server that fetches user data on-demand, and return transaction messages specific to a given user\n */\nexport class CentralServerDrift {\n\tprivate driftClient: DriftClient;\n\tprivate _perpMarketConfigs: PerpMarketConfig[];\n\tprivate spotMarketConfigs: SpotMarketConfig[];\n\n\t/**\n\t * @param solanaRpcEndpoint - The Solana RPC endpoint to use for reading RPC data.\n\t * @param driftEnv - The drift environment to use for the drift client.\n\t * @param activeTradeMarket - The active trade market to use for the drift client. This is used to subscribe to the market account, oracle data and mark price more frequently compared to the other markets.\n\t * @param additionalDriftClientConfig - Additional DriftClient config to use for the DriftClient.\n\t */\n\tconstructor(config: {\n\t\tsolanaRpcEndpoint: string;\n\t\tdriftEnv: DriftEnv;\n\t\tadditionalDriftClientConfig?: Partial<Omit<DriftClientConfig, 'env'>>;\n\t\tactiveTradeMarket?: MarketId;\n\t\tmarketsToSubscribe?: MarketId[];\n\t}) {\n\t\tconst driftEnv = config.driftEnv;\n\n\t\tconst connection = new Connection(config.solanaRpcEndpoint);\n\t\tconst driftProgramID = new PublicKey(DRIFT_PROGRAM_ID);\n\t\tconst accountLoader = new CustomizedCadenceBulkAccountLoader(\n\t\t\tconnection,\n\t\t\tDEFAULT_ACCOUNT_LOADER_COMMITMENT,\n\t\t\tDEFAULT_ACCOUNT_LOADER_POLLING_FREQUENCY_MS\n\t\t);\n\n\t\tconst wallet = COMMON_UI_UTILS.createPlaceholderIWallet(); // use random wallet to initialize a central-server instance\n\n\t\tconst driftClientConfig: DriftClientConfig = {\n\t\t\tenv: driftEnv,\n\t\t\tconnection,\n\t\t\twallet,\n\t\t\tprogramID: driftProgramID,\n\t\t\tenableMetricsEvents: false,\n\t\t\taccountSubscription: {\n\t\t\t\ttype: 'polling',\n\t\t\t\taccountLoader,\n\t\t\t},\n\t\t\tuserStats: false,\n\t\t\tincludeDelegates: false,\n\t\t\tskipLoadUsers: true,\n\t\t\tdelistedMarketSetting: DelistedMarketSetting.Unsubscribe,\n\t\t\t...config.additionalDriftClientConfig,\n\t\t};\n\t\tthis.driftClient = new DriftClient(driftClientConfig);\n\n\t\tconst txSender = new WhileValidTxSender({\n\t\t\tconnection,\n\t\t\twallet,\n\t\t\tadditionalConnections: [],\n\t\t\tadditionalTxSenderCallbacks: [],\n\t\t\ttxHandler: this.driftClient.txHandler,\n\t\t\tconfirmationStrategy: DEFAULT_TX_SENDER_CONFIRMATION_STRATEGY,\n\t\t\tretrySleep: DEFAULT_TX_SENDER_RETRY_INTERVAL,\n\t\t});\n\n\t\tthis.driftClient.txSender = txSender;\n\t\tthis._perpMarketConfigs =\n\t\t\tdriftEnv === 'devnet' ? DevnetPerpMarkets : MainnetPerpMarkets;\n\t\tthis.spotMarketConfigs =\n\t\t\tdriftEnv === 'devnet' ? DevnetSpotMarkets : MainnetSpotMarkets;\n\t}\n\n\tpublic async subscribe() {\n\t\tawait this.driftClient.subscribe();\n\t}\n\n\t/**\n\t * Manages DriftClient state for transaction creation with proper setup and cleanup.\n\t * This abstraction handles:\n\t * - User creation and subscription\n\t * - Authority management\n\t * - Wallet replacement for correct transaction signing\n\t * - Cleanup and state restoration\n\t *\n\t * @param userAccountPublicKey - The user account public key\n\t * @param operation - The transaction creation operation to execute\n\t * @returns The result of the operation\n\t */\n\tprivate async driftClientContextWrapper<T>(\n\t\tuserAccountPublicKey: PublicKey,\n\t\toperation: (user: User) => Promise<T>\n\t): Promise<T> {\n\t\tconst user = new User({\n\t\t\tdriftClient: this.driftClient,\n\t\t\tuserAccountPublicKey,\n\t\t});\n\n\t\t// Store original state\n\t\tconst originalWallet = this.driftClient.wallet;\n\t\tconst originalAuthority = this.driftClient.authority;\n\n\t\ttry {\n\t\t\t// Setup: Subscribe to user and configure DriftClient\n\t\t\tawait user.subscribe();\n\n\t\t\tconst authority = user.getUserAccount().authority;\n\t\t\tthis.driftClient.authority = authority;\n\n\t\t\tconst success = await this.driftClient.addUser(\n\t\t\t\tuser.getUserAccount().subAccountId,\n\t\t\t\tauthority\n\t\t\t);\n\n\t\t\tif (!success) {\n\t\t\t\tthrow new Error('Failed to add user to DriftClient');\n\t\t\t}\n\n\t\t\t// Replace wallet with user's authority to ensure correct transaction signing\n\t\t\t// This is necessary because DriftClient adds wallet.publicKey to instructions\n\t\t\tconst userWallet = {\n\t\t\t\tpublicKey: authority,\n\t\t\t\tsignTransaction: () =>\n\t\t\t\t\tPromise.reject(\n\t\t\t\t\t\t'This is a placeholder - do not sign with this wallet'\n\t\t\t\t\t),\n\t\t\t\tsignAllTransactions: () =>\n\t\t\t\t\tPromise.reject(\n\t\t\t\t\t\t'This is a placeholder - do not sign with this wallet'\n\t\t\t\t\t),\n\t\t\t};\n\n\t\t\t// Update wallet in all places that reference it\n\t\t\tthis.driftClient.wallet = userWallet;\n\t\t\t//@ts-ignore\n\t\t\tthis.driftClient.provider.wallet = userWallet;\n\t\t\tthis.driftClient.txHandler.updateWallet(userWallet);\n\n\t\t\t// Execute the operation\n\t\t\tconst result = await operation(user);\n\n\t\t\treturn result;\n\t\t} finally {\n\t\t\t// Cleanup: Always restore original state and unsubscribe\n\t\t\tthis.driftClient.wallet = originalWallet;\n\t\t\tthis.driftClient.txHandler.updateWallet(originalWallet);\n\t\t\tthis.driftClient.authority = originalAuthority;\n\n\t\t\ttry {\n\t\t\t\tawait user.unsubscribe();\n\t\t\t\tthis.driftClient.users.clear();\n\t\t\t} catch (cleanupError) {\n\t\t\t\tconsole.warn('Error during cleanup:', cleanupError);\n\t\t\t\t// Don't throw cleanup errors, but log them\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic async getDepositTxn(\n\t\tuserAccountPublicKey: PublicKey,\n\t\tamount: BN,\n\t\tspotMarketIndex: number\n\t): Promise<VersionedTransaction | Transaction> {\n\t\treturn this.driftClientContextWrapper(\n\t\t\tuserAccountPublicKey,\n\t\t\tasync (user) => {\n\t\t\t\tconst spotMarketConfig = this.spotMarketConfigs.find(\n\t\t\t\t\t(market) => market.marketIndex === spotMarketIndex\n\t\t\t\t);\n\n\t\t\t\tif (!spotMarketConfig) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Spot market config not found for index ${spotMarketIndex}`\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tconst depositTxn = await createDepositTxn({\n\t\t\t\t\tdriftClient: this.driftClient,\n\t\t\t\t\tuser,\n\t\t\t\t\tamount: BigNum.from(amount, spotMarketConfig.precisionExp),\n\t\t\t\t\tspotMarketConfig,\n\t\t\t\t});\n\n\t\t\t\treturn depositTxn;\n\t\t\t}\n\t\t);\n\t}\n\n\tpublic async getWithdrawTxn(\n\t\tuserAccountPublicKey: PublicKey,\n\t\tamount: BN,\n\t\tspotMarketIndex: number,\n\t\toptions?: {\n\t\t\tisBorrow?: boolean;\n\t\t\tisMax?: boolean;\n\t\t}\n\t): Promise<VersionedTransaction | Transaction> {\n\t\treturn this.driftClientContextWrapper(\n\t\t\tuserAccountPublicKey,\n\t\t\tasync (user) => {\n\t\t\t\tconst spotMarketConfig = this.spotMarketConfigs.find(\n\t\t\t\t\t(market) => market.marketIndex === spotMarketIndex\n\t\t\t\t);\n\n\t\t\t\tif (!spotMarketConfig) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Spot market config not found for index ${spotMarketIndex}`\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tconst withdrawTxn = await createWithdrawTxn({\n\t\t\t\t\tdriftClient: this.driftClient,\n\t\t\t\t\tuser,\n\t\t\t\t\tamount: BigNum.from(amount, spotMarketConfig.precisionExp),\n\t\t\t\t\tspotMarketConfig,\n\t\t\t\t\tisBorrow: options?.isBorrow,\n\t\t\t\t\tisMax: options?.isMax,\n\t\t\t\t});\n\n\t\t\t\treturn withdrawTxn;\n\t\t\t}\n\t\t);\n\t}\n\n\tpublic async getSettleFundingTxn(\n\t\tuserAccountPublicKey: PublicKey\n\t): Promise<VersionedTransaction | Transaction> {\n\t\treturn this.driftClientContextWrapper(\n\t\t\tuserAccountPublicKey,\n\t\t\tasync (user) => {\n\t\t\t\tconst settleFundingTxn = await createSettleFundingTxn({\n\t\t\t\t\tdriftClient: this.driftClient,\n\t\t\t\t\tuser,\n\t\t\t\t});\n\n\t\t\t\treturn settleFundingTxn;\n\t\t\t}\n\t\t);\n\t}\n\n\tpublic async getSettlePnlTxn(\n\t\tuserAccountPublicKey: PublicKey,\n\t\tmarketIndexes: number[]\n\t): Promise<VersionedTransaction | Transaction> {\n\t\treturn this.driftClientContextWrapper(\n\t\t\tuserAccountPublicKey,\n\t\t\tasync (user) => {\n\t\t\t\tconst settlePnlTxn = await createSettlePnlTxn({\n\t\t\t\t\tdriftClient: this.driftClient,\n\t\t\t\t\tuser,\n\t\t\t\t\tmarketIndexes,\n\t\t\t\t});\n\n\t\t\t\treturn settlePnlTxn;\n\t\t\t}\n\t\t);\n\t}\n\n\tpublic async getOpenPerpMarketOrderTxn<T extends boolean>({\n\t\tuserAccountPublicKey,\n\t\t...rest\n\t}: WithTxnParams<\n\t\tOmit<OpenPerpMarketOrderParams<T>, 'driftClient' | 'user'>\n\t> & {\n\t\tuserAccountPublicKey: PublicKey;\n\t}): Promise<TxnOrSwiftResult<T>> {\n\t\treturn this.driftClientContextWrapper(\n\t\t\tuserAccountPublicKey,\n\t\t\tasync (user) => {\n\t\t\t\tconst openPerpMarketOrderTxn = await createOpenPerpMarketOrder({\n\t\t\t\t\t...rest,\n\t\t\t\t\tdriftClient: this.driftClient,\n\t\t\t\t\tuser,\n\t\t\t\t});\n\t\t\t\treturn openPerpMarketOrderTxn;\n\t\t\t}\n\t\t);\n\t}\n\n\t/**\n\t * Create a perp non-market order with amount and asset type\n\t */\n\tpublic async getOpenPerpNonMarketOrderTxn({\n\t\tuserAccountPublicKey,\n\t\t...rest\n\t}: WithTxnParams<\n\t\tOmit<OpenPerpNonMarketOrderParams, 'driftClient' | 'user'>\n\t> & {\n\t\tuserAccountPublicKey: PublicKey;\n\t}): Promise<VersionedTransaction | Transaction | void> {\n\t\treturn this.driftClientContextWrapper(\n\t\t\tuserAccountPublicKey,\n\t\t\tasync (user) => {\n\t\t\t\tconst openPerpNonMarketOrderTxn = await createOpenPerpNonMarketOrderTxn(\n\t\t\t\t\t{\n\t\t\t\t\t\t...rest,\n\t\t\t\t\t\tdriftClient: this.driftClient,\n\t\t\t\t\t\tuser,\n\t\t\t\t\t}\n\t\t\t\t);\n\n\t\t\t\treturn openPerpNonMarketOrderTxn;\n\t\t\t}\n\t\t);\n\t}\n\n\t/**\n\t * Create a transaction to edit an existing order\n\t */\n\tpublic async getEditOrderTxn(\n\t\tuserAccountPublicKey: PublicKey,\n\t\torderId: number,\n\t\teditOrderParams: {\n\t\t\tnewDirection?: PositionDirection;\n\t\t\tnewBaseAmount?: BN;\n\t\t\tnewLimitPrice?: BN;\n\t\t\tnewOraclePriceOffset?: number;\n\t\t\tnewTriggerPrice?: BN;\n\t\t\tnewTriggerCondition?: OrderTriggerCondition;\n\t\t\tauctionDuration?: number;\n\t\t\tauctionStartPrice?: BN;\n\t\t\tauctionEndPrice?: BN;\n\t\t\treduceOnly?: boolean;\n\t\t\tpostOnly?: boolean;\n\t\t\tbitFlags?: number;\n\t\t\tmaxTs?: BN;\n\t\t\tpolicy?: number;\n\t\t}\n\t): Promise<VersionedTransaction | Transaction> {\n\t\treturn this.driftClientContextWrapper(\n\t\t\tuserAccountPublicKey,\n\t\t\tasync (user) => {\n\t\t\t\tconst editOrderTxn = await createEditOrderTxn(\n\t\t\t\t\tthis.driftClient,\n\t\t\t\t\tuser,\n\t\t\t\t\torderId,\n\t\t\t\t\teditOrderParams\n\t\t\t\t);\n\n\t\t\t\treturn editOrderTxn;\n\t\t\t}\n\t\t);\n\t}\n\n\t/**\n\t * Create a transaction to cancel specific orders by their IDs\n\t */\n\tpublic async getCancelOrdersTxn(\n\t\tuserAccountPublicKey: PublicKey,\n\t\torderIds: number[]\n\t): Promise<VersionedTransaction | Transaction> {\n\t\treturn this.driftClientContextWrapper(\n\t\t\tuserAccountPublicKey,\n\t\t\tasync (user) => {\n\t\t\t\tconst cancelOrdersTxn = await createCancelOrdersTxn(\n\t\t\t\t\tthis.driftClient,\n\t\t\t\t\tuser,\n\t\t\t\t\torderIds\n\t\t\t\t);\n\n\t\t\t\treturn cancelOrdersTxn;\n\t\t\t}\n\t\t);\n\t}\n\n\t/**\n\t * Create a transaction to cancel all orders for a user\n\t */\n\tpublic async getCancelAllOrdersTxn(\n\t\tuserAccountPublicKey: PublicKey,\n\t\tmarketType?: MarketType,\n\t\tmarketIndex?: number,\n\t\tdirection?: PositionDirection\n\t): Promise<VersionedTransaction | Transaction> {\n\t\treturn this.driftClientContextWrapper(\n\t\t\tuserAccountPublicKey,\n\t\t\tasync (user) => {\n\t\t\t\tconst ix = await this.driftClient.getCancelOrdersIx(\n\t\t\t\t\tmarketType ?? null,\n\t\t\t\t\tmarketIndex ?? null,\n\t\t\t\t\tdirection ?? null,\n\t\t\t\t\tuser.getUserAccount().subAccountId\n\t\t\t\t);\n\n\t\t\t\tconst cancelAllOrdersTxn = await this.driftClient.buildTransaction(ix);\n\n\t\t\t\treturn cancelAllOrdersTxn;\n\t\t\t}\n\t\t);\n\t}\n\n\t/**\n\t * Create a swap transaction between two spot markets using Jupiter\n\t */\n\tpublic async getSwapTxn(\n\t\tuserAccountPublicKey: PublicKey,\n\t\tfromMarketIndex: number,\n\t\ttoMarketIndex: number,\n\t\tamount: BN,\n\t\toptions?: {\n\t\t\tslippageBps?: number;\n\t\t\tswapMode?: SwapMode;\n\t\t\tonlyDirectRoutes?: boolean;\n\t\t\tquote?: QuoteResponse;\n\t\t}\n\t): Promise<VersionedTransaction | Transaction> {\n\t\treturn this.driftClientContextWrapper(\n\t\t\tuserAccountPublicKey,\n\t\t\tasync (user) => {\n\t\t\t\tconst fromSpotMarketConfig = this.spotMarketConfigs.find(\n\t\t\t\t\t(market) => market.marketIndex === fromMarketIndex\n\t\t\t\t);\n\t\t\t\tconst toSpotMarketConfig = this.spotMarketConfigs.find(\n\t\t\t\t\t(market) => market.marketIndex === toMarketIndex\n\t\t\t\t);\n\n\t\t\t\tif (!fromSpotMarketConfig) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`From spot market config not found for index ${fromMarketIndex}`\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tif (!toSpotMarketConfig) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`To spot market config not found for index ${toMarketIndex}`\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\t// Initialize Jupiter client\n\t\t\t\tconst jupiterClient = new JupiterClient({\n\t\t\t\t\tconnection: this.driftClient.connection,\n\t\t\t\t});\n\n\t\t\t\t// Get quote if not provided\n\t\t\t\tlet quote = options?.quote;\n\t\t\t\tif (!quote) {\n\t\t\t\t\tquote = await jupiterClient.getQuote({\n\t\t\t\t\t\tinputMint: fromSpotMarketConfig.mint,\n\t\t\t\t\t\toutputMint: toSpotMarketConfig.mint,\n\t\t\t\t\t\tamount,\n\t\t\t\t\t\tslippageBps: options?.slippageBps ?? 10, // Default 0.1%\n\t\t\t\t\t\tswapMode: options?.swapMode ?? 'ExactIn',\n\t\t\t\t\t\tonlyDirectRoutes: options?.onlyDirectRoutes ?? false,\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tconst swapTxn = await createSwapTxn({\n\t\t\t\t\tdriftClient: this.driftClient,\n\t\t\t\t\tjupiterClient,\n\t\t\t\t\tuser,\n\t\t\t\t\tswapFromMarketIndex: fromMarketIndex,\n\t\t\t\t\tswapToMarketIndex: toMarketIndex,\n\t\t\t\t\tamount,\n\t\t\t\t\tquote,\n\t\t\t\t\ttxParams: {\n\t\t\t\t\t\tuseSimulatedComputeUnits: true,\n\t\t\t\t\t\tcomputeUnitsBufferMultiplier: 1.5,\n\t\t\t\t\t},\n\t\t\t\t});\n\n\t\t\t\treturn swapTxn;\n\t\t\t}\n\t\t);\n\t}\n\n\tpublic async sendSignedTransaction(tx: VersionedTransaction | Transaction) {\n\t\treturn this.driftClient.sendTransaction(tx, undefined, undefined, true);\n\t}\n}\n"]}
|
|
@@ -1,6 +1,14 @@
|
|
|
1
|
+
import { OptionalOrderParams } from '@drift-labs/sdk';
|
|
1
2
|
/**
|
|
2
|
-
* Error thrown when a method is called while the user is
|
|
3
|
+
* Error thrown when a method is called while the user is geo-blocked.
|
|
3
4
|
*/
|
|
4
5
|
export declare class GeoBlockError extends Error {
|
|
5
6
|
constructor(methodName: string);
|
|
6
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* Error thrown when no top makers are found. The order params provided can still be used as a fallback.
|
|
10
|
+
*/
|
|
11
|
+
export declare class NoTopMakersError extends Error {
|
|
12
|
+
orderParams: OptionalOrderParams;
|
|
13
|
+
constructor(message: string, orderParams: OptionalOrderParams);
|
|
14
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GeoBlockError = void 0;
|
|
3
|
+
exports.NoTopMakersError = exports.GeoBlockError = void 0;
|
|
4
4
|
/**
|
|
5
|
-
* Error thrown when a method is called while the user is
|
|
5
|
+
* Error thrown when a method is called while the user is geo-blocked.
|
|
6
6
|
*/
|
|
7
7
|
class GeoBlockError extends Error {
|
|
8
8
|
constructor(methodName) {
|
|
@@ -11,4 +11,15 @@ class GeoBlockError extends Error {
|
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
exports.GeoBlockError = GeoBlockError;
|
|
14
|
+
/**
|
|
15
|
+
* Error thrown when no top makers are found. The order params provided can still be used as a fallback.
|
|
16
|
+
*/
|
|
17
|
+
class NoTopMakersError extends Error {
|
|
18
|
+
constructor(message, orderParams) {
|
|
19
|
+
super(message);
|
|
20
|
+
this.name = 'NoTopMakersError';
|
|
21
|
+
this.orderParams = orderParams;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.NoTopMakersError = NoTopMakersError;
|
|
14
25
|
//# sourceMappingURL=errors.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../../src/drift/Drift/constants/errors.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../../src/drift/Drift/constants/errors.ts"],"names":[],"mappings":";;;AAEA;;GAEG;AACH,MAAa,aAAc,SAAQ,KAAK;IACvC,YAAY,UAAkB;QAC7B,KAAK,CACJ,WAAW,UAAU,sDAAsD,CAC3E,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;IAC7B,CAAC;CACD;AAPD,sCAOC;AAED;;GAEG;AACH,MAAa,gBAAiB,SAAQ,KAAK;IAE1C,YAAY,OAAe,EAAE,WAAgC;QAC5D,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;QAC/B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IAChC,CAAC;CACD;AAPD,4CAOC","sourcesContent":["import { OptionalOrderParams } from '@drift-labs/sdk';\n\n/**\n * Error thrown when a method is called while the user is geo-blocked.\n */\nexport class GeoBlockError extends Error {\n\tconstructor(methodName: string) {\n\t\tsuper(\n\t\t\t`Method '${methodName}' is not available due to geographical restrictions.`\n\t\t);\n\t\tthis.name = 'GeoBlockError';\n\t}\n}\n\n/**\n * Error thrown when no top makers are found. The order params provided can still be used as a fallback.\n */\nexport class NoTopMakersError extends Error {\n\torderParams: OptionalOrderParams;\n\tconstructor(message: string, orderParams: OptionalOrderParams) {\n\t\tsuper(message);\n\t\tthis.name = 'NoTopMakersError';\n\t\tthis.orderParams = orderParams;\n\t}\n}\n"]}
|
|
@@ -21,23 +21,6 @@ export interface MarketPollingData {
|
|
|
21
21
|
marketId: MarketId;
|
|
22
22
|
data: L2WithOracleAndMarketData;
|
|
23
23
|
}
|
|
24
|
-
export interface BulkL2FetchingQueryParams {
|
|
25
|
-
marketIndex: number;
|
|
26
|
-
marketType: string;
|
|
27
|
-
depth: number;
|
|
28
|
-
includeVamm: boolean;
|
|
29
|
-
includePhoenix: boolean;
|
|
30
|
-
includeOpenbook: boolean;
|
|
31
|
-
includeSerum: boolean;
|
|
32
|
-
includeOracle: boolean;
|
|
33
|
-
includeIndicative: boolean;
|
|
34
|
-
}
|
|
35
|
-
export interface BulkL2FetchingParams {
|
|
36
|
-
markets: (BulkL2FetchingQueryParams & {
|
|
37
|
-
intervalMultiplier: number;
|
|
38
|
-
})[];
|
|
39
|
-
grouping?: number;
|
|
40
|
-
}
|
|
41
24
|
export declare const POLLING_INTERVALS: {
|
|
42
25
|
readonly LIVE_MARKET: 1;
|
|
43
26
|
readonly BACKGROUND_DEEP: 3;
|
|
@@ -148,7 +131,4 @@ export declare class PollingDlob {
|
|
|
148
131
|
*/
|
|
149
132
|
static createWithCommonIntervals(config: PollingConfig): PollingDlob;
|
|
150
133
|
private tick;
|
|
151
|
-
private fetchBulkMarketL2Data;
|
|
152
|
-
private bulkDlobL2Fetcher;
|
|
153
|
-
private encodeQueryParams;
|
|
154
134
|
}
|