Skip to content

Commit e7776c0

Browse files
committed
fix conflicts with new fee computation method
1 parent 8f5cd1f commit e7776c0

File tree

4 files changed

+8
-72
lines changed

4 files changed

+8
-72
lines changed

src/EulerSwapFactory.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ contract EulerSwapFactory is IEulerSwapFactory, EVCUtil {
221221
/// @param pool The address of the pool to query
222222
/// @return The addresses of asset0 and asset1 in the pool
223223
function _getAssets(address pool) internal view returns (address, address) {
224-
return (EulerSwap(pool).asset0(), EulerSwap(pool).asset1());
224+
return (IEulerSwap(pool).asset0(), IEulerSwap(pool).asset1());
225225
}
226226

227227
/// @notice Returns a slice of an array of addresses

src/EulerSwapHook.sol

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ contract EulerSwapHook is EulerSwap, BaseHook {
8686
// the debt will be paid by the swapper via the swap router
8787
// TODO: can we optimize the transfer by pulling from PoolManager directly to Euler?
8888
poolManager.take(inputCurrency, address(this), amountIn);
89-
amountInWithoutFee = depositAssets(zeroForOne ? vault0 : vault1, amountIn) * feeMultiplier / 1e18;
89+
amountInWithoutFee = depositAssets(zeroForOne ? asset0 : asset1, zeroForOne ? vault0 : vault1);
9090

9191
// pay the output token, to the PoolManager from an Euler vault
9292
// the credit will be forwarded to the swap router, which then forwards it to the swapper
@@ -120,8 +120,8 @@ contract EulerSwapHook is EulerSwap, BaseHook {
120120
require(evc.isAccountOperatorAuthorized(eulerAccount, address(this)), OperatorNotInstalled());
121121
require(amount <= type(uint112).max, SwapLimitExceeded());
122122

123-
// exactIn: decrease received amountIn, rounding down
124-
if (exactIn) amount = amount * feeMultiplier / 1e18;
123+
// exactIn: decrease effective amountIn
124+
if (exactIn) amount = amount - (amount * fee / 1e18);
125125

126126
(uint256 inLimit, uint256 outLimit) = calcLimits(asset0IsInput);
127127

@@ -135,8 +135,8 @@ contract EulerSwapHook is EulerSwap, BaseHook {
135135
require(amount <= outLimit && quote <= inLimit, SwapLimitExceeded());
136136
}
137137

138-
// exactOut: increase required quote(amountIn), rounding up
139-
if (!exactIn) quote = (quote * 1e18 + (feeMultiplier - 1)) / feeMultiplier;
138+
// exactOut: inflate required amountIn
139+
if (!exactIn) quote = (quote * 1e18) / (1e18 - fee);
140140

141141
return quote;
142142
}

test/EulerSwapFactoryTest.t.sol

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -103,70 +103,6 @@ contract EulerSwapFactoryTest is EulerSwapTestBase {
103103
vm.prank(holder);
104104
vm.expectRevert(EulerSwapFactory.OldOperatorStillInstalled.selector);
105105
evc.batch(items);
106-
107-
// test deploying new pool for same assets pair as old one
108-
address oldPool = eulerSwapFactory.poolByEulerAccount(holder);
109-
salt = bytes32(uint256(123456));
110-
predictedAddress = predictPoolAddress(address(eulerSwapFactory), poolParams, curveParams, salt);
111-
112-
items = new IEVC.BatchItem[](3);
113-
items[0] = IEVC.BatchItem({
114-
onBehalfOfAccount: address(0),
115-
targetContract: address(evc),
116-
value: 0,
117-
data: abi.encodeCall(evc.setAccountOperator, (holder, oldPool, false))
118-
});
119-
items[1] = IEVC.BatchItem({
120-
onBehalfOfAccount: address(0),
121-
targetContract: address(evc),
122-
value: 0,
123-
data: abi.encodeCall(evc.setAccountOperator, (holder, predictedAddress, true))
124-
});
125-
items[2] = IEVC.BatchItem({
126-
onBehalfOfAccount: holder,
127-
targetContract: address(eulerSwapFactory),
128-
value: 0,
129-
data: abi.encodeCall(EulerSwapFactory.deployPool, (poolParams, curveParams, salt))
130-
});
131-
132-
vm.prank(holder);
133-
evc.batch(items);
134-
135-
address pool = eulerSwapFactory.poolByEulerAccount(holder);
136-
assertEq(pool, predictedAddress);
137-
138-
// test deploying new pool for different assets pair as old one
139-
oldPool = eulerSwapFactory.poolByEulerAccount(holder);
140-
poolParams = IEulerSwap.Params(address(eTST), address(eTST3), holder, 1e18, 1e18, 1e18, 1e18, 0);
141-
142-
salt = bytes32(uint256(1234567));
143-
predictedAddress = predictPoolAddress(address(eulerSwapFactory), poolParams, curveParams, salt);
144-
145-
items = new IEVC.BatchItem[](3);
146-
items[0] = IEVC.BatchItem({
147-
onBehalfOfAccount: address(0),
148-
targetContract: address(evc),
149-
value: 0,
150-
data: abi.encodeCall(evc.setAccountOperator, (holder, oldPool, false))
151-
});
152-
items[1] = IEVC.BatchItem({
153-
onBehalfOfAccount: address(0),
154-
targetContract: address(evc),
155-
value: 0,
156-
data: abi.encodeCall(evc.setAccountOperator, (holder, predictedAddress, true))
157-
});
158-
items[2] = IEVC.BatchItem({
159-
onBehalfOfAccount: holder,
160-
targetContract: address(eulerSwapFactory),
161-
value: 0,
162-
data: abi.encodeCall(EulerSwapFactory.deployPool, (poolParams, curveParams, salt))
163-
});
164-
165-
vm.prank(holder);
166-
evc.batch(items);
167-
168-
pool = eulerSwapFactory.poolByEulerAccount(holder);
169-
assertEq(pool, predictedAddress);
170106
}
171107

172108
function testInvalidPoolsSliceOutOfBounds() public {

test/EulerSwapHook.fees.t.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ contract EulerSwapHookTest is EulerSwapTestBase {
4747
(uint112 r0, uint112 r1,) = eulerSwap.getReserves();
4848

4949
uint256 amountIn = 1e18;
50-
uint256 amountInWithoutFee = amountIn * eulerSwap.feeMultiplier() / 1e18;
50+
uint256 amountInWithoutFee = amountIn - (amountIn * eulerSwap.fee() / 1e18);
5151
uint256 amountOut =
5252
periphery.quoteExactInput(address(eulerSwap), address(assetTST), address(assetTST2), amountIn);
5353

@@ -89,7 +89,7 @@ contract EulerSwapHookTest is EulerSwapTestBase {
8989
periphery.quoteExactOutput(address(eulerSwap), address(assetTST), address(assetTST2), amountOut);
9090

9191
// inverse of the fee math in Periphery
92-
uint256 amountInWithoutFee = (amountIn * eulerSwap.feeMultiplier() - eulerSwap.feeMultiplier()) / 1e18;
92+
uint256 amountInWithoutFee = amountIn * (1e18 - eulerSwap.fee()) / 1e18;
9393

9494
assetTST.mint(anyone, amountIn);
9595

0 commit comments

Comments
 (0)