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

feat: duster pallet #104

Merged
merged 16 commits into from
Aug 10, 2021
Merged
Show file tree
Hide file tree
Changes from 8 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
23 changes: 23 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ members = [
# 'pallets/proposal', Update this
'node',
'pallets/nft',
'pallets/duster',
'runtime',
'pallets/xyk',
'pallets/exchange',
Expand Down
69 changes: 69 additions & 0 deletions pallets/duster/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
[package]
authors = ['GalacticCouncil']
description = 'Account duster'
edition = '2018'
homepage = '/~https://github.com/galacticcouncil/Basilisk-node'
license = 'Apache 2.0'
name = 'pallet-duster'
repository = '/~https://github.com/galacticcouncil/Basilisk-node'
version = '1.0.0'

[package.metadata.docs.rs]
targets = ['x86_64-unknown-linux-gnu']

[build-dependencies]
substrate-wasm-builder = {package = 'substrate-wasm-builder', version = '3.0.0'}

# alias "parity-scale-code" to "codec"
[dependencies.codec]
default-features = false
features = ['derive']
package = 'parity-scale-codec'
version = '2.0.0'

[dependencies]
serde = {features = ['derive'], optional = true, version = '1.0.101'}

# ORML dependencies
orml-traits = {default-features = false, version = "0.4.1-dev"}

# Substrate dependencies
sp-std = {default-features = false, version = '3.0.0'}
frame-support = {default-features = false, version = '3.0.0'}
frame-system = {default-features = false, version = '3.0.0'}

# Optionals
frame-system-benchmarking = {default-features = false, optional = true, version = '3.0.0'}
frame-benchmarking = {default-features = false, optional = true, version = '3.0.0'}

[dev-dependencies]
sp-io = {default-features = false, version = '3.0.0'}
orml-currencies = {default-features = false, version = "0.4.1-dev"}
orml-tokens = {default-features = false, version = "0.4.1-dev"}
primitives = {path = '../../primitives', default-features = false}
lazy_static = {features = ['spin_no_std'], version = "1.4.0"}
sp-core = {default-features = false, version = '3.0.0'}
sp-runtime = {default-features = false, version = '3.0.0'}
pallet-balances = {default-features = false, version = '3.0.0'}

[features]
default = ['std']
runtime-benchmarks = [
"frame-benchmarking",
"frame-system/runtime-benchmarks",
"frame-support/runtime-benchmarks",
]
std = [
'serde',
'codec/std',
'frame-support/std',
'frame-system/std',
'sp-runtime/std',
'sp-core/std',
'sp-std/std',
'orml-tokens/std',
'orml-traits/std',
'primitives/std',
'lazy_static/spin_no_std',
'pallet-balances/default',
]
66 changes: 66 additions & 0 deletions pallets/duster/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// This file is part of HydraDX.

// Copyright (C) 2020-2021 Intergalactic, Limited (GIB).
// SPDX-License-Identifier: Apache-2.0

// 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.

#![cfg(feature = "runtime-benchmarks")]

use super::*;

use frame_benchmarking::{account, benchmarks};
use frame_system::RawOrigin;

const SEED: u32 = 1;

fn funded_account<T: Config>(name: &'static str, index: u32) -> T::AccountId
where
<T as pallet::Config>::CurrencyId: From<u32>,
{
let caller: T::AccountId = account(name, index, SEED);
caller
}

benchmarks! {
dust_account{
let caller = funded_account::<T>("caller", 0);
let to_dust_account = funded_account::<T>("dust", 0);

let dust_amount : T::Amount = 1_000u32.into();

T::MultiCurrency::update_balance(1u32.into(), &to_dust_account, dust_amount).unwrap();
assert_eq!(T::MultiCurrency::free_balance(1u32.into(), &to_dust_account), 1000u32.into());

}: _(RawOrigin::Signed(caller.clone()), to_dust_account.clone(),1u32.into())
verify {
assert_eq!(T::MultiCurrency::free_balance(1u32.into(), &to_dust_account), 0u32.into());
assert_eq!(T::MultiCurrency::free_balance(0u32.into(), &caller), 10_000u32.into());
assert_eq!(T::MultiCurrency::free_balance(1u32.into(), &T::DustAccount::get()), 1000u32.into());
}
}

#[cfg(test)]
mod tests {
use super::mock::Test;
use super::*;
use crate::mock::ExtBuilder;
use frame_support::assert_ok;

#[test]
fn test_benchmarks() {
ExtBuilder::default().build().execute_with(|| {
assert_ok!(test_benchmark_dust_account::<Test>());
});
}
}
Loading