Skip to content
This repository was archived by the owner on Aug 26, 2024. It is now read-only.

Commit bae6f0e

Browse files
committed
Fix supply and borrow cap visibility
1 parent 10c3e43 commit bae6f0e

File tree

6 files changed

+156
-146
lines changed

6 files changed

+156
-146
lines changed

contracts/PoolLens.sol

Lines changed: 36 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,7 @@ contract PoolLens is Initializable {
110110
*/
111111
function getPublicPoolsWithData()
112112
external
113-
returns (
114-
uint256[] memory,
115-
PoolDirectory.Pool[] memory,
116-
IonicPoolData[] memory,
117-
bool[] memory
118-
)
113+
returns (uint256[] memory, PoolDirectory.Pool[] memory, IonicPoolData[] memory, bool[] memory)
119114
{
120115
(uint256[] memory indexes, PoolDirectory.Pool[] memory publicPools) = directory.getPublicPools();
121116
(IonicPoolData[] memory data, bool[] memory errored) = getPoolsData(publicPools);
@@ -127,15 +122,9 @@ contract PoolLens is Initializable {
127122
* @dev This function is not designed to be called in a transaction: it is too gas-intensive.
128123
* Ideally, we can add the `view` modifier, but many cToken functions potentially modify the state.
129124
*/
130-
function getPublicPoolsByVerificationWithData(bool whitelistedAdmin)
131-
external
132-
returns (
133-
uint256[] memory,
134-
PoolDirectory.Pool[] memory,
135-
IonicPoolData[] memory,
136-
bool[] memory
137-
)
138-
{
125+
function getPublicPoolsByVerificationWithData(
126+
bool whitelistedAdmin
127+
) external returns (uint256[] memory, PoolDirectory.Pool[] memory, IonicPoolData[] memory, bool[] memory) {
139128
(uint256[] memory indexes, PoolDirectory.Pool[] memory publicPools) = directory.getPublicPoolsByVerification(
140129
whitelistedAdmin
141130
);
@@ -148,15 +137,9 @@ contract PoolLens is Initializable {
148137
* @dev This function is not designed to be called in a transaction: it is too gas-intensive.
149138
* Ideally, we can add the `view` modifier, but many cToken functions potentially modify the state.
150139
*/
151-
function getPoolsByAccountWithData(address account)
152-
external
153-
returns (
154-
uint256[] memory,
155-
PoolDirectory.Pool[] memory,
156-
IonicPoolData[] memory,
157-
bool[] memory
158-
)
159-
{
140+
function getPoolsByAccountWithData(
141+
address account
142+
) external returns (uint256[] memory, PoolDirectory.Pool[] memory, IonicPoolData[] memory, bool[] memory) {
160143
(uint256[] memory indexes, PoolDirectory.Pool[] memory accountPools) = directory.getPoolsByAccount(account);
161144
(IonicPoolData[] memory data, bool[] memory errored) = getPoolsData(accountPools);
162145
return (indexes, accountPools, data, errored);
@@ -167,15 +150,9 @@ contract PoolLens is Initializable {
167150
* @dev This function is not designed to be called in a transaction: it is too gas-intensive.
168151
* Ideally, we can add the `view` modifier, but many cToken functions potentially modify the state.
169152
*/
170-
function getPoolsOIonicrWithData(address user)
171-
external
172-
returns (
173-
uint256[] memory,
174-
PoolDirectory.Pool[] memory,
175-
IonicPoolData[] memory,
176-
bool[] memory
177-
)
178-
{
153+
function getPoolsOIonicrWithData(
154+
address user
155+
) external returns (uint256[] memory, PoolDirectory.Pool[] memory, IonicPoolData[] memory, bool[] memory) {
179156
(uint256[] memory indexes, PoolDirectory.Pool[] memory userPools) = directory.getPoolsOfUser(user);
180157
(IonicPoolData[] memory data, bool[] memory errored) = getPoolsData(userPools);
181158
return (indexes, userPools, data, errored);
@@ -210,16 +187,9 @@ contract PoolLens is Initializable {
210187
/**
211188
* @notice Returns total supply balance (in ETH), total borrow balance (in ETH), underlying token addresses, and underlying token symbols of a Ionic pool.
212189
*/
213-
function getPoolSummary(IonicComptroller comptroller)
214-
external
215-
returns (
216-
uint256,
217-
uint256,
218-
address[] memory,
219-
string[] memory,
220-
bool
221-
)
222-
{
190+
function getPoolSummary(
191+
IonicComptroller comptroller
192+
) external returns (uint256, uint256, address[] memory, string[] memory, bool) {
223193
uint256 totalBorrow = 0;
224194
uint256 totalSupply = 0;
225195
ICErc20[] memory cTokens = comptroller.getAllMarkets();
@@ -359,7 +329,10 @@ contract PoolLens is Initializable {
359329
return (detailedAssets);
360330
}
361331

362-
function getBorrowCapsPerCollateral(ICErc20 borrowedAsset, IonicComptroller comptroller)
332+
function getBorrowCapsPerCollateral(
333+
ICErc20 borrowedAsset,
334+
IonicComptroller comptroller
335+
)
363336
internal
364337
view
365338
returns (
@@ -448,7 +421,7 @@ contract PoolLens is Initializable {
448421
uint256[] memory supplyCapsPerAsset = new uint256[](poolMarkets.length);
449422
for (uint256 i = 0; i < poolMarkets.length; i++) {
450423
assets[i] = address(poolMarkets[i]);
451-
supplyCapsPerAsset[i] = comptroller.supplyCaps(assets[i]);
424+
supplyCapsPerAsset[i] = comptroller.effectiveSupplyCaps(assets[i]);
452425
}
453426

454427
return (assets, supplyCapsPerAsset);
@@ -458,23 +431,17 @@ contract PoolLens is Initializable {
458431
* @notice returns the total supply cap for each asset in the pool and the total non-whitelist supplied assets
459432
* @dev This function is not designed to be called in a transaction: it is too gas-intensive.
460433
*/
461-
function getSupplyCapsDataForPool(IonicComptroller comptroller)
462-
public
463-
view
464-
returns (
465-
address[] memory,
466-
uint256[] memory,
467-
uint256[] memory
468-
)
469-
{
434+
function getSupplyCapsDataForPool(
435+
IonicComptroller comptroller
436+
) public view returns (address[] memory, uint256[] memory, uint256[] memory) {
470437
ICErc20[] memory poolMarkets = comptroller.getAllMarkets();
471438

472439
address[] memory assets = new address[](poolMarkets.length);
473440
uint256[] memory supplyCapsPerAsset = new uint256[](poolMarkets.length);
474441
uint256[] memory nonWhitelistedTotalSupply = new uint256[](poolMarkets.length);
475442
for (uint256 i = 0; i < poolMarkets.length; i++) {
476443
assets[i] = address(poolMarkets[i]);
477-
supplyCapsPerAsset[i] = comptroller.supplyCaps(assets[i]);
444+
supplyCapsPerAsset[i] = comptroller.effectiveSupplyCaps(assets[i]);
478445
uint256 assetTotalSupplied = poolMarkets[i].getTotalUnderlyingSupplied();
479446
uint256 whitelistedSuppliersSupply = comptroller.getWhitelistedSuppliersSupply(assets[i]);
480447
if (whitelistedSuppliersSupply >= assetTotalSupplied) nonWhitelistedTotalSupply[i] = 0;
@@ -488,7 +455,9 @@ contract PoolLens is Initializable {
488455
* @notice returns the total borrow cap and the per collateral borrowing cap/blacklist for the asset
489456
* @dev This function is not designed to be called in a transaction: it is too gas-intensive.
490457
*/
491-
function getBorrowCapsForAsset(ICErc20 asset)
458+
function getBorrowCapsForAsset(
459+
ICErc20 asset
460+
)
492461
public
493462
view
494463
returns (
@@ -500,14 +469,16 @@ contract PoolLens is Initializable {
500469
{
501470
IonicComptroller comptroller = IonicComptroller(asset.comptroller());
502471
(collateral, borrowCapsPerCollateral, collateralBlacklisted) = getBorrowCapsPerCollateral(asset, comptroller);
503-
totalBorrowCap = comptroller.borrowCaps(address(asset));
472+
totalBorrowCap = comptroller.effectiveBorrowCaps(address(asset));
504473
}
505474

506475
/**
507476
* @notice returns the total borrow cap, the per collateral borrowing cap/blacklist for the asset and the total non-whitelist borrows
508477
* @dev This function is not designed to be called in a transaction: it is too gas-intensive.
509478
*/
510-
function getBorrowCapsDataForAsset(ICErc20 asset)
479+
function getBorrowCapsDataForAsset(
480+
ICErc20 asset
481+
)
511482
public
512483
view
513484
returns (
@@ -520,7 +491,7 @@ contract PoolLens is Initializable {
520491
{
521492
IonicComptroller comptroller = IonicComptroller(asset.comptroller());
522493
(collateral, borrowCapsPerCollateral, collateralBlacklisted) = getBorrowCapsPerCollateral(asset, comptroller);
523-
totalBorrowCap = comptroller.borrowCaps(address(asset));
494+
totalBorrowCap = comptroller.effectiveBorrowCaps(address(asset));
524495
uint256 totalBorrows = asset.totalBorrowsCurrent();
525496
uint256 whitelistedBorrowersBorrows = comptroller.getWhitelistedBorrowersBorrows(address(asset));
526497
if (whitelistedBorrowersBorrows >= totalBorrows) nonWhitelistedTotalBorrows = 0;
@@ -532,11 +503,9 @@ contract PoolLens is Initializable {
532503
* Note that the whitelist does not have to be enforced.
533504
* @dev This function is not designed to be called in a transaction: it is too gas-intensive.
534505
*/
535-
function getWhitelistedPoolsByAccount(address account)
536-
public
537-
view
538-
returns (uint256[] memory, PoolDirectory.Pool[] memory)
539-
{
506+
function getWhitelistedPoolsByAccount(
507+
address account
508+
) public view returns (uint256[] memory, PoolDirectory.Pool[] memory) {
540509
(, PoolDirectory.Pool[] memory pools) = directory.getActivePools();
541510
uint256 arrayLength = 0;
542511

@@ -569,15 +538,9 @@ contract PoolLens is Initializable {
569538
* @dev This function is not designed to be called in a transaction: it is too gas-intensive.
570539
* Ideally, we can add the `view` modifier, but many cToken functions potentially modify the state.
571540
*/
572-
function getWhitelistedPoolsByAccountWithData(address account)
573-
external
574-
returns (
575-
uint256[] memory,
576-
PoolDirectory.Pool[] memory,
577-
IonicPoolData[] memory,
578-
bool[] memory
579-
)
580-
{
541+
function getWhitelistedPoolsByAccountWithData(
542+
address account
543+
) external returns (uint256[] memory, PoolDirectory.Pool[] memory, IonicPoolData[] memory, bool[] memory) {
581544
(uint256[] memory indexes, PoolDirectory.Pool[] memory accountPools) = getWhitelistedPoolsByAccount(account);
582545
(IonicPoolData[] memory data, bool[] memory errored) = getPoolsData(accountPools);
583546
return (indexes, accountPools, data, errored);

contracts/compound/Comptroller.sol

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { IFeeDistributor } from "./IFeeDistributor.sol";
1010
import { IIonicFlywheel } from "../ionic/strategies/flywheel/IIonicFlywheel.sol";
1111
import { DiamondExtension, DiamondBase, LibDiamond } from "../ionic/DiamondExtension.sol";
1212
import { ComptrollerExtensionInterface, ComptrollerBase, ComptrollerInterface } from "./ComptrollerInterface.sol";
13-
import { PrudentiaLib } from "../adrastia/PrudentiaLib.sol";
1413

1514
import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
1615

@@ -69,6 +68,26 @@ contract Comptroller is ComptrollerBase, ComptrollerInterface, ComptrollerErrorR
6968
_;
7069
}
7170

71+
/**
72+
* @notice Gets the supply cap of a cToken in the units of the underlying asset.
73+
* @param cToken The address of the cToken.
74+
*/
75+
function effectiveSupplyCaps(
76+
address cToken
77+
) public view override(ComptrollerBase, ComptrollerInterface) returns (uint256 supplyCap) {
78+
return ComptrollerBase.effectiveSupplyCaps(cToken);
79+
}
80+
81+
/**
82+
* @notice Gets the borrow cap of a cToken in the units of the underlying asset.
83+
* @param cToken The address of the cToken.
84+
*/
85+
function effectiveBorrowCaps(
86+
address cToken
87+
) public view override(ComptrollerBase, ComptrollerInterface) returns (uint256 borrowCap) {
88+
return ComptrollerBase.effectiveBorrowCaps(cToken);
89+
}
90+
7291
/*** Assets You Are In ***/
7392

7493
/**
@@ -243,7 +262,7 @@ contract Comptroller is ComptrollerBase, ComptrollerInterface, ComptrollerErrorR
243262
return uint256(Error.SUPPLIER_NOT_WHITELISTED);
244263
}
245264

246-
uint256 supplyCap = supplyCaps(cTokenAddress);
265+
uint256 supplyCap = effectiveSupplyCaps(cTokenAddress);
247266

248267
// Supply cap of 0 corresponds to unlimited supplying
249268
if (supplyCap != 0 && !supplyCapWhitelist[cTokenAddress].contains(minter)) {
@@ -451,7 +470,7 @@ contract Comptroller is ComptrollerBase, ComptrollerInterface, ComptrollerErrorR
451470
return uint256(Error.SUPPLIER_NOT_WHITELISTED);
452471
}
453472

454-
uint256 borrowCap = borrowCaps(cToken);
473+
uint256 borrowCap = effectiveBorrowCaps(cToken);
455474

456475
// Borrow cap of 0 corresponds to unlimited borrowing
457476
if (borrowCap != 0 && !borrowCapWhitelist[cToken].contains(borrower)) {
@@ -1266,8 +1285,8 @@ contract Comptroller is ComptrollerBase, ComptrollerInterface, ComptrollerErrorR
12661285
functionSelectors[--fnsCount] = this._beforeNonReentrant.selector;
12671286
functionSelectors[--fnsCount] = this._afterNonReentrant.selector;
12681287
functionSelectors[--fnsCount] = this._becomeImplementation.selector;
1269-
functionSelectors[--fnsCount] = this.supplyCaps.selector;
1270-
functionSelectors[--fnsCount] = this.borrowCaps.selector;
1288+
functionSelectors[--fnsCount] = this.effectiveSupplyCaps.selector;
1289+
functionSelectors[--fnsCount] = this.effectiveBorrowCaps.selector;
12711290

12721291
require(fnsCount == 0, "use the correct array length");
12731292
}

contracts/compound/ComptrollerFirstExtension.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ contract ComptrollerFirstExtension is
140140
}
141141
}
142142

143-
uint256 supplyCap = supplyCaps(address(collateral));
143+
uint256 supplyCap = effectiveSupplyCaps(address(collateral));
144144

145145
// if there is any supply cap, don't allow donations to the market/plugin to go around it
146146
if (supplyCap > 0 && !supplyCapWhitelist[address(collateral)].contains(account)) {
@@ -168,7 +168,7 @@ contract ComptrollerFirstExtension is
168168
require(numMarkets != 0 && numMarkets == numSupplyCaps, "!input");
169169

170170
for (uint256 i = 0; i < numMarkets; i++) {
171-
_supplyCaps[address(cTokens[i])] = newSupplyCaps[i];
171+
supplyCaps[address(cTokens[i])] = newSupplyCaps[i];
172172
emit NewSupplyCap(cTokens[i], newSupplyCaps[i]);
173173
}
174174
}
@@ -188,7 +188,7 @@ contract ComptrollerFirstExtension is
188188
require(numMarkets != 0 && numMarkets == numBorrowCaps, "!input");
189189

190190
for (uint256 i = 0; i < numMarkets; i++) {
191-
_borrowCaps[address(cTokens[i])] = newBorrowCaps[i];
191+
borrowCaps[address(cTokens[i])] = newBorrowCaps[i];
192192
emit NewBorrowCap(cTokens[i], newBorrowCaps[i]);
193193
}
194194
}

contracts/compound/ComptrollerInterface.sol

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,20 @@ interface ComptrollerInterface {
110110
function _beforeNonReentrant() external;
111111

112112
function _afterNonReentrant() external;
113+
114+
/*** New supply and borrow cap view functions ***/
115+
116+
/**
117+
* @notice Gets the supply cap of a cToken in the units of the underlying asset.
118+
* @param cToken The address of the cToken.
119+
*/
120+
function effectiveSupplyCaps(address cToken) external view returns (uint256 supplyCap);
121+
122+
/**
123+
* @notice Gets the borrow cap of a cToken in the units of the underlying asset.
124+
* @param cToken The address of the cToken.
125+
*/
126+
function effectiveBorrowCaps(address cToken) external view returns (uint256 borrowCap);
113127
}
114128

115129
interface ComptrollerStorageInterface {
@@ -145,8 +159,22 @@ interface ComptrollerStorageInterface {
145159

146160
function cTokensByUnderlying(address) external view returns (address);
147161

162+
/**
163+
* Gets the supply cap of a cToken in the units of the underlying asset.
164+
* @dev WARNING: This function is misleading if Adrastia Prudentia is being used for the supply cap. Instead, use
165+
* `effectiveSupplyCaps` to get the correct supply cap.
166+
* @param cToken The address of the cToken.
167+
* @return The supply cap in the units of the underlying asset.
168+
*/
148169
function supplyCaps(address cToken) external view returns (uint256);
149170

171+
/**
172+
* Gets the borrow cap of a cToken in the units of the underlying asset.
173+
* @dev WARNING: This function is misleading if Adrastia Prudentia is being used for the borrow cap. Instead, use
174+
* `effectiveBorrowCaps` to get the correct borrow cap.
175+
* @param cToken The address of the cToken.
176+
* @return The borrow cap in the units of the underlying asset.
177+
*/
150178
function borrowCaps(address cToken) external view returns (uint256);
151179

152180
function markets(address cToken) external view returns (bool, uint256);
@@ -321,7 +349,7 @@ abstract contract ComptrollerBase is ComptrollerV4Storage {
321349
* @notice Gets the supply cap of a cToken in the units of the underlying asset.
322350
* @param cToken The address of the cToken.
323351
*/
324-
function supplyCaps(address cToken) public view returns (uint256 supplyCap) {
352+
function effectiveSupplyCaps(address cToken) public view virtual returns (uint256 supplyCap) {
325353
PrudentiaLib.PrudentiaConfig memory capConfig = supplyCapConfig;
326354

327355
// Check if we're using Adrastia Prudentia for the supply cap
@@ -356,15 +384,15 @@ abstract contract ComptrollerBase is ComptrollerV4Storage {
356384
// We don't have a controller, so we're using the local supply cap
357385

358386
// Get the supply cap from the local supply cap
359-
supplyCap = _supplyCaps[cToken];
387+
supplyCap = supplyCaps[cToken];
360388
}
361389
}
362390

363391
/**
364392
* @notice Gets the borrow cap of a cToken in the units of the underlying asset.
365393
* @param cToken The address of the cToken.
366394
*/
367-
function borrowCaps(address cToken) public view returns (uint256 borrowCap) {
395+
function effectiveBorrowCaps(address cToken) public view virtual returns (uint256 borrowCap) {
368396
PrudentiaLib.PrudentiaConfig memory capConfig = borrowCapConfig;
369397

370398
// Check if we're using Adrastia Prudentia for the borrow cap
@@ -397,7 +425,7 @@ abstract contract ComptrollerBase is ComptrollerV4Storage {
397425
}
398426
} else {
399427
// We don't have a controller, so we're using the local borrow cap
400-
borrowCap = _borrowCaps[cToken];
428+
borrowCap = borrowCaps[cToken];
401429
}
402430
}
403431
}

0 commit comments

Comments
 (0)