Skip to content

Commit

Permalink
Support wsteth complex path, fix other tests (#30)
Browse files Browse the repository at this point in the history
* Support wsteth complex path, fix other tests

* fix typo - pooXlFee => poolXFee

Co-authored-by: Julien <[email protected]>

* Update wsteh callee address

Co-authored-by: Julien <[email protected]>
  • Loading branch information
talbaneth and julienmartinlevrai authored Aug 8, 2022
1 parent 4d3521e commit 3c40555
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 23 deletions.
2 changes: 1 addition & 1 deletion addresses.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"UniswapV2CalleeDai": "0x49399BB0Fcb52b32aB5A0909206BFf7B54FF80b3",
"UniswapV2LpTokenCalleeDai": "0x74893C37beACf205507ea794470b13DE06294220",
"UniswapV3Callee": "0xdB9C76109d102d2A1E645dCa3a7E671EBfd8e11A",
"WstETHCurveUniv3Callee": "0xC2D837173592194131827775a6Cd88322a98C825",
"WstETHCurveUniv3Callee": "0x21540b2653FeBa52eE2c8714CA7Abfb522bb5e8C",
"CurveLpTokenUniv3Callee": "0x71f2198849F3B1372EA90c079BD634928583f2d2"
},
"0x5": {
Expand Down
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

0 comments on commit 3c40555

Please sign in to comment.