Skip to content

Commit

Permalink
Mainly code documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
ndkazu committed Feb 4, 2023
1 parent 720a0e1 commit 71db366
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 13 deletions.
15 changes: 9 additions & 6 deletions pallets/asset_management/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ impl<T: Config> Pallet<T> {
let ror = T::RoR::get();
let price0 = Onboarding::Pallet::<T>::houses(collection, item).unwrap().price.unwrap();
let price1 = Onboarding::Pallet::<T>::balance_to_u64_option(ror.mul_floor(price0)).unwrap();
let rent = ((price1 as f64) / 12.0).round();
let time = <T as Config>::Lease::get();
let rent = ((price1 as f64) / time as f64).round();
let amount: u128 = coeff * (rent as u128);
amount
}
Expand Down Expand Up @@ -118,16 +119,17 @@ impl<T: Config> Pallet<T> {
Onboarding::Pallet::<T>::balance_to_u64_option(ror.mul_floor(price0)).unwrap();

//Update rent in tenant infos added.
let rent0 = ((price1 as f64) / 12.0).round();
let rent1 = (rent0 as u128) * 12;
let time = <T as Config>::Lease::get();
let rent0 = ((price1 as f64) / time as f64).round();
let rent1 = (rent0 as u128) * time as u128;
let now = <frame_system::Pallet<T>>::block_number();

let rent = Roles::Pallet::<T>::u128_to_balance_option(rent0 as u128).unwrap();
let year_rent = Roles::Pallet::<T>::u128_to_balance_option(rent1).unwrap();
val0.rent = rent.into();
val0.asset_account = Some(asset_account);
val0.remaining_rent = year_rent;
val0.remaining_payments = 12;
val0.remaining_payments = time as u8;
val0.contract_start = now;
*val = Some(val0);
});
Expand Down Expand Up @@ -263,10 +265,11 @@ impl<T: Config> Pallet<T> {
for i in tenants {
let tenant = Roles::Pallet::<T>::tenants(i).unwrap();
if !tenant.asset_account.is_none() {
let time = <T as Config>::Lease::get();
let remaining_p = tenant.remaining_payments;
let contract_begin = tenant.contract_start;
let rent =
Roles::Pallet::<T>::balance_to_u128_option(tenant.rent).unwrap() * 12;
Roles::Pallet::<T>::balance_to_u128_option(tenant.rent).unwrap() * time as u128;
let rent_float = rent as f64;

//Calculate rent per block
Expand All @@ -281,7 +284,7 @@ impl<T: Config> Pallet<T> {
let amount_due = blocks.saturating_mul(rpb);

//check how many rents were payed
let payed = (12 - remaining_p as u128) * rent.clone();
let payed = (time as u128 - remaining_p as u128) * rent.clone();
if payed < amount_due && (now % <T as Config>::RentCheck::get()).is_zero() {
let tenant_debt0 = amount_due - payed;
let debt = Self::u128_to_balance_option2(tenant_debt0).unwrap();
Expand Down
16 changes: 16 additions & 0 deletions pallets/asset_management/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
//! proposals:
//! - Admit a Tenant for a given asset.
//! - Evict a Tenant from a given asset.
//! The Representative has to submit a judgement about the tenant profile. This judgement
//! will be considered by the owners before voting.
//! Representatives receive a judgement fee from the aspiring tenant.
//! A positive result of the referendum will send a guaranty_deposit payment request to the tenant.
//! When the tenant finally pays the guaranty_deposit,his account is connected to the asset through `link_tenant_to_asset`
//! and this marks the start of his contract with the owners.
//!
//! * `link_tenant_to_asset` - Call used as a proposal to link an accepted tenant with an existing
//! asset.
Expand Down Expand Up @@ -101,26 +107,36 @@ pub mod pallet {
type Currency: Currency<Self::AccountId> + ReservableCurrency<Self::AccountId>;
type WeightInfo: WeightInfo;

/// Number of months for the guaranty deposit
#[pallet::constant]
type Guaranty: Get<u32>;

/// Return on Rent
#[pallet::constant]
type RoR: Get<Percent>;

#[pallet::constant]
type MinimumDepositVote: Get<BalanceOf<Self>>;

/// Fees payed to the Representative by the tenant, to provide a judgement
#[pallet::constant]
type RepFees: Get<BalanceOf<Self>>;

/// Lease period in number of blocks
#[pallet::constant]
type ContractLength: Get<Self::BlockNumber>;

/// Period between check of Referendum status
#[pallet::constant]
type CheckPeriod: Get<Self::BlockNumber>;

/// Period between check of rent payment status for active tenants
#[pallet::constant]
type RentCheck: Get<Self::BlockNumber>;

/// Lease period in number of months
#[pallet::constant]
type Lease: Get<u32>;
}

//Store the referendum_index and the struct containing the
Expand Down
2 changes: 2 additions & 0 deletions pallets/asset_management/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ parameter_types! {
pub const RoR:Percent = Percent::from_percent(RETURN_ON_RENT);
pub const RentCheckPeriod: BlockNumber = 1;
pub const ContractLength: BlockNumber = 365;
pub const Lease: u32 = 12;
}

impl pallet_asset_management::Config for Test {
Expand All @@ -426,6 +427,7 @@ impl pallet_asset_management::Config for Test {
type Guaranty = GuarantyCoefficient;
type ContractLength = ContractLength;
type RoR = RoR;
type Lease = Lease;
type WeightInfo = ();
}

Expand Down
32 changes: 25 additions & 7 deletions pallets/tenancy/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
//!# Tenancy Pallet
//!
//!The Tenancy pallet is used by aspiring and active tenants to execute payments
//!and make requests depending on their status.
//!
//!## Overview
//!Using this pallet, a user with the Tenant role can do the following:
//!- Request a lease for a purchased asset
//!- Pay a guaranty_deposit to confirm the lease start
//!- Pay his rent
//!
//!### Dispatchable Functions
//!
//!* `request_asset` - A prospecting tenant can requestfor a particular asset
//! after providing personal information requested by the Representative.
//!
//!* `pay_guaranty_deposit` - A newly selected tenant pays for a guaranty deposit
//! requested by the asset's owners, and confirms the start of his contract/lease.
//!
//!* `pay_rent` - The Tenant can pay the monthly rent anytime.
//! He cannot pay more than 12 months, which is the length of the lease/contract.
#![cfg_attr(not(feature = "std"), no_std)]
#![allow(clippy::unused_unit)]
#![allow(clippy::upper_case_acronyms)]
Expand Down Expand Up @@ -51,6 +73,7 @@ pub mod pallet {
type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
type WeightInfo: WeightInfo;
type Currency: Currency<Self::AccountId> + ReservableCurrency<Self::AccountId>;

}

#[pallet::storage]
Expand All @@ -59,15 +82,10 @@ pub mod pallet {
pub type Tenants<T: Config> =
StorageMap<_, Blake2_128Concat, T::AccountId, RegisteredTenant<T>, OptionQuery>;

// Pallets use events to inform users when important changes are made.
// https://docs.substrate.io/main-docs/build/events-errors/
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
/// Event documentation should end with an array that provides descriptive names for event
/// parameters. [something, who]
SomethingStored(u32, T::AccountId),


///Guaranty deposit successfully payed
GuarantyDepositPayment {
tenant: T::AccountId,
Expand Down Expand Up @@ -176,7 +194,7 @@ pub mod pallet {
}

/// The function below allows the newly selected tenant to pay for a guaranty deposit request
/// and confirm the start of his contract.
/// and confirms the start of his contract.
/// The origin must be the tenant.
/// - asset_type: Asset class requested by the tenant.
/// - asset_id: ID of the Asset requested by the tenant.
Expand Down
3 changes: 3 additions & 0 deletions pallets/tenancy/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ impl system::Config for Test {
type MaxConsumers = frame_support::traits::ConstU32<16>;
}


impl pallet_tenancy::Config for Test {
type Event = Event;
type Currency = Balances;
Expand Down Expand Up @@ -441,6 +442,7 @@ parameter_types! {
pub const RoR:Percent = Percent::from_percent(RETURN_ON_RENT);
pub const RentCheckPeriod: BlockNumber = 25;
pub const ContractLength: BlockNumber = 365;
pub const Lease: u32 = 12;
}

impl pallet_asset_management::Config for Test {
Expand All @@ -457,6 +459,7 @@ impl pallet_asset_management::Config for Test {
type Guaranty = GuarantyCoefficient;
type ContractLength = ContractLength;
type RoR = RoR;
type Lease = Lease;
type WeightInfo = ();
}

Expand Down
8 changes: 8 additions & 0 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -668,11 +668,18 @@ impl pallet_bidding::Config for Runtime {
}

parameter_types! {
//Fees payed to the Representative by the tenant, to provide a judgement
pub const JudgementFee: Balance= 50*DOLLARS;
//Number of months for the guaranty deposit
pub const GuarantyCoefficient: u32 = 3;
//Return on Rent
pub const RoR:Percent = Percent::from_percent(3);
//Period between check of rent payment status for active tenants
pub const RentCheckPeriod: BlockNumber = 15*DAYS;
//Lease period in number of blocks
pub const ContractLength: BlockNumber = 365*DAYS;
//Lease period in number of months
pub const Lease: u32 = 12;
}
impl pallet_asset_management::Config for Runtime {
type Event = Event;
Expand All @@ -688,6 +695,7 @@ impl pallet_asset_management::Config for Runtime {
type Guaranty = GuarantyCoefficient;
type ContractLength = ContractLength;
type RoR = RoR;
type Lease = Lease;
type WeightInfo = ();
}

Expand Down

0 comments on commit 71db366

Please sign in to comment.