Oracle Prediction API is a backend service that fetches NFL team and match data from ESPN, maps the data to event IDs, and integrates it with a blockchain oracle for resolving smart contract-based competitions.
- Fetch real-time NFL team and event data from ESPN
- Map team names to team IDs for contract integration
- Store and retrieve match event IDs
- Connect to a blockchain oracle to resolve competitions
- Automate event resolution with smart contracts
npm install
npm run dev
GET /teams
- Fetches team mappingsGET /events
- Fetches NFL event IDsPOST /competition
- Creates a competition with oracle integration
Create a .env
file and add API keys and database credentials.
MIT
Create a .env
file and add API keys and database credentials.
To fetch NFL teams and events and map their IDs, you can run the following scripts:
ts-node scripts/fetchTeams.ts
ts-node scripts/fetchEvents.ts
This script will retrieve the events from the ESPN API and log the mapping of event names to their corresponding IDs.
-
Research UMA Protocol:
- Understand how UMA (Universal Market Access) works and how it can be integrated in the application.
- Review UMA's documentation and examples to see how it handles oracle solutions.
-
Define Oracle Requirements:
- Determine what data needs to be fetched from the oracle.
- Identify the specific events or conditions that will trigger oracle interactions.
-
Set Up Oracle Integration:
- Decide whether the oracle integration should live in this repository or be a separate one.
- If separate, create a new repository for the oracle integration and set up the necessary project structure.
-
Implement Oracle Logic:
- Write the logic to interact with the UMA protocol.
- Ensure that the application can fetch and utilize data from the oracle effectively.
-
Testing:
- Create tests to ensure that the oracle integration works as expected.
- Test various scenarios to validate the reliability of the oracle data.
-
Asserting Data: Implement a function to assert data to the UMA Optimistic Oracle. This will involve creating a smart contract that can submit assertions about events (e.g., "Team A won the match").
-
Handling Disputes: Set up logic to handle disputes. If a dispute arises, the assertion will be sent to the DVM for resolution. Ensure that your application can respond to the outcome of these disputes.
-
Economic Incentives: Understand and implement the economic incentives for asserters and disputers. This includes bonding assertions and rewarding correct disputes.
-
Testing the Integration: Use test networks (like GΓΆrli) to test the integration of the UMA protocol. Ensure that assertions can be made, disputed, and resolved correctly.
oracle-nfl-integration/
βββ src/
β βββ config/
β β βββ env.ts # Environment variable handling
β β βββ constants.ts # Constants like API URLs
β β βββ db.ts # Database connection setup (PostgreSQL, MongoDB, or Redis)
β β βββ oracle.ts # Oracle smart contract interactions
β β βββ network.ts # Blockchain network config
β βββ services/
β β βββ espnApi.ts # Fetch ESPN team and event data
β β βββ teamMapping.ts # Process and store team -> ID mappings
β β βββ matchMapping.ts # Process and store match (event) IDs
β β βββ oracleHandler.ts # Interact with Oracle to update events
β βββ routes/
β β βββ auth.ts # Authentication routes (if needed)
β β βββ competitions.ts # Routes for creating & managing competitions
β β βββ oracle.ts # API endpoints for fetching oracle data
β βββ middleware/
β β βββ authMiddleware.ts # Authentication middleware
β β βββ errorHandler.ts # Error handling middleware
β βββ models/
β β βββ Team.ts # Team schema/model (if using a database)
β β βββ Match.ts # Match schema/model
β βββ utils/
β β βββ logger.ts # Logging utility
β β βββ helper.ts # Generic helper functions
β βββ index.ts # Main entry point
β
βββ scripts/
β βββ fetchTeams.ts # One-time script to populate teams
β βββ fetchEvents.ts # One-time script to populate match events
β
βββ tests/
β βββ espnApi.test.ts # Test ESPN API interactions
β βββ oracle.test.ts # Test Oracle integration
β
βββ .env # Environment variables
βββ .gitignore # Ignore sensitive files
βββ package.json # Dependencies and scripts
βββ README.md # Documentation
βββ tsconfig.json # TypeScript configuration