Skip to main content
1 of 2

Well remaining accounts at the end of the day is just an array of accounts, in anchor lingo context in aCpiContext you specify all the accounts defined in the context and it exposes a helper with_remaining_accounts that consumes CpiContext and returns another CpiContext with the remaining accounts.

If we glance at ToAccountinfos impl for CpiContext it calls accounts impl of to_account_infos and extends the vector with the accounts stored in its with_remaining_field and at the end adds the program id in question.

As far as solana is concerned , solana programs dont have the concept of remaining accounts, they take as input a slice of accounts and depend on the passing program/client/user to ensure the order is correct.

To answer your question , you must make sure the order of accounts you pass to solana::invoke if the recipient program is an anchor program ensure the accounts specified in its Instruction struct are specified first and then pass any remaining accounts you desire and in the end pass the program id, basically mimic what a CpiContext will do, but if you have access to the program crate you can construct a CpiContext from it and then use with_remaining_accounts to pass the additional accounts and bank on anchor to do the rest.