# Pledge

The Pledge Facet manages pledge collateral — a separate collateral pool that PartyBs deposit as a guarantee of good behavior. Pledge collateral is independent of the trading collateral used for positions and serves as a "skin in the game" mechanism. If a PartyB acts maliciously (e.g., abuses the Auto Deleveraging system by closing positions at unfair prices), their pledge can be slashed by an admin. The underlying logic is implemented in the `PledgeFacetImpl` library.

Pledge collateral is primarily used as a penalty mechanism for ADL (Auto-Deleveraging). Before enabling ADL for a PartyB via `ControlFacet.setADLEnabled`, they should have deposited sufficient pledge collateral. This ensures PartyBs are incentivized to use ADL fairly.

***

### Overview

The Pledge Facet provides the following key functionalities:

* **Deposit Pledge:** PartyB deposits pledge collateral in any ERC-20 token.
* **Request Pledge Withdrawal:** PartyB requests to withdraw pledge collateral, subject to admin approval.
* **Cancel Pledge Withdrawal:** PartyB cancels a pending withdrawal request.
* **Accept Pledge Withdrawal:** Admin approves a pending withdrawal, transferring funds to the requested recipient.
* **Slash Pledge:** Admin deducts pledge collateral as a penalty and redirects it to a specified recipient.

***

### depositPledge()

Deposits pledge collateral for the caller. Any ERC-20 token can be used. Amounts are in the token's native decimals (not normalized to 18 decimals).

**Function Signature:**

```solidity
function depositPledge(address token, uint256 amount) external whenNotAccountingPaused notSuspended(signer);
```

**Parameters:**

* `token`: The ERC-20 token address to deposit.
* `amount`: The amount to deposit (in the token's native decimals).

**Events Emitted:**

* `PledgeCollateralDeposited(address partyB, address token, uint256 amount)`

***

### requestPledgeWithdraw()

Requests withdrawal of pledge collateral to a specified recipient. The withdrawal is not immediate — it requires admin approval via `acceptPledgeWithdraw`. This two-step flow prevents PartyBs from quickly withdrawing pledge before a slashing can be applied.

Only one withdrawal request can be pending at a time per PartyB.

**Function Signature:**

```solidity
function requestPledgeWithdraw(address token, uint256 amount, address recipient) external whenNotAccountingPaused notSuspended(signer);
```

**Parameters:**

* `token`: The ERC-20 token to withdraw.
* `amount`: The amount to withdraw (in the token's native decimals).
* `recipient`: The address that will receive the funds if the withdrawal is approved.

**Events Emitted:**

* `PledgeWithdrawRequested(address partyB, address token, uint256 amount, address recipient)`

***

### cancelPledgeWithdraw()

Cancels a pending pledge withdrawal request.

**Function Signature:**

```solidity
function cancelPledgeWithdraw() external whenNotAccountingPaused notSuspended(signer);
```

**Events Emitted:**

* `PledgeWithdrawCancelled(address partyB, address token, uint256 amount)`

***

### acceptPledgeWithdraw()

Approves a pending pledge withdrawal and transfers the funds to the recipient specified in the original request.

**Function Signature:**

```solidity
function acceptPledgeWithdraw(address user, uint256 amount, address token) external whenNotAccountingPaused onlyRole(PARTY_B_MANAGER_ROLE);
```

**Parameters:**

* `user`: The PartyB whose withdrawal request is being approved.
* `amount`: The amount to withdraw (must match the request).
* `token`: The ERC-20 token to withdraw (must match the request).

**Access:** Requires `PARTY_B_MANAGER_ROLE`.

**Events Emitted:**

* `PledgeWithdrawApproved(address partyB, address token, uint256 amount)`

***

### slashPledge()

Slashes a PartyB's pledge collateral as a penalty and transfers the deducted amount to a specified recipient. This is used when a PartyB misbehaves — for example, by abusing ADL to close positions at prices that unfairly harm PartyA.

**Function Signature:**

```solidity
function slashPledge(address user, address token, uint256 amount, address recipient) external whenNotAccountingPaused onlyRole(PARTY_B_MANAGER_ROLE);
```

**Parameters:**

* `user`: The PartyB being penalized.
* `token`: The ERC-20 token to deduct.
* `amount`: The penalty amount (in the token's native decimals).
* `recipient`: The address receiving the penalty funds.

**Access:** Requires `PARTY_B_MANAGER_ROLE`.

**Events Emitted:**

* `UserSlashed(address partyB, address token, uint256 amount, address recipient)`
