@drift-labs/sdk 2.31.1-beta.20 → 2.31.1-beta.22
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/driftClient.js +3 -0
- package/lib/idl/drift.json +1 -1
- package/lib/math/superStake.d.ts +1 -0
- package/lib/math/superStake.js +9 -1
- package/lib/orderParams.d.ts +4 -4
- package/package.json +1 -1
- package/src/driftClient.ts +3 -0
- package/src/idl/drift.json +1 -1
- package/src/math/superStake.ts +15 -0
- package/src/orderParams.ts +4 -4
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.31.1-beta.
|
|
1
|
+
2.31.1-beta.22
|
package/lib/driftClient.js
CHANGED
|
@@ -1589,6 +1589,9 @@ class DriftClient {
|
|
|
1589
1589
|
const readablePerpMarketIndex = [];
|
|
1590
1590
|
const readableSpotMarketIndexes = [];
|
|
1591
1591
|
for (const param of params) {
|
|
1592
|
+
if (!param.marketType) {
|
|
1593
|
+
throw new Error('must set param.marketType');
|
|
1594
|
+
}
|
|
1592
1595
|
if ((0, types_1.isVariant)(param.marketType, 'perp')) {
|
|
1593
1596
|
readablePerpMarketIndex.push(param.marketIndex);
|
|
1594
1597
|
}
|
package/lib/idl/drift.json
CHANGED
package/lib/math/superStake.d.ts
CHANGED
|
@@ -19,3 +19,4 @@ export declare function calculateSolEarned({ user, depositRecords, }: {
|
|
|
19
19
|
user: User;
|
|
20
20
|
depositRecords: DepositRecord[];
|
|
21
21
|
}): Promise<BN>;
|
|
22
|
+
export declare function calculateEstimatedSuperStakeLiquidationPrice(msolDepositAmount: number, msolMaintenanceAssetWeight: number, solBorrowAmount: number, solMaintenanceLiabilityWeight: number, msolPriceRatio: number): number;
|
package/lib/math/superStake.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.calculateSolEarned = exports.findBestSuperStakeIxs = void 0;
|
|
6
|
+
exports.calculateEstimatedSuperStakeLiquidationPrice = exports.calculateSolEarned = exports.findBestSuperStakeIxs = void 0;
|
|
7
7
|
const web3_js_1 = require("@solana/web3.js");
|
|
8
8
|
const marinade_1 = require("../marinade");
|
|
9
9
|
const anchor_1 = require("@coral-xyz/anchor");
|
|
@@ -98,3 +98,11 @@ async function calculateSolEarned({ user, depositRecords, }) {
|
|
|
98
98
|
return solEarned;
|
|
99
99
|
}
|
|
100
100
|
exports.calculateSolEarned = calculateSolEarned;
|
|
101
|
+
// calculate estimated liquidation price (in mSOL/SOL) based on target amounts
|
|
102
|
+
function calculateEstimatedSuperStakeLiquidationPrice(msolDepositAmount, msolMaintenanceAssetWeight, solBorrowAmount, solMaintenanceLiabilityWeight, msolPriceRatio) {
|
|
103
|
+
const liquidationDivergence = (solMaintenanceLiabilityWeight * solBorrowAmount) /
|
|
104
|
+
(msolMaintenanceAssetWeight * msolDepositAmount * msolPriceRatio);
|
|
105
|
+
const liquidationPrice = msolPriceRatio * liquidationDivergence;
|
|
106
|
+
return liquidationPrice;
|
|
107
|
+
}
|
|
108
|
+
exports.calculateEstimatedSuperStakeLiquidationPrice = calculateEstimatedSuperStakeLiquidationPrice;
|
package/lib/orderParams.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { OptionalOrderParams, OrderTriggerCondition } from './types';
|
|
2
2
|
import { BN } from '@coral-xyz/anchor';
|
|
3
|
-
export declare function getLimitOrderParams(params: Omit<OptionalOrderParams, 'orderType'
|
|
3
|
+
export declare function getLimitOrderParams(params: Omit<OptionalOrderParams, 'orderType'> & {
|
|
4
4
|
price: BN;
|
|
5
5
|
}): OptionalOrderParams;
|
|
6
|
-
export declare function getTriggerMarketOrderParams(params: Omit<OptionalOrderParams, 'orderType'
|
|
6
|
+
export declare function getTriggerMarketOrderParams(params: Omit<OptionalOrderParams, 'orderType'> & {
|
|
7
7
|
triggerCondition: OrderTriggerCondition;
|
|
8
8
|
triggerPrice: BN;
|
|
9
9
|
}): OptionalOrderParams;
|
|
10
|
-
export declare function getTriggerLimitOrderParams(params: Omit<OptionalOrderParams, 'orderType'
|
|
10
|
+
export declare function getTriggerLimitOrderParams(params: Omit<OptionalOrderParams, 'orderType'> & {
|
|
11
11
|
triggerCondition: OrderTriggerCondition;
|
|
12
12
|
triggerPrice: BN;
|
|
13
13
|
price: BN;
|
|
14
14
|
}): OptionalOrderParams;
|
|
15
|
-
export declare function getMarketOrderParams(params: Omit<OptionalOrderParams, 'orderType'
|
|
15
|
+
export declare function getMarketOrderParams(params: Omit<OptionalOrderParams, 'orderType'>): OptionalOrderParams;
|
package/package.json
CHANGED
package/src/driftClient.ts
CHANGED
|
@@ -2863,6 +2863,9 @@ export class DriftClient {
|
|
|
2863
2863
|
const readablePerpMarketIndex: number[] = [];
|
|
2864
2864
|
const readableSpotMarketIndexes: number[] = [];
|
|
2865
2865
|
for (const param of params) {
|
|
2866
|
+
if (!param.marketType) {
|
|
2867
|
+
throw new Error('must set param.marketType');
|
|
2868
|
+
}
|
|
2866
2869
|
if (isVariant(param.marketType, 'perp')) {
|
|
2867
2870
|
readablePerpMarketIndex.push(param.marketIndex);
|
|
2868
2871
|
} else {
|
package/src/idl/drift.json
CHANGED
package/src/math/superStake.ts
CHANGED
|
@@ -131,3 +131,18 @@ export async function calculateSolEarned({
|
|
|
131
131
|
|
|
132
132
|
return solEarned;
|
|
133
133
|
}
|
|
134
|
+
|
|
135
|
+
// calculate estimated liquidation price (in mSOL/SOL) based on target amounts
|
|
136
|
+
export function calculateEstimatedSuperStakeLiquidationPrice(
|
|
137
|
+
msolDepositAmount: number,
|
|
138
|
+
msolMaintenanceAssetWeight: number,
|
|
139
|
+
solBorrowAmount: number,
|
|
140
|
+
solMaintenanceLiabilityWeight: number,
|
|
141
|
+
msolPriceRatio: number
|
|
142
|
+
): number {
|
|
143
|
+
const liquidationDivergence =
|
|
144
|
+
(solMaintenanceLiabilityWeight * solBorrowAmount) /
|
|
145
|
+
(msolMaintenanceAssetWeight * msolDepositAmount * msolPriceRatio);
|
|
146
|
+
const liquidationPrice = msolPriceRatio * liquidationDivergence;
|
|
147
|
+
return liquidationPrice;
|
|
148
|
+
}
|
package/src/orderParams.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { OptionalOrderParams, OrderTriggerCondition, OrderType } from './types';
|
|
|
2
2
|
import { BN } from '@coral-xyz/anchor';
|
|
3
3
|
|
|
4
4
|
export function getLimitOrderParams(
|
|
5
|
-
params: Omit<OptionalOrderParams, 'orderType'
|
|
5
|
+
params: Omit<OptionalOrderParams, 'orderType'> & { price: BN }
|
|
6
6
|
): OptionalOrderParams {
|
|
7
7
|
return Object.assign({}, params, {
|
|
8
8
|
orderType: OrderType.LIMIT,
|
|
@@ -10,7 +10,7 @@ export function getLimitOrderParams(
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export function getTriggerMarketOrderParams(
|
|
13
|
-
params: Omit<OptionalOrderParams, 'orderType'
|
|
13
|
+
params: Omit<OptionalOrderParams, 'orderType'> & {
|
|
14
14
|
triggerCondition: OrderTriggerCondition;
|
|
15
15
|
triggerPrice: BN;
|
|
16
16
|
}
|
|
@@ -21,7 +21,7 @@ export function getTriggerMarketOrderParams(
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
export function getTriggerLimitOrderParams(
|
|
24
|
-
params: Omit<OptionalOrderParams, 'orderType'
|
|
24
|
+
params: Omit<OptionalOrderParams, 'orderType'> & {
|
|
25
25
|
triggerCondition: OrderTriggerCondition;
|
|
26
26
|
triggerPrice: BN;
|
|
27
27
|
price: BN;
|
|
@@ -33,7 +33,7 @@ export function getTriggerLimitOrderParams(
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
export function getMarketOrderParams(
|
|
36
|
-
params: Omit<OptionalOrderParams, 'orderType'
|
|
36
|
+
params: Omit<OptionalOrderParams, 'orderType'>
|
|
37
37
|
): OptionalOrderParams {
|
|
38
38
|
return Object.assign({}, params, {
|
|
39
39
|
orderType: OrderType.MARKET,
|