Ambient Docs
  • Introduction to Ambient
  • Concepts
    • AMMs
    • Concentrated Liquidity
    • Knockout Liquidity
    • Governance & Policy
    • Surplus Collateral
    • Permissioned Pools
    • Account Abstraction
  • Users
    • Swaps
    • LP Positions
    • Surplus Collateral
    • Dynamic Fees
    • Knockout Positions
    • Initializing Pools
    • Gasless Transactions
    • External Routers
  • Governance & Policy
    • Ops & Treasury Multisigs
    • Policy
    • Upgrading Code
    • Emergency
  • Developers
    • Deployed Contracts
    • Token Transfers
    • Type Conventions
    • DEX Contract Interface
      • userCmd Callpaths
      • Swaps
        • Hot Path Swap Migration
          • Directly Calling CrocSwapDex
          • External Swap Router
      • Flat LP Calls
      • Long Form Orders
      • Knockout LP Calls
      • Pool Initialization
      • Surplus Collateral
      • Router Calls
      • Relayer Calls
    • Query Contracts
      • CrocQuery Contract
      • CrocImpact Contract
    • Logs and Queries
    • Libraries and APIs
      • SDK
      • Indexer API
      • Subgraph
Powered by GitBook
On this page
  1. Developers
  2. DEX Contract Interface

Pool Initialization

Pools can be initialized for a given pair by using callpath index 0:

userCmd(1, abi.encode(
  71,        // Fixed initPool subcode  
  base,      // address
  quote,     // address
  poolIdx,   // uint256
  price      // uint128
)

In addition to the fixed initPool command sub-code (71), the following parameters are passed to initialize a pool:

  • base - The address of the base token or virtual token

  • quote - The address of the quote token or virtual token

  • poolIdx - The arbitrary index of the pool type the user is swapping on.

  • price - The initial price in the pool. Represented as Q64.64 square root (see Type Conventions for description of how to represent prices)

Initializing a pool will require a permanent commitment of a small amount of base and quote tokens (based on the set newPoolLiquidity in the CrocSwapDex contract). Pool initialization will always try funding based on the user's surplus collateral. If insufficient will try to collect tokens directly.

Therefore user must either fund their surplus collateral, approve ERC20 tokens, or send sufficient quantity in msg.value of the call. (See Token Transfers for more information on these mechanics.)

PreviousKnockout LP CallsNextSurplus Collateral

Last updated 1 year ago