|
1 |
| -use abstract_sdk::feature_objects::RegistryContract; |
2 |
| -use abstract_sdk::std::{account::state::ACCOUNT_ID, ACCOUNT}; |
3 |
| -use abstract_std::account::ModuleInstallConfig; |
4 |
| -use abstract_std::objects::module::ModuleInfo; |
| 1 | +use abstract_sdk::std::ACCOUNT; |
| 2 | +use abstract_std::account::MigrateMsg; |
5 | 3 | use abstract_std::objects::module_version::assert_contract_upgrade;
|
6 |
| -use abstract_std::{account::MigrateMsg, objects::AccountId}; |
7 |
| -use abstract_std::{ |
8 |
| - account::{ |
9 |
| - state::{AccountInfo, WhitelistedModules, INFO, SUSPENSION_STATUS, WHITELISTED_MODULES}, |
10 |
| - UpdateSubAccountAction, |
11 |
| - }, |
12 |
| - objects::{ |
13 |
| - gov_type::GovernanceDetails, |
14 |
| - ownership::{self}, |
15 |
| - }, |
16 |
| - registry::state::LOCAL_ACCOUNT_SEQUENCE, |
17 |
| -}; |
18 |
| -use abstract_std::{native_addrs, AbstractError, IBC_CLIENT}; |
19 |
| -use cosmwasm_std::{wasm_execute, DepsMut, Env}; |
| 4 | + |
| 5 | +use abstract_std::AbstractError; |
| 6 | +use cosmwasm_std::{DepsMut, Env}; |
20 | 7 | use cw2::{get_contract_version, set_contract_version};
|
21 | 8 | use semver::Version;
|
22 | 9 |
|
23 |
| -use crate::{ |
24 |
| - modules::{_install_modules, MIGRATE_CONTEXT}, |
25 |
| - msg::ExecuteMsg, |
26 |
| -}; |
27 |
| - |
28 | 10 | use crate::contract::{AccountResponse, AccountResult, CONTRACT_VERSION};
|
29 | 11 |
|
| 12 | +/// This migration function allows migrating from 2 types of contract |
| 13 | +/// - Previous Abstract Account version (This is the first part of the function) |
| 14 | +/// - XION Account, to allow upgrading their account to a more feature rich account (second part of the function) |
| 15 | +/// All other contracts cannot be migrated to this version |
30 | 16 | #[cfg_attr(feature = "export", cosmwasm_std::entry_point)]
|
31 |
| -pub fn migrate(mut deps: DepsMut, env: Env, _msg: MigrateMsg) -> AccountResult { |
| 17 | +pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> AccountResult { |
32 | 18 | let version: Version = CONTRACT_VERSION.parse().unwrap();
|
33 | 19 |
|
34 | 20 | let current_contract_version = get_contract_version(deps.storage)?;
|
35 | 21 | // If we already have an abstract account, we just migrate like normal
|
36 | 22 | if current_contract_version.contract == ACCOUNT {
|
37 | 23 | assert_contract_upgrade(deps.storage, ACCOUNT, version)?;
|
38 | 24 | set_contract_version(deps.storage, ACCOUNT, CONTRACT_VERSION)?;
|
39 |
| - return Ok(AccountResponse::action("migrate")); |
| 25 | + Ok(AccountResponse::action("migrate")) |
| 26 | + } else { |
| 27 | + #[cfg(feature = "xion")] |
| 28 | + { |
| 29 | + // We might want to migrate from a XION account |
| 30 | + migrate_from_xion_account(deps, _env, current_contract_version) |
| 31 | + } |
| 32 | + #[cfg(not(feature = "xion"))] |
| 33 | + { |
| 34 | + Err(AbstractError::ContractNameMismatch { |
| 35 | + from: current_contract_version.contract, |
| 36 | + to: ACCOUNT.to_string(), |
| 37 | + })? |
| 38 | + } |
40 | 39 | }
|
| 40 | +} |
| 41 | + |
| 42 | +#[cfg(feature = "xion")] |
| 43 | +pub fn migrate_from_xion_account( |
| 44 | + mut deps: DepsMut, |
| 45 | + env: Env, |
| 46 | + current_contract_version: cw2::ContractVersion, |
| 47 | +) -> AccountResult { |
| 48 | + use crate::{ |
| 49 | + modules::{_install_modules, MIGRATE_CONTEXT}, |
| 50 | + msg::ExecuteMsg, |
| 51 | + }; |
| 52 | + use ::{ |
| 53 | + abstract_sdk::feature_objects::RegistryContract, |
| 54 | + abstract_sdk::std::account::state::ACCOUNT_ID, |
| 55 | + abstract_std::account::ModuleInstallConfig, |
| 56 | + abstract_std::objects::module::ModuleInfo, |
| 57 | + abstract_std::objects::AccountId, |
| 58 | + abstract_std::{ |
| 59 | + account::{ |
| 60 | + state::{ |
| 61 | + AccountInfo, WhitelistedModules, INFO, SUSPENSION_STATUS, WHITELISTED_MODULES, |
| 62 | + }, |
| 63 | + UpdateSubAccountAction, |
| 64 | + }, |
| 65 | + objects::{ |
| 66 | + gov_type::GovernanceDetails, |
| 67 | + ownership::{self}, |
| 68 | + }, |
| 69 | + registry::state::LOCAL_ACCOUNT_SEQUENCE, |
| 70 | + }, |
| 71 | + abstract_std::{native_addrs, IBC_CLIENT}, |
| 72 | + cosmwasm_std::wasm_execute, |
| 73 | + }; |
41 | 74 |
|
42 |
| - // else this means that we are migrating from another contract, we assert it's `account` and create an abstract account |
43 | 75 | if current_contract_version.contract != "account" {
|
44 | 76 | Err(AbstractError::ContractNameMismatch {
|
45 | 77 | from: current_contract_version.contract,
|
46 | 78 | to: ACCOUNT.to_string(),
|
47 | 79 | })?;
|
48 | 80 | }
|
49 |
| - |
50 | 81 | // Use CW2 to set the contract version, this is needed for migrations
|
51 | 82 | set_contract_version(deps.storage, ACCOUNT, CONTRACT_VERSION)?;
|
52 | 83 |
|
|
0 commit comments