From 2ba3ff898228102049f2b7921665ce87416b21c0 Mon Sep 17 00:00:00 2001 From: James Grugett Date: Fri, 19 Aug 2022 16:40:36 -0500 Subject: [PATCH] Pay back fraction of loan on redeem --- common/redeem.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/common/redeem.ts b/common/redeem.ts index 4a4080f6..e0839ff8 100644 --- a/common/redeem.ts +++ b/common/redeem.ts @@ -13,8 +13,9 @@ export const getRedeemableAmount = (bets: RedeemableBet[]) => { const yesShares = sumBy(yesBets, (b) => b.shares) const noShares = sumBy(noBets, (b) => b.shares) const shares = Math.max(Math.min(yesShares, noShares), 0) + const soldFrac = shares > 0 ? Math.min(yesShares, noShares) / shares : 0 const loanAmount = sumBy(bets, (bet) => bet.loanAmount ?? 0) - const loanPayment = Math.min(loanAmount, shares) + const loanPayment = loanAmount * soldFrac const netAmount = shares - loanPayment return { shares, loanPayment, netAmount } }