From 9bf35b95f3019269bba44b9dd93835814822be1b Mon Sep 17 00:00:00 2001 From: Anton Cheng Date: Wed, 30 Jun 2021 11:54:34 +0800 Subject: [PATCH] fix: getPrices fetching from wrong subgraph --- scripts/dataUtils.js | 15 ++++++++++----- scripts/migrateOracle.js | 23 +++++++++++------------ 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/scripts/dataUtils.js b/scripts/dataUtils.js index 4d20417e8..c704e1868 100644 --- a/scripts/dataUtils.js +++ b/scripts/dataUtils.js @@ -22,6 +22,7 @@ const getSubgraphUrl = (network, internal) => { if (network === 'mainnet' && internal) { url = 'https://api.thegraph.com/subgraphs/name/opynfinance/playground' } + console.log(`Using subgraph endpoint`, url) return url } @@ -55,7 +56,6 @@ module.exports.getOTokens = async (network, internal) => { }` try { const url = getSubgraphUrl(network, internal) - console.log(`Requesting subgraph`, url) const response = await postQuery(url, query) return response.data.otokens } catch (error) { @@ -70,13 +70,17 @@ module.exports.getOTokens = async (network, internal) => { module.exports.getAllSettlementPrices = async (asset, network, internal) => { const query = ` { - expiryPrices (where:{ - asset: "${asset}" - }, first:1000) { + expiryPrices( + first: 1000, + where: { + asset: "${asset}" + } + ){ expiry price } } + ` try { const url = getSubgraphUrl(network, internal) @@ -84,7 +88,8 @@ module.exports.getAllSettlementPrices = async (asset, network, internal) => { return response.data.expiryPrices } catch (error) { console.error(error) - return [] + throw 'WTF' + return null } } diff --git a/scripts/migrateOracle.js b/scripts/migrateOracle.js index 41ad18615..2c65f76fe 100644 --- a/scripts/migrateOracle.js +++ b/scripts/migrateOracle.js @@ -32,28 +32,21 @@ module.exports = async function(callback) { const asset = options.asset.toLowerCase() - // const factory = await OtokenFactory.at(options.factory) - // const oldOracle = await Oracle.at(options.oldOracle) const newOracle = await Oracle.at(options.newOracle) console.log(`Getting list of create Otokens with asset ${asset} 🍕`) - // const expiriesToMigrate = [] - // const pricesToMigrate = [] - const otokens = await apis.getOTokens(options.network, options.internal === 'true') console.log(`# of otokens from subgraph: ${otokens.length}`) - const prices = await apis.getAllSettlementPrices(asset, options.network, options.internal) + const prices = await apis.getAllSettlementPrices(asset, options.network, options.internal === 'true') const oTokensWithAsset = otokens.filter( otoken => otoken.underlyingAsset.id === asset || otoken.collateralAsset.id === asset || otoken.strikeAsset.id === asset, ) - console.log(`oTokensWithAsset`, oTokensWithAsset.length) - const filteredExpiries = oTokensWithAsset.reduce((prev, curr) => { if (!prev.includes(curr.expiryTimestamp)) { return [...prev, curr.expiryTimestamp] @@ -72,11 +65,11 @@ module.exports = async function(callback) { let finalPrices = [] let finalExpires = [] - if (options.coinId) { - const missingExpires = filteredExpiries.filter( - expiry => !knownRecordSubgraph.map(obj => obj.expiry).includes(expiry), - ) + const missingExpires = filteredExpiries.filter( + expiry => !knownRecordSubgraph.map(obj => obj.expiry).includes(expiry), + ) + if (options.coinId) { console.log(`Using coinID ${options.coinId} to fill in ${missingExpires.length} missing prices! `) const missingPrices = [] @@ -89,6 +82,12 @@ module.exports = async function(callback) { finalPrices = [...knownPrices, ...missingPrices] finalExpires = [...knownExpires, ...missingExpires] } else { + if (missingExpires.length > 0) { + console.log( + `Missing ${missingExpires.length} prices to support redeeming all options. Please put in coinId to fetch those `, + ) + } + finalPrices = knownPrices finalExpires = knownExpires }