pub fn process_instruction(
    program_id: &Pubkey, // Public key of the account the hello world program was loaded into
    accounts: &[AccountInfo], // The account to say hello to
    _instruction_data: &[u8], // Ignored, all helloworld instructions are hello
) -> ProgramResult {
     msg!("Hello World Rust program entrypoint");

    // Iterating accounts is safer than indexing
    let accounts_iter = &mut accounts.iter();
    msg!("1");
    // Get the account to say hello to
    let market1 = next_account_info(accounts_iter)?;
    let request_queue = next_account_info(accounts_iter)?;
    let event_queue = next_account_info(accounts_iter)?;
    let bids = next_account_info(accounts_iter)?;
    let asks = next_account_info(accounts_iter)?;
    let coin_vault = next_account_info(accounts_iter)?;
    let pc_vault = next_account_info(accounts_iter)?;
    let vault_signer = next_account_info(accounts_iter)?;
    let open_orders = next_account_info(accounts_iter)?;
    let order_payer_token_account = next_account_info(accounts_iter)?;
    let coin_wallet = next_account_info(accounts_iter)?;
    let pc_wallet = next_account_info(accounts_iter)?;
    let authority = next_account_info(accounts_iter)?;
    let dex_program = next_account_info(accounts_iter)?;
    let token_program = next_account_info(accounts_iter)?;
    let swap_program_id= next_account_info(accounts_iter)?;
    let rent = next_account_info(accounts_iter)?;
    let program_address= next_account_info(accounts_iter)?;
    let create_account_program=next_account_info(accounts_iter)?;
    let program_id_swap_info=swap_program_id.clone();
    let nonce=_instruction_data[0];
    msg!("2");
    let expected_allocated_key =Pubkey::create_program_address(&[&create_account_program.key.to_bytes()[..32], &[nonce]], program_id)?;
        if *program_address.key != expected_allocated_key {
        // allocated key does not match the derived address
        return Err(ProgramError::InvalidArgument);
        }
        msg!("4");
        let seeds=&[&create_account_program.key.to_bytes()[..32], &[nonce]];
        let signer_seeds = &[&seeds[..]];
    let cpi_accounts=serum_swap::cpi::accounts::Swap{
        market:serum_swap::cpi::accounts::MarketAccounts{
            market:market1.clone(),
            open_orders:open_orders.clone(),
            request_queue:request_queue.clone(),
            event_queue:event_queue.clone(),
            bids:bids.clone(),
            asks:asks.clone(),
            order_payer_token_account:order_payer_token_account.clone(),
            coin_vault:coin_vault.clone(),
            pc_vault:pc_vault.clone(),
            vault_signer:vault_signer.clone(),
            coin_wallet:coin_wallet.clone()
        },
        authority:authority.clone(),
        pc_wallet:pc_wallet.clone(),
        dex_program:dex_program.clone(),
        token_program:token_program.clone(),
        rent:rent.clone()
    };
    msg!("3");
   
    msg!("4");
    let rate:u64 = 8;
    let from_decimals:u8 = 6;
    let quote_decimals:u8 = 6;
    let strict:bool=false;
    let amount:u64=2000000;
      let min_exchange_rate=serum_swap::ExchangeRate{ rate, from_decimals, quote_decimals, strict };
let side=serum_swap::Side::Ask;
    msg!("8");
   // let cpi_ctx = CpiContext::new(program_id_swap_info cpi_accounts);
   let cpi_ctx = CpiContext::new(program_id_swap_info, cpi_accounts);
    msg!("5");
    serum_swap::cpi::swap(cpi_ctx,side,amount,min_exchange_rate);
    msg!("6");
    Ok(()) 
}
// Program entrypoint's implementation swap A To B // deposit 
Program entrypoint's implementation swap A To B // deposit
Program entrypoint ' s implementation swap A To B // deposit
pub fn process_instruction(
    program_id: &Pubkey, // Public key of the account the hello world program was loaded into
    accounts: &[AccountInfo], // The account to say hello to
    _instruction_data: &[u8], // Ignored, all helloworld instructions are hello
) -> ProgramResult {
     msg!("Hello World Rust program entrypoint");
    // Iterating accounts is safer than indexing
    let accounts_iter = &mut accounts.iter();
    msg!("1");
    // Get the account to say hello to
    let market1 = next_account_info(accounts_iter)?;
    let request_queue = next_account_info(accounts_iter)?;
    let event_queue = next_account_info(accounts_iter)?;
    let bids = next_account_info(accounts_iter)?;
    let asks = next_account_info(accounts_iter)?;
    let coin_vault = next_account_info(accounts_iter)?;
    let pc_vault = next_account_info(accounts_iter)?;
    let vault_signer = next_account_info(accounts_iter)?;
    let open_orders = next_account_info(accounts_iter)?;
    let order_payer_token_account = next_account_info(accounts_iter)?;
    let coin_wallet = next_account_info(accounts_iter)?;
    let pc_wallet = next_account_info(accounts_iter)?;
    let authority = next_account_info(accounts_iter)?;
    let dex_program = next_account_info(accounts_iter)?;
    let token_program = next_account_info(accounts_iter)?;
    let swap_program_id= next_account_info(accounts_iter)?;
    let rent = next_account_info(accounts_iter)?;
    let program_address= next_account_info(accounts_iter)?;
    let create_account_program=next_account_info(accounts_iter)?;
    let program_id_swap_info=swap_program_id.clone();
    let nonce=_instruction_data[0];
    msg!("2");
    let expected_allocated_key =Pubkey::create_program_address(&[&create_account_program.key.to_bytes()[..32], &[nonce]], program_id)?;
        if *program_address.key != expected_allocated_key {
        // allocated key does not match the derived address
        return Err(ProgramError::InvalidArgument);
        }
        msg!("4");
        let seeds=&[&create_account_program.key.to_bytes()[..32], &[nonce]];
        let signer_seeds = &[&seeds[..]];
    let cpi_accounts=serum_swap::cpi::accounts::Swap{
        market:serum_swap::cpi::accounts::MarketAccounts{
            market:market1.clone(),
            open_orders:open_orders.clone(),
            request_queue:request_queue.clone(),
            event_queue:event_queue.clone(),
            bids:bids.clone(),
            asks:asks.clone(),
            order_payer_token_account:order_payer_token_account.clone(),
            coin_vault:coin_vault.clone(),
            pc_vault:pc_vault.clone(),
            vault_signer:vault_signer.clone(),
            coin_wallet:coin_wallet.clone()
        },
        authority:authority.clone(),
        pc_wallet:pc_wallet.clone(),
        dex_program:dex_program.clone(),
        token_program:token_program.clone(),
        rent:rent.clone()
    };
    msg!("3");
    msg!("4");
    let rate:u64 = 8;
    let from_decimals:u8 = 6;
    let quote_decimals:u8 = 6;
    let strict:bool=false;
    let amount:u64=2000000;
      let min_exchange_rate=serum_swap::ExchangeRate{ rate, from_decimals, quote_decimals, strict };
let side=serum_swap::Side::Ask;
    msg!("8");
   // let cpi_ctx = CpiContext::new(program_id_swap_info cpi_accounts);
   let cpi_ctx = CpiContext::new(program_id_swap_info, cpi_accounts);
    msg!("5");
    serum_swap::cpi::swap(cpi_ctx,side,amount,min_exchange_rate);
    msg!("6");
    Ok(()) 
}
pub fn process_instruction ( program_id : & Pubkey , // Public key of the account the hello world program was loaded into accounts : & [ AccountInfo ] , // The account to say hello to _instruction_data : & [ u8 ] , // Ignored, all helloworld instructions are hello ) -> ProgramResult { msg ! ( " " ) ; // Iterating accounts is safer than indexing let accounts_iter = & mut accounts . iter ( ) ; msg ! ( " " ) ; // Get the account to say hello to let market1 = next_account_info ( accounts_iter ) ? ; let request_queue = next_account_info ( accounts_iter ) ? ; let event_queue = next_account_info ( accounts_iter ) ? ; let bids = next_account_info ( accounts_iter ) ? ; let asks = next_account_info ( accounts_iter ) ? ; let coin_vault = next_account_info ( accounts_iter ) ? ; let pc_vault = next_account_info ( accounts_iter ) ? ; let vault_signer = next_account_info ( accounts_iter ) ? ; let open_orders = next_account_info ( accounts_iter ) ? ; let order_payer_token_account = next_account_info ( accounts_iter ) ? ; let coin_wallet = next_account_info ( accounts_iter ) ? ; let pc_wallet = next_account_info ( accounts_iter ) ? ; let authority = next_account_info ( accounts_iter ) ? ; let dex_program = next_account_info ( accounts_iter ) ? ; let token_program = next_account_info ( accounts_iter ) ? ; let swap_program_id = next_account_info ( accounts_iter ) ? ; let rent = next_account_info ( accounts_iter ) ? ; let program_address = next_account_info ( accounts_iter ) ? ; let create_account_program = next_account_info ( accounts_iter ) ? ; let program_id_swap_info = swap_program_id . clone ( ) ; let nonce = _instruction_data [ 0 ] ; msg ! ( " " ) ; let expected_allocated_key = Pubkey :: create_program_address ( & [ & create_account_program . key . to_bytes ( ) [ .. 32 ] , & [ nonce ] ] , program_id ) ? ; if * program_address . key != expected_allocated_key { // allocated key does not match the derived address return Err ( ProgramError :: InvalidArgument ) ; } msg ! ( " " ) ; let seeds = & [ & create_account_program . key . to_bytes ( ) [ .. 32 ] , & [ nonce ] ] ; let signer_seeds = & [ & seeds [ .. ] ] ; let cpi_accounts = serum_swap :: cpi :: accounts :: Swap { market : serum_swap :: cpi :: accounts :: MarketAccounts { market : market1 . clone ( ) , open_orders : open_orders . clone ( ) , request_queue : request_queue . clone ( ) , event_queue : event_queue . clone ( ) , bids : bids . clone ( ) , asks : asks . clone ( ) , order_payer_token_account : order_payer_token_account . clone ( ) , coin_vault : coin_vault . clone ( ) , pc_vault : pc_vault . clone ( ) , vault_signer : vault_signer . clone ( ) , coin_wallet : coin_wallet . clone ( ) } , authority : authority . clone ( ) , pc_wallet : pc_wallet . clone ( ) , dex_program : dex_program . clone ( ) , token_program : token_program . clone ( ) , rent : rent . clone ( ) } ; msg ! ( " " ) ; msg ! ( " " ) ; let rate : u64 = 8 ; let from_decimals : u8 = 6 ; let quote_decimals : u8 = 6 ; let strict : bool = false ; let amount : u64 = 2000000 ; let min_exchange_rate = serum_swap :: ExchangeRate { rate , from_decimals , quote_decimals , strict } ; let side = serum_swap :: Side :: Ask ; msg ! ( " " ) ; // let cpi_ctx = CpiContext::new(program_id_swap_info cpi_accounts); let cpi_ctx = CpiContext :: new ( program_id_swap_info , cpi_accounts ) ; msg ! ( " " ) ; serum_swap :: cpi :: swap ( cpi_ctx , side , amount , min_exchange_rate ) ; msg ! ( " " ) ; Ok ( ( ) ) }
Program entrypoint's implementation swap A To B // deposit
Program entrypoint ' s implementation swap A To B // deposit
program_id
&Pubkey
accounts
&[AccountInfo]
_instruction_data
&[u8]
program_id
&Pubkey
accounts
&[AccountInfo]
_instruction_data
&[u8]