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

Onchain data fetching refactor #524

Merged
merged 10 commits into from
Nov 17, 2023
Merged

Onchain data fetching refactor #524

merged 10 commits into from
Nov 17, 2023

Conversation

gmbronco
Copy link
Contributor

@gmbronco gmbronco commented Nov 9, 2023

  • separating data fetching and parsing from database logic
  • splitting into separate responsibilities (state, data, gyro)
  • fixing protocol fee for pools in recovery - should be 0
  • fixing BPT price rate

* simpler data fetching and parsing
* splitting into separate responsibilities (state, data, gyro)
* fixing protocol fee for pools in recovery - should be 0
* fixing BPT price rate
Comment on lines 86 to 88
multicaller.call(`${id}.totalSupply`, address, 'totalSupply');
multicaller.call(`${id}.virtualSupply`, address, 'getVirtualSupply');
multicaller.call(`${id}.actualSupply`, address, 'getActualSupply');
Copy link
Contributor

Choose a reason for hiding this comment

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

I would move these to the pool type specific queries, otherwise its an extra 2 queries per pool that will either fail or are not needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that's the part where we need to know the composable stable pool type, which depends on adding logic based on the factory address. i understand we don't need overfetching, but we fetch so much already that the cost is marginal. i tested both versions (this vs previous) and there is no perfomance impact.

multicaller.call(`${id}.actualSupply`, address, 'getActualSupply');
multicaller.call(`${id}.swapFee`, address, getSwapFeeFn(type));
multicaller.call(`${id}.rate`, address, 'getRate');
multicaller.call(`${id}.protocolYieldFeePercentageCache`, address, 'getProtocolFeePercentageCache', [2]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, but I dont see a way to have this without relying on the network context :)


tokens.forEach(({ address: tokenAddress }, i) => {
multicaller.call(`${id}.tokenRate[${i}]`, address, 'getTokenRate', [tokenAddress]);
multicaller.call(`${id}.metaPriceRateCache[${i}]`, address, 'getPriceRateCache', [tokenAddress]);
Copy link
Contributor

Choose a reason for hiding this comment

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

same as above

Comment on lines 168 to 169
tokens: result.poolTokens[0].map((t) => t.toLocaleLowerCase()),
balances: result.poolTokens[1].map((w, i) => formatUnits(w, decimalsLookup[result.poolTokens[0][i].toLocaleLowerCase()])),
Copy link
Contributor

Choose a reason for hiding this comment

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

can you change toLocaleLowerCase() to toLowerCase()? Just avoid any side effects

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch

weights: result.weights?.map(formatEther),
targets: result.targets?.map(String),
poolTokens: result.poolTokens ? {
tokens: result.poolTokens[0].map((t) => t.toLocaleLowerCase()),
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm a fan of writing complete words for variables, we don't need to save any bytes :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure!

}
if (multicallResult[pool.id] && multicallResult[pool.id].pausedState) {
isPaused = multicallResult[pool.id].pausedState.paused;
}
operations.push(
prisma.prismaPoolDynamicData.update({
where: { id_chain: { id: pool.id, chain: networkContext.chain } },
Copy link
Contributor

Choose a reason for hiding this comment

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

any chance we could also get rid of the network context while we're refactoring that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point, moving it up to the pool service

@franzns franzns merged commit 3028b15 into v3-canary Nov 17, 2023
1 check passed
@franzns franzns deleted the onchain-data branch November 17, 2023 12:32
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