From 1d20ed7772216a900ccb41845b1166aaf64482a5 Mon Sep 17 00:00:00 2001 From: alex Date: Tue, 18 Jun 2024 22:06:22 -0700 Subject: [PATCH 1/4] upgrade instruction builder --- src/instruction.rs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/instruction.rs b/src/instruction.rs index da5d501..a185ce0 100644 --- a/src/instruction.rs +++ b/src/instruction.rs @@ -10,7 +10,7 @@ use solana_program::{ use crate::{ impl_instruction_from_bytes, impl_to_bytes, BUS, BUS_ADDRESSES, CONFIG, CONFIG_ADDRESS, - METADATA, MINT, MINT_ADDRESS, MINT_NOISE, PROOF, TREASURY, TREASURY_ADDRESS, + METADATA, MINT, MINT_ADDRESS, MINT_NOISE, MINT_V1_ADDRESS, PROOF, TREASURY, TREASURY_ADDRESS, }; #[repr(u8)] @@ -358,6 +358,31 @@ pub fn stake(signer: Pubkey, sender: Pubkey, amount: u64) -> Instruction { } } +// build an upgrade instruction. +pub fn upgrade(signer: Pubkey, beneficiary: Pubkey, sender: Pubkey, amount: u64) -> Instruction { + Instruction { + program_id: crate::id(), + accounts: vec![ + AccountMeta::new(signer, true), + AccountMeta::new(beneficiary, false), + AccountMeta::new(MINT_ADDRESS, false), + AccountMeta::new(MINT_V1_ADDRESS, false), + AccountMeta::new(sender, false), + AccountMeta::new(TREASURY_ADDRESS, false), + AccountMeta::new_readonly(spl_token::id(), false), + ], + data: [ + OreInstruction::Upgrade.to_vec(), + UpgradeArgs { + amount: amount.to_le_bytes(), + } + .to_bytes() + .to_vec(), + ] + .concat(), + } +} + /// Builds an initialize instruction. pub fn initialize(signer: Pubkey) -> Instruction { let bus_pdas = [ From 583461e8d1d315d134eb61e10014888e1a0c5896 Mon Sep 17 00:00:00 2001 From: alex Date: Tue, 18 Jun 2024 22:08:13 -0700 Subject: [PATCH 2/4] instruction tries to borrow reference for an account which is already borrowed --- src/processor/upgrade.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/processor/upgrade.rs b/src/processor/upgrade.rs index 53930d1..e6aff30 100644 --- a/src/processor/upgrade.rs +++ b/src/processor/upgrade.rs @@ -61,8 +61,8 @@ pub fn process_upgrade<'a, 'info>( 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)?; + let mint_data = mint_info.data.clone(); + let mint = Mint::unpack(&mint_data.borrow())?; if mint.supply.saturating_add(amount_to_mint).gt(&MAX_SUPPLY) { return Err(OreError::MaxSupply.into()); } From 039c0a615029abf765606cda2dfaf5b399ad1778 Mon Sep 17 00:00:00 2001 From: alex Date: Wed, 19 Jun 2024 15:01:38 -0700 Subject: [PATCH 3/4] drop not borrow --- src/processor/upgrade.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/processor/upgrade.rs b/src/processor/upgrade.rs index 50fa0c3..acfe18d 100644 --- a/src/processor/upgrade.rs +++ b/src/processor/upgrade.rs @@ -61,8 +61,8 @@ pub fn process_upgrade<'a, 'info>( let amount_to_mint = amount.saturating_mul(100); // Cap at max supply. - let mint_data = mint_info.data.clone(); - let mint = Mint::unpack(&mint_data.borrow())?; + 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()); } From 8d560d255b3fb42e895324d821121dc44e96024b Mon Sep 17 00:00:00 2001 From: alex Date: Wed, 19 Jun 2024 16:44:10 -0700 Subject: [PATCH 4/4] v1 token decimals --- src/consts.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/consts.rs b/src/consts.rs index dbd6c0b..dfca525 100644 --- a/src/consts.rs +++ b/src/consts.rs @@ -15,6 +15,9 @@ pub const MIN_DIFFICULTY: u32 = 8; // 12; /// There are 100 billion indivisible units per Ore (called "grains"). pub const TOKEN_DECIMALS: u8 = 11; +/// The decimal precision of the Ore v1 token. +pub const TOKEN_DECIMALS_V1: u8 = 9; + /// One Ore token, denominated in indivisible units. pub const ONE_ORE: u64 = 10u64.pow(TOKEN_DECIMALS as u32);