From 71db366c0ca44de3fd99d1d0d584ef92bcdf1b5e Mon Sep 17 00:00:00 2001 From: Kazunobu Ndong Date: Sat, 4 Feb 2023 12:30:01 +0900 Subject: [PATCH] Mainly code documentation --- pallets/asset_management/src/functions.rs | 15 ++++++----- pallets/asset_management/src/lib.rs | 16 ++++++++++++ pallets/asset_management/src/mock.rs | 2 ++ pallets/tenancy/src/lib.rs | 32 ++++++++++++++++++----- pallets/tenancy/src/mock.rs | 3 +++ runtime/src/lib.rs | 8 ++++++ 6 files changed, 63 insertions(+), 13 deletions(-) diff --git a/pallets/asset_management/src/functions.rs b/pallets/asset_management/src/functions.rs index abace7e2..457a49f5 100644 --- a/pallets/asset_management/src/functions.rs +++ b/pallets/asset_management/src/functions.rs @@ -72,7 +72,8 @@ impl Pallet { let ror = T::RoR::get(); let price0 = Onboarding::Pallet::::houses(collection, item).unwrap().price.unwrap(); let price1 = Onboarding::Pallet::::balance_to_u64_option(ror.mul_floor(price0)).unwrap(); - let rent = ((price1 as f64) / 12.0).round(); + let time = ::Lease::get(); + let rent = ((price1 as f64) / time as f64).round(); let amount: u128 = coeff * (rent as u128); amount } @@ -118,8 +119,9 @@ impl Pallet { Onboarding::Pallet::::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 = ::Lease::get(); + let rent0 = ((price1 as f64) / time as f64).round(); + let rent1 = (rent0 as u128) * time as u128; let now = >::block_number(); let rent = Roles::Pallet::::u128_to_balance_option(rent0 as u128).unwrap(); @@ -127,7 +129,7 @@ impl Pallet { 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); }); @@ -263,10 +265,11 @@ impl Pallet { for i in tenants { let tenant = Roles::Pallet::::tenants(i).unwrap(); if !tenant.asset_account.is_none() { + let time = ::Lease::get(); let remaining_p = tenant.remaining_payments; let contract_begin = tenant.contract_start; let rent = - Roles::Pallet::::balance_to_u128_option(tenant.rent).unwrap() * 12; + Roles::Pallet::::balance_to_u128_option(tenant.rent).unwrap() * time as u128; let rent_float = rent as f64; //Calculate rent per block @@ -281,7 +284,7 @@ impl Pallet { 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 % ::RentCheck::get()).is_zero() { let tenant_debt0 = amount_due - payed; let debt = Self::u128_to_balance_option2(tenant_debt0).unwrap(); diff --git a/pallets/asset_management/src/lib.rs b/pallets/asset_management/src/lib.rs index 9098d727..f3b53ff5 100644 --- a/pallets/asset_management/src/lib.rs +++ b/pallets/asset_management/src/lib.rs @@ -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. @@ -101,26 +107,36 @@ pub mod pallet { type Currency: Currency + ReservableCurrency; type WeightInfo: WeightInfo; + /// Number of months for the guaranty deposit #[pallet::constant] type Guaranty: Get; + /// Return on Rent #[pallet::constant] type RoR: Get; #[pallet::constant] type MinimumDepositVote: Get>; + /// Fees payed to the Representative by the tenant, to provide a judgement #[pallet::constant] type RepFees: Get>; + /// Lease period in number of blocks #[pallet::constant] type ContractLength: Get; + /// Period between check of Referendum status #[pallet::constant] type CheckPeriod: Get; + /// Period between check of rent payment status for active tenants #[pallet::constant] type RentCheck: Get; + + /// Lease period in number of months + #[pallet::constant] + type Lease: Get; } //Store the referendum_index and the struct containing the diff --git a/pallets/asset_management/src/mock.rs b/pallets/asset_management/src/mock.rs index 673a817a..2a41c018 100644 --- a/pallets/asset_management/src/mock.rs +++ b/pallets/asset_management/src/mock.rs @@ -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 { @@ -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 = (); } diff --git a/pallets/tenancy/src/lib.rs b/pallets/tenancy/src/lib.rs index 55b013e1..6a572f13 100644 --- a/pallets/tenancy/src/lib.rs +++ b/pallets/tenancy/src/lib.rs @@ -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)] @@ -51,6 +73,7 @@ pub mod pallet { type Event: From> + IsType<::Event>; type WeightInfo: WeightInfo; type Currency: Currency + ReservableCurrency; + } #[pallet::storage] @@ -59,15 +82,10 @@ pub mod pallet { pub type Tenants = StorageMap<_, Blake2_128Concat, T::AccountId, RegisteredTenant, 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 { - /// 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, @@ -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. diff --git a/pallets/tenancy/src/mock.rs b/pallets/tenancy/src/mock.rs index ab73fefc..173bbaa9 100644 --- a/pallets/tenancy/src/mock.rs +++ b/pallets/tenancy/src/mock.rs @@ -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; @@ -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 { @@ -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 = (); } diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 19994bd4..45459c61 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -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; @@ -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 = (); }