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: dummy pricing provider #58

Merged
merged 2 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion packages/pricing/src/external.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
13 changes: 13 additions & 0 deletions packages/pricing/src/providers/dummy.provider.ts
Original file line number Diff line number Diff line change
@@ -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<PriceResponse> {
return Promise.resolve(Object.fromEntries(addresses.map((address) => [address, 1])));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i was wondering if we should return undefined here, lets leave it as it is, and if we need a refactor it wouldn't take to much time

}
}
1 change: 1 addition & 0 deletions packages/pricing/src/providers/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./coingecko.provider.js";
export * from "./dummy.provider.js";
25 changes: 25 additions & 0 deletions packages/pricing/test/unit/services/dummy.provider.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { beforeEach, describe, expect, it } from "vitest";

import { Address } from "@zkchainhub/shared";

import { DummyPricingProvider } from "../../../src/providers/dummy.provider";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might want to add a .js?


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);
});
});