Skip to content

Commit

Permalink
Merge pull request #94 from 1inch/feature/patch-scripts
Browse files Browse the repository at this point in the history
[SC-948] Fix scripts
  • Loading branch information
zZoMROT authored Oct 3, 2023
2 parents 7287794 + ec32586 commit 94cfae8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 20 deletions.
18 changes: 3 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,13 @@ 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 price = usdPrice(await offchainOracle.getRateToEthWithThreshold(token, true, thresholdFilter) / 10 ** (18 - decimals));
if (parseFloat(price) !== 0) {
console.log(oracles.allOracles[i], 'oracle\'s price =', price);

Expand All @@ -68,7 +56,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

0 comments on commit 94cfae8

Please sign in to comment.