Skip to content

Commit

Permalink
Merge branch 'master' into runtime-upgrade/polkadot-1.1.0
Browse files Browse the repository at this point in the history
# Conflicts:
#	pallets/auction/src/lib.rs
#	scripts/init.sh
  • Loading branch information
chexware committed Mar 22, 2024
2 parents c0bf47d + d44448d commit e0e12b6
Show file tree
Hide file tree
Showing 14 changed files with 447 additions and 96 deletions.
2 changes: 1 addition & 1 deletion NODE.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ installed locally.
#### Downloading the docker image
```sh
docker pull bitcountry/continuum-collator-node:latest
docker pull bitcountry/continuum-collator-node:b2d0ea7
```
#### Running the docker image
Expand Down
7 changes: 2 additions & 5 deletions modules/bridge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,25 +194,22 @@ pub mod pallet {
ensure!(BridgeFee::<T>::contains_key(&chain_id), Error::<T>::FeeOptionsMissing);
let (min_fee, fee_scale) = Self::bridge_fee(chain_id);

let fee_estimated = amount.saturating_mul(fee_scale.into());
let fee_estimated = currency_id.1 * amount;
let fee = if fee_estimated > min_fee {
fee_estimated
} else {
min_fee
};

let mut actual_fee = Zero::zero();
let mut actual_fee = fee;
if currency_id.0 == FungibleTokenId::NativeToken(0) {
actual_fee = fee;
T::Currency::transfer(
&source,
&bridge_id,
(amount + actual_fee).into(),
ExistenceRequirement::AllowDeath,
)?;
} else {
actual_fee = currency_id.1 * fee;

// Transfer the fee as native token first
T::Currency::transfer(&source, &bridge_id, actual_fee.into(), ExistenceRequirement::AllowDeath)?;
// Handle the multi currency token transfer
Expand Down
55 changes: 28 additions & 27 deletions pallets/auction/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

use frame_support::traits::{Currency, ExistenceRequirement, LockableCurrency, ReservableCurrency};
use frame_support::{ensure, pallet_prelude::*, transactional};
use frame_system::{self as system, ensure_signed, pallet_prelude::BlockNumberFor};
use frame_system::{self as system, ensure_signed};
use sp_core::sp_std::convert::TryInto;
use sp_runtime::SaturatedConversion;
use sp_runtime::{
Expand Down Expand Up @@ -100,6 +100,7 @@ pub mod migration_v2 {
#[frame_support::pallet]
pub mod pallet {
use frame_support::dispatch::DispatchResultWithPostInfo;
use frame_support::log;
use frame_support::sp_runtime::traits::CheckedSub;
use frame_system::pallet_prelude::OriginFor;
use orml_traits::{MultiCurrency, MultiReservableCurrency};
Expand Down Expand Up @@ -799,9 +800,9 @@ pub mod pallet {
}

#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
impl<T: Config> Hooks<T::BlockNumber> for Pallet<T> {
/// Hooks that call every new block is initialized.
fn on_initialize(now: BlockNumberFor<T>) -> Weight {
fn on_initialize(now: T::BlockNumber) -> Weight {
let mut total_item = 0;
for (auction_id, _) in <AuctionEndTime<T>>::drain_prefix(&now) {
total_item += 1;
Expand All @@ -813,19 +814,19 @@ pub mod pallet {
T::WeightInfo::on_finalize().saturating_mul(total_item)
}

fn on_runtime_upgrade() -> Weight {
Self::upgrade_auction_item_data_v3();
Weight::from_parts(0, 0)
}
// fn on_runtime_upgrade() -> Weight {
// Self::upgrade_auction_item_data_v3();
// Weight::from_(0u64)
// }
}

impl<T: Config> Auction<T::AccountId, BlockNumberFor<T>> for Pallet<T> {
impl<T: Config> Auction<T::AccountId, T::BlockNumber> for Pallet<T> {
type Balance = BalanceOf<T>;

/// Internal update auction extension
fn update_auction(
id: AuctionId,
info: AuctionInfo<T::AccountId, Self::Balance, BlockNumberFor<T>>,
info: AuctionInfo<T::AccountId, Self::Balance, T::BlockNumber>,
) -> DispatchResult {
let auction = <Auctions<T>>::get(id).ok_or(Error::<T>::AuctionDoesNotExist)?;
if let Some(old_end) = auction.end {
Expand All @@ -843,10 +844,10 @@ pub mod pallet {
fn new_auction(
_recipient: T::AccountId,
_initial_amount: Self::Balance,
start: BlockNumberFor<T>,
end: Option<BlockNumberFor<T>>,
start: T::BlockNumber,
end: Option<T::BlockNumber>,
) -> Result<AuctionId, DispatchError> {
let auction: AuctionInfo<T::AccountId, Self::Balance, BlockNumberFor<T>> =
let auction: AuctionInfo<T::AccountId, Self::Balance, T::BlockNumber> =
AuctionInfo { bid: None, start, end };

let auction_id: AuctionId = AuctionsIndex::<T>::try_mutate(|n| -> Result<AuctionId, DispatchError> {
Expand All @@ -869,10 +870,10 @@ pub mod pallet {
fn create_auction(
auction_type: AuctionType,
item_id: ItemId<Self::Balance>,
_end: Option<BlockNumberFor<T>>,
_end: Option<T::BlockNumber>,
recipient: T::AccountId,
initial_amount: Self::Balance,
_start: BlockNumberFor<T>,
_start: T::BlockNumber,
listing_level: ListingLevel<T::AccountId>,
listing_fee: Perbill,
currency_id: FungibleTokenId,
Expand Down Expand Up @@ -1184,7 +1185,7 @@ pub mod pallet {

/// Internal auction bid handler
fn auction_bid_handler(from: T::AccountId, id: AuctionId, value: Self::Balance) -> DispatchResult {
let auction_item: AuctionItem<T::AccountId, BlockNumberFor<T>, BalanceOf<T>> =
let auction_item: AuctionItem<T::AccountId, T::BlockNumber, BalanceOf<T>> =
Self::get_auction_item(id.clone()).ok_or(Error::<T>::AuctionDoesNotExist)?;
ensure!(
auction_item.auction_type == AuctionType::Auction,
Expand Down Expand Up @@ -1267,7 +1268,7 @@ pub mod pallet {

/// Internal auction bid handler for local marketplace
fn local_auction_bid_handler(
_now: BlockNumberFor<T>,
_now: T::BlockNumber,
id: AuctionId,
new_bid: (T::AccountId, Self::Balance),
last_bid: Option<(T::AccountId, Self::Balance)>,
Expand Down Expand Up @@ -1319,12 +1320,12 @@ pub mod pallet {
}

/// Internal get auction info
fn auction_info(id: AuctionId) -> Option<AuctionInfo<T::AccountId, Self::Balance, BlockNumberFor<T>>> {
fn auction_info(id: AuctionId) -> Option<AuctionInfo<T::AccountId, Self::Balance, T::BlockNumber>> {
Self::auctions(id)
}

/// Internal get auction info
fn auction_item(id: AuctionId) -> Option<AuctionItem<T::AccountId, BlockNumberFor<T>, Self::Balance>> {
fn auction_item(id: AuctionId) -> Option<AuctionItem<T::AccountId, T::BlockNumber, Self::Balance>> {
Self::get_auction_item(id)
}

Expand Down Expand Up @@ -1388,7 +1389,7 @@ pub mod pallet {
let block_number = <system::Pallet<T>>::block_number();
ensure!(block_number >= auction.start, Error::<T>::AuctionHasNotStarted);
if !(auction.end.is_none()) {
let auction_end: BlockNumberFor<T> = auction.end.ok_or(Error::<T>::AuctionIsExpired)?;
let auction_end: T::BlockNumber = auction.end.ok_or(Error::<T>::AuctionIsExpired)?;
ensure!(block_number < auction_end, Error::<T>::AuctionIsExpired);
}

Expand Down Expand Up @@ -1576,13 +1577,13 @@ pub mod pallet {
}
}

impl<T: Config> AuctionHandler<T::AccountId, BalanceOf<T>, BlockNumberFor<T>, AuctionId> for Pallet<T> {
impl<T: Config> AuctionHandler<T::AccountId, BalanceOf<T>, T::BlockNumber, AuctionId> for Pallet<T> {
fn on_new_bid(
_now: BlockNumberFor<T>,
_now: T::BlockNumber,
_id: AuctionId,
_new_bid: (T::AccountId, BalanceOf<T>),
_last_bid: Option<(T::AccountId, BalanceOf<T>)>,
) -> OnNewBidResult<BlockNumberFor<T>> {
) -> OnNewBidResult<T::BlockNumber> {
OnNewBidResult {
accept_bid: true,
auction_end_change: Change::NoChange,
Expand Down Expand Up @@ -1786,7 +1787,7 @@ pub mod pallet {
}

impl<T: Config> Pallet<T> {
fn check_valid_finality(end: &BlockNumberFor<T>, quantity: u32) -> bool {
fn check_valid_finality(end: &T::BlockNumber, quantity: u32) -> bool {
let existing_auctions_same_block: u32 = <AuctionEndTime<T>>::iter_prefix_values(end).count() as u32;
let total_auction_in_same_block = existing_auctions_same_block.saturating_add(quantity);

Expand Down Expand Up @@ -1855,9 +1856,9 @@ pub mod pallet {
let mut num_auction_items = 0;

AuctionItems::<T>::translate(
|_k, auction_v2: AuctionItemV2<T::AccountId, BlockNumberFor<T>, BalanceOf<T>>| {
|_k, auction_v2: AuctionItemV2<T::AccountId, T::BlockNumber, BalanceOf<T>>| {
num_auction_items += 1;
let v3: AuctionItem<T::AccountId, BlockNumberFor<T>, BalanceOf<T>> = AuctionItem {
let v3: AuctionItem<T::AccountId, T::BlockNumber, BalanceOf<T>> = AuctionItem {
item_id: auction_v2.item_id,
recipient: auction_v2.recipient,
initial_amount: auction_v2.initial_amount,
Expand All @@ -1874,7 +1875,7 @@ pub mod pallet {
);

log::info!("{} auction items upgraded:", num_auction_items);
Weight::from_parts(0, 0)
Weight::from_ref_time(0)
}

pub fn swap_new_bid(
Expand Down Expand Up @@ -1938,7 +1939,7 @@ pub mod pallet {
})
}

fn extend_auction_end_time(id: AuctionId, new_end_block: BlockNumberFor<T>) -> DispatchResult {
fn extend_auction_end_time(id: AuctionId, new_end_block: T::BlockNumber) -> DispatchResult {
<AuctionItems<T>>::try_mutate_exists(id, |auction_item| -> DispatchResult {
let mut auction_item = auction_item.as_mut().ok_or(Error::<T>::AuctionDoesNotExist)?;
auction_item.end_time = new_end_block;
Expand Down
5 changes: 0 additions & 5 deletions pallets/crowdloan/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,6 @@ pub mod pallet {
let who = ensure_signed(origin.clone())?;

ensure!(Self::is_accepted_origin(&who), Error::<T>::NoPermission);
let target = T::Lookup::lookup(to.clone())?;
// Get existing vesting schedule
let vesting_info = T::VestingSchedule::vesting_balance(&target);
// Ensure user doesn't have any vested reward
ensure!(vesting_info == None, Error::<T>::UserAlreadyGotExistingVestingInfo);

VestingModule::<T>::vested_transfer(origin, to, schedule)?;

Expand Down
5 changes: 2 additions & 3 deletions pallets/economy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -601,10 +601,9 @@ pub mod pallet {
///
/// The dispatch origin for this call must be _Signed_.
///
/// `amount`: the unstake amount
///
/// Emit `UnstakedInnovation` event if successful
#[pallet::weight(T::WeightInfo::stake_a())]
/// Emit `ClaimRewards` event if successful
#[pallet::weight(T::WeightInfo::claim_reward())]
#[transactional]
pub fn claim_reward(origin: OriginFor<T>) -> DispatchResult {
let who = ensure_signed(origin)?;
Expand Down
16 changes: 9 additions & 7 deletions pallets/economy/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,13 +496,14 @@ impl ExtBuilder {
.unwrap();

pallet_balances::GenesisConfig::<Runtime> {
balances: vec![(ALICE, 10000)],
}
.assimilate_storage(&mut t)
.unwrap();

pallet_balances::GenesisConfig::<Runtime> {
balances: vec![(BOB, 20000)],
balances: vec![
(ALICE, 10000),
(BOB, 20000),
(
<mock::Runtime as pallet::Config>::RewardPayoutAccount::get().into_account_truncating(),
30000,
),
],
}
.assimilate_storage(&mut t)
.unwrap();
Expand All @@ -525,6 +526,7 @@ pub fn run_to_block(n: u64) {
System::set_block_number(System::block_number() + 1);
System::on_initialize(System::block_number());
Mining::on_initialize(System::block_number());
EconomyModule::on_initialize(System::block_number());
}
}

Expand Down
Loading

0 comments on commit e0e12b6

Please sign in to comment.