mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
refactor: generalized the AaveOracle variables and event names
This commit is contained in:
parent
4b9f282c9c
commit
8297b000fc
|
@ -18,29 +18,34 @@ import {SafeERC20} from '../dependencies/openzeppelin/contracts/SafeERC20.sol';
|
||||||
contract AaveOracle is IPriceOracleGetter, Ownable {
|
contract AaveOracle is IPriceOracleGetter, Ownable {
|
||||||
using SafeERC20 for IERC20;
|
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 AssetSourceUpdated(address indexed asset, address indexed source);
|
||||||
event FallbackOracleUpdated(address indexed fallbackOracle);
|
event FallbackOracleUpdated(address indexed fallbackOracle);
|
||||||
|
|
||||||
mapping(address => IChainlinkAggregator) private assetsSources;
|
mapping(address => IChainlinkAggregator) private assetsSources;
|
||||||
IPriceOracleGetter private _fallbackOracle;
|
IPriceOracleGetter private _fallbackOracle;
|
||||||
address public immutable WETH;
|
address public immutable BASE_CURRENCY;
|
||||||
|
uint256 public immutable BASE_CURRENCY_UNIT;
|
||||||
|
|
||||||
/// @notice Constructor
|
/// @notice Constructor
|
||||||
/// @param assets The addresses of the assets
|
/// @param assets The addresses of the assets
|
||||||
/// @param sources The address of the source of each asset
|
/// @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
|
/// @param fallbackOracle The address of the fallback oracle to use if the data of an
|
||||||
/// aggregator is not consistent
|
/// 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(
|
constructor(
|
||||||
address[] memory assets,
|
address[] memory assets,
|
||||||
address[] memory sources,
|
address[] memory sources,
|
||||||
address fallbackOracle,
|
address fallbackOracle,
|
||||||
address weth
|
address baseCurrency,
|
||||||
|
uint256 baseCurrencyUnit
|
||||||
) public {
|
) public {
|
||||||
_setFallbackOracle(fallbackOracle);
|
_setFallbackOracle(fallbackOracle);
|
||||||
_setAssetsSources(assets, sources);
|
_setAssetsSources(assets, sources);
|
||||||
WETH = weth;
|
BASE_CURRENCY = baseCurrency;
|
||||||
emit WethSet(weth);
|
BASE_CURRENCY_UNIT = baseCurrencyUnit;
|
||||||
|
emit BaseCurrencySet(baseCurrency, baseCurrencyUnit);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @notice External function called by the Aave governance to set or replace sources of assets
|
/// @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) {
|
function getAssetPrice(address asset) public view override returns (uint256) {
|
||||||
IChainlinkAggregator source = assetsSources[asset];
|
IChainlinkAggregator source = assetsSources[asset];
|
||||||
|
|
||||||
if (asset == WETH) {
|
if (asset == BASE_CURRENCY) {
|
||||||
return 1 ether;
|
return BASE_CURRENCY_UNIT;
|
||||||
} else if (address(source) == address(0)) {
|
} else if (address(source) == address(0)) {
|
||||||
return _fallbackOracle.getAssetPrice(asset);
|
return _fallbackOracle.getAssetPrice(asset);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { Contract } from 'ethers';
|
import { BigNumberish, Contract } from 'ethers';
|
||||||
import { DRE } from './misc-utils';
|
import { DRE } from './misc-utils';
|
||||||
import {
|
import {
|
||||||
tEthereumAddress,
|
tEthereumAddress,
|
||||||
|
@ -188,8 +188,8 @@ export const deployAaveLibraries = async (
|
||||||
return {
|
return {
|
||||||
['__$de8c0cf1a7d7c36c802af9a64fb9d86036$__']: validationLogic.address,
|
['__$de8c0cf1a7d7c36c802af9a64fb9d86036$__']: validationLogic.address,
|
||||||
['__$22cd43a9dda9ce44e9b92ba393b88fb9ac$__']: reserveLogic.address,
|
['__$22cd43a9dda9ce44e9b92ba393b88fb9ac$__']: reserveLogic.address,
|
||||||
["__$52a8a86ab43135662ff256bbc95497e8e3$__"]: genericLogic.address,
|
['__$52a8a86ab43135662ff256bbc95497e8e3$__']: genericLogic.address,
|
||||||
}
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const deployLendingPool = async (verify?: boolean) => {
|
export const deployLendingPool = async (verify?: boolean) => {
|
||||||
|
@ -224,7 +224,7 @@ export const deployMockAggregator = async (price: tStringTokenSmallUnits, verify
|
||||||
);
|
);
|
||||||
|
|
||||||
export const deployAaveOracle = async (
|
export const deployAaveOracle = async (
|
||||||
args: [tEthereumAddress[], tEthereumAddress[], tEthereumAddress, tEthereumAddress],
|
args: [tEthereumAddress[], tEthereumAddress[], tEthereumAddress, tEthereumAddress, string],
|
||||||
verify?: boolean
|
verify?: boolean
|
||||||
) =>
|
) =>
|
||||||
withSaveAndVerify(
|
withSaveAndVerify(
|
||||||
|
|
|
@ -18,6 +18,7 @@ import {
|
||||||
getLendingPoolAddressesProvider,
|
getLendingPoolAddressesProvider,
|
||||||
getPairsTokenAggregator,
|
getPairsTokenAggregator,
|
||||||
} from '../../helpers/contracts-getters';
|
} from '../../helpers/contracts-getters';
|
||||||
|
import { ethers } from 'ethers';
|
||||||
|
|
||||||
task('dev:deploy-oracles', 'Deploy oracles for dev enviroment')
|
task('dev:deploy-oracles', 'Deploy oracles for dev enviroment')
|
||||||
.addFlag('verify', 'Verify contracts at Etherscan')
|
.addFlag('verify', 'Verify contracts at Etherscan')
|
||||||
|
@ -58,7 +59,13 @@ task('dev:deploy-oracles', 'Deploy oracles for dev enviroment')
|
||||||
);
|
);
|
||||||
|
|
||||||
await deployAaveOracle(
|
await deployAaveOracle(
|
||||||
[tokens, aggregators, fallbackOracle.address, await getWethAddress(poolConfig)],
|
[
|
||||||
|
tokens,
|
||||||
|
aggregators,
|
||||||
|
fallbackOracle.address,
|
||||||
|
await getWethAddress(poolConfig),
|
||||||
|
ethers.constants.WeiPerEther.toString(),
|
||||||
|
],
|
||||||
verify
|
verify
|
||||||
);
|
);
|
||||||
await waitForTx(await addressesProvider.setPriceOracle(fallbackOracle.address));
|
await waitForTx(await addressesProvider.setPriceOracle(fallbackOracle.address));
|
||||||
|
|
|
@ -18,6 +18,7 @@ import {
|
||||||
getPairsTokenAggregator,
|
getPairsTokenAggregator,
|
||||||
} from '../../helpers/contracts-getters';
|
} from '../../helpers/contracts-getters';
|
||||||
import { AaveOracle, LendingRateOracle } from '../../types';
|
import { AaveOracle, LendingRateOracle } from '../../types';
|
||||||
|
import { ethers } from 'ethers';
|
||||||
|
|
||||||
task('full:deploy-oracles', 'Deploy oracles for dev enviroment')
|
task('full:deploy-oracles', 'Deploy oracles for dev enviroment')
|
||||||
.addFlag('verify', 'Verify contracts at Etherscan')
|
.addFlag('verify', 'Verify contracts at Etherscan')
|
||||||
|
@ -55,7 +56,13 @@ task('full:deploy-oracles', 'Deploy oracles for dev enviroment')
|
||||||
aaveOracle = await await getAaveOracle(aaveOracleAddress);
|
aaveOracle = await await getAaveOracle(aaveOracleAddress);
|
||||||
} else {
|
} else {
|
||||||
aaveOracle = await deployAaveOracle(
|
aaveOracle = await deployAaveOracle(
|
||||||
[tokens, aggregators, fallbackOracleAddress, await getWethAddress(poolConfig)],
|
[
|
||||||
|
tokens,
|
||||||
|
aggregators,
|
||||||
|
fallbackOracleAddress,
|
||||||
|
await getWethAddress(poolConfig),
|
||||||
|
ethers.constants.WeiPerEther.toString(),
|
||||||
|
],
|
||||||
verify
|
verify
|
||||||
);
|
);
|
||||||
await waitForTx(await aaveOracle.setAssetSources(tokens, aggregators));
|
await waitForTx(await aaveOracle.setAssetSources(tokens, aggregators));
|
||||||
|
|
|
@ -30,7 +30,7 @@ import {
|
||||||
authorizeWETHGateway,
|
authorizeWETHGateway,
|
||||||
} from '../../helpers/contracts-deployments';
|
} from '../../helpers/contracts-deployments';
|
||||||
import { eEthereumNetwork } from '../../helpers/types';
|
import { eEthereumNetwork } from '../../helpers/types';
|
||||||
import { Signer } from 'ethers';
|
import { ethers, Signer } from 'ethers';
|
||||||
import { TokenContractId, eContractid, tEthereumAddress, AavePools } from '../../helpers/types';
|
import { TokenContractId, eContractid, tEthereumAddress, AavePools } from '../../helpers/types';
|
||||||
import { MintableERC20 } from '../../types/MintableERC20';
|
import { MintableERC20 } from '../../types/MintableERC20';
|
||||||
import {
|
import {
|
||||||
|
@ -215,7 +215,13 @@ const buildTestEnv = async (deployer: Signer, secondaryWallet: Signer) => {
|
||||||
|
|
||||||
const [tokens, aggregators] = getPairsTokenAggregator(allTokenAddresses, allAggregatorsAddresses);
|
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));
|
await waitForTx(await addressesProvider.setPriceOracle(fallbackOracle.address));
|
||||||
|
|
||||||
const lendingRateOracle = await deployLendingRateOracle();
|
const lendingRateOracle = await deployLendingRateOracle();
|
||||||
|
@ -243,12 +249,8 @@ const buildTestEnv = async (deployer: Signer, secondaryWallet: Signer) => {
|
||||||
|
|
||||||
const config = loadPoolConfig(ConfigNames.Aave);
|
const config = loadPoolConfig(ConfigNames.Aave);
|
||||||
|
|
||||||
const {
|
const { ATokenNamePrefix, StableDebtTokenNamePrefix, VariableDebtTokenNamePrefix, SymbolPrefix } =
|
||||||
ATokenNamePrefix,
|
config;
|
||||||
StableDebtTokenNamePrefix,
|
|
||||||
VariableDebtTokenNamePrefix,
|
|
||||||
SymbolPrefix,
|
|
||||||
} = config;
|
|
||||||
const treasuryAddress = await getTreasuryAddress(config);
|
const treasuryAddress = await getTreasuryAddress(config);
|
||||||
|
|
||||||
await initReservesByHelper(
|
await initReservesByHelper(
|
||||||
|
|
|
@ -29,7 +29,7 @@ import {
|
||||||
deployFlashLiquidationAdapter,
|
deployFlashLiquidationAdapter,
|
||||||
authorizeWETHGateway,
|
authorizeWETHGateway,
|
||||||
} from '../../helpers/contracts-deployments';
|
} from '../../helpers/contracts-deployments';
|
||||||
import { Signer } from 'ethers';
|
import { ethers, Signer } from 'ethers';
|
||||||
import { TokenContractId, eContractid, tEthereumAddress, AavePools } from '../../helpers/types';
|
import { TokenContractId, eContractid, tEthereumAddress, AavePools } from '../../helpers/types';
|
||||||
import { MintableERC20 } from '../../types/MintableERC20';
|
import { MintableERC20 } from '../../types/MintableERC20';
|
||||||
import {
|
import {
|
||||||
|
@ -212,7 +212,7 @@ const buildTestEnv = async (deployer: Signer, secondaryWallet: Signer) => {
|
||||||
|
|
||||||
const [tokens, aggregators] = getPairsTokenAggregator(allTokenAddresses, allAggregatorsAddresses);
|
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));
|
await waitForTx(await addressesProvider.setPriceOracle(fallbackOracle.address));
|
||||||
|
|
||||||
const lendingRateOracle = await deployLendingRateOracle();
|
const lendingRateOracle = await deployLendingRateOracle();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user