BalanceManager
The BalanceManager shared object holds all balances for different assets. To perform trades, pass a combination of BalanceManager and TradeProof into a pool. TradeProofs are generated in one of two ways, either by the BalanceManager owner directly, or by any TradeCap owner. The owner can generate a TradeProof without the risk of equivocation. The TradeCap owner, because it's an owned object, risks equivocation when generating a TradeProof. Generally, a high frequency trading engine trades as the default owner.
With exception to swaps, all interactions with DeepBookV3 require a BalanceManager as one of its inputs. When orders are matched, funds are transferred to or from the BalanceManager. You can use a single BalanceManager between all pools.
API
Following are the different public functions that the BalanceManager exposes.
Create a BalanceManager
The new() function creates a BalanceManager. Combine it with share, or else the transaction fails. You can combine the transaction with deposit calls, allowing you to create, deposit, then share the balance manager in one transaction.
packages/deepbook/sources/balance_manager.move. You probably need to run `pnpm prebuild` and restart the site.Create a BalanceManager with custom owner
The new_with_custom_owner() function creates a BalanceManager with a custom owner. Combine it with share, or else the transaction fails. You can combine the transaction with deposit calls, allowing you to create, deposit, then share the balance manager in one transaction.
packages/deepbook/sources/balance_manager.move. You probably need to run `pnpm prebuild` and restart the site.Create a BalanceManager with custom owner and capabilities
The new_with_custom_owner_and_caps() function creates a BalanceManager with a custom owner and returns all three capabilities (DepositCap, WithdrawCap, and TradeCap) in a single call. Combine the balance manager with share, or else the transaction fails. This is a convenient way to set up a complete balance manager with all necessary capabilities in one transaction.
Move code using DeepBookV3 uses DepositCap, WithdrawCap, and TradeCap, while the DeepBookV3 SDK uses depositCap, withdrawCap, and tradeCap.
packages/deepbook/sources/balance_manager.move. You probably need to run `pnpm prebuild` and restart the site.