@drift-labs/sdk 2.53.0-beta.2 → 2.53.0-beta.4
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/dlob/DLOB.d.ts +2 -2
- package/lib/dlob/DLOB.js +10 -6
- package/lib/driftClient.js +1 -0
- package/lib/math/superStake.d.ts +11 -8
- package/lib/math/superStake.js +33 -41
- package/package.json +1 -1
- package/src/dlob/DLOB.ts +16 -10
- package/src/driftClient.ts +1 -0
- package/src/math/superStake.ts +41 -44
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.53.0-beta.
|
|
1
|
+
2.53.0-beta.4
|
package/lib/dlob/DLOB.d.ts
CHANGED
|
@@ -91,8 +91,8 @@ export declare class DLOB {
|
|
|
91
91
|
takerNode: DLOBNode;
|
|
92
92
|
makerNode: DLOBNode;
|
|
93
93
|
} | undefined;
|
|
94
|
-
getBestAsk(marketIndex: number, slot: number, marketType: MarketType, oraclePriceData: OraclePriceData): BN;
|
|
95
|
-
getBestBid(marketIndex: number, slot: number, marketType: MarketType, oraclePriceData: OraclePriceData): BN;
|
|
94
|
+
getBestAsk(marketIndex: number, slot: number, marketType: MarketType, oraclePriceData: OraclePriceData): BN | undefined;
|
|
95
|
+
getBestBid(marketIndex: number, slot: number, marketType: MarketType, oraclePriceData: OraclePriceData): BN | undefined;
|
|
96
96
|
getStopLosses(marketIndex: number, marketType: MarketType, direction: PositionDirection): Generator<DLOBNode>;
|
|
97
97
|
getStopLossMarkets(marketIndex: number, marketType: MarketType, direction: PositionDirection): Generator<DLOBNode>;
|
|
98
98
|
getStopLossLimits(marketIndex: number, marketType: MarketType, direction: PositionDirection): Generator<DLOBNode>;
|
package/lib/dlob/DLOB.js
CHANGED
|
@@ -822,14 +822,18 @@ class DLOB {
|
|
|
822
822
|
}
|
|
823
823
|
}
|
|
824
824
|
getBestAsk(marketIndex, slot, marketType, oraclePriceData) {
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
.
|
|
825
|
+
const bestAsk = this.getRestingLimitAsks(marketIndex, slot, marketType, oraclePriceData).next().value;
|
|
826
|
+
if (bestAsk) {
|
|
827
|
+
return bestAsk.getPrice(oraclePriceData, slot);
|
|
828
|
+
}
|
|
829
|
+
return undefined;
|
|
828
830
|
}
|
|
829
831
|
getBestBid(marketIndex, slot, marketType, oraclePriceData) {
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
.
|
|
832
|
+
const bestBid = this.getRestingLimitBids(marketIndex, slot, marketType, oraclePriceData).next().value;
|
|
833
|
+
if (bestBid) {
|
|
834
|
+
return bestBid.getPrice(oraclePriceData, slot);
|
|
835
|
+
}
|
|
836
|
+
return undefined;
|
|
833
837
|
}
|
|
834
838
|
*getStopLosses(marketIndex, marketType, direction) {
|
|
835
839
|
const marketTypeStr = (0, __1.getVariant)(marketType);
|
package/lib/driftClient.js
CHANGED
package/lib/math/superStake.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="bn.js" />
|
|
2
2
|
import { AddressLookupTableAccount, PublicKey, TransactionInstruction } from '@solana/web3.js';
|
|
3
|
-
import { JupiterClient } from '../jupiter/jupiterClient';
|
|
3
|
+
import { JupiterClient, QuoteResponse } from '../jupiter/jupiterClient';
|
|
4
4
|
import { DriftClient } from '../driftClient';
|
|
5
5
|
import { BN } from '@coral-xyz/anchor';
|
|
6
6
|
import { User } from '../user';
|
|
@@ -29,7 +29,7 @@ export type BSOL_EMISSIONS_API_RESPONSE = {
|
|
|
29
29
|
};
|
|
30
30
|
export declare function fetchBSolMetrics(): Promise<any>;
|
|
31
31
|
export declare function fetchBSolDriftEmissions(): Promise<any>;
|
|
32
|
-
export declare function findBestSuperStakeIxs({ marketIndex, amount, jupiterClient, driftClient, userAccountPublicKey, price, forceMarinade, onlyDirectRoutes, }: {
|
|
32
|
+
export declare function findBestSuperStakeIxs({ marketIndex, amount, jupiterClient, driftClient, userAccountPublicKey, price, forceMarinade, onlyDirectRoutes, jupiterQuote, }: {
|
|
33
33
|
marketIndex: number;
|
|
34
34
|
amount: BN;
|
|
35
35
|
jupiterClient: JupiterClient;
|
|
@@ -38,13 +38,14 @@ export declare function findBestSuperStakeIxs({ marketIndex, amount, jupiterClie
|
|
|
38
38
|
userAccountPublicKey?: PublicKey;
|
|
39
39
|
forceMarinade?: boolean;
|
|
40
40
|
onlyDirectRoutes?: boolean;
|
|
41
|
+
jupiterQuote?: QuoteResponse;
|
|
41
42
|
}): Promise<{
|
|
42
43
|
ixs: TransactionInstruction[];
|
|
43
44
|
lookupTables: AddressLookupTableAccount[];
|
|
44
45
|
method: 'jupiter' | 'marinade';
|
|
45
|
-
price
|
|
46
|
+
price?: number;
|
|
46
47
|
}>;
|
|
47
|
-
export declare function findBestMSolSuperStakeIxs({ amount, jupiterClient, driftClient, userAccountPublicKey, price, forceMarinade, onlyDirectRoutes, }: {
|
|
48
|
+
export declare function findBestMSolSuperStakeIxs({ amount, jupiterClient, driftClient, userAccountPublicKey, price, forceMarinade, onlyDirectRoutes, jupiterQuote, }: {
|
|
48
49
|
amount: BN;
|
|
49
50
|
jupiterClient: JupiterClient;
|
|
50
51
|
driftClient: DriftClient;
|
|
@@ -52,30 +53,32 @@ export declare function findBestMSolSuperStakeIxs({ amount, jupiterClient, drift
|
|
|
52
53
|
userAccountPublicKey?: PublicKey;
|
|
53
54
|
forceMarinade?: boolean;
|
|
54
55
|
onlyDirectRoutes?: boolean;
|
|
56
|
+
jupiterQuote?: QuoteResponse;
|
|
55
57
|
}): Promise<{
|
|
56
58
|
ixs: TransactionInstruction[];
|
|
57
59
|
lookupTables: AddressLookupTableAccount[];
|
|
58
60
|
method: 'jupiter' | 'marinade';
|
|
59
61
|
price: number;
|
|
60
62
|
}>;
|
|
61
|
-
export declare function findBestJitoSolSuperStakeIxs({ amount, jupiterClient, driftClient, userAccountPublicKey, onlyDirectRoutes, }: {
|
|
63
|
+
export declare function findBestJitoSolSuperStakeIxs({ amount, jupiterClient, driftClient, userAccountPublicKey, onlyDirectRoutes, jupiterQuote, }: {
|
|
62
64
|
amount: BN;
|
|
63
65
|
jupiterClient: JupiterClient;
|
|
64
66
|
driftClient: DriftClient;
|
|
65
67
|
userAccountPublicKey?: PublicKey;
|
|
66
68
|
onlyDirectRoutes?: boolean;
|
|
69
|
+
jupiterQuote?: QuoteResponse;
|
|
67
70
|
}): Promise<{
|
|
68
71
|
ixs: TransactionInstruction[];
|
|
69
72
|
lookupTables: AddressLookupTableAccount[];
|
|
70
73
|
method: 'jupiter' | 'marinade';
|
|
71
|
-
price
|
|
74
|
+
price?: number;
|
|
72
75
|
}>;
|
|
73
76
|
/**
|
|
74
77
|
* Finds best Jupiter Swap instructions for a generic lstMint
|
|
75
78
|
*
|
|
76
79
|
* Without doing any extra steps like checking if you can get a better rate by staking directly with that LST platform
|
|
77
80
|
*/
|
|
78
|
-
export declare function findBestLstSuperStakeIxs({ amount,
|
|
81
|
+
export declare function findBestLstSuperStakeIxs({ amount, jupiterClient, driftClient, userAccountPublicKey, onlyDirectRoutes, lstMarketIndex, jupiterQuote, }: {
|
|
79
82
|
amount: BN;
|
|
80
83
|
lstMint: PublicKey;
|
|
81
84
|
lstMarketIndex: number;
|
|
@@ -83,11 +86,11 @@ export declare function findBestLstSuperStakeIxs({ amount, lstMint, jupiterClien
|
|
|
83
86
|
driftClient: DriftClient;
|
|
84
87
|
userAccountPublicKey?: PublicKey;
|
|
85
88
|
onlyDirectRoutes?: boolean;
|
|
89
|
+
jupiterQuote?: QuoteResponse;
|
|
86
90
|
}): Promise<{
|
|
87
91
|
ixs: TransactionInstruction[];
|
|
88
92
|
lookupTables: AddressLookupTableAccount[];
|
|
89
93
|
method: 'jupiter' | 'marinade';
|
|
90
|
-
price: number;
|
|
91
94
|
}>;
|
|
92
95
|
export type JITO_SOL_METRICS_ENDPOINT_RESPONSE = {
|
|
93
96
|
data: {
|
package/lib/math/superStake.js
CHANGED
|
@@ -19,7 +19,7 @@ async function fetchBSolDriftEmissions() {
|
|
|
19
19
|
return await (0, node_fetch_1.default)('https://stake.solblaze.org/api/v1/drift_emissions');
|
|
20
20
|
}
|
|
21
21
|
exports.fetchBSolDriftEmissions = fetchBSolDriftEmissions;
|
|
22
|
-
async function findBestSuperStakeIxs({ marketIndex, amount, jupiterClient, driftClient, userAccountPublicKey, price, forceMarinade, onlyDirectRoutes, }) {
|
|
22
|
+
async function findBestSuperStakeIxs({ marketIndex, amount, jupiterClient, driftClient, userAccountPublicKey, price, forceMarinade, onlyDirectRoutes, jupiterQuote, }) {
|
|
23
23
|
if (marketIndex === 2) {
|
|
24
24
|
return findBestMSolSuperStakeIxs({
|
|
25
25
|
amount,
|
|
@@ -29,6 +29,7 @@ async function findBestSuperStakeIxs({ marketIndex, amount, jupiterClient, drift
|
|
|
29
29
|
price,
|
|
30
30
|
forceMarinade,
|
|
31
31
|
onlyDirectRoutes,
|
|
32
|
+
jupiterQuote,
|
|
32
33
|
});
|
|
33
34
|
}
|
|
34
35
|
else if (marketIndex === 6) {
|
|
@@ -38,6 +39,7 @@ async function findBestSuperStakeIxs({ marketIndex, amount, jupiterClient, drift
|
|
|
38
39
|
driftClient,
|
|
39
40
|
userAccountPublicKey,
|
|
40
41
|
onlyDirectRoutes,
|
|
42
|
+
jupiterQuote,
|
|
41
43
|
});
|
|
42
44
|
}
|
|
43
45
|
else if (marketIndex === 8) {
|
|
@@ -49,6 +51,7 @@ async function findBestSuperStakeIxs({ marketIndex, amount, jupiterClient, drift
|
|
|
49
51
|
driftClient,
|
|
50
52
|
userAccountPublicKey,
|
|
51
53
|
onlyDirectRoutes,
|
|
54
|
+
jupiterQuote,
|
|
52
55
|
});
|
|
53
56
|
}
|
|
54
57
|
else {
|
|
@@ -56,27 +59,30 @@ async function findBestSuperStakeIxs({ marketIndex, amount, jupiterClient, drift
|
|
|
56
59
|
}
|
|
57
60
|
}
|
|
58
61
|
exports.findBestSuperStakeIxs = findBestSuperStakeIxs;
|
|
59
|
-
async function findBestMSolSuperStakeIxs({ amount, jupiterClient, driftClient, userAccountPublicKey, price, forceMarinade, onlyDirectRoutes, }) {
|
|
62
|
+
async function findBestMSolSuperStakeIxs({ amount, jupiterClient, driftClient, userAccountPublicKey, price, forceMarinade, onlyDirectRoutes, jupiterQuote, }) {
|
|
60
63
|
if (!price) {
|
|
61
64
|
const marinadeProgram = (0, marinade_1.getMarinadeFinanceProgram)(driftClient.provider);
|
|
62
65
|
price = await (0, marinade_1.getMarinadeMSolPrice)(marinadeProgram);
|
|
63
66
|
}
|
|
64
|
-
const
|
|
65
|
-
const
|
|
67
|
+
const solSpotMarketAccount = driftClient.getSpotMarketAccount(1);
|
|
68
|
+
const mSolSpotMarketAccount = driftClient.getSpotMarketAccount(2);
|
|
66
69
|
let jupiterPrice;
|
|
67
|
-
let
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
70
|
+
let quote = jupiterQuote;
|
|
71
|
+
if (!jupiterQuote) {
|
|
72
|
+
try {
|
|
73
|
+
const fetchedQuote = await jupiterClient.getQuote({
|
|
74
|
+
inputMint: solSpotMarketAccount.mint,
|
|
75
|
+
outputMint: mSolSpotMarketAccount.mint,
|
|
76
|
+
amount,
|
|
77
|
+
slippageBps: 1000,
|
|
78
|
+
onlyDirectRoutes,
|
|
79
|
+
});
|
|
80
|
+
jupiterPrice = +quote.outAmount / +quote.inAmount;
|
|
81
|
+
quote = fetchedQuote;
|
|
82
|
+
}
|
|
83
|
+
catch (e) {
|
|
84
|
+
console.error('Error getting jupiter price', e);
|
|
85
|
+
}
|
|
80
86
|
}
|
|
81
87
|
if (!jupiterPrice || price <= jupiterPrice || forceMarinade) {
|
|
82
88
|
const ixs = await driftClient.getStakeForMSOLIx({
|
|
@@ -91,13 +97,14 @@ async function findBestMSolSuperStakeIxs({ amount, jupiterClient, driftClient, u
|
|
|
91
97
|
};
|
|
92
98
|
}
|
|
93
99
|
else {
|
|
94
|
-
const { ixs, lookupTables } = await driftClient.
|
|
100
|
+
const { ixs, lookupTables } = await driftClient.getJupiterSwapIxV6({
|
|
95
101
|
inMarketIndex: 1,
|
|
96
102
|
outMarketIndex: 2,
|
|
97
|
-
route: bestRoute,
|
|
98
103
|
jupiterClient,
|
|
99
104
|
amount,
|
|
100
105
|
userAccountPublicKey,
|
|
106
|
+
onlyDirectRoutes,
|
|
107
|
+
quote,
|
|
101
108
|
});
|
|
102
109
|
return {
|
|
103
110
|
method: 'jupiter',
|
|
@@ -108,7 +115,7 @@ async function findBestMSolSuperStakeIxs({ amount, jupiterClient, driftClient, u
|
|
|
108
115
|
}
|
|
109
116
|
}
|
|
110
117
|
exports.findBestMSolSuperStakeIxs = findBestMSolSuperStakeIxs;
|
|
111
|
-
async function findBestJitoSolSuperStakeIxs({ amount, jupiterClient, driftClient, userAccountPublicKey, onlyDirectRoutes, }) {
|
|
118
|
+
async function findBestJitoSolSuperStakeIxs({ amount, jupiterClient, driftClient, userAccountPublicKey, onlyDirectRoutes, jupiterQuote, }) {
|
|
112
119
|
return await findBestLstSuperStakeIxs({
|
|
113
120
|
amount,
|
|
114
121
|
jupiterClient,
|
|
@@ -117,6 +124,7 @@ async function findBestJitoSolSuperStakeIxs({ amount, jupiterClient, driftClient
|
|
|
117
124
|
onlyDirectRoutes,
|
|
118
125
|
lstMint: driftClient.getSpotMarketAccount(6).mint,
|
|
119
126
|
lstMarketIndex: 6,
|
|
127
|
+
jupiterQuote,
|
|
120
128
|
});
|
|
121
129
|
}
|
|
122
130
|
exports.findBestJitoSolSuperStakeIxs = findBestJitoSolSuperStakeIxs;
|
|
@@ -125,37 +133,21 @@ exports.findBestJitoSolSuperStakeIxs = findBestJitoSolSuperStakeIxs;
|
|
|
125
133
|
*
|
|
126
134
|
* Without doing any extra steps like checking if you can get a better rate by staking directly with that LST platform
|
|
127
135
|
*/
|
|
128
|
-
async function findBestLstSuperStakeIxs({ amount,
|
|
129
|
-
const
|
|
130
|
-
let jupiterPrice;
|
|
131
|
-
let bestRoute;
|
|
132
|
-
try {
|
|
133
|
-
const jupiterRoutes = await jupiterClient.getRoutes({
|
|
134
|
-
inputMint: solMint,
|
|
135
|
-
outputMint: lstMint,
|
|
136
|
-
amount,
|
|
137
|
-
onlyDirectRoutes,
|
|
138
|
-
});
|
|
139
|
-
bestRoute = jupiterRoutes[0];
|
|
140
|
-
jupiterPrice = bestRoute.inAmount / bestRoute.outAmount;
|
|
141
|
-
}
|
|
142
|
-
catch (e) {
|
|
143
|
-
console.error('Error getting jupiter price', e);
|
|
144
|
-
throw e;
|
|
145
|
-
}
|
|
146
|
-
const { ixs, lookupTables } = await driftClient.getJupiterSwapIx({
|
|
136
|
+
async function findBestLstSuperStakeIxs({ amount, jupiterClient, driftClient, userAccountPublicKey, onlyDirectRoutes, lstMarketIndex, jupiterQuote, }) {
|
|
137
|
+
const { ixs, lookupTables } = await driftClient.getJupiterSwapIxV6({
|
|
147
138
|
inMarketIndex: 1,
|
|
148
139
|
outMarketIndex: lstMarketIndex,
|
|
149
|
-
route: bestRoute,
|
|
150
140
|
jupiterClient,
|
|
151
141
|
amount,
|
|
152
142
|
userAccountPublicKey,
|
|
143
|
+
onlyDirectRoutes,
|
|
144
|
+
quote: jupiterQuote,
|
|
153
145
|
});
|
|
154
146
|
return {
|
|
155
147
|
method: 'jupiter',
|
|
156
148
|
ixs,
|
|
157
149
|
lookupTables,
|
|
158
|
-
price: jupiterPrice,
|
|
150
|
+
// price: jupiterPrice,
|
|
159
151
|
};
|
|
160
152
|
}
|
|
161
153
|
exports.findBestLstSuperStakeIxs = findBestLstSuperStakeIxs;
|
package/package.json
CHANGED
package/src/dlob/DLOB.ts
CHANGED
|
@@ -1472,15 +1472,18 @@ export class DLOB {
|
|
|
1472
1472
|
slot: number,
|
|
1473
1473
|
marketType: MarketType,
|
|
1474
1474
|
oraclePriceData: OraclePriceData
|
|
1475
|
-
): BN {
|
|
1476
|
-
|
|
1475
|
+
): BN | undefined {
|
|
1476
|
+
const bestAsk = this.getRestingLimitAsks(
|
|
1477
1477
|
marketIndex,
|
|
1478
1478
|
slot,
|
|
1479
1479
|
marketType,
|
|
1480
1480
|
oraclePriceData
|
|
1481
|
-
)
|
|
1482
|
-
|
|
1483
|
-
|
|
1481
|
+
).next().value;
|
|
1482
|
+
|
|
1483
|
+
if (bestAsk) {
|
|
1484
|
+
return bestAsk.getPrice(oraclePriceData, slot);
|
|
1485
|
+
}
|
|
1486
|
+
return undefined;
|
|
1484
1487
|
}
|
|
1485
1488
|
|
|
1486
1489
|
public getBestBid(
|
|
@@ -1488,15 +1491,18 @@ export class DLOB {
|
|
|
1488
1491
|
slot: number,
|
|
1489
1492
|
marketType: MarketType,
|
|
1490
1493
|
oraclePriceData: OraclePriceData
|
|
1491
|
-
): BN {
|
|
1492
|
-
|
|
1494
|
+
): BN | undefined {
|
|
1495
|
+
const bestBid = this.getRestingLimitBids(
|
|
1493
1496
|
marketIndex,
|
|
1494
1497
|
slot,
|
|
1495
1498
|
marketType,
|
|
1496
1499
|
oraclePriceData
|
|
1497
|
-
)
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
+
).next().value;
|
|
1501
|
+
|
|
1502
|
+
if (bestBid) {
|
|
1503
|
+
return bestBid.getPrice(oraclePriceData, slot);
|
|
1504
|
+
}
|
|
1505
|
+
return undefined;
|
|
1500
1506
|
}
|
|
1501
1507
|
|
|
1502
1508
|
public *getStopLosses(
|
package/src/driftClient.ts
CHANGED
package/src/math/superStake.ts
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
PublicKey,
|
|
5
5
|
TransactionInstruction,
|
|
6
6
|
} from '@solana/web3.js';
|
|
7
|
-
import { JupiterClient } from '../jupiter/jupiterClient';
|
|
7
|
+
import { JupiterClient, QuoteResponse } from '../jupiter/jupiterClient';
|
|
8
8
|
import { DriftClient } from '../driftClient';
|
|
9
9
|
import { getMarinadeFinanceProgram, getMarinadeMSolPrice } from '../marinade';
|
|
10
10
|
import { BN } from '@coral-xyz/anchor';
|
|
@@ -55,6 +55,7 @@ export async function findBestSuperStakeIxs({
|
|
|
55
55
|
price,
|
|
56
56
|
forceMarinade,
|
|
57
57
|
onlyDirectRoutes,
|
|
58
|
+
jupiterQuote,
|
|
58
59
|
}: {
|
|
59
60
|
marketIndex: number;
|
|
60
61
|
amount: BN;
|
|
@@ -64,11 +65,12 @@ export async function findBestSuperStakeIxs({
|
|
|
64
65
|
userAccountPublicKey?: PublicKey;
|
|
65
66
|
forceMarinade?: boolean;
|
|
66
67
|
onlyDirectRoutes?: boolean;
|
|
68
|
+
jupiterQuote?: QuoteResponse;
|
|
67
69
|
}): Promise<{
|
|
68
70
|
ixs: TransactionInstruction[];
|
|
69
71
|
lookupTables: AddressLookupTableAccount[];
|
|
70
72
|
method: 'jupiter' | 'marinade';
|
|
71
|
-
price
|
|
73
|
+
price?: number;
|
|
72
74
|
}> {
|
|
73
75
|
if (marketIndex === 2) {
|
|
74
76
|
return findBestMSolSuperStakeIxs({
|
|
@@ -79,6 +81,7 @@ export async function findBestSuperStakeIxs({
|
|
|
79
81
|
price,
|
|
80
82
|
forceMarinade,
|
|
81
83
|
onlyDirectRoutes,
|
|
84
|
+
jupiterQuote,
|
|
82
85
|
});
|
|
83
86
|
} else if (marketIndex === 6) {
|
|
84
87
|
return findBestJitoSolSuperStakeIxs({
|
|
@@ -87,6 +90,7 @@ export async function findBestSuperStakeIxs({
|
|
|
87
90
|
driftClient,
|
|
88
91
|
userAccountPublicKey,
|
|
89
92
|
onlyDirectRoutes,
|
|
93
|
+
jupiterQuote,
|
|
90
94
|
});
|
|
91
95
|
} else if (marketIndex === 8) {
|
|
92
96
|
return findBestLstSuperStakeIxs({
|
|
@@ -97,6 +101,7 @@ export async function findBestSuperStakeIxs({
|
|
|
97
101
|
driftClient,
|
|
98
102
|
userAccountPublicKey,
|
|
99
103
|
onlyDirectRoutes,
|
|
104
|
+
jupiterQuote,
|
|
100
105
|
});
|
|
101
106
|
} else {
|
|
102
107
|
throw new Error(`Unsupported superstake market index: ${marketIndex}`);
|
|
@@ -111,6 +116,7 @@ export async function findBestMSolSuperStakeIxs({
|
|
|
111
116
|
price,
|
|
112
117
|
forceMarinade,
|
|
113
118
|
onlyDirectRoutes,
|
|
119
|
+
jupiterQuote,
|
|
114
120
|
}: {
|
|
115
121
|
amount: BN;
|
|
116
122
|
jupiterClient: JupiterClient;
|
|
@@ -119,6 +125,7 @@ export async function findBestMSolSuperStakeIxs({
|
|
|
119
125
|
userAccountPublicKey?: PublicKey;
|
|
120
126
|
forceMarinade?: boolean;
|
|
121
127
|
onlyDirectRoutes?: boolean;
|
|
128
|
+
jupiterQuote?: QuoteResponse;
|
|
122
129
|
}): Promise<{
|
|
123
130
|
ixs: TransactionInstruction[];
|
|
124
131
|
lookupTables: AddressLookupTableAccount[];
|
|
@@ -130,23 +137,27 @@ export async function findBestMSolSuperStakeIxs({
|
|
|
130
137
|
price = await getMarinadeMSolPrice(marinadeProgram);
|
|
131
138
|
}
|
|
132
139
|
|
|
133
|
-
const
|
|
134
|
-
const
|
|
140
|
+
const solSpotMarketAccount = driftClient.getSpotMarketAccount(1);
|
|
141
|
+
const mSolSpotMarketAccount = driftClient.getSpotMarketAccount(2);
|
|
142
|
+
|
|
143
|
+
let jupiterPrice: number;
|
|
144
|
+
let quote = jupiterQuote;
|
|
145
|
+
if (!jupiterQuote) {
|
|
146
|
+
try {
|
|
147
|
+
const fetchedQuote = await jupiterClient.getQuote({
|
|
148
|
+
inputMint: solSpotMarketAccount.mint,
|
|
149
|
+
outputMint: mSolSpotMarketAccount.mint,
|
|
150
|
+
amount,
|
|
151
|
+
slippageBps: 1000,
|
|
152
|
+
onlyDirectRoutes,
|
|
153
|
+
});
|
|
135
154
|
|
|
136
|
-
|
|
137
|
-
let bestRoute;
|
|
138
|
-
try {
|
|
139
|
-
const jupiterRoutes = await jupiterClient.getRoutes({
|
|
140
|
-
inputMint: solMint,
|
|
141
|
-
outputMint: mSOLMint,
|
|
142
|
-
amount,
|
|
143
|
-
onlyDirectRoutes,
|
|
144
|
-
});
|
|
155
|
+
jupiterPrice = +quote.outAmount / +quote.inAmount;
|
|
145
156
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
157
|
+
quote = fetchedQuote;
|
|
158
|
+
} catch (e) {
|
|
159
|
+
console.error('Error getting jupiter price', e);
|
|
160
|
+
}
|
|
150
161
|
}
|
|
151
162
|
|
|
152
163
|
if (!jupiterPrice || price <= jupiterPrice || forceMarinade) {
|
|
@@ -161,13 +172,14 @@ export async function findBestMSolSuperStakeIxs({
|
|
|
161
172
|
price: price,
|
|
162
173
|
};
|
|
163
174
|
} else {
|
|
164
|
-
const { ixs, lookupTables } = await driftClient.
|
|
175
|
+
const { ixs, lookupTables } = await driftClient.getJupiterSwapIxV6({
|
|
165
176
|
inMarketIndex: 1,
|
|
166
177
|
outMarketIndex: 2,
|
|
167
|
-
route: bestRoute,
|
|
168
178
|
jupiterClient,
|
|
169
179
|
amount,
|
|
170
180
|
userAccountPublicKey,
|
|
181
|
+
onlyDirectRoutes,
|
|
182
|
+
quote,
|
|
171
183
|
});
|
|
172
184
|
return {
|
|
173
185
|
method: 'jupiter',
|
|
@@ -184,17 +196,19 @@ export async function findBestJitoSolSuperStakeIxs({
|
|
|
184
196
|
driftClient,
|
|
185
197
|
userAccountPublicKey,
|
|
186
198
|
onlyDirectRoutes,
|
|
199
|
+
jupiterQuote,
|
|
187
200
|
}: {
|
|
188
201
|
amount: BN;
|
|
189
202
|
jupiterClient: JupiterClient;
|
|
190
203
|
driftClient: DriftClient;
|
|
191
204
|
userAccountPublicKey?: PublicKey;
|
|
192
205
|
onlyDirectRoutes?: boolean;
|
|
206
|
+
jupiterQuote?: QuoteResponse;
|
|
193
207
|
}): Promise<{
|
|
194
208
|
ixs: TransactionInstruction[];
|
|
195
209
|
lookupTables: AddressLookupTableAccount[];
|
|
196
210
|
method: 'jupiter' | 'marinade';
|
|
197
|
-
price
|
|
211
|
+
price?: number;
|
|
198
212
|
}> {
|
|
199
213
|
return await findBestLstSuperStakeIxs({
|
|
200
214
|
amount,
|
|
@@ -204,6 +218,7 @@ export async function findBestJitoSolSuperStakeIxs({
|
|
|
204
218
|
onlyDirectRoutes,
|
|
205
219
|
lstMint: driftClient.getSpotMarketAccount(6).mint,
|
|
206
220
|
lstMarketIndex: 6,
|
|
221
|
+
jupiterQuote,
|
|
207
222
|
});
|
|
208
223
|
}
|
|
209
224
|
|
|
@@ -214,12 +229,12 @@ export async function findBestJitoSolSuperStakeIxs({
|
|
|
214
229
|
*/
|
|
215
230
|
export async function findBestLstSuperStakeIxs({
|
|
216
231
|
amount,
|
|
217
|
-
lstMint,
|
|
218
232
|
jupiterClient,
|
|
219
233
|
driftClient,
|
|
220
234
|
userAccountPublicKey,
|
|
221
235
|
onlyDirectRoutes,
|
|
222
236
|
lstMarketIndex,
|
|
237
|
+
jupiterQuote,
|
|
223
238
|
}: {
|
|
224
239
|
amount: BN;
|
|
225
240
|
lstMint: PublicKey;
|
|
@@ -228,44 +243,26 @@ export async function findBestLstSuperStakeIxs({
|
|
|
228
243
|
driftClient: DriftClient;
|
|
229
244
|
userAccountPublicKey?: PublicKey;
|
|
230
245
|
onlyDirectRoutes?: boolean;
|
|
246
|
+
jupiterQuote?: QuoteResponse;
|
|
231
247
|
}): Promise<{
|
|
232
248
|
ixs: TransactionInstruction[];
|
|
233
249
|
lookupTables: AddressLookupTableAccount[];
|
|
234
250
|
method: 'jupiter' | 'marinade';
|
|
235
|
-
price: number;
|
|
236
251
|
}> {
|
|
237
|
-
const
|
|
238
|
-
|
|
239
|
-
let jupiterPrice;
|
|
240
|
-
let bestRoute;
|
|
241
|
-
try {
|
|
242
|
-
const jupiterRoutes = await jupiterClient.getRoutes({
|
|
243
|
-
inputMint: solMint,
|
|
244
|
-
outputMint: lstMint,
|
|
245
|
-
amount,
|
|
246
|
-
onlyDirectRoutes,
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
bestRoute = jupiterRoutes[0];
|
|
250
|
-
jupiterPrice = bestRoute.inAmount / bestRoute.outAmount;
|
|
251
|
-
} catch (e) {
|
|
252
|
-
console.error('Error getting jupiter price', e);
|
|
253
|
-
throw e;
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
const { ixs, lookupTables } = await driftClient.getJupiterSwapIx({
|
|
252
|
+
const { ixs, lookupTables } = await driftClient.getJupiterSwapIxV6({
|
|
257
253
|
inMarketIndex: 1,
|
|
258
254
|
outMarketIndex: lstMarketIndex,
|
|
259
|
-
route: bestRoute,
|
|
260
255
|
jupiterClient,
|
|
261
256
|
amount,
|
|
262
257
|
userAccountPublicKey,
|
|
258
|
+
onlyDirectRoutes,
|
|
259
|
+
quote: jupiterQuote,
|
|
263
260
|
});
|
|
264
261
|
return {
|
|
265
262
|
method: 'jupiter',
|
|
266
263
|
ixs,
|
|
267
264
|
lookupTables,
|
|
268
|
-
price: jupiterPrice,
|
|
265
|
+
// price: jupiterPrice,
|
|
269
266
|
};
|
|
270
267
|
}
|
|
271
268
|
|