Skip to content

Commit

Permalink
Merge pull request #976 from gregdhill/chore/parachain-v1.23.1
Browse files Browse the repository at this point in the history
chore: increment spec versions to 1023001 and remove defi migrations
  • Loading branch information
sander2 authored Mar 21, 2023
2 parents 9cf3b68 + ae86316 commit 5ffe245
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 191 deletions.
6 changes: 1 addition & 5 deletions parachain/runtime/interlay/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("interlay-parachain"),
impl_name: create_runtime_str!("interlay-parachain"),
authoring_version: 1,
spec_version: 1023000,
spec_version: 1023001,
impl_version: 1,
transaction_version: 2, // added preimage
apis: RUNTIME_API_VERSIONS,
Expand Down Expand Up @@ -1257,10 +1257,6 @@ pub type Executive = frame_executive::Executive<
Runtime,
AllPalletsWithSystem,
(
// "Bound uses of call" <https://github.com/paritytech/substrate/pull/11649>
pallet_preimage::migration::v1::Migration<Runtime>,
pallet_scheduler::migration::v3::MigrateToV4<Runtime>,
pallet_multisig::migrations::v1::MigrateToV1<Runtime>,
reward::migration::v1::MigrateToV1<Runtime, EscrowRewardsInstance>,
vault_registry::migration::vault_capacity::RewardsMigration<
Runtime,
Expand Down
177 changes: 2 additions & 175 deletions parachain/runtime/kintsugi/src/dex.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
use super::{
parameter_types, Balance, CurrencyId, DexGeneral, DexStable, DispatchResult, Farming, Get, Loans, OnRuntimeUpgrade,
PalletId, Rate, Ratio, Runtime, RuntimeEvent, RuntimeOrigin, StablePoolId, Timestamp, Tokens, Vec, Weight, KBTC,
KINT, KSM,
parameter_types, Balance, CurrencyId, DexGeneral, DexStable, Get, PalletId, Runtime, RuntimeEvent, StablePoolId,
Timestamp, Tokens,
};
use sp_core::ConstU16;
use sp_runtime::{traits::Zero, FixedPointNumber};

#[cfg(feature = "try-runtime")]
use frame_support::ensure;

pub use dex_general::{AssetBalance, GenerateLpAssetId, PairInfo};
pub use dex_stable::traits::{StablePoolLpCurrencyIdGenerate, ValidateCurrency};
Expand Down Expand Up @@ -78,171 +73,3 @@ impl dex_swap_router::Config for Runtime {
type MaxSwaps = ConstU16<4>;
type WeightInfo = ();
}

pub struct DexSetup;

fn create_pair_and_update_rewards(asset_0: CurrencyId, asset_1: CurrencyId, rewards: Balance, fee_rate: Balance) {
if let Err(err) = DexGeneral::create_pair(RuntimeOrigin::root(), asset_0, asset_1, fee_rate) {
log::error!("Could not create pair: {:?}", err);
} else {
if let Err(err) = Farming::update_reward_schedule(
RuntimeOrigin::root(),
CurrencyId::join_lp_token(asset_0, asset_1).expect("currencies are valid; qed"),
CurrencyId::Token(KINT),
// period is 5 (blocks per minute)
// so period count for three months
// is 60 minutes * 24 hours * 92 days
132480,
rewards,
) {
log::error!("Could not update rewards: {:?}", err);
}
}
}

impl OnRuntimeUpgrade for DexSetup {
fn on_runtime_upgrade() -> Weight {
create_pair_and_update_rewards(
CurrencyId::Token(KBTC),
CurrencyId::Token(KSM),
45000000000000000, // 45,000 KINT
15, // 0.15%
);

create_pair_and_update_rewards(
CurrencyId::Token(KBTC),
CurrencyId::ForeignAsset(3), // USDT
40000000000000000, // 40,000 KINT
15, // 0.15%
);

create_pair_and_update_rewards(
CurrencyId::Token(KSM),
CurrencyId::Token(KINT),
35000000000000000, // 35,000 KINT
25, // 0.25%
);

Default::default()
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, &'static str> {
ensure!(
dex_general::PairStatuses::<Runtime>::iter().collect::<Vec<_>>().len() == 0,
"Should not have pools"
);
Ok(Vec::new())
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(_state: Vec<u8>) -> Result<(), &'static str> {
ensure!(
dex_general::PairStatuses::<Runtime>::iter().collect::<Vec<_>>().len() == 3,
"Should have pools"
);
Ok(())
}
}

pub struct LoansSetup;

fn add_and_activate_market(token: CurrencyId, market: loans::Market<Balance>) {
if let Err(err) = Loans::add_market(RuntimeOrigin::root(), token, market) {
log::error!("Could not add market: {:?}", err);
} else {
if let Err(err) = Loans::activate_market(RuntimeOrigin::root(), token) {
log::error!("Could not activate market: {:?}", err);
}
}
}

impl OnRuntimeUpgrade for LoansSetup {
fn on_runtime_upgrade() -> Weight {
add_and_activate_market(
CurrencyId::Token(KBTC),
loans::Market {
close_factor: Ratio::from_percent(50),
collateral_factor: Ratio::from_percent(63),
liquidation_threshold: Ratio::from_percent(67),
liquidate_incentive: Rate::from_inner(Rate::DIV / 100 * 110),
liquidate_incentive_reserved_factor: Ratio::zero(),
state: loans::MarketState::Pending,
rate_model: loans::InterestRateModel::Jump(loans::JumpModel {
base_rate: Rate::zero(),
jump_rate: Rate::from_inner(Rate::DIV / 100 * 5),
full_rate: Rate::from_inner(Rate::DIV / 100 * 50),
jump_utilization: Ratio::from_percent(90),
}),
reserve_factor: Ratio::from_percent(20),
supply_cap: 2000000000, // 20 KBTC
borrow_cap: 2000000000, // 20 KBTC
lend_token_id: CurrencyId::LendToken(1),
},
);

add_and_activate_market(
CurrencyId::Token(KSM),
loans::Market {
close_factor: Ratio::from_percent(50),
collateral_factor: Ratio::from_percent(54),
liquidation_threshold: Ratio::from_percent(61),
liquidate_incentive: Rate::from_inner(Rate::DIV / 100 * 110),
liquidate_incentive_reserved_factor: Ratio::zero(),
state: loans::MarketState::Pending,
rate_model: loans::InterestRateModel::Jump(loans::JumpModel {
base_rate: Rate::zero(),
jump_rate: Rate::from_inner(Rate::DIV / 100 * 15),
full_rate: Rate::from_inner(Rate::DIV / 100 * 40),
jump_utilization: Ratio::from_percent(90),
}),
reserve_factor: Ratio::from_percent(20),
supply_cap: 30000000000000000, // 30,000 KSM
borrow_cap: 30000000000000000, // 30,000 KSM
lend_token_id: CurrencyId::LendToken(2),
},
);

add_and_activate_market(
CurrencyId::ForeignAsset(3), // USDT
loans::Market {
close_factor: Ratio::from_percent(50),
collateral_factor: Ratio::from_percent(65),
liquidation_threshold: Ratio::from_percent(69),
liquidate_incentive: Rate::from_inner(Rate::DIV / 100 * 110),
liquidate_incentive_reserved_factor: Ratio::zero(),
state: loans::MarketState::Pending,
rate_model: loans::InterestRateModel::Jump(loans::JumpModel {
base_rate: Rate::zero(),
jump_rate: Rate::from_inner(Rate::DIV / 100 * 15),
full_rate: Rate::from_inner(Rate::DIV / 100 * 40),
jump_utilization: Ratio::from_percent(90),
}),
reserve_factor: Ratio::from_percent(20),
supply_cap: 800000000000, // 800,000 USDT
borrow_cap: 800000000000, // 800,000 USDT
lend_token_id: CurrencyId::LendToken(3),
},
);

Default::default()
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, &'static str> {
ensure!(
loans::Markets::<Runtime>::iter().collect::<Vec<_>>().len() == 0,
"Should not have markets"
);
Ok(Vec::new())
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(_state: Vec<u8>) -> Result<(), &'static str> {
ensure!(
loans::Markets::<Runtime>::iter().collect::<Vec<_>>().len() == 3,
"Should have markets"
);
Ok(())
}
}
12 changes: 3 additions & 9 deletions parachain/runtime/kintsugi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("kintsugi-parachain"),
impl_name: create_runtime_str!("kintsugi-parachain"),
authoring_version: 1,
spec_version: 1023000,
spec_version: 1023001,
impl_version: 1,
transaction_version: 3, // added preimage
apis: RUNTIME_API_VERSIONS,
Expand Down Expand Up @@ -1308,14 +1308,8 @@ pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, RuntimeCall,
/// Extrinsic type that has already been checked.
pub type CheckedExtrinsic = generic::CheckedExtrinsic<AccountId, RuntimeCall, SignedExtra>;
/// Executive: handles dispatch to the various modules.
pub type Executive = frame_executive::Executive<
Runtime,
Block,
frame_system::ChainContext<Runtime>,
Runtime,
AllPalletsWithSystem,
(dex::DexSetup, dex::LoansSetup),
>;
pub type Executive =
frame_executive::Executive<Runtime, Block, frame_system::ChainContext<Runtime>, Runtime, AllPalletsWithSystem>;

#[cfg(not(feature = "disable-runtime-api"))]
impl_runtime_apis! {
Expand Down
2 changes: 1 addition & 1 deletion parachain/runtime/testnet-interlay/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("testnet-interlay"),
impl_name: create_runtime_str!("testnet-interlay"),
authoring_version: 1,
spec_version: 1023000,
spec_version: 1023001,
impl_version: 1,
transaction_version: 1, // added preimage
apis: RUNTIME_API_VERSIONS,
Expand Down
2 changes: 1 addition & 1 deletion parachain/runtime/testnet-kintsugi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("testnet-kintsugi"),
impl_name: create_runtime_str!("testnet-kintsugi"),
authoring_version: 1,
spec_version: 1023000,
spec_version: 1023001,
impl_version: 1,
transaction_version: 1, // added preimage
apis: RUNTIME_API_VERSIONS,
Expand Down

0 comments on commit 5ffe245

Please sign in to comment.