-
Notifications
You must be signed in to change notification settings - Fork 504
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
update decrease #133
update decrease #133
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
258477 | ||
258575 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
190850 | ||
190948 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
279016 | ||
279114 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
190026 | ||
177014 | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
168894 | ||
177026 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
171241 | ||
171339 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
146823 | ||
146921 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
466530 | ||
466628 |
Large diffs are not rendered by default.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.20; | ||
|
||
import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol"; | ||
|
||
import "forge-std/console2.sol"; | ||
|
||
library LiquidityDeltaAccounting { | ||
function split(BalanceDelta liquidityDelta, BalanceDelta callerFeesAccrued, BalanceDelta totalFeesAccrued) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i like this library a lot and how its used. its a super minor nit but i think we should call it
|
||
internal | ||
returns (BalanceDelta callerDelta, BalanceDelta thisDelta) | ||
{ | ||
if (totalFeesAccrued == callerFeesAccrued) { | ||
// when totalFeesAccrued == callerFeesAccrued, the caller is not sharing the range | ||
// therefore, the caller is responsible for the entire liquidityDelta | ||
callerDelta = liquidityDelta; | ||
} else { | ||
// the delta for increasing liquidity assuming that totalFeesAccrued was not applied | ||
BalanceDelta principalDelta = liquidityDelta - totalFeesAccrued; | ||
|
||
// outstanding deltas the caller is responsible for, after their fees are credited to the principal delta | ||
callerDelta = principalDelta + callerFeesAccrued; | ||
|
||
// outstanding deltas this contract is responsible for, intuitively the contract is responsible for taking fees external to the caller's accrued fees | ||
thisDelta = totalFeesAccrued - callerFeesAccrued; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,18 +6,32 @@ import {BalanceDelta} from "v4-core/types/BalanceDelta.sol"; | |
|
||
// Updates Position storage | ||
library PositionLibrary { | ||
error InsufficientLiquidity(); | ||
|
||
// TODO ensure this is one sstore. | ||
function addTokensOwed(IBaseLiquidityManagement.Position storage position, BalanceDelta tokensOwed) internal { | ||
position.tokensOwed0 += uint128(tokensOwed.amount0()); | ||
position.tokensOwed1 += uint128(tokensOwed.amount1()); | ||
} | ||
|
||
function clearTokensOwed(IBaseLiquidityManagement.Position storage position) internal { | ||
position.tokensOwed0 = 0; | ||
position.tokensOwed1 = 0; | ||
} | ||
|
||
function addLiquidity(IBaseLiquidityManagement.Position storage position, uint256 liquidity) internal { | ||
unchecked { | ||
position.liquidity += liquidity; | ||
} | ||
} | ||
|
||
function subtractLiquidity(IBaseLiquidityManagement.Position storage position, uint256 liquidity) internal { | ||
if (position.liquidity < liquidity) revert InsufficientLiquidity(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could probably move this outside of here tbh and check it sooner but for now fine? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i dont mind it here, gives a nice assurance with the following unchecked block |
||
unchecked { | ||
position.liquidity -= liquidity; | ||
} | ||
} | ||
|
||
// TODO ensure this is one sstore. | ||
function updateFeeGrowthInside( | ||
IBaseLiquidityManagement.Position storage position, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
less gas!