From 114cba6e04c7de6615bffe2b5c81e9af5bfe3b23 Mon Sep 17 00:00:00 2001 From: Gemma Date: Tue, 2 Jul 2024 01:30:56 +0800 Subject: [PATCH] optimized traits in pallets --- .vscode/settings.json | 3 +- Cargo.lock | 1 + pallets/parachain-staking/Cargo.toml | 2 + pallets/parachain-staking/src/lib.rs | 13 +- pallets/parachain-staking/src/traits.rs | 320 +++++------ pallets/salp/src/lib.rs | 2 +- pallets/slp/Cargo.toml | 1 + pallets/slp/src/agents/astar_agent/agent.rs | 3 +- pallets/slp/src/agents/common.rs | 4 +- .../slp/src/agents/filecoin_agent/agent.rs | 5 +- .../agents/parachain_staking_agent/agent.rs | 4 +- pallets/slp/src/agents/phala_agent/agent.rs | 4 +- .../slp/src/agents/polkadot_agent/agent.rs | 4 +- pallets/slp/src/agents/utils.rs | 3 +- pallets/slp/src/lib.rs | 3 +- pallets/slp/src/traits.rs | 506 +++++++++--------- pallets/stable-pool/src/traits.rs | 311 +++++------ pallets/ve-minting/src/lib.rs | 1 + pallets/vtoken-minting/src/lib.rs | 4 +- pallets/vtoken-minting/src/traits.rs | 122 ++--- pallets/xcm-interface/src/lib.rs | 8 +- pallets/xcm-interface/src/traits.rs | 318 +++++------ primitives/src/lib.rs | 52 +- primitives/src/salp.rs | 1 + primitives/src/traits/mod.rs | 18 + primitives/src/traits/parachain_staking.rs | 160 ++++++ primitives/src/traits/slp.rs | 250 +++++++++ primitives/src/traits/stable_pool.rs | 89 +++ primitives/src/{ => traits}/traits.rs | 8 +- primitives/src/traits/ve_minting.rs | 107 ++++ primitives/src/traits/vtoken_minting.rs | 53 ++ primitives/src/traits/xcm_interface.rs | 148 +++++ runtime/bifrost-kusama/src/xcm_config.rs | 2 +- runtime/bifrost-polkadot/src/xcm_config.rs | 2 +- 34 files changed, 1713 insertions(+), 819 deletions(-) create mode 100644 primitives/src/traits/mod.rs create mode 100644 primitives/src/traits/parachain_staking.rs create mode 100644 primitives/src/traits/slp.rs create mode 100644 primitives/src/traits/stable_pool.rs rename primitives/src/{ => traits}/traits.rs (98%) create mode 100644 primitives/src/traits/ve_minting.rs create mode 100644 primitives/src/traits/vtoken_minting.rs create mode 100644 primitives/src/traits/xcm_interface.rs diff --git a/.vscode/settings.json b/.vscode/settings.json index d9adcb335..69fcc8aba 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,5 @@ { "makefile.extensionOutputFolder": "./.vscode", - "rust-analyzer.cargo.features": "all" + "rust-analyzer.cargo.features": "all", + "rust-analyzer.checkOnSave": false } \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index f8c3b0b04..769d949cb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1201,6 +1201,7 @@ dependencies = [ name = "bifrost-parachain-staking" version = "3.0.1" dependencies = [ + "bifrost-primitives", "frame-benchmarking", "frame-support", "frame-system", diff --git a/pallets/parachain-staking/Cargo.toml b/pallets/parachain-staking/Cargo.toml index c3e5089c3..9d5f977ab 100644 --- a/pallets/parachain-staking/Cargo.toml +++ b/pallets/parachain-staking/Cargo.toml @@ -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 } diff --git a/pallets/parachain-staking/src/lib.rs b/pallets/parachain-staking/src/lib.rs index aaa077312..05bfd2985 100755 --- a/pallets/parachain-staking/src/lib.rs +++ b/pallets/parachain-staking/src/lib.rs @@ -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; @@ -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 = ::AccountId; use frame_support::pallet_prelude::DispatchResultWithPostInfo; +pub use bifrost_primitives::parachain_staking::*; //add #[pallet] pub mod pallet { @@ -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] diff --git a/pallets/parachain-staking/src/traits.rs b/pallets/parachain-staking/src/traits.rs index 3107ab745..f80cb1dc2 100644 --- a/pallets/parachain-staking/src/traits.rs +++ b/pallets/parachain-staking/src/traits.rs @@ -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 . - -//! traits for parachain-staking -use frame_support::pallet_prelude::{DispatchResultWithPostInfo, Weight}; - -pub trait OnCollatorPayout { - fn on_collator_payout( - for_round: crate::RoundIndex, - collator_id: AccountId, - amount: Balance, - ) -> Weight; -} -impl OnCollatorPayout 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 { - 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 ParachainStakingInterface 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 . + +// //! traits for parachain-staking +// use frame_support::pallet_prelude::{DispatchResultWithPostInfo, Weight}; + +// pub trait OnCollatorPayout { +// fn on_collator_payout( +// for_round: crate::RoundIndex, +// collator_id: AccountId, +// amount: Balance, +// ) -> Weight; +// } +// impl OnCollatorPayout 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 { +// 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 ParachainStakingInterface 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) +// } +// } diff --git a/pallets/salp/src/lib.rs b/pallets/salp/src/lib.rs index 82a9749e2..5f22d5914 100644 --- a/pallets/salp/src/lib.rs +++ b/pallets/salp/src/lib.rs @@ -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}, diff --git a/pallets/slp/Cargo.toml b/pallets/slp/Cargo.toml index d07ad9dbf..486e63542 100644 --- a/pallets/slp/Cargo.toml +++ b/pallets/slp/Cargo.toml @@ -34,6 +34,7 @@ bifrost-asset-registry = { workspace = true } bifrost-parachain-staking = { workspace = true } bifrost-stable-pool = { workspace = true } bifrost-stable-asset = { workspace = true } +# bifrost-primitives = { workspace = true } [dev-dependencies] hex = "0.4.3" diff --git a/pallets/slp/src/agents/astar_agent/agent.rs b/pallets/slp/src/agents/astar_agent/agent.rs index ea0a27692..49d0ae6f5 100644 --- a/pallets/slp/src/agents/astar_agent/agent.rs +++ b/pallets/slp/src/agents/astar_agent/agent.rs @@ -23,11 +23,12 @@ use crate::{ Ledger, QueryId, SubstrateLedger, SubstrateLedgerUpdateEntry, SubstrateLedgerUpdateOperation, UnlockChunk, ValidatorsByDelegatorUpdateEntry, }, - traits::{QueryResponseManager, StakingAgent}, + // traits::{QueryResponseManager, StakingAgent}, AccountIdOf, BalanceOf, Config, DelegatorLedgerXcmUpdateQueue, DelegatorLedgers, DelegatorsMultilocation2Index, LedgerUpdateEntry, MinimumsAndMaximums, Pallet, TimeUnit, Validators, }; +use bifrost_primitives::{QueryResponseManager, StakingAgent}; use bifrost_primitives::{CurrencyId, VtokenMintingOperator, XcmOperationType, ASTR_TOKEN_ID}; use core::marker::PhantomData; use frame_support::{ensure, traits::Get}; diff --git a/pallets/slp/src/agents/common.rs b/pallets/slp/src/agents/common.rs index 021bb5b80..ea8cf350d 100644 --- a/pallets/slp/src/agents/common.rs +++ b/pallets/slp/src/agents/common.rs @@ -20,7 +20,7 @@ use crate::{ primitives::{ ParachainStakingLedgerUpdateEntry, ParachainStakingLedgerUpdateOperation, TIMEOUT_BLOCKS, }, - traits::QueryResponseManager, + // traits::QueryResponseManager, vec, AccountIdOf, BalanceOf, BlockNumberFor, BoundedVec, Config, CurrencyDelays, DelegationsOccupied, DelegatorLatestTuneRecord, DelegatorLedgerXcmUpdateQueue, DelegatorLedgers, DelegatorNextIndex, DelegatorsIndex2Multilocation, @@ -28,7 +28,7 @@ use crate::{ MinimumsAndMaximums, Pallet, TimeUnit, Validators, Vec, Weight, XcmOperationType, Zero, ASTR, BNC, DOT, GLMR, KSM, MANTA, MOVR, PHA, }; -use bifrost_primitives::{CurrencyId, VtokenMintingOperator, XcmDestWeightAndFeeHandler}; +use bifrost_primitives::{CurrencyId, VtokenMintingOperator, XcmDestWeightAndFeeHandler, QueryResponseManager}; use frame_support::{dispatch::GetDispatchInfo, ensure, traits::Len}; use orml_traits::{MultiCurrency, XcmTransfer}; use polkadot_parachain_primitives::primitives::Sibling; diff --git a/pallets/slp/src/agents/filecoin_agent/agent.rs b/pallets/slp/src/agents/filecoin_agent/agent.rs index f1a69b595..e74d5f5ae 100644 --- a/pallets/slp/src/agents/filecoin_agent/agent.rs +++ b/pallets/slp/src/agents/filecoin_agent/agent.rs @@ -18,12 +18,13 @@ use crate::{ pallet::{Error, Event}, primitives::{FilecoinLedger, Ledger}, - traits::StakingAgent, + // traits::StakingAgent, AccountIdOf, BalanceOf, BoundedVec, Config, DelegatorLatestTuneRecord, DelegatorLedgers, LedgerUpdateEntry, MinimumsAndMaximums, Pallet, TimeUnit, Validators, ValidatorsByDelegator, ValidatorsByDelegatorUpdateEntry, }; -use bifrost_primitives::{CurrencyId, VtokenMintingOperator}; +// use bifrost_primitives::StakingAgent; +use bifrost_primitives::{StakingAgent, CurrencyId, VtokenMintingOperator}; use core::marker::PhantomData; use frame_support::ensure; use orml_traits::MultiCurrency; diff --git a/pallets/slp/src/agents/parachain_staking_agent/agent.rs b/pallets/slp/src/agents/parachain_staking_agent/agent.rs index 54c265c3e..af80a1a7d 100644 --- a/pallets/slp/src/agents/parachain_staking_agent/agent.rs +++ b/pallets/slp/src/agents/parachain_staking_agent/agent.rs @@ -27,7 +27,7 @@ use crate::{ OneToManyScheduledRequest, ParachainStakingLedgerUpdateEntry, ParachainStakingLedgerUpdateOperation, QueryId, }, - traits::{QueryResponseManager, StakingAgent}, + // traits::{QueryResponseManager, StakingAgent}, AccountIdOf, BalanceOf, Config, DelegatorLedgerXcmUpdateQueue, DelegatorLedgers, DelegatorsMultilocation2Index, LedgerUpdateEntry, MinimumsAndMaximums, Pallet, TimeUnit, Validators, ValidatorsByDelegatorUpdateEntry, BNC, @@ -36,6 +36,8 @@ use bifrost_parachain_staking::ParachainStakingInterface; use bifrost_primitives::{ currency::{GLMR, MANTA, MOVR}, CurrencyId, VtokenMintingOperator, XcmOperationType, + QueryResponseManager, + StakingAgent }; use core::marker::PhantomData; use frame_support::{ensure, traits::Get}; diff --git a/pallets/slp/src/agents/phala_agent/agent.rs b/pallets/slp/src/agents/phala_agent/agent.rs index f6494fa41..86c60789f 100644 --- a/pallets/slp/src/agents/phala_agent/agent.rs +++ b/pallets/slp/src/agents/phala_agent/agent.rs @@ -23,12 +23,12 @@ use crate::{ primitives::{ Ledger, PhalaLedger, QueryId, SubstrateLedgerUpdateEntry, SubstrateLedgerUpdateOperation, }, - traits::{QueryResponseManager, StakingAgent}, + // traits::{QueryResponseManager, StakingAgent}, AccountIdOf, BalanceOf, Config, CurrencyId, DelegatorLedgerXcmUpdateQueue, DelegatorLedgers, DelegatorsMultilocation2Index, Hash, LedgerUpdateEntry, MinimumsAndMaximums, Pallet, TimeUnit, Validators, ValidatorsByDelegatorUpdateEntry, }; -use bifrost_primitives::{TokenSymbol, VtokenMintingOperator, XcmOperationType}; +use bifrost_primitives::{TokenSymbol, VtokenMintingOperator, XcmOperationType,QueryResponseManager, StakingAgent}; use core::marker::PhantomData; use frame_support::{ensure, traits::Get}; use frame_system::pallet_prelude::BlockNumberFor; diff --git a/pallets/slp/src/agents/polkadot_agent/agent.rs b/pallets/slp/src/agents/polkadot_agent/agent.rs index 3b6eff0e1..5a29b35b1 100644 --- a/pallets/slp/src/agents/polkadot_agent/agent.rs +++ b/pallets/slp/src/agents/polkadot_agent/agent.rs @@ -24,14 +24,14 @@ use crate::{ SubstrateLedgerUpdateOperation, SubstrateValidatorsByDelegatorUpdateEntry, UnlockChunk, ValidatorsByDelegatorUpdateEntry, }, - traits::{QueryResponseManager, StakingAgent}, + // traits::{QueryResponseManager, StakingAgent}, AccountIdOf, BalanceOf, BoundedVec, Config, DelegatorLedgerXcmUpdateQueue, DelegatorLedgers, DelegatorsMultilocation2Index, LedgerUpdateEntry, MinimumsAndMaximums, Pallet, TimeUnit, ValidatorsByDelegator, ValidatorsByDelegatorXcmUpdateQueue, }; use bifrost_primitives::{ currency::KSM, CurrencyId, VtokenMintingOperator, XcmDestWeightAndFeeHandler, XcmOperationType, - DOT, + DOT, QueryResponseManager, StakingAgent }; use core::marker::PhantomData; use frame_support::{ensure, traits::Get}; diff --git a/pallets/slp/src/agents/utils.rs b/pallets/slp/src/agents/utils.rs index 228d362f4..a8eef06b6 100644 --- a/pallets/slp/src/agents/utils.rs +++ b/pallets/slp/src/agents/utils.rs @@ -21,7 +21,8 @@ use crate::{ KSM, MANTA, MOVR, PHA, }; use bifrost_primitives::CurrencyId; -use bifrost_xcm_interface::traits::parachains; +// use bifrost_xcm_interface::traits::parachains; +use bifrost_primitives::parachains; use frame_support::ensure; use parity_scale_codec::Encode; use sp_core::Get; diff --git a/pallets/slp/src/lib.rs b/pallets/slp/src/lib.rs index 2e9f3fa92..db933f457 100644 --- a/pallets/slp/src/lib.rs +++ b/pallets/slp/src/lib.rs @@ -27,10 +27,11 @@ pub use crate::{ Delays, LedgerUpdateEntry, MinimumsMaximums, QueryId, SubstrateLedger, ValidatorsByDelegatorUpdateEntry, }, - traits::{OnRefund, QueryResponseManager, StakingAgent}, + // traits::{OnRefund, QueryResponseManager, StakingAgent}, Junction::AccountId32, Junctions::X1, }; +pub use bifrost_primitives::slp::{OnRefund, QueryResponseManager, StakingAgent}; // add use bifrost_asset_registry::AssetMetadata; use bifrost_parachain_staking::ParachainStakingInterface; use bifrost_primitives::{ diff --git a/pallets/slp/src/traits.rs b/pallets/slp/src/traits.rs index 8b1c0f426..d4f29d874 100644 --- a/pallets/slp/src/traits.rs +++ b/pallets/slp/src/traits.rs @@ -1,253 +1,253 @@ -// This file is part of Bifrost. - -// Copyright (C) Liebi Technologies PTE. 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 . - -use crate::{primitives::QueryId, Box, MultiLocation, TimeUnit}; -use bifrost_primitives::CurrencyId; -use sp_runtime::DispatchResult; -use sp_std::vec::Vec; -use xcm::latest::Weight; - -/// Abstraction over a staking agent for a certain POS chain. -pub trait StakingAgent< - Balance, - AccountId, - LedgerUpdateEntry, - ValidatorsByDelegatorUpdateEntry, - Error, -> -{ - /// Delegator initialization work. Generate a new delegator and return its ID. - fn initialize_delegator( - &self, - currency_id: CurrencyId, - delegator_location: Option>, - ) -> Result; - - /// First time bonding some amount to a delegator. - fn bond( - &self, - who: &MultiLocation, - amount: Balance, - validator: &Option, - currency_id: CurrencyId, - weight_and_fee: Option<(Weight, Balance)>, - ) -> Result; - - /// Bond extra amount to a delegator. - fn bond_extra( - &self, - who: &MultiLocation, - amount: Balance, - validator: &Option, - currency_id: CurrencyId, - weight_and_fee: Option<(Weight, Balance)>, - ) -> Result; - - /// Decrease the bonding amount of a delegator. - fn unbond( - &self, - who: &MultiLocation, - amount: Balance, - validator: &Option, - currency_id: CurrencyId, - weight_and_fee: Option<(Weight, Balance)>, - ) -> Result; - - /// Unbonding all amount of a delegator. Differentiate from regular unbonding. - fn unbond_all( - &self, - who: &MultiLocation, - currency_id: CurrencyId, - weight_and_fee: Option<(Weight, Balance)>, - ) -> Result; - - /// Cancel some unbonding amount. - fn rebond( - &self, - who: &MultiLocation, - amount: Option, - validator: &Option, - currency_id: CurrencyId, - weight_and_fee: Option<(Weight, Balance)>, - ) -> Result; - - /// Delegate to some validators. - fn delegate( - &self, - who: &MultiLocation, - targets: &Vec, - currency_id: CurrencyId, - weight_and_fee: Option<(Weight, Balance)>, - ) -> Result; - - /// Remove delegation relationship with some validators. - fn undelegate( - &self, - who: &MultiLocation, - targets: &Vec, - currency_id: CurrencyId, - weight_and_fee: Option<(Weight, Balance)>, - ) -> Result; - - /// Re-delegate existing delegation to a new validator set. - fn redelegate( - &self, - who: &MultiLocation, - targets: &Option>, - currency_id: CurrencyId, - weight_and_fee: Option<(Weight, Balance)>, - ) -> Result; - - /// Initiate payout for a certain delegator. - fn payout( - &self, - who: &MultiLocation, - validator: &MultiLocation, - when: &Option, - currency_id: CurrencyId, - weight_and_fee: Option<(Weight, Balance)>, - ) -> Result; - - /// Withdraw the due payout into free balance. - fn liquidize( - &self, - who: &MultiLocation, - when: &Option, - validator: &Option, - currency_id: CurrencyId, - amount: Option, - weight_and_fee: Option<(Weight, Balance)>, - ) -> Result; - - /// Cancel the identity of delegator. - fn chill( - &self, - who: &MultiLocation, - currency_id: CurrencyId, - weight_and_fee: Option<(Weight, Balance)>, - ) -> Result; - - /// Make token transferred back to Bifrost chain account. - fn transfer_back( - &self, - from: &MultiLocation, - to: &MultiLocation, - amount: Balance, - currency_id: CurrencyId, - weight_and_fee: Option<(Weight, Balance)>, - ) -> Result<(), Error>; - - /// Make token from Bifrost chain account to the staking chain account. - fn transfer_to( - &self, - from: &MultiLocation, - to: &MultiLocation, - amount: Balance, - currency_id: CurrencyId, - ) -> Result<(), Error>; - - // Convert token to another token. - fn convert_asset( - &self, - who: &MultiLocation, - amount: Balance, - currency_id: CurrencyId, - if_from_currency: bool, - weight_and_fee: Option<(Weight, Balance)>, - ) -> Result; - - /// Tune the vtoken exchage rate. - fn tune_vtoken_exchange_rate( - &self, - who: &Option, - token_amount: Balance, - vtoken_amount: Balance, - currency_id: CurrencyId, - ) -> Result<(), Error>; - - /// ************************************ - /// Abstraction over a fee manager for charging fee from the origin chain(Bifrost) - /// or deposit fee reserves for the destination chain nominator accounts. - /// ************************************ - /// Charge hosting fee. - fn charge_hosting_fee( - &self, - amount: Balance, - from: &MultiLocation, - to: &MultiLocation, - currency_id: CurrencyId, - ) -> DispatchResult; - - /// Deposit some amount as fee to nominator accounts. - fn supplement_fee_reserve( - &self, - amount: Balance, - from: &MultiLocation, - to: &MultiLocation, - currency_id: CurrencyId, - ) -> Result<(), Error>; - - /// Remove an existing serving delegator for a particular currency. - fn remove_delegator(&self, who: &MultiLocation, currency_id: CurrencyId) -> DispatchResult; - - /// ************************************ - /// Abstraction over a QueryResponseChecker. - /// ************************************ - - fn check_delegator_ledger_query_response( - &self, - query_id: QueryId, - query_entry: LedgerUpdateEntry, - manual_mode: bool, - currency_id: CurrencyId, - ) -> Result; - - fn check_validators_by_delegator_query_response( - &self, - query_id: QueryId, - query_entry: ValidatorsByDelegatorUpdateEntry, - manual_mode: bool, - ) -> Result; - - fn fail_delegator_ledger_query_response(&self, query_id: QueryId) -> Result<(), Error>; - - fn fail_validators_by_delegator_query_response(&self, query_id: QueryId) -> Result<(), Error>; -} - -/// Helper to communicate with pallet_xcm's Queries storage for Substrate chains in runtime. -pub trait QueryResponseManager { - // If the query exists and we've already got the Response, then True is returned. Otherwise, - // False is returned. - fn get_query_response_record(query_id: QueryId) -> bool; - fn create_query_record( - responder: AccountId, - call_back: Option, - timeout: BlockNumber, - ) -> u64; - fn remove_query_record(query_id: QueryId) -> bool; -} - -pub trait OnRefund { - fn on_refund(token_id: CurrencyId, to: AccountId, token_amount: Balance) -> u64; -} - -impl OnRefund for () { - fn on_refund(_token_id: CurrencyId, _to: AccountId, _token_amount: Balance) -> u64 { - 0 - } -} +// // This file is part of Bifrost. + +// // Copyright (C) Liebi Technologies PTE. 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 . + +// use crate::{primitives::QueryId, Box, MultiLocation, TimeUnit}; +// use bifrost_primitives::CurrencyId; +// use sp_runtime::DispatchResult; +// use sp_std::vec::Vec; +// use xcm::latest::Weight; + +// /// Abstraction over a staking agent for a certain POS chain. +// pub trait StakingAgent< +// Balance, +// AccountId, +// LedgerUpdateEntry, +// ValidatorsByDelegatorUpdateEntry, +// Error, +// > +// { +// /// Delegator initialization work. Generate a new delegator and return its ID. +// fn initialize_delegator( +// &self, +// currency_id: CurrencyId, +// delegator_location: Option>, +// ) -> Result; + +// /// First time bonding some amount to a delegator. +// fn bond( +// &self, +// who: &MultiLocation, +// amount: Balance, +// validator: &Option, +// currency_id: CurrencyId, +// weight_and_fee: Option<(Weight, Balance)>, +// ) -> Result; + +// /// Bond extra amount to a delegator. +// fn bond_extra( +// &self, +// who: &MultiLocation, +// amount: Balance, +// validator: &Option, +// currency_id: CurrencyId, +// weight_and_fee: Option<(Weight, Balance)>, +// ) -> Result; + +// /// Decrease the bonding amount of a delegator. +// fn unbond( +// &self, +// who: &MultiLocation, +// amount: Balance, +// validator: &Option, +// currency_id: CurrencyId, +// weight_and_fee: Option<(Weight, Balance)>, +// ) -> Result; + +// /// Unbonding all amount of a delegator. Differentiate from regular unbonding. +// fn unbond_all( +// &self, +// who: &MultiLocation, +// currency_id: CurrencyId, +// weight_and_fee: Option<(Weight, Balance)>, +// ) -> Result; + +// /// Cancel some unbonding amount. +// fn rebond( +// &self, +// who: &MultiLocation, +// amount: Option, +// validator: &Option, +// currency_id: CurrencyId, +// weight_and_fee: Option<(Weight, Balance)>, +// ) -> Result; + +// /// Delegate to some validators. +// fn delegate( +// &self, +// who: &MultiLocation, +// targets: &Vec, +// currency_id: CurrencyId, +// weight_and_fee: Option<(Weight, Balance)>, +// ) -> Result; + +// /// Remove delegation relationship with some validators. +// fn undelegate( +// &self, +// who: &MultiLocation, +// targets: &Vec, +// currency_id: CurrencyId, +// weight_and_fee: Option<(Weight, Balance)>, +// ) -> Result; + +// /// Re-delegate existing delegation to a new validator set. +// fn redelegate( +// &self, +// who: &MultiLocation, +// targets: &Option>, +// currency_id: CurrencyId, +// weight_and_fee: Option<(Weight, Balance)>, +// ) -> Result; + +// /// Initiate payout for a certain delegator. +// fn payout( +// &self, +// who: &MultiLocation, +// validator: &MultiLocation, +// when: &Option, +// currency_id: CurrencyId, +// weight_and_fee: Option<(Weight, Balance)>, +// ) -> Result; + +// /// Withdraw the due payout into free balance. +// fn liquidize( +// &self, +// who: &MultiLocation, +// when: &Option, +// validator: &Option, +// currency_id: CurrencyId, +// amount: Option, +// weight_and_fee: Option<(Weight, Balance)>, +// ) -> Result; + +// /// Cancel the identity of delegator. +// fn chill( +// &self, +// who: &MultiLocation, +// currency_id: CurrencyId, +// weight_and_fee: Option<(Weight, Balance)>, +// ) -> Result; + +// /// Make token transferred back to Bifrost chain account. +// fn transfer_back( +// &self, +// from: &MultiLocation, +// to: &MultiLocation, +// amount: Balance, +// currency_id: CurrencyId, +// weight_and_fee: Option<(Weight, Balance)>, +// ) -> Result<(), Error>; + +// /// Make token from Bifrost chain account to the staking chain account. +// fn transfer_to( +// &self, +// from: &MultiLocation, +// to: &MultiLocation, +// amount: Balance, +// currency_id: CurrencyId, +// ) -> Result<(), Error>; + +// // Convert token to another token. +// fn convert_asset( +// &self, +// who: &MultiLocation, +// amount: Balance, +// currency_id: CurrencyId, +// if_from_currency: bool, +// weight_and_fee: Option<(Weight, Balance)>, +// ) -> Result; + +// /// Tune the vtoken exchage rate. +// fn tune_vtoken_exchange_rate( +// &self, +// who: &Option, +// token_amount: Balance, +// vtoken_amount: Balance, +// currency_id: CurrencyId, +// ) -> Result<(), Error>; + +// /// ************************************ +// /// Abstraction over a fee manager for charging fee from the origin chain(Bifrost) +// /// or deposit fee reserves for the destination chain nominator accounts. +// /// ************************************ +// /// Charge hosting fee. +// fn charge_hosting_fee( +// &self, +// amount: Balance, +// from: &MultiLocation, +// to: &MultiLocation, +// currency_id: CurrencyId, +// ) -> DispatchResult; + +// /// Deposit some amount as fee to nominator accounts. +// fn supplement_fee_reserve( +// &self, +// amount: Balance, +// from: &MultiLocation, +// to: &MultiLocation, +// currency_id: CurrencyId, +// ) -> Result<(), Error>; + +// /// Remove an existing serving delegator for a particular currency. +// fn remove_delegator(&self, who: &MultiLocation, currency_id: CurrencyId) -> DispatchResult; + +// /// ************************************ +// /// Abstraction over a QueryResponseChecker. +// /// ************************************ + +// fn check_delegator_ledger_query_response( +// &self, +// query_id: QueryId, +// query_entry: LedgerUpdateEntry, +// manual_mode: bool, +// currency_id: CurrencyId, +// ) -> Result; + +// fn check_validators_by_delegator_query_response( +// &self, +// query_id: QueryId, +// query_entry: ValidatorsByDelegatorUpdateEntry, +// manual_mode: bool, +// ) -> Result; + +// fn fail_delegator_ledger_query_response(&self, query_id: QueryId) -> Result<(), Error>; + +// fn fail_validators_by_delegator_query_response(&self, query_id: QueryId) -> Result<(), Error>; +// } + +// /// Helper to communicate with pallet_xcm's Queries storage for Substrate chains in runtime. +// pub trait QueryResponseManager { +// // If the query exists and we've already got the Response, then True is returned. Otherwise, +// // False is returned. +// fn get_query_response_record(query_id: QueryId) -> bool; +// fn create_query_record( +// responder: AccountId, +// call_back: Option, +// timeout: BlockNumber, +// ) -> u64; +// fn remove_query_record(query_id: QueryId) -> bool; +// } + +// pub trait OnRefund { +// fn on_refund(token_id: CurrencyId, to: AccountId, token_amount: Balance) -> u64; +// } + +// impl OnRefund for () { +// fn on_refund(_token_id: CurrencyId, _to: AccountId, _token_amount: Balance) -> u64 { +// 0 +// } +// } diff --git a/pallets/stable-pool/src/traits.rs b/pallets/stable-pool/src/traits.rs index 5b69979ba..5cfb65510 100644 --- a/pallets/stable-pool/src/traits.rs +++ b/pallets/stable-pool/src/traits.rs @@ -18,75 +18,76 @@ //! traits for stable-pool use crate::*; - -pub trait StablePoolHandler { - type Balance; - type AccountId; - type CurrencyId; - - fn add_liquidity( - who: Self::AccountId, - pool_id: StableAssetPoolId, - amounts: Vec, - min_mint_amount: Self::Balance, - ) -> DispatchResult; - - fn swap( - who: &Self::AccountId, - pool_id: StableAssetPoolId, - currency_id_in: PoolTokenIndex, - currency_id_out: PoolTokenIndex, - amount: Self::Balance, - min_dy: Self::Balance, - ) -> DispatchResult; - - fn redeem_single( - who: Self::AccountId, - pool_id: StableAssetPoolId, - amount: Self::Balance, - i: PoolTokenIndex, - min_redeem_amount: Self::Balance, - asset_length: u32, - ) -> Result<(Self::Balance, Self::Balance), DispatchError>; - - fn redeem_multi( - who: Self::AccountId, - pool_id: StableAssetPoolId, - amounts: Vec, - max_redeem_amount: Self::Balance, - ) -> DispatchResult; - - fn redeem_proportion( - who: Self::AccountId, - pool_id: StableAssetPoolId, - amount: Self::Balance, - min_redeem_amounts: Vec, - ) -> DispatchResult; - - fn get_pool_token_index( - pool_id: StableAssetPoolId, - currency_id: CurrencyId, - ) -> Option; - - fn get_swap_output( - pool_id: StableAssetPoolId, - currency_id_in: PoolTokenIndex, - currency_id_out: PoolTokenIndex, - amount: Self::Balance, - ) -> Result; - - fn get_swap_input( - pool_id: StableAssetPoolId, - currency_id_in: PoolTokenIndex, - currency_id_out: PoolTokenIndex, - amount: Self::Balance, - ) -> Result; - - fn get_pool_id( - currency_id_in: &Self::CurrencyId, - currency_id_out: &Self::CurrencyId, - ) -> Option<(StableAssetPoolId, PoolTokenIndex, PoolTokenIndex)>; -} +pub use bifrost_primitives::StablePoolHandler; + +// pub trait StablePoolHandler { +// type Balance; +// type AccountId; +// type CurrencyId; + +// fn add_liquidity( +// who: Self::AccountId, +// pool_id: StableAssetPoolId, +// amounts: Vec, +// min_mint_amount: Self::Balance, +// ) -> DispatchResult; + +// fn swap( +// who: &Self::AccountId, +// pool_id: StableAssetPoolId, +// currency_id_in: PoolTokenIndex, +// currency_id_out: PoolTokenIndex, +// amount: Self::Balance, +// min_dy: Self::Balance, +// ) -> DispatchResult; + +// fn redeem_single( +// who: Self::AccountId, +// pool_id: StableAssetPoolId, +// amount: Self::Balance, +// i: PoolTokenIndex, +// min_redeem_amount: Self::Balance, +// asset_length: u32, +// ) -> Result<(Self::Balance, Self::Balance), DispatchError>; + +// fn redeem_multi( +// who: Self::AccountId, +// pool_id: StableAssetPoolId, +// amounts: Vec, +// max_redeem_amount: Self::Balance, +// ) -> DispatchResult; + +// fn redeem_proportion( +// who: Self::AccountId, +// pool_id: StableAssetPoolId, +// amount: Self::Balance, +// min_redeem_amounts: Vec, +// ) -> DispatchResult; + +// fn get_pool_token_index( +// pool_id: StableAssetPoolId, +// currency_id: CurrencyId, +// ) -> Option; + +// fn get_swap_output( +// pool_id: StableAssetPoolId, +// currency_id_in: PoolTokenIndex, +// currency_id_out: PoolTokenIndex, +// amount: Self::Balance, +// ) -> Result; + +// fn get_swap_input( +// pool_id: StableAssetPoolId, +// currency_id_in: PoolTokenIndex, +// currency_id_out: PoolTokenIndex, +// amount: Self::Balance, +// ) -> Result; + +// fn get_pool_id( +// currency_id_in: &Self::CurrencyId, +// currency_id_out: &Self::CurrencyId, +// ) -> Option<(StableAssetPoolId, PoolTokenIndex, PoolTokenIndex)>; +// } impl StablePoolHandler for Pallet { type Balance = T::Balance; @@ -180,89 +181,89 @@ impl StablePoolHandler for Pallet { } } -impl StablePoolHandler for () { - type Balance = u128; - type AccountId = sp_runtime::AccountId32; - type CurrencyId = CurrencyId; - - fn add_liquidity( - _who: Self::AccountId, - _pool_id: StableAssetPoolId, - _amounts: Vec, - _min_mint_amount: Self::Balance, - ) -> DispatchResult { - Ok(()) - } - - fn swap( - _who: &Self::AccountId, - _pool_id: StableAssetPoolId, - _currency_id_in: PoolTokenIndex, - _currency_id_out: PoolTokenIndex, - _amount: Self::Balance, - _min_dy: Self::Balance, - ) -> DispatchResult { - Ok(()) - } - - fn redeem_single( - _who: Self::AccountId, - _pool_id: StableAssetPoolId, - _amount: Self::Balance, - _i: PoolTokenIndex, - _min_redeem_amount: Self::Balance, - _asset_length: u32, - ) -> Result<(Self::Balance, Self::Balance), DispatchError> { - Ok((0, 0)) - } - - fn redeem_multi( - _who: Self::AccountId, - _pool_id: StableAssetPoolId, - _amounts: Vec, - _max_redeem_amount: Self::Balance, - ) -> DispatchResult { - Ok(()) - } - - fn redeem_proportion( - _who: Self::AccountId, - _pool_id: StableAssetPoolId, - _amount: Self::Balance, - _min_redeem_amounts: Vec, - ) -> DispatchResult { - Ok(()) - } - - fn get_pool_token_index( - _pool_id: StableAssetPoolId, - _currency_id: CurrencyId, - ) -> Option { - None - } - - fn get_swap_output( - _pool_id: StableAssetPoolId, - _currency_id_in: PoolTokenIndex, - _currency_id_out: PoolTokenIndex, - _amount: Self::Balance, - ) -> Result { - Ok(0) - } - - fn get_swap_input( - _pool_id: StableAssetPoolId, - _currency_id_in: PoolTokenIndex, - _currency_id_out: PoolTokenIndex, - _amount: Self::Balance, - ) -> Result { - Ok(0) - } - - fn get_pool_id( - _currency_id_in: &Self::CurrencyId, - _currency_id_out: &Self::CurrencyId, - ) -> Option<(StableAssetPoolId, PoolTokenIndex, PoolTokenIndex)> { - None - } -} +// impl StablePoolHandler for () { +// type Balance = u128; +// type AccountId = sp_runtime::AccountId32; +// type CurrencyId = CurrencyId; + +// fn add_liquidity( +// _who: Self::AccountId, +// _pool_id: StableAssetPoolId, +// _amounts: Vec, +// _min_mint_amount: Self::Balance, +// ) -> DispatchResult { +// Ok(()) +// } + +// fn swap( +// _who: &Self::AccountId, +// _pool_id: StableAssetPoolId, +// _currency_id_in: PoolTokenIndex, +// _currency_id_out: PoolTokenIndex, +// _amount: Self::Balance, +// _min_dy: Self::Balance, +// ) -> DispatchResult { +// Ok(()) +// } + +// fn redeem_single( +// _who: Self::AccountId, +// _pool_id: StableAssetPoolId, +// _amount: Self::Balance, +// _i: PoolTokenIndex, +// _min_redeem_amount: Self::Balance, +// _asset_length: u32, +// ) -> Result<(Self::Balance, Self::Balance), DispatchError> { +// Ok((0, 0)) +// } + +// fn redeem_multi( +// _who: Self::AccountId, +// _pool_id: StableAssetPoolId, +// _amounts: Vec, +// _max_redeem_amount: Self::Balance, +// ) -> DispatchResult { +// Ok(()) +// } + +// fn redeem_proportion( +// _who: Self::AccountId, +// _pool_id: StableAssetPoolId, +// _amount: Self::Balance, +// _min_redeem_amounts: Vec, +// ) -> DispatchResult { +// Ok(()) +// } + +// fn get_pool_token_index( +// _pool_id: StableAssetPoolId, +// _currency_id: CurrencyId, +// ) -> Option { +// None +// } + +// fn get_swap_output( +// _pool_id: StableAssetPoolId, +// _currency_id_in: PoolTokenIndex, +// _currency_id_out: PoolTokenIndex, +// _amount: Self::Balance, +// ) -> Result { +// Ok(0) +// } + +// fn get_swap_input( +// _pool_id: StableAssetPoolId, +// _currency_id_in: PoolTokenIndex, +// _currency_id_out: PoolTokenIndex, +// _amount: Self::Balance, +// ) -> Result { +// Ok(0) +// } + +// fn get_pool_id( +// _currency_id_in: &Self::CurrencyId, +// _currency_id_out: &Self::CurrencyId, +// ) -> Option<(StableAssetPoolId, PoolTokenIndex, PoolTokenIndex)> { +// None +// } +// } diff --git a/pallets/ve-minting/src/lib.rs b/pallets/ve-minting/src/lib.rs index a01b06665..5b388ba9d 100644 --- a/pallets/ve-minting/src/lib.rs +++ b/pallets/ve-minting/src/lib.rs @@ -53,6 +53,7 @@ use sp_std::{borrow::ToOwned, cmp::Ordering, collections::btree_map::BTreeMap, v pub use traits::{ LockedToken, MarkupCoefficientInfo, MarkupInfo, UserMarkupInfo, VeMintingInterface, }; +// pub use bifrost_primitives::{}; pub use weights::WeightInfo; type BalanceOf = <::MultiCurrency as MultiCurrency>>::Balance; diff --git a/pallets/vtoken-minting/src/lib.rs b/pallets/vtoken-minting/src/lib.rs index 24836a404..ef73c6006 100644 --- a/pallets/vtoken-minting/src/lib.rs +++ b/pallets/vtoken-minting/src/lib.rs @@ -37,7 +37,7 @@ use bifrost_asset_registry::AssetMetadata; use bifrost_primitives::{ CurrencyId, CurrencyIdConversion, CurrencyIdExt, CurrencyIdMapping, CurrencyIdRegister, RedeemType, SlpOperator, SlpxOperator, TimeUnit, VTokenMintRedeemProvider, - VTokenSupplyProvider, VtokenMintingInterface, VtokenMintingOperator, + VTokenSupplyProvider, VtokenMintingInterface, VtokenMintingOperator, RedeemTo }; use bifrost_ve_minting::traits::VeMintingInterface; use frame_support::{ @@ -57,7 +57,7 @@ use orml_traits::{MultiCurrency, MultiLockableCurrency}; pub use pallet::*; use sp_core::U256; use sp_std::{vec, vec::Vec}; -pub use traits::*; +pub use bifrost_primitives::vtoken_minting::*; use xcm::v3::MultiLocation; pub type AccountIdOf = ::AccountId; diff --git a/pallets/vtoken-minting/src/traits.rs b/pallets/vtoken-minting/src/traits.rs index 33a37c6d5..4b71d932a 100644 --- a/pallets/vtoken-minting/src/traits.rs +++ b/pallets/vtoken-minting/src/traits.rs @@ -1,72 +1,72 @@ -// This file is part of Bifrost. +// // This file is part of Bifrost. -// Copyright (C) Liebi Technologies PTE. LTD. -// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 +// // Copyright (C) Liebi Technologies PTE. 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 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. +// // 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 . +// // You should have received a copy of the GNU General Public License +// // along with this program. If not, see . -// Ensure we're `no_std` when compiling for Wasm. +// // Ensure we're `no_std` when compiling for Wasm. -use frame_support::pallet_prelude::Weight; -use parity_scale_codec::{Decode, Encode}; -use sp_core::H160; -use sp_runtime::RuntimeDebug; +// use frame_support::pallet_prelude::Weight; +// use parity_scale_codec::{Decode, Encode}; +// use sp_core::H160; +// use sp_runtime::RuntimeDebug; -#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, scale_info::TypeInfo)] -pub enum RedeemTo { - /// Native chain. - Native(AccountId), - /// Astar chain. - Astar(AccountId), - /// Moonbeam chain. - Moonbeam(H160), - /// Hydradx chain. - Hydradx(AccountId), - /// Interlay chain. - Interlay(AccountId), - /// Manta chain. - Manta(AccountId), -} +// #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, scale_info::TypeInfo)] +// pub enum RedeemTo { +// /// Native chain. +// Native(AccountId), +// /// Astar chain. +// Astar(AccountId), +// /// Moonbeam chain. +// Moonbeam(H160), +// /// Hydradx chain. +// Hydradx(AccountId), +// /// Interlay chain. +// Interlay(AccountId), +// /// Manta chain. +// Manta(AccountId), +// } -pub trait OnRedeemSuccess { - fn on_redeem_success( - token_id: CurrencyId, - to: AccountId, - token_amount: Balance, - ) -> frame_support::pallet_prelude::Weight; +// pub trait OnRedeemSuccess { +// fn on_redeem_success( +// token_id: CurrencyId, +// to: AccountId, +// token_amount: Balance, +// ) -> frame_support::pallet_prelude::Weight; - fn on_redeemed( - address: AccountId, - token_id: CurrencyId, - token_amount: Balance, - vtoken_amount: Balance, - fee: Balance, - ) -> frame_support::pallet_prelude::Weight; -} +// fn on_redeemed( +// address: AccountId, +// token_id: CurrencyId, +// token_amount: Balance, +// vtoken_amount: Balance, +// fee: Balance, +// ) -> frame_support::pallet_prelude::Weight; +// } -impl OnRedeemSuccess for () { - fn on_redeem_success(_token_id: CurrencyId, _to: AccountId, _token_amount: Balance) -> Weight { - Weight::zero() - } +// impl OnRedeemSuccess for () { +// fn on_redeem_success(_token_id: CurrencyId, _to: AccountId, _token_amount: Balance) -> Weight { +// Weight::zero() +// } - fn on_redeemed( - _address: AccountId, - _token_id: CurrencyId, - _token_amount: Balance, - _vtoken_amount: Balance, - _fee: Balance, - ) -> Weight { - Weight::zero() - } -} +// fn on_redeemed( +// _address: AccountId, +// _token_id: CurrencyId, +// _token_amount: Balance, +// _vtoken_amount: Balance, +// _fee: Balance, +// ) -> Weight { +// Weight::zero() +// } +// } diff --git a/pallets/xcm-interface/src/lib.rs b/pallets/xcm-interface/src/lib.rs index e7ea013fc..0b8b86a59 100644 --- a/pallets/xcm-interface/src/lib.rs +++ b/pallets/xcm-interface/src/lib.rs @@ -25,7 +25,8 @@ use bifrost_primitives::{traits::XcmDestWeightAndFeeHandler, CurrencyIdMapping, pub use calls::*; use orml_traits::MultiCurrency; pub use pallet::*; -pub use traits::{ChainId, MessageId, Nonce, SalpHelper}; +// pub use traits::{ChainId, MessageId, Nonce, SalpHelper}; +pub use bifrost_primitives::xcm_interface::{ChainId, MessageId, Nonce, SalpHelper}; macro_rules! use_relay { ({ $( $code:tt )* }) => { @@ -68,7 +69,8 @@ pub mod pallet { }; use super::*; - use crate::traits::*; + // use crate::traits::*; + use bifrost_primitives::xcm_interface::*; #[pallet::config] pub trait Config: frame_system::Config + pallet_xcm::Config { @@ -349,7 +351,7 @@ pub mod pallet { } pub(crate) fn build_ump_transact( - query_id: QueryId, + query_id: bifrost_primitives::xcm_interface::QueryId, call: DoubleEncoded<()>, weight: Weight, fee: BalanceOf, diff --git a/pallets/xcm-interface/src/traits.rs b/pallets/xcm-interface/src/traits.rs index 190dedf12..ccd23dfda 100644 --- a/pallets/xcm-interface/src/traits.rs +++ b/pallets/xcm-interface/src/traits.rs @@ -1,159 +1,159 @@ -// This file is part of Bifrost. - -// Copyright (C) Liebi Technologies PTE. 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 . - -use core::ops::{Add, Mul}; - -use parity_scale_codec::{Decode, Encode}; -use scale_info::TypeInfo; -use sp_runtime::DispatchError; -use sp_std::prelude::*; -use xcm::v3::QueryId; - -pub type MessageId = [u8; 32]; - -pub type ChainId = u32; - -pub type Nonce = u32; - -/// The type used to represent the xcmp transfer direction -#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, TypeInfo)] -pub enum TransferOriginType { - FromSelf = 0, - FromRelayChain = 1, - FromSiblingParaChain = 2, -} - -pub struct XcmBaseWeight(u64); - -impl XcmBaseWeight { - pub fn new(x: u64) -> Self { - XcmBaseWeight(x) - } -} - -impl From for XcmBaseWeight { - fn from(u: u64) -> Self { - XcmBaseWeight(u) - } -} - -impl From for u64 { - fn from(x: XcmBaseWeight) -> Self { - x.0.into() - } -} - -impl Add for XcmBaseWeight { - type Output = Self; - fn add(self, other: Self) -> Self::Output { - (self.0 + other.0).into() - } -} - -impl Mul for XcmBaseWeight { - type Output = Self; - - fn mul(self, rhs: u64) -> Self { - XcmBaseWeight::new(self.0 * rhs) - } -} - -/// represent the transact type -#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, TypeInfo)] -pub enum ParachainTransactType { - Xcm = 0, - Proxy = 1, -} - -/// represent the proxy type -#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, TypeInfo)] -pub enum ParachainTransactProxyType { - Primary = 0, - Derived = 1, -} - -/// represent the derived proxy account type -#[repr(u16)] -pub enum ParachainDerivedProxyAccountType { - Salp = 0, - Staking = 1, -} - -#[allow(non_snake_case)] -pub mod parachains { - // ********************* - // Kusama parachains** - // ********************* - - pub mod karura { - pub const ID: u32 = 2000; - pub const KAR_KEY: &[u8] = &[0, 128]; - pub const KUSD_KEY: &[u8] = &[0, 129]; - } - - pub mod Statemine { - pub const ID: u32 = 1000; - pub const PALLET_ID: u8 = 50; - pub const RMRK_ID: u32 = 8; - } - - pub mod phala { - pub const ID: u32 = 2004; - } - - pub mod moonriver { - pub const ID: u32 = 2023; - pub const PALLET_ID: u8 = 10; - } - - //********************* - // Polkadot parachains - //********************* - pub mod moonbeam { - pub const ID: u32 = 2004; - pub const PALLET_ID: u8 = 10; - } - - pub mod astar { - pub const ID: u32 = 2006; - pub const PALLET_ID: u8 = 34; - } - - pub mod manta { - pub const ID: u32 = 2104; - pub const PALLET_ID: u8 = 10; - } -} - -pub trait XcmHelper { - fn contribute( - contributer: AccountId, - index: ChainId, - value: Balance, - ) -> Result; -} - -pub trait SalpHelper { - fn confirm_contribute_call() -> RuntimeCall; - fn bind_query_id_and_contribution( - query_id: QueryId, - index: ChainId, - contributer: AccountId, - amount: Balance, - ); -} +// // This file is part of Bifrost. + +// // Copyright (C) Liebi Technologies PTE. 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 . + +// use core::ops::{Add, Mul}; + +// use parity_scale_codec::{Decode, Encode}; +// use scale_info::TypeInfo; +// use sp_runtime::DispatchError; +// use sp_std::prelude::*; +// use xcm::v3::QueryId; + +// pub type MessageId = [u8; 32]; + +// pub type ChainId = u32; + +// pub type Nonce = u32; + +// /// The type used to represent the xcmp transfer direction +// #[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, TypeInfo)] +// pub enum TransferOriginType { +// FromSelf = 0, +// FromRelayChain = 1, +// FromSiblingParaChain = 2, +// } + +// pub struct XcmBaseWeight(u64); + +// impl XcmBaseWeight { +// pub fn new(x: u64) -> Self { +// XcmBaseWeight(x) +// } +// } + +// impl From for XcmBaseWeight { +// fn from(u: u64) -> Self { +// XcmBaseWeight(u) +// } +// } + +// impl From for u64 { +// fn from(x: XcmBaseWeight) -> Self { +// x.0.into() +// } +// } + +// impl Add for XcmBaseWeight { +// type Output = Self; +// fn add(self, other: Self) -> Self::Output { +// (self.0 + other.0).into() +// } +// } + +// impl Mul for XcmBaseWeight { +// type Output = Self; + +// fn mul(self, rhs: u64) -> Self { +// XcmBaseWeight::new(self.0 * rhs) +// } +// } + +// /// represent the transact type +// #[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, TypeInfo)] +// pub enum ParachainTransactType { +// Xcm = 0, +// Proxy = 1, +// } + +// /// represent the proxy type +// #[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, TypeInfo)] +// pub enum ParachainTransactProxyType { +// Primary = 0, +// Derived = 1, +// } + +// /// represent the derived proxy account type +// #[repr(u16)] +// pub enum ParachainDerivedProxyAccountType { +// Salp = 0, +// Staking = 1, +// } + +// #[allow(non_snake_case)] +// pub mod parachains { +// // ********************* +// // Kusama parachains** +// // ********************* + +// pub mod karura { +// pub const ID: u32 = 2000; +// pub const KAR_KEY: &[u8] = &[0, 128]; +// pub const KUSD_KEY: &[u8] = &[0, 129]; +// } + +// pub mod Statemine { +// pub const ID: u32 = 1000; +// pub const PALLET_ID: u8 = 50; +// pub const RMRK_ID: u32 = 8; +// } + +// pub mod phala { +// pub const ID: u32 = 2004; +// } + +// pub mod moonriver { +// pub const ID: u32 = 2023; +// pub const PALLET_ID: u8 = 10; +// } + +// //********************* +// // Polkadot parachains +// //********************* +// pub mod moonbeam { +// pub const ID: u32 = 2004; +// pub const PALLET_ID: u8 = 10; +// } + +// pub mod astar { +// pub const ID: u32 = 2006; +// pub const PALLET_ID: u8 = 34; +// } + +// pub mod manta { +// pub const ID: u32 = 2104; +// pub const PALLET_ID: u8 = 10; +// } +// } + +// pub trait XcmHelper { +// fn contribute( +// contributer: AccountId, +// index: ChainId, +// value: Balance, +// ) -> Result; +// } + +// pub trait SalpHelper { +// fn confirm_contribute_call() -> RuntimeCall; +// fn bind_query_id_and_contribution( +// query_id: QueryId, +// index: ChainId, +// contributer: AccountId, +// amount: Balance, +// ); +// } diff --git a/primitives/src/lib.rs b/primitives/src/lib.rs index 9e675a505..d316fa1b4 100644 --- a/primitives/src/lib.rs +++ b/primitives/src/lib.rs @@ -21,12 +21,13 @@ #![cfg_attr(not(feature = "std"), no_std)] use parity_scale_codec::MaxEncodedLen; -use scale_info::TypeInfo; -use sp_core::{Decode, Encode, RuntimeDebug, H160}; +use scale_info::{TypeInfo, prelude::collections::BTreeMap}; +use sp_core::{Decode, Encode, RuntimeDebug, H160, U256}; use sp_runtime::{ generic, traits::{BlakeTwo256, IdentifyAccount, Verify}, FixedU128, MultiSignature, OpaqueExtrinsic, Permill, + DispatchResult, DispatchError }; use xcm::v4::{prelude::*, Asset, Location}; use xcm_executor::traits::{AssetTransferError, TransferType, XcmAssetTransfers}; @@ -35,6 +36,9 @@ pub mod currency; mod salp; pub mod traits; pub use salp::*; +pub use frame_support::{dispatch::Parameter, storage::types::StorageMap}; +use sp_std::{vec::Vec, boxed::Box}; +use core::ops::{Add, Mul}; #[cfg(test)] mod tests; @@ -155,6 +159,17 @@ pub type DerivativeIndex = u16; pub type TimeStampedPrice = orml_oracle::TimestampedValue; +pub type PoolTokenIndex = u32; + +pub type StableAssetPoolId = u32; + +pub type ChainId = u32; + +pub type RoundIndex = u32; + +pub type QueryId = u64; + + #[derive( Encode, Decode, Eq, PartialEq, Copy, Clone, RuntimeDebug, PartialOrd, Ord, scale_info::TypeInfo, )] @@ -344,3 +359,36 @@ impl Default for ExtraFeeInfo { } } } + +pub struct Point { + bias: i128, // i128 + slope: i128, // dweight / dt + block: BlockNumber, + amount: Balance, +} + +pub struct IncentiveConfig { + pub reward_rate: BTreeMap, + pub reward_per_token_stored: BTreeMap, + pub rewards_duration: BlockNumber, + pub period_finish: BlockNumber, + pub last_update_time: BlockNumber, + pub incentive_controller: Option, + pub last_reward: Vec<(CurrencyId, Balance)>, +} + +#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, scale_info::TypeInfo)] +pub enum RedeemTo { + /// Native chain. + Native(AccountId), + /// Astar chain. + Astar(AccountId), + /// Moonbeam chain. + Moonbeam(H160), + /// Hydradx chain. + Hydradx(AccountId), + /// Interlay chain. + Interlay(AccountId), + /// Manta chain. + Manta(AccountId), +} \ No newline at end of file diff --git a/primitives/src/salp.rs b/primitives/src/salp.rs index d63ae7ab6..bdb58932d 100644 --- a/primitives/src/salp.rs +++ b/primitives/src/salp.rs @@ -88,3 +88,4 @@ impl Default for ContributionStatus { } pub type MessageId = [u8; 32]; +// pub use crate::MessageId; diff --git a/primitives/src/traits/mod.rs b/primitives/src/traits/mod.rs new file mode 100644 index 000000000..e20ea5347 --- /dev/null +++ b/primitives/src/traits/mod.rs @@ -0,0 +1,18 @@ +pub mod traits; +pub mod parachain_staking; +pub mod slp; +pub mod stable_pool; +pub mod ve_minting; +pub mod vtoken_minting; +pub mod xcm_interface; + +pub use traits::*; +pub use parachain_staking::*; +pub use slp::*; +pub use stable_pool::*; +pub use ve_minting::*; +pub use vtoken_minting::*; +pub use xcm_interface::*; + + + diff --git a/primitives/src/traits/parachain_staking.rs b/primitives/src/traits/parachain_staking.rs new file mode 100644 index 000000000..3107ab745 --- /dev/null +++ b/primitives/src/traits/parachain_staking.rs @@ -0,0 +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 . + +//! traits for parachain-staking +use frame_support::pallet_prelude::{DispatchResultWithPostInfo, Weight}; + +pub trait OnCollatorPayout { + fn on_collator_payout( + for_round: crate::RoundIndex, + collator_id: AccountId, + amount: Balance, + ) -> Weight; +} +impl OnCollatorPayout 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 { + 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 ParachainStakingInterface 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) + } +} diff --git a/primitives/src/traits/slp.rs b/primitives/src/traits/slp.rs new file mode 100644 index 000000000..1d19a6f6f --- /dev/null +++ b/primitives/src/traits/slp.rs @@ -0,0 +1,250 @@ +// This file is part of Bifrost. + +// Copyright (C) Liebi Technologies PTE. 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 . + +use crate::{CurrencyId, TimeUnit, DispatchResult, QueryId, Vec, Box}; +use xcm::{latest::Weight, opaque::v3::MultiLocation}; + +/// Abstraction over a staking agent for a certain POS chain. +pub trait StakingAgent< + Balance, + AccountId, + LedgerUpdateEntry, + ValidatorsByDelegatorUpdateEntry, + Error, +> +{ + /// Delegator initialization work. Generate a new delegator and return its ID. + fn initialize_delegator( + &self, + currency_id: CurrencyId, + delegator_location: Option>, + ) -> Result; + + /// First time bonding some amount to a delegator. + fn bond( + &self, + who: &MultiLocation, + amount: Balance, + validator: &Option, + currency_id: CurrencyId, + weight_and_fee: Option<(Weight, Balance)>, + ) -> Result; + + /// Bond extra amount to a delegator. + fn bond_extra( + &self, + who: &MultiLocation, + amount: Balance, + validator: &Option, + currency_id: CurrencyId, + weight_and_fee: Option<(Weight, Balance)>, + ) -> Result; + + /// Decrease the bonding amount of a delegator. + fn unbond( + &self, + who: &MultiLocation, + amount: Balance, + validator: &Option, + currency_id: CurrencyId, + weight_and_fee: Option<(Weight, Balance)>, + ) -> Result; + + /// Unbonding all amount of a delegator. Differentiate from regular unbonding. + fn unbond_all( + &self, + who: &MultiLocation, + currency_id: CurrencyId, + weight_and_fee: Option<(Weight, Balance)>, + ) -> Result; + + /// Cancel some unbonding amount. + fn rebond( + &self, + who: &MultiLocation, + amount: Option, + validator: &Option, + currency_id: CurrencyId, + weight_and_fee: Option<(Weight, Balance)>, + ) -> Result; + + /// Delegate to some validators. + fn delegate( + &self, + who: &MultiLocation, + targets: &Vec, + currency_id: CurrencyId, + weight_and_fee: Option<(Weight, Balance)>, + ) -> Result; + + /// Remove delegation relationship with some validators. + fn undelegate( + &self, + who: &MultiLocation, + targets: &Vec, + currency_id: CurrencyId, + weight_and_fee: Option<(Weight, Balance)>, + ) -> Result; + + /// Re-delegate existing delegation to a new validator set. + fn redelegate( + &self, + who: &MultiLocation, + targets: &Option>, + currency_id: CurrencyId, + weight_and_fee: Option<(Weight, Balance)>, + ) -> Result; + + /// Initiate payout for a certain delegator. + fn payout( + &self, + who: &MultiLocation, + validator: &MultiLocation, + when: &Option, + currency_id: CurrencyId, + weight_and_fee: Option<(Weight, Balance)>, + ) -> Result; + + /// Withdraw the due payout into free balance. + fn liquidize( + &self, + who: &MultiLocation, + when: &Option, + validator: &Option, + currency_id: CurrencyId, + amount: Option, + weight_and_fee: Option<(Weight, Balance)>, + ) -> Result; + + /// Cancel the identity of delegator. + fn chill( + &self, + who: &MultiLocation, + currency_id: CurrencyId, + weight_and_fee: Option<(Weight, Balance)>, + ) -> Result; + + /// Make token transferred back to Bifrost chain account. + fn transfer_back( + &self, + from: &MultiLocation, + to: &MultiLocation, + amount: Balance, + currency_id: CurrencyId, + weight_and_fee: Option<(Weight, Balance)>, + ) -> Result<(), Error>; + + /// Make token from Bifrost chain account to the staking chain account. + fn transfer_to( + &self, + from: &MultiLocation, + to: &MultiLocation, + amount: Balance, + currency_id: CurrencyId, + ) -> Result<(), Error>; + + // Convert token to another token. + fn convert_asset( + &self, + who: &MultiLocation, + amount: Balance, + currency_id: CurrencyId, + if_from_currency: bool, + weight_and_fee: Option<(Weight, Balance)>, + ) -> Result; + + /// Tune the vtoken exchage rate. + fn tune_vtoken_exchange_rate( + &self, + who: &Option, + token_amount: Balance, + vtoken_amount: Balance, + currency_id: CurrencyId, + ) -> Result<(), Error>; + + /// ************************************ + /// Abstraction over a fee manager for charging fee from the origin chain(Bifrost) + /// or deposit fee reserves for the destination chain nominator accounts. + /// ************************************ + /// Charge hosting fee. + fn charge_hosting_fee( + &self, + amount: Balance, + from: &MultiLocation, + to: &MultiLocation, + currency_id: CurrencyId, + ) -> DispatchResult; + + /// Deposit some amount as fee to nominator accounts. + fn supplement_fee_reserve( + &self, + amount: Balance, + from: &MultiLocation, + to: &MultiLocation, + currency_id: CurrencyId, + ) -> Result<(), Error>; + + /// Remove an existing serving delegator for a particular currency. + fn remove_delegator(&self, who: &MultiLocation, currency_id: CurrencyId) -> DispatchResult; + + /// ************************************ + /// Abstraction over a QueryResponseChecker. + /// ************************************ + + fn check_delegator_ledger_query_response( + &self, + query_id: QueryId, + query_entry: LedgerUpdateEntry, + manual_mode: bool, + currency_id: CurrencyId, + ) -> Result; + + fn check_validators_by_delegator_query_response( + &self, + query_id: QueryId, + query_entry: ValidatorsByDelegatorUpdateEntry, + manual_mode: bool, + ) -> Result; + + fn fail_delegator_ledger_query_response(&self, query_id: QueryId) -> Result<(), Error>; + + fn fail_validators_by_delegator_query_response(&self, query_id: QueryId) -> Result<(), Error>; +} + +/// Helper to communicate with pallet_xcm's Queries storage for Substrate chains in runtime. +pub trait QueryResponseManager { + // If the query exists and we've already got the Response, then True is returned. Otherwise, + // False is returned. + fn get_query_response_record(query_id: QueryId) -> bool; + fn create_query_record( + responder: AccountId, + call_back: Option, + timeout: BlockNumber, + ) -> u64; + fn remove_query_record(query_id: QueryId) -> bool; +} + +pub trait OnRefund { + fn on_refund(token_id: CurrencyId, to: AccountId, token_amount: Balance) -> u64; +} + +impl OnRefund for () { + fn on_refund(_token_id: CurrencyId, _to: AccountId, _token_amount: Balance) -> u64 { + 0 + } +} diff --git a/primitives/src/traits/stable_pool.rs b/primitives/src/traits/stable_pool.rs new file mode 100644 index 000000000..547e2c7d0 --- /dev/null +++ b/primitives/src/traits/stable_pool.rs @@ -0,0 +1,89 @@ +// This file is part of Bifrost. + +// Copyright (C) Liebi Technologies PTE. 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 . + +use crate::*; + +pub trait StablePoolHandler { + type Balance; + type AccountId; + type CurrencyId; + + fn add_liquidity( + who: Self::AccountId, + pool_id: StableAssetPoolId, + amounts: Vec, + min_mint_amount: Self::Balance, + ) -> DispatchResult; + + fn swap( + who: &Self::AccountId, + pool_id: StableAssetPoolId, + currency_id_in: PoolTokenIndex, + currency_id_out: PoolTokenIndex, + amount: Self::Balance, + min_dy: Self::Balance, + ) -> DispatchResult; + + fn redeem_single( + who: Self::AccountId, + pool_id: StableAssetPoolId, + amount: Self::Balance, + i: PoolTokenIndex, + min_redeem_amount: Self::Balance, + asset_length: u32, + ) -> Result<(Self::Balance, Self::Balance), DispatchError>; + + fn redeem_multi( + who: Self::AccountId, + pool_id: StableAssetPoolId, + amounts: Vec, + max_redeem_amount: Self::Balance, + ) -> DispatchResult; + + fn redeem_proportion( + who: Self::AccountId, + pool_id: StableAssetPoolId, + amount: Self::Balance, + min_redeem_amounts: Vec, + ) -> DispatchResult; + + fn get_pool_token_index( + pool_id: StableAssetPoolId, + currency_id: CurrencyId, + ) -> Option; + + fn get_swap_output( + pool_id: StableAssetPoolId, + currency_id_in: PoolTokenIndex, + currency_id_out: PoolTokenIndex, + amount: Self::Balance, + ) -> Result; + + fn get_swap_input( + pool_id: StableAssetPoolId, + currency_id_in: PoolTokenIndex, + currency_id_out: PoolTokenIndex, + amount: Self::Balance, + ) -> Result; + + fn get_pool_id( + currency_id_in: &Self::CurrencyId, + currency_id_out: &Self::CurrencyId, + ) -> Option<(StableAssetPoolId, PoolTokenIndex, PoolTokenIndex)>; +} + diff --git a/primitives/src/traits.rs b/primitives/src/traits/traits.rs similarity index 98% rename from primitives/src/traits.rs rename to primitives/src/traits/traits.rs index 6279a91e9..dc6311067 100644 --- a/primitives/src/traits.rs +++ b/primitives/src/traits/traits.rs @@ -22,7 +22,7 @@ use crate::{ AssetIds, DerivativeIndex, ExtraFeeInfo, LeasePeriod, ParaId, PoolId, RedeemType, TokenId, - TokenSymbol, XcmOperationType, + TokenSymbol, XcmOperationType, Vec }; use frame_support::pallet_prelude::{DispatchResultWithPostInfo, Weight}; use parity_scale_codec::{Decode, Encode, FullCodec}; @@ -32,7 +32,7 @@ use sp_runtime::{ }, BoundedVec, DispatchError, DispatchResult, TokenError, TypeId, }; -use sp_std::{fmt::Debug, vec::Vec}; +use sp_std::fmt::Debug; pub trait TokenInfo { fn name(&self) -> Option<&str>; @@ -81,11 +81,11 @@ pub trait MultiCurrencyExt { } pub trait BancorHandler { - fn add_token(currency_id: super::CurrencyId, amount: Balance) -> DispatchResult; + fn add_token(currency_id: super::super::CurrencyId, amount: Balance) -> DispatchResult; } impl BancorHandler for () { - fn add_token(_currency_id: super::CurrencyId, _amount: Balance) -> DispatchResult { + fn add_token(_currency_id: super::super::CurrencyId, _amount: Balance) -> DispatchResult { DispatchResult::from(DispatchError::Token(TokenError::FundsUnavailable)) } } diff --git a/primitives/src/traits/ve_minting.rs b/primitives/src/traits/ve_minting.rs new file mode 100644 index 000000000..82e248edd --- /dev/null +++ b/primitives/src/traits/ve_minting.rs @@ -0,0 +1,107 @@ +// This file is part of Bifrost. + +// Copyright (C) Liebi Technologies PTE. 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 . + +// Ensure we're `no_std` when compiling for Wasm. +use crate::{DispatchResult, DispatchError, PoolId, Point, U256, Vec, + IncentiveConfig, FixedU128, Decode, RuntimeDebug, MaxEncodedLen, + TypeInfo, Encode, +}; + +pub trait VeMintingInterface { + fn deposit_for(_who: &AccountId, position: u128, value: Balance) -> DispatchResult; + fn withdraw_inner(who: &AccountId, position: u128) -> DispatchResult; + fn balance_of(addr: &AccountId, time: Option) -> Result; + fn total_supply(t: BlockNumber) -> Result; + fn supply_at( + point: Point, + t: BlockNumber, + ) -> Result; + fn find_block_epoch(_block: BlockNumber, max_epoch: U256) -> U256; + fn create_lock_inner( + who: &AccountId, + _value: Balance, + _unlock_time: BlockNumber, + ) -> DispatchResult; // Deposit `_value` BNC for `addr` and lock until `_unlock_time` + fn increase_amount_inner(who: &AccountId, position: u128, value: Balance) -> DispatchResult; // Deposit `_value` additional BNC for `addr` without modifying the unlock time + fn increase_unlock_time_inner( + who: &AccountId, + position: u128, + _unlock_time: BlockNumber, + ) -> DispatchResult; // Extend the unlock time for `addr` to `_unlock_time` + fn auto_notify_reward( + pool_id: PoolId, + n: BlockNumber, + rewards: Vec<(CurrencyId, Balance)>, + ) -> DispatchResult; + fn update_reward( + pool_id: PoolId, + addr: Option<&AccountId>, + share_info: Option<(Balance, Balance)>, + ) -> DispatchResult; + fn get_rewards( + pool_id: PoolId, + addr: &AccountId, + share_info: Option<(Balance, Balance)>, + ) -> DispatchResult; + fn set_incentive( + pool_id: PoolId, + rewards_duration: Option, + controller: Option, + ); + fn add_reward( + addr: &AccountId, + conf: &mut IncentiveConfig, + rewards: &Vec<(CurrencyId, Balance)>, + remaining: Balance, + ) -> DispatchResult; + fn notify_reward( + pool_id: PoolId, + addr: &Option, + rewards: Vec<(CurrencyId, Balance)>, + ) -> DispatchResult; +} + +#[derive(Clone, Encode, Decode, PartialEq, Eq, RuntimeDebug, TypeInfo, Default)] +pub struct UserMarkupInfo { + // pub old_locked: LockedBalance, + pub old_markup_coefficient: FixedU128, + pub markup_coefficient: FixedU128, +} + +#[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, MaxEncodedLen, TypeInfo)] +pub struct LockedToken { + // pub asset_id: CurrencyId, + pub amount: Balance, + pub markup_coefficient: FixedU128, + pub refresh_block: BlockNumber, +} + +#[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, MaxEncodedLen, TypeInfo)] +pub struct MarkupCoefficientInfo { + pub markup_coefficient: FixedU128, + pub hardcap: FixedU128, + pub update_block: BlockNumber, +} + +pub trait MarkupInfo { + fn update_markup_info( + addr: &AccountId, + new_markup_coefficient: FixedU128, + user_markup_info: &mut UserMarkupInfo, + ); +} \ No newline at end of file diff --git a/primitives/src/traits/vtoken_minting.rs b/primitives/src/traits/vtoken_minting.rs new file mode 100644 index 000000000..3848c56cb --- /dev/null +++ b/primitives/src/traits/vtoken_minting.rs @@ -0,0 +1,53 @@ +// This file is part of Bifrost. + +// Copyright (C) Liebi Technologies PTE. 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 . + +// Ensure we're `no_std` when compiling for Wasm. + +use crate::Weight; + +pub trait OnRedeemSuccess { + fn on_redeem_success( + token_id: CurrencyId, + to: AccountId, + token_amount: Balance, + ) -> frame_support::pallet_prelude::Weight; + + fn on_redeemed( + address: AccountId, + token_id: CurrencyId, + token_amount: Balance, + vtoken_amount: Balance, + fee: Balance, + ) -> frame_support::pallet_prelude::Weight; +} + +impl OnRedeemSuccess for () { + fn on_redeem_success(_token_id: CurrencyId, _to: AccountId, _token_amount: Balance) -> Weight { + Weight::zero() + } + + fn on_redeemed( + _address: AccountId, + _token_id: CurrencyId, + _token_amount: Balance, + _vtoken_amount: Balance, + _fee: Balance, + ) -> Weight { + Weight::zero() + } +} diff --git a/primitives/src/traits/xcm_interface.rs b/primitives/src/traits/xcm_interface.rs new file mode 100644 index 000000000..da514d8db --- /dev/null +++ b/primitives/src/traits/xcm_interface.rs @@ -0,0 +1,148 @@ + +// This file is part of Bifrost. + +// Copyright (C) Liebi Technologies PTE. 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 . + +pub use crate::*; + +/// The type used to represent the xcmp transfer direction +#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, TypeInfo)] +pub enum TransferOriginType { + FromSelf = 0, + FromRelayChain = 1, + FromSiblingParaChain = 2, +} + +pub struct XcmBaseWeight(u64); + +impl XcmBaseWeight { + pub fn new(x: u64) -> Self { + XcmBaseWeight(x) + } +} + +impl From for XcmBaseWeight { + fn from(u: u64) -> Self { + XcmBaseWeight(u) + } +} + +impl From for u64 { + fn from(x: XcmBaseWeight) -> Self { + x.0.into() + } +} + +impl Add for XcmBaseWeight { + type Output = Self; + fn add(self, other: Self) -> Self::Output { + (self.0 + other.0).into() + } +} + +impl Mul for XcmBaseWeight { + type Output = Self; + + fn mul(self, rhs: u64) -> Self { + XcmBaseWeight::new(self.0 * rhs) + } +} + +/// represent the transact type +#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, TypeInfo)] +pub enum ParachainTransactType { + Xcm = 0, + Proxy = 1, +} + +/// represent the proxy type +#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, TypeInfo)] +pub enum ParachainTransactProxyType { + Primary = 0, + Derived = 1, +} + +/// represent the derived proxy account type +#[repr(u16)] +pub enum ParachainDerivedProxyAccountType { + Salp = 0, + Staking = 1, +} + +#[allow(non_snake_case)] +pub mod parachains { + // ********************* + // Kusama parachains** + // ********************* + + pub mod karura { + pub const ID: u32 = 2000; + pub const KAR_KEY: &[u8] = &[0, 128]; + pub const KUSD_KEY: &[u8] = &[0, 129]; + } + + pub mod Statemine { + pub const ID: u32 = 1000; + pub const PALLET_ID: u8 = 50; + pub const RMRK_ID: u32 = 8; + } + + pub mod phala { + pub const ID: u32 = 2004; + } + + pub mod moonriver { + pub const ID: u32 = 2023; + pub const PALLET_ID: u8 = 10; + } + + //********************* + // Polkadot parachains + //********************* + pub mod moonbeam { + pub const ID: u32 = 2004; + pub const PALLET_ID: u8 = 10; + } + + pub mod astar { + pub const ID: u32 = 2006; + pub const PALLET_ID: u8 = 34; + } + + pub mod manta { + pub const ID: u32 = 2104; + pub const PALLET_ID: u8 = 10; + } +} + +pub trait XcmHelper { + fn contribute( + contributer: AccountId, + index: ChainId, + value: Balance, + ) -> Result; +} + +pub trait SalpHelper { + fn confirm_contribute_call() -> RuntimeCall; + fn bind_query_id_and_contribution( + query_id: QueryId, + index: ChainId, + contributer: AccountId, + amount: Balance, + ); +} diff --git a/runtime/bifrost-kusama/src/xcm_config.rs b/runtime/bifrost-kusama/src/xcm_config.rs index edecccb34..1418edab6 100644 --- a/runtime/bifrost-kusama/src/xcm_config.rs +++ b/runtime/bifrost-kusama/src/xcm_config.rs @@ -19,7 +19,7 @@ use super::*; use bifrost_asset_registry::{AssetIdMaps, FixedRateOfAsset}; use bifrost_primitives::{AccountId, CurrencyId, CurrencyIdMapping, TokenSymbol}; -pub use bifrost_xcm_interface::traits::{parachains, XcmBaseWeight}; +pub use bifrost_primitives::{parachains, XcmBaseWeight}; pub use cumulus_primitives_core::ParaId; use frame_support::{ ensure, parameter_types, diff --git a/runtime/bifrost-polkadot/src/xcm_config.rs b/runtime/bifrost-polkadot/src/xcm_config.rs index 22d7e397e..f3dc1bf96 100644 --- a/runtime/bifrost-polkadot/src/xcm_config.rs +++ b/runtime/bifrost-polkadot/src/xcm_config.rs @@ -21,7 +21,7 @@ use bifrost_asset_registry::AssetIdMaps; use bifrost_primitives::{ AccountId, CurrencyId, CurrencyIdMapping, TokenSymbol, DOT_TOKEN_ID, GLMR_TOKEN_ID, }; -pub use bifrost_xcm_interface::traits::{parachains, XcmBaseWeight}; +pub use bifrost_primitives::{parachains, XcmBaseWeight}; use cumulus_primitives_core::AggregateMessageOrigin; pub use cumulus_primitives_core::ParaId; use frame_support::{