24 releases (major breaking)

21.0.0 Jan 13, 2025
20.0.0 Sep 26, 2024
19.0.0 Jul 18, 2024
18.0.0 Jul 12, 2024
0.0.0 Mar 31, 2023

#22 in #swap

Download history 1301/week @ 2024-10-09 1875/week @ 2024-10-16 1969/week @ 2024-10-23 1887/week @ 2024-10-30 6601/week @ 2024-11-06 26753/week @ 2024-11-13 26071/week @ 2024-11-20 26059/week @ 2024-11-27 27631/week @ 2024-12-04 23945/week @ 2024-12-11 19401/week @ 2024-12-18 7162/week @ 2024-12-25 19257/week @ 2025-01-01 24443/week @ 2025-01-08 34579/week @ 2025-01-15 25084/week @ 2025-01-22

104,044 downloads per month
Used in 86 crates (10 directly)

Apache-2.0

3.5MB
56K SLoC

asset-conversion

A swap pallet

This pallet allows assets to be converted from one type to another by means of a constant product formula. The pallet based is based on Uniswap V2 logic.

Overview

This pallet allows you to:

  • create a liquidity pool for 2 assets
  • provide the liquidity and receive back an LP token
  • exchange the LP token back to assets
  • swap 2 assets if there is a pool created
  • query for an exchange price via a new runtime call endpoint
  • query the size of a liquidity pool.

Please see the rust module documentation for full details:

cargo doc -p pallet-asset-conversion --open

License

License: Apache-2.0

Release

Polkadot SDK Stable 2412


lib.rs:

Substrate Asset Conversion pallet

Substrate Asset Conversion pallet based on the Uniswap V2 logic.

Overview

This pallet allows you to:

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 asset to non-native asset 1, you would pass in a path of [DOT, 1] or [1, DOT]. If you want to swap from non-native asset 1 to non-native asset 2, you would pass in a path of [1, DOT, 2].

(For an example of configuring this pallet to use Location as an asset id, see the cumulus repo).

Here is an example state_call that asks for a quote of a pool of native versus asset 1:

curl -sS -H "Content-Type: application/json" -d \
'{"id":1, "jsonrpc":"2.0", "method": "state_call", "params": ["AssetConversionApi_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.)

Dependencies

~18–33MB
~540K SLoC