@drift-labs/sdk 2.31.1-beta.10 → 2.31.1-beta.11

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.31.1-beta.10",
3
+ "version": "2.31.1-beta.11",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -117,6 +117,7 @@ import { castNumberToSpotPrecision } from './math/spotMarket';
117
117
  import { JupiterClient, Route, SwapMode } from './jupiter/jupiterClient';
118
118
  import { getNonIdleUserFilter } from './memcmp';
119
119
  import { UserStatsSubscriptionConfig } from './userStatsConfig';
120
+ import { getMarinadeDepositIx, getMarinadeFinanceProgram } from './marinade';
120
121
 
121
122
  type RemainingAccountParams = {
122
123
  userAccounts: UserAccount[];
@@ -3540,6 +3541,63 @@ export class DriftClient {
3540
3541
  return { beginSwapIx, endSwapIx };
3541
3542
  }
3542
3543
 
3544
+ public async stakeForMSOL({ amount }: { amount: BN }): Promise<TxSigAndSlot> {
3545
+ const ixs = await this.getStakeForMSOLIx({ amount });
3546
+ const tx = await this.buildTransaction(ixs);
3547
+ return this.sendTransaction(tx);
3548
+ }
3549
+
3550
+ public async getStakeForMSOLIx({
3551
+ amount,
3552
+ }: {
3553
+ amount: BN;
3554
+ }): Promise<TransactionInstruction[]> {
3555
+ const wSOLMint = this.getSpotMarketAccount(1).mint;
3556
+ const mSOLAccount = await this.getAssociatedTokenAccount(2);
3557
+ const wSOLAccount = await this.getAssociatedTokenAccount(1, false);
3558
+
3559
+ const wSOLAccountExists = await this.checkIfAccountExists(wSOLAccount);
3560
+
3561
+ const closeWSOLIx = createCloseAccountInstruction(
3562
+ wSOLAccount,
3563
+ this.wallet.publicKey,
3564
+ this.wallet.publicKey
3565
+ );
3566
+
3567
+ const createWSOLIx =
3568
+ await this.createAssociatedTokenAccountIdempotentInstruction(
3569
+ wSOLAccount,
3570
+ this.wallet.publicKey,
3571
+ this.wallet.publicKey,
3572
+ wSOLMint
3573
+ );
3574
+
3575
+ const { beginSwapIx, endSwapIx } = await this.getSwapIx({
3576
+ inMarketIndex: 1,
3577
+ outMarketIndex: 2,
3578
+ amountIn: amount,
3579
+ inTokenAccount: wSOLAccount,
3580
+ outTokenAccount: mSOLAccount,
3581
+ });
3582
+
3583
+ const program = getMarinadeFinanceProgram(this.provider);
3584
+ const depositIx = await getMarinadeDepositIx({
3585
+ program,
3586
+ mSOLAccount: mSOLAccount,
3587
+ transferFrom: this.wallet.publicKey,
3588
+ amount,
3589
+ });
3590
+
3591
+ const ixs = [];
3592
+
3593
+ if (!wSOLAccountExists) {
3594
+ ixs.push(createWSOLIx);
3595
+ }
3596
+ ixs.push(beginSwapIx, closeWSOLIx, depositIx, createWSOLIx, endSwapIx);
3597
+
3598
+ return ixs;
3599
+ }
3600
+
3543
3601
  public async triggerOrder(
3544
3602
  userAccountPublicKey: PublicKey,
3545
3603
  user: UserAccount,
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.31.1-beta.10",
2
+ "version": "2.31.1-beta.11",
3
3
  "name": "drift",
4
4
  "instructions": [
5
5
  {
package/src/index.ts CHANGED
@@ -46,6 +46,7 @@ export * from './math/orders';
46
46
  export * from './math/repeg';
47
47
  export * from './math/margin';
48
48
  export * from './math/insurance';
49
+ export * from './marinade';
49
50
  export * from './orderParams';
50
51
  export * from './slot/SlotSubscriber';
51
52
  export * from './wallet';