@drift-labs/sdk 2.32.1-beta.6 → 2.32.1-beta.8

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.6
1
+ 2.32.1-beta.8
@@ -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/lib/user.js CHANGED
@@ -1151,7 +1151,7 @@ class User {
1151
1151
  .div(numericConstants_1.SPOT_MARKET_WEIGHT_PRECISION.div(new _1.BN(100)))
1152
1152
  .div(inOraclePrice); // just assume user can go 100x
1153
1153
  inSwap = maxSwap.div(numericConstants_1.TWO);
1154
- const error = _1.BN.min(numericConstants_1.QUOTE_PRECISION, freeCollateral.div(new _1.BN(100)));
1154
+ const error = freeCollateral.div(new _1.BN(10000));
1155
1155
  let i = 0;
1156
1156
  let freeCollateralAfter = freeCollateral;
1157
1157
  while (freeCollateralAfter.gt(error) || freeCollateralAfter.isNeg()) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.32.1-beta.6",
3
+ "version": "2.32.1-beta.8",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -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',
package/src/user.ts CHANGED
@@ -2066,7 +2066,7 @@ export class User {
2066
2066
  .div(SPOT_MARKET_WEIGHT_PRECISION.div(new BN(100)))
2067
2067
  .div(inOraclePrice); // just assume user can go 100x
2068
2068
  inSwap = maxSwap.div(TWO);
2069
- const error = BN.min(QUOTE_PRECISION, freeCollateral.div(new BN(100)));
2069
+ const error = freeCollateral.div(new BN(10000));
2070
2070
 
2071
2071
  let i = 0;
2072
2072
  let freeCollateralAfter = freeCollateral;