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
NotEnabledtrading 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.addLiquidityType
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
EnabledstatusOnly root can disable trading pair
token_a: Asset id A.token_b: Asset id B.
Namespace
api.tx.dex.disableTradingPairType
function disableTradingPair(
token_a: u32,
token_b: u32
)reenableTradingPair
Re enable a NotEnabled trading pair.
Requires LP token to be created and in the
NotEnabledstatusOnly root can enable a disabled trading pair
token_a: Asset id A.token_b: Asset id B.
Namespace
api.tx.dex.reenableTradingPairType
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
NotEnabledtrading 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.removeLiquidityType
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
setFeeTofee_to: the new account or None assigned to FeeTo.
Namespace
api.tx.dex.setFeeToType
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
swapExactTokensForTokenspath: 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.swapWithExactSupplyType
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
swapTokensForExactTokensamount_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.swapWithExactTargetType
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.feeToType
function feeTo(
): Option<SeedPrimitivesSignatureAccountId20>liquidityPool
Namespace
api.query.dex.liquidityPoolType
function liquidityPool(
PalletDexTradingPair
): (u128,u128)liquidityPoolLastK
Namespace
api.query.dex.liquidityPoolLastKType
function liquidityPoolLastK(
u32
): U256tradingPairLPToken
Namespace
api.query.dex.tradingPairLPTokenType
function tradingPairLPToken(
PalletDexTradingPair
): Option<u32>tradingPairStatuses
Namespace
api.query.dex.tradingPairStatusesType
function tradingPairStatuses(
PalletDexTradingPair
): PalletDexTradingPairStatusEvents
AddLiquidity
Add liquidity success. [who, asset_id_0, reserve_0_increment, asset_id_1, reserve_1_increment, share_increment, to]
Namespace
api.events.dex.AddLiquidityType
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.AddProvisionType
type AddProvision = {
param0: SeedPrimitivesSignatureAccountId20,
param1: u32,
param2: u128,
param3: u32,
param4: u128
}DisableTradingPair
Disable trading pair. [trading_pair]
Namespace
api.events.dex.DisableTradingPairType
type DisableTradingPair = {
param0: PalletDexTradingPair
}EnableTradingPair
Enable trading pair. [trading_pair]
Namespace
api.events.dex.EnableTradingPairType
type EnableTradingPair = {
param0: PalletDexTradingPair
}FeeToSet
Set FeeTo account success. [fee_to]
Namespace
api.events.dex.FeeToSetType
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.ProvisioningToEnabledType
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.RemoveLiquidityType
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.SwapType
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.ExcessiveSupplyAmountExpiredDeadline
The deadline has been missed
Namespace
api.errors.dex.ExpiredDeadlineIdenticalTokenAddress
Namespace
api.errors.dex.IdenticalTokenAddressInsufficientAmount
Insufficent amount
Namespace
api.errors.dex.InsufficientAmountInsufficientAmountA
Insufficient asset_a liquidity amount
Namespace
api.errors.dex.InsufficientAmountAInsufficientAmountB
Insufficient asset_b liquidity amount
Namespace
api.errors.dex.InsufficientAmountBInsufficientInputAmount
Insufficient input amount
Namespace
api.errors.dex.InsufficientInputAmountInsufficientLiquidity
Liquidity is not enough
Namespace
api.errors.dex.InsufficientLiquidityInsufficientLiquidityBurnt
Insufficient liquidity burnt
Namespace
api.errors.dex.InsufficientLiquidityBurntInsufficientOutputAmount
Insufficient output amount
Namespace
api.errors.dex.InsufficientOutputAmountInsufficientTargetAmount
Target amount is less to min_target_amount
Namespace
api.errors.dex.InsufficientTargetAmountInsufficientWithdrawnAmountA
Insufficient withdraw amount for token A
Namespace
api.errors.dex.InsufficientWithdrawnAmountAInsufficientWithdrawnAmountB
Insufficient withdraw amount for token B
Namespace
api.errors.dex.InsufficientWithdrawnAmountBInvalidAssetId
Invalid Asset id
Namespace
api.errors.dex.InvalidAssetIdInvalidConstantProduct
Invalid constant product K
Namespace
api.errors.dex.InvalidConstantProductInvalidInputAmounts
Must provide non-zero amount of liquidity
Namespace
api.errors.dex.InvalidInputAmountsInvalidLiquidityIncrement
The increment of liquidity is invalid
Namespace
api.errors.dex.InvalidLiquidityIncrementInvalidTradingPathLength
Invalid trading path length
Namespace
api.errors.dex.InvalidTradingPathLengthLiquidityProviderTokenNotCreated
The Liquidity Provider token does not exist
Namespace
api.errors.dex.LiquidityProviderTokenNotCreatedMustBeEnabled
Trading pair must be in Enabled status
Namespace
api.errors.dex.MustBeEnabledMustBeNotEnabled
Trading pair must be in NotEnabled status
Namespace
api.errors.dex.MustBeNotEnabledZeroSupplyAmount
The supply amount is zero
Namespace
api.errors.dex.ZeroSupplyAmountZeroTargetAmount
The target amount is zero
Namespace
api.errors.dex.ZeroTargetAmountConstants
defaultFeeTo
The default FeeTo account
Namespace
api.consts.dex.defaultFeeToType
type defaultFeeTo = Option<FrameSupportPalletId>dexBurnPalletId
The DEX's burn id, to provide for a redundant, unredeemable minter/burner address.
Namespace
api.consts.dex.dexBurnPalletIdType
type dexBurnPalletId = FrameSupportPalletIdgetExchangeFee
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.getExchangeFeeType
type getExchangeFee = (u32,u32)lpTokenDecimals
Liquidity pair default token decimals
Namespace
api.consts.dex.lpTokenDecimalsType
type lpTokenDecimals = u8tradingPathLimit
The limit for length of trading path
Namespace
api.consts.dex.tradingPathLimitType
type tradingPathLimit = u32JSON-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>): JsonJSON
{ "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>): JsonJSON
{ "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): JsonJSON
{ "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): JsonJSON
{ "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): TextJSON
{ "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): JsonJSON
{ "id":1, "jsonrpc":"2.0", "method":"dex_quote", "params":[amountA: u128, reserveA: u128, reserveB: u128] }