# Escalation period

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

#### Period actions

| Seller              | Buyer                | Dispute resolver   |
| ------------------- | -------------------- | ------------------ |
| Resolve the dispute | Retracts the dispute | Decide the dispute |
|                     | Resolve the dispute  | Refuse to decide   |

#### Post-period actions

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

***

### TypeScript SDK

{% tabs fullWidth="true" %}
{% 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.

```typescript
const exchangeId = "1534";

await buyerCoreSDK.retractDispute(exchangeId);
```

{% endtab %}

{% tab title="Decide the dispute" %}
The dispute resolver decides the split of the whole pot.

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

await drCoreSDK.decideDispute(exchangeId, buyerPercentBasisPoints);
```

{% endtab %}

{% tab title="Refuse escalated dispute" %}
The dispute resolver decides not to decide the dispute. The exchange is reverted. The seller gets back the seller's deposit and the buyer gets the price.

```typescript
const exchangeId = "1534";

await drCoreSDK.refuseEscalatedDispute(exchangeId);
```

{% endtab %}

{% tab title="Expire the escalated dispute" %}
If the seller, the buyer and the dispute resolver did not perform any protocol action, the escalated dispute can be expired. The outcome is equivalent to refused escalated dispute. The seller gets back the seller's deposit and the buyer gets the price.

```typescript
const exchangeId = "1534";

await coreSDK.expireEscalatedDispute(exchangeId);
```

{% endtab %}
{% endtabs %}

### Solidity

{% tabs fullWidth="true" %}
{% 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.

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

bosonProtocol.retractDispute(exchangeId);
```

{% endtab %}

{% tab title="Decide the dispute" %}
The dispute resolver decides the split of the whole pot.

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

bosonProtocol.decideDispute(exchangeId, buyerPercent);
```

{% endtab %}

{% tab title="Refuse escalated dispute" %}
The dispute resolver decides not to decide the dispute. The exchange is reverted. The seller gets back the seller's deposit and the buyer gets the price.

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

bosonProtocol.refuseEscalatedDispute(exchangeId);
```

{% endtab %}

{% tab title="Expire the escalated dispute" %}
If the seller, the buyer and the dispute resolver did not perform any protocol action, the escalated dispute can be expired. The outcome is equivalent to refused escalated dispute. The seller gets back the seller's deposit and the buyer gets the price.

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

bosonProtocol.expireEscalatedDispute(exchangeId);
```

{% endtab %}
{% endtabs %}
