Skip to content
Open
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
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ SONIC_PRIVATE_KEY=
GOAT_RPC_PROVIDER_URL=
GOAT_WALLET_PRIVATE_KEY=
SOLANA_PRIVATE_KEY=
DEBRIDGE_API_URL=
DISCORD_TOKEN=
XAI_API_KEY=
TOGETHER_API_KEY=
Expand Down
9 changes: 8 additions & 1 deletion agents/example.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,18 @@
"name": "allora",
"chain_slug": "testnet"
},
{
"name": "debridge",
"api_url": "https://dln.debridge.finance/v1.0"
},
{
"name": "ethereum",
"rpc": "https://eth.blockrazor.xyz"
},
{
"name": "evm",
"network": "ethereum"
},

{
"name": "discord",
"message_read_count": 10,
Expand Down
159 changes: 159 additions & 0 deletions src/actions/debridge_actions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
import time
from src.action_handler import register_action
from src.helpers import print_h_bar

@register_action("create_bridge_tx")
def create_bridge_transaction(agent, **kwargs):
"""Create a cross-chain bridging transaction"""
agent.logger.info("\n🌉 CREATING BRIDGE TRANSACTION")
try:
# Get the parameters from command line arguments
params = kwargs.get("params", [])
if len(params) < 6:
agent.logger.error("Not enough arguments. Expected: srcChainId srcChainTokenIn srcChainTokenInAmount dstChainId dstChainTokenOut dstChainTokenOutRecipient")
return {"status": "error", "message": "Missing required parameters"}

# Create transaction with command line parameters
result = agent.connection_manager.perform_action(
connection_name="debridge",
action_name="create_bridge_tx",
params={
"srcChainId": params[0],
"srcChainTokenIn": params[1],
"srcChainTokenInAmount": params[2],
"dstChainId": params[3],
"dstChainTokenOut": params[4],
"dstChainTokenOutRecipient": params[5]
}
)

# Store transaction data in agent state for later execution
agent.state["pending_bridge_tx"] = result

# Print transaction details
if result:
agent.logger.info("\n✅ Bridge transaction created successfully!")
agent.logger.info("\nTransaction Details:")
agent.logger.info(f"Order ID: {result['orderId']}")
agent.logger.info(f"Source: {result['estimation']['srcChainTokenIn']['amount']} {result['estimation']['srcChainTokenIn']['symbol']} (${result['estimation']['srcChainTokenIn']['approximateUsdValue']:.2f})")
agent.logger.info(f"Destination: {result['estimation']['dstChainTokenOut']['amount']} {result['estimation']['dstChainTokenOut']['symbol']} (${result['estimation']['dstChainTokenOut']['approximateUsdValue']:.2f})")
agent.logger.info(f"Slippage: {result['estimation']['recommendedSlippage']}%")
agent.logger.info(f"Expected Delay: {result['order']['approximateFulfillmentDelay']} seconds")

return {"status": "success", "tx_data": result}

except Exception as e:
agent.logger.error(f"\n❌ Failed to create bridge transaction: {str(e)}")
return {"status": "error", "message": str(e)}

@register_action("get_supported_chains")
def get_supported_chains(agent, **kwargs):
"""Get list of chains supported by deBridge for cross-chain transfers"""
agent.logger.info("\n🔗 FETCHING SUPPORTED CHAINS")
try:
result = agent.connection_manager.perform_action(
connection_name="debridge",
action_name="get_supported_chains",
params={}
)

if result and result.get("chains"):
agent.logger.info("\n✅ Retrieved supported chains successfully!")
agent.logger.info("\nSupported Chains:")
for chain in result["chains"]:
agent.logger.info(f"• {chain['chainName']} (Chain ID: {chain['chainId']})")

return {
"status": "success",
"chains": result.get("chains", []),
"message": "Retrieved supported chains"
}

except Exception as e:
agent.logger.error(f"\n❌ Failed to fetch supported chains: {str(e)}")
return {"status": "error", "message": str(e)}

@register_action("get_tokens_info")
def get_tokens_info(agent, **kwargs):
"""Get information about tokens available for cross-chain bridging via deBridge protocol"""
agent.logger.info("\n🪙 FETCHING TOKEN INFORMATION")
try:
# Get the parameters from command line arguments
params = kwargs.get("params", [])
if len(params) < 1:
agent.logger.error("Not enough arguments. Expected: chainId [search_term]")
return {"status": "error", "message": "Missing required parameters"}

# Create parameters dict
query_params = {
"chainId": params[0],
}

# Add optional search term if provided
if len(params) > 1:
query_params["search"] = params[1]

result = agent.connection_manager.perform_action(
connection_name="debridge",
action_name="get_tokens_info",
params=query_params
)

if result and result.get("tokens"):
agent.logger.info("\n✅ Retrieved token information successfully!")
agent.logger.info("\nTokens:")

# Limit output to prevent token consumption issues
token_list = list(result["tokens"].items())
display_count = min(5, len(token_list)) # Show at most 5 tokens

for address, token in token_list[:display_count]:
agent.logger.info(f"• {token['symbol']} ({token['name']}) - {address}")

if len(token_list) > display_count:
agent.logger.info(f"\n... and {len(token_list) - display_count} more tokens")

return {
"status": "success",
"tokens": result.get("tokens", {}),
"message": f"Retrieved tokens for chain {params[0]}"
}

except Exception as e:
agent.logger.error(f"\n❌ Failed to fetch token information: {str(e)}")
return {"status": "error", "message": str(e)}

@register_action("execute_bridge_tx")
def execute_bridge_transaction(agent, **kwargs):
"""Execute a previously created bridge transaction"""
agent.logger.info("\n🚀 EXECUTING BRIDGE TRANSACTION")
try:
# Get the pending transaction from agent state
pending_tx = agent.state.get("pending_bridge_tx")
if not pending_tx:
agent.logger.error("No pending bridge transaction found. Please create one first using create_bridge_tx.")
return {"status": "error", "message": "No pending bridge transaction"}

# Execute the transaction
result = agent.connection_manager.perform_action(
connection_name="debridge",
action_name="execute_bridge_tx",
params={"tx_data": pending_tx}
)

if result and result.get("signature"):
agent.logger.info("\n✅ Bridge transaction executed successfully!")
agent.logger.info(f"\nTransaction signature: {result['signature'][:10]}...")

# Clear the pending transaction from state
agent.state.pop("pending_bridge_tx", None)

return {
"status": "success",
"signature": result.get("signature"),
"message": f"Successfully executed bridge transaction. Signature: {result.get('signature', '')[:10]}..."
}

except Exception as e:
agent.logger.error(f"\n❌ Failed to execute bridge transaction: {str(e)}")
return {"status": "error", "message": str(e)}
12 changes: 12 additions & 0 deletions src/connection_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from src.connections.sonic_connection import SonicConnection
from src.connections.discord_connection import DiscordConnection
from src.connections.allora_connection import AlloraConnection
from src.connections.debridge_connection import DeBridgeConnection
from src.connections.xai_connection import XAIConnection
from src.connections.ethereum_connection import EthereumConnection
from src.connections.together_connection import TogetherAIConnection
Expand Down Expand Up @@ -63,6 +64,8 @@ def _class_name_to_type(class_name: str) -> Type[BaseConnection]:
return DiscordConnection
elif class_name == "allora":
return AlloraConnection
elif class_name == "debridge":
return DeBridgeConnection
elif class_name == "xai":
return XAIConnection
elif class_name == "ethereum":
Expand All @@ -89,6 +92,15 @@ def _register_connection(self, config_dic: Dict[str, Any]) -> None:
connection_class = self._class_name_to_type(name)
connection = connection_class(config_dic)
self.connections[name] = connection

# If this is a DeBridge connection, set its Solana connection
if name == "debridge":
solana_connection = self.connections.get("solana")
if solana_connection:
connection.set_solana_connection(solana_connection)
else:
logging.error("DeBridge requires a Solana connection. Make sure to configure it in the agent config.")

except Exception as e:
logging.error(f"Failed to initialize connection {name}: {e}")

Expand Down
Loading