@drift-labs/sdk 0.1.10 → 0.1.11
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/lib/math/position.d.ts +6 -0
- package/lib/math/position.d.ts.map +1 -1
- package/lib/math/position.js +17 -1
- package/package.json +1 -1
- package/src/math/position.ts +19 -0
package/lib/math/position.d.ts
CHANGED
|
@@ -24,4 +24,10 @@ export declare function calculatePositionPNL(market: Market, marketPosition: Use
|
|
|
24
24
|
* @returns // TODO-PRECISION
|
|
25
25
|
*/
|
|
26
26
|
export declare function calculatePositionFundingPNL(market: Market, marketPosition: UserPosition): BN;
|
|
27
|
+
/**
|
|
28
|
+
*
|
|
29
|
+
* @param userPosition
|
|
30
|
+
* @returns Precision: MARK_PRICE_PRECISION (10^10)
|
|
31
|
+
*/
|
|
32
|
+
export declare function calculateEntryPrice(userPosition: UserPosition): BN;
|
|
27
33
|
//# sourceMappingURL=position.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"position.d.ts","sourceRoot":"","sources":["../../src/math/position.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAqB,YAAY,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"position.d.ts","sourceRoot":"","sources":["../../src/math/position.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAqB,YAAY,EAAE,MAAM,UAAU,CAAC;AAQnE,OAAO,EAAE,MAAM,OAAO,CAAC;AAQvB;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACtC,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,YAAY,GACxB,EAAE,CA+BJ;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CACnC,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,YAAY,EAC5B,WAAW,UAAQ,GACjB,EAAE,CAgCJ;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAC1C,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,YAAY,GAC1B,EAAE,CAoBJ;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,YAAY,GAAG,EAAE,CAUlE"}
|
package/lib/math/position.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.calculatePositionFundingPNL = exports.calculatePositionPNL = exports.calculateBaseAssetValue = void 0;
|
|
6
|
+
exports.calculateEntryPrice = exports.calculatePositionFundingPNL = exports.calculatePositionPNL = exports.calculateBaseAssetValue = void 0;
|
|
7
7
|
const types_1 = require("../types");
|
|
8
8
|
const numericConstants_1 = require("../constants/numericConstants");
|
|
9
9
|
const bn_js_1 = __importDefault(require("bn.js"));
|
|
@@ -98,3 +98,19 @@ function calculatePositionFundingPNL(market, marketPosition) {
|
|
|
98
98
|
return perPositionFundingRate;
|
|
99
99
|
}
|
|
100
100
|
exports.calculatePositionFundingPNL = calculatePositionFundingPNL;
|
|
101
|
+
/**
|
|
102
|
+
*
|
|
103
|
+
* @param userPosition
|
|
104
|
+
* @returns Precision: MARK_PRICE_PRECISION (10^10)
|
|
105
|
+
*/
|
|
106
|
+
function calculateEntryPrice(userPosition) {
|
|
107
|
+
if (userPosition.baseAssetAmount.eq(numericConstants_1.ZERO)) {
|
|
108
|
+
return numericConstants_1.ZERO;
|
|
109
|
+
}
|
|
110
|
+
return userPosition.quoteAssetAmount
|
|
111
|
+
.mul(numericConstants_1.MARK_PRICE_PRECISION)
|
|
112
|
+
.mul(numericConstants_1.AMM_TO_QUOTE_PRECISION_RATIO)
|
|
113
|
+
.div(userPosition.baseAssetAmount)
|
|
114
|
+
.abs();
|
|
115
|
+
}
|
|
116
|
+
exports.calculateEntryPrice = calculateEntryPrice;
|
package/package.json
CHANGED
package/src/math/position.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { Market, PositionDirection, UserPosition } from '../types';
|
|
2
2
|
import {
|
|
3
3
|
AMM_TO_QUOTE_PRECISION_RATIO,
|
|
4
|
+
MARK_PRICE_PRECISION,
|
|
4
5
|
PEG_PRECISION,
|
|
6
|
+
QUOTE_PRECISION,
|
|
5
7
|
ZERO,
|
|
6
8
|
} from '../constants/numericConstants';
|
|
7
9
|
import BN from 'bn.js';
|
|
@@ -131,3 +133,20 @@ export function calculatePositionFundingPNL(
|
|
|
131
133
|
|
|
132
134
|
return perPositionFundingRate;
|
|
133
135
|
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
*
|
|
139
|
+
* @param userPosition
|
|
140
|
+
* @returns Precision: MARK_PRICE_PRECISION (10^10)
|
|
141
|
+
*/
|
|
142
|
+
export function calculateEntryPrice(userPosition: UserPosition): BN {
|
|
143
|
+
if (userPosition.baseAssetAmount.eq(ZERO)) {
|
|
144
|
+
return ZERO;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return userPosition.quoteAssetAmount
|
|
148
|
+
.mul(MARK_PRICE_PRECISION)
|
|
149
|
+
.mul(AMM_TO_QUOTE_PRECISION_RATIO)
|
|
150
|
+
.div(userPosition.baseAssetAmount)
|
|
151
|
+
.abs();
|
|
152
|
+
}
|