Skip to content

Commit

Permalink
feat: Replace AaveOracle to the latest version. Fix dev deployment sc…
Browse files Browse the repository at this point in the history
…ripts.
  • Loading branch information
kartojal authored and miguelmtzinf committed Jul 20, 2021
1 parent d460ab4 commit 0e7bc49
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 162 deletions.
19 changes: 12 additions & 7 deletions contracts/misc/AaveOracle.sol
Expand Up @@ -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);

This comment has been minimized.

Copy link
@DuncanBetts

DuncanBetts Aug 13, 2021

I'm not related to the project; am just trying to help out with code review. These changes seem unrelated, I can see they may be required for compatability with Avalanche but, they look like they're a different feature and should be (in my opinion) in a separate PR.

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
Expand Down Expand Up @@ -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 {
Expand Down
125 changes: 0 additions & 125 deletions contracts/misc/AaveOracleV2.sol

This file was deleted.

14 changes: 1 addition & 13 deletions helpers/contracts-deployments.ts
Expand Up @@ -48,7 +48,6 @@ import {
WETH9MockedFactory,
WETHGatewayFactory,
FlashLiquidationAdapterFactory,
AaveOracleV2Factory,
} from '../types';
import {
withSaveAndVerify,
Expand Down Expand Up @@ -225,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(
Expand All @@ -235,17 +234,6 @@ export const deployAaveOracle = async (
verify
);

export const deployAaveOracleV2 = async (
args: [tEthereumAddress[], tEthereumAddress[], tEthereumAddress, tEthereumAddress, string],
verify?: boolean
) =>
withSaveAndVerify(
await new AaveOracleV2Factory(await getFirstSigner()).deploy(...args),
eContractid.AaveOracleV2,
args,
verify
);

export const deployLendingPoolCollateralManager = async (verify?: boolean) => {
const collateralManagerImpl = await new LendingPoolCollateralManagerFactory(
await getFirstSigner()
Expand Down
1 change: 0 additions & 1 deletion helpers/types.ts
Expand Up @@ -96,7 +96,6 @@ export enum eContractid {
UniswapLiquiditySwapAdapter = 'UniswapLiquiditySwapAdapter',
UniswapRepayAdapter = 'UniswapRepayAdapter',
FlashLiquidationAdapter = 'FlashLiquidationAdapter',
AaveOracleV2 = 'AaveOracleV2',
}

/*
Expand Down
14 changes: 5 additions & 9 deletions tasks/dev/4_oracles.ts
@@ -1,7 +1,7 @@
import { task } from 'hardhat/config';
import {
deployPriceOracle,
deployAaveOracleV2,
deployAaveOracle,
deployLendingRateOracle,
} from '../../helpers/contracts-deployments';
import {
Expand All @@ -12,12 +12,7 @@ import {
import { ICommonConfiguration, iAssetBase, TokenContractId } from '../../helpers/types';
import { waitForTx } from '../../helpers/misc-utils';
import { getAllAggregatorsAddresses, getAllTokenAddresses } from '../../helpers/mock-helpers';
import {
ConfigNames,
loadPoolConfig,
getWethAddress,
getQuoteCurrency,
} from '../../helpers/configuration';
import { ConfigNames, loadPoolConfig, getQuoteCurrency } from '../../helpers/configuration';
import {
getAllMockedTokens,
getLendingPoolAddressesProvider,
Expand All @@ -35,6 +30,7 @@ task('dev:deploy-oracles', 'Deploy oracles for dev environment')
ProtocolGlobalParams: { UsdAddress, MockUsdPriceInWei },
LendingRateOracleRatesCommon,
OracleQuoteCurrency,
OracleQuoteUnit,
} = poolConfig as ICommonConfiguration;

const defaultTokenList = {
Expand Down Expand Up @@ -64,13 +60,13 @@ task('dev:deploy-oracles', 'Deploy oracles for dev environment')
OracleQuoteCurrency
);

await deployAaveOracleV2(
await deployAaveOracle(
[
tokens,
aggregators,
fallbackOracle.address,
await getQuoteCurrency(poolConfig),
pool.OracleQuoteUnit,
OracleQuoteUnit,
],
verify
);
Expand Down
10 changes: 4 additions & 6 deletions tasks/full/3_oracles.ts
@@ -1,13 +1,12 @@
import { task } from 'hardhat/config';
import { getParamPerNetwork } from '../../helpers/contracts-helpers';
import { deployAaveOracleV2, deployLendingRateOracle } from '../../helpers/contracts-deployments';
import { deployAaveOracle, deployLendingRateOracle } from '../../helpers/contracts-deployments';
import { setInitialMarketRatesInRatesOracleByHelper } from '../../helpers/oracles-helpers';
import { ICommonConfiguration, eNetwork, SymbolMap } from '../../helpers/types';
import { waitForTx, notFalsyOrZeroAddress } from '../../helpers/misc-utils';
import {
ConfigNames,
loadPoolConfig,
getWethAddress,
getGenesisPoolAdmin,
getLendingRateOracles,
getQuoteCurrency,
Expand All @@ -18,8 +17,7 @@ import {
getLendingRateOracle,
getPairsTokenAggregator,
} from '../../helpers/contracts-getters';
import { AaveOracle, AaveOracleV2, LendingRateOracle } from '../../types';
import { isAddress } from 'ethers/lib/utils';
import { AaveOracle, LendingRateOracle } from '../../types';

task('full:deploy-oracles', 'Deploy oracles for dev enviroment')
.addFlag('verify', 'Verify contracts at Etherscan')
Expand Down Expand Up @@ -54,14 +52,14 @@ task('full:deploy-oracles', 'Deploy oracles for dev enviroment')
poolConfig.OracleQuoteCurrency
);

let aaveOracle: AaveOracle | AaveOracleV2;
let aaveOracle: AaveOracle;
let lendingRateOracle: LendingRateOracle;

if (notFalsyOrZeroAddress(aaveOracleAddress)) {
aaveOracle = await await getAaveOracle(aaveOracleAddress);
await waitForTx(await aaveOracle.setAssetSources(tokens, aggregators));
} else {
aaveOracle = await deployAaveOracleV2(
aaveOracle = await deployAaveOracle(
[
tokens,
aggregators,
Expand Down
2 changes: 1 addition & 1 deletion tasks/migrations/aave.dev.ts
Expand Up @@ -24,7 +24,7 @@ task('aave:dev', 'Deploy development enviroment')
await localBRE.run('dev:deploy-address-provider', { verify });

console.log('3. Deploy lending pool');
await localBRE.run('dev:deploy-lending-pool', { verify });
await localBRE.run('dev:deploy-lending-pool', { verify, pool: POOL_NAME });

console.log('4. Deploy oracles');
await localBRE.run('dev:deploy-oracles', { verify, pool: POOL_NAME });
Expand Down

0 comments on commit 0e7bc49

Please sign in to comment.