@@ -13,6 +13,11 @@ import {OutputsBuilder} from "../util/OutputsBuilder.sol";
13
13
import {PermitSignature} from "../util/PermitSignature.sol " ;
14
14
import {ISwapRouter02, ExactInputSingleParams} from "../../src/external/ISwapRouter02.sol " ;
15
15
import {IPermit2} from "permit2/src/interfaces/IPermit2.sol " ;
16
+ import {
17
+ PriceOracleValidation,
18
+ MixedRouteQuoterV1Wrapper
19
+ } from "../../src/sample-validation-contracts/PriceOracleValidation.sol " ;
20
+ import {IValidationCallback} from "../../src/interfaces/IValidationCallback.sol " ;
16
21
17
22
// This set of tests will use a mainnet fork to test integration.
18
23
contract SwapRouter02IntegrationTest is Test , PermitSignature {
@@ -27,6 +32,7 @@ contract SwapRouter02IntegrationTest is Test, PermitSignature {
27
32
address constant WHALE = 0xF04a5cC80B1E94C69B48f5ee68a08CD2F09A7c3E ;
28
33
IPermit2 constant PERMIT2 = IPermit2 (0x000000000022D473030F116dDEE9F6B43aC78BA3 );
29
34
uint256 constant ONE = 1000000000000000000 ;
35
+ address constant MIXED_ROUTE_QUOTER = 0x84E44095eeBfEC7793Cd7d5b57B7e401D7f1cA2E ;
30
36
31
37
address swapper;
32
38
address swapper2;
@@ -35,6 +41,8 @@ contract SwapRouter02IntegrationTest is Test, PermitSignature {
35
41
address filler;
36
42
SwapRouter02Executor swapRouter02Executor;
37
43
DutchOrderReactor dloReactor;
44
+ IValidationCallback priceOracleValidationContract;
45
+ MixedRouteQuoterV1Wrapper mixedRouteQuoterV1Wrapper;
38
46
39
47
function setUp () public {
40
48
swapperPrivateKey = 0xbabe ;
@@ -45,6 +53,8 @@ contract SwapRouter02IntegrationTest is Test, PermitSignature {
45
53
vm.createSelectFork (vm.envString ("FOUNDRY_RPC_URL " ), 16586505 );
46
54
dloReactor = new DutchOrderReactor (PERMIT2, address (0 ));
47
55
swapRouter02Executor = new SwapRouter02Executor (address (this ), dloReactor, address (this ), SWAPROUTER02);
56
+ priceOracleValidationContract = IValidationCallback (address (new PriceOracleValidation ()));
57
+ mixedRouteQuoterV1Wrapper = new MixedRouteQuoterV1Wrapper (MIXED_ROUTE_QUOTER);
48
58
49
59
// Swapper max approves permit post
50
60
vm.prank (swapper);
@@ -410,6 +420,53 @@ contract SwapRouter02IntegrationTest is Test, PermitSignature {
410
420
assertEq (address (swapRouter02Executor).balance, 319317550497372609 );
411
421
}
412
422
423
+ // Same setup as test above
424
+ function testSwapWethToDaiViaV2_priceOracleValidationContract () public {
425
+ uint256 inputAmount = 2 * ONE;
426
+ address [] memory path = new address [](2 );
427
+ path[0 ] = address (WETH);
428
+ path[1 ] = address (DAI);
429
+ bytes memory encodedPath = abi.encodePacked (path[0 ], uint24 (uint256 (3000 )), path[1 ]);
430
+
431
+ bytes memory additionalValidationData = abi.encode (
432
+ address (mixedRouteQuoterV1Wrapper),
433
+ abi.encodeWithSelector (bytes4 (keccak256 ("quoteExactInput(bytes,uint256) " )), encodedPath, inputAmount)
434
+ );
435
+
436
+ uint256 outputAmount = 3000 * ONE;
437
+
438
+ DutchOrder memory order = DutchOrder ({
439
+ info: OrderInfoBuilder.init (address (dloReactor)).withSwapper (swapper).withDeadline (block .timestamp + 100 )
440
+ .withValidationContract (priceOracleValidationContract).withValidationData (additionalValidationData),
441
+ decayStartTime: block .timestamp - 100 ,
442
+ decayEndTime: block .timestamp + 100 ,
443
+ input: DutchInput (WETH, inputAmount, inputAmount),
444
+ outputs: OutputsBuilder.singleDutch (address (DAI), outputAmount, outputAmount, address (swapper))
445
+ });
446
+
447
+ address [] memory tokensToApproveForSwapRouter02 = new address [](1 );
448
+ tokensToApproveForSwapRouter02[0 ] = address (WETH);
449
+
450
+ address [] memory tokensToApproveForReactor = new address [](1 );
451
+ tokensToApproveForReactor[0 ] = address (DAI);
452
+ bytes [] memory multicallData = new bytes [](1 );
453
+
454
+ multicallData[0 ] = abi.encodeWithSelector (
455
+ ISwapRouter02.swapExactTokensForTokens.selector ,
456
+ inputAmount,
457
+ outputAmount,
458
+ path,
459
+ address (swapRouter02Executor)
460
+ );
461
+ swapRouter02Executor.execute (
462
+ SignedOrder (abi.encode (order), signOrder (swapperPrivateKey, address (PERMIT2), order)),
463
+ abi.encode (tokensToApproveForSwapRouter02, tokensToApproveForReactor, multicallData)
464
+ );
465
+ assertEq (WETH.balanceOf (swapper), ONE);
466
+ assertEq (DAI.balanceOf (swapper), outputAmount);
467
+ assertEq (DAI.balanceOf (address (swapRouter02Executor)), 275438458971501955836 );
468
+ }
469
+
413
470
// There is 10 WETH swapRouter02Executor. Test that we can convert it to ETH
414
471
// and withdraw successfully.
415
472
function testUnwrapWETH () public {
0 commit comments