Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add type to legal fee beneficiary. #24

Merged
merged 1 commit into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions logion-shared/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ keywords = ['logion']
targets = ['x86_64-unknown-linux-gnu']

[dependencies]
codec = { package = "parity-scale-codec", version = "3.2.1", default-features = false, features = ["derive", "max-encoded-len"] }
frame-support = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.41" }
frame-system = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.41" }
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
sp-std = { git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "polkadot-v0.9.41" }

[features]
Expand Down
10 changes: 9 additions & 1 deletion logion-shared/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use frame_support::{
Parameter,
traits::{EnsureOrigin, UnfilteredDispatchable, Imbalance},
};
use frame_support::codec::{Decode, Encode};
use frame_support::dispatch::DispatchResultWithPostInfo;
use frame_support::scale_info::TypeInfo;
use frame_support::sp_runtime::Percent;
use frame_support::traits::tokens::Balance;
use frame_system::{ensure_signed, RawOrigin};
Expand Down Expand Up @@ -137,10 +139,16 @@ pub trait RewardDistributor<I: Imbalance<B>, B: Balance> {

pub type EuroCent = u32;

#[derive(Encode, Decode, Clone, PartialEq, Eq, Debug, TypeInfo, Copy)]
pub enum Beneficiary<AccountId> {
Treasury,
LegalOfficer(AccountId),
}

pub trait LegalFee<I: Imbalance<B>, B: Balance, LocType, AccountId> {

fn get_legal_fee(loc_type: LocType) -> EuroCent;

/// Determine, distribute to, and return the beneficiary of Legal fee.
fn distribute(amount: I, loc_type: LocType, loc_owner: AccountId) -> AccountId;
fn distribute(amount: I, loc_type: LocType, loc_owner: AccountId) -> Beneficiary<AccountId>;
}
6 changes: 3 additions & 3 deletions pallet-logion-loc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ pub mod pallet {
};
use codec::HasCompact;
use frame_support::traits::{Currency};
use logion_shared::{LocQuery, LocValidity, IsLegalOfficer, RewardDistributor, DistributionKey, LegalFee, EuroCent};
use logion_shared::{LocQuery, LocValidity, IsLegalOfficer, RewardDistributor, DistributionKey, LegalFee, EuroCent, Beneficiary};
use super::*;
pub use crate::weights::WeightInfo;

Expand Down Expand Up @@ -438,8 +438,8 @@ pub mod pallet {
SponsorshipCreated(T::SponsorshipId, T::AccountId, SupportedAccountId<T::AccountId, T::EthereumAddress>),
/// Issued when a sponsorship was successfully withdrawn [sponsorship_id, sponsor, sponsored_account]
SponsorshipWithdrawn(T::SponsorshipId, T::AccountId, SupportedAccountId<T::AccountId, T::EthereumAddress>),
/// Issued when Legal Fee is withdrawn. [payerAccountId, beneficiaryAccountId, legalFee]
LegalFeeWithdrawn(T::AccountId, T::AccountId, BalanceOf<T>),
/// Issued when Legal Fee is withdrawn. [payerAccountId, beneficiary, legalFee]
LegalFeeWithdrawn(T::AccountId, Beneficiary<T::AccountId>, BalanceOf<T>),
}

#[pallet::error]
Expand Down
12 changes: 6 additions & 6 deletions pallet-logion-loc/src/mock.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{self as pallet_loc, LocType, NegativeImbalanceOf, RequesterOf};
use logion_shared::{DistributionKey, EuroCent, IsLegalOfficer, LegalFee, RewardDistributor};
use logion_shared::{Beneficiary, DistributionKey, EuroCent, IsLegalOfficer, LegalFee, RewardDistributor};
use sp_core::hash::H256;
use frame_support::{construct_runtime, parameter_types, traits::{EnsureOrigin, Currency}};
use sp_runtime::{traits::{BlakeTwo256, IdentityLookup}, testing::Header, Percent};
Expand Down Expand Up @@ -161,13 +161,13 @@ impl LegalFee<NegativeImbalanceOf<Test>, Balance, LocType, AccountId> for LegalF
}
}

fn distribute(amount: NegativeImbalanceOf<Test>, loc_type: LocType, loc_owner: AccountId) -> AccountId {
fn distribute(amount: NegativeImbalanceOf<Test>, loc_type: LocType, loc_owner: AccountId) -> Beneficiary<AccountId> {

let beneficiary = match loc_type {
LocType::Identity => TREASURY_ACCOUNT_ID,
_ => loc_owner,
let (beneficiary, target) = match loc_type {
LocType::Identity => (Beneficiary::Treasury, TREASURY_ACCOUNT_ID),
_ => (Beneficiary::LegalOfficer(loc_owner), loc_owner),
};
Balances::resolve_creating(&beneficiary, amount);
Balances::resolve_creating(&target, amount);
beneficiary
}
}
Expand Down
10 changes: 7 additions & 3 deletions pallet-logion-loc/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use sp_core::{H256, H160};
use sp_runtime::traits::BlakeTwo256;
use sp_runtime::traits::Hash;

use logion_shared::{LocQuery, LocValidity};
use logion_shared::{Beneficiary, LocQuery, LocValidity};

use crate::{Error, File, LegalOfficerCase, LocLink, LocType, MetadataItem, CollectionItem, CollectionItemFile, CollectionItemToken, mock::*, TermsAndConditionsElement, TokensRecordFile, UnboundedTokensRecordFileOf, VerifiedIssuer, Config, OtherAccountId, SupportedAccountId, MetadataItemParams, FileParams};
use crate::Requester::{Account, OtherAccount};
Expand Down Expand Up @@ -381,11 +381,15 @@ fn check_storage_fees(num_of_files: u32, tot_size: &u32, payer: AccountId) {
}));
}

fn check_legal_fees(expected_fees: Balance, payer: AccountId, beneficiary: AccountId) {
let credited_fees: Balance = get_free_balance(beneficiary) - BALANCE_OK_FOR_LOC_CREATION;
fn check_legal_fees(expected_fees: Balance, payer: AccountId, beneficiary_account: AccountId) {
let credited_fees: Balance = get_free_balance(beneficiary_account) - BALANCE_OK_FOR_LOC_CREATION;
assert_eq!(credited_fees, expected_fees);
let debited_fees: Balance = BALANCE_OK_FOR_LOC_CREATION - get_free_balance(payer);
assert_eq!(debited_fees, expected_fees);
let beneficiary = match beneficiary_account {
TREASURY_ACCOUNT_ID => Beneficiary::Treasury,
_ => Beneficiary::LegalOfficer(beneficiary_account)
};
if expected_fees > 0 {
System::assert_has_event(RuntimeEvent::LogionLoc(crate::Event::LegalFeeWithdrawn {
0: payer,
Expand Down