Skip to content
CCPEDIAby Unity Nodes
Discussions/App Development/Instrument Factory Create Base InterfaceForum ↗

Instrument Factory Create Base Interface

App Development2 posts278 views2 likesLast activity Feb 2023
DR
drdo.intellecteuOP
Jan 2023

Hello,

I have question regarding Daml Finance.

Why do the Instrument factories all return the Base instrument interface rather than the corresponding Interface?
E.g. the Token factory’s Create choice returns the interface from Base.Instrument rather than the more specific Token.Instrument.

Thanks,
Daniel

MA
Matteo_Limberto
Feb 2023

Hi @drdo.intellecteu,

There is no strong reason why this is the case.

I believe this made sense in the context of the Daml Finance Reference App, where we write generic functionality that is meant to handle multiple instrument templates.

However, I agree that returning the specific instrument interface type makes more sense from a library perspective. Also, an up-case is in this case more type-safe than a downcast. I raised an issue to track this item. Please, note that this would be a breaking change to the interface (hence we might consider it for a 2.0.0 version).

In the meantime, I suggest you use a coerceInterfaceContractId after the call to the Create method to work against the specific instrument interface type.

Thanks,
Matteo

← Back to Discussions