Skip to content

Commit

Permalink
Coretime market implementation (#17)
Browse files Browse the repository at this point in the history
* init coretime-market

* add storage

* cross-contract calling

* list_region

* init e2e tests

* add enumeration

* XcRegions: fix remove

* deposit docs

* current_timeslice

* list_region untested

* purchase_region implemented

* fix

* calculate_region_price wip

* fix calculate_region_price

* current_timeslice | wip

* use sp-arithmetic

* fix attempt

* introduce reference points

* init e2e js tests

* constructors work

* extrinsic calls work

* listing works

* listing fully tested

* init purchase tests

* use block-number provider

* tests passing

* more tests

* check events

* timeslice based pricing

* e2e tests passing

* fixes

* remove artifacts & types

* remove unused

* clippy
  • Loading branch information
Szegoo authored Feb 3, 2024
1 parent 403d89b commit 6772945
Show file tree
Hide file tree
Showing 30 changed files with 5,227 additions and 103 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
- name: Run cargo-tarpaulin
uses: actions-rs/tarpaulin@v0.1
with:
version: "0.21.0"
version: '0.21.0'

- name: Upload to codecov.io
uses: codecov/codecov-action@v3.1.0
Expand Down Expand Up @@ -96,7 +96,7 @@ jobs:

- name: Ensure clippy is happy
run: cargo clippy -- -D warnings

build:
needs: install
runs-on: ubuntu-latest
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@
# Remove Cargo.lock when creating an executable, leave it for libraries
# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock
Cargo.lock

node_modules

types/
artifacts/
5 changes: 5 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
dist
target
types
artifacts
8 changes: 8 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"semi": true,
"singleQuote": true,
"trailingComma": "all",
"printWidth": 100,
"tabWidth": 2,
"useTabs": false
}
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ license = "GPL-3.0-only"

[workspace]
members = [
"contracts/xc-regions",
"contracts/coretime-market",
"contracts/xc_regions",
"contracts/coretime_market",
"environment",
"primitives",
"extension",
Expand Down
90 changes: 57 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## 1. Introduction

[RegionX](https://regionx.tech/) is a project dedicated to developing components for the new [Agile Coretime](https://github.com/polkadot-fellows/RFCs/blob/main/text/0001-agile-coretime.md) model. The goal of the project is to enable developer teams, researchers, and speculators to start trading, tracking, and analyzing the product Polkadot offers - Coretime.
[RegionX](https://regionx.tech/) is a project dedicated to developing components for the new [Agile Coretime](https://github.com/polkadot-fellows/RFCs/blob/main/text/0001-agile-coretime.md) model. The goal of the project is to enable developer teams, researchers, and speculators to start trading, tracking, and analyzing the product Polkadot offers - Coretime.

This repository is establishing the smart contract components for creating a secondary Coretime market. This infrastructure is meant to be leveraged by any end-user product built around Coretime.

Expand All @@ -14,19 +14,19 @@ The repository currently contains two crucial components in the form of ink! con

From a procurement perspective, regions can be seen as NFT tokens representing ownership of Coretime. Each region is characterized by a defined set of attributes that encompass all its properties. The following is the list of these attributes:

- `begin`: Specifies the starting point of time from which a task assigned to the region can be scheduled on a core.
- `end`: Specifies the deadline until a task assigned to the region can be scheduled on a core.
- `length`: The duration of a region. Always equals to `end - begin`.
- `core`: The core index to which the region belongs.
- `mask`: The regularity parts in which this Region will be scheduled.
- `owner`: The owner of the region.
- `paid`: The payment for the region on the bulk market. Defined only for renewable regions. This is used to calculate the renewal price in the next bulk sale.
- `begin`: Specifies the starting point of time from which a task assigned to the region can be scheduled on a core.
- `end`: Specifies the deadline until a task assigned to the region can be scheduled on a core.
- `length`: The duration of a region. Always equals to `end - begin`.
- `core`: The core index to which the region belongs.
- `mask`: The regularity parts in which this Region will be scheduled.
- `owner`: The owner of the region.
- `paid`: The payment for the region on the bulk market. Defined only for renewable regions. This is used to calculate the renewal price in the next bulk sale.

The module containing all region-related logic is the [pallet-broker](https://github.com/paritytech/polkadot-sdk/tree/master/substrate/frame/broker). Deployed as part of the Coretime chain runtime, this pallet serves to handle all the Bulk Coretime procurement logic in Polkadot.

Given that the Coretime chain does not have any kind of smart-contract support it is not possible to create a secondary market on the Coretime chain itself.
Given that the Coretime chain does not have any kind of smart-contract support it is not possible to create a secondary market on the Coretime chain itself.
For this reason we have to store all the secondary market logic on a separate parachain which supports contract deployment.
Given that cross-chain NFT metadata transfer is still something that hasn't been resolved in the ecosystem we are implementing additional custom logic that will enable the transfer of regions acrross chains.
Given that cross-chain NFT metadata transfer is still something that hasn't been resolved in the ecosystem we are implementing additional custom logic that will enable the transfer of regions acrross chains.

An explanation of our solution for transferring the metadata of regions acrross chains can be found on the RegionX wiki: [Cross-Chain Regions](https://regionx.gitbook.io/wiki/advanced/cross-chain-regions).

Expand All @@ -35,17 +35,22 @@ An explanation of our solution for transferring the metadata of regions acrross
## 3. Develop

1. Make sure to have the latest [cargo contract](https://crates.io/crates/cargo-contract).
2. Clone the GitHub repository:
2. Clone the GitHub repository:

```sh
git clone https://github.com/RegionX-Labs/RegionX.git
```
3. Compile and run unit tests

3. Compile and run unit tests

```sh
cd RegionX/
cargo build
cargo test
```

3. Build the contracts:

```sh
# To build the xc-regions contract:
cd contracts/xc-regions/
Expand All @@ -57,29 +62,48 @@ cargo contract build --release
```

4. Running e2e-tests

Considering that the xc-regions contract necessitates the underlying chain to implement the uniques pallet for running e2e tests, it is required to specify a custom contracts node. For this purpose, we utilize the Astar local node from [Coretime-Mock](https://github.com/RegionX-Labs/Coretime-Mock) directory:
```sh
export CONTRACTS_NODE="~/Coretime-Mock/bin/astar-collator"
```
Once that is configured, we can proceed to run the e2e tests:"
```sh
cargo test --features e2e-tests
```

Considering that the xc-regions contract necessitates the underlying chain to implement the uniques pallet for running e2e tests, it is required to specify a custom contracts node. For this purpose, we utilize the Astar local node from [Coretime-Mock](https://github.com/RegionX-Labs/Coretime-Mock) directory:

```sh
export CONTRACTS_NODE="~/Coretime-Mock/bin/astar-collator"
```

Once that is configured, we can proceed to run the e2e tests:"

```sh
cargo test --features e2e-tests
```

Additionally, this repository contains e2e typescript tests, which can be run with the following steps:

```sh
# in a separate terminal run a the astar-collator node from Coretime-Mock
cd Coretime-Mock/
./bin/astar-collator --dev
```

After the node is running in a separate terminal:
```sh
# generate the artifacts
npm run compile

npm run test
```

## 4. Deploy

For the xc-regions contract to function correctly, the chain on which it is deployed must implement the uniques pallet. Given that the pallet index of the uniques pallet can vary across different chains, it's crucial to correctly configure this index before building and deploying the contract. To achieve this, the following steps should be taken:

1. Determine the index of the uniques pallet
2. Go to the `primitives/lib.rs` file:
3. Configure the index correctly:
```rust
#[derive(scale::Encode, scale::Decode)]
pub enum RuntimeCall {
// E.g: on shibuya this is 37. in local-runtime this is 30.
#[codec(index = <CORRECT PALLET INDEX>)]
Uniques(uniques::UniquesCall),
}
```
Once this is correctly configured, the contract can then be deployed.
1. Determine the index of the uniques pallet
2. Go to the `primitives/lib.rs` file:
3. Configure the index correctly:
```rust
#[derive(scale::Encode, scale::Decode)]
pub enum RuntimeCall {
// E.g: on shibuya this is 37. in local-runtime this is 30.
#[codec(index = <CORRECT PALLET INDEX>)]
Uniques(uniques::UniquesCall),
}
```
Once this is correctly configured, the contract can then be deployed.
6 changes: 6 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"projectFiles": ["contracts/**/*"],
"typechainGeneratedPath": "types",
"isWorkspace": true,
"workspacePath": "./"
}
40 changes: 0 additions & 40 deletions contracts/coretime-market/lib.rs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "coretime-market"
name = "coretime_market"
authors = ["RegionX <support@regionx.tech>"]
version = "0.1.0"
description = "Secondary Coretime marketpalce contract."
Expand All @@ -10,23 +10,36 @@ ink = { version = "4.2.1", default-features = false }

scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2.6", default-features = false, features = ["derive"], optional = true }
sp-arithmetic = { version = "23.0.0", default-features = false }

# OpenBrush dependency
openbrush = { git = "https://github.com/Brushfam/openbrush-contracts", branch = "develop", default-features = false, features=["psp34"] }

environment = { path = "../../environment", default-features = false, features = ["ink"] }
primitives = { path = "../../primitives", default-features = false }
block-number-extension = { path = "../../extension/block-number-extension", default-features = false, features = ["ink"]}
xc_regions = { path = "../xc_regions", default-features = false, features = ["ink-as-dependency"] }

[dev-dependencies]
ink_e2e = "4.2.1"

[lib]
path = "lib.rs"
path = "src/lib.rs"

[features]
default = ["std"]
std = [
"ink/std",
"primitives/std",
"scale/std",
"scale-info/std",
"sp-arithmetic/std",
"environment/ink-std",
"openbrush/std",
"xc_regions/std",
]
ink-as-dependency = []
e2e-tests = []

[profile.release]
overflow-checks = false
Loading

0 comments on commit 6772945

Please sign in to comment.