Merge pull request #45 from regolith-labs/upgrade-ix

Upgrade Instruction Builder
This commit is contained in:
Hardhat Chad
2024-06-24 12:05:50 -05:00
committed by GitHub
2 changed files with 29 additions and 1 deletions

View File

@@ -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);

View File

@@ -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 = [