# RegionX Docs

RegionX is a project aimed at making Web3 more accessible. We are achieving this by making deployment on Polkadot cheaper and easier, encouraging more development. We believe Polkadot is, and is headed in the direction of becoming, a highly scalable and decentralized system that can host many projects deployed.

"Deploying" on Polkadot means gaining access to its shared security. We highly recommend watching this video if you are not already familiar with Polkadot: [What is Shared Security? Shawn Tabrizi](https://www.youtube.com/watch?v=uKQOSPfM-W0)

Originally, on Polkadot, the community was involved in deciding which projects would be deployed on the network. This previous Slot Auction model was not nearly as flexible as Agile Coretime, but it had the valuable aspect of community involvement through crowdloans. We recommend reading more about this here: [Parachain Slot Auctions](< https://polkadot.network/features/auctions/>)

With RegionX, we are making access to Polkadot's resources very flexible (allowing projects to pay only for what they need) thanks to Agile Coretime, while also reintroducing the community element into the Coretime procurement process.

## Overview of the Documentation

The documentation of this wiki is structured into three categories.

* [Basics](/docs/basics/blockspace-and-coretime) - Covers all the fundamental concepts of Coretime, as well as highlights the distinctions between the primary bulk market and the secondary Coretime marketplace we are building. In the basic sections, we also cover all the ways projects can acquire Coretime for themselves.
* [Advanced](/docs/advanced/cross-chain-regions) - Goes into the technical details to understand how the RegionX Coretime market is structured and designed. This section will also provide the reader with an adequate understanding of how the Coretime pricing model works.
* [Build](/docs/build/market-pallet) - Offers documentation for teams looking to integrate with the RegionX Coretime marketplace.


# Blockspace & Coretime

Blockspace is a key concept in blockchain technology. It is the primary product that blockchains produce and can be used for multiple different purposes, depending on the blockchain that offers it. It describes the computing capacity and storage required to create a block. This resource can be used for things like transaction validation, smart contract execution, and data storage.&#x20;

For a comprehensive understanding of blockspace and its characteristics, we strongly recommend exploring the following resources. These articles offer in-depth insights into the concept of blockspace, particularly in the context of the Polkadot network and its role in advancing the Web3 ecosystem:

* [Understanding Blockspace: Unveiling Polkadot's Potential in Web3](https://polkadot.network/blog/blockspace-blockspace-ecosystems-how-polkadot-is-unlocking-the-full-potential-of-web3)
* [How Polkadot's Blockspace Empowers Developers](https://polkadot.network/blog/how-polkadots-blockspace-empowers-developers)

Coretime is one of the main resources Polkadot offers. Owning Coretime gives you access to utilize one of Polkadot's cores for your specific task. The new Agile Coretime model makes Coretime more accessible by allowing for a more granular allocation.

For a clear understanding of the Agile Coretime model, we recommend checking out the following resources:

* [Agile Coretime Allocation](https://wiki.polkadot.network/docs/polkadot-direction#agile-coretime-allocation)
* [Gavin Wood Sees Polkadot as a Global Supercomputer | Polkadot Decoded 2023](https://www.youtube.com/watch?v=GIB1WeVuJD0)


# Primary Coretime Market 🥇

The Agile Coretime RFC ([RFC-1: Agile Coretime](https://github.com/polkadot-fellows/RFCs/blob/main/text/0001-agile-coretime.md)) introduces two new allocation methods for Coretime on the Polkadot Ubiquitous Computer:

1. **Bulk Coretime**: Allocated in advance, this method involves periodic scheduling of Coretime through a specialized Coretime-chain. It is designed for users who plan their Coretime needs ahead of time.
2. **Instantaneous Coretime**: In contrast, this method allows for allocation of Coretime on the Relay-chain on an as-needed basis, right before usage and follows a block-by-block approach. It suits users requiring Coretime on short notice or for immediate tasks.

These two methods will allow projects to choose the approach they think is best suited for their project.

The Agile Coretime model uses 'Regions' to represent Bulk Coretime. These Regions, serving as assets, signify ownership of Coretime over a specified duration.&#x20;

They can be:

* **Partitioned**: Splitting a region into two new regions, each spanning over a shorter, non-overlapping period of time.
* **Interlaced**: Divided into two new regions, each utilizing a smaller portion of a core's resources. This way, a core can be shared by two projects simultaneously.

This allows regions purchased from the Bulk market to be divided, so that the project only keeps the portion they need, while the remaining part can be sold to someone else. This is where a secondary marketplace will come into play.


# Drawbacks of the Primary Market

The Coretime chain, introduced to provide greater flexibility in Coretime procurement compared to the slot auction lease model, still has certain limitations. However, the new Agile Coretime model introduces all the necessary functionalities to overcome these limitations, thereby allowing us to make Coretime procurement as flexible as possible.

When designing a secondary Coretime market, we concentrated on addressing three primary drawbacks of the Coretime chain:

1. **Limitation in Region Duration**: The market only allows users to purchase full regions, lacking the option to acquire regions spanning less than a four-week period. This restricts the flexibility for users who require shorter duration allocations.
2. **Limitation in Core Occupancy**: Each region acquired from the Coretime chain comes with a full core mask, meaning it gives 'ownership' over an entire Polkadot core. This allocation is often excessive for the needs of most parachains, wasting potential usage of these cores.
3. **Limitation on Immediate Region Procurement**: Users can only purchase regions for the upcoming Bulk period, which implies that teams must wait until the start of the next period, potentially up to four weeks, before they can purchase and assign a region to their specific parachain.


# Secondary Market 🥈

The secondary Coretime market is designed to address the constraints inherent in the Bulk market. Its objective is to facilitate more accessible Coretime procurement for all users by providing a platform where smaller chunks of Coretime can be purchased. This is made possible by the functionality offered by the new Agile Coretime model.

The RegionX market is envisioned as a platform where users can trade regions they have acquired from the Bulk sale. Unlike the primary market, regions available on the RegionX market can possess unique properties, each potentially suited to different project requirements.

The following sections outline the properties of the RegionX secondary market. A clear understanding of these aspects is essential for effective engagement and interaction within this market.


# Secondary Market Overview 🌐

The RegionX parachain provides two main ways of interacting with its Coretime marketplace. These two methods serve distinct purposes.

### `Direct Access`

The RegionX parachain has its own marketplace module which contains the core logic of the RegionX Coretime marketplace. It is described in greater detail in our [white paper](https://github.com/RegionX-Labs/Docs/blob/main/RegionX-Core.pdf). Essentially, it provides the functionality for listing regions purchased from the bulk market on sale. We categorize these regions into two categories based on their current 'lifecycle'. The two region types are as follows:

* Active regions. Active regions can be used in the current moment. This means that if we assign a task to an active region, it will start execution in the upcoming timeslice (assuming that the region doesn't begin later in the future)
* Inactive regions. These are the regions that will become active in the upcoming Bulk period. The regions purchased from the Coretime chain fall into this category until the start of the next Bulk period. Tasks assigned to these regions will only start with execution in the upcoming bulk period.

The pricing of inactive regions remains fixed at the amount initially determined by the seller. In contrast, the cost of active regions follows our dynamic pricing model, which accounts for gradual depreciation in value. The pricing of these regions reflects their decreasing value over time when not used.

Details on the pricing can be found in the [Dynamic Coretime pricing](/docs/advanced/dynamic-coretime-pricing) section of the wiki.

### `Orders`

Given that most parachains aim to be decentralized systems, it's crucial for them to procure Coretime in a decentralized manner as well. If a parachain depends on a specific group of people to sustain its operations, it fails to achieve true decentralization. Users on these chains should vigilantly monitor whether the chain continues to receive coretime renewals.

Since parachains are transparent systems, they are predictable. This means they cannot effectively interact with an open marketplace without risking others front-running them.

This is the primary reason why we developed the orders model. It enables parachains to acquire Coretime for the marketplace in a decentralized, community-driven manner.

This works by someone posting a Coretime order on behalf of the parachain (e.g., the team behind the chain). Such orders can also be posted by the chain itself. With Agile Coretime, each parachain can decide if it needs an entire core allocated to it or if sharing a core with other projects is sufficient, thereby reducing costs. A Coretime order describes these requirements. Tools such as <https://www.polkadot-weigher.com/> can assist in determining how much capacity the chain needs.

These orders need to be posted each sale cycle to ensure the chain doesn’t stop block production.&#x20;

The order itself doesn't hold any value. However, individuals can help an order by contributing their own DOT tokens to it. This process is similar to the legacy crowdloan model, but in this case, the DOT tokens are spent rather than being locked.

Similar to how parachains used to reward crowdloan participants, they can also specify rewards for the order contributors. This provides incentives for people to spend their DOT tokens on an order.

Of course, the parachain itself can always contribute to its own order.

> NOTE: Some parachains might not want to have the logic for posting orders in their runtime. This is why we also made it possible for anyone to create an order. For example, the team behind the project can create the order, and anyone can contribute to it. Once the order is fulfilled, the RegionX chain will automatically assign it to the parachain, ensuring that the region will be used for its intended purpose.


# Community Involvement 🌱

DOT holders can contribute to projects they find valuable and, depending on the parachain, receive rewards for doing so.

This is similar to contributing to crowdloans in the previous slot auction model. However, it is important to note that instead of locking the tokens, the tokens are now spent. Because of this, parachains will likely define rewards to incentivize DOT token holders to help them procure Coretime.

Via the RegionX UI, users will be able to make these contributions and browse the parachains looking to procure Coretime.

<figure><img src="https://1032083937-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYMYAQjIBVBJMcDRlWHYS%2Fuploads%2FQlSG78g4Jl8wbWX9jD84%2FScreenshot%20from%202024-07-26%2012-44-03.png?alt=media&amp;token=b7d282e0-a564-47a9-9b0a-4a42d7ea508d" alt=""><figcaption></figcaption></figure>


# Coretime Order Processing ⚙️

As explained in the '[Secondary Marketplace Overview](/docs/basics/secondary-market-overview)' section, RegionX offers the possibility to procure Coretime through what we call 'Coretime Orders.' These orders indicate that someone is looking for a region with specific requirements. The amount offered by this order is determined by the number of tokens contributed to the order.

Coretime traders(likely bots, rather than actual humans) will keep track of the primary bulk market and secondary marketplaces to see if they can make a profit by contributing some of the regions offered to the order.

If yes, they will be able to buy that Coretime region and sell it to the order to receive all the contributions made to the order.

The region used to fulfill an order will be automatically assigned to the specific parachain via an XCM message.

<figure><img src="https://1032083937-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYMYAQjIBVBJMcDRlWHYS%2Fuploads%2FEFyA6gexGl8Rdg41jgu2%2FScreenshot%20from%202024-07-27%2009-27-54.png?alt=media&amp;token=5f652c16-2fc1-4104-9e0e-039c4ab17600" alt=""><figcaption></figcaption></figure>

To learn more about our decisions when developing the order processor module, read the following document:

{% embed url="<https://docs.google.com/document/d/1OgbY5NIApnIBqrY4_JcR3541Jfi8jHJs4Zmqg1syhBo/edit?usp=sharing>" %}


# Cross-Chain Regions

The Coretime parachain, by itself, doesn't support deploying smart contracts. As a result, this limits the creation of a secondary Coretime market on top of it. Due to this limitation, the market logic must be implemented externally. In our specific scenario, the marketplace logic will be located on the RegionX parachain.

Considering that the assets sold in the Coretime market are regions acquired from the Bulk sale, it's essential to establish a mechanism for transferring these regions to the RegionX parachain where the market functionality is deployed.

Since regions can be represented as NFT assets, cross-chain transfers are feasible, particularly because the XCM format is designed to support such transactions. We can transfer regions using [XCM reserve-based asset transfers](https://wiki.polkadot.network/docs/learn-xcm-usecases#reserve-asset-transfer).

However, this approach only allows for the transfer of ownership information for the region, not the properties of the region itself. It's important to have these properties available on the parachain where the market operates, as the value of each region is intrinsically linked to its specific properties.

Each region possesses a set of properties that highly influence its value on the market. These properties are:

* `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.

To successfully list regions on the market, it is necessary to transfer not only the ownership but also the complete set of property values to the parachain where the market operates. This ensures that all relevant information about each region is accurately reflected and accessible in the marketplace.

We have developed a solution to address the challenge of transferring metadata, which is compatible with the existing XCM V3 message format. This solution is designed to function without the need for the 'Transact' instruction, a feature that is currently disabled on all production-ready parachains.

For the purpose of reading region metadata, we use [**ISMP**](https://docs.hyperbridge.network/protocol/ismp/), which allows us to trustlessly read the data from the Coretime chain. This is possible due to the architecture of Polkadot, as the state root of all parachains is stored on the relay chain. Thus, a relayer can provide the actual data, and we can verify it given that we have access to the Coretime chain's state root.

However, we don't actually need to have a relayer infrastructure. We implemented the relayer functionality in the frontend so that the frontend can self-relay for the users in the background.

We recommend reading more about ISMP here: <https://docs.hyperbridge.network/protocol/ismp>


# Dynamic Coretime pricing

The regions sold in the market are classified into two categories:

* Active regions. Active regions can be used in the current moment. This means that if we assign a task to an active region, it will start execution in the upcoming timeslice (assuming that the region doesn't begin later in the future)
* Inactive regions. These are the regions that will become active in the upcoming Bulk period. The regions purchased from the Coretime chain fall into this category until the start of the next Bulk period.

**Region pricing**

The formula used to calculate the price of a region listed for sale is as follows:

$$
r\_{price}=(r\_{end}- t)\*tp
$$

Where:

* $r\_{end}$: is the timeslice at which the region concludes
* $t$: represents the current timeslice
* $tp$: is the cost per timeslice defined by the seller upon listing the region on the market. Based on the region's core occupancy (which defines what portion of the core the region occupies), the timeslice price will likely differ.

> The parachain doesn't store the entire region's price; instead, it records the price of its timeslice, which is determined at the time of listing the region.

Through this, we are achieving dynamic pricing for 'active' regions which reflects their gradual loss of value when not being used.


# Market pallet

This section of the wiki will list all of the extrinsics provided by the market pallet.

### [`list_region`](https://github.com/RegionX-Labs/RegionX-Node/blob/1887388bc496d0ff4dafd51ece4329a9647a609f/pallets/market/src/lib.rs#L158)

Extrinsic for listing a region on sale.

Arguments:

* `region_id`: The region that the caller intends to list for sale.
* `timeslice_price`: The price per a single timeslice.
* `sale_recipient`: The \`AccountId\` receiving the payment from the sale. If not specified this will be the caller.

```rust
pub fn list_region(
	origin: OriginFor<T>,
	region_id: RegionId,
	timeslice_price: BalanceOf<T>,
	sale_recipient: Option<T::AccountId>,
) -> DispatchResult { }
```

### [`unlist_region`](https://github.com/RegionX-Labs/RegionX-Node/blob/1887388bc496d0ff4dafd51ece4329a9647a609f/pallets/market/src/lib.rs#L202)

Extrinsic for unlisting a region from sale.

Arguments:

* `region_id`: The region that the caller intends to unlist from sale.

```rust
pub fn unlist_region(origin: OriginFor<T>, region_id: RegionId) -> DispatchResult { }
```

### [`update_region_price`](https://github.com/RegionX-Labs/RegionX-Node/blob/1887388bc496d0ff4dafd51ece4329a9647a609f/pallets/market/src/lib.rs#L228)

Extrinsic for updating the price of a region listed on sale.

Arguments:

* `region_id`: The region for which we want to update the timeslice price.
* `new_timeslice_price`: The new timeslice price.

<pre class="language-rust"><code class="lang-rust">pub fn update_region_price(
	origin: OriginFor&#x3C;T>,
	region_id: RegionId,
	new_timeslice_price: BalanceOf&#x3C;T>,
<strong>) -> DispatchResult { }
</strong></code></pre>

### [`purchase_region`](https://github.com/RegionX-Labs/RegionX-Node/blob/1887388bc496d0ff4dafd51ece4329a9647a609f/pallets/market/src/lib.rs#L260C10-L260C25)

Extrinsic for purchasing a region listed on sale.

Arguments:

* `region_id`: The region that is listed on sale.
* `max_price`: The maximum price the buyer is willing to pay for the region. If the actual price exceeds this amount, the purchase will not be executed. The region price is linearly decreasing for currently active(i.e. usable) regions.

```rust
pub fn purchase_region(
	origin: OriginFor<T>,
	region_id: RegionId,
	max_price: BalanceOf<T>,
) -> DispatchResult { }
```


# Order pallet

The order pallet is mainly meant for parachains looking to interact with the market. Therefore, teams looking to deploy their parachain on Polkadot should look into procuring Coretime by accessing the Market pallet.

Nevertheless, if they cannot find Coretime on the market that meets their requirements, they can create an order. This way, they will signal to Coretime traders that there is demand for a region that meets the specified requirements.

### `create_order`

Extrinsic for creating an order.

Arguments:

* `para_id`: The para id to which Coretime will be allocated.
* `requirements`: Region requirements of the order.

```rust
pub fn create_order(
	origin: OriginFor<T>,
	para_id: ParaId,
	requirements: Requirements,
) -> DispatchResult {
```

### `cancel_order`

Extrinsic for cancelling an order.

If the region requirements on which the order was based are for an expired region, anyone can cancel the order.

Only expired orders can be cancelled.

Arguments:

* `order_id`: The order the caller wants to cancel.

```rust
pub fn cancel_order(origin: OriginFor<T>, order_id: OrderId) -> DispatchResult { }
```

### `contribute`

Extrinsic for contributing to an order.

Arguments:

* `order_id`: The order to which the caller wants to contribute.
* `amount`: The amount of tokens the user wants to contribute. This amount will be reserved and will only be spent if the order gets fulfilled.

```rust
pub fn contribute(
	origin: OriginFor<T>,
	order_id: OrderId,
	amount: BalanceOf<T>,
) -> DispatchResult { }
```

### `remove_contribution`

Extrinsic for removing contributions from a cancelled order.

Arguments:

* `order_id`: The cancelled order from which the user wants to claim back their contribution.

```rust
pub fn remove_contribution(origin: OriginFor<T>, order_id: OrderId) -> DispatchResult { }
```


# Order Processor pallet

Before attempting to use the order processor pallet directly we recommend reading the [Coretime Order Processing ⚙️](/docs/basics/coretime-order-processing) page.

We are looking forward to see the development of programs which will fulfill a coretime order when seeing a profitable opportunity.

### Risks & Rewards

The orders pallet is designed to minimize risk for anyone looking to fulfill an order. To reduce these risks, we have implemented the following limitations for order creators and contributors:

* **Only expired orders can be canceled.** Orders looking for a region that is currently or will be active in the future cannot be canceled. This ensures that when someone purchases a region to fulfill an order, they are not at risk of the order creator canceling it. This way, they can be confident that the order can be fulfilled, unless another user fulfills it before them.\
  \
  Expired orders are those that were not fulfilled, and the region they are looking for has already expired. These regions hold no real value, and anyone can cancel the order so that contributors can claim their contributions. Fulfilling such order is restricted.<br>
* **Contributions can only be removed for expired orders.** This restriction is implemented so that the user fulfilling the order can know in advance the amount they will receive before purchasing the region they will sell.

The reward of selling a region to an order is receiving all the tokens that were collected by the order.

Rewards for contributing to an order can vary depending on the parachain. It is up to the parachains/order creators to define how they will incentivize contributions. With further development on RegionX, we will facilitate the process of rewarding contributors for parachains.

### `fulfill_order`

Extrinsic for fulfilling an order.

**Arguments:**

* `origin`: Signed origin; the region owner.
* `order_id`: The order which the caller intends to fulfill.
* `region_id`: The region that the caller intends to sell to the Coretime order. The region must match the order requirements otherwise the extrinsic will fail

```rust
pub fn fulfill_order(
    origin: OriginFor<T>,
    order_id: OrderId,
    region_id: RegionId,
) -> DispatchResult { }
```

The order must not be expired; otherwise, the call will fail. If the region meets all the requirements and is not locked, the caller will receive the tokens accumulated by the order.&#x20;

The function will send an XCM message to assign the region to the parachain specified by the order. The assignment will be F`inal`.

If the XCM message fails to be sent, the region assignment will be stored in the `RegionAssignments` storage map. Using the `assign` extrinsic, anyone can attempt to make the assignment call, ideally after the issue is resolved.

### `assign`

Assign a region to the specific `para_id`.

**Arguments:**

* `origin`: Signed origin; can be anyone.
* `region_id`: The region that the caller intends assign. Must be found in the`RegionAssignments` mapping.

```rust
pub fn assign(origin: OriginFor<T>, region_id: RegionId) -> DispatchResult { }
```

Extrinsic used to reattempt assigning a region after the initial attempt failed during fulfillment.


# Integration with xcRegions

## ⚠️ Deprecated ⚠️

> Before attempting to integrate xcRegions into another smart contract or frontend code it is important to have a good understanding of our approach for solving NFT metadata transfers that is described here: [Solving NFT cross-chain transfers](https://hackmd.io/@Szegoo/rkryxwdIp). &#x20;

The xcRegions contract is designed to function as a facilitator, offering a convenient means for various applications to engage with Coretime regions from the Bulk market. It adheres to the PSP34 interface, enabling it to be utilized as a standard NFT token. However, the contract goes beyond the PSP34 interface by implementing the `MetadataWrapper` interface, as detailed in the [Solving NFT Cross-Chain Transfers](https://hackmd.io/@Szegoo/rkryxwdIp) article.

## Accessing region metadata

The xcRegions contract exposes the `get_metadata` ink! message, which can be used to retrieve all associated metadata of the region.

```rust
fn get_metadata(&self, region_id: RawRegionId) -> Result<VersionedRegion, XcRegionsError>;
```

However, it is important to note that not all metadata returned by this function is guaranteed to be accurate. The region's metadata is divided into two parts:&#x20;

**`RegionId`**

The `RegionId` is a unique identifier for regions. In itself, it contains parts of the metadata:

```rust
pub struct RegionId {
	/// The timeslice at which the region starts.
	pub begin: Timeslice,
	/// The index of the relay chain Core on which this Region will be scheduled.
	pub core: CoreIndex,
	/// The regularity parts in which this Region will be scheduled.
	pub mask: CoreMask,
}
```

Given that this type is used to identify regions for executing reserve transfers (in the form of `u128`), when a user sets the metadata of a region, the xcRegions contract can verify whether its properties align with those that are part of the `RegionId`. This way we can be assured this part of the metadata is correct.

**`RegionRecord`**

```rust
pub struct RegionRecord {
	/// The end of the Region.
	pub end: Timeslice,
	/// The owner of the Region.
	pub owner: AccountId,
	/// The amount paid to Polkadot for this Region, or `None` if renewal is not allowed.
	pub paid: Option<Balance>,
}
```

This part of the metadata is not stored within the region identifier. For this reason, the xcRegions contract cannot verify its correctness and it is the responsibility of the client to ensure its validity as described in the [Solving NFT Cross-Chain Transfers](https://hackmd.io/@Szegoo/rkryxwdIp) article.


# Integration with the Coretime market

## ⚠️ Deprecated ⚠️

> Before attempting to integrate xcRegions into another smart contract or frontend code it is important to have a good understanding of our approach for solving NFT metadata transfers that is described here: [Solving NFT cross-chain transfers](https://hackmd.io/@Szegoo/rkryxwdIp). &#x20;

The RegionX Coretime market utilizes an order-book model and integrates directly with the XcRegions contract. For a region to be listed on the market, it must be represented within the XcRegion contract.&#x20;

The regions sold in the market are classified into two categories:

* Active regions. The tasks that are assigned to active regions can currently be performed on a Polkadot core.&#x20;
* Inactive regions. These are the regions that will become active in the upcoming Bulk period. The regions purchased from the Coretime chain fall into this category until the start of the next Bulk period.

The active regions experience a depreciation in price over time, as described in the [RegionX white paper](https://github.com/RegionX-Labs/Docs).

## Region Pricing

The formula used to calculate the price of a region listed for sale is as follows:

$$
r\_{price}=(r\_{end}- t)\*(tp \* c\_{occupancy})
$$

Where:

* $$r\_{end}$$ is the timeslice at which the region concludes
* $$t$$ represents the current timeslice
* $$tp$$ is the cost per timeslice defined by the seller upon listing the region on the market.
* $$c\_{occupancy}$$ represents the proportion of the Core that is occupied by the region.

> The contract doesn't store the entire region's price; instead, it records the price of its timeslice, which is determined at the time of listing the region.

The price of a region listed for sale can be determined by invoking the `region_price` ink! message, which is made available by the market contract:

```rust
pub fn region_price(&self, id: Id) -> Result<Balance, MarketError>;
```

## Listing Regions on the Market

```rust
pub fn list_region(
    &mut self,
    id: Id,
    timeslice_price: Balance,
    sale_recepient: Option<AccountId>,
) -> Result<(), MarketError>;
```

The market contract provides a `list_region` ink! message, accessible to anyone wishing to list their region for sale. However, before initiating this call, the region's owner must grant approval to the market contract, as the region will be transferred to it upon listing.

Approvals are made by invoking the `approve` ink! message exposed by the XcRegions contract.

Based on the configuration set during contract deployment, listing a region may require a deposit from the caller. This deposit can be reclaimed when the region is delisted from sale. This mechanism is necessary to provide users with an incentive to remove their expired regions from the sale list, preventing storage bloat.

## Updating price

```rust
pub fn unlist_region(&mut self, id: Id) -> Result<(), MarketError>;
```

Once a region is listed for sale, the owner has the permission to update the region's timeslice price.

## Unlisting Regions from the Market

```rust
pub fn unlist_region(&mut self, id: Id) -> Result<(), MarketError>;
```

If the owner decides not to sell a region they've listed, they can choose to unlist it.&#x20;

Should the region expire before being sold, anyone can unlist the region and claim the listing deposit.

## Purchasing Regions from the Market

```rust
pub fn purchase_region(
    &mut self,
    id: Id,
    metadata_version: Version,
) -> Result<(), MarketError>;
```

Anyone willing to pay the asking price can purchase the regions listed for sale.

However, it's crucial for the client to verify the validity of the listed region's metadata. Upon verification, the buyer must specify the current `metadata_version` of the listed region. This allows the market to ensure that the purchase proceeds only if the metadata remains unchanged.


# Renewal Questions

### Why can't I renew my core?

There are multiple reasons why a core cannot be renewed. Instead of trying to outline all the reasons, we will list all the requirements for a core to be renewable.

For a core to be renewable in the upcoming cycles it must **not** be interlaced or partitioned. Additionally, the core must be assigned to a task with Final finality. Cores assigned to the Instantaneous Coretime pool cannot be renewed. Renewal is only available when the core is assigned to a task(parachain).

### When to renew?

There are three phases in the bulk sale:

* interlude phase
* leadin phase
* fixed price phase

Renewals can be made in any phase; however, it is recommended that they are made during the interlude phase. Otherwise, there is a risk that the core could be sold on the market, preventing the renewal.

Renewals must be made in advance. If a core is purchased in bulk sale #1, this means the user has obtained a core for the upcoming bulk period (during which bulk sale #2 takes place). The renewal must be made in bulk sale #2, ideally during the interlude phase.&#x20;

### Is it always worth renewing?

It is not always worth renewing a core. The renewal price is determined based on the price at which the user initially purchased the core from the market. If the price of cores drops in the next sale, it may be more advantageous to purchase a new core at the lower price and abandon the previous core. This will also reduce the renewal cost for that core in the future.


