Skip to content

Commit

Permalink
feat: accept rollup deployment block number for query (#239)
Browse files Browse the repository at this point in the history
  • Loading branch information
spsjvc authored Feb 14, 2025
1 parent c906634 commit ed742ea
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
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

0 comments on commit ed742ea

Please sign in to comment.