Skip to content

Commit

Permalink
Support new subquid version
Browse files Browse the repository at this point in the history
  • Loading branch information
Robiquet committed Jan 12, 2024
1 parent 23827a7 commit 1bce02d
Show file tree
Hide file tree
Showing 14 changed files with 66 additions and 110 deletions.
2 changes: 1 addition & 1 deletion components/markets/MarketsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const MarketsList = ({ className = "" }: MarketsListProps) => {
/>
<div className="grid grid-cols-1 gap-7 md:grid-cols-2 lg:grid-cols-3">
{markets?.map((market) => {
const volume = market.pool?.volume ?? market.neoPool?.volume ?? 0;
const volume = market.volume;
const scalarType = market.scalarType as ScalarRangeType;
const stat = stats?.find((s) => s.marketId === market.marketId);
const question = market.question ?? "";
Expand Down
4 changes: 1 addition & 3 deletions components/markets/SimilarMarketsSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ export const SimilarMarketsSection = ({
neoPool={market?.neoPool}
status={market.status}
baseAsset={market.baseAsset}
volume={new Decimal(market.pool?.volume ?? 0)
.div(ZTG)
.toNumber()}
volume={new Decimal(market.volume ?? 0).div(ZTG).toNumber()}
tags={
market.tags?.filter((tag): tag is string => tag !== null) ??
[]
Expand Down
2 changes: 1 addition & 1 deletion components/markets/market-card/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export interface IndexedMarketCardData {
scalarType: ScalarRangeType | null;
prediction: { name: string; price: number };
volume: number;
pool?: { poolId?: number; volume: string } | null;
pool?: { poolId?: number } | null;
neoPool?: FullMarketFragment["neoPool"] | null;
baseAsset: string;
tags?: string[];
Expand Down
2 changes: 1 addition & 1 deletion lib/gql/featured-markets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const getFeaturedMarkets = async (
creator: market.creator,
img: market.img ?? "",
prediction: prediction,
volume: new Decimal(market.pool?.volume ?? 0).div(ZTG).toNumber(),
volume: new Decimal(market.volume ?? 0).div(ZTG).toNumber(),
baseAsset: market.baseAsset,
outcomes: marketCategories,
pool: market.pool,
Expand Down
45 changes: 11 additions & 34 deletions lib/gql/get-network-stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,24 @@ import { parseAssetIdString } from "lib/util/parse-asset-id";
import { getBaseAssetHistoricalPrices, lookupPrice } from "./historical-prices";
import {
PoolOrderByInput,
MarketOrderByInput,
NeoPoolOrderByInput,
HistoricalSwapOrderByInput,
} from "@zeitgeistpm/indexer";
import { MarketsOrderBy } from "lib/types/market-filter";

export const getNetworkStats = async (sdk: Sdk<FullContext>) => {
const [marketCountBN, basePrices, pools, neoPools, historicalSwaps] =
const [marketCountBN, basePrices, markets, historicalSwaps] =
await Promise.all([
sdk.api.query.marketCommons.marketCounter(),
getBaseAssetHistoricalPrices(),
fetchAllPages(async (pageNumber, limit) => {
const { pools } = await sdk.indexer.pools({
const { markets } = await sdk.indexer.markets({
limit: limit,
offset: pageNumber * limit,
order: PoolOrderByInput.IdAsc,
order: MarketOrderByInput.IdAsc,
});
return pools;
}),
fetchAllPages(async (pageNumber, limit) => {
const { neoPools } = await sdk.indexer.neoPools({
limit: limit,
offset: pageNumber * limit,
order: NeoPoolOrderByInput.IdAsc,
});
return neoPools;
return markets;
}),
fetchAllPages(async (pageNumber, limit) => {
const { historicalSwaps } = await sdk.indexer.historicalSwaps({
Expand All @@ -40,28 +34,14 @@ export const getNetworkStats = async (sdk: Sdk<FullContext>) => {
}),
]);

const totalPoolVolumeUsd = pools.reduce<Decimal>((total, pool) => {
const poolCreationBaseAssetPrice = lookupPrice(
basePrices,
parseAssetIdString(pool.baseAsset) as BaseAssetId,
new Date(pool.createdAt).getTime(),
);

const volumeUsd = new Decimal(pool.volume).mul(
poolCreationBaseAssetPrice ?? 0,
);

return total.plus(volumeUsd);
}, new Decimal(0));

const totalNeopoolVolumeUsd = pools.reduce<Decimal>((total, pool) => {
const totalMarketVolumeUsd = markets.reduce<Decimal>((total, market) => {
const poolCreationBaseAssetPrice = lookupPrice(
basePrices,
parseAssetIdString(pool.baseAsset) as BaseAssetId,
new Date(pool.createdAt).getTime(),
parseAssetIdString(market.baseAsset) as BaseAssetId,
new Date(market.pool?.createdAt ?? market.neoPool?.createdAt).getTime(),
);

const volumeUsd = new Decimal(pool.volume).mul(
const volumeUsd = new Decimal(market.volume).mul(
poolCreationBaseAssetPrice ?? 0,
);

Expand All @@ -76,9 +56,6 @@ export const getNetworkStats = async (sdk: Sdk<FullContext>) => {
return {
marketCount: marketCountBN.toNumber(),
tradersCount,
volumeUsd: totalNeopoolVolumeUsd
.plus(totalPoolVolumeUsd)
.div(ZTG)
.toNumber(),
volumeUsd: totalMarketVolumeUsd.div(ZTG).toNumber(),
};
};
4 changes: 1 addition & 3 deletions lib/gql/trending-markets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,7 @@ const getTrendingMarkets = async (
img: market.img ?? "",
prediction: prediction,
creator: market.creator,
volume: Number(
new Decimal(market.neoPool?.volume ?? 0).div(ZTG).toFixed(0),
),
volume: Number(new Decimal(market?.volume ?? 0).div(ZTG).toFixed(0)),
baseAsset: market.baseAsset,
outcomes: marketCategories,
pool: market.pool ?? null,
Expand Down
4 changes: 2 additions & 2 deletions lib/hooks/queries/useInfiniteMarkets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export const rootKey = "markets-filtered";
const orderByMap = {
[MarketsOrderBy.Newest]: MarketOrderByInput.MarketIdDesc,
[MarketsOrderBy.Oldest]: MarketOrderByInput.MarketIdAsc,
[MarketsOrderBy.MostVolume]: "volume_DESC",
[MarketsOrderBy.LeastVolume]: MarketOrderByInput.PoolVolumeAsc,
[MarketsOrderBy.MostVolume]: MarketOrderByInput.VolumeDesc,
[MarketsOrderBy.LeastVolume]: MarketOrderByInput.VolumeAsc,
};

const validMarketWhereInput: MarketWhereInput = {
Expand Down
4 changes: 2 additions & 2 deletions lib/hooks/queries/useMarketSpotPrices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ const calcMarketPrices = (
const outcomeWeights = market.pool.weights.filter(
(weight) =>
weight.assetId.toLocaleLowerCase() !==
market.pool?.baseAsset.toLocaleLowerCase(),
market.baseAsset.toLocaleLowerCase(),
);

//base weight is equal to the sum of all other assets
const baseWeight = new Decimal(market.pool.totalWeight).div(2);
const baseWeight = new Decimal(market?.pool.totalWeight ?? 0).div(2);

outcomeWeights.forEach((weight, index) => {
const spotPrice = calcSpotPrice(
Expand Down
2 changes: 1 addition & 1 deletion lib/hooks/queries/usePortfolioPositions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ export const usePortfolioPositions = (
): null | Decimal => {
const poolZtgBalance = poolsZtgBalances[pool.poolId]?.toNumber();

const ztgWeight = new Decimal(pool.totalWeight).div(2);
const ztgWeight = new Decimal(pool.totalWeight ?? 0).div(2);
const assetWeight = getAssetWeight(pool, assetId).unwrap();

const poolAssetBalance = poolAssetBalances?.get(
Expand Down
12 changes: 4 additions & 8 deletions lib/hooks/queries/useRecommendedMarkets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,12 @@ export const useRecommendedMarkets = (marketId?: number, limit = 2) => {
if (enabled) {
const { markets: similarMarkets } = await sdk.indexer.markets({
limit,
order: [MarketOrderByInput.PoolVolumeDesc],
order: [MarketOrderByInput.VolumeDesc],
where: {
tags_containsAny: market?.tags,
status_eq: MarketStatus.Active,
marketId_not_eq: marketId,
pool: {
volume_gt: "0",
},
volume_gt: "0",
},
});

Expand All @@ -45,13 +43,11 @@ export const useRecommendedMarkets = (marketId?: number, limit = 2) => {
} else {
const { markets: popularMarkets } = await sdk.indexer.markets({
limit,
order: [MarketOrderByInput.PoolVolumeDesc],
order: [MarketOrderByInput.VolumeDesc],
where: {
status_eq: MarketStatus.Active,
marketId_not_eq: marketId,
pool: {
volume_gt: "0",
},
volume_gt: "0",
},
});
return {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"@zeitgeistpm/avatara-nft-sdk": "^1.3.1",
"@zeitgeistpm/avatara-react": "^1.3.2",
"@zeitgeistpm/avatara-util": "^1.2.0",
"@zeitgeistpm/sdk": "2.49.1",
"@zeitgeistpm/sdk": "2.51.0",
"@zeitgeistpm/utility": "^2.24.1",
"axios": "^0.21.4",
"boring-avatars": "^1.6.1",
Expand Down
4 changes: 1 addition & 3 deletions pages/api/og/[marketId].ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ export default async function (
prediction = getCurrentPrediction(market.assets as any, market);
}

const volume = new Decimal(market.pool?.volume ?? market.neoPool?.volume ?? 0)
.div(ZTG)
.toFixed(2);
const volume = new Decimal(market?.volume ?? 0).div(ZTG).toFixed(2);

const ends = moment(Number(market.period.end)).format("MMM Do, YYYY");

Expand Down
4 changes: 2 additions & 2 deletions pages/liquidity/[poolid].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ const PoolDetails: NextPage = () => {
const { data: pool, isInitialLoading, isFetched } = usePool({ poolId });
const { data: market } = useMarket({ poolId });

const baseAssetId = parseAssetIdString(pool?.baseAsset);
const baseAssetId = parseAssetIdString(market?.baseAsset);
const { data: metadata } = useAssetMetadata(baseAssetId);
const { data: liquidity } = usePoolLiquidity({ poolId });

const volume = isIndexedData(pool)
? new Decimal(pool.volume).div(ZTG).toFixed(2)
? new Decimal(market?.volume ?? 0).div(ZTG).toFixed(2)
: null;

const swapFee = Number(pool?.swapFee);
Expand Down
85 changes: 37 additions & 48 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4179,25 +4179,14 @@ __metadata:
languageName: node
linkType: hard

"@zeitgeistpm/augment-api@npm:^2.21.0":
version: 2.22.0
resolution: "@zeitgeistpm/augment-api@npm:2.22.0"
"@zeitgeistpm/augment-api@npm:^2.26.0":
version: 2.26.0
resolution: "@zeitgeistpm/augment-api@npm:2.26.0"
peerDependencies:
"@polkadot/api-base": "*"
"@polkadot/rpc-core": "*"
"@polkadot/types": "*"
checksum: 7976146bf19c72a3b92dd01eeecf6dd8513ba0769ad68e602c78f9568f9744aeb04ad00b658e9357206cd101c465f04e32356f61b1485784de91991f73a6f341
languageName: node
linkType: hard

"@zeitgeistpm/augment-api@npm:^2.25.1":
version: 2.25.1
resolution: "@zeitgeistpm/augment-api@npm:2.25.1"
peerDependencies:
"@polkadot/api-base": "*"
"@polkadot/rpc-core": "*"
"@polkadot/types": "*"
checksum: 57dd122445ce623e02bf4cc3ee91968d88711d35952d9295c5be4d7b0e4181fd643ebd13ec3a3548649ef172bb7634276043dd45325fe83a798b27b555643f93
checksum: e18fa3394246ec2d877dc91df532af03896ea85dd136741bf987c6e8a37ce664a67a1012e211394a01bfc452a520e9c48deb64aee7a1ae9a9e9745c4c7b580e1
languageName: node
linkType: hard

Expand Down Expand Up @@ -4267,40 +4256,40 @@ __metadata:
languageName: node
linkType: hard

"@zeitgeistpm/indexer@npm:^3.20.1":
version: 3.20.1
resolution: "@zeitgeistpm/indexer@npm:3.20.1"
"@zeitgeistpm/indexer@npm:^3.22.0":
version: 3.22.0
resolution: "@zeitgeistpm/indexer@npm:3.22.0"
dependencies:
graphql: ^16.6.0
graphql-request: ^5.0.0
graphql-tag: ^2.12.6
checksum: 4d8fa03c08eb154abdbed0e62e7ae4e2de6ae09677f6a2cf318a2c74a039e48fd5eaac5f26feefd3adfe5278a92e3481ddbc9cc9261cf4ece53f2f39dceb0f77
checksum: cf66a5a00343d8a76cb9a6745e41efc457ab1da6e3a3cec8a0e2a68edc8bee2cee2e0dcd36fc68dcaa22bf7d6671f8375822ebff8ff5b613cf9142b23cabe9e1
languageName: node
linkType: hard

"@zeitgeistpm/rpc@npm:^2.14.0":
version: 2.14.0
resolution: "@zeitgeistpm/rpc@npm:2.14.0"
"@zeitgeistpm/rpc@npm:^2.15.0":
version: 2.15.0
resolution: "@zeitgeistpm/rpc@npm:2.15.0"
dependencies:
"@zeitgeistpm/augment-api": ^2.21.0
"@zeitgeistpm/utility": ^2.24.0
"@zeitgeistpm/augment-api": ^2.26.0
"@zeitgeistpm/utility": ^2.25.0
peerDependencies:
"@polkadot/api": "*"
"@polkadot/keyring": "*"
"@polkadot/types": "*"
checksum: 3bb452b262e16f9169070889d298e1148564965b20a8ebbaccc35a2b14efb76f90f38ef6c1e822b1f9e3d82ab6c4f0ae4cad290458cd8be28b6a2b18932f3f6a
checksum: 2ffe91ca3101d688aa5da2e4dccf31b6c87dfc1c6994c7a8b9ae6a1c64cc274db65273f544ff32441f9801b431af2f499f02482a18669cbc0572a2f1b893144e
languageName: node
linkType: hard

"@zeitgeistpm/sdk@npm:2.49.1":
version: 2.49.1
resolution: "@zeitgeistpm/sdk@npm:2.49.1"
"@zeitgeistpm/sdk@npm:2.51.0":
version: 2.51.0
resolution: "@zeitgeistpm/sdk@npm:2.51.0"
dependencies:
"@zeitgeistpm/augment-api": ^2.25.1
"@zeitgeistpm/indexer": ^3.20.1
"@zeitgeistpm/rpc": ^2.14.0
"@zeitgeistpm/utility": ^2.24.1
"@zeitgeistpm/web3.storage": ^2.15.0
"@zeitgeistpm/augment-api": ^2.26.0
"@zeitgeistpm/indexer": ^3.22.0
"@zeitgeistpm/rpc": ^2.15.0
"@zeitgeistpm/utility": ^2.25.0
"@zeitgeistpm/web3.storage": ^2.16.0
cids: ^1.1.9
decimal.js: ^10.4.3
human-object-diff: ^3.0.0
Expand All @@ -4314,7 +4303,7 @@ __metadata:
"@polkadot/api": "*"
"@polkadot/types": "*"
"@polkadot/util": "*"
checksum: b0b6059c3bc8a018ecb148f91b54641f522aa74448468337562d6507340a2cd70df3594514f9edde367c27f8f2aa4cec6136679f5660f89fd7b7d3d09f5e83e1
checksum: d24e1e394d4af2b93382c76bd5ee04bb9e9258be93e4ded55eeae9ec48709eafff91960b15aa5f9c670ad9ceda02d9095aa882c08b9877a908e989c82f890017
languageName: node
linkType: hard

Expand Down Expand Up @@ -4376,7 +4365,7 @@ __metadata:
"@zeitgeistpm/avatara-nft-sdk": ^1.3.1
"@zeitgeistpm/avatara-react": ^1.3.2
"@zeitgeistpm/avatara-util": ^1.2.0
"@zeitgeistpm/sdk": 2.49.1
"@zeitgeistpm/sdk": 2.51.0
"@zeitgeistpm/utility": ^2.24.1
autoprefixer: 10.2.5
axios: ^0.21.4
Expand Down Expand Up @@ -4446,9 +4435,9 @@ __metadata:
languageName: unknown
linkType: soft

"@zeitgeistpm/utility@npm:^2.24.0":
version: 2.24.0
resolution: "@zeitgeistpm/utility@npm:2.24.0"
"@zeitgeistpm/utility@npm:^2.24.1":
version: 2.24.1
resolution: "@zeitgeistpm/utility@npm:2.24.1"
dependencies:
decimal.js: ^10.4.3
lodash.omit: ^4.5.0
Expand All @@ -4458,13 +4447,13 @@ __metadata:
"@polkadot/api": "*"
"@polkadot/types": "*"
"@polkadot/util": "*"
checksum: d671238f8b6baacd0c75bba2612754dde3d96586aa799f98d1b50d0de15c23d3c63868482c45aad4ee97884a88cdee5b7f0ab3b91201f4b1365262e27a79faec
checksum: 75416aca267e198e4f4f444ce80ad0988b3b3435430898121753773ac6873d84d7855b7ee9b4946dd8178b6d84c582124dda96d97cb681ee4c5b25fb84546133
languageName: node
linkType: hard

"@zeitgeistpm/utility@npm:^2.24.1":
version: 2.24.1
resolution: "@zeitgeistpm/utility@npm:2.24.1"
"@zeitgeistpm/utility@npm:^2.25.0":
version: 2.25.0
resolution: "@zeitgeistpm/utility@npm:2.25.0"
dependencies:
decimal.js: ^10.4.3
lodash.omit: ^4.5.0
Expand All @@ -4474,15 +4463,15 @@ __metadata:
"@polkadot/api": "*"
"@polkadot/types": "*"
"@polkadot/util": "*"
checksum: 75416aca267e198e4f4f444ce80ad0988b3b3435430898121753773ac6873d84d7855b7ee9b4946dd8178b6d84c582124dda96d97cb681ee4c5b25fb84546133
checksum: eb74e58bc28bfac1eb315f9b008b563e4ae8d1fa70b133d9ef9d16c4fdc7cf7aa731f1d155a5bf26a336b693fb0aea773f558bc60a6a1ec999289b42852fc190
languageName: node
linkType: hard

"@zeitgeistpm/web3.storage@npm:^2.15.0":
version: 2.15.0
resolution: "@zeitgeistpm/web3.storage@npm:2.15.0"
"@zeitgeistpm/web3.storage@npm:^2.16.0":
version: 2.16.0
resolution: "@zeitgeistpm/web3.storage@npm:2.16.0"
dependencies:
"@zeitgeistpm/utility": ^2.24.0
"@zeitgeistpm/utility": ^2.25.0
cids: ^1.1.9
ipfs-http-client: ^60.0.0
ipfs-only-hash: ^4.0.0
Expand All @@ -4491,7 +4480,7 @@ __metadata:
up: ^1.0.2
peerDependencies:
"@polkadot/util": "*"
checksum: 4b6255ac7a0f30f1dd7654ee792107689cc44c6ecedb55192592dbd68040a459437d69f9eedb3a5a82b575e07f48c345795d9954302a3baa73fbf7f1d5bddf7b
checksum: 3cafd120a3a68c510949369998035eaefbd48c27d6a98efe26e3c92e1e6b1bd429a5e47b314e35f88dff05d03b9b275ebbed40d4fa60494f1ea815a4c58dd2de
languageName: node
linkType: hard

Expand Down

0 comments on commit 1bce02d

Please sign in to comment.