@drift-labs/common 1.0.43 → 1.0.44

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.
@@ -37,6 +37,18 @@ export declare class CentralServerDrift {
37
37
  get driftClient(): DriftClient;
38
38
  subscribe(): Promise<void>;
39
39
  unsubscribe(): Promise<void>;
40
+ /**
41
+ * Temporarily swaps the DriftClient wallet/authority context to build transactions
42
+ * for a given authority, then restores the original state.
43
+ *
44
+ * Use this for authority-based operations that don't require a User account subscription
45
+ * (e.g. creating revenue share accounts, managing builders).
46
+ *
47
+ * @param authority - The authority to set on the DriftClient
48
+ * @param operation - The transaction creation operation to execute
49
+ * @returns The result of the operation
50
+ */
51
+ private authorityContextWrapper;
40
52
  /**
41
53
  * Manages DriftClient state for transaction creation with proper setup and cleanup.
42
54
  * This abstraction handles:
@@ -146,5 +158,32 @@ export declare class CentralServerDrift {
146
158
  onlyDirectRoutes?: boolean;
147
159
  quote?: UnifiedQuoteResponse;
148
160
  }): Promise<VersionedTransaction | Transaction>;
161
+ /**
162
+ * Create a transaction to initialize a RevenueShareEscrow account for a user.
163
+ * Optionally bundles an initial builder approval in the same transaction.
164
+ */
165
+ getCreateRevenueShareEscrowTxn(authority: PublicKey, options?: {
166
+ numOrders?: number;
167
+ builder?: {
168
+ builderAuthority: PublicKey;
169
+ maxFeeTenthBps: number;
170
+ };
171
+ txParams?: TxParams;
172
+ }): Promise<VersionedTransaction | Transaction>;
173
+ /**
174
+ * Create a transaction to initialize a RevenueShare account for a builder.
175
+ * This must be initialized before a builder can receive builder fees.
176
+ */
177
+ getCreateRevenueShareAccountTxn(authority: PublicKey, options?: {
178
+ txParams?: TxParams;
179
+ }): Promise<VersionedTransaction | Transaction>;
180
+ /**
181
+ * Create a transaction to configure a builder's approval status and fee cap.
182
+ * Handles approve, update, and revoke operations.
183
+ * Set maxFeeTenthBps to 0 to revoke a builder.
184
+ */
185
+ getConfigureApprovedBuilderTxn(authority: PublicKey, builderAuthority: PublicKey, maxFeeTenthBps: number, options?: {
186
+ txParams?: TxParams;
187
+ }): Promise<VersionedTransaction | Transaction>;
149
188
  sendSignedTransaction(tx: VersionedTransaction | Transaction): Promise<import("@drift-labs/sdk").TxSigAndSlot>;
150
189
  }
@@ -16,6 +16,9 @@ const cancelOrder_1 = require("../../../base/actions/trade/cancelOrder");
16
16
  const swap_1 = require("../../../base/actions/trade/swap");
17
17
  const create_1 = require("../../../base/actions/user/create");
18
18
  const delete_1 = require("../../../base/actions/user/delete");
19
+ const createRevenueShareEscrow_1 = require("../../../base/actions/builder/createRevenueShareEscrow");
20
+ const createRevenueShareAccount_1 = require("../../../base/actions/builder/createRevenueShareAccount");
21
+ const configureBuilder_1 = require("../../../base/actions/builder/configureBuilder");
19
22
  const EnvironmentConstants_1 = require("../../../../EnvironmentConstants");
20
23
  const markets_1 = require("./markets");
21
24
  const DriftOperations_1 = require("../AuthorityDrift/DriftOperations");
@@ -99,6 +102,41 @@ class CentralServerDrift {
99
102
  await this._driftClient.unsubscribe();
100
103
  await this.priorityFeeSubscriber.unsubscribe();
101
104
  }
105
+ /**
106
+ * Temporarily swaps the DriftClient wallet/authority context to build transactions
107
+ * for a given authority, then restores the original state.
108
+ *
109
+ * Use this for authority-based operations that don't require a User account subscription
110
+ * (e.g. creating revenue share accounts, managing builders).
111
+ *
112
+ * @param authority - The authority to set on the DriftClient
113
+ * @param operation - The transaction creation operation to execute
114
+ * @returns The result of the operation
115
+ */
116
+ async authorityContextWrapper(authority, operation) {
117
+ const originalWallet = this._driftClient.wallet;
118
+ const originalAuthority = this._driftClient.authority;
119
+ const authorityWallet = {
120
+ publicKey: authority,
121
+ signTransaction: () => Promise.reject('This is a placeholder - do not sign with this wallet'),
122
+ signAllTransactions: () => Promise.reject('This is a placeholder - do not sign with this wallet'),
123
+ };
124
+ try {
125
+ this._driftClient.wallet = authorityWallet;
126
+ // @ts-ignore
127
+ this._driftClient.provider.wallet = authorityWallet;
128
+ this._driftClient.txHandler.updateWallet(authorityWallet);
129
+ this._driftClient.authority = authority;
130
+ return await operation();
131
+ }
132
+ finally {
133
+ this._driftClient.wallet = originalWallet;
134
+ this._driftClient.txHandler.updateWallet(originalWallet);
135
+ // @ts-ignore
136
+ this._driftClient.provider.wallet = originalWallet;
137
+ this._driftClient.authority = originalAuthority;
138
+ }
139
+ }
102
140
  /**
103
141
  * Manages DriftClient state for transaction creation with proper setup and cleanup.
104
142
  * This abstraction handles:
@@ -198,26 +236,14 @@ class CentralServerDrift {
198
236
  };
199
237
  }
200
238
  async getCreateAndDepositTxn(authority, amount, spotMarketIndex, options) {
201
- var _a, _b;
239
+ var _a;
202
240
  const spotMarketConfig = this._spotMarketConfigs.find((market) => market.marketIndex === spotMarketIndex);
203
241
  if (!spotMarketConfig) {
204
242
  throw new Error(`Spot market config not found for index ${spotMarketIndex}`);
205
243
  }
206
244
  const userStatsAccount = await (0, sdk_1.fetchUserStatsAccount)(this._driftClient.connection, this._driftClient.program, authority);
207
- const originalWallet = this._driftClient.wallet;
208
- const originalAuthority = this._driftClient.authority;
209
- // Use external wallet for transaction signing context if provided
210
- const walletPublicKey = (_a = options === null || options === void 0 ? void 0 : options.externalWallet) !== null && _a !== void 0 ? _a : authority;
211
- const authorityWallet = {
212
- publicKey: walletPublicKey,
213
- signTransaction: () => Promise.reject('This is a placeholder - do not sign with this wallet'),
214
- signAllTransactions: () => Promise.reject('This is a placeholder - do not sign with this wallet'),
215
- };
216
- try {
217
- this._driftClient.wallet = authorityWallet;
218
- // @ts-ignore
219
- this._driftClient.provider.wallet = authorityWallet;
220
- this._driftClient.txHandler.updateWallet(authorityWallet);
245
+ return this.authorityContextWrapper((_a = options === null || options === void 0 ? void 0 : options.externalWallet) !== null && _a !== void 0 ? _a : authority, async () => {
246
+ var _a;
221
247
  this._driftClient.authority = authority;
222
248
  // Clear userStatsAccountPublicKey cache so it's recalculated for the new authority
223
249
  // @ts-ignore - accessing private property for cache invalidation
@@ -233,17 +259,10 @@ class CentralServerDrift {
233
259
  poolId: options === null || options === void 0 ? void 0 : options.poolId,
234
260
  fromSubAccountId: options === null || options === void 0 ? void 0 : options.fromSubAccountId,
235
261
  customMaxMarginRatio: options === null || options === void 0 ? void 0 : options.customMaxMarginRatio,
236
- txParams: (_b = options === null || options === void 0 ? void 0 : options.txParams) !== null && _b !== void 0 ? _b : this.getTxParams(),
262
+ txParams: (_a = options === null || options === void 0 ? void 0 : options.txParams) !== null && _a !== void 0 ? _a : this.getTxParams(),
237
263
  externalWallet: options === null || options === void 0 ? void 0 : options.externalWallet,
238
264
  });
239
- }
240
- finally {
241
- this._driftClient.wallet = originalWallet;
242
- this._driftClient.txHandler.updateWallet(originalWallet);
243
- // @ts-ignore
244
- this._driftClient.provider.wallet = originalWallet;
245
- this._driftClient.authority = originalAuthority;
246
- }
265
+ });
247
266
  }
248
267
  async getDepositTxn(userAccountPublicKey, amount, spotMarketIndex, options) {
249
268
  return this.driftClientContextWrapper(userAccountPublicKey, async (user) => {
@@ -461,6 +480,53 @@ class CentralServerDrift {
461
480
  return swapTxn;
462
481
  });
463
482
  }
483
+ /**
484
+ * Create a transaction to initialize a RevenueShareEscrow account for a user.
485
+ * Optionally bundles an initial builder approval in the same transaction.
486
+ */
487
+ async getCreateRevenueShareEscrowTxn(authority, options) {
488
+ return this.authorityContextWrapper(authority, () => {
489
+ var _a, _b;
490
+ return (0, createRevenueShareEscrow_1.createRevenueShareEscrowTxn)({
491
+ driftClient: this._driftClient,
492
+ authority,
493
+ numOrders: (_a = options === null || options === void 0 ? void 0 : options.numOrders) !== null && _a !== void 0 ? _a : 16,
494
+ builder: options === null || options === void 0 ? void 0 : options.builder,
495
+ txParams: (_b = options === null || options === void 0 ? void 0 : options.txParams) !== null && _b !== void 0 ? _b : this.getTxParams(),
496
+ });
497
+ });
498
+ }
499
+ /**
500
+ * Create a transaction to initialize a RevenueShare account for a builder.
501
+ * This must be initialized before a builder can receive builder fees.
502
+ */
503
+ async getCreateRevenueShareAccountTxn(authority, options) {
504
+ return this.authorityContextWrapper(authority, () => {
505
+ var _a;
506
+ return (0, createRevenueShareAccount_1.createRevenueShareAccountTxn)({
507
+ driftClient: this._driftClient,
508
+ authority,
509
+ txParams: (_a = options === null || options === void 0 ? void 0 : options.txParams) !== null && _a !== void 0 ? _a : this.getTxParams(),
510
+ });
511
+ });
512
+ }
513
+ /**
514
+ * Create a transaction to configure a builder's approval status and fee cap.
515
+ * Handles approve, update, and revoke operations.
516
+ * Set maxFeeTenthBps to 0 to revoke a builder.
517
+ */
518
+ async getConfigureApprovedBuilderTxn(authority, builderAuthority, maxFeeTenthBps, options) {
519
+ return this.authorityContextWrapper(authority, () => {
520
+ var _a;
521
+ return (0, configureBuilder_1.configureBuilderTxn)({
522
+ driftClient: this._driftClient,
523
+ authority,
524
+ builderAuthority,
525
+ maxFeeTenthBps,
526
+ txParams: (_a = options === null || options === void 0 ? void 0 : options.txParams) !== null && _a !== void 0 ? _a : this.getTxParams(),
527
+ });
528
+ });
529
+ }
464
530
  async sendSignedTransaction(tx) {
465
531
  return this._driftClient.sendTransaction(tx, undefined, undefined, true);
466
532
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/drift/Drift/clients/CentralServerDrift/index.ts"],"names":[],"mappings":";;;AAAA,yCA+ByB;AACzB,6CAAgF;AAChF,6EAA4E;AAC5E,+CAMyB;AACzB,gEAAsE;AACtE,kEAAwE;AACxE,4EAAkF;AAClF,oEAA0E;AAC1E,uGAA0G;AAC1G,6GAG0E;AAC1E,qEAA2E;AAC3E,yEAAgF;AAChF,2DAAiE;AACjE,8DAA0F;AAC1F,8DAAkE;AAGlE,2EAAwE;AAKxE,uCAAsD;AACtD,uEAAoE;AAEpE;;;;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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AAE,QAAQ,mCAAI,SAAS;oBACxC,gBAAgB,EAAE,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,gBAAgB,mCAAI,KAAK;iBACpD,CAAC,CAAC;YACJ,CAAC;YAED,MAAM,OAAO,GAAG,MAAM,IAAA,oBAAa,EAAC;gBACnC,WAAW,EAAE,IAAI,CAAC,YAAY;gBAC9B,UAAU;gBACV,IAAI;gBACJ,mBAAmB,EAAE,eAAe;gBACpC,iBAAiB,EAAE,aAAa;gBAChC,MAAM;gBACN,KAAK;gBACL,QAAQ,EAAE;oBACT,wBAAwB,EAAE,IAAI;oBAC9B,4BAA4B,EAAE,GAAG;iBACjC;aACD,CAAC,CAAC;YAEH,OAAO,OAAO,CAAC;QAChB,CAAC,CACD,CAAC;IACH,CAAC;IAEM,KAAK,CAAC,qBAAqB,CAAC,EAAsC;QACxE,OAAO,IAAI,CAAC,YAAY,CAAC,eAAe,CAAC,EAAE,EAAE,SAAS,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;IAC1E,CAAC;CACD;AA7vBD,gDA6vBC","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\tOneShotUserAccountSubscriber,\n\tOrderTriggerCondition,\n\tPerpMarketConfig,\n\tPositionDirection,\n\tPriorityFeeMethod,\n\tPriorityFeeSubscriber,\n\tPriorityFeeSubscriberConfig,\n\tPublicKey,\n\tSpotMarketConfig,\n\tSwapMode,\n\tTxParams,\n\tUnifiedQuoteResponse,\n\tUnifiedSwapClient,\n\tUser,\n\tWhileValidTxSender,\n} from '@drift-labs/sdk';\nimport { Connection, Transaction, VersionedTransaction } from '@solana/web3.js';\nimport { COMMON_UI_UTILS } from '../../../../common-ui-utils/commonUiUtils';\nimport {\n\tDEFAULT_ACCOUNT_LOADER_COMMITMENT,\n\tDEFAULT_ACCOUNT_LOADER_POLLING_FREQUENCY_MS,\n\tDEFAULT_TX_SENDER_CONFIRMATION_STRATEGY,\n\tDEFAULT_TX_SENDER_RETRY_INTERVAL,\n\tHIGH_ACTIVITY_MARKET_ACCOUNTS,\n} from '../../constants';\nimport { createDepositTxn } from '../../../base/actions/spot/deposit';\nimport { createWithdrawTxn } from '../../../base/actions/spot/withdraw';\nimport { createSettleFundingTxn } from '../../../base/actions/perp/settleFunding';\nimport { createSettlePnlTxn } from '../../../base/actions/perp/settlePnl';\nimport { createOpenPerpMarketOrder } 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 { TxnOrSwiftResult } from '../../../base/actions/trade/openPerpOrder/types';\nimport { WithTxnParams } from '../../../base/types';\nimport { EnvironmentConstants } from '../../../../EnvironmentConstants';\nimport {\n\tCentralServerGetOpenPerpMarketOrderTxnParams,\n\tCentralServerGetOpenPerpNonMarketOrderTxnParams,\n} from './types';\nimport { CentralServerDriftMarkets } from './markets';\nimport { DriftOperations } from '../AuthorityDrift/DriftOperations';\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 * 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\tconst originalWallet = this._driftClient.wallet;\n\t\tconst originalAuthority = this._driftClient.authority;\n\n\t\t// Use external wallet for transaction signing context if provided\n\t\tconst walletPublicKey = options?.externalWallet ?? authority;\n\t\tconst authorityWallet = {\n\t\t\tpublicKey: walletPublicKey,\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\t\t\t// Clear userStatsAccountPublicKey cache so it's recalculated for the new authority\n\t\t\t// @ts-ignore - accessing private property for cache invalidation\n\t\t\tthis._driftClient.userStatsAccountPublicKey = undefined;\n\n\t\t\treturn await createUserAndDepositCollateralBaseTxn({\n\t\t\t\tdriftClient: this._driftClient,\n\t\t\t\tamount,\n\t\t\t\tspotMarketConfig,\n\t\t\t\tauthority,\n\t\t\t\tuserStatsAccount,\n\t\t\t\treferrerName: options?.referrerName,\n\t\t\t\taccountName: options?.accountName,\n\t\t\t\tpoolId: options?.poolId,\n\t\t\t\tfromSubAccountId: options?.fromSubAccountId,\n\t\t\t\tcustomMaxMarginRatio: options?.customMaxMarginRatio,\n\t\t\t\ttxParams: options?.txParams ?? this.getTxParams(),\n\t\t\t\texternalWallet: options?.externalWallet,\n\t\t\t});\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\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\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} = rest;\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\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\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);\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\treturn this.driftClientContextWrapper(\n\t\t\tuserAccountPublicKey,\n\t\t\tasync (user) => {\n\t\t\t\tconst { useSwift, swiftOptions, txParams, ...otherProps } = rest;\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\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\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);\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\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,yCA+ByB;AACzB,6CAAgF;AAChF,6EAA4E;AAC5E,+CAMyB;AACzB,gEAAsE;AACtE,kEAAwE;AACxE,4EAAkF;AAClF,oEAA0E;AAC1E,uGAA0G;AAC1G,6GAG0E;AAC1E,qEAA2E;AAC3E,yEAAgF;AAChF,2DAAiE;AACjE,8DAA0F;AAC1F,8DAAkE;AAClE,qGAAqG;AACrG,uGAAuG;AACvG,qFAAqF;AAGrF,2EAAwE;AAKxE,uCAAsD;AACtD,uEAAoE;AAEpE;;;;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;QAChE,MAAM,oBAAoB,GACzB,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,uBAAiB,CAAC,CAAC,CAAC,wBAAkB,CAAC;QAChE,IAAI,CAAC,kBAAkB,GAAG,MAAM,CAAC,oBAAoB,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,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C,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;AAz1BD,gDAy1BC","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\tOneShotUserAccountSubscriber,\n\tOrderTriggerCondition,\n\tPerpMarketConfig,\n\tPositionDirection,\n\tPriorityFeeMethod,\n\tPriorityFeeSubscriber,\n\tPriorityFeeSubscriberConfig,\n\tPublicKey,\n\tSpotMarketConfig,\n\tSwapMode,\n\tTxParams,\n\tUnifiedQuoteResponse,\n\tUnifiedSwapClient,\n\tUser,\n\tWhileValidTxSender,\n} from '@drift-labs/sdk';\nimport { Connection, Transaction, VersionedTransaction } from '@solana/web3.js';\nimport { COMMON_UI_UTILS } from '../../../../common-ui-utils/commonUiUtils';\nimport {\n\tDEFAULT_ACCOUNT_LOADER_COMMITMENT,\n\tDEFAULT_ACCOUNT_LOADER_POLLING_FREQUENCY_MS,\n\tDEFAULT_TX_SENDER_CONFIRMATION_STRATEGY,\n\tDEFAULT_TX_SENDER_RETRY_INTERVAL,\n\tHIGH_ACTIVITY_MARKET_ACCOUNTS,\n} from '../../constants';\nimport { createDepositTxn } from '../../../base/actions/spot/deposit';\nimport { createWithdrawTxn } from '../../../base/actions/spot/withdraw';\nimport { createSettleFundingTxn } from '../../../base/actions/perp/settleFunding';\nimport { createSettlePnlTxn } from '../../../base/actions/perp/settlePnl';\nimport { createOpenPerpMarketOrder } 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} from './types';\nimport { CentralServerDriftMarkets } from './markets';\nimport { DriftOperations } from '../AuthorityDrift/DriftOperations';\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\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} = rest;\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\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\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);\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\treturn this.driftClientContextWrapper(\n\t\t\tuserAccountPublicKey,\n\t\t\tasync (user) => {\n\t\t\t\tconst { useSwift, swiftOptions, txParams, ...otherProps } = rest;\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\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\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);\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,10 +1,10 @@
1
1
  import { DriftClient } from '@drift-labs/sdk';
2
2
  import { Transaction, TransactionInstruction, VersionedTransaction, PublicKey } from '@solana/web3.js';
3
3
  import { WithTxnParams } from '../../types';
4
- interface ManageBuilderIxParams {
4
+ interface ConfigureBuilderIxParams {
5
5
  driftClient: DriftClient;
6
6
  /**
7
- * The public key of the builder to manage.
7
+ * The public key of the builder to configure.
8
8
  * This is the builder's authority address that owns their RevenueShare account.
9
9
  */
10
10
  builderAuthority: PublicKey;
@@ -32,9 +32,9 @@ interface ManageBuilderIxParams {
32
32
  payer?: PublicKey;
33
33
  }
34
34
  /**
35
- * Creates a transaction instruction to manage a builder's approval status and fee cap.
35
+ * Creates a transaction instruction to configure a builder's approval status and fee cap.
36
36
  *
37
- * This unified function handles all builder management operations:
37
+ * This unified function handles all builder configuration operations:
38
38
  * - **Approve**: Add a new builder to the approved list
39
39
  * - **Update**: Modify an existing builder's max fee cap
40
40
  * - **Revoke**: Disable a builder by setting their max fee to 0
@@ -59,7 +59,7 @@ interface ManageBuilderIxParams {
59
59
  * - Builder must have initialized a RevenueShare account (for receiving fees)
60
60
  *
61
61
  * @param driftClient - The Drift client instance
62
- * @param builderAuthority - The public key of the builder to manage
62
+ * @param builderAuthority - The public key of the builder to configure
63
63
  * @param maxFeeTenthBps - Maximum fee cap in tenths of basis points
64
64
  *
65
65
  * @returns Promise resolving to a TransactionInstruction
@@ -67,7 +67,7 @@ interface ManageBuilderIxParams {
67
67
  * @example
68
68
  * ```typescript
69
69
  * // Approve a new builder with 5 bps max fee
70
- * const ix = await manageBuilderIx({
70
+ * const ix = await configureBuilderIx({
71
71
  * driftClient,
72
72
  * builderAuthority: new PublicKey('BuilderAddress...'),
73
73
  * maxFeeTenthBps: 50 // 5 bps = 0.05%
@@ -77,7 +77,7 @@ interface ManageBuilderIxParams {
77
77
  * @example
78
78
  * ```typescript
79
79
  * // Update existing builder to 10 bps max fee
80
- * const ix = await manageBuilderIx({
80
+ * const ix = await configureBuilderIx({
81
81
  * driftClient,
82
82
  * builderAuthority: builderPubkey,
83
83
  * maxFeeTenthBps: 100 // 10 bps = 0.1%
@@ -88,18 +88,18 @@ interface ManageBuilderIxParams {
88
88
  * ```typescript
89
89
  * // Revoke builder (set max fee to 0)
90
90
  * // IMPORTANT: Must settle all builder's orders first!
91
- * const ix = await manageBuilderIx({
91
+ * const ix = await configureBuilderIx({
92
92
  * driftClient,
93
93
  * builderAuthority: builderPubkey,
94
94
  * maxFeeTenthBps: 0 // Revoked
95
95
  * });
96
96
  * ```
97
97
  */
98
- export declare const manageBuilderIx: (params: ManageBuilderIxParams) => Promise<TransactionInstruction>;
98
+ export declare const configureBuilderIx: (params: ConfigureBuilderIxParams) => Promise<TransactionInstruction>;
99
99
  /**
100
- * Creates a transaction to manage a builder's approval status and fee cap.
100
+ * Creates a transaction to configure a builder's approval status and fee cap.
101
101
  *
102
- * This unified function handles all builder management operations:
102
+ * This unified function handles all builder configuration operations:
103
103
  * - **Approve**: Add a new builder to the approved list
104
104
  * - **Update**: Modify an existing builder's max fee cap
105
105
  * - **Revoke**: Disable a builder by setting their max fee to 0
@@ -124,7 +124,7 @@ export declare const manageBuilderIx: (params: ManageBuilderIxParams) => Promise
124
124
  * - Builder must have initialized a RevenueShare account (for receiving fees)
125
125
  *
126
126
  * @param driftClient - The Drift client instance
127
- * @param builderAuthority - The public key of the builder to manage
127
+ * @param builderAuthority - The public key of the builder to configure
128
128
  * @param maxFeeTenthBps - Maximum fee cap in tenths of basis points
129
129
  * @param txParams - Optional transaction parameters for customizing the transaction
130
130
  *
@@ -133,7 +133,7 @@ export declare const manageBuilderIx: (params: ManageBuilderIxParams) => Promise
133
133
  * @example
134
134
  * ```typescript
135
135
  * // Approve a new builder with 2 bps max fee
136
- * const tx = await manageBuilderTxn({
136
+ * const tx = await configureBuilderTxn({
137
137
  * driftClient,
138
138
  * builderAuthority: new PublicKey('BuilderAddress...'),
139
139
  * maxFeeTenthBps: 20,
@@ -146,12 +146,12 @@ export declare const manageBuilderIx: (params: ManageBuilderIxParams) => Promise
146
146
  * @example
147
147
  * ```typescript
148
148
  * // Update existing builder's fee
149
- * await manageBuilderTxn({
149
+ * await configureBuilderTxn({
150
150
  * driftClient,
151
151
  * builderAuthority: builderPubkey,
152
152
  * maxFeeTenthBps: 100 // Increase to 10 bps
153
153
  * });
154
154
  * ```
155
155
  */
156
- export declare const manageBuilderTxn: (params: WithTxnParams<ManageBuilderIxParams>) => Promise<Transaction | VersionedTransaction>;
156
+ export declare const configureBuilderTxn: (params: WithTxnParams<ConfigureBuilderIxParams>) => Promise<Transaction | VersionedTransaction>;
157
157
  export {};
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.manageBuilderTxn = exports.manageBuilderIx = void 0;
3
+ exports.configureBuilderTxn = exports.configureBuilderIx = void 0;
4
4
  /**
5
- * Creates a transaction instruction to manage a builder's approval status and fee cap.
5
+ * Creates a transaction instruction to configure a builder's approval status and fee cap.
6
6
  *
7
- * This unified function handles all builder management operations:
7
+ * This unified function handles all builder configuration operations:
8
8
  * - **Approve**: Add a new builder to the approved list
9
9
  * - **Update**: Modify an existing builder's max fee cap
10
10
  * - **Revoke**: Disable a builder by setting their max fee to 0
@@ -29,7 +29,7 @@ exports.manageBuilderTxn = exports.manageBuilderIx = void 0;
29
29
  * - Builder must have initialized a RevenueShare account (for receiving fees)
30
30
  *
31
31
  * @param driftClient - The Drift client instance
32
- * @param builderAuthority - The public key of the builder to manage
32
+ * @param builderAuthority - The public key of the builder to configure
33
33
  * @param maxFeeTenthBps - Maximum fee cap in tenths of basis points
34
34
  *
35
35
  * @returns Promise resolving to a TransactionInstruction
@@ -37,7 +37,7 @@ exports.manageBuilderTxn = exports.manageBuilderIx = void 0;
37
37
  * @example
38
38
  * ```typescript
39
39
  * // Approve a new builder with 5 bps max fee
40
- * const ix = await manageBuilderIx({
40
+ * const ix = await configureBuilderIx({
41
41
  * driftClient,
42
42
  * builderAuthority: new PublicKey('BuilderAddress...'),
43
43
  * maxFeeTenthBps: 50 // 5 bps = 0.05%
@@ -47,7 +47,7 @@ exports.manageBuilderTxn = exports.manageBuilderIx = void 0;
47
47
  * @example
48
48
  * ```typescript
49
49
  * // Update existing builder to 10 bps max fee
50
- * const ix = await manageBuilderIx({
50
+ * const ix = await configureBuilderIx({
51
51
  * driftClient,
52
52
  * builderAuthority: builderPubkey,
53
53
  * maxFeeTenthBps: 100 // 10 bps = 0.1%
@@ -58,14 +58,14 @@ exports.manageBuilderTxn = exports.manageBuilderIx = void 0;
58
58
  * ```typescript
59
59
  * // Revoke builder (set max fee to 0)
60
60
  * // IMPORTANT: Must settle all builder's orders first!
61
- * const ix = await manageBuilderIx({
61
+ * const ix = await configureBuilderIx({
62
62
  * driftClient,
63
63
  * builderAuthority: builderPubkey,
64
64
  * maxFeeTenthBps: 0 // Revoked
65
65
  * });
66
66
  * ```
67
67
  */
68
- const manageBuilderIx = async (params) => {
68
+ const configureBuilderIx = async (params) => {
69
69
  const { driftClient, builderAuthority, maxFeeTenthBps, authority, payer } = params;
70
70
  const isRevoke = maxFeeTenthBps === 0;
71
71
  return driftClient.getChangeApprovedBuilderIx(builderAuthority, maxFeeTenthBps, !isRevoke, // add = true (approve/update), false (revoke)
@@ -74,11 +74,11 @@ const manageBuilderIx = async (params) => {
74
74
  payer: payer !== null && payer !== void 0 ? payer : authority,
75
75
  });
76
76
  };
77
- exports.manageBuilderIx = manageBuilderIx;
77
+ exports.configureBuilderIx = configureBuilderIx;
78
78
  /**
79
- * Creates a transaction to manage a builder's approval status and fee cap.
79
+ * Creates a transaction to configure a builder's approval status and fee cap.
80
80
  *
81
- * This unified function handles all builder management operations:
81
+ * This unified function handles all builder configuration operations:
82
82
  * - **Approve**: Add a new builder to the approved list
83
83
  * - **Update**: Modify an existing builder's max fee cap
84
84
  * - **Revoke**: Disable a builder by setting their max fee to 0
@@ -103,7 +103,7 @@ exports.manageBuilderIx = manageBuilderIx;
103
103
  * - Builder must have initialized a RevenueShare account (for receiving fees)
104
104
  *
105
105
  * @param driftClient - The Drift client instance
106
- * @param builderAuthority - The public key of the builder to manage
106
+ * @param builderAuthority - The public key of the builder to configure
107
107
  * @param maxFeeTenthBps - Maximum fee cap in tenths of basis points
108
108
  * @param txParams - Optional transaction parameters for customizing the transaction
109
109
  *
@@ -112,7 +112,7 @@ exports.manageBuilderIx = manageBuilderIx;
112
112
  * @example
113
113
  * ```typescript
114
114
  * // Approve a new builder with 2 bps max fee
115
- * const tx = await manageBuilderTxn({
115
+ * const tx = await configureBuilderTxn({
116
116
  * driftClient,
117
117
  * builderAuthority: new PublicKey('BuilderAddress...'),
118
118
  * maxFeeTenthBps: 20,
@@ -125,15 +125,15 @@ exports.manageBuilderIx = manageBuilderIx;
125
125
  * @example
126
126
  * ```typescript
127
127
  * // Update existing builder's fee
128
- * await manageBuilderTxn({
128
+ * await configureBuilderTxn({
129
129
  * driftClient,
130
130
  * builderAuthority: builderPubkey,
131
131
  * maxFeeTenthBps: 100 // Increase to 10 bps
132
132
  * });
133
133
  * ```
134
134
  */
135
- const manageBuilderTxn = async (params) => {
136
- return params.driftClient.buildTransaction(await (0, exports.manageBuilderIx)(params), params.txParams);
135
+ const configureBuilderTxn = async (params) => {
136
+ return params.driftClient.buildTransaction(await (0, exports.configureBuilderIx)(params), params.txParams);
137
137
  };
138
- exports.manageBuilderTxn = manageBuilderTxn;
139
- //# sourceMappingURL=manageBuilder.js.map
138
+ exports.configureBuilderTxn = configureBuilderTxn;
139
+ //# sourceMappingURL=configureBuilder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configureBuilder.js","sourceRoot":"","sources":["../../../../../src/drift/base/actions/builder/configureBuilder.ts"],"names":[],"mappings":";;;AAwCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+DG;AACI,MAAM,kBAAkB,GAAG,KAAK,EACtC,MAAgC,EACE,EAAE;IACpC,MAAM,EAAE,WAAW,EAAE,gBAAgB,EAAE,cAAc,EAAE,SAAS,EAAE,KAAK,EAAE,GACxE,MAAM,CAAC;IAER,MAAM,QAAQ,GAAG,cAAc,KAAK,CAAC,CAAC;IAEtC,OAAO,WAAW,CAAC,0BAA0B,CAC5C,gBAAgB,EAChB,cAAc,EACd,CAAC,QAAQ,EAAE,8CAA8C;IACzD;QACC,SAAS;QACT,KAAK,EAAE,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,SAAS;KACzB,CACD,CAAC;AACH,CAAC,CAAC;AAjBW,QAAA,kBAAkB,sBAiB7B;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AACI,MAAM,mBAAmB,GAAG,KAAK,EACvC,MAA+C,EACD,EAAE;IAChD,OAAO,MAAM,CAAC,WAAW,CAAC,gBAAgB,CACzC,MAAM,IAAA,0BAAkB,EAAC,MAAM,CAAC,EAChC,MAAM,CAAC,QAAQ,CACf,CAAC;AACH,CAAC,CAAC;AAPW,QAAA,mBAAmB,uBAO9B","sourcesContent":["import { DriftClient } from '@drift-labs/sdk';\nimport {\n\tTransaction,\n\tTransactionInstruction,\n\tVersionedTransaction,\n\tPublicKey,\n} from '@solana/web3.js';\nimport { WithTxnParams } from '../../types';\n\ninterface ConfigureBuilderIxParams {\n\tdriftClient: DriftClient;\n\t/**\n\t * The public key of the builder to configure.\n\t * This is the builder's authority address that owns their RevenueShare account.\n\t */\n\tbuilderAuthority: PublicKey;\n\t/**\n\t * Maximum fee the builder can charge, in tenths of basis points.\n\t *\n\t * Examples:\n\t * - 10 = 1 bps = 0.01%\n\t * - 50 = 5 bps = 0.05%\n\t * - 100 = 10 bps = 0.1%\n\t * - 1000 = 100 bps = 1%\n\t *\n\t * Special values:\n\t * - Set to 0 to revoke the builder (they remain in list but cannot be used)\n\t */\n\tmaxFeeTenthBps: number;\n\t/**\n\t * The public key of the authority to add the builder to the approved builders list.\n\t */\n\tauthority: PublicKey;\n\t/**\n\t * The public key of the wallet that will pay for the transaction.\n\t * If not provided, the authority provided will be the payer.\n\t */\n\tpayer?: PublicKey;\n}\n\n/**\n * Creates a transaction instruction to configure a builder's approval status and fee cap.\n *\n * This unified function handles all builder configuration operations:\n * - **Approve**: Add a new builder to the approved list\n * - **Update**: Modify an existing builder's max fee cap\n * - **Revoke**: Disable a builder by setting their max fee to 0\n *\n * ## Behavior:\n *\n * ### If builder NOT in list:\n * - Adds builder with specified `maxFeeTenthBps`\n *\n * ### If builder already in list:\n * - Updates builder's `maxFeeTenthBps` to new value\n * - Set to 0 to revoke (builder stays in list but cannot be used)\n *\n * ## Revocation Constraints:\n * When setting `maxFeeTenthBps = 0`, the builder cannot have active orders:\n * - No Open orders using this builder\n * - No Completed (unsettled) orders using this builder\n * - Error: `CannotRevokeBuilderWithOpenOrders` if constraint violated\n *\n * **Prerequisites**:\n * - User must have initialized a RevenueShareEscrow account\n * - Builder must have initialized a RevenueShare account (for receiving fees)\n *\n * @param driftClient - The Drift client instance\n * @param builderAuthority - The public key of the builder to configure\n * @param maxFeeTenthBps - Maximum fee cap in tenths of basis points\n *\n * @returns Promise resolving to a TransactionInstruction\n *\n * @example\n * ```typescript\n * // Approve a new builder with 5 bps max fee\n * const ix = await configureBuilderIx({\n * driftClient,\n * builderAuthority: new PublicKey('BuilderAddress...'),\n * maxFeeTenthBps: 50 // 5 bps = 0.05%\n * });\n * ```\n *\n * @example\n * ```typescript\n * // Update existing builder to 10 bps max fee\n * const ix = await configureBuilderIx({\n * driftClient,\n * builderAuthority: builderPubkey,\n * maxFeeTenthBps: 100 // 10 bps = 0.1%\n * });\n * ```\n *\n * @example\n * ```typescript\n * // Revoke builder (set max fee to 0)\n * // IMPORTANT: Must settle all builder's orders first!\n * const ix = await configureBuilderIx({\n * driftClient,\n * builderAuthority: builderPubkey,\n * maxFeeTenthBps: 0 // Revoked\n * });\n * ```\n */\nexport const configureBuilderIx = async (\n\tparams: ConfigureBuilderIxParams\n): Promise<TransactionInstruction> => {\n\tconst { driftClient, builderAuthority, maxFeeTenthBps, authority, payer } =\n\t\tparams;\n\n\tconst isRevoke = maxFeeTenthBps === 0;\n\n\treturn driftClient.getChangeApprovedBuilderIx(\n\t\tbuilderAuthority,\n\t\tmaxFeeTenthBps,\n\t\t!isRevoke, // add = true (approve/update), false (revoke)\n\t\t{\n\t\t\tauthority,\n\t\t\tpayer: payer ?? authority,\n\t\t}\n\t);\n};\n\n/**\n * Creates a transaction to configure a builder's approval status and fee cap.\n *\n * This unified function handles all builder configuration operations:\n * - **Approve**: Add a new builder to the approved list\n * - **Update**: Modify an existing builder's max fee cap\n * - **Revoke**: Disable a builder by setting their max fee to 0\n *\n * ## Behavior:\n *\n * ### If builder NOT in list:\n * - Adds builder with specified `maxFeeTenthBps`\n *\n * ### If builder already in list:\n * - Updates builder's `maxFeeTenthBps` to new value\n * - Set to 0 to revoke (builder stays in list but cannot be used)\n *\n * ## Revocation Constraints:\n * When setting `maxFeeTenthBps = 0`, the builder cannot have active orders:\n * - No Open orders using this builder\n * - No Completed (unsettled) orders using this builder\n * - Error: `CannotRevokeBuilderWithOpenOrders` if constraint violated\n *\n * **Prerequisites**:\n * - User must have initialized a RevenueShareEscrow account\n * - Builder must have initialized a RevenueShare account (for receiving fees)\n *\n * @param driftClient - The Drift client instance\n * @param builderAuthority - The public key of the builder to configure\n * @param maxFeeTenthBps - Maximum fee cap in tenths of basis points\n * @param txParams - Optional transaction parameters for customizing the transaction\n *\n * @returns Promise resolving to a Transaction or VersionedTransaction ready for signing\n *\n * @example\n * ```typescript\n * // Approve a new builder with 2 bps max fee\n * const tx = await configureBuilderTxn({\n * driftClient,\n * builderAuthority: new PublicKey('BuilderAddress...'),\n * maxFeeTenthBps: 20,\n * txParams: { computeUnits: 200000 }\n * });\n *\n * const signature = await wallet.sendTransaction(tx, connection);\n * ```\n\n * @example\n * ```typescript\n * // Update existing builder's fee\n * await configureBuilderTxn({\n * driftClient,\n * builderAuthority: builderPubkey,\n * maxFeeTenthBps: 100 // Increase to 10 bps\n * });\n * ```\n */\nexport const configureBuilderTxn = async (\n\tparams: WithTxnParams<ConfigureBuilderIxParams>\n): Promise<Transaction | VersionedTransaction> => {\n\treturn params.driftClient.buildTransaction(\n\t\tawait configureBuilderIx(params),\n\t\tparams.txParams\n\t);\n};\n"]}
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createRevenueShareEscrowTxn = exports.createRevenueShareEscrowIx = void 0;
4
- const manageBuilder_1 = require("./manageBuilder");
4
+ const configureBuilder_1 = require("./configureBuilder");
5
5
  /**
6
6
  * Creates a transaction instruction to initialize a `RevenueShareEscrow` account for a user.
7
7
  *
@@ -99,7 +99,7 @@ const createRevenueShareEscrowTxn = async (params) => {
99
99
  const createIx = await (0, exports.createRevenueShareEscrowIx)(params);
100
100
  const ixs = [createIx];
101
101
  if (params.builder) {
102
- const addBuilderIx = await (0, manageBuilder_1.manageBuilderIx)({
102
+ const addBuilderIx = await (0, configureBuilder_1.configureBuilderIx)({
103
103
  driftClient: params.driftClient,
104
104
  authority: params.authority,
105
105
  builderAuthority: params.builder.builderAuthority,
@@ -1 +1 @@
1
- {"version":3,"file":"createRevenueShareEscrow.js","sourceRoot":"","sources":["../../../../../src/drift/base/actions/builder/createRevenueShareEscrow.ts"],"names":[],"mappings":";;;AAQA,mDAAkD;AAsBlD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACI,MAAM,0BAA0B,GAAG,KAAK,EAAE,EAChD,WAAW,EACX,SAAS,EACT,SAAS,GAAG,EAAE,EACd,KAAK,GAC6B,EAAmC,EAAE;IACvE,OAAO,WAAW,CAAC,iCAAiC,CAAC,SAAS,EAAE,SAAS,EAAE;QAC1E,KAAK,EAAE,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,SAAS;KACzB,CAAC,CAAC;AACJ,CAAC,CAAC;AATW,QAAA,0BAA0B,8BASrC;AAmBF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACI,MAAM,2BAA2B,GAAG,KAAK,EAC/C,MAAyC,EACK,EAAE;;IAChD,MAAM,QAAQ,GAAG,MAAM,IAAA,kCAA0B,EAAC,MAAM,CAAC,CAAC;IAC1D,MAAM,GAAG,GAAG,CAAC,QAAQ,CAAC,CAAC;IAEvB,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;QACpB,MAAM,YAAY,GAAG,MAAM,IAAA,+BAAe,EAAC;YAC1C,WAAW,EAAE,MAAM,CAAC,WAAW;YAC/B,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,gBAAgB,EAAE,MAAM,CAAC,OAAO,CAAC,gBAAgB;YACjD,cAAc,EAAE,MAAM,CAAC,OAAO,CAAC,cAAc;YAC7C,KAAK,EAAE,MAAA,MAAM,CAAC,KAAK,mCAAI,MAAM,CAAC,SAAS;SACvC,CAAC,CAAC;QAEH,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACxB,CAAC;IAED,OAAO,MAAM,CAAC,WAAW,CAAC,gBAAgB,CAAC,GAAG,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;AAClE,CAAC,CAAC;AAnBW,QAAA,2BAA2B,+BAmBtC","sourcesContent":["import { DriftClient } from '@drift-labs/sdk';\nimport {\n\tTransaction,\n\tTransactionInstruction,\n\tVersionedTransaction,\n\tPublicKey,\n} from '@solana/web3.js';\nimport { WithTxnParams } from '../../types';\nimport { manageBuilderIx } from './manageBuilder';\n\ninterface CreateRevenueShareEscrowIxParams {\n\tdriftClient: DriftClient;\n\t/**\n\t * The authority (owner) of the revenue share escrow account to be created.\n\t * This is typically the user/taker's public key.\n\t */\n\tauthority: PublicKey;\n\t/**\n\t * Number of order slots to allocate in the escrow account.\n\t * This determines how many concurrent builder orders can be tracked.\n\t * Recommended: 8-32 for typical users, up to 128 maximum.\n\t */\n\tnumOrders?: number;\n\t/**\n\t * The public key of the account that will pay for the revenue share escrow account rent.\n\t * If not provided, the authority provided will be the payer.\n\t */\n\tpayer?: PublicKey;\n}\n\n/**\n * Creates a transaction instruction to initialize a `RevenueShareEscrow` account for a user.\n *\n * The RevenueShareEscrow account stores:\n * - List of approved builders with their max fee caps\n * - Pending builder fee orders waiting to be settled\n *\n * Users must initialize this account before they can place orders with builder codes.\n *\n * **Important**: `numOrders` determines CONCURRENT order capacity, not lifetime total orders.\n * When the escrow is full, new orders will succeed but builder fees won't be tracked.\n * See README_ORDER_LIMITS.md for capacity planning guidance.\n *\n * @param driftClient - The Drift client instance\n * @param authority - The public key of the user who will own this escrow account\n * @param numOrders - Number of concurrent order slots (default: 16, range: 1-128)\n * - 8: Casual traders (2-3 markets, occasional trading)\n * - 16: Active traders (3-5 markets, regular trading) ← Recommended default\n * - 32-64: Power users (many markets, frequent trading)\n * - 128: Maximum capacity (institutional usage)\n * @param payer - The public key of the account that will pay for the revenue share escrow account rent\n *\n * @returns Promise resolving to a TransactionInstruction that initializes the revenue share escrow\n *\n * @example\n * ```typescript\n * // Default configuration (16 order slots)\n * const instruction = await createRevenueShareEscrowIx({\n * driftClient,\n * authority: userPublicKey\n * });\n *\n * // Custom configuration for power user\n * const instruction = await createRevenueShareEscrowIx({\n * driftClient,\n * authority: userPublicKey,\n * numOrders: 32 // More concurrent capacity\n * });\n * ```\n */\nexport const createRevenueShareEscrowIx = async ({\n\tdriftClient,\n\tauthority,\n\tnumOrders = 16,\n\tpayer,\n}: CreateRevenueShareEscrowIxParams): Promise<TransactionInstruction> => {\n\treturn driftClient.getInitializeRevenueShareEscrowIx(authority, numOrders, {\n\t\tpayer: payer ?? authority,\n\t});\n};\n\ninterface CreateRevenueShareEscrowTxnParams\n\textends WithTxnParams<CreateRevenueShareEscrowIxParams> {\n\t/**\n\t * The builder to add to the escrow account.\n\t */\n\tbuilder?: {\n\t\t/**\n\t\t * The public key of the builder to add to the escrow account.\n\t\t */\n\t\tbuilderAuthority: PublicKey;\n\t\t/**\n\t\t * The maximum fee the builder can charge, in tenths of basis points.\n\t\t */\n\t\tmaxFeeTenthBps: number;\n\t};\n}\n\n/**\n * Creates a transaction to initialize a RevenueShareEscrow account for a user.\n *\n * The RevenueShareEscrow account stores:\n * - List of approved builders with their max fee caps\n * - Pending builder fee orders waiting to be settled\n *\n * Users must initialize this account before they can place orders with builder codes.\n *\n * **Important**: `numOrders` determines CONCURRENT order capacity, not lifetime total orders.\n * When the escrow is full, new orders will succeed but builder fees won't be tracked.\n * See README_ORDER_LIMITS.md for capacity planning guidance.\n *\n * @param driftClient - The Drift client instance\n * @param authority - The public key of the user who will own this escrow account\n * @param numOrders - Number of concurrent order slots (default: 16, range: 1-128)\n * - 8: Casual traders (2-3 markets, occasional trading)\n * - 16: Active traders (3-5 markets, regular trading) ← Recommended default\n * - 32-64: Power users (many markets, frequent trading)\n * - 128: Maximum capacity (institutional usage)\n * @param payer - The public key of the account that will pay for the revenue share escrow account rent\n * @param txParams - Optional transaction parameters for customizing the transaction\n *\n * @returns Promise resolving to a Transaction or VersionedTransaction ready for signing\n *\n * @example\n * ```typescript\n * // Default configuration (16 order slots)\n * const transaction = await createRevenueShareEscrowTxn({\n * driftClient,\n * authority: userPublicKey,\n * txParams: { computeUnits: 300000 }\n * });\n *\n * // Custom configuration for power user\n * const transaction = await createRevenueShareEscrowTxn({\n * driftClient,\n * authority: userPublicKey,\n * numOrders: 32, // More concurrent capacity\n * txParams: { computeUnits: 300000 }\n * });\n *\n * // Sign and send the transaction\n * const signature = await wallet.sendTransaction(transaction, connection);\n * ```\n */\nexport const createRevenueShareEscrowTxn = async (\n\tparams: CreateRevenueShareEscrowTxnParams\n): Promise<Transaction | VersionedTransaction> => {\n\tconst createIx = await createRevenueShareEscrowIx(params);\n\tconst ixs = [createIx];\n\n\tif (params.builder) {\n\t\tconst addBuilderIx = await manageBuilderIx({\n\t\t\tdriftClient: params.driftClient,\n\t\t\tauthority: params.authority,\n\t\t\tbuilderAuthority: params.builder.builderAuthority,\n\t\t\tmaxFeeTenthBps: params.builder.maxFeeTenthBps,\n\t\t\tpayer: params.payer ?? params.authority,\n\t\t});\n\n\t\tixs.push(addBuilderIx);\n\t}\n\n\treturn params.driftClient.buildTransaction(ixs, params.txParams);\n};\n"]}
1
+ {"version":3,"file":"createRevenueShareEscrow.js","sourceRoot":"","sources":["../../../../../src/drift/base/actions/builder/createRevenueShareEscrow.ts"],"names":[],"mappings":";;;AAQA,yDAAwD;AAsBxD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACI,MAAM,0BAA0B,GAAG,KAAK,EAAE,EAChD,WAAW,EACX,SAAS,EACT,SAAS,GAAG,EAAE,EACd,KAAK,GAC6B,EAAmC,EAAE;IACvE,OAAO,WAAW,CAAC,iCAAiC,CAAC,SAAS,EAAE,SAAS,EAAE;QAC1E,KAAK,EAAE,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,SAAS;KACzB,CAAC,CAAC;AACJ,CAAC,CAAC;AATW,QAAA,0BAA0B,8BASrC;AAmBF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACI,MAAM,2BAA2B,GAAG,KAAK,EAC/C,MAAyC,EACK,EAAE;;IAChD,MAAM,QAAQ,GAAG,MAAM,IAAA,kCAA0B,EAAC,MAAM,CAAC,CAAC;IAC1D,MAAM,GAAG,GAAG,CAAC,QAAQ,CAAC,CAAC;IAEvB,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;QACpB,MAAM,YAAY,GAAG,MAAM,IAAA,qCAAkB,EAAC;YAC7C,WAAW,EAAE,MAAM,CAAC,WAAW;YAC/B,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,gBAAgB,EAAE,MAAM,CAAC,OAAO,CAAC,gBAAgB;YACjD,cAAc,EAAE,MAAM,CAAC,OAAO,CAAC,cAAc;YAC7C,KAAK,EAAE,MAAA,MAAM,CAAC,KAAK,mCAAI,MAAM,CAAC,SAAS;SACvC,CAAC,CAAC;QAEH,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACxB,CAAC;IAED,OAAO,MAAM,CAAC,WAAW,CAAC,gBAAgB,CAAC,GAAG,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;AAClE,CAAC,CAAC;AAnBW,QAAA,2BAA2B,+BAmBtC","sourcesContent":["import { DriftClient } from '@drift-labs/sdk';\nimport {\n\tTransaction,\n\tTransactionInstruction,\n\tVersionedTransaction,\n\tPublicKey,\n} from '@solana/web3.js';\nimport { WithTxnParams } from '../../types';\nimport { configureBuilderIx } from './configureBuilder';\n\ninterface CreateRevenueShareEscrowIxParams {\n\tdriftClient: DriftClient;\n\t/**\n\t * The authority (owner) of the revenue share escrow account to be created.\n\t * This is typically the user/taker's public key.\n\t */\n\tauthority: PublicKey;\n\t/**\n\t * Number of order slots to allocate in the escrow account.\n\t * This determines how many concurrent builder orders can be tracked.\n\t * Recommended: 8-32 for typical users, up to 128 maximum.\n\t */\n\tnumOrders?: number;\n\t/**\n\t * The public key of the account that will pay for the revenue share escrow account rent.\n\t * If not provided, the authority provided will be the payer.\n\t */\n\tpayer?: PublicKey;\n}\n\n/**\n * Creates a transaction instruction to initialize a `RevenueShareEscrow` account for a user.\n *\n * The RevenueShareEscrow account stores:\n * - List of approved builders with their max fee caps\n * - Pending builder fee orders waiting to be settled\n *\n * Users must initialize this account before they can place orders with builder codes.\n *\n * **Important**: `numOrders` determines CONCURRENT order capacity, not lifetime total orders.\n * When the escrow is full, new orders will succeed but builder fees won't be tracked.\n * See README_ORDER_LIMITS.md for capacity planning guidance.\n *\n * @param driftClient - The Drift client instance\n * @param authority - The public key of the user who will own this escrow account\n * @param numOrders - Number of concurrent order slots (default: 16, range: 1-128)\n * - 8: Casual traders (2-3 markets, occasional trading)\n * - 16: Active traders (3-5 markets, regular trading) ← Recommended default\n * - 32-64: Power users (many markets, frequent trading)\n * - 128: Maximum capacity (institutional usage)\n * @param payer - The public key of the account that will pay for the revenue share escrow account rent\n *\n * @returns Promise resolving to a TransactionInstruction that initializes the revenue share escrow\n *\n * @example\n * ```typescript\n * // Default configuration (16 order slots)\n * const instruction = await createRevenueShareEscrowIx({\n * driftClient,\n * authority: userPublicKey\n * });\n *\n * // Custom configuration for power user\n * const instruction = await createRevenueShareEscrowIx({\n * driftClient,\n * authority: userPublicKey,\n * numOrders: 32 // More concurrent capacity\n * });\n * ```\n */\nexport const createRevenueShareEscrowIx = async ({\n\tdriftClient,\n\tauthority,\n\tnumOrders = 16,\n\tpayer,\n}: CreateRevenueShareEscrowIxParams): Promise<TransactionInstruction> => {\n\treturn driftClient.getInitializeRevenueShareEscrowIx(authority, numOrders, {\n\t\tpayer: payer ?? authority,\n\t});\n};\n\ninterface CreateRevenueShareEscrowTxnParams\n\textends WithTxnParams<CreateRevenueShareEscrowIxParams> {\n\t/**\n\t * The builder to add to the escrow account.\n\t */\n\tbuilder?: {\n\t\t/**\n\t\t * The public key of the builder to add to the escrow account.\n\t\t */\n\t\tbuilderAuthority: PublicKey;\n\t\t/**\n\t\t * The maximum fee the builder can charge, in tenths of basis points.\n\t\t */\n\t\tmaxFeeTenthBps: number;\n\t};\n}\n\n/**\n * Creates a transaction to initialize a RevenueShareEscrow account for a user.\n *\n * The RevenueShareEscrow account stores:\n * - List of approved builders with their max fee caps\n * - Pending builder fee orders waiting to be settled\n *\n * Users must initialize this account before they can place orders with builder codes.\n *\n * **Important**: `numOrders` determines CONCURRENT order capacity, not lifetime total orders.\n * When the escrow is full, new orders will succeed but builder fees won't be tracked.\n * See README_ORDER_LIMITS.md for capacity planning guidance.\n *\n * @param driftClient - The Drift client instance\n * @param authority - The public key of the user who will own this escrow account\n * @param numOrders - Number of concurrent order slots (default: 16, range: 1-128)\n * - 8: Casual traders (2-3 markets, occasional trading)\n * - 16: Active traders (3-5 markets, regular trading) ← Recommended default\n * - 32-64: Power users (many markets, frequent trading)\n * - 128: Maximum capacity (institutional usage)\n * @param payer - The public key of the account that will pay for the revenue share escrow account rent\n * @param txParams - Optional transaction parameters for customizing the transaction\n *\n * @returns Promise resolving to a Transaction or VersionedTransaction ready for signing\n *\n * @example\n * ```typescript\n * // Default configuration (16 order slots)\n * const transaction = await createRevenueShareEscrowTxn({\n * driftClient,\n * authority: userPublicKey,\n * txParams: { computeUnits: 300000 }\n * });\n *\n * // Custom configuration for power user\n * const transaction = await createRevenueShareEscrowTxn({\n * driftClient,\n * authority: userPublicKey,\n * numOrders: 32, // More concurrent capacity\n * txParams: { computeUnits: 300000 }\n * });\n *\n * // Sign and send the transaction\n * const signature = await wallet.sendTransaction(transaction, connection);\n * ```\n */\nexport const createRevenueShareEscrowTxn = async (\n\tparams: CreateRevenueShareEscrowTxnParams\n): Promise<Transaction | VersionedTransaction> => {\n\tconst createIx = await createRevenueShareEscrowIx(params);\n\tconst ixs = [createIx];\n\n\tif (params.builder) {\n\t\tconst addBuilderIx = await configureBuilderIx({\n\t\t\tdriftClient: params.driftClient,\n\t\t\tauthority: params.authority,\n\t\t\tbuilderAuthority: params.builder.builderAuthority,\n\t\t\tmaxFeeTenthBps: params.builder.maxFeeTenthBps,\n\t\t\tpayer: params.payer ?? params.authority,\n\t\t});\n\n\t\tixs.push(addBuilderIx);\n\t}\n\n\treturn params.driftClient.buildTransaction(ixs, params.txParams);\n};\n"]}
@@ -1,3 +1,3 @@
1
1
  export * from './createRevenueShareAccount';
2
2
  export * from './createRevenueShareEscrow';
3
- export * from './manageBuilder';
3
+ export * from './configureBuilder';
@@ -16,5 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./createRevenueShareAccount"), exports);
18
18
  __exportStar(require("./createRevenueShareEscrow"), exports);
19
- __exportStar(require("./manageBuilder"), exports);
19
+ __exportStar(require("./configureBuilder"), exports);
20
20
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/drift/base/actions/builder/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8DAA4C;AAC5C,6DAA2C;AAC3C,kDAAgC","sourcesContent":["export * from './createRevenueShareAccount';\nexport * from './createRevenueShareEscrow';\nexport * from './manageBuilder';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/drift/base/actions/builder/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8DAA4C;AAC5C,6DAA2C;AAC3C,qDAAmC","sourcesContent":["export * from './createRevenueShareAccount';\nexport * from './createRevenueShareEscrow';\nexport * from './configureBuilder';\n"]}
@@ -40,7 +40,7 @@ interface CreateSwiftAccountTxnParams extends CreateSwiftAccountIxParams {
40
40
  *
41
41
  * @returns The built transaction and the Swift account public key
42
42
  */
43
- export declare const createSwiftAccountTxn: ({ driftClient, authority, numOrders, rentPayerOverride: externalWallet, txParams, }: CreateSwiftAccountTxnParams) => Promise<{
43
+ export declare const createSwiftAccountTxn: ({ driftClient, authority, numOrders, rentPayerOverride, txParams, }: CreateSwiftAccountTxnParams) => Promise<{
44
44
  transaction: Transaction | VersionedTransaction;
45
45
  swiftAccountPublicKey: PublicKey;
46
46
  }>;
@@ -30,12 +30,12 @@ exports.createSwiftAccountIx = createSwiftAccountIx;
30
30
  *
31
31
  * @returns The built transaction and the Swift account public key
32
32
  */
33
- const createSwiftAccountTxn = async ({ driftClient, authority, numOrders, rentPayerOverride: externalWallet, txParams, }) => {
33
+ const createSwiftAccountTxn = async ({ driftClient, authority, numOrders, rentPayerOverride, txParams, }) => {
34
34
  const { swiftAccountPublicKey, ix } = await (0, exports.createSwiftAccountIx)({
35
35
  driftClient,
36
36
  authority,
37
37
  numOrders,
38
- rentPayerOverride: externalWallet,
38
+ rentPayerOverride,
39
39
  });
40
40
  const transaction = await driftClient.buildTransaction([ix], txParams);
41
41
  return { transaction, swiftAccountPublicKey };
@@ -1 +1 @@
1
- {"version":3,"file":"create.js","sourceRoot":"","sources":["../../../../../src/drift/base/actions/swift/create.ts"],"names":[],"mappings":";;;AAAA,yCAKyB;AAkBzB;;;;;;;;;GASG;AACI,MAAM,oBAAoB,GAAG,KAAK,EAAE,EAC1C,WAAW,EACX,SAAS,EACT,SAAS,GAAG,CAAC,EACb,iBAAiB,GACW,EAG1B,EAAE;IACJ,MAAM,CAAC,qBAAqB,EAAE,EAAE,CAAC,GAChC,MAAM,WAAW,CAAC,yCAAyC,CAC1D,SAAS,EACT,SAAS,EACT,EAAE,cAAc,EAAE,iBAAiB,EAAE,CACrC,CAAC;IAEH,OAAO,EAAE,qBAAqB,EAAE,EAAE,EAAE,CAAC;AACtC,CAAC,CAAC;AAjBW,QAAA,oBAAoB,wBAiB/B;AAMF;;;;;;;;;;;;GAYG;AACI,MAAM,qBAAqB,GAAG,KAAK,EAAE,EAC3C,WAAW,EACX,SAAS,EACT,SAAS,EACT,iBAAiB,EAAE,cAAc,EACjC,QAAQ,GACqB,EAG3B,EAAE;IACJ,MAAM,EAAE,qBAAqB,EAAE,EAAE,EAAE,GAAG,MAAM,IAAA,4BAAoB,EAAC;QAChE,WAAW;QACX,SAAS;QACT,SAAS;QACT,iBAAiB,EAAE,cAAc;KACjC,CAAC,CAAC;IAEH,MAAM,WAAW,GAAG,MAAM,WAAW,CAAC,gBAAgB,CAAC,CAAC,EAAE,CAAC,EAAE,QAAQ,CAAC,CAAC;IAEvE,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,CAAC;AAC/C,CAAC,CAAC;AApBW,QAAA,qBAAqB,yBAoBhC;AAEF;;;;;;;;;;;;GAYG;AACI,MAAM,+BAA+B,GAAG,KAAK,EAAE,EACrD,WAAW,EACX,SAAS,EACT,SAAS,GAAG,CAAC,EACb,iBAAiB,GACW,EAG1B,EAAE;IACJ,MAAM,aAAa,GAClB,MAAM,WAAW,CAAC,uCAAuC,CAAC,SAAS,CAAC,CAAC;IAEtE,IAAI,aAAa,EAAE,CAAC;QACnB,MAAM,qBAAqB,GAAG,IAAA,sCAAgC,EAC7D,WAAW,CAAC,OAAO,CAAC,SAAS,EAC7B,SAAS,CACT,CAAC;QAEF,OAAO,EAAE,qBAAqB,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC;IAC5C,CAAC;IAED,OAAO,MAAM,IAAA,4BAAoB,EAAC;QACjC,WAAW;QACX,SAAS;QACT,SAAS;QACT,iBAAiB;KACjB,CAAC,CAAC;AACJ,CAAC,CAAC;AA3BW,QAAA,+BAA+B,mCA2B1C","sourcesContent":["import {\n\tDriftClient,\n\tgetSignedMsgUserAccountPublicKey,\n\tPublicKey,\n\tTxParams,\n} from '@drift-labs/sdk';\nimport {\n\tTransaction,\n\tTransactionInstruction,\n\tVersionedTransaction,\n} from '@solana/web3.js';\n\ninterface CreateSwiftAccountIxParams {\n\tdriftClient: DriftClient;\n\tauthority: PublicKey;\n\tnumOrders?: number;\n\t/**\n\t * Optional external wallet to use as payer. If provided, this wallet will pay\n\t * for the account creation instead of the default wallet.\n\t */\n\trentPayerOverride?: PublicKey;\n}\n\n/**\n * Creates a transaction instruction for initializing a Swift (signed message user orders) account.\n *\n * @param driftClient - The Drift client instance\n * @param authority - The public key of the account authority\n * @param numOrders - The number of order slots to allocate (default: 8)\n * @param rentPayerOverride - Optional wallet to pay for account creation instead of the default wallet\n *\n * @returns The Swift account public key and the initialization instruction\n */\nexport const createSwiftAccountIx = async ({\n\tdriftClient,\n\tauthority,\n\tnumOrders = 8,\n\trentPayerOverride,\n}: CreateSwiftAccountIxParams): Promise<{\n\tswiftAccountPublicKey: PublicKey;\n\tix: TransactionInstruction;\n}> => {\n\tconst [swiftAccountPublicKey, ix] =\n\t\tawait driftClient.getInitializeSignedMsgUserOrdersAccountIx(\n\t\t\tauthority,\n\t\t\tnumOrders,\n\t\t\t{ externalWallet: rentPayerOverride }\n\t\t);\n\n\treturn { swiftAccountPublicKey, ix };\n};\n\ninterface CreateSwiftAccountTxnParams extends CreateSwiftAccountIxParams {\n\ttxParams?: TxParams;\n}\n\n/**\n * Creates a complete transaction for initializing a Swift (signed message user orders) account.\n *\n * Wraps {@link createSwiftAccountIx} and builds a transaction ready for signing and submission.\n *\n * @param driftClient - The Drift client instance\n * @param authority - The public key of the account authority\n * @param numOrders - The number of order slots to allocate (default: 8)\n * @param rentPayerOverride - Optional wallet to pay for account creation instead of the default wallet\n * @param txParams - Optional transaction parameters (compute units, priority fees, etc.)\n *\n * @returns The built transaction and the Swift account public key\n */\nexport const createSwiftAccountTxn = async ({\n\tdriftClient,\n\tauthority,\n\tnumOrders,\n\trentPayerOverride: externalWallet,\n\ttxParams,\n}: CreateSwiftAccountTxnParams): Promise<{\n\ttransaction: Transaction | VersionedTransaction;\n\tswiftAccountPublicKey: PublicKey;\n}> => {\n\tconst { swiftAccountPublicKey, ix } = await createSwiftAccountIx({\n\t\tdriftClient,\n\t\tauthority,\n\t\tnumOrders,\n\t\trentPayerOverride: externalWallet,\n\t});\n\n\tconst transaction = await driftClient.buildTransaction([ix], txParams);\n\n\treturn { transaction, swiftAccountPublicKey };\n};\n\n/**\n * Creates a Swift account instruction only if one doesn't already exist for the given authority.\n *\n * Always returns the Swift account public key. The `ix` will be `null` if the account\n * is already initialized, indicating no transaction is needed.\n *\n * @param driftClient - The Drift client instance\n * @param authority - The public key of the account authority\n * @param numOrders - The number of order slots to allocate (default: 8)\n * @param rentPayerOverride - Optional wallet to pay for account creation instead of the default wallet\n *\n * @returns The Swift account public key and the initialization instruction (null if already initialized)\n */\nexport const createSwiftAccountIxIfNotExists = async ({\n\tdriftClient,\n\tauthority,\n\tnumOrders = 8,\n\trentPayerOverride,\n}: CreateSwiftAccountIxParams): Promise<{\n\tswiftAccountPublicKey: PublicKey;\n\tix: TransactionInstruction | null;\n}> => {\n\tconst isInitialized =\n\t\tawait driftClient.isSignedMsgUserOrdersAccountInitialized(authority);\n\n\tif (isInitialized) {\n\t\tconst swiftAccountPublicKey = getSignedMsgUserAccountPublicKey(\n\t\t\tdriftClient.program.programId,\n\t\t\tauthority\n\t\t);\n\n\t\treturn { swiftAccountPublicKey, ix: null };\n\t}\n\n\treturn await createSwiftAccountIx({\n\t\tdriftClient,\n\t\tauthority,\n\t\tnumOrders,\n\t\trentPayerOverride,\n\t});\n};\n"]}
1
+ {"version":3,"file":"create.js","sourceRoot":"","sources":["../../../../../src/drift/base/actions/swift/create.ts"],"names":[],"mappings":";;;AAAA,yCAKyB;AAkBzB;;;;;;;;;GASG;AACI,MAAM,oBAAoB,GAAG,KAAK,EAAE,EAC1C,WAAW,EACX,SAAS,EACT,SAAS,GAAG,CAAC,EACb,iBAAiB,GACW,EAG1B,EAAE;IACJ,MAAM,CAAC,qBAAqB,EAAE,EAAE,CAAC,GAChC,MAAM,WAAW,CAAC,yCAAyC,CAC1D,SAAS,EACT,SAAS,EACT,EAAE,cAAc,EAAE,iBAAiB,EAAE,CACrC,CAAC;IAEH,OAAO,EAAE,qBAAqB,EAAE,EAAE,EAAE,CAAC;AACtC,CAAC,CAAC;AAjBW,QAAA,oBAAoB,wBAiB/B;AAMF;;;;;;;;;;;;GAYG;AACI,MAAM,qBAAqB,GAAG,KAAK,EAAE,EAC3C,WAAW,EACX,SAAS,EACT,SAAS,EACT,iBAAiB,EACjB,QAAQ,GACqB,EAG3B,EAAE;IACJ,MAAM,EAAE,qBAAqB,EAAE,EAAE,EAAE,GAAG,MAAM,IAAA,4BAAoB,EAAC;QAChE,WAAW;QACX,SAAS;QACT,SAAS;QACT,iBAAiB;KACjB,CAAC,CAAC;IAEH,MAAM,WAAW,GAAG,MAAM,WAAW,CAAC,gBAAgB,CAAC,CAAC,EAAE,CAAC,EAAE,QAAQ,CAAC,CAAC;IAEvE,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,CAAC;AAC/C,CAAC,CAAC;AApBW,QAAA,qBAAqB,yBAoBhC;AAEF;;;;;;;;;;;;GAYG;AACI,MAAM,+BAA+B,GAAG,KAAK,EAAE,EACrD,WAAW,EACX,SAAS,EACT,SAAS,GAAG,CAAC,EACb,iBAAiB,GACW,EAG1B,EAAE;IACJ,MAAM,aAAa,GAClB,MAAM,WAAW,CAAC,uCAAuC,CAAC,SAAS,CAAC,CAAC;IAEtE,IAAI,aAAa,EAAE,CAAC;QACnB,MAAM,qBAAqB,GAAG,IAAA,sCAAgC,EAC7D,WAAW,CAAC,OAAO,CAAC,SAAS,EAC7B,SAAS,CACT,CAAC;QAEF,OAAO,EAAE,qBAAqB,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC;IAC5C,CAAC;IAED,OAAO,MAAM,IAAA,4BAAoB,EAAC;QACjC,WAAW;QACX,SAAS;QACT,SAAS;QACT,iBAAiB;KACjB,CAAC,CAAC;AACJ,CAAC,CAAC;AA3BW,QAAA,+BAA+B,mCA2B1C","sourcesContent":["import {\n\tDriftClient,\n\tgetSignedMsgUserAccountPublicKey,\n\tPublicKey,\n\tTxParams,\n} from '@drift-labs/sdk';\nimport {\n\tTransaction,\n\tTransactionInstruction,\n\tVersionedTransaction,\n} from '@solana/web3.js';\n\ninterface CreateSwiftAccountIxParams {\n\tdriftClient: DriftClient;\n\tauthority: PublicKey;\n\tnumOrders?: number;\n\t/**\n\t * Optional external wallet to use as payer. If provided, this wallet will pay\n\t * for the account creation instead of the default wallet.\n\t */\n\trentPayerOverride?: PublicKey;\n}\n\n/**\n * Creates a transaction instruction for initializing a Swift (signed message user orders) account.\n *\n * @param driftClient - The Drift client instance\n * @param authority - The public key of the account authority\n * @param numOrders - The number of order slots to allocate (default: 8)\n * @param rentPayerOverride - Optional wallet to pay for account creation instead of the default wallet\n *\n * @returns The Swift account public key and the initialization instruction\n */\nexport const createSwiftAccountIx = async ({\n\tdriftClient,\n\tauthority,\n\tnumOrders = 8,\n\trentPayerOverride,\n}: CreateSwiftAccountIxParams): Promise<{\n\tswiftAccountPublicKey: PublicKey;\n\tix: TransactionInstruction;\n}> => {\n\tconst [swiftAccountPublicKey, ix] =\n\t\tawait driftClient.getInitializeSignedMsgUserOrdersAccountIx(\n\t\t\tauthority,\n\t\t\tnumOrders,\n\t\t\t{ externalWallet: rentPayerOverride }\n\t\t);\n\n\treturn { swiftAccountPublicKey, ix };\n};\n\ninterface CreateSwiftAccountTxnParams extends CreateSwiftAccountIxParams {\n\ttxParams?: TxParams;\n}\n\n/**\n * Creates a complete transaction for initializing a Swift (signed message user orders) account.\n *\n * Wraps {@link createSwiftAccountIx} and builds a transaction ready for signing and submission.\n *\n * @param driftClient - The Drift client instance\n * @param authority - The public key of the account authority\n * @param numOrders - The number of order slots to allocate (default: 8)\n * @param rentPayerOverride - Optional wallet to pay for account creation instead of the default wallet\n * @param txParams - Optional transaction parameters (compute units, priority fees, etc.)\n *\n * @returns The built transaction and the Swift account public key\n */\nexport const createSwiftAccountTxn = async ({\n\tdriftClient,\n\tauthority,\n\tnumOrders,\n\trentPayerOverride,\n\ttxParams,\n}: CreateSwiftAccountTxnParams): Promise<{\n\ttransaction: Transaction | VersionedTransaction;\n\tswiftAccountPublicKey: PublicKey;\n}> => {\n\tconst { swiftAccountPublicKey, ix } = await createSwiftAccountIx({\n\t\tdriftClient,\n\t\tauthority,\n\t\tnumOrders,\n\t\trentPayerOverride,\n\t});\n\n\tconst transaction = await driftClient.buildTransaction([ix], txParams);\n\n\treturn { transaction, swiftAccountPublicKey };\n};\n\n/**\n * Creates a Swift account instruction only if one doesn't already exist for the given authority.\n *\n * Always returns the Swift account public key. The `ix` will be `null` if the account\n * is already initialized, indicating no transaction is needed.\n *\n * @param driftClient - The Drift client instance\n * @param authority - The public key of the account authority\n * @param numOrders - The number of order slots to allocate (default: 8)\n * @param rentPayerOverride - Optional wallet to pay for account creation instead of the default wallet\n *\n * @returns The Swift account public key and the initialization instruction (null if already initialized)\n */\nexport const createSwiftAccountIxIfNotExists = async ({\n\tdriftClient,\n\tauthority,\n\tnumOrders = 8,\n\trentPayerOverride,\n}: CreateSwiftAccountIxParams): Promise<{\n\tswiftAccountPublicKey: PublicKey;\n\tix: TransactionInstruction | null;\n}> => {\n\tconst isInitialized =\n\t\tawait driftClient.isSignedMsgUserOrdersAccountInitialized(authority);\n\n\tif (isInitialized) {\n\t\tconst swiftAccountPublicKey = getSignedMsgUserAccountPublicKey(\n\t\t\tdriftClient.program.programId,\n\t\t\tauthority\n\t\t);\n\n\t\treturn { swiftAccountPublicKey, ix: null };\n\t}\n\n\treturn await createSwiftAccountIx({\n\t\tdriftClient,\n\t\tauthority,\n\t\tnumOrders,\n\t\trentPayerOverride,\n\t});\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/common",
3
- "version": "1.0.43",
3
+ "version": "1.0.44",
4
4
  "description": "Common functions for Drift",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -1 +0,0 @@
1
- {"version":3,"file":"manageBuilder.js","sourceRoot":"","sources":["../../../../../src/drift/base/actions/builder/manageBuilder.ts"],"names":[],"mappings":";;;AAwCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+DG;AACI,MAAM,eAAe,GAAG,KAAK,EACnC,MAA6B,EACK,EAAE;IACpC,MAAM,EAAE,WAAW,EAAE,gBAAgB,EAAE,cAAc,EAAE,SAAS,EAAE,KAAK,EAAE,GACxE,MAAM,CAAC;IAER,MAAM,QAAQ,GAAG,cAAc,KAAK,CAAC,CAAC;IAEtC,OAAO,WAAW,CAAC,0BAA0B,CAC5C,gBAAgB,EAChB,cAAc,EACd,CAAC,QAAQ,EAAE,8CAA8C;IACzD;QACC,SAAS;QACT,KAAK,EAAE,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,SAAS;KACzB,CACD,CAAC;AACH,CAAC,CAAC;AAjBW,QAAA,eAAe,mBAiB1B;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AACI,MAAM,gBAAgB,GAAG,KAAK,EACpC,MAA4C,EACE,EAAE;IAChD,OAAO,MAAM,CAAC,WAAW,CAAC,gBAAgB,CACzC,MAAM,IAAA,uBAAe,EAAC,MAAM,CAAC,EAC7B,MAAM,CAAC,QAAQ,CACf,CAAC;AACH,CAAC,CAAC;AAPW,QAAA,gBAAgB,oBAO3B","sourcesContent":["import { DriftClient } from '@drift-labs/sdk';\nimport {\n\tTransaction,\n\tTransactionInstruction,\n\tVersionedTransaction,\n\tPublicKey,\n} from '@solana/web3.js';\nimport { WithTxnParams } from '../../types';\n\ninterface ManageBuilderIxParams {\n\tdriftClient: DriftClient;\n\t/**\n\t * The public key of the builder to manage.\n\t * This is the builder's authority address that owns their RevenueShare account.\n\t */\n\tbuilderAuthority: PublicKey;\n\t/**\n\t * Maximum fee the builder can charge, in tenths of basis points.\n\t *\n\t * Examples:\n\t * - 10 = 1 bps = 0.01%\n\t * - 50 = 5 bps = 0.05%\n\t * - 100 = 10 bps = 0.1%\n\t * - 1000 = 100 bps = 1%\n\t *\n\t * Special values:\n\t * - Set to 0 to revoke the builder (they remain in list but cannot be used)\n\t */\n\tmaxFeeTenthBps: number;\n\t/**\n\t * The public key of the authority to add the builder to the approved builders list.\n\t */\n\tauthority: PublicKey;\n\t/**\n\t * The public key of the wallet that will pay for the transaction.\n\t * If not provided, the authority provided will be the payer.\n\t */\n\tpayer?: PublicKey;\n}\n\n/**\n * Creates a transaction instruction to manage a builder's approval status and fee cap.\n *\n * This unified function handles all builder management operations:\n * - **Approve**: Add a new builder to the approved list\n * - **Update**: Modify an existing builder's max fee cap\n * - **Revoke**: Disable a builder by setting their max fee to 0\n *\n * ## Behavior:\n *\n * ### If builder NOT in list:\n * - Adds builder with specified `maxFeeTenthBps`\n *\n * ### If builder already in list:\n * - Updates builder's `maxFeeTenthBps` to new value\n * - Set to 0 to revoke (builder stays in list but cannot be used)\n *\n * ## Revocation Constraints:\n * When setting `maxFeeTenthBps = 0`, the builder cannot have active orders:\n * - No Open orders using this builder\n * - No Completed (unsettled) orders using this builder\n * - Error: `CannotRevokeBuilderWithOpenOrders` if constraint violated\n *\n * **Prerequisites**:\n * - User must have initialized a RevenueShareEscrow account\n * - Builder must have initialized a RevenueShare account (for receiving fees)\n *\n * @param driftClient - The Drift client instance\n * @param builderAuthority - The public key of the builder to manage\n * @param maxFeeTenthBps - Maximum fee cap in tenths of basis points\n *\n * @returns Promise resolving to a TransactionInstruction\n *\n * @example\n * ```typescript\n * // Approve a new builder with 5 bps max fee\n * const ix = await manageBuilderIx({\n * driftClient,\n * builderAuthority: new PublicKey('BuilderAddress...'),\n * maxFeeTenthBps: 50 // 5 bps = 0.05%\n * });\n * ```\n *\n * @example\n * ```typescript\n * // Update existing builder to 10 bps max fee\n * const ix = await manageBuilderIx({\n * driftClient,\n * builderAuthority: builderPubkey,\n * maxFeeTenthBps: 100 // 10 bps = 0.1%\n * });\n * ```\n *\n * @example\n * ```typescript\n * // Revoke builder (set max fee to 0)\n * // IMPORTANT: Must settle all builder's orders first!\n * const ix = await manageBuilderIx({\n * driftClient,\n * builderAuthority: builderPubkey,\n * maxFeeTenthBps: 0 // Revoked\n * });\n * ```\n */\nexport const manageBuilderIx = async (\n\tparams: ManageBuilderIxParams\n): Promise<TransactionInstruction> => {\n\tconst { driftClient, builderAuthority, maxFeeTenthBps, authority, payer } =\n\t\tparams;\n\n\tconst isRevoke = maxFeeTenthBps === 0;\n\n\treturn driftClient.getChangeApprovedBuilderIx(\n\t\tbuilderAuthority,\n\t\tmaxFeeTenthBps,\n\t\t!isRevoke, // add = true (approve/update), false (revoke)\n\t\t{\n\t\t\tauthority,\n\t\t\tpayer: payer ?? authority,\n\t\t}\n\t);\n};\n\n/**\n * Creates a transaction to manage a builder's approval status and fee cap.\n *\n * This unified function handles all builder management operations:\n * - **Approve**: Add a new builder to the approved list\n * - **Update**: Modify an existing builder's max fee cap\n * - **Revoke**: Disable a builder by setting their max fee to 0\n *\n * ## Behavior:\n *\n * ### If builder NOT in list:\n * - Adds builder with specified `maxFeeTenthBps`\n *\n * ### If builder already in list:\n * - Updates builder's `maxFeeTenthBps` to new value\n * - Set to 0 to revoke (builder stays in list but cannot be used)\n *\n * ## Revocation Constraints:\n * When setting `maxFeeTenthBps = 0`, the builder cannot have active orders:\n * - No Open orders using this builder\n * - No Completed (unsettled) orders using this builder\n * - Error: `CannotRevokeBuilderWithOpenOrders` if constraint violated\n *\n * **Prerequisites**:\n * - User must have initialized a RevenueShareEscrow account\n * - Builder must have initialized a RevenueShare account (for receiving fees)\n *\n * @param driftClient - The Drift client instance\n * @param builderAuthority - The public key of the builder to manage\n * @param maxFeeTenthBps - Maximum fee cap in tenths of basis points\n * @param txParams - Optional transaction parameters for customizing the transaction\n *\n * @returns Promise resolving to a Transaction or VersionedTransaction ready for signing\n *\n * @example\n * ```typescript\n * // Approve a new builder with 2 bps max fee\n * const tx = await manageBuilderTxn({\n * driftClient,\n * builderAuthority: new PublicKey('BuilderAddress...'),\n * maxFeeTenthBps: 20,\n * txParams: { computeUnits: 200000 }\n * });\n *\n * const signature = await wallet.sendTransaction(tx, connection);\n * ```\n\n * @example\n * ```typescript\n * // Update existing builder's fee\n * await manageBuilderTxn({\n * driftClient,\n * builderAuthority: builderPubkey,\n * maxFeeTenthBps: 100 // Increase to 10 bps\n * });\n * ```\n */\nexport const manageBuilderTxn = async (\n\tparams: WithTxnParams<ManageBuilderIxParams>\n): Promise<Transaction | VersionedTransaction> => {\n\treturn params.driftClient.buildTransaction(\n\t\tawait manageBuilderIx(params),\n\t\tparams.txParams\n\t);\n};\n"]}