Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flexible fee with extra fee #1032

Merged
merged 12 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

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

6 changes: 2 additions & 4 deletions integration-tests/bifrost-kusama/src/slp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,9 @@ delegate/undelegate/redelegate confirm_validators_by_delegator_query_response

#![cfg(test)]
use bifrost_kusama_runtime::{NativeCurrencyId, VtokenMinting};
use bifrost_slp::{
primitives::UnlockChunk, Delays, Ledger, MinimumsMaximums, SubstrateLedger, XcmOperation,
};
use bifrost_slp::{primitives::UnlockChunk, Delays, Ledger, MinimumsMaximums, SubstrateLedger};
use frame_support::{assert_ok, BoundedVec};
use node_primitives::TimeUnit;
use node_primitives::{TimeUnit, XcmInterfaceOperation as XcmOperation};
use orml_traits::MultiCurrency;
use pallet_staking::{Nominations, StakingLedger};
use sp_runtime::Permill;
Expand Down
8 changes: 8 additions & 0 deletions integration-tests/bifrost-kusama/src/statemine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use crate::{kusama_integration_tests::*, kusama_test_net::*};
use bifrost_asset_registry::AssetMetadata;
use frame_support::assert_ok;
use node_primitives::XcmInterfaceOperation as XcmOperation;
use polkadot_parachain::primitives::Sibling;
use sp_runtime::traits::AccountIdConversion;
use xcm::{
Expand Down Expand Up @@ -130,6 +131,13 @@ fn cross_usdt() {
&sp_runtime::AccountId32::from(ALICE),
10 * USDT
));

assert_ok!(XcmInterface::set_xcm_dest_weight_and_fee(
RelayCurrencyId::get(),
XcmOperation::StatemineTransfer,
Some((Weight::from_parts(10000000000, 1000000), 10_000_000_000)),
));

assert_ok!(XcmInterface::transfer_statemine_assets(
RuntimeOrigin::signed(ALICE.into()),
5 * USDT,
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/bifrost-kusama/src/vtoken_voting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use frame_support::{
traits::{schedule::DispatchTime, StorePreimage},
weights::Weight,
};
use node_primitives::currency::VKSM;
use node_primitives::{currency::VKSM, XcmInterfaceOperation as XcmOperation};
use pallet_conviction_voting::{Conviction, Vote};
use xcm::v3::Parent;
use xcm_emulator::TestExt;
Expand Down Expand Up @@ -70,7 +70,7 @@ fn vote_works() {
assert_ok!(Slp::set_xcm_dest_weight_and_fee(
RuntimeOrigin::root(),
token,
bifrost_slp::XcmOperation::Vote,
XcmOperation::VoteVtoken,
Some((Weight::from_parts(4000000000, 100000), 4000000000u32.into())),
));
assert_ok!(Slp::set_minimums_and_maximums(
Expand Down
45 changes: 45 additions & 0 deletions node/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ pub type DistributionId = u32;
pub enum ExtraFeeName {
SalpContribute,
StatemineTransfer,
VoteVtoken,
VoteRemoveDelegatorVote,
NoExtraFee,
}

Expand Down Expand Up @@ -236,3 +238,46 @@ impl SendXcm for DoNothingRouter {
Ok([0; 32])
}
}

#[derive(Encode, Decode, Eq, PartialEq, Copy, Clone, RuntimeDebug, TypeInfo)]
pub enum XcmInterfaceOperation {
// SALP operations
UmpContributeTransact,
// Statemine operations
StatemineTransfer,
// SLP operations
Bond,
WithdrawUnbonded,
BondExtra,
Unbond,
Rebond,
Delegate,
Payout,
Liquidize,
TransferBack,
TransferTo,
Chill,
Undelegate,
CancelLeave,
XtokensTransferBack,
ExecuteLeave,
ConvertAsset,
// VtokenVoting operations
VoteVtoken,
VoteRemoveDelegatorVote,
Any,
}

pub struct ExtraFeeInfo {
pub extra_fee_name: ExtraFeeName,
pub extra_fee_currency: CurrencyId,
}

impl Default for ExtraFeeInfo {
fn default() -> Self {
Self {
extra_fee_name: ExtraFeeName::NoExtraFee,
extra_fee_currency: CurrencyId::Native(TokenSymbol::BNC),
}
}
}
48 changes: 45 additions & 3 deletions node/primitives/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@

#![allow(clippy::unnecessary_cast)]

use crate::{
AssetIds, ExtraFeeInfo, LeasePeriod, ParaId, PoolId, RedeemType, TokenId, TokenSymbol,
XcmInterfaceOperation,
};
use codec::{Decode, Encode, FullCodec};
use frame_support::{
dispatch::DispatchError,
pallet_prelude::DispatchResultWithPostInfo,
pallet_prelude::{DispatchResultWithPostInfo, Weight},
sp_runtime::{traits::AccountIdConversion, TokenError, TypeId},
};
use sp_runtime::{
Expand All @@ -32,8 +36,6 @@ use sp_runtime::{
};
use sp_std::{fmt::Debug, vec::Vec};

use crate::{AssetIds, LeasePeriod, ParaId, PoolId, RedeemType, TokenId, TokenSymbol};

pub trait TokenInfo {
fn currency_id(&self) -> u64;
fn name(&self) -> Option<&str>;
Expand Down Expand Up @@ -421,3 +423,43 @@ pub trait TryConvertFrom<CurrencyId> {
where
Self: Sized;
}

pub trait XcmDestWeightAndFeeHandler<CurrencyId, Balance>
where
Balance: AtLeast32BitUnsigned,
{
fn get_operation_weight_and_fee(
token: CurrencyId,
operation: XcmInterfaceOperation,
) -> Option<(Weight, Balance)>;

fn set_xcm_dest_weight_and_fee(
currency_id: CurrencyId,
operation: XcmInterfaceOperation,
weight_and_fee: Option<(Weight, Balance)>,
) -> DispatchResult;
}

impl<CurrencyId, Balance> XcmDestWeightAndFeeHandler<CurrencyId, Balance> for ()
where
Balance: AtLeast32BitUnsigned,
{
fn get_operation_weight_and_fee(
_token: CurrencyId,
_operation: XcmInterfaceOperation,
) -> Option<(Weight, Balance)> {
Some((Zero::zero(), Zero::zero()))
}

fn set_xcm_dest_weight_and_fee(
_currency_id: CurrencyId,
_operation: XcmInterfaceOperation,
_weight_and_fee: Option<(Weight, Balance)>,
) -> DispatchResult {
Ok(())
}
}

pub trait FeeGetter<RuntimeCall> {
fn get_fee_info(call: &RuntimeCall) -> ExtraFeeInfo;
}
1 change: 1 addition & 0 deletions pallets/fee-share/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ impl bifrost_slp::Config for Runtime {
type ParachainStaking = ();
type XcmTransfer = XTokens;
type MaxLengthLimit = MaxLengthLimit;
type XcmWeightAndFeeHandler = ();
}

parameter_type_with_key! {
Expand Down
2 changes: 1 addition & 1 deletion pallets/flexible-fee/rpc/runtime-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ decl_runtime_apis! {
AccountId: Codec,
{
/// get flexible fee token and amount to be deducted
fn get_fee_token_and_amount(who: AccountId, fee: Balance) -> (CurrencyId, Balance);
fn get_fee_token_and_amount(who: AccountId, fee: Balance, utx: Block::Extrinsic) -> (CurrencyId, Balance);
}
}
4 changes: 2 additions & 2 deletions pallets/flexible-fee/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ where
))
})?;

let fee_details = api.query_fee_details(at, uxt, encoded_len).map_err(|e| {
let fee_details = api.query_fee_details(at, uxt.clone(), encoded_len).map_err(|e| {
CallError::Custom(ErrorObject::owned(
Error::RuntimeError.into(),
"Unable to query fee details.",
Expand All @@ -127,7 +127,7 @@ where
}
};

let rs = api.get_fee_token_and_amount(at, who, total_inclusion_fee);
let rs = api.get_fee_token_and_amount(at, who, total_inclusion_fee, uxt);

let try_into_rpc_balance = |value: Balance| {
value.try_into().map_err(|e| {
Expand Down
Loading