Swaps
DeepBook provides a swap-like interface commonly seen in automatic market makers (AMMs). Unlike the order functions, you can call swap_exact_amount without a BalanceManager. You call it directly with Coin objects instead. When swapping from base to quote, base_in must have a positive value while quote_in must be zero. When swapping from quote to base, quote_in must be positive and base_in zero. Some deep_in amount is required to pay for trading fees. You can overestimate this amount, as the unused DEEP tokens are returned at the end of the call.
You can use the get_amount_out endpoint to simulate a swap. The function returns the exact amount of DEEP tokens that the swap requires.
API
Following are the endpoints that the Pool exposes for swaps.
Swap exact base for quote
Swap exact base quantity without needing a balance_manager. DEEP quantity can be overestimated. Returns three Coin objects:
BaseAssetQuoteAssetDEEP
Some base quantity may be left over, if the input quantity is not divisible by lot size.
You can overestimate the amount of DEEP required. The remaining balance is returned.
packages/deepbook/sources/pool.move. You probably need to run `pnpm prebuild` and restart the site.Swap exact quote for base
Swap exact quote quantity without needing a balance_manager. You can overestimate DEEP quantity. Returns three Coin objects:
BaseAssetQuoteAssetDEEP
Some quote quantity might be left over if the input quantity is not divisible by lot size.
packages/deepbook/sources/pool.move. You probably need to run `pnpm prebuild` and restart the site.Swap exact quantity
This function is what the previous two functions call with coin::zero() set for the third coin. Users can call this directly for base → quote or quote → base as long as base or quote have a zero value.
packages/deepbook/sources/pool.move. You probably need to run `pnpm prebuild` and restart the site.Swap exact base for quote with manager
Swap exact base for quote using a BalanceManager. Assumes fees are paid in DEEP. Assumes balance manager has enough DEEP for fees. Returns two Coin objects: base and quote.
packages/deepbook/sources/pool.move. You probably need to run `pnpm prebuild` and restart the site.Swap exact quote for base with manager
Swap exact quote for base using a BalanceManager. Assumes fees are paid in DEEP. Assumes balance manager has enough DEEP for fees. Returns two Coin objects: base and quote.
packages/deepbook/sources/pool.move. You probably need to run `pnpm prebuild` and restart the site.Swap exact quantity with manager
Swap exact quantity using a BalanceManager. This is the underlying function that the two manager-based swap functions call. Assumes fees are paid in DEEP and that the balance manager has sufficient DEEP for fees. Returns two Coin objects: base and quote.
packages/deepbook/sources/pool.move. You probably need to run `pnpm prebuild` and restart the site.Related links
The DeepBookV3 repository on GitHub.