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

implement SubstrateMultihopXcmHandler for pallet multihop xcm ibc #3764

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
36 changes: 18 additions & 18 deletions code/Cargo.lock

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

12 changes: 6 additions & 6 deletions code/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ orml-xcm-support = { git = "https://github.com/open-web3-stack/open-runtime-modu
orml-xtokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "a0751540591c88ccc2d4029464de887933727183", default-features = false }
orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "a0751540591c88ccc2d4029464de887933727183", default-features = false }

ibc = { git = "https://github.com/ComposableFi/centauri", rev = "604fc78d4ab36573793ee91484258898cce67ca0", default-features = false }
ibc-rpc = { git = "https://github.com/ComposableFi/centauri", rev = "604fc78d4ab36573793ee91484258898cce67ca0", default-features = false }
ibc-primitives = { git = "https://github.com/ComposableFi/centauri", rev = "604fc78d4ab36573793ee91484258898cce67ca0", default-features = false }
ibc-runtime-api = { git = "https://github.com/ComposableFi/centauri", rev = "604fc78d4ab36573793ee91484258898cce67ca0", default-features = false }
pallet-ibc = { git = "https://github.com/ComposableFi/centauri", rev = "604fc78d4ab36573793ee91484258898cce67ca0", default-features = false }
pallet-ibc-ping = { git = "https://github.com/ComposableFi/centauri", rev = "604fc78d4ab36573793ee91484258898cce67ca0", default-features = false }
ibc = { git = "https://github.com/ComposableFi/centauri", rev = "e19da8da70461dce572648035a8325a19ff9ed23", default-features = false }
ibc-rpc = { git = "https://github.com/ComposableFi/centauri", rev = "e19da8da70461dce572648035a8325a19ff9ed23", default-features = false }
ibc-primitives = { git = "https://github.com/ComposableFi/centauri", rev = "e19da8da70461dce572648035a8325a19ff9ed23", default-features = false }
ibc-runtime-api = { git = "https://github.com/ComposableFi/centauri", rev = "e19da8da70461dce572648035a8325a19ff9ed23", default-features = false }
pallet-ibc = { git = "https://github.com/ComposableFi/centauri", rev = "e19da8da70461dce572648035a8325a19ff9ed23", default-features = false }
pallet-ibc-ping = { git = "https://github.com/ComposableFi/centauri", rev = "e19da8da70461dce572648035a8325a19ff9ed23", default-features = false }

xcm-builder = { git = "https://github.com/paritytech/polkadot", rev = "c22e1c4173bf6966f5d1980f4299f7abe836f0c1", default-features = false }
polkadot-primitives = { git = "https://github.com/paritytech/polkadot", rev = "c22e1c4173bf6966f5d1980f4299f7abe836f0c1", default-features = false }
Expand Down
38 changes: 33 additions & 5 deletions code/parachain/frame/pallet-multihop-xcm-ibc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,22 @@ pub mod pallet {
Ok(())
}
}
impl<T: Config> Pallet<T> {

impl<T: Config> pallet_ibc::ics20::SubstrateMultihopXcmHandler for Pallet<T>
where u128 : Into<<T as orml_xtokens::Config>::Balance>,
u128 : Into<<T as orml_xtokens::Config>::CurrencyId>,
{
type AccountId = T::AccountId;
//todo use para id to xcm into some parachain
pub fn transfer_xcm(from: T::AccountId, to: T::AccountId, para_id: Option<u128>, amount: <T as orml_xtokens::Config>::Balance, currency: <T as orml_xtokens::Config>::CurrencyId){
// fn transfer_xcm(from: T::AccountId, to: T::AccountId, para_id: Option<u32>, amount: u128, currency: u128) -> Option<()> where <T as orml_xtokens::Config>::CurrencyId: From<u128>, <T as orml_xtokens::Config>::Balance: From<u128>{
fn transfer_xcm(from: T::AccountId, to: T::AccountId, para_id: Option<u32>, amount: u128, currency: u128) -> Option<()> {
let signed_account_id = RawOrigin::Signed(from.clone());
let acc_bytes = T::AccountId::encode(&to);
let id = acc_bytes.try_into().unwrap();
let _result = orml_xtokens::Pallet::<T>::transfer(
signed_account_id.into(),
currency,
amount,
currency.into(),
amount.into(),
Box::new(
xcm::latest::MultiLocation::new(
0,
Expand All @@ -161,8 +166,31 @@ pub mod pallet {
),
WeightLimit::Unlimited,
);

None
}
}
impl<T: Config> Pallet<T> {

// //todo use para id to xcm into some parachain
// pub fn transfer_xcm(from: T::AccountId, to: T::AccountId, para_id: Option<u128>, amount: u128, currency: u128) where <T as orml_xtokens::Config>::CurrencyId: From<u128>, <T as orml_xtokens::Config>::Balance: From<u128>{
// let signed_account_id = RawOrigin::Signed(from.clone());
// let acc_bytes = T::AccountId::encode(&to);
// let id = acc_bytes.try_into().unwrap();
// let _result = orml_xtokens::Pallet::<T>::transfer(
// signed_account_id.into(),
// currency.into(),
// amount.into(),
// Box::new(
// xcm::latest::MultiLocation::new(
// 0,
// xcm::latest::Junctions::X1(xcm::latest::Junction::AccountId32 { id: id, network: None })
// )
// .into()
// ),
// WeightLimit::Unlimited,
// );

// }

/// Support only addresses from cosmos ecosystem based on bech32.
pub fn create_memo(
Expand Down
5 changes: 3 additions & 2 deletions code/parachain/runtime/composable/src/ibc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use common::{
use composable_traits::assets::InspectRegistryMetadata;
use frame_system::EnsureSigned;
use pallet_ibc::{
ics20::{IbcModule, MODULE_ID_STR, PORT_ID_STR},
ics20::{IbcModule, MODULE_ID_STR, PORT_ID_STR, SubstrateMultihopXcmHandlerNone},
light_client_common::RelayChain,
routing::ModuleRouter,
DenomToAssetId, IbcAssetIds, IbcAssets,
Expand Down Expand Up @@ -221,7 +221,8 @@ impl pallet_ibc::Config for Runtime {
type Ics20RateLimiter = ConstantAny;
type IsReceiveEnabled = ConstBool<true>;
type IsSendEnabled = ConstBool<true>;

// type SubstrateMultihopXcmHandler = SubstrateMultihopXcmHandlerNone<Runtime>;
type SubstrateMultihopXcmHandler = pallet_multihop_xcm_ibc::Pallet<Runtime>;
type FeeAccount = FeeAccount;
type CleanUpPacketsPeriod = ConstU32<100>;
type ServiceChargeOut = IbcIcs20ServiceCharge;
Expand Down
4 changes: 3 additions & 1 deletion code/parachain/runtime/picasso/src/ibc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ parameter_types! {
pub FeeAccount: <Runtime as pallet_ibc::Config>::AccountIdConversion = ibc_primitives::IbcAccount(AccountId32::from(hex!("a72ef3ce1ecd46163bc5e23fd3e6a4623d9717c957fb59001a5d4cb949150f28")));
}

use pallet_ibc::ics20::{IbcModule, Ics20RateLimiter};
use pallet_ibc::ics20::{IbcModule, Ics20RateLimiter, SubstrateMultihopXcmHandlerNone};

pub struct ConstantAny;

Expand Down Expand Up @@ -197,6 +197,8 @@ impl pallet_ibc::Config for Runtime {
type IbcAccountId = Self::AccountId;
type HandleMemo = IbcModule<Runtime>;
type MemoMessage = MemoMessage;
type SubstrateMultihopXcmHandler = SubstrateMultihopXcmHandlerNone<Runtime>;
// type SubstrateMultihopXcmHandler = pallet_multihop_xcm_ibc::Pallet<Runtime>;
type Ics20RateLimiter = ConstantAny;
type IsReceiveEnabled = ConstBool<true>;
type IsSendEnabled = ConstBool<true>;
Expand Down
Loading