Skip to content

Commit

Permalink
Implicitly collect fees on adjust position, collect single frontend u…
Browse files Browse the repository at this point in the history
…pdates position too
  • Loading branch information
af-afk committed Dec 11, 2024
1 parent 4187810 commit 1eb096a
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 12 deletions.
2 changes: 1 addition & 1 deletion features/features.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"faucet enabled": true,
"graphql mock demo data": false,
"graphql mock demo data should delay": false,
"graphql whitelisted only pools": false,
"graphql whitelisted only pools": true,
"ui show boost incentives": false,
"ui show campaign banner": false,
"ui show claim all yield": true,
Expand Down
29 changes: 20 additions & 9 deletions pkg/seawater/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,13 +582,7 @@ impl Pools {
Ok(upper.sys())
}

#[allow(non_snake_case)]
pub fn collect_single_to_6_D_76575_F(
&mut self,
pool: Address,
id: U256,
recipient: Address,
) -> Result<(u128, u128), Revert> {
fn internal_collect_fees(&mut self, pool: Address, id: U256, recipient: Address) -> Result<(u128, u128), Revert> {
assert_eq_or!(
msg::sender(),
self.position_owners.get(id),
Expand All @@ -612,6 +606,17 @@ impl Pools {
Ok(res)
}

#[allow(non_snake_case)]
pub fn collect_single_to_6_D_76575_F(
&mut self,
pool: Address,
id: U256,
recipient: Address,
) -> Result<(u128, u128), Revert> {
self.pools.setter(pool).update_position(id, 0)?;
self.internal_collect_fees(pool, id, recipient)
}

/// Collects AMM fees from a position, and triggers a release of fluid LP rewards.
/// Only usable by the position's owner.
///
Expand All @@ -636,7 +641,7 @@ impl Pools {
pools
.iter()
.zip(ids.iter())
.map(|(&pool, &id)| self.collect_single_to_6_D_76575_F(pool, id, msg::sender()))
.map(|(&pool, &id)| self.internal_collect_fees(pool, id, msg::sender()))
.collect::<Result<Vec<(u128, u128)>, Revert>>()
}
}
Expand Down Expand Up @@ -754,7 +759,13 @@ impl Pools {
erc20::take(FUSDC_ADDR, amount_1, permit_1)?;
}

Ok((amount_0, amount_1))
let (amount0_collected, amount1_collected) =
self.internal_collect_fees(pool, id, msg::sender())?;

Ok((
amount_0 + U256::from(amount0_collected),
amount_1 + U256::from(amount1_collected),
))
}
}

Expand Down
1 change: 1 addition & 0 deletions pkg/seawater/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ impl StoragePool {

// shift tick
if state.price == step_next_price {

if step_next_tick_initialised {
let (fee_0, fee_1) = match zero_for_one {
true => (state.fee_growth_global, self.fee_growth_global_1.get()),
Expand Down
1 change: 1 addition & 0 deletions pkg/seawater/src/position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ impl StoragePositions {
.token_owed_0
.get()
.wrapping_add(U128::wrapping_from(owed_fees_0));

info.token_owed_0.set(new_fees_0);
}
if !owed_fees_1.is_zero() {
Expand Down
21 changes: 20 additions & 1 deletion pkg/sol/ISeawaterExecutors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,8 @@ interface ISeawaterExecutorAdmin is ISeawaterExecutorAdminExposed {
}

interface ISeawaterExecutorAdjustPosition {
/// @notice refreshes a position's fees, and adds liquidity, preventing less than the minimum from being taken.
/// @notice refreshes and takes a position's fees, and adds liquidity, preventing less than
/// the minimum from being taken.
/// @param pool of the token to use
/// @param id the id of the position
/// @param amount0Min minimum of amount0 to take from the user
Expand All @@ -298,6 +299,24 @@ interface ISeawaterExecutorAdjustPosition {
uint256 amount0Desired,
uint256 amount1Desired
) external returns (uint256, uint256);

/// @notice refreshes and takes a position's fees, and adds liquidity, preventing less than
/// the minimum from being taken.
/// @param pool of the token to use
/// @param id the id of the position
/// @param amount0Min minimum of amount0 to take from the user
/// @param amount1Min minimum of amount1 to take from the user
/// @param amount0Desired to give to the user. May go lower.
/// @param amount1Desired to give to the user. May go lower.
/// @return the deltas for token0, and token1
function decrPosition09293696(
address pool,
uint256 id,
uint256 amount0Min,
uint256 amount1Min,
uint256 amount0Desired,
uint256 amount1Desired
) external returns (uint256, uint256);
}

interface ISeawaterExecutorFallback {}
10 changes: 10 additions & 0 deletions pkg/sol/SeawaterAMM.sol
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,16 @@ contract SeawaterAMM is ISeawaterAMM {
directDelegate(_getExecutorAdjustPosition());
}

/// @inheritdoc ISeawaterExecutorAdjustPosition
function decrPosition09293696(
address /* pool */,
uint256 /* id */,
uint256 /* amount0Min */,
uint256 /* amount1Min */,
uint256 /* amount0Desired */,
uint256 /* amount1Desired */
) external returns (uint256, uint256);

function setExecutorSwap(address a) external onlyProxyAdmin {
StorageSlot.getAddressSlot(EXECUTOR_SWAP_SLOT).value = a;
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

export RUST_BACKTRACE=1

cargo test --features testing -- test_mint_position_ranges --nocapture
cargo test --features testing -- --nocapture

0 comments on commit 1eb096a

Please sign in to comment.