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: accept rollup deployment block number for query #239

Merged
merged 6 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/createRollupFetchCoreContracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,30 @@ import { createRollupFetchTransactionHash } from './createRollupFetchTransaction
import { createRollupPrepareTransactionReceipt } from './createRollupPrepareTransactionReceipt';

export type CreateRollupFetchCoreContractsParams<TChain extends Chain | undefined> = {
/**
* Address of the Rollup contract.
*/
rollup: Address;
/**
* Number of the block in which the Rollup contract was deployed.
*
* This parameter is used to reduce the span of blocks to query, so it doesn't have to be exactly the right block number.
* However, for the query to work properly, it has to be **less than or equal to** the right block number.
*/
rollupDeploymentBlockNumber?: bigint;
publicClient: PublicClient<Transport, TChain>;
};

export async function createRollupFetchCoreContracts<TChain extends Chain | undefined>({
rollup,
rollupDeploymentBlockNumber,
publicClient,
}: CreateRollupFetchCoreContractsParams<TChain>): Promise<CoreContracts> {
// getting core contract addresses
const transactionHash = await createRollupFetchTransactionHash({
rollup,
publicClient,
fromBlock: rollupDeploymentBlockNumber,
});

const transactionReceipt = createRollupPrepareTransactionReceipt(
Expand Down
15 changes: 15 additions & 0 deletions src/createTokenBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,21 @@ export type CreateTokenBridgeParams<
TParentChain extends Chain | undefined,
TOrbitChain extends Chain | undefined,
> = WithTokenBridgeCreatorAddressOverride<{
/**
* Owner of the Rollup contract.
*/
rollupOwner: Address;
/**
* Address of the Rollup contract.
*/
rollupAddress: Address;
/**
* Number of the block in which the Rollup contract was deployed.
*
* This parameter is used to reduce the span of blocks to query, so it doesn't have to be exactly the right block number.
* However, for the query to work properly, it has to be **less than or equal to** the right block number.
*/
rollupDeploymentBlockNumber?: bigint;
account: PrivateKeyAccount;
nativeTokenAddress?: Address;
parentChainPublicClient: PublicClient<Transport, TParentChain>;
Expand Down Expand Up @@ -161,6 +174,7 @@ export async function createTokenBridge<
>({
rollupOwner,
rollupAddress,
rollupDeploymentBlockNumber,
account,
nativeTokenAddress,
parentChainPublicClient,
Expand Down Expand Up @@ -274,6 +288,7 @@ export async function createTokenBridge<
// set weth gateway
const setWethGatewayTxRequest = await createTokenBridgePrepareSetWethGatewayTransactionRequest({
rollup: rollupAddress,
rollupDeploymentBlockNumber,
parentChainPublicClient,
orbitChainPublicClient,
account: account.address,
Expand Down
12 changes: 12 additions & 0 deletions src/createTokenBridgePrepareSetWethGatewayTransactionRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,17 @@ export type CreateTokenBridgePrepareRegisterWethGatewayTransactionRequestParams<
TOrbitChain extends Chain | undefined,
> = Prettify<
WithTokenBridgeCreatorAddressOverride<{
/**
* Address of the Rollup contract.
*/
rollup: Address;
/**
* Number of the block in which the Rollup contract was deployed.
*
* This parameter is used to reduce the span of blocks to query, so it doesn't have to be exactly the right block number.
* However, for the query to work properly, it has to be **less than or equal to** the right block number.
*/
rollupDeploymentBlockNumber?: bigint;
parentChainPublicClient: PublicClient<Transport, TParentChain>;
orbitChainPublicClient: PublicClient<Transport, TOrbitChain>;
account: Address;
Expand Down Expand Up @@ -97,6 +107,7 @@ export async function createTokenBridgePrepareSetWethGatewayTransactionRequest<
TOrbitChain extends Chain | undefined,
>({
rollup,
rollupDeploymentBlockNumber,
parentChainPublicClient,
orbitChainPublicClient,
account,
Expand Down Expand Up @@ -149,6 +160,7 @@ export async function createTokenBridgePrepareSetWethGatewayTransactionRequest<

const rollupCoreContracts = await createRollupFetchCoreContracts({
rollup,
rollupDeploymentBlockNumber,
publicClient: parentChainPublicClient,
});

Expand Down
Loading