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: xcm notification issue #1962

Merged
merged 8 commits into from
Mar 20, 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
50 changes: 11 additions & 39 deletions pallets/liquid-staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ mod benchmarking;

#[cfg(test)]
mod mock;
#[cfg(test)]
mod tests;
// TODO: Should be fixed after upgrade XCM version
// #[cfg(test)]
// mod tests;

pub mod distribution;
pub mod migrations;
Expand Down Expand Up @@ -226,10 +227,6 @@ pub mod pallet {

/// Decimal provider.
type Decimal: DecimalProvider<CurrencyId>;

/// The asset id for native currency.
#[pallet::constant]
type NativeCurrency: Get<AssetIdOf<Self>>;
}

#[pallet::event]
Expand Down Expand Up @@ -290,8 +287,6 @@ pub mod pallet {
FastUnstakeMatched(T::AccountId, BalanceOf<T>, BalanceOf<T>, BalanceOf<T>),
/// Incentive amount was updated
IncentiveUpdated(BalanceOf<T>),
/// Not the ideal staking ledger
NonIdealStakingLedger(DerivativeIndex),
/// Unstake_reserve_factor was updated
UnstakeReserveFactorUpdated(Ratio),
/// Event emitted when the unstake reserves are reduced
Expand Down Expand Up @@ -925,7 +920,7 @@ pub mod pallet {
era: EraIndex,
proof: Vec<Vec<u8>>,
) -> DispatchResultWithPostInfo {
let who = ensure_signed(origin)?;
Self::ensure_origin(origin)?;

let offset = era.saturating_sub(Self::current_era());

Expand All @@ -937,16 +932,6 @@ pub mod pallet {
);

Self::do_advance_era(offset)?;
if !offset.is_zero() {
let _ = T::Assets::transfer(
T::NativeCurrency::get(),
&Self::account_id(),
&who,
Self::incentive(),
false,
);
}

Ok(().into())
}

Expand All @@ -960,26 +945,20 @@ pub mod pallet {
staking_ledger: StakingLedger<T::AccountId, BalanceOf<T>>,
proof: Vec<Vec<u8>>,
) -> DispatchResultWithPostInfo {
let who = ensure_signed(origin)?;
Self::ensure_origin(origin)?;

Self::do_update_ledger(derivative_index, |ledger| {
ensure!(
!Self::is_updated(derivative_index)
&& XcmRequests::<T>::iter().count().is_zero(),
Error::<T>::StakingLedgerLocked
);
if staking_ledger.total < ledger.total
|| staking_ledger.active < ledger.active
|| staking_ledger.unlocking != ledger.unlocking
{
log::trace!(
target: "liquidStaking::set_staking_ledger::invalidStakingLedger",
"index: {:?}, staking_ledger: {:?}",
&derivative_index,
&staking_ledger,
);
Self::deposit_event(Event::<T>::NonIdealStakingLedger(derivative_index));
}
ensure!(
staking_ledger.total > ledger.total
&& staking_ledger.active > ledger.active
&& staking_ledger.unlocking == ledger.unlocking,
Error::<T>::InvalidStakingLedger
);
let key = Self::get_staking_ledger_key(derivative_index);
let value = staking_ledger.encode();
ensure!(
Expand All @@ -1004,13 +983,6 @@ pub mod pallet {
&staking_ledger,
inflate_liquid_amount,
);
let _ = T::Assets::transfer(
T::NativeCurrency::get(),
&Self::account_id(),
&who,
Self::incentive(),
false,
);
*ledger = staking_ledger;
Ok(())
})?;
Expand Down
1 change: 0 additions & 1 deletion pallets/liquid-staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,6 @@ impl crate::Config for Test {
type ElectionSolutionStoredOffset = ElectionSolutionStoredOffset;
type ProtocolFeeReceiver = DefaultProtocolFeeReceiver;
type Decimal = Decimal;
type NativeCurrency = NativeCurrencyId;
}

pub struct Decimal;
Expand Down
6 changes: 3 additions & 3 deletions pallets/xcm-helper/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,14 +268,14 @@ impl<T: Config> Pallet<T> {
let notify: <T as pallet_xcm::Config>::RuntimeCall = notify.into();
let max_weight = notify.get_dispatch_info().weight;
let query_id = pallet_xcm::Pallet::<T>::new_notify_query(responder, notify, timeout, Here);
let report_error = Xcm(vec![ReportError(QueryResponseInfo {
let report_error = ReportError(QueryResponseInfo {
destination,
query_id,
max_weight,
})]);
});
// Prepend SetAppendix(Xcm(vec![ReportError])) wont be able to pass barrier check
// so we need to insert it after Withdraw, BuyExecution
message.0.insert(2, SetAppendix(report_error));
message.0.insert(3, report_error);
Ok(query_id)
}

Expand Down
1 change: 0 additions & 1 deletion runtime/heiko/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,6 @@ impl pallet_liquid_staking::Config for Runtime {
type ElectionSolutionStoredOffset = ElectionSolutionStoredOffset;
type ProtocolFeeReceiver = DefaultProtocolFeeReceiver;
type Decimal = Decimal;
type NativeCurrency = NativeCurrencyId;
}

parameter_types! {
Expand Down
1 change: 0 additions & 1 deletion runtime/kerria/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,6 @@ impl pallet_liquid_staking::Config for Runtime {
type ElectionSolutionStoredOffset = ElectionSolutionStoredOffset;
type ProtocolFeeReceiver = DefaultProtocolFeeReceiver;
type Decimal = Decimal;
type NativeCurrency = NativeCurrencyId;
}

parameter_types! {
Expand Down
1 change: 0 additions & 1 deletion runtime/parallel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,6 @@ impl pallet_liquid_staking::Config for Runtime {
type ElectionSolutionStoredOffset = ElectionSolutionStoredOffset;
type ProtocolFeeReceiver = DefaultProtocolFeeReceiver;
type Decimal = Decimal;
type NativeCurrency = NativeCurrencyId;
}

parameter_types! {
Expand Down
1 change: 0 additions & 1 deletion runtime/vanilla/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,6 @@ impl pallet_liquid_staking::Config for Runtime {
type ElectionSolutionStoredOffset = ElectionSolutionStoredOffset;
type ProtocolFeeReceiver = DefaultProtocolFeeReceiver;
type Decimal = Decimal;
type NativeCurrency = NativeCurrencyId;
}

parameter_types! {
Expand Down
Loading