-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* first dispatchable for teerdays * basic bonding and unbonding without unlockingperiod. type trouble * fix type trouble * fix unbonding * cosmetics * implement unlock period * minimal benchmarks * add bond_extra call * refactor * add unhappy tests * pallet code docs * cleanup * cleanup * doc pimp * taplo * taplo * zepter+fmt * fmt nightly * fmt * clippy * review fixes * clippy again * clippy version mismatch? * clippy version mismatch? --------- Co-authored-by: Christian Langenbacher <[email protected]>
- Loading branch information
Showing
18 changed files
with
1,102 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
[package] | ||
name = "teerdays-primitives" | ||
version = "0.1.0" | ||
authors = ["Integritee AG <[email protected]>"] | ||
homepage = "https://integritee.network/" | ||
repository = "https://github.com/integritee-network/pallets/" | ||
license = "Apache-2.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
parity-scale-codec = { workspace = true } | ||
scale-info = { workspace = true } | ||
serde = { workspace = true } | ||
sp-core = { workspace = true } | ||
sp-runtime = { workspace = true } | ||
|
||
[features] | ||
default = ["std"] | ||
std = [ | ||
"parity-scale-codec/std", | ||
"scale-info/std", | ||
"serde/std", | ||
"sp-core/std", | ||
"sp-runtime/std", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use parity_scale_codec::{Decode, Encode}; | ||
use scale_info::TypeInfo; | ||
use sp_runtime::{traits::AtLeast32BitUnsigned, Saturating}; | ||
|
||
#[derive(Encode, Decode, Copy, Clone, PartialEq, Eq, Default, sp_core::RuntimeDebug, TypeInfo)] | ||
pub struct TeerDayBond<Balance, Moment> { | ||
pub value: Balance, | ||
pub last_updated: Moment, | ||
// the unit here is actually balance * moments. | ||
pub accumulated_tokentime: Balance, | ||
} | ||
|
||
impl<Balance, Moment> TeerDayBond<Balance, Moment> | ||
where | ||
Moment: Clone + Copy + Encode + Decode + Saturating, | ||
Balance: AtLeast32BitUnsigned + Clone + Copy + Encode + Decode + Default + From<Moment>, | ||
{ | ||
pub fn update(self, now: Moment) -> Self { | ||
let elapsed: Balance = now.saturating_sub(self.last_updated).into(); | ||
let new_tokentime = | ||
self.accumulated_tokentime.saturating_add(self.value.saturating_mul(elapsed)); | ||
Self { value: self.value, last_updated: now, accumulated_tokentime: new_tokentime } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
[toolchain] | ||
channel = "nightly-2023-06-01" | ||
channel = "stable" | ||
targets = ["wasm32-unknown-unknown"] | ||
profile = "default" # include rustfmt, clippy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
[package] | ||
name = "pallet-teerdays" | ||
version = "0.1.0" | ||
authors = ["Integritee AG <[email protected]>"] | ||
homepage = "https://integritee.network/" | ||
repository = "https://github.com/integritee-network/pallets/" | ||
license = "(GPL-3.0-only)" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
log = { workspace = true } | ||
parity-scale-codec = { workspace = true } | ||
scale-info = { workspace = true } | ||
serde = { workspace = true, optional = true } | ||
|
||
teerdays-primitives = { path = "../primitives/teerdays", default-features = false } | ||
|
||
# substrate dependencies | ||
frame-support = { workspace = true } | ||
frame-system = { workspace = true } | ||
pallet-balances = { workspace = true } | ||
pallet-timestamp = { workspace = true } | ||
sp-core = { workspace = true } | ||
sp-io = { workspace = true } | ||
sp-runtime = { workspace = true } | ||
sp-std = { workspace = true } | ||
|
||
# benchmarking | ||
frame-benchmarking = { workspace = true, optional = true } | ||
hex-literal = { workspace = true, optional = true } | ||
|
||
[dev-dependencies] | ||
env_logger = { workspace = true } | ||
sp-keyring = { workspace = true } | ||
|
||
[features] | ||
default = ["std"] | ||
std = [ | ||
"frame-benchmarking?/std", | ||
"frame-support/std", | ||
"frame-system/std", | ||
"log/std", | ||
"pallet-balances/std", | ||
"pallet-timestamp/std", | ||
"parity-scale-codec/std", | ||
"scale-info/std", | ||
"serde/std", | ||
"sp-core/std", | ||
"sp-io/std", | ||
"sp-keyring/std", | ||
"sp-runtime/std", | ||
"sp-std/std", | ||
"teerdays-primitives/std", | ||
] | ||
|
||
try-runtime = [ | ||
"frame-support/try-runtime", | ||
"frame-system/try-runtime", | ||
"pallet-balances/try-runtime", | ||
"pallet-timestamp/try-runtime", | ||
"sp-runtime/try-runtime", | ||
] | ||
|
||
runtime-benchmarks = [ | ||
"frame-benchmarking/runtime-benchmarks", | ||
"frame-support/runtime-benchmarks", | ||
"frame-system/runtime-benchmarks", | ||
"hex-literal", | ||
"pallet-balances/runtime-benchmarks", | ||
"pallet-timestamp/runtime-benchmarks", | ||
"sp-runtime/runtime-benchmarks", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
Copyright 2021 Integritee AG | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
//! TeerDays pallet benchmarking | ||
|
||
#![cfg(any(test, feature = "runtime-benchmarks"))] | ||
|
||
use super::*; | ||
|
||
use crate::Pallet as TeerDays; | ||
use frame_benchmarking::{account, benchmarks}; | ||
use frame_system::RawOrigin; | ||
use sp_std::prelude::*; | ||
|
||
benchmarks! { | ||
where_clause { where T::AccountId: From<[u8; 32]>, T::Hash: From<[u8; 32]> } | ||
bond { | ||
pallet_timestamp::Pallet::<T>::set_timestamp(0u32.into()); | ||
let signer: T::AccountId = account("alice", 1, 1); | ||
T::Currency::make_free_balance_be(&signer, 10_000u32.into()); | ||
}: _(RawOrigin::Signed(signer.clone()), 1_000u32.into()) | ||
verify { | ||
assert!(TeerDays::<T>::teerday_bonds(&signer).is_some()); | ||
} | ||
|
||
unbond { | ||
pallet_timestamp::Pallet::<T>::set_timestamp(0u32.into()); | ||
let signer: T::AccountId = account("alice", 1, 1); | ||
T::Currency::make_free_balance_be(&signer, 10_000u32.into()); | ||
TeerDays::<T>::bond(RawOrigin::Signed(signer.clone()).into(), 1_000u32.into())?; | ||
}: _(RawOrigin::Signed(signer.clone()), 500u32.into()) | ||
verify { | ||
assert!(TeerDays::<T>::teerday_bonds(&signer).is_some()); | ||
} | ||
|
||
update_other { | ||
pallet_timestamp::Pallet::<T>::set_timestamp(0u32.into()); | ||
let signer: T::AccountId = account("alice", 1, 1); | ||
T::Currency::make_free_balance_be(&signer, 10_000u32.into()); | ||
TeerDays::<T>::bond(RawOrigin::Signed(signer.clone()).into(), 1_000u32.into())?; | ||
}: _(RawOrigin::Signed(signer.clone()), signer.clone()) | ||
verify { | ||
assert!(TeerDays::<T>::teerday_bonds(&signer).is_some()); | ||
} | ||
withdraw_unbonded { | ||
pallet_timestamp::Pallet::<T>::set_timestamp(42u32.into()); | ||
let signer: T::AccountId = account("alice", 1, 1); | ||
T::Currency::make_free_balance_be(&signer, 10_000u32.into()); | ||
T::Currency::set_lock(TEERDAYS_ID, &signer, 1_000u32.into(), WithdrawReasons::all()); | ||
PendingUnlock::<T>::insert::<_, (T::Moment, BalanceOf<T>)>(&signer, (42u32.into(), 1_000u32.into())); | ||
}: _(RawOrigin::Signed(signer.clone())) | ||
verify { | ||
assert!(TeerDays::<T>::pending_unlock(&signer).is_none()); | ||
} | ||
|
||
} | ||
|
||
#[cfg(test)] | ||
use crate::{Config, Pallet as PalletModule}; | ||
|
||
#[cfg(test)] | ||
use frame_benchmarking::impl_benchmark_test_suite; | ||
|
||
#[cfg(test)] | ||
impl_benchmark_test_suite!(PalletModule, crate::mock::new_test_ext(), crate::mock::Test,); |
Oops, something went wrong.