Market Makers
Execute Market-Making for Limit Orders
To fill a user’s limit order x
, market-makers must perform two actions:
Place an equal and opposite limit order
x*
.Call the function
make_order(x, x*)
.
Step 1: Placing the User's Limit Order
A user places a limit order with the following parameters:
swap: The source chain, source token, and source quantity.
to: The destination chain and destination token.
at: The price in wei.
with fee: The fee in basis points.
The quantity of the destination token (dst_token
) that the user will receive on the destination chain is calculated as:
Example
A user wants to place a limit order on the Avalanche chain. The example parameters are as follows:
Source Chain: Avalanche
Source Token:
0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E
Source Quantity: (1,000,000 units)
The function call to place this limit order would look like this:
solidityCopy codeplaceTrade(
src_chain = 'avalanche',
src_token = '0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E',
src_quantity = 10**6,
to = 'destination_chain', // Specify the destination chain
dst_token = 'destination_token', // Specify the destination token
wei_price = price_in_wei, // Specify the price in wei
bps_fee = fee_in_basis_points // Specify the fee in basis points
);
Step 2: Making the Order
After placing the limit order, the market-maker must place an equal and opposite limit order and then call the function make_order(x, x*)
to complete the process.
Example function call:
make_order(
x = user_order_details, // Details of the user's limit order
x* = market_maker_order_details // Details of the market-maker's equal and opposite limit order
);
How to Call placeTrade()
as a Maker
placeTrade()
as a MakerSetting the Fee
Do not set the fee to 0.
Set the fee to be the same amount that the user pays.
Receiving the Fee
As the guarantor in the smart contract, you will receive this fee once the transaction is executed.
Example
pythonCopy code# Assume fee_amount is calculated based on the user’s transaction
fee_amount = calculate_fee(user_transaction)
# As the maker, call placeTrade with the calculated fee amount
placeTrade(trade_details, fee=fee_amount)
By setting the fee correctly, you ensure proper fee handling and consistency in the Mach protocol.
For more detailed information, refer to the specific line of code on GitHub (line 298).
Last updated