### Clone UMA Quick-Start Repositories Source: https://context7.com/umaprotocol/uma-docs/llms.txt Quickly set up your development environment by cloning UMA's official example repositories. This includes installing dependencies and running tests. ```bash # OOv3 Quick Start (Foundry/Forge) git clone https://github.com/UMAprotocol/dev-quickstart-oov3.git cd dev-quickstart-oov3 forge install forge test # Available contracts: # - src/DataAsserter.sol: Generic data assertion pattern # - src/Insurance.sol: Insurance claim verification # - src/PredictionMarket.sol: Binary prediction markets ``` -------------------------------- ### Clone and Install UMA Dev Quickstart Source: https://context7.com/umaprotocol/uma-docs/llms.txt Clone the UMA dev-quickstart repository and install its dependencies using Yarn. ```bash git clone https://github.com/UMAprotocol/dev-quickstart.git cd dev-quickstart yarn install ``` -------------------------------- ### Clone and Install Dependencies Source: https://github.com/umaprotocol/uma-docs/blob/master/developers/optimistic-oracle-v3/data-asserter.md Clone the UMA Optimistic Oracle V3 quick-start repository and install its dependencies using forge. ```bash git clone https://github.com/UMAprotocol/dev-quickstart-oov3.git cd dev-quickstart-oov3 forge install ``` -------------------------------- ### Clone Repository and Install Dependencies Source: https://github.com/umaprotocol/uma-docs/blob/master/developers/optimistic-oracle/in-depth-tutorial-insurance-claims-arbitration.md Clone the UMA dev-quickstart repository and install project dependencies using yarn. Ensure Node.js v16 (LTS) is installed. ```bash git clone git@github.com:UMAprotocol/dev-quickstart.git cd dev-quickstart yarn ``` -------------------------------- ### Install Dependencies and Build Source: https://github.com/umaprotocol/uma-docs/blob/master/verification-guide/across.md After cloning the repository, navigate into the directory and install dependencies, then build the project. This is a prerequisite for running verification scripts. ```bash cd relayer-v2 yarn install yarn build ``` -------------------------------- ### Install dependencies Source: https://github.com/umaprotocol/uma-docs/blob/master/developers/optimistic-oracle/in-depth-tutorial-event-based-prediction-market.md Install project dependencies using yarn. This command should be run after cloning the repository and navigating into the project directory. ```bash yarn ``` -------------------------------- ### Install Forge Dependencies Source: https://github.com/umaprotocol/uma-docs/blob/master/developers/optimistic-oracle/sandboxed-oracle-environment.md Install project dependencies for forge. Ensure you have the latest Foundry version installed. ```bash forge install ``` -------------------------------- ### Start Local Anvil Node Source: https://github.com/umaprotocol/uma-docs/blob/master/developers/optimistic-oracle-v3/prediction-market.md Run a local Ethereum node using Anvil. This command should be executed in a separate console. ```bash anvil ``` -------------------------------- ### Run Unit Tests Source: https://github.com/umaprotocol/uma-docs/blob/master/developers/optimistic-oracle/in-depth-tutorial-optimistic-arbitrator.md Execute all unit tests for the Optimistic Arbitrator. Ensure you have the project dependencies installed. ```bash yarn test test/OptimisticArbitrator/* ``` -------------------------------- ### Setup Environment Variables for Foundry Source: https://context7.com/umaprotocol/uma-docs/llms.txt Sets up necessary environment variables for local testing with Foundry, including mnemonic phrases, RPC URLs, and wallet addresses. ```bash # Setup environment export MNEMONIC="test test test test test test test test test test test junk" export ETH_RPC_URL="http://127.0.0.1:8545" export DEPLOYER_WALLET=$(cast wallet address --mnemonic "$MNEMONIC") export USER_WALLET=$(cast wallet address --mnemonic "$MNEMONIC" --mnemonic-index 1) export ASSERTER_WALLET=$(cast wallet address --mnemonic "$MNEMONIC" --mnemonic-index 2) ``` -------------------------------- ### Run Unit Tests Source: https://github.com/umaprotocol/uma-docs/blob/master/developers/optimistic-oracle/internal-optimistic-oracle.md Execute all unit tests for InternalOptimisticOracle contracts. Ensure you have the project dependencies installed. ```bash yarn test test/InternalOptimisticOracle/* ``` -------------------------------- ### Clone the dev-quickstart repo Source: https://github.com/umaprotocol/uma-docs/blob/master/developers/optimistic-oracle/in-depth-tutorial-event-based-prediction-market.md Clone the repository to access the Event Based Prediction Market contract and related development tools. Ensure you have Node.js v16 and yarn installed. ```bash git clone git@github.com:UMAprotocol/dev-quickstart.git cd dev-quickstart ``` -------------------------------- ### Example Validation Results Source: https://github.com/umaprotocol/uma-docs/blob/master/verification-guide/across.md This JSON output represents the results of the root bundle validation. An 'invalid': false status indicates a problem, with 'invalidReason' providing further details. This example shows an invalid bundle. ```json { "at": "RootBundleValidator", "message": "Validation results", "rootBundle": { "poolRebalanceRoot": "0x7005c47a8e476a2551d5325a6c53cd5b71f308b2ac670742ad7cceb8078a193f", "relayerRefundRoot": "0x9edefc2fc000e71fa1ea1c6ce666a0f8cb2d6da422c45a372585da5e3b738713", "slowRelayRoot": "0x0000000000000000000000000000000000000000000000000000000000000000", "proposer": "0xf7bAc63fc7CEaCf0589F25454Ecf5C2ce904997c", "unclaimedPoolRebalanceLeafCount": 5, "challengePeriodEndTimestamp": 1692117191, "bundleEvaluationBlockNumbers": [ 17920824, 108255396, 46338509, 977154, 121659934, 11305323 ], "proposalBlockNumber": 17920860 }, "valid": false, "invalidReason": "Disputed pending root bundle:\n..... // removed the rest of the invalidReason for the example } ``` -------------------------------- ### Start Hardhat Console for Görli Network Source: https://github.com/umaprotocol/uma-docs/blob/master/developers/optimistic-oracle/in-depth-tutorial-insurance-claims-arbitration.md Launch the Hardhat console connected to the Görli network for interacting with deployed contracts. Configure `NODE_URL_5` and `MNEMONIC` environment variables. ```bash NODE_URL_5=YOUR_GOERLI_NODE MNEMONIC=YOUR_MNEMONIC yarn hardhat console --network goerli ``` -------------------------------- ### Lookup UMA Contracts on Network using Finder Source: https://context7.com/umaprotocol/uma-docs/llms.txt Use the Finder contract to retrieve addresses of UMA contracts on various networks. Ensure you have `cast` installed and configured. ```bash # Ethereum Mainnet Finder export FINDER_MAINNET=0x40f941E48A552bF496B154Af6bf55725f18D77c3 # Get OptimisticOracleV3 address cast call $FINDER_MAINNET "getImplementationAddress(bytes32)(address)" \ $(cast --format-bytes32-string "OptimisticOracleV3") # Get OptimisticOracleV2 address cast call $FINDER_MAINNET "getImplementationAddress(bytes32)(address)" \ $(cast --format-bytes32-string "OptimisticOracle") # Get DVM (Data Verification Mechanism) Oracle cast call $FINDER_MAINNET "getImplementationAddress(bytes32)(address)" \ $(cast --format-bytes32-string "Oracle") # Get default currency from OOv3 export OOV3=$(cast call $FINDER_MAINNET "getImplementationAddress(bytes32)(address)" \ $(cast --format-bytes32-string "OptimisticOracleV3")) cast call $OOV3 "defaultCurrency()(address)" # Get minimum bond for a currency cast call $OOV3 "getMinimumBond(address)(uint256)" $CURRENCY_ADDRESS # Supported Networks: # - Ethereum Mainnet (1): Full DVM support # - Polygon (137): Full DVM support # - Optimism (10): Full DVM support # - Arbitrum (42161): Full DVM support # - Base (8453): Full DVM support # - Sepolia Testnet (11155111): No DVM, testnet only ``` -------------------------------- ### Set MNEMONIC Environment Variable Source: https://github.com/umaprotocol/uma-docs/blob/master/developers/optimistic-oracle-v3/data-asserter.md Export your passphrase for deriving private keys. This example uses the default Anvil unlocked accounts for a local testnet environment. ```bash export MNEMONIC="test test test test test test test test test test test junk" ``` -------------------------------- ### Initialize Contract Libraries and Connections Source: https://github.com/umaprotocol/uma-docs/blob/master/developers/optimistic-oracle/in-depth-tutorial-optimistic-arbitrator.md Sets up necessary libraries and connects to deployed UMA contracts like OptimisticArbitrator, Finder, Store, TestnetERC20, and MockOracleAncillary. ```javascript const { getAbi, getAddress } = require("@uma/contracts-node"); const { ethers } = require("hardhat"); const signer = (await ethers.getSigners())[0]; const optimisticArbitratorDeployment = await deployments.get("OptimisticArbitrator"); const optimisticArbitrator = new ethers.Contract( optimisticArbitratorDeployment.address, optimisticArbitratorDeployment.abi, ethers.provider ); const finder = new hre.ethers.Contract( "0xDC6b80D38004F495861E081e249213836a2F3217", // Finder address used in the deployment getAbi("Finder"), ethers.provider ); const store = new hre.ethers.Contract( await finder.getImplementationAddress(ethers.utils.formatBytes32String("Store")), getAbi("Store"), ethers.provider ); const currency = new hre.ethers.Contract( await optimisticArbitrator.currency(), getAbi("TestnetERC20"), ethers.provider ); const mockOracle = new hre.ethers.Contract( await finder.getImplementationAddress(ethers.utils.formatBytes32String("Oracle")), getAbi("MockOracleAncillary"), ethers.provider ); ``` -------------------------------- ### Initialize Contracts and Libraries Source: https://github.com/umaprotocol/uma-docs/blob/master/developers/optimistic-oracle/internal-optimistic-oracle.md Sets up connections to UMA contracts like InternalOptimisticOracle, Finder, Store, and TestnetERC20. Requires @uma/contracts-node and hardhat. ```javascript const { getAbi, getAddress } = require("@uma/contracts-node"); const { ethers } = require("hardhat"); const signer = (await ethers.getSigners())[0]; const iooDeployment = await deployments.get("InternalOptimisticOracle"); const ioo = new ethers.Contract( iooDeployment.address, iooDeployment.abi, ethers.provider ); const finder = new hre.ethers.Contract( "0xDC6b80D38004F495861E081e249213836a2F3217", // Finder address used in the deployment getAbi("Finder"), ethers.provider ); const store = new hre.ethers.Contract( await finder.getImplementationAddress( ethers.utils.formatBytes32String("Store") ), getAbi("Store"), ethers.provider ); const currency = new hre.ethers.Contract( await ioo.currency(), getAbi("TestnetERC20"), ethers.provider ); const mockOracle = new hre.ethers.Contract( await finder.getImplementationAddress( ethers.utils.formatBytes32String("Oracle") ), getAbi("MockOracleAncillary"), ethers.provider ); ``` -------------------------------- ### Initialize UMA Contracts and Signers Source: https://github.com/umaprotocol/uma-docs/blob/master/developers/optimistic-oracle/in-depth-tutorial-insurance-claims-arbitration.md Sets up the necessary environment by importing UMA contract utilities and defining insurer and insured accounts. ```javascript const { getAbi } = require("@uma/contracts-node"); const [insurer, insured] = await ethers.getSigners(); ``` -------------------------------- ### Settle and Get Price Source: https://github.com/umaprotocol/uma-docs/blob/master/developers/optimistic-oracle/internal-optimistic-oracle.md Settles a price request and retrieves the final price. Used to verify the proposed answer after the liveness period. ```javascript await( await ioo.connect(signer).settleAndGetPrice(requestTimestamp, ancillaryData) ).wait(); console.log( "Price is the correct answer: ", (await ioo.getPrice(requestTimestamp, ancillaryData)).eq(correctAnswer) ); ``` -------------------------------- ### Export Wallet and Network Environment Variables Source: https://github.com/umaprotocol/uma-docs/blob/master/developers/optimistic-oracle-v3/prediction-market.md Set up environment variables for mnemonics, user IDs, and RPC URLs required for deployment. Ensure these are exported in the same console where deployment commands will be run. ```bash export MNEMONIC="test test test test test test test test test test test junk" export USER_ID=1 export ASSERTER_ID=2 export DEPLOYER_WALLET=$(cast wallet address --mnemonic "$MNEMONIC") export USER_WALLET=$(cast wallet address --mnemonic "$MNEMONIC" --mnemonic-index $USER_ID) export ASSERTER_WALLET=$(cast wallet address --mnemonic "$MNEMONIC" --mnemonic-index $ASSERTER_ID) export ETH_RPC_URL="http://127.0.0.1:8545" ``` -------------------------------- ### Deploy FullPolicyEscalationManager Contract Source: https://github.com/umaprotocol/uma-docs/blob/master/developers/optimistic-oracle-v3/escalation-managers.md Deploys the FullPolicyEscalationManager contract on an EVM network using Hardhat and ethers.js. Ensure you have the necessary UMA contracts installed. ```typescript const hre = require("hardhat"); import { FullPolicyEscalationManagerEthers__factory } from "@uma/contracts-node"; const { getContractFactory } = hre.ethers; const { getAddress } = require("@uma/contracts-node"); async function main() { console.log("Running FullPolicyEscalationManager Deployments🔥"); const networkId = Number(await hre.getChainId()); const optimisticOracleV3 = getAddress("OptimisticOracleV3", networkId); const fullPolicyEscalationManagerFactory: FullPolicyEscalationManagerEthers__factory = await getContractFactory( "FullPolicyEscalationManager" ); const fullPolicyEscalationManager = await fullPolicyEscalationManagerFactory.deploy(optimisticOracleV3); console.log("Deployed FullPolicyEscalationManager: ", fullPolicyEscalationManager.address); } main() .then(() => process.exit(0)) .catch((error) => { console.error(error); process.exit(1); }); ``` -------------------------------- ### Initialize Prediction Market with Bash Source: https://github.com/umaprotocol/uma-docs/blob/master/developers/optimistic-oracle-v3/prediction-market.md Initialize a prediction market by sending a transaction with market details, reward, and bond. Captures transaction hash and decodes market initialization logs to retrieve market and outcome token addresses. ```bash export MARKET_ID_TX=$(cast send --json \ --mnemonic "$MNEMONIC" \ $PREDICTION_MARKET_ADDRESS \ "initializeMarket(string,string,string,uint256,uint256)(bytes32)" \ $OUTCOME_ONE $OUTCOME_TWO "$DESCRIPTION" $REWARD $REQUIRED_BOND \ | jq -r .transactionHash) export MARKET_ID=$(cast receipt --json $MARKET_ID_TX | jq -r .logs[-1].topics[1]) export OUTCOME_TOKEN_ONE_ADDRESS=$(cast --abi-decode \ "MarketInitializedNonIndexed()(string,string,string,address,address,uint256,uint256)" \ $(cast receipt --json $MARKET_ID_TX | jq -r .logs[-1].data) | awk 'NR==4 {print $1}') export OUTCOME_TOKEN_TWO_ADDRESS=$(cast --abi-decode \ "MarketInitializedNonIndexed()(string,string,string,address,address,uint256,uint256)" \ $(cast receipt --json $MARKET_ID_TX | jq -r .logs[-1].data) | awk 'NR==5 {print $1}') ``` -------------------------------- ### Dispute Assertion and Get Request ID with Cast Source: https://github.com/umaprotocol/uma-docs/blob/master/developers/optimistic-oracle/sandboxed-oracle-environment.md Disputes an assertion and extracts the request ID from the event logs. Requires jq for JSON parsing. ```bash export DISPUTE_TX=$(cast send --mnemonic "$MNEMONIC" --json $OOV3_ADDRESS "disputeAssertion(bytes32,address)" $ASSERTION_ID $USER_ADDRESS | jq -r '.transactionHash') export REQUEST_ID=$(cast receipt --json $DISPUTE_TX | jq -r --arg MOCK_LOWERCASE $(echo $MOCK_ORACLE_ADDRESS | tr [:upper:] [:lower:]) '.logs[] | select(.address==$MOCK_LOWERCASE).topics[3]') ``` -------------------------------- ### Initialize Prediction Market Source: https://context7.com/umaprotocol/uma-docs/llms.txt Initializes a prediction market with specified parameters, including reward, bond, and market details. Requires allocating and approving tokens. ```bash # Initialize market export REWARD=$(cast --to-wei 100) export BOND=$(cast --to-wei 5000) cast send --mnemonic "$MNEMONIC" $DEFAULT_CURRENCY "allocateTo(address,uint256)" $DEPLOYER_WALLET $REWARD cast send --mnemonic "$MNEMONIC" $DEFAULT_CURRENCY "approve(address,uint256)" $PREDICTION_MARKET $REWARD export MARKET_TX=$(cast send --json --mnemonic "$MNEMONIC" \ $PREDICTION_MARKET \ "initializeMarket(string,string,string,uint256,uint256)(bytes32)" \ "yes" "no" "Will BTC exceed 100k by end of 2024?" $REWARD $BOND \ | jq -r .transactionHash) export MARKET_ID=$(cast receipt --json $MARKET_TX | jq -r .logs[-1].topics[1]) ``` -------------------------------- ### Get Addresses on Whitelist Source: https://github.com/umaprotocol/uma-docs/blob/master/developers/managedoptimisticoraclev2/proposing-programmatically.md Call this function on a whitelist contract address to retrieve all addresses currently on that whitelist. This is useful for auditing or verifying allowed proposers. ```solidity function getWhitelist() external view returns (address[]) ``` -------------------------------- ### Deploy and Interact with Data Asserter using Foundry/Cast Source: https://context7.com/umaprotocol/uma-docs/llms.txt This bash script demonstrates deploying and interacting with the Data Asserter contract using Foundry tools on a local Goerli fork. It includes setting up environment variables, fetching necessary contract addresses, deploying the Data Asserter, and preparing assertion data. ```bash # Start local Goerli fork\nanvil --fork-url https://goerli.infura.io/v3/YOUR_INFURA_KEY\n\n# Export environment variables\nexport ETH_RPC_URL=http://127.0.0.1:8545\nexport MNEMONIC="test test test test test test test test test test test junk"\nexport FINDER_ADDRESS=0xE60dBa66B85E10E7Fd18a67a6859E241A243950e\n\n# Get OOv3 and currency addresses\nexport OOV3_ADDRESS=$(cast call $FINDER_ADDRESS "getImplementationAddress(bytes32)(address)" \ $(cast --format-bytes32-string "OptimisticOracleV3"))\nexport DEFAULT_CURRENCY_ADDRESS=$(cast call $OOV3_ADDRESS "defaultCurrency()(address)")\n\n# Deploy Data Asserter contract\nexport DATA_ASSERTER=$(forge create --json src/DataAsserter.sol:DataAsserter \ --mnemonic "$MNEMONIC" \ --constructor-args $DEFAULT_CURRENCY_ADDRESS $OOV3_ADDRESS \ | jq -r .deployedTo)\n\n# Prepare assertion data (simple computation: 69+420=489)\nexport DATA_ID=$(cast --format-bytes32-string "echo '69+420' | bc")\nexport DATA=$(cast --format-bytes32-string $(echo '69+420' | bc))\nexport ASSERTER_ID=1 ``` -------------------------------- ### Settle and Get Result of Price Request Source: https://github.com/umaprotocol/uma-docs/blob/master/developers/optimistic-oracle/in-depth-tutorial-optimistic-arbitrator.md Settles an accepted price request using the optimistic arbitrator and retrieves the final result. This confirms that the assertion was validated. ```javascript await (await optimisticArbitrator.connect(signer).settleAndGetResult(requestTimestamp, ancillaryData)).wait(); const resultRatify = await optimisticArbitrator.connect(signer).getResult(requestTimestamp, ancillaryData); // YES_ANSWER console.log("Assert and ratify result is a yes answer :", resultRatify.eq(YES_ANSWER)); ``` -------------------------------- ### Assert Truth and Get Assertion ID with Cast Source: https://github.com/umaprotocol/uma-docs/blob/master/developers/optimistic-oracle/sandboxed-oracle-environment.md Sends an assertion transaction and extracts the assertion ID from the event logs. Requires jq for JSON parsing. ```bash export ASSERTION_TX=$(cast send --mnemonic "$MNEMONIC" --json $OOV3_ADDRESS "assertTruthWithDefaults(bytes,address)" $(cast --from-utf8 "test claim") $USER_ADDRESS | jq -r '.transactionHash') export ASSERTION_ID=$(cast receipt --json $ASSERTION_TX | jq -r --arg OOV3_LOWERCASE $(echo $OOV3_ADDRESS | tr [:upper:] [:lower:]) '.logs[] | select(.address==$OOV3_LOWERCASE).topics[1]') ``` -------------------------------- ### Run EventBasedPredictionMarket Tests Source: https://github.com/umaprotocol/uma-docs/blob/master/developers/optimistic-oracle/in-depth-tutorial-event-based-prediction-market.md Execute tests for the EventBasedPredictionMarket contract. Ensure you are in the project root directory. ```bash yarn test test/EventBasedPredictionMarket/* ``` -------------------------------- ### Get Default Proposer Whitelist Address Source: https://github.com/umaprotocol/uma-docs/blob/master/developers/managedoptimisticoraclev2/proposing-programmatically.md Retrieve the address of the default proposer whitelist contract from a deployed ManagedOptimisticOracleV2 instance. This is used to view the default whitelist. ```solidity function defaultProposerWhitelist() external view returns (address) ``` -------------------------------- ### Initialize Prediction Market Source: https://context7.com/umaprotocol/uma-docs/llms.txt Use this function to create a new prediction market. It requires outcome names, a description, and optional reward and bond amounts. Ensure the market ID does not already exist. ```Solidity // SPDX-License-Identifier: MIT\npragma solidity ^0.8.16;\n\nimport "@uma/core/contracts/optimistic-oracle-v3/interfaces/OptimisticOracleV3Interface.sol";\nimport "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";\nimport "@uma/core/contracts/common/implementation/ExpandedERC20.sol";\n\ncontract PredictionMarket {\n using SafeERC20 for IERC20;\n\n struct Market {\n ExpandedERC20 outcome1Token;\n ExpandedERC20 outcome2Token;\n string outcome1;\n string outcome2;\n string description;\n uint256 reward;\n uint256 requiredBond;\n bytes32 assertedOutcomeId;\n bool resolved;\n }\n\n IERC20 public immutable currency;\n OptimisticOracleV3Interface public immutable oo;\n bytes32 public immutable defaultIdentifier;\n\n mapping(bytes32 => Market) public markets;\n mapping(bytes32 => bytes32) public assertionToMarket;\n\n event MarketInitialized(bytes32 indexed marketId, string outcome1, string outcome2, string description);\n event TokensCreated(bytes32 indexed marketId, address indexed account, uint256 amount);\n event MarketAsserted(bytes32 indexed marketId, string assertedOutcome, bytes32 indexed assertionId);\n event MarketResolved(bytes32 indexed marketId, bytes32 assertedOutcomeId);\n\n constructor(address _currency, address _optimisticOracleV3) {\n currency = IERC20(_currency);\n oo = OptimisticOracleV3Interface(_optimisticOracleV3);\n defaultIdentifier = oo.defaultIdentifier();\n }\n\n // Create a new prediction market\n function initializeMarket(\n string memory outcome1,\n string memory outcome2,\n string memory description,\n uint256 reward,\n uint256 requiredBond\n ) external returns (bytes32 marketId) {\n marketId = keccak256(abi.encode(outcome1, outcome2, description));\n require(address(markets[marketId].outcome1Token) == address(0), "Market exists");\n\n markets[marketId] = Market({\n outcome1Token: new ExpandedERC20(string.concat(outcome1, " Token"), "OUT1", 18),\n outcome2Token: new ExpandedERC20(string.concat(outcome2, " Token"), "OUT2", 18),\n outcome1: outcome1,\n outcome2: outcome2,\n description: description,\n reward: reward,\n requiredBond: requiredBond,\n assertedOutcomeId: bytes32(0),\n resolved: false\n });\n\n if (reward > 0) currency.safeTransferFrom(msg.sender, address(this), reward);\n emit MarketInitialized(marketId, outcome1, outcome2, description);\n }\n\n // Mint equal amounts of both outcome tokens\n function createOutcomeTokens(bytes32 marketId, uint256 amount) external {\n Market storage market = markets[marketId];\n require(address(market.outcome1Token) != address(0), "Market not found");\n\n currency.safeTransferFrom(msg.sender, address(this), amount);\n market.outcome1Token.mint(msg.sender, amount);\n market.outcome2Token.mint(msg.sender, amount);\n\n emit TokensCreated(marketId, msg.sender, amount);\n }\n\n // Assert market outcome\n function assertMarket(bytes32 marketId, string memory assertedOutcome) external returns (bytes32 assertionId) {\n Market storage market = markets[marketId];\n require(!market.resolved, "Already resolved");\n require(market.assertedOutcomeId == bytes32(0), "Assertion pending");\n\n bytes32 outcomeId = keccak256(bytes(assertedOutcome));\n require(\n outcomeId == keccak256(bytes(market.outcome1)) ||\n outcomeId == keccak256(bytes(market.outcome2)) ||\n outcomeId == keccak256(bytes("unresolvable")),\n "Invalid outcome"\n );\n\n market.assertedOutcomeId = outcomeId;\n uint256 bond = market.requiredBond > oo.getMinimumBond(address(currency))\n ? market.requiredBond\n : oo.getMinimumBond(address(currency));\n\n currency.safeTransferFrom(msg.sender, address(this), bond);\n currency.approve(address(oo), bond + market.reward);\n\n assertionId = oo.assertTruth(\n abi.encodePacked("Outcome '", assertedOutcome, "' for: ", market.description),\n msg.sender,\n address(this),\n address(0),\n 7200,\n currency,\n bond,\n defaultIdentifier,\n bytes32(0)\n );\n\n assertionToMarket[assertionId] = marketId;\n emit MarketAsserted(marketId, assertedOutcome, assertionId);\n }\n\n // Callback when assertion resolves\n function assertionResolvedCallback(bytes32 assertionId, bool assertedTruthfully) external {\n require(msg.sender == address(oo), "Not authorized");\n bytes32 marketId = assertionToMarket[assertionId];\n Market storage market = markets[marketId];\n\n ``` -------------------------------- ### Deploy Oracle Sandbox with Foundry Source: https://context7.com/umaprotocol/uma-docs/llms.txt Deploys the Oracle Sandbox contract using Foundry, which is useful for local testing. Requires setting up environment variables beforehand. ```bash # Deploy Oracle Sandbox (for local testing) forge script script/OracleSandbox.s.sol \ --fork-url $ETH_RPC_URL \ --mnemonics "$MNEMONIC" \ --sender $DEPLOYER_WALLET \ --broadcast ``` -------------------------------- ### Set DATA Environment Variable Source: https://github.com/umaprotocol/uma-docs/blob/master/developers/optimistic-oracle-v3/data-asserter.md Set the `data` field, which is the asserted output of a command, using `cast` for bytes32 encoding. This example uses the result of the `bc` command. ```bash export DATA=$(cast --format-bytes32-string $(echo '69+420' | bc)) echo "DATA=$(echo $DATA)" ``` -------------------------------- ### Deploy Prediction Market Contract with Foundry Source: https://context7.com/umaprotocol/uma-docs/llms.txt Deploys a PredictionMarket contract using Foundry. Requires the Finder, default currency, and Oracle V3 addresses to be set. ```bash # Deploy Prediction Market export PREDICTION_MARKET=$(forge create src/PredictionMarket.sol:PredictionMarket \ --json \ --mnemonic "$MNEMONIC" \ --constructor-args $FINDER_ADDRESS $DEFAULT_CURRENCY $OOV3_ADDRESS \ | jq -r .deployedTo) ``` -------------------------------- ### Fork Goerli Testnet with Anvil Source: https://github.com/umaprotocol/uma-docs/blob/master/developers/optimistic-oracle-v3/data-asserter.md Use this command to create a local fork of the Goerli testnet. Replace 'xxx' with your Infura key. This sets up a local environment running on 127.0.0.1:8545 with pre-loaded Eth. ```bash anvil --fork-url https://goerli.infura.io/v3/xxx ``` -------------------------------- ### Get Oracle Bond Amount Source: https://github.com/umaprotocol/uma-docs/blob/master/developers/optimistic-oracle-v3/in-depth-tutorial-insurance.md Retrieve the expected oracle bond amount for a given default currency address. This value is crucial for submitting and disputing insurance claims. ```bash export BOND_AMOUNT=$(cast call $OOV3_ADDRESS \ "getMinimumBond(address)(uint256)" $DEFAULT_CURRENCY_ADDRESS) ``` -------------------------------- ### Check Token Balances with Bash Source: https://github.com/umaprotocol/uma-docs/blob/master/developers/optimistic-oracle-v3/prediction-market.md Query and display the balances of outcome tokens (one and two) and the default currency for a given wallet address. Useful for verifying token minting and allocations. ```bash echo "BALANCE OUTCOME TOKEN ONE" $(cast call $OUTCOME_TOKEN_ONE_ADDRESS \ "balanceOf(address)(uint256)" $DEPLOYER_WALLET) echo "BALANCE OUTCOME TOKEN TWO" $(cast call $OUTCOME_TOKEN_TWO_ADDRESS \ "balanceOf(address)(uint256)" $DEPLOYER_WALLET) echo "BALANCE DEFAULT_CURRENCY" $(cast call $DEFAULT_CURRENCY_ADDRESS \ "balanceOf(address)(uint256)" $DEPLOYER_WALLET) ``` -------------------------------- ### Settle Assertion and Get Result Source: https://github.com/umaprotocol/uma-docs/blob/master/developers/optimistic-oracle/in-depth-tutorial-optimistic-arbitrator.md Settles an assertion after its dispute period has expired and retrieves the result. If not disputed, the bond and fee are returned, and the result should match the proposed answer. ```javascript await (await optimisticArbitrator.connect(signer).settleAndGetResult(requestTimestamp, ancillaryData)).wait(); const result = await optimisticArbitrator.connect(signer).getResult(requestTimestamp, ancillaryData); // YES_ANSWER console.log("The assertion has been accepted :", result.eq(YES_ANSWER)); ``` -------------------------------- ### Get Mock Oracle Address Source: https://github.com/umaprotocol/uma-docs/blob/master/developers/optimistic-oracle-v3/in-depth-tutorial-insurance.md Retrieves the address of the Mock Oracle contract used for testing dispute resolution in a sandboxed UMA ecosystem. This is a prerequisite for resolving requests in a test environment. ```bash export MOCK_ORACLE_ADDRESS=$(cast call $FINDER_ADDRESS "getImplementationAddress(bytes32)(address)" $(cast --format-bytes32-string "Oracle")) ``` -------------------------------- ### Initialize Market in Prediction Market Contract Source: https://github.com/umaprotocol/uma-docs/blob/master/developers/optimistic-oracle-v3/prediction-market.md Use this function to create a new market. It requires short names for two outcomes, a description, and reward/bond amounts. Ensure the contract is deployed and optional rewards are approved. ```Solidity function initializeMarket( string memory outcome1, // Short name of the first outcome. string memory outcome2, // Short name of the second outcome. string memory description, // Description of the market. uint256 reward, // Reward available for asserting true market outcome. uint256 requiredBond // Expected bond to assert market outcome (OOv3 can require higher bond). ) public returns (bytes32 marketId) { ... } ``` -------------------------------- ### Mint and Approve Asserter Rewards with Bash Source: https://github.com/umaprotocol/uma-docs/blob/master/developers/optimistic-oracle-v3/prediction-market.md Mint the specified amount of asserter rewards and approve them for the prediction market contract using `cast send`. Requires mnemonic and addresses. ```bash cast send --mnemonic "$MNEMONIC" \ $DEFAULT_CURRENCY_ADDRESS "allocateTo(address,uint256)" $DEPLOYER_WALLET $REWARD cast send --mnemonic "$MNEMONIC" \ $DEFAULT_CURRENCY_ADDRESS "approve(address,uint256)" $PREDICTION_MARKET_ADDRESS $REWARD ``` -------------------------------- ### Get Optimistic Oracle V3 and Default Currency Addresses Source: https://github.com/umaprotocol/uma-docs/blob/master/developers/optimistic-oracle-v3/data-asserter.md Use the `cast` command to retrieve the addresses of the Optimistic Oracle V3 and its default bonding token using the Finder contract. ```bash export OOV3_ADDRESS=$(cast call $FINDER_ADDRESS "getImplementationAddress(bytes32)(address)" $(cast --format-bytes32-string "OptimisticOracleV3")) export DEFAULT_CURRENCY_ADDRESS=$(cast call $OOV3_ADDRESS "defaultCurrency()(address)") ``` -------------------------------- ### Get Oracle Price for Settlement Source: https://github.com/umaprotocol/uma-docs/blob/master/developers/optimistic-oracle/solidity-examples.md Retrieves the resolved oracle price for settlement. It first checks if a price has been resolved and then settles and retrieves the price. Handles negative prices by setting them to zero. ```solidity function _getOraclePrice(uint256 withdrawalRequestTimestamp) internal returns (uint256) { OptimisticOracleInterface oracle = _getOptimisticOracle(); require( oracle.hasPrice(address(this), priceIdentifier, withdrawalRequestTimestamp, ""), "Unresolved oracle price" ); int256 oraclePrice = oracle.settleAndGetPrice(priceIdentifier, withdrawalRequestTimestamp, ""); // For simplicity we don't want to deal with negative prices. if (oraclePrice < 0) { oraclePrice = 0; } return uint256(oraclePrice); } ``` -------------------------------- ### Get Proposer Whitelist Status Source: https://github.com/umaprotocol/uma-docs/blob/master/developers/managedoptimisticoraclev2/proposing-programmatically.md Call this function with request details to check if a whitelist is enforced and retrieve the list of allowed proposers. If enforcement is true, only addresses in the allowed list can propose. ```solidity function getProposerWhitelistWithEnforcementStatus(bytes32 _requester, bytes32 _identifier, bytes _ancillaryData) external view returns (bool isEnforced, address[] allowedProposers) ``` -------------------------------- ### Dispute Assertion via OOv3 Source: https://context7.com/umaprotocol/uma-docs/llms.txt Dispute an assertion on OOv3 before its liveness period expires. This process involves getting assertion details, approving the bond, and submitting the dispute. The assertion will then be resolved by the DVM. ```solidity // Disputing through OOv3 directly function disputeAssertion(bytes32 assertionId, address disputer) external; ``` ```bash # Get assertion details cast call $OOV3_ADDRESS "getAssertion(bytes32)" $ASSERTION_ID # Approve bond for dispute export BOND=$(cast call $OOV3_ADDRESS "getMinimumBond(address)(uint256)" $DEFAULT_CURRENCY) cast send --mnemonic "$MNEMONIC" --mnemonic-index $DISPUTER_ID \ $DEFAULT_CURRENCY "approve(address,uint256)" $OOV3_ADDRESS $BOND # Submit dispute (must be within liveness period) cast send --mnemonic "$MNEMONIC" --mnemonic-index $DISPUTER_ID \ $OOV3_ADDRESS "disputeAssertion(bytes32,address)" $ASSERTION_ID $DISPUTER_ADDRESS # If disputed, assertion goes to DVM for resolution # DVM voting takes 48-96 hours # Winners receive bond + half of loser's bond ``` -------------------------------- ### Configure Environment Variables Source: https://github.com/umaprotocol/uma-docs/blob/master/verification-guide/across.md Update the .env file by uncommenting MNEMONIC or PRIVATE_KEY and providing your credentials. Configure RPC provider URLs for various networks using your Infura API key. ```dotenv RPC_PROVIDER_ALCHEMY_1=https://eth-mainnet.g.alchemy.com/v2/{API_KEY} RPC_PROVIDER_ALCHEMY_10=https://opt-mainnet.g.alchemy.com/v2/{API_KEY} RPC_PROVIDER_ALCHEMY_137=https://polygon-mainnet.g.alchemy.com/v2/{API_KEY} RPC_PROVIDER_ALCHEMY_42161=https://arb-mainnet.g.alchemy.com/v2/{API_KEY} NODE_URL_324=https://mainnet.era.zksync.io ``` -------------------------------- ### Deploy EventBasedPredictionMarket to Görli Source: https://github.com/umaprotocol/uma-docs/blob/master/developers/optimistic-oracle/in-depth-tutorial-event-based-prediction-market.md Deploy the EventBasedPredictionMarket contract to the Görli network. Replace placeholders with your actual node URL and mnemonic. ```bash NODE_URL_5=YOUR_GOERLI_NODE MNEMONIC=YOUR_MNEMONIC yarn hardhat deploy --network goerli --tags EventBasedPredictionMarket ``` -------------------------------- ### Get Optimistic Oracle V3 Address using Cast Source: https://github.com/umaprotocol/uma-docs/blob/master/developers/optimistic-oracle-v3/in-depth-tutorial-insurance.md Uses the `cast` command to retrieve the address of the Optimistic Oracle V3 contract from the Finder contract and exports it to the OOV3_ADDRESS environment variable. ```bash export OOV3_ADDRESS=$(cast call $FINDER_ADDRESS "getImplementationAddress(bytes32)(address)" $(cast --format-bytes32-string "OptimisticOracleV3")) ``` -------------------------------- ### Dispute Insurance Claim and Get Vote Request Source: https://github.com/umaprotocol/uma-docs/blob/master/developers/optimistic-oracle/in-depth-tutorial-insurance-claims-arbitration.md Initiates a dispute for an insurance claim via the Optimistic Oracle and retrieves the vote request details from the 'PriceRequestAdded' event emitted by the Mock Oracle. ```javascript const disputeReceipt = await (await oo.connect(insurer).disputePrice( request.requester, request.identifier, request.timestamp, request.ancillaryData )).wait(); const voteRequest = (await mockOracle.queryFilter( "PriceRequestAdded", disputeReceipt.blockNumber, disputeReceipt.blockNumber ))[0].args; ``` -------------------------------- ### Run Prediction Market Tests with Forge Source: https://github.com/umaprotocol/uma-docs/blob/master/developers/optimistic-oracle-v3/prediction-market.md Execute all Prediction Market related tests using the Forge testing framework. Ensure your environment is set up with Forge. ```bash forge test --match-path *PredictionMarket* ``` -------------------------------- ### Submit Insurance Claim and Get Request Details Source: https://github.com/umaprotocol/uma-docs/blob/master/developers/optimistic-oracle/in-depth-tutorial-insurance-claims-arbitration.md Initiates an insurance claim using the policy ID and extracts the price request details from the 'RequestPrice' event emitted by the Optimistic Oracle V2. ```javascript const oo = new ethers.Contract(await insuranceArbitrator.oo(), getAbi("OptimisticOracleV2"), ethers.provider); const claimReceipt = await (await insuranceArbitrator.connect(insured).submitClaim(policyId)).wait(); const request = (await oo.queryFilter("RequestPrice", claimReceipt.blockNumber, claimReceipt.blockNumber))[0].args; ``` -------------------------------- ### Export Market Parameters with Bash Source: https://github.com/umaprotocol/uma-docs/blob/master/developers/optimistic-oracle-v3/prediction-market.md Define market parameters such as description, outcomes, reward amount, and required bond using bash exports. Ensure correct Unix timestamp for descriptions. ```bash export DESCRIPTION="The Glacial Storms beat the Electric Titans on March 8, 2023 at 3:00 PM UTC, \ which is equivalent to the Unix timestamp 1686258000 seconds." export OUTCOME_ONE="yes" export OUTCOME_TWO="no" export REWARD=$(cast --to-wei 100) export REQUIRED_BOND=$(cast --to-wei 5000) ```