mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-13 23:16:52 +00:00
cap max supply on upgrade
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
use solana_program::{
|
||||
account_info::AccountInfo, entrypoint::ProgramResult, program_error::ProgramError,
|
||||
pubkey::Pubkey,
|
||||
program_pack::Pack, pubkey::Pubkey,
|
||||
};
|
||||
use spl_token::state::Mint;
|
||||
|
||||
use crate::{
|
||||
instruction::StakeArgs, loaders::*, MINT_ADDRESS, MINT_V1_ADDRESS, TREASURY, TREASURY_BUMP,
|
||||
error::OreError, instruction::StakeArgs, loaders::*, MAX_SUPPLY, MINT_ADDRESS, MINT_V1_ADDRESS,
|
||||
TREASURY, TREASURY_BUMP,
|
||||
};
|
||||
|
||||
/// Upgrade allows a user to migrate a v1 token to a v2 token one-for-one. Its responsibilies include:
|
||||
@@ -58,6 +60,13 @@ pub fn process_upgrade<'a, 'info>(
|
||||
// v1 token has 9 decimals. v2 token has 11.
|
||||
let amount_to_mint = amount.saturating_mul(100);
|
||||
|
||||
// Cap at max supply.
|
||||
let mint_data = mint_info.data.borrow();
|
||||
let mint = Mint::unpack(&mint_data)?;
|
||||
if mint.supply.saturating_add(amount_to_mint).gt(&MAX_SUPPLY) {
|
||||
return Err(OreError::MaxSupply.into());
|
||||
}
|
||||
|
||||
// Mint to the beneficiary account
|
||||
solana_program::program::invoke_signed(
|
||||
&spl_token::instruction::mint_to(
|
||||
|
||||
Reference in New Issue
Block a user