Skip to content

Commit

Permalink
Merge pull request #54 from smart-transaction/fix/limit-order-test
Browse files Browse the repository at this point in the history
Modified call objs and check slippage for limit order test
  • Loading branch information
TokenTitan authored Jul 24, 2024
2 parents a3eb022 + 33afc58 commit f040202
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 25 deletions.
2 changes: 1 addition & 1 deletion test/FlashLiquidityTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ contract FlashLiquidityTest is Test, FlashLiquidityExampleLib {
uint256 laminatorSequenceNumber;

vm.startPrank(pusher);
laminatorSequenceNumber = userLand(100000000000000000000, 10, 1);
laminatorSequenceNumber = userLand(100000000000000000000, 80, 1);
vm.stopPrank();

// go forward in time
Expand Down
12 changes: 4 additions & 8 deletions test/examples/LimitOrder.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.6.2 <0.9.0;

import "forge-std/Test.sol";
import "forge-std/console.sol";
pragma solidity 0.8.23;

import "../utils/interfaces/ISwapRouter.sol";
import "../../src/timetravel/CallBreaker.sol";
Expand Down Expand Up @@ -82,18 +79,17 @@ contract LimitOrder is SmarterContract {

// The call to `exactInputSingle` executes the swap.
uint256 amountOut = router.exactInputSingle(params);
console.log("WETH", amountOut);

// check whether or not
CallObject[] memory callObjs = new CallObject[](1);
callObjs[0] = CallObject({
amount: 0,
addr: address(this),
gas: 1000000,
addr: address(router),
gas: 10000000,
callvalue: abi.encodeWithSignature("checkSlippage(uint256)", slippagePercent)
});

assertFutureCallTo(callObjs[0], 2);
assertFutureCallTo(callObjs[0]);
}

function provideLiquidityToDAIETHPool(uint256 _amount0In, uint256 _amount1In) external {
Expand Down
5 changes: 2 additions & 3 deletions test/solve-lib/FlashLiquidityExample.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.6.2 <0.9.0;

import "forge-std/Vm.sol";
import "../../src/lamination/Laminator.sol";
import "../../src/timetravel/CallBreaker.sol";
import "../../test/examples/LimitOrder.sol";
Expand Down Expand Up @@ -89,8 +88,8 @@ contract FlashLiquidityExampleLib {

callObjs[2] = CallObject({
amount: 0,
addr: address(limitOrder),
gas: 1000000,
addr: address(swapRouter),
gas: 10000000,
callvalue: abi.encodeWithSignature("checkSlippage(uint256)", maxDeviationPercentage)
});

Expand Down
25 changes: 17 additions & 8 deletions test/solve-lib/LimitOrderExample.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ contract LimitOrderExampleLib {
LimitOrder public limitOrder;
Laminator public laminator;
CallBreaker public callbreaker;
uint256 maxSlippage = 10;
uint256 _tipWei = 33;

function deployerLand(address pusher) public {
Expand All @@ -33,6 +34,8 @@ contract LimitOrderExampleLib {
address(swapRouter), address(callbreaker), address(positionManager), address(aToken), address(bToken)
);
pusherLaminated = payable(laminator.computeProxyAddress(pusher));
aToken.mint(100e18, pusherLaminated);
bToken.mint(100e18, address(callbreaker));
}

function userLand() public returns (uint256) {
Expand All @@ -42,15 +45,20 @@ contract LimitOrderExampleLib {
// Userland operations
// Temporarily, this example uses a call to swap but only sets slippage protection in
// sqrtPriceLimitX96 (not within the call to Uniswaps)
CallObject[] memory pusherCallObjs = new CallObject[](2);
CallObject[] memory pusherCallObjs = new CallObject[](3);
pusherCallObjs[0] = CallObject({
amount: 0,
addr: address(aToken),
gas: 1000000,
callvalue: abi.encodeWithSignature("approve(address,uint256)", limitOrder, 100e18)
});
pusherCallObjs[1] = CallObject({
amount: 0,
addr: address(limitOrder),
gas: 1000000,
callvalue: abi.encodeWithSignature("swapDAIForWETH(uint256,uint160)", 100, 1)
callvalue: abi.encodeWithSignature("swapDAIForWETH(uint256,uint256)", 100, maxSlippage)
});

pusherCallObjs[1] = CallObject({amount: _tipWei, addr: address(callbreaker), gas: 10000000, callvalue: ""});
pusherCallObjs[2] = CallObject({amount: _tipWei, addr: address(callbreaker), gas: 10000000, callvalue: ""});

return laminator.pushToProxy(abi.encode(pusherCallObjs), 1);
}
Expand All @@ -66,17 +74,18 @@ contract LimitOrderExampleLib {
callvalue: abi.encodeWithSignature("pull(uint256)", laminatorSequenceNumber)
});

ReturnObject[] memory returnObjsFromPull = new ReturnObject[](2);
returnObjsFromPull[0] = ReturnObject({returnvalue: ""});
ReturnObject[] memory returnObjsFromPull = new ReturnObject[](3);
returnObjsFromPull[0] = ReturnObject({returnvalue: abi.encode(true)});
returnObjsFromPull[1] = ReturnObject({returnvalue: ""});
returnObjsFromPull[2] = ReturnObject({returnvalue: ""});

returnObjs[0] = ReturnObject({returnvalue: abi.encode(abi.encode(returnObjsFromPull))});

callObjs[1] = CallObject({
amount: 0,
addr: pusherLaminated,
addr: address(swapRouter),
gas: 10000000,
callvalue: abi.encodeWithSignature("checkSlippage(uint256)", laminatorSequenceNumber)
callvalue: abi.encodeWithSignature("checkSlippage(uint256)", maxSlippage)
});

returnObjs[1] = ReturnObject({returnvalue: ""});
Expand Down
3 changes: 0 additions & 3 deletions test/solve-lib/MEVOracle/PartialFunctionExample.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.23;

import "forge-std/Vm.sol";
import "forge-std/console.sol";

import "src/lamination/Laminator.sol";
import "src/timetravel/CallBreaker.sol";
import "src/timetravel/SmarterContract.sol";
Expand Down
4 changes: 2 additions & 2 deletions test/utils/MockSwapRouter.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.13;
pragma solidity 0.8.23;

import {IWETH, IERC20} from "../utils/interfaces/IWeth.sol";
import {ISwapRouter} from "../utils/interfaces/ISwapRouter.sol";
Expand All @@ -9,7 +9,7 @@ import {ISwapRouter} from "../utils/interfaces/ISwapRouter.sol";
* @dev not to be used for anything other than local tests
*/
contract MockSwapRouter is ISwapRouter {
uint256 public constant DECIMAL = 18;
uint256 public constant DECIMAL = 1e18;

uint256 private _balanceOfWeth;
uint256 private _balanceOfDai;
Expand Down

0 comments on commit f040202

Please sign in to comment.