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

Replace Currency->fungible trait migration for time-release pallet #1818

Merged
merged 14 commits into from
Jan 5, 2024
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
237 changes: 114 additions & 123 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ lint-audit:
format-lint: format lint

.PHONY: ci-local
ci-local: check lint lint-audit test e2e-tests
ci-local: check lint lint-audit test js e2e-tests

.PHONY: upgrade
upgrade-local:
Expand Down
1,128 changes: 696 additions & 432 deletions e2e/package-lock.json

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions pallets/time-release/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pallet-time-release"
description = "Provides scheduled balance locking mechanism, in a *graded release* way."
description = "Provides scheduled balance freezing mechanism, in a *graded release* way."
authors = ["Frequency"]
edition = "2021"
homepage = "https://frequency.xyz"
Expand All @@ -23,11 +23,12 @@ sp-io = { workspace = true }
sp-runtime = { workspace = true }
sp-std = { workspace = true }
frame-benchmarking = { workspace = true, optional = true }
sp-core = { workspace = true }
log = { workspace = true, default-features = false }

[dev-dependencies]
chrono = { workspace = true }
pallet-balances = { workspace = true }
sp-core = { workspace = true }
common-primitives = { default-features = false, path = "../../common/primitives" }

[features]
Expand Down
4 changes: 2 additions & 2 deletions pallets/time-release/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ This pallet is a fork of the [ORML-vesting]( [vesting](https://github.com/open-w

## Overview

Time-release module provides a means of scheduled balance lock on an account. It uses the *graded release* way, which unlocks a specific amount of balance every period of time, until all balance unlocked.
The `time-release` module offers a method for scheduling a balance freeze on an account. It employs a *graded release* approach, which thaws a specific amount of balance every period of time, until all balance is thawed.

### Release Schedule

The schedule of a release on hold is described by data structure `ReleaseSchedule`: from the block number of `start`, for every `period` amount of blocks, `per_period` amount of balance would unlocked, until number of periods `period_count` reached. Note in release schedules, *time* is measured by block number. All `ReleaseSchedule`s under an account could be queried in chain state.
The schedule of a release on hold is described by the data structure `ReleaseSchedule`. Starting from the specified block number denoted as `start`, the schedule operates on a periodic basis. For each `period` amount of blocks, a designated `per_period` amount of balance is unfrozen. This process continues until the specified number of periods, denoted as `period_count`, is reached. It's important to highlight that in release schedules, the concept of time is measured in terms of block numbers. Accessing all `ReleaseSchedule` instances associated with an account is possible through querying the chain state.
10 changes: 4 additions & 6 deletions pallets/time-release/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use super::*;
use crate::Pallet as TimeReleasePallet;

use frame_benchmarking::{account, benchmarks, whitelist_account, whitelisted_caller};
use frame_support::traits::{Currency, Imbalance};
use frame_system::{pallet_prelude::BlockNumberFor, RawOrigin};
use sp_runtime::{traits::TrailingZeroInput, SaturatedConversion};
use sp_std::prelude::*;
Expand All @@ -17,9 +16,8 @@ pub type Schedule<T> = ReleaseSchedule<BlockNumberFor<T>, BalanceOf<T>>;
const SEED: u32 = 0;

fn set_balance<T: Config>(who: &T::AccountId, balance: BalanceOf<T>) {
let deposit_result = T::Currency::deposit_creating(who, balance.saturated_into());
let actual_deposit = deposit_result.peek();
assert_eq!(balance, actual_deposit);
let actual_deposit = T::Currency::mint_into(&who, balance.saturated_into());
assert_eq!(balance, actual_deposit.unwrap());
}

fn lookup_of_account<T: Config>(
Expand Down Expand Up @@ -76,7 +74,7 @@ benchmarks! {
}: _(RawOrigin::Signed(to.clone()))
verify {
assert_eq!(
T::Currency::free_balance(&to),
T::Currency::balance(&to),
schedule.total_amount().unwrap() * BalanceOf::<T>::from(i) ,
);
}
Expand All @@ -103,7 +101,7 @@ benchmarks! {
}: _(RawOrigin::Root, to_lookup, schedules)
verify {
assert_eq!(
T::Currency::free_balance(&to),
T::Currency::balance(&to),
schedule.total_amount().unwrap() * BalanceOf::<T>::from(i)
);
}
Expand Down
Loading
Loading