Skip to content

Commit 8bb22c4

Browse files
committed
release new version
1 parent a556149 commit 8bb22c4

File tree

7 files changed

+65
-128
lines changed

7 files changed

+65
-128
lines changed

package.json

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
{
22
"name": "@quest-chains/sdk",
33
"description": "An SDK for building applications on top of Quest Chains",
4-
"version": "0.2.10",
4+
"version": "0.2.11",
55
"license": "GPL-3.0",
66
"main": "dist/index.js",
77
"typings": "dist/index.d.ts",
8-
"files": [
9-
"dist/**/*"
10-
],
8+
"files": ["dist/**/*"],
119
"engines": {
12-
"node": ">=14"
10+
"node": ">=18"
1311
},
1412
"scripts": {
1513
"start": "tsdx watch",
16-
"build": "rm -rf dist && yarn tsc",
14+
"build": "yarn generate && rm -rf dist && yarn tsc",
1715
"test": "tsdx test --passWithNoTests",
1816
"lint": "tsdx lint",
1917
"typecheck": "tsc --noEmit",
@@ -36,10 +34,7 @@
3634
"url": "https://github.com/quest-chains/sdk/issues"
3735
},
3836
"homepage": "https://github.com/quest-chains/sdk#readme",
39-
"keywords": [
40-
"ethereum",
41-
"quest-chains"
42-
],
37+
"keywords": ["ethereum", "quest-chains", "sdk"],
4338
"prettier": {
4439
"semi": true,
4540
"trailingComma": "all",

src/codegen.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
overwrite: true
2-
schema: 'https://api.thegraph.com/subgraphs/name/quest-chains/quest-chains-goerli'
2+
schema: 'https://api.studio.thegraph.com/query/71457/quest-chains-sepolia/version/latest'
33
generates:
44
src/graphql/types.ts:
55
config:

src/graphql/client.ts

Lines changed: 31 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,68 +3,59 @@ import { Client, createClient, dedupExchange, fetchExchange } from 'urql';
33
export type NetworkInfo = {
44
[chainId: string]: {
55
chainId: string;
6-
subgraphName: string;
7-
subgraphUrl: string;
6+
prodSubgraphUrl: string;
7+
devSubgraphUrl: string;
88
};
99
};
1010

11+
const GRAPH_API_KEY =
12+
process.env.REACT_APP_GRAPH_API_KEY || process.env.NEXT_PUBLIC_GRAPH_API_KEY || process.env.GRAPH_API_KEY;
13+
1114
export const SUPPORTED_NETWORK_INFO: NetworkInfo = {
12-
'0x5': {
13-
chainId: '0x5',
14-
subgraphName: 'quest-chains/quest-chains-goerli',
15-
subgraphUrl: 'https://api.thegraph.com/subgraphs/name/quest-chains/quest-chains-goerli',
16-
},
1715
'0xa': {
1816
chainId: '0xa',
19-
subgraphName: 'quest-chains/quest-chains-optimism',
20-
subgraphUrl: 'https://api.thegraph.com/subgraphs/name/quest-chains/quest-chains-optimism',
17+
prodSubgraphUrl: `https://gateway-arbitrum.network.thegraph.com/api/${GRAPH_API_KEY}/subgraphs/id/9GTxhTXaiJqgYGuSsMjH3KWdEQfFf8BzrTQKWNKZBMzB`,
18+
devSubgraphUrl: 'https://api.studio.thegraph.com/query/71457/quest-chains-optimism/version/latest',
2119
},
2220
'0x64': {
2321
chainId: '0x64',
24-
subgraphName: 'quest-chains/quest-chains-gnosis',
25-
subgraphUrl: 'https://api.thegraph.com/subgraphs/name/quest-chains/quest-chains-gnosis',
22+
prodSubgraphUrl: `https://gateway-arbitrum.network.thegraph.com/api/${GRAPH_API_KEY}/subgraphs/id/EdGKgTZKUfZnWmG3rPAirBis6xUJpAJ8dgvMts9Aiixb`,
23+
devSubgraphUrl: 'https://api.studio.thegraph.com/query/71457/quest-chains-gnosis/version/latest',
2624
},
2725
'0x89': {
2826
chainId: '0x89',
29-
subgraphName: 'quest-chains/quest-chains-polygon',
30-
subgraphUrl: 'https://api.thegraph.com/subgraphs/name/quest-chains/quest-chains-polygon',
31-
},
32-
'0x13881': {
33-
chainId: '0x13881',
34-
subgraphName: 'quest-chains/quest-chains-mumbai',
35-
subgraphUrl: 'https://api.thegraph.com/subgraphs/name/quest-chains/quest-chains-mumbai',
36-
},
37-
'0xa4b1': {
38-
chainId: '0xa4b1',
39-
subgraphName: 'quest-chains/quest-chains-arbitrum',
40-
subgraphUrl: 'https://api.thegraph.com/subgraphs/name/quest-chains/quest-chains-arbitrum',
41-
},
42-
'0x66eed': {
43-
chainId: '0x66eed',
44-
subgraphName: 'quest-chains/quest-chains-arbitrum-goerli',
45-
subgraphUrl: 'https://api.thegraph.com/subgraphs/name/quest-chains/quest-chains-arbitrum-goerli',
27+
prodSubgraphUrl: `https://gateway-arbitrum.network.thegraph.com/api/${GRAPH_API_KEY}/subgraphs/id/29xgvK1yyJkcq3zM1wqTvFh3riMzpTFjLqu3PYZ1ZSv5`,
28+
devSubgraphUrl: 'https://api.studio.thegraph.com/query/71457/quest-chains-polygon/version/latest',
29+
},
30+
// '0xa4b1': {
31+
// chainId: '0xa4b1',
32+
// prodSubgraphUrl: 'https://api.thegraph.com/subgraphs/name/quest-chains/quest-chains-arbitrum',
33+
// devSubgraphUrl: 'https://api.studio.thegraph.com/query/71457/quest-chains-arbitrum/version/latest',
34+
// },
35+
// '0x4268': {
36+
// chainId: '0x4268',
37+
// prodSubgraphUrl: 'https://api.thegraph.com/subgraphs/name/quest-chains/quest-chains-holesky',
38+
// devSubgraphUrl: 'https://api.studio.thegraph.com/query/71457/quest-chains-holesky/version/latest',
39+
// },
40+
'0xaa36a7': {
41+
chainId: '0xaa36a7',
42+
prodSubgraphUrl: `https://gateway-testnet-arbitrum.network.thegraph.com/api/${GRAPH_API_KEY}/subgraphs/id/5fRc469U46WVkH9WWYQ2wUuS3cdrX14WNmHGyaqg87Fe`,
43+
devSubgraphUrl: 'https://api.studio.thegraph.com/query/71457/quest-chains-sepolia/version/latest',
4644
},
4745
};
4846

4947
export const SUPPORTED_NETWORKS = Object.keys(SUPPORTED_NETWORK_INFO);
5048

51-
const clients: Record<string, Client> = Object.values(SUPPORTED_NETWORK_INFO).reduce<Record<string, Client>>(
52-
(o, info) => {
53-
o[info.chainId] = createClient({
54-
url: info.subgraphUrl,
55-
exchanges: [dedupExchange, fetchExchange],
56-
});
57-
return o;
58-
},
59-
{},
60-
);
61-
6249
export const isSupportedNetwork = (chainId: string | undefined | null) =>
6350
chainId ? SUPPORTED_NETWORKS.includes(chainId) : false;
6451

6552
export const getClient = (chainId: string | undefined | null): Client => {
6653
if (!chainId || !isSupportedNetwork(chainId)) {
6754
throw new Error('Unsupported chainId');
6855
}
69-
return clients[chainId];
56+
const info = SUPPORTED_NETWORK_INFO[chainId];
57+
return createClient({
58+
url: !!GRAPH_API_KEY ? info.prodSubgraphUrl : info.devSubgraphUrl,
59+
exchanges: [dedupExchange, fetchExchange],
60+
});
7061
};

src/graphql/health.ts

Lines changed: 17 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,20 @@
1-
/* eslint-disable no-console, no-await-in-loop */
2-
import { gql, request } from 'graphql-request';
3-
4-
import { SUPPORTED_NETWORK_INFO } from './client';
5-
6-
const GRAPH_HEALTH_ENDPOINT = 'https://api.thegraph.com/index-node/graphql';
7-
8-
const statusQuery = gql`
9-
query getSubgraphStatus($subgraph: String!) {
10-
status: indexingStatusForCurrentVersion(subgraphName: $subgraph) {
11-
chains {
12-
latestBlock {
13-
number
14-
}
15-
}
1+
import { getClient } from './client';
2+
import { GetMetaDocument, GetMetaQueryVariables, GetMetaQuery } from './types';
3+
4+
export const getSubgraphLatestBlock = async (chainId: string): Promise<number> => {
5+
try {
6+
const { data, error } = await getClient(chainId)
7+
.query<GetMetaQuery, GetMetaQueryVariables>(GetMetaDocument, {})
8+
.toPromise();
9+
10+
if (error) {
11+
console.error('Error querying subgraph meta', error);
12+
return 0;
1613
}
17-
}
18-
`;
19-
20-
const getLatestBlock = async (subgraph: string): Promise<number> => {
21-
const data = await request(GRAPH_HEALTH_ENDPOINT, statusQuery, {
22-
subgraph,
23-
});
24-
return data.status.chains[0].latestBlock.number;
25-
};
2614

27-
const UPDATE_INTERVAL = 10000;
28-
29-
class SubgraphHealthStore {
30-
graphHealth: Record<string, number> = {};
31-
32-
constructor() {
33-
// console.debug('@quest-chains/sdk: health store init');
34-
this.updateSubgraphHealth();
15+
return Number(data?._meta?.block?.number);
16+
} catch (e) {
17+
console.error(`Failed to get subgraph block number for chain ${chainId}`, e);
18+
return 0;
3519
}
36-
37-
public async updateSubgraphHealth() {
38-
await Promise.all(
39-
Object.values(SUPPORTED_NETWORK_INFO).map(async info => {
40-
this.graphHealth[info.chainId] = await getLatestBlock(info.subgraphName);
41-
}),
42-
);
43-
// console.debug('@quest-chains/sdk: updated graph health:', this.graphHealth);
44-
setTimeout(() => this.updateSubgraphHealth(), UPDATE_INTERVAL);
45-
}
46-
47-
status() {
48-
return this.graphHealth;
49-
}
50-
}
51-
52-
const HealthStoreSingleton = (function () {
53-
let instance: SubgraphHealthStore;
54-
55-
function createInstance() {
56-
return new SubgraphHealthStore();
57-
}
58-
59-
return {
60-
getInstance: function () {
61-
if (!instance) {
62-
instance = createInstance();
63-
}
64-
return instance;
65-
},
66-
};
67-
})();
68-
69-
const getSubgraphStatus = () => HealthStoreSingleton.getInstance().status();
70-
71-
const initSubgraphHealthStore = getSubgraphStatus;
72-
73-
if (typeof window !== 'undefined') {
74-
initSubgraphHealthStore();
75-
}
76-
77-
export const getSubgraphLatestBlock = (chainId: string): number => getSubgraphStatus()[chainId];
20+
};

src/graphql/queries.graphql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
query GetMeta {
2+
_meta {
3+
block {
4+
number
5+
}
6+
}
7+
}
8+
19
query GlobalInfo {
210
globals {
311
...GlobalInfo

src/helpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ const UPDATE_INTERVAL = 10000;
1212
const MAX_RETRIES = 6;
1313

1414
export const waitUntilSubgraphIndexed = async (chainId: string, block: number): Promise<boolean> => {
15-
let latestBlock = getSubgraphLatestBlock(chainId);
15+
let latestBlock = await getSubgraphLatestBlock(chainId);
1616
let tries = 0;
1717
while (latestBlock < block && tries < MAX_RETRIES) {
1818
await sleep(UPDATE_INTERVAL);
1919
tries += 1;
20-
latestBlock = getSubgraphLatestBlock(chainId);
20+
latestBlock = await getSubgraphLatestBlock(chainId);
2121
}
2222
return latestBlock >= block;
2323
};

src/metadata/metadata.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export class MetadataUploader extends EventEmitter {
7171

7272
try {
7373
const res = await axios.post(`${apiUrl ?? this.apiUrl}/upload/files`, formData, config);
74-
return res.data.response['/'];
74+
return res.data.response;
7575
} catch (error) {
7676
throw new Error(((error as AxiosError).response?.data as HttpResponse).error);
7777
}

0 commit comments

Comments
 (0)