Skip to content

Commit

Permalink
add nice type
Browse files Browse the repository at this point in the history
  • Loading branch information
spsjvc committed Feb 26, 2024
1 parent 8e8f3c3 commit f321549
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 19 deletions.
17 changes: 11 additions & 6 deletions src/createRollupEnoughCustomFeeTokenAllowance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,22 @@ import { rollupCreator } from './contracts';
import { validParentChainId } from './types/ParentChain';
import { fetchAllowance } from './utils/erc20';
import { createRollupDefaultRetryablesFees } from './constants';
import { WithRollupCreatorAddressOverride } from './createRollupTypes';
import { Prettify } from './types/utils';

export type CreateRollupEnoughCustomFeeTokenAllowanceParams = {
nativeToken: Address;
account: Address;
publicClient: PublicClient;
};
export type CreateRollupEnoughCustomFeeTokenAllowanceParams = Prettify<
WithRollupCreatorAddressOverride<{
nativeToken: Address;
account: Address;
publicClient: PublicClient;
}>
>;

export async function createRollupEnoughCustomFeeTokenAllowance({
nativeToken,
account,
publicClient,
rollupCreatorAddressOverride,
}: CreateRollupEnoughCustomFeeTokenAllowanceParams) {
const chainId = publicClient.chain?.id;

Expand All @@ -25,7 +30,7 @@ export async function createRollupEnoughCustomFeeTokenAllowance({
const allowance = await fetchAllowance({
address: nativeToken,
owner: account,
spender: rollupCreator.address[chainId],
spender: rollupCreatorAddressOverride ?? rollupCreator.address[chainId],
publicClient,
});

Expand Down
19 changes: 12 additions & 7 deletions src/createRollupPrepareCustomFeeTokenApprovalTransactionRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,24 @@ import { approvePrepareTransactionRequest } from './utils/erc20';
import { validParentChainId } from './types/ParentChain';
import { rollupCreator } from './contracts';
import { createRollupDefaultRetryablesFees } from './constants';
import { WithRollupCreatorAddressOverride } from './createRollupTypes';
import { Prettify } from './types/utils';

export type CreateRollupPrepareCustomFeeTokenApprovalTransactionRequestParams = {
amount?: bigint;
nativeToken: Address;
account: Address;
publicClient: PublicClient;
};
export type CreateRollupPrepareCustomFeeTokenApprovalTransactionRequestParams = Prettify<
WithRollupCreatorAddressOverride<{
amount?: bigint;
nativeToken: Address;
account: Address;
publicClient: PublicClient;
}>
>;

export async function createRollupPrepareCustomFeeTokenApprovalTransactionRequest({
amount = createRollupDefaultRetryablesFees,
nativeToken,
account,
publicClient,
rollupCreatorAddressOverride,
}: CreateRollupPrepareCustomFeeTokenApprovalTransactionRequestParams) {
const chainId = publicClient.chain?.id;

Expand All @@ -27,7 +32,7 @@ export async function createRollupPrepareCustomFeeTokenApprovalTransactionReques
const request = await approvePrepareTransactionRequest({
address: nativeToken,
owner: account,
spender: rollupCreator.address[chainId],
spender: rollupCreatorAddressOverride ?? rollupCreator.address[chainId],
amount,
publicClient,
});
Expand Down
9 changes: 3 additions & 6 deletions src/createRollupPrepareTransactionRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { ChainConfig } from './types/ChainConfig';
import { isAnyTrustChainConfig } from './utils/isAnyTrustChainConfig';
import { fetchDecimals } from './utils/erc20';
import { TransactionRequestGasOverrides, applyPercentIncrease } from './utils/gasOverrides';
import { WithRollupCreatorAddressOverride } from './createRollupTypes';

function createRollupEncodeFunctionData(args: CreateRollupFunctionInputs) {
return encodeFunctionData({
Expand All @@ -26,16 +27,12 @@ export async function createRollupPrepareTransactionRequest({
publicClient,
gasOverrides,
rollupCreatorAddressOverride,
}: {
}: WithRollupCreatorAddressOverride<{
params: CreateRollupParams;
account: Address;
publicClient: PublicClient;
gasOverrides?: TransactionRequestGasOverrides;
/**
* Specifies a custom address for the RollupCreator. By default, the address will be automatically detected based on the provided chain.
*/
rollupCreatorAddressOverride?: Address;
}) {
}>) {
const chainId = publicClient.chain?.id;

if (!validParentChainId(chainId)) {
Expand Down
8 changes: 8 additions & 0 deletions src/createRollupTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Address } from 'viem';

export type WithRollupCreatorAddressOverride<T> = T & {
/**
* Specifies a custom address for the RollupCreator. By default, the address will be automatically detected based on the provided chain.
*/
rollupCreatorAddressOverride?: Address;
};

0 comments on commit f321549

Please sign in to comment.