Skip to content

Commit

Permalink
test baseline
Browse files Browse the repository at this point in the history
  • Loading branch information
MrishoLukamba committed Dec 18, 2023
1 parent 2f9c119 commit b3f2851
Show file tree
Hide file tree
Showing 46,511 changed files with 5,898,793 additions and 163 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
64 changes: 49 additions & 15 deletions pallets/vane-xcm-transfer-system/src/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub use utils::*;
pub mod utils {
use core::ops::Add;
use frame_support::parameter_types;
use sp_core::crypto::Ss58Codec;
use sp_core::{crypto::Ss58Codec, sr25519::Public};
use sp_std::ops::{Mul, Sub};
use frame_system::{AccountInfo, RawOrigin};
use sp_runtime::traits::{TrailingZeroInput};
Expand Down Expand Up @@ -339,20 +339,20 @@ use sp_std::ops::{Mul, Sub};

pub trait UnknownAssetTrait {
/// Deposit unknown asset.
fn deposit(asset: &MultiAsset, to: &MultiLocation) -> DispatchResult;
fn deposit(asset: &MultiAsset, to: &MultiLocation) -> staging_xcm::v3::Result;

/// Withdraw unknown asset.
fn withdraw(asset: &MultiAsset, from: &MultiLocation) -> DispatchResult;
fn withdraw(asset: &MultiAsset, from: &MultiLocation) -> staging_xcm::v3::Result;
}

const NO_UNKNOWN_ASSET_IMPL: &str = "NoUnknownAssetImpl";

impl UnknownAssetTrait for () {
fn deposit(_asset: &MultiAsset, _to: &MultiLocation) -> DispatchResult {
Err(DispatchError::Other(NO_UNKNOWN_ASSET_IMPL))
fn deposit(_asset: &MultiAsset, _to: &MultiLocation) -> staging_xcm::v3::Result {
Err(staging_xcm::v3::Error::Unimplemented)
}
fn withdraw(_asset: &MultiAsset, _from: &MultiLocation) -> DispatchResult {
Err(DispatchError::Other(NO_UNKNOWN_ASSET_IMPL))
fn withdraw(_asset: &MultiAsset, _from: &MultiLocation) -> staging_xcm::v3::Result {
Err(staging_xcm::v3::Error::Unimplemented)
}
}

Expand Down Expand Up @@ -384,7 +384,7 @@ use sp_std::ops::{Mul, Sub};
MultiCurrency: VaneMultiCurrency<AccountId, CurrencyId = CurrencyId>,
UnknownAsset: UnknownAssetTrait,
Match: MatchesFungible<MultiCurrency::Balance>,
AccountId: Debug + Clone,
AccountId: Debug + Clone + From<[u8; 32]> + Into<[u8; 32]>,
AccountIdConvert: ConvertLocation<AccountId>,
CurrencyId: FullCodec + Eq + PartialEq + Copy + Debug,
CurrencyIdConvert: Convert<MultiAsset, Option<CurrencyId>>,
Expand All @@ -402,17 +402,49 @@ use sp_std::ops::{Mul, Sub};
>
{
fn deposit_asset(asset: &MultiAsset, location: &MultiLocation, context: &XcmContext) -> staging_xcm::v3::Result {
let sender = context.origin;
//let sender = context.origin;

//let sender = context.origin;
log::info!(
"MultiLocation: {:?} \n Multi Asset: {:?}",
location,asset
);


let receiver =AccountIdConvert::convert_location(location);
let currency_id = CurrencyIdConvert::convert(asset.clone());
let amount = Match::matches_fungible(asset);

log::info!(
"receiver: {:?} \n currency_id: {:?} \n amount: {:?}",
receiver,currency_id,amount
);

// Quick Fix for now

let acc= match *location {
MultiLocation { parents: 0, interior: X1(AccountId32 { id, network: None }) } => id,
_ => unreachable!()
};

let cc = Public(acc);

log::info!(
"AccountConverted: {:?} ",
acc
);


match (
AccountIdConvert::convert_location(location),
CurrencyIdConvert::convert(asset.clone()),
Match::matches_fungible(asset),
) {

// known asset
(Some(receiver), Some(currency_id), Some(amount)) => Ok(MultiCurrency::deposit(currency_id, &receiver, amount).unwrap()),// DepositFailAsset handler
(Some(receiver), Some(currency_id), Some(amount)) => Ok(MultiCurrency::deposit(currency_id, &receiver, amount).map_err(|_| staging_xcm::v3::Error::InvalidLocation)?),// DepositFailAsset handler
// unknown asset
_ => Ok(UnknownAsset::deposit(asset, location).unwrap()), // DepositFailAsset handler
_ => Ok(UnknownAsset::deposit(asset, location)?), // DepositFailAsset handler
}
}

Expand Down Expand Up @@ -507,21 +539,22 @@ use sp_std::ops::{Mul, Sub};

// 1. Construct a multi id account
// send the funds from alice to the multi id account ( Alice, Bob)
//TBD

let to_account = T::Lookup::unlookup(to.clone());
//<pallet_assets::Pallet<T>>::transfer(origin,currency_id,to.into(),amount)
pallet_assets::Call::<T,()>::transfer {
id: currency_id,
target: to_account,
amount,
}.dispatch_bypass_filter(oo).unwrap();
}.dispatch_bypass_filter(oo).unwrap(); // error handling

Ok(())

}


fn deposit(currency_id: Self::CurrencyId, receiver: &T::AccountId, amount: Self::Balance) -> Result<(),DispatchError> {
fn deposit(currency_id: Self::CurrencyId, receiver: &T::AccountId, amount: Self::Balance) -> DispatchResult {


// Include neccessary fees
Expand All @@ -536,8 +569,9 @@ use sp_std::ops::{Mul, Sub};
pallet_balances::Call::<T,()>::transfer_keep_alive {
dest: T::Lookup::unlookup(receiver.clone()),
value: fees_amount
}.dispatch_bypass_filter(para_account_origin).unwrap(); // Error handling
}.dispatch_bypass_filter(para_account_origin).map_err(|_| Error::<T>::FailedToDepositFeesToAccount)?; // Error handling

// Deposit using Pallet Asset deposit function
let _ = <pallet_assets::Pallet<T>>::deposit(currency_id.into(), receiver, amount, Precision::Exact)?;
Ok(())
}
Expand Down Expand Up @@ -715,7 +749,7 @@ use sp_std::ops::{Mul, Sub};
pallet_balances::Call::<T,()>::transfer_keep_alive {
dest: T::Lookup::unlookup(payee.clone()),
value: fees_amount
}.dispatch_bypass_filter(para_account_origin).unwrap();
}.dispatch_bypass_filter(para_account_origin).map_err(|_| Error::<T>::FailedToDepositFeesToAccount)?;


let time = <frame_system::Pallet<T>>::block_number();
Expand Down
6 changes: 5 additions & 1 deletion pallets/vane-xcm-transfer-system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,11 @@ mod pallet{

MultiSigCallFailed,

TxnReceiptUnavailable
TxnReceiptUnavailable,

FailedToDepositFeesToAccount,

ParaAccountNotFound

}

Expand Down
7 changes: 4 additions & 3 deletions runtime/vane-parachain-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
#[cfg(test)]
mod xcm_eml_testing;

#[cfg(test)]
mod xcm_sim_testing;

mod weights;
pub mod xcm_config;
Expand Down Expand Up @@ -190,8 +191,8 @@ impl_opaque_keys! {

#[sp_version::runtime_version]
pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("template-parachain"),
impl_name: create_runtime_str!("template-parachain"),
spec_name: create_runtime_str!("vane-parachain"),
impl_name: create_runtime_str!("vane-parachain"),
authoring_version: 1,
spec_version: 1,
impl_version: 0,
Expand Down
2 changes: 1 addition & 1 deletion runtime/vane-parachain-runtime/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use sp_runtime::traits::{CheckedConversion, Convert};

parameter_types! {
pub const RelayLocation: MultiLocation = MultiLocation::parent();
pub const RelayNetwork: Option<NetworkId> = None;
pub const RelayNetwork: Option<NetworkId> = Some(NetworkId::Rococo);
pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();
pub UniversalLocation: InteriorMultiLocation = Parachain(ParachainInfo::parachain_id().into()).into();
}
Expand Down
5 changes: 4 additions & 1 deletion runtime/vane-parachain-runtime/src/xcm_eml_testing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,12 +457,15 @@ use super::*;
<Rococo as RococoPallet>::XcmPallet::reserve_transfer_assets(
alice_relay_origin,
bx!(vane_destination.into()),
bx!(AccountId32 { network: None, id: alice_account.into() }.into()),
bx!(AccountId32 { network: None, id: alice_account.clone().into() }.into()),
bx!((Here, amount).into()),
0,
)
);

let teste: MultiLocation = AccountId32 { network: None, id: alice_account.into() }.into();
println!("Account teste: {:?}",teste);


RococoPalletSystem::events().iter().for_each(|e| println!("{:#?} \n",e));

Expand Down
Loading

0 comments on commit b3f2851

Please sign in to comment.