Skip to content

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
merged 2 commits into from
Mar 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion python/coinbase-agentkit/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ local-docs: docs

.PHONY: test
test:
poetry run pytest
poetry run pytest -m "not integration"

.PHONY: test-integration
test-integration:
poetry run pytest -m integration

.PHONY: generate-action-provider
generate-action-provider:
Expand Down
1 change: 1 addition & 0 deletions python/coinbase-agentkit/changelog.d/110.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added Allora Network action provider
2 changes: 2 additions & 0 deletions python/coinbase-agentkit/coinbase_agentkit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from .action_providers import (
Action,
ActionProvider,
allora_action_provider,
basename_action_provider,
cdp_api_action_provider,
cdp_wallet_action_provider,
Expand Down Expand Up @@ -56,5 +57,6 @@
"wallet_action_provider",
"weth_action_provider",
"wow_action_provider",
"allora_action_provider",
"__version__",
]
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from .action_decorator import create_action
from .action_provider import Action, ActionProvider
from .allora.allora_action_provider import AlloraActionProvider, allora_action_provider
from .basename.basename_action_provider import (
BasenameActionProvider,
basename_action_provider,
Expand Down Expand Up @@ -49,4 +50,6 @@
"weth_action_provider",
"WowActionProvider",
"wow_action_provider",
"AlloraActionProvider",
"allora_action_provider",
]
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/).
Loading