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

Fetch token rates in batches of 100 #3650

Merged
merged 8 commits into from
Dec 12, 2023
Merged

Conversation

mcmire
Copy link
Contributor

@mcmire mcmire commented Dec 12, 2023

Explanation

In cases where users have an enormous amount of tokens, we don't want to slow down our Price API with large requests. To combat this, when fetching token rates, send requests in batches of 100.

References

Fixes #3573.

Changelog

(Updated in PR)

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've highlighted breaking changes using the "BREAKING" category above as appropriate

In cases where users have an enormous amount of tokens, we don't want to
slow down our Price API with large requests. To combat this, when
fetching token rates, send requests in batches of 100.
@mcmire mcmire marked this pull request as ready for review December 12, 2023 16:06
@mcmire mcmire requested a review from a team as a code owner December 12, 2023 16:06
Gudahtt
Gudahtt previously approved these changes Dec 12, 2023
Copy link
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

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

LGTM!

packages/assets-controllers/src/assetsUtil.test.ts Outdated Show resolved Hide resolved
[tokenContractAddress]:
tokenPrice.value * fallbackCurrencyToNativeCurrencyConversionRate,
[tokenContractAddress]: tokenValue
? tokenValue * fallbackCurrencyToNativeCurrencyConversionRate
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, I don't totally follow why this additional branch was needed here. Is it now possible for tokenValue to be falsey?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Realistically, no, but because I've changed #fetchAndMapExchangeRatesForUnsupportedNativeCurrency to use #fetchAndMapExchangeRatesForSupportedNativeCurrency, contractExchangeRates is now a type of ContractExchangeRates, and that is defined as:

interface ContractExchangeRates {
  [address: string]: number | undefined;
}

So that means that tokenValue here is number | undefined.

Copy link
Member

@Gudahtt Gudahtt Dec 12, 2023

Choose a reason for hiding this comment

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

Interesting.... that | undefined seems like a mistake, I don't see a case where it is undefined.

Pre-existing issue though, and not a blocker, this doesn't really hurt

@mcmire mcmire merged commit e1ff173 into main Dec 12, 2023
136 checks passed
@mcmire mcmire deleted the fetch-token-rates-in-batches branch December 12, 2023 21:51
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.

[assets-controllers] Fetch token rates in batches to avoid hitting limits
2 participants