Skip to content

Commit

Permalink
chore: update formater and linter (#391)
Browse files Browse the repository at this point in the history
  • Loading branch information
Steffel authored Jun 2, 2021
1 parent a5f0b1e commit 7430895
Show file tree
Hide file tree
Showing 11 changed files with 850 additions and 1,559 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ jobs:
- name: Install node.js dependencies
run: yarn --frozen-lockfile

- name: Run linter on *.sol and *.json
run: yarn lint:check
- name: Run formater check on *.sol and *.json
run: yarn format:check

- name: run linter check on *.sol file
run: yarn hint

commits:
runs-on: ubuntu-latest

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ build/
reports/
node_modules/
.test_durations
yarn-error.log
1 change: 1 addition & 0 deletions .husky/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_
5 changes: 5 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn format:fix
yarn hint
6 changes: 6 additions & 0 deletions .solhint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "solhint:default",
"rules": {
"max-line-length": ["error", 145]
}
}
15 changes: 8 additions & 7 deletions contracts/BaseStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ interface StrategyAPI {
* accurate picture of the Strategy's performance. See `vault.report()`,
* `harvest()`, and `harvestTrigger()` for further details.
*/

abstract contract BaseStrategy {
using SafeMath for uint256;
using SafeERC20 for IERC20;
Expand All @@ -199,7 +200,7 @@ abstract contract BaseStrategy {
* `apiVersion()` function above.
* @return This Strategy's name.
*/
function name() external virtual view returns (string memory);
function name() external view virtual returns (string memory);

/**
* @notice
Expand All @@ -216,7 +217,7 @@ abstract contract BaseStrategy {
* The amount of assets this strategy manages that should not be included in Yearn's Total Value
* Locked (TVL) calculation across it's ecosystem.
*/
function delegatedAssets() external virtual view returns (uint256) {
function delegatedAssets() external view virtual returns (uint256) {
return 0;
}

Expand Down Expand Up @@ -493,7 +494,7 @@ abstract contract BaseStrategy {
* @param _amtInWei The amount (in wei/1e-18 ETH) to convert to `want`
* @return The amount in `want` of `_amtInEth` converted to `want`
**/
function ethToWant(uint256 _amtInWei) public virtual view returns (uint256);
function ethToWant(uint256 _amtInWei) public view virtual returns (uint256);

/**
* @notice
Expand All @@ -519,7 +520,7 @@ abstract contract BaseStrategy {
* value to be "safe".
* @return The estimated total assets in this Strategy.
*/
function estimatedTotalAssets() public virtual view returns (uint256);
function estimatedTotalAssets() public view virtual returns (uint256);

/*
* @notice
Expand Down Expand Up @@ -615,7 +616,7 @@ abstract contract BaseStrategy {
* @param callCostInWei The keeper's estimated gas cost to call `tend()` (in wei).
* @return `true` if `tend()` should be called, `false` otherwise.
*/
function tendTrigger(uint256 callCostInWei) public virtual view returns (bool) {
function tendTrigger(uint256 callCostInWei) public view virtual returns (bool) {
// We usually don't need tend, but if there are positions that need
// active maintainence, overriding this function is how you would
// signal for that.
Expand Down Expand Up @@ -667,7 +668,7 @@ abstract contract BaseStrategy {
* @param callCostInWei The keeper's estimated gas cost to call `harvest()` (in wei).
* @return `true` if `harvest()` should be called, `false` otherwise.
*/
function harvestTrigger(uint256 callCostInWei) public virtual view returns (bool) {
function harvestTrigger(uint256 callCostInWei) public view virtual returns (bool) {
uint256 callCost = ethToWant(callCostInWei);
StrategyParams memory params = vault.strategies(address(this));

Expand Down Expand Up @@ -828,7 +829,7 @@ abstract contract BaseStrategy {
* }
* ```
*/
function protectedTokens() internal virtual view returns (address[] memory);
function protectedTokens() internal view virtual returns (address[] memory);

/**
* @notice
Expand Down
13 changes: 7 additions & 6 deletions contracts/BaseWrapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ abstract contract BaseWrapper {
* Used to get the most revent vault for the token using the registry.
* @return An instance of a VaultAPI
*/
function bestVault() public virtual view returns (VaultAPI) {
function bestVault() public view virtual returns (VaultAPI) {
return VaultAPI(registry.latestVault(address(token)));
}

Expand All @@ -86,7 +86,7 @@ abstract contract BaseWrapper {
* Used to get all vaults from the registery for the token
* @return An array containing instances of VaultAPI
*/
function allVaults() public virtual view returns (VaultAPI[] memory) {
function allVaults() public view virtual returns (VaultAPI[] memory) {
uint256 cache_length = _cachedVaults.length;
uint256 num_vaults = registry.numVaults(address(token));

Expand Down Expand Up @@ -228,10 +228,11 @@ abstract contract BaseWrapper {

if (amount != WITHDRAW_EVERYTHING) {
// Compute amount to withdraw fully to satisfy the request
uint256 estimatedShares = amount
.sub(withdrawn) // NOTE: Changes every iteration
.mul(10**uint256(vaults[id].decimals()))
.div(vaults[id].pricePerShare()); // NOTE: Every Vault is different
uint256 estimatedShares =
amount
.sub(withdrawn) // NOTE: Changes every iteration
.mul(10**uint256(vaults[id].decimals()))
.div(vaults[id].pricePerShare()); // NOTE: Every Vault is different

// Limit amount to withdraw to the maximum made available to this contract
// NOTE: Avoid corner case where `estimatedShares` isn't precise enough
Expand Down
10 changes: 5 additions & 5 deletions contracts/test/TestStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ contract TestStrategy is BaseStrategyInitializable {

constructor(address _vault) public BaseStrategyInitializable(_vault) {}

function name() external override view returns (string memory) {
function name() external view override returns (string memory) {
return string(abi.encodePacked("TestStrategy ", apiVersion()));
}

Expand All @@ -30,7 +30,7 @@ contract TestStrategy is BaseStrategyInitializable {
delegateEverything = !delegateEverything;
}

function delegatedAssets() external override view returns (uint256) {
function delegatedAssets() external view override returns (uint256) {
if (delegateEverything) {
return vault.strategies(address(this)).totalDebt;
} else {
Expand All @@ -53,11 +53,11 @@ contract TestStrategy is BaseStrategyInitializable {
want = _want;
}

function ethToWant(uint256 amtInWei) public override view returns (uint256) {
function ethToWant(uint256 amtInWei) public view override returns (uint256) {
return amtInWei; // 1:1 conversion for testing
}

function estimatedTotalAssets() public override view returns (uint256) {
function estimatedTotalAssets() public view override returns (uint256) {
// For mock, this is just everything we have
return want.balanceOf(address(this));
}
Expand Down Expand Up @@ -120,7 +120,7 @@ contract TestStrategy is BaseStrategyInitializable {
// Nothing needed here because no additional tokens/tokenized positions for mock
}

function protectedTokens() internal override view returns (address[] memory) {
function protectedTokens() internal view override returns (address[] memory) {
address[] memory protected = new address[](1);
protected[0] = protectedToken;
return protected;
Expand Down
4 changes: 2 additions & 2 deletions contracts/yToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ contract yToken is IERC20, BaseWrapper {
return IERC20Metadata(address(token)).decimals();
}

function totalSupply() external override view returns (uint256 total) {
function totalSupply() external view override returns (uint256 total) {
return totalAssets();
}

function balanceOf(address account) external override view returns (uint256 balance) {
function balanceOf(address account) external view override returns (uint256 balance) {
return totalVaultBalance(account);
}

Expand Down
22 changes: 12 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
{
"name": "yearn-protocol",
"devDependencies": {
"@commitlint/cli": "^11.0.0",
"@commitlint/config-conventional": "^11.0.0",
"ethlint": "^1.2.5",
"husky": "^4.3.0",
"prettier": "^2.1.2",
"prettier-plugin-solidity": "^1.0.0-alpha.57",
"pretty-quick": "^3.0.2"
"@commitlint/cli": "^12.1.4",
"@commitlint/config-conventional": "^12.1.4",
"husky": "^6.0.0",
"prettier": "^2.3.0",
"prettier-plugin-solidity": "^1.0.0-beta.11",
"pretty-quick": "^3.1.0",
"solhint": "^3.3.6",
"solhint-plugin-prettier": "^0.0.5"
},
"scripts": {
"lint": "pretty-quick --pattern '**/*.*(sol|json)' --verbose",
"lint:check": "prettier --check **/*.sol **/*.json",
"lint:fix": "pretty-quick --pattern '**/*.*(sol|json)' --staged --verbose"
"format": "prettier --write 'contracts/**/*.sol' --verbose",
"format:check": "prettier --check '**/*.*(sol|json)'",
"format:fix": "pretty-quick --pattern '**/*.*(sol|json)' --staged --verbose",
"hint": "solhint \"contracts/**/*.sol\""
},
"husky": {
"hooks": {
Expand Down
Loading

0 comments on commit 7430895

Please sign in to comment.