Skip to content

Commit 4d61c7a

Browse files
authored
Merge pull request #1762 from cprussin/api-reference-improvements
Implement API reference feedback
2 parents f5af412 + 018e3f9 commit 4d61c7a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+633
-825
lines changed

apps/api-reference/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.env*.local

apps/api-reference/next.config.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import withMDX from "@next/mdx";
2-
3-
const config = {
1+
export default {
42
reactStrictMode: true,
53

64
pageExtensions: ["ts", "tsx", "mdx"],
@@ -24,7 +22,7 @@ const config = {
2422
return config;
2523
},
2624

27-
transpilePackages: ["@pyth.network/*"],
25+
transpilePackages: ["@pythnetwork/*"],
2826

2927
headers: () => [
3028
{
@@ -55,5 +53,3 @@ const config = {
5553
},
5654
],
5755
};
58-
59-
export default withMDX()(config);

apps/api-reference/package.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"fix": "pnpm fix:format && pnpm fix:lint",
1212
"fix:format": "prettier --write .",
1313
"fix:lint": "eslint --fix .",
14+
"pull:env": "VERCEL_ORG_ID=team_BKQrg3JJFLxZyTqpuYtIY0rj VERCEL_PROJECT_ID=prj_gbljYVzp0m5EpCuOF6nZpM4WMFM6 vercel env pull",
1415
"start:dev": "next dev",
1516
"start:prod": "next start",
1617
"test": "tsc && jest",
@@ -21,13 +22,10 @@
2122
},
2223
"dependencies": {
2324
"@amplitude/analytics-browser": "^2.9.0",
25+
"@amplitude/plugin-autocapture-browser": "^0.9.0",
2426
"@floating-ui/react": "^0.26.17",
2527
"@headlessui/react": "^2.0.4",
2628
"@heroicons/react": "^2.1.4",
27-
"@mdx-js/loader": "^3.0.1",
28-
"@mdx-js/mdx": "^3.0.1",
29-
"@mdx-js/react": "^3.0.1",
30-
"@next/mdx": "^14.2.4",
3129
"@next/third-parties": "^14.2.4",
3230
"@pythnetwork/pyth-sdk-solidity": "workspace:^",
3331
"@tanstack/react-query": "^5.45.1",
@@ -39,6 +37,7 @@
3937
"pino": "^9.2.0",
4038
"react": "^18.3.1",
4139
"react-dom": "^18.3.1",
40+
"react-markdown": "^9.0.1",
4241
"shiki": "^1.7.0",
4342
"viem": "^2.15.1",
4443
"wagmi": "^2.10.4",
@@ -53,7 +52,6 @@
5352
"@svgr/webpack": "^8.1.0",
5453
"@tailwindcss/forms": "^0.5.7",
5554
"@types/jest": "^29.5.12",
56-
"@types/mdx": "^2.0.13",
5755
"@types/node": "^20.14.6",
5856
"@types/react": "^18.3.3",
5957
"@types/react-dom": "^18.3.0",
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
6486ae45-385f-4747-b8b5-885380fb4ec8=57ef2db8537f4094003f355e80ee6a28a072d4b95baba68db01bac4981ea0f1b

apps/api-reference/src/apis/evm/common.ts

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,14 @@ import {
1010
import { singletonArray, safeFetch } from "../../zod-utils";
1111

1212
export const readApi = <ParameterName extends string>(
13-
spec: Omit<ReadApi<ParameterName>, "children" | "type"> & {
14-
description: string;
15-
},
13+
spec: Omit<ReadApi<ParameterName>, "type">,
1614
) => ({
1715
...spec,
1816
type: EvmApiType.Read,
1917
});
2018

2119
export const writeApi = <ParameterName extends string>(
22-
spec: Omit<WriteApi<ParameterName>, "children" | "type"> & {
23-
description: string;
24-
},
20+
spec: Omit<WriteApi<ParameterName>, "type">,
2521
) => ({
2622
...spec,
2723
type: EvmApiType.Write,
@@ -34,19 +30,15 @@ export const ETHUSD =
3430

3531
const HERMES_URL = "https://hermes.pyth.network";
3632

37-
export const getLatestPriceFeed = async (feedId: string) => {
33+
export const getLatestPriceUpdate = async (feedId: string) => {
3834
const url = new URL("/v2/updates/price/latest", HERMES_URL);
3935
url.searchParams.set("ids[]", feedId);
40-
url.searchParams.set("target_chain", "evm");
41-
url.searchParams.set("binary", "true");
4236
return safeFetch(priceFeedSchema, url);
4337
};
4438

4539
const priceFeedSchema = z.object({
4640
binary: z.object({
47-
data: singletonArray(z.string()).transform((value) =>
48-
toZeroXPrefixedHex(value),
49-
),
41+
data: singletonArray(z.string()).transform((value) => `0x${value}`),
5042
}),
5143
parsed: singletonArray(
5244
z.object({
@@ -57,9 +49,6 @@ const priceFeedSchema = z.object({
5749
),
5850
});
5951

60-
const toZeroXPrefixedHex = (value: string) =>
61-
`0x${Buffer.from(value, "base64").toString("hex")}`;
62-
6352
export const solidity = <ParameterName extends string>(
6453
code: string | ((params: Partial<Record<ParameterName, string>>) => string),
6554
) => ({

apps/api-reference/src/apis/evm/get-ema-price-no-older-than.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { ParameterType } from "../../components/EvmApi";
66

77
export const getEmaPriceNoOlderThan = readApi<"id" | "age">({
88
name: "getEmaPriceNoOlderThan",
9+
summary:
10+
"Get the exponentially weighted moving average (EMA) price object with a published timestamp from before than `age` seconds in the past.",
911
description: `
1012
Get the latest exponentially-weighted moving average (EMA) price and confidence
1113
interval for the requested price feed id. The price feed id is a 32-byte id

apps/api-reference/src/apis/evm/get-ema-price-unsafe.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { ParameterType } from "../../components/EvmApi";
66

77
export const getEmaPriceUnsafe = readApi<"id">({
88
name: "getEmaPriceUnsafe",
9+
summary:
10+
"Get the **last updated** exponentially weighted moving average (EMA) price object for the requested price feed ID. _Caution: This function may return a price arbitrarily in the past_",
911
description: `
1012
Get the latest exponentially-weighted moving average (EMA) price and confidence
1113
interval for the requested price feed id. The price feed id is a 32-byte id

apps/api-reference/src/apis/evm/get-ema-price.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { ParameterType } from "../../components/EvmApi";
66

77
export const getEmaPrice = readApi<"id">({
88
name: "getEmaPrice",
9+
summary:
10+
"Get the **latest** exponentially weighted moving average (EMA) price object for the requested price feed ID.",
911
description: `
1012
Get the latest exponentially-weighted moving average (EMA) price and confidence
1113
interval for the requested price feed id. The price feed id is a 32-byte id

apps/api-reference/src/apis/evm/get-price-no-older-than.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { ParameterType } from "../../components/EvmApi";
66

77
export const getPriceNoOlderThan = readApi<"id" | "age">({
88
name: "getPriceNoOlderThan",
9+
summary:
10+
"Get the price object with a published timestamp from before than `age` seconds in the past.",
911
description: `
1012
Get the latest price and confidence interval for the requested price feed id, if
1113
it has been updated sufficiently recently. The price feed id is a 32-byte id

apps/api-reference/src/apis/evm/get-price-unsafe.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { ParameterType } from "../../components/EvmApi";
66

77
export const getPriceUnsafe = readApi<"id">({
88
name: "getPriceUnsafe",
9+
summary:
10+
"Get the **last updated** price object for the requested price feed ID. _Caution: This function may return a price from arbitrarily in the the past_",
911
description: `
1012
Get the latest price and confidence interval for the requested price feed id.
1113
The price feed id is a 32-byte id written as a hexadecimal string; see the

0 commit comments

Comments
 (0)