API Reference

API Reference

Comprehensive API documentation with function signatures, parameters, and examples

Contract Addresses

Main Contracts

Diamond (Proxy):
[Deployed Address]
• BettingCoreFacet: Accessible through Diamond
• AMMFacet: Accessible through Diamond
• SecurityFacet: Accessible through Diamond
• OracleFacet: Accessible through Diamond

Tokens

SportGovernanceToken:
[Token Address]
BetUtilityToken:
[Token Address]
BettingCoreFacet API

Events

EventCreated

event EventCreated(
  bytes32 indexed eventId, 
  string description, 
  uint256 startTime, 
  uint256 endTime
);

Emitted when a new betting event is created.

BetPlaced

event BetPlaced(
  bytes32 indexed betId, 
  address indexed bettor, 
  bytes32 indexed eventId, 
  uint256 amount, 
  LibBetting.BetType betType
);

Emitted when a bet is successfully placed.

Functions

createEvent

function createEvent(
  bytes32 eventId,
  string memory description,
  uint256 startTime,
  uint256 endTime
) external onlyAdmin

Description: Creates a new betting event.

Parameters:

  • eventId: Unique identifier for the event
  • description: Human-readable event description
  • startTime: Unix timestamp when betting starts
  • endTime: Unix timestamp when betting ends

Access: Admin only

Emits: EventCreated

placeBet

function placeBet(
  bytes32 eventId,
  LibBetting.BetType betType,
  uint256 minOdds
) external payable

Description: Places a bet on an active event.

Parameters:

  • eventId: Event to bet on
  • betType: For (1) or Against (0)
  • minOdds: Minimum acceptable odds (slippage protection)

Payment: Requires ETH payment (bet amount)

Returns: Creates bet with unique betId

Emits: BetPlaced

AMMFacet API

createMarket

function createMarket(
  bytes32 eventId,
  uint256 initialOddsFor,
  uint256 initialOddsAgainst
) external payable onlyMarketMaker

Description: Creates a new market with initial liquidity.

Access: Market Maker only

Payment: Requires ETH payment (initial liquidity)

Emits: MarketCreated

getMarketPrices

function getMarketPrices(bytes32 eventId) 
  external view returns (uint256 oddsFor, uint256 oddsAgainst)

Description: Gets current market prices.

Returns:

  • oddsFor: Current odds for "For" side
  • oddsAgainst: Current odds for "Against" side
Integration Examples

JavaScript/TypeScript with ethers.js

// Connect to Diamond contract
const diamond = new ethers.Contract(diamondAddress, diamondABI, signer);

// Create a new event (admin only)
const eventId = ethers.utils.formatBytes32String("MATCH_001");
const description = "Arsenal vs Chelsea";
const startTime = Math.floor(Date.now() / 1000) + 3600; // 1 hour from now
const endTime = startTime + 7200; // 2 hours duration

await diamond.createEvent(eventId, description, startTime, endTime);

// Place a bet
const betAmount = ethers.utils.parseEther("0.1"); // 0.1 ETH
const betType = 1; // For
const minOdds = 15000; // 1.5x minimum odds

await diamond.placeBet(eventId, betType, minOdds, { value: betAmount });

Web3.py Integration

# Connect to contract
contract = web3.eth.contract(address=diamond_address, abi=diamond_abi)

# Create event
event_id = Web3.solidityKeccak(['string'], ['MATCH_001'])
tx = contract.functions.createEvent(
    event_id,
    "Arsenal vs Chelsea",
    int(time.time()) + 3600,
    int(time.time()) + 7200
).transact()

# Place bet
bet_tx = contract.functions.placeBet(
    event_id,
    1,  # For
    15000  # Min odds
).transact({'value': Web3.toWei(0.1, 'ether')})