Skip to content

Commit

Permalink
fix: getPrices fetching from wrong subgraph
Browse files Browse the repository at this point in the history
  • Loading branch information
antoncoding committed Jun 30, 2021
1 parent bebd2fb commit ae1f16a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
15 changes: 10 additions & 5 deletions scripts/dataUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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) {
Expand All @@ -70,21 +70,26 @@ 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)
const response = await postQuery(url, query)
return response.data.expiryPrices
} catch (error) {
console.error(error)
return []
throw 'WTF'
return null
}
}

Expand Down
23 changes: 11 additions & 12 deletions scripts/migrateOracle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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 = []
Expand All @@ -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
}
Expand Down

0 comments on commit ae1f16a

Please sign in to comment.