Skip to content

Commit

Permalink
Prepare release 4.4.0 (#1276)
Browse files Browse the repository at this point in the history
  • Loading branch information
vovac12 authored and ZlayaMorda committed Dec 4, 2024
1 parent 2ac5baf commit 1b566a3
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 10 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion node/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "framenode"
version = "4.3.2"
version = "4.4.0"
authors = ["Parity Technologies <[email protected]>"]
build = "build.rs"
edition = "2021"
Expand Down
2 changes: 1 addition & 1 deletion node/chain_spec/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "framenode-chain-spec"
version = "4.3.2"
version = "4.4.0"
authors = ["Parity Technologies <[email protected]>"]
edition = "2021"

Expand Down
4 changes: 2 additions & 2 deletions pallets/kensetsu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ pub struct CollateralRiskParameters {
}

/// Collateral parameters, includes risk info and additional data for interest rate calculation
#[derive(Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
#[derive(Debug, Encode, Decode, MaxEncodedLen, TypeInfo, PartialEq, Eq)]
pub struct CollateralInfo<Moment> {
/// Collateral Risk parameters set by risk management
pub risk_parameters: CollateralRiskParameters,
Expand Down Expand Up @@ -226,7 +226,7 @@ pub mod pallet {
pub type CdpId = u128;

/// The current storage version.
const STORAGE_VERSION: StorageVersion = StorageVersion::new(4);
const STORAGE_VERSION: StorageVersion = StorageVersion::new(5);

#[pallet::pallet]
#[pallet::generate_store(pub(super) trait Store)]
Expand Down
150 changes: 150 additions & 0 deletions pallets/kensetsu/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,3 +608,153 @@ pub mod v3_to_v4 {
}
}
}

/// Kensetsu version 5 replaces milliseconds to seconds in parameters
pub mod v4_to_v5 {
use crate::{CollateralInfos, Config, Pallet};
use core::marker::PhantomData;
use frame_support::dispatch::Weight;
use frame_support::traits::{GetStorageVersion, OnRuntimeUpgrade, StorageVersion};
use sp_core::Get;
use sp_runtime::traits::Saturating;
use sp_runtime::FixedU128;

pub struct UpgradeToV5<T>(PhantomData<T>);

impl<T: Config + pallet_timestamp::Config> OnRuntimeUpgrade for UpgradeToV5<T> {
fn on_runtime_upgrade() -> Weight {
if Pallet::<T>::on_chain_storage_version() == 4 {
let mut count = 0;

CollateralInfos::<T>::translate_values::<crate::CollateralInfo<T::Moment>, _>(
|mut value| {
value.risk_parameters.stability_fee_rate = value
.risk_parameters
.stability_fee_rate
.saturating_mul(FixedU128::from_u32(1000u32));
value.last_fee_update_time /= T::Moment::from(1000u32);
count += 1;
Some(value)
},
);

StorageVersion::new(5).put::<Pallet<T>>();
count += 1;

frame_support::log::info!("Migration to V5 applied");
T::DbWeight::get().reads_writes(count, count)
} else {
frame_support::log::info!("Migration to V5 already applied, skipping...");
T::DbWeight::get().reads(1)
}
}
}

#[cfg(test)]
mod tests {
use crate::migrations::v4_to_v5::UpgradeToV5;
use crate::mock::{new_test_ext, TestRuntime};
use crate::{
CollateralInfo, CollateralInfos, CollateralRiskParameters, Pallet,
StablecoinCollateralIdentifier,
};
use common::{balance, DAI, ETH, KUSD};
use frame_support::traits::{GetStorageVersion, OnRuntimeUpgrade, StorageVersion};
use sp_runtime::{FixedU128, Perbill};

#[test]
fn test() {
new_test_ext().execute_with(|| {
StorageVersion::new(4).put::<Pallet<TestRuntime>>();

CollateralInfos::<TestRuntime>::insert(
StablecoinCollateralIdentifier {
collateral_asset_id: DAI,
stablecoin_asset_id: KUSD,
},
CollateralInfo {
risk_parameters: CollateralRiskParameters {
hard_cap: balance!(1000),
liquidation_ratio: Perbill::from_rational(50u32, 100u32),
max_liquidation_lot: balance!(1),
stability_fee_rate: FixedU128::from_inner(123_456),
minimal_collateral_deposit: balance!(1),
},
total_collateral: balance!(10),
stablecoin_supply: balance!(20),
last_fee_update_time: 123_456_789,
interest_coefficient: FixedU128::from_u32(1),
},
);

CollateralInfos::<TestRuntime>::insert(
StablecoinCollateralIdentifier {
collateral_asset_id: ETH,
stablecoin_asset_id: KUSD,
},
CollateralInfo {
risk_parameters: CollateralRiskParameters {
hard_cap: balance!(10000),
liquidation_ratio: Perbill::from_rational(75u32, 100u32),
max_liquidation_lot: balance!(1),
stability_fee_rate: FixedU128::from_inner(123_456_789),
minimal_collateral_deposit: balance!(1),
},
total_collateral: balance!(1),
stablecoin_supply: balance!(30),
last_fee_update_time: 123_456,
interest_coefficient: FixedU128::from_u32(1),
},
);

UpgradeToV5::<TestRuntime>::on_runtime_upgrade();

assert_eq!(CollateralInfos::<TestRuntime>::iter().count(), 2);

assert_eq!(
CollateralInfos::<TestRuntime>::get(StablecoinCollateralIdentifier {
collateral_asset_id: DAI,
stablecoin_asset_id: KUSD,
})
.unwrap(),
CollateralInfo {
risk_parameters: CollateralRiskParameters {
hard_cap: balance!(1000),
liquidation_ratio: Perbill::from_rational(50u32, 100u32),
max_liquidation_lot: balance!(1),
stability_fee_rate: FixedU128::from_inner(123_456_000),
minimal_collateral_deposit: balance!(1),
},
total_collateral: balance!(10),
stablecoin_supply: balance!(20),
last_fee_update_time: 123_456,
interest_coefficient: FixedU128::from_u32(1),
},
);

assert_eq!(
CollateralInfos::<TestRuntime>::get(StablecoinCollateralIdentifier {
collateral_asset_id: ETH,
stablecoin_asset_id: KUSD,
})
.unwrap(),
CollateralInfo {
risk_parameters: CollateralRiskParameters {
hard_cap: balance!(10000),
liquidation_ratio: Perbill::from_rational(75u32, 100u32),
max_liquidation_lot: balance!(1),
stability_fee_rate: FixedU128::from_inner(123_456_789_000),
minimal_collateral_deposit: balance!(1),
},
total_collateral: balance!(1),
stablecoin_supply: balance!(30),
last_fee_update_time: 123,
interest_coefficient: FixedU128::from_u32(1),
},
);

assert_eq!(Pallet::<TestRuntime>::on_chain_storage_version(), 5);
});
}
}
}
2 changes: 1 addition & 1 deletion runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ license = "BSD-4-Clause"
homepage = "https://sora.org"
repository = "https://github.com/sora-xor/sora2-network"
name = "framenode-runtime"
version = "4.3.2"
version = "4.4.0"

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]
Expand Down
4 changes: 2 additions & 2 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,10 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("sora-substrate"),
impl_name: create_runtime_str!("sora-substrate"),
authoring_version: 1,
spec_version: 104,
spec_version: 105,
impl_version: 1,
apis: RUNTIME_API_VERSIONS,
transaction_version: 104,
transaction_version: 105,
state_version: 0,
};

Expand Down

0 comments on commit 1b566a3

Please sign in to comment.