Skip to content

Commit

Permalink
feat: Add deBridge plugin (#364)
Browse files Browse the repository at this point in the history
* add deBridge plugin

* Update deBridge plugin readme

* Update deBridge plugin readme and add linting

* Update get_supported_chains tool and add author information
  • Loading branch information
ofemeteng authored Feb 25, 2025
1 parent faec658 commit 0fa43b8
Show file tree
Hide file tree
Showing 5 changed files with 560 additions and 0 deletions.
59 changes: 59 additions & 0 deletions python/src/plugins/debridge/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# deBridge Plugin for GOAT SDK

A plugin for the GOAT SDK that provides access to deBridge Liquidity Network (DLN) functionality.

## Installation

```bash
# Install the plugin
poetry add goat-sdk-plugin-debridge


```

## Usage

```python
from goat_plugins.debridge import debridge, DebridgePluginOptions

# Initialize the plugin
options = DebridgePluginOptions()
plugin = debridge(options)

# Get order data
order_data = await plugin.get_order_data(
id="0x81fbb0ed8209eb57d084aee1986c00e597c1e1ec6bb93bc4dbe97266ca0398fb"
)

# Get supported chains
chains = await plugin.get_supported_chains()

# Get order IDs
order_IDs = await plugin.get_order_IDs(
hash="0xbe9071de34de9bd84a52039bc4bc6c8229d4bd65127d034ffc66b600d8260276" # Hash of the creation transaction
)
```

## Features

- DLN
- Create order transaction `create_order_transaction`
- Get order data `get_order_data`
- Get order status `get_order_status`
- Get order IDs `get_order_IDs`
- Cancel order `cancel_order`
- Cancel external call `cancel_external_call`
- Utils
- Get supported chains `get_supported_chains`
- Get token list `get_token_list`
- Single Chain Swap
- Estimation `single_chain_swap_estimation`
- Transaction `single_chain_swap_transaction`

### DLN Swagger Docs
The deBridge plugin tools is a 1-to-1 representation of the DLN API.
You can access the [deBridge Swagger docs](https://dln.debridge.finance/v1.0) page for more information about the various parameters.

## License

This project is licensed under the terms of the MIT license.
22 changes: 22 additions & 0 deletions python/src/plugins/debridge/goat_plugins/debridge/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from dataclasses import dataclass
from goat.classes.plugin_base import PluginBase
from .service import DebridgeService


@dataclass
class DebridgePluginOptions:
# Debridge currently doesn't require any auth keys
pass


class DebridgePlugin(PluginBase):

def __init__(self, options: DebridgePluginOptions):
super().__init__("debridge", [DebridgeService()])

def supports_chain(self, chain) -> bool:
return True


def debridge(options: DebridgePluginOptions) -> DebridgePlugin:
return DebridgePlugin(options)
186 changes: 186 additions & 0 deletions python/src/plugins/debridge/goat_plugins/debridge/parameters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
from pydantic import BaseModel, Field
from typing import Optional


class EmptyParameters(BaseModel):
pass


class GetTokenListParameters(BaseModel):
chainId: str = Field(description="ID of a chain")


class GetOrderDataParameters(BaseModel):
id: str = Field(description="ID of the order")


class GetOrderStatusParameters(BaseModel):
id: str = Field(description="ID of the order")


class GetOrderIDsParameters(BaseModel):
hash: str = Field(description="Hash of the creation transaction")


class CancelOrderParameters(BaseModel):
id: str = Field(description="ID of the order")


class CancelExternalCallParameters(BaseModel):
id: str = Field(description="ID of the order")


class CreateOrderTransactionParameters(BaseModel):
srcChainId: str = Field(
description=
"An ID of a source chain, a chain where the cross-chain swap will start"
)
srcChainTokenIn: str = Field(
description="An address (on a source chain) of an input token to swap")
srcChainTokenInAmount: str = Field(
description="An amount of input tokens to swap")
dstChainId: str = Field(
description=
"An ID of a destination chain, a chain where the cross-chain swap will finish. Must differ from srcChainId!"
)
dstChainTokenOut: str = Field(
description="An address (on a destination chain) of a target token")
dstChainTokenOutAmount: Optional[str] = Field(
default="auto",
description=
"Amount of the target asset the market maker expects to receive upon order fulfillment.",
)
additionalTakerRewardBps: Optional[int] = Field(
description=
"additionalTakerRewardBps is additionally laid in on top of default taker margin"
)
srcIntermediaryTokenAddress: Optional[str] = Field(
description=
"An address (on a source chain) of an intermediary token a user's input funds should be swapped to prior order creation"
)
dstIntermediaryTokenAddress: Optional[str] = Field(
description=
"An address (on a destination chain) of an intermediary token whose value assumed to be equal to the value of srcIntermediaryTokenAddress"
)
dstIntermediaryTokenSpenderAddress: Optional[str] = Field(
description=
"Applicable to a EVM-compatible destination chain. An address (on a EVM-compatible destination chain) assumed as a spender of the intermediary token (set as dstIntermediaryTokenAddress) during order fulfillment"
)
intermediaryTokenUSDPrice: Optional[float] = Field(
description=
"A value (a spot price) of the given intermediary token expressed in US dollars"
)
dstChainTokenOutRecipient: Optional[str] = Field(
description=
"Address (on the destination chain) where target tokens should be transferred to after the swap. Required for transaction construction, otherwise only the quote is returned!"
)
senderAddress: Optional[str] = Field(
description=
"Address (on the source chain) who submits input tokens for a cross-chain swap"
)
srcChainOrderAuthorityAddress: Optional[str] = Field(
description=
"Address (on the source chain) who submits input tokens for a cross-chain swap. Required for transaction construction, otherwise only the quote is returned!"
)
srcAllowedCancelBeneficiary: Optional[str] = Field(
description=
"Fixed recipient of the funds of an order in case it is being cancelled. If not set, the recipient could be set later upon order cancellation"
)
referralCode: Optional[float] = Field(
default=31494,
description=
"Your referral code which can be generated here: https://app.debridge.finance/refer",
)
affiliateFeePercent: Optional[float] = Field(
default=0,
description=
"The share of the input amount to be distributed to the affiliateFeeRecipient (if given) address as an affiliate fee",
)
affiliateFeeRecipient: Optional[str] = Field(
description=
"An address (on an origin chain) that will receive affiliate fees according to the affiliateFeePercent parameter"
)
srcChainTokenInSenderPermit: Optional[str] = Field(
description=
"Typically, a sender is required to approve token transfer to deBridge forwarder for further transfer and swap"
)
dstChainOrderAuthorityAddress: Optional[str] = Field(
description=
"Address on the destination chain whom should be granted the privileges to manage the order (patch, cancel, etc). Required for transaction construction, otherwise only the quote is returned!"
)
enableEstimate: Optional[bool] = Field(
description=
"This flag forces deSwap API to validate the resulting transaction and estimate its gas consumption"
)
allowedTaker: Optional[str] = Field(
description="An address (on a destination chain) of a allowed taker")
dlnHook: Optional[str] = Field(
description="JSON representing a DLN Hook to be attached to an order")
prependOperatingExpenses: Optional[bool] = Field(
default=False,
description=
"Tells API server to prepend operating expenses to the input amount",
)
metadata: Optional[str] = Field(default=False, description="Metadata")
ptp: Optional[bool] = Field(
default=False,
description=
"Forces a P2P order where input and output tokens are left intact",
)
skipSolanaRecipientValidation: Optional[bool] = Field(
default=False,
description=
"Skip system address validation dstChainTokenOutRecipient in Solana",
)


class SingleChainSwapEstimationParameters(BaseModel):
chainId: str = Field(
description="An ID of a chain, a chain where the swap must be performed"
)
tokenIn: str = Field(description="An address of an input token to swap")
tokenInAmount: str = Field(description="An amount of input tokens to swap")
slippage: Optional[str] = Field(
default="auto",
description=
"A slippage constraint (in %) is a safeguard during swaps (on both source and destination chains, if applicable). It is also used to calculate the minimum possible outcome during estimation",
)
tokenOut: str = Field(description="An address of a target token")
affiliateFeePercent: Optional[float] = Field(
default=0,
description=
"The share of the input amount to be distributed to the affiliateFeeRecipient (if given) address as an affiliate fee",
)
affiliateFeeRecipient: Optional[str] = Field(
description=
"An address (on an origin chain) that will receive affiliate fees according to the affiliateFeePercent parameter"
)


class SingleChainSwapTransactionParameters(BaseModel):
chainId: str = Field(
description="An ID of a chain, a chain where the swap must be performed"
)
tokenIn: str = Field(description="An address of an input token to swap")
tokenInAmount: str = Field(description="An amount of input tokens to swap")
slippage: Optional[str] = Field(
default="auto",
description=
"A slippage constraint (in %) is a safeguard during swaps (on both source and destination chains, if applicable). It is also used to calculate the minimum possible outcome during estimation",
)
tokenOut: str = Field(description="An address of a target token")
tokenOutRecipient: str = Field(
description="Address who receives the tokens from the swap")
affiliateFeePercent: Optional[float] = Field(
default=0,
description=
"The share of the input amount to be distributed to the affiliateFeeRecipient (if given) address as an affiliate fee",
)
affiliateFeeRecipient: Optional[str] = Field(
description=
"An address (on an origin chain) that will receive affiliate fees according to the affiliateFeePercent parameter"
)
senderAddress: Optional[str] = Field(
description=
"Address (on the source chain) who submits input tokens for a cross-chain swap"
)
Loading

0 comments on commit 0fa43b8

Please sign in to comment.