Skip to main content

Dex

Calls

addLiquidity

Add liquidity to Enabled trading pair, or add provision to Provisioning trading pair.

  • Add liquidity success will issue shares in current price which decided by the liquidity scale. Shares are temporarily not allowed to transfer and trade, it represents the proportion of assets in liquidity pool.

  • Add provision success will record the provision, issue shares to caller in the initial price when trading pair convert to Enabled.

  • Creates and enables TradingPair LP token if it does not exist for trading pair.

  • Fails to add liquidity for NotEnabled trading pair.

  • token_a: Asset id A.

  • token_b: Asset id B.

  • amount_a_desired: amount a desired to add.

  • amount_b_desired: amount b desired to add.

  • amount_a_min: amount a minimum willing to add.

  • amount_b_min: amount b minimum willing to add.

  • to: The recipient of the LP token. The caller is the default recipient if it is set to None.

  • deadline: The deadline of executing this extrinsic. The deadline won't be checked if it is set to None

Namespace

api.tx.dex.addLiquidity

Type

function addLiquidity(
  token_a: u32,
  token_b: u32,
  amount_a_desired: Compact<u128>,
  amount_b_desired: Compact<u128>,
  amount_a_min: Compact<u128>,
  amount_b_min: Compact<u128>,
  to: Option<SeedPrimitivesSignatureAccountId20>,
  deadline: Option<u32>
)

disableTradingPair

Disable an Enabled trading pair.

  • Requires LP token to be created and in the Enabled status

  • Only root can disable trading pair

  • token_a: Asset id A.

  • token_b: Asset id B.

Namespace

api.tx.dex.disableTradingPair

Type

function disableTradingPair(
  token_a: u32,
  token_b: u32
)

reenableTradingPair

Re enable a NotEnabled trading pair.

  • Requires LP token to be created and in the NotEnabled status

  • Only root can enable a disabled trading pair

  • token_a: Asset id A.

  • token_b: Asset id B.

Namespace

api.tx.dex.reenableTradingPair

Type

function reenableTradingPair(
  token_a: u32,
  token_b: u32
)

removeLiquidity

Remove liquidity from specific liquidity pool in the form of burning shares, and withdrawing currencies in trading pairs from liquidity pool in proportion, and withdraw liquidity incentive interest.

  • note: liquidity can still be withdrawn for NotEnabled trading pairs.

  • token_a: Asset id A.

  • token_b: Asset id B.

  • liquidity: liquidity amount to remove.

  • amount_a_min: minimum amount of asset A to be withdrawn from LP token.

  • amount_b_min: minimum amount of asset B to be withdrawn from LP token.

  • to: The recipient of the withdrawn token assets. The caller is the default recipient if it is set to None.

  • deadline: The deadline of executing this extrinsic. The deadline won't be checked if it is set to None

Namespace

api.tx.dex.removeLiquidity

Type

function removeLiquidity(
  token_a: u32,
  token_b: u32,
  liquidity: Compact<u128>,
  amount_a_min: Compact<u128>,
  amount_b_min: Compact<u128>,
  to: Option<SeedPrimitivesSignatureAccountId20>,
  deadline: Option<u32>
)

setFeeTo

Set the FeeTo account. This operation requires root access.

  • note: analogous to Uniswapv2 setFeeTo

  • fee_to: the new account or None assigned to FeeTo.

Namespace

api.tx.dex.setFeeTo

Type

function setFeeTo(
  fee_to: Option<SeedPrimitivesSignatureAccountId20>
)

swapWithExactSupply

Trading with DEX, swap with exact supply amount. Specify your input; retrieve variable output.

  • note: analogous to Uniswapv2 swapExactTokensForTokens

  • path: trading path.

  • amount_in: exact supply amount.

  • amount_out_min: acceptable minimum target amount.

  • to: The recipient of the swapped token asset. The caller is the default recipient if it is set to None.

  • deadline: The deadline of executing this extrinsic. The deadline won't be checked if it is set to None

Namespace

api.tx.dex.swapWithExactSupply

Type

function swapWithExactSupply(
  amount_in: Compact<u128>,
  amount_out_min: Compact<u128>,
  path: Vec<u32>,
  to: Option<SeedPrimitivesSignatureAccountId20>,
  deadline: Option<u32>
)

swapWithExactTarget

Trading with DEX, swap with exact target amount. Specify your output; supply variable input.

  • note: analogous to Uniswapv2 swapTokensForExactTokens

  • amount_out: exact target amount.

  • amount_in_max: acceptable maximum supply amount.

  • path: trading path.

  • to: The recipient of the swapped token asset. The caller is the default recipient if it is set to None.

  • deadline: The deadline of executing this extrinsic. The deadline won't be checked if it is set to None

Namespace

api.tx.dex.swapWithExactTarget

Type

function swapWithExactTarget(
  amount_out: Compact<u128>,
  amount_in_max: Compact<u128>,
  path: Vec<u32>,
  to: Option<SeedPrimitivesSignatureAccountId20>,
  deadline: Option<u32>
)

Storage

feeTo

FeeTo account where network fees are deposited

Namespace

api.query.dex.feeTo

Type

function feeTo(

): Option<SeedPrimitivesSignatureAccountId20>

liquidityPool

Namespace

api.query.dex.liquidityPool

Type

function liquidityPool(
  PalletDexTradingPair
): (u128,u128)

liquidityPoolLastK

Namespace

api.query.dex.liquidityPoolLastK

Type

function liquidityPoolLastK(
  u32
): U256

tradingPairLPToken

Namespace

api.query.dex.tradingPairLPToken

Type

function tradingPairLPToken(
  PalletDexTradingPair
): Option<u32>

tradingPairStatuses

Namespace

api.query.dex.tradingPairStatuses

Type

function tradingPairStatuses(
  PalletDexTradingPair
): PalletDexTradingPairStatus

Events

AddLiquidity

Add liquidity success. [who, asset_id_0, reserve_0_increment, asset_id_1, reserve_1_increment, share_increment, to]

Namespace

api.events.dex.AddLiquidity

Type

type AddLiquidity = {
  param0: SeedPrimitivesSignatureAccountId20,
  param1: u32,
  param2: u128,
  param3: u32,
  param4: u128,
  param5: u128,
  param6: SeedPrimitivesSignatureAccountId20
}

AddProvision

Add provision success. [who, asset_id_0, contribution_0, asset_id_1, contribution_1]

Namespace

api.events.dex.AddProvision

Type

type AddProvision = {
  param0: SeedPrimitivesSignatureAccountId20,
  param1: u32,
  param2: u128,
  param3: u32,
  param4: u128
}

DisableTradingPair

Disable trading pair. [trading_pair]

Namespace

api.events.dex.DisableTradingPair

Type

type DisableTradingPair = {
  param0: PalletDexTradingPair
}

EnableTradingPair

Enable trading pair. [trading_pair]

Namespace

api.events.dex.EnableTradingPair

Type

type EnableTradingPair = {
  param0: PalletDexTradingPair
}

FeeToSet

Set FeeTo account success. [fee_to]

Namespace

api.events.dex.FeeToSet

Type

type FeeToSet = {
  param0: Option<SeedPrimitivesSignatureAccountId20>
}

ProvisioningToEnabled

Provisioning trading pair convert to Enabled. [trading_pair, pool_0_amount, pool_1_amount, total_share_amount]

Namespace

api.events.dex.ProvisioningToEnabled

Type

type ProvisioningToEnabled = {
  param0: PalletDexTradingPair,
  param1: u128,
  param2: u128,
  param3: u128
}

RemoveLiquidity

Remove liquidity from the trading pool success. [who, asset_id_0, reserve_0_decrement, asset_id_1, reserve_1_decrement, share_decrement, to]

Namespace

api.events.dex.RemoveLiquidity

Type

type RemoveLiquidity = {
  param0: SeedPrimitivesSignatureAccountId20,
  param1: u32,
  param2: u128,
  param3: u32,
  param4: u128,
  param5: u128,
  param6: SeedPrimitivesSignatureAccountId20
}

Swap

Use supply Asset to swap target Asset. [trader, trading_path, supply_Asset_amount, target_Asset_amount, to]

Namespace

api.events.dex.Swap

Type

type Swap = {
  param0: SeedPrimitivesSignatureAccountId20,
  param1: Vec<u32>,
  param2: u128,
  param3: u128,
  param4: SeedPrimitivesSignatureAccountId20
}

Errors

ExcessiveSupplyAmount

Supply amount is more than max_supply_amount

Namespace

api.errors.dex.ExcessiveSupplyAmount

ExpiredDeadline

The deadline has been missed

Namespace

api.errors.dex.ExpiredDeadline

IdenticalTokenAddress

Namespace

api.errors.dex.IdenticalTokenAddress

InsufficientAmount

Insufficent amount

Namespace

api.errors.dex.InsufficientAmount

InsufficientAmountA

Insufficient asset_a liquidity amount

Namespace

api.errors.dex.InsufficientAmountA

InsufficientAmountB

Insufficient asset_b liquidity amount

Namespace

api.errors.dex.InsufficientAmountB

InsufficientInputAmount

Insufficient input amount

Namespace

api.errors.dex.InsufficientInputAmount

InsufficientLiquidity

Liquidity is not enough

Namespace

api.errors.dex.InsufficientLiquidity

InsufficientLiquidityBurnt

Insufficient liquidity burnt

Namespace

api.errors.dex.InsufficientLiquidityBurnt

InsufficientOutputAmount

Insufficient output amount

Namespace

api.errors.dex.InsufficientOutputAmount

InsufficientTargetAmount

Target amount is less to min_target_amount

Namespace

api.errors.dex.InsufficientTargetAmount

InsufficientWithdrawnAmountA

Insufficient withdraw amount for token A

Namespace

api.errors.dex.InsufficientWithdrawnAmountA

InsufficientWithdrawnAmountB

Insufficient withdraw amount for token B

Namespace

api.errors.dex.InsufficientWithdrawnAmountB

InvalidAssetId

Invalid Asset id

Namespace

api.errors.dex.InvalidAssetId

InvalidConstantProduct

Invalid constant product K

Namespace

api.errors.dex.InvalidConstantProduct

InvalidInputAmounts

Must provide non-zero amount of liquidity

Namespace

api.errors.dex.InvalidInputAmounts

InvalidLiquidityIncrement

The increment of liquidity is invalid

Namespace

api.errors.dex.InvalidLiquidityIncrement

InvalidTradingPathLength

Invalid trading path length

Namespace

api.errors.dex.InvalidTradingPathLength

LiquidityProviderTokenNotCreated

The Liquidity Provider token does not exist

Namespace

api.errors.dex.LiquidityProviderTokenNotCreated

MustBeEnabled

Trading pair must be in Enabled status

Namespace

api.errors.dex.MustBeEnabled

MustBeNotEnabled

Trading pair must be in NotEnabled status

Namespace

api.errors.dex.MustBeNotEnabled

ZeroSupplyAmount

The supply amount is zero

Namespace

api.errors.dex.ZeroSupplyAmount

ZeroTargetAmount

The target amount is zero

Namespace

api.errors.dex.ZeroTargetAmount

Constants

defaultFeeTo

The default FeeTo account

Namespace

api.consts.dex.defaultFeeTo

Type

type defaultFeeTo = Option<FrameSupportPalletId>

dexBurnPalletId

The DEX's burn id, to provide for a redundant, unredeemable minter/burner address.

Namespace

api.consts.dex.dexBurnPalletId

Type

type dexBurnPalletId = FrameSupportPalletId

getExchangeFee

Trading fee rate The first item of the tuple is the numerator of the fee rate, second item is the denominator, fee_rate = numerator / denominator, use (u32, u32) over Rate type to minimize internal division operation.

Namespace

api.consts.dex.getExchangeFee

Type

type getExchangeFee = (u32,u32)

lpTokenDecimals

Liquidity pair default token decimals

Namespace

api.consts.dex.lpTokenDecimals

Type

type lpTokenDecimals = u8

tradingPathLimit

The limit for length of trading path

Namespace

api.consts.dex.tradingPathLimit

Type

type tradingPathLimit = u32

JSON-RPC Methods

getAmountsIn

Given an array of AssetIds, return amounts in for an amount out

Interface

api.rpc.dex.getAmountsIn(amountOut: u128, path: Vec<AssetId>): Json

JSON

{ "id":1, "jsonrpc":"2.0", "method":"dex_getAmountsIn", "params":[amountOut: u128, path: Vec<AssetId>] }

getAmountsOut

Given an array of AssetIds, return amounts out for an amount in

Interface

api.rpc.dex.getAmountsOut(amountIn: u128, path: Vec<AssetId>): Json

JSON

{ "id":1, "jsonrpc":"2.0", "method":"dex_getAmountsOut", "params":[amountIn: u128, path: Vec<AssetId>] }

getLPTokenID

Given two AssetIds, return liquidity token created for the pair

Interface

api.rpc.dex.getLPTokenID(assetA: AssetId, assetB: AssetId): Json

JSON

{ "id":1, "jsonrpc":"2.0", "method":"dex_getLPTokenID", "params":[assetA: AssetId, assetB: AssetId] }

getLiquidity

Given two AssetIds, return liquidity

Interface

api.rpc.dex.getLiquidity(assetA: AssetId, assetB: AssetId): Json

JSON

{ "id":1, "jsonrpc":"2.0", "method":"dex_getLiquidity", "params":[assetA: AssetId, assetB: AssetId] }

getTradingPairStatus

Given two AssetIds, return whether trading pair is enabled or disabled

Interface

api.rpc.dex.getTradingPairStatus(assetA: AssetId, assetB: AssetId): Text

JSON

{ "id":1, "jsonrpc":"2.0", "method":"dex_getTradingPairStatus", "params":[assetA: AssetId, assetB: AssetId] }

quote

Given some amount of an asset and pair reserves, returns an equivalent amount of the other asset

Interface

api.rpc.dex.quote(amountA: u128, reserveA: u128, reserveB: u128): Json

JSON

{ "id":1, "jsonrpc":"2.0", "method":"dex_quote", "params":[amountA: u128, reserveA: u128, reserveB: u128] }