bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 31쪽 중 6쪽
oly.ts),
along with submitting a versioned transaction.
# Quoting Strategies
Source: https://docs.debridge.com/dln-details/integration-guidelines/order-creation/creating-order/quoting-strategies
Possible quoting strategies explained in detail.
DLN supports multiple quoting strategies that allow users to control how much is spent on the source chain and how much is
received on the destination chain. Each strategy is defined by how the `srcChainTokenInAmount` and `dstChainTokenOutAmount` fields
are set in the order input.
## Quoting Strategies Overview
### Market Order (Recommended)
```ts theme={null}
const orderInput: deBridgeOrderInput = {
...,
srcChainTokenInAmount: "<fixed_amount>",
dstChainTokenOutAmount: "auto",
...
};
```
* Default and most commonly used strategy.
* User defines the exact input amount.
* Protocol determines the best output amount.
✅ Recommended for most standard transfers.
Requirements:
* `srcChainTokenInAmount` = fixed numeric value
* `dstChainTokenOutAmount` = "auto"
***
### Market Order with Full Balance Utilization
```ts theme={null}
const orderInput: deBridgeOrderInput = {
...,
srcChainTokenInAmount: "max",
dstChainTokenOutAmount: "auto",
...
};
```
* Spends the full wallet balance.
* Useful for account abstraction, batch transfers, smart wallets.
Requirements:
* `srcChainTokenInAmount` = "max"
* `dstChainTokenOutAmount` = "auto"
A hands-on example can be found
[here](https://github.com/debridge-finance/api-integrator-example/blob/master/src/scripts/orders/max-bnb-to-poly.ts).
***
### Reverse Market Order
```ts theme={null}
const orderInput: deBridgeOrderInput = {
...,
srcChainTokenInAmount: "auto",
dstChainTokenOutAmount: "<fixed_amount>",
...
};
```
* User specifies how much to **receive**.
* Protocol calculates how much must be spent.
* Ideal for payment flows or contract interactions.
Requirements:
* `srcChainTokenInAmount` = "auto"
* `dstChainTokenOutAmount` = fixed numeric value
<Note>
An interesting use-case is improving user experience by
[determining the minimum input token amount dynamically](/dln-details/integration-guidelines/order-creation/creating-order/api-parameters/api-parameters#minimum-input-amounts).
</Note>
***
### Limit Order (Not Recommended)
```ts theme={null}
const orderInput: deBridgeOrderInput = {
...,
srcChainTokenInAmount: "<fixed_amount>",
dstChainTokenOutAmount: "<fixed_amount>",
...
};
```
* Defines both input and output amounts.
* Treated as a limit order.
* Will only be fulfilled if a solver accepts the exact terms.
<Warning>
Not recommended for production — risk of non-fulfillment.
</Warning>
Requirements:
* Both values must be fixed.
***
## Example: Order Input Structure
```ts theme={null}
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,
};
```
***
## Choosing a Strategy
| **Use Case** | **Recommended Strategy** |
| ---------------------------------- | ------------------------------- |
| Standard transfer with known input | Market Order |
| Full wallet balance transfer | Market Order with Full Balance |
| Target fixed destination output | Reverse Market Order |
| Exact 1-to-1 trade (limit) | Limit Order *(not recommended)* |
# Refreshing Estimates
Source: https://docs.debridge.com/dln-details/integration-guidelines/order-creation/creating-order/refreshing-estimates
How and when the estimates should be refreshed.
## Transaction Submission Timing
It is recommended that transactions returned by the `create-tx` API be signed and submitted within **30 seconds**. When `response.tx` is submitted
within this window, the likelihood of successful order execution exceeds **99.9%**.
There is no explicit time-to-live (TTL) on the transaction itself — i.e., the period between receiving the `create-tx` response and submitting it
on-chain. Transactions may remain valid for extended periods, especially when no [pre-order-swap](/dln-details/dln-specifics/bridging-non-reserve-assets) is
involved or the [pre-order-swap](/dln-details/dln-specifics/bridging-non-reserve-assets) is between stablecoins.
***
## Handling Operating Expense Fluctuations
When the `prependOperatingExpenses` [parameter](/dln-details/integration-guidelines/order-creation/creating-order/api-parameters/api-parameters) is
enabled, special attention must be paid to how token approval amounts are set.
If the allowance **exactly matches** `response.estimation.srcChainTokenIn.amount` and there's a delay — typically more than a minute — before
submitting `response.tx`, operating expenses may increase. In that case the estimate should be refreshed. If the updated expense exceeds the approved
amount, an additional approval step is required, degrading the experience.
### Recommendation
* **Set token allowance to infinity** if user experience allows
* **Or** add a 30% buffer when setting the allowance to absorb changes
```ts theme={null}
const { approximateOperatingExpense } = response.estimation.srcChainTokenIn;
const approveAmount = srcChainTokenInAmount + approximateOperatingExpense * 1.3;
```
This ensures the approved amount remains sufficient even if gas costs or execution fees rise before submission.
***
You can find more examples in the [code reference](https://github.com/debridge-finance/api-integrator-example/tree/master/src/scripts/orders)
# Specifying Assets
Source: https://docs.debridge.com/dln-details/integration-guidelines/order-creation/creating-order/specifying-assets
How to specify assets when creating an order.
# Specifying Assets
When creating an asset movement, it is essential to correctly specify the assets that will be included in a cross-chain order or a same-chain swap.
This section shows how to do it, and covers some special cases. This article is relevant for both same-chain swaps and cross-chain orders.
<Note>
Hands on examples can be found in the [examples repository](https://github.com/debridge-finance/api-integrator-example/tree/master).
</Note>
## EVM and SPL tokens
When specifying EVM or SPL tokens in an asset movement, token's contract/program address must be provided.
### EVM Example
```typescript theme={null}
const orderInput: deBridgeOrderInput = {
srcChainId: '42161',
srcChainTokenIn: "0xaf88d065e77c8cc2239327c5edb3a432268e5831", // USDC Arbitrum
srcChainTokenInAmount: "1000000", // 1 USDC (6 decimals)
dstChainId: '137',
dstChainTokenOut: "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359", // USDC Polygon
dstChainTokenOutRecipient: recipientAddress,
account: senderAddress,
srcChainOrderAuthorityAddress: senderAddress,
dstChainOrderAuthorityAddress: recipientAddress,
};
```
### Solana Example
```typescript theme={null}
const orderInput: deBridgeOrderInput = {
srcChainId: '7565164',
srcChainTokenIn: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", // USDC Solana
srcChainTokenInAmount: "1000000", // 1 USDC (6 decimals)
dstChainId: '137',
dstChainTokenOut: "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359", // USDC Polygon
dstChainTokenOutRecipient: evmUserAddress,
account: solWallet.publicKey.toBase58(),
srcChainOrderAuthorityAddress: solWallet.publicKey.toBase58(),
dstChainOrderAuthorityAddress: evmUserAddress,
};
```
## Native Assets
When specifying native assets, such as ETH on Ethereum or SOL on Solana, predefined identifiers for these assets must be used.
### EVM Example
On EVM chains, the native asset (e.g., ETH on Mainnet, ETH on Arbitrum, MATIC on Polygon, BNB on BNB) is represented by the zero address:
`0x0000000000000000000000000000000000000000`.
```typescript theme={null}
const orderInput: deBridgeOrderInput = {
srcChainId: '137',
srcChainTokenIn: "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359", // USDC Polygon
srcChainTokenInAmount: "1000000", // 1 USDC (6 decimals)
dstChainId: '56',
dstChainTokenOut: "0x0000000000000000000000000000000000000000",
dstChainTokenOutRecipient: recipientAddress,
account: senderAddress,
srcChainOrderAuthorityAddress: wallet.address,
dstChainOrderAuthorityAddress: recipientAddress
};
```
Wrapped versions of native assets (e.g., WETH, WMATIC) should be specified using their respective contract addresses.
### Solana Example
On Solana, we have two cases to consider: SOL and WSOL. It is important to not confuse the two.
#### SOL (Native SOL)
The native SOL asset is represented by the special identifier: `11111111111111111111111111111111`.
In this example, native SOL is moved to MATIC on Polygon:
```typescript theme={null}
const orderInput: deBridgeOrderInput = {
srcChainId: '7565164',
srcChainTokenIn: "11111111111111111111111111111111", // SOL native token
srcChainTokenInAmount: "100000000", // 0.1 SOL (9 decimals)
dstChainId: '137',
dstChainTokenOut: "0x0000000000000000000000000000000000000000", // Polygon native token
dstChainTokenOutRecipient: evmUserAddress,
account: solWallet.publicKey.toBase58(),
srcChainOrderAuthorityAddress: solWallet.publicKey.toBase58(),
dstChainOrderAuthorityAddress: evmUserAddress,
};
```
#### WSOL (Wrapped SOL)
The wrapped SOL asset is represented by the special identifier: `So11111111111111111111111111111111111111112`.
This example exchanged SOL for WSOL on Solana through a same-chain swap:
```typescript theme={null}
const sameChainSwapInput: SameChainSwapInput = {
chainId: '7565164',
tokenIn: "11111111111111111111111111111111", // native SOL
tokenInAmount: "100000000", // 0.1 SOL (9 decimals)
tokenOut: "So11111111111111111111111111111111111111112", // WSOL
tokenOutRecipient: solWallet.publicKey.toBase58(),
senderAddress: solWallet.publicKey.toBase58(),
};
```
# Integrating Hooks
Source: https://docs.debridge.com/dln-details/integration-guidelines/order-creation/hooks/integrating-hooks
Hooks integration guidelines.
The DLN API provides a convenient high-level interface to attach hooks to orders upon requesting [an order creation transaction](/dln-details/integration-guidelines/order-creation/creating-order/creating-order). The API takes the
burden of proper hook data validation, encoding, cost estimation, and simulation, ensuring that an order would get filled on the destination chain and
there is no technical inconsistencies that may prevent it. This is especially important for atomic success-required hooks, as an error during such
hook execution would prevent an order from getting filled, and an order's authority would need to initiate [a cancellation procedure](/dln-details/integration-guidelines/order-creation/cancelling-order) from the
destination chain, which increases friction and worsens UX.
To specify the hook, use the `dlnHook` parameter of the [`create-tx` endpoint](/api-reference/dln/this-endpoint-returns-the-data-for-a-transaction-to-place-a-cross-chain-dln-order). The value for this parameter must be a JSON object that describes the
hook for the given destination chain. Depending on the destination chain, different templates are available.
# Serialized instructions hook for Solana
To set the hook to be executed upon filling order on Solana (dstChainId=7565164), the following template should be used:
```typescript theme={null}
{ type: "solana_serialized_instructions"; data: "0x..." }
```
where data is represented as a versioned transaction with one or more instructions. Thus, only *non-atomic success-required* hooks are supported.
To craft a proper versioned transaction, use the [Creating Hook data for Solana](/dln-details/integration-guidelines/order-creation/hooks/solana-hook-data) guide.
<Accordion title="DlnHook encoding example">
```typescript theme={null}
dlnHook: JSON.stringify({
type: "solana_serialized_instructions";
data: "0x000000000000000001000000000000000000000000010000000000000000010000000000000000135d3e6be2a2ae5274cfe4007df2f62ed31c618f048337fd1435ca2dee2a0d5d12000000000000001968562fef0aab1b1d8f99d44306595cd4ba41d7cc899c007a774d23ad702ff60101fd97b70d573d364ef44769540777b1ecdc21b88ff7def38c45d020e271c589dc00010000000000000000000000000000000000000000000000000000000000000000000062584959deb8a728a91cebdc187b545d920479265052145f31fb80c73fac5aea00009845350d27001686985bbc5c4a3646c928d7de27ddab09f2de56d21537201c4300019845350d27001686985bbc5c4a3646c928d7de27ddab09f2de56d21537201c4300010c1e5ba8fe0ec5c5e44d12c2b6317a8781ca19ddb0e1532b136f418e1d588f9500010c1e5ba8fe0ec5c5e44d12c2b6317a8781ca19ddb0e1532b136f418e1d588f95000106ddf6e1d765a193d9cbe146ceeb79ac1cb485ed5f5b37913a8cf5857eff00a900000000000000000000000000000000000000000000000000000000000000000000000006a7d517187bd16635dad40455fdc2c0c124c68f215675a5dbbacb5f0800000000008c97258f4e2489f1bb3d1029148e0d830b5a1399daff1084048e7bd8dbe9f8590000ef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000974d0b69f43d964da48af118a28037ab921a95eae1e637497b22867ce416255a00016be7362bf52e4ea29063d29ab43a832253ed7c68b62cf68e8d706a2f9531c1eb0001c6fa7af3bedbad3a3d65f36aabc97431b1bbe4c2d2f6e0e47ca60203452f5d610000040000000000000000736f6c"
})
```
</Accordion>
# Transaction call hook for EVM
To easily attach an atomic success-required hook that executes an arbitrary transaction call via the default [Universal
hook](/dln-details/protocol-specs/evm-chains-hook-anatomy#universal-hook), the DLN API provides a simple shortcut for that:
```typescript theme={null}
{
type: "evm_transaction_call";
data: {
"to": "0x...",
"calldata": "0x...",
"gas": 0
}
}
```
The `data.to` and `data.calldata` properties represent the transaction call that should be made, as explained in the [Universal hook](/dln-details/protocol-specs/evm-chains-hook-anatomy#universal-hook) section. The `gas`
property must be specified if:
* the underlying call handles errors gracefully, which leads to [underestimation of gas](https://x.com/AlexSmirnov__/status/1538903343455772673).
* the transaction call can't be estimated currently, which leads to inability of the DLN API to properly estimate transaction costs.
<Accordion title="Deposit 0.1 USDC to AAVE Hook Example">
The following snippet produces a dlnHook parameter that results a hook to deposit 0.1 USDC to AAVE on behalf of `0xc31dcE63f4B284Cf3bFb93A278F970204409747f`:
```typescript theme={null}
const query = new URLSearchParams({
// other parameters were omitted for clarity
dstChainId: 137,
dstChainTokenOut: '0x3c499c542cef5e3811e1192ce70d8cc03d5c3359',
dstChainTokenOutAmount: '100000',
dlnHook: JSON.stringify({
type: "evm_transaction_call";
data: {
"to": "0x794a61358D6845594F94dc1DB02A252b5b4814aD",
"calldata": "0x617ba0370000000000000000000000003c499c542cef5e3811e1192ce70d8cc03d5c335900000000000000000000000000000000000000000000000000000000000186a0000000000000000000000000c31dce63f4b284cf3bfb93a278f970204409747f0000000000000000000000000000000000000000000000000000000000000000",
"gas": 0
}
})
})
```
</Accordion>
Full working example can be seen [here](https://github.com/debridge-finance/api-integrator-example/blob/master/src/scripts/hooks/evm-evm/basic.ts).
This simple shortcut would be transparently converted by the DLN API to a hook with the following properties:
```typescript theme={null}
{
fallbackAddress: dstChainTokenOutRecipient,
target: '0x0000000000000000000000000000000000000000',
reward: 0,
isNonAtomic: false,
isSuccessRequired: true,
targetPayload: {
to: dlnHook.data.to,
callData: dlnHook.calldata.data,
gas: dlnHook.data.gas
}
}
```
# Arbitrary hook for EVM
To provide a complete customization of a hook, the DLN API offers a template that fully replicates the
[HookDataV1](/dln-details/protocol-specs/evm-chains-hook-anatomy) struct:
```json theme={null}
{
"type": "evm_hook_data_v1",
"data": {
"fallbackAddress": "0x...",
"target": "0x...",
"reward": "0",
"isNonAtomic": boolean,
"isSuccessRequired": boolean,
"targetPayload": "0x"
}
}
```
The DLN API would encode it and inject into an order.
# Hook validity considerations
<Warning>
To ensure best and frictionless user experience, the DLN API would refuse to return a transaction to create an order if it is impossible to
fulfill an order with the given hook.
</Warning>
The hook is attached to the order during order's placement on the source chain, however actual fulfillment occurs on the destination chain. If the
attached hook is success-required and exits unsuccessfully upon fulfillment, it prevents the entire order from getting filled. This would necessitate
an order's authority to initiate [a cancellation procedure](/dln-details/integration-guidelines/order-creation/cancelling-order) from the destination chain, which increases friction and worsens UX.
To prevent this, the DLN API constructs a potential transaction to fulfill the order to be created, and simulates this transaction internally to
ensure that the order to be created could actually be filled. If such simulation causes an error, that points to the problem within the hook, the API
would refuse to return a transaction, but would return an error with details instead, so you can debug the potential fulfillment transaction to find a
pitfalls in the hook:
```json theme={null}
{
"errorId": "HOOK_FAILED",
"errorPayload": {
"potentialFulfillOrderTxSimulation": {
"simulationInput": {
"chainId": number,
"blockNumber": number,
"tx": {
"from": string,
"to": string,
"data": string,
"value"?: string
},
},
"simulationError": {
"errorName": string,
"data": string,
}
}
}
}
```
# Solana Hook Data
Source: https://docs.debridge.com/dln-details/integration-guidelines/order-creation/hooks/solana-hook-data
Solana-specific hook data.
# Order creation
Make sure that you're creating order with `receiver=exe59FS5cojZkPJVDFDV8RnXCC7wd6yoBjsUtqH7Zai` (hex:
`0x09b966be097f46dcf58ebaae2365f56b74cd218a2b8c62468ffa4c53d484b053`)
This is the program that deserializes calldata, converts it into Solana TransactionInstructions and executes them via CPI.
# Intro
Solana calldata is a serialized `TransactionInstruction` list with additional metadata (see next sections). It can be serialized using a wasm module
built by deBridge.
After order fulfillment funds are transferred to the AUTHORITY\_PLACEHOLDER (in case take token is native sol). When take token is SPL token funds are
being transferred to the WALLET\_PLACEHOLDER.
During calldata execution (via UI or automatic executor) executor (entity that sends transaction with ExecuteExternalCall instruction) transfers
*rewards* amount of native Sol to AUTHORITY\_PLACEHOLDER and receives *expenses* amount of take token from WALLET\_PLACEHOLDER.
Each calldata instruction is signed by AUTHORITY\_PLACEHOLDER during execution, no additional signatures could be passed to the CPI.
# Expenses
Determine how much lamports your instruction spends on the destination network (most often, for account creation). Record this value as expenses. Each
instruction is technically worth 5000 lamports (since we can't determine how many resources it will spend in advance, the implication is that it can
be executed in a separate transaction). Therefore, 5000 + expenses is the estimate of how much lamports will cost the execution.
## Rewards
Reward is an amount that covers taker expenses (expenses field) and makes execution of calldata profitable for executor => makes calldata to be
executed automatically. Reward for each instruction is ded프로젝트로 돌아가기