How openOracle works
The way openOracle works is with token commitments. If you wanted the price of ETH/USDC, you would pay a reporter to post some amount of ETH and some amount of USDC. For example, let’s say Bob the reporter locks up 1 ETH and 3000 USDC, and in doing so earns 0.01 ETH as a reward. Bob’s tokens are locked in the openOracle contract for a period of time, say 10 minutes. Over this entire 10-minute period, anyone has the option to swap 3000 USDC for Bob’s 1 ETH, or 1 ETH for Bob’s 3000 USDC. If Bob didn’t put up the correct amount of ETH and USDC, he would lose money to swappers. Let’s say the true price of 1 ETH is 4000 USDC, and Alice comes along and chooses to swap 3000 USDC for 1 of Bob’s ETH. Alice has made $1000 from Bob! But, in openOracle, in order for Alice to swap against Bob’s tokens, she must herself become the next reporter at the same time. Alice must now put up 50% more tokens: 1.5 ETH and her choice of USDC. Since the price of ETH is $4000, Alice puts up 6000 USDC, since she doesn’t want to lose money to swaps like Bob did. The 10 minute timer restarts and over this period, anyone can swap 1.5 ETH for 6000 of Alice’s USDC, or swap 6000 USDC for 1.5 of Alice’s ETH. If nobody swaps against Alice’s tokens for 10 minutes, the price is considered finalized and applications can use it. The final price comes from the ratio of token balances of the last reporter: 6000 USDC and 1.5 ETH implies 1 ETH is worth 4000 USDC. If someone wants to come swap against Alice, they must themselves put up 50% more ETH and USDC and the game repeats. We call this the oracle game.Smart contract flows
Here we will walk through how the smart contract’s flows work across three scenarios: a price reported too low, too high, and way too high.Bob reports an ETH price too low
We can use the previous example. First, Bob puts 1 ETH and 3000 USDC into the contract, earning a 0.01 ETH reward for being the first reporter. Contract balances: 1 ETH and 3000 USDC Next, since the true value of 1 ETH is 4000 USDC, Alice comes along and decides to swap 3000 of her USDC for 1 of Bob’s ETH, earning ~$1000 in the process. Bob receives the 3000 USDC he already put in the contract back and 3000 USDC from Alice, for a total of 6000 USDC. Alice receives 1 ETH in exchange for her 3000 USDC. Next, by openOracle contract rule, Alice must become the next reporter at the same time she swaps. Since the multiplier is 1.5x, Alice must put up 1.5 ETH and her choice of USDC. Since 1 ETH is 4000 USDC, she chooses to put up 6000 USDC. Contract balances: 1.5 ETH and 6000 USDC. Since we do the swap and report in a single step, we net out the flows: Alice only needs to transfer 0.5 ETH (since previous balance was 1 ETH) into the contract. She also must transfer 9000 USDC: 3000 USDC to Bob and 6000 USDC to match her 1.5 ETH. Once the game ends in 10 minutes, assuming nobody swapped against Alice, she gets 1.5 ETH and 6000 USDC back.Bob reports an ETH price too high
Let’s say Bob put 1 ETH and 5000 USDC into the contract when the true value of 1 ETH is 4000 USDC. Contract balances: 1 ETH and 5000 USDC Alice would now choose to swap 1 of her ETH for 5000 of Bob’s USDC, earning ~$1000 in the process. Bob receives the 1 ETH he already put in the contract back and 1 ETH from Alice, for a total of 2 ETH. Alice receives 5000 USDC in exchange for her 1 ETH. By openOracle contract rule, Alice must become the next reporter at the same time she swaps. Since the multiplier is 1.5x, Alice must put up 1.5 ETH and her choice of USDC. Since 1 ETH is 4000 USDC, she chooses to put up 6000 USDC. Contract balances: 1.5 ETH and 6000 USDC. We net out the flows: Alice only needs to transfer 1000 USDC (since previous balance was 5000 USDC) into the contract. She also must transfer 2.5 ETH: 1 ETH to Bob and 1.5 ETH to the oracle contract (multiplier of 1.5x). Once the game ends in 10 minutes, assuming nobody swapped against Alice, she gets 1.5 ETH and 6000 USDC back.Bob reports an ETH price way too high
Let’s say Bob put 1 ETH and 10000 USDC into the contract when the true value of 1 ETH is 4000 USDC. Contract balances: 1 ETH and 10000 USDC Alice would now choose to swap 1 of her ETH for 10000 of Bob’s USDC, earning ~$6000 in the process. Bob receives the 1 ETH he already put in the contract back and 1 ETH from Alice, for a total of 2 ETH. Alice receives 10000 USDC in exchange for her 1 ETH. By openOracle contract rule, Alice must become the next reporter at the same time she swaps. Since the multiplier is 1.5x, Alice must put up 1.5 ETH and her choice of USDC. Since 1 ETH is 4000 USDC, she chooses to put up 6000 USDC. Contract balances: 1.5 ETH and 6000 USDC. When we net out the flows here, Alice doesn’t need to transfer any USDC. In fact, she receives an immediate USDC refund from the oracle contract of 4000 USDC since there was already 10000 USDC there and she chose 6000 USDC to go along with her 1.5 ETH requirement. While Alice receives an immediate 4000 USDC refund, she still must transfer 2.5 ETH: 1 ETH to Bob and 1.5 ETH to the oracle contract. Once the game ends in 10 minutes, assuming nobody swapped against Alice, she receives 1.5 ETH and 6000 USDC.Game parameters
The examples above use specific values to illustrate the mechanics. In practice, these are configurable parameters set at the time of the price request:- Initial liquidity — The starting size of the token commitments. Bob’s 1 ETH in the examples above. Bob gets to choose how much USDC to pair with the 1 ETH.
- Settlement time — How long the tokens are locked before the price is finalized. 10 minutes in the examples above.
- Multiplier — How much larger each subsequent reporter’s commitments must be. 1.5x in the examples above.
- Initial reporter reward — The payment earned by the first reporter for locking up capital and bearing risk. 0.01 ETH in the examples above.