Skip to content

Commit

Permalink
done
Browse files Browse the repository at this point in the history
  • Loading branch information
spsjvc committed Sep 26, 2024
1 parent 8ad5963 commit 50085c1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
16 changes: 14 additions & 2 deletions src/createRollupGetCallValue.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { Chain, PublicClient, Transport } from 'viem';

import { CreateRollupParams } from './types/createRollupTypes';
import { isCustomFeeTokenAddress } from './utils/isCustomFeeTokenAddress';
import { createRollupDefaultRetryablesFees } from './constants';
import { createRollupGetRetryablesFees } from './createRollupGetRetryablesFees';

export function createRollupGetCallValue(params: CreateRollupParams) {
export async function createRollupGetCallValue<TChain extends Chain | undefined>(
publicClient: PublicClient<Transport, TChain>,
params: CreateRollupParams,
): Promise<bigint> {
// when not deploying deterministic factories to L2, no callvalue is necessary, as no retryable tickets will be created
if (!params.deployFactoriesToL2) {
return BigInt(0);
Expand All @@ -13,5 +19,11 @@ export function createRollupGetCallValue(params: CreateRollupParams) {
return BigInt(0);
}

return createRollupDefaultRetryablesFees;
try {
return await createRollupGetRetryablesFees(publicClient, params);
} catch (error) {
// todo: update message
console.error('failed to fetch retryables fees, falling back to defaults');
return createRollupDefaultRetryablesFees;
}
}
10 changes: 5 additions & 5 deletions src/createRollupGetRetryablesFees.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PublicClient, Address } from 'viem';
import { Chain, PublicClient, Transport, Address } from 'viem';

import { rollupCreatorABI } from './contracts/RollupCreator';
import { getRollupCreatorAddress } from './utils/getRollupCreatorAddress';
Expand Down Expand Up @@ -47,14 +47,14 @@ const bridgeCreatorABI = [
},
] as const;

type Params = {
export type CreateRollupGetRetryablesFeesParams = {
nativeToken?: Address;
maxFeePerGasForRetryables?: bigint;
};

export async function createRollupGetRetryablesFees(
publicClient: PublicClient,
{ nativeToken, maxFeePerGasForRetryables }: Params,
export async function createRollupGetRetryablesFees<TChain extends Chain | undefined>(
publicClient: PublicClient<Transport, TChain>,
{ nativeToken, maxFeePerGasForRetryables }: CreateRollupGetRetryablesFeesParams,
): Promise<bigint> {
const [deployHelperAddress, bridgeCreatorAddress] = await Promise.all([
publicClient.readContract({
Expand Down
2 changes: 1 addition & 1 deletion src/createRollupPrepareTransactionRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export async function createRollupPrepareTransactionRequest<TChain extends Chain
chain: publicClient.chain,
to: rollupCreatorAddressOverride ?? getRollupCreatorAddress(publicClient),
data: createRollupEncodeFunctionData([paramsWithDefaults]),
value: createRollupGetCallValue(paramsWithDefaults),
value: createRollupGetCallValue(publicClient, paramsWithDefaults),
account,
// if the base gas limit override was provided, hardcode gas to 0 to skip estimation
// we'll set the actual value in the code below
Expand Down

0 comments on commit 50085c1

Please sign in to comment.