@drift-labs/sdk 2.32.1-beta.6 → 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 +1 -1
- package/lib/math/superStake.d.ts +2 -1
- package/lib/math/superStake.js +20 -11
- package/package.json +1 -1
- package/src/math/superStake.ts +21 -10
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.32.1-beta.
|
|
1
|
+
2.32.1-beta.7
|
package/lib/math/superStake.d.ts
CHANGED
|
@@ -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[];
|
package/lib/math/superStake.js
CHANGED
|
@@ -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
|
-
|
|
15
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
package/src/math/superStake.ts
CHANGED
|
@@ -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
|
-
|
|
33
|
-
|
|
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
|
-
|
|
44
|
-
|
|
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',
|