@drift-labs/sdk 2.43.0-beta.16 → 2.43.0-beta.18

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/VERSION CHANGED
@@ -1 +1 @@
1
- 2.43.0-beta.16
1
+ 2.43.0-beta.18
@@ -33,6 +33,7 @@ export declare class AdminClient extends DriftClient {
33
33
  updateSpotFeeStructure(feeStructure: FeeStructure): Promise<TransactionSignature>;
34
34
  updateInitialPctToLiquidate(initialPctToLiquidate: number): Promise<TransactionSignature>;
35
35
  updateLiquidationDuration(liquidationDuration: number): Promise<TransactionSignature>;
36
+ updateLiquidationMarginBufferRatio(updateLiquidationMarginBufferRatio: number): Promise<TransactionSignature>;
36
37
  updateOracleGuardRails(oracleGuardRails: OracleGuardRails): Promise<TransactionSignature>;
37
38
  updateStateSettlementDuration(settlementDuration: number): Promise<TransactionSignature>;
38
39
  updateWithdrawGuardThreshold(spotMarketIndex: number, withdrawGuardThreshold: BN): Promise<TransactionSignature>;
@@ -421,6 +421,14 @@ class AdminClient extends driftClient_1.DriftClient {
421
421
  },
422
422
  });
423
423
  }
424
+ async updateLiquidationMarginBufferRatio(updateLiquidationMarginBufferRatio) {
425
+ return await this.program.rpc.updateLiquidationMarginBufferRatio(updateLiquidationMarginBufferRatio, {
426
+ accounts: {
427
+ admin: this.wallet.publicKey,
428
+ state: await this.getStatePublicKey(),
429
+ },
430
+ });
431
+ }
424
432
  async updateOracleGuardRails(oracleGuardRails) {
425
433
  const tx = await this.program.transaction.updateOracleGuardRails(oracleGuardRails, {
426
434
  accounts: {
@@ -87,10 +87,16 @@ export declare class DLOB {
87
87
  takerNode: DLOBNode;
88
88
  makerNode: DLOBNode;
89
89
  } | undefined;
90
- getBestAsk(marketIndex: number, fallbackAsk: BN | undefined, slot: number, marketType: MarketType, oraclePriceData: OraclePriceData): BN;
91
- getBestBid(marketIndex: number, fallbackBid: BN | undefined, slot: number, marketType: MarketType, oraclePriceData: OraclePriceData): BN;
90
+ getBestAsk(marketIndex: number, slot: number, marketType: MarketType, oraclePriceData: OraclePriceData): BN;
91
+ getBestBid(marketIndex: number, slot: number, marketType: MarketType, oraclePriceData: OraclePriceData): BN;
92
+ getStopLosses(marketIndex: number, marketType: MarketType, direction: PositionDirection): Generator<DLOBNode>;
93
+ getStopLossMarkets(marketIndex: number, marketType: MarketType, direction: PositionDirection): Generator<DLOBNode>;
94
+ getStopLossLimits(marketIndex: number, marketType: MarketType, direction: PositionDirection): Generator<DLOBNode>;
95
+ getTakeProfits(marketIndex: number, marketType: MarketType, direction: PositionDirection): Generator<DLOBNode>;
96
+ getTakeProfitMarkets(marketIndex: number, marketType: MarketType, direction: PositionDirection): Generator<DLOBNode>;
97
+ getTakeProfitLimits(marketIndex: number, marketType: MarketType, direction: PositionDirection): Generator<DLOBNode>;
92
98
  findNodesToTrigger(marketIndex: number, slot: number, oraclePrice: BN, marketType: MarketType, stateAccount: StateAccount): NodeToTrigger[];
93
- printTopOfOrderLists(sdkConfig: any, driftClient: DriftClient, slotSubscriber: SlotSubscriber, marketIndex: number, marketType: MarketType): void;
99
+ printTop(driftClient: DriftClient, slotSubscriber: SlotSubscriber, marketIndex: number, marketType: MarketType): void;
94
100
  getDLOBOrders(): DLOBOrders;
95
101
  getNodeLists(): Generator<NodeList<DLOBNodeType>>;
96
102
  /**
package/lib/dlob/DLOB.js CHANGED
@@ -796,16 +796,80 @@ class DLOB {
796
796
  };
797
797
  }
798
798
  }
799
- getBestAsk(marketIndex, fallbackAsk, slot, marketType, oraclePriceData) {
800
- return this.getAsks(marketIndex, fallbackAsk, slot, marketType, oraclePriceData)
799
+ getBestAsk(marketIndex, slot, marketType, oraclePriceData) {
800
+ return this.getRestingLimitAsks(marketIndex, slot, marketType, oraclePriceData)
801
801
  .next()
802
802
  .value.getPrice(oraclePriceData, slot);
803
803
  }
804
- getBestBid(marketIndex, fallbackBid, slot, marketType, oraclePriceData) {
805
- return this.getBids(marketIndex, fallbackBid, slot, marketType, oraclePriceData)
804
+ getBestBid(marketIndex, slot, marketType, oraclePriceData) {
805
+ return this.getRestingLimitBids(marketIndex, slot, marketType, oraclePriceData)
806
806
  .next()
807
807
  .value.getPrice(oraclePriceData, slot);
808
808
  }
809
+ *getStopLosses(marketIndex, marketType, direction) {
810
+ const marketTypeStr = (0, __1.getVariant)(marketType);
811
+ const marketNodeLists = this.orderLists.get(marketTypeStr).get(marketIndex);
812
+ if ((0, __1.isVariant)(direction, 'long') && marketNodeLists.trigger.below) {
813
+ for (const node of marketNodeLists.trigger.below.getGenerator()) {
814
+ if ((0, __1.isVariant)(node.order.direction, 'short')) {
815
+ yield node;
816
+ }
817
+ }
818
+ }
819
+ else if ((0, __1.isVariant)(direction, 'short') && marketNodeLists.trigger.above) {
820
+ for (const node of marketNodeLists.trigger.above.getGenerator()) {
821
+ if ((0, __1.isVariant)(node.order.direction, 'long')) {
822
+ yield node;
823
+ }
824
+ }
825
+ }
826
+ }
827
+ *getStopLossMarkets(marketIndex, marketType, direction) {
828
+ for (const node of this.getStopLosses(marketIndex, marketType, direction)) {
829
+ if ((0, __1.isVariant)(node.order.orderType, 'triggerMarket')) {
830
+ yield node;
831
+ }
832
+ }
833
+ }
834
+ *getStopLossLimits(marketIndex, marketType, direction) {
835
+ for (const node of this.getStopLosses(marketIndex, marketType, direction)) {
836
+ if ((0, __1.isVariant)(node.order.orderType, 'triggerLimit')) {
837
+ yield node;
838
+ }
839
+ }
840
+ }
841
+ *getTakeProfits(marketIndex, marketType, direction) {
842
+ const marketTypeStr = (0, __1.getVariant)(marketType);
843
+ const marketNodeLists = this.orderLists.get(marketTypeStr).get(marketIndex);
844
+ if ((0, __1.isVariant)(direction, 'long') && marketNodeLists.trigger.above) {
845
+ for (const node of marketNodeLists.trigger.above.getGenerator()) {
846
+ if ((0, __1.isVariant)(node.order.direction, 'short')) {
847
+ yield node;
848
+ }
849
+ }
850
+ }
851
+ else if ((0, __1.isVariant)(direction, 'short') && marketNodeLists.trigger.below) {
852
+ for (const node of marketNodeLists.trigger.below.getGenerator()) {
853
+ if ((0, __1.isVariant)(node.order.direction, 'long')) {
854
+ yield node;
855
+ }
856
+ }
857
+ }
858
+ }
859
+ *getTakeProfitMarkets(marketIndex, marketType, direction) {
860
+ for (const node of this.getTakeProfits(marketIndex, marketType, direction)) {
861
+ if ((0, __1.isVariant)(node.order.orderType, 'triggerMarket')) {
862
+ yield node;
863
+ }
864
+ }
865
+ }
866
+ *getTakeProfitLimits(marketIndex, marketType, direction) {
867
+ for (const node of this.getTakeProfits(marketIndex, marketType, direction)) {
868
+ if ((0, __1.isVariant)(node.order.orderType, 'triggerLimit')) {
869
+ yield node;
870
+ }
871
+ }
872
+ }
809
873
  findNodesToTrigger(marketIndex, slot, oraclePrice, marketType, stateAccount) {
810
874
  if ((0, exchangeStatus_1.exchangePaused)(stateAccount)) {
811
875
  return [];
@@ -845,15 +909,12 @@ class DLOB {
845
909
  }
846
910
  return nodesToTrigger;
847
911
  }
848
- printTopOfOrderLists(sdkConfig, driftClient, slotSubscriber, marketIndex, marketType) {
912
+ printTop(driftClient, slotSubscriber, marketIndex, marketType) {
849
913
  if ((0, __1.isVariant)(marketType, 'perp')) {
850
- const market = driftClient.getPerpMarketAccount(marketIndex);
851
914
  const slot = slotSubscriber.getSlot();
852
915
  const oraclePriceData = driftClient.getOracleDataForPerpMarket(marketIndex);
853
- const fallbackAsk = (0, __1.calculateAskPrice)(market, oraclePriceData);
854
- const fallbackBid = (0, __1.calculateBidPrice)(market, oraclePriceData);
855
- const bestAsk = this.getBestAsk(marketIndex, fallbackAsk, slot, marketType, oraclePriceData);
856
- const bestBid = this.getBestBid(marketIndex, fallbackBid, slot, marketType, oraclePriceData);
916
+ const bestAsk = this.getBestAsk(marketIndex, slot, marketType, oraclePriceData);
917
+ const bestBid = this.getBestBid(marketIndex, slot, marketType, oraclePriceData);
857
918
  const mid = bestAsk.add(bestBid).div(new __1.BN(2));
858
919
  const bidSpread = ((0, __1.convertToNumber)(bestBid, __1.PRICE_PRECISION) /
859
920
  (0, __1.convertToNumber)(oraclePriceData.price, __1.PRICE_PRECISION) -
@@ -863,7 +924,8 @@ class DLOB {
863
924
  (0, __1.convertToNumber)(oraclePriceData.price, __1.PRICE_PRECISION) -
864
925
  1) *
865
926
  100.0;
866
- console.log(`Market ${sdkConfig.MARKETS[marketIndex].symbol} Orders`);
927
+ const name = (0, __1.decodeName)(driftClient.getPerpMarketAccount(marketIndex).name);
928
+ console.log(`Market ${name} Orders`);
867
929
  console.log(` Ask`, (0, __1.convertToNumber)(bestAsk, __1.PRICE_PRECISION).toFixed(3), `(${askSpread.toFixed(4)}%)`);
868
930
  console.log(` Mid`, (0, __1.convertToNumber)(mid, __1.PRICE_PRECISION).toFixed(3));
869
931
  console.log(` Bid`, (0, __1.convertToNumber)(bestBid, __1.PRICE_PRECISION).toFixed(3), `(${bidSpread.toFixed(4)}%)`);
@@ -871,8 +933,8 @@ class DLOB {
871
933
  else if ((0, __1.isVariant)(marketType, 'spot')) {
872
934
  const slot = slotSubscriber.getSlot();
873
935
  const oraclePriceData = driftClient.getOracleDataForPerpMarket(marketIndex);
874
- const bestAsk = this.getBestAsk(marketIndex, undefined, slot, marketType, oraclePriceData);
875
- const bestBid = this.getBestBid(marketIndex, undefined, slot, marketType, oraclePriceData);
936
+ const bestAsk = this.getBestAsk(marketIndex, slot, marketType, oraclePriceData);
937
+ const bestBid = this.getBestBid(marketIndex, slot, marketType, oraclePriceData);
876
938
  const mid = bestAsk.add(bestBid).div(new __1.BN(2));
877
939
  const bidSpread = ((0, __1.convertToNumber)(bestBid, __1.PRICE_PRECISION) /
878
940
  (0, __1.convertToNumber)(oraclePriceData.price, __1.PRICE_PRECISION) -
@@ -882,7 +944,8 @@ class DLOB {
882
944
  (0, __1.convertToNumber)(oraclePriceData.price, __1.PRICE_PRECISION) -
883
945
  1) *
884
946
  100.0;
885
- console.log(`Market ${sdkConfig.MARKETS[marketIndex].symbol} Orders`);
947
+ const name = (0, __1.decodeName)(driftClient.getSpotMarketAccount(marketIndex).name);
948
+ console.log(`Market ${name} Orders`);
886
949
  console.log(` Ask`, (0, __1.convertToNumber)(bestAsk, __1.PRICE_PRECISION).toFixed(3), `(${askSpread.toFixed(4)}%)`);
887
950
  console.log(` Mid`, (0, __1.convertToNumber)(mid, __1.PRICE_PRECISION).toFixed(3));
888
951
  console.log(` Bid`, (0, __1.convertToNumber)(bestBid, __1.PRICE_PRECISION).toFixed(3), `(${bidSpread.toFixed(4)}%)`);
@@ -4098,6 +4098,27 @@
4098
4098
  }
4099
4099
  ]
4100
4100
  },
4101
+ {
4102
+ "name": "updateLiquidationMarginBufferRatio",
4103
+ "accounts": [
4104
+ {
4105
+ "name": "admin",
4106
+ "isMut": false,
4107
+ "isSigner": true
4108
+ },
4109
+ {
4110
+ "name": "state",
4111
+ "isMut": true,
4112
+ "isSigner": false
4113
+ }
4114
+ ],
4115
+ "args": [
4116
+ {
4117
+ "name": "liquidationMarginBufferRatio",
4118
+ "type": "u32"
4119
+ }
4120
+ ]
4121
+ },
4101
4122
  {
4102
4123
  "name": "updateOracleGuardRails",
4103
4124
  "accounts": [
package/lib/math/amm.js CHANGED
@@ -410,7 +410,8 @@ function calculateSpreadReserves(amm, oraclePriceData, now) {
410
410
  quoteAssetReserve: amm.quoteAssetReserve,
411
411
  };
412
412
  }
413
- const quoteAssetReserveDelta = amm.quoteAssetReserve.div(numericConstants_1.BID_ASK_SPREAD_PRECISION.div(new anchor_1.BN(spread / 2)));
413
+ const spreadFraction = anchor_1.BN.max(new anchor_1.BN(spread / 2), numericConstants_1.ONE);
414
+ const quoteAssetReserveDelta = amm.quoteAssetReserve.div(numericConstants_1.BID_ASK_SPREAD_PRECISION.div(spreadFraction));
414
415
  let quoteAssetReserve;
415
416
  if ((0, types_1.isVariant)(direction, 'long')) {
416
417
  quoteAssetReserve = amm.quoteAssetReserve.add(quoteAssetReserveDelta);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.43.0-beta.16",
3
+ "version": "2.43.0-beta.18",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -787,6 +787,20 @@ export class AdminClient extends DriftClient {
787
787
  );
788
788
  }
789
789
 
790
+ public async updateLiquidationMarginBufferRatio(
791
+ updateLiquidationMarginBufferRatio: number
792
+ ): Promise<TransactionSignature> {
793
+ return await this.program.rpc.updateLiquidationMarginBufferRatio(
794
+ updateLiquidationMarginBufferRatio,
795
+ {
796
+ accounts: {
797
+ admin: this.wallet.publicKey,
798
+ state: await this.getStatePublicKey(),
799
+ },
800
+ }
801
+ );
802
+ }
803
+
790
804
  public async updateOracleGuardRails(
791
805
  oracleGuardRails: OracleGuardRails
792
806
  ): Promise<TransactionSignature> {
package/src/dlob/DLOB.ts CHANGED
@@ -2,9 +2,8 @@ import { getOrderSignature, getVammNodeGenerator, NodeList } from './NodeList';
2
2
  import {
3
3
  BASE_PRECISION,
4
4
  BN,
5
- calculateAskPrice,
6
- calculateBidPrice,
7
5
  convertToNumber,
6
+ decodeName,
8
7
  DLOBNode,
9
8
  DLOBNodeType,
10
9
  DriftClient,
@@ -1430,14 +1429,12 @@ export class DLOB {
1430
1429
 
1431
1430
  public getBestAsk(
1432
1431
  marketIndex: number,
1433
- fallbackAsk: BN | undefined,
1434
1432
  slot: number,
1435
1433
  marketType: MarketType,
1436
1434
  oraclePriceData: OraclePriceData
1437
1435
  ): BN {
1438
- return this.getAsks(
1436
+ return this.getRestingLimitAsks(
1439
1437
  marketIndex,
1440
- fallbackAsk,
1441
1438
  slot,
1442
1439
  marketType,
1443
1440
  oraclePriceData
@@ -1448,14 +1445,12 @@ export class DLOB {
1448
1445
 
1449
1446
  public getBestBid(
1450
1447
  marketIndex: number,
1451
- fallbackBid: BN | undefined,
1452
1448
  slot: number,
1453
1449
  marketType: MarketType,
1454
1450
  oraclePriceData: OraclePriceData
1455
1451
  ): BN {
1456
- return this.getBids(
1452
+ return this.getRestingLimitBids(
1457
1453
  marketIndex,
1458
- fallbackBid,
1459
1454
  slot,
1460
1455
  marketType,
1461
1456
  oraclePriceData
@@ -1464,6 +1459,108 @@ export class DLOB {
1464
1459
  .value.getPrice(oraclePriceData, slot);
1465
1460
  }
1466
1461
 
1462
+ public *getStopLosses(
1463
+ marketIndex: number,
1464
+ marketType: MarketType,
1465
+ direction: PositionDirection
1466
+ ): Generator<DLOBNode> {
1467
+ const marketTypeStr = getVariant(marketType) as MarketTypeStr;
1468
+ const marketNodeLists = this.orderLists.get(marketTypeStr).get(marketIndex);
1469
+
1470
+ if (isVariant(direction, 'long') && marketNodeLists.trigger.below) {
1471
+ for (const node of marketNodeLists.trigger.below.getGenerator()) {
1472
+ if (isVariant(node.order.direction, 'short')) {
1473
+ yield node;
1474
+ }
1475
+ }
1476
+ } else if (isVariant(direction, 'short') && marketNodeLists.trigger.above) {
1477
+ for (const node of marketNodeLists.trigger.above.getGenerator()) {
1478
+ if (isVariant(node.order.direction, 'long')) {
1479
+ yield node;
1480
+ }
1481
+ }
1482
+ }
1483
+ }
1484
+
1485
+ public *getStopLossMarkets(
1486
+ marketIndex: number,
1487
+ marketType: MarketType,
1488
+ direction: PositionDirection
1489
+ ): Generator<DLOBNode> {
1490
+ for (const node of this.getStopLosses(marketIndex, marketType, direction)) {
1491
+ if (isVariant(node.order.orderType, 'triggerMarket')) {
1492
+ yield node;
1493
+ }
1494
+ }
1495
+ }
1496
+
1497
+ public *getStopLossLimits(
1498
+ marketIndex: number,
1499
+ marketType: MarketType,
1500
+ direction: PositionDirection
1501
+ ): Generator<DLOBNode> {
1502
+ for (const node of this.getStopLosses(marketIndex, marketType, direction)) {
1503
+ if (isVariant(node.order.orderType, 'triggerLimit')) {
1504
+ yield node;
1505
+ }
1506
+ }
1507
+ }
1508
+
1509
+ public *getTakeProfits(
1510
+ marketIndex: number,
1511
+ marketType: MarketType,
1512
+ direction: PositionDirection
1513
+ ): Generator<DLOBNode> {
1514
+ const marketTypeStr = getVariant(marketType) as MarketTypeStr;
1515
+ const marketNodeLists = this.orderLists.get(marketTypeStr).get(marketIndex);
1516
+
1517
+ if (isVariant(direction, 'long') && marketNodeLists.trigger.above) {
1518
+ for (const node of marketNodeLists.trigger.above.getGenerator()) {
1519
+ if (isVariant(node.order.direction, 'short')) {
1520
+ yield node;
1521
+ }
1522
+ }
1523
+ } else if (isVariant(direction, 'short') && marketNodeLists.trigger.below) {
1524
+ for (const node of marketNodeLists.trigger.below.getGenerator()) {
1525
+ if (isVariant(node.order.direction, 'long')) {
1526
+ yield node;
1527
+ }
1528
+ }
1529
+ }
1530
+ }
1531
+
1532
+ public *getTakeProfitMarkets(
1533
+ marketIndex: number,
1534
+ marketType: MarketType,
1535
+ direction: PositionDirection
1536
+ ): Generator<DLOBNode> {
1537
+ for (const node of this.getTakeProfits(
1538
+ marketIndex,
1539
+ marketType,
1540
+ direction
1541
+ )) {
1542
+ if (isVariant(node.order.orderType, 'triggerMarket')) {
1543
+ yield node;
1544
+ }
1545
+ }
1546
+ }
1547
+
1548
+ public *getTakeProfitLimits(
1549
+ marketIndex: number,
1550
+ marketType: MarketType,
1551
+ direction: PositionDirection
1552
+ ): Generator<DLOBNode> {
1553
+ for (const node of this.getTakeProfits(
1554
+ marketIndex,
1555
+ marketType,
1556
+ direction
1557
+ )) {
1558
+ if (isVariant(node.order.orderType, 'triggerLimit')) {
1559
+ yield node;
1560
+ }
1561
+ }
1562
+ }
1563
+
1467
1564
  public findNodesToTrigger(
1468
1565
  marketIndex: number,
1469
1566
  slot: number,
@@ -1512,32 +1609,25 @@ export class DLOB {
1512
1609
  return nodesToTrigger;
1513
1610
  }
1514
1611
 
1515
- public printTopOfOrderLists(
1516
- sdkConfig: any,
1612
+ public printTop(
1517
1613
  driftClient: DriftClient,
1518
1614
  slotSubscriber: SlotSubscriber,
1519
1615
  marketIndex: number,
1520
1616
  marketType: MarketType
1521
1617
  ) {
1522
1618
  if (isVariant(marketType, 'perp')) {
1523
- const market = driftClient.getPerpMarketAccount(marketIndex);
1524
-
1525
1619
  const slot = slotSubscriber.getSlot();
1526
1620
  const oraclePriceData =
1527
1621
  driftClient.getOracleDataForPerpMarket(marketIndex);
1528
- const fallbackAsk = calculateAskPrice(market, oraclePriceData);
1529
- const fallbackBid = calculateBidPrice(market, oraclePriceData);
1530
1622
 
1531
1623
  const bestAsk = this.getBestAsk(
1532
1624
  marketIndex,
1533
- fallbackAsk,
1534
1625
  slot,
1535
1626
  marketType,
1536
1627
  oraclePriceData
1537
1628
  );
1538
1629
  const bestBid = this.getBestBid(
1539
1630
  marketIndex,
1540
- fallbackBid,
1541
1631
  slot,
1542
1632
  marketType,
1543
1633
  oraclePriceData
@@ -1555,7 +1645,10 @@ export class DLOB {
1555
1645
  1) *
1556
1646
  100.0;
1557
1647
 
1558
- console.log(`Market ${sdkConfig.MARKETS[marketIndex].symbol} Orders`);
1648
+ const name = decodeName(
1649
+ driftClient.getPerpMarketAccount(marketIndex).name
1650
+ );
1651
+ console.log(`Market ${name} Orders`);
1559
1652
  console.log(
1560
1653
  ` Ask`,
1561
1654
  convertToNumber(bestAsk, PRICE_PRECISION).toFixed(3),
@@ -1574,14 +1667,12 @@ export class DLOB {
1574
1667
 
1575
1668
  const bestAsk = this.getBestAsk(
1576
1669
  marketIndex,
1577
- undefined,
1578
1670
  slot,
1579
1671
  marketType,
1580
1672
  oraclePriceData
1581
1673
  );
1582
1674
  const bestBid = this.getBestBid(
1583
1675
  marketIndex,
1584
- undefined,
1585
1676
  slot,
1586
1677
  marketType,
1587
1678
  oraclePriceData
@@ -1599,7 +1690,10 @@ export class DLOB {
1599
1690
  1) *
1600
1691
  100.0;
1601
1692
 
1602
- console.log(`Market ${sdkConfig.MARKETS[marketIndex].symbol} Orders`);
1693
+ const name = decodeName(
1694
+ driftClient.getSpotMarketAccount(marketIndex).name
1695
+ );
1696
+ console.log(`Market ${name} Orders`);
1603
1697
  console.log(
1604
1698
  ` Ask`,
1605
1699
  convertToNumber(bestAsk, PRICE_PRECISION).toFixed(3),
@@ -4098,6 +4098,27 @@
4098
4098
  }
4099
4099
  ]
4100
4100
  },
4101
+ {
4102
+ "name": "updateLiquidationMarginBufferRatio",
4103
+ "accounts": [
4104
+ {
4105
+ "name": "admin",
4106
+ "isMut": false,
4107
+ "isSigner": true
4108
+ },
4109
+ {
4110
+ "name": "state",
4111
+ "isMut": true,
4112
+ "isSigner": false
4113
+ }
4114
+ ],
4115
+ "args": [
4116
+ {
4117
+ "name": "liquidationMarginBufferRatio",
4118
+ "type": "u32"
4119
+ }
4120
+ ]
4121
+ },
4101
4122
  {
4102
4123
  "name": "updateOracleGuardRails",
4103
4124
  "accounts": [
package/src/math/amm.ts CHANGED
@@ -760,9 +760,9 @@ export function calculateSpreadReserves(
760
760
  quoteAssetReserve: amm.quoteAssetReserve,
761
761
  };
762
762
  }
763
-
763
+ const spreadFraction = BN.max(new BN(spread / 2), ONE);
764
764
  const quoteAssetReserveDelta = amm.quoteAssetReserve.div(
765
- BID_ASK_SPREAD_PRECISION.div(new BN(spread / 2))
765
+ BID_ASK_SPREAD_PRECISION.div(spreadFraction)
766
766
  );
767
767
 
768
768
  let quoteAssetReserve;