Skip to content

Commit

Permalink
refactor: split getters into separate files (#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
spsjvc authored Sep 9, 2024
1 parent c2ca2f2 commit a77dc33
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/createRollup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from './createRollupPrepareTransactionReceipt';
import { createRollupEnoughCustomFeeTokenAllowance } from './createRollupEnoughCustomFeeTokenAllowance';
import { createRollupPrepareCustomFeeTokenApprovalTransactionRequest } from './createRollupPrepareCustomFeeTokenApprovalTransactionRequest';
import { getBlockExplorerUrl } from './utils/getters';
import { getBlockExplorerUrl } from './utils/getBlockExplorerUrl';
import {
CreateRollupTransaction,
createRollupPrepareTransaction,
Expand Down
2 changes: 1 addition & 1 deletion src/createRollupEnoughCustomFeeTokenAllowance.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Address, PublicClient, Transport, Chain } from 'viem';

import { fetchAllowance } from './utils/erc20';
import { getRollupCreatorAddress } from './utils/getters';
import { getRollupCreatorAddress } from './utils/getRollupCreatorAddress';
import { createRollupDefaultRetryablesFees } from './constants';

import { Prettify } from './types/utils';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Address, PublicClient, Transport, Chain } from 'viem';

import { approvePrepareTransactionRequest } from './utils/erc20';
import { validateParentChain } from './types/ParentChain';
import { getRollupCreatorAddress } from './utils/getters';
import { getRollupCreatorAddress } from './utils/getRollupCreatorAddress';
import { createRollupDefaultRetryablesFees } from './constants';

import { Prettify } from './types/utils';
Expand Down
2 changes: 1 addition & 1 deletion src/createRollupPrepareTransactionRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { validateParentChain } from './types/ParentChain';
import { isCustomFeeTokenAddress } from './utils/isCustomFeeTokenAddress';
import { ChainConfig } from './types/ChainConfig';
import { isAnyTrustChainConfig } from './utils/isAnyTrustChainConfig';
import { getRollupCreatorAddress } from './utils/getters';
import { getRollupCreatorAddress } from './utils/getRollupCreatorAddress';
import { fetchDecimals } from './utils/erc20';
import { TransactionRequestGasOverrides, applyPercentIncrease } from './utils/gasOverrides';

Expand Down
5 changes: 1 addition & 4 deletions src/createTokenBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ import {
import { isCustomFeeTokenAddress } from './utils/isCustomFeeTokenAddress';
import { WithTokenBridgeCreatorAddressOverride } from './types/createTokenBridgeTypes';
import { TransactionRequestGasOverrides } from './utils/gasOverrides';

function getBlockExplorerUrl(chain: Chain | undefined) {
return chain?.blockExplorers?.default.url;
}
import { getBlockExplorerUrl } from './utils/getBlockExplorerUrl';

export type CreateTokenBridgeParams<
TParentChain extends Chain | undefined,
Expand Down
2 changes: 1 addition & 1 deletion src/createTokenBridgeEnoughCustomFeeTokenAllowance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { createTokenBridgeDefaultRetryablesFees } from './constants';

import { Prettify } from './types/utils';
import { WithTokenBridgeCreatorAddressOverride } from './types/createTokenBridgeTypes';
import { getTokenBridgeCreatorAddress } from './utils/getters';
import { getTokenBridgeCreatorAddress } from './utils/getTokenBridgeCreatorAddress';

export type CreateTokenBridgeEnoughCustomFeeTokenAllowanceParams<TChain extends Chain | undefined> =
Prettify<
Expand Down
2 changes: 1 addition & 1 deletion src/createTokenBridgeFetchTokenBridgeContracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { tokenBridgeCreatorABI } from './contracts/TokenBridgeCreator';
import { Prettify } from './types/utils';
import { WithTokenBridgeCreatorAddressOverride } from './types/createTokenBridgeTypes';
import { TokenBridgeContracts } from './types/TokenBridgeContracts';
import { getTokenBridgeCreatorAddress } from './utils/getters';
import { getTokenBridgeCreatorAddress } from './utils/getTokenBridgeCreatorAddress';

export type CreateTokenBridgeFetchTokenBridgeContractsParams<TChain extends Chain | undefined> =
Prettify<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { approvePrepareTransactionRequest } from './utils/erc20';
import { Prettify } from './types/utils';
import { validateParentChain } from './types/ParentChain';
import { WithTokenBridgeCreatorAddressOverride } from './types/createTokenBridgeTypes';
import { getTokenBridgeCreatorAddress } from './utils/getters';
import { getTokenBridgeCreatorAddress } from './utils/getTokenBridgeCreatorAddress';

export type CreateTokenBridgePrepareCustomFeeTokenApprovalTransactionRequestParams<
TChain extends Chain | undefined,
Expand Down
2 changes: 1 addition & 1 deletion src/createTokenBridgePrepareTransactionRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {

import { Prettify } from './types/utils';
import { WithTokenBridgeCreatorAddressOverride } from './types/createTokenBridgeTypes';
import { getTokenBridgeCreatorAddress } from './utils/getters';
import { getTokenBridgeCreatorAddress } from './utils/getTokenBridgeCreatorAddress';

export type TransactionRequestRetryableGasOverrides = {
maxSubmissionCostForFactory?: GasOverrideOptions;
Expand Down
5 changes: 5 additions & 0 deletions src/utils/getBlockExplorerUrl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Chain } from 'viem';

export function getBlockExplorerUrl(chain: Chain | undefined) {
return chain?.blockExplorers?.default.url;
}
16 changes: 16 additions & 0 deletions src/utils/getRollupCreatorAddress.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Client, Transport, Chain } from 'viem';

import { rollupCreatorAddress } from '../contracts/RollupCreator';
import { validateParentChain } from '../types/ParentChain';

export function getRollupCreatorAddress<TChain extends Chain | undefined>(
client: Client<Transport, TChain>,
) {
const chainId = validateParentChain(client);

if (!rollupCreatorAddress[chainId]) {
throw new Error(`Parent chain not supported: ${chainId}`);
}

return rollupCreatorAddress[chainId];
}
17 changes: 0 additions & 17 deletions src/utils/getters.ts → src/utils/getTokenBridgeCreatorAddress.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,8 @@
import { Client, Transport, Chain } from 'viem';

import { rollupCreatorAddress } from '../contracts/RollupCreator';
import { tokenBridgeCreatorAddress } from '../contracts/TokenBridgeCreator';
import { validateParentChain } from '../types/ParentChain';

export function getRollupCreatorAddress<TChain extends Chain | undefined>(
client: Client<Transport, TChain>,
) {
const chainId = validateParentChain(client);

if (!rollupCreatorAddress[chainId]) {
throw new Error(`Parent chain not supported: ${chainId}`);
}

return rollupCreatorAddress[chainId];
}

export function getTokenBridgeCreatorAddress<TChain extends Chain | undefined>(
client: Client<Transport, TChain>,
) {
Expand All @@ -27,7 +14,3 @@ export function getTokenBridgeCreatorAddress<TChain extends Chain | undefined>(

return tokenBridgeCreatorAddress[chainId];
}

export function getBlockExplorerUrl(chain: Chain) {
return chain.blockExplorers?.default.url;
}
3 changes: 2 additions & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { getParentChainLayer } from './getParentChainLayer';
import { sanitizePrivateKey } from './sanitizePrivateKey';
import { getArbOSVersion } from './getArbOSVersion';
import { getClientVersion } from './getClientVersion';
import { getRollupCreatorAddress, getTokenBridgeCreatorAddress } from './getters';
import { getRollupCreatorAddress } from './getRollupCreatorAddress';
import { getTokenBridgeCreatorAddress } from './getTokenBridgeCreatorAddress';

export {
generateChainId,
Expand Down

0 comments on commit a77dc33

Please sign in to comment.