Skip to content

Commit 0e7bc49

Browse files
kartojalmiguelmtzinf
authored andcommitted
feat: Replace AaveOracle to the latest version. Fix dev deployment scripts.
1 parent d460ab4 commit 0e7bc49

File tree

7 files changed

+23
-162
lines changed

7 files changed

+23
-162
lines changed

contracts/misc/AaveOracle.sol

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,34 @@ import {SafeERC20} from '../dependencies/openzeppelin/contracts/SafeERC20.sol';
1818
contract AaveOracle is IPriceOracleGetter, Ownable {
1919
using SafeERC20 for IERC20;
2020

21-
event WethSet(address indexed weth);
21+
event BaseCurrencySet(address indexed baseCurrency, uint256 baseCurrencyUnit);
2222
event AssetSourceUpdated(address indexed asset, address indexed source);
2323
event FallbackOracleUpdated(address indexed fallbackOracle);
2424

2525
mapping(address => IChainlinkAggregator) private assetsSources;
2626
IPriceOracleGetter private _fallbackOracle;
27-
address public immutable WETH;
27+
address public immutable BASE_CURRENCY;
28+
uint256 public immutable BASE_CURRENCY_UNIT;
2829

2930
/// @notice Constructor
3031
/// @param assets The addresses of the assets
3132
/// @param sources The address of the source of each asset
3233
/// @param fallbackOracle The address of the fallback oracle to use if the data of an
3334
/// aggregator is not consistent
35+
/// @param baseCurrency the base currency used for the price quotes. If USD is used, base currency is 0x0
36+
/// @param baseCurrencyUnit the unit of the base currency
3437
constructor(
3538
address[] memory assets,
3639
address[] memory sources,
3740
address fallbackOracle,
38-
address weth
41+
address baseCurrency,
42+
uint256 baseCurrencyUnit
3943
) public {
4044
_setFallbackOracle(fallbackOracle);
4145
_setAssetsSources(assets, sources);
42-
WETH = weth;
43-
emit WethSet(weth);
46+
BASE_CURRENCY = baseCurrency;
47+
BASE_CURRENCY_UNIT = baseCurrencyUnit;
48+
emit BaseCurrencySet(baseCurrency, baseCurrencyUnit);
4449
}
4550

4651
/// @notice External function called by the Aave governance to set or replace sources of assets
@@ -83,8 +88,8 @@ contract AaveOracle is IPriceOracleGetter, Ownable {
8388
function getAssetPrice(address asset) public view override returns (uint256) {
8489
IChainlinkAggregator source = assetsSources[asset];
8590

86-
if (asset == WETH) {
87-
return 1 ether;
91+
if (asset == BASE_CURRENCY) {
92+
return BASE_CURRENCY_UNIT;
8893
} else if (address(source) == address(0)) {
8994
return _fallbackOracle.getAssetPrice(asset);
9095
} else {

contracts/misc/AaveOracleV2.sol

Lines changed: 0 additions & 125 deletions
This file was deleted.

helpers/contracts-deployments.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ import {
4848
WETH9MockedFactory,
4949
WETHGatewayFactory,
5050
FlashLiquidationAdapterFactory,
51-
AaveOracleV2Factory,
5251
} from '../types';
5352
import {
5453
withSaveAndVerify,
@@ -225,7 +224,7 @@ export const deployMockAggregator = async (price: tStringTokenSmallUnits, verify
225224
);
226225

227226
export const deployAaveOracle = async (
228-
args: [tEthereumAddress[], tEthereumAddress[], tEthereumAddress, tEthereumAddress],
227+
args: [tEthereumAddress[], tEthereumAddress[], tEthereumAddress, tEthereumAddress, string],
229228
verify?: boolean
230229
) =>
231230
withSaveAndVerify(
@@ -235,17 +234,6 @@ export const deployAaveOracle = async (
235234
verify
236235
);
237236

238-
export const deployAaveOracleV2 = async (
239-
args: [tEthereumAddress[], tEthereumAddress[], tEthereumAddress, tEthereumAddress, string],
240-
verify?: boolean
241-
) =>
242-
withSaveAndVerify(
243-
await new AaveOracleV2Factory(await getFirstSigner()).deploy(...args),
244-
eContractid.AaveOracleV2,
245-
args,
246-
verify
247-
);
248-
249237
export const deployLendingPoolCollateralManager = async (verify?: boolean) => {
250238
const collateralManagerImpl = await new LendingPoolCollateralManagerFactory(
251239
await getFirstSigner()

helpers/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ export enum eContractid {
9696
UniswapLiquiditySwapAdapter = 'UniswapLiquiditySwapAdapter',
9797
UniswapRepayAdapter = 'UniswapRepayAdapter',
9898
FlashLiquidationAdapter = 'FlashLiquidationAdapter',
99-
AaveOracleV2 = 'AaveOracleV2',
10099
}
101100

102101
/*

tasks/dev/4_oracles.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { task } from 'hardhat/config';
22
import {
33
deployPriceOracle,
4-
deployAaveOracleV2,
4+
deployAaveOracle,
55
deployLendingRateOracle,
66
} from '../../helpers/contracts-deployments';
77
import {
@@ -12,12 +12,7 @@ import {
1212
import { ICommonConfiguration, iAssetBase, TokenContractId } from '../../helpers/types';
1313
import { waitForTx } from '../../helpers/misc-utils';
1414
import { getAllAggregatorsAddresses, getAllTokenAddresses } from '../../helpers/mock-helpers';
15-
import {
16-
ConfigNames,
17-
loadPoolConfig,
18-
getWethAddress,
19-
getQuoteCurrency,
20-
} from '../../helpers/configuration';
15+
import { ConfigNames, loadPoolConfig, getQuoteCurrency } from '../../helpers/configuration';
2116
import {
2217
getAllMockedTokens,
2318
getLendingPoolAddressesProvider,
@@ -35,6 +30,7 @@ task('dev:deploy-oracles', 'Deploy oracles for dev environment')
3530
ProtocolGlobalParams: { UsdAddress, MockUsdPriceInWei },
3631
LendingRateOracleRatesCommon,
3732
OracleQuoteCurrency,
33+
OracleQuoteUnit,
3834
} = poolConfig as ICommonConfiguration;
3935

4036
const defaultTokenList = {
@@ -64,13 +60,13 @@ task('dev:deploy-oracles', 'Deploy oracles for dev environment')
6460
OracleQuoteCurrency
6561
);
6662

67-
await deployAaveOracleV2(
63+
await deployAaveOracle(
6864
[
6965
tokens,
7066
aggregators,
7167
fallbackOracle.address,
7268
await getQuoteCurrency(poolConfig),
73-
pool.OracleQuoteUnit,
69+
OracleQuoteUnit,
7470
],
7571
verify
7672
);

tasks/full/3_oracles.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import { task } from 'hardhat/config';
22
import { getParamPerNetwork } from '../../helpers/contracts-helpers';
3-
import { deployAaveOracleV2, deployLendingRateOracle } from '../../helpers/contracts-deployments';
3+
import { deployAaveOracle, deployLendingRateOracle } from '../../helpers/contracts-deployments';
44
import { setInitialMarketRatesInRatesOracleByHelper } from '../../helpers/oracles-helpers';
55
import { ICommonConfiguration, eNetwork, SymbolMap } from '../../helpers/types';
66
import { waitForTx, notFalsyOrZeroAddress } from '../../helpers/misc-utils';
77
import {
88
ConfigNames,
99
loadPoolConfig,
10-
getWethAddress,
1110
getGenesisPoolAdmin,
1211
getLendingRateOracles,
1312
getQuoteCurrency,
@@ -18,8 +17,7 @@ import {
1817
getLendingRateOracle,
1918
getPairsTokenAggregator,
2019
} from '../../helpers/contracts-getters';
21-
import { AaveOracle, AaveOracleV2, LendingRateOracle } from '../../types';
22-
import { isAddress } from 'ethers/lib/utils';
20+
import { AaveOracle, LendingRateOracle } from '../../types';
2321

2422
task('full:deploy-oracles', 'Deploy oracles for dev enviroment')
2523
.addFlag('verify', 'Verify contracts at Etherscan')
@@ -54,14 +52,14 @@ task('full:deploy-oracles', 'Deploy oracles for dev enviroment')
5452
poolConfig.OracleQuoteCurrency
5553
);
5654

57-
let aaveOracle: AaveOracle | AaveOracleV2;
55+
let aaveOracle: AaveOracle;
5856
let lendingRateOracle: LendingRateOracle;
5957

6058
if (notFalsyOrZeroAddress(aaveOracleAddress)) {
6159
aaveOracle = await await getAaveOracle(aaveOracleAddress);
6260
await waitForTx(await aaveOracle.setAssetSources(tokens, aggregators));
6361
} else {
64-
aaveOracle = await deployAaveOracleV2(
62+
aaveOracle = await deployAaveOracle(
6563
[
6664
tokens,
6765
aggregators,

tasks/migrations/aave.dev.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ task('aave:dev', 'Deploy development enviroment')
2424
await localBRE.run('dev:deploy-address-provider', { verify });
2525

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

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

0 commit comments

Comments
 (0)