@drift-labs/sdk 2.25.0-beta.2 → 2.25.1

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 (45) hide show
  1. package/lib/addresses/pda.d.ts +0 -1
  2. package/lib/adminClient.d.ts +0 -1
  3. package/lib/constants/numericConstants.d.ts +59 -61
  4. package/lib/constants/perpMarkets.js +10 -0
  5. package/lib/constants/spotMarkets.d.ts +0 -1
  6. package/lib/dlob/DLOB.d.ts +0 -1
  7. package/lib/dlob/DLOBNode.d.ts +0 -1
  8. package/lib/dlob/NodeList.d.ts +0 -1
  9. package/lib/driftClient.d.ts +5 -2
  10. package/lib/driftClient.js +24 -17
  11. package/lib/factory/bigNum.d.ts +7 -8
  12. package/lib/idl/drift.json +1 -1
  13. package/lib/math/amm.d.ts +1 -2
  14. package/lib/math/auction.d.ts +0 -1
  15. package/lib/math/conversion.d.ts +1 -2
  16. package/lib/math/funding.d.ts +0 -1
  17. package/lib/math/insurance.d.ts +0 -1
  18. package/lib/math/margin.d.ts +0 -1
  19. package/lib/math/market.d.ts +0 -1
  20. package/lib/math/oracles.d.ts +0 -1
  21. package/lib/math/orders.d.ts +0 -1
  22. package/lib/math/position.d.ts +0 -1
  23. package/lib/math/repeg.d.ts +0 -1
  24. package/lib/math/spotBalance.d.ts +0 -1
  25. package/lib/math/spotMarket.d.ts +0 -1
  26. package/lib/math/spotPosition.d.ts +0 -1
  27. package/lib/math/trade.d.ts +0 -1
  28. package/lib/math/utils.d.ts +0 -1
  29. package/lib/oracles/pythClient.d.ts +1 -2
  30. package/lib/oracles/types.d.ts +0 -1
  31. package/lib/orderParams.d.ts +0 -1
  32. package/lib/serum/serumSubscriber.d.ts +0 -1
  33. package/lib/tokenFaucet.d.ts +0 -1
  34. package/lib/types.d.ts +0 -1
  35. package/lib/user.d.ts +0 -1
  36. package/package.json +1 -1
  37. package/src/assert/assert.js +9 -0
  38. package/src/constants/perpMarkets.ts +10 -0
  39. package/src/driftClient.ts +34 -17
  40. package/src/idl/drift.json +1 -1
  41. package/src/token/index.js +38 -0
  42. package/src/util/computeUnits.js +27 -0
  43. package/src/util/getTokenAddress.js +9 -0
  44. package/src/util/promiseTimeout.js +14 -0
  45. package/src/util/tps.js +27 -0
@@ -1,4 +1,3 @@
1
- /// <reference types="bn.js" />
2
1
  import { PublicKey } from '@solana/web3.js';
3
2
  import { BN } from '@coral-xyz/anchor';
4
3
  export declare function getDriftStateAccountPublicKeyAndNonce(programId: PublicKey): Promise<[PublicKey, number]>;
@@ -1,4 +1,3 @@
1
- /// <reference types="bn.js" />
2
1
  import { PublicKey, TransactionSignature } from '@solana/web3.js';
3
2
  import { FeeStructure, OracleGuardRails, OracleSource, ExchangeStatus, MarketStatus, ContractTier, AssetTier, SpotFulfillmentConfigStatus } from './types';
4
3
  import { BN } from '@coral-xyz/anchor';
@@ -1,62 +1,60 @@
1
- /// <reference types="bn.js" />
2
- import { BN } from '../';
3
- export declare const ZERO: BN;
4
- export declare const ONE: BN;
5
- export declare const TWO: BN;
6
- export declare const THREE: BN;
7
- export declare const FOUR: BN;
8
- export declare const FIVE: BN;
9
- export declare const SIX: BN;
10
- export declare const SEVEN: BN;
11
- export declare const EIGHT: BN;
12
- export declare const NINE: BN;
13
- export declare const TEN: BN;
14
- export declare const TEN_THOUSAND: BN;
15
- export declare const BN_MAX: BN;
16
- export declare const TEN_MILLION: BN;
17
- export declare const MAX_LEVERAGE: BN;
18
- export declare const MAX_LEVERAGE_ORDER_SIZE: BN;
19
- export declare const PERCENTAGE_PRECISION_EXP: BN;
20
- export declare const PERCENTAGE_PRECISION: BN;
21
- export declare const CONCENTRATION_PRECISION: BN;
22
- export declare const QUOTE_PRECISION_EXP: BN;
23
- export declare const FUNDING_RATE_BUFFER_PRECISION_EXP: BN;
24
- export declare const PRICE_PRECISION_EXP: BN;
25
- export declare const FUNDING_RATE_PRECISION_EXP: BN;
26
- export declare const PEG_PRECISION_EXP: BN;
27
- export declare const AMM_RESERVE_PRECISION_EXP: BN;
28
- export declare const SPOT_MARKET_RATE_PRECISION_EXP: BN;
29
- export declare const SPOT_MARKET_RATE_PRECISION: BN;
30
- export declare const SPOT_MARKET_CUMULATIVE_INTEREST_PRECISION_EXP: BN;
31
- export declare const SPOT_MARKET_CUMULATIVE_INTEREST_PRECISION: BN;
32
- export declare const SPOT_MARKET_UTILIZATION_PRECISION_EXP: BN;
33
- export declare const SPOT_MARKET_UTILIZATION_PRECISION: BN;
34
- export declare const SPOT_MARKET_WEIGHT_PRECISION: BN;
35
- export declare const SPOT_MARKET_BALANCE_PRECISION_EXP: BN;
36
- export declare const SPOT_MARKET_BALANCE_PRECISION: BN;
37
- export declare const SPOT_MARKET_IMF_PRECISION_EXP: BN;
38
- export declare const SPOT_MARKET_IMF_PRECISION: BN;
39
- export declare const LIQUIDATION_FEE_PRECISION: BN;
40
- export declare const QUOTE_PRECISION: BN;
41
- export declare const PRICE_PRECISION: BN;
42
- export declare const FUNDING_RATE_PRECISION: BN;
43
- export declare const FUNDING_RATE_BUFFER_PRECISION: BN;
44
- export declare const PEG_PRECISION: BN;
45
- export declare const AMM_RESERVE_PRECISION: BN;
46
- export declare const BASE_PRECISION: BN;
47
- export declare const BASE_PRECISION_EXP: BN;
48
- export declare const AMM_TO_QUOTE_PRECISION_RATIO: BN;
49
- export declare const PRICE_DIV_PEG: BN;
50
- export declare const PRICE_TO_QUOTE_PRECISION: BN;
51
- export declare const AMM_TIMES_PEG_TO_QUOTE_PRECISION_RATIO: BN;
52
- export declare const MARGIN_PRECISION: BN;
53
- export declare const BID_ASK_SPREAD_PRECISION: BN;
54
- export declare const LIQUIDATION_PCT_PRECISION: BN;
55
- export declare const FIVE_MINUTE: BN;
56
- export declare const ONE_HOUR: BN;
57
- export declare const ONE_YEAR: BN;
1
+ export declare const ZERO: any;
2
+ export declare const ONE: any;
3
+ export declare const TWO: any;
4
+ export declare const THREE: any;
5
+ export declare const FOUR: any;
6
+ export declare const FIVE: any;
7
+ export declare const SIX: any;
8
+ export declare const SEVEN: any;
9
+ export declare const EIGHT: any;
10
+ export declare const NINE: any;
11
+ export declare const TEN: any;
12
+ export declare const TEN_THOUSAND: any;
13
+ export declare const BN_MAX: any;
14
+ export declare const TEN_MILLION: any;
15
+ export declare const MAX_LEVERAGE: any;
16
+ export declare const MAX_LEVERAGE_ORDER_SIZE: any;
17
+ export declare const PERCENTAGE_PRECISION_EXP: any;
18
+ export declare const PERCENTAGE_PRECISION: any;
19
+ export declare const CONCENTRATION_PRECISION: any;
20
+ export declare const QUOTE_PRECISION_EXP: any;
21
+ export declare const FUNDING_RATE_BUFFER_PRECISION_EXP: any;
22
+ export declare const PRICE_PRECISION_EXP: any;
23
+ export declare const FUNDING_RATE_PRECISION_EXP: any;
24
+ export declare const PEG_PRECISION_EXP: any;
25
+ export declare const AMM_RESERVE_PRECISION_EXP: any;
26
+ export declare const SPOT_MARKET_RATE_PRECISION_EXP: any;
27
+ export declare const SPOT_MARKET_RATE_PRECISION: any;
28
+ export declare const SPOT_MARKET_CUMULATIVE_INTEREST_PRECISION_EXP: any;
29
+ export declare const SPOT_MARKET_CUMULATIVE_INTEREST_PRECISION: any;
30
+ export declare const SPOT_MARKET_UTILIZATION_PRECISION_EXP: any;
31
+ export declare const SPOT_MARKET_UTILIZATION_PRECISION: any;
32
+ export declare const SPOT_MARKET_WEIGHT_PRECISION: any;
33
+ export declare const SPOT_MARKET_BALANCE_PRECISION_EXP: any;
34
+ export declare const SPOT_MARKET_BALANCE_PRECISION: any;
35
+ export declare const SPOT_MARKET_IMF_PRECISION_EXP: any;
36
+ export declare const SPOT_MARKET_IMF_PRECISION: any;
37
+ export declare const LIQUIDATION_FEE_PRECISION: any;
38
+ export declare const QUOTE_PRECISION: any;
39
+ export declare const PRICE_PRECISION: any;
40
+ export declare const FUNDING_RATE_PRECISION: any;
41
+ export declare const FUNDING_RATE_BUFFER_PRECISION: any;
42
+ export declare const PEG_PRECISION: any;
43
+ export declare const AMM_RESERVE_PRECISION: any;
44
+ export declare const BASE_PRECISION: any;
45
+ export declare const BASE_PRECISION_EXP: any;
46
+ export declare const AMM_TO_QUOTE_PRECISION_RATIO: any;
47
+ export declare const PRICE_DIV_PEG: any;
48
+ export declare const PRICE_TO_QUOTE_PRECISION: any;
49
+ export declare const AMM_TIMES_PEG_TO_QUOTE_PRECISION_RATIO: any;
50
+ export declare const MARGIN_PRECISION: any;
51
+ export declare const BID_ASK_SPREAD_PRECISION: any;
52
+ export declare const LIQUIDATION_PCT_PRECISION: any;
53
+ export declare const FIVE_MINUTE: any;
54
+ export declare const ONE_HOUR: any;
55
+ export declare const ONE_YEAR: any;
58
56
  export declare const QUOTE_SPOT_MARKET_INDEX = 0;
59
- export declare const LAMPORTS_PRECISION: BN;
60
- export declare const LAMPORTS_EXP: BN;
61
- export declare const OPEN_ORDER_MARGIN_REQUIREMENT: BN;
62
- export declare const DEFAULT_REVENUE_SINCE_LAST_FUNDING_SPREAD_RETREAT: BN;
57
+ export declare const LAMPORTS_PRECISION: any;
58
+ export declare const LAMPORTS_EXP: any;
59
+ export declare const OPEN_ORDER_MARGIN_REQUIREMENT: any;
60
+ export declare const DEFAULT_REVENUE_SINCE_LAST_FUNDING_SPREAD_RETREAT: any;
@@ -176,6 +176,16 @@ exports.MainnetPerpMarkets = [
176
176
  launchTs: 1680808053000,
177
177
  oracleSource: __1.OracleSource.PYTH,
178
178
  },
179
+ {
180
+ fullName: 'Binance Coin',
181
+ category: ['Exchange'],
182
+ symbol: 'BNB-PERP',
183
+ baseAssetSymbol: 'BNB',
184
+ marketIndex: 8,
185
+ oracle: new web3_js_1.PublicKey('4CkQJBxhU8EZ2UjhigbtdaPbpTe6mqf811fipYBFbSYN'),
186
+ launchTs: 1680808053000,
187
+ oracleSource: __1.OracleSource.PYTH,
188
+ },
179
189
  ];
180
190
  exports.PerpMarkets = {
181
191
  devnet: exports.DevnetPerpMarkets,
@@ -1,4 +1,3 @@
1
- /// <reference types="bn.js" />
2
1
  import { PublicKey } from '@solana/web3.js';
3
2
  import { BN, DriftEnv, OracleSource } from '../';
4
3
  export type SpotMarketConfig = {
@@ -1,4 +1,3 @@
1
- /// <reference types="bn.js" />
2
1
  import { NodeList } from './NodeList';
3
2
  import { MarketType, BN, DriftClient, Order, SpotMarketAccount, PerpMarketAccount, OraclePriceData, SlotSubscriber, MarketTypeStr, StateAccount, UserMap, OrderRecord, OrderActionRecord } from '..';
4
3
  import { PublicKey } from '@solana/web3.js';
@@ -1,4 +1,3 @@
1
- /// <reference types="bn.js" />
2
1
  import { BN, OraclePriceData, Order } from '..';
3
2
  import { PublicKey } from '@solana/web3.js';
4
3
  export interface DLOBNode {
@@ -1,4 +1,3 @@
1
- /// <reference types="bn.js" />
2
1
  import { BN, MarketTypeStr, Order } from '..';
3
2
  import { PublicKey } from '@solana/web3.js';
4
3
  import { DLOBNode, DLOBNodeMap } from './DLOBNode';
@@ -1,5 +1,4 @@
1
1
  /// <reference types="node" />
2
- /// <reference types="bn.js" />
3
2
  import { AnchorProvider, BN, Program, ProgramAccount } from '@coral-xyz/anchor';
4
3
  import { StateAccount, IWallet, PositionDirection, UserAccount, PerpMarketAccount, OrderParams, Order, SpotMarketAccount, SpotPosition, MakerInfo, TakerInfo, OptionalOrderParams, ReferrerInfo, MarketType, TxParams, SerumV3FulfillmentConfigAccount, ReferrerNameAccount, OrderTriggerCondition, PerpMarketExtendedInfo, UserStatsAccount, ModifyOrderParams } from './types';
5
4
  import * as anchor from '@coral-xyz/anchor';
@@ -362,7 +361,11 @@ export declare class DriftClient {
362
361
  }): Promise<TransactionSignature>;
363
362
  requestRemoveInsuranceFundStake(marketIndex: number, amount: BN): Promise<TransactionSignature>;
364
363
  cancelRequestRemoveInsuranceFundStake(marketIndex: number): Promise<TransactionSignature>;
365
- removeInsuranceFundStake(marketIndex: number, collateralAccountPublicKey: PublicKey): Promise<TransactionSignature>;
364
+ removeInsuranceFundStake(marketIndex: number, collateralAccountPublicKey: PublicKey,
365
+ /**
366
+ * If unstaking SOL, it's required to pass in the amount
367
+ */
368
+ amount?: BN): Promise<TransactionSignature>;
366
369
  settleRevenueToInsuranceFund(marketIndex: number): Promise<TransactionSignature>;
367
370
  resolvePerpPnlDeficit(spotMarketIndex: number, perpMarketIndex: number, txParams?: TxParams): Promise<TransactionSignature>;
368
371
  getResolvePerpPnlDeficitIx(spotMarketIndex: number, perpMarketIndex: number): Promise<TransactionInstruction>;
@@ -2474,26 +2474,29 @@ class DriftClient {
2474
2474
  const { txSig } = await this.sendTransaction(tx, [], this.opts);
2475
2475
  return txSig;
2476
2476
  }
2477
- async removeInsuranceFundStake(marketIndex, collateralAccountPublicKey) {
2477
+ async removeInsuranceFundStake(marketIndex, collateralAccountPublicKey,
2478
+ /**
2479
+ * If unstaking SOL, it's required to pass in the amount
2480
+ */
2481
+ amount) {
2478
2482
  const tx = new web3_js_1.Transaction();
2479
2483
  const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
2480
2484
  const ifStakeAccountPublicKey = (0, pda_1.getInsuranceFundStakeAccountPublicKey)(this.program.programId, this.wallet.publicKey, marketIndex);
2481
- const tokenAccount = collateralAccountPublicKey;
2482
- // Todo wsol remove iF stake... how do we determine the amount?
2483
- // const amount = // get balance here...?
2484
- // const additionalSigners: Array<Signer> = [];
2485
- // const isSolMarket = spotMarketAccount.mint.equals(WRAPPED_SOL_MINT);
2486
- // const createWSOLTokenAccount =
2487
- // isSolMarket && collateralAccountPublicKey.equals(this.wallet.publicKey);
2488
- // if (createWSOLTokenAccount) {
2489
- // const { ixs, signers, pubkey } =
2490
- // await this.getWrappedSolAccountCreationIxs(amount, true);
2491
- // tokenAccount = pubkey;
2492
- // ixs.forEach((ix) => {
2493
- // tx.add(ix);
2494
- // });
2495
- // signers.forEach((signer) => additionalSigners.push(signer));
2496
- // }
2485
+ const additionalSigners = [];
2486
+ const isSolMarket = spotMarketAccount.mint.equals(spotMarkets_1.WRAPPED_SOL_MINT);
2487
+ const createWSOLTokenAccount = isSolMarket && collateralAccountPublicKey.equals(this.wallet.publicKey);
2488
+ let tokenAccount;
2489
+ if (createWSOLTokenAccount) {
2490
+ const { ixs, signers, pubkey } = await this.getWrappedSolAccountCreationIxs(amount, true);
2491
+ tokenAccount = pubkey;
2492
+ ixs.forEach((ix) => {
2493
+ tx.add(ix);
2494
+ });
2495
+ signers.forEach((signer) => additionalSigners.push(signer));
2496
+ }
2497
+ else {
2498
+ tokenAccount = collateralAccountPublicKey;
2499
+ }
2497
2500
  const remainingAccounts = this.getRemainingAccounts({
2498
2501
  userAccounts: [this.getUserAccount()],
2499
2502
  useMarketLastSlotCache: true,
@@ -2514,6 +2517,10 @@ class DriftClient {
2514
2517
  remainingAccounts,
2515
2518
  });
2516
2519
  tx.add(removeStakeIx);
2520
+ // Close the wrapped sol account at the end of the transaction
2521
+ if (createWSOLTokenAccount) {
2522
+ tx.add(spl_token_1.Token.createCloseAccountInstruction(spl_token_1.TOKEN_PROGRAM_ID, tokenAccount, this.wallet.publicKey, this.wallet.publicKey, []));
2523
+ }
2517
2524
  const { txSig } = await this.sendTransaction(tx, [], this.opts);
2518
2525
  return txSig;
2519
2526
  }
@@ -1,4 +1,3 @@
1
- /// <reference types="bn.js" />
2
1
  import { BN } from '@coral-xyz/anchor';
3
2
  export declare class BigNum {
4
3
  val: BN;
@@ -44,11 +43,11 @@ export declare class BigNum {
44
43
  gte(bn: BigNum | BN, ignorePrecision?: boolean): boolean;
45
44
  lte(bn: BigNum | BN, ignorePrecision?: boolean): boolean;
46
45
  eq(bn: BigNum | BN, ignorePrecision?: boolean): boolean;
47
- eqZero(): boolean;
48
- gtZero(): boolean;
49
- ltZero(): boolean;
50
- gteZero(): boolean;
51
- lteZero(): boolean;
46
+ eqZero(): any;
47
+ gtZero(): any;
48
+ ltZero(): any;
49
+ gteZero(): any;
50
+ lteZero(): any;
52
51
  abs(): BigNum;
53
52
  neg(): BigNum;
54
53
  toString: (base?: number | 'hex', length?: number) => string;
@@ -88,8 +87,8 @@ export declare class BigNum {
88
87
  toNotional(useTradePrecision?: boolean, precisionOverride?: number): string;
89
88
  toMillified(precision?: number, rounded?: boolean): string;
90
89
  toJSON(): {
91
- val: string;
92
- precision: string;
90
+ val: any;
91
+ precision: any;
93
92
  };
94
93
  isNeg(): boolean;
95
94
  isPos(): boolean;
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.25.0-beta.2",
2
+ "version": "2.25.1",
3
3
  "name": "drift",
4
4
  "instructions": [
5
5
  {
package/lib/math/amm.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- /// <reference types="bn.js" />
2
1
  import { BN } from '@coral-xyz/anchor';
3
2
  import { AMM, PositionDirection, SwapDirection, PerpMarketAccount } from '../types';
4
3
  import { OraclePriceData } from '../oracles/types';
@@ -87,7 +86,7 @@ export declare function getSwapDirection(inputAssetType: AssetType, positionDire
87
86
  * @param market
88
87
  * @returns cost : Precision PRICE_PRECISION
89
88
  */
90
- export declare function calculateTerminalPrice(market: PerpMarketAccount): BN;
89
+ export declare function calculateTerminalPrice(market: PerpMarketAccount): any;
91
90
  export declare function calculateMaxBaseAssetAmountToTrade(amm: AMM, limit_price: BN, direction: PositionDirection, oraclePriceData?: OraclePriceData, now?: BN): [BN, PositionDirection];
92
91
  export declare function calculateQuoteAssetAmountSwapped(quoteAssetReserves: BN, pegMultiplier: BN, swapDirection: SwapDirection): BN;
93
92
  export declare function calculateMaxBaseAssetAmountFillable(amm: AMM, orderDirection: PositionDirection): BN;
@@ -1,4 +1,3 @@
1
- /// <reference types="bn.js" />
2
1
  import { Order } from '../types';
3
2
  import { BN } from '../.';
4
3
  export declare function isAuctionComplete(order: Order, slot: number): boolean;
@@ -1,2 +1 @@
1
- import { BN } from '../';
2
- export declare const convertToNumber: (bigNumber: BN, precision?: BN) => number;
1
+ export declare const convertToNumber: (bigNumber: BN, precision?: BN) => any;
@@ -1,4 +1,3 @@
1
- /// <reference types="bn.js" />
2
1
  import { BN } from '@coral-xyz/anchor';
3
2
  import { PerpMarketAccount } from '../types';
4
3
  import { OraclePriceData } from '../oracles/types';
@@ -1,4 +1,3 @@
1
- /// <reference types="bn.js" />
2
1
  import { BN } from '../index';
3
2
  export declare function stakeAmountToShares(amount: BN, totalIfShares: BN, insuranceFundVaultBalance: BN): BN;
4
3
  export declare function unstakeSharesToAmount(nShares: BN, totalIfShares: BN, insuranceFundVaultBalance: BN): BN;
@@ -1,4 +1,3 @@
1
- /// <reference types="bn.js" />
2
1
  import { BN } from '@coral-xyz/anchor';
3
2
  import { OraclePriceData } from '../oracles/types';
4
3
  import { PerpMarketAccount, PerpPosition } from '..';
@@ -1,4 +1,3 @@
1
- /// <reference types="bn.js" />
2
1
  import { BN } from '@coral-xyz/anchor';
3
2
  import { PerpMarketAccount, PositionDirection, MarginCategory, SpotMarketAccount } from '../types';
4
3
  import { OraclePriceData } from '../oracles/types';
@@ -1,4 +1,3 @@
1
- /// <reference types="bn.js" />
2
1
  import { AMM, OracleGuardRails } from '../types';
3
2
  import { OraclePriceData } from '../oracles/types';
4
3
  import { BN, HistoricalOracleData, PerpMarketAccount } from '../index';
@@ -1,4 +1,3 @@
1
- /// <reference types="bn.js" />
2
1
  import { User } from '../user';
3
2
  import { PerpMarketAccount, AMM, Order } from '../types';
4
3
  import { BN } from '@coral-xyz/anchor';
@@ -1,4 +1,3 @@
1
- /// <reference types="bn.js" />
2
1
  import { BN, SpotMarketAccount } from '../';
3
2
  import { OraclePriceData } from '../oracles/types';
4
3
  import { PerpMarketAccount, PositionDirection, PerpPosition } from '../types';
@@ -1,4 +1,3 @@
1
- /// <reference types="bn.js" />
2
1
  import { BN } from '@coral-xyz/anchor';
3
2
  import { AMM } from '../types';
4
3
  /**
@@ -1,4 +1,3 @@
1
- /// <reference types="bn.js" />
2
1
  import { SpotMarketAccount, SpotBalanceType, MarginCategory } from '../types';
3
2
  import { BN } from '@coral-xyz/anchor';
4
3
  import { OraclePriceData } from '../oracles/types';
@@ -1,4 +1,3 @@
1
- /// <reference types="bn.js" />
2
1
  import { BN } from '@coral-xyz/anchor';
3
2
  import { MarginCategory, SpotBalanceType, SpotMarketAccount } from '../types';
4
3
  export declare function castNumberToSpotPrecision(value: number, spotMarket: SpotMarketAccount): BN;
@@ -1,4 +1,3 @@
1
- /// <reference types="bn.js" />
2
1
  import { SpotMarketAccount, SpotPosition } from '../types';
3
2
  import { BN } from '@coral-xyz/anchor';
4
3
  import { OraclePriceData } from '../oracles/types';
@@ -1,4 +1,3 @@
1
- /// <reference types="bn.js" />
2
1
  import { PerpMarketAccount, PositionDirection, SpotMarketAccount } from '../types';
3
2
  import { BN } from '@coral-xyz/anchor';
4
3
  import { AssetType } from './amm';
@@ -1,4 +1,3 @@
1
- /// <reference types="bn.js" />
2
1
  import { BN } from '../';
3
2
  export declare function clampBN(x: BN, min: BN, max: BN): BN;
4
3
  export declare const squareRootBN: (n: BN) => BN;
@@ -1,4 +1,3 @@
1
- /// <reference types="bn.js" />
2
1
  /// <reference types="node" />
3
2
  import { Connection, PublicKey } from '@solana/web3.js';
4
3
  import { OracleClient, OraclePriceData } from './types';
@@ -7,7 +6,7 @@ export declare class PythClient implements OracleClient {
7
6
  private connection;
8
7
  private multiple;
9
8
  private stableCoin;
10
- constructor(connection: Connection, multiple?: BN, stableCoin?: boolean);
9
+ constructor(connection: Connection, multiple?: any, stableCoin?: boolean);
11
10
  getOraclePriceData(pricePublicKey: PublicKey): Promise<OraclePriceData>;
12
11
  getOraclePriceDataFromBuffer(buffer: Buffer): OraclePriceData;
13
12
  }
@@ -1,4 +1,3 @@
1
- /// <reference types="bn.js" />
2
1
  /// <reference types="node" />
3
2
  import { BN } from '@coral-xyz/anchor';
4
3
  import { PublicKey } from '@solana/web3.js';
@@ -1,4 +1,3 @@
1
- /// <reference types="bn.js" />
2
1
  import { OptionalOrderParams, OrderTriggerCondition } from './types';
3
2
  import { BN } from '@coral-xyz/anchor';
4
3
  export declare function getLimitOrderParams(params: Omit<OptionalOrderParams, 'orderType' | 'marketType'> & {
@@ -1,4 +1,3 @@
1
- /// <reference types="bn.js" />
2
1
  import { Connection, PublicKey } from '@solana/web3.js';
3
2
  import { BulkAccountLoader } from '../accounts/bulkAccountLoader';
4
3
  import { Market, Orderbook } from '@project-serum/serum';
@@ -1,4 +1,3 @@
1
- /// <reference types="bn.js" />
2
1
  import * as anchor from '@coral-xyz/anchor';
3
2
  import { AnchorProvider, Program } from '@coral-xyz/anchor';
4
3
  import { AccountInfo } from '@solana/spl-token';
package/lib/types.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- /// <reference types="bn.js" />
2
1
  import { PublicKey, Transaction } from '@solana/web3.js';
3
2
  import { BN } from '.';
4
3
  export declare enum ExchangeStatus {
package/lib/user.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  /// <reference types="node" />
2
- /// <reference types="bn.js" />
3
2
  import { PublicKey } from '@solana/web3.js';
4
3
  import { EventEmitter } from 'events';
5
4
  import StrictEventEmitter from 'strict-event-emitter-types';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.25.0-beta.2",
3
+ "version": "2.25.1",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.assert = void 0;
4
+ function assert(condition, error) {
5
+ if (!condition) {
6
+ throw new Error(error || 'Unspecified AssertionError');
7
+ }
8
+ }
9
+ exports.assert = assert;
@@ -187,6 +187,16 @@ export const MainnetPerpMarkets: PerpMarketConfig[] = [
187
187
  launchTs: 1680808053000,
188
188
  oracleSource: OracleSource.PYTH,
189
189
  },
190
+ {
191
+ fullName: 'Binance Coin',
192
+ category: ['Exchange'],
193
+ symbol: 'BNB-PERP',
194
+ baseAssetSymbol: 'BNB',
195
+ marketIndex: 8,
196
+ oracle: new PublicKey('4CkQJBxhU8EZ2UjhigbtdaPbpTe6mqf811fipYBFbSYN'),
197
+ launchTs: 1680808053000,
198
+ oracleSource: OracleSource.PYTH,
199
+ },
190
200
  ];
191
201
 
192
202
  export const PerpMarkets: { [key in DriftEnv]: PerpMarketConfig[] } = {
@@ -4404,7 +4404,11 @@ export class DriftClient {
4404
4404
 
4405
4405
  public async removeInsuranceFundStake(
4406
4406
  marketIndex: number,
4407
- collateralAccountPublicKey: PublicKey
4407
+ collateralAccountPublicKey: PublicKey,
4408
+ /**
4409
+ * If unstaking SOL, it's required to pass in the amount
4410
+ */
4411
+ amount?: BN
4408
4412
  ): Promise<TransactionSignature> {
4409
4413
  const tx = new Transaction();
4410
4414
  const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
@@ -4413,26 +4417,26 @@ export class DriftClient {
4413
4417
  this.wallet.publicKey,
4414
4418
  marketIndex
4415
4419
  );
4416
- const tokenAccount = collateralAccountPublicKey;
4417
4420
 
4418
- // Todo wsol remove iF stake... how do we determine the amount?
4419
- // const amount = // get balance here...?
4421
+ const additionalSigners: Array<Signer> = [];
4422
+ const isSolMarket = spotMarketAccount.mint.equals(WRAPPED_SOL_MINT);
4423
+ const createWSOLTokenAccount =
4424
+ isSolMarket && collateralAccountPublicKey.equals(this.wallet.publicKey);
4420
4425
 
4421
- // const additionalSigners: Array<Signer> = [];
4422
- // const isSolMarket = spotMarketAccount.mint.equals(WRAPPED_SOL_MINT);
4423
- // const createWSOLTokenAccount =
4424
- // isSolMarket && collateralAccountPublicKey.equals(this.wallet.publicKey);
4426
+ let tokenAccount;
4425
4427
 
4426
- // if (createWSOLTokenAccount) {
4427
- // const { ixs, signers, pubkey } =
4428
- // await this.getWrappedSolAccountCreationIxs(amount, true);
4429
- // tokenAccount = pubkey;
4430
- // ixs.forEach((ix) => {
4431
- // tx.add(ix);
4432
- // });
4428
+ if (createWSOLTokenAccount) {
4429
+ const { ixs, signers, pubkey } =
4430
+ await this.getWrappedSolAccountCreationIxs(amount, true);
4431
+ tokenAccount = pubkey;
4432
+ ixs.forEach((ix) => {
4433
+ tx.add(ix);
4434
+ });
4433
4435
 
4434
- // signers.forEach((signer) => additionalSigners.push(signer));
4435
- // }
4436
+ signers.forEach((signer) => additionalSigners.push(signer));
4437
+ } else {
4438
+ tokenAccount = collateralAccountPublicKey;
4439
+ }
4436
4440
 
4437
4441
  const remainingAccounts = this.getRemainingAccounts({
4438
4442
  userAccounts: [this.getUserAccount()],
@@ -4458,6 +4462,19 @@ export class DriftClient {
4458
4462
 
4459
4463
  tx.add(removeStakeIx);
4460
4464
 
4465
+ // Close the wrapped sol account at the end of the transaction
4466
+ if (createWSOLTokenAccount) {
4467
+ tx.add(
4468
+ Token.createCloseAccountInstruction(
4469
+ TOKEN_PROGRAM_ID,
4470
+ tokenAccount,
4471
+ this.wallet.publicKey,
4472
+ this.wallet.publicKey,
4473
+ []
4474
+ )
4475
+ );
4476
+ }
4477
+
4461
4478
  const { txSig } = await this.sendTransaction(tx, [], this.opts);
4462
4479
  return txSig;
4463
4480
  }
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.25.0-beta.2",
2
+ "version": "2.25.1",
3
3
  "name": "drift",
4
4
  "instructions": [
5
5
  {
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseTokenAccount = void 0;
4
+ const spl_token_1 = require("@solana/spl-token");
5
+ const web3_js_1 = require("@solana/web3.js");
6
+ function parseTokenAccount(data) {
7
+ const accountInfo = spl_token_1.AccountLayout.decode(data);
8
+ accountInfo.mint = new web3_js_1.PublicKey(accountInfo.mint);
9
+ accountInfo.owner = new web3_js_1.PublicKey(accountInfo.owner);
10
+ accountInfo.amount = spl_token_1.u64.fromBuffer(accountInfo.amount);
11
+ if (accountInfo.delegateOption === 0) {
12
+ accountInfo.delegate = null;
13
+ // eslint-disable-next-line new-cap
14
+ accountInfo.delegatedAmount = new spl_token_1.u64(0);
15
+ }
16
+ else {
17
+ accountInfo.delegate = new web3_js_1.PublicKey(accountInfo.delegate);
18
+ accountInfo.delegatedAmount = spl_token_1.u64.fromBuffer(accountInfo.delegatedAmount);
19
+ }
20
+ accountInfo.isInitialized = accountInfo.state !== 0;
21
+ accountInfo.isFrozen = accountInfo.state === 2;
22
+ if (accountInfo.isNativeOption === 1) {
23
+ accountInfo.rentExemptReserve = spl_token_1.u64.fromBuffer(accountInfo.isNative);
24
+ accountInfo.isNative = true;
25
+ }
26
+ else {
27
+ accountInfo.rentExemptReserve = null;
28
+ accountInfo.isNative = false;
29
+ }
30
+ if (accountInfo.closeAuthorityOption === 0) {
31
+ accountInfo.closeAuthority = null;
32
+ }
33
+ else {
34
+ accountInfo.closeAuthority = new web3_js_1.PublicKey(accountInfo.closeAuthority);
35
+ }
36
+ return accountInfo;
37
+ }
38
+ exports.parseTokenAccount = parseTokenAccount;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.findComputeUnitConsumption = void 0;
13
+ function findComputeUnitConsumption(programId, connection, txSignature, commitment = 'confirmed') {
14
+ return __awaiter(this, void 0, void 0, function* () {
15
+ const tx = yield connection.getTransaction(txSignature, { commitment });
16
+ const computeUnits = [];
17
+ const regex = new RegExp(`Program ${programId.toString()} consumed ([0-9]{0,6}) of ([0-9]{0,7}) compute units`);
18
+ tx.meta.logMessages.forEach((logMessage) => {
19
+ const match = logMessage.match(regex);
20
+ if (match && match[1]) {
21
+ computeUnits.push(match[1]);
22
+ }
23
+ });
24
+ return computeUnits;
25
+ });
26
+ }
27
+ exports.findComputeUnitConsumption = findComputeUnitConsumption;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getTokenAddress = void 0;
4
+ const spl_token_1 = require("@solana/spl-token");
5
+ const web3_js_1 = require("@solana/web3.js");
6
+ const getTokenAddress = (mintAddress, userPubKey) => {
7
+ return spl_token_1.Token.getAssociatedTokenAddress(spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, spl_token_1.TOKEN_PROGRAM_ID, new web3_js_1.PublicKey(mintAddress), new web3_js_1.PublicKey(userPubKey));
8
+ };
9
+ exports.getTokenAddress = getTokenAddress;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.promiseTimeout = void 0;
4
+ function promiseTimeout(promise, timeoutMs) {
5
+ let timeoutId;
6
+ const timeoutPromise = new Promise((resolve) => {
7
+ timeoutId = setTimeout(() => resolve(null), timeoutMs);
8
+ });
9
+ return Promise.race([promise, timeoutPromise]).then((result) => {
10
+ clearTimeout(timeoutId);
11
+ return result;
12
+ });
13
+ }
14
+ exports.promiseTimeout = promiseTimeout;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.estimateTps = void 0;
13
+ function estimateTps(programId, connection, failed) {
14
+ return __awaiter(this, void 0, void 0, function* () {
15
+ let signatures = yield connection.getSignaturesForAddress(programId, undefined, 'finalized');
16
+ if (failed) {
17
+ signatures = signatures.filter((signature) => signature.err);
18
+ }
19
+ const numberOfSignatures = signatures.length;
20
+ if (numberOfSignatures === 0) {
21
+ return 0;
22
+ }
23
+ return (numberOfSignatures /
24
+ (signatures[0].blockTime - signatures[numberOfSignatures - 1].blockTime));
25
+ });
26
+ }
27
+ exports.estimateTps = estimateTps;