Automated Market Maker (AMM)
Automated Market Maker (AMM) system in Otmoic aims to provide price bases for cross-chain coin swaps while hedging on centralized exchanges to ensure the stability of assets for liquidity providers (LP Nodes).
AMM Process in Otmoic
Quoting Process
- Receive Quote Request: The system receives a quote request from a client and logs all necessary details.
- Query Orderbook: Checks current data from DEXs and centralized exchanges to ensure it's up-to-date.
- Balance Verification: Ensures the LP Node has sufficient balance. If not, the request is rejected.
- Hedging Check (if enabled): Confirms enough balance and liquidity on the centralized exchange and checks trading limits.
- Calculate Average Transaction Price: Uses the top levels of the orderbook to find a weighted average price.
- Fee Calculation: Applies a standard 0.3% fee and adjusts if needed to cover trading costs.
- Send Final Quote: Provides the adjusted quote back to the client.
Price Locking
- Verify Parameters: Ensures the quote is processed within the allowed timeframe.
- Re-check Balance: Confirms the LP Node's balance is still sufficient.
- Lock Balance: Locks the required balance for the transaction.
- Authentication: Verifies that the quote was issued by the system.
- Market Price Check: Compares the price at the time of quoting and locking. Rejects the request if market changes are too significant.
Transaction Execution
- TransferOut: Logs the transfer-out operation and sends an event to trigger the LP's next step.
- TransferIn: Logs the transfer-in step upon receiving confirmation of the transfer-out.
- Confirmation Steps: Ensures each part of the transfer process is complete, submitting hedging orders as needed and recording results.
Hedging Process
- Hedging Queue: Manages hedging operations sequentially to avoid issues with concurrent actions.
- Execution: Processes hedging based on market conditions and logs relevant details like order ID and fees.
- Unlock Balance: Updates balance status after hedging is completed to reflect changes promptly.