From 43d4d1c8c11a25e02d7f85349d274fb3768b2052 Mon Sep 17 00:00:00 2001 From: yooml Date: Mon, 2 Dec 2024 10:22:18 +0800 Subject: [PATCH] Bifrost v0.15.1 (#1514) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: 💡 update MaximumUnlockIdOfTimeUnit * refactor: 💡 cli * Fix slp transfer back (#1518) * Fix slp transfer_back * Vtoken minting redeem_amount must be greater than entrance_account_balance --------- Co-authored-by: NingBo Wang <2536935847@qq.com> --- Cargo.lock | 2 +- node/cli/Cargo.toml | 2 +- .../agents/parachain_staking_agent/agent.rs | 43 +++++++++++++------ .../types/moonbeam_types.rs | 29 ++++++------- pallets/vtoken-minting/src/impls.rs | 2 +- runtime/bifrost-kusama/src/lib.rs | 8 +--- runtime/bifrost-polkadot/src/lib.rs | 7 +-- 7 files changed, 48 insertions(+), 45 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1a525cb65..e0ca122fc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1025,7 +1025,7 @@ dependencies = [ [[package]] name = "bifrost-cli" -version = "0.15.0" +version = "0.15.1" dependencies = [ "bifrost-primitives", "bifrost-service", diff --git a/node/cli/Cargo.toml b/node/cli/Cargo.toml index 8411d2a18..9472dabfe 100644 --- a/node/cli/Cargo.toml +++ b/node/cli/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bifrost-cli" -version = "0.15.0" +version = "0.15.1" authors = ["Liebi Technologies "] description = "Bifrost Parachain Node" build = "build.rs" diff --git a/pallets/slp/src/agents/parachain_staking_agent/agent.rs b/pallets/slp/src/agents/parachain_staking_agent/agent.rs index f88245f27..b27f51ccf 100644 --- a/pallets/slp/src/agents/parachain_staking_agent/agent.rs +++ b/pallets/slp/src/agents/parachain_staking_agent/agent.rs @@ -16,9 +16,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use super::types::{ - MoonbeamCall, MoonbeamCurrencyId, MoonbeamParachainStakingCall, MoonbeamXtokensCall, -}; +use super::types::{MoonbeamCall, MoonbeamParachainStakingCall, PolkadotXcmCall}; use crate::{ agents::{MantaCall, MantaCurrencyId, MantaParachainStakingCall, MantaXtokensCall}, pallet::{Error, Event}, @@ -48,11 +46,13 @@ use sp_runtime::{ }; use sp_std::prelude::*; use xcm::{ + latest::{AssetId, Assets}, opaque::v3::{ Junction::{AccountId32, Parachain}, MultiLocation, }, v3::prelude::*, + v4::Asset, VersionedLocation, }; @@ -1370,6 +1370,8 @@ impl // Make sure the receiving account is the Exit_account from vtoken-minting module. let (entrance_account, _) = T::VtokenMinting::get_entrance_and_exit_accounts(); + let entrance_account_id = + entrance_account.encode().try_into().map_err(|_| Error::::FailToConvert)?; if currency_id == BNC { let from_account = Pallet::::multilocation_to_account(from)?; @@ -1381,22 +1383,35 @@ impl parents: 1, interior: X2( Parachain(T::ParachainId::get().into()), - AccountId32 { - network: None, - id: entrance_account - .encode() - .try_into() - .map_err(|_| Error::::FailToConvert)?, - }, + AccountId32 { network: None, id: entrance_account_id }, ), })); // Construct xcm message. let call: Vec = match currency_id { - MOVR | GLMR => MoonbeamCall::Xtokens(MoonbeamXtokensCall::::Transfer( - MoonbeamCurrencyId::SelfReserve, - amount.unique_saturated_into(), - dest, + MOVR | GLMR => MoonbeamCall::::PolkadotXcm(PolkadotXcmCall::TransferAssets( + Box::new( + Location::new(1, X1(Parachain(T::ParachainId::get().into()))) + .into_versioned(), + ), + Box::new( + Location::new( + 0, + X1(AccountId32 { network: None, id: entrance_account_id }), + ) + .into_versioned(), + ), + Box::new( + Assets::from(vec![Asset { + id: AssetId(xcm::v4::Location::new( + 0, + xcm::v4::prelude::PalletInstance(10), + )), + fun: xcm::v4::Fungibility::Fungible(amount.unique_saturated_into()), + }]) + .into(), + ), + 0, Unlimited, )) .encode() diff --git a/pallets/slp/src/agents/parachain_staking_agent/types/moonbeam_types.rs b/pallets/slp/src/agents/parachain_staking_agent/types/moonbeam_types.rs index abb20ae39..2c12f6d03 100644 --- a/pallets/slp/src/agents/parachain_staking_agent/types/moonbeam_types.rs +++ b/pallets/slp/src/agents/parachain_staking_agent/types/moonbeam_types.rs @@ -18,7 +18,6 @@ use crate::{BalanceOf, Config}; use parity_scale_codec::{Decode, Encode}; -use scale_info::TypeInfo; use sp_arithmetic::Percent; use sp_core::H160; use sp_runtime::{ @@ -26,7 +25,7 @@ use sp_runtime::{ RuntimeDebug, }; use sp_std::{boxed::Box, vec::Vec}; -use xcm::{opaque::v3::WeightLimit, VersionedLocation}; +use xcm::{opaque::v3::WeightLimit, VersionedAssets, VersionedLocation}; #[derive(Encode, Decode, RuntimeDebug, Clone)] pub enum MoonbeamCall { @@ -36,8 +35,8 @@ pub enum MoonbeamCall { Staking(MoonbeamParachainStakingCall), #[codec(index = 30)] Utility(Box>), - #[codec(index = 106)] - Xtokens(MoonbeamXtokensCall), + #[codec(index = 103)] + PolkadotXcm(PolkadotXcmCall), } impl MoonbeamCall { @@ -89,17 +88,13 @@ pub enum MoonbeamParachainStakingCall { } #[derive(Encode, Decode, RuntimeDebug, Clone)] -pub enum MoonbeamXtokensCall { - #[codec(index = 0)] - Transfer(MoonbeamCurrencyId, BalanceOf, Box, WeightLimit), -} - -#[derive(PartialEq, Eq, Copy, Clone, Encode, Decode, RuntimeDebug, TypeInfo)] -pub enum MoonbeamCurrencyId { - // Our native token - SelfReserve, - // Assets representing other chains native tokens - ForeignAsset(u128), - // Our local assets - LocalAssetReserve(u128), +pub enum PolkadotXcmCall { + #[codec(index = 11)] + TransferAssets( + Box, + Box, + Box, + u32, + WeightLimit, + ), } diff --git a/pallets/vtoken-minting/src/impls.rs b/pallets/vtoken-minting/src/impls.rs index 54efa07e5..55bddc782 100644 --- a/pallets/vtoken-minting/src/impls.rs +++ b/pallets/vtoken-minting/src/impls.rs @@ -537,8 +537,8 @@ impl Pallet { &redeemer, redeem_currency_amount, )?; + return Ok((redeem_currency_amount, RedeemTo::Native(redeemer))); } - return Ok((redeem_currency_amount, RedeemTo::Native(redeemer))); } Ok((Default::default(), RedeemTo::Native(redeemer))) } diff --git a/runtime/bifrost-kusama/src/lib.rs b/runtime/bifrost-kusama/src/lib.rs index 41fbea8ef..eb91d96cb 100644 --- a/runtime/bifrost-kusama/src/lib.rs +++ b/runtime/bifrost-kusama/src/lib.rs @@ -164,7 +164,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("bifrost"), impl_name: create_runtime_str!("bifrost"), authoring_version: 1, - spec_version: 15000, + spec_version: 15001, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 1, @@ -1539,7 +1539,7 @@ impl bifrost_vtoken_minting::OnRedeemSuccess for parameter_types! { pub const MaximumUnlockIdOfUser: u32 = 10; - pub const MaximumUnlockIdOfTimeUnit: u32 = 50; + pub const MaximumUnlockIdOfTimeUnit: u32 = 1000; pub BifrostFeeAccount: AccountId = TreasuryPalletId::get().into_account_truncating(); } @@ -2000,12 +2000,8 @@ pub mod migrations { /// Unreleased migrations. Add new ones here: pub type Unreleased = ( - bifrost_parachain_staking::migrations::RemoveDelegatorReserveToLockAndCollatorReserveToLock< - Runtime, - >, // permanent migration, do not remove pallet_xcm::migration::MigrateToLatestXcmVersion, - bifrost_flexible_fee::migrations::v3::MigrateToV3, ); } diff --git a/runtime/bifrost-polkadot/src/lib.rs b/runtime/bifrost-polkadot/src/lib.rs index 9a046b485..68bcdb986 100644 --- a/runtime/bifrost-polkadot/src/lib.rs +++ b/runtime/bifrost-polkadot/src/lib.rs @@ -188,7 +188,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("bifrost_polkadot"), impl_name: create_runtime_str!("bifrost_polkadot"), authoring_version: 0, - spec_version: 15000, + spec_version: 15001, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 1, @@ -1392,7 +1392,7 @@ impl bifrost_vtoken_minting::OnRedeemSuccess for parameter_types! { pub const MaximumUnlockIdOfUser: u32 = 10; - pub const MaximumUnlockIdOfTimeUnit: u32 = 50; + pub const MaximumUnlockIdOfTimeUnit: u32 = 1000; pub BifrostFeeAccount: AccountId = TreasuryPalletId::get().into_account_truncating(); } @@ -1902,9 +1902,6 @@ pub mod migrations { pub type Unreleased = ( // permanent migration, do not remove pallet_xcm::migration::MigrateToLatestXcmVersion, - bifrost_parachain_staking::migrations::InitGenesisMigration, - frame_support::migrations::RemovePallet, - bifrost_flexible_fee::migrations::v3::PolkadotMigrateToV3, ); }