From 51b7a58e36623ef1531a429a5c329412293b76b4 Mon Sep 17 00:00:00 2001 From: NingBo Wang <2536935847@qq.com> Date: Mon, 18 Sep 2023 21:29:34 +0800 Subject: [PATCH] Fix vASTR (#1049) --- Makefile | 2 +- pallets/slp/src/agents/astar_agent/agent.rs | 45 ++++++++++----------- pallets/slp/src/agents/astar_agent/types.rs | 8 ++-- pallets/slp/src/lib.rs | 2 + 4 files changed, 29 insertions(+), 28 deletions(-) diff --git a/Makefile b/Makefile index 394a17bbf..0f86041ac 100644 --- a/Makefile +++ b/Makefile @@ -39,7 +39,7 @@ test-runtimes: .PHONY: test-benchmarks test-benchmarks: - cargo test --all benchmarking --features="with-all-runtime,runtime-benchmarks, polkadot" --exclude "*-integration-tests" + cargo test --all benchmarking --features="runtime-benchmarks, polkadot" --exclude "*-integration-tests" --exclude "node-*" --exclude "*-runtime" .PHONY: integration-test # integration test integration-test: diff --git a/pallets/slp/src/agents/astar_agent/agent.rs b/pallets/slp/src/agents/astar_agent/agent.rs index 3dfe8b4c8..5985204aa 100644 --- a/pallets/slp/src/agents/astar_agent/agent.rs +++ b/pallets/slp/src/agents/astar_agent/agent.rs @@ -37,12 +37,13 @@ use frame_system::pallet_prelude::BlockNumberFor; use node_primitives::{ CurrencyId, VtokenMintingOperator, XcmDestWeightAndFeeHandler, XcmOperationType, ASTR_TOKEN_ID, }; +use orml_traits::XcmTransfer; use polkadot_parachain::primitives::Sibling; use sp_runtime::{ traits::{ AccountIdConversion, CheckedAdd, CheckedSub, Convert, Saturating, UniqueSaturatedInto, Zero, }, - DispatchResult, SaturatedConversion, + DispatchResult, }; use sp_std::prelude::*; use xcm::{ @@ -131,10 +132,7 @@ impl let smart_contract = SmartContract::::Evm(contract_h160); // Construct xcm message. - let call = AstarCall::Staking(AstarDappsStakingCall::BondAndStake( - smart_contract, - amount.saturated_into(), - )); + let call = AstarCall::Staking(AstarDappsStakingCall::BondAndStake(smart_contract, amount)); // Wrap the xcm message as it is sent from a subaccount of the parachain account, and // send it out. @@ -206,10 +204,8 @@ impl // Construct xcm message. let contract_h160 = Pallet::::multilocation_to_h160_account(&contract_multilocation)?; let smart_contract = SmartContract::::Evm(contract_h160); - let call = AstarCall::Staking(AstarDappsStakingCall::UnbondAndUnstake( - smart_contract, - amount.saturated_into(), - )); + let call = + AstarCall::Staking(AstarDappsStakingCall::UnbondAndUnstake(smart_contract, amount)); // Wrap the xcm message as it is sent from a subaccount of the parachain account, and // send it out. @@ -410,19 +406,13 @@ impl // Prepare parameter fee_asset_item. let fee_asset_item: u32 = 0; - let (weight_limit, _) = T::XcmWeightAndFeeHandler::get_operation_weight_and_fee( - currency_id, - XcmOperationType::TransferBack, - ) - .ok_or(Error::::WeightAndFeeNotExists)?; - // Construct xcm message. let call = AstarCall::Xcm(Box::new(XcmCall::LimitedReserveTransferAssets( dest, beneficiary, assets, fee_asset_item, - Limited(weight_limit), + Unlimited, ))); // Wrap the xcm message as it is sent from a subaccount of the parachain account, and @@ -897,17 +887,26 @@ impl AstarAgent { amount: BalanceOf, currency_id: CurrencyId, ) -> Result<(), Error> { + // Ensure amount is greater than zero. + ensure!(!amount.is_zero(), Error::::AmountZero); + // Prepare parameter dest and beneficiary. - let dest = Self::get_astar_multilocation(); + let entrance_account = Pallet::::multilocation_to_account(from)?; - // Prepare parameter assets. - let assets = { - let asset = - MultiAsset { fun: Fungible(amount.unique_saturated_into()), id: Concrete(dest) }; - MultiAssets::from(asset) + let to_32: [u8; 32] = Pallet::::multilocation_to_account_32(to)?; + + let dest = MultiLocation { + parents: 1, + interior: X2( + Parachain(parachains::astar::ID), + AccountId32 { network: None, id: to_32 }, + ), }; - Pallet::::inner_do_transfer_to(from, to, amount, currency_id, assets, &dest) + T::XcmTransfer::transfer(entrance_account, currency_id, amount, dest, Unlimited) + .map_err(|_| Error::::TransferToError)?; + + Ok(()) } fn inner_construct_xcm_message(extra_fee: BalanceOf) -> Vec { diff --git a/pallets/slp/src/agents/astar_agent/types.rs b/pallets/slp/src/agents/astar_agent/types.rs index 2490a1c15..95aea6bc9 100644 --- a/pallets/slp/src/agents/astar_agent/types.rs +++ b/pallets/slp/src/agents/astar_agent/types.rs @@ -16,7 +16,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::Config; +use crate::{BalanceOf, Config}; use codec::{Decode, Encode}; use frame_support::RuntimeDebug; use scale_info::TypeInfo; @@ -45,15 +45,15 @@ pub enum AstarUtilityCall { #[derive(Encode, Decode, RuntimeDebug, Clone)] pub enum AstarDappsStakingCall { #[codec(index = 3)] - BondAndStake(SmartContract, #[codec(compact)] u128), + BondAndStake(SmartContract, #[codec(compact)] BalanceOf), #[codec(index = 4)] - UnbondAndUnstake(SmartContract, #[codec(compact)] u128), + UnbondAndUnstake(SmartContract, #[codec(compact)] BalanceOf), #[codec(index = 5)] WithdrawUnbonded, #[codec(index = 6)] NominationTransfer( SmartContract, - #[codec(compact)] u128, + #[codec(compact)] BalanceOf, SmartContract, ), #[codec(index = 7)] diff --git a/pallets/slp/src/lib.rs b/pallets/slp/src/lib.rs index 3b5f43d89..933e1f7f4 100644 --- a/pallets/slp/src/lib.rs +++ b/pallets/slp/src/lib.rs @@ -239,6 +239,8 @@ pub mod pallet { AmountNotProvided, FailToConvert, ExceedMaxLengthLimit, + /// Transfer to failed + TransferToError, } #[pallet::event]