Skip to main content

Contracts Overview

The Swaap V1 protocol is comprised of a set of smart contracts and libraries that together allow for the creation of permissionless IL resistant pools.

Below is a high level description of the main contract interactions that power the Swaap Protocol.

Factory Contract

The Factory is used to deploy new permissionless Swaap pools, and acts as a pool registry. In addition, the Factory contract implements useful administrative functions that the Swaap Labs (and later on the DAO) can use to modify misconfigured pool parameters. These functions prevent pool controllers from creating bad market strategies that can harm Liquidity Providers on the long run.

Pool Contract

The Swaap Pool holds all the logic for the asset management, pool parametrization, liquidity provision and trading interfaces. Each pool can have up to 8 tokens and can be highly customized by its creator/controller.

The main functions for a day-to-day user are:

  • Buy a fixed amount of tokens
  • Sell a fixed amount of token
  • Join/exit a pool with using all the assets in the pool
  • Join/exit a pool with using one asset in the pool

The quotations for the swaps and for the one-asset-joins/exits are calculated by the Math library.

Math Library

The Math library computes the necessary quotations when swapping two tokens or when joining or exiting the pool with one asset. The Swaap Matrix Market Maker quotations are based on the constant geometric mean formula but also depends on the latest oracle prices, pools state, pool parameters, and on the spread derived from the historical prices percentage drift and percentage volatility returned by the GBM library.

GBM Library

The Geometric Brownian Motion library is what allows the Swaap protocol to obtain dynamic fees that brings competitive prices in a stable market while protecting the LPs in a highly volatile market. The GBM contract computes the percentage drift and the percentage volatility of the historical prices reported by the Chainlink oracles assuming a Geometric Brownian Motion process. These price statistics are in turn used by the Math library to compute the spread.

Proxy Contract

The Proxy contract is an optional component to the Swaap V1 that offers first and foremost convenience to the user by requiring only a single authorization per token to interact with different Swaap contracts. Additionally, the Proxy allows the users to atomically perform multiple contract interactions, namely:

  • Batchswapping: buy/sell the same token pairs accross multiple Swaap pools.
  • Multihopping: buy/sell the same token pairs with an intermediary asset accross multiple Swaap pools.
  • Joining a pool via 0x: buy multiple tokens externally via 0x using one asset and join a Swaap pool.
  • Creating a pool: deploy, balance and finalize a pool with all the custom parameters.