This smart contract implements a peer-to-peer (P2P) order system for cryptocurrency trading, leveraging Zero-Knowledge TLS Notary proofs for secure and private transactions. The contract supports partial order filling, allowing for flexible trading options.
- Create sell orders for cryptocurrencies
- Support for partial order filling
- ZK TLS Notary proof verification for secure transactions
- Cancel orders (including partially filled orders)
- Retrieve user orders
The main components of the contract are:
Order<CoinType>
: Struct representing an orderP2POrderbook<CoinType>
: Struct managing the orderbook- Key functions for order management and execution
Initializes the P2P orderbook for a specific coin type.
Creates a new sell order with the following parameters:
fiat_currency
: The fiat currency for paymenttotal_crypto_amount
: Total amount of cryptocurrency to sellfiat_price_per_crypto
: Price per unit of cryptocurrency in fiatpayment_method
: Accepted payment methodmin_crypto_amount
: Minimum amount that can be purchased in a single transaction
Cancels an open or partially filled order.
Fills an order (partially or fully) with ZK proof verification.
Retrieves all order IDs associated with a user.
ORDER_STATUS_OPEN
: Newly created orderORDER_STATUS_PARTIALLY_FILLED
: Order that has been partially filledORDER_STATUS_FILLED
: Completely filled orderORDER_STATUS_CANCELLED
: Cancelled order
- Initialize the orderbook for a specific coin type.
- Sellers create orders specifying the total amount, price, and minimum fill amount.
- Buyers fill orders by providing the amount they want to purchase and a ZK proof of payment.
- The contract verifies the ZK proof and updates the order status accordingly.
- Sellers can cancel unfilled or partially filled orders at any time.
The verify_zk_proof<CoinType>
function is a placeholder that needs to be implemented with the specific ZK TLS Notary proof verification logic. This function should verify:
- The buyer has made the fiat payment
- The proof demonstrates knowledge of the TLS session key
- The payment details match the order and the crypto amount being purchased
- Ensure proper implementation of the ZK proof verification logic.
- Implement secure fund locking and transfer mechanisms (not included in this contract).
- Consider adding time limits or expirations for orders.
- Implement proper access controls and ensure only authorized actions are permitted.
Use the initialize_for_testing<CoinType>
function to set up the contract in a test environment.
- Implement a dispute resolution mechanism.
- Add support for buy orders in addition to sell orders.
- Integrate with a price oracle for real-time price updates.
- Implement an order matching engine for automatic order filling.