refactor: generalized the AaveOracle variables and event names

This commit is contained in:
The3D 2021-07-16 19:26:49 +02:00
parent 4b9f282c9c
commit 8297b000fc
6 changed files with 44 additions and 23 deletions

View File

@ -18,29 +18,34 @@ import {SafeERC20} from '../dependencies/openzeppelin/contracts/SafeERC20.sol';
contract AaveOracle is IPriceOracleGetter, Ownable {
using SafeERC20 for IERC20;
event WethSet(address indexed weth);
event BaseCurrencySet(address indexed baseCurrency, uint256 baseCurrencyUnit);
event AssetSourceUpdated(address indexed asset, address indexed source);
event FallbackOracleUpdated(address indexed fallbackOracle);
mapping(address => IChainlinkAggregator) private assetsSources;
IPriceOracleGetter private _fallbackOracle;
address public immutable WETH;
address public immutable BASE_CURRENCY;
uint256 public immutable BASE_CURRENCY_UNIT;
/// @notice Constructor
/// @param assets The addresses of the assets
/// @param sources The address of the source of each asset
/// @param fallbackOracle The address of the fallback oracle to use if the data of an
/// aggregator is not consistent
/// @param baseCurrency the base currency used for the price quotes. If USD is used, base currency is 0x0
/// @param baseCurrencyUnit the unit of the base currency
constructor(
address[] memory assets,
address[] memory sources,
address fallbackOracle,
address weth
address baseCurrency,
uint256 baseCurrencyUnit
) public {
_setFallbackOracle(fallbackOracle);
_setAssetsSources(assets, sources);
WETH = weth;
emit WethSet(weth);
BASE_CURRENCY = baseCurrency;
BASE_CURRENCY_UNIT = baseCurrencyUnit;
emit BaseCurrencySet(baseCurrency, baseCurrencyUnit);
}
/// @notice External function called by the Aave governance to set or replace sources of assets
@ -83,8 +88,8 @@ contract AaveOracle is IPriceOracleGetter, Ownable {
function getAssetPrice(address asset) public view override returns (uint256) {
IChainlinkAggregator source = assetsSources[asset];
if (asset == WETH) {
return 1 ether;
if (asset == BASE_CURRENCY) {
return BASE_CURRENCY_UNIT;
} else if (address(source) == address(0)) {
return _fallbackOracle.getAssetPrice(asset);
} else {

View File

@ -1,4 +1,4 @@
import { Contract } from 'ethers';
import { BigNumberish, Contract } from 'ethers';
import { DRE } from './misc-utils';
import {
tEthereumAddress,
@ -188,8 +188,8 @@ export const deployAaveLibraries = async (
return {
['__$de8c0cf1a7d7c36c802af9a64fb9d86036$__']: validationLogic.address,
['__$22cd43a9dda9ce44e9b92ba393b88fb9ac$__']: reserveLogic.address,
["__$52a8a86ab43135662ff256bbc95497e8e3$__"]: genericLogic.address,
}
['__$52a8a86ab43135662ff256bbc95497e8e3$__']: genericLogic.address,
};
};
export const deployLendingPool = async (verify?: boolean) => {
@ -224,7 +224,7 @@ export const deployMockAggregator = async (price: tStringTokenSmallUnits, verify
);
export const deployAaveOracle = async (
args: [tEthereumAddress[], tEthereumAddress[], tEthereumAddress, tEthereumAddress],
args: [tEthereumAddress[], tEthereumAddress[], tEthereumAddress, tEthereumAddress, string],
verify?: boolean
) =>
withSaveAndVerify(

View File

@ -18,6 +18,7 @@ import {
getLendingPoolAddressesProvider,
getPairsTokenAggregator,
} from '../../helpers/contracts-getters';
import { ethers } from 'ethers';
task('dev:deploy-oracles', 'Deploy oracles for dev enviroment')
.addFlag('verify', 'Verify contracts at Etherscan')
@ -58,7 +59,13 @@ task('dev:deploy-oracles', 'Deploy oracles for dev enviroment')
);
await deployAaveOracle(
[tokens, aggregators, fallbackOracle.address, await getWethAddress(poolConfig)],
[
tokens,
aggregators,
fallbackOracle.address,
await getWethAddress(poolConfig),
ethers.constants.WeiPerEther.toString(),
],
verify
);
await waitForTx(await addressesProvider.setPriceOracle(fallbackOracle.address));

View File

@ -18,6 +18,7 @@ import {
getPairsTokenAggregator,
} from '../../helpers/contracts-getters';
import { AaveOracle, LendingRateOracle } from '../../types';
import { ethers } from 'ethers';
task('full:deploy-oracles', 'Deploy oracles for dev enviroment')
.addFlag('verify', 'Verify contracts at Etherscan')
@ -55,7 +56,13 @@ task('full:deploy-oracles', 'Deploy oracles for dev enviroment')
aaveOracle = await await getAaveOracle(aaveOracleAddress);
} else {
aaveOracle = await deployAaveOracle(
[tokens, aggregators, fallbackOracleAddress, await getWethAddress(poolConfig)],
[
tokens,
aggregators,
fallbackOracleAddress,
await getWethAddress(poolConfig),
ethers.constants.WeiPerEther.toString(),
],
verify
);
await waitForTx(await aaveOracle.setAssetSources(tokens, aggregators));

View File

@ -30,7 +30,7 @@ import {
authorizeWETHGateway,
} from '../../helpers/contracts-deployments';
import { eEthereumNetwork } from '../../helpers/types';
import { Signer } from 'ethers';
import { ethers, Signer } from 'ethers';
import { TokenContractId, eContractid, tEthereumAddress, AavePools } from '../../helpers/types';
import { MintableERC20 } from '../../types/MintableERC20';
import {
@ -215,7 +215,13 @@ const buildTestEnv = async (deployer: Signer, secondaryWallet: Signer) => {
const [tokens, aggregators] = getPairsTokenAggregator(allTokenAddresses, allAggregatorsAddresses);
await deployAaveOracle([tokens, aggregators, fallbackOracle.address, mockTokens.WETH.address]);
await deployAaveOracle([
tokens,
aggregators,
fallbackOracle.address,
mockTokens.WETH.address,
ethers.constants.WeiPerEther.toString(),
]);
await waitForTx(await addressesProvider.setPriceOracle(fallbackOracle.address));
const lendingRateOracle = await deployLendingRateOracle();
@ -243,12 +249,8 @@ const buildTestEnv = async (deployer: Signer, secondaryWallet: Signer) => {
const config = loadPoolConfig(ConfigNames.Aave);
const {
ATokenNamePrefix,
StableDebtTokenNamePrefix,
VariableDebtTokenNamePrefix,
SymbolPrefix,
} = config;
const { ATokenNamePrefix, StableDebtTokenNamePrefix, VariableDebtTokenNamePrefix, SymbolPrefix } =
config;
const treasuryAddress = await getTreasuryAddress(config);
await initReservesByHelper(

View File

@ -29,7 +29,7 @@ import {
deployFlashLiquidationAdapter,
authorizeWETHGateway,
} from '../../helpers/contracts-deployments';
import { Signer } from 'ethers';
import { ethers, Signer } from 'ethers';
import { TokenContractId, eContractid, tEthereumAddress, AavePools } from '../../helpers/types';
import { MintableERC20 } from '../../types/MintableERC20';
import {
@ -212,7 +212,7 @@ const buildTestEnv = async (deployer: Signer, secondaryWallet: Signer) => {
const [tokens, aggregators] = getPairsTokenAggregator(allTokenAddresses, allAggregatorsAddresses);
await deployAaveOracle([tokens, aggregators, fallbackOracle.address, mockTokens.WETH.address]);
await deployAaveOracle([tokens, aggregators, fallbackOracle.address, mockTokens.WETH.address, ethers.constants.WeiPerEther.toString()]);
await waitForTx(await addressesProvider.setPriceOracle(fallbackOracle.address));
const lendingRateOracle = await deployLendingRateOracle();