# OracleKit

The OracleKit is aimed at building services providing data streams onto the blockchain. For example, The Price Oracle is an agent service that provides an estimation of the Bitcoin price (USD) based on observations coming from different data sources. In the live demo, the service is using observations from Kraken, CoinGecko, Coinbase, and Binance.

Each agent collects an observation from one of the data sources above and shares it with the rest of the agents through the consensus gadget.

Once all the observations are collected, each agent computes locally a deterministic function that aggregates the observations shared by all the agents, and obtains an estimate of the current Bitcoin price. The live demo is currently using the average of the observed values, but other functions, such as the median, can also be considered. The estimates made by all the agents are shared, and a consensus is reached when one of them obtains at least $$\lceil(2N + 1) / 3\rceil$$ votes, where $$N$$ is the number of agents in the service.

Once the consensus on an estimate has been reached, it is settled in the Polygon chain. Note that the service is secured through a multisig contract. This means that, in order to settle the Bitcoin estimate in Polygon, the agents execute a multi-signature transaction that requires at least $$\lceil(2N + 1) / 3\rceil$$ agents signatures to be accepted.

Finally, a random agent (keeper) is voted among the agents in the service to submit the transaction, and the service starts its cycle again.

## Demo

Once you have set up your system to work with the Open Autonomy framework, you can run a local demo of the Price Oracle with a Hardhat node as follows:

1. Fetch the Price Oracle service (Hardhat flavour).

autonomy fetch valory/oracle_hardhat:0.1.0:bafybeiepp7cw5nfscuaa7wuj3zzfqyrfvww7ubpjc6eolyybordihew6j4 --service

2. Build the Docker image of the service agents

cd oracle_hardhat
autonomy build-image

3. Prepare the keys.json file containing the wallet address and the private key for each of the agents.

Example of a keys.json file

WARNING: Use this file for testing purposes only. Never use the keys or addresses provided in this example in a production environment or for personal use.

[
{
"private_key": "0x47e179ec197488593b187f80a00eb0da91f1b9d0b13f8733639f19c30a34926a"
},
{
"private_key": "0x8b3a350cf5c34c9194ca85829a2df0ec3153be0318b5e2d3348e872092edffba"
},
{
"private_key": "0x92db14e403b83dfe3df233f83dfa3a0d7096f21ca9b0d6d6b8d88b2b4ec1564e"
},
{
"private_key": "0x4bbbf85ce3377467afe5d46f804f221813b2bb87f24d81f60f1fcdbf7cbf4356"
}
]

4. Build the service deployment.

autonomy deploy build keys.json --aev

5. Run the service.

1. In a separate terminal, run a Hardhat node. We provide a pre-configured Docker image for testing.

docker run -p 8545:8545 -it valory/open-autonomy-hardhat:0.1.0

2. Once the Hardhat node is up and running, run the service deployment.

cd abci_build
autonomy deploy run


You can cancel the local execution at any time by pressing Ctrl+C.

## Build

1. Fork the OracleKit repository.
2. Make the necessary adjustments to tailor the service to your needs. This could include:
• Adjust configuration parameters (e.g., in the service.yaml file).
• Expand the service finite-state machine with your custom states.