Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support wsteth complex path, fix other tests #30

Merged
merged 3 commits into from
Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 2 additions & 4 deletions src/WstETHCurveUniv3Callee.sol
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ contract WstETHCurveUniv3Callee {
address to, // address to send remaining DAI to
address gemJoin, // gemJoin adapter address
uint256 minProfit, // minimum profit in DAI to make [wad]
uint24 poolFee, // uniswap V3 WETH-DAI pool fee
bytes memory path, // uniswap v3 path
address charterManager // pass address(0) if no manager
) = abi.decode(data, (address, address, uint256, uint24, address));
) = abi.decode(data, (address, address, uint256, bytes, address));

address gem = GemJoinLike(gemJoin).gem();

Expand Down Expand Up @@ -157,7 +157,6 @@ contract WstETHCurveUniv3Callee {
uint256 daiToJoin = _divup(owe, RAY);

// Do operation and get dai amount bought (checking the profit is achieved)
bytes memory path = abi.encodePacked(gem, poolFee, address(dai));
UniV3RouterLike.ExactInputParams memory params = UniV3RouterLike.ExactInputParams({
path: path,
recipient: address(this),
Expand All @@ -180,4 +179,3 @@ contract WstETHCurveUniv3Callee {
dai.transfer(to, dai.balanceOf(address(this)));
}
}

6 changes: 4 additions & 2 deletions src/test/Simulation.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,8 @@ contract SimulationTests is DSTest {
}

function testFrobMax() public {
uint256 amountLink = 2_000 * WAD;
(,,,, uint256 dustRad) = vat.ilks(linkName);
uint256 amountLink = (dustRad / getLinkPriceRay()) * 2;
getLink(amountLink);
joinLink(amountLink);
frobMax(amountLink, linkName);
Expand Down Expand Up @@ -739,7 +740,8 @@ contract SimulationTests is DSTest {
}

function testBarkLink() public {
uint256 amountLink = 2_000 * WAD;
(,,,, uint256 dustRad) = vat.ilks(linkName);
uint256 amountLink = (dustRad / getLinkPriceRay()) * 2;
uint256 kicksPre = linkClip.kicks();
getLink(amountLink);
joinLink(amountLink);
Expand Down
41 changes: 25 additions & 16 deletions src/test/WstETHCurveUniv3Callee.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,16 @@ contract CurveCalleeTest is DSTest {
WstETHCurveUniv3Callee callee;
uint256 tail;
address vat;
address weth;
address dai;
address usdc;

function setUp() public {
clipper = Chainlog(chainlog).getAddress("MCD_CLIP_WSTETH_A");
address daiJoin = Chainlog(chainlog).getAddress("MCD_JOIN_DAI");
address weth = Chainlog(chainlog).getAddress("ETH");
weth = Chainlog(chainlog).getAddress("ETH");
dai = Chainlog(chainlog).getAddress("MCD_DAI");
usdc = Chainlog(chainlog).getAddress("USDC");
callee = new WstETHCurveUniv3Callee(curve, uniV3, daiJoin, weth);
vat = Chainlog(chainlog).getAddress("MCD_VAT");
Vat(vat).hope(clipper);
Expand Down Expand Up @@ -138,11 +143,12 @@ contract CurveCalleeTest is DSTest {
function test_baseline() public {
uint256 amt = 50 * WAD;
newAuction(amt);
uint24 poolFee = 3000;
bytes memory data = abi.encode(
address(123),
address(gemJoin),
uint256(0),
uint24(3000),
abi.encodePacked(weth, poolFee, dai),
address(0)
);
Hevm(hevm).warp(block.timestamp + tail / 2);
Expand All @@ -153,40 +159,42 @@ contract CurveCalleeTest is DSTest {
who: address(callee),
data: data
});
address dai = Chainlog(chainlog).getAddress("MCD_DAI");
assertEq(Token(dai).balanceOf(address(this)), 0);
assertEq(Token(wstEth).balanceOf(address(this)), 0);
}

function test_bigAmt() public {
function test_bigAmtWithComplexPath() public {
uint256 amt = 3000 * WAD;
newAuction(amt);
uint24 poolAFee = 500;
uint24 poolBFee = 100;
bytes memory data = abi.encode(
address(this),
address(gemJoin),
uint256(0),
uint24(3000),
abi.encodePacked(weth, poolAFee, usdc, poolBFee, dai),
address(0)
);
Hevm(hevm).warp(block.timestamp + tail / 2);
Clipper(clipper).take({
id: id,
amt: amt,
max: type(uint256).max,
who: address(callee),
data: data
id: id,
amt: amt,
max: type(uint256).max,
who: address(callee),
data: data
});
}

function test_profit() public {
uint256 minProfit = 10_000 * WAD;
uint256 amt = 50 * WAD;
newAuction(amt);
uint24 poolFee = 3000;
bytes memory data = abi.encode(
address(123),
address(gemJoin),
uint256(minProfit),
uint24(3000),
abi.encodePacked(weth, poolFee, dai),
address(0)
);
Hevm(hevm).warp(block.timestamp + tail / 2);
Expand All @@ -197,7 +205,6 @@ contract CurveCalleeTest is DSTest {
who: address(callee),
data: data
});
address dai = Chainlog(chainlog).getAddress("MCD_DAI");
assertGe(Token(dai).balanceOf(address(123)), minProfit);
}

Expand All @@ -209,7 +216,7 @@ contract CurveCalleeTest is DSTest {
address(this),
address(gemJoin),
uint256(0),
poolFee,
abi.encodePacked(weth, poolFee, dai),
address(0)
);
Hevm(hevm).warp(block.timestamp + tail / 2);
Expand All @@ -230,7 +237,7 @@ contract CurveCalleeTest is DSTest {
address(this),
address(gemJoin),
uint256(0),
poolFee,
abi.encodePacked(weth, poolFee, dai),
address(0)
);
Hevm(hevm).warp(block.timestamp + tail / 2);
Expand All @@ -246,11 +253,12 @@ contract CurveCalleeTest is DSTest {
function test_maxPrice() public {
uint256 amt = 50 * WAD;
newAuction(amt);
uint24 poolFee = 3000;
bytes memory data = abi.encode(
address(this),
address(gemJoin),
uint256(0),
uint24(3000),
abi.encodePacked(weth, poolFee, dai),
address(0)
);
Hevm(hevm).warp(block.timestamp + tail / 2);
Expand All @@ -274,11 +282,12 @@ contract CurveCalleeTest is DSTest {
function testFail_maxPrice() public {
uint256 amt = 50 * WAD;
newAuction(amt);
uint24 poolFee = 3000;
bytes memory data = abi.encode(
address(this),
address(gemJoin),
uint256(0),
uint24(3000),
abi.encodePacked(weth, poolFee, dai),
address(0)
);
Hevm(hevm).warp(block.timestamp + tail / 5);
Expand Down