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