The OO is anoracle for arbitrary off-chain datawhich leverages an interactive escalation game between requesters, proposers and disputers and is secured by economic incentives.
There are multiple type of identifiers available like Prices , YES_OR_NO queries , Price Indexes, Insurance Claims , etc. More Approved identifiers can be found here :-
You will be working through a simple smart contract that asks the oracle the question: Q:Did the temperature on the 25th of July 2022 in Manhattan NY exceed 35c? A:1 for yes. 0 for no. After submitting the request, you will propose a solution using the UMA Optimistic Oracle UI.
Create the contracts instance with the OOv2 Oracle Contract address
// For Sepolia oracleAddress =0x3CBb6Dbe62CB2D2Daa2019B44d5D19C46AB9Dc45OptimisticOracleV2 oo =OptimisticOracleV2(oracleAddress);
Add the identifier as what type of oracle Data you are requesting , more info on identifier is available here
bytes32 identifier =bytes32("YES_OR_NO_QUERY");
Now ancillaryData needs to be added , it depends on type of identifier , details can be found on UMA docs
bytes ancillaryData =bytes("Q:Did the temperature on the 25th of July 2022 in Manhattan NY exceed 35c? A:1 for yes. 0 for no." );
Next , we need to create a Request to the Optimistic Oracle V2 , with bondCurrency , rewards and the liveness time using requestData .
functionrequestData() public {uint requestTime = block.timestamp; // Set the request time to the current block time.address bondCurrency =0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6; // Use Görli WETH as the bond currency.uint256 reward =0; // Set the reward to 0 (so we dont have to fund it from this contract). requestId = oo.requestData( identifier, ancillaryData, bondCurrency, reward,30 ); }
Currently rewards are not supported via DATUM oracles, so bondCurrenct and reward needs to be default
Later , Proposer will propose the answer , and disputor might dispute too under liveness time.
You can also propose the answer yourself here
After the voting ends , settleRequest needs to be called from Oracle , to complete and get the result
functionsettleRequest() public { oo.settleRequest(requestId); }
Get request result using getRequestResult from Oracle
// SPDX-License-Identifier: AGPL-3.0-onlypragmasolidity ^0.8.14;// *************************************// * Minimum Viable OO Intergration *// *************************************// This contract shows how to get up and running as quickly as posible with UMA's Optimistic Oracle.// We make a simple price request to the OO and return it to the user.import"datum-contracts/interfaces/OptimisticOracleV2Interface.sol";contract OOV2Test {// Create an Optimistic oracle instance at the deployed address on Görli. OptimisticOracleV2 oo =OptimisticOracleV2(0x3CBb6Dbe62CB2D2Daa2019B44d5D19C46AB9Dc45);// Use the yes no idetifier to ask arbitary questions, such as the weather on a particular day.bytes32 identifier =bytes32("YES_OR_NO_QUERY"); // Post the question in ancillary data. Note that this is a simplified form of ancillry data to work as an example. A real
// world prodition market would use something slightly more complex and would need to conform to a more robust structure.
bytes ancillaryData =bytes("Q:Did the temperature on the 25th of July 2022 in Manhattan NY exceed 35c? A:1 for yes. 0 for no." );uint256 requestTime =0; // Store the request time so we can re-use it lateruint requestId;// Submit a data request to the Optimistic oracle.functionrequestData() public { requestTime = block.timestamp; // Set the request time to the current block time.address bondCurrency =0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6; // Use Görli WETH as the bond currency.uint256 reward =0; // Set the reward to 0 (so we dont have to fund it from this contract). requestId = oo.requestData( identifier, ancillaryData, bondCurrency, reward,30 ); } // Settle the request once it's gone through the liveness period of 30 seconds. This acts the finalize the voted on price.
// In a real world use of the Optimistic Oracle this should be longer to give time to disputers to catch bat price proposals.
functionsettleRequest() public { oo.settleRequest(requestId); }// Fetch the resolved price from the Optimistic Oracle that was settled.functiongetSettledData() publicviewreturns (int256) {return oo.getRequestResult(requestId); }}
In this way , you can use Optimistic Oracle V2 in simple steps , extra info is available on the UMA docs