@drift-labs/sdk 2.110.0-beta.21 → 2.110.0-beta.23

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.
@@ -3154,6 +3154,138 @@ export class DriftClient {
3154
3154
  });
3155
3155
  }
3156
3156
 
3157
+ public async transferPools(
3158
+ depositFromMarketIndex: number,
3159
+ depositToMarketIndex: number,
3160
+ borrowFromMarketIndex: number,
3161
+ borrowToMarketIndex: number,
3162
+ depositAmount: BN | undefined,
3163
+ borrowAmount: BN | undefined,
3164
+ fromSubAccountId: number,
3165
+ toSubAccountId: number,
3166
+ txParams?: TxParams
3167
+ ): Promise<TransactionSignature> {
3168
+ const { txSig, slot } = await this.sendTransaction(
3169
+ await this.buildTransaction(
3170
+ await this.getTransferPoolsIx(
3171
+ depositFromMarketIndex,
3172
+ depositToMarketIndex,
3173
+ borrowFromMarketIndex,
3174
+ borrowToMarketIndex,
3175
+ depositAmount,
3176
+ borrowAmount,
3177
+ fromSubAccountId,
3178
+ toSubAccountId
3179
+ ),
3180
+ txParams
3181
+ ),
3182
+ [],
3183
+ this.opts
3184
+ );
3185
+
3186
+ if (
3187
+ fromSubAccountId === this.activeSubAccountId ||
3188
+ toSubAccountId === this.activeSubAccountId
3189
+ ) {
3190
+ this.spotMarketLastSlotCache.set(depositFromMarketIndex, slot);
3191
+ this.spotMarketLastSlotCache.set(depositToMarketIndex, slot);
3192
+ this.spotMarketLastSlotCache.set(borrowFromMarketIndex, slot);
3193
+ this.spotMarketLastSlotCache.set(borrowToMarketIndex, slot);
3194
+ }
3195
+ return txSig;
3196
+ }
3197
+
3198
+ public async getTransferPoolsIx(
3199
+ depositFromMarketIndex: number,
3200
+ depositToMarketIndex: number,
3201
+ borrowFromMarketIndex: number,
3202
+ borrowToMarketIndex: number,
3203
+ depositAmount: BN | undefined,
3204
+ borrowAmount: BN | undefined,
3205
+ fromSubAccountId: number,
3206
+ toSubAccountId: number
3207
+ ): Promise<TransactionInstruction> {
3208
+ const fromUser = await getUserAccountPublicKey(
3209
+ this.program.programId,
3210
+ this.wallet.publicKey,
3211
+ fromSubAccountId
3212
+ );
3213
+ const toUser = await getUserAccountPublicKey(
3214
+ this.program.programId,
3215
+ this.wallet.publicKey,
3216
+ toSubAccountId
3217
+ );
3218
+
3219
+ const userAccounts = [
3220
+ this.getUserAccount(fromSubAccountId),
3221
+ this.getUserAccount(toSubAccountId),
3222
+ ];
3223
+
3224
+ const remainingAccounts = this.getRemainingAccounts({
3225
+ userAccounts,
3226
+ useMarketLastSlotCache: true,
3227
+ writableSpotMarketIndexes: [
3228
+ depositFromMarketIndex,
3229
+ depositToMarketIndex,
3230
+ borrowFromMarketIndex,
3231
+ borrowToMarketIndex,
3232
+ ],
3233
+ });
3234
+
3235
+ const tokenPrograms = new Set<string>();
3236
+ const depositFromSpotMarket = this.getSpotMarketAccount(
3237
+ depositFromMarketIndex
3238
+ );
3239
+ const borrowFromSpotMarket = this.getSpotMarketAccount(
3240
+ borrowFromMarketIndex
3241
+ );
3242
+
3243
+ tokenPrograms.add(
3244
+ this.getTokenProgramForSpotMarket(depositFromSpotMarket).toBase58()
3245
+ );
3246
+ tokenPrograms.add(
3247
+ this.getTokenProgramForSpotMarket(borrowFromSpotMarket).toBase58()
3248
+ );
3249
+
3250
+ for (const tokenProgram of tokenPrograms) {
3251
+ remainingAccounts.push({
3252
+ isSigner: false,
3253
+ isWritable: false,
3254
+ pubkey: new PublicKey(tokenProgram),
3255
+ });
3256
+ }
3257
+
3258
+ return await this.program.instruction.transferPools(
3259
+ depositFromMarketIndex,
3260
+ depositToMarketIndex,
3261
+ borrowFromMarketIndex,
3262
+ borrowToMarketIndex,
3263
+ depositAmount ?? null,
3264
+ borrowAmount ?? null,
3265
+ {
3266
+ accounts: {
3267
+ authority: this.wallet.publicKey,
3268
+ fromUser,
3269
+ toUser,
3270
+ userStats: this.getUserStatsAccountPublicKey(),
3271
+ state: await this.getStatePublicKey(),
3272
+ depositFromSpotMarketVault: this.getSpotMarketAccount(
3273
+ depositFromMarketIndex
3274
+ ).vault,
3275
+ depositToSpotMarketVault:
3276
+ this.getSpotMarketAccount(depositToMarketIndex).vault,
3277
+ borrowFromSpotMarketVault: this.getSpotMarketAccount(
3278
+ borrowFromMarketIndex
3279
+ ).vault,
3280
+ borrowToSpotMarketVault:
3281
+ this.getSpotMarketAccount(borrowToMarketIndex).vault,
3282
+ driftSigner: this.getSignerPublicKey(),
3283
+ },
3284
+ remainingAccounts,
3285
+ }
3286
+ );
3287
+ }
3288
+
3157
3289
  public async updateSpotMarketCumulativeInterest(
3158
3290
  marketIndex: number,
3159
3291
  txParams?: TxParams
@@ -452,6 +452,91 @@
452
452
  }
453
453
  ]
454
454
  },
455
+ {
456
+ "name": "transferPools",
457
+ "accounts": [
458
+ {
459
+ "name": "fromUser",
460
+ "isMut": true,
461
+ "isSigner": false
462
+ },
463
+ {
464
+ "name": "toUser",
465
+ "isMut": true,
466
+ "isSigner": false
467
+ },
468
+ {
469
+ "name": "userStats",
470
+ "isMut": true,
471
+ "isSigner": false
472
+ },
473
+ {
474
+ "name": "authority",
475
+ "isMut": false,
476
+ "isSigner": true
477
+ },
478
+ {
479
+ "name": "state",
480
+ "isMut": false,
481
+ "isSigner": false
482
+ },
483
+ {
484
+ "name": "depositFromSpotMarketVault",
485
+ "isMut": true,
486
+ "isSigner": false
487
+ },
488
+ {
489
+ "name": "depositToSpotMarketVault",
490
+ "isMut": true,
491
+ "isSigner": false
492
+ },
493
+ {
494
+ "name": "borrowFromSpotMarketVault",
495
+ "isMut": true,
496
+ "isSigner": false
497
+ },
498
+ {
499
+ "name": "borrowToSpotMarketVault",
500
+ "isMut": true,
501
+ "isSigner": false
502
+ },
503
+ {
504
+ "name": "driftSigner",
505
+ "isMut": false,
506
+ "isSigner": false
507
+ }
508
+ ],
509
+ "args": [
510
+ {
511
+ "name": "depositFromMarketIndex",
512
+ "type": "u16"
513
+ },
514
+ {
515
+ "name": "depositToMarketIndex",
516
+ "type": "u16"
517
+ },
518
+ {
519
+ "name": "borrowFromMarketIndex",
520
+ "type": "u16"
521
+ },
522
+ {
523
+ "name": "borrowToMarketIndex",
524
+ "type": "u16"
525
+ },
526
+ {
527
+ "name": "depositAmount",
528
+ "type": {
529
+ "option": "u64"
530
+ }
531
+ },
532
+ {
533
+ "name": "borrowAmount",
534
+ "type": {
535
+ "option": "u64"
536
+ }
537
+ }
538
+ ]
539
+ },
455
540
  {
456
541
  "name": "placePerpOrder",
457
542
  "accounts": [