-
Notifications
You must be signed in to change notification settings - Fork 79
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
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 2e386e4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@@ -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, |
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.
It looks like this isn't getting mocked
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 }; | ||
} |
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.
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:
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.
// 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); |
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.
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.
export const getBscCorePoolParticipantsCount = vi.fn(async () => bscCorePoolParticipantsCount); | ||
|
||
export const getIsolatedPoolParticipantsCount = vi.fn(); |
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.
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.
Jira ticket(s)
VEN-3078
Changes