Skip to content

Commit

Permalink
Implement mAsset v2
Browse files Browse the repository at this point in the history
 - Upgrades solc version to 0.8.0
 - Migrates necessary files to 0.8.0
 - Refactors test suite to use hardhat natively
 - Develop, test and deploy new mAsset: mBTC
  • Loading branch information
alsco77 committed Feb 12, 2021
1 parent f0dfa3d commit 928bdc7
Show file tree
Hide file tree
Showing 245 changed files with 200,401 additions and 41,230 deletions.
11 changes: 4 additions & 7 deletions .eslintrc.js
Expand Up @@ -25,22 +25,19 @@ module.exports = {
}
},
"rules": {
"@typescript-eslint/no-use-before-define": 1
"@typescript-eslint/no-use-before-define": 1,
"import/no-extraneous-dependencies": 1,
"no-nested-ternary": 1
},
"overrides": [
{
"files": [
"./types/*.ts",
"./types/contracts.ts",
"./types/chai.d.ts",
"./types/interfaces.d.ts",
"./types/**/*.ts",
"./test/*.ts",
"./scripts/**/*.ts",
"./test/**/*.ts",
"./test-utils/*.ts",
"./test-utils/**/*.ts",
"./migrations/*.js"],
"./test-utils/**/*.ts"],
}
]
};
40 changes: 20 additions & 20 deletions .github/workflows/test.yaml
@@ -1,24 +1,24 @@
on: ["push", "pull_request"]
name: Test
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 10.22.0
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 10.22.0
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"

- uses: actions/cache@v2
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- run: yarn install
- run: yarn compile
- run: yarn test
- uses: actions/cache@v2
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- run: yarn
- run: yarn compile
- run: yarn test
12 changes: 11 additions & 1 deletion .gitignore
Expand Up @@ -37,6 +37,9 @@ build/
artifacts/
contracts-output/

# VS Code Solidity Extension
bin/contracts

# TSC
/artifacts/json
/artifacts/ts
Expand All @@ -49,6 +52,9 @@ package-lock.json
# .vscode
.vscode/

# WebStorm
.idea/

# solcover
.coverage_cache/
.coverage_artifacts/
Expand All @@ -58,4 +64,8 @@ cache

# sol-merger
flat/
_flat/
_flat/

# test data
/test-utils/validator-data/*.csv
testoutput.txt
6 changes: 0 additions & 6 deletions .prettierrc

This file was deleted.

26 changes: 26 additions & 0 deletions .prettierrc.json
@@ -0,0 +1,26 @@
{
"trailingComma": "es5",
"tabWidth": 4,
"semi": false,
"useTabs": false,
"singleQuote": false,
"printWidth": 140,
"overrides": [
{
"files": "*.ts",
"options": {
"parser": "typescript",
"trailingComma": "all",
"arrowParens": "always"
}
},
{
"files": "*.sol",
"options": {
"printWidth": 100,
"bracketSpacing": true,
"explicitTypes": "always"
}
}
]
}
6 changes: 4 additions & 2 deletions .solcover.js
@@ -1,10 +1,12 @@
module.exports = {
skipFiles: [
'Migrations.sol',
'interfaces',
'integrations',
'z_mocks',
'shared/InitializableReentrancyGuard.sol',
'integrations'
'integrations',
'masset/peripheral',
'savings/peripheral',
'upgradability'
]
};
10 changes: 10 additions & 0 deletions .solhint.json
@@ -0,0 +1,10 @@
{
"extends": "solhint:recommended",
"plugins": [],
"rules": {
"avoid-suicide": "error",
"avoid-sha3": "warn",
"compiler-version": ["warn","^0.8.0"],
"func-visibility": ["warn",{"ignoreConstructors":true}]
}
}
2 changes: 2 additions & 0 deletions .solhintignore
@@ -0,0 +1,2 @@
node_modules
contracts/z_mocks/**/*
2 changes: 0 additions & 2 deletions .soliumignore

This file was deleted.

21 changes: 0 additions & 21 deletions .soliumrc.json

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE
Expand Up @@ -667,7 +667,7 @@ Note:
Unless otherwise specified, individual files are licensed as AGPL-3.0-or-later
and are assumed to include the following text:

Copyright (C) 2020 Stability Labs Pty. Ltd. <https://mstable.org/>
Copyright (C) 2020 mStable <https://mstable.org/>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
Expand Down
83 changes: 26 additions & 57 deletions README.md
Expand Up @@ -2,35 +2,32 @@
<img src="https://mstable.org/assets/img/email/mstable_logo_horizontal_black.png" width="420" >

![CI](https://github.com/mstable/mStable-contracts/workflows/Test/badge.svg)
[![Coverage Status](https://coveralls.io/repos/github/mstable/mStable-contracts/badge.svg?branch=master)](https://coveralls.io/github/mstable/mStable-contracts?branch=master)
[![Coverage Status](https://coveralls.io/repos/github/mstable/mStable-ICSMM/badge.svg?branch=icsmm&t=BVkH5s)](https://coveralls.io/github/mstable/mStable-ICSMM?branch=icsmm)
[![Discord](https://img.shields.io/discord/525087739801239552?color=7289DA&label=discord%20)](https://discordapp.com/channels/525087739801239552/)
[![npm version](https://badge.fury.io/js/%40mstable%2Fprotocol.svg)](https://badge.fury.io/js/%40mstable%2Fprotocol)

<br />

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](./contracts/masset/Masset.sol)) are tokens that allow minting and redemption at a 1:1 ratio for underlying Basket Assets (`bAssets`) of the same peg (i.e. USD, BTC, Gold), with composition managed by the [BasketManager](./contracts/masset/BasketManager.sol). `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 1:1 (provided they remain within their [forge validator](./contracts/masset/forge-validator) limits), with a small `swapFee` credited additionally to Savers.
mStable Assets ([mAssets](./contracts/masset/Masset.sol)) 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](./contracts/masset/InvariantValidator.sol) limits), with a `swapFee` credited additionally to Savers.

Core mAsset contracts utilise OpenZeppelin's [InitializableAdminUpgradeabilityProxy](https://github.com/OpenZeppelin/openzeppelin-sdk/blob/master/packages/lib/contracts/upgradeability/InitializableAdminUpgradeabilityProxy.sol) to facilitate future upgrades, fixes or feature additions. The upgrades are proposed by the mStable Governors (with current governor address stored in the [Nexus](./contracts/nexus/Nexus.sol) - the system kernel) and executed via the [DelayedProxyAdmin](./contracts/upgradability/DelayedProxyAdmin.sol). 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 rewards](https://docs.mstable.org/meta-rewards-1/).

mStable rewards those who contribute to its utility and growth - for more information see [MTA](https://docs.mstable.org/mstable-assets/functions).

<br />

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

📄 https://docs.mstable.org

<br />

## Bug bounty

Found a bug? Claim a reward from our open [Bug Bounty](https://docs.mstable.org/protocol/security/mstable-bug-bounty) by reporting it to mStable (following the [responsible disclosure](https://docs.mstable.org/protocol/security/mstable-bug-bounty#responsible-disclosure) policy)


<br />

---
Expand All @@ -39,8 +36,8 @@ Found a bug? Claim a reward from our open [Bug Bounty](https://docs.mstable.org/

## Branches

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

<br />

Expand All @@ -54,42 +51,28 @@ We publish the contract artifacts to an npm package called [@mstable/protocol](h

### Prerequisites

* Node.js v10.22.0 (you may wish to use [nvm][1])
* [ganache-cli][2]
- Node.js v10.22.0 (you may wish to use [nvm][1])
- [ganache-cli][2]

### Installing dependencies

```
$ yarn
```

### Running migrations

Deployment scripts are located in `migrations/src`. To run, start `ganache` or `ganache-cli` and run the migration script.

*NB: You should locally use the latest version of `ganache-cli`, as contracts rely on recent opcodes.*
*In case you are using `ganache` GUI you should go to the settings/gear icon -> chain -> update the gas limit property to 8000000*

```
$ ganache-cli -p 7545 -l 8000000
$ yarn compile
$ yarn migrate
```

### Testing

Tests are written in Typescript, using [Typechain](https://github.com/ethereum-ts/TypeChain) to generate typings for all contracts. Tests are executed using `truffle` and `ganache-cli`.
Tests are written with Hardhat, Ethers, Waffle & Typescript, using [Typechain](https://github.com/ethereum-ts/TypeChain) to generate typings for all contracts. Tests are executed using `hardhat` in hardhats evm.

```
$ ganache-cli -p 7545 -l 50000000 --allowUnlimitedContractSize
$ yarn test
```

#### Ganache-fork
#### Forking

mStable-contracts test suite is built to support execution on a [mainnet fork](https://medium.com/ethereum-grid/forking-ethereum-mainnet-mint-your-own-dai-d8b62a82b3f7) of ganache. This allows tests to be ran using all mainnet dependencies (bAssets, lending protocols). To do this, certain mainnet accounts need to be unlocked to allows tx to be sent from that origin.
mStable-contracts test suite is built to support execution on a [mainnet fork](https://medium.com/ethereum-grid/forking-ethereum-mainnet-mint-your-own-dai-d8b62a82b3f7) of ganache. This allows tests to be ran using all mainnet dependencies (bAssets, lending protocols). To do this, certain mainnet accounts need to be unlocked to allows tx to be sent from that origin.

*NB: The following commands assume you have a full Ethereum node running and exposed on local port 1234*
_NB: The following commands assume you have a full Ethereum node running and exposed on local port 1234_

```
$ ganache-cli -f http://localhost:1234 -p 7545 -l 100000000 --allowUnlimitedContractSize --unlock "0x6cC5F688a315f3dC28A7781717a9A798a59fDA7b" --unlock "0x3f5CE5FBFe3E9af3971dD833D26bA9b5C936f0bE" --unlock "0x3dfd23a6c5e8bbcfc9581d2e864a68feb6a076d3"
Expand All @@ -101,49 +84,35 @@ $ truffle test ./test/xxx.spec.tx --network fork

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, Truffle-flavoured contract interfaces

- `/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](https://github.com/sc-forks/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](https://coveralls.io/github/mstable/mStable-contracts).

*NB: solidity-coverage runs with solc `optimizer=false` (see [discussion](https://github.com/sc-forks/solidity-coverage/issues/417))*


### Scripts

`script [scriptName] [args]` > Runs custom Truffle scripts

Example usage:

* Mint 100 MUSD: `yarn script mint 100`
* Redeem 100 of the MUSD basset at index 0 (USDT): `yarn redeem-basset 0 100`
* Deposit 100 mUSD into savings: `yarn deposit-savings 100`
* Withdraw 100 mUSD from savings: `yarn withdraw-savings 100`
* Travel through time (forwards only, sorry): `yarn script time-travel 1 year`
_NB: solidity-coverage runs with solc `optimizer=false` (see [discussion](https://github.com/sc-forks/solidity-coverage/issues/417))_

### CI

Codebase rules are enforced through a passing [CI](https://circleci.com) (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
- 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](https://solidity.readthedocs.io/en/v0.5.0/layout-of-source-files.html#comments)
- Internal function ordering from high > low order
- Solidity imports deconstructed as `import { xxx } from "../xxx.sol"`
- Solidity commented as per [NatSpec format](https://solidity.readthedocs.io/en/v0.5.0/layout-of-source-files.html#comments)
- Internal function ordering from high > low order

<br />

Expand Down
23 changes: 0 additions & 23 deletions contracts/Migrations.sol

This file was deleted.

0 comments on commit 928bdc7

Please sign in to comment.