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 loan payback amounts #1171

Merged
merged 1 commit into from
Mar 30, 2022
Merged
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
16 changes: 8 additions & 8 deletions src/masternodes/mn_checks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2979,10 +2979,6 @@ class CCustomTxApplyVisitor : public CCustomTxVisitor
if (!mnview.GetVaultCollaterals(obj.vaultId))
return Res::Err("Vault with id %s has no collaterals", obj.vaultId.GetHex());

auto loanAmounts = mnview.GetLoanTokens(obj.vaultId);
if (!loanAmounts)
return Res::Err("There are no loans on this vault (%s)!", obj.vaultId.GetHex());

if (!HasAuth(obj.from))
return Res::Err("tx must have at least one input from token owner");

Expand All @@ -2999,10 +2995,6 @@ class CCustomTxApplyVisitor : public CCustomTxVisitor
if (!loanToken)
return Res::Err("Loan token with id (%s) does not exist!", loanTokenId.ToString());

auto it = loanAmounts->balances.find(loanTokenId);
if (it == loanAmounts->balances.end())
return Res::Err("There is no loan on token (%s) in this vault!", loanToken->symbol);

for (const auto& kv : idx.second.balances)
{
DCT_ID paybackTokenId = kv.first;
Expand Down Expand Up @@ -3075,6 +3067,14 @@ class CCustomTxApplyVisitor : public CCustomTxVisitor
}
}

auto loanAmounts = mnview.GetLoanTokens(obj.vaultId);
if (!loanAmounts)
return Res::Err("There are no loans on this vault (%s)!", obj.vaultId.GetHex());

auto it = loanAmounts->balances.find(loanTokenId);
if (it == loanAmounts->balances.end())
return Res::Err("There is no loan on token (%s) in this vault!", loanToken->symbol);

auto rate = mnview.GetInterestRate(obj.vaultId, loanTokenId, height);
if (!rate)
return Res::Err("Cannot get interest rate for this token (%s)!", loanToken->symbol);
Expand Down