From aae40b0b3272600f209856e867c7c91bcccafb18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C5=ABdolfs=20O=C5=A1i=C5=86=C5=A1?= Date: Mon, 10 Oct 2022 17:26:59 +0200 Subject: [PATCH] Remove deprecated the Graph queries MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We have run out of funds on the Graph and the org functionality in its current form is deprecated. Signed-off-by: Rūdolfs Ošiņš --- src/base/orgs/Org.ts | 71 ++++---------------------------------------- src/config.json | 2 -- src/config.ts | 2 +- src/utils.ts | 70 ++++--------------------------------------- 4 files changed, 12 insertions(+), 133 deletions(-) diff --git a/src/base/orgs/Org.ts b/src/base/orgs/Org.ts index a57cb666b..5fc3b30e2 100644 --- a/src/base/orgs/Org.ts +++ b/src/base/orgs/Org.ts @@ -8,42 +8,6 @@ import * as cache from "@app/cache"; import type { Safe } from "@app/utils"; import type { Config } from "@app/config"; -const GetSafesByOwners = ` - query GetSafesByOwners($owners: [String!]!) { - safes(where: { owners_contains: $owners }) { - id - owners - threshold - } - } -`; - -const GetOrgsByOwners = ` - query GetOrgsByOwners($owners: [String!]!) { - orgs(where: { owner_in: $owners }) { - id - owner - safe { - id - owners - threshold - } - creator - timestamp - } - } -`; - -export const GetSafe = ` - query GetSafe($addr: ID!) { - safe(id: $addr) { - id - owners - threshold - } - } -`; - export class Org { address: string; owner: string; @@ -193,36 +157,11 @@ export class Org { } } - static async getOrgsByMember(owner: string, config: Config): Promise { - type Safe = { id: string; owners: string[]; threshold: number }; - - // TODO: We use two subgraph queries since we can't do a filter query yet in the subgraph - // https://github.com/graphprotocol/graph-node/issues/2539#issuecomment-855979841 - const safesByOwner = await utils.querySubgraph( - config.orgs.subgraph, - GetSafesByOwners, - { owners: [owner] }, - ); - - let safes = []; - if (safesByOwner && safesByOwner.safes.length > 0) { - safes = safesByOwner.safes.reduce( - (prev: any, curr: Safe) => prev.concat(curr.id), - [], - ); - } - - const orgsByOwner = await utils.querySubgraph( - config.orgs.subgraph, - GetOrgsByOwners, - { owners: [...safes, owner] }, - ); - let orgs: { id: string; owner: string }[] = []; - if (orgsByOwner && orgsByOwner.orgs) { - orgs = [...orgsByOwner.orgs]; - } - - return orgs.map(o => new Org(o.id, o.owner)); + static async getOrgsByMember( + _owner: string, + _config: Config, + ): Promise { + return []; } } diff --git a/src/config.json b/src/config.json index ab9123d93..171af0d46 100644 --- a/src/config.json +++ b/src/config.json @@ -11,7 +11,6 @@ "address": "0xa15bEb4876F20018b6b4A4116B7560c5fcC9336e" }, "orgs": { - "subgraph": "https://gateway.thegraph.com/api/1758a78ae257ad4906f9c638e4a68c19/subgraphs/id/0x2f0963e77ca6ac0c2dad1bf4147b6b40e0dd8728-0", "contractHash": "0x5c34bb0755876de98e801805e6685456eea739ad0abba1cc450a7ee0f2a70b74", "pinned": [ "alt-clients.radicle.eth", @@ -49,7 +48,6 @@ "address": "0xF3D04e874D07d680e8b26332eEae5b9B1c263121" }, "orgs": { - "subgraph": "https://api.thegraph.com/subgraphs/name/radicle-dev/radicle-orgs-rinkeby", "contractHash": "0x5c34bb0755876de98e801805e6685456eea739ad0abba1cc450a7ee0f2a70b74", "pinned": [] }, diff --git a/src/config.ts b/src/config.ts index 79afbcec6..ea6942c14 100644 --- a/src/config.ts +++ b/src/config.ts @@ -31,7 +31,7 @@ export class Config { radToken: { address: string; faucet: string }; orgFactory: { address: string }; reverseRegistrar: { address: string }; - orgs: { subgraph: string; contractHash: string; pinned: string[] }; + orgs: { contractHash: string; pinned: string[] }; users: { pinned: string[] }; projects: { pinned: { urn: string; name: string; seed: string }[] }; seeds: { pinned: Record }; diff --git a/src/utils.ts b/src/utils.ts index f4fb45c0e..887cfc7d6 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -21,7 +21,6 @@ import { } from "@app/base/registrations/registrar"; import { ProfileType } from "@app/profile"; import { parseUnits } from "@ethersproject/units"; -import { GetSafe } from "@app/base/orgs/Org"; import * as cache from "@app/cache"; import type { marked } from "marked"; import emojis from "@app/emojis"; @@ -358,45 +357,6 @@ export function safeLink(addr: string, config: Config): string { return explorerLink(addr, config); } -// Query a subgraph. -export async function querySubgraphWithRetry( - url: string, - query: string, - variables: Record, - retries = 3, -): Promise | null> { - const response = await fetch(url, { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify({ - query, - variables, - }), - }); - const json = await response.json(); - - if (json.errors) { - console.error("querySubgraph:", json.errors); - - if (retries > 0) { - return querySubgraphWithRetry(url, query, variables, retries - 1); - } else { - return null; - } - } else { - return json.data; - } -} - -export const querySubgraph = cache.cached( - querySubgraphWithRetry, - (url: string, query: string, variables: Record) => - JSON.stringify({ url, query, variables }), - { max: 500, ttl: 5 * 60 * 1000 }, // Cache results for 5 minutes. -); - // Format a name. export function formatName(input: string, config: Config): string { return parseEnsLabel(input, config); @@ -558,36 +518,18 @@ export async function resolveEnsProfile( // Check whether a Gnosis Safe exists at an address. export async function isSafe( - address: string, - config: Config, + _address: string, + _config: Config, ): Promise { - // For the subgraph we need to pass a lowercase address - const query = await querySubgraph(config.orgs.subgraph, GetSafe, { - addr: address.toLowerCase(), - }); - - return Boolean(query?.safe); + return false; } // Get a Gnosis Safe at an address. export async function getSafe( - address: string, - config: Config, + _address: string, + _config: Config, ): Promise { - // For the subgraph we need to pass a lowercase address - const query = await querySubgraph(config.orgs.subgraph, GetSafe, { - addr: address.toLowerCase(), - }); - - if (!query?.safe) { - return null; - } - - return { - address: query.safe.id, - owners: query.safe.owners, - threshold: query.safe.threshold, - }; + return null; } // Get token balances for an address.