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

Fix slp transfer back #1518

Merged
merged 2 commits into from
Nov 26, 2024
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
43 changes: 29 additions & 14 deletions pallets/slp/src/agents/parachain_staking_agent/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +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 super::types::{
MoonbeamCall, MoonbeamCurrencyId, MoonbeamParachainStakingCall, MoonbeamXtokensCall,
};
use super::types::{MoonbeamCall, MoonbeamParachainStakingCall, PolkadotXcmCall};
use crate::{
agents::{MantaCall, MantaCurrencyId, MantaParachainStakingCall, MantaXtokensCall},
pallet::{Error, Event},
Expand Down Expand Up @@ -48,11 +46,13 @@ use sp_runtime::{
};
use sp_std::prelude::*;
use xcm::{
latest::{AssetId, Assets},
opaque::v3::{
Junction::{AccountId32, Parachain},
MultiLocation,
},
v3::prelude::*,
v4::Asset,
VersionedLocation,
};

Expand Down Expand Up @@ -1370,6 +1370,8 @@ impl<T: Config>

// Make sure the receiving account is the Exit_account from vtoken-minting module.
let (entrance_account, _) = T::VtokenMinting::get_entrance_and_exit_accounts();
let entrance_account_id =
entrance_account.encode().try_into().map_err(|_| Error::<T>::FailToConvert)?;

if currency_id == BNC {
let from_account = Pallet::<T>::multilocation_to_account(from)?;
Expand All @@ -1381,22 +1383,35 @@ impl<T: Config>
parents: 1,
interior: X2(
Parachain(T::ParachainId::get().into()),
AccountId32 {
network: None,
id: entrance_account
.encode()
.try_into()
.map_err(|_| Error::<T>::FailToConvert)?,
},
AccountId32 { network: None, id: entrance_account_id },
),
}));

// Construct xcm message.
let call: Vec<u8> = match currency_id {
MOVR | GLMR => MoonbeamCall::Xtokens(MoonbeamXtokensCall::<T>::Transfer(
MoonbeamCurrencyId::SelfReserve,
amount.unique_saturated_into(),
dest,
MOVR | GLMR => MoonbeamCall::<T>::PolkadotXcm(PolkadotXcmCall::TransferAssets(
Box::new(
Location::new(1, X1(Parachain(T::ParachainId::get().into())))
.into_versioned(),
),
Box::new(
Location::new(
0,
X1(AccountId32 { network: None, id: entrance_account_id }),
)
.into_versioned(),
),
Box::new(
Assets::from(vec![Asset {
id: AssetId(xcm::v4::Location::new(
0,
xcm::v4::prelude::PalletInstance(10),
)),
fun: xcm::v4::Fungibility::Fungible(amount.unique_saturated_into()),
}])
.into(),
),
0,
Unlimited,
))
.encode()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@

use crate::{BalanceOf, Config};
use parity_scale_codec::{Decode, Encode};
use scale_info::TypeInfo;
use sp_arithmetic::Percent;
use sp_core::H160;
use sp_runtime::{
traits::{IdentityLookup, StaticLookup},
RuntimeDebug,
};
use sp_std::{boxed::Box, vec::Vec};
use xcm::{opaque::v3::WeightLimit, VersionedLocation};
use xcm::{opaque::v3::WeightLimit, VersionedAssets, VersionedLocation};

#[derive(Encode, Decode, RuntimeDebug, Clone)]
pub enum MoonbeamCall<T: Config> {
Expand All @@ -36,8 +35,8 @@ pub enum MoonbeamCall<T: Config> {
Staking(MoonbeamParachainStakingCall<T>),
#[codec(index = 30)]
Utility(Box<MoonbeamUtilityCall<Self>>),
#[codec(index = 106)]
Xtokens(MoonbeamXtokensCall<T>),
#[codec(index = 103)]
PolkadotXcm(PolkadotXcmCall),
}

impl<T: Config> MoonbeamCall<T> {
Expand Down Expand Up @@ -89,17 +88,13 @@ pub enum MoonbeamParachainStakingCall<T: Config> {
}

#[derive(Encode, Decode, RuntimeDebug, Clone)]
pub enum MoonbeamXtokensCall<T: Config> {
#[codec(index = 0)]
Transfer(MoonbeamCurrencyId, BalanceOf<T>, Box<VersionedLocation>, WeightLimit),
}

#[derive(PartialEq, Eq, Copy, Clone, Encode, Decode, RuntimeDebug, TypeInfo)]
pub enum MoonbeamCurrencyId {
// Our native token
SelfReserve,
// Assets representing other chains native tokens
ForeignAsset(u128),
// Our local assets
LocalAssetReserve(u128),
pub enum PolkadotXcmCall {
#[codec(index = 11)]
TransferAssets(
Box<VersionedLocation>,
Box<VersionedLocation>,
Box<VersionedAssets>,
u32,
WeightLimit,
),
}
2 changes: 1 addition & 1 deletion pallets/vtoken-minting/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,8 +537,8 @@ impl<T: Config> Pallet<T> {
&redeemer,
redeem_currency_amount,
)?;
return Ok((redeem_currency_amount, RedeemTo::Native(redeemer)));
}
return Ok((redeem_currency_amount, RedeemTo::Native(redeemer)));
}
Ok((Default::default(), RedeemTo::Native(redeemer)))
}
Expand Down