@lightconexyz/lightcone-sdk 0.4.0 → 0.4.11
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 +15 -9
- package/dist/client.d.ts +5 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +14 -1
- package/dist/client.js.map +1 -1
- package/dist/context.d.ts +2 -0
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +3 -2
- package/dist/context.js.map +1 -1
- package/dist/domain/market/client.d.ts +2 -9
- package/dist/domain/market/client.d.ts.map +1 -1
- package/dist/domain/market/client.js +2 -27
- package/dist/domain/market/client.js.map +1 -1
- package/dist/domain/market/index.d.ts +0 -1
- package/dist/domain/market/index.d.ts.map +1 -1
- package/dist/domain/market/index.js +0 -1
- package/dist/domain/market/index.js.map +1 -1
- package/dist/domain/order/client.d.ts.map +1 -1
- package/dist/domain/order/client.js +2 -1
- package/dist/domain/order/client.js.map +1 -1
- package/dist/domain/order/index.d.ts +12 -1
- package/dist/domain/order/index.d.ts.map +1 -1
- package/dist/domain/order/index.js +14 -5
- package/dist/domain/order/index.js.map +1 -1
- package/dist/domain/order/wire.d.ts +7 -2
- package/dist/domain/order/wire.d.ts.map +1 -1
- package/dist/domain/order/wire.js +18 -0
- package/dist/domain/order/wire.js.map +1 -1
- package/dist/domain/orderbook/client.d.ts.map +1 -1
- package/dist/domain/orderbook/client.js +2 -1
- package/dist/domain/orderbook/client.js.map +1 -1
- package/dist/domain/position/builders.d.ts +19 -19
- package/dist/domain/position/builders.d.ts.map +1 -1
- package/dist/domain/position/builders.js +63 -4
- package/dist/domain/position/builders.js.map +1 -1
- package/dist/domain/position/client.d.ts +2 -5
- package/dist/domain/position/client.d.ts.map +1 -1
- package/dist/domain/position/client.js +3 -61
- package/dist/domain/position/client.js.map +1 -1
- package/dist/error.d.ts +2 -1
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +8 -0
- package/dist/error.js.map +1 -1
- package/dist/prelude.d.ts +2 -2
- package/dist/prelude.d.ts.map +1 -1
- package/dist/prelude.js +3 -4
- package/dist/prelude.js.map +1 -1
- package/dist/privy/index.d.ts.map +1 -1
- package/dist/privy/index.js +3 -2
- package/dist/privy/index.js.map +1 -1
- package/dist/program/accounts.d.ts.map +1 -1
- package/dist/program/accounts.js +10 -9
- package/dist/program/accounts.js.map +1 -1
- package/dist/program/builder.d.ts.map +1 -1
- package/dist/program/builder.js +5 -4
- package/dist/program/builder.js.map +1 -1
- package/dist/program/envelope.d.ts +5 -0
- package/dist/program/envelope.d.ts.map +1 -1
- package/dist/program/envelope.js +39 -0
- package/dist/program/envelope.js.map +1 -1
- package/dist/program/error.d.ts +17 -2
- package/dist/program/error.d.ts.map +1 -1
- package/dist/program/error.js +46 -5
- package/dist/program/error.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 +5 -5
- package/dist/program/index.js.map +1 -1
- package/dist/program/instructions.d.ts +5 -5
- package/dist/program/instructions.d.ts.map +1 -1
- package/dist/program/instructions.js +19 -18
- package/dist/program/instructions.js.map +1 -1
- package/dist/program/orders.d.ts +3 -1
- package/dist/program/orders.d.ts.map +1 -1
- package/dist/program/orders.js +13 -9
- package/dist/program/orders.js.map +1 -1
- package/dist/program/pda.d.ts.map +1 -1
- package/dist/program/pda.js +2 -1
- package/dist/program/pda.js.map +1 -1
- package/dist/program/types.d.ts +4 -4
- package/dist/program/types.d.ts.map +1 -1
- package/dist/program/types.js.map +1 -1
- package/dist/program/utils.d.ts.map +1 -1
- package/dist/program/utils.js +4 -3
- package/dist/program/utils.js.map +1 -1
- package/dist/rpc.d.ts.map +1 -1
- package/dist/rpc.js +3 -2
- package/dist/rpc.js.map +1 -1
- package/dist/shared/price.d.ts.map +1 -1
- package/dist/shared/price.js +2 -1
- package/dist/shared/price.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 +4 -1
- package/dist/shared/types.js.map +1 -1
- package/dist/ws/index.d.ts.map +1 -1
- package/dist/ws/index.js +6 -5
- package/dist/ws/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/domain/market/builders.d.ts +0 -37
- package/dist/domain/market/builders.d.ts.map +0 -1
- package/dist/domain/market/builders.js +0 -114
- package/dist/domain/market/builders.js.map +0 -1
package/dist/shared/types.js
CHANGED
|
@@ -7,6 +7,7 @@ exports.parseSide = parseSide;
|
|
|
7
7
|
exports.sideLabel = sideLabel;
|
|
8
8
|
exports.resolutionSeconds = resolutionSeconds;
|
|
9
9
|
exports.deriveOrderbookId = deriveOrderbookId;
|
|
10
|
+
const error_1 = require("../error");
|
|
10
11
|
function asOrderBookId(value) {
|
|
11
12
|
return value;
|
|
12
13
|
}
|
|
@@ -23,7 +24,7 @@ function parseSide(value) {
|
|
|
23
24
|
return Side.Bid;
|
|
24
25
|
if (value === "ask" || value === "sell")
|
|
25
26
|
return Side.Ask;
|
|
26
|
-
throw
|
|
27
|
+
throw error_1.SdkError.validation(`Invalid side: ${value}`);
|
|
27
28
|
}
|
|
28
29
|
function sideLabel(side) {
|
|
29
30
|
return side === Side.Bid ? "Buy" : "Sell";
|
|
@@ -42,6 +43,7 @@ var TriggerType;
|
|
|
42
43
|
})(TriggerType || (exports.TriggerType = TriggerType = {}));
|
|
43
44
|
var TriggerStatus;
|
|
44
45
|
(function (TriggerStatus) {
|
|
46
|
+
TriggerStatus["Created"] = "created";
|
|
45
47
|
TriggerStatus["Triggered"] = "triggered";
|
|
46
48
|
TriggerStatus["Failed"] = "failed";
|
|
47
49
|
TriggerStatus["Expired"] = "expired";
|
|
@@ -54,6 +56,7 @@ var OrderUpdateType;
|
|
|
54
56
|
})(OrderUpdateType || (exports.OrderUpdateType = OrderUpdateType = {}));
|
|
55
57
|
var TriggerUpdateType;
|
|
56
58
|
(function (TriggerUpdateType) {
|
|
59
|
+
TriggerUpdateType["Created"] = "CREATED";
|
|
57
60
|
TriggerUpdateType["Triggered"] = "TRIGGERED";
|
|
58
61
|
TriggerUpdateType["Failed"] = "FAILED";
|
|
59
62
|
TriggerUpdateType["Expired"] = "EXPIRED";
|
package/dist/shared/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/shared/types.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/shared/types.ts"],"names":[],"mappings":";;;AAOA,sCAEC;AAED,kCAEC;AAOD,8BAIC;AAED,8BAEC;AAsDD,8CAeC;AAED,8CAEC;AArGD,oCAAoC;AAOpC,SAAgB,aAAa,CAAC,KAAa;IACzC,OAAO,KAAoB,CAAC;AAC9B,CAAC;AAED,SAAgB,WAAW,CAAC,KAAa;IACvC,OAAO,KAAkB,CAAC;AAC5B,CAAC;AAED,IAAY,IAGX;AAHD,WAAY,IAAI;IACd,mBAAW,CAAA;IACX,mBAAW,CAAA;AACb,CAAC,EAHW,IAAI,oBAAJ,IAAI,QAGf;AAED,SAAgB,SAAS,CAAC,KAAa;IACrC,IAAI,KAAK,KAAK,KAAK,IAAI,KAAK,KAAK,KAAK;QAAE,OAAO,IAAI,CAAC,GAAG,CAAC;IACxD,IAAI,KAAK,KAAK,KAAK,IAAI,KAAK,KAAK,MAAM;QAAE,OAAO,IAAI,CAAC,GAAG,CAAC;IACzD,MAAM,gBAAQ,CAAC,UAAU,CAAC,iBAAiB,KAAK,EAAE,CAAC,CAAC;AACtD,CAAC;AAED,SAAgB,SAAS,CAAC,IAAU;IAClC,OAAO,IAAI,KAAK,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC;AAC5C,CAAC;AAED,IAAY,WAKX;AALD,WAAY,WAAW;IACrB,0BAAW,CAAA;IACX,0BAAW,CAAA;IACX,0BAAW,CAAA;IACX,0BAAW,CAAA;AACb,CAAC,EALW,WAAW,2BAAX,WAAW,QAKtB;AAED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K,UAAU,CAAC,QAAQ;YACtB,OAAO,GAAG,CAAC;QACb,KAAK,UAAU,CAAC,KAAK;YACnB,OAAO,IAAI,CAAC;QACd,KAAK,UAAU,CAAC,KAAK;YACnB,OAAO,KAAK,CAAC;QACf,KAAK,UAAU,CAAC,IAAI;YAClB,OAAO,KAAK,CAAC;IACjB,CAAC;AACH,CAAC;AAED,SAAgB,iBAAiB,CAAC,SAAiB,EAAE,UAAkB;IACrE,OAAO,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAiB,CAAC;AAC7E,CAAC","sourcesContent":["import { SdkError } from \"../error\";\n\nexport type Branded<T, Brand extends string> = T & { readonly __brand: Brand };\n\nexport type OrderBookId = Branded<string, \"OrderBookId\">;\nexport type PubkeyStr = Branded<string, \"PubkeyStr\">;\n\nexport function asOrderBookId(value: string): OrderBookId {\n return value as OrderBookId;\n}\n\nexport function asPubkeyStr(value: string): PubkeyStr {\n return value as PubkeyStr;\n}\n\nexport enum Side {\n Bid = \"bid\",\n Ask = \"ask\",\n}\n\nexport function parseSide(value: string): Side {\n if (value === \"bid\" || value === \"buy\") return Side.Bid;\n if (value === \"ask\" || value === \"sell\") return Side.Ask;\n throw SdkError.validation(`Invalid side: ${value}`);\n}\n\nexport function sideLabel(side: Side): \"Buy\" | \"Sell\" {\n return side === Side.Bid ? \"Buy\" : \"Sell\";\n}\n\nexport enum TimeInForce {\n Gtc = \"GTC\",\n Ioc = \"IOC\",\n Fok = \"FOK\",\n Alo = \"ALO\",\n}\n\nexport enum TriggerType {\n TakeProfit = \"TP\",\n StopLoss = \"SL\",\n}\n\nexport enum TriggerStatus {\n Created = \"created\",\n Triggered = \"triggered\",\n Failed = \"failed\",\n Expired = \"expired\",\n}\n\nexport enum OrderUpdateType {\n Placement = \"PLACEMENT\",\n Update = \"UPDATE\",\n Cancellation = \"CANCELLATION\",\n}\n\nexport enum TriggerUpdateType {\n Created = \"CREATED\",\n Triggered = \"TRIGGERED\",\n Failed = \"FAILED\",\n Expired = \"EXPIRED\",\n}\n\nexport enum TriggerResultStatus {\n Filled = \"filled\",\n Accepted = \"accepted\",\n Rejected = \"rejected\",\n}\n\nexport enum DepositSource {\n Global = \"global\",\n Market = \"market\",\n}\n\nexport enum Resolution {\n Minute1 = \"1m\",\n Minute5 = \"5m\",\n Minute15 = \"15m\",\n Hour1 = \"1h\",\n Hour4 = \"4h\",\n Day1 = \"1d\",\n}\n\nexport function resolutionSeconds(resolution: Resolution): number {\n switch (resolution) {\n case Resolution.Minute1:\n return 60;\n case Resolution.Minute5:\n return 300;\n case Resolution.Minute15:\n return 900;\n case Resolution.Hour1:\n return 3600;\n case Resolution.Hour4:\n return 14400;\n case Resolution.Day1:\n return 86400;\n }\n}\n\nexport function deriveOrderbookId(baseToken: string, quoteToken: string): OrderBookId {\n return `${baseToken.slice(0, 8)}_${quoteToken.slice(0, 8)}` as OrderBookId;\n}\n\nexport interface SubmitOrderRequest {\n maker: string;\n nonce: number;\n salt: number;\n market_pubkey: string;\n base_token: string;\n quote_token: string;\n side: number;\n /** u64 amount — validated to fit in Number.MAX_SAFE_INTEGER at construction time */\n amount_in: number;\n /** u64 amount — validated to fit in Number.MAX_SAFE_INTEGER at construction time */\n amount_out: number;\n expiration: number;\n signature: string;\n orderbook_id: string;\n tif?: TimeInForce;\n trigger_price?: number;\n trigger_type?: TriggerType;\n deposit_source?: DepositSource;\n}\n"]}
|
package/dist/ws/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ws/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAA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AU,GAAG,UAAU,CAUlG;AAED,wBAAgB,uBAAuB,CAAC,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,GAAG,UAAU,CASpG;AAED,wBAAgB,eAAe,CAAC,YAAY,EAAE,WAAW,EAAE,GAAG,UAAU,CAQvE;AAED,wBAAgB,iBAAiB,CAAC,YAAY,EAAE,WAAW,EAAE,GAAG,UAAU,CAQzE;AAED,wBAAgB,eAAe,CAAC,YAAY,EAAE,SAAS,GAAG,UAAU,CAQnE;AAED,wBAAgB,iBAAiB,CAAC,YAAY,EAAE,SAAS,GAAG,UAAU,CAQrE;AAED,wBAAgB,qBAAqB,CAAC,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,GAAG,UAAU,CAS9F;AAED,wBAAgB,uBAAuB,CAAC,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,GAAG,UAAU,CAShG;AAeD,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAgBvD"}
|
package/dist/ws/index.js
CHANGED
|
@@ -32,6 +32,7 @@ exports.unsubscribeMarket = unsubscribeMarket;
|
|
|
32
32
|
exports.subscribeDepositPrice = subscribeDepositPrice;
|
|
33
33
|
exports.unsubscribeDepositPrice = unsubscribeDepositPrice;
|
|
34
34
|
exports.parseMessageIn = parseMessageIn;
|
|
35
|
+
const error_1 = require("../error");
|
|
35
36
|
const network_1 = require("../network");
|
|
36
37
|
__exportStar(require("./client.node"), exports);
|
|
37
38
|
__exportStar(require("./subscriptions"), exports);
|
|
@@ -41,7 +42,7 @@ exports.WS_DEFAULT_CONFIG = {
|
|
|
41
42
|
maxReconnectAttempts: 10,
|
|
42
43
|
baseReconnectDelayMs: 1_000,
|
|
43
44
|
pingIntervalMs: 30_000,
|
|
44
|
-
pongTimeoutMs:
|
|
45
|
+
pongTimeoutMs: 10_000,
|
|
45
46
|
};
|
|
46
47
|
var ReadyState;
|
|
47
48
|
(function (ReadyState) {
|
|
@@ -212,17 +213,17 @@ const VALID_MESSAGE_TYPES = new Set([
|
|
|
212
213
|
function parseMessageIn(input) {
|
|
213
214
|
const parsed = JSON.parse(input);
|
|
214
215
|
if (typeof parsed !== "object" || parsed === null || !("type" in parsed)) {
|
|
215
|
-
throw new
|
|
216
|
+
throw new error_1.WsError("ProtocolError", `Invalid WS message: missing "type" field`);
|
|
216
217
|
}
|
|
217
218
|
const obj = parsed;
|
|
218
219
|
if (typeof obj.type !== "string" || !VALID_MESSAGE_TYPES.has(obj.type)) {
|
|
219
|
-
throw new
|
|
220
|
+
throw new error_1.WsError("ProtocolError", `Invalid WS message type: "${String(obj.type)}"`);
|
|
220
221
|
}
|
|
221
222
|
if (!("version" in obj) || typeof obj.version !== "number") {
|
|
222
|
-
throw new
|
|
223
|
+
throw new error_1.WsError("ProtocolError", `Invalid WS message: missing or invalid "version" field`);
|
|
223
224
|
}
|
|
224
225
|
if (!("data" in obj) || typeof obj.data !== "object" || obj.data === null) {
|
|
225
|
-
throw new
|
|
226
|
+
throw new error_1.WsError("ProtocolError", `Invalid WS message: missing or invalid "data" field`);
|
|
226
227
|
}
|
|
227
228
|
return parsed;
|
|
228
229
|
}
|
package/dist/ws/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ws/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAyEA,wCAYC;AAED,oBAEC;AAED,wCAQC;AAED,4CAQC;AAED,0CAQC;AAED,8CAQC;AAED,sCAQC;AAED,0CAQC;AAED,sDAUC;AAED,0DASC;AAED,0CAQC;AAED,8CAQC;AAED,0CAQC;AAED,8CAQC;AAED,sDASC;AAED,0DASC;AAeD,wCAgBC;AApQD,wCAA4C;AAG5C,gDAA8B;AAC9B,kDAAgC;AAgDnB,QAAA,iBAAiB,GAAa;IACzC,GAAG,EAAE,wBAAc;IACnB,SAAS,EAAE,IAAI;IACf,oBAAoB,EAAE,EAAE;IACxB,oBAAoB,EAAE,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AAC,GAAG,CAAC,CAAC;IACpE,CAAC;IACD,IAAI,CAAC,CAAC,SAAS,IAAI,GAAG,CAAC,IAAI,OAAO,GAAG,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;QAC3D,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;IAC5E,CAAC;IACD,IAAI,CAAC,CAAC,MAAM,IAAI,GAAG,CAAC,IAAI,OAAO,GAAG,CAAC,IAAI,KAAK,QAAQ,IAAI,GAAG,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;QAC1E,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;IACzE,CAAC;IACD,OAAO,MAAmB,CAAC;AAC7B,CAAC","sourcesContent":["import type { MarketEvent } from \"../domain/market\";\nimport type { AuthUpdate, UserUpdate } from \"../domain/order\";\nimport type { OrderBook, WsTickerData } from \"../domain/orderbook\";\nimport type { DepositPrice, PriceHistory } from \"../domain/price_history\";\nimport type { WsTrade } from \"../domain/trade\";\nimport { DEFAULT_WS_URL } from \"../network\";\nimport type { OrderBookId, PubkeyStr, Resolution } from \"../shared\";\n\nexport * from \"./client.node\";\nexport * from \"./subscriptions\";\nexport type { IWsClient } from \"./types\";\n\nexport type MessageOut =\n | { method: \"subscribe\"; params: import(\"./subscriptions\").SubscribeParams }\n | { method: \"unsubscribe\"; params: import(\"./subscriptions\").UnsubscribeParams }\n | { method: \"ping\" };\n\nexport type MessageIn =\n | { type: \"book_update\"; version: number; data: OrderBook }\n | { type: \"pong\"; version: number; data: Record<string, never> }\n | { type: \"user\"; version: number; data: UserUpdate }\n | { type: \"error\"; version: number; data: WsError }\n | { type: \"price_history\"; version: number; data: PriceHistory }\n | { type: \"trades\"; version: number; data: WsTrade }\n | { type: \"auth\"; version: number; data: AuthUpdate }\n | { type: \"ticker\"; version: number; data: WsTickerData }\n | { type: \"market\"; version: number; data: MarketEvent }\n | { type: \"deposit_price\"; version: number; data: DepositPrice };\n\nexport type Kind = MessageIn;\n\nexport interface WsError {\n error: string;\n code?: string;\n orderbook_id?: string;\n wallet_address?: string;\n deposit_asset?: string;\n hint?: string;\n details?: string;\n}\n\nexport type WsEvent =\n | { type: \"Message\"; message: MessageIn }\n | { type: \"Connected\" }\n | { type: \"Disconnected\"; code?: number; reason: string }\n | { type: \"Error\"; error: string }\n | { type: \"MaxReconnectReached\" };\n\nexport interface WsConfig {\n url: string;\n reconnect: boolean;\n maxReconnectAttempts: number;\n baseReconnectDelayMs: number;\n pingIntervalMs: number;\n pongTimeoutMs: number;\n}\n\nexport const WS_DEFAULT_CONFIG: WsConfig = {\n url: DEFAULT_WS_URL,\n reconnect: true,\n maxReconnectAttempts: 10,\n baseReconnectDelayMs: 1_000,\n pingIntervalMs: 30_000,\n pongTimeoutMs: 1_000,\n};\n\nexport enum ReadyState {\n Connecting = 0,\n Open = 1,\n Closing = 2,\n Closed = 3,\n}\n\nexport function readyStateFrom(value: number): ReadyState {\n switch (value) {\n case 0:\n return ReadyState.Connecting;\n case 1:\n return ReadyState.Open;\n case 2:\n return ReadyState.Closing;\n case 3:\n default:\n return ReadyState.Closed;\n }\n}\n\nexport function ping(): MessageOut {\n return { method: \"ping\" };\n}\n\nexport function subscribeBooks(orderbookIds: OrderBookId[]): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"book_update\",\n orderbook_ids: orderbookIds,\n },\n };\n}\n\nexport function unsubscribeBooks(orderbookIds: OrderBookId[]): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"book_update\",\n orderbook_ids: orderbookIds,\n },\n };\n}\n\nexport function subscribeTrades(orderbookIds: OrderBookId[]): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"trades\",\n orderbook_ids: orderbookIds,\n },\n };\n}\n\nexport function unsubscribeTrades(orderbookIds: OrderBookId[]): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"trades\",\n orderbook_ids: orderbookIds,\n },\n };\n}\n\nexport function subscribeUser(walletAddress: PubkeyStr): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"user\",\n wallet_address: walletAddress,\n },\n };\n}\n\nexport function unsubscribeUser(walletAddress: PubkeyStr): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"user\",\n wallet_address: walletAddress,\n },\n };\n}\n\nexport function subscribePriceHistory(orderbookId: OrderBookId, resolution: Resolution): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"price_history\",\n orderbook_id: orderbookId,\n resolution,\n include_ohlcv: false,\n },\n };\n}\n\nexport function unsubscribePriceHistory(orderbookId: OrderBookId, resolution: Resolution): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"price_history\",\n orderbook_id: orderbookId,\n resolution,\n },\n };\n}\n\nexport function subscribeTicker(orderbookIds: OrderBookId[]): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"ticker\",\n orderbook_ids: orderbookIds,\n },\n };\n}\n\nexport function unsubscribeTicker(orderbookIds: OrderBookId[]): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"ticker\",\n orderbook_ids: orderbookIds,\n },\n };\n}\n\nexport function subscribeMarket(marketPubkey: PubkeyStr): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"market\",\n market_pubkey: marketPubkey,\n },\n };\n}\n\nexport function unsubscribeMarket(marketPubkey: PubkeyStr): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"market\",\n market_pubkey: marketPubkey,\n },\n };\n}\n\nexport function subscribeDepositPrice(depositAsset: string, resolution: Resolution): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"deposit_price\",\n deposit_asset: depositAsset,\n resolution,\n },\n };\n}\n\nexport function unsubscribeDepositPrice(depositAsset: string, resolution: Resolution): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"deposit_price\",\n deposit_asset: depositAsset,\n resolution,\n },\n };\n}\n\nconst VALID_MESSAGE_TYPES = new Set([\n \"book_update\",\n \"pong\",\n \"user\",\n \"error\",\n \"price_history\",\n \"trades\",\n \"auth\",\n \"ticker\",\n \"market\",\n \"deposit_price\",\n]);\n\nexport function parseMessageIn(input: string): MessageIn {\n const parsed: unknown = JSON.parse(input);\n if (typeof parsed !== \"object\" || parsed === null || !(\"type\" in parsed)) {\n throw new Error(`Invalid WS message: missing \"type\" field`);\n }\n const obj = parsed as Record<string, unknown>;\n if (typeof obj.type !== \"string\" || !VALID_MESSAGE_TYPES.has(obj.type)) {\n throw new Error(`Invalid WS message type: \"${String(obj.type)}\"`);\n }\n if (!(\"version\" in obj) || typeof obj.version !== \"number\") {\n throw new Error(`Invalid WS message: missing or invalid \"version\" field`);\n }\n if (!(\"data\" in obj) || typeof obj.data !== \"object\" || obj.data === null) {\n throw new Error(`Invalid WS message: missing or invalid \"data\" field`);\n }\n return parsed as MessageIn;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ws/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AA0EA,wCAYC;AAED,oBAEC;AAED,wCAQC;AAED,4CAQC;AAED,0CAQC;AAED,8CAQC;AAED,sCAQC;AAED,0CAQC;AAED,sDAUC;AAED,0DASC;AAED,0CAQC;AAED,8CAQC;AAED,0CAQC;AAED,8CAQC;AAED,sDASC;AAED,0DASC;AAeD,wCAgBC;AArQD,oCAAmD;AACnD,wCAA4C;AAG5C,gDAA8B;AAC9B,kDAAgC;AAgDnB,QAAA,iBAAiB,GAAa;IACzC,GAAG,EAAE,wBAAc;IACnB,SAAS,EAAE,IAAI;IACf,oBAAoB,EAAE,EAAE;IACxB,oBAAoB,EAAE,KAAK;IAC3B,cAAc,EAAE,MAAM;IACtB,aAAa,EAAE,MAAM;CACtB,CAAC;AAEF,IAAY,UAKX;AALD,WAAY,UAAU;IACpB,uDAAc,CAAA;IACd,2CAAQ,CAAA;IACR,iDAAW,CAAA;IACX,+CAAU,CAAA;AACZ,CAAC,EALW,UAAU,0BAAV,UAAU,QAKrB;AAED,SAA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G,CAAC;IACD,IAAI,CAAC,CAAC,MAAM,IAAI,GAAG,CAAC,IAAI,OAAO,GAAG,CAAC,IAAI,KAAK,QAAQ,IAAI,GAAG,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;QAC1E,MAAM,IAAI,eAAY,CAAC,eAAe,EAAE,qDAAqD,CAAC,CAAC;IACjG,CAAC;IACD,OAAO,MAAmB,CAAC;AAC7B,CAAC","sourcesContent":["import type { MarketEvent } from \"../domain/market\";\nimport type { AuthUpdate, UserUpdate } from \"../domain/order\";\nimport type { OrderBook, WsTickerData } from \"../domain/orderbook\";\nimport type { DepositPrice, PriceHistory } from \"../domain/price_history\";\nimport type { WsTrade } from \"../domain/trade\";\nimport { WsError as WsErrorClass } from \"../error\";\nimport { DEFAULT_WS_URL } from \"../network\";\nimport type { OrderBookId, PubkeyStr, Resolution } from \"../shared\";\n\nexport * from \"./client.node\";\nexport * from \"./subscriptions\";\nexport type { IWsClient } from \"./types\";\n\nexport type MessageOut =\n | { method: \"subscribe\"; params: import(\"./subscriptions\").SubscribeParams }\n | { method: \"unsubscribe\"; params: import(\"./subscriptions\").UnsubscribeParams }\n | { method: \"ping\" };\n\nexport type MessageIn =\n | { type: \"book_update\"; version: number; data: OrderBook }\n | { type: \"pong\"; version: number; data: Record<string, never> }\n | { type: \"user\"; version: number; data: UserUpdate }\n | { type: \"error\"; version: number; data: WsError }\n | { type: \"price_history\"; version: number; data: PriceHistory }\n | { type: \"trades\"; version: number; data: WsTrade }\n | { type: \"auth\"; version: number; data: AuthUpdate }\n | { type: \"ticker\"; version: number; data: WsTickerData }\n | { type: \"market\"; version: number; data: MarketEvent }\n | { type: \"deposit_price\"; version: number; data: DepositPrice };\n\nexport type Kind = MessageIn;\n\nexport interface WsError {\n error: string;\n code?: string;\n orderbook_id?: string;\n wallet_address?: string;\n deposit_asset?: string;\n hint?: string;\n details?: string;\n}\n\nexport type WsEvent =\n | { type: \"Message\"; message: MessageIn }\n | { type: \"Connected\" }\n | { type: \"Disconnected\"; code?: number; reason: string }\n | { type: \"Error\"; error: string }\n | { type: \"MaxReconnectReached\" };\n\nexport interface WsConfig {\n url: string;\n reconnect: boolean;\n maxReconnectAttempts: number;\n baseReconnectDelayMs: number;\n pingIntervalMs: number;\n pongTimeoutMs: number;\n}\n\nexport const WS_DEFAULT_CONFIG: WsConfig = {\n url: DEFAULT_WS_URL,\n reconnect: true,\n maxReconnectAttempts: 10,\n baseReconnectDelayMs: 1_000,\n pingIntervalMs: 30_000,\n pongTimeoutMs: 10_000,\n};\n\nexport enum ReadyState {\n Connecting = 0,\n Open = 1,\n Closing = 2,\n Closed = 3,\n}\n\nexport function readyStateFrom(value: number): ReadyState {\n switch (value) {\n case 0:\n return ReadyState.Connecting;\n case 1:\n return ReadyState.Open;\n case 2:\n return ReadyState.Closing;\n case 3:\n default:\n return ReadyState.Closed;\n }\n}\n\nexport function ping(): MessageOut {\n return { method: \"ping\" };\n}\n\nexport function subscribeBooks(orderbookIds: OrderBookId[]): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"book_update\",\n orderbook_ids: orderbookIds,\n },\n };\n}\n\nexport function unsubscribeBooks(orderbookIds: OrderBookId[]): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"book_update\",\n orderbook_ids: orderbookIds,\n },\n };\n}\n\nexport function subscribeTrades(orderbookIds: OrderBookId[]): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"trades\",\n orderbook_ids: orderbookIds,\n },\n };\n}\n\nexport function unsubscribeTrades(orderbookIds: OrderBookId[]): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"trades\",\n orderbook_ids: orderbookIds,\n },\n };\n}\n\nexport function subscribeUser(walletAddress: PubkeyStr): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"user\",\n wallet_address: walletAddress,\n },\n };\n}\n\nexport function unsubscribeUser(walletAddress: PubkeyStr): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"user\",\n wallet_address: walletAddress,\n },\n };\n}\n\nexport function subscribePriceHistory(orderbookId: OrderBookId, resolution: Resolution): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"price_history\",\n orderbook_id: orderbookId,\n resolution,\n include_ohlcv: false,\n },\n };\n}\n\nexport function unsubscribePriceHistory(orderbookId: OrderBookId, resolution: Resolution): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"price_history\",\n orderbook_id: orderbookId,\n resolution,\n },\n };\n}\n\nexport function subscribeTicker(orderbookIds: OrderBookId[]): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"ticker\",\n orderbook_ids: orderbookIds,\n },\n };\n}\n\nexport function unsubscribeTicker(orderbookIds: OrderBookId[]): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"ticker\",\n orderbook_ids: orderbookIds,\n },\n };\n}\n\nexport function subscribeMarket(marketPubkey: PubkeyStr): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"market\",\n market_pubkey: marketPubkey,\n },\n };\n}\n\nexport function unsubscribeMarket(marketPubkey: PubkeyStr): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"market\",\n market_pubkey: marketPubkey,\n },\n };\n}\n\nexport function subscribeDepositPrice(depositAsset: string, resolution: Resolution): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"deposit_price\",\n deposit_asset: depositAsset,\n resolution,\n },\n };\n}\n\nexport function unsubscribeDepositPrice(depositAsset: string, resolution: Resolution): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"deposit_price\",\n deposit_asset: depositAsset,\n resolution,\n },\n };\n}\n\nconst VALID_MESSAGE_TYPES = new Set([\n \"book_update\",\n \"pong\",\n \"user\",\n \"error\",\n \"price_history\",\n \"trades\",\n \"auth\",\n \"ticker\",\n \"market\",\n \"deposit_price\",\n]);\n\nexport function parseMessageIn(input: string): MessageIn {\n const parsed: unknown = JSON.parse(input);\n if (typeof parsed !== \"object\" || parsed === null || !(\"type\" in parsed)) {\n throw new WsErrorClass(\"ProtocolError\", `Invalid WS message: missing \"type\" field`);\n }\n const obj = parsed as Record<string, unknown>;\n if (typeof obj.type !== \"string\" || !VALID_MESSAGE_TYPES.has(obj.type)) {\n throw new WsErrorClass(\"ProtocolError\", `Invalid WS message type: \"${String(obj.type)}\"`);\n }\n if (!(\"version\" in obj) || typeof obj.version !== \"number\") {\n throw new WsErrorClass(\"ProtocolError\", `Invalid WS message: missing or invalid \"version\" field`);\n }\n if (!(\"data\" in obj) || typeof obj.data !== \"object\" || obj.data === null) {\n throw new WsErrorClass(\"ProtocolError\", `Invalid WS message: missing or invalid \"data\" field`);\n }\n return parsed as MessageIn;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,37 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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,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"}
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MergeCompleteSetBuilder = exports.MintCompleteSetBuilder = void 0;
|
|
4
|
-
const web3_js_1 = require("@solana/web3.js");
|
|
5
|
-
const context_1 = require("../../context");
|
|
6
|
-
const error_1 = require("../../error");
|
|
7
|
-
const instructions_1 = require("../../program/instructions");
|
|
8
|
-
function requireField(value, field) {
|
|
9
|
-
if (value === undefined) {
|
|
10
|
-
throw error_1.SdkError.validation(`${field} is required`);
|
|
11
|
-
}
|
|
12
|
-
return value;
|
|
13
|
-
}
|
|
14
|
-
// ─── MintCompleteSetBuilder ─────────────────────────────────────────────────
|
|
15
|
-
class MintCompleteSetBuilder {
|
|
16
|
-
client;
|
|
17
|
-
userValue;
|
|
18
|
-
marketValue;
|
|
19
|
-
mintValue;
|
|
20
|
-
amountValue;
|
|
21
|
-
numOutcomesValue;
|
|
22
|
-
constructor(client) {
|
|
23
|
-
this.client = client;
|
|
24
|
-
}
|
|
25
|
-
user(user) {
|
|
26
|
-
this.userValue = user;
|
|
27
|
-
return this;
|
|
28
|
-
}
|
|
29
|
-
market(market) {
|
|
30
|
-
this.marketValue = market;
|
|
31
|
-
return this;
|
|
32
|
-
}
|
|
33
|
-
mint(mint) {
|
|
34
|
-
this.mintValue = mint;
|
|
35
|
-
return this;
|
|
36
|
-
}
|
|
37
|
-
amount(amount) {
|
|
38
|
-
this.amountValue = amount;
|
|
39
|
-
return this;
|
|
40
|
-
}
|
|
41
|
-
numOutcomes(n) {
|
|
42
|
-
this.numOutcomesValue = n;
|
|
43
|
-
return this;
|
|
44
|
-
}
|
|
45
|
-
buildIx() {
|
|
46
|
-
const user = requireField(this.userValue, "user");
|
|
47
|
-
const market = requireField(this.marketValue, "market");
|
|
48
|
-
const depositMint = requireField(this.mintValue, "mint");
|
|
49
|
-
const amount = requireField(this.amountValue, "amount");
|
|
50
|
-
const numOutcomes = requireField(this.numOutcomesValue, "num_outcomes");
|
|
51
|
-
return (0, instructions_1.buildMintCompleteSetIx)({ user, market, depositMint, amount }, numOutcomes, this.client.programId);
|
|
52
|
-
}
|
|
53
|
-
buildTx() {
|
|
54
|
-
const user = requireField(this.userValue, "user");
|
|
55
|
-
const ix = this.buildIx();
|
|
56
|
-
return new web3_js_1.Transaction({ feePayer: user }).add(ix);
|
|
57
|
-
}
|
|
58
|
-
async signAndSubmit() {
|
|
59
|
-
const tx = this.buildTx();
|
|
60
|
-
return (0, context_1.signAndSubmitTx)(this.client, tx);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
exports.MintCompleteSetBuilder = MintCompleteSetBuilder;
|
|
64
|
-
// ─── MergeCompleteSetBuilder ────────────────────────────────────────────────
|
|
65
|
-
class MergeCompleteSetBuilder {
|
|
66
|
-
client;
|
|
67
|
-
userValue;
|
|
68
|
-
marketValue;
|
|
69
|
-
mintValue;
|
|
70
|
-
amountValue;
|
|
71
|
-
numOutcomesValue;
|
|
72
|
-
constructor(client) {
|
|
73
|
-
this.client = client;
|
|
74
|
-
}
|
|
75
|
-
user(user) {
|
|
76
|
-
this.userValue = user;
|
|
77
|
-
return this;
|
|
78
|
-
}
|
|
79
|
-
market(market) {
|
|
80
|
-
this.marketValue = market;
|
|
81
|
-
return this;
|
|
82
|
-
}
|
|
83
|
-
mint(mint) {
|
|
84
|
-
this.mintValue = mint;
|
|
85
|
-
return this;
|
|
86
|
-
}
|
|
87
|
-
amount(amount) {
|
|
88
|
-
this.amountValue = amount;
|
|
89
|
-
return this;
|
|
90
|
-
}
|
|
91
|
-
numOutcomes(n) {
|
|
92
|
-
this.numOutcomesValue = n;
|
|
93
|
-
return this;
|
|
94
|
-
}
|
|
95
|
-
buildIx() {
|
|
96
|
-
const user = requireField(this.userValue, "user");
|
|
97
|
-
const market = requireField(this.marketValue, "market");
|
|
98
|
-
const depositMint = requireField(this.mintValue, "mint");
|
|
99
|
-
const amount = requireField(this.amountValue, "amount");
|
|
100
|
-
const numOutcomes = requireField(this.numOutcomesValue, "num_outcomes");
|
|
101
|
-
return (0, instructions_1.buildMergeCompleteSetIx)({ user, market, depositMint, amount }, numOutcomes, this.client.programId);
|
|
102
|
-
}
|
|
103
|
-
buildTx() {
|
|
104
|
-
const user = requireField(this.userValue, "user");
|
|
105
|
-
const ix = this.buildIx();
|
|
106
|
-
return new web3_js_1.Transaction({ feePayer: user }).add(ix);
|
|
107
|
-
}
|
|
108
|
-
async signAndSubmit() {
|
|
109
|
-
const tx = this.buildTx();
|
|
110
|
-
return (0, context_1.signAndSubmitTx)(this.client, tx);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
exports.MergeCompleteSetBuilder = MergeCompleteSetBuilder;
|
|
114
|
-
//# sourceMappingURL=builders.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"builders.js","sourceRoot":"","sources":["../../../src/domain/market/builders.ts"],"names":[],"mappings":";;;AAAA,6CAAsF;AAEtF,2CAAgD;AAChD,uCAAuC;AACvC,6DAGoC;AAEpC,SAAS,YAAY,CAAI,KAAoB,EAAE,KAAa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ClientContext } from \"../../context\";\nimport { signAndSubmitTx } from \"../../context\";\nimport { SdkError } from \"../../error\";\nimport {\n buildMintCompleteSetIx,\n buildMergeCompleteSetIx,\n} from \"../../program/instructions\";\n\nfunction requireField<T>(value: T | undefined, field: string): T {\n if (value === undefined) {\n throw SdkError.validation(`${field} is required`);\n }\n return value;\n}\n\n// ─── MintCompleteSetBuilder ─────────────────────────────────────────────────\n\nexport class MintCompleteSetBuilder {\n private readonly client: ClientContext;\n private userValue?: PublicKey;\n private marketValue?: PublicKey;\n private mintValue?: PublicKey;\n private amountValue?: bigint;\n private numOutcomesValue?: number;\n\n constructor(client: ClientContext) {\n this.client = client;\n }\n\n user(user: PublicKey): this {\n this.userValue = user;\n return this;\n }\n\n market(market: PublicKey): this {\n this.marketValue = market;\n return this;\n }\n\n mint(mint: PublicKey): this {\n this.mintValue = mint;\n return this;\n }\n\n amount(amount: bigint): this {\n this.amountValue = amount;\n return this;\n }\n\n numOutcomes(n: number): this {\n this.numOutcomesValue = n;\n return this;\n }\n\n buildIx(): TransactionInstruction {\n const user = requireField(this.userValue, \"user\");\n const market = requireField(this.marketValue, \"market\");\n const depositMint = requireField(this.mintValue, \"mint\");\n const amount = requireField(this.amountValue, \"amount\");\n const numOutcomes = requireField(this.numOutcomesValue, \"num_outcomes\");\n\n return buildMintCompleteSetIx(\n { user, market, depositMint, amount },\n numOutcomes,\n this.client.programId,\n );\n }\n\n buildTx(): Transaction {\n const user = requireField(this.userValue, \"user\");\n const ix = this.buildIx();\n return new Transaction({ feePayer: user }).add(ix);\n }\n\n async signAndSubmit(): Promise<string> {\n const tx = this.buildTx();\n return signAndSubmitTx(this.client, tx);\n }\n}\n\n// ─── MergeCompleteSetBuilder ────────────────────────────────────────────────\n\nexport class MergeCompleteSetBuilder {\n private readonly client: ClientContext;\n private userValue?: PublicKey;\n private marketValue?: PublicKey;\n private mintValue?: PublicKey;\n private amountValue?: bigint;\n private numOutcomesValue?: number;\n\n constructor(client: ClientContext) {\n this.client = client;\n }\n\n user(user: PublicKey): this {\n this.userValue = user;\n return this;\n }\n\n market(market: PublicKey): this {\n this.marketValue = market;\n return this;\n }\n\n mint(mint: PublicKey): this {\n this.mintValue = mint;\n return this;\n }\n\n amount(amount: bigint): this {\n this.amountValue = amount;\n return this;\n }\n\n numOutcomes(n: number): this {\n this.numOutcomesValue = n;\n return this;\n }\n\n buildIx(): TransactionInstruction {\n const user = requireField(this.userValue, \"user\");\n const market = requireField(this.marketValue, \"market\");\n const depositMint = requireField(this.mintValue, \"mint\");\n const amount = requireField(this.amountValue, \"amount\");\n const numOutcomes = requireField(this.numOutcomesValue, \"num_outcomes\");\n\n return buildMergeCompleteSetIx(\n { user, market, depositMint, amount },\n numOutcomes,\n this.client.programId,\n );\n }\n\n buildTx(): Transaction {\n const user = requireField(this.userValue, \"user\");\n const ix = this.buildIx();\n return new Transaction({ feePayer: user }).add(ix);\n }\n\n async signAndSubmit(): Promise<string> {\n const tx = this.buildTx();\n return signAndSubmitTx(this.client, tx);\n }\n}\n"]}
|