17 releases (11 major breaking)

14.0.0 Apr 8, 2024
13.0.0 Mar 18, 2024
12.0.0 Feb 26, 2024
11.0.0 Feb 13, 2024
0.0.0 Mar 31, 2023

#731 in Magic Beans

Download history 570/week @ 2024-01-02 477/week @ 2024-01-09 226/week @ 2024-01-16 365/week @ 2024-01-23 284/week @ 2024-01-30 314/week @ 2024-02-06 851/week @ 2024-02-13 902/week @ 2024-02-20 1033/week @ 2024-02-27 532/week @ 2024-03-05 573/week @ 2024-03-12 967/week @ 2024-03-19 769/week @ 2024-03-26 769/week @ 2024-04-02 958/week @ 2024-04-09 537/week @ 2024-04-16

3,258 downloads per month
Used in 30 crates (6 directly)

Apache-2.0

2.5MB
51K 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


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

~17–33MB
~546K SLoC