fn process_deposit(
    program_id: &Pubkey,
    accounts: &[AccountInfo],
    amount: u64,
    expected_decimals: u8,
) -> ProgramResult {
    let account_info_iter = &mut accounts.iter();
    let token_account_info = next_account_info(account_info_iter)?;
    let dest_token_account_info = next_account_info(account_info_iter)?;
    let mint_info = next_account_info(account_info_iter)?;
    let authority_info = next_account_info(account_info_iter)?;
    let authority_info_data_len = authority_info.data_len();

    check_program_account(mint_info.owner)?;
    let mint_data = &mint_info.data.borrow_mut();
    let mint = StateWithExtensions::<Mint>::unpack(mint_data)?;

    if expected_decimals != mint.base.decimals {
        return Err(TokenError::MintDecimalsMismatch.into());
    }

    // Process source account
    {
        check_program_account(token_account_info.owner)?;
        let token_account_data = &mut token_account_info.data.borrow_mut();
        let mut token_account = StateWithExtensionsMut::<Account>::unpack(token_account_data)?;

        Processor::validate_owner(
            program_id,
            token_account_info.owner,
            authority_info,
            authority_info_data_len,
            account_info_iter.as_slice(),
        )?;

        if token_account.base.is_frozen() {
            return Err(TokenError::AccountFrozen.into());
        }

        if token_account.base.mint != *mint_info.key {
            return Err(TokenError::MintMismatch.into());
        }

        // Wrapped SOL deposits are not supported because lamports cannot be vanished.
        assert!(!token_account.base.is_native());
        token_account.base.amount = token_account
            .base
            .amount
            .checked_sub(amount)
            .ok_or(TokenError::Overflow)?;

        token_account.pack_base();
    }

    //
    // Finished with the source token account at this point. Drop all references to it to avoid a
    // double borrow if the source and destination accounts are the same
    //

    // Process destination account
    {
        check_program_account(dest_token_account_info.owner)?;
        let dest_token_account_data = &mut dest_token_account_info.data.borrow_mut();
        let mut dest_token_account =
            StateWithExtensionsMut::<Account>::unpack(dest_token_account_data)?;

        if dest_token_account.base.is_frozen() {
            return Err(TokenError::AccountFrozen.into());
        }

        if dest_token_account.base.mint != *mint_info.key {
            return Err(TokenError::MintMismatch.into());
        }

        let mut dest_ct_token_account =
            dest_token_account.get_extension_mut::<ConfidentialTransferAccount>()?;
        dest_ct_token_account.approved()?;

        if !bool::from(&dest_ct_token_account.allow_balance_credits) {
            return Err(TokenError::ConfidentialTransferDepositsAndTransfersDisabled.into());
        }

        dest_ct_token_account.pending_balance =
            ops::add_to(&dest_ct_token_account.pending_balance, amount)
                .ok_or(TokenError::Overflow)?;

        dest_ct_token_account.pending_balance_credit_counter =
            (u64::from(dest_ct_token_account.pending_balance_credit_counter)
                .checked_add(1)
                .ok_or(TokenError::Overflow)?)
            .into();
    }

    Ok(())
}
/// Processes a [Deposit] instruction.
Processes a [Deposit] instruction.
Processes a [ Deposit ] instruction .
fn process_deposit(
    program_id: &Pubkey,
    accounts: &[AccountInfo],
    amount: u64,
    expected_decimals: u8,
) -> ProgramResult {
    let account_info_iter = &mut accounts.iter();
    let token_account_info = next_account_info(account_info_iter)?;
    let dest_token_account_info = next_account_info(account_info_iter)?;
    let mint_info = next_account_info(account_info_iter)?;
    let authority_info = next_account_info(account_info_iter)?;
    let authority_info_data_len = authority_info.data_len();
    check_program_account(mint_info.owner)?;
    let mint_data = &mint_info.data.borrow_mut();
    let mint = StateWithExtensions::<Mint>::unpack(mint_data)?;
    if expected_decimals != mint.base.decimals {
        return Err(TokenError::MintDecimalsMismatch.into());
    }
    // Process source account
    {
        check_program_account(token_account_info.owner)?;
        let token_account_data = &mut token_account_info.data.borrow_mut();
        let mut token_account = StateWithExtensionsMut::<Account>::unpack(token_account_data)?;
        Processor::validate_owner(
            program_id,
            token_account_info.owner,
            authority_info,
            authority_info_data_len,
            account_info_iter.as_slice(),
        )?;
        if token_account.base.is_frozen() {
            return Err(TokenError::AccountFrozen.into());
        }
        if token_account.base.mint != *mint_info.key {
            return Err(TokenError::MintMismatch.into());
        }
        // Wrapped SOL deposits are not supported because lamports cannot be vanished.
        assert!(!token_account.base.is_native());
        token_account.base.amount = token_account
            .base
            .amount
            .checked_sub(amount)
            .ok_or(TokenError::Overflow)?;
        token_account.pack_base();
    }
    //
    // Finished with the source token account at this point. Drop all references to it to avoid a
    // double borrow if the source and destination accounts are the same
    //
    // Process destination account
    {
        check_program_account(dest_token_account_info.owner)?;
        let dest_token_account_data = &mut dest_token_account_info.data.borrow_mut();
        let mut dest_token_account =
            StateWithExtensionsMut::<Account>::unpack(dest_token_account_data)?;
        if dest_token_account.base.is_frozen() {
            return Err(TokenError::AccountFrozen.into());
        }
        if dest_token_account.base.mint != *mint_info.key {
            return Err(TokenError::MintMismatch.into());
        }
        let mut dest_ct_token_account =
            dest_token_account.get_extension_mut::<ConfidentialTransferAccount>()?;
        dest_ct_token_account.approved()?;
        if !bool::from(&dest_ct_token_account.allow_balance_credits) {
            return Err(TokenError::ConfidentialTransferDepositsAndTransfersDisabled.into());
        }
        dest_ct_token_account.pending_balance =
            ops::add_to(&dest_ct_token_account.pending_balance, amount)
                .ok_or(TokenError::Overflow)?;
        dest_ct_token_account.pending_balance_credit_counter =
            (u64::from(dest_ct_token_account.pending_balance_credit_counter)
                .checked_add(1)
                .ok_or(TokenError::Overflow)?)
            .into();
    }
    Ok(())
}
fn process_deposit ( program_id : & Pubkey , accounts : & [ AccountInfo ] , amount : u64 , expected_decimals : u8 , ) -> ProgramResult { let account_info_iter = & mut accounts . iter ( ) ; let token_account_info = next_account_info ( account_info_iter ) ? ; let dest_token_account_info = next_account_info ( account_info_iter ) ? ; let mint_info = next_account_info ( account_info_iter ) ? ; let authority_info = next_account_info ( account_info_iter ) ? ; let authority_info_data_len = authority_info . data_len ( ) ; check_program_account ( mint_info . owner ) ? ; let mint_data = & mint_info . data . borrow_mut ( ) ; let mint = StateWithExtensions :: < Mint > :: unpack ( mint_data ) ? ; if expected_decimals != mint . base . decimals { return Err ( TokenError :: MintDecimalsMismatch . into ( ) ) ; } // Process source account { check_program_account ( token_account_info . owner ) ? ; let token_account_data = & mut token_account_info . data . borrow_mut ( ) ; let mut token_account = StateWithExtensionsMut :: < Account > :: unpack ( token_account_data ) ? ; Processor :: validate_owner ( program_id , token_account_info . owner , authority_info , authority_info_data_len , account_info_iter . as_slice ( ) , ) ? ; if token_account . base . is_frozen ( ) { return Err ( TokenError :: AccountFrozen . into ( ) ) ; } if token_account . base . mint != * mint_info . key { return Err ( TokenError :: MintMismatch . into ( ) ) ; } // Wrapped SOL deposits are not supported because lamports cannot be vanished. assert ! ( token_account base is_native ( ) ) ; token_account . base . amount = token_account . base . amount . checked_sub ( amount ) . ok_or ( TokenError :: Overflow ) ? ; token_account . pack_base ( ) ; } // // Finished with the source token account at this point. Drop all references to it to avoid a // double borrow if the source and destination accounts are the same // // Process destination account { check_program_account ( dest_token_account_info . owner ) ? ; let dest_token_account_data = & mut dest_token_account_info . data . borrow_mut ( ) ; let mut dest_token_account = StateWithExtensionsMut :: < Account > :: unpack ( dest_token_account_data ) ? ; if dest_token_account . base . is_frozen ( ) { return Err ( TokenError :: AccountFrozen . into ( ) ) ; } if dest_token_account . base . mint != * mint_info . key { return Err ( TokenError :: MintMismatch . into ( ) ) ; } let mut dest_ct_token_account = dest_token_account . get_extension_mut :: < ConfidentialTransferAccount > ( ) ? ; dest_ct_token_account . approved ( ) ? ; if ! bool :: from ( & dest_ct_token_account . allow_balance_credits ) { return Err ( TokenError :: ConfidentialTransferDepositsAndTransfersDisabled . into ( ) ) ; } dest_ct_token_account . pending_balance = ops :: add_to ( & dest_ct_token_account . pending_balance , amount ) . ok_or ( TokenError :: Overflow ) ? ; dest_ct_token_account . pending_balance_credit_counter = ( u64 :: from ( dest_ct_token_account . pending_balance_credit_counter ) . checked_add ( 1 ) . ok_or ( TokenError :: Overflow ) ? ) . into ( ) ; } Ok ( ( ) ) }
Processes a [Deposit] instruction.
Processes a [ Deposit ] instruction .
program_id
&Pubkey
accounts
&[AccountInfo]
amount
u64
expected_decimals
u8
program_id
&Pubkey
accounts
&[AccountInfo]
amount
u64
expected_decimals
u8