deBridge 백서

deBridge

원문

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

------ | ----------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `enableEstimate` | `true` or `false` | Forces the API to validate the resulting transaction and estimate its gas consumption. When enabled, the estimate is returned at `tx.gasLimit` in the response object. | <Info> To estimate a transaction, `senderAddress` must be set to the address that will execute it. This address must hold: * Enough of the input token to cover `srcChainTokenInAmount` * Enough native currency to cover the protocol [fixed fee](/dln-details/overview/fee-structure#fixed-fee) </Info> <Warning> If `srcChainTokenIn` is an ERC-20 token, an approval must be provided for the specified `srcChainTokenInAmount` to the spender specified in the [`tx.to` from the response](/dln-details/integration-guidelines/order-creation/creating-order/api-parameters/response#tx) **before** the endpoint is called. Failing to provide a valid approval will result in an error response. </Warning> ### Solana-Specific Parameters | **Parameter** | **Example Value** | **Description** | | ------------------------------- | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `skipSolanaRecipientValidation` | `true` or `false` | When set to `true`, skips the validation of the Solana `dstChainTokenOutRecipient` address. The validation is in place to prevent accidental loss of funds. Might be necessary when the recipient address is a program-derived address (PDA) or a multi-sig. | ## Example Request The following example shows a complete `create-tx` API request: > [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](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) This request demonstrates how all core parameters are combined to generate a valid and executable cross-chain order. # Deep Dive Reference to common and interesting use-cases. Deep dive into certain parameters. ### Estimation Only The `create-tx` endpoint is designed for both estimation and transaction construction. It can be safely called without specifying [authority or recipient addresses](/dln-details/integration-guidelines/order-creation/creating-order/api-parameters/api-parameters#authorities-and-recipient-address) when a wallet address is not yet available—for example, during early stages of interaction in a dApp. In such cases, the endpoint can still be used to suggest input or output token amounts. Once the wallet address becomes available, the same `create-tx` request can be repeated with the necessary parameters to retrieve a [full transaction call](/dln-details/integration-guidelines/order-creation/creating-order/api-parameters/response#tx). To maintain solver profitability and ensure the order remains valid upon submission, it is recommended to allow the API to compute a reasonable output amount. This is achieved by setting the `dstChainTokenOutAmount` parameter to `auto` in both the estimation and transaction calls. <Warning> Additionally, orders should be submitted within 30 seconds of retrieving the transaction from the API. This expiration window helps ensure the order remains profitable for solvers at the time of on-chain placement. </Warning> ### `prependOperatingExpenses` The prependOperatingExpenses setting is a boolean. It is recommended to enable this option: ``` prependOperatingExpenses = true ``` #### Enabled (prependOperatingExpenses=true) When enabled, operating expenses are calculated separately from the spread and added on top of the input token amount, making all fees fully transparent. This approach helps clarify exactly what is being paid in fees. For example, swapping 100 USDC on Arbitrum for 100 USDC on Polygon in our application displays a small fee (just over \$0.03), shown above the red line in the figure below. This represents the solver's operating expenses. <img alt="Prepend Operating Expenses" /> * **ERC20 Approval**: The total amount (including operating expenses) must be approved using the `approve` function. This value is provided in `response.estimation.srcChainTokenIn.amount`. * **Buffer Recommendations**: Estimates may need to be refreshed if there is a delay between generating the response and submitting `response.tx`. Updated operating expenses might require a new approval. * **Fulfillment Likelihood**: When `response.tx` is signed and submitted within 30 seconds, the probability of successful execution is over 99.9%. #### Disabled (prependOperatingExpenses=false) When disabled, `response.estimation.srcChainTokenIn.amount` equals the `srcChainTokenInAmount` specified in the original `create-tx` request. In this case, the [operating expenses](/dln-details/overview/fee-structure#runtime-costs-built-into-the-spread) are subtracted directly from the spread between the input value and `response.estimation.dstChainTokenOut`. In this case, an additional error should be covered. It occurs when the input amount is too small to pay for the order costs. ```json theme={null} { "errorCode": 12, "errorId": "ERROR_LOW_GIVE_AMOUNT", "errorMessage": "Given amount of input asset is too small to cover operational costs of Takers, cannot estimate reasonable outcome of an order", "reqId": "79a2c431-e52c-48c0-a12e-2a9960644a59" } ``` [Sample error request](https://dln.debridge.finance/v1.0/dln/order/create-tx?prependOperatingExpenses=false\&dstChainTokenOutAmount=auto\&srcChainId=137\&dstChainId=42161\&srcChainTokenIn=0x3c499c542cef5e3811e1192ce70d8cc03d5c3359\&dstChainTokenOut=0xaf88d065e77c8cc2239327c5edb3a432268e5831\&srcChainOrderAuthorityAddress=0x55a8f5cce1d53d9ff84ec0962882b447e5914db8\&dstChainOrderAuthorityAddress=0x55a8f5cce1d53d9ff84ec0962882b447e5914db8\&dstChainTokenOutRecipient=0x55a8f5cce1d53d9ff84ec0962882b447e5914db8\&srcChainTokenInAmount=100000\&referralCode=31085\&senderAddress=0x55a8f5cce1d53d9ff84ec0962882b447e5914db8). Both modes produce the same execution outcome, but enabling `prependOperatingExpenses` typically provides a clearer breakdown of the fee structure for end users. ### Minimum Input Amounts When creating an order with Solana as the destination chain and when `dstChainTokenOut` is [SOL](/dln-details/integration-guidelines/order-creation/creating-order/specifying-assets#sol-native-sol), the required minimum output amount for SOL is **0.001 (1000000 lamports)**. This is due to the minimum balance requirement for SOL accounts on the Solana network, which ensures that accounts remain rent-exempt and can cover transaction fees. Due to shifting market conditions, the minimum input amount for tokens on the source chain may vary. It is recommended to determine the minimum input amount for a given token by creating a [reverse-market order](/dln-details/integration-guidelines/order-creation/creating-order/quoting-strategies#reverse-market-order) with the `dstChainTokenOutAmount` set to `1000000` and the `srcChainTokenInAmount` set to `auto`. This approach allows following the market conditions, without hardcoding specific minimum input amounts for each token. # API Response Source: https://docs.debridge.com/dln-details/integration-guidelines/order-creation/creating-order/api-parameters/response Detailed descriptions of the `create-tx` API response structure. There are several sections to a `create-tx` response. You can see a full, real-world API response example [here](/dln-details/integration-guidelines/order-creation/creating-order/api-parameters/response-example). They are: ## USD Value Fields The response contains several fields that provide estimated USD values for the assets involved in the trade. These fields are for informational purposes only and are not intended for real-time trading decisions. ### `usdPriceImpact` Estimated price impact of the trade, expressed as a input amount USD value percentage. Can be both postive and negative, depending on the direction of the USD price movement caused by the trade. <Info> When the value is high, it is strongly advised to let the user know about the potential price impact of their trade. The exact threshold for what constitutes a "high" value may vary depending on the specific use case and user preferences. </Info> ### `protocolFee` Estimated fee charged by the DLN protocol for facilitating the trade. Equal to `costDetails` entry with `type` `DlnProtocolFee` `payload.feeAmount` value. ### `protocolFeeApproximateUsdValue` Estimated USD value of the `protocolFee`. For informative purposes only – not for real-time trading. ## `estimation` This field contains gas and fee-related estimates used in the transaction planning process. ## `srcChainTokenIn` This field is always present. Represents the structure of what the user wants to sell on the source chain. | **Field Name** | **Type** | **Description** | | ----------------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------ | | `address` | `string` | Source chain input asset address – what the user is trying to sell on the source chain. | | `chainId` | `integer` | Source chain ID. | | `decimals` | `integer` | Source chain input asset decimals. | | `name` | `string` | Source chain input asset name. | | `symbol` | `string` | Source chain input asset symbol. | | `amount` | `string` | Source chain input asset amount, taking the decimals into account. May differ from `srcChainTokenInAmount` if operating expenses were prepended. | | `approximateOperatingExpense` | `string` | Solver's operating expense for this swap. | | `mutatedWithOperatingExpense` | `boolean` | Signifies if the request had prepended operating expenses. | | `approximateUsdValue` | `integer` | Approximate USD value of the source chain input assets. For informative purposes only – not for real-time trading. | | `originApproximateUsdValue` | `integer` | Approximate USD value before operating expenses were prepended. Only present if the input asset was **not** a reserve asset. | *** ## `srcChainTokenOut` *(optional)* This field is only present if the input asset was not a reserve asset and had to be [pre-swapped](/dln-details/dln-specifics/bridging-non-reserve-assets#pre-order-swap). | **Field Name** | **Type** | **Description** | | --------------------- | --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `address` | `string` | Source chain output asset address – what the input asset was swapped for during the [pre-order-swap](/dln-details/dln-specifics/bridging-non-reserve-assets#pre-order-swap). | | `chainId` | `integer` | Source chain ID. | | `decimals` | `integer` | Source chain output asset decimals. | | `name` | `string` | Source chain output asset name. | | `symbol` | `string` | Source chain output asset symbol. | | `amount` | `string` | Source chain output asset amount, taking the decimals into account. | | `maxRefundAmount` | `string` | Solver’s maximum refundable operating expense. | | `approximateUsdValue` | `integer` | Approximate USD value of the output asset. For informative purposes only – not for real-time trading. | *** ## `dstChainTokenOut` This field is always present. Represents the structure of what the user wants to receive on the destination chain. | **Field Name** | **Type** | **Description** | | ----------------------------------- | --------- | ---------------------------------------------------------------------------------------------------- | | `address` | `string` | Destination chain output asset address – what the user wants to receive when the order is fulfilled. | | `chainId` | `integer` | Destination chain ID. | | `decimals` | `integer` | Destination chain output asset decimals. | | `name` | `string` | Destination chain output asset name. | | `symbol` | `string` | Destination chain output asset symbol. | | `amount` | `string` | Destination chain output asset amount, taking the decimals into account. | | `approximateUsdValue` | `integer` | Approximate USD value of the output asset `amount`. Informative only. | | `recommendedAmount` | `string` | Recommended output asset amount, considering fees and taker margin. | | `recommendedApproximateUsdValue` | `integer` | Approximate USD value of `recommendedAmount`. Informative only. | | `maxTheoreticalAmount` | `string` | The maximum theoretical output amount that users can receive. | | `maxTheoreticalApproximateUsdValue` | `integer` | Approximate USD value of `maxTheoreticalAmount`. Informative only. | ## `costDetails` An array describing the cost components associated with the trade. Each entry has a `type` field. Possible cost types include: * `PreSwap` * `PreSwapEstimatedSlippage` * `DlnProtocolFee` * `TakerMargin` * `EstimatedOperatingExpenses` * `AfterSwap` * `AfterSwapEstimatedSlippage` Each of the fields in the `costDetails` entries, aside from `PreSwap` and `AfterSwap`, has the `payload.feeAmount` field, which is a string representing the fee amount, specified in the base (smallest) units of the asset (e.g., wei for Ethereum). All the `costDetails` entries have `chainId`, `tokenIn`, `tokenOut`, `amountIn`, `amountOut`. <Tip> Cost details can be used to break down the various fees and costs associated with the trade, providing transparency and insights into how the final amounts are calculated. This can be particularly useful for users and integrators to understand the fee structure and make informed decisions about their trades. </Tip> ## **`tx`** Only `data` field is present for Solana, while all the fields are present for EVM-based chains. * `data`: The data that must be signed and submitted. It contains all necessary information to initiate a [cross-chain order](/dln-details/dln-specifics/bridging-reserve-assets), including cases involving [non-reserve assets](/dln-details/dln-specifics/bridging-non-reserve-assets). It is either a calldata (for EVM-based chains) or a serialized transaction (for Solana). * `to`: Destination address for the transaction. Acts as the spender in the `approve` call for ERC-20 tokens. Applicable to EVM source chains only. * `value`: [Flat fee](/dln-details/overview/fees-supported-chains) in the source chain's native currency charged by the DLN protocol. Applicable to EVM source chains only. * `gasLimit`: Simulated, estimated gas limit for the transaction for EVM chains. Present if [`enableEstimate` flag](/dln-details/integration-guidelines/order-creation/creating-order/api-parameters/api-parameters#transaction-estimation) was set to `true` in the request. ## **`prependedOperatingExpenseCost`** Estimated operating cost added to the transaction, adjusted for token decimals. Present only if the request was made with `prependOperatingExpenses` enabled. ## **`order`** An object containing details required to facilitate the cross-chain trade. * **`approximateFulfillmentDelay`**\ Estimated delay, in seconds, for the order to be fulfilled. * **`salt`**\ Randomized value used to ensure uniqueness in the order hash. * **`metadata`**\ Additional contextual information about the order. ## **`orderId`** A deterministic identifier for the order. The same ID is used on both source and destination chains and can be used to [track order status](/dln-details/integration-guidelines/order-creation/order-tracking-api/tracking-orders). ## **`fixFee`** [Flat fee](/dln-details/overview/fees-supported-chains) charged in the source chain's native currency. This matches `tx.value` for EVM-based chains. ## **`userPoints`** The number of deBridge points that the user will get for this trade. ## **`integratorPoints`** The number of deBridge points that the integrator will get for this trade. ## **`estimatedTransactionFee`** Estimated transaction fee for the source chain, expressed in the source chain's native currency. This is an estimate of the gas cost for executing the transaction. For both Solana and EVM-based chains, the `estimatedTransactionFee` field contains a `total` – in wei for EVM-chains or lamports for Solana, and a breakdown of the fee components in the `details` object. ## Solana For Solana, `estimatedTransactionFee.details` fields are: | Field | Value (lamports) | Comment | SolScan Link | | ----------------- | ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------ | | `nonceMaster` | `1002240` | Unique for each user - only paid once, the first time users create a deBridge order. | [Link](https://solscan.io/account/Bah1BsjAHVYWV6hNgnQ72g9eFGBuWkeuETdQwtMUGqbD#transfers). | | `giveOrderState` | `17115840` | Give order state account rent and [`fixedFee`](/dln-details/overview/fees-supported-chains) | [Link](https://solscan.io/account/DSbotE7UyqU2yGAGbj1Xkd4WMsMeAaVHaokvLL7LL8Ka). | | `giveOrderWallet` | `2039280` | Give order wallet rent. | [Link](https://solscan.io/account/CoZPnKSCF2iLVuHozE56wwffL2mRFtjaxdWfUe23sqkN). | | `txFee` | `5000` | Transaction fee for the Solana network. | | | `priorityFee` | `4000000` | Can be updated by partners. [Example](https://github.com/debridge-finance/api-integrator-example/blob/master/src/utils/solana.ts). [Update function](https://github.com/debridge-finance/api-integrator-example/blob/master/src/utils/index.ts#L136C17-L136C34). | | | **total** | **24162360** | Total costs, without updating the priority fee. | | ## EVM For EVM-based chains, `estimatedTransactionFee.details` fields are: * `gasLimit` * `baseFee` * `maxFeePerGas` * `maxPriorityFeePerGas` <Info> Unlike for Solana, EVM `fixedFee` is not included in the `estimatedTransactionFee.total` value, as it is placed separately as `tx.value` in the transaction. </Info> # Response Example Source: https://docs.debridge.com/dln-details/integration-guidelines/order-creation/creating-order/api-parameters/response-example Example create-tx response showing key fields and values. If we take a look at request below, where we are trading 1000 ARB on Arbitrum for Matic on Polygon, it will produce the following JSON response. > [https://dln.debridge.finance/v1.0/dln/order/create-tx?srcChainId=42161 > \&srcChainTokenIn=0x912ce59144191c1204e64559fe8253a0e49e6548 > \&srcChainTokenInAmount=1000000000000000000000 > \&dstCha
프로젝트로 돌아가기