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

feat: init L1MetricsService #34

Merged
merged 7 commits into from
Aug 1, 2024
Merged

feat: init L1MetricsService #34

merged 7 commits into from
Aug 1, 2024

Conversation

0xkenj1
Copy link
Collaborator

@0xkenj1 0xkenj1 commented Jul 31, 2024

🤖 Linear

Closes ZKS-72 ZKS-73

Description

  • L1MetricsService

@0xkenj1 0xkenj1 requested a review from 0xnigir1 July 31, 2024 05:17
Copy link

linear bot commented Jul 31, 2024

ZKS-73 L1MetricsService

Implement L1MetricsService class following figma diagrams https://www.figma.com/board/xTyk97Ndh3qeUb9zOzSHq4/ZKchainHub%3A-Offchain-Architecture?node-id=76-1656&t=8uJneKN7nQmKGN28-4

AC:

  • All the necessary contracts as attributes
  • EvmProviderService as Attribute using constructor dependency injection
  • Unit test

ZKS-72 `metrics` module

Implement base skeleton for metrics module

@0xkenj1 0xkenj1 requested a review from 0xyaco July 31, 2024 05:53

constructor(
private readonly evmProviderService: EvmProviderService,
@Inject("IPricingService") private readonly pricingService: IPricingService,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

is there a better way to do this ser? @0xnigir1

notice that i am injecting an IPricingService interface not a class.

Copy link
Collaborator

@0xnigir1 0xnigir1 Jul 31, 2024

Choose a reason for hiding this comment

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

It's the way to go ser 🙌

To improve it a bit, we can export a symbol and use that as Token for provider so we don't have the hardcoded string

//interface.ts or constants.ts

export PRICING_PROVIDER = Symbol("IPricingService");

the string itself can be anything as long as it's unique across the app

this is like the Winston Module example

Copy link
Collaborator

Choose a reason for hiding this comment

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

just realized i should have written the token 😅

Comment on lines 15 to 21
providers: [
L1MetricsService,
{
provide: "IPricingService",
useClass: CoingeckoService,
},
],
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

same here , not sure if this is the way

@0xnigir1

Comment on lines 30 to 44
l1Tvl(): { [asset: string]: { amount: number; amountUsd: number } } {
return { ETH: { amount: 1000000, amountUsd: 1000000 } };
}
getBatchesInfo(_chainId: number): { commited: number; verified: number; proved: number } {
return { commited: 100, verified: 100, proved: 100 };
}
tvl(_chainId: number): { [asset: string]: { amount: number; amountUsd: number } } {
return { ETH: { amount: 1000000, amountUsd: 1000000 } };
}
chainType(_chainId: number): "validium" | "rollup" {
return "rollup";
}
ethGasInfo(): { gasPrice: number; ethTransfer: number; erc20Transfer: number } {
return { gasPrice: 50, ethTransfer: 21000, erc20Transfer: 65000 };
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are these mocked return values? If they are, we might want to mark them with a TODO or FIXME comment to not forget that these need to be implemented yet

@Inject(WINSTON_MODULE_NEST_PROVIDER) private readonly logger: LoggerService,
) {}

l1Tvl(): { [asset: string]: { amount: number; amountUsd: number } } {
Copy link
Collaborator

Choose a reason for hiding this comment

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

should we define types for the return types?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Lets refine types as we implement each method. There is no need to do it for now, i think it could be a waste of time since it is something that might change on implementation.

Copy link
Collaborator

Choose a reason for hiding this comment

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

although its mock data, I would add async to the functions signatures


/**
* Acts as a wrapper around Viem library to provide methods to interact with an EVM-based blockchain.
*/
@Injectable()
export class L1MetricsService {
constructor(private readonly evmProviderService: EvmProviderService) {}
private readonly bridgeHub: Readonly<AbiWithAddress> = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice

import { L1MetricsService } from "./l1MetricsService";

// Mock implementations of the dependencies
const mockEvmProviderService = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

just a tip but feel free to leave it as it is, you can use the createMock testing utility

@0xkenj1 0xkenj1 requested review from 0xnigir1 and 0xyaco July 31, 2024 23:02
Copy link
Collaborator

Choose a reason for hiding this comment

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

add await to methods call on tests (also fixes the pipeline xd)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ty ser! 🤣

@0xkenj1 0xkenj1 requested a review from 0xnigir1 August 1, 2024 16:00
0xnigir1
0xnigir1 previously approved these changes Aug 1, 2024
Copy link
Collaborator

@0xnigir1 0xnigir1 left a comment

Choose a reason for hiding this comment

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

lets goo

0xyaco
0xyaco previously approved these changes Aug 1, 2024
@0xkenj1 0xkenj1 dismissed stale reviews from 0xyaco and 0xnigir1 via dcea9fa August 1, 2024 19:27
@0xkenj1 0xkenj1 requested review from 0xnigir1 and 0xyaco August 1, 2024 19:27
@0xkenj1 0xkenj1 merged commit c6e1fe6 into dev Aug 1, 2024
6 checks passed
@0xkenj1 0xkenj1 deleted the feat/l1metrics branch August 1, 2024 23:34
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

Successfully merging this pull request may close these issues.

3 participants