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

BLOCK-40: add SDK functions for chainsaw #4004

Closed
wants to merge 47 commits into from

Conversation

iuwqyir
Copy link
Contributor

@iuwqyir iuwqyir commented Aug 8, 2024

Problem solved

Added the following chainsaw methods to the SDK

  • getLatestBlockNumber
  • getEvents
  • getBlock
  • getNFTsByCollection
  • getNFTsByOwner
  • getTransactions

NB! Will continue the comments & changes from this PR here

  1. this should be split into 2 parts (stack it?): SDK changes + dashboard changes - makes reviewing easier and we can ship it incrementally -- ✅
  2. note to self to add a lint rule to enforce avoiding const foo () => .... function definitions whenever possible (mostly style) -- ✅ removed const functions
  3. do not use .d.ts files if u do not have to - ✅ Changed
  4. consider chainsaw support - any "sdk method" that is not clearly a "chainsaw" method has to work across all EVM chain (looking at useOwnedNFTs()) -- 🔴 not relevant in this PR
  5. is production deployed? If we merge this will it work? - ✅ Yes it's in prod
  6. can we add some tests to formatting etc? - ✅ Added tests in d0f26f8
  7. can we find a way to use the same return types for "block" "transaction" etc that are returned from existing SDK methods? - 🟡 They basically are returning the same data (Transactions just has some extra on top). But since I was told we can't return Viem types directly, I ported them to custom types

PR-Codex overview

This PR adds chain ID and contract address to NFT retrieval functions, introduces indexer endpoints, and updates domain URLs.

Detailed summary

  • Added chainId and contractAddress to NFT retrieval functions
  • Introduced new indexer endpoints for block, transactions, and events
  • Updated domain URLs for chainsaw server
  • Added chainId and contractAddress to NFT parsing options

The following files were skipped due to too many changes: packages/thirdweb/src/indexer/urls.ts, packages/thirdweb/src/indexer/endpoints/getNFTsByOwner.test.ts, packages/thirdweb/src/indexer/endpoints/getContractTransactions.test.ts, packages/thirdweb/src/indexer/endpoints/getNFTsByCollection.test.ts, packages/thirdweb/src/indexer/types.ts, .changeset/swift-spoons-act.md, packages/thirdweb/src/indexer/endpoints/getLatestBlockNumber.ts, packages/thirdweb/src/indexer/endpoints/getNFTsByCollection.ts, packages/thirdweb/src/indexer/endpoints/getBlock.ts, packages/thirdweb/src/indexer/endpoints/getNFTsByOwner.ts, packages/thirdweb/src/indexer/endpoints/getEvents.ts, packages/thirdweb/src/indexer/endpoints/getContractTransactions.ts, packages/thirdweb/src/indexer/formatter.ts

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Copy link

changeset-bot bot commented Aug 8, 2024

🦋 Changeset detected

Latest commit: 920ad00

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

This PR includes changesets to release 1 package
Name Type
thirdweb Minor

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

Copy link

linear bot commented Aug 8, 2024

Copy link

vercel bot commented Aug 8, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs-v2 ❌ Failed (Inspect) Aug 14, 2024 8:57pm
thirdweb_playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 14, 2024 8:57pm
thirdweb-www ❌ Failed (Inspect) Aug 14, 2024 8:57pm
wallet-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 14, 2024 8:57pm

Copy link
Contributor Author

iuwqyir commented Aug 8, 2024

Copy link
Contributor

github-actions bot commented Aug 8, 2024

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
thirdweb (esm) 44.06 KB (+2.19% 🔺) 882 ms (+2.19% 🔺) 924 ms (+52.6% 🔺) 1.9 s
thirdweb (cjs) 93.42 KB (+1.4% 🔺) 1.9 s (+1.4% 🔺) 1.3 s (-20% 🔽) 3.2 s
thirdweb (minimal + tree-shaking) 4.82 KB (+0.23% 🔺) 97 ms (+0.23% 🔺) 46 ms (+41.89% 🔺) 142 ms
thirdweb/chains (tree-shaking) 498 B (+1.22% 🔺) 10 ms (0%) 14 ms (-67.28% 🔽) 24 ms
thirdweb/react (minimal + tree-shaking) 13.97 KB (+0.09% 🔺) 280 ms (+0.09% 🔺) 108 ms (+6.47% 🔺) 387 ms

Copy link

graphite-app bot commented Aug 8, 2024

Your org requires the Graphite merge queue for merging into main

Add the label “merge-queue” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge. Or use the label “hotfix” to add to the merge queue as a hot fix.

You must have a Graphite account and log in to Graphite in order to use the merge queue. Sign up using this link.

Copy link
Member

@gregfromstl gregfromstl left a comment

Choose a reason for hiding this comment

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

Code looks great! Just some comments on typedocs and types

packages/thirdweb/src/chainsaw/endpoints/getEvents.ts Outdated Show resolved Hide resolved
packages/thirdweb/src/chainsaw/endpoints/getNFTsByOwner.ts Outdated Show resolved Hide resolved
packages/thirdweb/src/chainsaw/formatter.ts Outdated Show resolved Hide resolved
packages/thirdweb/src/chainsaw/formatter.ts Outdated Show resolved Hide resolved
packages/thirdweb/src/chainsaw/paging.ts Outdated Show resolved Hide resolved
packages/thirdweb/src/chainsaw/types.ts Outdated Show resolved Hide resolved
@gregfromstl gregfromstl force-pushed the chainsaw-sdk-functions/BLOCK-40 branch from 660bb3b to 8fed67a Compare August 13, 2024 22:06
client,
chain: defineChain(1)
});
const events = await getEvents({
Copy link
Member

Choose a reason for hiding this comment

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

should we build this into the existing getContractEvents that we have?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah we should. Right now the indexer gets events based on start and end time though and getContractEvents does it based on block numbers. Let me ask if we can add block number filter options on the indexer, but we won't be able to fallback to RPC call when filtering by times

* });
* ```
*/
export async function getEvents(
Copy link
Member

Choose a reason for hiding this comment

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

i think if you call this inside getContractEvents() and the formats match it should do the decoding for you

type GetNFTsByCollectionParams,
} from "../indexer/endpoints/getNFTsByCollection.js";
export {
getNFTsByOwner,
Copy link
Member

Choose a reason for hiding this comment

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

getWalletBalance
getWalletNFTs
getWalletTokens

extensions/erc721/getOwnedNFTs
extensions/erc1155/getOwnedNFTs

type GetBlockParams,
} from "../indexer/endpoints/getBlock.js";
export {
getLatestBlockNumber,
Copy link
Member

@joaquim-verges joaquim-verges Aug 14, 2024

Choose a reason for hiding this comment

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

dont expose block functions

type GetLatestBlockNumberParams,
} from "../indexer/endpoints/getLatestBlockNumber.js";
export {
getNFTsByCollection,
Copy link
Member

Choose a reason for hiding this comment

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

should just be injected inside

extensions/erc721/getNFTs
extensions/erc1155/getNFTs

type GetNFTsByOwnerParams,
} from "../indexer/endpoints/getNFTsByOwner.js";
export {
getContractTransactions,
Copy link
Member

Choose a reason for hiding this comment

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

this one is good as is

* const block = await getContractTransactions({
* contract,
* pageSize: 20,
* page: 1
Copy link
Member

Choose a reason for hiding this comment

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

change to start and count

@jnsdls jnsdls closed this Aug 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DO NOT MERGE This pull request is still in progress and is not ready to be merged. TS SDK Involves changes to the v5 TypeScript SDK.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants