Suppose I am developing an application that allows users to input their current portfolio amount and the annual percentage gains they receive. In Solidity, I can create a function called
get_portfolio, which calculates the return percentage based on the current date and the growth rate entered by the user. Then, the function adds the calculated return value to the original amount and returns it.
However, in Solana, instructions cannot return data. Therefore, if I retrieve a user's on-chain account data for their portfolio, it will only show the original portfolio amount that the user entered along with the growth rate. It will not show the current portfolio balance with the added the amount they got from growth rate calculation. To include the user's growth amount in the data, I need to create a separate instruction that updates the user's on-chain data with the growth return amount based on when it's called according to the yearly return initially entered. Then, I can fetch the updated user data account.
The problem with this approach is that I don't want to rely on the user/client to call the update instruction each time before getting the latest portfolio balance, if the instruction is not called, then the data will not have the returned gains the next time it is fetched. What could be a potential solution for this issue?