Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
chore: apply suggestions from code review
  • Loading branch information
wischli committed Apr 3, 2023
commit 7153a2c98f37fe8588c4863bd3ff1b37978ba202
34 changes: 17 additions & 17 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ members = [
"frame/transaction-payment/rpc/runtime-api",
"frame/transaction-storage",
"frame/treasury",
"frame/treasury-oracle",
"frame/asset-rate",
"frame/tips",
"frame/uniques",
"frame/utility",
Expand Down
8 changes: 4 additions & 4 deletions bin/node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ frame-election-provider-support = { version = "4.0.0-dev", default-features = fa
frame-system-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, path = "../../../frame/system/rpc/runtime-api/" }
frame-try-runtime = { version = "0.10.0-dev", default-features = false, path = "../../../frame/try-runtime", optional = true }
pallet-alliance = { version = "4.0.0-dev", default-features = false, path = "../../../frame/alliance" }
pallet-asset-rate = { version = "4.0.0-dev", default-features = false, path = "../../../frame/asset-rate" }
pallet-assets = { version = "4.0.0-dev", default-features = false, path = "../../../frame/assets" }
pallet-authority-discovery = { version = "4.0.0-dev", default-features = false, path = "../../../frame/authority-discovery" }
pallet-authorship = { version = "4.0.0-dev", default-features = false, path = "../../../frame/authorship" }
Expand Down Expand Up @@ -110,7 +111,6 @@ pallet-sudo = { version = "4.0.0-dev", default-features = false, path = "../../.
pallet-timestamp = { version = "4.0.0-dev", default-features = false, path = "../../../frame/timestamp" }
pallet-tips = { version = "4.0.0-dev", default-features = false, path = "../../../frame/tips" }
pallet-treasury = { version = "4.0.0-dev", default-features = false, path = "../../../frame/treasury" }
pallet-treasury-oracle = { version = "4.0.0-dev", default-features = false, path = "../../../frame/treasury-oracle" }
pallet-utility = { version = "4.0.0-dev", default-features = false, path = "../../../frame/utility" }
pallet-transaction-payment = { version = "4.0.0-dev", default-features = false, path = "../../../frame/transaction-payment" }
pallet-transaction-payment-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, path = "../../../frame/transaction-payment/rpc/runtime-api/" }
Expand Down Expand Up @@ -202,7 +202,7 @@ std = [
"pallet-transaction-payment/std",
"pallet-transaction-storage/std",
"pallet-treasury/std",
"pallet-treasury-oracle/std",
"pallet-asset-rate/std",
"sp-transaction-pool/std",
"pallet-utility/std",
"sp-version/std",
Expand Down Expand Up @@ -274,7 +274,7 @@ runtime-benchmarks = [
"pallet-tips/runtime-benchmarks",
"pallet-transaction-storage/runtime-benchmarks",
"pallet-treasury/runtime-benchmarks",
"pallet-treasury-oracle/runtime-benchmarks",
"pallet-asset-rate/runtime-benchmarks",
"pallet-utility/runtime-benchmarks",
"pallet-uniques/runtime-benchmarks",
"pallet-nfts/runtime-benchmarks",
Expand Down Expand Up @@ -336,7 +336,7 @@ try-runtime = [
"pallet-timestamp/try-runtime",
"pallet-tips/try-runtime",
"pallet-treasury/try-runtime",
"pallet-treasury-oracle/try-runtime",
"pallet-asset-rate/try-runtime",
"pallet-utility/try-runtime",
"pallet-transaction-payment/try-runtime",
"pallet-asset-tx-payment/try-runtime",
Expand Down
8 changes: 4 additions & 4 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1114,15 +1114,15 @@ impl pallet_treasury::Config for Runtime {
type SpendOrigin = EnsureWithSuccess<EnsureRoot<AccountId>, AccountId, MaxBalance>;
}

impl pallet_treasury_oracle::Config for Runtime {
impl pallet_asset_rate::Config for Runtime {
type CreateOrigin = EnsureRoot<AccountId>;
type RemoveOrigin = EnsureRoot<AccountId>;
type UpdateOrigin = EnsureRoot<AccountId>;
type Balance = Balance;
type Currency = Balances;
type AssetId = u32;
type RuntimeEvent = RuntimeEvent;
type WeightInfo = pallet_treasury_oracle::weights::SubstrateWeight<Runtime>;
type WeightInfo = pallet_asset_rate::weights::SubstrateWeight<Runtime>;
}

parameter_types! {
Expand Down Expand Up @@ -1769,7 +1769,7 @@ construct_runtime!(
TechnicalMembership: pallet_membership::<Instance1>,
Grandpa: pallet_grandpa,
Treasury: pallet_treasury,
TreasuryOracle: pallet_treasury_oracle,
AssetRate: pallet_asset_rate,
Contracts: pallet_contracts,
Sudo: pallet_sudo,
ImOnline: pallet_im_online,
Expand Down Expand Up @@ -1927,7 +1927,7 @@ mod benches {
[pallet_tips, Tips]
[pallet_transaction_storage, TransactionStorage]
[pallet_treasury, Treasury]
[pallet_treasury_oracle, TreasuryOracle]
[pallet_asset_rate, AssetRate]
[pallet_uniques, Uniques]
[pallet_nfts, Nfts]
[pallet_utility, Utility]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "pallet-treasury-oracle"
name = "pallet-asset-rate"
version = "4.0.0-dev"
description = "Whitelist non-native assets for treasury spending and provide conversion to native balance"
authors = ["William Freudenberger <w.freude@icloud.com>"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
//! The crate's benchmarks.

use super::*;
use crate::{pallet as pallet_treasury_oracle, Pallet as TreasuryOracle};
use crate::{pallet as pallet_asset_rate, Pallet as AssetRate};

use frame_benchmarking::v2::*;
use frame_support::assert_ok;
Expand All @@ -41,7 +41,7 @@ mod benchmarks {
_(RawOrigin::Root, asset_id, default_conversion_rate());

assert_eq!(
pallet_treasury_oracle::ConversionRateToNative::<T>::get(asset_id),
pallet_asset_rate::ConversionRateToNative::<T>::get(asset_id),
Some(default_conversion_rate())
);
Ok(())
Expand All @@ -50,7 +50,7 @@ mod benchmarks {
#[benchmark]
fn update() -> Result<(), BenchmarkError> {
let asset_id: T::AssetId = ASSET_ID.into();
assert_ok!(TreasuryOracle::<T>::create(
assert_ok!(AssetRate::<T>::create(
RawOrigin::Root.into(),
asset_id,
default_conversion_rate()
Expand All @@ -60,7 +60,7 @@ mod benchmarks {
_(RawOrigin::Root, asset_id, FixedU128::from_u32(2));

assert_eq!(
pallet_treasury_oracle::ConversionRateToNative::<T>::get(asset_id),
pallet_asset_rate::ConversionRateToNative::<T>::get(asset_id),
Some(FixedU128::from_u32(2))
);
Ok(())
Expand All @@ -69,7 +69,7 @@ mod benchmarks {
#[benchmark]
fn remove() -> Result<(), BenchmarkError> {
let asset_id: T::AssetId = ASSET_ID.into();
assert_ok!(TreasuryOracle::<T>::create(
assert_ok!(AssetRate::<T>::create(
RawOrigin::Root.into(),
ASSET_ID.into(),
default_conversion_rate()
Expand All @@ -78,9 +78,9 @@ mod benchmarks {
#[extrinsic_call]
_(RawOrigin::Root, asset_id);

assert!(pallet_treasury_oracle::ConversionRateToNative::<T>::get(asset_id).is_none());
assert!(pallet_asset_rate::ConversionRateToNative::<T>::get(asset_id).is_none());
Ok(())
}

impl_benchmark_test_suite! { TreasuryOracle, crate::mock::new_test_ext(), crate::mock::Test }
impl_benchmark_test_suite! { AssetRate, crate::mock::new_test_ext(), crate::mock::Test }
}
25 changes: 12 additions & 13 deletions frame/treasury-oracle/src/lib.rs → frame/asset-rate/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//! # Treasury Oracle Pallet
//!
//! A simple oracle pallet for the treasury.
//! # Asset Rate Pallet
//!
//! - [`Config`]
//! - [`Call`]
//!
//! ## Overview
//!
//! The TreasuryOracle pallet provides means of setting conversion rates
//! The AssetRate pallet provides means of setting conversion rates
//! for some asset to native balance.
//!
//! The supported dispatchable functions are documented in the [`Call`] enum.
Expand All @@ -39,7 +37,7 @@
//!
//! ### Goals
//!
//! The treasury-oracle system in Substrate is designed to make the following possible:
//! The asset-rate system in Substrate is designed to make the following possible:
//!
//! * Whitelisting assets other than the native currency which can be accepted for Treasury spends.
//! * Providing a soft conversion for the balance of whitelisted assets to native.
Expand Down Expand Up @@ -139,11 +137,11 @@ pub mod pallet {
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
// Some `asset_id` conversion rate was created.
Created { asset_id: T::AssetId, rate: FixedU128 },
AssetRateCreated { asset_id: T::AssetId, rate: FixedU128 },
// Some `asset_id` conversion rate was removed.
Removed { asset_id: T::AssetId },
AssetRateRemoved { asset_id: T::AssetId },
// Some existing `asset_id` conversion rate was updated from `old` to `new`.
Updated { asset_id: T::AssetId, old: FixedU128, new: FixedU128 },
AssetRateUpdated { asset_id: T::AssetId, old: FixedU128, new: FixedU128 },
}

#[pallet::error]
Expand Down Expand Up @@ -175,11 +173,11 @@ pub mod pallet {
);
ConversionRateToNative::<T>::set(asset_id, Some(rate));

Self::deposit_event(Event::Created { asset_id, rate });
Self::deposit_event(Event::AssetRateCreated { asset_id, rate });
Ok(())
}

/// Remove the conversion rate for the given asset.
/// Update the conversion rate for the given asset.
///
/// ## Complexity
/// - O(1)
Expand All @@ -204,11 +202,11 @@ pub mod pallet {
}
})?;

Self::deposit_event(Event::Updated { asset_id, old, new: rate });
Self::deposit_event(Event::AssetRateUpdated { asset_id, old, new: rate });
Ok(())
}

/// Update an existing conversion rate for the given asset.
/// Remove an existing conversion rate for the given asset.
///
/// ## Complexity
/// - O(1)
Expand All @@ -223,13 +221,14 @@ pub mod pallet {
);
ConversionRateToNative::<T>::remove(asset_id);

Self::deposit_event(Event::Removed { asset_id });
Self::deposit_event(Event::AssetRateRemoved { asset_id });
Ok(())
}
}
}

// Exposes conversion of an arbitrary balance of an asset to native balance.
// TODO: Switch to `AssetBalanceToBalance` after merging Substrate #13610
impl<T> BalanceConversion<BalanceOf<T>, AssetIdOf<T>, BalanceOf<T>> for Pallet<T>
where
T: Config,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

//! The crate's mock.

use crate as pallet_treasury_oracle;
use crate as pallet_asset_rate;
use frame_support::traits::{ConstU16, ConstU64};
use sp_core::H256;
use sp_runtime::{
Expand All @@ -35,7 +35,7 @@ frame_support::construct_runtime!(
UncheckedExtrinsic = UncheckedExtrinsic,
{
System: frame_system,
TreasuryOracle: pallet_treasury_oracle,
AssetRate: pallet_asset_rate,
Balances: pallet_balances,
}
);
Expand Down Expand Up @@ -79,7 +79,7 @@ impl pallet_balances::Config for Test {
type ReserveIdentifier = [u8; 8];
}

impl pallet_treasury_oracle::Config for Test {
impl pallet_asset_rate::Config for Test {
type WeightInfo = ();
type RuntimeEvent = RuntimeEvent;
type CreateOrigin = frame_system::EnsureRoot<u64>;
Expand Down
Loading