Skip to content

Commit

Permalink
DD-350: Updated other blockchain documentation pages and matching api…
Browse files Browse the repository at this point in the history
… page to take into account the GSY DEX matching engine.
  • Loading branch information
spyrostz committed Aug 29, 2024
1 parent d585e9a commit baa7836
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
12 changes: 6 additions & 6 deletions wiki/docs/blockchain-matching-engine.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ The GSY Matching Engine is a critical component of the Grid Singularity Decentra
Multi-attribute auctions, which account for participant preferences and applicable market conditions, require more advanced clearing algorithms than single attribute auctions, such as those based on price alone. The optimal approach is to engage [off-chain workers](blockchain-off-chain-storage.md) to operate matching algorithms and then require either the use of trusted execution environments (enclaves) or on-chain verification to determine whether the matching algorithm was correctly executed. To enable this solution, the matching process is decoupled from the settlement verification and moved to a dedicated component, the Matching Engine. The GSY DEX Matching Engine has been designed to operate as (one or multiple) individual autonomous service(s), responsible for identifying suitable matches for multiple open order books. In order to manage the available GSY Matching Engine services, the GSY Node needs to register each such service and associate it with a user account responsible for operating the respective service. Grid Singularity will facilitate the Matching Engine registration process for the [GSY DEX](blockchain.md).


The GSY DEX Matching Engine reads open bids and offers through the [GSY Matching API](#gsy-dex-matching-api) and submits matches for validation. Since the exchange’s verification function (part of GSY Node) only checks the validity of each match rather than the result of a specific matching algorithm, there is no longer a need for an agreed matching algorithm, arbitration technique, or redundant off-chain worker computation. This alleviates the need for additional on-chain computational cost, avoiding a corresponding increase to the gas costs associated with matching. Moreover, the GSY Node verification function is able to ascertain whether the bid and offer limitations are satisfied by the matches generated by the GSY Matching Engine (for instance, if the clearing energy rate is lower than or equal to the bid rate and higher than or equal to the offer rate). Therefore, multiple competing GSY Matching Engines can calculate matches for different markets in parallel, each using their own matching algorithm, and afterwards the GSY Node can select and verify the matches that are eligible for clearing, and reject those that are violating their bid and offer requirements. Finally, as the verification function is executed on-chain any potential errors or fraud attempts, such as double counting of trades and matching results, are eliminated. The validation of the actual delivery of the traded energy cannot be performed at this time, due to the fact that the energy is traded ahead-of-time. Another GSY DEX service, the [GSY Execution Engine](blockchain-system-components-overview.md#gsy-dex-execution-engine), is tasked with reading the asset measurements of produced or consumed energy, thereby validating whether the energy delivery corresponds to the traded energy.
The GSY DEX Matching Engine reads open bids and offers through the [GSY DEX Matching API](#gsy-dex-matching-api) and submits matches for validation based on the [following process](matching-api-walkthrough.md). Since the exchange’s verification function (part of GSY Node) only checks the validity of each match rather than the result of a specific matching algorithm, there is no longer a need for an agreed matching algorithm, arbitration technique, or redundant off-chain worker computation. This alleviates the need for additional on-chain computational cost, avoiding a corresponding increase to the gas costs associated with matching. Moreover, the GSY Node verification function is able to ascertain whether the bid and offer limitations are satisfied by the matches generated by the GSY Matching Engine (for instance, if the clearing energy rate is lower than or equal to the bid rate and higher than or equal to the offer rate). Therefore, multiple competing GSY Matching Engines can calculate matches for different markets in parallel, each using their own matching algorithm, and afterwards the GSY Node can select and verify the matches that are eligible for clearing, and reject those that are violating their bid and offer requirements. Finally, as the verification function is executed on-chain any potential errors or fraud attempts, such as double counting of trades and matching results, are eliminated. The validation of the actual delivery of the traded energy cannot be performed at this time, due to the fact that the energy is traded ahead-of-time. Another GSY DEX service, the [GSY Execution Engine](blockchain-system-components-overview.md#gsy-dex-execution-engine), is tasked with reading the asset measurements of produced or consumed energy, thereby validating whether the energy delivery corresponds to the traded energy.

The main functions of the GSY Matching Engine are the following:
The main functions of the GSY DEX Matching Engine are the following:


- Order Retrieval: The GSY Matching Engine retrieves orders from the [GSY DEX Off-Chain Storage](blockchain-off-chain-storage.md). This storage system holds all active bids and offers, which the GSY Matching Engine reads in order to match suitable counterparts for energy trades.
Expand All @@ -20,9 +20,9 @@ To summarise, the GSY Matching Engine is [designed](development-path.md) as an a
- Flexibility: As a standalone service, the GSY Matching Engine can be easily updated or modified without impacting other platform components. This allows for the continuous improvement of the order matching process and overall energy trading experience for platform users. Moreover, the GSY Matching Engine enables operation of multiple different matching algorithms in parallel, thus providing the flexibility to use different matching algorithms per market or energy community. This facilitates conformance to local regulation, by not restricting Community Managers to a single matching process, but allowing them to tailor the matching process to their needs.


## GSY Matching Engine Implementation
## GSY DEX Matching Engine Implementation

The GSY Matching Engine is implemented in [Rust](https://www.rust-lang.org/){target=_blank}, in order to take advantage of the ease of interconnection with other components of the GSY DEX, especially with the GSY Node, and the Rust performance benefits compared to other programming languages. The GSY Matching Engine’s operation revolves around a loop that continuously submits requests to the [GSY DEX Off-Chain Storage](blockchain-off-chain-storage.md) as to whether new open offers or bids have been created. If the Off-Chain Storage reports that new offers and bids have been created, the Matching Engine calls the applicable matching algorithm to calculate the matches and then transmits the calculated matches to the GSY Node. The main Rust modules that comprise the Matching Engine are the Algorithms Module and the Connectors Module.
The GSY DEX Matching Engine is implemented in [Rust](https://www.rust-lang.org/){target=_blank}, in order to take advantage of the ease of interconnection with other components of the GSY DEX, especially with the GSY Node, and the Rust performance benefits compared to other programming languages. The Matching Engine’s operation revolves around a loop that continuously submits requests to the [GSY DEX Off-Chain Storage](blockchain-off-chain-storage.md) as to whether new open offers or bids have been created. If the Off-Chain Storage reports that new offers and bids have been created, the Matching Engine calls the applicable matching algorithm to calculate the matches and then transmits the calculated matches to the GSY Node. The main Rust modules that comprise the Matching Engine are the Algorithms Module and the Connectors Module.


<figure markdown>
Expand All @@ -32,7 +32,7 @@ The GSY Matching Engine is implemented in [Rust](https://www.rust-lang.org/){tar
</figure>


The GSY Matching Engine [Algorithms Module](https://github.com/gridsingularity/gsy-decentralized-exchange/tree/main/gsy-matching-engine/src/algorithms){target=_blank} stores the available matching algorithms. Currently the [two-sided pay-as-bid](market-types.md#two-sided-pay-as-bid-market) algorithm is supported, with additional matching algorithms to be added in the future, either by Grid Singularity or a third party via the Matching API. Furthermore, the design of the Algorithms Module allows multiple algorithms to be deployed in parallel. For instance, different matching algorithms can be applied in different energy communities, or in different buildings within an energy community to optimise their asset configuration
The GSY DEX Matching Engine [Algorithms Module](https://github.com/gridsingularity/gsy-decentralized-exchange/tree/main/gsy-matching-engine/src/algorithms){target=_blank} stores the available matching algorithms. Currently the [two-sided pay-as-bid](market-types.md#two-sided-pay-as-bid-market) algorithm is supported, with additional matching algorithms to be added in the future, either by Grid Singularity or a third party via the GSY DEX Matching API. Furthermore, the design of the Algorithms Module allows multiple algorithms to be deployed in parallel. For instance, different matching algorithms can be applied in different energy communities, or in different buildings within an energy community to optimise their asset configuration

The currently applied two-sided pay-as-bid algorithm does not require the offer and bid to fully match each other’s respective energy consumption and production. The algorithm can also conclude a bid-offer match that partially trades the energy required by the bid and/or provided by the offer, with the expectation that the rest of the required or offered energy will be traded at a later time. Subsequently, the residual energy of the bid and/or the offer can be processed by the Matching Engine either in the same list of matches, or in one of the following lists of matches by creating a new offer and bid that will represent the residual energy.

Expand All @@ -43,7 +43,7 @@ The GSY DEX Matching Engine has been customised for the energy market by setting

## GSY DEX Matching API

The GSY DEX Matching API defines the protocol of communication between the Matching Engine and other components of the GSY DEX. The API has two components, one for the inputs required by the Matching Engine to calculate the possible bid-offer matches, and one for transmitting the calculated matches to the GSY Node, in order for energy trades to be generated and trade settlement to be performed.
The GSY DEX Matching API defines the protocol of communication between the Matching Engine and other components of the GSY DEX, following the espoused approach of the Grid Singularity Engine. The API has two components, one for the inputs required by the Matching Engine to calculate the possible bid-offer matches, and one for transmitting the calculated matches to the GSY Node, in order for energy trades to be generated and trade settlement to be performed.

The inputs required by the GSY DEX Matching Engine are the open bids and the offers that are available for a [market slot](markets.md#market-slots) (energy delivery time period). These are retrieved not via the GSY Node, but by leveraging the API of the GSY DEX Off-Chain Storage, thereby minimising the gas cost required for the operation of the Matching Engine, and consequently decreasing the computational effort required from the GSY Node.

Expand Down
13 changes: 7 additions & 6 deletions wiki/docs/blockchain-system-components-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,23 @@ The off-chain storage component of the [GSY DEX](blockchain.md) is designed to s
1. GSY DEX Grid Topology Storage: contains information about the physical grid structure, such as the location and configuration of nodes, as well as the interconnections between energy assets, which enable the GSY DEX to both verify the eligibility of the assets for trading, and to facilitate [performance analytics](results-dashboard.md) that involve the topology of the grid.
2. GSY DEX Measurements Storage: stores the energy consumption and generation data from energy assets. Accurate measurement data is essential for validating and executing energy trades, managing grid stability, and optimising energy consumption and generation patterns.
3. GSY DEX Trades Storage: stores all [energy trades](trades.md) of the GSY DEX, which are required in order to maintain and update the trade status to facilitate trade execution, as well as for analytics, auditing the trading behaviour of the user energy assets, and historical market analysis.
4. GSY DEX Order Book Storage: This storage component holds all the orders inserted in the respective market, including bids and offers issued by participants. The Order Book Storage facilitates the efficient operation of the [GSY DEX Matching Engine](#gsy-dex-matching-engine) by providing it with the necessary data to match supply to demand according to participants' preferences and market conditions.
4. GSY DEX Order Book Storage: This storage component holds all the orders inserted in the respective market, including bids and offers issued by participants. The Order Book Storage facilitates the efficient operation of the [GSY DEX Matching Engine](blockchain-matching-engine.md) by providing it with the necessary data to match supply to demand according to participants' preferences and market conditions.

For more, please see the section on the [GSY DEX Off-Chain Storage](blockchain-off-chain-storage.md).


### GSY DEX Matching Engine
The GSY DEX Matching Engine is responsible for identifying suitable matches for energy supply and demand based on the participants' preferences and market conditions. By efficiently matching bids and offers, the engine facilitates a seamless and optimised exchange clearance.
The [GSY DEX Matching Engine](blockchain-matching-engine.md) is responsible for identifying suitable matches for energy supply and demand based on participant preferences and market conditions. By efficiently matching bids and offers, the engine facilitates a seamless and optimised exchange clearance.

Multi-attribute auctions, which account for the participants’ preferences and varied market conditions, require more advanced clearing algorithms than single attribute auctions, such as those based on price alone. The optimal approach is to engage [off-chain workers](blockchain-off-chain-storage.md) to run matching algorithms and then require either the use of trusted execution environments (enclaves) or on-chain verification to determine whether the matching algorithm ran correctly. To enable this approach, the matching process is decoupled from the exchange, and moved to a dedicated component, namely the Matching Engine. The GSY DEX Matching Engine will operate as (one or multiple) individual autonomous service(s), responsible for identifying suitable matches for multiple open order books. Grid Singularity will serve as the Matching Engine Operator for the [GSY DEX](blockchain.md).
Multi-attribute auctions, which account for participant preferences and applicable market conditions, require more advanced clearing algorithms than single attribute auctions, such as those based on price alone. The optimal approach is to engage [off-chain workers](blockchain-off-chain-storage.md) to run matching algorithms and then require either the use of trusted execution environments (enclaves) or on-chain verification to determine whether the matching algorithm was correctly executed. To enable this solution, the matching process is decoupled from the settlement verification, and moved to a dedicated component, the Matching Engine. The GSY DEX Matching Engine has been designed to operate as (one or multiple) individual autonomous service(s), responsible for identifying suitable matches for multiple open order books. In order to manage the available GSY Matching Engine services, the GSY Node needs to register each such service and associate it with a user account responsible for operating the respective service. Grid Singularity will facilitate the Matching Engine registration process for the [GSY DEX](blockchain.md).

The GSY DEX Matching Engine reads open bids and offers through the [GSY Matching API](matching-api-walkthrough.md) and submits matches for validation. Since the exchange’s verification function only checks the validity of each match rather than the result of a specific matching algorithm, there is no longer a need for an agreed matching algorithm, arbitration technique, or redundant off-chain worker computation.

For more, please see the [GSY Matching API](matching-api-walkthrough.md) section. The GSY DEX Matching Engine system component is currently in development.
The GSY DEX Matching Engine reads open bids and offers through the [GSY Matching API](blockchain-matching-engine.md#gsy-dex-matching-api) and submits matches for validation. Since the exchange’s verification function (part of [GSY Node](blockchain-system-components-overview.md#gsy-node)) only checks the validity of each match rather than the result of a specific matching algorithm, there is no longer a need for an agreed matching algorithm, arbitration technique, or redundant off-chain worker computation.

For more, please see the section on the [GSY DEX Matching Engine](blockchain-matching-engine.md).

### GSY DEX Execution Engine
Once a trade has been matched by the [GSY Matching API](matching-api-walkthrough.md), the GSY DEX Execution Engine handles the execution or rejection of the trade by processing energy production and consumption measurements from the energy assets. This component ensures that trades are executed securely, transparently and in accordance with the agreed terms, while maintaining the integrity of the exchange platform.
Once a trade has been matched by the [GSY DEX Matching Engine](blockchain-matching-engine.md), the GSY DEX Execution Engine handles the execution or rejection of the trade by processing energy production and consumption measurements from the energy assets. This component ensures that trades are executed securely, transparently and in accordance with the agreed terms, while maintaining the integrity of the exchange platform.

Spot and futures trading requires predictions of energy used at both the asset and network level, often associated with high prediction errors. Thus, although a balancing mechanism addresses the energy imbalances on the physical level, financial exchanges might still not be executed, causing a mismatch between the physical energy delivery and the market accounting. Multiple solutions for mismatch mitigation can be provided by the [GSY DEX](blockchain.md), to be applied pursuant to respective local regulation:

Expand Down
Loading

0 comments on commit baa7836

Please sign in to comment.