Awesome Open Source
Awesome Open Source

CI Coverage Status Discord npm version


This repo contains all contracts and tests relevant to the core mStable protocol. mStable is a protocol built to make stablecoins easy, robust and profitable.

mStable Assets (mAssets) are tokens that allow minting and redemption for underlying Basket Assets (bAssets) of the same peg (i.e. USD, BTC, Gold). The InvariantValidator applies both min and max weights to these bAssets, and enforces penalties and bonuses when minting with these assets to provide low slippage swaps. This Invariant applies progressive penalties and bonuses on either end of the weight scale - having the result of having a large area of low slippage. bAssets are integrated with lending protocols (initially Aave, Compound) to generate interest which is accrued in mAsset terms. mAssets can be deposited to earn native interest through their respective Savings Contract, just like you would with a savings account. bAssets within an mAsset can also be swapped with low slippage (provided they remain within their validator limits), with a swapFee credited additionally to Savers.

Core mAsset contracts utilise OpenZeppelin's InitializableAdminUpgradeabilityProxy to facilitate future upgrades, fixes or feature additions. The upgrades are proposed by the mStable Governors (with current governor address stored in the Nexus - the system kernel) and executed via the DelayedProxyAdmin. Both changes to the governor, and contract upgrades have a one week delay built in to execution. This allows mStable users a one week opt out window if they do not agree with the given change.

mStable rewards those who contribute to its utility and growth - for more information see MTA.


🏠 https://mstable.org
📀 https://app.mstable.org
📄 https://docs.mstable.org


Bug bounty

Found a bug? Claim a reward from our open Bug Bounty by reporting it to mStable (following the responsible disclosure policy)




Branches

  • master contains complete, tested and audited contract code, generally on mainnet
  • beta is for the pre-release code, generally on ropsten

Artifacts

We publish the contract artifacts to an npm package called @mstable/protocol. You can browse them via unpkg.com.


Dev notes

Prerequisites

Installing dependencies

$ yarn

Testing

Tests are written with Hardhat, Ethers, Waffle & Typescript, using Typechain to generate typings for all contracts. Tests are executed using hardhat in hardhats evm.

$ yarn test

Suite

Key folders:

  • /contracts/z_mocks: All mocks used throughout the test suite
  • /security: Scripts used to run static analysis tools like Slither and Securify
  • /test: Unit tests in folders corresponding to contracts/xx
  • /test-utils: Core util files used throughout the test framework
    • /machines: Mock contract machines for creating configurable instances of the contracts
  • /types: TS Types used throughout the suite
    • /generated: Output from Typechain; strongly-typed, Ethers-flavoured contract interfaces

Coverage

Solidity-coverage is used to run coverage analysis on test suite.

This produces reports that are visible in the /coverage folder, and navigatable/uploadable. Ultimately they are used as a reference that there is some sort of adequate cover, although they will not be a source of truth for a robust test framework. Reports publically available on coveralls.

NB: solidity-coverage runs with solc optimizer=false (see discussion)

CI

Codebase rules are enforced through a passing CI (visible in .circleci/config.yml). These rules are:

  • Linting of both the contracts (through Solium) and TS files (ESLint)
  • Passing test suite
  • Maintaining high unit testing coverage

Code formatting

  • Solidity imports deconstructed as import { xxx } from "../xxx.sol"
  • Solidity commented as per NatSpec format
  • Internal function ordering from high > low order

Command Line Interface

Hardhat Tasks are used for command line interactions with the mStable contracts. The tasks can be found in the tasks folder.

A separate Hardhat config file tasks.config.ts is used for task config. This inherits from the main Hardhat config file hardhat.config.ts. This avoids circular dependencies when the repository needs to be compiled before the Typechain artifacts have been generated. This means the --config tasks.config.ts Hardhat option needs to be used to run the mStable tasks.

Config your network. If you are just using readonly tasks like mBTC-snap you don't need to have a signer with Ether in it so the default Hardhat test account is ok to use. For safety, the mainnet config is not committed to the repository to avoid accidentally running tasks against mainnet.

mainnet: {
    url: process.env.NODE_URL || "",
    accounts: {
        mnemonic: "test test test test test test test test test test test junk",
    },
},

Never commit mainnet private keys, mnemonics or provider URLs to the repository.

Examples of using the Hardhat tasks

# List all Hardhat tasks
hh --config tasks.config.ts

# Set the provider url
export NODE_URL=https://mainnet.infura.io/v3/yourApiKey

# To run the mBTC-snap task against mainnet
yarn task mBTC-snap --network mainnet

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
Typescript (247,386) 
Ethereum (6,788) 
Solidity (5,751) 
Smart Contracts (2,196) 
Defi (567) 
Related Projects
Advertising 📦 9
All Projects
Application Programming Interfaces 📦 120
Applications 📦 181
Artificial Intelligence 📦 72
Blockchain 📦 70
Build Tools 📦 111
Cloud Computing 📦 79
Code Quality 📦 28
Collaboration 📦 30
Command Line Interface 📦 48
Community 📦 81
Companies 📦 60
Compilers 📦 60
Computer Science 📦 74
Configuration Management 📦 39
Content Management 📦 167
Control Flow 📦 197
Data Formats 📦 77
Data Processing 📦 266
Data Storage 📦 132
Economics 📦 60
Frameworks 📦 198
Games 📦 122
Graphics 📦 103
Hardware 📦 148
Integrated Development Environments 📦 47
Learning Resources 📦 147
Legal 📦 28
Libraries 📦 119
Lists Of Projects 📦 21
Machine Learning 📦 336
Mapping 📦 61
Marketing 📦 15
Mathematics 📦 55
Media 📦 228
Messaging 📦 97
Networking 📦 304
Operating Systems 📦 84
Operations 📦 120
Package Managers 📦 52
Programming Languages 📦 229
Runtime Environments 📦 96
Science 📦 42
Security 📦 375
Social Media 📦 26
Software Architecture 📦 70
Software Development 📦 68
Software Performance 📦 57
Software Quality 📦 127
Text Editors 📦 45
Text Processing 📦 131
User Interface 📦 310
User Interface Components 📦 465
Version Control 📦 29
Virtualization 📦 68
Web Browsers 📦 38
Web Servers 📦 25
Web User Interface 📦 194