Swap Parameters

The swap function contains _swapParams as input, whose type is the following struct:

struct SovereignPoolSwapParams {
    bool isSwapCallback;
    bool isZeroToOne;
    uint256 amountIn;
    uint256 amountOutMin;
    uint256 deadline;
    address recipient;
    address swapTokenOut;
    SovereignPoolSwapContextData swapContext;
}
  • _swapParams.isSwapCallback True if msg.sender expects a callback to claim input token amounts after all swap amounts have been determined (analogous to the swap callback in UniswapV3 pools). If False, input token claiming will happen via ERC20.transferFrom

  • _swapParams.isZeroToOne Direction of the swap

  • _swapParams.amountIn Maximum amount of input token which the user wants to trade.

  • _swapParams.amountOutMin Minimum required amount of output token.

  • _swapParams.deadline Block height at which the swap becomes invalid.

  • _swapParams.recipient Address which should receive the output token amount.

  • _swapParams.swapTokenOut Token which the user wants to receive as output. Does not necessarily need to be token0 or token1.

  • _swapParams.swapContext Struct containing external byte encoded calldata for the Liquidity Module, Swap Fee Module, Verifier Module and swap callback, if applicable.

Swap Context

The swapContext struct includes 4 fields optionally utilized by different modules during swap execution.

struct SovereignPoolSwapContextData {
    bytes externalContext;
    bytes verifierContext;
    bytes swapCallbackContext;
    bytes swapFeeModuleContext;
}
  • _swapParams.swapContext.externalContext Is sent to the Liquidity Module during the getLiquidityQuote call, this context is likely used to inform the Liquidity Module about any external data it should use for pricing.

  • _swapParams.swapContext.verifierContext Is sent to the Verifier Module before a swap is made. The verifier module can revert or produce verifierContext sent to the Liquidity Module during the getLiquidityQuote call.

  • _swapParams.swapContext.swapCallbackContext Is sent to the Liquidity Module after a swap has been made. This allows the AMM to update state according to external data post swap.

  • _swapParams.swapContext.swapFeeModuleContext Is sent to the Swap Fee Module before a swap to compute the fees.

Last updated