1

I'd like to make custom token program which just proxies all transaction to TOKEN_PROGRAM. I've made custom TOKEN_PROGRAM and ASSOCIATIED_TOKEN_PROGRAM, and what I'm trying to achieve is to make that token_program to invoke existing TOKEN_PROGRAM.

For instance, When I try to invoke token program for transfer, It just simply invokes existing TOKEN_PROGRAM to transfer.

This is what I tried:

                let account_info_iter = &mut accounts.iter();

                let source_account_info = next_account_info(account_info_iter)?;
                let test1 = source_account_info.clone();
                let destination_account_info = next_account_info(account_info_iter)?;
                let test2 = destination_account_info.clone();
                let authority_info = next_account_info(account_info_iter)?;
        
                let transfer_tokens_instruction = transfer(
                    &program_id,
                    &source_account_info.key,
                    &destination_account_info.key,
                    &authority_info.key,
                    &[&source_account_info.key],
                    amount,
                )?;
                let required_accounts_for_transfer = [
                    test1,
                    test2,
                ];
                
                invoke(
                    &transfer_tokens_instruction,
                    &required_accounts_for_transfer,
                )?;

But it just simply don't work. How do I invoke token program? is there any source I can see?

1
  • please update the question to elaborate what "simply don't work". surely there's an error message of some kind
    – trent.sol
    Commented Aug 18, 2022 at 6:39

2 Answers 2

1

Use the anchor_spl crate.

This source code uses that crate to accomplish exactly what I believe you're trying to do, hope it helps you:

https://github.com/coral-xyz/anchor/blob/master/tests/spl/token-proxy/programs/token-proxy/src/lib.rs

0

check this detailed and very helpful article on Cross Program Invocation.

https://blocksecteam.medium.com/secure-the-solana-ecosystem-2-calling-between-programs-5fa3d947c4ed

1
  • this is effectively a url-only answer. improve it by discussing the content of the link sufficiently to answer the the question
    – trent.sol
    Commented Aug 18, 2022 at 6:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.