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

Commit 922ae6e

Browse files
committed
Use underlying token addresses with the Prudentia cap controller
1 parent a533fef commit 922ae6e

File tree

2 files changed

+60
-58
lines changed

2 files changed

+60
-58
lines changed

contracts/compound/Comptroller.sol

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,14 +258,15 @@ contract Comptroller is ComptrollerBase, ComptrollerInterface, ComptrollerErrorR
258258
if (capConfig.controller != address(0)) {
259259
// We have a controller, so we're using Adrastia Prudentia
260260

261+
address underlyingToken = ICErc20(cTokenAddress).underlying();
262+
261263
// Get the supply cap from Adrastia Prudentia
262-
supplyCap = IHistoricalRates(capConfig.controller).getRateAt(cTokenAddress, capConfig.offset).current;
264+
supplyCap = IHistoricalRates(capConfig.controller).getRateAt(underlyingToken, capConfig.offset).current;
263265

264266
// Prudentia trims decimal points from amounts while our code requires the mantissa amount, so we
265267
// must scale the supply cap to get the correct amount
266268

267269
int256 scaleByDecimals = 18;
268-
address underlyingToken = ICErc20(cTokenAddress).underlying();
269270
// Not all ERC20s implement decimals(), so we use a staticcall and check the return data
270271
(bool success, bytes memory data) = underlyingToken.staticcall(abi.encodeWithSignature("decimals()"));
271272
if (success && data.length == 32) {
@@ -514,14 +515,15 @@ contract Comptroller is ComptrollerBase, ComptrollerInterface, ComptrollerErrorR
514515
if (capConfig.controller != address(0)) {
515516
// We have a controller, so we're using Adrastia Prudentia
516517

518+
address underlyingToken = ICErc20(cToken).underlying();
519+
517520
// Get the borrow cap from Adrastia Prudentia
518-
borrowCap = IHistoricalRates(capConfig.controller).getRateAt(cToken, capConfig.offset).current;
521+
borrowCap = IHistoricalRates(capConfig.controller).getRateAt(underlyingToken, capConfig.offset).current;
519522

520523
// Prudentia trims decimal points from amounts while our code requires the mantissa amount, so we
521524
// must scale the supply cap to get the correct amount
522525

523526
int256 scaleByDecimals = 18;
524-
address underlyingToken = ICErc20(cToken).underlying();
525527
// Not all ERC20s implement decimals(), so we use a staticcall and check the return data
526528
(bool success, bytes memory data) = underlyingToken.staticcall(abi.encodeWithSignature("decimals()"));
527529
if (success && data.length == 32) {

0 commit comments

Comments
 (0)