Skip to content

Commit

Permalink
Run fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
0xVolosnikov committed May 16, 2024
1 parent 2d4e5f0 commit 48dc19a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
12 changes: 5 additions & 7 deletions src/libraries/Pool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,8 @@ library Pool {

tick = TickMath.getTickAtSqrtPrice(sqrtPriceX96);

self.slot0 =
Slot0.wrap(bytes32(0))
.setSqrtPriceX96(sqrtPriceX96)
.setTick(tick)
.setProtocolFee(protocolFee)
.setLpFee(lpFee);
self.slot0 = Slot0.wrap(bytes32(0)).setSqrtPriceX96(sqrtPriceX96).setTick(tick).setProtocolFee(protocolFee)
.setLpFee(lpFee);
}

function setProtocolFee(State storage self, uint24 protocolFee) internal {
Expand Down Expand Up @@ -300,7 +296,9 @@ library Pool {

SwapCache memory cache = SwapCache({
liquidityStart: self.liquidity,
protocolFee: zeroForOne ? slot0Start.protocolFee().getZeroForOneFee() : slot0Start.protocolFee().getOneForZeroFee()
protocolFee: zeroForOne
? slot0Start.protocolFee().getZeroForOneFee()
: slot0Start.protocolFee().getOneForZeroFee()
});

state.amountSpecifiedRemaining = params.amountSpecified;
Expand Down
17 changes: 9 additions & 8 deletions src/types/Slot0.sol
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

/** @dev Slot0 is a packed version of solidity structure.
/**
* @dev Slot0 is a packed version of solidity structure.
* Using the packaged version saves gas by not storing the structure fields in memory slots.
*
*
* Layout:
* 24 bits empty | 24 bits lpFee | 24 bits protocolFee | 24 bits tick | 160 bits sqrtPriceX96
*
*
* Fields in the direction from the least significant bit:
*
*
* The current price
* uint160 sqrtPriceX96;
*
*
* The current tick
* int24 tick;
*
*
* Protocol fee, expressed in hundredths of a bip, upper 12 bits are for 1->0, and the lower 12 are for 0->1
* the maximum is 1000 - meaning the maximum protocol fee is 0.1%
* the protocolFee is taken from the input first, then the lpFee is taken from the remaining input
* uint24 protocolFee;
*
*
* Used for the lp fee, either static at initialize or dynamic via hook
* uint24 lpFee;
*/
Expand Down Expand Up @@ -97,4 +98,4 @@ library Slot0Library {
or(and(not(shl(LP_FEE_OFFSET, UINT24_MASK)), _packed), shl(LP_FEE_OFFSET, and(UINT24_MASK, _lpFee)))
}
}
}
}
12 changes: 9 additions & 3 deletions test/types/Slot0.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,23 @@ contract TestSlot0 is Test {
assertEq(Slot0Library.UINT24_MASK, type(uint24).max);
}

function test_slot0_fuzz_pack_unpack(uint160 sqrtPriceX96, int24 tick, uint24 protocolFee, uint24 lpFee) public pure {
function test_slot0_fuzz_pack_unpack(uint160 sqrtPriceX96, int24 tick, uint24 protocolFee, uint24 lpFee)
public
pure
{
// pack starting from "lowest" field
Slot0 _slot0 = Slot0.wrap(bytes32(0)).setSqrtPriceX96(sqrtPriceX96).setTick(tick).setProtocolFee(protocolFee).setLpFee(lpFee);
Slot0 _slot0 = Slot0.wrap(bytes32(0)).setSqrtPriceX96(sqrtPriceX96).setTick(tick).setProtocolFee(protocolFee)
.setLpFee(lpFee);

assertEq(_slot0.sqrtPriceX96(), sqrtPriceX96);
assertEq(_slot0.tick(), tick);
assertEq(_slot0.protocolFee(), protocolFee);
assertEq(_slot0.lpFee(), lpFee);

// pack starting from "highest" field
_slot0 = Slot0.wrap(bytes32(0)).setLpFee(lpFee).setProtocolFee(protocolFee).setTick(tick).setSqrtPriceX96(sqrtPriceX96);
_slot0 = Slot0.wrap(bytes32(0)).setLpFee(lpFee).setProtocolFee(protocolFee).setTick(tick).setSqrtPriceX96(
sqrtPriceX96
);

assertEq(_slot0.sqrtPriceX96(), sqrtPriceX96);
assertEq(_slot0.tick(), tick);
Expand Down

0 comments on commit 48dc19a

Please sign in to comment.