From 1d20ed7772216a900ccb41845b1166aaf64482a5 Mon Sep 17 00:00:00 2001 From: alex Date: Tue, 18 Jun 2024 22:06:22 -0700 Subject: [PATCH] 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 = [