Document for Liquidity Provider(LP)

Flit Liquidity Provider Guide

1. Project Design Overview

Flit is a cross-chain liquidity protocol that enables users to transfer tokens across EVM-compatible chains efficiently. As a liquidity provider (LP), you play a crucial role in this ecosystem.

1.1 Cross-Chain Transfer Process

  • User locks tokens on the source chain.

  • FTokens are minted on the destination chain.

  • FTokens are swapped for base tokens in the CSAMM (Constant Sum Automated Market Maker).

  • The contract sends the tokens to the user on the destination chain.

1.2 LP's Role

As an LP, you provide liquidity to the CSAMM pools on various chains. This liquidity enables smooth token swaps and cross-chain transfers for users.

1.3 Earning Rewards

As an LP, you earn rewards through:

  • Swap Fees: A small fee is charged for each swap in the CSAMM. These fees are distributed proportionally to all LPs.

  • LP Token Appreciation: As fees accumulate in the pool, the value of your LP tokens increases relative to the underlying assets.

To claim your rewards:

  • Remove liquidity using the removeLiquidity function.

  • The returned amounts will include your initial deposit plus accumulated fees.

2. Interacting with the Contract

TokenID: A single tokenID corresponds to the same token (or its representation) on all supported chains. For example, USDC might have a tokenID of 1, which would represent USDC on Ethereum, Polygon, and any other supported network.Querying TokenID: Users and developers can query the tokenID for a specific token using its address on a particular chain. As an LP, you'll primarily interact with the FlitManager contract:

2.1 Adding Liquidity with ERC20 Token

function addLiquidity(uint256 tokenID, uint256 amount0, uint256 amount1) external returns (uint256 liquidity)

Provide both tokens in the pair to add liquidity. You'll receive LP tokens in return. amount0 is the ERC20 token you want to provide with. amount1 is the FToken you want to provide with. Before calling this function, you'll need to call the approve(address(FlitManager), amount) of both tokens first.

2.4 Removing Liquidity of ETH

function removeLiquidityETH(uint256 _tokenID, uint256 _share, address _to) external returns (uint256 baseAmount, uint256 ftokenAmount)

Burn your LP tokens to withdraw your share of the liquidity pool when one of the tokens is ETH (or the native token of the chain). The function will automatically unwrap WETH to ETH and send it to the specified address along with the corresponding amount of FTokens. Before calling this function, ensure you have approved the FlitManager contract to spend your LP tokens.

2.5 Checking Your LP Token Balance

To check your LP token balance, you need to follow these steps to get the address of the LP token:

First, call the getFlit function on the FlitManager contract with the specific token ID:

function getFlit(uint256 _tokenID) public view returns (Flit)

This returns the address of the Flit contract for that token ID.

Then, call the amm() function on the returned Flit contract:

function amm() external view returns (ICSAMM)

This will return the address of the CSAMM contract, which is also the LP token address.

Once you have the LP token address, you can call the standard ERC20 balanceOf function:

function balanceOf(address account) external view returns (uint256)

This process will allow you to view your current LP token balance for that specific Flit pool.

2.6 Cross-Chain Swapping FToken to Base Token

If there's insufficient liquidity in the current chain to swap your FToken for the base token, you can perform a cross-chain swap. This is a two-step process:

a. Transfer FTokens to another chain

 function xFTokenTransfer(uint256 _tokenID, uint32 _dstEid, address _recipient, uint256 _amount, MessagingFee calldata _fee, bytes calldata _options) external payable

This function transfers your FTokens to a chain with more liquidity. You'll need to specify the destination chain ID (_dstEid), the recipient address (usually your address on the destination chain), and the amount of FTokens to transfer.

b. Swap FTokens for Base Tokens

function swapForBaseToken(uint256 _tokenID, uint256 _amount) external

After the FTokens have been transferred, you can call this function on the destination chain to swap your FTokens for base tokens.Here's how the process works:

1. Call xFTokenTransfer to move your FTokens to a chain with more liquidity.

2. Wait for the cross-chain transfer to complete.

3. On the destination chain, call swapForBaseToken to perform the swap.

4. The base tokens will be sent back to your address on the original chain once the swap is completed.

Before calling these functions, ensure you have approved the FlitManager contract to spend your FTokens. The actual process may take some time due to the cross-chain nature of the transactions.

Note: Cross-chain operations incur additional fees due to the messaging between chains. Always check the current gas prices and cross-chain messaging fees before initiating a transfer or swap.

3.RESTful APIs for Liquidity Providers

To enhance the experience for Liquidity Providers (LPs), we've designed the following RESTful APIs:

Query Liquidity State

Endpoint: GET /api/v1/liquidity

This endpoint allows LPs to query the liquidity state of the AMM on supported chains and tokens.Response example:

{
    "data": {
        "1": { // Ethereum Mainnet
            "1": { // USDC
                "baseTokenAddress": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
                "fTokenAddress": "0x1234567890123456789012345678901234567890",
                "baseTokenReserve": "1000000000000",
                "fTokenReserve": "990000000000",
                "pendingOrdersCount": 5,
                "pendingOrdersValue": "10000000000"
            },
            "2": { // USDT
                "baseTokenAddress": "0xdAC17F958D2ee523a2206206994597C13D831ec7",
                "fTokenAddress": "0x0987654321098765432109876543210987654321",
                "baseTokenReserve": "500000000000",
                "fTokenReserve": "495000000000",
                "pendingOrdersCount": 3,
                "pendingOrdersValue": "5000000000"
            }
        },
        "137": { // Polygon
            "1": { // USDC
                "baseTokenAddress": "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174",
                "fTokenAddress": "0xabcdef1234567890abcdef1234567890abcdef12",
                "baseTokenReserve": "2000000000000",
                "fTokenReserve": "1980000000000",
                "pendingOrdersCount": 8,
                "pendingOrdersValue": "20000000000"
            }
        }
    },
    "message": "",
    "code": 200
}

An interface provided to lp to monitor the balance of the liquidity pool: https://github.com/sparklex-io/flit-contracts/blob/main/docs/lp.md

Last updated