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
The system emits this event when you create a new margin pool.
packages/deepbook_margin/sources/margin_pool.move. You probably need to run `pnpm prebuild` and restart the site.DeepbookPoolUpdated
The system emits this event when you enable or disable a DeepBook pool for lending.
packages/deepbook_margin/sources/margin_pool.move. You probably need to run `pnpm prebuild` and restart the site.InterestParamsUpdated
The system emits this event when you update interest rate parameters.
packages/deepbook_margin/sources/margin_pool.move. You probably need to run `pnpm prebuild` and restart the site.MarginPoolConfigUpdated
The system emits this event when you update the margin pool configuration.
packages/deepbook_margin/sources/margin_pool.move. You probably need to run `pnpm prebuild` and restart the site.SupplierCapMinted
The system emits this event when you mint a new supplier cap.
packages/deepbook_margin/sources/margin_pool.move. You probably need to run `pnpm prebuild` and restart the site.AssetSupplied
The system emits this event when you supply assets to a margin pool.
packages/deepbook_margin/sources/margin_pool.move. You probably need to run `pnpm prebuild` and restart the site.AssetWithdrawn
The system emits this event when you withdraw assets from a margin pool.
packages/deepbook_margin/sources/margin_pool.move. You probably need to run `pnpm prebuild` and restart the site.MaintainerFeesWithdrawn
The system emits this event when you withdraw maintainer fees.
packages/deepbook_margin/sources/margin_pool.move. You probably need to run `pnpm prebuild` and restart the site.ProtocolFeesWithdrawn
The system emits this event when you withdraw protocol fees.
packages/deepbook_margin/sources/margin_pool.move. You probably need to run `pnpm prebuild` and restart the site.ProtocolFeesIncreased
The system emits this event when it accrues protocol fees from interest payments.
packages/deepbook_margin/sources/margin_pool/protocol_fees.move. You probably need to run `pnpm prebuild` and restart the site.