Use deBridge

The Use deBridge tool, part of AgentiPy, enables users to perform cross-chain swaps and interact with the deBridge protocol. It allows for creating and executing transactions that bridge assets between different blockchains supported by deBridge, using their Liquidity Network API.

Functionality

This tool is implemented in the DeBridgeManager class.

Key Methods:

  • create_debridge_transaction(src_chain_id: str, src_chain_token_in: str, src_chain_token_in_amount: str, dst_chain_id: str, dst_chain_token_out: str, dst_chain_token_out_recipient: str, src_chain_order_authority_address: str, dst_chain_order_authority_address: str, ... ) -> dict:

    • (Static method) Constructs the parameters for a deBridge cross-chain transaction.

    • Requires source and destination chain IDs, token addresses (in and out), amounts, recipient address, and order authority addresses on both chains.

    • Optional parameters include affiliate fees and whether to prepend operating expenses.

    • Makes a GET request to the deBridge API (https://api.dln.trade/v1.0/dln/create-tx) to get the transaction details.

    • Returns a dictionary containing the API response, which includes the serialized transaction data if successful.

  • execute_debridge_transaction(agent: SolanaAgentKit, transaction_data: dict) -> str:

    • (Static async method) Takes the transaction_data (typically from create_debridge_transaction) and an agent (SolanaAgentKit).

    • This method is specifically for executing transactions where the source chain is Solana.

    • Decodes the base64 serialized transaction from transaction_data["data"].

    • Signs the VersionedTransaction with the agent's wallet.

    • Sends and confirms the transaction on the Solana network.

    • Returns the Solana transaction signature (ID) as a string.

  • check_transaction_status(tx_hash: str) -> list[dict]:

    • (Static async method) Checks the status of a deBridge transaction using its source transaction tx_hash.

    • First, it queries the deBridge API to get order IDs associated with the tx_hash.

    • Then, for each order ID, it queries the status.

    • Returns a list of status dictionaries for each order, including a link to view the order on the deBridge app.

Important Considerations:

  • External API: This tool relies on the deBridge API. Its functionality is subject to the API's availability, terms, supported chains/tokens, and potential fees.

  • On-Chain Transactions: Executing a deBridge transaction involves actual on-chain transactions on the source blockchain (e.g., Solana), which will spend tokens and incur gas fees.

  • Cross-Chain Complexity: Bridging assets across chains has inherent risks, including smart contract vulnerabilities on either chain or the bridge protocol itself, and potential delays in finality.

  • Parameter Accuracy: Correct chain IDs, token contract addresses, amounts, and recipient addresses are crucial for the transaction to succeed and for funds to arrive at the intended destination. Always verify these from official deBridge documentation or interfaces.

Source Code

You can find the source code for this tool on GitHub: https://github.com/niceberginc/agentipy/blob/main/agentipy/tools/use_debridge.py

Last updated