Skip to content

Commit

Permalink
refactor: remove redundancy from script
Browse files Browse the repository at this point in the history
  • Loading branch information
GitGuru7 committed Sep 21, 2023
1 parent f94e9a6 commit 07fb361
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 68 deletions.
87 changes: 24 additions & 63 deletions deploy/2-configure-feeds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,78 +10,39 @@ const func: DeployFunction = async function ({ network, deployments, getNamedAcc
const { deployer } = await getNamedAccounts();

const resilientOracle = await hre.ethers.getContract("ResilientOracle");
const binanceOracle = await hre.ethers.getContract("BinanceOracle");
const chainlinkOracle = await hre.ethers.getContract("ChainlinkOracle");

const oraclesData: Oracles = await getOraclesData();

for (const asset of assets[networkName]) {
const { oracle } = asset;
console.log(`Configuring ${asset.token}`);

if (network.live) {
console.log(`Configuring ${oracle} oracle for ${asset.token}`);

const { getTokenConfig, getDirectPriceConfig } = oraclesData[oracle];

if (
oraclesData[oracle].underlyingOracle.address === chainlinkOracle.address &&
getDirectPriceConfig !== undefined
) {
const assetConfig: any = getDirectPriceConfig(asset);
const tx = await oraclesData[oracle].underlyingOracle?.setDirectPrice(assetConfig.asset, assetConfig.price);
tx.wait(1);
}

if (oraclesData[oracle].underlyingOracle.address !== binanceOracle.address && getTokenConfig !== undefined) {
const tx = await oraclesData[oracle].underlyingOracle?.setTokenConfig(getTokenConfig(asset, networkName));
tx.wait(1);
}

const { getStalePeriodConfig } = oraclesData[oracle];
if (
oraclesData[oracle].underlyingOracle.address === binanceOracle.address &&
getStalePeriodConfig !== undefined
) {
const tx = await oraclesData[oracle].underlyingOracle?.setTokenConfig(...getStalePeriodConfig(asset));
tx.wait(1);
}

console.log(`Configuring resillient oracle for ${asset.token}`);
const tx = await resilientOracle.setTokenConfig({
asset: asset.address,
oracles: oraclesData[oracle].oracles,
enableFlagsForOracles: oraclesData[oracle].enableFlagsForOracles,
});

await tx.wait(1);
} else {
await deploy(`Mock${asset.token}`, {
from: deployer,
log: true,
deterministicDeployment: false,
args: [`Mock${asset.token}`, `Mock${asset.token}`, 18],
autoMine: true,
contract: "BEP20Harness",
});

const mock = await hre.ethers.getContract(`Mock${asset.token}`);

console.log(`Configuring resillient oracle for ${asset.token}`);
let tx = await resilientOracle.setTokenConfig({
asset: mock.address,
oracles: oraclesData[oracle].oracles,
enableFlagsForOracles: oraclesData[oracle].enableFlagsForOracles,
});

await tx.wait(1);

console.log(`Configuring ${oracle} oracle for ${asset.token}`);
tx = await oraclesData[oracle].underlyingOracle?.setPrice(mock.address, asset.price);
await tx.wait(1);
}
await deploy(`Mock${asset.token}`, {
from: deployer,
log: true,
deterministicDeployment: false,
args: [`Mock${asset.token}`, `Mock${asset.token}`, 18],
autoMine: true,
contract: "BEP20Harness",
});

const mock = await hre.ethers.getContract(`Mock${asset.token}`);

console.log(`Configuring resillient oracle for ${asset.token}`);
let tx = await resilientOracle.setTokenConfig({
asset: mock.address,
oracles: oraclesData[oracle].oracles,
enableFlagsForOracles: oraclesData[oracle].enableFlagsForOracles,
});

await tx.wait(1);

console.log(`Configuring ${oracle} oracle for ${asset.token}`);
tx = await oraclesData[oracle].underlyingOracle?.setPrice(mock.address, asset.price);
await tx.wait(1);
}
};

export default func;
func.tags = ["configure"];
func.skip = async hre => hre.network.live;

Check failure on line 48 in deploy/2-configure-feeds.ts

View workflow job for this annotation

GitHub Actions / Lint

'hre' is already declared in the upper scope on line 1 column 8
9 changes: 4 additions & 5 deletions deploy/3-vip-based-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ const configurePriceFeeds = async (hre: HardhatRuntimeEnvironment): Promise<Gove

for (const asset of assets[networkName]) {
const { oracle } = asset;
console.log(`Configuring ${asset.token}`);

console.log(`Configuring ${oracle} oracle for ${asset.token}`);
console.log(`Adding commands for configuring ${asset.token}`);
console.log(`Adding a command to configure ${oracle} oracle for ${asset.token}`);

const { getTokenConfig, getDirectPriceConfig } = oraclesData[oracle];

Expand Down Expand Up @@ -72,8 +71,8 @@ const configurePriceFeeds = async (hre: HardhatRuntimeEnvironment): Promise<Gove
});
}

console.log(`Configuring resillient oracle for ${asset.token}`);

console.log(``);
console.log(`Adding a command to configure resillient oracle for ${asset.token}`);
commands.push({
contract: resilientOracle.address,
signature: "setTokenConfig((address,address[3],bool[3]))",
Expand Down

0 comments on commit 07fb361

Please sign in to comment.