Skip to content

Commit 0bfa35b

Browse files
committed
feat(update-oracle): add task to update the price oracle address for an asset in the Aave V3 protocol
1 parent 513b5c5 commit 0bfa35b

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

tasks/misc/update-AaveOracle.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { task } from "hardhat/config";
2+
import { ethers } from "hardhat";
3+
import dotenv from "dotenv";
4+
dotenv.config();
5+
6+
// Usage:
7+
// npx hardhat update-AaveOracle --network <network> --asset <asset-address> --oracle <oracle-address>
8+
9+
task("update-AaveOracle", "Update the price oracle address for an asset in the Aave V3 protocol")
10+
.addParam("asset", "The address of the asset to update the oracle for")
11+
.addParam("oracle", "The new oracle address for the asset")
12+
.setAction(async ({ asset, oracle }, hre) => {
13+
if (!ethers.utils.isAddress(asset)) {
14+
throw new Error("Invalid asset address provided.");
15+
}
16+
if (!ethers.utils.isAddress(oracle)) {
17+
throw new Error("Invalid oracle address provided.");
18+
}
19+
const [signer] = await hre.ethers.getSigners();
20+
const AAVE_ORACLE_ADDRESS = process.env.AAVE_ORACLE_ADDRESS || "<AAVE_ORACLE_ADDRESS_HERE>";
21+
if (!ethers.utils.isAddress(AAVE_ORACLE_ADDRESS)) {
22+
throw new Error("Invalid AaveOracle address. Set AAVE_ORACLE_ADDRESS in your .env file.");
23+
}
24+
const aaveOracle = await ethers.getContractAt("AaveOracle", AAVE_ORACLE_ADDRESS, signer);
25+
console.log(`Updating oracle for asset: ${asset} to new oracle: ${oracle}`);
26+
const tx = await aaveOracle.setAssetSources([asset], [oracle]);
27+
await tx.wait();
28+
console.log(`Oracle for asset ${asset} successfully updated to ${oracle}.`);
29+
});

0 commit comments

Comments
 (0)