@lightconexyz/lightcone-sdk 0.8.1-rc.8 → 0.8.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/README.md +198 -10
- package/dist/auth/client.d.ts +27 -1
- package/dist/auth/client.d.ts.map +1 -1
- package/dist/auth/client.js +94 -4
- package/dist/auth/client.js.map +1 -1
- package/dist/auth/index.d.ts +59 -5
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/index.js +31 -5
- package/dist/auth/index.js.map +1 -1
- package/dist/client.d.ts +49 -3
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +70 -2
- package/dist/client.js.map +1 -1
- package/dist/context.d.ts +59 -3
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +303 -6
- package/dist/context.js.map +1 -1
- package/dist/domain/market/client.d.ts +16 -0
- package/dist/domain/market/client.d.ts.map +1 -1
- package/dist/domain/market/client.js +33 -0
- package/dist/domain/market/client.js.map +1 -1
- package/dist/domain/market/convert.d.ts.map +1 -1
- package/dist/domain/market/convert.js +24 -10
- package/dist/domain/market/convert.js.map +1 -1
- package/dist/domain/market/index.d.ts +18 -4
- package/dist/domain/market/index.d.ts.map +1 -1
- package/dist/domain/market/index.js.map +1 -1
- package/dist/domain/market/outcome.d.ts +9 -3
- package/dist/domain/market/outcome.d.ts.map +1 -1
- package/dist/domain/market/outcome.js +10 -7
- package/dist/domain/market/outcome.js.map +1 -1
- package/dist/domain/market/tokens.js +8 -2
- package/dist/domain/market/tokens.js.map +1 -1
- package/dist/domain/market/wire.d.ts +20 -3
- package/dist/domain/market/wire.d.ts.map +1 -1
- package/dist/domain/market/wire.js.map +1 -1
- package/dist/domain/order/client.d.ts +8 -7
- package/dist/domain/order/client.d.ts.map +1 -1
- package/dist/domain/order/client.js +23 -8
- package/dist/domain/order/client.js.map +1 -1
- package/dist/domain/orderbook/client.d.ts +7 -1
- package/dist/domain/orderbook/client.d.ts.map +1 -1
- package/dist/domain/orderbook/client.js +54 -1
- package/dist/domain/orderbook/client.js.map +1 -1
- package/dist/domain/orderbook/index.d.ts +7 -9
- package/dist/domain/orderbook/index.d.ts.map +1 -1
- package/dist/domain/orderbook/index.js +28 -24
- package/dist/domain/orderbook/index.js.map +1 -1
- package/dist/domain/orderbook/state.d.ts +21 -16
- package/dist/domain/orderbook/state.d.ts.map +1 -1
- package/dist/domain/orderbook/state.js +36 -15
- package/dist/domain/orderbook/state.js.map +1 -1
- package/dist/domain/orderbook/ticker.d.ts +1 -0
- package/dist/domain/orderbook/ticker.d.ts.map +1 -1
- package/dist/domain/orderbook/ticker.js.map +1 -1
- package/dist/domain/orderbook/wire.d.ts +34 -10
- package/dist/domain/orderbook/wire.d.ts.map +1 -1
- package/dist/domain/orderbook/wire.js +47 -0
- package/dist/domain/orderbook/wire.js.map +1 -1
- package/dist/domain/position/builders.d.ts +6 -2
- package/dist/domain/position/builders.d.ts.map +1 -1
- package/dist/domain/position/builders.js +24 -8
- package/dist/domain/position/builders.js.map +1 -1
- package/dist/domain/position/client.d.ts +166 -12
- package/dist/domain/position/client.d.ts.map +1 -1
- package/dist/domain/position/client.js +614 -15
- package/dist/domain/position/client.js.map +1 -1
- package/dist/domain/position/index.d.ts +58 -3
- package/dist/domain/position/index.d.ts.map +1 -1
- package/dist/domain/position/index.js +1 -0
- package/dist/domain/position/index.js.map +1 -1
- package/dist/domain/position/state.d.ts +118 -0
- package/dist/domain/position/state.d.ts.map +1 -0
- package/dist/domain/position/state.js +262 -0
- package/dist/domain/position/state.js.map +1 -0
- package/dist/env.d.ts.map +1 -1
- package/dist/env.js +2 -2
- package/dist/env.js.map +1 -1
- package/dist/error.d.ts +32 -2
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +59 -1
- package/dist/error.js.map +1 -1
- package/dist/http/client.d.ts +76 -1
- package/dist/http/client.d.ts.map +1 -1
- package/dist/http/client.js +259 -39
- package/dist/http/client.js.map +1 -1
- package/dist/http/credentialRestorer.d.ts +49 -0
- package/dist/http/credentialRestorer.d.ts.map +1 -0
- package/dist/http/credentialRestorer.js +3 -0
- package/dist/http/credentialRestorer.js.map +1 -0
- package/dist/http/index.d.ts +1 -0
- package/dist/http/index.d.ts.map +1 -1
- package/dist/http/index.js.map +1 -1
- package/dist/index.d.ts +6 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/prelude.d.ts +10 -7
- package/dist/prelude.d.ts.map +1 -1
- package/dist/prelude.js +12 -2
- package/dist/prelude.js.map +1 -1
- package/dist/privy/client.d.ts +4 -0
- package/dist/privy/client.d.ts.map +1 -1
- package/dist/privy/client.js +4 -0
- package/dist/privy/client.js.map +1 -1
- package/dist/privy/index.d.ts +4 -4
- package/dist/privy/index.d.ts.map +1 -1
- package/dist/privy/index.js +11 -16
- package/dist/privy/index.js.map +1 -1
- package/dist/program/builder.d.ts +13 -11
- package/dist/program/builder.d.ts.map +1 -1
- package/dist/program/builder.js +31 -16
- package/dist/program/builder.js.map +1 -1
- package/dist/program/constants.d.ts +1 -0
- package/dist/program/constants.d.ts.map +1 -1
- package/dist/program/constants.js +1 -0
- package/dist/program/constants.js.map +1 -1
- package/dist/program/envelope.d.ts +14 -16
- package/dist/program/envelope.d.ts.map +1 -1
- package/dist/program/envelope.js +48 -39
- package/dist/program/envelope.js.map +1 -1
- package/dist/program/index.d.ts +2 -2
- package/dist/program/index.d.ts.map +1 -1
- package/dist/program/index.js +6 -4
- package/dist/program/index.js.map +1 -1
- package/dist/program/instructions.d.ts +17 -9
- package/dist/program/instructions.d.ts.map +1 -1
- package/dist/program/instructions.js +40 -19
- package/dist/program/instructions.js.map +1 -1
- package/dist/program/orders.d.ts +7 -8
- package/dist/program/orders.d.ts.map +1 -1
- package/dist/program/orders.js +20 -22
- package/dist/program/orders.js.map +1 -1
- package/dist/program/types.d.ts +4 -3
- package/dist/program/types.d.ts.map +1 -1
- package/dist/program/types.js.map +1 -1
- package/dist/rpc.d.ts +89 -1
- package/dist/rpc.d.ts.map +1 -1
- package/dist/rpc.js +285 -4
- package/dist/rpc.js.map +1 -1
- package/dist/shared/api_response.d.ts +16 -1
- package/dist/shared/api_response.d.ts.map +1 -1
- package/dist/shared/api_response.js +26 -1
- package/dist/shared/api_response.js.map +1 -1
- package/dist/shared/index.d.ts +3 -3
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/index.js +13 -6
- package/dist/shared/index.js.map +1 -1
- package/dist/shared/json.d.ts +5 -0
- package/dist/shared/json.d.ts.map +1 -0
- package/dist/shared/json.js +38 -0
- package/dist/shared/json.js.map +1 -0
- package/dist/shared/rejection.d.ts.map +1 -1
- package/dist/shared/rejection.js +8 -0
- package/dist/shared/rejection.js.map +1 -1
- package/dist/shared/scaling.d.ts +30 -18
- package/dist/shared/scaling.d.ts.map +1 -1
- package/dist/shared/scaling.js +153 -95
- package/dist/shared/scaling.js.map +1 -1
- package/dist/shared/signing.d.ts +17 -0
- package/dist/shared/signing.d.ts.map +1 -1
- package/dist/shared/signing.js +27 -0
- package/dist/shared/signing.js.map +1 -1
- package/dist/shared/types.d.ts +9 -7
- package/dist/shared/types.d.ts.map +1 -1
- package/dist/shared/types.js +12 -4
- package/dist/shared/types.js.map +1 -1
- package/dist/ws/client.browser.d.ts +4 -0
- package/dist/ws/client.browser.d.ts.map +1 -1
- package/dist/ws/client.browser.js +13 -1
- package/dist/ws/client.browser.js.map +1 -1
- package/dist/ws/client.node.d.ts +4 -0
- package/dist/ws/client.node.d.ts.map +1 -1
- package/dist/ws/client.node.js +13 -1
- package/dist/ws/client.node.js.map +1 -1
- package/dist/ws/index.d.ts +24 -0
- package/dist/ws/index.d.ts.map +1 -1
- package/dist/ws/index.js +176 -2
- package/dist/ws/index.js.map +1 -1
- package/dist/ws/subscriptions.d.ts +12 -1
- package/dist/ws/subscriptions.d.ts.map +1 -1
- package/dist/ws/subscriptions.js +11 -0
- package/dist/ws/subscriptions.js.map +1 -1
- package/dist/ws/types.d.ts +5 -0
- package/dist/ws/types.d.ts.map +1 -1
- package/dist/ws/types.js.map +1 -1
- package/package.json +6 -2
package/dist/auth/index.d.ts
CHANGED
|
@@ -48,6 +48,46 @@ export interface GoogleAccountData {
|
|
|
48
48
|
family_name?: string;
|
|
49
49
|
avatar_url?: string;
|
|
50
50
|
}
|
|
51
|
+
/** Canonical address for a passwordless Email login identity. */
|
|
52
|
+
export interface EmailAccountData {
|
|
53
|
+
email: string;
|
|
54
|
+
}
|
|
55
|
+
/** Public login-method names exposed in profiles and bounded conflicts. */
|
|
56
|
+
export type LinkedIdentityType = "email" | "google" | "x" | "wallet";
|
|
57
|
+
/** Connected Login Identity without repeated Account-level Privy wallet data. */
|
|
58
|
+
export type LinkedIdentity = {
|
|
59
|
+
type: "email";
|
|
60
|
+
account: EmailAccountData;
|
|
61
|
+
} | {
|
|
62
|
+
type: "google";
|
|
63
|
+
account: GoogleAccountData;
|
|
64
|
+
} | {
|
|
65
|
+
type: "x";
|
|
66
|
+
account: XAccountData;
|
|
67
|
+
} | {
|
|
68
|
+
type: "wallet";
|
|
69
|
+
address: string;
|
|
70
|
+
chain: ChainType;
|
|
71
|
+
};
|
|
72
|
+
/** Verified method and canonical identifier that initiated Privy authentication. */
|
|
73
|
+
export type LinkedIdentitySelector = {
|
|
74
|
+
type: "email";
|
|
75
|
+
email: string;
|
|
76
|
+
} | {
|
|
77
|
+
type: "google";
|
|
78
|
+
email: string;
|
|
79
|
+
} | {
|
|
80
|
+
type: "x";
|
|
81
|
+
username: string;
|
|
82
|
+
} | {
|
|
83
|
+
type: "wallet";
|
|
84
|
+
address: string;
|
|
85
|
+
chain: ChainType;
|
|
86
|
+
};
|
|
87
|
+
/** Register-or-sync request naming the verified attempted identity. */
|
|
88
|
+
export interface RegisterPrivyRequest {
|
|
89
|
+
attempted_identity: LinkedIdentitySelector;
|
|
90
|
+
}
|
|
51
91
|
/**
|
|
52
92
|
* The login identity — how the user authenticates. `type` narrows the variant.
|
|
53
93
|
*
|
|
@@ -57,6 +97,10 @@ export interface GoogleAccountData {
|
|
|
57
97
|
* self-custody.
|
|
58
98
|
*/
|
|
59
99
|
export type UserIdentity = {
|
|
100
|
+
type: "email";
|
|
101
|
+
account: EmailAccountData;
|
|
102
|
+
privy: UserPrivyData;
|
|
103
|
+
} | {
|
|
60
104
|
type: "google";
|
|
61
105
|
account: GoogleAccountData;
|
|
62
106
|
privy: UserPrivyData;
|
|
@@ -74,6 +118,10 @@ export type UserIdentity = {
|
|
|
74
118
|
export interface User {
|
|
75
119
|
user_id: string;
|
|
76
120
|
identity: UserIdentity;
|
|
121
|
+
/** Every verified login identity connected to the Account, primary first. */
|
|
122
|
+
linked_identities?: LinkedIdentity[];
|
|
123
|
+
/** Remembered account-wide percentage below 10%; null until one is stored. */
|
|
124
|
+
max_slippage_preference: string | null;
|
|
77
125
|
/** X account connected by a non-X-identity user; absent when identity is X. */
|
|
78
126
|
connected_x?: XAccountData;
|
|
79
127
|
}
|
|
@@ -88,8 +136,12 @@ export interface SessionResponse {
|
|
|
88
136
|
auth_method: AuthMethod;
|
|
89
137
|
is_beta: boolean;
|
|
90
138
|
}
|
|
91
|
-
/**
|
|
92
|
-
export
|
|
139
|
+
/** Exact decimal-string body used to update and return max slippage. */
|
|
140
|
+
export interface MaxSlippagePreferenceBody {
|
|
141
|
+
max_slippage_preference: string;
|
|
142
|
+
}
|
|
143
|
+
/** Human-readable login-method label ("Email" / "Google" / "X" / "Solana"). */
|
|
144
|
+
export declare function identityText(identity: UserIdentity): "Email" | "Google" | "X" | "Solana";
|
|
93
145
|
/** Privy account data, regardless of identity type. */
|
|
94
146
|
export declare function userPrivy(user: User): UserPrivyData | undefined;
|
|
95
147
|
/** The X account, whether it is the login identity or a connected account. */
|
|
@@ -104,10 +156,12 @@ export declare function userXAccount(user: User): XAccountData | undefined;
|
|
|
104
156
|
* wallet that signed in.
|
|
105
157
|
*/
|
|
106
158
|
export declare function tradingWallet(user: User, authMethod: AuthMethod): string;
|
|
159
|
+
/** Short display label for the wallet a session operates as. */
|
|
160
|
+
export declare function walletDisplayName(user: User, authMethod: AuthMethod): string;
|
|
107
161
|
/**
|
|
108
|
-
* Best display name for the user.
|
|
109
|
-
*
|
|
110
|
-
* shortened address (`FRGk...WcPR`).
|
|
162
|
+
* Best display name for the user. Email addresses are limited to 20 characters;
|
|
163
|
+
* Google uses `name` with an email fallback; X uses `display_name` with a
|
|
164
|
+
* username fallback; wallet identities show the shortened address (`FRGk...WcPR`).
|
|
111
165
|
*/
|
|
112
166
|
export declare function displayName(user: User): string;
|
|
113
167
|
/** Avatar URL from the login identity's OAuth provider, if any. */
|
package/dist/auth/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAG3C,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AAEzB;;;GAGG;AACH,oBAAY,UAAU;IACpB,KAAK,UAAU;IACf,SAAS,cAAc;CACxB;AAED,oBAAY,SAAS;IACnB,MAAM,WAAW;IACjB,QAAQ,aAAa;CACtB;AAED,uCAAuC;AACvC,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,SAAS,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,kDAAkD;AAClD,MAAM,WAAW,aAAa;IAC5B,uCAAuC;IACvC,EAAE,EAAE,MAAM,CAAC;IACX;;;OAGG;IACH,MAAM,EAAE,mBAAmB,CAAC;CAC7B;AAED;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,kEAAkE;IAClE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,uDAAuD;AACvD,MAAM,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AAC9E,wBAAgB,YAAY,CAAC,IAAI,EAAE,IAAI,GAAG,YAAY,GAAG,SAAS,CAEjE;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,UAAU,GAAG,MAAM,CAWxE;AAED,gEAAgE;AAChE,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,UAAU,GAAG,MAAM,CAE5E;AAiBD;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAa9C;AAED,mEAAmE;AACnE,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,GAAG,SAAS,CAUxD;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,SAAS,CAAC;IAC1B,UAAU,EAAE,IAAI,CAAC;CAClB;AAED,wBAAgB,eAAe,CAAC,WAAW,CAAC,EAAE,eAAe,GAAG,OAAO,CAKtE;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAE/D;AAED,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B;AAED,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;CACf"}
|
package/dist/auth/index.js
CHANGED
|
@@ -19,6 +19,7 @@ exports.identityText = identityText;
|
|
|
19
19
|
exports.userPrivy = userPrivy;
|
|
20
20
|
exports.userXAccount = userXAccount;
|
|
21
21
|
exports.tradingWallet = tradingWallet;
|
|
22
|
+
exports.walletDisplayName = walletDisplayName;
|
|
22
23
|
exports.displayName = displayName;
|
|
23
24
|
exports.avatarUrl = avatarUrl;
|
|
24
25
|
exports.isAuthenticated = isAuthenticated;
|
|
@@ -40,9 +41,11 @@ var ChainType;
|
|
|
40
41
|
ChainType["Solana"] = "solana";
|
|
41
42
|
ChainType["Ethereum"] = "ethereum";
|
|
42
43
|
})(ChainType || (exports.ChainType = ChainType = {}));
|
|
43
|
-
/** Human-readable login-method label ("Google" / "X" / "Solana"). */
|
|
44
|
+
/** Human-readable login-method label ("Email" / "Google" / "X" / "Solana"). */
|
|
44
45
|
function identityText(identity) {
|
|
45
46
|
switch (identity.type) {
|
|
47
|
+
case "email":
|
|
48
|
+
return "Email";
|
|
46
49
|
case "google":
|
|
47
50
|
return "Google";
|
|
48
51
|
case "x":
|
|
@@ -58,6 +61,7 @@ function identityText(identity) {
|
|
|
58
61
|
/** Privy account data, regardless of identity type. */
|
|
59
62
|
function userPrivy(user) {
|
|
60
63
|
switch (user.identity.type) {
|
|
64
|
+
case "email":
|
|
61
65
|
case "google":
|
|
62
66
|
case "x":
|
|
63
67
|
return user.identity.privy;
|
|
@@ -80,6 +84,7 @@ function userXAccount(user) {
|
|
|
80
84
|
*/
|
|
81
85
|
function tradingWallet(user, authMethod) {
|
|
82
86
|
switch (user.identity.type) {
|
|
87
|
+
case "email":
|
|
83
88
|
case "google":
|
|
84
89
|
case "x":
|
|
85
90
|
return user.identity.privy.wallet.address;
|
|
@@ -89,17 +94,36 @@ function tradingWallet(user, authMethod) {
|
|
|
89
94
|
: user.identity.address;
|
|
90
95
|
}
|
|
91
96
|
}
|
|
97
|
+
/** Short display label for the wallet a session operates as. */
|
|
98
|
+
function walletDisplayName(user, authMethod) {
|
|
99
|
+
return (0, str_1.shorten)(tradingWallet(user, authMethod), 8);
|
|
100
|
+
}
|
|
101
|
+
/** Keeps Email labels compact while preserving the recognizable address ends. */
|
|
102
|
+
function emailDisplayName(email) {
|
|
103
|
+
const maxChars = 20;
|
|
104
|
+
const chars = [...email];
|
|
105
|
+
if (chars.length <= maxChars) {
|
|
106
|
+
return email;
|
|
107
|
+
}
|
|
108
|
+
const visibleChars = maxChars - 3;
|
|
109
|
+
const prefixChars = Math.floor(visibleChars / 2);
|
|
110
|
+
return `${chars.slice(0, prefixChars).join("")}...${chars
|
|
111
|
+
.slice(-(visibleChars - prefixChars))
|
|
112
|
+
.join("")}`;
|
|
113
|
+
}
|
|
92
114
|
/**
|
|
93
|
-
* Best display name for the user.
|
|
94
|
-
*
|
|
95
|
-
* shortened address (`FRGk...WcPR`).
|
|
115
|
+
* Best display name for the user. Email addresses are limited to 20 characters;
|
|
116
|
+
* Google uses `name` with an email fallback; X uses `display_name` with a
|
|
117
|
+
* username fallback; wallet identities show the shortened address (`FRGk...WcPR`).
|
|
96
118
|
*/
|
|
97
119
|
function displayName(user) {
|
|
98
120
|
switch (user.identity.type) {
|
|
121
|
+
case "email":
|
|
122
|
+
return emailDisplayName(user.identity.account.email);
|
|
99
123
|
case "google":
|
|
100
124
|
return user.identity.account.name ?? user.identity.account.email;
|
|
101
125
|
case "x":
|
|
102
|
-
return user.identity.account.display_name ?? user.identity.account.username;
|
|
126
|
+
return (user.identity.account.display_name ?? user.identity.account.username);
|
|
103
127
|
case "wallet":
|
|
104
128
|
return (0, str_1.shorten)(user.identity.address, 8);
|
|
105
129
|
}
|
|
@@ -107,6 +131,8 @@ function displayName(user) {
|
|
|
107
131
|
/** Avatar URL from the login identity's OAuth provider, if any. */
|
|
108
132
|
function avatarUrl(user) {
|
|
109
133
|
switch (user.identity.type) {
|
|
134
|
+
case "email":
|
|
135
|
+
return undefined;
|
|
110
136
|
case "google":
|
|
111
137
|
case "x":
|
|
112
138
|
return user.identity.account.avatar_url;
|
package/dist/auth/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AA6FA,oCAaC;AAGD,8BAQC;AAGD,oCAEC;AAWD,sCAUC;AAOD,kCASC;AAGD,8BAQC;AAQD,0CAKC;AAED,sDAEC;AA1LD,2CAA4C;AAE5C,2CAAy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B;IAC3D,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,WAAW,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;AACvD,CAAC;AAED,SAAgB,qBAAqB,CAAC,KAAa;IACjD,OAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,gCAAgC,KAAK,EAAE,CAAC,CAAC;AAC3E,CAAC","sourcesContent":["import type { PubkeyStr } from \"../shared\";\nimport { shorten } from \"../shared/fmt/str\";\n\nexport * from \"./client\";\nexport * from \"./native\";\n\n/**\n * How a session authenticated, as reported by the backend (derived from which\n * token verified the request).\n */\nexport enum AuthMethod {\n Privy = \"privy\",\n Lightcone = \"lightcone\",\n}\n\nexport enum ChainType {\n Solana = \"solana\",\n Ethereum = \"ethereum\",\n}\n\n/** A Privy-managed embedded wallet. */\nexport interface PrivyEmbeddedWallet {\n privy_id: string;\n chain: ChainType;\n address: string;\n}\n\n/** Privy account data attached to an identity. */\nexport interface UserPrivyData {\n /** The Privy DID (`did:privy:...`). */\n id: string;\n /**\n * Always present: Privy registration provisions the embedded wallet in the\n * same transaction that creates the user.\n */\n wallet: PrivyEmbeddedWallet;\n}\n\n/**\n * X account data — the same shape whether X is the login identity or a\n * connected account on a Google/wallet identity.\n */\nexport interface XAccountData {\n /** X numeric user id (Privy `subject`); absent on legacy rows. */\n user_id?: string;\n username: string;\n display_name?: string;\n avatar_url?: string;\n}\n\n/** Google account data for a Google login identity. */\nexport interface GoogleAccountData {\n email: string;\n name?: string;\n given_name?: string;\n family_name?: string;\n avatar_url?: string;\n}\n\n/**\n * The login identity — how the user authenticates. `type` narrows the variant.\n *\n * Privy data lives on the variant because its presence is determined by the\n * identity type: Google/X login only exists via Privy OAuth (guaranteed DID +\n * embedded wallet), while wallet users opt into Privy (SIWS) or stay\n * self-custody.\n */\nexport type UserIdentity =\n | { type: \"google\"; account: GoogleAccountData; privy: UserPrivyData }\n | { type: \"x\"; account: XAccountData; privy: UserPrivyData }\n | { type: \"wallet\"; address: string; chain: ChainType; privy?: UserPrivyData };\n\n/** Full user profile — the `user` object of {@link SessionResponse}. */\nexport interface User {\n user_id: string;\n identity: UserIdentity;\n /** X account connected by a non-X-identity user; absent when identity is X. */\n connected_x?: XAccountData;\n}\n\n/**\n * Session envelope returned by `loginWithMessage`, `register-privy`, and\n * `GET /api/auth/me`. There is no `wallet_address` field — derive the\n * session's trading wallet with {@link tradingWallet}.\n */\nexport interface SessionResponse {\n user: User;\n expires_at: number;\n auth_method: AuthMethod;\n is_beta: boolean;\n}\n\n/** Human-readable login-method label (\"Google\" / \"X\" / \"Solana\"). */\nexport function identityText(identity: UserIdentity): \"Google\" | \"X\" | \"Solana\" {\n switch (identity.type) {\n case \"google\":\n return \"Google\";\n case \"x\":\n return \"X\";\n case \"wallet\":\n return \"Solana\";\n default: {\n const exhaustive: never = identity;\n throw new Error(`Unknown identity: ${JSON.stringify(exhaustive)}`);\n }\n }\n}\n\n/** Privy account data, regardless of identity type. */\nexport function userPrivy(user: User): UserPrivyData | undefined {\n switch (user.identity.type) {\n case \"google\":\n case \"x\":\n return user.identity.privy;\n case \"wallet\":\n return user.identity.privy;\n }\n}\n\n/** The X account, whether it is the login identity or a connected account. */\nexport function userXAccount(user: User): XAccountData | undefined {\n return user.identity.type === \"x\" ? user.identity.account : user.connected_x;\n}\n\n/**\n * The wallet a session operates as.\n *\n * Google/X identities only exist via Privy registration, which always\n * provisions an embedded wallet — that wallet is the answer regardless of\n * auth method. Wallet identities depend on the session: a Privy (SIWS)\n * session trades via the embedded wallet, a Lightcone session trades via the\n * wallet that signed in.\n */\nexport function tradingWallet(user: User, authMethod: AuthMethod): string {\n switch (user.identity.type) {\n case \"google\":\n case \"x\":\n return user.identity.privy.wallet.address;\n case \"wallet\":\n return authMethod === AuthMethod.Privy\n ? (user.identity.privy?.wallet.address ?? user.identity.address)\n : user.identity.address;\n }\n}\n\n/**\n * Best display name for the user. Google: `name`, falling back to the email;\n * X: `display_name`, falling back to the username; wallet identities show the\n * shortened address (`FRGk...WcPR`).\n */\nexport function displayName(user: User): string {\n switch (user.identity.type) {\n case \"google\":\n return user.identity.account.name ?? user.identity.account.email;\n case \"x\":\n return user.identity.account.display_name ?? user.identity.account.username;\n case \"wallet\":\n return shorten(user.identity.address, 8);\n }\n}\n\n/** Avatar URL from the login identity's OAuth provider, if any. */\nexport function avatarUrl(user: User): string | undefined {\n switch (user.identity.type) {\n case \"google\":\n case \"x\":\n return user.identity.account.avatar_url;\n case \"wallet\":\n return undefined;\n }\n}\n\nexport interface AuthCredentials {\n user_id: string;\n wallet_address: PubkeyStr;\n expires_at: Date;\n}\n\nexport function isAuthenticated(credentials?: AuthCredentials): boolean {\n if (!credentials) {\n return false;\n }\n return Date.now() < credentials.expires_at.getTime();\n}\n\nexport function generateSigninMessage(nonce: string): Uint8Array {\n return new TextEncoder().encode(`Sign in to Lightcone\\nNonce: ${nonce}`);\n}\n\nexport interface LoginRequest {\n message: string;\n signature_bs58: string;\n pubkey_bytes: number[];\n use_embedded_wallet?: boolean;\n}\n\nexport interface NonceResponse {\n nonce: string;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAuIA,oCAiBC;AAGD,8BASC;AAGD,oCAEC;AAWD,sCAWC;AAGD,8CAEC;AAsBD,kCAaC;AAGD,8BAUC;AAQD,0CAKC;AAED,sDAEC;AApQD,2CAA4C;AAE5C,2CAAyB;AACzB,2CAAyB;AAEzB;;;GAGG;AACH,IAAY,UAGX;AAHD,WAAY,UAAU;IACpB,6BAAe,CAAA;IACf,qCAAuB,CAAA;AACzB,CAAC,EAHW,UAAU,0BAAV,UAAU,QAGrB;AAED,IAAY,SAGX;AAHD,WAAY,SAAS;IACnB,8BAAiB,CAAA;IACjB,kCAAqB,CAAA;AACvB,CAAC,EAHW,SAAS,yBAAT,S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;YACX,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,IAAI,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC;QACnE,KAAK,GAAG;YACN,OAAO,CACL,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,YAAY,IAAI,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,QAAQ,CACrE,CAAC;QACJ,KAAK,QAAQ;YACX,OAAO,IAAA,aAAO,EAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;IAC7C,CAAC;AACH,CAAC;AAED,mEAAmE;AACnE,SAAgB,SAAS,CAAC,IAAU;IAClC,QAAQ,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;QAC3B,KAAK,OAAO;YACV,OAAO,SAAS,CAAC;QACnB,KAAK,QAAQ,CAAC;QACd,KAAK,GAAG;YACN,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,UAAU,CAAC;QAC1C,KAAK,QAAQ;YACX,OAAO,SAAS,CAAC;IACrB,CAAC;AACH,CAAC;AAQD,SAAgB,eAAe,CAAC,WAA6B;IAC3D,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,WAAW,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;AACvD,CAAC;AAED,SAAgB,qBAAqB,CAAC,KAAa;IACjD,OAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,gCAAgC,KAAK,EAAE,CAAC,CAAC;AAC3E,CAAC","sourcesContent":["import type { PubkeyStr } from \"../shared\";\nimport { shorten } from \"../shared/fmt/str\";\n\nexport * from \"./client\";\nexport * from \"./native\";\n\n/**\n * How a session authenticated, as reported by the backend (derived from which\n * token verified the request).\n */\nexport enum AuthMethod {\n Privy = \"privy\",\n Lightcone = \"lightcone\",\n}\n\nexport enum ChainType {\n Solana = \"solana\",\n Ethereum = \"ethereum\",\n}\n\n/** A Privy-managed embedded wallet. */\nexport interface PrivyEmbeddedWallet {\n privy_id: string;\n chain: ChainType;\n address: string;\n}\n\n/** Privy account data attached to an identity. */\nexport interface UserPrivyData {\n /** The Privy DID (`did:privy:...`). */\n id: string;\n /**\n * Always present: Privy registration provisions the embedded wallet in the\n * same transaction that creates the user.\n */\n wallet: PrivyEmbeddedWallet;\n}\n\n/**\n * X account data — the same shape whether X is the login identity or a\n * connected account on a Google/wallet identity.\n */\nexport interface XAccountData {\n /** X numeric user id (Privy `subject`); absent on legacy rows. */\n user_id?: string;\n username: string;\n display_name?: string;\n avatar_url?: string;\n}\n\n/** Google account data for a Google login identity. */\nexport interface GoogleAccountData {\n email: string;\n name?: string;\n given_name?: string;\n family_name?: string;\n avatar_url?: string;\n}\n\n/** Canonical address for a passwordless Email login identity. */\nexport interface EmailAccountData {\n email: string;\n}\n\n/** Public login-method names exposed in profiles and bounded conflicts. */\nexport type LinkedIdentityType = \"email\" | \"google\" | \"x\" | \"wallet\";\n\n/** Connected Login Identity without repeated Account-level Privy wallet data. */\nexport type LinkedIdentity =\n | { type: \"email\"; account: EmailAccountData }\n | { type: \"google\"; account: GoogleAccountData }\n | { type: \"x\"; account: XAccountData }\n | { type: \"wallet\"; address: string; chain: ChainType };\n\n/** Verified method and canonical identifier that initiated Privy authentication. */\nexport type LinkedIdentitySelector =\n | { type: \"email\"; email: string }\n | { type: \"google\"; email: string }\n | { type: \"x\"; username: string }\n | { type: \"wallet\"; address: string; chain: ChainType };\n\n/** Register-or-sync request naming the verified attempted identity. */\nexport interface RegisterPrivyRequest {\n attempted_identity: LinkedIdentitySelector;\n}\n\n/**\n * The login identity — how the user authenticates. `type` narrows the variant.\n *\n * Privy data lives on the variant because its presence is determined by the\n * identity type: Google/X login only exists via Privy OAuth (guaranteed DID +\n * embedded wallet), while wallet users opt into Privy (SIWS) or stay\n * self-custody.\n */\nexport type UserIdentity =\n | { type: \"email\"; account: EmailAccountData; privy: UserPrivyData }\n | { type: \"google\"; account: GoogleAccountData; privy: UserPrivyData }\n | { type: \"x\"; account: XAccountData; privy: UserPrivyData }\n | {\n type: \"wallet\";\n address: string;\n chain: ChainType;\n privy?: UserPrivyData;\n };\n\n/** Full user profile — the `user` object of {@link SessionResponse}. */\nexport interface User {\n user_id: string;\n identity: UserIdentity;\n /** Every verified login identity connected to the Account, primary first. */\n linked_identities?: LinkedIdentity[];\n /** Remembered account-wide percentage below 10%; null until one is stored. */\n max_slippage_preference: string | null;\n /** X account connected by a non-X-identity user; absent when identity is X. */\n connected_x?: XAccountData;\n}\n\n/**\n * Session envelope returned by `loginWithMessage`, `register-privy`, and\n * `GET /api/auth/me`. There is no `wallet_address` field — derive the\n * session's trading wallet with {@link tradingWallet}.\n */\nexport interface SessionResponse {\n user: User;\n expires_at: number;\n auth_method: AuthMethod;\n is_beta: boolean;\n}\n\n/** Exact decimal-string body used to update and return max slippage. */\nexport interface MaxSlippagePreferenceBody {\n max_slippage_preference: string;\n}\n\n/** Human-readable login-method label (\"Email\" / \"Google\" / \"X\" / \"Solana\"). */\nexport function identityText(\n identity: UserIdentity,\n): \"Email\" | \"Google\" | \"X\" | \"Solana\" {\n switch (identity.type) {\n case \"email\":\n return \"Email\";\n case \"google\":\n return \"Google\";\n case \"x\":\n return \"X\";\n case \"wallet\":\n return \"Solana\";\n default: {\n const exhaustive: never = identity;\n throw new Error(`Unknown identity: ${JSON.stringify(exhaustive)}`);\n }\n }\n}\n\n/** Privy account data, regardless of identity type. */\nexport function userPrivy(user: User): UserPrivyData | undefined {\n switch (user.identity.type) {\n case \"email\":\n case \"google\":\n case \"x\":\n return user.identity.privy;\n case \"wallet\":\n return user.identity.privy;\n }\n}\n\n/** The X account, whether it is the login identity or a connected account. */\nexport function userXAccount(user: User): XAccountData | undefined {\n return user.identity.type === \"x\" ? user.identity.account : user.connected_x;\n}\n\n/**\n * The wallet a session operates as.\n *\n * Google/X identities only exist via Privy registration, which always\n * provisions an embedded wallet — that wallet is the answer regardless of\n * auth method. Wallet identities depend on the session: a Privy (SIWS)\n * session trades via the embedded wallet, a Lightcone session trades via the\n * wallet that signed in.\n */\nexport function tradingWallet(user: User, authMethod: AuthMethod): string {\n switch (user.identity.type) {\n case \"email\":\n case \"google\":\n case \"x\":\n return user.identity.privy.wallet.address;\n case \"wallet\":\n return authMethod === AuthMethod.Privy\n ? (user.identity.privy?.wallet.address ?? user.identity.address)\n : user.identity.address;\n }\n}\n\n/** Short display label for the wallet a session operates as. */\nexport function walletDisplayName(user: User, authMethod: AuthMethod): string {\n return shorten(tradingWallet(user, authMethod), 8);\n}\n\n/** Keeps Email labels compact while preserving the recognizable address ends. */\nfunction emailDisplayName(email: string): string {\n const maxChars = 20;\n const chars = [...email];\n if (chars.length <= maxChars) {\n return email;\n }\n\n const visibleChars = maxChars - 3;\n const prefixChars = Math.floor(visibleChars / 2);\n return `${chars.slice(0, prefixChars).join(\"\")}...${chars\n .slice(-(visibleChars - prefixChars))\n .join(\"\")}`;\n}\n\n/**\n * Best display name for the user. Email addresses are limited to 20 characters;\n * Google uses `name` with an email fallback; X uses `display_name` with a\n * username fallback; wallet identities show the shortened address (`FRGk...WcPR`).\n */\nexport function displayName(user: User): string {\n switch (user.identity.type) {\n case \"email\":\n return emailDisplayName(user.identity.account.email);\n case \"google\":\n return user.identity.account.name ?? user.identity.account.email;\n case \"x\":\n return (\n user.identity.account.display_name ?? user.identity.account.username\n );\n case \"wallet\":\n return shorten(user.identity.address, 8);\n }\n}\n\n/** Avatar URL from the login identity's OAuth provider, if any. */\nexport function avatarUrl(user: User): string | undefined {\n switch (user.identity.type) {\n case \"email\":\n return undefined;\n case \"google\":\n case \"x\":\n return user.identity.account.avatar_url;\n case \"wallet\":\n return undefined;\n }\n}\n\nexport interface AuthCredentials {\n user_id: string;\n wallet_address: PubkeyStr;\n expires_at: Date;\n}\n\nexport function isAuthenticated(credentials?: AuthCredentials): boolean {\n if (!credentials) {\n return false;\n }\n return Date.now() < credentials.expires_at.getTime();\n}\n\nexport function generateSigninMessage(nonce: string): Uint8Array {\n return new TextEncoder().encode(`Sign in to Lightcone\\nNonce: ${nonce}`);\n}\n\nexport interface LoginRequest {\n message: string;\n signature_bs58: string;\n pubkey_bytes: number[];\n use_embedded_wallet?: boolean;\n}\n\nexport interface NonceResponse {\n nonce: string;\n}\n"]}
|
package/dist/client.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Connection, Keypair, PublicKey, Transaction } from "@solana/web3.js";
|
|
2
2
|
import { Auth, type AuthCredentials } from "./auth";
|
|
3
3
|
import type { ClientContext } from "./context";
|
|
4
|
+
import type { ConfirmedTransaction } from "./context";
|
|
4
5
|
import type { FaucetResponse } from "./domain/faucet";
|
|
5
6
|
import { Markets } from "./domain/market";
|
|
6
7
|
import { Metrics } from "./domain/metrics";
|
|
@@ -11,12 +12,12 @@ import { Positions } from "./domain/position";
|
|
|
11
12
|
import { PriceHistoryClient } from "./domain/price_history";
|
|
12
13
|
import { Referrals } from "./domain/referral";
|
|
13
14
|
import { Trades } from "./domain/trade";
|
|
14
|
-
import { LightconeHttp } from "./http";
|
|
15
|
+
import { LightconeHttp, type CredentialRestorer } from "./http";
|
|
15
16
|
import { LightconeEnv } from "./env";
|
|
16
17
|
import { Privy } from "./privy";
|
|
17
18
|
import { Rpc } from "./rpc";
|
|
18
19
|
import { RpcFailoverState } from "./rpcFailover";
|
|
19
|
-
import { DepositSource, type PubkeyStr } from "./shared";
|
|
20
|
+
import { DepositSource, type OrderbookRules, type PubkeyStr } from "./shared";
|
|
20
21
|
import { type ExternalSigner, type SigningStrategy } from "./shared/signing";
|
|
21
22
|
import { WsClient, type WsConfig } from "./ws";
|
|
22
23
|
declare class AuthState {
|
|
@@ -34,9 +35,11 @@ export declare class LightconeClient implements ClientContext {
|
|
|
34
35
|
readonly rpcFailoverState: RpcFailoverState;
|
|
35
36
|
private depositSourceValue;
|
|
36
37
|
private signingStrategyValue?;
|
|
38
|
+
private transactionSponsorshipEnabledValue;
|
|
37
39
|
private orderNonceValue;
|
|
38
40
|
private readonly wsConfigValue;
|
|
39
41
|
private readonly authStateStore;
|
|
42
|
+
readonly orderbookRulesCache: Map<string, Promise<OrderbookRules>>;
|
|
40
43
|
/** @deprecated Use primaryConnection — kept for ClientContext compat. */
|
|
41
44
|
get connection(): Connection | undefined;
|
|
42
45
|
constructor(params: {
|
|
@@ -48,15 +51,28 @@ export declare class LightconeClient implements ClientContext {
|
|
|
48
51
|
rpcFailoverState?: RpcFailoverState;
|
|
49
52
|
depositSource?: DepositSource;
|
|
50
53
|
signingStrategy?: SigningStrategy;
|
|
54
|
+
transactionSponsorshipEnabled?: boolean;
|
|
51
55
|
orderNonce?: number;
|
|
52
56
|
authCredentials?: AuthCredentials;
|
|
53
57
|
authState?: AuthState;
|
|
58
|
+
orderbookRulesCache?: Map<string, Promise<OrderbookRules>>;
|
|
54
59
|
});
|
|
55
60
|
get depositSource(): DepositSource;
|
|
56
61
|
setDepositSource(source: DepositSource): void;
|
|
57
62
|
get signingStrategy(): SigningStrategy | undefined;
|
|
63
|
+
/**
|
|
64
|
+
* Cached authenticated identity shared by domain sub-clients.
|
|
65
|
+
*
|
|
66
|
+
* This is distinct from the HTTP cookie token and may be expired; fund-moving
|
|
67
|
+
* operations must re-check its lifetime and wallet before signing.
|
|
68
|
+
*/
|
|
69
|
+
get authCredentials(): AuthCredentials | undefined;
|
|
58
70
|
setSigningStrategy(strategy: SigningStrategy): void;
|
|
59
71
|
clearSigningStrategy(): void;
|
|
72
|
+
/** Return the client-wide trusted assertion that an external sponsor pays fees. */
|
|
73
|
+
get transactionSponsorshipEnabled(): boolean;
|
|
74
|
+
/** Replace the Transaction Sponsorship Capability for subsequent submissions. */
|
|
75
|
+
setTransactionSponsorshipEnabled(enabled: boolean): void;
|
|
60
76
|
orderNonce(): number | undefined;
|
|
61
77
|
setOrderNonce(nonce: number): void;
|
|
62
78
|
clearOrderNonce(): void;
|
|
@@ -73,7 +89,30 @@ export declare class LightconeClient implements ClientContext {
|
|
|
73
89
|
* `*WithCookies` variant.
|
|
74
90
|
*/
|
|
75
91
|
clearAuthToken(): Promise<void>;
|
|
92
|
+
/**
|
|
93
|
+
* Register the credential restorer consulted when a request fails with
|
|
94
|
+
* HTTP 401: it attempts to restore credentials (e.g. refresh the app's
|
|
95
|
+
* auth session so the auth cookie is valid again); on success the
|
|
96
|
+
* transport replays the request once IF it declared itself retry-safe
|
|
97
|
+
* (RetryPolicy.None mutations are never auto-replayed). See {@link CredentialRestorer}.
|
|
98
|
+
* Without a restorer, 401s propagate to callers unchanged.
|
|
99
|
+
*
|
|
100
|
+
* Common use: set once at app startup, alongside the signing strategy.
|
|
101
|
+
*/
|
|
102
|
+
setCredentialRestorer(restorer: CredentialRestorer): void;
|
|
103
|
+
/** Remove the credential restorer (e.g. in tests); 401s propagate again. */
|
|
104
|
+
clearCredentialRestorer(): void;
|
|
76
105
|
signAndSubmitTx(tx: Transaction): Promise<string>;
|
|
106
|
+
/**
|
|
107
|
+
* Sign and submit a transaction, then wait until it reaches `confirmed`
|
|
108
|
+
* commitment on-chain. Prefer this over {@link signAndSubmitTx} when a
|
|
109
|
+
* follow-up transaction depends on this one's state.
|
|
110
|
+
*/
|
|
111
|
+
signAndSubmitTxConfirmed(tx: Transaction): Promise<string>;
|
|
112
|
+
/** Sign, submit, confirm, and return the transaction's processing slot. */
|
|
113
|
+
signAndSubmitTxConfirmedWithSlot(tx: Transaction): Promise<ConfirmedTransaction>;
|
|
114
|
+
/** Confirm a fee-prepared transaction without replacing its message. */
|
|
115
|
+
signAndSubmitPreparedTxConfirmedWithSlot(tx: Transaction): Promise<ConfirmedTransaction>;
|
|
77
116
|
static builder(): LightconeClientBuilder;
|
|
78
117
|
markets(): Markets;
|
|
79
118
|
orderbooks(): Orderbooks;
|
|
@@ -102,6 +141,10 @@ export declare class LightconeClient implements ClientContext {
|
|
|
102
141
|
rpc(): Rpc;
|
|
103
142
|
wsConfig(): WsConfig;
|
|
104
143
|
ws(): WsClient;
|
|
144
|
+
/**
|
|
145
|
+
* Return a client whose Transaction Sponsorship Capability starts at this value.
|
|
146
|
+
* Later runtime changes remain local to each clone, matching other mutable settings.
|
|
147
|
+
*/
|
|
105
148
|
clone(): LightconeClient;
|
|
106
149
|
}
|
|
107
150
|
export declare class LightconeClientBuilder {
|
|
@@ -111,6 +154,7 @@ export declare class LightconeClientBuilder {
|
|
|
111
154
|
private programIdValue;
|
|
112
155
|
private depositSourceValue;
|
|
113
156
|
private signingStrategyValue?;
|
|
157
|
+
private transactionSponsorshipEnabledValue;
|
|
114
158
|
private primaryRpcUrlValue?;
|
|
115
159
|
private backupRpcUrlValue?;
|
|
116
160
|
/**
|
|
@@ -131,7 +175,9 @@ export declare class LightconeClientBuilder {
|
|
|
131
175
|
depositSource(source: DepositSource): LightconeClientBuilder;
|
|
132
176
|
nativeSigner(keypair: Keypair): LightconeClientBuilder;
|
|
133
177
|
externalSigner(signer: ExternalSigner): LightconeClientBuilder;
|
|
134
|
-
privyWalletId(walletId: string): LightconeClientBuilder;
|
|
178
|
+
privyWalletId(walletId: string, walletAddress?: string): LightconeClientBuilder;
|
|
179
|
+
/** Set the initial trusted Transaction Sponsorship Capability; defaults to false. */
|
|
180
|
+
transactionSponsorship(enabled: boolean): LightconeClientBuilder;
|
|
135
181
|
rpcUrl(url: string): LightconeClientBuilder;
|
|
136
182
|
/** Set a backup Solana RPC URL for automatic failover. */
|
|
137
183
|
backupRpcUrl(url: string): LightconeClientBuilder;
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9E,OAAO,EAAE,IAAI,EAAE,KAAK,eAAe,EAAE,MAAM,QAAQ,CAAC;AACpD,OAAO,KAAK,E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,CAAC,GAAG,EAAE,MAAM,GAAG,sBAAsB;IAKhD,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,sBAAsB;IAI1C,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,sBAAsB;IAK9C,IAAI,CAAC,WAAW,EAAE,eAAe,GAAG,sBAAsB;IAI1D,QAAQ,CAAC,WAAW,EAAE,eAAe,GAAG,sBAAsB;IAK9D,SAAS,CAAC,EAAE,EAAE,SAAS,GAAG,sBAAsB;IAKhD,aAAa,CAAC,MAAM,EAAE,aAAa,GAAG,sBAAsB;IAK5D,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,sBAAsB;IAKtD,cAAc,CAAC,MAAM,EAAE,cAAc,GAAG,sBAAsB;IAK9D,aAAa,CACX,QAAQ,EAAE,MAAM,EAChB,aAAa,CAAC,EAAE,MAAM,GACrB,sBAAsB;IAKzB,qFAAqF;IACrF,sBAAsB,CAAC,OAAO,EAAE,OAAO,GAAG,sBAAsB;IAKhE,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,sBAAsB;IAK3C,0DAA0D;IAC1D,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,sBAAsB;IAKjD,KAAK,IAAI,eAAe;CAwBzB"}
|
package/dist/client.js
CHANGED
|
@@ -43,9 +43,11 @@ class LightconeClient {
|
|
|
43
43
|
rpcFailoverState;
|
|
44
44
|
depositSourceValue;
|
|
45
45
|
signingStrategyValue;
|
|
46
|
+
transactionSponsorshipEnabledValue;
|
|
46
47
|
orderNonceValue;
|
|
47
48
|
wsConfigValue;
|
|
48
49
|
authStateStore;
|
|
50
|
+
orderbookRulesCache;
|
|
49
51
|
/** @deprecated Use primaryConnection — kept for ClientContext compat. */
|
|
50
52
|
get connection() {
|
|
51
53
|
return this.primaryConnection;
|
|
@@ -59,11 +61,14 @@ class LightconeClient {
|
|
|
59
61
|
params.rpcFailoverState ?? new rpcFailover_1.RpcFailoverState();
|
|
60
62
|
this.depositSourceValue = params.depositSource ?? shared_1.DepositSource.Global;
|
|
61
63
|
this.signingStrategyValue = params.signingStrategy;
|
|
64
|
+
this.transactionSponsorshipEnabledValue =
|
|
65
|
+
params.transactionSponsorshipEnabled ?? false;
|
|
62
66
|
this.orderNonceValue = params.orderNonce;
|
|
63
67
|
this.wsConfigValue = params.wsConfig;
|
|
64
68
|
this.authStateStore =
|
|
65
69
|
params.authState ??
|
|
66
70
|
new AuthState(params.authCredentials);
|
|
71
|
+
this.orderbookRulesCache = params.orderbookRulesCache ?? new Map();
|
|
67
72
|
}
|
|
68
73
|
// ── Deposit source ──────────────────────────────────────────────────
|
|
69
74
|
get depositSource() {
|
|
@@ -76,12 +81,29 @@ class LightconeClient {
|
|
|
76
81
|
get signingStrategy() {
|
|
77
82
|
return this.signingStrategyValue;
|
|
78
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* Cached authenticated identity shared by domain sub-clients.
|
|
86
|
+
*
|
|
87
|
+
* This is distinct from the HTTP cookie token and may be expired; fund-moving
|
|
88
|
+
* operations must re-check its lifetime and wallet before signing.
|
|
89
|
+
*/
|
|
90
|
+
get authCredentials() {
|
|
91
|
+
return this.authStateStore.getCredentials();
|
|
92
|
+
}
|
|
79
93
|
setSigningStrategy(strategy) {
|
|
80
94
|
this.signingStrategyValue = strategy;
|
|
81
95
|
}
|
|
82
96
|
clearSigningStrategy() {
|
|
83
97
|
this.signingStrategyValue = undefined;
|
|
84
98
|
}
|
|
99
|
+
/** Return the client-wide trusted assertion that an external sponsor pays fees. */
|
|
100
|
+
get transactionSponsorshipEnabled() {
|
|
101
|
+
return this.transactionSponsorshipEnabledValue;
|
|
102
|
+
}
|
|
103
|
+
/** Replace the Transaction Sponsorship Capability for subsequent submissions. */
|
|
104
|
+
setTransactionSponsorshipEnabled(enabled) {
|
|
105
|
+
this.transactionSponsorshipEnabledValue = enabled;
|
|
106
|
+
}
|
|
85
107
|
// ── Nonce cache ──────────────────────────────────────────────────────
|
|
86
108
|
orderNonce() {
|
|
87
109
|
return this.orderNonceValue;
|
|
@@ -110,10 +132,43 @@ class LightconeClient {
|
|
|
110
132
|
async clearAuthToken() {
|
|
111
133
|
await this.http.clearAuthToken();
|
|
112
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* Register the credential restorer consulted when a request fails with
|
|
137
|
+
* HTTP 401: it attempts to restore credentials (e.g. refresh the app's
|
|
138
|
+
* auth session so the auth cookie is valid again); on success the
|
|
139
|
+
* transport replays the request once IF it declared itself retry-safe
|
|
140
|
+
* (RetryPolicy.None mutations are never auto-replayed). See {@link CredentialRestorer}.
|
|
141
|
+
* Without a restorer, 401s propagate to callers unchanged.
|
|
142
|
+
*
|
|
143
|
+
* Common use: set once at app startup, alongside the signing strategy.
|
|
144
|
+
*/
|
|
145
|
+
setCredentialRestorer(restorer) {
|
|
146
|
+
this.http.setCredentialRestorer(restorer);
|
|
147
|
+
}
|
|
148
|
+
/** Remove the credential restorer (e.g. in tests); 401s propagate again. */
|
|
149
|
+
clearCredentialRestorer() {
|
|
150
|
+
this.http.clearCredentialRestorer();
|
|
151
|
+
}
|
|
113
152
|
// ── Transaction signing + submission ────────────────────────────────
|
|
114
153
|
async signAndSubmitTx(tx) {
|
|
115
154
|
return (0, context_1.signAndSubmitTx)(this, tx);
|
|
116
155
|
}
|
|
156
|
+
/**
|
|
157
|
+
* Sign and submit a transaction, then wait until it reaches `confirmed`
|
|
158
|
+
* commitment on-chain. Prefer this over {@link signAndSubmitTx} when a
|
|
159
|
+
* follow-up transaction depends on this one's state.
|
|
160
|
+
*/
|
|
161
|
+
async signAndSubmitTxConfirmed(tx) {
|
|
162
|
+
return (0, context_1.signAndSubmitTxConfirmed)(this, tx);
|
|
163
|
+
}
|
|
164
|
+
/** Sign, submit, confirm, and return the transaction's processing slot. */
|
|
165
|
+
async signAndSubmitTxConfirmedWithSlot(tx) {
|
|
166
|
+
return (0, context_1.signAndSubmitTxConfirmedWithSlot)(this, tx);
|
|
167
|
+
}
|
|
168
|
+
/** Confirm a fee-prepared transaction without replacing its message. */
|
|
169
|
+
async signAndSubmitPreparedTxConfirmedWithSlot(tx) {
|
|
170
|
+
return (0, context_1.signAndSubmitPreparedTxConfirmedWithSlot)(this, tx);
|
|
171
|
+
}
|
|
117
172
|
static builder() {
|
|
118
173
|
return new LightconeClientBuilder();
|
|
119
174
|
}
|
|
@@ -179,6 +234,10 @@ class LightconeClient {
|
|
|
179
234
|
ws() {
|
|
180
235
|
return new ws_1.WsClient(this.wsConfigValue, this.http.authTokenRef());
|
|
181
236
|
}
|
|
237
|
+
/**
|
|
238
|
+
* Return a client whose Transaction Sponsorship Capability starts at this value.
|
|
239
|
+
* Later runtime changes remain local to each clone, matching other mutable settings.
|
|
240
|
+
*/
|
|
182
241
|
clone() {
|
|
183
242
|
return new LightconeClient({
|
|
184
243
|
http: this.http,
|
|
@@ -193,8 +252,10 @@ class LightconeClient {
|
|
|
193
252
|
rpcFailoverState: this.rpcFailoverState,
|
|
194
253
|
depositSource: this.depositSourceValue,
|
|
195
254
|
signingStrategy: this.signingStrategyValue,
|
|
255
|
+
transactionSponsorshipEnabled: this.transactionSponsorshipEnabledValue,
|
|
196
256
|
orderNonce: this.orderNonceValue,
|
|
197
257
|
authState: this.authStateStore,
|
|
258
|
+
orderbookRulesCache: this.orderbookRulesCache,
|
|
198
259
|
});
|
|
199
260
|
}
|
|
200
261
|
}
|
|
@@ -206,6 +267,7 @@ class LightconeClientBuilder {
|
|
|
206
267
|
programIdValue = (0, env_1.programId)(env_1.LightconeEnv.Prod);
|
|
207
268
|
depositSourceValue = shared_1.DepositSource.Global;
|
|
208
269
|
signingStrategyValue;
|
|
270
|
+
transactionSponsorshipEnabledValue = false;
|
|
209
271
|
primaryRpcUrlValue = (0, env_1.rpcUrl)(env_1.LightconeEnv.Prod);
|
|
210
272
|
backupRpcUrlValue;
|
|
211
273
|
/**
|
|
@@ -259,8 +321,13 @@ class LightconeClientBuilder {
|
|
|
259
321
|
this.signingStrategyValue = { type: "walletAdapter", signer };
|
|
260
322
|
return this;
|
|
261
323
|
}
|
|
262
|
-
privyWalletId(walletId) {
|
|
263
|
-
this.signingStrategyValue = { type: "privy", walletId };
|
|
324
|
+
privyWalletId(walletId, walletAddress) {
|
|
325
|
+
this.signingStrategyValue = { type: "privy", walletId, walletAddress };
|
|
326
|
+
return this;
|
|
327
|
+
}
|
|
328
|
+
/** Set the initial trusted Transaction Sponsorship Capability; defaults to false. */
|
|
329
|
+
transactionSponsorship(enabled) {
|
|
330
|
+
this.transactionSponsorshipEnabledValue = enabled;
|
|
264
331
|
return this;
|
|
265
332
|
}
|
|
266
333
|
rpcUrl(url) {
|
|
@@ -286,6 +353,7 @@ class LightconeClientBuilder {
|
|
|
286
353
|
programId: this.programIdValue,
|
|
287
354
|
depositSource: this.depositSourceValue,
|
|
288
355
|
signingStrategy: this.signingStrategyValue,
|
|
356
|
+
transactionSponsorshipEnabled: this.transactionSponsorshipEnabledValue,
|
|
289
357
|
primaryConnection: this.primaryRpcUrlValue
|
|
290
358
|
? new web3_js_1.Connection(this.primaryRpcUrlValue, { commitment: "confirmed" })
|
|
291
359
|
: undefined,
|