Path: blob/main/docs/versioned_docs/version-v0.26/02-guide/07-interchange/06-creating-sell-orders.md
1007 views
---
---
Create Sell Orders
In this chapter, you implement the logic for creating sell orders.
The packet proto file for a sell order is already generated. Add the seller information:
Now, use Ignite CLI to build the proto files for the send-sell-order
command. You used this command in a previous chapter.
Message Handling in SendSellOrder
Sell orders are created using the send-sell-order
command. This command creates a transaction with a SendSellOrder
message that triggers the SendSellOrder
keeper method.
The SendSellOrder
command:
Checks that an order book for a specified denom pair exists.
Safely burns or locks token.
If the token is an IBC token, burn the token.
If the token is a native token, lock the token.
Saves the voucher that is received on the target chain to later resolve a denom.
Transmits an IBC packet to the target chain.
On Receiving a Sell Order
When a "sell order" packet is received on the target chain, you want the module to:
Update the sell order book
Distribute sold token to the buyer
Send the sell order to chain A after the fill attempt
Implement the FillSellOrder Function
The FillSellOrder
function tries to fill the buy order with the order book and returns all the side effects:
Implement The LiquidateFromSellOrder Function
The LiquidateFromSellOrder
function liquidates the first sell order of the book from the buy order. If no match is found, return false for match:
Implement the OnAcknowledgement Function for Sell Order Packets
After an IBC packet is processed on the target chain, an acknowledgement is returned to the source chain and processed by the OnAcknowledgementSellOrderPacket
function.
The dex module on the source chain:
Stores the remaining sell order in the sell order book.
Distributes sold tokens to the buyers.
Distributes the price of the amount sold to the seller.
On error, mints the burned tokens.
Add the OnTimeout of a Sell Order Packet Function
If a timeout occurs, mint back the native token:
Summary
Great, you have completed the sell order logic.
It is a good time to make another git commit again to save the state of your work: