Skip to content

Commit 8af428b

Browse files
committed
upgrade compiler to 0.8.30 and remove deprecated mocks
- Updated all source and test contracts to Solidity 0.8.30 - Removed outdated diagram and redundant - Introduced for better internal state testing - Enhanced constructor with native token validation - Added library integration in - Expanded unit tests with coverage (exchange rate, utilization, borrow index) - Improved Makefile to use updated bulloak scaffold command with 0.8.30
1 parent 425bec0 commit 8af428b

22 files changed

Lines changed: 228 additions & 135 deletions

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ gen:
66
@find test/unit -type f -name "*.tree" \
77
! -size 0c \
88
! -exec test -f "$$(dirname "{}")/$$(basename "{}" .tree).t.sol" \; \
9-
-exec sh -c 'if grep -q "[A-Za-z]" "$$1"; then bulloak scaffold -S -w -s 0.8.28 "$$1"; fi' _ {} \;
9+
-exec sh -c 'if grep -q "[A-Za-z]" "$$1"; then bulloak scaffold -S -w -s 0.8.30 "$$1"; fi' _ {} \;
1010

1111
check:
1212
@python3 convert_trees.py test/unit

images/contract-interaction.png

346 KB
Loading

design.mmd renamed to images/design.mmd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@ graph TD
3131
AM --> AN[Borrower Redeems Collateral]
3232
AN --> AO[Exit]
3333
AL -->|Continue Borrowing| AG
34+

images/user-interaction.png

820 KB
Loading

src/CollateralManager.sol

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
// SPDX-License-Identifier: MIT
2-
pragma solidity 0.8.28;
2+
pragma solidity 0.8.30;
3+
4+
contract CollateralManager { }

src/LiquidationManger.sol

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity 0.8.30;
3+
4+
contract LiquidationManager { }

src/ZErc20.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: MIT
2-
pragma solidity 0.8.28;
2+
pragma solidity 0.8.30;
33

44
import { IZToken, ZToken } from "./ZToken.sol";
55

src/ZNative.sol

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
// SPDX-License-Identifier: MIT
2-
pragma solidity 0.8.28;
2+
pragma solidity 0.8.30;
33

44
import { IZToken, ZToken } from "./ZToken.sol";
55

66
contract ZNative is ZToken {
7-
constructor(IZToken.MarketConfig memory _config) ZToken(_config) { }
7+
address private constant NATIVE_TOKEN_ADDRESS = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
8+
9+
constructor(IZToken.MarketConfig memory _config) ZToken(_config) {
10+
if (_config.underlyingToken != NATIVE_TOKEN_ADDRESS) revert();
11+
}
812

913
function name() public view override returns (string memory) { }
1014

src/ZToken.sol

Lines changed: 22 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,33 @@
11
// SPDX-License-Identifier: MIT
2-
pragma solidity 0.8.28;
2+
pragma solidity 0.8.30;
33

44
import { ERC20 } from "solady/tokens/ERC20.sol";
55
import { IZToken } from "./interfaces/IZToken.sol";
66
import { FixedPointMathLib } from "solady/utils/FixedPointMathLib.sol";
7+
import { InterestMath } from "./libraries/InterestMath.sol";
78

89
abstract contract ZToken is IZToken, ERC20 {
910
using FixedPointMathLib for uint256;
11+
using InterestMath for uint256;
1012

11-
uint256 private totalCash;
12-
uint256 private totalBorrow;
13-
uint256 private totalReserve;
14-
uint256 private borrowIndex;
13+
uint256 internal totalBorrow;
14+
uint256 internal totalReserve;
15+
uint256 internal borrowIndex;
1516

16-
address private immutable UNDERLYING_TOKEN;
17+
address public immutable UNDERLYING_TOKEN;
1718

18-
uint256 private immutable UTILIZATION_THRESHOLD;
19-
uint256 private immutable SLOPE_BEFORE_KINK;
20-
uint256 private immutable SLOPE_AFTER_KINK;
21-
uint256 private immutable BASE_BORROW_RATE;
22-
uint256 private immutable RESERVE_FACTOR;
23-
uint256 private immutable COLLATERAL_FACTOR;
19+
uint256 public immutable UTILIZATION_THRESHOLD;
20+
uint256 public immutable SLOPE_BEFORE_KINK;
21+
uint256 public immutable SLOPE_AFTER_KINK;
22+
uint256 public immutable BASE_BORROW_RATE;
23+
uint256 public immutable RESERVE_FACTOR;
24+
uint256 public immutable COLLATERAL_FACTOR;
2425

25-
uint256 private constant SECONDS_PER_YEAR = 365 days;
26+
uint256 public constant SECONDS_PER_YEAR = 365 days;
27+
uint256 public constant INITIAL_EXCHANGE_RATE = 0.02e18;
2628

27-
mapping(address user => uint256 index) private userBorrowIndex;
28-
mapping(address user => uint256 amount) private collateralAmount;
29+
mapping(address user => uint256 index) public userBorrowIndex;
30+
mapping(address user => uint256 amount) public collateralAmount;
2931

3032
constructor(MarketConfig memory _config) {
3133
UNDERLYING_TOKEN = _config.underlyingToken;
@@ -39,45 +41,12 @@ abstract contract ZToken is IZToken, ERC20 {
3941
borrowIndex = 1e18;
4042
}
4143

42-
function _mint(uint256 _zTokenAmount) internal returns (uint256) { }
44+
function _getCash() internal view virtual returns (uint256) { }
4345

44-
function _getUtilization() internal pure returns (uint256) { }
46+
function getExchangeRate() external view returns (uint256) {
47+
uint256 cash = _getCash();
48+
if (cash == 0) return INITIAL_EXCHANGE_RATE;
4549

46-
function getTotalCash() external view returns (uint256) {
47-
return totalCash;
48-
}
49-
50-
function getReserves() external view returns (uint256) {
51-
return totalReserve;
52-
}
53-
54-
function getExchangeRate() external view returns (uint256) { }
55-
56-
function getUnderlyingToken() external view returns (address) {
57-
return UNDERLYING_TOKEN;
58-
}
59-
60-
function utilizationThreshold() external view returns (uint256) {
61-
return UTILIZATION_THRESHOLD;
62-
}
63-
64-
function slopeBeforeKink() external view returns (uint256) {
65-
return SLOPE_BEFORE_KINK;
66-
}
67-
68-
function slopeAfterKink() external view returns (uint256) {
69-
return SLOPE_AFTER_KINK;
70-
}
71-
72-
function baseBorrowRate() external view returns (uint256) {
73-
return BASE_BORROW_RATE;
74-
}
75-
76-
function reserveFactor() external view returns (uint256) {
77-
return RESERVE_FACTOR;
78-
}
79-
80-
function collateralFactor() external view returns (uint256) {
81-
return COLLATERAL_FACTOR;
50+
return cash.getExchangeRate(totalBorrow, totalReserve, totalSupply());
8251
}
8352
}

src/ZTokenFactory.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
// SPDX-License-Identifier: MIT
2-
pragma solidity 0.8.28;
2+
pragma solidity 0.8.30;
33

44
contract ZTokenFactory { }

0 commit comments

Comments
 (0)