Skip to content
This repository has been archived by the owner on Oct 8, 2024. It is now read-only.

Cropper tack shutdown #34

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/DssProxyActionsCropper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ interface GemJoinLike {
function gem() external returns (GemLike);
function ilk() external returns (bytes32);
function bonus() external returns (GemLike);
function tack(address src, address dst, uint256 wad) external;
}

interface DaiJoinLike {
Expand Down Expand Up @@ -760,13 +761,16 @@ contract DssProxyActionsEndCropper is Common {
bytes32 ilk = GemJoinLike(ethJoin).ilk();
EndLike(end).cash(ilk, wad);
uint256 wadC = _mul(wad, EndLike(end).fix(ilk)) / RAY;
address urnProxy = CropperLike(cropper).getOrCreateProxy(address(this));
// Flux to the proxy's UrnProxy in cropper, so it can be pulled out with the managed gem join
VatLike(vat).flux(
ilk,
address(this),
CropperLike(cropper).getOrCreateProxy(address(this)),
urnProxy,
wadC
);
// Tack from the End to allow fleeing, assumes vaults' stakes were tacked to the End after skimming
GemJoinLike(ethJoin).tack(end, urnProxy, wadC);
// Exits WETH amount to proxy address as a token
CropperLike(cropper).flee(ethJoin, address(this), wadC);
// Converts WETH to ETH
Expand All @@ -783,13 +787,16 @@ contract DssProxyActionsEndCropper is Common {
bytes32 ilk = GemJoinLike(gemJoin).ilk();
EndLike(end).cash(ilk, wad);
uint256 wadC = _mul(wad, EndLike(end).fix(ilk)) / RAY;
address urnProxy = CropperLike(cropper).getOrCreateProxy(address(this));
// Flux to the proxy's UrnProxy in cropper, so it can be pulled out with the managed gem join
VatLike(vat).flux(
ilk,
address(this),
CropperLike(cropper).getOrCreateProxy(address(this)),
urnProxy,
wadC
);
// Tack from the End to allow fleeing, assumes vaults' stakes were tacked to the End after skimming
GemJoinLike(gemJoin).tack(end, urnProxy, wadC);
// Exits token amount to the user's wallet as a token
uint256 amt = wadC / 10 ** (18 - GemJoinLike(gemJoin).dec());
CropperLike(cropper).flee(gemJoin, msg.sender, amt);
Expand Down
57 changes: 49 additions & 8 deletions src/test/DssProxyActionsCropper.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,34 @@ contract MockCdpManager {
}
}

contract User {
DSProxy public proxy;
address public dssProxyActionsEnd;

receive() external payable {}

constructor(ProxyRegistry registry, address _dssProxyActionsEnd) public {
proxy = DSProxy(registry.build());
dssProxyActionsEnd = _dssProxyActionsEnd;
}

function approve(address token, address usr, uint256 amount) public {
Token(token).approve(usr, amount);
}

function end_pack(address a, address b, uint256 c) public {
proxy.execute(dssProxyActionsEnd, abi.encodeWithSignature("pack(address,address,uint256)", a, b, c));
}

function end_cashETH(address a, address b, uint256 c) public {
proxy.execute(dssProxyActionsEnd, abi.encodeWithSignature("cashETH(address,address,uint256)", a, b, c));
}

function end_cashGem(address a, address b, uint256 c) public {
proxy.execute(dssProxyActionsEnd, abi.encodeWithSignature("cashGem(address,address,uint256)", a, b, c));
}
}

contract ProxyCalls {
DSProxy proxy;
address dssProxyActions;
Expand Down Expand Up @@ -669,7 +697,9 @@ contract DssProxyActionsTest is DssDeployTestBase, ProxyCalls {
(inkV, artV) = vat.urns("ETH", charterProxy);
assertEq(inkV, 0);
assertEq(artV, 0);
uint256 remainInkVal = 2 ether - 300 * end.tag("ETH") / 10 ** 9; // 2 ETH (deposited) - 300 DAI debt * ETH cage price
uint256 skimmedEth = vat.gem("ETH", address(end));
assertEq(skimmedEth, 300 * end.tag("ETH") / 10 ** 9);
uint256 remainInkVal = 2 ether - skimmedEth; // 2 ETH (deposited) - 300 DAI debt * ETH cage price
assertEq(address(this).balance, prevBalanceETH + remainInkVal);
assertProxyRewarded(address(ethManagedJoin), 100 * 10 ** 12);

Expand All @@ -678,7 +708,9 @@ contract DssProxyActionsTest is DssDeployTestBase, ProxyCalls {
(inkV, artV) = vat.urns("WBTC", charterProxy);
assertEq(inkV, 0);
assertEq(artV, 0);
remainInkVal = (1 ether - 5 * end.tag("WBTC") / 10 ** 9) / 10 ** 10; // 1 WBTC (deposited) - 5 DAI debt * WBTC cage price
uint256 skimmedWbtc = vat.gem("WBTC", address(end));
assertEq(skimmedWbtc, 5 * end.tag("WBTC") / 10 ** 9);
remainInkVal = (1 ether - skimmedWbtc) / 10 ** 10; // 1 WBTC (deposited) - 5 DAI debt * WBTC cage price
assertEq(wbtc.balanceOf(address(this)), prevBalanceWBTC + remainInkVal);
assertProxyRewarded(address(ethManagedJoin), 200 * 10 ** 12);

Expand All @@ -687,14 +719,23 @@ contract DssProxyActionsTest is DssDeployTestBase, ProxyCalls {
end.flow("ETH");
end.flow("WBTC");

dai.approve(address(proxy), 305 ether);
this.end_pack(address(daiJoin), address(end), 305 ether);
User user = new User(registry, dssProxyActionsEnd);

// Move dai to user so he can redeem it for collateral
dai.transfer(address(user), 305 ether);

user.approve(address(dai), address(user.proxy()), 305 ether);
user.end_pack(address(daiJoin), address(end), 305 ether);

// Tack from the skimmed vaults to End, required for cashing
ethManagedJoin.tack(charterProxy, address(end), ethManagedJoin.stake(charterProxy));
wbtcJoin.tack(charterProxy, address(end), wbtcJoin.stake(charterProxy));

this.end_cashETH(address(ethManagedJoin), address(end), 305 ether);
this.end_cashGem(address(wbtcJoin), address(end), 305 ether);
user.end_cashETH(address(ethManagedJoin), address(end), 305 ether);
user.end_cashGem(address(wbtcJoin), address(end), 305 ether);

assertEq(address(this).balance, prevBalanceETH + 2 ether - 1); // (-1 rounding)
assertEq(wbtc.balanceOf(address(this)), prevBalanceWBTC + 1 * 10 ** 8 - 1); // (-1 rounding)
assertEq(address(user).balance, skimmedEth - 1); // (-1 rounding)
assertEq(wbtc.balanceOf(address(user)), skimmedWbtc / 10 ** 10 - 1); // (-1 rounding)
}

receive() external payable {}
Expand Down