@drift-labs/sdk 2.64.0-beta.0 → 2.64.0-beta.1
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/decode/user.js +1 -1
- package/lib/dlob/orderBookLevels.js +13 -3
- package/package.json +1 -1
- package/src/decode/user.ts +1 -1
- package/src/dlob/orderBookLevels.ts +18 -4
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.64.0-beta.
|
|
1
|
+
2.64.0-beta.1
|
package/lib/decode/user.js
CHANGED
|
@@ -94,7 +94,7 @@ function decodeUser(buffer) {
|
|
|
94
94
|
offset += 8;
|
|
95
95
|
const lastQuoteAssetAmountPerLp = readSignedBigInt64LE(buffer, offset);
|
|
96
96
|
offset += 8;
|
|
97
|
-
const remainderBaseAssetAmount = buffer.
|
|
97
|
+
const remainderBaseAssetAmount = buffer.readInt32LE(offset);
|
|
98
98
|
offset += 4;
|
|
99
99
|
const marketIndex = buffer.readUInt16LE(offset);
|
|
100
100
|
offset += 3;
|
|
@@ -213,6 +213,15 @@ function groupL2(l2, grouping, depth) {
|
|
|
213
213
|
};
|
|
214
214
|
}
|
|
215
215
|
exports.groupL2 = groupL2;
|
|
216
|
+
function cloneL2Level(level) {
|
|
217
|
+
if (!level)
|
|
218
|
+
return level;
|
|
219
|
+
return {
|
|
220
|
+
price: level.price,
|
|
221
|
+
size: level.size,
|
|
222
|
+
sources: { ...level.sources },
|
|
223
|
+
};
|
|
224
|
+
}
|
|
216
225
|
function groupL2Levels(levels, grouping, direction, depth) {
|
|
217
226
|
const groupedLevels = [];
|
|
218
227
|
for (const level of levels) {
|
|
@@ -220,7 +229,8 @@ function groupL2Levels(levels, grouping, direction, depth) {
|
|
|
220
229
|
const size = level.size;
|
|
221
230
|
if (groupedLevels.length > 0 &&
|
|
222
231
|
groupedLevels[groupedLevels.length - 1].price.eq(price)) {
|
|
223
|
-
|
|
232
|
+
// Clones things so we don't mutate the original
|
|
233
|
+
const currentLevel = cloneL2Level(groupedLevels[groupedLevels.length - 1]);
|
|
224
234
|
currentLevel.size = currentLevel.size.add(size);
|
|
225
235
|
for (const [source, size] of Object.entries(level.sources)) {
|
|
226
236
|
if (currentLevel.sources[source]) {
|
|
@@ -302,8 +312,8 @@ function uncrossL2(bids, asks, oraclePrice, oracleTwap5Min, markTwap5Min, groupi
|
|
|
302
312
|
let bidIndex = 0;
|
|
303
313
|
let askIndex = 0;
|
|
304
314
|
while (bidIndex < bids.length || askIndex < asks.length) {
|
|
305
|
-
const nextBid = bids[bidIndex];
|
|
306
|
-
const nextAsk = asks[askIndex];
|
|
315
|
+
const nextBid = cloneL2Level(bids[bidIndex]);
|
|
316
|
+
const nextAsk = cloneL2Level(asks[askIndex]);
|
|
307
317
|
if (!nextBid) {
|
|
308
318
|
newAsks.push(nextAsk);
|
|
309
319
|
askIndex++;
|
package/package.json
CHANGED
package/src/decode/user.ts
CHANGED
|
@@ -110,7 +110,7 @@ export function decodeUser(buffer: Buffer): UserAccount {
|
|
|
110
110
|
offset += 8;
|
|
111
111
|
const lastQuoteAssetAmountPerLp = readSignedBigInt64LE(buffer, offset);
|
|
112
112
|
offset += 8;
|
|
113
|
-
const remainderBaseAssetAmount = buffer.
|
|
113
|
+
const remainderBaseAssetAmount = buffer.readInt32LE(offset);
|
|
114
114
|
offset += 4;
|
|
115
115
|
const marketIndex = buffer.readUInt16LE(offset);
|
|
116
116
|
offset += 3;
|
|
@@ -369,13 +369,23 @@ export function groupL2(
|
|
|
369
369
|
};
|
|
370
370
|
}
|
|
371
371
|
|
|
372
|
+
function cloneL2Level(level: L2Level): L2Level {
|
|
373
|
+
if (!level) return level;
|
|
374
|
+
|
|
375
|
+
return {
|
|
376
|
+
price: level.price,
|
|
377
|
+
size: level.size,
|
|
378
|
+
sources: { ...level.sources },
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
|
|
372
382
|
function groupL2Levels(
|
|
373
383
|
levels: L2Level[],
|
|
374
384
|
grouping: BN,
|
|
375
385
|
direction: PositionDirection,
|
|
376
386
|
depth: number
|
|
377
387
|
): L2Level[] {
|
|
378
|
-
const groupedLevels = [];
|
|
388
|
+
const groupedLevels: L2Level[] = [];
|
|
379
389
|
for (const level of levels) {
|
|
380
390
|
const price = standardizePrice(level.price, grouping, direction);
|
|
381
391
|
const size = level.size;
|
|
@@ -383,7 +393,11 @@ function groupL2Levels(
|
|
|
383
393
|
groupedLevels.length > 0 &&
|
|
384
394
|
groupedLevels[groupedLevels.length - 1].price.eq(price)
|
|
385
395
|
) {
|
|
386
|
-
|
|
396
|
+
// Clones things so we don't mutate the original
|
|
397
|
+
const currentLevel = cloneL2Level(
|
|
398
|
+
groupedLevels[groupedLevels.length - 1]
|
|
399
|
+
);
|
|
400
|
+
|
|
387
401
|
currentLevel.size = currentLevel.size.add(size);
|
|
388
402
|
for (const [source, size] of Object.entries(level.sources)) {
|
|
389
403
|
if (currentLevel.sources[source]) {
|
|
@@ -479,8 +493,8 @@ export function uncrossL2(
|
|
|
479
493
|
let bidIndex = 0;
|
|
480
494
|
let askIndex = 0;
|
|
481
495
|
while (bidIndex < bids.length || askIndex < asks.length) {
|
|
482
|
-
const nextBid = bids[bidIndex];
|
|
483
|
-
const nextAsk = asks[askIndex];
|
|
496
|
+
const nextBid = cloneL2Level(bids[bidIndex]);
|
|
497
|
+
const nextAsk = cloneL2Level(asks[askIndex]);
|
|
484
498
|
|
|
485
499
|
if (!nextBid) {
|
|
486
500
|
newAsks.push(nextAsk);
|