@drift-labs/sdk 2.32.1-beta.5 → 2.32.1-beta.7

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.32.1-beta.5
1
+ 2.32.1-beta.7
package/lib/index.d.ts CHANGED
@@ -83,4 +83,5 @@ export * from './orderSubscriber';
83
83
  export * from './orderSubscriber/types';
84
84
  export * from './auctionSubscriber';
85
85
  export * from './auctionSubscriber/types';
86
+ export * from './memcmp';
86
87
  export { BN, PublicKey, pyth };
package/lib/index.js CHANGED
@@ -106,3 +106,4 @@ __exportStar(require("./orderSubscriber"), exports);
106
106
  __exportStar(require("./orderSubscriber/types"), exports);
107
107
  __exportStar(require("./auctionSubscriber"), exports);
108
108
  __exportStar(require("./auctionSubscriber/types"), exports);
109
+ __exportStar(require("./memcmp"), exports);
@@ -4,10 +4,11 @@ import { DriftClient } from '../driftClient';
4
4
  import { BN } from '@coral-xyz/anchor';
5
5
  import { User } from '../user';
6
6
  import { DepositRecord } from '../types';
7
- export declare function findBestSuperStakeIxs({ amount, jupiterClient, driftClient, userAccountPublicKey, }: {
7
+ export declare function findBestSuperStakeIxs({ amount, jupiterClient, driftClient, userAccountPublicKey, marinadePrice, }: {
8
8
  amount: BN;
9
9
  jupiterClient: JupiterClient;
10
10
  driftClient: DriftClient;
11
+ marinadePrice?: number;
11
12
  userAccountPublicKey?: PublicKey;
12
13
  }): Promise<{
13
14
  ixs: TransactionInstruction[];
@@ -10,19 +10,28 @@ const anchor_1 = require("@coral-xyz/anchor");
10
10
  const types_1 = require("../types");
11
11
  const numericConstants_1 = require("../constants/numericConstants");
12
12
  const node_fetch_1 = __importDefault(require("node-fetch"));
13
- async function findBestSuperStakeIxs({ amount, jupiterClient, driftClient, userAccountPublicKey, }) {
14
- const marinadeProgram = (0, marinade_1.getMarinadeFinanceProgram)(driftClient.provider);
15
- const marinadePrice = await (0, marinade_1.getMarinadeMSolPrice)(marinadeProgram);
13
+ async function findBestSuperStakeIxs({ amount, jupiterClient, driftClient, userAccountPublicKey, marinadePrice, }) {
14
+ if (!marinadePrice) {
15
+ const marinadeProgram = (0, marinade_1.getMarinadeFinanceProgram)(driftClient.provider);
16
+ marinadePrice = await (0, marinade_1.getMarinadeMSolPrice)(marinadeProgram);
17
+ }
16
18
  const solMint = driftClient.getSpotMarketAccount(1).mint;
17
19
  const mSOLMint = driftClient.getSpotMarketAccount(2).mint;
18
- const jupiterRoutes = await jupiterClient.getRoutes({
19
- inputMint: solMint,
20
- outputMint: mSOLMint,
21
- amount,
22
- });
23
- const bestRoute = jupiterRoutes[0];
24
- const jupiterPrice = bestRoute.inAmount / bestRoute.outAmount;
25
- if (marinadePrice <= jupiterPrice) {
20
+ let jupiterPrice;
21
+ let bestRoute;
22
+ try {
23
+ const jupiterRoutes = await jupiterClient.getRoutes({
24
+ inputMint: solMint,
25
+ outputMint: mSOLMint,
26
+ amount,
27
+ });
28
+ bestRoute = jupiterRoutes[0];
29
+ jupiterPrice = bestRoute.inAmount / bestRoute.outAmount;
30
+ }
31
+ catch (e) {
32
+ console.error('Error getting jupiter price', e);
33
+ }
34
+ if (!jupiterPrice || marinadePrice <= jupiterPrice) {
26
35
  const ixs = await driftClient.getStakeForMSOLIx({ amount });
27
36
  return {
28
37
  method: 'marinade',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.32.1-beta.5",
3
+ "version": "2.32.1-beta.7",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
package/src/index.ts CHANGED
@@ -84,5 +84,6 @@ export * from './orderSubscriber';
84
84
  export * from './orderSubscriber/types';
85
85
  export * from './auctionSubscriber';
86
86
  export * from './auctionSubscriber/types';
87
+ export * from './memcmp';
87
88
 
88
89
  export { BN, PublicKey, pyth };
@@ -18,10 +18,12 @@ export async function findBestSuperStakeIxs({
18
18
  jupiterClient,
19
19
  driftClient,
20
20
  userAccountPublicKey,
21
+ marinadePrice,
21
22
  }: {
22
23
  amount: BN;
23
24
  jupiterClient: JupiterClient;
24
25
  driftClient: DriftClient;
26
+ marinadePrice?: number;
25
27
  userAccountPublicKey?: PublicKey;
26
28
  }): Promise<{
27
29
  ixs: TransactionInstruction[];
@@ -29,21 +31,30 @@ export async function findBestSuperStakeIxs({
29
31
  method: 'jupiter' | 'marinade';
30
32
  price: number;
31
33
  }> {
32
- const marinadeProgram = getMarinadeFinanceProgram(driftClient.provider);
33
- const marinadePrice = await getMarinadeMSolPrice(marinadeProgram);
34
+ if (!marinadePrice) {
35
+ const marinadeProgram = getMarinadeFinanceProgram(driftClient.provider);
36
+ marinadePrice = await getMarinadeMSolPrice(marinadeProgram);
37
+ }
34
38
 
35
39
  const solMint = driftClient.getSpotMarketAccount(1).mint;
36
40
  const mSOLMint = driftClient.getSpotMarketAccount(2).mint;
37
- const jupiterRoutes = await jupiterClient.getRoutes({
38
- inputMint: solMint,
39
- outputMint: mSOLMint,
40
- amount,
41
- });
42
41
 
43
- const bestRoute = jupiterRoutes[0];
44
- const jupiterPrice = bestRoute.inAmount / bestRoute.outAmount;
42
+ let jupiterPrice;
43
+ let bestRoute;
44
+ try {
45
+ const jupiterRoutes = await jupiterClient.getRoutes({
46
+ inputMint: solMint,
47
+ outputMint: mSOLMint,
48
+ amount,
49
+ });
50
+
51
+ bestRoute = jupiterRoutes[0];
52
+ jupiterPrice = bestRoute.inAmount / bestRoute.outAmount;
53
+ } catch (e) {
54
+ console.error('Error getting jupiter price', e);
55
+ }
45
56
 
46
- if (marinadePrice <= jupiterPrice) {
57
+ if (!jupiterPrice || marinadePrice <= jupiterPrice) {
47
58
  const ixs = await driftClient.getStakeForMSOLIx({ amount });
48
59
  return {
49
60
  method: 'marinade',