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

Mmi 3924 implement new de fi adapter for uniswap v 3 in new repo #71

Merged

Conversation

jpsains
Copy link
Collaborator

@jpsains jpsains commented Oct 5, 2023

No description provided.

@jpsains jpsains requested a review from bergarces as a code owner October 5, 2023 11:32
@jpsains jpsains force-pushed the MMI-3924-implement-new-de-fi-adapter-for-uniswap-v-3-in-new-repo branch from e90f552 to 67b2812 Compare October 5, 2023 11:43
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this contract likely to be needed in future? It doesn't look like it's being used here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ill remove until its needed

})

const tokenIds = await Promise.all(
[...Array(Number(balanceOf)).keys()].map((index) =>
Copy link
Collaborator

Choose a reason for hiding this comment

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

This could result in a pretty big loop. We might want to come back to this eventually.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm unsure what the best policy would be here.

I'm pretty sure we could have a single async map that returns nonZeroPositions directly without looping three times with something like this.

const nonZeroPositions = await Promise.all(
      filterMap([...Array(Number(balanceOf)).keys()], async (index) => {
        const tokenId = await positionsManagerContract.tokenOfOwnerByIndex(
          userAddress,
          index,
          {
            blockTag: blockNumber,
          },
        )

        const position = await positionsManagerContract.positions(tokenId, {
          blockTag: blockNumber,
        })

        if (position.liquidity == 0n) {
          return undefined
        }

        return {
          liquidity: position.liquidity,
          token0: position.token0,
          token1: position.token1,
          fee: position.fee,
          tokenId: tokenIds[index],
        }
      }),
    )

I'm unsure whether it'll save any time at all. We would need to run profiling with users with a lot of positions.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually ignore my previous code. It won't work as filterMap doesn't work with promises.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ive implemented

bergarces
bergarces previously approved these changes Oct 5, 2023
@jpsains jpsains merged commit 5243bf6 into main Oct 9, 2023
1 check passed
@jpsains jpsains deleted the MMI-3924-implement-new-de-fi-adapter-for-uniswap-v-3-in-new-repo branch October 9, 2023 11:12
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