From a46b09e6144450911cde84c4f4ab383cd36bf41f Mon Sep 17 00:00:00 2001 From: brucedonovan Date: Thu, 21 Apr 2022 11:58:04 +0100 Subject: [PATCH] repaybugfix: fix accruedDebt --- package.json | 2 +- src/contexts/UserContext.tsx | 12 +++++++++--- src/utils/yieldMath.ts | 3 +-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 45b0af4fd..aa6ca48a1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "app-v2", - "version": "2.2.8", + "version": "2.2.9", "private": true, "dependencies": { "@multiavatar/multiavatar": "^1.0.6", diff --git a/src/contexts/UserContext.tsx b/src/contexts/UserContext.tsx index 24474981c..a5727dfcb 100644 --- a/src/contexts/UserContext.tsx +++ b/src/contexts/UserContext.tsx @@ -392,10 +392,11 @@ const UserProvider = ({ children }: any) => { rate_ = cleanValue(ethers.utils.formatUnits(rate, 18), 2); // always 18 decimals when getting rate from rate oracle diagnostics && console.log('mature series : ', seriesId, rate, rateAtMaturity, art); - const [ _accruedArt ] = rateAtMaturity.gt(ZERO_BN) + + + [ accruedArt ] = rateAtMaturity.gt(ZERO_BN) ? calcAccruedDebt(rate, rateAtMaturity, art) - : calcAccruedDebt(rate, rate, art); - accruedArt = _accruedArt // .mul(10001).div(10000); // add 0.01% to account for slippage during tx time + : calcAccruedDebt(rate, rate, art); } else { rate = BigNumber.from('1'); @@ -404,6 +405,11 @@ const UserProvider = ({ children }: any) => { accruedArt = art; } + diagnostics && console.log( 'RATE', rate.toString() ) + diagnostics && console.log( 'RATEATMATURITY', rateAtMaturity.toString() ) + diagnostics && console.log( 'ART' , art.toString() ) + diagnostics && console.log( 'ACCRUED_ ART' , accruedArt.toString() ) + const baseRoot = assetRootMap.get(vault.baseId); const ilkRoot = assetRootMap.get(ilkId); diff --git a/src/utils/yieldMath.ts b/src/utils/yieldMath.ts index 7d240567d..c9ca7333a 100644 --- a/src/utils/yieldMath.ts +++ b/src/utils/yieldMath.ts @@ -1202,10 +1202,9 @@ export const calcAccruedDebt = (rate: BigNumber, rateAtMaturity: BigNumber, debt const debt_ = new Decimal(debt.toString()); const accRatio_ = rate_.div(rateAtMaturity_); - const invRatio_ = rateAtMaturity_.div(rate_); // to reverse calc the debt LESS the accrued value - const accruedDebt = !accRatio_.isNaN ? debt_.mul(accRatio_) : debt_; + const accruedDebt = !accRatio_.isNaN() ? debt_.mul(accRatio_) : debt_; const debtLessAccrued = debt_.mul(invRatio_); return [toBn(accruedDebt), toBn(debtLessAccrued)];