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: dispatch as Treasury or AAVEManager from OpenGov #973

Merged
merged 34 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
9a3798d
dispatcher pallet base with mock weights
vgantchev Dec 3, 2024
971c454
heal std
vgantchev Dec 3, 2024
d4175c7
add possibility to dispatch call (without preimage)
vgantchev Dec 9, 2024
0d1b8f8
add benchmarks
vgantchev Dec 10, 2024
5cc2215
fmt
vgantchev Dec 10, 2024
f3bdbad
start benchmarks
vgantchev Dec 13, 2024
c1bb1b1
add aave
vgantchev Dec 13, 2024
e20b2e1
Merge branch 'opengov' into dispatcher
vgantchev Dec 16, 2024
3a075ac
buildable
vgantchev Dec 29, 2024
45ee509
benchmarks
vgantchev Dec 29, 2024
cbca5ae
add OpenGov track EconomicParameters as AaveManagerOrigin
vgantchev Dec 29, 2024
af30e2f
format
vgantchev Dec 29, 2024
ea47f94
Merge branch 'master' into dispatcher
vgantchev Dec 29, 2024
451b697
bump runtime version
vgantchev Dec 29, 2024
057849a
rename to dispatch_as_treasury
vgantchev Dec 29, 2024
ee4cc47
update README
vgantchev Dec 29, 2024
43fbb69
versions
vgantchev Dec 29, 2024
763a7bf
weights from reference machine
vgantchev Dec 29, 2024
bb4d491
update code docs
vgantchev Dec 29, 2024
e3e9544
Merge branch 'master' into dispatcher
vgantchev Jan 14, 2025
9bbc194
clippy
vgantchev Jan 14, 2025
8bc6f60
update economic_parameters track
vgantchev Jan 14, 2025
f89e817
clippy
vgantchev Jan 15, 2025
5d6f2df
wip
mrq1911 Jan 21, 2025
d6d74cf
integration tests
mrq1911 Jan 21, 2025
5a8a4eb
imports
mrq1911 Jan 21, 2025
b95917c
refactor + benchmarks
mrq1911 Jan 21, 2025
9a06ea7
clippy
mrq1911 Jan 21, 2025
057fc0c
klippy
mrq1911 Jan 21, 2025
bd87d22
fix bench
mrq1911 Jan 21, 2025
9d3d3da
revert
mrq1911 Jan 21, 2025
83e5660
de klippy
mrq1911 Jan 21, 2025
c944279
weights
mrq1911 Jan 22, 2025
84e560b
Merge branch 'refs/heads/master' into dispatcher
mrq1911 Jan 22, 2025
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
25 changes: 23 additions & 2 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 @@ -119,6 +119,7 @@ pallet-collator-rewards = { path = "pallets/collator-rewards", default-features
pallet-currencies = { path = "pallets/currencies", default-features = false }
pallet-currencies-rpc-runtime-api = { path = "pallets/currencies/rpc/runtime-api", default-features = false }
pallet-dca = { path = "pallets/dca", default-features = false }
pallet-dispatcher = { path = "pallets/dispatcher", default-features = false }
pallet-duster = { path = "pallets/duster", default-features = false }
pallet-dynamic-fees = { path = "pallets/dynamic-fees", default-features = false }
pallet-dynamic-evm-fee = { path = "pallets/dynamic-evm-fee", default-features = false }
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ coverage:

.PHONY: clippy
clippy:
$(cargo) clippy --release --locked --all-targets -- -D warnings -A deprecated
$(cargo) clippy --release --locked --all-targets -- -A deprecated

.PHONY: clippy-all
clippy-all:
$(cargo) clippy --release --locked --all-targets --all-features -- -D warnings -A deprecated
$(cargo) clippy --release --locked --all-targets --all-features -- -A deprecated

.PHONY: format
format:
Expand Down
2 changes: 2 additions & 0 deletions integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ pallet-elections-phragmen = { workspace = true }
pallet-tips = { workspace = true }
pallet-referenda = { workspace = true }
pallet-conviction-voting = { workspace = true }
pallet-dispatcher = { workspace = true }

# collator support
pallet-collator-selection = { workspace = true }
Expand Down Expand Up @@ -215,6 +216,7 @@ std = [
"pallet-transaction-pause/std",
"pallet-liquidation/std",
"pallet-broadcast/std",
"pallet-dispatcher/std",
]

# we don't include integration tests when benchmarking feature is enabled
Expand Down
84 changes: 84 additions & 0 deletions integration-tests/src/dispatcher.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
use crate::polkadot_test_net::*;
use frame_support::assert_ok;
use hydradx_runtime::evm::WethAssetId;
use hydradx_runtime::*;
use primitives::EvmAddress;
use sp_core::Get;
use sp_core::{ByteArray, U256};
use test_utils::last_events;
use xcm_emulator::TestExt;

fn testnet_manager_address() -> EvmAddress {
hex!["52341e77341788Ebda44C8BcB4C8BD1B1913B204"].into()
}

fn pad_to_32_bytes(bytes: &[u8]) -> [u8; 32] {
let mut padded = [0u8; 32];
padded[..bytes.len()].copy_from_slice(bytes);
padded
}

fn testnet_manager() -> AccountId {
pad_to_32_bytes(testnet_manager_address().as_bytes()).into()
}

#[test]
fn testnet_aave_manager_can_be_set_as_dispatcher() {
TestNet::reset();
Hydra::execute_with(|| {
assert_eq!(
hydradx_runtime::Dispatcher::aave_manager_account(),
pad_to_32_bytes(hex!["aa7e0000000000000000000000000000000aa7e0"].as_ref()).into()
);
assert_ok!(hydradx_runtime::Dispatcher::note_aave_manager(
hydradx_runtime::RuntimeOrigin::root(),
testnet_manager()
));
assert_eq!(hydradx_runtime::Dispatcher::aave_manager_account(), testnet_manager());
});
}

#[test]
fn dispatch_as_aave_admin_can_modify_supply_cap_on_testnet() {
TestNet::reset();
Hydra::execute_with(|| {
assert_ok!(hydradx_runtime::Dispatcher::note_aave_manager(
hydradx_runtime::RuntimeOrigin::root(),
testnet_manager()
));
assert_ok!(hydradx_runtime::Tokens::set_balance(
hydradx_runtime::RuntimeOrigin::root(),
EVMAccounts::account_id(testnet_manager_address()),
WethAssetId::get(),
1_000_000_000_000_000_000u128,
0
));
let set_cap_data = hex!["571f03e50000000000000000000000000000000000000000000000000000000100000005000000000000000000000000000000000000000000000000000000000006c81c"].into();
let call = Box::new(RuntimeCall::EVM(pallet_evm::Call::call {
source: EvmAddress::from_slice(&testnet_manager().as_slice()[0..20]),
target: hex!["5AFf8be73B6AA6890DaCe9483a6AE9CEfA002795"].into(),
input: set_cap_data,
gas_limit: 100_000,
value: U256::zero(),
max_fee_per_gas: U256::from(233_460_000),
max_priority_fee_per_gas: None,
nonce: None,
access_list: vec![],
}));
assert_ok!(Dispatcher::dispatch_as_aave_manager(
RuntimeOrigin::root(),
call.clone()
));
let event = last_events::<RuntimeEvent, Runtime>(1)
.into_iter()
.take(1)
.next()
.unwrap();
match event {
RuntimeEvent::Dispatcher(pallet_dispatcher::Event::AaveManagerCallDispatched {
result: Ok(..), ..
}) => {}
_ => panic!("Unexpected event: {:?}", event),
}
});
}
9 changes: 3 additions & 6 deletions integration-tests/src/exchange_asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@ use frame_support::traits::fungible::Balanced;
use frame_support::traits::tokens::Precision;
use frame_support::weights::Weight;
use frame_support::{assert_ok, pallet_prelude::*};
use hydradx_runtime::Omnipool;
use hydradx_runtime::AssetRegistry;
use hydradx_runtime::Router;
use hydradx_runtime::RuntimeEvent;
use hydradx_runtime::RuntimeOrigin;
use hydradx_runtime::TempAccountForXcmAssetExchange;
use hydradx_runtime::{AssetRegistry, LRNA};
use hydradx_traits::AssetKind;
use hydradx_traits::Create;
use orml_traits::currency::MultiCurrency;
Expand Down Expand Up @@ -157,7 +154,7 @@ fn hydra_should_swap_assets_when_receiving_from_acala_with_sell() {
RuntimeOrigin::signed(ALICE.into()),
HDX,
ACA,
1 * UNITS,
UNITS,
0,
vec![],
));
Expand Down Expand Up @@ -1193,7 +1190,7 @@ fn half(asset: &Asset) -> Asset {
id: asset.clone().id,
}
}
use pallet_broadcast::types::{ExecutionType, Fee};
use pallet_broadcast::types::ExecutionType;
use rococo_runtime::xcm_config::BaseXcmWeight;
use xcm_builder::FixedWeightBounds;
use xcm_executor::traits::WeightBounds;
Expand Down
1 change: 1 addition & 0 deletions integration-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ mod circuit_breaker;
mod contracts;
mod cross_chain_transfer;
mod dca;
mod dispatcher;
mod driver;
mod dust;
mod dust_removal_whitelist;
Expand Down
6 changes: 2 additions & 4 deletions integration-tests/src/referrals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,7 @@ fn trading_in_omnipool_should_use_asset_rewards_when_set() {
outputs: vec![Asset::new(LRNA, 1205768843)],
fees: vec![Fee::new(LRNA, 602884, Destination::Burned)],
operation_stack: vec![ExecutionType::Omnipool(0)],
}
.into(),
},
pallet_broadcast::Event::Swapped {
swapper: BOB.into(),
filler: Omnipool::protocol_account(),
Expand All @@ -354,8 +353,7 @@ fn trading_in_omnipool_should_use_asset_rewards_when_set() {
Fee::new(DAI, 9168140377593, Destination::Account(Referrals::pot_account_id()))
],
operation_stack: vec![ExecutionType::Omnipool(0)],
}
.into(),
},
]
);
});
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/src/utility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use pallet_broadcast::types::Destination;
use crate::assert_balance;
use hydradx_runtime::LBP;
use hydradx_runtime::XYK;
use hydradx_runtime::{Currencies, Omnipool, Runtime, RuntimeEvent};
use hydradx_runtime::{Currencies, Omnipool, Runtime};
use hydradx_runtime::{RuntimeCall, Utility};
use hydradx_traits::router::PoolType;
use pallet_broadcast::types::Asset;
Expand Down
2 changes: 0 additions & 2 deletions integration-tests/src/xcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ use sp_runtime::codec::Encode;

use crate::assert_operation_stack;
use frame_support::dispatch::GetDispatchInfo;
use hydradx_runtime::Omnipool;
use hydradx_runtime::RuntimeEvent;
use orml_traits::MultiCurrency;
use pallet_broadcast::types::ExecutionType;
use polkadot_xcm::v4::prelude::*;
Expand Down
56 changes: 56 additions & 0 deletions pallets/dispatcher/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
[package]
name = "pallet-dispatcher"
version = "1.0.0"
authors = ['GalacticCouncil']
edition = "2021"
license = "Apache-2.0"
homepage = 'https://github.com/galacticcouncil/hydration-node'
repository = 'https://github.com/galacticcouncil/hydration-node'
description = "Pallet for dispatching calls as specific origins"
readme = "README.md"

[dependencies]
# parity
codec = { workspace = true, features = ["derive", "max-encoded-len"] }
scale-info = { workspace = true }

# primitives
sp-runtime = { workspace = true }
sp-std = { workspace = true }
sp-core = { workspace = true }

# FRAME
frame-support = { workspace = true }
frame-system = { workspace = true }

# Optional imports for benchmarking
frame-benchmarking = { workspace = true, optional = true }

[dev-dependencies]
sp-io = { workspace = true }
hydradx-traits = { workspace = true }
orml-tokens = { workspace = true }
orml-traits = { workspace = true }
test-utils = { workspace = true }

[features]
default = ['std']
std = [
'codec/std',
'scale-info/std',
'sp-runtime/std',
'sp-core/std',
'sp-io/std',
'sp-std/std',
'frame-benchmarking/std',
'hydradx-traits/std',
'orml-tokens/std',
'orml-traits/std',
]

runtime-benchmarks = [
"frame-benchmarking",
"frame-system/runtime-benchmarks",
"frame-support/runtime-benchmarks",
]
try-runtime = ["frame-support/try-runtime"]
6 changes: 6 additions & 0 deletions pallets/dispatcher/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Dispatcher Pallet
This pallet enables specific OpenGov tracks to dispatch Runtime calls as predefined origins.

The pallet supports the following dispatchables:
* `dispatch_as_treasury` - allows the `Treasury` track to dispatch calls as the Treasury account on Hydration (`7L53bUTBopuwFt3mKUfmkzgGLayYa1Yvn1hAg9v5UMrQzTfh`)
* `dispatch_as_aave_manager` - allows the `EconomicParameters` track to dispatch calls as the Money Market authority on Hydration (`add addr`)
57 changes: 57 additions & 0 deletions pallets/dispatcher/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// This file is part of https://github.com/galacticcouncil/*
//
// $$$$$$$ Licensed under the Apache License, Version 2.0 (the "License")
// $$$$$$$$$$$$$ you may only use this file in compliance with the License
// $$$$$$$$$$$$$$$$$$$
// $$$$$$$$$ Copyright (C) 2021-2024 Intergalactic, Limited (GIB)
// $$$$$$$$$$$ $$$$$$$$$$ SPDX-License-Identifier: Apache-2.0
// $$$$$$$$$$$$$$$$$$$$$$$$$$
// $$$$$$$$$$$$$$$$$$$$$$$ $ Built with <3 for decentralisation
// $$$$$$$$$$$$$$$$$$$ $$$$$$$
// $$$$$$$ $$$$$$$$$$$$$$$$$$ 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.
// $$$$$$$
// $$
// $$$$$ $$$$$ $$ $
// $$$ $$$ $$$ $$ $$$$$ $$ $$$ $$$$ $$$$$$$ $$$$ $$$ $$$$$$ $$ $$$$$$
// $$$ $$$ $$$ $$ $$$ $$$ $$$ $ $$ $$ $$ $$ $$ $$ $$$ $$$
// $$$$$$$$$$$ $$ $$ $$$ $$ $$ $$$$$$$ $$ $$ $$ $$$ $$ $$
// $$$ $$$ $$$$ $$$ $$ $$ $$$ $$ $$ $$ $$ $$ $$ $$
// $$$$$ $$$$$ $$ $$$$$$$$ $ $$$ $$$$$$$$ $$$ $$$$ $$$$$$$ $$$$ $$$$
// $$$

use super::*;

use frame_benchmarking::benchmarks;
use frame_system::RawOrigin;
use sp_std::boxed::Box;

benchmarks! {
where_clause { where
T: crate::Config,
}

dispatch_as_treasury {
let n in 1 .. 10_000;
let remark = sp_std::vec![1u8; n as usize];

let call: <T as pallet::Config>::RuntimeCall = frame_system::Call::remark { remark }.into();
}: _(RawOrigin::Root, Box::new(call))

dispatch_as_aave_manager {
let n in 1 .. 10_000;
let remark = sp_std::vec![1u8; n as usize];

let call: <T as pallet::Config>::RuntimeCall = frame_system::Call::remark { remark }.into();
}: _(RawOrigin::Root, Box::new(call))

note_aave_manager {
}: _(RawOrigin::Root, Pallet::<T>::aave_manager_account())

impl_benchmark_test_suite!(Pallet, crate::mock::ExtBuilder::default().build(), crate::mock::Test);
}
Loading
Loading