11// SPDX-License-Identifier: MIT
2- pragma solidity 0.8.28 ;
2+ pragma solidity 0.8.30 ;
33
44import { ERC20 } from "solady/tokens/ERC20.sol " ;
55import { IZToken } from "./interfaces/IZToken.sol " ;
66import { FixedPointMathLib } from "solady/utils/FixedPointMathLib.sol " ;
7+ import { InterestMath } from "./libraries/InterestMath.sol " ;
78
89abstract 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}
0 commit comments