From 7801c7855d80514dc74b680c6f488c6b57ca562d Mon Sep 17 00:00:00 2001 From: chef-burger <137024020+chefburger@users.noreply.github.com> Date: Tue, 22 Oct 2024 11:45:23 +0800 Subject: [PATCH] chore: improve comments (#192) --- src/Vault.sol | 1 + src/interfaces/IVault.sol | 3 ++- src/libraries/math/UnsafeMath.sol | 4 ++-- src/pool-bin/libraries/BinHooks.sol | 2 ++ src/pool-cl/interfaces/ICLHooks.sol | 2 +- src/pool-cl/libraries/CLHooks.sol | 2 ++ src/pool-cl/libraries/Tick.sol | 4 +++- 7 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Vault.sol b/src/Vault.sol index 6e67f64..853fedd 100644 --- a/src/Vault.sol +++ b/src/Vault.sol @@ -179,6 +179,7 @@ contract Vault is IVault, VaultToken, Ownable { } } + // if settling native, integrators should still call `sync` first to avoid DoS attack vectors function _settle(address recipient) internal returns (uint256 paid) { (Currency currency, uint256 reservesBefore) = VaultReserve.getVaultReserve(); if (!currency.isNative()) { diff --git a/src/interfaces/IVault.sol b/src/interfaces/IVault.sol index 3e938e7..98e4abc 100644 --- a/src/interfaces/IVault.sol +++ b/src/interfaces/IVault.sol @@ -72,7 +72,8 @@ interface IVault is IVaultToken { function accountAppBalanceDelta(Currency currency, int128 delta, address settler) external; /// @notice Called by the user to net out some value owed to the user - /// @dev Can also be used as a mechanism for _free_ flash loans + /// @dev Will revert if the requested amount is not available, consider using `mint` instead + /// @dev Can also be used as a mechanism for free flash loans function take(Currency currency, address to, uint256 amount) external; /// @notice Writes the current ERC20 balance of the specified currency to transient storage diff --git a/src/libraries/math/UnsafeMath.sol b/src/libraries/math/UnsafeMath.sol index 969b279..f278bba 100644 --- a/src/libraries/math/UnsafeMath.sol +++ b/src/libraries/math/UnsafeMath.sol @@ -6,7 +6,7 @@ pragma solidity ^0.8.0; /// @notice Contains methods that perform common math functions but do not do any overflow or underflow checks library UnsafeMath { /// @notice Returns ceil(x / y) - /// @dev division by 0 has unspecified behavior, and must be checked externally + /// @dev division by 0 will return 0, and should be checked externally /// @param x The dividend /// @param y The divisor /// @return z The quotient, ceil(x / y) @@ -17,7 +17,7 @@ library UnsafeMath { } /// @notice Calculates floor(a×b÷denominator) - /// @dev division by 0 has unspecified behavior, and must be checked externally + /// @dev division by 0 will return 0, and should be checked externally /// @param a The multiplicand /// @param b The multiplier /// @param denominator The divisor diff --git a/src/pool-bin/libraries/BinHooks.sol b/src/pool-bin/libraries/BinHooks.sol index db6524f..d4e2539 100644 --- a/src/pool-bin/libraries/BinHooks.sol +++ b/src/pool-bin/libraries/BinHooks.sol @@ -163,6 +163,8 @@ library BinHooks { // A length of 96 bytes is required to return a bytes4, a 32 byte delta, and an LP fee if (result.length != 96) revert Hooks.InvalidHookResponse(); + // dynamic fee pools that want to override the cache fee, return a valid fee with the override flag. If override flag + // is set but an invalid fee is returned, the transaction will revert. Otherwise the current LP fee will be used if (key.fee.isDynamicLPFee()) { lpFeeOverride = result.parseFee(); } diff --git a/src/pool-cl/interfaces/ICLHooks.sol b/src/pool-cl/interfaces/ICLHooks.sol index 0376ae3..865ae10 100644 --- a/src/pool-cl/interfaces/ICLHooks.sol +++ b/src/pool-cl/interfaces/ICLHooks.sol @@ -93,7 +93,7 @@ interface ICLHooks is IHooks { /// @param sender The initial msg.sender for the remove liquidity call /// @param key The key for the pool /// @param params The parameters for removing liquidity - /// @param delta The caller's balance delta after adding liquidity; the sum of principal delta, fees accrued, and hook delta + /// @param delta The caller's balance delta after remvoing liquidity; the sum of principal delta, fees accrued, and hook delta /// @param feesAccrued The fees accrued since the last time fees were collected from this position /// @param hookData Arbitrary data handed into the PoolManager by the liquidty provider to be be passed on to the hook /// @return bytes4 The function selector for the hook diff --git a/src/pool-cl/libraries/CLHooks.sol b/src/pool-cl/libraries/CLHooks.sol index f5db439..8f943d8 100644 --- a/src/pool-cl/libraries/CLHooks.sol +++ b/src/pool-cl/libraries/CLHooks.sol @@ -140,6 +140,8 @@ library CLHooks { // A length of 96 bytes is required to return a bytes4, a 32 byte delta, and an LP fee if (result.length != 96) revert Hooks.InvalidHookResponse(); + // dynamic fee pools that want to override the cache fee, return a valid fee with the override flag. If override flag + // is set but an invalid fee is returned, the transaction will revert. Otherwise the current LP fee will be used if (key.fee.isDynamicLPFee()) { lpFeeOverride = result.parseFee(); } diff --git a/src/pool-cl/libraries/Tick.sol b/src/pool-cl/libraries/Tick.sol index cc5af59..8c6b41d 100644 --- a/src/pool-cl/libraries/Tick.sol +++ b/src/pool-cl/libraries/Tick.sol @@ -54,6 +54,7 @@ library Tick { function tickSpacingToMaxLiquidityPerTick(int24 tickSpacing) internal pure returns (uint128 result) { // Equivalent to v3 but in assembly for gas efficiency: // int24 minTick = (TickMath.MIN_TICK / tickSpacing); + // if (TickMath.MIN_TICK % tickSpacing != 0) minTick--; // int24 maxTick = (TickMath.MAX_TICK / tickSpacing); // uint24 numTicks = maxTick - minTick + 1; // return type(uint128).max / numTicks; @@ -162,7 +163,8 @@ library Tick { } } - // when the lower (upper) tick is crossed left to right (right to left), liquidity must be added (removed) + // when the lower (upper) tick is crossed left to right, liquidity must be added (removed) + // when the lower (upper) tick is crossed right to left, liquidity must be removed (added) int128 liquidityNetAfter = upper ? (liquidityNetBefore - liquidityDelta) : (liquidityNetBefore + liquidityDelta); // update two members in one go