Developers

The Manual Loop Markets architecture is designed with modularity, extensibility, and composability in mind. Developers can integrate looping/unlooping capabilities into their own protocols or dApps, extend existing strategies, or build entirely new leverage logic by interacting directly with our Looping and Strategy layers.

At its core, the system provides:

  • Atomic loop/unloop execution using Aave V3 flash loans and the Universal DEX module.

  • User-isolated strategy contracts for safe and flexible leverage management.

  • Abstract contracts and libraries to speed up integration while maintaining security best practices.


Architecture for Developers

1. Looping Layer

Located in /src/looping/, this is the execution layer responsible for:

  • Handling flash loan requests and callbacks.

  • Managing token swaps for leverage adjustments.

  • Encoding/decoding execution parameters.

Key Contracts

  • LoopingHelper — Primary entry point for loop/unloop calls.

  • LoopingHelperSwaps — Abstract swap handling using the universal DEX router.

  • LoopingHelperEncoding — Encoding/decoding of operation parameters for atomic execution.

  • DataTypes — Centralized structs/enums for type safety.

Usage Example

solidityCopyEditLoopingHelper(loopingHelperAddress).loop(
    DataTypes.LoopCallParams({
        supplyToken: address(USDC),
        borrowToken: address(DAI),
        supplyAmount: 1_000e6,
        borrowAmount: 500e18,
        swapParams: swapData
    })
);

2. Strategy Layer

Located in /src/strategy/, this layer provides user-specific leverage management. Strategies are non-upgradeable, owned by the user, and deployable through the factory.

Key Contracts

  • SuperlendLoopingStrategyFactory — Deploys isolated strategy contracts per user/market.

  • SuperlendLoopingStrategy — Manages position opening, closing, and configuration.

  • SuperlendLoopingStrategyStorage — Holds state/config for each strategy.

Factory Deployment Example

solidityCopyEditaddress strategy = SuperlendLoopingStrategyFactory(factory).createStrategy(
    loopingHelper,
    aavePool,
    yieldAsset,
    debtAsset,
    eMode
);

Integration Points

Supported Modules:

  • Aave V3 — flash loans, supply/borrow, credit delegation, eMode.

  • Universal DEX — multi-route swaps, slippage control, execution.

  • ERC20 Standards — SafeERC20 for all transfers.

Key Considerations for Integrators

  • Always validate asset pair compatibility with eMode before execution.

  • Ensure sufficient ERC20 approvals for looping operations.

  • Monitor position health factors post-execution.

  • Handle slippage and gas considerations in your UI/strategy logic.


Developer Tooling

  • Events:

    • LoopExecuted (loop params, result amounts)

    • UnloopExecuted (unloop params, result amounts)

    • StrategyDeployed (owner, config, strategy address)

  • Modifiers:

    • onlyOwner (strategy level)

    • nonReentrant (looping level)

  • Libraries:

    • SafeERC20 — for token safety.

    • DataTypes — for struct consistency across layers.


Best Practices

  • Use callStatic in tests to simulate loops/unloops before sending transactions.

  • Implement position health monitoring and liquidation prevention in your app layer.

  • Keep swap execution paths optimized to reduce gas.

  • Treat leftover tokens from _handleLeftOverAmounts() as potential yield and reinvest where possible.


Resources

Manual Loop Markets

Last updated