@drift-labs/sdk 2.53.0-beta.1 → 2.53.0-beta.2

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.53.0-beta.1
1
+ 2.53.0-beta.2
@@ -11,7 +11,7 @@ export declare class FastSingleTxSender extends BaseTxSender {
11
11
  blockhashRefreshInterval: number;
12
12
  additionalConnections: Connection[];
13
13
  timoutCount: number;
14
- recentBlockhash: string;
14
+ blockhashQueue: string[];
15
15
  constructor({ connection, wallet, opts, timeout, blockhashRefreshInterval, additionalConnections, }: {
16
16
  connection: Connection;
17
17
  wallet: IWallet;
@@ -21,6 +21,7 @@ export declare class FastSingleTxSender extends BaseTxSender {
21
21
  additionalConnections?: any;
22
22
  });
23
23
  startBlockhashRefreshLoop(): void;
24
+ addBlockhashToQueue(blockhash: string): void;
24
25
  prepareTx(tx: Transaction, additionalSigners: Array<Signer>, opts: ConfirmOptions): Promise<Transaction>;
25
26
  getVersionedTransaction(ixs: TransactionInstruction[], lookupTableAccounts: AddressLookupTableAccount[], additionalSigners?: Array<Signer>, opts?: ConfirmOptions): Promise<VersionedTransaction>;
26
27
  sendRawTransaction(rawTransaction: Buffer | Uint8Array, opts: ConfirmOptions): Promise<TxSigAndSlot>;
@@ -5,11 +5,13 @@ const web3_js_1 = require("@solana/web3.js");
5
5
  const anchor_1 = require("@coral-xyz/anchor");
6
6
  const baseTxSender_1 = require("./baseTxSender");
7
7
  const DEFAULT_TIMEOUT = 35000;
8
- const DEFAULT_BLOCKHASH_REFRESH = 10000;
8
+ const DEFAULT_BLOCKHASH_REFRESH = 500;
9
+ const MAX_BLOCKHASH_QUEUE_LENGTH = 100;
9
10
  class FastSingleTxSender extends baseTxSender_1.BaseTxSender {
10
11
  constructor({ connection, wallet, opts = anchor_1.AnchorProvider.defaultOptions(), timeout = DEFAULT_TIMEOUT, blockhashRefreshInterval = DEFAULT_BLOCKHASH_REFRESH, additionalConnections = new Array(), }) {
11
12
  super({ connection, wallet, opts, timeout, additionalConnections });
12
13
  this.timoutCount = 0;
14
+ this.blockhashQueue = [];
13
15
  this.connection = connection;
14
16
  this.wallet = wallet;
15
17
  this.opts = opts;
@@ -21,18 +23,29 @@ class FastSingleTxSender extends baseTxSender_1.BaseTxSender {
21
23
  startBlockhashRefreshLoop() {
22
24
  setInterval(async () => {
23
25
  try {
24
- this.recentBlockhash = (await this.connection.getLatestBlockhash(this.opts)).blockhash;
26
+ const blockhash = (await this.connection.getLatestBlockhash(this.opts))
27
+ .blockhash;
28
+ this.addBlockhashToQueue(blockhash);
25
29
  }
26
30
  catch (e) {
27
31
  console.error('Error in startBlockhashRefreshLoop: ', e);
28
32
  }
29
33
  }, this.blockhashRefreshInterval);
30
34
  }
35
+ addBlockhashToQueue(blockhash) {
36
+ if (blockhash !== this.blockhashQueue[0]) {
37
+ this.blockhashQueue.push(blockhash);
38
+ return;
39
+ }
40
+ if (this.blockhashQueue.length > MAX_BLOCKHASH_QUEUE_LENGTH) {
41
+ this.blockhashQueue.shift();
42
+ }
43
+ }
31
44
  async prepareTx(tx, additionalSigners, opts) {
32
45
  var _a;
33
46
  tx.feePayer = this.wallet.publicKey;
34
47
  tx.recentBlockhash =
35
- (_a = this.recentBlockhash) !== null && _a !== void 0 ? _a : (await this.connection.getLatestBlockhash(opts.preflightCommitment))
48
+ (_a = this.blockhashQueue.shift()) !== null && _a !== void 0 ? _a : (await this.connection.getLatestBlockhash(opts.preflightCommitment))
36
49
  .blockhash;
37
50
  additionalSigners
38
51
  .filter((s) => s !== undefined)
@@ -52,7 +65,7 @@ class FastSingleTxSender extends baseTxSender_1.BaseTxSender {
52
65
  }
53
66
  const message = new web3_js_1.TransactionMessage({
54
67
  payerKey: this.wallet.publicKey,
55
- recentBlockhash: (_a = this.recentBlockhash) !== null && _a !== void 0 ? _a : (await this.connection.getLatestBlockhash(opts.preflightCommitment))
68
+ recentBlockhash: (_a = this.blockhashQueue.shift()) !== null && _a !== void 0 ? _a : (await this.connection.getLatestBlockhash(opts.preflightCommitment))
56
69
  .blockhash,
57
70
  instructions: ixs,
58
71
  }).compileToV0Message(lookupTableAccounts);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.53.0-beta.1",
3
+ "version": "2.53.0-beta.2",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -15,7 +15,8 @@ import { IWallet } from '../types';
15
15
  import { BaseTxSender } from './baseTxSender';
16
16
 
17
17
  const DEFAULT_TIMEOUT = 35000;
18
- const DEFAULT_BLOCKHASH_REFRESH = 10000;
18
+ const DEFAULT_BLOCKHASH_REFRESH = 500;
19
+ const MAX_BLOCKHASH_QUEUE_LENGTH = 100;
19
20
 
20
21
  export class FastSingleTxSender extends BaseTxSender {
21
22
  connection: Connection;
@@ -25,7 +26,7 @@ export class FastSingleTxSender extends BaseTxSender {
25
26
  blockhashRefreshInterval: number;
26
27
  additionalConnections: Connection[];
27
28
  timoutCount = 0;
28
- recentBlockhash: string;
29
+ blockhashQueue: string[] = [];
29
30
 
30
31
  public constructor({
31
32
  connection,
@@ -55,15 +56,25 @@ export class FastSingleTxSender extends BaseTxSender {
55
56
  startBlockhashRefreshLoop(): void {
56
57
  setInterval(async () => {
57
58
  try {
58
- this.recentBlockhash = (
59
- await this.connection.getLatestBlockhash(this.opts)
60
- ).blockhash;
59
+ const blockhash = (await this.connection.getLatestBlockhash(this.opts))
60
+ .blockhash;
61
+ this.addBlockhashToQueue(blockhash);
61
62
  } catch (e) {
62
63
  console.error('Error in startBlockhashRefreshLoop: ', e);
63
64
  }
64
65
  }, this.blockhashRefreshInterval);
65
66
  }
66
67
 
68
+ addBlockhashToQueue(blockhash: string): void {
69
+ if (blockhash !== this.blockhashQueue[0]) {
70
+ this.blockhashQueue.push(blockhash);
71
+ return;
72
+ }
73
+ if (this.blockhashQueue.length > MAX_BLOCKHASH_QUEUE_LENGTH) {
74
+ this.blockhashQueue.shift();
75
+ }
76
+ }
77
+
67
78
  async prepareTx(
68
79
  tx: Transaction,
69
80
  additionalSigners: Array<Signer>,
@@ -72,7 +83,7 @@ export class FastSingleTxSender extends BaseTxSender {
72
83
  tx.feePayer = this.wallet.publicKey;
73
84
 
74
85
  tx.recentBlockhash =
75
- this.recentBlockhash ??
86
+ this.blockhashQueue.shift() ??
76
87
  (await this.connection.getLatestBlockhash(opts.preflightCommitment))
77
88
  .blockhash;
78
89
 
@@ -103,7 +114,7 @@ export class FastSingleTxSender extends BaseTxSender {
103
114
  const message = new TransactionMessage({
104
115
  payerKey: this.wallet.publicKey,
105
116
  recentBlockhash:
106
- this.recentBlockhash ??
117
+ this.blockhashQueue.shift() ??
107
118
  (await this.connection.getLatestBlockhash(opts.preflightCommitment))
108
119
  .blockhash,
109
120
  instructions: ixs,