@drift-labs/sdk 2.96.0-beta.13 → 2.96.0-beta.15

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 (51) hide show
  1. package/VERSION +1 -1
  2. package/bun.lockb +0 -0
  3. package/lib/accounts/pollingDriftClientAccountSubscriber.d.ts +5 -3
  4. package/lib/accounts/pollingDriftClientAccountSubscriber.js +24 -1
  5. package/lib/accounts/types.d.ts +5 -0
  6. package/lib/accounts/types.js +7 -1
  7. package/lib/accounts/utils.d.ts +7 -0
  8. package/lib/accounts/utils.js +33 -1
  9. package/lib/accounts/webSocketDriftClientAccountSubscriber.d.ts +5 -4
  10. package/lib/accounts/webSocketDriftClientAccountSubscriber.js +24 -1
  11. package/lib/config.d.ts +2 -0
  12. package/lib/config.js +5 -1
  13. package/lib/constants/spotMarkets.js +10 -0
  14. package/lib/driftClient.d.ts +6 -7
  15. package/lib/driftClient.js +16 -15
  16. package/lib/driftClientConfig.d.ts +2 -0
  17. package/lib/index.d.ts +1 -0
  18. package/lib/index.js +1 -0
  19. package/lib/tokenFaucet.js +2 -1
  20. package/lib/tx/baseTxSender.js +2 -2
  21. package/lib/tx/fastSingleTxSender.js +2 -2
  22. package/lib/tx/forwardOnlyTxSender.js +2 -2
  23. package/lib/tx/retryTxSender.js +2 -2
  24. package/lib/tx/txHandler.js +10 -7
  25. package/lib/tx/whileValidTxSender.d.ts +2 -4
  26. package/lib/tx/whileValidTxSender.js +16 -17
  27. package/lib/types.d.ts +4 -0
  28. package/lib/types.js +6 -1
  29. package/lib/util/TransactionConfirmationManager.d.ts +14 -0
  30. package/lib/util/TransactionConfirmationManager.js +96 -0
  31. package/package.json +2 -1
  32. package/src/accounts/pollingDriftClientAccountSubscriber.ts +41 -5
  33. package/src/accounts/types.ts +6 -0
  34. package/src/accounts/utils.ts +42 -0
  35. package/src/accounts/webSocketDriftClientAccountSubscriber.ts +40 -5
  36. package/src/config.ts +6 -0
  37. package/src/constants/spotMarkets.ts +11 -0
  38. package/src/driftClient.ts +62 -46
  39. package/src/driftClientConfig.ts +2 -0
  40. package/src/index.ts +1 -0
  41. package/src/tokenFaucet.ts +2 -2
  42. package/src/tx/baseTxSender.ts +2 -2
  43. package/src/tx/fastSingleTxSender.ts +2 -2
  44. package/src/tx/forwardOnlyTxSender.ts +2 -2
  45. package/src/tx/retryTxSender.ts +2 -2
  46. package/src/tx/txHandler.ts +8 -1
  47. package/src/tx/whileValidTxSender.ts +23 -26
  48. package/src/types.ts +5 -0
  49. package/src/util/TransactionConfirmationManager.ts +155 -0
  50. package/tests/ci/verifyConstants.ts +13 -0
  51. package/tests/tx/TransactionConfirmationManager.test.ts +286 -0
@@ -1,3 +1,4 @@
1
+ import * as anchor from '@coral-xyz/anchor';
1
2
  import {
2
3
  AnchorProvider,
3
4
  BN,
@@ -13,64 +14,65 @@ import {
13
14
  createCloseAccountInstruction,
14
15
  createInitializeAccountInstruction,
15
16
  getAssociatedTokenAddress,
16
- TOKEN_PROGRAM_ID,
17
17
  TOKEN_2022_PROGRAM_ID,
18
+ TOKEN_PROGRAM_ID,
18
19
  } from '@solana/spl-token';
19
20
  import {
20
- StateAccount,
21
+ DriftClientMetricsEvents,
22
+ isVariant,
21
23
  IWallet,
22
- PositionDirection,
23
- UserAccount,
24
- PerpMarketAccount,
25
- OrderParams,
26
- Order,
27
- SpotMarketAccount,
28
- SpotPosition,
29
24
  MakerInfo,
30
- TakerInfo,
31
- OptionalOrderParams,
32
- OrderType,
33
- ReferrerInfo,
25
+ MappedRecord,
34
26
  MarketType,
35
- TxParams,
36
- SerumV3FulfillmentConfigAccount,
37
- isVariant,
38
- ReferrerNameAccount,
27
+ ModifyOrderParams,
28
+ ModifyOrderPolicy,
29
+ OpenbookV2FulfillmentConfigAccount,
30
+ OptionalOrderParams,
31
+ Order,
32
+ OrderParams,
39
33
  OrderTriggerCondition,
40
- SpotBalanceType,
34
+ OrderType,
35
+ PerpMarketAccount,
41
36
  PerpMarketExtendedInfo,
42
- UserStatsAccount,
43
- ModifyOrderParams,
44
37
  PhoenixV1FulfillmentConfigAccount,
45
- ModifyOrderPolicy,
46
- SwapReduceOnly,
38
+ PlaceAndTakeOrderSuccessCondition,
39
+ PositionDirection,
40
+ ReferrerInfo,
41
+ ReferrerNameAccount,
42
+ SerumV3FulfillmentConfigAccount,
47
43
  SettlePnlMode,
48
44
  SignedTxData,
49
- MappedRecord,
50
- OpenbookV2FulfillmentConfigAccount,
45
+ SpotBalanceType,
46
+ SpotMarketAccount,
47
+ SpotPosition,
48
+ StateAccount,
49
+ SwapReduceOnly,
51
50
  SwiftOrderParamsMessage,
51
+ TakerInfo,
52
+ TxParams,
53
+ UserAccount,
54
+ UserStatsAccount,
52
55
  } from './types';
53
- import * as anchor from '@coral-xyz/anchor';
54
56
  import driftIDL from './idl/drift.json';
55
57
 
56
58
  import {
57
- Connection,
58
- PublicKey,
59
- TransactionSignature,
60
- ConfirmOptions,
61
- Transaction,
62
- TransactionInstruction,
63
59
  AccountMeta,
60
+ AddressLookupTableAccount,
61
+ BlockhashWithExpiryBlockHeight,
62
+ ConfirmOptions,
63
+ Connection,
64
+ Ed25519Program,
64
65
  Keypair,
65
66
  LAMPORTS_PER_SOL,
67
+ PublicKey,
66
68
  Signer,
67
69
  SystemProgram,
68
- AddressLookupTableAccount,
70
+ SYSVAR_INSTRUCTIONS_PUBKEY,
71
+ Transaction,
72
+ TransactionInstruction,
73
+ TransactionSignature,
69
74
  TransactionVersion,
70
75
  VersionedTransaction,
71
- BlockhashWithExpiryBlockHeight,
72
- SYSVAR_INSTRUCTIONS_PUBKEY,
73
- Ed25519Program,
74
76
  } from '@solana/web3.js';
75
77
 
76
78
  import { TokenFaucet } from './tokenFaucet';
@@ -93,19 +95,19 @@ import {
93
95
  getUserStatsAccountPublicKey,
94
96
  } from './addresses/pda';
95
97
  import {
96
- DriftClientAccountSubscriber,
97
- DriftClientAccountEvents,
98
98
  DataAndSlot,
99
+ DelistedMarketSetting,
100
+ DriftClientAccountEvents,
101
+ DriftClientAccountSubscriber,
99
102
  } from './accounts/types';
100
- import { DriftClientMetricsEvents } from './types';
101
103
  import { TxSender, TxSigAndSlot } from './tx/types';
102
104
  import {
103
105
  BASE_PRECISION,
106
+ GOV_SPOT_MARKET_INDEX,
104
107
  PRICE_PRECISION,
108
+ QUOTE_PRECISION,
105
109
  QUOTE_SPOT_MARKET_INDEX,
106
110
  ZERO,
107
- QUOTE_PRECISION,
108
- GOV_SPOT_MARKET_INDEX,
109
111
  } from './constants/numericConstants';
110
112
  import { findDirectionToClose, positionIsAvailable } from './math/position';
111
113
  import { getSignedTokenAmount, getTokenAmount } from './math/spotBalance';
@@ -117,7 +119,12 @@ import { WebSocketDriftClientAccountSubscriber } from './accounts/webSocketDrift
117
119
  import { RetryTxSender } from './tx/retryTxSender';
118
120
  import { User } from './user';
119
121
  import { UserSubscriptionConfig } from './userConfig';
120
- import { configs, DRIFT_PROGRAM_ID } from './config';
122
+ import {
123
+ configs,
124
+ DRIFT_ORACLE_RECEIVER_ID,
125
+ DEFAULT_CONFIRMATION_OPTS,
126
+ DRIFT_PROGRAM_ID,
127
+ } from './config';
121
128
  import { WRAPPED_SOL_MINT } from './constants/spotMarkets';
122
129
  import { UserStats } from './userStats';
123
130
  import { isSpotPositionAvailable } from './math/spotPosition';
@@ -139,15 +146,14 @@ import { TransactionParamProcessor } from './tx/txParamProcessor';
139
146
  import { isOracleValid, trimVaaSignatures } from './math/oracles';
140
147
  import { TxHandler } from './tx/txHandler';
141
148
  import {
142
- wormholeCoreBridgeIdl,
143
149
  DEFAULT_RECEIVER_PROGRAM_ID,
150
+ wormholeCoreBridgeIdl,
144
151
  } from '@pythnetwork/pyth-solana-receiver';
145
152
  import { parseAccumulatorUpdateData } from '@pythnetwork/price-service-sdk';
146
153
  import {
147
154
  DEFAULT_WORMHOLE_PROGRAM_ID,
148
155
  getGuardianSetPda,
149
156
  } from '@pythnetwork/pyth-solana-receiver/lib/address';
150
- import { DRIFT_ORACLE_RECEIVER_ID } from './config';
151
157
  import { WormholeCoreBridgeSolana } from '@pythnetwork/pyth-solana-receiver/lib/idl/wormhole_core_bridge_solana';
152
158
  import { PythSolanaReceiver } from '@pythnetwork/pyth-solana-receiver/lib/idl/pyth_solana_receiver';
153
159
  import { getFeedIdUint8Array, trimFeedId } from './util/pythPullOracleUtils';
@@ -222,7 +228,7 @@ export class DriftClient {
222
228
  this.connection = config.connection;
223
229
  this.wallet = config.wallet;
224
230
  this.opts = config.opts || {
225
- ...AnchorProvider.defaultOptions(),
231
+ ...DEFAULT_CONFIRMATION_OPTS,
226
232
  commitment: config?.connection?.commitment,
227
233
  preflightCommitment: config?.connection?.commitment, // At the moment this ensures that our transaction simulations (which use Connection object) will use the same commitment level as our Transaction blockhashes (which use these opts)
228
234
  };
@@ -330,6 +336,8 @@ export class DriftClient {
330
336
  );
331
337
  }
332
338
 
339
+ const delistedMarketSetting =
340
+ config.delistedMarketSetting || DelistedMarketSetting.Subscribe;
333
341
  const noMarketsAndOraclesSpecified =
334
342
  config.perpMarketIndexes === undefined &&
335
343
  config.spotMarketIndexes === undefined &&
@@ -341,7 +349,8 @@ export class DriftClient {
341
349
  config.perpMarketIndexes ?? [],
342
350
  config.spotMarketIndexes ?? [],
343
351
  config.oracleInfos ?? [],
344
- noMarketsAndOraclesSpecified
352
+ noMarketsAndOraclesSpecified,
353
+ delistedMarketSetting
345
354
  );
346
355
  } else {
347
356
  this.accountSubscriber = new WebSocketDriftClientAccountSubscriber(
@@ -350,6 +359,7 @@ export class DriftClient {
350
359
  config.spotMarketIndexes ?? [],
351
360
  config.oracleInfos ?? [],
352
361
  noMarketsAndOraclesSpecified,
362
+ delistedMarketSetting,
353
363
  {
354
364
  resubTimeoutMs: config.accountSubscription?.resubTimeoutMs,
355
365
  logResubMessages: config.accountSubscription?.logResubMessages,
@@ -2999,6 +3009,7 @@ export class DriftClient {
2999
3009
  undefined,
3000
3010
  undefined,
3001
3011
  undefined,
3012
+ undefined,
3002
3013
  subAccountId
3003
3014
  );
3004
3015
  }
@@ -4958,6 +4969,7 @@ export class DriftClient {
4958
4969
  orderParams: OptionalOrderParams,
4959
4970
  makerInfo?: MakerInfo | MakerInfo[],
4960
4971
  referrerInfo?: ReferrerInfo,
4972
+ successCondition?: PlaceAndTakeOrderSuccessCondition,
4961
4973
  txParams?: TxParams,
4962
4974
  subAccountId?: number
4963
4975
  ): Promise<TransactionSignature> {
@@ -4967,6 +4979,7 @@ export class DriftClient {
4967
4979
  orderParams,
4968
4980
  makerInfo,
4969
4981
  referrerInfo,
4982
+ successCondition,
4970
4983
  subAccountId
4971
4984
  ),
4972
4985
  txParams
@@ -5014,6 +5027,7 @@ export class DriftClient {
5014
5027
  orderParams,
5015
5028
  makerInfo,
5016
5029
  referrerInfo,
5030
+ undefined,
5017
5031
  subAccountId
5018
5032
  );
5019
5033
 
@@ -5204,6 +5218,7 @@ export class DriftClient {
5204
5218
  orderParams: OptionalOrderParams,
5205
5219
  makerInfo?: MakerInfo | MakerInfo[],
5206
5220
  referrerInfo?: ReferrerInfo,
5221
+ successCondition?: PlaceAndTakeOrderSuccessCondition,
5207
5222
  subAccountId?: number
5208
5223
  ): Promise<TransactionInstruction> {
5209
5224
  orderParams = getOrderParams(orderParams, { marketType: MarketType.PERP });
@@ -5260,7 +5275,7 @@ export class DriftClient {
5260
5275
 
5261
5276
  return await this.program.instruction.placeAndTakePerpOrder(
5262
5277
  orderParams,
5263
- null,
5278
+ successCondition ?? null,
5264
5279
  {
5265
5280
  accounts: {
5266
5281
  state: await this.getStatePublicKey(),
@@ -5812,6 +5827,7 @@ export class DriftClient {
5812
5827
  undefined,
5813
5828
  undefined,
5814
5829
  undefined,
5830
+ undefined,
5815
5831
  subAccountId
5816
5832
  );
5817
5833
  }
@@ -11,6 +11,7 @@ import { BulkAccountLoader } from './accounts/bulkAccountLoader';
11
11
  import { DriftEnv } from './config';
12
12
  import { TxSender } from './tx/types';
13
13
  import { TxHandler, TxHandlerConfig } from './tx/txHandler';
14
+ import { DelistedMarketSetting } from './accounts/types';
14
15
 
15
16
  export type DriftClientConfig = {
16
17
  connection: Connection;
@@ -36,6 +37,7 @@ export type DriftClientConfig = {
36
37
  txParams?: TxParams; // default tx params to use
37
38
  enableMetricsEvents?: boolean;
38
39
  txHandlerConfig?: TxHandlerConfig;
40
+ delistedMarketSetting?: DelistedMarketSetting;
39
41
  };
40
42
 
41
43
  export type DriftClientSubscriptionConfig =
package/src/index.ts CHANGED
@@ -108,6 +108,7 @@ export * from './memcmp';
108
108
  export * from './decode/user';
109
109
  export * from './blockhashSubscriber';
110
110
  export * from './util/chainClock';
111
+ export * from './util/TransactionConfirmationManager';
111
112
  export * from './clock/clockSubscriber';
112
113
 
113
114
  export { BN, PublicKey, pyth };
@@ -16,7 +16,7 @@ import {
16
16
  TransactionInstruction,
17
17
  TransactionSignature,
18
18
  } from '@solana/web3.js';
19
- import { BN } from '.';
19
+ import { BN, DEFAULT_CONFIRMATION_OPTS } from '.';
20
20
  import tokenFaucet from './idl/token_faucet.json';
21
21
  import { IWallet } from './types';
22
22
  import { BankrunContextWrapper } from './bankrun/bankrunConnection';
@@ -41,7 +41,7 @@ export class TokenFaucet {
41
41
  this.connection = connection;
42
42
  this.context = context;
43
43
  this.wallet = wallet;
44
- this.opts = opts || AnchorProvider.defaultOptions();
44
+ this.opts = opts || DEFAULT_CONFIRMATION_OPTS;
45
45
  // @ts-ignore
46
46
  const provider = new AnchorProvider(
47
47
  context ? context.connection.toConnection() : this.connection,
@@ -20,12 +20,12 @@ import {
20
20
  AddressLookupTableAccount,
21
21
  BlockhashWithExpiryBlockHeight,
22
22
  } from '@solana/web3.js';
23
- import { AnchorProvider } from '@coral-xyz/anchor';
24
23
  import assert from 'assert';
25
24
  import bs58 from 'bs58';
26
25
  import { TxHandler } from './txHandler';
27
26
  import { IWallet } from '../types';
28
27
  import NodeCache from 'node-cache';
28
+ import { DEFAULT_CONFIRMATION_OPTS } from '../config';
29
29
 
30
30
  const BASELINE_TX_LAND_RATE = 0.9;
31
31
  const DEFAULT_TIMEOUT = 35000;
@@ -54,7 +54,7 @@ export abstract class BaseTxSender implements TxSender {
54
54
  public constructor({
55
55
  connection,
56
56
  wallet,
57
- opts = AnchorProvider.defaultOptions(),
57
+ opts = DEFAULT_CONFIRMATION_OPTS,
58
58
  timeout = DEFAULT_TIMEOUT,
59
59
  additionalConnections = new Array<Connection>(),
60
60
  confirmationStrategy = ConfirmationStrategy.Combo,
@@ -6,10 +6,10 @@ import {
6
6
  Commitment,
7
7
  BlockhashWithExpiryBlockHeight,
8
8
  } from '@solana/web3.js';
9
- import { AnchorProvider } from '@coral-xyz/anchor';
10
9
  import { BaseTxSender } from './baseTxSender';
11
10
  import { TxHandler } from './txHandler';
12
11
  import { IWallet } from '../types';
12
+ import { DEFAULT_CONFIRMATION_OPTS } from '../config';
13
13
 
14
14
  const DEFAULT_TIMEOUT = 35000;
15
15
  const DEFAULT_BLOCKHASH_REFRESH = 10000;
@@ -31,7 +31,7 @@ export class FastSingleTxSender extends BaseTxSender {
31
31
  public constructor({
32
32
  connection,
33
33
  wallet,
34
- opts = { ...AnchorProvider.defaultOptions(), maxRetries: 0 },
34
+ opts = { ...DEFAULT_CONFIRMATION_OPTS, maxRetries: 0 },
35
35
  timeout = DEFAULT_TIMEOUT,
36
36
  blockhashRefreshInterval = DEFAULT_BLOCKHASH_REFRESH,
37
37
  additionalConnections = new Array<Connection>(),
@@ -1,4 +1,3 @@
1
- import { AnchorProvider } from '@coral-xyz/anchor';
2
1
  import {
3
2
  ConfirmOptions,
4
3
  Connection,
@@ -9,6 +8,7 @@ import { BaseTxSender } from './baseTxSender';
9
8
  import { ConfirmationStrategy, TxSigAndSlot } from './types';
10
9
  import { TxHandler } from './txHandler';
11
10
  import { IWallet } from '../types';
11
+ import { DEFAULT_CONFIRMATION_OPTS } from '../config';
12
12
 
13
13
  const DEFAULT_TIMEOUT = 35000;
14
14
  const DEFAULT_RETRY = 5000;
@@ -29,7 +29,7 @@ export class ForwardOnlyTxSender extends BaseTxSender {
29
29
  public constructor({
30
30
  connection,
31
31
  wallet,
32
- opts = { ...AnchorProvider.defaultOptions(), maxRetries: 0 },
32
+ opts = { ...DEFAULT_CONFIRMATION_OPTS, maxRetries: 0 },
33
33
  timeout = DEFAULT_TIMEOUT,
34
34
  retrySleep = DEFAULT_RETRY,
35
35
  confirmationStrategy = ConfirmationStrategy.Combo,
@@ -1,9 +1,9 @@
1
1
  import { ConfirmationStrategy, TxSigAndSlot } from './types';
2
2
  import { ConfirmOptions, Connection } from '@solana/web3.js';
3
- import { AnchorProvider } from '@coral-xyz/anchor';
4
3
  import { BaseTxSender } from './baseTxSender';
5
4
  import { TxHandler } from './txHandler';
6
5
  import { IWallet } from '../types';
6
+ import { DEFAULT_CONFIRMATION_OPTS } from '../config';
7
7
 
8
8
  const DEFAULT_TIMEOUT = 35000;
9
9
  const DEFAULT_RETRY = 2000;
@@ -24,7 +24,7 @@ export class RetryTxSender extends BaseTxSender {
24
24
  public constructor({
25
25
  connection,
26
26
  wallet,
27
- opts = { ...AnchorProvider.defaultOptions(), maxRetries: 0 },
27
+ opts = { ...DEFAULT_CONFIRMATION_OPTS, maxRetries: 0 },
28
28
  timeout = DEFAULT_TIMEOUT,
29
29
  retrySleep = DEFAULT_RETRY,
30
30
  additionalConnections = new Array<Connection>(),
@@ -29,6 +29,7 @@ import { CachedBlockhashFetcher } from './blockhashFetcher/cachedBlockhashFetche
29
29
  import { BaseBlockhashFetcher } from './blockhashFetcher/baseBlockhashFetcher';
30
30
  import { BlockhashFetcher } from './blockhashFetcher/types';
31
31
  import { isVersionedTransaction } from './utils';
32
+ import { DEFAULT_CONFIRMATION_OPTS } from '../config';
32
33
 
33
34
  /**
34
35
  * Explanation for SIGNATURE_BLOCK_AND_EXPIRY:
@@ -81,7 +82,8 @@ export class TxHandler {
81
82
  private preSignedCb?: () => void;
82
83
  private onSignedCb?: (txSigs: DriftClientMetricsEvents['txSigned']) => void;
83
84
 
84
- private blockhashCommitment: Commitment = 'finalized';
85
+ private blockhashCommitment: Commitment =
86
+ DEFAULT_CONFIRMATION_OPTS.commitment;
85
87
  private blockHashFetcher: BlockhashFetcher;
86
88
 
87
89
  constructor(props: {
@@ -98,6 +100,11 @@ export class TxHandler {
98
100
  this.connection = props.connection;
99
101
  this.wallet = props.wallet;
100
102
  this.confirmationOptions = props.confirmationOptions;
103
+ this.blockhashCommitment =
104
+ props.confirmationOptions?.preflightCommitment ??
105
+ props?.connection?.commitment ??
106
+ this.blockhashCommitment ??
107
+ 'confirmed';
101
108
 
102
109
  this.blockHashFetcher = props?.config?.blockhashCachingEnabled
103
110
  ? new CachedBlockhashFetcher(
@@ -1,22 +1,20 @@
1
1
  import { TxSigAndSlot } from './types';
2
2
  import {
3
- Commitment,
4
3
  ConfirmOptions,
5
4
  Connection,
5
+ SendTransactionError,
6
6
  Signer,
7
7
  Transaction,
8
8
  VersionedTransaction,
9
9
  } from '@solana/web3.js';
10
- import { AnchorProvider } from '@coral-xyz/anchor';
11
10
  import { BaseTxSender } from './baseTxSender';
12
11
  import bs58 from 'bs58';
13
12
  import { TxHandler } from './txHandler';
14
13
  import { IWallet } from '../types';
14
+ import { DEFAULT_CONFIRMATION_OPTS } from '../config';
15
15
 
16
16
  const DEFAULT_RETRY = 2000;
17
17
 
18
- const VALID_BLOCK_HEIGHT_OFFSET = -150; // This is a bit of weirdness but the lastValidBlockHeight value returned from connection.getLatestBlockhash is always 300 blocks ahead of the current block, even though the transaction actually expires after 150 blocks. This accounts for that so that we can at least accuractely estimate the transaction expiry.
19
-
20
18
  type ResolveReference = {
21
19
  resolve?: () => void;
22
20
  };
@@ -33,7 +31,6 @@ export class WhileValidTxSender extends BaseTxSender {
33
31
  string,
34
32
  { blockhash: string; lastValidBlockHeight: number }
35
33
  >();
36
- blockhashCommitment: Commitment;
37
34
 
38
35
  useBlockHeightOffset = true;
39
36
 
@@ -62,11 +59,10 @@ export class WhileValidTxSender extends BaseTxSender {
62
59
  public constructor({
63
60
  connection,
64
61
  wallet,
65
- opts = { ...AnchorProvider.defaultOptions(), maxRetries: 0 },
62
+ opts = { ...DEFAULT_CONFIRMATION_OPTS, maxRetries: 0 },
66
63
  retrySleep = DEFAULT_RETRY,
67
64
  additionalConnections = new Array<Connection>(),
68
65
  additionalTxSenderCallbacks = [],
69
- blockhashCommitment = 'finalized',
70
66
  txHandler,
71
67
  trackTxLandRate,
72
68
  txLandRateLookbackWindowMinutes,
@@ -78,7 +74,6 @@ export class WhileValidTxSender extends BaseTxSender {
78
74
  retrySleep?: number;
79
75
  additionalConnections?;
80
76
  additionalTxSenderCallbacks?: ((base58EncodedTx: string) => void)[];
81
- blockhashCommitment?: Commitment;
82
77
  txHandler?: TxHandler;
83
78
  trackTxLandRate?: boolean;
84
79
  txLandRateLookbackWindowMinutes?: number;
@@ -96,7 +91,6 @@ export class WhileValidTxSender extends BaseTxSender {
96
91
  landRateToFeeFunc,
97
92
  });
98
93
  this.retrySleep = retrySleep;
99
- this.blockhashCommitment = blockhashCommitment;
100
94
 
101
95
  this.checkAndSetUseBlockHeightOffset();
102
96
  }
@@ -139,7 +133,7 @@ export class WhileValidTxSender extends BaseTxSender {
139
133
 
140
134
  // handle subclass-specific side effects
141
135
  const txSig = bs58.encode(
142
- signedTx.signatures[0]?.signature || signedTx.signatures[0]
136
+ signedTx?.signature || signedTx.signatures[0]?.signature
143
137
  );
144
138
  this.untilValid.set(txSig, latestBlockhash);
145
139
 
@@ -193,6 +187,11 @@ export class WhileValidTxSender extends BaseTxSender {
193
187
  const txSig = bs58.encode(signedTx.signatures[0]);
194
188
  this.untilValid.set(txSig, latestBlockhash);
195
189
 
190
+ console.debug(
191
+ `preflight_commitment`,
192
+ `sending_tx_with_preflight_commitment::${opts?.preflightCommitment}`
193
+ );
194
+
196
195
  return this.sendRawTransaction(signedTx.serialize(), opts);
197
196
  }
198
197
 
@@ -202,6 +201,10 @@ export class WhileValidTxSender extends BaseTxSender {
202
201
  ): Promise<TxSigAndSlot> {
203
202
  const startTime = this.getTimestamp();
204
203
 
204
+ console.debug(
205
+ `preflight_commitment`,
206
+ `sending_tx_with_preflight_commitment::${opts?.preflightCommitment}`
207
+ );
205
208
  const txid = await this.connection.sendRawTransaction(rawTransaction, opts);
206
209
  this.txSigCache?.set(txid, false);
207
210
  this.sendToAdditionalConnections(rawTransaction, opts);
@@ -234,27 +237,21 @@ export class WhileValidTxSender extends BaseTxSender {
234
237
 
235
238
  let slot: number;
236
239
  try {
237
- const { blockhash, lastValidBlockHeight } = this.untilValid.get(txid);
238
-
239
- const result = await this.connection.confirmTransaction(
240
- {
241
- signature: txid,
242
- blockhash,
243
- lastValidBlockHeight: this.useBlockHeightOffset
244
- ? lastValidBlockHeight + VALID_BLOCK_HEIGHT_OFFSET
245
- : lastValidBlockHeight,
246
- },
247
- opts?.commitment
248
- );
249
-
250
- if (!result) {
251
- throw new Error(`Couldn't get signature status for txid: ${txid}`);
252
- }
240
+ const result = await this.confirmTransaction(txid, opts.commitment);
253
241
 
254
242
  this.txSigCache?.set(txid, true);
255
243
 
256
244
  await this.checkConfirmationResultForError(txid, result.value);
257
245
 
246
+ if (result?.value?.err) {
247
+ // Fallback error handling if there's a problem reporting the error in checkConfirmationResultForError
248
+ throw new SendTransactionError({
249
+ action: 'send',
250
+ signature: txid,
251
+ transactionMessage: `Transaction Failed`,
252
+ });
253
+ }
254
+
258
255
  slot = result.context.slot;
259
256
  // eslint-disable-next-line no-useless-catch
260
257
  } catch (e) {
package/src/types.ts CHANGED
@@ -1083,6 +1083,11 @@ export type ReferrerInfo = {
1083
1083
  referrerStats: PublicKey;
1084
1084
  };
1085
1085
 
1086
+ export enum PlaceAndTakeOrderSuccessCondition {
1087
+ PartialFill = 1,
1088
+ FullFill = 2,
1089
+ }
1090
+
1086
1091
  type ExactType<T> = Pick<T, keyof T>;
1087
1092
 
1088
1093
  export type BaseTxParams = ExactType<{