makeOrder Function
Function Type: external
Function Signature: makeOrder(address,MetadataMakeOrder,bytes,uint256,uint256,bool,bytes)
The makeOrder function creates a new token swap order in the P2P marketplace, allowing users to offer one token in exchange for another at a specified rate. This function handles market creation, order storage, and reward distribution for staker executors.
Key features:
- Order Creation: Establishes a new swap order offering tokenA for tokenB
- Automatic Market Creation: Creates new markets for previously unseen token pairs
- Staker Rewards: Executors who are stakers receive MATE token rewards and priority fees
- Signature Verification: Uses EIP-191 signatures for secure authorization
- EVVM Integration: Leverages EVVM payment system for token transfers
Parameters
| Field | Type | Description |
|---|---|---|
user | address | The address creating the order whose tokens will be locked and signature is verified |
metadata | MetadataMakeOrder | Struct containing order details (nonce, tokenA, tokenB, amountA, amountB) |
signature | bytes | EIP-191 signature from user authorizing the order creation |
_priorityFee_Evvm | uint256 | Fee amount distributed to stakers as reward for processing the transaction. |
_nonce_Evvm | uint256 | Nonce for EVVM payment transaction |
_priority_Evvm | bool | Priority flag (sync/async) for the EVVM payment function call. |
_signature_Evvm | bytes | EIP-191 signature for EVVM payment authorization |
MetadataMakeOrder Structure
| Field | Type | Description |
|---|---|---|
nonce | uint256 | Unique nonce for P2P Swap replay protection |
tokenA | address | Token being offered by the order creator |
tokenB | address | Token being requested in exchange |
amountA | uint256 | Amount of tokenA being offered |
amountB | uint256 | Amount of tokenB being requested |
Return Values
| Field | Type | Description |
|---|---|---|
market | uint256 | ID of the market where the order was placed |
orderId | uint256 | Unique ID of the created order within the market |
Execution Methods
Fisher Execution
- User signs both P2P order details and EVVM payment authorization
- Fisher captures the transaction and validates all signatures
- Fisher submits the transaction and receives staker rewards if eligible
- Order is created and tokens are locked in the contract
Direct Execution
- User or authorized service calls the function directly
- All signature validations are performed on-chain
- Order creation and token locking happen immediately
- Staker benefits are distributed if executor qualifies
Workflow
-
P2P Signature Verification: Validates the
signatureagainst theuseraddress and order metadata usingSignatureUtils.verifyMessageSignedForMakeOrder. Reverts with"Invalid signature"on failure. -
Nonce Validation: Checks if the P2P nonce has been used before by consulting
nonceP2PSwap[user][metadata.nonce]. Reverts with"Nonce already used"if the nonce was previously used. -
Token Transfer: Executes payment to lock the user's tokens using
makePaywith the provided EVVM parameters, transferringmetadata.amountAofmetadata.tokenAfromuserto the contract. -
Market Resolution: Determines the appropriate market using
findMarket(metadata.tokenA, metadata.tokenB). If no market exists (returns 0), creates a new market usingcreateMarket. -
Order ID Assignment: Assigns an order ID within the market:
- If market is at capacity (
maxSlot == ordersAvailable), incrementsmaxSlotand uses the new slot - Otherwise, finds the first available slot by iterating through existing orders
- Updates
ordersAvailablecounter
- If market is at capacity (
-
Order Storage: Stores the order in
ordersInsideMarket[market][orderId]with seller address, token amounts, and metadata. -
Staker Reward Distribution: If the executor (
msg.sender) is a registered staker:- Priority Fee Transfer: If
_priorityFee_Evvm > 0, transfers the priority fee inmetadata.tokenAto the executor - MATE Token Rewards: Grants MATE tokens to the executor:
- 3x base reward amount if priority fee was provided
- 2x base reward amount if no priority fee
- Priority Fee Transfer: If
-
Nonce Update: Marks the P2P nonce as used to prevent replay attacks.
Example
Scenario: User wants to create an order offering 100 USDC for 0.05 ETH
Parameters:
user:0x742c7b6b472c8f4bd58e6f9f6c82e8e6e7c82d8cmetadata.nonce:15metadata.tokenA:0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48(USDC)metadata.tokenB:0x0000000000000000000000000000000000000000(ETH)metadata.amountA:100000000(100 USDC, 6 decimals)metadata.amountB:50000000000000000(0.05 ETH in wei)_priorityFee_Evvm:1000000000000000(0.001 ETH priority fee)
Process:
- User signs the order details with their private key
- Fisher or user submits the transaction
- Contract validates signature and transfers 100 USDC to contract
- Order is assigned to USDC/ETH market (created if new)
- Order stored with unique ID for future fulfillment
- Staker executor receives priority fee + 3x MATE reward
Market Creation: If this is the first USDC/ETH order:
- New market created with ID (e.g., market #5)
- Market metadata initialized for USDC/ETH pair
- Order becomes first order in the new market
Order Assignment:
- Order receives ID #1 in the market
- Market statistics updated (maxSlot: 1, ordersAvailable: 1)
- Order can now be discovered and fulfilled by other users
For signature structure details, see Make Order Signature Structure
Want to cancel your order?
Use cancelOrder to cancel your order and reclaim your tokens.
Looking for existing orders?
Check the Getter Functions to browse available orders in different markets.