Skip to content

Commit

Permalink
feat: dummy pricing provider (#58)
Browse files Browse the repository at this point in the history
# 🤖 Linear

Closes ZKS-212

## Description

Implement DummyPricingProvider
- return fixed price of 1 for every token
- to be used in testnet or local
  • Loading branch information
0xnigir1 authored Aug 29, 2024
1 parent 435d870 commit dd33a59
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
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])));
}
}
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.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);
});
});

0 comments on commit dd33a59

Please sign in to comment.