From 2942a1219b29d285bc880e169c457b90bdbbc07a Mon Sep 17 00:00:00 2001 From: nikhilbajaj31 Date: Wed, 30 Oct 2024 17:10:45 +0530 Subject: [PATCH] feat: add support for corn staking enabled atokens --- contracts/interfaces/ICornStakingSilo.sol | 7 ++++++ .../IDefaultInterestRateStrategy.sol | 6 +++++ .../DefaultReserveInterestRateStrategy.sol | 22 ++++++++++++++++++- 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 contracts/interfaces/ICornStakingSilo.sol diff --git a/contracts/interfaces/ICornStakingSilo.sol b/contracts/interfaces/ICornStakingSilo.sol new file mode 100644 index 000000000..dd092d130 --- /dev/null +++ b/contracts/interfaces/ICornStakingSilo.sol @@ -0,0 +1,7 @@ +// SPDX-License-Identifier: AGPL-3.0 +pragma solidity ^0.8.0; + + +interface ICornStakingSilo { + function sharesOf(address user, address token) external view returns (uint256); +} \ No newline at end of file diff --git a/contracts/interfaces/IDefaultInterestRateStrategy.sol b/contracts/interfaces/IDefaultInterestRateStrategy.sol index 22770226a..ee8594d0b 100644 --- a/contracts/interfaces/IDefaultInterestRateStrategy.sol +++ b/contracts/interfaces/IDefaultInterestRateStrategy.sol @@ -42,6 +42,12 @@ interface IDefaultInterestRateStrategy is IReserveInterestRateStrategy { */ function ADDRESSES_PROVIDER() external view returns (IPoolAddressesProvider); + /** + * @notice Returns the address of the Corn Staking Silo + * @return The address of the Corn Staking Silo contract + */ + function CORN_STAKING() external view returns (ICornStakingSilo); + /** * @notice Returns the variable rate slope below optimal usage ratio * @dev It's the variable rate when usage ratio > 0 and <= OPTIMAL_USAGE_RATIO diff --git a/contracts/protocol/pool/DefaultReserveInterestRateStrategy.sol b/contracts/protocol/pool/DefaultReserveInterestRateStrategy.sol index 61363dd14..cb005202f 100644 --- a/contracts/protocol/pool/DefaultReserveInterestRateStrategy.sol +++ b/contracts/protocol/pool/DefaultReserveInterestRateStrategy.sol @@ -9,6 +9,7 @@ import {Errors} from '../libraries/helpers/Errors.sol'; import {IDefaultInterestRateStrategy} from '../../interfaces/IDefaultInterestRateStrategy.sol'; import {IReserveInterestRateStrategy} from '../../interfaces/IReserveInterestRateStrategy.sol'; import {IPoolAddressesProvider} from '../../interfaces/IPoolAddressesProvider.sol'; +import { ICornStakingSilo } from "../../interfaces/ICornStakingSilo.sol"; /** * @title DefaultReserveInterestRateStrategy contract @@ -58,6 +59,10 @@ contract DefaultReserveInterestRateStrategy is IDefaultInterestRateStrategy { // Additional premium applied to stable rate when stable debt surpass `OPTIMAL_STABLE_TO_TOTAL_DEBT_RATIO` uint256 internal immutable _stableRateExcessOffset; + // The corn staking contract + ICornStakingSilo public immutable CORN_STAKING; + + /** * @dev Constructor. * @param provider The address of the PoolAddressesProvider contract @@ -81,7 +86,8 @@ contract DefaultReserveInterestRateStrategy is IDefaultInterestRateStrategy { uint256 stableRateSlope2, uint256 baseStableRateOffset, uint256 stableRateExcessOffset, - uint256 optimalStableToTotalDebtRatio + uint256 optimalStableToTotalDebtRatio, + address cornStaking ) { require(WadRayMath.RAY >= optimalUsageRatio, Errors.INVALID_OPTIMAL_USAGE_RATIO); require( @@ -93,6 +99,7 @@ contract DefaultReserveInterestRateStrategy is IDefaultInterestRateStrategy { OPTIMAL_STABLE_TO_TOTAL_DEBT_RATIO = optimalStableToTotalDebtRatio; MAX_EXCESS_STABLE_TO_TOTAL_DEBT_RATIO = WadRayMath.RAY - optimalStableToTotalDebtRatio; ADDRESSES_PROVIDER = provider; + CORN_STAKING = ICornStakingSilo(cornStaking); _baseVariableBorrowRate = baseVariableBorrowRate; _variableRateSlope1 = variableRateSlope1; _variableRateSlope2 = variableRateSlope2; @@ -170,6 +177,7 @@ contract DefaultReserveInterestRateStrategy is IDefaultInterestRateStrategy { vars.stableToTotalDebtRatio = params.totalStableDebt.rayDiv(vars.totalDebt); vars.availableLiquidity = IERC20(params.reserve).balanceOf(params.aToken) + + _getCornStakingBalance(params.reserve, params.aToken) + params.liquidityAdded - params.liquidityTaken; @@ -253,4 +261,16 @@ contract DefaultReserveInterestRateStrategy is IDefaultInterestRateStrategy { return overallBorrowRate; } + + /** + * @dev Returns the number of assets staked in the corn staking, if the asset is being staked into the corn staking + * else returns 0. + * @param asset The address of the asset + * @param aToken The address of the aToken + * @return The number of assets staked in the corn staking + */ + function _getCornStakingBalance(address asset, address aToken) internal view returns (uint256) { + return CORN_STAKING.sharesOf(aToken, asset); + } + }