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

refactor: modular architecture #141

Merged
merged 1 commit into from
Jan 25, 2024
Merged

refactor: modular architecture #141

merged 1 commit into from
Jan 25, 2024

Conversation

mfw78
Copy link
Contributor

@mfw78 mfw78 commented Jan 23, 2024

Description

This PR refactors legacy locations of code to more accurately reflect the area of responsibility for the respective code.

Changes

  • Any core "service" that is running is located within the "services" module.
  • Domain logic is split related to indexing ("events"), and polling ("polling")
  • Filtering that has been applied is made more meaningful and moved to a "filtering" module

How to test

  1. Verify that yarn test passes
  2. Run from genesis on mainnet and verify the block watcher comes online (passes warmUp).

@mfw78 mfw78 added the enhancement New feature or request label Jan 23, 2024
@mfw78 mfw78 requested review from anxolin and a team January 23, 2024 12:48
@mfw78 mfw78 self-assigned this Jan 23, 2024
Copy link
Contributor

@anxolin anxolin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Soft approve

I don't see the functional difference between domain and services.

Also, no need to address, but my 2c. If we are structuring in layers, i think i miss a bit the layer for DAO or Repository layer.

So I would leave these 4 => commands, services, repository, model
Each layer interacts with the one below.

/**
* Process an order to determine if it is valid
* @param order The GPv2.Order data struct to validate
* @throws Error if the order is invalid
*/
export function validateOrder(order: Order) {
export function check(order: Order) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would think, check should return a boolean not throw.
If you want it to throw, a better name is assertValidOrder(order)

nit: If you want to make this more modular, you can have all the assertions as independent checks. This way, is easier to test them in isolation, reuse them for different checks, or define different messages.

type OrderCheck = (order: Order) => boolean

export ZeroAmountOrderCheck: OrderCheck = ...

This way, you can use it for filtering or for asserting and is easier to maintain as you can have smaller atomic checks.

Also, allows you to define your error messages easier:

const BAD_ORDER_ERRORS: Record<OrderCheck, string> = ...

Base automatically changed from metrics-imports to main January 25, 2024 08:11
@mfw78 mfw78 merged commit d714c38 into main Jan 25, 2024
4 checks passed
@mfw78 mfw78 deleted the module-refactor branch January 25, 2024 08:21
@github-actions github-actions bot locked and limited conversation to collaborators Jan 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants