interbtc-api

@interlay/interbtc-api / Exports / DefaultAMMAPI

Class: DefaultAMMAPI

Implements

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new DefaultAMMAPI(api, tokensAPI): DefaultAMMAPI

Parameters

Name Type
api ApiPromise
tokensAPI TokensAPI

Returns

DefaultAMMAPI

Defined in

src/parachain/amm.ts:197

Properties

api

Private api: ApiPromise

Defined in

src/parachain/amm.ts:197


tokensAPI

Private tokensAPI: TokensAPI

Defined in

src/parachain/amm.ts:197

Methods

_getClaimableFarmingRewardsByPool

_getClaimableFarmingRewardsByPool(accountId, lpToken): Promise<MonetaryAmount<CurrencyExt>[]>

Parameters

Name Type
accountId AccountId
lpToken LpCurrency

Returns

Promise<MonetaryAmount<CurrencyExt>[]>

Defined in

src/parachain/amm.ts:607


_getFarmingRewardCurrencyIds

_getFarmingRewardCurrencyIds(lpTokenCurrencyId): Promise<InterbtcPrimitivesCurrencyId[]>

Parameters

Name Type
lpTokenCurrencyId InterbtcPrimitivesCurrencyId

Returns

Promise<InterbtcPrimitivesCurrencyId[]>

Defined in

src/parachain/amm.ts:597


_getLiquidityDepositStablePoolParams

_getLiquidityDepositStablePoolParams(amounts, pool, maxSlippageComplement, deadline, recipient): ExtrinsicData

Parameters

Name Type
amounts PooledCurrencies
pool StableLiquidityPool
maxSlippageComplement number
deadline number
recipient AddressOrPair

Returns

ExtrinsicData

Defined in

src/parachain/amm.ts:706


_getLiquidityDepositStandardPoolParams

_getLiquidityDepositStandardPoolParams(amounts, pool, maxSlippageComplement, deadline): ExtrinsicData

Parameters

Name Type
amounts PooledCurrencies
pool StandardLiquidityPool
maxSlippageComplement number
deadline number

Returns

ExtrinsicData

Defined in

src/parachain/amm.ts:670


_getLiquidityWithdrawalStablePoolParams

_getLiquidityWithdrawalStablePoolParams(amount, pool, maxSlippageComplement, recipient, deadline): ExtrinsicData

Parameters

Name Type
amount MonetaryAmount<StableLpToken>
pool StableLiquidityPool
maxSlippageComplement number
recipient AddressOrPair
deadline number

Returns

ExtrinsicData

Defined in

src/parachain/amm.ts:830


_getLiquidityWithdrawalStandardPoolParams

_getLiquidityWithdrawalStandardPoolParams(amount, pool, maxSlippageComplement, recipient, deadline): ExtrinsicData

Parameters

Name Type
amount MonetaryAmount<StandardLpToken>
pool StandardLiquidityPool
maxSlippageComplement number
recipient AddressOrPair
deadline number

Returns

ExtrinsicData

Defined in

src/parachain/amm.ts:806


_getPoolRewardAmountsYearly

_getPoolRewardAmountsYearly(lpTokenCurrencyId, blockTimeMs): Promise<MonetaryAmount<CurrencyExt>[]>

Parameters

Name Type
lpTokenCurrencyId InterbtcPrimitivesCurrencyId
blockTimeMs number

Returns

Promise<MonetaryAmount<CurrencyExt>[]>

Defined in

src/parachain/amm.ts:276


_getStableBasePooledCurrenciesAdjustedToLpTokenAmount

_getStableBasePooledCurrenciesAdjustedToLpTokenAmount(basePooledCurrencies, lpTokenTotalSupply, metaPoolLpTokenAmount): MonetaryAmount<CurrencyExt>[]

Parameters

Name Type
basePooledCurrencies PooledCurrencies
lpTokenTotalSupply MonetaryAmount<StableLpToken>
metaPoolLpTokenAmount MonetaryAmount<StableLpToken>

Returns

MonetaryAmount<CurrencyExt>[]

Defined in

src/parachain/amm.ts:395


_getStableLiquidityPool

_getStableLiquidityPool(poolId, poolData, blockTimeMs, metaPoolLpTokenAmount?): Promise<null | StableLiquidityPool>

Parameters

Name Type
poolId number
poolData DexStablePrimitivesPool
blockTimeMs number
metaPoolLpTokenAmount? MonetaryAmount<StableLpToken>

Returns

Promise<null | StableLiquidityPool>

Defined in

src/parachain/amm.ts:472


_getStableLiquidityPoolData

_getStableLiquidityPoolData(poolId, poolData, blockTimeMs, metaPoolLpTokenAmount?): Promise<null | { actuallyPooledCurrencies: MonetaryAmount<CurrencyExt>[] ; amplificationCoefficient: Big ; lpToken: StableLpToken ; totalSupply: MonetaryAmount<StableLpToken> ; tradingFee: Big ; yearlyRewards: MonetaryAmount<CurrencyExt>[] }>

Parameters

Name Type
poolId number
poolData DexStablePrimitivesPool
blockTimeMs number
metaPoolLpTokenAmount? MonetaryAmount<StableLpToken>

Returns

Promise<null | { actuallyPooledCurrencies: MonetaryAmount<CurrencyExt>[] ; amplificationCoefficient: Big ; lpToken: StableLpToken ; totalSupply: MonetaryAmount<StableLpToken> ; tradingFee: Big ; yearlyRewards: MonetaryAmount<CurrencyExt>[] }>

Defined in

src/parachain/amm.ts:404


_getStableLpTokens

_getStableLpTokens(): Promise<StableLpToken[]>

Returns

Promise<StableLpToken[]>

Defined in

src/parachain/amm.ts:233


_getStableMetaPoolBasePool

_getStableMetaPoolBasePool(poolData, pooledCurrencies, blockTimeMs): Promise<StableLiquidityPool>

Parameters

Name Type
poolData DexStablePrimitivesMetaPool
pooledCurrencies PooledCurrencies
blockTimeMs number

Returns

Promise<StableLiquidityPool>

Defined in

src/parachain/amm.ts:442


_getStablePoolAmplificationCoefficient

_getStablePoolAmplificationCoefficient(poolId): Promise<Big>

Parameters

Name Type
poolId number

Returns

Promise<Big>

Defined in

src/parachain/amm.ts:380


_getStablePoolPooledCurrencies

_getStablePoolPooledCurrencies(currencyIds, balances): Promise<MonetaryAmount<CurrencyExt>[]>

Parameters

Name Type
currencyIds InterbtcPrimitivesCurrencyId[]
balances u128[]

Returns

Promise<MonetaryAmount<CurrencyExt>[]>

Defined in

src/parachain/amm.ts:365


_getStandardLiquidityPool

_getStandardLiquidityPool(pairCurrencies, lpTokenCurrencyId, pairStatus, blockTimeMs): Promise<null | StandardLiquidityPool>

Parameters

Name Type
pairCurrencies [InterbtcPrimitivesCurrencyId, InterbtcPrimitivesCurrencyId]
lpTokenCurrencyId InterbtcPrimitivesCurrencyId
pairStatus DexGeneralPrimitivesPairStatus
blockTimeMs number

Returns

Promise<null | StandardLiquidityPool>

Defined in

src/parachain/amm.ts:293


_getStandardLpTokens

_getStandardLpTokens(): Promise<StandardLpToken[]>

Returns

Promise<StandardLpToken[]>

Defined in

src/parachain/amm.ts:222


_getStandardPoolReserveBalances

_getStandardPoolReserveBalances(token0, token1, pairAccount): Promise<[MonetaryAmount<CurrencyExt>, MonetaryAmount<CurrencyExt>]>

Parameters

Name Type
token0 CurrencyExt
token1 CurrencyExt
pairAccount AccountId

Returns

Promise<[MonetaryAmount<CurrencyExt>, MonetaryAmount<CurrencyExt>]>

Defined in

src/parachain/amm.ts:261


_poolHasZeroLiquidity

_poolHasZeroLiquidity(pooledCurrencies): boolean

Parameters

Name Type
pooledCurrencies PooledCurrencies

Returns

boolean

Defined in

src/parachain/amm.ts:257


_swapThroughStandardAndStablePools

_swapThroughStandardAndStablePools(trade, minimumAmountOut, recipient, deadline): ExtrinsicData

Parameters

Name Type
trade Trade
minimumAmountOut MonetaryAmount<CurrencyExt>
recipient AddressOrPair
deadline string | number

Returns

ExtrinsicData

Defined in

src/parachain/amm.ts:575


_swapThroughStandardPoolsOnly

_swapThroughStandardPoolsOnly(trade, minimumAmountOut, recipient, deadline): ExtrinsicData

Parameters

Name Type
trade Trade
minimumAmountOut MonetaryAmount<CurrencyExt>
recipient AddressOrPair
deadline string | number

Returns

ExtrinsicData

Defined in

src/parachain/amm.ts:552


addLiquidity

addLiquidity(amounts, pool, maxSlippage, deadline, recipient): Promise<ExtrinsicData>

Adds liquidity to liquidity pool

Parameters

Name Type Description
amounts PooledCurrencies Array of monetary amounts of pooled currencies sorted in the same order as in the pool.
pool LiquidityPool Type of liquidity pool.
maxSlippage number Maximum allowed slippage.
deadline number Deadline block number.
recipient AddressOrPair Recipient of the liquidity pool token.

Returns

Promise<ExtrinsicData>

A submittable extrinsic and an event that is emitted when extrinsic is submitted.

Implementation of

AMMAPI.addLiquidity

Defined in

src/parachain/amm.ts:770


claimFarmingRewards

claimFarmingRewards(claimableRewards): ExtrinsicData

Claim all pending farming rewards.

Parameters

Name Type Description
claimableRewards Map<LpCurrency, MonetaryAmount<CurrencyExt>[]> Map of LpToken -> Array of reward monetary amounts -> supposed to be output of getClaimableFarmingRewards

Returns

ExtrinsicData

A submittable extrinsic and an event that is emitted when extrinsic is submitted.

Implementation of

AMMAPI.claimFarmingRewards

Defined in

src/parachain/amm.ts:930


getClaimableFarmingRewards

getClaimableFarmingRewards(accountId, accountLiquidity, pools): Promise<Map<LpCurrency, MonetaryAmount<CurrencyExt>[]>>

Get claimable farming reward amounts for all farmed liquidity provided by account.

Parameters

Name Type Description
accountId AccountId Account id for which to get claimable rewards.
accountLiquidity MonetaryAmount<LpCurrency>[] Amount of liquidity the account has provided.
pools LiquidityPool[] All liquidity pools.

Returns

Promise<Map<LpCurrency, MonetaryAmount<CurrencyExt>[]>>

Map of LpCurrency -> Array of reward monetary amounts.

Implementation of

AMMAPI.getClaimableFarmingRewards

Defined in

src/parachain/amm.ts:631


getLiquidityPools

getLiquidityPools(): Promise<LiquidityPool[]>

Get all liquidity pools.

Returns

Promise<LiquidityPool[]>

All liquidity pools.

Implementation of

AMMAPI.getLiquidityPools

Defined in

src/parachain/amm.ts:542


getLiquidityProvidedByAccount

getLiquidityProvidedByAccount(accountId): Promise<MonetaryAmount<LpCurrency>[]>

Get liquidity provided by account.

Parameters

Name Type Description
accountId AccountId Account to get provided liquidity information about.

Returns

Promise<MonetaryAmount<LpCurrency>[]>

Array of LP token amounts that represent account’s positions in respective liquidity pools.

Implementation of

AMMAPI.getLiquidityProvidedByAccount

Defined in

src/parachain/amm.ts:213


getLpTokens

getLpTokens(): Promise<LpCurrency[]>

Get all LP tokens.

Returns

Promise<LpCurrency[]>

Array of all standard and stable LP tokens.

Implementation of

AMMAPI.getLpTokens

Defined in

src/parachain/amm.ts:248


getOptimalTrade

getOptimalTrade(inputAmount, outputCurrency, pools): null | Trade

Get optimal trade for provided trade type and amount.

Parameters

Name Type Description
inputAmount MonetaryAmount<CurrencyExt> Amount to be exchanged.
outputCurrency CurrencyExt Currency to purchase.
pools LiquidityPool[] Array of all liquidity pools.

Returns

null | Trade

Optimal trade information or null if the trade is not possible.

Implementation of

AMMAPI.getOptimalTrade

Defined in

src/parachain/amm.ts:199


getStableLiquidityPools

getStableLiquidityPools(blockTimeMs): Promise<StableLiquidityPool[]>

Parameters

Name Type
blockTimeMs number

Returns

Promise<StableLiquidityPool[]>

Defined in

src/parachain/amm.ts:530


getStandardLiquidityPools

getStandardLiquidityPools(blockTimeMs): Promise<StandardLiquidityPool[]>

Parameters

Name Type
blockTimeMs number

Returns

Promise<StandardLiquidityPool[]>

Defined in

src/parachain/amm.ts:345


removeLiquidity

removeLiquidity(amount, pool, maxSlippage, deadline, recipient): Promise<ExtrinsicData>

Removes liquidity from pool.

Parameters

Name Type Description
amount MonetaryAmount<LpCurrency> Amount of LP token to be removed
pool LiquidityPool Liquidity pool to remove from.
maxSlippage number Maximum allowed slippage.
deadline number Deadline block number.
recipient AddressOrPair Recipient of the pooled currencies.

Returns

Promise<ExtrinsicData>

A submittable extrinsic and an event that is emitted when extrinsic is submitted.

Note

Removes amount of liquidity in LP token, breaks it down and transfers to account.

Implementation of

AMMAPI.removeLiquidity

Defined in

src/parachain/amm.ts:882


swap

swap(trade, minimumAmountOut, recipient, deadline): ExtrinsicData

Swap assets.

Parameters

Name Type Description
trade Trade Trade object containing information about the trade.
minimumAmountOut MonetaryAmount<CurrencyExt> Minimum output amount to be received.
recipient AddressOrPair Recipient address.
deadline string | number Deadline block for the swap transaction.

Returns

ExtrinsicData

A submittable extrinsic and an event that is emitted when extrinsic is submitted.

Implementation of

AMMAPI.swap

Defined in

src/parachain/amm.ts:656


getStableLpTokenFromPoolData

getStableLpTokenFromPoolData(poolId, basePoolData): StableLpToken

Parameters

Name Type
poolId number
basePoolData DexStablePrimitivesBasePool

Returns

StableLpToken

Defined in

src/parachain/amm.ts:182


getStablePoolInfo

getStablePoolInfo(poolData): null | DexStablePrimitivesBasePool

Parameters

Name Type
poolData DexStablePrimitivesPool

Returns

null | DexStablePrimitivesBasePool

Defined in

src/parachain/amm.ts:172