LBAMM Integration Generator
Generate router/aggregator/frontend contracts that integrate with LBAMM.
Project Setup
Before generating code, check the user's project is configured:
- Foundry:
foundry.toml must exist. If not: forge init
- LBAMM Core:
lib/lbamm-core/ must exist. If not: forge install limitbreakinc/lbamm-core
- Remappings:
remappings.txt needs @limitbreak/lbamm-core/=lib/lbamm-core/. Append if missing -- do not overwrite existing entries.
- Local testing: LBAMM is in audit and not yet on public networks. For local testing, use
lbamm-examples -- see lbamm-protocol/references/local-dev.md. Generated scripts should read addresses from environment variables (vm.envAddress) so they work with the local Anvil deployment.
Instructions
Parse integration requirements from $ARGUMENTS
Resolve ambiguities before generating -- if $ARGUMENTS doesn't specify key addresses (pool IDs, token addresses, router deployment target) or leaves the integration pattern unclear (single swap vs multi-hop, basic vs with handler), ask in a single message. If clear, proceed.
Determine which LBAMM entry points are needed:
singleSwap -- Single-pool swaps
multiSwap -- Multi-hop routes
directSwap -- Peer-to-peer swaps (with transfer handlers)
createPool -- Pool deployment
addLiquidity / removeLiquidity / collectFees -- Liquidity management
Generate complete integration contract with:
- Proper struct construction (
SwapOrder, BPSFeeWithRecipient, FlatFeeWithRecipient, etc.)
- Token approval handling
- Native token (ETH) wrapping if needed
- Transfer handler data encoding if needed
- Hook data encoding if needed
Handle key integration details:
- The router becomes the executor -- hooks see it as
msg.sender
- Token ordering:
token0 < token1 always
amountSpecified > 0 = input swap, < 0 = output swap
deadline must be in the future
recipient cannot be address(0)
Note: The router is the executor for hook-policy purposes. If a token hook restricts executors, the router must be whitelisted.
Reference Files
references/swap-interface.md -- singleSwap, multiSwap, directSwap details and struct construction
references/liquidity-interface.md -- createPool, addLiquidity, removeLiquidity, collectFees
references/integration-patterns.md -- Router, aggregator, liquidity manager examples
- Protocol knowledge:
lbamm-protocol
Common Mistakes
- Not whitelisting LBAMM as an operator in the Transfer Validator for the token -- swaps will revert
- Forgetting that the router contract is the executor -- hooks see
msg.sender = router, not the end user
- Using
amountSpecified = 0 -- this is invalid. Positive = input swap, negative = output swap.
- Setting fee recipient to
address(0) when fee amount is non-zero -- will revert with LBAMM__FeeRecipientCannotBeAddressZero
Dependencies
@limitbreak/lbamm-core/src/interfaces/core/ILimitBreakAMMSwap.sol
@limitbreak/lbamm-core/src/interfaces/core/ILimitBreakAMMLiquidity.sol
@limitbreak/lbamm-core/src/DataTypes.sol
Related Skills
- lbamm-handler-protocol -- Transfer handler architecture and custom handler development
- lbamm-permit-handler -- Generate PermitTransferHandler integration (gasless swaps via directSwap)
- lbamm-clob -- Generate CLOBTransferHandler integration (limit orders via directSwap)
- lbamm-test -- Generate Foundry test suites for integration contracts
1---2name: lbamm-integrator3description: Generate DEX integration contracts that call LBAMM4---56# LBAMM Integration Generator78Generate router/aggregator/frontend contracts that integrate with LBAMM.910## Project Setup1112Before generating code, check the user's project is configured:131. **Foundry**: `foundry.toml` must exist. If not: `forge init`142. **LBAMM Core**: `lib/lbamm-core/` must exist. If not: `forge install limitbreakinc/lbamm-core`153. **Remappings**: `remappings.txt` needs `@limitbreak/lbamm-core/=lib/lbamm-core/`. Append if missing -- do not overwrite existing entries.164. **Local testing**: LBAMM is in audit and not yet on public networks. For local testing, use `lbamm-examples` -- see `lbamm-protocol/references/local-dev.md`. Generated scripts should read addresses from environment variables (`vm.envAddress`) so they work with the local Anvil deployment.1718## Instructions19201. **Parse integration requirements** from `$ARGUMENTS`21222. **Resolve ambiguities before generating** -- if $ARGUMENTS doesn't specify key addresses (pool IDs, token addresses, router deployment target) or leaves the integration pattern unclear (single swap vs multi-hop, basic vs with handler), ask in a single message. If clear, proceed.23243. **Determine which LBAMM entry points are needed:**25 - `singleSwap` -- Single-pool swaps26 - `multiSwap` -- Multi-hop routes27 - `directSwap` -- Peer-to-peer swaps (with transfer handlers)28 - `createPool` -- Pool deployment29 - `addLiquidity` / `removeLiquidity` / `collectFees` -- Liquidity management30314. **Generate complete integration contract** with:32 - Proper struct construction (`SwapOrder`, `BPSFeeWithRecipient`, `FlatFeeWithRecipient`, etc.)33 - Token approval handling34 - Native token (ETH) wrapping if needed35 - Transfer handler data encoding if needed36 - Hook data encoding if needed37385. **Handle key integration details:**39 - The router becomes the **executor** -- hooks see it as `msg.sender`40 - Token ordering: `token0 < token1` always41 - `amountSpecified > 0` = input swap, `< 0` = output swap42 - `deadline` must be in the future43 - `recipient` cannot be `address(0)`44456. **Note**: The router is the executor for hook-policy purposes. If a token hook restricts executors, the router must be whitelisted.4647## Reference Files4849- `references/swap-interface.md` -- singleSwap, multiSwap, directSwap details and struct construction50- `references/liquidity-interface.md` -- createPool, addLiquidity, removeLiquidity, collectFees51- `references/integration-patterns.md` -- Router, aggregator, liquidity manager examples52- Protocol knowledge: `lbamm-protocol`5354## Common Mistakes5556- Not whitelisting LBAMM as an operator in the Transfer Validator for the token -- swaps will revert57- Forgetting that the router contract is the executor -- hooks see `msg.sender = router`, not the end user58- Using `amountSpecified = 0` -- this is invalid. Positive = input swap, negative = output swap.59- Setting fee recipient to `address(0)` when fee amount is non-zero -- will revert with `LBAMM__FeeRecipientCannotBeAddressZero`6061## Dependencies6263```64@limitbreak/lbamm-core/src/interfaces/core/ILimitBreakAMMSwap.sol65@limitbreak/lbamm-core/src/interfaces/core/ILimitBreakAMMLiquidity.sol66@limitbreak/lbamm-core/src/DataTypes.sol67```6869## Related Skills7071- **lbamm-handler-protocol** -- Transfer handler architecture and custom handler development72- **lbamm-permit-handler** -- Generate PermitTransferHandler integration (gasless swaps via directSwap)73- **lbamm-clob** -- Generate CLOBTransferHandler integration (limit orders via directSwap)74- **lbamm-test** -- Generate Foundry test suites for integration contracts