@drift-labs/sdk 2.64.0-beta.3 → 2.65.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/dlob/orderBookLevels.js +1 -1
- package/lib/idl/drift.json +1 -1
- package/package.json +1 -1
- package/src/dlob/orderBookLevels.ts +1 -1
- package/src/idl/drift.json +1 -1
- package/tests/dlob/test.ts +85 -0
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.
|
|
1
|
+
2.65.0-beta.1
|
|
@@ -324,7 +324,7 @@ function uncrossL2(bids, asks, oraclePrice, oracleTwap5Min, markTwap5Min, groupi
|
|
|
324
324
|
bidIndex++;
|
|
325
325
|
continue;
|
|
326
326
|
}
|
|
327
|
-
if (nextBid.price.
|
|
327
|
+
if (nextBid.price.gte(nextAsk.price)) {
|
|
328
328
|
if (userBids.has(nextBid.price.toString())) {
|
|
329
329
|
newBids.push(nextBid);
|
|
330
330
|
bidIndex++;
|
package/lib/idl/drift.json
CHANGED
package/package.json
CHANGED
package/src/idl/drift.json
CHANGED
package/tests/dlob/test.ts
CHANGED
|
@@ -24,11 +24,32 @@ import {
|
|
|
24
24
|
QUOTE_PRECISION,
|
|
25
25
|
isVariant,
|
|
26
26
|
uncrossL2,
|
|
27
|
+
L2Level,
|
|
27
28
|
} from '../../src';
|
|
28
29
|
|
|
29
30
|
import { mockPerpMarkets, mockSpotMarkets, mockStateAccount } from './helpers';
|
|
30
31
|
import { DLOBOrdersCoder } from '../../src/dlob/DLOBOrders';
|
|
31
32
|
|
|
33
|
+
// Returns true if asks are sorted ascending
|
|
34
|
+
const asksAreSortedAsc = (asks: L2Level[]) => {
|
|
35
|
+
return asks.every((ask, i) => {
|
|
36
|
+
if (i === 0) {
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
return ask.price.gt(asks[i - 1].price);
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// Returns true if asks are sorted descending
|
|
44
|
+
const bidsAreSortedDesc = (bids: L2Level[]) => {
|
|
45
|
+
return bids.every((bid, i) => {
|
|
46
|
+
if (i === 0) {
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
return bid.price.lt(bids[i - 1].price);
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
|
|
32
53
|
function insertOrderToDLOB(
|
|
33
54
|
dlob: DLOB,
|
|
34
55
|
userAccount: PublicKey,
|
|
@@ -6592,4 +6613,68 @@ describe('Uncross L2', () => {
|
|
|
6592
6613
|
new BN(1).mul(BASE_PRECISION).toString()
|
|
6593
6614
|
);
|
|
6594
6615
|
});
|
|
6616
|
+
|
|
6617
|
+
it('Handles edge case bide and asks with large cross and an overlapping level', () => {
|
|
6618
|
+
|
|
6619
|
+
const bids = [
|
|
6620
|
+
"104411000",
|
|
6621
|
+
"103835800",
|
|
6622
|
+
"103826259",
|
|
6623
|
+
"103825000",
|
|
6624
|
+
"103822000",
|
|
6625
|
+
"103821500",
|
|
6626
|
+
"103820283",
|
|
6627
|
+
"103816900",
|
|
6628
|
+
"103816000",
|
|
6629
|
+
"103815121",
|
|
6630
|
+
].map(priceStr => (
|
|
6631
|
+
{
|
|
6632
|
+
price: new BN(priceStr),
|
|
6633
|
+
size: new BN(1).mul(BASE_PRECISION),
|
|
6634
|
+
sources: { vamm: new BN(1).mul(BASE_PRECISION) },
|
|
6635
|
+
}
|
|
6636
|
+
));
|
|
6637
|
+
|
|
6638
|
+
const asks = [
|
|
6639
|
+
"103822000",
|
|
6640
|
+
"103838354",
|
|
6641
|
+
"103843087",
|
|
6642
|
+
"103843351",
|
|
6643
|
+
"103843880",
|
|
6644
|
+
"103845114",
|
|
6645
|
+
"103846148",
|
|
6646
|
+
"103850100",
|
|
6647
|
+
"103851300",
|
|
6648
|
+
"103854304",
|
|
6649
|
+
].map(priceStr => ({
|
|
6650
|
+
price: new BN(priceStr),
|
|
6651
|
+
size: new BN(1).mul(BASE_PRECISION),
|
|
6652
|
+
sources: { vamm: new BN(1).mul(BASE_PRECISION) },
|
|
6653
|
+
}));
|
|
6654
|
+
|
|
6655
|
+
expect(asksAreSortedAsc(asks), "Input asks are ascending").to.be.true;
|
|
6656
|
+
expect(bidsAreSortedDesc(bids), "Input bids are descending").to.be.true;
|
|
6657
|
+
|
|
6658
|
+
const oraclePrice = new BN("103649895");
|
|
6659
|
+
const oraclePrice5Min = new BN("103285000");
|
|
6660
|
+
const markPrice5Min = new BN("103371000");
|
|
6661
|
+
|
|
6662
|
+
const groupingSize = new BN("100");
|
|
6663
|
+
|
|
6664
|
+
const userAsks = new Set<string>();
|
|
6665
|
+
|
|
6666
|
+
const { bids: newBids, asks: newAsks } = uncrossL2(
|
|
6667
|
+
bids,
|
|
6668
|
+
asks,
|
|
6669
|
+
oraclePrice,
|
|
6670
|
+
oraclePrice5Min,
|
|
6671
|
+
markPrice5Min,
|
|
6672
|
+
groupingSize,
|
|
6673
|
+
new Set<string>(),
|
|
6674
|
+
userAsks
|
|
6675
|
+
);
|
|
6676
|
+
|
|
6677
|
+
expect(asksAreSortedAsc(newAsks), "Uncrossed asks are ascending").to.be.true;
|
|
6678
|
+
expect(bidsAreSortedDesc(newBids), "Uncrossed bids are descending").to.be.true;
|
|
6679
|
+
});
|
|
6595
6680
|
});
|