πLimitOrderManager contracts
The `LimitOrderManager` is a critical component of the f(x) Protocol that enables users to create and execute limit orders for position management. This system allows traders to:
Open new positions when market conditions meet specific price criteria
Close existing positions at predetermined price levels
Set up stop-loss and take-profit orders for risk management
Execute complex trading strategies programmatically
Interacting with LimitOrderManager
To interact with LimitOrderManager, send a contract call to its address.
Key Functions
fillOrder(order, signature, makingAmount, takingAmount)
Executes a limit order by filling it with the specified amounts. (taker's operation)
cancelOrder(order)
Cancels an existing order (only callable by the order maker).
getOrderDetails(order)
Returns the order details (including making/taking tokens and amounts) for an order.
getExecution(orderHash)
Returns the current execution status of an order.
getOrderHash(order)
Calculates and returns the unique hash for a given order. This hash is used as the identifier for tracking order execution status.
increaseNonce()
Increments the caller's nonce, effectively invalidating all previously signed orders with the old nonce. Useful for batch cancelling multiple orders. (Basically, it means cancelAll)
Key Concepts
Order Structure
The Order struct contains the following key fields:
Pool Address: f(x) pool addresses, for example
WBTCLong :
0xAB709e26Fa6B0A30c119D8c55B887DeD24952473wstETHLong:
0x6Ecfa38FeE8a5277B91eFdA204c235814F0122E8WBTCShort:
0xA0cC8162c523998856D59065fAa254F87D20A5b0wstETHShort:
0x25707b9e6690B52C60aE6744d711cf9C1dFC1876LimitOrderManager: 0x112873b395B98287F3A4db266a58e2D01779Ad96
Making Amount vs Taking Amount
Making Amount: The amount of tokens the order maker is offering
Taking Amount: The amount of tokens the order maker wants to receive
These amounts are calculated based on the order type and side.
Order Hash
The Order Hash is a unique identifier for each order, calculated using the EIP712 standard. This hash serves as:
Unique Identifier: Each order has a distinct hash based on its parameters
Execution Tracker: Used to store and retrieve order execution status
Signature Target: The hash is what gets signed by the order maker
Database Key: Off-chain systems use this hash to index and track orders
The order hash is deterministic - the same order parameters will always produce the same hash. This allows for consistent tracking across different systems and ensures order integrity.
Signature
The Signature is a cryptographic proof that the order hash was authorized by the order maker. The signature content is the order hash (not the raw order data), ensuring any parameter changes invalidate the signature.
Signature Format:
EOA Signatures: 65 bytes (r, s, v) or 64 bytes (r, s) for EIP-2098 compact format
Smart Contract Signatures: Variable length, validated through EIP-1271
isValidSignaturemethod
Integrate Examples:
Signature Creation Example
How to Call fillOrder
Function Signature
Parameters
order: The order struct containing all order detailssignature: EIP712 signature from the order makermakingAmount: Amount of making tokens the filler providestakingAmount: Amount of taking tokens the filler wants from the order
Prerequisites
Valid Signature: The order must be properly signed by the maker
Order Validation: Order parameters must pass validation checks
Price Conditions: Trigger price conditions must be met (if applicable)
Token Approvals: Filler must approve tokens to the LimitOrderManager
Sufficient Balance: Filler must have sufficient token balance
Example Integration
Last updated