From ef5183474074d3bb684d075ebaaa65f1d64a0965 Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Tue, 28 Jan 2025 16:08:11 +0100 Subject: [PATCH] vault: cannot burn flowing tokens --- contracts/vault/VaultBase.sol | 6 ++++++ test/Vault.tests.js | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/contracts/vault/VaultBase.sol b/contracts/vault/VaultBase.sol index 48553ac..600b284 100644 --- a/contracts/vault/VaultBase.sol +++ b/contracts/vault/VaultBase.sol @@ -110,9 +110,14 @@ abstract contract VaultBase { Context context, Recipient recipient ) internal { + Flow memory flow = _flows[controller][context][recipient]; + require(flow.rate == TokensPerSecond.wrap(0), CannotBurnFlowingTokens()); + Balance memory balance = _getBalance(controller, context, recipient); uint128 amount = balance.available + balance.designated; + _delete(controller, context, recipient); + _token.safeTransfer(address(0xdead), amount); } @@ -230,4 +235,5 @@ abstract contract VaultBase { error InvalidExpiry(); error LockRequired(); error NegativeFlow(); + error CannotBurnFlowingTokens(); } diff --git a/test/Vault.tests.js b/test/Vault.tests.js index 5de8280..1501408 100644 --- a/test/Vault.tests.js +++ b/test/Vault.tests.js @@ -598,6 +598,22 @@ describe("Vault", function () { vault.transfer(context, sender, receiver, 1) ).to.be.revertedWith("InsufficientBalance") }) + + it("cannot burn tokens that are flowing", async function () { + await vault.flow(context, sender, receiver, 5) + await expect( + vault.burn(context, sender) + ).to.be.revertedWith("CannotBurnFlowingTokens") + await expect( + vault.burn(context, receiver) + ).to.be.revertedWith("CannotBurnFlowingTokens") + }) + + it("can burn tokens that are no longer flowing", async function () { + await vault.flow(context, sender, receiver, 5) + await vault.flow(context, receiver, sender, 5) + await expect(vault.burn(context, sender)).not.to.be.reverted + }) }) }) })