@lightconexyz/lightcone-sdk 0.1.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.
- package/README.md +232 -0
- package/dist/api/client.d.ts +225 -0
- package/dist/api/client.d.ts.map +1 -0
- package/dist/api/client.js +452 -0
- package/dist/api/client.js.map +1 -0
- package/dist/api/error.d.ts +58 -0
- package/dist/api/error.d.ts.map +1 -0
- package/dist/api/error.js +98 -0
- package/dist/api/error.js.map +1 -0
- package/dist/api/index.d.ts +23 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +51 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/types/admin.d.ts +49 -0
- package/dist/api/types/admin.d.ts.map +1 -0
- package/dist/api/types/admin.js +13 -0
- package/dist/api/types/admin.js.map +1 -0
- package/dist/api/types/index.d.ts +14 -0
- package/dist/api/types/index.d.ts.map +1 -0
- package/dist/api/types/index.js +13 -0
- package/dist/api/types/index.js.map +1 -0
- package/dist/api/types/market.d.ts +186 -0
- package/dist/api/types/market.d.ts.map +1 -0
- package/dist/api/types/market.js +6 -0
- package/dist/api/types/market.js.map +1 -0
- package/dist/api/types/order.d.ts +190 -0
- package/dist/api/types/order.d.ts.map +1 -0
- package/dist/api/types/order.js +6 -0
- package/dist/api/types/order.js.map +1 -0
- package/dist/api/types/orderbook.d.ts +36 -0
- package/dist/api/types/orderbook.d.ts.map +1 -0
- package/dist/api/types/orderbook.js +6 -0
- package/dist/api/types/orderbook.js.map +1 -0
- package/dist/api/types/position.d.ts +60 -0
- package/dist/api/types/position.d.ts.map +1 -0
- package/dist/api/types/position.js +6 -0
- package/dist/api/types/position.js.map +1 -0
- package/dist/api/types/price_history.d.ts +68 -0
- package/dist/api/types/price_history.d.ts.map +1 -0
- package/dist/api/types/price_history.js +13 -0
- package/dist/api/types/price_history.js.map +1 -0
- package/dist/api/types/trade.d.ts +67 -0
- package/dist/api/types/trade.d.ts.map +1 -0
- package/dist/api/types/trade.js +13 -0
- package/dist/api/types/trade.js.map +1 -0
- package/dist/api/validation.d.ts +24 -0
- package/dist/api/validation.d.ts.map +1 -0
- package/dist/api/validation.js +53 -0
- package/dist/api/validation.js.map +1 -0
- package/dist/auth.d.ts +80 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +149 -0
- package/dist/auth.js.map +1 -0
- package/dist/index.d.ts +55 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +107 -0
- package/dist/index.js.map +1 -0
- package/dist/network.d.ts +5 -0
- package/dist/network.d.ts.map +1 -0
- package/dist/network.js +8 -0
- package/dist/network.js.map +1 -0
- package/dist/program/accounts.d.ts +98 -0
- package/dist/program/accounts.d.ts.map +1 -0
- package/dist/program/accounts.js +319 -0
- package/dist/program/accounts.js.map +1 -0
- package/dist/program/builder.d.ts +94 -0
- package/dist/program/builder.d.ts.map +1 -0
- package/dist/program/builder.js +175 -0
- package/dist/program/builder.js.map +1 -0
- package/dist/program/client.d.ts +56 -0
- package/dist/program/client.d.ts.map +1 -0
- package/dist/program/client.js +288 -0
- package/dist/program/client.js.map +1 -0
- package/dist/program/constants.d.ts +108 -0
- package/dist/program/constants.d.ts.map +1 -0
- package/dist/program/constants.js +112 -0
- package/dist/program/constants.js.map +1 -0
- package/dist/program/index.d.ts +14 -0
- package/dist/program/index.d.ts.map +1 -0
- package/dist/program/index.js +149 -0
- package/dist/program/index.js.map +1 -0
- package/dist/program/instructions.d.ts +248 -0
- package/dist/program/instructions.d.ts.map +1 -0
- package/dist/program/instructions.js +692 -0
- package/dist/program/instructions.js.map +1 -0
- package/dist/program/orders.d.ts +151 -0
- package/dist/program/orders.d.ts.map +1 -0
- package/dist/program/orders.js +417 -0
- package/dist/program/orders.js.map +1 -0
- package/dist/program/pda.d.ts +73 -0
- package/dist/program/pda.d.ts.map +1 -0
- package/dist/program/pda.js +131 -0
- package/dist/program/pda.js.map +1 -0
- package/dist/program/types.d.ts +380 -0
- package/dist/program/types.d.ts.map +1 -0
- package/dist/program/types.js +27 -0
- package/dist/program/types.js.map +1 -0
- package/dist/program/utils.d.ts +91 -0
- package/dist/program/utils.d.ts.map +1 -0
- package/dist/program/utils.js +219 -0
- package/dist/program/utils.js.map +1 -0
- package/dist/shared/index.d.ts +8 -0
- package/dist/shared/index.d.ts.map +1 -0
- package/dist/shared/index.js +18 -0
- package/dist/shared/index.js.map +1 -0
- package/dist/shared/price.d.ts +41 -0
- package/dist/shared/price.d.ts.map +1 -0
- package/dist/shared/price.js +57 -0
- package/dist/shared/price.js.map +1 -0
- package/dist/shared/scaling.d.ts +45 -0
- package/dist/shared/scaling.d.ts.map +1 -0
- package/dist/shared/scaling.js +84 -0
- package/dist/shared/scaling.js.map +1 -0
- package/dist/shared/types.d.ts +19 -0
- package/dist/shared/types.d.ts.map +1 -0
- package/dist/shared/types.js +23 -0
- package/dist/shared/types.js.map +1 -0
- package/dist/websocket/client.d.ts +238 -0
- package/dist/websocket/client.d.ts.map +1 -0
- package/dist/websocket/client.js +580 -0
- package/dist/websocket/client.js.map +1 -0
- package/dist/websocket/error.d.ts +47 -0
- package/dist/websocket/error.d.ts.map +1 -0
- package/dist/websocket/error.js +83 -0
- package/dist/websocket/error.js.map +1 -0
- package/dist/websocket/handlers.d.ts +97 -0
- package/dist/websocket/handlers.d.ts.map +1 -0
- package/dist/websocket/handlers.js +277 -0
- package/dist/websocket/handlers.js.map +1 -0
- package/dist/websocket/index.d.ts +38 -0
- package/dist/websocket/index.d.ts.map +1 -0
- package/dist/websocket/index.js +75 -0
- package/dist/websocket/index.js.map +1 -0
- package/dist/websocket/state/index.d.ts +7 -0
- package/dist/websocket/state/index.d.ts.map +1 -0
- package/dist/websocket/state/index.js +14 -0
- package/dist/websocket/state/index.js.map +1 -0
- package/dist/websocket/state/orderbook.d.ts +107 -0
- package/dist/websocket/state/orderbook.d.ts.map +1 -0
- package/dist/websocket/state/orderbook.js +293 -0
- package/dist/websocket/state/orderbook.js.map +1 -0
- package/dist/websocket/state/price.d.ts +108 -0
- package/dist/websocket/state/price.d.ts.map +1 -0
- package/dist/websocket/state/price.js +243 -0
- package/dist/websocket/state/price.js.map +1 -0
- package/dist/websocket/state/user.d.ts +83 -0
- package/dist/websocket/state/user.d.ts.map +1 -0
- package/dist/websocket/state/user.js +228 -0
- package/dist/websocket/state/user.js.map +1 -0
- package/dist/websocket/subscriptions.d.ts +143 -0
- package/dist/websocket/subscriptions.d.ts.map +1 -0
- package/dist/websocket/subscriptions.js +244 -0
- package/dist/websocket/subscriptions.js.map +1 -0
- package/dist/websocket/types.d.ts +417 -0
- package/dist/websocket/types.d.ts.map +1 -0
- package/dist/websocket/types.js +195 -0
- package/dist/websocket/types.js.map +1 -0
- package/package.json +75 -0
package/dist/auth.d.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Authentication module for Lightcone.
|
|
3
|
+
*
|
|
4
|
+
* Provides functionality for authenticating with the Lightcone API.
|
|
5
|
+
* Used by both the REST API client and WebSocket client.
|
|
6
|
+
*
|
|
7
|
+
* # Authentication Flow
|
|
8
|
+
*
|
|
9
|
+
* 1. Generate a sign-in message with timestamp
|
|
10
|
+
* 2. Sign the message with an Ed25519 keypair
|
|
11
|
+
* 3. POST to the authentication endpoint
|
|
12
|
+
* 4. Extract token from JSON response
|
|
13
|
+
*/
|
|
14
|
+
import { Keypair } from "@solana/web3.js";
|
|
15
|
+
/**
|
|
16
|
+
* Auth error variants (mirrors Rust's AuthError enum).
|
|
17
|
+
*/
|
|
18
|
+
export type AuthErrorVariant = "SystemTime" | "HttpError" | "AuthenticationFailed";
|
|
19
|
+
/**
|
|
20
|
+
* Authentication error class.
|
|
21
|
+
*/
|
|
22
|
+
export declare class AuthError extends Error {
|
|
23
|
+
readonly variant: AuthErrorVariant;
|
|
24
|
+
constructor(variant: AuthErrorVariant, message: string);
|
|
25
|
+
static systemTime(message: string): AuthError;
|
|
26
|
+
static httpError(message: string): AuthError;
|
|
27
|
+
static authenticationFailed(message: string): AuthError;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Authentication credentials returned after successful login.
|
|
31
|
+
*/
|
|
32
|
+
export interface AuthCredentials {
|
|
33
|
+
/** The authentication token to use for WebSocket connection */
|
|
34
|
+
authToken: string;
|
|
35
|
+
/** The user's public key (Base58 encoded) */
|
|
36
|
+
userPubkey: string;
|
|
37
|
+
/** The user's ID */
|
|
38
|
+
userId: string;
|
|
39
|
+
/** Token expiration timestamp (Unix seconds) */
|
|
40
|
+
expiresAt: number;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Generate the sign-in message with current timestamp.
|
|
44
|
+
*
|
|
45
|
+
* @returns The message to be signed
|
|
46
|
+
*/
|
|
47
|
+
export declare function generateSigninMessage(): string;
|
|
48
|
+
/**
|
|
49
|
+
* Generate the sign-in message with a specific timestamp.
|
|
50
|
+
*
|
|
51
|
+
* @param timestampMs - Unix timestamp in milliseconds
|
|
52
|
+
* @returns The message to be signed
|
|
53
|
+
*/
|
|
54
|
+
export declare function generateSigninMessageWithTimestamp(timestampMs: number): string;
|
|
55
|
+
/**
|
|
56
|
+
* Authenticate with Lightcone and obtain credentials using a Solana Keypair.
|
|
57
|
+
*
|
|
58
|
+
* @param keypair - The Solana Keypair for authentication
|
|
59
|
+
* @returns AuthCredentials containing the auth token and user public key
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* import { Keypair } from "@solana/web3.js";
|
|
64
|
+
* import { auth } from "@lightcone/sdk";
|
|
65
|
+
*
|
|
66
|
+
* const keypair = Keypair.generate();
|
|
67
|
+
* const credentials = await auth.authenticate(keypair);
|
|
68
|
+
* console.log("Auth token:", credentials.authToken);
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export declare function authenticate(keypair: Keypair): Promise<AuthCredentials>;
|
|
72
|
+
/**
|
|
73
|
+
* Sign a message with a Solana Keypair.
|
|
74
|
+
*
|
|
75
|
+
* @param message - The message to sign
|
|
76
|
+
* @param keypair - The Solana Keypair
|
|
77
|
+
* @returns The Base58-encoded signature
|
|
78
|
+
*/
|
|
79
|
+
export declare function signMessage(message: string, keypair: Keypair): string;
|
|
80
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAQ1C;;GAEG;AACH,MAAM,MAAM,gBAAgB,GACxB,YAAY,GACZ,WAAW,GACX,sBAAsB,CAAC;AAE3B;;GAEG;AACH,qBAAa,SAAU,SAAQ,KAAK;IAClC,QAAQ,CAAC,OAAO,EAAE,gBAAgB,CAAC;gBAEvB,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM;IAMtD,MAAM,CAAC,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS;IAI7C,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS;IAI5C,MAAM,CAAC,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS;CAGxD;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,+DAA+D;IAC/D,SAAS,EAAE,MAAM,CAAC;IAClB,6CAA6C;IAC7C,UAAU,EAAE,MAAM,CAAC;IACnB,oBAAoB;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,gDAAgD;IAChD,SAAS,EAAE,MAAM,CAAC;CACnB;AA4BD;;;;GAIG;AACH,wBAAgB,qBAAqB,IAAI,MAAM,CAG9C;AAED;;;;;GAKG;AACH,wBAAgB,kCAAkC,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAE9E;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,YAAY,CAChC,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,eAAe,CAAC,CA8D1B;AAGD;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CAIrE"}
|
package/dist/auth.js
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Authentication module for Lightcone.
|
|
4
|
+
*
|
|
5
|
+
* Provides functionality for authenticating with the Lightcone API.
|
|
6
|
+
* Used by both the REST API client and WebSocket client.
|
|
7
|
+
*
|
|
8
|
+
* # Authentication Flow
|
|
9
|
+
*
|
|
10
|
+
* 1. Generate a sign-in message with timestamp
|
|
11
|
+
* 2. Sign the message with an Ed25519 keypair
|
|
12
|
+
* 3. POST to the authentication endpoint
|
|
13
|
+
* 4. Extract token from JSON response
|
|
14
|
+
*/
|
|
15
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
16
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
17
|
+
};
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.AuthError = void 0;
|
|
20
|
+
exports.generateSigninMessage = generateSigninMessage;
|
|
21
|
+
exports.generateSigninMessageWithTimestamp = generateSigninMessageWithTimestamp;
|
|
22
|
+
exports.authenticate = authenticate;
|
|
23
|
+
exports.signMessage = signMessage;
|
|
24
|
+
const bs58_1 = __importDefault(require("bs58"));
|
|
25
|
+
const tweetnacl_1 = __importDefault(require("tweetnacl"));
|
|
26
|
+
const network_1 = require("./network");
|
|
27
|
+
/** Authentication timeout in milliseconds */
|
|
28
|
+
const AUTH_TIMEOUT_MS = 10000;
|
|
29
|
+
/**
|
|
30
|
+
* Authentication error class.
|
|
31
|
+
*/
|
|
32
|
+
class AuthError extends Error {
|
|
33
|
+
variant;
|
|
34
|
+
constructor(variant, message) {
|
|
35
|
+
super(message);
|
|
36
|
+
this.name = "AuthError";
|
|
37
|
+
this.variant = variant;
|
|
38
|
+
}
|
|
39
|
+
static systemTime(message) {
|
|
40
|
+
return new AuthError("SystemTime", `System time error: ${message}`);
|
|
41
|
+
}
|
|
42
|
+
static httpError(message) {
|
|
43
|
+
return new AuthError("HttpError", `HTTP error: ${message}`);
|
|
44
|
+
}
|
|
45
|
+
static authenticationFailed(message) {
|
|
46
|
+
return new AuthError("AuthenticationFailed", `Authentication failed: ${message}`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.AuthError = AuthError;
|
|
50
|
+
/**
|
|
51
|
+
* Generate the sign-in message with current timestamp.
|
|
52
|
+
*
|
|
53
|
+
* @returns The message to be signed
|
|
54
|
+
*/
|
|
55
|
+
function generateSigninMessage() {
|
|
56
|
+
const timestampMs = Date.now();
|
|
57
|
+
return `Sign in to Lightcone\n\nTimestamp: ${timestampMs}`;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Generate the sign-in message with a specific timestamp.
|
|
61
|
+
*
|
|
62
|
+
* @param timestampMs - Unix timestamp in milliseconds
|
|
63
|
+
* @returns The message to be signed
|
|
64
|
+
*/
|
|
65
|
+
function generateSigninMessageWithTimestamp(timestampMs) {
|
|
66
|
+
return `Sign in to Lightcone\n\nTimestamp: ${timestampMs}`;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Authenticate with Lightcone and obtain credentials using a Solana Keypair.
|
|
70
|
+
*
|
|
71
|
+
* @param keypair - The Solana Keypair for authentication
|
|
72
|
+
* @returns AuthCredentials containing the auth token and user public key
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* import { Keypair } from "@solana/web3.js";
|
|
77
|
+
* import { auth } from "@lightcone/sdk";
|
|
78
|
+
*
|
|
79
|
+
* const keypair = Keypair.generate();
|
|
80
|
+
* const credentials = await auth.authenticate(keypair);
|
|
81
|
+
* console.log("Auth token:", credentials.authToken);
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
async function authenticate(keypair) {
|
|
85
|
+
// Generate the message
|
|
86
|
+
const message = generateSigninMessage();
|
|
87
|
+
// Sign the message
|
|
88
|
+
const messageBytes = new TextEncoder().encode(message);
|
|
89
|
+
const signature = tweetnacl_1.default.sign.detached(messageBytes, keypair.secretKey);
|
|
90
|
+
const signatureB58 = bs58_1.default.encode(signature);
|
|
91
|
+
// Get the public key
|
|
92
|
+
const publicKeyB58 = keypair.publicKey.toBase58();
|
|
93
|
+
// Create the request body
|
|
94
|
+
const request = {
|
|
95
|
+
pubkey_bytes: Array.from(keypair.publicKey.toBytes()),
|
|
96
|
+
message,
|
|
97
|
+
signature_bs58: signatureB58,
|
|
98
|
+
};
|
|
99
|
+
// Send the authentication request with timeout
|
|
100
|
+
const url = `${network_1.DEFAULT_API_URL}/auth/login_or_register_with_message`;
|
|
101
|
+
const controller = new AbortController();
|
|
102
|
+
const timeoutId = setTimeout(() => controller.abort(), AUTH_TIMEOUT_MS);
|
|
103
|
+
let response;
|
|
104
|
+
try {
|
|
105
|
+
response = await fetch(url, {
|
|
106
|
+
method: "POST",
|
|
107
|
+
headers: {
|
|
108
|
+
"Content-Type": "application/json",
|
|
109
|
+
},
|
|
110
|
+
body: JSON.stringify(request),
|
|
111
|
+
signal: controller.signal,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
clearTimeout(timeoutId);
|
|
116
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
117
|
+
throw AuthError.authenticationFailed("Authentication request timed out");
|
|
118
|
+
}
|
|
119
|
+
throw AuthError.httpError(error instanceof Error ? error.message : String(error));
|
|
120
|
+
}
|
|
121
|
+
finally {
|
|
122
|
+
clearTimeout(timeoutId);
|
|
123
|
+
}
|
|
124
|
+
// Check for HTTP errors
|
|
125
|
+
if (!response.ok) {
|
|
126
|
+
throw AuthError.httpError(`HTTP ${response.status}`);
|
|
127
|
+
}
|
|
128
|
+
// Parse the response body
|
|
129
|
+
const loginResponse = (await response.json());
|
|
130
|
+
return {
|
|
131
|
+
authToken: loginResponse.token,
|
|
132
|
+
userPubkey: publicKeyB58,
|
|
133
|
+
userId: loginResponse.user_id,
|
|
134
|
+
expiresAt: loginResponse.expires_at,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Sign a message with a Solana Keypair.
|
|
139
|
+
*
|
|
140
|
+
* @param message - The message to sign
|
|
141
|
+
* @param keypair - The Solana Keypair
|
|
142
|
+
* @returns The Base58-encoded signature
|
|
143
|
+
*/
|
|
144
|
+
function signMessage(message, keypair) {
|
|
145
|
+
const messageBytes = new TextEncoder().encode(message);
|
|
146
|
+
const signature = tweetnacl_1.default.sign.detached(messageBytes, keypair.secretKey);
|
|
147
|
+
return bs58_1.default.encode(signature);
|
|
148
|
+
}
|
|
149
|
+
//# sourceMappingURL=auth.js.map
|
package/dist/auth.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"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","sourcesContent":["/**\n * Authentication module for Lightcone.\n *\n * Provides functionality for authenticating with the Lightcone API.\n * Used by both the REST API client and WebSocket client.\n *\n * # Authentication Flow\n *\n * 1. Generate a sign-in message with timestamp\n * 2. Sign the message with an Ed25519 keypair\n * 3. POST to the authentication endpoint\n * 4. Extract token from JSON response\n */\n\nimport { Keypair } from \"@solana/web3.js\";\nimport bs58 from \"bs58\";\nimport nacl from \"tweetnacl\";\nimport { DEFAULT_API_URL } from \"./network\";\n\n/** Authentication timeout in milliseconds */\nconst AUTH_TIMEOUT_MS = 10000;\n\n/**\n * Auth error variants (mirrors Rust's AuthError enum).\n */\nexport type AuthErrorVariant =\n | \"SystemTime\"\n | \"HttpError\"\n | \"AuthenticationFailed\";\n\n/**\n * Authentication error class.\n */\nexport class AuthError extends Error {\n readonly variant: AuthErrorVariant;\n\n constructor(variant: AuthErrorVariant, message: string) {\n super(message);\n this.name = \"AuthError\";\n this.variant = variant;\n }\n\n static systemTime(message: string): AuthError {\n return new AuthError(\"SystemTime\", `System time error: ${message}`);\n }\n\n static httpError(message: string): AuthError {\n return new AuthError(\"HttpError\", `HTTP error: ${message}`);\n }\n\n static authenticationFailed(message: string): AuthError {\n return new AuthError(\"AuthenticationFailed\", `Authentication failed: ${message}`);\n }\n}\n\n/**\n * Authentication credentials returned after successful login.\n */\nexport interface AuthCredentials {\n /** The authentication token to use for WebSocket connection */\n authToken: string;\n /** The user's public key (Base58 encoded) */\n userPubkey: string;\n /** The user's ID */\n userId: string;\n /** Token expiration timestamp (Unix seconds) */\n expiresAt: number;\n}\n\n/**\n * Request body for login endpoint.\n */\ninterface LoginRequest {\n /** Raw 32-byte public key as array */\n pubkey_bytes: number[];\n /** The message that was signed */\n message: string;\n /** Base58 encoded signature */\n signature_bs58: string;\n}\n\n/**\n * Response from login endpoint.\n */\ninterface LoginResponse {\n /** The authentication token */\n token: string;\n /** The user's ID */\n user_id: string;\n /** The user's wallet address */\n wallet_address: string;\n /** Token expiration timestamp (Unix seconds) */\n expires_at: number;\n}\n\n/**\n * Generate the sign-in message with current timestamp.\n *\n * @returns The message to be signed\n */\nexport function generateSigninMessage(): string {\n const timestampMs = Date.now();\n return `Sign in to Lightcone\\n\\nTimestamp: ${timestampMs}`;\n}\n\n/**\n * Generate the sign-in message with a specific timestamp.\n *\n * @param timestampMs - Unix timestamp in milliseconds\n * @returns The message to be signed\n */\nexport function generateSigninMessageWithTimestamp(timestampMs: number): string {\n return `Sign in to Lightcone\\n\\nTimestamp: ${timestampMs}`;\n}\n\n/**\n * Authenticate with Lightcone and obtain credentials using a Solana Keypair.\n *\n * @param keypair - The Solana Keypair for authentication\n * @returns AuthCredentials containing the auth token and user public key\n *\n * @example\n * ```typescript\n * import { Keypair } from \"@solana/web3.js\";\n * import { auth } from \"@lightcone/sdk\";\n *\n * const keypair = Keypair.generate();\n * const credentials = await auth.authenticate(keypair);\n * console.log(\"Auth token:\", credentials.authToken);\n * ```\n */\nexport async function authenticate(\n keypair: Keypair\n): Promise<AuthCredentials> {\n // Generate the message\n const message = generateSigninMessage();\n\n // Sign the message\n const messageBytes = new TextEncoder().encode(message);\n const signature = nacl.sign.detached(messageBytes, keypair.secretKey);\n const signatureB58 = bs58.encode(signature);\n\n // Get the public key\n const publicKeyB58 = keypair.publicKey.toBase58();\n\n // Create the request body\n const request: LoginRequest = {\n pubkey_bytes: Array.from(keypair.publicKey.toBytes()),\n message,\n signature_bs58: signatureB58,\n };\n\n // Send the authentication request with timeout\n const url = `${DEFAULT_API_URL}/auth/login_or_register_with_message`;\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), AUTH_TIMEOUT_MS);\n\n let response: Response;\n try {\n response = await fetch(url, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify(request),\n signal: controller.signal,\n });\n } catch (error) {\n clearTimeout(timeoutId);\n if (error instanceof Error && error.name === \"AbortError\") {\n throw AuthError.authenticationFailed(\n \"Authentication request timed out\"\n );\n }\n throw AuthError.httpError(\n error instanceof Error ? error.message : String(error)\n );\n } finally {\n clearTimeout(timeoutId);\n }\n\n // Check for HTTP errors\n if (!response.ok) {\n throw AuthError.httpError(`HTTP ${response.status}`);\n }\n\n // Parse the response body\n const loginResponse = (await response.json()) as LoginResponse;\n\n return {\n authToken: loginResponse.token,\n userPubkey: publicKeyB58,\n userId: loginResponse.user_id,\n expiresAt: loginResponse.expires_at,\n };\n}\n\n\n/**\n * Sign a message with a Solana Keypair.\n *\n * @param message - The message to sign\n * @param keypair - The Solana Keypair\n * @returns The Base58-encoded signature\n */\nexport function signMessage(message: string, keypair: Keypair): string {\n const messageBytes = new TextEncoder().encode(message);\n const signature = nacl.sign.detached(messageBytes, keypair.secretKey);\n return bs58.encode(signature);\n}\n"]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lightcone SDK - TypeScript SDK for the Lightcone protocol on Solana.
|
|
3
|
+
*
|
|
4
|
+
* This SDK provides three main modules:
|
|
5
|
+
* - `program`: On-chain program interaction (smart contract)
|
|
6
|
+
* - `api`: REST API client for market data, orders, and positions
|
|
7
|
+
* - `websocket`: Real-time data streaming for orderbooks, trades, and user events
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { LightconePinocchioClient, PROGRAM_ID, api, websocket } from "@lightcone/sdk";
|
|
12
|
+
*
|
|
13
|
+
* // On-chain program interaction
|
|
14
|
+
* const programClient = new LightconePinocchioClient(connection, payer);
|
|
15
|
+
*
|
|
16
|
+
* // REST API client
|
|
17
|
+
* const apiClient = new api.LightconeApiClient();
|
|
18
|
+
* const markets = await apiClient.getMarkets();
|
|
19
|
+
*
|
|
20
|
+
* // WebSocket client for real-time data
|
|
21
|
+
* const wsClient = await websocket.LightconeWebSocketClient.connectDefault();
|
|
22
|
+
* await wsClient.subscribeBookUpdates(["market1:ob1"]);
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
/**
|
|
26
|
+
* On-chain program interaction module.
|
|
27
|
+
* Contains the client and utilities for interacting with the Lightcone smart contract.
|
|
28
|
+
*/
|
|
29
|
+
export * from "./program";
|
|
30
|
+
/**
|
|
31
|
+
* Network URL constants (API and WebSocket endpoints).
|
|
32
|
+
*/
|
|
33
|
+
export { DEFAULT_API_URL, DEFAULT_WS_URL } from "./network";
|
|
34
|
+
/**
|
|
35
|
+
* Shared utilities, types, and constants.
|
|
36
|
+
* Used across all SDK modules.
|
|
37
|
+
*/
|
|
38
|
+
export * from "./shared";
|
|
39
|
+
/**
|
|
40
|
+
* REST API client module.
|
|
41
|
+
* Provides HTTP client functionality for market data, orders, and positions.
|
|
42
|
+
*/
|
|
43
|
+
export * as api from "./api";
|
|
44
|
+
/**
|
|
45
|
+
* WebSocket client module.
|
|
46
|
+
* Provides real-time data streaming for orderbooks, trades, and user events.
|
|
47
|
+
*/
|
|
48
|
+
export * as websocket from "./websocket";
|
|
49
|
+
/**
|
|
50
|
+
* Authentication module.
|
|
51
|
+
* Provides authentication functionality shared by API and WebSocket clients.
|
|
52
|
+
*/
|
|
53
|
+
export * as auth from "./auth";
|
|
54
|
+
export { PublicKey, Connection, Keypair, Transaction, TransactionInstruction, } from "@solana/web3.js";
|
|
55
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAMH;;;GAGG;AACH,cAAc,WAAW,CAAC;AAE1B;;GAEG;AACH,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAE5D;;;GAGG;AACH,cAAc,UAAU,CAAC;AAEzB;;;GAGG;AACH,OAAO,KAAK,GAAG,MAAM,OAAO,CAAC;AAE7B;;;GAGG;AACH,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AAEzC;;;GAGG;AACH,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC;AAK/B,OAAO,EACL,SAAS,EACT,UAAU,EACV,OAAO,EACP,WAAW,EACX,sBAAsB,GACvB,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Lightcone SDK - TypeScript SDK for the Lightcone protocol on Solana.
|
|
4
|
+
*
|
|
5
|
+
* This SDK provides three main modules:
|
|
6
|
+
* - `program`: On-chain program interaction (smart contract)
|
|
7
|
+
* - `api`: REST API client for market data, orders, and positions
|
|
8
|
+
* - `websocket`: Real-time data streaming for orderbooks, trades, and user events
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { LightconePinocchioClient, PROGRAM_ID, api, websocket } from "@lightcone/sdk";
|
|
13
|
+
*
|
|
14
|
+
* // On-chain program interaction
|
|
15
|
+
* const programClient = new LightconePinocchioClient(connection, payer);
|
|
16
|
+
*
|
|
17
|
+
* // REST API client
|
|
18
|
+
* const apiClient = new api.LightconeApiClient();
|
|
19
|
+
* const markets = await apiClient.getMarkets();
|
|
20
|
+
*
|
|
21
|
+
* // WebSocket client for real-time data
|
|
22
|
+
* const wsClient = await websocket.LightconeWebSocketClient.connectDefault();
|
|
23
|
+
* await wsClient.subscribeBookUpdates(["market1:ob1"]);
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
27
|
+
if (k2 === undefined) k2 = k;
|
|
28
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
29
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
30
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
31
|
+
}
|
|
32
|
+
Object.defineProperty(o, k2, desc);
|
|
33
|
+
}) : (function(o, m, k, k2) {
|
|
34
|
+
if (k2 === undefined) k2 = k;
|
|
35
|
+
o[k2] = m[k];
|
|
36
|
+
}));
|
|
37
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
38
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
39
|
+
}) : function(o, v) {
|
|
40
|
+
o["default"] = v;
|
|
41
|
+
});
|
|
42
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
43
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
44
|
+
};
|
|
45
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
46
|
+
var ownKeys = function(o) {
|
|
47
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
48
|
+
var ar = [];
|
|
49
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
50
|
+
return ar;
|
|
51
|
+
};
|
|
52
|
+
return ownKeys(o);
|
|
53
|
+
};
|
|
54
|
+
return function (mod) {
|
|
55
|
+
if (mod && mod.__esModule) return mod;
|
|
56
|
+
var result = {};
|
|
57
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
58
|
+
__setModuleDefault(result, mod);
|
|
59
|
+
return result;
|
|
60
|
+
};
|
|
61
|
+
})();
|
|
62
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
63
|
+
exports.TransactionInstruction = exports.Transaction = exports.Keypair = exports.Connection = exports.PublicKey = exports.auth = exports.websocket = exports.api = exports.DEFAULT_WS_URL = exports.DEFAULT_API_URL = void 0;
|
|
64
|
+
// ============================================================================
|
|
65
|
+
// MODULE EXPORTS
|
|
66
|
+
// ============================================================================
|
|
67
|
+
/**
|
|
68
|
+
* On-chain program interaction module.
|
|
69
|
+
* Contains the client and utilities for interacting with the Lightcone smart contract.
|
|
70
|
+
*/
|
|
71
|
+
__exportStar(require("./program"), exports);
|
|
72
|
+
/**
|
|
73
|
+
* Network URL constants (API and WebSocket endpoints).
|
|
74
|
+
*/
|
|
75
|
+
var network_1 = require("./network");
|
|
76
|
+
Object.defineProperty(exports, "DEFAULT_API_URL", { enumerable: true, get: function () { return network_1.DEFAULT_API_URL; } });
|
|
77
|
+
Object.defineProperty(exports, "DEFAULT_WS_URL", { enumerable: true, get: function () { return network_1.DEFAULT_WS_URL; } });
|
|
78
|
+
/**
|
|
79
|
+
* Shared utilities, types, and constants.
|
|
80
|
+
* Used across all SDK modules.
|
|
81
|
+
*/
|
|
82
|
+
__exportStar(require("./shared"), exports);
|
|
83
|
+
/**
|
|
84
|
+
* REST API client module.
|
|
85
|
+
* Provides HTTP client functionality for market data, orders, and positions.
|
|
86
|
+
*/
|
|
87
|
+
exports.api = __importStar(require("./api"));
|
|
88
|
+
/**
|
|
89
|
+
* WebSocket client module.
|
|
90
|
+
* Provides real-time data streaming for orderbooks, trades, and user events.
|
|
91
|
+
*/
|
|
92
|
+
exports.websocket = __importStar(require("./websocket"));
|
|
93
|
+
/**
|
|
94
|
+
* Authentication module.
|
|
95
|
+
* Provides authentication functionality shared by API and WebSocket clients.
|
|
96
|
+
*/
|
|
97
|
+
exports.auth = __importStar(require("./auth"));
|
|
98
|
+
// ============================================================================
|
|
99
|
+
// RE-EXPORTS FROM DEPENDENCIES
|
|
100
|
+
// ============================================================================
|
|
101
|
+
var web3_js_1 = require("@solana/web3.js");
|
|
102
|
+
Object.defineProperty(exports, "PublicKey", { enumerable: true, get: function () { return web3_js_1.PublicKey; } });
|
|
103
|
+
Object.defineProperty(exports, "Connection", { enumerable: true, get: function () { return web3_js_1.Connection; } });
|
|
104
|
+
Object.defineProperty(exports, "Keypair", { enumerable: true, get: function () { return web3_js_1.Keypair; } });
|
|
105
|
+
Object.defineProperty(exports, "Transaction", { enumerable: true, get: function () { return web3_js_1.Transaction; } });
|
|
106
|
+
Object.defineProperty(exports, "TransactionInstruction", { enumerable: true, get: function () { return web3_js_1.TransactionInstruction; } });
|
|
107
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,+EAA+E;AAC/E,iBAAiB;AACjB,+EAA+E;AAE/E;;;GAGG;AACH,4CAA0B;AAE1B;;GAEG;AACH,qCAA4D;AAAnD,0GAAA,eAAe,OAAA;AAAE,yGAAA,cAAc,OAAA;AAExC;;;GAGG;AACH,2CAAyB;AAEzB;;;GAGG;AACH,6CAA6B;AAE7B;;;GAGG;AACH,yDAAyC;AAEzC;;;GAGG;AACH,+CAA+B;AAE/B,+EAA+E;AAC/E,+BAA+B;AAC/B,+EAA+E;AAC/E,2CAMyB;AALvB,oGAAA,SAAS,OAAA;AACT,qGAAA,UAAU,OAAA;AACV,kGAAA,OAAO,OAAA;AACP,sGAAA,WAAW,OAAA;AACX,iHAAA,sBAAsB,OAAA","sourcesContent":["/**\n * Lightcone SDK - TypeScript SDK for the Lightcone protocol on Solana.\n *\n * This SDK provides three main modules:\n * - `program`: On-chain program interaction (smart contract)\n * - `api`: REST API client for market data, orders, and positions\n * - `websocket`: Real-time data streaming for orderbooks, trades, and user events\n *\n * @example\n * ```typescript\n * import { LightconePinocchioClient, PROGRAM_ID, api, websocket } from \"@lightcone/sdk\";\n *\n * // On-chain program interaction\n * const programClient = new LightconePinocchioClient(connection, payer);\n *\n * // REST API client\n * const apiClient = new api.LightconeApiClient();\n * const markets = await apiClient.getMarkets();\n *\n * // WebSocket client for real-time data\n * const wsClient = await websocket.LightconeWebSocketClient.connectDefault();\n * await wsClient.subscribeBookUpdates([\"market1:ob1\"]);\n * ```\n */\n\n// ============================================================================\n// MODULE EXPORTS\n// ============================================================================\n\n/**\n * On-chain program interaction module.\n * Contains the client and utilities for interacting with the Lightcone smart contract.\n */\nexport * from \"./program\";\n\n/**\n * Network URL constants (API and WebSocket endpoints).\n */\nexport { DEFAULT_API_URL, DEFAULT_WS_URL } from \"./network\";\n\n/**\n * Shared utilities, types, and constants.\n * Used across all SDK modules.\n */\nexport * from \"./shared\";\n\n/**\n * REST API client module.\n * Provides HTTP client functionality for market data, orders, and positions.\n */\nexport * as api from \"./api\";\n\n/**\n * WebSocket client module.\n * Provides real-time data streaming for orderbooks, trades, and user events.\n */\nexport * as websocket from \"./websocket\";\n\n/**\n * Authentication module.\n * Provides authentication functionality shared by API and WebSocket clients.\n */\nexport * as auth from \"./auth\";\n\n// ============================================================================\n// RE-EXPORTS FROM DEPENDENCIES\n// ============================================================================\nexport {\n PublicKey,\n Connection,\n Keypair,\n Transaction,\n TransactionInstruction,\n} from \"@solana/web3.js\";\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Default REST API base URL for Lightcone. */
|
|
2
|
+
export declare const DEFAULT_API_URL = "https://tapi.lightcone.xyz/api";
|
|
3
|
+
/** Default WebSocket URL for Lightcone. */
|
|
4
|
+
export declare const DEFAULT_WS_URL = "wss://ws.lightcone.xyz/ws";
|
|
5
|
+
//# sourceMappingURL=network.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../src/network.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,eAAO,MAAM,eAAe,mCAAmC,CAAC;AAEhE,2CAA2C;AAC3C,eAAO,MAAM,cAAc,8BAA8B,CAAC"}
|
package/dist/network.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_WS_URL = exports.DEFAULT_API_URL = void 0;
|
|
4
|
+
/** Default REST API base URL for Lightcone. */
|
|
5
|
+
exports.DEFAULT_API_URL = "https://tapi.lightcone.xyz/api";
|
|
6
|
+
/** Default WebSocket URL for Lightcone. */
|
|
7
|
+
exports.DEFAULT_WS_URL = "wss://ws.lightcone.xyz/ws";
|
|
8
|
+
//# sourceMappingURL=network.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"network.js","sourceRoot":"","sources":["../src/network.ts"],"names":[],"mappings":";;;AAAA,+CAA+C;AAClC,QAAA,eAAe,GAAG,gCAAgC,CAAC;AAEhE,2CAA2C;AAC9B,QAAA,cAAc,GAAG,2BAA2B,CAAC","sourcesContent":["/** Default REST API base URL for Lightcone. */\nexport const DEFAULT_API_URL = \"https://tapi.lightcone.xyz/api\";\n\n/** Default WebSocket URL for Lightcone. */\nexport const DEFAULT_WS_URL = \"wss://ws.lightcone.xyz/ws\";\n"]}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { Exchange, Market, OrderStatus, UserNonce, Position, Orderbook } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Check if a buffer has a valid Exchange discriminator
|
|
4
|
+
*/
|
|
5
|
+
export declare function isExchangeAccount(data: Buffer): boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Check if a buffer has a valid Market discriminator
|
|
8
|
+
*/
|
|
9
|
+
export declare function isMarketAccount(data: Buffer): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Check if a buffer has a valid OrderStatus discriminator
|
|
12
|
+
*/
|
|
13
|
+
export declare function isOrderStatusAccount(data: Buffer): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Check if a buffer has a valid UserNonce discriminator
|
|
16
|
+
*/
|
|
17
|
+
export declare function isUserNonceAccount(data: Buffer): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Check if a buffer has a valid Position discriminator
|
|
20
|
+
*/
|
|
21
|
+
export declare function isPositionAccount(data: Buffer): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Check if a buffer has a valid Orderbook discriminator
|
|
24
|
+
*/
|
|
25
|
+
export declare function isOrderbookAccount(data: Buffer): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Deserialize Exchange account data
|
|
28
|
+
*
|
|
29
|
+
* Layout (88 bytes):
|
|
30
|
+
* - discriminator: [u8; 8]
|
|
31
|
+
* - authority: Pubkey (32 bytes)
|
|
32
|
+
* - operator: Pubkey (32 bytes)
|
|
33
|
+
* - market_count: u64 (8 bytes)
|
|
34
|
+
* - paused: u8 (1 byte)
|
|
35
|
+
* - bump: u8 (1 byte)
|
|
36
|
+
* - _padding: [u8; 6]
|
|
37
|
+
*/
|
|
38
|
+
export declare function deserializeExchange(data: Buffer): Exchange;
|
|
39
|
+
/**
|
|
40
|
+
* Deserialize Market account data
|
|
41
|
+
*
|
|
42
|
+
* Layout (120 bytes):
|
|
43
|
+
* - discriminator: [u8; 8]
|
|
44
|
+
* - market_id: u64 (8 bytes)
|
|
45
|
+
* - num_outcomes: u8 (1 byte)
|
|
46
|
+
* - status: u8 (1 byte)
|
|
47
|
+
* - winning_outcome: u8 (1 byte)
|
|
48
|
+
* - has_winning_outcome: u8 (1 byte)
|
|
49
|
+
* - bump: u8 (1 byte)
|
|
50
|
+
* - _padding: [u8; 3]
|
|
51
|
+
* - oracle: Pubkey (32 bytes)
|
|
52
|
+
* - question_id: [u8; 32]
|
|
53
|
+
* - condition_id: [u8; 32]
|
|
54
|
+
*/
|
|
55
|
+
export declare function deserializeMarket(data: Buffer): Market;
|
|
56
|
+
/**
|
|
57
|
+
* Deserialize OrderStatus account data
|
|
58
|
+
*
|
|
59
|
+
* Layout (24 bytes):
|
|
60
|
+
* - discriminator: [u8; 8]
|
|
61
|
+
* - remaining: u64 (8 bytes)
|
|
62
|
+
* - is_cancelled: u8 (1 byte)
|
|
63
|
+
* - _padding: [u8; 7]
|
|
64
|
+
*/
|
|
65
|
+
export declare function deserializeOrderStatus(data: Buffer): OrderStatus;
|
|
66
|
+
/**
|
|
67
|
+
* Deserialize UserNonce account data
|
|
68
|
+
*
|
|
69
|
+
* Layout (16 bytes):
|
|
70
|
+
* - discriminator: [u8; 8]
|
|
71
|
+
* - nonce: u64 (8 bytes)
|
|
72
|
+
*/
|
|
73
|
+
export declare function deserializeUserNonce(data: Buffer): UserNonce;
|
|
74
|
+
/**
|
|
75
|
+
* Deserialize Position account data
|
|
76
|
+
*
|
|
77
|
+
* Layout (80 bytes):
|
|
78
|
+
* - discriminator: [u8; 8]
|
|
79
|
+
* - owner: Pubkey (32 bytes)
|
|
80
|
+
* - market: Pubkey (32 bytes)
|
|
81
|
+
* - bump: u8 (1 byte)
|
|
82
|
+
* - _padding: [u8; 7]
|
|
83
|
+
*/
|
|
84
|
+
export declare function deserializePosition(data: Buffer): Position;
|
|
85
|
+
/**
|
|
86
|
+
* Deserialize Orderbook account data
|
|
87
|
+
*
|
|
88
|
+
* Layout (144 bytes):
|
|
89
|
+
* - discriminator: [u8; 8]
|
|
90
|
+
* - market: Pubkey (32 bytes)
|
|
91
|
+
* - mint_a: Pubkey (32 bytes)
|
|
92
|
+
* - mint_b: Pubkey (32 bytes)
|
|
93
|
+
* - lookup_table: Pubkey (32 bytes)
|
|
94
|
+
* - bump: u8 (1 byte)
|
|
95
|
+
* - _padding: [u8; 7]
|
|
96
|
+
*/
|
|
97
|
+
export declare function deserializeOrderbook(data: Buffer): Orderbook;
|
|
98
|
+
//# sourceMappingURL=accounts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accounts.d.ts","sourceRoot":"","sources":["../../src/program/accounts.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,QAAQ,EACR,MAAM,EAEN,WAAW,EACX,SAAS,EACT,QAAQ,EACR,SAAS,EACV,MAAM,SAAS,CAAC;AAuBjB;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAGvD;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAGrD;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAG1D;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAGxD;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAGvD;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAGxD;AAMD;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,CAuC1D;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CA2EtD;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CA2BhE;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAqB5D;AAED;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,CA+B1D;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAuC5D"}
|