@@ -5,6 +5,7 @@ import {IEVault, IEulerSwap, EulerSwapTestBase, EulerSwap, TestERC20} from "./Eu
55import {QuoteLib} from "../src/libraries/QuoteLib.sol " ;
66import {SwapLib} from "../src/libraries/SwapLib.sol " ;
77import "../src/interfaces/IEulerSwapHookTarget.sol " ;
8+ import "evk/EVault/shared/lib/RevertBytes.sol " ;
89
910contract EulerSwapHooks is EulerSwapTestBase {
1011 EulerSwap public eulerSwap;
@@ -18,6 +19,7 @@ contract EulerSwapHooks is EulerSwapTestBase {
1819 uint64 fee0 = 0 ;
1920 uint64 fee1 = 0 ;
2021 bool expectRejectedError = false ;
22+ bytes expectSwapError;
2123 address toOverride;
2224 address swapHookOverride;
2325 bool setSwapHookOverride = false ;
@@ -39,12 +41,15 @@ contract EulerSwapHooks is EulerSwapTestBase {
3941
4042 uint64 beforeSwapCounter = 0 ;
4143
44+ bytes bs_throwError;
4245 uint256 bs_amount0Out;
4346 uint256 bs_amount1Out;
4447 address bs_msgSender;
4548 address bs_to;
4649
4750 function beforeSwap (uint256 amount0Out , uint256 amount1Out , address msgSender , address to ) external {
51+ if (bs_throwError.length > 0 ) RevertBytes.revertBytes (bs_throwError);
52+
4853 beforeSwapCounter++ ;
4954
5055 bs_amount0Out = amount0Out;
@@ -53,6 +58,7 @@ contract EulerSwapHooks is EulerSwapTestBase {
5358 bs_to = to;
5459 }
5560
61+ bytes gf_throwError;
5662 uint64 getFeeCounter = 0 ;
5763 uint112 gf_reserve0;
5864 uint112 gf_reserve1;
@@ -62,6 +68,8 @@ contract EulerSwapHooks is EulerSwapTestBase {
6268 returns (uint64 fee )
6369 {
6470 if (! readOnly) {
71+ if (gf_throwError.length > 0 ) RevertBytes.revertBytes (gf_throwError);
72+
6573 getFeeCounter++ ;
6674
6775 gf_reserve0 = reserve0;
@@ -85,6 +93,7 @@ contract EulerSwapHooks is EulerSwapTestBase {
8593 uint256 as_reserve1;
8694
8795 uint64 as_reconfigure_fee0;
96+ uint8 as_reconfigure_swapHookedOperations;
8897
8998 function afterSwap (
9099 uint256 amount0In ,
@@ -125,6 +134,16 @@ contract EulerSwapHooks is EulerSwapTestBase {
125134 // called from hook, not eulerAccount!
126135 eulerSwap.reconfigure (p, initial);
127136 }
137+
138+ if (as_reconfigure_swapHookedOperations != 0 ) {
139+ EulerSwap.InitialState memory initial;
140+ (initial.reserve0, initial.reserve1,) = eulerSwap.getReserves (); // confirms re-entrancy lock released
141+
142+ EulerSwap.DynamicParams memory p = eulerSwap.getDynamicParams ();
143+
144+ p.swapHookedOperations = as_reconfigure_swapHookedOperations;
145+ eulerSwap.reconfigure (p, initial);
146+ }
128147 }
129148
130149 function doSwap (bool exactIn , TestERC20 assetIn , TestERC20 assetOut , uint256 amount , uint256 expectedAmount )
@@ -149,6 +168,7 @@ contract EulerSwapHooks is EulerSwapTestBase {
149168 assetIn.transfer (address (eulerSwap), amountIn);
150169
151170 if (expectRejectedError) vm.expectRevert (QuoteLib.SwapRejected.selector );
171+ if (expectSwapError.length > 0 ) vm.expectRevert (expectSwapError);
152172
153173 address to = toOverride == address (0 ) ? address (this ) : toOverride;
154174
@@ -158,6 +178,8 @@ contract EulerSwapHooks is EulerSwapTestBase {
158178 eulerSwap.swap (amountOut, 0 , to, "" );
159179 }
160180
181+ if (expectRejectedError || expectSwapError.length > 0 ) return ;
182+
161183 assertEq (assetOut.balanceOf (to), amountOut);
162184 }
163185
@@ -220,6 +242,14 @@ contract EulerSwapHooks is EulerSwapTestBase {
220242 assertEq (bs_to, toOverride);
221243 }
222244
245+ function test_beforeSwapError () public {
246+ setHook (EULER_SWAP_HOOK_BEFORE_SWAP, 0 , 0 );
247+ bs_throwError = bytes ("oops! " );
248+
249+ expectSwapError = abi.encodeWithSelector (SwapLib.HookError.selector , EULER_SWAP_HOOK_BEFORE_SWAP, bs_throwError);
250+ doSwap (true , assetTST, assetTST2, 1e18 , 0.9974e18 );
251+ }
252+
223253 // getFee hook
224254
225255 function test_getFeeHook1 () public {
@@ -255,6 +285,14 @@ contract EulerSwapHooks is EulerSwapTestBase {
255285 doSwap (true , assetTST2, assetTST, 1e18 , 0.9875e18 ); // 1% fee
256286 }
257287
288+ function test_getFeeHookError () public {
289+ setHook (EULER_SWAP_HOOK_GET_FEE, 0 , 0 );
290+ gf_throwError = bytes ("oh no! " );
291+
292+ expectSwapError = abi.encodeWithSelector (SwapLib.HookError.selector , EULER_SWAP_HOOK_GET_FEE, gf_throwError);
293+ doSwap (true , assetTST, assetTST2, 1e18 , 0.9974e18 );
294+ }
295+
258296 // Hooks, but hook returns sentinel value, indicating to use default fee
259297
260298 function test_getFeeHookDefault1 () public {
@@ -335,6 +373,18 @@ contract EulerSwapHooks is EulerSwapTestBase {
335373 assertEq (p.fee0, 0.077e18 );
336374 }
337375
376+ function test_afterSwapReconfigureError () public {
377+ setHook (EULER_SWAP_HOOK_AFTER_SWAP, 0 , 0 );
378+ as_reconfigure_swapHookedOperations = 100 ;
379+
380+ expectSwapError = abi.encodeWithSelector (
381+ SwapLib.HookError.selector ,
382+ EULER_SWAP_HOOK_AFTER_SWAP,
383+ abi.encodeWithSelector (EulerSwap.BadDynamicParam.selector )
384+ );
385+ doSwap (true , assetTST, assetTST2, 1e18 , 0.9974e18 );
386+ }
387+
338388 // Multiple hooks
339389
340390 function test_multipleHooks1 () public {
0 commit comments