@drift-labs/sdk 2.31.1-beta.7 → 2.31.1-beta.8

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.31.1-beta.7
1
+ 2.31.1-beta.8
@@ -136,7 +136,12 @@ class DriftClient {
136
136
  this.accountSubscriber = new webSocketDriftClientAccountSubscriber_1.WebSocketDriftClientAccountSubscriber(this.program, (_r = config.perpMarketIndexes) !== null && _r !== void 0 ? _r : [], (_s = config.spotMarketIndexes) !== null && _s !== void 0 ? _s : [], (_t = config.oracleInfos) !== null && _t !== void 0 ? _t : [], noMarketsAndOraclesSpecified);
137
137
  }
138
138
  this.eventEmitter = this.accountSubscriber.eventEmitter;
139
- this.txSender = (_u = config.txSender) !== null && _u !== void 0 ? _u : new retryTxSender_1.RetryTxSender(this.provider);
139
+ this.txSender =
140
+ (_u = config.txSender) !== null && _u !== void 0 ? _u : new retryTxSender_1.RetryTxSender({
141
+ connection: this.connection,
142
+ wallet: this.wallet,
143
+ opts: this.opts,
144
+ });
140
145
  }
141
146
  getUserMapKey(subAccountId, authority) {
142
147
  return `${subAccountId}_${authority.toString()}`;
@@ -287,7 +292,7 @@ class DriftClient {
287
292
  const newProgram = new anchor_1.Program(drift_json_1.default, this.program.programId, newProvider);
288
293
  this.skipLoadUsers = false;
289
294
  // Update provider for txSender with new wallet details
290
- this.txSender.provider = newProvider;
295
+ this.txSender.wallet = newWallet;
291
296
  this.wallet = newWallet;
292
297
  this.provider = newProvider;
293
298
  this.program = newProgram;
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.31.1-beta.6",
2
+ "version": "2.31.1-beta.7",
3
3
  "name": "drift",
4
4
  "instructions": [
5
5
  {
@@ -1,17 +1,26 @@
1
1
  /// <reference types="node" />
2
2
  import { TxSender, TxSigAndSlot } from './types';
3
3
  import { Commitment, ConfirmOptions, RpcResponseAndContext, Signer, SignatureResult, Transaction, TransactionSignature, Connection, VersionedTransaction, TransactionInstruction, AddressLookupTableAccount } from '@solana/web3.js';
4
- import { AnchorProvider } from '@coral-xyz/anchor';
4
+ import { IWallet } from '../types';
5
5
  type ResolveReference = {
6
6
  resolve?: () => void;
7
7
  };
8
8
  export declare class RetryTxSender implements TxSender {
9
- provider: AnchorProvider;
9
+ connection: Connection;
10
+ wallet: IWallet;
11
+ opts: ConfirmOptions;
10
12
  timeout: number;
11
13
  retrySleep: number;
12
14
  additionalConnections: Connection[];
13
15
  timoutCount: number;
14
- constructor(provider: AnchorProvider, timeout?: number, retrySleep?: number, additionalConnections?: Connection[]);
16
+ constructor({ connection, wallet, opts, timeout, retrySleep, additionalConnections, }: {
17
+ connection: Connection;
18
+ wallet: IWallet;
19
+ opts?: ConfirmOptions;
20
+ timeout?: number;
21
+ retrySleep?: number;
22
+ additionalConnections?: any;
23
+ });
15
24
  send(tx: Transaction, additionalSigners?: Array<Signer>, opts?: ConfirmOptions, preSigned?: boolean): Promise<TxSigAndSlot>;
16
25
  prepareTx(tx: Transaction, additionalSigners: Array<Signer>, opts: ConfirmOptions): Promise<Transaction>;
17
26
  getVersionedTransaction(ixs: TransactionInstruction[], lookupTableAccounts: AddressLookupTableAccount[], additionalSigners?: Array<Signer>, opts?: ConfirmOptions): Promise<VersionedTransaction>;
@@ -5,16 +5,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.RetryTxSender = void 0;
7
7
  const web3_js_1 = require("@solana/web3.js");
8
+ const anchor_1 = require("@coral-xyz/anchor");
8
9
  const assert_1 = __importDefault(require("assert"));
9
10
  const bs58_1 = __importDefault(require("bs58"));
10
11
  const DEFAULT_TIMEOUT = 35000;
11
12
  const DEFAULT_RETRY = 8000;
12
13
  class RetryTxSender {
13
- constructor(provider, timeout, retrySleep, additionalConnections = new Array()) {
14
+ constructor({ connection, wallet, opts = anchor_1.AnchorProvider.defaultOptions(), timeout = DEFAULT_TIMEOUT, retrySleep = DEFAULT_RETRY, additionalConnections = new Array(), }) {
14
15
  this.timoutCount = 0;
15
- this.provider = provider;
16
- this.timeout = timeout !== null && timeout !== void 0 ? timeout : DEFAULT_TIMEOUT;
17
- this.retrySleep = retrySleep !== null && retrySleep !== void 0 ? retrySleep : DEFAULT_RETRY;
16
+ this.connection = connection;
17
+ this.wallet = wallet;
18
+ this.opts = opts;
19
+ this.timeout = timeout;
20
+ this.retrySleep = retrySleep;
18
21
  this.additionalConnections = additionalConnections;
19
22
  }
20
23
  async send(tx, additionalSigners, opts, preSigned) {
@@ -22,7 +25,7 @@ class RetryTxSender {
22
25
  additionalSigners = [];
23
26
  }
24
27
  if (opts === undefined) {
25
- opts = this.provider.opts;
28
+ opts = this.opts;
26
29
  }
27
30
  const signedTx = preSigned
28
31
  ? tx
@@ -30,14 +33,14 @@ class RetryTxSender {
30
33
  return this.sendRawTransaction(signedTx.serialize(), opts);
31
34
  }
32
35
  async prepareTx(tx, additionalSigners, opts) {
33
- tx.feePayer = this.provider.wallet.publicKey;
34
- tx.recentBlockhash = (await this.provider.connection.getRecentBlockhash(opts.preflightCommitment)).blockhash;
36
+ tx.feePayer = this.wallet.publicKey;
37
+ tx.recentBlockhash = (await this.connection.getRecentBlockhash(opts.preflightCommitment)).blockhash;
35
38
  additionalSigners
36
39
  .filter((s) => s !== undefined)
37
40
  .forEach((kp) => {
38
41
  tx.partialSign(kp);
39
42
  });
40
- const signedTx = await this.provider.wallet.signTransaction(tx);
43
+ const signedTx = await this.wallet.signTransaction(tx);
41
44
  return signedTx;
42
45
  }
43
46
  async getVersionedTransaction(ixs, lookupTableAccounts, additionalSigners, opts) {
@@ -45,11 +48,11 @@ class RetryTxSender {
45
48
  additionalSigners = [];
46
49
  }
47
50
  if (opts === undefined) {
48
- opts = this.provider.opts;
51
+ opts = this.opts;
49
52
  }
50
53
  const message = new web3_js_1.TransactionMessage({
51
- payerKey: this.provider.wallet.publicKey,
52
- recentBlockhash: (await this.provider.connection.getRecentBlockhash(opts.preflightCommitment)).blockhash,
54
+ payerKey: this.wallet.publicKey,
55
+ recentBlockhash: (await this.connection.getRecentBlockhash(opts.preflightCommitment)).blockhash,
53
56
  instructions: ixs,
54
57
  }).compileToV0Message(lookupTableAccounts);
55
58
  const tx = new web3_js_1.VersionedTransaction(message);
@@ -61,9 +64,9 @@ class RetryTxSender {
61
64
  signedTx = tx;
62
65
  // @ts-ignore
63
66
  }
64
- else if (this.provider.wallet.payer) {
67
+ else if (this.wallet.payer) {
65
68
  // @ts-ignore
66
- tx.sign((additionalSigners !== null && additionalSigners !== void 0 ? additionalSigners : []).concat(this.provider.wallet.payer));
69
+ tx.sign((additionalSigners !== null && additionalSigners !== void 0 ? additionalSigners : []).concat(this.wallet.payer));
67
70
  signedTx = tx;
68
71
  }
69
72
  else {
@@ -71,10 +74,10 @@ class RetryTxSender {
71
74
  tx.sign([kp]);
72
75
  });
73
76
  // @ts-ignore
74
- signedTx = await this.provider.wallet.signTransaction(tx);
77
+ signedTx = await this.wallet.signTransaction(tx);
75
78
  }
76
79
  if (opts === undefined) {
77
- opts = this.provider.opts;
80
+ opts = this.opts;
78
81
  }
79
82
  return this.sendRawTransaction(signedTx.serialize(), opts);
80
83
  }
@@ -82,7 +85,7 @@ class RetryTxSender {
82
85
  const startTime = this.getTimestamp();
83
86
  let txid;
84
87
  try {
85
- txid = await this.provider.connection.sendRawTransaction(rawTransaction, opts);
88
+ txid = await this.connection.sendRawTransaction(rawTransaction, opts);
86
89
  this.sendToAdditionalConnections(rawTransaction, opts);
87
90
  }
88
91
  catch (e) {
@@ -103,7 +106,7 @@ class RetryTxSender {
103
106
  while (!done && this.getTimestamp() - startTime < this.timeout) {
104
107
  await this.sleep(resolveReference);
105
108
  if (!done) {
106
- this.provider.connection
109
+ this.connection
107
110
  .sendRawTransaction(rawTransaction, opts)
108
111
  .catch((e) => {
109
112
  console.error(e);
@@ -137,12 +140,9 @@ class RetryTxSender {
137
140
  }
138
141
  (0, assert_1.default)(decodedSignature.length === 64, 'signature has invalid length');
139
142
  const start = Date.now();
140
- const subscriptionCommitment = commitment || this.provider.opts.commitment;
143
+ const subscriptionCommitment = commitment || this.opts.commitment;
141
144
  const subscriptionIds = new Array();
142
- const connections = [
143
- this.provider.connection,
144
- ...this.additionalConnections,
145
- ];
145
+ const connections = [this.connection, ...this.additionalConnections];
146
146
  let response = null;
147
147
  const promises = connections.map((connection, i) => {
148
148
  let subscriptionId;
package/lib/tx/types.d.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  /// <reference types="node" />
2
- import { Provider } from '@coral-xyz/anchor';
3
2
  import { AddressLookupTableAccount, ConfirmOptions, Signer, Transaction, TransactionInstruction, TransactionSignature, VersionedTransaction } from '@solana/web3.js';
3
+ import { IWallet } from '../types';
4
4
  export type TxSigAndSlot = {
5
5
  txSig: TransactionSignature;
6
6
  slot: number;
7
7
  };
8
8
  export interface TxSender {
9
- provider: Provider;
9
+ wallet: IWallet;
10
10
  send(tx: Transaction, additionalSigners?: Array<Signer>, opts?: ConfirmOptions, preSigned?: boolean): Promise<TxSigAndSlot>;
11
11
  sendVersionedTransaction(tx: VersionedTransaction, additionalSigners?: Array<Signer>, opts?: ConfirmOptions, preSigned?: boolean): Promise<TxSigAndSlot>;
12
12
  getVersionedTransaction(ixs: TransactionInstruction[], lookupTableAccounts: AddressLookupTableAccount[], additionalSigners?: Array<Signer>, opts?: ConfirmOptions): Promise<VersionedTransaction>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.31.1-beta.7",
3
+ "version": "2.31.1-beta.8",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -273,7 +273,13 @@ export class DriftClient {
273
273
  );
274
274
  }
275
275
  this.eventEmitter = this.accountSubscriber.eventEmitter;
276
- this.txSender = config.txSender ?? new RetryTxSender(this.provider);
276
+ this.txSender =
277
+ config.txSender ??
278
+ new RetryTxSender({
279
+ connection: this.connection,
280
+ wallet: this.wallet,
281
+ opts: this.opts,
282
+ });
277
283
  }
278
284
 
279
285
  public getUserMapKey(subAccountId: number, authority: PublicKey): string {
@@ -514,7 +520,7 @@ export class DriftClient {
514
520
 
515
521
  this.skipLoadUsers = false;
516
522
  // Update provider for txSender with new wallet details
517
- this.txSender.provider = newProvider;
523
+ this.txSender.wallet = newWallet;
518
524
  this.wallet = newWallet;
519
525
  this.provider = newProvider;
520
526
  this.program = newProgram;
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.31.1-beta.7",
2
+ "version": "2.31.1-beta.8",
3
3
  "name": "drift",
4
4
  "instructions": [
5
5
  {
@@ -17,6 +17,7 @@ import {
17
17
  import { AnchorProvider } from '@coral-xyz/anchor';
18
18
  import assert from 'assert';
19
19
  import bs58 from 'bs58';
20
+ import { IWallet } from '../types';
20
21
 
21
22
  const DEFAULT_TIMEOUT = 35000;
22
23
  const DEFAULT_RETRY = 8000;
@@ -26,21 +27,34 @@ type ResolveReference = {
26
27
  };
27
28
 
28
29
  export class RetryTxSender implements TxSender {
29
- provider: AnchorProvider;
30
+ connection: Connection;
31
+ wallet: IWallet;
32
+ opts: ConfirmOptions;
30
33
  timeout: number;
31
34
  retrySleep: number;
32
35
  additionalConnections: Connection[];
33
36
  timoutCount = 0;
34
37
 
35
- public constructor(
36
- provider: AnchorProvider,
37
- timeout?: number,
38
- retrySleep?: number,
39
- additionalConnections = new Array<Connection>()
40
- ) {
41
- this.provider = provider;
42
- this.timeout = timeout ?? DEFAULT_TIMEOUT;
43
- this.retrySleep = retrySleep ?? DEFAULT_RETRY;
38
+ public constructor({
39
+ connection,
40
+ wallet,
41
+ opts = AnchorProvider.defaultOptions(),
42
+ timeout = DEFAULT_TIMEOUT,
43
+ retrySleep = DEFAULT_RETRY,
44
+ additionalConnections = new Array<Connection>(),
45
+ }: {
46
+ connection: Connection;
47
+ wallet: IWallet;
48
+ opts?: ConfirmOptions;
49
+ timeout?: number;
50
+ retrySleep?: number;
51
+ additionalConnections?;
52
+ }) {
53
+ this.connection = connection;
54
+ this.wallet = wallet;
55
+ this.opts = opts;
56
+ this.timeout = timeout;
57
+ this.retrySleep = retrySleep;
44
58
  this.additionalConnections = additionalConnections;
45
59
  }
46
60
 
@@ -54,7 +68,7 @@ export class RetryTxSender implements TxSender {
54
68
  additionalSigners = [];
55
69
  }
56
70
  if (opts === undefined) {
57
- opts = this.provider.opts;
71
+ opts = this.opts;
58
72
  }
59
73
 
60
74
  const signedTx = preSigned
@@ -69,11 +83,9 @@ export class RetryTxSender implements TxSender {
69
83
  additionalSigners: Array<Signer>,
70
84
  opts: ConfirmOptions
71
85
  ): Promise<Transaction> {
72
- tx.feePayer = this.provider.wallet.publicKey;
86
+ tx.feePayer = this.wallet.publicKey;
73
87
  tx.recentBlockhash = (
74
- await this.provider.connection.getRecentBlockhash(
75
- opts.preflightCommitment
76
- )
88
+ await this.connection.getRecentBlockhash(opts.preflightCommitment)
77
89
  ).blockhash;
78
90
 
79
91
  additionalSigners
@@ -82,7 +94,7 @@ export class RetryTxSender implements TxSender {
82
94
  tx.partialSign(kp);
83
95
  });
84
96
 
85
- const signedTx = await this.provider.wallet.signTransaction(tx);
97
+ const signedTx = await this.wallet.signTransaction(tx);
86
98
 
87
99
  return signedTx;
88
100
  }
@@ -97,15 +109,13 @@ export class RetryTxSender implements TxSender {
97
109
  additionalSigners = [];
98
110
  }
99
111
  if (opts === undefined) {
100
- opts = this.provider.opts;
112
+ opts = this.opts;
101
113
  }
102
114
 
103
115
  const message = new TransactionMessage({
104
- payerKey: this.provider.wallet.publicKey,
116
+ payerKey: this.wallet.publicKey,
105
117
  recentBlockhash: (
106
- await this.provider.connection.getRecentBlockhash(
107
- opts.preflightCommitment
108
- )
118
+ await this.connection.getRecentBlockhash(opts.preflightCommitment)
109
119
  ).blockhash,
110
120
  instructions: ixs,
111
121
  }).compileToV0Message(lookupTableAccounts);
@@ -125,9 +135,9 @@ export class RetryTxSender implements TxSender {
125
135
  if (preSigned) {
126
136
  signedTx = tx;
127
137
  // @ts-ignore
128
- } else if (this.provider.wallet.payer) {
138
+ } else if (this.wallet.payer) {
129
139
  // @ts-ignore
130
- tx.sign((additionalSigners ?? []).concat(this.provider.wallet.payer));
140
+ tx.sign((additionalSigners ?? []).concat(this.wallet.payer));
131
141
  signedTx = tx;
132
142
  } else {
133
143
  additionalSigners
@@ -136,11 +146,11 @@ export class RetryTxSender implements TxSender {
136
146
  tx.sign([kp]);
137
147
  });
138
148
  // @ts-ignore
139
- signedTx = await this.provider.wallet.signTransaction(tx);
149
+ signedTx = await this.wallet.signTransaction(tx);
140
150
  }
141
151
 
142
152
  if (opts === undefined) {
143
- opts = this.provider.opts;
153
+ opts = this.opts;
144
154
  }
145
155
 
146
156
  return this.sendRawTransaction(signedTx.serialize(), opts);
@@ -154,10 +164,7 @@ export class RetryTxSender implements TxSender {
154
164
 
155
165
  let txid: TransactionSignature;
156
166
  try {
157
- txid = await this.provider.connection.sendRawTransaction(
158
- rawTransaction,
159
- opts
160
- );
167
+ txid = await this.connection.sendRawTransaction(rawTransaction, opts);
161
168
  this.sendToAdditionalConnections(rawTransaction, opts);
162
169
  } catch (e) {
163
170
  console.error(e);
@@ -179,7 +186,7 @@ export class RetryTxSender implements TxSender {
179
186
  while (!done && this.getTimestamp() - startTime < this.timeout) {
180
187
  await this.sleep(resolveReference);
181
188
  if (!done) {
182
- this.provider.connection
189
+ this.connection
183
190
  .sendRawTransaction(rawTransaction, opts)
184
191
  .catch((e) => {
185
192
  console.error(e);
@@ -218,13 +225,10 @@ export class RetryTxSender implements TxSender {
218
225
  assert(decodedSignature.length === 64, 'signature has invalid length');
219
226
 
220
227
  const start = Date.now();
221
- const subscriptionCommitment = commitment || this.provider.opts.commitment;
228
+ const subscriptionCommitment = commitment || this.opts.commitment;
222
229
 
223
230
  const subscriptionIds = new Array<number>();
224
- const connections = [
225
- this.provider.connection,
226
- ...this.additionalConnections,
227
- ];
231
+ const connections = [this.connection, ...this.additionalConnections];
228
232
  let response: RpcResponseAndContext<SignatureResult> | null = null;
229
233
  const promises = connections.map((connection, i) => {
230
234
  let subscriptionId;
package/src/tx/types.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { Provider } from '@coral-xyz/anchor';
2
1
  import {
3
2
  AddressLookupTableAccount,
4
3
  ConfirmOptions,
@@ -8,6 +7,7 @@ import {
8
7
  TransactionSignature,
9
8
  VersionedTransaction,
10
9
  } from '@solana/web3.js';
10
+ import { IWallet } from '../types';
11
11
 
12
12
  export type TxSigAndSlot = {
13
13
  txSig: TransactionSignature;
@@ -15,7 +15,7 @@ export type TxSigAndSlot = {
15
15
  };
16
16
 
17
17
  export interface TxSender {
18
- provider: Provider;
18
+ wallet: IWallet;
19
19
 
20
20
  send(
21
21
  tx: Transaction,