-
Notifications
You must be signed in to change notification settings - Fork 465
feat: Adds Allora Network price inference to the CDP AgentKit (python) #110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
0xRAG
merged 2 commits into
coinbase:main
from
allora-network:feat/allora-network-integration
Mar 13, 2025
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Added Allora Network action provider |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
python/coinbase-agentkit/coinbase_agentkit/action_providers/allora/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
# Allora Action Provider | ||
|
||
This directory contains the **AlloraActionProvider** implementation, which enables interaction with the **Allora Network**, allowing AI agents to fetch topics and inferences for prediction markets. | ||
|
||
## Directory Structure | ||
|
||
``` | ||
allora/ | ||
├── allora_action_provider.py # Main provider with Allora functionality | ||
├── schemas.py # Pydantic schemas for action inputs | ||
├── __init__.py # Package exports | ||
└── README.md # This file | ||
|
||
# From python/coinbase-agentkit/ | ||
tests/action_providers/allora/ | ||
├── conftest.py # Test fixtures | ||
├── test_allora_action_provider.py # Tests for Allora provider | ||
``` | ||
|
||
## Actions | ||
|
||
- `get_all_topics`: Fetches all available topics from Allora Network | ||
- `get_inference_by_topic_id`: Fetches inference data for a specific topic | ||
- `get_price_inference`: Fetches price inference for a specific token and timeframe | ||
|
||
## Setup | ||
|
||
To use the Allora action provider: | ||
|
||
```python | ||
from coinbase_agentkit.action_providers.allora import allora_action_provider | ||
|
||
# With default configuration | ||
provider = allora_action_provider() | ||
|
||
# Or with custom configuration | ||
provider_with_config = allora_action_provider( | ||
api_key="your-api-key", # optional, defaults to a public, development-only key | ||
chain_slug="testnet" # optional, defaults to testnet | ||
) | ||
``` | ||
|
||
## Action Details | ||
|
||
### Get All Topics | ||
|
||
Fetches all available topics from Allora Network. Each topic represents a prediction market. | ||
|
||
Example usage: | ||
```python | ||
result = provider.get_all_topics({}) | ||
``` | ||
|
||
Example response: | ||
```json | ||
[ | ||
{ | ||
"topic_id": 1, | ||
"topic_name": "Bitcoin 8h", | ||
"description": "Bitcoin price prediction for the next 8 hours", | ||
"epoch_length": 100, | ||
"ground_truth_lag": 10, | ||
"loss_method": "method1", | ||
"worker_submission_window": 50, | ||
"worker_count": 5, | ||
"reputer_count": 3, | ||
"total_staked_allo": 1000, | ||
"total_emissions_allo": 500, | ||
"is_active": true, | ||
"updated_at": "2023-01-01T00:00:00Z" | ||
} | ||
] | ||
``` | ||
|
||
### Get Inference By Topic ID | ||
|
||
Fetches inference data for a specific topic. Requires a topic ID which can be obtained from the get_all_topics action. | ||
|
||
Example usage: | ||
```python | ||
result = provider.get_inference_by_topic_id({"topic_id": 1}) | ||
``` | ||
|
||
Example response: | ||
```json | ||
{ | ||
"network_inference": "0.5", | ||
"network_inference_normalized": "0.5", | ||
"confidence_interval_percentiles": ["0.1", "0.5", "0.9"], | ||
"confidence_interval_percentiles_normalized": ["0.1", "0.5", "0.9"], | ||
"confidence_interval_values": ["0.1", "0.5", "0.9"], | ||
"confidence_interval_values_normalized": ["0.1", "0.5", "0.9"], | ||
"topic_id": "1", | ||
"timestamp": 1718198400, | ||
"extra_data": "extra_data" | ||
} | ||
``` | ||
|
||
### Get Price Inference | ||
|
||
Fetches price inference for a specific token and timeframe. Requires a token symbol from the supported list and a timeframe. | ||
|
||
Example usage: | ||
```python | ||
from allora_sdk.v2.api_client import PriceInferenceToken, PriceInferenceTimeframe | ||
|
||
result = provider.get_price_inference({ | ||
"asset": PriceInferenceToken.BTC, | ||
"timeframe": PriceInferenceTimeframe.EIGHT_HOURS | ||
}) | ||
``` | ||
|
||
Example response: | ||
```json | ||
{ | ||
"price": "50000.00", | ||
"timestamp": 1718198400, | ||
"asset": "BTC", | ||
"timeframe": "8h" | ||
} | ||
``` | ||
|
||
## Adding New Actions | ||
|
||
To add new Allora actions: | ||
|
||
1. Define your action schema in `schemas.py`. See [Defining the input schema](https://github.com/coinbase/agentkit/blob/main/CONTRIBUTING-PYTHON.md#defining-the-input-schema) for more information. | ||
2. Implement the action in `allora_action_provider.py` | ||
3. Add tests in `tests/action_providers/allora/test_allora_action_provider.py` | ||
|
||
## Network Support | ||
|
||
The Allora provider is network-agnostic. | ||
|
||
## Notes | ||
|
||
For more information about Allora Network and its capabilities, visit [Allora Documentation](https://docs.allora.network/). |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.