AMM
Automatic Market Maker

Overview

Parallel offers two distinct types of Automatic Market Makers to provide a wider range of possibilities to its users. More specifically, "Stable" is a low slippage AMM suitable for stable 1:1 ratio assets while "Dynamic" is a general-purpose AMM for any kind of asset combination with a higher slippage.
To have a better understating on each type of AMM, take a look at the sub-categories of this chapter.

Swap operations

The nomenclature chose for internal swaps is the old buy and sell operations used on the Stock market, Forex market, crypto CEXs or any other order-book based entity.
Given a [X, Y] asset pair, buying X (base) means swapping Y (quote) for X (base) while the opposite (selling) means swapping X (base) for Y (quote). Therefore, for any [X, Y] asset pair, base is X and quote is Y.
All with that said, accounts buy or sell base assets and pay or charge quote assets.

View Data Storage

ExchangeRate

The exchange rate from the underlying to the internal collateral.
Code
View Method
1
pub type ExchangeRate<T: Config> = StorageValue<_, Rate, ValueQuery>;
Copied!
1
ExchangeRate::<T>::get();
Copied!

LiquidityProviders

Accounts that deposits and withdraw assets in one or more pools.
Code
View Method
1
pub type LiquidityProviders<T: Config> = StorageDoubleMap<
2
_,
3
Blake2_128Concat,
4
T::PoolId,
5
Blake2_128Concat,
6
T::AccountId,
7
LiquidityProviderAmounts,
8
>;
Copied!
1
LiquidityProviders::<T>::get(&T::PoolId, &T::AccountId);
Copied!

Pools

A bag of liquidity composed by two different assets.
Code
View Method
1
pub type Pools<T: Config> = StorageMap<_, Blake2_128Concat, T::PoolId, Pool>;
Copied!
1
Pools::<T>::get(&T::PoolId);
Copied!

PoolsCounter

Auxiliary storage used to track pool ids.
Code
View Method
1
pub type PoolsCounter<T: Config> = StorageValue<_, T::PoolId, ValueQuery>;
Copied!
1
PoolsCounter::<T>::get();
Copied!

View Methods

add_liquidity()

Adds liquidity to a pool based on the provided base amount and the quote amount range.
1
pub fn add_liquidity(
2
origin: OriginFor<T>,
3
amm_type: AmmType,
4
amount_base: Balance,
5
amount_quote_range: RangeInclusive<Balance>,
6
pool_id: T::PoolId,
7
) -> DispatchResult;
Copied!

buy()

Buys a given amount of base asset within the quote amount range.
1
pub fn buy(
2
origin: OriginFor<T>,
3
amm_type: AmmType,
4
amount_base: Balance,
5
amount_quote_range: RangeInclusive<Balance>,
6
pool_id: T::PoolId,
7
) -> DispatchResult;
Copied!

create_pool()

Creates an initial pool with the specified asset ratio.
1
pub fn create_pool(origin: OriginFor<T>, pool: Pool) -> DispatchResult;
Copied!

remove_liquidity()

Removes liquidity of a pool based on the provided base amount and the quote amount range.
1
pub fn remove_liquidity(
2
origin: OriginFor<T>,
3
amm_type: AmmType,
4
amount_base: Balance,
5
amount_quote_range: RangeInclusive<Balance>,
6
pool_id: T::PoolId,
7
) -> DispatchResult;
Copied!

sell()

Sells a given amount of base asset within the quote amount range.
1
pub fn sell(
2
origin: OriginFor<T>,
3
amm_type: AmmType,
4
amount_base: Balance,
5
amount_quote_range: RangeInclusive<Balance>,
6
pool_id: T::PoolId,
7
) -> DispatchResult;
Copied!

View events

View errors

Name
Description
AssetsCanNotBeEqual
It is not possible to create a pool with the equal assets.
LiquidityProviderDoesNotExist
The corresponding amounts of a liquidity provided could not be found
PoolDoesNotExist
Stored pool fetched by its corresponding id does not exist.
PoolDoesNotSatisfySlippage
Provided quote range does not satisfy the current pool asset ratio.

Last modified 3mo ago