Skip to content

Integrating with the SwapFacility

The SwapFacility is the central, permissioned router for the M0 ecosystem. It is the only contract that can perform wrap and unwrap operations between the core $M token and any M0 Extension. This ensures all conversions are 1:1, secure, and standardized.

Understanding how to interact with it is a critical step for launching your extension.

The Approval Process: A Two-Step Whitelisting

For your extension to be fully integrated, two components must be approved by M0 Governance: your Extension Contract and your Swapper Contract.

Step 1: Get Your Extension Approved as an M0 Earner

First, your deployed extension contract address must be on the official earners list in the TTGRegistrar. This is a prerequisite for any interaction with the SwapFacility.

This process ensures that only recognized and audited extensions are part of the ecosystem.

For a detailed walkthrough, follow the Gaining Earner Approval guide.

Step 2: Configure Your Swapper Address

Direct calls from end-users’ wallets to swapInM and swapOutM are restricted. The SwapFacility enforces a permissions layer:

  • Non-permissioned extensions: Only addresses with the M_SWAPPER_ROLE can call.
  • Permissioned extensions: Only addresses explicitly allow-listed for that extension via setPermissionedMSwapper can call.

Recommended pattern: Deploy an intermediary contract (router) that contains your app’s logic for deposits/withdrawals. Then have the SwapFacility admin grant that contract either the global M_SWAPPER_ROLE or a per-extension approval.

Users interact only with your contract, which securely proxies calls into the SwapFacility.

Advanced: Permissioned Extensions

The SwapFacility also supports a stricter model for institutional or private use cases. An extension can be marked as "permissioned" by the DEFAULT_ADMIN_ROLE.

  • Effect: A permissioned extension blocks all general swap calls.
  • Access: To interact with a permissioned extension, a swapper address must be granted specific approval for that individual extension via setPermissionedMSwapper().

This provides an extra layer of access control for extensions that are not intended for public use.