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/getPriceQuote #2065

Merged
merged 2 commits into from
Mar 4, 2025
Merged

Feat/getPriceQuote #2065

merged 2 commits into from
Mar 4, 2025

Conversation

brendan-defi
Copy link
Contributor

@brendan-defi brendan-defi commented Mar 3, 2025

What changed? Why?

  • added API endpoint getPriceQuote
    • getPriceQuote fetches price quotes for the provided token contract addresses and/or ETH
    • getPriceQuote is available only on Base mainnet

getPriceQuote interface

Request

type GetPriceQuoteParams = {
  tokens: PriceQuoteToken[];
};

Response

type GetPriceQuoteResponse =
  | {
      priceQuote: PriceQuote[];
    }
  | APIError;

type PriceQuote = {
  name: string | '';
  symbol: string | '';
  contractAddress: Address | '';
  price: string | '';
  timestamp: number | 0;
};

Usage

const response = getPriceQuote({ tokens: ["ETH", "0x123...ABC"] });
if (response.error) {
  throw New Error(priceQuotes.error)
}

const tokenPrice = response.priceQuotes[0].price;

Notes to reviewers

How has it been tested?

Comment on lines +53 to +54
error: 'Invalid input: tokens must be an array of at least one token',
message: '',
Copy link
Contributor

Choose a reason for hiding this comment

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

May be useful to have tokens must be an array of at least one token in the message ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good call, adding

Comment on lines +398 to +409
type PriceQuote = {
/** The name of the token */
name: string | '';
/** The symbol of the token */
symbol: string | '';
/** The contract address of the token */
contractAddress: Address | '';
/** The price of the token */
price: string | '';
/** The timestamp of the price quote */
timestamp: number | 0;
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Out of curiosity why the ''?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I haven't been able to discern the pattern, but sometimes the API doesn't return all the fields.

I don't think this is a problem, because it has so far always returned the contractAddress, and the caller should have all the other info.

Copy link
Contributor

Choose a reason for hiding this comment

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

wouldn't '' be covered under string?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@alessey ah, you're right, i can remove those nullish versions of the types. will handle in a follow-up

Copy link
Contributor

@abcrane123 abcrane123 left a comment

Choose a reason for hiding this comment

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

lgtm

@brendan-defi brendan-defi merged commit 87aefa6 into main Mar 4, 2025
16 checks passed
@brendan-defi brendan-defi deleted the feat/getpricequote branch March 4, 2025 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

4 participants