Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions contracts/interfaces/ICornStakingSilo.sol
Original file line number Diff line number Diff line change
@@ -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);
}
6 changes: 6 additions & 0 deletions contracts/interfaces/IDefaultInterestRateStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 21 additions & 1 deletion contracts/protocol/pool/DefaultReserveInterestRateStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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(
Expand All @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}

}