@canton-network/core-ledger-client 0.20.1 → 0.20.3

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.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './token-standard-service.js';
2
+ export { AmuletService } from './amulet-service.js';
2
3
  export * from './ledger-client.js';
3
4
  export * from './generated-clients/openapi-3.3.0-SNAPSHOT.js';
4
5
  export * from './acs/acs-container.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,6BAA6B,CAAA;AAC3C,cAAc,oBAAoB,CAAA;AAClC,cAAc,+CAA+C,CAAA;AAC7D,cAAc,wBAAwB,CAAA;AACtC,cAAc,qBAAqB,CAAA;AACnC,YAAY,EACR,WAAW,EACX,kBAAkB,EAClB,OAAO,EACP,WAAW,EACX,cAAc,EACd,qBAAqB,EACrB,uBAAuB,EACvB,mBAAmB,EACnB,kBAAkB,EAClB,cAAc,EACd,SAAS,EACT,KAAK,EACL,UAAU,EACV,WAAW,EACX,UAAU,EACV,IAAI,EACJ,IAAI,EACJ,MAAM,EACN,UAAU,EACV,UAAU,EACV,SAAS,GACZ,MAAM,oBAAoB,CAAA;AAE3B,OAAO,EACH,eAAe,EACf,kBAAkB,EAClB,eAAe,EACf,eAAe,EACf,aAAa,EACb,uBAAuB,GAC1B,MAAM,uBAAuB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,6BAA6B,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACnD,cAAc,oBAAoB,CAAA;AAClC,cAAc,+CAA+C,CAAA;AAC7D,cAAc,wBAAwB,CAAA;AACtC,cAAc,qBAAqB,CAAA;AACnC,YAAY,EACR,WAAW,EACX,kBAAkB,EAClB,OAAO,EACP,WAAW,EACX,cAAc,EACd,qBAAqB,EACrB,uBAAuB,EACvB,mBAAmB,EACnB,kBAAkB,EAClB,cAAc,EACd,SAAS,EACT,KAAK,EACL,UAAU,EACV,WAAW,EACX,UAAU,EACV,IAAI,EACJ,IAAI,EACJ,MAAM,EACN,UAAU,EACV,UAAU,EACV,SAAS,GACZ,MAAM,oBAAoB,CAAA;AAE3B,OAAO,EACH,eAAe,EACf,kBAAkB,EAClB,eAAe,EACf,eAAe,EACf,aAAa,EACb,uBAAuB,GAC1B,MAAM,uBAAuB,CAAA"}
package/dist/index.js CHANGED
@@ -1098,13 +1098,11 @@ function holdingChangesNonEmpty(event) {
1098
1098
  }
1099
1099
 
1100
1100
  // src/token-standard-service.ts
1101
- var MEMO_KEY = "splice.lfdecentralizedtrust.org/reason";
1102
1101
  var REQUESTED_AT_SKEW_MS = 6e4;
1103
1102
  var EMPTY_META = { values: {} };
1104
1103
  var CoreService = class _CoreService {
1105
- constructor(ledgerClient, scanProxyClient, logger, accessTokenProvider, isMasterUser, isAdmin = false, accessToken = "") {
1104
+ constructor(ledgerClient, logger, accessTokenProvider, isMasterUser, isAdmin = false, accessToken = "") {
1106
1105
  this.ledgerClient = ledgerClient;
1107
- this.scanProxyClient = scanProxyClient;
1108
1106
  this.logger = logger;
1109
1107
  this.accessTokenProvider = accessTokenProvider;
1110
1108
  this.isMasterUser = isMasterUser;
@@ -1120,6 +1118,7 @@ var CoreService = class _CoreService {
1120
1118
  this.accessTokenProvider
1121
1119
  );
1122
1120
  }
1121
+ // TODO: probably needs a filter by instrument ID as well?
1123
1122
  async getInputHoldingsCids(sender, inputUtxos, amount) {
1124
1123
  const now = /* @__PURE__ */ new Date();
1125
1124
  if (inputUtxos && inputUtxos.length > 0) {
@@ -1559,7 +1558,12 @@ var TransferService = class {
1559
1558
  ).toISOString(),
1560
1559
  executeBefore: (expiryDate ?? new Date(Date.now() + 24 * 60 * 60 * 1e3)).toISOString(),
1561
1560
  inputHoldingCids,
1562
- meta: { values: { [MEMO_KEY]: memo || "", ...meta?.values } }
1561
+ meta: {
1562
+ values: {
1563
+ [TokenStandardService.MEMO_KEY]: memo || "",
1564
+ ...meta?.values
1565
+ }
1566
+ }
1563
1567
  },
1564
1568
  extraArgs: {
1565
1569
  context: { values: {} },
@@ -1869,19 +1873,16 @@ var TransferService = class {
1869
1873
  }
1870
1874
  };
1871
1875
  var TokenStandardService = class {
1872
- constructor(ledgerClient, scanProxyClient, logger, accessTokenProvider, isMasterUser, scanClient) {
1876
+ constructor(ledgerClient, logger, accessTokenProvider, isMasterUser) {
1873
1877
  this.ledgerClient = ledgerClient;
1874
- this.scanProxyClient = scanProxyClient;
1875
1878
  this.logger = logger;
1876
1879
  this.accessTokenProvider = accessTokenProvider;
1877
1880
  this.isMasterUser = isMasterUser;
1878
- this.scanClient = scanClient;
1879
1881
  __publicField(this, "core");
1880
1882
  __publicField(this, "allocation");
1881
1883
  __publicField(this, "transfer");
1882
1884
  this.core = new CoreService(
1883
1885
  ledgerClient,
1884
- scanProxyClient,
1885
1886
  logger,
1886
1887
  accessTokenProvider,
1887
1888
  isMasterUser,
@@ -1891,28 +1892,6 @@ var TokenStandardService = class {
1891
1892
  this.allocation = new AllocationService(this.core, this.logger);
1892
1893
  this.transfer = new TransferService(this.core, this.logger);
1893
1894
  }
1894
- async getTransferPreApprovalByParty(partyId) {
1895
- const { transfer_preapproval } = await this.scanProxyClient.get(
1896
- "/v0/scan-proxy/transfer-preapprovals/by-party/{party}",
1897
- {
1898
- path: {
1899
- party: partyId
1900
- }
1901
- }
1902
- );
1903
- return transfer_preapproval;
1904
- }
1905
- async getFeaturedAppsByParty(partyId) {
1906
- const { featured_app_right } = await this.scanProxyClient.get(
1907
- "/v0/scan-proxy/featured-apps/{provider_party_id}",
1908
- {
1909
- path: {
1910
- provider_party_id: partyId
1911
- }
1912
- }
1913
- );
1914
- return featured_app_right;
1915
- }
1916
1895
  async getInstrumentById(registryUrl, instrumentId) {
1917
1896
  try {
1918
1897
  const params = {
@@ -1932,77 +1911,6 @@ var TokenStandardService = class {
1932
1911
  );
1933
1912
  }
1934
1913
  }
1935
- async buyMemberTraffic(dso, provider, trafficAmount, synchronizerId, memberId, migrationId, inputUtxos) {
1936
- const amuletRules = await this.scanProxyClient.getAmuletRules();
1937
- const activeRound = await this.scanProxyClient.getActiveOpenMiningRound();
1938
- const inputHoldings = await this.core.getInputHoldingsCids(
1939
- provider,
1940
- inputUtxos,
1941
- trafficAmount
1942
- );
1943
- if (!amuletRules) {
1944
- throw new Error("AmuletRules contract not found");
1945
- }
1946
- if (!activeRound) {
1947
- throw new Error(
1948
- "OpenMiningRound active at current moment not found"
1949
- );
1950
- }
1951
- const disclosed = [
1952
- {
1953
- templateId: amuletRules.template_id,
1954
- contractId: amuletRules.contract_id,
1955
- createdEventBlob: amuletRules.created_event_blob,
1956
- synchronizerId
1957
- },
1958
- {
1959
- templateId: activeRound.template_id,
1960
- contractId: activeRound.contract_id,
1961
- createdEventBlob: activeRound.created_event_blob,
1962
- synchronizerId
1963
- }
1964
- ];
1965
- const context = {
1966
- openMiningRound: activeRound.contract_id,
1967
- issuingMiningRounds: [],
1968
- validatorRights: [],
1969
- featuredAppRight: null
1970
- };
1971
- const choiceArgs = {
1972
- context,
1973
- inputs: inputHoldings.map((cid) => ({
1974
- tag: "InputAmulet",
1975
- value: cid
1976
- })),
1977
- provider,
1978
- memberId: this.core.toQualifiedMemberId(memberId),
1979
- synchronizerId,
1980
- migrationId,
1981
- trafficAmount,
1982
- expectedDso: dso
1983
- };
1984
- const exercise = {
1985
- templateId: "#splice-amulet:Splice.AmuletRules:AmuletRules",
1986
- contractId: amuletRules.contract_id,
1987
- choice: "AmuletRules_BuyMemberTraffic",
1988
- choiceArgument: choiceArgs
1989
- };
1990
- return [exercise, disclosed];
1991
- }
1992
- async getMemberTrafficStatus(domainId, memberId) {
1993
- if (!this.scanClient) {
1994
- throw new Error("Scan API URL was not provided");
1995
- }
1996
- return this.scanClient.get(
1997
- "/v0/domains/{domain_id}/members/{member_id}/traffic-status",
1998
- {
1999
- path: {
2000
- domain_id: domainId,
2001
- member_id: this.core.toQualifiedMemberId(memberId)
2002
- }
2003
- }
2004
- );
2005
- }
2006
1914
  async getInstrumentAdmin(registryUrl) {
2007
1915
  const client = this.core.getTokenStandardClient(registryUrl);
2008
1916
  const info = await client.get("/registry/metadata/v1/info");
@@ -2088,8 +1996,8 @@ var TokenStandardService = class {
2088
1996
  this.ledgerClient
2089
1997
  );
2090
1998
  }
2091
- async getInputHoldingsCids(sender, inputUtxos) {
2092
- return this.core.getInputHoldingsCids(sender, inputUtxos);
1999
+ async getInputHoldingsCids(sender, inputUtxos, amount) {
2000
+ return this.core.getInputHoldingsCids(sender, inputUtxos, amount);
2093
2001
  }
2094
2002
  async createDelegateProxyTranfser(sender, receiver, amount, instrumentAdmin, instrumentId, registryUrl, featuredAppRightCid, proxyCid, beneficiaries, inputUtxos, memo, expiryDate, meta) {
2095
2003
  const [transferCommand, disclosedContracts] = await this.transfer.createTransfer(
@@ -2127,58 +2035,137 @@ var TokenStandardService = class {
2127
2035
  };
2128
2036
  return [exercise, disclosedContracts];
2129
2037
  }
2130
- // TODO(#583) as it's not a part of token standard, should be moved somewhere else
2131
- async createTap(receiver, amount, instrumentAdmin, instrumentId, registryUrl) {
2132
- const now = /* @__PURE__ */ new Date();
2133
- const tomorrow = new Date(now);
2134
- tomorrow.setDate(tomorrow.getDate() + 1);
2038
+ async exerciseDelegateProxyTransferInstructionAccept(exchangeParty, proxyCid, transferInstructionCid, registryUrl, featuredAppRightCid) {
2039
+ const [acceptTransferInstructionContext, disclosedContracts] = await this.transfer.createAcceptTransferInstruction(
2040
+ transferInstructionCid,
2041
+ registryUrl
2042
+ );
2135
2043
  const choiceArgs = {
2136
- expectedAdmin: instrumentAdmin,
2137
- transfer: {
2138
- sender: instrumentAdmin,
2139
- receiver,
2140
- amount,
2141
- instrumentId: { admin: instrumentAdmin, id: instrumentId },
2142
- lock: null,
2143
- requestedAt: new Date(
2144
- Date.now() - REQUESTED_AT_SKEW_MS
2145
- ).toISOString(),
2146
- executeBefore: tomorrow.toISOString(),
2147
- inputHoldingCids: [],
2148
- meta: { values: {} }
2149
- },
2150
- extraArgs: {
2151
- context: { values: {} },
2152
- meta: { values: {} }
2044
+ cid: acceptTransferInstructionContext.contractId,
2045
+ proxyArg: {
2046
+ featuredAppRightCid,
2047
+ beneficiaries: [
2048
+ {
2049
+ beneficiary: exchangeParty,
2050
+ weight: 1
2051
+ }
2052
+ ],
2053
+ choiceArg: acceptTransferInstructionContext.choiceArgument
2153
2054
  }
2154
2055
  };
2155
- const transferFactory = await this.core.getTokenStandardClient(registryUrl).post("/registry/transfer-instruction/v1/transfer-factory", {
2156
- choiceArguments: choiceArgs
2157
- });
2158
- const disclosedContracts = transferFactory.choiceContext.disclosedContracts;
2056
+ return [
2057
+ {
2058
+ templateId: "#splice-util-featured-app-proxies:Splice.Util.FeaturedApp.DelegateProxy:DelegateProxy",
2059
+ contractId: proxyCid,
2060
+ choice: "DelegateProxy_TransferInstruction_Accept",
2061
+ choiceArgument: choiceArgs
2062
+ },
2063
+ disclosedContracts
2064
+ ];
2065
+ }
2066
+ };
2067
+ __publicField(TokenStandardService, "MEMO_KEY", "splice.lfdecentralizedtrust.org/reason");
2068
+
2069
+ // src/amulet-service.ts
2070
+ var REQUESTED_AT_SKEW_MS2 = 6e4;
2071
+ var AmuletService = class {
2072
+ constructor(tokenStandard, scanProxyClient, scanClient) {
2073
+ this.tokenStandard = tokenStandard;
2074
+ this.scanProxyClient = scanProxyClient;
2075
+ this.scanClient = scanClient;
2076
+ }
2077
+ async getTransferPreApprovalByParty(partyId) {
2078
+ const { transfer_preapproval } = await this.scanProxyClient.get(
2079
+ "/v0/scan-proxy/transfer-preapprovals/by-party/{party}",
2080
+ {
2081
+ path: {
2082
+ party: partyId
2083
+ }
2084
+ }
2085
+ );
2086
+ return transfer_preapproval;
2087
+ }
2088
+ async getFeaturedAppsByParty(partyId) {
2089
+ const { featured_app_right } = await this.scanProxyClient.get(
2090
+ "/v0/scan-proxy/featured-apps/{provider_party_id}",
2091
+ {
2092
+ path: {
2093
+ provider_party_id: partyId
2094
+ }
2095
+ }
2096
+ );
2097
+ return featured_app_right;
2098
+ }
2099
+ async buyMemberTraffic(dso, provider, trafficAmount, synchronizerId, memberId, migrationId, inputUtxos) {
2159
2100
  const amuletRules = await this.scanProxyClient.getAmuletRules();
2101
+ const activeRound = await this.scanProxyClient.getActiveOpenMiningRound();
2102
+ const inputHoldings = await this.tokenStandard.getInputHoldingsCids(
2103
+ provider,
2104
+ inputUtxos,
2105
+ trafficAmount
2106
+ );
2160
2107
  if (!amuletRules) {
2161
2108
  throw new Error("AmuletRules contract not found");
2162
2109
  }
2163
- const latestOpenMiningRound = await this.scanProxyClient.getActiveOpenMiningRound();
2164
- if (!latestOpenMiningRound) {
2110
+ if (!activeRound) {
2165
2111
  throw new Error(
2166
2112
  "OpenMiningRound active at current moment not found"
2167
2113
  );
2168
2114
  }
2169
- return [
2115
+ const disclosed = [
2170
2116
  {
2171
2117
  templateId: amuletRules.template_id,
2172
2118
  contractId: amuletRules.contract_id,
2173
- choice: "AmuletRules_DevNet_Tap",
2174
- choiceArgument: {
2175
- receiver,
2176
- amount,
2177
- openRound: latestOpenMiningRound.contract_id
2178
- }
2119
+ createdEventBlob: amuletRules.created_event_blob,
2120
+ synchronizerId
2179
2121
  },
2180
- disclosedContracts
2122
+ {
2123
+ templateId: activeRound.template_id,
2124
+ contractId: activeRound.contract_id,
2125
+ createdEventBlob: activeRound.created_event_blob,
2126
+ synchronizerId
2127
+ }
2181
2128
  ];
2129
+ const context = {
2130
+ openMiningRound: activeRound.contract_id,
2131
+ issuingMiningRounds: [],
2132
+ validatorRights: [],
2133
+ featuredAppRight: null
2134
+ };
2135
+ const choiceArgs = {
2136
+ context,
2137
+ inputs: inputHoldings.map((cid) => ({
2138
+ tag: "InputAmulet",
2139
+ value: cid
2140
+ })),
2141
+ provider,
2142
+ memberId: this.tokenStandard.core.toQualifiedMemberId(memberId),
2143
+ synchronizerId,
2144
+ migrationId,
2145
+ trafficAmount,
2146
+ expectedDso: dso
2147
+ };
2148
+ const exercise = {
2149
+ templateId: "#splice-amulet:Splice.AmuletRules:AmuletRules",
2150
+ contractId: amuletRules.contract_id,
2151
+ choice: "AmuletRules_BuyMemberTraffic",
2152
+ choiceArgument: choiceArgs
2153
+ };
2154
+ return [exercise, disclosed];
2155
+ }
2156
+ async getMemberTrafficStatus(domainId, memberId) {
2157
+ if (!this.scanClient) {
2158
+ throw new Error("Scan API URL was not provided");
2159
+ }
2160
+ return this.scanClient.get(
2161
+ "/v0/domains/{domain_id}/members/{member_id}/traffic-status",
2162
+ {
2163
+ path: {
2164
+ domain_id: domainId,
2165
+ member_id: this.tokenStandard.core.toQualifiedMemberId(memberId)
2166
+ }
2167
+ }
2168
+ );
2182
2169
  }
2183
2170
  async selfGrantFeatureAppRight(providerPartyId, synchronizerId) {
2184
2171
  const amuletRules = await this.scanProxyClient.getAmuletRules();
@@ -2234,7 +2221,7 @@ var TokenStandardService = class {
2234
2221
  synchronizerId
2235
2222
  }
2236
2223
  ];
2237
- const inputHoldings = await this.core.getInputHoldingsCids(
2224
+ const inputHoldings = await this.tokenStandard.getInputHoldingsCids(
2238
2225
  provider,
2239
2226
  inputUtxos
2240
2227
  );
@@ -2263,30 +2250,54 @@ var TokenStandardService = class {
2263
2250
  };
2264
2251
  return [exercise, disclosed];
2265
2252
  }
2266
- async exerciseDelegateProxyTransferInstructionAccept(exchangeParty, proxyCid, transferInstructionCid, registryUrl, featuredAppRightCid) {
2267
- const [acceptTransferInstructionContext, disclosedContracts] = await this.transfer.createAcceptTransferInstruction(
2268
- transferInstructionCid,
2269
- registryUrl
2270
- );
2253
+ async createTap(receiver, amount, instrumentAdmin, instrumentId, registryUrl) {
2254
+ const now = /* @__PURE__ */ new Date();
2255
+ const tomorrow = new Date(now);
2256
+ tomorrow.setDate(tomorrow.getDate() + 1);
2271
2257
  const choiceArgs = {
2272
- cid: acceptTransferInstructionContext.contractId,
2273
- proxyArg: {
2274
- featuredAppRightCid,
2275
- beneficiaries: [
2276
- {
2277
- beneficiary: exchangeParty,
2278
- weight: 1
2279
- }
2280
- ],
2281
- choiceArg: acceptTransferInstructionContext.choiceArgument
2258
+ expectedAdmin: instrumentAdmin,
2259
+ transfer: {
2260
+ sender: instrumentAdmin,
2261
+ receiver,
2262
+ amount,
2263
+ instrumentId: { admin: instrumentAdmin, id: instrumentId },
2264
+ lock: null,
2265
+ requestedAt: new Date(
2266
+ Date.now() - REQUESTED_AT_SKEW_MS2
2267
+ ).toISOString(),
2268
+ executeBefore: tomorrow.toISOString(),
2269
+ inputHoldingCids: [],
2270
+ meta: { values: {} }
2271
+ },
2272
+ extraArgs: {
2273
+ context: { values: {} },
2274
+ meta: { values: {} }
2282
2275
  }
2283
2276
  };
2277
+ const disclosedContracts = (await this.tokenStandard.transfer.fetchTransferFactoryChoiceContext(
2278
+ registryUrl,
2279
+ choiceArgs
2280
+ )).choiceContext.disclosedContracts;
2281
+ const amuletRules = await this.scanProxyClient.getAmuletRules();
2282
+ if (!amuletRules) {
2283
+ throw new Error("AmuletRules contract not found");
2284
+ }
2285
+ const latestOpenMiningRound = await this.scanProxyClient.getActiveOpenMiningRound();
2286
+ if (!latestOpenMiningRound) {
2287
+ throw new Error(
2288
+ "OpenMiningRound active at current moment not found"
2289
+ );
2290
+ }
2284
2291
  return [
2285
2292
  {
2286
- templateId: "#splice-util-featured-app-proxies:Splice.Util.FeaturedApp.DelegateProxy:DelegateProxy",
2287
- contractId: proxyCid,
2288
- choice: "DelegateProxy_TransferInstruction_Accept",
2289
- choiceArgument: choiceArgs
2293
+ templateId: amuletRules.template_id,
2294
+ contractId: amuletRules.contract_id,
2295
+ choice: "AmuletRules_DevNet_Tap",
2296
+ choiceArgument: {
2297
+ receiver,
2298
+ amount,
2299
+ openRound: latestOpenMiningRound.contract_id
2300
+ }
2290
2301
  },
2291
2302
  disclosedContracts
2292
2303
  ];
@@ -3289,6 +3300,6 @@ var WSSupportWithBackOffSwitch = class {
3289
3300
  }
3290
3301
  };
3291
3302
 
3292
- export { ACSContainer, ACS_UPDATE_CONFIG, CoreService, LedgerClient, TokenStandardService, WSSupportWithBackOffSwitch, asJsCantonError, awaitCompletion, defaultRetryableOptions, isJsCantonError, promiseWithTimeout, supportedVersions };
3303
+ export { ACSContainer, ACS_UPDATE_CONFIG, AmuletService, CoreService, LedgerClient, TokenStandardService, WSSupportWithBackOffSwitch, asJsCantonError, awaitCompletion, defaultRetryableOptions, isJsCantonError, promiseWithTimeout, supportedVersions };
3293
3304
  //# sourceMappingURL=index.js.map
3294
3305
  //# sourceMappingURL=index.js.map