Skip to content
Snippets Groups Projects
Unverified Commit 3c9dfb7d authored by bgallois's avatar bgallois
Browse files

Fix #226

parent a307901c
No related branches found
No related tags found
1 merge request!263Upgrade to polkadot-v1.11.0
Showing
with 241 additions and 246 deletions
......@@ -53,7 +53,7 @@ Anonymously schedule a task.
<details><summary><code>cancel(when, index)</code></summary>
Taking 0.0239 % of a block.
Taking 0.0241 % of a block.
```rust
when: BlockNumberFor<T>
......@@ -86,7 +86,7 @@ Schedule a named task.
<details><summary><code>cancel_named(id)</code></summary>
Taking 0.0252 % of a block.
Taking 0.0253 % of a block.
```rust
id: TaskName
......@@ -162,7 +162,7 @@ original `total_retries`.
<details><summary><code>set_retry_named(id, retries, period)</code></summary>
Taking 0.0129 % of a block.
Taking 0.0127 % of a block.
```rust
id: TaskName
......@@ -203,7 +203,7 @@ Removes the retry configuration of a task.
<details><summary><code>cancel_retry_named(id)</code></summary>
Taking 0.0128 % of a block.
Taking 0.0127 % of a block.
```rust
id: TaskName
......@@ -334,7 +334,7 @@ The dispatch origin for this call is `root`.
<details><summary><code>force_adjust_total_issuance(direction, delta)</code></summary>
Taking 0.0039 % of a block.
Taking 0.0038 % of a block.
```rust
direction: AdjustmentDirection
......@@ -359,7 +359,7 @@ Taking 0.0113 % of a block.
```rust
dest: <T::Lookup as StaticLookup>::Source
value: <T::Currency as Currency<T::AccountId>>::Balance
value: BalanceOf<T>
```
</details>
......@@ -400,7 +400,7 @@ Taking 0.0269 % of a block.
block_height: BlockNumberFor<T>
dest: Account<<T::Lookup as StaticLookup>::Source>
remaining_to: Account<<T::Lookup as StaticLookup>::Source>
balance: <T::Currency as Currency<T::AccountId>>::Balance
balance: BalanceOf<T>
```
</details>
......@@ -422,7 +422,7 @@ and the remaining amount to another account.
<details><summary><code>invite_smith(receiver)</code></summary>
Taking 0.0239 % of a block.
Taking 0.0237 % of a block.
```rust
receiver: T::IdtyIndex
......@@ -449,7 +449,7 @@ Accept an invitation (must have been invited first)
<details><summary><code>certify_smith(receiver)</code></summary>
Taking 0.0287 % of a block.
Taking 0.0286 % of a block.
```rust
receiver: T::IdtyIndex
......@@ -465,7 +465,7 @@ Certify an invited smith which can lead the certified to become a Smith
<details><summary><code>go_offline()</code></summary>
Taking 0.0167 % of a block.
Taking 0.0165 % of a block.
```rust
```
......@@ -478,7 +478,7 @@ ask to leave the set of validators two sessions after
<details><summary><code>go_online()</code></summary>
Taking 0.0192 % of a block.
Taking 0.0188 % of a block.
```rust
```
......@@ -491,7 +491,7 @@ ask to join the set of validators two sessions after
<details><summary><code>set_session_keys(keys)</code></summary>
Taking 0.0254 % of a block.
Taking 0.0251 % of a block.
```rust
keys: T::Keys
......@@ -562,7 +562,7 @@ The weight of this call is defined by the caller.
<details><summary><code>note_preimage(bytes)</code></summary>
Taking 0.2893 % of a block.
Taking 0.2953 % of a block.
```rust
bytes: Vec<u8>
......@@ -598,7 +598,7 @@ If `len` is provided, then it will be a much cheaper operation.
<details><summary><code>request_preimage(hash)</code></summary>
Taking 0.0127 % of a block.
Taking 0.0126 % of a block.
```rust
hash: T::Hash
......@@ -615,7 +615,7 @@ a user may have paid, and take the control of the preimage out of their hands.
<details><summary><code>unrequest_preimage(hash)</code></summary>
Taking 0.0185 % of a block.
Taking 0.0186 % of a block.
```rust
hash: T::Hash
......@@ -631,7 +631,7 @@ NOTE: THIS MUST NOT BE CALLED ON `hash` MORE TIMES THAN `request_preimage`.
<details><summary><code>ensure_updated(hashes)</code></summary>
Taking 20.7987 % of a block.
Taking 21.073 % of a block.
```rust
hashes: Vec<T::Hash>
......@@ -649,7 +649,7 @@ The caller pays no fee if at least 90% of pre-images were successfully updated.
<details><summary><code>execute(proposal, length_bound)</code></summary>
Taking 0.0052 % of a block.
Taking 0.0051 % of a block.
```rust
proposal: Box<<T as Config<I>>::Proposal>
......@@ -701,7 +701,7 @@ or put up for voting.
<details><summary><code>vote(proposal, index, approve)</code></summary>
Taking 0.0125 % of a block.
Taking 0.0124 % of a block.
```rust
proposal: T::Hash
......@@ -767,7 +767,7 @@ proposal.
<details><summary><code>claim_uds()</code></summary>
Taking 0.022 % of a block.
Taking 0.0218 % of a block.
```rust
```
......@@ -812,7 +812,7 @@ Transfer some liquid free balance to another account, in milliUD.
<details><summary><code>create_identity(owner_key)</code></summary>
Taking 0.0906 % of a block.
Taking 0.0912 % of a block.
```rust
owner_key: T::AccountId
......@@ -830,7 +830,7 @@ The origin must be allowed to create an identity.
<details><summary><code>confirm_identity(idty_name)</code></summary>
Taking 0.0337 % of a block.
Taking 0.0338 % of a block.
```rust
idty_name: IdtyName
......@@ -848,7 +848,7 @@ The identity must have been created using `create_identity` before it can be con
<details><summary><code>change_owner_key(new_key, new_key_sig)</code></summary>
Taking 0.0429 % of a block.
Taking 0.0431 % of a block.
```rust
new_key: T::AccountId
......@@ -869,7 +869,7 @@ The origin should be the old identity owner key.
<details><summary><code>revoke_identity(idty_index, revocation_key, revocation_sig)</code></summary>
Taking 0.0413 % of a block.
Taking 0.0416 % of a block.
```rust
idty_index: T::IdtyIndex
......@@ -938,7 +938,7 @@ Add a new certification.
<details><summary><code>renew_cert(receiver)</code></summary>
Taking 0.03 % of a block.
Taking 0.0299 % of a block.
```rust
receiver: T::IdtyIndex
......@@ -952,7 +952,7 @@ Renew an existing certification.
<details><summary><code>del_cert(issuer, receiver)</code></summary>
Taking 0.0265 % of a block.
Taking 0.0263 % of a block.
```rust
issuer: T::IdtyIndex
......@@ -967,7 +967,7 @@ remove a certification (only root)
<details><summary><code>remove_all_certs_received_by(idty_index)</code></summary>
Taking 7.3619 % of a block.
Taking 7.395 % of a block.
```rust
idty_index: T::IdtyIndex
......@@ -983,7 +983,7 @@ remove all certifications received by an identity (only root)
<details><summary><code>request_distance_evaluation()</code></summary>
Taking 0.0327 % of a block.
Taking 0.0325 % of a block.
```rust
```
......@@ -998,7 +998,7 @@ negative evaluation will result in slash for caller
<details><summary><code>request_distance_evaluation_for(target)</code></summary>
Taking 0.0339 % of a block.
Taking 0.0336 % of a block.
```rust
target: T::IdtyIndex
......@@ -1013,7 +1013,7 @@ only possible for unvalidated identity
<details><summary><code>update_evaluation(computation_result)</code></summary>
Taking 0.0347 % of a block.
Taking 0.0346 % of a block.
```rust
computation_result: ComputationResult
......@@ -1028,7 +1028,7 @@ this is called internally by validators (= inherent)
<details><summary><code>force_update_evaluation(evaluator, computation_result)</code></summary>
Taking 0.0184 % of a block.
Taking 0.0183 % of a block.
```rust
evaluator: <T as frame_system::Config>::AccountId
......@@ -1130,7 +1130,7 @@ The dispatch origin for this call must be _Signed_.
<details><summary><code>as_multi_threshold_1(other_signatories, call)</code></summary>
Taking 0.0041 % of a block.
Taking 0.004 % of a block.
```rust
other_signatories: Vec<T::AccountId>
......@@ -1298,7 +1298,7 @@ transaction for this dispatch.
<details><summary><code>request(randomness_type, salt)</code></summary>
Taking 0.0418 % of a block.
Taking 0.042 % of a block.
```rust
randomness_type: RandomnessType
......@@ -1315,7 +1315,7 @@ Request a randomness
<details><summary><code>proxy(real, force_proxy_type, call)</code></summary>
Taking 0.0053 % of a block.
Taking 0.0052 % of a block.
```rust
real: AccountIdLookupOf<T>
......@@ -1498,7 +1498,7 @@ Parameters:
<details><summary><code>remove_announcement(real, call_hash)</code></summary>
Taking 0.0185 % of a block.
Taking 0.0186 % of a block.
```rust
real: AccountIdLookupOf<T>
......@@ -1522,7 +1522,7 @@ Parameters:
<details><summary><code>reject_announcement(delegate, call_hash)</code></summary>
Taking 0.0185 % of a block.
Taking 0.0186 % of a block.
```rust
delegate: AccountIdLookupOf<T>
......@@ -1575,7 +1575,7 @@ Parameters:
<details><summary><code>batch(calls)</code></summary>
Taking 0.1077 % of a block.
Taking 0.1039 % of a block.
```rust
calls: Vec<<T as Config>::RuntimeCall>
......@@ -1606,7 +1606,7 @@ event is deposited.
<details><summary><code>as_derivative(index, call)</code></summary>
Taking 0.0038 % of a block.
Taking 0.0037 % of a block.
```rust
index: u16
......@@ -1633,7 +1633,7 @@ The dispatch origin for this call must be _Signed_.
<details><summary><code>batch_all(calls)</code></summary>
Taking 0.1127 % of a block.
Taking 0.1131 % of a block.
```rust
calls: Vec<<T as Config>::RuntimeCall>
......@@ -1659,7 +1659,7 @@ includes bypassing `frame_system::Config::BaseCallFilter`).
<details><summary><code>force_batch(calls)</code></summary>
Taking 0.1071 % of a block.
Taking 0.104 % of a block.
```rust
calls: Vec<<T as Config>::RuntimeCall>
......@@ -1707,7 +1707,7 @@ The dispatch origin for this call must be _Root_.
<details><summary><code>propose_spend(value, beneficiary)</code></summary>
Taking 0.0172 % of a block.
Taking 0.0174 % of a block.
```rust
value: BalanceOf<T, I>
......@@ -1737,7 +1737,7 @@ Emits [`Event::Proposed`] if successful.
<details><summary><code>spend_local(amount, beneficiary)</code></summary>
Taking 0.0036 % of a block.
Taking 0.0035 % of a block.
```rust
amount: BalanceOf<T, I>
......@@ -1768,7 +1768,7 @@ Emits [`Event::SpendApproved`] if successful.
<details><summary><code>remove_approval(proposal_id)</code></summary>
Taking 0.0108 % of a block.
Taking 0.0107 % of a block.
```rust
proposal_id: ProposalIndex
......@@ -1802,7 +1802,7 @@ The original deposit will no longer be returned.
<details><summary><code>spend(asset_kind, amount, beneficiary, valid_from)</code></summary>
Taking 0.0036 % of a block.
Taking 0.0035 % of a block.
```rust
asset_kind: Box<T::AssetKind>
......@@ -1844,7 +1844,7 @@ Emits [`Event::AssetSpendApproved`] if successful.
<details><summary><code>payout(index)</code></summary>
Taking 0.0263 % of a block.
Taking 0.0265 % of a block.
```rust
index: SpendIndex
......@@ -1945,7 +1945,7 @@ There are **18** root calls from **8** pallets.
<details><summary><code>set_heap_pages(pages)</code></summary>
Taking 0.0165 % of a block.
Taking 0.0166 % of a block.
```rust
pages: u64
......@@ -1959,7 +1959,7 @@ Set the number of pages in the WebAssembly environment's heap.
<details><summary><code>set_code(code)</code></summary>
Taking 4.0113 % of a block.
Taking 3.2097 % of a block.
```rust
code: Vec<u8>
......@@ -1990,7 +1990,7 @@ version!
<details><summary><code>set_storage(items)</code></summary>
Taking 5.8851 % of a block.
Taking 6.0054 % of a block.
```rust
items: Vec<KeyValue>
......@@ -2004,7 +2004,7 @@ Set some items of storage.
<details><summary><code>kill_storage(keys)</code></summary>
Taking 5.8773 % of a block.
Taking 5.9992 % of a block.
```rust
keys: Vec<Key>
......@@ -2018,7 +2018,7 @@ Kill some items from storage.
<details><summary><code>kill_prefix(prefix, subkeys)</code></summary>
Taking 6.9458 % of a block.
Taking 7.0112 % of a block.
```rust
prefix: Key
......@@ -2036,7 +2036,7 @@ the prefix we are removing to accurately calculate the weight of this function.
<details><summary><code>authorize_upgrade(code_hash)</code></summary>
Taking 0.0101 % of a block.
Taking 0.01 % of a block.
```rust
code_hash: T::Hash
......@@ -2074,7 +2074,7 @@ This call requires Root origin.
<details><summary><code>apply_authorized_upgrade(code)</code></summary>
Taking 4.2016 % of a block.
Taking 3.461 % of a block.
```rust
code: Vec<u8>
......@@ -2117,7 +2117,7 @@ not been enacted yet.
<details><summary><code>force_transfer(source, dest, value)</code></summary>
Taking 0.0265 % of a block.
Taking 0.0266 % of a block.
```rust
source: AccountIdLookupOf<T>
......@@ -2134,7 +2134,7 @@ may be specified.
<details><summary><code>force_unreserve(who, amount)</code></summary>
Taking 0.0112 % of a block.
Taking 0.0111 % of a block.
```rust
who: AccountIdLookupOf<T>
......@@ -2153,7 +2153,7 @@ Can only be called by ROOT.
<details><summary><code>remove_member(member_id)</code></summary>
Taking 0.0701 % of a block.
Taking 0.0709 % of a block.
```rust
member_id: T::MemberId
......@@ -2197,7 +2197,7 @@ Only callable by root.
<details><summary><code>set_members(new_members, prime, old_count)</code></summary>
Taking 0.1657 % of a block.
Taking 0.1668 % of a block.
```rust
new_members: Vec<T::AccountId>
......@@ -2236,7 +2236,7 @@ with other logic managing the member set.
<details><summary><code>disapprove_proposal(proposal_hash)</code></summary>
Taking 0.0229 % of a block.
Taking 0.0231 % of a block.
```rust
proposal_hash: T::Hash
......@@ -2261,7 +2261,7 @@ O(P) where P is the number of max proposals
<details><summary><code>prune_item_identities_names(names)</code></summary>
Taking 5.9211 % of a block.
Taking 6.0421 % of a block.
```rust
names: Vec<IdtyName>
......@@ -2277,7 +2277,7 @@ remove identity names from storage
<details><summary><code>dispatch_as(as_origin, call)</code></summary>
Taking 0.0039 % of a block.
Taking 0.0038 % of a block.
```rust
as_origin: Box<T::PalletsOrigin>
......@@ -2324,7 +2324,7 @@ Can be executed by every `origin`.
<details><summary><code>remark_with_event(remark)</code></summary>
Taking 0.2052 % of a block.
Taking 0.2151 % of a block.
```rust
remark: Vec<u8>
......@@ -2340,7 +2340,7 @@ Make some on-chain remark and emit event.
<details><summary><code>set_keys(keys, proof)</code></summary>
Taking 0.0394 % of a block.
Taking 0.0395 % of a block.
```rust
keys: T::Keys
......@@ -2363,7 +2363,7 @@ The dispatch origin of this function must be signed.
<details><summary><code>purge_keys()</code></summary>
Taking 0.0347 % of a block.
Taking 0.0351 % of a block.
```rust
```
......
......@@ -581,7 +581,7 @@ A oneshot account was created.
```rust
account: T::AccountId
balance: <T::Currency as Currency<T::AccountId>>::Balance
balance: BalanceOf<T>
creator: T::AccountId
```
......@@ -595,10 +595,8 @@ A oneshot account was consumed.
```rust
account: T::AccountId
dest1: (T::AccountId,<T::Currency as Currency<T::AccountId>>::Balance,)
dest2: Option<
(T::AccountId,<T::Currency as Currency<T::AccountId>>::Balance,)
>
dest1: (T::AccountId, BalanceOf<T>)
dest2: Option<(T::AccountId, BalanceOf<T>)>
```
</details>
......@@ -611,7 +609,7 @@ A withdrawal was executed on a oneshot account.
```rust
account: T::AccountId
balance: <T::Currency as Currency<T::AccountId>>::Balance
balance: BalanceOf<T>
```
</details>
......
......@@ -21,13 +21,9 @@ use super::*;
use codec::Encode;
use frame_benchmarking::v2::*;
use frame_support::traits::Get;
use frame_support::traits::OnInitialize;
use frame_support::traits::{Currency, OnFinalize};
use frame_support::traits::{Get, OnFinalize, OnInitialize};
use frame_system::pallet_prelude::BlockNumberFor;
use frame_system::RawOrigin;
use pallet_balances::Pallet as Balances;
use sp_runtime::traits::Bounded;
use sp_runtime::Perbill;
use crate::Pallet;
......@@ -35,7 +31,7 @@ use crate::Pallet;
#[benchmarks(
where
T: pallet_balances::Config,
T::Balance: From<u64>,
BalanceOf<T>: From<u32>,
BlockNumberFor<T>: From<u32>,
)]
mod benchmarks {
......@@ -63,8 +59,7 @@ mod benchmarks {
let caller: T::AccountId = pallet_identity::Identities::<T>::get(idty)
.unwrap()
.owner_key;
let _ =
<Balances<T> as Currency<_>>::make_free_balance_be(&caller, T::Balance::max_value());
let _ = T::Currency::set_balance(&caller, u32::MAX.into());
#[extrinsic_call]
_(RawOrigin::Signed(caller.clone()));
......@@ -88,7 +83,7 @@ mod benchmarks {
let caller: T::AccountId = pallet_identity::Identities::<T>::get(idty)
.unwrap()
.owner_key;
<Balances<T> as Currency<_>>::make_free_balance_be(&caller, T::Balance::max_value());
T::Currency::set_balance(&caller, u32::MAX.into());
let target: T::IdtyIndex = 2u32;
// set target status since targeted distance evaluation only allowed for unvalidated
pallet_identity::Identities::<T>::mutate(target, |idty_val| {
......@@ -193,8 +188,7 @@ mod benchmarks {
let caller: T::AccountId = pallet_identity::Identities::<T>::get(idty)
.unwrap()
.owner_key;
let _ =
<Balances<T> as Currency<_>>::make_free_balance_be(&caller, T::Balance::max_value());
let _ = T::Currency::set_balance(&caller, u32::MAX.into());
Pallet::<T>::request_distance_evaluation(RawOrigin::Signed(caller.clone()).into())?;
assert_has_event::<T>(
Event::<T>::EvaluationRequested {
......@@ -237,8 +231,7 @@ mod benchmarks {
let caller: T::AccountId = pallet_identity::Identities::<T>::get(idty)
.unwrap()
.owner_key;
let _ =
<Balances<T> as Currency<_>>::make_free_balance_be(&caller, T::Balance::max_value());
let _ = T::Currency::set_balance(&caller, u32::MAX.into());
Pallet::<T>::request_distance_evaluation(RawOrigin::Signed(caller.clone()).into())?;
assert_has_event::<T>(
Event::<T>::EvaluationRequested {
......
......@@ -34,14 +34,16 @@ pub use traits::*;
pub use types::*;
pub use weights::WeightInfo;
use frame_support::traits::StorageVersion;
use frame_support::traits::{
fungible::{self, hold::Balanced, Mutate, MutateHold},
tokens::Precision,
StorageVersion,
};
use sp_distance::{InherentError, INHERENT_IDENTIFIER};
use sp_inherents::{InherentData, InherentIdentifier};
use sp_runtime::traits::One;
use sp_runtime::traits::Zero;
use sp_runtime::traits::{One, Zero};
use sp_runtime::Saturating;
use sp_std::convert::TryInto;
use sp_std::prelude::*;
use sp_std::{convert::TryInto, prelude::*};
type IdtyIndex = u32;
......@@ -53,9 +55,17 @@ pub const MAX_EVALUATORS_PER_SESSION: u32 = 100;
#[frame_support::pallet()]
pub mod pallet {
use super::*;
use frame_support::{pallet_prelude::*, traits::ReservableCurrency};
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
use sp_runtime::Perbill;
pub type AccountIdOf<T> = <T as frame_system::Config>::AccountId;
pub type BalanceOf<T> = <<T as Config>::Currency as fungible::Inspect<AccountIdOf<T>>>::Balance;
#[pallet::composite_enum]
pub enum HoldReason {
/// The funds are held as deposit for the distance evaluation.
DistanceHold,
}
/// The current storage version.
const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);
......@@ -71,12 +81,14 @@ pub mod pallet {
+ pallet_identity::Config<IdtyIndex = IdtyIndex>
{
/// Currency type used in this pallet (used for reserve/slash)
type Currency: ReservableCurrency<Self::AccountId>;
type Currency: Mutate<Self::AccountId>
+ MutateHold<Self::AccountId, Reason = Self::RuntimeHoldReason>
+ Balanced<Self::AccountId>;
/// Overarching hold reason.
type RuntimeHoldReason: From<HoldReason>;
/// Amount reserved during evaluation
#[pallet::constant]
type EvaluationPrice: Get<
<Self::Currency as frame_support::traits::Currency<Self::AccountId>>::Balance,
>;
type EvaluationPrice: Get<BalanceOf<Self>>;
/// Evaluation period number of blocks.
/// As the evaluation is done using 3 pools,
/// the evaluation will take 3 * EvaluationPeriod.
......@@ -463,7 +475,11 @@ pub mod pallet {
Error::<T>::QueueFull
);
T::Currency::reserve(who, <T as Config>::EvaluationPrice::get())?;
T::Currency::hold(
&HoldReason::DistanceHold.into(),
who,
<T as Config>::EvaluationPrice::get(),
)?;
current_pool
.evaluations
......@@ -559,9 +575,11 @@ pub mod pallet {
if let Some(distance) = distance_result {
if distance >= T::MinAccessibleReferees::get() {
// Positive result, unreserve and apply
T::Currency::unreserve(
let _ = T::Currency::release(
&HoldReason::DistanceHold.into(),
&requester,
<T as Config>::EvaluationPrice::get(),
Precision::Exact,
);
Self::do_valid_distance_status(idty, distance);
weight = weight.saturating_add(
......@@ -572,7 +590,8 @@ pub mod pallet {
);
} else {
// Negative result, slash and deposit event
let _ = T::Currency::slash_reserved(
let _ = T::Currency::slash(
&HoldReason::DistanceHold.into(),
&requester,
<T as Config>::EvaluationPrice::get(),
);
......@@ -589,7 +608,12 @@ pub mod pallet {
}
} else {
// No result, unreserve
T::Currency::unreserve(&requester, <T as Config>::EvaluationPrice::get());
let _ = T::Currency::release(
&HoldReason::DistanceHold.into(),
&requester,
<T as Config>::EvaluationPrice::get(),
Precision::Exact,
);
weight = weight.saturating_add(
<T as pallet::Config>::WeightInfo::do_evaluation_failure()
.saturating_sub(
......
......@@ -210,7 +210,7 @@ impl pallet_balances::Config for Test {
type ReserveIdentifier = [u8; 8];
type RuntimeEvent = RuntimeEvent;
type RuntimeFreezeReason = ();
type RuntimeHoldReason = ();
type RuntimeHoldReason = RuntimeHoldReason;
type WeightInfo = pallet_balances::weights::SubstrateWeight<Test>;
}
......@@ -262,6 +262,7 @@ impl pallet_distance::Config for Test {
type MinAccessibleReferees = MinAccessibleReferees;
type OnValidDistanceStatus = ();
type RuntimeEvent = RuntimeEvent;
type RuntimeHoldReason = RuntimeHoldReason;
type WeightInfo = ();
}
......
......@@ -29,8 +29,7 @@ pub use types::*;
pub use weights::WeightInfo;
use frame_support::pallet_prelude::*;
use frame_support::traits::StoredMap;
use frame_support::traits::{Currency, StorageVersion};
use frame_support::traits::{fungible, fungible::Credit, IsSubType, StorageVersion, StoredMap};
use frame_system::pallet_prelude::*;
use pallet_quota::traits::RefundFee;
use pallet_transaction_payment::OnChargeTransaction;
......@@ -42,8 +41,8 @@ pub mod pallet {
use super::*;
pub type IdtyIdOf<T> = <T as pallet_identity::Config>::IdtyIndex;
pub type CurrencyOf<T> = pallet_balances::Pallet<T>;
pub type BalanceOf<T> =
<CurrencyOf<T> as Currency<<T as frame_system::Config>::AccountId>>::Balance;
type AccountIdOf<T> = <T as frame_system::Config>::AccountId;
pub type BalanceOf<T> = <CurrencyOf<T> as fungible::Inspect<AccountIdOf<T>>>::Balance;
/// The current storage version.
const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);
......@@ -290,14 +289,15 @@ where
// allows pay fees with quota instead of currency if available
impl<T: Config> OnChargeTransaction<T> for Pallet<T>
where
T::RuntimeCall: IsSubType<Call<T>>,
T::InnerOnChargeTransaction: OnChargeTransaction<
T,
Balance = <CurrencyOf<T> as Currency<T::AccountId>>::Balance,
LiquidityInfo = Option<<CurrencyOf<T> as Currency<T::AccountId>>::NegativeImbalance>,
Balance = BalanceOf<T>,
LiquidityInfo = Option<Credit<T::AccountId, T::Currency>>,
>,
{
type Balance = BalanceOf<T>;
type LiquidityInfo = Option<<CurrencyOf<T> as Currency<T::AccountId>>::NegativeImbalance>;
type LiquidityInfo = Option<Credit<T::AccountId, T::Currency>>;
fn withdraw_fee(
who: &T::AccountId,
......
......@@ -22,16 +22,19 @@ use super::*;
use frame_benchmarking::v2::*;
use frame_benchmarking::{account, whitelisted_caller};
use frame_support::pallet_prelude::IsType;
use frame_support::traits::fungible::Mutate;
use frame_system::RawOrigin;
use pallet_balances::Pallet as Balances;
use crate::Pallet;
type BalanceOf<T> = <<T as Config>::Currency as fungible::Inspect<AccountIdOf<T>>>::Balance;
#[benchmarks(
where
T: pallet_balances::Config,
T::Balance: From<u64>,
<T::Currency as Currency<T::AccountId>>::Balance: IsType<T::Balance>+From<T::Balance>
BalanceOf<T>: IsType<T::Balance>+From<T::Balance>
)]
mod benchmarks {
use super::*;
......@@ -41,7 +44,10 @@ mod benchmarks {
let existential_deposit = T::ExistentialDeposit::get();
let caller = whitelisted_caller();
let balance = existential_deposit.saturating_mul((2).into());
let _ = T::Currency::make_free_balance_be(&caller, balance.into());
let _ = <<T as pallet::Config>::Currency as Mutate<T::AccountId>>::set_balance(
&caller,
balance.into(),
);
let recipient: T::AccountId = account("recipient", 0, 1);
let recipient_lookup: <T::Lookup as StaticLookup>::Source =
T::Lookup::unlookup(recipient.clone());
......@@ -66,16 +72,16 @@ mod benchmarks {
let existential_deposit = T::ExistentialDeposit::get();
let caller: T::AccountId = whitelisted_caller();
let balance = existential_deposit.saturating_mul((2).into());
OneshotAccounts::<T>::insert(
caller.clone(),
Into::<<T::Currency as Currency<T::AccountId>>::Balance>::into(balance),
);
OneshotAccounts::<T>::insert(caller.clone(), Into::<BalanceOf<T>>::into(balance));
// Deposit into a normal account is more expensive than into a oneshot account
// so we create the recipient account with an existential deposit.
let recipient: T::AccountId = account("recipient", 0, 1);
let recipient_lookup: <T::Lookup as StaticLookup>::Source =
T::Lookup::unlookup(recipient.clone());
let _ = T::Currency::make_free_balance_be(&recipient, existential_deposit.into());
let _ = <<T as pallet::Config>::Currency as Mutate<T::AccountId>>::set_balance(
&recipient,
existential_deposit.into(),
);
#[extrinsic_call]
_(
......@@ -96,20 +102,23 @@ mod benchmarks {
let existential_deposit = T::ExistentialDeposit::get();
let caller: T::AccountId = whitelisted_caller();
let balance = existential_deposit.saturating_mul((2).into());
OneshotAccounts::<T>::insert(
caller.clone(),
Into::<<T::Currency as Currency<T::AccountId>>::Balance>::into(balance),
);
OneshotAccounts::<T>::insert(caller.clone(), Into::<BalanceOf<T>>::into(balance));
// Deposit into a normal account is more expensive than into a oneshot account
// so we create the recipient accounts with an existential deposits.
let recipient1: T::AccountId = account("recipient1", 0, 1);
let recipient1_lookup: <T::Lookup as StaticLookup>::Source =
T::Lookup::unlookup(recipient1.clone());
let _ = T::Currency::make_free_balance_be(&recipient1, existential_deposit.into());
let _ = <<T as pallet::Config>::Currency as Mutate<T::AccountId>>::set_balance(
&recipient1,
existential_deposit.into(),
);
let recipient2: T::AccountId = account("recipient2", 1, 1);
let recipient2_lookup: <T::Lookup as StaticLookup>::Source =
T::Lookup::unlookup(recipient2.clone());
let _ = T::Currency::make_free_balance_be(&recipient2, existential_deposit.into());
let _ = <<T as pallet::Config>::Currency as Mutate<T::AccountId>>::set_balance(
&recipient2,
existential_deposit.into(),
);
#[extrinsic_call]
_(
......
......@@ -29,14 +29,20 @@ pub use types::*;
pub use weights::WeightInfo;
use frame_support::pallet_prelude::*;
use frame_support::traits::fungible;
use frame_support::traits::{
Currency, ExistenceRequirement, Imbalance, IsSubType, WithdrawReasons,
fungible::{Balanced, Credit, Inspect},
tokens::{Fortitude, Precision, Preservation},
Imbalance, IsSubType,
};
use frame_system::pallet_prelude::*;
use pallet_transaction_payment::OnChargeTransaction;
use sp_runtime::traits::{DispatchInfoOf, PostDispatchInfoOf, Saturating, StaticLookup, Zero};
use sp_std::convert::TryInto;
type AccountIdOf<T> = <T as frame_system::Config>::AccountId;
type BalanceOf<T> = <<T as Config>::Currency as fungible::Inspect<AccountIdOf<T>>>::Balance;
#[frame_support::pallet]
pub mod pallet {
use super::*;
......@@ -49,7 +55,7 @@ pub mod pallet {
#[pallet::config]
pub trait Config: frame_system::Config + pallet_transaction_payment::Config {
type Currency: Currency<Self::AccountId>;
type Currency: fungible::Balanced<Self::AccountId> + fungible::Mutate<Self::AccountId>;
type InnerOnChargeTransaction: OnChargeTransaction<Self>;
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
/// Type representing the weight of this pallet
......@@ -60,13 +66,8 @@ pub mod pallet {
#[pallet::storage]
#[pallet::getter(fn oneshot_account)]
pub type OneshotAccounts<T: Config> = StorageMap<
_,
Blake2_128Concat,
T::AccountId,
<T::Currency as Currency<T::AccountId>>::Balance,
OptionQuery,
>;
pub type OneshotAccounts<T: Config> =
StorageMap<_, Blake2_128Concat, T::AccountId, BalanceOf<T>, OptionQuery>;
// EVENTS //
......@@ -77,25 +78,19 @@ pub mod pallet {
/// A oneshot account was created.
OneshotAccountCreated {
account: T::AccountId,
balance: <T::Currency as Currency<T::AccountId>>::Balance,
balance: BalanceOf<T>,
creator: T::AccountId,
},
/// A oneshot account was consumed.
OneshotAccountConsumed {
account: T::AccountId,
dest1: (
T::AccountId,
<T::Currency as Currency<T::AccountId>>::Balance,
),
dest2: Option<(
T::AccountId,
<T::Currency as Currency<T::AccountId>>::Balance,
)>,
dest1: (T::AccountId, BalanceOf<T>),
dest2: Option<(T::AccountId, BalanceOf<T>)>,
},
/// A withdrawal was executed on a oneshot account.
Withdraw {
account: T::AccountId,
balance: <T::Currency as Currency<T::AccountId>>::Balance,
balance: BalanceOf<T>,
},
}
......@@ -133,13 +128,13 @@ pub mod pallet {
pub fn create_oneshot_account(
origin: OriginFor<T>,
dest: <T::Lookup as StaticLookup>::Source,
#[pallet::compact] value: <T::Currency as Currency<T::AccountId>>::Balance,
#[pallet::compact] value: BalanceOf<T>,
) -> DispatchResult {
let transactor = ensure_signed(origin)?;
let dest = T::Lookup::lookup(dest)?;
ensure!(
value >= <T::Currency as Currency<T::AccountId>>::minimum_balance(),
value >= T::Currency::minimum_balance(),
Error::<T>::ExistentialDeposit
);
ensure!(
......@@ -147,11 +142,12 @@ pub mod pallet {
Error::<T>::OneshotAccountAlreadyCreated
);
let _ = <T::Currency as Currency<T::AccountId>>::withdraw(
let _ = T::Currency::withdraw(
&transactor,
value,
WithdrawReasons::TRANSFER,
ExistenceRequirement::KeepAlive,
Precision::Exact,
Preservation::Preserve,
Fortitude::Polite,
)?;
OneshotAccounts::<T>::insert(&dest, value);
Self::deposit_event(Event::OneshotAccountCreated {
......@@ -205,9 +201,8 @@ pub mod pallet {
balance: value,
creator: transactor.clone(),
});
} else {
let _ =
<T::Currency as Currency<T::AccountId>>::deposit_into_existing(&dest, value)?;
} else if frame_system::Pallet::<T>::providers(&dest) > 0 {
let _ = T::Currency::deposit(&dest, value, Precision::Exact)?;
}
OneshotAccounts::<T>::remove(&transactor);
Self::deposit_event(Event::OneshotAccountConsumed {
......@@ -236,7 +231,7 @@ pub mod pallet {
block_height: BlockNumberFor<T>,
dest: Account<<T::Lookup as StaticLookup>::Source>,
remaining_to: Account<<T::Lookup as StaticLookup>::Source>,
#[pallet::compact] balance: <T::Currency as Currency<T::AccountId>>::Balance,
#[pallet::compact] balance: BalanceOf<T>,
) -> DispatchResult {
let transactor = ensure_signed(origin)?;
......@@ -271,12 +266,12 @@ pub mod pallet {
Error::<T>::OneshotAccountAlreadyCreated
);
ensure!(
balance1 >= <T::Currency as Currency<T::AccountId>>::minimum_balance(),
balance1 >= T::Currency::minimum_balance(),
Error::<T>::ExistentialDeposit
);
} else {
ensure!(
!<T::Currency as Currency<T::AccountId>>::free_balance(&dest1).is_zero(),
!T::Currency::balance(&dest1).is_zero(),
Error::<T>::DestAccountNotExist
);
}
......@@ -286,7 +281,7 @@ pub mod pallet {
Error::<T>::OneshotAccountAlreadyCreated
);
ensure!(
balance2 >= <T::Currency as Currency<T::AccountId>>::minimum_balance(),
balance2 >= T::Currency::minimum_balance(),
Error::<T>::ExistentialDeposit
);
OneshotAccounts::<T>::insert(&dest2, balance2);
......@@ -295,10 +290,8 @@ pub mod pallet {
balance: balance2,
creator: transactor.clone(),
});
} else {
let _ = <T::Currency as Currency<T::AccountId>>::deposit_into_existing(
&dest2, balance2,
)?;
} else if frame_system::Pallet::<T>::providers(&dest2) > 0 {
let _ = T::Currency::deposit(&dest2, balance2, Precision::Exact)?;
}
if dest1_is_oneshot {
OneshotAccounts::<T>::insert(&dest1, balance1);
......@@ -307,10 +300,8 @@ pub mod pallet {
balance: balance1,
creator: transactor.clone(),
});
} else {
let _ = <T::Currency as Currency<T::AccountId>>::deposit_into_existing(
&dest1, balance1,
)?;
} else if frame_system::Pallet::<T>::providers(&dest1) > 0 {
let _ = T::Currency::deposit(&dest1, balance1, Precision::Exact)?;
}
OneshotAccounts::<T>::remove(&transactor);
Self::deposit_event(Event::OneshotAccountConsumed {
......@@ -329,12 +320,12 @@ where
T::RuntimeCall: IsSubType<Call<T>>,
T::InnerOnChargeTransaction: OnChargeTransaction<
T,
Balance = <T::Currency as Currency<T::AccountId>>::Balance,
LiquidityInfo = Option<<T::Currency as Currency<T::AccountId>>::NegativeImbalance>,
Balance = BalanceOf<T>,
LiquidityInfo = Option<Credit<T::AccountId, T::Currency>>,
>,
{
type Balance = <T::Currency as Currency<T::AccountId>>::Balance;
type LiquidityInfo = Option<<T::Currency as Currency<T::AccountId>>::NegativeImbalance>;
type Balance = BalanceOf<T>;
type LiquidityInfo = Option<Credit<T::AccountId, T::Currency>>;
fn withdraw_fee(
who: &T::AccountId,
......@@ -359,10 +350,7 @@ where
account: who.clone(),
balance: fee,
});
// TODO
return Ok(Some(
<T::Currency as Currency<T::AccountId>>::NegativeImbalance::zero(),
));
return Ok(Some(Imbalance::zero()));
}
}
Err(TransactionValidityError::Invalid(
......
......@@ -14,12 +14,10 @@
// You should have received a copy of the GNU Affero General Public License
// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>.
#![allow(deprecated)] // TODO
use crate::{self as pallet_oneshot_account};
use frame_support::{parameter_types, traits::Everything, weights::IdentityFee};
use frame_system as system;
use pallet_transaction_payment::CurrencyAdapter;
use pallet_transaction_payment::FungibleAdapter;
use sp_core::{ConstU32, H256};
use sp_runtime::{
traits::{BlakeTwo256, IdentityLookup},
......@@ -107,16 +105,15 @@ impl pallet_transaction_payment::Config for Test {
}
impl pallet_oneshot_account::Config for Test {
type Currency = Balances;
type InnerOnChargeTransaction = CurrencyAdapter<Balances, HandleFees>;
type InnerOnChargeTransaction = FungibleAdapter<Balances, HandleFees>;
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
}
pub struct HandleFees;
type NegativeImbalance = <Balances as frame_support::traits::Currency<u64>>::NegativeImbalance;
impl frame_support::traits::OnUnbalanced<NegativeImbalance> for HandleFees {
fn on_nonzero_unbalanced(_amount: NegativeImbalance) {}
}
type Imbalance =
frame_support::traits::fungible::Credit<<Test as frame_system::Config>::AccountId, Balances>;
impl frame_support::traits::OnUnbalanced<Imbalance> for HandleFees {}
// Build genesis storage according to the mock runtime.
#[allow(dead_code)]
......
......@@ -19,14 +19,14 @@
use super::*;
use frame_benchmarking::v2::*;
use frame_benchmarking::whitelisted_caller;
use frame_support::ensure;
use frame_support::pallet_prelude::IsType;
use frame_support::sp_runtime::{traits::One, Saturating};
use frame_support::traits::{Currency, Get, OnInitialize};
use frame_system::pallet_prelude::BlockNumberFor;
use frame_system::RawOrigin;
use frame_benchmarking::{v2::*, whitelisted_caller};
use frame_support::{
ensure,
pallet_prelude::IsType,
sp_runtime::{traits::One, Saturating},
traits::{fungible::Mutate, Get, OnInitialize},
};
use frame_system::{pallet_prelude::BlockNumberFor, RawOrigin};
use sp_core::H256;
use crate::Pallet;
......@@ -35,7 +35,7 @@ use crate::Pallet;
where
T: pallet_balances::Config,
T::Balance: From<u64>,
<T::Currency as Currency<T::AccountId>>::Balance: IsType<T::Balance>,
BalanceOf<T>: IsType<T::Balance>,
BlockNumberFor<T>: From<u32>,
)]
mod benchmarks {
......@@ -80,7 +80,7 @@ mod benchmarks {
// Provide deposit
let existential_deposit = T::ExistentialDeposit::get();
let balance = existential_deposit.saturating_mul((200).into());
let _ = T::Currency::make_free_balance_be(&caller, balance.into());
let _ = T::Currency::set_balance(&caller, balance.into());
// Set randomness parameters
let random = RandomnessType::RandomnessFromOneEpochAgo;
......
......@@ -24,6 +24,10 @@ mod types;
pub mod weights;
use frame_support::pallet_prelude::Weight;
use frame_support::traits::{
fungible::{self, Balanced, Credit},
tokens::{Fortitude, Precision, Preservation},
};
use sp_core::H256;
use sp_std::prelude::*;
......@@ -46,17 +50,12 @@ impl OnFilledRandomness for () {
pub mod pallet {
use super::*;
use frame_support::pallet_prelude::*;
use frame_support::traits::{
Currency, ExistenceRequirement, OnUnbalanced, Randomness, StorageVersion, WithdrawReasons,
};
use frame_support::traits::{OnUnbalanced, Randomness, StorageVersion};
use frame_system::pallet_prelude::*;
use sp_core::H256;
pub type BalanceOf<T> =
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
pub type NegativeImbalanceOf<T> = <<T as Config>::Currency as Currency<
<T as frame_system::Config>::AccountId,
>>::NegativeImbalance;
type AccountIdOf<T> = <T as frame_system::Config>::AccountId;
pub type BalanceOf<T> = <<T as Config>::Currency as fungible::Inspect<AccountIdOf<T>>>::Balance;
/// The current storage version.
const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);
......@@ -70,7 +69,7 @@ pub mod pallet {
#[pallet::config]
pub trait Config: frame_system::Config<Hash = H256> {
// The currency
type Currency: Currency<Self::AccountId>;
type Currency: fungible::Balanced<Self::AccountId> + fungible::Mutate<Self::AccountId>;
/// Get the current epoch index
type GetCurrentEpochIndex: Get<u64>;
/// Maximum number of not yet filled requests
......@@ -82,7 +81,7 @@ pub mod pallet {
/// On filled randomness
type OnFilledRandomness: OnFilledRandomness;
/// Handler for the unbalanced reduction when the requestor pays fees.
type OnUnbalanced: OnUnbalanced<NegativeImbalanceOf<Self>>;
type OnUnbalanced: OnUnbalanced<Credit<Self::AccountId, Self::Currency>>;
/// A safe source of randomness from the parent block
type ParentBlockRandomness: Randomness<Option<H256>, BlockNumberFor<Self>>;
/// A safe source of randomness from one epoch ago
......@@ -251,8 +250,9 @@ pub mod pallet {
let imbalance = T::Currency::withdraw(
requestor,
T::RequestPrice::get(),
WithdrawReasons::FEE,
ExistenceRequirement::KeepAlive,
Precision::Exact,
Preservation::Preserve,
Fortitude::Polite,
)?;
T::OnUnbalanced::on_unbalanced(imbalance);
Ok(())
......
......@@ -18,15 +18,11 @@
#![allow(clippy::multiple_bound_locations)]
use super::*;
use core::num::NonZeroU16;
use frame_benchmarking::v2::*;
use frame_benchmarking::{account, whitelisted_caller};
use frame_support::pallet_prelude::IsType;
use frame_support::traits::StoredMap;
use frame_benchmarking::{account, v2::*, whitelisted_caller};
use frame_support::{pallet_prelude::IsType, traits::StoredMap};
use frame_system::RawOrigin;
use pallet_balances::Pallet as Balances;
use sp_runtime::traits::Bounded;
use crate::Pallet;
......@@ -35,7 +31,7 @@ const ED_MULTIPLIER: u32 = 10;
#[benchmarks(
where
T: pallet_balances::Config, T::Balance: From<u64>,
<T::Currency as Currency<T::AccountId>>::Balance: IsType<T::Balance>
BalanceOf<T>: IsType<T::Balance>
)]
mod benchmarks {
use super::*;
......@@ -82,7 +78,7 @@ mod benchmarks {
let existential_deposit = T::ExistentialDeposit::get();
let caller = whitelisted_caller();
let balance = existential_deposit.saturating_mul(ED_MULTIPLIER.into());
let _ = T::Currency::make_free_balance_be(&caller, balance.into());
let _ = T::Currency::set_balance(&caller, balance.into());
// Transfer `e - 1` existential deposits + 1 unit, which guarantees to create one account and reap this user.
let recipient: T::AccountId = account("recipient", 0, 1);
let recipient_lookup: <T::Lookup as StaticLookup>::Source =
......@@ -112,10 +108,7 @@ mod benchmarks {
let recipient_lookup: <T::Lookup as StaticLookup>::Source =
T::Lookup::unlookup(recipient.clone());
// Give the sender account max funds, thus a transfer will not kill account.
let _ = T::Currency::make_free_balance_be(
&caller,
<T::Currency as Currency<T::AccountId>>::Balance::max_value(),
);
let _ = T::Currency::set_balance(&caller, u32::MAX.into());
let existential_deposit = T::ExistentialDeposit::get();
let transfer_amount = existential_deposit.saturating_mul(ED_MULTIPLIER.into());
let transfer_amount_ud =
......
......@@ -33,7 +33,11 @@ pub use pallet::*;
pub use types::*;
pub use weights::WeightInfo;
use frame_support::traits::{tokens::ExistenceRequirement, Currency, OnTimestampSet};
use frame_support::traits::tokens::{Precision, Preservation};
use frame_support::traits::{
fungible::{self, Balanced, Mutate},
OnTimestampSet,
};
use sp_arithmetic::{
per_things::Perbill,
traits::{One, Saturating, Zero},
......@@ -48,8 +52,8 @@ pub mod pallet {
use frame_system::pallet_prelude::*;
use sp_runtime::traits::Convert;
pub type BalanceOf<T> =
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
type AccountIdOf<T> = <T as frame_system::Config>::AccountId;
pub type BalanceOf<T> = <<T as Config>::Currency as fungible::Inspect<AccountIdOf<T>>>::Balance;
/// The current storage version.
const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);
......@@ -64,7 +68,7 @@ pub mod pallet {
// Moment into Balance converter
type MomentIntoBalance: Convert<Self::Moment, BalanceOf<Self>>;
// The currency
type Currency: Currency<Self::AccountId>;
type Currency: fungible::Balanced<Self::AccountId> + fungible::Mutate<Self::AccountId>;
/// Maximum number of past UD revaluations to keep in storage.
#[pallet::constant]
type MaxPastReeval: Get<u32>;
......@@ -310,7 +314,7 @@ pub mod pallet {
core::num::NonZeroU16::new(current_ud_index)
.expect("unreachable because current_ud_index is never zero."),
);
let _ = T::Currency::deposit_creating(who, uds_total);
let _ = T::Currency::deposit(who, uds_total, Precision::Exact);
Self::deposit_event(Event::UdsClaimed {
count: uds_count,
total: uds_total,
......@@ -329,7 +333,7 @@ pub mod pallet {
origin: OriginFor<T>,
dest: <T::Lookup as StaticLookup>::Source,
value: BalanceOf<T>,
existence_requirement: ExistenceRequirement,
preservation: Preservation,
) -> DispatchResultWithPostInfo {
let who = ensure_signed(origin)?;
let dest = T::Lookup::lookup(dest)?;
......@@ -338,7 +342,7 @@ pub mod pallet {
&who,
&dest,
value.saturating_mul(ud_amount) / T::UnitsPerUd::get(),
existence_requirement,
preservation,
)?;
Ok(().into())
}
......@@ -416,7 +420,7 @@ pub mod pallet {
dest: <T::Lookup as StaticLookup>::Source,
#[pallet::compact] value: BalanceOf<T>,
) -> DispatchResultWithPostInfo {
Self::do_transfer_ud(origin, dest, value, ExistenceRequirement::AllowDeath)
Self::do_transfer_ud(origin, dest, value, Preservation::Expendable)
}
/// Transfer some liquid free balance to another account, in milliUD.
......@@ -427,7 +431,7 @@ pub mod pallet {
dest: <T::Lookup as StaticLookup>::Source,
#[pallet::compact] value: BalanceOf<T>,
) -> DispatchResultWithPostInfo {
Self::do_transfer_ud(origin, dest, value, ExistenceRequirement::KeepAlive)
Self::do_transfer_ud(origin, dest, value, Preservation::Preserve)
}
}
......@@ -448,7 +452,7 @@ pub mod pallet {
first_ud_index,
PastReevals::<T>::get().into_iter(),
);
let _ = T::Currency::deposit_creating(who, uds_total);
let _ = T::Currency::deposit(who, uds_total, Precision::Exact);
Self::deposit_event(Event::UdsAutoPaid {
count: uds_count,
total: uds_total,
......
No preview for this file type
......@@ -108,7 +108,7 @@ macro_rules! pallets_config {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = common_runtime::weights::pallet_duniter_account::WeightInfo<Runtime>;
// does currency adapter in any case, but adds "refund with quota" feature
type InnerOnChargeTransaction = CurrencyAdapter<Balances, HandleFees>;
type InnerOnChargeTransaction = FungibleAdapter<Balances, HandleFees>;
type Refund = Quota;
}
......@@ -165,15 +165,14 @@ type MaxNominators = MaxNominators;
// MONEY MANAGEMENT //
impl pallet_balances::Config for Runtime {
type RuntimeHoldReason = ();
type RuntimeHoldReason = RuntimeHoldReason;
type RuntimeFreezeReason = ();
type RuntimeEvent = RuntimeEvent;
type MaxLocks = MaxLocks;
type MaxReserves = frame_support::pallet_prelude::ConstU32<5>;
type ReserveIdentifier = [u8; 8];
/// The type for recording an account's balance.
type Balance = Balance;
type DustRemoval = HandleDust;
type DustRemoval = HandleFees;
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = Account;
type FreezeIdentifier = ();
......@@ -181,27 +180,12 @@ type RuntimeFreezeReason = ();
type WeightInfo = common_runtime::weights::pallet_balances::WeightInfo<Runtime>;
}
// Take Dust from Balances and put it in the Treasury pot
pub struct HandleDust;
type CreditOf = frame_support::traits::tokens::fungible::Credit<AccountId, Balances>;
impl frame_support::traits::OnUnbalanced<CreditOf> for HandleDust {
fn on_nonzero_unbalanced(amount: CreditOf) {
use frame_support::traits::Currency as _;
use frame_support::traits::Imbalance as _;
let imbalance = NegativeImbalance::new(amount.peek());
Balances::resolve_creating(&Treasury::account_id(), imbalance);
}
}
// fees are moved to the treasury
pub struct HandleFees;
type NegativeImbalance = <Balances as frame_support::traits::Currency<AccountId>>::NegativeImbalance;
impl frame_support::traits::OnUnbalanced<NegativeImbalance> for HandleFees {
fn on_nonzero_unbalanced(amount: NegativeImbalance) {
use frame_support::traits::Currency as _;
impl frame_support::traits::OnUnbalanced<CreditOf> for HandleFees {
fn on_nonzero_unbalanced(amount: CreditOf) {
// fee is moved to treasury
Balances::resolve_creating(&Treasury::account_id(), amount);
let _ = Balances::deposit(&Treasury::account_id(), amount.peek(), frame_support::traits::tokens::Precision::Exact);
// should move the tip to author
// if let Some(author) = Authorship::author() {
// Balances::resolve_creating(&author, amount);
......@@ -349,7 +333,7 @@ type RuntimeFreezeReason = ();
type MaxRequests = frame_support::traits::ConstU32<100>;
type RequestPrice = frame_support::traits::ConstU64<2_000>;
type OnFilledRandomness = ();
type OnUnbalanced = Treasury;
type OnUnbalanced = HandleFees;
type ParentBlockRandomness = pallet_babe::ParentBlockRandomness<Self>;
type RandomnessFromOneEpochAgo = pallet_babe::RandomnessFromOneEpochAgo<Self>;
type WeightInfo = common_runtime::weights::pallet_provide_randomness::WeightInfo<Runtime>;
......@@ -534,6 +518,7 @@ type RuntimeFreezeReason = ();
type EvaluationPrice = frame_support::traits::ConstU64<1000>;
type MaxRefereeDistance = frame_support::traits::ConstU32<5>;
type MinAccessibleReferees = MinAccessibleReferees;
type RuntimeHoldReason = RuntimeHoldReason;
type RuntimeEvent = RuntimeEvent;
type WeightInfo = common_runtime::weights::pallet_distance::WeightInfo<Runtime>;
type OnValidDistanceStatus = Wot;
......
......@@ -14,7 +14,6 @@
// You should have received a copy of the GNU Affero General Public License
// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>.
#![allow(deprecated)] // TODO
#![cfg_attr(not(feature = "std"), no_std)]
// `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256.
#![recursion_limit = "256"]
......@@ -34,13 +33,15 @@ pub use common_runtime::{
constants::*, entities::*, handlers::*, AccountId, Address, Balance, BlockNumber,
FullIdentificationOfImpl, GetCurrentEpochIndex, Hash, Header, IdtyIndex, Index, Signature,
};
use frame_support::traits::fungible::Balanced;
use frame_support::traits::Imbalance;
pub use frame_system::Call as SystemCall;
pub use pallet_balances::Call as BalancesCall;
pub use pallet_identity::{IdtyStatus, IdtyValue};
pub use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
use pallet_session::historical as session_historical;
pub use pallet_timestamp::Call as TimestampCall;
use pallet_transaction_payment::CurrencyAdapter;
use pallet_transaction_payment::FungibleAdapter;
pub use pallet_universal_dividend;
#[cfg(any(feature = "std", test))]
pub use sp_runtime::BuildStorage;
......
......@@ -14,7 +14,6 @@
// You should have received a copy of the GNU Affero General Public License
// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>.
#![allow(deprecated)] // TODO
#![cfg_attr(not(feature = "std"), no_std)]
// `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256.
#![recursion_limit = "256"]
......@@ -34,13 +33,15 @@ pub use common_runtime::{
constants::*, entities::*, handlers::*, AccountId, Address, Balance, BlockNumber,
FullIdentificationOfImpl, GetCurrentEpochIndex, Hash, Header, IdtyIndex, Index, Signature,
};
use frame_support::traits::fungible::Balanced;
use frame_support::traits::Imbalance;
pub use frame_system::Call as SystemCall;
pub use pallet_balances::Call as BalancesCall;
pub use pallet_duniter_test_parameters::Parameters as GenesisParameters;
pub use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
use pallet_session::historical as session_historical;
pub use pallet_timestamp::Call as TimestampCall;
use pallet_transaction_payment::CurrencyAdapter;
use pallet_transaction_payment::FungibleAdapter;
pub use pallet_universal_dividend;
#[cfg(any(feature = "std", test))]
pub use sp_runtime::BuildStorage;
......
......@@ -14,7 +14,6 @@
// You should have received a copy of the GNU Affero General Public License
// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>.
#![allow(deprecated)] // TODO
#![cfg_attr(not(feature = "std"), no_std)]
// `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256.
#![recursion_limit = "256"]
......@@ -34,12 +33,14 @@ pub use common_runtime::{
constants::*, entities::*, handlers::*, AccountId, Address, Balance, BlockNumber,
FullIdentificationOfImpl, GetCurrentEpochIndex, Hash, Header, IdtyIndex, Index, Signature,
};
use frame_support::traits::fungible::Balanced;
use frame_support::traits::Imbalance;
pub use frame_system::Call as SystemCall;
pub use pallet_balances::Call as BalancesCall;
pub use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
use pallet_session::historical as session_historical;
pub use pallet_timestamp::Call as TimestampCall;
use pallet_transaction_payment::CurrencyAdapter;
use pallet_transaction_payment::FungibleAdapter;
pub use pallet_universal_dividend;
#[cfg(any(feature = "std", test))]
pub use sp_runtime::BuildStorage;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment