Skip to content

Commit

Permalink
optimized traits in pallets
Browse files Browse the repository at this point in the history
  • Loading branch information
MJLNSN committed Jul 1, 2024
1 parent 776839e commit 114cba6
Show file tree
Hide file tree
Showing 34 changed files with 1,713 additions and 819 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"makefile.extensionOutputFolder": "./.vscode",
"rust-analyzer.cargo.features": "all"
"rust-analyzer.cargo.features": "all",
"rust-analyzer.checkOnSave": false
}
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.

2 changes: 2 additions & 0 deletions pallets/parachain-staking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ version = "3.0.1"
[dependencies]
log = { workspace = true }
serde = { workspace = true, features = ["derive"] }
#bifrost-primitives = { path = "../../primitives" }
bifrost-primitives = { workspace = true }

# Substrate
frame-benchmarking = { workspace = true, optional = true }
Expand Down
13 changes: 9 additions & 4 deletions pallets/parachain-staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@
mod delegation_requests;
pub mod inflation;
pub mod migrations;
pub mod traits;
// pub mod traits; // to be delleted
pub mod types;
pub mod weights;
//pub mod bifrost_primitives::parachain_staking;
// pub mod parachain_staking;

#[cfg(any(test, feature = "runtime-benchmarks"))]
mod benchmarks;
Expand All @@ -68,12 +70,14 @@ pub use delegation_requests::{CancelledScheduledRequest, DelegationAction, Sched
use frame_support::pallet;
pub use inflation::{InflationInfo, Range};
pub use pallet::*;
pub use traits::*;
// pub use traits::*; // to be delleted
pub use types::*;
use weights::WeightInfo;
pub use RoundIndex;
// pub use RoundIndex;
pub use pallet::RoundIndex;
pub type AccountIdOf<T> = <T as frame_system::Config>::AccountId;
use frame_support::pallet_prelude::DispatchResultWithPostInfo;
pub use bifrost_primitives::parachain_staking::*; //add

#[pallet]
pub mod pallet {
Expand All @@ -99,10 +103,11 @@ pub mod pallet {
use crate::{
delegation_requests::{CancelledScheduledRequest, DelegationAction, ScheduledRequest},
set::OrderedSet,
traits::*,
// traits::*,
types::*,
InflationInfo, Range, WeightInfo,
};
use bifrost_primitives::parachain_staking::*; // add

/// Pallet for parachain staking
#[pallet::pallet]
Expand Down
320 changes: 160 additions & 160 deletions pallets/parachain-staking/src/traits.rs
Original file line number Diff line number Diff line change
@@ -1,160 +1,160 @@
// Copyright 2019-2022 PureStake Inc.
// This file is part of Moonbeam.

// Moonbeam 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.

// Moonbeam 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 Moonbeam. If not, see <http://www.gnu.org/licenses/>.

//! traits for parachain-staking
use frame_support::pallet_prelude::{DispatchResultWithPostInfo, Weight};

pub trait OnCollatorPayout<AccountId, Balance> {
fn on_collator_payout(
for_round: crate::RoundIndex,
collator_id: AccountId,
amount: Balance,
) -> Weight;
}
impl<AccountId, Balance> OnCollatorPayout<AccountId, Balance> for () {
fn on_collator_payout(
_for_round: crate::RoundIndex,
_collator_id: AccountId,
_amount: Balance,
) -> Weight {
Weight::zero()
}
}

pub trait OnNewRound {
fn on_new_round(round_index: crate::RoundIndex) -> Weight;
}
impl OnNewRound for () {
fn on_new_round(_round_index: crate::RoundIndex) -> Weight {
Weight::zero()
}
}

pub trait ParachainStakingInterface<AccountId, Balance> {
fn delegate(
delegator: AccountId,
candidate: AccountId,
amount: Balance,
candidate_delegation_count: u32,
delegation_count: u32,
) -> DispatchResultWithPostInfo;

fn delegator_bond_more(
delegator: AccountId,
candidate: AccountId,
more: Balance,
) -> DispatchResultWithPostInfo;

fn schedule_delegator_bond_less(
delegator: AccountId,
candidate: AccountId,
less: Balance,
) -> DispatchResultWithPostInfo;

fn schedule_leave_delegators(delegator: AccountId) -> DispatchResultWithPostInfo;

fn cancel_delegation_request(
delegator: AccountId,
candidate: AccountId,
) -> DispatchResultWithPostInfo;

fn schedule_revoke_delegation(
delegator: AccountId,
collator: AccountId,
) -> DispatchResultWithPostInfo;

fn cancel_leave_delegators(delegator: AccountId) -> DispatchResultWithPostInfo;

fn execute_leave_delegators(
delegator: AccountId,
delegation_count: u32,
) -> DispatchResultWithPostInfo;

fn execute_delegation_request(
delegator: AccountId,
candidate: AccountId,
) -> DispatchResultWithPostInfo;

fn get_delegation_count(delegator: AccountId, candidate: AccountId) -> (u32, u32);
}

impl<AccountId, Balance> ParachainStakingInterface<AccountId, Balance> for () {
fn delegate(
_delegator: AccountId,
_candidate: AccountId,
_amount: Balance,
_candidate_delegation_count: u32,
_delegation_count: u32,
) -> DispatchResultWithPostInfo {
Ok(().into())
}

fn delegator_bond_more(
_delegator: AccountId,
_candidate: AccountId,
_more: Balance,
) -> DispatchResultWithPostInfo {
Ok(().into())
}

fn schedule_delegator_bond_less(
_delegator: AccountId,
_candidate: AccountId,
_less: Balance,
) -> DispatchResultWithPostInfo {
Ok(().into())
}

fn schedule_leave_delegators(_delegator: AccountId) -> DispatchResultWithPostInfo {
Ok(().into())
}

fn cancel_delegation_request(
_delegator: AccountId,
_candidate: AccountId,
) -> DispatchResultWithPostInfo {
Ok(().into())
}

fn schedule_revoke_delegation(
_delegator: AccountId,
_collator: AccountId,
) -> DispatchResultWithPostInfo {
Ok(().into())
}

fn cancel_leave_delegators(_delegator: AccountId) -> DispatchResultWithPostInfo {
Ok(().into())
}

fn execute_leave_delegators(
_delegator: AccountId,
_delegation_count: u32,
) -> DispatchResultWithPostInfo {
Ok(().into())
}

fn execute_delegation_request(
_delegator: AccountId,
_candidate: AccountId,
) -> DispatchResultWithPostInfo {
Ok(().into())
}

fn get_delegation_count(_delegator: AccountId, _candidate: AccountId) -> (u32, u32) {
(0, 0)
}
}
// // Copyright 2019-2022 PureStake Inc.
// // This file is part of Moonbeam.

// // Moonbeam 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.

// // Moonbeam 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 Moonbeam. If not, see <http://www.gnu.org/licenses/>.

// //! traits for parachain-staking
// use frame_support::pallet_prelude::{DispatchResultWithPostInfo, Weight};

// pub trait OnCollatorPayout<AccountId, Balance> {
// fn on_collator_payout(
// for_round: crate::RoundIndex,
// collator_id: AccountId,
// amount: Balance,
// ) -> Weight;
// }
// impl<AccountId, Balance> OnCollatorPayout<AccountId, Balance> for () {
// fn on_collator_payout(
// _for_round: crate::RoundIndex,
// _collator_id: AccountId,
// _amount: Balance,
// ) -> Weight {
// Weight::zero()
// }
// }

// pub trait OnNewRound {
// fn on_new_round(round_index: crate::RoundIndex) -> Weight;
// }
// impl OnNewRound for () {
// fn on_new_round(_round_index: crate::RoundIndex) -> Weight {
// Weight::zero()
// }
// }

// pub trait ParachainStakingInterface<AccountId, Balance> {
// fn delegate(
// delegator: AccountId,
// candidate: AccountId,
// amount: Balance,
// candidate_delegation_count: u32,
// delegation_count: u32,
// ) -> DispatchResultWithPostInfo;

// fn delegator_bond_more(
// delegator: AccountId,
// candidate: AccountId,
// more: Balance,
// ) -> DispatchResultWithPostInfo;

// fn schedule_delegator_bond_less(
// delegator: AccountId,
// candidate: AccountId,
// less: Balance,
// ) -> DispatchResultWithPostInfo;

// fn schedule_leave_delegators(delegator: AccountId) -> DispatchResultWithPostInfo;

// fn cancel_delegation_request(
// delegator: AccountId,
// candidate: AccountId,
// ) -> DispatchResultWithPostInfo;

// fn schedule_revoke_delegation(
// delegator: AccountId,
// collator: AccountId,
// ) -> DispatchResultWithPostInfo;

// fn cancel_leave_delegators(delegator: AccountId) -> DispatchResultWithPostInfo;

// fn execute_leave_delegators(
// delegator: AccountId,
// delegation_count: u32,
// ) -> DispatchResultWithPostInfo;

// fn execute_delegation_request(
// delegator: AccountId,
// candidate: AccountId,
// ) -> DispatchResultWithPostInfo;

// fn get_delegation_count(delegator: AccountId, candidate: AccountId) -> (u32, u32);
// }

// impl<AccountId, Balance> ParachainStakingInterface<AccountId, Balance> for () {
// fn delegate(
// _delegator: AccountId,
// _candidate: AccountId,
// _amount: Balance,
// _candidate_delegation_count: u32,
// _delegation_count: u32,
// ) -> DispatchResultWithPostInfo {
// Ok(().into())
// }

// fn delegator_bond_more(
// _delegator: AccountId,
// _candidate: AccountId,
// _more: Balance,
// ) -> DispatchResultWithPostInfo {
// Ok(().into())
// }

// fn schedule_delegator_bond_less(
// _delegator: AccountId,
// _candidate: AccountId,
// _less: Balance,
// ) -> DispatchResultWithPostInfo {
// Ok(().into())
// }

// fn schedule_leave_delegators(_delegator: AccountId) -> DispatchResultWithPostInfo {
// Ok(().into())
// }

// fn cancel_delegation_request(
// _delegator: AccountId,
// _candidate: AccountId,
// ) -> DispatchResultWithPostInfo {
// Ok(().into())
// }

// fn schedule_revoke_delegation(
// _delegator: AccountId,
// _collator: AccountId,
// ) -> DispatchResultWithPostInfo {
// Ok(().into())
// }

// fn cancel_leave_delegators(_delegator: AccountId) -> DispatchResultWithPostInfo {
// Ok(().into())
// }

// fn execute_leave_delegators(
// _delegator: AccountId,
// _delegation_count: u32,
// ) -> DispatchResultWithPostInfo {
// Ok(().into())
// }

// fn execute_delegation_request(
// _delegator: AccountId,
// _candidate: AccountId,
// ) -> DispatchResultWithPostInfo {
// Ok(().into())
// }

// fn get_delegation_count(_delegator: AccountId, _candidate: AccountId) -> (u32, u32) {
// (0, 0)
// }
// }
2 changes: 1 addition & 1 deletion pallets/salp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ pub mod pallet {
use bifrost_primitives::{
BancorHandler, CurrencyId, CurrencyId::VSBond, LeasePeriod, MessageId, Nonce, ParaId,
};
use bifrost_xcm_interface::traits::XcmHelper;
use bifrost_primitives::XcmHelper;
use frame_support::{
pallet_prelude::{storage::child, *},
sp_runtime::traits::{AccountIdConversion, CheckedAdd, Hash, Saturating, Zero},
Expand Down
Loading

0 comments on commit 114cba6

Please sign in to comment.