Skip to content

Commit

Permalink
Add receiver parameter to free
Browse files Browse the repository at this point in the history
  • Loading branch information
sunbreak1211 committed Dec 8, 2023
1 parent d3e4a6b commit fae2bea
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/LockstakeEngine.sol
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ contract LockstakeEngine {
emit Lock(urn, wad);
}

function free(address urn, uint256 wad) external urnOwner(urn) {
function free(address urn, address to, uint256 wad) external urnOwner(urn) {
require(wad <= uint256(type(int256).max), "LockstakeEngine/wad-overflow");
vat.frob(ilk, urn, urn, address(0), -int256(wad), 0);
vat.slip(ilk, urn, -int256(wad));
Expand All @@ -222,7 +222,7 @@ contract LockstakeEngine {
}
uint256 burn = wad * fee / WAD;
gov.burn(address(this), burn);
gov.transfer(msg.sender, wad - burn);
gov.transfer(to, wad - burn);
emit Free(urn, wad, burn);
}

Expand Down
14 changes: 9 additions & 5 deletions test/LockstakeEngine.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ contract AllocatorVaultTest is DssTest {
vm.expectRevert("LockstakeEngine/wad-overflow");
engine.lock(urn, uint256(type(int256).max) + 1);
vm.expectRevert("LockstakeEngine/wad-overflow");
engine.free(urn, uint256(type(int256).max) + 1);
engine.free(urn, address(this), uint256(type(int256).max) + 1);
if (withDelegate) {
engine.delegate(urn, voterDelegate);
}
Expand All @@ -243,17 +243,21 @@ contract AllocatorVaultTest is DssTest {
assertEq(gov.totalSupply(), initialSupply);
vm.expectEmit(true, true, true, true);
emit Free(urn, 40_000 * 10**18, 40_000 * 10**18 * 15 / 100);
engine.free(urn, 40_000 * 10**18);
engine.free(urn, address(this), 40_000 * 10**18);
assertEq(_ink(ilk, urn), 60_000 * 10**18);
assertEq(stkGov.balanceOf(urn), 60_000 * 10**18);
assertEq(gov.balanceOf(address(this)), 40_000 * 10**18 - 40_000 * 10**18 * 15 / 100);
engine.free(urn, address(123), 10_000 * 10**18);
assertEq(_ink(ilk, urn), 50_000 * 10**18);
assertEq(stkGov.balanceOf(urn), 50_000 * 10**18);
assertEq(gov.balanceOf(address(123)), 10_000 * 10**18 - 10_000 * 10**18 * 15 / 100);
if (withDelegate) {
assertEq(gov.balanceOf(address(engine)), 0);
assertEq(gov.balanceOf(address(voterDelegate)), 60_000 * 10**18);
assertEq(gov.balanceOf(address(voterDelegate)), 50_000 * 10**18);
} else {
assertEq(gov.balanceOf(address(engine)), 60_000 * 10**18);
assertEq(gov.balanceOf(address(engine)), 50_000 * 10**18);
}
assertEq(gov.totalSupply(), initialSupply - 40_000 * 10**18 * 15 / 100);
assertEq(gov.totalSupply(), initialSupply - 50_000 * 10**18 * 15 / 100);
}

function testLockFreeNoDelegate() public {
Expand Down

0 comments on commit fae2bea

Please sign in to comment.