mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
Fixed total supply, tests
This commit is contained in:
parent
4a1e1156f4
commit
de8ae523c8
|
@ -303,6 +303,7 @@ interface ILendingPool {
|
|||
uint256 currentVariableDebt,
|
||||
uint256 principalStableDebt,
|
||||
uint256 principalVariableDebt,
|
||||
uint256 scaledVariableDebt,
|
||||
uint256 stableBorrowRate,
|
||||
uint256 liquidityRate,
|
||||
uint40 stableRateLastUpdated,
|
||||
|
|
|
@ -619,6 +619,7 @@ contract LendingPool is VersionedInitializable, ILendingPool {
|
|||
uint256 currentVariableDebt,
|
||||
uint256 principalStableDebt,
|
||||
uint256 principalVariableDebt,
|
||||
uint256 scaledVariableDebt,
|
||||
uint256 stableBorrowRate,
|
||||
uint256 liquidityRate,
|
||||
uint40 stableRateLastUpdated,
|
||||
|
@ -630,6 +631,7 @@ contract LendingPool is VersionedInitializable, ILendingPool {
|
|||
currentATokenBalance = IERC20(reserve.aTokenAddress).balanceOf(user);
|
||||
(currentStableDebt, currentVariableDebt) = Helpers.getUserCurrentDebt(user, reserve);
|
||||
(principalStableDebt, principalVariableDebt) = Helpers.getUserPrincipalDebt(user, reserve);
|
||||
scaledVariableDebt = IVariableDebtToken(reserve.variableDebtTokenAddress).scaledBalanceOf(user);
|
||||
liquidityRate = reserve.currentLiquidityRate;
|
||||
stableBorrowRate = IStableDebtToken(reserve.stableDebtTokenAddress).getUserStableRate(user);
|
||||
stableRateLastUpdated = IStableDebtToken(reserve.stableDebtTokenAddress).getUserLastUpdated(
|
||||
|
|
|
@ -39,7 +39,7 @@ contract VariableDebtToken is DebtTokenBase, IVariableDebtToken {
|
|||
* @return the debt balance of the user
|
||||
**/
|
||||
function balanceOf(address user) public virtual override view returns (uint256) {
|
||||
uint256 scaledBalance = principalBalanceOf(user);
|
||||
uint256 scaledBalance = super.principalBalanceOf(user);
|
||||
|
||||
if (scaledBalance == 0) {
|
||||
return 0;
|
||||
|
@ -84,4 +84,16 @@ contract VariableDebtToken is DebtTokenBase, IVariableDebtToken {
|
|||
function principalBalanceOf(address user) public virtual override view returns (uint256) {
|
||||
return super.balanceOf(user).rayMul(_userIndexes[user]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the principal debt balance of the user from
|
||||
* @return The debt balance of the user since the last burn/mint action
|
||||
**/
|
||||
function scaledBalanceOf(address user) public virtual override view returns (uint256) {
|
||||
return super.balanceOf(user);
|
||||
}
|
||||
|
||||
function totalSupply() public virtual override view returns(uint256) {
|
||||
return super.totalSupply().rayMul(POOL.getReserveNormalizedVariableDebt(UNDERLYING_ASSET));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,4 +46,10 @@ interface IVariableDebtToken {
|
|||
**/
|
||||
function burn(address user, uint256 amount) external;
|
||||
|
||||
/**
|
||||
* @dev returns the scaled balance of the variable debt token
|
||||
* @param user the user
|
||||
**/
|
||||
function scaledBalanceOf(address user) external view returns(uint256);
|
||||
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ import BigNumber from 'bignumber.js';
|
|||
import {Ierc20Detailed} from '../types/Ierc20Detailed';
|
||||
import {StableDebtToken} from '../types/StableDebtToken';
|
||||
import {VariableDebtToken} from '../types/VariableDebtToken';
|
||||
import { ZERO_ADDRESS } from './constants';
|
||||
|
||||
export const registerContractInJsonDb = async (contractId: string, contractInstance: Contract) => {
|
||||
const currentNetwork = BRE.network.name;
|
||||
|
@ -277,7 +278,8 @@ export const deployVariableDebtToken = async ([name, symbol, underlyingAsset, po
|
|||
return token;
|
||||
};
|
||||
|
||||
export const deployGenericAToken = async ([poolAddress, underlyingAssetAddress, name, symbol]: [
|
||||
export const deployGenericAToken = async ([poolAddress, underlyingAssetAddress, reserveTreasuryAddress, name, symbol]: [
|
||||
tEthereumAddress,
|
||||
tEthereumAddress,
|
||||
tEthereumAddress,
|
||||
string,
|
||||
|
@ -286,6 +288,7 @@ export const deployGenericAToken = async ([poolAddress, underlyingAssetAddress,
|
|||
const token = await deployContract<AToken>(eContractid.AToken, [
|
||||
poolAddress,
|
||||
underlyingAssetAddress,
|
||||
ZERO_ADDRESS,
|
||||
name,
|
||||
symbol,
|
||||
]);
|
||||
|
|
|
@ -241,6 +241,7 @@ const initReserves = async (
|
|||
const aToken = await deployGenericAToken([
|
||||
lendingPool.address,
|
||||
tokenAddress,
|
||||
ZERO_ADDRESS,
|
||||
`Aave interest bearing ${assetSymbol === 'WETH' ? 'ETH' : assetSymbol}`,
|
||||
`a${assetSymbol === 'WETH' ? 'ETH' : assetSymbol}`,
|
||||
]);
|
||||
|
|
|
@ -1164,13 +1164,10 @@ export const calcExpectedVariableDebtTokenBalance = (
|
|||
) => {
|
||||
const debt = calcExpectedReserveNormalizedDebt(reserveDataBeforeAction, currentTimestamp);
|
||||
|
||||
const { principalVariableDebt, variableBorrowIndex } = userDataBeforeAction;
|
||||
const { scaledVariableDebt } = userDataBeforeAction;
|
||||
|
||||
if (variableBorrowIndex.eq(0)) {
|
||||
return principalVariableDebt;
|
||||
}
|
||||
|
||||
return principalVariableDebt.wadToRay().rayMul(debt).rayDiv(variableBorrowIndex).rayToWad();
|
||||
return scaledVariableDebt.rayMul(debt);
|
||||
};
|
||||
|
||||
export const calcExpectedStableDebtTokenBalance = (
|
||||
|
|
|
@ -90,7 +90,7 @@ export const getUserData = async (
|
|||
currentVariableDebt: new BigNumber(userData.currentVariableDebt.toString()),
|
||||
principalStableDebt: new BigNumber(userData.principalStableDebt.toString()),
|
||||
principalVariableDebt: new BigNumber(userData.principalVariableDebt.toString()),
|
||||
variableBorrowIndex: new BigNumber(userData.variableBorrowIndex.toString()),
|
||||
scaledVariableDebt: new BigNumber(userData.scaledVariableDebt.toString()),
|
||||
stableBorrowRate: new BigNumber(userData.stableBorrowRate.toString()),
|
||||
liquidityRate: new BigNumber(userData.liquidityRate.toString()),
|
||||
usageAsCollateralEnabled: userData.usageAsCollateralEnabled,
|
||||
|
|
|
@ -11,7 +11,7 @@ export interface UserReserveData {
|
|||
currentVariableDebt: BigNumber;
|
||||
principalStableDebt: BigNumber;
|
||||
principalVariableDebt: BigNumber;
|
||||
variableBorrowIndex: BigNumber;
|
||||
scaledVariableDebt: BigNumber;
|
||||
liquidityRate: BigNumber;
|
||||
stableBorrowRate: BigNumber;
|
||||
stableRateLastUpdated: BigNumber;
|
||||
|
|
Loading…
Reference in New Issue
Block a user