# Sell-side Protocol Functions

PoolLiquidityManager Functions for sell-side LPs

**Liquidity Management**

```solidity
function addLiquidity(uint256 amount) external
```

* **Purpose**: Add liquidity to the pool
* **Parameters**:
  * `amount`: Amount of liquidity to add
* **Note**: Creates a pending request that will be processed in the next cycle

```solidity
function reduceLiquidity(uint256 amount) external
```

* **Purpose**: Request to reduce liquidity from the pool
* **Parameters**:
  * `amount`: Amount of liquidity to reduce
* **Note**: Creates a pending request that will be processed in the next cycle

**Collateral Management**

```solidity
function addCollateral(address lp, uint256 amount) external
```

* **Purpose**: Add additional collateral to an LP position
* **Parameters**:
  * `lp`: Address of the LP receiving the collateral
  * `amount`: Amount of collateral to add

```solidity
function reduceCollateral(uint256 amount) external
```

* **Purpose**: Withdraw excess collateral if above the minimum requirement
* **Parameters**:
  * `amount`: Amount of collateral to reduce
* **Note**: Will fail if trying to withdraw below the required collateral ratio

**Interest Claims**

```solidity
function claimInterest() external
```

* **Purpose**: Claim accrued interest earned by providing liquidity
* **Note**: Can be called anytime interest has accrued to the LP

**Emergency Functions**

```solidity
function exitPool() external
```

* **Purpose**: Emergency exit when the pool is halted
* **Note**: Can only be used when the pool is in a halted state

#### PoolCycleManager Functions for LPs

**Rebalancing Operations**

```solidity
function rebalancePool(address lp, uint256 rebalancePrice) external
```

* **Purpose**: Perform rebalancing at the end of a cycle
* **Parameters**:
  * `lp`: Address of the LP performing the rebalance
  * `rebalancePrice`: Price at which to execute the rebalance
* **Note**: Must be called during the POOL\_REBALANCING\_ONCHAIN state

```solidity
function calculateLPRebalanceAmount(address lp, uint256 rebalancePrice) external view returns (uint256 rebalanceAmount, bool isDeposit)
```

* **Purpose**: Calculate how much an LP needs to deposit or will receive during rebalancing
* **Parameters**:
  * `lp`: Address of the LP
  * `rebalancePrice`: Price at which to calculate the rebalance
* **Returns**:
  * `rebalanceAmount`: Amount the LP needs to deposit or will receive
  * `isDeposit`: True if LP needs to deposit, false if LP will receive funds

```solidity
function getLPAssetShare(address lp) external view returns (uint256)
```

* **Purpose**: Get the LP's current share of the asset tokens in the pool
* **Parameters**:
  * `lp`: Address of the LP
* **Returns**: The LP's proportional share of the asset supply
* **Note**: Based on the LP's current liquidity commitment relative to total liquidity

```solidity
function getLPCycleAssetShare(address lp, uint256 expectedRebalancePrice) external view returns (uint256)
```

* **Purpose**: Calculate the LP's projected asset share after the current cycle completes
* **Parameters**:
  * `lp`: Address of the LP
  * `expectedRebalancePrice`: The price at which rebalancing is expected to occur
* **Returns**: The LP's projected share of the asset supply after the cycle
* **Note**: Takes into account pending requests that will be processed in the current cycle

```solidity
function getLPCollateralHealth(address liquidityManager, address lp) external view returns (uint8 health)

Purpose: Check the collateral health status of an lp
Returns: 3 = Healthy, 2 = Warning, 1 = Liquidatable
```

```solidity
function getLPPosition(address lp) external view returns (LPPosition memory)
```

* **Purpose**: Get detailed information about an LP's position
* **Parameters**:
  * `lp`: Address of the LP
* **Returns**: LP's liquidity commitment, collateral, and accrued interest

### Cycle Management (Anyone can call these functions)

Protocol operators manage the cycle transitions in the protocol.

```solidity
function initiateOffchainRebalance() external
```

* **Purpose**: Start the offchain rebalancing phase
* **Note**: Can only be called when the pool is active and the market is open

```solidity
function initiateOnchainRebalance() external
```

* **Purpose**: Start the onchain rebalancing phase after offchain rebalancing
* **Note**: Can only be called when the pool is in offchain rebalancing and the market is closed

```solidity
function rebalanceLP(address lp) external
```

* **Purpose**: Rebalance an LP that hasn't self-rebalanced before the window expires
* **Parameters**:
  * `lp`: Address of the LP to rebalance
* **Note**: Anyone can call this after the rebalance window expires

```solidity
function forceRebalanceLP(address lp) external
```

* **Purpose**: Force rebalance an LP when the halt threshold is reached
* **Parameters**:
  * `lp`: Address of the LP to force rebalance
* **Note**: Can only be called when the halt threshold is reached
