@drift-labs/sdk 2.77.0-beta.3 → 2.78.0-beta.0

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.77.0-beta.3
1
+ 2.78.0-beta.0
@@ -661,6 +661,7 @@ export declare class DriftClient {
661
661
  marketType: MarketType;
662
662
  } | undefined;
663
663
  private handleSignedTransaction;
664
+ private isVersionedTransaction;
664
665
  sendTransaction(tx: Transaction | VersionedTransaction, additionalSigners?: Array<Signer>, opts?: ConfirmOptions, preSigned?: boolean): Promise<TxSigAndSlot>;
665
666
  /**
666
667
  *
@@ -2524,9 +2524,10 @@ class DriftClient {
2524
2524
  };
2525
2525
  let placeAndTakeTx = await this.buildTransaction(ixs, txParamsWithoutImplicitSimulation);
2526
2526
  if (shouldUseSimulationComputeUnits || shouldExitIfSimulationFails) {
2527
- const simulationResult = await txParamProcessor_1.TransactionProcessor.getTxSimComputeUnits(
2528
- // @ts-ignore :: TODO - TEST WITH LEGACY TRANSACTION
2529
- placeAndTakeTx, this.connection);
2527
+ const versionedPlaceAndTakeTx = this.isVersionedTransaction(placeAndTakeTx)
2528
+ ? placeAndTakeTx
2529
+ : (await this.buildTransaction(ixs, txParamsWithoutImplicitSimulation, undefined, undefined, true));
2530
+ const simulationResult = await txParamProcessor_1.TransactionProcessor.getTxSimComputeUnits(versionedPlaceAndTakeTx, this.connection);
2530
2531
  if (shouldExitIfSimulationFails && !simulationResult.success) {
2531
2532
  return;
2532
2533
  }
@@ -3517,6 +3518,11 @@ class DriftClient {
3517
3518
  handleSignedTransaction() {
3518
3519
  this.metricsEventEmitter.emit('txSigned');
3519
3520
  }
3521
+ isVersionedTransaction(tx) {
3522
+ const version = tx === null || tx === void 0 ? void 0 : tx.version;
3523
+ const isVersionedTx = tx instanceof web3_js_1.VersionedTransaction || version !== undefined;
3524
+ return isVersionedTx;
3525
+ }
3520
3526
  sendTransaction(tx, additionalSigners, opts, preSigned) {
3521
3527
  const extraConfirmationOptions = this
3522
3528
  .enableMetricsEvents
@@ -3524,8 +3530,7 @@ class DriftClient {
3524
3530
  onSignedCb: this.handleSignedTransaction.bind(this),
3525
3531
  }
3526
3532
  : undefined;
3527
- const version = tx === null || tx === void 0 ? void 0 : tx.version;
3528
- const isVersionedTx = tx instanceof web3_js_1.VersionedTransaction || version !== undefined;
3533
+ const isVersionedTx = this.isVersionedTransaction(tx);
3529
3534
  if (isVersionedTx) {
3530
3535
  return this.txSender.sendVersionedTransaction(tx, additionalSigners, opts, preSigned, extraConfirmationOptions);
3531
3536
  }
@@ -3559,6 +3564,8 @@ class DriftClient {
3559
3564
  txParamProcessingParams: {
3560
3565
  useSimulatedComputeUnits: txParams === null || txParams === void 0 ? void 0 : txParams.useSimulatedComputeUnits,
3561
3566
  computeUnitsBufferMultiplier: txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsBufferMultiplier,
3567
+ useSimulatedComputeUnitsForCUPriceCalculation: txParams === null || txParams === void 0 ? void 0 : txParams.useSimulatedComputeUnitsForCUPriceCalculation,
3568
+ getCUPriceFromComputeUnits: txParams === null || txParams === void 0 ? void 0 : txParams.getCUPriceFromComputeUnits,
3562
3569
  },
3563
3570
  };
3564
3571
  const processedTxParams = await this.getProcessedTransactionParams({
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.75.0",
2
+ "version": "2.77.0",
3
3
  "name": "drift",
4
4
  "instructions": [
5
5
  {
@@ -64,6 +64,18 @@ class TransactionProcessor {
64
64
  };
65
65
  }
66
66
  }
67
+ if (processConfig === null || processConfig === void 0 ? void 0 : processConfig.useSimulatedComputeUnitsForCUPriceCalculation) {
68
+ if (!(processConfig === null || processConfig === void 0 ? void 0 : processConfig.useSimulatedComputeUnits)) {
69
+ throw new Error(`encountered useSimulatedComputeUnitsForFees=true, but useSimulatedComputeUnits is false`);
70
+ }
71
+ if (!(processConfig === null || processConfig === void 0 ? void 0 : processConfig.getCUPriceFromComputeUnits)) {
72
+ throw new Error(`encountered useSimulatedComputeUnitsForFees=true, but getComputeUnitPriceFromUnitsToUse helper method is undefined`);
73
+ }
74
+ const simulatedComputeUnits = finalTxProps.txParams.computeUnits;
75
+ const computeUnitPrice = processConfig.getCUPriceFromComputeUnits(simulatedComputeUnits);
76
+ console.debug(`🔧:: Adjusting compute unit price for simulated compute unit budget :: ${finalTxProps.txParams.computeUnitsPrice}=>${computeUnitPrice}`);
77
+ finalTxProps.txParams.computeUnitsPrice = computeUnitPrice;
78
+ }
67
79
  // # Return Final Tx Params
68
80
  return finalTxProps.txParams;
69
81
  }
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import { ExtraConfirmationOptions, TxSigAndSlot } from './types';
3
- import { AddressLookupTableAccount, ConfirmOptions, Connection, Signer, Transaction, TransactionInstruction, VersionedTransaction } from '@solana/web3.js';
3
+ import { AddressLookupTableAccount, Commitment, ConfirmOptions, Connection, Signer, Transaction, TransactionInstruction, VersionedTransaction } from '@solana/web3.js';
4
4
  import { IWallet } from '../types';
5
5
  import { BaseTxSender } from './baseTxSender';
6
6
  type ResolveReference = {
@@ -18,13 +18,15 @@ export declare class WhileValidTxSender extends BaseTxSender {
18
18
  blockhash: string;
19
19
  lastValidBlockHeight: number;
20
20
  }>;
21
- constructor({ connection, wallet, opts, retrySleep, additionalConnections, additionalTxSenderCallbacks, }: {
21
+ blockhashCommitment: Commitment;
22
+ constructor({ connection, wallet, opts, retrySleep, additionalConnections, additionalTxSenderCallbacks, blockhashCommitment, }: {
22
23
  connection: Connection;
23
24
  wallet: IWallet;
24
25
  opts?: ConfirmOptions;
25
26
  retrySleep?: number;
26
27
  additionalConnections?: any;
27
28
  additionalTxSenderCallbacks?: ((base58EncodedTx: string) => void)[];
29
+ blockhashCommitment?: Commitment;
28
30
  });
29
31
  sleep(reference: ResolveReference): Promise<void>;
30
32
  prepareTx(tx: Transaction, additionalSigners: Array<Signer>, opts: ConfirmOptions, preSigned?: boolean): Promise<Transaction>;
@@ -11,7 +11,7 @@ const bs58_1 = __importDefault(require("bs58"));
11
11
  const DEFAULT_RETRY = 2000;
12
12
  const PLACEHOLDER_BLOCKHASH = 'Fdum64WVeej6DeL85REV9NvfSxEJNPZ74DBk7A8kTrKP';
13
13
  class WhileValidTxSender extends baseTxSender_1.BaseTxSender {
14
- constructor({ connection, wallet, opts = { ...anchor_1.AnchorProvider.defaultOptions(), maxRetries: 0 }, retrySleep = DEFAULT_RETRY, additionalConnections = new Array(), additionalTxSenderCallbacks = [], }) {
14
+ constructor({ connection, wallet, opts = { ...anchor_1.AnchorProvider.defaultOptions(), maxRetries: 0 }, retrySleep = DEFAULT_RETRY, additionalConnections = new Array(), additionalTxSenderCallbacks = [], blockhashCommitment = 'finalized', }) {
15
15
  super({
16
16
  connection,
17
17
  wallet,
@@ -22,6 +22,7 @@ class WhileValidTxSender extends baseTxSender_1.BaseTxSender {
22
22
  this.timoutCount = 0;
23
23
  this.untilValid = new Map();
24
24
  this.retrySleep = retrySleep;
25
+ this.blockhashCommitment = blockhashCommitment;
25
26
  }
26
27
  async sleep(reference) {
27
28
  return new Promise((resolve) => {
@@ -31,7 +32,7 @@ class WhileValidTxSender extends baseTxSender_1.BaseTxSender {
31
32
  }
32
33
  async prepareTx(tx, additionalSigners, opts, preSigned) {
33
34
  var _a;
34
- const latestBlockhash = await this.connection.getLatestBlockhash(opts.preflightCommitment);
35
+ const latestBlockhash = await this.connection.getLatestBlockhash(this.blockhashCommitment);
35
36
  // handle tx
36
37
  let signedTx = tx;
37
38
  if (!preSigned) {
@@ -59,7 +60,7 @@ class WhileValidTxSender extends baseTxSender_1.BaseTxSender {
59
60
  return tx;
60
61
  }
61
62
  async sendVersionedTransaction(tx, additionalSigners, opts, preSigned, extraConfirmationOptions) {
62
- const latestBlockhash = await this.connection.getLatestBlockhash();
63
+ const latestBlockhash = await this.connection.getLatestBlockhash(this.blockhashCommitment);
63
64
  let signedTx;
64
65
  if (preSigned) {
65
66
  signedTx = tx;
package/lib/types.d.ts CHANGED
@@ -1045,6 +1045,8 @@ export type BaseTxParams = {
1045
1045
  export type ProcessingTxParams = {
1046
1046
  useSimulatedComputeUnits?: boolean;
1047
1047
  computeUnitsBufferMultiplier?: number;
1048
+ useSimulatedComputeUnitsForCUPriceCalculation?: boolean;
1049
+ getCUPriceFromComputeUnits?: (computeUnits: number) => number;
1048
1050
  };
1049
1051
  export type TxParams = BaseTxParams & ProcessingTxParams;
1050
1052
  export declare class SwapReduceOnly {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.77.0-beta.3",
3
+ "version": "2.78.0-beta.0",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -4577,10 +4577,21 @@ export class DriftClient {
4577
4577
  );
4578
4578
 
4579
4579
  if (shouldUseSimulationComputeUnits || shouldExitIfSimulationFails) {
4580
+ const versionedPlaceAndTakeTx = this.isVersionedTransaction(
4581
+ placeAndTakeTx
4582
+ )
4583
+ ? (placeAndTakeTx as VersionedTransaction)
4584
+ : ((await this.buildTransaction(
4585
+ ixs,
4586
+ txParamsWithoutImplicitSimulation,
4587
+ undefined,
4588
+ undefined,
4589
+ true
4590
+ )) as VersionedTransaction);
4591
+
4580
4592
  const simulationResult =
4581
4593
  await TransactionParamProcessor.getTxSimComputeUnits(
4582
- // @ts-ignore :: TODO - TEST WITH LEGACY TRANSACTION
4583
- placeAndTakeTx,
4594
+ versionedPlaceAndTakeTx,
4584
4595
  this.connection
4585
4596
  );
4586
4597
 
@@ -6541,6 +6552,16 @@ export class DriftClient {
6541
6552
  this.metricsEventEmitter.emit('txSigned');
6542
6553
  }
6543
6554
 
6555
+ private isVersionedTransaction(
6556
+ tx: Transaction | VersionedTransaction
6557
+ ): boolean {
6558
+ const version = (tx as VersionedTransaction)?.version;
6559
+ const isVersionedTx =
6560
+ tx instanceof VersionedTransaction || version !== undefined;
6561
+
6562
+ return isVersionedTx;
6563
+ }
6564
+
6544
6565
  sendTransaction(
6545
6566
  tx: Transaction | VersionedTransaction,
6546
6567
  additionalSigners?: Array<Signer>,
@@ -6554,9 +6575,7 @@ export class DriftClient {
6554
6575
  }
6555
6576
  : undefined;
6556
6577
 
6557
- const version = (tx as VersionedTransaction)?.version;
6558
- const isVersionedTx =
6559
- tx instanceof VersionedTransaction || version !== undefined;
6578
+ const isVersionedTx = this.isVersionedTransaction(tx);
6560
6579
 
6561
6580
  if (isVersionedTx) {
6562
6581
  return this.txSender.sendVersionedTransaction(
@@ -6614,6 +6633,9 @@ export class DriftClient {
6614
6633
  txParamProcessingParams: {
6615
6634
  useSimulatedComputeUnits: txParams?.useSimulatedComputeUnits,
6616
6635
  computeUnitsBufferMultiplier: txParams?.computeUnitsBufferMultiplier,
6636
+ useSimulatedComputeUnitsForCUPriceCalculation:
6637
+ txParams?.useSimulatedComputeUnitsForCUPriceCalculation,
6638
+ getCUPriceFromComputeUnits: txParams?.getCUPriceFromComputeUnits,
6617
6639
  },
6618
6640
  };
6619
6641
 
@@ -6643,7 +6665,9 @@ export class DriftClient {
6643
6665
  })
6644
6666
  );
6645
6667
  }
6668
+
6646
6669
  const computeUnitsPrice = baseTxParams?.computeUnitsPrice;
6670
+
6647
6671
  if (computeUnitsPrice !== 0) {
6648
6672
  allIx.push(
6649
6673
  ComputeBudgetProgram.setComputeUnitPrice({
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.75.0",
2
+ "version": "2.77.0",
3
3
  "name": "drift",
4
4
  "instructions": [
5
5
  {
@@ -120,6 +120,31 @@ export class TransactionProcessor {
120
120
  }
121
121
  }
122
122
 
123
+ if (processConfig?.useSimulatedComputeUnitsForCUPriceCalculation) {
124
+ if (!processConfig?.useSimulatedComputeUnits) {
125
+ throw new Error(
126
+ `encountered useSimulatedComputeUnitsForFees=true, but useSimulatedComputeUnits is false`
127
+ );
128
+ }
129
+ if (!processConfig?.getCUPriceFromComputeUnits) {
130
+ throw new Error(
131
+ `encountered useSimulatedComputeUnitsForFees=true, but getComputeUnitPriceFromUnitsToUse helper method is undefined`
132
+ );
133
+ }
134
+
135
+ const simulatedComputeUnits = finalTxProps.txParams.computeUnits;
136
+
137
+ const computeUnitPrice = processConfig.getCUPriceFromComputeUnits(
138
+ simulatedComputeUnits
139
+ );
140
+
141
+ console.debug(
142
+ `🔧:: Adjusting compute unit price for simulated compute unit budget :: ${finalTxProps.txParams.computeUnitsPrice}=>${computeUnitPrice}`
143
+ );
144
+
145
+ finalTxProps.txParams.computeUnitsPrice = computeUnitPrice;
146
+ }
147
+
123
148
  // # Return Final Tx Params
124
149
  return finalTxProps.txParams;
125
150
  }
@@ -1,6 +1,7 @@
1
1
  import { ExtraConfirmationOptions, TxSigAndSlot } from './types';
2
2
  import {
3
3
  AddressLookupTableAccount,
4
+ Commitment,
4
5
  ConfirmOptions,
5
6
  Connection,
6
7
  Signer,
@@ -33,6 +34,7 @@ export class WhileValidTxSender extends BaseTxSender {
33
34
  string,
34
35
  { blockhash: string; lastValidBlockHeight: number }
35
36
  >();
37
+ blockhashCommitment: Commitment;
36
38
 
37
39
  public constructor({
38
40
  connection,
@@ -41,6 +43,7 @@ export class WhileValidTxSender extends BaseTxSender {
41
43
  retrySleep = DEFAULT_RETRY,
42
44
  additionalConnections = new Array<Connection>(),
43
45
  additionalTxSenderCallbacks = [],
46
+ blockhashCommitment = 'finalized',
44
47
  }: {
45
48
  connection: Connection;
46
49
  wallet: IWallet;
@@ -48,6 +51,7 @@ export class WhileValidTxSender extends BaseTxSender {
48
51
  retrySleep?: number;
49
52
  additionalConnections?;
50
53
  additionalTxSenderCallbacks?: ((base58EncodedTx: string) => void)[];
54
+ blockhashCommitment?: Commitment;
51
55
  }) {
52
56
  super({
53
57
  connection,
@@ -57,6 +61,7 @@ export class WhileValidTxSender extends BaseTxSender {
57
61
  additionalTxSenderCallbacks,
58
62
  });
59
63
  this.retrySleep = retrySleep;
64
+ this.blockhashCommitment = blockhashCommitment;
60
65
  }
61
66
 
62
67
  async sleep(reference: ResolveReference): Promise<void> {
@@ -73,7 +78,7 @@ export class WhileValidTxSender extends BaseTxSender {
73
78
  preSigned?: boolean
74
79
  ): Promise<Transaction> {
75
80
  const latestBlockhash = await this.connection.getLatestBlockhash(
76
- opts.preflightCommitment
81
+ this.blockhashCommitment
77
82
  );
78
83
 
79
84
  // handle tx
@@ -125,7 +130,9 @@ export class WhileValidTxSender extends BaseTxSender {
125
130
  preSigned?: boolean,
126
131
  extraConfirmationOptions?: ExtraConfirmationOptions
127
132
  ): Promise<TxSigAndSlot> {
128
- const latestBlockhash = await this.connection.getLatestBlockhash();
133
+ const latestBlockhash = await this.connection.getLatestBlockhash(
134
+ this.blockhashCommitment
135
+ );
129
136
 
130
137
  let signedTx;
131
138
  if (preSigned) {
package/src/types.ts CHANGED
@@ -1007,6 +1007,8 @@ export type BaseTxParams = {
1007
1007
  export type ProcessingTxParams = {
1008
1008
  useSimulatedComputeUnits?: boolean;
1009
1009
  computeUnitsBufferMultiplier?: number;
1010
+ useSimulatedComputeUnitsForCUPriceCalculation?: boolean;
1011
+ getCUPriceFromComputeUnits?: (computeUnits: number) => number;
1010
1012
  };
1011
1013
 
1012
1014
  export type TxParams = BaseTxParams & ProcessingTxParams;