This project is a subgraph for an Odds Weighted Pari Mutuel contract, designed to power decentralized betting or prediction markets. It indexes key events from the smart contract, providing a robust and transparent data layer for a pari-mutuel betting system on the blockchain.
The subgraph indexes the following events:
BetPlaced: Records details of each bet placed by users, including game ID, user address, chosen team, amount, and shares minted.Claimed: Tracks when users claim their winnings, including the payout amount and associated fees.GameCreated: Logs the creation of new games, including details like game ID, participating teams, content identifier (CID), start and end times, and various betting parameters (wMaxBps,wMinBps,kVirtualWei).GameSettled: Records the settlement of a game, indicating the winning team.GameCanceled: Logs when a game is canceled.FeesWithdrawn: Tracks the withdrawal of accumulated fees from the contract.FeeBpsUpdated: Records updates to the fee percentage.OwnershipTransferred: Logs changes in contract ownership.Paused/Unpaused: Records when the contract is paused or unpaused.
- The Graph Protocol: For indexing and querying blockchain data.
- AssemblyScript: For writing the mapping handlers.
src/odds-weighted-pari-mutuel.ts: Contains the AssemblyScript mappings that define how blockchain events are transformed into entities for the subgraph.schema.graphql: Defines the data schema for the subgraph, specifying the entities and their relationships.subgraph.yaml: The manifest file that defines the data sources, entities, and mappings for the subgraph.generated/: Contains auto-generated code based on theschema.graphqland contract ABIs.abis/: Stores the Application Binary Interface (ABI) files for the smart contracts being indexed.
- Node.js and npm/yarn
- Graph CLI (
@graphprotocol/graph-cli)
-
Clone the repository:
git clone [repository-url] cd bet -
Install dependencies:
npm install
or
yarn install
-
Generate code:
npm run codegen
This command generates AssemblyScript types from the GraphQL schema and contract ABIs.
-
Build the subgraph:
npm run build
This compiles the AssemblyScript mappings into WebAssembly.
-
Deploy to The Graph Studio (or a local node):
-
Local Deployment:
npm run create-local npm run deploy-local
-
Hosted Service Deployment:
npm run deploy
(Note: You will need to configure your access token and subgraph name in
subgraph.yamlor viagraph init.)
-
Once deployed, you can query the subgraph using GraphQL. The Graph Explorer provides a user-friendly interface to explore the available entities and their fields.
Example Query (assuming a GameCreated entity exists):
{
gameCreateds(first: 5, orderBy: blockTimestamp, orderDirection: desc) {
id
gameId
teamA
teamB
cid
startTime
endTime
blockTimestamp
}
}This subgraph provides a foundational data layer for building decentralized applications that require transparent and verifiable information about pari-mutuel betting markets.