Skip to content

subdarkdex/subdex-xc-network

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

69 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Subdex cross chain network

This repo provides simple scripts, inspired by polkadot/cumulus, to set up a network with:-

  1. Relay Chain with 3 validators (Alice, Bob, Charlie)
  2. Generic parachain (parachain with generic-assets-token-dealer, assets and balances pallets)
  3. Subdex parachain (parachain with dex-xcmp and dex-pallet)

The relay chain chain-specs is rococo-3.json from cumulus-workshop

This is a part of the submission for Open Grant awarded by the Web3Foundation

  1. subdex-ui (React frontend providing friendly UI)
  2. pallet-subdex & pallet-dex-xcmp
  3. pallet-generic-token-dealer
  4. Helper Repo - subdex-xc-network (current repo)
  5. Helper Repo - subdex-parachain (Parachains using the Cumulus framework with the dex-xcmp and dex-pallet)
  6. Helper Repo - generic-parachain (Parachains using the Cumulus framework with the generic-assets-token-dealer and assets pallet)

You can checkout the blog post for an overview.


Interaction

The subdex testnet can be interacted with through

  • Subdex Parachain - wss://subdex.link/dex
  • Relay Chain - wss://subdex.link/relay
  • Generic Parachain - wss://subdex.link/generic

We are also serving a polkadot.js apps web application v0.69.1 on https://subdex.link

Subdex User Interface

  • Subdex Parachain - Please visit our dex UI here to connect to the Subdex Parachain

Interaction with subdex.link

Types:

If you are using the subdex.link - A polkadotJs Apps web application, please make sure you add the following types


{
  "Address": "AccountId",
  "LookupSource": "AccountId",
  "RefCount": "u8",
  "AssetId": "u64",
  "Shares": "Balance",
  "ParaChainAssetId": "Option<AssetId>",
  "DexAssetId": "AssetIdOf<T>",
  "AssetIdOf": "AssetId",
  "TreasuryFee": "Option<Balance>",
  "ValidationFunction": "Vec<u8>",
  "ValidationFunctionParams": {
    "max_code_size": "u32",
    "relay_chain_height": "RelayChainBlockNumber",
    "code_upgrade_allowed": "Option<RelayChainBlockNumber>"
  },
  "Exchange": {
    "first_asset_pool": "Balance",
    "second_asset_pool": "Balance",
    "invariant": "Balance",
    "total_shares": "Balance",
    "last_timestamp": "IMoment",
    "price1_cumulative_last": "Balance",
    "price2_cumulative_last": "Balance",
    "shares": "BTreeMap<AccountId, Balance>"
  },
  "IMoment": "u64",
  "DexTreasury": {
    "dex_account": "AccountId",
    "treasury_fee_rate_nominator": "Balance",
    "treasury_fee_rate_denominator": "Balance"
  },
  "Asset": {
    "_enum": {
      "MainNetworkCurrency": null,
      "ParachainAsset": "(AssetId)"
    }
  },
}

Network Details

Accounts

The parachain account is tied to the parachain_id encoded The relay account is tied to the binary representation of relay here

 Parachain id: Id(100) Generic Parachain
 Parachain Account: 5Ec4AhP7HwJNrY2CxEcFSy1BuqAY3qxvCQCfoois983TTxDA
... 
 Parachain id: Id(200) Dex Parachain
 Parachain Account: 5Ec4AhPTL6nWnUnw58QzjJvFd3QATwHA3UJnvSD4GVSQ7Gop

 Relay Account on Parachain: 5Dvjuthoa1stHkMDTH8Ljr9XaFiVLYe4f9LkAQLDjL3KqHoX

Milestone 1

Assets representations

For this milestone we demostrate the use of pallet-generic-token-dealer in a Generic Parachain, this parachain includes the assets pallet which we use to demostrate the many parachains in the future with their own currencies without having to deploy many parachains.

The pallet-subdex creates a map or any parachain id + asset id to para_asset_id, however, since supporting dynamic amount assets in the UI is not part of the scope. Therefore we have created the mapping on the subdex-parachain such that:

On Generic Parachain
AssetId 0 -> ParaAssetID 1
AssetID 1 -> ParaAssetID 2

On Subdex Parachain
ParaAssetID 1 -> BTC
ParaAssetID 2 -> EDG

The native currency of the subdex parachain is the testnet KSM from the relay chain.

It is of course possible to interact with the subdex-parachain through other api clients to test all the currencies.


Development

Run a local testnet with docker

# in the root of this directory
docker-compose --file docker-compose-xc.yml up

# To stop it and remove all data
docker-compose --file docker-compose-xc.yml down -v

Run local parachain binarys

Pre-requisits

  • Docker version 19.03.8, build afacb8b
  • execute access for the .sh files in this repo

Setup for native parachain binaries

NOTE: - we are not using the script provided in cumulus because we want 2 parachains, also, need to be able to build and rebuild the parachain binaries as we experiment. But when we get more familiar / more stable versions of the parachains, we can build a similar script to do all steps.

Steps required are:-

  1. set up relay chain validators
  2. set up default cumulus parachain
  3. register parachains
  4. run subdex and generic parachains

1. Set up validators

docker-compose -f docker-compose-validatorsOnly.yml up will set up alice, bob and charlie

2. build parachains

./build_collators_from_local.sh

This will set up 2 repositories parallel to this one if they are not already setup, one is generic-parachain and the other the subdex-chain

3. register parachains

./register_parachain.sh

4. run the parachains

# Run whichever you need
./start_generic_chain.sh
./start_subdex_chain.sh

5. run network tests

./run_network_tests.sh

6. stop validators

docker-compose -f docker-compose-validatorsOnly.yml down -v

7. (purge-chains, all chains, all genesis states)

./clear_all.sh

Interacting with local testnet

  • PolkadotJS App - localhost:8080
  • Subdex Parachain - localhost:9944
  • Relay Chain - localhost:6644
  • Generic Parachain - localhost:7744
  • subdex-ui - you can use https://subdex.network or run subdex-ui

Building all docker images for dockerhub

  1. Base images - this is to compile the binary / wasm file from branches of subdex_cumulus
# To build

# same for generic-parachain
git clone https://github.com/subdarkdex/subdex_parachain.git dex-parachain
cd dex-parachain
docker build --tag subdarkdex/subdex-chain:<version>
  1. Collators, WASM Runtime Volume, Registrar
  • collators - both dex and generic parachains
  • wasm runtime volume - this is a copy of the wasm runtime for the collators, used to register parachain, we also have the genesis state volume built during docker-compose up for this purpose
  • registrar - simple polkadotjs cli container to register the parachains using sudo
cd docker
./build-containers.sh v0.2.0 
# or other versions