Skip to content

Commit

Permalink
Fix vASTR
Browse files Browse the repository at this point in the history
  • Loading branch information
hqwangningbo committed Sep 18, 2023
1 parent e7ae241 commit 3c8b77f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
45 changes: 22 additions & 23 deletions pallets/slp/src/agents/astar_agent/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -131,10 +132,7 @@ impl<T: Config>
let smart_contract = SmartContract::<T::AccountId>::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.
Expand Down Expand Up @@ -206,10 +204,8 @@ impl<T: Config>
// Construct xcm message.
let contract_h160 = Pallet::<T>::multilocation_to_h160_account(&contract_multilocation)?;
let smart_contract = SmartContract::<T::AccountId>::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.
Expand Down Expand Up @@ -410,19 +406,13 @@ impl<T: Config>
// 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::<T>::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
Expand Down Expand Up @@ -897,17 +887,26 @@ impl<T: Config> AstarAgent<T> {
amount: BalanceOf<T>,
currency_id: CurrencyId,
) -> Result<(), Error<T>> {
// Ensure amount is greater than zero.
ensure!(!amount.is_zero(), Error::<T>::AmountZero);

// Prepare parameter dest and beneficiary.
let dest = Self::get_astar_multilocation();
let entrance_account = Pallet::<T>::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::<T>::multilocation_to_account_32(to)?;

let dest = MultiLocation {
parents: 1,
interior: X2(
Parachain(parachains::astar::ID),
AccountId32 { network: None, id: to_32 },
),
};

Pallet::<T>::inner_do_transfer_to(from, to, amount, currency_id, assets, &dest)
T::XcmTransfer::transfer(entrance_account, currency_id, amount, dest, Unlimited)
.map_err(|_| Error::<T>::TransferToError)?;

Ok(())
}

fn inner_construct_xcm_message(extra_fee: BalanceOf<T>) -> Vec<Instruction> {
Expand Down
8 changes: 4 additions & 4 deletions pallets/slp/src/agents/astar_agent/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// 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::Config;
use crate::{BalanceOf, Config};
use codec::{Decode, Encode};
use frame_support::RuntimeDebug;
use scale_info::TypeInfo;
Expand Down Expand Up @@ -45,15 +45,15 @@ pub enum AstarUtilityCall<AstarCall> {
#[derive(Encode, Decode, RuntimeDebug, Clone)]
pub enum AstarDappsStakingCall<T: Config> {
#[codec(index = 3)]
BondAndStake(SmartContract<T::AccountId>, #[codec(compact)] u128),
BondAndStake(SmartContract<T::AccountId>, #[codec(compact)] BalanceOf<T>),
#[codec(index = 4)]
UnbondAndUnstake(SmartContract<T::AccountId>, #[codec(compact)] u128),
UnbondAndUnstake(SmartContract<T::AccountId>, #[codec(compact)] BalanceOf<T>),
#[codec(index = 5)]
WithdrawUnbonded,
#[codec(index = 6)]
NominationTransfer(
SmartContract<T::AccountId>,
#[codec(compact)] u128,
#[codec(compact)] BalanceOf<T>,
SmartContract<T::AccountId>,
),
#[codec(index = 7)]
Expand Down
2 changes: 2 additions & 0 deletions pallets/slp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ pub mod pallet {
AmountNotProvided,
FailToConvert,
ExceedMaxLengthLimit,
/// Transfer to failed
TransferToError,
}

#[pallet::event]
Expand Down

0 comments on commit 3c8b77f

Please sign in to comment.