Integrate the Broker

This guide walks through integrating with Mento's Broker contract to execute swaps between stable assets and their collateral. The Broker serves as the main entry point for all Mento exchanges, handling trading limits, mint/burn operations, and routing to appropriate exchange providers.

Common Use Cases

DEX Aggregators

Route trades through Mento for optimal stable asset pricing, accessing deep on-chain liquidity with minimal slippage.

Trading Interfaces

Offer direct stable asset swaps to users through your UI, leveraging Mento's oracle-anchored rates.

Arbitrage Bots

Access Mento liquidity for market making between Mento pools and external venues.

Wallets

Enable in-app swaps between stable assets and collateral directly within your wallet interface.

Integration Steps

Step 1: Connect to the Broker Contract

The Broker is the main interface for executing swaps:

See Smart Contracts > Deployments for testnet addresses.

Step 2: Discover Available Exchange Providers

Query the Broker for registered exchange providers and their supported pairs:

Step 3: Get Swap Quotes

Before executing a swap, query the expected output amount:

Step 4: Execute Swaps

Perform the actual swap with slippage protection:

Working Examples

For complete integration examples including quote aggregation and multi-hop swaps, see the Mento SDK Examples repository.

Key Concepts

Exchange Providers and IDs

  • Exchange Provider: A contract managing one or more trading pools (e.g., BiPoolManager)

  • Exchange ID: Unique identifier for a specific trading pair within a provider

  • Multiple providers can offer the same pair with different parameters

Token Types

  • Stable Assets: Minted/burned on demand (USDm, EURm, etc.)

  • Collateral Assets: Held in reserve (CELO, USDC, etc.)

  • The Broker automatically handles minting/burning for stable assets

Trading Limits

The Broker enforces per-token trading limits to protect against large flows:

  • Limits are configured per exchange and token

  • Both time-based and absolute limits may apply

  • Transactions revert if limits are exceeded

Best Practices

Slippage Protection

Always use amountOutMin parameter to protect against unfavorable price movements between quote and execution.

Gas Optimization

  • Query multiple exchanges in a single call using multicall patterns

  • Cache exchange IDs and provider addresses instead of querying repeatedly

Error Handling

Common revert reasons:

  • "ExchangeProvider does not exist" - Invalid provider address

  • "amountOutMin not met" - Slippage tolerance exceeded

  • "Insufficient balance in reserve" - Not enough collateral available

  • Trading limit errors - Flow restrictions triggered

Last updated