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

feat: integrate BSC Core pool subgraph #3942

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

gleiser-oliveira
Copy link
Contributor

Jira ticket(s)

VEN-3078

Changes

  • Added the BSC Core Pool subraph, it is now used to unify fetching the counts of borrowers and suppliers along with the isolated pools

Copy link

changeset-bot bot commented Feb 26, 2025

🦋 Changeset detected

Latest commit: 2e386e4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@venusprotocol/evm Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Feb 26, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
app.venus.io ✅ Ready (Inspect) Visit Preview Feb 26, 2025 1:25pm
dapp-preview ✅ Ready (Inspect) Visit Preview Feb 26, 2025 1:25pm
dapp-testnet ✅ Ready (Inspect) Visit Preview Feb 26, 2025 1:25pm
venus.io ✅ Ready (Inspect) Visit Preview Feb 26, 2025 1:25pm

Copy link
Contributor

Coverage Report for ./apps/evm

Status Category Percentage Covered / Total
🔵 Lines 81.66% 41747 / 51120
🔵 Statements 81.66% 41747 / 51120
🔵 Functions 71.54% 948 / 1325
🔵 Branches 88.93% 6135 / 6898
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
apps/evm/src/clients/api/queries/useGetPools/getPools/index.ts 99.18% 95.65% 100% 99.18% 95
apps/evm/src/clients/api/queries/useGetPools/getPools/formatOutput/index.ts 99.09% 94.44% 100% 99.09% 61-62
apps/evm/src/clients/api/queries/useGetPools/getPools/getApiPools/index.ts 65.21% 42.85% 100% 65.21% 94-101, 104-111
apps/evm/src/clients/api/queries/useGetPools/getPools/getParticipantCounts/index.ts 100% 71.42% 100% 100%
apps/evm/src/clients/api/queries/useGetPools/getPools/safeGetParticipantCounts/index.ts 58.33% 50% 100% 58.33% 17-23
apps/evm/src/clients/subgraph/index.ts 100% 100% 100% 100%
apps/evm/src/clients/subgraph/queries/bscCorePool/getBscCorePoolParticipantsCount/index.ts 28.57% 100% 0% 28.57% 12-16
apps/evm/src/config/index.ts 100% 0% 100% 100%
apps/evm/src/config/subgraphUrls.ts 100% 100% 100% 100%
Generated in workflow #10160 for commit 2e386e4 by the Vitest Coverage Report Action

@@ -1090,7 +1090,7 @@ exports[`useGetPools > returns pools with time based reward rates in the correct
"liquidityCents": "1.000006200805040439464388948970138750743214608e+23",
"reserveFactor": 1,
"reserveTokens": "0",
"supplierCount": 10,
"supplierCount": 0,
Copy link
Member

Choose a reason for hiding this comment

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

It looks like this isn't getting mocked

Comment on lines +9 to +30
const participantsCountMap = new Map<string, MarketParticipantsCounts>();
if (chainId === ChainId.BSC_MAINNET || chainId === ChainId.BSC_TESTNET) {
const bscCorePoolParticipantsCount = await getBscCorePoolParticipantsCount({ chainId });
(bscCorePoolParticipantsCount?.markets || []).forEach(market => {
participantsCountMap.set(market.id.toLowerCase(), {
borrowerCount: +market.borrowerCount,
supplierCount: +market.supplierCount,
});
});

const isolatedPoolParticipantsCount = await getIsolatedPoolParticipantsCount({ chainId });
(isolatedPoolParticipantsCount?.pools || []).forEach(pool =>
pool.markets.forEach(market => {
participantsCountMap.set(market.id.toLowerCase(), {
borrowerCount: +market.borrowerCount,
supplierCount: +market.supplierCount,
});
}),
);

return { participantsCountMap };
}
Copy link
Member

Choose a reason for hiding this comment

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

The IF condition means participants counts will only be fetched on BNB Chain mainnet and testnet, while I believe what you want is to call getBscCorePoolParticipantsCount only on those chains instead. You can also batch the two requests in a Promise.allSettled (and not a Promise.all, so that all calls are completed even if some fail) call and make the code a bit more DRY:

Suggested change
const participantsCountMap = new Map<string, MarketParticipantsCounts>();
if (chainId === ChainId.BSC_MAINNET || chainId === ChainId.BSC_TESTNET) {
const bscCorePoolParticipantsCount = await getBscCorePoolParticipantsCount({ chainId });
(bscCorePoolParticipantsCount?.markets || []).forEach(market => {
participantsCountMap.set(market.id.toLowerCase(), {
borrowerCount: +market.borrowerCount,
supplierCount: +market.supplierCount,
});
});
const isolatedPoolParticipantsCount = await getIsolatedPoolParticipantsCount({ chainId });
(isolatedPoolParticipantsCount?.pools || []).forEach(pool =>
pool.markets.forEach(market => {
participantsCountMap.set(market.id.toLowerCase(), {
borrowerCount: +market.borrowerCount,
supplierCount: +market.supplierCount,
});
}),
);
return { participantsCountMap };
}
const participantsCountMap = new Map<string, MarketParticipantsCounts>();
const [isolatedPoolParticipantsCountsResult, bscCorePoolParticipantsCountsResult] =
await Promise.allSettled([
getIsolatedPoolParticipantsCount({ chainId }),
chainId === ChainId.BSC_MAINNET || chainId === ChainId.BSC_TESTNET
? getBscCorePoolParticipantsCount({ chainId })
: undefined,
]);
if (isolatedPoolParticipantsCountsResult.status === 'rejected') {
logError(isolatedPoolParticipantsCountsResult.reason);
}
if (bscCorePoolParticipantsCountsResult.status === 'rejected') {
logError(bscCorePoolParticipantsCountsResult.reason);
}
const isolatedPoolParticipantsCounts = (
extractSettledPromiseValue(isolatedPoolParticipantsCountsResult)?.pools || []
).flatMap(p => p.markets);
const bscCorePoolParticipantsCounts =
extractSettledPromiseValue(bscCorePoolParticipantsCountsResult)?.markets || [];
[...isolatedPoolParticipantsCounts, ...bscCorePoolParticipantsCounts].forEach(market => {
participantsCountMap.set(market.id.toLowerCase(), {
borrowerCount: +market.borrowerCount,
supplierCount: +market.supplierCount,
});
});
return { participantsCountMap };

Since this code uses Promise.allSettled, you would be able to remove the safeGetParticipantCounts function.

Comment on lines +14 to +22
// Safari throws a "TypeError: Load failed" error if the fetch is canceled
// e.g., if the user navigates away from the page before the request is finished
// we can safely filter them out from being logged
if (error instanceof Error && error.name === 'TypeError' && error.message === 'Load failed') {
return undefined;
}
// Log error without throwing to prevent the entire query from failing, since this relies on a
// third-party service that could be down and doesn't constitute a critical failure
logError(error);
Copy link
Member

Choose a reason for hiding this comment

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

I was thinking about this more; how about the IF condition directly inside the logError function? This way we'll apply this filter to all errors sent from the dApp.

Comment on lines +18 to 20
export const getBscCorePoolParticipantsCount = vi.fn(async () => bscCorePoolParticipantsCount);

export const getIsolatedPoolParticipantsCount = vi.fn();
Copy link
Member

Choose a reason for hiding this comment

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

I'd suggest mocking the calls made to fetch participant counts the same way (with the current approach, getIsolatedPoolParticipantsCount is mocked to returned undefined and its returned value is later mocked in the tests directly, while getBscCorePoolParticipantsCount is mocked to returned values).

It might be useful to dynamically mock the returned values based on the __mocks__/api/pools.json file content, since it's what we use as mock data throughout tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants