Skip to content

Commit

Permalink
feat: Gho UI helper (#180)
Browse files Browse the repository at this point in the history
* feat: GHO Ui helper interface
* feat: GHO Ui helper contract
* feat: add GHO Ui helper deployment task
  • Loading branch information
defispartan authored Feb 2, 2023
1 parent d50f241 commit eb90fa9
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 0 deletions.
30 changes: 30 additions & 0 deletions deploy/09_deploy_uighodataprovider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { HardhatRuntimeEnvironment } from 'hardhat/types';
import { DeployFunction } from 'hardhat-deploy/types';
import { getGhoToken } from '../src/helpers/contract-getters';
import { getPoolAddressesProvider } from '@aave/deploy-v3';

const func: DeployFunction = async function ({
getNamedAccounts,
deployments,
...hre
}: HardhatRuntimeEnvironment) {
const { deploy } = deployments;
const { deployer } = await getNamedAccounts();

const ghoToken = await getGhoToken();
const addressesProvider = await getPoolAddressesProvider();
const pool = await addressesProvider.getPool();

const uiGhoDataProviderResult = await deploy('UiGhoDataProvider', {
from: deployer,
args: [pool, ghoToken.address],
});
console.log(`UiGhoDataProvider: ${uiGhoDataProviderResult.address}`);

return true;
};

func.id = 'UiGhoDataProvider';
func.tags = ['UiGhoDataProvider', 'full_gho_deploy'];

export default func;
73 changes: 73 additions & 0 deletions src/contracts/facilitators/aave/misc/UiGhoDataProvider.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;

import {IERC20} from '@aave/core-v3/contracts/dependencies/openzeppelin/contracts/IERC20.sol';
import {IPool} from '@aave/core-v3/contracts/interfaces/IPool.sol';
import {DataTypes} from '@aave/core-v3/contracts/protocol/libraries/types/DataTypes.sol';
import {IGhoToken} from '../../../gho/interfaces/IGhoToken.sol';
import {GhoDiscountRateStrategy} from '../interestStrategy/GhoDiscountRateStrategy.sol';
import {IGhoVariableDebtToken} from '../tokens/interfaces/IGhoVariableDebtToken.sol';
import {IUiGhoDataProvider} from './interfaces/IUiGhoDataProvider.sol';

/**
* @title UiGhoDataProvider
* @author Aave
* @notice Data provider of GHO token as a reserve within the Aave Protocol
*/
contract UiGhoDataProvider is IUiGhoDataProvider {
IPool public immutable POOL;
IGhoToken public immutable GHO;

/**
* @dev Constructor
* @param pool The address of the Pool contract
* @param ghoToken The address of the GhoToken contract
*/
constructor(IPool pool, IGhoToken ghoToken) {
POOL = pool;
GHO = ghoToken;
}

/// @inheritdoc IUiGhoDataProvider
function getGhoReserveData() public view override returns (GhoReserveData memory) {
DataTypes.ReserveData memory baseData = POOL.getReserveData(address(GHO));
IGhoVariableDebtToken debtToken = IGhoVariableDebtToken(baseData.variableDebtTokenAddress);
GhoDiscountRateStrategy discountRateStrategy = GhoDiscountRateStrategy(
debtToken.getDiscountRateStrategy()
);

(uint256 bucketCapacity, uint256 bucketLevel) = GHO.getFacilitatorBucket(
baseData.aTokenAddress
);

return
GhoReserveData({
ghoBaseVariableBorrowRate: baseData.currentVariableBorrowRate,
ghoDiscountedPerToken: discountRateStrategy.GHO_DISCOUNTED_PER_DISCOUNT_TOKEN(),
ghoDiscountRate: discountRateStrategy.DISCOUNT_RATE(),
ghoDiscountLockPeriod: debtToken.getDiscountLockPeriod(),
ghoMinDebtTokenBalanceForDiscount: discountRateStrategy.MIN_DISCOUNT_TOKEN_BALANCE(),
ghoMinDiscountTokenBalanceForDiscount: discountRateStrategy.MIN_DEBT_TOKEN_BALANCE(),
ghoReserveLastUpdateTimestamp: baseData.lastUpdateTimestamp,
ghoCurrentBorrowIndex: baseData.variableBorrowIndex,
aaveFacilitatorBucketLevel: bucketLevel,
aaveFacilitatorBucketMaxCapacity: bucketCapacity
});
}

/// @inheritdoc IUiGhoDataProvider
function getGhoUserData(address user) public view override returns (GhoUserData memory) {
DataTypes.ReserveData memory baseData = POOL.getReserveData(address(GHO));
IGhoVariableDebtToken debtToken = IGhoVariableDebtToken(baseData.variableDebtTokenAddress);
address discountToken = debtToken.getDiscountToken();

return
GhoUserData({
userGhoDiscountPercent: debtToken.getDiscountPercent(user),
userDiscountTokenBalance: IERC20(discountToken).balanceOf(user),
userPreviousGhoBorrowIndex: debtToken.getPreviousIndex(user),
userGhoScaledBorrowBalance: debtToken.scaledBalanceOf(user),
userDiscountLockPeriodEndTimestamp: debtToken.getUserRebalanceTimestamp(user)
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;

/**
* @title IUiGhoDataProvider
* @author Aave
* @notice Defines the basic interface of the UiGhoDataProvider
*/
interface IUiGhoDataProvider {
struct GhoReserveData {
uint256 ghoBaseVariableBorrowRate;
uint256 ghoDiscountedPerToken;
uint256 ghoDiscountRate;
uint256 ghoDiscountLockPeriod;
uint256 ghoMinDebtTokenBalanceForDiscount;
uint256 ghoMinDiscountTokenBalanceForDiscount;
uint40 ghoReserveLastUpdateTimestamp;
uint128 ghoCurrentBorrowIndex;
uint256 aaveFacilitatorBucketLevel;
uint256 aaveFacilitatorBucketMaxCapacity;
}

struct GhoUserData {
uint256 userGhoDiscountPercent;
uint256 userDiscountTokenBalance;
uint256 userPreviousGhoBorrowIndex;
uint256 userGhoScaledBorrowBalance;
uint256 userDiscountLockPeriodEndTimestamp;
}

/**
* @notice Returns data of the GHO reserve and the Aave Facilitator
* @return An object with information related to the GHO reserve and the Aave Facilitator
*/
function getGhoReserveData() external view returns (GhoReserveData memory);

/**
* @notice Returns data of the user's position on GHO
* @return An object with information related to the user's position with regard to GHO
*/
function getGhoUserData(address user) external view returns (GhoUserData memory);
}

0 comments on commit eb90fa9

Please sign in to comment.