INNER CODE UNIT · TypeScript
burn_token
Deezzir/solana-bot · src/commands.ts:34
export async function burn_token(mint: PublicKey, burner: Keypair, amount?: number, percent?: number): Promise<void> {
if (!amount && !percent) throw new Error('Either amount or percent should be provided.');
if (amount && percent) throw new Error('Only one of amount or percent should be provided.');
if (amount && amount <= 0) throw new Error('Amount should be greater than 0.');
if (percent && (percent <= 0 || percent > 1)) throw new Error('Percent should be between 0 and 1.');
const mint_meta = await trade.get_token_meta(mint);
if (!mint_meta) throw new Error(`Mint metadata not found for the mint: ${mint.toString()}.`);
common.log(common.yellow(`Burning the token by the mint ${mint.toString()}...`));
common.log(
common.yellow(
`Burning ${amount ? `${amount} tokens` : `${percent! * 100}% of ${mint_meta.token_symbol.toUpperCase()}`}...`
)
);
const token_amount = await trade.get_token_balance(burner.publicKey, mint, COMMITMENT, mint_meta.token_program);
common.log(