@drift-labs/sdk 2.35.1-beta.5 → 2.35.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/dlob/DLOB.js +14 -4
- package/lib/math/orders.d.ts +1 -1
- package/lib/math/orders.js +9 -2
- package/lib/user.js +7 -0
- package/package.json +1 -1
- package/src/dlob/DLOB.ts +14 -4
- package/src/math/orders.ts +13 -2
- package/src/user.ts +13 -0
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.35.1-beta.
|
|
1
|
+
2.35.1-beta.7
|
package/lib/dlob/DLOB.js
CHANGED
|
@@ -491,11 +491,21 @@ class DLOB {
|
|
|
491
491
|
}
|
|
492
492
|
// All bids/asks that can expire
|
|
493
493
|
// dont try to expire limit orders with tif as its inefficient use of blockspace
|
|
494
|
-
const bidGenerators = [
|
|
495
|
-
|
|
494
|
+
const bidGenerators = [
|
|
495
|
+
nodeLists.takingLimit.bid.getGenerator(),
|
|
496
|
+
nodeLists.restingLimit.bid.getGenerator(),
|
|
497
|
+
nodeLists.floatingLimit.bid.getGenerator(),
|
|
498
|
+
nodeLists.market.bid.getGenerator(),
|
|
499
|
+
];
|
|
500
|
+
const askGenerators = [
|
|
501
|
+
nodeLists.takingLimit.ask.getGenerator(),
|
|
502
|
+
nodeLists.restingLimit.ask.getGenerator(),
|
|
503
|
+
nodeLists.floatingLimit.ask.getGenerator(),
|
|
504
|
+
nodeLists.market.ask.getGenerator(),
|
|
505
|
+
];
|
|
496
506
|
for (const bidGenerator of bidGenerators) {
|
|
497
507
|
for (const bid of bidGenerator) {
|
|
498
|
-
if ((0, __1.isOrderExpired)(bid.order, ts)) {
|
|
508
|
+
if ((0, __1.isOrderExpired)(bid.order, ts, true)) {
|
|
499
509
|
nodesToFill.push({
|
|
500
510
|
node: bid,
|
|
501
511
|
makerNodes: [],
|
|
@@ -505,7 +515,7 @@ class DLOB {
|
|
|
505
515
|
}
|
|
506
516
|
for (const askGenerator of askGenerators) {
|
|
507
517
|
for (const ask of askGenerator) {
|
|
508
|
-
if ((0, __1.isOrderExpired)(ask.order, ts)) {
|
|
518
|
+
if ((0, __1.isOrderExpired)(ask.order, ts, true)) {
|
|
509
519
|
nodesToFill.push({
|
|
510
520
|
node: ask,
|
|
511
521
|
makerNodes: [],
|
package/lib/math/orders.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export declare function hasAuctionPrice(order: Order, slot: number): boolean;
|
|
|
13
13
|
export declare function isFillableByVAMM(order: Order, market: PerpMarketAccount, oraclePriceData: OraclePriceData, slot: number, ts: number): boolean;
|
|
14
14
|
export declare function calculateBaseAssetAmountForAmmToFulfill(order: Order, market: PerpMarketAccount, oraclePriceData: OraclePriceData, slot: number): BN;
|
|
15
15
|
export declare function calculateBaseAssetAmountToFillUpToLimitPrice(order: Order, amm: AMM, limitPrice: BN, oraclePriceData: OraclePriceData): BN;
|
|
16
|
-
export declare function isOrderExpired(order: Order, ts: number): boolean;
|
|
16
|
+
export declare function isOrderExpired(order: Order, ts: number, enforceBuffer?: boolean): boolean;
|
|
17
17
|
export declare function isMarketOrder(order: Order): boolean;
|
|
18
18
|
export declare function isLimitOrder(order: Order): boolean;
|
|
19
19
|
export declare function mustBeTriggered(order: Order): boolean;
|
package/lib/math/orders.js
CHANGED
|
@@ -168,13 +168,20 @@ function isSameDirection(firstDirection, secondDirection) {
|
|
|
168
168
|
return (((0, types_1.isVariant)(firstDirection, 'long') && (0, types_1.isVariant)(secondDirection, 'long')) ||
|
|
169
169
|
((0, types_1.isVariant)(firstDirection, 'short') && (0, types_1.isVariant)(secondDirection, 'short')));
|
|
170
170
|
}
|
|
171
|
-
function isOrderExpired(order, ts) {
|
|
171
|
+
function isOrderExpired(order, ts, enforceBuffer = false) {
|
|
172
172
|
if (mustBeTriggered(order) ||
|
|
173
173
|
!(0, types_1.isVariant)(order.status, 'open') ||
|
|
174
174
|
order.maxTs.eq(numericConstants_1.ZERO)) {
|
|
175
175
|
return false;
|
|
176
176
|
}
|
|
177
|
-
|
|
177
|
+
let maxTs;
|
|
178
|
+
if (enforceBuffer && isLimitOrder(order)) {
|
|
179
|
+
maxTs = order.maxTs.addn(15);
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
maxTs = order.maxTs;
|
|
183
|
+
}
|
|
184
|
+
return new anchor_1.BN(ts).gt(maxTs);
|
|
178
185
|
}
|
|
179
186
|
exports.isOrderExpired = isOrderExpired;
|
|
180
187
|
function isMarketOrder(order) {
|
package/lib/user.js
CHANGED
|
@@ -709,6 +709,13 @@ class User {
|
|
|
709
709
|
.div(numericConstants_1.MARGIN_PRECISION);
|
|
710
710
|
if (includeOpenOrders) {
|
|
711
711
|
baseAssetValue = baseAssetValue.add(new _1.BN(perpPosition.openOrders).mul(numericConstants_1.OPEN_ORDER_MARGIN_REQUIREMENT));
|
|
712
|
+
if (perpPosition.lpShares.gt(numericConstants_1.ZERO)) {
|
|
713
|
+
baseAssetValue = baseAssetValue.add(_1.BN.max(numericConstants_1.QUOTE_PRECISION, valuationPrice
|
|
714
|
+
.mul(market.amm.orderStepSize)
|
|
715
|
+
.mul(numericConstants_1.QUOTE_PRECISION)
|
|
716
|
+
.div(numericConstants_1.AMM_RESERVE_PRECISION)
|
|
717
|
+
.div(numericConstants_1.PRICE_PRECISION)));
|
|
718
|
+
}
|
|
712
719
|
}
|
|
713
720
|
}
|
|
714
721
|
return totalPerpValue.add(baseAssetValue);
|
package/package.json
CHANGED
package/src/dlob/DLOB.ts
CHANGED
|
@@ -931,12 +931,22 @@ export class DLOB {
|
|
|
931
931
|
|
|
932
932
|
// All bids/asks that can expire
|
|
933
933
|
// dont try to expire limit orders with tif as its inefficient use of blockspace
|
|
934
|
-
const bidGenerators = [
|
|
935
|
-
|
|
934
|
+
const bidGenerators = [
|
|
935
|
+
nodeLists.takingLimit.bid.getGenerator(),
|
|
936
|
+
nodeLists.restingLimit.bid.getGenerator(),
|
|
937
|
+
nodeLists.floatingLimit.bid.getGenerator(),
|
|
938
|
+
nodeLists.market.bid.getGenerator(),
|
|
939
|
+
];
|
|
940
|
+
const askGenerators = [
|
|
941
|
+
nodeLists.takingLimit.ask.getGenerator(),
|
|
942
|
+
nodeLists.restingLimit.ask.getGenerator(),
|
|
943
|
+
nodeLists.floatingLimit.ask.getGenerator(),
|
|
944
|
+
nodeLists.market.ask.getGenerator(),
|
|
945
|
+
];
|
|
936
946
|
|
|
937
947
|
for (const bidGenerator of bidGenerators) {
|
|
938
948
|
for (const bid of bidGenerator) {
|
|
939
|
-
if (isOrderExpired(bid.order, ts)) {
|
|
949
|
+
if (isOrderExpired(bid.order, ts, true)) {
|
|
940
950
|
nodesToFill.push({
|
|
941
951
|
node: bid,
|
|
942
952
|
makerNodes: [],
|
|
@@ -947,7 +957,7 @@ export class DLOB {
|
|
|
947
957
|
|
|
948
958
|
for (const askGenerator of askGenerators) {
|
|
949
959
|
for (const ask of askGenerator) {
|
|
950
|
-
if (isOrderExpired(ask.order, ts)) {
|
|
960
|
+
if (isOrderExpired(ask.order, ts, true)) {
|
|
951
961
|
nodesToFill.push({
|
|
952
962
|
node: ask,
|
|
953
963
|
makerNodes: [],
|
package/src/math/orders.ts
CHANGED
|
@@ -279,7 +279,11 @@ function isSameDirection(
|
|
|
279
279
|
);
|
|
280
280
|
}
|
|
281
281
|
|
|
282
|
-
export function isOrderExpired(
|
|
282
|
+
export function isOrderExpired(
|
|
283
|
+
order: Order,
|
|
284
|
+
ts: number,
|
|
285
|
+
enforceBuffer = false
|
|
286
|
+
): boolean {
|
|
283
287
|
if (
|
|
284
288
|
mustBeTriggered(order) ||
|
|
285
289
|
!isVariant(order.status, 'open') ||
|
|
@@ -288,7 +292,14 @@ export function isOrderExpired(order: Order, ts: number): boolean {
|
|
|
288
292
|
return false;
|
|
289
293
|
}
|
|
290
294
|
|
|
291
|
-
|
|
295
|
+
let maxTs;
|
|
296
|
+
if (enforceBuffer && isLimitOrder(order)) {
|
|
297
|
+
maxTs = order.maxTs.addn(15);
|
|
298
|
+
} else {
|
|
299
|
+
maxTs = order.maxTs;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
return new BN(ts).gt(maxTs);
|
|
292
303
|
}
|
|
293
304
|
|
|
294
305
|
export function isMarketOrder(order: Order): boolean {
|
package/src/user.ts
CHANGED
|
@@ -1290,6 +1290,19 @@ export class User {
|
|
|
1290
1290
|
baseAssetValue = baseAssetValue.add(
|
|
1291
1291
|
new BN(perpPosition.openOrders).mul(OPEN_ORDER_MARGIN_REQUIREMENT)
|
|
1292
1292
|
);
|
|
1293
|
+
|
|
1294
|
+
if (perpPosition.lpShares.gt(ZERO)) {
|
|
1295
|
+
baseAssetValue = baseAssetValue.add(
|
|
1296
|
+
BN.max(
|
|
1297
|
+
QUOTE_PRECISION,
|
|
1298
|
+
valuationPrice
|
|
1299
|
+
.mul(market.amm.orderStepSize)
|
|
1300
|
+
.mul(QUOTE_PRECISION)
|
|
1301
|
+
.div(AMM_RESERVE_PRECISION)
|
|
1302
|
+
.div(PRICE_PRECISION)
|
|
1303
|
+
)
|
|
1304
|
+
);
|
|
1305
|
+
}
|
|
1293
1306
|
}
|
|
1294
1307
|
}
|
|
1295
1308
|
|