Skip to content

Commit

Permalink
Merge pull request #629 from galacticcouncil/fix-nft-weights
Browse files Browse the repository at this point in the history
fix: nft weights
  • Loading branch information
mrq1911 authored Jun 7, 2023
2 parents a907ef9 + 7f211fc commit b5fb0a0
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 29 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.9.10"
version = "0.9.11"
description = "Integration tests"
authors = ["GalacticCouncil"]
edition = "2021"
Expand Down
38 changes: 20 additions & 18 deletions integration-tests/src/fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,23 @@ use xcm_emulator::TestExt;

macro_rules! assert_eq_approx {
( $x:expr, $y:expr, $z:expr, $r:expr) => {{
let diff = if $x >= $y { $x - $y } else { $y - $x };
if diff > $z {
panic!("\n{} not equal\nleft: {:?}\nright: {:?}\n", $r, $x, $y);
let d = if $x >= $y { $x - $y } else { $y - $x };
if d > $z {
panic!(
"\n{}\nleft: {:?}\nright: {:?}\nallowed diff: {:?}\nactual diff: {:?}\n",
$r, $x, $y, $z, d
);
}
}};
}

//NOTE: rust encoded call size is differen from UI encoded call size that's why we have asserts for 2 fees.
//NOTE: rust encoded call size is different from UI encoded call size that's why we have asserts for 2 fees.

const DIFF: u128 = 100 * UNITS;

#[test]
fn transaction_fees_should_be_as_expected_when_transfer_happen() {
Basilisk::execute_with(|| {
let diff = UNITS / 100; //0.01

let expected_rust_encoded_fees = 4_705 * UNITS / 100; //47.05
let expected_ui_fees = 4_804 * UNITS / 100; //48.04

Expand Down Expand Up @@ -64,17 +67,14 @@ fn transaction_fees_should_be_as_expected_when_transfer_happen() {
format_num(min_multiplier_rust_fees * 10_000 / UNITS, 4),
);

assert_eq_approx!(rust_encoded_fees, expected_rust_encoded_fees, diff, "rust fees changed");
assert_eq_approx!(ui_fees, expected_ui_fees, diff, "ui fees changed");
assert_eq_approx!(rust_encoded_fees, expected_rust_encoded_fees, DIFF, "rust fees changed");
assert_eq_approx!(ui_fees, expected_ui_fees, DIFF, "ui fees changed");
});
}

#[test]
fn transaction_fees_should_be_as_expected_when_nft_is_minted() {
Basilisk::execute_with(|| {
//NOTE: Price showed by polkadotAPPS is changing at second decimal place between runs.
let diff = UNITS / 10; //0.1

let expected_rust_encoded_fees = 48_619 * UNITS / 100; //486.19
let expected_ui_fees = 48_724 * UNITS / 100; //487.24

Expand Down Expand Up @@ -120,17 +120,19 @@ fn transaction_fees_should_be_as_expected_when_nft_is_minted() {
format_num(min_multiplier_rust_fees * 10_000 / UNITS, 4),
);

assert_eq_approx!(rust_encoded_fees, expected_rust_encoded_fees, diff, "rust fees changed");
assert_eq_approx!(ui_fees, expected_ui_fees, diff, "ui fees changed");
assert_eq_approx!(
rust_encoded_fees,
expected_rust_encoded_fees,
DIFF,
"rust fees difference too large"
);
assert_eq_approx!(ui_fees, expected_ui_fees, DIFF, "ui fees difference too large");
});
}

#[test]
fn transaction_fees_should_be_as_expected_when_nft_collection_is_created() {
Basilisk::execute_with(|| {
//NOTE: Price showed by polkadotAPPS is changing at second decimal place between runs.
let diff = UNITS / 10; //0.1

let expected_rust_encoded_fees = 45_584 * UNITS / 100; //455.84
let expected_ui_fees = 45_689 * UNITS / 100; //456.89

Expand Down Expand Up @@ -176,8 +178,8 @@ fn transaction_fees_should_be_as_expected_when_nft_collection_is_created() {
format_num(min_multiplier_rust_fees * 10_000 / UNITS, 4),
);

assert_eq_approx!(rust_encoded_fees, expected_rust_encoded_fees, diff, "rust fees changed");
assert_eq_approx!(ui_fees, expected_ui_fees, diff, "ui fees changed");
assert_eq_approx!(rust_encoded_fees, expected_rust_encoded_fees, DIFF, "rust fees changed");
assert_eq_approx!(ui_fees, expected_ui_fees, DIFF, "ui fees changed");
});
}

Expand Down
2 changes: 1 addition & 1 deletion pallets/xyk/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = 'pallet-xyk'
version = "6.2.7"
version = "6.2.8"
description = 'XYK automated market maker'
authors = ['GalacticCouncil']
edition = '2021'
Expand Down
2 changes: 0 additions & 2 deletions pallets/xyk/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ benchmarks! {
}: _(RawOrigin::Signed(caller.clone()), asset_a, asset_b, amount, min_bought, discount)
verify{
assert_eq!(T::Currency::free_balance(asset_a, &caller), 999999000000000);
assert_eq!(T::Currency::free_balance(asset_b, &caller), 1000002988011991);
}

buy {
Expand All @@ -122,7 +121,6 @@ benchmarks! {
}: _(RawOrigin::Signed(caller.clone()), asset_a, asset_b, amount, max_sold, discount)
verify{
assert_eq!(T::Currency::free_balance(asset_a, &caller), 1000001000000000);
assert_eq!(T::Currency::free_balance(asset_b, &caller), 999996987987987);
}
}

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 = "100.0.0"
version = "101.0.0"
authors = ["GalacticCouncil"]
edition = "2021"
homepage = "https://github.com/galacticcouncil/Basilisk-node"
Expand Down
2 changes: 1 addition & 1 deletion runtime/basilisk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("basilisk"),
impl_name: create_runtime_str!("basilisk"),
authoring_version: 1,
spec_version: 100,
spec_version: 101,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
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 = "2.3.13"
version = "2.3.14"
authors = ["GalacticCouncil"]
edition = "2021"
homepage = "https://github.com/galacticcouncil/Basilisk-node"
Expand Down
6 changes: 6 additions & 0 deletions runtime/common/src/weights/nft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ use pallet_nft::weights::WeightInfo;

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

//This consts are here to make `create_collection()` and `mint()` more expensive.
const CREATE_COLLECTION_OFFSET: u64 = 180 * 2;
const MINT_OFFSET: u64 = 140 * 2;

impl<T: frame_system::Config> WeightInfo for BasiliskWeight<T> {
// Storage: Uniques Class (r:1 w:1)
// Proof: Uniques Class (max_values: None, max_size: Some(190), added: 2665, mode: MaxEncodedLen)
Expand All @@ -63,6 +67,7 @@ impl<T: frame_system::Config> WeightInfo for BasiliskWeight<T> {
fn create_collection() -> Weight {
// Minimum execution time: 19_500 nanoseconds.
Weight::from_ref_time(19_928_000 as u64)
.saturating_mul(CREATE_COLLECTION_OFFSET)
.saturating_add(T::DbWeight::get().reads(3 as u64))
.saturating_add(T::DbWeight::get().writes(3 as u64))
}
Expand All @@ -85,6 +90,7 @@ impl<T: frame_system::Config> WeightInfo for BasiliskWeight<T> {
fn mint() -> Weight {
// Minimum execution time: 31_625 nanoseconds.
Weight::from_ref_time(32_251_000 as u64)
.saturating_mul(MINT_OFFSET)
.saturating_add(T::DbWeight::get().reads(6 as u64))
.saturating_add(T::DbWeight::get().writes(4 as u64))
}
Expand Down

0 comments on commit b5fb0a0

Please sign in to comment.