Skip to content

Commit

Permalink
Merge branch 'develop' into v0.9.78
Browse files Browse the repository at this point in the history
  • Loading branch information
ark930 committed Jul 14, 2023
2 parents 2e44ec1 + 46348b9 commit 7ed0c3a
Show file tree
Hide file tree
Showing 16 changed files with 104 additions and 192 deletions.
25 changes: 8 additions & 17 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion integration-tests/bifrost-kusama/src/slp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,6 @@ fn vtoken_minting() {
),
99900000000000
);
// TODO : entrance_account should have 100 KSM
assert_eq!(
Currencies::free_balance(
CurrencyId::Token(TokenSymbol::KSM),
Expand Down
2 changes: 1 addition & 1 deletion pallets/fee-share/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ impl pallet_xcm::Config for Runtime {
type TrustedLockers = ();
type SovereignAccountOf = ();
type MaxLockers = ConstU32<8>;
type WeightInfo = pallet_xcm::TestWeightInfo; // TODO: config after polkadot impl WeightInfo for ()
type WeightInfo = pallet_xcm::TestWeightInfo;
#[cfg(feature = "runtime-benchmarks")]
type ReachableDest = ReachableDest;
type AdminOrigin = EnsureRoot<AccountId>;
Expand Down
2 changes: 1 addition & 1 deletion pallets/flexible-fee/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ impl pallet_xcm::Config for Test {
type TrustedLockers = ();
type SovereignAccountOf = ();
type MaxLockers = ConstU32<8>;
type WeightInfo = pallet_xcm::TestWeightInfo; // TODO: config after polkadot impl WeightInfo for ()
type WeightInfo = pallet_xcm::TestWeightInfo;
#[cfg(feature = "runtime-benchmarks")]
type ReachableDest = ReachableDest;
type AdminOrigin = EnsureRoot<AccountId>;
Expand Down
2 changes: 1 addition & 1 deletion pallets/salp/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ impl pallet_xcm::Config for Test {
type TrustedLockers = ();
type SovereignAccountOf = ();
type MaxLockers = ConstU32<8>;
type WeightInfo = pallet_xcm::TestWeightInfo; // TODO: config after polkadot impl WeightInfo for ()
type WeightInfo = pallet_xcm::TestWeightInfo;
#[cfg(feature = "runtime-benchmarks")]
type ReachableDest = ReachableDest;
type AdminOrigin = EnsureRoot<AccountId>;
Expand Down
2 changes: 1 addition & 1 deletion pallets/slp/src/mocks/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ impl pallet_xcm::Config for Runtime {
type TrustedLockers = ();
type SovereignAccountOf = ();
type MaxLockers = ConstU32<8>;
type WeightInfo = pallet_xcm::TestWeightInfo; // TODO: config after polkadot impl WeightInfo for ()
type WeightInfo = pallet_xcm::TestWeightInfo;
#[cfg(feature = "runtime-benchmarks")]
type ReachableDest = ReachableDest;
type AdminOrigin = EnsureRoot<AccountId>;
Expand Down
2 changes: 1 addition & 1 deletion pallets/slp/src/mocks/mock_kusama.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ impl pallet_xcm::Config for Runtime {
type TrustedLockers = ();
type SovereignAccountOf = ();
type MaxLockers = ConstU32<8>;
type WeightInfo = pallet_xcm::TestWeightInfo; // TODO: config after polkadot impl WeightInfo for ()
type WeightInfo = pallet_xcm::TestWeightInfo;
#[cfg(feature = "runtime-benchmarks")]
type ReachableDest = ReachableDest;
type AdminOrigin = EnsureRoot<AccountId>;
Expand Down
14 changes: 8 additions & 6 deletions pallets/slpx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ use orml_traits::{MultiCurrency, XcmTransfer};
pub use pallet::*;
use scale_info::TypeInfo;
use sp_core::{Hasher, H160};
use sp_runtime::{traits::BlakeTwo256, DispatchError, Saturating};
use sp_runtime::{
traits::{BlakeTwo256, CheckedSub},
DispatchError, Saturating,
};
use sp_std::vec;
use xcm::{latest::prelude::*, v3::MultiLocation};
use zenlink_protocol::AssetBalance;
Expand Down Expand Up @@ -555,17 +558,16 @@ impl<T: Config> Pallet<T> {
let execution_fee =
Self::execution_fee(currency_id).unwrap_or_else(|| Self::get_default_fee(currency_id));
let minimum_balance = T::MultiCurrency::minimum_balance(currency_id);
ensure!(
free_balance > execution_fee.saturating_add(minimum_balance),
Error::<T>::FreeBalanceTooLow
);
T::MultiCurrency::transfer(
currency_id,
evm_caller_account_id,
&T::TreasuryAccount::get(),
execution_fee,
)?;
Ok(free_balance - execution_fee.saturating_add(minimum_balance))
let balance_exclude_fee = free_balance
.checked_sub(&execution_fee.saturating_add(minimum_balance))
.ok_or(Error::<T>::FreeBalanceTooLow)?;
Ok(balance_exclude_fee)
}

fn match_support_chain(
Expand Down
2 changes: 1 addition & 1 deletion pallets/slpx/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ impl pallet_xcm::Config for Test {
type TrustedLockers = ();
type SovereignAccountOf = ();
type MaxLockers = ConstU32<8>;
type WeightInfo = pallet_xcm::TestWeightInfo; // TODO: config after polkadot impl WeightInfo for ()
type WeightInfo = pallet_xcm::TestWeightInfo;
#[cfg(feature = "runtime-benchmarks")]
type ReachableDest = ReachableDest;
type AdminOrigin = EnsureRoot<AccountId>;
Expand Down
2 changes: 1 addition & 1 deletion pallets/system-maker/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ impl pallet_xcm::Config for Runtime {
type TrustedLockers = ();
type SovereignAccountOf = ();
type MaxLockers = ConstU32<8>;
type WeightInfo = pallet_xcm::TestWeightInfo; // TODO: config after polkadot impl WeightInfo for ()
type WeightInfo = pallet_xcm::TestWeightInfo;
#[cfg(feature = "runtime-benchmarks")]
type ReachableDest = ReachableDest;
type AdminOrigin = EnsureRoot<AccountId>;
Expand Down
2 changes: 1 addition & 1 deletion pallets/system-staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ impl pallet_xcm::Config for Runtime {
type TrustedLockers = ();
type SovereignAccountOf = ();
type MaxLockers = ConstU32<8>;
type WeightInfo = pallet_xcm::TestWeightInfo; // TODO: config after polkadot impl WeightInfo for ()
type WeightInfo = pallet_xcm::TestWeightInfo;
#[cfg(feature = "runtime-benchmarks")]
type ReachableDest = ReachableDest;
type AdminOrigin = EnsureRoot<AccountId>;
Expand Down
2 changes: 1 addition & 1 deletion pallets/ve-minting/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ impl pallet_xcm::Config for Runtime {
type TrustedLockers = ();
type SovereignAccountOf = ();
type MaxLockers = ConstU32<8>;
type WeightInfo = pallet_xcm::TestWeightInfo; // TODO: config after polkadot impl WeightInfo for ()
type WeightInfo = pallet_xcm::TestWeightInfo;
#[cfg(feature = "runtime-benchmarks")]
type ReachableDest = ReachableDest;
type AdminOrigin = EnsureRoot<AccountId>;
Expand Down
136 changes: 72 additions & 64 deletions pallets/vtoken-minting/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,87 +385,95 @@ pub mod pallet {
ledger_list =
BoundedVec::<UnlockId, T::MaximumUnlockIdOfUser>::try_from(ledger_list_rev)
.map_err(|_| Error::<T>::ExceedMaximumUnlockId)?;
ledger_list.retain(|index| {
if let Some((_, unlock_amount, time_unit, _)) =
Self::token_unlock_ledger(token_id, index)
{
if tmp_amount >= unlock_amount {
if let Some((_, _, time_unit, _)) =
TokenUnlockLedger::<T>::take(&token_id, &index)
{
let mut tmp = ledger_list
.iter()
.map(|&index| -> Result<(UnlockId, bool), Error<T>> {
if let Some((_, unlock_amount, time_unit, _)) =
Self::token_unlock_ledger(token_id, index)
{
if tmp_amount >= unlock_amount {
if let Some((_, _, time_unit, _)) =
TokenUnlockLedger::<T>::take(&token_id, &index)
{
TimeUnitUnlockLedger::<T>::mutate_exists(
&time_unit,
&token_id,
|value| -> Result<(), Error<T>> {
if let Some((
total_locked_origin,
ledger_list_origin,
_,
)) = value
{
if total_locked_origin == &unlock_amount {
*value = None;
return Ok(());
}
*total_locked_origin = total_locked_origin
.checked_sub(&unlock_amount)
.ok_or(Error::<T>::CalculationOverflow)?;
ledger_list_origin.retain(|&x| x != index);
} else {
return Err(
Error::<T>::TimeUnitUnlockLedgerNotFound,
);
}
Ok(())
},
)?;
tmp_amount = tmp_amount.saturating_sub(unlock_amount);
} else {
return Err(Error::<T>::TokenUnlockLedgerNotFound.into());
}
Ok((index, false))
} else {
TokenUnlockLedger::<T>::mutate_exists(
&token_id,
&index,
|value| -> Result<(), Error<T>> {
if let Some((_, total_locked_origin, _, _)) = value {
if total_locked_origin == &tmp_amount {
*value = None;
return Ok(());
}
*total_locked_origin = total_locked_origin
.checked_sub(&tmp_amount)
.ok_or(Error::<T>::CalculationOverflow)?;
} else {
return Err(Error::<T>::TokenUnlockLedgerNotFound);
}
Ok(())
},
)?;
TimeUnitUnlockLedger::<T>::mutate_exists(
&time_unit,
&token_id,
|value| -> Result<(), Error<T>> {
if let Some((total_locked_origin, ledger_list_origin, _)) =
value
{
if total_locked_origin == &unlock_amount {
if let Some((total_locked_origin, _, _)) = value {
if total_locked_origin == &tmp_amount {
*value = None;
return Ok(());
}
*total_locked_origin = total_locked_origin
.checked_sub(&unlock_amount)
.checked_sub(&tmp_amount)
.ok_or(Error::<T>::CalculationOverflow)?;
ledger_list_origin.retain(|x| x != index);
} else {
return Err(Error::<T>::TimeUnitUnlockLedgerNotFound);
}
Ok(())
},
)
.ok();
tmp_amount = tmp_amount.saturating_sub(unlock_amount);
// } else {
// return Err(Error::<T>::TokenUnlockLedgerNotFound.into());
)?;
Ok((index, true))
}
false
} else {
TokenUnlockLedger::<T>::mutate_exists(
&token_id,
&index,
|value| -> Result<(), Error<T>> {
if let Some((_, total_locked_origin, _, _)) = value {
if total_locked_origin == &tmp_amount {
*value = None;
return Ok(());
}
*total_locked_origin = total_locked_origin
.checked_sub(&tmp_amount)
.ok_or(Error::<T>::CalculationOverflow)?;
} else {
return Err(Error::<T>::TokenUnlockLedgerNotFound);
}
Ok(())
},
)
.ok();
TimeUnitUnlockLedger::<T>::mutate_exists(
&time_unit,
&token_id,
|value| -> Result<(), Error<T>> {
if let Some((total_locked_origin, _, _)) = value {
if total_locked_origin == &tmp_amount {
*value = None;
return Ok(());
}
*total_locked_origin = total_locked_origin
.checked_sub(&tmp_amount)
.ok_or(Error::<T>::CalculationOverflow)?;
} else {
return Err(Error::<T>::TimeUnitUnlockLedgerNotFound);
}
Ok(())
},
)
.ok();
true
Ok((index, true))
}
} else {
true
}
});
let ledger_list_tmp: Vec<UnlockId> = ledger_list.into_iter().rev().collect();
})
.collect::<Result<Vec<(UnlockId, bool)>, Error<T>>>()?;
tmp.retain(|(_index, result)| *result);

let ledger_list_tmp: Vec<UnlockId> =
tmp.into_iter().map(|(index, _)| index).rev().collect();

ledger_list =
BoundedVec::<UnlockId, T::MaximumUnlockIdOfUser>::try_from(ledger_list_tmp)
Expand Down
2 changes: 1 addition & 1 deletion pallets/vtoken-minting/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ impl pallet_xcm::Config for Runtime {
type TrustedLockers = ();
type SovereignAccountOf = ();
type MaxLockers = ConstU32<8>;
type WeightInfo = pallet_xcm::TestWeightInfo; // TODO: config after polkadot impl WeightInfo for ()
type WeightInfo = pallet_xcm::TestWeightInfo;
#[cfg(feature = "runtime-benchmarks")]
type ReachableDest = ReachableDest;
type AdminOrigin = EnsureRoot<AccountId>;
Expand Down
Loading

0 comments on commit 7ed0c3a

Please sign in to comment.