Skip to content
This repository has been archived by the owner on Oct 6, 2023. It is now read-only.

AP-774: Task manage: Update ChainLink price feeds on Registrar #382

Merged
merged 1 commit into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tasks/manage/registrar/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ import "./setVaultOperatorStatus";
import "./transferOwnership";
import "./updateConfig";
import "./updateNetworkConnections";
import "./updateTokenPriceFeed";
72 changes: 72 additions & 0 deletions tasks/manage/registrar/updateTokenPriceFeed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import {task} from "hardhat/config";
import {submitMultiSigTx} from "tasks/helpers";
import {IRegistrar__factory} from "typechain-types";
import {confirmAction, getAPTeamOwner, getAddresses, logger} from "utils";

type TaskArgs = {
token: string;
priceFeed: string;
apTeamSignerPkey?: string;
yes: boolean;
};

task(
"manage:registrar:updateTokenPriceFeed",
"Updates a Registrar-Level Accepted Token's Price Feed contract address in storage."
)
.addParam("token", "Address of the token.")
.addParam("priceFeed", "Address of the token's price feed.")
.addOptionalParam(
"apTeamSignerPkey",
"If running on prod, provide a pkey for a valid APTeam Multisig Owner."
)
.addFlag("yes", "Automatic yes to prompt.")
.setAction(async (taskArgs: TaskArgs, hre) => {
try {
logger.divider();
logger.out(
`Updating price feed of token at address ${taskArgs.token} to: ${taskArgs.priceFeed}...`
);

const addresses = await getAddresses(hre);

// checking current price feed address
const registrar = IRegistrar__factory.connect(addresses.registrar.proxy, hre.ethers.provider);
const curPriceFeed = await registrar.queryTokenPriceFeed(taskArgs.token);
if (curPriceFeed === taskArgs.priceFeed) {
return logger.out("Nothing to change.");
}
logger.out(`Current price feed: ${curPriceFeed}`);

const isConfirmed = taskArgs.yes || (await confirmAction());
if (!isConfirmed) {
return logger.out("Confirmation denied.", logger.Level.Warn);
}

// submitting Tx
const apTeamOwner = await getAPTeamOwner(hre, taskArgs.apTeamSignerPkey);

const data = registrar.interface.encodeFunctionData("updateTokenPriceFeed", [
taskArgs.token,
taskArgs.priceFeed,
]);
const isExecuted = await submitMultiSigTx(
addresses.multiSig.apTeam.proxy,
apTeamOwner,
registrar.address,
data
);

if (isExecuted) {
// verify price feed was correctly updated
const newPriceFeed = await registrar.queryTokenPriceFeed(taskArgs.token);
if (newPriceFeed !== taskArgs.priceFeed) {
throw new Error(
`Error updating price feed: expected '${taskArgs.priceFeed}', actual: '${newPriceFeed}'`
);
}
}
} catch (error) {
logger.out(error, logger.Level.Error);
}
});