This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
feat: pallet asset-rate #13608
Merged
paritytech-processbot
merged 21 commits into
paritytech:master
from
wischli:feat/treasury-oracle
Apr 19, 2023
Merged
feat: pallet asset-rate #13608
Changes from 13 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
8996e05
poc
wischli 8a07bc0
fix: remove AssetIdParameter
wischli 47443ec
tests: add
wischli 8d3ddee
docs: add pallet description
wischli 109a321
feat: add benches
wischli 4a0fca4
refactor: UnknownAssetId
wischli d78f6cb
Merge remote-tracking branch 'origin/master' into feat/treasury-oracle
wischli 719364f
fix: normalize mock cfg
wischli 0adf951
fix: benchmarks
wischli ffb6d95
chore: add weights
wischli 301ddb2
refactor: remove storage getter
wischli 7153a2c
chore: apply suggestions from code review
wischli fdeefbd
docs: add native balance to calls
wischli 65df23e
chore: apply suggestions from code review
wischli acf046b
Merge remote-tracking branch 'origin/master' into feat/treasury-oracle
58cc428
chore: apply ConversionFromAssetBalance
wischli 44a9f6a
tests: update balance mock
wischli 03acddb
chore: apply suggestions from code review
wischli 1f14c39
ci: set publish to false
wischli 329b846
docs: fix missing rustdoc
wischli 57c5c6f
Merge remote-tracking branch 'origin/master' into feat/treasury-oracle
wischli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,51 @@ | ||
| [package] | ||
| 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 <[email protected]>"] | ||
| homepage = "https://substrate.io" | ||
| edition = "2021" | ||
| license = "Unlicense" | ||
| repository = "https://github.com/paritytech/substrate/" | ||
|
|
||
| [package.metadata.docs.rs] | ||
| targets = ["x86_64-unknown-linux-gnu"] | ||
|
|
||
| [dependencies] | ||
| codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = [ | ||
| "derive", | ||
| ] } | ||
| scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } | ||
| frame-benchmarking = { version = "4.0.0-dev", default-features = false, optional = true, path = "../benchmarking" } | ||
| frame-support = { version = "4.0.0-dev", default-features = false, path = "../support" } | ||
| frame-system = { version = "4.0.0-dev", default-features = false, path = "../system" } | ||
| sp-runtime = { version = "7.0.0", default-features = false, path = "../../primitives/runtime" } | ||
| sp-std = { version = "5.0.0", default-features = false, path = "../../primitives/std" } | ||
|
|
||
| [dev-dependencies] | ||
| pallet-balances = { version = "4.0.0-dev", path = "../balances" } | ||
| sp-core = { version = "7.0.0", path = "../../primitives/core" } | ||
| sp-io = { version = "7.0.0", path = "../../primitives/io" } | ||
|
|
||
| [features] | ||
| default = ["std"] | ||
| std = [ | ||
| "codec/std", | ||
| "frame-benchmarking?/std", | ||
| "frame-support/std", | ||
| "frame-system/std", | ||
| "scale-info/std", | ||
| "sp-runtime/std", | ||
| "sp-std/std", | ||
| ] | ||
| runtime-benchmarks = [ | ||
| "frame-benchmarking/runtime-benchmarks", | ||
| "frame-support/runtime-benchmarks", | ||
| "frame-system/runtime-benchmarks", | ||
| "sp-runtime/runtime-benchmarks", | ||
| ] | ||
| try-runtime = [ | ||
| "frame-support/try-runtime", | ||
| "frame-system/try-runtime", | ||
| "sp-runtime/try-runtime", | ||
| ] | ||
This file contains hidden or 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,86 @@ | ||
| // This file is part of Substrate. | ||
|
|
||
| // Copyright (C) Parity Technologies (UK) Ltd. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // 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. | ||
|
|
||
| //! The crate's benchmarks. | ||
|
|
||
| use super::*; | ||
| use crate::{pallet as pallet_asset_rate, Pallet as AssetRate}; | ||
|
|
||
| use frame_benchmarking::v2::*; | ||
| use frame_support::assert_ok; | ||
| use frame_system::RawOrigin; | ||
|
|
||
| const ASSET_ID: u32 = 1; | ||
|
|
||
| fn default_conversion_rate() -> FixedU128 { | ||
| FixedU128::from_u32(1u32) | ||
| } | ||
|
|
||
| #[benchmarks(where <T as Config>::AssetId: From<u32>)] | ||
| mod benchmarks { | ||
| use super::*; | ||
|
|
||
| #[benchmark] | ||
| fn create() -> Result<(), BenchmarkError> { | ||
| let asset_id: T::AssetId = ASSET_ID.into(); | ||
| #[extrinsic_call] | ||
| _(RawOrigin::Root, asset_id, default_conversion_rate()); | ||
|
|
||
| assert_eq!( | ||
| pallet_asset_rate::ConversionRateToNative::<T>::get(asset_id), | ||
| Some(default_conversion_rate()) | ||
| ); | ||
| Ok(()) | ||
| } | ||
|
|
||
| #[benchmark] | ||
| fn update() -> Result<(), BenchmarkError> { | ||
| let asset_id: T::AssetId = ASSET_ID.into(); | ||
| assert_ok!(AssetRate::<T>::create( | ||
| RawOrigin::Root.into(), | ||
| asset_id, | ||
| default_conversion_rate() | ||
| )); | ||
|
|
||
| #[extrinsic_call] | ||
| _(RawOrigin::Root, asset_id, FixedU128::from_u32(2)); | ||
|
|
||
| assert_eq!( | ||
| pallet_asset_rate::ConversionRateToNative::<T>::get(asset_id), | ||
| Some(FixedU128::from_u32(2)) | ||
| ); | ||
| Ok(()) | ||
| } | ||
|
|
||
| #[benchmark] | ||
| fn remove() -> Result<(), BenchmarkError> { | ||
| let asset_id: T::AssetId = ASSET_ID.into(); | ||
| assert_ok!(AssetRate::<T>::create( | ||
| RawOrigin::Root.into(), | ||
| ASSET_ID.into(), | ||
| default_conversion_rate() | ||
| )); | ||
|
|
||
| #[extrinsic_call] | ||
| _(RawOrigin::Root, asset_id); | ||
|
|
||
| assert!(pallet_asset_rate::ConversionRateToNative::<T>::get(asset_id).is_none()); | ||
| Ok(()) | ||
| } | ||
|
|
||
| impl_benchmark_test_suite! { AssetRate, crate::mock::new_test_ext(), crate::mock::Test } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.