@drift-labs/sdk 2.84.0-beta.2 → 2.84.0-beta.4

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.84.0-beta.2
1
+ 2.84.0-beta.4
@@ -1601,7 +1601,7 @@ class AdminClient extends driftClient_1.DriftClient {
1601
1601
  maxPrice: maxPrice || null,
1602
1602
  };
1603
1603
  const perpMarketPublicKey = await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex);
1604
- return await this.program.instruction.getDeletePrelaunchOracleIx(params, {
1604
+ return await this.program.instruction.deletePrelaunchOracle(params, {
1605
1605
  accounts: {
1606
1606
  admin: this.isSubscribed
1607
1607
  ? this.getStateAccount().admin
@@ -582,9 +582,9 @@ exports.MainnetPerpMarkets = [
582
582
  symbol: 'IO-PERP',
583
583
  baseAssetSymbol: 'IO',
584
584
  marketIndex: 32,
585
- oracle: new web3_js_1.PublicKey('5sAqMGidMtztNFdUukyguz6jMFS8DvTmSUr4p5u5zsSg'),
585
+ oracle: new web3_js_1.PublicKey('Gcm39uDrFyRCZko4hdrKMTBQsboPJHEd4RwnWhWFKr9a'),
586
586
  launchTs: 1718021389000,
587
- oracleSource: __1.OracleSource.Prelaunch,
587
+ oracleSource: __1.OracleSource.SWITCHBOARD,
588
588
  },
589
589
  ];
590
590
  exports.PerpMarkets = {
@@ -8849,7 +8849,7 @@
8849
8849
  "kind": "enum",
8850
8850
  "variants": [
8851
8851
  {
8852
- "name": "Invalid"
8852
+ "name": "NonPositive"
8853
8853
  },
8854
8854
  {
8855
8855
  "name": "TooVolatile"
@@ -11962,6 +11962,36 @@
11962
11962
  "code": 6260,
11963
11963
  "name": "PnlPoolCantSettleUser",
11964
11964
  "msg": "PnlPoolCantSettleUser"
11965
+ },
11966
+ {
11967
+ "code": 6261,
11968
+ "name": "OracleNonPositive",
11969
+ "msg": "OracleInvalid"
11970
+ },
11971
+ {
11972
+ "code": 6262,
11973
+ "name": "OracleTooVolatile",
11974
+ "msg": "OracleTooVolatile"
11975
+ },
11976
+ {
11977
+ "code": 6263,
11978
+ "name": "OracleTooUncertain",
11979
+ "msg": "OracleTooUncertain"
11980
+ },
11981
+ {
11982
+ "code": 6264,
11983
+ "name": "OracleStaleForMargin",
11984
+ "msg": "OracleStaleForMargin"
11985
+ },
11986
+ {
11987
+ "code": 6265,
11988
+ "name": "OracleInsufficientDataPoints",
11989
+ "msg": "OracleInsufficientDataPoints"
11990
+ },
11991
+ {
11992
+ "code": 6266,
11993
+ "name": "OracleStaleForAMM",
11994
+ "msg": "OracleStaleForAMM"
11965
11995
  }
11966
11996
  ]
11967
11997
  }
@@ -32,7 +32,7 @@ export declare function calculateUnrealizedAssetWeight(market: PerpMarketAccount
32
32
  export declare function calculateMarketAvailablePNL(perpMarket: PerpMarketAccount, spotMarket: SpotMarketAccount): BN;
33
33
  export declare function calculateMarketMaxAvailableInsurance(perpMarket: PerpMarketAccount, spotMarket: SpotMarketAccount): BN;
34
34
  export declare function calculateNetUserPnl(perpMarket: PerpMarketAccount, oraclePriceData: OraclePriceData): BN;
35
- export declare function calculateNetUserPnlImbalance(perpMarket: PerpMarketAccount, spotMarket: SpotMarketAccount, oraclePriceData: OraclePriceData): BN;
35
+ export declare function calculateNetUserPnlImbalance(perpMarket: PerpMarketAccount, spotMarket: SpotMarketAccount, oraclePriceData: OraclePriceData, applyFeePoolDiscount?: boolean): BN;
36
36
  export declare function calculateAvailablePerpLiquidity(market: PerpMarketAccount, oraclePriceData: OraclePriceData, dlob: DLOB, slot: number): {
37
37
  bids: BN;
38
38
  asks: BN;
@@ -123,10 +123,13 @@ function calculateNetUserPnl(perpMarket, oraclePriceData) {
123
123
  return netUserPnl;
124
124
  }
125
125
  exports.calculateNetUserPnl = calculateNetUserPnl;
126
- function calculateNetUserPnlImbalance(perpMarket, spotMarket, oraclePriceData) {
126
+ function calculateNetUserPnlImbalance(perpMarket, spotMarket, oraclePriceData, applyFeePoolDiscount = true) {
127
127
  const netUserPnl = calculateNetUserPnl(perpMarket, oraclePriceData);
128
128
  const pnlPool = (0, spotBalance_1.getTokenAmount)(perpMarket.pnlPool.scaledBalance, spotMarket, types_1.SpotBalanceType.DEPOSIT);
129
- const feePool = (0, spotBalance_1.getTokenAmount)(perpMarket.amm.feePool.scaledBalance, spotMarket, types_1.SpotBalanceType.DEPOSIT).div(new anchor_1.BN(5));
129
+ let feePool = (0, spotBalance_1.getTokenAmount)(perpMarket.amm.feePool.scaledBalance, spotMarket, types_1.SpotBalanceType.DEPOSIT);
130
+ if (applyFeePoolDiscount) {
131
+ feePool = feePool.div(new anchor_1.BN(5));
132
+ }
130
133
  const imbalance = netUserPnl.sub(pnlPool.add(feePool));
131
134
  return imbalance;
132
135
  }
package/lib/testClient.js CHANGED
@@ -8,6 +8,8 @@ class TestClient extends adminClient_1.AdminClient {
8
8
  throw new Error('Test client must be polling');
9
9
  }
10
10
  super(config);
11
+ // @ts-ignore
12
+ this.txHandler.blockhashCommitment = 'recent';
11
13
  }
12
14
  async sendTransaction(tx, additionalSigners, opts, preSigned) {
13
15
  const { txSig, slot } = await super.sendTransaction(tx, additionalSigners, opts, preSigned);
@@ -238,7 +238,12 @@ class BaseTxSender {
238
238
  const logs = transactionResult.meta.logMessages;
239
239
  const lastLog = logs[logs.length - 1];
240
240
  const friendlyMessage = (_b = lastLog === null || lastLog === void 0 ? void 0 : lastLog.match(/(failed:) (.+)/)) === null || _b === void 0 ? void 0 : _b[2];
241
- throw new web3_js_1.SendTransactionError(`Transaction Failed${friendlyMessage ? `: ${friendlyMessage}` : ''}`, transactionResult.meta.logMessages);
241
+ throw new web3_js_1.SendTransactionError({
242
+ action: 'send',
243
+ signature: txSig,
244
+ transactionMessage: `Transaction Failed${friendlyMessage ? `: ${friendlyMessage}` : ''}`,
245
+ logs,
246
+ });
242
247
  }
243
248
  }
244
249
  exports.BaseTxSender = BaseTxSender;
@@ -24,6 +24,7 @@ export declare class TxHandler {
24
24
  private confirmationOptions;
25
25
  private preSignedCb?;
26
26
  private onSignedCb?;
27
+ private blockhashCommitment;
27
28
  constructor(props: {
28
29
  connection: Connection;
29
30
  wallet: IWallet;
@@ -13,7 +13,7 @@ const computeUnits_1 = require("../util/computeUnits");
13
13
  *
14
14
  * When the whileValidTxSender waits for confirmation of a given transaction, it needs the last available blockheight and blockhash used in the signature to do so. For pre-signed transactions, these values aren't attached to the transaction object by default. For a "scrappy" workaround which doesn't break backwards compatibility, the SIGNATURE_BLOCK_AND_EXPIRY property is simply attached to the transaction objects as they are created or signed in this handler despite a mismatch in the typescript types. If the values are attached to the transaction when they reach the whileValidTxSender, it can opt-in to use these values.
15
15
  */
16
- const DEV_TRY_FORCE_TX_TIMEOUTS = false;
16
+ const DEV_TRY_FORCE_TX_TIMEOUTS = process.env.DEV_TRY_FORCE_TX_TIMEOUTS === 'true' || false;
17
17
  exports.COMPUTE_UNITS_DEFAULT = 200000;
18
18
  /**
19
19
  * This class is responsible for creating and signing transactions.
@@ -23,6 +23,7 @@ class TxHandler {
23
23
  var _a, _b, _c, _d;
24
24
  this.blockHashToLastValidBlockHeightLookup = {};
25
25
  this.returnBlockHeightsWithSignedTxCallbackData = false;
26
+ this.blockhashCommitment = 'finalized';
26
27
  this.getProps = (wallet, confirmationOpts) => [wallet !== null && wallet !== void 0 ? wallet : this.wallet, confirmationOpts !== null && confirmationOpts !== void 0 ? confirmationOpts : this.confirmationOptions];
27
28
  this.connection = props.connection;
28
29
  this.wallet = props.wallet;
@@ -50,7 +51,7 @@ class TxHandler {
50
51
  * @returns
51
52
  */
52
53
  getLatestBlockhashForTransaction() {
53
- return this.connection.getLatestBlockhash('finalized');
54
+ return this.connection.getLatestBlockhash(this.blockhashCommitment);
54
55
  }
55
56
  /**
56
57
  * Applies recent blockhash and signs a given transaction
@@ -283,7 +284,7 @@ class TxHandler {
283
284
  }));
284
285
  }
285
286
  const computeUnitsPrice = baseTxParams === null || baseTxParams === void 0 ? void 0 : baseTxParams.computeUnitsPrice;
286
- if (process.env.DEV_TRY_FORCE_TX_TIMEOUTS || DEV_TRY_FORCE_TX_TIMEOUTS) {
287
+ if (DEV_TRY_FORCE_TX_TIMEOUTS) {
287
288
  allIx.push(web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({
288
289
  microLamports: 0,
289
290
  }));
@@ -319,7 +320,7 @@ class TxHandler {
319
320
  units: computeUnits,
320
321
  }));
321
322
  }
322
- if (process.env.DEV_TRY_FORCE_TX_TIMEOUTS || DEV_TRY_FORCE_TX_TIMEOUTS) {
323
+ if (DEV_TRY_FORCE_TX_TIMEOUTS) {
323
324
  tx.add(web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({
324
325
  microLamports: 0,
325
326
  }));
@@ -32,7 +32,7 @@ class WhileValidTxSender extends baseTxSender_1.BaseTxSender {
32
32
  }
33
33
  async prepareTx(tx, additionalSigners, opts, preSigned) {
34
34
  var _a;
35
- const latestBlockhash = await this.txHandler.getLatestBlockhashForTransaction();
35
+ let latestBlockhash = await this.txHandler.getLatestBlockhashForTransaction();
36
36
  // handle tx
37
37
  let signedTx = tx;
38
38
  if (!preSigned) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.84.0-beta.2",
3
+ "version": "2.84.0-beta.4",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -39,7 +39,7 @@
39
39
  "@project-serum/serum": "^0.13.38",
40
40
  "@pythnetwork/client": "2.5.3",
41
41
  "@solana/spl-token": "^0.3.7",
42
- "@solana/web3.js": "1.91.7",
42
+ "@solana/web3.js": "1.92.3",
43
43
  "strict-event-emitter-types": "^2.0.0",
44
44
  "uuid": "^8.3.2",
45
45
  "zstddec": "^0.1.0"
@@ -3472,7 +3472,7 @@ export class AdminClient extends DriftClient {
3472
3472
  perpMarketIndex
3473
3473
  );
3474
3474
 
3475
- return await this.program.instruction.getDeletePrelaunchOracleIx(params, {
3475
+ return await this.program.instruction.deletePrelaunchOracle(params, {
3476
3476
  accounts: {
3477
3477
  admin: this.isSubscribed
3478
3478
  ? this.getStateAccount().admin
@@ -593,9 +593,9 @@ export const MainnetPerpMarkets: PerpMarketConfig[] = [
593
593
  symbol: 'IO-PERP',
594
594
  baseAssetSymbol: 'IO',
595
595
  marketIndex: 32,
596
- oracle: new PublicKey('5sAqMGidMtztNFdUukyguz6jMFS8DvTmSUr4p5u5zsSg'),
596
+ oracle: new PublicKey('Gcm39uDrFyRCZko4hdrKMTBQsboPJHEd4RwnWhWFKr9a'),
597
597
  launchTs: 1718021389000,
598
- oracleSource: OracleSource.Prelaunch,
598
+ oracleSource: OracleSource.SWITCHBOARD,
599
599
  },
600
600
  ];
601
601
 
@@ -8849,7 +8849,7 @@
8849
8849
  "kind": "enum",
8850
8850
  "variants": [
8851
8851
  {
8852
- "name": "Invalid"
8852
+ "name": "NonPositive"
8853
8853
  },
8854
8854
  {
8855
8855
  "name": "TooVolatile"
@@ -11962,6 +11962,36 @@
11962
11962
  "code": 6260,
11963
11963
  "name": "PnlPoolCantSettleUser",
11964
11964
  "msg": "PnlPoolCantSettleUser"
11965
+ },
11966
+ {
11967
+ "code": 6261,
11968
+ "name": "OracleNonPositive",
11969
+ "msg": "OracleInvalid"
11970
+ },
11971
+ {
11972
+ "code": 6262,
11973
+ "name": "OracleTooVolatile",
11974
+ "msg": "OracleTooVolatile"
11975
+ },
11976
+ {
11977
+ "code": 6263,
11978
+ "name": "OracleTooUncertain",
11979
+ "msg": "OracleTooUncertain"
11980
+ },
11981
+ {
11982
+ "code": 6264,
11983
+ "name": "OracleStaleForMargin",
11984
+ "msg": "OracleStaleForMargin"
11985
+ },
11986
+ {
11987
+ "code": 6265,
11988
+ "name": "OracleInsufficientDataPoints",
11989
+ "msg": "OracleInsufficientDataPoints"
11990
+ },
11991
+ {
11992
+ "code": 6266,
11993
+ "name": "OracleStaleForAMM",
11994
+ "msg": "OracleStaleForAMM"
11965
11995
  }
11966
11996
  ]
11967
11997
  }
@@ -252,7 +252,8 @@ export function calculateNetUserPnl(
252
252
  export function calculateNetUserPnlImbalance(
253
253
  perpMarket: PerpMarketAccount,
254
254
  spotMarket: SpotMarketAccount,
255
- oraclePriceData: OraclePriceData
255
+ oraclePriceData: OraclePriceData,
256
+ applyFeePoolDiscount = true
256
257
  ): BN {
257
258
  const netUserPnl = calculateNetUserPnl(perpMarket, oraclePriceData);
258
259
 
@@ -261,11 +262,14 @@ export function calculateNetUserPnlImbalance(
261
262
  spotMarket,
262
263
  SpotBalanceType.DEPOSIT
263
264
  );
264
- const feePool = getTokenAmount(
265
+ let feePool = getTokenAmount(
265
266
  perpMarket.amm.feePool.scaledBalance,
266
267
  spotMarket,
267
268
  SpotBalanceType.DEPOSIT
268
- ).div(new BN(5));
269
+ );
270
+ if (applyFeePoolDiscount) {
271
+ feePool = feePool.div(new BN(5));
272
+ }
269
273
 
270
274
  const imbalance = netUserPnl.sub(pnlPool.add(feePool));
271
275
 
package/src/testClient.ts CHANGED
@@ -10,6 +10,8 @@ export class TestClient extends AdminClient {
10
10
  throw new Error('Test client must be polling');
11
11
  }
12
12
  super(config);
13
+ // @ts-ignore
14
+ this.txHandler.blockhashCommitment = 'recent';
13
15
  }
14
16
 
15
17
  async sendTransaction(
@@ -394,9 +394,13 @@ export abstract class BaseTxSender implements TxSender {
394
394
 
395
395
  const friendlyMessage = lastLog?.match(/(failed:) (.+)/)?.[2];
396
396
 
397
- throw new SendTransactionError(
398
- `Transaction Failed${friendlyMessage ? `: ${friendlyMessage}` : ''}`,
399
- transactionResult.meta.logMessages
400
- );
397
+ throw new SendTransactionError({
398
+ action: 'send',
399
+ signature: txSig,
400
+ transactionMessage: `Transaction Failed${
401
+ friendlyMessage ? `: ${friendlyMessage}` : ''
402
+ }`,
403
+ logs,
404
+ });
401
405
  }
402
406
  }
@@ -31,7 +31,8 @@ import { containsComputeUnitIxs } from '../util/computeUnits';
31
31
  * When the whileValidTxSender waits for confirmation of a given transaction, it needs the last available blockheight and blockhash used in the signature to do so. For pre-signed transactions, these values aren't attached to the transaction object by default. For a "scrappy" workaround which doesn't break backwards compatibility, the SIGNATURE_BLOCK_AND_EXPIRY property is simply attached to the transaction objects as they are created or signed in this handler despite a mismatch in the typescript types. If the values are attached to the transaction when they reach the whileValidTxSender, it can opt-in to use these values.
32
32
  */
33
33
 
34
- const DEV_TRY_FORCE_TX_TIMEOUTS = false;
34
+ const DEV_TRY_FORCE_TX_TIMEOUTS =
35
+ process.env.DEV_TRY_FORCE_TX_TIMEOUTS === 'true' || false;
35
36
 
36
37
  export const COMPUTE_UNITS_DEFAULT = 200_000;
37
38
 
@@ -62,6 +63,8 @@ export class TxHandler {
62
63
  private preSignedCb?: () => void;
63
64
  private onSignedCb?: (txSigs: DriftClientMetricsEvents['txSigned']) => void;
64
65
 
66
+ private blockhashCommitment: Commitment = 'finalized';
67
+
65
68
  constructor(props: {
66
69
  connection: Connection;
67
70
  wallet: IWallet;
@@ -110,7 +113,7 @@ export class TxHandler {
110
113
  * @returns
111
114
  */
112
115
  public getLatestBlockhashForTransaction() {
113
- return this.connection.getLatestBlockhash('finalized');
116
+ return this.connection.getLatestBlockhash(this.blockhashCommitment);
114
117
  }
115
118
 
116
119
  /**
@@ -457,7 +460,7 @@ export class TxHandler {
457
460
 
458
461
  const computeUnitsPrice = baseTxParams?.computeUnitsPrice;
459
462
 
460
- if (process.env.DEV_TRY_FORCE_TX_TIMEOUTS || DEV_TRY_FORCE_TX_TIMEOUTS) {
463
+ if (DEV_TRY_FORCE_TX_TIMEOUTS) {
461
464
  allIx.push(
462
465
  ComputeBudgetProgram.setComputeUnitPrice({
463
466
  microLamports: 0,
@@ -512,7 +515,7 @@ export class TxHandler {
512
515
  );
513
516
  }
514
517
 
515
- if (process.env.DEV_TRY_FORCE_TX_TIMEOUTS || DEV_TRY_FORCE_TX_TIMEOUTS) {
518
+ if (DEV_TRY_FORCE_TX_TIMEOUTS) {
516
519
  tx.add(
517
520
  ComputeBudgetProgram.setComputeUnitPrice({
518
521
  microLamports: 0,
@@ -79,7 +79,7 @@ export class WhileValidTxSender extends BaseTxSender {
79
79
  opts: ConfirmOptions,
80
80
  preSigned?: boolean
81
81
  ): Promise<Transaction> {
82
- const latestBlockhash =
82
+ let latestBlockhash =
83
83
  await this.txHandler.getLatestBlockhashForTransaction();
84
84
 
85
85
  // handle tx