Skip to content

Commit

Permalink
add-lightening-redeem-to-bifrost (#347)
Browse files Browse the repository at this point in the history
* add-lightening-redeem-to-bifrost

* Update lib.rs

* Update lib.rs

Co-authored-by: Edwin <lark930@gmail.com>
  • Loading branch information
herryho and ark930 authored Oct 14, 2021
1 parent c95560b commit 583951c
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions runtime/bifrost/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ pallet-vesting = { package = "bifrost-vesting", path = "../../pallets/vesting",
bifrost-liquidity-mining = { path = "../../pallets/liquidity-mining", default-features = false }
bifrost-liquidity-mining-rpc-runtime-api = { path = "../../pallets/liquidity-mining/rpc/runtime-api", default-features = false }
bifrost-token-issuer = { path = "../../pallets/token-issuer", default-features = false }
bifrost-lightening-redeem= { path = "../../pallets/lightening-redeem", default-features = false }
xcm-support = { path = "../../xcm-support", default-features = false }

# orml
Expand Down Expand Up @@ -170,6 +171,7 @@ std = [
"bifrost-liquidity-mining/std",
"bifrost-liquidity-mining-rpc-runtime-api/std",
"bifrost-token-issuer/std",
"bifrost-lightening-redeem/std",
"zenlink-protocol/std",
"zenlink-protocol-runtime-api/std",
"xcm-support/std"
Expand Down Expand Up @@ -197,6 +199,7 @@ runtime-benchmarks = [
"bifrost-salp/runtime-benchmarks",
"bifrost-liquidity-mining/runtime-benchmarks",
"bifrost-token-issuer/runtime-benchmarks",
"bifrost-lightening-redeem/runtime-benchmarks",
]

try-runtime = [
Expand Down
16 changes: 15 additions & 1 deletion runtime/bifrost/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ parameter_types! {
pub const TreasuryPalletId: PalletId = PalletId(*b"bf/trsry");
pub const BifrostCrowdloanId: PalletId = PalletId(*b"bf/salp#");
pub const LiquidityMiningPalletId: PalletId = PalletId(*b"bf/lm###");
pub const LighteningRedeemPalletId: PalletId = PalletId(*b"bf/ltnrd");
}

impl frame_system::Config for Runtime {
Expand Down Expand Up @@ -921,7 +922,8 @@ impl Contains<AccountId> for DustRemovalWhitelist {
fn contains(a: &AccountId) -> bool {
AccountIdConversion::<AccountId>::into_account(&TreasuryPalletId::get()).eq(a) ||
AccountIdConversion::<AccountId>::into_account(&BifrostCrowdloanId::get()).eq(a) ||
LiquidityMiningPalletId::get().check_sub_account::<PoolId>(a)
AccountIdConversion::<AccountId>::into_account(&LighteningRedeemPalletId::get())
.eq(a) || LiquidityMiningPalletId::get().check_sub_account::<PoolId>(a)
}
}

Expand Down Expand Up @@ -1148,6 +1150,15 @@ impl bifrost_token_issuer::Config for Runtime {
type WeightInfo = weights::bifrost_token_issuer::WeightInfo<Runtime>;
}

impl bifrost_lightening_redeem::Config for Runtime {
type Event = Event;
type MultiCurrency = Tokens;
type ControlOrigin =
EnsureOneOf<AccountId, MoreThanHalfCouncil, EnsureRootOrAllTechnicalCommittee>;
type PalletId = LighteningRedeemPalletId;
type WeightInfo = weights::bifrost_lightening_redeem::WeightInfo<Runtime>;
}

// Bifrost modules end

// zenlink runtime start
Expand Down Expand Up @@ -1319,6 +1330,7 @@ construct_runtime! {
Salp: bifrost_salp::{Pallet, Call, Storage, Event<T>} = 105,
LiquidityMining: bifrost_liquidity_mining::{Pallet, Call, Storage, Event<T>} = 108,
TokenIssuer: bifrost_token_issuer::{Pallet, Call, Storage, Event<T>} = 109,
LighteningRedeem: bifrost_lightening_redeem::{Pallet, Call, Storage, Event<T>} = 110,
}
}

Expand Down Expand Up @@ -1565,6 +1577,7 @@ impl_runtime_apis! {
list_benchmark!(list, extra, bifrost_salp, Salp);
list_benchmark!(list, extra, bifrost_liquidity_mining, LiquidityMining);
list_benchmark!(list, extra, bifrost_token_issuer, TokenIssuer);
list_benchmark!(list, extra, bifrost_lightening_redeem, LighteningRedeem);

let storage_info = AllPalletsWithSystem::storage_info();

Expand Down Expand Up @@ -1599,6 +1612,7 @@ impl_runtime_apis! {
add_benchmark!(params, batches, bifrost_salp, Salp);
add_benchmark!(params, batches, bifrost_liquidity_mining, LiquidityMining);
add_benchmark!(params, batches, bifrost_token_issuer, TokenIssuer);
add_benchmark!(params, batches, bifrost_lightening_redeem, LighteningRedeem);

if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }
Ok(batches)
Expand Down
89 changes: 89 additions & 0 deletions runtime/bifrost/src/weights/bifrost_lightening_redeem.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// This file is part of Bifrost.

// Copyright (C) 2019-2021 Liebi Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

//! Autogenerated weights for `bifrost_lightening_redeem`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2021-10-09, STEPS: `50`, REPEAT: 1, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("asgard-local"), DB CACHE: 128
// Executed Command:
// target/release/bifrost
// benchmark
// --chain=asgard-local
// --steps=50
// --repeat=1
// --pallet=bifrost_lightening_redeem
// --extrinsic=*
// --execution=wasm
// --wasm-execution=compiled
// --heap-pages=4096
// --header=./HEADER-GPL3
// --output=./runtime/asgard/src/weights/bifrost_lightening_redeem.rs


#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unused_parens)]
#![allow(unused_imports)]

use frame_support::{traits::Get, weights::Weight};
use sp_std::marker::PhantomData;

/// Weight functions for bifrost_lightening_redeem.
pub struct WeightInfo<T>(PhantomData<T>);
impl<T: frame_system::Config> bifrost_lightening_redeem::WeightInfo for WeightInfo<T> {
// Storage: Tokens Accounts (r:2 w:2)
// Storage: System Account (r:1 w:1)
fn add_ksm_to_pool() -> Weight {
(89_467_000 as Weight)
.saturating_add(T::DbWeight::get().reads(3 as Weight))
.saturating_add(T::DbWeight::get().writes(3 as Weight))
}
// Storage: LighteningRedeem PoolAmount (r:1 w:1)
// Storage: LighteningRedeem ExchangePriceDiscount (r:1 w:0)
// Storage: Tokens Accounts (r:6 w:6)
// Storage: System Account (r:1 w:1)
fn exchange_for_ksm() -> Weight {
(189_565_000 as Weight)
.saturating_add(T::DbWeight::get().reads(9 as Weight))
.saturating_add(T::DbWeight::get().writes(8 as Weight))
}
// Storage: LighteningRedeem ExchangePriceDiscount (r:1 w:1)
fn edit_exchange_price() -> Weight {
(25_427_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
// Storage: LighteningRedeem TokenReleasePerDay (r:1 w:1)
fn edit_release_per_day() -> Weight {
(25_718_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
// Storage: LighteningRedeem StartEndReleaseBlock (r:1 w:1)
fn edit_release_start_and_end_block() -> Weight {
(25_608_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
// Storage: LighteningRedeem StartEndReleaseBlock (r:1 w:0)
fn on_initialize() -> Weight {
(5_009_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
}
}
1 change: 1 addition & 0 deletions runtime/bifrost/src/weights/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
//! A list of the different weight modules for our runtime.
pub mod bifrost_flexible_fee;
pub mod bifrost_lightening_redeem;
pub mod bifrost_liquidity_mining;
pub mod bifrost_salp;
pub mod bifrost_token_issuer;
Expand Down

0 comments on commit 583951c

Please sign in to comment.