# Margin Pool

*[Documentation index](/llms.txt) · [Full index](/llms-full.txt)*

The `MarginPool` is a shared object that manages liquidity for a specific asset, enabling lenders to supply assets and margin traders to borrow them. Each margin pool tracks supply and borrow positions, accrues interest over time, and enforces risk parameters to maintain system health.

Margin pools use a shares-based accounting system where suppliers receive shares representing their proportion of the total supply. Interest accrues continuously, increasing the value of these shares over time. Borrowers can only borrow from pools that have enabled their specific DeepBook trading pool.

## API

Following are the different public functions that the `MarginPool` exposes.

**Mint a `SupplierCap`**

Create a new `SupplierCap` that can be used to supply and withdraw from margin pools. One `SupplierCap` can be used across multiple margin pools.

<!-- External code reference: packages/deepbook_margin/sources/margin_pool.move -->

**Supply liquidity**

Supply assets to the margin pool to earn interest. Returns the total supply shares owned by the supplier after this operation.

<!-- External code reference: packages/deepbook_margin/sources/margin_pool.move -->

**Withdraw liquidity**

Withdraw supplied assets from the margin pool. You can specify an exact amount or withdraw all available shares.

<!-- External code reference: packages/deepbook_margin/sources/margin_pool.move -->

**Read endpoints**

<!-- External code reference: packages/deepbook_margin/sources/margin_pool.move -->

## Events

**`MarginPoolCreated`**

Emitted when a new margin pool is created.

<!-- External code reference: packages/deepbook_margin/sources/margin_pool.move -->

**`DeepbookPoolUpdated`**

Emitted when a DeepBook pool is enabled or disabled for lending.

<!-- External code reference: packages/deepbook_margin/sources/margin_pool.move -->

**`InterestParamsUpdated`**

Emitted when interest rate parameters are updated.

<!-- External code reference: packages/deepbook_margin/sources/margin_pool.move -->

**`MarginPoolConfigUpdated`**

Emitted when margin pool configuration is updated.

<!-- External code reference: packages/deepbook_margin/sources/margin_pool.move -->

**`SupplierCapMinted`**

Emitted when a new supplier cap is minted.

<!-- External code reference: packages/deepbook_margin/sources/margin_pool.move -->

**`AssetSupplied`**

Emitted when assets are supplied to a margin pool.

<!-- External code reference: packages/deepbook_margin/sources/margin_pool.move -->

**`AssetWithdrawn`**

Emitted when assets are withdrawn from a margin pool.

<!-- External code reference: packages/deepbook_margin/sources/margin_pool.move -->

**`MaintainerFeesWithdrawn`**

Emitted when maintainer fees are withdrawn.

<!-- External code reference: packages/deepbook_margin/sources/margin_pool.move -->

**`ProtocolFeesWithdrawn`**

Emitted when protocol fees are withdrawn.

<!-- External code reference: packages/deepbook_margin/sources/margin_pool.move -->

**`ProtocolFeesIncreased`**

Emitted when protocol fees are accrued from interest payments.

<!-- External code reference: packages/deepbook_margin/sources/margin_pool/protocol_fees.move -->
