@drift-labs/sdk 2.28.0-beta.4 → 2.28.0-beta.5

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/lib/config.d.ts CHANGED
@@ -14,6 +14,7 @@ type DriftConfig = {
14
14
  MARKET_LOOKUP_TABLE: string;
15
15
  };
16
16
  export type DriftEnv = 'devnet' | 'mainnet-beta';
17
+ export declare const DRIFT_PROGRAM_ID = "dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH";
17
18
  export declare const configs: {
18
19
  [key in DriftEnv]: DriftConfig;
19
20
  };
package/lib/config.js CHANGED
@@ -1,13 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getMarketsAndOraclesForSubscription = exports.initialize = exports.getConfig = exports.configs = void 0;
3
+ exports.getMarketsAndOraclesForSubscription = exports.initialize = exports.getConfig = exports.configs = exports.DRIFT_PROGRAM_ID = void 0;
4
4
  const perpMarkets_1 = require("./constants/perpMarkets");
5
5
  const spotMarkets_1 = require("./constants/spotMarkets");
6
+ exports.DRIFT_PROGRAM_ID = 'dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH';
6
7
  exports.configs = {
7
8
  devnet: {
8
9
  ENV: 'devnet',
9
10
  PYTH_ORACLE_MAPPING_ADDRESS: 'BmA9Z6FjioHJPpjT39QazZyhDRUdZy2ezwx4GiDdE2u2',
10
- DRIFT_PROGRAM_ID: 'dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH',
11
+ DRIFT_PROGRAM_ID: exports.DRIFT_PROGRAM_ID,
11
12
  USDC_MINT_ADDRESS: '8zGuJQqwhZafTah7Uc7Z4tXRnguqkn5KLFAP8oV6PHe2',
12
13
  SERUM_V3: 'DESVgJVGajEgKGXhb6XmqDHGz3VjdgP7rEVESBgxmroY',
13
14
  PHOENIX: 'PhoeNiXZ8ByJGLkxNfZRnkUfjvmuYqLR89jjFHGqdXY',
@@ -19,7 +20,7 @@ exports.configs = {
19
20
  'mainnet-beta': {
20
21
  ENV: 'mainnet-beta',
21
22
  PYTH_ORACLE_MAPPING_ADDRESS: 'AHtgzX45WTKfkPG53L6WYhGEXwQkN1BVknET3sVsLL8J',
22
- DRIFT_PROGRAM_ID: 'dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH',
23
+ DRIFT_PROGRAM_ID: exports.DRIFT_PROGRAM_ID,
23
24
  USDC_MINT_ADDRESS: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
24
25
  SERUM_V3: 'srmqPvymJeFKQ4zGQed1GFppgkRHL9kaELCbyksJtPX',
25
26
  PHOENIX: 'PhoeNiXZ8ByJGLkxNfZRnkUfjvmuYqLR89jjFHGqdXY',
@@ -104,6 +104,16 @@ exports.DevnetPerpMarkets = [
104
104
  launchTs: 1683125906000,
105
105
  oracleSource: __1.OracleSource.PYTH,
106
106
  },
107
+ {
108
+ fullName: 'Pepe',
109
+ category: ['Meme'],
110
+ symbol: '1MPEPE-PERP',
111
+ baseAssetSymbol: '1MPEPE',
112
+ marketIndex: 10,
113
+ oracle: new web3_js_1.PublicKey('Gz9RfgDeAFSsH7BHDGyNTgCik74rjNwsodJpsCizzmkj'),
114
+ launchTs: 1683125906000,
115
+ oracleSource: __1.OracleSource.PYTH_1M,
116
+ },
107
117
  ];
108
118
  exports.MainnetPerpMarkets = [
109
119
  {
@@ -206,6 +216,16 @@ exports.MainnetPerpMarkets = [
206
216
  launchTs: 1683125906000,
207
217
  oracleSource: __1.OracleSource.PYTH,
208
218
  },
219
+ {
220
+ fullName: 'Pepe',
221
+ category: ['Meme'],
222
+ symbol: '1MPEPE-PERP',
223
+ baseAssetSymbol: '1MPEPE',
224
+ marketIndex: 10,
225
+ oracle: new web3_js_1.PublicKey('FSfxunDmjjbDV2QxpyxFCAPKmYJHSLnLuvQXDLkMzLBm'),
226
+ launchTs: 1683125906000,
227
+ oracleSource: __1.OracleSource.PYTH_1M,
228
+ },
209
229
  ];
210
230
  exports.PerpMarkets = {
211
231
  devnet: exports.DevnetPerpMarkets,
@@ -2,7 +2,7 @@
2
2
  import { AnchorProvider, BN, Program, ProgramAccount } from '@coral-xyz/anchor';
3
3
  import { StateAccount, IWallet, PositionDirection, UserAccount, PerpMarketAccount, OrderParams, Order, SpotMarketAccount, SpotPosition, MakerInfo, TakerInfo, OptionalOrderParams, ReferrerInfo, MarketType, TxParams, SerumV3FulfillmentConfigAccount, ReferrerNameAccount, OrderTriggerCondition, PerpMarketExtendedInfo, UserStatsAccount, ModifyOrderParams, PhoenixV1FulfillmentConfigAccount } from './types';
4
4
  import * as anchor from '@coral-xyz/anchor';
5
- import { Connection, PublicKey, TransactionSignature, ConfirmOptions, Transaction, TransactionInstruction, AccountMeta, Signer, AddressLookupTableAccount } from '@solana/web3.js';
5
+ import { Connection, PublicKey, TransactionSignature, ConfirmOptions, Transaction, TransactionInstruction, AccountMeta, Signer, AddressLookupTableAccount, TransactionVersion, VersionedTransaction } from '@solana/web3.js';
6
6
  import { TokenFaucet } from './tokenFaucet';
7
7
  import { EventEmitter } from 'events';
8
8
  import StrictEventEmitter from 'strict-event-emitter-types';
@@ -47,6 +47,7 @@ export declare class DriftClient {
47
47
  includeDelegates?: boolean;
48
48
  authoritySubAccountMap?: Map<string, number[]>;
49
49
  skipLoadUsers?: boolean;
50
+ txVersion: TransactionVersion;
50
51
  get isSubscribed(): boolean;
51
52
  set isSubscribed(val: boolean);
52
53
  constructor(config: DriftClientConfig);
@@ -105,6 +106,7 @@ export declare class DriftClient {
105
106
  initializeUserAccount(subAccountId?: number, name?: string, referrerInfo?: ReferrerInfo): Promise<[TransactionSignature, PublicKey]>;
106
107
  getInitializeUserInstructions(subAccountId?: number, name?: string, referrerInfo?: ReferrerInfo): Promise<[PublicKey, TransactionInstruction]>;
107
108
  getInitializeUserStatsIx(): Promise<TransactionInstruction>;
109
+ getNextSubAccountId(): Promise<number>;
108
110
  initializeReferrerName(name: string): Promise<TransactionSignature>;
109
111
  updateUserName(name: string, subAccountId?: number): Promise<TransactionSignature>;
110
112
  updateUserCustomMarginRatio(marginRatio: number, subAccountId?: number): Promise<TransactionSignature>;
@@ -133,7 +135,28 @@ export declare class DriftClient {
133
135
  getUserAccountAndSlot(subAccountId?: number): DataAndSlot<UserAccount> | undefined;
134
136
  getSpotPosition(marketIndex: number): SpotPosition | undefined;
135
137
  getQuoteAssetTokenAmount(): BN;
138
+ /**
139
+ * Returns the token amount for a given market. The spot market precision is based on the token mint decimals.
140
+ * Positive if it is a deposit, negative if it is a borrow.
141
+ * @param marketIndex
142
+ */
136
143
  getTokenAmount(marketIndex: number): BN;
144
+ /**
145
+ * Converts an amount to the spot precision for a given market. The spot market precision is based on the token mint decimals.
146
+ * @param marketIndex
147
+ * @param amount
148
+ */
149
+ convertToSpotPrecision(marketIndex: number, amount: BN | number): BN;
150
+ /**
151
+ * Converts an amount to the perp precision. The perp market precision is {@link BASE_PRECISION} (1e9).
152
+ * @param amount
153
+ */
154
+ convertToPerpPrecision(amount: BN | number): BN;
155
+ /**
156
+ * Converts an amount to the price precision. The perp market precision is {@link PRICE_PRECISION} (1e6).
157
+ * @param amount
158
+ */
159
+ convertToPricePrecision(amount: BN | number): BN;
137
160
  getRemainingAccounts(params: RemainingAccountParams): AccountMeta[];
138
161
  getRemainingAccountMapsForUsers(userAccounts: UserAccount[]): {
139
162
  oracleAccountMap: Map<string, AccountMeta>;
@@ -142,7 +165,22 @@ export declare class DriftClient {
142
165
  };
143
166
  getOrder(orderId: number): Order | undefined;
144
167
  getOrderByUserId(userOrderId: number): Order | undefined;
145
- deposit(amount: BN, marketIndex: number, collateralAccountPublicKey: PublicKey, subAccountId?: number, reduceOnly?: boolean): Promise<TransactionSignature>;
168
+ /**
169
+ * Get the associated token address for the given spot market
170
+ * @param marketIndex
171
+ * @param useNative
172
+ */
173
+ getAssociatedTokenAccount(marketIndex: number, useNative?: boolean): Promise<PublicKey>;
174
+ /**
175
+ * Deposit funds into the given spot market
176
+ *
177
+ * @param amount
178
+ * @param marketIndex
179
+ * @param associatedTokenAccount can be the wallet public key if using native sol
180
+ * @param subAccountId
181
+ * @param reduceOnly
182
+ */
183
+ deposit(amount: BN, marketIndex: number, associatedTokenAccount: PublicKey, subAccountId?: number, reduceOnly?: boolean): Promise<TransactionSignature>;
146
184
  getDepositInstruction(amount: BN, marketIndex: number, userTokenAccount: PublicKey, subAccountId?: number, reduceOnly?: boolean, userInitialized?: boolean): Promise<TransactionInstruction>;
147
185
  private checkIfAccountExists;
148
186
  private getWrappedSolAccountCreationIxs;
@@ -159,8 +197,23 @@ export declare class DriftClient {
159
197
  */
160
198
  initializeUserAccountAndDepositCollateral(amount: BN, userTokenAccount: PublicKey, marketIndex?: number, subAccountId?: number, name?: string, fromSubAccountId?: number, referrerInfo?: ReferrerInfo, txParams?: TxParams): Promise<[TransactionSignature, PublicKey]>;
161
199
  initializeUserAccountForDevnet(subAccountId: number, name: string, marketIndex: number, tokenFaucet: TokenFaucet, amount: BN, referrerInfo?: ReferrerInfo): Promise<[TransactionSignature, PublicKey]>;
162
- withdraw(amount: BN, marketIndex: number, userTokenAccount: PublicKey, reduceOnly?: boolean): Promise<TransactionSignature>;
200
+ /**
201
+ * Withdraws from a user account. If deposit doesn't already exist, creates a borrow
202
+ * @param amount
203
+ * @param marketIndex
204
+ * @param associatedTokenAddress - the token account to withdraw to. can be the wallet public key if using native sol
205
+ * @param reduceOnly
206
+ */
207
+ withdraw(amount: BN, marketIndex: number, associatedTokenAddress: PublicKey, reduceOnly?: boolean): Promise<TransactionSignature>;
163
208
  getWithdrawIx(amount: BN, marketIndex: number, userTokenAccount: PublicKey, reduceOnly?: boolean): Promise<TransactionInstruction>;
209
+ /**
210
+ * Withdraws from the fromSubAccount and deposits into the toSubAccount
211
+ * @param amount
212
+ * @param marketIndex
213
+ * @param fromSubAccountId
214
+ * @param toSubAccountId
215
+ * @param txParams
216
+ */
164
217
  transferDeposit(amount: BN, marketIndex: number, fromSubAccountId: number, toSubAccountId: number, txParams?: TxParams): Promise<TransactionSignature>;
165
218
  getTransferDepositIx(amount: BN, marketIndex: number, fromSubAccountId: number, toSubAccountId: number): Promise<TransactionInstruction>;
166
219
  updateSpotMarketCumulativeInterest(marketIndex: number, txParams?: TxParams): Promise<TransactionSignature>;
@@ -173,6 +226,9 @@ export declare class DriftClient {
173
226
  getRemovePerpLpSharesIx(marketIndex: number, sharesToBurn?: BN): Promise<TransactionInstruction>;
174
227
  addPerpLpShares(amount: BN, marketIndex: number, txParams?: TxParams): Promise<TransactionSignature>;
175
228
  getAddPerpLpSharesIx(amount: BN, marketIndex: number): Promise<TransactionInstruction>;
229
+ /**
230
+ * @deprecated use {@link placePerpOrder} or {@link placeAndTakePerpOrder} instead
231
+ */
176
232
  openPosition(direction: PositionDirection, amount: BN, marketIndex: number, limitPrice?: BN): Promise<TransactionSignature>;
177
233
  sendSignedTx(tx: Transaction): Promise<TransactionSignature>;
178
234
  /**
@@ -233,9 +289,7 @@ export declare class DriftClient {
233
289
  placeAndMakeSpotOrder(orderParams: OptionalOrderParams, takerInfo: TakerInfo, fulfillmentConfig?: SerumV3FulfillmentConfigAccount, referrerInfo?: ReferrerInfo, txParams?: TxParams): Promise<TransactionSignature>;
234
290
  getPlaceAndMakeSpotOrderIx(orderParams: OptionalOrderParams, takerInfo: TakerInfo, fulfillmentConfig?: SerumV3FulfillmentConfigAccount, referrerInfo?: ReferrerInfo): Promise<TransactionInstruction>;
235
291
  /**
236
- * Close an entire position. If you want to reduce a position, use the {@link openPosition} method in the opposite direction of the current position.
237
- * @param marketIndex
238
- * @returns
292
+ * @deprecated use {@link placePerpOrder} or {@link placeAndTakePerpOrder} instead
239
293
  */
240
294
  closePosition(marketIndex: number, limitPrice?: BN): Promise<TransactionSignature>;
241
295
  /**
@@ -395,6 +449,7 @@ export declare class DriftClient {
395
449
  marketIndex: number;
396
450
  marketType: MarketType;
397
451
  } | undefined;
398
- sendTransaction(tx: Transaction, additionalSigners?: Array<Signer>, opts?: ConfirmOptions, preSigned?: boolean): Promise<TxSigAndSlot>;
452
+ sendTransaction(tx: Transaction | VersionedTransaction, additionalSigners?: Array<Signer>, opts?: ConfirmOptions, preSigned?: boolean): Promise<TxSigAndSlot>;
453
+ buildTransaction(instructions: TransactionInstruction | TransactionInstruction[], txParams?: TxParams): Promise<Transaction | VersionedTransaction>;
399
454
  }
400
455
  export {};