-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Lending Protocol implementation XLS-66 #5270
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
base: ximinez/lending-refactoring-4
Are you sure you want to change the base?
Conversation
1240135
to
6f5d1ad
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## ximinez/lending-refactoring-4 #5270 +/- ##
===============================================================
+ Coverage 78.8% 79.1% +0.3%
===============================================================
Files 814 837 +23
Lines 71102 72716 +1614
Branches 8359 8411 +52
===============================================================
+ Hits 56007 57493 +1486
- Misses 15095 15223 +128
🚀 New features to boost your workflow:
|
27e4c4f
to
2d209c4
Compare
e8fbd22
to
a697138
Compare
72d979e
to
441d5b5
Compare
b1e091c
to
2a8861d
Compare
5223459
to
c7b296c
Compare
- Clean up some of the payment parameters - Also factor out Payment::makeMPTDirectPayment for future use
- Not all tests are passing yet
- Low hanging fruit
* Unit tests for self lending
038b776
to
1e74626
Compare
…to ximinez/lending-XLS-66 * XRPLF/ximinez/lending-refactoring-4: fixup! Rename Transactor preflight functions Rename Transactor preflight functions fixup! Make preflight1 and preflight2 private static Transactor functions Make preflight1 and preflight2 private static Transactor functions Fix formatting
There are build errors in the latest commit: /User/rippled/src/test/app/Loan_test.cpp:1816:25: error: use of undeclared identifier 'json' |
Unity build strikes again. I'll have it fixed ASAP. |
91e0286
to
57c78c5
Compare
loan(uint256 const& loanBrokerID, std::uint32_t loanSeq) noexcept; | ||
|
||
inline Keylet | ||
loan(uint256 const& vaultKey) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't look right
loanbroker(AccountID const& owner, std::uint32_t seq) noexcept; | ||
|
||
inline Keylet | ||
loanbroker(uint256 const& vaultKey) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't look right
} | ||
else | ||
{ | ||
auto const vaultID = tx[sfVaultID]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sfVaultID
is also used on line 98. It makes sense to define vaultID
at the start of the function and use it in both cases.
adjustOwnerCount(view(), owner, -2, j_); | ||
} | ||
|
||
return tesSUCCESS; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specifications has State Changes
section describing the balances update by CoverAvailable
. Why is this state change requirements not implemented?
auto const pseudoAccountID = sleBroker->at(sfAccount); | ||
|
||
// Cannot send a frozen Asset | ||
if (auto const ret = checkFrozen(ctx.view, pseudoAccountID, vaultAsset)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This returns tecFROZEN
if lsfGlobalFreeze
is set on the issuer's account for IOU. It returns tecLOCKED
if MPTokenIssuance
has lsfMPTLocked
set. Therefore, the tx fails. But if destination account is the issuer account then withdraw should succeed. This is fail condition according to the specs:
The AccountRoot object of the Issuer has the lsfGlobalFreeze flag set and Destination is not the Issuer of the asset.
The MPTokenIssuance object of the Vault(LoanBroker(LoanBrokerID).VaultID).Asset has the lsfMPTLocked flag set and Destination is not the Issuer of the asset.
} | ||
|
||
// Transfer assets from pseudo-account to depositor. | ||
return accountSend( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You've already made a payment of amount
above from brokerPseudoID
to dstAcct
. What is this for?
TRANSACTION(ttLOAN_BROKER_COVER_CLAWBACK, 78, LoanBrokerCoverClawback, | ||
Delegation::delegatable, | ||
noPriv, ({ | ||
{sfLoanBrokerID, soeOPTIONAL}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are these two fields optional? They are required according to the specs.
*/ | ||
//============================================================================== | ||
|
||
#include <xrpld/app/tx/detail/LoanBrokerSet.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are quite a few unnecessary include files in every loan related transactor. I only mention it here as an example. The unnecessary includes are commented out:
#include <xrpld/app/tx/detail/LoanBrokerSet.h>
//
#include <xrpld/app/misc/LendingHelpers.h>
//#include <xrpld/app/tx/detail/SignerEntries.h>
//#include <xrpld/app/tx/detail/VaultCreate.h>
#include <xrpld/ledger/ApplyView.h>
#include <xrpld/ledger/View.h>
#include <xrpl/basics/Log.h>
#include <xrpl/basics/Number.h>
//#include <xrpl/basics/chrono.h>
//#include <xrpl/beast/utility/Journal.h>
//#include <xrpl/beast/utility/instrumentation.h>
//#include <xrpl/protocol/AccountID.h>
//#include <xrpl/protocol/Feature.h>
#include <xrpl/protocol/Indexes.h>
//#include <xrpl/protocol/PublicKey.h>
#include <xrpl/protocol/SField.h>
//#include <xrpl/protocol/STAmount.h>
//#include <xrpl/protocol/STNumber.h>
//#include <xrpl/protocol/STObject.h>
//#include <xrpl/protocol/STXChainBridge.h>
#include <xrpl/protocol/TER.h>
//#include <xrpl/protocol/TxFlags.h>
//#include <xrpl/protocol/XRPAmount.h>
{ | ||
// Create the holding if it doesn't already exist (necessary for MPTs). | ||
// The owner may have deleted their MPT / line at some point. | ||
if (auto const ter = addEmptyHolding( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this applicable only when originationFee
is set?
return temINVALID; | ||
|
||
// Flags are mutually exclusive | ||
int numFlags = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can simplify:
auto const flags = ctx.tx[sfFlags];
if (flags & (flags - 1)) != 0)
{
JLOG(ctx.j.warn())
<< "LoanManage: Only one of tfLoanDefault, tfLoanImpair, or "
"tfLoanUnimpair can be set.";
return temINVALID_FLAG;
}
j_)) | ||
return ter; | ||
} | ||
if (tx.isFlag(tfLoanImpair)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The flags are mutually exclusive so should be else if
here and below.
(365 * 24 * 60 * 60); | ||
} | ||
|
||
Number |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there corresponding sections or formulas in the specifications for all of the functions here and in *cpp? It's not easy to verify without a reference. Comments pointing to a location in the specifications would be very helpful.
High Level Overview of Change
Implement the Lending Protocol as described in XLS-66
Context of Change
Type of Change
API Impact
libxrpl
change (any change that may affectlibxrpl
or dependents oflibxrpl
)