From 4f1e3524fcd9f602dee054f8f4468300c5ba622f Mon Sep 17 00:00:00 2001 From: Sergej Sakac <73715684+Szegoo@users.noreply.github.com> Date: Sun, 12 May 2024 10:03:32 +0200 Subject: [PATCH] RegionX parachain (#46) * RegionX parachain reorganization * update docs * small fix * lint * fixes * lint * remove unused * fix --- .gitmodules | 8 - Astar | 1 - README.md | 101 +--- package-lock.json | 548 ++++++++++++++++-- package.json | 12 +- polkadot-sdk | 1 - scripts/full_init.sh | 25 - scripts/minimal_init.sh | 21 - scripts/run_zombienet.sh | 13 +- src/contracts/contract.ts | 164 ------ src/contracts/index.init.ts | 52 -- src/contracts/uniques.ts | 83 --- src/contracts/utils.ts | 43 -- src/coretime/index.init.ts | 64 +- src/regionx/index.init.ts | 87 +++ src/relay/index.init.ts | 19 +- src/utils.ts | 42 +- src/zombienet.init.ts | 24 +- zombienet/{full_network.toml => network.toml} | 36 +- 19 files changed, 672 insertions(+), 672 deletions(-) delete mode 100644 .gitmodules delete mode 160000 Astar delete mode 160000 polkadot-sdk delete mode 100755 scripts/full_init.sh delete mode 100755 scripts/minimal_init.sh delete mode 100644 src/contracts/contract.ts delete mode 100644 src/contracts/index.init.ts delete mode 100644 src/contracts/uniques.ts delete mode 100644 src/contracts/utils.ts create mode 100644 src/regionx/index.init.ts rename zombienet/{full_network.toml => network.toml} (52%) diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index af7ede3..0000000 --- a/.gitmodules +++ /dev/null @@ -1,8 +0,0 @@ -[submodule "polkadot-sdk"] - path = polkadot-sdk - url = https://github.com/Szegoo/polkadot-sdk.git - branch = "release-polkadot-v1.7.0-patch" -[submodule "Astar"] - path = Astar - url = https://github.com/RegionX-Labs/Astar.git - branch = "regionx-astar" diff --git a/Astar b/Astar deleted file mode 160000 index 223fca1..0000000 --- a/Astar +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 223fca1bc39295ceee2b53c591fcbd34702521d4 diff --git a/README.md b/README.md index 1531572..dd93ff2 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ # Simulated Coretime Environment -The primary purpose of this repository is to provide all the necessary components for testing the [RegionX contracts](https://github.com/RegionX-Labs/RegionX), as well as the [RegionX CoreHub UI](https://github.com/RegionX-Labs/CoreHub). +The primary purpose of this repository is to provide all the necessary components for testing the [RegionX-Node](https://github.com/RegionX-Labs/RegionX-Node), as well as the [RegionX CoreHub UI](https://github.com/RegionX-Labs/CoreHub). ## Topology @@ -10,117 +10,60 @@ The local environment consists of three chains: - Rococo relay chain - Coretime parachain -- Astar Shibuya parachain +- RegionX parachain

-The two parachains are connected through HRMP channels in both directions. In our mock environment, the Shibuya parachain treats the Coretime chain as a reserve chain for Coretime regions, thus supporting reserve transfers. +The two parachains are connected through HRMP channels in both directions. In our mock environment, the RegionX parachain treats the Coretime chain as a reserve chain for Coretime regions, thus supporting reserve transfers. -The Shibuya chain will represent the derivatives of Coretime regions as standard NFTs. This means that regions are presented as a single NFT collection, where the `ItemId` of each region corresponds to the encoded [`RegionId`](https://github.com/paritytech/polkadot-sdk/blob/2aa006e094e248110af14a742d4e2f56b7931959/substrate/frame/broker/src/types.rs#L55). +The XCM Nonfungible `Index` of each region corresponds to the encoded [`RegionId`](https://github.com/paritytech/polkadot-sdk/blob/2aa006e094e248110af14a742d4e2f56b7931959/substrate/frame/broker/src/types.rs#L55). ## Getting started with Zombienet Before proceeding, ensure that Zombienet is set up on the machine and accessible from the PATH. Linux and macOS executables for the Zombienet CLI are available [here](https://github.com/paritytech/zombienet/releases). -```sh -# Clone the repo: -git clone https://github.com/RegionX-Labs/Coretime-Mock.git - -# Pull the submodules: -git submodule update --init -``` - -To initiate the local environment, it is essential to get all the necessary binaries. - -```sh -# This script compiles all the necessary binaries for running the Rococo relay chain, -# Coretime chain, and the Shibuya parachain. -./scripts/full_init.sh -``` +Follow the first three steps from the [RegionX-Node README](https://github.com/RegionX-Labs/RegionX-Node?tab=readme-ov-file#running-zombienet-tests) to get all the necessary binaries. After getting them move them to `Coretime-Mock/bin` directory. -After successful compilation, the local network can be initiated: +After that we can run the zombienet network: ``` -npm run zombienet:full +npm run zombienet ``` -After waiting a few minutes for the network initialization and once **both** parachains **start producing blocks**, we can proceed with setting up the environment. +After waiting a few seconds for the network initialization and once **both** parachains **start producing blocks**, we can proceed with setting up the environment. This repo provides an initialization program which will based on the selected options set up the local network accordingly. The program provides the following options: 1. `--relayInit`: - - Opens two HRMP channels: Coretime Chain <--> Contracts chain + - Opens two HRMP channels: Coretime Chain <--> RegionX chain 2. `--coretimeInit`: - Initializes the Coretime chain by setting the initial configuration, starting the bulk sale, and purchasing a region. - -3. `--coretimeAccount `: - - - When specified the program will transfer the purchased region to this account. - -4. `--contractsInit`: - - - Initializes the contracts parachain by creating a collection that represents Coretime regions. Also, deploys both the `xc-regions` and the `coretime-market` contracts. - -5. `--mintXcRegions`: +3. `--regionxInit`: - - Mints a couple of mock xc-regions. Convenient for testing the market functionality. + - Initializes the RegionX chain by registering the relay chain token in its asset-registry. -6. `--contractsAccount `: +4. `--coretimeAccount `: - - When specified the program will transfer the mock xc-regions to this account. - -7. `--contractsPath `: + - When specified the program will transfer the purchased region to this account. +5. `--regionxAccount `: - - The path to the compiled contracts. - -### Example: Testing contracts only: + - The initialization script will fund the specified account with relay chain tokens. -> NOTE: In this case, we don't need to run the zombienet network, instead it is expected that the `astar-collator` node is running in the background in `--dev` mode at port `9920`. -> -> Command for running the node: `astar-collator --dev --rpc-port 9920` - -1. Compile the contracts within the RegionX directory - ```sh - cd RegionX/contracts/xc-regions - cargo contract build +### Example: Setting up the full environment - cd ../coretime_market - cargo contract build - ``` - -2. After successful compilation, setup the environment using the command below: - ```sh - npm run zombienet-init -- \ - --contractsInit \ - --contractsPath ../RegionX/target/ink/ \ - --contractsAccount "
" \ - --mintXcRegions - ``` - -### Example: Testing with full environment -> NOTE: For the following steps to function, it is required to execute `npm run zombienet:full` in the background. - -1. Compile the contracts in the RegionX directory - ```sh - cd RegionX/contracts/xc-regions - cargo contract build - - cd ../coretime_market - cargo contract build - ``` -2. After successful compilation and once all the parachains **started producing blocks**, setup the environment using the command below: +1. Run `npm run zombienet` in a separate terminal +2. Once the parachains **started producing blocks**, setup the environment using the command below: ```sh - npm run zombienet-init -- \ - --contractsInit \ + npm run init -- \ --coretimeInit \ --relayInit \ - --contractsPath ../RegionX/target/ink/ \ - --contractsAccount "
" \ - --coretimeAccount "
" + --regionxInit \ + --coretimeAccount "
" \ + --regionxAccount "
" ``` ## Getting started with Chopsticks diff --git a/package-lock.json b/package-lock.json index d150479..665f337 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,13 +10,11 @@ "license": "ISC", "dependencies": { "@acala-network/chopsticks": "0.9.4", - "@polkadot/api": "^10.11.1", - "@polkadot/api-contract": "^10.11.2", + "@polkadot/api": "^11.0.3", "@polkadot/keyring": "^12.6.2", "@polkadot/util-crypto": "^12.6.2", - "bn.js": "^5.2.1", "commander": "^11.1.0", - "coretime-utils": "^0.2.3", + "coretime-utils": "^0.3.2", "ts-node": "^10.9.2" }, "devDependencies": { @@ -409,23 +407,84 @@ "node": ">=12" } }, + "node_modules/@polkadot-api/json-rpc-provider": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/@polkadot-api/json-rpc-provider/-/json-rpc-provider-0.0.1.tgz", + "integrity": "sha512-/SMC/l7foRjpykLTUTacIH05H3mr9ip8b5xxfwXlVezXrNVLp3Cv0GX6uItkKd+ZjzVPf3PFrDF2B2/HLSNESA==", + "optional": true + }, + "node_modules/@polkadot-api/json-rpc-provider-proxy": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/@polkadot-api/json-rpc-provider-proxy/-/json-rpc-provider-proxy-0.0.1.tgz", + "integrity": "sha512-gmVDUP8LpCH0BXewbzqXF2sdHddq1H1q+XrAW2of+KZj4woQkIGBRGTJHeBEVHe30EB+UejR1N2dT4PO/RvDdg==", + "optional": true + }, + "node_modules/@polkadot-api/metadata-builders": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/@polkadot-api/metadata-builders/-/metadata-builders-0.0.1.tgz", + "integrity": "sha512-GCI78BHDzXAF/L2pZD6Aod/yl82adqQ7ftNmKg51ixRL02JpWUA+SpUKTJE5MY1p8kiJJIo09P2um24SiJHxNA==", + "optional": true, + "dependencies": { + "@polkadot-api/substrate-bindings": "0.0.1", + "@polkadot-api/utils": "0.0.1" + } + }, + "node_modules/@polkadot-api/observable-client": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/@polkadot-api/observable-client/-/observable-client-0.1.0.tgz", + "integrity": "sha512-GBCGDRztKorTLna/unjl/9SWZcRmvV58o9jwU2Y038VuPXZcr01jcw/1O3x+yeAuwyGzbucI/mLTDa1QoEml3A==", + "optional": true, + "dependencies": { + "@polkadot-api/metadata-builders": "0.0.1", + "@polkadot-api/substrate-bindings": "0.0.1", + "@polkadot-api/substrate-client": "0.0.1", + "@polkadot-api/utils": "0.0.1" + }, + "peerDependencies": { + "rxjs": ">=7.8.0" + } + }, + "node_modules/@polkadot-api/substrate-bindings": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/@polkadot-api/substrate-bindings/-/substrate-bindings-0.0.1.tgz", + "integrity": "sha512-bAe7a5bOPnuFVmpv7y4BBMRpNTnMmE0jtTqRUw/+D8ZlEHNVEJQGr4wu3QQCl7k1GnSV1wfv3mzIbYjErEBocg==", + "optional": true, + "dependencies": { + "@noble/hashes": "^1.3.1", + "@polkadot-api/utils": "0.0.1", + "@scure/base": "^1.1.1", + "scale-ts": "^1.6.0" + } + }, + "node_modules/@polkadot-api/substrate-client": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/@polkadot-api/substrate-client/-/substrate-client-0.0.1.tgz", + "integrity": "sha512-9Bg9SGc3AwE+wXONQoW8GC00N3v6lCZLW74HQzqB6ROdcm5VAHM4CB/xRzWSUF9CXL78ugiwtHx3wBcpx4H4Wg==", + "optional": true + }, + "node_modules/@polkadot-api/utils": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/@polkadot-api/utils/-/utils-0.0.1.tgz", + "integrity": "sha512-3j+pRmlF9SgiYDabSdZsBSsN5XHbpXOAce1lWj56IEEaFZVjsiCaxDOA7C9nCcgfVXuvnbxqqEGQvnY+QfBAUw==", + "optional": true + }, "node_modules/@polkadot/api": { - "version": "10.11.2", - "resolved": "https://registry.npmjs.org/@polkadot/api/-/api-10.11.2.tgz", - "integrity": "sha512-AorCZxCWCoTtdbl4DPUZh+ACe/pbLIS1BkdQY0AFJuZllm0x/yWzjgampcPd5jQAA/O3iKShRBkZqj6Mk9yG/A==", + "version": "11.0.3", + "resolved": "https://registry.npmjs.org/@polkadot/api/-/api-11.0.3.tgz", + "integrity": "sha512-VYuS42s5MiUOLo/PP1deYsddelGP4/mb1KFonXyWk69XowsfihGbVjsjh+DA4jPXvoNJqdGnDdu3SeppTY9MZQ==", "dependencies": { - "@polkadot/api-augment": "10.11.2", - "@polkadot/api-base": "10.11.2", - "@polkadot/api-derive": "10.11.2", + "@polkadot/api-augment": "11.0.3", + "@polkadot/api-base": "11.0.3", + "@polkadot/api-derive": "11.0.3", "@polkadot/keyring": "^12.6.2", - "@polkadot/rpc-augment": "10.11.2", - "@polkadot/rpc-core": "10.11.2", - "@polkadot/rpc-provider": "10.11.2", - "@polkadot/types": "10.11.2", - "@polkadot/types-augment": "10.11.2", - "@polkadot/types-codec": "10.11.2", - "@polkadot/types-create": "10.11.2", - "@polkadot/types-known": "10.11.2", + "@polkadot/rpc-augment": "11.0.3", + "@polkadot/rpc-core": "11.0.3", + "@polkadot/rpc-provider": "11.0.3", + "@polkadot/types": "11.0.3", + "@polkadot/types-augment": "11.0.3", + "@polkadot/types-codec": "11.0.3", + "@polkadot/types-create": "11.0.3", + "@polkadot/types-known": "11.0.3", "@polkadot/util": "^12.6.2", "@polkadot/util-crypto": "^12.6.2", "eventemitter3": "^5.0.1", @@ -468,16 +527,123 @@ "node": ">=18" } }, - "node_modules/@polkadot/api-contract": { - "version": "10.11.2", - "resolved": "https://registry.npmjs.org/@polkadot/api-contract/-/api-contract-10.11.2.tgz", - "integrity": "sha512-n+G1puptaQA5CwO2EHmD29QR1qlV/dVs6R0cBSGFaXvYJxqYJvN2LEir3i9vWjO0IVqulTjLPWvv7MbR3CxhmA==", + "node_modules/@polkadot/api-derive": { + "version": "11.0.3", + "resolved": "https://registry.npmjs.org/@polkadot/api-derive/-/api-derive-11.0.3.tgz", + "integrity": "sha512-WJriPWX0WnDhHAETAYkgCxIhkKmnRPqSsBKUHZxq+GgMJByOA4wgo3gzq5aQLXgkcCLV3wM4a6hALodYz0urSw==", + "dependencies": { + "@polkadot/api": "11.0.3", + "@polkadot/api-augment": "11.0.3", + "@polkadot/api-base": "11.0.3", + "@polkadot/rpc-core": "11.0.3", + "@polkadot/types": "11.0.3", + "@polkadot/types-codec": "11.0.3", + "@polkadot/util": "^12.6.2", + "@polkadot/util-crypto": "^12.6.2", + "rxjs": "^7.8.1", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/@polkadot/api-derive/node_modules/@polkadot/api-augment": { + "version": "11.0.3", + "resolved": "https://registry.npmjs.org/@polkadot/api-augment/-/api-augment-11.0.3.tgz", + "integrity": "sha512-O1QEUXiHpPJqVe398EQ+tywZLj1vDNZALzh2TKsyFSqEjT4N/EschCck9aFXpB0Bp0K2lm7+fKJf6eWPShNfFQ==", "dependencies": { - "@polkadot/api": "10.11.2", - "@polkadot/api-augment": "10.11.2", - "@polkadot/types": "10.11.2", - "@polkadot/types-codec": "10.11.2", - "@polkadot/types-create": "10.11.2", + "@polkadot/api-base": "11.0.3", + "@polkadot/rpc-augment": "11.0.3", + "@polkadot/types": "11.0.3", + "@polkadot/types-augment": "11.0.3", + "@polkadot/types-codec": "11.0.3", + "@polkadot/util": "^12.6.2", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/@polkadot/api-derive/node_modules/@polkadot/api-base": { + "version": "11.0.3", + "resolved": "https://registry.npmjs.org/@polkadot/api-base/-/api-base-11.0.3.tgz", + "integrity": "sha512-e/KSsDcFIG17SPw+buBXAq5NnBOMMOWljTljazDF7Nq3Sz6P+SFqOSb3kdICtp1fYAxg5my/uTs2OOARxJRXKA==", + "dependencies": { + "@polkadot/rpc-core": "11.0.3", + "@polkadot/types": "11.0.3", + "@polkadot/util": "^12.6.2", + "rxjs": "^7.8.1", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/@polkadot/api-derive/node_modules/@polkadot/rpc-augment": { + "version": "11.0.3", + "resolved": "https://registry.npmjs.org/@polkadot/rpc-augment/-/rpc-augment-11.0.3.tgz", + "integrity": "sha512-Yuiv6EPwdRXMZmleKE0u/qVc20Ut+9O5mLoxKM6jCplg+aWvc51pbS2XOpXEpvWRIWWzCSpqzVc6WcMMYU6MTA==", + "dependencies": { + "@polkadot/rpc-core": "11.0.3", + "@polkadot/types": "11.0.3", + "@polkadot/types-codec": "11.0.3", + "@polkadot/util": "^12.6.2", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/@polkadot/api-derive/node_modules/@polkadot/rpc-core": { + "version": "11.0.3", + "resolved": "https://registry.npmjs.org/@polkadot/rpc-core/-/rpc-core-11.0.3.tgz", + "integrity": "sha512-DhMUoAVxRw1Cv49lkVQ889eLbrfXZbNCFBTEMyauNUQFZUyIDE8w/FLPiOsyhiXwUww5wTMWte9UnWxvBlppvQ==", + "dependencies": { + "@polkadot/rpc-augment": "11.0.3", + "@polkadot/rpc-provider": "11.0.3", + "@polkadot/types": "11.0.3", + "@polkadot/util": "^12.6.2", + "rxjs": "^7.8.1", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/@polkadot/api-derive/node_modules/@polkadot/rpc-provider": { + "version": "11.0.3", + "resolved": "https://registry.npmjs.org/@polkadot/rpc-provider/-/rpc-provider-11.0.3.tgz", + "integrity": "sha512-xgfHOF4y9jAD9aDDX/i9WUCRw8N6duRs0P/ysw2AafGKUGSBA/pqP/WXN61dQqq+DzZYfzL/FsMyTcUirsEkJA==", + "dependencies": { + "@polkadot/keyring": "^12.6.2", + "@polkadot/types": "11.0.3", + "@polkadot/types-support": "11.0.3", + "@polkadot/util": "^12.6.2", + "@polkadot/util-crypto": "^12.6.2", + "@polkadot/x-fetch": "^12.6.2", + "@polkadot/x-global": "^12.6.2", + "@polkadot/x-ws": "^12.6.2", + "eventemitter3": "^5.0.1", + "mock-socket": "^9.3.1", + "nock": "^13.5.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18" + }, + "optionalDependencies": { + "@substrate/connect": "0.8.10" + } + }, + "node_modules/@polkadot/api-derive/node_modules/@polkadot/types": { + "version": "11.0.3", + "resolved": "https://registry.npmjs.org/@polkadot/types/-/types-11.0.3.tgz", + "integrity": "sha512-7AGUaObaGKZntOzHX4IRKj+K1AjZpYBgrivnY73tqGCp7biByn8Ht6a74xFngGfay1yRrx7eS3NOeIpp4nKhrw==", + "dependencies": { + "@polkadot/keyring": "^12.6.2", + "@polkadot/types-augment": "11.0.3", + "@polkadot/types-codec": "11.0.3", + "@polkadot/types-create": "11.0.3", "@polkadot/util": "^12.6.2", "@polkadot/util-crypto": "^12.6.2", "rxjs": "^7.8.1", @@ -487,17 +653,182 @@ "node": ">=18" } }, - "node_modules/@polkadot/api-derive": { - "version": "10.11.2", - "resolved": "https://registry.npmjs.org/@polkadot/api-derive/-/api-derive-10.11.2.tgz", - "integrity": "sha512-m3BQbPionkd1iSlknddxnL2hDtolPIsT+aRyrtn4zgMRPoLjHFmTmovvg8RaUyYofJtZeYrnjMw0mdxiSXx7eA==", + "node_modules/@polkadot/api-derive/node_modules/@polkadot/types-augment": { + "version": "11.0.3", + "resolved": "https://registry.npmjs.org/@polkadot/types-augment/-/types-augment-11.0.3.tgz", + "integrity": "sha512-/LXP/LDDr59ZigfeYXtYWrIr4qttYwlkEV7EMUnse5zYWAGH8mkras0Um7gX7kd/GndJAHvXAbbSdrduhg/uNA==", "dependencies": { - "@polkadot/api": "10.11.2", - "@polkadot/api-augment": "10.11.2", - "@polkadot/api-base": "10.11.2", - "@polkadot/rpc-core": "10.11.2", - "@polkadot/types": "10.11.2", - "@polkadot/types-codec": "10.11.2", + "@polkadot/types": "11.0.3", + "@polkadot/types-codec": "11.0.3", + "@polkadot/util": "^12.6.2", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/@polkadot/api-derive/node_modules/@polkadot/types-codec": { + "version": "11.0.3", + "resolved": "https://registry.npmjs.org/@polkadot/types-codec/-/types-codec-11.0.3.tgz", + "integrity": "sha512-WSYmacSfUnnspKpLbagng8zo84eXLOztCYSppmqLoCrwtQE0zg5P/jF18qIeozvmPh+I/HMordXKt34JPgI/6w==", + "dependencies": { + "@polkadot/util": "^12.6.2", + "@polkadot/x-bigint": "^12.6.2", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/@polkadot/api-derive/node_modules/@polkadot/types-create": { + "version": "11.0.3", + "resolved": "https://registry.npmjs.org/@polkadot/types-create/-/types-create-11.0.3.tgz", + "integrity": "sha512-/uK9BCaivd5kcqZZCeIOlN0pSFyIELk9VGVOM3HsitE6IQrOlYPrYe0RqrQhoU/kjNC5BHaWviYV3Hu3TlOJuw==", + "dependencies": { + "@polkadot/types-codec": "11.0.3", + "@polkadot/util": "^12.6.2", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/@polkadot/api-derive/node_modules/@polkadot/types-support": { + "version": "11.0.3", + "resolved": "https://registry.npmjs.org/@polkadot/types-support/-/types-support-11.0.3.tgz", + "integrity": "sha512-U9EG48zbbx5Q8B3GgHav8+/8hNYDOTijvSnEhUWsshh8U0Z7sNCmjfD4y0zfEzxoJyP7PTad62lJXfhQtehEsQ==", + "dependencies": { + "@polkadot/util": "^12.6.2", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/@polkadot/api-derive/node_modules/@substrate/connect": { + "version": "0.8.10", + "resolved": "https://registry.npmjs.org/@substrate/connect/-/connect-0.8.10.tgz", + "integrity": "sha512-DIyQ13DDlXqVFnLV+S6/JDgiGowVRRrh18kahieJxhgvzcWicw5eLc6jpfQ0moVVLBYkO7rctB5Wreldwpva8w==", + "optional": true, + "dependencies": { + "@substrate/connect-extension-protocol": "^2.0.0", + "@substrate/connect-known-chains": "^1.1.4", + "@substrate/light-client-extension-helpers": "^0.0.6", + "smoldot": "2.0.22" + } + }, + "node_modules/@polkadot/api-derive/node_modules/@substrate/connect-extension-protocol": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@substrate/connect-extension-protocol/-/connect-extension-protocol-2.0.0.tgz", + "integrity": "sha512-nKu8pDrE3LNCEgJjZe1iGXzaD6OSIDD4Xzz/yo4KO9mQ6LBvf49BVrt4qxBFGL6++NneLiWUZGoh+VSd4PyVIg==", + "optional": true + }, + "node_modules/@polkadot/api-derive/node_modules/smoldot": { + "version": "2.0.22", + "resolved": "https://registry.npmjs.org/smoldot/-/smoldot-2.0.22.tgz", + "integrity": "sha512-B50vRgTY6v3baYH6uCgL15tfaag5tcS2o/P5q1OiXcKGv1axZDfz2dzzMuIkVpyMR2ug11F6EAtQlmYBQd292g==", + "optional": true, + "dependencies": { + "ws": "^8.8.1" + } + }, + "node_modules/@polkadot/api/node_modules/@polkadot/api-augment": { + "version": "11.0.3", + "resolved": "https://registry.npmjs.org/@polkadot/api-augment/-/api-augment-11.0.3.tgz", + "integrity": "sha512-O1QEUXiHpPJqVe398EQ+tywZLj1vDNZALzh2TKsyFSqEjT4N/EschCck9aFXpB0Bp0K2lm7+fKJf6eWPShNfFQ==", + "dependencies": { + "@polkadot/api-base": "11.0.3", + "@polkadot/rpc-augment": "11.0.3", + "@polkadot/types": "11.0.3", + "@polkadot/types-augment": "11.0.3", + "@polkadot/types-codec": "11.0.3", + "@polkadot/util": "^12.6.2", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/@polkadot/api/node_modules/@polkadot/api-base": { + "version": "11.0.3", + "resolved": "https://registry.npmjs.org/@polkadot/api-base/-/api-base-11.0.3.tgz", + "integrity": "sha512-e/KSsDcFIG17SPw+buBXAq5NnBOMMOWljTljazDF7Nq3Sz6P+SFqOSb3kdICtp1fYAxg5my/uTs2OOARxJRXKA==", + "dependencies": { + "@polkadot/rpc-core": "11.0.3", + "@polkadot/types": "11.0.3", + "@polkadot/util": "^12.6.2", + "rxjs": "^7.8.1", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/@polkadot/api/node_modules/@polkadot/rpc-augment": { + "version": "11.0.3", + "resolved": "https://registry.npmjs.org/@polkadot/rpc-augment/-/rpc-augment-11.0.3.tgz", + "integrity": "sha512-Yuiv6EPwdRXMZmleKE0u/qVc20Ut+9O5mLoxKM6jCplg+aWvc51pbS2XOpXEpvWRIWWzCSpqzVc6WcMMYU6MTA==", + "dependencies": { + "@polkadot/rpc-core": "11.0.3", + "@polkadot/types": "11.0.3", + "@polkadot/types-codec": "11.0.3", + "@polkadot/util": "^12.6.2", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/@polkadot/api/node_modules/@polkadot/rpc-core": { + "version": "11.0.3", + "resolved": "https://registry.npmjs.org/@polkadot/rpc-core/-/rpc-core-11.0.3.tgz", + "integrity": "sha512-DhMUoAVxRw1Cv49lkVQ889eLbrfXZbNCFBTEMyauNUQFZUyIDE8w/FLPiOsyhiXwUww5wTMWte9UnWxvBlppvQ==", + "dependencies": { + "@polkadot/rpc-augment": "11.0.3", + "@polkadot/rpc-provider": "11.0.3", + "@polkadot/types": "11.0.3", + "@polkadot/util": "^12.6.2", + "rxjs": "^7.8.1", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/@polkadot/api/node_modules/@polkadot/rpc-provider": { + "version": "11.0.3", + "resolved": "https://registry.npmjs.org/@polkadot/rpc-provider/-/rpc-provider-11.0.3.tgz", + "integrity": "sha512-xgfHOF4y9jAD9aDDX/i9WUCRw8N6duRs0P/ysw2AafGKUGSBA/pqP/WXN61dQqq+DzZYfzL/FsMyTcUirsEkJA==", + "dependencies": { + "@polkadot/keyring": "^12.6.2", + "@polkadot/types": "11.0.3", + "@polkadot/types-support": "11.0.3", + "@polkadot/util": "^12.6.2", + "@polkadot/util-crypto": "^12.6.2", + "@polkadot/x-fetch": "^12.6.2", + "@polkadot/x-global": "^12.6.2", + "@polkadot/x-ws": "^12.6.2", + "eventemitter3": "^5.0.1", + "mock-socket": "^9.3.1", + "nock": "^13.5.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18" + }, + "optionalDependencies": { + "@substrate/connect": "0.8.10" + } + }, + "node_modules/@polkadot/api/node_modules/@polkadot/types": { + "version": "11.0.3", + "resolved": "https://registry.npmjs.org/@polkadot/types/-/types-11.0.3.tgz", + "integrity": "sha512-7AGUaObaGKZntOzHX4IRKj+K1AjZpYBgrivnY73tqGCp7biByn8Ht6a74xFngGfay1yRrx7eS3NOeIpp4nKhrw==", + "dependencies": { + "@polkadot/keyring": "^12.6.2", + "@polkadot/types-augment": "11.0.3", + "@polkadot/types-codec": "11.0.3", + "@polkadot/types-create": "11.0.3", "@polkadot/util": "^12.6.2", "@polkadot/util-crypto": "^12.6.2", "rxjs": "^7.8.1", @@ -507,6 +838,101 @@ "node": ">=18" } }, + "node_modules/@polkadot/api/node_modules/@polkadot/types-augment": { + "version": "11.0.3", + "resolved": "https://registry.npmjs.org/@polkadot/types-augment/-/types-augment-11.0.3.tgz", + "integrity": "sha512-/LXP/LDDr59ZigfeYXtYWrIr4qttYwlkEV7EMUnse5zYWAGH8mkras0Um7gX7kd/GndJAHvXAbbSdrduhg/uNA==", + "dependencies": { + "@polkadot/types": "11.0.3", + "@polkadot/types-codec": "11.0.3", + "@polkadot/util": "^12.6.2", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/@polkadot/api/node_modules/@polkadot/types-codec": { + "version": "11.0.3", + "resolved": "https://registry.npmjs.org/@polkadot/types-codec/-/types-codec-11.0.3.tgz", + "integrity": "sha512-WSYmacSfUnnspKpLbagng8zo84eXLOztCYSppmqLoCrwtQE0zg5P/jF18qIeozvmPh+I/HMordXKt34JPgI/6w==", + "dependencies": { + "@polkadot/util": "^12.6.2", + "@polkadot/x-bigint": "^12.6.2", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/@polkadot/api/node_modules/@polkadot/types-create": { + "version": "11.0.3", + "resolved": "https://registry.npmjs.org/@polkadot/types-create/-/types-create-11.0.3.tgz", + "integrity": "sha512-/uK9BCaivd5kcqZZCeIOlN0pSFyIELk9VGVOM3HsitE6IQrOlYPrYe0RqrQhoU/kjNC5BHaWviYV3Hu3TlOJuw==", + "dependencies": { + "@polkadot/types-codec": "11.0.3", + "@polkadot/util": "^12.6.2", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/@polkadot/api/node_modules/@polkadot/types-known": { + "version": "11.0.3", + "resolved": "https://registry.npmjs.org/@polkadot/types-known/-/types-known-11.0.3.tgz", + "integrity": "sha512-nuv/a32QYtZYCD7IMj+WKgcblgMJse2t3RuWO+ZtT/uscOmR7TjctkS2ayzSJDQ5wWCPGet1eIwYpJYfGFOPkw==", + "dependencies": { + "@polkadot/networks": "^12.6.2", + "@polkadot/types": "11.0.3", + "@polkadot/types-codec": "11.0.3", + "@polkadot/types-create": "11.0.3", + "@polkadot/util": "^12.6.2", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/@polkadot/api/node_modules/@polkadot/types-support": { + "version": "11.0.3", + "resolved": "https://registry.npmjs.org/@polkadot/types-support/-/types-support-11.0.3.tgz", + "integrity": "sha512-U9EG48zbbx5Q8B3GgHav8+/8hNYDOTijvSnEhUWsshh8U0Z7sNCmjfD4y0zfEzxoJyP7PTad62lJXfhQtehEsQ==", + "dependencies": { + "@polkadot/util": "^12.6.2", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/@polkadot/api/node_modules/@substrate/connect": { + "version": "0.8.10", + "resolved": "https://registry.npmjs.org/@substrate/connect/-/connect-0.8.10.tgz", + "integrity": "sha512-DIyQ13DDlXqVFnLV+S6/JDgiGowVRRrh18kahieJxhgvzcWicw5eLc6jpfQ0moVVLBYkO7rctB5Wreldwpva8w==", + "optional": true, + "dependencies": { + "@substrate/connect-extension-protocol": "^2.0.0", + "@substrate/connect-known-chains": "^1.1.4", + "@substrate/light-client-extension-helpers": "^0.0.6", + "smoldot": "2.0.22" + } + }, + "node_modules/@polkadot/api/node_modules/@substrate/connect-extension-protocol": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@substrate/connect-extension-protocol/-/connect-extension-protocol-2.0.0.tgz", + "integrity": "sha512-nKu8pDrE3LNCEgJjZe1iGXzaD6OSIDD4Xzz/yo4KO9mQ6LBvf49BVrt4qxBFGL6++NneLiWUZGoh+VSd4PyVIg==", + "optional": true + }, + "node_modules/@polkadot/api/node_modules/smoldot": { + "version": "2.0.22", + "resolved": "https://registry.npmjs.org/smoldot/-/smoldot-2.0.22.tgz", + "integrity": "sha512-B50vRgTY6v3baYH6uCgL15tfaag5tcS2o/P5q1OiXcKGv1axZDfz2dzzMuIkVpyMR2ug11F6EAtQlmYBQd292g==", + "optional": true, + "dependencies": { + "ws": "^8.8.1" + } + }, "node_modules/@polkadot/keyring": { "version": "12.6.2", "resolved": "https://registry.npmjs.org/@polkadot/keyring/-/keyring-12.6.2.tgz", @@ -936,6 +1362,36 @@ "integrity": "sha512-161JhCC1csjH3GE5mPLEd7HbWtwNSPJBg3p1Ksz9SFlTzj/bgEwudiRN2y5i0MoLGCIJRYKyKGMxVnd29PzNjg==", "optional": true }, + "node_modules/@substrate/connect-known-chains": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@substrate/connect-known-chains/-/connect-known-chains-1.1.4.tgz", + "integrity": "sha512-iT+BdKqvKl/uBLd8BAJysFM1BaMZXRkaXBP2B7V7ob/EyNs5h0EMhTVbO6MJxV/IEOg5OKsyl6FUqQK7pKnqyw==", + "optional": true + }, + "node_modules/@substrate/light-client-extension-helpers": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/@substrate/light-client-extension-helpers/-/light-client-extension-helpers-0.0.6.tgz", + "integrity": "sha512-girltEuxQ1BvkJWmc8JJlk4ZxnlGXc/wkLcNguhY+UoDEMBK0LsdtfzQKIfrIehi4QdeSBlFEFBoI4RqPmsZzA==", + "optional": true, + "dependencies": { + "@polkadot-api/json-rpc-provider": "0.0.1", + "@polkadot-api/json-rpc-provider-proxy": "0.0.1", + "@polkadot-api/observable-client": "0.1.0", + "@polkadot-api/substrate-client": "0.0.1", + "@substrate/connect-extension-protocol": "^2.0.0", + "@substrate/connect-known-chains": "^1.1.4", + "rxjs": "^7.8.1" + }, + "peerDependencies": { + "smoldot": "2.x" + } + }, + "node_modules/@substrate/light-client-extension-helpers/node_modules/@substrate/connect-extension-protocol": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@substrate/connect-extension-protocol/-/connect-extension-protocol-2.0.0.tgz", + "integrity": "sha512-nKu8pDrE3LNCEgJjZe1iGXzaD6OSIDD4Xzz/yo4KO9mQ6LBvf49BVrt4qxBFGL6++NneLiWUZGoh+VSd4PyVIg==", + "optional": true + }, "node_modules/@substrate/ss58-registry": { "version": "1.44.0", "resolved": "https://registry.npmjs.org/@substrate/ss58-registry/-/ss58-registry-1.44.0.tgz", @@ -1734,9 +2190,9 @@ "integrity": "sha512-ty/fTekppD2fIwRvnZAVdeOiGd1c7YXEixbgJTNzqcxJWKQnjJ/V1bNEEE6hygpM3WjwHFUVK6HTjWSzV4a8sQ==" }, "node_modules/coretime-utils": { - "version": "0.2.3", - "resolved": "https://registry.npmjs.org/coretime-utils/-/coretime-utils-0.2.3.tgz", - "integrity": "sha512-dhKdYwv7XOd5LUYIQR1R3FZGtEG75buzmoKoYXov5Cnc0xcBXwdAC33rAKR1NbTTXiImQvEG/kpgOVhG+H7RwA==", + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/coretime-utils/-/coretime-utils-0.3.2.tgz", + "integrity": "sha512-9n/RUznOMJv62W4zht5a+A3xAHTup9Aqja62YKDZEa7S64Nocf3EJItZba/xAXGuCGPVGQHtZbZ21OiJ7b4ZDA==", "dependencies": { "@polkadot/util": "^12.6.2" } @@ -3265,9 +3721,9 @@ } }, "node_modules/nock": { - "version": "13.4.0", - "resolved": "https://registry.npmjs.org/nock/-/nock-13.4.0.tgz", - "integrity": "sha512-W8NVHjO/LCTNA64yxAPHV/K47LpGYcVzgKd3Q0n6owhwvD0Dgoterc25R4rnZbckJEb6Loxz1f5QMuJpJnbSyQ==", + "version": "13.5.4", + "resolved": "https://registry.npmjs.org/nock/-/nock-13.5.4.tgz", + "integrity": "sha512-yAyTfdeNJGGBFxWdzSKCBYxs5FxLbCg5X5Q4ets974hcQzG1+qCxvIyOo4j2Ry6MUlhWVMX4OoYDefAIIwupjw==", "dependencies": { "debug": "^4.1.0", "json-stringify-safe": "^5.0.1", @@ -3949,6 +4405,12 @@ "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", "optional": true }, + "node_modules/scale-ts": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/scale-ts/-/scale-ts-1.6.0.tgz", + "integrity": "sha512-Ja5VCjNZR8TGKhUumy9clVVxcDpM+YFjAnkMuwQy68Hixio3VRRvWdE3g8T/yC+HXA0ZDQl2TGyUmtmbcVl40Q==", + "optional": true + }, "node_modules/secure-json-parse": { "version": "2.7.0", "resolved": "https://registry.npmjs.org/secure-json-parse/-/secure-json-parse-2.7.0.tgz", diff --git a/package.json b/package.json index 8d32a74..d71856e 100644 --- a/package.json +++ b/package.json @@ -5,11 +5,9 @@ "main": "index.js", "scripts": { "chopsticks": "npx @acala-network/chopsticks@latest -c ./configs/coretime-rococo.yml", - "zombienet:full": "./scripts/run_zombienet.sh full", + "zombienet": "./scripts/run_zombienet.sh full", "chopsticks-init": "npx ts-node src/chopsticks.init.ts", - "zombienet-init": "npx ts-node src/zombienet.init.ts", - "zombienet-init:full": "npx ts-node src/zombienet.init.ts --fullNetwork", - "zombienet-init:local": "npx ts-node src/zombienet.init.ts --local", + "init": "npx ts-node src/zombienet.init.ts", "prettier": "prettier --write src/", "lint": "eslint src --ext .ts,.tsx", "lint:fix": "eslint src --ext .ts,.tsx --fix" @@ -19,13 +17,11 @@ "license": "ISC", "dependencies": { "@acala-network/chopsticks": "0.9.4", - "@polkadot/api": "^10.11.1", - "@polkadot/api-contract": "^10.11.2", + "@polkadot/api": "^11.0.3", "@polkadot/keyring": "^12.6.2", "@polkadot/util-crypto": "^12.6.2", - "bn.js": "^5.2.1", "commander": "^11.1.0", - "coretime-utils": "^0.2.3", + "coretime-utils": "^0.3.2", "ts-node": "^10.9.2" }, "devDependencies": { diff --git a/polkadot-sdk b/polkadot-sdk deleted file mode 160000 index 150d492..0000000 --- a/polkadot-sdk +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 150d4921cdad4540b2af7142ee70c16e48405549 diff --git a/scripts/full_init.sh b/scripts/full_init.sh deleted file mode 100755 index 2819f86..0000000 --- a/scripts/full_init.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash - -if [ -d "bin" ]; then - rm -r bin/ -fi -mkdir bin/ - -cd polkadot-sdk/ - -# Build the polkadot relay chain binary. Needed to run rococo. -cargo build --locked --profile testnet --features fast-runtime --bin polkadot --bin polkadot-prepare-worker --bin polkadot-execute-worker - -# Build the polkadot-parachain binary. Needed to run the Coretime chain. -cargo build --profile testnet -p polkadot-parachain-bin - -cp ./target/testnet/polkadot-parachain ../bin/ -cp ./target/testnet/polkadot ../bin/ -cp ./target/testnet/polkadot-execute-worker ../bin/ -cp ./target/testnet/polkadot-prepare-worker ../bin/ - -cd ../Astar/ -cargo build --release -cp ./target/release/astar-collator ../bin/ - -cd .. diff --git a/scripts/minimal_init.sh b/scripts/minimal_init.sh deleted file mode 100755 index 9528d2f..0000000 --- a/scripts/minimal_init.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash - -if [ -d "bin" ]; then - rm -r bin/ -fi -mkdir bin/ - -cd polkadot-sdk/ - -# Build the polkadot relay chain binary. Needed to run rococo. -cargo build --locked --profile testnet --features fast-runtime --bin polkadot --bin polkadot-prepare-worker --bin polkadot-execute-worker - -# Build the polkadot-parachain binary. Needed to run the Coretime chain. -cargo build --profile testnet -p polkadot-parachain-bin - -cp ./target/testnet/polkadot-parachain ../bin/ -cp ./target/testnet/polkadot ../bin/ -cp ./target/testnet/polkadot-execute-worker ../bin/ -cp ./target/testnet/polkadot-prepare-worker ../bin/ - -cd .. diff --git a/scripts/run_zombienet.sh b/scripts/run_zombienet.sh index 5f5aaf8..40c5ad7 100755 --- a/scripts/run_zombienet.sh +++ b/scripts/run_zombienet.sh @@ -1,17 +1,6 @@ #!/bin/bash -start_full="-p native spawn ./zombienet/full_network.toml" -start_minimal="-p native spawn ./zombienet/minimal_network.toml" - -# Check the mode and set the appropriate arguments -if [ "$1" == "full" ]; then - zombienet_args=$start_full -elif [ "$1" == "minimal" ]; then - zombienet_args=$start_minimal -else - echo "Invalid mode. Please specify 'full' or 'minimal'." - exit 1 -fi +zombienet_args="-p native spawn ./zombienet/network.toml" if which zombienet-macos &> /dev/null; then zombienet-macos $zombienet_args diff --git a/src/contracts/contract.ts b/src/contracts/contract.ts deleted file mode 100644 index da339c3..0000000 --- a/src/contracts/contract.ts +++ /dev/null @@ -1,164 +0,0 @@ -import { ApiPromise } from "@polkadot/api"; -import { keyring, log } from "../utils"; -import { - getContractAddress, - getMarketMetadata, - getMarketWasm, - getMaxGasLimit, - getXcRegionsMetadata, - getXcRegionsWasm, -} from "./utils"; -import { Abi, ContractPromise } from "@polkadot/api-contract"; -import { Region } from "coretime-utils"; -import { u8aToHex } from "@polkadot/util"; -import type { WeightV2 } from "@polkadot/types/interfaces"; -import { BN, bnToBn } from "@polkadot/util"; - -export async function deployXcRegions(contractsApi: ApiPromise, contractsPath: string): Promise { - log(`Uploading xcRegions contract code`); - - const wasm = getXcRegionsWasm(contractsPath); - const metadata = getXcRegionsMetadata(contractsApi, contractsPath); - - return Promise.resolve(instantiateWithCode(contractsApi, wasm, metadata, [])); -} - -export async function deployMarket( - contractsApi: ApiPromise, - xcRegionsContract: string, - contractsPath: string -): Promise { - log(`Uploading market contract code`); - - const wasm = getMarketWasm(contractsPath); - const metadata = getMarketMetadata(contractsApi, contractsPath); - const listingDeposit = 0; - const timeslicePeriod = 80; - - return Promise.resolve( - instantiateWithCode(contractsApi, wasm, metadata, [xcRegionsContract, listingDeposit, timeslicePeriod]) - ); -} - -export async function instantiateWithCode( - contractsApi: ApiPromise, - wasm: Buffer, - metadata: Abi, - params: any[] -): Promise { - const alice = keyring.addFromUri("//Alice"); - - const value = 0; - const storageDepositLimit = null; - - const instantiate = contractsApi.tx.contracts.instantiateWithCode( - value, - getMaxGasLimit(), - storageDepositLimit, - u8aToHex(wasm), - metadata.findConstructor(0).toU8a(params), - null - ); - - const callTx = async (resolve: (address: string) => void) => { - const unsub = await instantiate.signAndSend(alice, async (result: any) => { - if (result.status.isInBlock) { - const address = await getContractAddress(contractsApi); - unsub(); - resolve(address); - } - }); - }; - - return new Promise(callTx); -} - -export async function initXcRegion( - contractsApi: ApiPromise, - contractAddress: string, - region: Region, - contractsPath: string -): Promise { - log(`Initializing the metadata for a xc-region`); - - const metadata = getXcRegionsMetadata(contractsApi, contractsPath); - const xcRegionsContract = new ContractPromise(contractsApi, metadata, contractAddress); - - const rawRegionId = region.getEncodedRegionId(contractsApi); - const id = contractsApi.createType("Id", { U128: rawRegionId }); - - const alice = keyring.addFromUri("//Alice"); - - const callArguments = [ - id, - // All the region metadata combined: - { - begin: region.getBegin(), - end: region.getEnd(), - core: region.getCore(), - mask: region.getMask().getMask(), - }, - ]; - - const initCall = xcRegionsContract.tx["regionMetadata::init"]( - { gasLimit: getGasLimit(contractsApi, "8000000000", "250000"), storageDepositLimit: null }, - ...callArguments - ); - - const callTx = async (resolve: () => void) => { - const unsub = await initCall.signAndSend(alice, (result: any) => { - if (result.status.isInBlock) { - unsub(); - resolve(); - } - }); - }; - - return new Promise(callTx); -} - -export async function transferWrappedRegion( - contractsApi: ApiPromise, - contractAddress: string, - region: Region, - receiver: string, - contractsPath: string -): Promise { - log(`Transferring wrapped region to ${receiver}`); - - const metadata = getXcRegionsMetadata(contractsApi, contractsPath); - const xcRegionsContract = new ContractPromise(contractsApi, metadata, contractAddress); - - const rawRegionId = region.getEncodedRegionId(contractsApi); - - const alice = keyring.addFromUri("//Alice"); - - const id = contractsApi.createType("Id", { U128: rawRegionId }); - const callArguments = [receiver, id, []]; - - const transferCall = xcRegionsContract.tx["psp34::transfer"]( - { gasLimit: getGasLimit(contractsApi, "8000000000", "250000"), storageDepositLimit: null }, - ...callArguments - ); - - const callTx = async (resolve: () => void) => { - const unsub = await transferCall.signAndSend(alice, (result: any) => { - if (result.status.isInBlock) { - unsub(); - resolve(); - } - }); - }; - - return new Promise(callTx); -} - -export const getGasLimit = (api: ApiPromise, _refTime: string | BN, _proofSize: string | BN): WeightV2 => { - const refTime = bnToBn(_refTime); - const proofSize = bnToBn(_proofSize); - - return api.registry.createType("WeightV2", { - refTime, - proofSize, - }) as WeightV2; -}; diff --git a/src/contracts/index.init.ts b/src/contracts/index.init.ts deleted file mode 100644 index fcab393..0000000 --- a/src/contracts/index.init.ts +++ /dev/null @@ -1,52 +0,0 @@ -import { ApiPromise, WsProvider } from "@polkadot/api"; -import Keyring from "@polkadot/keyring"; -import { CoreMask, Id, Region } from "coretime-utils"; -import { log, setBalance } from "../utils"; -import { deployMarket, deployXcRegions, initXcRegion, transferWrappedRegion } from "./contract"; -import { approveTransfer, createRegionCollection, mintRegion, registerXcRegionAsset } from "./uniques"; -import * as consts from "../consts"; - -const keyring = new Keyring({ type: "sr25519" }); - -export async function contractsInit(contractsEndpoint: string, account: string, contractsPath: string, mint: boolean) { - const alice = keyring.addFromUri("//Alice"); - - const contractsProvider = new WsProvider(contractsEndpoint); - const contractsApi = await ApiPromise.create({ provider: contractsProvider, types: { Id } }); - - const xcRegionsAddress = await deployXcRegions(contractsApi, contractsPath); - log(`XcRegions address: ${xcRegionsAddress}`); - - const marketAddress = await deployMarket(contractsApi, xcRegionsAddress, contractsPath); - log(`Market address: ${marketAddress}`); - - await createRegionCollection(contractsApi); - await registerXcRegionAsset(contractsApi); - - if (account) { - await setBalance(contractsApi, account, (10 ** 8 * consts.UNIT).toString()); - } - - if (mint) { - const mockRegions = [ - new Region( - { begin: 30, core: 0, mask: CoreMask.fromChunk(0, 40) }, - { end: 60, owner: alice.address, paid: null } - ), - new Region({ begin: 5, core: 1, mask: CoreMask.completeMask() }, { end: 30, owner: alice.address, paid: null }), - new Region( - { begin: 5, core: 2, mask: CoreMask.fromChunk(40, 60) }, - { end: 30, owner: alice.address, paid: null } - ), - ]; - - for await (const mockRegion of mockRegions) { - await mintRegion(contractsApi, mockRegion); - await approveTransfer(contractsApi, mockRegion, xcRegionsAddress); - await initXcRegion(contractsApi, xcRegionsAddress, mockRegion, contractsPath); - if (account) { - await transferWrappedRegion(contractsApi, xcRegionsAddress, mockRegion, account, contractsPath); - } - } - } -} diff --git a/src/contracts/uniques.ts b/src/contracts/uniques.ts deleted file mode 100644 index 7b2e0f9..0000000 --- a/src/contracts/uniques.ts +++ /dev/null @@ -1,83 +0,0 @@ -import { ApiPromise } from "@polkadot/api"; -import { force, log } from "../utils"; -import { keyring } from "../utils"; -import { Region } from "coretime-utils"; - -const REGION_COLLECTION_ID = 42; - -// Create a mock collection that will represent regions. -export async function createRegionCollection(contractsApi: ApiPromise): Promise { - log(`Creating the region collection`); - - const alice = keyring.addFromUri("//Alice"); - const createCollectionCall = contractsApi.tx.uniques.create(REGION_COLLECTION_ID, alice.address); - - const callTx = async (resolve: () => void) => { - const unsub = await createCollectionCall.signAndSend(alice, (result: any) => { - if (result.status.isInBlock) { - unsub(); - resolve(); - } - }); - }; - - return new Promise(callTx); -} - -export async function registerXcRegionAsset(contractsApi: ApiPromise): Promise { - if (!contractsApi.tx.xcAssetConfig) return; - - log(`Registering xc-region asset`); - - const registerCall = contractsApi.tx.xcAssetConfig.registerAssetLocation( - { - V3: { - parents: 1, - interior: { - X2: [{ Parachain: 1005 }, { PalletInstance: 50 }], - }, - }, - }, - REGION_COLLECTION_ID - ); - - return force(contractsApi, registerCall); -} - -export async function mintRegion(contractsApi: ApiPromise, region: Region): Promise { - log(`Minting a region`); - - const alice = keyring.addFromUri("//Alice"); - const rawRegionId = region.getEncodedRegionId(contractsApi); - const mintCall = contractsApi.tx.uniques.mint(REGION_COLLECTION_ID, rawRegionId, alice.address); - - const callTx = async (resolve: () => void) => { - const unsub = await mintCall.signAndSend(alice, (result: any) => { - if (result.status.isInBlock) { - unsub(); - resolve(); - } - }); - }; - - return new Promise(callTx); -} - -export async function approveTransfer(contractsApi: ApiPromise, region: Region, delegate: string): Promise { - log(`Approving region to ${delegate}`); - - const alice = keyring.addFromUri("//Alice"); - const rawRegionId = region.getEncodedRegionId(contractsApi); - const approveCall = contractsApi.tx.uniques.approveTransfer(REGION_COLLECTION_ID, rawRegionId, delegate); - - const callTx = async (resolve: () => void) => { - const unsub = await approveCall.signAndSend(alice, (result: any) => { - if (result.status.isInBlock) { - unsub(); - resolve(); - } - }); - }; - - return new Promise(callTx); -} diff --git a/src/contracts/utils.ts b/src/contracts/utils.ts deleted file mode 100644 index f1265bd..0000000 --- a/src/contracts/utils.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { ApiPromise } from "@polkadot/api"; -import fs from "fs"; -import { Abi } from "@polkadot/api-contract"; -import { log } from "../utils"; - -export async function getContractAddress(contractsApi: ApiPromise): Promise { - log("Getting contract address"); - const events: any = await contractsApi.query.system.events(); - - for (const record of events) { - const { event } = record; - if (event.section === "contracts" && event.method === "Instantiated") { - return event.data[1].toString(); - } - } - - return ""; -} - -export const getXcRegionsMetadata = (contractsApi: ApiPromise, contractsPath: string) => - new Abi( - fs.readFileSync(`${contractsPath}/xc_regions/xc_regions.json`, "utf-8"), - contractsApi.registry.getChainProperties() - ); - -export const getMarketMetadata = (contractsApi: ApiPromise, contractsPath: string) => - new Abi( - fs.readFileSync(`${contractsPath}/coretime_market/coretime_market.json`, "utf-8"), - contractsApi.registry.getChainProperties() - ); - -export const getXcRegionsWasm = (contractsPath: string) => - fs.readFileSync(`${contractsPath}/xc_regions/xc_regions.wasm`); - -export const getMarketWasm = (contractsPath: string) => - fs.readFileSync(`${contractsPath}/coretime_market/coretime_market.wasm`); - -export const getMaxGasLimit = () => { - return { - refTime: 5000000000, - proofSize: 900000, - }; -}; diff --git a/src/coretime/index.init.ts b/src/coretime/index.init.ts index 8decd1d..eca62f8 100644 --- a/src/coretime/index.init.ts +++ b/src/coretime/index.init.ts @@ -1,12 +1,8 @@ import { ApiPromise, WsProvider } from "@polkadot/api"; -import { force, keyring, log, setBalance } from "../utils"; -import { KeyringPair } from "@polkadot/keyring/types"; -import { CoreMask, RegionId } from "coretime-utils"; +import { force, log, setBalance } from "../utils"; import * as consts from "../consts"; export async function coretimeInit(coretimeEndpoint: string, coretimeAccount: string) { - const alice = keyring.addFromUri("//Alice"); - const coretimeWsProvider = new WsProvider(coretimeEndpoint); const coretimeApi = await ApiPromise.create({ provider: coretimeWsProvider }); @@ -14,13 +10,8 @@ export async function coretimeInit(coretimeEndpoint: string, coretimeAccount: st await configureBroker(coretimeApi); await startSales(coretimeApi); - await setBalance(coretimeApi, alice.address, (1000 * consts.UNIT).toString()); - - const regionId = await purchaseRegion(coretimeApi, alice); - if (coretimeAccount) { await setBalance(coretimeApi, coretimeAccount, (1000 * consts.UNIT).toString()); - await transferRegion(coretimeApi, alice, coretimeAccount, regionId); } } @@ -44,56 +35,3 @@ async function forceSafeXCMVersion(coretimeApi: ApiPromise): Promise { const setVersionCall = coretimeApi.tx.polkadotXcm.forceDefaultXcmVersion([3]); return force(coretimeApi, setVersionCall); } - -export async function purchaseRegion(coretimeApi: ApiPromise, buyer: KeyringPair): Promise { - log(`Purchasing a region.`); - - const callTx = async (resolve: (regionId: RegionId) => void) => { - const purchase = coretimeApi.tx.broker.purchase(consts.INITIAL_PRICE * 2); - const unsub = await purchase.signAndSend(buyer, async (result: any) => { - if (result.status.isInBlock) { - const regionId = await getRegionId(coretimeApi); - unsub(); - resolve(regionId); - } - }); - }; - - return new Promise(callTx); -} - -export async function transferRegion( - coretimeApi: ApiPromise, - sender: KeyringPair, - receiver: string, - regionId: RegionId -): Promise { - log(`Transferring a region to ${receiver}`); - - const callTx = async (resolve: () => void) => { - const transfer = coretimeApi.tx.broker.transfer(regionId, receiver); - const unsub = await transfer.signAndSend(sender, (result: any) => { - if (result.status.isInBlock) { - unsub(); - resolve(); - } - }); - }; - - return new Promise(callTx); -} - -async function getRegionId(coretimeApi: ApiPromise): Promise { - log("Getting regionId"); - const events: any = await coretimeApi.query.system.events(); - - for (const record of events) { - const { event } = record; - if (event.section === "broker" && event.method === "Purchased") { - log("Found RegionId: " + event.data[1].toString()); - return event.data[1]; - } - } - - return { begin: 0, core: 0, mask: CoreMask.voidMask() }; -} diff --git a/src/regionx/index.init.ts b/src/regionx/index.init.ts new file mode 100644 index 0000000..1796902 --- /dev/null +++ b/src/regionx/index.init.ts @@ -0,0 +1,87 @@ +import { ApiPromise, Keyring, WsProvider } from "@polkadot/api"; +import { force, keyring, log, submitExtrinsic } from "../utils"; +import { KeyringPair } from "@polkadot/keyring/types"; + +const RELAY_ASSET_ID = 1; + +export async function regionxInit(relayEndpoint: string, regionxEndpoint: string, regionxAccount: string) { + const alice = keyring.addFromUri("//Alice"); + + const regionxWsProvider = new WsProvider(regionxEndpoint); + const regionxApi = await ApiPromise.create({ provider: regionxWsProvider }); + const relayWsProvider = new WsProvider(relayEndpoint); + const relayApi = await ApiPromise.create({ provider: relayWsProvider }); + + await setupRelayAsset(regionxApi); + + if (regionxAccount) { + const giveBalanceCall = regionxApi.tx.balances.forceSetBalance(regionxAccount, 10n ** 18n); + await force(regionxApi, giveBalanceCall); + await transferRelayTokensToRegionX(100n * 10n ** 12n, regionxAccount, relayApi, alice); + } +} + +async function setupRelayAsset(api: ApiPromise) { + log("Settting up relay token on RegionX"); + const assetMetadata = { + decimals: 12, + name: "ROC", + symbol: "ROC", + existentialDeposit: 10n ** 3n, + location: null, + additional: null, + }; + + const assetSetupCalls = [ + api.tx.assetRegistry.registerAsset(assetMetadata, RELAY_ASSET_ID), + api.tx.assetRate.create(RELAY_ASSET_ID, 1_000_000_000_000_000_000n), // 1 on 1 + ]; + + const batchCall = api.tx.utility.batch(assetSetupCalls); + return force(api, batchCall); +} +async function transferRelayTokensToRegionX( + amount: bigint, + receiver: string, + relayApi: ApiPromise, + signer: KeyringPair +): Promise { + log("Teleporting relay tokens to RegionX"); + const receiverKeypair = new Keyring(); + receiverKeypair.addFromAddress(receiver); + + const feeAssetItem = 0; + const weightLimit = "Unlimited"; + const reserveTransfer = relayApi.tx.xcmPallet.limitedReserveTransferAssets( + { V3: { parents: 0, interior: { X1: { Parachain: 2000 } } } }, //dest + { + V3: { + parents: 0, + interior: { + X1: { + AccountId32: { + chain: "Any", + id: receiverKeypair.pairs[0].publicKey, + }, + }, + }, + }, + }, //beneficiary + { + V3: [ + { + id: { + Concrete: { parents: 0, interior: "Here" }, + }, + fun: { + Fungible: amount, + }, + }, + ], + }, //asset + feeAssetItem, + weightLimit + ); + + return submitExtrinsic(signer, reserveTransfer, {}); +} diff --git a/src/relay/index.init.ts b/src/relay/index.init.ts index 9c6fb1f..3eb1184 100644 --- a/src/relay/index.init.ts +++ b/src/relay/index.init.ts @@ -1,10 +1,11 @@ import { ApiPromise, WsProvider } from "@polkadot/api"; -import { keyring, log } from "../utils"; +import { force, keyring, log, submitExtrinsic } from "../utils"; export async function relayInit(relayEndpoint: string, coretimeParaId: number, contractsParaId: number) { const relayWsProvider = new WsProvider(relayEndpoint); const relayApi = await ApiPromise.create({ provider: relayWsProvider }); + await forceSafeXCMVersion(relayApi); await openHrmpChannel(relayApi, coretimeParaId, contractsParaId); await openHrmpChannel(relayApi, contractsParaId, coretimeParaId); } @@ -24,14 +25,12 @@ async function openHrmpChannel(relayApi: ApiPromise, sender: number, recipient: const openHrmp = relayApi.tx.parasSudoWrapper.sudoEstablishHrmpChannel(...newHrmpChannel); const sudoCall = relayApi.tx.sudo.sudo(openHrmp); - const callTx = async (resolve: () => void) => { - const unsub = await sudoCall.signAndSend(alice, (result: any) => { - if (result.status.isInBlock) { - unsub(); - resolve(); - } - }); - }; + return submitExtrinsic(alice, sudoCall, {}); +} + +async function forceSafeXCMVersion(relayApi: ApiPromise): Promise { + log(`Setting the safe XCM version to V3`); - return new Promise(callTx); + const setVersionCall = relayApi.tx.xcmPallet.forceDefaultXcmVersion([3]); + return force(relayApi, setVersionCall); } diff --git a/src/utils.ts b/src/utils.ts index 3f58354..025154b 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,4 +1,6 @@ import { ApiPromise, Keyring } from "@polkadot/api"; +import { SignerOptions, SubmittableExtrinsic } from "@polkadot/api/types"; +import { KeyringPair } from "@polkadot/keyring/types"; export const keyring = new Keyring({ type: "sr25519" }); @@ -21,19 +23,37 @@ export async function setBalance(coretimeApi: ApiPromise, who: string, balance: return force(coretimeApi, setBalanceCall); } -export async function force(api: ApiPromise, call: any): Promise { +export async function submitExtrinsic( + signer: KeyringPair, + call: SubmittableExtrinsic<"promise">, + options: Partial +): Promise { + try { + return new Promise((resolve, reject) => { + const unsub = call.signAndSend(signer, options, (result) => { + console.log(`Current status is ${result.status}`); + if (result.status.isInBlock) { + console.log(`Transaction included at blockHash ${result.status.asInBlock}`); + } else if (result.status.isFinalized) { + console.log(`Transaction finalized at blockHash ${result.status.asFinalized}`); + unsub.then(); + return resolve(); + } else if (result.isError) { + console.log("Transaction error"); + unsub.then(); + return reject(); + } + }); + }); + } catch (e) { + console.log(e); + } +} + +export async function force(api: ApiPromise, call: SubmittableExtrinsic<"promise">): Promise { const sudoCall = api.tx.sudo.sudo(call); const alice = keyring.addFromUri("//Alice"); - const callTx = async (resolve: () => void) => { - const unsub = await sudoCall.signAndSend(alice, (result: any) => { - if (result.status.isInBlock) { - unsub(); - resolve(); - } - }); - }; - - return new Promise(callTx); + await submitExtrinsic(alice, sudoCall, {}); } diff --git a/src/zombienet.init.ts b/src/zombienet.init.ts index fd2e551..f4efeb2 100644 --- a/src/zombienet.init.ts +++ b/src/zombienet.init.ts @@ -3,17 +3,14 @@ import { program } from "commander"; import process from "process"; import { relayInit } from "./relay/index.init"; import { coretimeInit } from "./coretime/index.init"; -import { contractsInit } from "./contracts/index.init"; -import { normalizePath } from "./utils"; +import { regionxInit } from "./regionx/index.init"; program .option("--relayInit") .option("--coretimeInit") - .option("--contractsInit") - .option("--contractsPath ") - .option("--contractsAccount ") + .option("--regionxInit") .option("--coretimeAccount ") - .option("--mintXcRegions"); + .option("--regionxAccount "); program.parse(process.argv); @@ -22,7 +19,7 @@ const CONTRACTS_PARA_ID = 2000; const ROCOCO_ENDPOINT = "ws://127.0.0.1:9900"; const CORETIME_ENDPOINT = "ws://127.0.0.1:9910"; -const CONTRACTS_ENDPOINT = "ws://127.0.0.1:9920"; +const REGIONX_ENDPOINT = "ws://127.0.0.1:9920"; async function init() { await cryptoWaitReady(); @@ -35,17 +32,8 @@ async function init() { await coretimeInit(CORETIME_ENDPOINT, program.opts().coretimeAccount || ""); } - if (program.opts().contractsInit) { - if (!program.opts().contractsPath) { - throw new Error("--contractsPath must be specified"); - } - const contractsPath = normalizePath(program.opts().contractsPath); - await contractsInit( - CONTRACTS_ENDPOINT, - program.opts().contractsAccount || "", - contractsPath, - program.opts().mintXcRegions - ); + if (program.opts().regionxInit) { + await regionxInit(ROCOCO_ENDPOINT, REGIONX_ENDPOINT, program.opts().regionxAccount || ""); } } diff --git a/zombienet/full_network.toml b/zombienet/network.toml similarity index 52% rename from zombienet/full_network.toml rename to zombienet/network.toml index ffd272d..2e06bf6 100644 --- a/zombienet/full_network.toml +++ b/zombienet/network.toml @@ -16,20 +16,9 @@ default_command = "./bin/polkadot" validator = true extra_args = [ "-lparachain=debug" ] - [[relaychain.nodes]] - name = "charlie" - validator = true - extra_args = [ "-lparachain=debug" ] - - [[relaychain.nodes]] - name = "dave" - validator = true - extra_args = [ "-lparachain=debug" ] - [[parachains]] id = 1005 -add_to_genesis = true -cumulus_based = true +add_to_genesis = false chain = "coretime-rococo-local" [[parachains.collators]] @@ -46,23 +35,10 @@ chain = "coretime-rococo-local" [[parachains]] id = 2000 -add_to_genesis = true -cumulus_based = true -chain = "shibuya-dev" +addToGenesis = false - [[parachains.collators]] - name = "astar-collator01" - command = "./bin/astar-collator" + [parachains.collator] + name = "regionx-collator01" + command = "./bin/regionx-node" ws_port = 9920 - args = ["--log=xcm=trace"] - - [[parachains.collators]] - name = "astar-collator02" - command = "./bin/astar-collator" - ws_port = 9921 - args = ["--log=xcm=trace"] - -[types.Header] -number = "u64" -parent_hash = "Hash" -post_state = "Hash" + args = [ "--log=xcm=trace,regions=trace" ]