vault: cannot burn flowing tokens

This commit is contained in:
Mark Spanbroek 2025-01-28 16:08:11 +01:00
parent 7e1e71d25e
commit ef51834740
2 changed files with 22 additions and 0 deletions

View File

@ -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();
}

View File

@ -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
})
})
})
})