-
Notifications
You must be signed in to change notification settings - Fork 18
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
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 = ` | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -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: { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -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; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
const response = await axios.post(subgraphUrl, { | ||||||||||||||||||||||||||||||||||||||||||||||||||
query: getFlowsQuery, | ||||||||||||||||||||||||||||||||||||||||||||||||||
variables: { | ||||||||||||||||||||||||||||||||||||||||||||||||||
where: params, | ||||||||||||||||||||||||||||||||||||||||||||||||||
where: whereParams, | ||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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
Suggested change
🧰 Tools🪛 GitHub Check: test[failure] 211-211: 🪛 eslint[error] 211-211: 'networkId' is assigned a value but never used. (@typescript-eslint/no-unused-vars) |
||||||||||||||||||||||||||||||||||||||||||||||||||
orderBy: 'timestamp', | ||||||||||||||||||||||||||||||||||||||||||||||||||
orderDirection: 'asc', | ||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -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; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
const response = await axios.post(subgraphUrl, { | ||||||||||||||||||||||||||||||||||||||||||||||||||
query: getFlowsQuery, | ||||||||||||||||||||||||||||||||||||||||||||||||||
variables: { | ||||||||||||||||||||||||||||||||||||||||||||||||||
where: params, | ||||||||||||||||||||||||||||||||||||||||||||||||||
where: whereParams, | ||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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
Suggested change
🧰 Tools🪛 GitHub Check: test[failure] 242-242: 🪛 eslint[error] 242-242: 'networkId' is assigned a value but never used. (@typescript-eslint/no-unused-vars) |
||||||||||||||||||||||||||||||||||||||||||||||||||
orderBy: 'timestamp', | ||||||||||||||||||||||||||||||||||||||||||||||||||
orderDirection: 'asc', | ||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interface missing networkId in one of the method definitions 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>; | ||
} |
There was a problem hiding this comment.
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:
📝 Committable suggestion