@drift-labs/sdk 2.83.0-beta.10 → 2.83.0-beta.12
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 +5 -5
- package/lib/dlob/DLOB.js +8 -8
- package/lib/driftClient.d.ts +1 -1
- package/lib/driftClient.js +2 -2
- package/lib/math/auction.js +2 -2
- package/lib/math/orders.js +1 -1
- package/package.json +1 -1
- package/src/dlob/DLOB.ts +17 -9
- package/src/driftClient.ts +8 -4
- package/src/math/auction.ts +2 -2
- package/src/math/orders.ts +5 -2
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.83.0-beta.
|
|
1
|
+
2.83.0-beta.12
|
package/lib/dlob/DLOB.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ type OrderBookCallback = () => void;
|
|
|
31
31
|
* Receives a DLOBNode and is expected to return true if the node should
|
|
32
32
|
* be taken into account when generating, or false otherwise.
|
|
33
33
|
*
|
|
34
|
-
* Currently used in
|
|
34
|
+
* Currently used in functions that rely on getBestNode
|
|
35
35
|
*/
|
|
36
36
|
export type DLOBFilterFcn = (node: DLOBNode) => boolean;
|
|
37
37
|
export type NodeToFill = {
|
|
@@ -79,13 +79,13 @@ export declare class DLOB {
|
|
|
79
79
|
findNodesCrossingFallbackLiquidity(marketType: MarketType, slot: number, oraclePriceData: OraclePriceData, nodeGenerator: Generator<DLOBNode>, doesCross: (nodePrice: BN | undefined) => boolean, minAuctionDuration: number): NodeToFill[];
|
|
80
80
|
findExpiredNodesToFill(marketIndex: number, ts: number, marketType: MarketType): NodeToFill[];
|
|
81
81
|
findJitAuctionNodesToFill(marketIndex: number, slot: number, oraclePriceData: OraclePriceData, marketType: MarketType): NodeToFill[];
|
|
82
|
-
getTakingBids(marketIndex: number, marketType: MarketType, slot: number, oraclePriceData: OraclePriceData): Generator<DLOBNode>;
|
|
83
|
-
getTakingAsks(marketIndex: number, marketType: MarketType, slot: number, oraclePriceData: OraclePriceData): Generator<DLOBNode>;
|
|
82
|
+
getTakingBids(marketIndex: number, marketType: MarketType, slot: number, oraclePriceData: OraclePriceData, filterFcn?: DLOBFilterFcn): Generator<DLOBNode>;
|
|
83
|
+
getTakingAsks(marketIndex: number, marketType: MarketType, slot: number, oraclePriceData: OraclePriceData, filterFcn?: DLOBFilterFcn): Generator<DLOBNode>;
|
|
84
84
|
private getBestNode;
|
|
85
85
|
getRestingLimitAsks(marketIndex: number, slot: number, marketType: MarketType, oraclePriceData: OraclePriceData, filterFcn?: DLOBFilterFcn): Generator<DLOBNode>;
|
|
86
86
|
getRestingLimitBids(marketIndex: number, slot: number, marketType: MarketType, oraclePriceData: OraclePriceData, filterFcn?: DLOBFilterFcn): Generator<DLOBNode>;
|
|
87
|
-
getAsks(marketIndex: number, fallbackAsk: BN | undefined, slot: number, marketType: MarketType, oraclePriceData: OraclePriceData): Generator<DLOBNode>;
|
|
88
|
-
getBids(marketIndex: number, fallbackBid: BN | undefined, slot: number, marketType: MarketType, oraclePriceData: OraclePriceData): Generator<DLOBNode>;
|
|
87
|
+
getAsks(marketIndex: number, fallbackAsk: BN | undefined, slot: number, marketType: MarketType, oraclePriceData: OraclePriceData, filterFcn?: DLOBFilterFcn): Generator<DLOBNode>;
|
|
88
|
+
getBids(marketIndex: number, fallbackBid: BN | undefined, slot: number, marketType: MarketType, oraclePriceData: OraclePriceData, filterFcn?: DLOBFilterFcn): Generator<DLOBNode>;
|
|
89
89
|
findCrossingRestingLimitOrders(marketIndex: number, slot: number, marketType: MarketType, oraclePriceData: OraclePriceData): NodeToFill[];
|
|
90
90
|
determineMakerAndTaker(askNode: DLOBNode, bidNode: DLOBNode): {
|
|
91
91
|
takerNode: DLOBNode;
|
package/lib/dlob/DLOB.js
CHANGED
|
@@ -565,7 +565,7 @@ class DLOB {
|
|
|
565
565
|
}
|
|
566
566
|
return nodesToFill;
|
|
567
567
|
}
|
|
568
|
-
*getTakingBids(marketIndex, marketType, slot, oraclePriceData) {
|
|
568
|
+
*getTakingBids(marketIndex, marketType, slot, oraclePriceData, filterFcn) {
|
|
569
569
|
const marketTypeStr = (0, __1.getVariant)(marketType);
|
|
570
570
|
const orderLists = this.orderLists.get(marketTypeStr).get(marketIndex);
|
|
571
571
|
if (!orderLists) {
|
|
@@ -578,9 +578,9 @@ class DLOB {
|
|
|
578
578
|
];
|
|
579
579
|
yield* this.getBestNode(generatorList, oraclePriceData, slot, (bestNode, currentNode) => {
|
|
580
580
|
return bestNode.order.slot.lt(currentNode.order.slot);
|
|
581
|
-
});
|
|
581
|
+
}, filterFcn);
|
|
582
582
|
}
|
|
583
|
-
*getTakingAsks(marketIndex, marketType, slot, oraclePriceData) {
|
|
583
|
+
*getTakingAsks(marketIndex, marketType, slot, oraclePriceData, filterFcn) {
|
|
584
584
|
const marketTypeStr = (0, __1.getVariant)(marketType);
|
|
585
585
|
const orderLists = this.orderLists.get(marketTypeStr).get(marketIndex);
|
|
586
586
|
if (!orderLists) {
|
|
@@ -593,7 +593,7 @@ class DLOB {
|
|
|
593
593
|
];
|
|
594
594
|
yield* this.getBestNode(generatorList, oraclePriceData, slot, (bestNode, currentNode) => {
|
|
595
595
|
return bestNode.order.slot.lt(currentNode.order.slot);
|
|
596
|
-
});
|
|
596
|
+
}, filterFcn);
|
|
597
597
|
}
|
|
598
598
|
*getBestNode(generatorList, oraclePriceData, slot, compareFcn, filterFcn) {
|
|
599
599
|
const generators = generatorList.map((generator) => {
|
|
@@ -675,7 +675,7 @@ class DLOB {
|
|
|
675
675
|
.gt(currentNode.getPrice(oraclePriceData, slot));
|
|
676
676
|
}, filterFcn);
|
|
677
677
|
}
|
|
678
|
-
*getAsks(marketIndex, fallbackAsk, slot, marketType, oraclePriceData) {
|
|
678
|
+
*getAsks(marketIndex, fallbackAsk, slot, marketType, oraclePriceData, filterFcn) {
|
|
679
679
|
if ((0, __1.isVariant)(marketType, 'spot') && !oraclePriceData) {
|
|
680
680
|
throw new Error('Must provide OraclePriceData to get spot asks');
|
|
681
681
|
}
|
|
@@ -706,9 +706,9 @@ class DLOB {
|
|
|
706
706
|
return bestNode
|
|
707
707
|
.getPrice(oraclePriceData, slot)
|
|
708
708
|
.lt(currentNode.getPrice(oraclePriceData, slot));
|
|
709
|
-
});
|
|
709
|
+
}, filterFcn);
|
|
710
710
|
}
|
|
711
|
-
*getBids(marketIndex, fallbackBid, slot, marketType, oraclePriceData) {
|
|
711
|
+
*getBids(marketIndex, fallbackBid, slot, marketType, oraclePriceData, filterFcn) {
|
|
712
712
|
if ((0, __1.isVariant)(marketType, 'spot') && !oraclePriceData) {
|
|
713
713
|
throw new Error('Must provide OraclePriceData to get spot bids');
|
|
714
714
|
}
|
|
@@ -739,7 +739,7 @@ class DLOB {
|
|
|
739
739
|
return bestNode
|
|
740
740
|
.getPrice(oraclePriceData, slot)
|
|
741
741
|
.gt(currentNode.getPrice(oraclePriceData, slot));
|
|
742
|
-
});
|
|
742
|
+
}, filterFcn);
|
|
743
743
|
}
|
|
744
744
|
findCrossingRestingLimitOrders(marketIndex, slot, marketType, oraclePriceData) {
|
|
745
745
|
const nodesToFill = new Array();
|
package/lib/driftClient.d.ts
CHANGED
|
@@ -593,7 +593,7 @@ export declare class DriftClient {
|
|
|
593
593
|
settleeUserAccount: UserAccount;
|
|
594
594
|
}[], marketIndexes: number[], opts?: {
|
|
595
595
|
filterInvalidMarkets?: boolean;
|
|
596
|
-
}): Promise<TransactionSignature>;
|
|
596
|
+
}, txParams?: TxParams): Promise<TransactionSignature>;
|
|
597
597
|
getSettlePNLsIxs(users: {
|
|
598
598
|
settleeUserAccountPublicKey: PublicKey;
|
|
599
599
|
settleeUserAccount: UserAccount;
|
package/lib/driftClient.js
CHANGED
|
@@ -2949,7 +2949,7 @@ class DriftClient {
|
|
|
2949
2949
|
remainingAccounts,
|
|
2950
2950
|
});
|
|
2951
2951
|
}
|
|
2952
|
-
async settlePNLs(users, marketIndexes, opts) {
|
|
2952
|
+
async settlePNLs(users, marketIndexes, opts, txParams) {
|
|
2953
2953
|
const filterInvalidMarkets = opts === null || opts === void 0 ? void 0 : opts.filterInvalidMarkets;
|
|
2954
2954
|
// # Filter market indexes by markets with valid oracle
|
|
2955
2955
|
const marketIndexToSettle = filterInvalidMarkets
|
|
@@ -2969,7 +2969,7 @@ class DriftClient {
|
|
|
2969
2969
|
}
|
|
2970
2970
|
// # Settle filtered market indexes
|
|
2971
2971
|
const ixs = await this.getSettlePNLsIxs(users, marketIndexToSettle);
|
|
2972
|
-
const tx = await this.buildTransaction(ixs, {
|
|
2972
|
+
const tx = await this.buildTransaction(ixs, txParams !== null && txParams !== void 0 ? txParams : {
|
|
2973
2973
|
computeUnits: 1400000,
|
|
2974
2974
|
});
|
|
2975
2975
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
package/lib/math/auction.js
CHANGED
|
@@ -69,7 +69,7 @@ function getAuctionPriceForOracleOffsetAuction(order, slot, oraclePrice) {
|
|
|
69
69
|
const deltaDenominator = new _1.BN(order.auctionDuration);
|
|
70
70
|
const deltaNumerator = _1.BN.min(slotsElapsed, deltaDenominator);
|
|
71
71
|
if (deltaDenominator.eq(_1.ZERO)) {
|
|
72
|
-
return oraclePrice.add(order.auctionEndPrice);
|
|
72
|
+
return _1.BN.max(oraclePrice.add(order.auctionEndPrice), _1.ONE);
|
|
73
73
|
}
|
|
74
74
|
let priceOffsetDelta;
|
|
75
75
|
if ((0, types_1.isVariant)(order.direction, 'long')) {
|
|
@@ -91,7 +91,7 @@ function getAuctionPriceForOracleOffsetAuction(order, slot, oraclePrice) {
|
|
|
91
91
|
else {
|
|
92
92
|
priceOffset = order.auctionStartPrice.sub(priceOffsetDelta);
|
|
93
93
|
}
|
|
94
|
-
return oraclePrice.add(priceOffset);
|
|
94
|
+
return _1.BN.max(oraclePrice.add(priceOffset), _1.ONE);
|
|
95
95
|
}
|
|
96
96
|
exports.getAuctionPriceForOracleOffsetAuction = getAuctionPriceForOracleOffsetAuction;
|
|
97
97
|
function deriveOracleAuctionParams({ direction, oraclePrice, auctionStartPrice, auctionEndPrice, limitPrice, }) {
|
package/lib/math/orders.js
CHANGED
|
@@ -102,7 +102,7 @@ function getLimitPrice(order, oraclePriceData, slot, fallbackPrice) {
|
|
|
102
102
|
limitPrice = (0, auction_1.getAuctionPrice)(order, slot, oraclePriceData.price);
|
|
103
103
|
}
|
|
104
104
|
else if (order.oraclePriceOffset !== 0) {
|
|
105
|
-
limitPrice = oraclePriceData.price.add(new anchor_1.BN(order.oraclePriceOffset));
|
|
105
|
+
limitPrice = anchor_1.BN.max(oraclePriceData.price.add(new anchor_1.BN(order.oraclePriceOffset)), numericConstants_1.ONE);
|
|
106
106
|
}
|
|
107
107
|
else if (order.price.eq(numericConstants_1.ZERO)) {
|
|
108
108
|
limitPrice = fallbackPrice;
|
package/package.json
CHANGED
package/src/dlob/DLOB.ts
CHANGED
|
@@ -76,7 +76,7 @@ type OrderBookCallback = () => void;
|
|
|
76
76
|
* Receives a DLOBNode and is expected to return true if the node should
|
|
77
77
|
* be taken into account when generating, or false otherwise.
|
|
78
78
|
*
|
|
79
|
-
* Currently used in
|
|
79
|
+
* Currently used in functions that rely on getBestNode
|
|
80
80
|
*/
|
|
81
81
|
export type DLOBFilterFcn = (node: DLOBNode) => boolean;
|
|
82
82
|
|
|
@@ -1046,7 +1046,8 @@ export class DLOB {
|
|
|
1046
1046
|
marketIndex: number,
|
|
1047
1047
|
marketType: MarketType,
|
|
1048
1048
|
slot: number,
|
|
1049
|
-
oraclePriceData: OraclePriceData
|
|
1049
|
+
oraclePriceData: OraclePriceData,
|
|
1050
|
+
filterFcn?: DLOBFilterFcn
|
|
1050
1051
|
): Generator<DLOBNode> {
|
|
1051
1052
|
const marketTypeStr = getVariant(marketType) as MarketTypeStr;
|
|
1052
1053
|
const orderLists = this.orderLists.get(marketTypeStr).get(marketIndex);
|
|
@@ -1067,7 +1068,8 @@ export class DLOB {
|
|
|
1067
1068
|
slot,
|
|
1068
1069
|
(bestNode, currentNode) => {
|
|
1069
1070
|
return bestNode.order.slot.lt(currentNode.order.slot);
|
|
1070
|
-
}
|
|
1071
|
+
},
|
|
1072
|
+
filterFcn
|
|
1071
1073
|
);
|
|
1072
1074
|
}
|
|
1073
1075
|
|
|
@@ -1075,7 +1077,8 @@ export class DLOB {
|
|
|
1075
1077
|
marketIndex: number,
|
|
1076
1078
|
marketType: MarketType,
|
|
1077
1079
|
slot: number,
|
|
1078
|
-
oraclePriceData: OraclePriceData
|
|
1080
|
+
oraclePriceData: OraclePriceData,
|
|
1081
|
+
filterFcn?: DLOBFilterFcn
|
|
1079
1082
|
): Generator<DLOBNode> {
|
|
1080
1083
|
const marketTypeStr = getVariant(marketType) as MarketTypeStr;
|
|
1081
1084
|
const orderLists = this.orderLists.get(marketTypeStr).get(marketIndex);
|
|
@@ -1096,7 +1099,8 @@ export class DLOB {
|
|
|
1096
1099
|
slot,
|
|
1097
1100
|
(bestNode, currentNode) => {
|
|
1098
1101
|
return bestNode.order.slot.lt(currentNode.order.slot);
|
|
1099
|
-
}
|
|
1102
|
+
},
|
|
1103
|
+
filterFcn
|
|
1100
1104
|
);
|
|
1101
1105
|
}
|
|
1102
1106
|
|
|
@@ -1241,7 +1245,8 @@ export class DLOB {
|
|
|
1241
1245
|
fallbackAsk: BN | undefined,
|
|
1242
1246
|
slot: number,
|
|
1243
1247
|
marketType: MarketType,
|
|
1244
|
-
oraclePriceData: OraclePriceData
|
|
1248
|
+
oraclePriceData: OraclePriceData,
|
|
1249
|
+
filterFcn?: DLOBFilterFcn
|
|
1245
1250
|
): Generator<DLOBNode> {
|
|
1246
1251
|
if (isVariant(marketType, 'spot') && !oraclePriceData) {
|
|
1247
1252
|
throw new Error('Must provide OraclePriceData to get spot asks');
|
|
@@ -1284,7 +1289,8 @@ export class DLOB {
|
|
|
1284
1289
|
return bestNode
|
|
1285
1290
|
.getPrice(oraclePriceData, slot)
|
|
1286
1291
|
.lt(currentNode.getPrice(oraclePriceData, slot));
|
|
1287
|
-
}
|
|
1292
|
+
},
|
|
1293
|
+
filterFcn
|
|
1288
1294
|
);
|
|
1289
1295
|
}
|
|
1290
1296
|
|
|
@@ -1293,7 +1299,8 @@ export class DLOB {
|
|
|
1293
1299
|
fallbackBid: BN | undefined,
|
|
1294
1300
|
slot: number,
|
|
1295
1301
|
marketType: MarketType,
|
|
1296
|
-
oraclePriceData: OraclePriceData
|
|
1302
|
+
oraclePriceData: OraclePriceData,
|
|
1303
|
+
filterFcn?: DLOBFilterFcn
|
|
1297
1304
|
): Generator<DLOBNode> {
|
|
1298
1305
|
if (isVariant(marketType, 'spot') && !oraclePriceData) {
|
|
1299
1306
|
throw new Error('Must provide OraclePriceData to get spot bids');
|
|
@@ -1336,7 +1343,8 @@ export class DLOB {
|
|
|
1336
1343
|
return bestNode
|
|
1337
1344
|
.getPrice(oraclePriceData, slot)
|
|
1338
1345
|
.gt(currentNode.getPrice(oraclePriceData, slot));
|
|
1339
|
-
}
|
|
1346
|
+
},
|
|
1347
|
+
filterFcn
|
|
1340
1348
|
);
|
|
1341
1349
|
}
|
|
1342
1350
|
|
package/src/driftClient.ts
CHANGED
|
@@ -5385,7 +5385,8 @@ export class DriftClient {
|
|
|
5385
5385
|
marketIndexes: number[],
|
|
5386
5386
|
opts?: {
|
|
5387
5387
|
filterInvalidMarkets?: boolean;
|
|
5388
|
-
}
|
|
5388
|
+
},
|
|
5389
|
+
txParams?: TxParams
|
|
5389
5390
|
): Promise<TransactionSignature> {
|
|
5390
5391
|
const filterInvalidMarkets = opts?.filterInvalidMarkets;
|
|
5391
5392
|
|
|
@@ -5418,9 +5419,12 @@ export class DriftClient {
|
|
|
5418
5419
|
// # Settle filtered market indexes
|
|
5419
5420
|
const ixs = await this.getSettlePNLsIxs(users, marketIndexToSettle);
|
|
5420
5421
|
|
|
5421
|
-
const tx = await this.buildTransaction(
|
|
5422
|
-
|
|
5423
|
-
|
|
5422
|
+
const tx = await this.buildTransaction(
|
|
5423
|
+
ixs,
|
|
5424
|
+
txParams ?? {
|
|
5425
|
+
computeUnits: 1_400_000,
|
|
5426
|
+
}
|
|
5427
|
+
);
|
|
5424
5428
|
|
|
5425
5429
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
5426
5430
|
return txSig;
|
package/src/math/auction.ts
CHANGED
|
@@ -88,7 +88,7 @@ export function getAuctionPriceForOracleOffsetAuction(
|
|
|
88
88
|
const deltaNumerator = BN.min(slotsElapsed, deltaDenominator);
|
|
89
89
|
|
|
90
90
|
if (deltaDenominator.eq(ZERO)) {
|
|
91
|
-
return oraclePrice.add(order.auctionEndPrice);
|
|
91
|
+
return BN.max(oraclePrice.add(order.auctionEndPrice), ONE);
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
let priceOffsetDelta;
|
|
@@ -111,7 +111,7 @@ export function getAuctionPriceForOracleOffsetAuction(
|
|
|
111
111
|
priceOffset = order.auctionStartPrice.sub(priceOffsetDelta);
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
-
return oraclePrice.add(priceOffset);
|
|
114
|
+
return BN.max(oraclePrice.add(priceOffset), ONE);
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
export function deriveOracleAuctionParams({
|
package/src/math/orders.ts
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
Order,
|
|
8
8
|
PositionDirection,
|
|
9
9
|
} from '../types';
|
|
10
|
-
import { ZERO, TWO } from '../constants/numericConstants';
|
|
10
|
+
import { ZERO, TWO, ONE } from '../constants/numericConstants';
|
|
11
11
|
import { BN } from '@coral-xyz/anchor';
|
|
12
12
|
import { OraclePriceData } from '../oracles/types';
|
|
13
13
|
import {
|
|
@@ -160,7 +160,10 @@ export function getLimitPrice(
|
|
|
160
160
|
if (hasAuctionPrice(order, slot)) {
|
|
161
161
|
limitPrice = getAuctionPrice(order, slot, oraclePriceData.price);
|
|
162
162
|
} else if (order.oraclePriceOffset !== 0) {
|
|
163
|
-
limitPrice =
|
|
163
|
+
limitPrice = BN.max(
|
|
164
|
+
oraclePriceData.price.add(new BN(order.oraclePriceOffset)),
|
|
165
|
+
ONE
|
|
166
|
+
);
|
|
164
167
|
} else if (order.price.eq(ZERO)) {
|
|
165
168
|
limitPrice = fallbackPrice;
|
|
166
169
|
} else {
|