Skip to content

Commit

Permalink
Calculate floor price using the currently harvested LUSD amount to av…
Browse files Browse the repository at this point in the history
…oid price floor appearing to go down
  • Loading branch information
edmulraney committed Nov 9, 2022
1 parent 3536c37 commit efc0d1d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
8 changes: 6 additions & 2 deletions packages/dev-frontend/src/components/Bonds/context/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ import {
getBreakEvenDays,
getFutureBLusdAccrualFactor,
getFutureDateByDays,
getRebondDays
getRebondDays,
getFloorPrice
} from "../utils";
import { UNKNOWN_DATE } from "../../HorizontalTimeline";
import { BLusdAmmTokenIndex } from "./transitions";
Expand Down Expand Up @@ -500,7 +501,10 @@ const getProtocolInfo = async (
.div(bLusdSupply);
}

const floorPrice = bLusdSupply.isZero ? Decimal.ONE : treasury.reserve.div(bLusdSupply);
const floorPrice = bLusdSupply.isZero
? Decimal.ONE
: await getFloorPrice(chickenBondManager, bLusdSupply);

const claimBondFee = decimalify(await chickenBondManager.CHICKEN_IN_AMM_FEE());
const alphaAccrualFactor = decimalify(await chickenBondManager.calcUpdatedAccrualParameter()).div(
24 * 60 * 60
Expand Down
16 changes: 15 additions & 1 deletion packages/dev-frontend/src/components/Bonds/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ChickenBondManager } from "@liquity/chicken-bonds/lusd/types";
import { Decimal } from "@liquity/lib-base";
import { BigNumber } from "ethers";

Expand Down Expand Up @@ -79,6 +80,18 @@ const getFutureDateByDays = (days: number): Date => {
return new Date(Math.round(Date.now() + daysToMilliseconds(days)));
};

const getFloorPrice = async (
chickenBondManager: ChickenBondManager,
bLusdSupply: Decimal
): Promise<Decimal> => {
return decimalify(
(await chickenBondManager.getBAMMLUSDDebt())
.add(await chickenBondManager.getTotalLUSDInCurve())
.sub(await chickenBondManager.getPendingLUSD())
.sub(await chickenBondManager.getPermanentLUSD())
).div(bLusdSupply);
};

export {
milliseconds,
toFloat,
Expand All @@ -93,5 +106,6 @@ export {
getFutureBLusdAccrualFactor,
getBreakEvenDays,
getRebondDays,
getFutureDateByDays
getFutureDateByDays,
getFloorPrice
};

0 comments on commit efc0d1d

Please sign in to comment.