Enforce no negative balance at the end of transaction

This commit is contained in:
Bronek Kozicki
2025-03-21 16:45:52 +00:00
parent 58f15307ba
commit 0959bf82b7
3 changed files with 30 additions and 0 deletions

View File

@@ -176,6 +176,16 @@ VaultClawback::doApply()
if (auto ter = accountSend(view(), vaultAccount, account_, assets, j_))
return ter;
// Sanity check
if (accountHolds(
view(),
vaultAccount,
assets.asset(),
FreezeHandling::fhIGNORE_FREEZE,
AuthHandling::ahIGNORE_AUTH,
j_) < beast::zero)
return tefINTERNAL;
return tesSUCCESS;
}

View File

@@ -177,6 +177,16 @@ VaultDeposit::doApply()
view(), account_, vaultAccount, assets, j_, WaiveTransferFee::Yes))
return ter;
// Sanity check
if (accountHolds(
view(),
account_,
assets.asset(),
FreezeHandling::fhIGNORE_FREEZE,
AuthHandling::ahIGNORE_AUTH,
j_) < beast::zero)
return tefINTERNAL;
// Transfer shares from vault to depositor.
if (auto ter = accountSend(
view(), vaultAccount, account_, shares, j_, WaiveTransferFee::Yes))

View File

@@ -181,6 +181,16 @@ VaultWithdraw::doApply()
view(), vaultAccount, dstAcct, assets, j_, WaiveTransferFee::Yes))
return ter;
// Sanity check
if (accountHolds(
view(),
vaultAccount,
assets.asset(),
FreezeHandling::fhIGNORE_FREEZE,
AuthHandling::ahIGNORE_AUTH,
j_) < beast::zero)
return tefINTERNAL;
return tesSUCCESS;
}