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

Coretime market implementation #17

Merged
merged 37 commits into from
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
7c7863b
init coretime-market
Szegoo Jan 15, 2024
d39bfb4
Merge remote-tracking branch 'origin' into coretime-market
Szegoo Jan 15, 2024
2cccfad
add storage
Szegoo Jan 15, 2024
e9ec056
cross-contract calling
Szegoo Jan 16, 2024
4c6a7ea
list_region
Szegoo Jan 17, 2024
6bcb9a4
init e2e tests
Szegoo Jan 17, 2024
e1d65e7
add enumeration
Szegoo Jan 17, 2024
4303e85
XcRegions: fix remove
Szegoo Jan 17, 2024
553bfc1
deposit docs
Szegoo Jan 17, 2024
441efa2
current_timeslice
Szegoo Jan 17, 2024
2ca666d
list_region untested
Szegoo Jan 18, 2024
5a81152
purchase_region implemented
Szegoo Jan 20, 2024
a05c3de
fix
Szegoo Jan 20, 2024
82fb8f7
calculate_region_price wip
Szegoo Jan 21, 2024
84fa1d9
fix calculate_region_price
Szegoo Jan 21, 2024
03942ac
current_timeslice | wip
Szegoo Jan 21, 2024
435c6f2
use sp-arithmetic
Szegoo Jan 24, 2024
1a9eb96
fix attempt
Szegoo Jan 24, 2024
950f39e
introduce reference points
Szegoo Jan 26, 2024
934154b
init e2e js tests
Szegoo Jan 26, 2024
de9a339
constructors work
Szegoo Jan 26, 2024
d3a0834
Merge branch 'main' of https://github.com/RegionX-Labs/RegionX into c…
Szegoo Jan 26, 2024
fdfcd0a
Merge branch 'main' into coretime-market
Szegoo Jan 26, 2024
b44ddde
extrinsic calls work
Szegoo Jan 26, 2024
ed1bbcd
listing works
Szegoo Jan 27, 2024
3364256
listing fully tested
Szegoo Jan 27, 2024
f317a30
init purchase tests
Szegoo Jan 27, 2024
d888fc1
use block-number provider
Szegoo Jan 28, 2024
286d1d4
tests passing
Szegoo Jan 28, 2024
8dece31
more tests
Szegoo Jan 28, 2024
578297b
check events
Szegoo Jan 28, 2024
5f2c2a1
timeslice based pricing
Szegoo Feb 1, 2024
fc739c2
e2e tests passing
Szegoo Feb 1, 2024
6d7352e
fixes
Szegoo Feb 3, 2024
a59c672
remove artifacts & types
Szegoo Feb 3, 2024
0dbc312
remove unused
Szegoo Feb 3, 2024
b208cb0
clippy
Szegoo Feb 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading