@canton-network/core-token-standard-service 1.13.0 → 2.0.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 +54 -0
- package/dist/core-service.d.ts.map +1 -0
- package/dist/index.cjs +710 -365
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +678 -360
- package/dist/index.js.map +1 -1
- package/dist/token-standard-service.d.ts +54 -159
- package/dist/token-standard-service.d.ts.map +1 -1
- package/dist/types.d.ts +61 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/v1/allocation-service.d.ts +33 -0
- package/dist/v1/allocation-service.d.ts.map +1 -0
- package/dist/v1/transfer-service.d.ts +49 -0
- package/dist/v1/transfer-service.d.ts.map +1 -0
- package/dist/v2/allocation-service.d.ts +44 -0
- package/dist/v2/allocation-service.d.ts.map +1 -0
- package/dist/v2/transfer-service.d.ts +32 -0
- package/dist/v2/transfer-service.d.ts.map +1 -0
- package/package.json +14 -14
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["TokenStandardClient","HOLDING_INTERFACE_ID","Decimal","ACSReader","txUpdate","TransactionParser","renderTransaction","ensureInterfaceViewIsPresent","ALLOCATION_FACTORY_INTERFACE_ID","ALLOCATION_INTERFACE_ID","ALLOCATION_INSTRUCTION_INTERFACE_ID","ALLOCATION_REQUEST_INTERFACE_ID","TRANSFER_FACTORY_INTERFACE_ID","TRANSFER_INSTRUCTION_INTERFACE_ID","FEATURED_APP_DELEGATE_PROXY_INTERFACE_ID","EventFilterBySetup","TokenStandardTransactionInterfaces"],"sources":["../src/token-standard-service.ts"],"sourcesContent":["// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport {\n TokenStandardClient,\n TRANSFER_FACTORY_INTERFACE_ID,\n HOLDING_INTERFACE_ID,\n ALLOCATION_FACTORY_INTERFACE_ID,\n ALLOCATION_INTERFACE_ID,\n ALLOCATION_REQUEST_INTERFACE_ID,\n ALLOCATION_INSTRUCTION_INTERFACE_ID,\n TRANSFER_INSTRUCTION_INTERFACE_ID,\n type HoldingView,\n type AllocationFactory_Allocate,\n type AllocationSpecification,\n type Transfer,\n type ExtraArgs,\n type Metadata,\n FEATURED_APP_DELEGATE_PROXY_INTERFACE_ID,\n type Holding,\n type Beneficiaries,\n type OffLedger,\n} from '@canton-network/core-token-standard'\nimport {\n EventFilterBySetup,\n type LedgerCommonSchemas,\n} from '@canton-network/core-ledger-client-types'\nimport type { ContractId, Logger, PartyId } from '@canton-network/core-types'\nimport { ACSReader, type AcsOptions } from '@canton-network/core-acs-reader'\nimport {\n TokenStandardTransactionInterfaces,\n ensureInterfaceViewIsPresent,\n TransactionParser,\n type PrettyContract,\n renderTransaction,\n type ViewValue,\n type PrettyTransactions,\n type Transaction,\n type TransferObject,\n} from '@canton-network/core-tx-parser'\nimport type { AccessTokenProvider } from '@canton-network/core-wallet-auth'\nimport type {\n AbstractLedgerProvider,\n Ops,\n} from '@canton-network/core-provider-ledger'\nimport { Decimal } from 'decimal.js'\n\nconst REQUESTED_AT_SKEW_MS = 60_000\n\nexport type ExerciseCommand = LedgerCommonSchemas['ExerciseCommand']\nexport type DisclosedContract = LedgerCommonSchemas['DisclosedContract']\nconst EMPTY_META: Metadata = { values: {} }\n\ntype JsGetActiveContractsResponse =\n LedgerCommonSchemas['JsGetActiveContractsResponse']\ntype JsGetUpdatesResponse = Ops.PostV2Updates['ledgerApi']['result'][number]\ntype JsGetUpdateResponse = LedgerCommonSchemas['JsGetUpdateResponse']\ntype OffsetCheckpoint2 = LedgerCommonSchemas['OffsetCheckpoint2']\ntype JsTransaction = LedgerCommonSchemas['JsTransaction']\ntype UpdateFormat = LedgerCommonSchemas['UpdateFormat']\n\ntype JsActiveContract = LedgerCommonSchemas['JsActiveContract']\n\ntype OffsetCheckpointUpdate = {\n update: { OffsetCheckpoint: OffsetCheckpoint2 }\n}\ntype TransactionUpdate = {\n update: { Transaction: { value: JsTransaction } }\n}\n\ntype JsActiveContractEntryResponse = JsGetActiveContractsResponse & {\n contractEntry: {\n JsActiveContract: {\n createdEvent: LedgerCommonSchemas['CreatedEvent']\n }\n }\n}\n\ntype CreateTransferChoiceArgs = {\n expectedAdmin: PartyId\n transfer: Transfer\n extraArgs: ExtraArgs\n}\n\ntype ApiVersion = 'v1' | 'v2'\ntype SupportedVersions = ApiVersion[]\nconst SUPPORTED_VERSIONS: readonly ApiVersion[] = ['v1', 'v2'] as const\n\nfunction isApiVersion(v: string): v is ApiVersion {\n return (SUPPORTED_VERSIONS as readonly string[]).includes(v)\n}\n\nexport interface AssetCapabilities {\n holding: SupportedVersions\n transferInstruction: SupportedVersions\n allocation: SupportedVersions\n allocationInstruction: SupportedVersions\n allocationRequest: SupportedVersions\n}\n\nconst KEY_MAPPING: Record<string, keyof AssetCapabilities> = {\n holding: 'holding',\n 'transfer-instruction': 'transferInstruction',\n allocation: 'allocation',\n 'allocation-instruction': 'allocationInstruction',\n 'allocation-request': 'allocationRequest',\n}\n\nexport type InstrumentInfo = {\n id: string\n displayName: string\n symbol: string\n registryUrl: string\n admin: PartyId\n capabilities: AssetCapabilities\n}\n\nexport function resolveCapabilities(opts: {\n supportedApis: {\n [key: string]: number\n }\n}): AssetCapabilities {\n const supportedApis = opts.supportedApis\n\n const resolvedCapabilities: AssetCapabilities = {\n holding: [],\n transferInstruction: [],\n allocation: [],\n allocationInstruction: [],\n allocationRequest: [],\n }\n\n for (const key of Object.keys(supportedApis)) {\n const match = key.match(\n /^splice-api-token-(?<capabilityName>.+)-(?<version>v\\d+)$/\n )\n\n if (match?.groups) {\n const { capabilityName, version } = match.groups\n const targetKey = KEY_MAPPING[capabilityName]\n\n if (\n targetKey &&\n supportedApis[key] === 1 &&\n isApiVersion(version)\n ) {\n resolvedCapabilities[targetKey].push(version)\n }\n }\n }\n\n for (const key in resolvedCapabilities) {\n resolvedCapabilities[key as keyof AssetCapabilities].sort()\n }\n\n return resolvedCapabilities\n}\n\nexport class CoreService {\n constructor(\n private ledgerProvider: AbstractLedgerProvider,\n private readonly logger: Logger,\n private accessTokenProvider: AccessTokenProvider,\n private readonly isMasterUser: boolean\n ) {}\n\n getTokenStandardClient(registryUrl: string): TokenStandardClient {\n return new TokenStandardClient(\n registryUrl,\n this.logger,\n this.accessTokenProvider\n )\n }\n\n async getInputHoldingsCids(options: {\n sender: PartyId\n instrumentAdmin?: string\n instrumentId?: string\n inputUtxos?: string[]\n amount?: Decimal\n continueUntilCompletion?: boolean\n }) {\n const { sender, instrumentAdmin, instrumentId } = options\n const now = new Date()\n if (options.inputUtxos && options.inputUtxos.length > 0) {\n return options.inputUtxos\n }\n const senderHoldings = await this.listContractsByInterface<HoldingView>(\n HOLDING_INTERFACE_ID,\n sender,\n undefined,\n undefined,\n options.continueUntilCompletion\n )\n if (senderHoldings.length === 0) {\n throw new Error(\n \"Sender has no holdings, so transfer can't be executed.\"\n )\n }\n\n const unlockedSenderHoldings = senderHoldings.filter(\n (utxo) => !TokenStandardService.isHoldingLocked(utxo, now)\n )\n\n if (unlockedSenderHoldings.length > 100) {\n this.logger.warn(`Sender has more than 100 unlocked utxos.`)\n }\n\n const unlockedHoldingsForInstrument =\n instrumentAdmin && instrumentId\n ? await CoreService.filterHoldingsByInstrument({\n holdings: unlockedSenderHoldings,\n instrumentAdmin,\n instrumentId,\n })\n : unlockedSenderHoldings\n\n if (options.amount) {\n return CoreService.getInputHoldingsCidsForAmount(\n options.amount,\n unlockedHoldingsForInstrument\n )\n } else {\n return unlockedHoldingsForInstrument.map((h) => h.contractId)\n }\n }\n\n static async filterHoldingsByInstrument(options: {\n holdings: PrettyContract<HoldingView>[]\n instrumentAdmin: string\n instrumentId: string\n }) {\n const { holdings, instrumentAdmin, instrumentId } = options\n return holdings.filter((utxo) => {\n return (\n utxo.interfaceViewValue.instrumentId.id === instrumentId &&\n utxo.interfaceViewValue.instrumentId.admin === instrumentAdmin\n )\n })\n }\n\n static async getInputHoldingsCidsForAmount(\n amount: Decimal,\n unlockedSenderHoldings: PrettyContract<HoldingView>[]\n ) {\n //find holding that is the exact amount if possible\n const exactAmount = unlockedSenderHoldings.find((holding) =>\n new Decimal(holding.interfaceViewValue.amount).equals(amount)\n )\n\n if (exactAmount) {\n return [exactAmount.contractId]\n }\n\n //sort holdings from smallest to largest\n const sortedUnlockedSenderHoldings = unlockedSenderHoldings.toSorted(\n (a, b) =>\n new Decimal(a.interfaceViewValue.amount).comparedTo(\n new Decimal(b.interfaceViewValue.amount)\n )\n )\n\n const largestHoldingAmount = sortedUnlockedSenderHoldings.pop()\n\n if (!largestHoldingAmount) {\n throw new Error(`Sender doesn't have any unlocked holdings`)\n }\n\n let currentSum = new Decimal(\n largestHoldingAmount.interfaceViewValue.amount\n )\n const cIds = [largestHoldingAmount.contractId]\n\n for (const h of sortedUnlockedSenderHoldings) {\n if (currentSum.greaterThanOrEqualTo(amount)) {\n break\n }\n\n const currentHoldingAmount = new Decimal(\n h.interfaceViewValue.amount\n )\n\n currentSum = currentSum.plus(currentHoldingAmount)\n cIds.push(h.contractId)\n }\n\n if (currentSum.lessThan(amount)) {\n throw new Error(\n `Sender doesn't have sufficient funds for this transfer. Missing amount: ${amount.minus(currentSum)}`\n )\n }\n\n if (cIds.length > 100) {\n throw new Error(\n `Exceeded the maximum of 100 utxos in 1 transaction`\n )\n }\n\n return cIds\n }\n\n async listContractsByInterface<T = ViewValue>(\n interfaceId: string,\n partyId?: PartyId,\n limit?: number,\n offset?: number,\n continueUntilCompletion?: boolean\n ): Promise<PrettyContract<T>[]> {\n try {\n const ledgerEnd =\n offset ??\n (\n await this.ledgerProvider.request<Ops.GetV2StateLedgerEnd>({\n method: 'ledgerApi',\n params: {\n resource: '/v2/state/ledger-end',\n requestMethod: 'get',\n query: {},\n },\n })\n ).offset!\n\n const options: AcsOptions = {\n offset: ledgerEnd,\n interfaceIds: [interfaceId],\n parties: [partyId!],\n filterByParty: true,\n continueUntilCompletion: Boolean(continueUntilCompletion),\n }\n\n if (limit !== undefined) {\n options.limit = limit\n }\n\n //TODO: based on the. provider design we can't pass in the continue to completion, so right now it's defaulted to true in the ledger provider. we need to figure out how to add an ACS functionality and ensure better composability\n this.logger.info(\n `continue to completion: ${Boolean(continueUntilCompletion)}`\n )\n\n const reader = new ACSReader(this.ledgerProvider)\n\n const acsResponses: JsGetActiveContractsResponse[] =\n (await reader.raw.read(\n options\n ))! as JsGetActiveContractsResponse[]\n\n /* This filters out responses with entries of:\n - JsEmpty\n - JsIncompleteAssigned\n - JsIncompleteUnassigned\n while leaving JsActiveContract.\n It works fine only with single synchronizer\n TODO (#353) add support for multiple synchronizers\n */\n const isActiveContractEntry = (\n acsResponse: JsGetActiveContractsResponse\n ): acsResponse is JsActiveContractEntryResponse =>\n acsResponse.contractEntry != null &&\n 'JsActiveContract' in acsResponse.contractEntry &&\n acsResponse.contractEntry.JsActiveContract != null &&\n acsResponse.contractEntry.JsActiveContract.createdEvent != null\n\n const results: PrettyContract<T>[] = acsResponses\n .filter(isActiveContractEntry)\n .map((response) =>\n this.toPrettyContract<T>(\n interfaceId,\n response as JsActiveContractEntryResponse,\n ledgerEnd\n )\n )\n return results\n } catch (err) {\n this.logger.error(\n `Failed to list contracts of interface ${interfaceId}`,\n err\n )\n throw err\n }\n }\n\n async toPrettyTransactions(\n updates: JsGetUpdatesResponse[],\n partyId: PartyId\n ): Promise<PrettyTransactions> {\n // Runtime filters that also let TS know which of OneOfs types to check against\n const isOffsetCheckpointUpdate = (\n updateResponse: JsGetUpdatesResponse\n ): updateResponse is OffsetCheckpointUpdate =>\n updateResponse.update != null &&\n 'OffsetCheckpoint' in updateResponse.update\n\n const isTransactionUpdate = (\n updateResponse: JsGetUpdatesResponse\n ): updateResponse is TransactionUpdate =>\n updateResponse.update != null &&\n 'Transaction' in updateResponse.update &&\n !!updateResponse.update.Transaction?.value\n\n const offsetCheckpoints: number[] = updates\n .filter(isOffsetCheckpointUpdate)\n .map(\n (update) =>\n (update.update as OffsetCheckpointUpdate['update'])\n .OffsetCheckpoint.value.offset\n )\n const latestCheckpointOffset =\n offsetCheckpoints.length > 0 ? Math.max(...offsetCheckpoints) : 0\n\n const transactions: Transaction[] = await Promise.all(\n updates\n // exclude OffsetCheckpoint, Reassignment, TopologyTransaction\n .filter(isTransactionUpdate)\n .map(async (update) => {\n const txUpdate = update as TransactionUpdate\n const tx = txUpdate.update.Transaction\n .value as JsTransaction\n const parser = new TransactionParser(\n this.ledgerProvider,\n tx,\n partyId,\n this.isMasterUser\n )\n\n return await parser.parseTransaction()\n })\n )\n\n const transactionOffsets = transactions\n .map((tx) => tx.offset)\n .filter((offset): offset is number => offset !== undefined)\n\n return {\n // OffsetCheckpoint can be anywhere... or not at all, maybe\n nextOffset: Math.max(\n latestCheckpointOffset,\n ...(transactionOffsets.length > 0 ? transactionOffsets : [0])\n ),\n transactions: transactions\n .filter((tx) => tx.events.length > 0)\n .map(renderTransaction),\n }\n }\n\n async toPrettyTransaction(\n getUpdateResponse: JsGetUpdateResponse,\n partyId: PartyId\n ): Promise<Transaction> {\n const tx = this.getTransactionFromUpdate(getUpdateResponse)\n const parser = new TransactionParser(\n this.ledgerProvider,\n tx,\n partyId,\n this.isMasterUser\n )\n const parsedTx = await parser.parseTransaction()\n return renderTransaction(parsedTx)\n }\n\n async toPrettyTransferObjects(\n getUpdateResponse: JsGetUpdateResponse,\n partyId: PartyId\n ): Promise<TransferObject[]> {\n const tx = this.getTransactionFromUpdate(getUpdateResponse)\n const parser = new TransactionParser(\n this.ledgerProvider,\n tx,\n partyId,\n this.isMasterUser\n )\n return await parser.parseTransferObjects()\n }\n\n private getTransactionFromUpdate(\n getUpdateResponse: JsGetUpdateResponse\n ): JsTransaction {\n const update = getUpdateResponse.update\n if (!update || !('Transaction' in update)) {\n throw new Error('Expected transaction update')\n }\n return update.Transaction.value\n }\n\n async toPrettyTransactionsPerParty(\n updates: JsGetUpdatesResponse[],\n parties: PartyId[]\n ): Promise<Map<PartyId, PrettyTransactions>> {\n const all = await Promise.all(\n parties.map(\n async (partyId): Promise<[PartyId, PrettyTransactions]> => [\n partyId,\n await this.toPrettyTransactions(updates, partyId),\n ]\n )\n )\n return new Map(all)\n }\n\n // returns object with JsActiveContract content\n // and contractId and interface view value extracted from it as separate fields for convenience\n toPrettyContract<T>(\n interfaceId: string,\n response: JsActiveContractEntryResponse,\n offset?: number\n ): PrettyContract<T> {\n const activeContract = response.contractEntry\n .JsActiveContract as JsActiveContract\n const { createdEvent } = activeContract\n return {\n contractId: createdEvent.contractId,\n activeContract,\n interfaceViewValue: ensureInterfaceViewIsPresent(\n createdEvent,\n interfaceId\n ).viewValue as T,\n fetchedAtOffset: offset,\n }\n }\n\n toQualifiedMemberId(memberId: string) {\n if (!memberId) throw new Error('memberId is required')\n\n return /^(PAR|MED)::/.test(memberId) ? memberId : `PAR::${memberId}`\n }\n}\n\nclass AllocationService {\n constructor(\n private core: CoreService,\n private readonly logger: Logger\n ) {}\n\n public async buildAllocationFactoryChoiceArgs(\n allocationSpecification: AllocationSpecification,\n expectedAdmin: PartyId,\n inputUtxos?: string[],\n requestedAt?: string\n ): Promise<AllocationFactory_Allocate> {\n const allocationSpecificationNormalized: AllocationSpecification = {\n ...allocationSpecification,\n settlement: {\n ...allocationSpecification.settlement,\n meta: allocationSpecification.settlement.meta ?? { values: {} },\n },\n transferLeg: {\n ...allocationSpecification.transferLeg,\n meta: allocationSpecification.transferLeg.meta ?? {\n values: {},\n },\n },\n }\n\n const inputHoldingCids = await this.core.getInputHoldingsCids({\n sender: allocationSpecificationNormalized.transferLeg.sender,\n inputUtxos: inputUtxos ?? [],\n instrumentAdmin:\n allocationSpecificationNormalized.transferLeg.instrumentId\n .admin,\n instrumentId:\n allocationSpecificationNormalized.transferLeg.instrumentId.id,\n })\n\n return {\n expectedAdmin,\n allocation: allocationSpecificationNormalized,\n requestedAt:\n requestedAt ??\n new Date(Date.now() - REQUESTED_AT_SKEW_MS).toISOString(),\n inputHoldingCids:\n inputHoldingCids as unknown as ContractId<Holding>[],\n extraArgs: {\n context: { values: {} },\n meta: { values: {} },\n },\n }\n }\n\n async fetchAllocationFactoryChoiceContext(\n registryUrl: string,\n choiceArgs: AllocationFactory_Allocate,\n excludeDebugFields: boolean = true\n ): Promise<\n OffLedger.AllocationInstructionV1.components['schemas']['FactoryWithChoiceContext']\n > {\n return this.core\n .getTokenStandardClient(registryUrl)\n .post('/registry/allocation-instruction/v1/allocation-factory', {\n choiceArguments: choiceArgs as unknown as Record<string, never>,\n excludeDebugFields,\n })\n }\n\n async createAllocationInstructionFromContext(\n factoryId: string,\n choiceArgs: AllocationFactory_Allocate,\n choiceContext: OffLedger.AllocationInstructionV1.components['schemas']['ChoiceContext']\n ): Promise<[ExerciseCommand, DisclosedContract[]]> {\n choiceArgs.extraArgs.context = {\n ...choiceContext.choiceContextData,\n values: choiceContext.choiceContextData?.values ?? {},\n }\n const exercise: ExerciseCommand = {\n templateId: ALLOCATION_FACTORY_INTERFACE_ID,\n contractId: factoryId,\n choice: 'AllocationFactory_Allocate',\n choiceArgument: choiceArgs,\n }\n return [exercise, choiceContext.disclosedContracts]\n }\n\n async createAllocationInstruction(\n allocationSpecification: AllocationSpecification,\n expectedAdmin: PartyId,\n registryUrl: string,\n inputUtxos?: string[],\n requestedAt?: string,\n prefetchedRegistryChoiceContext?: {\n factoryId: string\n choiceContext: OffLedger.AllocationInstructionV1.components['schemas']['ChoiceContext']\n }\n ): Promise<[ExerciseCommand, DisclosedContract[]]> {\n const choiceArgs = await this.buildAllocationFactoryChoiceArgs(\n allocationSpecification,\n expectedAdmin,\n inputUtxos,\n requestedAt\n )\n\n if (prefetchedRegistryChoiceContext) {\n return this.createAllocationInstructionFromContext(\n prefetchedRegistryChoiceContext.factoryId,\n choiceArgs,\n prefetchedRegistryChoiceContext.choiceContext\n )\n }\n\n const { factoryId, choiceContext } =\n await this.fetchAllocationFactoryChoiceContext(\n registryUrl,\n choiceArgs\n )\n return this.createAllocationInstructionFromContext(\n factoryId,\n choiceArgs,\n choiceContext\n )\n }\n\n private buildAllocationExerciseWithContext(\n templateId: string,\n contractId: string,\n choice:\n | 'Allocation_ExecuteTransfer'\n | 'Allocation_Withdraw'\n | 'Allocation_Cancel',\n choiceContext: OffLedger.AllocationInstructionV1.components['schemas']['ChoiceContext']\n ): [ExerciseCommand, DisclosedContract[]] {\n const exercise: ExerciseCommand = {\n templateId,\n contractId,\n choice,\n choiceArgument: {\n extraArgs: {\n context: choiceContext.choiceContextData,\n meta: EMPTY_META,\n },\n },\n }\n return [exercise, choiceContext.disclosedContracts ?? []]\n }\n\n async fetchExecuteTransferChoiceContext(\n allocationId: string,\n registryUrl: string\n ) {\n return this.core.getTokenStandardClient(registryUrl).post(\n '/registry/allocations/v1/{allocationId}/choice-contexts/execute-transfer',\n {\n excludeDebugFields: true,\n },\n {\n path: {\n allocationId,\n },\n }\n )\n }\n\n createExecuteTransferAllocationFromContext(\n allocationCid: string,\n choiceContext: OffLedger.AllocationInstructionV1.components['schemas']['ChoiceContext']\n ): [ExerciseCommand, DisclosedContract[]] {\n return this.buildAllocationExerciseWithContext(\n ALLOCATION_INTERFACE_ID,\n allocationCid,\n 'Allocation_ExecuteTransfer',\n choiceContext\n )\n }\n\n async createExecuteTransferAllocation(\n allocationCid: string,\n registryUrl: string,\n prefetchedRegistryChoiceContext?: OffLedger.AllocationInstructionV1.components['schemas']['ChoiceContext']\n ): Promise<[ExerciseCommand, DisclosedContract[]]> {\n if (prefetchedRegistryChoiceContext) {\n return this.createExecuteTransferAllocationFromContext(\n allocationCid,\n prefetchedRegistryChoiceContext\n )\n }\n const choiceContext = await this.fetchExecuteTransferChoiceContext(\n allocationCid,\n registryUrl\n )\n return this.createExecuteTransferAllocationFromContext(\n allocationCid,\n choiceContext\n )\n }\n\n async fetchWithdrawAllocationChoiceContext(\n allocationCid: string,\n registryUrl: string\n ): Promise<\n OffLedger.AllocationInstructionV1.components['schemas']['ChoiceContext']\n > {\n return this.core.getTokenStandardClient(registryUrl).post(\n '/registry/allocations/v1/{allocationId}/choice-contexts/withdraw',\n {\n excludeDebugFields: true,\n },\n { path: { allocationId: allocationCid } }\n )\n }\n\n createWithdrawAllocationFromContext(\n allocationCid: string,\n choiceContext: OffLedger.AllocationInstructionV1.components['schemas']['ChoiceContext']\n ): [ExerciseCommand, DisclosedContract[]] {\n return this.buildAllocationExerciseWithContext(\n ALLOCATION_INTERFACE_ID,\n allocationCid,\n 'Allocation_Withdraw',\n choiceContext\n )\n }\n\n async createWithdrawAllocation(\n allocationCid: string,\n registryUrl: string,\n prefetchedRegistryChoiceContext?: OffLedger.AllocationInstructionV1.components['schemas']['ChoiceContext']\n ): Promise<[ExerciseCommand, DisclosedContract[]]> {\n if (prefetchedRegistryChoiceContext) {\n return this.createWithdrawAllocationFromContext(\n allocationCid,\n prefetchedRegistryChoiceContext\n )\n }\n const choiceContext = await this.fetchWithdrawAllocationChoiceContext(\n allocationCid,\n registryUrl\n )\n return this.createWithdrawAllocationFromContext(\n allocationCid,\n choiceContext\n )\n }\n\n async fetchCancelAllocationChoiceContext(\n allocationCid: string,\n registryUrl: string\n ): Promise<\n OffLedger.AllocationInstructionV1.components['schemas']['ChoiceContext']\n > {\n return this.core.getTokenStandardClient(registryUrl).post(\n '/registry/allocations/v1/{allocationId}/choice-contexts/cancel',\n {\n excludeDebugFields: true,\n },\n { path: { allocationId: allocationCid } }\n )\n }\n\n createCancelAllocationFromContext(\n allocationCid: string,\n choiceContext: OffLedger.AllocationInstructionV1.components['schemas']['ChoiceContext']\n ): [ExerciseCommand, DisclosedContract[]] {\n return this.buildAllocationExerciseWithContext(\n ALLOCATION_INTERFACE_ID,\n allocationCid,\n 'Allocation_Cancel',\n choiceContext\n )\n }\n\n async createCancelAllocation(\n allocationCid: string,\n registryUrl: string,\n prefetchedRegistryChoiceContext?: OffLedger.AllocationInstructionV1.components['schemas']['ChoiceContext']\n ): Promise<[ExerciseCommand, DisclosedContract[]]> {\n if (prefetchedRegistryChoiceContext) {\n return this.createCancelAllocationFromContext(\n allocationCid,\n prefetchedRegistryChoiceContext\n )\n }\n const choiceContext = await this.fetchCancelAllocationChoiceContext(\n allocationCid,\n registryUrl\n )\n return this.createCancelAllocationFromContext(\n allocationCid,\n choiceContext\n )\n }\n\n async createWithdrawAllocationInstruction(\n allocationInstructionCid: string\n ): Promise<[ExerciseCommand, DisclosedContract[]]> {\n const exercise: ExerciseCommand = {\n templateId: ALLOCATION_INSTRUCTION_INTERFACE_ID,\n contractId: allocationInstructionCid,\n choice: 'AllocationInstruction_Withdraw',\n choiceArgument: {\n extraArgs: {\n context: { values: {} },\n meta: { values: {} },\n },\n },\n }\n return [exercise, []]\n }\n\n async createUpdateAllocationInstruction(\n allocationInstructionCid: string,\n extraActors: PartyId[] = [],\n extraArgsContext: Record<string, unknown> = {},\n extraArgsMeta: Record<string, unknown> = {}\n ): Promise<[ExerciseCommand, DisclosedContract[]]> {\n const exercise: ExerciseCommand = {\n templateId: ALLOCATION_INSTRUCTION_INTERFACE_ID,\n contractId: allocationInstructionCid,\n choice: 'AllocationInstruction_Update',\n choiceArgument: {\n extraActors,\n extraArgs: {\n context: { values: extraArgsContext },\n meta: { values: extraArgsMeta },\n },\n },\n }\n return [exercise, []]\n }\n\n async createRejectAllocationRequest(\n allocationRequestCid: string,\n actor: PartyId\n ): Promise<[ExerciseCommand, DisclosedContract[]]> {\n const exercise: ExerciseCommand = {\n templateId: ALLOCATION_REQUEST_INTERFACE_ID,\n contractId: allocationRequestCid,\n choice: 'AllocationRequest_Reject',\n choiceArgument: {\n actor,\n extraArgs: {\n context: { values: {} },\n meta: { values: {} },\n },\n },\n }\n return [exercise, []]\n }\n\n async createWithdrawAllocationRequest(\n allocationRequestCid: string\n ): Promise<[ExerciseCommand, DisclosedContract[]]> {\n const exercise: ExerciseCommand = {\n templateId: ALLOCATION_REQUEST_INTERFACE_ID,\n contractId: allocationRequestCid,\n choice: 'AllocationRequest_Withdraw',\n choiceArgument: {\n extraArgs: {\n context: { values: {} },\n meta: { values: {} },\n },\n },\n }\n return [exercise, []]\n }\n}\n\nclass TransferService {\n constructor(\n private core: CoreService,\n private readonly logger: Logger\n ) {}\n\n public async buildTransferChoiceArgs(\n sender: PartyId,\n receiver: PartyId,\n amount: string,\n instrumentAdmin: PartyId,\n instrumentId: string,\n inputUtxos?: string[],\n memo?: string,\n expiryDate?: Date,\n meta?: Metadata,\n continueUntilCompletion?: boolean\n ): Promise<CreateTransferChoiceArgs> {\n const inputHoldingCids: string[] = await this.core.getInputHoldingsCids(\n {\n sender,\n instrumentAdmin,\n instrumentId,\n inputUtxos: inputUtxos ?? [],\n amount: new Decimal(amount),\n continueUntilCompletion: continueUntilCompletion ?? false,\n }\n )\n\n return {\n expectedAdmin: instrumentAdmin,\n transfer: {\n sender,\n receiver,\n amount,\n instrumentId: { admin: instrumentAdmin, id: instrumentId },\n requestedAt: new Date(\n Date.now() - REQUESTED_AT_SKEW_MS\n ).toISOString(),\n executeBefore: (\n expiryDate ?? new Date(Date.now() + 24 * 60 * 60 * 1000)\n ).toISOString(),\n inputHoldingCids:\n inputHoldingCids as unknown as ContractId<Holding>[],\n meta: {\n values: {\n [TokenStandardService.MEMO_KEY]: memo || '',\n ...meta?.values,\n },\n },\n },\n extraArgs: {\n context: { values: {} },\n meta: { values: {} },\n },\n }\n }\n\n async fetchTransferFactoryChoiceContext(\n registryUrl: string,\n choiceArgs: CreateTransferChoiceArgs,\n excludeDebugFields: boolean = true\n ): Promise<\n OffLedger.TransferInstructionV1.components['schemas']['TransferFactoryWithChoiceContext']\n > {\n return await this.core\n .getTokenStandardClient(registryUrl)\n .post('/registry/transfer-instruction/v1/transfer-factory', {\n choiceArguments: choiceArgs as unknown as Record<string, never>,\n excludeDebugFields,\n })\n }\n\n async createTransferFromContext(\n factoryId: string,\n choiceArgs: CreateTransferChoiceArgs,\n choiceContext: OffLedger.TransferInstructionV1.components['schemas']['ChoiceContext']\n ): Promise<[ExerciseCommand, DisclosedContract[]]> {\n this.logger.debug('Creating transfer from pre-fetched context...')\n choiceArgs.extraArgs.context = {\n ...choiceContext.choiceContextData,\n values: choiceContext.choiceContextData?.values ?? {},\n }\n const exercise: ExerciseCommand = {\n templateId: TRANSFER_FACTORY_INTERFACE_ID,\n contractId: factoryId,\n choice: 'TransferFactory_Transfer',\n choiceArgument: choiceArgs,\n }\n return [exercise, choiceContext.disclosedContracts]\n }\n\n // TODO: use named parameters\n async createTransfer(\n sender: PartyId,\n receiver: PartyId,\n amount: string,\n instrumentAdmin: PartyId, // TODO (#907): replace with registry call\n instrumentId: string,\n registryUrl: string,\n inputUtxos?: string[],\n memo?: string,\n expiryDate?: Date,\n meta?: Metadata,\n prefetchedRegistryChoiceContext?: {\n factoryId: string\n choiceContext: OffLedger.TransferInstructionV1.components['schemas']['ChoiceContext']\n },\n continueUntilCompletion?: boolean\n ): Promise<[ExerciseCommand, DisclosedContract[]]> {\n try {\n const choiceArgs = await this.buildTransferChoiceArgs(\n sender,\n receiver,\n amount,\n instrumentAdmin,\n instrumentId,\n inputUtxos,\n memo,\n expiryDate,\n meta,\n continueUntilCompletion\n )\n\n if (prefetchedRegistryChoiceContext) {\n return this.createTransferFromContext(\n prefetchedRegistryChoiceContext.factoryId,\n choiceArgs,\n prefetchedRegistryChoiceContext.choiceContext\n )\n }\n\n const { factoryId, choiceContext } =\n await this.fetchTransferFactoryChoiceContext(\n registryUrl,\n choiceArgs\n )\n\n return this.createTransferFromContext(\n factoryId,\n choiceArgs,\n choiceContext\n )\n } catch (e) {\n this.logger.error('Failed to execute transfer:', e)\n throw e\n }\n }\n\n async fetchAcceptTransferInstructionChoiceContext(\n transferInstructionCid: string,\n registryUrl: string\n ): Promise<{\n choiceContextData: unknown\n disclosedContracts: DisclosedContract[]\n }> {\n const client = this.core.getTokenStandardClient(registryUrl)\n const choiceContext = await client.post(\n '/registry/transfer-instruction/v1/{transferInstructionId}/choice-contexts/accept',\n {\n excludeDebugFields: true,\n },\n {\n path: {\n transferInstructionId: transferInstructionCid,\n },\n }\n )\n return {\n choiceContextData: choiceContext.choiceContextData,\n disclosedContracts: choiceContext.disclosedContracts,\n }\n }\n\n async createAcceptTransferInstructionFromContext(\n transferInstructionCid: string,\n choiceContext: {\n choiceContextData: unknown\n disclosedContracts: DisclosedContract[]\n }\n ): Promise<[ExerciseCommand, DisclosedContract[]]> {\n try {\n const exercise: ExerciseCommand = {\n templateId: TRANSFER_INSTRUCTION_INTERFACE_ID,\n contractId: transferInstructionCid,\n choice: 'TransferInstruction_Accept',\n choiceArgument: {\n extraArgs: {\n context: choiceContext.choiceContextData,\n meta: { values: {} },\n },\n },\n }\n return [exercise, choiceContext.disclosedContracts]\n } catch (e) {\n this.logger.error(\n 'Failed to create accept transfer instruction:',\n e\n )\n throw e\n }\n }\n\n async exerciseDelegateProxyTransferInstructionAccept(\n proxyCid: string,\n transferInstructionCid: string,\n registryUrl: URL,\n featuredAppRightCid: string,\n beneficiaries: Beneficiaries[]\n ): Promise<[ExerciseCommand, DisclosedContract[]]> {\n const [acceptTransferInstructionContext, disclosedContracts] =\n await this.createAcceptTransferInstruction(\n transferInstructionCid,\n registryUrl.href\n )\n\n const choiceArgs = {\n cid: acceptTransferInstructionContext.contractId,\n proxyArg: {\n featuredAppRightCid: featuredAppRightCid,\n beneficiaries: beneficiaries,\n choiceArg: acceptTransferInstructionContext.choiceArgument,\n },\n }\n\n return [\n {\n templateId: FEATURED_APP_DELEGATE_PROXY_INTERFACE_ID,\n contractId: proxyCid,\n choice: 'DelegateProxy_TransferInstruction_Accept',\n choiceArgument: choiceArgs,\n },\n disclosedContracts,\n ]\n }\n\n async exerciseDelegateProxyTransferInstructionReject(\n proxyCid: string,\n transferInstructionCid: string,\n registryUrl: URL,\n featuredAppRightCid: string,\n beneficiaries: Beneficiaries[]\n ): Promise<[ExerciseCommand, DisclosedContract[]]> {\n const [rejectTransferInstructionContext, disclosedContracts] =\n await this.createRejectTransferInstruction(\n transferInstructionCid,\n registryUrl.href\n )\n\n const choiceArgs = {\n cid: rejectTransferInstructionContext.contractId,\n proxyArg: {\n featuredAppRightCid: featuredAppRightCid,\n beneficiaries,\n choiceArg: rejectTransferInstructionContext.choiceArgument,\n },\n }\n\n return [\n {\n templateId: FEATURED_APP_DELEGATE_PROXY_INTERFACE_ID,\n contractId: proxyCid,\n choice: 'DelegateProxy_TransferInstruction_Reject',\n choiceArgument: choiceArgs,\n },\n disclosedContracts,\n ]\n }\n\n async exerciseDelegateProxyTransferInstructioWithdraw(\n proxyCid: string,\n transferInstructionCid: string,\n registryUrl: URL,\n featuredAppRightCid: string,\n beneficiaries: Beneficiaries[]\n ): Promise<[ExerciseCommand, DisclosedContract[]]> {\n const [withdrawTransferInstructionContext, disclosedContracts] =\n await this.createWithdrawTransferInstruction(\n transferInstructionCid,\n registryUrl.href\n )\n\n const sumOfWeights: number = beneficiaries.reduce(\n (totalWeight, beneficiary) => totalWeight + beneficiary.weight,\n 0\n )\n\n if (sumOfWeights > 1.0) {\n throw new Error('Sum of beneficiary weights is larger than 1.')\n }\n\n const choiceArgs = {\n cid: withdrawTransferInstructionContext.contractId,\n proxyArg: {\n featuredAppRightCid: featuredAppRightCid,\n beneficiaries,\n choiceArg: withdrawTransferInstructionContext.choiceArgument,\n },\n }\n\n return [\n {\n templateId: FEATURED_APP_DELEGATE_PROXY_INTERFACE_ID,\n contractId: proxyCid,\n choice: 'DelegateProxy_TransferInstruction_Withdraw',\n choiceArgument: choiceArgs,\n },\n disclosedContracts,\n ]\n }\n\n async createAcceptTransferInstruction(\n transferInstructionCid: string,\n registryUrl: string,\n prefetchedRegistryChoiceContext?: OffLedger.TransferInstructionV1.components['schemas']['ChoiceContext']\n ): Promise<[ExerciseCommand, DisclosedContract[]]> {\n if (prefetchedRegistryChoiceContext) {\n return this.createAcceptTransferInstructionFromContext(\n transferInstructionCid,\n {\n choiceContextData:\n prefetchedRegistryChoiceContext.choiceContextData,\n disclosedContracts:\n prefetchedRegistryChoiceContext.disclosedContracts,\n }\n )\n }\n const choiceContext =\n await this.fetchAcceptTransferInstructionChoiceContext(\n transferInstructionCid,\n registryUrl\n )\n return this.createAcceptTransferInstructionFromContext(\n transferInstructionCid,\n choiceContext\n )\n }\n\n async fetchRejectTransferInstructionChoiceContext(\n transferInstructionCid: string,\n registryUrl: string\n ): Promise<{\n choiceContextData: unknown\n disclosedContracts: DisclosedContract[]\n }> {\n const client = this.core.getTokenStandardClient(registryUrl)\n const choiceContext = await client.post(\n '/registry/transfer-instruction/v1/{transferInstructionId}/choice-contexts/reject',\n {\n excludeDebugFields: true,\n },\n {\n path: {\n transferInstructionId: transferInstructionCid,\n },\n }\n )\n return {\n choiceContextData: choiceContext.choiceContextData,\n disclosedContracts: choiceContext.disclosedContracts,\n }\n }\n\n async createRejectTransferInstructionFromContext(\n transferInstructionCid: string,\n choiceContext: {\n choiceContextData: unknown\n disclosedContracts: DisclosedContract[]\n }\n ): Promise<[ExerciseCommand, DisclosedContract[]]> {\n try {\n const exercise: ExerciseCommand = {\n templateId: TRANSFER_INSTRUCTION_INTERFACE_ID,\n contractId: transferInstructionCid,\n choice: 'TransferInstruction_Reject',\n choiceArgument: {\n extraArgs: {\n context: choiceContext.choiceContextData,\n meta: { values: {} },\n },\n },\n }\n return [exercise, choiceContext.disclosedContracts]\n } catch (e) {\n this.logger.error(\n 'Failed to create reject transfer instruction:',\n e\n )\n throw e\n }\n }\n\n async createRejectTransferInstruction(\n transferInstructionCid: string,\n registryUrl: string,\n prefetchedRegistryChoiceContext?: OffLedger.TransferInstructionV1.components['schemas']['ChoiceContext']\n ): Promise<[ExerciseCommand, DisclosedContract[]]> {\n if (prefetchedRegistryChoiceContext) {\n return this.createRejectTransferInstructionFromContext(\n transferInstructionCid,\n {\n choiceContextData:\n prefetchedRegistryChoiceContext.choiceContextData,\n disclosedContracts:\n prefetchedRegistryChoiceContext.disclosedContracts,\n }\n )\n }\n const choiceContext =\n await this.fetchRejectTransferInstructionChoiceContext(\n transferInstructionCid,\n registryUrl\n )\n return this.createRejectTransferInstructionFromContext(\n transferInstructionCid,\n choiceContext\n )\n }\n\n async fetchWithdrawTransferInstructionChoiceContext(\n transferInstructionCid: string,\n registryUrl: string\n ): Promise<{\n choiceContextData: unknown\n disclosedContracts: DisclosedContract[]\n }> {\n const client = this.core.getTokenStandardClient(registryUrl)\n\n const choiceContext = await client.post(\n '/registry/transfer-instruction/v1/{transferInstructionId}/choice-contexts/withdraw',\n {\n excludeDebugFields: true,\n },\n {\n path: {\n transferInstructionId: transferInstructionCid,\n },\n }\n )\n return {\n choiceContextData: choiceContext.choiceContextData,\n disclosedContracts: choiceContext.disclosedContracts,\n }\n }\n\n async createWithdrawTransferInstructionFromContext(\n transferInstructionCid: string,\n choiceContext: {\n choiceContextData: unknown\n disclosedContracts: DisclosedContract[]\n }\n ): Promise<[ExerciseCommand, DisclosedContract[]]> {\n try {\n const exercise: ExerciseCommand = {\n templateId: TRANSFER_INSTRUCTION_INTERFACE_ID,\n contractId: transferInstructionCid,\n choice: 'TransferInstruction_Withdraw',\n choiceArgument: {\n extraArgs: {\n context: choiceContext.choiceContextData,\n meta: { values: {} },\n },\n },\n }\n return [exercise, choiceContext.disclosedContracts]\n } catch (e) {\n this.logger.error(\n 'Failed to create withdraw transfer instruction:',\n e\n )\n throw e\n }\n }\n\n async createWithdrawTransferInstruction(\n transferInstructionCid: string,\n registryUrl: string,\n prefetchedRegistryChoiceContext?: OffLedger.TransferInstructionV1.components['schemas']['ChoiceContext']\n ): Promise<[ExerciseCommand, DisclosedContract[]]> {\n if (prefetchedRegistryChoiceContext) {\n return this.createWithdrawTransferInstructionFromContext(\n transferInstructionCid,\n {\n choiceContextData:\n prefetchedRegistryChoiceContext.choiceContextData,\n disclosedContracts:\n prefetchedRegistryChoiceContext.disclosedContracts,\n }\n )\n }\n const choiceContext =\n await this.fetchWithdrawTransferInstructionChoiceContext(\n transferInstructionCid,\n registryUrl\n )\n return this.createWithdrawTransferInstructionFromContext(\n transferInstructionCid,\n choiceContext\n )\n }\n\n async createTransferInstruction(\n transferInstructionCid: string,\n registryUrl: string,\n instructionChoice: 'Accept' | 'Reject' | 'Withdraw',\n prefetchedRegistryChoiceContext?: OffLedger.TransferInstructionV1.components['schemas']['ChoiceContext']\n ): Promise<[ExerciseCommand, DisclosedContract[]]> {\n switch (instructionChoice) {\n case 'Accept':\n return this.createAcceptTransferInstruction(\n transferInstructionCid,\n registryUrl,\n prefetchedRegistryChoiceContext\n )\n case 'Reject':\n return this.createRejectTransferInstruction(\n transferInstructionCid,\n registryUrl,\n prefetchedRegistryChoiceContext\n )\n case 'Withdraw':\n return this.createWithdrawTransferInstruction(\n transferInstructionCid,\n registryUrl,\n prefetchedRegistryChoiceContext\n )\n }\n }\n}\n\nexport class TokenStandardService {\n static readonly MEMO_KEY = 'splice.lfdecentralizedtrust.org/reason'\n\n readonly core: CoreService\n readonly allocation: AllocationService\n readonly transfer: TransferService\n\n constructor(\n private ledgerProvider: AbstractLedgerProvider,\n private logger: Logger,\n private accessTokenProvider: AccessTokenProvider,\n private readonly isMasterUser: boolean\n ) {\n this.core = new CoreService(\n ledgerProvider,\n logger,\n accessTokenProvider,\n isMasterUser\n )\n this.allocation = new AllocationService(this.core, this.logger)\n this.transfer = new TransferService(this.core, this.logger)\n }\n\n async resolveCapabilitiesFromRegistryByInstrumentId(\n registryUrl: string,\n instrumentId: string\n ): Promise<AssetCapabilities> {\n const metadataInfo = await this.getInstrumentById(\n registryUrl,\n instrumentId\n )\n return resolveCapabilities({\n supportedApis: metadataInfo.supportedApis,\n })\n }\n\n async getInstrumentById(registryUrl: string, instrumentId: string) {\n try {\n const params: Record<string, unknown> = {\n path: {\n instrumentId,\n },\n }\n\n const client = this.core.getTokenStandardClient(registryUrl)\n\n return await client.get(\n '/registry/metadata/v1/instruments/{instrumentId}',\n params\n )\n } catch (e) {\n this.logger.error(e)\n throw new Error(\n `Instrument id ${instrumentId} does not exist for this instrument admin.`,\n { cause: e }\n )\n }\n }\n\n async getInstrumentAdmin(registryUrl: string): Promise<string> {\n const client = this.core.getTokenStandardClient(registryUrl)\n\n const info = await client.get('/registry/metadata/v1/info')\n\n return info.adminId\n }\n\n async listInstruments(\n registryUrl: string,\n pageSize?: number,\n pageToken?: string\n ) {\n const client = this.core.getTokenStandardClient(registryUrl)\n return client.get('/registry/metadata/v1/instruments', {\n query: {\n ...(pageSize && { pageSize }),\n ...(pageToken && { pageToken }),\n },\n })\n }\n\n async instrumentsToAsset(registryUrl: string): Promise<\n {\n id: string\n displayName: string\n symbol: string\n registryUrl: string\n admin: PartyId\n capabilities: AssetCapabilities\n }[]\n > {\n let instrumentsResponse = await this.listInstruments(registryUrl)\n const instruments = [...instrumentsResponse.instruments]\n\n while (instrumentsResponse.nextPageToken) {\n instrumentsResponse = await this.listInstruments(\n registryUrl,\n undefined,\n instrumentsResponse.nextPageToken\n )\n instruments.push(...instrumentsResponse.instruments)\n }\n const instrumentAdmin = await this.getInstrumentAdmin(registryUrl)\n\n return instruments.map((instrument) => ({\n id: instrument.id,\n displayName: instrument.name,\n symbol: instrument.symbol,\n registryUrl,\n admin: instrumentAdmin,\n capabilities: resolveCapabilities({\n supportedApis: instrument.supportedApis,\n }),\n }))\n }\n\n async registriesToAssets(\n registryUrls: string[]\n ): Promise<InstrumentInfo[]> {\n const allInstruments: {\n id: string\n displayName: string\n symbol: string\n registryUrl: string\n admin: PartyId\n capabilities: AssetCapabilities\n }[] = []\n for (const registryUrl of registryUrls) {\n const instruments = await this.instrumentsToAsset(registryUrl)\n allInstruments.push(...instruments)\n }\n return allInstruments\n }\n\n // <T> is shape of viewValue related to queried interface.\n // i.e. when querying by TransferInstruction interfaceId, <T> would be TransferInstructionView from daml codegen\n async listContractsByInterface<T = ViewValue>(\n interfaceId: string,\n partyId?: PartyId,\n limit?: number,\n offset?: number,\n continueUntilCompletion?: boolean\n ): Promise<PrettyContract<T>[]> {\n return this.core.listContractsByInterface<T>(\n interfaceId,\n partyId,\n limit,\n offset,\n continueUntilCompletion\n )\n }\n\n async listHoldingTransactions(\n partyId: PartyId,\n afterOffset?: number,\n beforeOffset?: number\n ): Promise<PrettyTransactions> {\n try {\n this.logger.debug('Set or query offset')\n const afterOffsetOrLatest =\n afterOffset ??\n (\n await this.ledgerProvider.request<Ops.GetV2StateLatestPrunedOffsets>(\n {\n method: 'ledgerApi',\n params: {\n resource: '/v2/state/latest-pruned-offsets',\n requestMethod: 'get',\n },\n }\n )\n ).participantPrunedUpToInclusive!\n const beforeOffsetOrLatest =\n beforeOffset ??\n (\n await this.ledgerProvider.request<Ops.GetV2StateLedgerEnd>({\n method: 'ledgerApi',\n params: {\n resource: '/v2/state/ledger-end',\n requestMethod: 'get',\n query: {},\n },\n })\n ).offset!\n\n this.logger.debug(afterOffsetOrLatest, 'Using offset')\n const updatesResponse: JsGetUpdatesResponse[] =\n await this.ledgerProvider.request<Ops.PostV2Updates>({\n method: 'ledgerApi',\n params: {\n resource: '/v2/updates',\n requestMethod: 'post',\n query: {},\n body: {\n updateFormat: {\n includeTransactions: {\n eventFormat: EventFilterBySetup({\n interfaceIds:\n TokenStandardTransactionInterfaces,\n isMasterUser: this.isMasterUser,\n partyId: partyId,\n includeWildcard: true,\n }),\n transactionShape:\n 'TRANSACTION_SHAPE_LEDGER_EFFECTS',\n },\n },\n beginExclusive: afterOffsetOrLatest,\n endInclusive: beforeOffsetOrLatest,\n },\n },\n })\n\n return this.core.toPrettyTransactions(\n updatesResponse,\n partyId\n // this.ledgerProvider\n )\n } catch (err) {\n this.logger.error('Failed to list holding transactions.', err)\n throw err\n }\n }\n\n async getTransactionById(\n updateId: string,\n partyId: PartyId\n ): Promise<Transaction> {\n const updateFormat: UpdateFormat = {\n includeTransactions: {\n eventFormat: EventFilterBySetup({\n interfaceIds: TokenStandardTransactionInterfaces,\n isMasterUser: this.isMasterUser,\n partyId: partyId,\n includeWildcard: true,\n }),\n transactionShape: 'TRANSACTION_SHAPE_LEDGER_EFFECTS',\n },\n }\n\n const getUpdateResponse =\n await this.ledgerProvider.request<Ops.PostV2UpdatesUpdateById>({\n method: 'ledgerApi',\n params: {\n resource: '/v2/updates/update-by-id',\n requestMethod: 'post',\n body: {\n updateId,\n updateFormat,\n },\n },\n })\n\n return this.core.toPrettyTransaction(getUpdateResponse, partyId)\n }\n\n async getTransferObjectsById(\n updateId: string,\n partyId: PartyId\n ): Promise<TransferObject[]> {\n const updateFormat: UpdateFormat = {\n includeTransactions: {\n eventFormat: EventFilterBySetup({\n interfaceIds: TokenStandardTransactionInterfaces,\n isMasterUser: this.isMasterUser,\n partyId: partyId,\n includeWildcard: true,\n }),\n transactionShape: 'TRANSACTION_SHAPE_LEDGER_EFFECTS',\n },\n }\n\n const getUpdateResponse =\n await this.ledgerProvider.request<Ops.PostV2UpdatesUpdateById>({\n method: 'ledgerApi',\n params: {\n resource: '/v2/updates/update-by-id',\n requestMethod: 'post',\n body: {\n updateId,\n updateFormat,\n },\n },\n })\n\n return this.core.toPrettyTransferObjects(getUpdateResponse, partyId)\n }\n\n async getInputHoldingsCids(\n sender: PartyId,\n inputUtxos?: string[],\n amount?: Decimal\n ) {\n if (amount) {\n return this.core.getInputHoldingsCids({\n sender,\n inputUtxos: inputUtxos ?? [],\n amount,\n })\n } else {\n return this.core.getInputHoldingsCids({\n sender,\n inputUtxos: inputUtxos ?? [],\n })\n }\n }\n\n async createDelegateProxyTransfer(\n sender: PartyId,\n receiver: PartyId,\n amount: string,\n instrumentAdmin: PartyId, // TODO (#907): replace with registry call\n instrumentId: string,\n registryUrl: string,\n featuredAppRightCid: string,\n proxyCid: string,\n beneficiaries: Beneficiaries[],\n inputUtxos?: string[],\n memo?: string,\n expiryDate?: Date,\n meta?: Metadata\n ): Promise<[ExerciseCommand, DisclosedContract[]]> {\n const [transferCommand, disclosedContracts] =\n await this.transfer.createTransfer(\n sender,\n receiver,\n amount,\n instrumentAdmin,\n instrumentId,\n registryUrl,\n inputUtxos,\n memo,\n expiryDate,\n meta\n )\n\n const sumOfWeights: number = beneficiaries.reduce(\n (totalWeight, beneficiary) => totalWeight + beneficiary.weight,\n 0\n )\n\n if (sumOfWeights > 1.0) {\n throw new Error('Sum of beneficiary weights is larger than 1.')\n }\n\n const choiceArgs = {\n cid: transferCommand.contractId,\n proxyArg: {\n featuredAppRightCid: featuredAppRightCid,\n beneficiaries,\n choiceArg: transferCommand.choiceArgument,\n },\n }\n\n const exercise: ExerciseCommand = {\n templateId: FEATURED_APP_DELEGATE_PROXY_INTERFACE_ID,\n contractId: proxyCid,\n choice: 'DelegateProxy_TransferFactory_Transfer',\n choiceArgument: choiceArgs,\n }\n\n return [exercise, disclosedContracts]\n }\n\n async exerciseDelegateProxyTransferInstructionAccept(\n exchangeParty: PartyId,\n proxyCid: string,\n transferInstructionCid: string,\n registryUrl: string,\n featuredAppRightCid: string\n ): Promise<[ExerciseCommand, DisclosedContract[]]> {\n const [acceptTransferInstructionContext, disclosedContracts] =\n await this.transfer.createAcceptTransferInstruction(\n transferInstructionCid,\n registryUrl\n )\n\n const choiceArgs = {\n cid: acceptTransferInstructionContext.contractId,\n proxyArg: {\n featuredAppRightCid: featuredAppRightCid,\n beneficiaries: [\n {\n beneficiary: exchangeParty,\n weight: 1.0,\n },\n ],\n choiceArg: acceptTransferInstructionContext.choiceArgument,\n },\n }\n\n return [\n {\n templateId:\n '#splice-util-featured-app-proxies:Splice.Util.FeaturedApp.DelegateProxy:DelegateProxy',\n contractId: proxyCid,\n choice: 'DelegateProxy_TransferInstruction_Accept',\n choiceArgument: choiceArgs,\n },\n disclosedContracts,\n ]\n }\n\n static isHoldingLocked(\n holding: PrettyContract<HoldingView>,\n currentTime: Date = new Date()\n ): boolean {\n const lock = holding.interfaceViewValue.lock\n if (!lock) return false\n\n let expiresAtAbsolute: Date | null = null\n let expiresAtRelative: Date | null = null\n\n if (lock.expiresAfter) {\n const createdAt = new Date(\n holding.activeContract.createdEvent.createdAt\n )\n\n // 1 microsecond = 0.001 milliseconds\n const msToAdd = parseInt(lock.expiresAfter.microseconds) / 1000\n\n expiresAtRelative = new Date(createdAt.getTime() + msToAdd)\n }\n if (lock.expiresAt) {\n expiresAtAbsolute = new Date(lock.expiresAt)\n }\n\n let expiresAt: Date\n\n // If both `expiresAt` and `expiresAfter` are set, the lock expires at the earlier of the two times.\n if (expiresAtRelative && expiresAtAbsolute) {\n expiresAt =\n expiresAtRelative < expiresAtAbsolute\n ? expiresAtRelative\n : expiresAtAbsolute\n } else if (expiresAtRelative) {\n expiresAt = expiresAtRelative\n } else if (expiresAtAbsolute) {\n expiresAt = expiresAtAbsolute\n } else {\n // No expiration => locked\n return true\n }\n\n return currentTime < expiresAt\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CA,MAAM,uBAAuB;AAI7B,MAAM,aAAuB,EAAE,QAAQ,CAAC,EAAE;AAmC1C,MAAM,qBAA4C,CAAC,MAAM,IAAI;AAE7D,SAAS,aAAa,GAA4B;CAC9C,OAAQ,mBAAyC,SAAS,CAAC;AAC/D;AAUA,MAAM,cAAuD;CACzD,SAAS;CACT,wBAAwB;CACxB,YAAY;CACZ,0BAA0B;CAC1B,sBAAsB;AAC1B;AAWA,SAAgB,oBAAoB,MAId;CAClB,MAAM,gBAAgB,KAAK;CAE3B,MAAM,uBAA0C;EAC5C,SAAS,CAAC;EACV,qBAAqB,CAAC;EACtB,YAAY,CAAC;EACb,uBAAuB,CAAC;EACxB,mBAAmB,CAAC;CACxB;CAEA,KAAK,MAAM,OAAO,OAAO,KAAK,aAAa,GAAG;EAC1C,MAAM,QAAQ,IAAI,MACd,2DACJ;EAEA,IAAI,OAAO,QAAQ;GACf,MAAM,EAAE,gBAAgB,YAAY,MAAM;GAC1C,MAAM,YAAY,YAAY;GAE9B,IACI,aACA,cAAc,SAAS,KACvB,aAAa,OAAO,GAEpB,qBAAqB,UAAU,CAAC,KAAK,OAAO;EAEpD;CACJ;CAEA,KAAK,MAAM,OAAO,sBACd,qBA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,IAAI,CAAC,MAAM,OAAO;EAElB,IAAI,oBAAiC;EACrC,IAAI,oBAAiC;EAErC,IAAI,KAAK,cAAc;GACnB,MAAM,YAAY,IAAI,KAClB,QAAQ,eAAe,aAAa,SACxC;GAGA,MAAM,UAAU,SAAS,KAAK,aAAa,YAAY,IAAI;GAE3D,oBAAoB,IAAI,KAAK,UAAU,QAAQ,IAAI,OAAO;EAC9D;EACA,IAAI,KAAK,WACL,oBAAoB,IAAI,KAAK,KAAK,SAAS;EAG/C,IAAI;EAGJ,IAAI,qBAAqB,mBACrB,YACI,oBAAoB,oBACd,oBACA;OACP,IAAI,mBACP,YAAY;OACT,IAAI,mBACP,YAAY;OAGZ,OAAO;EAGX,OAAO,cAAc;CACzB;AACJ;AA7boB,gBAAA,sBAAA,YAAW,wCAAA"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["getLogger","Decimal","TRANSFER_FACTORY_INTERFACE_ID_V2","TRANSFER_INSTRUCTION_INTERFACE_ID_V2","TransferInstruction","getLogger","Decimal","TRANSFER_FACTORY_INTERFACE_ID","TRANSFER_INSTRUCTION_INTERFACE_ID","TransferInstruction","FEATURED_APP_DELEGATE_PROXY_INTERFACE_ID","AllocationService","ALLOCATION_FACTORY_INTERFACE_ID","ALLOCATION_INTERFACE_ID","ALLOCATION_INSTRUCTION_INTERFACE_ID","ALLOCATION_REQUEST_INTERFACE_ID","getLogger","TokenStandardClientV2","TokenStandardClient","HOLDING_INTERFACE_ID","Decimal","ACSReader","txUpdate","TransactionParser","renderTransaction","ensureInterfaceViewIsPresent","getLogger","Decimal","ALLOCATION_INTERFACE_ID_V2","ALLOCATION_REQUEST_INTERFACE_ID_V2","ALLOCATION_INSTRUCTION_INTERFACE_ID_V2","ALLOCATION_FACTORY_INTERFACE_ID_V2","getLogger","AllocationService","AllocationServiceV2","EventFilterBySetup","TokenStandardTransactionInterfaces","FEATURED_APP_DELEGATE_PROXY_INTERFACE_ID"],"sources":["../src/types.ts","../src/v2/transfer-service.ts","../src/v1/transfer-service.ts","../src/v1/allocation-service.ts","../src/core-service.ts","../src/v2/allocation-service.ts","../src/token-standard-service.ts"],"sourcesContent":["// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { LedgerCommonSchemas } from '@canton-network/core-ledger-client-types'\nimport type { Ops } from '@canton-network/core-provider-ledger'\nimport type {\n TokenStandardClient,\n Metadata,\n Transfer,\n ExtraArgs,\n} from '@canton-network/core-token-standard'\nimport type { PartyId } from '@canton-network/core-types'\nimport type { TokenStandardClient as TokenStandardClientV2 } from '@canton-network/core-token-standard-v2'\n\nexport const REQUESTED_AT_SKEW_MS = 60_000\n\nexport type ExerciseCommand = LedgerCommonSchemas['ExerciseCommand']\nexport type DisclosedContract = LedgerCommonSchemas['DisclosedContract']\nexport type GenericTokenStandardClient =\n TokenStandardClient | TokenStandardClientV2\nexport const EMPTY_META: Metadata = { values: {} }\n\nexport type JsGetActiveContractsResponse =\n LedgerCommonSchemas['JsGetActiveContractsResponse']\nexport type JsGetUpdatesResponse =\n Ops.PostV2Updates['ledgerApi']['result'][number]\nexport type JsGetUpdateResponse = LedgerCommonSchemas['JsGetUpdateResponse']\nexport type OffsetCheckpoint2 = LedgerCommonSchemas['OffsetCheckpoint2']\nexport type JsTransaction = LedgerCommonSchemas['JsTransaction']\nexport type UpdateFormat = LedgerCommonSchemas['UpdateFormat']\n\nexport type JsActiveContract = LedgerCommonSchemas['JsActiveContract']\n\nexport type OffsetCheckpointUpdate = {\n update: { OffsetCheckpoint: OffsetCheckpoint2 }\n}\nexport type TransactionUpdate = {\n update: { Transaction: { value: JsTransaction } }\n}\n\nexport type JsActiveContractEntryResponse = JsGetActiveContractsResponse & {\n contractEntry: {\n JsActiveContract: {\n createdEvent: LedgerCommonSchemas['CreatedEvent']\n }\n }\n}\n\nexport type CreateTransferChoiceArgs = {\n expectedAdmin: PartyId\n transfer: Transfer\n extraArgs: ExtraArgs\n}\n\nexport type ApiVersion = 'v1' | 'v2'\nexport type SupportedVersions = ApiVersion[]\nexport const SUPPORTED_VERSIONS: readonly ApiVersion[] = ['v1', 'v2'] as const\n\nexport interface AssetCapabilities {\n holding: SupportedVersions\n transferInstruction: SupportedVersions\n allocation: SupportedVersions\n allocationInstruction: SupportedVersions\n allocationRequest: SupportedVersions\n}\n\nexport const KEY_MAPPING: Record<string, keyof AssetCapabilities> = {\n holding: 'holding',\n 'transfer-instruction': 'transferInstruction',\n allocation: 'allocation',\n 'allocation-instruction': 'allocationInstruction',\n 'allocation-request': 'allocationRequest',\n}\n\nexport type AssetBody = {\n id: string\n displayName: string\n symbol: string\n registryUrl: URL\n admin: PartyId\n capabilities: AssetCapabilities\n}\n","// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { Metadata } from '@canton-network/core-token-standard'\nimport type { ContractId, PartyId } from '@canton-network/core-types'\nimport Decimal from 'decimal.js'\nimport { TokenStandardService } from '../token-standard-service'\nimport {\n type DisclosedContract,\n EMPTY_META,\n type ExerciseCommand,\n REQUESTED_AT_SKEW_MS,\n} from '../types'\nimport {\n type Account,\n type TransferFactory_Transfer as TransferFactory_TransferV2,\n type Holding as HoldingV2,\n type OffLedger as OffLedgerV2,\n TRANSFER_FACTORY_INTERFACE_ID_V2,\n TRANSFER_INSTRUCTION_INTERFACE_ID_V2,\n TransferInstruction,\n} from '@canton-network/core-token-standard-v2'\nimport type { CoreService } from '../core-service.js'\nimport { getLogger } from '@logtape/logtape'\n\nexport class TransferServiceV2 {\n private logger = getLogger([\n 'core',\n 'token-standard-service',\n 'TransferServiceV2',\n ])\n\n constructor(private core: CoreService) {}\n\n public async buildTransferChoiceArgs(opts: {\n sender: Account\n receiver: Account\n amount: string\n instrumentAdmin: PartyId\n instrumentId: string\n inputUtxos?: string[]\n memo?: string\n expiryDate?: Date\n meta?: Metadata\n actors?: PartyId[]\n continueUntilCompletion?: boolean\n }): Promise<TransferFactory_TransferV2> {\n const inputHoldingCids: string[] =\n await this.core.getInputHoldingCidsForAccount({\n account: opts.sender,\n instrumentAdmin: opts.instrumentAdmin,\n instrumentId: opts.instrumentId,\n inputUtxos: opts.inputUtxos ?? [],\n amount: new Decimal(opts.amount),\n continueUntilCompletion: opts.continueUntilCompletion ?? false,\n })\n\n return {\n //TODO: find a better way to flatmap party ids\n actors:\n opts.actors ??\n [opts.sender.owner, opts.sender.provider].flatMap((partyId) =>\n partyId != null ? [partyId] : []\n ),\n transfer: {\n sender: opts.sender,\n receiver: opts.receiver,\n amount: opts.amount,\n instrumentId: {\n admin: opts.instrumentAdmin,\n id: opts.instrumentId,\n },\n requestedAt: new Date(\n Date.now() - REQUESTED_AT_SKEW_MS\n ).toISOString(),\n executeBefore: (\n opts.expiryDate ??\n new Date(Date.now() + 24 * 60 * 60 * 1000)\n ).toISOString(),\n inputHoldingCids:\n inputHoldingCids as unknown as ContractId<HoldingV2>[],\n meta: {\n values: {\n [TokenStandardService.MEMO_KEY]: opts.memo || '',\n ...opts.meta?.values,\n },\n },\n },\n extraArgs: {\n context: { values: {} },\n meta: { values: {} },\n },\n }\n }\n\n async createTransfer(\n args: Parameters<TransferServiceV2['buildTransferChoiceArgs']>[0],\n registryUrl: URL,\n prefetched?: {\n factoryId: string\n choiceContext: OffLedgerV2.TransferInstructionV2.components['schemas']['ChoiceContext']\n }\n ): Promise<[ExerciseCommand, DisclosedContract[]]> {\n const choiceArgs = await this.buildTransferChoiceArgs(args)\n const { factoryId, choiceContext } =\n prefetched ??\n (await this.core\n .getTokenStandardClientV2(registryUrl)\n .post('/registry/transfer-instruction/v2/transfer-factory', {\n choiceArguments: choiceArgs as unknown as Record<\n string,\n never\n >,\n excludeDebugFields: true,\n }))\n\n return this.createTransferFromContext(\n factoryId,\n choiceArgs,\n choiceContext\n )\n }\n\n async createTransferFromContext(\n factoryId: string,\n choiceArgs: TransferFactory_TransferV2,\n choiceContext: OffLedgerV2.TransferInstructionV2.components['schemas']['ChoiceContext']\n ): Promise<[ExerciseCommand, DisclosedContract[]]> {\n this.logger.debug('Creating transfer from pre-fetched context...')\n choiceArgs.extraArgs.context = {\n ...choiceContext.choiceContextData,\n values: choiceContext.choiceContextData?.values ?? {},\n }\n const exercise: ExerciseCommand = {\n templateId: TRANSFER_FACTORY_INTERFACE_ID_V2,\n contractId: factoryId,\n choice: 'TransferFactory_Transfer',\n choiceArgument: choiceArgs,\n }\n return [exercise, choiceContext.disclosedContracts]\n }\n\n async rejectTransferInstruction(\n transferInstructionCid: string,\n actors: PartyId[],\n registryUrl: URL\n ): Promise<[ExerciseCommand, DisclosedContract[]]> {\n const ctx = await this.core.getTokenStandardClientV2(registryUrl).post(\n '/registry/transfer-instruction/v2/{transferInstructionId}/choice-contexts/reject',\n {\n excludeDebugFields: true,\n },\n { path: { transferInstructionId: transferInstructionCid } }\n )\n\n return [\n {\n templateId: TRANSFER_INSTRUCTION_INTERFACE_ID_V2,\n contractId: transferInstructionCid,\n choice: TransferInstruction.TransferInstruction_Reject\n .choiceName,\n choiceArgument: {\n actors,\n extraArgs: {\n context: ctx.choiceContextData,\n meta: EMPTY_META,\n },\n },\n },\n ctx.disclosedContracts ?? [],\n ]\n }\n\n async withdrawTransferInstruction(\n transferInstructionCid: string,\n actors: PartyId[],\n registryUrl: URL\n ): Promise<[ExerciseCommand, DisclosedContract[]]> {\n const ctx = await this.core.getTokenStandardClientV2(registryUrl).post(\n '/registry/transfer-instruction/v2/{transferInstructionId}/choice-contexts/withdraw',\n {\n excludeDebugFields: true,\n },\n { path: { transferInstructionId: transferInstructionCid } }\n )\n\n return [\n {\n templateId: TRANSFER_INSTRUCTION_INTERFACE_ID_V2,\n contractId: transferInstructionCid,\n choice: TransferInstruction.TransferInstruction_Withdraw\n .choiceName,\n choiceArgument: {\n actors,\n extraArgs: {\n context: ctx.choiceContextData,\n meta: EMPTY_META,\n },\n },\n },\n ctx.disclosedContracts ?? [],\n ]\n }\n\n async acceptTransferInstruction(\n transferInstructionCid: string,\n actors: PartyId[],\n registryUrl: URL\n ): Promise<[ExerciseCommand, DisclosedContract[]]> {\n const ctx = await this.core.getTokenStandardClientV2(registryUrl).post(\n '/registry/transfer-instruction/v2/{transferInstructionId}/choice-contexts/accept',\n {\n excludeDebugFields: true,\n },\n { path: { transferInstructionId: transferInstructionCid } }\n )\n\n return [\n {\n templateId: TRANSFER_INSTRUCTION_INTERFACE_ID_V2,\n contractId: transferInstructionCid,\n choice: TransferInstruction.TransferInstruction_Accept\n .choiceName,\n choiceArgument: {\n actors,\n extraArgs: {\n context: ctx.choiceContextData,\n meta: EMPTY_META,\n },\n },\n },\n ctx.disclosedContracts ?? [],\n ]\n }\n}\n","// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport {\n TRANSFER_FACTORY_INTERFACE_ID,\n TRANSFER_INSTRUCTION_INTERFACE_ID,\n type Metadata,\n FEATURED_APP_DELEGATE_PROXY_INTERFACE_ID,\n type Holding,\n type Beneficiaries,\n type OffLedger,\n TransferInstruction,\n} from '@canton-network/core-token-standard'\nimport { getLogger } from '@logtape/logtape'\nimport type { ContractId, PartyId } from '@canton-network/core-types'\nimport { Decimal } from 'decimal.js'\nimport {\n type CreateTransferChoiceArgs,\n type DisclosedContract,\n type ExerciseCommand,\n REQUESTED_AT_SKEW_MS,\n} from '../types.js'\nimport { TokenStandardService } from '../token-standard-service.js'\nimport type { CoreService } from '../core-service.js'\nexport class TransferService {\n private logger = getLogger([\n 'core',\n 'token-standard-service',\n 'TransferService',\n ])\n\n constructor(private core: CoreService) {}\n\n public async buildTransferChoiceArgs(\n sender: PartyId,\n receiver: PartyId,\n amount: string,\n instrumentAdmin: PartyId,\n instrumentId: string,\n inputUtxos?: string[],\n memo?: string,\n expiryDate?: Date,\n meta?: Metadata,\n continueUntilCompletion?: boolean\n ): Promise<CreateTransferChoiceArgs> {\n const inputHoldingCids: string[] = await this.core.getInputHoldingsCids(\n {\n sender,\n instrumentAdmin,\n instrumentId,\n inputUtxos: inputUtxos ?? [],\n amount: new Decimal(amount),\n continueUntilCompletion: continueUntilCompletion ?? false,\n }\n )\n\n return {\n expectedAdmin: instrumentAdmin,\n transfer: {\n sender,\n receiver,\n amount,\n instrumentId: { admin: instrumentAdmin, id: instrumentId },\n requestedAt: new Date(\n Date.now() - REQUESTED_AT_SKEW_MS\n ).toISOString(),\n executeBefore: (\n expiryDate ?? new Date(Date.now() + 24 * 60 * 60 * 1000)\n ).toISOString(),\n inputHoldingCids:\n inputHoldingCids as unknown as ContractId<Holding>[],\n meta: {\n values: {\n [TokenStandardService.MEMO_KEY]: memo || '',\n ...meta?.values,\n },\n },\n },\n extraArgs: {\n context: { values: {} },\n meta: { values: {} },\n },\n }\n }\n\n async fetchTransferFactoryChoiceContext(\n registryUrl: URL,\n choiceArgs: CreateTransferChoiceArgs,\n excludeDebugFields: boolean = true\n ): Promise<\n OffLedger.TransferInstructionV1.components['schemas']['TransferFactoryWithChoiceContext']\n > {\n return await this.core\n .getTokenStandardClient(registryUrl)\n .post('/registry/transfer-instruction/v1/transfer-factory', {\n choiceArguments: choiceArgs as unknown as Record<string, never>,\n excludeDebugFields,\n })\n }\n\n async createTransferFromContext(\n factoryId: string,\n choiceArgs: CreateTransferChoiceArgs,\n choiceContext: OffLedger.TransferInstructionV1.components['schemas']['ChoiceContext']\n ): Promise<[ExerciseCommand, DisclosedContract[]]> {\n this.logger.debug('Creating transfer from pre-fetched context...')\n choiceArgs.extraArgs.context = {\n ...choiceContext.choiceContextData,\n values: choiceContext.choiceContextData?.values ?? {},\n }\n const exercise: ExerciseCommand = {\n templateId: TRANSFER_FACTORY_INTERFACE_ID,\n contractId: factoryId,\n choice: 'TransferFactory_Transfer',\n choiceArgument: choiceArgs,\n }\n return [exercise, choiceContext.disclosedContracts]\n }\n\n // TODO: use named parameters\n async createTransfer(\n sender: PartyId,\n receiver: PartyId,\n amount: string,\n instrumentAdmin: PartyId, // TODO (#907): replace with registry call\n instrumentId: string,\n registryUrl: URL,\n inputUtxos?: string[],\n memo?: string,\n expiryDate?: Date,\n meta?: Metadata,\n prefetchedRegistryChoiceContext?: {\n factoryId: string\n choiceContext: OffLedger.TransferInstructionV1.components['schemas']['ChoiceContext']\n },\n continueUntilCompletion?: boolean\n ): Promise<[ExerciseCommand, DisclosedContract[]]> {\n try {\n const choiceArgs = await this.buildTransferChoiceArgs(\n sender,\n receiver,\n amount,\n instrumentAdmin,\n instrumentId,\n inputUtxos,\n memo,\n expiryDate,\n meta,\n continueUntilCompletion\n )\n\n if (prefetchedRegistryChoiceContext) {\n return this.createTransferFromContext(\n prefetchedRegistryChoiceContext.factoryId,\n choiceArgs,\n prefetchedRegistryChoiceContext.choiceContext\n )\n }\n\n const { factoryId, choiceContext } =\n await this.fetchTransferFactoryChoiceContext(\n registryUrl,\n choiceArgs\n )\n\n return this.createTransferFromContext(\n factoryId,\n choiceArgs,\n choiceContext\n )\n } catch (e) {\n this.logger.warn('Failed to execute transfer:', { error: e })\n throw e\n }\n }\n\n async fetchAcceptTransferInstructionChoiceContext(\n transferInstructionCid: string,\n registryUrl: URL\n ): Promise<{\n choiceContextData: unknown\n disclosedContracts: DisclosedContract[]\n }> {\n const client = this.core.getTokenStandardClient(registryUrl)\n const choiceContext = await client.post(\n '/registry/transfer-instruction/v1/{transferInstructionId}/choice-contexts/accept',\n {\n excludeDebugFields: true,\n },\n {\n path: {\n transferInstructionId: transferInstructionCid,\n },\n }\n )\n return {\n choiceContextData: choiceContext.choiceContextData,\n disclosedContracts: choiceContext.disclosedContracts,\n }\n }\n\n async createAcceptTransferInstructionFromContext(\n transferInstructionCid: string,\n choiceContext: {\n choiceContextData: unknown\n disclosedContracts: DisclosedContract[]\n }\n ): Promise<[ExerciseCommand, DisclosedContract[]]> {\n try {\n const exercise: ExerciseCommand = {\n templateId: TRANSFER_INSTRUCTION_INTERFACE_ID,\n contractId: transferInstructionCid,\n choice: TransferInstruction.TransferInstruction_Accept\n .choiceName,\n choiceArgument: {\n extraArgs: {\n context: choiceContext.choiceContextData,\n meta: { values: {} },\n },\n },\n }\n return [exercise, choiceContext.disclosedContracts]\n } catch (e) {\n this.logger.warn('Failed to create accept transfer instruction:', {\n error: e,\n })\n throw e\n }\n }\n\n async exerciseDelegateProxyTransferInstructionAccept(\n proxyCid: string,\n transferInstructionCid: string,\n registryUrl: URL,\n featuredAppRightCid: string,\n beneficiaries: Beneficiaries[]\n ): Promise<[ExerciseCommand, DisclosedContract[]]> {\n const [acceptTransferInstructionContext, disclosedContracts] =\n await this.createAcceptTransferInstruction(\n transferInstructionCid,\n registryUrl\n )\n\n const choiceArgs = {\n cid: acceptTransferInstructionContext.contractId,\n proxyArg: {\n featuredAppRightCid: featuredAppRightCid,\n beneficiaries: beneficiaries,\n choiceArg: acceptTransferInstructionContext.choiceArgument,\n },\n }\n\n return [\n {\n templateId: FEATURED_APP_DELEGATE_PROXY_INTERFACE_ID,\n contractId: proxyCid,\n choice: 'DelegateProxy_TransferInstruction_Accept',\n choiceArgument: choiceArgs,\n },\n disclosedContracts,\n ]\n }\n\n async exerciseDelegateProxyTransferInstructionReject(\n proxyCid: string,\n transferInstructionCid: string,\n registryUrl: URL,\n featuredAppRightCid: string,\n beneficiaries: Beneficiaries[]\n ): Promise<[ExerciseCommand, DisclosedContract[]]> {\n const [rejectTransferInstructionContext, disclosedContracts] =\n await this.createRejectTransferInstruction(\n transferInstructionCid,\n registryUrl\n )\n\n const choiceArgs = {\n cid: rejectTransferInstructionContext.contractId,\n proxyArg: {\n featuredAppRightCid: featuredAppRightCid,\n beneficiaries,\n choiceArg: rejectTransferInstructionContext.choiceArgument,\n },\n }\n\n return [\n {\n templateId: FEATURED_APP_DELEGATE_PROXY_INTERFACE_ID,\n contractId: proxyCid,\n choice: 'DelegateProxy_TransferInstruction_Reject',\n choiceArgument: choiceArgs,\n },\n disclosedContracts,\n ]\n }\n\n async exerciseDelegateProxyTransferInstructioWithdraw(\n proxyCid: string,\n transferInstructionCid: string,\n registryUrl: URL,\n featuredAppRightCid: string,\n beneficiaries: Beneficiaries[]\n ): Promise<[ExerciseCommand, DisclosedContract[]]> {\n const [withdrawTransferInstructionContext, disclosedContracts] =\n await this.createWithdrawTransferInstruction(\n transferInstructionCid,\n registryUrl\n )\n\n const sumOfWeights: number = beneficiaries.reduce(\n (totalWeight, beneficiary) => totalWeight + beneficiary.weight,\n 0\n )\n\n if (sumOfWeights > 1.0) {\n throw new Error('Sum of beneficiary weights is larger than 1.')\n }\n\n const choiceArgs = {\n cid: withdrawTransferInstructionContext.contractId,\n proxyArg: {\n featuredAppRightCid: featuredAppRightCid,\n beneficiaries,\n choiceArg: withdrawTransferInstructionContext.choiceArgument,\n },\n }\n\n return [\n {\n templateId: FEATURED_APP_DELEGATE_PROXY_INTERFACE_ID,\n contractId: proxyCid,\n choice: 'DelegateProxy_TransferInstruction_Withdraw',\n choiceArgument: choiceArgs,\n },\n disclosedContracts,\n ]\n }\n\n async createAcceptTransferInstruction(\n transferInstructionCid: string,\n registryUrl: URL,\n prefetchedRegistryChoiceContext?: OffLedger.TransferInstructionV1.components['schemas']['ChoiceContext']\n ): Promise<[ExerciseCommand, DisclosedContract[]]> {\n if (prefetchedRegistryChoiceContext) {\n return this.createAcceptTransferInstructionFromContext(\n transferInstructionCid,\n {\n choiceContextData:\n prefetchedRegistryChoiceContext.choiceContextData,\n disclosedContracts:\n prefetchedRegistryChoiceContext.disclosedContracts,\n }\n )\n }\n const choiceContext =\n await this.fetchAcceptTransferInstructionChoiceContext(\n transferInstructionCid,\n registryUrl\n )\n return this.createAcceptTransferInstructionFromContext(\n transferInstructionCid,\n choiceContext\n )\n }\n\n async fetchRejectTransferInstructionChoiceContext(\n transferInstructionCid: string,\n registryUrl: URL\n ): Promise<{\n choiceContextData: unknown\n disclosedContracts: DisclosedContract[]\n }> {\n const client = this.core.getTokenStandardClient(registryUrl)\n const choiceContext = await client.post(\n '/registry/transfer-instruction/v1/{transferInstructionId}/choice-contexts/reject',\n {\n excludeDebugFields: true,\n },\n {\n path: {\n transferInstructionId: transferInstructionCid,\n },\n }\n )\n return {\n choiceContextData: choiceContext.choiceContextData,\n disclosedContracts: choiceContext.disclosedContracts,\n }\n }\n\n async createRejectTransferInstructionFromContext(\n transferInstructionCid: string,\n choiceContext: {\n choiceContextData: unknown\n disclosedContracts: DisclosedContract[]\n }\n ): Promise<[ExerciseCommand, DisclosedContract[]]> {\n try {\n const exercise: ExerciseCommand = {\n templateId: TRANSFER_INSTRUCTION_INTERFACE_ID,\n contractId: transferInstructionCid,\n choice: TransferInstruction.TransferInstruction_Reject\n .choiceName,\n choiceArgument: {\n extraArgs: {\n context: choiceContext.choiceContextData,\n meta: { values: {} },\n },\n },\n }\n return [exercise, choiceContext.disclosedContracts]\n } catch (e) {\n this.logger.warn('Failed to create reject transfer instruction:', {\n error: e,\n })\n throw e\n }\n }\n\n async createRejectTransferInstruction(\n transferInstructionCid: string,\n registryUrl: URL,\n prefetchedRegistryChoiceContext?: OffLedger.TransferInstructionV1.components['schemas']['ChoiceContext']\n ): Promise<[ExerciseCommand, DisclosedContract[]]> {\n if (prefetchedRegistryChoiceContext) {\n return this.createRejectTransferInstructionFromContext(\n transferInstructionCid,\n {\n choiceContextData:\n prefetchedRegistryChoiceContext.choiceContextData,\n disclosedContracts:\n prefetchedRegistryChoiceContext.disclosedContracts,\n }\n )\n }\n const choiceContext =\n await this.fetchRejectTransferInstructionChoiceContext(\n transferInstructionCid,\n registryUrl\n )\n return this.createRejectTransferInstructionFromContext(\n transferInstructionCid,\n choiceContext\n )\n }\n\n async fetchWithdrawTransferInstructionChoiceContext(\n transferInstructionCid: string,\n registryUrl: URL\n ): Promise<{\n choiceContextData: unknown\n disclosedContracts: DisclosedContract[]\n }> {\n const client = this.core.getTokenStandardClient(registryUrl)\n\n const choiceContext = await client.post(\n '/registry/transfer-instruction/v1/{transferInstructionId}/choice-contexts/withdraw',\n {\n excludeDebugFields: true,\n },\n {\n path: {\n transferInstructionId: transferInstructionCid,\n },\n }\n )\n return {\n choiceContextData: choiceContext.choiceContextData,\n disclosedContracts: choiceContext.disclosedContracts,\n }\n }\n\n async createWithdrawTransferInstructionFromContext(\n transferInstructionCid: string,\n choiceContext: {\n choiceContextData: unknown\n disclosedContracts: DisclosedContract[]\n }\n ): Promise<[ExerciseCommand, DisclosedContract[]]> {\n try {\n const exercise: ExerciseCommand = {\n templateId: TRANSFER_INSTRUCTION_INTERFACE_ID,\n contractId: transferInstructionCid,\n choice: TransferInstruction.TransferInstruction_Withdraw\n .choiceName,\n choiceArgument: {\n extraArgs: {\n context: choiceContext.choiceContextData,\n meta: { values: {} },\n },\n },\n }\n return [exercise, choiceContext.disclosedContracts]\n } catch (e) {\n this.logger.warn(\n 'Failed to create withdraw transfer instruction:',\n {\n error: e,\n }\n )\n throw e\n }\n }\n\n async createWithdrawTransferInstruction(\n transferInstructionCid: string,\n registryUrl: URL,\n prefetchedRegistryChoiceContext?: OffLedger.TransferInstructionV1.components['schemas']['ChoiceContext']\n ): Promise<[ExerciseCommand, DisclosedContract[]]> {\n if (prefetchedRegistryChoiceContext) {\n return this.createWithdrawTransferInstructionFromContext(\n transferInstructionCid,\n {\n choiceContextData:\n prefetchedRegistryChoiceContext.choiceContextData,\n disclosedContracts:\n prefetchedRegistryChoiceContext.disclosedContracts,\n }\n )\n }\n const choiceContext =\n await this.fetchWithdrawTransferInstructionChoiceContext(\n transferInstructionCid,\n registryUrl\n )\n return this.createWithdrawTransferInstructionFromContext(\n transferInstructionCid,\n choiceContext\n )\n }\n\n async createTransferInstruction(\n transferInstructionCid: string,\n registryUrl: URL,\n instructionChoice: 'Accept' | 'Reject' | 'Withdraw',\n prefetchedRegistryChoiceContext?: OffLedger.TransferInstructionV1.components['schemas']['ChoiceContext']\n ): Promise<[ExerciseCommand, DisclosedContract[]]> {\n switch (instructionChoice) {\n case 'Accept':\n return this.createAcceptTransferInstruction(\n transferInstructionCid,\n registryUrl,\n prefetchedRegistryChoiceContext\n )\n case 'Reject':\n return this.createRejectTransferInstruction(\n transferInstructionCid,\n registryUrl,\n prefetchedRegistryChoiceContext\n )\n case 'Withdraw':\n return this.createWithdrawTransferInstruction(\n transferInstructionCid,\n registryUrl,\n prefetchedRegistryChoiceContext\n )\n }\n }\n}\n","// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport {\n ALLOCATION_FACTORY_INTERFACE_ID,\n ALLOCATION_INTERFACE_ID,\n ALLOCATION_REQUEST_INTERFACE_ID,\n ALLOCATION_INSTRUCTION_INTERFACE_ID,\n type AllocationFactory_Allocate,\n type AllocationSpecification,\n type Holding,\n type OffLedger,\n} from '@canton-network/core-token-standard'\nimport type { ContractId, PartyId } from '@canton-network/core-types'\nimport {\n type DisclosedContract,\n EMPTY_META,\n type ExerciseCommand,\n REQUESTED_AT_SKEW_MS,\n} from '../types.js'\nimport type { CoreService } from '../core-service.js'\n\nexport class AllocationService {\n constructor(private core: CoreService) {}\n\n public async buildAllocationFactoryChoiceArgs(\n allocationSpecification: AllocationSpecification,\n expectedAdmin: PartyId,\n inputUtxos?: string[],\n requestedAt?: string\n ): Promise<AllocationFactory_Allocate> {\n const allocationSpecificationNormalized: AllocationSpecification = {\n ...allocationSpecification,\n settlement: {\n ...allocationSpecification.settlement,\n meta: allocationSpecification.settlement.meta ?? { values: {} },\n },\n transferLeg: {\n ...allocationSpecification.transferLeg,\n meta: allocationSpecification.transferLeg.meta ?? {\n values: {},\n },\n },\n }\n\n const inputHoldingCids = await this.core.getInputHoldingsCids({\n sender: allocationSpecificationNormalized.transferLeg.sender,\n inputUtxos: inputUtxos ?? [],\n instrumentAdmin:\n allocationSpecificationNormalized.transferLeg.instrumentId\n .admin,\n instrumentId:\n allocationSpecificationNormalized.transferLeg.instrumentId.id,\n })\n\n return {\n expectedAdmin,\n allocation: allocationSpecificationNormalized,\n requestedAt:\n requestedAt ??\n new Date(Date.now() - REQUESTED_AT_SKEW_MS).toISOString(),\n inputHoldingCids:\n inputHoldingCids as unknown as ContractId<Holding>[],\n extraArgs: {\n context: { values: {} },\n meta: { values: {} },\n },\n }\n }\n\n async fetchAllocationFactoryChoiceContext(\n registryUrl: URL,\n choiceArgs: AllocationFactory_Allocate,\n excludeDebugFields: boolean = true\n ): Promise<\n OffLedger.AllocationInstructionV1.components['schemas']['FactoryWithChoiceContext']\n > {\n return this.core\n .getTokenStandardClient(registryUrl)\n .post('/registry/allocation-instruction/v1/allocation-factory', {\n choiceArguments: choiceArgs as unknown as Record<string, never>,\n excludeDebugFields,\n })\n }\n\n async createAllocationInstructionFromContext(\n factoryId: string,\n choiceArgs: AllocationFactory_Allocate,\n choiceContext: OffLedger.AllocationInstructionV1.components['schemas']['ChoiceContext']\n ): Promise<[ExerciseCommand, DisclosedContract[]]> {\n choiceArgs.extraArgs.context = {\n ...choiceContext.choiceContextData,\n values: choiceContext.choiceContextData?.values ?? {},\n }\n const exercise: ExerciseCommand = {\n templateId: ALLOCATION_FACTORY_INTERFACE_ID,\n contractId: factoryId,\n choice: 'AllocationFactory_Allocate',\n choiceArgument: choiceArgs,\n }\n return [exercise, choiceContext.disclosedContracts]\n }\n\n async createAllocationInstruction(\n allocationSpecification: AllocationSpecification,\n expectedAdmin: PartyId,\n registryUrl: URL,\n inputUtxos?: string[],\n requestedAt?: string,\n prefetchedRegistryChoiceContext?: {\n factoryId: string\n choiceContext: OffLedger.AllocationInstructionV1.components['schemas']['ChoiceContext']\n }\n ): Promise<[ExerciseCommand, DisclosedContract[]]> {\n const choiceArgs = await this.buildAllocationFactoryChoiceArgs(\n allocationSpecification,\n expectedAdmin,\n inputUtxos,\n requestedAt\n )\n\n if (prefetchedRegistryChoiceContext) {\n return this.createAllocationInstructionFromContext(\n prefetchedRegistryChoiceContext.factoryId,\n choiceArgs,\n prefetchedRegistryChoiceContext.choiceContext\n )\n }\n\n const { factoryId, choiceContext } =\n await this.fetchAllocationFactoryChoiceContext(\n registryUrl,\n choiceArgs\n )\n return this.createAllocationInstructionFromContext(\n factoryId,\n choiceArgs,\n choiceContext\n )\n }\n\n private buildAllocationExerciseWithContext(\n templateId: string,\n contractId: string,\n choice:\n | 'Allocation_ExecuteTransfer'\n | 'Allocation_Withdraw'\n | 'Allocation_Cancel',\n choiceContext: OffLedger.AllocationInstructionV1.components['schemas']['ChoiceContext']\n ): [ExerciseCommand, DisclosedContract[]] {\n const exercise: ExerciseCommand = {\n templateId,\n contractId,\n choice,\n choiceArgument: {\n extraArgs: {\n context: choiceContext.choiceContextData,\n meta: EMPTY_META,\n },\n },\n }\n return [exercise, choiceContext.disclosedContracts ?? []]\n }\n\n async fetchExecuteTransferChoiceContext(\n allocationId: string,\n registryUrl: URL\n ) {\n return this.core.getTokenStandardClient(registryUrl).post(\n '/registry/allocations/v1/{allocationId}/choice-contexts/execute-transfer',\n {\n excludeDebugFields: true,\n },\n {\n path: {\n allocationId,\n },\n }\n )\n }\n\n createExecuteTransferAllocationFromContext(\n allocationCid: string,\n choiceContext: OffLedger.AllocationInstructionV1.components['schemas']['ChoiceContext']\n ): [ExerciseCommand, DisclosedContract[]] {\n return this.buildAllocationExerciseWithContext(\n ALLOCATION_INTERFACE_ID,\n allocationCid,\n 'Allocation_ExecuteTransfer',\n choiceContext\n )\n }\n\n async createExecuteTransferAllocation(\n allocationCid: string,\n registryUrl: URL,\n prefetchedRegistryChoiceContext?: OffLedger.AllocationInstructionV1.components['schemas']['ChoiceContext']\n ): Promise<[ExerciseCommand, DisclosedContract[]]> {\n if (prefetchedRegistryChoiceContext) {\n return this.createExecuteTransferAllocationFromContext(\n allocationCid,\n prefetchedRegistryChoiceContext\n )\n }\n const choiceContext = await this.fetchExecuteTransferChoiceContext(\n allocationCid,\n registryUrl\n )\n return this.createExecuteTransferAllocationFromContext(\n allocationCid,\n choiceContext\n )\n }\n\n async fetchWithdrawAllocationChoiceContext(\n allocationCid: string,\n registryUrl: URL\n ): Promise<\n OffLedger.AllocationInstructionV1.components['schemas']['ChoiceContext']\n > {\n return this.core.getTokenStandardClient(registryUrl).post(\n '/registry/allocations/v1/{allocationId}/choice-contexts/withdraw',\n {\n excludeDebugFields: true,\n },\n { path: { allocationId: allocationCid } }\n )\n }\n\n createWithdrawAllocationFromContext(\n allocationCid: string,\n choiceContext: OffLedger.AllocationInstructionV1.components['schemas']['ChoiceContext']\n ): [ExerciseCommand, DisclosedContract[]] {\n return this.buildAllocationExerciseWithContext(\n ALLOCATION_INTERFACE_ID,\n allocationCid,\n 'Allocation_Withdraw',\n choiceContext\n )\n }\n\n async createWithdrawAllocation(\n allocationCid: string,\n registryUrl: URL,\n prefetchedRegistryChoiceContext?: OffLedger.AllocationInstructionV1.components['schemas']['ChoiceContext']\n ): Promise<[ExerciseCommand, DisclosedContract[]]> {\n if (prefetchedRegistryChoiceContext) {\n return this.createWithdrawAllocationFromContext(\n allocationCid,\n prefetchedRegistryChoiceContext\n )\n }\n const choiceContext = await this.fetchWithdrawAllocationChoiceContext(\n allocationCid,\n registryUrl\n )\n return this.createWithdrawAllocationFromContext(\n allocationCid,\n choiceContext\n )\n }\n\n async fetchCancelAllocationChoiceContext(\n allocationCid: string,\n registryUrl: URL\n ): Promise<\n OffLedger.AllocationInstructionV1.components['schemas']['ChoiceContext']\n > {\n return this.core.getTokenStandardClient(registryUrl).post(\n '/registry/allocations/v1/{allocationId}/choice-contexts/cancel',\n {\n excludeDebugFields: true,\n },\n { path: { allocationId: allocationCid } }\n )\n }\n\n createCancelAllocationFromContext(\n allocationCid: string,\n choiceContext: OffLedger.AllocationInstructionV1.components['schemas']['ChoiceContext']\n ): [ExerciseCommand, DisclosedContract[]] {\n return this.buildAllocationExerciseWithContext(\n ALLOCATION_INTERFACE_ID,\n allocationCid,\n 'Allocation_Cancel',\n choiceContext\n )\n }\n\n async createCancelAllocation(\n allocationCid: string,\n registryUrl: URL,\n prefetchedRegistryChoiceContext?: OffLedger.AllocationInstructionV1.components['schemas']['ChoiceContext']\n ): Promise<[ExerciseCommand, DisclosedContract[]]> {\n if (prefetchedRegistryChoiceContext) {\n return this.createCancelAllocationFromContext(\n allocationCid,\n prefetchedRegistryChoiceContext\n )\n }\n const choiceContext = await this.fetchCancelAllocationChoiceContext(\n allocationCid,\n registryUrl\n )\n return this.createCancelAllocationFromContext(\n allocationCid,\n choiceContext\n )\n }\n\n async createWithdrawAllocationInstruction(\n allocationInstructionCid: string\n ): Promise<[ExerciseCommand, DisclosedContract[]]> {\n const exercise: ExerciseCommand = {\n templateId: ALLOCATION_INSTRUCTION_INTERFACE_ID,\n contractId: allocationInstructionCid,\n choice: 'AllocationInstruction_Withdraw',\n choiceArgument: {\n extraArgs: {\n context: { values: {} },\n meta: { values: {} },\n },\n },\n }\n return [exercise, []]\n }\n\n async createUpdateAllocationInstruction(\n allocationInstructionCid: string,\n extraActors: PartyId[] = [],\n extraArgsContext: Record<string, unknown> = {},\n extraArgsMeta: Record<string, unknown> = {}\n ): Promise<[ExerciseCommand, DisclosedContract[]]> {\n const exercise: ExerciseCommand = {\n templateId: ALLOCATION_INSTRUCTION_INTERFACE_ID,\n contractId: allocationInstructionCid,\n choice: 'AllocationInstruction_Update',\n choiceArgument: {\n extraActors,\n extraArgs: {\n context: { values: extraArgsContext },\n meta: { values: extraArgsMeta },\n },\n },\n }\n return [exercise, []]\n }\n\n async createRejectAllocationRequest(\n allocationRequestCid: string,\n actor: PartyId\n ): Promise<[ExerciseCommand, DisclosedContract[]]> {\n const exercise: ExerciseCommand = {\n templateId: ALLOCATION_REQUEST_INTERFACE_ID,\n contractId: allocationRequestCid,\n choice: 'AllocationRequest_Reject',\n choiceArgument: {\n actor,\n extraArgs: {\n context: { values: {} },\n meta: { values: {} },\n },\n },\n }\n return [exercise, []]\n }\n\n async createWithdrawAllocationRequest(\n allocationRequestCid: string\n ): Promise<[ExerciseCommand, DisclosedContract[]]> {\n const exercise: ExerciseCommand = {\n templateId: ALLOCATION_REQUEST_INTERFACE_ID,\n contractId: allocationRequestCid,\n choice: 'AllocationRequest_Withdraw',\n choiceArgument: {\n extraArgs: {\n context: { values: {} },\n meta: { values: {} },\n },\n },\n }\n return [exercise, []]\n }\n}\n","// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport {\n TokenStandardClient,\n HOLDING_INTERFACE_ID,\n type HoldingView,\n} from '@canton-network/core-token-standard'\nimport {\n type Account,\n TokenStandardClient as TokenStandardClientV2,\n type HoldingView as HoldingViewV2,\n} from '@canton-network/core-token-standard-v2'\nimport type { PartyId } from '@canton-network/core-types'\nimport { ACSReader, type AcsOptions } from '@canton-network/core-acs-reader'\nimport {\n ensureInterfaceViewIsPresent,\n TransactionParser,\n type PrettyContract,\n renderTransaction,\n type ViewValue,\n type PrettyTransactions,\n type Transaction,\n type TransferObject,\n type JsActiveContract,\n} from '@canton-network/core-tx-parser'\nimport type { AccessTokenProvider } from '@canton-network/core-wallet-auth'\nimport type {\n AbstractLedgerProvider,\n Ops,\n} from '@canton-network/core-provider-ledger'\nimport { Decimal } from 'decimal.js'\nimport type {\n ApiVersion,\n GenericTokenStandardClient,\n JsActiveContractEntryResponse,\n JsGetActiveContractsResponse,\n JsGetUpdateResponse,\n JsGetUpdatesResponse,\n JsTransaction,\n OffsetCheckpointUpdate,\n TransactionUpdate,\n} from './types.js'\nimport { isApiVersion, TokenStandardService } from './token-standard-service.js'\nimport { getLogger } from '@logtape/logtape'\n\nexport class CoreService {\n private logger = getLogger([\n 'core',\n 'token-standard-service',\n 'CoreService',\n ])\n\n constructor(\n private ledgerProvider: AbstractLedgerProvider,\n private accessTokenProvider: AccessTokenProvider,\n private readonly isMasterUser: boolean\n ) {}\n\n getTokenStandardClientWithVersion(\n registryUrl: URL,\n version: ApiVersion\n ): GenericTokenStandardClient {\n if (!isApiVersion(version)) {\n throw new Error(`Unsupported token standard api version.`)\n }\n\n return version === 'v2'\n ? new TokenStandardClientV2(\n registryUrl.href,\n this.logger,\n this.accessTokenProvider\n )\n : new TokenStandardClient(\n registryUrl.href,\n this.logger,\n this.accessTokenProvider\n )\n }\n\n getTokenStandardClient(registryUrl: URL): TokenStandardClient {\n return new TokenStandardClient(\n registryUrl.href,\n this.logger,\n this.accessTokenProvider\n )\n }\n\n getTokenStandardClientV2(registryUrl: URL): TokenStandardClientV2 {\n return new TokenStandardClientV2(\n registryUrl.href,\n this.logger,\n this.accessTokenProvider\n )\n }\n\n toBasicAccount(partyId: PartyId): Account {\n return {\n owner: partyId,\n provider: null,\n id: '',\n }\n }\n\n private isSameAccount(a: Account, b: Account) {\n return a.id === b.id && a.owner === b.owner && a.provider === b.provider\n }\n async getInputHoldingCidsForAccount(opts: {\n account: Account\n partyId?: PartyId\n instrumentAdmin: string\n instrumentId: string\n inputUtxos?: string[]\n amount?: Decimal\n limit?: number\n offset?: number\n continueUntilCompletion?: boolean\n }) {\n if (opts.inputUtxos?.length) return opts.inputUtxos\n\n const party = opts.partyId ?? opts.account.owner\n if (!party) throw new Error('No party to query as')\n\n const now = new Date()\n const holdings = (\n await this.listContractsByInterface<HoldingViewV2>(\n '#splice-api-token-holding-v2:Splice.Api.Token.HoldingV2:Holding',\n party,\n opts.limit,\n opts.offset,\n opts.continueUntilCompletion ?? false\n )\n ).filter(\n (h) =>\n h.interfaceViewValue.instrumentId.admin ===\n opts.instrumentAdmin &&\n h.interfaceViewValue.instrumentId.id == opts.instrumentId &&\n this.isSameAccount(\n opts.account,\n h.interfaceViewValue.account\n ) &&\n !TokenStandardService.isHoldingLocked(h, now)\n )\n\n return opts.amount\n ? CoreService.getInputHoldingsCidsForAmount(opts.amount, holdings)\n : holdings.map((h) => h.contractId)\n }\n\n async getInputHoldingsCids(options: {\n sender: PartyId\n instrumentAdmin?: string\n instrumentId?: string\n inputUtxos?: string[]\n amount?: Decimal\n continueUntilCompletion?: boolean\n }) {\n const { sender, instrumentAdmin, instrumentId } = options\n const now = new Date()\n if (options.inputUtxos && options.inputUtxos.length > 0) {\n return options.inputUtxos\n }\n const senderHoldings = await this.listContractsByInterface<HoldingView>(\n HOLDING_INTERFACE_ID,\n sender,\n undefined,\n undefined,\n options.continueUntilCompletion\n )\n if (senderHoldings.length === 0) {\n throw new Error(\n \"Sender has no holdings, so transfer can't be executed.\"\n )\n }\n\n const unlockedSenderHoldings = senderHoldings.filter(\n (utxo) => !TokenStandardService.isHoldingLocked(utxo, now)\n )\n\n if (unlockedSenderHoldings.length > 100) {\n this.logger.warn(`Sender has more than 100 unlocked utxos.`)\n }\n\n const unlockedHoldingsForInstrument =\n instrumentAdmin && instrumentId\n ? await CoreService.filterHoldingsByInstrument({\n holdings: unlockedSenderHoldings,\n instrumentAdmin,\n instrumentId,\n })\n : unlockedSenderHoldings\n\n if (options.amount) {\n return CoreService.getInputHoldingsCidsForAmount(\n options.amount,\n unlockedHoldingsForInstrument\n )\n } else {\n return unlockedHoldingsForInstrument.map((h) => h.contractId)\n }\n }\n\n static async filterHoldingsByInstrument(options: {\n holdings: PrettyContract<HoldingView>[]\n instrumentAdmin: string\n instrumentId: string\n }) {\n const { holdings, instrumentAdmin, instrumentId } = options\n return holdings.filter((utxo) => {\n return (\n utxo.interfaceViewValue.instrumentId.id === instrumentId &&\n utxo.interfaceViewValue.instrumentId.admin === instrumentAdmin\n )\n })\n }\n\n static async getInputHoldingsCidsForAmount(\n amount: Decimal,\n unlockedSenderHoldings:\n PrettyContract<HoldingView>[] | PrettyContract<HoldingViewV2>[]\n ) {\n //find holding that is the exact amount if possible\n const exactAmount = unlockedSenderHoldings.find((holding) =>\n new Decimal(holding.interfaceViewValue.amount).equals(amount)\n )\n\n if (exactAmount) {\n return [exactAmount.contractId]\n }\n\n //sort holdings from smallest to largest\n const sortedUnlockedSenderHoldings = unlockedSenderHoldings.toSorted(\n (a, b) =>\n new Decimal(a.interfaceViewValue.amount).comparedTo(\n new Decimal(b.interfaceViewValue.amount)\n )\n )\n\n const largestHoldingAmount = sortedUnlockedSenderHoldings.pop()\n\n if (!largestHoldingAmount) {\n throw new Error(`Sender doesn't have any unlocked holdings`)\n }\n\n let currentSum = new Decimal(\n largestHoldingAmount.interfaceViewValue.amount\n )\n const cIds = [largestHoldingAmount.contractId]\n\n for (const h of sortedUnlockedSenderHoldings) {\n if (currentSum.greaterThanOrEqualTo(amount)) {\n break\n }\n\n const currentHoldingAmount = new Decimal(\n h.interfaceViewValue.amount\n )\n\n currentSum = currentSum.plus(currentHoldingAmount)\n cIds.push(h.contractId)\n }\n\n if (currentSum.lessThan(amount)) {\n throw new Error(\n `Sender doesn't have sufficient funds for this transfer. Missing amount: ${amount.minus(currentSum)}`\n )\n }\n\n if (cIds.length > 100) {\n throw new Error(\n `Exceeded the maximum of 100 utxos in 1 transaction`\n )\n }\n\n return cIds\n }\n\n async listContractsByInterface<T = ViewValue>(\n interfaceId: string,\n partyId?: PartyId,\n limit?: number,\n offset?: number,\n continueUntilCompletion?: boolean\n ): Promise<PrettyContract<T>[]> {\n try {\n const ledgerEnd =\n offset ??\n (\n await this.ledgerProvider.request<Ops.GetV2StateLedgerEnd>({\n method: 'ledgerApi',\n params: {\n resource: '/v2/state/ledger-end',\n requestMethod: 'get',\n query: {},\n },\n })\n ).offset!\n\n const options: AcsOptions = {\n offset: ledgerEnd,\n interfaceIds: [interfaceId],\n parties: [partyId!],\n filterByParty: true,\n continueUntilCompletion: Boolean(continueUntilCompletion),\n }\n\n if (limit !== undefined) {\n options.limit = limit\n }\n\n //TODO: based on the. provider design we can't pass in the continue to completion, so right now it's defaulted to true in the ledger provider. we need to figure out how to add an ACS functionality and ensure better composability\n this.logger.debug(\n 'Continue to completion: {continueUntilCompletion}',\n {\n continueUntilCompletion: Boolean(continueUntilCompletion),\n }\n )\n\n const reader = new ACSReader(this.ledgerProvider)\n\n const acsResponses: JsGetActiveContractsResponse[] =\n (await reader.raw.read(\n options\n ))! as JsGetActiveContractsResponse[]\n\n /* This filters out responses with entries of:\n - JsEmpty\n - JsIncompleteAssigned\n - JsIncompleteUnassigned\n while leaving JsActiveContract.\n It works fine only with single synchronizer\n TODO (#353) add support for multiple synchronizers\n */\n const isActiveContractEntry = (\n acsResponse: JsGetActiveContractsResponse\n ): acsResponse is JsActiveContractEntryResponse =>\n acsResponse.contractEntry != null &&\n 'JsActiveContract' in acsResponse.contractEntry &&\n acsResponse.contractEntry.JsActiveContract != null &&\n acsResponse.contractEntry.JsActiveContract.createdEvent != null\n\n const results: PrettyContract<T>[] = acsResponses\n .filter(isActiveContractEntry)\n .map((response) =>\n this.toPrettyContract<T>(\n interfaceId,\n response as JsActiveContractEntryResponse,\n ledgerEnd\n )\n )\n return results\n } catch (err) {\n this.logger.error(\n `Failed to list contracts of interface {interfaceId}`,\n { interfaceId, err }\n )\n throw err\n }\n }\n\n async toPrettyTransactions(\n updates: JsGetUpdatesResponse[],\n partyId: PartyId\n ): Promise<PrettyTransactions> {\n // Runtime filters that also let TS know which of OneOfs types to check against\n const isOffsetCheckpointUpdate = (\n updateResponse: JsGetUpdatesResponse\n ): updateResponse is OffsetCheckpointUpdate =>\n updateResponse.update != null &&\n 'OffsetCheckpoint' in updateResponse.update\n\n const isTransactionUpdate = (\n updateResponse: JsGetUpdatesResponse\n ): updateResponse is TransactionUpdate =>\n updateResponse.update != null &&\n 'Transaction' in updateResponse.update &&\n !!updateResponse.update.Transaction?.value\n\n const offsetCheckpoints: number[] = updates\n .filter(isOffsetCheckpointUpdate)\n .map(\n (update) =>\n (update.update as OffsetCheckpointUpdate['update'])\n .OffsetCheckpoint.value.offset\n )\n const latestCheckpointOffset =\n offsetCheckpoints.length > 0 ? Math.max(...offsetCheckpoints) : 0\n\n const transactions: Transaction[] = await Promise.all(\n updates\n // exclude OffsetCheckpoint, Reassignment, TopologyTransaction\n .filter(isTransactionUpdate)\n .map(async (update) => {\n const txUpdate = update as TransactionUpdate\n const tx = txUpdate.update.Transaction\n .value as JsTransaction\n const parser = new TransactionParser(\n this.ledgerProvider,\n tx,\n partyId,\n this.isMasterUser\n )\n\n return await parser.parseTransaction()\n })\n )\n\n const transactionOffsets = transactions\n .map((tx) => tx.offset)\n .filter((offset): offset is number => offset !== undefined)\n\n return {\n // OffsetCheckpoint can be anywhere... or not at all, maybe\n nextOffset: Math.max(\n latestCheckpointOffset,\n ...(transactionOffsets.length > 0 ? transactionOffsets : [0])\n ),\n transactions: transactions\n .filter((tx) => tx.events.length > 0)\n .map(renderTransaction),\n }\n }\n\n async toPrettyTransaction(\n getUpdateResponse: JsGetUpdateResponse,\n partyId: PartyId\n ): Promise<Transaction> {\n const tx = this.getTransactionFromUpdate(getUpdateResponse)\n const parser = new TransactionParser(\n this.ledgerProvider,\n tx,\n partyId,\n this.isMasterUser\n )\n const parsedTx = await parser.parseTransaction()\n return renderTransaction(parsedTx)\n }\n\n async toPrettyTransferObjects(\n getUpdateResponse: JsGetUpdateResponse,\n partyId: PartyId\n ): Promise<TransferObject[]> {\n const tx = this.getTransactionFromUpdate(getUpdateResponse)\n const parser = new TransactionParser(\n this.ledgerProvider,\n tx,\n partyId,\n this.isMasterUser\n )\n return await parser.parseTransferObjects()\n }\n\n private getTransactionFromUpdate(\n getUpdateResponse: JsGetUpdateResponse\n ): JsTransaction {\n const update = getUpdateResponse.update\n if (!update || !('Transaction' in update)) {\n throw new Error('Expected transaction update')\n }\n return update.Transaction.value\n }\n\n async toPrettyTransactionsPerParty(\n updates: JsGetUpdatesResponse[],\n parties: PartyId[]\n ): Promise<Map<PartyId, PrettyTransactions>> {\n const all = await Promise.all(\n parties.map(\n async (partyId): Promise<[PartyId, PrettyTransactions]> => [\n partyId,\n await this.toPrettyTransactions(updates, partyId),\n ]\n )\n )\n return new Map(all)\n }\n\n // returns object with JsActiveContract content\n // and contractId and interface view value extracted from it as separate fields for convenience\n toPrettyContract<T>(\n interfaceId: string,\n response: JsActiveContractEntryResponse,\n offset?: number\n ): PrettyContract<T> {\n const activeContract = response.contractEntry\n .JsActiveContract as JsActiveContract\n const { createdEvent } = activeContract\n return {\n contractId: createdEvent.contractId,\n activeContract,\n interfaceViewValue: ensureInterfaceViewIsPresent(\n createdEvent,\n interfaceId\n ).viewValue as T,\n fetchedAtOffset: offset,\n }\n }\n\n toQualifiedMemberId(memberId: string) {\n if (!memberId) throw new Error('memberId is required')\n\n return /^(PAR|MED)::/.test(memberId) ? memberId : `PAR::${memberId}`\n }\n}\n","// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { CoreService } from '../core-service'\nimport {\n type AllocationFactory_Allocate,\n type AllocationSpecification,\n type Holding,\n type SettlementInfo,\n ALLOCATION_FACTORY_INTERFACE_ID_V2,\n type SettlementFactory_SettleBatch as SettlementFactory_SettleBatchV2,\n ALLOCATION_INTERFACE_ID_V2,\n ALLOCATION_REQUEST_INTERFACE_ID_V2,\n ALLOCATION_INSTRUCTION_INTERFACE_ID_V2,\n type AllocationRequestView as AllocationRequestViewV2,\n type OffLedger,\n} from '@canton-network/core-token-standard-v2'\nimport {\n REQUESTED_AT_SKEW_MS,\n type DisclosedContract,\n type ExerciseCommand,\n} from '../types'\nimport Decimal from 'decimal.js'\nimport type { PartyId } from '@canton-network/core-types'\nimport type { ContractId } from '@daml/types'\nimport { getLogger } from '@logtape/logtape'\n\ntype AllocationChoiceContextV2 =\n OffLedger.AllocationInstructionV2.components['schemas']['ChoiceContext']\n\ntype CreateAllocateChoiceArgs = {\n settlement: SettlementInfo\n spec: AllocationSpecification\n admin: PartyId\n actors?: PartyId[] | undefined\n inputUtxos?: string[]\n excludeCids?: ReadonlySet<string>\n requestedAt?: string\n}\n\nconst EMPTY_EXTRA_ARGS = () => ({\n context: { values: {} },\n meta: { values: {} },\n})\n\nexport class AllocationService {\n private logger = getLogger([\n 'core',\n 'token-standard-service',\n 'v2',\n 'allocation-service',\n ])\n\n constructor(private core: CoreService) {}\n\n // sent - received + nextIterationFunding (amount per instrument Id that authorizer must fund)\n static fundingNeeds(spec: AllocationSpecification): Map<string, Decimal> {\n const needs = new Map<string, Decimal>()\n const add = (id: string, d: Decimal) =>\n needs.set(id, (needs.get(id) ?? new Decimal(0)).plus(d))\n\n for (const leg of spec.transferLegSides) {\n const amount = new Decimal(leg.amount)\n add(\n leg.instrumentId,\n leg.side === 'SenderSide' ? amount : amount.negated()\n )\n }\n\n for (const [id, amount] of Object.entries(\n spec.nextIterationFunding ?? {}\n )) {\n add(id, new Decimal(amount))\n }\n\n for (const [id, amount] of needs) if (amount.lte(0)) needs.delete(id)\n\n return needs\n }\n\n async buildAllocateChoiceArgs(\n opts: CreateAllocateChoiceArgs\n ): Promise<AllocationFactory_Allocate> {\n const { spec, admin } = opts\n let inputHoldingCids = opts.inputUtxos ?? []\n if (!opts.inputUtxos?.length) {\n const used = new Set(opts.excludeCids)\n inputHoldingCids = []\n for (const [instrumentId, amount] of AllocationService.fundingNeeds(\n spec\n )) {\n const cids = await this.core.getInputHoldingCidsForAccount({\n account: spec.authorizer,\n instrumentAdmin: admin,\n instrumentId,\n amount,\n })\n\n cids.forEach((c) => used.add(c))\n inputHoldingCids.push(...cids)\n }\n }\n\n if (!spec.authorizer.owner && !opts.actors) {\n throw new Error(\n 'Ownerless authorizer account: actors must be provided explicitly'\n )\n }\n\n return {\n settlement: opts.settlement,\n allocation: opts.spec,\n requestedAt:\n opts.requestedAt ??\n new Date(Date.now() - REQUESTED_AT_SKEW_MS).toISOString(),\n inputHoldingCids:\n inputHoldingCids as unknown as ContractId<Holding>[],\n actors: opts.actors ?? [opts.spec.authorizer.owner!],\n extraArgs: EMPTY_EXTRA_ARGS(),\n }\n }\n\n async createAllocation(\n args: CreateAllocateChoiceArgs,\n registryUrl: URL,\n prefetched?: {\n factoryId: string\n choiceContext: AllocationChoiceContextV2\n }\n ): Promise<[ExerciseCommand, DisclosedContract[]]> {\n const choiceArgs = await this.buildAllocateChoiceArgs(args)\n\n const { factoryId, choiceContext } =\n prefetched ??\n (await this.core\n .getTokenStandardClientV2(registryUrl)\n .post(\n '/registry/allocation-instruction/v2/allocation-factory',\n {\n choiceArguments: choiceArgs as unknown as Record<\n string,\n never\n >,\n excludeDebugFields: true,\n }\n ))\n\n return this.createAllocationFromContext(\n factoryId,\n choiceArgs,\n choiceContext\n )\n }\n\n async fetchAllocationChoiceContext(\n action: 'withdraw' | 'cancel',\n allocationCid: string,\n registryUrl: URL\n ): Promise<AllocationChoiceContextV2> {\n return this.core.getTokenStandardClientV2(registryUrl).post(\n `/registry/allocations/v2/{allocationId}/choice-contexts/${action}`,\n {\n excludeDebugFields: true,\n },\n { path: { allocationId: allocationCid } }\n )\n }\n\n async createAllocationChoiceFromContext(\n action: 'withdraw' | 'cancel',\n allocationCid: string,\n actors: PartyId[],\n ctx: AllocationChoiceContextV2\n ): Promise<[ExerciseCommand, DisclosedContract[]]> {\n return [\n {\n templateId: ALLOCATION_INTERFACE_ID_V2,\n contractId: allocationCid,\n choice:\n action === 'withdraw'\n ? 'Allocation_Withdraw'\n : 'Allocation_Cancel',\n choiceArgument: {\n actors,\n extraArgs: {\n context: ctx.choiceContextData,\n meta: { values: {} },\n },\n },\n },\n ctx.disclosedContracts ?? [],\n ]\n }\n\n async createAllocationChoice(\n action: 'withdraw' | 'cancel',\n allocationCid: string,\n actors: PartyId[],\n registryUrl: URL,\n prefetched?: AllocationChoiceContextV2\n ): Promise<[ExerciseCommand, DisclosedContract[]]> {\n const ctx =\n prefetched ??\n (await this.fetchAllocationChoiceContext(\n action,\n allocationCid,\n registryUrl\n ))\n\n return this.createAllocationChoiceFromContext(\n action,\n allocationCid,\n actors,\n ctx\n )\n }\n\n createAllocationRequestChoice(\n action: 'withdraw' | 'reject',\n allocationRequestCid: string,\n actors: PartyId[]\n ): [ExerciseCommand, DisclosedContract[]] {\n const exercise: ExerciseCommand = {\n templateId: ALLOCATION_REQUEST_INTERFACE_ID_V2,\n contractId: allocationRequestCid,\n choice:\n action === 'reject'\n ? 'AllocationRequest_Reject'\n : 'AllocationRequest_Withdraw',\n choiceArgument: { actors, extraArgs: EMPTY_EXTRA_ARGS() },\n }\n return [exercise, []]\n }\n\n createWithdrawAllocationInstruction(\n withdrawCid: string,\n actors: PartyId[]\n ): [ExerciseCommand, DisclosedContract[]] {\n const exercise: ExerciseCommand = {\n templateId: ALLOCATION_INSTRUCTION_INTERFACE_ID_V2,\n contractId: withdrawCid,\n choice: 'AllocationInstruction_Withdraw',\n choiceArgument: { actors, extraArgs: EMPTY_EXTRA_ARGS() },\n }\n return [exercise, []]\n }\n\n async createAllocationFromContext(\n factoryId: string,\n choiceArgs: AllocationFactory_Allocate,\n choiceContext: OffLedger.AllocationInstructionV2.components['schemas']['ChoiceContext']\n ): Promise<[ExerciseCommand, DisclosedContract[]]> {\n this.logger.debug('Creating transfer from pre-fetched context...')\n choiceArgs.extraArgs.context = {\n ...choiceContext.choiceContextData,\n values: choiceContext.choiceContextData?.values ?? {},\n }\n const exercise: ExerciseCommand = {\n templateId: ALLOCATION_FACTORY_INTERFACE_ID_V2,\n contractId: factoryId,\n choice: 'AllocationFactory_Allocate',\n choiceArgument: choiceArgs,\n }\n return [exercise, choiceContext.disclosedContracts]\n }\n\n async fetchSettlementFactory(\n args: SettlementFactory_SettleBatchV2,\n registryUrl: URL\n ) {\n return this.core\n .getTokenStandardClientV2(registryUrl)\n .post('/registry/allocation/v2/settlement-factory', {\n choiceArguments: args as unknown as Record<string, never>,\n excludeDebugFields: true,\n })\n }\n\n async createAllocationsForRequest(opts: {\n requestCid: string\n request: AllocationRequestViewV2\n registry: (admin: PartyId) => Promise<URL>\n actors?: PartyId[]\n }): Promise<[ExerciseCommand[], DisclosedContract[]]> {\n const used = new Set<string>()\n const results: [ExerciseCommand, DisclosedContract[]][] = []\n\n for (const spec of opts.request.allocations) {\n const [cmd, dcs] = await this.createAllocation(\n {\n settlement: opts.request.settlement,\n spec,\n admin: spec.admin,\n actors: opts.actors,\n excludeCids: used,\n },\n await opts.registry(spec.admin)\n )\n\n for (const cid of (cmd.choiceArgument as AllocationFactory_Allocate)\n .inputHoldingCids) {\n used.add(cid as unknown as string)\n }\n results.push([cmd, dcs])\n }\n\n const acceptActors =\n opts.actors ??\n [\n ...new Set(\n opts.request.allocations.flatMap((s) =>\n s.authorizer.owner ? [s.authorizer.owner] : []\n )\n ),\n ].slice(0, 1)\n\n if (acceptActors.length === 0) {\n throw new Error(\n `Cannot accept allocation requests. No actors given and no authorizer has an owner`\n )\n }\n\n results.push([\n {\n templateId: ALLOCATION_REQUEST_INTERFACE_ID_V2,\n contractId: opts.requestCid,\n choice: 'AllocationRequest_Accept',\n choiceArgument: {\n actors: acceptActors,\n extraArgs: EMPTY_EXTRA_ARGS(),\n },\n },\n [],\n ])\n\n const dcs = new Map<string, DisclosedContract>(\n results\n .flatMap(([, d]) => d)\n .filter(\n (d): d is DisclosedContract & { contractId: string } =>\n d.contractId !== undefined\n )\n .map((d) => [d.contractId, d])\n )\n\n return [results.map(([c]) => c), [...dcs.values()]]\n }\n}\n","// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport {\n type HoldingView,\n type Metadata,\n FEATURED_APP_DELEGATE_PROXY_INTERFACE_ID,\n type Beneficiaries,\n} from '@canton-network/core-token-standard'\nimport type { HoldingView as HoldingViewV2 } from '@canton-network/core-token-standard-v2'\nimport { EventFilterBySetup } from '@canton-network/core-ledger-client-types'\nimport type { PartyId } from '@canton-network/core-types'\nimport {\n TokenStandardTransactionInterfaces,\n type PrettyContract,\n type ViewValue,\n type PrettyTransactions,\n type Transaction,\n type TransferObject,\n} from '@canton-network/core-tx-parser'\nimport type { AccessTokenProvider } from '@canton-network/core-wallet-auth'\nimport type {\n AbstractLedgerProvider,\n Ops,\n} from '@canton-network/core-provider-ledger'\nimport type { Decimal } from 'decimal.js'\nimport {\n type ApiVersion,\n type AssetCapabilities,\n type DisclosedContract,\n type ExerciseCommand,\n type AssetBody,\n type JsGetUpdatesResponse,\n KEY_MAPPING,\n SUPPORTED_VERSIONS,\n type UpdateFormat,\n} from './types.js'\nimport { TransferServiceV2 } from './v2/transfer-service.js'\nimport { TransferService } from './v1/transfer-service.js'\nimport { AllocationService } from './v1/allocation-service.js'\nimport { CoreService } from './core-service.js'\nimport { getLogger } from '@logtape/logtape'\nimport { AllocationService as AllocationServiceV2 } from './v2/allocation-service.js'\n\nexport function isApiVersion(v: string): v is ApiVersion {\n return (SUPPORTED_VERSIONS as readonly string[]).includes(v)\n}\n\nexport function resolveCapabilities(opts: {\n supportedApis: {\n [key: string]: number\n }\n}): AssetCapabilities {\n const supportedApis = opts.supportedApis\n\n const resolvedCapabilities: AssetCapabilities = {\n holding: [],\n transferInstruction: [],\n allocation: [],\n allocationInstruction: [],\n allocationRequest: [],\n }\n\n for (const key of Object.keys(supportedApis)) {\n const match = key.match(\n /^splice-api-token-(?<capabilityName>.+)-(?<version>v\\d+)$/\n )\n\n if (match?.groups) {\n const { capabilityName, version } = match.groups\n const targetKey = KEY_MAPPING[capabilityName]\n\n if (\n targetKey &&\n supportedApis[key] === 1 &&\n isApiVersion(version)\n ) {\n resolvedCapabilities[targetKey].push(version)\n }\n }\n }\n\n for (const key in resolvedCapabilities) {\n resolvedCapabilities[key as keyof AssetCapabilities].sort()\n }\n\n return resolvedCapabilities\n}\n\nexport class TokenStandardService {\n static readonly MEMO_KEY = 'splice.lfdecentralizedtrust.org/reason'\n\n private logger = getLogger([\n 'core',\n 'token-standard-service',\n 'TokenStandardService',\n ])\n\n readonly core: CoreService\n readonly allocation: AllocationService\n readonly transfer: TransferService\n readonly v2: {\n readonly transfer: TransferServiceV2\n readonly allocation: AllocationServiceV2\n }\n\n constructor(\n private ledgerProvider: AbstractLedgerProvider,\n private accessTokenProvider: AccessTokenProvider,\n private readonly isMasterUser: boolean\n ) {\n this.core = new CoreService(\n ledgerProvider,\n accessTokenProvider,\n isMasterUser\n )\n this.allocation = new AllocationService(this.core)\n this.transfer = new TransferService(this.core)\n this.v2 = {\n transfer: new TransferServiceV2(this.core),\n allocation: new AllocationServiceV2(this.core),\n }\n }\n\n async resolveCapabilitiesFromRegistryByInstrumentId(\n registryUrl: URL,\n instrumentId: string\n ): Promise<AssetCapabilities> {\n const metadataInfo = await this.getInstrumentById(\n registryUrl,\n instrumentId\n )\n return resolveCapabilities({\n supportedApis: metadataInfo.supportedApis,\n })\n }\n\n async getInstrumentById(registryUrl: URL, instrumentId: string) {\n try {\n const params: Record<string, unknown> = {\n path: {\n instrumentId,\n },\n }\n\n const client = this.core.getTokenStandardClient(registryUrl)\n\n return await client.get(\n '/registry/metadata/v1/instruments/{instrumentId}',\n params\n )\n } catch (e) {\n this.logger.warn(\n 'An error occurred while fetching the instrument by ID.',\n { error: e }\n )\n throw new Error(\n `Instrument id ${instrumentId} does not exist for this instrument admin.`,\n { cause: e }\n )\n }\n }\n\n async getInstrumentAdmin(registryUrl: URL): Promise<string> {\n const client = this.core.getTokenStandardClient(registryUrl)\n\n const info = await client.get('/registry/metadata/v1/info')\n\n return info.adminId\n }\n\n async listInstruments(\n registryUrl: URL,\n pageSize?: number,\n pageToken?: string\n ) {\n const client = this.core.getTokenStandardClient(registryUrl)\n return client.get('/registry/metadata/v1/instruments', {\n query: {\n ...(pageSize && { pageSize }),\n ...(pageToken && { pageToken }),\n },\n })\n }\n\n async instrumentsToAsset(registryUrl: URL): Promise<\n {\n id: string\n displayName: string\n symbol: string\n registryUrl: URL\n admin: PartyId\n capabilities: AssetCapabilities\n }[]\n > {\n let instrumentsResponse = await this.listInstruments(registryUrl)\n const instruments = [...instrumentsResponse.instruments]\n\n while (instrumentsResponse.nextPageToken) {\n instrumentsResponse = await this.listInstruments(\n registryUrl,\n undefined,\n instrumentsResponse.nextPageToken\n )\n instruments.push(...instrumentsResponse.instruments)\n }\n const instrumentAdmin = await this.getInstrumentAdmin(registryUrl)\n\n return instruments.map((instrument) => ({\n id: instrument.id,\n displayName: instrument.name,\n symbol: instrument.symbol,\n registryUrl,\n admin: instrumentAdmin,\n capabilities: resolveCapabilities({\n supportedApis: instrument.supportedApis,\n }),\n }))\n }\n\n async registriesToAssets(registryUrls: URL[]): Promise<AssetBody[]> {\n const allInstruments: {\n id: string\n displayName: string\n symbol: string\n registryUrl: URL\n admin: PartyId\n capabilities: AssetCapabilities\n }[] = []\n for (const registryUrl of registryUrls) {\n const instruments = await this.instrumentsToAsset(registryUrl)\n allInstruments.push(...instruments)\n }\n return allInstruments\n }\n\n // <T> is shape of viewValue related to queried interface.\n // i.e. when querying by TransferInstruction interfaceId, <T> would be TransferInstructionView from daml codegen\n async listContractsByInterface<T = ViewValue>(\n interfaceId: string,\n partyId?: PartyId,\n limit?: number,\n offset?: number,\n continueUntilCompletion?: boolean\n ): Promise<PrettyContract<T>[]> {\n return this.core.listContractsByInterface<T>(\n interfaceId,\n partyId,\n limit,\n offset,\n continueUntilCompletion\n )\n }\n\n async listHoldingTransactions(\n partyId: PartyId,\n afterOffset?: number,\n beforeOffset?: number\n ): Promise<PrettyTransactions> {\n try {\n this.logger.debug('Set or query offset')\n const afterOffsetOrLatest =\n afterOffset ??\n (\n await this.ledgerProvider.request<Ops.GetV2StateLatestPrunedOffsets>(\n {\n method: 'ledgerApi',\n params: {\n resource: '/v2/state/latest-pruned-offsets',\n requestMethod: 'get',\n },\n }\n )\n ).participantPrunedUpToInclusive!\n const beforeOffsetOrLatest =\n beforeOffset ??\n (\n await this.ledgerProvider.request<Ops.GetV2StateLedgerEnd>({\n method: 'ledgerApi',\n params: {\n resource: '/v2/state/ledger-end',\n requestMethod: 'get',\n query: {},\n },\n })\n ).offset!\n\n this.logger.debug('Using offset', { afterOffsetOrLatest })\n const updatesResponse: JsGetUpdatesResponse[] =\n await this.ledgerProvider.request<Ops.PostV2Updates>({\n method: 'ledgerApi',\n params: {\n resource: '/v2/updates',\n requestMethod: 'post',\n query: {},\n body: {\n updateFormat: {\n includeTransactions: {\n eventFormat: EventFilterBySetup({\n interfaceIds:\n TokenStandardTransactionInterfaces,\n isMasterUser: this.isMasterUser,\n partyId: partyId,\n includeWildcard: true,\n }),\n transactionShape:\n 'TRANSACTION_SHAPE_LEDGER_EFFECTS',\n },\n },\n beginExclusive: afterOffsetOrLatest,\n endInclusive: beforeOffsetOrLatest,\n },\n },\n })\n\n return this.core.toPrettyTransactions(\n updatesResponse,\n partyId\n // this.ledgerProvider\n )\n } catch (err) {\n this.logger.warn('Failed to list holding transactions.', {\n error: err,\n })\n throw err\n }\n }\n\n async getTransactionById(\n updateId: string,\n partyId: PartyId\n ): Promise<Transaction> {\n const updateFormat: UpdateFormat = {\n includeTransactions: {\n eventFormat: EventFilterBySetup({\n interfaceIds: TokenStandardTransactionInterfaces,\n isMasterUser: this.isMasterUser,\n partyId: partyId,\n includeWildcard: true,\n }),\n transactionShape: 'TRANSACTION_SHAPE_LEDGER_EFFECTS',\n },\n }\n\n const getUpdateResponse =\n await this.ledgerProvider.request<Ops.PostV2UpdatesUpdateById>({\n method: 'ledgerApi',\n params: {\n resource: '/v2/updates/update-by-id',\n requestMethod: 'post',\n body: {\n updateId,\n updateFormat,\n },\n },\n })\n\n return this.core.toPrettyTransaction(getUpdateResponse, partyId)\n }\n\n async getTransferObjectsById(\n updateId: string,\n partyId: PartyId\n ): Promise<TransferObject[]> {\n const updateFormat: UpdateFormat = {\n includeTransactions: {\n eventFormat: EventFilterBySetup({\n interfaceIds: TokenStandardTransactionInterfaces,\n isMasterUser: this.isMasterUser,\n partyId: partyId,\n includeWildcard: true,\n }),\n transactionShape: 'TRANSACTION_SHAPE_LEDGER_EFFECTS',\n },\n }\n\n const getUpdateResponse =\n await this.ledgerProvider.request<Ops.PostV2UpdatesUpdateById>({\n method: 'ledgerApi',\n params: {\n resource: '/v2/updates/update-by-id',\n requestMethod: 'post',\n body: {\n updateId,\n updateFormat,\n },\n },\n })\n\n return this.core.toPrettyTransferObjects(getUpdateResponse, partyId)\n }\n\n async getInputHoldingsCids(\n sender: PartyId,\n inputUtxos?: string[],\n amount?: Decimal\n ) {\n if (amount) {\n return this.core.getInputHoldingsCids({\n sender,\n inputUtxos: inputUtxos ?? [],\n amount,\n })\n } else {\n return this.core.getInputHoldingsCids({\n sender,\n inputUtxos: inputUtxos ?? [],\n })\n }\n }\n\n async createDelegateProxyTransfer(\n sender: PartyId,\n receiver: PartyId,\n amount: string,\n instrumentAdmin: PartyId, // TODO (#907): replace with registry call\n instrumentId: string,\n registryUrl: URL,\n featuredAppRightCid: string,\n proxyCid: string,\n beneficiaries: Beneficiaries[],\n inputUtxos?: string[],\n memo?: string,\n expiryDate?: Date,\n meta?: Metadata\n ): Promise<[ExerciseCommand, DisclosedContract[]]> {\n const [transferCommand, disclosedContracts] =\n await this.transfer.createTransfer(\n sender,\n receiver,\n amount,\n instrumentAdmin,\n instrumentId,\n registryUrl,\n inputUtxos,\n memo,\n expiryDate,\n meta\n )\n\n const sumOfWeights: number = beneficiaries.reduce(\n (totalWeight, beneficiary) => totalWeight + beneficiary.weight,\n 0\n )\n\n if (sumOfWeights > 1.0) {\n throw new Error('Sum of beneficiary weights is larger than 1.')\n }\n\n const choiceArgs = {\n cid: transferCommand.contractId,\n proxyArg: {\n featuredAppRightCid: featuredAppRightCid,\n beneficiaries,\n choiceArg: transferCommand.choiceArgument,\n },\n }\n\n const exercise: ExerciseCommand = {\n templateId: FEATURED_APP_DELEGATE_PROXY_INTERFACE_ID,\n contractId: proxyCid,\n choice: 'DelegateProxy_TransferFactory_Transfer',\n choiceArgument: choiceArgs,\n }\n\n return [exercise, disclosedContracts]\n }\n\n async exerciseDelegateProxyTransferInstructionAccept(\n exchangeParty: PartyId,\n proxyCid: string,\n transferInstructionCid: string,\n registryUrl: URL,\n featuredAppRightCid: string\n ): Promise<[ExerciseCommand, DisclosedContract[]]> {\n const [acceptTransferInstructionContext, disclosedContracts] =\n await this.transfer.createAcceptTransferInstruction(\n transferInstructionCid,\n registryUrl\n )\n\n const choiceArgs = {\n cid: acceptTransferInstructionContext.contractId,\n proxyArg: {\n featuredAppRightCid: featuredAppRightCid,\n beneficiaries: [\n {\n beneficiary: exchangeParty,\n weight: 1.0,\n },\n ],\n choiceArg: acceptTransferInstructionContext.choiceArgument,\n },\n }\n\n return [\n {\n templateId:\n '#splice-util-featured-app-proxies:Splice.Util.FeaturedApp.DelegateProxy:DelegateProxy',\n contractId: proxyCid,\n choice: 'DelegateProxy_TransferInstruction_Accept',\n choiceArgument: choiceArgs,\n },\n disclosedContracts,\n ]\n }\n\n static isHoldingLocked(\n holding: PrettyContract<HoldingView> | PrettyContract<HoldingViewV2>,\n currentTime: Date = new Date()\n ): boolean {\n const lock = holding.interfaceViewValue.lock\n if (!lock) return false\n\n let expiresAtAbsolute: Date | null = null\n let expiresAtRelative: Date | null = null\n\n if (lock.expiresAfter) {\n const createdAt = new Date(\n holding.activeContract.createdEvent.createdAt\n )\n\n // 1 microsecond = 0.001 milliseconds\n const msToAdd = parseInt(lock.expiresAfter.microseconds) / 1000\n\n expiresAtRelative = new Date(createdAt.getTime() + msToAdd)\n }\n if (lock.expiresAt) {\n expiresAtAbsolute = new Date(lock.expiresAt)\n }\n\n let expiresAt: Date\n\n // If both `expiresAt` and `expiresAfter` are set, the lock expires at the earlier of the two times.\n if (expiresAtRelative && expiresAtAbsolute) {\n expiresAt =\n expiresAtRelative < expiresAtAbsolute\n ? expiresAtRelative\n : expiresAtAbsolute\n } else if (expiresAtRelative) {\n expiresAt = expiresAtRelative\n } else if (expiresAtAbsolute) {\n expiresAt = expiresAtAbsolute\n } else {\n // No expiration => locked\n return true\n }\n\n return currentTime < expiresAt\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAcA,MAAa,uBAAuB;AAMpC,MAAa,aAAuB,EAAE,QAAQ,CAAC,EAAE;AAoCjD,MAAa,qBAA4C,CAAC,MAAM,IAAI;AAUpE,MAAa,cAAuD;CAChE,SAAS;CACT,wBAAwB;CACxB,YAAY;CACZ,0BAA0B;CAC1B,sBAAsB;AAC1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AC/CA,IAAa,oBAAb,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BAAgB;GAC/B;EACJ;EASA,OAAO,CAAC;GANJ,YAAYC,oCAAAA;GACZ,YAAY;GACZ,QAAQ;GACR,gBAAgB;EAGL,GAAG,kBAAkB;CACxC;CAEA,MAAM,+CACF,eACA,UACA,wBACA,aACA,qBAC+C;EAC/C,MAAM,CAAC,kCAAkC,sBACrC,MAAM,KAAK,SAAS,gCAChB,wBACA,WACJ;EAgBJ,OAAO,CACH;GACI,YACI;GACJ,YAAY;GACZ,QAAQ;GACR,gBAAgB;IAnBpB,KAAK,iCAAiC;IACtC,UAAU;KACe;KACrB,eAAe,CACX;MACI,aAAa;MACb,QAAQ;KACZ,CACJ;KACA,WAAW,iCAAiC;IAChD;GAS6B;EAC7B,GACA,kBACJ;CACJ;CAEA,OAAO,gBACH,SACA,8BAAoB,IAAI,KAAK,GACtB;EACP,MAAM,OAAO,QAAQ,mBAAmB;EACxC,IAAI,CAAC,MAAM,OAAO;EAElB,IAAI,oBAAiC;EACrC,IAAI,oBAAiC;EAErC,IAAI,KAAK,cAAc;GACnB,MAAM,YAAY,IAAI,KAClB,QAAQ,eAAe,aAAa,SACxC;GAGA,MAAM,UAAU,SAAS,KAAK,aAAa,YAAY,IAAI;GAE3D,oBAAoB,IAAI,KAAK,UAAU,QAAQ,IAAI,OAAO;EAC9D;EACA,IAAI,KAAK,WACL,oBAAoB,IAAI,KAAK,KAAK,SAAS;EAG/C,IAAI;EAGJ,IAAI,qBAAqB,mBACrB,YACI,oBAAoB,oBACd,oBACA;OACP,IAAI,mBACP,YAAY;OACT,IAAI,mBACP,YAAY;OAGZ,OAAO;EAGX,OAAO,cAAc;CACzB;AACJ;AA5coB,gBAAA,sBAAA,YAAW,wCAAA"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,6BAA6B,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,6BAA6B,CAAA;AAC3C,cAAc,YAAY,CAAA"}
|