You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The document describes the functioning of DEX AMM (Decentralized EXchange with Automatic MarketMaking) on the Enecuum blockchain.
Key Points
DEX is designed for digital asset exchange. Assets are exchanged within independent liquidity pools. Only one pool can exist for each pair. The fee for exchange operations in the pool is set automatically at the time of creation. Any user can create pools, add liquidity to existing pools, remove previously added liquidity, and exchange assets. Each operation is performed by calling the corresponding smart contract.
Asset Management
To manage assets, the user must send a transaction with the necessary parameters to genesis.
Creating Pool (create_pool)
Parameters:
asset_1 - hash of the first asset
amount_1 - volume of the first asset
asset_2 - hash of the second asset
amount_2 - volume of the second asset
A pool {asset_1, asset_2} is created containing the volumes amount_1 and amount_2, respectively. The specified amounts of assets and the transaction fee in the native token are debited from the sender's active balance.
The pool volume k is calculated as amount_1 * amount_2. The exchange fee pool_fee is set as the default parameter default_pool_fee.
The sender is transferred lt = sqrt(amount_1 * amount_2) of liquidity tokens of this pair.
A transaction is rejected if:
asset_1 == asset_2
the pool for the specified pair already exists
the sender has insufficient assets
the sender does not have enough native tokens to pay the transaction fee
amount_1 * amount_2 == 0
Adding liquidity (add_liquidity)
Parameters:
asset_1 - hash of the first asset
amount_1 - volume of the first asset
asset_2 - hash of the second asset
amount_2 - volume of the second asset
Based on the parameters of the pool {volume_1', volume_2'} (volume of the first asset, volume of the second asset), the values of the required amount of the first asset are calculated as required_1 = volume_1 * amount_2 / volume_2, and the required amount of the second asset as required_2 = volume_2 * amount_1 / volume_1.
In case amount_1 >= required_1, the pool parameters are changed as
volume_1 += required_1
volume_2 += amount_2, and the corresponding volumes of assets are debited from the sender's active balance, and the amount of added liquidity is calculated as
lt = sqrt(required_1 * amount_2) and lt liquidity tokens are credited to the sender.
In case amount_1 < required_1, the pool parameters are changed as
volume_1 += amount_1
volume_2 += required_2, and the corresponding volumes of assets are debited from the sender's active balance, and the amount of added liquidity is calculated as
lt = sqrt(amount_1 * required_2) and lt liquidity tokens are credited to the sender.
The new pool volume k is calculated as volume_1 * volume_2.
A transaction is rejected if:
the pool for the specified pair does not exist
the sender does not have enough native tokens to pay the transaction fee
Sell exact amount (sell_exact)
Parameters:
asset_in - hash of the first asset
amount_in - volume of the first asset
asset_out - hash of the second asset
The amount of funds that will be received as a result of the exchange is calculated as amount_out = volume_2 - (volume_1 * volume_2)/(volume_1 + amount_in * (1 - pool_fee))
The specified amount amount_in of the asset asset_in and the transaction fee in the native token are debited from the sender's active balance. The calculated amount amount_out of the asset asset_out is credited to the sender's active balance.
Also, additional liquidity tokens are minted. cmd_tokens = lp_total * cmd_fee * amount_in / volume_1,
where lp_total is total supply of liquidity token.
Minted tokens are added to Commander ENEX (alias for certain address), if corresponding liquidy pool ENX/LPtoken exists. Minted tokens are added to burn address otherwise.
A transaction is rejected if:
the pool for the specified pair does not exist
the sender does not have enough native tokens to pay the transaction fee
Buy exact amount (buy_exact)
Parameters:
asset_in - hash of the first asset
asset_out - hash of the second asset
amount_out - volume of the second asset
The amount of funds that will be taken as a result of the exchange is calculated as amount_in = (volume_1 * volume_2)/(volume_2 - amount_in * (1 - pool_fee)) - volume_1
The specified amount amount_in of the asset asset_in and the transaction fee in the native token are debited from the sender's active balance. The calculated amount amount_out of the asset asset_out is credited to the sender's active balance.
Also, additional liquidity tokens are minted. cmd_tokens = lp_total * cmd_fee * amount_in / volume_1,
where lp_total is total supply of liquidity token.
Minted tokens are added to Commander ENEX (alias for certain address), if corresponding liquidy pool ENX/LPtoken exists. Minted tokens are added to burn address otherwise.
A transaction is rejected if:
the pool for the specified pair does not exist
the sender does not have enough native tokens to pay the transaction fee
Removing liquidity (remove_liquidity)
Parameters:
lt - hash of the liquidity token
amount - volume of liquidity to be removed
The amount of funds that will be received as a result of removing liquidity is calculated as
amount_1 = volume_1 * amount / lt_emission
amount_2 = volume_2 * amount / lt_emission
, where lt_emission is overall emission of liquidity token. Liquidity token emission will be decreased for corresponding amount.
A transaction is rejected if:
the pool for the specified pair does not exist
the sender does not have enough liquidity tokens
the sender does not have enough native tokens to pay the transaction fee
The text was updated successfully, but these errors were encountered:
DEX
Metadata
Summary
The document describes the functioning of DEX AMM (Decentralized EXchange with Automatic MarketMaking) on the Enecuum blockchain.
Key Points
DEX is designed for digital asset exchange. Assets are exchanged within independent liquidity pools. Only one pool can exist for each pair. The fee for exchange operations in the pool is set automatically at the time of creation. Any user can create pools, add liquidity to existing pools, remove previously added liquidity, and exchange assets. Each operation is performed by calling the corresponding smart contract.
Asset Management
To manage assets, the user must send a transaction with the necessary parameters to genesis.
Creating Pool (create_pool)
Parameters:
A pool {asset_1, asset_2} is created containing the volumes amount_1 and amount_2, respectively. The specified amounts of assets and the transaction fee in the native token are debited from the sender's active balance.
The pool volume k is calculated as amount_1 * amount_2. The exchange fee pool_fee is set as the default parameter default_pool_fee.
The sender is transferred lt = sqrt(amount_1 * amount_2) of liquidity tokens of this pair.
A transaction is rejected if:
Adding liquidity (add_liquidity)
Parameters:
Based on the parameters of the pool {volume_1', volume_2'} (volume of the first asset, volume of the second asset), the values of the required amount of the first asset are calculated as required_1 = volume_1 * amount_2 / volume_2, and the required amount of the second asset as required_2 = volume_2 * amount_1 / volume_1.
In case amount_1 >= required_1, the pool parameters are changed as
volume_1 += required_1
volume_2 += amount_2, and the corresponding volumes of assets are debited from the sender's active balance, and the amount of added liquidity is calculated as
lt = sqrt(required_1 * amount_2) and lt liquidity tokens are credited to the sender.
In case amount_1 < required_1, the pool parameters are changed as
volume_1 += amount_1
volume_2 += required_2, and the corresponding volumes of assets are debited from the sender's active balance, and the amount of added liquidity is calculated as
lt = sqrt(amount_1 * required_2) and lt liquidity tokens are credited to the sender.
The new pool volume k is calculated as volume_1 * volume_2.
A transaction is rejected if:
Sell exact amount (sell_exact)
Parameters:
The amount of funds that will be received as a result of the exchange is calculated as amount_out = volume_2 - (volume_1 * volume_2)/(volume_1 + amount_in * (1 - pool_fee))
The specified amount amount_in of the asset asset_in and the transaction fee in the native token are debited from the sender's active balance. The calculated amount amount_out of the asset asset_out is credited to the sender's active balance.
Also, additional liquidity tokens are minted.
cmd_tokens = lp_total * cmd_fee * amount_in / volume_1,
where lp_total is total supply of liquidity token.
Minted tokens are added to Commander ENEX (alias for certain address), if corresponding liquidy pool ENX/LPtoken exists. Minted tokens are added to burn address otherwise.
A transaction is rejected if:
Buy exact amount (buy_exact)
Parameters:
The amount of funds that will be taken as a result of the exchange is calculated as amount_in = (volume_1 * volume_2)/(volume_2 - amount_in * (1 - pool_fee)) - volume_1
The specified amount amount_in of the asset asset_in and the transaction fee in the native token are debited from the sender's active balance. The calculated amount amount_out of the asset asset_out is credited to the sender's active balance.
Also, additional liquidity tokens are minted.
cmd_tokens = lp_total * cmd_fee * amount_in / volume_1,
where lp_total is total supply of liquidity token.
Minted tokens are added to Commander ENEX (alias for certain address), if corresponding liquidy pool ENX/LPtoken exists. Minted tokens are added to burn address otherwise.
A transaction is rejected if:
Removing liquidity (remove_liquidity)
Parameters:
The amount of funds that will be received as a result of removing liquidity is calculated as
amount_1 = volume_1 * amount / lt_emission
amount_2 = volume_2 * amount / lt_emission
, where lt_emission is overall emission of liquidity token. Liquidity token emission will be decreased for corresponding amount.
A transaction is rejected if:
The text was updated successfully, but these errors were encountered: