diff --git a/packages/pricing/src/external.ts b/packages/pricing/src/external.ts index 210c7be..7e4e301 100644 --- a/packages/pricing/src/external.ts +++ b/packages/pricing/src/external.ts @@ -2,4 +2,4 @@ export type { IPricingProvider, PriceResponse } from "./internal.js"; export { RateLimitExceeded, ApiNotAvailable } from "./internal.js"; -export { CoingeckoProvider } from "./internal.js"; +export { CoingeckoProvider, DummyPricingProvider } from "./internal.js"; diff --git a/packages/pricing/src/providers/dummy.provider.ts b/packages/pricing/src/providers/dummy.provider.ts new file mode 100644 index 0000000..606f444 --- /dev/null +++ b/packages/pricing/src/providers/dummy.provider.ts @@ -0,0 +1,13 @@ +import { Address } from "@zkchainhub/shared"; + +import { IPricingProvider, PriceResponse } from "../internal.js"; + +/** + * DummyPricingProvider class that implements the IPricingProvider interface. + * This provider returns a fixed price of 1 for each token address. + */ +export class DummyPricingProvider implements IPricingProvider { + async getTokenPrices(addresses: Address[]): Promise { + return Promise.resolve(Object.fromEntries(addresses.map((address) => [address, 1]))); + } +} diff --git a/packages/pricing/src/providers/index.ts b/packages/pricing/src/providers/index.ts index 7172e08..9c05289 100644 --- a/packages/pricing/src/providers/index.ts +++ b/packages/pricing/src/providers/index.ts @@ -1 +1,2 @@ export * from "./coingecko.provider.js"; +export * from "./dummy.provider.js"; diff --git a/packages/pricing/test/unit/services/dummy.provider.spec.ts b/packages/pricing/test/unit/services/dummy.provider.spec.ts new file mode 100644 index 0000000..87cb557 --- /dev/null +++ b/packages/pricing/test/unit/services/dummy.provider.spec.ts @@ -0,0 +1,25 @@ +import { beforeEach, describe, expect, it } from "vitest"; + +import { Address } from "@zkchainhub/shared"; + +import { DummyPricingProvider } from "../../../src/providers/dummy.provider"; + +describe("DummyPricingProvider", () => { + let provider: DummyPricingProvider; + + beforeEach(() => { + provider = new DummyPricingProvider(); + }); + + it("return 1 for all token prices", async () => { + const addresses: Address[] = ["0x123456789", "0xabcdef123"]; + const expectedResponse = { + "0x123456789": 1, + "0xabcdef123": 1, + }; + + const response = await provider.getTokenPrices(addresses); + + expect(response).toEqual(expectedResponse); + }); +});