Apex146 x Chainlink

Technical Documentation


 

Steps For Using This Oracle

  • Write and deploy your contract using the network details and example consumer contract below.

  • Fund your consumer contract with LINK.

  • Call your request method, as described in these docs.

 

Networks Available

Polygon (Matic) Mainnet

Payment Amount: 0.1 LINK

LINK Token Address: 0xb0897686c545045afc77cf20ec7a532e3120e0f1
Oracle Address: 0x079A7039Be143Bfbfa83816a53389eeA0d9eB5aE

Job Ids

Pre (or Post)-Qualifying Probabilities: 4d7f5fe2-edbd-4358-803f-d1684069d65d
Results (Provisional or Final): 86a6fe11-af96-4e11-9d74-47e0141e135d

Polygon (Mumbai) Testnet

Payment Amount: 0.1 LINK

LINK Token Address: 0xb0897686c545045afc77cf20ec7a532e3120e0f1
Oracle Address: 0x079A7039Be143Bfbfa83816a53389eeA0d9eB5aE

Job Ids

Pre (or Post)-Qualifying Probabilities: 4d7f5fe2-edbd-4358-803f-d1684069d65d
Results (Provisional or Final): 86a6fe11-af96-4e11-9d74-47e0141e135d

 

Get Probabilities By Event Id, Qualifying Status, and Bet Type

Request Parameters

event_id (as event_id)

  • The id of the event you want to request data for. Event Ids will be provided in advance by us before the season begins.

Qualifying Status (as qualifying_status)

  • To determine if the request is for pre qualifying status or post qualifying status

Bet Type (as bet_type)

  • To determine which bet type you want to request. (ex. dream_teams)

Outputs

  • Bet Detail: The riders or categories each matchup will include, returned as bytes.

  • Probability_A: Probability for Team/Category/Rider A, returned as uint256.

  • Probability_B: Probability for Team/Category/Rider B, returned as uint256.

  • Probability_C: Probability for Team/Category/Rider C, returned as uint256.

  • Probability_D: Probability for Team/Category/Rider D, returned as uint256.

 

Get Results By Event Id, Result Type, and Bet Type

Adapter

  • tbd

Request Parameters

event_id (as event_id)

  • The id of the event you want to request data for. Event Ids will be provided in advance by us before the season begins. This will most likely stay the same throughout the week for any given race

result_type (as result_type)

  • To determine if the request is for provisional results or final results. Provisional will come out very quickly after the end of the race, whereas final results come out after any post race announcements and finalizations happen.

bet_type (as bet_type)

  • To determine which bet type you want to request. (ex. dream_teams)

Outputs

  • Results: The win/loss column, alongside positional data for dream teams, returned as bytes

  • Result Details: The numerical scores and/or times for any given category/matchup, returned as bytes.

 

Data Types

Probabilities

bytes betTypeDetail;
uint256 probA;
uint256 probB;
uint256 probC;
uint256 probD;

Results

bytes result;
bytes resultsSpecificDetails;

Output Condition Decimal Conversions and Units

Probabilities multiplied by 10000

 

Sample Consumer Contract

 
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
import "@chainlink/contracts/src/v0.8/ChainlinkClient.sol";
import "@chainlink/contracts/src/v0.8/ConfirmedOwner.sol";
/*
 * **** Data Conversions ****
 *
 * Decimals to integers
 * ---------------------------------------------------
 * Value                           Conversion
 * ---------------------------------------------------
 * probability A                multiplied by 10000
 * probability B                multiplied by 10000
 * probability C                multiplied by 10000
 * probability D                multiplied by 10000
 *
 */

contract SampleContract is ChainlinkClient, ConfirmedOwner {
using Chainlink for Chainlink.Request;

/* ========== CONSUMER STATE VARIABLES ========== */

  uint256 constant private ORACLE_PAYMENT = 1 * LINK_DIVISIBILITY;
  bytes public betTypeDetail;
  uint256 public probabilityA;
  uint256 public probabilityB;
  uint256 public probabilityC;
  uint256 public probabilityD;
    
  bytes public results;
  bytes public resultsDetail;

  event RequestProbabilitiesFulfilled(
    bytes32 indexed requestId,
    bytes betTypeDetail,
    uint256 probA,
    uint256 probB,
    uint256 probC,
    uint256 probD
  );
    
  event RequestResultsFulfilled(
    bytes32 indexed requestId,
    bytes result,
    bytes resultDetails
  );

/* ========== CONSTRUCTOR ========== */

/**
 * @input the LINK token address.
 */
  constructor() ConfirmedOwner(msg.sender){
    setPublicChainlinkToken();
    // use the function below for Polygon/Non-Ethereum related calls. 
    setChainlinkToken(0xb0897686c545045aFc77CF20eC7A532E3120E0F1);
  }
/* ========== CONSUMER REQUEST FUNCTIONS ========== */
  /**
   * @notice Returns the matchup information. This function is requesting pre-qualifying probabilities 
   *  for the bet type outright_head_to_head_1 for the event id mgr_assen21
   * @param _jobId the job id being requested
   * @param _oracle the Operator.sol contract address
   */

  function requestMatchup(address _oracle, string memory _jobId)
    public
    onlyOwner
  {
    Chainlink.Request memory req = buildChainlinkRequest(stringToBytes32(_jobId), address(this), this.fulfillMatchup.selector);
    req.add("event_id", "mgr_assen21"); // example data points
    req.add("qualifying_status", "pre");
    req.add("bet_type", "outright_head_to_head_1");
    sendChainlinkRequestTo(_oracle, req, ORACLE_PAYMENT);
  }

  /**
   * @notice Returns the results information. Function is requesting provisional results for the 
   * bet type fastest_lap_head_to_head_1 for the event id mgr_assen21
   * @param _jobId the job id being requested
   * @param _oracle the Operator.sol contract address
   */

  function requestResults(address _oracle, string memory _jobId)
    public
    onlyOwner
  {
    Chainlink.Request memory req = buildChainlinkRequest(stringToBytes32(_jobId), address(this), this.fulfillResults.selector);
    req.add("event_id", "mgr_assen21");
    req.add("result_type", "provisional");
    req.add("bet_type", "fastest_lap_head_to_head_1");
    sendChainlinkRequestTo(_oracle, req, ORACLE_PAYMENT);
  }

/* ========== CONSUMER FULFILL FUNCTIONS ========== */
  /**
   * @notice Consumes the data returned by the node job on a particular request.
   * @param _requestId the request ID for fulfillment
   * @param _bet_type the type of bet being requested.
   * @param _probA: Probability for Team/Category/Rider A, returned as uint256.
   * @param _probB: Probability for Team/Category/Rider B, returned as uint256.
   * @param _probC: Probability for Team/Category/Rider C, returned as uint256.
   * @param _probD: Probability for Team/Category/Rider D, returned as uint256.
   */

  function fulfillMatchup(bytes32 _requestId, bytes calldata _betTypeDetail, uint256 _probA, uint256 _probB, uint256 _probC, uint256 _probD)
    public
    recordChainlinkFulfillment(_requestId)
  {
    emit RequestProbabilitiesFulfilled(_requestId, _betTypeDetail, _probA, _probB, _probC, _probD);
    betDetail = _betTypeDetail;
    probabilityA = _probA;
    probabilityB = _probB;
    probabilityC = _probC;
    probabilityD = _probD;
  }

  /**
   * @notice Consumes the data returned by the node job on a particular request.
   * @param _requestId the request ID for fulfillment
   * @param _result win/loss for the matchup.
   * @param _resultsDetail ranking/timing data to elaborate on win/loss
   */
  function fulfillResults(bytes32 _requestId, bytes calldata _result, bytes calldata _resultDetails)
    public
    recordChainlinkFulfillment(_requestId)
  {
    emit RequestResultsFulilled(_requestId, _result, _resultDetails);
    results = _result;
    resultsDetail = _resultDetails;
  }

/* ========== OTHER FUNCTIONS ========== */
    function getOracleAddress() external view returns (address) {
        return chainlinkOracleAddress();
    }

    function setOracle(address _oracle) external {
        setChainlinkOracle(_oracle);
    }

    function getChainlinkToken() public view returns (address) {
      return chainlinkTokenAddress();
    }

    function withdrawLink() public onlyOwner {
      LinkTokenInterface link = LinkTokenInterface(chainlinkTokenAddress());
      require(link.transfer(msg.sender, link.balanceOf(address(this))), "Unable to transfer");
    }

    function cancelRequest(
      bytes32 _requestId,
      uint256 _payment,
      bytes4 _callbackFunctionId,
      uint256 _expiration
    )
      public
      onlyOwner
    {
      cancelChainlinkRequest(_requestId, _payment, _callbackFunctionId, _expiration);
    }

    function stringToBytes32(string memory source) private pure returns (bytes32 result) {
      bytes memory tempEmptyStringTest = bytes(source);
      if (tempEmptyStringTest.length == 0) {
        return 0x0;
      }
      assembly { // solhint-disable-line no-inline-assembly
        result := mload(add(source, 32))
      }
    }
}