⚙️
Native Developers
  • Native V1
    • Overview
    • Operations
      • Single-Hop Transaction: Off-chain Pricing
      • Single-Hop Transaction: On-chain Pricing
      • Multi-Hop Transaction
      • L1 Token Swap
      • Creating a Pool
      • Updating a Pool
    • System Components
      • GUI
      • Native Backend
      • Pricer
      • Registry
      • Signer
      • Pool
      • Pool Factory
      • Treasury
      • Router
    • Smart Contracts
      • Core
        • Registry
        • NativePool
        • NativePoolFactory
        • NativeRouter
      • Liquidity Pools
    • Contract Address
    • API References
      • GET /v1/indicative-quote
      • GET /v1/orderbook
      • GET v1/firm-quote
      • GET v1/firm-quote/calldata
    • Guide
      • Get quote for ETH to USDT
      • Execute ETH to USDT swap on Native
    • Routing
  • Market Maker Integration
    • WebSocket Connection
Powered by GitBook
On this page
  1. Native V1
  2. Operations

Single-Hop Transaction: Off-chain Pricing

PreviousOperationsNextSingle-Hop Transaction: On-chain Pricing

Last updated 2 years ago

A general process for swap on Native is that when user inputs an amount, Native queries the backend to get an indicative quote. When user confirms the swap, Native will query the backend again, and execute with the firm quote with the Router.

Detailed Steps

  1. User selects desired tokens to swap and fill in the desired amount to swap in the GUI

  2. The Get Indicative Quote API in the GUI will ask the Native Backend for the indicative quote

  3. The Native Backend will in turn call its Get Indicative Quote API to ask the Pricer for an indicative quote

  4. The Pricer will check for the pricing model of the selected trading pair. In this case, it is using off-chain pricing

  5. The Pricer will do an off-chain calculation for the price and return an indicative quote to the Native Backend

  6. The Native Backend will return the the indicative quote to the GUI which would then display the quote to the user

  7. At the same time that the Get Indicative Quote API in the GUI is called, the Get Sign Quote API is also called

  8. It follows the same flow as getting the indicative quote with the exception that it will get the quote signed by the Signer

  9. This signed quote is used to run the estimatedGas function to estimate the gas fee required for the transaction and displayed in the GUI

  10. User clicks on "Swap" in the GUI

  11. The Get Firm Quote API is called. An order is created in the Native database and the GUI will ask the Native Backend for a firm quote

  12. The Native Backend will in turn ask the Pricer for a firm quote

  13. The firm quote is returned from the Pricer and sent to the Signer to be signed

  14. The signed quote is returned from the Signer then to the Native backend then to the GUI

  15. The User Wallet will be prompted to sign the transaction

  16. With the signed transaction, the GUI will call the Router contract to trigger the swap() function in the Pool

  17. Using the safeTransferFrom() function of the Pool, assets are transferred from the Treasury to the User Wallet

  18. The swapCallback() function in the Router is called to transfer assets from the User Wallet to the Pool

  19. The safeTransferFrom() function is used again to transfer assets from the Pool to the Treasury

  20. After the swapping is done, there is a check to make sure the slippage for the entire transaction is within the slippage threshold set by the user. If yes, the swap is completed. If no, the transaction will be reverted

off-chain pricing