The trade flow

1. Nora and Levi enter limit orders on tanX.

Nora wants to trade 1 ETH for 2000 USDC, and Bob wants to trade 2000 USDC for 1 ETH. They both enter limit orders using tanX.

2. tanX sends a settlement request transaction to Starkware.

tanX matches the limit orders of Nora and Levi, and sends a settlement request transaction to the Starkware gateway, using the add_transaction API with the SettlementRequest transaction type. The API call includes both orders, including the actual amounts transferred between Nora’s and Levi’s vaults.

The request that the application sends to the Starkware REST API includes the following information for each party:

3. Starkware validates the settlement request.

Starkware checks the following to validate the settlement request:

  • The ids of the assets of the two orders match.

  • The ratio between the amount to sell and the amount to buy matches the ratio that each party signed on. Both Nora and Levi want to trade at a ratio of 1 ETH to 2000 USDC.

  • Each of the orders in the settlement request is signed by a Stark key that corresponds to the order’s vault id.

  • The balance in each vault id is sufficient to fulfill the trade.

  • The maximum fee that both parties are willing to pay for the transaction is not less than the actual fee.

  • Neither order has already been fulfilled, and the amount to be traded does not cause Nora or Levi to transfer more than what they signed on in the order.

  • The settlement request has not expired.

4. Starkware includes the settlement in a batch.

If the settlement request is valid, the settlement is included in a batch to be submitted on-chain along with a validity proof.

Last updated