Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add convenience DEX #273

Merged
merged 7 commits into from
Feb 19, 2024
Merged

add convenience DEX #273

merged 7 commits into from
Feb 19, 2024

Conversation

brenzi
Copy link
Collaborator

@brenzi brenzi commented Feb 16, 2024

closes #269
this adds pallet-asset-conversion. The goal is to improve UX for first-timers that don't have TEER yet. They can just transfer KSM from relay or asset hub and convert into directly on our chain without any more hops. Even if we don't expect this dex to be deeply liquid, it will serve well for small amounts in the order of paying fees for utility

testing

zombienet-linux-x64 spawn --provider native zombienet/rococo-local-with-integritee.toml

note preimage to register ROC as an asset on Integritee, set metadata and register its multilocation

execution should result in Events:

  • assets.forceCreated
  • assets.MetadataSet
  • assetRegistry.ReserveAssetRegistered

if testing with polkadot >= 1.7 binaries, need to downgrade safeXcmVersion to V3 on relaychain

transfer 100.0 ROC from relay to itee

create DEX

everyone can create a pool, but that's ok as only two tokens exist so there can be only one pool

create pool for ROC/TEER

this will create a new LPT asset for the new pool, and it will create a new technical account we will call PoolReserve to hold the assets in the liq pool: 2PUnzrp5fQnwWJgoNexyUaysy4i7KN9MNDesMa1BdyyrAKar

you should see events

  • assets.Touched PoolReserve
  • poolAssets.ForceCreated
  • poolAssets.Touched PoolReserve
  • assetConversion.PoolCreated

add liquidity: 900 TEER + 25 ROC

you should see events:

  • system.NewAccount PoolReserve
  • balances.Transfer Alice to PoolReserve 900 TEER
  • assets.Transferred Alice to PoolReserve 25 ROC
  • poolAssets.Issued 100 LPT to PoolReserve (guess this is meant as ED)
  • poolAssets.Issued 149'999'999'999'900 LPT to Alice
  • assetConversion.LiquidityAdded

swap exactly 10 TEER for a market rate of ROC

event: assetConversion.SwapExecuted: in : 10TEER, out: 273.910128905 mROC

the original exchange rate was 25/900 = 27.777
We sold TEER, so price of TEER went down and we get less ROC (CPMM slippage) 27.391...mROC/TEER

if we do the same again, we'll only get 26.79 mROC per TEER

also, there's an LPfee of 0.3% which stays in the PoolReserve

Alice withdraws her liquidity

Alice can't withdraw EVERYTHING, she must leave an existential amount

events:

  • balances.Transfer from PoolReserve to Alice: 913.86.. TEER
  • assets.Transferred from PoolReserve to Alice: 24.265 ROC
  • assetConversion.LiquidityRemoved, burning 149.0 LPT

@brenzi brenzi marked this pull request as ready for review February 16, 2024 16:37
@brenzi brenzi requested a review from clangenb February 16, 2024 16:37
Copy link
Contributor

@clangenb clangenb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice, this seemed surprisingly straight forward. 👍

@brenzi brenzi merged commit bcf6180 into master Feb 19, 2024
19 of 20 checks passed
@clangenb
Copy link
Contributor

Did not do a lot of monkey testing, just transferred some ROCs on our integritee-chain and used another account to create the liquidity pool, but everything worked so far.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add convenience DEX for KSM/TEER
2 participants