Skip to content

Commit

Permalink
Fix payback to account for negative interest (#1447)
Browse files Browse the repository at this point in the history
* Add FortCanningEpilogue fork

* Fix payback not to reduce negative interest from wallet. Imrpove tests.

Co-authored-by: Peter Bushnell <[email protected]>
  • Loading branch information
Mixa84 and Bushstar authored Sep 9, 2022
1 parent 3e3d1d8 commit 76987d1
Show file tree
Hide file tree
Showing 3 changed files with 232 additions and 73 deletions.
15 changes: 9 additions & 6 deletions src/masternodes/mn_checks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3133,14 +3133,14 @@ class CCustomTxApplyVisitor : public CCustomTxVisitor
const auto totalInterest = TotalInterest(*rate, height);

if (totalInterest < 0) {
loanAmountChange = currentLoanAmount > std::abs(totalInterest) ?
loanAmountChange = currentLoanAmount > std::abs(totalInterest) ?
// Interest to decrease smaller than overall existing loan amount.
// So reduce interest from the borrowing principal. If this is negative,
// we'll reduce from principal.
tokenAmount + totalInterest :
// we'll reduce from principal.
tokenAmount + totalInterest :
// Interest to decrease is larger than old loan amount.
// We reduce from the borrowing principal. If this is negative,
// we'll reduce from principal.
// We reduce from the borrowing principal. If this is negative,
// we'll reduce from principal.
tokenAmount - currentLoanAmount;
resetInterestToHeight = true;
}
Expand Down Expand Up @@ -3427,7 +3427,10 @@ class CCustomTxApplyVisitor : public CCustomTxVisitor
if (paybackTokenId == loanTokenId)
{
// If interest was negative remove it from sub amount
res = mnview.SubMintedTokens(loanTokenId, subInterest > 0 ? subLoan : subLoan + subInterest);
if (height >= static_cast<uint32_t>(consensus.FortCanningEpilogueHeight) && subInterest < 0)
subLoan += subInterest;

res = mnview.SubMintedTokens(loanTokenId, subLoan);
if (!res)
return res;

Expand Down
Loading

0 comments on commit 76987d1

Please sign in to comment.