Skip to content

Commit

Permalink
Merge pull request #518 from galacticcouncil/feat/fees
Browse files Browse the repository at this point in the history
fix: fees adjusted
  • Loading branch information
mrq1911 authored Jul 12, 2022
2 parents 03c8061 + 91c8770 commit 0446e6c
Show file tree
Hide file tree
Showing 14 changed files with 161 additions and 31 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "runtime-integration-tests"
version = "0.4.0"
version = "0.5.0"
description = "Integration tests"
authors = ["GalacticCouncil"]
edition = "2021"
Expand Down
18 changes: 9 additions & 9 deletions integration-tests/src/cross_chain_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,24 @@ fn transfer_from_relay_chain() {
.into()
.into()
),
Box::new((Here, 3 * UNITS).into()),
Box::new((Here, 300 * UNITS).into()),
0,
));

assert_eq!(
kusama_runtime::Balances::free_balance(&ParaId::from(2000).into_account()),
13 * UNITS
310 * UNITS
);
});

Basilisk::execute_with(|| {
assert_eq!(
basilisk_runtime::Tokens::free_balance(1, &AccountId::from(BOB)),
10028 * UNITS / 10
12780 * UNITS / 10
);
assert_eq!(
basilisk_runtime::Tokens::free_balance(1, &basilisk_runtime::Treasury::account_id()),
2 * UNITS / 10 // fees should go to treasury
22 * UNITS
);
});
}
Expand Down Expand Up @@ -108,7 +108,7 @@ fn transfer_from_hydra() {
assert_ok!(basilisk_runtime::XTokens::transfer(
basilisk_runtime::Origin::signed(ALICE.into()),
0,
3 * UNITS,
30 * UNITS,
Box::new(
MultiLocation::new(
1,
Expand All @@ -126,18 +126,18 @@ fn transfer_from_hydra() {
));
assert_eq!(
basilisk_runtime::Balances::free_balance(&AccountId::from(ALICE)),
200 * UNITS - 3 * UNITS
200 * UNITS - 30 * UNITS
);
});

Basilisk::execute_with(|| {
assert_eq!(
basilisk_runtime::Tokens::free_balance(1, &AccountId::from(BOB)),
10028 * UNITS / 10
10080 * UNITS / 10
);
assert_eq!(
basilisk_runtime::Tokens::free_balance(1, &basilisk_runtime::Treasury::account_id()),
2 * UNITS / 10 // fees should go to treasury
22 * UNITS // fees should go to treasury
);
});
}
Expand Down Expand Up @@ -241,7 +241,7 @@ fn fee_currency_set_on_xcm_transfer() {
});

Basilisk::execute_with(|| {
let fee_amount = 2 * UNITS / 10;
let fee_amount = 22 * UNITS;
assert_eq!(
basilisk_runtime::Tokens::free_balance(1, &AccountId::from(HITCHHIKER)),
transfer_amount - fee_amount
Expand Down
49 changes: 49 additions & 0 deletions integration-tests/src/fees.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#![cfg(test)]

use crate::kusama_test_net::*;
use basilisk_runtime::TransactionPayment;
use frame_support::weights::GetDispatchInfo;
use sp_runtime::codec::Encode;
use xcm_emulator::TestExt;

#[test]
// #[ignore]
//TODO: fix this, fees calculcated in this test are apporx 2bsx off.
fn transfer_transaction_fees() {
//This test is not correct
Basilisk::execute_with(|| {
let call = orml_currencies::Call::<basilisk_runtime::Runtime>::transfer {
dest: AccountId::from(ALICE),
currency_id: 0,
amount: 50 * UNITS,
};

let info = call.get_dispatch_info();
let len = call.encoded_size() as u32;
let fees = TransactionPayment::compute_fee(len, &info, 0);

//This test is not correct it's approx 1bsx of from real fees
println!("transfer cost {:?} BSX", fees / UNITS);
});
}

#[test]
fn nft_mint_transaction_fees() {
Basilisk::execute_with(|| {
let call = pallet_nft::Call::<basilisk_runtime::Runtime>::mint {
class_id: 0,
instance_id: 0,
metadata: b"ipfs://QmQu2jUmtFNPd86tEHFs6hmAArKYyjEC3xuwVWpFGjcMgm"
.to_vec()
.try_into()
.unwrap(),
};

let info = call.get_dispatch_info();
let len = call.encoded_size() as u32;
let fees = TransactionPayment::compute_fee(len, &info, 0);

//This test is not correct it's approx 1bsx of from real fees
println!("mint nft cost {:?} BSX", fees / UNITS);
});
}
1 change: 1 addition & 0 deletions integration-tests/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod cross_chain_transfer;
mod fees;
mod kusama_test_net;
mod nft_marketplace;
mod non_native_fee;
8 changes: 4 additions & 4 deletions integration-tests/src/non_native_fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fn non_native_fee_payment_works() {
let bob_balance = basilisk_runtime::Tokens::free_balance(1, &AccountId::from(BOB));

// 462_676_500_000 (~0.46 UNITS) spent on fee
assert_eq!(bob_balance, 999_493_284_500_000);
assert_eq!(bob_balance, 944_261_295_000_000);

let pair_account = basilisk_runtime::XYK::get_pair_id(AssetPair {
asset_in: currency_0,
Expand Down Expand Up @@ -112,14 +112,14 @@ fn non_native_fee_payment_works() {
));

let dave_balance = basilisk_runtime::Tokens::free_balance(1, &AccountId::from(DAVE));
assert_eq!(dave_balance, 999_709_532_354_655);
assert_eq!(dave_balance, 968_048_559_011_998);

expect_basilisk_events(vec![
pallet_transaction_multi_payment::Event::FeeWithdrawn {
account_id: DAVE.into(),
asset_id: 1,
native_fee_amount: 506_715_500_000,
non_native_fee_amount: 290_467_645_345,
native_fee_amount: 55_738_705_000_000,
non_native_fee_amount: 31_951_440_988_002,
destination_account_id: basilisk_runtime::MultiTransactionPayment::get_fee_receiver(),
}
.into(),
Expand Down
2 changes: 1 addition & 1 deletion runtime/basilisk/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "basilisk-runtime"
version = "64.0.0"
version = "65.0.0"
authors = ["GalacticCouncil"]
edition = "2021"
homepage = "/~https://github.com/galacticcouncil/Basilisk-node"
Expand Down
12 changes: 6 additions & 6 deletions runtime/basilisk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("basilisk"),
impl_name: create_runtime_str!("basilisk"),
authoring_version: 1,
spec_version: 64,
spec_version: 65,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down Expand Up @@ -171,14 +171,13 @@ impl WeightToFeePolynomial for WeightToFee {
/// - Setting it to `0` will essentially disable the weight fee.
/// - Setting it to `1` will cause the literal `#[weight = x]` values to be charged.
fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {
// extrinsic base weight (smallest non-zero weight) is mapped to 1/10 CENT
let p = CENTS; // 1_000_000_000_000
let q = 10 * Balance::from(ExtrinsicBaseWeight::get()); // 7_919_840_000
let p = 11 * CENTS;
let q = Balance::from(ExtrinsicBaseWeight::get());
smallvec![WeightToFeeCoefficient {
degree: 1,
negative: false,
coeff_frac: Perbill::from_rational(p % q, q),
coeff_integer: p / q, // 124
coeff_integer: p / q,
}]
}
}
Expand Down Expand Up @@ -549,7 +548,8 @@ parameter_types! {

impl pallet_nft::Config for Runtime {
type Event = Event;
type WeightInfo = weights::nft::BasiliskWeight<Runtime>;
//Generated weight file is not used because we want diffent prices for now.
type WeightInfo = weights::offsetted_nft::BasiliskWeight<Runtime>;
type NftClassId = ClassId;
type NftInstanceId = InstanceId;
type ProtocolOrigin = EnsureRoot<AccountId>;
Expand Down
3 changes: 1 addition & 2 deletions runtime/basilisk/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ fn full_block_cost() {
#[test]
// This function tests that the fee for `ExtrinsicBaseWeight` of weight is correct
fn extrinsic_base_fee_is_correct() {
// `ExtrinsicBaseWeight` should cost 1/10 of a CENT
let base_fee = WeightToFee::calc(&ExtrinsicBaseWeight::get());
let base_fee_expected = CENTS / 10;
let base_fee_expected = CENTS * 11;
assert!(base_fee.max(base_fee_expected) - base_fee.min(base_fee_expected) < MILLICENTS);
}

Expand Down
2 changes: 1 addition & 1 deletion runtime/common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "common-runtime"
version = "1.10.0"
version = "1.11.0"
authors = ["GalacticCouncil"]
edition = "2021"
homepage = "/~https://github.com/galacticcouncil/Basilisk-node"
Expand Down
2 changes: 1 addition & 1 deletion runtime/common/src/weights/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub mod duster;
pub mod exchange;
pub mod lbp;
pub mod marketplace;
pub mod nft;
pub mod offsetted_nft;
pub mod payment;
pub mod price_oracle;
pub mod scheduler;
Expand Down
81 changes: 81 additions & 0 deletions runtime/common/src/weights/offsetted_nft.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// This file is part of Basilisk-node.

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

//! Autogenerated weights for pallet_nft
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2022-07-06, STEPS: 5, REPEAT: 20, LOW RANGE: [], HIGH RANGE: []
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024
// Executed Command:
// target/release/basilisk
// benchmark
// --chain=dev
// --steps=5
// --repeat=20
// --execution=wasm
// --wasm-execution=compiled
// --heap-pages=4096
// --template=.maintain/pallet-weight-template-no-back.hbs
// --pallet=pallet_nft
// --output=nft.rs
// --extrinsic=*
#![allow(unused_parens)]
#![allow(unused_imports)]
#![allow(clippy::unnecessary_cast)]

use frame_support::{
traits::Get,
weights::{constants::RocksDbWeight, Weight},
};
use sp_std::marker::PhantomData;

use pallet_nft::weights::WeightInfo;

pub struct BasiliskWeight<T>(PhantomData<T>);

//This consts are here to make `create_class()` and `mint()` more expensive.
const CREATE_CLASS_OFFSET: u64 = 160;
const MINT_OFFSET: u64 = 120;

impl<T: frame_system::Config> WeightInfo for BasiliskWeight<T> {
fn create_class() -> Weight {
(CREATE_CLASS_OFFSET * 41_173_000 as Weight)
.saturating_add(T::DbWeight::get().reads(2 as Weight))
.saturating_add(T::DbWeight::get().writes(4 as Weight))
}
fn mint() -> Weight {
(MINT_OFFSET * 55_520_000 as Weight)
.saturating_add(T::DbWeight::get().reads(4 as Weight))
.saturating_add(T::DbWeight::get().writes(5 as Weight))
}
fn transfer() -> Weight {
(46_700_000 as Weight)
.saturating_add(T::DbWeight::get().reads(3 as Weight))
.saturating_add(T::DbWeight::get().writes(3 as Weight))
}
fn destroy_class() -> Weight {
(63_644_000 as Weight)
.saturating_add(T::DbWeight::get().reads(4 as Weight))
.saturating_add(T::DbWeight::get().writes(5 as Weight))
}
fn burn() -> Weight {
(58_040_000 as Weight)
.saturating_add(T::DbWeight::get().reads(4 as Weight))
.saturating_add(T::DbWeight::get().writes(5 as Weight))
}
}
2 changes: 1 addition & 1 deletion runtime/testing-basilisk/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "testing-basilisk-runtime"
version = "64.0.0"
version = "65.0.0"
authors = ["GalacticCouncil"]
edition = "2021"
homepage = "/~https://github.com/galacticcouncil/Basilisk-node"
Expand Down
2 changes: 1 addition & 1 deletion runtime/testing-basilisk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("testing-basilisk"),
impl_name: create_runtime_str!("testing-basilisk"),
authoring_version: 1,
spec_version: 64,
spec_version: 65,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down

0 comments on commit 0446e6c

Please sign in to comment.