# Resolution period

| Previous state | State    | Next state(s)                             |
| -------------- | -------- | ----------------------------------------- |
| REDEEMED       | DISPUTED | <p>RETRACTED<br>RESOLVED<br>ESCALATED</p> |

#### Period actions

| Seller                     | Buyer                | Dispute resolver |
| -------------------------- | -------------------- | ---------------- |
| Extend the dispute timeout | Retracts the dispute | /                |
| Resolve the dispute        | Resolve the dispute  |                  |
|                            | Escalate the dispute |                  |

#### Post-period actions

| Seller             | Buyer              | Dispute resolver   |
| ------------------ | ------------------ | ------------------ |
| Expire the dispute | Expire the dispute | Expire the dispute |

### TypeScript SDK

{% tabs fullWidth="true" %}
{% tab title="Extend the dispute timeout" %}
Extends the dispute timeout, allowing more time for mutual resolution.

```typescript
const exchangeId = "1534";
const newTimeout = Date.now()/1000 + 5 * 24 * 60 * 60;

await sellerCoreSDK.extendDisputeTimeout(
    exchangeId,
    newTimeout
);
```

{% endtab %}

{% tab title="Resolve the dispute" %}
The buyer and the seller mutually resolve the dispute and submit the decision on how the pot is split.

#### The buyer signs the proposal; the seller submits the transaction

```typescript
const exchangeId = "1534";
const buyerPercentBasisPoints = 30_00;

const { signature } = await buyerCoreSDK.signDisputeResolutionProposal({
      exchangeId,
      buyerPercentBasisPoints
});

await sellerCoreSDK.resolveDispute({
      exchangeId: exchangeId,
      buyerPercentBasisPoints,
      signature
});
```

#### The seller signs the proposal; the buyer submits the transaction

```typescript
const exchangeId = "1534";
const buyerPercentBasisPoints = 30_00;

const { signature } = await sellerCoreSDK.signDisputeResolutionProposal({
      exchangeId,
      buyerPercentBasisPoints
});

await buyerCoreSDK.resolveDispute({
      exchangeId: exchangeId,
      buyerPercentBasisPoints,
      signature
});
```

{% endtab %}

{% tab title="Retract the dispute" %}
The buyer retracts the dispute. The outcome is equivalent to a normally completed exchange. The seller gets the price and the seller's deposit and the DR Fee is returned to the mutualizer.

```typescript
const exchangeId = "1534";

await buyerCoreSDK.retractDispute(exchangeId);
```

{% endtab %}

{% tab title="Escalate the dispute" %}
The dispute cannot be mutually resolved, and the Dispute Resolver is activated to decide on the split of the pot. The buyer must pay an escalation deposit to call this method. The escalation deposit is added to the pot that is then split between the seller and the buyer.

```typescript
const exchangeId = "1534";

await buyerCoreSDK.escalateDispute(exchangeId);
```

{% endtab %}

{% tab title="Expire the dispute" %}
If the seller and buyer did not perform any protocol action, the dispute can be expired. The outcome is equivalent to a normally completed exchange. The seller gets the price and the seller's deposit and the DR Fee is returned to the mutualizer.

```typescript
const exchangeId = "1534";

await coreSDK.expireDispute(exchangeId);
```

Multiple exchanges can be expired in a single transaction.

```typescript
const exchangeId1 = "1534";
const exchangeId2 = "2";
const exchangeId3 = "758";

await coreSDK.expireDisputeBatch([exchangeId1, exchangeId2, exchangeId3]);
```

{% endtab %}
{% endtabs %}

### Solidity

{% tabs fullWidth="true" %}
{% tab title="Extend the dispute timeout" %}
Extends the dispute timeout, allowing more time for mutual resolution.

```solidity
IBosonDisputeHandler bosonProtocol = IBosonDisputeHandler(_bosonProtocolAddress);
uint256 exchangeId = 1534;
uint256 newTimeout = block.timestamp + 1 days;

bosonProtocol.extendDisputeTimeout(exchangeId, newTimeout);
```

{% endtab %}

{% tab title="Resolve the dispute" %}
The buyer and the seller mutually resolve the dispute and submit the decision on how the pot is split.

#### The other party signed the proposal, and this contract is submitting the transaction

```solidity
IBosonDisputeHandler bosonProtocol = IBosonDisputeHandler(_bosonProtocolAddress);
uint256 exchangeId = 1534;
uint256 buyerPercent = 30_00;
bytes memory signature = 0x...; // must be provided by other signer

bosonProtocol.resolveDispute(exchangeId, buyerPercent, signature);
```

#### The other party is submitting the transaction, and this contract uses EIP1271 verification

```typescript
import { IERC1271 } from "@openzeppelin/contracts/interfaces/IERC1271.sol";

function isValidSignature(bytes32, bytes calldata) public view override returns (bytes4) {
    // validate the signature, e.g. ECDSA verification
    ...
    
    // If everything is ok, return the correct magic value
    return IERC1271.isValidSignature.selector;
}
```

{% endtab %}

{% tab title="Retract the dispute" %}
The buyer retracts the dispute. The outcome is equivalent to a normally completed exchange. The seller gets the price and the seller's deposit and the DR Fee is returned to the mutualizer.

```solidity
IBosonDisputeHandler bosonProtocol = IBosonDisputeHandler(_bosonProtocolAddress);
uint256 exchangeId = 1534;

bosonProtocol.retractDispute(exchangeId);
```

{% endtab %}

{% tab title="Escalate the dispute" %}
The dispute cannot be mutually resolved, and the Dispute Resolver is activated to decide on the split of the pot. The buyer must pay an escalation deposit to call this method. The escalation deposit is added to the pot that is then split between the seller and the buyer.

```solidity
IBosonDisputeHandler bosonProtocol = IBosonDisputeHandler(_bosonProtocolAddress);
uint256 exchangeId = 1534;

bosonProtocol.escalateDispute(exchangeId);
```

{% endtab %}

{% tab title="Expire the dispute" %}
If the seller and buyer did not perform any protocol action, the dispute can be expired. The outcome is equivalent to a normally completed exchange. The seller gets the price and the seller's deposit and the DR Fee is returned to the mutualizer.

```solidity
IBosonDisputeHandler bosonProtocol = IBosonDisputeHandler(_bosonProtocolAddress);
uint256 exchangeId = 1534;

bosonProtocol.expireDispute(exchangeId);
```

Multiple exchanges can be expired in a single transaction.

```solidity
IBosonDisputeHandler bosonProtocol = IBosonDisputeHandler(_bosonProtocolAddress);
uint256[] memory exchangeIds = new uint256[](3);

exchangeIds[0] = 1534;
exchangeIds[1] = 2;
exchangeIds[2] = 758;

bosonProtocol.expireDispute(exchangeId);
```

{% endtab %}
{% endtabs %}
