diff --git a/lazer/sdk/js/examples/index.ts b/lazer/sdk/js/examples/index.ts index 3c3ea22657..21c9d734ea 100644 --- a/lazer/sdk/js/examples/index.ts +++ b/lazer/sdk/js/examples/index.ts @@ -52,7 +52,7 @@ await client.subscribe({ subscriptionId: 1, priceFeedIds: [1, 2], properties: ["price"], - chains: ["solana"], + formats: ["solana"], deliveryFormat: "binary", channel: "fixed_rate@200ms", parsed: false, @@ -63,7 +63,7 @@ await client.subscribe({ subscriptionId: 2, priceFeedIds: [1, 2, 3, 4, 5], properties: ["price", "exponent", "publisherCount", "confidence"], - chains: ["evm"], + formats: ["evm"], deliveryFormat: "json", channel: "fixed_rate@200ms", parsed: true, diff --git a/lazer/sdk/js/package.json b/lazer/sdk/js/package.json index 37bd04d0e4..ac165e0b0c 100644 --- a/lazer/sdk/js/package.json +++ b/lazer/sdk/js/package.json @@ -1,6 +1,6 @@ { "name": "@pythnetwork/pyth-lazer-sdk", - "version": "0.3.3", + "version": "0.4.0", "description": "Pyth Lazer SDK", "publishConfig": { "access": "public" diff --git a/lazer/sdk/js/src/client.ts b/lazer/sdk/js/src/client.ts index 755b426129..3626757aff 100644 --- a/lazer/sdk/js/src/client.ts +++ b/lazer/sdk/js/src/client.ts @@ -2,13 +2,11 @@ import WebSocket from "isomorphic-ws"; import { dummyLogger, type Logger } from "ts-log"; import { - BINARY_UPDATE_FORMAT_MAGIC, - EVM_FORMAT_MAGIC, - PARSED_FORMAT_MAGIC, + BINARY_UPDATE_FORMAT_MAGIC_LE, + FORMAT_MAGICS_LE, type ParsedPayload, type Request, type Response, - SOLANA_FORMAT_MAGIC_BE, } from "./protocol.js"; import { WebSocketPool } from "./socket/websocket-pool.js"; @@ -17,6 +15,8 @@ export type BinaryResponse = { evm?: Buffer | undefined; solana?: Buffer | undefined; parsed?: ParsedPayload | undefined; + leEcdsa?: Buffer | undefined; + leUnsigned?: Buffer | undefined; }; export type JsonOrBinaryResponse = | { @@ -64,9 +64,9 @@ export class PythLazerClient { }); } else if (Buffer.isBuffer(data)) { let pos = 0; - const magic = data.subarray(pos, pos + UINT32_NUM_BYTES).readUint32BE(); + const magic = data.subarray(pos, pos + UINT32_NUM_BYTES).readUint32LE(); pos += UINT32_NUM_BYTES; - if (magic != BINARY_UPDATE_FORMAT_MAGIC) { + if (magic != BINARY_UPDATE_FORMAT_MAGIC_LE) { throw new Error("binary update format magic mismatch"); } // TODO: some uint64 values may not be representable as Number. @@ -81,12 +81,16 @@ export class PythLazerClient { pos += UINT16_NUM_BYTES; const magic = data .subarray(pos, pos + UINT32_NUM_BYTES) - .readUint32BE(); - if (magic == EVM_FORMAT_MAGIC) { + .readUint32LE(); + if (magic == FORMAT_MAGICS_LE.EVM) { value.evm = data.subarray(pos, pos + len); - } else if (magic == SOLANA_FORMAT_MAGIC_BE) { + } else if (magic == FORMAT_MAGICS_LE.SOLANA) { value.solana = data.subarray(pos, pos + len); - } else if (magic == PARSED_FORMAT_MAGIC) { + } else if (magic == FORMAT_MAGICS_LE.LE_ECDSA) { + value.leEcdsa = data.subarray(pos, pos + len); + } else if (magic == FORMAT_MAGICS_LE.LE_UNSIGNED) { + value.leUnsigned = data.subarray(pos, pos + len); + } else if (magic == FORMAT_MAGICS_LE.JSON) { value.parsed = JSON.parse( data.subarray(pos + UINT32_NUM_BYTES, pos + len).toString() ) as ParsedPayload; diff --git a/lazer/sdk/js/src/protocol.ts b/lazer/sdk/js/src/protocol.ts index 8ca021232f..e698d7b88d 100644 --- a/lazer/sdk/js/src/protocol.ts +++ b/lazer/sdk/js/src/protocol.ts @@ -1,4 +1,4 @@ -export type Chain = "evm" | "solana"; +export type Format = "evm" | "solana" | "leEcdsa" | "leUnsigned"; export type DeliveryFormat = "json" | "binary"; export type JsonBinaryEncoding = "base64" | "hex"; export type PriceFeedProperty = @@ -16,7 +16,7 @@ export type Request = subscriptionId: number; priceFeedIds: number[]; properties: PriceFeedProperty[]; - chains: Chain[]; + formats: Format[]; deliveryFormat?: DeliveryFormat; jsonBinaryEncoding?: JsonBinaryEncoding; parsed?: boolean; @@ -71,9 +71,16 @@ export type Response = parsed?: ParsedPayload | undefined; evm?: JsonBinaryData | undefined; solana?: JsonBinaryData | undefined; + leEcdsa?: JsonBinaryData | undefined; + leUnsigned?: JsonBinaryData | undefined; }; -export const BINARY_UPDATE_FORMAT_MAGIC = 1_937_213_467; -export const PARSED_FORMAT_MAGIC = 2_584_795_844; -export const EVM_FORMAT_MAGIC = 706_910_618; -export const SOLANA_FORMAT_MAGIC_BE = 3_103_857_282; +export const BINARY_UPDATE_FORMAT_MAGIC_LE = 461_928_307; + +export const FORMAT_MAGICS_LE = { + JSON: 3_302_625_434, + EVM: 2_593_727_018, + SOLANA: 2_182_742_457, + LE_ECDSA: 1_296_547_300, + LE_UNSIGNED: 1_499_680_012, +};