@drift-labs/sdk 0.2.0-master.1 → 0.2.0-master.4

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.
@@ -1,5 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="bn.js" />
3
+ /// <reference types="node" />
3
4
  import { BankAccount, MarketAccount, OracleSource, StateAccount, UserAccount } from '../types';
4
5
  import StrictEventEmitter from 'strict-event-emitter-types';
5
6
  import { EventEmitter } from 'events';
package/lib/admin.d.ts CHANGED
@@ -20,6 +20,7 @@ export declare class Admin extends ClearingHouse {
20
20
  updateCurveUpdateIntensity(marketIndex: BN, curveUpdateIntensity: number): Promise<TransactionSignature>;
21
21
  updateMarginRatio(marketIndex: BN, marginRatioInitial: number, marginRatioPartial: number, marginRatioMaintenance: number): Promise<TransactionSignature>;
22
22
  updateMarketBaseSpread(marketIndex: BN, baseSpread: number): Promise<TransactionSignature>;
23
+ updateMarketMaxSpread(marketIndex: BN, maxSpread: number): Promise<TransactionSignature>;
23
24
  updatePartialLiquidationClosePercentage(numerator: BN, denominator: BN): Promise<TransactionSignature>;
24
25
  updatePartialLiquidationPenaltyPercentage(numerator: BN, denominator: BN): Promise<TransactionSignature>;
25
26
  updateFullLiquidationPenaltyPercentage(numerator: BN, denominator: BN): Promise<TransactionSignature>;
@@ -37,5 +38,7 @@ export declare class Admin extends ClearingHouse {
37
38
  updateFundingPaused(fundingPaused: boolean): Promise<TransactionSignature>;
38
39
  updateExchangePaused(exchangePaused: boolean): Promise<TransactionSignature>;
39
40
  disableAdminControlsPrices(): Promise<TransactionSignature>;
40
- updateOrderAuctionTime(time: BN | number): Promise<TransactionSignature>;
41
+ updateAuctionDuration(minDuration: BN | number, maxDuration: BN | number): Promise<TransactionSignature>;
42
+ updateMaxBaseAssetAmountRatio(marketIndex: BN, maxBaseAssetAmountRatio: number): Promise<TransactionSignature>;
43
+ updateMaxSlippageRatio(marketIndex: BN, maxSlippageRatio: number): Promise<TransactionSignature>;
41
44
  }
package/lib/admin.js CHANGED
@@ -255,6 +255,15 @@ class Admin extends clearingHouse_1.ClearingHouse {
255
255
  },
256
256
  });
257
257
  }
258
+ async updateMarketMaxSpread(marketIndex, maxSpread) {
259
+ return await this.program.rpc.updateMarketMaxSpread(maxSpread, {
260
+ accounts: {
261
+ admin: this.wallet.publicKey,
262
+ state: await this.getStatePublicKey(),
263
+ market: await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex),
264
+ },
265
+ });
266
+ }
258
267
  async updatePartialLiquidationClosePercentage(numerator, denominator) {
259
268
  return await this.program.rpc.updatePartialLiquidationClosePercentage(numerator, denominator, {
260
269
  accounts: {
@@ -394,11 +403,29 @@ class Admin extends clearingHouse_1.ClearingHouse {
394
403
  },
395
404
  });
396
405
  }
397
- async updateOrderAuctionTime(time) {
398
- return await this.program.rpc.updateOrderAuctionTime(typeof time === 'number' ? time : time.toNumber, {
406
+ async updateAuctionDuration(minDuration, maxDuration) {
407
+ return await this.program.rpc.updateAuctionDuration(typeof minDuration === 'number' ? minDuration : minDuration.toNumber(), typeof maxDuration === 'number' ? maxDuration : maxDuration.toNumber(), {
408
+ accounts: {
409
+ admin: this.wallet.publicKey,
410
+ state: await this.getStatePublicKey(),
411
+ },
412
+ });
413
+ }
414
+ async updateMaxBaseAssetAmountRatio(marketIndex, maxBaseAssetAmountRatio) {
415
+ return await this.program.rpc.updateMaxBaseAssetAmountRatio(maxBaseAssetAmountRatio, {
416
+ accounts: {
417
+ admin: this.wallet.publicKey,
418
+ state: await this.getStatePublicKey(),
419
+ market: this.getMarketAccount(marketIndex).pubkey,
420
+ },
421
+ });
422
+ }
423
+ async updateMaxSlippageRatio(marketIndex, maxSlippageRatio) {
424
+ return await this.program.rpc.updateMaxSlippageRatio(maxSlippageRatio, {
399
425
  accounts: {
400
426
  admin: this.wallet.publicKey,
401
427
  state: await this.getStatePublicKey(),
428
+ market: this.getMarketAccount(marketIndex).pubkey,
402
429
  },
403
430
  });
404
431
  }
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="bn.js" />
3
3
  import { AnchorProvider, BN, Program } from '@project-serum/anchor';
4
- import { StateAccount, IWallet, PositionDirection, UserAccount, MarketAccount, OrderParams, Order, BankAccount, UserBankBalance, MakerInfo } from './types';
4
+ import { StateAccount, IWallet, PositionDirection, UserAccount, MarketAccount, OrderParams, Order, BankAccount, UserBankBalance, MakerInfo, OptionalOrderParams } from './types';
5
5
  import { Connection, PublicKey, TransactionSignature, ConfirmOptions, TransactionInstruction, AccountMeta } from '@solana/web3.js';
6
6
  import { MockUSDCFaucet } from './mockUSDCFaucet';
7
7
  import { EventEmitter } from 'events';
@@ -95,24 +95,21 @@ export declare class ClearingHouse {
95
95
  updateBankCumulativeInterest(bankIndex: BN): Promise<TransactionSignature>;
96
96
  updateBankCumulativeInterestIx(bankIndex: BN): Promise<TransactionInstruction>;
97
97
  openPosition(direction: PositionDirection, amount: BN, marketIndex: BN, limitPrice?: BN): Promise<TransactionSignature>;
98
- placeOrder(orderParams: OrderParams): Promise<TransactionSignature>;
99
- getPlaceOrderIx(orderParams: OrderParams): Promise<TransactionInstruction>;
100
- expireOrders(userAccountPublicKey: PublicKey): Promise<TransactionSignature>;
101
- getExpireOrdersIx(userAccountPublicKey: PublicKey): Promise<TransactionInstruction>;
98
+ placeOrder(orderParams: OptionalOrderParams): Promise<TransactionSignature>;
99
+ getOrderParams(optionalOrderParams: OptionalOrderParams): OrderParams;
100
+ getPlaceOrderIx(orderParams: OptionalOrderParams): Promise<TransactionInstruction>;
102
101
  updateAMMs(marketIndexes: BN[]): Promise<TransactionSignature>;
103
102
  getUpdateAMMsIx(marketIndexes: BN[]): Promise<TransactionInstruction>;
104
- cancelOrder(orderId: BN): Promise<TransactionSignature>;
105
- getCancelOrderIx(orderId: BN): Promise<TransactionInstruction>;
103
+ cancelOrder(orderId?: BN): Promise<TransactionSignature>;
104
+ getCancelOrderIx(orderId?: BN): Promise<TransactionInstruction>;
106
105
  cancelOrderByUserId(userOrderId: number): Promise<TransactionSignature>;
107
106
  getCancelOrderByUserIdIx(userOrderId: number): Promise<TransactionInstruction>;
108
- cancelAllOrders(bestEffort?: boolean): Promise<TransactionSignature>;
109
- getCancelAllOrdersIx(bestEffort?: boolean): Promise<TransactionInstruction>;
110
- cancelOrdersByMarketAndSide(bestEffort?: boolean, marketIndexOnly?: BN, directionOnly?: PositionDirection): Promise<TransactionSignature>;
111
- getCancelOrdersByMarketAndSideIx(bestEffort?: boolean, marketIndexOnly?: BN, directionOnly?: PositionDirection): Promise<TransactionInstruction>;
112
- fillOrder(userAccountPublicKey: PublicKey, user: UserAccount, order: Order, makerInfo?: MakerInfo): Promise<TransactionSignature>;
107
+ fillOrder(userAccountPublicKey: PublicKey, user: UserAccount, order?: Order, makerInfo?: MakerInfo): Promise<TransactionSignature>;
113
108
  getFillOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order: Order, makerInfo?: MakerInfo): Promise<TransactionInstruction>;
114
- placeAndTake(orderParams: OrderParams, makerInfo?: MakerInfo): Promise<TransactionSignature>;
115
- getPlaceAndTakeIx(orderParams: OrderParams, makerInfo?: MakerInfo): Promise<TransactionInstruction>;
109
+ triggerOrder(userAccountPublicKey: PublicKey, user: UserAccount, order: Order): Promise<TransactionSignature>;
110
+ getTriggerOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order: Order): Promise<TransactionInstruction>;
111
+ placeAndTake(orderParams: OptionalOrderParams, makerInfo?: MakerInfo): Promise<TransactionSignature>;
112
+ getPlaceAndTakeIx(orderParams: OptionalOrderParams, makerInfo?: MakerInfo): Promise<TransactionInstruction>;
116
113
  /**
117
114
  * Close an entire position. If you want to reduce a position, use the {@link openPosition} method in the opposite direction of the current position.
118
115
  * @param marketIndex
@@ -29,6 +29,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.ClearingHouse = void 0;
30
30
  const anchor_1 = require("@project-serum/anchor");
31
31
  const spl_token_1 = require("@solana/spl-token");
32
+ const types_1 = require("./types");
32
33
  const anchor = __importStar(require("@project-serum/anchor"));
33
34
  const clearing_house_json_1 = __importDefault(require("./idl/clearing_house.json"));
34
35
  const web3_js_1 = require("@solana/web3.js");
@@ -42,7 +43,6 @@ const pollingClearingHouseAccountSubscriber_1 = require("./accounts/pollingClear
42
43
  const webSocketClearingHouseAccountSubscriber_1 = require("./accounts/webSocketClearingHouseAccountSubscriber");
43
44
  const retryTxSender_1 = require("./tx/retryTxSender");
44
45
  const clearingHouseUser_1 = require("./clearingHouseUser");
45
- const orderParams_1 = require("./orderParams");
46
46
  const config_1 = require("./config");
47
47
  /**
48
48
  * # ClearingHouse
@@ -482,17 +482,25 @@ class ClearingHouse {
482
482
  });
483
483
  }
484
484
  async openPosition(direction, amount, marketIndex, limitPrice) {
485
- return await this.placeAndTake((0, orderParams_1.getMarketOrderParams)(marketIndex, direction, numericConstants_1.ZERO, amount, false, limitPrice));
485
+ return await this.placeAndTake({
486
+ orderType: types_1.OrderType.MARKET,
487
+ marketIndex,
488
+ direction,
489
+ baseAssetAmount: amount,
490
+ price: limitPrice,
491
+ });
486
492
  }
487
493
  async placeOrder(orderParams) {
488
494
  const { txSig, slot } = await this.txSender.send((0, utils_1.wrapInTx)(await this.getPlaceOrderIx(orderParams)), [], this.opts);
489
495
  this.marketLastSlotCache.set(orderParams.marketIndex.toNumber(), slot);
490
496
  return txSig;
491
497
  }
498
+ getOrderParams(optionalOrderParams) {
499
+ return Object.assign({}, types_1.DefaultOrderParams, optionalOrderParams);
500
+ }
492
501
  async getPlaceOrderIx(orderParams) {
502
+ orderParams = this.getOrderParams(orderParams);
493
503
  const userAccountPublicKey = await this.getUserAccountPublicKey();
494
- const priceOracle = this.getMarketAccount(orderParams.marketIndex).amm
495
- .oracle;
496
504
  const remainingAccounts = this.getRemainingAccounts({
497
505
  writableMarketIndex: orderParams.marketIndex,
498
506
  });
@@ -501,26 +509,10 @@ class ClearingHouse {
501
509
  state: await this.getStatePublicKey(),
502
510
  user: userAccountPublicKey,
503
511
  authority: this.wallet.publicKey,
504
- oracle: priceOracle,
505
512
  },
506
513
  remainingAccounts,
507
514
  });
508
515
  }
509
- async expireOrders(userAccountPublicKey) {
510
- const { txSig } = await this.txSender.send((0, utils_1.wrapInTx)(await this.getExpireOrdersIx(userAccountPublicKey)), [], this.opts);
511
- return txSig;
512
- }
513
- async getExpireOrdersIx(userAccountPublicKey) {
514
- const fillerPublicKey = await this.getUserAccountPublicKey();
515
- return await this.program.instruction.expireOrders({
516
- accounts: {
517
- state: await this.getStatePublicKey(),
518
- filler: fillerPublicKey,
519
- user: userAccountPublicKey,
520
- authority: this.wallet.publicKey,
521
- },
522
- });
523
- }
524
516
  async updateAMMs(marketIndexes) {
525
517
  const { txSig } = await this.txSender.send((0, utils_1.wrapInTx)(await this.getUpdateAMMsIx(marketIndexes)), [], this.opts);
526
518
  return txSig;
@@ -561,15 +553,12 @@ class ClearingHouse {
561
553
  }
562
554
  async getCancelOrderIx(orderId) {
563
555
  const userAccountPublicKey = await this.getUserAccountPublicKey();
564
- const order = this.getOrder(orderId);
565
- const oracle = this.getMarketAccount(order.marketIndex).amm.oracle;
566
556
  const remainingAccounts = this.getRemainingAccounts({});
567
- return await this.program.instruction.cancelOrder(orderId, {
557
+ return await this.program.instruction.cancelOrder(orderId !== null && orderId !== void 0 ? orderId : null, {
568
558
  accounts: {
569
559
  state: await this.getStatePublicKey(),
570
560
  user: userAccountPublicKey,
571
561
  authority: this.wallet.publicKey,
572
- oracle,
573
562
  },
574
563
  remainingAccounts,
575
564
  });
@@ -593,63 +582,79 @@ class ClearingHouse {
593
582
  remainingAccounts,
594
583
  });
595
584
  }
596
- async cancelAllOrders(bestEffort) {
597
- const { txSig } = await this.txSender.send((0, utils_1.wrapInTx)(await this.getCancelAllOrdersIx(bestEffort)), [], this.opts);
585
+ async fillOrder(userAccountPublicKey, user, order, makerInfo) {
586
+ const { txSig } = await this.txSender.send((0, utils_1.wrapInTx)(await this.getFillOrderIx(userAccountPublicKey, user, order, makerInfo)), [], this.opts);
598
587
  return txSig;
599
588
  }
600
- async getCancelAllOrdersIx(bestEffort) {
601
- const userAccountPublicKey = await this.getUserAccountPublicKey();
602
- const remainingAccounts = this.getRemainingAccounts({});
603
- for (const order of this.getUserAccount().orders) {
604
- const oracle = this.getMarketAccount(order.marketIndex).amm.oracle;
605
- remainingAccounts.push({
606
- pubkey: oracle,
589
+ async getFillOrderIx(userAccountPublicKey, userAccount, order, makerInfo) {
590
+ const fillerPublicKey = await this.getUserAccountPublicKey();
591
+ const marketIndex = order.marketIndex;
592
+ const marketAccount = this.getMarketAccount(marketIndex);
593
+ const bankAccountInfos = [
594
+ {
595
+ pubkey: this.getQuoteAssetBankAccount().pubkey,
596
+ isSigner: false,
597
+ isWritable: true,
598
+ },
599
+ ];
600
+ const marketAccountInfos = [
601
+ {
602
+ pubkey: marketAccount.pubkey,
603
+ isWritable: true,
604
+ isSigner: false,
605
+ },
606
+ ];
607
+ const oracleAccountInfos = [
608
+ {
609
+ pubkey: marketAccount.amm.oracle,
607
610
  isWritable: false,
608
611
  isSigner: false,
609
- });
610
- }
611
- return await this.program.instruction.cancelAllOrders(bestEffort, {
612
- accounts: {
613
- state: await this.getStatePublicKey(),
614
- user: userAccountPublicKey,
615
- authority: this.wallet.publicKey,
616
612
  },
617
- remainingAccounts,
618
- });
619
- }
620
- async cancelOrdersByMarketAndSide(bestEffort, marketIndexOnly, directionOnly) {
621
- const { txSig } = await this.txSender.send((0, utils_1.wrapInTx)(await this.getCancelOrdersByMarketAndSideIx(bestEffort, marketIndexOnly, directionOnly)), [], this.opts);
622
- return txSig;
623
- }
624
- async getCancelOrdersByMarketAndSideIx(bestEffort, marketIndexOnly, directionOnly) {
625
- const userAccountPublicKey = await this.getUserAccountPublicKey();
626
- const remainingAccounts = this.getRemainingAccounts({});
627
- for (const order of this.getUserAccount().orders) {
628
- const oracle = this.getMarketAccount(order.marketIndex).amm.oracle;
613
+ ];
614
+ for (const position of userAccount.positions) {
615
+ if (!(0, position_1.positionIsAvailable)(position) &&
616
+ !position.marketIndex.eq(order.marketIndex)) {
617
+ const market = this.getMarketAccount(position.marketIndex);
618
+ marketAccountInfos.push({
619
+ pubkey: market.pubkey,
620
+ isWritable: true,
621
+ isSigner: false,
622
+ });
623
+ oracleAccountInfos.push({
624
+ pubkey: market.amm.oracle,
625
+ isWritable: false,
626
+ isSigner: false,
627
+ });
628
+ }
629
+ }
630
+ const remainingAccounts = oracleAccountInfos.concat(bankAccountInfos.concat(marketAccountInfos));
631
+ if (makerInfo) {
629
632
  remainingAccounts.push({
630
- pubkey: oracle,
631
- isWritable: false,
633
+ pubkey: makerInfo.maker,
634
+ isWritable: true,
632
635
  isSigner: false,
633
636
  });
634
637
  }
635
- return await this.program.instruction.cancelOrdersByMarketAndSide(bestEffort, marketIndexOnly, directionOnly, {
638
+ const orderId = order.orderId;
639
+ const makerOrderId = makerInfo ? makerInfo.order.orderId : null;
640
+ return await this.program.instruction.fillOrder(orderId, makerOrderId, {
636
641
  accounts: {
637
642
  state: await this.getStatePublicKey(),
643
+ filler: fillerPublicKey,
638
644
  user: userAccountPublicKey,
639
645
  authority: this.wallet.publicKey,
640
646
  },
641
647
  remainingAccounts,
642
648
  });
643
649
  }
644
- async fillOrder(userAccountPublicKey, user, order, makerInfo) {
645
- const { txSig } = await this.txSender.send((0, utils_1.wrapInTx)(await this.getFillOrderIx(userAccountPublicKey, user, order, makerInfo)), [], this.opts);
650
+ async triggerOrder(userAccountPublicKey, user, order) {
651
+ const { txSig } = await this.txSender.send((0, utils_1.wrapInTx)(await this.getTriggerOrderIx(userAccountPublicKey, user, order)), [], this.opts);
646
652
  return txSig;
647
653
  }
648
- async getFillOrderIx(userAccountPublicKey, userAccount, order, makerInfo) {
654
+ async getTriggerOrderIx(userAccountPublicKey, userAccount, order) {
649
655
  const fillerPublicKey = await this.getUserAccountPublicKey();
650
656
  const marketIndex = order.marketIndex;
651
657
  const marketAccount = this.getMarketAccount(marketIndex);
652
- const oracle = marketAccount.amm.oracle;
653
658
  const bankAccountInfos = [
654
659
  {
655
660
  pubkey: this.getQuoteAssetBankAccount().pubkey,
@@ -688,22 +693,13 @@ class ClearingHouse {
688
693
  }
689
694
  }
690
695
  const remainingAccounts = oracleAccountInfos.concat(bankAccountInfos.concat(marketAccountInfos));
691
- if (makerInfo) {
692
- remainingAccounts.push({
693
- pubkey: makerInfo.maker,
694
- isWritable: true,
695
- isSigner: false,
696
- });
697
- }
698
696
  const orderId = order.orderId;
699
- const makerOrderId = makerInfo ? makerInfo.order.orderId : null;
700
- return await this.program.instruction.fillOrder(orderId, makerOrderId, {
697
+ return await this.program.instruction.triggerOrder(orderId, {
701
698
  accounts: {
702
699
  state: await this.getStatePublicKey(),
703
700
  filler: fillerPublicKey,
704
701
  user: userAccountPublicKey,
705
702
  authority: this.wallet.publicKey,
706
- oracle: oracle,
707
703
  },
708
704
  remainingAccounts,
709
705
  });
@@ -714,9 +710,8 @@ class ClearingHouse {
714
710
  return txSig;
715
711
  }
716
712
  async getPlaceAndTakeIx(orderParams, makerInfo) {
713
+ orderParams = this.getOrderParams(orderParams);
717
714
  const userAccountPublicKey = await this.getUserAccountPublicKey();
718
- const priceOracle = this.getMarketAccount(orderParams.marketIndex).amm
719
- .oracle;
720
715
  const remainingAccounts = this.getRemainingAccounts({
721
716
  writableMarketIndex: orderParams.marketIndex,
722
717
  writableBankIndex: numericConstants_1.QUOTE_ASSET_BANK_INDEX,
@@ -735,7 +730,6 @@ class ClearingHouse {
735
730
  state: await this.getStatePublicKey(),
736
731
  user: userAccountPublicKey,
737
732
  authority: this.wallet.publicKey,
738
- oracle: priceOracle,
739
733
  },
740
734
  remainingAccounts,
741
735
  });
@@ -750,7 +744,13 @@ class ClearingHouse {
750
744
  if (!userPosition) {
751
745
  throw Error(`No position in market ${marketIndex.toString()}`);
752
746
  }
753
- return await this.placeAndTake((0, orderParams_1.getMarketOrderParams)(marketIndex, (0, position_1.findDirectionToClose)(userPosition), numericConstants_1.ZERO, userPosition.baseAssetAmount, true, undefined));
747
+ return await this.placeAndTake({
748
+ orderType: types_1.OrderType.MARKET,
749
+ marketIndex,
750
+ direction: (0, position_1.findDirectionToClose)(userPosition),
751
+ baseAssetAmount: userPosition.baseAssetAmount,
752
+ reduceOnly: true,
753
+ });
754
754
  }
755
755
  async settlePNLs(users, marketIndex) {
756
756
  const ixs = [];
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: 'GCuH76fb1rXc7bjFXNcnNvWSekLgzpsnMbc1Ng4FsGSs',
10
+ CLEARING_HOUSE_PROGRAM_ID: '9jwr5nC2f9yAraXrg4UzHXmCX3vi9FQkjD6p9e8bRqNa',
11
11
  USDC_MINT_ADDRESS: '8zGuJQqwhZafTah7Uc7Z4tXRnguqkn5KLFAP8oV6PHe2',
12
12
  MARKETS: markets_1.DevnetMarkets,
13
13
  BANKS: banks_1.DevnetBanks,
@@ -29,6 +29,7 @@ export declare const AMM_RESERVE_PRECISION: BN;
29
29
  export declare const BASE_PRECISION: BN;
30
30
  export declare const BASE_PRECISION_EXP: BN;
31
31
  export declare const AMM_TO_QUOTE_PRECISION_RATIO: BN;
32
+ export declare const PRICE_DIV_PEG: BN;
32
33
  export declare const PRICE_TO_QUOTE_PRECISION: BN;
33
34
  export declare const AMM_TIMES_PEG_TO_QUOTE_PRECISION_RATIO: BN;
34
35
  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.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);
@@ -31,6 +31,7 @@ exports.AMM_RESERVE_PRECISION = new __1.BN(10).pow(exports.AMM_RESERVE_PRECISION
31
31
  exports.BASE_PRECISION = exports.AMM_RESERVE_PRECISION;
32
32
  exports.BASE_PRECISION_EXP = exports.AMM_RESERVE_PRECISION_EXP;
33
33
  exports.AMM_TO_QUOTE_PRECISION_RATIO = exports.AMM_RESERVE_PRECISION.div(exports.QUOTE_PRECISION); // 10^7
34
+ exports.PRICE_DIV_PEG = exports.MARK_PRICE_PRECISION.div(exports.PEG_PRECISION); //10^7
34
35
  exports.PRICE_TO_QUOTE_PRECISION = exports.MARK_PRICE_PRECISION.div(exports.QUOTE_PRECISION);
35
36
  exports.AMM_TIMES_PEG_TO_QUOTE_PRECISION_RATIO = exports.AMM_RESERVE_PRECISION.mul(exports.PEG_PRECISION).div(exports.QUOTE_PRECISION); // 10^10
36
37
  exports.MARGIN_PRECISION = exports.TEN_THOUSAND;
@@ -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
- toNotional(): string;
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;
@@ -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
- toNotional() {
258
- return `${this.lt(BigNum.zero()) ? `-` : ``}$${BigNum.fromPrint(this.toFixed(2), new anchor_1.BN(2))
259
- .prettyPrint()
260
- .replace('-', '')}`;
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();