Overview

Marginly architecture consists of the following contracts:

  • marginly pool implementation

  • factory

  • pool

  • router

Marginly pool implementation (contracts/contract/MarginlyPool.sol) is a pool bytecode. This deployed contract is basically an uninitialized version of marginly pool, which is cloned during creation of a new pool. The cloning approach is chosen in order for our factory contract size to fit with ethereum evm limit of 24 KiB.

Factory (contracts/contracts/MarginlyFactory.sol) creates new Marginly pools via 'createPool' method. This method clones marginly pool implementation and calls 'initialize' method, which sets pool variables and parameters that can be found here and here.

Factory stores the following info common for all our pools:

  • router address

  • fee holder address

  • tech position owner address

Though 'createPool' method is 'ownerOnly' right now, we are planning to make it permissionless in the future versions.

Router (router/contracts/MarginlyRouter.sol) is a contract that makes swaps on different DEXs of user's choice. It has two main methods:

  • swapExactInput -- makes swap with exact amount of swapped tokens

  • swapExactOutput -- makes swap with exact amount of tokens, received after swap

The user's choice is defined by a swapCalldata argument, which is decoded to an array of DEX indexes and their swap ratio. Default value for this argument is 0. It represents swap on UniswapV3 and is used during liquidation. Such swaps can be performed by any wallet or contract not limited to Marginly pools.

DEXs Swap implementations are located in router/contract/abstract/dex directory.

Last updated