Skip to content
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

Add manual test for swap #40

Merged
merged 4 commits into from
Feb 5, 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
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ TELEGRAM_CHAT_ID=your_chat_id

# Wallet Configuration (Required for trading)
ETH_WALLET_ADDRESS=your_ethereum_wallet_address
ETH_SEPOLIA_WALLET_ADDRESS=your_ethereum_sepolia_wallet_address
BASE_WALLET_ADDRESS=your_base_wallet_address
SOL_WALLET_ADDRESS=your_solana_wallet_address

# Private Keys (Required for trading - BE VERY CAREFUL!)
# These keys have full control over your wallets. Never share them!
ETH_PRIVATE_KEY=your_ethereum_private_key
ETH_SEPOLIA_PRIVATE_KEY=your_ethereum_sepolia_private_key
BASE_PRIVATE_KEY=your_base_private_key
SOL_PRIVATE_KEY=your_solana_private_key

Expand Down
9 changes: 6 additions & 3 deletions config/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ chain_config:

ethereum_sepolia:
wallet_address:
fromEnvVar: ETH_WALLET_ADDRESS
fromEnvVar: ETH_SEPOLIA_WALLET_ADDRESS
private_key:
fromEnvVar: ETH_PRIVATE_KEY
fromEnvVar: ETH_SEPOLIA_PRIVATE_KEY
gas_settings:
max_priority_fee: 10000000000 # 10 gwei, currently not used
gas_limit: 300000
Expand All @@ -91,7 +91,10 @@ chain_config:
USDC:
address: "0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238"
decimals: 6

EURC:
address: "0x08210F9170F89Ab7658F0B5E3fF39b0E03C594D4"
decimals: 6

base:
wallet_address:
fromEnvVar: BASE_WALLET_ADDRESS
Expand Down
3 changes: 2 additions & 1 deletion examples/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from alphaswarm.agent.clients import TerminalClient
from alphaswarm.config import CONFIG_PATH, Config
from alphaswarm.tools.alchemy import AlchemyPriceHistoryByAddress, AlchemyPriceHistoryBySymbol
from alphaswarm.tools.exchanges import GetTokenPriceTool
from alphaswarm.tools.exchanges import ExecuteTokenSwapTool, GetTokenPriceTool
from alphaswarm.tools.price_tool import PriceTool
from alphaswarm.tools.strategy_analysis.generic import GenericStrategyAnalysisTool
from alphaswarm.tools.strategy_analysis.strategy import Strategy
Expand All @@ -33,6 +33,7 @@ async def main() -> None:
AlchemyPriceHistoryBySymbol(),
GenericStrategyAnalysisTool(strategy=strategy),
SendTelegramNotificationTool(telegram_bot_token=telegram_bot_token, chat_id=chat_id),
ExecuteTokenSwapTool(config),
] # Add your tools here

# Optional step to provide a custom system prompt.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from decimal import Decimal

import pytest

from alphaswarm.config import Config
Expand All @@ -16,6 +18,11 @@ def eth_client(default_config: Config) -> UniswapClientV3:
return UniswapClientV3(default_config, chain="ethereum")


@pytest.fixture
def eth_sepolia_client(default_config: Config) -> UniswapClientV3:
return UniswapClientV3(default_config, chain="ethereum_sepolia")


def test_get_price(base_client: UniswapClientV3) -> None:
token0 = base_client.chain_config.get_token_info("USDC")
token1 = base_client.chain_config.get_token_info("WETH")
Expand Down Expand Up @@ -79,10 +86,17 @@ def test_get_markets_for_tokens(eth_client: UniswapClientV3) -> None:
assert quote_token.chain == eth_client.chain


# TO DO make this a unit test with mocks
# def test_swap(base_client: UniswapClientV3) -> None:
# usdc = base_client.chain_config.get_token_info("USDC")
# weth = base_client.chain_config.get_token_info("WETH")
#
# # Buy X USDC for 1 Weth
# result = base_client.swap(usdc, weth, Decimal(1))
@pytest.mark.skip("Needs a wallet with USDC to perform the swap to WETH. Run manually")
def test_swap_eth_sepolia(eth_sepolia_client: UniswapClientV3) -> None:
usdc = eth_sepolia_client.chain_config.get_token_info("USDC")
weth = eth_sepolia_client.chain_config.get_token_info("WETH")

pool = eth_sepolia_client._get_pool(usdc, weth)
print(f"find pool {pool.address}")

quote = eth_sepolia_client._get_token_price_from_pool(quote_token=usdc, pool_details=pool)
print(f"1 {weth.symbol} is {quote} {usdc.symbol}")

# Buy X Weth for 1 USDC
result = eth_sepolia_client.swap(weth, usdc, Decimal(1))
print(result)
17 changes: 17 additions & 0 deletions tests/integration/tools/exchanges/test_execute_token_swap_tool.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from decimal import Decimal

import pytest

from alphaswarm.config import Config
from alphaswarm.tools.exchanges import ExecuteTokenSwapTool


@pytest.fixture
def token_swap_tool(default_config: Config) -> ExecuteTokenSwapTool:
return ExecuteTokenSwapTool(default_config)


@pytest.mark.skip("Requires a founded wallet. Run manually")
def test_token_swap_tool(token_swap_tool: ExecuteTokenSwapTool) -> None:
result = token_swap_tool.forward("WETH", "USDC", Decimal(1), "ethereum_sepolia")
print(result)