Crate serai_dex_pallet
source ·Expand description
§Serai Dex pallet
Serai Dex pallet based on the Uniswap V2 logic.
§Overview
This pallet allows you to:
- create a liquidity pool for 2 coins
- provide the liquidity and receive back an LP token
- exchange the LP token back to coins
- swap a specific amount of coins for another if there is a pool created, or
- swap some coins for a specific amount of another.
- query for an exchange price via a runtime call endpoint
- query the size of a liquidity pool via a runtime api endpoint.
The quote_price_exact_tokens_for_tokens
and quote_price_tokens_for_exact_tokens
functions
both take a path parameter of the route to take. If you want to swap from native coin to
non-native coin 1, you would pass in a path of [DOT, 1]
or [1, DOT]
. If you want to swap
from non-native coin 1 to non-native coin 2, you would pass in a path of [1, DOT, 2]
.
(For an example of configuring this pallet to use MultiLocation
as an coin id, see the
cumulus repo).
Here is an example state_call
that asks for a quote of a pool of native versus coin 1:
curl -sS -H "Content-Type: application/json" -d \
'{
"id": 1,
"jsonrpc": "2.0",
"method": "state_call",
"params": [
"DexApi_quote_price_tokens_for_exact_tokens",
"0x0101000000000000000000000011000000000000000000"
]
}' \
http://localhost:9933/
(This can be run against the kitchen sync node in the node
folder of this repo.)
Re-exports§
pub use weights::WeightInfo;
pub use pallet::*;
Modules§
- The
pallet
module in each FRAME pallet hosts the most important items needed to construct this pallet. - Autogenerated weights for Dex Pallet.
Macros§
- Enable/disable the given code depending on
feature = "runtime-benchmarks"
being enabled for the crate or not.
Traits§
- This runtime api allows people to query the size of the liquidity pools and quote prices for swaps.
- Trait for providing methods to swap between the various coin classes.