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.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.
10,000 is a basis point denominator. More details here.
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
DlnSourcecontract spend tokens on your behalf, - call the
DlnSource.createOrder()method
Preparing OrderCreation struct
OrderCreation has the following structure:
Preparing other arguments
Subsequent arguments of thecreateOrder() method can be safely omitted by specifying the default values:
_affiliateFeecan 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._referralCodecan 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._permitEnvelopecan 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 theDlnSourcecontract to spend tokens on your behalf. This argument acceptsamount+deadline+signatureas 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 thevalue to
cover the DLN protocol fee (globalFixedNativeFee).
Order Preparation
Order Preparation
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.
Tracking order status
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 theDlnDestination.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:
DlnDestination contact:
FulfilledOrderwhenever the order has been successfully fulfilled.SentOrderCancelwhenever the cancel procedure has been initiated, as per order’sorderAuthorityAddressDstrequest.
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 (thetakeChainId 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:
- mind that only the
orderAuthorityAddressDstaddress 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
_orderargument, use theOrderstructure obtained from theCreatedOrder()upon order creation; - for the
_cancelBeneficiaryargument, use the address you’d like the given funds to be unlocked to on the source chain. Whenever theallowedCancelBeneficiarySrchas been explicitly provided upon order creation, you are only allowed to use that value; - for the
_executionFeeargument, 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 and claim it manually. Consider understanding how the cross-chain call is handled.