Monk Data Oracles

About

Monk Data Oracles are offchain nodes that index and store blockchain events and Monk-related information. These oracles serve as efficient data providers for Player Pool proposals by computing complex operations (e.g., wager race leaderboard sorting) offchain and then delivering those results onchain.

Consuming from Monk Data Oracles

Currently, proposal contracts must be whitelisted to use the Monk Data Oracles. If you'd like to whitelist your deployed proposal contract, then publish & verify the source code on BaseScan and open a support ticket in our Discord.

  1. Inherit the MonkOracleConsumerBase contract

MonkOracleConsumerBase.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

// minimal interface for ProposalLaunchpad
interface IProposalLaunchpad {
  function verifiedSender() external view returns (address);
  function deployContract(
    string memory contractType,
    bytes memory config,
    address deployer
  ) external returns (address);
}

abstract contract MonkOracleConsumerBase {
  IProposalLaunchpad public launchpadAddress;

  constructor(IProposalLaunchpad _launchpadAddress) {
    launchpadAddress = _launchpadAddress;
  }

  modifier onlyVerifiedSender() {
    address verifiedSender = launchpadAddress.verifiedSender();
    require(msg.sender == verifiedSender, "Sender is not verified");
    _;
  }

  function _fullfillRequest(bytes memory _request, bytes memory result)
    internal
    virtual;

  function fullfillRequest(bytes memory _request, bytes memory result)
    internal 
    onlyVerifiedSender
  {
    _fullfillRequest(_request, result);
  }
}
  1. Override the _fullfillRequest method with Player Pool processing logic

/**
 * @param result - An array of winner addresses 
 */
function _fullfillRequest(bytes memory, bytes memory result)
  internal
  override
  virtual
{
  uint256 totalBalance = monkToken.balanceOf(address(this));
  // process winners
  (address[] memory winners) = abi.decode(result, (address[]));
  require(winners.length == winnerDistribution.length, "Invalid oracle result");
  for (uint256 i = 0; i < winners.length; i++) {
    address winner = winners[i];
    if (winner != address(0)) {
      uint256 prize = (payout * winnerDistribution[i]) / 100;
      require(monkToken.transfer(winner, prize), "Transfer failed");
      emit MonkLotteryWinnerDrawn(winner, prize, i);
    }
  }
}
  1. Pass in the correct Proposal Launchpad contract address when deploying

Coming Soon: Onchain Data Query Language

Developers will be able to query from the Monk Data Oracles directly from their custom proposal contracts without requiring a whitelist or special configuration. The query system will enable developers to build more intricate and innovative Player Pool proposals.

With this capability, developers can create proposals such as:

  • Wager races that combine offchain and onchain wager data

  • Advanced lottery systems (e.g., entry via gifted bets)

  • Player rakeback based on site-wide loss data

  • …or anything else that comes to mind

Last updated