Skip to content

Commit

Permalink
Fixed most shallow problems reported by slither
Browse files Browse the repository at this point in the history
  • Loading branch information
2xic committed Apr 16, 2022
1 parent e536452 commit ca5156f
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 32 deletions.
3 changes: 2 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 2,7 @@
"recommendations": [
"juanblanco.solidity",
"dbaeumer.vscode-eslint",
"streetsidesoftware.code-spell-checker"
"streetsidesoftware.code-spell-checker",
"eamodio.gitlens"
]
}
15 changes: 9 additions & 6 deletions contracts/Pool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 51,6 @@ contract Pool {

function init(uint256 amount, SharedStructs.PositionType userPosition)
external
payable
{
require(!poolState.isInitialized, 'Init should only be called once');

Expand Down Expand Up @@ -82,7 81,6 @@ contract Pool {

function enter(uint256 amount, SharedStructs.PositionType userPosition)
external
payable
{
require(poolState.isInitialized, 'call init before enter');

Expand Down Expand Up @@ -110,15 108,20 @@ contract Pool {

function withdrawal(uint256 amount, SharedStructs.PositionType position)
external
payable
{
if (position == SharedStructs.PositionType.SHORT) {
require(false, 'Not implemented');
} else if (position == SharedStructs.PositionType.LONG) {
uint256 chipTokens = poolState.longRedeemPrice * amount;
longCfd.burn(amount, msg.sender);
chipToken.approve(address(this), chipTokens);
chipToken.transferFrom(address(this), msg.sender, chipTokens);
require(
chipToken.approve(address(this), chipTokens),
'failed approve'
);
require(
chipToken.transferFrom(address(this), msg.sender, chipTokens),
'failed transfer'
);

poolState.longSupply -= amount;
poolState.longPoolSize -= chipTokens.increasePrecision();
Expand All @@ -129,7 132,7 @@ contract Pool {
}
}

function rebalance() public payable {
function rebalance() public {
uint256 price = priceOracle.getLatestPrice();
uint256 protocolChips = poolState.protocolState.size;

Expand Down
4 changes: 2 additions & 2 deletions contracts/helpers/SimpleRebalanceHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 125,9 @@ library SimpleRebalanceHelper {

if (shouldProtocolCashOut && canCashOut) {
if (isProtocolLong) {
poolState.cashOutProtocol();
poolState = poolState.cashOutProtocol();
} else {
poolState.cashOutProtocol();
poolState = poolState.cashOutProtocol();
}
}

Expand Down
23 changes: 11 additions & 12 deletions contracts/tokens/Chip.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 8,46 @@ contract Chip is ERC20 {
address private owner;
ERC20 private usdc;

constructor(
address _owner,
address _usdc
) ERC20('Chip', 'C') {
constructor(address _owner, address _usdc) ERC20('Chip', 'C') {
require(_owner != address(0), 'Cannot use zero address as owner');
owner = _owner;
usdc = ERC20(_usdc);
}

function mint(uint256 amount) external payable returns (uint256) {
function mint(uint256 amount) external {
require(msg.sender == owner, 'Only owner can mint tokens');
require(amount > 0, 'Amount not specified');
_mint(owner, amount);
return amount;
}

function burn(uint256 amount) external payable returns (uint256) {
function burn(uint256 amount) external {
require(msg.sender == owner, 'Only owner can burn tokens');
require(amount > 0, 'Amount not specified');
_burn(owner, amount);
return amount;
}

function transferToken(uint256 amount, address target)
external
payable
returns (uint256)
{
require(msg.sender == owner, 'Only owner can transfer minted tokens');
transfer(target, amount);
return amount;
}

function transferOwnerShip(address newOwner) external payable returns (bool) {
function transferOwnerShip(address newOwner) external returns (bool) {
require(newOwner != address(0), 'Cannot use zero address as owner');
require(owner == msg.sender, 'Only owner can change ownership');
owner = newOwner;

return true;
}

function exchange(uint256 amount) external payable {
require(usdc.transferFrom(msg.sender, address(this), amount), 'Transfer of usdc failed');
function exchange(uint256 amount) external {
require(
usdc.transferFrom(msg.sender, address(this), amount),
'Transfer of usdc failed'
);
_mint(msg.sender, amount);
}
}
9 changes: 6 additions & 3 deletions contracts/tokens/EthLongCfd.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 8,15 @@ contract EthLongCfd is ERC20 {
address private owner;

constructor(address _owner) ERC20('EthLongCfd', 'ETHLCDF') {
require(
_owner != address(0),
'Cannot use zero address as owner'
);
owner = _owner;
}

function mint(uint256 amount, address receiver)
external
payable
returns (uint256)
{
require(
Expand All @@ -25,11 28,11 @@ contract EthLongCfd is ERC20 {
return amount;
}

function burn(uint256 amount, address account) external payable {
function burn(uint256 amount, address account) external {
_burn(account, amount);
}

function transferOwnerShip(address newOwner) external payable returns (bool) {
function transferOwnerShip(address newOwner) external returns (bool) {
require(
msg.sender == owner,
'Only the owner contract should call this function'
Expand Down
17 changes: 10 additions & 7 deletions contracts/tokens/EthShortCfd.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 8,15 @@ contract EthShortCfd is ERC20 {
address private owner;

constructor(address _owner) ERC20('EthShortCfd', 'ETHSCDF') {
require(
_owner != address(0),
'Cannot use zero address as owner'
);
owner = _owner;
}

function mint(uint256 amount, address receiver)
external
payable
returns (uint256)
{
require(
Expand All @@ -25,19 28,19 @@ contract EthShortCfd is ERC20 {
return amount;
}

function burn(uint256 amount, address account) external payable {
function burn(uint256 amount, address account) external {
_burn(account, amount);
}

function transferOwnerShip(address newOwner) external payable returns (bool) {
require(
msg.sender == owner,
'Only the owner contract should call this function'
);
function transferOwnerShip(address newOwner) external returns (bool) {
require(
newOwner != address(0),
'Cannot use zero address as owner'
);
require(
msg.sender == owner,
'Only the owner contract should call this function'
);
owner = newOwner;

return true;
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 4,8 @@
"lint": "npm run lint-ts && npm run lint-sol && npm run lint-security",
"lint-ts": "npx eslint . --fix --quiet --ext .ts",
"lint-sol": "solhint --fix 'contracts/**/*.sol'",
"lint-security-deep": "slither ./contracts/ --solc-remaps \"@openzeppelin=node_modules/@openzeppelin hardhat=node_modules/hardhat\" --filter-paths \"node_modules\" --exclude solc-version",
"lint-security-deep": "slither ./contracts/ --solc-remaps \"@openzeppelin=node_modules/@openzeppelin hardhat=node_modules/hardhat\" --filter-paths \"node_modules\"",
"lint-security-shallow": "slither ./contracts/ --solc-remaps \"@openzeppelin=node_modules/@openzeppelin hardhat=node_modules/hardhat\" --filter-paths \"node_modules\" --exclude \"solc-version reentrancy-no-eth\"",
"lint-security": "slither contracts --print human-summary --solc-remaps \"@openzeppelin=node_modules/@openzeppelin hardhat=node_modules/hardhat\""
},
"devDependencies": {
Expand Down

0 comments on commit ca5156f

Please sign in to comment.