Skip to content
Merged
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
7 changes: 2 additions & 5 deletions src/libraries/SqrtPriceMath.sol
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,8 @@ library SqrtPriceMath {
{
uint256 numerator = absDiff(sqrtPriceAX96, sqrtPriceBX96);
uint256 denominator = FixedPoint96.Q96;
uint256 _liquidity;
assembly ("memory-safe") {
// avoid implicit upcasting
_liquidity := and(liquidity, 0xffffffffffffffffffffffffffffffff)
}
uint256 _liquidity = uint256(liquidity);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm but why do we have a comment that says "avoid implicit upcasting".. feels like this is what we/someone was trying to avoid?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was just done in PR #676 to save gas. But now that we've added masking and optimiser runs are higher, it doesnt save gas anymore.


/**
* Equivalent to:
* amount1 = roundUp
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/StateLibrary.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ library StateLibrary {

/// @notice index of feeGrowthGlobal0X128 in Pool.State
uint256 public constant FEE_GROWTH_GLOBAL0_OFFSET = 1;
/// @notice index of feeGrowthGlobal1X128 in Pool.State
uint256 public constant FEE_GROWTH_GLOBAL1_OFFSET = 2;
Comment thread
hensha256 marked this conversation as resolved.

// feeGrowthGlobal1X128 offset in Pool.State = 2

/// @notice index of liquidity in Pool.State
uint256 public constant LIQUIDITY_OFFSET = 3;
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/SwapMath.sol
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ library SwapMath {
// `amountIn` is capped by the target price
sqrtPriceNextX96 = sqrtPriceTargetX96;
feeAmount = _feePips == MAX_SWAP_FEE
? amountIn
? amountIn // amountIn is always 0 here, as amountRemainingLessFee == 0 and amountRemainingLessFee >= amountIn
: FullMath.mulDivRoundingUp(amountIn, _feePips, MAX_SWAP_FEE - _feePips);
} else {
// exhaust the remaining amount
Expand Down
6 changes: 2 additions & 4 deletions src/libraries/UnsafeMath.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ library UnsafeMath {
/// @param y The divisor
/// @return z The quotient, ceil(x / y)
function divRoundingUp(uint256 x, uint256 y) internal pure returns (uint256 z) {
unchecked {
assembly ("memory-safe") {
z := add(div(x, y), gt(mod(x, y), 0))
}
assembly ("memory-safe") {
z := add(div(x, y), gt(mod(x, y), 0))
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/types/PoolId.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ library PoolIdLibrary {
/// @notice Returns value equal to keccak256(abi.encode(poolKey))
function toId(PoolKey memory poolKey) internal pure returns (PoolId poolId) {
assembly ("memory-safe") {
poolId := keccak256(poolKey, mul(32, 5))
// 0xa0 represents the total size of the poolKey struct (5 slots of 32 bytes)
poolId := keccak256(poolKey, 0xa0)
}
}
}