-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathMorphoGetters.sol
180 lines (143 loc) · 7.97 KB
/
MorphoGetters.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.17;
import {IMorphoGetters} from "./interfaces/IMorpho.sol";
import {Types} from "./libraries/Types.sol";
import {MarketLib} from "./libraries/MarketLib.sol";
import {MarketBalanceLib} from "./libraries/MarketBalanceLib.sol";
import {BucketDLL} from "@morpho-data-structures/BucketDLL.sol";
import {LogarithmicBuckets} from "@morpho-data-structures/LogarithmicBuckets.sol";
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import {MorphoInternal} from "./MorphoInternal.sol";
/// @title MorphoGetters
/// @author Morpho Labs
/// @custom:contact security@morpho.xyz
/// @notice Abstract contract exposing all accessible getters.
abstract contract MorphoGetters is IMorphoGetters, MorphoInternal {
using MarketLib for Types.Market;
using MarketBalanceLib for Types.MarketBalances;
using BucketDLL for BucketDLL.List;
using EnumerableSet for EnumerableSet.AddressSet;
/* STORAGE */
/// @notice Returns the domain separator of the EIP712.
function DOMAIN_SEPARATOR() external view returns (bytes32) {
return _domainSeparator();
}
/// @notice Returns the pool address.
function pool() external view returns (address) {
return address(_pool);
}
/// @notice Returns the addresses provider address.
function addressesProvider() external view returns (address) {
return address(_addressesProvider);
}
/// @notice Returns the e-mode category ID of Morpho on the Aave protocol.
function eModeCategoryId() external view returns (uint256) {
return _eModeCategoryId;
}
/// @notice Returns the market data.
function market(address underlying) external view returns (Types.Market memory) {
return _market[underlying];
}
/// @notice Returns the list of the markets created.
function marketsCreated() external view returns (address[] memory) {
return _marketsCreated;
}
/// @notice Returns the scaled balance of `user` on the `underlying` market, supplied on pool (with `underlying` decimals).
function scaledPoolSupplyBalance(address underlying, address user) external view returns (uint256) {
return _marketBalances[underlying].scaledPoolSupplyBalance(user);
}
/// @notice Returns the scaled balance of `user` on the `underlying` market, supplied peer-to-peer (with `underlying` decimals).
function scaledP2PSupplyBalance(address underlying, address user) external view returns (uint256) {
return _marketBalances[underlying].scaledP2PSupplyBalance(user);
}
/// @notice Returns the scaled balance of `user` on the `underlying` market, borrowed from pool (with `underlying` decimals).
function scaledPoolBorrowBalance(address underlying, address user) external view returns (uint256) {
return _marketBalances[underlying].scaledPoolBorrowBalance(user);
}
/// @notice Returns the scaled balance of `user` on the `underlying` market, borrowed peer-to-peer (with `underlying` decimals).
function scaledP2PBorrowBalance(address underlying, address user) external view returns (uint256) {
return _marketBalances[underlying].scaledP2PBorrowBalance(user);
}
/// @notice Returns the scaled balance of `user` on the `underlying` market, supplied on pool & used as collateral (with `underlying` decimals).
function scaledCollateralBalance(address underlying, address user) external view returns (uint256) {
return _marketBalances[underlying].scaledCollateralBalance(user);
}
/// @notice Returns the total supply balance of `user` on the `underlying` market (in underlying).
function supplyBalance(address underlying, address user) external view returns (uint256) {
Types.Indexes256 memory indexes = _computeIndexes(underlying);
return _getUserSupplyBalanceFromIndexes(underlying, user, indexes);
}
/// @notice Returns the total borrow balance of `user` on the `underlying` market (in underlying).
function borrowBalance(address underlying, address user) external view returns (uint256) {
Types.Indexes256 memory indexes = _computeIndexes(underlying);
return _getUserBorrowBalanceFromIndexes(underlying, user, indexes);
}
/// @notice Returns the supply collateral balance of `user` on the `underlying` market (in underlying).
function collateralBalance(address underlying, address user) external view returns (uint256) {
return _getUserCollateralBalanceFromIndex(underlying, user, _pool.getReserveNormalizedIncome(underlying));
}
/// @notice Returns the list of collateral underlyings of `user`.
function userCollaterals(address user) external view returns (address[] memory) {
return _userCollaterals[user].values();
}
/// @notice Returns the list of borrowed underlyings of `user`.
function userBorrows(address user) external view returns (address[] memory) {
return _userBorrows[user].values();
}
/// @notice Returns whether `manager` is a manager of `delegator`.
function isManagedBy(address delegator, address manager) external view returns (bool) {
return _isManagedBy[delegator][manager];
}
/// @notice Returns the nonce of `user` for the manager approval signature.
function userNonce(address user) external view returns (uint256) {
return _userNonce[user];
}
/// @notice Returns the default iterations.
function defaultIterations() external view returns (Types.Iterations memory) {
return _defaultIterations;
}
/// @notice Returns the address of the positions manager.
function positionsManager() external view returns (address) {
return _positionsManager;
}
/// @notice Returns the address of the rewards manager.
function rewardsManager() external view returns (address) {
return address(_rewardsManager);
}
/// @notice Returns the address of the treasury vault.
function treasuryVault() external view returns (address) {
return _treasuryVault;
}
/// @notice Returns whether the claim rewards is paused or not.
function isClaimRewardsPaused() external view returns (bool) {
return _isClaimRewardsPaused;
}
/// @notice Returns the updated indexes (peer-to-peer and pool).
function updatedIndexes(address underlying) external view returns (Types.Indexes256 memory indexes) {
indexes = _computeIndexes(underlying);
}
/// @notice Returns the liquidity data about the position of `user`.
/// @param user The address of the user to get the liquidity data for.
/// @return The liquidity data of the user.
function liquidityData(address user) external view returns (Types.LiquidityData memory) {
return _liquidityData(user);
}
/// @notice Returns the account after `user` in the same bucket of the corresponding market side.
/// @dev Input address zero to get the head of the bucket.
/// @param underlying The address of the underlying asset.
/// @param position The position type, either pool or peer-to-peer and either supply or borrow.
/// @return The address of the next account in the data structure.
function getNext(address underlying, Types.Position position, address user) external view returns (address) {
LogarithmicBuckets.Buckets storage buckets = _getBuckets(underlying, position);
uint256 userBalance = buckets.valueOf[user];
uint256 userBucket = LogarithmicBuckets.highestSetBit(userBalance);
return buckets.buckets[userBucket].getNext(user);
}
/// @notice Returns the buckets mask of the corresponding market side.
/// @param underlying The address of the underlying asset.
/// @param position The position type, either pool or peer-to-peer and either supply or borrow.
/// @return The buckets mask of the corresponding market side.
function getBucketsMask(address underlying, Types.Position position) external view returns (uint256) {
return _getBuckets(underlying, position).bucketsMask;
}
}