@pythnetwork/pyth-lazer-sdk 0.3.3 → 0.5.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.
@@ -1,10 +1,12 @@
1
- import { type Logger } from "ts-log";
2
- import { type ParsedPayload, type Request, type Response } from "./protocol.js";
1
+ import type { Logger } from "ts-log";
2
+ import type { ParsedPayload, Request, Response } from "./protocol.js";
3
3
  export type BinaryResponse = {
4
4
  subscriptionId: number;
5
5
  evm?: Buffer | undefined;
6
6
  solana?: Buffer | undefined;
7
7
  parsed?: ParsedPayload | undefined;
8
+ leEcdsa?: Buffer | undefined;
9
+ leUnsigned?: Buffer | undefined;
8
10
  };
9
11
  export type JsonOrBinaryResponse = {
10
12
  type: "json";
@@ -39,9 +39,9 @@ class PythLazerClient {
39
39
  }
40
40
  else if (Buffer.isBuffer(data)) {
41
41
  let pos = 0;
42
- const magic = data.subarray(pos, pos + UINT32_NUM_BYTES).readUint32BE();
42
+ const magic = data.subarray(pos, pos + UINT32_NUM_BYTES).readUint32LE();
43
43
  pos += UINT32_NUM_BYTES;
44
- if (magic != protocol_js_1.BINARY_UPDATE_FORMAT_MAGIC) {
44
+ if (magic != protocol_js_1.BINARY_UPDATE_FORMAT_MAGIC_LE) {
45
45
  throw new Error("binary update format magic mismatch");
46
46
  }
47
47
  // TODO: some uint64 values may not be representable as Number.
@@ -53,14 +53,20 @@ class PythLazerClient {
53
53
  pos += UINT16_NUM_BYTES;
54
54
  const magic = data
55
55
  .subarray(pos, pos + UINT32_NUM_BYTES)
56
- .readUint32BE();
57
- if (magic == protocol_js_1.EVM_FORMAT_MAGIC) {
56
+ .readUint32LE();
57
+ if (magic == protocol_js_1.FORMAT_MAGICS_LE.EVM) {
58
58
  value.evm = data.subarray(pos, pos + len);
59
59
  }
60
- else if (magic == protocol_js_1.SOLANA_FORMAT_MAGIC_BE) {
60
+ else if (magic == protocol_js_1.FORMAT_MAGICS_LE.SOLANA) {
61
61
  value.solana = data.subarray(pos, pos + len);
62
62
  }
63
- else if (magic == protocol_js_1.PARSED_FORMAT_MAGIC) {
63
+ else if (magic == protocol_js_1.FORMAT_MAGICS_LE.LE_ECDSA) {
64
+ value.leEcdsa = data.subarray(pos, pos + len);
65
+ }
66
+ else if (magic == protocol_js_1.FORMAT_MAGICS_LE.LE_UNSIGNED) {
67
+ value.leUnsigned = data.subarray(pos, pos + len);
68
+ }
69
+ else if (magic == protocol_js_1.FORMAT_MAGICS_LE.JSON) {
64
70
  value.parsed = JSON.parse(data.subarray(pos + UINT32_NUM_BYTES, pos + len).toString());
65
71
  }
66
72
  else {
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
26
36
  exports.createEd25519Instruction = void 0;
27
37
  const BufferLayout = __importStar(require("@solana/buffer-layout"));
@@ -1,4 +1,4 @@
1
- export type Chain = "evm" | "solana";
1
+ export type Format = "evm" | "solana" | "leEcdsa" | "leUnsigned";
2
2
  export type DeliveryFormat = "json" | "binary";
3
3
  export type JsonBinaryEncoding = "base64" | "hex";
4
4
  export type PriceFeedProperty = "price" | "bestBidPrice" | "bestAskPrice" | "exponent" | "publisherCount" | "confidence";
@@ -8,10 +8,11 @@ export type Request = {
8
8
  subscriptionId: number;
9
9
  priceFeedIds: number[];
10
10
  properties: PriceFeedProperty[];
11
- chains: Chain[];
11
+ formats: Format[];
12
12
  deliveryFormat?: DeliveryFormat;
13
13
  jsonBinaryEncoding?: JsonBinaryEncoding;
14
14
  parsed?: boolean;
15
+ ignoreInvalidFeedIds?: boolean;
15
16
  channel: Channel;
16
17
  } | {
17
18
  type: "unsubscribe";
@@ -34,12 +35,22 @@ export type JsonBinaryData = {
34
35
  encoding: JsonBinaryEncoding;
35
36
  data: string;
36
37
  };
38
+ export type InvalidFeedSubscriptionDetails = {
39
+ unknownIds: number[];
40
+ unsupportedChannels: number[];
41
+ unstable: number[];
42
+ };
37
43
  export type Response = {
38
44
  type: "error";
39
45
  error: string;
40
46
  } | {
41
47
  type: "subscribed";
42
48
  subscriptionId: number;
49
+ } | {
50
+ type: "subscribedWithInvalidFeedIdsIgnored";
51
+ subscriptionId: number;
52
+ subscribedFeedIds: number[];
53
+ ignoredInvalidFeedIds: InvalidFeedSubscriptionDetails;
43
54
  } | {
44
55
  type: "unsubscribed";
45
56
  subscriptionId: number;
@@ -53,8 +64,14 @@ export type Response = {
53
64
  parsed?: ParsedPayload | undefined;
54
65
  evm?: JsonBinaryData | undefined;
55
66
  solana?: JsonBinaryData | undefined;
67
+ leEcdsa?: JsonBinaryData | undefined;
68
+ leUnsigned?: JsonBinaryData | undefined;
69
+ };
70
+ export declare const BINARY_UPDATE_FORMAT_MAGIC_LE = 461928307;
71
+ export declare const FORMAT_MAGICS_LE: {
72
+ JSON: number;
73
+ EVM: number;
74
+ SOLANA: number;
75
+ LE_ECDSA: number;
76
+ LE_UNSIGNED: number;
56
77
  };
57
- export declare const BINARY_UPDATE_FORMAT_MAGIC = 1937213467;
58
- export declare const PARSED_FORMAT_MAGIC = 2584795844;
59
- export declare const EVM_FORMAT_MAGIC = 706910618;
60
- export declare const SOLANA_FORMAT_MAGIC_BE = 3103857282;
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SOLANA_FORMAT_MAGIC_BE = exports.EVM_FORMAT_MAGIC = exports.PARSED_FORMAT_MAGIC = exports.BINARY_UPDATE_FORMAT_MAGIC = void 0;
4
- exports.BINARY_UPDATE_FORMAT_MAGIC = 1_937_213_467;
5
- exports.PARSED_FORMAT_MAGIC = 2_584_795_844;
6
- exports.EVM_FORMAT_MAGIC = 706_910_618;
7
- exports.SOLANA_FORMAT_MAGIC_BE = 3_103_857_282;
3
+ exports.FORMAT_MAGICS_LE = exports.BINARY_UPDATE_FORMAT_MAGIC_LE = void 0;
4
+ exports.BINARY_UPDATE_FORMAT_MAGIC_LE = 461_928_307;
5
+ exports.FORMAT_MAGICS_LE = {
6
+ JSON: 3_302_625_434,
7
+ EVM: 2_593_727_018,
8
+ SOLANA: 2_182_742_457,
9
+ LE_ECDSA: 1_296_547_300,
10
+ LE_UNSIGNED: 1_499_680_012,
11
+ };
@@ -1,5 +1,6 @@
1
1
  import type { ClientRequestArgs } from "node:http";
2
- import WebSocket, { type ClientOptions, type ErrorEvent } from "isomorphic-ws";
2
+ import type { ClientOptions, ErrorEvent } from "isomorphic-ws";
3
+ import WebSocket from "isomorphic-ws";
3
4
  import type { Logger } from "ts-log";
4
5
  export declare class ResilientWebSocket {
5
6
  endpoint: string;
@@ -1,7 +1,7 @@
1
1
  import WebSocket from "isomorphic-ws";
2
- import { type Logger } from "ts-log";
3
- import { ResilientWebSocket } from "./resilient-websocket.js";
2
+ import type { Logger } from "ts-log";
4
3
  import type { Request } from "../protocol.js";
4
+ import { ResilientWebSocket } from "./resilient-websocket.js";
5
5
  export declare class WebSocketPool {
6
6
  private readonly logger;
7
7
  rwsPool: ResilientWebSocket[];
@@ -1,10 +1,12 @@
1
- import { type Logger } from "ts-log";
2
- import { type ParsedPayload, type Request, type Response } from "./protocol.js";
1
+ import type { Logger } from "ts-log";
2
+ import type { ParsedPayload, Request, Response } from "./protocol.js";
3
3
  export type BinaryResponse = {
4
4
  subscriptionId: number;
5
5
  evm?: Buffer | undefined;
6
6
  solana?: Buffer | undefined;
7
7
  parsed?: ParsedPayload | undefined;
8
+ leEcdsa?: Buffer | undefined;
9
+ leUnsigned?: Buffer | undefined;
8
10
  };
9
11
  export type JsonOrBinaryResponse = {
10
12
  type: "json";
@@ -1,6 +1,6 @@
1
1
  import WebSocket from "isomorphic-ws";
2
2
  import { dummyLogger } from "ts-log";
3
- import { BINARY_UPDATE_FORMAT_MAGIC, EVM_FORMAT_MAGIC, PARSED_FORMAT_MAGIC, SOLANA_FORMAT_MAGIC_BE, } from "./protocol.js";
3
+ import { BINARY_UPDATE_FORMAT_MAGIC_LE, FORMAT_MAGICS_LE } from "./protocol.js";
4
4
  import { WebSocketPool } from "./socket/websocket-pool.js";
5
5
  const UINT16_NUM_BYTES = 2;
6
6
  const UINT32_NUM_BYTES = 4;
@@ -37,9 +37,9 @@ export class PythLazerClient {
37
37
  }
38
38
  else if (Buffer.isBuffer(data)) {
39
39
  let pos = 0;
40
- const magic = data.subarray(pos, pos + UINT32_NUM_BYTES).readUint32BE();
40
+ const magic = data.subarray(pos, pos + UINT32_NUM_BYTES).readUint32LE();
41
41
  pos += UINT32_NUM_BYTES;
42
- if (magic != BINARY_UPDATE_FORMAT_MAGIC) {
42
+ if (magic != BINARY_UPDATE_FORMAT_MAGIC_LE) {
43
43
  throw new Error("binary update format magic mismatch");
44
44
  }
45
45
  // TODO: some uint64 values may not be representable as Number.
@@ -51,14 +51,20 @@ export class PythLazerClient {
51
51
  pos += UINT16_NUM_BYTES;
52
52
  const magic = data
53
53
  .subarray(pos, pos + UINT32_NUM_BYTES)
54
- .readUint32BE();
55
- if (magic == EVM_FORMAT_MAGIC) {
54
+ .readUint32LE();
55
+ if (magic == FORMAT_MAGICS_LE.EVM) {
56
56
  value.evm = data.subarray(pos, pos + len);
57
57
  }
58
- else if (magic == SOLANA_FORMAT_MAGIC_BE) {
58
+ else if (magic == FORMAT_MAGICS_LE.SOLANA) {
59
59
  value.solana = data.subarray(pos, pos + len);
60
60
  }
61
- else if (magic == PARSED_FORMAT_MAGIC) {
61
+ else if (magic == FORMAT_MAGICS_LE.LE_ECDSA) {
62
+ value.leEcdsa = data.subarray(pos, pos + len);
63
+ }
64
+ else if (magic == FORMAT_MAGICS_LE.LE_UNSIGNED) {
65
+ value.leUnsigned = data.subarray(pos, pos + len);
66
+ }
67
+ else if (magic == FORMAT_MAGICS_LE.JSON) {
62
68
  value.parsed = JSON.parse(data.subarray(pos + UINT32_NUM_BYTES, pos + len).toString());
63
69
  }
64
70
  else {
@@ -1,4 +1,4 @@
1
- export type Chain = "evm" | "solana";
1
+ export type Format = "evm" | "solana" | "leEcdsa" | "leUnsigned";
2
2
  export type DeliveryFormat = "json" | "binary";
3
3
  export type JsonBinaryEncoding = "base64" | "hex";
4
4
  export type PriceFeedProperty = "price" | "bestBidPrice" | "bestAskPrice" | "exponent" | "publisherCount" | "confidence";
@@ -8,10 +8,11 @@ export type Request = {
8
8
  subscriptionId: number;
9
9
  priceFeedIds: number[];
10
10
  properties: PriceFeedProperty[];
11
- chains: Chain[];
11
+ formats: Format[];
12
12
  deliveryFormat?: DeliveryFormat;
13
13
  jsonBinaryEncoding?: JsonBinaryEncoding;
14
14
  parsed?: boolean;
15
+ ignoreInvalidFeedIds?: boolean;
15
16
  channel: Channel;
16
17
  } | {
17
18
  type: "unsubscribe";
@@ -34,12 +35,22 @@ export type JsonBinaryData = {
34
35
  encoding: JsonBinaryEncoding;
35
36
  data: string;
36
37
  };
38
+ export type InvalidFeedSubscriptionDetails = {
39
+ unknownIds: number[];
40
+ unsupportedChannels: number[];
41
+ unstable: number[];
42
+ };
37
43
  export type Response = {
38
44
  type: "error";
39
45
  error: string;
40
46
  } | {
41
47
  type: "subscribed";
42
48
  subscriptionId: number;
49
+ } | {
50
+ type: "subscribedWithInvalidFeedIdsIgnored";
51
+ subscriptionId: number;
52
+ subscribedFeedIds: number[];
53
+ ignoredInvalidFeedIds: InvalidFeedSubscriptionDetails;
43
54
  } | {
44
55
  type: "unsubscribed";
45
56
  subscriptionId: number;
@@ -53,8 +64,14 @@ export type Response = {
53
64
  parsed?: ParsedPayload | undefined;
54
65
  evm?: JsonBinaryData | undefined;
55
66
  solana?: JsonBinaryData | undefined;
67
+ leEcdsa?: JsonBinaryData | undefined;
68
+ leUnsigned?: JsonBinaryData | undefined;
69
+ };
70
+ export declare const BINARY_UPDATE_FORMAT_MAGIC_LE = 461928307;
71
+ export declare const FORMAT_MAGICS_LE: {
72
+ JSON: number;
73
+ EVM: number;
74
+ SOLANA: number;
75
+ LE_ECDSA: number;
76
+ LE_UNSIGNED: number;
56
77
  };
57
- export declare const BINARY_UPDATE_FORMAT_MAGIC = 1937213467;
58
- export declare const PARSED_FORMAT_MAGIC = 2584795844;
59
- export declare const EVM_FORMAT_MAGIC = 706910618;
60
- export declare const SOLANA_FORMAT_MAGIC_BE = 3103857282;
@@ -1,4 +1,8 @@
1
- export const BINARY_UPDATE_FORMAT_MAGIC = 1_937_213_467;
2
- export const PARSED_FORMAT_MAGIC = 2_584_795_844;
3
- export const EVM_FORMAT_MAGIC = 706_910_618;
4
- export const SOLANA_FORMAT_MAGIC_BE = 3_103_857_282;
1
+ export const BINARY_UPDATE_FORMAT_MAGIC_LE = 461_928_307;
2
+ export const FORMAT_MAGICS_LE = {
3
+ JSON: 3_302_625_434,
4
+ EVM: 2_593_727_018,
5
+ SOLANA: 2_182_742_457,
6
+ LE_ECDSA: 1_296_547_300,
7
+ LE_UNSIGNED: 1_499_680_012,
8
+ };
@@ -1,5 +1,6 @@
1
1
  import type { ClientRequestArgs } from "node:http";
2
- import WebSocket, { type ClientOptions, type ErrorEvent } from "isomorphic-ws";
2
+ import type { ClientOptions, ErrorEvent } from "isomorphic-ws";
3
+ import WebSocket from "isomorphic-ws";
3
4
  import type { Logger } from "ts-log";
4
5
  export declare class ResilientWebSocket {
5
6
  endpoint: string;
@@ -1,4 +1,4 @@
1
- import WebSocket, {} from "isomorphic-ws";
1
+ import WebSocket from "isomorphic-ws";
2
2
  const HEARTBEAT_TIMEOUT_DURATION = 10_000;
3
3
  const CONNECTION_TIMEOUT = 5000;
4
4
  export class ResilientWebSocket {
@@ -1,7 +1,7 @@
1
1
  import WebSocket from "isomorphic-ws";
2
- import { type Logger } from "ts-log";
3
- import { ResilientWebSocket } from "./resilient-websocket.js";
2
+ import type { Logger } from "ts-log";
4
3
  import type { Request } from "../protocol.js";
4
+ import { ResilientWebSocket } from "./resilient-websocket.js";
5
5
  export declare class WebSocketPool {
6
6
  private readonly logger;
7
7
  rwsPool: ResilientWebSocket[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pythnetwork/pyth-lazer-sdk",
3
- "version": "0.3.3",
3
+ "version": "0.5.0",
4
4
  "description": "Pyth Lazer SDK",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -23,26 +23,25 @@
23
23
  "scripts": {
24
24
  "build:cjs": "tsc --project tsconfig.build.json --verbatimModuleSyntax false --module commonjs --outDir ./dist/cjs && echo '{\"type\":\"commonjs\"}' > dist/cjs/package.json",
25
25
  "build:esm": "tsc --project tsconfig.build.json --outDir ./dist/esm && echo '{\"type\":\"module\"}' > dist/esm/package.json",
26
- "fix:lint": "eslint --fix .",
27
- "test:lint": "eslint .",
26
+ "fix:lint": "eslint --fix . --max-warnings 0",
27
+ "test:lint": "eslint . --max-warnings 0",
28
28
  "test:types": "tsc",
29
+ "test:format": "prettier --check .",
30
+ "fix:format": "prettier --write .",
29
31
  "example": "node --loader ts-node/esm examples/index.js",
30
32
  "doc": "typedoc --out docs/typedoc src",
31
33
  "publish": "pnpm run script -- publish"
32
34
  },
33
35
  "devDependencies": {
34
- "@cprussin/eslint-config": "^3.0.0",
35
- "@cprussin/tsconfig": "^3.0.1",
36
- "@eslint/js": "^9.12.0",
37
- "@types/eslint__js": "^8.42.3",
36
+ "@cprussin/eslint-config": "catalog:",
37
+ "@cprussin/tsconfig": "catalog:",
38
38
  "@types/node": "^18.19.54",
39
39
  "@types/ws": "^8.5.12",
40
- "eslint": "^9.12.0",
41
- "prettier": "^3.3.3",
42
- "ts-node": "^10.9.2",
40
+ "eslint": "catalog:",
41
+ "prettier": "catalog:",
42
+ "ts-node": "catalog:",
43
43
  "typedoc": "^0.26.8",
44
- "typescript": ">=5.5.0 < 5.6.0",
45
- "typescript-eslint": "^8.8.0"
44
+ "typescript": "catalog:"
46
45
  },
47
46
  "bugs": {
48
47
  "url": "https://github.com/pyth-lazer-sdk/pyth-lazer-sdk/issues"
@@ -67,5 +66,5 @@
67
66
  "ts-log": "^2.2.7",
68
67
  "ws": "^8.18.0"
69
68
  },
70
- "gitHead": "5aababcf9efb72594ab8f5e1083454f2ecab1c43"
69
+ "gitHead": "da6c1185d9fce5e6ca2df4f7e6e1f5edc9b366eb"
71
70
  }