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: scaffold pricing module lib #28

Merged
merged 5 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions libs/pricing/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from "./pricing.module";
export * from "./services/coingecko.service";
export * from "./interfaces";
1 change: 1 addition & 0 deletions libs/pricing/src/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./pricing.interface";
19 changes: 19 additions & 0 deletions libs/pricing/src/interfaces/pricing.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Represents a pricing service that provides token prices.
*/
/**
* Represents a pricing service that retrieves token prices.
*/
export interface IPricingService {
/**
* Retrieves the prices of the specified tokens.
* @param tokenIds - An array of token IDs.
* @param [config] - Optional configuration object.
* @param config.currency - The currency in which the prices should be returned.
* @returns A promise that resolves to a record containing the token IDs as keys and their corresponding prices as values.
*/
getTokenPrices<TokenId extends string = string>(
tokenIds: TokenId[],
config?: { currency: string },
): Promise<Record<string, number>>;
}
9 changes: 9 additions & 0 deletions libs/pricing/src/pricing.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Module } from "@nestjs/common";

import { CoingeckoService } from "./services";

@Module({
providers: [CoingeckoService],
exports: [CoingeckoService],
})
export class PricingModule {}
28 changes: 28 additions & 0 deletions libs/pricing/src/services/coingecko.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Test, TestingModule } from "@nestjs/testing";

import { CoingeckoService } from "./coingecko.service";

describe("CoingeckoService", () => {
let service: CoingeckoService;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [
{
provide: CoingeckoService,
useFactory: () => {
const apiKey = "COINGECKO_API_KEY";
const apiBaseUrl = "https://api.coingecko.com/api/v3/";
return new CoingeckoService(apiKey, apiBaseUrl);
},
},
],
}).compile();

service = module.get<CoingeckoService>(CoingeckoService);
});

it("should be defined", () => {
expect(service).toBeDefined();
});
});
18 changes: 18 additions & 0 deletions libs/pricing/src/services/coingecko.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Injectable } from "@nestjs/common";

import { IPricingService } from "@zkchainhub/pricing/interfaces";

@Injectable()
export class CoingeckoService implements IPricingService {
constructor(
private readonly apiKey: string,
private readonly apiBaseUrl: string = "https://api.coingecko.com/api/v3/",
) {}

async getTokenPrices(
_tokenIds: string[],
_config: { currency: string } = { currency: "usd" },
): Promise<Record<string, number>> {
throw new Error("Method not implemented.");
}
}
1 change: 1 addition & 0 deletions libs/pricing/src/services/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./coingecko.service";
9 changes: 9 additions & 0 deletions libs/pricing/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"declaration": true,
"outDir": "../../dist/libs/pricing"
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist", "test", "**/*spec.ts"]
}
121 changes: 65 additions & 56 deletions nest-cli.json
Original file line number Diff line number Diff line change
@@ -1,59 +1,68 @@
{
"$schema": "https://json.schemastore.org/nest-cli",
"collection": "@nestjs/schematics",
"sourceRoot": "apps/api/src",
"compilerOptions": {
"deleteOutDir": true,
"webpack": true,
"tsConfigPath": "apps/api/tsconfig.app.json",
"plugins": [
{
"name": "@nestjs/swagger",
"options": {
"classValidatorShim": false,
"introspectComments": true
}
}
]
},
"monorepo": true,
"root": "apps/api",
"projects": {
"api": {
"type": "application",
"root": "apps/api",
"entryFile": "main",
"sourceRoot": "apps/api/src",
"compilerOptions": {
"tsConfigPath": "apps/api/tsconfig.app.json"
}
},
"providers": {
"type": "library",
"root": "libs/providers",
"entryFile": "index",
"sourceRoot": "libs/providers/src",
"compilerOptions": {
"tsConfigPath": "libs/providers/tsconfig.lib.json"
}
"$schema": "https://json.schemastore.org/nest-cli",
"collection": "@nestjs/schematics",
"sourceRoot": "apps/api/src",
"compilerOptions": {
"deleteOutDir": true,
"webpack": true,
"tsConfigPath": "apps/api/tsconfig.app.json",
"plugins": [
{
"name": "@nestjs/swagger",
"options": {
"classValidatorShim": false,
"introspectComments": true
}
}
]
},
"metrics": {
"type": "library",
"root": "libs/metrics",
"entryFile": "index",
"sourceRoot": "libs/metrics/src",
"compilerOptions": {
"tsConfigPath": "libs/metrics/tsconfig.lib.json"
}
},
"shared": {
"type": "library",
"root": "libs/shared",
"entryFile": "index",
"sourceRoot": "libs/shared/src",
"compilerOptions": {
"tsConfigPath": "libs/shared/tsconfig.lib.json"
}
"monorepo": true,
"root": "apps/api",
"projects": {
"api": {
"type": "application",
"root": "apps/api",
"entryFile": "main",
"sourceRoot": "apps/api/src",
"compilerOptions": {
"tsConfigPath": "apps/api/tsconfig.app.json"
}
},
"providers": {
"type": "library",
"root": "libs/providers",
"entryFile": "index",
"sourceRoot": "libs/providers/src",
"compilerOptions": {
"tsConfigPath": "libs/providers/tsconfig.lib.json"
}
},
"metrics": {
"type": "library",
"root": "libs/metrics",
"entryFile": "index",
"sourceRoot": "libs/metrics/src",
"compilerOptions": {
"tsConfigPath": "libs/metrics/tsconfig.lib.json"
}
},
"shared": {
"type": "library",
"root": "libs/shared",
"entryFile": "index",
"sourceRoot": "libs/shared/src",
"compilerOptions": {
"tsConfigPath": "libs/shared/tsconfig.lib.json"
}
},
"pricing": {
"type": "library",
"root": "libs/pricing",
"entryFile": "index",
"sourceRoot": "libs/pricing/src",
"compilerOptions": {
"tsConfigPath": "libs/pricing/tsconfig.lib.json"
}
}
}
}
}
}
Loading