@lightconexyz/lightcone-sdk 0.7.1 → 0.8.1-rc.3
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 +20 -0
- package/dist/auth/client.d.ts +3 -3
- package/dist/auth/client.d.ts.map +1 -1
- package/dist/auth/client.js +19 -38
- package/dist/auth/client.js.map +1 -1
- package/dist/auth/index.d.ts +95 -54
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/index.js +82 -7
- package/dist/auth/index.js.map +1 -1
- package/dist/client.d.ts +0 -2
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +0 -4
- package/dist/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/tokens.d.ts +2 -0
- package/dist/domain/market/tokens.d.ts.map +1 -1
- package/dist/domain/market/tokens.js +8 -0
- package/dist/domain/market/tokens.js.map +1 -1
- package/dist/domain/market/wire.d.ts +1 -0
- package/dist/domain/market/wire.d.ts.map +1 -1
- package/dist/domain/market/wire.js.map +1 -1
- package/dist/domain/metrics/client.d.ts +8 -2
- package/dist/domain/metrics/client.d.ts.map +1 -1
- package/dist/domain/metrics/client.js +48 -1
- package/dist/domain/metrics/client.js.map +1 -1
- package/dist/domain/metrics/wire.d.ts +107 -4
- package/dist/domain/metrics/wire.d.ts.map +1 -1
- package/dist/domain/metrics/wire.js.map +1 -1
- package/dist/domain/order/client.d.ts +4 -2
- package/dist/domain/order/client.d.ts.map +1 -1
- package/dist/domain/order/client.js.map +1 -1
- package/dist/domain/order/wire.d.ts +41 -24
- package/dist/domain/order/wire.d.ts.map +1 -1
- package/dist/domain/order/wire.js +46 -18
- package/dist/domain/order/wire.js.map +1 -1
- package/dist/domain/orderbook/aggregation.d.ts +50 -0
- package/dist/domain/orderbook/aggregation.d.ts.map +1 -0
- package/dist/domain/orderbook/aggregation.js +85 -0
- package/dist/domain/orderbook/aggregation.js.map +1 -0
- package/dist/domain/orderbook/client.d.ts +11 -1
- package/dist/domain/orderbook/client.d.ts.map +1 -1
- package/dist/domain/orderbook/client.js +24 -3
- package/dist/domain/orderbook/client.js.map +1 -1
- package/dist/domain/orderbook/index.d.ts +1 -0
- package/dist/domain/orderbook/index.d.ts.map +1 -1
- package/dist/domain/orderbook/index.js +1 -0
- package/dist/domain/orderbook/index.js.map +1 -1
- package/dist/domain/orderbook/state.d.ts +29 -31
- package/dist/domain/orderbook/state.d.ts.map +1 -1
- package/dist/domain/orderbook/state.js +20 -67
- package/dist/domain/orderbook/state.js.map +1 -1
- package/dist/domain/orderbook/wire.d.ts +32 -0
- package/dist/domain/orderbook/wire.d.ts.map +1 -1
- package/dist/domain/orderbook/wire.js.map +1 -1
- package/dist/env.d.ts +18 -3
- package/dist/env.d.ts.map +1 -1
- package/dist/env.js +28 -4
- package/dist/env.js.map +1 -1
- package/dist/http/client.d.ts +1 -4
- package/dist/http/client.d.ts.map +1 -1
- package/dist/http/client.js +56 -22
- package/dist/http/client.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -1
- package/dist/index.js.map +1 -1
- package/dist/prelude.d.ts +9 -8
- package/dist/prelude.d.ts.map +1 -1
- package/dist/prelude.js +20 -4
- package/dist/prelude.js.map +1 -1
- package/dist/shared/fmt/index.d.ts +1 -0
- package/dist/shared/fmt/index.d.ts.map +1 -1
- package/dist/shared/fmt/index.js +2 -1
- package/dist/shared/fmt/index.js.map +1 -1
- package/dist/shared/fmt/str.d.ts +8 -0
- package/dist/shared/fmt/str.d.ts.map +1 -0
- package/dist/shared/fmt/str.js +17 -0
- package/dist/shared/fmt/str.js.map +1 -0
- package/dist/shared/index.d.ts +1 -1
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/index.js +11 -1
- package/dist/shared/index.js.map +1 -1
- package/dist/shared/rejection.d.ts.map +1 -1
- package/dist/shared/rejection.js +11 -0
- package/dist/shared/rejection.js.map +1 -1
- package/dist/shared/types.d.ts +41 -0
- package/dist/shared/types.d.ts.map +1 -1
- package/dist/shared/types.js +85 -1
- package/dist/shared/types.js.map +1 -1
- package/dist/ws/index.d.ts +25 -2
- package/dist/ws/index.d.ts.map +1 -1
- package/dist/ws/index.js +23 -2
- package/dist/ws/index.js.map +1 -1
- package/dist/ws/subscriptions.d.ts +12 -0
- package/dist/ws/subscriptions.d.ts.map +1 -1
- package/dist/ws/subscriptions.js +14 -4
- package/dist/ws/subscriptions.js.map +1 -1
- package/package.json +1 -1
- package/dist/domain/admin/client.d.ts +0 -63
- package/dist/domain/admin/client.d.ts.map +0 -1
- package/dist/domain/admin/client.js +0 -234
- package/dist/domain/admin/client.js.map +0 -1
- package/dist/domain/admin/index.d.ts +0 -16
- package/dist/domain/admin/index.d.ts.map +0 -1
- package/dist/domain/admin/index.js +0 -19
- package/dist/domain/admin/index.js.map +0 -1
- package/dist/domain/admin/wire.d.ts +0 -450
- package/dist/domain/admin/wire.d.ts.map +0 -1
- package/dist/domain/admin/wire.js +0 -3
- package/dist/domain/admin/wire.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wire.d.ts","sourceRoot":"","sources":["../../../src/domain/order/wire.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,WAAW,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACrE,OAAO,KAAK,EACV,WAAW,EACX,eAAe,EACf,SAAS,EACT,IAAI,EACJ,mBAAmB,EACnB,aAAa,EACb,iBAAiB,EAClB,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEzD,MAAM,WAAW,kBAAkB;IACjC,aAAa,EAAE,MAAM,CAAC;IACtB,
|
|
1
|
+
{"version":3,"file":"wire.d.ts","s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GAC7B;IACD,WAAW,EAAE,SAAS,CAAC;IACvB,MAAM,EAAE,iBAAiB,EAAE,CAAC;IAC5B,eAAe,EAAE,iBAAiB,EAAE,CAAC;IACrC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,OAAO,CAAC;CACnB,CAWA;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,aAAa,GAAG,UAAU,CAuDlE"}
|
|
@@ -4,7 +4,9 @@ exports.triggerUpdateToTriggerOrder = triggerUpdateToTriggerOrder;
|
|
|
4
4
|
exports.normalizeConditionalBalance = normalizeConditionalBalance;
|
|
5
5
|
exports.normalizeOrderUpdate = normalizeOrderUpdate;
|
|
6
6
|
exports.normalizeUserSnapshotOrder = normalizeUserSnapshotOrder;
|
|
7
|
-
exports.
|
|
7
|
+
exports.normalizeUserOutcomeBalance = normalizeUserOutcomeBalance;
|
|
8
|
+
exports.normalizeUserDepositAssetBalance = normalizeUserDepositAssetBalance;
|
|
9
|
+
exports.normalizeUserMarketBalance = normalizeUserMarketBalance;
|
|
8
10
|
exports.normalizeUserOrdersPayload = normalizeUserOrdersPayload;
|
|
9
11
|
exports.normalizeUserUpdate = normalizeUserUpdate;
|
|
10
12
|
const shared_1 = require("../../shared");
|
|
@@ -25,13 +27,12 @@ function triggerUpdateToTriggerOrder(update) {
|
|
|
25
27
|
};
|
|
26
28
|
}
|
|
27
29
|
function normalizeConditionalBalance(balance) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
throw new Error("Invalid conditional balance: missing mint");
|
|
30
|
+
if (!balance.conditional_token) {
|
|
31
|
+
throw new Error("Invalid conditional balance: missing conditional_token");
|
|
31
32
|
}
|
|
32
33
|
return {
|
|
33
34
|
outcome_index: balance.outcome_index,
|
|
34
|
-
|
|
35
|
+
conditional_token: (0, shared_1.asPubkeyStr)(balance.conditional_token),
|
|
35
36
|
idle: balance.idle,
|
|
36
37
|
on_book: balance.on_book,
|
|
37
38
|
};
|
|
@@ -92,23 +93,47 @@ function normalizeUserSnapshotOrder(order) {
|
|
|
92
93
|
const rawOrderType = order.order_type;
|
|
93
94
|
throw new Error(`Invalid user snapshot order: unsupported order_type "${rawOrderType}"`);
|
|
94
95
|
}
|
|
95
|
-
function
|
|
96
|
+
function requireArray(value, context) {
|
|
97
|
+
if (!Array.isArray(value)) {
|
|
98
|
+
throw new Error(`Invalid ${context}: expected array`);
|
|
99
|
+
}
|
|
100
|
+
return value;
|
|
101
|
+
}
|
|
102
|
+
function normalizeUserOutcomeBalance(balance) {
|
|
103
|
+
if (!balance.conditional_token) {
|
|
104
|
+
throw new Error("Invalid user outcome balance: missing conditional_token");
|
|
105
|
+
}
|
|
96
106
|
return {
|
|
97
|
-
|
|
98
|
-
|
|
107
|
+
outcome_index: balance.outcome_index,
|
|
108
|
+
conditional_token: (0, shared_1.asPubkeyStr)(balance.conditional_token),
|
|
109
|
+
balance: balance.balance,
|
|
110
|
+
balance_idle: balance.balance_idle,
|
|
111
|
+
balance_on_book: balance.balance_on_book,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
function normalizeUserDepositAssetBalance(balance) {
|
|
115
|
+
if (!balance.deposit_asset) {
|
|
116
|
+
throw new Error("Invalid user deposit asset balance: missing deposit_asset");
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
deposit_asset: (0, shared_1.asPubkeyStr)(balance.deposit_asset),
|
|
120
|
+
outcomes: requireArray(balance.outcomes, "user deposit asset balance outcomes").map(normalizeUserOutcomeBalance),
|
|
99
121
|
};
|
|
100
122
|
}
|
|
101
|
-
function
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
123
|
+
function normalizeUserMarketBalance(balance) {
|
|
124
|
+
if (!balance.market_pubkey) {
|
|
125
|
+
throw new Error("Invalid user market balance: missing market_pubkey");
|
|
126
|
+
}
|
|
127
|
+
return {
|
|
128
|
+
market_pubkey: (0, shared_1.asPubkeyStr)(balance.market_pubkey),
|
|
129
|
+
deposit_assets: requireArray(balance.deposit_assets, "user market balance deposit_assets").map(normalizeUserDepositAssetBalance),
|
|
130
|
+
};
|
|
106
131
|
}
|
|
107
132
|
function normalizeUserOrdersPayload(response) {
|
|
108
133
|
return {
|
|
109
134
|
user_pubkey: response.user_pubkey,
|
|
110
135
|
orders: (response.orders ?? []).map(normalizeUserSnapshotOrder),
|
|
111
|
-
|
|
136
|
+
market_balances: requireArray(response.market_balances, "user orders response market_balances").map(normalizeUserMarketBalance),
|
|
112
137
|
next_cursor: response.next_cursor ?? undefined,
|
|
113
138
|
has_more: response.has_more ?? false,
|
|
114
139
|
};
|
|
@@ -120,7 +145,7 @@ function normalizeUserUpdate(raw) {
|
|
|
120
145
|
...raw,
|
|
121
146
|
event_type: "snapshot",
|
|
122
147
|
orders: raw.orders.map(normalizeUserSnapshotOrder),
|
|
123
|
-
|
|
148
|
+
market_balances: requireArray(raw.market_balances, "user snapshot market_balances").map(normalizeUserMarketBalance),
|
|
124
149
|
global_deposits: raw.global_deposits ?? [],
|
|
125
150
|
notifications: raw.notifications ?? [],
|
|
126
151
|
nonce: raw.nonce ?? 0,
|
|
@@ -141,11 +166,12 @@ function normalizeUserUpdate(raw) {
|
|
|
141
166
|
};
|
|
142
167
|
}
|
|
143
168
|
throw new Error(`Invalid user order event: unsupported order_type "${raw.order_type}"`);
|
|
144
|
-
case "
|
|
169
|
+
case "market_balance_update":
|
|
145
170
|
return {
|
|
146
171
|
...raw,
|
|
147
|
-
event_type: "
|
|
148
|
-
|
|
172
|
+
event_type: "market_balance_update",
|
|
173
|
+
market_pubkey: (0, shared_1.asPubkeyStr)(raw.market_pubkey),
|
|
174
|
+
market_balance: normalizeUserMarketBalance(raw.market_balance),
|
|
149
175
|
};
|
|
150
176
|
case "global_deposit_update":
|
|
151
177
|
return raw;
|
|
@@ -157,6 +183,8 @@ function normalizeUserUpdate(raw) {
|
|
|
157
183
|
};
|
|
158
184
|
case "notification":
|
|
159
185
|
return raw;
|
|
186
|
+
default:
|
|
187
|
+
throw new Error(`Invalid user update event_type "${raw.event_type}"`);
|
|
160
188
|
}
|
|
161
189
|
}
|
|
162
190
|
//# sourceMappingURL=wire.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wire.js","sourceRoot":"","sources":["../../../src/domain/order/wire.ts"],"names":[],"mappings":";;AAgIA,kEAeC;AAiID,kEAYC;AAmBD,oDAKC;AAsBD,gEA0BC;AAED,oEAOC;AAaD,gEAgBC;AAED,kDA+CC;AA3bD,yCAAqE;AAgIrE,SAAgB,2BAA2B,CAAC,MAA0B;IACpE,MAAM,WAAW,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,oBAAW,CAAC,UAAU,CAAC,CAAC,CAAC,oBAAW,CAAC,QAAQ,CAAC;IACzF,OAAO;QACL,cAAc,EAAE,MAAM,CAAC,gBAAgB;QACvC,SAAS,EAAE,MAAM,CAAC,UAAU;QAC5B,YAAY,EAAE,MAAM,CAAC,aAAa;QAClC,WAAW,EAAE,MAAM,CAAC,YAAY;QAChC,YAAY,EAAE,MAAM,CAAC,aAAa;QAClC,WAAW;QACX,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,QAAQ,EAAE,MAAM,CAAC,YAAY,IAAI,GAAG;QACpC,SAAS,EAAE,MAAM,CAAC,YAAY,IAAI,GAAG;QACrC,WAAW,EAAE,MAAM,CAAC,GAAG,IAAI,oBAAW,CAAC,GAAG;QAC1C,SAAS,EAAE,IAAI,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC;KACtC,CAAC;AACJ,CAAC;AAiID,SAAgB,2BAA2B,CAAC,OAA8B;IACxE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,iBAAiB,CAAC;IACvD,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;IAC/D,CAAC;IAED,OAAO;QACL,aAAa,EAAE,OAAO,CAAC,aAAa;QACpC,IAAI,EAAE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OAAO;gBACL,GAAG,GAAG;gBACN,UAAU,EAAE,OAAO;aACpB,CAAC;QACJ,KAAK,cAAc;YACjB,OAAO,GAAG,CAAC;IACf,CAAC;AACH,CAAC","sourcesContent":["import { asPubkeyStr, TimeInForce, TriggerType } from \"../../shared\";\nimport type {\n OrderBookId,\n OrderUpdateType,\n PubkeyStr,\n Side,\n TriggerResultStatus,\n TriggerStatus,\n TriggerUpdateType,\n} from \"../../shared\";\nimport type { Notification } from \"../notification\";\nimport type { OrderStatus, TriggerOrder } from \"./index\";\n\nexport interface ConditionalBalance {\n outcome_index: number;\n mint: PubkeyStr;\n idle: string;\n on_book: string;\n}\n\nexport interface UserSnapshotBalance {\n market_pubkey: PubkeyStr;\n orderbook_id: OrderBookId;\n outcomes: ConditionalBalance[];\n}\n\nexport interface GlobalDepositBalance {\n mint: PubkeyStr;\n balance: string;\n}\n\nexport interface GlobalDepositUpdate {\n mint: PubkeyStr;\n balance: string;\n timestamp: string;\n}\n\nexport interface NonceUpdate {\n user_pubkey: PubkeyStr;\n new_nonce: number;\n timestamp: string;\n}\n\nexport interface UserOrderUpdateBalance {\n outcomes: ConditionalBalance[];\n}\n\nexport interface WsOrder {\n order_hash: string;\n price: string;\n is_maker: boolean;\n remaining: string;\n filled: string;\n fill_amount: string;\n side: Side;\n created_at: number;\n base_mint: PubkeyStr;\n quote_mint: PubkeyStr;\n outcome_index: number;\n status: OrderStatus;\n balance?: UserOrderUpdateBalance;\n}\n\nexport interface OrderUpdate {\n market_pubkey: PubkeyStr;\n orderbook_id: OrderBookId;\n timestamp: string;\n tx_signature?: string;\n type?: OrderUpdateType;\n order: WsOrder;\n}\n\nexport interface UserSnapshotOrderCommon {\n order_hash: string;\n market_pubkey: PubkeyStr;\n orderbook_id: OrderBookId;\n side: Side;\n amount_in: string;\n amount_out: string;\n remaining: string;\n filled: string;\n price: string;\n created_at: number;\n expiration: number;\n base_mint: PubkeyStr;\n quote_mint: PubkeyStr;\n outcome_index: number;\n status: OrderStatus;\n}\n\nexport type UserSnapshotOrder =\n | ({ order_type: \"limit\"; tx_signature?: string } & UserSnapshotOrderCommon)\n | ({\n order_type: \"trigger\";\n trigger_order_id: string;\n trigger_price: string;\n trigger_type: TriggerType;\n time_in_force?: TimeInForce;\n } & UserSnapshotOrderCommon);\n\nexport interface UserSnapshot {\n orders: UserSnapshotOrder[];\n balances: Record<string, UserSnapshotBalance>;\n global_deposits: GlobalDepositBalance[];\n notifications: Notification[];\n nonce?: number;\n}\n\nexport interface TriggerOrderUpdate {\n trigger_order_id: string;\n user_pubkey?: PubkeyStr;\n market_pubkey: PubkeyStr;\n orderbook_id: OrderBookId;\n trigger_price: string;\n trigger_above: boolean;\n status: TriggerStatus;\n type?: TriggerUpdateType;\n order_hash: string;\n side: Side;\n result_status?: TriggerResultStatus;\n result_filled?: string;\n result_remaining?: string;\n timestamp: string;\n maker_amount?: string;\n taker_amount?: string;\n tif?: TimeInForce;\n}\n\nexport function triggerUpdateToTriggerOrder(update: TriggerOrderUpdate): TriggerOrder {\n const triggerType = update.trigger_above ? TriggerType.TakeProfit : TriggerType.StopLoss;\n return {\n triggerOrderId: update.trigger_order_id,\n orderHash: update.order_hash,\n marketPubkey: update.market_pubkey,\n orderbookId: update.orderbook_id,\n triggerPrice: update.trigger_price,\n triggerType,\n side: update.side,\n amountIn: update.maker_amount ?? \"0\",\n amountOut: update.taker_amount ?? \"0\",\n timeInForce: update.tif ?? TimeInForce.Gtc,\n createdAt: new Date(update.timestamp),\n };\n}\n\nexport type OrderEvent =\n | ({ order_type: \"limit\" } & OrderUpdate)\n | ({ order_type: \"trigger\" } & TriggerOrderUpdate);\n\nexport interface NotificationUpdate {\n notification: Notification;\n}\n\nexport interface UserBalanceUpdate {\n market_pubkey: PubkeyStr;\n orderbook_id: OrderBookId;\n balance: { outcomes: ConditionalBalance[] };\n timestamp: string;\n}\n\nexport type UserUpdate =\n | ({ event_type: \"snapshot\" } & UserSnapshot)\n | ({ event_type: \"order\" } & OrderEvent)\n | ({ event_type: \"balance_update\" } & UserBalanceUpdate)\n | ({ event_type: \"global_deposit_update\" } & GlobalDepositUpdate)\n | ({ event_type: \"nonce\" } & NonceUpdate)\n | ({ event_type: \"notification\" } & NotificationUpdate);\n\nexport type AuthUpdate =\n | { status: \"authenticated\"; wallet: PubkeyStr }\n | { status: \"anonymous\"; reason?: string };\n\n// ─── User order fills (REST) ────────────────────────────────────────────────\n\nexport type Role = \"maker\" | \"taker\";\n\nexport type FillStatus = \"filled\" | \"cancelled\" | \"partially_filled\";\n\nexport interface OrderFillEvent {\n fill_amount: string;\n tx_signature: string;\n filled_at: number;\n}\n\nexport interface UserOrderFill {\n order_hash: string;\n market_pubkey: PubkeyStr;\n orderbook_id: OrderBookId;\n side: Side;\n role: Role;\n price: string;\n size: string;\n filled_size: string;\n remaining_size: string;\n base_mint: PubkeyStr;\n quote_mint: PubkeyStr;\n outcome_index: number;\n status: FillStatus;\n created_at: number;\n fills: OrderFillEvent[];\n}\n\nexport interface UserOrderFillsResponse {\n orders: UserOrderFill[];\n next_cursor?: string;\n has_more: boolean;\n}\n\ntype RawConditionalBalance = Omit<ConditionalBalance, \"mint\"> & {\n mint?: string;\n conditional_token?: string;\n};\n\ntype RawUserOrderUpdateBalance = {\n outcomes: RawConditionalBalance[];\n};\n\ntype RawWsOrder = Omit<WsOrder, \"balance\"> & {\n balance?: RawUserOrderUpdateBalance;\n};\n\ntype RawOrderUpdate = Omit<OrderUpdate, \"order\"> & {\n order: RawWsOrder;\n};\n\ntype RawUserSnapshotOrderCommon = Omit<UserSnapshotOrderCommon, \"amount_in\" | \"amount_out\"> & {\n amount_in?: string;\n amount_out?: string;\n maker_amount?: string;\n taker_amount?: string;\n};\n\ntype RawUserSnapshotOrder =\n | ({ order_type: \"limit\"; tx_signature?: string } & RawUserSnapshotOrderCommon)\n | ({\n order_type: \"trigger\";\n trigger_order_id: string;\n trigger_price: string;\n trigger_type: TriggerType;\n time_in_force?: TimeInForce;\n } & RawUserSnapshotOrderCommon);\n\ntype RawUserSnapshotBalance = Omit<UserSnapshotBalance, \"outcomes\"> & {\n outcomes: RawConditionalBalance[];\n};\n\ntype RawUserSnapshot = Omit<UserSnapshot, \"orders\" | \"balances\"> & {\n orders: RawUserSnapshotOrder[];\n balances: Record<string, RawUserSnapshotBalance>;\n};\n\ntype RawUserBalanceUpdate = Omit<UserBalanceUpdate, \"balance\"> & {\n balance: RawUserOrderUpdateBalance;\n};\n\ntype RawUserUpdate =\n | ({ event_type: \"snapshot\" } & RawUserSnapshot)\n | ({ event_type: \"order\" } & ({ order_type: \"limit\" } & RawOrderUpdate))\n | ({ event_type: \"order\" } & ({ order_type: \"trigger\" } & TriggerOrderUpdate))\n | ({ event_type: \"balance_update\" } & RawUserBalanceUpdate)\n | ({ event_type: \"global_deposit_update\" } & GlobalDepositUpdate)\n | ({ event_type: \"nonce\" | \"nonce_update\" } & NonceUpdate)\n | ({ event_type: \"notification\" } & NotificationUpdate);\n\ntype RawUserOrdersPayload = {\n user_pubkey: PubkeyStr;\n orders?: RawUserSnapshotOrder[];\n balances?: RawUserSnapshotBalance[];\n next_cursor?: string | null;\n has_more?: boolean;\n};\n\nexport function normalizeConditionalBalance(balance: RawConditionalBalance): ConditionalBalance {\n const mint = balance.mint ?? balance.conditional_token;\n if (!mint) {\n throw new Error(\"Invalid conditional balance: missing mint\");\n }\n\n return {\n outcome_index: balance.outcome_index,\n mint: asPubkeyStr(mint),\n idle: balance.idle,\n on_book: balance.on_book,\n };\n}\n\nfunction normalizeUserOrderUpdateBalance(\n balance: RawUserOrderUpdateBalance\n): UserOrderUpdateBalance {\n return {\n outcomes: balance.outcomes.map(normalizeConditionalBalance),\n };\n}\n\nfunction normalizeWsOrder(order: RawWsOrder): WsOrder {\n return {\n ...order,\n balance: order.balance\n ? normalizeUserOrderUpdateBalance(order.balance)\n : undefined,\n };\n}\n\nexport function normalizeOrderUpdate(update: RawOrderUpdate): OrderUpdate {\n return {\n ...update,\n order: normalizeWsOrder(update.order),\n };\n}\n\nfunction normalizeUserSnapshotOrderCommon(\n order: RawUserSnapshotOrderCommon\n): UserSnapshotOrderCommon {\n const amountIn = order.amount_in ?? order.maker_amount;\n const amountOut = order.amount_out ?? order.taker_amount;\n\n if (amountIn === undefined) {\n throw new Error(\"Invalid user snapshot order: missing amount_in/maker_amount\");\n }\n if (amountOut === undefined) {\n throw new Error(\"Invalid user snapshot order: missing amount_out/taker_amount\");\n }\n\n return {\n ...order,\n amount_in: amountIn,\n amount_out: amountOut,\n };\n}\n\nexport function normalizeUserSnapshotOrder(\n order: RawUserSnapshotOrder\n): UserSnapshotOrder {\n const common = normalizeUserSnapshotOrderCommon(order);\n\n if (order.order_type === \"limit\") {\n return {\n ...common,\n order_type: \"limit\",\n tx_signature: order.tx_signature,\n };\n }\n\n if (order.order_type === \"trigger\") {\n return {\n ...common,\n order_type: \"trigger\",\n trigger_order_id: order.trigger_order_id,\n trigger_price: order.trigger_price,\n trigger_type: order.trigger_type,\n time_in_force: order.time_in_force,\n };\n }\n\n const rawOrderType = (order as { order_type: string }).order_type;\n throw new Error(`Invalid user snapshot order: unsupported order_type \"${rawOrderType}\"`);\n}\n\nexport function normalizeUserSnapshotBalance(\n balance: RawUserSnapshotBalance\n): UserSnapshotBalance {\n return {\n ...balance,\n outcomes: balance.outcomes.map(normalizeConditionalBalance),\n };\n}\n\nfunction normalizeUserSnapshotBalancesRecord(\n balances: Record<string, RawUserSnapshotBalance>\n): Record<string, UserSnapshotBalance> {\n return Object.fromEntries(\n Object.entries(balances).map(([orderbookId, balance]) => [\n orderbookId,\n normalizeUserSnapshotBalance(balance),\n ])\n );\n}\n\nexport function normalizeUserOrdersPayload(\n response: RawUserOrdersPayload\n): {\n user_pubkey: PubkeyStr;\n orders: UserSnapshotOrder[];\n balances: UserSnapshotBalance[];\n next_cursor?: string;\n has_more: boolean;\n} {\n return {\n user_pubkey: response.user_pubkey,\n orders: (response.orders ?? []).map(normalizeUserSnapshotOrder),\n balances: (response.balances ?? []).map(normalizeUserSnapshotBalance),\n next_cursor: response.next_cursor ?? undefined,\n has_more: response.has_more ?? false,\n };\n}\n\nexport function normalizeUserUpdate(raw: RawUserUpdate): UserUpdate {\n switch (raw.event_type) {\n case \"snapshot\":\n return {\n ...raw,\n event_type: \"snapshot\",\n orders: raw.orders.map(normalizeUserSnapshotOrder),\n balances: normalizeUserSnapshotBalancesRecord(raw.balances),\n global_deposits: raw.global_deposits ?? [],\n notifications: raw.notifications ?? [],\n nonce: raw.nonce ?? 0,\n };\n case \"order\":\n if (raw.order_type === \"limit\") {\n return {\n ...normalizeOrderUpdate(raw),\n event_type: \"order\",\n order_type: \"limit\",\n };\n }\n if (raw.order_type === \"trigger\") {\n return {\n ...raw,\n event_type: \"order\",\n order_type: \"trigger\",\n };\n }\n throw new Error(\n `Invalid user order event: unsupported order_type \"${(raw as { order_type: string }).order_type}\"`\n );\n case \"balance_update\":\n return {\n ...raw,\n event_type: \"balance_update\",\n balance: normalizeUserOrderUpdateBalance(raw.balance),\n };\n case \"global_deposit_update\":\n return raw;\n case \"nonce\":\n case \"nonce_update\":\n return {\n ...raw,\n event_type: \"nonce\",\n };\n case \"notification\":\n return raw;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"wire.js","sourceRoot":"","sources":["../../../src/domain/order/wire.ts"],"names":[],"mappings":";;AA4IA,kEAeC;AA0ID,kEAWC;AAmBD,oDAKC;AAsBD,gEA0BC;AASD,kEAcC;AAED,4EAaC;AAED,gEAcC;AAED,gEAmBC;AAED,kDAuDC;AA5fD,yCAAqE;AA4IrE,SAAgB,2BAA2B,CAAC,MAA0B;IACpE,MAAM,WAAW,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,oBAAW,CAAC,UAAU,CAAC,CAAC,CAAC,oBAAW,CAAC,QAAQ,CAAC;IACzF,OAAO;QACL,cAAc,EAAE,MAAM,CAAC,gBAAgB;QACvC,SAAS,EAAE,MAAM,CAAC,UAAU;QAC5B,YAAY,EAAE,MAAM,CAAC,aAAa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AI,KAAK,CACb,qDAAsD,GAA8B,CAAC,UAAU,GAAG,CACnG,CAAC;QACJ,KAAK,uBAAuB;YAC1B,OAAO;gBACL,GAAG,GAAG;gBACN,UAAU,EAAE,uBAAuB;gBACnC,aAAa,EAAE,IAAA,oBAAW,EAAC,GAAG,CAAC,aAAa,CAAC;gBAC7C,cAAc,EAAE,0BAA0B,CAAC,GAAG,CAAC,cAAc,CAAC;aAC/D,CAAC;QACJ,KAAK,uBAAuB;YAC1B,OAAO,GAAG,CAAC;QACb,KAAK,OAAO,CAAC;QACb,KAAK,cAAc;YACjB,OAAO;gBACL,GAAG,GAAG;gBACN,UAAU,EAAE,OAAO;aACpB,CAAC;QACJ,KAAK,cAAc;YACjB,OAAO,GAAG,CAAC;QACb;YACE,MAAM,IAAI,KAAK,CACb,mCAAoC,GAA8B,CAAC,UAAU,GAAG,CACjF,CAAC;IACN,CAAC;AACH,CAAC","sourcesContent":["import { asPubkeyStr, TimeInForce, TriggerType } from \"../../shared\";\nimport type {\n OrderBookId,\n OrderUpdateType,\n PubkeyStr,\n Side,\n TriggerResultStatus,\n TriggerStatus,\n TriggerUpdateType,\n} from \"../../shared\";\nimport type { Notification } from \"../notification\";\nimport type { OrderStatus, TriggerOrder } from \"./index\";\n\nexport interface ConditionalBalance {\n outcome_index: number;\n conditional_token: PubkeyStr;\n idle: string;\n on_book: string;\n}\n\nexport interface UserMarketBalance {\n market_pubkey: PubkeyStr;\n deposit_assets: UserDepositAssetBalance[];\n}\n\nexport interface UserDepositAssetBalance {\n deposit_asset: PubkeyStr;\n outcomes: UserOutcomeBalance[];\n}\n\nexport interface UserOutcomeBalance {\n outcome_index: number;\n conditional_token: PubkeyStr;\n balance: string;\n balance_idle: string;\n balance_on_book: string;\n}\n\nexport interface GlobalDepositBalance {\n mint: PubkeyStr;\n balance: string;\n}\n\nexport interface GlobalDepositUpdate {\n mint: PubkeyStr;\n balance: string;\n timestamp: string;\n}\n\nexport interface NonceUpdate {\n user_pubkey: PubkeyStr;\n new_nonce: number;\n timestamp: string;\n}\n\nexport interface UserOrderUpdateBalance {\n outcomes: ConditionalBalance[];\n}\n\nexport interface WsOrder {\n order_hash: string;\n price: string;\n is_maker: boolean;\n remaining: string;\n filled: string;\n fill_amount: string;\n side: Side;\n created_at: number;\n base_mint: PubkeyStr;\n quote_mint: PubkeyStr;\n outcome_index: number;\n status: OrderStatus;\n balance?: UserOrderUpdateBalance;\n}\n\nexport interface OrderUpdate {\n market_pubkey: PubkeyStr;\n orderbook_id: OrderBookId;\n timestamp: string;\n tx_signature?: string;\n type?: OrderUpdateType;\n order: WsOrder;\n}\n\nexport interface UserSnapshotOrderCommon {\n order_hash: string;\n market_pubkey: PubkeyStr;\n orderbook_id: OrderBookId;\n side: Side;\n amount_in: string;\n amount_out: string;\n remaining: string;\n filled: string;\n price: string;\n created_at: number;\n expiration: number;\n base_mint: PubkeyStr;\n quote_mint: PubkeyStr;\n outcome_index: number;\n status: OrderStatus;\n}\n\nexport type UserSnapshotOrder =\n | ({ order_type: \"limit\"; tx_signature?: string } & UserSnapshotOrderCommon)\n | ({\n order_type: \"trigger\";\n trigger_order_id: string;\n trigger_price: string;\n trigger_type: TriggerType;\n time_in_force?: TimeInForce;\n } & UserSnapshotOrderCommon);\n\nexport interface UserSnapshot {\n orders: UserSnapshotOrder[];\n market_balances: UserMarketBalance[];\n global_deposits: GlobalDepositBalance[];\n notifications: Notification[];\n nonce?: number;\n}\n\nexport interface TriggerOrderUpdate {\n trigger_order_id: string;\n user_pubkey?: PubkeyStr;\n market_pubkey: PubkeyStr;\n orderbook_id: OrderBookId;\n trigger_price: string;\n trigger_above: boolean;\n status: TriggerStatus;\n type?: TriggerUpdateType;\n order_hash: string;\n side: Side;\n result_status?: TriggerResultStatus;\n result_filled?: string;\n result_remaining?: string;\n timestamp: string;\n maker_amount?: string;\n taker_amount?: string;\n tif?: TimeInForce;\n}\n\nexport function triggerUpdateToTriggerOrder(update: TriggerOrderUpdate): TriggerOrder {\n const triggerType = update.trigger_above ? TriggerType.TakeProfit : TriggerType.StopLoss;\n return {\n triggerOrderId: update.trigger_order_id,\n orderHash: update.order_hash,\n marketPubkey: update.market_pubkey,\n orderbookId: update.orderbook_id,\n triggerPrice: update.trigger_price,\n triggerType,\n side: update.side,\n amountIn: update.maker_amount ?? \"0\",\n amountOut: update.taker_amount ?? \"0\",\n timeInForce: update.tif ?? TimeInForce.Gtc,\n createdAt: new Date(update.timestamp),\n };\n}\n\nexport type OrderEvent =\n | ({ order_type: \"limit\" } & OrderUpdate)\n | ({ order_type: \"trigger\" } & TriggerOrderUpdate);\n\nexport interface NotificationUpdate {\n notification: Notification;\n}\n\nexport interface UserBalanceUpdate {\n market_pubkey: PubkeyStr;\n market_balance: UserMarketBalance;\n timestamp: string;\n}\n\nexport type UserUpdate =\n | ({ event_type: \"snapshot\" } & UserSnapshot)\n | ({ event_type: \"order\" } & OrderEvent)\n | ({ event_type: \"market_balance_update\" } & UserBalanceUpdate)\n | ({ event_type: \"global_deposit_update\" } & GlobalDepositUpdate)\n | ({ event_type: \"nonce\" } & NonceUpdate)\n | ({ event_type: \"notification\" } & NotificationUpdate);\n\nexport type AuthUpdate =\n | { status: \"authenticated\"; wallet: PubkeyStr }\n | { status: \"anonymous\"; reason?: string };\n\n// ─── User order fills (REST) ────────────────────────────────────────────────\n\nexport type Role = \"maker\" | \"taker\";\n\nexport type FillStatus = \"filled\" | \"cancelled\" | \"partially_filled\";\n\nexport interface OrderFillEvent {\n fill_amount: string;\n tx_signature: string;\n filled_at: number;\n}\n\nexport interface UserOrderFill {\n order_hash: string;\n market_pubkey: PubkeyStr;\n orderbook_id: OrderBookId;\n side: Side;\n role: Role;\n price: string;\n size: string;\n filled_size: string;\n remaining_size: string;\n base_mint: PubkeyStr;\n quote_mint: PubkeyStr;\n outcome_index: number;\n status: FillStatus;\n created_at: number;\n fills: OrderFillEvent[];\n}\n\nexport interface UserOrderFillsResponse {\n orders: UserOrderFill[];\n next_cursor?: string;\n has_more: boolean;\n}\n\ntype RawConditionalBalance = Omit<ConditionalBalance, \"conditional_token\"> & {\n conditional_token: string;\n};\n\ntype RawUserOutcomeBalance = Omit<UserOutcomeBalance, \"conditional_token\"> & {\n conditional_token: string;\n};\n\ntype RawUserDepositAssetBalance = Omit<UserDepositAssetBalance, \"deposit_asset\" | \"outcomes\"> & {\n deposit_asset: string;\n outcomes: RawUserOutcomeBalance[];\n};\n\ntype RawUserMarketBalance = Omit<UserMarketBalance, \"market_pubkey\" | \"deposit_assets\"> & {\n market_pubkey: string;\n deposit_assets: RawUserDepositAssetBalance[];\n};\n\ntype RawUserOrderUpdateBalance = {\n outcomes: RawConditionalBalance[];\n};\n\ntype RawWsOrder = Omit<WsOrder, \"balance\"> & {\n balance?: RawUserOrderUpdateBalance;\n};\n\ntype RawOrderUpdate = Omit<OrderUpdate, \"order\"> & {\n order: RawWsOrder;\n};\n\ntype RawUserSnapshotOrderCommon = Omit<UserSnapshotOrderCommon, \"amount_in\" | \"amount_out\"> & {\n amount_in?: string;\n amount_out?: string;\n maker_amount?: string;\n taker_amount?: string;\n};\n\ntype RawUserSnapshotOrder =\n | ({ order_type: \"limit\"; tx_signature?: string } & RawUserSnapshotOrderCommon)\n | ({\n order_type: \"trigger\";\n trigger_order_id: string;\n trigger_price: string;\n trigger_type: TriggerType;\n time_in_force?: TimeInForce;\n } & RawUserSnapshotOrderCommon);\n\ntype RawUserSnapshot = Omit<UserSnapshot, \"orders\" | \"market_balances\"> & {\n orders: RawUserSnapshotOrder[];\n market_balances: RawUserMarketBalance[];\n};\n\ntype RawUserBalanceUpdate = Omit<UserBalanceUpdate, \"market_pubkey\" | \"market_balance\"> & {\n market_pubkey: string;\n market_balance: RawUserMarketBalance;\n};\n\ntype RawUserUpdate =\n | ({ event_type: \"snapshot\" } & RawUserSnapshot)\n | ({ event_type: \"order\" } & ({ order_type: \"limit\" } & RawOrderUpdate))\n | ({ event_type: \"order\" } & ({ order_type: \"trigger\" } & TriggerOrderUpdate))\n | ({ event_type: \"market_balance_update\" } & RawUserBalanceUpdate)\n | ({ event_type: \"global_deposit_update\" } & GlobalDepositUpdate)\n | ({ event_type: \"nonce\" | \"nonce_update\" } & NonceUpdate)\n | ({ event_type: \"notification\" } & NotificationUpdate);\n\ntype RawUserOrdersPayload = {\n user_pubkey: PubkeyStr;\n orders?: RawUserSnapshotOrder[];\n market_balances: RawUserMarketBalance[];\n next_cursor?: string | null;\n has_more?: boolean;\n};\n\nexport function normalizeConditionalBalance(balance: RawConditionalBalance): ConditionalBalance {\n if (!balance.conditional_token) {\n throw new Error(\"Invalid conditional balance: missing conditional_token\");\n }\n\n return {\n outcome_index: balance.outcome_index,\n conditional_token: asPubkeyStr(balance.conditional_token),\n idle: balance.idle,\n on_book: balance.on_book,\n };\n}\n\nfunction normalizeUserOrderUpdateBalance(\n balance: RawUserOrderUpdateBalance\n): UserOrderUpdateBalance {\n return {\n outcomes: balance.outcomes.map(normalizeConditionalBalance),\n };\n}\n\nfunction normalizeWsOrder(order: RawWsOrder): WsOrder {\n return {\n ...order,\n balance: order.balance\n ? normalizeUserOrderUpdateBalance(order.balance)\n : undefined,\n };\n}\n\nexport function normalizeOrderUpdate(update: RawOrderUpdate): OrderUpdate {\n return {\n ...update,\n order: normalizeWsOrder(update.order),\n };\n}\n\nfunction normalizeUserSnapshotOrderCommon(\n order: RawUserSnapshotOrderCommon\n): UserSnapshotOrderCommon {\n const amountIn = order.amount_in ?? order.maker_amount;\n const amountOut = order.amount_out ?? order.taker_amount;\n\n if (amountIn === undefined) {\n throw new Error(\"Invalid user snapshot order: missing amount_in/maker_amount\");\n }\n if (amountOut === undefined) {\n throw new Error(\"Invalid user snapshot order: missing amount_out/taker_amount\");\n }\n\n return {\n ...order,\n amount_in: amountIn,\n amount_out: amountOut,\n };\n}\n\nexport function normalizeUserSnapshotOrder(\n order: RawUserSnapshotOrder\n): UserSnapshotOrder {\n const common = normalizeUserSnapshotOrderCommon(order);\n\n if (order.order_type === \"limit\") {\n return {\n ...common,\n order_type: \"limit\",\n tx_signature: order.tx_signature,\n };\n }\n\n if (order.order_type === \"trigger\") {\n return {\n ...common,\n order_type: \"trigger\",\n trigger_order_id: order.trigger_order_id,\n trigger_price: order.trigger_price,\n trigger_type: order.trigger_type,\n time_in_force: order.time_in_force,\n };\n }\n\n const rawOrderType = (order as { order_type: string }).order_type;\n throw new Error(`Invalid user snapshot order: unsupported order_type \"${rawOrderType}\"`);\n}\n\nfunction requireArray<T>(value: T[] | undefined, context: string): T[] {\n if (!Array.isArray(value)) {\n throw new Error(`Invalid ${context}: expected array`);\n }\n return value;\n}\n\nexport function normalizeUserOutcomeBalance(\n balance: RawUserOutcomeBalance\n): UserOutcomeBalance {\n if (!balance.conditional_token) {\n throw new Error(\"Invalid user outcome balance: missing conditional_token\");\n }\n\n return {\n outcome_index: balance.outcome_index,\n conditional_token: asPubkeyStr(balance.conditional_token),\n balance: balance.balance,\n balance_idle: balance.balance_idle,\n balance_on_book: balance.balance_on_book,\n };\n}\n\nexport function normalizeUserDepositAssetBalance(\n balance: RawUserDepositAssetBalance\n): UserDepositAssetBalance {\n if (!balance.deposit_asset) {\n throw new Error(\"Invalid user deposit asset balance: missing deposit_asset\");\n }\n\n return {\n deposit_asset: asPubkeyStr(balance.deposit_asset),\n outcomes: requireArray(balance.outcomes, \"user deposit asset balance outcomes\").map(\n normalizeUserOutcomeBalance\n ),\n };\n}\n\nexport function normalizeUserMarketBalance(\n balance: RawUserMarketBalance\n): UserMarketBalance {\n if (!balance.market_pubkey) {\n throw new Error(\"Invalid user market balance: missing market_pubkey\");\n }\n\n return {\n market_pubkey: asPubkeyStr(balance.market_pubkey),\n deposit_assets: requireArray(\n balance.deposit_assets,\n \"user market balance deposit_assets\"\n ).map(normalizeUserDepositAssetBalance),\n };\n}\n\nexport function normalizeUserOrdersPayload(\n response: RawUserOrdersPayload\n): {\n user_pubkey: PubkeyStr;\n orders: UserSnapshotOrder[];\n market_balances: UserMarketBalance[];\n next_cursor?: string;\n has_more: boolean;\n} {\n return {\n user_pubkey: response.user_pubkey,\n orders: (response.orders ?? []).map(normalizeUserSnapshotOrder),\n market_balances: requireArray(\n response.market_balances,\n \"user orders response market_balances\"\n ).map(normalizeUserMarketBalance),\n next_cursor: response.next_cursor ?? undefined,\n has_more: response.has_more ?? false,\n };\n}\n\nexport function normalizeUserUpdate(raw: RawUserUpdate): UserUpdate {\n switch (raw.event_type) {\n case \"snapshot\":\n return {\n ...raw,\n event_type: \"snapshot\",\n orders: raw.orders.map(normalizeUserSnapshotOrder),\n market_balances: requireArray(\n raw.market_balances,\n \"user snapshot market_balances\"\n ).map(normalizeUserMarketBalance),\n global_deposits: raw.global_deposits ?? [],\n notifications: raw.notifications ?? [],\n nonce: raw.nonce ?? 0,\n };\n case \"order\":\n if (raw.order_type === \"limit\") {\n return {\n ...normalizeOrderUpdate(raw),\n event_type: \"order\",\n order_type: \"limit\",\n };\n }\n if (raw.order_type === \"trigger\") {\n return {\n ...raw,\n event_type: \"order\",\n order_type: \"trigger\",\n };\n }\n throw new Error(\n `Invalid user order event: unsupported order_type \"${(raw as { order_type: string }).order_type}\"`\n );\n case \"market_balance_update\":\n return {\n ...raw,\n event_type: \"market_balance_update\",\n market_pubkey: asPubkeyStr(raw.market_pubkey),\n market_balance: normalizeUserMarketBalance(raw.market_balance),\n };\n case \"global_deposit_update\":\n return raw;\n case \"nonce\":\n case \"nonce_update\":\n return {\n ...raw,\n event_type: \"nonce\",\n };\n case \"notification\":\n return raw;\n default:\n throw new Error(\n `Invalid user update event_type \"${(raw as { event_type: string }).event_type}\"`\n );\n }\n}\n"]}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hyperliquid-style book aggregation parameters.
|
|
3
|
+
*
|
|
4
|
+
* `{}` (both fields absent) is full precision. `nSigFigs` must be 2, 3, 4,
|
|
5
|
+
* or 5; `mantissa` must be 1, 2, or 5 and is only valid with `nSigFigs: 5`.
|
|
6
|
+
* `{ nSigFigs: 5 }` normalizes to `{ nSigFigs: 5, mantissa: 1 }` — the
|
|
7
|
+
* backend treats them as the same subscription, so all key/matching logic
|
|
8
|
+
* compares normalized values.
|
|
9
|
+
*
|
|
10
|
+
* Property names use the wire spelling shared with subscribe params and REST
|
|
11
|
+
* query keys (camelCase `nSigFigs`). Incoming `book_update` frames tag their
|
|
12
|
+
* view with snake_case `n_sig_figs`/`mantissa` (omitted = full precision);
|
|
13
|
+
* use {@link aggregationFromFrame} to key per-`(orderbook, aggregation)`
|
|
14
|
+
* state from those tags.
|
|
15
|
+
*/
|
|
16
|
+
export interface BookAggregation {
|
|
17
|
+
nSigFigs?: number;
|
|
18
|
+
mantissa?: number;
|
|
19
|
+
}
|
|
20
|
+
/** Full precision (no aggregation). */
|
|
21
|
+
export declare const FULL_PRECISION: BookAggregation;
|
|
22
|
+
/**
|
|
23
|
+
* Validate aggregation params against the backend's contract, returning the
|
|
24
|
+
* normalized form. Throws on invalid combinations — the server rejects them
|
|
25
|
+
* with `INVALID_ORDERBOOK_SUBSCRIPTION` (WS) or HTTP 400 (REST), so validate
|
|
26
|
+
* before sending.
|
|
27
|
+
*/
|
|
28
|
+
export declare function validateAggregation(aggregation: BookAggregation): BookAggregation;
|
|
29
|
+
/**
|
|
30
|
+
* Normalized form: `{ nSigFigs: 5 }` becomes `{ nSigFigs: 5, mantissa: 1 }`;
|
|
31
|
+
* everything else is unchanged. Lenient — never throws. Use
|
|
32
|
+
* {@link validateAggregation} to reject invalid combinations before sending.
|
|
33
|
+
*/
|
|
34
|
+
export declare function normalizeAggregation(aggregation: BookAggregation): BookAggregation;
|
|
35
|
+
/**
|
|
36
|
+
* Aggregation identified by an incoming frame's snake_case tags. Untagged
|
|
37
|
+
* frames (both fields absent) are full precision. Lenient — never throws.
|
|
38
|
+
*/
|
|
39
|
+
export declare function aggregationFromFrame(nSigFigs?: number, mantissa?: number): BookAggregation;
|
|
40
|
+
/** Whether this is the full-precision (no aggregation) view. */
|
|
41
|
+
export declare function isFullPrecision(aggregation: BookAggregation): boolean;
|
|
42
|
+
/** Compare two aggregations as the backend does: by normalized value. */
|
|
43
|
+
export declare function aggregationsEqual(a: BookAggregation, b: BookAggregation): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Stable suffix for subscription keys: `"full"`, `"sig2"`..`"sig4"`, or
|
|
46
|
+
* `"sig5m1"`/`"sig5m2"`/`"sig5m5"`. Matches the backend's subscription-key
|
|
47
|
+
* vocabulary so keys are comparable across normalized spellings.
|
|
48
|
+
*/
|
|
49
|
+
export declare function aggregationKeySuffix(aggregation: BookAggregation): string;
|
|
50
|
+
//# sourceMappingURL=aggregation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aggregation.d.ts","sourceRoot":"","sources":["../../../src/domain/orderbook/aggregation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,uCAAuC;AACvC,eAAO,MAAM,cAAc,EAAE,eAAoB,CAAC;AAElD;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,eAAe,GAAG,eAAe,CAwBjF;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,eAAe,GAAG,eAAe,CAKlF;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,eAAe,CAE1F;AAED,gEAAgE;AAChE,wBAAgB,eAAe,CAAC,WAAW,EAAE,eAAe,GAAG,OAAO,CAGrE;AAED,yEAAyE;AACzE,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,eAAe,EAAE,CAAC,EAAE,eAAe,GAAG,OAAO,CAOjF;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,eAAe,GAAG,MAAM,CAMzE"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FULL_PRECISION = void 0;
|
|
4
|
+
exports.validateAggregation = validateAggregation;
|
|
5
|
+
exports.normalizeAggregation = normalizeAggregation;
|
|
6
|
+
exports.aggregationFromFrame = aggregationFromFrame;
|
|
7
|
+
exports.isFullPrecision = isFullPrecision;
|
|
8
|
+
exports.aggregationsEqual = aggregationsEqual;
|
|
9
|
+
exports.aggregationKeySuffix = aggregationKeySuffix;
|
|
10
|
+
/** Full precision (no aggregation). */
|
|
11
|
+
exports.FULL_PRECISION = {};
|
|
12
|
+
/**
|
|
13
|
+
* Validate aggregation params against the backend's contract, returning the
|
|
14
|
+
* normalized form. Throws on invalid combinations — the server rejects them
|
|
15
|
+
* with `INVALID_ORDERBOOK_SUBSCRIPTION` (WS) or HTTP 400 (REST), so validate
|
|
16
|
+
* before sending.
|
|
17
|
+
*/
|
|
18
|
+
function validateAggregation(aggregation) {
|
|
19
|
+
const { nSigFigs, mantissa } = aggregation;
|
|
20
|
+
if (nSigFigs === undefined) {
|
|
21
|
+
if (mantissa !== undefined) {
|
|
22
|
+
throw new Error("mantissa is only valid when nSigFigs is 5");
|
|
23
|
+
}
|
|
24
|
+
return {};
|
|
25
|
+
}
|
|
26
|
+
if (nSigFigs >= 2 && nSigFigs <= 4) {
|
|
27
|
+
if (mantissa !== undefined) {
|
|
28
|
+
throw new Error("mantissa is only valid when nSigFigs is 5");
|
|
29
|
+
}
|
|
30
|
+
return { nSigFigs };
|
|
31
|
+
}
|
|
32
|
+
if (nSigFigs === 5) {
|
|
33
|
+
if (mantissa === undefined) {
|
|
34
|
+
return { nSigFigs: 5, mantissa: 1 };
|
|
35
|
+
}
|
|
36
|
+
if (mantissa === 1 || mantissa === 2 || mantissa === 5) {
|
|
37
|
+
return { nSigFigs: 5, mantissa };
|
|
38
|
+
}
|
|
39
|
+
throw new Error("mantissa must be 1, 2, or 5");
|
|
40
|
+
}
|
|
41
|
+
throw new Error("nSigFigs must be 2, 3, 4, 5, or omitted");
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Normalized form: `{ nSigFigs: 5 }` becomes `{ nSigFigs: 5, mantissa: 1 }`;
|
|
45
|
+
* everything else is unchanged. Lenient — never throws. Use
|
|
46
|
+
* {@link validateAggregation} to reject invalid combinations before sending.
|
|
47
|
+
*/
|
|
48
|
+
function normalizeAggregation(aggregation) {
|
|
49
|
+
if (aggregation.nSigFigs === 5 && aggregation.mantissa === undefined) {
|
|
50
|
+
return { nSigFigs: 5, mantissa: 1 };
|
|
51
|
+
}
|
|
52
|
+
return aggregation;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Aggregation identified by an incoming frame's snake_case tags. Untagged
|
|
56
|
+
* frames (both fields absent) are full precision. Lenient — never throws.
|
|
57
|
+
*/
|
|
58
|
+
function aggregationFromFrame(nSigFigs, mantissa) {
|
|
59
|
+
return normalizeAggregation({ nSigFigs, mantissa });
|
|
60
|
+
}
|
|
61
|
+
/** Whether this is the full-precision (no aggregation) view. */
|
|
62
|
+
function isFullPrecision(aggregation) {
|
|
63
|
+
const normalized = normalizeAggregation(aggregation);
|
|
64
|
+
return normalized.nSigFigs === undefined && normalized.mantissa === undefined;
|
|
65
|
+
}
|
|
66
|
+
/** Compare two aggregations as the backend does: by normalized value. */
|
|
67
|
+
function aggregationsEqual(a, b) {
|
|
68
|
+
const normalizedA = normalizeAggregation(a);
|
|
69
|
+
const normalizedB = normalizeAggregation(b);
|
|
70
|
+
return (normalizedA.nSigFigs === normalizedB.nSigFigs &&
|
|
71
|
+
normalizedA.mantissa === normalizedB.mantissa);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Stable suffix for subscription keys: `"full"`, `"sig2"`..`"sig4"`, or
|
|
75
|
+
* `"sig5m1"`/`"sig5m2"`/`"sig5m5"`. Matches the backend's subscription-key
|
|
76
|
+
* vocabulary so keys are comparable across normalized spellings.
|
|
77
|
+
*/
|
|
78
|
+
function aggregationKeySuffix(aggregation) {
|
|
79
|
+
const { nSigFigs, mantissa } = normalizeAggregation(aggregation);
|
|
80
|
+
if (nSigFigs === undefined) {
|
|
81
|
+
return mantissa === undefined ? "full" : "invalid";
|
|
82
|
+
}
|
|
83
|
+
return mantissa === undefined ? `sig${nSigFigs}` : `sig${nSigFigs}m${mantissa}`;
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=aggregation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aggregation.js","sourceRoot":"","sources":["../../../src/domain/orderbook/aggregation.ts"],"names":[],"mappings":";;;AA6BA,kDAwBC;AAOD,oDAKC;AAMD,oDAEC;AAGD,0CAGC;AAGD,8CAOC;AAOD,oDAMC;AAlFD,uCAAuC;AAC1B,QAAA,cAAc,GAAoB,EAAE,CAAC;AAElD;;;;;GAKG;AACH,SAAgB,mBAAmB,CAAC,WAA4B;IAC9D,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,WAAW,CAAC;IAC3C,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC3B,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;YAC3B,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;QAC/D,CAAC;QACD,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,IAAI,QAAQ,IAAI,CAAC,IAAI,QAAQ,IAAI,CAAC,EAAE,CAAC;QACnC,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;YAC3B,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;QAC/D,CAAC;QACD,OAAO,EAAE,QAAQ,EAAE,CAAC;IACtB,CAAC;IACD,IAAI,QAAQ,KAAK,CAAC,EAAE,CAAC;QACnB,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;YAC3B,OAAO,EAAE,QAAQ,EAAE,CAAC,EAAE,QAAQ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9C,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,SAAgB,oBAAoB,CAAC,WAA4B;IAC/D,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,oBAAoB,CAAC,WAAW,CAAC,CAAC;IACjE,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC3B,OAAO,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;IACrD,CAAC;IACD,OAAO,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,QAAQ,EAAE,CAAC,CAAC,CAAC,MAAM,QAAQ,IAAI,QAAQ,EAAE,CAAC;AAClF,CAAC","sourcesContent":["/**\n * Hyperliquid-style book aggregation parameters.\n *\n * `{}` (both fields absent) is full precision. `nSigFigs` must be 2, 3, 4,\n * or 5; `mantissa` must be 1, 2, or 5 and is only valid with `nSigFigs: 5`.\n * `{ nSigFigs: 5 }` normalizes to `{ nSigFigs: 5, mantissa: 1 }` — the\n * backend treats them as the same subscription, so all key/matching logic\n * compares normalized values.\n *\n * Property names use the wire spelling shared with subscribe params and REST\n * query keys (camelCase `nSigFigs`). Incoming `book_update` frames tag their\n * view with snake_case `n_sig_figs`/`mantissa` (omitted = full precision);\n * use {@link aggregationFromFrame} to key per-`(orderbook, aggregation)`\n * state from those tags.\n */\nexport interface BookAggregation {\n nSigFigs?: number;\n mantissa?: number;\n}\n\n/** Full precision (no aggregation). */\nexport const FULL_PRECISION: BookAggregation = {};\n\n/**\n * Validate aggregation params against the backend's contract, returning the\n * normalized form. Throws on invalid combinations — the server rejects them\n * with `INVALID_ORDERBOOK_SUBSCRIPTION` (WS) or HTTP 400 (REST), so validate\n * before sending.\n */\nexport function validateAggregation(aggregation: BookAggregation): BookAggregation {\n const { nSigFigs, mantissa } = aggregation;\n if (nSigFigs === undefined) {\n if (mantissa !== undefined) {\n throw new Error(\"mantissa is only valid when nSigFigs is 5\");\n }\n return {};\n }\n if (nSigFigs >= 2 && nSigFigs <= 4) {\n if (mantissa !== undefined) {\n throw new Error(\"mantissa is only valid when nSigFigs is 5\");\n }\n return { nSigFigs };\n }\n if (nSigFigs === 5) {\n if (mantissa === undefined) {\n return { nSigFigs: 5, mantissa: 1 };\n }\n if (mantissa === 1 || mantissa === 2 || mantissa === 5) {\n return { nSigFigs: 5, mantissa };\n }\n throw new Error(\"mantissa must be 1, 2, or 5\");\n }\n throw new Error(\"nSigFigs must be 2, 3, 4, 5, or omitted\");\n}\n\n/**\n * Normalized form: `{ nSigFigs: 5 }` becomes `{ nSigFigs: 5, mantissa: 1 }`;\n * everything else is unchanged. Lenient — never throws. Use\n * {@link validateAggregation} to reject invalid combinations before sending.\n */\nexport function normalizeAggregation(aggregation: BookAggregation): BookAggregation {\n if (aggregation.nSigFigs === 5 && aggregation.mantissa === undefined) {\n return { nSigFigs: 5, mantissa: 1 };\n }\n return aggregation;\n}\n\n/**\n * Aggregation identified by an incoming frame's snake_case tags. Untagged\n * frames (both fields absent) are full precision. Lenient — never throws.\n */\nexport function aggregationFromFrame(nSigFigs?: number, mantissa?: number): BookAggregation {\n return normalizeAggregation({ nSigFigs, mantissa });\n}\n\n/** Whether this is the full-precision (no aggregation) view. */\nexport function isFullPrecision(aggregation: BookAggregation): boolean {\n const normalized = normalizeAggregation(aggregation);\n return normalized.nSigFigs === undefined && normalized.mantissa === undefined;\n}\n\n/** Compare two aggregations as the backend does: by normalized value. */\nexport function aggregationsEqual(a: BookAggregation, b: BookAggregation): boolean {\n const normalizedA = normalizeAggregation(a);\n const normalizedB = normalizeAggregation(b);\n return (\n normalizedA.nSigFigs === normalizedB.nSigFigs &&\n normalizedA.mantissa === normalizedB.mantissa\n );\n}\n\n/**\n * Stable suffix for subscription keys: `\"full\"`, `\"sig2\"`..`\"sig4\"`, or\n * `\"sig5m1\"`/`\"sig5m2\"`/`\"sig5m5\"`. Matches the backend's subscription-key\n * vocabulary so keys are comparable across normalized spellings.\n */\nexport function aggregationKeySuffix(aggregation: BookAggregation): string {\n const { nSigFigs, mantissa } = normalizeAggregation(aggregation);\n if (nSigFigs === undefined) {\n return mantissa === undefined ? \"full\" : \"invalid\";\n }\n return mantissa === undefined ? `sig${nSigFigs}` : `sig${nSigFigs}m${mantissa}`;\n}\n"]}
|
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
import { Transaction, type PublicKey, type TransactionInstruction } from "@solana/web3.js";
|
|
2
2
|
import type { ClientContext } from "../../context";
|
|
3
3
|
import type { CloseOrderbookAltParams, CloseOrderbookParams, Orderbook as ProgramOrderbook } from "../../program/types";
|
|
4
|
+
import { type BookAggregation } from "./aggregation";
|
|
4
5
|
import type { OrderbookDepthResponse } from "./wire";
|
|
5
6
|
export declare class Orderbooks {
|
|
6
7
|
private readonly client;
|
|
7
8
|
constructor(client: ClientContext);
|
|
8
9
|
pda(mintA: PublicKey, mintB: PublicKey): PublicKey;
|
|
9
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Get live orderbook depth, optionally aggregated (Hyperliquid-style).
|
|
12
|
+
*
|
|
13
|
+
* `depth` is capped server-side at 20 levels per side (omitted, `0`, or
|
|
14
|
+
* `>20` all serve 20). Invalid aggregation combinations throw client-side
|
|
15
|
+
* before any request is made (the server would 400 with
|
|
16
|
+
* `INVALID_ORDERBOOK_QUERY`), and unknown query params are rejected
|
|
17
|
+
* server-side — only `depth`, `nSigFigs`, and `mantissa` are ever sent.
|
|
18
|
+
*/
|
|
19
|
+
get(orderbookId: string, depth?: number, aggregation?: BookAggregation): Promise<OrderbookDepthResponse>;
|
|
10
20
|
closeOrderbookAltIx(params: CloseOrderbookAltParams): TransactionInstruction;
|
|
11
21
|
closeOrderbookIx(params: CloseOrderbookParams): TransactionInstruction;
|
|
12
22
|
closeOrderbookAltTx(params: CloseOrderbookAltParams): Transaction;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/domain/orderbook/client.ts"],"names":[],"mappings":"AAAA,OA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B,GAAG,sBAAsB;IAI5E,gBAAgB,CAAC,MAAM,EAAE,oBAAoB,GAAG,sBAAsB;IAItE,mBAAmB,CAAC,MAAM,EAAE,uBAAuB,GAAG,WAAW;IAKjE,gBAAgB,CAAC,MAAM,EAAE,oBAAoB,GAAG,WAAW;IAOrD,UAAU,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,GAAG,OAAO,CAAC,gBAAgB,CAAC;CAWhF"}
|
|
@@ -8,6 +8,7 @@ const http_1 = require("../../http");
|
|
|
8
8
|
const instructions_1 = require("../../program/instructions");
|
|
9
9
|
const pda_1 = require("../../program/pda");
|
|
10
10
|
const accounts_1 = require("../../program/accounts");
|
|
11
|
+
const aggregation_1 = require("./aggregation");
|
|
11
12
|
class Orderbooks {
|
|
12
13
|
client;
|
|
13
14
|
constructor(client) {
|
|
@@ -18,9 +19,29 @@ class Orderbooks {
|
|
|
18
19
|
return (0, pda_1.getOrderbookPda)(mintA, mintB, this.client.programId)[0];
|
|
19
20
|
}
|
|
20
21
|
// ── HTTP methods ─────────────────────────────────────────────────────
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Get live orderbook depth, optionally aggregated (Hyperliquid-style).
|
|
24
|
+
*
|
|
25
|
+
* `depth` is capped server-side at 20 levels per side (omitted, `0`, or
|
|
26
|
+
* `>20` all serve 20). Invalid aggregation combinations throw client-side
|
|
27
|
+
* before any request is made (the server would 400 with
|
|
28
|
+
* `INVALID_ORDERBOOK_QUERY`), and unknown query params are rejected
|
|
29
|
+
* server-side — only `depth`, `nSigFigs`, and `mantissa` are ever sent.
|
|
30
|
+
*/
|
|
31
|
+
async get(orderbookId, depth, aggregation = aggregation_1.FULL_PRECISION) {
|
|
32
|
+
const validated = (0, aggregation_1.validateAggregation)(aggregation);
|
|
33
|
+
const query = new URLSearchParams();
|
|
34
|
+
if (depth !== undefined) {
|
|
35
|
+
query.set("depth", String(depth));
|
|
36
|
+
}
|
|
37
|
+
if (validated.nSigFigs !== undefined) {
|
|
38
|
+
query.set("nSigFigs", String(validated.nSigFigs));
|
|
39
|
+
}
|
|
40
|
+
if (validated.mantissa !== undefined) {
|
|
41
|
+
query.set("mantissa", String(validated.mantissa));
|
|
42
|
+
}
|
|
43
|
+
const queryString = query.toString();
|
|
44
|
+
const url = `${this.client.http.baseUrl()}/api/orderbook/${encodeURIComponent(orderbookId)}${queryString ? `?${queryString}` : ""}`;
|
|
24
45
|
return this.client.http.get(url, http_1.RetryPolicy.Idempotent);
|
|
25
46
|
}
|
|
26
47
|
// ── On-chain transaction builders ────────────────────────────────────
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/domain/orderbook/client.ts"],"names":[],"mappings":";;;AAAA,6CAA2F;AAE3F,2CAAkD;AAClD,+CAAsD;AACtD,qCAAyC;AACzC,6DAGoC;AACpC,2CAAoD;AACpD,qDAA6F;
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/domain/orderbook/client.ts"],"names":[],"mappings":";;;AAAA,6CAA2F;AAE3F,2CAAkD;AAClD,+CAAsD;AACtD,qCAAyC;AACzC,6DAGoC;AACpC,2CAAoD;AACpD,qDAA6F;AAM7F,+CAIuB;AAGvB,MAAa,UAAU;IACQ;IAA7B,YAA6B,MAAqB;QAArB,WAAM,GAAN,MAAM,CAAe;IAAG,CAAC;IAEtD,wEAAwE;IAExE,GAAG,CAAC,KAAgB,EAAE,KAAgB;QACpC,OAAO,IAAA,qBAAe,EAAC,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;IACjE,CAAC;IAED,wEAAwE;IAExE;;;;;;;;OAQG;IACH,KAAK,CAAC,GAAG,CACP,WAAmB,EACnB,KAAc,EACd,cAA+B,4BAAc;QAE7C,MAAM,SAAS,GAAG,IAAA,iCAAmB,EAAC,WAAW,CAAC,CAAC;Q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OAAO,IAAI,qBAAW,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAChE,CAAC;IAED,gBAAgB,CAAC,MAA4B;QAC3C,MAAM,EAAE,GAAG,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC;QACzC,OAAO,IAAI,qBAAW,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAChE,CAAC;IAED,uEAAuE;IAEvE,KAAK,CAAC,UAAU,CAAC,KAAgB,EAAE,KAAgB;QACjD,MAAM,UAAU,GAAG,IAAA,2BAAiB,EAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAClD,MAAM,YAAY,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QAC5C,MAAM,WAAW,GAAG,MAAM,UAAU,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC;QAClE,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,MAAM,uBAAe,CAAC,eAAe,CACnC,iBAAiB,KAAK,CAAC,QAAQ,EAAE,MAAM,KAAK,CAAC,QAAQ,EAAE,EAAE,CAC1D,CAAC;QACJ,CAAC;QACD,OAAO,IAAA,+BAA2B,EAAC,WAAW,CAAC,IAAc,CAAC,CAAC;IACjE,CAAC;CACF;AA1ED,gCA0EC","sourcesContent":["import { Transaction, type PublicKey, type TransactionInstruction } from \"@solana/web3.js\";\nimport type { ClientContext } from \"../../context\";\nimport { requireConnection } from \"../../context\";\nimport { ProgramSdkError } from \"../../program/error\";\nimport { RetryPolicy } from \"../../http\";\nimport {\n buildCloseOrderbookAltIx,\n buildCloseOrderbookIx,\n} from \"../../program/instructions\";\nimport { getOrderbookPda } from \"../../program/pda\";\nimport { deserializeOrderbook as deserializeProgramOrderbook } from \"../../program/accounts\";\nimport type {\n CloseOrderbookAltParams,\n CloseOrderbookParams,\n Orderbook as ProgramOrderbook,\n} from \"../../program/types\";\nimport {\n FULL_PRECISION,\n validateAggregation,\n type BookAggregation,\n} from \"./aggregation\";\nimport type { OrderbookDepthResponse } from \"./wire\";\n\nexport class Orderbooks {\n constructor(private readonly client: ClientContext) {}\n\n // ── PDA helpers ──────────────────────────────────────────────────────\n\n pda(mintA: PublicKey, mintB: PublicKey): PublicKey {\n return getOrderbookPda(mintA, mintB, this.client.programId)[0];\n }\n\n // ── HTTP methods ─────────────────────────────────────────────────────\n\n /**\n * Get live orderbook depth, optionally aggregated (Hyperliquid-style).\n *\n * `depth` is capped server-side at 20 levels per side (omitted, `0`, or\n * `>20` all serve 20). Invalid aggregation combinations throw client-side\n * before any request is made (the server would 400 with\n * `INVALID_ORDERBOOK_QUERY`), and unknown query params are rejected\n * server-side — only `depth`, `nSigFigs`, and `mantissa` are ever sent.\n */\n async get(\n orderbookId: string,\n depth?: number,\n aggregation: BookAggregation = FULL_PRECISION\n ): Promise<OrderbookDepthResponse> {\n const validated = validateAggregation(aggregation);\n const query = new URLSearchParams();\n if (depth !== undefined) {\n query.set(\"depth\", String(depth));\n }\n if (validated.nSigFigs !== undefined) {\n query.set(\"nSigFigs\", String(validated.nSigFigs));\n }\n if (validated.mantissa !== undefined) {\n query.set(\"mantissa\", String(validated.mantissa));\n }\n const queryString = query.toString();\n const url = `${this.client.http.baseUrl()}/api/orderbook/${encodeURIComponent(orderbookId)}${queryString ? `?${queryString}` : \"\"}`;\n return this.client.http.get<OrderbookDepthResponse>(url, RetryPolicy.Idempotent);\n }\n\n // ── On-chain transaction builders ────────────────────────────────────\n\n closeOrderbookAltIx(params: CloseOrderbookAltParams): TransactionInstruction {\n return buildCloseOrderbookAltIx(params, this.client.programId);\n }\n\n closeOrderbookIx(params: CloseOrderbookParams): TransactionInstruction {\n return buildCloseOrderbookIx(params, this.client.programId);\n }\n\n closeOrderbookAltTx(params: CloseOrderbookAltParams): Transaction {\n const ix = this.closeOrderbookAltIx(params);\n return new Transaction({ feePayer: params.operator }).add(ix);\n }\n\n closeOrderbookTx(params: CloseOrderbookParams): Transaction {\n const ix = this.closeOrderbookIx(params);\n return new Transaction({ feePayer: params.operator }).add(ix);\n }\n\n // ── On-chain account fetchers (require Connection) ──────────────────\n\n async getOnchain(mintA: PublicKey, mintB: PublicKey): Promise<ProgramOrderbook> {\n const connection = requireConnection(this.client);\n const orderbookPda = this.pda(mintA, mintB);\n const accountInfo = await connection.getAccountInfo(orderbookPda);\n if (!accountInfo) {\n throw ProgramSdkError.accountNotFound(\n `Orderbook for ${mintA.toBase58()} / ${mintB.toBase58()}`\n );\n }\n return deserializeProgramOrderbook(accountInfo.data as Buffer);\n }\n}\n"]}
|
|
@@ -3,6 +3,7 @@ import { PublicKey } from "@solana/web3.js";
|
|
|
3
3
|
import type { OrderBookId, PubkeyStr } from "../../shared";
|
|
4
4
|
import type { OrderbookDecimals } from "../../shared/scaling";
|
|
5
5
|
import type { ConditionalToken } from "../market";
|
|
6
|
+
export * from "./aggregation";
|
|
6
7
|
export * from "./client";
|
|
7
8
|
export * from "./wire";
|
|
8
9
|
export * from "./state";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/domain/orderbook/index.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,YAAY,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAElD,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAElD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5F;AAED,wBAAgB,MAAM,CACpB,iBAAiB,EAAE,OAAO,EAC1B,gBAAgB,EAAE,OAAO,GACxB,aAAa,CAef;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,aAAa,GAAG,iBAAiB,CAUxE;AAED,0CAA0C;AAC1C,wBAAgB,eAAe,CAAC,IAAI,EAAE,aAAa,GAAG,SAAS,CAE9D;AAED,+DAA+D;AAC/D,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,aAAa,GAAG,SAAS,CAEhE;AAED,gEAAgE;AAChE,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,aAAa,GAAG,SAAS,CAEjE;AAED,qBAAa,wBAAyB,SAAQ,KAAK;IACjD,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,CAAC;gBAEf,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE;CAMnD"}
|
|
@@ -22,6 +22,7 @@ exports.orderBookMarket = orderBookMarket;
|
|
|
22
22
|
exports.orderBookBaseMint = orderBookBaseMint;
|
|
23
23
|
exports.orderBookQuoteMint = orderBookQuoteMint;
|
|
24
24
|
const web3_js_1 = require("@solana/web3.js");
|
|
25
|
+
__exportStar(require("./aggregation"), exports);
|
|
25
26
|
__exportStar(require("./client"), exports);
|
|
26
27
|
__exportStar(require("./wire"), exports);
|
|
27
28
|
__exportStar(require("./state"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/domain/orderbook/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/domain/orderbook/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAmCA,8BAOC;AAED,wBAkBC;AAOD,8CAUC;AAGD,0CAEC;AAGD,8CAEC;AAGD,gDAEC;AA7FD,6CAA4C;AAK5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WAAW,CAAC;QAC/B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;CACF;AAVD,4DAUC","sourcesContent":["import Decimal from \"decimal.js\";\nimport { PublicKey } from \"@solana/web3.js\";\nimport type { OrderBookId, PubkeyStr } from \"../../shared\";\nimport type { OrderbookDecimals } from \"../../shared/scaling\";\nimport type { ConditionalToken } from \"../market\";\n\nexport * from \"./aggregation\";\nexport * from \"./client\";\nexport * from \"./wire\";\nexport * from \"./state\";\nexport * from \"./ticker\";\nexport { orderBookPairFromWire } from \"./convert\";\n\nexport interface OrderBookPair {\n id: number;\n marketPubkey: PubkeyStr;\n orderbookId: OrderBookId;\n base: ConditionalToken;\n quote: ConditionalToken;\n outcomeIndex: number;\n tickSize: number;\n totalBids: number;\n totalAsks: number;\n lastTradePrice?: string;\n lastTradeTime?: Date;\n active: boolean;\n}\n\nexport interface OutcomeImpact {\n sign: string;\n pct: number;\n dollar: string;\n isPositive: boolean;\n}\n\nexport function impactPct(depositPrice: Decimal, conditionalPrice: Decimal): [number, string] {\n if (depositPrice.isZero() || conditionalPrice.isZero()) {\n return [0, \"\"];\n }\n\n const value = conditionalPrice.minus(depositPrice).div(depositPrice).mul(100);\n return [value.toNumber(), value.greaterThan(0) ? \"+\" : \"\"];\n}\n\nexport function impact(\n depositAssetPrice: Decimal,\n conditionalPrice: Decimal\n): OutcomeImpact {\n if (depositAssetPrice.isZero()) {\n return { sign: \"\", pct: 0, dollar: \"0\", isPositive: false };\n }\n\n const pctDecimal = conditionalPrice.minus(depositAssetPrice).div(depositAssetPrice).mul(100);\n const pct = pctDecimal.toNumber();\n const dollar = conditionalPrice.minus(depositAssetPrice).abs().toString();\n\n return {\n sign: pct > 0 ? \"+\" : \"-\",\n pct: Math.abs(pct),\n dollar,\n isPositive: pct > 0,\n };\n}\n\n/**\n * Derive scaling decimals from an orderbook pair's token metadata.\n *\n * No REST call needed — decimals are computed from the base/quote token objects.\n */\nexport function orderbookDecimals(pair: OrderBookPair): OrderbookDecimals {\n const baseDecimals = pair.base.decimals;\n const quoteDecimals = pair.quote.decimals;\n return {\n orderbookId: pair.orderbookId,\n baseDecimals,\n quoteDecimals,\n priceDecimals: Math.max(0, 6 + quoteDecimals - baseDecimals),\n tickSize: BigInt(Math.max(pair.tickSize, 0)),\n };\n}\n\n/** Return the market as a `PublicKey`. */\nexport function orderBookMarket(pair: OrderBookPair): PublicKey {\n return new PublicKey(pair.marketPubkey);\n}\n\n/** Return the base conditional-token mint as a `PublicKey`. */\nexport function orderBookBaseMint(pair: OrderBookPair): PublicKey {\n return new PublicKey(pair.base.pubkey);\n}\n\n/** Return the quote conditional-token mint as a `PublicKey`. */\nexport function orderBookQuoteMint(pair: OrderBookPair): PublicKey {\n return new PublicKey(pair.quote.pubkey);\n}\n\nexport class OrderBookValidationError extends Error {\n readonly orderbookId: string;\n readonly details: string[];\n\n constructor(orderbookId: string, details: string[]) {\n super(`OrderBook validation errors (${orderbookId}): ${details.join(\"; \")}`);\n this.name = \"OrderBookValidationError\";\n this.orderbookId = orderbookId;\n this.details = details;\n }\n}\n"]}
|