@drift-labs/sdk 0.2.0-master.30 → 0.2.0-master.32
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/lib/admin.d.ts +11 -7
- package/lib/admin.js +50 -12
- package/lib/clearingHouse.d.ts +26 -23
- package/lib/clearingHouse.js +290 -652
- package/lib/clearingHouseUser.d.ts +1 -1
- package/lib/clearingHouseUser.js +9 -12
- package/lib/config.js +1 -1
- package/lib/constants/numericConstants.d.ts +7 -0
- package/lib/constants/numericConstants.js +8 -1
- package/lib/constants/spotMarkets.js +4 -4
- package/lib/dlob/DLOB.d.ts +7 -5
- package/lib/dlob/DLOB.js +159 -88
- package/lib/dlob/DLOBNode.d.ts +2 -0
- package/lib/dlob/DLOBNode.js +3 -0
- package/lib/dlob/NodeList.d.ts +2 -1
- package/lib/dlob/NodeList.js +10 -4
- package/lib/events/types.d.ts +2 -1
- package/lib/events/types.js +1 -0
- package/lib/factory/bigNum.d.ts +1 -0
- package/lib/factory/bigNum.js +14 -0
- package/lib/idl/clearing_house.json +1091 -611
- package/lib/math/amm.d.ts +2 -2
- package/lib/math/amm.js +31 -28
- package/lib/math/market.d.ts +1 -1
- package/lib/math/market.js +6 -6
- package/lib/math/spotBalance.js +7 -8
- package/lib/math/trade.js +11 -11
- package/lib/types.d.ts +118 -41
- package/lib/types.js +34 -4
- package/package.json +4 -2
- package/src/admin.ts +129 -29
- package/src/clearingHouse.ts +380 -787
- package/src/clearingHouseUser.ts +11 -14
- package/src/config.ts +1 -1
- package/src/constants/numericConstants.ts +7 -0
- package/src/constants/spotMarkets.ts +5 -4
- package/src/dlob/DLOB.ts +221 -103
- package/src/dlob/DLOBNode.ts +5 -0
- package/src/dlob/NodeList.ts +15 -5
- package/src/events/types.ts +3 -0
- package/src/factory/bigNum.ts +23 -0
- package/src/idl/clearing_house.json +1091 -611
- package/src/math/amm.ts +42 -29
- package/src/math/market.ts +9 -4
- package/src/math/spotBalance.ts +11 -8
- package/src/math/trade.ts +11 -11
- package/src/types.ts +82 -41
- package/tests/bn/test.ts +13 -8
- package/tests/dlob/helpers.ts +56 -33
- package/tests/dlob/test.ts +1397 -495
- package/src/assert/assert.js +0 -9
- package/src/events/eventList.js +0 -77
- package/src/examples/makeTradeExample.js +0 -157
- package/src/token/index.js +0 -38
- package/src/tx/types.js +0 -2
- package/src/tx/utils.js +0 -17
- package/src/util/computeUnits.js +0 -27
- package/src/util/getTokenAddress.js +0 -9
- package/src/util/promiseTimeout.js +0 -14
- package/src/util/tps.js +0 -27
package/src/events/types.ts
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
SettlePnlRecord,
|
|
11
11
|
LPRecord,
|
|
12
12
|
InsuranceFundRecord,
|
|
13
|
+
SpotInterestRecord,
|
|
13
14
|
} from '../index';
|
|
14
15
|
|
|
15
16
|
export type EventSubscriptionOptions = {
|
|
@@ -37,6 +38,7 @@ export const DefaultEventSubscriptionOptions: EventSubscriptionOptions = {
|
|
|
37
38
|
'SettlePnlRecord',
|
|
38
39
|
'LPRecord',
|
|
39
40
|
'InsuranceFundRecord',
|
|
41
|
+
'SpotInterestRecord',
|
|
40
42
|
],
|
|
41
43
|
maxEventsPerType: 4096,
|
|
42
44
|
orderBy: 'blockchain',
|
|
@@ -74,6 +76,7 @@ export type EventMap = {
|
|
|
74
76
|
NewUserRecord: Event<NewUserRecord>;
|
|
75
77
|
LPRecord: Event<LPRecord>;
|
|
76
78
|
InsuranceFundRecord: Event<InsuranceFundRecord>;
|
|
79
|
+
SpotInterestRecord: Event<SpotInterestRecord>;
|
|
77
80
|
};
|
|
78
81
|
|
|
79
82
|
export type EventType = keyof EventMap;
|
package/src/factory/bigNum.ts
CHANGED
|
@@ -290,6 +290,8 @@ export class BigNum {
|
|
|
290
290
|
? this.toTradePrecision()
|
|
291
291
|
: this.print();
|
|
292
292
|
|
|
293
|
+
if (!printVal.includes(BigNum.delim)) return printVal;
|
|
294
|
+
|
|
293
295
|
return printVal.replace(/0+$/g, '').replace(/\.$/, '').replace(/,$/, '');
|
|
294
296
|
}
|
|
295
297
|
|
|
@@ -319,6 +321,10 @@ export class BigNum {
|
|
|
319
321
|
return `${leftSide}${BigNum.delim}${filledRightSide}`;
|
|
320
322
|
}
|
|
321
323
|
|
|
324
|
+
private getZeroes(count: number) {
|
|
325
|
+
return new Array(count).fill('0').join('');
|
|
326
|
+
}
|
|
327
|
+
|
|
322
328
|
/**
|
|
323
329
|
* Pretty print to the specified number of significant figures
|
|
324
330
|
* @param fixedPrecision
|
|
@@ -329,6 +335,19 @@ export class BigNum {
|
|
|
329
335
|
|
|
330
336
|
let precisionPrintString = printString.slice(0, fixedPrecision + 1);
|
|
331
337
|
|
|
338
|
+
const thisString = this.toString();
|
|
339
|
+
|
|
340
|
+
if (
|
|
341
|
+
!printString.includes(BigNum.delim) &&
|
|
342
|
+
thisString.length < fixedPrecision
|
|
343
|
+
) {
|
|
344
|
+
const precisionMismatch = fixedPrecision - thisString.length;
|
|
345
|
+
return BigNum.from(
|
|
346
|
+
thisString + this.getZeroes(precisionMismatch),
|
|
347
|
+
precisionMismatch
|
|
348
|
+
).toPrecision(fixedPrecision, trailingZeroes);
|
|
349
|
+
}
|
|
350
|
+
|
|
332
351
|
if (
|
|
333
352
|
!precisionPrintString.includes(BigNum.delim) ||
|
|
334
353
|
precisionPrintString[precisionPrintString.length - 1] === BigNum.delim
|
|
@@ -438,6 +457,10 @@ export class BigNum {
|
|
|
438
457
|
return this.shift(new BN(precision)).toPrecision(precision, true);
|
|
439
458
|
}
|
|
440
459
|
|
|
460
|
+
if (leftSide.length <= precision) {
|
|
461
|
+
return this.toPrecision(precision);
|
|
462
|
+
}
|
|
463
|
+
|
|
441
464
|
if (leftSide.length <= 3) {
|
|
442
465
|
return this.shift(new BN(precision)).toPrecision(precision, true);
|
|
443
466
|
}
|