Skip to content

Commit

Permalink
Upgrading tslint (mstable#32)
Browse files Browse the repository at this point in the history
* Added a new bAsset status

* Deprecated ts-lint and added new eslint methods

* Removed duplicate identifier
  • Loading branch information
superduck35 authored Feb 25, 2020
1 parent 2681c23 commit 1cd4115
Show file tree
Hide file tree
Showing 38 changed files with 1,355 additions and 283 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
name: Install packages
command: yarn
- run:
name: Lint Contracts
name: Lint Everything
command: yarn lint
- run:
name: Test Contracts
Expand Down
9 changes: 9 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# don't ever lint node_modules
node_modules
# don't lint build output (make sure it's set to your correct build folder name)
dist
# don't lint nyc coverage output
coverage
# no generated types
types/generated
test-utils/env_setup.ts
30 changes: 30 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module.exports = {
"extends": [
"airbnb-typescript",
"plugin:@typescript-eslint/recommended",
"prettier",
"prettier/@typescript-eslint"
],
"env": {
"node": true,
"browser": true,
"jest": true
},
"parserOptions": {
"project": "./tsconfig.json"
},
"settings": {
'import/resolver': {
"alias": {
map: [
['@utils', './test-utils'],
['types/generated', './types/generated/index']
],
extensions: ['.ts', '.d.ts', '.js', '.jsx', '.json']
}
}
},
"rules": {
"@typescript-eslint/no-use-before-define": 1
}
};
17 changes: 1 addition & 16 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,16 +1 @@
{
"editor.formatOnSave": true,
"[javascript]": {
"editor.formatOnSave": false
},
"[handlebars]": {
"editor.formatOnSave": false
},
"eslint.autoFixOnSave": true,
"eslint.alwaysShowStatus": true,
"files.autoSave": "onFocusChange",
"editor.detectIndentation": false,
"solidity.compileUsingRemoteVersion": "^0.5.16",
"solidity.packageDefaultDependenciesContractsDirectory": "",
"solidity.packageDefaultDependenciesDirectory": "node_modules",
}
{}
2 changes: 1 addition & 1 deletion contracts/masset/Masset.sol
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ contract Masset is IMasset, MassetToken, MassetBasket {
onlyManager
{
(bool exists, uint256 i) = _isAssetInBasket(_basset);
require(exists, "bASset must exist in Basket");
require(exists, "bAsset must exist in Basket");

(, , , , , BassetStatus status) = _getBasset(i);
require(status == BassetStatus.Liquidating, "Invalid Basset state");
Expand Down
130 changes: 68 additions & 62 deletions contracts/masset/MassetBasket.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ contract MassetBasket is MassetStructs, MassetCore {

using SafeMath for uint256;
using SafeERC20 for IERC20;

/** @dev Struct holding Basket details */
Basket public basket;
bool public measurementMultipleEnabled;
Expand All @@ -37,16 +38,16 @@ contract MassetBasket is MassetStructs, MassetCore {
bool[] memory _hasTransferFees
)
MassetCore(_nexus)
public
internal
{
require(_bassets.length > 0, "Must initialise with some bAssets");

measurementMultipleEnabled = _multiples.length > 0;

// Defaults
basket.maxBassets = 16; // 16
basket.maxBassets = 16; // 16
basket.collateralisationRatio = 1e18; // 100%
redemptionFee = 2e16; // 2%
redemptionFee = 2e16; // 2%

for (uint256 i = 0; i < _bassets.length; i++) {
_addBasset(
Expand All @@ -63,7 +64,6 @@ contract MassetBasket is MassetStructs, MassetCore {
_;
}


/***************************************
RE-COLLATERALISATION
****************************************/
Expand All @@ -75,10 +75,11 @@ contract MassetBasket is MassetStructs, MassetCore {
* @return alreadyActioned Bool to show whether a Basset had already been actioned
*/
function handlePegLoss(address _basset, bool _belowPeg)
external
onlyManager
basketIsHealthy
returns (bool alreadyActioned) {
external
onlyManager
basketIsHealthy
returns (bool alreadyActioned)
{
(bool exists, uint256 i) = _isAssetInBasket(_basset);
require(exists, "bASset must exist in Basket");

Expand All @@ -93,10 +94,6 @@ contract MassetBasket is MassetStructs, MassetCore {
// If we need to update the status.. then do it
basket.bassets[i].status = newStatus;

if(newStatus == BassetStatus.BrokenBelowPeg) {
// REDISTRIBUTE THIS BASSET'S WEIGHT TO THE OTHER BASSETS?
// Good point
}
return false;
}

Expand All @@ -122,10 +119,11 @@ contract MassetBasket is MassetStructs, MassetCore {
* @param _recollateraliser Address of the recollateraliser, to which the tokens should be sent
*/
function initiateRecol(address _basset, address _recollateraliser)
external
onlyManager
basketIsHealthy
returns (bool requiresAuction) {
external
onlyManager
basketIsHealthy
returns (bool requiresAuction)
{
(bool exists, uint256 i) = _isAssetInBasket(_basset);
require(exists, "bASset must exist in Basket");

Expand Down Expand Up @@ -232,17 +230,32 @@ contract MassetBasket is MassetStructs, MassetCore {
emit BassetAdded(_basset);
}

/**
* @dev Update transfer fee flag
* @param _bAsset bAsset address
* @param _flag Charge transfer fee when its set to 'true', otherwise 'false'
*/
function upgradeTransferFees(address _bAsset, bool _flag)
external
onlyGovernor
{
(bool exist, uint256 index) = _isAssetInBasket(_bAsset);
require(exist, "bAsset does not exist");
basket.bassets[index].isTransferFeeCharged = _flag;
}

/**
* @dev Removes a specific Asset from the Basket, given that its target/collateral level is 0
* As this is a cleanup operation, anybody should be able to perform this task
* @param _assetToRemove The asset to remove from the basket
* @return bool To signify whether the asset was found and removed from the basket
*/
function removeBasset(address _assetToRemove)
external
basketIsHealthy
managerOrGovernor
returns (bool removed) {
external
basketIsHealthy
managerOrGovernor
returns (bool removed)
{
_removeBasset(_assetToRemove);
return true;
}
Expand Down Expand Up @@ -324,21 +337,6 @@ contract MassetBasket is MassetStructs, MassetCore {
emit BasketWeightsUpdated(_bassets, _weights);
}

/**
* @dev Update transfer fee flag
* @param _bAsset bAsset address
* @param _flag Charge transfer fee when its set to 'true', otherwise 'false'
*/
function upgradeTransferFees(address _bAsset, bool _flag)
external
onlyGovernor
{
(bool exist, uint256 index) = _isAssetInBasket(_bAsset);
require(exist, "bAsset does not exist");
basket.bassets[index].isTransferFeeCharged = _flag;
}


/***************************************
GETTERS
****************************************/
Expand Down Expand Up @@ -393,16 +391,17 @@ contract MassetBasket is MassetStructs, MassetCore {
* @return Struct array of all basket assets
*/
function getBasset(address _basset)
public
view
returns (
address addr,
uint256 ratio,
uint256 maxWeight,
uint256 vaultBalance,
bool isTransferFeeCharged,
BassetStatus status
) {
public
view
returns (
address addr,
uint256 ratio,
uint256 maxWeight,
uint256 vaultBalance,
bool isTransferFeeCharged,
BassetStatus status
)
{
(bool exists, uint256 index) = _isAssetInBasket(_basset);
require(exists, "bASset must exist");
return _getBasset(index);
Expand All @@ -412,7 +411,11 @@ contract MassetBasket is MassetStructs, MassetCore {
* @dev Get all bAssets addresses
* @return return an array of bAssets addresses
*/
function getAllBassetsAddress() public view returns (address[] memory) {
function getAllBassetsAddress()
public
view
returns (address[] memory)
{
uint256 len = basket.bassets.length;
address[] memory bAssets = new address[](len);
for(uint256 i = 0; i < len; i++) {
Expand All @@ -426,16 +429,17 @@ contract MassetBasket is MassetStructs, MassetCore {
* @return Struct array of all basket assets
*/
function _getBasset(uint256 _bassetIndex)
internal
view
returns (
address addr,
uint256 ratio,
uint256 maxWeight,
uint256 vaultBalance,
bool isTransferFeeCharged,
BassetStatus status
) {
internal
view
returns (
address addr,
uint256 ratio,
uint256 maxWeight,
uint256 vaultBalance,
bool isTransferFeeCharged,
BassetStatus status
)
{
Basset memory b = basket.bassets[_bassetIndex];
return (b.addr, b.ratio, b.maxWeight, b.vaultBalance, b.isTransferFeeCharged, b.status);
}
Expand All @@ -448,9 +452,10 @@ contract MassetBasket is MassetStructs, MassetCore {
* @return uint256 Index of the Basset
*/
function _isAssetInBasket(address _asset)
internal
view
returns (bool exists, uint256 index) {
internal
view
returns (bool exists, uint256 index)
{
index = basket.bassetsMap[_asset];
if(index == 0) {
if(basket.bassets.length == 0){
Expand All @@ -465,9 +470,10 @@ contract MassetBasket is MassetStructs, MassetCore {
* @notice Determine whether or not a Basset has already undergone re-collateralisation
*/
function _bassetHasRecolled(BassetStatus _status)
internal
pure
returns (bool) {
internal
pure
returns (bool)
{
if(_status == BassetStatus.Liquidating ||
_status == BassetStatus.Liquidated ||
_status == BassetStatus.Failed) {
Expand Down
2 changes: 1 addition & 1 deletion contracts/masset/MassetCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ contract MassetCore is Module {
event RedemptionFeeChanged(uint256 fee);
event FeeRecipientChanged(address feePool);

constructor(address _nexus) Module(_nexus) public {}
constructor(address _nexus) Module(_nexus) internal {}

/**
* @dev Verifies that the caller either Manager or Gov
Expand Down
2 changes: 1 addition & 1 deletion contracts/masset/shared/MassetStructs.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ interface MassetStructs {

/** @dev Status of the Basset - has it broken its peg? */
enum BassetStatus {
// Default,
Default,
Normal,
BrokenBelowPeg,
BrokenAbovePeg,
Expand Down
17 changes: 13 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"migrate": "truffle migrate --network development --reset",
"migrate:rinkeby": "truffle migrate --network rinkeby --reset",
"lint": "yarn run lint-ts; yarn run lint-sol",
"lint-ts": "tslint migrations/*.ts test/**/*.ts",
"lint-ts": "yarn eslint ./test --ext .ts,.js --fix",
"lint-sol": "solium -d contracts/ --fix ",
"coverage": "node --max_old_space_size=6144 node_modules/truffle/build/cli.bundled.js run coverage --network coverage --solcoverjs './.solcover.js'",
"script": "yarn truffle exec ./scripts/main.js",
Expand All @@ -28,14 +28,25 @@
"@types/lodash": "^4.14.138",
"@types/mocha": "^5.2.7",
"@types/node": "^12.7.5",
"@typescript-eslint/eslint-plugin": "^2.21.0",
"@typescript-eslint/eslint-plugin-tslint": "^2.21.0",
"@typescript-eslint/parser": "^2.21.0",
"chai": "^4.2.0",
"chai-bn": "^0.2.0",
"chalk": "^3.0.0",
"copyfiles": "^2.1.1",
"dayjs": "^1.8.20",
"eslint": "^6.8.0",
"eslint-config-airbnb-typescript": "^7.0.0",
"eslint-config-prettier": "^6.10.0",
"eslint-import-resolver-alias": "^1.1.2",
"eslint-plugin-import": "^2.20.1",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-react": "^7.18.3",
"eth-gas-reporter": "^0.2.14",
"ethlint": "^1.2.5",
"minimetoken": "ssh://[email protected]/mstable/minime.git#6348055a0a8f73d65d86a3a6845621bd4a8d6b15",
"mocha": "^7.0.1",
"openzeppelin-solidity": "^2.3.0",
"openzeppelin-test-helpers": "0.3.1",
"prettier": "^1.18.2",
Expand All @@ -45,8 +56,6 @@
"truffle-typings": "^1.0.8",
"ts-node": "^8.4.1",
"tsconfig-paths": "^3.9.0",
"tslint": "^5.20.0",
"tslint-no-unused-expression-chai": "0.0.3",
"typechain": "1.0.4",
"types-ethereumjs-util": "^0.0.8",
"typescript": "^3.6.3",
Expand All @@ -56,4 +65,4 @@
"_moduleAliases": {
"@utils": "transpiled/test-utils"
}
}
}
2 changes: 1 addition & 1 deletion scripts/src/fund.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { StandardAccounts } from "@utils/machines/standardAccounts";
import { simpleToExactAmount } from "@utils/math";
import { getForgeContractInstances } from "./utils/getForgeContractInstances";
import { logTrancheData, logTx } from "./utils/logging";
import { simpleToExactAmount } from "@utils/math";

export default async (scope: any, trancheNumber: string, amount: string) => {
const { forge, MTA } = await getForgeContractInstances(scope);
Expand Down
Loading

0 comments on commit 1cd4115

Please sign in to comment.