Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mint_token function to account for token decimals #114

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

alex-js-ltd
Copy link

@alex-js-ltd alex-js-ltd commented Aug 13, 2024

Description

the mint_token function in tokens/token-2022/basics/anchor/programs/basics/src/lib.rs file does not correctly account for the token's decimal places, leading to incorrect minting amounts.

Proposed Solution

Update the mint_token function to correctly handle token decimals.

Updated Code:

pub fn mint_token(ctx: Context<MintToken>, amount: u64) -> Result<()> {
    let cpi_accounts = MintTo {
        mint: ctx.accounts.mint.to_account_info().clone(),
        to: ctx.accounts.receiver.to_account_info().clone(),
        authority: ctx.accounts.signer.to_account_info(),
    };

    let cpi_program = ctx.accounts.token_program.to_account_info();
    let cpi_context = CpiContext::new(cpi_program, cpi_accounts);
    token_interface::mint_to(cpi_context, amount * 10u64.pow(ctx.accounts.mint.decimals as u32))?;
    msg!("Mint Token");
    Ok(())
}

Thank you! 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant