improve: implement a common interface in sdk providers#932
Closed
improve: implement a common interface in sdk providers#932
Conversation
Signed-off-by: bennett <bennett@umaproject.org>
bmzig
commented
Mar 21, 2025
| const [firstBlock, lastBlock] = (await Promise.all([ | ||
| provider.getBlock(earliestBlockNumber), | ||
| provider.getBlock(highBlock), | ||
| ]); |
Contributor
Author
There was a problem hiding this comment.
Unsafe cast here. Marking as need to change.
pxrl
reviewed
Mar 24, 2025
| @@ -0,0 +1,5 @@ | |||
| export interface CrosschainProvider { | |||
| getBlock(blockTag: number | string): Promise<unknown>; | |||
Collaborator
There was a problem hiding this comment.
getTransactionCount is another one that seems to be common.
pxrl
reviewed
Mar 24, 2025
Comment on lines
+70
to
+80
| async getBlock(blockNumber: string | number): Promise<unknown> { | ||
| // TODO: Support other evm block tags. | ||
| let slot; | ||
| try { | ||
| slot = BigInt(blockNumber); | ||
| } catch { | ||
| // Assume block tag = "latest"; | ||
| slot = BigInt(await this.getBlockNumber()); | ||
| } | ||
| return this.rateLimitedRpcClient.getBlock(slot, {}); | ||
| } |
Collaborator
There was a problem hiding this comment.
This could be simplified by narrowing the string type.
Suggested change
| async getBlock(blockNumber: string | number): Promise<unknown> { | |
| // TODO: Support other evm block tags. | |
| let slot; | |
| try { | |
| slot = BigInt(blockNumber); | |
| } catch { | |
| // Assume block tag = "latest"; | |
| slot = BigInt(await this.getBlockNumber()); | |
| } | |
| return this.rateLimitedRpcClient.getBlock(slot, {}); | |
| } | |
| async getBlock(blockNumber: number | "latest"): Promise<unknown> { | |
| const slot = blockNumber === "latest" | |
| ? BigInt(await this.getBlockNumber()) | |
| : BigInt(blockNumber); | |
| return this.rateLimitedRpcClient.getBlock(slot, {}); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ideally we can make custom implementations for our providers (e.g.
speedProvider) and also make providers for other networks (e.g. a Solana provider) while still using a common utility type (e.g. BlockFinder). I think a good way to achieve this is to extend these providers from a common interface and start utilizing generic types more.