@drift-labs/sdk 2.49.0-beta.1 → 2.49.0-beta.10
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/accounts/{mockUserAccountSubscriber.d.ts → basicUserAccountSubscriber.d.ts} +2 -2
- package/lib/accounts/{mockUserAccountSubscriber.js → basicUserAccountSubscriber.js} +9 -6
- package/lib/accounts/pollingInsuranceFundStakeAccountSubscriber.d.ts +29 -0
- package/lib/accounts/pollingInsuranceFundStakeAccountSubscriber.js +110 -0
- package/lib/accounts/types.d.ts +14 -1
- package/lib/accounts/webSocketInsuranceFundStakeAccountSubscriber.d.ts +23 -0
- package/lib/accounts/webSocketInsuranceFundStakeAccountSubscriber.js +65 -0
- package/lib/dlob/DLOB.d.ts +6 -2
- package/lib/dlob/DLOB.js +37 -12
- package/lib/driftClient.d.ts +66 -66
- package/lib/driftClient.js +208 -194
- package/lib/events/eventSubscriber.js +2 -1
- package/lib/events/sort.d.ts +2 -2
- package/lib/events/sort.js +6 -23
- package/lib/examples/loadDlob.js +10 -5
- package/lib/index.d.ts +3 -1
- package/lib/index.js +3 -1
- package/lib/orderSubscriber/OrderSubscriber.js +4 -0
- package/lib/orderSubscriber/WebsocketSubscription.d.ts +1 -1
- package/lib/orderSubscriber/WebsocketSubscription.js +8 -6
- package/lib/types.d.ts +0 -2
- package/lib/userMap/PollingSubscription.d.ts +15 -0
- package/lib/userMap/PollingSubscription.js +26 -0
- package/lib/userMap/WebsocketSubscription.d.ts +19 -0
- package/lib/userMap/WebsocketSubscription.js +40 -0
- package/lib/userMap/userMap.d.ts +15 -18
- package/lib/userMap/userMap.js +62 -31
- package/lib/userMap/userMapConfig.d.ts +20 -0
- package/lib/userMap/userMapConfig.js +2 -0
- package/package.json +1 -1
- package/src/accounts/{mockUserAccountSubscriber.ts → basicUserAccountSubscriber.ts} +8 -6
- package/src/accounts/pollingInsuranceFundStakeAccountSubscriber.ts +185 -0
- package/src/accounts/types.ts +21 -0
- package/src/accounts/webSocketInsuranceFundStakeAccountSubscriber.ts +127 -0
- package/src/dlob/DLOB.ts +55 -15
- package/src/driftClient.ts +429 -272
- package/src/events/eventSubscriber.ts +2 -1
- package/src/events/sort.ts +7 -29
- package/src/examples/loadDlob.ts +11 -6
- package/src/index.ts +3 -1
- package/src/orderSubscriber/OrderSubscriber.ts +4 -0
- package/src/orderSubscriber/WebsocketSubscription.ts +19 -16
- package/src/types.ts +0 -2
- package/src/userMap/PollingSubscription.ts +46 -0
- package/src/userMap/WebsocketSubscription.ts +74 -0
- package/src/userMap/userMap.ts +88 -60
- package/src/userMap/userMapConfig.ts +31 -0
- package/tests/amm/test.ts +6 -3
- package/tests/dlob/helpers.ts +2 -6
- package/tests/dlob/test.ts +194 -0
package/tests/dlob/helpers.ts
CHANGED
|
@@ -539,15 +539,13 @@ export const mockStateAccount: StateAccount = {
|
|
|
539
539
|
feeNumerator: 0,
|
|
540
540
|
feeDenominator: 0,
|
|
541
541
|
makerRebateNumerator: 0,
|
|
542
|
-
makerRebateDenominator:
|
|
542
|
+
makerRebateDenominator: 1,
|
|
543
543
|
referrerRewardNumerator: 0,
|
|
544
544
|
referrerRewardDenominator: 0,
|
|
545
545
|
refereeFeeNumerator: 0,
|
|
546
546
|
refereeFeeDenominator: 0,
|
|
547
547
|
},
|
|
548
548
|
],
|
|
549
|
-
makerRebateNumerator: new BN(0),
|
|
550
|
-
makerRebateDenominator: new BN(0),
|
|
551
549
|
fillerRewardStructure: {
|
|
552
550
|
rewardNumerator: new BN(0),
|
|
553
551
|
rewardDenominator: new BN(0),
|
|
@@ -565,15 +563,13 @@ export const mockStateAccount: StateAccount = {
|
|
|
565
563
|
feeNumerator: 0,
|
|
566
564
|
feeDenominator: 0,
|
|
567
565
|
makerRebateNumerator: 0,
|
|
568
|
-
makerRebateDenominator:
|
|
566
|
+
makerRebateDenominator: 1,
|
|
569
567
|
referrerRewardNumerator: 0,
|
|
570
568
|
referrerRewardDenominator: 0,
|
|
571
569
|
refereeFeeNumerator: 0,
|
|
572
570
|
refereeFeeDenominator: 0,
|
|
573
571
|
},
|
|
574
572
|
],
|
|
575
|
-
makerRebateNumerator: new BN(0),
|
|
576
|
-
makerRebateDenominator: new BN(0),
|
|
577
573
|
fillerRewardStructure: {
|
|
578
574
|
rewardNumerator: new BN(0),
|
|
579
575
|
rewardDenominator: new BN(0),
|
package/tests/dlob/test.ts
CHANGED
|
@@ -1914,6 +1914,8 @@ describe('DLOB Perp Tests', () => {
|
|
|
1914
1914
|
},
|
|
1915
1915
|
false,
|
|
1916
1916
|
10,
|
|
1917
|
+
0,
|
|
1918
|
+
1,
|
|
1917
1919
|
undefined,
|
|
1918
1920
|
undefined
|
|
1919
1921
|
);
|
|
@@ -2059,6 +2061,8 @@ describe('DLOB Perp Tests', () => {
|
|
|
2059
2061
|
},
|
|
2060
2062
|
false,
|
|
2061
2063
|
10,
|
|
2064
|
+
0,
|
|
2065
|
+
1,
|
|
2062
2066
|
undefined,
|
|
2063
2067
|
undefined
|
|
2064
2068
|
);
|
|
@@ -2267,6 +2271,194 @@ describe('DLOB Perp Tests', () => {
|
|
|
2267
2271
|
expect(nodesToFillAfter[1].makerNodes[0]?.order?.orderId).to.equal(3);
|
|
2268
2272
|
});
|
|
2269
2273
|
|
|
2274
|
+
it('Test post only bid fills against fallback', async () => {
|
|
2275
|
+
const vAsk = new BN(150);
|
|
2276
|
+
const vBid = new BN(100);
|
|
2277
|
+
|
|
2278
|
+
const user0 = Keypair.generate();
|
|
2279
|
+
|
|
2280
|
+
const dlob = new DLOB();
|
|
2281
|
+
const marketIndex = 0;
|
|
2282
|
+
|
|
2283
|
+
const makerRebateNumerator = 1;
|
|
2284
|
+
const makerRebateDenominator = 10;
|
|
2285
|
+
|
|
2286
|
+
// post only bid same as ask
|
|
2287
|
+
insertOrderToDLOB(
|
|
2288
|
+
dlob,
|
|
2289
|
+
user0.publicKey,
|
|
2290
|
+
OrderType.LIMIT,
|
|
2291
|
+
MarketType.PERP,
|
|
2292
|
+
1, // orderId
|
|
2293
|
+
marketIndex,
|
|
2294
|
+
vAsk, // same price as vAsk
|
|
2295
|
+
BASE_PRECISION, // quantity
|
|
2296
|
+
PositionDirection.LONG,
|
|
2297
|
+
vBid,
|
|
2298
|
+
vAsk,
|
|
2299
|
+
undefined,
|
|
2300
|
+
undefined,
|
|
2301
|
+
undefined,
|
|
2302
|
+
true
|
|
2303
|
+
);
|
|
2304
|
+
|
|
2305
|
+
// should have no crossing orders
|
|
2306
|
+
const nodesToFillBefore = dlob.findRestingLimitOrderNodesToFill(
|
|
2307
|
+
marketIndex,
|
|
2308
|
+
12, // auction over
|
|
2309
|
+
MarketType.PERP,
|
|
2310
|
+
{
|
|
2311
|
+
price: vBid.add(vAsk).div(new BN(2)),
|
|
2312
|
+
slot: new BN(12),
|
|
2313
|
+
confidence: new BN(1),
|
|
2314
|
+
hasSufficientNumberOfDataPoints: true,
|
|
2315
|
+
},
|
|
2316
|
+
false,
|
|
2317
|
+
10,
|
|
2318
|
+
makerRebateNumerator,
|
|
2319
|
+
makerRebateDenominator,
|
|
2320
|
+
vAsk,
|
|
2321
|
+
vBid
|
|
2322
|
+
);
|
|
2323
|
+
expect(nodesToFillBefore.length).to.equal(0);
|
|
2324
|
+
|
|
2325
|
+
// post only bid crosses ask
|
|
2326
|
+
const price = vAsk.add(
|
|
2327
|
+
vAsk.muln(makerRebateNumerator).divn(makerRebateDenominator)
|
|
2328
|
+
);
|
|
2329
|
+
insertOrderToDLOB(
|
|
2330
|
+
dlob,
|
|
2331
|
+
user0.publicKey,
|
|
2332
|
+
OrderType.LIMIT,
|
|
2333
|
+
MarketType.PERP,
|
|
2334
|
+
2, // orderId
|
|
2335
|
+
marketIndex,
|
|
2336
|
+
price, // crosses vask
|
|
2337
|
+
BASE_PRECISION, // quantity
|
|
2338
|
+
PositionDirection.LONG,
|
|
2339
|
+
vBid,
|
|
2340
|
+
vAsk,
|
|
2341
|
+
undefined,
|
|
2342
|
+
undefined,
|
|
2343
|
+
undefined,
|
|
2344
|
+
true
|
|
2345
|
+
);
|
|
2346
|
+
|
|
2347
|
+
// should have no crossing orders
|
|
2348
|
+
const nodesToFillAfter = dlob.findRestingLimitOrderNodesToFill(
|
|
2349
|
+
marketIndex,
|
|
2350
|
+
12, // auction over
|
|
2351
|
+
MarketType.PERP,
|
|
2352
|
+
{
|
|
2353
|
+
price: vBid.add(vAsk).div(new BN(2)),
|
|
2354
|
+
slot: new BN(12),
|
|
2355
|
+
confidence: new BN(1),
|
|
2356
|
+
hasSufficientNumberOfDataPoints: true,
|
|
2357
|
+
},
|
|
2358
|
+
false,
|
|
2359
|
+
10,
|
|
2360
|
+
makerRebateNumerator,
|
|
2361
|
+
makerRebateDenominator,
|
|
2362
|
+
vAsk,
|
|
2363
|
+
vBid
|
|
2364
|
+
);
|
|
2365
|
+
expect(nodesToFillAfter.length).to.equal(1);
|
|
2366
|
+
});
|
|
2367
|
+
|
|
2368
|
+
it('Test post only ask fills against fallback', async () => {
|
|
2369
|
+
const vAsk = new BN(150);
|
|
2370
|
+
const vBid = new BN(100);
|
|
2371
|
+
|
|
2372
|
+
const user0 = Keypair.generate();
|
|
2373
|
+
|
|
2374
|
+
const dlob = new DLOB();
|
|
2375
|
+
const marketIndex = 0;
|
|
2376
|
+
|
|
2377
|
+
const makerRebateNumerator = 1;
|
|
2378
|
+
const makerRebateDenominator = 10;
|
|
2379
|
+
|
|
2380
|
+
// post only bid same as ask
|
|
2381
|
+
insertOrderToDLOB(
|
|
2382
|
+
dlob,
|
|
2383
|
+
user0.publicKey,
|
|
2384
|
+
OrderType.LIMIT,
|
|
2385
|
+
MarketType.PERP,
|
|
2386
|
+
1, // orderId
|
|
2387
|
+
marketIndex,
|
|
2388
|
+
vBid, // same price as vAsk
|
|
2389
|
+
BASE_PRECISION, // quantity
|
|
2390
|
+
PositionDirection.SHORT,
|
|
2391
|
+
vBid,
|
|
2392
|
+
vAsk,
|
|
2393
|
+
undefined,
|
|
2394
|
+
undefined,
|
|
2395
|
+
undefined,
|
|
2396
|
+
true
|
|
2397
|
+
);
|
|
2398
|
+
|
|
2399
|
+
// should have no crossing orders
|
|
2400
|
+
const nodesToFillBefore = dlob.findRestingLimitOrderNodesToFill(
|
|
2401
|
+
marketIndex,
|
|
2402
|
+
12, // auction over
|
|
2403
|
+
MarketType.PERP,
|
|
2404
|
+
{
|
|
2405
|
+
price: vBid.add(vAsk).div(new BN(2)),
|
|
2406
|
+
slot: new BN(12),
|
|
2407
|
+
confidence: new BN(1),
|
|
2408
|
+
hasSufficientNumberOfDataPoints: true,
|
|
2409
|
+
},
|
|
2410
|
+
false,
|
|
2411
|
+
10,
|
|
2412
|
+
makerRebateNumerator,
|
|
2413
|
+
makerRebateDenominator,
|
|
2414
|
+
vAsk,
|
|
2415
|
+
vBid
|
|
2416
|
+
);
|
|
2417
|
+
expect(nodesToFillBefore.length).to.equal(0);
|
|
2418
|
+
|
|
2419
|
+
// post only bid crosses ask
|
|
2420
|
+
const price = vBid.sub(
|
|
2421
|
+
vAsk.muln(makerRebateNumerator).divn(makerRebateDenominator)
|
|
2422
|
+
);
|
|
2423
|
+
insertOrderToDLOB(
|
|
2424
|
+
dlob,
|
|
2425
|
+
user0.publicKey,
|
|
2426
|
+
OrderType.LIMIT,
|
|
2427
|
+
MarketType.PERP,
|
|
2428
|
+
2, // orderId
|
|
2429
|
+
marketIndex,
|
|
2430
|
+
price, // crosses vask
|
|
2431
|
+
BASE_PRECISION, // quantity
|
|
2432
|
+
PositionDirection.SHORT,
|
|
2433
|
+
vBid,
|
|
2434
|
+
vAsk,
|
|
2435
|
+
undefined,
|
|
2436
|
+
undefined,
|
|
2437
|
+
undefined,
|
|
2438
|
+
true
|
|
2439
|
+
);
|
|
2440
|
+
|
|
2441
|
+
// should have no crossing orders
|
|
2442
|
+
const nodesToFillAfter = dlob.findRestingLimitOrderNodesToFill(
|
|
2443
|
+
marketIndex,
|
|
2444
|
+
12, // auction over
|
|
2445
|
+
MarketType.PERP,
|
|
2446
|
+
{
|
|
2447
|
+
price: vBid.add(vAsk).div(new BN(2)),
|
|
2448
|
+
slot: new BN(12),
|
|
2449
|
+
confidence: new BN(1),
|
|
2450
|
+
hasSufficientNumberOfDataPoints: true,
|
|
2451
|
+
},
|
|
2452
|
+
false,
|
|
2453
|
+
10,
|
|
2454
|
+
makerRebateNumerator,
|
|
2455
|
+
makerRebateDenominator,
|
|
2456
|
+
vAsk,
|
|
2457
|
+
vBid
|
|
2458
|
+
);
|
|
2459
|
+
expect(nodesToFillAfter.length).to.equal(1);
|
|
2460
|
+
});
|
|
2461
|
+
|
|
2270
2462
|
it('Test trigger orders', () => {
|
|
2271
2463
|
const vAsk = new BN(15);
|
|
2272
2464
|
const vBid = new BN(8);
|
|
@@ -2901,6 +3093,8 @@ describe('DLOB Perp Tests', () => {
|
|
|
2901
3093
|
oracle,
|
|
2902
3094
|
false,
|
|
2903
3095
|
10,
|
|
3096
|
+
0,
|
|
3097
|
+
1,
|
|
2904
3098
|
undefined,
|
|
2905
3099
|
undefined
|
|
2906
3100
|
);
|