Deposits and Withdrawals

The entry-point for LP deposits and withdrawals is the Validly contract itself.

Deposits

On deposits, the user first calls Validly's deposit function:

    /**
     * @notice Deposit liquidity into `pool` and mint LP tokens.
     * @param _amount0 Amount of token0 deposited.
     * @param _amount1 Amount of token1 deposited.
     * @param _minShares Minimum amount of shares to mint.
     * @param _deadline Block timestamp after which this call reverts.
     * @param _recipient Address to mint LP tokens for.
     * @param _verificationContext Bytes encoded payload, in case `pool` has a Verifier Module.
     * @return shares Amount of shares minted.
     */
    function deposit(
        uint256 _amount0,
        uint256 _amount1,
        uint256 _minShares,
        uint256 _deadline,
        address _recipient,
        bytes calldata _verificationContext
    )
        external
        returns (uint256 shares, uint256 amount0, uint256 amount1);

The deposit function contains most of the business logic, including minting shares worth of LP tokens in the Validly contract, representing pro-rata ownership of the liquidity pool. The actual token balances are stored in the Sovereign Pool. Source: https://github.com/ValantisLabs/Validly/blob/main/src/Validly.sol#L123-L191

Withdrawals

On withdrawals, Validly's withdraw function is the first to get called:

function withdraw(
        uint256 _shares,
        uint256 _amount0Min,
        uint256 _amount1Min,
        uint256 _deadline,
        address _recipient,
        bytes calldata _verificationContext
    ) external returns (uint256 amount0, uint256 amount1);

The LP can call withdraw to redeem _shares worth of liquidity for the equivalent amount of token0 and token1 balances. Upon burning the LP tokens, token0 and token1 amounts get transferred from the Sovereign Pool into _recipient. Source: https://github.com/ValantisLabs/Validly/blob/main/src/Validly.sol#L193-L237

Last updated