From 8ab8143a6ec6aa38d8c5b44ce0a1731a4abe4004 Mon Sep 17 00:00:00 2001 From: Patrick McKelvy Date: Thu, 10 Aug 2023 13:30:56 -0400 Subject: [PATCH 1/4] use comet decimals instead of wrapper decimals. --- contracts/plugins/assets/compoundv3/CTokenV3Collateral.sol | 2 +- contracts/plugins/assets/compoundv3/vendor/IComet.sol | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/contracts/plugins/assets/compoundv3/CTokenV3Collateral.sol b/contracts/plugins/assets/compoundv3/CTokenV3Collateral.sol index a4d9e8f62..033cce97d 100644 --- a/contracts/plugins/assets/compoundv3/CTokenV3Collateral.sol +++ b/contracts/plugins/assets/compoundv3/CTokenV3Collateral.sol @@ -53,7 +53,7 @@ contract CTokenV3Collateral is AppreciatingFiatCollateral { } function _underlyingRefPerTok() internal view virtual override returns (uint192) { - return shiftl_toFix(ICusdcV3Wrapper(address(erc20)).exchangeRate(), -int8(erc20Decimals)); + return shiftl_toFix(ICusdcV3Wrapper(address(erc20)).exchangeRate(), -int8(comet.decimals())); } /// Refresh exchange rates and update default status. diff --git a/contracts/plugins/assets/compoundv3/vendor/IComet.sol b/contracts/plugins/assets/compoundv3/vendor/IComet.sol index 44fffae2d..e249a3663 100644 --- a/contracts/plugins/assets/compoundv3/vendor/IComet.sol +++ b/contracts/plugins/assets/compoundv3/vendor/IComet.sol @@ -6,4 +6,6 @@ interface IComet { /// @dev uint104 function targetReserves() external view returns (uint256); + + function decimals() external view returns (uint8); } From ff85cc33b886162067a333e3a699630cc452cdbe Mon Sep 17 00:00:00 2001 From: Patrick McKelvy Date: Thu, 10 Aug 2023 15:08:03 -0400 Subject: [PATCH 2/4] fix linting. --- contracts/plugins/assets/compoundv3/CTokenV3Collateral.sol | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contracts/plugins/assets/compoundv3/CTokenV3Collateral.sol b/contracts/plugins/assets/compoundv3/CTokenV3Collateral.sol index 033cce97d..fbcee8e90 100644 --- a/contracts/plugins/assets/compoundv3/CTokenV3Collateral.sol +++ b/contracts/plugins/assets/compoundv3/CTokenV3Collateral.sol @@ -53,7 +53,8 @@ contract CTokenV3Collateral is AppreciatingFiatCollateral { } function _underlyingRefPerTok() internal view virtual override returns (uint192) { - return shiftl_toFix(ICusdcV3Wrapper(address(erc20)).exchangeRate(), -int8(comet.decimals())); + return + shiftl_toFix(ICusdcV3Wrapper(address(erc20)).exchangeRate(), -int8(comet.decimals())); } /// Refresh exchange rates and update default status. From 8ddeef2c8c3e6d907db60f5b857937cd84561f7f Mon Sep 17 00:00:00 2001 From: Patrick McKelvy Date: Mon, 21 Aug 2023 11:05:06 -0400 Subject: [PATCH 3/4] cache comet decimals. --- contracts/plugins/assets/compoundv3/CTokenV3Collateral.sol | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/contracts/plugins/assets/compoundv3/CTokenV3Collateral.sol b/contracts/plugins/assets/compoundv3/CTokenV3Collateral.sol index fbcee8e90..369f93532 100644 --- a/contracts/plugins/assets/compoundv3/CTokenV3Collateral.sol +++ b/contracts/plugins/assets/compoundv3/CTokenV3Collateral.sol @@ -31,6 +31,7 @@ contract CTokenV3Collateral is AppreciatingFiatCollateral { IERC20 public immutable rewardERC20; IComet public immutable comet; uint256 public immutable reservesThresholdIffy; // {qUSDC} + uint8 public immutable cometDecimals; /// @param config.chainlinkFeed Feed units: {UoA/ref} constructor( @@ -41,6 +42,7 @@ contract CTokenV3Collateral is AppreciatingFiatCollateral { rewardERC20 = ICusdcV3Wrapper(address(config.erc20)).rewardERC20(); comet = IComet(address(ICusdcV3Wrapper(address(erc20)).underlyingComet())); reservesThresholdIffy = reservesThresholdIffy_; + cometDecimals = comet.decimals(); } function bal(address account) external view override(Asset, IAsset) returns (uint192) { @@ -54,7 +56,7 @@ contract CTokenV3Collateral is AppreciatingFiatCollateral { function _underlyingRefPerTok() internal view virtual override returns (uint192) { return - shiftl_toFix(ICusdcV3Wrapper(address(erc20)).exchangeRate(), -int8(comet.decimals())); + shiftl_toFix(ICusdcV3Wrapper(address(erc20)).exchangeRate(), -int8(cometDecimals)); } /// Refresh exchange rates and update default status. From ff132ca6e2fad741a26035204ddd00af3425b024 Mon Sep 17 00:00:00 2001 From: Patrick McKelvy Date: Tue, 22 Aug 2023 13:12:52 -0400 Subject: [PATCH 4/4] fix linting. --- contracts/plugins/assets/compoundv3/CTokenV3Collateral.sol | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/contracts/plugins/assets/compoundv3/CTokenV3Collateral.sol b/contracts/plugins/assets/compoundv3/CTokenV3Collateral.sol index 369f93532..f0f170360 100644 --- a/contracts/plugins/assets/compoundv3/CTokenV3Collateral.sol +++ b/contracts/plugins/assets/compoundv3/CTokenV3Collateral.sol @@ -55,8 +55,7 @@ contract CTokenV3Collateral is AppreciatingFiatCollateral { } function _underlyingRefPerTok() internal view virtual override returns (uint192) { - return - shiftl_toFix(ICusdcV3Wrapper(address(erc20)).exchangeRate(), -int8(cometDecimals)); + return shiftl_toFix(ICusdcV3Wrapper(address(erc20)).exchangeRate(), -int8(cometDecimals)); } /// Refresh exchange rates and update default status.