@drift-labs/sdk 2.53.0-beta.4 → 2.53.0-beta.6
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 +4 -3
- package/lib/tx/fastSingleTxSender.js +15 -25
- package/package.json +1 -1
- package/src/tx/fastSingleTxSender.ts +19 -24
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.53.0-beta.
|
|
1
|
+
2.53.0-beta.6
|
|
@@ -11,17 +11,18 @@ export declare class FastSingleTxSender extends BaseTxSender {
|
|
|
11
11
|
blockhashRefreshInterval: number;
|
|
12
12
|
additionalConnections: Connection[];
|
|
13
13
|
timoutCount: number;
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
recentBlockhash: string;
|
|
15
|
+
skipConfirmation: boolean;
|
|
16
|
+
constructor({ connection, wallet, opts, timeout, blockhashRefreshInterval, additionalConnections, skipConfirmation, }: {
|
|
16
17
|
connection: Connection;
|
|
17
18
|
wallet: IWallet;
|
|
18
19
|
opts?: ConfirmOptions;
|
|
19
20
|
timeout?: number;
|
|
20
21
|
blockhashRefreshInterval?: number;
|
|
21
22
|
additionalConnections?: any;
|
|
23
|
+
skipConfirmation?: boolean;
|
|
22
24
|
});
|
|
23
25
|
startBlockhashRefreshLoop(): void;
|
|
24
|
-
addBlockhashToQueue(blockhash: string): void;
|
|
25
26
|
prepareTx(tx: Transaction, additionalSigners: Array<Signer>, opts: ConfirmOptions): Promise<Transaction>;
|
|
26
27
|
getVersionedTransaction(ixs: TransactionInstruction[], lookupTableAccounts: AddressLookupTableAccount[], additionalSigners?: Array<Signer>, opts?: ConfirmOptions): Promise<VersionedTransaction>;
|
|
27
28
|
sendRawTransaction(rawTransaction: Buffer | Uint8Array, opts: ConfirmOptions): Promise<TxSigAndSlot>;
|
|
@@ -5,47 +5,35 @@ 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(), }) {
|
|
10
|
+
constructor({ connection, wallet, opts = anchor_1.AnchorProvider.defaultOptions(), timeout = DEFAULT_TIMEOUT, blockhashRefreshInterval = DEFAULT_BLOCKHASH_REFRESH, additionalConnections = new Array(), skipConfirmation = false, }) {
|
|
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;
|
|
18
16
|
this.timeout = timeout;
|
|
19
17
|
this.blockhashRefreshInterval = blockhashRefreshInterval;
|
|
20
18
|
this.additionalConnections = additionalConnections;
|
|
19
|
+
this.skipConfirmation = skipConfirmation;
|
|
21
20
|
this.startBlockhashRefreshLoop();
|
|
22
21
|
}
|
|
23
22
|
startBlockhashRefreshLoop() {
|
|
24
23
|
setInterval(async () => {
|
|
25
24
|
try {
|
|
26
|
-
|
|
27
|
-
.blockhash;
|
|
28
|
-
this.addBlockhashToQueue(blockhash);
|
|
25
|
+
this.recentBlockhash = (await this.connection.getLatestBlockhash(this.opts)).blockhash;
|
|
29
26
|
}
|
|
30
27
|
catch (e) {
|
|
31
28
|
console.error('Error in startBlockhashRefreshLoop: ', e);
|
|
32
29
|
}
|
|
33
30
|
}, this.blockhashRefreshInterval);
|
|
34
31
|
}
|
|
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
|
-
}
|
|
44
32
|
async prepareTx(tx, additionalSigners, opts) {
|
|
45
33
|
var _a;
|
|
46
34
|
tx.feePayer = this.wallet.publicKey;
|
|
47
35
|
tx.recentBlockhash =
|
|
48
|
-
(_a = this.
|
|
36
|
+
(_a = this.recentBlockhash) !== null && _a !== void 0 ? _a : (await this.connection.getLatestBlockhash(opts.preflightCommitment))
|
|
49
37
|
.blockhash;
|
|
50
38
|
additionalSigners
|
|
51
39
|
.filter((s) => s !== undefined)
|
|
@@ -65,7 +53,7 @@ class FastSingleTxSender extends baseTxSender_1.BaseTxSender {
|
|
|
65
53
|
}
|
|
66
54
|
const message = new web3_js_1.TransactionMessage({
|
|
67
55
|
payerKey: this.wallet.publicKey,
|
|
68
|
-
recentBlockhash: (_a = this.
|
|
56
|
+
recentBlockhash: (_a = this.recentBlockhash) !== null && _a !== void 0 ? _a : (await this.connection.getLatestBlockhash(opts.preflightCommitment))
|
|
69
57
|
.blockhash,
|
|
70
58
|
instructions: ixs,
|
|
71
59
|
}).compileToV0Message(lookupTableAccounts);
|
|
@@ -87,13 +75,15 @@ class FastSingleTxSender extends baseTxSender_1.BaseTxSender {
|
|
|
87
75
|
});
|
|
88
76
|
this.sendToAdditionalConnections(rawTransaction, opts);
|
|
89
77
|
let slot;
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
78
|
+
if (!this.skipConfirmation) {
|
|
79
|
+
try {
|
|
80
|
+
const result = await this.confirmTransaction(txid, opts.commitment);
|
|
81
|
+
slot = result.context.slot;
|
|
82
|
+
}
|
|
83
|
+
catch (e) {
|
|
84
|
+
console.error(e);
|
|
85
|
+
throw e;
|
|
86
|
+
}
|
|
97
87
|
}
|
|
98
88
|
return { txSig: txid, slot };
|
|
99
89
|
}
|
package/package.json
CHANGED
|
@@ -15,8 +15,7 @@ import { IWallet } from '../types';
|
|
|
15
15
|
import { BaseTxSender } from './baseTxSender';
|
|
16
16
|
|
|
17
17
|
const DEFAULT_TIMEOUT = 35000;
|
|
18
|
-
const DEFAULT_BLOCKHASH_REFRESH =
|
|
19
|
-
const MAX_BLOCKHASH_QUEUE_LENGTH = 100;
|
|
18
|
+
const DEFAULT_BLOCKHASH_REFRESH = 10000;
|
|
20
19
|
|
|
21
20
|
export class FastSingleTxSender extends BaseTxSender {
|
|
22
21
|
connection: Connection;
|
|
@@ -26,7 +25,8 @@ export class FastSingleTxSender extends BaseTxSender {
|
|
|
26
25
|
blockhashRefreshInterval: number;
|
|
27
26
|
additionalConnections: Connection[];
|
|
28
27
|
timoutCount = 0;
|
|
29
|
-
|
|
28
|
+
recentBlockhash: string;
|
|
29
|
+
skipConfirmation: boolean;
|
|
30
30
|
|
|
31
31
|
public constructor({
|
|
32
32
|
connection,
|
|
@@ -35,6 +35,7 @@ export class FastSingleTxSender extends BaseTxSender {
|
|
|
35
35
|
timeout = DEFAULT_TIMEOUT,
|
|
36
36
|
blockhashRefreshInterval = DEFAULT_BLOCKHASH_REFRESH,
|
|
37
37
|
additionalConnections = new Array<Connection>(),
|
|
38
|
+
skipConfirmation = false,
|
|
38
39
|
}: {
|
|
39
40
|
connection: Connection;
|
|
40
41
|
wallet: IWallet;
|
|
@@ -42,6 +43,7 @@ export class FastSingleTxSender extends BaseTxSender {
|
|
|
42
43
|
timeout?: number;
|
|
43
44
|
blockhashRefreshInterval?: number;
|
|
44
45
|
additionalConnections?;
|
|
46
|
+
skipConfirmation?: boolean;
|
|
45
47
|
}) {
|
|
46
48
|
super({ connection, wallet, opts, timeout, additionalConnections });
|
|
47
49
|
this.connection = connection;
|
|
@@ -50,31 +52,22 @@ export class FastSingleTxSender extends BaseTxSender {
|
|
|
50
52
|
this.timeout = timeout;
|
|
51
53
|
this.blockhashRefreshInterval = blockhashRefreshInterval;
|
|
52
54
|
this.additionalConnections = additionalConnections;
|
|
55
|
+
this.skipConfirmation = skipConfirmation;
|
|
53
56
|
this.startBlockhashRefreshLoop();
|
|
54
57
|
}
|
|
55
58
|
|
|
56
59
|
startBlockhashRefreshLoop(): void {
|
|
57
60
|
setInterval(async () => {
|
|
58
61
|
try {
|
|
59
|
-
|
|
60
|
-
.
|
|
61
|
-
|
|
62
|
+
this.recentBlockhash = (
|
|
63
|
+
await this.connection.getLatestBlockhash(this.opts)
|
|
64
|
+
).blockhash;
|
|
62
65
|
} catch (e) {
|
|
63
66
|
console.error('Error in startBlockhashRefreshLoop: ', e);
|
|
64
67
|
}
|
|
65
68
|
}, this.blockhashRefreshInterval);
|
|
66
69
|
}
|
|
67
70
|
|
|
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
|
-
|
|
78
71
|
async prepareTx(
|
|
79
72
|
tx: Transaction,
|
|
80
73
|
additionalSigners: Array<Signer>,
|
|
@@ -83,7 +76,7 @@ export class FastSingleTxSender extends BaseTxSender {
|
|
|
83
76
|
tx.feePayer = this.wallet.publicKey;
|
|
84
77
|
|
|
85
78
|
tx.recentBlockhash =
|
|
86
|
-
this.
|
|
79
|
+
this.recentBlockhash ??
|
|
87
80
|
(await this.connection.getLatestBlockhash(opts.preflightCommitment))
|
|
88
81
|
.blockhash;
|
|
89
82
|
|
|
@@ -114,7 +107,7 @@ export class FastSingleTxSender extends BaseTxSender {
|
|
|
114
107
|
const message = new TransactionMessage({
|
|
115
108
|
payerKey: this.wallet.publicKey,
|
|
116
109
|
recentBlockhash:
|
|
117
|
-
this.
|
|
110
|
+
this.recentBlockhash ??
|
|
118
111
|
(await this.connection.getLatestBlockhash(opts.preflightCommitment))
|
|
119
112
|
.blockhash,
|
|
120
113
|
instructions: ixs,
|
|
@@ -144,12 +137,14 @@ export class FastSingleTxSender extends BaseTxSender {
|
|
|
144
137
|
this.sendToAdditionalConnections(rawTransaction, opts);
|
|
145
138
|
|
|
146
139
|
let slot: number;
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
140
|
+
if (!this.skipConfirmation) {
|
|
141
|
+
try {
|
|
142
|
+
const result = await this.confirmTransaction(txid, opts.commitment);
|
|
143
|
+
slot = result.context.slot;
|
|
144
|
+
} catch (e) {
|
|
145
|
+
console.error(e);
|
|
146
|
+
throw e;
|
|
147
|
+
}
|
|
153
148
|
}
|
|
154
149
|
|
|
155
150
|
return { txSig: txid, slot };
|