diff --git a/libs/pricing/src/index.ts b/libs/pricing/src/index.ts new file mode 100644 index 0000000..f7850bb --- /dev/null +++ b/libs/pricing/src/index.ts @@ -0,0 +1,3 @@ +export * from "./pricing.module"; +export * from "./services/coingecko.service"; +export * from "./interfaces"; diff --git a/libs/pricing/src/interfaces/index.ts b/libs/pricing/src/interfaces/index.ts new file mode 100644 index 0000000..2a231ae --- /dev/null +++ b/libs/pricing/src/interfaces/index.ts @@ -0,0 +1 @@ +export * from "./pricing.interface"; diff --git a/libs/pricing/src/interfaces/pricing.interface.ts b/libs/pricing/src/interfaces/pricing.interface.ts new file mode 100644 index 0000000..34055d2 --- /dev/null +++ b/libs/pricing/src/interfaces/pricing.interface.ts @@ -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( + tokenIds: TokenId[], + config?: { currency: string }, + ): Promise>; +} diff --git a/libs/pricing/src/pricing.module.ts b/libs/pricing/src/pricing.module.ts new file mode 100644 index 0000000..5fc6280 --- /dev/null +++ b/libs/pricing/src/pricing.module.ts @@ -0,0 +1,9 @@ +import { Module } from "@nestjs/common"; + +import { CoingeckoService } from "./services"; + +@Module({ + providers: [CoingeckoService], + exports: [CoingeckoService], +}) +export class PricingModule {} diff --git a/libs/pricing/src/services/coingecko.service.spec.ts b/libs/pricing/src/services/coingecko.service.spec.ts new file mode 100644 index 0000000..2c58646 --- /dev/null +++ b/libs/pricing/src/services/coingecko.service.spec.ts @@ -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); + }); + + it("should be defined", () => { + expect(service).toBeDefined(); + }); +}); diff --git a/libs/pricing/src/services/coingecko.service.ts b/libs/pricing/src/services/coingecko.service.ts new file mode 100644 index 0000000..1d853eb --- /dev/null +++ b/libs/pricing/src/services/coingecko.service.ts @@ -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> { + throw new Error("Method not implemented."); + } +} diff --git a/libs/pricing/src/services/index.ts b/libs/pricing/src/services/index.ts new file mode 100644 index 0000000..2dde225 --- /dev/null +++ b/libs/pricing/src/services/index.ts @@ -0,0 +1 @@ +export * from "./coingecko.service"; diff --git a/libs/pricing/tsconfig.lib.json b/libs/pricing/tsconfig.lib.json new file mode 100644 index 0000000..c92c214 --- /dev/null +++ b/libs/pricing/tsconfig.lib.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "declaration": true, + "outDir": "../../dist/libs/pricing" + }, + "include": ["src/**/*"], + "exclude": ["node_modules", "dist", "test", "**/*spec.ts"] +} diff --git a/nest-cli.json b/nest-cli.json index 6472ea1..967dbf6 100644 --- a/nest-cli.json +++ b/nest-cli.json @@ -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" + } + } } - } -} \ No newline at end of file +} diff --git a/package.json b/package.json index d61d728..7d70ce9 100644 --- a/package.json +++ b/package.json @@ -1,104 +1,105 @@ { - "name": "zkchainhub", - "version": "0.0.1", - "description": "", - "author": "", - "private": true, - "license": "UNLICENSED", - "scripts": { - "build": "nest build", - "format": "prettier --write \"{apps,libs}/**/*.ts\"", - "start": "nest start", - "start:dev": "nest start --watch", - "start:debug": "nest start --debug --watch", - "start:prod": "node dist/apps/api/main", - "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", - "test": "jest", - "test:watch": "jest --watch", - "test:cov": "jest --coverage", - "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand", - "test:e2e": "jest --config ./apps/api/test/jest-e2e.json", - "create-lib": "echo @zkchainhub | pnpm nest g library $1 ", - "prepare": "husky", - "preinstall": "npx only-allow pnpm" - }, - "dependencies": { - "@nestjs/common": "10.0.0", - "@nestjs/core": "10.0.0", - "@nestjs/platform-express": "10.0.0", - "@nestjs/swagger": "7.4.0", - "abitype": "1.0.5", - "reflect-metadata": "0.1.13", - "rxjs": "7.8.1", - "viem": "2.17.5" - }, - "devDependencies": { - "@commitlint/config-conventional": "19.2.2", - "@golevelup/ts-jest": "0.5.0", - "@ianvs/prettier-plugin-sort-imports": "4.3.0", - "@nestjs/cli": "10.0.0", - "@nestjs/schematics": "10.0.0", - "@nestjs/testing": "10.0.0", - "@total-typescript/tsconfig": "1.0.4", - "@types/express": "4.17.17", - "@types/jest": "29.5.2", - "@types/node": "20.3.1", - "@types/supertest": "6.0.0", - "@typescript-eslint/eslint-plugin": "7.0.0", - "@typescript-eslint/parser": "7.0.0", - "commitlint": "19.3.0", - "eslint": "8.42.0", - "eslint-config-prettier": "9.0.0", - "eslint-plugin-prettier": "5.0.0", - "husky": "9.0.11", - "jest": "29.5.0", - "lint-staged": "15.2.7", - "prettier": "3.0.0", - "source-map-support": "0.5.21", - "supertest": "7.0.0", - "ts-jest": "29.1.0", - "ts-loader": "9.4.3", - "ts-node": "10.9.1", - "tsconfig-paths": "4.2.0", - "typescript": "5.1.3" - }, - "jest": { - "moduleFileExtensions": [ - "js", - "json", - "ts" - ], - "rootDir": ".", - "testRegex": ".*\\.spec\\.ts$", - "transform": { - ".+\\.(t|j)s$": "ts-jest" + "name": "zkchainhub", + "version": "0.0.1", + "description": "", + "author": "", + "private": true, + "license": "UNLICENSED", + "scripts": { + "build": "nest build", + "format": "prettier --write \"{apps,libs}/**/*.ts\"", + "start": "nest start", + "start:dev": "nest start --watch", + "start:debug": "nest start --debug --watch", + "start:prod": "node dist/apps/api/main", + "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", + "test": "jest", + "test:watch": "jest --watch", + "test:cov": "jest --coverage", + "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand", + "test:e2e": "jest --config ./apps/api/test/jest-e2e.json", + "create-lib": "echo @zkchainhub | pnpm nest g library $1 ", + "prepare": "husky", + "preinstall": "npx only-allow pnpm" }, - "collectCoverageFrom": [ - "**/*.(t|j)s" - ], - "coverageDirectory": "./coverage", - "coveragePathIgnorePatterns": [ - "/node_modules/", - ".e2e-spec.ts", - ".module.ts", - "main.ts" - ], - "testEnvironment": "node", - "roots": [ - "/apps/", - "/libs/" - ], - "moduleNameMapper": { - "^@zkchainhub/providers(|/.*)$": "/libs/providers/src/$1", - "^@zkchainhub/metrics(|/.*)$": "/libs/metrics/src/$1", - "^@zkchainhub/shared(|/.*)$": "/libs/shared/src/$1" + "dependencies": { + "@nestjs/common": "10.0.0", + "@nestjs/core": "10.0.0", + "@nestjs/platform-express": "10.0.0", + "@nestjs/swagger": "7.4.0", + "abitype": "1.0.5", + "reflect-metadata": "0.1.13", + "rxjs": "7.8.1", + "viem": "2.17.5" + }, + "devDependencies": { + "@commitlint/config-conventional": "19.2.2", + "@golevelup/ts-jest": "0.5.0", + "@ianvs/prettier-plugin-sort-imports": "4.3.0", + "@nestjs/cli": "10.0.0", + "@nestjs/schematics": "10.0.0", + "@nestjs/testing": "10.0.0", + "@total-typescript/tsconfig": "1.0.4", + "@types/express": "4.17.17", + "@types/jest": "29.5.2", + "@types/node": "20.3.1", + "@types/supertest": "6.0.0", + "@typescript-eslint/eslint-plugin": "7.0.0", + "@typescript-eslint/parser": "7.0.0", + "commitlint": "19.3.0", + "eslint": "8.42.0", + "eslint-config-prettier": "9.0.0", + "eslint-plugin-prettier": "5.0.0", + "husky": "9.0.11", + "jest": "29.5.0", + "lint-staged": "15.2.7", + "prettier": "3.0.0", + "source-map-support": "0.5.21", + "supertest": "7.0.0", + "ts-jest": "29.1.0", + "ts-loader": "9.4.3", + "ts-node": "10.9.1", + "tsconfig-paths": "4.2.0", + "typescript": "5.1.3" + }, + "jest": { + "moduleFileExtensions": [ + "js", + "json", + "ts" + ], + "rootDir": ".", + "testRegex": ".*\\.spec\\.ts$", + "transform": { + ".+\\.(t|j)s$": "ts-jest" + }, + "collectCoverageFrom": [ + "**/*.(t|j)s" + ], + "coverageDirectory": "./coverage", + "coveragePathIgnorePatterns": [ + "/node_modules/", + ".e2e-spec.ts", + ".module.ts", + "main.ts" + ], + "testEnvironment": "node", + "roots": [ + "/apps/", + "/libs/" + ], + "moduleNameMapper": { + "^@zkchainhub/providers(|/.*)$": "/libs/providers/src/$1", + "^@zkchainhub/metrics(|/.*)$": "/libs/metrics/src/$1", + "^@zkchainhub/shared(|/.*)$": "/libs/shared/src/$1", + "^@zkchainhub/pricing(|/.*)$": "/libs/pricing/src/$1" + } + }, + "packageManager": "pnpm@9.5.0+sha1.8c155dc114e1689d18937974f6571e0ceee66f1d", + "lint-staged": { + "(apps|libs)/**/*.(ts|js)": [ + "pnpm lint", + "pnpm format" + ] } - }, - "packageManager": "pnpm@9.5.0+sha1.8c155dc114e1689d18937974f6571e0ceee66f1d", - "lint-staged": { - "(apps|libs)/**/*.(ts|js)": [ - "pnpm lint", - "pnpm format" - ] - } -} \ No newline at end of file +} diff --git a/tsconfig.json b/tsconfig.json index f5db647..66b175d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,43 +1,33 @@ { - "extends": "@total-typescript/tsconfig/tsc/no-dom/app", - "compilerOptions": { - "module": "commonjs", - "declaration": true, - "removeComments": true, - "emitDecoratorMetadata": true, - "experimentalDecorators": true, - "allowSyntheticDefaultImports": true, - "target": "ES2021", - "sourceMap": true, - "outDir": "./dist", - "baseUrl": "./", - "incremental": true, - "skipLibCheck": true, - "strictNullChecks": true, - "noImplicitAny": true, - "strictBindCallApply": true, - "forceConsistentCasingInFileNames": true, - "noFallthroughCasesInSwitch": true, - "paths": { - "@zkchainhub/providers": [ - "libs/providers/src" - ], - "@zkchainhub/providers/*": [ - "libs/providers/src/*" - ], - "@zkchainhub/metrics": [ - "libs/metrics/src" - ], - "@zkchainhub/metrics/*": [ - "libs/metrics/src/*" - ], - "@zkchainhub/shared": [ - "libs/shared/src" - ], - "@zkchainhub/shared/*": [ - "libs/shared/src/*" - ] - }, - "verbatimModuleSyntax": false - } -} \ No newline at end of file + "extends": "@total-typescript/tsconfig/tsc/no-dom/app", + "compilerOptions": { + "module": "commonjs", + "declaration": true, + "removeComments": true, + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "allowSyntheticDefaultImports": true, + "target": "ES2021", + "sourceMap": true, + "outDir": "./dist", + "baseUrl": "./", + "incremental": true, + "skipLibCheck": true, + "strictNullChecks": true, + "noImplicitAny": true, + "strictBindCallApply": true, + "forceConsistentCasingInFileNames": true, + "noFallthroughCasesInSwitch": true, + "paths": { + "@zkchainhub/providers": ["libs/providers/src"], + "@zkchainhub/providers/*": ["libs/providers/src/*"], + "@zkchainhub/metrics": ["libs/metrics/src"], + "@zkchainhub/metrics/*": ["libs/metrics/src/*"], + "@zkchainhub/shared": ["libs/shared/src"], + "@zkchainhub/shared/*": ["libs/shared/src/*"], + "@zkchainhub/pricing": ["libs/pricing/src"], + "@zkchainhub/pricing/*": ["libs/pricing/src/*"] + }, + "verbatimModuleSyntax": false + } +}