diff --git a/contracts/vault/VaultBase.sol b/contracts/vault/VaultBase.sol index c7baccb..c79dd7c 100644 --- a/contracts/vault/VaultBase.sol +++ b/contracts/vault/VaultBase.sol @@ -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( diff --git a/test/Vault.tests.js b/test/Vault.tests.js index 3f6a4cd..5866cef 100644 --- a/test/Vault.tests.js +++ b/test/Vault.tests.js @@ -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)