Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix payback to account for negative interest #1447

Merged
merged 3 commits into from
Sep 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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