Skip to content

Commit

Permalink
Remove unused HooksConfigLib arguments (#698)
Browse files Browse the repository at this point in the history
  • Loading branch information
EndymionJkb authored Jul 1, 2024
1 parent a6eb7e1 commit b24dfc7
Show file tree
Hide file tree
Showing 15 changed files with 23 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
179.6k
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
197.4k
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
211.7k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
170.4k
168.7k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
188.6k
186.9k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
210.4k
208.7k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
236.8k
235.0k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
201.3k
199.6k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
230.2k
228.4k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
225.6k
223.9k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
190.5k
188.8k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
212.3k
210.6k
14 changes: 8 additions & 6 deletions pkg/vault/contracts/Vault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ contract Vault is IVaultMain, VaultCommon, Proxy {
IBasePool.PoolSwapParams memory swapParams = _buildPoolSwapParams(params, state, poolData);

if (poolData.poolConfigBits.shouldCallBeforeSwap()) {
poolData.poolConfigBits.callBeforeSwapHook(swapParams, params.pool, _hooksContracts[params.pool]);
HooksConfigLib.callBeforeSwapHook(swapParams, params.pool, _hooksContracts[params.pool]);

// The call to `onBeforeSwap` could potentially update token rates and balances.
// We update `poolData.tokenRates`, `poolData.rawBalances` and `poolData.balancesLiveScaled18`
Expand All @@ -222,9 +222,11 @@ contract Vault is IVaultMain, VaultCommon, Proxy {
// to be used unless the pool has a dynamic swap fee. It is also passed into the hook, to support common cases
// where the dynamic fee computation logic uses it.
if (poolData.poolConfigBits.shouldCallComputeDynamicSwapFee()) {
(bool dynamicSwapFeeCalculated, uint256 dynamicSwapFee) = poolData
.poolConfigBits
.callComputeDynamicSwapFeeHook(swapParams, state.swapFeePercentage, _hooksContracts[params.pool]);
(bool dynamicSwapFeeCalculated, uint256 dynamicSwapFee) = HooksConfigLib.callComputeDynamicSwapFeeHook(
swapParams,
state.swapFeePercentage,
_hooksContracts[params.pool]
);

if (dynamicSwapFeeCalculated) {
state.swapFeePercentage = dynamicSwapFee;
Expand Down Expand Up @@ -536,7 +538,7 @@ contract Vault is IVaultMain, VaultCommon, Proxy {
);

if (poolData.poolConfigBits.shouldCallBeforeAddLiquidity()) {
poolData.poolConfigBits.callBeforeAddLiquidityHook(
HooksConfigLib.callBeforeAddLiquidityHook(
msg.sender,
maxAmountsInScaled18,
params,
Expand Down Expand Up @@ -774,7 +776,7 @@ contract Vault is IVaultMain, VaultCommon, Proxy {

// Uses msg.sender as the router (the contract that called the vault)
if (poolData.poolConfigBits.shouldCallBeforeRemoveLiquidity()) {
poolData.poolConfigBits.callBeforeRemoveLiquidityHook(
HooksConfigLib.callBeforeRemoveLiquidityHook(
minAmountsOutScaled18,
msg.sender,
params,
Expand Down
11 changes: 3 additions & 8 deletions pkg/vault/contracts/VaultExtension.sol
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ contract VaultExtension is IVaultExtension, VaultCommon, Proxy {
);

if (poolData.poolConfigBits.shouldCallBeforeInitialize()) {
poolData.poolConfigBits.callBeforeInitializeHook(exactAmountsInScaled18, userData, _hooksContracts[pool]);
HooksConfigLib.callBeforeInitializeHook(exactAmountsInScaled18, userData, _hooksContracts[pool]);
// The before hook is reentrant, and could have changed token rates.
// Updating balances here is unnecessary since they're 0, but we do not special case before init
// for the sake of bytecode size.
Expand All @@ -407,12 +407,7 @@ contract VaultExtension is IVaultExtension, VaultCommon, Proxy {
// fix stack too deep
IHooks hooksContract = _hooksContracts[pool];

poolData.poolConfigBits.callAfterInitializeHook(
exactAmountsInScaled18,
bptAmountOut,
userData,
hooksContract
);
HooksConfigLib.callAfterInitializeHook(exactAmountsInScaled18, bptAmountOut, userData, hooksContract);
}
}

Expand Down Expand Up @@ -620,7 +615,7 @@ contract VaultExtension is IVaultExtension, VaultCommon, Proxy {
IBasePool.PoolSwapParams memory swapParams
) external view onlyVaultDelegateCall withInitializedPool(pool) returns (bool success, uint256 dynamicSwapFee) {
return
_poolConfigBits[pool].callComputeDynamicSwapFeeHook(
HooksConfigLib.callComputeDynamicSwapFeeHook(
swapParams,
_poolConfigBits[pool].getStaticSwapFeePercentage(),
_hooksContracts[pool]
Expand Down
12 changes: 0 additions & 12 deletions pkg/vault/contracts/lib/HooksConfigLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,13 @@ library HooksConfigLib {
* @dev Check if dynamic swap fee hook should be called and call it. Throws an error if the hook contract fails to
* execute the hook.
*
* @param config config The encoded pool configuration
* @param swapParams The swap parameters used to calculate the fee
* @param staticSwapFeePercentage Value of the static swap fee, for reference
* @param hooksContract Storage slot with the address of the hooks contract
* @return success false if hook is disabled, true if hooks is enabled and succeeded to execute
* @return swapFeePercentage the calculated swap fee percentage. 0 if hook is disabled
*/
function callComputeDynamicSwapFeeHook(
PoolConfigBits config,
IBasePool.PoolSwapParams memory swapParams,
uint256 staticSwapFeePercentage,
IHooks hooksContract
Expand All @@ -183,13 +181,11 @@ library HooksConfigLib {
* @dev Check if before swap hook should be called and call it. Throws an error if the hook contract fails to
* execute the hook.
*
* @param config The encoded pool configuration
* @param swapParams The swap parameters used in the hook
* @param pool Pool address
* @param hooksContract Storage slot with the address of the hooks contract
*/
function callBeforeSwapHook(
PoolConfigBits config,
IBasePool.PoolSwapParams memory swapParams,
address pool,
IHooks hooksContract
Expand Down Expand Up @@ -270,15 +266,13 @@ library HooksConfigLib {
* @dev Check if before add liquidity hook should be called and call it. Throws an error if the hook contract fails
* to execute the hook.
*
* @param config The encoded pool configuration
* @param router Router address
* @param maxAmountsInScaled18 An array with maximum amounts for each input token of the add liquidity operation
* @param params The add liquidity parameters
* @param poolData Struct containing balance and token information of the pool
* @param hooksContract Storage slot with the address of the hooks contract
*/
function callBeforeAddLiquidityHook(
PoolConfigBits config,
address router,
uint256[] memory maxAmountsInScaled18,
AddLiquidityParams memory params,
Expand Down Expand Up @@ -361,15 +355,13 @@ library HooksConfigLib {
* @dev Check if before remove liquidity hook should be called and call it. Throws an error if the hook contract
* fails to execute the hook.
*
* @param config The encoded pool configuration
* @param minAmountsOutScaled18 Minimum amounts for each output token of the remove liquidity operation
* @param router Router address
* @param params The remove liquidity parameters
* @param poolData Struct containing balance and token information of the pool
* @param hooksContract Storage slot with the address of the hooks contract
*/
function callBeforeRemoveLiquidityHook(
PoolConfigBits config,
uint256[] memory minAmountsOutScaled18,
address router,
RemoveLiquidityParams memory params,
Expand Down Expand Up @@ -452,13 +444,11 @@ library HooksConfigLib {
* @dev Check if before initialization hook should be called and call it. Throws an error if the hook contract
* fails to execute the hook.
*
* @param config The encoded pool configuration
* @param exactAmountsInScaled18 An array with the initial liquidity of the pool
* @param userData Additional (optional) data required for adding initial liquidity
* @param hooksContract Storage slot with the address of the hooks contract
*/
function callBeforeInitializeHook(
PoolConfigBits config,
uint256[] memory exactAmountsInScaled18,
bytes memory userData,
IHooks hooksContract
Expand All @@ -472,14 +462,12 @@ library HooksConfigLib {
* @dev Check if after initialization hook should be called and call it. Throws an error if the hook contract
* fails to execute the hook.
*
* @param config The encoded pool configuration
* @param exactAmountsInScaled18 An array with the initial liquidity of the pool
* @param bptAmountOut The BPT amount a user will receive after initialization operation succeeds
* @param userData Additional (optional) data required for adding initial liquidity
* @param hooksContract Storage slot with the address of the hooks contract
*/
function callAfterInitializeHook(
PoolConfigBits config,
uint256[] memory exactAmountsInScaled18,
uint256 bptAmountOut,
bytes memory userData,
Expand Down

0 comments on commit b24dfc7

Please sign in to comment.