Skip to content

Commit

Permalink
fix: traded interest rates (#768)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffywu authored Apr 19, 2024
1 parent 4984998 commit df7f9fc
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions packages/notionable/src/base-trade/trade-calculation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -459,24 +459,22 @@ function computeCollateralOptions(
return options.map((c) => {
const i = { ...inputs, collateral: c };
try {
const { collateralBalance, netRealizedCollateralBalance, collateralFee } =
calculationFn(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
i as any
) as {
collateralFee: TokenBalance;
collateralBalance: TokenBalance;
netRealizedCollateralBalance: TokenBalance;
};
const { collateralBalance, netRealizedCollateralBalance } = calculationFn(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
i as any
) as {
collateralFee: TokenBalance;
collateralBalance: TokenBalance;
netRealizedCollateralBalance: TokenBalance;
};

return {
token: c,
balance: collateralBalance,
..._getTradedInterestRate(
netRealizedCollateralBalance,
collateralBalance,
fCashMarket,
collateralFee
fCashMarket
),
};
} catch (e) {
Expand Down Expand Up @@ -510,7 +508,7 @@ function computeDebtOptions(
);
}

const { debtBalance, netRealizedDebtBalance, debtFee } = calculationFn(
const { debtBalance, netRealizedDebtBalance } = calculationFn(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
i as any
) as {
Expand All @@ -526,7 +524,6 @@ function computeDebtOptions(
netRealizedDebtBalance,
debtBalance.unwrapVaultToken(),
fCashMarket,
debtFee,
tradeType
),
};
Expand All @@ -545,18 +542,14 @@ function _getTradedInterestRate(
realized: TokenBalance,
amount: TokenBalance,
fCashMarket: fCashMarket,
fee?: TokenBalance,
tradeType?: TradeType | VaultTradeType
) {
let interestRate: number | undefined;
let utilization: number | undefined;
if (amount.tokenType === 'fCash') {
// We net off the fee for fcash so that we show it as an up-front
// trading fee rather than part of the implied yield
interestRate = fCashMarket.getImpliedInterestRate(
realized.sub(fee?.toUnderlying() || realized.copy(0)),
amount
);
interestRate = fCashMarket.getImpliedInterestRate(realized, amount);
} else if (amount.tokenType === 'PrimeCash') {
// Increases or decreases the prime supply accordingly
utilization = fCashMarket.getPrimeCashUtilization(amount, undefined);
Expand Down

0 comments on commit df7f9fc

Please sign in to comment.