Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add networkId logic to superfluid subgraphs #1896

Merged
merged 3 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 33 additions & 9 deletions src/adapters/superFluid/superFluidAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
import axios from 'axios';
import { logger } from '../../utils/logger';
import { isProduction } from '../../utils/utils';
import {
FlowUpdatedEvent,
SuperFluidAdapterInterface,
} from './superFluidAdapterInterface';
import { NETWORK_IDS } from '../../provider';

const superFluidGraphqlUrl =
const superFluidGraphqlPolygonUrl =
'https://subgraph-endpoints.superfluid.dev/optimism-mainnet/protocol-v1';
const superFluidGraphqlStagingUrl =
const superFluidGraphqlPolygonStagingUrl =
'https://optimism-sepolia.subgraph.x.superfluid.dev';
const superFluidGraphBaseUrl =
'https://subgraph-endpoints.superfluid.dev/base-mainnet/protocol-v1';
Comment on lines +9 to +14
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Fix misleading constant names

The constant names suggest Polygon network but they're actually for Optimism network. This could lead to confusion and maintenance issues.

Apply this diff to fix the naming:

-const superFluidGraphqlPolygonUrl =
+const superFluidGraphqlOptimismUrl =
   'https://subgraph-endpoints.superfluid.dev/optimism-mainnet/protocol-v1';
-const superFluidGraphqlPolygonStagingUrl =
+const superFluidGraphqlOptimismSepoliaUrl =
   'https://optimism-sepolia.subgraph.x.superfluid.dev';
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const superFluidGraphqlPolygonUrl =
'https://subgraph-endpoints.superfluid.dev/optimism-mainnet/protocol-v1';
const superFluidGraphqlStagingUrl =
const superFluidGraphqlPolygonStagingUrl =
'https://optimism-sepolia.subgraph.x.superfluid.dev';
const superFluidGraphBaseUrl =
'https://subgraph-endpoints.superfluid.dev/base-mainnet/protocol-v1';
const superFluidGraphqlOptimismUrl =
'https://subgraph-endpoints.superfluid.dev/optimism-mainnet/protocol-v1';
const superFluidGraphqlOptimismSepoliaUrl =
'https://optimism-sepolia.subgraph.x.superfluid.dev';
const superFluidGraphBaseUrl =
'https://subgraph-endpoints.superfluid.dev/base-mainnet/protocol-v1';


const subgraphUrl = isProduction
? superFluidGraphqlUrl
: superFluidGraphqlStagingUrl;
const subgraphUrlMap = {
[NETWORK_IDS.OPTIMISTIC]: superFluidGraphqlPolygonUrl,
[NETWORK_IDS.OPTIMISM_SEPOLIA]: superFluidGraphqlPolygonStagingUrl,
[NETWORK_IDS.BASE_MAINNET]: superFluidGraphBaseUrl,
[NETWORK_IDS.BASE_SEPOLIA]: superFluidGraphBaseUrl,
};

// Function to retrieve the subgraph URL for a given network ID
const getSubgraphUrl = (networkId: number) => {
const url = subgraphUrlMap[networkId];
if (!url) {
throw new Error(`No subgraph URL found for network ID: ${networkId}`);
}
return url;
};

// Define your GraphQL query as a string and prepare your variables
const accountQuery = `
Expand Down Expand Up @@ -169,8 +183,9 @@
*/

// Optimism works
async accountBalance(accountId: string) {
async accountBalance(accountId: string, networkId: number) {
try {
const subgraphUrl = getSubgraphUrl(networkId);
const response = await axios.post(subgraphUrl, {
query: accountQuery,
variables: {
Expand All @@ -189,12 +204,16 @@
sender: string;
flowRate: string;
transactionHash: string;
networkId: number;
}): Promise<FlowUpdatedEvent | undefined> {
try {
const subgraphUrl = getSubgraphUrl(params.networkId);
const { networkId, ...whereParams } = params;

Check failure on line 211 in src/adapters/superFluid/superFluidAdapter.ts

View workflow job for this annotation

GitHub Actions / test

'networkId' is assigned a value but never used

const response = await axios.post(subgraphUrl, {
query: getFlowsQuery,
variables: {
where: params,
where: whereParams,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix unused networkId variable

The destructured networkId variable is not used. The linter correctly flagged this issue.

Apply this diff to fix the issue:

-      const { networkId, ...whereParams } = params;
+      const { networkId: _, ...whereParams } = params;

This change explicitly indicates that we're intentionally not using the networkId after destructuring.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const subgraphUrl = getSubgraphUrl(params.networkId);
const { networkId, ...whereParams } = params;
const response = await axios.post(subgraphUrl, {
query: getFlowsQuery,
variables: {
where: params,
where: whereParams,
const subgraphUrl = getSubgraphUrl(params.networkId);
const { networkId: _, ...whereParams } = params;
const response = await axios.post(subgraphUrl, {
query: getFlowsQuery,
variables: {
where: whereParams,
🧰 Tools
🪛 GitHub Check: test

[failure] 211-211:
'networkId' is assigned a value but never used

🪛 eslint

[error] 211-211: 'networkId' is assigned a value but never used.

(@typescript-eslint/no-unused-vars)

orderBy: 'timestamp',
orderDirection: 'asc',
},
Expand All @@ -213,14 +232,19 @@
sender: string;
flowRate: string;
timestamp_gt: number;
networkId: number;
}): Promise<FlowUpdatedEvent | undefined> {
try {
const subgraphUrl = getSubgraphUrl(params.networkId);

logger.debug('getFlowByReceiverSenderFlowRate has been called', params);

const { networkId, ...whereParams } = params;

Check failure on line 242 in src/adapters/superFluid/superFluidAdapter.ts

View workflow job for this annotation

GitHub Actions / test

'networkId' is assigned a value but never used

const response = await axios.post(subgraphUrl, {
query: getFlowsQuery,
variables: {
where: params,
where: whereParams,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix unused networkId variable and improve logging

Similar to the previous issue, the networkId variable is unused. Also, the debug log could be more informative.

Apply this diff to fix these issues:

       const subgraphUrl = getSubgraphUrl(params.networkId);
 
-      logger.debug('getFlowByReceiverSenderFlowRate has been called', params);
+      logger.debug('getFlowByReceiverSenderFlowRate called with params:', {
+        ...params,
+        subgraphUrl
+      });
 
-      const { networkId, ...whereParams } = params;
+      const { networkId: _, ...whereParams } = params;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const subgraphUrl = getSubgraphUrl(params.networkId);
logger.debug('getFlowByReceiverSenderFlowRate has been called', params);
const { networkId, ...whereParams } = params;
const response = await axios.post(subgraphUrl, {
query: getFlowsQuery,
variables: {
where: params,
where: whereParams,
const subgraphUrl = getSubgraphUrl(params.networkId);
logger.debug('getFlowByReceiverSenderFlowRate called with params:', {
...params,
subgraphUrl
});
const { networkId: _, ...whereParams } = params;
const response = await axios.post(subgraphUrl, {
query: getFlowsQuery,
variables: {
where: whereParams,
🧰 Tools
🪛 GitHub Check: test

[failure] 242-242:
'networkId' is assigned a value but never used

🪛 eslint

[error] 242-242: 'networkId' is assigned a value but never used.

(@typescript-eslint/no-unused-vars)

orderBy: 'timestamp',
orderDirection: 'asc',
},
Expand Down
4 changes: 3 additions & 1 deletion src/adapters/superFluid/superFluidAdapterInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,19 @@ export interface SuperFluidAdapterInterface {
currency: string;
recurringDonationTxHash: string;
}): Promise<any>;
accountBalance(accountId: string): Promise<any>;
accountBalance(accountId: string, networkId: number): Promise<any>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Interface missing networkId in one of the method definitions
The getFlowByReceiverSenderFlowRate method in the adapter now accepts networkId, but the interface doesn't match. This can lead to inconsistent usage.

Apply this diff to keep the interface in sync:

 export interface SuperFluidAdapterInterface {
   ...
   getFlowByReceiverSenderFlowRate(params: {
     receiver: string;
     sender: string;
     flowRate: string;
     timestamp_gt: number;
+    networkId: number;
   }): Promise<FlowUpdatedEvent | undefined>;
 }

Also applies to: 29-29

getFlowByTxHash(params: {
receiver: string;
sender: string;
flowRate: string;
transactionHash: string;
networkId: number;
}): Promise<FlowUpdatedEvent | undefined>;
getFlowByReceiverSenderFlowRate(params: {
receiver: string;
sender: string;
flowRate: string;
timestamp_gt: number;
networkId: number;
}): Promise<FlowUpdatedEvent | undefined>;
}
2 changes: 2 additions & 0 deletions src/adapters/superFluid/superFluidMockAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export class SuperFluidMockAdapter implements SuperFluidAdapterInterface {
sender: string;
flowRate: string;
timestamp_gt: number;
networkId: number;
}): Promise<FlowUpdatedEvent | undefined> {
return Promise.resolve(undefined);
}
Expand All @@ -94,6 +95,7 @@ export class SuperFluidMockAdapter implements SuperFluidAdapterInterface {
sender: string;
flowRate: string;
transactionHash: string;
networkId: number;
}): Promise<FlowUpdatedEvent | undefined> {
const { receiver, sender, flowRate, transactionHash } = params;
return Promise.resolve({
Expand Down
1 change: 1 addition & 0 deletions src/services/chains/evm/draftRecurringDonationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export async function matchDraftRecurringDonations(
timestamp_gt: convertTimeStampToSeconds(
draftRecurringDonation.createdAt.getTime(),
),
networkId: draftRecurringDonation.networkId,
};
const flow =
await superFluidAdapter.getFlowByReceiverSenderFlowRate(getFlowParams);
Expand Down
1 change: 1 addition & 0 deletions src/services/cronJobs/checkUserSuperTokenBalancesQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export const validateDonorSuperTokenBalance = async (

const accountBalances = await superFluidAdapter.accountBalance(
user.walletAddress!,
recurringDonation.networkId,
);

logger.debug(
Expand Down
1 change: 1 addition & 0 deletions src/services/recurringDonationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ export const updateRecurringDonationStatusWithNetwork = async (params: {
flowRate: recurringDonation.flowRate,
sender: recurringDonation?.donor?.walletAddress?.toLowerCase() as string,
transactionHash: recurringDonation.txHash,
networkId: recurringDonation.networkId,
});
if (!txData) {
throw new Error(
Expand Down
18 changes: 18 additions & 0 deletions test/graphqlQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2072,6 +2072,24 @@ export const removeSocialProfileMutation = `
}
`;

export const recurringDonationEligibleProjectsQuery = `
query (
networkId: Int
page: Int
limit: Int
) {
recurringDonationEligibleProjects {
id
slug
title
anchorContracts {
address
networkId
}
}
}
`;

export const getAllowedCountries = `
query {
getAllowedCountries {
Expand Down
Loading