DLMM Contract Architecture
Ramses DLMM is an LFJ v2.2-style Liquidity Book implementation integrated with Ramses fee routing and optional voter-directed rewards.Contract map
Factory
Pool identity
There is at most one pool for an unordered token pair and bin step. The factory sorts tokens for storage, but initialization preserves the suppliedtokenX and tokenY order.
Key reads:
getLBPairImplementation() changes the implementation used for future pools; it does not upgrade an existing clone.
Creation constraints
createLBPair(tokenX, tokenY, activeId, binStep) requires:
- An existing preset for
binStep - An open preset unless the caller is the factory owner
- A whitelisted
tokenYquote asset - Distinct, non-zero tokens
- No existing pool for that token pair and bin step
- A valid active-bin price
LBPairCreated event is the canonical discovery event.
Mutable configuration
The factory owner controls:- Preset parameters and whether a preset is open
- Fee parameters on an existing pool
- Pool protocol share
- Quote-asset membership
- Routing-ignore state
- Hook installation and removal through the hook-manager role
- Fee recipient and flash-loan fee
- Forced volatility decay
- The implementation used for future pools
Voter may change an existing pool’s protocolShare.
Pool
Core reads
getReserves() reports pool reserves net of accrued protocol fees. getBin(id) reports the token reserves assigned to one bin.
State-changing entrypoints
swap() relies on pre-transferred input and mint() expects packed liquidity configurations. Public integrations should normally use DLMMRouter.
LP share behavior
Each bin ID has independentbalanceOf() and totalSupply() accounting. Initial shares are derived from the square root of bin liquidity; later deposits mint proportionally to the bin’s existing reserves and supply.
DLMMToken is ERC1155-like, but:
- It does not call receiver hooks
- It has no URI surface
- Operator approval for all bin IDs uses
approveForAll() - A linked rewarder hook can disable batch transfers
Router and quoter
DLMMRouter is the intended safety boundary for end-user transactions. It adds:
- Deadlines
- Token and active-ID slippage checks
- ERC20 and native-asset handling
- Refund routing
- A caller-only LP recipient check on public add-liquidity functions
- Exact-input and exact-output swaps
- Fee-on-transfer swap variants
- Batched per-bin liquidity operations
V2_1. Its V1 and V2 enum members are compatibility placeholders.
DLMMQuoter evaluates every registered, non-ignored bin-step candidate for a hop and returns the best complete fill. It catches failing candidates, so callers must still verify that every selected pair and amount is non-zero.
Fees
Pool static parameters are:baseFactor × binStep. The variable fee scales quadratically with volatilityAccumulator × binStep and is capped. The maximum total swap fee is 10%.
protocolShare is measured out of 10,000 and applies to the swap fee, not to trade notional:
DLMMFeeCollector.collectProtocolFees(pool):
- Pulls the pool’s accrued protocol fees
- Sends them to treasury if no live rewarder exists
- Otherwise applies its configured treasury skim and notifies the rewarder’s
FeeDistributor
10%.
Oracle
Each pool contains an oracle of cumulative active ID, volatility, and bins crossed. It remains inactive untilincreaseOracleLength() allocates storage.
Hooks and rewards
Hooks can execute before or after swaps, flash loans, mints, burns, and batch transfers. Hook calls are synchronous; an enabled hook that reverts or returns an invalid selector can block the corresponding pool operation until governance replaces or removes it.DLMMRewarder enables Ramses voter-directed emissions:
Votertreats the rewarder as the pool’s emission target- RAM streams over a configurable, upper-exclusive range of at most 11 bins
- The default
(0, 1)range rewards only the active bin - Reward weight is calculated from bin liquidity at the active-bin price
- Each bin then distributes pro rata to its share holders
- Owners claim only for their own address
Voter and AccessHub integration
When configured,Voter reuses its existing pool/gauge mappings:
AccessHub exposes dedicated DLMM operations for pool and rewarder creation, fee changes, hook managers, reward ranges, fee collector settings, and factory ownership. Regular users call an open factory preset directly; protocol operators use createDLMMPool().
Events
Factory
Pool
Rewards and fee routing
Integration invariants
binStep = 1means one basis point, or0.01%- Prices are unsigned 128.128 fixed-point values
destinationBin = liveActiveId + deltaId;activeIdDesiredis the slippage anchorrefundToreceives unused mint inputs- Public router adds require
to == msg.sender - Router paths execute
Version.V2_1 protocolShareis basis points of swap fees- Pool settings and hook state are mutable
- Current deployment state takes precedence over generic factory constants or documentation labels
