# Question about Holdings from the Finance Library

**URL:** <https://forum.canton.network/t/question-about-holdings-from-the-finance-library/5842>\
**Category:** App Development\
**Tags:** daml-finance\
**Created:** [December 20, 2022, 12:08pm UTC](https://forum.canton.network/t/question-about-holdings-from-the-finance-library/5842 "2022-12-20T12:08:58Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![cohen.avraham](https://avatars.discourse-cdn.com/v4/letter/c/a87d85/32.png) [@cohen.avraham](https://forum.canton.network/u/cohen.avraham)\
**Post date:** [December 20, 2022, 12:08pm UTC](https://forum.canton.network/t/question-about-holdings-from-the-finance-library/5842/1 "2022-12-20T12:08:58Z")

</div>

G-d willing

Hello,  
I am using the Finance Library, assuming a party would like to transfer holdings to another party. However, the flow does not allow him to transfer it directly - he needs to apply a request for it, and once the custodian approves it, the custodian will do the transfer.  
However, since the Holding does not have a key, how does the custodian can pull the owner’s holdings in order to find the best one (or more, in case a merge will be first needed) to do the transfer with?

Thanks,

---

<div class="post-metadata">

**Author:** ![georg](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/georg/32/368_2.png) [@georg](https://forum.canton.network/u/georg)\
**Post date:** [December 20, 2022, 2:22pm UTC](https://forum.canton.network/t/question-about-holdings-from-the-finance-library/5842/2 "2022-12-20T14:22:22Z")

</div>

- The necessary authorization restriction on transfers can be achieved through the [`controllers` property](https://github.com/digital-asset/daml-finance/blob/3f0cfae0787a9dde2395c761f820b30c4b2ddc91/src/main/daml/Daml/Finance/Account/Account.daml#L26) on accounts. It determines who needs to authorize outgoing and incoming transfers for an account.
- Your design to collect joint authorization though eg. a `TransferRequest` contract makes sense
- As a signatory the `custodian` has visibility on the `owner`’s holdings with them. So they can (using off-ledger logic) select suitable holdings, and pass them into eg. an `Execute` choice on the `TransferRequest`, which can take care of the “right-sizing” (ie. splitting / merging) of holdings, and subsequently calls `Transfer` on the resulting holding.

Hope this helps.

---

<div class="post-metadata">

**Author:** ![cohen.avraham](https://avatars.discourse-cdn.com/v4/letter/c/a87d85/32.png) [@cohen.avraham](https://forum.canton.network/u/cohen.avraham)\
**Post date:** [December 20, 2022, 2:32pm UTC](https://forum.canton.network/t/question-about-holdings-from-the-finance-library/5842/3 "2022-12-20T14:32:35Z")

</div>

G-d willing

Thanks @georg for your answer, however, my question was about the proper way of doing it.  
I know that the custodian can query the holdings for the owner, but since there is no key on holdings, the custodian will query for all the active holdings available on the ledger.  
So, going through them can consume precious time, and it does not sound like the best approach. Is there a way to filter them?  
Or is there something else that I can do in order to achieve it?

---

<div class="post-metadata">

**Author:** ![Johan\_Sjodin](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/johan_sjodin/32/2822_2.png) [@Johan\_Sjodin](https://forum.canton.network/u/Johan_Sjodin)\
**Post date:** [December 20, 2022, 2:48pm UTC](https://forum.canton.network/t/question-about-holdings-from-the-finance-library/5842/4 "2022-12-20T14:48:48Z")

</div>

You could let the `owner` lock one of its holding to the `custodian`, and refer to that contract id in the `TransferRequest` (i.e., the `TransferRequest` template would have a `ContractId Base.I` as field). In the `Execute` choice body, the `custodian` would then:

1. Unlock the holding
2. Split off the right amount
3. Do the transfer

By locking the holding, you make sure that the provided holding can’t be used by another process, and the `custodian` would not need to do any query off-ledger.

---

<div class="post-metadata">

**Author:** ![cohen.avraham](https://avatars.discourse-cdn.com/v4/letter/c/a87d85/32.png) [@cohen.avraham](https://forum.canton.network/u/cohen.avraham)\
**Post date:** [December 20, 2022, 3:01pm UTC](https://forum.canton.network/t/question-about-holdings-from-the-finance-library/5842/5 "2022-12-20T15:01:11Z")

</div>

G-d willing

I preferred to find some efficient solution from the custodian side. But, I assume it is not possible 😔

---

<div class="post-metadata">

**Author:** ![georg](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/georg/32/368_2.png) [@georg](https://forum.canton.network/u/georg)\
**Post date:** [December 20, 2022, 3:57pm UTC](https://forum.canton.network/t/question-about-holdings-from-the-finance-library/5842/6 "2022-12-20T15:57:11Z")

</div>

I’m not sure a key would solve this: you’d need to have a unique key on each holding, and could only ever fetch a single contract by its key. And not sure what a sensible key would be for a holding.

If you’re referring to eg. querying holdings by _instrument key_, that is definitely something to be done on the client side - there’s no such functionality within Daml. Through the JSON API, for example, you can submit queries (eg. via the JS bindings) that contain such filter.

Something along the lines of:

```haskell
const { contracts } = useStreamQueries(Holding, () => { your_query });

```

(check the docs for the exact syntax of the query)

The other option is what Johan mentions: “tagging” certain holdings by locking them, and referring to them specifically by contract id on the `TransferRequest`.

---

<div class="post-metadata">

**Author:** ![cohen.avraham](https://avatars.discourse-cdn.com/v4/letter/c/a87d85/32.png) [@cohen.avraham](https://forum.canton.network/u/cohen.avraham)\
**Post date:** [December 20, 2022, 4:35pm UTC](https://forum.canton.network/t/question-about-holdings-from-the-finance-library/5842/7 "2022-12-20T16:35:03Z")

</div>

G-d willing

@georg I think that having the ability to query for contracts by multiple parties could solve such an issue.  
I mean for example to do something like the following:

```haskell
  holdingCids <- query @Holding [custodian, owner]

```

In this case, the custodian can query for only the holdings that belong to the owner.

---

<div class="post-metadata">

**Author:** ![georg](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/georg/32/368_2.png) [@georg](https://forum.canton.network/u/georg)\
**Post date:** [December 20, 2022, 7:50pm UTC](https://forum.canton.network/t/question-about-holdings-from-the-finance-library/5842/8 "2022-12-20T19:50:24Z")

</div>

In Daml scripts you can do that using [queryFilter](https://docs.daml.com/daml-script/api/Daml-Script.html#function-daml-script-queryfilter-79010). It only works on concrete templates though, not interfaces.
