PartyA Close Facet

The PartyA Close Facet manages the close side of a trade from PartyA's perspective. PartyB then has a window to fill it. If things don't go to plan, PartyA can request cancellation or let the intent expire.

Key Concepts:

  • Close Intent: A signed expression of PartyA's desire to close an open trade at a specified price and quantity. Think of it as a limit order for closing a position — it sits pending until PartyB fills it or it expires.

  • Partial Close: The quantity parameter allows PartyA to close only part of an open position, leaving the remainder running. The trade isn't fully closed until its full quantity has been covered.

  • Deadline: A timestamp after which the close intent is no longer valid. Once past the deadline, anyone can call expireCloseIntent() to formally transition it to EXPIRED state.

  • CloseIntentStatus: An enum tracking where an intent is in its lifecycle — relevant states here are PENDING (just created), EXPIRED (past deadline), and CANCEL_PENDING (PartyA has requested cancellation but PartyB hasn't acknowledged yet).

  • Instant Mode: When a user has instant mode active, creating or cancelling close intents is blocked. Instant mode has its own separate settlement path.


Overview

The close lifecycle from PartyA's side follows a straightforward flow:

  1. PartyA has an open trade and wants to close it — they call sendCloseIntent() specifying the trade, the price they'll accept, the quantity, and a deadline

  2. The intent sits in PENDING state waiting for PartyB to fill it

  3. If the deadline passes without a fill, anyone (including PartyA) can call expireCloseIntent() to formally mark it as EXPIRED

  4. If PartyA wants to cancel before the deadline, they call cancelCloseIntent() — depending on whether the deadline has already passed, this either moves the intent directly to EXPIRED or puts it into CANCEL_PENDING, waiting for PartyB to acknowledge the cancellation


sendCloseIntent()

Creates a new close intent for an existing open trade. Only the PartyA who owns the trade can submit one, and they must not have instant mode active. Returns the newly assigned intent ID.

Function Signature:

Parameters:

  • tradeId: The ID of the open trade to close. The caller must be the PartyA of this trade.

  • quantity: The amount of the trade to close. Can be less than the full trade size for partial closures.

  • price: The price at which PartyA is willing to close. For a long position, this acts as a minimum acceptable price. For example, if the market is at $1000, PartyA might set this to $990 to allow some slippage.

  • deadline: A Unix timestamp. If PartyB hasn't filled the intent by this time, it can be expired.


expireCloseIntent()

Transitions a batch of close intents to EXPIRED state once their deadlines have passed. This is a public function — anyone can call it.

Function Signature:

Parameters:

  • expiredIntentIds: An array of close intent IDs to expire. Each must have a deadline that has already passed.

Example Usage:


cancelCloseIntent()

Requests cancellation of one or more close intents. The resulting state depends on whether the intent's deadline has already passed:

  • If the deadline has passed → intent immediately moves to EXPIRED

  • If the deadline has not passed → intent moves to CANCEL_PENDING, awaiting PartyB's acknowledgement

This two-path behaviour means PartyA can use a single function whether they're cleaning up expired intents they created or actively asking to cancel a live one.

Function Signature:

Parameters:

  • intentIds: An array of close intent IDs to cancel. The caller must be the PartyA of each intent.


Last updated