Skip to content

Commit cfe1254

Browse files
committed
if feeRecipient is configured, verify it is not a known subaccount to avoid losing fees
- Spearbit #8
1 parent 315466d commit cfe1254

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

src/EulerSwapManagement.sol

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ contract EulerSwapManagement is EulerSwapBase {
2121
error BadDynamicParam();
2222
error AssetsOutOfOrderOrEqual();
2323
error InvalidAssets();
24+
error BadFeeRecipient();
2425

2526
/// @notice Emitted upon EulerSwap instance creation or reconfiguration.
2627
event EulerSwapConfigured(IEulerSwap.DynamicParams dParams, IEulerSwap.InitialState initialState);
@@ -87,6 +88,11 @@ contract EulerSwapManagement is EulerSwapBase {
8788

8889
require(sParams.eulerAccount != sParams.feeRecipient, BadStaticParam()); // set feeRecipient to 0 instead
8990

91+
if (sParams.feeRecipient != address(0)) {
92+
address owner = evc.getAccountOwner(sParams.feeRecipient);
93+
require(owner == sParams.feeRecipient || owner == address(0), BadFeeRecipient());
94+
}
95+
9096
// Dynamic parameters
9197

9298
if (initialState.reserve0 != 0) {

test/EulerSwapTestBase.t.sol

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ contract EulerSwapTestBase is EVaultTestBase {
4242
address installedOperator;
4343
bool expectInsufficientValidityBondRevert = false;
4444
bool expectAccountLiquidityRevert = false;
45+
bool expectBadFeeRecipient = false;
4546

4647
error E_AccountLiquidity();
4748

@@ -172,13 +173,14 @@ contract EulerSwapTestBase is EVaultTestBase {
172173

173174
vm.prank(holder);
174175
if (expectAccountLiquidityRevert) vm.expectRevert(E_AccountLiquidity.selector);
176+
if (expectBadFeeRecipient) vm.expectRevert(EulerSwapManagement.BadFeeRecipient.selector);
175177
bytes memory result = IEVC(evc).call(
176178
address(eulerSwapFactory),
177179
sParams.eulerAccount,
178180
0,
179181
abi.encodeCall(EulerSwapFactory.deployPool, (sParams, dParams, initialState, salt))
180182
);
181-
if (expectAccountLiquidityRevert) return EulerSwap(address(0)); // Just to return to test
183+
if (expectAccountLiquidityRevert || expectBadFeeRecipient) return EulerSwap(address(0)); // Just to return to test
182184
EulerSwap eulerSwap = EulerSwap(abi.decode(result, (address)));
183185

184186
vm.prank(holder);

test/Fees.t.sol

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,23 @@ contract FeesTest is EulerSwapTestBase {
163163
assertEq(assetTST.balanceOf(address(54321)), amountIn - amountInNoFees);
164164
}
165165

166+
function test_altFeeRecipient_subAccount() public {
167+
address recipient = makeAddr("feeRecipient");
168+
169+
// Register owner with EVC
170+
vm.prank(recipient);
171+
evc.enableCollateral(recipient, address(0));
172+
173+
address subAccount = address(uint160(recipient) ^ 1);
174+
175+
(IEulerSwap.StaticParams memory sParams, IEulerSwap.DynamicParams memory dParams) =
176+
getEulerSwapParams(60e18, 60e18, 1e18, 1e18, 0.9e18, 0.9e18, 0.01e18, subAccount);
177+
IEulerSwap.InitialState memory initialState = IEulerSwap.InitialState({reserve0: 60e18, reserve1: 60e18});
178+
179+
expectBadFeeRecipient = true;
180+
eulerSwap = createEulerSwapFull(sParams, dParams, initialState);
181+
}
182+
166183
function test_fees_protocolFees_swap() public {
167184
uint256 fee = 0.05e18;
168185
uint256 protocolFee = 0.1e18;

0 commit comments

Comments
 (0)