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

Xorless fee #1279

Merged
merged 24 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
34f2497
benchmark and extrinsic: not fully redacted
ZlayaMorda Oct 28, 2024
73a76dc
fee payments in whitelisted tokens
ZlayaMorda Oct 30, 2024
bcb2694
Merge branch 'master' into 1171-xorless-fee
ZlayaMorda Nov 11, 2024
f434441
main logic for xor-fee without tests
ZlayaMorda Nov 13, 2024
037e220
Merge branch 'master' into 1171-xorless-fee
ZlayaMorda Nov 18, 2024
7886525
mostly fixed xorless logic
ZlayaMorda Nov 18, 2024
69287c8
merge master into 1171-xorless-fee
ZlayaMorda Nov 19, 2024
1024891
tests and main logic of xorless
ZlayaMorda Nov 20, 2024
c4e2413
add migrations, benchmarks and weights
ZlayaMorda Nov 20, 2024
0d35937
update thiserror to 2v for std feature, update lock file
ZlayaMorda Nov 20, 2024
5b31e67
merge master into 1171-xorless-fee
ZlayaMorda Nov 20, 2024
25b891e
fix clippy issues
ZlayaMorda Nov 20, 2024
8a96d00
fix clippy issues and tests
ZlayaMorda Nov 21, 2024
ee5ebd7
fix clippy
ZlayaMorda Nov 21, 2024
796d496
change to fast price
ZlayaMorda Nov 21, 2024
1be3aa1
fix review issues
ZlayaMorda Nov 21, 2024
b4e7c6c
add fee estimation for xorless_call
ZlayaMorda Nov 22, 2024
8ae826d
simplify declaration of minimal fee, add description
ZlayaMorda Dec 3, 2024
07d8ea8
Merge branch 'master' into 1171-xorless-fee
ZlayaMorda Dec 3, 2024
254fe11
fix balance value
ZlayaMorda Dec 3, 2024
733fa90
fix balance value
ZlayaMorda Dec 3, 2024
2a71792
return error for not available call
ZlayaMorda Dec 4, 2024
4efecbc
Merge branch 'master' into 1171-xorless-fee
ZlayaMorda Dec 4, 2024
477f4e5
Merge branch 'master' into 1171-xorless-fee-ORIGINAL
ZlayaMorda Dec 4, 2024
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
253 changes: 137 additions & 116 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ frame-system = { git = "https://github.com/sora-xor/substrate.git", branch = "po
secp256k1 = { version = "0.7", features = [
'hmac',
], default-features = false, package = "libsecp256k1" }
thiserror = "1.0"
thiserror = { version = "2.0", default-features = false }
num-traits = { version = "0.2.12", default-features = false }
orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library.git", package = "orml-traits", default-features = false }
paste = "1.0.0"
Expand Down Expand Up @@ -73,6 +73,7 @@ std = [
'sp-std/std',
'currencies/std',
'orml-traits/std',
'thiserror/std',
]

test = ["env_logger"]
Expand Down
3 changes: 2 additions & 1 deletion common/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,8 @@ macro_rules! mock_currencies_config {
macro_rules! mock_demeter_farming_platform_config {
($runtime:ty, $demeter_asset_id:ty) => {
impl demeter_farming_platform::Config for $runtime {
const BLOCKS_PER_HOUR_AND_A_HALF: BlockNumberFor<Self> = 900;
const BLOCKS_PER_HOUR_AND_A_HALF: frame_system::pallet_prelude::BlockNumberFor<Self> =
900;
type AssetInfoProvider = assets::Pallet<Runtime>;
type DemeterAssetId = $demeter_asset_id;
type RuntimeEvent = RuntimeEvent;
Expand Down
14 changes: 13 additions & 1 deletion pallets/xor-fee/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,34 @@ sp-core = { git = "https://github.com/sora-xor/substrate.git", branch = "polkado
traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library.git", package = "orml-traits", default-features = false }
smallvec = "1.5.0"
common = { path = "../../common", default-features = false }
hex-literal = { version = "0.4.1"}

[dev-dependencies]
currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library.git", package = "orml-currencies" }
pallet-balances = { git = "https://github.com/sora-xor/substrate.git", branch = "polkadot-v0.9.38" }
pallet-timestamp = { git = "https://github.com/sora-xor/substrate.git", branch = "polkadot-v0.9.38" }
sp-core = { git = "https://github.com/sora-xor/substrate.git", branch = "polkadot-v0.9.38" }
sp-io = { git = "https://github.com/sora-xor/substrate.git", branch = "polkadot-v0.9.38" }
tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library.git", package = "orml-tokens" }
assets = { path = "../assets" }
common = { path = "../../common", features = ["test"] }
permissions = { path = "../permissions" }
price-tools = { path = "../price-tools", default-features = false }
pool-xyk = { path = "../pool-xyk", default-features = false }
pswap-distribution = { path = "../pswap-distribution", default-features = false }
dex-manager = { path = "../dex-manager", default-features = false }
trading-pair = { path = "../trading-pair", default-features = false }
demeter-farming-platform = { path = "../demeter-farming-platform", default-features = false }
ceres-liquidity-locker = { path = "../ceres-liquidity-locker", default-features = false }
technical = { path = "../technical", default-features = false }
tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library.git", package = "orml-tokens" }

[features]
default = ["std"]

std = [
"codec/std",
"dex-manager/std",
"demeter-farming-platform/std",
"scale-info/std",
"frame-support/std",
"frame-system/std",
Expand All @@ -67,6 +78,7 @@ runtime-benchmarks = [
"frame-benchmarking",
"frame-system/runtime-benchmarks",
"frame-support/runtime-benchmarks",
# "hex-literal", TODO: After applying migrations change to optional
]

try-runtime = [
Expand Down
51 changes: 47 additions & 4 deletions pallets/xor-fee/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,25 @@
#![cfg(feature = "runtime-benchmarks")]

use super::*;
use codec::Decode;

use common::balance;
#[cfg(feature = "wip")] // Dynamic fee
use crate::pallet::UpdatePeriod;
use crate::{Config, Pallet};
use common::{balance, AssetIdOf, VAL, XOR};
use frame_benchmarking::benchmarks;
use frame_support::sp_runtime::FixedU128;
use frame_system::RawOrigin;
use hex_literal::hex;
#[cfg(feature = "wip")] // Xorless fee
use sp_core::bounded::BoundedVec;
use sp_std::vec;
use traits::MultiCurrency;

#[cfg(feature = "wip")] // Dynamic fee
use crate::pallet::UpdatePeriod;
use crate::{Config, Pallet};
fn alice<T: Config>() -> T::AccountId {
let bytes = hex!("d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d");
T::AccountId::decode(&mut &bytes[..]).expect("Failed to decode account ID")
}

benchmarks! {
update_multiplier {
Expand All @@ -65,5 +75,38 @@ benchmarks! {
assert_eq!(<SmallReferenceAmount<T>>::get(), new_reference_amount);
}

xorless_call {
let caller = alice::<T>();
<T as common::Config>::MultiCurrency::deposit(XOR.into(), &caller, balance!(1))?;
let call: Box<<T as Config>::RuntimeCall> = Box::new(frame_system::Call::remark { remark: vec![] }.into());
let asset_id: AssetIdOf<T> = XOR.into();
}: _(RawOrigin::Signed(caller), call, Some(asset_id))

add_asset_to_white_list {}: _(RawOrigin::Root, VAL.into())
verify {
#[cfg(feature = "wip")] // Xorless fee
{
let mut white_list: BoundedVec<AssetIdOf<T>, T::MaxWhiteListTokens> = BoundedVec::default();
white_list.try_push(VAL.into()).expect("Error while push asset to bounded vec");
assert_eq!(<WhitelistTokensForFee<T>>::get(), white_list)
}
}
remove_asset_from_white_list {
#[cfg(feature = "wip")] // Xorless fee
WhitelistTokensForFee::<T>::try_mutate(|whitelist| {
whitelist
.try_push(VAL.into())
.map_err(|_| Error::<T>::WhitelistFull)?;
Ok::<(), Error<T>>(())
}).expect("Error while push asset to storage");
}: _(RawOrigin::Root, VAL.into())
verify {
#[cfg(feature = "wip")] // Xorless fee
{
let white_list: BoundedVec<AssetIdOf<T>, T::MaxWhiteListTokens> = BoundedVec::default();
assert_eq!(<WhitelistTokensForFee<T>>::get(), white_list)
}
}

impl_benchmark_test_suite!(Pallet, mock::ExtBuilder::build(), mock::Runtime);
}
Loading