-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #973 from galacticcouncil/dispatcher
feat: dispatch as Treasury or AAVEManager from OpenGov
- Loading branch information
Showing
25 changed files
with
1,043 additions
and
22 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
Oops, something went wrong.