@canton-network/core-tx-parser 1.14.0 → 1.16.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.
package/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- //#region \0rolldown/runtime.js
2
+ // \0rolldown/runtime.js
3
3
  var __create = Object.create;
4
4
  var __defProp = Object.defineProperty;
5
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -20,12 +20,12 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
20
20
  value: mod,
21
21
  enumerable: true
22
22
  }) : target, mod));
23
- //#endregion
24
23
  let _canton_network_core_token_standard = require("@canton-network/core-token-standard");
25
24
  let _canton_network_core_ledger_client_types = require("@canton-network/core-ledger-client-types");
26
25
  let bignumber_js = require("bignumber.js");
27
26
  bignumber_js = __toESM(bignumber_js, 1);
28
- //#region src/constants.ts
27
+ let _canton_network_core_token_standard_v2 = require("@canton-network/core-token-standard-v2");
28
+ // src/constants.ts
29
29
  function splitInterfaceId(interfaceId) {
30
30
  const match = /^#?([^:]+):([^:]+):([^:]+)$/.exec(interfaceId);
31
31
  if (!match) return null;
@@ -61,8 +61,7 @@ const AllKnownMetaKeys = [
61
61
  ReasonMetaKey,
62
62
  BurnedMetaKey
63
63
  ];
64
- //#endregion
65
- //#region src/utils.ts
64
+ // src/utils.ts
66
65
  function hasInterface(interfaceId, event) {
67
66
  return (event.implementedInterfaces || []).some((id) => matchInterfaceIds(id, interfaceId));
68
67
  }
@@ -88,10 +87,9 @@ function getKnownInterfaceView(createdEvent) {
88
87
  * include it, and thus is guaranteed to be returned by the API.
89
88
  */
90
89
  function ensureInterfaceViewIsPresent(createdEvent, interfaceId) {
91
- const interfaceView = getInterfaceView(createdEvent);
92
- if (!interfaceView) throw new Error(`Expected to have interface views, but didn't: ${JSON.stringify(createdEvent)}`);
93
- if (!interfaceView.interfaceId || !matchInterfaceIds(interfaceId, interfaceView.interfaceId)) throw new Error(`Not a ${interfaceId} but a ${interfaceView.interfaceId}: ${JSON.stringify(createdEvent)}`);
94
- return interfaceView;
90
+ const view = createdEvent.interfaceViews?.find((v) => v.interfaceId && matchInterfaceIds(interfaceId, v.interfaceId));
91
+ if (!view) throw new Error(`Expected to ${createdEvent.contractId} to implement ${interfaceId} found: ${JSON.stringify(createdEvent.interfaceViews?.map((v) => v.interfaceId))}`);
92
+ return view;
95
93
  }
96
94
  function mergeMetas(event, extra) {
97
95
  const choiceArgument = event.choiceArgument;
@@ -123,8 +121,7 @@ function getMetaKeyValue(key, meta) {
123
121
  function removeParsedMetaKeys(meta) {
124
122
  return { values: Object.fromEntries(Object.entries(meta?.values || {}).filter(([k]) => !AllKnownMetaKeys.includes(k))) };
125
123
  }
126
- //#endregion
127
- //#region src/types.ts
124
+ // src/types.ts
128
125
  const renderTransaction = (t) => {
129
126
  return {
130
127
  ...t,
@@ -164,8 +161,7 @@ const renderHoldingsChange = (c) => {
164
161
  ...c.archives.length !== 0 && { archives: c.archives }
165
162
  };
166
163
  };
167
- //#endregion
168
- //#region \0@oxc-project+runtime@0.153.0/helpers/esm/typeof.js
164
+ // \0@oxc-project+runtime@0.155.0/helpers/esm/typeof.js
169
165
  function _typeof(o) {
170
166
  "@babel/helpers - typeof";
171
167
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -174,8 +170,7 @@ function _typeof(o) {
174
170
  return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
175
171
  }, _typeof(o);
176
172
  }
177
- //#endregion
178
- //#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPrimitive.js
173
+ // \0@oxc-project+runtime@0.155.0/helpers/esm/toPrimitive.js
179
174
  function toPrimitive(t, r) {
180
175
  if ("object" != _typeof(t) || !t) return t;
181
176
  var e = t[Symbol.toPrimitive];
@@ -186,14 +181,12 @@ function toPrimitive(t, r) {
186
181
  }
187
182
  return ("string" === r ? String : Number)(t);
188
183
  }
189
- //#endregion
190
- //#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPropertyKey.js
184
+ // \0@oxc-project+runtime@0.155.0/helpers/esm/toPropertyKey.js
191
185
  function toPropertyKey(t) {
192
186
  var i = toPrimitive(t, "string");
193
187
  return "symbol" == _typeof(i) ? i : i + "";
194
188
  }
195
- //#endregion
196
- //#region \0@oxc-project+runtime@0.153.0/helpers/esm/defineProperty.js
189
+ // \0@oxc-project+runtime@0.155.0/helpers/esm/defineProperty.js
197
190
  function _defineProperty(e, r, t) {
198
191
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
199
192
  value: t,
@@ -202,8 +195,7 @@ function _defineProperty(e, r, t) {
202
195
  writable: !0
203
196
  }) : e[r] = t, e;
204
197
  }
205
- //#endregion
206
- //#region src/instrumentmap.ts
198
+ // src/instrumentmap.ts
207
199
  /** InstrumentMap is a helper for when you want to group values by instrument. */
208
200
  var InstrumentMap = class {
209
201
  encodeKey(instrumentId) {
@@ -236,8 +228,132 @@ var InstrumentMap = class {
236
228
  for (const [key, value] of this.map.entries()) yield [this.decodeKey(key), value];
237
229
  }
238
230
  };
239
- //#endregion
240
- //#region src/parser.ts
231
+ // src/v2-events.ts
232
+ const MINT_ACCOUNT_ID = "cip-112/mint";
233
+ const BURN_ACCOUNT_ID = "cip-112/burn";
234
+ function extractHoldingsChange(exercised) {
235
+ if (exercised.choice !== "EventLog_HoldingsChange" || !exercised.interfaceId || !matchInterfaceIds(_canton_network_core_token_standard_v2.EVENT_LOG_INTERFACE_ID, exercised.interfaceId)) return null;
236
+ return exercised.choiceArgument;
237
+ }
238
+ function getHoldingViewV2(createdEvent) {
239
+ return (createdEvent.interfaceViews?.find((v) => v.interfaceId && matchInterfaceIds(_canton_network_core_token_standard_v2.HOLDING_INTERFACE_ID_V2, v.interfaceId)))?.viewValue ?? null;
240
+ }
241
+ function sameAccount(a, b) {
242
+ return (a.owner ?? null) === (b.owner ?? null) && (a.provider ?? null) === (b.provider ?? null) && a.id === b.id;
243
+ }
244
+ function netChangeCids(change) {
245
+ const inputs = change.inputHoldingCids;
246
+ const outputs = change.outputHoldingCids;
247
+ return {
248
+ inputs: inputs.filter((cid) => !outputs.includes(cid)),
249
+ outputs: outputs.filter((cid) => !inputs.includes(cid))
250
+ };
251
+ }
252
+ /**
253
+ * Holding cids an EventLog_HoldingsChange refers to
254
+ */
255
+ function holdingCidsOf(change) {
256
+ return [...change.inputHoldingCids, ...change.outputHoldingCids];
257
+ }
258
+ function toHolding(cid, view) {
259
+ return {
260
+ contractId: cid,
261
+ owner: view.account.owner ?? "",
262
+ account: view.account,
263
+ instrumentId: view.instrumentId,
264
+ amount: view.amount,
265
+ lock: view.lock ?? null,
266
+ meta: view.meta
267
+ };
268
+ }
269
+ const isSpecialAccount = (account, id) => account.owner == null && account.id === id;
270
+ const sumAmounts = (legs) => legs.reduce((sum, leg) => sum.plus(leg.amount), new bignumber_js.default(0));
271
+ function deriveV2Label(opts) {
272
+ const { change, parentChoice, tokenStandardChoice, onlyUnlocks } = opts;
273
+ const meta = change.extraArgs.meta;
274
+ const legReasons = [...new Set(change.transferLegSides.map((l) => getMetaKeyValue(ReasonMetaKey, l.meta)).filter((r) => !!r))];
275
+ const reason = getMetaKeyValue("splice.lfdecentralizedtrust.org/reason", meta) ?? (legReasons.length === 1 ? legReasons[0] : null);
276
+ const v2 = {
277
+ admin: change.admin,
278
+ account: change.account,
279
+ transferLegSides: change.transferLegSides,
280
+ parentChoice
281
+ };
282
+ const external = change.transferLegSides.filter((l) => !sameAccount(l.otherside, change.account));
283
+ const sent = external.filter((l) => l.side === "SenderSide");
284
+ const received = external.filter((l) => l.side === "ReceiverSide");
285
+ const burned = sent.filter((l) => isSpecialAccount(l.otherside, BURN_ACCOUNT_ID));
286
+ const minted = received.filter((l) => isSpecialAccount(l.otherside, MINT_ACCOUNT_ID));
287
+ const transfersOut = sent.filter((l) => !burned.includes(l));
288
+ const transfersIn = received.filter((l) => !minted.includes(l));
289
+ const common = {
290
+ burnAmount: sumAmounts(burned).toString(),
291
+ mintAmount: sumAmounts(minted).toString(),
292
+ tokenStandardChoice,
293
+ reason,
294
+ meta,
295
+ v2
296
+ };
297
+ const noTransferType = () => burned.length > 0 && minted.length === 0 ? "Burn" : minted.length > 0 && burned.length === 0 ? "Mint" : change.transferLegSides.length === 0 && onlyUnlocks ? "Unlock" : "MergeSplit";
298
+ if (transfersOut.length === 0 && transfersIn.length === 0) return {
299
+ ...common,
300
+ type: noTransferType()
301
+ };
302
+ const net = /* @__PURE__ */ new Map();
303
+ for (const l of [...transfersOut, ...transfersIn]) {
304
+ const counterparty = l.otherside.owner ?? l.otherside.id;
305
+ const key = JSON.stringify([counterparty, l.instrumentId]);
306
+ const entry = net.get(key) ?? {
307
+ counterparty,
308
+ instrumentId: l.instrumentId,
309
+ amount: new bignumber_js.default(0)
310
+ };
311
+ entry.amount = l.side === "SenderSide" ? entry.amount.plus(l.amount) : entry.amount.minus(l.amount);
312
+ net.set(key, entry);
313
+ }
314
+ const outs = [...net.values()].filter((e) => e.amount.gt(0));
315
+ const ins = [...net.values()].filter((e) => e.amount.lt(0));
316
+ const instrument = (id) => ({
317
+ admin: change.admin,
318
+ id
319
+ });
320
+ if (outs.length === 0 && ins.length === 0) return {
321
+ ...common,
322
+ type: noTransferType()
323
+ };
324
+ if (outs.length > 0 && ins.length > 0) return {
325
+ ...common,
326
+ type: "Settlement",
327
+ netTransfers: [...outs, ...ins].map((e) => ({
328
+ counterparty: e.counterparty,
329
+ amount: e.amount.toString(),
330
+ instrumentId: instrument(e.instrumentId)
331
+ }))
332
+ };
333
+ if (outs.length > 0) return {
334
+ ...common,
335
+ type: "TransferOut",
336
+ receiverAmounts: outs.map((e) => ({
337
+ receiver: e.counterparty,
338
+ amount: e.amount.toString(),
339
+ instrumentId: instrument(e.instrumentId)
340
+ }))
341
+ };
342
+ const senders = [...new Set(ins.map((l) => l.counterparty))];
343
+ return {
344
+ ...common,
345
+ type: "TransferIn",
346
+ burnAmount: "0",
347
+ mintAmount: "0",
348
+ sender: senders.length === 1 ? senders[0] : senders.join(","),
349
+ senderAmounts: ins.map((l) => ({
350
+ sender: l.counterparty,
351
+ amount: l.amount.negated().toString(),
352
+ instrumentId: instrument(l.instrumentId)
353
+ }))
354
+ };
355
+ }
356
+ // src/parser.ts
241
357
  function currentStatusFromChoiceOrResult(choice, resultTag) {
242
358
  if (resultTag === "TransferInstructionResult_Failed") return "Failed";
243
359
  if (resultTag === "TransferInstructionResult_Completed") return "Completed";
@@ -270,6 +386,7 @@ var TransactionParser = class {
270
386
  _defineProperty(this, "partyId", void 0);
271
387
  _defineProperty(this, "transaction", void 0);
272
388
  _defineProperty(this, "isMasterUser", void 0);
389
+ _defineProperty(this, "explainedCids", /* @__PURE__ */ new Set());
273
390
  this.ledgerProvider = ledgerProvider;
274
391
  this.partyId = partyId;
275
392
  this.transaction = transaction;
@@ -304,14 +421,44 @@ var TransactionParser = class {
304
421
  }
305
422
  return result;
306
423
  }
424
+ async fetchContractEvents(contractId, interfaceIds) {
425
+ const body = {
426
+ contractId,
427
+ eventFormat: (0, _canton_network_core_ledger_client_types.EventFilterBySetup)({
428
+ interfaceIds,
429
+ isMasterUser: this.isMasterUser,
430
+ partyId: this.partyId,
431
+ verbose: true
432
+ })
433
+ };
434
+ const events = await this.ledgerProvider.request({
435
+ method: "ledgerApi",
436
+ params: {
437
+ resource: "/v2/events/events-by-contract-id",
438
+ requestMethod: "post",
439
+ body
440
+ }
441
+ }).catch((err) => {
442
+ if (isContractEventsNotFoundError(err)) return null;
443
+ throw err;
444
+ });
445
+ if (!events) return null;
446
+ return {
447
+ created: events.created,
448
+ archived: events.archived
449
+ };
450
+ }
307
451
  async parseEvents(eventsStack) {
452
+ const v2 = await this.collectV2Events();
453
+ this.explainedCids = v2.explained;
454
+ const v1Events = [];
455
+ const contextOnly = [];
308
456
  let callStack = [];
309
457
  let continueAfterNodeId = -1;
310
- const result = [];
311
458
  while (eventsStack.length > 0) {
312
459
  const currentEvent = eventsStack.pop();
313
460
  const { nodeId, createdEvent, archivedEvent, exercisedEvent } = getNodeIdAndEvent(currentEvent);
314
- callStack = callStack.filter((s) => s.untilNodeId <= nodeId);
461
+ callStack = callStack.filter((s) => s.untilNodeId >= nodeId);
315
462
  const parentChoice = callStack[callStack.length - 1] && callStack[callStack.length - 1].parentChoiceName || "none (root node)";
316
463
  let parsed;
317
464
  if (nodeId <= continueAfterNodeId) parsed = null;
@@ -320,22 +467,56 @@ var TransactionParser = class {
320
467
  else if (exercisedEvent) parsed = await this.parseExercise(exercisedEvent);
321
468
  else throw new Error(`Impossible event: ${JSON.stringify(currentEvent)}`);
322
469
  if (parsed && isLeafEventNode(parsed)) {
323
- if (holdingChangesNonEmpty(parsed.event) || parsed.event.transferInstruction?.transfer != null) result.push({
324
- ...parsed.event,
325
- label: {
326
- ...parsed.event.label,
327
- meta: removeParsedMetaKeys(parsed.event.label.meta)
470
+ const emittedV1 = {
471
+ nodeId,
472
+ lastNodeId: parsed.continueAfterNodeId,
473
+ event: {
474
+ ...parsed.event,
475
+ label: {
476
+ ...parsed.event.label,
477
+ meta: removeParsedMetaKeys(parsed.event.label.meta)
478
+ }
328
479
  }
329
- });
480
+ };
481
+ if (holdingChangesNonEmpty(parsed.event) || parsed.event.transferInstruction?.transfer != null) v1Events.push(emittedV1);
482
+ else if (choiceOf(emittedV1)) contextOnly.push(emittedV1);
330
483
  continueAfterNodeId = parsed.continueAfterNodeId;
331
484
  } else if (parsed) callStack.push({
332
485
  parentChoiceName: parsed.parentChoiceName,
333
486
  untilNodeId: parsed.lastDescendantNodeId
334
487
  });
335
488
  }
336
- return result;
489
+ for (const v1 of [...v1Events, ...contextOnly]) {
490
+ const choice = choiceOf(v1);
491
+ if (!choice) continue;
492
+ for (const e of v2.events) if (e.nodeId >= v1.nodeId && e.nodeId <= v1.lastNodeId) e.event.label.tokenStandardChoice = choice;
493
+ }
494
+ const kept = [];
495
+ for (const v1 of v1Events) {
496
+ const ti = v1.event.transferInstruction;
497
+ if (holdingChangesNonEmpty(v1.event) || ti?.transfer == null) {
498
+ kept.push(v1);
499
+ continue;
500
+ }
501
+ const inRange = v2.events.filter((e) => e.nodeId >= v1.nodeId && e.nodeId <= v1.lastNodeId && e.event.transferInstruction == null);
502
+ const target = inRange.find(hasExternalLegs) ?? inRange[0];
503
+ if (target) target.event.transferInstruction = ti;
504
+ else kept.push(v1);
505
+ }
506
+ const cleanupV2 = v2.events.map((e) => ({
507
+ ...e,
508
+ event: {
509
+ ...e.event,
510
+ label: {
511
+ ...e.event.label,
512
+ meta: removeParsedMetaKeys(e.event.label.meta)
513
+ }
514
+ }
515
+ }));
516
+ return [...kept, ...cleanupV2].sort((a, b) => a.nodeId - b.nodeId).map((e) => e.event);
337
517
  }
338
518
  parseRawCreate(create, parentChoice) {
519
+ if (this.explainedCids.has(create.contractId)) return null;
339
520
  return this.buildRawEvent(create, create.nodeId, (result) => {
340
521
  return {
341
522
  type: Number(result.lockedHoldingsChangeSummaries[0]?.amountChange) > 0 ? "Lock" : "Create",
@@ -350,6 +531,7 @@ var TransactionParser = class {
350
531
  });
351
532
  }
352
533
  async parseRawArchive(archive, parentChoice) {
534
+ if (this.explainedCids.has(archive.contractId)) return null;
353
535
  const events = await this.getEventsForArchive(archive);
354
536
  if (!events) return null;
355
537
  return this.buildRawEvent(events.created.createdEvent, archive.nodeId, (result) => {
@@ -536,7 +718,7 @@ var TransactionParser = class {
536
718
  const reason = getMetaKeyValue(ReasonMetaKey, meta);
537
719
  const rawTransferArg = exercisedEvent.choiceArgument.transfer;
538
720
  const choiceArgumentTransfer = rawTransferArg?.receiver != null && rawTransferArg?.amount != null ? rawTransferArg : void 0;
539
- const sender = transferInstructions?.transfer?.sender || getMetaKeyValue(SenderMetaKey, meta) || rawTransferArg?.sender;
721
+ const sender = transferInstructions?.transfer?.sender || getMetaKeyValue("splice.lfdecentralizedtrust.org/sender", meta) || rawTransferArg?.sender;
540
722
  if (!sender) {
541
723
  console.error(`Malformed transfer didn't contain sender. Will instead attempt to parse the children.
542
724
  Transfer: ${JSON.stringify(exercisedEvent)}`);
@@ -713,33 +895,15 @@ var TransactionParser = class {
713
895
  mutatingResult.archives.push(toHoldingWithContractId(holdingView, archivedEvent?.contractId || exercisedEvent.contractId));
714
896
  }
715
897
  }
898
+ const unxplained = (h) => !this.explainedCids.has(h.contractId);
716
899
  return {
717
- creates: mutatingResult.creates.filter((create) => !mutatingResult.archives.some((archive) => create.contractId === archive.contractId)),
718
- archives: mutatingResult.archives.filter((archive) => !mutatingResult.creates.some((create) => create.contractId === archive.contractId))
900
+ creates: mutatingResult.creates.filter((create) => !mutatingResult.archives.some((archive) => create.contractId === archive.contractId)).filter(unxplained),
901
+ archives: mutatingResult.archives.filter((archive) => !mutatingResult.creates.some((create) => create.contractId === archive.contractId)).filter(unxplained)
719
902
  };
720
903
  }
721
904
  async getEventsForArchive(archivedEvent) {
722
905
  if (!(archivedEvent.witnessParties || []).includes(this.partyId)) return null;
723
- const basePayload = {
724
- contractId: archivedEvent.contractId,
725
- eventFormat: (0, _canton_network_core_ledger_client_types.EventFilterBySetup)({
726
- interfaceIds: [_canton_network_core_token_standard.HOLDING_INTERFACE_ID, _canton_network_core_token_standard.TRANSFER_INSTRUCTION_INTERFACE_ID],
727
- isMasterUser: this.isMasterUser,
728
- partyId: this.partyId,
729
- verbose: true
730
- })
731
- };
732
- const events = await this.ledgerProvider.request({
733
- method: "ledgerApi",
734
- params: {
735
- resource: "/v2/events/events-by-contract-id",
736
- requestMethod: "post",
737
- body: basePayload
738
- }
739
- }).catch((err) => {
740
- if (isContractEventsNotFoundError(err)) return null;
741
- else throw err;
742
- });
906
+ const events = await this.fetchContractEvents(archivedEvent.contractId, [_canton_network_core_token_standard.HOLDING_INTERFACE_ID, _canton_network_core_token_standard.TRANSFER_INSTRUCTION_INTERFACE_ID]);
743
907
  if (!events) return null;
744
908
  const created = events.created;
745
909
  const archived = events.archived;
@@ -749,6 +913,84 @@ var TransactionParser = class {
749
913
  archived
750
914
  };
751
915
  }
916
+ async collectV2Events() {
917
+ const views = /* @__PURE__ */ new Map();
918
+ const emitted = [];
919
+ const explained = /* @__PURE__ */ new Set();
920
+ let stack = [];
921
+ for (const raw of this.transaction.events ?? []) {
922
+ const { nodeId, createdEvent, exercisedEvent } = getNodeIdAndEvent(raw);
923
+ stack = stack.filter((s) => s.until >= nodeId);
924
+ const parentChoice = stack.at(-1)?.choice ?? "none (root node)";
925
+ if (createdEvent) {
926
+ const view = getHoldingViewV2(createdEvent);
927
+ if (view) views.set(createdEvent.contractId, view);
928
+ }
929
+ if (!exercisedEvent) continue;
930
+ stack.push({
931
+ choice: exercisedEvent.choice,
932
+ until: exercisedEvent.lastDescendantNodeId
933
+ });
934
+ const change = extractHoldingsChange(exercisedEvent);
935
+ if (!change || change.account.owner !== this.partyId) continue;
936
+ const { inputs, outputs } = netChangeCids(change);
937
+ const resolve = (cid) => this.resolveV2Holding(cid, views);
938
+ const ins = (await Promise.all(inputs.map(resolve))).filter((h) => h !== null);
939
+ const outs = (await Promise.all(outputs.map(resolve))).filter((h) => h !== null);
940
+ if ([...ins, ...outs].some((h) => h.instrumentId.admin !== change.admin || !sameAccount(h.account, change.account))) {
941
+ console.warn(`Ignoring EventLog_holdingsChange at node ${nodeId}: holdings do not match admin/account`);
942
+ continue;
943
+ }
944
+ const lockedHoldingsChange = {
945
+ creates: outs.filter((h) => !!h.lock),
946
+ archives: ins.filter((h) => !!h.lock)
947
+ };
948
+ const unlockedHoldingsChange = {
949
+ creates: outs.filter((h) => !h.lock),
950
+ archives: ins.filter((h) => !h.lock)
951
+ };
952
+ const lockedHoldingsChangeSummaries = computeSummaries(lockedHoldingsChange, this.partyId);
953
+ const unlockedHoldingsChangeSummaries = computeSummaries(unlockedHoldingsChange, this.partyId);
954
+ const event = {
955
+ label: deriveV2Label({
956
+ change,
957
+ parentChoice,
958
+ tokenStandardChoice: {
959
+ name: exercisedEvent.choice,
960
+ choiceArgument: exercisedEvent.choiceArgument,
961
+ exerciseResult: exercisedEvent.exerciseResult
962
+ },
963
+ onlyUnlocks: lockedHoldingsChange.creates.length === 0 && lockedHoldingsChange.archives.length > 0
964
+ }),
965
+ lockedHoldingsChange,
966
+ lockedHoldingsChangeSummaries,
967
+ lockedHoldingsChangeSummary: lockedHoldingsChangeSummaries[0] ?? emptyHoldingsChangeSummary,
968
+ unlockedHoldingsChange,
969
+ unlockedHoldingsChangeSummaries,
970
+ unlockedHoldingsChangeSummary: unlockedHoldingsChangeSummaries[0] ?? emptyHoldingsChangeSummary,
971
+ transferInstruction: null
972
+ };
973
+ holdingCidsOf(change).forEach((cid) => explained.add(cid));
974
+ if (holdingChangesNonEmpty(event) || change.transferLegSides.length > 0) emitted.push({
975
+ nodeId,
976
+ lastNodeId: nodeId,
977
+ event
978
+ });
979
+ }
980
+ return {
981
+ events: emitted,
982
+ explained
983
+ };
984
+ }
985
+ async resolveV2Holding(cid, views) {
986
+ const cached = views.get(cid);
987
+ if (cached) return toHolding(cid, cached);
988
+ const events = await this.fetchContractEvents(cid, [_canton_network_core_token_standard_v2.HOLDING_INTERFACE_ID_V2]);
989
+ const view = events?.created?.createdEvent && getHoldingViewV2(events.created.createdEvent);
990
+ if (!view) return null;
991
+ views.set(cid, view);
992
+ return toHolding(cid, view);
993
+ }
752
994
  };
753
995
  function isLeafEventNode(result) {
754
996
  return !!result.event;
@@ -771,7 +1013,7 @@ function getNodeIdAndEvent(event) {
771
1013
  nodeId: event.ArchivedEvent.nodeId,
772
1014
  archivedEvent: event.ArchivedEvent
773
1015
  };
774
- else throw new Error(`Impossible event type: ${event}`);
1016
+ else throw new Error(`Impossible event type: ${String(event)}`);
775
1017
  }
776
1018
  /** sumHoldingsChange sums all the changes over a number of holdings.
777
1019
  * Note that this function currently assumes all holdings use the same
@@ -793,7 +1035,7 @@ function toHoldingWithContractId(holding, contractId) {
793
1035
  };
794
1036
  }
795
1037
  function computeAmountChanges(children, meta, partyId) {
796
- const burnAmount = (0, bignumber_js.default)(getMetaKeyValue(BurnedMetaKey, meta) || "0");
1038
+ const burnAmount = (0, bignumber_js.default)(getMetaKeyValue("splice.lfdecentralizedtrust.org/burned", meta) || "0");
797
1039
  const partyHoldingAmountChange = sumHoldingsChange(children, (owner) => owner === partyId);
798
1040
  const otherPartiesHoldingAmountChange = sumHoldingsChange(children, (owner) => owner !== partyId);
799
1041
  const mintAmount = partyHoldingAmountChange.plus(burnAmount).plus(otherPartiesHoldingAmountChange);
@@ -860,7 +1102,13 @@ const emptyHoldingsChangeSummary = {
860
1102
  outputAmount: "0",
861
1103
  amountChange: "0"
862
1104
  };
863
- //#endregion
1105
+ function hasExternalLegs(e) {
1106
+ const v2Label = e.event.label.v2;
1107
+ return !!v2Label?.transferLegSides.some((l) => !sameAccount(l.otherside, v2Label.account));
1108
+ }
1109
+ function choiceOf(e) {
1110
+ return e.event.label.tokenStandardChoice ?? null;
1111
+ }
864
1112
  exports.AllKnownMetaKeys = AllKnownMetaKeys;
865
1113
  exports.BurnedMetaKey = BurnedMetaKey;
866
1114
  exports.ReasonMetaKey = ReasonMetaKey;