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

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>;
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: {
@@ -101,16 +101,18 @@ export declare class ClearingHouse {
101
101
  getExpireOrdersIx(userAccountPublicKey: PublicKey): Promise<TransactionInstruction>;
102
102
  updateAMMs(marketIndexes: BN[]): Promise<TransactionSignature>;
103
103
  getUpdateAMMsIx(marketIndexes: BN[]): Promise<TransactionInstruction>;
104
- cancelOrder(orderId: BN): Promise<TransactionSignature>;
105
- getCancelOrderIx(orderId: BN): Promise<TransactionInstruction>;
104
+ cancelOrder(orderId?: BN): Promise<TransactionSignature>;
105
+ getCancelOrderIx(orderId?: BN): Promise<TransactionInstruction>;
106
106
  cancelOrderByUserId(userOrderId: number): Promise<TransactionSignature>;
107
107
  getCancelOrderByUserIdIx(userOrderId: number): Promise<TransactionInstruction>;
108
108
  cancelAllOrders(bestEffort?: boolean): Promise<TransactionSignature>;
109
109
  getCancelAllOrdersIx(bestEffort?: boolean): Promise<TransactionInstruction>;
110
110
  cancelOrdersByMarketAndSide(bestEffort?: boolean, marketIndexOnly?: BN, directionOnly?: PositionDirection): Promise<TransactionSignature>;
111
111
  getCancelOrdersByMarketAndSideIx(bestEffort?: boolean, marketIndexOnly?: BN, directionOnly?: PositionDirection): Promise<TransactionInstruction>;
112
- fillOrder(userAccountPublicKey: PublicKey, user: UserAccount, order: Order, makerInfo?: MakerInfo): Promise<TransactionSignature>;
112
+ fillOrder(userAccountPublicKey: PublicKey, user: UserAccount, order?: Order, makerInfo?: MakerInfo): Promise<TransactionSignature>;
113
113
  getFillOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order: Order, makerInfo?: MakerInfo): Promise<TransactionInstruction>;
114
+ triggerOrder(userAccountPublicKey: PublicKey, user: UserAccount, order: Order): Promise<TransactionSignature>;
115
+ getTriggerOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order: Order): Promise<TransactionInstruction>;
114
116
  placeAndTake(orderParams: OrderParams, makerInfo?: MakerInfo): Promise<TransactionSignature>;
115
117
  getPlaceAndTakeIx(orderParams: OrderParams, makerInfo?: MakerInfo): Promise<TransactionInstruction>;
116
118
  /**
@@ -561,15 +561,12 @@ class ClearingHouse {
561
561
  }
562
562
  async getCancelOrderIx(orderId) {
563
563
  const userAccountPublicKey = await this.getUserAccountPublicKey();
564
- const order = this.getOrder(orderId);
565
- const oracle = this.getMarketAccount(order.marketIndex).amm.oracle;
566
564
  const remainingAccounts = this.getRemainingAccounts({});
567
- return await this.program.instruction.cancelOrder(orderId, {
565
+ return await this.program.instruction.cancelOrder(orderId !== null && orderId !== void 0 ? orderId : null, {
568
566
  accounts: {
569
567
  state: await this.getStatePublicKey(),
570
568
  user: userAccountPublicKey,
571
569
  authority: this.wallet.publicKey,
572
- oracle,
573
570
  },
574
571
  remainingAccounts,
575
572
  });
@@ -708,6 +705,63 @@ class ClearingHouse {
708
705
  remainingAccounts,
709
706
  });
710
707
  }
708
+ async triggerOrder(userAccountPublicKey, user, order) {
709
+ const { txSig } = await this.txSender.send((0, utils_1.wrapInTx)(await this.getTriggerOrderIx(userAccountPublicKey, user, order)), [], this.opts);
710
+ return txSig;
711
+ }
712
+ async getTriggerOrderIx(userAccountPublicKey, userAccount, order) {
713
+ const fillerPublicKey = await this.getUserAccountPublicKey();
714
+ const marketIndex = order.marketIndex;
715
+ const marketAccount = this.getMarketAccount(marketIndex);
716
+ const bankAccountInfos = [
717
+ {
718
+ pubkey: this.getQuoteAssetBankAccount().pubkey,
719
+ isSigner: false,
720
+ isWritable: true,
721
+ },
722
+ ];
723
+ const marketAccountInfos = [
724
+ {
725
+ pubkey: marketAccount.pubkey,
726
+ isWritable: true,
727
+ isSigner: false,
728
+ },
729
+ ];
730
+ const oracleAccountInfos = [
731
+ {
732
+ pubkey: marketAccount.amm.oracle,
733
+ isWritable: false,
734
+ isSigner: false,
735
+ },
736
+ ];
737
+ for (const position of userAccount.positions) {
738
+ if (!(0, position_1.positionIsAvailable)(position) &&
739
+ !position.marketIndex.eq(order.marketIndex)) {
740
+ const market = this.getMarketAccount(position.marketIndex);
741
+ marketAccountInfos.push({
742
+ pubkey: market.pubkey,
743
+ isWritable: false,
744
+ isSigner: false,
745
+ });
746
+ oracleAccountInfos.push({
747
+ pubkey: market.amm.oracle,
748
+ isWritable: false,
749
+ isSigner: false,
750
+ });
751
+ }
752
+ }
753
+ const remainingAccounts = oracleAccountInfos.concat(bankAccountInfos.concat(marketAccountInfos));
754
+ const orderId = order.orderId;
755
+ return await this.program.instruction.triggerOrder(orderId, {
756
+ accounts: {
757
+ state: await this.getStatePublicKey(),
758
+ filler: fillerPublicKey,
759
+ user: userAccountPublicKey,
760
+ authority: this.wallet.publicKey,
761
+ },
762
+ remainingAccounts,
763
+ });
764
+ }
711
765
  async placeAndTake(orderParams, makerInfo) {
712
766
  const { txSig, slot } = await this.txSender.send((0, utils_1.wrapInTx)(await this.getPlaceAndTakeIx(orderParams, makerInfo)), [], this.opts);
713
767
  this.marketLastSlotCache.set(orderParams.marketIndex.toNumber(), slot);
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();
@@ -414,17 +414,14 @@
414
414
  "name": "authority",
415
415
  "isMut": false,
416
416
  "isSigner": true
417
- },
418
- {
419
- "name": "oracle",
420
- "isMut": false,
421
- "isSigner": false
422
417
  }
423
418
  ],
424
419
  "args": [
425
420
  {
426
421
  "name": "orderId",
427
- "type": "u64"
422
+ "type": {
423
+ "option": "u64"
424
+ }
428
425
  }
429
426
  ]
430
427
  },
@@ -445,11 +442,6 @@
445
442
  "name": "authority",
446
443
  "isMut": false,
447
444
  "isSigner": true
448
- },
449
- {
450
- "name": "oracle",
451
- "isMut": false,
452
- "isSigner": false
453
445
  }
454
446
  ],
455
447
  "args": [
@@ -491,7 +483,9 @@
491
483
  "args": [
492
484
  {
493
485
  "name": "orderId",
494
- "type": "u64"
486
+ "type": {
487
+ "option": "u64"
488
+ }
495
489
  },
496
490
  {
497
491
  "name": "makerOrderId",
@@ -582,6 +576,37 @@
582
576
  }
583
577
  ]
584
578
  },
579
+ {
580
+ "name": "triggerOrder",
581
+ "accounts": [
582
+ {
583
+ "name": "state",
584
+ "isMut": false,
585
+ "isSigner": false
586
+ },
587
+ {
588
+ "name": "authority",
589
+ "isMut": false,
590
+ "isSigner": true
591
+ },
592
+ {
593
+ "name": "filler",
594
+ "isMut": true,
595
+ "isSigner": false
596
+ },
597
+ {
598
+ "name": "user",
599
+ "isMut": true,
600
+ "isSigner": false
601
+ }
602
+ ],
603
+ "args": [
604
+ {
605
+ "name": "orderId",
606
+ "type": "u64"
607
+ }
608
+ ]
609
+ },
585
610
  {
586
611
  "name": "updateAmms",
587
612
  "accounts": [
@@ -993,11 +1018,6 @@
993
1018
  "name": "user",
994
1019
  "isMut": true,
995
1020
  "isSigner": false
996
- },
997
- {
998
- "name": "market",
999
- "isMut": false,
1000
- "isSigner": false
1001
1021
  }
1002
1022
  ],
1003
1023
  "args": []
@@ -1389,6 +1409,32 @@
1389
1409
  }
1390
1410
  ]
1391
1411
  },
1412
+ {
1413
+ "name": "updateMarketMaxSpread",
1414
+ "accounts": [
1415
+ {
1416
+ "name": "admin",
1417
+ "isMut": false,
1418
+ "isSigner": true
1419
+ },
1420
+ {
1421
+ "name": "state",
1422
+ "isMut": false,
1423
+ "isSigner": false
1424
+ },
1425
+ {
1426
+ "name": "market",
1427
+ "isMut": true,
1428
+ "isSigner": false
1429
+ }
1430
+ ],
1431
+ "args": [
1432
+ {
1433
+ "name": "maxSpread",
1434
+ "type": "u32"
1435
+ }
1436
+ ]
1437
+ },
1392
1438
  {
1393
1439
  "name": "updateMarketBaseAssetAmountStepSize",
1394
1440
  "accounts": [
@@ -2194,6 +2240,10 @@
2194
2240
  "name": "shortSpread",
2195
2241
  "type": "u128"
2196
2242
  },
2243
+ {
2244
+ "name": "maxSpread",
2245
+ "type": "u32"
2246
+ },
2197
2247
  {
2198
2248
  "name": "askBaseAssetReserve",
2199
2249
  "type": "u128"
@@ -2252,7 +2302,7 @@
2252
2302
  },
2253
2303
  {
2254
2304
  "name": "totalFeeMinusDistributions",
2255
- "type": "u128"
2305
+ "type": "i128"
2256
2306
  },
2257
2307
  {
2258
2308
  "name": "totalFeeWithdrawn",
@@ -2712,6 +2762,10 @@
2712
2762
  "defined": "OrderTriggerCondition"
2713
2763
  }
2714
2764
  },
2765
+ {
2766
+ "name": "triggered",
2767
+ "type": "bool"
2768
+ },
2715
2769
  {
2716
2770
  "name": "referrer",
2717
2771
  "type": "publicKey"
@@ -2848,6 +2902,9 @@
2848
2902
  {
2849
2903
  "name": "Fill"
2850
2904
  },
2905
+ {
2906
+ "name": "Trigger"
2907
+ },
2851
2908
  {
2852
2909
  "name": "Expire"
2853
2910
  }
@@ -3016,6 +3073,11 @@
3016
3073
  "type": "u64",
3017
3074
  "index": false
3018
3075
  },
3076
+ {
3077
+ "name": "oraclePrice",
3078
+ "type": "i128",
3079
+ "index": false
3080
+ },
3019
3081
  {
3020
3082
  "name": "from",
3021
3083
  "type": {
@@ -3217,7 +3279,7 @@
3217
3279
  },
3218
3280
  {
3219
3281
  "name": "totalFeeMinusDistributions",
3220
- "type": "u128",
3282
+ "type": "i128",
3221
3283
  "index": false
3222
3284
  },
3223
3285
  {
@@ -3349,6 +3411,16 @@
3349
3411
  },
3350
3412
  "index": false
3351
3413
  },
3414
+ {
3415
+ "name": "makerUnsettledPnl",
3416
+ "type": "i128",
3417
+ "index": false
3418
+ },
3419
+ {
3420
+ "name": "takerUnsettledPnl",
3421
+ "type": "i128",
3422
+ "index": false
3423
+ },
3352
3424
  {
3353
3425
  "name": "action",
3354
3426
  "type": {
@@ -3854,6 +3926,21 @@
3854
3926
  },
3855
3927
  {
3856
3928
  "code": 6087,
3929
+ "name": "OrderMustBeTriggeredFirst",
3930
+ "msg": "OrderMustBeTriggeredFirst"
3931
+ },
3932
+ {
3933
+ "code": 6088,
3934
+ "name": "OrderNotTriggerable",
3935
+ "msg": "OrderNotTriggerable"
3936
+ },
3937
+ {
3938
+ "code": 6089,
3939
+ "name": "OrderDidNotSatisfyTriggerCondition",
3940
+ "msg": "OrderDidNotSatisfyTriggerCondition"
3941
+ },
3942
+ {
3943
+ "code": 6090,
3857
3944
  "name": "DefaultError",
3858
3945
  "msg": "DefaultError"
3859
3946
  }
package/lib/math/amm.d.ts CHANGED
@@ -2,6 +2,8 @@
2
2
  import { BN } from '@project-serum/anchor';
3
3
  import { AMM, PositionDirection, SwapDirection, MarketAccount } from '../types';
4
4
  import { OraclePriceData } from '../oracles/types';
5
+ export declare function calculatePegFromTargetPrice(targetPrice: BN, baseAssetReserve: BN, quoteAssetReserve: BN): BN;
6
+ export declare function calculateOptimalPegAndBudget(amm: AMM, oraclePriceData: OraclePriceData): [BN, BN, BN, boolean];
5
7
  export declare function calculateNewAmm(amm: AMM, oraclePriceData: OraclePriceData): [BN, BN, BN, BN];
6
8
  export declare function calculateUpdatedAMM(amm: AMM, oraclePriceData: OraclePriceData): AMM;
7
9
  export declare function calculateUpdatedAMMSpreadReserves(amm: AMM, direction: PositionDirection, oraclePriceData: OraclePriceData): {
@@ -10,7 +12,7 @@ export declare function calculateUpdatedAMMSpreadReserves(amm: AMM, direction: P
10
12
  sqrtK: BN;
11
13
  newPeg: BN;
12
14
  };
13
- export declare function calculateBidAskPrice(amm: AMM, oraclePriceData: OraclePriceData): [BN, BN];
15
+ export declare function calculateBidAskPrice(amm: AMM, oraclePriceData: OraclePriceData, withUpdate?: boolean): [BN, BN];
14
16
  /**
15
17
  * Calculates a price given an arbitrary base and quote amount (they must have the same precision)
16
18
  *
@@ -31,6 +33,9 @@ export declare type AssetType = 'quote' | 'base';
31
33
  * @returns quoteAssetReserve and baseAssetReserve after swap. : Precision AMM_RESERVE_PRECISION
32
34
  */
33
35
  export declare function calculateAmmReservesAfterSwap(amm: Pick<AMM, 'pegMultiplier' | 'quoteAssetReserve' | 'sqrtK' | 'baseAssetReserve'>, inputAssetType: AssetType, swapAmount: BN, swapDirection: SwapDirection): [BN, BN];
36
+ export declare function calculateEffectiveLeverage(baseSpread: number, quoteAssetReserve: BN, terminalQuoteAssetReserve: BN, pegMultiplier: BN, netBaseAssetAmount: BN, markPrice: BN, totalFeeMinusDistributions: BN): number;
37
+ export declare function calculateMaxSpread(marginRatioInitial: number): number;
38
+ export declare function calculateSpreadBN(baseSpread: number, lastOracleMarkSpreadPct: BN, lastOracleConfPct: BN, maxSpread: number, quoteAssetReserve: BN, terminalQuoteAssetReserve: BN, pegMultiplier: BN, netBaseAssetAmount: BN, markPrice: BN, totalFeeMinusDistributions: BN): [number, number];
34
39
  export declare function calculateSpread(amm: AMM, direction: PositionDirection, oraclePriceData: OraclePriceData): number;
35
40
  export declare function calculateSpreadReserves(amm: AMM, direction: PositionDirection, oraclePriceData: OraclePriceData): {
36
41
  baseAssetReserve: BN;