Skip to content

Commit ee4b32f

Browse files
committed
compiler warning fixes
1 parent 31eee6b commit ee4b32f

8 files changed

Lines changed: 239 additions & 45 deletions

File tree

foundry.toml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
[profile.default]
22
src = "src"
33
out = "out"
4-
coverage = true
54
libs = ["lib"]
6-
exclude_paths = ["lib/*", "test/mocks/*"]
75

86

97
[lint]
10-
exclude_lints=["mixed-case-function"]
11-
ignore = ["*.t.sol"]
8+
exclude_lints=["mixed-case-function", "asm-keccak256"]
9+
ignore = ["test/*"]

src/NostalgicController.sol

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,7 @@ contract NostalgicController is AccessControl, INostalgicController {
4444
}
4545

4646
modifier onlyOwnerOrFactory() {
47-
require(
48-
hasRole(DEFAULT_ADMIN_ROLE, msg.sender) || msg.sender == factory,
49-
InvalidCaller()
50-
);
47+
_onlyOwnerOrFactory();
5148
_;
5249
}
5350

@@ -180,4 +177,12 @@ contract NostalgicController is AccessControl, INostalgicController {
180177
) public view returns (uint256) {
181178
return amount.mulDiv(collateralFactors[pool.asset()], SCALING_FACTOR);
182179
}
180+
181+
function _onlyOwnerOrFactory() internal view {
182+
require(
183+
hasRole(DEFAULT_ADMIN_ROLE, msg.sender) || msg.sender == factory,
184+
InvalidCaller()
185+
);
186+
}
183187
}
188+

src/NostalgicFactory.sol

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
pragma solidity ^0.8.28;
33

44
import {Clones} from "@openzeppelin/contracts/proxy/Clones.sol";
5-
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
65
import {NostalgicPool} from "./NostalgicPool.sol";
76
import {INostalgicController} from "./interfaces/INostalgicController.sol";
87
import {IAggregatorV3} from "./interfaces/IAggregatorV3.sol";
@@ -25,7 +24,7 @@ import {INostalgicFactory} from "./interfaces/INostalgicFactory.sol";
2524
contract NostalgicFactory is INostalgicFactory {
2625
using Clones for address;
2726

28-
address public immutable poolImplementation;
27+
address public immutable POOL_IMPLEMENTATION;
2928

3029
address public controller;
3130
address public admin;
@@ -54,9 +53,9 @@ contract NostalgicFactory is INostalgicFactory {
5453
_controller != address(0) &&
5554
_admin != address(0) &&
5655
_pauser != address(0),
57-
"Invalid addresses"
56+
ZeroAddress()
5857
);
59-
poolImplementation = _poolImplementation;
58+
POOL_IMPLEMENTATION = _poolImplementation;
6059
controller = _controller;
6160
admin = _admin;
6261
pauser = _pauser;
@@ -80,7 +79,7 @@ contract NostalgicFactory is INostalgicFactory {
8079
)
8180
);
8281

83-
address clone = poolImplementation.cloneDeterministic(salt);
82+
address clone = POOL_IMPLEMENTATION.cloneDeterministic(salt);
8483

8584
NostalgicPool(clone).initialize(
8685
_underlyingAsset,
@@ -109,7 +108,7 @@ contract NostalgicFactory is INostalgicFactory {
109108
abi.encodePacked(_underlyingAsset, _name, _symbol, index)
110109
);
111110
return
112-
poolImplementation.predictDeterministicAddress(salt, address(this));
111+
POOL_IMPLEMENTATION.predictDeterministicAddress(salt, address(this));
113112
}
114113

115114
function getPoolsByCreator(

src/NostalgicPool.sol

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ import {INostalgicController} from "./interfaces/INostalgicController.sol";
1010
import {IAggregatorV3} from "./interfaces/IAggregatorV3.sol";
1111
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
1212
import {IERC20Metadata} from "@openzeppelin/contracts/interfaces/IERC20Metadata.sol";
13-
import {ERC20Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
14-
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
1513
import {ERC4626Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC4626Upgradeable.sol";
1614
import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
1715
import {IERC4626} from "@openzeppelin/contracts/interfaces/IERC4626.sol";
1816
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
17+
import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";
1918

2019
// /$$ /$$ /$$ /$$ /$$ /$$$$$$$ /$$
2120
// | $$$ | $$ | $$ | $$ |__/ | $$__ $$ | $$
@@ -63,6 +62,10 @@ contract NostalgicPool is
6362

6463
uint256 internal lastUpdateBlockNumber;
6564

65+
constructor() {
66+
_disableInitializers();
67+
}
68+
6669
function initialize(
6770
IERC20 _underyingAsset,
6871
string memory _name,
@@ -94,8 +97,8 @@ contract NostalgicPool is
9497
priceFeed = _priceFeed;
9598
borrowIndex = 1e18;
9699
protocolFeesFactor = _protocolFeesFactor;
97-
grantRole(DEFAULT_ADMIN_ROLE, _admin);
98-
grantRole(PAUSER_ROLE, _pauser);
100+
_grantRole(DEFAULT_ADMIN_ROLE, _admin);
101+
_grantRole(PAUSER_ROLE, _pauser);
99102
}
100103

101104
modifier accrueInterest() {
@@ -131,19 +134,20 @@ contract NostalgicPool is
131134
*/
132135
function getUnderlyingPriceInUSD() public view returns (uint256) {
133136
(, int256 price, , , ) = priceFeed.latestRoundData();
134-
require(price > 0, "Invalid price");
137+
require(price > 0, InvalidPrice());
135138

136139
uint8 priceDecimals = priceFeed.decimals();
137140
uint8 tokenDecimals = IERC20Metadata(asset()).decimals();
138141

139142
// Scale price to token decimals
140143
if (priceDecimals < tokenDecimals) {
141-
return uint256(price) * (10 ** (tokenDecimals - priceDecimals));
144+
return SafeCast.toUint256(price) * (10 ** (tokenDecimals - priceDecimals));
142145
} else {
143-
return uint256(price) / (10 ** (priceDecimals - tokenDecimals));
146+
return SafeCast.toUint256(price) / (10 ** (priceDecimals - tokenDecimals));
144147
}
145148
}
146149

150+
147151
/**
148152
* Returns USD value of a given token amount (18-decimals result)
149153
*/

src/interfaces/INostalgicPool.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ interface INostalgicPoolErrors {
1313
error ZeroAddress();
1414
error CannotLiquidateSelf();
1515
error CallerNotController();
16+
error InvalidPrice();
1617
}
1718

1819
interface INostalgicPoolEvents {

test/Counter.t.sol

Lines changed: 0 additions & 24 deletions
This file was deleted.

test/NostalgicFactory.t.sol

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.28;
3+
4+
import {Test, console} from "forge-std/Test.sol";
5+
import {NostalgicFactory} from "../src/NostalgicFactory.sol";
6+
import {NostalgicPool} from "../src/NostalgicPool.sol";
7+
import {IAggregatorV3} from "../src/interfaces/IAggregatorV3.sol";
8+
import {INostalgicRateModel} from "../src/interfaces/INostalgicRateModel.sol";
9+
10+
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
11+
import {MockERC20} from "./mocks/MockERC20.t.sol";
12+
contract NostalgicFactoryTest is Test {
13+
NostalgicFactory factory;
14+
address admin = makeAddr("admin");
15+
address pauser = makeAddr("pauser");
16+
IERC20 asset;
17+
function setUp() public {
18+
NostalgicPool impl = new NostalgicPool();
19+
asset = new MockERC20();
20+
factory = new NostalgicFactory(
21+
address(impl),
22+
address(1),
23+
admin,
24+
pauser
25+
);
26+
}
27+
28+
function testCreatePool() public {
29+
address pool = factory.createPool(
30+
asset,
31+
"MOCK",
32+
"MOCK",
33+
IAggregatorV3(address(2)),
34+
INostalgicRateModel(address(3)),
35+
500
36+
);
37+
}
38+
}

test/mocks/MockERC20.t.sol

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.28;
3+
4+
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
5+
import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
6+
7+
contract MockERC20 is IERC20, IERC20Metadata {
8+
string private _name;
9+
string private _symbol;
10+
uint8 private _decimals;
11+
12+
mapping(address => uint256) private _balances;
13+
mapping(address => mapping(address => uint256)) private _allowances;
14+
15+
uint256 private _totalSupply;
16+
17+
constructor() {
18+
_name = "Mock ERC20";
19+
_symbol = "MOCK";
20+
_decimals = 18;
21+
}
22+
23+
function name() public view override returns (string memory) {
24+
return _name;
25+
}
26+
27+
function symbol() public view override returns (string memory) {
28+
return _symbol;
29+
}
30+
31+
function decimals() public view override returns (uint8) {
32+
return _decimals;
33+
}
34+
35+
function totalSupply() public view override returns (uint256) {
36+
return _totalSupply;
37+
}
38+
39+
function balanceOf(address account) public view override returns (uint256) {
40+
return _balances[account];
41+
}
42+
43+
function transfer(
44+
address to,
45+
uint256 amount
46+
) public override returns (bool) {
47+
address owner = msg.sender;
48+
_transfer(owner, to, amount);
49+
return true;
50+
}
51+
52+
function allowance(
53+
address owner,
54+
address spender
55+
) public view override returns (uint256) {
56+
return _allowances[owner][spender];
57+
}
58+
59+
function approve(
60+
address spender,
61+
uint256 amount
62+
) public override returns (bool) {
63+
address owner = msg.sender;
64+
_approve(owner, spender, amount);
65+
return true;
66+
}
67+
68+
function transferFrom(
69+
address from,
70+
address to,
71+
uint256 amount
72+
) public override returns (bool) {
73+
address spender = msg.sender;
74+
_spendAllowance(from, spender, amount);
75+
_transfer(from, to, amount);
76+
return true;
77+
}
78+
79+
function increaseAllowance(
80+
address spender,
81+
uint256 addedValue
82+
) public returns (bool) {
83+
address owner = msg.sender;
84+
_approve(owner, spender, allowance(owner, spender) + addedValue);
85+
return true;
86+
}
87+
88+
function decreaseAllowance(
89+
address spender,
90+
uint256 subtractedValue
91+
) public returns (bool) {
92+
address owner = msg.sender;
93+
uint256 currentAllowance = allowance(owner, spender);
94+
require(
95+
currentAllowance >= subtractedValue,
96+
"ERC20: decreased allowance below zero"
97+
);
98+
unchecked {
99+
_approve(owner, spender, currentAllowance - subtractedValue);
100+
}
101+
return true;
102+
}
103+
104+
function mint(address account, uint256 amount) public {
105+
require(account != address(0), "ERC20: mint to the zero address");
106+
_totalSupply += amount;
107+
_balances[account] += amount;
108+
emit Transfer(address(0), account, amount);
109+
}
110+
111+
function burn(address account, uint256 amount) public {
112+
require(account != address(0), "ERC20: burn from the zero address");
113+
uint256 accountBalance = _balances[account];
114+
require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
115+
unchecked {
116+
_balances[account] = accountBalance - amount;
117+
}
118+
_totalSupply -= amount;
119+
emit Transfer(account, address(0), amount);
120+
}
121+
function burnFrom(address account, uint256 amount) public {
122+
require(account != address(0), "ERC20: burn from the zero address");
123+
uint256 accountBalance = _balances[account];
124+
require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
125+
unchecked {
126+
_balances[account] = accountBalance - amount;
127+
}
128+
_totalSupply -= amount;
129+
emit Transfer(account, address(0), amount);
130+
}
131+
132+
function _transfer(address from, address to, uint256 amount) internal {
133+
require(from != address(0), "ERC20: transfer from the zero address");
134+
require(to != address(0), "ERC20: transfer to the zero address");
135+
136+
uint256 fromBalance = _balances[from];
137+
require(
138+
fromBalance >= amount,
139+
"ERC20: transfer amount exceeds balance"
140+
);
141+
unchecked {
142+
_balances[from] = fromBalance - amount;
143+
}
144+
_balances[to] += amount;
145+
146+
emit Transfer(from, to, amount);
147+
}
148+
149+
function _approve(address owner, address spender, uint256 amount) internal {
150+
require(owner != address(0), "ERC20: approve from the zero address");
151+
require(spender != address(0), "ERC20: approve to the zero address");
152+
153+
_allowances[owner][spender] = amount;
154+
emit Approval(owner, spender, amount);
155+
}
156+
157+
function _spendAllowance(
158+
address owner,
159+
address spender,
160+
uint256 amount
161+
) internal {
162+
uint256 currentAllowance = allowance(owner, spender);
163+
if (currentAllowance != type(uint256).max) {
164+
require(
165+
currentAllowance >= amount,
166+
"ERC20: insufficient allowance"
167+
);
168+
unchecked {
169+
_approve(owner, spender, currentAllowance - amount);
170+
}
171+
}
172+
}
173+
}

0 commit comments

Comments
 (0)