-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
ZKS-73 L1MetricsService
Implement AC:
|
|
||
constructor( | ||
private readonly evmProviderService: EvmProviderService, | ||
@Inject("IPricingService") private readonly pricingService: IPricingService, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 😅
libs/metrics/src/metrics.module.ts
Outdated
providers: [ | ||
L1MetricsService, | ||
{ | ||
provide: "IPricingService", | ||
useClass: CoingeckoService, | ||
}, | ||
], |
There was a problem hiding this comment.
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
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 }; | ||
} |
There was a problem hiding this comment.
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 } } { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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> = { |
There was a problem hiding this comment.
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 = { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ty ser! 🤣
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets goo
🤖 Linear
Closes ZKS-72 ZKS-73
Description