Skip to content

Commit 54f584d

Browse files
authored
feat(lazer): add new formats to js sdk (#2430)
* feat(lazer): add new formats to js sdk * chore: bump version
1 parent ad49514 commit 54f584d

File tree

4 files changed

+30
-19
lines changed

4 files changed

+30
-19
lines changed

lazer/sdk/js/examples/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ await client.subscribe({
5252
subscriptionId: 1,
5353
priceFeedIds: [1, 2],
5454
properties: ["price"],
55-
chains: ["solana"],
55+
formats: ["solana"],
5656
deliveryFormat: "binary",
5757
channel: "fixed_rate@200ms",
5858
parsed: false,
@@ -63,7 +63,7 @@ await client.subscribe({
6363
subscriptionId: 2,
6464
priceFeedIds: [1, 2, 3, 4, 5],
6565
properties: ["price", "exponent", "publisherCount", "confidence"],
66-
chains: ["evm"],
66+
formats: ["evm"],
6767
deliveryFormat: "json",
6868
channel: "fixed_rate@200ms",
6969
parsed: true,

lazer/sdk/js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pythnetwork/pyth-lazer-sdk",
3-
"version": "0.3.3",
3+
"version": "0.4.0",
44
"description": "Pyth Lazer SDK",
55
"publishConfig": {
66
"access": "public"

lazer/sdk/js/src/client.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ import WebSocket from "isomorphic-ws";
22
import { dummyLogger, type Logger } from "ts-log";
33

44
import {
5-
BINARY_UPDATE_FORMAT_MAGIC,
6-
EVM_FORMAT_MAGIC,
7-
PARSED_FORMAT_MAGIC,
5+
BINARY_UPDATE_FORMAT_MAGIC_LE,
6+
FORMAT_MAGICS_LE,
87
type ParsedPayload,
98
type Request,
109
type Response,
11-
SOLANA_FORMAT_MAGIC_BE,
1210
} from "./protocol.js";
1311
import { WebSocketPool } from "./socket/websocket-pool.js";
1412

@@ -17,6 +15,8 @@ export type BinaryResponse = {
1715
evm?: Buffer | undefined;
1816
solana?: Buffer | undefined;
1917
parsed?: ParsedPayload | undefined;
18+
leEcdsa?: Buffer | undefined;
19+
leUnsigned?: Buffer | undefined;
2020
};
2121
export type JsonOrBinaryResponse =
2222
| {
@@ -64,9 +64,9 @@ export class PythLazerClient {
6464
});
6565
} else if (Buffer.isBuffer(data)) {
6666
let pos = 0;
67-
const magic = data.subarray(pos, pos + UINT32_NUM_BYTES).readUint32BE();
67+
const magic = data.subarray(pos, pos + UINT32_NUM_BYTES).readUint32LE();
6868
pos += UINT32_NUM_BYTES;
69-
if (magic != BINARY_UPDATE_FORMAT_MAGIC) {
69+
if (magic != BINARY_UPDATE_FORMAT_MAGIC_LE) {
7070
throw new Error("binary update format magic mismatch");
7171
}
7272
// TODO: some uint64 values may not be representable as Number.
@@ -81,12 +81,16 @@ export class PythLazerClient {
8181
pos += UINT16_NUM_BYTES;
8282
const magic = data
8383
.subarray(pos, pos + UINT32_NUM_BYTES)
84-
.readUint32BE();
85-
if (magic == EVM_FORMAT_MAGIC) {
84+
.readUint32LE();
85+
if (magic == FORMAT_MAGICS_LE.EVM) {
8686
value.evm = data.subarray(pos, pos + len);
87-
} else if (magic == SOLANA_FORMAT_MAGIC_BE) {
87+
} else if (magic == FORMAT_MAGICS_LE.SOLANA) {
8888
value.solana = data.subarray(pos, pos + len);
89-
} else if (magic == PARSED_FORMAT_MAGIC) {
89+
} else if (magic == FORMAT_MAGICS_LE.LE_ECDSA) {
90+
value.leEcdsa = data.subarray(pos, pos + len);
91+
} else if (magic == FORMAT_MAGICS_LE.LE_UNSIGNED) {
92+
value.leUnsigned = data.subarray(pos, pos + len);
93+
} else if (magic == FORMAT_MAGICS_LE.JSON) {
9094
value.parsed = JSON.parse(
9195
data.subarray(pos + UINT32_NUM_BYTES, pos + len).toString()
9296
) as ParsedPayload;

lazer/sdk/js/src/protocol.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export type Chain = "evm" | "solana";
1+
export type Format = "evm" | "solana" | "leEcdsa" | "leUnsigned";
22
export type DeliveryFormat = "json" | "binary";
33
export type JsonBinaryEncoding = "base64" | "hex";
44
export type PriceFeedProperty =
@@ -16,7 +16,7 @@ export type Request =
1616
subscriptionId: number;
1717
priceFeedIds: number[];
1818
properties: PriceFeedProperty[];
19-
chains: Chain[];
19+
formats: Format[];
2020
deliveryFormat?: DeliveryFormat;
2121
jsonBinaryEncoding?: JsonBinaryEncoding;
2222
parsed?: boolean;
@@ -71,9 +71,16 @@ export type Response =
7171
parsed?: ParsedPayload | undefined;
7272
evm?: JsonBinaryData | undefined;
7373
solana?: JsonBinaryData | undefined;
74+
leEcdsa?: JsonBinaryData | undefined;
75+
leUnsigned?: JsonBinaryData | undefined;
7476
};
7577

76-
export const BINARY_UPDATE_FORMAT_MAGIC = 1_937_213_467;
77-
export const PARSED_FORMAT_MAGIC = 2_584_795_844;
78-
export const EVM_FORMAT_MAGIC = 706_910_618;
79-
export const SOLANA_FORMAT_MAGIC_BE = 3_103_857_282;
78+
export const BINARY_UPDATE_FORMAT_MAGIC_LE = 461_928_307;
79+
80+
export const FORMAT_MAGICS_LE = {
81+
JSON: 3_302_625_434,
82+
EVM: 2_593_727_018,
83+
SOLANA: 2_182_742_457,
84+
LE_ECDSA: 1_296_547_300,
85+
LE_UNSIGNED: 1_499_680_012,
86+
};

0 commit comments

Comments
 (0)