@@ -9,6 +9,7 @@ import {CtxLib} from "./CtxLib.sol";
99import {CurveLib} from "./CurveLib.sol " ;
1010import {FundsLib} from "./FundsLib.sol " ;
1111import {QuoteLib} from "./QuoteLib.sol " ;
12+ import {EulerSwapProtocolFeeConfig} from "../EulerSwapProtocolFeeConfig.sol " ;
1213import {IEulerSwap} from "../interfaces/IEulerSwap.sol " ;
1314import "../interfaces/IEulerSwapHookTarget.sol " ;
1415
@@ -40,6 +41,7 @@ library SwapLib {
4041 struct SwapContext {
4142 // Populated by init
4243 address evc;
44+ address protocolFeeConfig;
4345 IEulerSwap.StaticParams sParams;
4446 IEulerSwap.DynamicParams dParams;
4547 address asset0;
@@ -56,8 +58,13 @@ library SwapLib {
5658 uint256 amount1In; // full minus fees
5759 }
5860
59- function init (address evc , address sender , address to ) internal view returns (SwapContext memory ctx ) {
61+ function init (address evc , address protocolFeeConfig , address sender , address to )
62+ internal
63+ view
64+ returns (SwapContext memory ctx )
65+ {
6066 ctx.evc = evc;
67+ ctx.protocolFeeConfig = protocolFeeConfig;
6168 ctx.sParams = CtxLib.getStaticParams ();
6269 ctx.dParams = CtxLib.getDynamicParams ();
6370
@@ -170,14 +177,19 @@ library SwapLib {
170177
171178 // Slice off protocol fee
172179
173- if (ctx.sParams.protocolFeeRecipient != address (0 )) {
174- uint256 protocolFeeAmount = feeAmount * ctx.sParams.protocolFee / 1e18 ;
180+ {
181+ (address protocolFeeRecipient , uint64 protocolFee ) =
182+ EulerSwapProtocolFeeConfig (ctx.protocolFeeConfig).getProtocolFee (address (this ));
175183
176- if (protocolFeeAmount != 0 ) {
177- IERC20 (assetInput). safeTransfer (ctx.sParams.protocolFeeRecipient, protocolFeeAmount) ;
184+ if (protocolFee != 0 ) {
185+ uint256 protocolFeeAmount = feeAmount * protocolFee / 1e18 ;
178186
179- amount -= protocolFeeAmount;
180- feeAmount -= protocolFeeAmount;
187+ if (protocolFeeAmount != 0 ) {
188+ IERC20 (assetInput).safeTransfer (protocolFeeRecipient, protocolFeeAmount);
189+
190+ amount -= protocolFeeAmount;
191+ feeAmount -= protocolFeeAmount;
192+ }
181193 }
182194 }
183195
0 commit comments