TideFi PropAMM

Integrate with Ulmo Markets instant posted liquidity.

What is TideFi?

TideFi is Ulmo Markets' PropAMM. It brings CEX-like pricing on-chain, enabling token swaps with competitive pricing backed by Ulmo Markets' proprietary quoting engine.

Integrators can get quotes and execute swaps directly against the contract. TideFi exposes a quote function for previewing swap amounts and a swap function for execution.

Market makers can also provide liquidity through TideFi and be part of Ulmo Markets. See Providing liquidity in TideFi.

Deployments

ChainTideFi
Base0x71Def100007A540305DD65d1034D10e809679FD5

Contract interface

quote

Returns the amounts that would result from a swap given the caller's limits. This function is read-only (view).

function quote(address tokenIn, address tokenOut, uint256 maxAmountIn, UFixed18 limitPrice)
    external
    view
    returns (uint256 amountIn, uint256 amountOut);
ParameterTypeDescription
tokenInaddressInput token
tokenOutaddressOutput token
maxAmountInuint256Cap on the amount of input token spent
limitPriceUFixed18Max tokenIn paid per tokenOut, 18-decimal fixed point over raw token amounts (no decimals adjustment). Pass type(uint256).max for no limit

swap

Executes a swap against TideFi. Two overloads are available: with and without a callback.

function swap(
    address tokenIn,
    address tokenOut,
    uint256 maxAmountIn,
    uint256 minAmountOut,
    UFixed18 limitPrice,
    address to,
    bytes calldata callbackData
) external returns (uint256 amountIn, uint256 amountOut);
function swap(
    address tokenIn,
    address tokenOut,
    uint256 maxAmountIn,
    uint256 minAmountOut,
    UFixed18 limitPrice,
    address to
) external returns (uint256 amountIn, uint256 amountOut);
ParameterTypeDescription
tokenInaddressInput token
tokenOutaddressOutput token
maxAmountInuint256Cap on the amount of input token spent
minAmountOutuint256Minimum output: reverts with TideFiInsufficientAmountOut if not met
limitPriceUFixed18Max tokenIn paid per tokenOut, 18-decimal fixed point over raw token amounts (no decimals adjustment). Pass type(uint256).max for no limit
toaddressRecipient of the output tokens
callbackDatabytesForwarded to the caller's callback

Returns amountIn and amountOut: the actual amounts swapped. Filling stops once the marginal price exceeds limitPrice or the amountOut exceeds the contract's balance, so amountIn can be below maxAmountIn. The swap reverts if amountOut ends up below minAmountOut.

Swap callback

Callers of the callback overload must implement:

interface ITideFiCallback {
    function tidefiSwap(
        address tokenIn,
        address tokenOut,
        uint256 amountIn,
        uint256 amountOut,
        bytes calldata data
    ) external;
}

Computing limitPrice

limitPrice is the maximum tokenIn paid per tokenOut over raw token amounts, encoded as the value times 1e18:

limitPrice = humanPrice * 10**decimalsIn / 10**decimalsOut * 1e18

For example, buying WETH with USDC at a max price of 2000 USDC per WETH:

2000 * 10**6 / 10**18 * 1e18 = 2000e6

Selling WETH for USDC at the same price (max 1/2000 WETH per USDC):

(1/2000) * 10**18 / 10**6 * 1e18 = 5e26

It is always a cap on tokenIn per tokenOut, so a worse price is always a larger number, in either direction.

Integration overview

  1. Call quote to preview amounts for your limits and limit price.
  2. Approve tokenIn on the TideFi contract.
  3. Call swap with the same limits, a minAmountOut derived from the quote, a recipient address, and optional callbackData.