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

feat(lens): update validation method #463

Merged
merged 19 commits into from
Jul 1, 2024
Merged

feat(lens): update validation method #463

merged 19 commits into from
Jul 1, 2024

Conversation

mmackz
Copy link
Collaborator

@mmackz mmackz commented Jun 25, 2024

  • updates validation method to use NFT apis

After checking through several api providers, the best suited one is blockspan, as it has the needed lookup for our usecase, and it has generous rate-limits available. It does require an api key, so we will need to set up an environment variable.

Choose to use Alchemy SDK instead of blockspan due to high latency for the api to index new mints transactions.

Reservoir api will be used as a backup option in case blockspan alchemy goes down or gets rate-limited. Reservoir does not require an API key, but adding one would increase the limits.

There is minimal latency using this method, with most requests taking between 600-1000ms, which is around the same as the previous validation methods.

Will need to add the BLOCKSPAN_API_KEY to heroku.

We already have an ALCHEMY_API_KEY available, so no new env variables are required.

@mmackz mmackz requested a review from a team as a code owner June 25, 2024 20:50
Copy link

changeset-bot bot commented Jun 25, 2024

🦋 Changeset detected

Latest commit: 645e14a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 52 packages
Name Type
@rabbitholegg/questdk-plugin-utils Minor
@rabbitholegg/questdk-plugin-lens Minor
@rabbitholegg/questdk-plugin-across Patch
@rabbitholegg/questdk-plugin-aerodrome Patch
@rabbitholegg/questdk-plugin-artblocks Patch
@rabbitholegg/questdk-plugin-balancer Patch
@rabbitholegg/questdk-plugin-base Patch
@rabbitholegg/questdk-plugin-basepaint Patch
@rabbitholegg/questdk-plugin-boost Patch
@rabbitholegg/questdk-plugin-camelot Patch
@rabbitholegg/questdk-plugin-connext Patch
@rabbitholegg/questdk-plugin-fabric Patch
@rabbitholegg/questdk-plugin-foundation Patch
@rabbitholegg/questdk-plugin-gmx Patch
@rabbitholegg/questdk-plugin-handlefi Patch
@rabbitholegg/questdk-plugin-hop Patch
@rabbitholegg/questdk-plugin-hyphen Patch
@rabbitholegg/questdk-plugin-jojo Patch
@rabbitholegg/questdk-plugin-kote Patch
@rabbitholegg/questdk-plugin-kwenta Patch
@rabbitholegg/questdk-plugin-llama Patch
@rabbitholegg/questdk-plugin-manifold Patch
@rabbitholegg/questdk-plugin-mirror Patch
@rabbitholegg/questdk-plugin-moshicam Patch
@rabbitholegg/questdk-plugin-mux Patch
@rabbitholegg/questdk-plugin-neynar Patch
@rabbitholegg/questdk-plugin-okutrade Patch
@rabbitholegg/questdk-plugin-optimism Patch
@rabbitholegg/questdk-plugin-orbit Patch
@rabbitholegg/questdk-plugin-paragraph Patch
@rabbitholegg/questdk-plugin-paraswap Patch
@rabbitholegg/questdk-plugin-pendle Patch
@rabbitholegg/questdk-plugin-pods Patch
@rabbitholegg/questdk-plugin-polygon Patch
@rabbitholegg/questdk-plugin-rabbithole Patch
@rabbitholegg/questdk-plugin-registry Patch
@rabbitholegg/questdk-plugin-soundxyz Patch
@rabbitholegg/questdk-plugin-stargate Patch
@rabbitholegg/questdk-plugin-superbridge Patch
@rabbitholegg/questdk-plugin-sushi Patch
@rabbitholegg/questdk-plugin-symbiosis Patch
@rabbitholegg/questdk-plugin-synapse Patch
@rabbitholegg/questdk-plugin-tally Patch
@rabbitholegg/questdk-plugin-thirdweb Patch
@rabbitholegg/questdk-plugin-thruster Patch
@rabbitholegg/questdk-plugin-titles Patch
@rabbitholegg/questdk-plugin-traderjoe Patch
@rabbitholegg/questdk-plugin-treasure Patch
@rabbitholegg/questdk-plugin-uniswap Patch
@rabbitholegg/questdk-plugin-vela Patch
@rabbitholegg/questdk-plugin-woofi Patch
@rabbitholegg/questdk-plugin-zora Patch

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

) {
try {
return await checkMintedUsingBlockspan(actor, collectAddress)
} catch {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

how to deal with error handling here?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

@mmackz mmackz Jun 25, 2024

Choose a reason for hiding this comment

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

It should be caught here and a ValidationNotValid is thrown. Is that okay or should I move this logic into the validateCollect function.

import { getClient } from './client'
import { Chains } from '@rabbitholegg/questdk-plugin-utils'
import axios from 'axios'
import dotenv from 'dotenv'
Copy link
Member

Choose a reason for hiding this comment

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

Just use process.env directly as done here and see if that works.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Tried using process.env directly and it did not work. It logs as undefined.

But obviously it has worked for neynar package, so Im a bit confused 🫤

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it worked in Neynar because there was a check for process.env

if (!process.env.NEYNAR_API_KEY) throw new Error('Neynar API key not found')

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Did some more testing here, and it looks like as long as you have the environment variable in the RH repo .env file, it will be picked up in the plugin-validator. Ive removed the dotenv file from the lens package, since it is not needed.

CleanShot 2024-06-27 at 11 12 09@2x

@mmackz
Copy link
Collaborator Author

mmackz commented Jun 27, 2024

@Quazia I got the ENV situation sorted out. It should just work as long as we have the ENV variable in the backend repo. I removed the dotenv as a dependancy in the lens package.

I also added the ValidationNotValid error to the utils package and imported it form there. I feel it will be useful to have it in the utils for any other plugins that will use this validation type. wdyt?

@mmackz
Copy link
Collaborator Author

mmackz commented Jun 27, 2024

Blockscan not reliable. It does not update fast enough. Took roughly 5 minutes for it to pick up the collect

@mmackz
Copy link
Collaborator Author

mmackz commented Jun 28, 2024

Switched to use Alchemy SDK. It is appears to be extremely fast to pick up and index fresh mint transactions and is quite responsive. Another benefit of using alchemy is that we already have an api key environment variable available.

Pretty happy with the results.

@mmackz mmackz requested review from Quazia and jonathandiep June 28, 2024 00:22
const settings = {
apiKey: process.env.ALCHEMY_API_KEY,
network: Network.MATIC_MAINNET,
requestTimeout: 2000,
Copy link
Collaborator Author

@mmackz mmackz Jun 28, 2024

Choose a reason for hiding this comment

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

It isn't required, but I put an arbitrary value as the requestTimeout. Thought was to let it timeout soonish and hit the reservoir backup. I couldn't find the default value and didn't want it to hang for too long.

Not sure if this is too much or too little.

)

// only count nfts that originate from zeroAddress
const mintedNfts = transfers.nfts.filter((nft) => nft.from === zeroAddress)
Copy link
Member

Choose a reason for hiding this comment

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

Clever - you know we could actually handle this just with the contract Transfer events. Just ship this implementation though that's hilarious it's full circle though.

@mmackz mmackz merged commit 82c29a9 into main Jul 1, 2024
9 checks passed
@github-actions github-actions bot mentioned this pull request Jul 1, 2024
@mmackz mmackz deleted the mmackz/lens-collect branch July 2, 2024 16:23
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.

3 participants