Hyperion Docs
  • Home
  • Overview
    • Introduction
    • Contact
    • Glossary
    • Roadmap
  • Concepts
    • Concentrated Liquidity
    • Fees
    • Swap
    • Liquidity Mining
    • Range Order
    • Drips
  • Guides
    • FAQ
    • How to Swap
    • How to Create New Position
    • How to Add/Remove Liquidity
    • How to Create a New Pool
    • How to Place a Limit Order
  • Developer
    • Dev Overview
    • via SDK
      • Getting Started
      • Prerequisites
      • Features Available
        • Get pools
        • Get positions
        • Get ticks
        • Create pool
        • Add Liquidity
        • Remove Liquidity
        • Fee & Rewards
        • Swap
        • Types
    • via Contract
      • Get Started
      • Data structure
      • Features available
        • Create pool
        • Swap
        • Open position
        • Add liquidity
        • Remove liquidity
        • Collect fees
        • Collect rewards
    • via API
    • Contract ErrorCode
  • Security
    • Audits
  • Resource
    • Brand Asset
Powered by GitBook
On this page
  • 1. Create a pool with some initial liquidity to be added
  • Function input params
  • Example
  1. Developer
  2. via SDK
  3. Features Available

Create pool

PreviousGet ticksNextAdd Liquidity

Last updated 2 months ago

1. Create a pool with some initial liquidity to be added

use sdk.pool.createPoolTransactionPayload method.

Function input params

  • currencyA: coin/fa type of currency token

  • currencyB: coin/fa type of currency token

  • currencyAAmount: the amount about currency A, which used to add liquidity

  • currencyBAmount: the amount about currency B, which used to add liquidity

  • feeRateTier: Fee Rate Tier will affect price precision. Now mainnet exist some different type FeeRateTier, the correspond to different fee rates.

  • currentPriceTick : The tick corresponds to the current price.

  • tickLower : The tick corresponds to the lower price.

  • tickUpper : The tick corresponds to the upper price.

  • SDK provided a util function `priceToTick` for the calculation from price to tick.

  • -443636 < tickLowerIndex < currentPriceTickIndex<tickUpperIndex < 443636, 443636 is a constant, derived from the maximum range representable by the Q32.62 fixed-point number format.

  • Currently, creating a pool requires adding bidirectional liquidity.

  • slippage : slippage value. 0.1 means 0.1%

Example


import { FeeTierIndex, roundTickBySpacing } from "@hyperionxyz/sdk";

const currencyAAmount = Math.pow(10, 8);
// currencyA's decimals is 8
// currencyB's decimals is 6
const decimalsRatio = Math.pow(10, 8 - 6);
const feeTierIndex = FeeTierIndex["PER_0.05_SPACING_5"]

const currentPriceTick = priceToTick({
  price: 995,
  feeTierIndex,
  decimalsRatio,
})

const tickLower = priceToTick({
  price: 992,
  feeTierIndex,
  decimalsRatio,
})

const tickUpper = priceToTick({
  price: 1336,
  feeTierIndex,
  decimalsRatio,
})

const [_, currencyBAmount] = await sdk.Pool.estCurrencyBAmountFromA({
  // address here mus be fa type
  currencyA: "0xa",
  currencyB:
    "0xc5bcdea4d8a9f5809c5c945a3ff5698a347afb982c7389a335100e1b0043d115",
  currencyAAmount,
  feeTierIndex,
  tickLower,
  tickUpper,
  currentPriceTick,
});

const params = {
  currencyA: "0x1::aptos_coin::AptosCoin",
  currencyB:
    "0x6926bff1eab5554fa72ae167ed736acf623ab17fe81ebf2ea0d2138f8c533f77::type::T",
  currencyAAmount,
  currencyBAmount,
  feeTierIndex,
  currentPriceTick,
  tickLower,
  tickUpper,
  slippage: 0.1
};

// generate payload
const payload = await sdk.Pool.createPoolTransactionPayload(params)
/*
{
  "function": "0xdd8d1a676801c6789fac9a06b8f6ced76f766c798f7e5ea276f25d80b9aa0af0::router_adapter::create_liquidity_both_coin_entry",
  "typeArguments": [
    "0x1::aptos_coin::AptosCoin",
    "0x6926bff1eab5554fa72ae167ed736acf623ab17fe81ebf2ea0d2138f8c533f77::type::T"
  ],
  "functionArguments": [
    1,
    false,
    22410,
    25930,
    22940,
    100000000,
    200287120,
    99900000,
    200086833,
    4891474469
  ]
}
*/

Tick spacing
Fee Rate
FeeTierIndex

1

0.01%

0

5

0.05%

1

60

0.3%

2

200

1%

3