Skip to content

Commit

Permalink
Run forge fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
0xVolosnikov committed May 14, 2024
1 parent 24cf25e commit b457246
Show file tree
Hide file tree
Showing 4 changed files with 187 additions and 513 deletions.
204 changes: 60 additions & 144 deletions src/PoolManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,7 @@ import {Extsload} from "./Extsload.sol";

/// @notice Holds the state for all pools

contract PoolManager is
IPoolManager,
ProtocolFees,
NoDelegateCall,
ERC6909Claims,
Extsload
{
contract PoolManager is IPoolManager, ProtocolFees, NoDelegateCall, ERC6909Claims, Extsload {
using PoolIdLibrary for PoolKey;
using SafeCast for *;
using Pool for *;
Expand All @@ -55,67 +49,48 @@ contract PoolManager is

constructor(uint256 controllerGasLimit) ProtocolFees(controllerGasLimit) {}

function _getPool(
PoolId id
) internal view override returns (Pool.State storage) {
function _getPool(PoolId id) internal view override returns (Pool.State storage) {
return pools[id];
}

/// @inheritdoc IPoolManager
function getSlot0(
PoolId id
)
function getSlot0(PoolId id)
external
view
override
returns (
uint160 sqrtPriceX96,
int24 tick,
uint24 protocolFee,
uint24 lpFee
)
returns (uint160 sqrtPriceX96, int24 tick, uint24 protocolFee, uint24 lpFee)
{
Slot0Packed slot0 = pools[id].slot0.loadPacked();

return (
slot0.sqrtPriceX96(),
slot0.tick(),
slot0.protocolFee(),
slot0.lpFee()
);
return (slot0.sqrtPriceX96(), slot0.tick(), slot0.protocolFee(), slot0.lpFee());
}

/// @inheritdoc IPoolManager
function getLiquidity(
PoolId id
) external view override returns (uint128 liquidity) {
function getLiquidity(PoolId id) external view override returns (uint128 liquidity) {
return pools[id].liquidity;
}

/// @inheritdoc IPoolManager
function getLiquidity(
PoolId id,
address _owner,
int24 tickLower,
int24 tickUpper
) external view override returns (uint128 liquidity) {
function getLiquidity(PoolId id, address _owner, int24 tickLower, int24 tickUpper)
external
view
override
returns (uint128 liquidity)
{
return pools[id].positions.get(_owner, tickLower, tickUpper).liquidity;
}

function getPosition(
PoolId id,
address _owner,
int24 tickLower,
int24 tickUpper
) external view override returns (Position.Info memory position) {
function getPosition(PoolId id, address _owner, int24 tickLower, int24 tickUpper)
external
view
override
returns (Position.Info memory position)
{
return pools[id].positions.get(_owner, tickLower, tickUpper);
}

/// @inheritdoc IPoolManager
function currencyDelta(
address caller,
Currency currency
) external view returns (int256) {
function currencyDelta(address caller, Currency currency) external view returns (int256) {
return currency.getDelta(caller);
}

Expand All @@ -131,18 +106,21 @@ contract PoolManager is
}

/// @inheritdoc IPoolManager
function initialize(
PoolKey memory key,
uint160 sqrtPriceX96,
bytes calldata hookData
) external override noDelegateCall returns (int24 tick) {
function initialize(PoolKey memory key, uint160 sqrtPriceX96, bytes calldata hookData)
external
override
noDelegateCall
returns (int24 tick)
{
// see TickBitmap.sol for overflow conditions that can arise from tick spacing being too large
if (key.tickSpacing > MAX_TICK_SPACING) revert TickSpacingTooLarge();
if (key.tickSpacing < MIN_TICK_SPACING) revert TickSpacingTooSmall();
if (key.currency0 >= key.currency1)
if (key.currency0 >= key.currency1) {
revert CurrenciesOutOfOrderOrEqual();
if (!key.hooks.isValidHookAddress(key.fee))
}
if (!key.hooks.isValidHookAddress(key.fee)) {
revert Hooks.HookAddressNotValid(address(key.hooks));
}

uint24 lpFee = key.fee.getInitialLPFee();

Expand All @@ -156,20 +134,11 @@ contract PoolManager is
key.hooks.afterInitialize(key, sqrtPriceX96, tick, hookData);

// On intitalize we emit the key's fee, which tells us all fee settings a pool can have: either a static swap fee or dynamic swap fee and if the hook has enabled swap or withdraw fees.
emit Initialize(
id,
key.currency0,
key.currency1,
key.fee,
key.tickSpacing,
key.hooks
);
emit Initialize(id, key.currency0, key.currency1, key.fee, key.tickSpacing, key.hooks);
}

/// @inheritdoc IPoolManager
function unlock(
bytes calldata data
) external override noDelegateCall returns (bytes memory result) {
function unlock(bytes calldata data) external override noDelegateCall returns (bytes memory result) {
if (Lock.isUnlocked()) revert AlreadyUnlocked();

Lock.unlock();
Expand Down Expand Up @@ -203,10 +172,7 @@ contract PoolManager is
}

/// @dev Accumulates a balance change to a map of currency to balance changes
function _accountPoolBalanceDelta(
PoolKey memory key,
BalanceDelta delta
) internal {
function _accountPoolBalanceDelta(PoolKey memory key, BalanceDelta delta) internal {
_accountDelta(key.currency0, delta.amount0());
_accountDelta(key.currency1, delta.amount1());
}
Expand All @@ -220,12 +186,7 @@ contract PoolManager is
PoolKey memory key,
IPoolManager.ModifyLiquidityParams memory params,
bytes calldata hookData
)
external
override
onlyWhenUnlocked
returns (BalanceDelta delta, BalanceDelta feeDelta)
{
) external override onlyWhenUnlocked returns (BalanceDelta delta, BalanceDelta feeDelta) {
PoolId id = key.toId();
_checkPoolInitialized(id);

Expand All @@ -243,23 +204,18 @@ contract PoolManager is

_accountPoolBalanceDelta(key, delta + feeDelta);

emit ModifyLiquidity(
id,
msg.sender,
params.tickLower,
params.tickUpper,
params.liquidityDelta
);
emit ModifyLiquidity(id, msg.sender, params.tickLower, params.tickUpper, params.liquidityDelta);

key.hooks.afterModifyLiquidity(key, params, delta, hookData);
}

/// @inheritdoc IPoolManager
function swap(
PoolKey memory key,
IPoolManager.SwapParams memory params,
bytes calldata hookData
) external override onlyWhenUnlocked returns (BalanceDelta delta) {
function swap(PoolKey memory key, IPoolManager.SwapParams memory params, bytes calldata hookData)
external
override
onlyWhenUnlocked
returns (BalanceDelta delta)
{
PoolId id = key.toId();
_checkPoolInitialized(id);

Expand All @@ -281,33 +237,23 @@ contract PoolManager is

// The fee is on the input currency.
if (feeForProtocol > 0) {
_updateProtocolFees(
params.zeroForOne ? key.currency0 : key.currency1,
feeForProtocol
);
_updateProtocolFees(params.zeroForOne ? key.currency0 : key.currency1, feeForProtocol);
}

emit Swap(
id,
msg.sender,
delta.amount0(),
delta.amount1(),
state.sqrtPriceX96,
state.liquidity,
state.tick,
swapFee
id, msg.sender, delta.amount0(), delta.amount1(), state.sqrtPriceX96, state.liquidity, state.tick, swapFee
);

key.hooks.afterSwap(key, params, delta, hookData);
}

/// @inheritdoc IPoolManager
function donate(
PoolKey memory key,
uint256 amount0,
uint256 amount1,
bytes calldata hookData
) external override onlyWhenUnlocked returns (BalanceDelta delta) {
function donate(PoolKey memory key, uint256 amount0, uint256 amount1, bytes calldata hookData)
external
override
onlyWhenUnlocked
returns (BalanceDelta delta)
{
PoolId id = key.toId();
_checkPoolInitialized(id);

Expand All @@ -321,11 +267,7 @@ contract PoolManager is
}

/// @inheritdoc IPoolManager
function take(
Currency currency,
address to,
uint256 amount
) external override onlyWhenUnlocked {
function take(Currency currency, address to, uint256 amount) external override onlyWhenUnlocked {
unchecked {
// subtraction must be safe
_accountDelta(currency, -(amount.toInt128()));
Expand All @@ -334,9 +276,7 @@ contract PoolManager is
}

/// @inheritdoc IPoolManager
function settle(
Currency currency
) external payable override onlyWhenUnlocked returns (uint256 paid) {
function settle(Currency currency) external payable override onlyWhenUnlocked returns (uint256 paid) {
if (currency.isNative()) {
paid = msg.value;
} else {
Expand All @@ -349,11 +289,7 @@ contract PoolManager is
}

/// @inheritdoc IPoolManager
function mint(
address to,
uint256 id,
uint256 amount
) external override onlyWhenUnlocked {
function mint(address to, uint256 id, uint256 amount) external override onlyWhenUnlocked {
unchecked {
// subtraction must be safe
_accountDelta(CurrencyLibrary.fromId(id), -(amount.toInt128()));
Expand All @@ -362,58 +298,38 @@ contract PoolManager is
}

/// @inheritdoc IPoolManager
function burn(
address from,
uint256 id,
uint256 amount
) external override onlyWhenUnlocked {
function burn(address from, uint256 id, uint256 amount) external override onlyWhenUnlocked {
_accountDelta(CurrencyLibrary.fromId(id), amount.toInt128());
_burnFrom(from, id, amount);
}

function updateDynamicLPFee(
PoolKey memory key,
uint24 newDynamicLPFee
) external {
if (!key.fee.isDynamicFee() || msg.sender != address(key.hooks))
function updateDynamicLPFee(PoolKey memory key, uint24 newDynamicLPFee) external {
if (!key.fee.isDynamicFee() || msg.sender != address(key.hooks)) {
revert UnauthorizedDynamicLPFeeUpdate();
}
newDynamicLPFee.validate();
PoolId id = key.toId();
pools[id].setLPFee(newDynamicLPFee);
}

function getNonzeroDeltaCount()
external
view
returns (uint256 _nonzeroDeltaCount)
{
function getNonzeroDeltaCount() external view returns (uint256 _nonzeroDeltaCount) {
return NonZeroDeltaCount.read();
}

function getPoolTickInfo(
PoolId id,
int24 tick
) external view returns (Pool.TickInfo memory) {
function getPoolTickInfo(PoolId id, int24 tick) external view returns (Pool.TickInfo memory) {
return pools[id].getPoolTickInfo(tick);
}

function getPoolBitmapInfo(
PoolId id,
int16 word
) external view returns (uint256 tickBitmap) {
function getPoolBitmapInfo(PoolId id, int16 word) external view returns (uint256 tickBitmap) {
return pools[id].getPoolBitmapInfo(word);
}

/// @notice Temporary view function. Replaceable by transient EXTSLOAD.
function getReserves(
Currency currency
) external view returns (uint256 balance) {
function getReserves(Currency currency) external view returns (uint256 balance) {
return currency.getReserves();
}

function getFeeGrowthGlobals(
PoolId id
)
function getFeeGrowthGlobals(PoolId id)
external
view
returns (uint256 feeGrowthGlobal0x128, uint256 feeGrowthGlobal1x128)
Expand Down
Loading

0 comments on commit b457246

Please sign in to comment.