Skip to content

Commit

Permalink
repaybugfix: fix accruedDebt
Browse files Browse the repository at this point in the history
  • Loading branch information
brucedonovan committed Apr 21, 2022
1 parent 18d75bc commit a46b09e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "app-v2",
"version": "2.2.8",
"version": "2.2.9",
"private": true,
"dependencies": {
"@multiavatar/multiavatar": "^1.0.6",
Expand Down
12 changes: 9 additions & 3 deletions src/contexts/UserContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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);

Expand Down
3 changes: 1 addition & 2 deletions src/utils/yieldMath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)];
Expand Down

0 comments on commit a46b09e

Please sign in to comment.