LogoLogo
  • Introduction to Unizen
    • Unizen Overview
      • Unizen Liquidity Distribution Mechanism (ULDM)
        • ULDM Performance
      • Unizen Interoperability Protocol (UIP)
        • LayerZero
        • DeBridge
        • Stargate
        • Celer
        • Axelar
        • Thorchain
    • Unizen Dashboard
      • General
      • Portfolio
      • History
    • Unizen Trade
      • Fees
    • Unizen Explore
      • Unizen Omni-Chain Data Pool
    • Unizen Earn
  • ZCX
    • Token Utility
    • Tokenomics
  • API - Introduction
    • Introduction
    • Before you get started
      • Understanding Price Impact and Price Slippage in Token Swaps
      • Token Allowance Management for Non-updatable Allowance Tokens
      • Tokens with taxes
      • Wrapping and Unwrapping Native Tokens
      • Quote expiration deadline
    • Security Best Practices for Integrating Unizen
      • Why disable CORS
      • How to integrate with a reverse proxy
    • Version 2 of our smart contracts
      • Migration to smart contract v2
  • API - GET STARTED
    • QuickStart guide
    • Swagger
    • Information endpoints
      • GET /trade/v1/info/chains
      • GET /trade/v1/info/sources
      • GET/v1/info/cross-providers
      • GET /trade/v1/info/token/search
      • GET /v1/info/token/popular
      • GET /trade/v1/info/token/{chainId}/{tokenAddress}
      • GET /trade/v1/info/tokenLogo/{chainId}/{tokenAddress}
      • GET /info/thorchain-inbound-address
      • GET /trade/v1/info/tx/{txHash}
      • GET /trade/v1/info/trade/{chainId}/{txHash}
      • GET /trade/v1/info/trades
    • Approval
      • GET /trade/v1/{chainId}/approval/spender
      • GET /trade/v1/{chainId}/approval/transaction
      • GET /trade/v1/{chainId}/approval/allowance
    • Single-Chain Swap
      • GET /trade/v1/{chainId}/quote/single
      • GET /trade/v1/{chainId}/swap/single
      • Send transaction in evm chains
      • Send transaction in Solana
    • Cross-Chain Swap
      • GET /trade/v1/{chainId}/quote/cross
      • GET /trade/v1/{chainId}/swap/cross
      • Send transaction
    • Gasless orders
      • POST /trade/v1/gasless/typed-data
      • POST /v1/gasless/estimate
      • POST /v1/gasless/create
      • POST /v1/gasless/cancel
      • GET /trade/v1/gasless/status/{orderId}
      • GET /v1/gasless/orderByAddress/{address}
    • UTXO Assets and Cosmos Swap
      • GET /trade/v1/{chainId}/quote/cross 1
      • GET /trade/v1/{chainId}/swap/cross
      • Sending transactions
    • Efficient Quote Retrieval with Batch Processing
      • GET /trade/v1/{chainId}/batch_quote/single
    • Error Messages
  • GASLESS TRADES
    • Obtaining gasless quotes
    • Gas estimation
    • Executing the trade
    • Following the orders
  • On-Chain Contracts - Get Started
    • Integration with Unizen Contracts for Token Swapping
    • Registering Errors on Smart Contract Calls
  • PERMIT2
    • What is Permit2?
    • Usage in our api
  • WIDGET - Get Started
    • Embed the Unizen Widget
    • Playground
  • Other
    • Smart Contracts
    • Security Audits
    • Roadmap
  • links
    • Unizen
    • Marketing Website
    • Medium
    • Twitter
    • Discord
    • Telegram
Powered by GitBook
On this page

Was this helpful?

  1. GASLESS TRADES

Executing the trade

The gasless trade has to be executed by us, given that we pay the gas instead of the user

Gasless Trading Flow

To perform a gasless trade, follow these steps using the gasless endpoints:


1. Retrieve Typed Data

Endpoint: /v1/gasless/typed-data Send a request with the trade details to this endpoint to retrieve the structured data required for the user to sign.

Request:

{
    "transactionData": {
        "info": {
            "feeReceiver": "0xf4AA7a82B1d7f30Ca22D306c5eC429CF8AF160ef",
            "feePercent": 0,
            ...
        },
        "call": [
            {
                "targetExchange": "0x1F721E2E82F6676FCE4eA07A5958cF098D339e18",
                "targetExchangeID": "camelotv3",
                "sellToken": "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9",
                "buyToken": "0x0000000000000000000000000000000000000000",
                "amountDelta": "1972679740777741",
                "amount": "6603531",
                "data": "0xac9650d80000...00000000000000000"
            }
        ],
        "version": "v2",
        "amountInAfterFee": "6603531",
        "amountInBeforeFee": "6623429",
        "fee": "19898"
    },
    "sender": "0x2472d3EF4bF71af00c3dE490a5a53A99CbAC0791",
    "chainId": 42161
}

Response:

{
    "account": "0x2472d3EF4bF71af00c3dE490a5a53A99CbAC0791",
    "domain": {
        "name": "GasLessExecutor",
        "version": "1",
        "chainId": 42161,
        "verifyingContract": "0x9BCd841436ef4f85dacefB1aEc772aF71619024e"
    },
    "types": {
        "UnizenGasLessOrder": [
            {
                "name": "user",
                "type": "address"
            },
            ...
        ]
    },
    "primaryType": "UnizenGasLessOrder",
    "message": {
        "user": "0x2472d3EF4bF71af00c3dE490a5a53A99CbAC0791",
        "receiver": "0x2472d3EF4bF71af00c3dE490a5a53A99CbAC0791",
        "srcToken": "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9",
        "dstToken": "0x0000000000000000000000000000000000000000",
        "amountIn": "6623429",
        "fee": "19898",
        "amountOutMin": "1972679740777741",
        "deadline": 1734963690,
        "tradeHash": "0x8748ade4edde06...e40b4dbc11fa47"
    }
}

2. User Signs the Typed Data

After receiving the typedData structure, the user must sign it using their wallet or signing tool (e.g., MetaMask, hardware wallets). This signature proves the user’s intent to perform the trade.


3. Create the Order

Endpoint: /v1/gasless/create Send the signature obtained from the user, along with the trade details, to this endpoint to create the order.

Request:

{
    "chainFrom": 42161,
    "order": { // result of /v1/gasless/typed-data (message object)
        "user": "0x2472d3EF4bF71af00c3dE490a5a53A99CbAC0791",
        "receiver": "0x2472d3EF4bF71af00c3dE490a5a53A99CbAC0791",
        "srcToken": "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9",
        "dstToken": "0x0000000000000000000000000000000000000000",
        "amountIn": "6623429",
        "fee": "19898",
        "amountOutMin": "1972679740777741",
        "deadline": 1734963690,
        "tradeHash": "0x8748ade4edde06...e40b4dbc11fa47"
    },
    "call": [ // call array from transactionData object of the quote 
        {
            "targetExchange": "0x1F721E2E82F6676FCE4eA07A5958cF098D339e18",
            "targetExchangeID": "camelotv3",
            "sellToken": "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9",
            "buyToken": "0x0000000000000000000000000000000000000000",
            "amountDelta": "1972679740777741",
            "amount": "6603531",
            "data": "0xac9650d8000000000000000000000...00000000"
        }
    ],
    "permitData": { // if use Permit2
        "user": "0x2472d3EF4bF71af00c3dE490a5a53A99CbAC0791",
        "amount": "6623429",
        "deadline": 1734963223,
        "nonce": 569626219515420,
        "sign": "0xb43dbbcdcf610ff77fd17ab0630d5e85391086...04121f1b"
    },
    "signature": "0x2728c5bd1d666623533d899f6f6...7387b9e41c" // signature from step 2
}

Response:

{"orderId":"561e1e2f-c32b-48c7-bb85-b9bc599d4d91"}

Once the order is created, it will be processed by our gasless trade processor. The system will cover the gas fees and execute the trade on behalf of the user.


4. Cancel the Order (Optional)

If the order has not been processed yet (this typically happens very quickly), it can be cancelled.

Endpoint: /v1/gasless/cancel

Request:

{
  "orderId": "12345"
}

Response:

{
  "success": true,
  "message": "Order cancelled successfully"
}

Summary of Workflow

  1. Call /v1/gasless/typed-data: Retrieve the structured data for the user to sign.

  2. User Signs the Data: Obtain a valid signature from the user.

  3. Call /v1/gasless/create: Create the gasless order using the signature and trade details.

  4. (Optional) Cancel the Order: If necessary, call /v1/gasless/cancel to cancel the order before it is processed.


Key Notes

  • Speed: Orders are typically processed very quickly, minimizing the need for cancellations.

  • Security: User signatures ensure the trade is authorized and secure.

  • Gasless Execution: All gas fees are handled by the system, simplifying the process for the user.

For further details or troubleshooting, refer to the full API documentation or contact support. 🚀

PreviousGas estimationNextFollowing the orders

Last updated 4 months ago

Was this helpful?