@drift-labs/common 1.0.46 → 1.0.48

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.
Files changed (31) hide show
  1. package/lib/drift/Drift/clients/AuthorityDrift/DriftOperations/index.js +8 -4
  2. package/lib/drift/Drift/clients/AuthorityDrift/DriftOperations/index.js.map +1 -1
  3. package/lib/drift/Drift/clients/AuthorityDrift/DriftOperations/types.d.ts +4 -2
  4. package/lib/drift/Drift/clients/AuthorityDrift/DriftOperations/types.js.map +1 -1
  5. package/lib/drift/Drift/clients/CentralServerDrift/index.d.ts +5 -3
  6. package/lib/drift/Drift/clients/CentralServerDrift/index.js +40 -46
  7. package/lib/drift/Drift/clients/CentralServerDrift/index.js.map +1 -1
  8. package/lib/drift/Drift/clients/CentralServerDrift/types.d.ts +27 -10
  9. package/lib/drift/Drift/clients/CentralServerDrift/types.js.map +1 -1
  10. package/lib/drift/base/actions/trade/openPerpOrder/isolatedPositionDeposit.d.ts +56 -1
  11. package/lib/drift/base/actions/trade/openPerpOrder/isolatedPositionDeposit.js +102 -4
  12. package/lib/drift/base/actions/trade/openPerpOrder/isolatedPositionDeposit.js.map +1 -1
  13. package/lib/drift/base/actions/trade/openPerpOrder/openPerpMarketOrder/index.d.ts +26 -14
  14. package/lib/drift/base/actions/trade/openPerpOrder/openPerpMarketOrder/index.js +88 -18
  15. package/lib/drift/base/actions/trade/openPerpOrder/openPerpMarketOrder/index.js.map +1 -1
  16. package/lib/drift/base/actions/trade/openPerpOrder/openPerpNonMarketOrder/index.d.ts +26 -8
  17. package/lib/drift/base/actions/trade/openPerpOrder/openPerpNonMarketOrder/index.js +90 -21
  18. package/lib/drift/base/actions/trade/openPerpOrder/openPerpNonMarketOrder/index.js.map +1 -1
  19. package/lib/drift/base/actions/trade/openPerpOrder/openSwiftOrder/index.d.ts +55 -0
  20. package/lib/drift/base/actions/trade/openPerpOrder/openSwiftOrder/index.js +60 -25
  21. package/lib/drift/base/actions/trade/openPerpOrder/openSwiftOrder/index.js.map +1 -1
  22. package/lib/drift/base/actions/trade/openPerpOrder/types.d.ts +10 -6
  23. package/lib/drift/base/actions/trade/openPerpOrder/types.js.map +1 -1
  24. package/lib/drift/base/details/user/positionMarginMode.d.ts +8 -0
  25. package/lib/drift/base/details/user/positionMarginMode.js +18 -0
  26. package/lib/drift/base/details/user/positionMarginMode.js.map +1 -0
  27. package/lib/drift/cli.js +65 -56
  28. package/lib/drift/cli.js.map +1 -1
  29. package/lib/drift/utils/orderParams.d.ts +1 -1
  30. package/lib/drift/utils/orderParams.js.map +1 -1
  31. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/drift/Drift/clients/CentralServerDrift/index.ts"],"names":[],"mappings":";;;AAAA,yCAkCyB;AACzB,6CAKyB;AACzB,6EAA4E;AAC5E,+CAMyB;AACzB,gEAAsE;AACtE,kEAAwE;AACxE,mDAA+E;AAC/E,4EAAkF;AAClF,oEAG8C;AAC9C,uGAGuE;AACvE,6GAG0E;AAC1E,qEAA2E;AAC3E,yEAAgF;AAChF,2DAAiE;AACjE,8DAA0F;AAC1F,8DAAkE;AAClE,qGAAqG;AACrG,uGAAuG;AACvG,qFAAqF;AAGrF,2EAAwE;AASxE,uCAAsD;AACtD,uEAAoE;AASpE;;;;GAIG;AACH,MAAa,kBAAkB;IAmB9B;;;;;OAKG;IACH,YAAY,MAOX;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,UAAU,EACV,6CAAiC,EACjC,uDAA2C,CAC3C,CAAC;QAEF,MAAM,MAAM,GAAG,+BAAe,CAAC,wBAAwB,EAAE,CAAC,C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CAAC,SAAS,EAAE,GAAG,EAAE;;YACnD,OAAA,IAAA,wDAA4B,EAAC;gBAC5B,WAAW,EAAE,IAAI,CAAC,YAAY;gBAC9B,SAAS;gBACT,QAAQ,EAAE,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,QAAQ,mCAAI,IAAI,CAAC,WAAW,EAAE;aACjD,CAAC,CAAA;SAAA,CACF,CAAC;IACH,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,8BAA8B,CAC1C,SAAoB,EACpB,gBAA2B,EAC3B,cAAsB,EACtB,OAEC;QAED,OAAO,IAAI,CAAC,uBAAuB,CAAC,SAAS,EAAE,GAAG,EAAE;;YACnD,OAAA,IAAA,sCAAmB,EAAC;gBACnB,WAAW,EAAE,IAAI,CAAC,YAAY;gBAC9B,SAAS;gBACT,gBAAgB;gBAChB,cAAc;gBACd,QAAQ,EAAE,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,QAAQ,mCAAI,IAAI,CAAC,WAAW,EAAE;aACjD,CAAC,CAAA;SAAA,CACF,CAAC;IACH,CAAC;IAEM,KAAK,CAAC,qBAAqB,CAAC,EAAsC;QACxE,OAAO,IAAI,CAAC,YAAY,CAAC,eAAe,CAAC,EAAE,EAAE,SAAS,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;IAC1E,CAAC;CACD;AA1mCD,gDA0mCC","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\tfetchUserStatsAccount,\n\tgetMarketsAndOraclesForSubscription,\n\tMainnetPerpMarkets,\n\tMainnetSpotMarkets,\n\tMarketType,\n\tMIN_I64,\n\tOneShotUserAccountSubscriber,\n\tOrderTriggerCondition,\n\tPerpMarketConfig,\n\tPositionDirection,\n\tPriorityFeeMethod,\n\tPriorityFeeSubscriber,\n\tPriorityFeeSubscriberConfig,\n\tPublicKey,\n\tSettlePnlMode,\n\tSpotMarketConfig,\n\tSwapMode,\n\tTxParams,\n\tUnifiedQuoteResponse,\n\tUnifiedSwapClient,\n\tUser,\n\tWhileValidTxSender,\n\tZERO,\n} from '@drift-labs/sdk';\nimport {\n\tConnection,\n\tTransaction,\n\tTransactionInstruction,\n\tVersionedTransaction,\n} 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\tHIGH_ACTIVITY_MARKET_ACCOUNTS,\n} from '../../constants';\nimport { createDepositTxn } from '../../../base/actions/spot/deposit';\nimport { createWithdrawTxn } from '../../../base/actions/spot/withdraw';\nimport { getTokenAddressForDepositAndWithdraw } from '../../../../utils/token';\nimport { createSettleFundingTxn } from '../../../base/actions/perp/settleFunding';\nimport {\n\tcreateSettlePnlIx,\n\tcreateSettlePnlTxn,\n} from '../../../base/actions/perp/settlePnl';\nimport {\n\tcreateOpenPerpMarketOrder,\n\tcreateOpenPerpMarketOrderIxs,\n} from '../../../base/actions/trade/openPerpOrder/openPerpMarketOrder';\nimport {\n\tcreateOpenPerpNonMarketOrder,\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 { createUserAndDepositCollateralBaseTxn } from '../../../base/actions/user/create';\nimport { deleteUserTxn } from '../../../base/actions/user/delete';\nimport { createRevenueShareEscrowTxn } from '../../../base/actions/builder/createRevenueShareEscrow';\nimport { createRevenueShareAccountTxn } from '../../../base/actions/builder/createRevenueShareAccount';\nimport { configureBuilderTxn } from '../../../base/actions/builder/configureBuilder';\nimport { TxnOrSwiftResult } from '../../../base/actions/trade/openPerpOrder/types';\nimport { WithTxnParams } from '../../../base/types';\nimport { EnvironmentConstants } from '../../../../EnvironmentConstants';\nimport {\n\tCentralServerGetOpenPerpMarketOrderTxnParams,\n\tCentralServerGetOpenPerpNonMarketOrderTxnParams,\n\tCentralServerGetWithdrawIsolatedPerpPositionCollateralTxnParams,\n\tCentralServerGetCloseAndWithdrawIsolatedPerpPositionTxnParams,\n\tCentralServerGetDepositAndOpenIsolatedPerpPositionTxnParams,\n\tCentralServerGetCloseAndWithdrawIsolatedPerpPositionToWalletTxnParams,\n} from './types';\nimport { CentralServerDriftMarkets } from './markets';\nimport { DriftOperations } from '../AuthorityDrift/DriftOperations';\n\nexport type {\n\tCentralServerGetWithdrawIsolatedPerpPositionCollateralTxnParams,\n\tCentralServerGetCloseAndWithdrawIsolatedPerpPositionTxnParams,\n\tCentralServerGetDepositAndOpenIsolatedPerpPositionTxnParams,\n\tCentralServerGetCloseAndWithdrawIsolatedPerpPositionToWalletTxnParams,\n} from './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\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};\n\n\t/**\n\t * Handles priority fee tracking and calculation for optimized transaction costs.\n\t */\n\tprivate priorityFeeSubscriber!: PriorityFeeSubscriber;\n\n\tpublic readonly markets: CentralServerDriftMarkets;\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 supportedPerpMarkets - The perp markets indexes to support. See https://github.com/drift-labs/protocol-v2/blob/master/sdk/src/constants/perpMarkets.ts for all available markets. It is recommended to only include markets that will be used.\n\t * @param supportedSpotMarkets - The spot markets indexes to support. See https://github.com/drift-labs/protocol-v2/blob/master/sdk/src/constants/spotMarkets.ts for all available markets. It is recommended to only include markets that will be used.\n\t */\n\tconstructor(config: {\n\t\tsolanaRpcEndpoint: string;\n\t\tdriftEnv: DriftEnv;\n\t\tsupportedPerpMarkets: number[];\n\t\tsupportedSpotMarkets: number[];\n\t\tadditionalDriftClientConfig?: Partial<Omit<DriftClientConfig, 'env'>>;\n\t\tpriorityFeeSubscriberConfig?: Partial<PriorityFeeSubscriberConfig>;\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 allPerpMarketConfigs =\n\t\t\tdriftEnv === 'devnet' ? DevnetPerpMarkets : MainnetPerpMarkets;\n\t\tconst allSpotMarketConfigs =\n\t\t\tdriftEnv === 'devnet' ? DevnetSpotMarkets : MainnetSpotMarkets;\n\t\tthis._perpMarketConfigs = config.supportedPerpMarkets.map((marketIndex) =>\n\t\t\tallPerpMarketConfigs.find((market) => market.marketIndex === marketIndex)\n\t\t);\n\t\tthis._spotMarketConfigs = config.supportedSpotMarkets.map((marketIndex) =>\n\t\t\tallSpotMarketConfigs.find((market) => market.marketIndex === marketIndex)\n\t\t);\n\n\t\tconst oracleInfos = getMarketsAndOraclesForSubscription(\n\t\t\tdriftEnv,\n\t\t\tthis._perpMarketConfigs,\n\t\t\tthis._spotMarketConfigs\n\t\t);\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\tperpMarketIndexes: this._perpMarketConfigs.map(\n\t\t\t\t(market) => market.marketIndex\n\t\t\t),\n\t\t\tspotMarketIndexes: this._spotMarketConfigs.map(\n\t\t\t\t(market) => market.marketIndex\n\t\t\t),\n\t\t\toracleInfos: oracleInfos.oracleInfos,\n\t\t\t...config.additionalDriftClientConfig,\n\t\t};\n\t\tthis._driftClient = new DriftClient(driftClientConfig);\n\t\tthis.markets = new CentralServerDriftMarkets(this._driftClient);\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\t// set up Drift endpoints\n\t\tconst driftDlobServerHttpUrlToUse =\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\tthis._driftEndpoints = {\n\t\t\tdlobServerHttpUrl: driftDlobServerHttpUrlToUse,\n\t\t\tswiftServerUrl: swiftServerUrlToUse,\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\taddresses: HIGH_ACTIVITY_MARKET_ACCOUNTS,\n\t\t\t...config.priorityFeeSubscriberConfig,\n\t\t};\n\n\t\tthis.priorityFeeSubscriber = new PriorityFeeSubscriber(priorityFeeConfig);\n\t}\n\n\tpublic get driftClient() {\n\t\treturn this._driftClient;\n\t}\n\n\tpublic async subscribe() {\n\t\tawait this._driftClient.subscribe();\n\t\tawait this.priorityFeeSubscriber.subscribe();\n\t}\n\n\tpublic async unsubscribe() {\n\t\tawait this._driftClient.unsubscribe();\n\t\tawait this.priorityFeeSubscriber.unsubscribe();\n\t}\n\n\t/**\n\t * Temporarily swaps the DriftClient wallet/authority context to build transactions\n\t * for a given authority, then restores the original state.\n\t *\n\t * Use this for authority-based operations that don't require a User account subscription\n\t * (e.g. creating revenue share accounts, managing builders).\n\t *\n\t * @param authority - The authority to set on the DriftClient\n\t * @param operation - The transaction creation operation to execute\n\t * @returns The result of the operation\n\t */\n\tprivate async authorityContextWrapper<T>(\n\t\tauthority: PublicKey,\n\t\toperation: () => Promise<T>\n\t): Promise<T> {\n\t\tconst originalWallet = this._driftClient.wallet;\n\t\tconst originalAuthority = this._driftClient.authority;\n\n\t\tconst authorityWallet = {\n\t\t\tpublicKey: authority,\n\t\t\tsignTransaction: () =>\n\t\t\t\tPromise.reject('This is a placeholder - do not sign with this wallet'),\n\t\t\tsignAllTransactions: () =>\n\t\t\t\tPromise.reject('This is a placeholder - do not sign with this wallet'),\n\t\t};\n\n\t\ttry {\n\t\t\tthis._driftClient.wallet = authorityWallet;\n\t\t\t// @ts-ignore\n\t\t\tthis._driftClient.provider.wallet = authorityWallet;\n\t\t\tthis._driftClient.txHandler.updateWallet(authorityWallet);\n\t\t\tthis._driftClient.authority = authority;\n\n\t\t\treturn await operation();\n\t\t} finally {\n\t\t\tthis._driftClient.wallet = originalWallet;\n\t\t\tthis._driftClient.txHandler.updateWallet(originalWallet);\n\t\t\t// @ts-ignore\n\t\t\tthis._driftClient.provider.wallet = originalWallet;\n\t\t\tthis._driftClient.authority = originalAuthority;\n\t\t}\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\texternalWallet?: PublicKey\n\t): Promise<T> {\n\t\tconst user = new User({\n\t\t\tdriftClient: this._driftClient,\n\t\t\tuserAccountPublicKey,\n\t\t\taccountSubscription: {\n\t\t\t\ttype: 'custom',\n\t\t\t\tuserAccountSubscriber: new OneShotUserAccountSubscriber(\n\t\t\t\t\tthis._driftClient.program,\n\t\t\t\t\tuserAccountPublicKey,\n\t\t\t\t\tundefined,\n\t\t\t\t\tundefined\n\t\t\t\t),\n\t\t\t},\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: externalWallet ?? 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\t/**\n\t * Returns a User object for a given user account public key. This fetches the user account data once.\n\t *\n\t * You may read more about the User object [here](https://github.com/drift-labs/protocol-v2/blob/master/sdk/src/user.ts)\n\t *\n\t * @param userAccountPublicKey - The user account public key\n\t */\n\tpublic async getUser(userAccountPublicKey: PublicKey): Promise<User> {\n\t\tconst oneShotUserAccountSubscriber = new OneShotUserAccountSubscriber(\n\t\t\tthis._driftClient.program,\n\t\t\tuserAccountPublicKey,\n\t\t\tundefined,\n\t\t\tundefined\n\t\t);\n\t\tconst user = new User({\n\t\t\tdriftClient: this._driftClient,\n\t\t\tuserAccountPublicKey,\n\t\t\taccountSubscription: {\n\t\t\t\ttype: 'custom',\n\t\t\t\tuserAccountSubscriber: oneShotUserAccountSubscriber,\n\t\t\t},\n\t\t});\n\t\tawait user.subscribe();\n\t\treturn user;\n\t}\n\n\t/**\n\t * Gets transaction parameters with dynamic priority fees.\n\t * Falls back to default if priority fee function is not available.\n\t */\n\tgetTxParams(overrides?: Partial<TxParams>): TxParams {\n\t\tconst unsafePriorityFee = Math.floor(\n\t\t\tthis.priorityFeeSubscriber.getCustomStrategyResult() ??\n\t\t\t\tDriftOperations.DEFAULT_TX_PARAMS.computeUnitsPrice\n\t\t);\n\n\t\tconst safePriorityFee = Math.min(\n\t\t\tunsafePriorityFee,\n\t\t\tDriftOperations.MAX_COMPUTE_UNITS_PRICE\n\t\t);\n\n\t\treturn {\n\t\t\t...DriftOperations.DEFAULT_TX_PARAMS,\n\t\t\tcomputeUnitsPrice: safePriorityFee,\n\t\t\t...overrides,\n\t\t};\n\t}\n\n\tpublic async getCreateAndDepositTxn(\n\t\tauthority: PublicKey,\n\t\tamount: BN,\n\t\tspotMarketIndex: number,\n\t\toptions?: {\n\t\t\treferrerName?: string;\n\t\t\taccountName?: string;\n\t\t\tpoolId?: number;\n\t\t\tfromSubAccountId?: number;\n\t\t\tcustomMaxMarginRatio?: number;\n\t\t\ttxParams?: TxParams;\n\t\t\t/**\n\t\t\t * Optional external wallet to deposit from. If provided, the deposit will be made\n\t\t\t * from this wallet instead of the authority wallet.\n\t\t\t */\n\t\t\texternalWallet?: PublicKey;\n\t\t}\n\t): Promise<{\n\t\ttransaction: VersionedTransaction | Transaction;\n\t\tuserAccountPublicKey: PublicKey;\n\t\tsubAccountId: number;\n\t}> {\n\t\tconst spotMarketConfig = this._spotMarketConfigs.find(\n\t\t\t(market) => market.marketIndex === spotMarketIndex\n\t\t);\n\n\t\tif (!spotMarketConfig) {\n\t\t\tthrow new Error(\n\t\t\t\t`Spot market config not found for index ${spotMarketIndex}`\n\t\t\t);\n\t\t}\n\n\t\tconst userStatsAccount = await fetchUserStatsAccount(\n\t\t\tthis._driftClient.connection,\n\t\t\tthis._driftClient.program,\n\t\t\tauthority\n\t\t);\n\n\t\treturn this.authorityContextWrapper(\n\t\t\toptions?.externalWallet ?? authority,\n\t\t\tasync () => {\n\t\t\t\tthis._driftClient.authority = authority;\n\t\t\t\t// Clear userStatsAccountPublicKey cache so it's recalculated for the new authority\n\t\t\t\t// @ts-ignore - accessing private property for cache invalidation\n\t\t\t\tthis._driftClient.userStatsAccountPublicKey = undefined;\n\n\t\t\t\treturn await createUserAndDepositCollateralBaseTxn({\n\t\t\t\t\tdriftClient: this._driftClient,\n\t\t\t\t\tamount,\n\t\t\t\t\tspotMarketConfig,\n\t\t\t\t\tauthority,\n\t\t\t\t\tuserStatsAccount,\n\t\t\t\t\treferrerName: options?.referrerName,\n\t\t\t\t\taccountName: options?.accountName,\n\t\t\t\t\tpoolId: options?.poolId,\n\t\t\t\t\tfromSubAccountId: options?.fromSubAccountId,\n\t\t\t\t\tcustomMaxMarginRatio: options?.customMaxMarginRatio,\n\t\t\t\t\ttxParams: options?.txParams ?? this.getTxParams(),\n\t\t\t\t\texternalWallet: options?.externalWallet,\n\t\t\t\t});\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\toptions?: {\n\t\t\ttxParams?: TxParams;\n\t\t\t/**\n\t\t\t * Optional external wallet to deposit from. If provided, the deposit will be made\n\t\t\t * from this wallet instead of the user's authority wallet.\n\t\t\t */\n\t\t\texternalWallet?: PublicKey;\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 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\ttxParams: options?.txParams ?? this.getTxParams(),\n\t\t\t\t\texternalWallet: options?.externalWallet,\n\t\t\t\t});\n\n\t\t\t\treturn depositTxn;\n\t\t\t},\n\t\t\toptions?.externalWallet\n\t\t);\n\t}\n\n\tpublic async getDeleteUserTxn(\n\t\tuserAccountPublicKey: PublicKey,\n\t\toptions?: {\n\t\t\ttxParams?: TxParams;\n\t\t}\n\t): Promise<VersionedTransaction | Transaction> {\n\t\treturn this.driftClientContextWrapper(userAccountPublicKey, async () => {\n\t\t\treturn deleteUserTxn({\n\t\t\t\tdriftClient: this._driftClient,\n\t\t\t\tuserPublicKey: userAccountPublicKey,\n\t\t\t\ttxParams: options?.txParams ?? this.getTxParams(),\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\ttxParams?: TxParams;\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\ttxParams: options?.txParams ?? this.getTxParams(),\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\toptions?: {\n\t\t\ttxParams?: TxParams;\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 settleFundingTxn = await createSettleFundingTxn({\n\t\t\t\t\tdriftClient: this._driftClient,\n\t\t\t\t\tuser,\n\t\t\t\t\ttxParams: options?.txParams ?? this.getTxParams(),\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\toptions?: {\n\t\t\ttxParams?: TxParams;\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 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\ttxParams: options?.txParams ?? this.getTxParams(),\n\t\t\t\t});\n\n\t\t\t\treturn settlePnlTxn;\n\t\t\t}\n\t\t);\n\t}\n\n\t// overloads for better type inference\n\tpublic async getOpenPerpMarketOrderTxn(\n\t\tparams: CentralServerGetOpenPerpMarketOrderTxnParams<true>\n\t): Promise<void>;\n\tpublic async getOpenPerpMarketOrderTxn(\n\t\tparams: CentralServerGetOpenPerpMarketOrderTxnParams<false>\n\t): Promise<Transaction | VersionedTransaction>;\n\tpublic async getOpenPerpMarketOrderTxn<T extends boolean>({\n\t\tuserAccountPublicKey,\n\t\t...rest\n\t}: CentralServerGetOpenPerpMarketOrderTxnParams<T>): Promise<\n\t\tTxnOrSwiftResult<T>\n\t> {\n\t\tconst { mainSignerOverride, ...restWithoutSigner } = rest;\n\t\treturn this.driftClientContextWrapper(\n\t\t\tuserAccountPublicKey,\n\t\t\tasync (user): Promise<TxnOrSwiftResult<T>> => {\n\t\t\t\tconst {\n\t\t\t\t\tuseSwift,\n\t\t\t\t\tswiftOptions,\n\t\t\t\t\tplaceAndTake,\n\t\t\t\t\ttxParams,\n\t\t\t\t\t...otherProps\n\t\t\t\t} = restWithoutSigner;\n\n\t\t\t\tif (useSwift) {\n\t\t\t\t\tconst swiftOrderResult = await createOpenPerpMarketOrder({\n\t\t\t\t\t\tuseSwift: true,\n\t\t\t\t\t\tswiftOptions: {\n\t\t\t\t\t\t\t...swiftOptions,\n\t\t\t\t\t\t\tswiftServerUrl: this._driftEndpoints.swiftServerUrl,\n\t\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\tdlobServerHttpUrl: this._driftEndpoints.dlobServerHttpUrl,\n\t\t\t\t\t\ttxParams: txParams ?? this.getTxParams(),\n\t\t\t\t\t\tmainSignerOverride,\n\t\t\t\t\t\t...otherProps,\n\t\t\t\t\t});\n\t\t\t\t\treturn swiftOrderResult as TxnOrSwiftResult<T>;\n\t\t\t\t} else {\n\t\t\t\t\tconst openPerpMarketOrderTxn = await createOpenPerpMarketOrder({\n\t\t\t\t\t\tplaceAndTake,\n\t\t\t\t\t\tuseSwift: false,\n\t\t\t\t\t\tdriftClient: this._driftClient,\n\t\t\t\t\t\tuser,\n\t\t\t\t\t\tdlobServerHttpUrl: this._driftEndpoints.dlobServerHttpUrl,\n\t\t\t\t\t\ttxParams: txParams ?? this.getTxParams(),\n\t\t\t\t\t\tmainSignerOverride,\n\t\t\t\t\t\t...otherProps,\n\t\t\t\t\t});\n\t\t\t\t\treturn openPerpMarketOrderTxn as TxnOrSwiftResult<T>;\n\t\t\t\t}\n\t\t\t},\n\t\t\tmainSignerOverride\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\tparams: CentralServerGetOpenPerpNonMarketOrderTxnParams<true>\n\t): Promise<void>;\n\tpublic async getOpenPerpNonMarketOrderTxn(\n\t\tparams: CentralServerGetOpenPerpNonMarketOrderTxnParams<false>\n\t): Promise<Transaction | VersionedTransaction>;\n\tpublic async getOpenPerpNonMarketOrderTxn<T extends boolean>({\n\t\tuserAccountPublicKey,\n\t\t...rest\n\t}: WithTxnParams<\n\t\tOmit<OpenPerpNonMarketOrderParams<T>, 'driftClient' | 'user'>\n\t> & {\n\t\tuserAccountPublicKey: PublicKey;\n\t}): Promise<TxnOrSwiftResult<T>> {\n\t\tconst { mainSignerOverride, ...restWithoutSigner } = rest;\n\t\treturn this.driftClientContextWrapper(\n\t\t\tuserAccountPublicKey,\n\t\t\tasync (user) => {\n\t\t\t\tconst { useSwift, swiftOptions, txParams, ...otherProps } =\n\t\t\t\t\trestWithoutSigner;\n\n\t\t\t\tif (useSwift) {\n\t\t\t\t\tconst swiftOrderResult = await createOpenPerpNonMarketOrder({\n\t\t\t\t\t\tuseSwift: true,\n\t\t\t\t\t\tswiftOptions: {\n\t\t\t\t\t\t\t...swiftOptions,\n\t\t\t\t\t\t\tswiftServerUrl: this._driftEndpoints.swiftServerUrl,\n\t\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\tdlobServerHttpUrl: this._driftEndpoints.dlobServerHttpUrl,\n\t\t\t\t\t\ttxParams: txParams ?? this.getTxParams(),\n\t\t\t\t\t\tmainSignerOverride,\n\t\t\t\t\t\t...otherProps,\n\t\t\t\t\t});\n\t\t\t\t\treturn swiftOrderResult as TxnOrSwiftResult<T>;\n\t\t\t\t} else {\n\t\t\t\t\tconst openPerpNonMarketOrderTxn = await createOpenPerpNonMarketOrder({\n\t\t\t\t\t\tuseSwift: false,\n\t\t\t\t\t\tdriftClient: this._driftClient,\n\t\t\t\t\t\tuser,\n\t\t\t\t\t\tdlobServerHttpUrl: this._driftEndpoints.dlobServerHttpUrl,\n\t\t\t\t\t\ttxParams: txParams ?? this.getTxParams(),\n\t\t\t\t\t\tmainSignerOverride,\n\t\t\t\t\t\t...otherProps,\n\t\t\t\t\t});\n\t\t\t\t\treturn openPerpNonMarketOrderTxn as TxnOrSwiftResult<T>;\n\t\t\t\t}\n\t\t\t},\n\t\t\tmainSignerOverride\n\t\t);\n\t}\n\n\t/**\n\t * Create a transaction to withdraw collateral from an isolated perp position back to cross. Often to be called after fully closing position\n\t */\n\tpublic async getWithdrawIsolatedPerpPositionCollateralTxn(\n\t\tparams: CentralServerGetWithdrawIsolatedPerpPositionCollateralTxnParams\n\t): Promise<VersionedTransaction | Transaction> {\n\t\tconst perpMarketConfig = this._perpMarketConfigs.find(\n\t\t\t(m) => m.marketIndex === params.marketIndex\n\t\t);\n\t\tif (!perpMarketConfig) {\n\t\t\tthrow new Error(\n\t\t\t\t`Perp market config not found for index ${params.marketIndex}`\n\t\t\t);\n\t\t}\n\t\treturn this.driftClientContextWrapper(\n\t\t\tparams.userAccountPublicKey,\n\t\t\tasync (user) => {\n\t\t\t\tconst signingAuthority = params.mainSignerOverride;\n\t\t\t\tconst ixs: import('@solana/web3.js').TransactionInstruction[] = [];\n\t\t\t\tconst shouldSettlePnl =\n\t\t\t\t\tparams.settlePnlFirst ?? params.isFullWithdrawal ?? false;\n\t\t\t\tif (shouldSettlePnl) {\n\t\t\t\t\tconst settleIx = await createSettlePnlIx({\n\t\t\t\t\t\tdriftClient: this._driftClient,\n\t\t\t\t\t\tuser,\n\t\t\t\t\t\tmarketIndexes: [params.marketIndex],\n\t\t\t\t\t\tmode: SettlePnlMode.TRY_SETTLE,\n\t\t\t\t\t\tmainSignerOverride: signingAuthority,\n\t\t\t\t\t});\n\t\t\t\t\tixs.push(settleIx);\n\t\t\t\t}\n\t\t\t\tconst position =\n\t\t\t\t\tuser.getUserAccount().perpPositions[params.marketIndex];\n\t\t\t\tconst transferAmount =\n\t\t\t\t\tparams.isFullWithdrawal && position.baseAssetAmount.eq(ZERO)\n\t\t\t\t\t\t? MIN_I64\n\t\t\t\t\t\t: params.amount.neg();\n\t\t\t\tconst transferIx =\n\t\t\t\t\tawait this._driftClient.getTransferIsolatedPerpPositionDepositIx(\n\t\t\t\t\t\ttransferAmount,\n\t\t\t\t\t\tparams.marketIndex,\n\t\t\t\t\t\tuser.getUserAccount().subAccountId,\n\t\t\t\t\t\ttrue,\n\t\t\t\t\t\tsigningAuthority\n\t\t\t\t\t);\n\t\t\t\tixs.push(transferIx);\n\t\t\t\treturn this._driftClient.buildTransaction(\n\t\t\t\t\tixs,\n\t\t\t\t\tparams.txParams ?? this.getTxParams()\n\t\t\t\t);\n\t\t\t},\n\t\t\tparams.mainSignerOverride\n\t\t);\n\t}\n\n\t/**\n\t * Single transaction: close isolated position + optionally withdraw collateral.\n\t * Without placeAndTake that atomically fills the close, the entire transaction may FAIL:\n\t * the withdraw ix runs after the close, and if the close did not fill in this tx,\n\t * the whole tx will fail. Strongly consider placeAndTake: { enable: true, referrerInfo: undefined }\n\t * when closing and withdrawing in the same tx.\n\t */\n\tpublic async getCloseAndWithdrawIsolatedPerpPositionTxn(\n\t\tparams: CentralServerGetCloseAndWithdrawIsolatedPerpPositionTxnParams\n\t): Promise<VersionedTransaction | Transaction> {\n\t\tconst perpMarketConfig = this._perpMarketConfigs.find(\n\t\t\t(m) => m.marketIndex === params.marketIndex\n\t\t);\n\t\tif (!perpMarketConfig) {\n\t\t\tthrow new Error(\n\t\t\t\t`Perp market config not found for index ${params.marketIndex}`\n\t\t\t);\n\t\t}\n\t\treturn this.driftClientContextWrapper(\n\t\t\tparams.userAccountPublicKey,\n\t\t\tasync (user) => {\n\t\t\t\tconst signingAuthority = params.mainSignerOverride;\n\t\t\t\tconst ixs: TransactionInstruction[] = [];\n\t\t\t\tif (\n\t\t\t\t\tparams.settlePnlBeforeClose &&\n\t\t\t\t\tparams.withdrawCollateralAfterClose\n\t\t\t\t) {\n\t\t\t\t\tconst settleIx = await createSettlePnlIx({\n\t\t\t\t\t\tdriftClient: this._driftClient,\n\t\t\t\t\t\tuser,\n\t\t\t\t\t\tmarketIndexes: [params.marketIndex],\n\t\t\t\t\t\tmode: SettlePnlMode.TRY_SETTLE,\n\t\t\t\t\t\tmainSignerOverride: signingAuthority,\n\t\t\t\t\t});\n\t\t\t\t\tixs.push(settleIx);\n\t\t\t\t}\n\t\t\t\tconst closeIxs = await createOpenPerpMarketOrderIxs({\n\t\t\t\t\tdriftClient: this._driftClient,\n\t\t\t\t\tuser,\n\t\t\t\t\tmarketIndex: params.marketIndex,\n\t\t\t\t\tdirection: params.direction,\n\t\t\t\t\tamount: params.baseAssetAmount,\n\t\t\t\t\tassetType: params.assetType ?? 'base',\n\t\t\t\t\treduceOnly: true,\n\t\t\t\t\tdlobServerHttpUrl: this._driftEndpoints.dlobServerHttpUrl,\n\t\t\t\t\tpositionMaxLeverage: 0,\n\t\t\t\t\tmainSignerOverride: signingAuthority,\n\t\t\t\t\tplaceAndTake: params.placeAndTake,\n\t\t\t\t});\n\t\t\t\tixs.push(...closeIxs);\n\t\t\t\tif (params.withdrawCollateralAfterClose) {\n\t\t\t\t\tconst transferIx =\n\t\t\t\t\t\tawait this._driftClient.getTransferIsolatedPerpPositionDepositIx(\n\t\t\t\t\t\t\tMIN_I64,\n\t\t\t\t\t\t\tparams.marketIndex,\n\t\t\t\t\t\t\tuser.getUserAccount().subAccountId,\n\t\t\t\t\t\t\ttrue,\n\t\t\t\t\t\t\tsigningAuthority\n\t\t\t\t\t\t);\n\t\t\t\t\tixs.push(transferIx);\n\t\t\t\t}\n\t\t\t\treturn this._driftClient.buildTransaction(\n\t\t\t\t\tixs,\n\t\t\t\t\tparams.txParams ?? this.getTxParams()\n\t\t\t\t);\n\t\t\t},\n\t\t\tparams.mainSignerOverride\n\t\t);\n\t}\n\n\t/**\n\t * Deposit from wallet + open isolated perp position in one transaction.\n\t * Flow: deposit from wallet directly into isolated, then place order.\n\t */\n\tpublic async getDepositAndOpenIsolatedPerpPositionTxn(\n\t\tparams: CentralServerGetDepositAndOpenIsolatedPerpPositionTxnParams\n\t): Promise<Transaction | VersionedTransaction> {\n\t\tconst { depositAmount, userAccountPublicKey, ...rest } = params;\n\t\tif (!depositAmount || depositAmount.isZero()) {\n\t\t\tthrow new Error('depositAmount is required and must be non-zero');\n\t\t}\n\t\tconst perpMarketConfig = this._perpMarketConfigs.find(\n\t\t\t(m) => m.marketIndex === params.marketIndex\n\t\t);\n\t\tif (!perpMarketConfig) {\n\t\t\tthrow new Error(\n\t\t\t\t`Perp market config not found for index ${params.marketIndex}`\n\t\t\t);\n\t\t}\n\t\treturn this.driftClientContextWrapper(\n\t\t\tuserAccountPublicKey,\n\t\t\tasync (user) => {\n\t\t\t\tconst signingAuthority = rest.mainSignerOverride;\n\t\t\t\tconst subAccountId = user.getUserAccount().subAccountId;\n\n\t\t\t\tconst perpMarketAccount = this._driftClient.getPerpMarketAccount(\n\t\t\t\t\tparams.marketIndex\n\t\t\t\t);\n\t\t\t\tconst quoteSpotMarketIndex = perpMarketAccount.quoteSpotMarketIndex;\n\t\t\t\tconst spotMarketAccount =\n\t\t\t\t\tthis._driftClient.getSpotMarketAccount(quoteSpotMarketIndex);\n\t\t\t\tconst depositor = signingAuthority ?? user.getUserAccount().authority;\n\t\t\t\tconst userTokenAccount = await getTokenAddressForDepositAndWithdraw(\n\t\t\t\t\tspotMarketAccount,\n\t\t\t\t\tdepositor\n\t\t\t\t);\n\n\t\t\t\tconst depositIx =\n\t\t\t\t\tawait this._driftClient.getDepositIntoIsolatedPerpPositionIx(\n\t\t\t\t\t\tdepositAmount,\n\t\t\t\t\t\tparams.marketIndex,\n\t\t\t\t\t\tuserTokenAccount,\n\t\t\t\t\t\tsubAccountId\n\t\t\t\t\t);\n\n\t\t\t\tconst orderIxs = await createOpenPerpMarketOrderIxs({\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\tdlobServerHttpUrl: this._driftEndpoints.dlobServerHttpUrl,\n\t\t\t\t\tisolatedPositionDeposit: undefined,\n\t\t\t\t\tmainSignerOverride: signingAuthority,\n\t\t\t\t});\n\n\t\t\t\tconst ixs = [depositIx, ...orderIxs];\n\t\t\t\treturn this._driftClient.buildTransaction(\n\t\t\t\t\tixs,\n\t\t\t\t\tparams.txParams ?? this.getTxParams()\n\t\t\t\t);\n\t\t\t},\n\t\t\trest.mainSignerOverride\n\t\t);\n\t}\n\n\t/**\n\t * Close isolated position + withdraw to wallet in one transaction.\n\t * Flow: close order, then withdraw from isolated directly to wallet (bundle handles settle if needed).\n\t * Without placeAndTake that atomically fills the close, the entire transaction may FAIL:\n\t * the withdraw runs after the close, and if the close did not fill in this tx, the withdraw may fail depending on withdraw amount.\n\t * Strongly consider placeAndTake: { enable: true, referrerInfo: undefined } when closing and withdrawing.\n\t */\n\tpublic async getCloseAndWithdrawIsolatedPerpPositionToWalletTxn(\n\t\tparams: CentralServerGetCloseAndWithdrawIsolatedPerpPositionToWalletTxnParams\n\t): Promise<VersionedTransaction | Transaction> {\n\t\tconst perpMarketConfig = this._perpMarketConfigs.find(\n\t\t\t(m) => m.marketIndex === params.marketIndex\n\t\t);\n\t\tif (!perpMarketConfig) {\n\t\t\tthrow new Error(\n\t\t\t\t`Perp market config not found for index ${params.marketIndex}`\n\t\t\t);\n\t\t}\n\t\treturn this.driftClientContextWrapper(\n\t\t\tparams.userAccountPublicKey,\n\t\t\tasync (user) => {\n\t\t\t\tconst signingAuthority = params.mainSignerOverride;\n\t\t\t\tconst subAccountId = user.getUserAccount().subAccountId;\n\n\t\t\t\tconst closeIxs = await createOpenPerpMarketOrderIxs({\n\t\t\t\t\tdriftClient: this._driftClient,\n\t\t\t\t\tuser,\n\t\t\t\t\tmarketIndex: params.marketIndex,\n\t\t\t\t\tdirection: params.direction,\n\t\t\t\t\tamount: params.baseAssetAmount,\n\t\t\t\t\tassetType: params.assetType ?? 'base',\n\t\t\t\t\treduceOnly: true,\n\t\t\t\t\tdlobServerHttpUrl: this._driftEndpoints.dlobServerHttpUrl,\n\t\t\t\t\tpositionMaxLeverage: 0,\n\t\t\t\t\tmainSignerOverride: signingAuthority,\n\t\t\t\t\tplaceAndTake: params.placeAndTake,\n\t\t\t\t});\n\n\t\t\t\tconst perpMarketAccount = this._driftClient.getPerpMarketAccount(\n\t\t\t\t\tparams.marketIndex\n\t\t\t\t);\n\t\t\t\tconst quoteSpotMarketIndex = perpMarketAccount.quoteSpotMarketIndex;\n\t\t\t\tconst spotMarketAccount =\n\t\t\t\t\tthis._driftClient.getSpotMarketAccount(quoteSpotMarketIndex);\n\t\t\t\tconst withdrawToAuthority =\n\t\t\t\t\tparams.mainSignerOverride ?? user.getUserAccount().authority;\n\t\t\t\tconst userTokenAccount = await getTokenAddressForDepositAndWithdraw(\n\t\t\t\t\tspotMarketAccount,\n\t\t\t\t\twithdrawToAuthority\n\t\t\t\t);\n\n\t\t\t\tconst withdrawAmount =\n\t\t\t\t\tparams.estimatedWithdrawAmount ??\n\t\t\t\t\tthis._driftClient.getIsolatedPerpPositionTokenAmount(\n\t\t\t\t\t\tparams.marketIndex,\n\t\t\t\t\t\tsubAccountId\n\t\t\t\t\t);\n\t\t\t\tconst withdrawIxs =\n\t\t\t\t\tawait this._driftClient.getWithdrawFromIsolatedPerpPositionIxsBundle(\n\t\t\t\t\t\twithdrawAmount,\n\t\t\t\t\t\tparams.marketIndex,\n\t\t\t\t\t\tsubAccountId,\n\t\t\t\t\t\tuserTokenAccount\n\t\t\t\t\t);\n\n\t\t\t\tconst ixs = [...closeIxs, ...withdrawIxs];\n\t\t\t\treturn this._driftClient.buildTransaction(\n\t\t\t\t\tixs,\n\t\t\t\t\tparams.txParams ?? this.getTxParams()\n\t\t\t\t);\n\t\t\t},\n\t\t\tparams.mainSignerOverride\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\tpositionMaxLeverage?: 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\tdriftClient: this._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\tdriftClient: this._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?: UnifiedQuoteResponse;\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\tconst swapClient = new UnifiedSwapClient({\n\t\t\t\t\tclientType: 'jupiter',\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 swapClient.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\tswapClient,\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\t/**\n\t * Create a transaction to initialize a RevenueShareEscrow account for a user.\n\t * Optionally bundles an initial builder approval in the same transaction.\n\t */\n\tpublic async getCreateRevenueShareEscrowTxn(\n\t\tauthority: PublicKey,\n\t\toptions?: {\n\t\t\tnumOrders?: number;\n\t\t\tbuilder?: {\n\t\t\t\tbuilderAuthority: PublicKey;\n\t\t\t\tmaxFeeTenthBps: number;\n\t\t\t};\n\t\t\ttxParams?: TxParams;\n\t\t}\n\t): Promise<VersionedTransaction | Transaction> {\n\t\treturn this.authorityContextWrapper(authority, () =>\n\t\t\tcreateRevenueShareEscrowTxn({\n\t\t\t\tdriftClient: this._driftClient,\n\t\t\t\tauthority,\n\t\t\t\tnumOrders: options?.numOrders ?? 16,\n\t\t\t\tbuilder: options?.builder,\n\t\t\t\ttxParams: options?.txParams ?? this.getTxParams(),\n\t\t\t})\n\t\t);\n\t}\n\n\t/**\n\t * Create a transaction to initialize a RevenueShare account for a builder.\n\t * This must be initialized before a builder can receive builder fees.\n\t */\n\tpublic async getCreateRevenueShareAccountTxn(\n\t\tauthority: PublicKey,\n\t\toptions?: {\n\t\t\ttxParams?: TxParams;\n\t\t}\n\t): Promise<VersionedTransaction | Transaction> {\n\t\treturn this.authorityContextWrapper(authority, () =>\n\t\t\tcreateRevenueShareAccountTxn({\n\t\t\t\tdriftClient: this._driftClient,\n\t\t\t\tauthority,\n\t\t\t\ttxParams: options?.txParams ?? this.getTxParams(),\n\t\t\t})\n\t\t);\n\t}\n\n\t/**\n\t * Create a transaction to configure a builder's approval status and fee cap.\n\t * Handles approve, update, and revoke operations.\n\t * Set maxFeeTenthBps to 0 to revoke a builder.\n\t */\n\tpublic async getConfigureApprovedBuilderTxn(\n\t\tauthority: PublicKey,\n\t\tbuilderAuthority: PublicKey,\n\t\tmaxFeeTenthBps: number,\n\t\toptions?: {\n\t\t\ttxParams?: TxParams;\n\t\t}\n\t): Promise<VersionedTransaction | Transaction> {\n\t\treturn this.authorityContextWrapper(authority, () =>\n\t\t\tconfigureBuilderTxn({\n\t\t\t\tdriftClient: this._driftClient,\n\t\t\t\tauthority,\n\t\t\t\tbuilderAuthority,\n\t\t\t\tmaxFeeTenthBps,\n\t\t\t\ttxParams: options?.txParams ?? this.getTxParams(),\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":"index.js","sourceRoot":"","sources":["../../../../../src/drift/Drift/clients/CentralServerDrift/index.ts"],"names":[],"mappings":";;;AAAA,yCAkCyB;AACzB,6CAKyB;AACzB,6EAA4E;AAC5E,+CAMyB;AACzB,gEAAsE;AACtE,kEAAwE;AACxE,mDAA+E;AAC/E,4EAAkF;AAClF,oEAG8C;AAC9C,uGAIuE;AACvE,6GAG0E;AAG1E,qEAA2E;AAC3E,yEAAgF;AAChF,2DAAiE;AACjE,8DAA0F;AAC1F,8DAAkE;AAClE,qGAAqG;AACrG,uGAAuG;AACvG,qFAAqF;AACrF,2EAAwE;AASxE,uCAAsD;AACtD,uEAAoE;AAapE;;;;GAIG;AACH,MAAa,kBAAkB;IAmB9B;;;;;OAKG;IACH,YAAY,MAOX;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,UAAU,EACV,6CAAiC,EACjC,uDAA2C,CAC3C,CAAC;QAEF,MAAM,MAAM,GAAG,+BAAe,CAAC,wBAAwB,EAAE,CAAC,CAAC,4DAA4D;QAEvH,MAAM,oBAAoB,GACzB,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,uBAAiB,CAAC,CAAC,CAAC,wBAAkB,CAAC;QACh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EAAE;;YACnD,OAAA,IAAA,wDAA4B,EAAC;gBAC5B,WAAW,EAAE,IAAI,CAAC,YAAY;gBAC9B,SAAS;gBACT,QAAQ,EAAE,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,QAAQ,mCAAI,IAAI,CAAC,WAAW,EAAE;aACjD,CAAC,CAAA;SAAA,CACF,CAAC;IACH,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,8BAA8B,CAC1C,SAAoB,EACpB,gBAA2B,EAC3B,cAAsB,EACtB,OAEC;QAED,OAAO,IAAI,CAAC,uBAAuB,CAAC,SAAS,EAAE,GAAG,EAAE;;YACnD,OAAA,IAAA,sCAAmB,EAAC;gBACnB,WAAW,EAAE,IAAI,CAAC,YAAY;gBAC9B,SAAS;gBACT,gBAAgB;gBAChB,cAAc;gBACd,QAAQ,EAAE,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,QAAQ,mCAAI,IAAI,CAAC,WAAW,EAAE;aACjD,CAAC,CAAA;SAAA,CACF,CAAC;IACH,CAAC;IAEM,KAAK,CAAC,qBAAqB,CAAC,EAAsC;QACxE,OAAO,IAAI,CAAC,YAAY,CAAC,eAAe,CAAC,EAAE,EAAE,SAAS,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;IAC1E,CAAC;CACD;AArmCD,gDAqmCC","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\tfetchUserStatsAccount,\n\tgetMarketsAndOraclesForSubscription,\n\tMainnetPerpMarkets,\n\tMainnetSpotMarkets,\n\tMarketType,\n\tMIN_I64,\n\tOneShotUserAccountSubscriber,\n\tOrderTriggerCondition,\n\tPerpMarketConfig,\n\tPositionDirection,\n\tPriorityFeeMethod,\n\tPriorityFeeSubscriber,\n\tPriorityFeeSubscriberConfig,\n\tPublicKey,\n\tSettlePnlMode,\n\tSpotMarketConfig,\n\tSwapMode,\n\tTxParams,\n\tUnifiedQuoteResponse,\n\tUnifiedSwapClient,\n\tUser,\n\tWhileValidTxSender,\n\tZERO,\n} from '@drift-labs/sdk';\nimport {\n\tConnection,\n\tTransaction,\n\tTransactionInstruction,\n\tVersionedTransaction,\n} 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\tHIGH_ACTIVITY_MARKET_ACCOUNTS,\n} from '../../constants';\nimport { createDepositTxn } from '../../../base/actions/spot/deposit';\nimport { createWithdrawTxn } from '../../../base/actions/spot/withdraw';\nimport { getTokenAddressForDepositAndWithdraw } from '../../../../utils/token';\nimport { createSettleFundingTxn } from '../../../base/actions/perp/settleFunding';\nimport {\n\tcreateSettlePnlIx,\n\tcreateSettlePnlTxn,\n} from '../../../base/actions/perp/settlePnl';\nimport {\n\tcreateOpenPerpMarketOrder,\n\tcreateOpenPerpMarketOrderIxs,\n\tcreateSwiftMarketOrderMessage,\n} from '../../../base/actions/trade/openPerpOrder/openPerpMarketOrder';\nimport {\n\tcreateOpenPerpNonMarketOrder,\n\tcreateSwiftLimitOrderMessage,\n} from '../../../base/actions/trade/openPerpOrder/openPerpNonMarketOrder';\nimport { SwiftOrderMessage } from '../../../base/actions/trade/openPerpOrder/openSwiftOrder';\nimport { LimitOrderParamsOrderConfig } from '../../../base/actions/trade/openPerpOrder/types';\nimport { createEditOrderTxn } from '../../../base/actions/trade/editOrder';\nimport { createCancelOrdersTxn } from '../../../base/actions/trade/cancelOrder';\nimport { createSwapTxn } from '../../../base/actions/trade/swap';\nimport { createUserAndDepositCollateralBaseTxn } from '../../../base/actions/user/create';\nimport { deleteUserTxn } from '../../../base/actions/user/delete';\nimport { createRevenueShareEscrowTxn } from '../../../base/actions/builder/createRevenueShareEscrow';\nimport { createRevenueShareAccountTxn } from '../../../base/actions/builder/createRevenueShareAccount';\nimport { configureBuilderTxn } from '../../../base/actions/builder/configureBuilder';\nimport { EnvironmentConstants } from '../../../../EnvironmentConstants';\nimport {\n\tCentralServerGetOpenPerpMarketOrderTxnParams,\n\tCentralServerGetOpenPerpNonMarketOrderTxnParams,\n\tCentralServerGetWithdrawIsolatedPerpPositionCollateralTxnParams,\n\tCentralServerGetCloseAndWithdrawIsolatedPerpPositionTxnParams,\n\tCentralServerGetDepositAndOpenIsolatedPerpPositionTxnParams,\n\tCentralServerGetCloseAndWithdrawIsolatedPerpPositionToWalletTxnParams,\n} from './types';\nimport { CentralServerDriftMarkets } from './markets';\nimport { DriftOperations } from '../AuthorityDrift/DriftOperations';\n\nexport type {\n\tCentralServerGetOpenPerpMarketOrderTxnParams,\n\tCentralServerGetOpenPerpNonMarketOrderTxnParams,\n\tCentralServerSwiftOrderOptions,\n\tCentralServerGetWithdrawIsolatedPerpPositionCollateralTxnParams,\n\tCentralServerGetCloseAndWithdrawIsolatedPerpPositionTxnParams,\n\tCentralServerGetDepositAndOpenIsolatedPerpPositionTxnParams,\n\tCentralServerGetCloseAndWithdrawIsolatedPerpPositionToWalletTxnParams,\n} from './types';\nexport type { SwiftOrderMessage } 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\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};\n\n\t/**\n\t * Handles priority fee tracking and calculation for optimized transaction costs.\n\t */\n\tprivate priorityFeeSubscriber!: PriorityFeeSubscriber;\n\n\tpublic readonly markets: CentralServerDriftMarkets;\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 supportedPerpMarkets - The perp markets indexes to support. See https://github.com/drift-labs/protocol-v2/blob/master/sdk/src/constants/perpMarkets.ts for all available markets. It is recommended to only include markets that will be used.\n\t * @param supportedSpotMarkets - The spot markets indexes to support. See https://github.com/drift-labs/protocol-v2/blob/master/sdk/src/constants/spotMarkets.ts for all available markets. It is recommended to only include markets that will be used.\n\t */\n\tconstructor(config: {\n\t\tsolanaRpcEndpoint: string;\n\t\tdriftEnv: DriftEnv;\n\t\tsupportedPerpMarkets: number[];\n\t\tsupportedSpotMarkets: number[];\n\t\tadditionalDriftClientConfig?: Partial<Omit<DriftClientConfig, 'env'>>;\n\t\tpriorityFeeSubscriberConfig?: Partial<PriorityFeeSubscriberConfig>;\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 allPerpMarketConfigs =\n\t\t\tdriftEnv === 'devnet' ? DevnetPerpMarkets : MainnetPerpMarkets;\n\t\tconst allSpotMarketConfigs =\n\t\t\tdriftEnv === 'devnet' ? DevnetSpotMarkets : MainnetSpotMarkets;\n\t\tthis._perpMarketConfigs = config.supportedPerpMarkets.map((marketIndex) =>\n\t\t\tallPerpMarketConfigs.find((market) => market.marketIndex === marketIndex)\n\t\t);\n\t\tthis._spotMarketConfigs = config.supportedSpotMarkets.map((marketIndex) =>\n\t\t\tallSpotMarketConfigs.find((market) => market.marketIndex === marketIndex)\n\t\t);\n\n\t\tconst oracleInfos = getMarketsAndOraclesForSubscription(\n\t\t\tdriftEnv,\n\t\t\tthis._perpMarketConfigs,\n\t\t\tthis._spotMarketConfigs\n\t\t);\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\tperpMarketIndexes: this._perpMarketConfigs.map(\n\t\t\t\t(market) => market.marketIndex\n\t\t\t),\n\t\t\tspotMarketIndexes: this._spotMarketConfigs.map(\n\t\t\t\t(market) => market.marketIndex\n\t\t\t),\n\t\t\toracleInfos: oracleInfos.oracleInfos,\n\t\t\t...config.additionalDriftClientConfig,\n\t\t};\n\t\tthis._driftClient = new DriftClient(driftClientConfig);\n\t\tthis.markets = new CentralServerDriftMarkets(this._driftClient);\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\t// set up Drift endpoints\n\t\tconst driftDlobServerHttpUrlToUse =\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\tthis._driftEndpoints = {\n\t\t\tdlobServerHttpUrl: driftDlobServerHttpUrlToUse,\n\t\t\tswiftServerUrl: swiftServerUrlToUse,\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\taddresses: HIGH_ACTIVITY_MARKET_ACCOUNTS,\n\t\t\t...config.priorityFeeSubscriberConfig,\n\t\t};\n\n\t\tthis.priorityFeeSubscriber = new PriorityFeeSubscriber(priorityFeeConfig);\n\t}\n\n\tpublic get driftClient() {\n\t\treturn this._driftClient;\n\t}\n\n\tpublic async subscribe() {\n\t\tawait this._driftClient.subscribe();\n\t\tawait this.priorityFeeSubscriber.subscribe();\n\t}\n\n\tpublic async unsubscribe() {\n\t\tawait this._driftClient.unsubscribe();\n\t\tawait this.priorityFeeSubscriber.unsubscribe();\n\t}\n\n\t/**\n\t * Temporarily swaps the DriftClient wallet/authority context to build transactions\n\t * for a given authority, then restores the original state.\n\t *\n\t * Use this for authority-based operations that don't require a User account subscription\n\t * (e.g. creating revenue share accounts, managing builders).\n\t *\n\t * @param authority - The authority to set on the DriftClient\n\t * @param operation - The transaction creation operation to execute\n\t * @returns The result of the operation\n\t */\n\tprivate async authorityContextWrapper<T>(\n\t\tauthority: PublicKey,\n\t\toperation: () => Promise<T>\n\t): Promise<T> {\n\t\tconst originalWallet = this._driftClient.wallet;\n\t\tconst originalAuthority = this._driftClient.authority;\n\n\t\tconst authorityWallet = {\n\t\t\tpublicKey: authority,\n\t\t\tsignTransaction: () =>\n\t\t\t\tPromise.reject('This is a placeholder - do not sign with this wallet'),\n\t\t\tsignAllTransactions: () =>\n\t\t\t\tPromise.reject('This is a placeholder - do not sign with this wallet'),\n\t\t};\n\n\t\ttry {\n\t\t\tthis._driftClient.wallet = authorityWallet;\n\t\t\t// @ts-ignore\n\t\t\tthis._driftClient.provider.wallet = authorityWallet;\n\t\t\tthis._driftClient.txHandler.updateWallet(authorityWallet);\n\t\t\tthis._driftClient.authority = authority;\n\n\t\t\treturn await operation();\n\t\t} finally {\n\t\t\tthis._driftClient.wallet = originalWallet;\n\t\t\tthis._driftClient.txHandler.updateWallet(originalWallet);\n\t\t\t// @ts-ignore\n\t\t\tthis._driftClient.provider.wallet = originalWallet;\n\t\t\tthis._driftClient.authority = originalAuthority;\n\t\t}\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\texternalWallet?: PublicKey\n\t): Promise<T> {\n\t\tconst user = new User({\n\t\t\tdriftClient: this._driftClient,\n\t\t\tuserAccountPublicKey,\n\t\t\taccountSubscription: {\n\t\t\t\ttype: 'custom',\n\t\t\t\tuserAccountSubscriber: new OneShotUserAccountSubscriber(\n\t\t\t\t\tthis._driftClient.program,\n\t\t\t\t\tuserAccountPublicKey,\n\t\t\t\t\tundefined,\n\t\t\t\t\tundefined\n\t\t\t\t),\n\t\t\t},\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: externalWallet ?? 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\t/**\n\t * Returns a User object for a given user account public key. This fetches the user account data once.\n\t *\n\t * You may read more about the User object [here](https://github.com/drift-labs/protocol-v2/blob/master/sdk/src/user.ts)\n\t *\n\t * @param userAccountPublicKey - The user account public key\n\t */\n\tpublic async getUser(userAccountPublicKey: PublicKey): Promise<User> {\n\t\tconst oneShotUserAccountSubscriber = new OneShotUserAccountSubscriber(\n\t\t\tthis._driftClient.program,\n\t\t\tuserAccountPublicKey,\n\t\t\tundefined,\n\t\t\tundefined\n\t\t);\n\t\tconst user = new User({\n\t\t\tdriftClient: this._driftClient,\n\t\t\tuserAccountPublicKey,\n\t\t\taccountSubscription: {\n\t\t\t\ttype: 'custom',\n\t\t\t\tuserAccountSubscriber: oneShotUserAccountSubscriber,\n\t\t\t},\n\t\t});\n\t\tawait user.subscribe();\n\t\treturn user;\n\t}\n\n\t/**\n\t * Gets transaction parameters with dynamic priority fees.\n\t * Falls back to default if priority fee function is not available.\n\t */\n\tgetTxParams(overrides?: Partial<TxParams>): TxParams {\n\t\tconst unsafePriorityFee = Math.floor(\n\t\t\tthis.priorityFeeSubscriber.getCustomStrategyResult() ??\n\t\t\t\tDriftOperations.DEFAULT_TX_PARAMS.computeUnitsPrice\n\t\t);\n\n\t\tconst safePriorityFee = Math.min(\n\t\t\tunsafePriorityFee,\n\t\t\tDriftOperations.MAX_COMPUTE_UNITS_PRICE\n\t\t);\n\n\t\treturn {\n\t\t\t...DriftOperations.DEFAULT_TX_PARAMS,\n\t\t\tcomputeUnitsPrice: safePriorityFee,\n\t\t\t...overrides,\n\t\t};\n\t}\n\n\tpublic async getCreateAndDepositTxn(\n\t\tauthority: PublicKey,\n\t\tamount: BN,\n\t\tspotMarketIndex: number,\n\t\toptions?: {\n\t\t\treferrerName?: string;\n\t\t\taccountName?: string;\n\t\t\tpoolId?: number;\n\t\t\tfromSubAccountId?: number;\n\t\t\tcustomMaxMarginRatio?: number;\n\t\t\ttxParams?: TxParams;\n\t\t\t/**\n\t\t\t * Optional external wallet to deposit from. If provided, the deposit will be made\n\t\t\t * from this wallet instead of the authority wallet.\n\t\t\t */\n\t\t\texternalWallet?: PublicKey;\n\t\t}\n\t): Promise<{\n\t\ttransaction: VersionedTransaction | Transaction;\n\t\tuserAccountPublicKey: PublicKey;\n\t\tsubAccountId: number;\n\t}> {\n\t\tconst spotMarketConfig = this._spotMarketConfigs.find(\n\t\t\t(market) => market.marketIndex === spotMarketIndex\n\t\t);\n\n\t\tif (!spotMarketConfig) {\n\t\t\tthrow new Error(\n\t\t\t\t`Spot market config not found for index ${spotMarketIndex}`\n\t\t\t);\n\t\t}\n\n\t\tconst userStatsAccount = await fetchUserStatsAccount(\n\t\t\tthis._driftClient.connection,\n\t\t\tthis._driftClient.program,\n\t\t\tauthority\n\t\t);\n\n\t\treturn this.authorityContextWrapper(\n\t\t\toptions?.externalWallet ?? authority,\n\t\t\tasync () => {\n\t\t\t\tthis._driftClient.authority = authority;\n\t\t\t\t// Clear userStatsAccountPublicKey cache so it's recalculated for the new authority\n\t\t\t\t// @ts-ignore - accessing private property for cache invalidation\n\t\t\t\tthis._driftClient.userStatsAccountPublicKey = undefined;\n\n\t\t\t\treturn await createUserAndDepositCollateralBaseTxn({\n\t\t\t\t\tdriftClient: this._driftClient,\n\t\t\t\t\tamount,\n\t\t\t\t\tspotMarketConfig,\n\t\t\t\t\tauthority,\n\t\t\t\t\tuserStatsAccount,\n\t\t\t\t\treferrerName: options?.referrerName,\n\t\t\t\t\taccountName: options?.accountName,\n\t\t\t\t\tpoolId: options?.poolId,\n\t\t\t\t\tfromSubAccountId: options?.fromSubAccountId,\n\t\t\t\t\tcustomMaxMarginRatio: options?.customMaxMarginRatio,\n\t\t\t\t\ttxParams: options?.txParams ?? this.getTxParams(),\n\t\t\t\t\texternalWallet: options?.externalWallet,\n\t\t\t\t});\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\toptions?: {\n\t\t\ttxParams?: TxParams;\n\t\t\t/**\n\t\t\t * Optional external wallet to deposit from. If provided, the deposit will be made\n\t\t\t * from this wallet instead of the user's authority wallet.\n\t\t\t */\n\t\t\texternalWallet?: PublicKey;\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 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\ttxParams: options?.txParams ?? this.getTxParams(),\n\t\t\t\t\texternalWallet: options?.externalWallet,\n\t\t\t\t});\n\n\t\t\t\treturn depositTxn;\n\t\t\t},\n\t\t\toptions?.externalWallet\n\t\t);\n\t}\n\n\tpublic async getDeleteUserTxn(\n\t\tuserAccountPublicKey: PublicKey,\n\t\toptions?: {\n\t\t\ttxParams?: TxParams;\n\t\t}\n\t): Promise<VersionedTransaction | Transaction> {\n\t\treturn this.driftClientContextWrapper(userAccountPublicKey, async () => {\n\t\t\treturn deleteUserTxn({\n\t\t\t\tdriftClient: this._driftClient,\n\t\t\t\tuserPublicKey: userAccountPublicKey,\n\t\t\t\ttxParams: options?.txParams ?? this.getTxParams(),\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\ttxParams?: TxParams;\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\ttxParams: options?.txParams ?? this.getTxParams(),\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\toptions?: {\n\t\t\ttxParams?: TxParams;\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 settleFundingTxn = await createSettleFundingTxn({\n\t\t\t\t\tdriftClient: this._driftClient,\n\t\t\t\t\tuser,\n\t\t\t\t\ttxParams: options?.txParams ?? this.getTxParams(),\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\toptions?: {\n\t\t\ttxParams?: TxParams;\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 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\ttxParams: options?.txParams ?? this.getTxParams(),\n\t\t\t\t});\n\n\t\t\t\treturn settlePnlTxn;\n\t\t\t}\n\t\t);\n\t}\n\n\t// overloads for better type inference\n\tpublic async getOpenPerpMarketOrderTxn(\n\t\tparams: CentralServerGetOpenPerpMarketOrderTxnParams<true>\n\t): Promise<SwiftOrderMessage>;\n\tpublic async getOpenPerpMarketOrderTxn(\n\t\tparams: CentralServerGetOpenPerpMarketOrderTxnParams<false>\n\t): Promise<Transaction | VersionedTransaction>;\n\tpublic async getOpenPerpMarketOrderTxn(\n\t\tparams:\n\t\t\t| CentralServerGetOpenPerpMarketOrderTxnParams<true>\n\t\t\t| CentralServerGetOpenPerpMarketOrderTxnParams<false>\n\t): Promise<SwiftOrderMessage | Transaction | VersionedTransaction> {\n\t\tconst { userAccountPublicKey, useSwift, ...genericRest } = params;\n\n\t\tif (useSwift) {\n\t\t\tconst { swiftOptions, ...rest } =\n\t\t\t\tgenericRest as CentralServerGetOpenPerpMarketOrderTxnParams<true>;\n\t\t\treturn this.driftClientContextWrapper(\n\t\t\t\tuserAccountPublicKey,\n\t\t\t\tasync (user): Promise<SwiftOrderMessage> => {\n\t\t\t\t\treturn createSwiftMarketOrderMessage({\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\tdlobServerHttpUrl: this._driftEndpoints.dlobServerHttpUrl,\n\t\t\t\t\t\tuserSigningSlotBuffer: swiftOptions?.userSigningSlotBuffer,\n\t\t\t\t\t\tisDelegate: swiftOptions?.isDelegate ?? !!rest.mainSignerOverride,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t);\n\t\t} else {\n\t\t\tconst { txParams, ...rest } =\n\t\t\t\tgenericRest as CentralServerGetOpenPerpMarketOrderTxnParams<false>;\n\t\t\treturn this.driftClientContextWrapper(\n\t\t\t\tuserAccountPublicKey,\n\t\t\t\tasync (user): Promise<Transaction | VersionedTransaction> => {\n\t\t\t\t\tconst openPerpMarketOrderTxn = await createOpenPerpMarketOrder({\n\t\t\t\t\t\t...rest,\n\t\t\t\t\t\tuseSwift: false,\n\t\t\t\t\t\tdriftClient: this._driftClient,\n\t\t\t\t\t\tuser,\n\t\t\t\t\t\tdlobServerHttpUrl: this._driftEndpoints.dlobServerHttpUrl,\n\t\t\t\t\t\ttxParams: txParams ?? this.getTxParams(),\n\t\t\t\t\t});\n\t\t\t\t\treturn openPerpMarketOrderTxn as Transaction | VersionedTransaction;\n\t\t\t\t},\n\t\t\t\trest.mainSignerOverride\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\tparams: CentralServerGetOpenPerpNonMarketOrderTxnParams<true>\n\t): Promise<SwiftOrderMessage>;\n\tpublic async getOpenPerpNonMarketOrderTxn(\n\t\tparams: CentralServerGetOpenPerpNonMarketOrderTxnParams<false>\n\t): Promise<Transaction | VersionedTransaction>;\n\tpublic async getOpenPerpNonMarketOrderTxn(\n\t\tparams:\n\t\t\t| CentralServerGetOpenPerpNonMarketOrderTxnParams<true>\n\t\t\t| CentralServerGetOpenPerpNonMarketOrderTxnParams<false>\n\t): Promise<SwiftOrderMessage | Transaction | VersionedTransaction> {\n\t\tconst { userAccountPublicKey, useSwift, ...genericRest } = params;\n\n\t\tif (useSwift) {\n\t\t\tconst { swiftOptions, ...rest } =\n\t\t\t\tgenericRest as CentralServerGetOpenPerpNonMarketOrderTxnParams<true>;\n\n\t\t\tif (rest.orderConfig.orderType !== 'limit') {\n\t\t\t\tthrow new Error('Only limit orders are supported with Swift');\n\t\t\t}\n\n\t\t\treturn this.driftClientContextWrapper(\n\t\t\t\tuserAccountPublicKey,\n\t\t\t\tasync (user): Promise<SwiftOrderMessage> => {\n\t\t\t\t\treturn createSwiftLimitOrderMessage({\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\torderConfig: rest.orderConfig as LimitOrderParamsOrderConfig,\n\t\t\t\t\t\tuserSigningSlotBuffer: swiftOptions?.userSigningSlotBuffer,\n\t\t\t\t\t\tisDelegate: swiftOptions?.isDelegate ?? !!rest.mainSignerOverride,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t);\n\t\t} else {\n\t\t\tconst { txParams, ...rest } =\n\t\t\t\tgenericRest as CentralServerGetOpenPerpNonMarketOrderTxnParams<false>;\n\t\t\treturn this.driftClientContextWrapper(\n\t\t\t\tuserAccountPublicKey,\n\t\t\t\tasync (user): Promise<Transaction | VersionedTransaction> => {\n\t\t\t\t\tconst openPerpNonMarketOrderTxn = await createOpenPerpNonMarketOrder({\n\t\t\t\t\t\t...rest,\n\t\t\t\t\t\tuseSwift: false,\n\t\t\t\t\t\tdriftClient: this._driftClient,\n\t\t\t\t\t\tuser,\n\t\t\t\t\t\ttxParams: txParams ?? this.getTxParams(),\n\t\t\t\t\t});\n\t\t\t\t\treturn openPerpNonMarketOrderTxn as\n\t\t\t\t\t\t| Transaction\n\t\t\t\t\t\t| VersionedTransaction;\n\t\t\t\t},\n\t\t\t\trest.mainSignerOverride\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Create a transaction to withdraw collateral from an isolated perp position back to cross. Often to be called after fully closing position\n\t */\n\tpublic async getWithdrawIsolatedPerpPositionCollateralTxn(\n\t\tparams: CentralServerGetWithdrawIsolatedPerpPositionCollateralTxnParams\n\t): Promise<VersionedTransaction | Transaction> {\n\t\tconst perpMarketConfig = this._perpMarketConfigs.find(\n\t\t\t(m) => m.marketIndex === params.marketIndex\n\t\t);\n\t\tif (!perpMarketConfig) {\n\t\t\tthrow new Error(\n\t\t\t\t`Perp market config not found for index ${params.marketIndex}`\n\t\t\t);\n\t\t}\n\t\treturn this.driftClientContextWrapper(\n\t\t\tparams.userAccountPublicKey,\n\t\t\tasync (user) => {\n\t\t\t\tconst signingAuthority = params.mainSignerOverride;\n\t\t\t\tconst ixs: import('@solana/web3.js').TransactionInstruction[] = [];\n\t\t\t\tconst shouldSettlePnl =\n\t\t\t\t\tparams.settlePnlFirst ?? params.isFullWithdrawal ?? false;\n\t\t\t\tif (shouldSettlePnl) {\n\t\t\t\t\tconst settleIx = await createSettlePnlIx({\n\t\t\t\t\t\tdriftClient: this._driftClient,\n\t\t\t\t\t\tuser,\n\t\t\t\t\t\tmarketIndexes: [params.marketIndex],\n\t\t\t\t\t\tmode: SettlePnlMode.TRY_SETTLE,\n\t\t\t\t\t\tmainSignerOverride: signingAuthority,\n\t\t\t\t\t});\n\t\t\t\t\tixs.push(settleIx);\n\t\t\t\t}\n\t\t\t\tconst position =\n\t\t\t\t\tuser.getUserAccount().perpPositions[params.marketIndex];\n\t\t\t\tconst transferAmount =\n\t\t\t\t\tparams.isFullWithdrawal && position.baseAssetAmount.eq(ZERO)\n\t\t\t\t\t\t? MIN_I64\n\t\t\t\t\t\t: params.amount.neg();\n\t\t\t\tconst transferIx =\n\t\t\t\t\tawait this._driftClient.getTransferIsolatedPerpPositionDepositIx(\n\t\t\t\t\t\ttransferAmount,\n\t\t\t\t\t\tparams.marketIndex,\n\t\t\t\t\t\tuser.getUserAccount().subAccountId,\n\t\t\t\t\t\ttrue,\n\t\t\t\t\t\tsigningAuthority\n\t\t\t\t\t);\n\t\t\t\tixs.push(transferIx);\n\t\t\t\treturn this._driftClient.buildTransaction(\n\t\t\t\t\tixs,\n\t\t\t\t\tparams.txParams ?? this.getTxParams()\n\t\t\t\t);\n\t\t\t},\n\t\t\tparams.mainSignerOverride\n\t\t);\n\t}\n\n\t/**\n\t * Single transaction: close isolated position + optionally withdraw collateral.\n\t * Without placeAndTake that atomically fills the close, the entire transaction may FAIL:\n\t * the withdraw ix runs after the close, and if the close did not fill in this tx,\n\t * the whole tx will fail. Strongly consider placeAndTake: { enable: true, referrerInfo: undefined }\n\t * when closing and withdrawing in the same tx.\n\t */\n\tpublic async getCloseAndWithdrawIsolatedPerpPositionTxn(\n\t\tparams: CentralServerGetCloseAndWithdrawIsolatedPerpPositionTxnParams\n\t): Promise<VersionedTransaction | Transaction> {\n\t\tconst perpMarketConfig = this._perpMarketConfigs.find(\n\t\t\t(m) => m.marketIndex === params.marketIndex\n\t\t);\n\t\tif (!perpMarketConfig) {\n\t\t\tthrow new Error(\n\t\t\t\t`Perp market config not found for index ${params.marketIndex}`\n\t\t\t);\n\t\t}\n\t\treturn this.driftClientContextWrapper(\n\t\t\tparams.userAccountPublicKey,\n\t\t\tasync (user) => {\n\t\t\t\tconst signingAuthority = params.mainSignerOverride;\n\t\t\t\tconst ixs: TransactionInstruction[] = [];\n\t\t\t\tif (\n\t\t\t\t\tparams.settlePnlBeforeClose &&\n\t\t\t\t\tparams.withdrawCollateralAfterClose\n\t\t\t\t) {\n\t\t\t\t\tconst settleIx = await createSettlePnlIx({\n\t\t\t\t\t\tdriftClient: this._driftClient,\n\t\t\t\t\t\tuser,\n\t\t\t\t\t\tmarketIndexes: [params.marketIndex],\n\t\t\t\t\t\tmode: SettlePnlMode.TRY_SETTLE,\n\t\t\t\t\t\tmainSignerOverride: signingAuthority,\n\t\t\t\t\t});\n\t\t\t\t\tixs.push(settleIx);\n\t\t\t\t}\n\t\t\t\tconst closeIxs = await createOpenPerpMarketOrderIxs({\n\t\t\t\t\tdriftClient: this._driftClient,\n\t\t\t\t\tuser,\n\t\t\t\t\tmarketIndex: params.marketIndex,\n\t\t\t\t\tdirection: params.direction,\n\t\t\t\t\tamount: params.baseAssetAmount,\n\t\t\t\t\tassetType: params.assetType ?? 'base',\n\t\t\t\t\treduceOnly: true,\n\t\t\t\t\tdlobServerHttpUrl: this._driftEndpoints.dlobServerHttpUrl,\n\t\t\t\t\tpositionMaxLeverage: 0,\n\t\t\t\t\tmainSignerOverride: signingAuthority,\n\t\t\t\t\tplaceAndTake: params.placeAndTake,\n\t\t\t\t});\n\t\t\t\tixs.push(...closeIxs);\n\t\t\t\tif (params.withdrawCollateralAfterClose) {\n\t\t\t\t\tconst transferIx =\n\t\t\t\t\t\tawait this._driftClient.getTransferIsolatedPerpPositionDepositIx(\n\t\t\t\t\t\t\tMIN_I64,\n\t\t\t\t\t\t\tparams.marketIndex,\n\t\t\t\t\t\t\tuser.getUserAccount().subAccountId,\n\t\t\t\t\t\t\ttrue,\n\t\t\t\t\t\t\tsigningAuthority\n\t\t\t\t\t\t);\n\t\t\t\t\tixs.push(transferIx);\n\t\t\t\t}\n\t\t\t\treturn this._driftClient.buildTransaction(\n\t\t\t\t\tixs,\n\t\t\t\t\tparams.txParams ?? this.getTxParams()\n\t\t\t\t);\n\t\t\t},\n\t\t\tparams.mainSignerOverride\n\t\t);\n\t}\n\n\t/**\n\t * Deposit from wallet + open isolated perp position in one transaction.\n\t * Flow: deposit from wallet directly into isolated, then place order.\n\t */\n\tpublic async getDepositAndOpenIsolatedPerpPositionTxn(\n\t\tparams: CentralServerGetDepositAndOpenIsolatedPerpPositionTxnParams\n\t): Promise<Transaction | VersionedTransaction> {\n\t\tconst { depositAmount, userAccountPublicKey, ...rest } = params;\n\t\tif (!depositAmount || depositAmount.isZero()) {\n\t\t\tthrow new Error('depositAmount is required and must be non-zero');\n\t\t}\n\t\tconst perpMarketConfig = this._perpMarketConfigs.find(\n\t\t\t(m) => m.marketIndex === params.marketIndex\n\t\t);\n\t\tif (!perpMarketConfig) {\n\t\t\tthrow new Error(\n\t\t\t\t`Perp market config not found for index ${params.marketIndex}`\n\t\t\t);\n\t\t}\n\t\treturn this.driftClientContextWrapper(\n\t\t\tuserAccountPublicKey,\n\t\t\tasync (user) => {\n\t\t\t\tconst signingAuthority = rest.mainSignerOverride;\n\t\t\t\tconst subAccountId = user.getUserAccount().subAccountId;\n\n\t\t\t\tconst perpMarketAccount = this._driftClient.getPerpMarketAccount(\n\t\t\t\t\tparams.marketIndex\n\t\t\t\t);\n\t\t\t\tconst quoteSpotMarketIndex = perpMarketAccount.quoteSpotMarketIndex;\n\t\t\t\tconst spotMarketAccount =\n\t\t\t\t\tthis._driftClient.getSpotMarketAccount(quoteSpotMarketIndex);\n\t\t\t\tconst depositor = signingAuthority ?? user.getUserAccount().authority;\n\t\t\t\tconst userTokenAccount = await getTokenAddressForDepositAndWithdraw(\n\t\t\t\t\tspotMarketAccount,\n\t\t\t\t\tdepositor\n\t\t\t\t);\n\n\t\t\t\tconst depositIx =\n\t\t\t\t\tawait this._driftClient.getDepositIntoIsolatedPerpPositionIx(\n\t\t\t\t\t\tdepositAmount,\n\t\t\t\t\t\tparams.marketIndex,\n\t\t\t\t\t\tuserTokenAccount,\n\t\t\t\t\t\tsubAccountId\n\t\t\t\t\t);\n\n\t\t\t\tconst orderIxs = await createOpenPerpMarketOrderIxs({\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\tdlobServerHttpUrl: this._driftEndpoints.dlobServerHttpUrl,\n\t\t\t\t\tmainSignerOverride: signingAuthority,\n\t\t\t\t});\n\n\t\t\t\tconst ixs = [depositIx, ...orderIxs];\n\t\t\t\treturn this._driftClient.buildTransaction(\n\t\t\t\t\tixs,\n\t\t\t\t\tparams.txParams ?? this.getTxParams()\n\t\t\t\t);\n\t\t\t},\n\t\t\trest.mainSignerOverride\n\t\t);\n\t}\n\n\t/**\n\t * Close isolated position + withdraw to wallet in one transaction.\n\t * Flow: close order, then withdraw from isolated directly to wallet (bundle handles settle if needed).\n\t * Without placeAndTake that atomically fills the close, the entire transaction may FAIL:\n\t * the withdraw runs after the close, and if the close did not fill in this tx, the withdraw may fail depending on withdraw amount.\n\t * Strongly consider placeAndTake: { enable: true, referrerInfo: undefined } when closing and withdrawing.\n\t */\n\tpublic async getCloseAndWithdrawIsolatedPerpPositionToWalletTxn(\n\t\tparams: CentralServerGetCloseAndWithdrawIsolatedPerpPositionToWalletTxnParams\n\t): Promise<VersionedTransaction | Transaction> {\n\t\tconst perpMarketConfig = this._perpMarketConfigs.find(\n\t\t\t(m) => m.marketIndex === params.marketIndex\n\t\t);\n\t\tif (!perpMarketConfig) {\n\t\t\tthrow new Error(\n\t\t\t\t`Perp market config not found for index ${params.marketIndex}`\n\t\t\t);\n\t\t}\n\t\treturn this.driftClientContextWrapper(\n\t\t\tparams.userAccountPublicKey,\n\t\t\tasync (user) => {\n\t\t\t\tconst signingAuthority = params.mainSignerOverride;\n\t\t\t\tconst subAccountId = user.getUserAccount().subAccountId;\n\n\t\t\t\tconst closeIxs = await createOpenPerpMarketOrderIxs({\n\t\t\t\t\tdriftClient: this._driftClient,\n\t\t\t\t\tuser,\n\t\t\t\t\tmarketIndex: params.marketIndex,\n\t\t\t\t\tdirection: params.direction,\n\t\t\t\t\tamount: params.baseAssetAmount,\n\t\t\t\t\tassetType: params.assetType ?? 'base',\n\t\t\t\t\treduceOnly: true,\n\t\t\t\t\tdlobServerHttpUrl: this._driftEndpoints.dlobServerHttpUrl,\n\t\t\t\t\tpositionMaxLeverage: 0,\n\t\t\t\t\tmainSignerOverride: signingAuthority,\n\t\t\t\t\tplaceAndTake: params.placeAndTake,\n\t\t\t\t});\n\n\t\t\t\tconst perpMarketAccount = this._driftClient.getPerpMarketAccount(\n\t\t\t\t\tparams.marketIndex\n\t\t\t\t);\n\t\t\t\tconst quoteSpotMarketIndex = perpMarketAccount.quoteSpotMarketIndex;\n\t\t\t\tconst spotMarketAccount =\n\t\t\t\t\tthis._driftClient.getSpotMarketAccount(quoteSpotMarketIndex);\n\t\t\t\tconst withdrawToAuthority =\n\t\t\t\t\tparams.mainSignerOverride ?? user.getUserAccount().authority;\n\t\t\t\tconst userTokenAccount = await getTokenAddressForDepositAndWithdraw(\n\t\t\t\t\tspotMarketAccount,\n\t\t\t\t\twithdrawToAuthority\n\t\t\t\t);\n\n\t\t\t\tconst withdrawAmount =\n\t\t\t\t\tparams.estimatedWithdrawAmount ??\n\t\t\t\t\tthis._driftClient.getIsolatedPerpPositionTokenAmount(\n\t\t\t\t\t\tparams.marketIndex,\n\t\t\t\t\t\tsubAccountId\n\t\t\t\t\t);\n\t\t\t\tconst withdrawIxs =\n\t\t\t\t\tawait this._driftClient.getWithdrawFromIsolatedPerpPositionIxsBundle(\n\t\t\t\t\t\twithdrawAmount,\n\t\t\t\t\t\tparams.marketIndex,\n\t\t\t\t\t\tsubAccountId,\n\t\t\t\t\t\tuserTokenAccount\n\t\t\t\t\t);\n\n\t\t\t\tconst ixs = [...closeIxs, ...withdrawIxs];\n\t\t\t\treturn this._driftClient.buildTransaction(\n\t\t\t\t\tixs,\n\t\t\t\t\tparams.txParams ?? this.getTxParams()\n\t\t\t\t);\n\t\t\t},\n\t\t\tparams.mainSignerOverride\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\tpositionMaxLeverage?: 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\tdriftClient: this._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\tdriftClient: this._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?: UnifiedQuoteResponse;\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\tconst swapClient = new UnifiedSwapClient({\n\t\t\t\t\tclientType: 'jupiter',\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 swapClient.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\tswapClient,\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\t/**\n\t * Create a transaction to initialize a RevenueShareEscrow account for a user.\n\t * Optionally bundles an initial builder approval in the same transaction.\n\t */\n\tpublic async getCreateRevenueShareEscrowTxn(\n\t\tauthority: PublicKey,\n\t\toptions?: {\n\t\t\tnumOrders?: number;\n\t\t\tbuilder?: {\n\t\t\t\tbuilderAuthority: PublicKey;\n\t\t\t\tmaxFeeTenthBps: number;\n\t\t\t};\n\t\t\ttxParams?: TxParams;\n\t\t}\n\t): Promise<VersionedTransaction | Transaction> {\n\t\treturn this.authorityContextWrapper(authority, () =>\n\t\t\tcreateRevenueShareEscrowTxn({\n\t\t\t\tdriftClient: this._driftClient,\n\t\t\t\tauthority,\n\t\t\t\tnumOrders: options?.numOrders ?? 16,\n\t\t\t\tbuilder: options?.builder,\n\t\t\t\ttxParams: options?.txParams ?? this.getTxParams(),\n\t\t\t})\n\t\t);\n\t}\n\n\t/**\n\t * Create a transaction to initialize a RevenueShare account for a builder.\n\t * This must be initialized before a builder can receive builder fees.\n\t */\n\tpublic async getCreateRevenueShareAccountTxn(\n\t\tauthority: PublicKey,\n\t\toptions?: {\n\t\t\ttxParams?: TxParams;\n\t\t}\n\t): Promise<VersionedTransaction | Transaction> {\n\t\treturn this.authorityContextWrapper(authority, () =>\n\t\t\tcreateRevenueShareAccountTxn({\n\t\t\t\tdriftClient: this._driftClient,\n\t\t\t\tauthority,\n\t\t\t\ttxParams: options?.txParams ?? this.getTxParams(),\n\t\t\t})\n\t\t);\n\t}\n\n\t/**\n\t * Create a transaction to configure a builder's approval status and fee cap.\n\t * Handles approve, update, and revoke operations.\n\t * Set maxFeeTenthBps to 0 to revoke a builder.\n\t */\n\tpublic async getConfigureApprovedBuilderTxn(\n\t\tauthority: PublicKey,\n\t\tbuilderAuthority: PublicKey,\n\t\tmaxFeeTenthBps: number,\n\t\toptions?: {\n\t\t\ttxParams?: TxParams;\n\t\t}\n\t): Promise<VersionedTransaction | Transaction> {\n\t\treturn this.authorityContextWrapper(authority, () =>\n\t\t\tconfigureBuilderTxn({\n\t\t\t\tdriftClient: this._driftClient,\n\t\t\t\tauthority,\n\t\t\t\tbuilderAuthority,\n\t\t\t\tmaxFeeTenthBps,\n\t\t\t\ttxParams: options?.txParams ?? this.getTxParams(),\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,15 +1,31 @@
1
1
  import { BN, PositionDirection, TxParams } from '@drift-labs/sdk';
2
- import { SwiftOrderOptions } from '../../../base/actions/trade/openPerpOrder/openSwiftOrder';
3
2
  import { WithTxnParams } from '../../../base/types';
4
- import { OpenPerpMarketOrderParams } from '../../../base/actions/trade/openPerpOrder/openPerpMarketOrder';
5
- import { OpenPerpNonMarketOrderParams } from '../../../base/actions/trade/openPerpOrder/openPerpNonMarketOrder';
6
- import { PlaceAndTakeParams } from '../../../base/actions/trade/openPerpOrder/types';
3
+ import { OpenPerpMarketOrderBaseParams } from '../../../base/actions/trade/openPerpOrder/openPerpMarketOrder';
4
+ import { OpenPerpNonMarketOrderBaseParams } from '../../../base/actions/trade/openPerpOrder/openPerpNonMarketOrder';
5
+ import { IsolatedPositionDepositsOverride, PlaceAndTakeParams } from '../../../base/actions/trade/openPerpOrder/types';
7
6
  import { PublicKey } from '@solana/web3.js';
8
- export type CentralServerSwiftOrderOptions = Omit<SwiftOrderOptions, 'swiftServerUrl'>;
9
- export type CentralServerGetOpenPerpMarketOrderTxnParams<T extends boolean = boolean> = WithTxnParams<Omit<OpenPerpMarketOrderParams<T, CentralServerSwiftOrderOptions>, 'driftClient' | 'user' | 'dlobServerHttpUrl'>> & {
10
- userAccountPublicKey: PublicKey;
7
+ export type CentralServerSwiftOrderOptions = {
8
+ userSigningSlotBuffer?: number;
9
+ isDelegate?: boolean;
11
10
  };
12
- export type CentralServerGetOpenPerpNonMarketOrderTxnParams<T extends boolean = boolean> = WithTxnParams<Omit<OpenPerpNonMarketOrderParams<T, CentralServerSwiftOrderOptions>, 'driftClient' | 'user' | 'dlobServerHttpUrl'>> & {
11
+ type CsdBaseMarketOrderParams = Omit<OpenPerpMarketOrderBaseParams, 'driftClient' | 'user' | 'dlobServerHttpUrl'>;
12
+ export type CentralServerGetOpenPerpMarketOrderTxnParams<T extends boolean = boolean> = T extends true ? Omit<CsdBaseMarketOrderParams, 'placeAndTake'> & {
13
+ useSwift: true;
14
+ swiftOptions?: CentralServerSwiftOrderOptions;
15
+ isolatedPositionDepositsOverride?: Omit<IsolatedPositionDepositsOverride, 'additionalDeposits'>;
16
+ userAccountPublicKey: PublicKey;
17
+ } : WithTxnParams<CsdBaseMarketOrderParams & {
18
+ useSwift: false;
19
+ userAccountPublicKey: PublicKey;
20
+ }>;
21
+ type CsdBaseNonMarketOrderParams = Omit<OpenPerpNonMarketOrderBaseParams, 'driftClient' | 'user'>;
22
+ export type CentralServerGetOpenPerpNonMarketOrderTxnParams<T extends boolean = boolean> = (T extends true ? CsdBaseNonMarketOrderParams & {
23
+ useSwift: true;
24
+ swiftOptions?: CentralServerSwiftOrderOptions;
25
+ isolatedPositionDepositsOverride?: Omit<IsolatedPositionDepositsOverride, 'additionalDeposits'>;
26
+ } : WithTxnParams<CsdBaseNonMarketOrderParams & {
27
+ useSwift: false;
28
+ }>) & {
13
29
  userAccountPublicKey: PublicKey;
14
30
  };
15
31
  /** Params for withdrawing collateral from an isolated perp position (transfer to cross). */
@@ -22,7 +38,7 @@ export interface CentralServerGetWithdrawIsolatedPerpPositionCollateralTxnParams
22
38
  isFullWithdrawal?: boolean;
23
39
  /** If true, prepends settle PnL ix before transfer (recommended for full withdrawal or when position base is zero). */
24
40
  settlePnlFirst?: boolean;
25
- txParams?: import('@drift-labs/sdk').TxParams;
41
+ txParams?: TxParams;
26
42
  /** Optional signer override for transaction signing; defaults to user authority. */
27
43
  mainSignerOverride?: PublicKey;
28
44
  }
@@ -45,7 +61,7 @@ export interface CentralServerGetCloseAndWithdrawIsolatedPerpPositionTxnParams {
45
61
  mainSignerOverride?: PublicKey;
46
62
  }
47
63
  /** Params for deposit from wallet + open isolated perp position (wallet → isolated → place). */
48
- export interface CentralServerGetDepositAndOpenIsolatedPerpPositionTxnParams extends Omit<CentralServerGetOpenPerpMarketOrderTxnParams<false>, 'isolatedPositionDeposit'> {
64
+ export interface CentralServerGetDepositAndOpenIsolatedPerpPositionTxnParams extends Omit<CentralServerGetOpenPerpMarketOrderTxnParams<false>, 'isolatedPositionDepositsOverride' | 'useSwift' | 'marginMode'> {
49
65
  /** Amount to deposit from wallet directly into isolated (QUOTE_PRECISION, e.g. USDC). */
50
66
  depositAmount: BN;
51
67
  }
@@ -68,3 +84,4 @@ export interface CentralServerGetCloseAndWithdrawIsolatedPerpPositionToWalletTxn
68
84
  /** Optional signer override and withdrawal destination; when provided, used for signing and as the wallet that receives the withdrawal; defaults to user authority. */
69
85
  mainSignerOverride?: PublicKey;
70
86
  }
87
+ export {};
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/drift/Drift/clients/CentralServerDrift/types.ts"],"names":[],"mappings":"","sourcesContent":["import { BN, PositionDirection, TxParams } from '@drift-labs/sdk';\nimport { SwiftOrderOptions } from '../../../base/actions/trade/openPerpOrder/openSwiftOrder';\nimport { WithTxnParams } from '../../../base/types';\nimport { OpenPerpMarketOrderParams } from '../../../base/actions/trade/openPerpOrder/openPerpMarketOrder';\nimport { OpenPerpNonMarketOrderParams } from '../../../base/actions/trade/openPerpOrder/openPerpNonMarketOrder';\nimport { PlaceAndTakeParams } from '../../../base/actions/trade/openPerpOrder/types';\nimport { PublicKey } from '@solana/web3.js';\n\nexport type CentralServerSwiftOrderOptions = Omit<\n\tSwiftOrderOptions,\n\t'swiftServerUrl'\n>;\n\nexport type CentralServerGetOpenPerpMarketOrderTxnParams<\n\tT extends boolean = boolean\n> = WithTxnParams<\n\tOmit<\n\t\tOpenPerpMarketOrderParams<T, CentralServerSwiftOrderOptions>,\n\t\t'driftClient' | 'user' | 'dlobServerHttpUrl'\n\t>\n> & {\n\tuserAccountPublicKey: PublicKey;\n};\n\nexport type CentralServerGetOpenPerpNonMarketOrderTxnParams<\n\tT extends boolean = boolean\n> = WithTxnParams<\n\tOmit<\n\t\tOpenPerpNonMarketOrderParams<T, CentralServerSwiftOrderOptions>,\n\t\t'driftClient' | 'user' | 'dlobServerHttpUrl'\n\t>\n> & {\n\tuserAccountPublicKey: PublicKey;\n};\n\n/** Params for withdrawing collateral from an isolated perp position (transfer to cross). */\nexport interface CentralServerGetWithdrawIsolatedPerpPositionCollateralTxnParams {\n\tuserAccountPublicKey: PublicKey;\n\tmarketIndex: number;\n\t/** Positive amount to withdraw in QUOTE_PRECISION. Ignored when isFullWithdrawal is true. */\n\tamount: BN;\n\t/** If true, transfers all available isolated margin (use when position is closed). Prepends settle PnL ix. */\n\tisFullWithdrawal?: boolean;\n\t/** If true, prepends settle PnL ix before transfer (recommended for full withdrawal or when position base is zero). */\n\tsettlePnlFirst?: boolean;\n\ttxParams?: import('@drift-labs/sdk').TxParams;\n\t/** Optional signer override for transaction signing; defaults to user authority. */\n\tmainSignerOverride?: PublicKey;\n}\n\n/** Params for single-tx close + withdraw (best-effort; fill-dependent). */\nexport interface CentralServerGetCloseAndWithdrawIsolatedPerpPositionTxnParams {\n\tuserAccountPublicKey: PublicKey;\n\tmarketIndex: number;\n\t/** Base asset amount to close. */\n\tbaseAssetAmount: BN;\n\t/** Direction of the close order (opposite of position). */\n\tdirection: PositionDirection;\n\t/** If true, includes collateral transfer ix after close order (will withdraw available isolated margin; amount is fill-dependent). */\n\twithdrawCollateralAfterClose?: boolean;\n\t/** If true and withdrawCollateralAfterClose, prepends settle PnL ix. */\n\tsettlePnlBeforeClose?: boolean;\n\tassetType?: 'base' | 'quote';\n\tplaceAndTake?: PlaceAndTakeParams;\n\ttxParams?: TxParams;\n\t/** Optional signer override for transaction signing; defaults to user authority. */\n\tmainSignerOverride?: PublicKey;\n}\n\n/** Params for deposit from wallet + open isolated perp position (wallet → isolated → place). */\nexport interface CentralServerGetDepositAndOpenIsolatedPerpPositionTxnParams\n\textends Omit<\n\t\tCentralServerGetOpenPerpMarketOrderTxnParams<false>,\n\t\t'isolatedPositionDeposit'\n\t> {\n\t/** Amount to deposit from wallet directly into isolated (QUOTE_PRECISION, e.g. USDC). */\n\tdepositAmount: BN;\n}\n\n/** Params for close isolated position + withdraw to wallet (close → withdraw from isolated to wallet). */\nexport interface CentralServerGetCloseAndWithdrawIsolatedPerpPositionToWalletTxnParams {\n\tuserAccountPublicKey: PublicKey;\n\tmarketIndex: number;\n\t/** Base asset amount to close. */\n\tbaseAssetAmount: BN;\n\t/** Direction of the close order (opposite of position). */\n\tdirection: PositionDirection;\n\t/**\n\t * Amount to withdraw (QUOTE_PRECISION). When omitted or larger than available,\n\t * the SDK withdraws all. Pass a specific amount for partial withdrawal.\n\t */\n\testimatedWithdrawAmount?: BN;\n\tassetType?: 'base' | 'quote';\n\tplaceAndTake?: PlaceAndTakeParams;\n\ttxParams?: TxParams;\n\t/** Optional signer override and withdrawal destination; when provided, used for signing and as the wallet that receives the withdrawal; defaults to user authority. */\n\tmainSignerOverride?: PublicKey;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/drift/Drift/clients/CentralServerDrift/types.ts"],"names":[],"mappings":"","sourcesContent":["import { BN, PositionDirection, TxParams } from '@drift-labs/sdk';\nimport { WithTxnParams } from '../../../base/types';\nimport { OpenPerpMarketOrderBaseParams } from '../../../base/actions/trade/openPerpOrder/openPerpMarketOrder';\nimport { OpenPerpNonMarketOrderBaseParams } from '../../../base/actions/trade/openPerpOrder/openPerpNonMarketOrder';\nimport {\n\tIsolatedPositionDepositsOverride,\n\tPlaceAndTakeParams,\n} from '../../../base/actions/trade/openPerpOrder/types';\nimport { PublicKey } from '@solana/web3.js';\n\nexport type CentralServerSwiftOrderOptions = {\n\tuserSigningSlotBuffer?: number;\n\tisDelegate?: boolean;\n};\n\ntype CsdBaseMarketOrderParams = Omit<\n\tOpenPerpMarketOrderBaseParams,\n\t'driftClient' | 'user' | 'dlobServerHttpUrl'\n>;\n\nexport type CentralServerGetOpenPerpMarketOrderTxnParams<\n\tT extends boolean = boolean\n> = T extends true\n\t? Omit<CsdBaseMarketOrderParams, 'placeAndTake'> & {\n\t\t\tuseSwift: true;\n\t\t\tswiftOptions?: CentralServerSwiftOrderOptions;\n\t\t\tisolatedPositionDepositsOverride?: Omit<\n\t\t\t\tIsolatedPositionDepositsOverride,\n\t\t\t\t'additionalDeposits'\n\t\t\t>;\n\t\t\tuserAccountPublicKey: PublicKey;\n\t }\n\t: WithTxnParams<\n\t\t\tCsdBaseMarketOrderParams & {\n\t\t\t\tuseSwift: false;\n\t\t\t\tuserAccountPublicKey: PublicKey;\n\t\t\t}\n\t >;\n\ntype CsdBaseNonMarketOrderParams = Omit<\n\tOpenPerpNonMarketOrderBaseParams,\n\t'driftClient' | 'user'\n>;\n\nexport type CentralServerGetOpenPerpNonMarketOrderTxnParams<\n\tT extends boolean = boolean\n> = (T extends true\n\t? CsdBaseNonMarketOrderParams & {\n\t\t\tuseSwift: true;\n\t\t\tswiftOptions?: CentralServerSwiftOrderOptions;\n\t\t\tisolatedPositionDepositsOverride?: Omit<\n\t\t\t\tIsolatedPositionDepositsOverride,\n\t\t\t\t'additionalDeposits'\n\t\t\t>;\n\t }\n\t: WithTxnParams<\n\t\t\tCsdBaseNonMarketOrderParams & {\n\t\t\t\tuseSwift: false;\n\t\t\t}\n\t >) & {\n\tuserAccountPublicKey: PublicKey;\n};\n\n/** Params for withdrawing collateral from an isolated perp position (transfer to cross). */\nexport interface CentralServerGetWithdrawIsolatedPerpPositionCollateralTxnParams {\n\tuserAccountPublicKey: PublicKey;\n\tmarketIndex: number;\n\t/** Positive amount to withdraw in QUOTE_PRECISION. Ignored when isFullWithdrawal is true. */\n\tamount: BN;\n\t/** If true, transfers all available isolated margin (use when position is closed). Prepends settle PnL ix. */\n\tisFullWithdrawal?: boolean;\n\t/** If true, prepends settle PnL ix before transfer (recommended for full withdrawal or when position base is zero). */\n\tsettlePnlFirst?: boolean;\n\ttxParams?: TxParams;\n\t/** Optional signer override for transaction signing; defaults to user authority. */\n\tmainSignerOverride?: PublicKey;\n}\n\n/** Params for single-tx close + withdraw (best-effort; fill-dependent). */\nexport interface CentralServerGetCloseAndWithdrawIsolatedPerpPositionTxnParams {\n\tuserAccountPublicKey: PublicKey;\n\tmarketIndex: number;\n\t/** Base asset amount to close. */\n\tbaseAssetAmount: BN;\n\t/** Direction of the close order (opposite of position). */\n\tdirection: PositionDirection;\n\t/** If true, includes collateral transfer ix after close order (will withdraw available isolated margin; amount is fill-dependent). */\n\twithdrawCollateralAfterClose?: boolean;\n\t/** If true and withdrawCollateralAfterClose, prepends settle PnL ix. */\n\tsettlePnlBeforeClose?: boolean;\n\tassetType?: 'base' | 'quote';\n\tplaceAndTake?: PlaceAndTakeParams;\n\ttxParams?: TxParams;\n\t/** Optional signer override for transaction signing; defaults to user authority. */\n\tmainSignerOverride?: PublicKey;\n}\n\n/** Params for deposit from wallet + open isolated perp position (wallet → isolated → place). */\nexport interface CentralServerGetDepositAndOpenIsolatedPerpPositionTxnParams\n\textends Omit<\n\t\tCentralServerGetOpenPerpMarketOrderTxnParams<false>,\n\t\t'isolatedPositionDepositsOverride' | 'useSwift' | 'marginMode'\n\t> {\n\t/** Amount to deposit from wallet directly into isolated (QUOTE_PRECISION, e.g. USDC). */\n\tdepositAmount: BN;\n}\n\n/** Params for close isolated position + withdraw to wallet (close → withdraw from isolated to wallet). */\nexport interface CentralServerGetCloseAndWithdrawIsolatedPerpPositionToWalletTxnParams {\n\tuserAccountPublicKey: PublicKey;\n\tmarketIndex: number;\n\t/** Base asset amount to close. */\n\tbaseAssetAmount: BN;\n\t/** Direction of the close order (opposite of position). */\n\tdirection: PositionDirection;\n\t/**\n\t * Amount to withdraw (QUOTE_PRECISION). When omitted or larger than available,\n\t * the SDK withdraws all. Pass a specific amount for partial withdrawal.\n\t */\n\testimatedWithdrawAmount?: BN;\n\tassetType?: 'base' | 'quote';\n\tplaceAndTake?: PlaceAndTakeParams;\n\ttxParams?: TxParams;\n\t/** Optional signer override and withdrawal destination; when provided, used for signing and as the wallet that receives the withdrawal; defaults to user authority. */\n\tmainSignerOverride?: PublicKey;\n}\n"]}
@@ -1,5 +1,6 @@
1
1
  import { BN, DriftClient, User, PositionDirection } from '@drift-labs/sdk';
2
2
  import { PublicKey, TransactionInstruction } from '@solana/web3.js';
3
+ import { AdditionalIsolatedPositionDeposit, IsolatedPositionDepositsOverride } from './types';
3
4
  export declare const ISOLATED_POSITION_DEPOSIT_BUFFER_BPS = 15;
4
5
  export interface IsolatedMarginShortfall {
5
6
  marketIndex: number;
@@ -74,10 +75,64 @@ export interface ComputeIsolatedPositionDepositParams {
74
75
  * will be added to the deposit amount.
75
76
  */
76
77
  includeExistingShortfall?: boolean;
78
+ /**
79
+ * Pre-computed existing shortfall for the current market.
80
+ * When provided alongside includeExistingShortfall, avoids a redundant getMarginCalculation call.
81
+ */
82
+ existingShortfall?: BN;
77
83
  }
78
84
  /**
79
85
  * Computes the isolated position deposit required for opening an isolated perp position.
80
86
  * Returns a BN in QUOTE_PRECISION (USDC).
81
87
  */
82
- export declare function computeIsolatedPositionDepositForTrade({ driftClient, user, marketIndex, baseAssetAmount, direction, marginRatio, entryPrice, numOfOpenHighLeverageSpots, bufferDenominator, includeExistingShortfall, }: ComputeIsolatedPositionDepositParams): BN | null;
88
+ export declare function computeIsolatedPositionDepositForTrade({ driftClient, user, marketIndex, baseAssetAmount, direction, marginRatio, entryPrice, numOfOpenHighLeverageSpots, bufferDenominator, includeExistingShortfall, existingShortfall: precomputedShortfall, }: ComputeIsolatedPositionDepositParams): BN | null;
89
+ /**
90
+ * Error thrown when underwater isolated positions are detected and
91
+ * replenishUnderwaterPositions is not set to true.
92
+ */
93
+ export declare class UnderwaterIsolatedPositionsError extends Error {
94
+ readonly shortfalls: IsolatedMarginShortfall[];
95
+ constructor(shortfalls: IsolatedMarginShortfall[]);
96
+ }
97
+ /**
98
+ * Calculates isolated position deposits for a trade.
99
+ * Auto-computes the main deposit from positionMaxLeverage.
100
+ * Also detects underwater positions on other markets and either throws or computes additional deposits.
101
+ */
102
+ export declare function calculateIsolatedPositionDeposits(params: {
103
+ driftClient: DriftClient;
104
+ user: User;
105
+ marketIndex: number;
106
+ baseAssetAmount: BN;
107
+ direction?: PositionDirection;
108
+ positionMaxLeverage: number;
109
+ replenishUnderwaterPositions?: boolean;
110
+ numOfOpenHighLeverageSpots?: number;
111
+ }): {
112
+ mainDeposit: BN | undefined;
113
+ additionalIsolatedPositionDeposits: AdditionalIsolatedPositionDeposit[] | undefined;
114
+ };
115
+ /**
116
+ * Resolves isolated position deposits based on margin mode.
117
+ * Returns undefined for cross margin mode, otherwise computes deposits.
118
+ *
119
+ * If marginMode is not explicitly provided, derives it from the user's existing position.
120
+ */
121
+ export declare function resolveIsolatedPositionDeposits(params: {
122
+ driftClient: DriftClient;
123
+ user: User;
124
+ marketIndex: number;
125
+ baseAssetAmount: BN;
126
+ direction?: PositionDirection;
127
+ positionMaxLeverage: number;
128
+ marginMode?: 'isolated' | 'cross';
129
+ replenishUnderwaterPositions?: boolean;
130
+ numOfOpenHighLeverageSpots?: number;
131
+ }): ReturnType<typeof calculateIsolatedPositionDeposits> | undefined;
132
+ /**
133
+ * Resolves isolated position deposits, using pre-computed overrides if provided.
134
+ * When `isolatedPositionDepositsOverride` is provided, skips auto-compute and uses
135
+ * the override values directly. Otherwise, delegates to `resolveIsolatedPositionDeposits()`.
136
+ */
137
+ export declare function resolveIsolatedPositionDepositsWithOverride(override: IsolatedPositionDepositsOverride | undefined, computeParams: Parameters<typeof resolveIsolatedPositionDeposits>[0]): ReturnType<typeof resolveIsolatedPositionDeposits>;
83
138
  export declare function getIsolatedPositionDepositIxIfNeeded(driftClient: DriftClient, user: User, marketIndex: number, isolatedPositionDeposit?: BN, signingAuthority?: PublicKey): Promise<TransactionInstruction | undefined>;
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getIsolatedPositionDepositIxIfNeeded = exports.computeIsolatedPositionDepositForTrade = exports.getTotalIsolatedMarginShortfall = exports.getOtherIsolatedMarginShortfalls = exports.getIsolatedMarginShortfall = exports.getIsolatedMarginShortfalls = exports.ISOLATED_POSITION_DEPOSIT_BUFFER_BPS = void 0;
3
+ exports.getIsolatedPositionDepositIxIfNeeded = exports.resolveIsolatedPositionDepositsWithOverride = exports.resolveIsolatedPositionDeposits = exports.calculateIsolatedPositionDeposits = exports.UnderwaterIsolatedPositionsError = exports.computeIsolatedPositionDepositForTrade = exports.getTotalIsolatedMarginShortfall = exports.getOtherIsolatedMarginShortfalls = exports.getIsolatedMarginShortfall = exports.getIsolatedMarginShortfalls = exports.ISOLATED_POSITION_DEPOSIT_BUFFER_BPS = void 0;
4
4
  const sdk_1 = require("@drift-labs/sdk");
5
+ const trading_1 = require("../../../../../common-ui-utils/trading");
6
+ const positionMarginMode_1 = require("../../../details/user/positionMarginMode");
5
7
  exports.ISOLATED_POSITION_DEPOSIT_BUFFER_BPS = 15;
6
8
  /**
7
9
  * Computes the initial margin shortfall for all isolated perp positions.
@@ -62,7 +64,7 @@ exports.getTotalIsolatedMarginShortfall = getTotalIsolatedMarginShortfall;
62
64
  * Computes the isolated position deposit required for opening an isolated perp position.
63
65
  * Returns a BN in QUOTE_PRECISION (USDC).
64
66
  */
65
- function computeIsolatedPositionDepositForTrade({ driftClient, user, marketIndex, baseAssetAmount, direction, marginRatio, entryPrice, numOfOpenHighLeverageSpots, bufferDenominator, includeExistingShortfall, }) {
67
+ function computeIsolatedPositionDepositForTrade({ driftClient, user, marketIndex, baseAssetAmount, direction, marginRatio, entryPrice, numOfOpenHighLeverageSpots, bufferDenominator, includeExistingShortfall, existingShortfall: precomputedShortfall, }) {
66
68
  var _a;
67
69
  // Only require isolated deposit if the order will increase the position (when direction is provided)
68
70
  if (direction !== undefined) {
@@ -83,10 +85,10 @@ function computeIsolatedPositionDepositForTrade({ driftClient, user, marketIndex
83
85
  const hasOpenHighLeverageSpots = numOfOpenHighLeverageSpots !== undefined && numOfOpenHighLeverageSpots > 0;
84
86
  const enteringHighLeverageMode = userIsInHighLeverageMode || hasOpenHighLeverageSpots;
85
87
  const marginRequired = (0, sdk_1.calculateMarginUSDCRequiredForTrade)(driftClient, marketIndex, baseAssetAmount, marginRatio, enteringHighLeverageMode, entryPrice);
86
- let depositAmount = marginRequired.add(marginRequired.div(new sdk_1.BN(bufferDenominator !== null && bufferDenominator !== void 0 ? bufferDenominator : exports.ISOLATED_POSITION_DEPOSIT_BUFFER_BPS))); // buffer in basis points
88
+ let depositAmount = marginRequired.add(marginRequired.div(new sdk_1.BN(bufferDenominator !== null && bufferDenominator !== void 0 ? bufferDenominator : exports.ISOLATED_POSITION_DEPOSIT_BUFFER_BPS)));
87
89
  // Add existing shortfall for this market if requested
88
90
  if (includeExistingShortfall) {
89
- const existingShortfall = getIsolatedMarginShortfall(user, marketIndex);
91
+ const existingShortfall = precomputedShortfall !== null && precomputedShortfall !== void 0 ? precomputedShortfall : getIsolatedMarginShortfall(user, marketIndex);
90
92
  if (existingShortfall.gt(sdk_1.ZERO)) {
91
93
  // Add shortfall with a 5% buffer on top (same as new margin)
92
94
  const shortfallWithBuffer = existingShortfall.add(existingShortfall.div(new sdk_1.BN(bufferDenominator !== null && bufferDenominator !== void 0 ? bufferDenominator : exports.ISOLATED_POSITION_DEPOSIT_BUFFER_BPS)));
@@ -96,6 +98,102 @@ function computeIsolatedPositionDepositForTrade({ driftClient, user, marketIndex
96
98
  return depositAmount;
97
99
  }
98
100
  exports.computeIsolatedPositionDepositForTrade = computeIsolatedPositionDepositForTrade;
101
+ /**
102
+ * Error thrown when underwater isolated positions are detected and
103
+ * replenishUnderwaterPositions is not set to true.
104
+ */
105
+ class UnderwaterIsolatedPositionsError extends Error {
106
+ constructor(shortfalls) {
107
+ super(`Underwater isolated positions detected for markets: ${shortfalls
108
+ .map((s) => s.marketIndex)
109
+ .join(', ')}. ` +
110
+ `Set replenishUnderwaterPositions: true to auto-cover, or manually handle shortfalls.`);
111
+ this.shortfalls = shortfalls;
112
+ this.name = 'UnderwaterIsolatedPositionsError';
113
+ }
114
+ }
115
+ exports.UnderwaterIsolatedPositionsError = UnderwaterIsolatedPositionsError;
116
+ /**
117
+ * Calculates isolated position deposits for a trade.
118
+ * Auto-computes the main deposit from positionMaxLeverage.
119
+ * Also detects underwater positions on other markets and either throws or computes additional deposits.
120
+ */
121
+ function calculateIsolatedPositionDeposits(params) {
122
+ var _a;
123
+ // Compute all shortfalls once (single getMarginCalculation call)
124
+ // to avoid duplicate expensive margin calculations
125
+ const allShortfalls = getIsolatedMarginShortfalls(params.user);
126
+ // Extract current market's shortfall from the pre-computed map
127
+ const currentMarketShortfall = (_a = allShortfalls.get(params.marketIndex)) !== null && _a !== void 0 ? _a : sdk_1.ZERO;
128
+ let mainIsolatedPositionDeposit;
129
+ const marginRatio = trading_1.TRADING_UTILS.convertLeverageToMarginRatio(params.positionMaxLeverage);
130
+ if (marginRatio) {
131
+ mainIsolatedPositionDeposit = computeIsolatedPositionDepositForTrade({
132
+ driftClient: params.driftClient,
133
+ user: params.user,
134
+ marketIndex: params.marketIndex,
135
+ baseAssetAmount: params.baseAssetAmount,
136
+ direction: params.direction,
137
+ marginRatio,
138
+ numOfOpenHighLeverageSpots: params.numOfOpenHighLeverageSpots,
139
+ bufferDenominator: exports.ISOLATED_POSITION_DEPOSIT_BUFFER_BPS,
140
+ includeExistingShortfall: true,
141
+ // Use pre-computed shortfall to avoid a second getMarginCalculation call
142
+ existingShortfall: currentMarketShortfall,
143
+ });
144
+ }
145
+ // Check for underwater positions (excluding current market)
146
+ const otherShortfalls = Array.from(allShortfalls)
147
+ .filter(([marketIndex]) => marketIndex !== params.marketIndex)
148
+ .map(([marketIndex, shortfall]) => ({ marketIndex, shortfall }));
149
+ if (otherShortfalls.length > 0 && !params.replenishUnderwaterPositions) {
150
+ throw new UnderwaterIsolatedPositionsError(otherShortfalls);
151
+ }
152
+ let additionalIsolatedPositionDeposits;
153
+ if (otherShortfalls.length > 0 && params.replenishUnderwaterPositions) {
154
+ additionalIsolatedPositionDeposits = otherShortfalls.map((shortfall) => {
155
+ const shortfallWithBuffer = shortfall.shortfall.add(shortfall.shortfall.div(new sdk_1.BN(exports.ISOLATED_POSITION_DEPOSIT_BUFFER_BPS)));
156
+ return {
157
+ marketIndex: shortfall.marketIndex,
158
+ amount: shortfallWithBuffer,
159
+ };
160
+ });
161
+ }
162
+ return {
163
+ mainDeposit: mainIsolatedPositionDeposit,
164
+ additionalIsolatedPositionDeposits,
165
+ };
166
+ }
167
+ exports.calculateIsolatedPositionDeposits = calculateIsolatedPositionDeposits;
168
+ /**
169
+ * Resolves isolated position deposits based on margin mode.
170
+ * Returns undefined for cross margin mode, otherwise computes deposits.
171
+ *
172
+ * If marginMode is not explicitly provided, derives it from the user's existing position.
173
+ */
174
+ function resolveIsolatedPositionDeposits(params) {
175
+ var _a;
176
+ const isIsolated = ((_a = params.marginMode) !== null && _a !== void 0 ? _a : (0, positionMarginMode_1.getPositionMarginMode)(params.user, params.marketIndex)) === 'isolated';
177
+ if (!isIsolated)
178
+ return undefined;
179
+ return calculateIsolatedPositionDeposits(params);
180
+ }
181
+ exports.resolveIsolatedPositionDeposits = resolveIsolatedPositionDeposits;
182
+ /**
183
+ * Resolves isolated position deposits, using pre-computed overrides if provided.
184
+ * When `isolatedPositionDepositsOverride` is provided, skips auto-compute and uses
185
+ * the override values directly. Otherwise, delegates to `resolveIsolatedPositionDeposits()`.
186
+ */
187
+ function resolveIsolatedPositionDepositsWithOverride(override, computeParams) {
188
+ if (override !== undefined) {
189
+ return {
190
+ mainDeposit: override.mainDeposit,
191
+ additionalIsolatedPositionDeposits: override.additionalDeposits,
192
+ };
193
+ }
194
+ return resolveIsolatedPositionDeposits(computeParams);
195
+ }
196
+ exports.resolveIsolatedPositionDepositsWithOverride = resolveIsolatedPositionDepositsWithOverride;
99
197
  async function getIsolatedPositionDepositIxIfNeeded(driftClient, user, marketIndex, isolatedPositionDeposit, signingAuthority) {
100
198
  if (!isolatedPositionDeposit) {
101
199
  return undefined;