TheMayor


Chia App Building Series - AMM (in-process)

Before you begin

You will need the Chia Client version 2.1.2 or above.
You'll need PowerShell Version 7.4 or above.
It's recommended to have VSCode or another PowerShell capable editor.

Starting out

First we have to know what tokens we want to provide liquidity for. For this project we will provide liquidity for:

-HOA
-DBX
-SBX

Add Chia Assets to Wallet

We first need to get their ASSET IDs. We can find this over at dexie.space/assets

HOA = e816ee18ce2337c4128449bc539fbbe2ecfdd2098c4e7cab4667e223c3bdc23d 
DBX = db1a9020d48d9d4ad22631b66ab4b9ebd3637ef7758ad38881348c5d24c38f20
SBX = a628c1c2c6fcb74d53746157e438e108eab5c0bb3e5c80ff9b1910b3e4832913

We need the asset ids in order to add them to our Chia Wallet. Lets do this now.

Make sure your chia client is running, then Start up PowerShell.

Run the following to add the Tokens. This is safe to run even if the tokens exist already, but it will rename the wallet.

chia wallet add_token -id e816ee18ce2337c4128449bc539fbbe2ecfdd2098c4e7cab4667e223c3bdc23d -n "HOA"
chia wallet add_token -id db1a9020d48d9d4ad22631b66ab4b9ebd3637ef7758ad38881348c5d24c38f20 -n "DBX"
chia wallet add_token -id a628c1c2c6fcb74d53746157e438e108eab5c0bb3e5c80ff9b1910b3e4832913 -n "SBX"

Note: If you have more than one fingerprint installed, you'll need to choose the correct wallet to add them to.

Remember that X * Y = K

That's the formula for the constant product market (The thing we're trying to build). So, what's X and Y? For the rest of this series we're going to use DBX and XCH as our X and Y. That means we're going to be a Dexie Bucks Liquidity Provider.

You'll have to decide on your own how much liquidity you want to provide and how much do you want to provide in each offer. For me this is easiest to think of in terms of XCH. For example, I want to provide 1 XCH worth of liquidity, and I want to provide it in increments of 0.2 XCH. That means I'm going to have 5 buy offers where I spend 0.2XCH for xxxDBX, and I'll have 5 Sell offers of xxxDBX for 0.2XCH. In total I will have 10 Offers created, 5 buy and 5 sell.

The Coin Set model

What's this random Segway????

This is important in the Chia Blockchain. Unlike Ethereum or other popular blockchains, Chia uses the Coin Set model. You'll need to understand this in order to run your AMM. It's not enough to have 1 XCH worth of Chia if you want to provide 5 buy offers for DBX. You specifically need 5 coins of 0.2XCH each to create the buy offers. You need 5 coins because you are creating 5 offers.

You need to assign the coin to an offer you create. This is can be done automatically and I recommend not trying to manage it yourself.

This brings us to the first problem we need to solve. Do you have enough coins and are they the right size?

I'm including a link to my GitHub page. This has some premade functions you can use. We use the Invoke-WalletGetSpendableCoins function inside the wallet.ps1 file.

Function

Running the following code will give you a list of all your coins

$coins = Invoke-WalletGetSpendableCoins -wallet_id 
$coins.confirmed_records

Output:

confirmed_records
-----------------
{@{coin=; coinbase=


Help support me by donating below.

XCH Address: xch1xtn62vckj2dmpdlttewfgpsz6zluw8jpj57v308whcu5ty86xhlq3a0h0e

XCH Amount