The Chaos Labs Risk Oracle is a smart contract that serves as a dynamic oracle for risk parameters. It allows authorized senders to publish and update risk parameters, which can be queried by other contracts or off-chain systems.
- Authorized senders can publish risk parameter updates
- Support for different types of updates
- Bulk update functionality
- Historical tracking of parameter changes
- Query functionality for latest updates by type and market
- Owner-controlled management of authorized senders and update types
- Git
- Foundry (for development and testing)
- An Ethereum wallet with some ETH for deployment
To get started with RiskOracle, clone the repository to your local machine:
git clone https://github.com/ChaosLabsInc/risk-oracle.git
cd risk-oracle
After cloning the repository, install the necessary dependencies:
forge install
The main contract is RiskOracle.sol
, which implements the following key components:
RiskParameterUpdate
: A struct that holds details about each updatepublishRiskParameterUpdate
: Function to publish a single updatepublishBulkRiskParameterUpdates
: Function to publish multiple updates in one transactiongetUpdateById
: Function to retrieve an update by IDgetLatestUpdateByParameterAndMarket
: Function to fetch the latest update for a specific parameter and market- Access control functions for managing authorized senders and update types
-
Set up your environment variables as described in the "Setting Up Environment Variables" section above.
-
Use the provided deployment script
DeployRiskOracle.s.sol
: -
Modify the
description
,initialSenders
andinitialUpdateTypes
in the script to match your desired initial configuration. -
Compile the contracts:
forge build
-
Deploy the contract using the script:
forge script script/DeployRiskOracle.s.sol:DeployRiskOracle --rpc-url $RPC_URL --broadcast
-
After deployment, note the address of the deployed contract. You'll need this to interact with the contract.
A comprehensive test suite is provided in RiskOracleTest.t.sol
. It covers various scenarios including:
- Access control for adding/removing authorized senders
- Adding new update types
- Publishing updates
- Querying updates
To run the tests:
forge test
- Use the owner account to manage authorized senders and update types as needed.
- Authorized senders can publish updates using
publishRiskParameterUpdate
orpublishBulkRiskParameterUpdates
. - Other contracts or off-chain systems can query the latest updates using the provided getter functions.
This project uses Foundry for development and testing. Make sure you have Foundry installed and properly set up before working on this project.