deBridge 백서

deBridge

원문

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 31쪽 중 9쪽

action hash for a single order, or by the referral code for the integration. Same-chain Swaps are available in the [deBridge Explorer](https://explorer.debridge.com/) under the **Same-Chain** filter. For tracking orders related to an integration, referral code must be generated and included in requests. Instructions for generating a referral code are available in the [referrers guide](/dln-details/affiliates/referrers). ### Summary DLN’s same-chain swaps are designed to eliminate fragility from a straightforward action. The API performs live simulation during estimation, constructs transactions that are execution-ready, applies conservative automatic limits with adaptive slippage, and enforces freshness to prevent stale quotes. With a single router contract on EVM chains and a minimal serialization path on Solana, the integration process prioritizes robustness and clarity. Built-in support for affiliate fees and referral tracking adds a monetization layer without increasing integration complexity, while observability through the Stats API and Explorer reinforces transparency across all activity. For detailed request and response specifications, the [**OpenAPI reference**](https://dln.debridge.finance/v1.0#/single%20chain%20swap/SingleSwapControllerV10_getChainTransaction) and [Integration Guidelines](/dln-details/integration-guidelines/same-chain-swaps/engineer) provide full coverage. # Filling Orders Source: https://docs.debridge.com/dln-details/integration-guidelines/smart-contracts/filling-orders How to fulfill DLN orders via smart contracts. We are going to release a reference documentation for fulfilling orders placed on the deBridge Liquidity Network Protocol soon. Until this, please look at the documentation on [dln-taker](https://github.com/debridge-finance/dln-taker#dln-taker) — our open source service for solvers that automates order estimation and fulfillment. # Introduction Source: https://docs.debridge.com/dln-details/integration-guidelines/smart-contracts/introduction Overview of DLN smart contracts and direct on-chain integration. The deBridge Liquidity Network Protocol is an on-chain system of smart contracts where users place their cross-chain limit orders, giving a specific amount of input token on the source chain (`giveAmount` of the `giveToken` on the `giveChain`) and specifying the outcome they are willing to take on the destination chain (`takeAmount` of the `takeToken` on the `takeChain`). The given amount is being locked by the `DlnSource` smart contract on the source chain and anyone with enough liquidity (called **Solvers**) can attempt to fulfill the order by calling the `DlnDestination` smart contract on the destination chain supplying the requested amount of tokens the user is willing to take. After the order is fulfilled, the supplied amount is immediately transferred to the recipient specified by the user, and a cross-chain message is sent to the source chain via the deBridge infrastructure to unlock the funds, effectively completing the order.Getting ready to make on-chain calls The DLN Protocol consists of two contracts: the `DlnSource` contract responsible for order placement, and the `DlnDestination` contract responsible for order fulfillment. Currently, both contracts are deployed on the supported blockchains effectively allowing anyone to place orders in any direction. Contract addresses can be found [here for DMP](/dmp-details/dmp/deployed-contracts), [here for DLN](/dln-details/overview/deployed-contracts) and ABIs/IDLs can be found here: [Trusted Smart Contracts](https://github.com/debridge-finance/abis-and-idls) # Placing Orders Source: https://docs.debridge.com/dln-details/integration-guidelines/smart-contracts/placing-orders Placing orders on the deBridge Liquidity Network: order preparation, on-chain placement, tracking order status, and cancellation procedures. # Estimating the order First, decide which tokens you are willing to sell on the source chain and which tokens you are willing to buy on the destination chain. Say, you're selling 1 wBTC on Ethereum and buying a reasonable amount of DOGE on BNB. <Info> The deBridge Liquidity Network Protocol is completely asset-agnostic, meaning that you can place an order giving wBTC or WETH, or any other asset. However, solvers mainly hold USDC and ETH on their wallets' balance and execute only the orders where the input token is either a USDC token or a native ETH. Thus, for a quick fulfillment of the order placed in the deBridge Liquidity Network Protocol, it's recommended to pre-swap your input token to any of these reserve-ready tokens before placing an order. On the other hand, DLN is an open market, so anyone can become a solver and execute orders with custom input tokens or profitability. </Info> Let's assume you've swapped your 1 wBTC to 25,000 USDC which will be then used upon order creation. Second, calculate the reasonable amount of tokens you are willing to receive on the destination chain upon order fulfillment according to the current market condition and the protocol fees. Simply speaking, give at least 4 bps (DLN protocol fee) + 4 bps (Taker's incentive) = 8 bps + \$6 (expected gas expenses taken by the taker to fulfill the order). This amount is laid in as a spread of the limit order, or margin between input and output tokens. Getting back to the example, the math below gives us a reasonable amount of DOGE we are willing to take: ```typescript theme={null} 25,000 * (10,000 - 8) / 10,000 - 6 = 24,974 DOGE ``` <Note> 10,000 is a basis point denominator. More details [here](https://en.wikipedia.org/wiki/Basis_point). </Note> Third, make sure you have enough Ether to cover the protocol fee, which is being taken by `DlnSource` smart contract for order creation. You are advised to query `DlnSource.globalFixedNativeFee()` function to retrieve this value. For example, the `globalFixedNativeFee` value for the Ethereum blockchain would be `1000000000000000`, which resolves to 0.001 ETH. # Placing order on-chain To place an order * set USDC token approval to allow the `DlnSource` contract spend tokens on your behalf, * call the `DlnSource.createOrder()` method ```solidity theme={null} function createOrder( OrderCreation calldata _orderCreation, bytes calldata _affiliateFee, uint32 _referralCode, bytes calldata _permitEnvelope ) external payable returns (bytes32 orderId); ``` ## Preparing OrderCreation struct `OrderCreation` has the following structure: ```solidity theme={null} struct OrderCreation { // the address of the ERC-20 token you are giving; // use the zero address to indicate you are giving a native blockchain token (ether, matic, etc). address giveTokenAddress; // the amount of tokens you are giving uint256 giveAmount; // the address of the ERC-20 token you are willing to take on the destination chain bytes takeTokenAddress; // the amount of tokens you are willing to take on the destination chain uint256 takeAmount; // the ID of the chain where an order should be fulfilled. // Use the list of supported chains mentioned above uint256 takeChainId; // the address on the destination chain where the funds // should be sent to upon order fulfillment bytes receiverDst; // the address on the source (current) chain who is allowed to patch the order // giving more input tokens and thus making the order more attractive to takers, just in case address givePatchAuthoritySrc; // the address on the destination chain who is allowed to patch the order // decreasing the take amount and thus making the order more attractive to takers, just in case bytes orderAuthorityAddressDst; // an optional address restricting anyone in the open market from fulfilling // this order but the given address. This can be useful if you are creating a order // for a specific taker. By default, set to empty bytes array (0x) bytes allowedTakerDst; // *optional // set to an empty bytes array (0x) bytes externalCall; // N/A, *optional // an optional address on the source (current) chain where the given input tokens // would be transferred to in case order cancellation is initiated by the orderAuthorityAddressDst // on the destination chain. This property can be safely set to an empty bytes array (0x): // in this case, tokens would be transferred to the arbitrary address specified // by the orderAuthorityAddressDst upon order cancellation bytes allowedCancelBeneficiarySrc; // *optional } ``` ## Preparing other arguments Subsequent arguments of the `createOrder()` method can be safely omitted by specifying the default values: * `_affiliateFee` can be set to empty bytes array (`0x`); this argument allows you to ask the protocol to keep the given amount as an affiliate fee in favor of affiliate beneficiary and release it whenever an order is completely fulfilled. This is useful if you built a protocol and place orders on behalf of your users. To do so, concat the address and the amount into a single bytes array, whose length is expected to be exactly 52 bytes. * `_referralCode` can be set to zero (`0`); it is an invitation code to identify your transaction. If you don't have it, you can get one by pressing the INVITE FRIENDS button at app.debridge.com. Governance may thank you later for being an early builder. * `_permitEnvelope` can be set to empty bytes array (`0x`); it allows you to use an EIP-2612-compliant signed approval so you don't have to give a prior spending approval to allow the `DlnSource` contract to spend tokens on your behalf. This argument accepts `amount` + `deadline` + `signature` as a single bytes array ## Making a call Once all arguments are prepared, you are ready to make the call. Make sure you supply the exact amount of native blockchain currency to the `value` to cover the DLN protocol fee (`globalFixedNativeFee`). <Accordion title="Order Preparation"> ```solidity theme={null} // preparing an order OrderCreation memory orderCreation; orderCreation.giveTokenAddress = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48; // USDC orderCreation.giveAmount = 25000000000; // 25,000 USDC orderCreation.takeTokenAddress = abi.encodePacked(0xba2ae424d960c26247dd6c32edc70b295c744c43); orderCreation.takeAmount = 2497400000000; // 249,740 DOGE orderCreation.takeChainId = 56; // BNB Chain orderCreation.receiverDst = abi.encodePacked(0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045); orderCreation.givePatchAuthoritySrc = 0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045; orderCreation.orderAuthorityAddressDst = abi.encodePacked(0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045); orderCreation.allowedTakerDst = ""; orderCreation.externalCall = ""; orderCreation.allowedCancelBeneficiarySrc = ""; // getting the protocol fee uint protocolFee = DlnSource(dlnSourceAddress).globalFixedNativeFee(); // giving approval IERC20(orderCreation.giveTokenAddress).approve(dlnSourceAddress, orderCreation.giveAmount); // placing an order bytes32 orderId = DlnSource(dlnSourceAddress).createOrder{value: protocolFee}( orderCreation, "", 0, "" ); ``` </Accordion> Whenever the call to `DlnSource.createOrder()` succeeds, it will return a unique `orderId` which can be used to track, cancel and fulfill the order. Additionally, `CreatedOrder` event is emitted. It contains the `Order` structure which is important in specifying how to fulfill or cancel the order. ```solidity theme={null} event CreatedOrder( Order order, bytes32 orderId, bytes affiliateFee, uint256 nativeFixFee, uint256 percentFee, uint32 referralCode ); ``` # Tracking order status <Warning> There is no way to know the order status on the chain where the order was placed. You need to switch to the chain it is intended to be fulfilled on (the `takeChainId` property of the order). </Warning> You have two options to programmatically find whenever an order has been fulfilled or cancelled on the destination chain (not the chain where you placed it): either by querying the `DlnDestination.takeOrders()` getter method, or by capturing the `FulfilledOrder()` and `SentOrderCancel()` events emitted by the `DlnDestination` contract. The `DlnDestination.takeOrders()` getter method is defined as follows: ```solidity theme={null} function takeOrders(bytes32 orderId) external view returns ( uint8 status, address takerAddress, uint256 giveChainId ); ``` It returns the status property which indicates: -status=0: the given order is neither fulfilled nor cancelled, -status=1: the given order is successfully fulfilled (funds sent to the given receiver) -status=2: unlock procedure has been initiated upon fulfillment to unlock the given funds on the source chain, as per taker request -status=3: cancel procedure has been initiated to unlock the given funds on the source chain, as per order's orderAuthorityAddressDst request Alternatively, you can capture events emitted by the `DlnDestination` contact: ```solidity theme={null} event FulfilledOrder(Order order, bytes32 orderId, address sender, address unlockAuthority); event SentOrderCancel(Order order, bytes32 orderId, bytes cancelBeneficiary, bytes32 submissionId); ``` Events are emitted: * `FulfilledOrder` whenever the order has been successfully fulfilled. * `SentOrderCancel` whenever the cancel procedure has been initiated, as per order's `orderAuthorityAddressDst` request. # Canceling order The only way to cancel the order is to initiate the cancellation procedure on the chain it was intended to be fulfilled on (the `takeChainId` property of the order). During the cancellation process, the order is marked as cancelled (to prevent further fulfillment) and a cross-chain message is sent through the deBridge cross-chain messaging infrastructure to the `DlnSource` contract on the source chain to unlock the given funds. The funds locked on the source chain are returned in full including affiliate and protocol fees. To initiate the cancellation procedure, call the `DlnDestination.sendEvmOrderCancel()` method on the destination chain as follows: ```solidity theme={null} function sendEvmOrderCancel( Order memory _order, address _cancelBeneficiary, uint256 _executionFee ) external payable; ``` * mind that only the `orderAuthorityAddressDst` address specified during the order creation is allowed to perform this call for the given order; * you need to cover the deBridge cross-chain messaging protocol fee (measured in the blockchain native currency where the message is being sent from) to make a cancellation message accepted. Consider looking at the details on retrieving the deBridge protocol fee; * for the `_order` argument, use the `Order` structure obtained from the `CreatedOrder()` upon order creation; * for the `_cancelBeneficiary` argument, use the address you'd like the given funds to be unlocked to on the source chain. Whenever the `allowedCancelBeneficiarySrc` has been explicitly provided upon order creation, you are only allowed to use that value; * for the `_executionFee` argument, specify the amount of native blockchain currency (in addition to the deBridge protocol fee) to provide an incentive to keepers for the successful claim of the cross-chain message on the destination chain. In other words, this is a prepayment for potential gas expenses on the destination chain, that will be transferred by the protocol. Otherwise, you'd need to find the cross-chain transaction in the [deExplorer](https://explorer.debridge.com/) and claim it manually. Consider understanding how the cross-chain call is handled. Finally, you are ready to initiate a cancellation procedure: ```solidity theme={null} uint protocolFee = IDebridgeGate(DlnDestination(dlnDestinationAddress).deBridgeGate()) .globalFixedNativeFee(); uint executionFee = 30000000000000000; // e.g. 0.03 BNB ≈ \$10 DlnDestination(dlnDestinationAddress).sendEvmOrderCancel{value: protocolFee + executionFee}( order, 0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045, executionFee ); ``` # MCP Server Source: https://docs.debridge.com/dln-details/mcp/mcp-server Connect AI coding agents to deBridge for cross-chain swaps Ask your AI assistant to bridge 1 ETH from Arbitrum to Solana. Get a quote in seconds. Click one link to execute. The deBridge MCP Server ([`@debridge-finance/debridge-mcp`](http://npmjs.com/package/@debridge-finance/debridge-mcp)) gives AI agents direct access to the deBridge Liquidity Network — search 40,000+ tokens, get quotes for cross-chain and same-chain swaps, generate transaction data, and create shareable [deBridge App](https://app.debridge.finance) links based on [custom linking](/dln-details/widget/app). No API keys required. ## How It Works The MCP server is a stateless proxy that translates MCP tool calls into deBridge REST API requests. It does no heavy computation, keeps no state, and stores nothing. The AI agent never talks to the deBridge API directly — all requests flow through the server. ```mermaid theme={null} sequenceDiagram participant Agent as AI Agent participant Server as MCP Server participant API as deBridge API Agent->>Server: MCP tool call (e.g. create_tx) Server->>API: REST request API-->>Server: JSON response Server-->>Agent: Tool result Agent->>Agent: Presents result to user ``` The server calls public deBridge APIs, which provide a generous 50 requests per minute rate limit without authentication. ## Use Cases * **Developers building on deBridge** — test quotes, check token addresses, and verify chain IDs without leaving the IDE. The MCP server turns an AI assistant into a live deBridge API explorer. * **Power users in AI chat** — get quick swap quotes as part of a broader conversation. One click on the generated link to execute the swap. * **Analysts and content creators** — query live pricing data conversationally. Compare bridge rates across chains for reports and research. * **Trading bots and dashboards** — autonomous agents that monitor prices across chains and generate swap links when conditions are met. * **Integrate with the existing AI agents** — any agent that supports MCP servers can use this to offer deBridge swaps without building their own API integration and expand their capabilities into DeFi space. ## Quick Start Add this to your MCP configuration file: ```json theme={null} { "mcpServers": { "debridge-mcp": { "command": "npx", "args": [ "-y", "@debridge-finance/debridge-mcp@latest" ] } } } ``` This works for most AI coding agents (Cursor, Claude Code, Windsurf, Cline, etc.). See [Configuration](#configuration) for framework-specific paths and options. <Note> **Claude Desktop** requires HTTP transport. Start the server with `MCP_TRANSPORT=http npx -y @debridge-finance/debridge-mcp@latest`, then configure the URL `http://localhost:3000/mcp`. See [Configuration](#configuration) for details. </Note> ## Tools ### `get_instructions` Returns the built-in workflow guide that describes the recommended sequence for using the deBridge MCP tools. No parameters. <Tip> Call this first to understand the recommended workflow before using other tools. </Tip> ### `search_tokens` Resolves token names, symbols, or addresses to contract addresses across supported chains. | Parameter | Type | Required | Description | | --------- | ------ | -------- | ------------------------------------ | | `query` | string | Yes | Token name, symbol, or address | | `chainId` | string | No | Filter by chain ID | | `name` | string | No | Filter by token name (partial match) | | `limit` | number | No | Max results (default: 10) | Results are ranked by relevance: exact symbol match → exact name match → starts-with → substring. **Example:** ```json theme={null} { "query": "USDC", "chainId": "1" } ``` ```json theme={null} { "tokens": [ { "symbol": "USDC", "name": "USD Coin", "address": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "decimals": 6, "chainId": "1" } ] } ``` ### `get_supported_chains` Lists all blockchain
프로젝트로 돌아가기