From cc7dc60e64639d1c3cb25d7c8df6de05e98f707d Mon Sep 17 00:00:00 2001 From: MantisClone Date: Fri, 28 Jun 2024 16:20:08 -0400 Subject: [PATCH 1/7] fix: superfluid subgraph urls (part 2) --- .../payment-detection/src/thegraph/superfluid.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/payment-detection/src/thegraph/superfluid.ts b/packages/payment-detection/src/thegraph/superfluid.ts index 30924f24a..fcfa28f1d 100644 --- a/packages/payment-detection/src/thegraph/superfluid.ts +++ b/packages/payment-detection/src/thegraph/superfluid.ts @@ -4,8 +4,16 @@ import { RequestConfig } from 'graphql-request/src/types'; const BASE_URL = `https://subgraph-endpoints.superfluid.dev`; const NETWORK_TO_URL: Record = { - optimism: 'optimism-mainnet', + 'arbitrum-one': 'arbitrum-one', avalanche: 'avalanche-c', + matic: 'polygon-mainnet', + optimism: 'optimism-mainnet', + sepolia: 'eth-sepolia', + xdai: 'xdai-mainnet', + bsc: 'bsc-mainnet', + mainnet: 'eth-mainnet', + celo: 'celo-mainnet', + base: 'base-mainnet', }; // NB: the GraphQL client is automatically generated based on files present in ./queries, @@ -31,6 +39,6 @@ export const getTheGraphSuperfluidClient = ( // which is a better security but would require an update of the // library each time the subgraph is updated, which isn't ideal // for early testing. - const url = `${baseUrl}/${NETWORK_TO_URL[network] || network}/protocol-v1`; + const url = `${baseUrl}/${NETWORK_TO_URL[network]}/protocol-v1`; return getSdk(new GraphQLClient(url, clientOptions)); }; From d079b480cdb78d3c555efb854791af153e4d5b3d Mon Sep 17 00:00:00 2001 From: MantisClone Date: Fri, 28 Jun 2024 16:48:53 -0400 Subject: [PATCH 2/7] Split logic and write unit test for buildTheGraphSuperfluidUrl --- .../payment-detection/src/thegraph/superfluid.ts | 10 ++++++++-- .../test/thegraph/superfulid.test.ts | 13 +++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 packages/payment-detection/test/thegraph/superfulid.test.ts diff --git a/packages/payment-detection/src/thegraph/superfluid.ts b/packages/payment-detection/src/thegraph/superfluid.ts index fcfa28f1d..a2a5f4306 100644 --- a/packages/payment-detection/src/thegraph/superfluid.ts +++ b/packages/payment-detection/src/thegraph/superfluid.ts @@ -32,13 +32,19 @@ export const getTheGraphSuperfluidClient = ( options?: TheGraphClientOptions, ): TheGraphSuperfluidClient => { const { baseUrl: _baseUrl, ...clientOptions } = options ?? {}; + const url = buildTheGraphSuperfluidUrl(_baseUrl, network); + return getSdk(new GraphQLClient(url, clientOptions)); +}; +export const buildTheGraphSuperfluidUrl = ( + _baseUrl: string | undefined, + network: string, +): string => { const baseUrl = _baseUrl || network === 'private' ? 'http://localhost:8000' : BASE_URL; // Note: it is also possible to use the IPFS hash of the subgraph // eg. /subgraphs/id/QmcCaSkefrmhe4xQj6Y6BBbHiFkbrn6UGDEBUWER7nt399 // which is a better security but would require an update of the // library each time the subgraph is updated, which isn't ideal // for early testing. - const url = `${baseUrl}/${NETWORK_TO_URL[network]}/protocol-v1`; - return getSdk(new GraphQLClient(url, clientOptions)); + return `${baseUrl}/${NETWORK_TO_URL[network]}/protocol-v1`; }; diff --git a/packages/payment-detection/test/thegraph/superfulid.test.ts b/packages/payment-detection/test/thegraph/superfulid.test.ts new file mode 100644 index 000000000..d28ca0185 --- /dev/null +++ b/packages/payment-detection/test/thegraph/superfulid.test.ts @@ -0,0 +1,13 @@ +import { buildTheGraphSuperfluidUrl } from '../../src/thegraph/superfluid'; + +describe('buildTheGraphSuperfluidUrl', () => { + it('should build the correct URL when baseUrl is undefined', () => { + const url = buildTheGraphSuperfluidUrl(undefined, 'sepolia'); + expect(url).toBe('https://subgraph-endpoints.superfluid.dev/eth-sepolia/protocol-v1'); + }); + + it('should build the correct URL when baseUrl is defined', () => { + const url = buildTheGraphSuperfluidUrl('https://example.com', 'sepolia'); + expect(url).toBe('https://example.com/eth-sepolia/protocol-v1'); + }); +}); From dd255f784f35c176e1457d9296adf3e11df2411c Mon Sep 17 00:00:00 2001 From: MantisClone Date: Fri, 28 Jun 2024 17:11:56 -0400 Subject: [PATCH 3/7] Fix logic --- packages/payment-detection/src/thegraph/superfluid.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/payment-detection/src/thegraph/superfluid.ts b/packages/payment-detection/src/thegraph/superfluid.ts index a2a5f4306..f05cd93ae 100644 --- a/packages/payment-detection/src/thegraph/superfluid.ts +++ b/packages/payment-detection/src/thegraph/superfluid.ts @@ -37,14 +37,14 @@ export const getTheGraphSuperfluidClient = ( }; export const buildTheGraphSuperfluidUrl = ( - _baseUrl: string | undefined, + baseUrl: string | undefined, network: string, ): string => { - const baseUrl = _baseUrl || network === 'private' ? 'http://localhost:8000' : BASE_URL; + const _baseUrl = baseUrl || (network === 'private' ? 'http://localhost:8000' : BASE_URL); // Note: it is also possible to use the IPFS hash of the subgraph // eg. /subgraphs/id/QmcCaSkefrmhe4xQj6Y6BBbHiFkbrn6UGDEBUWER7nt399 // which is a better security but would require an update of the // library each time the subgraph is updated, which isn't ideal // for early testing. - return `${baseUrl}/${NETWORK_TO_URL[network]}/protocol-v1`; + return `${_baseUrl}/${NETWORK_TO_URL[network]}/protocol-v1`; }; From 1a52929a734363c8d2d8ea74618946316da7369d Mon Sep 17 00:00:00 2001 From: MantisClone Date: Fri, 28 Jun 2024 17:12:48 -0400 Subject: [PATCH 4/7] Add test for private network --- packages/payment-detection/test/thegraph/superfulid.test.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/payment-detection/test/thegraph/superfulid.test.ts b/packages/payment-detection/test/thegraph/superfulid.test.ts index d28ca0185..f718d3cb3 100644 --- a/packages/payment-detection/test/thegraph/superfulid.test.ts +++ b/packages/payment-detection/test/thegraph/superfulid.test.ts @@ -5,9 +5,12 @@ describe('buildTheGraphSuperfluidUrl', () => { const url = buildTheGraphSuperfluidUrl(undefined, 'sepolia'); expect(url).toBe('https://subgraph-endpoints.superfluid.dev/eth-sepolia/protocol-v1'); }); - it('should build the correct URL when baseUrl is defined', () => { const url = buildTheGraphSuperfluidUrl('https://example.com', 'sepolia'); expect(url).toBe('https://example.com/eth-sepolia/protocol-v1'); }); + it('should build the correct URL when network is private', () => { + const url = buildTheGraphSuperfluidUrl(undefined, 'private'); + expect(url).toBe('http://localhost:8000/protocol-v1'); + }); }); From 17d8cd24a8112053613b69f290bfc4afeb9b4525 Mon Sep 17 00:00:00 2001 From: MantisClone Date: Fri, 28 Jun 2024 17:32:49 -0400 Subject: [PATCH 5/7] Fix tests for private --- packages/payment-detection/src/thegraph/superfluid.ts | 5 +++-- packages/payment-detection/test/thegraph/superfulid.test.ts | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/payment-detection/src/thegraph/superfluid.ts b/packages/payment-detection/src/thegraph/superfluid.ts index f05cd93ae..8d51e71ff 100644 --- a/packages/payment-detection/src/thegraph/superfluid.ts +++ b/packages/payment-detection/src/thegraph/superfluid.ts @@ -40,11 +40,12 @@ export const buildTheGraphSuperfluidUrl = ( baseUrl: string | undefined, network: string, ): string => { - const _baseUrl = baseUrl || (network === 'private' ? 'http://localhost:8000' : BASE_URL); // Note: it is also possible to use the IPFS hash of the subgraph // eg. /subgraphs/id/QmcCaSkefrmhe4xQj6Y6BBbHiFkbrn6UGDEBUWER7nt399 // which is a better security but would require an update of the // library each time the subgraph is updated, which isn't ideal // for early testing. - return `${_baseUrl}/${NETWORK_TO_URL[network]}/protocol-v1`; + return network === 'private' + ? 'http://localhost:8000/subgraphs/name/superfluid-finance/protocol-v1-goerli' + : `${baseUrl || BASE_URL}/${NETWORK_TO_URL[network]}/protocol-v1`; }; diff --git a/packages/payment-detection/test/thegraph/superfulid.test.ts b/packages/payment-detection/test/thegraph/superfulid.test.ts index f718d3cb3..bada2b7cb 100644 --- a/packages/payment-detection/test/thegraph/superfulid.test.ts +++ b/packages/payment-detection/test/thegraph/superfulid.test.ts @@ -11,6 +11,6 @@ describe('buildTheGraphSuperfluidUrl', () => { }); it('should build the correct URL when network is private', () => { const url = buildTheGraphSuperfluidUrl(undefined, 'private'); - expect(url).toBe('http://localhost:8000/protocol-v1'); + expect(url).toBe('http://localhost:8000/subgraphs/name/superfluid-finance/protocol-v1-goerli'); }); }); From 08d962e3e0abe7d8983226b66f2670bece7bb96f Mon Sep 17 00:00:00 2001 From: MantisClone Date: Fri, 28 Jun 2024 17:33:06 -0400 Subject: [PATCH 6/7] Update old url --- .../src/thegraph/queries/superfluid/graphql.config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/payment-detection/src/thegraph/queries/superfluid/graphql.config.yml b/packages/payment-detection/src/thegraph/queries/superfluid/graphql.config.yml index 33533565a..37f2dbe0a 100644 --- a/packages/payment-detection/src/thegraph/queries/superfluid/graphql.config.yml +++ b/packages/payment-detection/src/thegraph/queries/superfluid/graphql.config.yml @@ -1 +1 @@ -schema: https://api.thegraph.com/subgraphs/name/superfluid-finance/protocol-v1-goerli +schema: https://subgraph-endpoints.superfluid.dev/eth-sepolia/protocol-v1 From f288c8fac4523c608657a54576a9f7ec745b6c70 Mon Sep 17 00:00:00 2001 From: MantisClone Date: Fri, 28 Jun 2024 19:44:41 -0400 Subject: [PATCH 7/7] Add tests for all chains --- .../src/thegraph/superfluid.ts | 8 ++-- .../test/thegraph/superfulid.test.ts | 48 +++++++++++++++++-- 2 files changed, 48 insertions(+), 8 deletions(-) diff --git a/packages/payment-detection/src/thegraph/superfluid.ts b/packages/payment-detection/src/thegraph/superfluid.ts index 8d51e71ff..941d2bc2b 100644 --- a/packages/payment-detection/src/thegraph/superfluid.ts +++ b/packages/payment-detection/src/thegraph/superfluid.ts @@ -6,14 +6,14 @@ const BASE_URL = `https://subgraph-endpoints.superfluid.dev`; const NETWORK_TO_URL: Record = { 'arbitrum-one': 'arbitrum-one', avalanche: 'avalanche-c', + base: 'base-mainnet', + bsc: 'bsc-mainnet', + celo: 'celo-mainnet', + mainnet: 'eth-mainnet', matic: 'polygon-mainnet', optimism: 'optimism-mainnet', sepolia: 'eth-sepolia', xdai: 'xdai-mainnet', - bsc: 'bsc-mainnet', - mainnet: 'eth-mainnet', - celo: 'celo-mainnet', - base: 'base-mainnet', }; // NB: the GraphQL client is automatically generated based on files present in ./queries, diff --git a/packages/payment-detection/test/thegraph/superfulid.test.ts b/packages/payment-detection/test/thegraph/superfulid.test.ts index bada2b7cb..904066079 100644 --- a/packages/payment-detection/test/thegraph/superfulid.test.ts +++ b/packages/payment-detection/test/thegraph/superfulid.test.ts @@ -1,10 +1,6 @@ import { buildTheGraphSuperfluidUrl } from '../../src/thegraph/superfluid'; describe('buildTheGraphSuperfluidUrl', () => { - it('should build the correct URL when baseUrl is undefined', () => { - const url = buildTheGraphSuperfluidUrl(undefined, 'sepolia'); - expect(url).toBe('https://subgraph-endpoints.superfluid.dev/eth-sepolia/protocol-v1'); - }); it('should build the correct URL when baseUrl is defined', () => { const url = buildTheGraphSuperfluidUrl('https://example.com', 'sepolia'); expect(url).toBe('https://example.com/eth-sepolia/protocol-v1'); @@ -13,4 +9,48 @@ describe('buildTheGraphSuperfluidUrl', () => { const url = buildTheGraphSuperfluidUrl(undefined, 'private'); expect(url).toBe('http://localhost:8000/subgraphs/name/superfluid-finance/protocol-v1-goerli'); }); + it('should build the correct URL when baseUrl is undefined and network is private', () => { + const url = buildTheGraphSuperfluidUrl(undefined, 'private'); + expect(url).toBe('http://localhost:8000/subgraphs/name/superfluid-finance/protocol-v1-goerli'); + }); + it('should build the correct URL when baseUrl is undefined and network is arbitrum-one', () => { + const url = buildTheGraphSuperfluidUrl(undefined, 'arbitrum-one'); + expect(url).toBe('https://subgraph-endpoints.superfluid.dev/arbitrum-one/protocol-v1'); + }); + it('should build the correct URL when baseUrl is undefined and network is avalanche', () => { + const url = buildTheGraphSuperfluidUrl(undefined, 'avalanche'); + expect(url).toBe('https://subgraph-endpoints.superfluid.dev/avalanche-c/protocol-v1'); + }); + it('should build the correct URL when baseUrl is undefined and network is base', () => { + const url = buildTheGraphSuperfluidUrl(undefined, 'base'); + expect(url).toBe('https://subgraph-endpoints.superfluid.dev/base-mainnet/protocol-v1'); + }); + it('should build the correct URL when baseUrl is undefined and network is bsc', () => { + const url = buildTheGraphSuperfluidUrl(undefined, 'bsc'); + expect(url).toBe('https://subgraph-endpoints.superfluid.dev/bsc-mainnet/protocol-v1'); + }); + it('should build the correct URL when baseUrl is undefined and network is celo', () => { + const url = buildTheGraphSuperfluidUrl(undefined, 'celo'); + expect(url).toBe('https://subgraph-endpoints.superfluid.dev/celo-mainnet/protocol-v1'); + }); + it('should build the correct URL when baseUrl is undefined and network is mainnet', () => { + const url = buildTheGraphSuperfluidUrl(undefined, 'mainnet'); + expect(url).toBe('https://subgraph-endpoints.superfluid.dev/eth-mainnet/protocol-v1'); + }); + it('should build the correct URL when baseUrl is undefined and network is matic', () => { + const url = buildTheGraphSuperfluidUrl(undefined, 'matic'); + expect(url).toBe('https://subgraph-endpoints.superfluid.dev/polygon-mainnet/protocol-v1'); + }); + it('should build the correct URL when baseUrl is undefined and network is optimism', () => { + const url = buildTheGraphSuperfluidUrl(undefined, 'optimism'); + expect(url).toBe('https://subgraph-endpoints.superfluid.dev/optimism-mainnet/protocol-v1'); + }); + it('should build the correct URL when baseUrl is undefined and network is sepolia', () => { + const url = buildTheGraphSuperfluidUrl(undefined, 'sepolia'); + expect(url).toBe('https://subgraph-endpoints.superfluid.dev/eth-sepolia/protocol-v1'); + }); + it('should build the correct URL when baseUrl is undefined and network is xdai', () => { + const url = buildTheGraphSuperfluidUrl(undefined, 'xdai'); + expect(url).toBe('https://subgraph-endpoints.superfluid.dev/xdai-mainnet/protocol-v1'); + }); });