Git Product home page Git Product logo

dfmm's Introduction

DFMM

This repository contains the smart contracts source code for the DFMM protocol.

What is DFMM?

The DFMM protocol is a novel portfolio management system designed to leverage external strategy contracts. This system separates the operational logic and the mathematical model: the DFMM core contract completely relies on the strategies to validate the state of each interaction. On the other hand, this core contract acts as a single entry point and performs all the operations, such as:

  • Passing the input data to the strategies for validation
  • Safely transferring the assets between the users and the core contract
  • Tracking the reserves in a singleton pattern
  • Tokenizing the liquidity and distributing the LP tokens to the users

Contracts Architecture

The DFMM protocol relies on two main components: the DFMM core contract and the strategies.

DFMM

This contract is the core of the protocol and is the single entry point for all the user interactions. It also handles all the following operations on the behalf of the strategies:

  • Deploying an ERC20 token for each new pool (using the minimal proxy pattern)
  • Wrapping / unwrapping native ETH when necessary
  • Transferring the assets from or to the user's wallet
  • Preventing reentrancy by locking the contract during the operations
  • Emitting according events for each interaction
  • Keeping track of the reserves for each pool

Strategies

The strategies are the mathematical models that define the logic of the pools. They all implement a specific trading curve (for example xy=k) and are responsible for validating the state of the pool at each interaction.

Initializing and updating a pool

Creating a new pool

flowchart LR
  A(Pool Creator) --> |Creates pool| B[DFMM]
  B --> |Forwards pool parameters| C[Strategy]
  D -...-> |Transfers LP tokens| A
  C -...-> |Validates the creation| B
  B --> |Mints new LP tokens| D[LP Token]
Loading

Updating a pool

flowchart LR
    A(Pool Creator) --> |Updates pool| B[DFMM]
    B --> |Forwards pool parameters| E[Strategy]
    E -...-> |Validates the update| B
Loading

Providing liquidity

Allocating

flowchart LR
  A(Liquidity Provider) --> |Provides liquidity| B[DFMM]
  B --> |Forwards pool new state| D[Strategy]
  C -...-> |Transfers LP tokens| A
  D -...-> |Validates pool new state| B
  B --> |Mints new LP tokens| C[LP Token]
Loading

Arbitrage

Development

Installation

This repository uses Foundry, be sure to have it installed or run the following command to install it:

curl -L https://foundry.paradigm.xyz | bash

Then clone the repository along with its dependencies:

git clone [email protected]:primitivefinance/DFMM.git --recurse-submodules

One last step is to set up the environment variables, run this to copy the template:

cp .env.example .env

Then populate the .env file with the required environment variables.

Testing

To run all the tests, simply run the following command:

forge t

Learn more about our testing suite here.

Deployment

You can deploy the contracts with the following command:

$ forge script ./src/script/Deployment.s.sol --rpc-url $OPTIMISM_SEPOLIA_RPC_URL --broadcast --verify -vvv

Arbiter Security Report

To build the arbiter run

$ make tex

Current Deployments

The DFMM protocol is currently deployed on the following networks:

Designation Network Address
DFMM Optimism Sepolia 0x89a023e3cbccf1c96F00749F87D24C9B1124BaE1
G3M Optimism Sepolia 0xB5C2c5a4000FB230b289bB54f8b48F4dd8075F3D
LogNormal Optimism Sepolia 0x6A74a571c638dDDF13ae52F48A37D1019B916520

Terminology

These terms are used to name specific variables throuhout the codebase and the documentation. They are noted here for clarity and are expected to be reused in the future by strategy developers or contributors.

  • The prefix delta is used to denote the amount of tokens or liquidity to be added or removed from a pool: deltaX, deltaY, deltaLiquidity.
  • The prefix adjusted is used to denote the amount of tokens or liquidity after the addition or removal of liquidity: adjustedReserveX, adjustedReserveY, adjustedLiquidity.
Term Definition
reserveX The amount of token X held by a pool
reserveY The amount of token Y held by a pool
liquidity The amount of liquidity held by a pool
deltaX The amount of token X to be added or removed from a pool
deltaY The amount of token Y to be added or removed from a pool
deltaLiquidity The amount of liquidity to be added or removed from a pool
adjustedReserveX The amount of token X after the addition or removal of liquidity
adjustedReserveY The amount of token Y after the addition or removal of liquidity
adjustedLiquidity The amount of liquidity after the addition or removal of liquidity

Contributing

Contributions are welcome! Check out our guidelines.

Licences

The Solidity contracts that make up the DFMM protocol are licensed under the GPL-3.0. The rust sdk in the kit/ directory is Apache 2.

dfmm's People

Contributors

clemlak avatar kinrezc avatar autoparallel avatar alexangelj avatar 0xjepsen avatar sam-goldman avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.