Margin Pool
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.
packages/deepbook_margin/sources/margin_pool.move. You probably need to run `pnpm prebuild` and restart the site.Supply liquidity
Supply assets to the margin pool to earn interest. Returns the total supply shares owned by the supplier after this operation.
packages/deepbook_margin/sources/margin_pool.move. You probably need to run `pnpm prebuild` and restart the site.Withdraw liquidity
Withdraw supplied assets from the margin pool. You can specify an exact amount or withdraw all available shares.
packages/deepbook_margin/sources/margin_pool.move. You probably need to run `pnpm prebuild` and restart the site.Read endpoints
packages/deepbook_margin/sources/margin_pool.move. You probably need to run `pnpm prebuild` and restart the site.Events
MarginPoolCreated
Emitted when a new margin pool is created.
packages/deepbook_margin/sources/margin_pool.move. You probably need to run `pnpm prebuild` and restart the site.DeepbookPoolUpdated
Emitted when a DeepBook pool is enabled or disabled for lending.
packages/deepbook_margin/sources/margin_pool.move. You probably need to run `pnpm prebuild` and restart the site.InterestParamsUpdated
Emitted when interest rate parameters are updated.
packages/deepbook_margin/sources/margin_pool.move. You probably need to run `pnpm prebuild` and restart the site.MarginPoolConfigUpdated
Emitted when margin pool configuration is updated.
packages/deepbook_margin/sources/margin_pool.move. You probably need to run `pnpm prebuild` and restart the site.SupplierCapMinted
Emitted when a new supplier cap is minted.
packages/deepbook_margin/sources/margin_pool.move. You probably need to run `pnpm prebuild` and restart the site.AssetSupplied
Emitted when assets are supplied to a margin pool.
packages/deepbook_margin/sources/margin_pool.move. You probably need to run `pnpm prebuild` and restart the site.AssetWithdrawn
Emitted when assets are withdrawn from a margin pool.
packages/deepbook_margin/sources/margin_pool.move. You probably need to run `pnpm prebuild` and restart the site.MaintainerFeesWithdrawn
Emitted when maintainer fees are withdrawn.
packages/deepbook_margin/sources/margin_pool.move. You probably need to run `pnpm prebuild` and restart the site.ProtocolFeesWithdrawn
Emitted when protocol fees are withdrawn.
packages/deepbook_margin/sources/margin_pool.move. You probably need to run `pnpm prebuild` and restart the site.ProtocolFeesIncreased
Emitted when protocol fees are accrued from interest payments.
packages/deepbook_margin/sources/margin_pool/protocol_fees.move. You probably need to run `pnpm prebuild` and restart the site.Related links
Learn how interest rates are calculated for margin pool borrowing.
Learn how to earn referral fees by referring liquidity suppliers.
The DeepBook Margin package on GitHub.