Skip to content

Commit

Permalink
Slpx support interlay (#1086)
Browse files Browse the repository at this point in the history
  • Loading branch information
hqwangningbo authored Dec 4, 2023
1 parent 8f55579 commit 978de63
Show file tree
Hide file tree
Showing 17 changed files with 90 additions and 2 deletions.
1 change: 1 addition & 0 deletions pallets/fee-share/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ impl bifrost_vtoken_minting::Config for Runtime {
type AstarParachainId = ConstU32<2007>;
type MoonbeamParachainId = ConstU32<2023>;
type HydradxParachainId = ConstU32<2034>;
type InterlayParachainId = ConstU32<2032>;
}

parameter_types! {
Expand Down
1 change: 1 addition & 0 deletions pallets/salp/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ impl bifrost_vtoken_minting::Config for Test {
type MoonbeamParachainId = ConstU32<2023>;
type BifrostSlpx = SlpxInterface;
type HydradxParachainId = ConstU32<2034>;
type InterlayParachainId = ConstU32<2032>;
}

impl salp::Config for Test {
Expand Down
22 changes: 21 additions & 1 deletion pallets/slp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1215,7 +1215,8 @@ pub mod pallet {
RedeemType::Native => {},
RedeemType::Astar(_) |
RedeemType::Moonbeam(_) |
RedeemType::Hydradx(_) => break,
RedeemType::Hydradx(_) |
RedeemType::Interlay(_) => break,
};
deduct_amount = exit_account_balance;
};
Expand Down Expand Up @@ -1267,6 +1268,25 @@ pub mod pallet {
Unlimited,
)?;
},
RedeemType::Interlay(receiver) => {
let dest = MultiLocation {
parents: 1,
interior: X2(
Parachain(T::VtokenMinting::get_interlay_parachain_id()),
AccountId32 {
network: None,
id: receiver.encode().try_into().unwrap(),
},
),
};
T::XcmTransfer::transfer(
user_account.clone(),
currency_id,
deduct_amount,
dest,
Unlimited,
)?;
},
RedeemType::Moonbeam(receiver) => {
let dest = MultiLocation {
parents: 1,
Expand Down
1 change: 1 addition & 0 deletions pallets/slp/src/mocks/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ impl bifrost_vtoken_minting::Config for Runtime {
type AstarParachainId = ConstU32<2007>;
type MoonbeamParachainId = ConstU32<2023>;
type HydradxParachainId = ConstU32<2034>;
type InterlayParachainId = ConstU32<2032>;
}

parameter_types! {
Expand Down
1 change: 1 addition & 0 deletions pallets/slp/src/mocks/mock_kusama.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ impl bifrost_vtoken_minting::Config for Runtime {
type AstarParachainId = ConstU32<2007>;
type MoonbeamParachainId = ConstU32<2023>;
type HydradxParachainId = ConstU32<2034>;
type InterlayParachainId = ConstU32<2032>;
}

parameter_types! {
Expand Down
18 changes: 18 additions & 0 deletions pallets/slpx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ pub enum SupportChain {
Astar,
Moonbeam,
Hydradx,
Interlay,
}

#[derive(
Expand All @@ -97,6 +98,7 @@ pub enum TargetChain<AccountId> {
Astar(H160),
Moonbeam(H160),
Hydradx(AccountId),
Interlay(AccountId),
}

#[frame_support::pallet]
Expand Down Expand Up @@ -424,6 +426,7 @@ pub mod pallet {
},
TargetChain::Moonbeam(receiver) => RedeemType::Moonbeam(receiver),
TargetChain::Hydradx(receiver) => RedeemType::Hydradx(receiver),
TargetChain::Interlay(receiver) => RedeemType::Interlay(receiver),
};

if vtoken_id == VFIL {
Expand Down Expand Up @@ -637,6 +640,10 @@ impl<T: Config> Pallet<T> {
evm_caller_account_id = evm_contract_account_id.clone();
SupportChain::Hydradx
},
TargetChain::Interlay(_) => {
evm_caller_account_id = evm_contract_account_id.clone();
SupportChain::Interlay
},
};
let whitelist_account_ids = WhitelistAccountId::<T>::get(&support_chain);
ensure!(
Expand Down Expand Up @@ -698,6 +705,17 @@ impl<T: Config> Pallet<T> {

T::XcmTransfer::transfer(caller, currency_id, amount, dest, Unlimited)?;
},
TargetChain::Interlay(receiver) => {
let dest = MultiLocation {
parents: 1,
interior: X2(
Parachain(T::VtokenMintingInterface::get_interlay_parachain_id()),
AccountId32 { network: None, id: receiver.encode().try_into().unwrap() },
),
};

T::XcmTransfer::transfer(caller, currency_id, amount, dest, Unlimited)?;
},
TargetChain::Moonbeam(receiver) => {
let dest = MultiLocation {
parents: 1,
Expand Down
1 change: 1 addition & 0 deletions pallets/slpx/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ impl bifrost_vtoken_minting::Config for Test {
type AstarParachainId = ConstU32<2007>;
type MoonbeamParachainId = ConstU32<2023>;
type HydradxParachainId = ConstU32<2034>;
type InterlayParachainId = ConstU32<2032>;
}
// Below is the implementation of tokens manipulation functions other than native token.
pub struct LocalAssetAdaptor<Local>(PhantomData<Local>);
Expand Down
1 change: 1 addition & 0 deletions pallets/stable-pool/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ impl bifrost_vtoken_minting::Config for Test {
type MoonbeamParachainId = ConstU32<2023>;
type BifrostSlpx = SlpxInterface;
type HydradxParachainId = ConstU32<2034>;
type InterlayParachainId = ConstU32<2032>;
}

pub struct Slp;
Expand Down
1 change: 1 addition & 0 deletions pallets/system-maker/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ impl bifrost_vtoken_minting::Config for Runtime {
type AstarParachainId = ConstU32<2007>;
type MoonbeamParachainId = ConstU32<2023>;
type HydradxParachainId = ConstU32<2034>;
type InterlayParachainId = ConstU32<2032>;
}

parameter_types! {
Expand Down
1 change: 1 addition & 0 deletions pallets/system-staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ impl bifrost_vtoken_minting::Config for Runtime {
type AstarParachainId = ConstU32<2007>;
type MoonbeamParachainId = ConstU32<2023>;
type HydradxParachainId = ConstU32<2034>;
type InterlayParachainId = ConstU32<2032>;
}

ord_parameter_types! {
Expand Down
1 change: 1 addition & 0 deletions pallets/ve-minting/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ impl bifrost_vtoken_minting::Config for Runtime {
type AstarParachainId = ConstU32<2007>;
type MoonbeamParachainId = ConstU32<2023>;
type HydradxParachainId = ConstU32<2034>;
type InterlayParachainId = ConstU32<2032>;
}

ord_parameter_types! {
Expand Down
33 changes: 32 additions & 1 deletion pallets/vtoken-minting/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ pub mod pallet {
#[pallet::constant]
type HydradxParachainId: Get<u32>;

#[pallet::constant]
type InterlayParachainId: Get<u32>;

type BifrostSlp: SlpOperator<CurrencyId>;

type BifrostSlpx: SlpxOperator<BalanceOf<Self>>;
Expand Down Expand Up @@ -984,6 +987,25 @@ pub mod pallet {
Unlimited,
)?;
},
RedeemType::Interlay(receiver) => {
let dest = MultiLocation {
parents: 1,
interior: X2(
Parachain(T::InterlayParachainId::get()),
AccountId32 {
network: None,
id: receiver.encode().try_into().unwrap(),
},
),
};
T::XcmTransfer::transfer(
account.clone(),
token_id,
unlock_amount,
dest,
Unlimited,
)?;
},
RedeemType::Moonbeam(receiver) => {
let dest = MultiLocation {
parents: 1,
Expand Down Expand Up @@ -1018,7 +1040,10 @@ pub mod pallet {
};
} else {
match redeem_type {
RedeemType::Astar(_) | RedeemType::Moonbeam(_) | RedeemType::Hydradx(_) => {
RedeemType::Astar(_) |
RedeemType::Moonbeam(_) |
RedeemType::Hydradx(_) |
RedeemType::Interlay(_) => {
return Ok(());
},
RedeemType::Native => {},
Expand Down Expand Up @@ -1581,6 +1606,9 @@ impl<T: Config> VtokenMintingOperator<CurrencyId, BalanceOf<T>, AccountIdOf<T>,
fn get_hydradx_parachain_id() -> u32 {
T::HydradxParachainId::get()
}
fn get_interlay_parachain_id() -> u32 {
T::InterlayParachainId::get()
}
}

impl<T: Config> VtokenMintingInterface<AccountIdOf<T>, CurrencyIdOf<T>, BalanceOf<T>>
Expand Down Expand Up @@ -1649,6 +1677,9 @@ impl<T: Config> VtokenMintingInterface<AccountIdOf<T>, CurrencyIdOf<T>, BalanceO
fn get_hydradx_parachain_id() -> u32 {
T::HydradxParachainId::get()
}
fn get_interlay_parachain_id() -> u32 {
T::InterlayParachainId::get()
}
}

impl<T: Config> VTokenSupplyProvider<CurrencyIdOf<T>, BalanceOf<T>> for Pallet<T> {
Expand Down
1 change: 1 addition & 0 deletions pallets/vtoken-minting/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ impl vtoken_minting::Config for Runtime {
type AstarParachainId = ConstU32<2007>;
type MoonbeamParachainId = ConstU32<2023>;
type HydradxParachainId = ConstU32<2034>;
type InterlayParachainId = ConstU32<2032>;
}

ord_parameter_types! {
Expand Down
2 changes: 2 additions & 0 deletions primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ pub enum RedeemType<AccountId> {
Moonbeam(H160),
/// Hydradx chain.
Hydradx(AccountId),
/// Interlay chain.
Interlay(AccountId),
}

impl<AccountId> Default for RedeemType<AccountId> {
Expand Down
5 changes: 5 additions & 0 deletions primitives/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ pub trait VtokenMintingOperator<CurrencyId, Balance, AccountId, TimeUnit> {
fn get_astar_parachain_id() -> u32;
fn get_moonbeam_parachain_id() -> u32;
fn get_hydradx_parachain_id() -> u32;
fn get_interlay_parachain_id() -> u32;
}

/// Trait for Vtoken-Minting module to check whether accept redeeming or not.
Expand Down Expand Up @@ -345,6 +346,7 @@ pub trait VtokenMintingInterface<AccountId, CurrencyId, Balance> {
fn get_astar_parachain_id() -> u32;
fn get_moonbeam_parachain_id() -> u32;
fn get_hydradx_parachain_id() -> u32;
fn get_interlay_parachain_id() -> u32;
}

impl<AccountId, CurrencyId, Balance: Zero> VtokenMintingInterface<AccountId, CurrencyId, Balance>
Expand Down Expand Up @@ -413,6 +415,9 @@ impl<AccountId, CurrencyId, Balance: Zero> VtokenMintingInterface<AccountId, Cur
fn get_hydradx_parachain_id() -> u32 {
0
}
fn get_interlay_parachain_id() -> u32 {
0
}
}

pub trait TryConvertFrom<CurrencyId> {
Expand Down
1 change: 1 addition & 0 deletions runtime/bifrost-kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1619,6 +1619,7 @@ impl bifrost_vtoken_minting::Config for Runtime {
type AstarParachainId = ConstU32<2007>;
type MoonbeamParachainId = ConstU32<2023>;
type HydradxParachainId = ConstU32<2034>;
type InterlayParachainId = ConstU32<2092>;
}

impl bifrost_slpx::Config for Runtime {
Expand Down
1 change: 1 addition & 0 deletions runtime/bifrost-polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1451,6 +1451,7 @@ impl bifrost_vtoken_minting::Config for Runtime {
type AstarParachainId = ConstU32<2006>;
type MoonbeamParachainId = ConstU32<2004>;
type HydradxParachainId = ConstU32<2034>;
type InterlayParachainId = ConstU32<2032>;
}

parameter_types! {
Expand Down

0 comments on commit 978de63

Please sign in to comment.