-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: scaffold pricing module lib (#28)
# 🤖 Linear Closes ZKS-63 ## Description Scaffold Pricing module library: - `CoingeckoService`
- Loading branch information
Showing
11 changed files
with
287 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./pricing.interface"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./coingecko.service"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.