@pythnetwork/hermes-client 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zodSchemas.d.ts","sourceRoot":"","sources":["../src/zodSchemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,aAAa,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AA4CxB,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAYnB,CAAC;AA+IF,eAAO,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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schemas = void 0;
4
+ const core_1 = require("@zodios/core");
5
+ const zod_1 = require("zod");
6
+ const AssetType = zod_1.z.enum(["crypto", "fx", "equity", "metals", "rates"]);
7
+ const asset_type = AssetType.nullish();
8
+ const RpcPriceIdentifier = zod_1.z.string();
9
+ const PriceFeedMetadata = zod_1.z
10
+ .object({ attributes: zod_1.z.record(zod_1.z.string()), id: RpcPriceIdentifier })
11
+ .passthrough();
12
+ const PriceIdInput = zod_1.z.string();
13
+ const EncodingType = zod_1.z.enum(["hex", "base64"]);
14
+ const BinaryPriceUpdate = zod_1.z
15
+ .object({ data: zod_1.z.array(zod_1.z.string()), encoding: EncodingType })
16
+ .passthrough();
17
+ const RpcPrice = zod_1.z
18
+ .object({
19
+ conf: zod_1.z.string(),
20
+ expo: zod_1.z.number().int(),
21
+ price: zod_1.z.string(),
22
+ publish_time: zod_1.z.number().int(),
23
+ })
24
+ .passthrough();
25
+ const RpcPriceFeedMetadataV2 = zod_1.z
26
+ .object({
27
+ prev_publish_time: zod_1.z.number().int().nullable(),
28
+ proof_available_time: zod_1.z.number().int().nullable(),
29
+ slot: zod_1.z.number().int().gte(0).nullable(),
30
+ })
31
+ .partial()
32
+ .passthrough();
33
+ const ParsedPriceUpdate = zod_1.z
34
+ .object({
35
+ ema_price: RpcPrice,
36
+ id: RpcPriceIdentifier,
37
+ metadata: RpcPriceFeedMetadataV2,
38
+ price: RpcPrice,
39
+ })
40
+ .passthrough();
41
+ const PriceUpdate = zod_1.z
42
+ .object({
43
+ binary: BinaryPriceUpdate,
44
+ parsed: zod_1.z.array(ParsedPriceUpdate).nullish(),
45
+ })
46
+ .passthrough();
47
+ exports.schemas = {
48
+ AssetType,
49
+ asset_type,
50
+ RpcPriceIdentifier,
51
+ PriceFeedMetadata,
52
+ PriceIdInput,
53
+ EncodingType,
54
+ BinaryPriceUpdate,
55
+ RpcPrice,
56
+ RpcPriceFeedMetadataV2,
57
+ ParsedPriceUpdate,
58
+ PriceUpdate,
59
+ };
60
+ const endpoints = (0, core_1.makeApi)([
61
+ {
62
+ method: "get",
63
+ path: "/v2/price_feeds",
64
+ alias: "price_feeds_metadata",
65
+ description: `Get the set of price feeds.
66
+
67
+ This endpoint fetches all price feeds from the Pyth network. It can be filtered by asset type
68
+ and query string.`,
69
+ requestFormat: "json",
70
+ parameters: [
71
+ {
72
+ name: "query",
73
+ type: "Query",
74
+ schema: zod_1.z.string().nullish(),
75
+ },
76
+ {
77
+ name: "asset_type",
78
+ type: "Query",
79
+ schema: asset_type,
80
+ },
81
+ ],
82
+ response: zod_1.z.array(PriceFeedMetadata),
83
+ },
84
+ {
85
+ method: "get",
86
+ path: "/v2/updates/price/:publish_time",
87
+ alias: "timestamp_price_updates",
88
+ description: `Get the latest price updates by price feed id.
89
+
90
+ Given a collection of price feed ids, retrieve the latest Pyth price for each price feed.`,
91
+ requestFormat: "json",
92
+ parameters: [
93
+ {
94
+ name: "publish_time",
95
+ type: "Path",
96
+ schema: zod_1.z.number().int(),
97
+ },
98
+ {
99
+ name: "ids[]",
100
+ type: "Query",
101
+ schema: zod_1.z.array(PriceIdInput),
102
+ },
103
+ {
104
+ name: "encoding",
105
+ type: "Query",
106
+ schema: zod_1.z.enum(["hex", "base64"]).optional(),
107
+ },
108
+ {
109
+ name: "parsed",
110
+ type: "Query",
111
+ schema: zod_1.z.boolean().optional(),
112
+ },
113
+ ],
114
+ response: PriceUpdate,
115
+ errors: [
116
+ {
117
+ status: 404,
118
+ description: `Price ids not found`,
119
+ schema: zod_1.z.void(),
120
+ },
121
+ ],
122
+ },
123
+ {
124
+ method: "get",
125
+ path: "/v2/updates/price/latest",
126
+ alias: "latest_price_updates",
127
+ description: `Get the latest price updates by price feed id.
128
+
129
+ Given a collection of price feed ids, retrieve the latest Pyth price for each price feed.`,
130
+ requestFormat: "json",
131
+ parameters: [
132
+ {
133
+ name: "ids[]",
134
+ type: "Query",
135
+ schema: zod_1.z.array(PriceIdInput),
136
+ },
137
+ {
138
+ name: "encoding",
139
+ type: "Query",
140
+ schema: zod_1.z.enum(["hex", "base64"]).optional(),
141
+ },
142
+ {
143
+ name: "parsed",
144
+ type: "Query",
145
+ schema: zod_1.z.boolean().optional(),
146
+ },
147
+ ],
148
+ response: PriceUpdate,
149
+ errors: [
150
+ {
151
+ status: 404,
152
+ description: `Price ids not found`,
153
+ schema: zod_1.z.void(),
154
+ },
155
+ ],
156
+ },
157
+ {
158
+ method: "get",
159
+ path: "/v2/updates/price/stream",
160
+ alias: "price_stream_sse_handler",
161
+ description: `SSE route handler for streaming price updates.`,
162
+ requestFormat: "json",
163
+ parameters: [
164
+ {
165
+ name: "ids[]",
166
+ type: "Query",
167
+ schema: zod_1.z.array(PriceIdInput),
168
+ },
169
+ {
170
+ name: "encoding",
171
+ type: "Query",
172
+ schema: zod_1.z.enum(["hex", "base64"]).optional(),
173
+ },
174
+ {
175
+ name: "parsed",
176
+ type: "Query",
177
+ schema: zod_1.z.boolean().optional(),
178
+ },
179
+ {
180
+ name: "allow_unordered",
181
+ type: "Query",
182
+ schema: zod_1.z.boolean().optional(),
183
+ },
184
+ {
185
+ name: "benchmarks_only",
186
+ type: "Query",
187
+ schema: zod_1.z.boolean().optional(),
188
+ },
189
+ ],
190
+ response: PriceUpdate,
191
+ errors: [
192
+ {
193
+ status: 404,
194
+ description: `Price ids not found`,
195
+ schema: zod_1.z.void(),
196
+ },
197
+ ],
198
+ },
199
+ ]);
200
+ exports.api = new core_1.Zodios(endpoints);
201
+ function createApiClient(baseUrl, options) {
202
+ return new core_1.Zodios(baseUrl, endpoints, options);
203
+ }
204
+ exports.createApiClient = createApiClient;
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@pythnetwork/hermes-client",
3
+ "version": "1.0.0",
4
+ "description": "Pyth Hermes Client",
5
+ "author": {
6
+ "name": "Pyth Data Association"
7
+ },
8
+ "homepage": "https://pyth.network",
9
+ "main": "lib/HermesClient.js",
10
+ "types": "lib/HermesClient.d.ts",
11
+ "files": [
12
+ "lib/**/*"
13
+ ],
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/pyth-network/pyth-crosschain",
17
+ "directory": "apps/hermes/client/js"
18
+ },
19
+ "publishConfig": {
20
+ "access": "public"
21
+ },
22
+ "scripts": {
23
+ "test": "jest --testPathIgnorePatterns=.*.e2e.test.ts --passWithNoTests",
24
+ "test:e2e": "jest --testPathPattern=.*.e2e.test.ts",
25
+ "build": "tsc",
26
+ "generate-hermes-api-types": "openapi-zod-client https://hermes.pyth.network/docs/openapi.json --output src/zodSchemas.ts && prettier --write src/zodSchemas.ts",
27
+ "check-hermes-api-types": "git diff --exit-code src/zodSchemas.ts",
28
+ "example": "npm run build && node lib/examples/HermesClient.js",
29
+ "format": "prettier --write \"src/**/*.ts\"",
30
+ "lint": "eslint src/",
31
+ "prepublishOnly": "npm run build && npm test && npm run lint",
32
+ "preversion": "npm run lint",
33
+ "version": "npm run format && git add -A src"
34
+ },
35
+ "keywords": [
36
+ "pyth",
37
+ "oracle"
38
+ ],
39
+ "license": "Apache-2.0",
40
+ "devDependencies": {
41
+ "@types/eventsource": "^1.1.15",
42
+ "@types/jest": "^29.4.0",
43
+ "@types/yargs": "^17.0.10",
44
+ "@typescript-eslint/eslint-plugin": "^5.21.0",
45
+ "@typescript-eslint/parser": "^5.21.0",
46
+ "eslint": "^8.14.0",
47
+ "jest": "^29.4.0",
48
+ "openapi-zod-client": "^1.18.1",
49
+ "prettier": "^2.6.2",
50
+ "ts-jest": "^29.0.5",
51
+ "typescript": "^4.6.3",
52
+ "yargs": "^17.4.1"
53
+ },
54
+ "dependencies": {
55
+ "eventsource": "^2.0.2",
56
+ "zod": "^3.23.8"
57
+ },
58
+ "gitHead": "113f8797625be44370b31c73b22bd115a3e167aa"
59
+ }