docs/content/standards/deepbook-margin/contract-information/margin-pool.mdx
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.
Following are the different public functions that the MarginPool exposes.
Create a new SupplierCap that can be used to supply and withdraw from margin pools. One SupplierCap can be used across multiple margin pools.
<ImportContent source="packages/deepbook_margin/sources/margin_pool.move" mode="code" org="MystenLabs" repo="deepbookv3" fun="mint_supplier_cap" />
</details> <details> <summary>Supply liquidity</summary>Supply assets to the margin pool to earn interest. Returns the total supply shares owned by the supplier after this operation.
<ImportContent source="packages/deepbook_margin/sources/margin_pool.move" mode="code" org="MystenLabs" repo="deepbookv3" fun="supply" />
</details> <details> <summary>Withdraw liquidity</summary>Withdraw supplied assets from the margin pool. You can specify an exact amount or withdraw all available shares.
<ImportContent source="packages/deepbook_margin/sources/margin_pool.move" mode="code" org="MystenLabs" repo="deepbookv3" fun="withdraw" />
</details> <details> <summary>Read endpoints</summary><ImportContent source="packages/deepbook_margin/sources/margin_pool.move" mode="code" org="MystenLabs" repo="deepbookv3" fun="id,deepbook_pool_allowed,total_supply,supply_shares,total_borrow,borrow_shares,last_update_timestamp,supply_cap,protocol_fees,max_utilization_rate,protocol_spread,min_borrow,interest_rate,user_supply_shares,user_supply_amount" />
</details>Emitted when a new margin pool is created.
<ImportContent source="packages/deepbook_margin/sources/margin_pool.move" mode="code" org="MystenLabs" repo="deepbookv3" struct="MarginPoolCreated" />
</details> <details> <summary>`DeepbookPoolUpdated`</summary>Emitted when a DeepBook pool is enabled or disabled for lending.
<ImportContent source="packages/deepbook_margin/sources/margin_pool.move" mode="code" org="MystenLabs" repo="deepbookv3" struct="DeepbookPoolUpdated" />
</details> <details> <summary>`InterestParamsUpdated`</summary>Emitted when interest rate parameters are updated.
<ImportContent source="packages/deepbook_margin/sources/margin_pool.move" mode="code" org="MystenLabs" repo="deepbookv3" struct="InterestParamsUpdated" />
</details> <details> <summary>`MarginPoolConfigUpdated`</summary>Emitted when margin pool configuration is updated.
<ImportContent source="packages/deepbook_margin/sources/margin_pool.move" mode="code" org="MystenLabs" repo="deepbookv3" struct="MarginPoolConfigUpdated" />
</details> <details> <summary>`SupplierCapMinted`</summary>Emitted when a new supplier cap is minted.
<ImportContent source="packages/deepbook_margin/sources/margin_pool.move" mode="code" org="MystenLabs" repo="deepbookv3" struct="SupplierCapMinted" />
</details> <details> <summary>`AssetSupplied`</summary>Emitted when assets are supplied to a margin pool.
<ImportContent source="packages/deepbook_margin/sources/margin_pool.move" mode="code" org="MystenLabs" repo="deepbookv3" struct="AssetSupplied" />
</details> <details> <summary>`AssetWithdrawn`</summary>Emitted when assets are withdrawn from a margin pool.
<ImportContent source="packages/deepbook_margin/sources/margin_pool.move" mode="code" org="MystenLabs" repo="deepbookv3" struct="AssetWithdrawn" />
</details> <details> <summary>`MaintainerFeesWithdrawn`</summary>Emitted when maintainer fees are withdrawn.
<ImportContent source="packages/deepbook_margin/sources/margin_pool.move" mode="code" org="MystenLabs" repo="deepbookv3" struct="MaintainerFeesWithdrawn" />
</details> <details> <summary>`ProtocolFeesWithdrawn`</summary>Emitted when protocol fees are withdrawn.
<ImportContent source="packages/deepbook_margin/sources/margin_pool.move" mode="code" org="MystenLabs" repo="deepbookv3" struct="ProtocolFeesWithdrawn" />
</details> <details> <summary>`ProtocolFeesIncreased`</summary>Emitted when protocol fees are accrued from interest payments.
<ImportContent source="packages/deepbook_margin/sources/margin_pool/protocol_fees.move" mode="code" org="MystenLabs" repo="deepbookv3" struct="ProtocolFeesIncreasedEvent" />
</details>