The Graph exposes a GraphQL endpoint to query the events and entities within the Thales protocol.
Thales has multiple subgraphs generated from this repository.
- Optimism: https://thegraph.com/legacy-explorer/subgraph/thales-markets/thales-token
- Arbitrum: https://thegraph.com/hosted-service/subgraph/thales-markets/thales-token-arbitrum
- Optimism-Goerli: https://thegraph.com/hosted-service/subgraph/thales-markets/token-goerli
- TokenTransaction
- Staker
- CanClaimOnBehalfItem
- Optimism: https://thegraph.com/hosted-service/subgraph/thales-markets/thales-markets
- Arbitrum: https://thegraph.com/hosted-service/subgraph/thales-markets/thales-arbitrum
- Polygon: https://thegraph.com/hosted-service/subgraph/thales-markets/thales-polygon
- BNBChain: https://thegraph.com/hosted-service/subgraph/thales-markets/thales-bsc
- Optimism-Goerli: https://thegraph.com/hosted-service/subgraph/thales-markets/thales-markets-goerli-ovm
- Market
- RangedMarket
- OptionTransaction
- Trade
- AccountBuyVolume
- ReferralTransfer
- Referrer
- ReferredTrader
- Position
- PositionBalance
- RangedPosition
- RangedPositionBalance
- LiquidityPool
- LiquidityPoolPnl
- LiquidityPoolUserTransaction
- Vault
- VaultPnl
- VaultTransactions
- VaultUserTransactions
- Optimism: https://thegraph.com/hosted-service/subgraph/thales-markets/sport-markets-optimism
- Arbitrum: https://thegraph.com/hosted-service/subgraph/thales-markets/overtime-arbitrum
- Optimism-Goerli: https://thegraph.com/hosted-service/subgraph/thales-markets/sport-markets-optimism-goerli
- SportMarket
- MarketTransaction
- ClaimTx
- BuyTransaction
- Position
- PositionBalance
- ParlayMarket
- GameIdToParentMarket
- ParentMarketToDoubleChanceMarket
- LiquidityPool
- LiquidityPoolPnl
- LiquidityPoolUserTransaction
- OvertimeVoucher
- Vault
- VaultPnl
- VaultTransactions
- VaultUserTransactions
- ParlayVaultTransaction
- Referrer
- ReferredTrader
- ReferralTransaction
- User
- Zebro
For any of the supported networks (Optimism, Arbitrum, Polygon, BNBChain, Optimism-Goerli):
- Run the
npm run codegen:[subgraph]task to prepare the TypeScript sources for the GraphQL (generated/schema) and the ABIs (generated/[ABI]/*). Note:subgraphparameter can be found in thepackage.jsonfile. - [Optional] run the
npm run build:[subgraph]task for the subgraph - Deploy via
npm run deploy:[subgraph]. Note: requires env variable of$THEGRAPH_THALES_ACCESS_TOKENset in bash to work.
Please use our node & browser utility: thales-data.
In it's simplest version (on a modern browser assuming async await support and fetch):
// Fetch all markets in the last 24 hours
(async () => {
const ts = Math.floor(Date.now() / 1e3);
const oneDayAgo = ts - 3600 * 24;
const body = JSON.stringify({
query: `{
markets(
orderBy:timestamp,
orderDirection:desc,
where:{timestamp_gt: ${oneDayAgo}}
)
{
id
timestamp
creator
currencyKey
strikePrice
maturityDate
expiryDate
isOpen
poolSize
longAddress
shortAddress
result
customMarket
customOracle
}
}`,
variables: null,
});
const response = await fetch('https://api.thegraph.com/subgraphs/name/thales-markets/thales-markets', {
method: 'POST',
body,
});
const json = await response.json();
const { markets } = json.data;
// ...
console.log(markets);
})();Note: due to The Graph limitation, only
1000results will be returned (the maximum allowedfirstamount). The way around this is to use paging (using theskipoperator in GraphQL). See the functionpageResultsin thales-data for an example.