Skip to main content

Overview

This guide teaches you how to build your own liquidity provider service from scratch. You’ll learn the complete technical flow for:
  1. Polling for quote requests from users
  2. Calculating and submitting competitive quotes
  3. Monitoring for quote acceptance
  4. Executing the on-chain order fulfillment
  5. Settling cross-chain via LayerZero
  6. Withdrawing your earned fees
By the end, you’ll understand how to implement a production-ready LP service that earns 3-15 basis points per swap.
This is a technical implementation guide. You should be comfortable with TypeScript, blockchain transactions, and smart contract interactions.

Prerequisites

  • Blockchain development experience: Understanding of transactions, gas, signatures
  • TypeScript/JavaScript knowledge
  • Web3 library: Viem, ethers.js, or web3.js
  • Funded wallet with gas tokens and stablecoins on multiple chains
  • API key from Lidian Developer Portal

Core Concepts

The LP Business Model

As an LP, you profit from the spread between input and output amounts:

The Order Lifecycle

Step 1: Poll for Quote Requests

Fetch Quote Requests from API

Continuous Polling Loop

Step 2: Calculate Quote with Fee

Fee Structure

Different tokens have different basis point fees:

Calculate Output Amount

Check Liquidity Availability

Step 3: Submit Quote to API

Create Quote Object

Handle Quote Request (Complete Flow)

Step 4: Monitor for Quote Acceptance

Poll for Order Creation

When a user accepts your quote, they sign the order and create it in the API:

Fetch Order Details

Step 5: Execute Deposit on Source Chain

Build Order Struct for Contract

Call deposit() on Lidian Contract

Important: The deposit transaction uses the user’s signature to pull tokens from their wallet. The LP does not need to hold the input tokens.

Step 6: Execute Fill on Destination Chain

Approve Token Spending (if needed)

Call fill() on Destination Chain

After fill, the LP’s output tokens are locked in the destination chain contract. You must complete settlement to unlock your funds on the source chain.

Step 7: Settle via LayerZero

Quote LayerZero Fee

Execute Settlement

Settlement triggers a LayerZero cross-chain message. It takes ~30-60 seconds for the message to be delivered and verified on the source chain.

Step 8: Withdraw Funds + Fee

Wait for Settlement Delivery

Execute Withdrawal

Complete Implementation Example

Profit Calculation

After completing an order, calculate your earnings:

Production Considerations

Error Handling

Balance Monitoring

Nonce Management

Testing Your Implementation

Testnet Setup

  1. Get testnet tokens from faucets:
  2. Fund your LP wallet with:
    • Gas tokens (ETH, MATIC)
    • Stablecoins (USDC, USDT)
  3. Test with small amounts first:
    • Start with $1-10 swaps
    • Verify all transactions succeed
    • Check balance updates

Debug Logging

Contract Addresses

Testnet Contracts

Next Steps

Now that you understand the implementation:
  1. Build your service using this guide as a reference
  2. Test thoroughly on testnets before mainnet
  3. Monitor performance and optimize for your use case
  4. Scale gradually as you gain confidence
For production API keys and support, contact the Lidian team.

Additional Resources