Skip to content

feat: added custom dars example#1607

Open
PHOL-DA wants to merge 10 commits into
mainfrom
phol/daml-codegen
Open

feat: added custom dars example#1607
PHOL-DA wants to merge 10 commits into
mainfrom
phol/daml-codegen

Conversation

@PHOL-DA
Copy link
Copy Markdown
Contributor

@PHOL-DA PHOL-DA commented Apr 13, 2026

anything in the damljs/ is codegen, so i leave it up to the reviewer if they want to go through those 600+ files.

recommended to reivew:
script 14, showcasing custom dar implementation
Typed contracts
implementation guide

PHOL-DA added 3 commits April 13, 2026 12:36
Signed-off-by: Phillip Olesen <phillip.olesen@digitalasset.com>
Signed-off-by: Phillip Olesen <phillip.olesen@digitalasset.com>
Signed-off-by: Phillip Olesen <phillip.olesen@digitalasset.com>
@PHOL-DA PHOL-DA requested review from a team as code owners April 13, 2026 11:42
Signed-off-by: Phillip Olesen <phillip.olesen@digitalasset.com>
Comment thread scripts/src/lib/utils.ts Dismissed
PHOL-DA added 4 commits April 13, 2026 14:21
Signed-off-by: Phillip Olesen <phillip.olesen@digitalasset.com>
Signed-off-by: Phillip Olesen <phillip.olesen@digitalasset.com>
Signed-off-by: Phillip Olesen <phillip.olesen@digitalasset.com>
Signed-off-by: Phillip Olesen <phillip.olesen@digitalasset.com>
Copy link
Copy Markdown
Contributor

@mjuchli-da mjuchli-da left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The focus of this PR lays imho on typed-contract.ts, which is a (de-)serialization facility from/to codegen objects.

This has been clunky for a while in the current codegen and there is an ongoing (scala) project that is supposed to introduce an improved codegen that covers the features here (will remember the name of the project tomorrow hopefully).

That said, we have done similar things in Java in the past where one could use the COMPANION object (belonging to a codegenned template): https://github.com/mjuchli-da/pqsj/blob/main/src/main/java/com/daml/pqsj/repository/ContractRepository.java#L44. Maybe there is similar stuff for Typescript given?

As for the rest: this resembles a classical App that makes use of some arbitrary daml codegen (and daml generic types) – the same way it has been done since Daml 2.0. As such, any reference to dvp should imho reside as an independent example app under /examples/dvp (or similar). This includes all the boilerplating necessary to build this app; except of course the codegen itself which must be built as part of the example app build.

(Extremely hard to review, highlights that codegen does not belong in a repo).

// SPDX-License-Identifier: Apache-2.0

export { AcsReader, AcsOptions } from './acs-reader.js'
export {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

relevant

// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

export type AcsContractLike = {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

relevant

Comment thread package.json
@@ -30,6 +30,7 @@
"script:generate:protobufs": "tsx ./scripts/src/generate-protobufs.ts",
"script:generate:tokenstandard": "tsx ./scripts/src/generate-token-standard.ts",
"script:generate:featured-dars": "tsx ./scripts/src/generate-featured-dars.ts",
"script:generate:dvp-testing-app": "tsx ./scripts/src/generate-dvp-testing-app.ts",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Command specific so an example app

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so the dvp trading is not an example app, we use it several places in code (script 04 and otc-trade.ts specifically in our repo).

so any place where we test transfer allocations, then we need the dvp trading app

Comment thread package.json
@@ -53,7 +54,11 @@
"api-specs",
"core/**",
"docs/wallet-integration-guide/examples",
"damljs/**",
"damljs/token-standard-models/**",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also an app under /examples can depend on some 3rd party package – either internally generated or from an external source

Comment thread package.json
@@ -122,7 +127,31 @@
"glob": "^10.5.0",
"vite": "^7.2.4",
"uri-js": "npm:uri-js-replace@^1.0.1",
"seroval": "^1.4.2"
"seroval": "^1.4.2",
"@daml.js/daml-prim-DA-Exception-ArithmeticError-1.0.0": "workspace:^",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a classical setup (standard practice since Daml 2.0), where a frontend app (dvp example in this case) depends on 1) generic daml types and 2) dar specific codegen. As such, we shouldn't have any of these dependencies in our root package.json

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not dependencies but resolutions, im just telling the repo (now that it is finding multiple versions) which version to use

Comment thread package.json
@@ -30,6 +30,7 @@
"script:generate:protobufs": "tsx ./scripts/src/generate-protobufs.ts",
"script:generate:tokenstandard": "tsx ./scripts/src/generate-token-standard.ts",
"script:generate:featured-dars": "tsx ./scripts/src/generate-featured-dars.ts",
"script:generate:dvp-testing-app": "tsx ./scripts/src/generate-dvp-testing-app.ts",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to example app

Comment thread package.json
@@ -53,7 +54,11 @@
"api-specs",
"core/**",
"docs/wallet-integration-guide/examples",
"damljs/**",
"damljs/token-standard-models/**",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codegen should not be part of the repo

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

codegen is already part of the repo, we do it for the token standard. All i did was make it work with more than one codegen from daml in the repo

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was actually to avoid to many of the codegen packages being part of our repo (now we only have the four main packages instead of every single codegen package)


.. code-block:: typescript

const proposalsForBob = toTemplateContracts<
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would try to hide this in sdk.ledger.acs.read(args, TradingApp.COMPANION)

return contract as TypedAcsContract<TPayload, TContract>
}

export function toTemplateContracts<
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the java codegen there are COMPANION objects for each template, isn't this the case in typescript?
If so, they come with a parse function.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return contract as TypedAcsContract<TPayload, TContract>
}

export function toTemplateContracts<
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the java codegen there are COMPANION objects for each template, isn't this the case in typescript?
If so, they come with a parse function.

PHOL-DA added 2 commits April 14, 2026 08:05
Signed-off-by: Phillip Olesen <phillip.olesen@digitalasset.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants