use alloc::vec::*;
use pezframe_support::{
dispatch::DispatchResult,
traits::{Currency, ReservableCurrency},
};
use pezkuwi_primitives::{HeadData, Id as ParaId, ValidationCode};
pub trait Registrar {
type AccountId;
fn manager_of(id: ParaId) -> Option<Self::AccountId>;
fn teyrchains() -> Vec<ParaId>;
fn is_teyrchain(id: ParaId) -> bool {
Self::teyrchains().binary_search(&id).is_ok()
}
fn is_parathread(id: ParaId) -> bool;
fn is_registered(id: ParaId) -> bool {
Self::is_parathread(id) || Self::is_teyrchain(id)
}
fn apply_lock(id: ParaId);
fn remove_lock(id: ParaId);
fn register(
who: Self::AccountId,
id: ParaId,
genesis_head: HeadData,
validation_code: ValidationCode,
) -> DispatchResult;
fn deregister(id: ParaId) -> DispatchResult;
fn make_teyrchain(id: ParaId) -> DispatchResult;
fn make_parathread(id: ParaId) -> DispatchResult;
#[cfg(any(feature = "runtime-benchmarks", test))]
fn worst_head_data() -> HeadData;
#[cfg(any(feature = "runtime-benchmarks", test))]
fn worst_validation_code() -> ValidationCode;
#[cfg(any(feature = "runtime-benchmarks", test))]
fn execute_pending_transitions();
}
#[derive(Debug)]
pub enum LeaseError {
ReserveFailed,
AlreadyLeased,
AlreadyEnded,
NoLeasePeriod,
}
pub trait Leaser<BlockNumber> {
type AccountId;
type LeasePeriod;
type Currency: ReservableCurrency<Self::AccountId>;
fn lease_out(
para: ParaId,
leaser: &Self::AccountId,
amount: <Self::Currency as Currency<Self::AccountId>>::Balance,
period_begin: Self::LeasePeriod,
period_count: Self::LeasePeriod,
) -> Result<(), LeaseError>;
fn deposit_held(
para: ParaId,
leaser: &Self::AccountId,
) -> <Self::Currency as Currency<Self::AccountId>>::Balance;
#[cfg(any(feature = "runtime-benchmarks", test))]
fn lease_period_length() -> (BlockNumber, BlockNumber);
fn lease_period_index(block: BlockNumber) -> Option<(Self::LeasePeriod, bool)>;
fn already_leased(
para_id: ParaId,
first_period: Self::LeasePeriod,
last_period: Self::LeasePeriod,
) -> bool;
}
#[derive(PartialEq, Debug)]
pub enum AuctionStatus<BlockNumber> {
NotStarted,
StartingPeriod,
EndingPeriod(BlockNumber, BlockNumber),
VrfDelay(BlockNumber),
}
impl<BlockNumber> AuctionStatus<BlockNumber> {
pub fn is_in_progress(&self) -> bool {
!matches!(self, Self::NotStarted)
}
pub fn is_starting(&self) -> bool {
matches!(self, Self::StartingPeriod)
}
pub fn is_ending(self) -> Option<(BlockNumber, BlockNumber)> {
match self {
Self::EndingPeriod(sample, sub_sample) => Some((sample, sub_sample)),
_ => None,
}
}
pub fn is_vrf(&self) -> bool {
matches!(self, Self::VrfDelay(_))
}
}
pub trait Auctioneer<BlockNumber> {
type AccountId;
type LeasePeriod;
type Currency: ReservableCurrency<Self::AccountId>;
fn new_auction(duration: BlockNumber, lease_period_index: Self::LeasePeriod) -> DispatchResult;
fn auction_status(now: BlockNumber) -> AuctionStatus<BlockNumber>;
fn place_bid(
bidder: Self::AccountId,
para: ParaId,
first_slot: Self::LeasePeriod,
last_slot: Self::LeasePeriod,
amount: <Self::Currency as Currency<Self::AccountId>>::Balance,
) -> DispatchResult;
#[cfg(any(feature = "runtime-benchmarks", test))]
fn lease_period_length() -> (BlockNumber, BlockNumber);
fn lease_period_index(block: BlockNumber) -> Option<(Self::LeasePeriod, bool)>;
fn has_won_an_auction(para: ParaId, bidder: &Self::AccountId) -> bool;
}
#[impl_trait_for_tuples::impl_for_tuples(30)]
pub trait OnSwap {
fn on_swap(one: ParaId, other: ParaId);
}