Optimistic Oracle V3

Assert Statements by making a truth claim on-chain

The OOV3 works by making a truth claim about the world, stating that something has happened or is true. Once asserted, the assertion enters a challenge period wherein someone can disagree with the assertion, by disputing it. If no one disputes it during the challenge window the statement is taken as true. If disputed, the outcome is arbitrated using the UMA DVM (more info on how this works here).

It differs from the Optimistic Oracle V2 (getting started can be found here) by being easier to reason about and simpler in integration points.

In this tutorial you will be working through a simple smart contract that asserts the following truth: Statement: Argentina won the 2022 Fifa world cup in Qatar.

Using OO v3

  • Start by importing the datum-contracts package

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.14;

import "datum-contracts/interfaces/OptimisticOracleV3Interface.sol";
  • Create the contracts instance with the OOv3 Oracle Contract address

  // For Sepolia 
oracleAddress = 0xa197690c527C4015e557185E42997d65348fD377
  
OptimisticOracleV3 oa =
        OptimisticOracleV3(oracleAddress);
  • This is the main step where we define the assertedClaim , could be any truth statement from the realWorld.

    bytes public assertedClaim =
        bytes("Argentina won the 2022 Fifa world cup in Qatar");
  • Next , we need to just assert the Claim from Oracle using assertTruthWithDefaults with the assertedClaim

All values are default , such as
a) challenge window to 120 seconds (2 mins)
b) identifier to ASSERT_TRUTH,
c) bond currencyto USDC
d) and default bond size to 0 (which means we dont need to worry about approvals in this example).
    function assertTruth() public {
        assertionId = oa.assertTruthWithDefaults(assertedClaim);
    }

Currently DATUM only supports the default method

  • Later ,it will under challenge period for 120 seconds and the final result will be added to the contract

  • After the voting ends , settleAssertion needs to be called from Oracle , to complete and get the result

    function settleResult() public {
        oa.settleAssertion(assertionId);
    }
  • Get assertion result using getAssertionResult from Oracle

    function getAssertionResult() public view returns (bool) {
        return oa.getAssertionResult(assertionId);
    }

Full Contract Code

// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.16;

// *************************************
// *    Minimum Viable OA Integration  *
// *************************************

// This contract shows how to get up and running as quickly as possible with UMA's Optimistic Asserter.
// We make a simple data assertion about the real world and let the OA arbitrate the outcome.

import "datum-contracts/interfaces/OptimisticOracleV3Interface.sol";

contract OO_GettingStarted {
    // Create an Optimistic Asserter instance at the deployed address on Görli.
    OptimisticOracleV3 oa =
        OptimisticOracleV3(0xa197690c527C4015e557185E42997d65348fD377);

    // Asserted claim. This is some truth statement about the world and can be verified by the network of disputers.
    bytes public assertedClaim =
        bytes("Argentina won the 2022 Fifa world cup in Qatar");

    // Each assertion has an associated assertionID that uniquly identifies the assertion. We will store this here.
    uint public assertionId;

    // Assert the truth against the Optimistic Asserter. This uses the assertion with defaults method which defaults
    // all values, such as a) challenge window to 120 seconds (2 mins), b) identifier to ASSERT_TRUTH, c) bond currency
    //  to USDC and c) and default bond size to 0 (which means we dont need to worry about approvals in this example).
    function assertTruth() public {
        assertionId = oa.assertTruthWithDefaults(assertedClaim);
    }

    // Settle the assertion, if it has not been disputed and it has passed the challenge window, and return the result.
    // result
    function settleResult() public {
        oa.settleAssertion(assertionId);
    }

    // Just return the assertion result. Can only be called once the assertion has been settled.
    function getAssertionResult() public view returns (bool) {
        return oa.getAssertionResult(assertionId);
    }

    // Return the full assertion object contain all information associated with the assertion. Can be called any time.
    // function getAssertion()
    //     public
    //     view
    //     returns (OptimisticAsserterInterface.Assertion memory)
    // {
    //     return oa.getAssertion(assertionId);
    // }
}

In this way , you can use Optimistic Oracle V3 in simple steps , extra info is available on the UMA docs

Last updated