0xKitsune / cfmms-rs

The predecessor to `amms-rs`. CFMM lib built in Rust enabling pair syncing and swap simulation with pools on Ethereum.
282 stars 69 forks source link

Liquidity Provisioning Utilities for Liquidity Providors + JIT Exploitation #26

Open 0xOsiris opened 1 year ago

0xOsiris commented 1 year ago

I think adding liquidity provision helpers on the pools could be very appealing to liquidity providers monitoring and moving around large amounts of liquidity across CFMMs. This would allow liquidity providers to seamlessly automate their liquidity provision, and analytically optimize the profitability of their positions.

For Starters:

Mint Liquidity

function mint(
        address recipient,
        int24 tickLower,
        int24 tickUpper,
        uint128 amount,
        bytes calldata data
    ) external returns (uint256 amount0, uint256 amount1);

Collect Fees

function collect(
        address recipient,
        int24 tickLower,
        int24 tickUpper,
        uint128 amount0Requested,
        uint128 amount1Requested
    ) external returns (uint128 amount0, uint128 amount1);

Remove Liquidity from a position

function burn(
        int24 tickLower,
        int24 tickUpper,
        uint128 amount
    ) external returns (uint256 amount0, uint256 amount1);

Ranged Liquidity or Time Weighted Average price

function observe(uint32[] calldata secondsAgos)
        external
        view
        returns (int56[] memory tickCumulatives, uint160[] memory secondsPerLiquidityCumulativeX128s);

Seconds per Liquidity & Seconds inside a tick range

function snapshotCumulativesInside(int24 tickLower, int24 tickUpper)
        external
        view
        returns (
            int56 tickCumulativeInside,
            uint160 secondsPerLiquidityInsideX128,
            uint32 secondsInside
        );

The above function would also be helpful for calculating optimal JIT positions and amounts.

0xKitsune commented 1 year ago

Yeah lets, definitely add some functions to calculate JIT on pools. We can figure out what functionality we want and what those functions might look like after we get the rest of the lib tested.

tim-schultz commented 1 year ago

Have you all started on this yet? Would be happy to help out if not

0xKitsune commented 1 year ago

Hey, this has not been started yet. Feel free to take this on if you would like. I think we should add all of the helpful functions that a user might interact with for v2 and v3 pools. Feel free to drop any comments here for any brainstorming / feedback that you want along the way!

tim-schultz commented 1 year ago

👋 sounds great! I will let you know as I make progress