deepbookv3-swaps
Installation
SKILL.md
DeepBook V3: Swaps
DeepBook V3 offers an AMM-style swap interface. This is highly suitable for decentralized exchanges, routers, or applications that need instant execution without locking assets in a BalanceManager or managing order cancellations.
1. Key Concepts
Two Operational Modes
Swaps can be executed in two ways depending on system architecture:
- Without a
BalanceManager: Perfect for user-facing dApps. Traders swap rawCoinobjects directly. The function returns the bought asset coin, any leftover input asset coin, and any remaining/unused fee tokens. - With a
BalanceManager: Leverages the user's on-chain balance manager. Fees are paid using the manager's DEEP balance.
Mechanics & Constraints
- Direction: Swapping from base to quote requires
base_in > 0andquote_in = 0. Swapping from quote to base requiresquote_in > 0andbase_in = 0. - Trading Fees: Swapping requires DEEP tokens to pay for trading fees.
- Overestimating Fees: For swaps without a balance manager, you can safely overestimate the DEEP fee coin input. DeepBook V3 calculates the exact fee, takes what is needed, and returns the rest.
- Divisibility: If the input quantity is not perfectly divisible by the pool's lot size, some input token quantity might remain unswapped and be returned.