@drift-labs/sdk 2.88.0-beta.1 → 2.88.0-beta.3

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.88.0-beta.1
1
+ 2.88.0-beta.3
@@ -301,6 +301,16 @@ exports.MainnetSpotMarkets = [
301
301
  precisionExp: numericConstants_1.NINE,
302
302
  launchTs: 1721316817000,
303
303
  },
304
+ {
305
+ symbol: 'PYUSD',
306
+ marketIndex: 22,
307
+ oracle: new web3_js_1.PublicKey('HpMoKp3TCd3QT4MWYUKk2zCBwmhr5Df45fB6wdxYqEeh'),
308
+ oracleSource: __1.OracleSource.PYTH_STABLE_COIN_PULL,
309
+ mint: new web3_js_1.PublicKey('2b1kV6DkPAnxd5ixfnxCpjxmKwqjjaYmCZfHsFu24GXo'),
310
+ precision: new __1.BN(10).pow(numericConstants_1.SIX),
311
+ precisionExp: numericConstants_1.SIX,
312
+ pythFeedId: '0xc1da1b73d7f01e7ddd54b3766cf7fcd644395ad14f70aa706ec5384c59e76692',
313
+ },
304
314
  ];
305
315
  exports.SpotMarkets = {
306
316
  devnet: exports.DevnetSpotMarkets,
@@ -228,8 +228,9 @@ export declare class DriftClient {
228
228
  * Get the associated token address for the given spot market
229
229
  * @param marketIndex
230
230
  * @param useNative
231
+ * @param tokenProgram
231
232
  */
232
- getAssociatedTokenAccount(marketIndex: number, useNative?: boolean): Promise<PublicKey>;
233
+ getAssociatedTokenAccount(marketIndex: number, useNative?: boolean, tokenProgram?: anchor.web3.PublicKey): Promise<PublicKey>;
233
234
  createAssociatedTokenAccountIdempotentInstruction(account: PublicKey, payer: PublicKey, owner: PublicKey, mint: PublicKey, tokenProgram?: anchor.web3.PublicKey): TransactionInstruction;
234
235
  createDepositTxn(amount: BN, marketIndex: number, associatedTokenAccount: PublicKey, subAccountId?: number, reduceOnly?: boolean, txParams?: TxParams): Promise<VersionedTransaction | Transaction>;
235
236
  /**
@@ -1053,14 +1053,15 @@ class DriftClient {
1053
1053
  * Get the associated token address for the given spot market
1054
1054
  * @param marketIndex
1055
1055
  * @param useNative
1056
+ * @param tokenProgram
1056
1057
  */
1057
- async getAssociatedTokenAccount(marketIndex, useNative = true) {
1058
+ async getAssociatedTokenAccount(marketIndex, useNative = true, tokenProgram = spl_token_1.TOKEN_PROGRAM_ID) {
1058
1059
  const spotMarket = this.getSpotMarketAccount(marketIndex);
1059
1060
  if (useNative && spotMarket.mint.equals(spotMarkets_1.WRAPPED_SOL_MINT)) {
1060
1061
  return this.wallet.publicKey;
1061
1062
  }
1062
1063
  const mint = spotMarket.mint;
1063
- return await (0, spl_token_1.getAssociatedTokenAddress)(mint, this.wallet.publicKey);
1064
+ return await (0, spl_token_1.getAssociatedTokenAddress)(mint, this.wallet.publicKey, undefined, tokenProgram);
1064
1065
  }
1065
1066
  createAssociatedTokenAccountIdempotentInstruction(account, payer, owner, mint, tokenProgram = spl_token_1.TOKEN_PROGRAM_ID) {
1066
1067
  return new web3_js_1.TransactionInstruction({
@@ -2373,18 +2374,18 @@ class DriftClient {
2373
2374
  });
2374
2375
  const preInstructions = [];
2375
2376
  if (!outAssociatedTokenAccount) {
2376
- outAssociatedTokenAccount = await this.getAssociatedTokenAccount(outMarket.marketIndex, false);
2377
+ const tokenProgram = this.getTokenProgramForSpotMarket(outMarket);
2378
+ outAssociatedTokenAccount = await this.getAssociatedTokenAccount(outMarket.marketIndex, false, tokenProgram);
2377
2379
  const accountInfo = await this.connection.getAccountInfo(outAssociatedTokenAccount);
2378
2380
  if (!accountInfo) {
2379
- const tokenProgram = this.getTokenProgramForSpotMarket(outMarket);
2380
2381
  preInstructions.push(this.createAssociatedTokenAccountIdempotentInstruction(outAssociatedTokenAccount, this.provider.wallet.publicKey, this.provider.wallet.publicKey, outMarket.mint, tokenProgram));
2381
2382
  }
2382
2383
  }
2383
2384
  if (!inAssociatedTokenAccount) {
2384
- inAssociatedTokenAccount = await this.getAssociatedTokenAccount(inMarket.marketIndex, false);
2385
+ const tokenProgram = this.getTokenProgramForSpotMarket(outMarket);
2386
+ inAssociatedTokenAccount = await this.getAssociatedTokenAccount(inMarket.marketIndex, false, tokenProgram);
2385
2387
  const accountInfo = await this.connection.getAccountInfo(inAssociatedTokenAccount);
2386
2388
  if (!accountInfo) {
2387
- const tokenProgram = this.getTokenProgramForSpotMarket(outMarket);
2388
2389
  preInstructions.push(this.createAssociatedTokenAccountIdempotentInstruction(inAssociatedTokenAccount, this.provider.wallet.publicKey, this.provider.wallet.publicKey, inMarket.mint, tokenProgram));
2389
2390
  }
2390
2391
  }
@@ -2440,17 +2441,19 @@ class DriftClient {
2440
2441
  });
2441
2442
  const preInstructions = [];
2442
2443
  if (!outAssociatedTokenAccount) {
2443
- outAssociatedTokenAccount = await this.getAssociatedTokenAccount(outMarket.marketIndex, false);
2444
+ const tokenProgram = this.getTokenProgramForSpotMarket(outMarket);
2445
+ outAssociatedTokenAccount = await this.getAssociatedTokenAccount(outMarket.marketIndex, false, tokenProgram);
2444
2446
  const accountInfo = await this.connection.getAccountInfo(outAssociatedTokenAccount);
2445
2447
  if (!accountInfo) {
2446
- preInstructions.push(this.createAssociatedTokenAccountIdempotentInstruction(outAssociatedTokenAccount, this.provider.wallet.publicKey, this.provider.wallet.publicKey, outMarket.mint));
2448
+ preInstructions.push(this.createAssociatedTokenAccountIdempotentInstruction(outAssociatedTokenAccount, this.provider.wallet.publicKey, this.provider.wallet.publicKey, outMarket.mint, tokenProgram));
2447
2449
  }
2448
2450
  }
2449
2451
  if (!inAssociatedTokenAccount) {
2450
- inAssociatedTokenAccount = await this.getAssociatedTokenAccount(inMarket.marketIndex, false);
2452
+ const tokenProgram = this.getTokenProgramForSpotMarket(inMarket);
2453
+ inAssociatedTokenAccount = await this.getAssociatedTokenAccount(inMarket.marketIndex, false, tokenProgram);
2451
2454
  const accountInfo = await this.connection.getAccountInfo(inAssociatedTokenAccount);
2452
2455
  if (!accountInfo) {
2453
- preInstructions.push(this.createAssociatedTokenAccountIdempotentInstruction(inAssociatedTokenAccount, this.provider.wallet.publicKey, this.provider.wallet.publicKey, inMarket.mint));
2456
+ preInstructions.push(this.createAssociatedTokenAccountIdempotentInstruction(inAssociatedTokenAccount, this.provider.wallet.publicKey, this.provider.wallet.publicKey, inMarket.mint, tokenProgram));
2454
2457
  }
2455
2458
  }
2456
2459
  const { beginSwapIx, endSwapIx } = await this.getSwapIx({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.88.0-beta.1",
3
+ "version": "2.88.0-beta.3",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -373,6 +373,17 @@ export const MainnetSpotMarkets: SpotMarketConfig[] = [
373
373
  precisionExp: NINE,
374
374
  launchTs: 1721316817000,
375
375
  },
376
+ {
377
+ symbol: 'PYUSD',
378
+ marketIndex: 22,
379
+ oracle: new PublicKey('HpMoKp3TCd3QT4MWYUKk2zCBwmhr5Df45fB6wdxYqEeh'),
380
+ oracleSource: OracleSource.PYTH_STABLE_COIN_PULL,
381
+ mint: new PublicKey('2b1kV6DkPAnxd5ixfnxCpjxmKwqjjaYmCZfHsFu24GXo'),
382
+ precision: new BN(10).pow(SIX),
383
+ precisionExp: SIX,
384
+ pythFeedId:
385
+ '0xc1da1b73d7f01e7ddd54b3766cf7fcd644395ad14f70aa706ec5384c59e76692',
386
+ },
376
387
  ];
377
388
 
378
389
  export const SpotMarkets: { [key in DriftEnv]: SpotMarketConfig[] } = {
@@ -1813,17 +1813,24 @@ export class DriftClient {
1813
1813
  * Get the associated token address for the given spot market
1814
1814
  * @param marketIndex
1815
1815
  * @param useNative
1816
+ * @param tokenProgram
1816
1817
  */
1817
1818
  public async getAssociatedTokenAccount(
1818
1819
  marketIndex: number,
1819
- useNative = true
1820
+ useNative = true,
1821
+ tokenProgram = TOKEN_PROGRAM_ID
1820
1822
  ): Promise<PublicKey> {
1821
1823
  const spotMarket = this.getSpotMarketAccount(marketIndex);
1822
1824
  if (useNative && spotMarket.mint.equals(WRAPPED_SOL_MINT)) {
1823
1825
  return this.wallet.publicKey;
1824
1826
  }
1825
1827
  const mint = spotMarket.mint;
1826
- return await getAssociatedTokenAddress(mint, this.wallet.publicKey);
1828
+ return await getAssociatedTokenAddress(
1829
+ mint,
1830
+ this.wallet.publicKey,
1831
+ undefined,
1832
+ tokenProgram
1833
+ );
1827
1834
  }
1828
1835
 
1829
1836
  public createAssociatedTokenAccountIdempotentInstruction(
@@ -4250,17 +4257,17 @@ export class DriftClient {
4250
4257
 
4251
4258
  const preInstructions = [];
4252
4259
  if (!outAssociatedTokenAccount) {
4260
+ const tokenProgram = this.getTokenProgramForSpotMarket(outMarket);
4253
4261
  outAssociatedTokenAccount = await this.getAssociatedTokenAccount(
4254
4262
  outMarket.marketIndex,
4255
- false
4263
+ false,
4264
+ tokenProgram
4256
4265
  );
4257
4266
 
4258
4267
  const accountInfo = await this.connection.getAccountInfo(
4259
4268
  outAssociatedTokenAccount
4260
4269
  );
4261
4270
  if (!accountInfo) {
4262
- const tokenProgram = this.getTokenProgramForSpotMarket(outMarket);
4263
-
4264
4271
  preInstructions.push(
4265
4272
  this.createAssociatedTokenAccountIdempotentInstruction(
4266
4273
  outAssociatedTokenAccount,
@@ -4274,17 +4281,17 @@ export class DriftClient {
4274
4281
  }
4275
4282
 
4276
4283
  if (!inAssociatedTokenAccount) {
4284
+ const tokenProgram = this.getTokenProgramForSpotMarket(outMarket);
4277
4285
  inAssociatedTokenAccount = await this.getAssociatedTokenAccount(
4278
4286
  inMarket.marketIndex,
4279
- false
4287
+ false,
4288
+ tokenProgram
4280
4289
  );
4281
4290
 
4282
4291
  const accountInfo = await this.connection.getAccountInfo(
4283
4292
  inAssociatedTokenAccount
4284
4293
  );
4285
4294
  if (!accountInfo) {
4286
- const tokenProgram = this.getTokenProgramForSpotMarket(outMarket);
4287
-
4288
4295
  preInstructions.push(
4289
4296
  this.createAssociatedTokenAccountIdempotentInstruction(
4290
4297
  inAssociatedTokenAccount,
@@ -4390,9 +4397,11 @@ export class DriftClient {
4390
4397
 
4391
4398
  const preInstructions = [];
4392
4399
  if (!outAssociatedTokenAccount) {
4400
+ const tokenProgram = this.getTokenProgramForSpotMarket(outMarket);
4393
4401
  outAssociatedTokenAccount = await this.getAssociatedTokenAccount(
4394
4402
  outMarket.marketIndex,
4395
- false
4403
+ false,
4404
+ tokenProgram
4396
4405
  );
4397
4406
 
4398
4407
  const accountInfo = await this.connection.getAccountInfo(
@@ -4404,16 +4413,19 @@ export class DriftClient {
4404
4413
  outAssociatedTokenAccount,
4405
4414
  this.provider.wallet.publicKey,
4406
4415
  this.provider.wallet.publicKey,
4407
- outMarket.mint
4416
+ outMarket.mint,
4417
+ tokenProgram
4408
4418
  )
4409
4419
  );
4410
4420
  }
4411
4421
  }
4412
4422
 
4413
4423
  if (!inAssociatedTokenAccount) {
4424
+ const tokenProgram = this.getTokenProgramForSpotMarket(inMarket);
4414
4425
  inAssociatedTokenAccount = await this.getAssociatedTokenAccount(
4415
4426
  inMarket.marketIndex,
4416
- false
4427
+ false,
4428
+ tokenProgram
4417
4429
  );
4418
4430
 
4419
4431
  const accountInfo = await this.connection.getAccountInfo(
@@ -4425,7 +4437,8 @@ export class DriftClient {
4425
4437
  inAssociatedTokenAccount,
4426
4438
  this.provider.wallet.publicKey,
4427
4439
  this.provider.wallet.publicKey,
4428
- inMarket.mint
4440
+ inMarket.mint,
4441
+ tokenProgram
4429
4442
  )
4430
4443
  );
4431
4444
  }