Skip to content

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.

Notifications You must be signed in to change notification settings

bhas10bc/sub_graph

Repository files navigation

Odds Weighted Pari Mutuel Subgraph

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.

Features

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.

Technologies Used

  • The Graph Protocol: For indexing and querying blockchain data.
  • AssemblyScript: For writing the mapping handlers.

Project Structure

  • 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 the schema.graphql and contract ABIs.
  • abis/: Stores the Application Binary Interface (ABI) files for the smart contracts being indexed.

Getting Started

Prerequisites

  • Node.js and npm/yarn
  • Graph CLI (@graphprotocol/graph-cli)

Installation

  1. Clone the repository:

    git clone [repository-url]
    cd bet
  2. Install dependencies:

    npm install

    or

    yarn install

Building and Deployment

  1. Generate code:

    npm run codegen

    This command generates AssemblyScript types from the GraphQL schema and contract ABIs.

  2. Build the subgraph:

    npm run build

    This compiles the AssemblyScript mappings into WebAssembly.

  3. 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.yaml or via graph init.)

Usage

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.

About

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.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published