Skip to content

Commit

Permalink
Rebase master
Browse files Browse the repository at this point in the history
  • Loading branch information
fernandofcampos committed Jan 23, 2025
1 parent 6c31561 commit 838c2f1
Show file tree
Hide file tree
Showing 16 changed files with 330 additions and 1,426 deletions.

This file was deleted.

2 changes: 1 addition & 1 deletion cdp-agentkit-core/python/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
### Added

- Added `wrap_eth` action to wrap ETH to WETH on Base.
- Added support for Allora Chain machine learning (`get_price_prediction` and `get_all_topics` actions).
- Added support for Allora Chain machine learning (`get_price_inference` and `get_all_topics` actions).

## [0.0.7] - 2025-01-08

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from cdp_agentkit_core.actions.allora.get_all_topics import GetAllTopicsAction
from cdp_agentkit_core.actions.allora.get_price_inference import GetPriceInferenceAction
from cdp_agentkit_core.actions.cdp_action import CdpAction
from cdp_agentkit_core.actions.deploy_nft import DeployNftAction
from cdp_agentkit_core.actions.deploy_token import DeployTokenAction
Expand Down Expand Up @@ -54,4 +56,6 @@ def get_all_cdp_actions() -> list[type[CdpAction]]:
"MorphoWithdrawAction",
"PythFetchPriceFeedIDAction",
"PythFetchPriceAction",
"GetPriceInferenceAction",
"GetAllTopicsAction",
]
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from cdp_agentkit_core.actions.allora.action import AlloraAction
from cdp_agentkit_core.actions.allora.get_all_topics import GetAllTopicsAction
from cdp_agentkit_core.actions.allora.get_price_prediction import GetPricePredictionAction
from cdp_agentkit_core.actions.allora.get_price_inference import GetPriceInferenceAction


def get_all_allora_actions() -> list[type[AlloraAction]]:
Expand All @@ -15,6 +15,6 @@ def get_all_allora_actions() -> list[type[AlloraAction]]:

__all__ = [
"ALLORA_ACTIONS",
"GetPricePredictionAction",
"GetPriceInferenceAction",
"GetAllTopicsAction",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from collections.abc import Callable

from allora_sdk.v2.api_client import AlloraAPIClient
from pydantic import BaseModel, Field

from cdp_agentkit_core.actions.allora.action import AlloraAction

GET_PRICE_INFERENCE_PROMPT = """
This tool will get the future price inference for a given crypto asset from Allora Network.
It takes the crypto asset and timeframe as inputs.
"""


class GetPriceInferenceInput(BaseModel):
"""Input argument schema for get price inference action."""

token: str = Field(
..., description="The crypto asset to get the price inference for, e.g. `BTC`"
)
timeframe: str = Field(
..., description="The timeframe to get the price inference for, e.g. `5m` or `8h`"
)


async def get_price_inference(client: AlloraAPIClient, token: str, timeframe: str) -> str:
"""Get the future price inference for a given crypto asset from Allora Network.
Args:
client (AlloraAPIClient): The Allora API client.
token (str): The crypto asset to get the price inference for, e.g. `BTC`
timeframe (str): The timeframe to get the price inference for, e.g. `5m` or `8h`
Returns:
str: The future price inference for the given crypto asset
"""
try:
price_inference = await client.get_price_inference(token, timeframe)
return f"The future price inference for {token} in {timeframe} is {price_inference.inference_data.network_inference_normalized}"
except Exception as e:
return f"Error getting price inference: {e}"


class GetPriceInferenceAction(AlloraAction):
"""Get price inference action."""

name: str = "get_price_inference"
description: str = GET_PRICE_INFERENCE_PROMPT
args_schema: type[BaseModel] | None = GetPriceInferenceInput
func: Callable[..., str] = get_price_inference
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,15 @@
class MorphoDepositInput(BaseModel):
"""Input schema for Morpho Vault deposit action."""

assets: str = Field(
...,
description="The quantity of assets to deposit, in whole units"
)
assets: str = Field(..., description="The quantity of assets to deposit, in whole units")
receiver: str = Field(
...,
description="The address that will own the position on the vault which will receive the shares"
description="The address that will own the position on the vault which will receive the shares",
)
token_address: str = Field(
...,
description="The address of the assets token to approve for deposit"
)
vault_address: str = Field(
...,
description="The address of the Morpho Vault to deposit to"
..., description="The address of the assets token to approve for deposit"
)
vault_address: str = Field(..., description="The address of the Morpho Vault to deposit to")


DEPOSIT_PROMPT = """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,9 @@
class MorphoWithdrawInput(BaseModel):
"""Input schema for Morpho Vault withdraw action."""

vault_address: str = Field(
...,
description="The address of the Morpho Vault to withdraw from"
)
assets: str = Field(
...,
description="The amount of assets to withdraw in atomic units"
)
receiver: str = Field(
...,
description="The address to receive the withdrawn assets"
)
vault_address: str = Field(..., description="The address of the Morpho Vault to withdraw from")
assets: str = Field(..., description="The amount of assets to withdraw in atomic units")
receiver: str = Field(..., description="The address to receive the withdrawn assets")


WITHDRAW_PROMPT = """
Expand Down
8 changes: 4 additions & 4 deletions cdp-agentkit-core/python/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cdp-agentkit-core/python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ python = "^3.10"
cdp-sdk = "^0.14.1"
pydantic = "^2.0"
web3 = "^7.6.0"
allora-sdk = "^0.1.0"
allora-sdk = "^0.2.0"
pytest-asyncio = "^0.25.2"

[tool.poetry.group.dev.dependencies]
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
from unittest.mock import AsyncMock, Mock, patch

import pytest

from cdp_agentkit_core.actions.allora.get_price_inference import (
GetPriceInferenceInput,
get_price_inference,
)

MOCK_TOKEN = "BTC"
MOCK_TIMEFRAME = "5m"


def test_get_price_inference_input_model_valid():
"""Test that GetPriceInferenceInput accepts valid parameters."""
input_model = GetPriceInferenceInput(
token=MOCK_TOKEN,
timeframe=MOCK_TIMEFRAME,
)

assert input_model.token == MOCK_TOKEN
assert input_model.timeframe == MOCK_TIMEFRAME


def test_get_price_inference_input_model_missing_params():
"""Test that GetPriceInferenceInput raises error when params are missing."""
with pytest.raises(ValueError):
GetPriceInferenceInput()


@pytest.mark.asyncio
async def test_get_price_inference_success():
"""Test successful price inference with valid parameters."""
mock_inference = Mock()
mock_inference.inference_data.network_inference_normalized = "50000.00"

with patch(
"cdp_agentkit_core.actions.allora.get_price_inference.AlloraAPIClient"
) as mock_client:
mock_client_instance = mock_client.return_value
mock_client_instance.get_price_inference = AsyncMock(return_value=mock_inference)

result = await get_price_inference(mock_client_instance, MOCK_TOKEN, MOCK_TIMEFRAME)

expected_response = (
f"The future price inference for {MOCK_TOKEN} in {MOCK_TIMEFRAME} is 50000.00"
)
assert result == expected_response

mock_client_instance.get_price_inference.assert_called_once_with(MOCK_TOKEN, MOCK_TIMEFRAME)


@pytest.mark.asyncio
async def test_get_price_inference_api_error():
"""Test price inference when API error occurs."""
with patch(
"cdp_agentkit_core.actions.allora.get_price_inference.AlloraAPIClient"
) as mock_client:
mock_client_instance = mock_client.return_value
mock_client_instance.get_price_inference.side_effect = Exception("API error")

result = await get_price_inference(mock_client_instance, MOCK_TOKEN, MOCK_TIMEFRAME)

expected_response = "Error getting price inference: API error"
assert result == expected_response

mock_client_instance.get_price_inference.assert_called_once_with(MOCK_TOKEN, MOCK_TIMEFRAME)

This file was deleted.

Loading

0 comments on commit 838c2f1

Please sign in to comment.