Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add events for initial aggregate pool fees #1250

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions pkg/interfaces/contracts/vault/IProtocolFeeController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,36 @@ interface IProtocolFeeController {
uint256 amount
);

/**
* @notice Emitted on pool registration with the initial aggregate swap fee percentage, for off-chain processes.
* @dev If the pool is registered as protocol fee exempt, this will be zero (until changed). Otherwise, it will
* equal the current global swap fee percentage.
*
* @param pool The pool being registered
* @param aggregateSwapFeePercentage The initial aggregate swap fee percentage
* @param isProtocolFeeExempt True if the pool is exempt from taking protocol fees initially
*/
event InitialPoolAggregateSwapFeePercentage(
address indexed pool,
uint256 aggregateSwapFeePercentage,
bool isProtocolFeeExempt
);

/**
* @notice Emitted on pool registration with the initial aggregate yield fee percentage, for off-chain processes.
* @dev If the pool is registered as protocol fee exempt, this will be zero (until changed). Otherwise, it will
* equal the current global yield fee percentage.
*
* @param pool The pool being registered
* @param aggregateYieldFeePercentage The initial aggregate yield fee percentage
* @param isProtocolFeeExempt True if the pool is exempt from taking protocol fees initially
*/
event InitialPoolAggregateYieldFeePercentage(
address indexed pool,
uint256 aggregateYieldFeePercentage,
bool isProtocolFeeExempt
);

/**
* @notice Error raised when the protocol swap fee percentage exceeds the maximum allowed value.
* @dev Note that this is checked for both the global and pool-specific protocol swap fee percentages.
Expand Down
4 changes: 4 additions & 0 deletions pkg/vault/contracts/ProtocolFeeController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,10 @@ contract ProtocolFeeController is
feePercentage: aggregateYieldFeePercentage.toUint64(),
isOverride: protocolFeeExempt
});

// Allow tracking pool fee percentages in all cases (e.g., when the pool is protocol-fee exempt).
emit InitialPoolAggregateSwapFeePercentage(pool, aggregateSwapFeePercentage, protocolFeeExempt);
emit InitialPoolAggregateYieldFeePercentage(pool, aggregateYieldFeePercentage, protocolFeeExempt);
}

/// @inheritdoc IProtocolFeeController
Expand Down
58 changes: 58 additions & 0 deletions pkg/vault/test/foundry/ProtocolFeeController.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1265,6 +1265,64 @@ contract ProtocolFeeControllerTest is BaseVaultTest {
);
}

function testPoolRegistrationEventsExempt() public {
TokenConfig[] memory tokenConfig = new TokenConfig[](2);
tokenConfig[daiIdx].token = IERC20(dai);
tokenConfig[usdcIdx].token = IERC20(usdc);

PoolRoleAccounts memory roleAccounts;

pool = address(deployPoolMock(IVault(address(vault)), "Exempt Pool", "EXEMPT"));

vm.expectEmit();
emit IProtocolFeeController.InitialPoolAggregateSwapFeePercentage(pool, 0, true);

vm.expectEmit();
emit IProtocolFeeController.InitialPoolAggregateYieldFeePercentage(pool, 0, true);

PoolFactoryMock(poolFactory).registerGeneralTestPool(
pool,
tokenConfig,
0,
365 days,
true, // exempt from protocol fees
roleAccounts,
address(0)
);
}

function testPoolRegistrationEventsNonExempt() public {
authorizer.grantRole(
feeControllerAuth.getActionId(IProtocolFeeController.setGlobalProtocolSwapFeePercentage.selector),
admin
);
authorizer.grantRole(
feeControllerAuth.getActionId(IProtocolFeeController.setGlobalProtocolYieldFeePercentage.selector),
admin
);

vm.startPrank(admin);
feeController.setGlobalProtocolSwapFeePercentage(MAX_PROTOCOL_SWAP_FEE_PCT);
feeController.setGlobalProtocolYieldFeePercentage(MAX_PROTOCOL_YIELD_FEE_PCT);
vm.stopPrank();

TokenConfig[] memory tokenConfig = new TokenConfig[](2);
tokenConfig[daiIdx].token = IERC20(dai);
tokenConfig[usdcIdx].token = IERC20(usdc);

PoolRoleAccounts memory roleAccounts;

pool = address(deployPoolMock(IVault(address(vault)), "Exempt Pool", "EXEMPT"));

vm.expectEmit();
emit IProtocolFeeController.InitialPoolAggregateSwapFeePercentage(pool, MAX_PROTOCOL_SWAP_FEE_PCT, false);

vm.expectEmit();
emit IProtocolFeeController.InitialPoolAggregateYieldFeePercentage(pool, MAX_PROTOCOL_YIELD_FEE_PCT, false);

PoolFactoryMock(poolFactory).registerTestPool(pool, tokenConfig);
}

function _registerPoolWithMaxProtocolFees() internal {
authorizer.grantRole(
feeControllerAuth.getActionId(IProtocolFeeController.setGlobalProtocolSwapFeePercentage.selector),
Expand Down