Skip to content

Commit

Permalink
Update logs and error message in mn_checks.cpp (#1066)
Browse files Browse the repository at this point in the history
* Log with class name for consistency

* Better error message on 50% DFI ratio

* Use correct class name

* Update test

Co-authored-by: Prasanna Loganathar <pvl@prasannavl.com>
  • Loading branch information
Jouzo and prasannavl authored Jan 26, 2022
1 parent 4c2044a commit 28c8cbc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
22 changes: 11 additions & 11 deletions src/masternodes/mn_checks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1349,7 +1349,7 @@ class CCustomTxApplyVisitor : public CCustomTxVisitor
return Res::Err("Attributes unavailable");

CDataStructureV0 activeKey{AttributeTypes::Param, ParamIDs::DFIP2201, DFIP2201Keys::Active};

if (!attributes->GetValue(activeKey, false))
return Res::Err("DFIP2201 smart contract is not enabled");

Expand Down Expand Up @@ -2653,7 +2653,7 @@ class CCustomTxApplyVisitor : public CCustomTxVisitor
return Res::Err("At least 50%% of the collateral must be in DFI");
} else {
if (arith_uint256(totalDFI) * 100 < arith_uint256(collateralsLoans.val->totalLoans) * scheme->ratio / 2)
return Res::Err("At least 50%% of the collateral must be in DFI");
return Res::Err("At least 50%% of the minimum required collateral must be in DFI");
}

if (collateralsLoans.val->ratio() < scheme->ratio)
Expand Down Expand Up @@ -2764,7 +2764,7 @@ class CCustomTxApplyVisitor : public CCustomTxVisitor
return Res::Err("At least 50%% of the collateral must be in DFI when taking a loan.");
} else {
if (arith_uint256(totalDFI) * 100 < arith_uint256(collateralsLoans.val->totalLoans) * scheme->ratio / 2)
return Res::Err("At least 50%% of the collateral must be in DFI when taking a loan.");
return Res::Err("At least 50%% of the minimum required collateral must be in DFI when taking a loan.");
}

if (collateralsLoans.val->ratio() < scheme->ratio)
Expand Down Expand Up @@ -2855,7 +2855,7 @@ class CCustomTxApplyVisitor : public CCustomTxVisitor
if (!rate)
return Res::Err("Cannot get interest rate for this token (%s)!", loanToken->symbol);

LogPrint(BCLog::LOAN,"CLoanPaybackMessage()->%s->", loanToken->symbol); /* Continued */
LogPrint(BCLog::LOAN,"CLoanPaybackLoanMessage()->%s->", loanToken->symbol); /* Continued */
auto subInterest = TotalInterest(*rate, height);
auto subLoan = paybackAmount - subInterest;

Expand All @@ -2873,7 +2873,7 @@ class CCustomTxApplyVisitor : public CCustomTxVisitor
if (!res)
return res;

LogPrint(BCLog::LOAN,"CLoanPaybackMessage()->%s->", loanToken->symbol); /* Continued */
LogPrint(BCLog::LOAN,"CLoanPaybackLoanMessage()->%s->", loanToken->symbol); /* Continued */
res = mnview.EraseInterest(height, obj.vaultId, vault->schemeId, tokenId, subLoan, subInterest);
if (!res)
return res;
Expand All @@ -2897,15 +2897,15 @@ class CCustomTxApplyVisitor : public CCustomTxVisitor
return res;

// subtract loan amount first, interest is burning below
LogPrint(BCLog::LOAN, "CLoanTakeLoanMessage(): Sub loan from balance - %lld, height - %d\n", subLoan, height);
LogPrint(BCLog::LOAN, "CLoanPaybackLoanMessage(): Sub loan from balance - %lld, height - %d\n", subLoan, height);
res = mnview.SubBalance(obj.from, CTokenAmount{tokenId, subLoan});
if (!res)
return res;

// burn interest Token->USD->DFI->burnAddress
if (subInterest)
{
LogPrint(BCLog::LOAN, "CLoanTakeLoanMessage(): Swapping %s interest to DFI - %lld, height - %d\n", loanToken->symbol, subInterest, height);
LogPrint(BCLog::LOAN, "CLoanPaybackLoanMessage(): Swapping %s interest to DFI - %lld, height - %d\n", loanToken->symbol, subInterest, height);
res = SwapToDFIOverUSD(mnview, tokenId, subInterest, obj.from, consensus.burnAddress, height);
}
}
Expand Down Expand Up @@ -2935,7 +2935,7 @@ class CCustomTxApplyVisitor : public CCustomTxVisitor

shouldSetVariable = true;

LogPrint(BCLog::LOAN, "CLoanTakeLoanMessage(): Burning interest and loan in DFI directly - %lld (%lld DFI), height - %d\n", subLoan + subInterest, subInDFI, height);
LogPrint(BCLog::LOAN, "CLoanPaybackLoanMessage(): Burning interest and loan in DFI directly - %lld (%lld DFI), height - %d\n", subLoan + subInterest, subInDFI, height);
res = TransferTokenBalance(DCT_ID{0}, subInDFI, obj.from, consensus.burnAddress);
}

Expand Down Expand Up @@ -3273,10 +3273,10 @@ Res CustomTxVisit(CCustomCSView& mnview, const CCoinsViewCache& coins, const CTr
TBytes dummy;
switch(GuessCustomTxType(tx, dummy))
{
case CustomTxType::TakeLoan:
case CustomTxType::PaybackLoan:
case CustomTxType::TakeLoan:
case CustomTxType::PaybackLoan:
case CustomTxType::DepositToVault:
case CustomTxType::WithdrawFromVault:
case CustomTxType::WithdrawFromVault:
case CustomTxType::UpdateVault:
return Res::Err("This type of transaction is not possible around hard fork height");
break;
Expand Down
2 changes: 1 addition & 1 deletion test/functional/feature_loan_vault.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ def run_test(self):
self.nodes[0].withdrawfromvault(vaultId4, accountDFI, "0.26@DFI")
except JSONRPCException as e:
errorString = e.error['message']
assert("At least 50% of the collateral must be in DFI" in errorString)
assert("At least 50% of the minimum required collateral must be in DFI" in errorString)

# Should be able to take 0.33@TSLA and respect 50% DFI ratio
self.nodes[0].takeloan({
Expand Down

0 comments on commit 28c8cbc

Please sign in to comment.