@drift-labs/sdk 2.88.0-beta.2 → 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 +1 -1
- package/lib/driftClient.d.ts +2 -1
- package/lib/driftClient.js +11 -10
- package/package.json +1 -1
- package/src/driftClient.ts +21 -14
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.88.0-beta.
|
|
1
|
+
2.88.0-beta.3
|
package/lib/driftClient.d.ts
CHANGED
|
@@ -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
|
/**
|
package/lib/driftClient.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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,18 +2441,18 @@ class DriftClient {
|
|
|
2440
2441
|
});
|
|
2441
2442
|
const preInstructions = [];
|
|
2442
2443
|
if (!outAssociatedTokenAccount) {
|
|
2443
|
-
|
|
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
|
-
const tokenProgram = this.getTokenProgramForSpotMarket(outMarket);
|
|
2447
2448
|
preInstructions.push(this.createAssociatedTokenAccountIdempotentInstruction(outAssociatedTokenAccount, this.provider.wallet.publicKey, this.provider.wallet.publicKey, outMarket.mint, tokenProgram));
|
|
2448
2449
|
}
|
|
2449
2450
|
}
|
|
2450
2451
|
if (!inAssociatedTokenAccount) {
|
|
2451
|
-
|
|
2452
|
+
const tokenProgram = this.getTokenProgramForSpotMarket(inMarket);
|
|
2453
|
+
inAssociatedTokenAccount = await this.getAssociatedTokenAccount(inMarket.marketIndex, false, tokenProgram);
|
|
2452
2454
|
const accountInfo = await this.connection.getAccountInfo(inAssociatedTokenAccount);
|
|
2453
2455
|
if (!accountInfo) {
|
|
2454
|
-
const tokenProgram = this.getTokenProgramForSpotMarket(inMarket);
|
|
2455
2456
|
preInstructions.push(this.createAssociatedTokenAccountIdempotentInstruction(inAssociatedTokenAccount, this.provider.wallet.publicKey, this.provider.wallet.publicKey, inMarket.mint, tokenProgram));
|
|
2456
2457
|
}
|
|
2457
2458
|
}
|
package/package.json
CHANGED
package/src/driftClient.ts
CHANGED
|
@@ -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(
|
|
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,17 +4397,17 @@ 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(
|
|
4399
4408
|
outAssociatedTokenAccount
|
|
4400
4409
|
);
|
|
4401
4410
|
if (!accountInfo) {
|
|
4402
|
-
const tokenProgram = this.getTokenProgramForSpotMarket(outMarket);
|
|
4403
|
-
|
|
4404
4411
|
preInstructions.push(
|
|
4405
4412
|
this.createAssociatedTokenAccountIdempotentInstruction(
|
|
4406
4413
|
outAssociatedTokenAccount,
|
|
@@ -4414,17 +4421,17 @@ export class DriftClient {
|
|
|
4414
4421
|
}
|
|
4415
4422
|
|
|
4416
4423
|
if (!inAssociatedTokenAccount) {
|
|
4424
|
+
const tokenProgram = this.getTokenProgramForSpotMarket(inMarket);
|
|
4417
4425
|
inAssociatedTokenAccount = await this.getAssociatedTokenAccount(
|
|
4418
4426
|
inMarket.marketIndex,
|
|
4419
|
-
false
|
|
4427
|
+
false,
|
|
4428
|
+
tokenProgram
|
|
4420
4429
|
);
|
|
4421
4430
|
|
|
4422
4431
|
const accountInfo = await this.connection.getAccountInfo(
|
|
4423
4432
|
inAssociatedTokenAccount
|
|
4424
4433
|
);
|
|
4425
4434
|
if (!accountInfo) {
|
|
4426
|
-
const tokenProgram = this.getTokenProgramForSpotMarket(inMarket);
|
|
4427
|
-
|
|
4428
4435
|
preInstructions.push(
|
|
4429
4436
|
this.createAssociatedTokenAccountIdempotentInstruction(
|
|
4430
4437
|
inAssociatedTokenAccount,
|