From e24c9ff517e8326d0bdce8494ea355eefc5d69e5 Mon Sep 17 00:00:00 2001 From: Denis Date: Sun, 1 Oct 2023 13:43:09 +0300 Subject: [PATCH 1/3] Fix check-token script --- scripts/check-token.js | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/scripts/check-token.js b/scripts/check-token.js index eca7ec06..eb1856b7 100644 --- a/scripts/check-token.js +++ b/scripts/check-token.js @@ -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(); @@ -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]; + const price = usdPrice(await offchainOracle.getRateToEthWithThreshold(...getRateParams) / 10 ** (18 - decimals)); if (parseFloat(price) !== 0) { console.log(oracles.allOracles[i], 'oracle\'s price =', price); @@ -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 {} } From 7a21a158182ad2ef22748f23a7a57e68877e59b4 Mon Sep 17 00:00:00 2001 From: Denis Date: Sun, 1 Oct 2023 13:48:09 +0300 Subject: [PATCH 2/3] Fix check-tokens-prices script --- scripts/check-tokens-prices.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/scripts/check-tokens-prices.js b/scripts/check-tokens-prices.js index 9cd63097..4b9445fc 100644 --- a/scripts/check-tokens-prices.js +++ b/scripts/check-tokens-prices.js @@ -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(); @@ -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); From ec3258652a47d6e6fb20f46b9bb03f4bae5c24fd Mon Sep 17 00:00:00 2001 From: Denis Date: Tue, 3 Oct 2023 01:04:46 +0300 Subject: [PATCH 3/3] Inline only once used const --- scripts/check-token.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/check-token.js b/scripts/check-token.js index eb1856b7..2fd3dfd2 100644 --- a/scripts/check-token.js +++ b/scripts/check-token.js @@ -42,8 +42,7 @@ async function main () { for (let i = 0; i < oracles.allOracles.length; i++) { await offchainOracle.addOracle(oracles.allOracles[i], oracles.oracleTypes[i]); - const getRateParams = [token, true, thresholdFilter]; - const price = usdPrice(await offchainOracle.getRateToEthWithThreshold(...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);