Skip to content

Commit

Permalink
update subgraph endpoints as they were migrated to Arbitrum. Remove d…
Browse files Browse the repository at this point in the history
…eprecated hosted subgraph
  • Loading branch information
QYuQianchen committed Aug 26, 2024
1 parent 0c7afed commit 359084a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
11 changes: 7 additions & 4 deletions src/strategies/hopr-stake-and-balance-qv/examples.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,21 @@
"useChannelStake": true,
"useHoprOnGnosis": true,
"useHoprOnMainnet": true,
"subgraphStudioProdSafeStakeQueryId": "DrkbaCvNGVcNH1RghepLRy6NSHFi8Dmwp4T2LN3LqcjY",
"subgraphStudioProdSafeStakeQueryId": "GP2abJCarirMJCanuk4SBmnadiobEWH9ME2MNRAHbBTp",
"subgraphStudioDevSafeStakeSubgraphName": "hopr-nodes-dufour",
"subgraphStudioDevSafeStakeVersion": "latest",
"subgraphHostedSafeStakeSubgraphName": null,
"subgraphStudioProdChannelsQueryId": "Feg6Jero3aQzesVYuqk253NNLyNAZZppbDPKFYEGJ1Hj",
"subgraphStudioProdChannelsQueryId": "GoJ4KRuYEcELQk42hir2tjau6r1u4ibDFY6t1zH6zpKk",
"subgraphStudioDevChannelsSubgraphName": "hopr-channels",
"subgraphStudioDevChannelsVersion": "latest",
"subgraphHostedChannelsSubgraphName": null,
"subgraphStudioProdHoprOnGnosisQueryId": "njToE7kpetd3P9sJdYQPSq6yQjBs7w9DahQpBj6WAoD",
"subgraphStudioProdHoprOnGnosisQueryId": "2wMRp1AW1ghxoFiM6WeRD93djHNvNGhXsuQyadmwCyqE",
"subgraphStudioDevHoprOnGnosisSubgraphName": "hopr-on-gnosis",
"subgraphStudioDevHoprOnGnosisVersion": "v0.0.2",
"subgraphHostedHoprOnGnosisSubgraphName": "hopr-on-xdai",
"subgraphStudioProdGnosisBlockQueryId": "FxV6YUix58SpYmLBwc9gEHkwjfkqwe1X5FJQjn8nKPyA",
"subgraphStudioDevGnosisBlockSubgraphName": "gnosis-blocks",
"subgraphStudioDevGnosisBlockVersion": "latest",
"subgraphHostedGnosisBlockSubgraphName": null,
"exponent": "0.75"
}
},
Expand Down
19 changes: 16 additions & 3 deletions src/strategies/hopr-stake-and-balance-qv/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ export const version = '0.2.0';
*************** PARAMETERS ***************
******************************************
*/
const XDAI_BLOCK_HOSTED_SUBGRAPH_URL =
'https://api.thegraph.com/subgraphs/name/1hive/xdai-blocks'; // convert mainnet block to its corresponding block on Gnosis chain
const tokenAbi = ['function balanceOf(address) view returns (uint256)']; // get mainnet HOPR token balance
const DEFAULT_HOPR_HOSTED_ACCOUNT_NAME = 'hoprnet';
const DEFAULT_FACTOR = 0.75; // Quadratic-voting-like factor
Expand Down Expand Up @@ -105,8 +103,23 @@ export async function strategy(
]);

// get the block number for subgraph query
const hostedSafeStakeSubgraphUrl = getHostedSubgraphUrl(
options.subgraphHostedAccountName ?? DEFAULT_HOPR_HOSTED_ACCOUNT_NAME,
options.subgraphHostednosisBlockSubgraphName
);
const stuidoDevGnosisBlockSubgraphUrl = getStudioDevSubgraphUrl(
options.subgraphStudioDevAccountId,
options.subgraphStudioDevGnosisBlockSubgraphName,
options.subgraphStudioDevGnosisBlockVersion
);
const studioProdGnosisBlockSubgraphUrl = getStudioProdSubgraphUrl(
options.subgraphStudioProdQueryApiKey,
options.subgraphStudioProdGnosisBlockQueryId
);
const subgraphBlock = await getGnosisBlockNumber(
XDAI_BLOCK_HOSTED_SUBGRAPH_URL,
hostedSafeStakeSubgraphUrl,
stuidoDevGnosisBlockSubgraphUrl,
studioProdGnosisBlockSubgraphUrl,
block.timestamp,
options.fallbackGnosisBlock
);
Expand Down
12 changes: 7 additions & 5 deletions src/strategies/hopr-stake-and-balance-qv/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function getStudioProdSubgraphUrl(
): string | null {
return !apiKey
? null
: `https://gateway.thegraph.com/api/${apiKey}/subgraphs/id/${subgraphId}`;
: `https://gateway-arbitrum.network.thegraph.com/api/${apiKey}/subgraphs/id/${subgraphId}`;
}

export function getStudioDevSubgraphUrl(
Expand Down Expand Up @@ -111,7 +111,9 @@ export async function subgraphRequestsToVariousServices(
* @returns a number
*/
export async function getGnosisBlockNumber(
queryUrl: string,
hostedQueryUrl: string | null,
devQueryUrl: string | null,
prodQueryUrl: string | null,
timestamp: number,
fallbackBlockNumber: number
): Promise<number> {
Expand All @@ -132,9 +134,9 @@ export async function getGnosisBlockNumber(

// query from subgraph
const data = await subgraphRequestsToVariousServices(
queryUrl,
null,
null,
hostedQueryUrl,
devQueryUrl,
prodQueryUrl,
query
);
return !data ? fallbackBlockNumber : Number(data.blocks[0].number);
Expand Down

0 comments on commit 359084a

Please sign in to comment.