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

Payback of DUSD loan with DFI #1024

Merged
merged 17 commits into from
Jan 24, 2022
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Get DFI payback penalty from Gov var
Bushstar committed Jan 19, 2022
commit 7a7f9f31269dd8e547f2317891a8224d9f23e22d
12 changes: 11 additions & 1 deletion src/masternodes/mn_checks.cpp
Original file line number Diff line number Diff line change
@@ -2716,8 +2716,18 @@ class CCustomTxApplyVisitor : public CCustomTxVisitor
return std::move(resVal);
}

// Apply 1% penalty
// Apply penalty
CAmount penalty{99000000}; // Update from Gov var
CDataStructureV0 penaltyKey{AttributeTypes::Token, tokenDUSD->first.v, TokenKeys::PaybackDFIFeePCT};
try {
const auto& value = attrs.at(penaltyKey);
auto valueV0 = boost::get<const CValueV0>(&value);
if (valueV0) {
if (auto storedPenalty = boost::get<const CAmount>(valueV0)) {
penalty = COIN - *storedPenalty;
}
}
} catch (const std::out_of_range&) {}
dfiUSDPrice = MultiplyAmounts(*resVal.val, penalty);

// Set tokenId to DUSD
22 changes: 21 additions & 1 deletion test/functional/feature_loan_payback_dfi.py
Original file line number Diff line number Diff line change
@@ -160,12 +160,32 @@ def run_test(self):
self.nodes[0].generate(1)

vaultAfter = self.nodes[0].getvault(vaultId)
print(vaultAfter)
[amountAfter, _] = vaultAfter['loanAmounts'][0].split('@')
[interestAfter, _] = vaultAfter['interestAmounts'][0].split('@')

assert_equal(Decimal(amountAfter) - Decimal(interestAfter), (Decimal(amountBefore) - (10 * Decimal('0.99'))))

# Test 5% penalty
self.nodes[0].setgov({"ATTRIBUTES":{'v0/token/' + iddUSD + '/payback_dfi_fee_pct':'0.05'}})
self.nodes[0].generate(1)

vaultBefore = self.nodes[0].getvault(vaultId)
[amountBefore, _] = vaultBefore['loanAmounts'][0].split('@')

# Partial loan payback in DFI
self.nodes[0].paybackloan({
'vaultId': vaultId,
'from': account0,
'amounts': "1@DFI"
})
self.nodes[0].generate(1)

vaultAfter = self.nodes[0].getvault(vaultId)
[amountAfter, _] = vaultAfter['loanAmounts'][0].split('@')
[interestAfter, _] = vaultAfter['interestAmounts'][0].split('@')

assert_equal(Decimal(amountAfter) - Decimal(interestAfter), (Decimal(amountBefore) - (10 * Decimal('0.95'))))

# Payback of loan token other than DUSD
vaultId2 = self.nodes[0].createvault(account0, 'LOAN150')
self.nodes[0].generate(1)