@drift-labs/sdk 2.31.1-beta.6 → 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.6
1
+ 2.31.1-beta.8
@@ -51,6 +51,7 @@ export declare class DriftClient {
51
51
  authoritySubAccountMap?: Map<string, number[]>;
52
52
  skipLoadUsers?: boolean;
53
53
  txVersion: TransactionVersion;
54
+ txParams: TxParams;
54
55
  get isSubscribed(): boolean;
55
56
  set isSubscribed(val: boolean);
56
57
  constructor(config: DriftClientConfig);
@@ -64,7 +64,7 @@ class DriftClient {
64
64
  this._isSubscribed = val;
65
65
  }
66
66
  constructor(config) {
67
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
67
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
68
68
  this.users = new Map();
69
69
  this._isSubscribed = false;
70
70
  this.perpMarketLastSlotCache = new Map();
@@ -78,6 +78,10 @@ class DriftClient {
78
78
  this.activeSubAccountId = (_c = config.activeSubAccountId) !== null && _c !== void 0 ? _c : 0;
79
79
  this.skipLoadUsers = (_d = config.skipLoadUsers) !== null && _d !== void 0 ? _d : false;
80
80
  this.txVersion = (_e = config.txVersion) !== null && _e !== void 0 ? _e : 'legacy';
81
+ this.txParams = {
82
+ computeUnits: (_g = (_f = config.txParams) === null || _f === void 0 ? void 0 : _f.computeUnits) !== null && _g !== void 0 ? _g : 600000,
83
+ computeUnitsPrice: (_j = (_h = config.txParams) === null || _h === void 0 ? void 0 : _h.computeUnitsPrice) !== null && _j !== void 0 ? _j : 0,
84
+ };
81
85
  if (config.includeDelegates && config.subAccountIds) {
82
86
  throw new Error('Can only pass one of includeDelegates or subAccountIds. If you want to specify subaccount ids for multiple authorities, pass authoritySubaccountMap instead');
83
87
  }
@@ -92,8 +96,8 @@ class DriftClient {
92
96
  : config.subAccountIds
93
97
  ? new Map([[this.authority.toString(), config.subAccountIds]])
94
98
  : new Map();
95
- this.includeDelegates = (_f = config.includeDelegates) !== null && _f !== void 0 ? _f : false;
96
- if (((_g = config.accountSubscription) === null || _g === void 0 ? void 0 : _g.type) === 'polling') {
99
+ this.includeDelegates = (_k = config.includeDelegates) !== null && _k !== void 0 ? _k : false;
100
+ if (((_l = config.accountSubscription) === null || _l === void 0 ? void 0 : _l.type) === 'polling') {
97
101
  this.userAccountSubscriptionConfig = {
98
102
  type: 'polling',
99
103
  accountLoader: config.accountSubscription.accountLoader,
@@ -125,14 +129,19 @@ class DriftClient {
125
129
  const noMarketsAndOraclesSpecified = config.perpMarketIndexes === undefined &&
126
130
  config.spotMarketIndexes === undefined &&
127
131
  config.oracleInfos === undefined;
128
- if (((_h = config.accountSubscription) === null || _h === void 0 ? void 0 : _h.type) === 'polling') {
129
- this.accountSubscriber = new pollingDriftClientAccountSubscriber_1.PollingDriftClientAccountSubscriber(this.program, config.accountSubscription.accountLoader, (_j = config.perpMarketIndexes) !== null && _j !== void 0 ? _j : [], (_k = config.spotMarketIndexes) !== null && _k !== void 0 ? _k : [], (_l = config.oracleInfos) !== null && _l !== void 0 ? _l : [], noMarketsAndOraclesSpecified);
132
+ if (((_m = config.accountSubscription) === null || _m === void 0 ? void 0 : _m.type) === 'polling') {
133
+ this.accountSubscriber = new pollingDriftClientAccountSubscriber_1.PollingDriftClientAccountSubscriber(this.program, config.accountSubscription.accountLoader, (_o = config.perpMarketIndexes) !== null && _o !== void 0 ? _o : [], (_p = config.spotMarketIndexes) !== null && _p !== void 0 ? _p : [], (_q = config.oracleInfos) !== null && _q !== void 0 ? _q : [], noMarketsAndOraclesSpecified);
130
134
  }
131
135
  else {
132
- this.accountSubscriber = new webSocketDriftClientAccountSubscriber_1.WebSocketDriftClientAccountSubscriber(this.program, (_m = config.perpMarketIndexes) !== null && _m !== void 0 ? _m : [], (_o = config.spotMarketIndexes) !== null && _o !== void 0 ? _o : [], (_p = config.oracleInfos) !== null && _p !== void 0 ? _p : [], noMarketsAndOraclesSpecified);
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);
133
137
  }
134
138
  this.eventEmitter = this.accountSubscriber.eventEmitter;
135
- this.txSender = (_q = config.txSender) !== null && _q !== void 0 ? _q : 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
+ });
136
145
  }
137
146
  getUserMapKey(subAccountId, authority) {
138
147
  return `${subAccountId}_${authority.toString()}`;
@@ -283,7 +292,7 @@ class DriftClient {
283
292
  const newProgram = new anchor_1.Program(drift_json_1.default, this.program.programId, newProvider);
284
293
  this.skipLoadUsers = false;
285
294
  // Update provider for txSender with new wallet details
286
- this.txSender.provider = newProvider;
295
+ this.txSender.wallet = newWallet;
287
296
  this.wallet = newWallet;
288
297
  this.provider = newProvider;
289
298
  this.program = newProgram;
@@ -3071,13 +3080,13 @@ class DriftClient {
3071
3080
  async buildTransaction(instructions, txParams, txVersion, lookupTables) {
3072
3081
  var _a, _b;
3073
3082
  const allIx = [];
3074
- const computeUnits = (_a = txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits) !== null && _a !== void 0 ? _a : 600000;
3083
+ const computeUnits = (_a = txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits) !== null && _a !== void 0 ? _a : this.txParams.computeUnits;
3075
3084
  if (computeUnits !== 200000) {
3076
3085
  allIx.push(web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({
3077
3086
  units: computeUnits,
3078
3087
  }));
3079
3088
  }
3080
- const computeUnitsPrice = (_b = txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice) !== null && _b !== void 0 ? _b : 0;
3089
+ const computeUnitsPrice = (_b = txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice) !== null && _b !== void 0 ? _b : this.txParams.computeUnitsPrice;
3081
3090
  if (computeUnitsPrice !== 0) {
3082
3091
  allIx.push(web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({
3083
3092
  microLamports: computeUnitsPrice,
@@ -1,5 +1,5 @@
1
1
  import { ConfirmOptions, Connection, PublicKey, TransactionVersion } from '@solana/web3.js';
2
- import { IWallet } from './types';
2
+ import { IWallet, TxParams } from './types';
3
3
  import { OracleInfo } from './oracles/types';
4
4
  import { BulkAccountLoader } from './accounts/bulkAccountLoader';
5
5
  import { DriftEnv } from './config';
@@ -24,6 +24,7 @@ export type DriftClientConfig = {
24
24
  authoritySubAccountMap?: Map<string, number[]>;
25
25
  skipLoadUsers?: boolean;
26
26
  txVersion?: TransactionVersion;
27
+ txParams?: TxParams;
27
28
  };
28
29
  export type DriftClientSubscriptionConfig = {
29
30
  type: 'websocket';
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.31.1-beta.5",
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.6",
3
+ "version": "2.31.1-beta.8",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -155,6 +155,7 @@ export class DriftClient {
155
155
  authoritySubAccountMap?: Map<string, number[]>;
156
156
  skipLoadUsers?: boolean;
157
157
  txVersion: TransactionVersion;
158
+ txParams: TxParams;
158
159
 
159
160
  public get isSubscribed() {
160
161
  return this._isSubscribed && this.accountSubscriber.isSubscribed;
@@ -183,6 +184,10 @@ export class DriftClient {
183
184
  this.activeSubAccountId = config.activeSubAccountId ?? 0;
184
185
  this.skipLoadUsers = config.skipLoadUsers ?? false;
185
186
  this.txVersion = config.txVersion ?? 'legacy';
187
+ this.txParams = {
188
+ computeUnits: config.txParams?.computeUnits ?? 600_000,
189
+ computeUnitsPrice: config.txParams?.computeUnitsPrice ?? 0,
190
+ };
186
191
 
187
192
  if (config.includeDelegates && config.subAccountIds) {
188
193
  throw new Error(
@@ -268,7 +273,13 @@ export class DriftClient {
268
273
  );
269
274
  }
270
275
  this.eventEmitter = this.accountSubscriber.eventEmitter;
271
- 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
+ });
272
283
  }
273
284
 
274
285
  public getUserMapKey(subAccountId: number, authority: PublicKey): string {
@@ -509,7 +520,7 @@ export class DriftClient {
509
520
 
510
521
  this.skipLoadUsers = false;
511
522
  // Update provider for txSender with new wallet details
512
- this.txSender.provider = newProvider;
523
+ this.txSender.wallet = newWallet;
513
524
  this.wallet = newWallet;
514
525
  this.provider = newProvider;
515
526
  this.program = newProgram;
@@ -5401,7 +5412,7 @@ export class DriftClient {
5401
5412
  lookupTables?: AddressLookupTableAccount[]
5402
5413
  ): Promise<Transaction | VersionedTransaction> {
5403
5414
  const allIx = [];
5404
- const computeUnits = txParams?.computeUnits ?? 600_000;
5415
+ const computeUnits = txParams?.computeUnits ?? this.txParams.computeUnits;
5405
5416
  if (computeUnits !== 200_000) {
5406
5417
  allIx.push(
5407
5418
  ComputeBudgetProgram.setComputeUnitLimit({
@@ -5409,7 +5420,8 @@ export class DriftClient {
5409
5420
  })
5410
5421
  );
5411
5422
  }
5412
- const computeUnitsPrice = txParams?.computeUnitsPrice ?? 0;
5423
+ const computeUnitsPrice =
5424
+ txParams?.computeUnitsPrice ?? this.txParams.computeUnitsPrice;
5413
5425
  if (computeUnitsPrice !== 0) {
5414
5426
  allIx.push(
5415
5427
  ComputeBudgetProgram.setComputeUnitPrice({
@@ -4,7 +4,7 @@ import {
4
4
  PublicKey,
5
5
  TransactionVersion,
6
6
  } from '@solana/web3.js';
7
- import { IWallet } from './types';
7
+ import { IWallet, TxParams } from './types';
8
8
  import { OracleInfo } from './oracles/types';
9
9
  import { BulkAccountLoader } from './accounts/bulkAccountLoader';
10
10
  import { DriftEnv } from './config';
@@ -30,6 +30,7 @@ export type DriftClientConfig = {
30
30
  authoritySubAccountMap?: Map<string, number[]>; // if passed this will override subAccountIds and includeDelegates
31
31
  skipLoadUsers?: boolean; // if passed to constructor, no user accounts will be loaded. they will load if updateWallet is called afterwards.
32
32
  txVersion?: TransactionVersion; // which tx version to use
33
+ txParams?: TxParams; // default tx params to use
33
34
  };
34
35
 
35
36
  export type DriftClientSubscriptionConfig =
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.31.1-beta.6",
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,