# Specification for Predicate Indexer for Limit Order Predicate #### Overview This specification outlines the requirements for a predicate indexer for a limit order predicate. The indexer will track and index events related to order creation, cancellation, and fulfillment based on the predicate's logic, tests, and scripts. #### Predicate Reference - **Predicate**: Limit Order Predicate - **Source Code**: [Limit Order Predicate on GitHub](https://github.com/compolabs/spark-rs/blob/beta-5/limit-order-predicate/src/main.sw) #### Test Suite - **Location**: [Local Tests on GitHub](https://github.com/compolabs/spark-rs/tree/beta-5/tests/local_tests) - **Key Tests**: - `create_order` - `cancel_order` - `fulfill_order` #### Testnet Scripts - **Location**: [Testnet Scripts on GitHub](https://github.com/compolabs/spark-rs/tree/beta-5/scripts) - **Scripts**: - `cancel_order` - `fulfill_order` #### Event Indexing The indexer will be responsible for monitoring and storing the following events: 1. **Create Order Event**: Triggered when an order is created. 2. **Cancel Order Event**: Triggered when an order is canceled. 3. **Fulfill Order Event**: Triggered when an order is fulfilled. #### Implementation Details 1. **Data Collection**: The indexer will listen for events emitted by the limit order predicate on the Fuel Beta 5 testnet. 2. **Data Storage**: Relevant data from each event will be stored in a structured format, ensuring quick retrieval and query capabilities. This may include order details, transaction identifiers, timestamps, and participant addresses. 3. **Script Execution Tracking**: For the `cancel_order` and `fulfill_order` scripts, the indexer will capture the outcomes and the sequence of actions within each script execution. 4. **Event Parsing**: Each event type will be parsed to extract and store relevant information, such as order ID, trader address, order size, price, and status changes. 5. **Integration with Test Suites**: The indexer will be integrated with the local test suite to validate the correctness of indexed data against known outcomes. #### Requirements - **Real-Time Indexing**: The system should index events in real-time or near-real-time for prompt data availability. - **Scalability**: The indexer should be scalable to handle an increasing number of transactions and events without significant performance degradation. - **Reliability**: The system should ensure data integrity and consistency, even in cases of network or system failures. - **Query Interface**: Provide an API or query interface for retrieving indexed data, supporting queries based on order ID, trader address, and order status. #### Testing and Validation - **Local Test Integration**: Validate the indexer against local tests for create, cancel, and fulfill orders. - **Testnet Script Results Analysis**: Analyze the results of the `cancel_order` and `fulfill_order` scripts executed on the testnet to ensure accurate indexing and representation of events. #### Output Documentation - **Indexing Results**: Document the outcomes and indexed data for both local tests and testnet script executions. - **Discrepancies and Anomalies**: Any deviations from expected results should be documented and analyzed for root cause determination. #### Future Considerations - **Upgrades and Maintenance**: Plan for regular updates and maintenance to accommodate changes in the limit order predicate and the Fuel ecosystem. - **Expansion of Indexed Events**: Consider future expansion to include additional event types as the limit order predicate evolves. ### Cancel Order script output ``` maker address = 0x194c4d5d321ea3bc2e87109f4a86520ad60f924998f67007d487d3cc0acc45d2 amount0 = 40000 USDC (0450e4d385cbd2914f74505f18f01587cc4f4ad1fdef4b80cbde2a8155a86d72) amount1 = 1 BTC (593b117a05f5ea64b39ba1f9bc3fb7e7a791c9be130e28376ad552eacdb3b746) price = 0 USDC/BTC predicate root = Bech32Address { hrp: "fuel", hash: 02d8f51b84a8ad850a7d844af62331c16c6cc1068c9303b45879b77ca5a1b2fd } create order tx: 1192b64a4742d7729652bdb7906f2e454d2c5ae114937e9f1b3c83476fc7039b cancel order tx: dda0c8a501aeca4acf1c3f61895fbbac0ef5b192f3802cc4cd26c102b4406416 ``` ### Fulfill Order script output ``` maker address = 0x194c4d5d321ea3bc2e87109f4a86520ad60f924998f67007d487d3cc0acc45d2 taker address = 0x47010c8ecfeaa888954d7a536131fa962060e28552f3353c06954afdc558410e amount0 = 40000 USDC (0450e4d385cbd2914f74505f18f01587cc4f4ad1fdef4b80cbde2a8155a86d72) amount1 = 1 BTC (593b117a05f5ea64b39ba1f9bc3fb7e7a791c9be130e28376ad552eacdb3b746) price = 0 USDC/BTC predicate root = Bech32Address { hrp: "fuel", hash: 02d8f51b84a8ad850a7d844af62331c16c6cc1068c9303b45879b77ca5a1b2fd } create order tx: dc4ec0b49d8e34ef8a56c2bc8af48578445633b233d36de829319f262b1251a4 fulfill order tx: 0b8b0ca86951c1923d5377410a064eda025651e011d9869d04c040fdc3daba4d ```