From e83a6204472ad1abd276a90dd5489b8d296c4c9a Mon Sep 17 00:00:00 2001 From: P-Yevhenii <86720500+P-Yevhenii@users.noreply.github.com> Date: Wed, 5 Apr 2023 14:06:30 +0200 Subject: [PATCH] fix(pair configs): fix migration (#44) * Fix CL pair type migration: * remove the old key * save with a new key --- Cargo.lock | 8 ++++---- contracts/factory/src/migration.rs | 11 ++++++++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c2c8a9785..7967a2a3f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1288,9 +1288,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.140" +version = "0.2.141" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c" +checksum = "3304a64d199bb964be99741b7a14d26972741915b3649639149b2479bb46f4b5" [[package]] name = "libm" @@ -1632,9 +1632,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.37.6" +version = "0.37.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d097081ed288dfe45699b72f5b5d648e5f15d64d900c7080273baa20c16a6849" +checksum = "2aae838e49b3d63e9274e1c01833cc8139d3fec468c3b84688c628f44b1ae11d" dependencies = [ "bitflags", "errno", diff --git a/contracts/factory/src/migration.rs b/contracts/factory/src/migration.rs index 229b4dc9a..2eb620be6 100644 --- a/contracts/factory/src/migration.rs +++ b/contracts/factory/src/migration.rs @@ -78,7 +78,7 @@ pub fn migrate_pair_configs(storage: &mut dyn Storage) -> Result<(), StdError> { for key in keys { let old_pair_configs = OLD_PAIR_CONFIGS.load(storage, key.clone())?; - let pair_type = match old_pair_configs.pair_type { + let pair_type = match old_pair_configs.pair_type.clone() { OldPairType::Xyk {} => PairType::Xyk {}, OldPairType::Stable {} => PairType::Stable {}, OldPairType::Concentrated {} => PairType::Custom("concentrated".to_string()), @@ -87,14 +87,19 @@ pub fn migrate_pair_configs(storage: &mut dyn Storage) -> Result<(), StdError> { let pair_config = PairConfig { code_id: old_pair_configs.code_id, - pair_type, + pair_type: pair_type.clone(), total_fee_bps: old_pair_configs.total_fee_bps, maker_fee_bps: old_pair_configs.maker_fee_bps, is_disabled: old_pair_configs.is_disabled, is_generator_disabled: old_pair_configs.is_generator_disabled, }; - PAIR_CONFIGS.save(storage, key, &pair_config)?; + if key != pair_type.to_string() { + PAIR_CONFIGS.remove(storage, key); + PAIR_CONFIGS.save(storage, pair_type.to_string(), &pair_config)?; + } else { + PAIR_CONFIGS.save(storage, key, &pair_config)?; + } } Ok(())