Table of Contents
This document provides an overview of the application.
It outlines the use cases, i.e., desirable functionality, in addition to requirements for the smart contracts and scripts.
This section contains general information about the functionality of the application and thus does not touch upon any technical aspects.
If you are interested in a functional overview then this is the section for you.
- Specifies the legitimate exchange contract implementation that the AMM will operate with (this is a safety mechanism against adding malicious exchange contract implementations to the AMM)
- Requires bytecode root of the desired exchange contract implementation
- Adds the liquidity pool for the specified asset pair
- If the AMM is initialized
- Requires the identifiers of the two assets
- Requires the exchange contract identifier that is also the identifier of the liquidity pool asset for the given pair
- If the exchange contract is legitimate, i.e., the bytecode root matches
- If the exchange contract defines the pool for the specified asset pair
- Returns the exchange contract identifier for an asset pair
- Requires the identifiers of the two assets
- Allows specifying the asset pair that the liquidity pool in the exchange contract will consist of
- If the asset pair for the exchange contract has not already been set
- Requires two different asset identifiers
- Deposits an asset into the contract
- If the asset pair of the pool is set
- Requires any amount of either asset in the pair
- Allows adding liquidity to the pool by using up at least one asset's deposited amount
- If the asset pair of the pool is set
- If the deadline has not passed
- If the deposit amounts of both assets are sufficient for adding desired liquidity
- If the resulting liquidity amount is more than the minimum liquidity for a pool to exist.
NOTE This lower limit for liquidity can be modified per asset pair and exists to protect against excessive slippage.
- Requires the desired liquidity amount
- Requires a deadline (block height limit)
- Allows removing liquidity from the pool
- If the asset pair of the pool is set
- If the deadline has not passed
- If the amount of liquidity pool assets are sufficient
- Requires the minimum amounts of both assets to receive after burning
- Requires a deadline (block height limit)
- Allows withdrawing previously deposited assets without using them to add liquidity
- If the asset pair of the pool is set
- If the deposited amount of the asset is sufficient
- Requires an amount of either asset to withdraw
- Allows selling an exact amount of an asset for the other asset
- If the asset pair of the pool is set
- If the deadline has not passed
- If the asset reserve of asset to buy in the contract is sufficient
- If the bought amount is not less than the optional minimum output amount
- Requires an exact amount of either asset to sell
- Requires an optional minimum desired output amount
NOTE This is a safety mechanism against excessive slippage. The
preview_swap_exact_input()
function can be used to calculate a reasonable minimum output amount. - Requires a deadline (block height limit)
- Allows selling an asset for an exact amount of the other asset
- If the asset pair of the pool is set
- If the deadline has not passed
- If the input amount is sufficient
- If the asset reserve of asset to buy in the contract is sufficient
- If the bought amount is not less than the exact output amount
- Requires an exact amount of either asset to buy
- Requires a maximum input amount
NOTE This is a safety mechanism against excessive slippage. The
preview_swap_exact_output()
function can be used to calculate a reasonable maximum input amount. - Requires a deadline (block height limit)
- Returns the amount of the other asset to input and the liquidity asset amount to receive after an add liquidity operation
- If the asset pair of the pool is set
- Requires the amount of an asset to input to
add_liquidity
NOTE If any liquidity in the contract already exists, then the amount of the other asset is calculated based on the ratio of the assets. Otherwise, the ratio is assumed to be 1.
- Returns the minimum output amount to receive after a
swap_exact_input
and whether the output asset reserves are sufficient for the swap- If the asset pair of the pool is set
- Requires an exact amount of either asset to sell
- Returns the maximum input amount for a
swap_exact_output
and whether the input asset reserves are sufficient for the swap- If the asset pair of the pool is set
- If the output asset reserves are sufficient for the swap
- Requires an exact amount of either asset to buy
- Returns the asset balance of the sender in the contract
- If the asset pair of the pool is set
- Requires the asset identifier to return the balance for
- Returns the pool info, i.e., the identifiers and amounts of assets and the liquidity pool asset amount
- If the asset pair of the pool is set
- Deposits pool assets and adds liquidity
- If desired liquidity is more than 0
- If
deposit
andadd_liquidity
conditions are met
- Swaps assets along a route by specifying exact input for each swap
- If the route has at least 2 assets
- If the AMM has a pool for each subsequent asset pair in route
- If the bought amount of the last asset is more than the optional minimum output amount
- If
swap_exact_input
conditions are met
- Swaps assets along a route by specifying exact output for each swap
- If the route has at least 2 assets
- If the AMM has a pool for each subsequent asset pair in route
- If the sold amount of the first asset is less than the specified maximum input amount
- If
swap_exact_output
conditions are met