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

Filter markets by known oracles #2100

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
13 changes: 6 additions & 7 deletions app/src/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,14 @@ export const TRADING_FEE_OPTIONS = [
'5.00',
]

export const GRAPH_MAINNET_HTTP =
'https://gateway.thegraph.com/api/47e8db8d0f1b4a6c98b190e04f20dcb1/subgraphs/id/0x0503024fcc5e1bd834530e69d592dbb6e8c03968-0'
export const GRAPH_MAINNET_WS = 'wss://api.thegraph.com/subgraphs/name/protofire/omen'
export const GRAPH_RINKEBY_HTTP = 'https://api.thegraph.com/subgraphs/name/protofire/omen-rinkeby'
export const GRAPH_RINKEBY_WS = 'wss://api.thegraph.com/subgraphs/name/protofire/omen-rinkeby'
export const GRAPH_MAINNET_HTTP = 'https://api.thegraph.com/subgraphs/id/Qmaouym9tSLyb2Fbs2AXjqN3dtxHQ2o3YCredgiLhWLbje'
export const GRAPH_MAINNET_WS = 'wss://api.thegraph.com/subgraphs/id/Qmaouym9tSLyb2Fbs2AXjqN3dtxHQ2o3YCredgiLhWLbje'
export const GRAPH_RINKEBY_HTTP = 'https://api.thegraph.com/subgraphs/id/Qmcxf8mKFFswy5GpbL5AU3Bx9sYSCYkzFbHjPVaNiZPjzy'
export const GRAPH_RINKEBY_WS = 'wss://api.thegraph.com/subgraphs/id/Qmcxf8mKFFswy5GpbL5AU3Bx9sYSCYkzFbHjPVaNiZPjzy'
export const GRAPH_SOKOL_HTTP = 'https://api.thegraph.com/subgraphs/name/protofire/omen-sokol'
export const GRAPH_SOKOL_WS = 'wss://api.thegraph.com/subgraphs/name/protofire/omen-sokol'
export const GRAPH_XDAI_HTTP = 'https://api.thegraph.com/subgraphs/name/protofire/omen-xdai'
export const GRAPH_XDAI_WS = 'wss://api.thegraph.com/subgraphs/name/protofire/omen-xdai'
export const GRAPH_XDAI_HTTP = 'https://api.thegraph.com/subgraphs/name/kadenzipfel/omen-xdai'
export const GRAPH_XDAI_WS = 'wss://api.thegraph.com/subgraphs/name/kadenzipfel/omen-xdai'

export const KLEROS_CURATE_GRAPH_MAINNET_HTTP = 'https://api.thegraph.com/subgraphs/name/kleros/curate'
export const KLEROS_CURATE_GRAPH_MAINNET_WS = 'wss://api.thegraph.com/subgraphs/name/kleros/curate'
Expand Down
1 change: 1 addition & 0 deletions app/src/hooks/market_data/useMarkets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ interface MarketVariables {
fee: string
now: number
knownArbitrators: string[]
knownOracles: string[]
}

type Options = MarketVariables & MarketFilters
Expand Down
6 changes: 5 additions & 1 deletion app/src/pages/market_sections/market_home_container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { MarketHome, myMarketsSortOptions } from '../../components/market/market
import { useConnectedWeb3Context } from '../../contexts'
import { useMarkets } from '../../hooks/market_data/useMarkets'
import { queryCategories } from '../../queries/markets_home'
import { getArbitratorsByNetwork, getOutcomes, networkIds } from '../../util/networks'
import { getArbitratorsByNetwork, getContractAddress, getOutcomes, networkIds } from '../../util/networks'
import { RemoteData } from '../../util/remote_data'
import {
CategoryDataItem,
Expand Down Expand Up @@ -279,6 +279,9 @@ const MarketHomeContainer: React.FC = () => {
const feeBN = ethers.utils.parseEther('' + MAX_MARKET_FEE / Math.pow(10, 2))

const knownArbitrators = getArbitratorsByNetwork(context.networkId).map(x => x.address)
const realitioScalarAdapterAddress = getContractAddress(context.networkId, 'realitioScalarAdapter').toLowerCase()
const oracleAddress = getContractAddress(context.networkId, 'oracle').toLowerCase()
const knownOracles = [oracleAddress, realitioScalarAdapterAddress]
const fetchMyMarkets = filter.state === MarketStates.myMarkets

const marketsQueryVariables = {
Expand All @@ -289,6 +292,7 @@ const MarketHomeContainer: React.FC = () => {
fee: feeBN.toString(),
now: +now,
knownArbitrators,
knownOracles,
...filter,
}

Expand Down
12 changes: 6 additions & 6 deletions app/src/queries/markets_home.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { DEFAULT_OPTIONS, MarketDataFragment, buildQueryMarkets } from './market

const getExpectedQuery = (whereClause: string) => {
return gql`
query GetMarkets($first: Int!, $skip: Int!, $sortBy: String, $sortByDirection: String, $category: String, $title: String, $currency: String, $arbitrator: String, $knownArbitrators: [String!], $templateId: String, $accounts: [String!], $now: Int, $fee: String) {
query GetMarkets($first: Int!, $skip: Int!, $sortBy: String, $sortByDirection: String, $category: String, $title: String, $currency: String, $arbitrator: String, $knownArbitrators: [String!], $knownOracles: [String!], $templateId: String, $accounts: [String!], $now: Int, $fee: String) {
fixedProductMarketMakers(first: $first, skip: $skip, orderBy: $sortBy, orderDirection: $sortByDirection, where: { ${whereClause} }) {
...marketData
}
Expand All @@ -19,7 +19,7 @@ const getExpectedQuery = (whereClause: string) => {
test('Query markets with default options', () => {
const query = buildQueryMarkets(DEFAULT_OPTIONS)
const expectedQuery = getExpectedQuery(
'openingTimestamp_gt: $now, arbitrator_in: $knownArbitrators, templateId_in: ["0", "1", "2", "6"], fee_lte: $fee, timeout_gte: 86400, curatedByDxDaoOrKleros: true',
'openingTimestamp_gt: $now, arbitrator_in: $knownArbitrators, oracle_in: $knownOracles, templateId_in: ["0", "1", "2", "6"], fee_lte: $fee, timeout_gte: 86400, curatedByDxDaoOrKleros: true',
)
expect(query).toBe(expectedQuery)
})
Expand All @@ -31,7 +31,7 @@ test('Query markets', () => {
category: 'SimpleQuestions',
})
const expectedQuery = getExpectedQuery(
'category: $category, arbitrator_in: $knownArbitrators, templateId_in: ["0", "1", "2", "6"], fee_lte: $fee, timeout_gte: 86400, curatedByDxDaoOrKleros: true',
'category: $category, arbitrator_in: $knownArbitrators, oracle_in: $knownOracles, templateId_in: ["0", "1", "2", "6"], fee_lte: $fee, timeout_gte: 86400, curatedByDxDaoOrKleros: true',
)
expect(query).toBe(expectedQuery)
})
Expand All @@ -43,7 +43,7 @@ test('Markets with template_id', () => {
templateId: '2',
})
const expectedQuery = getExpectedQuery(
'arbitrator_in: $knownArbitrators, templateId: $templateId, fee_lte: $fee, timeout_gte: 86400, curatedByDxDaoOrKleros: true',
'arbitrator_in: $knownArbitrators, oracle_in: $knownOracles, templateId: $templateId, fee_lte: $fee, timeout_gte: 86400, curatedByDxDaoOrKleros: true',
)
expect(query).toBe(expectedQuery)
})
Expand All @@ -59,7 +59,7 @@ test('Markets closed with title and arbitrator', () => {
arbitrator: 'arbitratorTest',
})
const expectedQuery = getExpectedQuery(
'answerFinalizedTimestamp_lt: $now, title_contains: $title, arbitrator: $arbitrator, templateId: $templateId, fee_lte: $fee, timeout_gte: 86400, curatedByDxDaoOrKleros: true',
'answerFinalizedTimestamp_lt: $now, title_contains: $title, arbitrator: $arbitrator, oracle_in: $knownOracles, templateId: $templateId, fee_lte: $fee, timeout_gte: 86400, curatedByDxDaoOrKleros: true',
)
expect(query).toBe(expectedQuery)
})
Expand All @@ -71,7 +71,7 @@ test('Query finalizing markets', () => {
category: 'SimpleQuestions',
})
const expectedQuery = getExpectedQuery(
'openingTimestamp_lt: $now, isPendingArbitration: false, answerFinalizedTimestamp_gt: $now, currentAnswer_not: null, category: $category, arbitrator_in: $knownArbitrators, templateId_in: ["0", "1", "2", "6"], fee_lte: $fee, timeout_gte: 86400, curatedByDxDaoOrKleros: true',
'openingTimestamp_lt: $now, isPendingArbitration: false, answerFinalizedTimestamp_gt: $now, currentAnswer_not: null, category: $category, arbitrator_in: $knownArbitrators, oracle_in: $knownOracles, templateId_in: ["0", "1", "2", "6"], fee_lte: $fee, timeout_gte: 86400, curatedByDxDaoOrKleros: true',
)

expect(query).toBe(expectedQuery)
Expand Down
3 changes: 2 additions & 1 deletion app/src/queries/markets_home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export const buildQueryMarkets = (options: BuildQueryType = DEFAULT_OPTIONS) =>
title ? 'title_contains: $title' : '',
currency ? 'collateralToken: $currency' : '',
arbitrator ? 'arbitrator: $arbitrator' : 'arbitrator_in: $knownArbitrators',
'oracle_in: $knownOracles',
templateId ? 'templateId: $templateId' : whitelistedTemplateIds ? 'templateId_in: ["0", "1", "2", "6"]' : '',
'fee_lte: $fee',
`timeout_gte: ${MIN_TIMEOUT}`,
Expand All @@ -125,7 +126,7 @@ export const buildQueryMarkets = (options: BuildQueryType = DEFAULT_OPTIONS) =>
.join(',')

const query = gql`
query GetMarkets($first: Int!, $skip: Int!, $sortBy: String, $sortByDirection: String, $category: String, $title: String, $currency: String, $arbitrator: String, $knownArbitrators: [String!], $templateId: String, $accounts: [String!], $now: Int, $fee: String) {
query GetMarkets($first: Int!, $skip: Int!, $sortBy: String, $sortByDirection: String, $category: String, $title: String, $currency: String, $arbitrator: String, $knownArbitrators: [String!], $knownOracles: [String!], $templateId: String, $accounts: [String!], $now: Int, $fee: String) {
fixedProductMarketMakers(first: $first, skip: $skip, orderBy: $sortBy, orderDirection: $sortByDirection, where: { ${whereClause} }) {
...marketData
}
Expand Down