@lightconexyz/lightcone-sdk 0.2.43 → 0.4.1

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.
Files changed (71) hide show
  1. package/README.md +32 -39
  2. package/dist/client.d.ts +19 -1
  3. package/dist/client.d.ts.map +1 -1
  4. package/dist/client.js +49 -0
  5. package/dist/client.js.map +1 -1
  6. package/dist/context.d.ts +7 -0
  7. package/dist/context.d.ts.map +1 -1
  8. package/dist/context.js +79 -0
  9. package/dist/context.js.map +1 -1
  10. package/dist/domain/market/builders.d.ts +37 -0
  11. package/dist/domain/market/builders.d.ts.map +1 -0
  12. package/dist/domain/market/builders.js +114 -0
  13. package/dist/domain/market/builders.js.map +1 -0
  14. package/dist/domain/market/client.d.ts +3 -0
  15. package/dist/domain/market/client.d.ts.map +1 -1
  16. package/dist/domain/market/client.js +8 -0
  17. package/dist/domain/market/client.js.map +1 -1
  18. package/dist/domain/market/index.d.ts +1 -0
  19. package/dist/domain/market/index.d.ts.map +1 -1
  20. package/dist/domain/market/index.js +1 -0
  21. package/dist/domain/market/index.js.map +1 -1
  22. package/dist/domain/order/client.d.ts +8 -1
  23. package/dist/domain/order/client.d.ts.map +1 -1
  24. package/dist/domain/order/client.js +109 -0
  25. package/dist/domain/order/client.js.map +1 -1
  26. package/dist/domain/order/wire.d.ts +15 -0
  27. package/dist/domain/order/wire.d.ts.map +1 -1
  28. package/dist/domain/order/wire.js.map +1 -1
  29. package/dist/domain/position/builders.d.ts +179 -0
  30. package/dist/domain/position/builders.d.ts.map +1 -0
  31. package/dist/domain/position/builders.js +501 -0
  32. package/dist/domain/position/builders.js.map +1 -0
  33. package/dist/domain/position/client.d.ts +15 -1
  34. package/dist/domain/position/client.d.ts.map +1 -1
  35. package/dist/domain/position/client.js +90 -0
  36. package/dist/domain/position/client.js.map +1 -1
  37. package/dist/domain/position/index.d.ts +1 -0
  38. package/dist/domain/position/index.d.ts.map +1 -1
  39. package/dist/domain/position/index.js +1 -0
  40. package/dist/domain/position/index.js.map +1 -1
  41. package/dist/error.d.ts +4 -1
  42. package/dist/error.d.ts.map +1 -1
  43. package/dist/error.js +9 -0
  44. package/dist/error.js.map +1 -1
  45. package/dist/index.d.ts +1 -1
  46. package/dist/index.d.ts.map +1 -1
  47. package/dist/index.js +4 -1
  48. package/dist/index.js.map +1 -1
  49. package/dist/prelude.d.ts +5 -2
  50. package/dist/prelude.d.ts.map +1 -1
  51. package/dist/prelude.js +16 -1
  52. package/dist/prelude.js.map +1 -1
  53. package/dist/privy/index.js +25 -25
  54. package/dist/privy/index.js.map +1 -1
  55. package/dist/program/envelope.d.ts +20 -15
  56. package/dist/program/envelope.d.ts.map +1 -1
  57. package/dist/program/envelope.js +99 -31
  58. package/dist/program/envelope.js.map +1 -1
  59. package/dist/program/orders.d.ts +3 -1
  60. package/dist/program/orders.d.ts.map +1 -1
  61. package/dist/program/orders.js +5 -2
  62. package/dist/program/orders.js.map +1 -1
  63. package/dist/shared/index.d.ts +1 -0
  64. package/dist/shared/index.d.ts.map +1 -1
  65. package/dist/shared/index.js +3 -1
  66. package/dist/shared/index.js.map +1 -1
  67. package/dist/shared/signing.d.ts +17 -0
  68. package/dist/shared/signing.d.ts.map +1 -0
  69. package/dist/shared/signing.js +13 -0
  70. package/dist/shared/signing.js.map +1 -0
  71. package/package.json +1 -1
package/README.md CHANGED
@@ -29,13 +29,14 @@ npm install @lightconexyz/lightcone-sdk
29
29
  import { Keypair, PublicKey } from "@solana/web3.js";
30
30
  import {
31
31
  LightconeClient,
32
- LimitOrderEnvelope,
32
+ DepositSource,
33
33
  auth,
34
34
  } from "@lightconexyz/lightcone-sdk";
35
35
 
36
36
  async function main() {
37
37
  const client = LightconeClient.builder()
38
38
  .rpcUrl("https://api.devnet.solana.com")
39
+ .depositSource(DepositSource.Market)
39
40
  .build();
40
41
  const keypair = Keypair.generate();
41
42
 
@@ -58,7 +59,7 @@ async function main() {
58
59
  // 3. Build, sign, and submit a limit order
59
60
  // Decimals are derived automatically from the orderbook's token metadata.
60
61
  const nonce = await client.orders().currentNonce(keypair.publicKey);
61
- const request = LimitOrderEnvelope.new()
62
+ const request = client.orders().limitOrder()
62
63
  .maker(keypair.publicKey)
63
64
  .market(new PublicKey(market.pubkey))
64
65
  .baseMint(new PublicKey(orderbook.base.pubkey))
@@ -87,7 +88,7 @@ main().catch(console.error);
87
88
  import * as fs from "fs";
88
89
  import * as path from "path";
89
90
  import { Keypair, PublicKey } from "@solana/web3.js";
90
- import { LightconeClient } from "@lightconexyz/lightcone-sdk";
91
+ import { LightconeClient, DepositSource } from "@lightconexyz/lightcone-sdk";
91
92
 
92
93
  function readKeypairFile(filePath: string): Keypair {
93
94
  const resolved = filePath.startsWith("~")
@@ -97,10 +98,12 @@ function readKeypairFile(filePath: string): Keypair {
97
98
  return Keypair.fromSecretKey(Uint8Array.from(secret));
98
99
  }
99
100
 
101
+ const keypair = readKeypairFile("~/.config/solana/id.json");
102
+
100
103
  const client = LightconeClient.builder()
101
104
  .rpcUrl("https://api.devnet.solana.com")
105
+ .nativeSigner(keypair)
102
106
  .build();
103
- const keypair = readKeypairFile("~/.config/solana/id.json");
104
107
  ```
105
108
 
106
109
  ### Step 1: Find a Market
@@ -115,32 +118,20 @@ const orderbook =
115
118
  ### Step 2: Deposit Collateral
116
119
 
117
120
  ```typescript
118
- import { Transaction } from "@solana/web3.js";
119
-
120
- const marketPubkey = new PublicKey(market.pubkey);
121
121
  const depositMint = new PublicKey(market.depositAssets[0].pubkey);
122
122
  const numOutcomes = market.outcomes.length;
123
- const mintIx = client.markets().mintCompleteSetIx(
124
- {
125
- user: keypair.publicKey,
126
- market: marketPubkey,
127
- depositMint,
128
- amount: 1_000_000n,
129
- },
130
- numOutcomes
131
- );
132
- const tx = new Transaction().add(mintIx);
133
- tx.feePayer = keypair.publicKey;
134
- tx.recentBlockhash = (await client.rpc().getLatestBlockhash()).blockhash;
135
- tx.sign(keypair);
123
+ const depositIx = client.positions().deposit()
124
+ .user(keypair.publicKey)
125
+ .mint(depositMint)
126
+ .amount(1_000_000n)
127
+ .market(market)
128
+ .buildIx();
136
129
  ```
137
130
 
138
131
  ### Step 3: Place an Order
139
132
 
140
133
  ```typescript
141
- import { LimitOrderEnvelope } from "@lightconexyz/lightcone-sdk";
142
-
143
- const request = LimitOrderEnvelope.new()
134
+ const request = client.orders().limitOrder()
144
135
  .maker(keypair.publicKey)
145
136
  .market(new PublicKey(market.pubkey))
146
137
  .baseMint(new PublicKey(orderbook.base.pubkey))
@@ -186,19 +177,14 @@ await client.orders().cancel({
186
177
  ### Step 6: Exit a Position
187
178
 
188
179
  ```typescript
189
- const mergeIx = client.markets().mergeCompleteSetIx(
190
- {
191
- user: keypair.publicKey,
192
- market: new PublicKey(market.pubkey),
193
- depositMint,
194
- amount: 1_000_000n,
195
- },
196
- numOutcomes
197
- );
198
- const mergeTx = new Transaction().add(mergeIx);
199
- mergeTx.feePayer = keypair.publicKey;
200
- mergeTx.recentBlockhash = (await client.rpc().getLatestBlockhash()).blockhash;
201
- mergeTx.sign(keypair);
180
+ // signAndSubmit builds the tx, signs it using the client's signing strategy, and submits
181
+ const txHash = await client.markets().mergeCompleteSet()
182
+ .user(keypair.publicKey)
183
+ .market(new PublicKey(market.pubkey))
184
+ .mint(depositMint)
185
+ .amount(1_000_000n)
186
+ .numOutcomes(numOutcomes)
187
+ .signAndSubmit();
202
188
  ```
203
189
 
204
190
  ## Authentication
@@ -227,7 +213,7 @@ All examples are runnable with `npx tsx examples/<name>.ts`. Set environment var
227
213
 
228
214
  | Example | Description |
229
215
  |---------|-------------|
230
- | [`submit_order`](examples/submit_order.ts) | `LimitOrderEnvelope` with human-readable price/size, auto-scaling, and fill tracking |
216
+ | [`submit_order`](examples/submit_order.ts) | Limit order via `client.orders().limitOrder()` with human-readable price/size, auto-scaling, and fill tracking |
231
217
 
232
218
  ### Cancelling Orders
233
219
 
@@ -242,7 +228,7 @@ All examples are runnable with `npx tsx examples/<name>.ts`. Set environment var
242
228
  |---------|-------------|
243
229
  | [`read_onchain`](examples/read_onchain.ts) | Read exchange state, market state, user nonce, and PDA derivations via RPC |
244
230
  | [`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 |
231
+ | [`global_deposit_withdrawal`](examples/global_deposit_withdrawal.ts) | Init position tokens, deposit to global pool, move capital into a market, extend an existing ALT, and withdraw from global |
246
232
 
247
233
  ### WebSocket Streaming
248
234
 
@@ -263,15 +249,22 @@ All SDK operations return promises that reject with `SdkError`:
263
249
  | `SdkError.Auth(AuthError)` | Authentication failures |
264
250
  | `SdkError.Validation(string)` | Domain type conversion failures |
265
251
  | `SdkError.Serde(Error)` | Serialization errors |
252
+ | `SdkError.MissingMarketContext(string)` | Market context not provided for operation requiring `DepositSource.Market` |
253
+ | `SdkError.Signing(string)` | Signing operation failures |
254
+ | `SdkError.UserCancelled` | User cancelled wallet signing prompt |
266
255
  | `SdkError.Other(string)` | Catch-all |
267
256
 
268
- Notable `HttpError` variants:
257
+ `HttpError` variants:
269
258
 
270
259
  | Variant | Meaning |
271
260
  |---------|---------|
261
+ | `Request { message }` | Network/transport failure |
272
262
  | `ServerError { status, body }` | Non-2xx response from the backend |
273
263
  | `RateLimited { retryAfterMs }` | 429 - back off and retry |
274
264
  | `Unauthorized` | 401 - session expired or missing |
265
+ | `NotFound { body }` | 404 - resource not found |
266
+ | `BadRequest { body }` | 400 - invalid request |
267
+ | `Timeout` | Request timed out |
275
268
  | `MaxRetriesExceeded { attempts, lastError }` | All retry attempts exhausted |
276
269
 
277
270
  ## Retry Strategy
package/dist/client.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Connection, PublicKey } from "@solana/web3.js";
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
4
  import { Admin } from "./domain/admin";
@@ -13,6 +13,8 @@ import { Trades } from "./domain/trade";
13
13
  import { LightconeHttp } from "./http";
14
14
  import { Privy } from "./privy";
15
15
  import { Rpc } from "./rpc";
16
+ import { DepositSource } from "./shared";
17
+ import { type ExternalSigner, type SigningStrategy } from "./shared/signing";
16
18
  import { WsClient, type WsConfig } from "./ws";
17
19
  declare class AuthState {
18
20
  private credentialsValue;
@@ -25,6 +27,8 @@ export declare class LightconeClient implements ClientContext {
25
27
  readonly http: LightconeHttp;
26
28
  readonly programId: PublicKey;
27
29
  readonly connection?: Connection;
30
+ private depositSourceValue;
31
+ private signingStrategyValue?;
28
32
  private readonly wsConfigValue;
29
33
  private readonly authStateStore;
30
34
  constructor(params: {
@@ -32,9 +36,17 @@ export declare class LightconeClient implements ClientContext {
32
36
  wsConfig: WsConfig;
33
37
  programId?: PublicKey;
34
38
  connection?: Connection;
39
+ depositSource?: DepositSource;
40
+ signingStrategy?: SigningStrategy;
35
41
  authCredentials?: AuthCredentials;
36
42
  authState?: AuthState;
37
43
  });
44
+ get depositSource(): DepositSource;
45
+ setDepositSource(source: DepositSource): void;
46
+ get signingStrategy(): SigningStrategy | undefined;
47
+ setSigningStrategy(strategy: SigningStrategy): void;
48
+ clearSigningStrategy(): void;
49
+ signAndSubmitTx(tx: Transaction): Promise<string>;
38
50
  static builder(): LightconeClientBuilder;
39
51
  markets(): Markets;
40
52
  orderbooks(): Orderbooks;
@@ -57,6 +69,8 @@ export declare class LightconeClientBuilder {
57
69
  private wsUrlValue;
58
70
  private authCredentials?;
59
71
  private programIdValue;
72
+ private depositSourceValue;
73
+ private signingStrategyValue?;
60
74
  private rpcUrlValue?;
61
75
  baseUrl(url: string): LightconeClientBuilder;
62
76
  withBaseUrl(url: string): LightconeClientBuilder;
@@ -65,6 +79,10 @@ export declare class LightconeClientBuilder {
65
79
  auth(credentials: AuthCredentials): LightconeClientBuilder;
66
80
  withAuth(credentials: AuthCredentials): LightconeClientBuilder;
67
81
  programId(id: PublicKey): LightconeClientBuilder;
82
+ depositSource(source: DepositSource): LightconeClientBuilder;
83
+ nativeSigner(keypair: Keypair): LightconeClientBuilder;
84
+ externalSigner(signer: ExternalSigner): LightconeClientBuilder;
85
+ privyWalletId(walletId: string): LightconeClientBuilder;
68
86
  rpcUrl(url: string): LightconeClientBuilder;
69
87
  build(): LightconeClient;
70
88
  }
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,IAAI,EAAE,KAAK,eAAe,EAAE,MAAM,QAAQ,CAAC;AACpD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAEvC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,OAAO,EAAE,QAAQ,EAAE,KAAK,QAAQ,EAAE,MAAM,MAAM,CAAC;AAE/C,cAAM,SAAS;IACb,OAAO,CAAC,gBAAgB,CAA8B;gB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AC,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,CAAC,QAAQ,EAAE,MAAM,GAAG,sBAAsB;IAKvD,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,sBAAsB;IAK3C,KAAK,IAAI,eAAe;CAoBzB"}
package/dist/client.js CHANGED
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LightconeClientBuilder = exports.LightconeClient = void 0;
4
4
  const web3_js_1 = require("@solana/web3.js");
5
5
  const auth_1 = require("./auth");
6
+ const context_1 = require("./context");
6
7
  const admin_1 = require("./domain/admin");
7
8
  const market_1 = require("./domain/market");
8
9
  const notification_1 = require("./domain/notification");
@@ -17,6 +18,7 @@ const network_1 = require("./network");
17
18
  const privy_1 = require("./privy");
18
19
  const constants_1 = require("./program/constants");
19
20
  const rpc_1 = require("./rpc");
21
+ const shared_1 = require("./shared");
20
22
  const ws_1 = require("./ws");
21
23
  class AuthState {
22
24
  credentialsValue;
@@ -37,17 +39,42 @@ class LightconeClient {
37
39
  http;
38
40
  programId;
39
41
  connection;
42
+ depositSourceValue;
43
+ signingStrategyValue;
40
44
  wsConfigValue;
41
45
  authStateStore;
42
46
  constructor(params) {
43
47
  this.http = params.http;
44
48
  this.programId = params.programId ?? constants_1.PROGRAM_ID;
45
49
  this.connection = params.connection;
50
+ this.depositSourceValue = params.depositSource ?? shared_1.DepositSource.Global;
51
+ this.signingStrategyValue = params.signingStrategy;
46
52
  this.wsConfigValue = params.wsConfig;
47
53
  this.authStateStore =
48
54
  params.authState ??
49
55
  new AuthState(params.authCredentials);
50
56
  }
57
+ // ── Deposit source ──────────────────────────────────────────────────
58
+ get depositSource() {
59
+ return this.depositSourceValue;
60
+ }
61
+ setDepositSource(source) {
62
+ this.depositSourceValue = source;
63
+ }
64
+ // ── Signing strategy ────────────────────────────────────────────────
65
+ get signingStrategy() {
66
+ return this.signingStrategyValue;
67
+ }
68
+ setSigningStrategy(strategy) {
69
+ this.signingStrategyValue = strategy;
70
+ }
71
+ clearSigningStrategy() {
72
+ this.signingStrategyValue = undefined;
73
+ }
74
+ // ── Transaction signing + submission ────────────────────────────────
75
+ async signAndSubmitTx(tx) {
76
+ return (0, context_1.signAndSubmitTx)(this, tx);
77
+ }
51
78
  static builder() {
52
79
  return new LightconeClientBuilder();
53
80
  }
@@ -105,6 +132,8 @@ class LightconeClient {
105
132
  connection: this.connection
106
133
  ? new web3_js_1.Connection(this.connection.rpcEndpoint)
107
134
  : undefined,
135
+ depositSource: this.depositSourceValue,
136
+ signingStrategy: this.signingStrategyValue,
108
137
  authState: this.authStateStore,
109
138
  });
110
139
  }
@@ -115,6 +144,8 @@ class LightconeClientBuilder {
115
144
  wsUrlValue = network_1.DEFAULT_WS_URL;
116
145
  authCredentials;
117
146
  programIdValue = constants_1.PROGRAM_ID;
147
+ depositSourceValue = shared_1.DepositSource.Global;
148
+ signingStrategyValue;
118
149
  rpcUrlValue;
119
150
  baseUrl(url) {
120
151
  return this.withBaseUrl(url);
@@ -141,6 +172,22 @@ class LightconeClientBuilder {
141
172
  this.programIdValue = id;
142
173
  return this;
143
174
  }
175
+ depositSource(source) {
176
+ this.depositSourceValue = source;
177
+ return this;
178
+ }
179
+ nativeSigner(keypair) {
180
+ this.signingStrategyValue = { type: "native", keypair };
181
+ return this;
182
+ }
183
+ externalSigner(signer) {
184
+ this.signingStrategyValue = { type: "walletAdapter", signer };
185
+ return this;
186
+ }
187
+ privyWalletId(walletId) {
188
+ this.signingStrategyValue = { type: "privy", walletId };
189
+ return this;
190
+ }
144
191
  rpcUrl(url) {
145
192
  this.rpcUrlValue = url;
146
193
  return this;
@@ -157,6 +204,8 @@ class LightconeClientBuilder {
157
204
  pongTimeoutMs: 1_000,
158
205
  },
159
206
  programId: this.programIdValue,
207
+ depositSource: this.depositSourceValue,
208
+ signingStrategy: this.signingStrategyValue,
160
209
  connection: this.rpcUrlValue
161
210
  ? new web3_js_1.Connection(this.rpcUrlValue)
162
211
  : undefined,
@@ -1 +1 @@
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,gBAAgB,CAAC;IAC/B,CAAC;IAED,cAAc,CAAC,WAAwC;QACrD,IAAI,CAAC,gBAAgB,GAAG,WAAW,CAAC;IACtC,CAAC;IAED,KAAK,CAAC,WAAW;QACf,6EAA6E;IAC/E,CAAC;CACF;AAED,MAAa,eAAe;IACjB,IAAI,CAAgB;IACpB,SAAS,CAAY;IACrB,UAAU,CAAc;IAChB,aAAa,CAAW;IACxB,cAAc,CAAY;IAE3C,YAAY,MAOX;QACC,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;QACxB,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,IAAI,sBAAU,CAAC;QAChD,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;QACpC,IAAI,CAAC,aAAa,GAAG,MAAM,CAAC,QAAQ,CAAC;QACrC,IAAI,CAAC,cAAc;Y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AAC;QACzB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,CAAC,GAAW;QAChB,IAAI,CAAC,WAAW,GAAG,GAAG,CAAC;QACvB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK;QACH,OAAO,IAAI,eAAe,CAAC;YACzB,IAAI,EAAE,IAAI,oBAAa,CAAC,IAAI,CAAC,YAAY,CAAC;YAC1C,QAAQ,EAAE;gBACR,GAAG,EAAE,IAAI,CAAC,UAAU;gBACpB,SAAS,EAAE,IAAI;gBACf,oBAAoB,EAAE,EAAE;gBACxB,oBAAoB,EAAE,KAAK;gBAC3B,cAAc,EAAE,MAAM;gBACtB,aAAa,EAAE,KAAK;aACrB;YACD,SAAS,EAAE,IAAI,CAAC,cAAc;YAC9B,UAAU,EAAE,IAAI,CAAC,WAAW;gBAC1B,CAAC,CAAC,IAAI,oBAAU,CAAC,IAAI,CAAC,WAAW,CAAC;gBAClC,CAAC,CAAC,SAAS;YACb,eAAe,EAAE,IAAI,CAAC,eAAe;SACtC,CAAC,CAAC;IACL,CAAC;CACF;AA9DD,wDA8DC","sourcesContent":["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"]}
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;AAAA,6CAA8E;AAC9E,iCAAoD;AAEpD,uCAAiE;AACjE,0CAAuC;AACvC,4CAA0C;AAC1C,wDAAsD;AACtD,0CAAwC;AACxC,kDAAgD;AAChD,gDAA8C;AAC9C,0DAA4D;AAC5D,gDAA8C;AAC9C,0CAAwC;AACxC,iCAAuC;AACvC,uCAA4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,SAAS,EAAE,IAAI;gBACf,oBAAoB,EAAE,EAAE;gBACxB,oBAAoB,EAAE,KAAK;gBAC3B,cAAc,EAAE,MAAM;gBACtB,aAAa,EAAE,KAAK;aACrB;YACD,SAAS,EAAE,IAAI,CAAC,cAAc;YAC9B,aAAa,EAAE,IAAI,CAAC,kBAAkB;YACtC,eAAe,EAAE,IAAI,CAAC,oBAAoB;YAC1C,UAAU,EAAE,IAAI,CAAC,WAAW;gBAC1B,CAAC,CAAC,IAAI,oBAAU,CAAC,IAAI,CAAC,WAAW,CAAC;gBAClC,CAAC,CAAC,SAAS;YACb,eAAe,EAAE,IAAI,CAAC,eAAe;SACtC,CAAC,CAAC;IACL,CAAC;CACF;AAtFD,wDAsFC","sourcesContent":["import { Connection, Keypair, PublicKey, Transaction } from \"@solana/web3.js\";\nimport { Auth, type AuthCredentials } from \"./auth\";\nimport type { ClientContext } from \"./context\";\nimport { signAndSubmitTx as signAndSubmitTxFn } 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 { DepositSource } from \"./shared\";\nimport { type ExternalSigner, type SigningStrategy } from \"./shared/signing\";\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 depositSourceValue: DepositSource;\n private signingStrategyValue?: SigningStrategy;\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 depositSource?: DepositSource;\n signingStrategy?: SigningStrategy;\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.depositSourceValue = params.depositSource ?? DepositSource.Global;\n this.signingStrategyValue = params.signingStrategy;\n this.wsConfigValue = params.wsConfig;\n this.authStateStore =\n params.authState ??\n new AuthState(params.authCredentials);\n }\n\n // ── Deposit source ──────────────────────────────────────────────────\n\n get depositSource(): DepositSource {\n return this.depositSourceValue;\n }\n\n setDepositSource(source: DepositSource): void {\n this.depositSourceValue = source;\n }\n\n // ── Signing strategy ────────────────────────────────────────────────\n\n get signingStrategy(): SigningStrategy | undefined {\n return this.signingStrategyValue;\n }\n\n setSigningStrategy(strategy: SigningStrategy): void {\n this.signingStrategyValue = strategy;\n }\n\n clearSigningStrategy(): void {\n this.signingStrategyValue = undefined;\n }\n\n // ── Transaction signing + submission ────────────────────────────────\n\n async signAndSubmitTx(tx: Transaction): Promise<string> {\n return signAndSubmitTxFn(this, tx);\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 depositSource: this.depositSourceValue,\n signingStrategy: this.signingStrategyValue,\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 depositSourceValue: DepositSource = DepositSource.Global;\n private signingStrategyValue?: SigningStrategy;\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 depositSource(source: DepositSource): LightconeClientBuilder {\n this.depositSourceValue = source;\n return this;\n }\n\n nativeSigner(keypair: Keypair): LightconeClientBuilder {\n this.signingStrategyValue = { type: \"native\", keypair };\n return this;\n }\n\n externalSigner(signer: ExternalSigner): LightconeClientBuilder {\n this.signingStrategyValue = { type: \"walletAdapter\", signer };\n return this;\n }\n\n privyWalletId(walletId: string): LightconeClientBuilder {\n this.signingStrategyValue = { type: \"privy\", walletId };\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 depositSource: this.depositSourceValue,\n signingStrategy: this.signingStrategyValue,\n connection: this.rpcUrlValue\n ? new Connection(this.rpcUrlValue)\n : undefined,\n authCredentials: this.authCredentials,\n });\n }\n}\n"]}
package/dist/context.d.ts CHANGED
@@ -1,9 +1,16 @@
1
1
  import type { Connection, PublicKey } from "@solana/web3.js";
2
2
  import type { LightconeHttp } from "./http";
3
+ import type { DepositSource } from "./shared";
4
+ import type { SigningStrategy } from "./shared/signing";
3
5
  export interface ClientContext {
4
6
  readonly http: LightconeHttp;
5
7
  readonly programId: PublicKey;
6
8
  readonly connection?: Connection;
9
+ readonly depositSource: DepositSource;
10
+ readonly signingStrategy?: SigningStrategy;
7
11
  }
8
12
  export declare function requireConnection(ctx: ClientContext): Connection;
13
+ export declare function resolveDepositSource(ctx: ClientContext, overrideSource: DepositSource | undefined): DepositSource;
14
+ export declare function requireSigningStrategy(ctx: ClientContext): SigningStrategy;
15
+ export declare function signAndSubmitTx(ctx: ClientContext, tx: import("@solana/web3.js").Transaction): Promise<string>;
9
16
  //# sourceMappingURL=context.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAA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GACxC,OAAO,CAAC,MAAM,CAAC,CAsCjB"}
package/dist/context.js CHANGED
@@ -1,10 +1,89 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  Object.defineProperty(exports, "__esModule", { value: true });
3
36
  exports.requireConnection = requireConnection;
37
+ exports.resolveDepositSource = resolveDepositSource;
38
+ exports.requireSigningStrategy = requireSigningStrategy;
39
+ exports.signAndSubmitTx = signAndSubmitTx;
4
40
  function requireConnection(ctx) {
5
41
  if (!ctx.connection) {
6
42
  throw new Error("RPC client not configured — use .rpcUrl() on the builder");
7
43
  }
8
44
  return ctx.connection;
9
45
  }
46
+ function resolveDepositSource(ctx, overrideSource) {
47
+ return overrideSource ?? ctx.depositSource;
48
+ }
49
+ function requireSigningStrategy(ctx) {
50
+ if (!ctx.signingStrategy) {
51
+ throw new Error("Signing strategy not configured — use .nativeSigner(), .externalSigner(), or .privyWalletId() on the builder");
52
+ }
53
+ return ctx.signingStrategy;
54
+ }
55
+ async function signAndSubmitTx(ctx, tx) {
56
+ const { isUserCancellation } = await Promise.resolve().then(() => __importStar(require("./shared/signing")));
57
+ const { SdkError } = await Promise.resolve().then(() => __importStar(require("./error")));
58
+ const { RetryPolicy } = await Promise.resolve().then(() => __importStar(require("./http")));
59
+ const strategy = requireSigningStrategy(ctx);
60
+ const connection = requireConnection(ctx);
61
+ const { blockhash } = await connection.getLatestBlockhash();
62
+ tx.recentBlockhash = blockhash;
63
+ switch (strategy.type) {
64
+ case "native": {
65
+ tx.partialSign(strategy.keypair);
66
+ return connection.sendRawTransaction(tx.serialize());
67
+ }
68
+ case "walletAdapter": {
69
+ const txBytes = tx.serialize({ requireAllSignatures: false });
70
+ const signedBytes = await strategy.signer
71
+ .signTransaction(txBytes)
72
+ .catch((err) => {
73
+ const msg = err instanceof Error ? err.message : String(err);
74
+ if (isUserCancellation(msg))
75
+ throw SdkError.userCancelled();
76
+ throw SdkError.signing(msg);
77
+ });
78
+ return connection.sendRawTransaction(signedBytes);
79
+ }
80
+ case "privy": {
81
+ const txBytes = tx.serialize({ requireAllSignatures: false });
82
+ const base64Tx = Buffer.from(txBytes).toString("base64");
83
+ const url = `${ctx.http.baseUrl()}/api/privy/sign_and_send_tx`;
84
+ const result = await ctx.http.post(url, { wallet_id: strategy.walletId, base64_tx: base64Tx }, RetryPolicy.None);
85
+ return result.hash;
86
+ }
87
+ }
88
+ }
10
89
  //# sourceMappingURL=context.js.map
@@ -1 +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"]}
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAaA,8CAOC;AAED,oDAKC;AAED,wDAOC;AAED,0CAyCC;AAlED,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;AAED,SAAgB,oBAAoB,CAClC,GAAkB,EAClB,cAAyC;IAEzC,OAAO,cAAc,IAAI,GAAG,CAAC,aAAa,CAAC;AAC7C,CAAC;AAED,SAAgB,sBAAsB,CAAC,GAAkB;IACvD,IAAI,CAAC,GAAG,CAAC,eAAe,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CACb,8GAA8G,CAC/G,CAAC;IACJ,CAAC;IACD,OAAO,GAAG,CAAC,eAAe,CAAC;AAC7B,CAAC;AAEM,KAAK,UAAU,eAAe,CACnC,GAAkB,EAClB,EAAyC;IAEzC,MAAM,EAAE,kBAAkB,EAAE,GAAG,wDAAa,kBAAkB,GAAC,CAAC;IAChE,MAAM,EAAE,QAAQ,EAAE,GAAG,wDAAa,SAAS,GAAC,CAAC;IAC7C,MAAM,EAAE,WAAW,EAAE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AC,CAAC;YAC9D,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;YACzD,MAAM,GAAG,GAAG,GAAG,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,6BAA6B,CAAC;YAC/D,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,IAAI,CAAC,IAAI,CAChC,GAAG,EACH,EAAE,SAAS,EAAE,QAAQ,CAAC,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,EACrD,WAAW,CAAC,IAAI,CACjB,CAAC;YACF,OAAO,MAAM,CAAC,IAAI,CAAC;QACrB,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import type { Connection, PublicKey } from \"@solana/web3.js\";\nimport type { LightconeHttp } from \"./http\";\nimport type { DepositSource } from \"./shared\";\nimport type { SigningStrategy } from \"./shared/signing\";\n\nexport interface ClientContext {\n readonly http: LightconeHttp;\n readonly programId: PublicKey;\n readonly connection?: Connection;\n readonly depositSource: DepositSource;\n readonly signingStrategy?: SigningStrategy;\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\nexport function resolveDepositSource(\n ctx: ClientContext,\n overrideSource: DepositSource | undefined\n): DepositSource {\n return overrideSource ?? ctx.depositSource;\n}\n\nexport function requireSigningStrategy(ctx: ClientContext): SigningStrategy {\n if (!ctx.signingStrategy) {\n throw new Error(\n \"Signing strategy not configured — use .nativeSigner(), .externalSigner(), or .privyWalletId() on the builder\"\n );\n }\n return ctx.signingStrategy;\n}\n\nexport async function signAndSubmitTx(\n ctx: ClientContext,\n tx: import(\"@solana/web3.js\").Transaction\n): Promise<string> {\n const { isUserCancellation } = await import(\"./shared/signing\");\n const { SdkError } = await import(\"./error\");\n const { RetryPolicy } = await import(\"./http\");\n\n const strategy = requireSigningStrategy(ctx);\n const connection = requireConnection(ctx);\n const { blockhash } = await connection.getLatestBlockhash();\n tx.recentBlockhash = blockhash;\n\n switch (strategy.type) {\n case \"native\": {\n tx.partialSign(strategy.keypair);\n return connection.sendRawTransaction(tx.serialize());\n }\n case \"walletAdapter\": {\n const txBytes = tx.serialize({ requireAllSignatures: false });\n const signedBytes = await strategy.signer\n .signTransaction(txBytes)\n .catch((err: unknown) => {\n const msg = err instanceof Error ? err.message : String(err);\n if (isUserCancellation(msg)) throw SdkError.userCancelled();\n throw SdkError.signing(msg);\n });\n return connection.sendRawTransaction(signedBytes);\n }\n case \"privy\": {\n const txBytes = tx.serialize({ requireAllSignatures: false });\n const base64Tx = Buffer.from(txBytes).toString(\"base64\");\n const url = `${ctx.http.baseUrl()}/api/privy/sign_and_send_tx`;\n const result = await ctx.http.post<{ hash: string }, object>(\n url,\n { wallet_id: strategy.walletId, base64_tx: base64Tx },\n RetryPolicy.None\n );\n return result.hash;\n }\n }\n}\n"]}
@@ -0,0 +1,37 @@
1
+ import { PublicKey, Transaction, type TransactionInstruction } from "@solana/web3.js";
2
+ import type { ClientContext } from "../../context";
3
+ export declare class MintCompleteSetBuilder {
4
+ private readonly client;
5
+ private userValue?;
6
+ private marketValue?;
7
+ private mintValue?;
8
+ private amountValue?;
9
+ private numOutcomesValue?;
10
+ constructor(client: ClientContext);
11
+ user(user: PublicKey): this;
12
+ market(market: PublicKey): this;
13
+ mint(mint: PublicKey): this;
14
+ amount(amount: bigint): this;
15
+ numOutcomes(n: number): this;
16
+ buildIx(): TransactionInstruction;
17
+ buildTx(): Transaction;
18
+ signAndSubmit(): Promise<string>;
19
+ }
20
+ export declare class MergeCompleteSetBuilder {
21
+ private readonly client;
22
+ private userValue?;
23
+ private marketValue?;
24
+ private mintValue?;
25
+ private amountValue?;
26
+ private numOutcomesValue?;
27
+ constructor(client: ClientContext);
28
+ user(user: PublicKey): this;
29
+ market(market: PublicKey): this;
30
+ mint(mint: PublicKey): this;
31
+ amount(amount: bigint): this;
32
+ numOutcomes(n: number): this;
33
+ buildIx(): TransactionInstruction;
34
+ buildTx(): Transaction;
35
+ signAndSubmit(): Promise<string>;
36
+ }
37
+ //# sourceMappingURL=builders.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"builders.d.ts","sourceRoot":"","sources":["../../../src/domain/market/builders.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,KAAK,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACtF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAiBnD,qBAAa,sBAAsB;IACjC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgB;IACvC,OAAO,CAAC,SAAS,CAAC,CAAY;IAC9B,OAAO,CAAC,WAAW,CAAC,CAAY;IAChC,OAAO,CAAC,SAAS,CAAC,CAAY;IAC9B,OAAO,CAAC,WAAW,CAAC,CAAS;IAC7B,OAAO,CAAC,gBAAgB,CAAC,CAAS;gBAEtB,MAAM,EAAE,aAAa;IAIjC,IAAI,CAAC,IAAI,EAAE,SAAS,GAAG,IAAI;IAK3B,MAAM,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI;IAK/B,IAAI,CAAC,IAAI,EAAE,SAAS,GAAG,IAAI;IAK3B,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAK5B,WAAW,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI;IAK5B,OAAO,IAAI,sBAAsB;IAcjC,OAAO,IAAI,WAAW;IAMhB,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;CAIvC;AAID,qBAAa,uBAAuB;IAClC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgB;IACvC,OAAO,CAAC,SAAS,CAAC,CAAY;IAC9B,OAAO,CAAC,WAAW,CAAC,CAAY;IAChC,OAAO,CAAC,SAAS,CAAC,CAAY;IAC9B,OAAO,CAAC,WAAW,CAAC,CAAS;IAC7B,OAAO,CAAC,gBAAgB,CAAC,CA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