Skip to content

Commit e37d138

Browse files
authored
Add events for initial aggregate pool fees (#1250)
1 parent 767a6a1 commit e37d138

File tree

3 files changed

+92
-0
lines changed

3 files changed

+92
-0
lines changed

pkg/interfaces/contracts/vault/IProtocolFeeController.sol

+30
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,36 @@ interface IProtocolFeeController {
9595
uint256 amount
9696
);
9797

98+
/**
99+
* @notice Emitted on pool registration with the initial aggregate swap fee percentage, for off-chain processes.
100+
* @dev If the pool is registered as protocol fee exempt, this will be zero (until changed). Otherwise, it will
101+
* equal the current global swap fee percentage.
102+
*
103+
* @param pool The pool being registered
104+
* @param aggregateSwapFeePercentage The initial aggregate swap fee percentage
105+
* @param isProtocolFeeExempt True if the pool is exempt from taking protocol fees initially
106+
*/
107+
event InitialPoolAggregateSwapFeePercentage(
108+
address indexed pool,
109+
uint256 aggregateSwapFeePercentage,
110+
bool isProtocolFeeExempt
111+
);
112+
113+
/**
114+
* @notice Emitted on pool registration with the initial aggregate yield fee percentage, for off-chain processes.
115+
* @dev If the pool is registered as protocol fee exempt, this will be zero (until changed). Otherwise, it will
116+
* equal the current global yield fee percentage.
117+
*
118+
* @param pool The pool being registered
119+
* @param aggregateYieldFeePercentage The initial aggregate yield fee percentage
120+
* @param isProtocolFeeExempt True if the pool is exempt from taking protocol fees initially
121+
*/
122+
event InitialPoolAggregateYieldFeePercentage(
123+
address indexed pool,
124+
uint256 aggregateYieldFeePercentage,
125+
bool isProtocolFeeExempt
126+
);
127+
98128
/**
99129
* @notice Error raised when the protocol swap fee percentage exceeds the maximum allowed value.
100130
* @dev Note that this is checked for both the global and pool-specific protocol swap fee percentages.

pkg/vault/contracts/ProtocolFeeController.sol

+4
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,10 @@ contract ProtocolFeeController is
408408
feePercentage: aggregateYieldFeePercentage.toUint64(),
409409
isOverride: protocolFeeExempt
410410
});
411+
412+
// Allow tracking pool fee percentages in all cases (e.g., when the pool is protocol-fee exempt).
413+
emit InitialPoolAggregateSwapFeePercentage(pool, aggregateSwapFeePercentage, protocolFeeExempt);
414+
emit InitialPoolAggregateYieldFeePercentage(pool, aggregateYieldFeePercentage, protocolFeeExempt);
411415
}
412416

413417
/// @inheritdoc IProtocolFeeController

pkg/vault/test/foundry/ProtocolFeeController.t.sol

+58
Original file line numberDiff line numberDiff line change
@@ -1265,6 +1265,64 @@ contract ProtocolFeeControllerTest is BaseVaultTest {
12651265
);
12661266
}
12671267

1268+
function testPoolRegistrationEventsExempt() public {
1269+
TokenConfig[] memory tokenConfig = new TokenConfig[](2);
1270+
tokenConfig[daiIdx].token = IERC20(dai);
1271+
tokenConfig[usdcIdx].token = IERC20(usdc);
1272+
1273+
PoolRoleAccounts memory roleAccounts;
1274+
1275+
pool = address(deployPoolMock(IVault(address(vault)), "Exempt Pool", "EXEMPT"));
1276+
1277+
vm.expectEmit();
1278+
emit IProtocolFeeController.InitialPoolAggregateSwapFeePercentage(pool, 0, true);
1279+
1280+
vm.expectEmit();
1281+
emit IProtocolFeeController.InitialPoolAggregateYieldFeePercentage(pool, 0, true);
1282+
1283+
PoolFactoryMock(poolFactory).registerGeneralTestPool(
1284+
pool,
1285+
tokenConfig,
1286+
0,
1287+
365 days,
1288+
true, // exempt from protocol fees
1289+
roleAccounts,
1290+
address(0)
1291+
);
1292+
}
1293+
1294+
function testPoolRegistrationEventsNonExempt() public {
1295+
authorizer.grantRole(
1296+
feeControllerAuth.getActionId(IProtocolFeeController.setGlobalProtocolSwapFeePercentage.selector),
1297+
admin
1298+
);
1299+
authorizer.grantRole(
1300+
feeControllerAuth.getActionId(IProtocolFeeController.setGlobalProtocolYieldFeePercentage.selector),
1301+
admin
1302+
);
1303+
1304+
vm.startPrank(admin);
1305+
feeController.setGlobalProtocolSwapFeePercentage(MAX_PROTOCOL_SWAP_FEE_PCT);
1306+
feeController.setGlobalProtocolYieldFeePercentage(MAX_PROTOCOL_YIELD_FEE_PCT);
1307+
vm.stopPrank();
1308+
1309+
TokenConfig[] memory tokenConfig = new TokenConfig[](2);
1310+
tokenConfig[daiIdx].token = IERC20(dai);
1311+
tokenConfig[usdcIdx].token = IERC20(usdc);
1312+
1313+
PoolRoleAccounts memory roleAccounts;
1314+
1315+
pool = address(deployPoolMock(IVault(address(vault)), "Exempt Pool", "EXEMPT"));
1316+
1317+
vm.expectEmit();
1318+
emit IProtocolFeeController.InitialPoolAggregateSwapFeePercentage(pool, MAX_PROTOCOL_SWAP_FEE_PCT, false);
1319+
1320+
vm.expectEmit();
1321+
emit IProtocolFeeController.InitialPoolAggregateYieldFeePercentage(pool, MAX_PROTOCOL_YIELD_FEE_PCT, false);
1322+
1323+
PoolFactoryMock(poolFactory).registerTestPool(pool, tokenConfig);
1324+
}
1325+
12681326
function _registerPoolWithMaxProtocolFees() internal {
12691327
authorizer.grantRole(
12701328
feeControllerAuth.getActionId(IProtocolFeeController.setGlobalProtocolSwapFeePercentage.selector),

0 commit comments

Comments
 (0)