@drift-labs/sdk 0.2.0-master.0 → 0.2.0-master.11
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 +8 -5
- package/lib/admin.js +43 -11
- package/lib/clearingHouse.d.ts +28 -18
- package/lib/clearingHouse.js +366 -143
- package/lib/clearingHouseUser.d.ts +2 -2
- package/lib/clearingHouseUser.js +8 -17
- package/lib/config.js +1 -1
- package/lib/constants/banks.js +9 -2
- package/lib/constants/numericConstants.d.ts +2 -0
- package/lib/constants/numericConstants.js +3 -1
- package/lib/factory/bigNum.d.ts +8 -2
- package/lib/factory/bigNum.js +14 -6
- package/lib/idl/clearing_house.json +805 -202
- package/lib/idl/{mock_usdc_faucet.json → token_faucet.json} +46 -23
- package/lib/index.d.ts +3 -2
- package/lib/index.js +7 -2
- package/lib/math/amm.d.ts +6 -1
- package/lib/math/amm.js +124 -41
- package/lib/math/auction.js +4 -1
- package/lib/math/orders.d.ts +2 -2
- package/lib/math/orders.js +18 -11
- package/lib/math/position.js +3 -1
- package/lib/math/repeg.js +1 -1
- package/lib/math/trade.d.ts +1 -1
- package/lib/math/trade.js +7 -10
- package/lib/orderParams.d.ts +14 -5
- package/lib/orderParams.js +8 -96
- package/lib/orders.d.ts +1 -2
- package/lib/orders.js +6 -85
- package/lib/slot/SlotSubscriber.d.ts +7 -0
- package/lib/slot/SlotSubscriber.js +3 -0
- package/lib/{mockUSDCFaucet.d.ts → tokenFaucet.d.ts} +7 -5
- package/lib/{mockUSDCFaucet.js → tokenFaucet.js} +41 -40
- package/lib/tx/utils.js +1 -1
- package/lib/types.d.ts +137 -14
- package/lib/types.js +53 -1
- package/lib/util/computeUnits.js +1 -1
- package/package.json +3 -3
- package/src/accounts/bulkAccountLoader.js +197 -0
- package/src/accounts/bulkUserSubscription.js +33 -0
- package/src/accounts/fetch.js +29 -0
- package/src/accounts/pollingClearingHouseAccountSubscriber.js +311 -0
- package/src/accounts/pollingOracleSubscriber.js +93 -0
- package/src/accounts/pollingTokenAccountSubscriber.js +90 -0
- package/src/accounts/pollingUserAccountSubscriber.js +132 -0
- package/src/accounts/types.js +10 -0
- package/src/accounts/utils.js +7 -0
- package/src/accounts/webSocketAccountSubscriber.js +93 -0
- package/src/accounts/webSocketClearingHouseAccountSubscriber.js +233 -0
- package/src/accounts/webSocketUserAccountSubscriber.js +62 -0
- package/src/addresses/marketAddresses.js +26 -0
- package/src/addresses/pda.js +104 -0
- package/src/admin.ts +66 -14
- package/src/assert/assert.js +9 -0
- package/src/clearingHouse.ts +558 -230
- package/src/clearingHouseUser.ts +12 -23
- package/src/config.ts +1 -1
- package/src/constants/banks.ts +9 -2
- package/src/constants/numericConstants.ts +2 -0
- package/src/events/eventList.js +77 -0
- package/src/events/eventSubscriber.js +139 -0
- package/src/events/fetchLogs.js +50 -0
- package/src/events/pollingLogProvider.js +64 -0
- package/src/events/sort.js +44 -0
- package/src/events/txEventCache.js +71 -0
- package/src/events/types.js +20 -0
- package/src/events/webSocketLogProvider.js +41 -0
- package/src/examples/makeTradeExample.js +80 -0
- package/src/factory/bigNum.js +364 -0
- package/src/factory/bigNum.ts +26 -9
- package/src/factory/oracleClient.js +20 -0
- package/src/idl/clearing_house.json +805 -202
- package/src/idl/{mock_usdc_faucet.json → token_faucet.json} +46 -23
- package/src/index.js +100 -0
- package/src/index.ts +3 -2
- package/src/math/amm.js +369 -0
- package/src/math/amm.ts +207 -52
- package/src/math/auction.js +42 -0
- package/src/math/auction.ts +5 -1
- package/src/math/bankBalance.js +75 -0
- package/src/math/conversion.js +11 -0
- package/src/math/funding.js +248 -0
- package/src/math/market.js +57 -0
- package/src/math/oracles.js +26 -0
- package/src/math/orders.js +110 -0
- package/src/math/orders.ts +17 -13
- package/src/math/position.js +140 -0
- package/src/math/position.ts +5 -1
- package/src/math/repeg.js +128 -0
- package/src/math/repeg.ts +2 -1
- package/src/math/state.js +15 -0
- package/src/math/trade.js +253 -0
- package/src/math/trade.ts +23 -25
- package/src/math/utils.js +0 -1
- package/src/mockUSDCFaucet.js +280 -0
- package/src/oracles/oracleClientCache.js +19 -0
- package/src/oracles/pythClient.js +46 -0
- package/src/oracles/quoteAssetOracleClient.js +32 -0
- package/src/oracles/switchboardClient.js +69 -0
- package/src/oracles/types.js +2 -0
- package/src/orderParams.js +20 -0
- package/src/orderParams.ts +20 -141
- package/src/orders.js +134 -0
- package/src/orders.ts +7 -131
- package/src/slot/SlotSubscriber.js +39 -0
- package/src/slot/SlotSubscriber.ts +11 -1
- package/src/token/index.js +38 -0
- package/src/{mockUSDCFaucet.ts → tokenFaucet.ts} +48 -59
- package/src/tx/retryTxSender.js +188 -0
- package/src/tx/types.js +2 -0
- package/src/tx/utils.js +17 -0
- package/src/tx/utils.ts +1 -1
- package/src/types.js +114 -0
- package/src/types.ts +132 -16
- package/src/userName.js +20 -0
- package/src/util/computeUnits.ts +1 -1
- package/src/util/promiseTimeout.js +14 -0
- package/src/util/tps.js +27 -0
- package/src/wallet.js +35 -0
- package/src/util/computeUnits.js +0 -17
- package/src/util/computeUnits.js.map +0 -1
|
@@ -63,7 +63,7 @@ export declare class ClearingHouseUser {
|
|
|
63
63
|
/**
|
|
64
64
|
* @returns The partial margin requirement in USDC. : QUOTE_PRECISION
|
|
65
65
|
*/
|
|
66
|
-
|
|
66
|
+
getMaintenanceMarginRequirement(): BN;
|
|
67
67
|
/**
|
|
68
68
|
* calculates unrealized position price pnl
|
|
69
69
|
* @returns : Precision QUOTE_PRECISION
|
|
@@ -132,7 +132,7 @@ export declare class ClearingHouseUser {
|
|
|
132
132
|
* @param partial
|
|
133
133
|
* @returns Precision : MARK_PRICE_PRECISION
|
|
134
134
|
*/
|
|
135
|
-
liquidationPrice(marketPosition: Pick<UserPosition, 'marketIndex'>, positionBaseSizeChange?: BN
|
|
135
|
+
liquidationPrice(marketPosition: Pick<UserPosition, 'marketIndex'>, positionBaseSizeChange?: BN): BN;
|
|
136
136
|
/**
|
|
137
137
|
* Calculates the estimated liquidation price for a position after closing a quote amount of the position.
|
|
138
138
|
* @param positionMarketIndex
|
package/lib/clearingHouseUser.js
CHANGED
|
@@ -126,12 +126,12 @@ class ClearingHouseUser {
|
|
|
126
126
|
/**
|
|
127
127
|
* @returns The partial margin requirement in USDC. : QUOTE_PRECISION
|
|
128
128
|
*/
|
|
129
|
-
|
|
129
|
+
getMaintenanceMarginRequirement() {
|
|
130
130
|
return this.getUserAccount()
|
|
131
131
|
.positions.reduce((marginRequirement, marketPosition) => {
|
|
132
132
|
const market = this.clearingHouse.getMarketAccount(marketPosition.marketIndex);
|
|
133
133
|
return marginRequirement.add((0, _1.calculateBaseAssetValue)(market, marketPosition, this.getOracleDataForMarket(market.marketIndex))
|
|
134
|
-
.mul(new _1.BN(market.
|
|
134
|
+
.mul(new _1.BN(market.marginRatioMaintenance))
|
|
135
135
|
.div(numericConstants_1.MARGIN_PRECISION));
|
|
136
136
|
}, numericConstants_1.ZERO)
|
|
137
137
|
.add(this.getTotalLiability());
|
|
@@ -319,9 +319,6 @@ class ClearingHouseUser {
|
|
|
319
319
|
case 'Maintenance':
|
|
320
320
|
marginRatioCategory = market.marginRatioMaintenance;
|
|
321
321
|
break;
|
|
322
|
-
case 'Partial':
|
|
323
|
-
marginRatioCategory = market.marginRatioPartial;
|
|
324
|
-
break;
|
|
325
322
|
default:
|
|
326
323
|
marginRatioCategory = market.marginRatioInitial;
|
|
327
324
|
break;
|
|
@@ -342,7 +339,7 @@ class ClearingHouseUser {
|
|
|
342
339
|
}
|
|
343
340
|
canBeLiquidated() {
|
|
344
341
|
const totalCollateral = this.getTotalCollateral();
|
|
345
|
-
const partialMaintenanceRequirement = this.
|
|
342
|
+
const partialMaintenanceRequirement = this.getMaintenanceMarginRequirement();
|
|
346
343
|
const marginRatio = this.getMarginRatio();
|
|
347
344
|
const canLiquidate = totalCollateral.lt(partialMaintenanceRequirement);
|
|
348
345
|
return [canLiquidate, marginRatio];
|
|
@@ -372,7 +369,7 @@ class ClearingHouseUser {
|
|
|
372
369
|
* @param partial
|
|
373
370
|
* @returns Precision : MARK_PRICE_PRECISION
|
|
374
371
|
*/
|
|
375
|
-
liquidationPrice(marketPosition, positionBaseSizeChange = numericConstants_1.ZERO
|
|
372
|
+
liquidationPrice(marketPosition, positionBaseSizeChange = numericConstants_1.ZERO) {
|
|
376
373
|
// solves formula for example canBeLiquidated below
|
|
377
374
|
/* example: assume BTC price is $40k (examine 10% up/down)
|
|
378
375
|
|
|
@@ -413,9 +410,7 @@ class ClearingHouseUser {
|
|
|
413
410
|
const market = this.clearingHouse.getMarketAccount(position.marketIndex);
|
|
414
411
|
const positionValue = (0, _1.calculateBaseAssetValue)(market, position, this.getOracleDataForMarket(market.marketIndex));
|
|
415
412
|
const marketMarginRequirement = positionValue
|
|
416
|
-
.mul(
|
|
417
|
-
? new _1.BN(market.marginRatioPartial)
|
|
418
|
-
: new _1.BN(market.marginRatioMaintenance))
|
|
413
|
+
.mul(new _1.BN(market.marginRatioMaintenance))
|
|
419
414
|
.div(numericConstants_1.MARGIN_PRECISION);
|
|
420
415
|
totalMarginRequirement = totalMarginRequirement.add(marketMarginRequirement);
|
|
421
416
|
}
|
|
@@ -428,14 +423,10 @@ class ClearingHouseUser {
|
|
|
428
423
|
return new _1.BN(-1);
|
|
429
424
|
}
|
|
430
425
|
const marginRequirementAfterTrade = marginRequirementExcludingTargetMarket.add(proposedMarketPositionValue
|
|
431
|
-
.mul(
|
|
432
|
-
? new _1.BN(market.marginRatioPartial)
|
|
433
|
-
: new _1.BN(market.marginRatioMaintenance))
|
|
426
|
+
.mul(new _1.BN(market.marginRatioMaintenance))
|
|
434
427
|
.div(numericConstants_1.MARGIN_PRECISION));
|
|
435
428
|
const freeCollateralAfterTrade = totalCollateral.sub(marginRequirementAfterTrade);
|
|
436
|
-
const marketMaxLeverage =
|
|
437
|
-
? this.getMaxLeverage(proposedMarketPosition.marketIndex, 'Partial')
|
|
438
|
-
: this.getMaxLeverage(proposedMarketPosition.marketIndex, 'Maintenance');
|
|
429
|
+
const marketMaxLeverage = this.getMaxLeverage(proposedMarketPosition.marketIndex, 'Maintenance');
|
|
439
430
|
let priceDelta;
|
|
440
431
|
if (proposedBaseAssetAmount.lt(numericConstants_1.ZERO)) {
|
|
441
432
|
priceDelta = freeCollateralAfterTrade
|
|
@@ -486,7 +477,7 @@ class ClearingHouseUser {
|
|
|
486
477
|
.neg();
|
|
487
478
|
return this.liquidationPrice({
|
|
488
479
|
marketIndex: positionMarketIndex,
|
|
489
|
-
}, closeBaseAmount
|
|
480
|
+
}, closeBaseAmount);
|
|
490
481
|
}
|
|
491
482
|
/**
|
|
492
483
|
* Get the maximum trade size for a given market, taking into account the user's current leverage, positions, collateral, etc.
|
package/lib/config.js
CHANGED
|
@@ -7,7 +7,7 @@ exports.configs = {
|
|
|
7
7
|
devnet: {
|
|
8
8
|
ENV: 'devnet',
|
|
9
9
|
PYTH_ORACLE_MAPPING_ADDRESS: 'BmA9Z6FjioHJPpjT39QazZyhDRUdZy2ezwx4GiDdE2u2',
|
|
10
|
-
CLEARING_HOUSE_PROGRAM_ID: '
|
|
10
|
+
CLEARING_HOUSE_PROGRAM_ID: '4oyTJnAQ9FqJj1y9mPytbWsLeeHmBzGYfuFqypwyQvuh',
|
|
11
11
|
USDC_MINT_ADDRESS: '8zGuJQqwhZafTah7Uc7Z4tXRnguqkn5KLFAP8oV6PHe2',
|
|
12
12
|
MARKETS: markets_1.DevnetMarkets,
|
|
13
13
|
BANKS: banks_1.DevnetBanks,
|
package/lib/constants/banks.js
CHANGED
|
@@ -12,11 +12,18 @@ exports.DevnetBanks = [
|
|
|
12
12
|
mint: new web3_js_1.PublicKey('8zGuJQqwhZafTah7Uc7Z4tXRnguqkn5KLFAP8oV6PHe2'),
|
|
13
13
|
},
|
|
14
14
|
{
|
|
15
|
-
symbol: '
|
|
15
|
+
symbol: 'SOL',
|
|
16
16
|
bankIndex: new __1.BN(1),
|
|
17
|
+
oracle: new web3_js_1.PublicKey('J83w4HKfqxwcq3BEMMkPFSppX3gqekLyLJBexebFVkix'),
|
|
18
|
+
oracleSource: __1.OracleSource.PYTH,
|
|
19
|
+
mint: new web3_js_1.PublicKey('So11111111111111111111111111111111111111112'),
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
symbol: 'BTC',
|
|
23
|
+
bankIndex: new __1.BN(2),
|
|
17
24
|
oracle: new web3_js_1.PublicKey('HovQMDrbAgAYPCmHVSrezcSmkMtXSSUsLDFANExrZh2J'),
|
|
18
25
|
oracleSource: __1.OracleSource.PYTH,
|
|
19
|
-
mint: new web3_js_1.PublicKey('
|
|
26
|
+
mint: new web3_js_1.PublicKey('3BZPwbcqB5kKScF3TEXxwNfx5ipV13kbRVDvfVp5c6fv'),
|
|
20
27
|
},
|
|
21
28
|
];
|
|
22
29
|
exports.MainnetBanks = [
|
|
@@ -21,6 +21,7 @@ export declare const BANK_RATE_PRECISION: BN;
|
|
|
21
21
|
export declare const BANK_WEIGHT_PRECISION: BN;
|
|
22
22
|
export declare const BANK_BALANCE_PRECISION_EXP: BN;
|
|
23
23
|
export declare const BANK_BALANCE_PRECISION: BN;
|
|
24
|
+
export declare const LIQUIDATION_FEE_PRECISION: BN;
|
|
24
25
|
export declare const QUOTE_PRECISION: BN;
|
|
25
26
|
export declare const MARK_PRICE_PRECISION: BN;
|
|
26
27
|
export declare const FUNDING_PAYMENT_PRECISION: BN;
|
|
@@ -29,6 +30,7 @@ export declare const AMM_RESERVE_PRECISION: BN;
|
|
|
29
30
|
export declare const BASE_PRECISION: BN;
|
|
30
31
|
export declare const BASE_PRECISION_EXP: BN;
|
|
31
32
|
export declare const AMM_TO_QUOTE_PRECISION_RATIO: BN;
|
|
33
|
+
export declare const PRICE_DIV_PEG: BN;
|
|
32
34
|
export declare const PRICE_TO_QUOTE_PRECISION: BN;
|
|
33
35
|
export declare const AMM_TIMES_PEG_TO_QUOTE_PRECISION_RATIO: BN;
|
|
34
36
|
export declare const MARGIN_PRECISION: BN;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.QUOTE_ASSET_BANK_INDEX = exports.ONE_YEAR = exports.BID_ASK_SPREAD_PRECISION = exports.MARGIN_PRECISION = exports.AMM_TIMES_PEG_TO_QUOTE_PRECISION_RATIO = exports.PRICE_TO_QUOTE_PRECISION = exports.AMM_TO_QUOTE_PRECISION_RATIO = exports.BASE_PRECISION_EXP = exports.BASE_PRECISION = exports.AMM_RESERVE_PRECISION = exports.PEG_PRECISION = exports.FUNDING_PAYMENT_PRECISION = exports.MARK_PRICE_PRECISION = exports.QUOTE_PRECISION = exports.BANK_BALANCE_PRECISION = exports.BANK_BALANCE_PRECISION_EXP = exports.BANK_WEIGHT_PRECISION = exports.BANK_RATE_PRECISION = exports.BANK_UTILIZATION_PRECISION = exports.BANK_CUMULATIVE_INTEREST_PRECISION = exports.BANK_INTEREST_PRECISION = exports.AMM_RESERVE_PRECISION_EXP = exports.PEG_PRECISION_EXP = exports.FUNDING_RATE_PRECISION_EXP = exports.MARK_PRICE_PRECISION_EXP = exports.FUNDING_PAYMENT_PRECISION_EXP = exports.QUOTE_PRECISION_EXP = exports.MAX_LEVERAGE = exports.TEN_MILLION = exports.BN_MAX = exports.TEN_THOUSAND = exports.TEN = exports.TWO = exports.ONE = exports.ZERO = void 0;
|
|
3
|
+
exports.QUOTE_ASSET_BANK_INDEX = exports.ONE_YEAR = exports.BID_ASK_SPREAD_PRECISION = exports.MARGIN_PRECISION = exports.AMM_TIMES_PEG_TO_QUOTE_PRECISION_RATIO = exports.PRICE_TO_QUOTE_PRECISION = exports.PRICE_DIV_PEG = exports.AMM_TO_QUOTE_PRECISION_RATIO = exports.BASE_PRECISION_EXP = exports.BASE_PRECISION = exports.AMM_RESERVE_PRECISION = exports.PEG_PRECISION = exports.FUNDING_PAYMENT_PRECISION = exports.MARK_PRICE_PRECISION = exports.QUOTE_PRECISION = exports.LIQUIDATION_FEE_PRECISION = exports.BANK_BALANCE_PRECISION = exports.BANK_BALANCE_PRECISION_EXP = exports.BANK_WEIGHT_PRECISION = exports.BANK_RATE_PRECISION = exports.BANK_UTILIZATION_PRECISION = exports.BANK_CUMULATIVE_INTEREST_PRECISION = exports.BANK_INTEREST_PRECISION = exports.AMM_RESERVE_PRECISION_EXP = exports.PEG_PRECISION_EXP = exports.FUNDING_RATE_PRECISION_EXP = exports.MARK_PRICE_PRECISION_EXP = exports.FUNDING_PAYMENT_PRECISION_EXP = exports.QUOTE_PRECISION_EXP = exports.MAX_LEVERAGE = exports.TEN_MILLION = exports.BN_MAX = exports.TEN_THOUSAND = exports.TEN = exports.TWO = exports.ONE = exports.ZERO = void 0;
|
|
4
4
|
const __1 = require("../");
|
|
5
5
|
exports.ZERO = new __1.BN(0);
|
|
6
6
|
exports.ONE = new __1.BN(1);
|
|
@@ -23,6 +23,7 @@ exports.BANK_RATE_PRECISION = new __1.BN(1000000);
|
|
|
23
23
|
exports.BANK_WEIGHT_PRECISION = new __1.BN(100);
|
|
24
24
|
exports.BANK_BALANCE_PRECISION_EXP = new __1.BN(6);
|
|
25
25
|
exports.BANK_BALANCE_PRECISION = new __1.BN(10).pow(exports.BANK_BALANCE_PRECISION_EXP);
|
|
26
|
+
exports.LIQUIDATION_FEE_PRECISION = new __1.BN(1000000);
|
|
26
27
|
exports.QUOTE_PRECISION = new __1.BN(10).pow(exports.QUOTE_PRECISION_EXP);
|
|
27
28
|
exports.MARK_PRICE_PRECISION = new __1.BN(10).pow(exports.MARK_PRICE_PRECISION_EXP);
|
|
28
29
|
exports.FUNDING_PAYMENT_PRECISION = new __1.BN(10).pow(exports.FUNDING_PAYMENT_PRECISION_EXP);
|
|
@@ -31,6 +32,7 @@ exports.AMM_RESERVE_PRECISION = new __1.BN(10).pow(exports.AMM_RESERVE_PRECISION
|
|
|
31
32
|
exports.BASE_PRECISION = exports.AMM_RESERVE_PRECISION;
|
|
32
33
|
exports.BASE_PRECISION_EXP = exports.AMM_RESERVE_PRECISION_EXP;
|
|
33
34
|
exports.AMM_TO_QUOTE_PRECISION_RATIO = exports.AMM_RESERVE_PRECISION.div(exports.QUOTE_PRECISION); // 10^7
|
|
35
|
+
exports.PRICE_DIV_PEG = exports.MARK_PRICE_PRECISION.div(exports.PEG_PRECISION); //10^7
|
|
34
36
|
exports.PRICE_TO_QUOTE_PRECISION = exports.MARK_PRICE_PRECISION.div(exports.QUOTE_PRECISION);
|
|
35
37
|
exports.AMM_TIMES_PEG_TO_QUOTE_PRECISION_RATIO = exports.AMM_RESERVE_PRECISION.mul(exports.PEG_PRECISION).div(exports.QUOTE_PRECISION); // 10^10
|
|
36
38
|
exports.MARGIN_PRECISION = exports.TEN_THOUSAND;
|
package/lib/factory/bigNum.d.ts
CHANGED
|
@@ -55,7 +55,7 @@ export declare class BigNum {
|
|
|
55
55
|
* @returns
|
|
56
56
|
*/
|
|
57
57
|
print(): string;
|
|
58
|
-
prettyPrint(): string;
|
|
58
|
+
prettyPrint(useTradePrecision?: boolean, precisionOverride?: number): string;
|
|
59
59
|
/**
|
|
60
60
|
* Print and remove unnecessary trailing zeroes
|
|
61
61
|
* @returns
|
|
@@ -75,7 +75,13 @@ export declare class BigNum {
|
|
|
75
75
|
*/
|
|
76
76
|
toPrecision(fixedPrecision: number, trailingZeroes?: boolean): string;
|
|
77
77
|
toTradePrecision(): string;
|
|
78
|
-
|
|
78
|
+
/**
|
|
79
|
+
* Print dollar formatted value. Defaults to fixed decimals two unless a given precision is given.
|
|
80
|
+
* @param useTradePrecision
|
|
81
|
+
* @param precisionOverride
|
|
82
|
+
* @returns
|
|
83
|
+
*/
|
|
84
|
+
toNotional(useTradePrecision?: boolean, precisionOverride?: number): string;
|
|
79
85
|
toMillified(precision?: number): string;
|
|
80
86
|
toJSON(): {
|
|
81
87
|
val: string;
|
package/lib/factory/bigNum.js
CHANGED
|
@@ -156,8 +156,8 @@ class BigNum {
|
|
|
156
156
|
printString = printString.slice(0, printString.length - 1);
|
|
157
157
|
return printString;
|
|
158
158
|
}
|
|
159
|
-
prettyPrint() {
|
|
160
|
-
const [leftSide, rightSide] = this.printShort().split(BigNum.delim);
|
|
159
|
+
prettyPrint(useTradePrecision, precisionOverride) {
|
|
160
|
+
const [leftSide, rightSide] = this.printShort(useTradePrecision, precisionOverride).split(BigNum.delim);
|
|
161
161
|
let formattedLeftSide = leftSide;
|
|
162
162
|
const isNeg = formattedLeftSide.includes('-');
|
|
163
163
|
if (isNeg) {
|
|
@@ -254,10 +254,18 @@ class BigNum {
|
|
|
254
254
|
toTradePrecision() {
|
|
255
255
|
return this.toPrecision(6, true);
|
|
256
256
|
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
257
|
+
/**
|
|
258
|
+
* Print dollar formatted value. Defaults to fixed decimals two unless a given precision is given.
|
|
259
|
+
* @param useTradePrecision
|
|
260
|
+
* @param precisionOverride
|
|
261
|
+
* @returns
|
|
262
|
+
*/
|
|
263
|
+
toNotional(useTradePrecision, precisionOverride) {
|
|
264
|
+
const prefix = `${this.lt(BigNum.zero()) ? `-` : ``}$`;
|
|
265
|
+
const val = useTradePrecision || precisionOverride
|
|
266
|
+
? this.prettyPrint(useTradePrecision, precisionOverride)
|
|
267
|
+
: BigNum.fromPrint(this.toFixed(2), new anchor_1.BN(2)).prettyPrint();
|
|
268
|
+
return `${prefix}${val.replace('-', '')}`;
|
|
261
269
|
}
|
|
262
270
|
toMillified(precision = 3) {
|
|
263
271
|
const stringVal = this.print();
|