Imagine this usecase. We have a central treasury/vault, which holds all of the funds in the protocol. There are multiple separate games, which execute game logic, but do not hold the funds. Once game logic requires to deposit funds, they sent it to treasury/vault, and once logic requires to withdraw funds, they instruct treasury/vault to make a withdrawal.
The key here, is that the funds are mutual between different games and are pooled together. They also need to be securely accessed by the Treasury and different Games in the protocol, but no one else.
the only way I can think of implementing this is to have:
- Treasury program which owns the general PDA which stores the funds, as well as allows for admin pubkey to interact with the PDA
- Multiple separate game programs, which make CPI signed with game PDA into Treasury program in order to withdraw the funds.
The questions are:
- is there a better practices/architecture to implement this?
Maybe it is possible to share the same account between different programs, with account being mutable in each of them.
- is it possible to validate, that the CPI was made from specific game program, for example by retrieving the signing PDA, and comparing it against some hardcoded value?
I've read that it is not possible to retrieve the caller program ID in the callee.
- If I would not make the treasury program code open source, would it be 100% impossible to make a CPI to it by some 3rd party (I am using Anchor)?
I've read, that it is possible to reverse engineer the code and make CPIs even if code is not public, thus access control is needed.
- Puppet - Puppet master Anchor example seems outdated and JS test part does not work for me. Maybe there are another good examples of PDA signed CPI to another program (not System program, but native to project/user program)
Thanks in advance