-
Notifications
You must be signed in to change notification settings - Fork 505
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* change add liq accounting * remove rand comments * fix exact fees * use closeAllDeltas * comments cleanup * additional liquidity tests (#129) * additional increase liquidity tests * edge case of using cached fees for autocompound * wip * fix autocompound bug, use custodied and unclaimed fees in the autocompound * fix tests and use BalanceDeltas (#130) * fix some assertions * use BalanceDeltas for arithmetic * cleanest code in the game??? * additional cleaning * typo lol * autocompound gas benchmarks * autocompound excess credit gas benchmark * save 600 gas, cleaner code when moving caller delta to tokensOwed --------- Co-authored-by: saucepoint <[email protected]>
- Loading branch information
1 parent
2227265
commit 0cff6ef
Showing
21 changed files
with
567 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
258477 |
1 change: 1 addition & 0 deletions
1
.forge-snapshots/autocompound_exactUnclaimedFees_exactCustodiedFees.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
190850 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
279016 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
187556 | ||
190026 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
166551 | ||
168894 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
183251 | ||
171241 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
158833 | ||
146823 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
478540 | ||
466530 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.20; | ||
|
||
import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol"; | ||
|
||
library BalanceDeltaExtensionLibrary { | ||
function setAmount0(BalanceDelta a, int128 amount0) internal pure returns (BalanceDelta) { | ||
assembly { | ||
// set the upper 128 bits of a to amount0 | ||
a := or(shl(128, amount0), and(sub(shl(128, 1), 1), a)) | ||
} | ||
return a; | ||
} | ||
|
||
function setAmount1(BalanceDelta a, int128 amount1) internal pure returns (BalanceDelta) { | ||
assembly { | ||
// set the lower 128 bits of a to amount1 | ||
a := or(and(shl(128, sub(shl(128, 1), 1)), a), amount1) | ||
} | ||
return a; | ||
} | ||
|
||
function addAmount0(BalanceDelta a, int128 amount0) internal pure returns (BalanceDelta) { | ||
assembly { | ||
let a0 := sar(128, a) | ||
let res0 := add(a0, amount0) | ||
a := or(shl(128, res0), and(sub(shl(128, 1), 1), a)) | ||
} | ||
return a; | ||
} | ||
|
||
function addAmount1(BalanceDelta a, int128 amount1) internal pure returns (BalanceDelta) { | ||
assembly { | ||
let a1 := signextend(15, a) | ||
let res1 := add(a1, amount1) | ||
a := or(and(shl(128, sub(shl(128, 1), 1)), a), res1) | ||
} | ||
return a; | ||
} | ||
|
||
function addAndAssign(BalanceDelta a, BalanceDelta b) internal pure returns (BalanceDelta) { | ||
assembly { | ||
let a0 := sar(128, a) | ||
let a1 := signextend(15, a) | ||
let b0 := sar(128, b) | ||
let b1 := signextend(15, b) | ||
let res0 := add(a0, b0) | ||
let res1 := add(a1, b1) | ||
a := or(shl(128, res0), and(sub(shl(128, 1), 1), res1)) | ||
} | ||
return a; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
pragma solidity >=0.8.20; | ||
|
||
import {IBaseLiquidityManagement} from "../interfaces/IBaseLiquidityManagement.sol"; | ||
import {BalanceDelta} from "v4-core/types/BalanceDelta.sol"; | ||
|
||
// Updates Position storage | ||
library PositionLibrary { | ||
// 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 addLiquidity(IBaseLiquidityManagement.Position storage position, uint256 liquidity) internal { | ||
unchecked { | ||
position.liquidity += liquidity; | ||
} | ||
} | ||
|
||
// TODO ensure this is one sstore. | ||
function updateFeeGrowthInside( | ||
IBaseLiquidityManagement.Position storage position, | ||
uint256 feeGrowthInside0X128, | ||
uint256 feeGrowthInside1X128 | ||
) internal { | ||
position.feeGrowthInside0LastX128 = feeGrowthInside0X128; | ||
position.feeGrowthInside1LastX128 = feeGrowthInside1X128; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.