From 359084a534bb8c257f32bf063195825f580f1ba1 Mon Sep 17 00:00:00 2001 From: QYuQianchen <10935300+QYuQianchen@users.noreply.github.com> Date: Mon, 26 Aug 2024 13:35:24 +0800 Subject: [PATCH] update subgraph endpoints as they were migrated to Arbitrum. Remove deprecated hosted subgraph --- .../hopr-stake-and-balance-qv/examples.json | 11 +++++++---- .../hopr-stake-and-balance-qv/index.ts | 19 ++++++++++++++++--- .../hopr-stake-and-balance-qv/utils.ts | 12 +++++++----- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/strategies/hopr-stake-and-balance-qv/examples.json b/src/strategies/hopr-stake-and-balance-qv/examples.json index c04b7e2c7..4bc83b8f9 100644 --- a/src/strategies/hopr-stake-and-balance-qv/examples.json +++ b/src/strategies/hopr-stake-and-balance-qv/examples.json @@ -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" } }, diff --git a/src/strategies/hopr-stake-and-balance-qv/index.ts b/src/strategies/hopr-stake-and-balance-qv/index.ts index c8753b13f..9d4dc7123 100644 --- a/src/strategies/hopr-stake-and-balance-qv/index.ts +++ b/src/strategies/hopr-stake-and-balance-qv/index.ts @@ -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 @@ -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 ); diff --git a/src/strategies/hopr-stake-and-balance-qv/utils.ts b/src/strategies/hopr-stake-and-balance-qv/utils.ts index c8a72cff6..3f8bce9cf 100644 --- a/src/strategies/hopr-stake-and-balance-qv/utils.ts +++ b/src/strategies/hopr-stake-and-balance-qv/utils.ts @@ -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( @@ -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 { @@ -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);