Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/primitivefinance/rmm-examples
https://github.com/primitivefinance/rmm-examples
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/primitivefinance/rmm-examples
- Owner: primitivefinance
- License: gpl-3.0
- Created: 2021-11-26T18:33:06.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-06-17T14:30:21.000Z (over 2 years ago)
- Last Synced: 2024-05-13T00:40:38.502Z (4 months ago)
- Language: Solidity
- Size: 277 KB
- Stars: 10
- Watchers: 5
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- defi-derivatives - RMM Examples
README
![](https://pbs.twimg.com/profile_banners/1241234631707381760/1588727988/1500x500)
# 🦣 RMM Examples
[![License](https://img.shields.io/badge/License-GPLv3-green.svg)](https://www.gnu.org/licenses/gpl-3.0)
This repository contains examples showing how to interact with the RMM protocol.
Alternatively, you can use this repository as a base if you plan on building on top of the RMM protocol, as it contains all the necessary setup to run the whole protocol locally.
> ⚠️ These example contracts are written for educational purposes and were **NOT AUDITED**. Keep this in mind before using them in production.
## 🚀 Usage
Clone the repository on your computer:
```bash
git clone https://github.com/primitivefinance/rmm-examples.git
```Then install the required dependencies:
```bash
# Using npm
npm install# Using yarn
yarn
```After that, you can try the other commands:
```bash
# Using npm and npx# Compile the contracts
npm run compile# Run a test
npx hardhat test ./path/to/the/test.ts# Style the contracts using Prettier
npm run prettier# Using yarn
# Compile the contracts
yarn compile# Run a test
yarn hardhat test ./path/to/the/test.ts# Style the contracts using Prettier
yarn prettier
```## 📚 Example Contracts
### 💦 LiquidityManager
This simple example shows how a contract can manage liquidity pool tokens on the behalf of users, allowing them to allocate or remove into different pools. It's a very basic version of the `PrimitiveManager` contract.
The features of this example are quite basic:
- Users can allocate or remove liquidity into a pool of a predefined risky / stable pair
- Check the liquidity of each user currently managed by the contractSee the code [here](contracts/liquidityManager/liquidityManager.sol).
### 🎁 LiquidityWrapper
The PrimitiveManager contract tokenizes liquidity pool tokens using the ERC1155 standard. This allows significant gas optimizations at a contract level, but adds a little bit of friction when it comes to integrating with other protocols, more used to deal with ERC20 tokens. Luckily, a straightforward solution to this problem is to use a "wrapper" contract.
The specifications of the `LiquidityWrapper` contract are extremely simple:
- A wrapper can only be associated with a unique PrimitiveManager token id (a specific pool)
- Deposit (wrap) liquidity pool tokens (ERC1155) to receive wrapped tokens (ERC20)
- Withdraw (unwrap) wrapped liquidity pool tokens (ERC20) to get their unwrapped tokens back (ERC1155)See the code [here](contracts/liquidityWrapper/LiquidityWrapper.sol).
### 🧑🍳 PrimitiveChef
Based on the [MasterChef](https://github.com/sushiswap/sushiswap/blob/canary/contracts/MasterChef.sol) created by SushiSwap, this contract is a reimplementation of the code with the support of ERC1155 tokens, the token standard used by the PrimitiveManager.
In a few words, the `PrimitiveChef` goals are to:
- Create staking pools dedicated to specific ERC1155 tokens
- Reward users depositing liquidity pool tokens in these staking poolsSee the code [here](contracts/primitiveChef/PrimitiveChef.sol).
## 🏗 Building
As mentioned above, if you plan on building on top of the RMM protocol, this repository can be used as a base for your work, as it already contains:
- A local context deploying a complete version of the protocol (PrimitiveFactory, PrimitiveEngine, PrimitiveManager and test ERC20 tokens)
- Custom Mocha hooks specific to the RMM protocolFeel free to remove the examples or any files you don't want to keep to make yourself at home!