-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Adds functionality to block vault deposits #6361
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: tapanito/lending-fix-amendment
Are you sure you want to change the base?
Changes from all commits
c808c46
a219814
1010866
087a9c1
82b0d57
f57b715
71b9f98
3cfb5fe
cd1e8eb
d972071
884530e
8732e84
81e69b9
b08451c
8723472
2b716eb
f034ca0
3deb0de
ebfa659
cc9dbe2
68d7555
7e5a4c9
b970c66
5fe99dc
8899d34
f2495dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| #pragma once | ||
|
|
||
| #include <xrpl/ledger/helpers/VaultHelpers.h> | ||
| #include <xrpl/tx/Transactor.h> | ||
|
|
||
| namespace xrpl { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| #pragma once | ||
|
|
||
| #include <xrpl/ledger/helpers/VaultHelpers.h> | ||
| #include <xrpl/tx/Transactor.h> | ||
|
|
||
| namespace xrpl { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| #pragma once | ||
|
|
||
| #include <xrpl/ledger/helpers/VaultHelpers.h> | ||
| #include <xrpl/tx/Transactor.h> | ||
|
|
||
| namespace xrpl { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,29 @@ VaultSet::checkExtraFeatures(PreflightContext const& ctx) | |
| return !ctx.tx.isFieldPresent(sfDomainID) || ctx.rules.enabled(featurePermissionedDomains); | ||
| } | ||
|
|
||
| std::uint32_t | ||
| VaultSet::getFlagsMask(PreflightContext const& ctx) | ||
| { | ||
| if (ctx.rules.enabled(featureLendingProtocolV1_1)) | ||
| return tfVaultSetMask; | ||
|
|
||
| // Add tfVaultDepositBlock and tfVaultDepositUnblock flags to indicate they are disabled | ||
| return tfVaultSetMask | tfVaultDepositBlock | tfVaultDepositUnblock; | ||
| } | ||
|
|
||
| static bool | ||
| isValidVaultUpdate(PreflightContext const& ctx) | ||
| { | ||
| auto const atLeastOneFieldPresent = ctx.tx.isFieldPresent(sfDomainID) || | ||
| ctx.tx.isFieldPresent(sfAssetsMaximum) || ctx.tx.isFieldPresent(sfData); | ||
|
|
||
| // Mask of valid, non-universal flags: any bit set here means the | ||
| // transaction is requesting a meaningful flag change. | ||
| auto const expectedFlags = ~(VaultSet::getFlagsMask(ctx) | tfUniversal); | ||
|
Tapanito marked this conversation as resolved.
|
||
|
|
||
| return atLeastOneFieldPresent || (ctx.tx.getFlags() & expectedFlags); | ||
| } | ||
|
|
||
| NotTEC | ||
| VaultSet::preflight(PreflightContext const& ctx) | ||
| { | ||
|
|
@@ -44,13 +67,19 @@ VaultSet::preflight(PreflightContext const& ctx) | |
| } | ||
| } | ||
|
|
||
| if (!ctx.tx.isFieldPresent(sfDomainID) && !ctx.tx.isFieldPresent(sfAssetsMaximum) && | ||
| !ctx.tx.isFieldPresent(sfData)) | ||
| if (!isValidVaultUpdate(ctx)) | ||
| { | ||
| JLOG(ctx.j.debug()) << "VaultSet: nothing is being updated."; | ||
| return temMALFORMED; | ||
| } | ||
|
|
||
| if (ctx.tx.isFlag(tfVaultDepositBlock) && ctx.tx.isFlag(tfVaultDepositUnblock)) | ||
| { | ||
| JLOG(ctx.j.debug()) | ||
| << "VaultSet: cannot set tfVaultDepositBlock and tfVaultDepositUnblock simultaneously."; | ||
| return temINVALID_FLAG; | ||
| } | ||
|
|
||
| return tesSUCCESS; | ||
| } | ||
|
|
||
|
|
@@ -104,6 +133,29 @@ VaultSet::preclaim(PreclaimContext const& ctx) | |
| } | ||
| } | ||
|
|
||
| if (ctx.view.rules().enabled(featureLendingProtocolV1_1)) | ||
| { | ||
| // The Vault is not configured to support deposit blocking | ||
| if (!vault->isFlag(lsfVaultOwnerCanBlockDeposit) && | ||
| (ctx.tx.isFlag(tfVaultDepositBlock) || ctx.tx.isFlag(tfVaultDepositUnblock))) | ||
| { | ||
| JLOG(ctx.j.debug()) << "VaultSet: vault does not support blocking deposits"; | ||
| return tecNO_PERMISSION; | ||
| } | ||
|
|
||
| if (vault->isFlag(lsfVaultDepositBlocked) && ctx.tx.isFlag(tfVaultDepositBlock)) | ||
| { | ||
| JLOG(ctx.j.debug()) << "VaultSet: vault deposit is already blocked"; | ||
| return tecNO_PERMISSION; | ||
| } | ||
|
|
||
| if (!vault->isFlag(lsfVaultDepositBlocked) && ctx.tx.isFlag(tfVaultDepositUnblock)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it may make sense to allow cases where the flag we want to add already exists or the flag we want to remove doesn't exist. We don't return an error when a transaction is updating another field and the value is the same as the current value, but we do return an error when the flag is already added, which feels inconsistent. |
||
| { | ||
| JLOG(ctx.j.debug()) << "VaultSet: vault deposit is already unblocked"; | ||
| return tecNO_PERMISSION; | ||
| } | ||
|
Tapanito marked this conversation as resolved.
|
||
| } | ||
|
|
||
| return tesSUCCESS; | ||
| } | ||
|
|
||
|
|
@@ -161,6 +213,15 @@ VaultSet::doApply() | |
| view().update(sleIssuance); | ||
| } | ||
|
|
||
| if (view().rules().enabled(featureLendingProtocolV1_1)) | ||
| { | ||
| if (tx.isFlag(tfVaultDepositBlock)) | ||
| vault->setFlag(lsfVaultDepositBlocked); | ||
|
|
||
| if (tx.isFlag(tfVaultDepositUnblock)) | ||
| vault->clearFlag(lsfVaultDepositBlocked); | ||
| } | ||
|
|
||
| // Note, we must update Vault object even if only DomainID is being updated | ||
| // in Issuance object. Otherwise it's really difficult for Vault invariants | ||
| // to verify the operation. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.