The DLN API provides a convenient high-level interface to attach hooks to orders upon requesting an order creation transaction. 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 atomicsuccess-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 from the destination chain, which increases friction and worsens UX.
To specify the hook, use the dlnHook parameter of the create-tx endpoint. The value for this parameter must be a JSON in a specific format 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:
To easily attach an atomic success-required hook that executes an arbitrary transaction call via the default Universal hook, the DLN API provides a simple shortcut for that:
The data.to and data.calldata properties represent the transaction call that should be made, as explained in the Universal hook section. The gas property must be specified if:
the underlying call handles errors gracefully, which leads to underestimation of gas (see our investigation on this)
the transaction call can't be estimated currently, which leads to inability of the DLN API to properly estimate transaction costs.
Example of a hook that deposits 0.1 USDC to AAVE
The following snippet produces a dlnHook parameter that results a hook to deposit 0.1 USDC to AAVE on behalf of 0xc31dcE63f4B284Cf3bFb93A278F970204409747f:
constquery=newURLSearchParams({// 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 } })})
This simple shortcut would be transparently converted by the DLN API to a hook with the following properties:
The DLN API would encode it and inject into an order.
Example of a hook that deposits 0.1 USDC to AAVE
The following snippet produces a dlnHook parameter that results a hook to deposit 0.1 USDC to AAVE on behalf of 0xc31dcE63f4B284Cf3bFb93A278F970204409747f via the default Univarsal hook:
constquery=newURLSearchParams({// other parameters were omitted for clarity dstChainId:137, dstChainTokenOut:'0x3c499c542cef5e3811e1192ce70d8cc03d5c3359', dstChainTokenOutAmount:'100000', dlnHook:JSON.stringify({ type:"evm_hook_data_v1"; data: { "fallbackAddress":"0xc31dcE63f4B284Cf3bFb93A278F970204409747f","target":"0x0000000000000000000000000000000000000000","reward":"0","isNonAtomic":false,"isSuccessRequired":true, "targetPayload": "0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000794a61358d6845594f94dc1db02a252b5b4814ad000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000084617ba0370000000000000000000000003c499c542cef5e3811e1192ce70d8cc03d5c335900000000000000000000000000000000000000000000000000000000000186a0000000000000000000000000c31dce63f4b284cf3bfb93a278f970204409747f000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
} })})
Hook validity considerations
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.
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 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: