### GET /get_instructions Source: https://docs.debridge.com/dln-details/mcp/mcp-server Retrieves the built-in workflow guide for using deBridge MCP tools. Call this first to understand the recommended workflow. ```APIDOC ## GET /get_instructions ### Description Returns the built-in workflow guide that describes the recommended sequence for using the deBridge MCP tools. ### Method GET ### Endpoint /get_instructions ### Parameters No parameters. ### Response #### Success Response (200) - **workflow_guide** (string) - The recommended workflow for using deBridge MCP tools. ``` -------------------------------- ### Create Transaction API Example Source: https://docs.debridge.com/dln-details/integration-guidelines/order-creation/creating-order/api-parameters/api-parameters An example of a complete `create-tx` API request demonstrating core parameters. ```APIDOC ## GET /v1.0/dln/order/create-tx ### Description Example request for creating a cross-chain order with core parameters. ### Method GET ### Endpoint /v1.0/dln/order/create-tx ### Parameters #### Query Parameters - **srcChainId** (number) - Required - Source chain ID. - **srcChainTokenIn** (string) - Required - Input token address on the source chain. - **srcChainTokenInAmount** (string) - Required - Amount of input token. - **dstChainId** (number) - Required - Destination chain ID. - **dstChainTokenOut** (string) - Required - Output token address on the destination chain. - **dstChainTokenOutAmount** (string) - Required - Amount of output token (can be 'auto'). - **dstChainTokenOutRecipient** (string) - Required - Recipient address on the destination chain. - **srcChainOrderAuthorityAddress** (string) - Required - Authority address on the source chain. - **dstChainOrderAuthorityAddress** (string) - Required - Authority address on the destination chain. - **affiliateFeePercent** (number) - Optional - Affiliate fee percentage. - **affiliateFeeRecipient** (string) - Optional - Recipient address for affiliate fees. ### Request Example ``` https://dln.debridge.finance/v1.0/dln/order/create-tx?srcChainId=56&srcChainTokenIn=0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d&srcChainTokenInAmount=100000000000000000000&dstChainId=43114&dstChainTokenOut=0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7&dstChainTokenOutAmount=auto&dstChainTokenOutRecipient=0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045&srcChainOrderAuthorityAddress=0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045&dstChainOrderAuthorityAddress=0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045&affiliateFeePercent=0.1&affiliateFeeRecipient=0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045 ``` ### Response #### Success Response (200) (Response details not provided in the source text) ``` -------------------------------- ### Example of Sending EVM Order Cancellation Source: https://docs.debridge.com/dln-details/integration-guidelines/smart-contracts/placing-orders This example demonstrates how to calculate the protocol fee and execution fee, and then call `sendEvmOrderCancel` to initiate the order cancellation. The `_cancelBeneficiary` is set to a specific address, and the `executionFee` is provided as an incentive for keepers. ```solidity 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 ); ``` -------------------------------- ### Search Tokens Response Example Source: https://docs.debridge.com/dln-details/mcp/mcp-server This is an example response from the search_tokens tool, detailing token symbol, name, address, decimals, and chain ID. ```json { "tokens": [ { "symbol": "USDC", "name": "USD Coin", "address": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "decimals": 6, "chainId": "1" } ] } ``` -------------------------------- ### Example Order Input Structure Source: https://docs.debridge.com/dln-details/integration-guidelines/order-creation/creating-order/quoting-strategies This example demonstrates the structure of an order input object, including chain IDs, token addresses, amounts, recipient, and authority addresses. It shows how to convert a user-friendly amount to an atomic unit using ethers.parseUnits. ```typescript const arbUsdcAddress = "0xaf88d065e77c8cc2239327c5edb3a432268e5831"; const bnbUsdcAddress = "0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d"; const usdcDecimals = 18; const amountToSend = "0.01"; const amountInAtomicUnit = ethers.parseUnits(amountToSend, usdcDecimals); const orderInput: deBridgeOrderInput = { srcChainId: "56", srcChainTokenIn: bnbUsdcAddress, srcChainTokenInAmount: amountInAtomicUnit.toString(), dstChainTokenOutAmount: "auto", dstChainId: "42161", dstChainTokenOut: arbUsdcAddress, dstChainTokenOutRecipient: wallet.address, account: wallet.address, srcChainOrderAuthorityAddress: wallet.address, dstChainOrderAuthorityAddress: wallet.address, referralCode: 31805, }; ``` -------------------------------- ### Basic Link with Referral Code Example Source: https://docs.debridge.com/home/monetization/custom-linking A simple example of a deBridge link that includes only a referral code. ```url https://app.debridge.com/?r=7895 ``` -------------------------------- ### Get Orders by Referral Code Example Source: https://docs.debridge.com/home/monetization/referral-codes This TypeScript example demonstrates how to query all orders associated with a specific referral code using the deBridge tracking API. Ensure you have the necessary API credentials and environment variables set up. ```typescript import { de சே } from "@de சே/api-client"; async function getOrdersByReferralCode(referralCode: string) { const apiClient = new de சே(); const response = await apiClient.query({ operationName: "getOrdersByReferralCode", query: ` query getOrdersByReferralCode($referralCode: String!) { orders(filter: { referralCode: $referralCode }) { id amount fee status createdAt } } `, variables: { referralCode: referralCode, }, }); if (response.errors) { console.error("Error fetching orders:", response.errors); return; } console.log("Orders:", response.data.orders); } // Example usage: // getOrdersByReferralCode("7895"); ``` -------------------------------- ### deSwap Custom Link Example Source: https://docs.debridge.com/dln-details/widget/app Example of a deSwap custom link with BSC(USDC) to Ethereum (USDT) parameters, including referral code and recipient address. ```url https://app.debridge.com/deswap?inputChain=56&inputCurrency=0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d&outputChain=1&outputCurrency=0xdac17f958d2ee523a2206206994597c13d831ec7&r=111&address=0x0000000000000000000000000000000000000000​ ``` -------------------------------- ### dePort Custom Link Example Source: https://docs.debridge.com/dln-details/widget/app Example of a dePort custom link with BSC(USDC) parameters, including referral code. ```url https://app.debridge.com/deport?inputChain=56&inputCurrency=0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d&r=111 ``` -------------------------------- ### Example Response for Filtered Wallet Histories Source: https://docs.debridge.com/dln-details/integration-guidelines/same-chain-swaps/engineer This is an example response structure for the filtered list endpoint, detailing swap information including metadata and state. ```json { "orders": [ { "orderId": { /* order ID object - with bytes, bytes array and string values */ }, "creationTimestamp": 1759141461, // Unix timestamp "giveOfferWithMetadata": { "chainId": { /* chain ID object with different representations */ }, "tokenAddress": { /* token address object - with different representations */ }, "amount": { /* amount object - with different representations */ }, "metadata": { "decimals": 6, "name": "Dephaser JPY", "symbol": "JPYT", "logoURI": null }, "decimals": 6, "name": "Dephaser JPY", "symbol": "JPYT", "logoURI": null }, "takeOfferWithMetadata": { "chainId": { /* chain ID object with different representations */ }, "tokenAddress": { /* token address object - with different representations */ }, "amount": { /* amount object - with different representations */ }, "metadata": { "decimals": 18, "name": "AntHive", "symbol": "ANTH", "logoURI": null }, "decimals": 18, "name": "AntHive", "symbol": "ANTH", "logoURI": null }, "state": "Fulfilled", // Swap state "affiliateFee": { "beneficiarySrc": { /* affiliate fee beneficiary address object - with bytes, bytes array and string values */ }, "amount": { /* amount object - with bytes, bytes array and string values */ } }, "createEventTransactionHash": { /* transaction hash object - with bytes, bytes array and string values */ }, "tradeType": "SameChain" } ], "totalCount": 24 } ``` -------------------------------- ### DlnHook Encoding Example for Solana Source: https://docs.debridge.com/dln-details/integration-guidelines/order-creation/hooks/integrating-hooks Example demonstrating how to stringify the `dlnHook` object for Solana, including a complex `data` field representing a versioned transaction. ```typescript dlnHook: JSON.stringify({ type: "solana_serialized_instructions"; data: "0x0000000000000000010000000000000000000000001000000000000000010000000000000000135d3e6be2a2ae5274cfe4007df2f62ed31c618f048337fd1435ca2dee2a0d5d12000000000000001968562fef0aab1b1d8f99d44306595cd4ba41d7cc899c007a774d23ad702ff60101fd97b70d573d364ef44769540777b1ecdc21b88ff7def38c45d020e271c589dc00010000000000000000000000000000000000000000000000000000000000000000000062584959deb8a728a91cebdc187b545d920479265052145f31fb80c73fac5aea00009845350d27001686985bbc5c4a3646c928d7de27ddab09f2de56d21537201c4300019845350d27001686985bbc5c4a3646c928d7de27ddab09f2de56d21537201c4300010c1e5ba8fe0ec5c5e44d12c2b6317a8781ca19ddb0e1532b136f418e1d588f9500010c1e5ba8fe0ec5c5e44d12c2b6317a8781ca19ddb0e1532b136f418e1d588f95000106ddf6e1d765a193d9cbe146ceeb79ac1cb485ed5f5b37913a8cf5857eff00a900000000000000000000000000000000000000000000000000000000000000000000000006a7d517187bd16635dad40455fdc2c0c124c68f215675a5dbbacb5f0800000000008c97258f4e2489f1bb3d1029148e0d830b5a1399daff1084048e7bd8dbe9f8590000ef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000974d0b69f43d964da48af118a28037ab921a95eae1e637497b22867ce416255a00016be7362bf52e4ea29063d29ab43a832253ed7c68b62cf68e8d706a2f9531c1eb0001c6fa7af3bedbad3a3d65f36aabc97431b1bbe4c2d2f6e0e47ca60203452f5d610000040000000000000000736f6c" }) ``` -------------------------------- ### BSC USDC to Ethereum USDT Link Example Source: https://docs.debridge.com/home/monetization/custom-linking Example of a deBridge link pre-selecting the input chain (BSC), input currency (USDC), output chain (Ethereum), output currency (USDT), and including a referral code. ```url https://app.debridge.com/?inputChain=56&inputCurrency=0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d&outputChain=1&outputCurrency=0xdac17f958d2ee523a2206206994597c13d831ec7&r=7895 ``` -------------------------------- ### ETH to Polygon USDC Link Example Source: https://docs.debridge.com/home/monetization/custom-linking Example of a deBridge link pre-selecting the input chain (Ethereum), output chain (Polygon), output currency (USDC), and including a referral code. ```url https://app.debridge.com/?inputChain=1&outputChain=137&outputCurrency=0x3c499c542cef5e3811e1192ce70d8cc03d5c3359&r=7895 ``` -------------------------------- ### Example Order Response Source: https://docs.debridge.com/dln-details/integration-guidelines/order-creation/order-tracking-api/tracking-orders A sample JSON response indicating the status of an order, specifically when it has been 'ClaimedUnlock'. ```json { "status": "ClaimedUnlock" } ``` -------------------------------- ### Get Supported Chains Response Example Source: https://docs.debridge.com/dln-details/mcp/mcp-server This JSON response lists all blockchain networks supported by DLN, including their chain ID and name. ```json { "chains": [ { "chainId": "1", "chainName": "Ethereum" }, { "chainId": "56", "chainName": "BNB Chain" }, { "chainId": "137", "chainName": "Polygon" }, { "chainId": "42161", "chainName": "Arbitrum" }, { "chainId": "7565164", "chainName": "Solana" } ] } ``` -------------------------------- ### Get Submission Chain ID - Solidity Source: https://docs.debridge.com/dmp-details/dev-guides/evm/interfaces/ICallProxy Retrieves the chain ID from which the current submission is received. No specific setup is required beyond calling the function. ```solidity function submissionChainIdFrom() external returns (uint256) ``` -------------------------------- ### Create Order Source: https://docs.debridge.com/dln-details/integration-guidelines/smart-contracts/placing-orders This section demonstrates how to prepare and create an order using the DlnSource.createOrder function. ```APIDOC ## POST /api/orders ### Description Creates a new order for token exchange. ### Method POST ### Endpoint /api/orders ### Parameters #### Request Body - **orderCreation** (object) - Required - Details of the order to be created. - **giveTokenAddress** (address) - Required - The address of the token to give. - **giveAmount** (uint256) - Required - The amount of the token to give. - **takeTokenAddress** (bytes) - Required - The address of the token to take (encoded). - **takeAmount** (uint256) - Required - The amount of the token to take. - **takeChainId** (uint256) - Required - The chain ID to take the token on. - **receiverDst** (bytes) - Required - The destination address for the received token (encoded). - **givePatchAuthoritySrc** (address) - Required - The authority address on the source chain. - **orderAuthorityAddressDst** (bytes) - Required - The destination order authority address (encoded). - **allowedTakerDst** (string) - Optional - Allowed taker address on the destination chain. - **externalCall** (string) - Optional - External call data. - **allowedCancelBeneficiarySrc** (string) - Optional - Allowed cancel beneficiary on the source chain. - **affiliateFee** (string) - Optional - Affiliate fee information. - **referralCode** (uint32) - Optional - Referral code. ### Request Example ```json { "orderCreation": { "giveTokenAddress": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", "giveAmount": "25000000000", "takeTokenAddress": "0xba2ae424d960c26247dd6c32edc70b295c744c43", "takeAmount": "2497400000000", "takeChainId": 56, "receiverDst": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045", "givePatchAuthoritySrc": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045", "orderAuthorityAddressDst": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045", "allowedTakerDst": "", "externalCall": "", "allowedCancelBeneficiarySrc": "" }, "affiliateFee": "", "referralCode": 0 } ``` ### Response #### Success Response (200) - **orderId** (bytes32) - The unique ID of the created order. #### Response Example ```json { "orderId": "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef" } ``` ``` -------------------------------- ### Get Filtered Orders List - OpenAPI Spec Source: https://docs.debridge.com/api-reference/orders/get-filtered-list-of-orders-ordered-by-block-timestamp-desc-max-page-size%3A-100 This OpenAPI specification defines the POST endpoint `/api/Orders/filteredList` for retrieving a filtered list of orders. It includes request body examples for various content types. ```yaml openapi: 3.0.1 info: title: DLN stats API description: >- # Introduction This API is part of [deBridge](https://debridge.com/) protocol infrastructure. Protocol documentation is available [here](https://docs.debridge.com/). [Terms and Condition](https://debridge.com/assets/files/debridge_terms_of_service.pdf) | [Privacy Policy](https://debridge.com/assets/files/debridge_privacy_policy.pdf) # Swagger Swagger document can be found [here](/swagger) Redoc document can be found [here](/redoc) version: v1 servers: - url: https://dln-api.debridge.finance security: [] paths: /api/Orders/filteredList: post: tags: - Orders summary: >- Get filtered list of orders (ordered by block timestamp desc) max page size: 100 operationId: Orders_GetOrders requestBody: content: application/json-patch+json: schema: $ref: '#/components/schemas/OrdersRequestDTO' example: giveChainIds: - 1 - 137 - 250 takeChainIds: - 56 orderStates: - Created - Fulfilled externalCallStates: - NoExtCall filter: '' skip: 0 take: 1 blockTimestampFrom: null blockTimestampTo: null fulfiller: null unlockAuthorities: null maker: null creator: null referralCode: null orderAuthorityInSourceChain: null orderAuthorityInDestinationChain: null orderTradeType: null filterMode: CrossChain application/json: schema: $ref: '#/components/schemas/OrdersRequestDTO' example: giveChainIds: - 1 - 137 - 250 takeChainIds: - 56 orderStates: - Created - Fulfilled externalCallStates: - NoExtCall filter: '' skip: 0 take: 1 blockTimestampFrom: null blockTimestampTo: null fulfiller: null unlockAuthorities: null maker: null creator: null referralCode: null orderAuthorityInSourceChain: null orderAuthorityInDestinationChain: null orderTradeType: null filterMode: CrossChain text/json: schema: $ref: '#/components/schemas/OrdersRequestDTO' example: giveChainIds: - 1 - 137 - 250 takeChainIds: - 56 orderStates: - Created - Fulfilled externalCallStates: - NoExtCall filter: '' skip: 0 take: 1 blockTimestampFrom: null blockTimestampTo: null fulfiller: null unlockAuthorities: null maker: null creator: null referralCode: null orderAuthorityInSourceChain: null orderAuthorityInDestinationChain: null orderTradeType: null filterMode: CrossChain application/*+json: schema: $ref: '#/components/schemas/OrdersRequestDTO' example: giveChainIds: - 1 - 137 - 250 takeChainIds: - 56 orderStates: - Created - Fulfilled externalCallStates: - NoExtCall filter: '' skip: 0 take: 1 blockTimestampFrom: null blockTimestampTo: null fulfiller: null unlockAuthorities: null maker: null creator: null referralCode: null orderAuthorityInSourceChain: null orderAuthorityInDestinationChain: null orderTradeType: null filterMode: CrossChain responses: '200': description: OK content: application/json: schema: $ref: '#/components/schemas/OrdersResponseDTO' example: orders: - orderId: bytesValue: LHQS/4QxSDmHwiC+vdMuC07ZvjWfRhAUzF+SOBoy+tU= bytesArrayValue: >- ``` -------------------------------- ### initialize Function Source: https://docs.debridge.com/dmp-details/dev-guides/evm/periphery/CallProxy Initializes the CallProxy contract. ```solidity function initialize() public ``` -------------------------------- ### Widget Initialization Source: https://docs.debridge.com/dln-details/widget/deBridge-widget Demonstrates how to initialize the deBridge widget with various configuration options. ```APIDOC ## Widget Initialization The widget is initialized asynchronously using: ```typescript theme={null} const widget = await deBridge.widget(params); ``` ### Parameters for `deBridge.widget(params)` - **v** (string) - Required - Widget version. - **element** (string) - Required - The ID of the HTML element where the widget will be rendered. - **title** (string) - Optional - The title to display in the widget. - **description** (string) - Optional - A description to display in the widget. - **width** (string) - Optional - The width of the widget. - **height** (string) - Optional - The height of the widget. - **r** (string) - Required - A reference or routing parameter. - **supportedChains** (object) - Required - Defines supported input and output chains. - **inputChains** (object) - Supported input chains. - **[chainId]** (string) - e.g., "all" or specific chain identifiers. - **outputChains** (object) - Supported output chains. - **[chainId]** (string) - e.g., "all" or specific chain identifiers. - **inputChain** (number | string) - Required - The default input chain ID. - **outputChain** (number | string) - Required - The default output chain ID. - **inputCurrency** (string) - Required - The default input currency address or identifier. - **outputCurrency** (string) - Required - The default output currency address or identifier. - **address** (string) - Optional - An address parameter. - **showSwapTransfer** (boolean) - Optional - Whether to show swap and transfer options. - **amount** (string) - Optional - The initial input amount. - **outputAmount** (string) - Optional - The initial output amount. - **isAmountFromNotModifiable** (boolean) - Optional - If true, the input amount is not modifiable. - **isAmountToNotModifiable** (boolean) - Optional - If true, the output amount is not modifiable. - **lang** (string) - Optional - The language for the widget (e.g., "en"). - **mode** (string) - Optional - The widget mode (e.g., "deswap"). - **isEnableCalldata** (boolean) - Optional - If true, enables calldata functionality. - **styles** (string) - Optional - Base64 encoded styles for the widget. - **theme** (string) - Optional - The theme for the widget (e.g., "dark"). - **isHideLogo** (boolean) - Optional - If true, hides the deBridge logo. - **logo** (string) - Optional - A custom logo URL. - **disabledWallets** (array) - Optional - A list of disabled wallet identifiers. - **disabledElements** (array) - Optional - A list of disabled widget elements. ### Request Example ```json { "v": "1", "element": "debridgeWidget", "title": "Swap Tokens", "description": "Swap tokens securely and efficiently.", "width": "600", "height": "800", "r": "31805", "supportedChains": { "inputChains": {"1": "all", "10": "all"}, "outputChains": {"1": "all", "10": "all"} }, "inputChain": 7565164, "outputChain": 42161, "inputCurrency": "11111111111111111111111111111111111111111", "outputCurrency": "0xaf88d065e77c8cc2239327c5edb3a432268e5831", "showSwapTransfer": true, "lang": "en", "mode": "deswap", "styles": "e30=", "theme": "dark", "isHideLogo": false, "disabledWallets": [], "disabledElements": [] } ``` ### Styles Object The `styles` field within the widget parameters accepts an object with the following properties: ```typescript theme={null} { appBackground: string, appAccentBg: string, chartBg: string, primary: string, secondary: string, badge: string, borderColor: string, borderRadius: number, fontColor: string, fontColorAccent: string, fontFamily: string } ``` ``` -------------------------------- ### HTML Example for deBridge Widget Integration Source: https://docs.debridge.com/dln-details/widget/deBridge-widget Demonstrates how to embed and initialize the deBridge widget in an HTML page. Ensure the widget script is loaded before attempting to initialize. ```html Widget Example
``` -------------------------------- ### Configure External Instruction with Data Substitutions Source: https://docs.debridge.com/dmp-details/dev-guides/solana/on-chain-external-call-preparation Configure an ExternalInstruction to include data substitutions. This allows for dynamic data insertion into instructions, such as excluding a portion of a wallet balance for future transfers. ```Solidity DeBridgeSolana.ExternalInstruction memory externalInstruction = DeBridgeSolana.ExternalInstruction({ // [...] data_substitutions: dataSubstitutions }); ``` -------------------------------- ### Update Priority Fee Function Example Source: https://docs.debridge.com/dln-details/integration-guidelines/order-creation/creating-order/api-parameters/response An example of a function used to update the priority fee on the Solana network. This function is part of the debridge-finance/api-integrator-example. ```typescript const priorityFee = await getPriorityFee(connection); const transaction = new Transaction().add(SystemProgram.transfer({ fromPubkey: fromWallet.publicKey, toPubkey: toWallet.publicKey, lamports: 1000, })); transaction.recentBlockhash = (await connection.getLatestBlockhash()).blockhash; transaction.lastValidBlockHeight = (await connection.getLatestBlockhash()).lastValidBlockHeight; transaction.feePayer = fromWallet.publicKey; // Set priority fee transaction.setTransaction({ feePayer: fromWallet.publicKey, instructions: transaction.instructions, recentBlockhash: transaction.recentBlockhash, lastValidBlockHeight: transaction.lastValidBlockHeight, minContextSlot: undefined, priorityFee: priorityFee }); const signedTransaction = await signTransaction(transaction, fromWallet); const rawTransaction = signedTransaction.serializeMessage().toString('hex'); console.log(rawTransaction); ``` -------------------------------- ### Configure Affiliate Fee Parameters for Widget Source: https://docs.debridge.com/home/monetization/affiliate-fees Add `affiliateFeePercent` and `affiliateFeeRecipient` to your widget configuration to enable affiliate fees for widget integrations. ```javascript const widgetConfig = { // ... other config affiliateFeePercent: 100, // 1% fee affiliateFeeRecipient: "0xabc123..." }; ``` -------------------------------- ### EVM Cross-Chain Swap Example (TypeScript) Source: https://docs.debridge.com/dln-details/integration-guidelines/order-creation/creating-order/quick-start Demonstrates a USDC transfer from Polygon to Arbitrum, including ERC-20 approvals and deBridge API integrations. This script is useful for understanding cross-chain swap mechanics on EVM networks. ```typescript import { ethers } from "ethers"; import { DeBridge, OrderSide } from "@debridge/web3-sdk"; // --- Configuration --- const providerUrl = "https://polygon-rpc.com"; // Polygon RPC URL const privateKey = "YOUR_PRIVATE_KEY"; // Your private key const usdcContractAddress = "0x2791bca1f2de4661ed88a30c99a7a94e3cbba79c"; // USDC contract address on Polygon const debridgeRouterAddress = "0x4323777307146777177777777777777777777777"; // deBridge router address on Polygon const arbProviderUrl = "https://arb1.arbitrum.one/rpc"; // Arbitrum RPC URL const arbDebridgeRouterAddress = "0x4323777307146777177777777777777777777777"; // deBridge router address on Arbitrum const arbUsdcContractAddress = "0xaf88d065e77c8c24270774787a989f701909f6dc"; // USDC contract address on Arbitrum const amountToSwap = "0.1"; // Amount of USDC to swap const recipientAddress = "0x..."; // Recipient address on Arbitrum const arbChainId = 42161; // Arbitrum chain ID const polygonChainId = 137; // Polygon chain ID async function swapUsdc() { // --- Polygon Setup --- const polygonProvider = new ethers.providers.JsonRpcProvider(providerUrl); const wallet = new ethers.Wallet(privateKey, polygonProvider); const debridge = new DeBridge(wallet, debridgeRouterAddress); const usdcContract = new ethers.Contract(usdcContractAddress, ["function approve(address spender, uint256 amount) returns (bool)"], wallet); // --- Arbitrum Setup --- const arbProvider = new ethers.providers.JsonRpcProvider(arbProviderUrl); const arbWallet = new ethers.Wallet(privateKey, arbProvider); const arbDebridge = new DeBridge(arbWallet, arbDebridgeRouterAddress); const arbUsdcContract = new ethers.Contract(arbUsdcContractAddress, ["function balanceOf(address owner) view returns (uint256)"], arbWallet); // --- Approve USDC --- const amount = ethers.utils.parseUnits(amountToSwap, 6); // USDC has 6 decimals const approveTx = await usdcContract.approve(debridgeRouterAddress, amount); await approveTx.wait(); console.log("USDC approved successfully on Polygon."); // --- Submit Order --- const order = await debridge.submitOrder({ fromChainId: polygonChainId, toChainId: arbChainId, fromAmount: amount, fromAssetAddress: usdcContractAddress, toAssetAddress: arbUsdcContractAddress, toAddress: recipientAddress, side: OrderSide.ORDER_SIDE_LIMIT, limit: amount.mul(10001).div(10000) // Example limit: 0.01% slippage tolerance }); console.log("Order submitted successfully:", order); // --- Verify Balance on Arbitrum (Optional) --- const arbBalance = await arbUsdcContract.balanceOf(recipientAddress); console.log(`USDC balance on Arbitrum for ${recipientAddress}: ${ethers.utils.formatUnits(arbBalance, 6)}`); } swapUsdc().catch(console.error); ``` -------------------------------- ### Prepare and Create a DLN Order Source: https://docs.debridge.com/dln-details/integration-guidelines/smart-contracts/placing-orders Prepares order details, retrieves the protocol fee, approves the token, and creates an order using the DlnSource contract. Ensure sufficient native currency is provided for the `value` to cover the `globalFixedNativeFee`. ```solidity // 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, "" ); ``` -------------------------------- ### Get Quote for SOL to USDC on Solana Source: https://docs.debridge.com/dln-details/integration-guidelines/same-chain-swaps/engineer Use this endpoint to get a price quote for a token swap. The `slippage` parameter defaults to `auto` for optimal execution. ```json { "chainId": "7565164", "tokenIn": "11111111111111111111111111111111", // SOL on Solana "tokenInAmount": "200000", "tokenOut": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", // USDC on Solana, "slippage": "auto" // Default value } ``` -------------------------------- ### Docker Build and Run for debridge-mcp Source: https://docs.debridge.com/dln-details/mcp/mcp-server Instructions to build the debridge-mcp Docker image from source and run it. This is useful for containerized deployments. ```bash docker build -t debridge-mcp . docker run -p 3000:3000 debridge-mcp ``` -------------------------------- ### Default Values for createOrder() Arguments Source: https://docs.debridge.com/dln-details/integration-guidelines/smart-contracts/placing-orders Shows how to set default values for optional arguments in the createOrder() method. Affiliate fees require a 52-byte array, referral codes are uint256, and permit envelopes are EIP-2612 signed approvals. ```solidity _affiliateFee can be set to empty bytes array (0x); _referralCode can be set to zero (0); _permitEnvelope can be set to empty bytes array (0x); ``` -------------------------------- ### Calculate Token Allowance with Buffer Source: https://docs.debridge.com/dln-details/integration-guidelines/order-creation/creating-order/refreshing-estimates When `prependOperatingExpenses` is enabled, use this to calculate the token allowance by adding a 30% buffer to the estimated operating expense. This ensures the approved amount remains sufficient even if gas costs or execution fees rise before submission. ```typescript const { approximateOperatingExpense } = response.estimation.srcChainTokenIn; const approveAmount = srcChainTokenInAmount + approximateOperatingExpense * 1.3; ``` -------------------------------- ### Get Token Decimals Source: https://docs.debridge.com/dmp-details/dev-guides/evm/periphery/DeBridgeToken Public function to retrieve the number of decimals for the token. ```solidity function decimals() public returns (uint8) ``` -------------------------------- ### Search Tokens Query Example Source: https://docs.debridge.com/dln-details/mcp/mcp-server Use this JSON payload to query for token information, such as USDC on chain ID 1. The results are ranked by relevance. ```json { "query": "USDC", "chainId": "1" } ```