@drift-labs/sdk 2.76.0-beta.9 → 2.77.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/VERSION CHANGED
@@ -1 +1 @@
1
- 2.76.0-beta.9
1
+ 2.77.0-beta.1
@@ -11,6 +11,8 @@ export declare class AdminClient extends DriftClient {
11
11
  getInitializeSpotMarketIx(mint: PublicKey, optimalUtilization: number, optimalRate: number, maxRate: number, oracle: PublicKey, oracleSource: OracleSource, initialAssetWeight: number, maintenanceAssetWeight: number, initialLiabilityWeight: number, maintenanceLiabilityWeight: number, imfFactor?: number, liquidatorFee?: number, ifLiquidationFee?: number, activeStatus?: boolean, assetTier?: {
12
12
  collateral: {};
13
13
  }, scaleInitialAssetWeightStart?: BN, withdrawGuardThreshold?: BN, orderTickSize?: BN, orderStepSize?: BN, ifTotalFactor?: number, name?: string): Promise<TransactionInstruction>;
14
+ deleteInitializedSpotMarket(marketIndex: number): Promise<TransactionSignature>;
15
+ getDeleteInitializedSpotMarketIx(marketIndex: number): Promise<TransactionInstruction>;
14
16
  initializeSerumFulfillmentConfig(marketIndex: number, serumMarket: PublicKey, serumProgram: PublicKey): Promise<TransactionSignature>;
15
17
  getInitializeSerumFulfillmentConfigIx(marketIndex: number, serumMarket: PublicKey, serumProgram: PublicKey): Promise<TransactionInstruction>;
16
18
  initializePhoenixFulfillmentConfig(marketIndex: number, phoenixMarket: PublicKey): Promise<TransactionSignature>;
@@ -100,6 +100,30 @@ class AdminClient extends driftClient_1.DriftClient {
100
100
  });
101
101
  return initializeIx;
102
102
  }
103
+ async deleteInitializedSpotMarket(marketIndex) {
104
+ const deleteInitializeMarketIx = await this.getDeleteInitializedSpotMarketIx(marketIndex);
105
+ const tx = await this.buildTransaction(deleteInitializeMarketIx);
106
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
107
+ return txSig;
108
+ }
109
+ async getDeleteInitializedSpotMarketIx(marketIndex) {
110
+ const spotMarketPublicKey = await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, marketIndex);
111
+ const spotMarketVaultPublicKey = await (0, pda_1.getSpotMarketVaultPublicKey)(this.program.programId, marketIndex);
112
+ const insuranceFundVaultPublicKey = await (0, pda_1.getInsuranceFundVaultPublicKey)(this.program.programId, marketIndex);
113
+ return await this.program.instruction.deleteInitializedSpotMarket(marketIndex, {
114
+ accounts: {
115
+ state: await this.getStatePublicKey(),
116
+ admin: this.isSubscribed
117
+ ? this.getStateAccount().admin
118
+ : this.wallet.publicKey,
119
+ spotMarket: spotMarketPublicKey,
120
+ spotMarketVault: spotMarketVaultPublicKey,
121
+ insuranceFundVault: insuranceFundVaultPublicKey,
122
+ driftSigner: this.getSignerPublicKey(),
123
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
124
+ },
125
+ });
126
+ }
103
127
  async initializeSerumFulfillmentConfig(marketIndex, serumMarket, serumProgram) {
104
128
  const initializeIx = await this.getInitializeSerumFulfillmentConfigIx(marketIndex, serumMarket, serumProgram);
105
129
  const tx = await this.buildTransaction(initializeIx);
@@ -546,6 +546,16 @@ exports.MainnetPerpMarkets = [
546
546
  launchTs: 1712240681000,
547
547
  oracleSource: __1.OracleSource.Prelaunch,
548
548
  },
549
+ {
550
+ fullName: 'Tensor',
551
+ category: ['NFT', 'Solana'],
552
+ symbol: 'TNSR-PERP',
553
+ baseAssetSymbol: 'TNSR',
554
+ marketIndex: 29,
555
+ oracle: new web3_js_1.PublicKey('7Cfyymx49ipGsgEsCA2XygAB2DUsan4C6Cyb5c8oR5st'),
556
+ launchTs: 1712593532000,
557
+ oracleSource: __1.OracleSource.SWITCHBOARD,
558
+ },
549
559
  ];
550
560
  exports.PerpMarkets = {
551
561
  devnet: exports.DevnetPerpMarkets,
@@ -186,6 +186,17 @@ exports.MainnetSpotMarkets = [
186
186
  phoenixMarket: new web3_js_1.PublicKey('8dFTCTAbtGuHsdDL8WEPrTU6pXFDrU1QSjBTutw8fwZk'),
187
187
  launchTs: 1712149014000,
188
188
  },
189
+ {
190
+ symbol: 'TNSR',
191
+ marketIndex: 14,
192
+ oracle: new web3_js_1.PublicKey('7Cfyymx49ipGsgEsCA2XygAB2DUsan4C6Cyb5c8oR5st'),
193
+ oracleSource: __1.OracleSource.SWITCHBOARD,
194
+ mint: new web3_js_1.PublicKey('TNSRxcUxoT9xBG3de7PiJyTDYu7kskLqcpddxnEJAS6'),
195
+ precision: new __1.BN(10).pow(numericConstants_1.NINE),
196
+ precisionExp: numericConstants_1.NINE,
197
+ phoenixMarket: new web3_js_1.PublicKey('AbJCZ9TAJiby5AY3cHcXS2gUdENC6mtsm6m7XpC2ZMvE'),
198
+ launchTs: 1712593532000,
199
+ },
189
200
  ];
190
201
  exports.SpotMarkets = {
191
202
  devnet: exports.DevnetSpotMarkets,
@@ -112,7 +112,8 @@ export declare class DriftClient {
112
112
  * Adds and subscribes to users based on params set by the constructor or by updateWallet.
113
113
  */
114
114
  addAndSubscribeToUsers(): Promise<boolean>;
115
- initializeUserAccount(subAccountId?: number, name?: string, referrerInfo?: ReferrerInfo): Promise<[TransactionSignature, PublicKey]>;
115
+ private getProcessedTransactionParams;
116
+ initializeUserAccount(subAccountId?: number, name?: string, referrerInfo?: ReferrerInfo, txParams?: TxParams): Promise<[TransactionSignature, PublicKey]>;
116
117
  getInitializeUserInstructions(subAccountId?: number, name?: string, referrerInfo?: ReferrerInfo): Promise<[PublicKey, TransactionInstruction]>;
117
118
  getInitializeUserStatsIx(): Promise<TransactionInstruction>;
118
119
  getNextSubAccountId(): Promise<number>;
@@ -249,7 +250,7 @@ export declare class DriftClient {
249
250
  * @returns
250
251
  */
251
252
  initializeUserAccountAndDepositCollateral(amount: BN, userTokenAccount: PublicKey, marketIndex?: number, subAccountId?: number, name?: string, fromSubAccountId?: number, referrerInfo?: ReferrerInfo, donateAmount?: BN, txParams?: TxParams, customMaxMarginRatio?: number): Promise<[TransactionSignature, PublicKey]>;
252
- initializeUserAccountForDevnet(subAccountId: number, name: string, marketIndex: number, tokenFaucet: TokenFaucet, amount: BN, referrerInfo?: ReferrerInfo): Promise<[TransactionSignature, PublicKey]>;
253
+ initializeUserAccountForDevnet(subAccountId: number, name: string, marketIndex: number, tokenFaucet: TokenFaucet, amount: BN, referrerInfo?: ReferrerInfo, txParams?: TxParams): Promise<[TransactionSignature, PublicKey]>;
253
254
  /**
254
255
  * Withdraws from a user account. If deposit doesn't already exist, creates a borrow
255
256
  * @param amount
@@ -661,6 +662,15 @@ export declare class DriftClient {
661
662
  } | undefined;
662
663
  private handleSignedTransaction;
663
664
  sendTransaction(tx: Transaction | VersionedTransaction, additionalSigners?: Array<Signer>, opts?: ConfirmOptions, preSigned?: boolean): Promise<TxSigAndSlot>;
664
- buildTransaction(instructions: TransactionInstruction | TransactionInstruction[], txParams?: TxParams, txVersion?: TransactionVersion, lookupTables?: AddressLookupTableAccount[]): Promise<Transaction | VersionedTransaction>;
665
+ /**
666
+ *
667
+ * @param instructions
668
+ * @param txParams
669
+ * @param txVersion
670
+ * @param lookupTables
671
+ * @param forceVersionedTransaction Return a VersionedTransaction instance even if the version of the transaction is Legacy
672
+ * @returns
673
+ */
674
+ buildTransaction(instructions: TransactionInstruction | TransactionInstruction[], txParams?: TxParams, txVersion?: TransactionVersion, lookupTables?: AddressLookupTableAccount[], forceVersionedTransaction?: boolean): Promise<Transaction | VersionedTransaction>;
665
675
  }
666
676
  export {};
@@ -56,6 +56,7 @@ const memcmp_1 = require("./memcmp");
56
56
  const marinade_1 = require("./marinade");
57
57
  const orderParams_1 = require("./orderParams");
58
58
  const utils_2 = require("./math/utils");
59
+ const txParamProcessor_1 = require("./tx/txParamProcessor");
59
60
  /**
60
61
  * # DriftClient
61
62
  * This class is the main way to interact with Drift Protocol. It allows you to subscribe to the various accounts where the Market's state is stored, as well as: opening positions, liquidating, settling funding, depositing & withdrawing, and more.
@@ -437,7 +438,23 @@ class DriftClient {
437
438
  }
438
439
  return result;
439
440
  }
440
- async initializeUserAccount(subAccountId = 0, name, referrerInfo) {
441
+ async getProcessedTransactionParams(txParams, txParamProcessingParams) {
442
+ const tx = await txParamProcessor_1.TransactionProcessor.process({
443
+ txProps: {
444
+ instructions: txParams.instructions,
445
+ txParams: txParams.txParams,
446
+ txVersion: txParams.txVersion,
447
+ lookupTables: txParams.lookupTables,
448
+ },
449
+ txBuilder: (updatedTxParams) => this.buildTransaction(updatedTxParams.instructions, updatedTxParams === null || updatedTxParams === void 0 ? void 0 : updatedTxParams.txParams, updatedTxParams.txVersion, updatedTxParams.lookupTables, true),
450
+ processConfig: txParamProcessingParams,
451
+ processParams: {
452
+ connection: this.connection,
453
+ },
454
+ });
455
+ return tx;
456
+ }
457
+ async initializeUserAccount(subAccountId = 0, name, referrerInfo, txParams) {
441
458
  const initializeIxs = [];
442
459
  const [userAccountPublicKey, initializeUserAccountIx] = await this.getInitializeUserInstructions(subAccountId, name, referrerInfo);
443
460
  if (subAccountId === 0) {
@@ -446,7 +463,7 @@ class DriftClient {
446
463
  }
447
464
  }
448
465
  initializeIxs.push(initializeUserAccountIx);
449
- const tx = await this.buildTransaction(initializeIxs);
466
+ const tx = await this.buildTransaction(initializeIxs, txParams);
450
467
  const { txSig } = await this.sendTransaction(tx, [], this.opts);
451
468
  await this.addUser(subAccountId);
452
469
  return [txSig, userAccountPublicKey];
@@ -1147,21 +1164,11 @@ class DriftClient {
1147
1164
  * @returns
1148
1165
  */
1149
1166
  async initializeUserAccountAndDepositCollateral(amount, userTokenAccount, marketIndex = 0, subAccountId = 0, name, fromSubAccountId, referrerInfo, donateAmount, txParams, customMaxMarginRatio) {
1150
- var _a;
1151
1167
  const ixs = [];
1152
1168
  const [userAccountPublicKey, initializeUserAccountIx] = await this.getInitializeUserInstructions(subAccountId, name, referrerInfo);
1153
1169
  const additionalSigners = [];
1154
1170
  const spotMarket = this.getSpotMarketAccount(marketIndex);
1155
1171
  const isSolMarket = spotMarket.mint.equals(spotMarkets_1.WRAPPED_SOL_MINT);
1156
- let params = {
1157
- computeUnits: (_a = txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits) !== null && _a !== void 0 ? _a : 600000,
1158
- };
1159
- if (txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice) {
1160
- params = {
1161
- ...params,
1162
- computeUnitsPrice: txParams.computeUnitsPrice,
1163
- };
1164
- }
1165
1172
  const authority = this.wallet.publicKey;
1166
1173
  const isFromSubaccount = fromSubAccountId !== null &&
1167
1174
  fromSubAccountId !== undefined &&
@@ -1203,13 +1210,13 @@ class DriftClient {
1203
1210
  if (createWSOLTokenAccount) {
1204
1211
  ixs.push((0, spl_token_1.createCloseAccountInstruction)(wsolTokenAccount, authority, authority, []));
1205
1212
  }
1206
- const tx = await this.buildTransaction(ixs, params);
1213
+ const tx = await this.buildTransaction(ixs, txParams);
1207
1214
  const { txSig, slot } = await this.sendTransaction(tx, additionalSigners, this.opts);
1208
1215
  this.spotMarketLastSlotCache.set(marketIndex, slot);
1209
1216
  await this.addUser(subAccountId);
1210
1217
  return [txSig, userAccountPublicKey];
1211
1218
  }
1212
- async initializeUserAccountForDevnet(subAccountId = 0, name = userName_1.DEFAULT_USER_NAME, marketIndex, tokenFaucet, amount, referrerInfo) {
1219
+ async initializeUserAccountForDevnet(subAccountId = 0, name = userName_1.DEFAULT_USER_NAME, marketIndex, tokenFaucet, amount, referrerInfo, txParams) {
1213
1220
  const ixs = [];
1214
1221
  const [associateTokenPublicKey, createAssociatedAccountIx, mintToIx] = await tokenFaucet.createAssociatedTokenAccountAndMintToInstructions(this.wallet.publicKey, amount);
1215
1222
  const [userAccountPublicKey, initializeUserAccountIx] = await this.getInitializeUserInstructions(subAccountId, name, referrerInfo);
@@ -1221,7 +1228,7 @@ class DriftClient {
1221
1228
  }
1222
1229
  }
1223
1230
  ixs.push(initializeUserAccountIx, depositCollateralIx);
1224
- const tx = await this.buildTransaction(ixs);
1231
+ const tx = await this.buildTransaction(ixs, txParams);
1225
1232
  const { txSig } = await this.sendTransaction(tx, [], this.opts);
1226
1233
  await this.addUser(subAccountId);
1227
1234
  return [txSig, userAccountPublicKey];
@@ -1258,10 +1265,7 @@ class DriftClient {
1258
1265
  if (createWSOLTokenAccount) {
1259
1266
  withdrawIxs.push((0, spl_token_1.createCloseAccountInstruction)(associatedTokenAddress, authority, authority, []));
1260
1267
  }
1261
- const tx = await this.buildTransaction(withdrawIxs, {
1262
- ...(txParams !== null && txParams !== void 0 ? txParams : this.txParams),
1263
- computeUnits: 1400000,
1264
- });
1268
+ const tx = await this.buildTransaction(withdrawIxs, txParams !== null && txParams !== void 0 ? txParams : this.txParams);
1265
1269
  const { txSig, slot } = await this.sendTransaction(tx, additionalSigners, this.opts);
1266
1270
  this.spotMarketLastSlotCache.set(marketIndex, slot);
1267
1271
  return txSig;
@@ -2512,12 +2516,26 @@ class DriftClient {
2512
2516
  const bracketOrdersIx = await this.getPlaceOrdersIx(bracketOrdersParams, subAccountId);
2513
2517
  ixs.push(bracketOrdersIx);
2514
2518
  }
2515
- const placeAndTakeTx = (await this.buildTransaction(ixs, txParams));
2516
- // if param is passed, return early before the tx fails so ui can fallback to placeOrder
2517
- if (simulateFirst) {
2518
- const success = await this.txSender.simulateTransaction(placeAndTakeTx);
2519
- if (!success)
2519
+ const shouldUseSimulationComputeUnits = txParams === null || txParams === void 0 ? void 0 : txParams.useSimulatedComputeUnits;
2520
+ const shouldExitIfSimulationFails = simulateFirst;
2521
+ const txParamsWithoutImplicitSimulation = {
2522
+ ...txParams,
2523
+ useSimulationComputeUnits: false,
2524
+ };
2525
+ let placeAndTakeTx = await this.buildTransaction(ixs, txParamsWithoutImplicitSimulation);
2526
+ if (shouldUseSimulationComputeUnits || shouldExitIfSimulationFails) {
2527
+ const simulationResult = await txParamProcessor_1.TransactionProcessor.getTxSimComputeUnits(
2528
+ // @ts-ignore :: TODO - TEST WITH LEGACY TRANSACTION
2529
+ placeAndTakeTx, this.connection);
2530
+ if (shouldExitIfSimulationFails && !simulationResult.success) {
2520
2531
  return;
2532
+ }
2533
+ if (shouldUseSimulationComputeUnits) {
2534
+ placeAndTakeTx = await this.buildTransaction(ixs, {
2535
+ ...txParamsWithoutImplicitSimulation,
2536
+ computeUnits: simulationResult.computeUnits,
2537
+ });
2538
+ }
2521
2539
  }
2522
2540
  let cancelExistingOrdersTx;
2523
2541
  if (cancelExistingOrders && (0, types_1.isVariant)(orderParams.marketType, 'perp')) {
@@ -3506,23 +3524,63 @@ class DriftClient {
3506
3524
  onSignedCb: this.handleSignedTransaction.bind(this),
3507
3525
  }
3508
3526
  : undefined;
3509
- if (tx instanceof web3_js_1.VersionedTransaction) {
3527
+ const version = tx === null || tx === void 0 ? void 0 : tx.version;
3528
+ const isVersionedTx = tx instanceof web3_js_1.VersionedTransaction || version !== undefined;
3529
+ if (isVersionedTx) {
3510
3530
  return this.txSender.sendVersionedTransaction(tx, additionalSigners, opts, preSigned, extraConfirmationOptions);
3511
3531
  }
3512
3532
  else {
3513
3533
  return this.txSender.send(tx, additionalSigners, opts, preSigned, extraConfirmationOptions);
3514
3534
  }
3515
3535
  }
3516
- async buildTransaction(instructions, txParams, txVersion, lookupTables) {
3536
+ /**
3537
+ *
3538
+ * @param instructions
3539
+ * @param txParams
3540
+ * @param txVersion
3541
+ * @param lookupTables
3542
+ * @param forceVersionedTransaction Return a VersionedTransaction instance even if the version of the transaction is Legacy
3543
+ * @returns
3544
+ */
3545
+ async buildTransaction(instructions, txParams, txVersion, lookupTables, forceVersionedTransaction) {
3517
3546
  var _a, _b;
3547
+ txVersion = txVersion !== null && txVersion !== void 0 ? txVersion : this.txVersion;
3548
+ // # Collect and process Tx Params
3549
+ let baseTxParams = {
3550
+ computeUnits: (_a = txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits) !== null && _a !== void 0 ? _a : this.txParams.computeUnits,
3551
+ computeUnitsPrice: (_b = txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice) !== null && _b !== void 0 ? _b : this.txParams.computeUnitsPrice,
3552
+ };
3553
+ if (txParams === null || txParams === void 0 ? void 0 : txParams.useSimulatedComputeUnits) {
3554
+ const splitTxParams = {
3555
+ baseTxParams: {
3556
+ computeUnits: txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits,
3557
+ computeUnitsPrice: txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice,
3558
+ },
3559
+ txParamProcessingParams: {
3560
+ useSimulatedComputeUnits: txParams === null || txParams === void 0 ? void 0 : txParams.useSimulatedComputeUnits,
3561
+ computeUnitsBufferMultiplier: txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsBufferMultiplier,
3562
+ },
3563
+ };
3564
+ const processedTxParams = await this.getProcessedTransactionParams({
3565
+ instructions,
3566
+ txParams: splitTxParams.baseTxParams,
3567
+ txVersion,
3568
+ lookupTables,
3569
+ }, splitTxParams.txParamProcessingParams);
3570
+ baseTxParams = {
3571
+ ...baseTxParams,
3572
+ ...processedTxParams,
3573
+ };
3574
+ }
3575
+ // # Create Tx Instructions
3518
3576
  const allIx = [];
3519
- const computeUnits = (_a = txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits) !== null && _a !== void 0 ? _a : this.txParams.computeUnits;
3577
+ const computeUnits = baseTxParams === null || baseTxParams === void 0 ? void 0 : baseTxParams.computeUnits;
3520
3578
  if (computeUnits !== 200000) {
3521
3579
  allIx.push(web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({
3522
3580
  units: computeUnits,
3523
3581
  }));
3524
3582
  }
3525
- const computeUnitsPrice = (_b = txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice) !== null && _b !== void 0 ? _b : this.txParams.computeUnitsPrice;
3583
+ const computeUnitsPrice = baseTxParams === null || baseTxParams === void 0 ? void 0 : baseTxParams.computeUnitsPrice;
3526
3584
  if (computeUnitsPrice !== 0) {
3527
3585
  allIx.push(web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({
3528
3586
  microLamports: computeUnitsPrice,
@@ -3534,9 +3592,22 @@ class DriftClient {
3534
3592
  else {
3535
3593
  allIx.push(instructions);
3536
3594
  }
3537
- txVersion = txVersion !== null && txVersion !== void 0 ? txVersion : this.txVersion;
3595
+ const latestBlockHashAndContext = await this.connection.getLatestBlockhashAndContext({
3596
+ commitment: this.opts.preflightCommitment,
3597
+ });
3598
+ // # Create and return Transaction
3538
3599
  if (txVersion === 'legacy') {
3539
- return new web3_js_1.Transaction().add(...allIx);
3600
+ if (forceVersionedTransaction) {
3601
+ const message = new web3_js_1.TransactionMessage({
3602
+ payerKey: this.provider.wallet.publicKey,
3603
+ recentBlockhash: latestBlockHashAndContext.value.blockhash,
3604
+ instructions: allIx,
3605
+ }).compileToLegacyMessage();
3606
+ return new web3_js_1.VersionedTransaction(message);
3607
+ }
3608
+ else {
3609
+ return new web3_js_1.Transaction().add(...allIx);
3610
+ }
3540
3611
  }
3541
3612
  else {
3542
3613
  const marketLookupTable = await this.fetchMarketLookupTableAccount();
@@ -3545,7 +3616,7 @@ class DriftClient {
3545
3616
  : [marketLookupTable];
3546
3617
  const message = new web3_js_1.TransactionMessage({
3547
3618
  payerKey: this.provider.wallet.publicKey,
3548
- recentBlockhash: (await this.provider.connection.getRecentBlockhash(this.opts.preflightCommitment)).blockhash,
3619
+ recentBlockhash: latestBlockHashAndContext.value.blockhash,
3549
3620
  instructions: allIx,
3550
3621
  }).compileToV0Message(lookupTables);
3551
3622
  return new web3_js_1.VersionedTransaction(message);
@@ -2696,6 +2696,52 @@
2696
2696
  }
2697
2697
  ]
2698
2698
  },
2699
+ {
2700
+ "name": "deleteInitializedSpotMarket",
2701
+ "accounts": [
2702
+ {
2703
+ "name": "admin",
2704
+ "isMut": true,
2705
+ "isSigner": true
2706
+ },
2707
+ {
2708
+ "name": "state",
2709
+ "isMut": true,
2710
+ "isSigner": false
2711
+ },
2712
+ {
2713
+ "name": "spotMarket",
2714
+ "isMut": true,
2715
+ "isSigner": false
2716
+ },
2717
+ {
2718
+ "name": "spotMarketVault",
2719
+ "isMut": true,
2720
+ "isSigner": false
2721
+ },
2722
+ {
2723
+ "name": "insuranceFundVault",
2724
+ "isMut": true,
2725
+ "isSigner": false
2726
+ },
2727
+ {
2728
+ "name": "driftSigner",
2729
+ "isMut": false,
2730
+ "isSigner": false
2731
+ },
2732
+ {
2733
+ "name": "tokenProgram",
2734
+ "isMut": false,
2735
+ "isSigner": false
2736
+ }
2737
+ ],
2738
+ "args": [
2739
+ {
2740
+ "name": "marketIndex",
2741
+ "type": "u16"
2742
+ }
2743
+ ]
2744
+ },
2699
2745
  {
2700
2746
  "name": "initializeSerumFulfillmentConfig",
2701
2747
  "accounts": [
@@ -0,0 +1,3 @@
1
+ import { HeliusPriorityFeeLevels } from './heliusPriorityFeeMethod';
2
+ export type DriftPriorityFeeResponse = HeliusPriorityFeeLevels[];
3
+ export declare function fetchDriftPriorityFee(url: string, marketTypes: string[], marketIndexs: number[]): Promise<DriftPriorityFeeResponse>;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.fetchDriftPriorityFee = void 0;
7
+ const node_fetch_1 = __importDefault(require("node-fetch"));
8
+ async function fetchDriftPriorityFee(url, marketTypes, marketIndexs) {
9
+ const response = await (0, node_fetch_1.default)(`${url}/batchPriorityFees?marketType=${marketTypes.join(',')}&marketIndex=${marketIndexs.join(',')}`);
10
+ return await response.json();
11
+ }
12
+ exports.fetchDriftPriorityFee = fetchDriftPriorityFee;
@@ -3,10 +3,15 @@ import { PriorityFeeMethod, PriorityFeeStrategy, PriorityFeeSubscriberConfig } f
3
3
  import { AverageOverSlotsStrategy } from './averageOverSlotsStrategy';
4
4
  import { MaxOverSlotsStrategy } from './maxOverSlotsStrategy';
5
5
  import { HeliusPriorityFeeLevels, HeliusPriorityLevel } from './heliusPriorityFeeMethod';
6
+ export type DriftMarketInfo = {
7
+ marketType: string;
8
+ marketIndex: number;
9
+ };
6
10
  export declare class PriorityFeeSubscriber {
7
11
  connection: Connection;
8
12
  frequencyMs: number;
9
13
  addresses: string[];
14
+ driftMarkets?: DriftMarketInfo[];
10
15
  customStrategy?: PriorityFeeStrategy;
11
16
  averageStrategy: AverageOverSlotsStrategy;
12
17
  maxStrategy: MaxOverSlotsStrategy;
@@ -14,6 +19,7 @@ export declare class PriorityFeeSubscriber {
14
19
  lookbackDistance: number;
15
20
  maxFeeMicroLamports?: number;
16
21
  priorityFeeMultiplier?: number;
22
+ driftPriorityFeeEndpoint?: string;
17
23
  heliusRpcUrl?: string;
18
24
  lastHeliusSample?: HeliusPriorityFeeLevels;
19
25
  intervalId?: ReturnType<typeof setTimeout>;
@@ -26,6 +32,7 @@ export declare class PriorityFeeSubscriber {
26
32
  subscribe(): Promise<void>;
27
33
  private loadForSolana;
28
34
  private loadForHelius;
35
+ private loadForDrift;
29
36
  getMaxPriorityFee(): number | undefined;
30
37
  updateMaxPriorityFee(newMaxFee: number | undefined): void;
31
38
  getPriorityFeeMultiplier(): number;
@@ -38,4 +45,5 @@ export declare class PriorityFeeSubscriber {
38
45
  load(): Promise<void>;
39
46
  unsubscribe(): Promise<void>;
40
47
  updateAddresses(addresses: PublicKey[]): void;
48
+ updateMarketTypeAndIndex(driftMarkets: DriftMarketInfo[]): void;
41
49
  }
@@ -6,6 +6,7 @@ const averageOverSlotsStrategy_1 = require("./averageOverSlotsStrategy");
6
6
  const maxOverSlotsStrategy_1 = require("./maxOverSlotsStrategy");
7
7
  const solanaPriorityFeeMethod_1 = require("./solanaPriorityFeeMethod");
8
8
  const heliusPriorityFeeMethod_1 = require("./heliusPriorityFeeMethod");
9
+ const driftPriorityFeeMethod_1 = require("./driftPriorityFeeMethod");
9
10
  class PriorityFeeSubscriber {
10
11
  constructor(config) {
11
12
  var _a, _b;
@@ -19,7 +20,10 @@ class PriorityFeeSubscriber {
19
20
  this.lastSlotSeen = 0;
20
21
  this.connection = config.connection;
21
22
  this.frequencyMs = config.frequencyMs;
22
- this.addresses = config.addresses.map((address) => address.toBase58());
23
+ this.addresses = config.addresses
24
+ ? config.addresses.map((address) => address.toBase58())
25
+ : [];
26
+ this.driftMarkets = config.driftMarkets;
23
27
  if (config.customStrategy) {
24
28
  this.customStrategy = config.customStrategy;
25
29
  }
@@ -42,6 +46,9 @@ class PriorityFeeSubscriber {
42
46
  this.heliusRpcUrl = config.heliusRpcUrl;
43
47
  }
44
48
  }
49
+ else if (this.priorityFeeMethod === types_1.PriorityFeeMethod.DRIFT) {
50
+ this.driftPriorityFeeEndpoint = config.driftPriorityFeeEndpoint;
51
+ }
45
52
  }
46
53
  if (this.priorityFeeMethod === types_1.PriorityFeeMethod.SOLANA) {
47
54
  if (this.connection === undefined) {
@@ -74,9 +81,22 @@ class PriorityFeeSubscriber {
74
81
  this.lastHeliusSample = (_b = (_a = sample === null || sample === void 0 ? void 0 : sample.result) === null || _a === void 0 ? void 0 : _a.priorityFeeLevels) !== null && _b !== void 0 ? _b : undefined;
75
82
  if (this.lastHeliusSample) {
76
83
  this.lastAvgStrategyResult =
77
- this.heliusRpcUrl[heliusPriorityFeeMethod_1.HeliusPriorityLevel.MEDIUM];
84
+ this.lastHeliusSample[heliusPriorityFeeMethod_1.HeliusPriorityLevel.MEDIUM];
78
85
  this.lastMaxStrategyResult =
79
- this.heliusRpcUrl[heliusPriorityFeeMethod_1.HeliusPriorityLevel.UNSAFE_MAX];
86
+ this.lastHeliusSample[heliusPriorityFeeMethod_1.HeliusPriorityLevel.UNSAFE_MAX];
87
+ if (this.customStrategy) {
88
+ this.lastCustomStrategyResult = this.customStrategy.calculate(sample);
89
+ }
90
+ }
91
+ }
92
+ async loadForDrift() {
93
+ if (!this.driftMarkets) {
94
+ return;
95
+ }
96
+ const sample = await (0, driftPriorityFeeMethod_1.fetchDriftPriorityFee)(this.driftPriorityFeeEndpoint, this.driftMarkets.map((m) => m.marketType), this.driftMarkets.map((m) => m.marketIndex));
97
+ if (sample.length > 0) {
98
+ this.lastAvgStrategyResult = sample[heliusPriorityFeeMethod_1.HeliusPriorityLevel.MEDIUM];
99
+ this.lastMaxStrategyResult = sample[heliusPriorityFeeMethod_1.HeliusPriorityLevel.UNSAFE_MAX];
80
100
  if (this.customStrategy) {
81
101
  this.lastCustomStrategyResult = this.customStrategy.calculate(sample);
82
102
  }
@@ -136,6 +156,9 @@ class PriorityFeeSubscriber {
136
156
  else if (this.priorityFeeMethod === types_1.PriorityFeeMethod.HELIUS) {
137
157
  await this.loadForHelius();
138
158
  }
159
+ else if (this.priorityFeeMethod === types_1.PriorityFeeMethod.DRIFT) {
160
+ await this.loadForDrift();
161
+ }
139
162
  else {
140
163
  throw new Error(`${this.priorityFeeMethod} load not implemented`);
141
164
  }
@@ -155,5 +178,8 @@ class PriorityFeeSubscriber {
155
178
  updateAddresses(addresses) {
156
179
  this.addresses = addresses.map((k) => k.toBase58());
157
180
  }
181
+ updateMarketTypeAndIndex(driftMarkets) {
182
+ this.driftMarkets = driftMarkets;
183
+ }
158
184
  }
159
185
  exports.PriorityFeeSubscriber = PriorityFeeSubscriber;
@@ -1,21 +1,26 @@
1
1
  import { Connection, PublicKey } from '@solana/web3.js';
2
2
  import { SolanaPriorityFeeResponse } from './solanaPriorityFeeMethod';
3
3
  import { HeliusPriorityFeeResponse } from './heliusPriorityFeeMethod';
4
+ import { DriftMarketInfo } from './priorityFeeSubscriber';
5
+ import { DriftPriorityFeeResponse } from './driftPriorityFeeMethod';
4
6
  export interface PriorityFeeStrategy {
5
- calculate(samples: SolanaPriorityFeeResponse[] | HeliusPriorityFeeResponse): number;
7
+ calculate(samples: SolanaPriorityFeeResponse[] | HeliusPriorityFeeResponse | DriftPriorityFeeResponse): number;
6
8
  }
7
9
  export declare enum PriorityFeeMethod {
8
10
  SOLANA = "solana",
9
- HELIUS = "helius"
11
+ HELIUS = "helius",
12
+ DRIFT = "drift"
10
13
  }
11
14
  export type PriorityFeeSubscriberConfig = {
12
15
  connection?: Connection;
13
16
  frequencyMs: number;
14
- addresses: PublicKey[];
17
+ addresses?: PublicKey[];
18
+ driftMarkets?: DriftMarketInfo[];
15
19
  customStrategy?: PriorityFeeStrategy;
16
20
  priorityFeeMethod?: PriorityFeeMethod;
17
21
  slotsToCheck?: number;
18
22
  heliusRpcUrl?: string;
23
+ driftPriorityFeeEndpoint?: string;
19
24
  maxFeeMicroLamports?: number;
20
25
  priorityFeeMultiplier?: number;
21
26
  };
@@ -5,4 +5,5 @@ var PriorityFeeMethod;
5
5
  (function (PriorityFeeMethod) {
6
6
  PriorityFeeMethod["SOLANA"] = "solana";
7
7
  PriorityFeeMethod["HELIUS"] = "helius";
8
+ PriorityFeeMethod["DRIFT"] = "drift";
8
9
  })(PriorityFeeMethod = exports.PriorityFeeMethod || (exports.PriorityFeeMethod = {}));
@@ -0,0 +1,28 @@
1
+ import { AddressLookupTableAccount, Connection, TransactionInstruction, TransactionVersion, VersionedTransaction } from '@solana/web3.js';
2
+ import { BaseTxParams, ProcessingTxParams } from '..';
3
+ type TransactionProps = {
4
+ instructions: TransactionInstruction | TransactionInstruction[];
5
+ txParams?: BaseTxParams;
6
+ txVersion?: TransactionVersion;
7
+ lookupTables?: AddressLookupTableAccount[];
8
+ forceVersionedTransaction?: boolean;
9
+ };
10
+ /**
11
+ * This class is responsible for running through a "processing" pipeline for a base transaction, to adjust the standard transaction parameters based on a given configuration.
12
+ */
13
+ export declare class TransactionProcessor {
14
+ private static getComputeUnitsFromSim;
15
+ static getTxSimComputeUnits(tx: VersionedTransaction, connection: Connection): Promise<{
16
+ success: boolean;
17
+ computeUnits: number;
18
+ }>;
19
+ static process(props: {
20
+ txProps: TransactionProps;
21
+ txBuilder: (baseTransactionProps: TransactionProps) => Promise<VersionedTransaction>;
22
+ processConfig: ProcessingTxParams;
23
+ processParams: {
24
+ connection: Connection;
25
+ };
26
+ }): Promise<BaseTxParams>;
27
+ }
28
+ export {};