# PartyB Close Facet

### PartyB Close Facet

The **PartyB Close Facet** is the counterpart to the PartyA Close Facet. PartyB can either fill it (fully or partially) at a price favorable to PartyA, or accept a cancellation if PartyA has asked to back out.

This is one of the leanest facets in the protocol. PartyB's close-side responsibilities reduce to just these two actions.

> **Key Concepts:**
>
> * **Fill vs. Partial Fill:** PartyB can fill the full quantity requested in the close intent, or choose to fill only part of it. A partial fill leaves the remainder of the close intent open for further fills or cancellation.
> * **Price Favorability:** The fill price must be at least as favorable to PartyA as the price they specified in the close intent. For a BUY position PartyA is closing, this means PartyB must fill at or above PartyA's requested price.
> * **CANCEL\_PENDING:** When PartyA calls `cancelCloseIntent()` while a PartyB has the intent in progress, it moves to `CANCEL_PENDING` rather than cancelling immediately. `acceptCancelCloseIntent()` is how PartyB clears that pending state.
> * **Emergency Mode:** In emergency mode, PartyBs may have access to additional close-side actions not covered in this facet. This facet covers the standard path only.

***

#### fillCloseIntent()

Executes a full or partial closure of a trade based on an existing close intent. PartyB specifies the quantity they're willing to close and the price at which they'll do it. The price must be at least as good as what PartyA requested.

**Function Signature:**

```solidity
function fillCloseIntent(
    uint256 intentId,
    uint256 quantity,
    uint256 price
) external whenPartyNotPaused(msg.sender);
```

**Parameters:**

* **intentId:** The unique identifier of the close intent to fill.
* **quantity:** The amount to close. Can be equal to or less than the quantity in the close intent — partial fills are allowed, leaving the remainder open.
* **price:** The execution price. Must be at least as favorable to PartyA as the price they specified when creating the intent — the library enforces this and will revert if the condition isn't met.

***

#### acceptCancelCloseIntent()

Acknowledges and accepts a cancellation request that PartyA has already submitted. When PartyA calls `cancelCloseIntent()` on a live (non-expired) intent, it transitions to `CANCEL_PENDING` rather than cancelling outright pending PartyB to confirm they're not in the middle of processing it.&#x20;

**Function Signature:**

```solidity
function acceptCancelCloseIntent(uint256 intentId) external whenPartyNotPaused(msg.sender);
```

**Parameters:**

* **intentId:** The unique identifier of the close intent in `CANCEL_PENDING` state to accept the cancellation of.

***

#### Events

```solidity
event FillCloseIntent(uint256 indexed intentId, uint256 quantity, uint256 price);
event AcceptCancelCloseIntent(uint256 indexed intentId);
```

***
