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 #32

Merged
merged 4 commits into from
Nov 14, 2024
Merged

feat: dummy pricing provider #32

merged 4 commits into from
Nov 14, 2024

Conversation

0xnigir1
Copy link
Collaborator

@0xnigir1 0xnigir1 commented Nov 13, 2024

🤖 Linear

Closes GIT-136 GIT-144

Description

  • DummyPricingProvider for testing, dev environments to avoid rate limiting
  • write a Factory to instantiate a pricing provider from Env config
  • makes timestampEnd optional for IPricingProvider

Checklist before requesting a review

  • I have conducted a self-review of my code.
  • I have conducted a QA.
  • If it is a core feature, I have included comprehensive tests.

@0xnigir1 0xnigir1 changed the title Feat/dummy pricing provider feat: dummy pricing provider Nov 13, 2024
Copy link
Collaborator

@0xkenj1 0xkenj1 left a comment

Choose a reason for hiding this comment

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

approved with smoll comment :)

Comment on lines +32 to +57
const dummyPricingSchema = baseSchema.extend({
PRICING_SOURCE: z.literal("dummy"),
DUMMY_PRICE: z.coerce.number().optional().default(1),
});

const coingeckoPricingSchema = baseSchema.extend({
PRICING_SOURCE: z.literal("coingecko"),
COINGECKO_API_KEY: z.string().min(1),
COINGECKO_API_TYPE: z.enum(["demo", "pro"]).default("pro"),
});

const validationSchema = z
.discriminatedUnion("PRICING_SOURCE", [dummyPricingSchema, coingeckoPricingSchema])
.transform((val) => {
if (val.PRICING_SOURCE === "dummy") {
return { pricingSource: val.PRICING_SOURCE, dummyPrice: val.DUMMY_PRICE, ...val };
}

return {
pricingSource: val.PRICING_SOURCE,
apiKey: val.COINGECKO_API_KEY,
apiType: val.COINGECKO_API_TYPE,
...val,
};
});

Copy link
Collaborator

Choose a reason for hiding this comment

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

We can move this into a different file in the future(not now), to have a more readable and modular code.

Copy link
Collaborator

@0xyaco 0xyaco left a comment

Choose a reason for hiding this comment

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

Super minor comments/questions, good to go!

@@ -13,5 +13,7 @@ INDEXER_ADMIN_SECRET=testing

IPFS_GATEWAYS_URL=["https://ipfs.io","https://gateway.pinata.cloud","https://dweb.link", "https://ipfs.eth.aragon.network"]

PRICING_SOURCE= #coingecko | dummy
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is that #coingecko ok?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

is # for comment, in next PR i'll add a whitespace

Comment on lines +38 to +40
if (!deps?.logger) {
throw new MissingDependencies();
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm wondering if we should standardize the dependencies validation with some kind of generic pattern (with the help of zod maybe?) while initializing objects.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

you mean inside constructors or having a zod schema here instead of if (!deps?.logger)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Zod schema could be a solution yeah. I'm thinking in general, whenever a service needs dependencies and those dependencies might need to accomodate themselves to some particular schema (like optional dependencies, some dependencies need to be present based on some other dependency value, etc)

I guess that applying a zod schema could cover 99% of the cases, I'll apply it in my code and I'll let you know how happy/sad it is to use it lol

constructor(private readonly dummyPrice: number = 1) {}

/* @inheritdoc */
async getTokenPrice(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Extremely minor detail but the async keyword here is not necessary given the Promise.resolve() usage

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ooo didn't know that

@0xnigir1 0xnigir1 merged commit 0d4872b into dev Nov 14, 2024
6 checks passed
@0xnigir1 0xnigir1 deleted the feat/dummy-pricing-provider branch November 14, 2024 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants