Skip to content
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

add position manager [wip] #141

Merged
merged 112 commits into from
Jul 23, 2024
Merged

add position manager [wip] #141

merged 112 commits into from
Jul 23, 2024

Conversation

snreynolds
Copy link
Member

@snreynolds snreynolds commented Jul 9, 2024

Related Issue

Which issue does this pull request resolve?

This is the dev branch for everything related to position manager and should be reviewed in entirety before merging into main.

Closed:

  • Base functionality: mint/burn/increaseLiquidity/decreaseLiquidity/collect
  • Move operator out of Position struct - @saucepoint
  • Update the nonce scheme (non-incrementing nonce) - @saucepoint
  • Use internal calls instead of external multicall from within _unlockCallback - @snreynolds
  • Remove all internal delta accounting by using a salt for every tokenId's position. - @snreynolds
  • Enforce a deadline on all relevant functions
  • Initialize a pool if it doesn't exist - add createAndInitializePoolIfNecessary - @saucepoint
  • Add external multicall - @saucepoint
  • deprecate collect, use decrease with 0
  • Add a deadline check
  • Fix: _beforeTransferFrom. Must use salt to uniquely identify the same range per owner.
  • Fix: Remove external call from within unlockCallback
  • Add salt to LiquidityRange(fixes _beforeTokenTransfer) [FIXED WITH SALTS ON POSITION]

OUT-OF-SCOPE for base PositionManager, but tracking below:

  • Add library for posm specific view functions [171]
  • Optimization: store hash of PoolKey, tickLower, tickUpper instead of full LiquidityRange. [169]
  • Add permit [167]
  • Use Actions Router + Add SETTLE, TAKE, CLOSE_PAIR (& potentially SETTLE_PERMIT) functionality [168]
  • Improve CurrencySettleTake library 165
  • Optimize encode/decode [173]
  • Add transient reentrancy lock [170]
  • General Natspec needed [174]
  • Bubble up reverts[175]
  • Combine mint/burn with decrease/increase [176]
  • Add slippage parameters[177]
  • Add staking functionality [178]- @snreynolds
  • Support ETH functionality [178] - @gretzke
  • CurrencySettlerLibrary should use permit2 [180]

Outstanding tests:

  • batch + combination testing
  • ERC721 tests: operator, nonce, transfer (transfer and burn, transfer and increase/decrease liquidity, transfer and collect)

@snreynolds snreynolds requested a review from hensha256 July 21, 2024 19:28
src/interfaces/IPositionManager.sol Outdated Show resolved Hide resolved
src/lens/Quoter.sol Show resolved Hide resolved
src/PositionManager.sol Outdated Show resolved Hide resolved
src/PositionManager.sol Outdated Show resolved Hide resolved
src/PositionManager.sol Show resolved Hide resolved
donateRouter.donate(key, 0.2e18, 0.2e18, ZERO_BYTES);

// subtract 1 cause we'd rather take than pay
uint256 feesAmount = amountDonate.mulDivDown(liquidityAlice, liquidityAlice + liquidityBob) - 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

doesnt the div down already handle the downward rounding for take vs settle? is it not enough?

Copy link
Member Author

Choose a reason for hiding this comment

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

it didn't in this case. if i dont subtract 1 it does a pay/settle

test/position-managers/IncreaseLiquidity.t.sol Outdated Show resolved Hide resolved
// transplant: burn and mint on different keys
function test_execute_transplant() public {}
// cross-coalesce: burn and increase on different keys
function test_execute_crossCoalesce() public {}
Copy link
Contributor

Choose a reason for hiding this comment

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

lmao i like the fun name ideas but i do think it would be much easier to see what was failing if you saw

test_execute_burnAndIncreaseDifferentKeys

instead of test_execute_crossCoalesce

Copy link
Member Author

Choose a reason for hiding this comment

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

I am gonna keep this for now - sauce has a really great doc/table explaining all these names LOL. we can change later when we actually implement the tests if u still dont like

test/position-managers/Gas.t.sol Outdated Show resolved Hide resolved
test/position-managers/FeeCollection.t.sol Outdated Show resolved Hide resolved
import {LiquidityOperations} from "./LiquidityOperations.sol";

/// @notice A shared test contract that wraps the v4-core deployers contract and exposes basic liquidity operations on posm.
contract PosmTestSetup is Test, Deployers, LiquidityOperations {
Copy link
Contributor

Choose a reason for hiding this comment

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

nice i like it


contract Quoter is IQuoter, IUnlockCallback {
contract Quoter is IQuoter, SafeCallback {
Copy link
Contributor

Choose a reason for hiding this comment

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

oh great spot

bytes memory calls = planner.finalize(range.poolKey);
vm.prank(alice);
lpm.modifyLiquidities(calls, _deadline);
snapLastCall("PositionManager_mint_warmedPool_differentRange");
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe stupid question... what about a warmed pool is cheaper than an un-warmed pool when it doesnt share a tick? Like which slot(s) that it writes to is "warm" that decreases the cost?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh I just added this because the gas costs were different when I didn't "touch" a pool before the mint. Like compare this to just PositionManager_mint.. they are different. Im not really sure why I'm guessing its because the tokens are touched, and pool key is touched? But not totally sure.

swap(key, true, -int256(swapAmount), ZERO_BYTES); // zeroForOne is true, so zero is the input
swap(key, false, -int256(swapAmount), ZERO_BYTES); // move the price back, // zeroForOne is false, so one is the input

uint256 tolerance = 0.000000001 ether;
Copy link
Contributor

Choose a reason for hiding this comment

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

the tolerance stuff for auto-compounding fees has given me an idea - currently you have a command for doing either settle or take that you can call for these cases of dust in one direction or the other.
I'm wondering if itll be worth having a command thats like either settle or clear?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes! Although I also wonder if we could just "auto" clear if its less than some threshold.. basically abstracting away clear a bit? or at least still having some check around clearing? I dont want someone to encode a clear that wipes non negligible funds

@snreynolds snreynolds merged commit 1abe26d into main Jul 23, 2024
3 checks passed
@snreynolds snreynolds deleted the dev-posm branch July 23, 2024 12:29
@saucepoint saucepoint mentioned this pull request Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
posm position manager
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants