@drift-labs/sdk 2.6.0-beta.1 → 2.7.0
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/factory/bigNum.js +9 -7
- package/lib/idl/drift.json +1 -1
- package/package.json +1 -1
- package/src/factory/bigNum.ts +11 -8
- package/src/idl/drift.json +1 -1
- package/tests/amm/test.ts +197 -190
- package/tests/bn/test.ts +10 -0
package/lib/factory/bigNum.js
CHANGED
|
@@ -252,13 +252,14 @@ class BigNum {
|
|
|
252
252
|
if (rounded) {
|
|
253
253
|
return this.toRounded(fixedPrecision).toPrecision(fixedPrecision, trailingZeroes);
|
|
254
254
|
}
|
|
255
|
-
const
|
|
255
|
+
const isNeg = this.isNeg();
|
|
256
|
+
const printString = this.abs().print();
|
|
257
|
+
const thisString = this.abs().toString();
|
|
256
258
|
let precisionPrintString = printString.slice(0, fixedPrecision + 1);
|
|
257
|
-
const thisString = this.toString();
|
|
258
259
|
if (!printString.includes(BigNum.delim) &&
|
|
259
260
|
thisString.length < fixedPrecision) {
|
|
260
261
|
const precisionMismatch = fixedPrecision - thisString.length;
|
|
261
|
-
return BigNum.from(thisString + this.getZeroes(precisionMismatch), precisionMismatch).toPrecision(fixedPrecision, trailingZeroes);
|
|
262
|
+
return BigNum.from((isNeg ? '-' : '') + thisString + this.getZeroes(precisionMismatch), precisionMismatch).toPrecision(fixedPrecision, trailingZeroes);
|
|
262
263
|
}
|
|
263
264
|
if (!precisionPrintString.includes(BigNum.delim) ||
|
|
264
265
|
precisionPrintString[precisionPrintString.length - 1] === BigNum.delim) {
|
|
@@ -298,7 +299,7 @@ class BigNum {
|
|
|
298
299
|
}
|
|
299
300
|
}
|
|
300
301
|
}
|
|
301
|
-
return precisionPrintString
|
|
302
|
+
return `${isNeg ? '-' : ''}${precisionPrintString}`;
|
|
302
303
|
}
|
|
303
304
|
toTradePrecision(rounded = false) {
|
|
304
305
|
return this.toPrecision(6, true, rounded);
|
|
@@ -333,7 +334,8 @@ class BigNum {
|
|
|
333
334
|
if (rounded) {
|
|
334
335
|
return this.toRounded(precision).toMillified(precision);
|
|
335
336
|
}
|
|
336
|
-
const
|
|
337
|
+
const isNeg = this.isNeg();
|
|
338
|
+
const stringVal = this.abs().print();
|
|
337
339
|
const [leftSide] = stringVal.split(BigNum.delim);
|
|
338
340
|
if (!leftSide) {
|
|
339
341
|
return this.shift(new anchor_1.BN(precision)).toPrecision(precision, true);
|
|
@@ -362,7 +364,7 @@ class BigNum {
|
|
|
362
364
|
else {
|
|
363
365
|
leadString = `${leadDigits.slice(0, decimalLocation)}${BigNum.delim}${leadDigits.slice(decimalLocation)}`;
|
|
364
366
|
}
|
|
365
|
-
return `${leadString}${unit}`;
|
|
367
|
+
return `${isNeg ? '-' : ''}${leadString}${unit}`;
|
|
366
368
|
}
|
|
367
369
|
toJSON() {
|
|
368
370
|
return {
|
|
@@ -426,7 +428,7 @@ class BigNum {
|
|
|
426
428
|
}
|
|
427
429
|
const sides = val.split(BigNum.delim);
|
|
428
430
|
const rightSide = sides[1];
|
|
429
|
-
const leftSide = sides[0].replace(/\
|
|
431
|
+
const leftSide = sides[0].replace(/\s/g, '');
|
|
430
432
|
const bnInput = `${leftSide !== null && leftSide !== void 0 ? leftSide : ''}${rightSide !== null && rightSide !== void 0 ? rightSide : ''}`;
|
|
431
433
|
const rawBn = new anchor_1.BN(bnInput);
|
|
432
434
|
const rightSideLength = (_a = rightSide === null || rightSide === void 0 ? void 0 : rightSide.length) !== null && _a !== void 0 ? _a : 0;
|
package/lib/idl/drift.json
CHANGED
package/package.json
CHANGED
package/src/factory/bigNum.ts
CHANGED
|
@@ -385,11 +385,12 @@ export class BigNum {
|
|
|
385
385
|
);
|
|
386
386
|
}
|
|
387
387
|
|
|
388
|
-
const
|
|
388
|
+
const isNeg = this.isNeg();
|
|
389
389
|
|
|
390
|
-
|
|
390
|
+
const printString = this.abs().print();
|
|
391
|
+
const thisString = this.abs().toString();
|
|
391
392
|
|
|
392
|
-
|
|
393
|
+
let precisionPrintString = printString.slice(0, fixedPrecision + 1);
|
|
393
394
|
|
|
394
395
|
if (
|
|
395
396
|
!printString.includes(BigNum.delim) &&
|
|
@@ -397,7 +398,7 @@ export class BigNum {
|
|
|
397
398
|
) {
|
|
398
399
|
const precisionMismatch = fixedPrecision - thisString.length;
|
|
399
400
|
return BigNum.from(
|
|
400
|
-
thisString + this.getZeroes(precisionMismatch),
|
|
401
|
+
(isNeg ? '-' : '') + thisString + this.getZeroes(precisionMismatch),
|
|
401
402
|
precisionMismatch
|
|
402
403
|
).toPrecision(fixedPrecision, trailingZeroes);
|
|
403
404
|
}
|
|
@@ -455,7 +456,7 @@ export class BigNum {
|
|
|
455
456
|
}
|
|
456
457
|
}
|
|
457
458
|
|
|
458
|
-
return precisionPrintString
|
|
459
|
+
return `${isNeg ? '-' : ''}${precisionPrintString}`;
|
|
459
460
|
}
|
|
460
461
|
|
|
461
462
|
public toTradePrecision(rounded = false): string {
|
|
@@ -501,7 +502,9 @@ export class BigNum {
|
|
|
501
502
|
return this.toRounded(precision).toMillified(precision);
|
|
502
503
|
}
|
|
503
504
|
|
|
504
|
-
const
|
|
505
|
+
const isNeg = this.isNeg();
|
|
506
|
+
|
|
507
|
+
const stringVal = this.abs().print();
|
|
505
508
|
|
|
506
509
|
const [leftSide] = stringVal.split(BigNum.delim);
|
|
507
510
|
|
|
@@ -542,7 +545,7 @@ export class BigNum {
|
|
|
542
545
|
}${leadDigits.slice(decimalLocation)}`;
|
|
543
546
|
}
|
|
544
547
|
|
|
545
|
-
return `${leadString}${unit}`;
|
|
548
|
+
return `${isNeg ? '-' : ''}${leadString}${unit}`;
|
|
546
549
|
}
|
|
547
550
|
|
|
548
551
|
public toJSON() {
|
|
@@ -618,7 +621,7 @@ export class BigNum {
|
|
|
618
621
|
|
|
619
622
|
const sides = val.split(BigNum.delim);
|
|
620
623
|
const rightSide = sides[1];
|
|
621
|
-
const leftSide = sides[0].replace(/\
|
|
624
|
+
const leftSide = sides[0].replace(/\s/g, '');
|
|
622
625
|
const bnInput = `${leftSide ?? ''}${rightSide ?? ''}`;
|
|
623
626
|
|
|
624
627
|
const rawBn = new BN(bnInput);
|
package/src/idl/drift.json
CHANGED
package/tests/amm/test.ts
CHANGED
|
@@ -1,193 +1,196 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
BN,
|
|
3
|
+
PEG_PRECISION,
|
|
4
|
+
PRICE_PRECISION,
|
|
4
5
|
AMM_RESERVE_PRECISION,
|
|
5
6
|
QUOTE_PRECISION,
|
|
6
7
|
calculateSpreadBN,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
ZERO,
|
|
9
|
+
calculateLiveOracleStd,
|
|
10
|
+
calculateLiveOracleTwap,
|
|
10
11
|
} from '../../src';
|
|
11
|
-
import {
|
|
12
|
-
mockPerpMarkets,
|
|
13
|
-
} from '../dlob/helpers';
|
|
12
|
+
import { mockPerpMarkets } from '../dlob/helpers';
|
|
14
13
|
|
|
15
14
|
import { assert } from '../../src/assert/assert';
|
|
16
15
|
|
|
17
16
|
class AMMSpreadTerms {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
17
|
+
longVolSpread: number;
|
|
18
|
+
shortVolSpread: number;
|
|
19
|
+
longSpreadwPS: number;
|
|
20
|
+
shortSpreadwPS: number;
|
|
21
|
+
maxTargetSpread: number;
|
|
22
|
+
inventorySpreadScale: number;
|
|
23
|
+
longSpreadwInvScale: number;
|
|
24
|
+
shortSpreadwInvScale: number;
|
|
25
|
+
effectiveLeverage: number;
|
|
26
|
+
effectiveLeverageCapped: number;
|
|
27
|
+
longSpreadwEL: number;
|
|
28
|
+
shortSpreadwEL: number;
|
|
29
|
+
revenueRetreatAmount: number;
|
|
30
|
+
halfRevenueRetreatAmount: number;
|
|
31
|
+
longSpreadwRevRetreat: number;
|
|
32
|
+
shortSpreadwRevRetreat: number;
|
|
33
|
+
totalSpread: number;
|
|
34
|
+
longSpread: number;
|
|
35
|
+
shortSpread: number;
|
|
37
36
|
}
|
|
38
37
|
|
|
39
38
|
describe('AMM Tests', () => {
|
|
40
39
|
it('Various Spreads', () => {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
40
|
+
const baseSpread: number = 0.025 * 1e6;
|
|
41
|
+
const lastOracleReservePriceSpreadPct: BN = ZERO;
|
|
42
|
+
const lastOracleConfPct: BN = ZERO;
|
|
43
|
+
const maxSpread: number = 0.03 * 1e6;
|
|
44
|
+
const quoteAssetReserve: BN = new BN(
|
|
45
|
+
AMM_RESERVE_PRECISION.toNumber() * 100
|
|
46
|
+
);
|
|
47
|
+
const terminalQuoteAssetReserve: BN = new BN(
|
|
48
|
+
AMM_RESERVE_PRECISION.toNumber() * 100
|
|
49
|
+
);
|
|
50
|
+
const pegMultiplier: BN = new BN(13.455 * PEG_PRECISION.toNumber());
|
|
51
|
+
const baseAssetAmountWithAmm: BN = ZERO;
|
|
52
|
+
const reservePrice: BN = new BN(13.455 * PRICE_PRECISION.toNumber());
|
|
53
|
+
const totalFeeMinusDistributions: BN = new BN(1);
|
|
54
|
+
const netRevenueSinceLastFunding: BN = new BN(
|
|
55
|
+
QUOTE_PRECISION.toNumber() * 2
|
|
56
|
+
);
|
|
57
|
+
const baseAssetReserve: BN = new BN(AMM_RESERVE_PRECISION.toNumber() * 100);
|
|
58
|
+
const minBaseAssetReserve: BN = new BN(
|
|
59
|
+
AMM_RESERVE_PRECISION.toNumber() * 90
|
|
60
|
+
);
|
|
61
|
+
const maxBaseAssetReserve: BN = new BN(
|
|
62
|
+
AMM_RESERVE_PRECISION.toNumber() * 110
|
|
63
|
+
);
|
|
64
|
+
const markStd: BN = new BN(0.45 * PRICE_PRECISION.toNumber());
|
|
65
|
+
const oracleStd: BN = new BN(0.55 * PRICE_PRECISION.toNumber());
|
|
66
|
+
const longIntensity: BN = new BN(QUOTE_PRECISION.toNumber() * 20);
|
|
67
|
+
const shortIntensity: BN = new BN(QUOTE_PRECISION.toNumber() * 2);
|
|
68
|
+
const volume24H: BN = new BN(QUOTE_PRECISION.toNumber() * 25);
|
|
69
|
+
|
|
70
|
+
const spreads = calculateSpreadBN(
|
|
71
|
+
baseSpread,
|
|
72
|
+
lastOracleReservePriceSpreadPct,
|
|
73
|
+
lastOracleConfPct,
|
|
74
|
+
maxSpread,
|
|
75
|
+
quoteAssetReserve,
|
|
76
|
+
terminalQuoteAssetReserve,
|
|
77
|
+
pegMultiplier,
|
|
78
|
+
baseAssetAmountWithAmm,
|
|
79
|
+
reservePrice,
|
|
80
|
+
totalFeeMinusDistributions,
|
|
81
|
+
netRevenueSinceLastFunding,
|
|
82
|
+
baseAssetReserve,
|
|
83
|
+
minBaseAssetReserve,
|
|
84
|
+
maxBaseAssetReserve,
|
|
85
|
+
markStd,
|
|
86
|
+
oracleStd,
|
|
87
|
+
longIntensity,
|
|
88
|
+
shortIntensity,
|
|
89
|
+
volume24H
|
|
90
|
+
);
|
|
91
|
+
const l1 = spreads[0];
|
|
92
|
+
const s1 = spreads[1];
|
|
93
|
+
|
|
94
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
87
95
|
// @ts-ignore
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
96
|
+
const terms1: AMMSpreadTerms = calculateSpreadBN(
|
|
97
|
+
baseSpread,
|
|
98
|
+
lastOracleReservePriceSpreadPct,
|
|
99
|
+
lastOracleConfPct,
|
|
100
|
+
maxSpread,
|
|
101
|
+
quoteAssetReserve,
|
|
102
|
+
terminalQuoteAssetReserve,
|
|
103
|
+
pegMultiplier,
|
|
104
|
+
baseAssetAmountWithAmm,
|
|
105
|
+
reservePrice,
|
|
106
|
+
totalFeeMinusDistributions,
|
|
107
|
+
netRevenueSinceLastFunding,
|
|
108
|
+
baseAssetReserve,
|
|
109
|
+
minBaseAssetReserve,
|
|
110
|
+
maxBaseAssetReserve,
|
|
111
|
+
markStd,
|
|
112
|
+
oracleStd,
|
|
113
|
+
longIntensity,
|
|
114
|
+
shortIntensity,
|
|
115
|
+
volume24H,
|
|
116
|
+
true
|
|
117
|
+
);
|
|
118
|
+
console.log(terms1);
|
|
119
|
+
|
|
120
|
+
console.log('long/short spread:', l1, s1);
|
|
121
|
+
assert(l1 == 14864);
|
|
122
|
+
assert(s1 == 12500);
|
|
123
|
+
assert(l1 == terms1.longSpread);
|
|
124
|
+
assert(s1 == terms1.shortSpread);
|
|
125
|
+
|
|
126
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
120
127
|
// @ts-ignore
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
128
|
+
const terms2: AMMSpreadTerms = calculateSpreadBN(
|
|
129
|
+
300,
|
|
130
|
+
new BN(0),
|
|
131
|
+
new BN(484),
|
|
132
|
+
47500,
|
|
133
|
+
new BN(923807816209694),
|
|
134
|
+
new BN(925117623772584),
|
|
135
|
+
new BN(13731157),
|
|
136
|
+
new BN(-1314027016625),
|
|
137
|
+
new BN(13667686),
|
|
138
|
+
new BN(115876379475),
|
|
139
|
+
new BN(91316628),
|
|
140
|
+
new BN(928097825691666),
|
|
141
|
+
new BN(907979542352912),
|
|
142
|
+
new BN(945977491145601),
|
|
143
|
+
new BN(161188),
|
|
144
|
+
new BN(1459632439),
|
|
145
|
+
new BN(12358265776),
|
|
146
|
+
new BN(72230366233),
|
|
147
|
+
new BN(432067603632),
|
|
148
|
+
true
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
console.log(terms2);
|
|
152
|
+
assert(terms2.effectiveLeverageCapped >= 1.0002);
|
|
153
|
+
assert(terms2.inventorySpreadScale == 10);
|
|
154
|
+
assert(terms2.longSpread == 798);
|
|
155
|
+
assert(terms2.shortSpread == 46702);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it('Corner Case Spreads', () => {
|
|
159
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
155
160
|
// @ts-ignore
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
const mockAmm = mockPerpMarkets[0].amm;
|
|
190
|
-
const now = new BN(new Date().getTime() / 1000); //todo
|
|
161
|
+
const terms2: AMMSpreadTerms = calculateSpreadBN(
|
|
162
|
+
1000,
|
|
163
|
+
new BN(5555),
|
|
164
|
+
new BN(1131),
|
|
165
|
+
20000,
|
|
166
|
+
new BN(1009967115003047),
|
|
167
|
+
new BN(1009811402660255),
|
|
168
|
+
new BN(13460124),
|
|
169
|
+
new BN(15328930153),
|
|
170
|
+
new BN(13667686),
|
|
171
|
+
new BN(1235066973),
|
|
172
|
+
new BN(88540713),
|
|
173
|
+
new BN(994097717724176),
|
|
174
|
+
new BN(974077854655784),
|
|
175
|
+
new BN(1014841945381208),
|
|
176
|
+
new BN(103320),
|
|
177
|
+
new BN(59975),
|
|
178
|
+
new BN(768323534),
|
|
179
|
+
new BN(243875031),
|
|
180
|
+
new BN(130017761029),
|
|
181
|
+
true
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
console.log(terms2);
|
|
185
|
+
assert(terms2.effectiveLeverageCapped <= 1.000001);
|
|
186
|
+
assert(terms2.inventorySpreadScale == 1.117371);
|
|
187
|
+
assert(terms2.longSpread == 1263);
|
|
188
|
+
assert(terms2.shortSpread == 6686);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it('live update functions', () => {
|
|
192
|
+
const mockAmm = mockPerpMarkets[0].amm;
|
|
193
|
+
const now = new BN(new Date().getTime() / 1000); //todo
|
|
191
194
|
|
|
192
195
|
const oraclePriceData = {
|
|
193
196
|
price: new BN(13.553 * PRICE_PRECISION.toNumber()),
|
|
@@ -195,19 +198,23 @@ describe('AMM Tests', () => {
|
|
|
195
198
|
confidence: new BN(1),
|
|
196
199
|
hasSufficientNumberOfDataPoints: true,
|
|
197
200
|
};
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
201
|
+
mockAmm.oracleStd = new BN(0.18 * PRICE_PRECISION.toNumber());
|
|
202
|
+
mockAmm.fundingPeriod = new BN(3600);
|
|
203
|
+
mockAmm.historicalOracleData.lastOraclePriceTwap = oraclePriceData.price
|
|
204
|
+
.mul(new BN(999))
|
|
205
|
+
.div(new BN(1000));
|
|
206
|
+
mockAmm.historicalOracleData.lastOraclePriceTwapTs = now.sub(new BN(11));
|
|
207
|
+
|
|
208
|
+
const liveOracleTwap = calculateLiveOracleTwap(
|
|
209
|
+
mockAmm,
|
|
210
|
+
oraclePriceData,
|
|
211
|
+
now
|
|
212
|
+
);
|
|
213
|
+
console.log('liveOracleTwap:', liveOracleTwap.toNumber());
|
|
214
|
+
assert(liveOracleTwap.eq(new BN(13539488)));
|
|
215
|
+
|
|
216
|
+
const liveOracleStd = calculateLiveOracleStd(mockAmm, oraclePriceData, now);
|
|
217
|
+
console.log('liveOracleStd:', liveOracleStd.toNumber());
|
|
218
|
+
assert(liveOracleStd.eq(new BN(192962)));
|
|
219
|
+
});
|
|
220
|
+
});
|
package/tests/bn/test.ts
CHANGED
|
@@ -128,6 +128,16 @@ describe('BigNum Tests', () => {
|
|
|
128
128
|
expect(BigNum.fromPrint('12345678').toMillified(5)).to.equal('12.345M');
|
|
129
129
|
expect(BigNum.fromPrint('123456789').toMillified(5)).to.equal('123.45M');
|
|
130
130
|
|
|
131
|
+
expect(BigNum.fromPrint('-1').toMillified(5)).to.equal('-1.0000');
|
|
132
|
+
expect(BigNum.fromPrint('-12').toMillified(5)).to.equal('-12.000');
|
|
133
|
+
expect(BigNum.fromPrint('-123').toMillified(5)).to.equal('-123.00');
|
|
134
|
+
expect(BigNum.fromPrint('-1234').toMillified(5)).to.equal('-1234.0');
|
|
135
|
+
expect(BigNum.fromPrint('-12345').toMillified(5)).to.equal('-12345');
|
|
136
|
+
expect(BigNum.fromPrint('-123456').toMillified(5)).to.equal('-123.45K');
|
|
137
|
+
expect(BigNum.fromPrint('-1234567').toMillified(5)).to.equal('-1.2345M');
|
|
138
|
+
expect(BigNum.fromPrint('-12345678').toMillified(5)).to.equal('-12.345M');
|
|
139
|
+
expect(BigNum.fromPrint('-123456789').toMillified(5)).to.equal('-123.45M');
|
|
140
|
+
|
|
131
141
|
expect(BigNum.from(-95, 2).print()).to.equal('-0.95');
|
|
132
142
|
|
|
133
143
|
// Case 6 strange numbers
|