@drift-labs/sdk 2.97.0-beta.26 → 2.97.0-beta.28

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.
Files changed (37) hide show
  1. package/VERSION +1 -1
  2. package/lib/browser/index.d.ts +7 -0
  3. package/lib/browser/index.js +7 -0
  4. package/lib/browser/oracles/pythClient.d.ts +0 -1
  5. package/lib/browser/oracles/pythClient.js +1 -2
  6. package/lib/browser/tx/baseTxSender.d.ts +3 -1
  7. package/lib/browser/tx/baseTxSender.js +8 -3
  8. package/lib/browser/tx/fastSingleTxSender.d.ts +2 -1
  9. package/lib/browser/tx/fastSingleTxSender.js +2 -1
  10. package/lib/browser/tx/forwardOnlyTxSender.d.ts +2 -1
  11. package/lib/browser/tx/forwardOnlyTxSender.js +2 -1
  12. package/lib/browser/tx/retryTxSender.d.ts +2 -1
  13. package/lib/browser/tx/retryTxSender.js +2 -1
  14. package/lib/browser/tx/whileValidTxSender.d.ts +2 -1
  15. package/lib/browser/tx/whileValidTxSender.js +2 -1
  16. package/lib/node/index.d.ts +7 -0
  17. package/lib/node/index.js +7 -0
  18. package/lib/node/oracles/pythClient.d.ts +0 -1
  19. package/lib/node/oracles/pythClient.js +1 -2
  20. package/lib/node/tx/baseTxSender.d.ts +3 -1
  21. package/lib/node/tx/baseTxSender.js +8 -3
  22. package/lib/node/tx/fastSingleTxSender.d.ts +2 -1
  23. package/lib/node/tx/fastSingleTxSender.js +2 -1
  24. package/lib/node/tx/forwardOnlyTxSender.d.ts +2 -1
  25. package/lib/node/tx/forwardOnlyTxSender.js +2 -1
  26. package/lib/node/tx/retryTxSender.d.ts +2 -1
  27. package/lib/node/tx/retryTxSender.js +2 -1
  28. package/lib/node/tx/whileValidTxSender.d.ts +2 -1
  29. package/lib/node/tx/whileValidTxSender.js +2 -1
  30. package/package.json +1 -1
  31. package/src/index.ts +7 -0
  32. package/src/oracles/pythClient.ts +1 -5
  33. package/src/tx/baseTxSender.ts +20 -12
  34. package/src/tx/fastSingleTxSender.ts +3 -0
  35. package/src/tx/forwardOnlyTxSender.ts +3 -0
  36. package/src/tx/retryTxSender.ts +3 -0
  37. package/src/tx/whileValidTxSender.ts +3 -0
package/VERSION CHANGED
@@ -1 +1 @@
1
- 2.97.0-beta.26
1
+ 2.97.0-beta.28
@@ -24,12 +24,14 @@ export * from './accounts/oneShotUserAccountSubscriber';
24
24
  export * from './accounts/types';
25
25
  export * from './addresses/pda';
26
26
  export * from './adminClient';
27
+ export * from './assert/assert';
27
28
  export * from './testClient';
28
29
  export * from './user';
29
30
  export * from './userConfig';
30
31
  export * from './userStats';
31
32
  export * from './userName';
32
33
  export * from './userStatsConfig';
34
+ export * from './decode/user';
33
35
  export * from './driftClient';
34
36
  export * from './factory/oracleClient';
35
37
  export * from './factory/bigNum';
@@ -58,6 +60,7 @@ export * from './math/insurance';
58
60
  export * from './math/superStake';
59
61
  export * from './math/spotPosition';
60
62
  export * from './math/state';
63
+ export * from './math/tiers';
61
64
  export * from './marinade';
62
65
  export * from './orderParams';
63
66
  export * from './slot/SlotSubscriber';
@@ -75,6 +78,9 @@ export * from './priorityFee';
75
78
  export * from './phoenix/phoenixFulfillmentConfigMap';
76
79
  export * from './openbook/openbookV2Subscriber';
77
80
  export * from './openbook/openbookV2FulfillmentConfigMap';
81
+ export * from './oracles/pythClient';
82
+ export * from './oracles/pythPullClient';
83
+ export * from './oracles/switchboardOnDemandClient';
78
84
  export * from './tx/fastSingleTxSender';
79
85
  export * from './tx/retryTxSender';
80
86
  export * from './tx/whileValidTxSender';
@@ -85,6 +91,7 @@ export * from './tx/txHandler';
85
91
  export * from './util/computeUnits';
86
92
  export * from './util/tps';
87
93
  export * from './util/promiseTimeout';
94
+ export * from './util/pythPullOracleUtils';
88
95
  export * from './math/spotBalance';
89
96
  export * from './constants/spotMarkets';
90
97
  export * from './driftClientConfig';
@@ -47,12 +47,14 @@ __exportStar(require("./accounts/oneShotUserAccountSubscriber"), exports);
47
47
  __exportStar(require("./accounts/types"), exports);
48
48
  __exportStar(require("./addresses/pda"), exports);
49
49
  __exportStar(require("./adminClient"), exports);
50
+ __exportStar(require("./assert/assert"), exports);
50
51
  __exportStar(require("./testClient"), exports);
51
52
  __exportStar(require("./user"), exports);
52
53
  __exportStar(require("./userConfig"), exports);
53
54
  __exportStar(require("./userStats"), exports);
54
55
  __exportStar(require("./userName"), exports);
55
56
  __exportStar(require("./userStatsConfig"), exports);
57
+ __exportStar(require("./decode/user"), exports);
56
58
  __exportStar(require("./driftClient"), exports);
57
59
  __exportStar(require("./factory/oracleClient"), exports);
58
60
  __exportStar(require("./factory/bigNum"), exports);
@@ -81,6 +83,7 @@ __exportStar(require("./math/insurance"), exports);
81
83
  __exportStar(require("./math/superStake"), exports);
82
84
  __exportStar(require("./math/spotPosition"), exports);
83
85
  __exportStar(require("./math/state"), exports);
86
+ __exportStar(require("./math/tiers"), exports);
84
87
  __exportStar(require("./marinade"), exports);
85
88
  __exportStar(require("./orderParams"), exports);
86
89
  __exportStar(require("./slot/SlotSubscriber"), exports);
@@ -98,6 +101,9 @@ __exportStar(require("./priorityFee"), exports);
98
101
  __exportStar(require("./phoenix/phoenixFulfillmentConfigMap"), exports);
99
102
  __exportStar(require("./openbook/openbookV2Subscriber"), exports);
100
103
  __exportStar(require("./openbook/openbookV2FulfillmentConfigMap"), exports);
104
+ __exportStar(require("./oracles/pythClient"), exports);
105
+ __exportStar(require("./oracles/pythPullClient"), exports);
106
+ __exportStar(require("./oracles/switchboardOnDemandClient"), exports);
101
107
  __exportStar(require("./tx/fastSingleTxSender"), exports);
102
108
  __exportStar(require("./tx/retryTxSender"), exports);
103
109
  __exportStar(require("./tx/whileValidTxSender"), exports);
@@ -108,6 +114,7 @@ __exportStar(require("./tx/txHandler"), exports);
108
114
  __exportStar(require("./util/computeUnits"), exports);
109
115
  __exportStar(require("./util/tps"), exports);
110
116
  __exportStar(require("./util/promiseTimeout"), exports);
117
+ __exportStar(require("./util/pythPullOracleUtils"), exports);
111
118
  __exportStar(require("./math/spotBalance"), exports);
112
119
  __exportStar(require("./constants/spotMarkets"), exports);
113
120
  __exportStar(require("./driftClientConfig"), exports);
@@ -12,4 +12,3 @@ export declare class PythClient implements OracleClient {
12
12
  getOraclePriceData(pricePublicKey: PublicKey): Promise<OraclePriceData>;
13
13
  getOraclePriceDataFromBuffer(buffer: Buffer): OraclePriceData;
14
14
  }
15
- export declare function convertPythPrice(price: number, exponent: number, multiple: BN): BN;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.convertPythPrice = exports.PythClient = void 0;
3
+ exports.PythClient = void 0;
4
4
  const client_1 = require("@pythnetwork/client");
5
5
  const anchor_1 = require("@coral-xyz/anchor");
6
6
  const numericConstants_1 = require("../constants/numericConstants");
@@ -40,7 +40,6 @@ function convertPythPrice(price, exponent, multiple) {
40
40
  .mul(numericConstants_1.PRICE_PRECISION)
41
41
  .div(pythPrecision);
42
42
  }
43
- exports.convertPythPrice = convertPythPrice;
44
43
  const fiveBPS = new anchor_1.BN(500);
45
44
  function getStableCoinPrice(price, confidence) {
46
45
  if (price.sub(numericConstants_1.QUOTE_PRECISION).abs().lt(anchor_1.BN.min(confidence, fiveBPS))) {
@@ -16,12 +16,13 @@ export declare abstract class BaseTxSender implements TxSender {
16
16
  additionalTxSenderCallbacks: ((base58EncodedTx: string) => void)[];
17
17
  txHandler: TxHandler;
18
18
  trackTxLandRate?: boolean;
19
+ throwOnTimeoutError: boolean;
19
20
  lookbackWindowMinutes: number;
20
21
  txSigCache?: NodeCache;
21
22
  txLandRate: number;
22
23
  lastPriorityFeeSuggestion: number;
23
24
  landRateToFeeFunc: (landRate: number) => number;
24
- constructor({ connection, wallet, opts, timeout, additionalConnections, confirmationStrategy, additionalTxSenderCallbacks, trackTxLandRate, txHandler, txLandRateLookbackWindowMinutes, landRateToFeeFunc, }: {
25
+ constructor({ connection, wallet, opts, timeout, additionalConnections, confirmationStrategy, additionalTxSenderCallbacks, trackTxLandRate, txHandler, txLandRateLookbackWindowMinutes, landRateToFeeFunc, throwOnTimeoutError, }: {
25
26
  connection: Connection;
26
27
  wallet: IWallet;
27
28
  opts?: ConfirmOptions;
@@ -33,6 +34,7 @@ export declare abstract class BaseTxSender implements TxSender {
33
34
  trackTxLandRate?: boolean;
34
35
  txLandRateLookbackWindowMinutes?: number;
35
36
  landRateToFeeFunc?: (landRate: number) => number;
37
+ throwOnTimeoutError?: boolean;
36
38
  });
37
39
  send(tx: Transaction, additionalSigners?: Array<Signer>, opts?: ConfirmOptions, preSigned?: boolean): Promise<TxSigAndSlot>;
38
40
  prepareTx(tx: Transaction, additionalSigners: Array<Signer>, opts: ConfirmOptions, preSigned?: boolean): Promise<Transaction>;
@@ -16,7 +16,7 @@ const BASELINE_TX_LAND_RATE = 0.9;
16
16
  const DEFAULT_TIMEOUT = 35000;
17
17
  const DEFAULT_TX_LAND_RATE_LOOKBACK_WINDOW_MINUTES = 10;
18
18
  class BaseTxSender {
19
- constructor({ connection, wallet, opts = config_1.DEFAULT_CONFIRMATION_OPTS, timeout = DEFAULT_TIMEOUT, additionalConnections = new Array(), confirmationStrategy = types_1.ConfirmationStrategy.Combo, additionalTxSenderCallbacks, trackTxLandRate, txHandler, txLandRateLookbackWindowMinutes = DEFAULT_TX_LAND_RATE_LOOKBACK_WINDOW_MINUTES, landRateToFeeFunc, }) {
19
+ constructor({ connection, wallet, opts = config_1.DEFAULT_CONFIRMATION_OPTS, timeout = DEFAULT_TIMEOUT, additionalConnections = new Array(), confirmationStrategy = types_1.ConfirmationStrategy.Combo, additionalTxSenderCallbacks, trackTxLandRate, txHandler, txLandRateLookbackWindowMinutes = DEFAULT_TX_LAND_RATE_LOOKBACK_WINDOW_MINUTES, landRateToFeeFunc, throwOnTimeoutError = true, }) {
20
20
  this.timeoutCount = 0;
21
21
  this.txLandRate = 0;
22
22
  this.lastPriorityFeeSuggestion = 1;
@@ -43,6 +43,7 @@ class BaseTxSender {
43
43
  }
44
44
  this.landRateToFeeFunc =
45
45
  landRateToFeeFunc !== null && landRateToFeeFunc !== void 0 ? landRateToFeeFunc : this.defaultLandRateToFeeFunc.bind(this);
46
+ this.throwOnTimeoutError = throwOnTimeoutError;
46
47
  }
47
48
  async send(tx, additionalSigners, opts, preSigned) {
48
49
  if (additionalSigners === undefined) {
@@ -166,7 +167,9 @@ class BaseTxSender {
166
167
  }
167
168
  this.timeoutCount += 1;
168
169
  const duration = (Date.now() - start) / 1000;
169
- throw new types_1.TxSendError(`Transaction was not confirmed in ${duration.toFixed(2)} seconds. It is unknown if it succeeded or failed. Check signature ${signature} using the Solana Explorer or CLI tools.`, txConstants_1.NOT_CONFIRMED_ERROR_CODE);
170
+ if (this.throwOnTimeoutError) {
171
+ throw new types_1.TxSendError(`Transaction was not confirmed in ${duration.toFixed(2)} seconds. It is unknown if it succeeded or failed. Check signature ${signature} using the Solana Explorer or CLI tools.`, txConstants_1.NOT_CONFIRMED_ERROR_CODE);
172
+ }
170
173
  }
171
174
  return response;
172
175
  }
@@ -192,7 +195,9 @@ class BaseTxSender {
192
195
  // Transaction not confirmed within 30 seconds
193
196
  this.timeoutCount += 1;
194
197
  const duration = (Date.now() - start) / 1000;
195
- throw new types_1.TxSendError(`Transaction was not confirmed in ${duration.toFixed(2)} seconds. It is unknown if it succeeded or failed. Check signature ${signature} using the Solana Explorer or CLI tools.`, txConstants_1.NOT_CONFIRMED_ERROR_CODE);
198
+ if (this.throwOnTimeoutError) {
199
+ throw new types_1.TxSendError(`Transaction was not confirmed in ${duration.toFixed(2)} seconds. It is unknown if it succeeded or failed. Check signature ${signature} using the Solana Explorer or CLI tools.`, txConstants_1.NOT_CONFIRMED_ERROR_CODE);
200
+ }
196
201
  }
197
202
  async confirmTransaction(signature, commitment) {
198
203
  if (this.confirmationStrategy === types_1.ConfirmationStrategy.WebSocket ||
@@ -19,7 +19,7 @@ export declare class FastSingleTxSender extends BaseTxSender {
19
19
  confirmInBackground: boolean;
20
20
  blockhashCommitment: Commitment;
21
21
  blockhashIntervalId: NodeJS.Timer;
22
- constructor({ connection, wallet, opts, timeout, blockhashRefreshInterval, additionalConnections, skipConfirmation, confirmInBackground, blockhashCommitment, confirmationStrategy, trackTxLandRate, txHandler, txLandRateLookbackWindowMinutes, landRateToFeeFunc, }: {
22
+ constructor({ connection, wallet, opts, timeout, blockhashRefreshInterval, additionalConnections, skipConfirmation, confirmInBackground, blockhashCommitment, confirmationStrategy, trackTxLandRate, txHandler, txLandRateLookbackWindowMinutes, landRateToFeeFunc, throwOnTimeoutError, }: {
23
23
  connection: Connection;
24
24
  wallet: IWallet;
25
25
  opts?: ConfirmOptions;
@@ -34,6 +34,7 @@ export declare class FastSingleTxSender extends BaseTxSender {
34
34
  txHandler?: TxHandler;
35
35
  txLandRateLookbackWindowMinutes?: number;
36
36
  landRateToFeeFunc?: (landRate: number) => number;
37
+ throwOnTimeoutError?: boolean;
37
38
  });
38
39
  startBlockhashRefreshLoop(): void;
39
40
  sendRawTransaction(rawTransaction: Buffer | Uint8Array, opts: ConfirmOptions): Promise<TxSigAndSlot>;
@@ -7,7 +7,7 @@ const config_1 = require("../config");
7
7
  const DEFAULT_TIMEOUT = 35000;
8
8
  const DEFAULT_BLOCKHASH_REFRESH = 10000;
9
9
  class FastSingleTxSender extends baseTxSender_1.BaseTxSender {
10
- constructor({ connection, wallet, opts = { ...config_1.DEFAULT_CONFIRMATION_OPTS, maxRetries: 0 }, timeout = DEFAULT_TIMEOUT, blockhashRefreshInterval = DEFAULT_BLOCKHASH_REFRESH, additionalConnections = new Array(), skipConfirmation = false, confirmInBackground = false, blockhashCommitment = 'finalized', confirmationStrategy = types_1.ConfirmationStrategy.Combo, trackTxLandRate, txHandler, txLandRateLookbackWindowMinutes, landRateToFeeFunc, }) {
10
+ constructor({ connection, wallet, opts = { ...config_1.DEFAULT_CONFIRMATION_OPTS, maxRetries: 0 }, timeout = DEFAULT_TIMEOUT, blockhashRefreshInterval = DEFAULT_BLOCKHASH_REFRESH, additionalConnections = new Array(), skipConfirmation = false, confirmInBackground = false, blockhashCommitment = 'finalized', confirmationStrategy = types_1.ConfirmationStrategy.Combo, trackTxLandRate, txHandler, txLandRateLookbackWindowMinutes, landRateToFeeFunc, throwOnTimeoutError = true, }) {
11
11
  super({
12
12
  connection,
13
13
  wallet,
@@ -19,6 +19,7 @@ class FastSingleTxSender extends baseTxSender_1.BaseTxSender {
19
19
  trackTxLandRate,
20
20
  txLandRateLookbackWindowMinutes,
21
21
  landRateToFeeFunc,
22
+ throwOnTimeoutError,
22
23
  });
23
24
  this.timoutCount = 0;
24
25
  this.connection = connection;
@@ -16,7 +16,7 @@ export declare class ForwardOnlyTxSender extends BaseTxSender {
16
16
  retrySleep: number;
17
17
  additionalConnections: Connection[];
18
18
  timoutCount: number;
19
- constructor({ connection, wallet, opts, timeout, retrySleep, confirmationStrategy, additionalTxSenderCallbacks, txHandler, trackTxLandRate, txLandRateLookbackWindowMinutes, landRateToFeeFunc, }: {
19
+ constructor({ connection, wallet, opts, timeout, retrySleep, confirmationStrategy, additionalTxSenderCallbacks, txHandler, trackTxLandRate, txLandRateLookbackWindowMinutes, landRateToFeeFunc, throwOnTimeoutError, }: {
20
20
  connection: Connection;
21
21
  wallet: IWallet;
22
22
  opts?: ConfirmOptions;
@@ -28,6 +28,7 @@ export declare class ForwardOnlyTxSender extends BaseTxSender {
28
28
  trackTxLandRate?: boolean;
29
29
  txLandRateLookbackWindowMinutes?: number;
30
30
  landRateToFeeFunc?: (landRate: number) => number;
31
+ throwOnTimeoutError?: boolean;
31
32
  });
32
33
  sleep(reference: ResolveReference): Promise<void>;
33
34
  sendToAdditionalConnections(rawTx: Buffer | Uint8Array, _opts: ConfirmOptions): void;
@@ -12,7 +12,7 @@ const config_1 = require("../config");
12
12
  const DEFAULT_TIMEOUT = 35000;
13
13
  const DEFAULT_RETRY = 5000;
14
14
  class ForwardOnlyTxSender extends baseTxSender_1.BaseTxSender {
15
- constructor({ connection, wallet, opts = { ...config_1.DEFAULT_CONFIRMATION_OPTS, maxRetries: 0 }, timeout = DEFAULT_TIMEOUT, retrySleep = DEFAULT_RETRY, confirmationStrategy = types_1.ConfirmationStrategy.Combo, additionalTxSenderCallbacks = [], txHandler, trackTxLandRate, txLandRateLookbackWindowMinutes, landRateToFeeFunc, }) {
15
+ constructor({ connection, wallet, opts = { ...config_1.DEFAULT_CONFIRMATION_OPTS, maxRetries: 0 }, timeout = DEFAULT_TIMEOUT, retrySleep = DEFAULT_RETRY, confirmationStrategy = types_1.ConfirmationStrategy.Combo, additionalTxSenderCallbacks = [], txHandler, trackTxLandRate, txLandRateLookbackWindowMinutes, landRateToFeeFunc, throwOnTimeoutError = true, }) {
16
16
  super({
17
17
  connection,
18
18
  wallet,
@@ -25,6 +25,7 @@ class ForwardOnlyTxSender extends baseTxSender_1.BaseTxSender {
25
25
  trackTxLandRate,
26
26
  txLandRateLookbackWindowMinutes,
27
27
  landRateToFeeFunc,
28
+ throwOnTimeoutError,
28
29
  });
29
30
  this.timoutCount = 0;
30
31
  this.connection = connection;
@@ -16,7 +16,7 @@ export declare class RetryTxSender extends BaseTxSender {
16
16
  retrySleep: number;
17
17
  additionalConnections: Connection[];
18
18
  timoutCount: number;
19
- constructor({ connection, wallet, opts, timeout, retrySleep, additionalConnections, confirmationStrategy, additionalTxSenderCallbacks, txHandler, trackTxLandRate, txLandRateLookbackWindowMinutes, landRateToFeeFunc, }: {
19
+ constructor({ connection, wallet, opts, timeout, retrySleep, additionalConnections, confirmationStrategy, additionalTxSenderCallbacks, txHandler, trackTxLandRate, txLandRateLookbackWindowMinutes, landRateToFeeFunc, throwOnTimeoutError, }: {
20
20
  connection: Connection;
21
21
  wallet: IWallet;
22
22
  opts?: ConfirmOptions;
@@ -29,6 +29,7 @@ export declare class RetryTxSender extends BaseTxSender {
29
29
  trackTxLandRate?: boolean;
30
30
  txLandRateLookbackWindowMinutes?: number;
31
31
  landRateToFeeFunc?: (landRate: number) => number;
32
+ throwOnTimeoutError?: boolean;
32
33
  });
33
34
  sleep(reference: ResolveReference): Promise<void>;
34
35
  sendRawTransaction(rawTransaction: Buffer | Uint8Array, opts: ConfirmOptions): Promise<TxSigAndSlot>;
@@ -7,7 +7,7 @@ const config_1 = require("../config");
7
7
  const DEFAULT_TIMEOUT = 35000;
8
8
  const DEFAULT_RETRY = 2000;
9
9
  class RetryTxSender extends baseTxSender_1.BaseTxSender {
10
- constructor({ connection, wallet, opts = { ...config_1.DEFAULT_CONFIRMATION_OPTS, maxRetries: 0 }, timeout = DEFAULT_TIMEOUT, retrySleep = DEFAULT_RETRY, additionalConnections = new Array(), confirmationStrategy = types_1.ConfirmationStrategy.Combo, additionalTxSenderCallbacks = [], txHandler, trackTxLandRate, txLandRateLookbackWindowMinutes, landRateToFeeFunc, }) {
10
+ constructor({ connection, wallet, opts = { ...config_1.DEFAULT_CONFIRMATION_OPTS, maxRetries: 0 }, timeout = DEFAULT_TIMEOUT, retrySleep = DEFAULT_RETRY, additionalConnections = new Array(), confirmationStrategy = types_1.ConfirmationStrategy.Combo, additionalTxSenderCallbacks = [], txHandler, trackTxLandRate, txLandRateLookbackWindowMinutes, landRateToFeeFunc, throwOnTimeoutError = true, }) {
11
11
  super({
12
12
  connection,
13
13
  wallet,
@@ -20,6 +20,7 @@ class RetryTxSender extends baseTxSender_1.BaseTxSender {
20
20
  trackTxLandRate,
21
21
  txLandRateLookbackWindowMinutes,
22
22
  landRateToFeeFunc,
23
+ throwOnTimeoutError,
23
24
  });
24
25
  this.timoutCount = 0;
25
26
  this.connection = connection;
@@ -22,7 +22,7 @@ export declare class WhileValidTxSender extends BaseTxSender {
22
22
  }>;
23
23
  useBlockHeightOffset: boolean;
24
24
  private checkAndSetUseBlockHeightOffset;
25
- constructor({ connection, wallet, opts, retrySleep, additionalConnections, confirmationStrategy, additionalTxSenderCallbacks, txHandler, trackTxLandRate, txLandRateLookbackWindowMinutes, landRateToFeeFunc, }: {
25
+ constructor({ connection, wallet, opts, retrySleep, additionalConnections, confirmationStrategy, additionalTxSenderCallbacks, txHandler, trackTxLandRate, txLandRateLookbackWindowMinutes, landRateToFeeFunc, throwOnTimeoutError, }: {
26
26
  connection: Connection;
27
27
  wallet: IWallet;
28
28
  opts?: ConfirmOptions;
@@ -34,6 +34,7 @@ export declare class WhileValidTxSender extends BaseTxSender {
34
34
  trackTxLandRate?: boolean;
35
35
  txLandRateLookbackWindowMinutes?: number;
36
36
  landRateToFeeFunc?: (landRate: number) => number;
37
+ throwOnTimeoutError?: boolean;
37
38
  });
38
39
  sleep(reference: ResolveReference): Promise<void>;
39
40
  prepareTx(tx: Transaction, additionalSigners: Array<Signer>, opts: ConfirmOptions, preSigned?: boolean): Promise<Transaction>;
@@ -30,7 +30,7 @@ class WhileValidTxSender extends baseTxSender_1.BaseTxSender {
30
30
  }
31
31
  });
32
32
  }
33
- constructor({ connection, wallet, opts = { ...config_1.DEFAULT_CONFIRMATION_OPTS, maxRetries: 0 }, retrySleep = DEFAULT_RETRY, additionalConnections = new Array(), confirmationStrategy = types_1.ConfirmationStrategy.Combo, additionalTxSenderCallbacks = [], txHandler, trackTxLandRate, txLandRateLookbackWindowMinutes, landRateToFeeFunc, }) {
33
+ constructor({ connection, wallet, opts = { ...config_1.DEFAULT_CONFIRMATION_OPTS, maxRetries: 0 }, retrySleep = DEFAULT_RETRY, additionalConnections = new Array(), confirmationStrategy = types_1.ConfirmationStrategy.Combo, additionalTxSenderCallbacks = [], txHandler, trackTxLandRate, txLandRateLookbackWindowMinutes, landRateToFeeFunc, throwOnTimeoutError = true, }) {
34
34
  super({
35
35
  connection,
36
36
  wallet,
@@ -42,6 +42,7 @@ class WhileValidTxSender extends baseTxSender_1.BaseTxSender {
42
42
  txLandRateLookbackWindowMinutes,
43
43
  confirmationStrategy,
44
44
  landRateToFeeFunc,
45
+ throwOnTimeoutError,
45
46
  });
46
47
  this.timoutCount = 0;
47
48
  this.untilValid = new Map();
@@ -24,12 +24,14 @@ export * from './accounts/oneShotUserAccountSubscriber';
24
24
  export * from './accounts/types';
25
25
  export * from './addresses/pda';
26
26
  export * from './adminClient';
27
+ export * from './assert/assert';
27
28
  export * from './testClient';
28
29
  export * from './user';
29
30
  export * from './userConfig';
30
31
  export * from './userStats';
31
32
  export * from './userName';
32
33
  export * from './userStatsConfig';
34
+ export * from './decode/user';
33
35
  export * from './driftClient';
34
36
  export * from './factory/oracleClient';
35
37
  export * from './factory/bigNum';
@@ -58,6 +60,7 @@ export * from './math/insurance';
58
60
  export * from './math/superStake';
59
61
  export * from './math/spotPosition';
60
62
  export * from './math/state';
63
+ export * from './math/tiers';
61
64
  export * from './marinade';
62
65
  export * from './orderParams';
63
66
  export * from './slot/SlotSubscriber';
@@ -75,6 +78,9 @@ export * from './priorityFee';
75
78
  export * from './phoenix/phoenixFulfillmentConfigMap';
76
79
  export * from './openbook/openbookV2Subscriber';
77
80
  export * from './openbook/openbookV2FulfillmentConfigMap';
81
+ export * from './oracles/pythClient';
82
+ export * from './oracles/pythPullClient';
83
+ export * from './oracles/switchboardOnDemandClient';
78
84
  export * from './tx/fastSingleTxSender';
79
85
  export * from './tx/retryTxSender';
80
86
  export * from './tx/whileValidTxSender';
@@ -85,6 +91,7 @@ export * from './tx/txHandler';
85
91
  export * from './util/computeUnits';
86
92
  export * from './util/tps';
87
93
  export * from './util/promiseTimeout';
94
+ export * from './util/pythPullOracleUtils';
88
95
  export * from './math/spotBalance';
89
96
  export * from './constants/spotMarkets';
90
97
  export * from './driftClientConfig';
package/lib/node/index.js CHANGED
@@ -47,12 +47,14 @@ __exportStar(require("./accounts/oneShotUserAccountSubscriber"), exports);
47
47
  __exportStar(require("./accounts/types"), exports);
48
48
  __exportStar(require("./addresses/pda"), exports);
49
49
  __exportStar(require("./adminClient"), exports);
50
+ __exportStar(require("./assert/assert"), exports);
50
51
  __exportStar(require("./testClient"), exports);
51
52
  __exportStar(require("./user"), exports);
52
53
  __exportStar(require("./userConfig"), exports);
53
54
  __exportStar(require("./userStats"), exports);
54
55
  __exportStar(require("./userName"), exports);
55
56
  __exportStar(require("./userStatsConfig"), exports);
57
+ __exportStar(require("./decode/user"), exports);
56
58
  __exportStar(require("./driftClient"), exports);
57
59
  __exportStar(require("./factory/oracleClient"), exports);
58
60
  __exportStar(require("./factory/bigNum"), exports);
@@ -81,6 +83,7 @@ __exportStar(require("./math/insurance"), exports);
81
83
  __exportStar(require("./math/superStake"), exports);
82
84
  __exportStar(require("./math/spotPosition"), exports);
83
85
  __exportStar(require("./math/state"), exports);
86
+ __exportStar(require("./math/tiers"), exports);
84
87
  __exportStar(require("./marinade"), exports);
85
88
  __exportStar(require("./orderParams"), exports);
86
89
  __exportStar(require("./slot/SlotSubscriber"), exports);
@@ -98,6 +101,9 @@ __exportStar(require("./priorityFee"), exports);
98
101
  __exportStar(require("./phoenix/phoenixFulfillmentConfigMap"), exports);
99
102
  __exportStar(require("./openbook/openbookV2Subscriber"), exports);
100
103
  __exportStar(require("./openbook/openbookV2FulfillmentConfigMap"), exports);
104
+ __exportStar(require("./oracles/pythClient"), exports);
105
+ __exportStar(require("./oracles/pythPullClient"), exports);
106
+ __exportStar(require("./oracles/switchboardOnDemandClient"), exports);
101
107
  __exportStar(require("./tx/fastSingleTxSender"), exports);
102
108
  __exportStar(require("./tx/retryTxSender"), exports);
103
109
  __exportStar(require("./tx/whileValidTxSender"), exports);
@@ -108,6 +114,7 @@ __exportStar(require("./tx/txHandler"), exports);
108
114
  __exportStar(require("./util/computeUnits"), exports);
109
115
  __exportStar(require("./util/tps"), exports);
110
116
  __exportStar(require("./util/promiseTimeout"), exports);
117
+ __exportStar(require("./util/pythPullOracleUtils"), exports);
111
118
  __exportStar(require("./math/spotBalance"), exports);
112
119
  __exportStar(require("./constants/spotMarkets"), exports);
113
120
  __exportStar(require("./driftClientConfig"), exports);
@@ -12,4 +12,3 @@ export declare class PythClient implements OracleClient {
12
12
  getOraclePriceData(pricePublicKey: PublicKey): Promise<OraclePriceData>;
13
13
  getOraclePriceDataFromBuffer(buffer: Buffer): OraclePriceData;
14
14
  }
15
- export declare function convertPythPrice(price: number, exponent: number, multiple: BN): BN;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.convertPythPrice = exports.PythClient = void 0;
3
+ exports.PythClient = void 0;
4
4
  const client_1 = require("@pythnetwork/client");
5
5
  const anchor_1 = require("@coral-xyz/anchor");
6
6
  const numericConstants_1 = require("../constants/numericConstants");
@@ -40,7 +40,6 @@ function convertPythPrice(price, exponent, multiple) {
40
40
  .mul(numericConstants_1.PRICE_PRECISION)
41
41
  .div(pythPrecision);
42
42
  }
43
- exports.convertPythPrice = convertPythPrice;
44
43
  const fiveBPS = new anchor_1.BN(500);
45
44
  function getStableCoinPrice(price, confidence) {
46
45
  if (price.sub(numericConstants_1.QUOTE_PRECISION).abs().lt(anchor_1.BN.min(confidence, fiveBPS))) {
@@ -16,12 +16,13 @@ export declare abstract class BaseTxSender implements TxSender {
16
16
  additionalTxSenderCallbacks: ((base58EncodedTx: string) => void)[];
17
17
  txHandler: TxHandler;
18
18
  trackTxLandRate?: boolean;
19
+ throwOnTimeoutError: boolean;
19
20
  lookbackWindowMinutes: number;
20
21
  txSigCache?: NodeCache;
21
22
  txLandRate: number;
22
23
  lastPriorityFeeSuggestion: number;
23
24
  landRateToFeeFunc: (landRate: number) => number;
24
- constructor({ connection, wallet, opts, timeout, additionalConnections, confirmationStrategy, additionalTxSenderCallbacks, trackTxLandRate, txHandler, txLandRateLookbackWindowMinutes, landRateToFeeFunc, }: {
25
+ constructor({ connection, wallet, opts, timeout, additionalConnections, confirmationStrategy, additionalTxSenderCallbacks, trackTxLandRate, txHandler, txLandRateLookbackWindowMinutes, landRateToFeeFunc, throwOnTimeoutError, }: {
25
26
  connection: Connection;
26
27
  wallet: IWallet;
27
28
  opts?: ConfirmOptions;
@@ -33,6 +34,7 @@ export declare abstract class BaseTxSender implements TxSender {
33
34
  trackTxLandRate?: boolean;
34
35
  txLandRateLookbackWindowMinutes?: number;
35
36
  landRateToFeeFunc?: (landRate: number) => number;
37
+ throwOnTimeoutError?: boolean;
36
38
  });
37
39
  send(tx: Transaction, additionalSigners?: Array<Signer>, opts?: ConfirmOptions, preSigned?: boolean): Promise<TxSigAndSlot>;
38
40
  prepareTx(tx: Transaction, additionalSigners: Array<Signer>, opts: ConfirmOptions, preSigned?: boolean): Promise<Transaction>;
@@ -16,7 +16,7 @@ const BASELINE_TX_LAND_RATE = 0.9;
16
16
  const DEFAULT_TIMEOUT = 35000;
17
17
  const DEFAULT_TX_LAND_RATE_LOOKBACK_WINDOW_MINUTES = 10;
18
18
  class BaseTxSender {
19
- constructor({ connection, wallet, opts = config_1.DEFAULT_CONFIRMATION_OPTS, timeout = DEFAULT_TIMEOUT, additionalConnections = new Array(), confirmationStrategy = types_1.ConfirmationStrategy.Combo, additionalTxSenderCallbacks, trackTxLandRate, txHandler, txLandRateLookbackWindowMinutes = DEFAULT_TX_LAND_RATE_LOOKBACK_WINDOW_MINUTES, landRateToFeeFunc, }) {
19
+ constructor({ connection, wallet, opts = config_1.DEFAULT_CONFIRMATION_OPTS, timeout = DEFAULT_TIMEOUT, additionalConnections = new Array(), confirmationStrategy = types_1.ConfirmationStrategy.Combo, additionalTxSenderCallbacks, trackTxLandRate, txHandler, txLandRateLookbackWindowMinutes = DEFAULT_TX_LAND_RATE_LOOKBACK_WINDOW_MINUTES, landRateToFeeFunc, throwOnTimeoutError = true, }) {
20
20
  this.timeoutCount = 0;
21
21
  this.txLandRate = 0;
22
22
  this.lastPriorityFeeSuggestion = 1;
@@ -43,6 +43,7 @@ class BaseTxSender {
43
43
  }
44
44
  this.landRateToFeeFunc =
45
45
  landRateToFeeFunc !== null && landRateToFeeFunc !== void 0 ? landRateToFeeFunc : this.defaultLandRateToFeeFunc.bind(this);
46
+ this.throwOnTimeoutError = throwOnTimeoutError;
46
47
  }
47
48
  async send(tx, additionalSigners, opts, preSigned) {
48
49
  if (additionalSigners === undefined) {
@@ -166,7 +167,9 @@ class BaseTxSender {
166
167
  }
167
168
  this.timeoutCount += 1;
168
169
  const duration = (Date.now() - start) / 1000;
169
- throw new types_1.TxSendError(`Transaction was not confirmed in ${duration.toFixed(2)} seconds. It is unknown if it succeeded or failed. Check signature ${signature} using the Solana Explorer or CLI tools.`, txConstants_1.NOT_CONFIRMED_ERROR_CODE);
170
+ if (this.throwOnTimeoutError) {
171
+ throw new types_1.TxSendError(`Transaction was not confirmed in ${duration.toFixed(2)} seconds. It is unknown if it succeeded or failed. Check signature ${signature} using the Solana Explorer or CLI tools.`, txConstants_1.NOT_CONFIRMED_ERROR_CODE);
172
+ }
170
173
  }
171
174
  return response;
172
175
  }
@@ -192,7 +195,9 @@ class BaseTxSender {
192
195
  // Transaction not confirmed within 30 seconds
193
196
  this.timeoutCount += 1;
194
197
  const duration = (Date.now() - start) / 1000;
195
- throw new types_1.TxSendError(`Transaction was not confirmed in ${duration.toFixed(2)} seconds. It is unknown if it succeeded or failed. Check signature ${signature} using the Solana Explorer or CLI tools.`, txConstants_1.NOT_CONFIRMED_ERROR_CODE);
198
+ if (this.throwOnTimeoutError) {
199
+ throw new types_1.TxSendError(`Transaction was not confirmed in ${duration.toFixed(2)} seconds. It is unknown if it succeeded or failed. Check signature ${signature} using the Solana Explorer or CLI tools.`, txConstants_1.NOT_CONFIRMED_ERROR_CODE);
200
+ }
196
201
  }
197
202
  async confirmTransaction(signature, commitment) {
198
203
  if (this.confirmationStrategy === types_1.ConfirmationStrategy.WebSocket ||
@@ -19,7 +19,7 @@ export declare class FastSingleTxSender extends BaseTxSender {
19
19
  confirmInBackground: boolean;
20
20
  blockhashCommitment: Commitment;
21
21
  blockhashIntervalId: NodeJS.Timer;
22
- constructor({ connection, wallet, opts, timeout, blockhashRefreshInterval, additionalConnections, skipConfirmation, confirmInBackground, blockhashCommitment, confirmationStrategy, trackTxLandRate, txHandler, txLandRateLookbackWindowMinutes, landRateToFeeFunc, }: {
22
+ constructor({ connection, wallet, opts, timeout, blockhashRefreshInterval, additionalConnections, skipConfirmation, confirmInBackground, blockhashCommitment, confirmationStrategy, trackTxLandRate, txHandler, txLandRateLookbackWindowMinutes, landRateToFeeFunc, throwOnTimeoutError, }: {
23
23
  connection: Connection;
24
24
  wallet: IWallet;
25
25
  opts?: ConfirmOptions;
@@ -34,6 +34,7 @@ export declare class FastSingleTxSender extends BaseTxSender {
34
34
  txHandler?: TxHandler;
35
35
  txLandRateLookbackWindowMinutes?: number;
36
36
  landRateToFeeFunc?: (landRate: number) => number;
37
+ throwOnTimeoutError?: boolean;
37
38
  });
38
39
  startBlockhashRefreshLoop(): void;
39
40
  sendRawTransaction(rawTransaction: Buffer | Uint8Array, opts: ConfirmOptions): Promise<TxSigAndSlot>;
@@ -7,7 +7,7 @@ const config_1 = require("../config");
7
7
  const DEFAULT_TIMEOUT = 35000;
8
8
  const DEFAULT_BLOCKHASH_REFRESH = 10000;
9
9
  class FastSingleTxSender extends baseTxSender_1.BaseTxSender {
10
- constructor({ connection, wallet, opts = { ...config_1.DEFAULT_CONFIRMATION_OPTS, maxRetries: 0 }, timeout = DEFAULT_TIMEOUT, blockhashRefreshInterval = DEFAULT_BLOCKHASH_REFRESH, additionalConnections = new Array(), skipConfirmation = false, confirmInBackground = false, blockhashCommitment = 'finalized', confirmationStrategy = types_1.ConfirmationStrategy.Combo, trackTxLandRate, txHandler, txLandRateLookbackWindowMinutes, landRateToFeeFunc, }) {
10
+ constructor({ connection, wallet, opts = { ...config_1.DEFAULT_CONFIRMATION_OPTS, maxRetries: 0 }, timeout = DEFAULT_TIMEOUT, blockhashRefreshInterval = DEFAULT_BLOCKHASH_REFRESH, additionalConnections = new Array(), skipConfirmation = false, confirmInBackground = false, blockhashCommitment = 'finalized', confirmationStrategy = types_1.ConfirmationStrategy.Combo, trackTxLandRate, txHandler, txLandRateLookbackWindowMinutes, landRateToFeeFunc, throwOnTimeoutError = true, }) {
11
11
  super({
12
12
  connection,
13
13
  wallet,
@@ -19,6 +19,7 @@ class FastSingleTxSender extends baseTxSender_1.BaseTxSender {
19
19
  trackTxLandRate,
20
20
  txLandRateLookbackWindowMinutes,
21
21
  landRateToFeeFunc,
22
+ throwOnTimeoutError,
22
23
  });
23
24
  this.timoutCount = 0;
24
25
  this.connection = connection;
@@ -16,7 +16,7 @@ export declare class ForwardOnlyTxSender extends BaseTxSender {
16
16
  retrySleep: number;
17
17
  additionalConnections: Connection[];
18
18
  timoutCount: number;
19
- constructor({ connection, wallet, opts, timeout, retrySleep, confirmationStrategy, additionalTxSenderCallbacks, txHandler, trackTxLandRate, txLandRateLookbackWindowMinutes, landRateToFeeFunc, }: {
19
+ constructor({ connection, wallet, opts, timeout, retrySleep, confirmationStrategy, additionalTxSenderCallbacks, txHandler, trackTxLandRate, txLandRateLookbackWindowMinutes, landRateToFeeFunc, throwOnTimeoutError, }: {
20
20
  connection: Connection;
21
21
  wallet: IWallet;
22
22
  opts?: ConfirmOptions;
@@ -28,6 +28,7 @@ export declare class ForwardOnlyTxSender extends BaseTxSender {
28
28
  trackTxLandRate?: boolean;
29
29
  txLandRateLookbackWindowMinutes?: number;
30
30
  landRateToFeeFunc?: (landRate: number) => number;
31
+ throwOnTimeoutError?: boolean;
31
32
  });
32
33
  sleep(reference: ResolveReference): Promise<void>;
33
34
  sendToAdditionalConnections(rawTx: Buffer | Uint8Array, _opts: ConfirmOptions): void;
@@ -12,7 +12,7 @@ const config_1 = require("../config");
12
12
  const DEFAULT_TIMEOUT = 35000;
13
13
  const DEFAULT_RETRY = 5000;
14
14
  class ForwardOnlyTxSender extends baseTxSender_1.BaseTxSender {
15
- constructor({ connection, wallet, opts = { ...config_1.DEFAULT_CONFIRMATION_OPTS, maxRetries: 0 }, timeout = DEFAULT_TIMEOUT, retrySleep = DEFAULT_RETRY, confirmationStrategy = types_1.ConfirmationStrategy.Combo, additionalTxSenderCallbacks = [], txHandler, trackTxLandRate, txLandRateLookbackWindowMinutes, landRateToFeeFunc, }) {
15
+ constructor({ connection, wallet, opts = { ...config_1.DEFAULT_CONFIRMATION_OPTS, maxRetries: 0 }, timeout = DEFAULT_TIMEOUT, retrySleep = DEFAULT_RETRY, confirmationStrategy = types_1.ConfirmationStrategy.Combo, additionalTxSenderCallbacks = [], txHandler, trackTxLandRate, txLandRateLookbackWindowMinutes, landRateToFeeFunc, throwOnTimeoutError = true, }) {
16
16
  super({
17
17
  connection,
18
18
  wallet,
@@ -25,6 +25,7 @@ class ForwardOnlyTxSender extends baseTxSender_1.BaseTxSender {
25
25
  trackTxLandRate,
26
26
  txLandRateLookbackWindowMinutes,
27
27
  landRateToFeeFunc,
28
+ throwOnTimeoutError,
28
29
  });
29
30
  this.timoutCount = 0;
30
31
  this.connection = connection;
@@ -16,7 +16,7 @@ export declare class RetryTxSender extends BaseTxSender {
16
16
  retrySleep: number;
17
17
  additionalConnections: Connection[];
18
18
  timoutCount: number;
19
- constructor({ connection, wallet, opts, timeout, retrySleep, additionalConnections, confirmationStrategy, additionalTxSenderCallbacks, txHandler, trackTxLandRate, txLandRateLookbackWindowMinutes, landRateToFeeFunc, }: {
19
+ constructor({ connection, wallet, opts, timeout, retrySleep, additionalConnections, confirmationStrategy, additionalTxSenderCallbacks, txHandler, trackTxLandRate, txLandRateLookbackWindowMinutes, landRateToFeeFunc, throwOnTimeoutError, }: {
20
20
  connection: Connection;
21
21
  wallet: IWallet;
22
22
  opts?: ConfirmOptions;
@@ -29,6 +29,7 @@ export declare class RetryTxSender extends BaseTxSender {
29
29
  trackTxLandRate?: boolean;
30
30
  txLandRateLookbackWindowMinutes?: number;
31
31
  landRateToFeeFunc?: (landRate: number) => number;
32
+ throwOnTimeoutError?: boolean;
32
33
  });
33
34
  sleep(reference: ResolveReference): Promise<void>;
34
35
  sendRawTransaction(rawTransaction: Buffer | Uint8Array, opts: ConfirmOptions): Promise<TxSigAndSlot>;
@@ -7,7 +7,7 @@ const config_1 = require("../config");
7
7
  const DEFAULT_TIMEOUT = 35000;
8
8
  const DEFAULT_RETRY = 2000;
9
9
  class RetryTxSender extends baseTxSender_1.BaseTxSender {
10
- constructor({ connection, wallet, opts = { ...config_1.DEFAULT_CONFIRMATION_OPTS, maxRetries: 0 }, timeout = DEFAULT_TIMEOUT, retrySleep = DEFAULT_RETRY, additionalConnections = new Array(), confirmationStrategy = types_1.ConfirmationStrategy.Combo, additionalTxSenderCallbacks = [], txHandler, trackTxLandRate, txLandRateLookbackWindowMinutes, landRateToFeeFunc, }) {
10
+ constructor({ connection, wallet, opts = { ...config_1.DEFAULT_CONFIRMATION_OPTS, maxRetries: 0 }, timeout = DEFAULT_TIMEOUT, retrySleep = DEFAULT_RETRY, additionalConnections = new Array(), confirmationStrategy = types_1.ConfirmationStrategy.Combo, additionalTxSenderCallbacks = [], txHandler, trackTxLandRate, txLandRateLookbackWindowMinutes, landRateToFeeFunc, throwOnTimeoutError = true, }) {
11
11
  super({
12
12
  connection,
13
13
  wallet,
@@ -20,6 +20,7 @@ class RetryTxSender extends baseTxSender_1.BaseTxSender {
20
20
  trackTxLandRate,
21
21
  txLandRateLookbackWindowMinutes,
22
22
  landRateToFeeFunc,
23
+ throwOnTimeoutError,
23
24
  });
24
25
  this.timoutCount = 0;
25
26
  this.connection = connection;
@@ -22,7 +22,7 @@ export declare class WhileValidTxSender extends BaseTxSender {
22
22
  }>;
23
23
  useBlockHeightOffset: boolean;
24
24
  private checkAndSetUseBlockHeightOffset;
25
- constructor({ connection, wallet, opts, retrySleep, additionalConnections, confirmationStrategy, additionalTxSenderCallbacks, txHandler, trackTxLandRate, txLandRateLookbackWindowMinutes, landRateToFeeFunc, }: {
25
+ constructor({ connection, wallet, opts, retrySleep, additionalConnections, confirmationStrategy, additionalTxSenderCallbacks, txHandler, trackTxLandRate, txLandRateLookbackWindowMinutes, landRateToFeeFunc, throwOnTimeoutError, }: {
26
26
  connection: Connection;
27
27
  wallet: IWallet;
28
28
  opts?: ConfirmOptions;
@@ -34,6 +34,7 @@ export declare class WhileValidTxSender extends BaseTxSender {
34
34
  trackTxLandRate?: boolean;
35
35
  txLandRateLookbackWindowMinutes?: number;
36
36
  landRateToFeeFunc?: (landRate: number) => number;
37
+ throwOnTimeoutError?: boolean;
37
38
  });
38
39
  sleep(reference: ResolveReference): Promise<void>;
39
40
  prepareTx(tx: Transaction, additionalSigners: Array<Signer>, opts: ConfirmOptions, preSigned?: boolean): Promise<Transaction>;
@@ -30,7 +30,7 @@ class WhileValidTxSender extends baseTxSender_1.BaseTxSender {
30
30
  }
31
31
  });
32
32
  }
33
- constructor({ connection, wallet, opts = { ...config_1.DEFAULT_CONFIRMATION_OPTS, maxRetries: 0 }, retrySleep = DEFAULT_RETRY, additionalConnections = new Array(), confirmationStrategy = types_1.ConfirmationStrategy.Combo, additionalTxSenderCallbacks = [], txHandler, trackTxLandRate, txLandRateLookbackWindowMinutes, landRateToFeeFunc, }) {
33
+ constructor({ connection, wallet, opts = { ...config_1.DEFAULT_CONFIRMATION_OPTS, maxRetries: 0 }, retrySleep = DEFAULT_RETRY, additionalConnections = new Array(), confirmationStrategy = types_1.ConfirmationStrategy.Combo, additionalTxSenderCallbacks = [], txHandler, trackTxLandRate, txLandRateLookbackWindowMinutes, landRateToFeeFunc, throwOnTimeoutError = true, }) {
34
34
  super({
35
35
  connection,
36
36
  wallet,
@@ -42,6 +42,7 @@ class WhileValidTxSender extends baseTxSender_1.BaseTxSender {
42
42
  txLandRateLookbackWindowMinutes,
43
43
  confirmationStrategy,
44
44
  landRateToFeeFunc,
45
+ throwOnTimeoutError,
45
46
  });
46
47
  this.timoutCount = 0;
47
48
  this.untilValid = new Map();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.97.0-beta.26",
3
+ "version": "2.97.0-beta.28",
4
4
  "main": "lib/node/index.js",
5
5
  "types": "lib/node/index.d.ts",
6
6
  "browser": "./lib/browser/index.js",
package/src/index.ts CHANGED
@@ -25,12 +25,14 @@ export * from './accounts/oneShotUserAccountSubscriber';
25
25
  export * from './accounts/types';
26
26
  export * from './addresses/pda';
27
27
  export * from './adminClient';
28
+ export * from './assert/assert';
28
29
  export * from './testClient';
29
30
  export * from './user';
30
31
  export * from './userConfig';
31
32
  export * from './userStats';
32
33
  export * from './userName';
33
34
  export * from './userStatsConfig';
35
+ export * from './decode/user';
34
36
  export * from './driftClient';
35
37
  export * from './factory/oracleClient';
36
38
  export * from './factory/bigNum';
@@ -59,6 +61,7 @@ export * from './math/insurance';
59
61
  export * from './math/superStake';
60
62
  export * from './math/spotPosition';
61
63
  export * from './math/state';
64
+ export * from './math/tiers';
62
65
  export * from './marinade';
63
66
  export * from './orderParams';
64
67
  export * from './slot/SlotSubscriber';
@@ -76,6 +79,9 @@ export * from './priorityFee';
76
79
  export * from './phoenix/phoenixFulfillmentConfigMap';
77
80
  export * from './openbook/openbookV2Subscriber';
78
81
  export * from './openbook/openbookV2FulfillmentConfigMap';
82
+ export * from './oracles/pythClient';
83
+ export * from './oracles/pythPullClient';
84
+ export * from './oracles/switchboardOnDemandClient';
79
85
  export * from './tx/fastSingleTxSender';
80
86
  export * from './tx/retryTxSender';
81
87
  export * from './tx/whileValidTxSender';
@@ -86,6 +92,7 @@ export * from './tx/txHandler';
86
92
  export * from './util/computeUnits';
87
93
  export * from './util/tps';
88
94
  export * from './util/promiseTimeout';
95
+ export * from './util/pythPullOracleUtils';
89
96
  export * from './math/spotBalance';
90
97
  export * from './constants/spotMarkets';
91
98
  export * from './driftClientConfig';
@@ -67,11 +67,7 @@ export class PythClient implements OracleClient {
67
67
  }
68
68
  }
69
69
 
70
- export function convertPythPrice(
71
- price: number,
72
- exponent: number,
73
- multiple: BN
74
- ): BN {
70
+ function convertPythPrice(price: number, exponent: number, multiple: BN): BN {
75
71
  exponent = Math.abs(exponent);
76
72
  const pythPrecision = TEN.pow(new BN(exponent).abs()).div(multiple);
77
73
  return new BN(price * Math.pow(10, exponent))
@@ -43,6 +43,7 @@ export abstract class BaseTxSender implements TxSender {
43
43
  additionalTxSenderCallbacks: ((base58EncodedTx: string) => void)[];
44
44
  txHandler: TxHandler;
45
45
  trackTxLandRate?: boolean;
46
+ throwOnTimeoutError: boolean;
46
47
 
47
48
  // For landing rate calcs
48
49
  lookbackWindowMinutes: number;
@@ -63,6 +64,7 @@ export abstract class BaseTxSender implements TxSender {
63
64
  txHandler,
64
65
  txLandRateLookbackWindowMinutes = DEFAULT_TX_LAND_RATE_LOOKBACK_WINDOW_MINUTES,
65
66
  landRateToFeeFunc,
67
+ throwOnTimeoutError = true,
66
68
  }: {
67
69
  connection: Connection;
68
70
  wallet: IWallet;
@@ -75,6 +77,7 @@ export abstract class BaseTxSender implements TxSender {
75
77
  trackTxLandRate?: boolean;
76
78
  txLandRateLookbackWindowMinutes?: number;
77
79
  landRateToFeeFunc?: (landRate: number) => number;
80
+ throwOnTimeoutError?: boolean;
78
81
  }) {
79
82
  this.connection = connection;
80
83
  this.wallet = wallet;
@@ -100,6 +103,7 @@ export abstract class BaseTxSender implements TxSender {
100
103
  }
101
104
  this.landRateToFeeFunc =
102
105
  landRateToFeeFunc ?? this.defaultLandRateToFeeFunc.bind(this);
106
+ this.throwOnTimeoutError = throwOnTimeoutError;
103
107
  }
104
108
 
105
109
  async send(
@@ -283,12 +287,14 @@ export abstract class BaseTxSender implements TxSender {
283
287
  }
284
288
  this.timeoutCount += 1;
285
289
  const duration = (Date.now() - start) / 1000;
286
- throw new TxSendError(
287
- `Transaction was not confirmed in ${duration.toFixed(
288
- 2
289
- )} seconds. It is unknown if it succeeded or failed. Check signature ${signature} using the Solana Explorer or CLI tools.`,
290
- NOT_CONFIRMED_ERROR_CODE
291
- );
290
+ if (this.throwOnTimeoutError) {
291
+ throw new TxSendError(
292
+ `Transaction was not confirmed in ${duration.toFixed(
293
+ 2
294
+ )} seconds. It is unknown if it succeeded or failed. Check signature ${signature} using the Solana Explorer or CLI tools.`,
295
+ NOT_CONFIRMED_ERROR_CODE
296
+ );
297
+ }
292
298
  }
293
299
 
294
300
  return response;
@@ -326,12 +332,14 @@ export abstract class BaseTxSender implements TxSender {
326
332
  // Transaction not confirmed within 30 seconds
327
333
  this.timeoutCount += 1;
328
334
  const duration = (Date.now() - start) / 1000;
329
- throw new TxSendError(
330
- `Transaction was not confirmed in ${duration.toFixed(
331
- 2
332
- )} seconds. It is unknown if it succeeded or failed. Check signature ${signature} using the Solana Explorer or CLI tools.`,
333
- NOT_CONFIRMED_ERROR_CODE
334
- );
335
+ if (this.throwOnTimeoutError) {
336
+ throw new TxSendError(
337
+ `Transaction was not confirmed in ${duration.toFixed(
338
+ 2
339
+ )} seconds. It is unknown if it succeeded or failed. Check signature ${signature} using the Solana Explorer or CLI tools.`,
340
+ NOT_CONFIRMED_ERROR_CODE
341
+ );
342
+ }
335
343
  }
336
344
 
337
345
  async confirmTransaction(
@@ -43,6 +43,7 @@ export class FastSingleTxSender extends BaseTxSender {
43
43
  txHandler,
44
44
  txLandRateLookbackWindowMinutes,
45
45
  landRateToFeeFunc,
46
+ throwOnTimeoutError = true,
46
47
  }: {
47
48
  connection: Connection;
48
49
  wallet: IWallet;
@@ -58,6 +59,7 @@ export class FastSingleTxSender extends BaseTxSender {
58
59
  txHandler?: TxHandler;
59
60
  txLandRateLookbackWindowMinutes?: number;
60
61
  landRateToFeeFunc?: (landRate: number) => number;
62
+ throwOnTimeoutError?: boolean;
61
63
  }) {
62
64
  super({
63
65
  connection,
@@ -70,6 +72,7 @@ export class FastSingleTxSender extends BaseTxSender {
70
72
  trackTxLandRate,
71
73
  txLandRateLookbackWindowMinutes,
72
74
  landRateToFeeFunc,
75
+ throwOnTimeoutError,
73
76
  });
74
77
  this.connection = connection;
75
78
  this.wallet = wallet;
@@ -38,6 +38,7 @@ export class ForwardOnlyTxSender extends BaseTxSender {
38
38
  trackTxLandRate,
39
39
  txLandRateLookbackWindowMinutes,
40
40
  landRateToFeeFunc,
41
+ throwOnTimeoutError = true,
41
42
  }: {
42
43
  connection: Connection;
43
44
  wallet: IWallet;
@@ -50,6 +51,7 @@ export class ForwardOnlyTxSender extends BaseTxSender {
50
51
  trackTxLandRate?: boolean;
51
52
  txLandRateLookbackWindowMinutes?: number;
52
53
  landRateToFeeFunc?: (landRate: number) => number;
54
+ throwOnTimeoutError?: boolean;
53
55
  }) {
54
56
  super({
55
57
  connection,
@@ -63,6 +65,7 @@ export class ForwardOnlyTxSender extends BaseTxSender {
63
65
  trackTxLandRate,
64
66
  txLandRateLookbackWindowMinutes,
65
67
  landRateToFeeFunc,
68
+ throwOnTimeoutError,
66
69
  });
67
70
  this.connection = connection;
68
71
  this.wallet = wallet;
@@ -34,6 +34,7 @@ export class RetryTxSender extends BaseTxSender {
34
34
  trackTxLandRate,
35
35
  txLandRateLookbackWindowMinutes,
36
36
  landRateToFeeFunc,
37
+ throwOnTimeoutError = true,
37
38
  }: {
38
39
  connection: Connection;
39
40
  wallet: IWallet;
@@ -47,6 +48,7 @@ export class RetryTxSender extends BaseTxSender {
47
48
  trackTxLandRate?: boolean;
48
49
  txLandRateLookbackWindowMinutes?: number;
49
50
  landRateToFeeFunc?: (landRate: number) => number;
51
+ throwOnTimeoutError?: boolean;
50
52
  }) {
51
53
  super({
52
54
  connection,
@@ -60,6 +62,7 @@ export class RetryTxSender extends BaseTxSender {
60
62
  trackTxLandRate,
61
63
  txLandRateLookbackWindowMinutes,
62
64
  landRateToFeeFunc,
65
+ throwOnTimeoutError,
63
66
  });
64
67
  this.connection = connection;
65
68
  this.wallet = wallet;
@@ -68,6 +68,7 @@ export class WhileValidTxSender extends BaseTxSender {
68
68
  trackTxLandRate,
69
69
  txLandRateLookbackWindowMinutes,
70
70
  landRateToFeeFunc,
71
+ throwOnTimeoutError = true,
71
72
  }: {
72
73
  connection: Connection;
73
74
  wallet: IWallet;
@@ -80,6 +81,7 @@ export class WhileValidTxSender extends BaseTxSender {
80
81
  trackTxLandRate?: boolean;
81
82
  txLandRateLookbackWindowMinutes?: number;
82
83
  landRateToFeeFunc?: (landRate: number) => number;
84
+ throwOnTimeoutError?: boolean;
83
85
  }) {
84
86
  super({
85
87
  connection,
@@ -92,6 +94,7 @@ export class WhileValidTxSender extends BaseTxSender {
92
94
  txLandRateLookbackWindowMinutes,
93
95
  confirmationStrategy,
94
96
  landRateToFeeFunc,
97
+ throwOnTimeoutError,
95
98
  });
96
99
  this.retrySleep = retrySleep;
97
100