@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.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import { ALLOCATION_FACTORY_INTERFACE_ID, ALLOCATION_INSTRUCTION_INTERFACE_ID, ALLOCATION_INTERFACE_ID, ALLOCATION_REQUEST_INTERFACE_ID, HOLDING_INTERFACE_ID, TRANSFER_FACTORY_INTERFACE_ID, TRANSFER_INSTRUCTION_INTERFACE_ID } from "@canton-network/core-token-standard";
2
2
  import { EventFilterBySetup } from "@canton-network/core-ledger-client-types";
3
3
  import BigNumber from "bignumber.js";
4
- //#region src/constants.ts
4
+ import { EVENT_LOG_INTERFACE_ID, HOLDING_INTERFACE_ID_V2 } from "@canton-network/core-token-standard-v2";
5
+ // src/constants.ts
5
6
  function splitInterfaceId(interfaceId) {
6
7
  const match = /^#?([^:]+):([^:]+):([^:]+)$/.exec(interfaceId);
7
8
  if (!match) return null;
@@ -37,8 +38,7 @@ const AllKnownMetaKeys = [
37
38
  ReasonMetaKey,
38
39
  BurnedMetaKey
39
40
  ];
40
- //#endregion
41
- //#region src/utils.ts
41
+ // src/utils.ts
42
42
  function hasInterface(interfaceId, event) {
43
43
  return (event.implementedInterfaces || []).some((id) => matchInterfaceIds(id, interfaceId));
44
44
  }
@@ -64,10 +64,9 @@ function getKnownInterfaceView(createdEvent) {
64
64
  * include it, and thus is guaranteed to be returned by the API.
65
65
  */
66
66
  function ensureInterfaceViewIsPresent(createdEvent, interfaceId) {
67
- const interfaceView = getInterfaceView(createdEvent);
68
- if (!interfaceView) throw new Error(`Expected to have interface views, but didn't: ${JSON.stringify(createdEvent)}`);
69
- if (!interfaceView.interfaceId || !matchInterfaceIds(interfaceId, interfaceView.interfaceId)) throw new Error(`Not a ${interfaceId} but a ${interfaceView.interfaceId}: ${JSON.stringify(createdEvent)}`);
70
- return interfaceView;
67
+ const view = createdEvent.interfaceViews?.find((v) => v.interfaceId && matchInterfaceIds(interfaceId, v.interfaceId));
68
+ if (!view) throw new Error(`Expected to ${createdEvent.contractId} to implement ${interfaceId} found: ${JSON.stringify(createdEvent.interfaceViews?.map((v) => v.interfaceId))}`);
69
+ return view;
71
70
  }
72
71
  function mergeMetas(event, extra) {
73
72
  const choiceArgument = event.choiceArgument;
@@ -99,8 +98,7 @@ function getMetaKeyValue(key, meta) {
99
98
  function removeParsedMetaKeys(meta) {
100
99
  return { values: Object.fromEntries(Object.entries(meta?.values || {}).filter(([k]) => !AllKnownMetaKeys.includes(k))) };
101
100
  }
102
- //#endregion
103
- //#region src/types.ts
101
+ // src/types.ts
104
102
  const renderTransaction = (t) => {
105
103
  return {
106
104
  ...t,
@@ -140,8 +138,7 @@ const renderHoldingsChange = (c) => {
140
138
  ...c.archives.length !== 0 && { archives: c.archives }
141
139
  };
142
140
  };
143
- //#endregion
144
- //#region \0@oxc-project+runtime@0.153.0/helpers/esm/typeof.js
141
+ // \0@oxc-project+runtime@0.155.0/helpers/esm/typeof.js
145
142
  function _typeof(o) {
146
143
  "@babel/helpers - typeof";
147
144
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -150,8 +147,7 @@ function _typeof(o) {
150
147
  return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
151
148
  }, _typeof(o);
152
149
  }
153
- //#endregion
154
- //#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPrimitive.js
150
+ // \0@oxc-project+runtime@0.155.0/helpers/esm/toPrimitive.js
155
151
  function toPrimitive(t, r) {
156
152
  if ("object" != _typeof(t) || !t) return t;
157
153
  var e = t[Symbol.toPrimitive];
@@ -162,14 +158,12 @@ function toPrimitive(t, r) {
162
158
  }
163
159
  return ("string" === r ? String : Number)(t);
164
160
  }
165
- //#endregion
166
- //#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPropertyKey.js
161
+ // \0@oxc-project+runtime@0.155.0/helpers/esm/toPropertyKey.js
167
162
  function toPropertyKey(t) {
168
163
  var i = toPrimitive(t, "string");
169
164
  return "symbol" == _typeof(i) ? i : i + "";
170
165
  }
171
- //#endregion
172
- //#region \0@oxc-project+runtime@0.153.0/helpers/esm/defineProperty.js
166
+ // \0@oxc-project+runtime@0.155.0/helpers/esm/defineProperty.js
173
167
  function _defineProperty(e, r, t) {
174
168
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
175
169
  value: t,
@@ -178,8 +172,7 @@ function _defineProperty(e, r, t) {
178
172
  writable: !0
179
173
  }) : e[r] = t, e;
180
174
  }
181
- //#endregion
182
- //#region src/instrumentmap.ts
175
+ // src/instrumentmap.ts
183
176
  /** InstrumentMap is a helper for when you want to group values by instrument. */
184
177
  var InstrumentMap = class {
185
178
  encodeKey(instrumentId) {
@@ -212,8 +205,132 @@ var InstrumentMap = class {
212
205
  for (const [key, value] of this.map.entries()) yield [this.decodeKey(key), value];
213
206
  }
214
207
  };
215
- //#endregion
216
- //#region src/parser.ts
208
+ // src/v2-events.ts
209
+ const MINT_ACCOUNT_ID = "cip-112/mint";
210
+ const BURN_ACCOUNT_ID = "cip-112/burn";
211
+ function extractHoldingsChange(exercised) {
212
+ if (exercised.choice !== "EventLog_HoldingsChange" || !exercised.interfaceId || !matchInterfaceIds(EVENT_LOG_INTERFACE_ID, exercised.interfaceId)) return null;
213
+ return exercised.choiceArgument;
214
+ }
215
+ function getHoldingViewV2(createdEvent) {
216
+ return (createdEvent.interfaceViews?.find((v) => v.interfaceId && matchInterfaceIds(HOLDING_INTERFACE_ID_V2, v.interfaceId)))?.viewValue ?? null;
217
+ }
218
+ function sameAccount(a, b) {
219
+ return (a.owner ?? null) === (b.owner ?? null) && (a.provider ?? null) === (b.provider ?? null) && a.id === b.id;
220
+ }
221
+ function netChangeCids(change) {
222
+ const inputs = change.inputHoldingCids;
223
+ const outputs = change.outputHoldingCids;
224
+ return {
225
+ inputs: inputs.filter((cid) => !outputs.includes(cid)),
226
+ outputs: outputs.filter((cid) => !inputs.includes(cid))
227
+ };
228
+ }
229
+ /**
230
+ * Holding cids an EventLog_HoldingsChange refers to
231
+ */
232
+ function holdingCidsOf(change) {
233
+ return [...change.inputHoldingCids, ...change.outputHoldingCids];
234
+ }
235
+ function toHolding(cid, view) {
236
+ return {
237
+ contractId: cid,
238
+ owner: view.account.owner ?? "",
239
+ account: view.account,
240
+ instrumentId: view.instrumentId,
241
+ amount: view.amount,
242
+ lock: view.lock ?? null,
243
+ meta: view.meta
244
+ };
245
+ }
246
+ const isSpecialAccount = (account, id) => account.owner == null && account.id === id;
247
+ const sumAmounts = (legs) => legs.reduce((sum, leg) => sum.plus(leg.amount), new BigNumber(0));
248
+ function deriveV2Label(opts) {
249
+ const { change, parentChoice, tokenStandardChoice, onlyUnlocks } = opts;
250
+ const meta = change.extraArgs.meta;
251
+ const legReasons = [...new Set(change.transferLegSides.map((l) => getMetaKeyValue(ReasonMetaKey, l.meta)).filter((r) => !!r))];
252
+ const reason = getMetaKeyValue("splice.lfdecentralizedtrust.org/reason", meta) ?? (legReasons.length === 1 ? legReasons[0] : null);
253
+ const v2 = {
254
+ admin: change.admin,
255
+ account: change.account,
256
+ transferLegSides: change.transferLegSides,
257
+ parentChoice
258
+ };
259
+ const external = change.transferLegSides.filter((l) => !sameAccount(l.otherside, change.account));
260
+ const sent = external.filter((l) => l.side === "SenderSide");
261
+ const received = external.filter((l) => l.side === "ReceiverSide");
262
+ const burned = sent.filter((l) => isSpecialAccount(l.otherside, BURN_ACCOUNT_ID));
263
+ const minted = received.filter((l) => isSpecialAccount(l.otherside, MINT_ACCOUNT_ID));
264
+ const transfersOut = sent.filter((l) => !burned.includes(l));
265
+ const transfersIn = received.filter((l) => !minted.includes(l));
266
+ const common = {
267
+ burnAmount: sumAmounts(burned).toString(),
268
+ mintAmount: sumAmounts(minted).toString(),
269
+ tokenStandardChoice,
270
+ reason,
271
+ meta,
272
+ v2
273
+ };
274
+ const noTransferType = () => burned.length > 0 && minted.length === 0 ? "Burn" : minted.length > 0 && burned.length === 0 ? "Mint" : change.transferLegSides.length === 0 && onlyUnlocks ? "Unlock" : "MergeSplit";
275
+ if (transfersOut.length === 0 && transfersIn.length === 0) return {
276
+ ...common,
277
+ type: noTransferType()
278
+ };
279
+ const net = /* @__PURE__ */ new Map();
280
+ for (const l of [...transfersOut, ...transfersIn]) {
281
+ const counterparty = l.otherside.owner ?? l.otherside.id;
282
+ const key = JSON.stringify([counterparty, l.instrumentId]);
283
+ const entry = net.get(key) ?? {
284
+ counterparty,
285
+ instrumentId: l.instrumentId,
286
+ amount: new BigNumber(0)
287
+ };
288
+ entry.amount = l.side === "SenderSide" ? entry.amount.plus(l.amount) : entry.amount.minus(l.amount);
289
+ net.set(key, entry);
290
+ }
291
+ const outs = [...net.values()].filter((e) => e.amount.gt(0));
292
+ const ins = [...net.values()].filter((e) => e.amount.lt(0));
293
+ const instrument = (id) => ({
294
+ admin: change.admin,
295
+ id
296
+ });
297
+ if (outs.length === 0 && ins.length === 0) return {
298
+ ...common,
299
+ type: noTransferType()
300
+ };
301
+ if (outs.length > 0 && ins.length > 0) return {
302
+ ...common,
303
+ type: "Settlement",
304
+ netTransfers: [...outs, ...ins].map((e) => ({
305
+ counterparty: e.counterparty,
306
+ amount: e.amount.toString(),
307
+ instrumentId: instrument(e.instrumentId)
308
+ }))
309
+ };
310
+ if (outs.length > 0) return {
311
+ ...common,
312
+ type: "TransferOut",
313
+ receiverAmounts: outs.map((e) => ({
314
+ receiver: e.counterparty,
315
+ amount: e.amount.toString(),
316
+ instrumentId: instrument(e.instrumentId)
317
+ }))
318
+ };
319
+ const senders = [...new Set(ins.map((l) => l.counterparty))];
320
+ return {
321
+ ...common,
322
+ type: "TransferIn",
323
+ burnAmount: "0",
324
+ mintAmount: "0",
325
+ sender: senders.length === 1 ? senders[0] : senders.join(","),
326
+ senderAmounts: ins.map((l) => ({
327
+ sender: l.counterparty,
328
+ amount: l.amount.negated().toString(),
329
+ instrumentId: instrument(l.instrumentId)
330
+ }))
331
+ };
332
+ }
333
+ // src/parser.ts
217
334
  function currentStatusFromChoiceOrResult(choice, resultTag) {
218
335
  if (resultTag === "TransferInstructionResult_Failed") return "Failed";
219
336
  if (resultTag === "TransferInstructionResult_Completed") return "Completed";
@@ -246,6 +363,7 @@ var TransactionParser = class {
246
363
  _defineProperty(this, "partyId", void 0);
247
364
  _defineProperty(this, "transaction", void 0);
248
365
  _defineProperty(this, "isMasterUser", void 0);
366
+ _defineProperty(this, "explainedCids", /* @__PURE__ */ new Set());
249
367
  this.ledgerProvider = ledgerProvider;
250
368
  this.partyId = partyId;
251
369
  this.transaction = transaction;
@@ -280,14 +398,44 @@ var TransactionParser = class {
280
398
  }
281
399
  return result;
282
400
  }
401
+ async fetchContractEvents(contractId, interfaceIds) {
402
+ const body = {
403
+ contractId,
404
+ eventFormat: EventFilterBySetup({
405
+ interfaceIds,
406
+ isMasterUser: this.isMasterUser,
407
+ partyId: this.partyId,
408
+ verbose: true
409
+ })
410
+ };
411
+ const events = await this.ledgerProvider.request({
412
+ method: "ledgerApi",
413
+ params: {
414
+ resource: "/v2/events/events-by-contract-id",
415
+ requestMethod: "post",
416
+ body
417
+ }
418
+ }).catch((err) => {
419
+ if (isContractEventsNotFoundError(err)) return null;
420
+ throw err;
421
+ });
422
+ if (!events) return null;
423
+ return {
424
+ created: events.created,
425
+ archived: events.archived
426
+ };
427
+ }
283
428
  async parseEvents(eventsStack) {
429
+ const v2 = await this.collectV2Events();
430
+ this.explainedCids = v2.explained;
431
+ const v1Events = [];
432
+ const contextOnly = [];
284
433
  let callStack = [];
285
434
  let continueAfterNodeId = -1;
286
- const result = [];
287
435
  while (eventsStack.length > 0) {
288
436
  const currentEvent = eventsStack.pop();
289
437
  const { nodeId, createdEvent, archivedEvent, exercisedEvent } = getNodeIdAndEvent(currentEvent);
290
- callStack = callStack.filter((s) => s.untilNodeId <= nodeId);
438
+ callStack = callStack.filter((s) => s.untilNodeId >= nodeId);
291
439
  const parentChoice = callStack[callStack.length - 1] && callStack[callStack.length - 1].parentChoiceName || "none (root node)";
292
440
  let parsed;
293
441
  if (nodeId <= continueAfterNodeId) parsed = null;
@@ -296,22 +444,56 @@ var TransactionParser = class {
296
444
  else if (exercisedEvent) parsed = await this.parseExercise(exercisedEvent);
297
445
  else throw new Error(`Impossible event: ${JSON.stringify(currentEvent)}`);
298
446
  if (parsed && isLeafEventNode(parsed)) {
299
- if (holdingChangesNonEmpty(parsed.event) || parsed.event.transferInstruction?.transfer != null) result.push({
300
- ...parsed.event,
301
- label: {
302
- ...parsed.event.label,
303
- meta: removeParsedMetaKeys(parsed.event.label.meta)
447
+ const emittedV1 = {
448
+ nodeId,
449
+ lastNodeId: parsed.continueAfterNodeId,
450
+ event: {
451
+ ...parsed.event,
452
+ label: {
453
+ ...parsed.event.label,
454
+ meta: removeParsedMetaKeys(parsed.event.label.meta)
455
+ }
304
456
  }
305
- });
457
+ };
458
+ if (holdingChangesNonEmpty(parsed.event) || parsed.event.transferInstruction?.transfer != null) v1Events.push(emittedV1);
459
+ else if (choiceOf(emittedV1)) contextOnly.push(emittedV1);
306
460
  continueAfterNodeId = parsed.continueAfterNodeId;
307
461
  } else if (parsed) callStack.push({
308
462
  parentChoiceName: parsed.parentChoiceName,
309
463
  untilNodeId: parsed.lastDescendantNodeId
310
464
  });
311
465
  }
312
- return result;
466
+ for (const v1 of [...v1Events, ...contextOnly]) {
467
+ const choice = choiceOf(v1);
468
+ if (!choice) continue;
469
+ for (const e of v2.events) if (e.nodeId >= v1.nodeId && e.nodeId <= v1.lastNodeId) e.event.label.tokenStandardChoice = choice;
470
+ }
471
+ const kept = [];
472
+ for (const v1 of v1Events) {
473
+ const ti = v1.event.transferInstruction;
474
+ if (holdingChangesNonEmpty(v1.event) || ti?.transfer == null) {
475
+ kept.push(v1);
476
+ continue;
477
+ }
478
+ const inRange = v2.events.filter((e) => e.nodeId >= v1.nodeId && e.nodeId <= v1.lastNodeId && e.event.transferInstruction == null);
479
+ const target = inRange.find(hasExternalLegs) ?? inRange[0];
480
+ if (target) target.event.transferInstruction = ti;
481
+ else kept.push(v1);
482
+ }
483
+ const cleanupV2 = v2.events.map((e) => ({
484
+ ...e,
485
+ event: {
486
+ ...e.event,
487
+ label: {
488
+ ...e.event.label,
489
+ meta: removeParsedMetaKeys(e.event.label.meta)
490
+ }
491
+ }
492
+ }));
493
+ return [...kept, ...cleanupV2].sort((a, b) => a.nodeId - b.nodeId).map((e) => e.event);
313
494
  }
314
495
  parseRawCreate(create, parentChoice) {
496
+ if (this.explainedCids.has(create.contractId)) return null;
315
497
  return this.buildRawEvent(create, create.nodeId, (result) => {
316
498
  return {
317
499
  type: Number(result.lockedHoldingsChangeSummaries[0]?.amountChange) > 0 ? "Lock" : "Create",
@@ -326,6 +508,7 @@ var TransactionParser = class {
326
508
  });
327
509
  }
328
510
  async parseRawArchive(archive, parentChoice) {
511
+ if (this.explainedCids.has(archive.contractId)) return null;
329
512
  const events = await this.getEventsForArchive(archive);
330
513
  if (!events) return null;
331
514
  return this.buildRawEvent(events.created.createdEvent, archive.nodeId, (result) => {
@@ -512,7 +695,7 @@ var TransactionParser = class {
512
695
  const reason = getMetaKeyValue(ReasonMetaKey, meta);
513
696
  const rawTransferArg = exercisedEvent.choiceArgument.transfer;
514
697
  const choiceArgumentTransfer = rawTransferArg?.receiver != null && rawTransferArg?.amount != null ? rawTransferArg : void 0;
515
- const sender = transferInstructions?.transfer?.sender || getMetaKeyValue(SenderMetaKey, meta) || rawTransferArg?.sender;
698
+ const sender = transferInstructions?.transfer?.sender || getMetaKeyValue("splice.lfdecentralizedtrust.org/sender", meta) || rawTransferArg?.sender;
516
699
  if (!sender) {
517
700
  console.error(`Malformed transfer didn't contain sender. Will instead attempt to parse the children.
518
701
  Transfer: ${JSON.stringify(exercisedEvent)}`);
@@ -689,33 +872,15 @@ var TransactionParser = class {
689
872
  mutatingResult.archives.push(toHoldingWithContractId(holdingView, archivedEvent?.contractId || exercisedEvent.contractId));
690
873
  }
691
874
  }
875
+ const unxplained = (h) => !this.explainedCids.has(h.contractId);
692
876
  return {
693
- creates: mutatingResult.creates.filter((create) => !mutatingResult.archives.some((archive) => create.contractId === archive.contractId)),
694
- archives: mutatingResult.archives.filter((archive) => !mutatingResult.creates.some((create) => create.contractId === archive.contractId))
877
+ creates: mutatingResult.creates.filter((create) => !mutatingResult.archives.some((archive) => create.contractId === archive.contractId)).filter(unxplained),
878
+ archives: mutatingResult.archives.filter((archive) => !mutatingResult.creates.some((create) => create.contractId === archive.contractId)).filter(unxplained)
695
879
  };
696
880
  }
697
881
  async getEventsForArchive(archivedEvent) {
698
882
  if (!(archivedEvent.witnessParties || []).includes(this.partyId)) return null;
699
- const basePayload = {
700
- contractId: archivedEvent.contractId,
701
- eventFormat: EventFilterBySetup({
702
- interfaceIds: [HOLDING_INTERFACE_ID, TRANSFER_INSTRUCTION_INTERFACE_ID],
703
- isMasterUser: this.isMasterUser,
704
- partyId: this.partyId,
705
- verbose: true
706
- })
707
- };
708
- const events = await this.ledgerProvider.request({
709
- method: "ledgerApi",
710
- params: {
711
- resource: "/v2/events/events-by-contract-id",
712
- requestMethod: "post",
713
- body: basePayload
714
- }
715
- }).catch((err) => {
716
- if (isContractEventsNotFoundError(err)) return null;
717
- else throw err;
718
- });
883
+ const events = await this.fetchContractEvents(archivedEvent.contractId, [HOLDING_INTERFACE_ID, TRANSFER_INSTRUCTION_INTERFACE_ID]);
719
884
  if (!events) return null;
720
885
  const created = events.created;
721
886
  const archived = events.archived;
@@ -725,6 +890,84 @@ var TransactionParser = class {
725
890
  archived
726
891
  };
727
892
  }
893
+ async collectV2Events() {
894
+ const views = /* @__PURE__ */ new Map();
895
+ const emitted = [];
896
+ const explained = /* @__PURE__ */ new Set();
897
+ let stack = [];
898
+ for (const raw of this.transaction.events ?? []) {
899
+ const { nodeId, createdEvent, exercisedEvent } = getNodeIdAndEvent(raw);
900
+ stack = stack.filter((s) => s.until >= nodeId);
901
+ const parentChoice = stack.at(-1)?.choice ?? "none (root node)";
902
+ if (createdEvent) {
903
+ const view = getHoldingViewV2(createdEvent);
904
+ if (view) views.set(createdEvent.contractId, view);
905
+ }
906
+ if (!exercisedEvent) continue;
907
+ stack.push({
908
+ choice: exercisedEvent.choice,
909
+ until: exercisedEvent.lastDescendantNodeId
910
+ });
911
+ const change = extractHoldingsChange(exercisedEvent);
912
+ if (!change || change.account.owner !== this.partyId) continue;
913
+ const { inputs, outputs } = netChangeCids(change);
914
+ const resolve = (cid) => this.resolveV2Holding(cid, views);
915
+ const ins = (await Promise.all(inputs.map(resolve))).filter((h) => h !== null);
916
+ const outs = (await Promise.all(outputs.map(resolve))).filter((h) => h !== null);
917
+ if ([...ins, ...outs].some((h) => h.instrumentId.admin !== change.admin || !sameAccount(h.account, change.account))) {
918
+ console.warn(`Ignoring EventLog_holdingsChange at node ${nodeId}: holdings do not match admin/account`);
919
+ continue;
920
+ }
921
+ const lockedHoldingsChange = {
922
+ creates: outs.filter((h) => !!h.lock),
923
+ archives: ins.filter((h) => !!h.lock)
924
+ };
925
+ const unlockedHoldingsChange = {
926
+ creates: outs.filter((h) => !h.lock),
927
+ archives: ins.filter((h) => !h.lock)
928
+ };
929
+ const lockedHoldingsChangeSummaries = computeSummaries(lockedHoldingsChange, this.partyId);
930
+ const unlockedHoldingsChangeSummaries = computeSummaries(unlockedHoldingsChange, this.partyId);
931
+ const event = {
932
+ label: deriveV2Label({
933
+ change,
934
+ parentChoice,
935
+ tokenStandardChoice: {
936
+ name: exercisedEvent.choice,
937
+ choiceArgument: exercisedEvent.choiceArgument,
938
+ exerciseResult: exercisedEvent.exerciseResult
939
+ },
940
+ onlyUnlocks: lockedHoldingsChange.creates.length === 0 && lockedHoldingsChange.archives.length > 0
941
+ }),
942
+ lockedHoldingsChange,
943
+ lockedHoldingsChangeSummaries,
944
+ lockedHoldingsChangeSummary: lockedHoldingsChangeSummaries[0] ?? emptyHoldingsChangeSummary,
945
+ unlockedHoldingsChange,
946
+ unlockedHoldingsChangeSummaries,
947
+ unlockedHoldingsChangeSummary: unlockedHoldingsChangeSummaries[0] ?? emptyHoldingsChangeSummary,
948
+ transferInstruction: null
949
+ };
950
+ holdingCidsOf(change).forEach((cid) => explained.add(cid));
951
+ if (holdingChangesNonEmpty(event) || change.transferLegSides.length > 0) emitted.push({
952
+ nodeId,
953
+ lastNodeId: nodeId,
954
+ event
955
+ });
956
+ }
957
+ return {
958
+ events: emitted,
959
+ explained
960
+ };
961
+ }
962
+ async resolveV2Holding(cid, views) {
963
+ const cached = views.get(cid);
964
+ if (cached) return toHolding(cid, cached);
965
+ const events = await this.fetchContractEvents(cid, [HOLDING_INTERFACE_ID_V2]);
966
+ const view = events?.created?.createdEvent && getHoldingViewV2(events.created.createdEvent);
967
+ if (!view) return null;
968
+ views.set(cid, view);
969
+ return toHolding(cid, view);
970
+ }
728
971
  };
729
972
  function isLeafEventNode(result) {
730
973
  return !!result.event;
@@ -747,7 +990,7 @@ function getNodeIdAndEvent(event) {
747
990
  nodeId: event.ArchivedEvent.nodeId,
748
991
  archivedEvent: event.ArchivedEvent
749
992
  };
750
- else throw new Error(`Impossible event type: ${event}`);
993
+ else throw new Error(`Impossible event type: ${String(event)}`);
751
994
  }
752
995
  /** sumHoldingsChange sums all the changes over a number of holdings.
753
996
  * Note that this function currently assumes all holdings use the same
@@ -769,7 +1012,7 @@ function toHoldingWithContractId(holding, contractId) {
769
1012
  };
770
1013
  }
771
1014
  function computeAmountChanges(children, meta, partyId) {
772
- const burnAmount = BigNumber(getMetaKeyValue(BurnedMetaKey, meta) || "0");
1015
+ const burnAmount = BigNumber(getMetaKeyValue("splice.lfdecentralizedtrust.org/burned", meta) || "0");
773
1016
  const partyHoldingAmountChange = sumHoldingsChange(children, (owner) => owner === partyId);
774
1017
  const otherPartiesHoldingAmountChange = sumHoldingsChange(children, (owner) => owner !== partyId);
775
1018
  const mintAmount = partyHoldingAmountChange.plus(burnAmount).plus(otherPartiesHoldingAmountChange);
@@ -836,7 +1079,13 @@ const emptyHoldingsChangeSummary = {
836
1079
  outputAmount: "0",
837
1080
  amountChange: "0"
838
1081
  };
839
- //#endregion
1082
+ function hasExternalLegs(e) {
1083
+ const v2Label = e.event.label.v2;
1084
+ return !!v2Label?.transferLegSides.some((l) => !sameAccount(l.otherside, v2Label.account));
1085
+ }
1086
+ function choiceOf(e) {
1087
+ return e.event.label.tokenStandardChoice ?? null;
1088
+ }
840
1089
  export { AllKnownMetaKeys, BurnedMetaKey, ReasonMetaKey, SenderMetaKey, TokenStandardTransactionInterfaces, TransactionParser, TxKindMetaKey, ensureInterfaceViewIsPresent, getInterfaceView, getKnownInterfaceView, getMetaKeyValue, hasInterface, isContractEventsNotFoundError, matchInterfaceIds, mergeMetas, removeParsedMetaKeys, renderTransaction, splitInterfaceId };
841
1090
 
842
1091
  //# sourceMappingURL=index.js.map