Skip to content

improve: implement a common interface in sdk providers #932

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

bmzig
Copy link
Contributor

@bmzig bmzig commented Mar 21, 2025

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.

provider.getBlock(earliestBlockNumber),
provider.getBlock(highBlock),
]);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unsafe cast here. Marking as need to change.

Signed-off-by: bennett <[email protected]>
@@ -0,0 +1,5 @@
export interface CrosschainProvider {
getBlock(blockTag: number | string): Promise<unknown>;
Copy link
Contributor

Choose a reason for hiding this comment

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

getTransactionCount is another one that seems to be common.

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, {});
}
Copy link
Contributor

@pxrl pxrl Mar 24, 2025

Choose a reason for hiding this comment

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

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, {});
}

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