Skip to content

Commit

Permalink
#52 Implement create-start-evm Subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
mich-master committed Jul 14, 2022
1 parent 468d152 commit 437db89
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 113 deletions.
38 changes: 19 additions & 19 deletions governance-lib/src/proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ use {
std::fmt,
};

pub const COMPUTE_BUDGET_UNITS: u32 = 1_200_000;

#[derive(Debug)]
pub struct Proposal<'a> {
pub governance: &'a Governance<'a>,
Expand Down Expand Up @@ -157,14 +155,14 @@ impl<'a> Proposal<'a> {
)
}

pub fn execute_transactions(&self, option_index: u8) -> ClientResult<Vec<Signature>> {
pub fn execute_transactions(&self, option_index: u8, compute_budget_opt: Option<u32>) -> ClientResult<Vec<Signature>> {
let mut signatures = vec!();
let mut index = 0;

while let Some(proposal_transaction) = self.get_proposal_transaction_data(option_index, index)? {
if proposal_transaction.execution_status == TransactionExecutionStatus::None {
//println!("Execute proposal transaction: {} {} =====================", option_index, index);
signatures.push(self._execute_transaction(&proposal_transaction)?);
signatures.push(self._execute_transaction(&proposal_transaction,compute_budget_opt)?);
}
index += 1;
}
Expand All @@ -176,7 +174,7 @@ impl<'a> Proposal<'a> {
// self._execute_transaction(&proposal_transaction)
// }

fn _execute_transaction(&self, proposal_transaction: &ProposalTransactionV2) -> ClientResult<Signature> {
fn _execute_transaction(&self, proposal_transaction: &ProposalTransactionV2, compute_budget_opt: Option<u32>) -> ClientResult<Signature> {
//println!("Proposal transaction: {:?}", proposal_transaction);
let mut accounts = vec!();
for instruction in &proposal_transaction.instructions {
Expand All @@ -193,21 +191,23 @@ impl<'a> Proposal<'a> {
//println!("Proposal: {}", self.proposal_address);
//println!("Execute transaction with accounts {:?}", accounts);

self.governance.realm.client.send_and_confirm_transaction_with_payer_only(
&[
ComputeBudgetInstruction::set_compute_unit_limit(COMPUTE_BUDGET_UNITS),
execute_transaction(
&self.governance.realm.program_id,
&self.governance.governance_address,
&self.proposal_address,
&self.get_proposal_transaction_address(
proposal_transaction.option_index,
proposal_transaction.transaction_index),
&self.governance.governance_address, // Dummy account to call execute_transaction (bug in instruction.rs implementation)
&accounts,
),
]
let mut instructions: Vec<Instruction> = Vec::new();
if let Some(compute_budget) = compute_budget_opt {
instructions.push(ComputeBudgetInstruction::set_compute_unit_limit(compute_budget));
};
instructions.push(
execute_transaction(
&self.governance.realm.program_id,
&self.governance.governance_address,
&self.proposal_address,
&self.get_proposal_transaction_address(
proposal_transaction.option_index,
proposal_transaction.transaction_index),
&self.governance.governance_address, // Dummy account to call execute_transaction (bug in instruction.rs implementation)
&accounts,
)
);
self.governance.realm.client.send_and_confirm_transaction_with_payer_only(&instructions)
}

pub fn finalize_vote(&self, proposal_owner_record: &Pubkey) -> ClientResult<Signature> {
Expand Down
12 changes: 11 additions & 1 deletion launch-script/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,13 @@ fn main() {
)
.subcommand(SubCommand::with_name("execute")
.about("Execute proposal (after approve)")
.arg(
Arg::with_name("compute-units")
.long("compute-units")
.takes_value(true)
.value_name("COMPUTE_UNITS")
.help("Compute Budget Units")
)
)
).get_matches();

Expand Down Expand Up @@ -463,7 +470,10 @@ fn main() {
finalize_vote_proposal(&wallet, &client, &proposal, verbose).unwrap()
}
"execute" => {
execute_proposal(&wallet, &client, &proposal, verbose).unwrap()
let compute_budget_opt: Option<u32> = cmd_matches
.value_of("compute-units")
.and_then(|v| v.parse::<u32>().ok() );
execute_proposal(&wallet, &client, &proposal, compute_budget_opt, verbose).unwrap()
}
_ => unreachable!(),
}
Expand Down
48 changes: 0 additions & 48 deletions launch-script/src/proposals/create_treasury_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
// Create collateral pool accounts
// =========================================================================

// use solana_sdk::{
// signer::keypair::Keypair,
// system_instruction::create_account,
// };
use crate::prelude::*;

const TREASURY_POOL_ACCOUNT_COUNT: u32 = 10;
Expand All @@ -26,7 +22,6 @@ pub fn create_collateral_pool_accounts(wallet: &Wallet, client: &Client, transac

println!("Maintenance DAO Address: {:?}", maintenance_governance_pubkey);
println!("Maintenance Record Address: {:?}", maintenance_record_pubkey);
// println!("Proposal Governance Address: {:?}", transaction_inserter.proposal.governance.governance_address);


let minimum_balance_for_rent_exemption = cfg.client.get_minimum_balance_for_rent_exemption(0).unwrap();
Expand All @@ -37,38 +32,6 @@ pub fn create_collateral_pool_accounts(wallet: &Wallet, client: &Client, transac
verbose: transaction_inserter.verbose,
};

// let internal_payer: Keypair = Keypair::new();
// let internal_payer_pubkey: Pubkey = internal_payer.pubkey();
// println!("Internal Payer: {:?}", internal_payer_pubkey);

// // ----------- Check or create internal payer ----------------------
// executor.check_and_create_object(
// "Proposal Internal Payer",
// client.get_account(&internal_payer_pubkey)?,
// |_| {
// Ok(None)
// },
// || {
// let lamports: u64 = minimum_balance_for_rent_exemption * (TREASURY_POOL_ACCOUNT_COUNT as u64 + 1);
// let transaction = client.create_transaction(
// &[
// create_account(
// &client.payer.pubkey(), // from
// &internal_payer_pubkey, // to
// lamports, // lamports
// 0, // space
// &transaction_inserter.proposal.governance.governance_address, // owner
// ),
// ],
// &[
// &client.payer,
// &internal_payer,
// ]
// )?;
// Ok(Some(transaction))
// },
// )?;

for index in 0u32..TREASURY_POOL_ACCOUNT_COUNT {
let seed: String = format!("collateral_seed_{}", index.to_string().as_str());
println!("\nCollateral Poool Seed: {}", seed);
Expand Down Expand Up @@ -104,17 +67,6 @@ pub fn create_collateral_pool_accounts(wallet: &Wallet, client: &Client, transac
seed.as_str(),
&cfg.wallet.neon_evm_program_id,
).into(),
// system_instruction::create_account_with_seed(
// // &maintenance_governance_pubkey,
// &internal_payer_pubkey,
// &collateral_pool_account,
// &maintenance_governance_pubkey,
// seed.as_str(),
// // 0,
// minimum_balance_for_rent_exemption,
// 0,
// &cfg.wallet.neon_evm_program_id,
// ).into(),
],
)?;
}
Expand Down
46 changes: 16 additions & 30 deletions launch-script/src/proposals/create_upgrade_evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,6 @@ pub fn create_upgrade_evm(wallet: &Wallet, client: &Client,
verbose: transaction_inserter.verbose,
};

// executor.check_and_create_object(
// "EVM loader",
// client.get_account(&wallet.neon_evm_program_id)?,
// |evm_loader_account| {
// let (maintenance_record_pubkey,_): (Pubkey,u8) =
// println!("Address: {:?}", get_maintenance_record_address(&wallet.maintenance_program_id, &wallet.neon_evm_program_id));
// if evm_loader_account.owner != maintenance_record_pubkey {
// return Err( StateError::WrongEvmLoaderAccountOwner(evm_loader_account.owner).into() );
// }
// Ok(None)
// },
// || Err( StateError::MissingEvmLoader(wallet.neon_evm_program_id).into() ),
// )?;

let upgrade_authority_opt = client.get_program_upgrade_authority(&wallet.neon_evm_program_id)?;
executor.check_and_create_object(
&format!("EVM loader upgrade authority: {:?}", upgrade_authority_opt),
Expand All @@ -86,28 +72,28 @@ pub fn create_upgrade_evm(wallet: &Wallet, client: &Client,
let elf = Elf::parse(program_data).expect("Can't parse Elf data");
let elf_params = parse_elf_params(elf, program_data);

println!("elf_params: {:?}", elf_params);
// if elf_params.get("NEON_TOKEN_MINT")
// .and_then(|value| Pubkey::from_str(value.as_str()).ok() )
// .map(|neon_mint| {
// println!("neon_mint: {:?}", neon_mint);
// neon_mint != wallet.community_pubkey
// })
// .unwrap_or(true) {
// return Err( StateError::InvalidNeonMint.into() );
// }
// println!("elf_params: {:?}", elf_params);
if elf_params.get("NEON_TOKEN_MINT")
.and_then(|value| Pubkey::from_str(value.as_str()).ok() )
.map(|neon_mint| {
println!("neon_mint: {:?}", neon_mint);
neon_mint != wallet.community_pubkey
})
.unwrap_or(true) {
return Err( StateError::InvalidNeonMint.into() );
}
if elf_params.get("NEON_TOKEN_MINT_DECIMALS")
.and_then(|value| value.parse().ok() )
.map(|decimals: u32| decimals != 9 )
.unwrap_or(true) {
return Err( StateError::WrongNeonDecimals.into() );
}
// if elf_params.get("NEON_POOL_BASE")
// .and_then(|value| Pubkey::from_str(value.as_str()).ok() )
// .map(|neon_pool_base| neon_pool_base != wallet.maintenance_program_id )
// .unwrap_or(true) {
// return Err( StateError::InvalidPoolBase.into() );
// }
if elf_params.get("NEON_POOL_BASE")
.and_then(|value| Pubkey::from_str(value.as_str()).ok() )
.map(|neon_pool_base| neon_pool_base != wallet.maintenance_program_id )
.unwrap_or(true) {
return Err( StateError::InvalidPoolBase.into() );
}
if elf_params.get("NEON_CHAIN_ID")
.and_then(|value| value.parse().ok() )
.map(|chain_id: u64| chain_id != cfg.chain_id )
Expand Down
3 changes: 2 additions & 1 deletion launch-script/src/proposals/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,10 @@ pub fn execute_proposal(
_wallet: &Wallet,
_client: &Client,
proposal: &Proposal,
compute_budget_opt: Option<u32>,
_verbose: bool,
) -> Result<(), ScriptError> {
let result = proposal.execute_transactions(0)?;
let result = proposal.execute_transactions(0,compute_budget_opt)?;
println!("Execute transactions from proposal option 0: {:?}", result);

Ok(())
Expand Down
26 changes: 13 additions & 13 deletions run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ launch-script --config testing.cfg --send-trx proposal --governance MSIG_5.$DELE
sleep 5
launch-script --config testing.cfg --send-trx proposal --governance MSIG_5.$DELEGATED_BALANCE --proposal LAST execute

# # Stage 1: Preparing Token Genesis Event and switch to vesting-addin
# launch-script --config testing.cfg --send-trx proposal --name 'Token Genesis Event' create-tge
# launch-script --config testing.cfg --send-trx proposal --proposal LAST sign-off
# launch-script --config testing.cfg --send-trx proposal --proposal LAST approve --voters artifacts/voters/
# sleep 185
# launch-script --config testing.cfg --send-trx proposal --proposal LAST finalize-vote
# sleep 65
# launch-script --config testing.cfg --send-trx proposal --proposal LAST execute

solana program deploy -v --keypair artifacts/payer.keypair --upgrade-authority artifacts/creator.keypair --program-id artifacts/neon-evm.keypair deploy/evm_loader.so

solana program write-buffer -v --keypair artifacts/payer.keypair --buffer artifacts/buffer.keypair deploy/evm_loader.so
# Stage 1: Preparing Token Genesis Event and switch to vesting-addin
launch-script --config testing.cfg --send-trx proposal --name 'Token Genesis Event' create-tge
launch-script --config testing.cfg --send-trx proposal --proposal LAST sign-off
launch-script --config testing.cfg --send-trx proposal --proposal LAST approve --voters artifacts/voters/
sleep 185
launch-script --config testing.cfg --send-trx proposal --proposal LAST finalize-vote
sleep 65
launch-script --config testing.cfg --send-trx proposal --proposal LAST execute

solana program deploy -v --keypair artifacts/payer.keypair --upgrade-authority artifacts/creator.keypair --program-id artifacts/neon-evm.keypair deploy/evm_loader-govertest.so

solana program write-buffer -v --keypair artifacts/payer.keypair --buffer artifacts/buffer.keypair deploy/evm_loader-govertest.so
solana program set-buffer-authority -v --buffer-authority artifacts/payer.keypair artifacts/buffer.keypair --new-buffer-authority $MAINTENANCE_RECORD_ADDRESS

launch-script --config testing.cfg --send-trx environment evm
Expand All @@ -52,4 +52,4 @@ launch-script --config testing.cfg --send-trx proposal --governance MAINTENANCE
sleep 185
launch-script --config testing.cfg --send-trx proposal --governance MAINTENANCE --proposal LAST finalize-vote
sleep 65
launch-script --config testing.cfg --send-trx proposal --governance MAINTENANCE --proposal LAST execute
launch-script --config testing.cfg --send-trx proposal --governance MAINTENANCE --proposal LAST execute --compute-units 1200000
2 changes: 1 addition & 1 deletion testing.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"vesting-addin": "5tgpCGfXYaZhKWJsrNR4zyp4o4n3wSQ81i5MzPqKEeAK",
"neon-evm-program": "DCPSnJHB38e7vNK6o3AVLswJGRaP87iiNx2zvvapiKBz",
"maintenance-program": "7aPH9mBAvUtJDGV2L1KyvpR5nKF7man5DZzBPaxmisg5",
"executables-paths": ["deploy/evm_loader.so"],
"executables-paths": ["deploy/evm_loader-govertest.so"],
"delegates": ["CVAimMqtcmSUCV4RLZSJAreDpEd7JEZmrvCVj85yaRzZ"],
"chain-id": 111,
"start-time": "2022-06-21T00:00:00",
Expand Down

0 comments on commit 437db89

Please sign in to comment.