Skip to content

Commit

Permalink
feat: Add events and methods for off-chain farming
Browse files Browse the repository at this point in the history
  • Loading branch information
chef-omelette committed Apr 16, 2024
1 parent a3cf6ea commit 61a33d3
Show file tree
Hide file tree
Showing 15 changed files with 34 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
348804
350133
Original file line number Diff line number Diff line change
@@ -1 +1 @@
59352
60681
Original file line number Diff line number Diff line change
@@ -1 +1 @@
242397
243726
Original file line number Diff line number Diff line change
@@ -1 +1 @@
42330
43659
Original file line number Diff line number Diff line change
@@ -1 +1 @@
54822
54779
Original file line number Diff line number Diff line change
@@ -1 +1 @@
102898
102855
Original file line number Diff line number Diff line change
@@ -1 +1 @@
25042646
25042603
2 changes: 1 addition & 1 deletion .forge-snapshots/CLPoolManagerTest#swap_simple.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
36022
35979
Original file line number Diff line number Diff line change
@@ -1 +1 @@
101660
101617
2 changes: 1 addition & 1 deletion .forge-snapshots/CLPoolManagerTest#swap_withHooks.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
41672
41629
2 changes: 1 addition & 1 deletion .forge-snapshots/CLPoolManagerTest#swap_withNative.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
36025
35982
2 changes: 1 addition & 1 deletion .forge-snapshots/CLPoolManagerTest#testNoOp_gas_Swap.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
21667
21624
2 changes: 1 addition & 1 deletion .forge-snapshots/ExtsloadTest#extsloadInBatch.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
11352
11397
8 changes: 8 additions & 0 deletions src/pool-cl/CLPoolManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,14 @@ contract CLPoolManager is ICLPoolManager, Fees, Extsload {
return pools[id].tickBitmap[word];
}

function getPoolFeeGrowthInside(PoolId id, int24 tickLower, int24 tickUpper)
external
view
returns (uint256 feeGrowthInside0X128, uint256 feeGrowthInside1X128)
{
return pools[id].getFeeGrowthInside(tickLower, tickUpper);
}

/// @inheritdoc ICLPoolManager
function setMasterChef(address _masterChef) external override onlyOwner {
masterChef = _masterChef;
Expand Down
13 changes: 13 additions & 0 deletions src/pool-cl/libraries/CLPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ library CLPool {
/// @notice Thrown by donate if there is currently 0 liquidity, since the fees will not go to any liquidity providers
error NoLiquidityToReceiveFees();

/// @dev for off-chain farming
event SwapFees(uint256 feesOwed0, uint256 feesOwed1);

struct Slot0 {
// the current price
uint160 sqrtPriceX96;
Expand Down Expand Up @@ -110,6 +113,8 @@ library CLPool {
Tick.checkTicks(params.tickLower, params.tickUpper);

(uint256 feesOwed0, uint256 feesOwed1) = _updatePosition(self, params, _slot0.tick);
// @dev track swap fees for off-chain farming
emit SwapFees(feesOwed0, feesOwed1);

///@dev calculate the tokens delta needed
if (params.liquidityDelta != 0) {
Expand Down Expand Up @@ -490,4 +495,12 @@ library CLPool {
function isNotInitialized(State storage self) internal view returns (bool) {
return self.slot0.sqrtPriceX96 == 0;
}

function getFeeGrowthInside(State storage self, int24 tickLower, int24 tickUpper)
internal
view
returns (uint256 feeGrowthInside0X128, uint256 feeGrowthInside1X128)
{
return self.ticks.getFeeGrowthInside(tickLower, tickUpper, self.slot0.tick, self.feeGrowthGlobal0X128, self.feeGrowthGlobal1X128);
}
}

0 comments on commit 61a33d3

Please sign in to comment.