Skip to content

Commit

Permalink
chore: update tweepy
Browse files Browse the repository at this point in the history
  • Loading branch information
hyacinthus committed Jan 17, 2025
1 parent 36bca18 commit 29f4113
Show file tree
Hide file tree
Showing 6 changed files with 251 additions and 113 deletions.
16 changes: 8 additions & 8 deletions 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 pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ openai = "^1.59.6"
cdp-langchain = "^0.0.9"
cdp-sdk = "^0.13.0"
cdp-agentkit-core = "^0.0.7"
tweepy = "^4.14.0"
tweepy = "^4.15.0"
python-dotenv = "^1.0.1"
APScheduler = "^3.11.0"
anyio = "^4.8.0"
Expand Down
31 changes: 24 additions & 7 deletions skills/enso/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Enso skills."""

from abstracts.skill import SkillStoreABC
from skills.enso.base import EnsoBaseTool
from skills.enso.prices import EnsoGetPrices
Expand All @@ -12,23 +13,39 @@


def get_enso_skill(
name: str, api_token: str, main_tokens: list[str], store: SkillStoreABC, agent_id: str
name: str,
api_token: str,
main_tokens: list[str],
store: SkillStoreABC,
agent_id: str,
) -> EnsoBaseTool:
if not api_token:
raise ValueError("Enso API token is empty")

if name == "get_tokens":
return EnsoGetTokens(api_token=api_token, main_tokens=main_tokens, store=store, agent_id=agent_id)
return EnsoGetTokens(
api_token=api_token, main_tokens=main_tokens, store=store, agent_id=agent_id
)
if name == "get_route_shortcut":
return EnsoGetRouteShortcut(api_token=api_token, main_tokens=main_tokens, store=store, agent_id=agent_id)
return EnsoGetRouteShortcut(
api_token=api_token, main_tokens=main_tokens, store=store, agent_id=agent_id
)
if name == "get_wallet_approve":
return EnsoGetWalletApprove(api_token=api_token, main_tokens=main_tokens, store=store, agent_id=agent_id)
return EnsoGetWalletApprove(
api_token=api_token, main_tokens=main_tokens, store=store, agent_id=agent_id
)
if name == "get_wallet_approvals":
return EnsoGetWalletApprovals(api_token=api_token, main_tokens=main_tokens, store=store, agent_id=agent_id)
return EnsoGetWalletApprovals(
api_token=api_token, main_tokens=main_tokens, store=store, agent_id=agent_id
)
if name == "get_wallet_balances":
return EnsoGetWalletBalances(api_token=api_token, main_tokens=main_tokens, store=store, agent_id=agent_id)
return EnsoGetWalletBalances(
api_token=api_token, main_tokens=main_tokens, store=store, agent_id=agent_id
)
if name == "get_prices":
return EnsoGetPrices(api_token=api_token, main_tokens=main_tokens, store=store, agent_id=agent_id)
return EnsoGetPrices(
api_token=api_token, main_tokens=main_tokens, store=store, agent_id=agent_id
)

else:
raise ValueError(f"Unknown Enso skill: {name}")
29 changes: 20 additions & 9 deletions skills/enso/prices.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@

class EnsoGetPricesInput(BaseModel):
chainId: int = Field(1, description="Blockchain chain ID of the token")
address: str = Field("0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", description="Contract address of the token")
address: str = Field(
"0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",
description="Contract address of the token",
)


class PriceInfo(BaseModel):
Expand All @@ -21,8 +24,12 @@ class PriceInfo(BaseModel):


class EnsoGetPricesOutput(BaseModel):
res: PriceInfo | None = Field(None, description="Price information of the requested token")
error: str | None = Field(None, description="Error message if price retrieval fails")
res: PriceInfo | None = Field(
None, description="Price information of the requested token"
)
error: str | None = Field(
None, description="Error message if price retrieval fails"
)


class EnsoGetPrices(EnsoBaseTool):
Expand All @@ -39,9 +46,11 @@ class EnsoGetPrices(EnsoBaseTool):
description: str = "Retrieve the price of a token by chain ID and contract address"
args_schema: Type[BaseModel] = EnsoGetPricesInput

def _run(self,
chainId: int = 1,
address: str = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee") -> EnsoGetPricesOutput:
def _run(
self,
chainId: int = 1,
address: str = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",
) -> EnsoGetPricesOutput:
"""
Asynchronous function to request the token price from the API.
Expand Down Expand Up @@ -77,9 +86,11 @@ def _run(self,
except Exception as e:
return EnsoGetPricesOutput(res=None, error=str(e))

async def _arun(self,
chainId: int = 1,
address: str = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee") -> EnsoGetPricesOutput:
async def _arun(
self,
chainId: int = 1,
address: str = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",
) -> EnsoGetPricesOutput:
"""Async implementation of the tool.
This tool doesn't have a native async implementation, so we call the sync version.
Expand Down
140 changes: 92 additions & 48 deletions skills/enso/route.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ class EnsoGetRouteShortcutInput(BaseModel):
fromAddress: str = Field(
description="Ethereum address of the wallet to send the transaction from (It could be an EoA, or a Smart Wallet)."
)
amountIn: list[int] = Field(
description="Amount of tokenIn to swap in wei."
)
amountIn: list[int] = Field(description="Amount of tokenIn to swap in wei.")
tokenIn: list[str] = Field(
description="Ethereum address of the token to swap or enter into a position from (For ETH, use 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee)."
)
Expand All @@ -22,89 +20,105 @@ class EnsoGetRouteShortcutInput(BaseModel):
)
chainId: int | None = Field(
1,
description="(Optional) Chain ID of the network to execute the transaction on."
description="(Optional) Chain ID of the network to execute the transaction on.",
)
routingStrategy: Literal["router", "delegate", "ensowallet", None] = Field(
None,
description="(Optional) Routing strategy to use. Options: 'ensowallet', 'router', 'delegate'."
description="(Optional) Routing strategy to use. Options: 'ensowallet', 'router', 'delegate'.",
)
receiver: str | None = Field(
None,
description="(Optional) Ethereum address of the receiver of the tokenOut."
None, description="(Optional) Ethereum address of the receiver of the tokenOut."
)
spender: str | None = Field(
None,
description="(Optional) Ethereum address of the spender of the tokenIn."
None, description="(Optional) Ethereum address of the spender of the tokenIn."
)
amountOut: list[str] | None = Field(
None,
description="(Optional) Amount of tokenOut to receive."
None, description="(Optional) Amount of tokenOut to receive."
)
minAmountOut: list[str] | None = Field(
None,
description="(Optional) Minimum amount out in wei. If specified, slippage should not be specified."
description="(Optional) Minimum amount out in wei. If specified, slippage should not be specified.",
)
slippage: str | None = Field(
None,
description="(Optional) Slippage in basis points (1/10000). If specified, minAmountOut should not be specified."
description="(Optional) Slippage in basis points (1/10000). If specified, minAmountOut should not be specified.",
)
fee: list[str] | None = Field(
None,
description="(Optional) Fee in basis points (1/10000) for each amountIn value."
description="(Optional) Fee in basis points (1/10000) for each amountIn value.",
)
feeReceiver: str | None = Field(
None,
description="(Optional) Ethereum address that will receive the collected fee if fee was provided."
description="(Optional) Ethereum address that will receive the collected fee if fee was provided.",
)
disableRFQs: bool | None = Field(
None,
description="(Optional) Exclude RFQ sources from routes."
None, description="(Optional) Exclude RFQ sources from routes."
)
ignoreAggregators: list[str] | None = Field(
None,
description="(Optional) List of swap aggregators to ignore."
None, description="(Optional) List of swap aggregators to ignore."
)
ignoreStandards: list[str] | None = Field(
None,
description="(Optional) List of standards to ignore."
None, description="(Optional) List of standards to ignore."
)
variableEstimates: dict | None = Field(
None,
description="Variable estimates for the route."
None, description="Variable estimates for the route."
)


class Transaction(BaseModel):
data: str = Field(None, description="Data of the transaction.")
to: str = Field(None, description="Ethereum address of the receiver of the transaction.")
from_: str = Field(None, description="Ethereum address of the sender of the transaction.")
to: str = Field(
None, description="Ethereum address of the receiver of the transaction."
)
from_: str = Field(
None, description="Ethereum address of the sender of the transaction."
)
value: str = Field(None, description="Amount of token to send.")


class Route(BaseModel):
tokenIn: list[str] | None = Field(
None, description="Ethereum address of the token to swap or enter into a position from."
None,
description="Ethereum address of the token to swap or enter into a position from.",
)
tokenOut: list[str] | None = Field(
None, description="Ethereum address of the token to swap or enter into a position to."
None,
description="Ethereum address of the token to swap or enter into a position to.",
)
protocol: str | None = Field(None, description="Protocol used for finding route.")
action: str | None = Field(None, description="Action has been done for route (e.g. swap).")
internalRoutes: list[str] | None = Field(None, description="Internal routes needed for the route.")
action: str | None = Field(
None, description="Action has been done for route (e.g. swap)."
)
internalRoutes: list[str] | None = Field(
None, description="Internal routes needed for the route."
)


class RouteShortcutGetTransaction(BaseModel):
"""
Output schema for the `/api/v1/shortcuts/route` GET endpoint.
"""

gas: str | None = Field(None, description="Gas amount for the transaction.")
amountOut: str | dict | None = Field(None, description="The final calculated amountOut as an object.")
priceImpact: float | None = Field(None,
description="Price impact in basis points, it is null if USD price is not found.")
feeAmount: list[str] | None = Field(None, description="An array of the fee amounts collected for each tokenIn.")
createdAt: int | None = Field(None, description="Block number the transaction was created on.")
tx: Transaction | None = Field(None, description="The tx object to use in `ethers`.")
route: list[Route] | None = Field(None, description="Route that the shortcut will use.")
amountOut: str | dict | None = Field(
None, description="The final calculated amountOut as an object."
)
priceImpact: float | None = Field(
None,
description="Price impact in basis points, it is null if USD price is not found.",
)
feeAmount: list[str] | None = Field(
None, description="An array of the fee amounts collected for each tokenIn."
)
createdAt: int | None = Field(
None, description="Block number the transaction was created on."
)
tx: Transaction | None = Field(
None, description="The tx object to use in `ethers`."
)
route: list[Route] | None = Field(
None, description="Route that the shortcut will use."
)


class EnsoGetRouteShortcutOutput(BaseModel):
Expand All @@ -128,8 +142,14 @@ class EnsoGetRouteShortcut(EnsoBaseTool):
description: str = "This tool optimizes DeFi swaps, identifying the most efficient execution path across various protocols (e.g., liquidity pools, lending platforms) by considering factors like return rates, gas costs, and slippage."
args_schema: Type[BaseModel] = EnsoGetRouteShortcutInput

def _run(self, fromAddress: str, amountIn: list[int], tokenIn: list[str], tokenOut: list[str],
**kwargs) -> EnsoGetRouteShortcutOutput:
def _run(
self,
fromAddress: str,
amountIn: list[int],
tokenIn: list[str],
tokenOut: list[str],
**kwargs,
) -> EnsoGetRouteShortcutOutput:
"""
Run the tool to get swap route information.
Expand All @@ -150,32 +170,56 @@ def _run(self, fromAddress: str, amountIn: list[int], tokenIn: list[str], tokenO
}

# Prepare query parameters
params = EnsoGetRouteShortcutInput(fromAddress=fromAddress, amountIn=amountIn, tokenIn=tokenIn,
tokenOut=tokenOut, **kwargs)
params = EnsoGetRouteShortcutInput(
fromAddress=fromAddress,
amountIn=amountIn,
tokenIn=tokenIn,
tokenOut=tokenOut,
**kwargs,
)

if params.fromAddress == "0xYourWalletAddress":
raise ToolException("the ethereum from address is required")

with httpx.Client() as client:
try:
response = client.get(url, headers=headers, params=params.model_dump(exclude_none=True))
response = client.get(
url, headers=headers, params=params.model_dump(exclude_none=True)
)
response.raise_for_status() # Raise HTTPError for non-2xx responses

# Parse and return the response as a RouteShortcutGetTransaction object
return EnsoGetRouteShortcutOutput(res=RouteShortcutGetTransaction(**response.json()), error=None)
return EnsoGetRouteShortcutOutput(
res=RouteShortcutGetTransaction(**response.json()), error=None
)

except httpx.RequestError as req_err:
return EnsoGetRouteShortcutOutput(res=None, error=f"Request error: {req_err}")
return EnsoGetRouteShortcutOutput(
res=None, error=f"Request error: {req_err}"
)
except httpx.HTTPStatusError as http_err:
return EnsoGetRouteShortcutOutput(res=None, error=f"HTTP error: {http_err}")
return EnsoGetRouteShortcutOutput(
res=None, error=f"HTTP error: {http_err}"
)
except Exception as e:
return EnsoGetRouteShortcutOutput(res=None, error=str(e))

async def _arun(self, fromAddress: str, amountIn: list[int], tokenIn: list[str], tokenOut: list[str],
**kwargs) -> EnsoGetRouteShortcutOutput:
async def _arun(
self,
fromAddress: str,
amountIn: list[int],
tokenIn: list[str],
tokenOut: list[str],
**kwargs,
) -> EnsoGetRouteShortcutOutput:
"""Async implementation of the tool.
This tool doesn't have a native async implementation, so we call the sync version.
"""
return self._run(fromAddress=fromAddress, amountIn=amountIn, tokenIn=tokenIn,
tokenOut=tokenOut, **kwargs)
return self._run(
fromAddress=fromAddress,
amountIn=amountIn,
tokenIn=tokenIn,
tokenOut=tokenOut,
**kwargs,
)
Loading

0 comments on commit 29f4113

Please sign in to comment.