@canton-network/core-token-standard-service 1.14.0 → 2.1.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
@@ -3,6 +3,7 @@ import { EventFilterBySetup } from "@canton-network/core-ledger-client-types";
3
3
  import { TokenStandardTransactionInterfaces, TransactionParser, ensureInterfaceViewIsPresent, renderTransaction } from "@canton-network/core-tx-parser";
4
4
  import Decimal$1, { Decimal } from "decimal.js";
5
5
  import { ALLOCATION_FACTORY_INTERFACE_ID_V2, ALLOCATION_INSTRUCTION_INTERFACE_ID_V2, ALLOCATION_INTERFACE_ID_V2, ALLOCATION_REQUEST_INTERFACE_ID_V2, TRANSFER_FACTORY_INTERFACE_ID_V2, TRANSFER_INSTRUCTION_INTERFACE_ID_V2, TokenStandardClient as TokenStandardClient$1, TransferInstruction as TransferInstruction$1 } from "@canton-network/core-token-standard-v2";
6
+ import { getLogger } from "@logtape/logtape";
6
7
  import { ACSReader } from "@canton-network/core-acs-reader";
7
8
  //#region src/types.ts
8
9
  const REQUESTED_AT_SKEW_MS = 6e4;
@@ -16,11 +17,53 @@ const KEY_MAPPING = {
16
17
  "allocation-request": "allocationRequest"
17
18
  };
18
19
  //#endregion
20
+ //#region \0@oxc-project+runtime@0.154.0/helpers/esm/typeof.js
21
+ function _typeof(o) {
22
+ "@babel/helpers - typeof";
23
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
24
+ return typeof o;
25
+ } : function(o) {
26
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
27
+ }, _typeof(o);
28
+ }
29
+ //#endregion
30
+ //#region \0@oxc-project+runtime@0.154.0/helpers/esm/toPrimitive.js
31
+ function toPrimitive(t, r) {
32
+ if ("object" != _typeof(t) || !t) return t;
33
+ var e = t[Symbol.toPrimitive];
34
+ if (void 0 !== e) {
35
+ var i = e.call(t, r || "default");
36
+ if ("object" != _typeof(i)) return i;
37
+ throw new TypeError("@@toPrimitive must return a primitive value.");
38
+ }
39
+ return ("string" === r ? String : Number)(t);
40
+ }
41
+ //#endregion
42
+ //#region \0@oxc-project+runtime@0.154.0/helpers/esm/toPropertyKey.js
43
+ function toPropertyKey(t) {
44
+ var i = toPrimitive(t, "string");
45
+ return "symbol" == _typeof(i) ? i : i + "";
46
+ }
47
+ //#endregion
48
+ //#region \0@oxc-project+runtime@0.154.0/helpers/esm/defineProperty.js
49
+ function _defineProperty(e, r, t) {
50
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
51
+ value: t,
52
+ enumerable: !0,
53
+ configurable: !0,
54
+ writable: !0
55
+ }) : e[r] = t, e;
56
+ }
57
+ //#endregion
19
58
  //#region src/v2/transfer-service.ts
20
59
  var TransferServiceV2 = class {
21
- constructor(core, logger) {
60
+ constructor(core) {
22
61
  this.core = core;
23
- this.logger = logger;
62
+ _defineProperty(this, "logger", getLogger([
63
+ "core",
64
+ "token-standard-service",
65
+ "TransferServiceV2"
66
+ ]));
24
67
  }
25
68
  async buildTransferChoiceArgs(opts) {
26
69
  const inputHoldingCids = await this.core.getInputHoldingCidsForAccount({
@@ -125,9 +168,13 @@ var TransferServiceV2 = class {
125
168
  //#endregion
126
169
  //#region src/v1/transfer-service.ts
127
170
  var TransferService = class {
128
- constructor(core, logger) {
171
+ constructor(core) {
129
172
  this.core = core;
130
- this.logger = logger;
173
+ _defineProperty(this, "logger", getLogger([
174
+ "core",
175
+ "token-standard-service",
176
+ "TransferService"
177
+ ]));
131
178
  }
132
179
  async buildTransferChoiceArgs(sender, receiver, amount, instrumentAdmin, instrumentId, inputUtxos, memo, expiryDate, meta, continueUntilCompletion) {
133
180
  const inputHoldingCids = await this.core.getInputHoldingsCids({
@@ -188,7 +235,7 @@ var TransferService = class {
188
235
  const { factoryId, choiceContext } = await this.fetchTransferFactoryChoiceContext(registryUrl, choiceArgs);
189
236
  return this.createTransferFromContext(factoryId, choiceArgs, choiceContext);
190
237
  } catch (e) {
191
- this.logger.error("Failed to execute transfer:", e);
238
+ this.logger.warn("Failed to execute transfer:", { error: e });
192
239
  throw e;
193
240
  }
194
241
  }
@@ -211,7 +258,7 @@ var TransferService = class {
211
258
  } }
212
259
  }, choiceContext.disclosedContracts];
213
260
  } catch (e) {
214
- this.logger.error("Failed to create accept transfer instruction:", e);
261
+ this.logger.warn("Failed to create accept transfer instruction:", { error: e });
215
262
  throw e;
216
263
  }
217
264
  }
@@ -294,7 +341,7 @@ var TransferService = class {
294
341
  } }
295
342
  }, choiceContext.disclosedContracts];
296
343
  } catch (e) {
297
- this.logger.error("Failed to create reject transfer instruction:", e);
344
+ this.logger.warn("Failed to create reject transfer instruction:", { error: e });
298
345
  throw e;
299
346
  }
300
347
  }
@@ -325,7 +372,7 @@ var TransferService = class {
325
372
  } }
326
373
  }, choiceContext.disclosedContracts];
327
374
  } catch (e) {
328
- this.logger.error("Failed to create withdraw transfer instruction:", e);
375
+ this.logger.warn("Failed to create withdraw transfer instruction:", { error: e });
329
376
  throw e;
330
377
  }
331
378
  }
@@ -348,9 +395,8 @@ var TransferService = class {
348
395
  //#endregion
349
396
  //#region src/v1/allocation-service.ts
350
397
  var AllocationService$1 = class {
351
- constructor(core, logger) {
398
+ constructor(core) {
352
399
  this.core = core;
353
- this.logger = logger;
354
400
  }
355
401
  async buildAllocationFactoryChoiceArgs(allocationSpecification, expectedAdmin, inputUtxos, requestedAt) {
356
402
  const allocationSpecificationNormalized = {
@@ -503,11 +549,15 @@ var AllocationService$1 = class {
503
549
  //#endregion
504
550
  //#region src/core-service.ts
505
551
  var CoreService = class CoreService {
506
- constructor(ledgerProvider, logger, accessTokenProvider, isMasterUser) {
552
+ constructor(ledgerProvider, accessTokenProvider, isMasterUser) {
507
553
  this.ledgerProvider = ledgerProvider;
508
- this.logger = logger;
509
554
  this.accessTokenProvider = accessTokenProvider;
510
555
  this.isMasterUser = isMasterUser;
556
+ _defineProperty(this, "logger", getLogger([
557
+ "core",
558
+ "token-standard-service",
559
+ "CoreService"
560
+ ]));
511
561
  }
512
562
  getTokenStandardClientWithVersion(registryUrl, version) {
513
563
  if (!isApiVersion(version)) throw new Error(`Unsupported token standard api version.`);
@@ -573,7 +623,7 @@ var CoreService = class CoreService {
573
623
  currentSum = currentSum.plus(currentHoldingAmount);
574
624
  cIds.push(h.contractId);
575
625
  }
576
- if (currentSum.lessThan(amount)) throw new Error(`Sender doesn't have sufficient funds for this transfer. Missing amount: ${amount.minus(currentSum)}`);
626
+ if (currentSum.lessThan(amount)) throw new Error(`Sender doesn't have sufficient funds for this transfer. Missing amount: ${amount.minus(currentSum).toString()}`);
577
627
  if (cIds.length > 100) throw new Error(`Exceeded the maximum of 100 utxos in 1 transaction`);
578
628
  return cIds;
579
629
  }
@@ -595,12 +645,15 @@ var CoreService = class CoreService {
595
645
  continueUntilCompletion: Boolean(continueUntilCompletion)
596
646
  };
597
647
  if (limit !== void 0) options.limit = limit;
598
- this.logger.info(`continue to completion: ${Boolean(continueUntilCompletion)}`);
648
+ this.logger.debug("Continue to completion: {continueUntilCompletion}", { continueUntilCompletion: Boolean(continueUntilCompletion) });
599
649
  const acsResponses = await new ACSReader(this.ledgerProvider).raw.read(options);
600
650
  const isActiveContractEntry = (acsResponse) => acsResponse.contractEntry != null && "JsActiveContract" in acsResponse.contractEntry && acsResponse.contractEntry.JsActiveContract != null && acsResponse.contractEntry.JsActiveContract.createdEvent != null;
601
651
  return acsResponses.filter(isActiveContractEntry).map((response) => this.toPrettyContract(interfaceId, response, ledgerEnd));
602
652
  } catch (err) {
603
- this.logger.error(`Failed to list contracts of interface ${interfaceId}`, err);
653
+ this.logger.error(`Failed to list contracts of interface {interfaceId}`, {
654
+ interfaceId,
655
+ err
656
+ });
604
657
  throw err;
605
658
  }
606
659
  }
@@ -659,9 +712,14 @@ const EMPTY_EXTRA_ARGS = () => ({
659
712
  meta: { values: {} }
660
713
  });
661
714
  var AllocationService = class AllocationService {
662
- constructor(core, logger) {
715
+ constructor(core) {
663
716
  this.core = core;
664
- this.logger = logger;
717
+ _defineProperty(this, "logger", getLogger([
718
+ "core",
719
+ "token-standard-service",
720
+ "v2",
721
+ "allocation-service"
722
+ ]));
665
723
  }
666
724
  static fundingNeeds(spec) {
667
725
  const needs = /* @__PURE__ */ new Map();
@@ -752,6 +810,17 @@ var AllocationService = class AllocationService {
752
810
  }
753
811
  }, []];
754
812
  }
813
+ createAcceptAllocationInstruction(acceptCid, actors) {
814
+ return [{
815
+ templateId: ALLOCATION_INSTRUCTION_INTERFACE_ID_V2,
816
+ contractId: acceptCid,
817
+ choice: "AllocationInstruction_Accept",
818
+ choiceArgument: {
819
+ actors,
820
+ extraArgs: EMPTY_EXTRA_ARGS()
821
+ }
822
+ }, []];
823
+ }
755
824
  async createAllocationFromContext(factoryId, choiceArgs, choiceContext) {
756
825
  this.logger.debug("Creating transfer from pre-fetched context...");
757
826
  choiceArgs.extraArgs.context = {
@@ -801,44 +870,6 @@ var AllocationService = class AllocationService {
801
870
  }
802
871
  };
803
872
  //#endregion
804
- //#region \0@oxc-project+runtime@0.153.0/helpers/esm/typeof.js
805
- function _typeof(o) {
806
- "@babel/helpers - typeof";
807
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
808
- return typeof o;
809
- } : function(o) {
810
- return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
811
- }, _typeof(o);
812
- }
813
- //#endregion
814
- //#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPrimitive.js
815
- function toPrimitive(t, r) {
816
- if ("object" != _typeof(t) || !t) return t;
817
- var e = t[Symbol.toPrimitive];
818
- if (void 0 !== e) {
819
- var i = e.call(t, r || "default");
820
- if ("object" != _typeof(i)) return i;
821
- throw new TypeError("@@toPrimitive must return a primitive value.");
822
- }
823
- return ("string" === r ? String : Number)(t);
824
- }
825
- //#endregion
826
- //#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPropertyKey.js
827
- function toPropertyKey(t) {
828
- var i = toPrimitive(t, "string");
829
- return "symbol" == _typeof(i) ? i : i + "";
830
- }
831
- //#endregion
832
- //#region \0@oxc-project+runtime@0.153.0/helpers/esm/defineProperty.js
833
- function _defineProperty(e, r, t) {
834
- return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
835
- value: t,
836
- enumerable: !0,
837
- configurable: !0,
838
- writable: !0
839
- }) : e[r] = t, e;
840
- }
841
- //#endregion
842
873
  //#region src/token-standard-service.ts
843
874
  function isApiVersion(v) {
844
875
  return SUPPORTED_VERSIONS.includes(v);
@@ -864,21 +895,25 @@ function resolveCapabilities(opts) {
864
895
  return resolvedCapabilities;
865
896
  }
866
897
  var TokenStandardService = class {
867
- constructor(ledgerProvider, logger, accessTokenProvider, isMasterUser) {
898
+ constructor(ledgerProvider, accessTokenProvider, isMasterUser) {
868
899
  this.ledgerProvider = ledgerProvider;
869
- this.logger = logger;
870
900
  this.accessTokenProvider = accessTokenProvider;
871
901
  this.isMasterUser = isMasterUser;
902
+ _defineProperty(this, "logger", getLogger([
903
+ "core",
904
+ "token-standard-service",
905
+ "TokenStandardService"
906
+ ]));
872
907
  _defineProperty(this, "core", void 0);
873
908
  _defineProperty(this, "allocation", void 0);
874
909
  _defineProperty(this, "transfer", void 0);
875
910
  _defineProperty(this, "v2", void 0);
876
- this.core = new CoreService(ledgerProvider, logger, accessTokenProvider, isMasterUser);
877
- this.allocation = new AllocationService$1(this.core, this.logger);
878
- this.transfer = new TransferService(this.core, this.logger);
911
+ this.core = new CoreService(ledgerProvider, accessTokenProvider, isMasterUser);
912
+ this.allocation = new AllocationService$1(this.core);
913
+ this.transfer = new TransferService(this.core);
879
914
  this.v2 = {
880
- transfer: new TransferServiceV2(this.core, this.logger),
881
- allocation: new AllocationService(this.core, this.logger)
915
+ transfer: new TransferServiceV2(this.core),
916
+ allocation: new AllocationService(this.core)
882
917
  };
883
918
  }
884
919
  async resolveCapabilitiesFromRegistryByInstrumentId(registryUrl, instrumentId) {
@@ -889,7 +924,7 @@ var TokenStandardService = class {
889
924
  const params = { path: { instrumentId } };
890
925
  return await this.core.getTokenStandardClient(registryUrl).get("/registry/metadata/v1/instruments/{instrumentId}", params);
891
926
  } catch (e) {
892
- this.logger.error(e);
927
+ this.logger.warn("An error occurred while fetching the instrument by ID.", { error: e });
893
928
  throw new Error(`Instrument id ${instrumentId} does not exist for this instrument admin.`, { cause: e });
894
929
  }
895
930
  }
@@ -948,7 +983,7 @@ var TokenStandardService = class {
948
983
  query: {}
949
984
  }
950
985
  })).offset;
951
- this.logger.debug(afterOffsetOrLatest, "Using offset");
986
+ this.logger.debug("Using offset", { afterOffsetOrLatest });
952
987
  const updatesResponse = await this.ledgerProvider.request({
953
988
  method: "ledgerApi",
954
989
  params: {
@@ -972,7 +1007,7 @@ var TokenStandardService = class {
972
1007
  });
973
1008
  return this.core.toPrettyTransactions(updatesResponse, partyId);
974
1009
  } catch (err) {
975
- this.logger.error("Failed to list holding transactions.", err);
1010
+ this.logger.warn("Failed to list holding transactions.", { error: err });
976
1011
  throw err;
977
1012
  }
978
1013
  }