Handling close out/clear state if local state is empty

Hi, I think that’s not possible but I’ll search for a confirmation. Thanks in advance.
In my current smart contract I don’t allow the close out and the clear state programs (returning 0). This is because there is stored the asa_id that the escrow has I wanted to handle this by sending out the asa_id stored, then allowing to clear or opt out. But in order to do this I will have to know the asa id stored.
Is the only way pass the asa ids as an argument?

I am not completely sure to understand the use case.
Can you just have the associated smart contract store in local storage the ASA ID used? You need it to opt-in anyway.
If not, there is no way to my knowledge to get the list of ASA an account opted in to.

An additional note: there is no way to prevent “clear state” from happening. Even if the clear program always fails, the account will be opt out and the local storage will be cleared completely (contrary to what happens with “close out”). That being said, if you call a smart contract from a smart signature account, then the smart signature can prevent “clear state” from ever being issue.

I’ll try to explain better, The user sends an asset to the smart contract, the smart contract saves on his local storage the asa id this user has sended to the escrow account ( this in order to permit him to claim that asset). My thought was in the case in which the user sends an assets, forgot about it, he optout or clear the local storage. If he wanted to claim it, so he maybe does the opt in again but, he can’t claim because the local storage was cleared, right? So my solution was to permit the clear state or the optout calls only if he has the local storage empty.
That being said, seem that is useless as you said that I can’t prevent “clear state” from happening. Of course my interface to the smart contract will not show this option! contrary to close out which the best solution maybe is to permit it (as soon as it’s impossible to dinamically know when a local storage is empty) but warning if there is a not-empty local storage.
Another solution that came in my mind was to use a local vairable (counter) that keeps track dinamically on the total local variables saved, sacrificing one of the 16 variables. Could be an idea
Thanks for the answer!

You can easily prevent the “close out” operation when the ASA is still in the escrow, by checking the ASA balance using asset_holding_get

But you cannot prevent the clear out from making the user lose access to the ASA.
There is no way around it.
What you can do is store cleared-out ASA ID in global storage, maybe with the address of the account that cleared out.
But global storage is limited to 64 key/values, which means you can only save the first 64 or so assets (maybe a bit more if you compress smartly data).