Skip to content

Commit

Permalink
fix: addressing linter warnings (#49)
Browse files Browse the repository at this point in the history
* fix: addressing linter warnings

* fix: rm extra line

* fix: reenable linter pre-commit
  • Loading branch information
wei3erHase authored Jun 3, 2024
1 parent 8dbb7bc commit 6c85298
Show file tree
Hide file tree
Showing 12 changed files with 152 additions and 155 deletions.
7 changes: 3 additions & 4 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
. "$(dirname "$0")/_/husky.sh"

# 1. Build the contracts
# 2. Stage build output
# 2. Lint and stage style improvements
# TODO: remember to re-enable linter
yarn build # && npx lint-staged
# 2. Stage build output
# 2. Lint and stage style improvements
yarn build && npx lint-staged
5 changes: 3 additions & 2 deletions .solhint.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"no-console": "off",
"max-line-length": ["warn", 120],
"TODO": "REMOVE_TEMPORARY_LINTER_SETTINGS_BELOW",
"custom-errors": "warn",
"definition-name-capwords": "warn"
"custom-errors": "off",
"one-contract-per-file": "off",
"definition-name-capwords": "off"
}
}
8 changes: 5 additions & 3 deletions .solhint.tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
"named-parameters-function": "off",
"no-global-import": "off",
"max-states-count": "off",
"private-vars-leading-underscore": ["warn", { "strict": false }],
"ordering": "warn",
"no-unused-vars": "off",
"private-vars-leading-underscore": ["off"],
"ordering": "off",
"state-visibility": "off",
"immutable-name-snakecase": "warn",
"avoid-low-level-calls": "off",
"one-contract-per-file": "off",
"max-line-length": ["warn", 120]
"max-line-length": ["warn", 125]
}
}
1 change: 1 addition & 0 deletions .solhintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test/smock/*
2 changes: 1 addition & 1 deletion src/contracts/BColor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ abstract contract BColor {
}

contract BBronze is BColor {
function getColor() external view override returns (bytes32) {
function getColor() external pure override returns (bytes32) {
return bytes32('BRONZE');
}
}
2 changes: 1 addition & 1 deletion src/contracts/BConst.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.23;

import './BColor.sol';
import {BBronze} from './BColor.sol';

contract BConst is BBronze {
uint256 public constant BONE = 10 ** 18;
Expand Down
31 changes: 16 additions & 15 deletions src/contracts/BFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@ pragma solidity 0.8.23;

// Builds new BPools, logging their addresses and providing `isBPool(address) -> (bool)`

import './BPool.sol';
import {BBronze} from './BColor.sol';
import {BPool} from './BPool.sol';
import {IERC20} from './BToken.sol';

contract BFactory is BBronze {
mapping(address => bool) internal _isBPool;
address internal _blabs;

event LOG_NEW_POOL(address indexed caller, address indexed pool);

event LOG_BLABS(address indexed caller, address indexed blabs);

mapping(address => bool) internal _isBPool;

function isBPool(address b) external view returns (bool) {
return _isBPool[b];
constructor() {
_blabs = msg.sender;
}

function newBPool() external returns (BPool) {
Expand All @@ -24,16 +27,6 @@ contract BFactory is BBronze {
return bpool;
}

address internal _blabs;

constructor() {
_blabs = msg.sender;
}

function getBLabs() external view returns (address) {
return _blabs;
}

function setBLabs(address b) external {
require(msg.sender == _blabs, 'ERR_NOT_BLABS');
emit LOG_BLABS(msg.sender, b);
Expand All @@ -46,4 +39,12 @@ contract BFactory is BBronze {
bool xfer = pool.transfer(_blabs, collected);
require(xfer, 'ERR_ERC20_FAILED');
}

function isBPool(address b) external view returns (bool) {
return _isBPool[b];
}

function getBLabs() external view returns (address) {
return _blabs;
}
}
4 changes: 3 additions & 1 deletion src/contracts/BMath.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.23;

import './BNum.sol';
import {BBronze} from './BColor.sol';
import {BConst} from './BConst.sol';
import {BNum} from './BNum.sol';

contract BMath is BBronze, BConst, BNum {
/**
Expand Down
4 changes: 3 additions & 1 deletion src/contracts/BNum.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.23;

import './BConst.sol';
import {BConst} from './BConst.sol';

// solhint-disable private-vars-leading-underscore
// solhint-disable named-return-values
contract BNum is BConst {
function btoi(uint256 a) internal pure returns (uint256) {
unchecked {
Expand Down
174 changes: 88 additions & 86 deletions src/contracts/BPool.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.23;

import './BMath.sol';
import './BToken.sol';
import {BBronze} from './BColor.sol';
import {BMath} from './BMath.sol';
import {BToken, IERC20} from './BToken.sol';

contract BPool is BBronze, BToken, BMath {
struct Record {
Expand All @@ -12,37 +13,6 @@ contract BPool is BBronze, BToken, BMath {
uint256 balance;
}

event LOG_SWAP(
address indexed caller,
address indexed tokenIn,
address indexed tokenOut,
uint256 tokenAmountIn,
uint256 tokenAmountOut
);

event LOG_JOIN(address indexed caller, address indexed tokenIn, uint256 tokenAmountIn);

event LOG_EXIT(address indexed caller, address indexed tokenOut, uint256 tokenAmountOut);

event LOG_CALL(bytes4 indexed sig, address indexed caller, bytes data) anonymous;

modifier _logs_() {
emit LOG_CALL(msg.sig, msg.sender, msg.data);
_;
}

modifier _lock_() {
require(!_mutex, 'ERR_REENTRY');
_mutex = true;
_;
_mutex = false;
}

modifier _viewlock_() {
require(!_mutex, 'ERR_REENTRY');
_;
}

bool internal _mutex;

address internal _factory; // BFactory address to push token exitFee to
Expand All @@ -58,6 +28,20 @@ contract BPool is BBronze, BToken, BMath {
mapping(address => Record) internal _records;
uint256 internal _totalWeight;

event LOG_SWAP(
address indexed caller,
address indexed tokenIn,
address indexed tokenOut,
uint256 tokenAmountIn,
uint256 tokenAmountOut
);

event LOG_JOIN(address indexed caller, address indexed tokenIn, uint256 tokenAmountIn);

event LOG_EXIT(address indexed caller, address indexed tokenOut, uint256 tokenAmountOut);

event LOG_CALL(bytes4 indexed sig, address indexed caller, bytes data) anonymous;

constructor() {
_controller = msg.sender;
_factory = msg.sender;
Expand All @@ -66,59 +50,6 @@ contract BPool is BBronze, BToken, BMath {
_finalized = false;
}

function isPublicSwap() external view returns (bool) {
return _publicSwap;
}

function isFinalized() external view returns (bool) {
return _finalized;
}

function isBound(address t) external view returns (bool) {
return _records[t].bound;
}

function getNumTokens() external view returns (uint256) {
return _tokens.length;
}

function getCurrentTokens() external view _viewlock_ returns (address[] memory tokens) {
return _tokens;
}

function getFinalTokens() external view _viewlock_ returns (address[] memory tokens) {
require(_finalized, 'ERR_NOT_FINALIZED');
return _tokens;
}

function getDenormalizedWeight(address token) external view _viewlock_ returns (uint256) {
require(_records[token].bound, 'ERR_NOT_BOUND');
return _records[token].denorm;
}

function getTotalDenormalizedWeight() external view _viewlock_ returns (uint256) {
return _totalWeight;
}

function getNormalizedWeight(address token) external view _viewlock_ returns (uint256) {
require(_records[token].bound, 'ERR_NOT_BOUND');
uint256 denorm = _records[token].denorm;
return bdiv(denorm, _totalWeight);
}

function getBalance(address token) external view _viewlock_ returns (uint256) {
require(_records[token].bound, 'ERR_NOT_BOUND');
return _records[token].balance;
}

function getSwapFee() external view _viewlock_ returns (uint256) {
return _swapFee;
}

function getController() external view _viewlock_ returns (address) {
return _controller;
}

function setSwapFee(uint256 swapFee) external _logs_ _lock_ {
require(!_finalized, 'ERR_IS_FINALIZED');
require(msg.sender == _controller, 'ERR_NOT_CONTROLLER');
Expand Down Expand Up @@ -202,6 +133,7 @@ contract BPool is BBronze, BToken, BMath {
}
}

// solhint-disable-next-line ordering
function unbind(address token) external _logs_ _lock_ {
require(msg.sender == _controller, 'ERR_NOT_CONTROLLER');
require(_records[token].bound, 'ERR_NOT_BOUND');
Expand Down Expand Up @@ -492,6 +424,59 @@ contract BPool is BBronze, BToken, BMath {
return poolAmountIn;
}

function isPublicSwap() external view returns (bool) {
return _publicSwap;
}

function isFinalized() external view returns (bool) {
return _finalized;
}

function isBound(address t) external view returns (bool) {
return _records[t].bound;
}

function getNumTokens() external view returns (uint256) {
return _tokens.length;
}

function getCurrentTokens() external view _viewlock_ returns (address[] memory tokens) {
return _tokens;
}

function getFinalTokens() external view _viewlock_ returns (address[] memory tokens) {
require(_finalized, 'ERR_NOT_FINALIZED');
return _tokens;
}

function getDenormalizedWeight(address token) external view _viewlock_ returns (uint256) {
require(_records[token].bound, 'ERR_NOT_BOUND');
return _records[token].denorm;
}

function getTotalDenormalizedWeight() external view _viewlock_ returns (uint256) {
return _totalWeight;
}

function getNormalizedWeight(address token) external view _viewlock_ returns (uint256) {
require(_records[token].bound, 'ERR_NOT_BOUND');
uint256 denorm = _records[token].denorm;
return bdiv(denorm, _totalWeight);
}

function getBalance(address token) external view _viewlock_ returns (uint256) {
require(_records[token].bound, 'ERR_NOT_BOUND');
return _records[token].balance;
}

function getSwapFee() external view _viewlock_ returns (uint256) {
return _swapFee;
}

function getController() external view _viewlock_ returns (address) {
return _controller;
}

// ==
// 'Underlying' token-manipulation functions make external calls but are NOT locked
// You must `_lock_` or otherwise ensure reentry-safety
Expand Down Expand Up @@ -521,4 +506,21 @@ contract BPool is BBronze, BToken, BMath {
function _burnPoolShare(uint256 amount) internal {
_burn(amount);
}

modifier _logs_() {
emit LOG_CALL(msg.sig, msg.sender, msg.data);
_;
}

modifier _lock_() {
require(!_mutex, 'ERR_REENTRY');
_mutex = true;
_;
_mutex = false;
}

modifier _viewlock_() {
require(!_mutex, 'ERR_REENTRY');
_;
}
}
Loading

0 comments on commit 6c85298

Please sign in to comment.