@lightconexyz/lightcone-sdk 0.2.3 → 0.2.41
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 +30 -37
- package/dist/auth/client.d.ts.map +1 -1
- package/dist/auth/client.js +3 -10
- package/dist/auth/client.js.map +1 -1
- package/dist/auth/index.d.ts +3 -1
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/index.js.map +1 -1
- package/dist/client.d.ts +14 -15
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +33 -31
- package/dist/client.js.map +1 -1
- package/dist/context.d.ts +9 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +10 -0
- package/dist/context.js.map +1 -0
- package/dist/domain/admin/client.d.ts +27 -5
- package/dist/domain/admin/client.d.ts.map +1 -1
- package/dist/domain/admin/client.js +89 -0
- package/dist/domain/admin/client.js.map +1 -1
- package/dist/domain/index.d.ts +0 -1
- package/dist/domain/index.d.ts.map +1 -1
- package/dist/domain/index.js +1 -2
- package/dist/domain/index.js.map +1 -1
- package/dist/domain/market/client.d.ts +13 -5
- package/dist/domain/market/client.d.ts.map +1 -1
- package/dist/domain/market/client.js +86 -0
- package/dist/domain/market/client.js.map +1 -1
- package/dist/domain/order/client.d.ts +23 -5
- package/dist/domain/order/client.d.ts.map +1 -1
- package/dist/domain/order/client.js +99 -0
- package/dist/domain/order/client.js.map +1 -1
- package/dist/domain/order/index.d.ts +8 -2
- package/dist/domain/order/index.d.ts.map +1 -1
- package/dist/domain/order/index.js +23 -0
- package/dist/domain/order/index.js.map +1 -1
- package/dist/domain/orderbook/client.d.ts +6 -14
- package/dist/domain/orderbook/client.d.ts.map +1 -1
- package/dist/domain/orderbook/client.js +16 -11
- package/dist/domain/orderbook/client.js.map +1 -1
- package/dist/domain/orderbook/index.d.ts +7 -0
- package/dist/domain/orderbook/index.d.ts.map +1 -1
- package/dist/domain/orderbook/index.js +17 -0
- package/dist/domain/orderbook/index.js.map +1 -1
- package/dist/domain/orderbook/state.d.ts +2 -0
- package/dist/domain/orderbook/state.d.ts.map +1 -1
- package/dist/domain/orderbook/state.js +25 -2
- package/dist/domain/orderbook/state.js.map +1 -1
- package/dist/domain/position/client.d.ts +19 -5
- package/dist/domain/position/client.d.ts.map +1 -1
- package/dist/domain/position/client.js +71 -0
- package/dist/domain/position/client.js.map +1 -1
- package/dist/domain/position/index.d.ts +4 -1
- package/dist/domain/position/index.d.ts.map +1 -1
- package/dist/domain/position/index.js +20 -0
- package/dist/domain/position/index.js.map +1 -1
- package/dist/domain/position/wire.d.ts +6 -0
- package/dist/domain/position/wire.d.ts.map +1 -1
- package/dist/domain/position/wire.js.map +1 -1
- package/dist/domain/price_history/client.d.ts +14 -1
- package/dist/domain/price_history/client.d.ts.map +1 -1
- package/dist/domain/price_history/client.js +53 -0
- package/dist/domain/price_history/client.js.map +1 -1
- package/dist/domain/price_history/index.d.ts +4 -0
- package/dist/domain/price_history/index.d.ts.map +1 -1
- package/dist/domain/price_history/index.js.map +1 -1
- package/dist/domain/price_history/state.d.ts +16 -0
- package/dist/domain/price_history/state.d.ts.map +1 -1
- package/dist/domain/price_history/state.js +42 -1
- package/dist/domain/price_history/state.js.map +1 -1
- package/dist/domain/price_history/wire.d.ts +34 -0
- package/dist/domain/price_history/wire.d.ts.map +1 -1
- package/dist/domain/price_history/wire.js.map +1 -1
- package/dist/http/client.d.ts +0 -1
- package/dist/http/client.d.ts.map +1 -1
- package/dist/http/client.js +29 -39
- package/dist/http/client.js.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/prelude.d.ts +5 -6
- package/dist/prelude.d.ts.map +1 -1
- package/dist/prelude.js +4 -5
- package/dist/prelude.js.map +1 -1
- package/dist/privy/client.d.ts +1 -0
- package/dist/privy/client.d.ts.map +1 -1
- package/dist/privy/client.js +10 -0
- package/dist/privy/client.js.map +1 -1
- package/dist/privy/index.d.ts +1 -0
- package/dist/privy/index.d.ts.map +1 -1
- package/dist/privy/index.js +4 -0
- package/dist/privy/index.js.map +1 -1
- package/dist/program/accounts.d.ts +2 -1
- package/dist/program/accounts.d.ts.map +1 -1
- package/dist/program/accounts.js +2 -1
- package/dist/program/accounts.js.map +1 -1
- package/dist/program/builder.d.ts +3 -0
- package/dist/program/builder.d.ts.map +1 -1
- package/dist/program/builder.js +8 -0
- package/dist/program/builder.js.map +1 -1
- package/dist/program/constants.d.ts +3 -2
- package/dist/program/constants.d.ts.map +1 -1
- package/dist/program/constants.js +3 -2
- package/dist/program/constants.js.map +1 -1
- package/dist/program/envelope.d.ts +19 -9
- package/dist/program/envelope.d.ts.map +1 -1
- package/dist/program/envelope.js +54 -20
- package/dist/program/envelope.js.map +1 -1
- package/dist/program/index.d.ts +3 -4
- package/dist/program/index.d.ts.map +1 -1
- package/dist/program/index.js +34 -6
- package/dist/program/index.js.map +1 -1
- package/dist/program/instructions.d.ts +40 -3
- package/dist/program/instructions.d.ts.map +1 -1
- package/dist/program/instructions.js +158 -3
- package/dist/program/instructions.js.map +1 -1
- package/dist/program/orders.d.ts +36 -18
- package/dist/program/orders.d.ts.map +1 -1
- package/dist/program/orders.js +97 -20
- package/dist/program/orders.js.map +1 -1
- package/dist/program/types.d.ts +14 -2
- package/dist/program/types.d.ts.map +1 -1
- package/dist/program/types.js.map +1 -1
- package/dist/rpc.d.ts +19 -0
- package/dist/rpc.d.ts.map +1 -0
- package/dist/rpc.js +51 -0
- package/dist/rpc.js.map +1 -0
- package/dist/shared/fmt/decimal.d.ts +1 -1
- package/dist/shared/fmt/decimal.d.ts.map +1 -1
- package/dist/shared/fmt/decimal.js +2 -2
- package/dist/shared/fmt/decimal.js.map +1 -1
- package/dist/shared/index.d.ts +1 -1
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/index.js +2 -1
- package/dist/shared/index.js.map +1 -1
- package/dist/shared/scaling.d.ts.map +1 -1
- package/dist/shared/scaling.js +7 -3
- package/dist/shared/scaling.js.map +1 -1
- package/dist/shared/types.d.ts +2 -0
- package/dist/shared/types.d.ts.map +1 -1
- package/dist/shared/types.js +9 -1
- package/dist/shared/types.js.map +1 -1
- package/dist/ws/client.browser.d.ts +2 -0
- package/dist/ws/client.browser.d.ts.map +1 -1
- package/dist/ws/client.browser.js +43 -6
- package/dist/ws/client.browser.js.map +1 -1
- package/dist/ws/client.node.d.ts +2 -0
- package/dist/ws/client.node.d.ts.map +1 -1
- package/dist/ws/client.node.js +43 -6
- package/dist/ws/client.node.js.map +1 -1
- package/dist/ws/index.d.ts +1 -2
- package/dist/ws/index.d.ts.map +1 -1
- package/dist/ws/index.js.map +1 -1
- package/dist/ws/types.d.ts +2 -0
- package/dist/ws/types.d.ts.map +1 -1
- package/dist/ws/types.js.map +1 -1
- package/package.json +1 -1
- package/dist/domain/deposit_price/client.d.ts +0 -21
- package/dist/domain/deposit_price/client.d.ts.map +0 -1
- package/dist/domain/deposit_price/client.js +0 -68
- package/dist/domain/deposit_price/client.js.map +0 -1
- package/dist/domain/deposit_price/index.d.ts +0 -9
- package/dist/domain/deposit_price/index.d.ts.map +0 -1
- package/dist/domain/deposit_price/index.js +0 -20
- package/dist/domain/deposit_price/index.js.map +0 -1
- package/dist/domain/deposit_price/state.d.ts +0 -17
- package/dist/domain/deposit_price/state.d.ts.map +0 -1
- package/dist/domain/deposit_price/state.js +0 -45
- package/dist/domain/deposit_price/state.js.map +0 -1
- package/dist/domain/deposit_price/wire.d.ts +0 -36
- package/dist/domain/deposit_price/wire.d.ts.map +0 -1
- package/dist/domain/deposit_price/wire.js +0 -3
- package/dist/domain/deposit_price/wire.js.map +0 -1
- package/dist/program/client.d.ts +0 -96
- package/dist/program/client.d.ts.map +0 -1
- package/dist/program/client.js +0 -372
- package/dist/program/client.js.map +0 -1
package/README.md
CHANGED
|
@@ -31,12 +31,12 @@ import {
|
|
|
31
31
|
LightconeClient,
|
|
32
32
|
LimitOrderEnvelope,
|
|
33
33
|
auth,
|
|
34
|
-
program,
|
|
35
34
|
} from "@lightconexyz/lightcone-sdk";
|
|
36
35
|
|
|
37
36
|
async function main() {
|
|
38
|
-
const client = LightconeClient.builder()
|
|
39
|
-
|
|
37
|
+
const client = LightconeClient.builder()
|
|
38
|
+
.rpcUrl("https://api.devnet.solana.com")
|
|
39
|
+
.build();
|
|
40
40
|
const keypair = Keypair.generate();
|
|
41
41
|
|
|
42
42
|
// 1. Authenticate
|
|
@@ -51,21 +51,13 @@ async function main() {
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
// 2. Find a market
|
|
54
|
-
const
|
|
54
|
+
const { markets } = await client.markets().get();
|
|
55
|
+
const market = markets[0];
|
|
55
56
|
const orderbook = market.orderbookPairs[0];
|
|
56
57
|
|
|
57
|
-
// 3.
|
|
58
|
-
|
|
59
|
-
const
|
|
60
|
-
orderbookId: raw.orderbook_id,
|
|
61
|
-
baseDecimals: raw.base_decimals,
|
|
62
|
-
quoteDecimals: raw.quote_decimals,
|
|
63
|
-
priceDecimals: raw.price_decimals,
|
|
64
|
-
tickSize: BigInt(Math.max(orderbook.tickSize, 0)),
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
// 4. Build, sign, and submit a limit order
|
|
68
|
-
const nonce = await rpc.getCurrentNonce(keypair.publicKey);
|
|
58
|
+
// 3. Build, sign, and submit a limit order
|
|
59
|
+
// Decimals are derived automatically from the orderbook's token metadata.
|
|
60
|
+
const nonce = await client.orders().currentNonce(keypair.publicKey);
|
|
69
61
|
const request = LimitOrderEnvelope.new()
|
|
70
62
|
.maker(keypair.publicKey)
|
|
71
63
|
.market(new PublicKey(market.pubkey))
|
|
@@ -75,8 +67,7 @@ async function main() {
|
|
|
75
67
|
.price("0.55")
|
|
76
68
|
.size("100")
|
|
77
69
|
.nonce(nonce)
|
|
78
|
-
.
|
|
79
|
-
.sign(keypair, orderbook.orderbookId);
|
|
70
|
+
.sign(keypair, orderbook);
|
|
80
71
|
|
|
81
72
|
const response = await client.orders().submit(request);
|
|
82
73
|
console.log("Order submitted:", response);
|
|
@@ -96,7 +87,7 @@ main().catch(console.error);
|
|
|
96
87
|
import * as fs from "fs";
|
|
97
88
|
import * as path from "path";
|
|
98
89
|
import { Keypair, PublicKey } from "@solana/web3.js";
|
|
99
|
-
import { LightconeClient
|
|
90
|
+
import { LightconeClient } from "@lightconexyz/lightcone-sdk";
|
|
100
91
|
|
|
101
92
|
function readKeypairFile(filePath: string): Keypair {
|
|
102
93
|
const resolved = filePath.startsWith("~")
|
|
@@ -106,15 +97,17 @@ function readKeypairFile(filePath: string): Keypair {
|
|
|
106
97
|
return Keypair.fromSecretKey(Uint8Array.from(secret));
|
|
107
98
|
}
|
|
108
99
|
|
|
109
|
-
const client = LightconeClient.builder()
|
|
110
|
-
|
|
100
|
+
const client = LightconeClient.builder()
|
|
101
|
+
.rpcUrl("https://api.devnet.solana.com")
|
|
102
|
+
.build();
|
|
111
103
|
const keypair = readKeypairFile("~/.config/solana/id.json");
|
|
112
104
|
```
|
|
113
105
|
|
|
114
106
|
### Step 1: Find a Market
|
|
115
107
|
|
|
116
108
|
```typescript
|
|
117
|
-
const
|
|
109
|
+
const { markets } = await client.markets().get();
|
|
110
|
+
const market = markets[0];
|
|
118
111
|
const orderbook =
|
|
119
112
|
market.orderbookPairs.find((pair) => pair.active) ?? market.orderbookPairs[0];
|
|
120
113
|
```
|
|
@@ -122,10 +115,12 @@ const orderbook =
|
|
|
122
115
|
### Step 2: Deposit Collateral
|
|
123
116
|
|
|
124
117
|
```typescript
|
|
118
|
+
import { Transaction } from "@solana/web3.js";
|
|
119
|
+
|
|
125
120
|
const marketPubkey = new PublicKey(market.pubkey);
|
|
126
121
|
const depositMint = new PublicKey(market.depositAssets[0].pubkey);
|
|
127
122
|
const numOutcomes = market.outcomes.length;
|
|
128
|
-
const
|
|
123
|
+
const mintIx = client.markets().mintCompleteSetIx(
|
|
129
124
|
{
|
|
130
125
|
user: keypair.publicKey,
|
|
131
126
|
market: marketPubkey,
|
|
@@ -134,7 +129,10 @@ const mintResult = await rpc.mintCompleteSet(
|
|
|
134
129
|
},
|
|
135
130
|
numOutcomes
|
|
136
131
|
);
|
|
137
|
-
|
|
132
|
+
const tx = new Transaction().add(mintIx);
|
|
133
|
+
tx.feePayer = keypair.publicKey;
|
|
134
|
+
tx.recentBlockhash = (await client.rpc().getLatestBlockhash()).blockhash;
|
|
135
|
+
tx.sign(keypair);
|
|
138
136
|
```
|
|
139
137
|
|
|
140
138
|
### Step 3: Place an Order
|
|
@@ -142,14 +140,6 @@ mintResult.transaction.sign(keypair);
|
|
|
142
140
|
```typescript
|
|
143
141
|
import { LimitOrderEnvelope } from "@lightconexyz/lightcone-sdk";
|
|
144
142
|
|
|
145
|
-
const decimals = await client.orderbooks().decimals(orderbook.orderbookId);
|
|
146
|
-
const scales = {
|
|
147
|
-
orderbookId: decimals.orderbook_id,
|
|
148
|
-
baseDecimals: decimals.base_decimals,
|
|
149
|
-
quoteDecimals: decimals.quote_decimals,
|
|
150
|
-
priceDecimals: decimals.price_decimals,
|
|
151
|
-
tickSize: BigInt(Math.max(orderbook.tickSize, 0)),
|
|
152
|
-
};
|
|
153
143
|
const request = LimitOrderEnvelope.new()
|
|
154
144
|
.maker(keypair.publicKey)
|
|
155
145
|
.market(new PublicKey(market.pubkey))
|
|
@@ -158,9 +148,8 @@ const request = LimitOrderEnvelope.new()
|
|
|
158
148
|
.bid()
|
|
159
149
|
.price("0.55")
|
|
160
150
|
.size("1")
|
|
161
|
-
.nonce(await
|
|
162
|
-
.
|
|
163
|
-
.sign(keypair, orderbook.orderbookId);
|
|
151
|
+
.nonce(await client.orders().currentNonce(keypair.publicKey))
|
|
152
|
+
.sign(keypair, orderbook);
|
|
164
153
|
const order = await client.orders().submit(request);
|
|
165
154
|
```
|
|
166
155
|
|
|
@@ -197,7 +186,7 @@ await client.orders().cancel({
|
|
|
197
186
|
### Step 6: Exit a Position
|
|
198
187
|
|
|
199
188
|
```typescript
|
|
200
|
-
const
|
|
189
|
+
const mergeIx = client.markets().mergeCompleteSetIx(
|
|
201
190
|
{
|
|
202
191
|
user: keypair.publicKey,
|
|
203
192
|
market: new PublicKey(market.pubkey),
|
|
@@ -206,7 +195,10 @@ const mergeResult = await rpc.mergeCompleteSet(
|
|
|
206
195
|
},
|
|
207
196
|
numOutcomes
|
|
208
197
|
);
|
|
209
|
-
|
|
198
|
+
const mergeTx = new Transaction().add(mergeIx);
|
|
199
|
+
mergeTx.feePayer = keypair.publicKey;
|
|
200
|
+
mergeTx.recentBlockhash = (await client.rpc().getLatestBlockhash()).blockhash;
|
|
201
|
+
mergeTx.sign(keypair);
|
|
210
202
|
```
|
|
211
203
|
|
|
212
204
|
## Authentication
|
|
@@ -250,6 +242,7 @@ All examples are runnable with `npx tsx examples/<name>.ts`. Set environment var
|
|
|
250
242
|
|---------|-------------|
|
|
251
243
|
| [`read_onchain`](examples/read_onchain.ts) | Read exchange state, market state, user nonce, and PDA derivations via RPC |
|
|
252
244
|
| [`onchain_transactions`](examples/onchain_transactions.ts) | Build, sign, and submit mint/merge complete set and increment nonce on-chain |
|
|
245
|
+
| [`global_deposit`](examples/global_deposit.ts) | Init position tokens, deposit to global pool, move capital into a market, and extend an existing ALT |
|
|
253
246
|
|
|
254
247
|
### WebSocket Streaming
|
|
255
248
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/auth/client.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,KAAK,aAAa,EAAE,MAAM,SAAS,CAAC;AAE1D,OAAO,KAAK,EAAE,eAAe,EAA0D,IAAI,EAAE,MAAM,SAAS,CAAC;AAE7G,UAAU,SAAS;IACjB,cAAc,IAAI,eAAe,GAAG,SAAS,CAAC;IAC9C,cAAc,CAAC,WAAW,EAAE,eAAe,GAAG,SAAS,GAAG,IAAI,CAAC;IAC/D,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B;AAED,UAAU,aAAa;I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OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,YAAY,CAAC,EAAE,MAAM,GACpB,OAAO,CAAC,IAAI,CAAC;IAahB,WAAW,IAAI,eAAe,GAAG,SAAS;IAI1C,eAAe,IAAI,OAAO;CAO3B"}
|
package/dist/auth/client.js
CHANGED
|
@@ -22,16 +22,7 @@ class Auth {
|
|
|
22
22
|
pubkey_bytes: Array.from(pubkeyBytes),
|
|
23
23
|
use_embedded_wallet: useEmbeddedWallet,
|
|
24
24
|
};
|
|
25
|
-
|
|
26
|
-
try {
|
|
27
|
-
response = await this.client.http.post(url, body, http_1.RetryPolicy.None);
|
|
28
|
-
}
|
|
29
|
-
catch (error) {
|
|
30
|
-
throw error_1.SdkError.from(new error_1.AuthError("LoginFailed", error instanceof Error ? error.message : String(error)));
|
|
31
|
-
}
|
|
32
|
-
if (response.token) {
|
|
33
|
-
await this.client.http.setAuthToken(response.token);
|
|
34
|
-
}
|
|
25
|
+
const response = await this.client.http.post(url, body, http_1.RetryPolicy.None);
|
|
35
26
|
const credentials = {
|
|
36
27
|
user_id: response.user_id,
|
|
37
28
|
wallet_address: (0, shared_1.asPubkeyStr)(response.wallet_address),
|
|
@@ -47,6 +38,7 @@ class Auth {
|
|
|
47
38
|
x_username: response.x_username,
|
|
48
39
|
x_user_id: response.x_user_id,
|
|
49
40
|
x_display_name: response.x_display_name,
|
|
41
|
+
google_email: response.google_email,
|
|
50
42
|
};
|
|
51
43
|
}
|
|
52
44
|
async checkSession() {
|
|
@@ -73,6 +65,7 @@ class Auth {
|
|
|
73
65
|
x_username: response.x_username,
|
|
74
66
|
x_user_id: response.x_user_id,
|
|
75
67
|
x_display_name: response.x_display_name,
|
|
68
|
+
google_email: response.google_email,
|
|
76
69
|
};
|
|
77
70
|
}
|
|
78
71
|
async logout() {
|
package/dist/auth/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/auth/client.ts"],"names":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YAClB,UAAU,EAAE,SAAS;YACrB,cAAc,EAAE,YAAY;SAC7B,EACD,kBAAW,CAAC,IAAI,CACjB,CAAC;IACJ,CAAC;IAED,WAAW;QACT,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,EAAE,CAAC;IAChD,CAAC;IAED,eAAe;QACb,MAAM,WAAW,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;QACvC,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,OAAO,KAAK,CAAC;QACf,CAAC;QACD,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,WAAW,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;IACvD,CAAC;CACF;AA7HD,oBA6HC;AAED,SAAS,WAAW,CAAC,SAAiB;IACpC,IAAI,SAAS,GAAG,iBAAiB,EAAE,CAAC;QAClC,OAAO,IAAI,IAAI,CAAC,SAAS,CAAC,CAAC;IAC7B,CAAC;IACD,OAAO,IAAI,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC;AACpC,CAAC","sourcesContent":["import { SdkError } from \"../error\";\nimport { RetryPolicy, type LightconeHttp } from \"../http\";\nimport { asPubkeyStr } from \"../shared\";\nimport type { AuthCredentials, LoginRequest, LoginResponse, MeResponse, NonceResponse, User } from \"./index\";\n\ninterface AuthState {\n getCredentials(): AuthCredentials | undefined;\n setCredentials(credentials: AuthCredentials | undefined): void;\n clearCaches(): Promise<void>;\n}\n\ninterface ClientContext {\n http: LightconeHttp;\n authState: AuthState;\n}\n\nexport class Auth {\n constructor(private readonly client: ClientContext) {}\n\n async getNonce(): Promise<string> {\n const url = `${this.client.http.baseUrl()}/api/auth/nonce`;\n const response = await this.client.http.get<NonceResponse>(url, RetryPolicy.None);\n return response.nonce;\n }\n\n async loginWithMessage(\n message: string,\n signatureBs58: string,\n pubkeyBytes: Uint8Array,\n useEmbeddedWallet?: boolean\n ): Promise<User> {\n const url = `${this.client.http.baseUrl()}/api/auth/login_or_register_with_message`;\n const body: LoginRequest = {\n message,\n signature_bs58: signatureBs58,\n pubkey_bytes: Array.from(pubkeyBytes),\n use_embedded_wallet: useEmbeddedWallet,\n };\n\n const response = await this.client.http.post<LoginResponse, LoginRequest>(\n url,\n body,\n RetryPolicy.None\n );\n\n const credentials: AuthCredentials = {\n user_id: response.user_id,\n wallet_address: asPubkeyStr(response.wallet_address),\n expires_at: parseExpiry(response.expires_at),\n };\n this.client.authState.setCredentials(credentials);\n\n return {\n id: response.user_id,\n wallet_address: response.wallet_address,\n linked_account: response.linked_account,\n privy_id: response.privy_id,\n embedded_wallet: response.embedded_wallet,\n x_username: response.x_username,\n x_user_id: response.x_user_id,\n x_display_name: response.x_display_name,\n google_email: response.google_email,\n };\n }\n\n async checkSession(): Promise<User> {\n const url = `${this.client.http.baseUrl()}/api/auth/me`;\n\n let response: MeResponse;\n try {\n response = await this.client.http.get<MeResponse>(url, RetryPolicy.Idempotent);\n } catch (error) {\n this.client.authState.setCredentials(undefined);\n throw SdkError.from(error);\n }\n\n this.client.authState.setCredentials({\n user_id: response.user_id,\n wallet_address: asPubkeyStr(response.wallet_address),\n expires_at: parseExpiry(response.expires_at),\n });\n\n return {\n id: response.user_id,\n wallet_address: response.wallet_address,\n linked_account: response.linked_account,\n privy_id: response.privy_id,\n embedded_wallet: response.embedded_wallet,\n x_username: response.x_username,\n x_user_id: response.x_user_id,\n x_display_name: response.x_display_name,\n google_email: response.google_email,\n };\n }\n\n async logout(): Promise<void> {\n const url = `${this.client.http.baseUrl()}/api/auth/logout`;\n try {\n await this.client.http.post<{ success: boolean }, Record<string, never>>(url, {}, RetryPolicy.None);\n } catch {\n // Backend cookie clear can fail in local/dev setups; still clear local state.\n }\n\n await this.client.http.clearAuthToken();\n this.client.authState.setCredentials(undefined);\n await this.client.authState.clearCaches();\n }\n\n async disconnectX(): Promise<void> {\n const url = `${this.client.http.baseUrl()}/api/auth/disconnect_x`;\n await this.client.http.post<{ success: boolean }, Record<string, never>>(url, {}, RetryPolicy.None);\n }\n\n async connectX(\n xUserId: string,\n xUsername: string,\n xDisplayName?: string\n ): Promise<void> {\n const url = `${this.client.http.baseUrl()}/api/auth/connect_x`;\n await this.client.http.post<{ success: boolean }, { x_user_id: string; x_username: string; x_display_name?: string }>(\n url,\n {\n x_user_id: xUserId,\n x_username: xUsername,\n x_display_name: xDisplayName,\n },\n RetryPolicy.None\n );\n }\n\n credentials(): AuthCredentials | undefined {\n return this.client.authState.getCredentials();\n }\n\n isAuthenticated(): boolean {\n const credentials = this.credentials();\n if (!credentials) {\n return false;\n }\n return Date.now() < credentials.expires_at.getTime();\n }\n}\n\nfunction parseExpiry(timestamp: number): Date {\n if (timestamp > 1_000_000_000_000) {\n return new Date(timestamp);\n }\n return new Date(timestamp * 1000);\n}\n"]}
|
package/dist/auth/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export interface User {
|
|
|
10
10
|
x_username?: string;
|
|
11
11
|
x_user_id?: string;
|
|
12
12
|
x_display_name?: string;
|
|
13
|
+
google_email?: string;
|
|
13
14
|
}
|
|
14
15
|
export interface LinkedAccount {
|
|
15
16
|
id: string;
|
|
@@ -45,7 +46,6 @@ export interface LoginRequest {
|
|
|
45
46
|
use_embedded_wallet?: boolean;
|
|
46
47
|
}
|
|
47
48
|
export interface LoginResponse {
|
|
48
|
-
token: string;
|
|
49
49
|
user_id: string;
|
|
50
50
|
wallet_address: string;
|
|
51
51
|
expires_at: number;
|
|
@@ -55,6 +55,7 @@ export interface LoginResponse {
|
|
|
55
55
|
x_username?: string;
|
|
56
56
|
x_user_id?: string;
|
|
57
57
|
x_display_name?: string;
|
|
58
|
+
google_email?: string;
|
|
58
59
|
}
|
|
59
60
|
export interface MeResponse {
|
|
60
61
|
user_id: string;
|
|
@@ -65,6 +66,7 @@ export interface MeResponse {
|
|
|
65
66
|
x_username?: string;
|
|
66
67
|
x_user_id?: string;
|
|
67
68
|
x_display_name?: string;
|
|
69
|
+
google_email?: string;
|
|
68
70
|
expires_at: number;
|
|
69
71
|
}
|
|
70
72
|
export interface NonceResponse {
|
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;AAE3C,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AAEzB,MAAM,WAAW,IAAI;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,aAAa,CAAC;IAC9B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,eAAe,CAAC,EAAE,cAAc,CAAC;IACjC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAE3C,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AAEzB,MAAM,WAAW,IAAI;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,aAAa,CAAC;IAC9B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,eAAe,CAAC,EAAE,cAAc,CAAC;IACjC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,iBAAiB,CAAC;IACxB,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB;AA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AE,cAAc,CAAC;IACjC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;CACf"}
|
package/dist/auth/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AA+CA,0CAKC;AAED,sDAEC;AAtDD,2CAAyB;AACzB,2CAAyB;AAqBzB,IAAY,iBAIX;AAJD,WAAY,iBAAiB;IAC3B,sCAAiB,CAAA;IACjB,mDAA8B,CAAA;IAC9B,iDAA4B,CAAA;AAC9B,CAAC,EAJW,iBAAiB,iCAAjB,iBAAiB,QAI5B;AAED,IAAY,SAGX;AAHD,WAAY,SAAS;IACnB,8BAAiB,CAAA;IACjB,kCAAqB,CAAA;AACvB,CAAC,EAHW,SAAS,yBAAT,SAAS,QAGpB;AAcD,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\";\n\nexport * from \"./client\";\nexport * from \"./native\";\n\nexport interface User {\n id: string;\n wallet_address: string;\n linked_account: LinkedAccount;\n privy_id?: string;\n embedded_wallet?: EmbeddedWallet;\n x_username?: string;\n x_user_id?: string;\n x_display_name?: string;\n google_email?: string;\n}\n\nexport interface LinkedAccount {\n id: string;\n type: LinkedAccountType;\n chain?: ChainType;\n address: string;\n}\n\nexport enum LinkedAccountType {\n Wallet = \"wallet\",\n TwitterOauth = \"twitter_oauth\",\n GoogleOauth = \"google_oauth\",\n}\n\nexport enum ChainType {\n Solana = \"solana\",\n Ethereum = \"ethereum\",\n}\n\nexport interface EmbeddedWallet {\n privy_id: string;\n chain: ChainType;\n address: string;\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 LoginResponse {\n user_id: string;\n wallet_address: string;\n expires_at: number;\n linked_account: LinkedAccount;\n privy_id?: string;\n embedded_wallet?: EmbeddedWallet;\n x_username?: string;\n x_user_id?: string;\n x_display_name?: string;\n google_email?: string;\n}\n\nexport interface MeResponse {\n user_id: string;\n wallet_address: string;\n linked_account: LinkedAccount;\n privy_id?: string;\n embedded_wallet?: EmbeddedWallet;\n x_username?: string;\n x_user_id?: string;\n x_display_name?: string;\n google_email?: string;\n expires_at: number;\n}\n\nexport interface NonceResponse {\n nonce: string;\n}\n"]}
|
package/dist/client.d.ts
CHANGED
|
@@ -1,42 +1,38 @@
|
|
|
1
|
+
import { Connection, PublicKey } from "@solana/web3.js";
|
|
1
2
|
import { Auth, type AuthCredentials } from "./auth";
|
|
3
|
+
import type { ClientContext } from "./context";
|
|
2
4
|
import { Admin } from "./domain/admin";
|
|
3
5
|
import { Markets } from "./domain/market";
|
|
4
6
|
import { Notifications } from "./domain/notification";
|
|
5
7
|
import { Orders } from "./domain/order";
|
|
6
8
|
import { Orderbooks } from "./domain/orderbook";
|
|
7
|
-
import type { DecimalsResponse } from "./domain/orderbook";
|
|
8
9
|
import { Positions } from "./domain/position";
|
|
9
|
-
import { DepositPriceClient } from "./domain/deposit_price";
|
|
10
10
|
import { PriceHistoryClient } from "./domain/price_history";
|
|
11
11
|
import { Referrals } from "./domain/referral";
|
|
12
12
|
import { Trades } from "./domain/trade";
|
|
13
13
|
import { LightconeHttp } from "./http";
|
|
14
14
|
import { Privy } from "./privy";
|
|
15
|
+
import { Rpc } from "./rpc";
|
|
15
16
|
import { WsClient, type WsConfig } from "./ws";
|
|
16
|
-
declare class DecimalsCache {
|
|
17
|
-
private readonly map;
|
|
18
|
-
get(orderbookId: string): DecimalsResponse | undefined;
|
|
19
|
-
set(orderbookId: string, response: DecimalsResponse): void;
|
|
20
|
-
clear(): void;
|
|
21
|
-
}
|
|
22
17
|
declare class AuthState {
|
|
23
|
-
private readonly clearCachesFn;
|
|
24
18
|
private credentialsValue;
|
|
25
|
-
constructor(
|
|
19
|
+
constructor(initial?: AuthCredentials);
|
|
26
20
|
getCredentials(): AuthCredentials | undefined;
|
|
27
21
|
setCredentials(credentials: AuthCredentials | undefined): void;
|
|
28
22
|
clearCaches(): Promise<void>;
|
|
29
23
|
}
|
|
30
|
-
export declare class LightconeClient {
|
|
24
|
+
export declare class LightconeClient implements ClientContext {
|
|
31
25
|
readonly http: LightconeHttp;
|
|
26
|
+
readonly programId: PublicKey;
|
|
27
|
+
readonly connection?: Connection;
|
|
32
28
|
private readonly wsConfigValue;
|
|
33
|
-
private readonly decimalsCacheStore;
|
|
34
29
|
private readonly authStateStore;
|
|
35
30
|
constructor(params: {
|
|
36
31
|
http: LightconeHttp;
|
|
37
32
|
wsConfig: WsConfig;
|
|
33
|
+
programId?: PublicKey;
|
|
34
|
+
connection?: Connection;
|
|
38
35
|
authCredentials?: AuthCredentials;
|
|
39
|
-
decimalsCache?: DecimalsCache;
|
|
40
36
|
authState?: AuthState;
|
|
41
37
|
});
|
|
42
38
|
static builder(): LightconeClientBuilder;
|
|
@@ -46,27 +42,30 @@ export declare class LightconeClient {
|
|
|
46
42
|
positions(): Positions;
|
|
47
43
|
trades(): Trades;
|
|
48
44
|
priceHistory(): PriceHistoryClient;
|
|
49
|
-
depositPrice(): DepositPriceClient;
|
|
50
45
|
notifications(): Notifications;
|
|
51
46
|
admin(): Admin;
|
|
52
47
|
auth(): Auth;
|
|
53
48
|
privy(): Privy;
|
|
54
49
|
referrals(): Referrals;
|
|
50
|
+
rpc(): Rpc;
|
|
55
51
|
wsConfig(): WsConfig;
|
|
56
52
|
ws(): WsClient;
|
|
57
|
-
clearDecimalsCache(): Promise<void>;
|
|
58
53
|
clone(): LightconeClient;
|
|
59
54
|
}
|
|
60
55
|
export declare class LightconeClientBuilder {
|
|
61
56
|
private baseUrlValue;
|
|
62
57
|
private wsUrlValue;
|
|
63
58
|
private authCredentials?;
|
|
59
|
+
private programIdValue;
|
|
60
|
+
private rpcUrlValue?;
|
|
64
61
|
baseUrl(url: string): LightconeClientBuilder;
|
|
65
62
|
withBaseUrl(url: string): LightconeClientBuilder;
|
|
66
63
|
wsUrl(url: string): LightconeClientBuilder;
|
|
67
64
|
withWsUrl(url: string): LightconeClientBuilder;
|
|
68
65
|
auth(credentials: AuthCredentials): LightconeClientBuilder;
|
|
69
66
|
withAuth(credentials: AuthCredentials): LightconeClientBuilder;
|
|
67
|
+
programId(id: PublicKey): LightconeClientBuilder;
|
|
68
|
+
rpcUrl(url: string): LightconeClientBuilder;
|
|
70
69
|
build(): LightconeClient;
|
|
71
70
|
}
|
|
72
71
|
export {};
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA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AG,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,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,sBAAsB;IAK3C,KAAK,IAAI,eAAe;CAkBzB"}
|
package/dist/client.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LightconeClientBuilder = exports.LightconeClient = void 0;
|
|
4
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
4
5
|
const auth_1 = require("./auth");
|
|
5
6
|
const admin_1 = require("./domain/admin");
|
|
6
7
|
const market_1 = require("./domain/market");
|
|
@@ -8,31 +9,18 @@ const notification_1 = require("./domain/notification");
|
|
|
8
9
|
const order_1 = require("./domain/order");
|
|
9
10
|
const orderbook_1 = require("./domain/orderbook");
|
|
10
11
|
const position_1 = require("./domain/position");
|
|
11
|
-
const deposit_price_1 = require("./domain/deposit_price");
|
|
12
12
|
const price_history_1 = require("./domain/price_history");
|
|
13
13
|
const referral_1 = require("./domain/referral");
|
|
14
14
|
const trade_1 = require("./domain/trade");
|
|
15
15
|
const http_1 = require("./http");
|
|
16
16
|
const network_1 = require("./network");
|
|
17
17
|
const privy_1 = require("./privy");
|
|
18
|
+
const constants_1 = require("./program/constants");
|
|
19
|
+
const rpc_1 = require("./rpc");
|
|
18
20
|
const ws_1 = require("./ws");
|
|
19
|
-
class DecimalsCache {
|
|
20
|
-
map = new Map();
|
|
21
|
-
get(orderbookId) {
|
|
22
|
-
return this.map.get(orderbookId);
|
|
23
|
-
}
|
|
24
|
-
set(orderbookId, response) {
|
|
25
|
-
this.map.set(orderbookId, response);
|
|
26
|
-
}
|
|
27
|
-
clear() {
|
|
28
|
-
this.map.clear();
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
21
|
class AuthState {
|
|
32
|
-
clearCachesFn;
|
|
33
22
|
credentialsValue;
|
|
34
|
-
constructor(
|
|
35
|
-
this.clearCachesFn = clearCachesFn;
|
|
23
|
+
constructor(initial) {
|
|
36
24
|
this.credentialsValue = initial;
|
|
37
25
|
}
|
|
38
26
|
getCredentials() {
|
|
@@ -42,33 +30,33 @@ class AuthState {
|
|
|
42
30
|
this.credentialsValue = credentials;
|
|
43
31
|
}
|
|
44
32
|
async clearCaches() {
|
|
45
|
-
|
|
33
|
+
// No caches to clear — decimals are derived locally from orderbook metadata.
|
|
46
34
|
}
|
|
47
35
|
}
|
|
48
36
|
class LightconeClient {
|
|
49
37
|
http;
|
|
38
|
+
programId;
|
|
39
|
+
connection;
|
|
50
40
|
wsConfigValue;
|
|
51
|
-
decimalsCacheStore;
|
|
52
41
|
authStateStore;
|
|
53
42
|
constructor(params) {
|
|
54
43
|
this.http = params.http;
|
|
44
|
+
this.programId = params.programId ?? constants_1.PROGRAM_ID;
|
|
45
|
+
this.connection = params.connection;
|
|
55
46
|
this.wsConfigValue = params.wsConfig;
|
|
56
|
-
this.decimalsCacheStore = params.decimalsCache ?? new DecimalsCache();
|
|
57
47
|
this.authStateStore =
|
|
58
48
|
params.authState ??
|
|
59
|
-
new AuthState(
|
|
49
|
+
new AuthState(params.authCredentials);
|
|
60
50
|
}
|
|
61
51
|
static builder() {
|
|
62
52
|
return new LightconeClientBuilder();
|
|
63
53
|
}
|
|
54
|
+
// ── Sub-client accessors ─────────────────────────────────────────────
|
|
64
55
|
markets() {
|
|
65
56
|
return new market_1.Markets(this);
|
|
66
57
|
}
|
|
67
58
|
orderbooks() {
|
|
68
|
-
return new orderbook_1.Orderbooks(
|
|
69
|
-
http: this.http,
|
|
70
|
-
decimalsCache: this.decimalsCacheStore,
|
|
71
|
-
});
|
|
59
|
+
return new orderbook_1.Orderbooks(this);
|
|
72
60
|
}
|
|
73
61
|
orders() {
|
|
74
62
|
return new order_1.Orders(this);
|
|
@@ -82,9 +70,6 @@ class LightconeClient {
|
|
|
82
70
|
priceHistory() {
|
|
83
71
|
return new price_history_1.PriceHistoryClient(this);
|
|
84
72
|
}
|
|
85
|
-
depositPrice() {
|
|
86
|
-
return new deposit_price_1.DepositPriceClient(this);
|
|
87
|
-
}
|
|
88
73
|
notifications() {
|
|
89
74
|
return new notification_1.Notifications(this);
|
|
90
75
|
}
|
|
@@ -103,20 +88,23 @@ class LightconeClient {
|
|
|
103
88
|
referrals() {
|
|
104
89
|
return new referral_1.Referrals(this);
|
|
105
90
|
}
|
|
91
|
+
rpc() {
|
|
92
|
+
return new rpc_1.Rpc(this);
|
|
93
|
+
}
|
|
106
94
|
wsConfig() {
|
|
107
95
|
return this.wsConfigValue;
|
|
108
96
|
}
|
|
109
97
|
ws() {
|
|
110
98
|
return new ws_1.WsClient(this.wsConfigValue, this.http.authTokenRef());
|
|
111
99
|
}
|
|
112
|
-
async clearDecimalsCache() {
|
|
113
|
-
this.decimalsCacheStore.clear();
|
|
114
|
-
}
|
|
115
100
|
clone() {
|
|
116
101
|
return new LightconeClient({
|
|
117
102
|
http: this.http,
|
|
118
103
|
wsConfig: { ...this.wsConfigValue },
|
|
119
|
-
|
|
104
|
+
programId: this.programId,
|
|
105
|
+
connection: this.connection
|
|
106
|
+
? new web3_js_1.Connection(this.connection.rpcEndpoint)
|
|
107
|
+
: undefined,
|
|
120
108
|
authState: this.authStateStore,
|
|
121
109
|
});
|
|
122
110
|
}
|
|
@@ -126,6 +114,8 @@ class LightconeClientBuilder {
|
|
|
126
114
|
baseUrlValue = network_1.DEFAULT_API_URL;
|
|
127
115
|
wsUrlValue = network_1.DEFAULT_WS_URL;
|
|
128
116
|
authCredentials;
|
|
117
|
+
programIdValue = constants_1.PROGRAM_ID;
|
|
118
|
+
rpcUrlValue;
|
|
129
119
|
baseUrl(url) {
|
|
130
120
|
return this.withBaseUrl(url);
|
|
131
121
|
}
|
|
@@ -147,6 +137,14 @@ class LightconeClientBuilder {
|
|
|
147
137
|
this.authCredentials = credentials;
|
|
148
138
|
return this;
|
|
149
139
|
}
|
|
140
|
+
programId(id) {
|
|
141
|
+
this.programIdValue = id;
|
|
142
|
+
return this;
|
|
143
|
+
}
|
|
144
|
+
rpcUrl(url) {
|
|
145
|
+
this.rpcUrlValue = url;
|
|
146
|
+
return this;
|
|
147
|
+
}
|
|
150
148
|
build() {
|
|
151
149
|
return new LightconeClient({
|
|
152
150
|
http: new http_1.LightconeHttp(this.baseUrlValue),
|
|
@@ -158,6 +156,10 @@ class LightconeClientBuilder {
|
|
|
158
156
|
pingIntervalMs: 30_000,
|
|
159
157
|
pongTimeoutMs: 1_000,
|
|
160
158
|
},
|
|
159
|
+
programId: this.programIdValue,
|
|
160
|
+
connection: this.rpcUrlValue
|
|
161
|
+
? new web3_js_1.Connection(this.rpcUrlValue)
|
|
162
|
+
: undefined,
|
|
161
163
|
authCredentials: this.authCredentials,
|
|
162
164
|
});
|
|
163
165
|
}
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;AAAA,iCAAoD;
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;AAAA,6CAAwD;AACxD,iCAAoD;AAEpD,0CAAuC;AACvC,4CAA0C;AAC1C,wDAAsD;AACtD,0CAAwC;AACxC,kDAAgD;AAChD,gDAA8C;AAC9C,0DAA4D;AAC5D,gDAA8C;AAC9C,0CAAwC;AACxC,iCAAuC;AACvC,uCAA4D;AAC5D,mCAAgC;AAChC,mDAAiD;AACjD,+BAA4B;AAC5B,6BAA+C;AAE/C,MAAM,SAAS;IACL,gBAAgB,CAA8B;IAEtD,YAAY,OAAyB;QACnC,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC;IAClC,CAAC;IAED,cAAc;QACZ,OAAO,IAAI,CAAC,gB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import { Connection, PublicKey } from \"@solana/web3.js\";\nimport { Auth, type AuthCredentials } from \"./auth\";\nimport type { ClientContext } from \"./context\";\nimport { Admin } from \"./domain/admin\";\nimport { Markets } from \"./domain/market\";\nimport { Notifications } from \"./domain/notification\";\nimport { Orders } from \"./domain/order\";\nimport { Orderbooks } from \"./domain/orderbook\";\nimport { Positions } from \"./domain/position\";\nimport { PriceHistoryClient } from \"./domain/price_history\";\nimport { Referrals } from \"./domain/referral\";\nimport { Trades } from \"./domain/trade\";\nimport { LightconeHttp } from \"./http\";\nimport { DEFAULT_API_URL, DEFAULT_WS_URL } from \"./network\";\nimport { Privy } from \"./privy\";\nimport { PROGRAM_ID } from \"./program/constants\";\nimport { Rpc } from \"./rpc\";\nimport { WsClient, type WsConfig } from \"./ws\";\n\nclass AuthState {\n private credentialsValue: AuthCredentials | undefined;\n\n constructor(initial?: AuthCredentials) {\n this.credentialsValue = initial;\n }\n\n getCredentials(): AuthCredentials | undefined {\n return this.credentialsValue;\n }\n\n setCredentials(credentials: AuthCredentials | undefined): void {\n this.credentialsValue = credentials;\n }\n\n async clearCaches(): Promise<void> {\n // No caches to clear — decimals are derived locally from orderbook metadata.\n }\n}\n\nexport class LightconeClient implements ClientContext {\n readonly http: LightconeHttp;\n readonly programId: PublicKey;\n readonly connection?: Connection;\n private readonly wsConfigValue: WsConfig;\n private readonly authStateStore: AuthState;\n\n constructor(params: {\n http: LightconeHttp;\n wsConfig: WsConfig;\n programId?: PublicKey;\n connection?: Connection;\n authCredentials?: AuthCredentials;\n authState?: AuthState;\n }) {\n this.http = params.http;\n this.programId = params.programId ?? PROGRAM_ID;\n this.connection = params.connection;\n this.wsConfigValue = params.wsConfig;\n this.authStateStore =\n params.authState ??\n new AuthState(params.authCredentials);\n }\n\n static builder(): LightconeClientBuilder {\n return new LightconeClientBuilder();\n }\n\n // ── Sub-client accessors ─────────────────────────────────────────────\n\n markets(): Markets {\n return new Markets(this);\n }\n\n orderbooks(): Orderbooks {\n return new Orderbooks(this);\n }\n\n orders(): Orders {\n return new Orders(this);\n }\n\n positions(): Positions {\n return new Positions(this);\n }\n\n trades(): Trades {\n return new Trades(this);\n }\n\n priceHistory(): PriceHistoryClient {\n return new PriceHistoryClient(this);\n }\n\n notifications(): Notifications {\n return new Notifications(this);\n }\n\n admin(): Admin {\n return new Admin(this);\n }\n\n auth(): Auth {\n return new Auth({\n http: this.http,\n authState: this.authStateStore,\n });\n }\n\n privy(): Privy {\n return new Privy(this);\n }\n\n referrals(): Referrals {\n return new Referrals(this);\n }\n\n rpc(): Rpc {\n return new Rpc(this);\n }\n\n wsConfig(): WsConfig {\n return this.wsConfigValue;\n }\n\n ws(): WsClient {\n return new WsClient(this.wsConfigValue, this.http.authTokenRef());\n }\n\n clone(): LightconeClient {\n return new LightconeClient({\n http: this.http,\n wsConfig: { ...this.wsConfigValue },\n programId: this.programId,\n connection: this.connection\n ? new Connection(this.connection.rpcEndpoint)\n : undefined,\n authState: this.authStateStore,\n });\n }\n}\n\nexport class LightconeClientBuilder {\n private baseUrlValue: string = DEFAULT_API_URL;\n private wsUrlValue: string = DEFAULT_WS_URL;\n private authCredentials?: AuthCredentials;\n private programIdValue: PublicKey = PROGRAM_ID;\n private rpcUrlValue?: string;\n\n baseUrl(url: string): LightconeClientBuilder {\n return this.withBaseUrl(url);\n }\n\n withBaseUrl(url: string): LightconeClientBuilder {\n this.baseUrlValue = url;\n return this;\n }\n\n wsUrl(url: string): LightconeClientBuilder {\n return this.withWsUrl(url);\n }\n\n withWsUrl(url: string): LightconeClientBuilder {\n this.wsUrlValue = url;\n return this;\n }\n\n auth(credentials: AuthCredentials): LightconeClientBuilder {\n return this.withAuth(credentials);\n }\n\n withAuth(credentials: AuthCredentials): LightconeClientBuilder {\n this.authCredentials = credentials;\n return this;\n }\n\n programId(id: PublicKey): LightconeClientBuilder {\n this.programIdValue = id;\n return this;\n }\n\n rpcUrl(url: string): LightconeClientBuilder {\n this.rpcUrlValue = url;\n return this;\n }\n\n build(): LightconeClient {\n return new LightconeClient({\n http: new LightconeHttp(this.baseUrlValue),\n wsConfig: {\n url: this.wsUrlValue,\n reconnect: true,\n maxReconnectAttempts: 10,\n baseReconnectDelayMs: 1_000,\n pingIntervalMs: 30_000,\n pongTimeoutMs: 1_000,\n },\n programId: this.programIdValue,\n connection: this.rpcUrlValue\n ? new Connection(this.rpcUrlValue)\n : undefined,\n authCredentials: this.authCredentials,\n });\n }\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Connection, PublicKey } from "@solana/web3.js";
|
|
2
|
+
import type { LightconeHttp } from "./http";
|
|
3
|
+
export interface ClientContext {
|
|
4
|
+
readonly http: LightconeHttp;
|
|
5
|
+
readonly programId: PublicKey;
|
|
6
|
+
readonly connection?: Connection;
|
|
7
|
+
}
|
|
8
|
+
export declare function requireConnection(ctx: ClientContext): Connection;
|
|
9
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAE5C,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAC7B,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAC9B,QAAQ,CAAC,UAAU,CAAC,EAAE,UAAU,CAAC;CAClC;AAED,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,aAAa,GAAG,UAAU,CAOhE"}
|
package/dist/context.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.requireConnection = requireConnection;
|
|
4
|
+
function requireConnection(ctx) {
|
|
5
|
+
if (!ctx.connection) {
|
|
6
|
+
throw new Error("RPC client not configured — use .rpcUrl() on the builder");
|
|
7
|
+
}
|
|
8
|
+
return ctx.connection;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":";;AASA,8CAOC;AAPD,SAAgB,iBAAiB,CAAC,GAAkB;IAClD,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CACb,0DAA0D,CAC3D,CAAC;IACJ,CAAC;IACD,OAAO,GAAG,CAAC,UAAU,CAAC;AACxB,CAAC","sourcesContent":["import type { Connection, PublicKey } from \"@solana/web3.js\";\nimport type { LightconeHttp } from \"./http\";\n\nexport interface ClientContext {\n readonly http: LightconeHttp;\n readonly programId: PublicKey;\n readonly connection?: Connection;\n}\n\nexport function requireConnection(ctx: ClientContext): Connection {\n if (!ctx.connection) {\n throw new Error(\n \"RPC client not configured — use .rpcUrl() on the builder\"\n );\n }\n return ctx.connection;\n}\n"]}
|