Skip to content

Commit

Permalink
New timegraph tokenomics (#1161)
Browse files Browse the repository at this point in the history
Co-authored-by: juniuszhou <[email protected]>
Co-authored-by: Github Actions <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: taniasaleem123 <[email protected]>
Co-authored-by: TaniaSaleem <[email protected]>
Co-authored-by: Tania Saleem <[email protected]>
Co-authored-by: Florian Franzen <[email protected]>
  • Loading branch information
7 people authored Oct 17, 2024
1 parent d0cc4b2 commit 06132e9
Show file tree
Hide file tree
Showing 21 changed files with 1,107 additions and 238 deletions.
5 changes: 3 additions & 2 deletions pallets/timegraph/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ scale-codec = { workspace = true, features = [ "max-encoded-len" ] }
scale-info.workspace = true
simple-mermaid.workspace = true

polkadot-sdk = { workspace = true, features = [ "frame-support", "frame-system" ] }
polkadot-sdk = { workspace = true, features = [ "frame-support", "frame-system", "sp-runtime" ] }

[dev-dependencies]
polkadot-sdk = { workspace = true, features = [ "pallet-balances", "sp-core", "sp-io", "sp-runtime" ] }
polkadot-sdk = { workspace = true, features = [ "pallet-balances", "sp-core", "sp-io", "sp-tracing" ] }


[features]
default = [ "std" ]
Expand Down
68 changes: 62 additions & 6 deletions pallets/timegraph/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,85 @@ use frame_system::RawOrigin;
#[benchmarks]
mod benchmarks {
use super::*;
use frame_support::traits::Currency;
use frame_support::traits::{Currency, ReservableCurrency};

#[benchmark]
fn deposit() {
let caller = whitelisted_caller();
let recipient = account("recipient", 0, 1);
let amount: BalanceOf<T> = 5_000_000u32.into();
let amount_be: BalanceOf<T> = amount * 100u32.into();
T::Currency::resolve_creating(&caller, T::Currency::issue(amount_be));
#[extrinsic_call]
deposit(RawOrigin::Signed(caller), recipient, amount);
deposit(RawOrigin::Signed(caller), amount);
}

#[benchmark]
fn withdraw() {
let caller = whitelisted_caller();
let recipient = account("recipient", 0, 1);
let amount: BalanceOf<T> = 5_000_000u32.into();
let amount_be: BalanceOf<T> = amount * 100u32.into();
let sequence = 1;
T::Currency::resolve_creating(&caller, T::Currency::issue(amount_be));
let _ = T::Currency::reserve(&caller, Threshold::<T>::get() + amount);

#[extrinsic_call]
withdraw(RawOrigin::Signed(caller), amount);
}

#[benchmark]
fn transfer_to_pool() {
let caller: T::AccountId = whitelisted_caller();
let account: T::AccountId = account("name", 0, 0);
let amount: BalanceOf<T> = 5_000_000_u32.into();
T::Currency::resolve_creating(
&account,
T::Currency::issue(amount * 100u32.into() + Threshold::<T>::get()),
);
TimegraphAccount::<T>::set(caller.clone());
let _ = T::Currency::reserve(&account, Threshold::<T>::get() + amount);

#[extrinsic_call]
transfer_to_pool(RawOrigin::Signed(caller), account, amount);
}

#[benchmark]
fn transfer_award_to_user() {
let caller: T::AccountId = whitelisted_caller();
let account: T::AccountId = account("name", 0, 0);
let amount: BalanceOf<T> = 5_000_000_u32.into();

T::Currency::resolve_creating(&caller, T::Currency::issue(amount * 200u32.into()));

T::Currency::resolve_creating(&account, T::Currency::issue(amount * 100u32.into()));

TimegraphAccount::<T>::set(caller.clone());
RewardPoolAccount::<T>::set(caller.clone());

#[extrinsic_call]
transfer_award_to_user(RawOrigin::Signed(caller), account, amount);
}

#[benchmark]
fn set_timegraph_account() {
let new_account: T::AccountId = account("name", 0, 0);
#[extrinsic_call]
// Example new account
set_timegraph_account(RawOrigin::Root, new_account);
}

#[benchmark]
fn set_reward_pool_account() {
let new_account: T::AccountId = account("name", 0, 0);

#[extrinsic_call]
set_reward_pool_account(RawOrigin::Root, new_account);
}

#[benchmark]
fn set_threshold() {
let amount: BalanceOf<T> = 5_000_000_u32.into();

#[extrinsic_call]
withdraw(RawOrigin::Signed(caller), recipient, amount, sequence);
set_threshold(RawOrigin::Root, amount);
}

impl_benchmark_test_suite!(Timegraph, crate::mock::new_test_ext(), crate::mock::Test);
Expand Down
Loading

0 comments on commit 06132e9

Please sign in to comment.