Skip to content

Commit

Permalink
Moved several traits from pallets to primitives/src/traits
Browse files Browse the repository at this point in the history
  • Loading branch information
MJLNSN committed Jul 6, 2024
1 parent 0fca212 commit 5cad3d9
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 188 deletions.
1 change: 0 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"makefile.extensionOutputFolder": "./.vscode",
"rust-analyzer.cargo.features": "all",
"rust-analyzer.checkOnSave": false
}
2 changes: 1 addition & 1 deletion pallets/parachain-staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ pub mod pallet {
Range,
WeightInfo,
};
use bifrost_primitives::parachain_staking::*; // add
use bifrost_primitives::parachain_staking::*;

/// Pallet for parachain staking
#[pallet::pallet]
Expand Down
2 changes: 1 addition & 1 deletion pallets/slp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub use crate::{
};
use bifrost_asset_registry::AssetMetadata;
use bifrost_parachain_staking::ParachainStakingInterface;
pub use bifrost_primitives::slp::{OnRefund, QueryResponseManager, StakingAgent}; // add
pub use bifrost_primitives::slp::{OnRefund, QueryResponseManager, StakingAgent};
use bifrost_primitives::{
currency::{BNC, KSM, MANTA, MOVR, PHA},
traits::XcmDestWeightAndFeeHandler,
Expand Down
157 changes: 1 addition & 156 deletions pallets/stable-pool/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,75 +18,7 @@

//! 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<Self::Balance>,
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<Self::Balance>,
max_redeem_amount: Self::Balance,
) -> DispatchResult;

fn redeem_proportion(
who: Self::AccountId,
pool_id: StableAssetPoolId,
amount: Self::Balance,
min_redeem_amounts: Vec<Self::Balance>,
) -> DispatchResult;

fn get_pool_token_index(
pool_id: StableAssetPoolId,
currency_id: CurrencyId,
) -> Option<PoolTokenIndex>;

fn get_swap_output(
pool_id: StableAssetPoolId,
currency_id_in: PoolTokenIndex,
currency_id_out: PoolTokenIndex,
amount: Self::Balance,
) -> Result<Self::Balance, DispatchError>;

fn get_swap_input(
pool_id: StableAssetPoolId,
currency_id_in: PoolTokenIndex,
currency_id_out: PoolTokenIndex,
amount: Self::Balance,
) -> Result<Self::Balance, DispatchError>;

fn get_pool_id(
currency_id_in: &Self::CurrencyId,
currency_id_out: &Self::CurrencyId,
) -> Option<(StableAssetPoolId, PoolTokenIndex, PoolTokenIndex)>;
}
pub use bifrost_primitives::StablePoolHandler;

impl<T: Config> StablePoolHandler for Pallet<T> {
type Balance = T::Balance;
Expand Down Expand Up @@ -179,90 +111,3 @@ impl<T: Config> StablePoolHandler for Pallet<T> {
Self::get_pool_id(currency_id_in, currency_id_out)
}
}

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<Self::Balance>,
_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<Self::Balance>,
_max_redeem_amount: Self::Balance,
) -> DispatchResult {
Ok(())
}

fn redeem_proportion(
_who: Self::AccountId,
_pool_id: StableAssetPoolId,
_amount: Self::Balance,
_min_redeem_amounts: Vec<Self::Balance>,
) -> DispatchResult {
Ok(())
}

fn get_pool_token_index(
_pool_id: StableAssetPoolId,
_currency_id: CurrencyId,
) -> Option<PoolTokenIndex> {
None
}

fn get_swap_output(
_pool_id: StableAssetPoolId,
_currency_id_in: PoolTokenIndex,
_currency_id_out: PoolTokenIndex,
_amount: Self::Balance,
) -> Result<Self::Balance, DispatchError> {
Ok(0)
}

fn get_swap_input(
_pool_id: StableAssetPoolId,
_currency_id_in: PoolTokenIndex,
_currency_id_out: PoolTokenIndex,
_amount: Self::Balance,
) -> Result<Self::Balance, DispatchError> {
Ok(0)
}

fn get_pool_id(
_currency_id_in: &Self::CurrencyId,
_currency_id_out: &Self::CurrencyId,
) -> Option<(StableAssetPoolId, PoolTokenIndex, PoolTokenIndex)> {
None
}
}
5 changes: 2 additions & 3 deletions pallets/vtoken-minting/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ mod tests;
mod benchmarking;

pub mod migration;
pub mod traits;
pub mod weights;
pub use weights::WeightInfo;

use bifrost_asset_registry::AssetMetadata;
pub use bifrost_primitives::vtoken_minting::*;
use bifrost_primitives::{
CurrencyId, CurrencyIdConversion, CurrencyIdExt, CurrencyIdMapping, CurrencyIdRegister,
RedeemType, SlpOperator, SlpxOperator, TimeUnit, VTokenMintRedeemProvider,
RedeemTo, RedeemType, SlpOperator, SlpxOperator, TimeUnit, VTokenMintRedeemProvider,
VTokenSupplyProvider, VtokenMintingInterface, VtokenMintingOperator,
};
use bifrost_ve_minting::traits::VeMintingInterface;
Expand All @@ -57,7 +57,6 @@ use orml_traits::{MultiCurrency, MultiLockableCurrency};
pub use pallet::*;
use sp_core::U256;
use sp_std::{vec, vec::Vec};
pub use traits::*;
use xcm::v3::MultiLocation;

pub type AccountIdOf<T> = <T as frame_system::Config>::AccountId;
Expand Down
10 changes: 4 additions & 6 deletions primitives/src/traits/mod.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
pub mod parachain_staking;
pub mod slp;
pub mod stable_pool;
pub mod traits;
// pub mod stable_pool;
// pub mod ve_minting;
// pub mod vtoken_minting;
pub mod vtoken_minting;
pub mod xcm_interface;

pub use parachain_staking::*;
pub use slp::*;
pub use stable_pool::*;
pub use traits::*;
// pub use stable_pool::*;
// pub use ve_minting::*;
// pub use vtoken_minting::*;
pub use vtoken_minting::*;
pub use xcm_interface::*;
88 changes: 88 additions & 0 deletions primitives/src/traits/stable_pool.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// 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 <https://www.gnu.org/licenses/>.

use crate::*;

pub trait StablePoolHandler {
type Balance;
type AccountId;
type CurrencyId;

fn add_liquidity(
who: Self::AccountId,
pool_id: StableAssetPoolId,
amounts: Vec<Self::Balance>,
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<Self::Balance>,
max_redeem_amount: Self::Balance,
) -> DispatchResult;

fn redeem_proportion(
who: Self::AccountId,
pool_id: StableAssetPoolId,
amount: Self::Balance,
min_redeem_amounts: Vec<Self::Balance>,
) -> DispatchResult;

fn get_pool_token_index(
pool_id: StableAssetPoolId,
currency_id: CurrencyId,
) -> Option<PoolTokenIndex>;

fn get_swap_output(
pool_id: StableAssetPoolId,
currency_id_in: PoolTokenIndex,
currency_id_out: PoolTokenIndex,
amount: Self::Balance,
) -> Result<Self::Balance, DispatchError>;

fn get_swap_input(
pool_id: StableAssetPoolId,
currency_id_in: PoolTokenIndex,
currency_id_out: PoolTokenIndex,
amount: Self::Balance,
) -> Result<Self::Balance, DispatchError>;

fn get_pool_id(
currency_id_in: &Self::CurrencyId,
currency_id_out: &Self::CurrencyId,
) -> Option<(StableAssetPoolId, PoolTokenIndex, PoolTokenIndex)>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,7 @@

// 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;

#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, scale_info::TypeInfo)]
pub enum RedeemTo<AccountId> {
/// Native chain.
Native(AccountId),
/// Astar chain.
Astar(AccountId),
/// Moonbeam chain.
Moonbeam(H160),
/// Hydradx chain.
Hydradx(AccountId),
/// Interlay chain.
Interlay(AccountId),
/// Manta chain.
Manta(AccountId),
}
use crate::Weight;

pub trait OnRedeemSuccess<AccountId, CurrencyId, Balance> {
fn on_redeem_success(
Expand Down

0 comments on commit 5cad3d9

Please sign in to comment.