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

Uniswap registry fetch using all pairs by default #30

Closed
wants to merge 1 commit into from

Conversation

diwu1989
Copy link
Contributor

Uniswap registry was using pairwise combination to fetch pairs by default:
if (!this.opts?.fetchUsingAllPairs), fetchUsingAllPairs === undefined and negated become true

Given the number of tokens in the default token whitelist is pretty large now, this causes over 2k calls into the factory.

The actual number of pairs created by the factories are a lot smaller:

ubeswap nPairs 548
sushiswap nPairs 146
celodex nPairs 28

We can save the calls if we default fetchUsingAllPairs to true

@@ -26,7 +26,7 @@ export class RegistryUniswapV2 extends Registry {

findPairs = async (tokenWhitelist: Address[]): Promise<Pair[]> => {
let pairsFetched
if (!this.opts?.fetchUsingAllPairs) {
if (this.opts?.fetchUsingAllPairs === false) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

unless fetchUsingAllPairs is not undefined and is explicitly set to false
we will use using the allPairsLength and allPairs factory methods

@zviadm
Copy link
Collaborator

zviadm commented Jun 20, 2022

I just changed name of the flag and made it default to false

@zviadm zviadm closed this Jun 20, 2022
@diwu1989 diwu1989 deleted the fixFetchAllPairs branch June 21, 2022 04:18
@diwu1989
Copy link
Contributor Author

I see, i like the new var name better

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