@proof-labs/trading-sdk 8.0.0 → 9.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/README.md +22 -1
  2. package/dist/account-recovery.d.ts.map +1 -1
  3. package/dist/account-recovery.js +9 -8
  4. package/dist/account-recovery.js.map +1 -1
  5. package/dist/account-state.d.ts +3 -0
  6. package/dist/account-state.d.ts.map +1 -1
  7. package/dist/account-state.js +12 -4
  8. package/dist/account-state.js.map +1 -1
  9. package/dist/client.d.ts +24 -6
  10. package/dist/client.d.ts.map +1 -1
  11. package/dist/client.js +60 -165
  12. package/dist/client.js.map +1 -1
  13. package/dist/codec-adapter.d.ts +11 -1
  14. package/dist/codec-adapter.d.ts.map +1 -1
  15. package/dist/codec-adapter.js +162 -14
  16. package/dist/codec-adapter.js.map +1 -1
  17. package/dist/errors.d.ts +4 -2
  18. package/dist/errors.d.ts.map +1 -1
  19. package/dist/errors.js +21 -5
  20. package/dist/errors.js.map +1 -1
  21. package/dist/feed-types.d.ts +1 -1
  22. package/dist/financial-state.d.ts +14 -3
  23. package/dist/financial-state.d.ts.map +1 -1
  24. package/dist/financial-state.js +46 -32
  25. package/dist/financial-state.js.map +1 -1
  26. package/dist/funding.d.ts +20 -0
  27. package/dist/funding.d.ts.map +1 -0
  28. package/dist/funding.js +35 -0
  29. package/dist/funding.js.map +1 -0
  30. package/dist/gateway-reads.d.ts +5 -36
  31. package/dist/gateway-reads.d.ts.map +1 -1
  32. package/dist/gateway-reads.js +7 -0
  33. package/dist/gateway-reads.js.map +1 -1
  34. package/dist/governance-query.d.ts +7 -21
  35. package/dist/governance-query.d.ts.map +1 -1
  36. package/dist/governance-query.js +59 -488
  37. package/dist/governance-query.js.map +1 -1
  38. package/dist/index.d.ts +6 -4
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +4 -2
  41. package/dist/index.js.map +1 -1
  42. package/dist/liquidation-config.d.ts +4 -0
  43. package/dist/liquidation-config.d.ts.map +1 -1
  44. package/dist/liquidation-config.js +10 -0
  45. package/dist/liquidation-config.js.map +1 -1
  46. package/dist/liquidation-events.d.ts +15 -1
  47. package/dist/liquidation-events.d.ts.map +1 -1
  48. package/dist/liquidation-events.js +19 -0
  49. package/dist/liquidation-events.js.map +1 -1
  50. package/dist/liquidation-history.d.ts +52 -0
  51. package/dist/liquidation-history.d.ts.map +1 -0
  52. package/dist/liquidation-history.js +101 -0
  53. package/dist/liquidation-history.js.map +1 -0
  54. package/dist/market-snapshot.d.ts +3 -6
  55. package/dist/market-snapshot.d.ts.map +1 -1
  56. package/dist/market-snapshot.js +7 -278
  57. package/dist/market-snapshot.js.map +1 -1
  58. package/dist/trigger-history.d.ts.map +1 -1
  59. package/dist/trigger-history.js +20 -99
  60. package/dist/trigger-history.js.map +1 -1
  61. package/dist/triggers.d.ts.map +1 -1
  62. package/dist/triggers.js +18 -50
  63. package/dist/triggers.js.map +1 -1
  64. package/dist/types.d.ts +96 -57
  65. package/dist/types.d.ts.map +1 -1
  66. package/dist/wasm/proof_trading_sdk_wasm.d.ts +42 -0
  67. package/dist/wasm/proof_trading_sdk_wasm.js +65 -0
  68. package/dist/wasm/proof_trading_sdk_wasm_bg.wasm +0 -0
  69. package/dist/wasm/proof_trading_sdk_wasm_bg.wasm.d.ts +2 -0
  70. package/dist/wasm-loader.d.ts +12 -0
  71. package/dist/wasm-loader.d.ts.map +1 -1
  72. package/dist/wasm-loader.js.map +1 -1
  73. package/package.json +1 -1
@@ -1,12 +1,25 @@
1
- import { validateSetLiquidationConfig } from "./liquidation-config.js";
2
- import { validateSetOracleGuards } from "./oracle-guards.js";
3
- import { validateFundInsuranceFund, validateWithdrawInsuranceFund, } from "./insurance-funding.js";
4
- import { validateScheduleUpgrade } from "./upgrade-plan.js";
5
- import { Outcome } from "./types.js";
1
+ import { Encoder } from "@msgpack/msgpack";
2
+ import { adminActionFromWasm } from "./codec-adapter.js";
3
+ import { INITIAL_TAKEOVER_DISCOUNT_BPS } from "./liquidation-config.js";
4
+ import { getWasm } from "./wasm-loader.js";
5
+ const actionEncoder = new Encoder({ useBigInt64: true });
6
+ /** Integers past 32 bits as bigint: the encoder writes such a number as a
7
+ * float, which the wire refuses. */
8
+ function integral(value) {
9
+ if (typeof value === "number" && Number.isSafeInteger(value)) {
10
+ return Math.abs(value) > 0xffff_ffff ? BigInt(value) : value;
11
+ }
12
+ if (Array.isArray(value))
13
+ return value.map(integral);
14
+ if (value && typeof value === "object" && !ArrayBuffer.isView(value)) {
15
+ return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, integral(v)]));
16
+ }
17
+ return value;
18
+ }
6
19
  /**
7
20
  * Typed decoders for the engine's governance READ model — the responses
8
- * behind `GET /v1/admin/signer-registry`, `GET /v1/proposals`, and
9
- * `GET /v1/events`.
21
+ * behind `GET /v1/admin/signer-registry` and `GET /v1/proposals`. The
22
+ * proposal's `AdminAction` is decoded as its wire type in the Rust core.
10
23
  *
11
24
  * These mirror engine structs (`exchange-core/src/query.rs`), they do not
12
25
  * define them. The engine serializes with `rmp_serde::to_vec` — the COMPACT
@@ -108,61 +121,27 @@ function toArray(value, field) {
108
121
  return value;
109
122
  throw new Error(`governance decode: ${field} is not an array`);
110
123
  }
111
- /// CU-06 (inner tag 19): the per-account fixed withdrawal window. Tuple
112
- /// layout matches `SetWithdrawalLimit`'s declaration order: [cap, window].
113
- function decodeSetWithdrawalLimit(value) {
114
- const raw = toTuple(value, "setWithdrawalLimit", 2);
115
- const limit = {
116
- perAccountCapMicroUsdc: toU64(raw[0], "setWithdrawalLimit.perAccountCapMicroUsdc"),
117
- windowSecs: toU32(raw[1], "setWithdrawalLimit.windowSecs"),
118
- };
119
- return limit;
120
- }
121
- /// Inner tag 17: `[predecessor, sequence, config]`, where `config` is
122
- /// `[targetRatioBps, [numerator, denominator], partialPenaltyBps,
123
- /// maxBookOrders, maxCommittedFills]`. Every newtype is its bare integer. A proposal the
124
- /// engine would refuse fails closed here too.
125
- function decodeSetLiquidationConfig(value) {
126
- const raw = toTuple(value, "setLiquidationConfig", 3);
127
- const c = toTuple(raw[2], "setLiquidationConfig.config", 5);
128
- const threshold = toTuple(c[1], "setLiquidationConfig.config.fullCloseThreshold", 2);
129
- const field = (name) => `setLiquidationConfig.config.${name}`;
130
- const action = {
131
- predecessor: toU64(raw[0], "setLiquidationConfig.predecessor"),
132
- sequence: toU64(raw[1], "setLiquidationConfig.sequence"),
133
- config: {
134
- targetRatioBps: toU32(c[0], field("targetRatioBps")),
135
- fullCloseThreshold: {
136
- numerator: toU32(threshold[0], field("fullCloseThreshold.numerator")),
137
- denominator: toU32(threshold[1], field("fullCloseThreshold.denominator")),
138
- },
139
- partialPenaltyBps: toU32(c[2], field("partialPenaltyBps")),
140
- maxBookOrders: toU32(c[3], field("maxBookOrders")),
141
- maxCommittedFills: toU32(c[4], field("maxCommittedFills")),
124
+ /// A `LiquidationConfig` as `[targetRatioBps, [numerator, denominator],
125
+ /// partialPenaltyBps, maxBookOrders, maxCommittedFills, takeoverDiscountBps?]`.
126
+ /// Every newtype is its bare integer; a record without the takeover discount
127
+ /// decodes with the engine's initial value.
128
+ function decodeLiquidationConfigTuple(value, name) {
129
+ const c = toTupleBetween(value, name, 5, 6);
130
+ const threshold = toTuple(c[1], `${name}.fullCloseThreshold`, 2);
131
+ const field = (part) => `${name}.${part}`;
132
+ return {
133
+ targetRatioBps: toU32(c[0], field("targetRatioBps")),
134
+ fullCloseThreshold: {
135
+ numerator: toU32(threshold[0], field("fullCloseThreshold.numerator")),
136
+ denominator: toU32(threshold[1], field("fullCloseThreshold.denominator")),
142
137
  },
138
+ partialPenaltyBps: toU32(c[2], field("partialPenaltyBps")),
139
+ maxBookOrders: toU32(c[3], field("maxBookOrders")),
140
+ maxCommittedFills: toU32(c[4], field("maxCommittedFills")),
141
+ takeoverDiscountBps: c.length > 5
142
+ ? toU32(c[5], field("takeoverDiscountBps"))
143
+ : INITIAL_TAKEOVER_DISCOUNT_BPS,
143
144
  };
144
- validateSetLiquidationConfig(action);
145
- return action;
146
- }
147
- /// DEC-112 (inner tag 20): the operator receipt registry rotation. Tuple
148
- /// layout matches `SetOperatorReceiptRegistry`'s declaration order:
149
- /// [deploymentId, epoch, threshold, operatorKeys]. The keys are 32-byte
150
- /// ed25519 verification keys — validated as bytes here; point validity is
151
- /// the store seam's job (validate_operator_registry).
152
- function decodeSetOperatorReceiptRegistry(value) {
153
- const raw = toTuple(value, "setOperatorReceiptRegistry", 4);
154
- const keysJson = toArray(raw[3], "setOperatorReceiptRegistry.operatorKeys");
155
- const registry = {
156
- deploymentId: toBytes(raw[0], "setOperatorReceiptRegistry.deploymentId", 32),
157
- epoch: toU64(raw[1], "setOperatorReceiptRegistry.epoch"),
158
- threshold: toU32(raw[2], "setOperatorReceiptRegistry.threshold"),
159
- operatorKeys: keysJson.map((k) => toBytes(k, "setOperatorReceiptRegistry.operatorKeys[i]", 32)),
160
- };
161
- if (registry.threshold === 0 ||
162
- registry.threshold > registry.operatorKeys.length) {
163
- throw new Error(`governance decode: setOperatorReceiptRegistry threshold ${registry.threshold} is outside 1..=${registry.operatorKeys.length}`);
164
- }
165
- return registry;
166
145
  }
167
146
  function toTuple(value, field, expectedLength) {
168
147
  const fields = toArray(value, field);
@@ -171,11 +150,6 @@ function toTuple(value, field, expectedLength) {
171
150
  }
172
151
  return fields;
173
152
  }
174
- function toString(value, field) {
175
- if (typeof value === "string")
176
- return value;
177
- throw new Error(`governance decode: ${field} is not a string`);
178
- }
179
153
  /** The single entry of an externally-tagged enum map (encoding fact 3). */
180
154
  function variantOf(value, field) {
181
155
  if (typeof value !== "object" || value === null || Array.isArray(value)) {
@@ -188,26 +162,6 @@ function variantOf(value, field) {
188
162
  const [name, payload] = entries[0];
189
163
  return { name, payload };
190
164
  }
191
- /** `CreateMarket` as the engine's 12-field positional payload. Distinct from
192
- * `decodeMarketConfig` in client.ts: that decodes the STORED market config,
193
- * this decodes the proposed action. */
194
- function decodeCreateMarket(value) {
195
- const raw = toTuple(value, "createMarket", 12);
196
- return {
197
- market: toU32(raw[0], "createMarket.market"),
198
- imBps: toU32(raw[1], "createMarket.imBps"),
199
- mmBps: toU32(raw[2], "createMarket.mmBps"),
200
- takerFeeBps: toU32(raw[3], "createMarket.takerFeeBps"),
201
- makerFeeBps: toU32(raw[4], "createMarket.makerFeeBps"),
202
- signer: toBytes(raw[5], "createMarket.signer", ADDRESS_LEN),
203
- fundingIntervalMs: toU64(raw[6], "createMarket.fundingIntervalMs"),
204
- maxFundingRateBps: toU32(raw[7], "createMarket.maxFundingRateBps"),
205
- poolId: toU8(raw[8], "createMarket.poolId"),
206
- szDecimals: toU8(raw[9], "createMarket.szDecimals"),
207
- ticker: toString(raw[10], "createMarket.ticker"),
208
- maxOpenInterest: toU64(raw[11], "createMarket.maxOpenInterest"),
209
- };
210
- }
211
165
  function toTupleBetween(value, field, minLength, maxLength) {
212
166
  const fields = toArray(value, field);
213
167
  if (fields.length < minLength || fields.length > maxLength) {
@@ -216,292 +170,6 @@ function toTupleBetween(value, field, minLength, maxLength) {
216
170
  }
217
171
  return fields;
218
172
  }
219
- const PRICE_COMPARISONS = [
220
- "GreaterThan",
221
- "LessThan",
222
- "GreaterThanOrEqual",
223
- "LessThanOrEqual",
224
- ];
225
- function toPriceComparison(value, field) {
226
- if (typeof value === "string" &&
227
- PRICE_COMPARISONS.includes(value)) {
228
- return value;
229
- }
230
- throw new Error(`governance decode: ${field} is not a known PriceComparison`);
231
- }
232
- /** `Option<EventOracleSource>`: `None` is nil (fact 4), the unit variant is a
233
- * bare string (fact 2), the struct variants are single-entry maps with
234
- * positional payloads (fact 3). Fails closed on an unknown variant — a
235
- * resolution mode this build cannot name must never render as one it can.
236
- * Exported for the client's event read, which carries the same
237
- * enum in the same compact-rmp form. */
238
- export function decodeOracleSource(value, field) {
239
- if (value === null || value === undefined)
240
- return undefined;
241
- if (value === "RelayerAttested")
242
- return { kind: "RelayerAttested" };
243
- const { name, payload } = variantOf(value, field);
244
- switch (name) {
245
- case "UnderlyingPriceVsStrike": {
246
- const raw = toTuple(payload, field, 2);
247
- return {
248
- kind: "UnderlyingPriceVsStrike",
249
- strikePrice: toU64(raw[0], `${field}.strikePrice`),
250
- comparison: toPriceComparison(raw[1], `${field}.comparison`),
251
- };
252
- }
253
- case "MarketOracle": {
254
- const raw = toTuple(payload, field, 3);
255
- return {
256
- kind: "MarketOracle",
257
- market: toU32(raw[0], `${field}.market`),
258
- strikePrice: toU64(raw[1], `${field}.strikePrice`),
259
- comparison: toPriceComparison(raw[2], `${field}.comparison`),
260
- };
261
- }
262
- default:
263
- throw new Error(`governance decode: ${field} has unknown EventOracleSource variant "${name}"`);
264
- }
265
- }
266
- const OUTCOMES = {
267
- Yes: Outcome.Yes,
268
- No: Outcome.No,
269
- Void: Outcome.Void,
270
- };
271
- /** Event lifecycle status: unit variants are bare strings (fact 2);
272
- * `Resolved(Outcome)` is a single-entry map whose newtype payload is the
273
- * outcome's variant name — a bare string, no array wrapper (confirmed from
274
- * engine bytes, not inferred). Fails closed: a status or outcome this build
275
- * cannot name must never render as one it can — these drive settle
276
- * displays. */
277
- function decodeEventStatus(value, field) {
278
- if (value === "Trading")
279
- return { kind: "Trading" };
280
- if (value === "PreResolution")
281
- return { kind: "PreResolution" };
282
- if (typeof value === "object" && value !== null && !Array.isArray(value)) {
283
- const { name, payload } = variantOf(value, field);
284
- if (name !== "Resolved") {
285
- throw new Error(`governance decode: ${field} has unknown EventStatus variant "${name}"`);
286
- }
287
- const outcome = typeof payload === "string" ? OUTCOMES[payload] : undefined;
288
- if (outcome === undefined) {
289
- throw new Error(`governance decode: ${field} has unknown Outcome ${JSON.stringify(payload)}`);
290
- }
291
- return { kind: "Resolved", outcome };
292
- }
293
- throw new Error(`governance decode: ${field} is not a known EventStatus`);
294
- }
295
- /** One `AttachedConditional` entry of an event's attachment list: the
296
- * positional `[underlying, cpy, cpn]` triple. */
297
- function decodeAttachedConditional(value, field) {
298
- const raw = toTuple(value, field, 3);
299
- return {
300
- underlyingMarket: toU32(raw[0], `${field}.underlyingMarket`),
301
- cpyMarket: toU32(raw[1], `${field}.cpyMarket`),
302
- cpnMarket: toU32(raw[2], `${field}.cpnMarket`),
303
- };
304
- }
305
- /** Whether an `EventInfo` tuple is in the one-book shape: the engine with
306
- * one binary book per event stores no No book, so the question sits where
307
- * the two-book shape keeps the No book's id. */
308
- export function isOneBookEventRow(raw) {
309
- return typeof raw[2] === "string";
310
- }
311
- /** `EventInfo` (the `get_event` read model) as a positional tuple, in either
312
- * engine shape: one book (8 required fields) or two books (9, the No book
313
- * third), each plus the `serde(default)` trailers `oracleSource` and
314
- * `attachedConditionals`. The read model IS the stored record — no appended
315
- * presentation copy. */
316
- export function decodeEventInfo(value, index) {
317
- const f = index == null ? "event" : `event[${index}]`;
318
- const oneBook = isOneBookEventRow(toArray(value, f));
319
- const required = oneBook ? 8 : 9;
320
- const raw = toTupleBetween(value, f, required, required + 2);
321
- // Fields after the books sit one place earlier in the one-book shape.
322
- const at = (i) => raw[oneBook ? i - 1 : i];
323
- const info = {
324
- eventId: toU32(raw[0], `${f}.eventId`),
325
- ebyMarket: toU32(raw[1], `${f}.ebyMarket`),
326
- question: toString(at(3), `${f}.question`),
327
- settlementMs: toU64(at(4), `${f}.settlementMs`),
328
- resolutionWindowMs: toU64(at(5), `${f}.resolutionWindowMs`),
329
- status: decodeEventStatus(at(6), `${f}.status`),
330
- createdMs: toU64(at(7), `${f}.createdMs`),
331
- resolvedMs: toU64(at(8), `${f}.resolvedMs`),
332
- attachedConditionals: [],
333
- };
334
- if (!oneBook)
335
- info.ebnMarket = toU32(raw[2], `${f}.ebnMarket`);
336
- if (raw.length > required) {
337
- const oracleSource = decodeOracleSource(at(9), `${f}.oracleSource`);
338
- if (oracleSource)
339
- info.oracleSource = oracleSource;
340
- }
341
- if (raw.length > required + 1) {
342
- info.attachedConditionals = toArray(at(10), `${f}.attachedConditionals`).map((entry, i) => decodeAttachedConditional(entry, `${f}.attachedConditionals[${i}]`));
343
- }
344
- return info;
345
- }
346
- /** `AttachConditional` as the engine's positional payload (admin inner tag
347
- * 10): 8 required fields plus the `serde(default)` `maxOpenInterest`
348
- * trailer. */
349
- function decodeAttachConditional(value) {
350
- const f = "attachConditional";
351
- const raw = toTupleBetween(value, f, 8, 9);
352
- return {
353
- eventId: toU32(raw[0], `${f}.eventId`),
354
- underlyingMarket: toU32(raw[1], `${f}.underlyingMarket`),
355
- childMarketBase: toU32(raw[2], `${f}.childMarketBase`),
356
- imBps: toU32(raw[3], `${f}.imBps`),
357
- mmBps: toU32(raw[4], `${f}.mmBps`),
358
- takerFeeBps: toU32(raw[5], `${f}.takerFeeBps`),
359
- makerFeeBps: toU32(raw[6], `${f}.makerFeeBps`),
360
- signer: toBytes(raw[7], `${f}.signer`, ADDRESS_LEN),
361
- maxOpenInterest: raw.length > 8 ? toU64(raw[8], `${f}.maxOpenInterest`) : 0n,
362
- };
363
- }
364
- /** `CreateEvent` as the engine's positional payload (admin inner tag 9): 9
365
- * required fields plus four `serde(default)` trailers (oracleSource,
366
- * description, rules, maxOpenInterest). Same tolerance/defaults as the
367
- * engine decoder. */
368
- function decodeCreateEvent(value) {
369
- const f = "createEvent";
370
- const raw = toTupleBetween(value, f, 9, 13);
371
- const decoded = {
372
- eventId: toU32(raw[0], `${f}.eventId`),
373
- childMarketBase: toU32(raw[1], `${f}.childMarketBase`),
374
- poolId: toU32(raw[2], `${f}.poolId`),
375
- question: toString(raw[3], `${f}.question`),
376
- settlementMs: toU64(raw[4], `${f}.settlementMs`),
377
- resolutionWindowMs: toU64(raw[5], `${f}.resolutionWindowMs`),
378
- takerFeeBps: toU32(raw[6], `${f}.takerFeeBps`),
379
- makerFeeBps: toU32(raw[7], `${f}.makerFeeBps`),
380
- signer: toBytes(raw[8], `${f}.signer`, ADDRESS_LEN),
381
- description: raw.length > 10 ? toString(raw[10], `${f}.description`) : "",
382
- rules: raw.length > 11 ? toString(raw[11], `${f}.rules`) : "",
383
- maxOpenInterest: raw.length > 12 ? toU64(raw[12], `${f}.maxOpenInterest`) : 0n,
384
- };
385
- const oracleSource = raw.length > 9
386
- ? decodeOracleSource(raw[9], `${f}.oracleSource`)
387
- : undefined;
388
- if (oracleSource)
389
- decoded.oracleSource = oracleSource;
390
- return decoded;
391
- }
392
- /** One item of a governance `Batch` — the CLOSED market-creation subset.
393
- * Fails closed on any other variant name: a batch item this build cannot
394
- * decode must never let the batch around it render as understood. */
395
- function decodeBatchItem(value, field) {
396
- const { name, payload } = variantOf(value, field);
397
- switch (name) {
398
- case "CreateMarket":
399
- return { kind: "CreateMarket", value: decodeCreateMarket(payload) };
400
- case "AttachConditional":
401
- return {
402
- kind: "AttachConditional",
403
- value: decodeAttachConditional(payload),
404
- };
405
- default:
406
- throw new Error(`governance decode: ${field} has unknown AdminBatchItem variant "${name}" — this SDK build cannot render it`);
407
- }
408
- }
409
- function decodeUpdateRegistry(value) {
410
- const raw = toTuple(value, "updateRegistry", 2);
411
- return {
412
- newThreshold: toU32(raw[0], "updateRegistry.newThreshold"),
413
- newMembers: toArray(raw[1], "updateRegistry.newMembers").map((m, i) => toBytes(m, `updateRegistry.newMembers[${i}]`, ADDRESS_LEN)),
414
- };
415
- }
416
- function decodeCancelAllOrdersForAccount(value) {
417
- const raw = toTuple(value, "cancelAllOrdersForAccount", 2);
418
- const market = raw[1];
419
- return {
420
- owner: toBytes(raw[0], "cancelAllOrdersForAccount.owner", ADDRESS_LEN),
421
- market: market === null || market === undefined
422
- ? null
423
- : toU32(market, "cancelAllOrdersForAccount.market"),
424
- };
425
- }
426
- const AUTHORITY_DOMAINS = new Set([
427
- "Oracle",
428
- "CexComposite",
429
- "Relayer",
430
- "Custody",
431
- "MarketParams",
432
- "ScheduledOps",
433
- ]);
434
- function decodeAuthorityDomain(value, field) {
435
- if (typeof value === "string" &&
436
- AUTHORITY_DOMAINS.has(value)) {
437
- return value;
438
- }
439
- throw new Error(`governance decode: ${field} is not a known AuthorityDomain: ${JSON.stringify(value)}`);
440
- }
441
- function decodeUpdateAuthoritySet(value) {
442
- const raw = toTuple(value, "updateAuthoritySet", 3);
443
- return {
444
- domain: decodeAuthorityDomain(raw[0], "updateAuthoritySet.domain"),
445
- add: toArray(raw[1], "updateAuthoritySet.add").map((a, i) => toBytes(a, `updateAuthoritySet.add[${i}]`, ADDRESS_LEN)),
446
- remove: toArray(raw[2], "updateAuthoritySet.remove").map((a, i) => toBytes(a, `updateAuthoritySet.remove[${i}]`, ADDRESS_LEN)),
447
- };
448
- }
449
- function decodeSetOracleGuards(value) {
450
- const raw = toTuple(value, "setOracleGuards", 3);
451
- const guards = {
452
- market: toU32(raw[0], "setOracleGuards.market"),
453
- markPriceMaxOracleAgeMs: raw[1] == null
454
- ? null
455
- : toU64(raw[1], "setOracleGuards.markPriceMaxOracleAgeMs"),
456
- maxOracleDeviationBps: raw[2] == null
457
- ? null
458
- : toU32(raw[2], "setOracleGuards.maxOracleDeviationBps"),
459
- };
460
- validateSetOracleGuards(guards);
461
- return guards;
462
- }
463
- function decodeScheduleUpgrade(value) {
464
- const raw = toTuple(value, "scheduleUpgrade", 4);
465
- const plan = {
466
- targetHeight: toU64(raw[0], "scheduleUpgrade.targetHeight"),
467
- major: toU32(raw[1], "scheduleUpgrade.major"),
468
- minor: toU32(raw[2], "scheduleUpgrade.minor"),
469
- successorSha256: toBytes(raw[3], "scheduleUpgrade.successorSha256", 32),
470
- };
471
- validateScheduleUpgrade(plan);
472
- return plan;
473
- }
474
- function decodeCancelUpgrade(value) {
475
- const raw = toTuple(value, "cancelUpgrade", 1);
476
- return { targetHeight: toU64(raw[0], "cancelUpgrade.targetHeight") };
477
- }
478
- function decodeSetTriggerMarketConfig(value) {
479
- const raw = toTuple(value, "setTriggerMarketConfig", 7);
480
- if (typeof raw[2] !== "boolean") {
481
- throw new Error("governance decode: setTriggerMarketConfig.enabled is not boolean");
482
- }
483
- return {
484
- market: toU32(raw[0], "setTriggerMarketConfig.market"),
485
- expectedCurrentVersion: raw[1] == null
486
- ? null
487
- : toU64(raw[1], "setTriggerMarketConfig.expectedCurrentVersion"),
488
- enabled: raw[2],
489
- maxTriggerSlippageBps: toU32(raw[3], "setTriggerMarketConfig.maxTriggerSlippageBps"),
490
- maxMarkAgeMs: toU64(raw[4], "setTriggerMarketConfig.maxMarkAgeMs"),
491
- maxFuturePublishSkewMs: toU64(raw[5], "setTriggerMarketConfig.maxFuturePublishSkewMs"),
492
- maxActiveBrackets: toU64(raw[6], "setTriggerMarketConfig.maxActiveBrackets"),
493
- };
494
- }
495
- function decodeInsuranceAllocations(raw, field) {
496
- return toArray(raw, `${field}.allocations`).map((value, i) => {
497
- const at = `${field}.allocations[${i}]`;
498
- const row = toTuple(value, at, 2);
499
- return {
500
- poolId: toU8(row[0], `${at}.poolId`),
501
- amount: toU64(row[1], `${at}.amount`),
502
- };
503
- });
504
- }
505
173
  /** `kind` → the engine's `AdminActionType` tag, as a TABLE rather than
506
174
  * arithmetic: a new arm added to `decodeAdminAction` without a row here is
507
175
  * a compile error (`Record` over the closed union), never a silently
@@ -521,6 +189,8 @@ export const ACTION_TAG_BY_KIND = {
521
189
  SetOracleGuards: 13,
522
190
  FundInsuranceFund: 18,
523
191
  WithdrawInsuranceFund: 25,
192
+ ExecInsuranceFund: 26,
193
+ SetMarginOffsetPolicy: 27,
524
194
  ScheduleUpgrade: 14,
525
195
  CancelUpgrade: 15,
526
196
  SetWithdrawalLimit: 19,
@@ -528,124 +198,17 @@ export const ACTION_TAG_BY_KIND = {
528
198
  SetOperatorReceiptRegistry: 20,
529
199
  EnableSubAccounts: 21,
530
200
  };
531
- /** The typed inner operation a proposal carries. Fails closed on an unknown
532
- * variant: an SDK build that does not know an operation must never let a
533
- * caller render or approve it as though it did. */
201
+ /** The typed inner operation a proposal carries, decoded as the wire's
202
+ * `AdminAction` in the Rust core. Fails closed on an unknown variant: an SDK
203
+ * build that does not know an operation must never let a caller render or
204
+ * approve it as though it did. */
534
205
  export function decodeAdminAction(value, field = "action") {
535
- // Unit variants (no fields) arrive as a bare string, not a single-entry map.
536
- // Only the known unit variants are accepted here; any other bare string falls
537
- // through to `variantOf`, which rejects it as "not an enum variant".
538
- if (value === "UnpauseBridge")
539
- return { kind: "UnpauseBridge" };
540
- if (value === "EnableSubAccounts")
541
- return { kind: "EnableSubAccounts" };
542
- const { name, payload } = variantOf(value, field);
543
- switch (name) {
544
- case "FundInsuranceFund": {
545
- const raw = toTuple(payload, field, 3);
546
- const decoded = {
547
- kind: "FundInsuranceFund",
548
- value: {
549
- fundingId: toU64(raw[0], `${field}.fundingId`),
550
- source: toBytes(raw[1], `${field}.source`, ADDRESS_LEN),
551
- allocations: decodeInsuranceAllocations(raw[2], field),
552
- },
553
- };
554
- validateFundInsuranceFund(decoded.value);
555
- return decoded;
556
- }
557
- case "WithdrawInsuranceFund": {
558
- const raw = toTuple(payload, field, 3);
559
- const decoded = {
560
- withdrawalId: toU64(raw[0], `${field}.withdrawalId`),
561
- recipient: toBytes(raw[1], `${field}.recipient`, ADDRESS_LEN),
562
- allocations: decodeInsuranceAllocations(raw[2], field),
563
- };
564
- validateWithdrawInsuranceFund(decoded);
565
- return { kind: "WithdrawInsuranceFund", value: decoded };
566
- }
567
- case "CancelAllOrdersForAccount":
568
- return {
569
- kind: "CancelAllOrdersForAccount",
570
- value: decodeCancelAllOrdersForAccount(payload),
571
- };
572
- case "SetOracleGuards":
573
- return {
574
- kind: "SetOracleGuards",
575
- value: decodeSetOracleGuards(payload),
576
- };
577
- case "SetWithdrawalLimit":
578
- return {
579
- kind: "SetWithdrawalLimit",
580
- value: decodeSetWithdrawalLimit(payload),
581
- };
582
- case "SetLiquidationConfig":
583
- return {
584
- kind: "SetLiquidationConfig",
585
- value: decodeSetLiquidationConfig(payload),
586
- };
587
- case "SetOperatorReceiptRegistry":
588
- return {
589
- kind: "SetOperatorReceiptRegistry",
590
- value: decodeSetOperatorReceiptRegistry(payload),
591
- };
592
- case "ConfigureOraclePolicy": {
593
- const raw = toTuple(payload, "configureOraclePolicy", 2);
594
- return {
595
- kind: "ConfigureOraclePolicy",
596
- value: {
597
- effectiveHeight: toU64(raw[0], "configureOraclePolicy.effectiveHeight"),
598
- bundle: toBytes(raw[1], "configureOraclePolicy.bundle"),
599
- },
600
- };
601
- }
602
- case "CreateMarket":
603
- return {
604
- kind: "CreateMarket",
605
- value: decodeCreateMarket(payload),
606
- };
607
- case "UpdateAdminSignerRegistry":
608
- return {
609
- kind: "UpdateAdminSignerRegistry",
610
- value: decodeUpdateRegistry(payload),
611
- };
612
- case "CreateEvent":
613
- return {
614
- kind: "CreateEvent",
615
- value: decodeCreateEvent(payload),
616
- };
617
- case "AttachConditional":
618
- return {
619
- kind: "AttachConditional",
620
- value: decodeAttachConditional(payload),
621
- };
622
- case "Batch":
623
- return {
624
- kind: "Batch",
625
- value: toArray(payload, `${field}.batch`).map((item, i) => decodeBatchItem(item, `${field}.batch[${i}]`)),
626
- };
627
- case "SetTriggerMarketConfig":
628
- return {
629
- kind: "SetTriggerMarketConfig",
630
- value: decodeSetTriggerMarketConfig(payload),
631
- };
632
- case "UpdateAuthoritySet":
633
- return {
634
- kind: "UpdateAuthoritySet",
635
- value: decodeUpdateAuthoritySet(payload),
636
- };
637
- case "ScheduleUpgrade":
638
- return {
639
- kind: "ScheduleUpgrade",
640
- value: decodeScheduleUpgrade(payload),
641
- };
642
- case "CancelUpgrade":
643
- return {
644
- kind: "CancelUpgrade",
645
- value: decodeCancelUpgrade(payload),
646
- };
647
- default:
648
- throw new Error(`governance decode: ${field} has unknown AdminAction variant "${name}" — this SDK build cannot render it`);
206
+ try {
207
+ const wasm = getWasm();
208
+ return adminActionFromWasm(wasm.decode_read(wasm.ReadKind.AdminAction, actionEncoder.encode(integral(value))));
209
+ }
210
+ catch (e) {
211
+ throw new Error(`governance decode: ${field}: ${e instanceof Error ? e.message : String(e)}`);
649
212
  }
650
213
  }
651
214
  /** Proposal status. Unit variants are strings, payload variants are
@@ -805,6 +368,14 @@ export function decodeUpgradesInfo(raw) {
805
368
  });
806
369
  return { plan, executed };
807
370
  }
371
+ /** Decode `GET /v1/liquidation-config`: `[sequence, config]`. */
372
+ export function decodeLiquidationConfigInfo(raw) {
373
+ const fields = toTuple(raw, "liquidationConfig", 2);
374
+ return {
375
+ sequence: toU64(fields[0], "liquidationConfig.sequence"),
376
+ config: decodeLiquidationConfigTuple(fields[1], "liquidationConfig.config"),
377
+ };
378
+ }
808
379
  /** Validate the node's JSON `GET /v1/version` body. */
809
380
  export function decodeNodeVersion(raw) {
810
381
  if (raw == null || typeof raw !== "object" || Array.isArray(raw)) {