@canton-network/core-token-standard-service 2.2.0 → 2.3.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/core-service.d.ts +1 -0
- package/dist/core-service.d.ts.map +1 -1
- package/dist/index.cjs +96 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +97 -12
- package/dist/index.js.map +1 -1
- package/dist/token-standard-service.d.ts +1 -0
- package/dist/token-standard-service.d.ts.map +1 -1
- package/dist/v2/allocation-service.d.ts +43 -1
- package/dist/v2/allocation-service.d.ts.map +1 -1
- package/package.json +10 -10
package/dist/core-service.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core-service.d.ts","sourceRoot":"","sources":["../src/core-service.ts"],"names":[],"mappings":"AAGA,OAAO,EACH,mBAAmB,EAEnB,KAAK,WAAW,EACnB,MAAM,qCAAqC,CAAA;AAC5C,OAAO,EACH,KAAK,OAAO,EACZ,mBAAmB,IAAI,qBAAqB,EAC5C,KAAK,WAAW,IAAI,aAAa,
|
|
1
|
+
{"version":3,"file":"core-service.d.ts","sourceRoot":"","sources":["../src/core-service.ts"],"names":[],"mappings":"AAGA,OAAO,EACH,mBAAmB,EAEnB,KAAK,WAAW,EACnB,MAAM,qCAAqC,CAAA;AAC5C,OAAO,EACH,KAAK,OAAO,EACZ,mBAAmB,IAAI,qBAAqB,EAC5C,KAAK,WAAW,IAAI,aAAa,EAEpC,MAAM,wCAAwC,CAAA;AAC/C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAEzD,OAAO,EAGH,KAAK,cAAc,EAEnB,KAAK,SAAS,EACd,KAAK,kBAAkB,EACvB,KAAK,WAAW,EAChB,KAAK,cAAc,EAEtB,MAAM,gCAAgC,CAAA;AACvC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAA;AAC3E,OAAO,KAAK,EACR,sBAAsB,EAEzB,MAAM,sC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E,MAAM,EACnB,QAAQ,EAAE,6BAA6B,EACvC,MAAM,CAAC,EAAE,MAAM,GAChB,cAAc,CAAC,CAAC,CAAC,CAanB;IAED,mBAAmB,CAAC,QAAQ,EAAE,MAAM,UAInC;CACJ"}
|
package/dist/index.cjs
CHANGED
|
@@ -39,7 +39,7 @@ const KEY_MAPPING = {
|
|
|
39
39
|
"allocation-instruction": "allocationInstruction",
|
|
40
40
|
"allocation-request": "allocationRequest"
|
|
41
41
|
};
|
|
42
|
-
// \0@oxc-project+runtime@0.
|
|
42
|
+
// \0@oxc-project+runtime@0.156.0/helpers/esm/typeof.js
|
|
43
43
|
function _typeof(o) {
|
|
44
44
|
"@babel/helpers - typeof";
|
|
45
45
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -48,7 +48,7 @@ function _typeof(o) {
|
|
|
48
48
|
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
49
49
|
}, _typeof(o);
|
|
50
50
|
}
|
|
51
|
-
// \0@oxc-project+runtime@0.
|
|
51
|
+
// \0@oxc-project+runtime@0.156.0/helpers/esm/toPrimitive.js
|
|
52
52
|
function toPrimitive(t, r) {
|
|
53
53
|
if ("object" != _typeof(t) || !t) return t;
|
|
54
54
|
var e = t[Symbol.toPrimitive];
|
|
@@ -59,12 +59,12 @@ function toPrimitive(t, r) {
|
|
|
59
59
|
}
|
|
60
60
|
return ("string" === r ? String : Number)(t);
|
|
61
61
|
}
|
|
62
|
-
// \0@oxc-project+runtime@0.
|
|
62
|
+
// \0@oxc-project+runtime@0.156.0/helpers/esm/toPropertyKey.js
|
|
63
63
|
function toPropertyKey(t) {
|
|
64
64
|
var i = toPrimitive(t, "string");
|
|
65
65
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
66
66
|
}
|
|
67
|
-
// \0@oxc-project+runtime@0.
|
|
67
|
+
// \0@oxc-project+runtime@0.156.0/helpers/esm/defineProperty.js
|
|
68
68
|
function _defineProperty(e, r, t) {
|
|
69
69
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
70
70
|
value: t,
|
|
@@ -599,7 +599,7 @@ var CoreService = class CoreService {
|
|
|
599
599
|
const party = opts.partyId ?? opts.account.owner;
|
|
600
600
|
if (!party) throw new Error("No party to query as");
|
|
601
601
|
const now = /* @__PURE__ */ new Date();
|
|
602
|
-
const holdings = (await this.listContractsByInterface(
|
|
602
|
+
const holdings = (await this.listContractsByInterface(_canton_network_core_token_standard_v2.HOLDING_INTERFACE_ID_V2, party, opts.limit, opts.offset, opts.continueUntilCompletion ?? true)).filter((h) => h.interfaceViewValue.instrumentId.admin === opts.instrumentAdmin && h.interfaceViewValue.instrumentId.id === opts.instrumentId && this.isSameAccount(opts.account, h.interfaceViewValue.account) && !TokenStandardService.isHoldingLocked(h, now) && !opts.excludeCids?.has(h.contractId));
|
|
603
603
|
return opts.amount ? CoreService.getInputHoldingsCidsForAmount(opts.amount, holdings) : holdings.map((h) => h.contractId);
|
|
604
604
|
}
|
|
605
605
|
async getInputHoldingsCids(options) {
|
|
@@ -757,7 +757,8 @@ var AllocationService = class AllocationService {
|
|
|
757
757
|
account: spec.authorizer,
|
|
758
758
|
instrumentAdmin: admin,
|
|
759
759
|
instrumentId,
|
|
760
|
-
amount
|
|
760
|
+
amount,
|
|
761
|
+
excludeCids: used
|
|
761
762
|
});
|
|
762
763
|
cids.forEach((c) => used.add(c));
|
|
763
764
|
inputHoldingCids.push(...cids);
|
|
@@ -803,10 +804,15 @@ var AllocationService = class AllocationService {
|
|
|
803
804
|
return this.createAllocationChoiceFromContext(action, allocationCid, actors, ctx);
|
|
804
805
|
}
|
|
805
806
|
createAllocationRequestChoice(action, allocationRequestCid, actors) {
|
|
807
|
+
const choice = {
|
|
808
|
+
accept: "AllocationRequest_Accept",
|
|
809
|
+
reject: "AllocationRequest_Reject",
|
|
810
|
+
withdraw: "AllocationRequest_Withdraw"
|
|
811
|
+
}[action];
|
|
806
812
|
return [{
|
|
807
813
|
templateId: _canton_network_core_token_standard_v2.ALLOCATION_REQUEST_INTERFACE_ID_V2,
|
|
808
814
|
contractId: allocationRequestCid,
|
|
809
|
-
choice
|
|
815
|
+
choice,
|
|
810
816
|
choiceArgument: {
|
|
811
817
|
actors,
|
|
812
818
|
extraArgs: EMPTY_EXTRA_ARGS()
|
|
@@ -848,12 +854,36 @@ var AllocationService = class AllocationService {
|
|
|
848
854
|
choiceArgument: choiceArgs
|
|
849
855
|
}, choiceContext.disclosedContracts];
|
|
850
856
|
}
|
|
857
|
+
async fetchAllocationInstructionChoiceContext(action, allocationInstructionCid, registryUrl, excludeDebugFields = true) {
|
|
858
|
+
return this.core.getTokenStandardClientV2(registryUrl).post(`/registry/allocation-instruction/v2/{allocationInstructionId}/choice-contexts/${action}`, { excludeDebugFields }, { path: { allocationInstructionId: allocationInstructionCid } });
|
|
859
|
+
}
|
|
860
|
+
async createAllocationInstructionChoice(action, allocationInstructionCid, actors, registryUrl, excludeDebugFields = true, prefetched) {
|
|
861
|
+
const ctx = prefetched ?? await this.fetchAllocationInstructionChoiceContext(action, allocationInstructionCid, registryUrl, excludeDebugFields);
|
|
862
|
+
return [{
|
|
863
|
+
templateId: _canton_network_core_token_standard_v2.ALLOCATION_INSTRUCTION_INTERFACE_ID_V2,
|
|
864
|
+
contractId: allocationInstructionCid,
|
|
865
|
+
choice: action === "accept" ? _canton_network_core_token_standard_v2.AllocationInstruction.AllocationInstruction_Accept.choiceName : _canton_network_core_token_standard_v2.AllocationInstruction.AllocationInstruction_Withdraw.choiceName,
|
|
866
|
+
choiceArgument: {
|
|
867
|
+
actors,
|
|
868
|
+
extraArgs: {
|
|
869
|
+
context: ctx.choiceContextData,
|
|
870
|
+
meta: { values: {} }
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
}, ctx.disclosedContracts ?? []];
|
|
874
|
+
}
|
|
851
875
|
async fetchSettlementFactory(args, registryUrl) {
|
|
852
876
|
return this.core.getTokenStandardClientV2(registryUrl).post("/registry/allocation/v2/settlement-factory", {
|
|
853
877
|
choiceArguments: args,
|
|
854
878
|
excludeDebugFields: true
|
|
855
879
|
});
|
|
856
880
|
}
|
|
881
|
+
/**
|
|
882
|
+
*
|
|
883
|
+
* @deprecated Use {@link createAllocationsForRequestForLoggedInParty}
|
|
884
|
+
* instead, which creates only the allocations owned by a given party and
|
|
885
|
+
* reports allocations whose registry could not be resolved
|
|
886
|
+
*/
|
|
857
887
|
async createAllocationsForRequest(opts) {
|
|
858
888
|
const used = /* @__PURE__ */ new Set();
|
|
859
889
|
const results = [];
|
|
@@ -882,6 +912,58 @@ var AllocationService = class AllocationService {
|
|
|
882
912
|
const dcs = new Map(results.flatMap(([, d]) => d).filter((d) => d.contractId !== void 0).map((d) => [d.contractId, d]));
|
|
883
913
|
return [results.map(([c]) => c), [...dcs.values()]];
|
|
884
914
|
}
|
|
915
|
+
/**
|
|
916
|
+
* Prepares the commands for a party to accept an allocation request.
|
|
917
|
+
*
|
|
918
|
+
* Creates one `AllocationFactory_Allocate` command for each allocation in the
|
|
919
|
+
* request that the party owns, followed by an `AllocationRequest_Accept`
|
|
920
|
+
* command. Holdings used as inputs by one allocation are excluded from later
|
|
921
|
+
* allocations, so no holding is spent twice within the same request.
|
|
922
|
+
*
|
|
923
|
+
* If no registry serves an allocation's instrument admin, that allocation is
|
|
924
|
+
* skipped and its admin is added to `skipped`. In that case `accept` is
|
|
925
|
+
* `null`, because the request cannot be accepted until every allocation
|
|
926
|
+
* exists.
|
|
927
|
+
*
|
|
928
|
+
* @param opts.requestCid - Contract ID of the allocation request.
|
|
929
|
+
* @param opts.request - The allocation request's interface view.
|
|
930
|
+
* @param opts.registry - Resolves an instrument admin to its registry URL,
|
|
931
|
+
* or `null` if no registry serves that admin.
|
|
932
|
+
* @param opts.partyId - The party accepting the request. Only allocations
|
|
933
|
+
* this party owns are created, and it acts on every command.
|
|
934
|
+
* @returns The allocate commands with their disclosed contracts, the accept
|
|
935
|
+
* command with its disclosed contracts (or `null` if any allocation was
|
|
936
|
+
* skipped), and the admins whose allocations were skipped.
|
|
937
|
+
* @throws If the request contains no allocations owned by `partyId`.
|
|
938
|
+
*/
|
|
939
|
+
async createAllocationsForRequestForLoggedInParty(opts) {
|
|
940
|
+
const specs = opts.request.allocations.filter((p) => p.authorizer.owner === opts.partyId);
|
|
941
|
+
if (specs.length === 0) throw new Error(`Request ${opts.requestCid} has no allocation for account ${opts.partyId}`);
|
|
942
|
+
const used = /* @__PURE__ */ new Set();
|
|
943
|
+
const allocate = [];
|
|
944
|
+
const skipped = [];
|
|
945
|
+
for (const spec of specs) {
|
|
946
|
+
const registryUrl = await opts.registry(spec.admin);
|
|
947
|
+
if (!registryUrl) {
|
|
948
|
+
skipped.push(spec.admin);
|
|
949
|
+
continue;
|
|
950
|
+
}
|
|
951
|
+
const [cmd, dcs] = await this.createAllocation({
|
|
952
|
+
settlement: opts.request.settlement,
|
|
953
|
+
spec,
|
|
954
|
+
admin: spec.admin,
|
|
955
|
+
actors: [opts.partyId],
|
|
956
|
+
excludeCids: used
|
|
957
|
+
}, registryUrl);
|
|
958
|
+
for (const cid of cmd.choiceArgument.inputHoldingCids) used.add(cid);
|
|
959
|
+
allocate.push([cmd, dcs]);
|
|
960
|
+
}
|
|
961
|
+
return {
|
|
962
|
+
allocate,
|
|
963
|
+
accept: skipped.length === 0 ? this.createAllocationRequestChoice("accept", opts.requestCid, [opts.partyId]) : null,
|
|
964
|
+
skipped
|
|
965
|
+
};
|
|
966
|
+
}
|
|
885
967
|
};
|
|
886
968
|
// src/token-standard-service.ts
|
|
887
969
|
function isApiVersion(v) {
|
|
@@ -907,7 +989,7 @@ function resolveCapabilities(opts) {
|
|
|
907
989
|
for (const key in resolvedCapabilities) resolvedCapabilities[key].sort();
|
|
908
990
|
return resolvedCapabilities;
|
|
909
991
|
}
|
|
910
|
-
var TokenStandardService = class {
|
|
992
|
+
var TokenStandardService = class TokenStandardService {
|
|
911
993
|
constructor(ledgerProvider, accessTokenProvider, isMasterUser) {
|
|
912
994
|
this.ledgerProvider = ledgerProvider;
|
|
913
995
|
this.accessTokenProvider = accessTokenProvider;
|
|
@@ -1118,13 +1200,12 @@ var TokenStandardService = class {
|
|
|
1118
1200
|
}
|
|
1119
1201
|
}, disclosedContracts];
|
|
1120
1202
|
}
|
|
1121
|
-
static
|
|
1122
|
-
const lock = holding.interfaceViewValue.lock;
|
|
1203
|
+
static checkLock(lock, createdAtTime, currentTime = /* @__PURE__ */ new Date()) {
|
|
1123
1204
|
if (!lock) return false;
|
|
1124
1205
|
let expiresAtAbsolute = null;
|
|
1125
1206
|
let expiresAtRelative = null;
|
|
1126
1207
|
if (lock.expiresAfter) {
|
|
1127
|
-
const createdAt = new Date(
|
|
1208
|
+
const createdAt = new Date(createdAtTime);
|
|
1128
1209
|
const msToAdd = parseInt(lock.expiresAfter.microseconds) / 1e3;
|
|
1129
1210
|
expiresAtRelative = new Date(createdAt.getTime() + msToAdd);
|
|
1130
1211
|
}
|
|
@@ -1136,6 +1217,10 @@ var TokenStandardService = class {
|
|
|
1136
1217
|
else return true;
|
|
1137
1218
|
return currentTime < expiresAt;
|
|
1138
1219
|
}
|
|
1220
|
+
static isHoldingLocked(holding, currentTime = /* @__PURE__ */ new Date()) {
|
|
1221
|
+
const lock = holding.interfaceViewValue.lock;
|
|
1222
|
+
return TokenStandardService.checkLock(lock, holding.activeContract.createdEvent.createdAt, currentTime);
|
|
1223
|
+
}
|
|
1139
1224
|
};
|
|
1140
1225
|
_defineProperty(TokenStandardService, "MEMO_KEY", "splice.lfdecentralizedtrust.org/reason");
|
|
1141
1226
|
exports.EMPTY_META = EMPTY_META;
|