Deprecate upgrade (#101)

* deprecate upgrade function

* bump versions

* move flag
This commit is contained in:
Hardhat Chad
2024-11-01 16:08:02 -05:00
committed by GitHub
parent cb24b65133
commit 0e1460e2a4
7 changed files with 11 additions and 69 deletions

View File

@@ -21,6 +21,7 @@ use upgrade::*;
use ore_api::instruction::*;
use steel::*;
#[allow(deprecated)]
pub fn process_instruction(
program_id: &Pubkey,
accounts: &[AccountInfo],
@@ -34,7 +35,6 @@ pub fn process_instruction(
OreInstruction::Mine => process_mine(accounts, data)?,
OreInstruction::Open => process_open(accounts, data)?,
OreInstruction::Reset => process_reset(accounts, data)?,
#[allow(deprecated)]
OreInstruction::Stake => process_stake(accounts, data)?,
OreInstruction::Update => process_update(accounts, data)?,
OreInstruction::Upgrade => process_upgrade(accounts, data)?,

View File

@@ -1,67 +1,6 @@
use ore_api::prelude::*;
use steel::*;
/// Upgrade allows a user to migrate a v1 token to a v2 token at a 1:1 exchange rate.
pub fn process_upgrade(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult {
// Parse args
let args = Upgrade::try_from_bytes(data)?;
let amount = u64::from_le_bytes(args.amount);
// Load accounts
let [signer_info, beneficiary_info, mint_info, mint_v1_info, sender_info, treasury_info, token_program] =
accounts
else {
return Err(ProgramError::NotEnoughAccountKeys);
};
signer_info.is_signer()?;
beneficiary_info
.is_writable()?
.as_token_account()?
.assert(|t| t.owner == *signer_info.key)?
.assert(|t| t.mint == MINT_ADDRESS)?;
let mint = mint_info
.is_writable()?
.has_address(&MINT_ADDRESS)?
.as_mint()?;
mint_v1_info
.is_writable()?
.has_address(&MINT_V1_ADDRESS)?
.as_mint()?;
sender_info
.is_writable()?
.as_token_account()?
.assert(|t| t.owner == *signer_info.key)?
.assert(|t| t.mint == MINT_V1_ADDRESS)?;
treasury_info.is_treasury()?;
token_program.is_program(&spl_token::ID)?;
// Burn v1 tokens
burn(
sender_info,
mint_v1_info,
signer_info,
token_program,
amount,
)?;
// Account for decimals change.
// v1 token has 9 decimals. v2 token has 11.
let amount_to_mint = amount.saturating_mul(100);
// Cap at max supply.
if mint.supply.saturating_add(amount_to_mint).gt(&MAX_SUPPLY) {
return Err(OreError::MaxSupply.into());
}
// Mint to the beneficiary account
mint_to_signed(
mint_info,
beneficiary_info,
treasury_info,
token_program,
amount_to_mint,
&[TREASURY],
)?;
Ok(())
pub fn process_upgrade(_accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResult {
panic!("This instruction has been deprecated. v1 tokens are no longer eligable to upgrade.");
}