-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/yral-dapp/hot-or-not-backen…
…d-canister into airdrop_amt_fix
- Loading branch information
Showing
18 changed files
with
398 additions
and
72 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
...anister/individual_user_template/src/api/cdao/upgrade_creator_dao_governance_canisters.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
use crate::{util::cycles::request_cycles_from_subnet_orchestrator, CANISTER_DATA}; | ||
use candid::Principal; | ||
use ic_cdk::api::management_canister::main::{ | ||
deposit_cycles, CanisterIdRecord, CanisterInstallMode, InstallCodeArgument, | ||
}; | ||
|
||
use ic_cdk_macros::update; | ||
use ic_sns_governance::{init::GovernanceCanisterInitPayloadBuilder, pb::v1::governance::Version}; | ||
|
||
use shared_utils::{ | ||
common::utils::{ | ||
permissions::is_caller_controller_or_global_admin, task::run_task_concurrently, | ||
upgrade_canister::upgrade_canister_util, | ||
}, | ||
constant::{ | ||
SNS_TOKEN_ARCHIVE_MODULE_HASH, SNS_TOKEN_GOVERNANCE_MODULE_HASH, | ||
SNS_TOKEN_INDEX_MODULE_HASH, SNS_TOKEN_LEDGER_MODULE_HASH, SNS_TOKEN_ROOT_MODULE_HASH, | ||
SNS_TOKEN_SWAP_MODULE_HASH, | ||
}, | ||
}; | ||
|
||
#[update(guard = "is_caller_controller_or_global_admin")] | ||
pub async fn upgrade_creator_dao_governance_canisters(wasm_module: Vec<u8>) -> Result<(), String> { | ||
let governance_canisters: Vec<candid::Principal> = | ||
CANISTER_DATA.with_borrow_mut(|canister_data| { | ||
canister_data | ||
.cdao_canisters | ||
.iter() | ||
.map(|canisters| canisters.governance) | ||
.collect() | ||
}); | ||
|
||
let recharge_amount = 100_000_000_000; | ||
|
||
let futures = governance_canisters | ||
.iter() | ||
.map(|governance_canister_id| async { | ||
let result = recharge_and_upgrade_canister( | ||
*governance_canister_id, | ||
wasm_module.clone(), | ||
recharge_amount, | ||
) | ||
.await; | ||
|
||
match result { | ||
Ok(()) => Ok(*governance_canister_id), | ||
Err(e) => Err((*governance_canister_id, e)), | ||
} | ||
}); | ||
|
||
run_task_concurrently( | ||
futures, | ||
10, | ||
|result| match result { | ||
Ok(canister_id) => ic_cdk::println!( | ||
"Governance canister {} upgraded Successfully", | ||
canister_id.to_text() | ||
), | ||
Err(e) => ic_cdk::println!( | ||
"Failed upgrading governance Canister {} . Error: {}", | ||
e.0, | ||
e.1 | ||
), | ||
}, | ||
|| false, | ||
) | ||
.await; | ||
|
||
Ok(()) | ||
} | ||
|
||
async fn recharge_and_upgrade_canister( | ||
canister_id: Principal, | ||
wasm_module: Vec<u8>, | ||
recharge_amount: u128, | ||
) -> Result<(), String> { | ||
//Add cycles in individual canister | ||
request_cycles_from_subnet_orchestrator(recharge_amount).await?; | ||
|
||
deposit_cycles(CanisterIdRecord { canister_id }, recharge_amount) | ||
.await | ||
.map_err(|e| e.1)?; | ||
|
||
let gov_hash = hex::decode(SNS_TOKEN_GOVERNANCE_MODULE_HASH).unwrap(); | ||
let ledger_hash = hex::decode(SNS_TOKEN_LEDGER_MODULE_HASH).unwrap(); | ||
let root_hash = hex::decode(SNS_TOKEN_ROOT_MODULE_HASH).unwrap(); | ||
let swap_hash = hex::decode(SNS_TOKEN_SWAP_MODULE_HASH).unwrap(); | ||
let index_hash = hex::decode(SNS_TOKEN_INDEX_MODULE_HASH).unwrap(); | ||
let archive_hash = hex::decode(SNS_TOKEN_ARCHIVE_MODULE_HASH).unwrap(); | ||
|
||
let mut governance_init_payload = GovernanceCanisterInitPayloadBuilder::new().build(); | ||
|
||
governance_init_payload.deployed_version = Some(Version { | ||
governance_wasm_hash: gov_hash, | ||
ledger_wasm_hash: ledger_hash, | ||
root_wasm_hash: root_hash, | ||
swap_wasm_hash: swap_hash, | ||
archive_wasm_hash: archive_hash, | ||
index_wasm_hash: index_hash, | ||
}); | ||
|
||
let upgrade_arg = candid::encode_one(governance_init_payload).map_err(|e| e.to_string())?; | ||
|
||
let install_code_argument = InstallCodeArgument { | ||
mode: CanisterInstallMode::Upgrade(None), | ||
canister_id, | ||
wasm_module, | ||
arg: upgrade_arg, | ||
}; | ||
|
||
upgrade_canister_util(install_code_argument) | ||
.await | ||
.map_err(|e| e.1) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...management/notify_all_individual_canisters_to_upgrade_creator_dao_governance_canisters.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use ic_cdk_macros::update; | ||
|
||
use crate::{guard::is_caller::is_caller_global_admin_or_controller, CANISTER_DATA}; | ||
|
||
#[update(guard = "is_caller_global_admin_or_controller")] | ||
pub fn notify_all_individual_canisters_to_upgrade_creator_dao_governance_canisters( | ||
wasm_module: Vec<u8>, | ||
) -> Result<(), String> { | ||
CANISTER_DATA.with_borrow(|canister_data| { | ||
let subnet_orchestrators = canister_data.all_subnet_orchestrator_canisters_list.iter(); | ||
|
||
for canister_id in subnet_orchestrators { | ||
ic_cdk::notify::<_>( | ||
*canister_id, | ||
"notify_all_individual_canisters_to_upgrade_creator_dao_governance_canisters", | ||
(wasm_module.clone(),), | ||
) | ||
.map_err(|e| format!("Error: {:?}", e))?; | ||
} | ||
|
||
Ok(()) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...management/notify_all_individual_canisters_to_upgrade_creator_dao_governance_canisters.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use candid::Principal; | ||
use ic_cdk_macros::update; | ||
use shared_utils::common::utils::permissions::is_caller_controller_or_global_admin; | ||
|
||
use crate::CANISTER_DATA; | ||
|
||
#[update(guard = "is_caller_controller_or_global_admin")] | ||
pub fn notify_all_individual_canisters_to_upgrade_creator_dao_governance_canisters( | ||
wasm_module: Vec<u8>, | ||
) -> Result<(), String> { | ||
CANISTER_DATA.with_borrow(|canister_data| { | ||
let individual_canisters = canister_data.user_principal_id_to_canister_id_map.iter(); | ||
|
||
for (_, canister_id) in individual_canisters { | ||
ic_cdk::notify::<_>( | ||
*canister_id, | ||
"upgrade_creator_dao_governance_canisters", | ||
(wasm_module.clone(),), | ||
) | ||
.map_err(|e| format!("Error: {:?}", e))?; | ||
} | ||
|
||
Ok(()) | ||
}) | ||
} |
16 changes: 16 additions & 0 deletions
16
...gement/notify_specific_individual_canister_to_upgrade_creator_dao_governance_canisters.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use candid::Principal; | ||
use ic_cdk_macros::update; | ||
use shared_utils::common::utils::permissions::{ | ||
is_caller_controller, is_caller_controller_or_global_admin, | ||
}; | ||
|
||
use crate::util::types::individual_user_canister::IndividualUserCanister; | ||
|
||
#[update(guard = "is_caller_controller_or_global_admin")] | ||
pub async fn notify_specific_individual_canister_to_upgrade_creator_dao_governance_canisters( | ||
individual_canister_id: Principal, | ||
wasm_module: Vec<u8>, | ||
) -> Result<(), String> { | ||
let individual_canister = IndividualUserCanister::new(individual_canister_id)?; | ||
individual_canister.notify_to_upgrade_creator_dao_governance_canisters(wasm_module) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.