Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SC-948] Fix scripts #94

Merged
merged 3 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
19 changes: 4 additions & 15 deletions scripts/check-token.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ async function main () {
const OffchainOracle = await ethers.getContractFactory('OffchainOracle');
const offchainOracleInDeployments = require(`../deployments/${networkName}/OffchainOracle.json`);
const deployedOffchainOracle = OffchainOracle.attach(offchainOracleInDeployments.address);
const isDeployedOracleWithFilter = !!offchainOracleInDeployments.devdoc.methods['getRateToEthWithThreshold(address,bool,uint256)'];

const weth = offchainOracleInDeployments.args[4];
const connectors = await deployedOffchainOracle.connectors();
Expand All @@ -37,24 +36,14 @@ async function main () {
} catch {}

console.log('======================');
const getRateToEthDeployedOracle = isDeployedOracleWithFilter
? () => deployedOffchainOracle.getRateToEthWithThreshold(token, true, thresholdFilter)
: () => deployedOffchainOracle.getRateToEth(token, true);
console.log('Current state\'s price =', usdPrice(await deployedOffchainOracle.getRateToEthWithThreshold(token, true, thresholdFilter) / 10 ** (18 - decimals)));

console.log('Current state\'s price =', usdPrice(await getRateToEthDeployedOracle() / 10 ** (18 - decimals)));

const getRateToEth = isDeployedOracleWithFilter
? offchainOracle.getRateToEthWithThreshold
: offchainOracle.getRateToEth;
const oracles = await deployedOffchainOracle.oracles();
for (let i = 0; i < oracles.allOracles.length; i++) {
await offchainOracle.addOracle(oracles.allOracles[i], oracles.oracleTypes[i]);

const getRateParams = [token, true];
if (isDeployedOracleWithFilter) {
getRateParams.push(thresholdFilter);
}
const price = usdPrice(await getRateToEth(...getRateParams) / 10 ** (18 - decimals));
const getRateParams = [token, true, thresholdFilter];
zZoMROT marked this conversation as resolved.
Show resolved Hide resolved
const price = usdPrice(await offchainOracle.getRateToEthWithThreshold(...getRateParams) / 10 ** (18 - decimals));
if (parseFloat(price) !== 0) {
console.log(oracles.allOracles[i], 'oracle\'s price =', price);

Expand All @@ -68,7 +57,7 @@ async function main () {
else if (tokens.EEE === connectors[j]) symbol = 'EEE';
else symbol = await (await ethers.getContractAt('IERC20Metadata', connectors[j])).symbol();

const { rate, weight } = await oracle.getRate(token, weth, connectors[j]);
const { rate, weight } = await oracle.getRate(token, weth, connectors[j], thresholdFilter);
pricesViaConnector.push({ connector: symbol, rate: parseFloat(usdPrice(rate / 10 ** (18 - decimals))).toFixed(2), weight: weight.toString() });
} catch {}
}
Expand Down
6 changes: 1 addition & 5 deletions scripts/check-tokens-prices.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ async function main () {
const OffchainOracle = await ethers.getContractFactory('OffchainOracle');
const offchainOracleInDeployments = require(`../deployments/${networkName}/OffchainOracle.json`);
const deployedOffchainOracle = OffchainOracle.attach(offchainOracleInDeployments.address);
const isDeployedOracleWithFilter = !!offchainOracleInDeployments.devdoc.methods['getRateToEthWithThreshold(address,bool,uint256)'];

const weth = offchainOracleInDeployments.args[4];
const connectors = await deployedOffchainOracle.connectors();
Expand Down Expand Up @@ -68,10 +67,7 @@ async function main () {
} catch {}

clearAndPrint(`Progress: ${i} / ${tokenlist.length}`);
const getRateToEthDeployedOracle = isDeployedOracleWithFilter
? () => deployedOffchainOracle.getRateToEthWithThreshold(token.address, true, thresholdFilter)
: () => deployedOffchainOracle.getRateToEth(token.address, true);
const deployedOraclePrice = await getRateToEthDeployedOracle();
const deployedOraclePrice = await deployedOffchainOracle.getRateToEthWithThreshold(token.address, true, thresholdFilter);
const currentImplPrice = await offchainOracle.getRateToEthWithThreshold(token.address, true, thresholdFilter);

const currentImplPriceUsd = parseFloat(usdPrice(currentImplPrice / 10 ** (18 - tokenDecimals))).toFixed(2);
Expand Down
Loading