@@ -32,6 +32,8 @@ contract SkipGoSwapRouterTest is Test {
32
32
address usdc = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 ;
33
33
address wbtc = 0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599 ;
34
34
35
+ SkipGoSwapRouter.Affiliate[] memory affiliates = new SkipGoSwapRouter.Affiliate [](0 );
36
+
35
37
SkipGoSwapRouter.Hop[] memory hops = new SkipGoSwapRouter.Hop [](2 );
36
38
37
39
{
@@ -73,7 +75,7 @@ contract SkipGoSwapRouterTest is Test {
73
75
74
76
IERC20 (weth).approve (address (router), amountIn);
75
77
76
- uint256 amountOut = router.swapExactIn (amountIn, 1 , weth, wbtc, hops);
78
+ uint256 amountOut = router.swapExactIn (amountIn, 1 , weth, wbtc, hops, affiliates );
77
79
78
80
vm.stopPrank ();
79
81
@@ -86,11 +88,82 @@ contract SkipGoSwapRouterTest is Test {
86
88
assertEq (amountOut, expectedAmountOut);
87
89
}
88
90
91
+ function test_swapExactIn_WithAffiliate () public {
92
+ address weth = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 ;
93
+ address usdc = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 ;
94
+ address wbtc = 0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599 ;
95
+
96
+ SkipGoSwapRouter.Hop[] memory hops = new SkipGoSwapRouter.Hop [](2 );
97
+
98
+ {
99
+ UniswapV2Adapter.UniswapV2Data memory hopOneData = UniswapV2Adapter.UniswapV2Data ({
100
+ pool: 0xB4e16d0168e52d35CaCD2c6185b44281Ec28C9Dc ,
101
+ zeroToOne: false ,
102
+ fee: 300
103
+ });
104
+
105
+ bytes memory encodedHopOneData = abi.encode (hopOneData);
106
+
107
+ hops[0 ] = SkipGoSwapRouter.Hop ({exchangeType: 1 , data: encodedHopOneData});
108
+
109
+ UniswapV3Adapter.UniswapV3Data memory hopTwoData = UniswapV3Adapter.UniswapV3Data ({
110
+ tokenIn: usdc,
111
+ tokenOut: wbtc,
112
+ fee: 3000 ,
113
+ quoter: 0x5e55C9e631FAE526cd4B0526C4818D6e0a9eF0e3 ,
114
+ swapRouter: 0xE592427A0AEce92De3Edee1F18E0157C05861564
115
+ });
116
+
117
+ bytes memory encodedHopTwoData = abi.encode (hopTwoData);
118
+
119
+ hops[1 ] = SkipGoSwapRouter.Hop ({exchangeType: 2 , data: encodedHopTwoData});
120
+ }
121
+
122
+ uint256 amountIn = 1 ether ;
123
+
124
+ address alice = makeAddr ("alice " );
125
+ address bob = makeAddr ("bob " );
126
+
127
+ deal (weth, alice, amountIn);
128
+
129
+ SkipGoSwapRouter.Affiliate[] memory affiliates = new SkipGoSwapRouter.Affiliate [](1 );
130
+
131
+ {
132
+ affiliates[0 ] = SkipGoSwapRouter.Affiliate ({recipient: bob, feeBPS: 100 });
133
+ }
134
+
135
+ uint256 expectedAmountOut = router.getAmountOut (amountIn, hops);
136
+
137
+ uint256 expectedAffiliateFee = (expectedAmountOut * 100 ) / 10000 ;
138
+
139
+ vm.startPrank (alice);
140
+
141
+ IERC20 (weth).approve (address (router), amountIn);
142
+
143
+ uint256 amountOut = router.swapExactIn (amountIn, 1 , weth, wbtc, hops, affiliates);
144
+
145
+ vm.stopPrank ();
146
+
147
+ uint256 wethBalanceAfter = IERC20 (weth).balanceOf (alice);
148
+ uint256 wbtcBalanceAfter = IERC20 (wbtc).balanceOf (alice);
149
+
150
+ uint256 bobWbtcBalanceAfter = IERC20 (wbtc).balanceOf (bob);
151
+
152
+ assertEq (wethBalanceAfter, 0 );
153
+ assertEq (wbtcBalanceAfter, amountOut);
154
+
155
+ assertEq (amountOut, expectedAmountOut - expectedAffiliateFee);
156
+
157
+ assertEq (bobWbtcBalanceAfter, expectedAffiliateFee);
158
+ }
159
+
89
160
function test_revertSwapExactIn_WhenAmountOutIsLessThanAmountIn () public {
90
161
address weth = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 ;
91
162
address usdc = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 ;
92
163
address wbtc = 0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599 ;
93
164
165
+ SkipGoSwapRouter.Affiliate[] memory affiliates = new SkipGoSwapRouter.Affiliate [](0 );
166
+
94
167
SkipGoSwapRouter.Hop[] memory hops = new SkipGoSwapRouter.Hop [](2 );
95
168
96
169
{
@@ -130,7 +203,7 @@ contract SkipGoSwapRouterTest is Test {
130
203
IERC20 (weth).approve (address (router), amountIn);
131
204
132
205
vm.expectRevert ("amount out is less than amount out min " );
133
- router.swapExactIn (amountIn, expectedAmountOut + 1 , weth, wbtc, hops);
206
+ router.swapExactIn (amountIn, expectedAmountOut + 1 , weth, wbtc, hops, affiliates );
134
207
135
208
vm.stopPrank ();
136
209
}
@@ -140,6 +213,8 @@ contract SkipGoSwapRouterTest is Test {
140
213
address usdc = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 ;
141
214
address wbtc = 0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599 ;
142
215
216
+ SkipGoSwapRouter.Affiliate[] memory affiliates = new SkipGoSwapRouter.Affiliate [](0 );
217
+
143
218
SkipGoSwapRouter.Hop[] memory hops = new SkipGoSwapRouter.Hop [](2 );
144
219
145
220
{
@@ -181,7 +256,7 @@ contract SkipGoSwapRouterTest is Test {
181
256
182
257
IERC20 (weth).approve (address (router), expectedAmountIn);
183
258
184
- uint256 amountIn = router.swapExactOut (amountOut, type (uint256 ).max, weth, wbtc, hops);
259
+ uint256 amountIn = router.swapExactOut (amountOut, type (uint256 ).max, weth, wbtc, hops, affiliates );
185
260
186
261
vm.stopPrank ();
187
262
@@ -194,11 +269,82 @@ contract SkipGoSwapRouterTest is Test {
194
269
assertEq (amountIn, expectedAmountIn);
195
270
}
196
271
272
+ function test_swapExactOut_WithAffiliate () public {
273
+ address weth = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 ;
274
+ address usdc = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 ;
275
+ address wbtc = 0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599 ;
276
+
277
+ SkipGoSwapRouter.Hop[] memory hops = new SkipGoSwapRouter.Hop [](2 );
278
+
279
+ {
280
+ UniswapV2Adapter.UniswapV2Data memory hopOneData = UniswapV2Adapter.UniswapV2Data ({
281
+ pool: 0xB4e16d0168e52d35CaCD2c6185b44281Ec28C9Dc ,
282
+ zeroToOne: false ,
283
+ fee: 300
284
+ });
285
+
286
+ bytes memory encodedHopOneData = abi.encode (hopOneData);
287
+
288
+ hops[0 ] = SkipGoSwapRouter.Hop ({exchangeType: 1 , data: encodedHopOneData});
289
+
290
+ UniswapV3Adapter.UniswapV3Data memory hopTwoData = UniswapV3Adapter.UniswapV3Data ({
291
+ tokenIn: usdc,
292
+ tokenOut: wbtc,
293
+ fee: 3000 ,
294
+ quoter: 0x5e55C9e631FAE526cd4B0526C4818D6e0a9eF0e3 ,
295
+ swapRouter: 0xE592427A0AEce92De3Edee1F18E0157C05861564
296
+ });
297
+
298
+ bytes memory encodedHopTwoData = abi.encode (hopTwoData);
299
+
300
+ hops[1 ] = SkipGoSwapRouter.Hop ({exchangeType: 2 , data: encodedHopTwoData});
301
+ }
302
+
303
+ uint256 amountOut = 100000000 ;
304
+
305
+ address alice = makeAddr ("alice " );
306
+ address bob = makeAddr ("bob " );
307
+
308
+ uint256 expectedAmountIn = router.getAmountIn (amountOut, hops);
309
+
310
+ deal (weth, alice, expectedAmountIn);
311
+
312
+ SkipGoSwapRouter.Affiliate[] memory affiliates = new SkipGoSwapRouter.Affiliate [](1 );
313
+
314
+ {
315
+ affiliates[0 ] = SkipGoSwapRouter.Affiliate ({recipient: bob, feeBPS: 100 });
316
+ }
317
+
318
+ vm.startPrank (alice);
319
+
320
+ IERC20 (weth).approve (address (router), expectedAmountIn);
321
+
322
+ uint256 amountIn = router.swapExactOut (amountOut, type (uint256 ).max, weth, wbtc, hops, affiliates);
323
+
324
+ vm.stopPrank ();
325
+
326
+ uint256 expectedAffiliateFee = (amountOut * 100 ) / 10000 ;
327
+
328
+ uint256 wethBalanceAfter = IERC20 (weth).balanceOf (alice);
329
+ uint256 wbtcBalanceAfter = IERC20 (wbtc).balanceOf (alice);
330
+
331
+ uint256 bobWbtcBalanceAfter = IERC20 (wbtc).balanceOf (bob);
332
+
333
+ assertEq (wethBalanceAfter, 0 );
334
+ assertEq (wbtcBalanceAfter, amountOut - expectedAffiliateFee);
335
+
336
+ assertEq (amountIn, expectedAmountIn);
337
+
338
+ assertEq (bobWbtcBalanceAfter, expectedAffiliateFee);
339
+ }
340
+
197
341
function test_revertSwapExactOut_WhenAmountInIsGreaterThanAmountInMax () public {
198
342
address weth = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 ;
199
343
address usdc = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 ;
200
344
address wbtc = 0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599 ;
201
345
346
+ SkipGoSwapRouter.Affiliate[] memory affiliates = new SkipGoSwapRouter.Affiliate [](0 );
347
+
202
348
SkipGoSwapRouter.Hop[] memory hops = new SkipGoSwapRouter.Hop [](2 );
203
349
204
350
{
@@ -238,7 +384,7 @@ contract SkipGoSwapRouterTest is Test {
238
384
IERC20 (weth).approve (address (router), expectedAmountIn);
239
385
240
386
vm.expectRevert ("amount in is greater than amount in max " );
241
- router.swapExactOut (amountOut, expectedAmountIn - 1 , weth, wbtc, hops);
387
+ router.swapExactOut (amountOut, expectedAmountIn - 1 , weth, wbtc, hops, affiliates );
242
388
243
389
vm.stopPrank ();
244
390
}
0 commit comments