vault: burning funds

This commit is contained in:
Mark Spanbroek 2025-01-14 14:11:53 +01:00
parent 230e2140eb
commit eb1b821346
2 changed files with 38 additions and 0 deletions

View File

@ -41,4 +41,11 @@ contract Vault {
delete _available[controller][context][recipient];
_token.safeTransfer(Recipient.unwrap(recipient), amount);
}
function burn(Context context, Recipient recipient) public {
Controller controller = Controller.wrap(msg.sender);
uint256 amount = _available[controller][context][recipient];
delete _available[controller][context][recipient];
_token.safeTransfer(address(0xdead), amount);
}
}

View File

@ -96,4 +96,35 @@ describe("Vault", function () {
expect(after).to.equal(before)
})
})
describe("burning", function () {
const context = randomBytes(32)
const amount = 42
beforeEach(async function () {
await token.connect(account).approve(vault.address, amount)
await vault.deposit(context, account.address, amount)
})
it("can burn a deposit", async function () {
await vault.burn(context, account.address)
expect(await vault.balance(context, account.address)).to.equal(0)
})
it("no longer allows withdrawal", async function () {
await vault.burn(context, account.address)
const before = await token.balanceOf(account.address)
await vault.withdraw(context, account.address)
const after = await token.balanceOf(account.address)
expect(after).to.equal(before)
})
it("moves the tokens to address 0xdead", async function () {
const dead = "0x000000000000000000000000000000000000dead"
const before = await token.balanceOf(dead)
await vault.burn(context, account.address)
const after = await token.balanceOf(dead)
expect(after - before).to.equal(amount)
})
})
})