vault: disallow designating of flowing tokens

This commit is contained in:
Mark Spanbroek 2025-01-30 13:36:46 +01:00
parent b988db9bd3
commit 28ad5ced18
2 changed files with 17 additions and 1 deletions

View File

@ -150,10 +150,17 @@ abstract contract VaultBase {
Recipient recipient,
uint128 amount
) internal {
Balance storage balance = _balances[controller][context][recipient];
Balance memory balance = _balances[controller][context][recipient];
require(amount <= balance.available, InsufficientBalance());
balance.available -= amount;
balance.designated += amount;
Flow memory flow = _flows[controller][context][recipient];
Lock memory lock = _locks[controller][context];
_checkFlowInvariant(balance, lock, flow);
_balances[controller][context][recipient] = balance;
}
function _lockup(

View File

@ -600,6 +600,15 @@ describe("Vault", function () {
).to.be.revertedWith("InsufficientBalance")
})
it("cannot designate tokens that are flowing", async function () {
await vault.flow(context, sender, receiver, 5)
setAutomine(true)
await vault.designate(context, sender, 500)
await expect(vault.designate(context, sender, 1)).to.be.revertedWith(
"InsufficientBalance"
)
})
it("cannot burn tokens that are flowing", async function () {
await vault.flow(context, sender, receiver, 5)
setAutomine(true)