@pythnetwork/pyth-lazer-sdk 0.1.0 → 0.1.2
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.
- package/dist/cjs/client.d.ts +21 -0
- package/dist/cjs/client.js +73 -0
- package/dist/cjs/ed25519.d.ts +2 -0
- package/dist/cjs/ed25519.js +69 -0
- package/dist/cjs/index.d.ts +3 -0
- package/dist/cjs/index.js +19 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/protocol.d.ts +57 -0
- package/dist/cjs/protocol.js +7 -0
- package/dist/esm/client.d.ts +21 -0
- package/dist/esm/client.js +66 -0
- package/dist/esm/ed25519.d.ts +2 -0
- package/dist/esm/ed25519.js +42 -0
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/protocol.d.ts +57 -0
- package/dist/esm/protocol.js +4 -0
- package/package.json +22 -8
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import WebSocket from "isomorphic-ws";
|
|
2
|
+
import { type ParsedPayload, type Request, type Response } from "./protocol.js";
|
|
3
|
+
export type BinaryResponse = {
|
|
4
|
+
subscriptionId: number;
|
|
5
|
+
evm?: Buffer | undefined;
|
|
6
|
+
solana?: Buffer | undefined;
|
|
7
|
+
parsed?: ParsedPayload | undefined;
|
|
8
|
+
};
|
|
9
|
+
export type JsonOrBinaryResponse = {
|
|
10
|
+
type: "json";
|
|
11
|
+
value: Response;
|
|
12
|
+
} | {
|
|
13
|
+
type: "binary";
|
|
14
|
+
value: BinaryResponse;
|
|
15
|
+
};
|
|
16
|
+
export declare class PythLazerClient {
|
|
17
|
+
ws: WebSocket;
|
|
18
|
+
constructor(url: string, token: string);
|
|
19
|
+
addMessageListener(handler: (event: JsonOrBinaryResponse) => void): void;
|
|
20
|
+
send(request: Request): void;
|
|
21
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.PythLazerClient = void 0;
|
|
7
|
+
const isomorphic_ws_1 = __importDefault(require("isomorphic-ws"));
|
|
8
|
+
const protocol_js_1 = require("./protocol.js");
|
|
9
|
+
const UINT16_NUM_BYTES = 2;
|
|
10
|
+
const UINT32_NUM_BYTES = 4;
|
|
11
|
+
const UINT64_NUM_BYTES = 8;
|
|
12
|
+
class PythLazerClient {
|
|
13
|
+
ws;
|
|
14
|
+
constructor(url, token) {
|
|
15
|
+
const finalUrl = new URL(url);
|
|
16
|
+
finalUrl.searchParams.append("ACCESS_TOKEN", token);
|
|
17
|
+
this.ws = new isomorphic_ws_1.default(finalUrl);
|
|
18
|
+
}
|
|
19
|
+
addMessageListener(handler) {
|
|
20
|
+
this.ws.addEventListener("message", (event) => {
|
|
21
|
+
if (typeof event.data == "string") {
|
|
22
|
+
handler({
|
|
23
|
+
type: "json",
|
|
24
|
+
value: JSON.parse(event.data),
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
else if (Buffer.isBuffer(event.data)) {
|
|
28
|
+
let pos = 0;
|
|
29
|
+
const magic = event.data
|
|
30
|
+
.subarray(pos, pos + UINT32_NUM_BYTES)
|
|
31
|
+
.readUint32BE();
|
|
32
|
+
pos += UINT32_NUM_BYTES;
|
|
33
|
+
if (magic != protocol_js_1.BINARY_UPDATE_FORMAT_MAGIC) {
|
|
34
|
+
throw new Error("binary update format magic mismatch");
|
|
35
|
+
}
|
|
36
|
+
// TODO: some uint64 values may not be representable as Number.
|
|
37
|
+
const subscriptionId = Number(event.data.subarray(pos, pos + UINT64_NUM_BYTES).readBigInt64BE());
|
|
38
|
+
pos += UINT64_NUM_BYTES;
|
|
39
|
+
const value = { subscriptionId };
|
|
40
|
+
while (pos < event.data.length) {
|
|
41
|
+
const len = event.data
|
|
42
|
+
.subarray(pos, pos + UINT16_NUM_BYTES)
|
|
43
|
+
.readUint16BE();
|
|
44
|
+
pos += UINT16_NUM_BYTES;
|
|
45
|
+
const magic = event.data
|
|
46
|
+
.subarray(pos, pos + UINT32_NUM_BYTES)
|
|
47
|
+
.readUint32BE();
|
|
48
|
+
if (magic == protocol_js_1.EVM_FORMAT_MAGIC) {
|
|
49
|
+
value.evm = event.data.subarray(pos, pos + len);
|
|
50
|
+
}
|
|
51
|
+
else if (magic == protocol_js_1.SOLANA_FORMAT_MAGIC_BE) {
|
|
52
|
+
value.solana = event.data.subarray(pos, pos + len);
|
|
53
|
+
}
|
|
54
|
+
else if (magic == protocol_js_1.PARSED_FORMAT_MAGIC) {
|
|
55
|
+
value.parsed = JSON.parse(event.data.subarray(pos + UINT32_NUM_BYTES, pos + len).toString());
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
throw new Error("unknown magic: " + magic.toString());
|
|
59
|
+
}
|
|
60
|
+
pos += len;
|
|
61
|
+
}
|
|
62
|
+
handler({ type: "binary", value });
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
throw new TypeError("unexpected event data type");
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
send(request) {
|
|
70
|
+
this.ws.send(JSON.stringify(request));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.PythLazerClient = PythLazerClient;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
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
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.createEd25519Instruction = void 0;
|
|
27
|
+
const BufferLayout = __importStar(require("@solana/buffer-layout"));
|
|
28
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
29
|
+
const ED25519_INSTRUCTION_LEN = 16;
|
|
30
|
+
const SIGNATURE_LEN = 64;
|
|
31
|
+
const PUBKEY_LEN = 32;
|
|
32
|
+
const MAGIC_LEN = 4;
|
|
33
|
+
const MESSAGE_SIZE_LEN = 2;
|
|
34
|
+
const ED25519_INSTRUCTION_LAYOUT = BufferLayout.struct([
|
|
35
|
+
BufferLayout.u8("numSignatures"),
|
|
36
|
+
BufferLayout.u8("padding"),
|
|
37
|
+
BufferLayout.u16("signatureOffset"),
|
|
38
|
+
BufferLayout.u16("signatureInstructionIndex"),
|
|
39
|
+
BufferLayout.u16("publicKeyOffset"),
|
|
40
|
+
BufferLayout.u16("publicKeyInstructionIndex"),
|
|
41
|
+
BufferLayout.u16("messageDataOffset"),
|
|
42
|
+
BufferLayout.u16("messageDataSize"),
|
|
43
|
+
BufferLayout.u16("messageInstructionIndex"),
|
|
44
|
+
]);
|
|
45
|
+
const createEd25519Instruction = (message, instructionIndex, startingOffset) => {
|
|
46
|
+
const signatureOffset = startingOffset + MAGIC_LEN;
|
|
47
|
+
const publicKeyOffset = signatureOffset + SIGNATURE_LEN;
|
|
48
|
+
const messageDataSizeOffset = publicKeyOffset + PUBKEY_LEN;
|
|
49
|
+
const messageDataOffset = messageDataSizeOffset + MESSAGE_SIZE_LEN;
|
|
50
|
+
const messageDataSize = message.readUInt16LE(messageDataSizeOffset - startingOffset);
|
|
51
|
+
const instructionData = Buffer.alloc(ED25519_INSTRUCTION_LEN);
|
|
52
|
+
ED25519_INSTRUCTION_LAYOUT.encode({
|
|
53
|
+
numSignatures: 1,
|
|
54
|
+
padding: 0,
|
|
55
|
+
signatureOffset,
|
|
56
|
+
signatureInstructionIndex: instructionIndex,
|
|
57
|
+
publicKeyOffset,
|
|
58
|
+
publicKeyInstructionIndex: instructionIndex,
|
|
59
|
+
messageDataOffset,
|
|
60
|
+
messageDataSize: messageDataSize,
|
|
61
|
+
messageInstructionIndex: instructionIndex,
|
|
62
|
+
}, instructionData);
|
|
63
|
+
return new web3_js_1.TransactionInstruction({
|
|
64
|
+
keys: [],
|
|
65
|
+
programId: web3_js_1.Ed25519Program.programId,
|
|
66
|
+
data: instructionData,
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
exports.createEd25519Instruction = createEd25519Instruction;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./client.js"), exports);
|
|
18
|
+
__exportStar(require("./protocol.js"), exports);
|
|
19
|
+
__exportStar(require("./ed25519.js"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export type Chain = "evm" | "solana";
|
|
2
|
+
export type DeliveryFormat = "json" | "binary";
|
|
3
|
+
export type JsonBinaryEncoding = "base64" | "hex";
|
|
4
|
+
export type PriceFeedProperty = "price" | "bestBidPrice" | "bestAskPrice";
|
|
5
|
+
export type Channel = "real_time" | "fixed_rate@50ms" | "fixed_rate@200ms";
|
|
6
|
+
export type Request = {
|
|
7
|
+
type: "subscribe";
|
|
8
|
+
subscriptionId: number;
|
|
9
|
+
priceFeedIds: number[];
|
|
10
|
+
properties: PriceFeedProperty[];
|
|
11
|
+
chains: Chain[];
|
|
12
|
+
deliveryFormat?: DeliveryFormat;
|
|
13
|
+
jsonBinaryEncoding?: JsonBinaryEncoding;
|
|
14
|
+
parsed?: boolean;
|
|
15
|
+
channel: Channel;
|
|
16
|
+
} | {
|
|
17
|
+
type: "unsubscribe";
|
|
18
|
+
subscriptionId: number;
|
|
19
|
+
};
|
|
20
|
+
export type ParsedFeedPayload = {
|
|
21
|
+
priceFeedId: number;
|
|
22
|
+
price?: string | undefined;
|
|
23
|
+
bestBidPrice?: string | undefined;
|
|
24
|
+
bestAskPrice?: string | undefined;
|
|
25
|
+
};
|
|
26
|
+
export type ParsedPayload = {
|
|
27
|
+
timestampUs: string;
|
|
28
|
+
priceFeeds: ParsedFeedPayload[];
|
|
29
|
+
};
|
|
30
|
+
export type JsonBinaryData = {
|
|
31
|
+
encoding: JsonBinaryEncoding;
|
|
32
|
+
data: string;
|
|
33
|
+
};
|
|
34
|
+
export type Response = {
|
|
35
|
+
type: "error";
|
|
36
|
+
error: string;
|
|
37
|
+
} | {
|
|
38
|
+
type: "subscribed";
|
|
39
|
+
subscriptionId: number;
|
|
40
|
+
} | {
|
|
41
|
+
type: "unsubscribed";
|
|
42
|
+
subscriptionId: number;
|
|
43
|
+
} | {
|
|
44
|
+
type: "subscriptionError";
|
|
45
|
+
subscriptionId: number;
|
|
46
|
+
error: string;
|
|
47
|
+
} | {
|
|
48
|
+
type: "streamUpdated";
|
|
49
|
+
subscriptionId: number;
|
|
50
|
+
parsed?: ParsedPayload | undefined;
|
|
51
|
+
evm?: JsonBinaryData | undefined;
|
|
52
|
+
solana?: JsonBinaryData | undefined;
|
|
53
|
+
};
|
|
54
|
+
export declare const BINARY_UPDATE_FORMAT_MAGIC = 1937213467;
|
|
55
|
+
export declare const PARSED_FORMAT_MAGIC = 2584795844;
|
|
56
|
+
export declare const EVM_FORMAT_MAGIC = 706910618;
|
|
57
|
+
export declare const SOLANA_FORMAT_MAGIC_BE = 3103857282;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
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;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import WebSocket from "isomorphic-ws";
|
|
2
|
+
import { type ParsedPayload, type Request, type Response } from "./protocol.js";
|
|
3
|
+
export type BinaryResponse = {
|
|
4
|
+
subscriptionId: number;
|
|
5
|
+
evm?: Buffer | undefined;
|
|
6
|
+
solana?: Buffer | undefined;
|
|
7
|
+
parsed?: ParsedPayload | undefined;
|
|
8
|
+
};
|
|
9
|
+
export type JsonOrBinaryResponse = {
|
|
10
|
+
type: "json";
|
|
11
|
+
value: Response;
|
|
12
|
+
} | {
|
|
13
|
+
type: "binary";
|
|
14
|
+
value: BinaryResponse;
|
|
15
|
+
};
|
|
16
|
+
export declare class PythLazerClient {
|
|
17
|
+
ws: WebSocket;
|
|
18
|
+
constructor(url: string, token: string);
|
|
19
|
+
addMessageListener(handler: (event: JsonOrBinaryResponse) => void): void;
|
|
20
|
+
send(request: Request): void;
|
|
21
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import WebSocket from "isomorphic-ws";
|
|
2
|
+
import { BINARY_UPDATE_FORMAT_MAGIC, EVM_FORMAT_MAGIC, PARSED_FORMAT_MAGIC, SOLANA_FORMAT_MAGIC_BE, } from "./protocol.js";
|
|
3
|
+
const UINT16_NUM_BYTES = 2;
|
|
4
|
+
const UINT32_NUM_BYTES = 4;
|
|
5
|
+
const UINT64_NUM_BYTES = 8;
|
|
6
|
+
export class PythLazerClient {
|
|
7
|
+
ws;
|
|
8
|
+
constructor(url, token) {
|
|
9
|
+
const finalUrl = new URL(url);
|
|
10
|
+
finalUrl.searchParams.append("ACCESS_TOKEN", token);
|
|
11
|
+
this.ws = new WebSocket(finalUrl);
|
|
12
|
+
}
|
|
13
|
+
addMessageListener(handler) {
|
|
14
|
+
this.ws.addEventListener("message", (event) => {
|
|
15
|
+
if (typeof event.data == "string") {
|
|
16
|
+
handler({
|
|
17
|
+
type: "json",
|
|
18
|
+
value: JSON.parse(event.data),
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
else if (Buffer.isBuffer(event.data)) {
|
|
22
|
+
let pos = 0;
|
|
23
|
+
const magic = event.data
|
|
24
|
+
.subarray(pos, pos + UINT32_NUM_BYTES)
|
|
25
|
+
.readUint32BE();
|
|
26
|
+
pos += UINT32_NUM_BYTES;
|
|
27
|
+
if (magic != BINARY_UPDATE_FORMAT_MAGIC) {
|
|
28
|
+
throw new Error("binary update format magic mismatch");
|
|
29
|
+
}
|
|
30
|
+
// TODO: some uint64 values may not be representable as Number.
|
|
31
|
+
const subscriptionId = Number(event.data.subarray(pos, pos + UINT64_NUM_BYTES).readBigInt64BE());
|
|
32
|
+
pos += UINT64_NUM_BYTES;
|
|
33
|
+
const value = { subscriptionId };
|
|
34
|
+
while (pos < event.data.length) {
|
|
35
|
+
const len = event.data
|
|
36
|
+
.subarray(pos, pos + UINT16_NUM_BYTES)
|
|
37
|
+
.readUint16BE();
|
|
38
|
+
pos += UINT16_NUM_BYTES;
|
|
39
|
+
const magic = event.data
|
|
40
|
+
.subarray(pos, pos + UINT32_NUM_BYTES)
|
|
41
|
+
.readUint32BE();
|
|
42
|
+
if (magic == EVM_FORMAT_MAGIC) {
|
|
43
|
+
value.evm = event.data.subarray(pos, pos + len);
|
|
44
|
+
}
|
|
45
|
+
else if (magic == SOLANA_FORMAT_MAGIC_BE) {
|
|
46
|
+
value.solana = event.data.subarray(pos, pos + len);
|
|
47
|
+
}
|
|
48
|
+
else if (magic == PARSED_FORMAT_MAGIC) {
|
|
49
|
+
value.parsed = JSON.parse(event.data.subarray(pos + UINT32_NUM_BYTES, pos + len).toString());
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
throw new Error("unknown magic: " + magic.toString());
|
|
53
|
+
}
|
|
54
|
+
pos += len;
|
|
55
|
+
}
|
|
56
|
+
handler({ type: "binary", value });
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
throw new TypeError("unexpected event data type");
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
send(request) {
|
|
64
|
+
this.ws.send(JSON.stringify(request));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import * as BufferLayout from "@solana/buffer-layout";
|
|
2
|
+
import { Ed25519Program, TransactionInstruction } from "@solana/web3.js";
|
|
3
|
+
const ED25519_INSTRUCTION_LEN = 16;
|
|
4
|
+
const SIGNATURE_LEN = 64;
|
|
5
|
+
const PUBKEY_LEN = 32;
|
|
6
|
+
const MAGIC_LEN = 4;
|
|
7
|
+
const MESSAGE_SIZE_LEN = 2;
|
|
8
|
+
const ED25519_INSTRUCTION_LAYOUT = BufferLayout.struct([
|
|
9
|
+
BufferLayout.u8("numSignatures"),
|
|
10
|
+
BufferLayout.u8("padding"),
|
|
11
|
+
BufferLayout.u16("signatureOffset"),
|
|
12
|
+
BufferLayout.u16("signatureInstructionIndex"),
|
|
13
|
+
BufferLayout.u16("publicKeyOffset"),
|
|
14
|
+
BufferLayout.u16("publicKeyInstructionIndex"),
|
|
15
|
+
BufferLayout.u16("messageDataOffset"),
|
|
16
|
+
BufferLayout.u16("messageDataSize"),
|
|
17
|
+
BufferLayout.u16("messageInstructionIndex"),
|
|
18
|
+
]);
|
|
19
|
+
export const createEd25519Instruction = (message, instructionIndex, startingOffset) => {
|
|
20
|
+
const signatureOffset = startingOffset + MAGIC_LEN;
|
|
21
|
+
const publicKeyOffset = signatureOffset + SIGNATURE_LEN;
|
|
22
|
+
const messageDataSizeOffset = publicKeyOffset + PUBKEY_LEN;
|
|
23
|
+
const messageDataOffset = messageDataSizeOffset + MESSAGE_SIZE_LEN;
|
|
24
|
+
const messageDataSize = message.readUInt16LE(messageDataSizeOffset - startingOffset);
|
|
25
|
+
const instructionData = Buffer.alloc(ED25519_INSTRUCTION_LEN);
|
|
26
|
+
ED25519_INSTRUCTION_LAYOUT.encode({
|
|
27
|
+
numSignatures: 1,
|
|
28
|
+
padding: 0,
|
|
29
|
+
signatureOffset,
|
|
30
|
+
signatureInstructionIndex: instructionIndex,
|
|
31
|
+
publicKeyOffset,
|
|
32
|
+
publicKeyInstructionIndex: instructionIndex,
|
|
33
|
+
messageDataOffset,
|
|
34
|
+
messageDataSize: messageDataSize,
|
|
35
|
+
messageInstructionIndex: instructionIndex,
|
|
36
|
+
}, instructionData);
|
|
37
|
+
return new TransactionInstruction({
|
|
38
|
+
keys: [],
|
|
39
|
+
programId: Ed25519Program.programId,
|
|
40
|
+
data: instructionData,
|
|
41
|
+
});
|
|
42
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export type Chain = "evm" | "solana";
|
|
2
|
+
export type DeliveryFormat = "json" | "binary";
|
|
3
|
+
export type JsonBinaryEncoding = "base64" | "hex";
|
|
4
|
+
export type PriceFeedProperty = "price" | "bestBidPrice" | "bestAskPrice";
|
|
5
|
+
export type Channel = "real_time" | "fixed_rate@50ms" | "fixed_rate@200ms";
|
|
6
|
+
export type Request = {
|
|
7
|
+
type: "subscribe";
|
|
8
|
+
subscriptionId: number;
|
|
9
|
+
priceFeedIds: number[];
|
|
10
|
+
properties: PriceFeedProperty[];
|
|
11
|
+
chains: Chain[];
|
|
12
|
+
deliveryFormat?: DeliveryFormat;
|
|
13
|
+
jsonBinaryEncoding?: JsonBinaryEncoding;
|
|
14
|
+
parsed?: boolean;
|
|
15
|
+
channel: Channel;
|
|
16
|
+
} | {
|
|
17
|
+
type: "unsubscribe";
|
|
18
|
+
subscriptionId: number;
|
|
19
|
+
};
|
|
20
|
+
export type ParsedFeedPayload = {
|
|
21
|
+
priceFeedId: number;
|
|
22
|
+
price?: string | undefined;
|
|
23
|
+
bestBidPrice?: string | undefined;
|
|
24
|
+
bestAskPrice?: string | undefined;
|
|
25
|
+
};
|
|
26
|
+
export type ParsedPayload = {
|
|
27
|
+
timestampUs: string;
|
|
28
|
+
priceFeeds: ParsedFeedPayload[];
|
|
29
|
+
};
|
|
30
|
+
export type JsonBinaryData = {
|
|
31
|
+
encoding: JsonBinaryEncoding;
|
|
32
|
+
data: string;
|
|
33
|
+
};
|
|
34
|
+
export type Response = {
|
|
35
|
+
type: "error";
|
|
36
|
+
error: string;
|
|
37
|
+
} | {
|
|
38
|
+
type: "subscribed";
|
|
39
|
+
subscriptionId: number;
|
|
40
|
+
} | {
|
|
41
|
+
type: "unsubscribed";
|
|
42
|
+
subscriptionId: number;
|
|
43
|
+
} | {
|
|
44
|
+
type: "subscriptionError";
|
|
45
|
+
subscriptionId: number;
|
|
46
|
+
error: string;
|
|
47
|
+
} | {
|
|
48
|
+
type: "streamUpdated";
|
|
49
|
+
subscriptionId: number;
|
|
50
|
+
parsed?: ParsedPayload | undefined;
|
|
51
|
+
evm?: JsonBinaryData | undefined;
|
|
52
|
+
solana?: JsonBinaryData | undefined;
|
|
53
|
+
};
|
|
54
|
+
export declare const BINARY_UPDATE_FORMAT_MAGIC = 1937213467;
|
|
55
|
+
export declare const PARSED_FORMAT_MAGIC = 2584795844;
|
|
56
|
+
export declare const EVM_FORMAT_MAGIC = 706910618;
|
|
57
|
+
export declare const SOLANA_FORMAT_MAGIC_BE = 3103857282;
|
package/package.json
CHANGED
|
@@ -1,21 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pythnetwork/pyth-lazer-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Pyth Lazer SDK",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
8
|
"files": [
|
|
9
|
-
"
|
|
9
|
+
"dist/**/*"
|
|
10
10
|
],
|
|
11
|
+
"main": "./dist/cjs/index.js",
|
|
12
|
+
"types": "./dist/cjs/index.d.ts",
|
|
13
|
+
"exports": {
|
|
14
|
+
"import": {
|
|
15
|
+
"types": "./dist/esm/index.d.ts",
|
|
16
|
+
"default": "./dist/esm/index.js"
|
|
17
|
+
},
|
|
18
|
+
"require": {
|
|
19
|
+
"types": "./dist/cjs/index.d.ts",
|
|
20
|
+
"default": "./dist/cjs/index.js"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
11
23
|
"scripts": {
|
|
12
|
-
"build:cjs": "tsc --project tsconfig.json --verbatimModuleSyntax false --module commonjs --outDir ./dist/cjs && echo '{\"type\":\"commonjs\"}' > dist/cjs/package.json",
|
|
13
|
-
"build:esm": "tsc --project tsconfig.json --outDir ./dist/esm && echo '{\"type\":\"module\"}' > dist/esm/package.json",
|
|
24
|
+
"build:cjs": "tsc --project tsconfig.build.json --verbatimModuleSyntax false --module commonjs --outDir ./dist/cjs && echo '{\"type\":\"commonjs\"}' > dist/cjs/package.json",
|
|
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 .",
|
|
28
|
+
"test:types": "tsc",
|
|
14
29
|
"example": "node --loader ts-node/esm examples/index.js",
|
|
15
|
-
"test": "pnpm run test:lint && pnpm run build:cjs && pnpm run build:esm",
|
|
16
30
|
"doc": "typedoc --out docs/typedoc src",
|
|
17
|
-
"test:lint": "eslint .",
|
|
18
|
-
"fix:lint": "eslint --fix .",
|
|
19
31
|
"publish": "pnpm run script -- publish"
|
|
20
32
|
},
|
|
21
33
|
"devDependencies": {
|
|
@@ -48,8 +60,10 @@
|
|
|
48
60
|
],
|
|
49
61
|
"license": "Apache-2.0",
|
|
50
62
|
"dependencies": {
|
|
63
|
+
"@solana/buffer-layout": "^4.0.1",
|
|
64
|
+
"@solana/web3.js": "^1.98.0",
|
|
51
65
|
"isomorphic-ws": "^5.0.0",
|
|
52
66
|
"ws": "^8.18.0"
|
|
53
67
|
},
|
|
54
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "57670ca732de0be3ed7926f38f4853f01cd816fa"
|
|
55
69
|
}
|