Skip to content

improve: implement a common interface in sdk providers#932

Closed
bmzig wants to merge 2 commits intomasterfrom
bz/commonProvider
Closed

improve: implement a common interface in sdk providers#932
bmzig wants to merge 2 commits intomasterfrom
bz/commonProvider

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.

Signed-off-by: bennett <bennett@umaproject.org>
const [firstBlock, lastBlock] = (await Promise.all([
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 <bennett@umaproject.org>
@@ -0,0 +1,5 @@
export interface CrosschainProvider {
getBlock(blockTag: number | string): Promise<unknown>;
Copy link
Collaborator

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
Collaborator

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

@bmzig bmzig closed this May 12, 2025
@bmzig bmzig deleted the bz/commonProvider branch May 12, 2025 22:18
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