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 Jun 30, 2022
1 parent 98d76e4 commit 37dec5b
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 103 deletions.
6 changes: 6 additions & 0 deletions launch-script/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::str::FromStr;
use crate::prelude::*;

pub struct Configuration<'a> {
Expand All @@ -9,6 +10,8 @@ pub struct Configuration<'a> {
pub testing: bool,
pub start_time: NaiveDateTime,

pub maintenance_program_address: Pubkey,

pub startup_realm_config: RealmConfig,
pub working_realm_config: RealmConfig,
pub community_governance_config: GovernanceConfig,
Expand All @@ -34,6 +37,7 @@ impl<'a> Configuration<'a> {
verbose,
config.testing,
Some(config.start_time),
Pubkey::from_str(&config.maintenance_program).unwrap(),
)
}

Expand All @@ -44,6 +48,7 @@ impl<'a> Configuration<'a> {
verbose: bool,
testing: bool,
start_time: Option<NaiveDateTime>,
maintenance_pubkey: Pubkey,
) -> Self {
let account = |seed, program| wallet.account_by_seed(seed, program);
Self {
Expand All @@ -59,6 +64,7 @@ impl<'a> Configuration<'a> {
Utc::today().naive_utc().and_hms(0, 0, 0)
}
}),
maintenance_program_address: maintenance_pubkey,
startup_realm_config: RealmConfig {
council_token_mint: None,
community_voter_weight_addin: Some(wallet.fixed_weight_addin_id),
Expand Down
37 changes: 1 addition & 36 deletions launch-script/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,48 +295,13 @@ fn main() {
)
.subcommand(SubCommand::with_name("create-start-evm")
.about("Create proposal for Neon EVM start")
.arg(
Arg::with_name("collateral-pool-base")
.long("collateral-pool-base")
.required(true)
.takes_value(true)
.value_name("COLLATERAL_POOL_BASE")
.help("Collateral pool base")
)
.arg(
Arg::with_name("evm-loader")
.long("evm-loader")
.required(true)
.takes_value(true)
.value_name("EVM_LOADER_ADDRESS")
.help("EVM loader address")
)
)
.subcommand(SubCommand::with_name("create-evm-from-buffer")
.about("Deploy EVM from buffer")
.arg(
Arg::with_name("evm-loader")
.long("evm-loader")
.required(true)
.takes_value(true)
.value_name("EVM_LOADER_ADDRESS")
.help("EVM loader address")
)
.arg(
Arg::with_name("buffer")
.long("buffer")
.required(true)
.takes_value(true)
.value_name("PROGRAM_BUFFER")
.help("Program buffer")
)
.arg(
Arg::with_name("upgrade_authority")
.long("upgrade_authority")
.required(true)
.takes_value(true)
.value_name("UPGRADE_AUTHORITY")
.help("Upgrade authority")
.help("Program buffer to upgrade from")
)
)
.subcommand(SubCommand::with_name("sign-off")
Expand Down
19 changes: 6 additions & 13 deletions launch-script/src/proposals/create_treasury_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,27 @@

use crate::prelude::*;

pub fn create_collateral_pool_accounts(_wallet: &Wallet, _client: &Client,
transaction_inserter: &mut ProposalTransactionInserter,
cfg: &Configuration,
evm_loader_pubkey: Pubkey,
collateral_pool_base_pubkey: Pubkey,
) -> Result<(), ScriptError> {
pub fn create_collateral_pool_accounts(transaction_inserter: &mut ProposalTransactionInserter, cfg: &Configuration) -> Result<(), ScriptError> {

let mut seed: String = String::with_capacity(25);
let minimum_balance_for_rent_exemption = cfg.client.get_minimum_balance_for_rent_exemption(0).unwrap();

for index in 0u32..10 {
seed.push_str("collateral_seed_");
seed.push_str(index.to_string().as_str());
let seed: String = format!("collateral_seed_{}", index.to_string().as_str());
println!("\nCollateral Poool Seed: {}", seed);

let collateral_pool_account: Pubkey = Pubkey::create_with_seed(&collateral_pool_base_pubkey, &seed, &evm_loader_pubkey).unwrap();
let collateral_pool_account: Pubkey = Pubkey::create_with_seed(&cfg.maintenance_program_address, &seed, &cfg.wallet.neon_evm_program_id).unwrap();

transaction_inserter.insert_transaction_checked(
&format!("Create collateral pool account [{}] - {}", index, collateral_pool_account),
vec![
system_instruction::create_account_with_seed(
&collateral_pool_base_pubkey,
&cfg.maintenance_program_address,
&collateral_pool_account,
&collateral_pool_base_pubkey,
&cfg.maintenance_program_address,
seed.as_str(),
minimum_balance_for_rent_exemption,
0,
&evm_loader_pubkey,
&cfg.wallet.neon_evm_program_id,
).into(),
],
)?;
Expand Down
27 changes: 27 additions & 0 deletions launch-script/src/proposals/create_upgrade_evm.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// =========================================================================
// Deploy evm_loader from buffer account
// =========================================================================
use solana_sdk::{
bpf_loader_upgradeable,
};
use crate::prelude::*;

pub fn create_upgrade_evm(client: &Client,
transaction_inserter: &mut ProposalTransactionInserter,
cfg: &Configuration,
buffer_pubkey: Pubkey,
) -> Result<(), ScriptError> {

transaction_inserter.insert_transaction_checked(
&format!("Upgrade evm_loader from buffer at address {}", buffer_pubkey),
vec![
bpf_loader_upgradeable::upgrade(
&cfg.wallet.neon_evm_program_id,
&buffer_pubkey,
&cfg.maintenance_program_address,
&client.payer.pubkey(),
).into(),
],
)

}
44 changes: 0 additions & 44 deletions launch-script/src/proposals/deploy_evm_loader_from_buffer.rs

This file was deleted.

14 changes: 4 additions & 10 deletions launch-script/src/proposals/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mod proposal_vote_proposal;
mod set_mint_auth;
mod set_transfer_auth;
mod create_treasury_pool;
mod deploy_evm_loader_from_buffer;
mod create_upgrade_evm;

pub mod prelude {
pub use super::approve_proposal;
Expand All @@ -28,7 +28,7 @@ use proposal_vote_proposal::setup_proposal_vote_proposal;
use set_mint_auth::setup_set_mint_auth;
use set_transfer_auth::setup_set_transfer_auth;
use create_treasury_pool::create_collateral_pool_accounts;
use deploy_evm_loader_from_buffer::deploy_evm_loader_from_buffer;
use create_upgrade_evm::create_upgrade_evm;

pub enum ProposalInfo {
Create(String, String), // name, description
Expand Down Expand Up @@ -216,15 +216,9 @@ pub fn process_proposal_create(
)?
},
"create-start-evm" => {
let evm_loader: Pubkey = pubkey_of(cmd_matches, "evm-loader").unwrap();
let collateral_pool_base: Pubkey = pubkey_of(cmd_matches, "collateral-pool-base").unwrap();
create_collateral_pool_accounts(wallet, client, &mut transaction_inserter, cfg, evm_loader, collateral_pool_base)?
},
"create-evm-from-buffer" => {
let evm_loader: Pubkey = pubkey_of(cmd_matches, "evm-loader").unwrap();
let buffer_pubkey: Pubkey = pubkey_of(cmd_matches, "buffer").unwrap();
let upgrade_authority_pubkey: Pubkey = pubkey_of(cmd_matches, "upgrade_authority").unwrap();
deploy_evm_loader_from_buffer(wallet, client, &mut transaction_inserter, cfg, evm_loader, buffer_pubkey, upgrade_authority_pubkey)?
create_collateral_pool_accounts(&mut transaction_inserter, cfg)?;
create_upgrade_evm(client, &mut transaction_inserter, cfg, buffer_pubkey)?
},
_ => unreachable!(),
}
Expand Down

0 comments on commit 37dec5b

Please sign in to comment.