Skip to content

Commit

Permalink
Slpx supports manta chain (#1200)
Browse files Browse the repository at this point in the history
* Slpx supports manta chain

* Fix clippy
  • Loading branch information
hqwangningbo committed Feb 26, 2024
1 parent 626462f commit 5461aaf
Show file tree
Hide file tree
Showing 19 changed files with 88 additions and 0 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 @@ -360,6 +360,7 @@ impl bifrost_vtoken_minting::Config for Runtime {
type AstarParachainId = ConstU32<2007>;
type MoonbeamParachainId = ConstU32<2023>;
type HydradxParachainId = ConstU32<2034>;
type MantaParachainId = ConstU32<2104>;
type InterlayParachainId = ConstU32<2032>;
type ChannelCommission = ();
}
Expand Down
1 change: 1 addition & 0 deletions pallets/leverage-staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ impl bifrost_vtoken_minting::Config for Test {
type MoonbeamParachainId = ConstU32<2023>;
type BifrostSlpx = SlpxInterface;
type HydradxParachainId = ConstU32<2034>;
type MantaParachainId = ConstU32<2104>;
type InterlayParachainId = ConstU32<2032>;
type ChannelCommission = ();
}
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 @@ -450,6 +450,7 @@ impl bifrost_vtoken_minting::Config for Test {
type MoonbeamParachainId = ConstU32<2023>;
type BifrostSlpx = SlpxInterface;
type HydradxParachainId = ConstU32<2034>;
type MantaParachainId = ConstU32<2104>;
type InterlayParachainId = ConstU32<2032>;
type ChannelCommission = ();
}
Expand Down
20 changes: 20 additions & 0 deletions pallets/slp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1253,6 +1253,7 @@ pub mod pallet {
RedeemType::Astar(_) |
RedeemType::Moonbeam(_) |
RedeemType::Hydradx(_) |
RedeemType::Manta(_) |
RedeemType::Interlay(_) => break,
};
deduct_amount = exit_account_balance;
Expand Down Expand Up @@ -1324,6 +1325,25 @@ pub mod pallet {
Unlimited,
)?;
},
RedeemType::Manta(receiver) => {
let dest = MultiLocation {
parents: 1,
interior: X2(
Parachain(T::VtokenMinting::get_manta_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 @@ -227,6 +227,7 @@ impl bifrost_vtoken_minting::Config for Runtime {
type AstarParachainId = ConstU32<2007>;
type MoonbeamParachainId = ConstU32<2023>;
type HydradxParachainId = ConstU32<2034>;
type MantaParachainId = ConstU32<2104>;
type InterlayParachainId = ConstU32<2032>;
type ChannelCommission = ();
}
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 @@ -249,6 +249,7 @@ impl bifrost_vtoken_minting::Config for Runtime {
type AstarParachainId = ConstU32<2007>;
type MoonbeamParachainId = ConstU32<2023>;
type HydradxParachainId = ConstU32<2034>;
type MantaParachainId = ConstU32<2104>;
type InterlayParachainId = ConstU32<2032>;
type ChannelCommission = ();
}
Expand Down
17 changes: 17 additions & 0 deletions pallets/slpx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ pub mod pallet {
TargetChain::Moonbeam(receiver) => RedeemType::Moonbeam(receiver),
TargetChain::Hydradx(receiver) => RedeemType::Hydradx(receiver),
TargetChain::Interlay(receiver) => RedeemType::Interlay(receiver),
TargetChain::Manta(receiver) => RedeemType::Manta(receiver),
};

if vtoken_id == VFIL {
Expand Down Expand Up @@ -889,10 +890,15 @@ impl<T: Config> Pallet<T> {
evm_caller_account_id = evm_contract_account_id.clone();
SupportChain::Interlay
},
TargetChain::Manta(_) => {
evm_caller_account_id = evm_contract_account_id.clone();
SupportChain::Manta
},
};

match target_chain {
TargetChain::Hydradx(_) => {},
TargetChain::Manta(_) => {},
_ => {
let whitelist_account_ids = WhitelistAccountId::<T>::get(&support_chain);
ensure!(
Expand Down Expand Up @@ -967,6 +973,17 @@ impl<T: Config> Pallet<T> {

T::XcmTransfer::transfer(caller, currency_id, amount, dest, Unlimited)?;
},
TargetChain::Manta(receiver) => {
let dest = MultiLocation {
parents: 1,
interior: X2(
Parachain(T::VtokenMintingInterface::get_manta_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 @@ -226,6 +226,7 @@ impl bifrost_vtoken_minting::Config for Test {
type AstarParachainId = ConstU32<2007>;
type MoonbeamParachainId = ConstU32<2023>;
type HydradxParachainId = ConstU32<2034>;
type MantaParachainId = ConstU32<2104>;
type InterlayParachainId = ConstU32<2032>;
type ChannelCommission = ();
}
Expand Down
2 changes: 2 additions & 0 deletions pallets/slpx/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pub enum SupportChain {
Moonbeam,
Hydradx,
Interlay,
Manta,
}

#[derive(Encode, Decode, Copy, Clone, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
Expand All @@ -56,6 +57,7 @@ pub enum TargetChain<AccountId> {
Moonbeam(H160),
Hydradx(AccountId),
Interlay(AccountId),
Manta(AccountId),
}

#[derive(Clone, Debug, Eq, PartialEq, Encode, Decode, TypeInfo, MaxEncodedLen)]
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 @@ -315,6 +315,7 @@ impl bifrost_vtoken_minting::Config for Test {
type MoonbeamParachainId = ConstU32<2023>;
type BifrostSlpx = SlpxInterface;
type HydradxParachainId = ConstU32<2034>;
type MantaParachainId = ConstU32<2104>;
type InterlayParachainId = ConstU32<2032>;
type ChannelCommission = ();
}
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 @@ -367,6 +367,7 @@ impl bifrost_vtoken_minting::Config for Runtime {
type AstarParachainId = ConstU32<2007>;
type MoonbeamParachainId = ConstU32<2023>;
type HydradxParachainId = ConstU32<2034>;
type MantaParachainId = ConstU32<2104>;
type InterlayParachainId = ConstU32<2032>;
type ChannelCommission = ();
}
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 @@ -217,6 +217,7 @@ impl bifrost_vtoken_minting::Config for Runtime {
type AstarParachainId = ConstU32<2007>;
type MoonbeamParachainId = ConstU32<2023>;
type HydradxParachainId = ConstU32<2034>;
type MantaParachainId = ConstU32<2104>;
type InterlayParachainId = ConstU32<2032>;
type ChannelCommission = ();
}
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 @@ -240,6 +240,7 @@ impl bifrost_vtoken_minting::Config for Runtime {
type AstarParachainId = ConstU32<2007>;
type MoonbeamParachainId = ConstU32<2023>;
type HydradxParachainId = ConstU32<2034>;
type MantaParachainId = ConstU32<2104>;
type InterlayParachainId = ConstU32<2032>;
type ChannelCommission = ();
}
Expand Down
29 changes: 29 additions & 0 deletions pallets/vtoken-minting/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ pub mod pallet {
#[pallet::constant]
type InterlayParachainId: Get<u32>;

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

type BifrostSlp: SlpOperator<CurrencyId>;

type BifrostSlpx: SlpxOperator<BalanceOf<Self>>;
Expand Down Expand Up @@ -1034,6 +1037,25 @@ pub mod pallet {
Unlimited,
)?;
},
RedeemType::Manta(receiver) => {
let dest = MultiLocation {
parents: 1,
interior: X2(
Parachain(T::MantaParachainId::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 @@ -1071,6 +1093,7 @@ pub mod pallet {
RedeemType::Astar(_) |
RedeemType::Moonbeam(_) |
RedeemType::Hydradx(_) |
RedeemType::Manta(_) |
RedeemType::Interlay(_) => {
return Ok(());
},
Expand Down Expand Up @@ -1648,6 +1671,9 @@ impl<T: Config> VtokenMintingOperator<CurrencyId, BalanceOf<T>, AccountIdOf<T>,
fn get_interlay_parachain_id() -> u32 {
T::InterlayParachainId::get()
}
fn get_manta_parachain_id() -> u32 {
T::MantaParachainId::get()
}
}

impl<T: Config> VtokenMintingInterface<AccountIdOf<T>, CurrencyIdOf<T>, BalanceOf<T>>
Expand Down Expand Up @@ -1724,6 +1750,9 @@ impl<T: Config> VtokenMintingInterface<AccountIdOf<T>, CurrencyIdOf<T>, BalanceO
fn get_interlay_parachain_id() -> u32 {
T::InterlayParachainId::get()
}
fn get_manta_parachain_id() -> u32 {
T::MantaParachainId::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 @@ -245,6 +245,7 @@ impl vtoken_minting::Config for Runtime {
type AstarParachainId = ConstU32<2007>;
type MoonbeamParachainId = ConstU32<2023>;
type HydradxParachainId = ConstU32<2034>;
type MantaParachainId = ConstU32<2104>;
type InterlayParachainId = ConstU32<2032>;
type ChannelCommission = ();
}
Expand Down
2 changes: 2 additions & 0 deletions primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ pub enum RedeemType<AccountId> {
Hydradx(AccountId),
/// Interlay chain.
Interlay(AccountId),
/// Manta chain.
Manta(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_moonbeam_parachain_id() -> u32;
fn get_hydradx_parachain_id() -> u32;
fn get_interlay_parachain_id() -> u32;
fn get_manta_parachain_id() -> u32;
}

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

impl<AccountId, CurrencyId, Balance: Zero> VtokenMintingInterface<AccountId, CurrencyId, Balance>
Expand Down Expand Up @@ -424,6 +426,9 @@ impl<AccountId, CurrencyId, Balance: Zero> VtokenMintingInterface<AccountId, Cur
fn get_interlay_parachain_id() -> u32 {
0
}
fn get_manta_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 @@ -1662,6 +1662,7 @@ impl bifrost_vtoken_minting::Config for Runtime {
type AstarParachainId = ConstU32<2007>;
type MoonbeamParachainId = ConstU32<2023>;
type HydradxParachainId = ConstU32<2034>;
type MantaParachainId = ConstU32<2104>;
type InterlayParachainId = ConstU32<2092>;
type ChannelCommission = ChannelCommission;
}
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 @@ -1496,6 +1496,7 @@ impl bifrost_vtoken_minting::Config for Runtime {
type AstarParachainId = ConstU32<2006>;
type MoonbeamParachainId = ConstU32<2004>;
type HydradxParachainId = ConstU32<2034>;
type MantaParachainId = ConstU32<2104>;
type InterlayParachainId = ConstU32<2032>;
type ChannelCommission = ChannelCommission;
}
Expand Down

0 comments on commit 5461aaf

Please sign in to comment.