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

Improvement Suggestion: Refactoring and Consistency in Export Statements #195

Open
Durgesh4993 opened this issue Jan 15, 2025 · 1 comment

Comments

@Durgesh4993
Copy link

Issue Summary

The current export statements in the module could benefit from several improvements for consistency, readability, and maintainability. While the exports are functional, a few refinements can be made to follow best practices and align the code more closely with modern TypeScript conventions. This will ensure the codebase is clean, consistent, and scalable.

Proposed Changes:

  1. Group Export Statements by Category:

    • Exports can be grouped into logical categories for better organization (e.g., actions, types, utils, decorators).
    • This makes it easier for developers to locate relevant exports, and improves readability.
  2. Consolidate Similar Exports:

    • Instead of having multiple lines for similar types or functions, consider grouping them where possible. This reduces redundancy and makes the code more concise.
  3. Use export { default as ... } for Named Exports (where applicable):

    • If a module contains a default export and multiple named exports, we can use export { default as ... } syntax to clarify the distinction and keep it consistent.
  4. Ensure Correct Typing:

    • Double-check for any mismatched or redundant types in the exports, ensuring that types are appropriately and consistently applied.

Example Refactor:

// Grouping export statements logically for clarity and readability

// Public actions
export { type ProvenWithdrawal } from './actions/public/L1/readProvenWithdrawals.js';
export { type ProveWithdrawalTransactionParameters } from './actions/wallet/L1/writeProveWithdrawalTransaction.js';

// Public L1 and L2 Op Stack Actions
export { type PublicL1OpStackActions, publicL1OpStackActions } from './decorators/publicL1OpStackActions.js';
export { type PublicL2OpStackActions, publicL2OpStackActions } from './decorators/publicL2OpStackActions.js';

// Wallet L1 and L2 Op Stack Actions
export { type WalletL1OpStackActions, walletL1OpStackActions } from './decorators/walletL1OpStackActions.js';
export { type WalletL2OpStackActions, walletL2OpStackActions } from './decorators/walletL2OpStackActions.js';

// Types related to addresses, deposits, and transactions
export type { Addresses, ContractAddress, RawOrContractAddress } from './types/addresses.js';
export type { DepositERC20Parameters, DepositETHParameters, DepositTransaction, TransactionDepositedEvent } from './types/depositTransaction.js';
export { DEPOSIT_TX_PREFIX, SourceHashDomain } from './types/depositTransaction.js';
export type { WithdrawETHParameters, WithdrawToParameters } from './types/withdrawTo.js';

// Gas Price Oracle and Transaction Parameters
export type { BlockOptions, GasPriceOracleEstimator, GasPriceOracleParameters, OracleTransactionParameters } from './types/gasPriceOracle.js';

// Contract-related types for Op Stack L2
export { type OpStackL2ChainContracts, opStackL2ChainContracts, OpStackL2Contract } from './types/opStackContracts.js';

// Events and utilities
export type { MessagePassedEvent } from './types/withdrawal.js';
export type { GetDepositTransactionParams } from './utils/getDepositTransaction.js';
export { getDepositTransaction, getL2HashFromL1DepositInfo, getSourceHash, getTransactionDepositedEvents, getWithdrawalMessageStorageSlot, rlpEncodeDepositTransaction } from './utils';

// Event types for transaction deposits
export type { GetTransactionDepositedEventsParams, GetTransactionDepositedEventsReturnType, TransactionDepositedEventDetails } from './utils/getTransactionDepositedEvents.js';
@Durgesh4993
Copy link
Author

Benefits of the Proposed Changes:

Increased Readability:

  • By categorizing and organizing export statements, developers can navigate the code more easily.

Improved Maintainability:

  • Having fewer lines of code with grouped exports makes it easier to update or add new exports in the future without clutter.

Consistency with Modern TypeScript Practices:

  • Applying the best practices for imports and exports will help keep the codebase aligned with TypeScript standards and improve collaboration among developers.

Steps to Reproduce:

  1. Examine the current state of the export statements.
  2. Follow the above example refactor to group and simplify the exports.

Expected Outcome:

  • A more organized and consistent module with grouped export statements for better readability and maintainability.

Proposed Action:

I propose updating the export structure as described above and applying it to all relevant modules. This will improve clarity and make it easier for developers to work with the code.

Please review and consider applying these changes in the next iteration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant