-
Notifications
You must be signed in to change notification settings - Fork 23
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
Add market pallet #1119
Open
vovac12
wants to merge
3
commits into
master
Choose a base branch
from
marketplace
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add market pallet #1119
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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,60 @@ | ||
[package] | ||
edition = '2021' | ||
authors = ['Polka Biome Ltd. <jihoon@tutanota.de>'] | ||
license = "BSD-4-Clause" | ||
homepage = 'https://sora.org' | ||
repository = 'https://github.com/sora-xor/sora2-network' | ||
name = 'market' | ||
version = '1.0.1' | ||
|
||
[package.metadata.docs.rs] | ||
targets = ['x86_64-unknown-linux-gnu'] | ||
|
||
[dependencies] | ||
codec = { package = "parity-scale-codec", version = "3", default-features = false, features = [ | ||
"derive", | ||
] } | ||
scale-info = { version = "2", default-features = false, features = ["derive"] } | ||
frame-support = { git = "https://github.com/sora-xor/substrate.git", branch = "polkadot-v0.9.38", default-features = false } | ||
frame-system = { git = "https://github.com/sora-xor/substrate.git", branch = "polkadot-v0.9.38", default-features = false } | ||
frame-benchmarking = { git = "https://github.com/sora-xor/substrate.git", branch = "polkadot-v0.9.38", default-features = false, optional = true } | ||
sp-core = { git = "https://github.com/sora-xor/substrate.git", branch = "polkadot-v0.9.38", default-features = false } | ||
sp-runtime = { git = "https://github.com/sora-xor/substrate.git", branch = "polkadot-v0.9.38", default-features = false } | ||
sp-std = { git = "https://github.com/sora-xor/substrate.git", branch = "polkadot-v0.9.38", default-features = false } | ||
common = { path = "../../common", default-features = false } | ||
hex-literal = "0.4.1" | ||
traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library.git", package = "orml-traits", default-features = false } | ||
|
||
[dev-dependencies] | ||
sp-core = { git = "https://github.com/sora-xor/substrate.git", branch = "polkadot-v0.9.38", default-features = false } | ||
sp-io = { git = "https://github.com/sora-xor/substrate.git", branch = "polkadot-v0.9.38", default-features = false } | ||
sp-runtime = { version = "7.0.0", git = "https://github.com/sora-xor/substrate.git", branch = "polkadot-v0.9.38", default-features = false } | ||
pallet-balances = { git = "https://github.com/sora-xor/substrate.git", branch = "polkadot-v0.9.38" } | ||
currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library.git", package = "orml-currencies" } | ||
tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library.git", package = "orml-tokens", default-features = false } | ||
hex-literal = { version = "0.4.1"} | ||
common = { path = "../../common", features = ['test']} | ||
assets = { path = "../assets" } | ||
permissions = { path = "../permissions" } | ||
technical = { path = "../technical" } | ||
|
||
[features] | ||
default = ['std'] | ||
std = [ | ||
"codec/std", | ||
"scale-info/std", | ||
"frame-support/std", | ||
"frame-system/std", | ||
"sp-core/std", | ||
"sp-std/std", | ||
"sp-runtime/std", | ||
"traits/std", | ||
"common/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,193 @@ | ||
// This file is part of the SORA network and Polkaswap app. | ||
|
||
// Copyright (c) 2020, 2021, Polka Biome Ltd. All rights reserved. | ||
// SPDX-License-Identifier: BSD-4-Clause | ||
|
||
// Redistribution and use in source and binary forms, with or without modification, | ||
// are permitted provided that the following conditions are met: | ||
|
||
// Redistributions of source code must retain the above copyright notice, this list | ||
// of conditions and the following disclaimer. | ||
// Redistributions in binary form must reproduce the above copyright notice, this | ||
// list of conditions and the following disclaimer in the documentation and/or other | ||
// materials provided with the distribution. | ||
// | ||
// All advertising materials mentioning features or use of this software must display | ||
// the following acknowledgement: This product includes software developed by Polka Biome | ||
// Ltd., SORA, and Polkaswap. | ||
// | ||
// Neither the name of the Polka Biome Ltd. nor the names of its contributors may be used | ||
// to endorse or promote products derived from this software without specific prior written permission. | ||
|
||
// THIS SOFTWARE IS PROVIDED BY Polka Biome Ltd. AS IS AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Polka Biome Ltd. BE LIABLE FOR ANY | ||
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | ||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | ||
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
//! Market module benchmarking. | ||
|
||
#![cfg(feature = "runtime-benchmarks")] | ||
|
||
use super::*; | ||
|
||
use frame_benchmarking::benchmarks; | ||
use frame_system::RawOrigin; | ||
|
||
use common::{AssetManager, AssetName, AssetSymbol, DEFAULT_BALANCE_PRECISION}; | ||
|
||
fn asset_owner<T: Config>() -> T::AccountId { | ||
frame_benchmarking::account("owner", 0, 0) | ||
} | ||
|
||
fn buyer<T: Config>(i: u32) -> T::AccountId { | ||
frame_benchmarking::account("buyer", i, 0) | ||
} | ||
|
||
fn add_product<T: Config>(price_asset: AssetIdOf<T>) -> AssetIdOf<T> { | ||
let owner = asset_owner::<T>(); | ||
|
||
Pallet::<T>::create_new_product( | ||
owner, | ||
common::AssetName(b"PRODUCT".to_vec()), | ||
common::AssetSymbol(b"PRODUCT".to_vec()), | ||
common::Description(b"PRODUCT".to_vec()), | ||
common::ContentSource(b"PRODUCT".to_vec()), | ||
Product { | ||
price_asset, | ||
price: 100, | ||
extensions: vec![], | ||
}, | ||
) | ||
.expect("Failed to register product") | ||
} | ||
|
||
fn add_asset<T: Config>() -> AssetIdOf<T> { | ||
let owner = asset_owner::<T>(); | ||
frame_system::Pallet::<T>::inc_providers(&owner); | ||
|
||
T::AssetManager::register_from( | ||
&owner, | ||
AssetSymbol(b"TOKEN".to_vec()), | ||
AssetName(b"TOKEN".to_vec()), | ||
DEFAULT_BALANCE_PRECISION, | ||
10000, | ||
true, | ||
AssetType::Regular, | ||
None, | ||
None, | ||
) | ||
.expect("Failed to register asset") | ||
} | ||
|
||
benchmarks! { | ||
create_product { | ||
let owner = asset_owner::<T>(); | ||
let owner_origin: <T as frame_system::Config>::RuntimeOrigin = RawOrigin::Signed(owner).into(); | ||
let price_asset = add_asset::<T>(); | ||
let required_product = add_product::<T>(price_asset); | ||
let disallowed_product = add_product::<T>(price_asset); | ||
}: { | ||
Pallet::<T>::create_product(owner_origin, | ||
common::AssetName(b"PRODUCT".to_vec()), | ||
common::AssetSymbol(b"PRODUCT".to_vec()), | ||
common::Description(b"PRODUCT".to_vec()), | ||
common::ContentSource(b"PRODUCT".to_vec()), | ||
Product { | ||
price_asset, | ||
price: 100, | ||
extensions: vec![ | ||
Extension::Expirable(10u32.into()), | ||
Extension::MaxAmount(10), | ||
Extension::RequiredProduct(required_product, 1), | ||
Extension::DisallowedProduct(disallowed_product) | ||
], | ||
} | ||
).unwrap(); | ||
} | ||
|
||
buy { | ||
let owner = asset_owner::<T>(); | ||
let owner_origin: <T as frame_system::Config>::RuntimeOrigin = RawOrigin::Signed(owner.clone()).into(); | ||
let price_asset = add_asset::<T>(); | ||
let required_product = add_product::<T>(price_asset); | ||
let disallowed_product = add_product::<T>(price_asset); | ||
let product = Pallet::<T>::create_new_product(owner.clone(), | ||
common::AssetName(b"PRODUCT".to_vec()), | ||
common::AssetSymbol(b"PRODUCT".to_vec()), | ||
common::Description(b"PRODUCT".to_vec()), | ||
common::ContentSource(b"PRODUCT".to_vec()), | ||
Product { | ||
price_asset, | ||
price: 100, | ||
extensions: vec![ | ||
Extension::Expirable(10u32.into()), | ||
Extension::MaxAmount(10), | ||
Extension::RequiredProduct(required_product, 1), | ||
Extension::DisallowedProduct(disallowed_product) | ||
], | ||
} | ||
).unwrap(); | ||
Pallet::<T>::buy(owner_origin.clone(), required_product, 1).unwrap(); | ||
}: { | ||
Pallet::<T>::buy(owner_origin, product, 1).unwrap(); | ||
} | ||
verify { | ||
assert_eq!( | ||
T::AssetInfoProvider::total_balance(&product, &owner).unwrap(), | ||
1 | ||
); | ||
} | ||
|
||
on_initialize { | ||
let a in 1..50; | ||
let owner = asset_owner::<T>(); | ||
let owner_origin: <T as frame_system::Config>::RuntimeOrigin = RawOrigin::Signed(owner.clone()).into(); | ||
let price_asset = add_asset::<T>(); | ||
let product = Pallet::<T>::create_new_product(owner.clone(), | ||
common::AssetName(b"PRODUCT".to_vec()), | ||
common::AssetSymbol(b"PRODUCT".to_vec()), | ||
common::Description(b"PRODUCT".to_vec()), | ||
common::ContentSource(b"PRODUCT".to_vec()), | ||
Product { | ||
price_asset, | ||
price: 100, | ||
extensions: vec![ | ||
Extension::Expirable(10u32.into()), | ||
], | ||
} | ||
).unwrap(); | ||
for i in 0..a { | ||
let buyer = buyer::<T>(i); | ||
let buyer_origin: <T as frame_system::Config>::RuntimeOrigin = RawOrigin::Signed(buyer.clone()).into(); | ||
T::AssetManager::mint_unchecked(&price_asset, &buyer, 1000).unwrap(); | ||
Pallet::<T>::buy(buyer_origin, product, 1).unwrap(); | ||
assert_eq!( | ||
T::AssetInfoProvider::total_balance(&product, &buyer).unwrap(), | ||
1 | ||
); | ||
} | ||
frame_system::Pallet::<T>::set_block_number(frame_system::Pallet::<T>::block_number() + 10u32.into()); | ||
}: { | ||
Pallet::<T>::on_initialize(frame_system::Pallet::<T>::block_number()); | ||
} | ||
verify { | ||
assert_eq!(Expirations::<T>::iter().collect::<Vec<_>>(), vec![]); | ||
for i in 0..a { | ||
let buyer = buyer::<T>(i); | ||
assert_eq!( | ||
T::AssetInfoProvider::total_balance(&product, &buyer).unwrap(), | ||
0 | ||
); | ||
} | ||
} | ||
|
||
impl_benchmark_test_suite!( | ||
Pallet, | ||
crate::mock::new_test_ext(), | ||
crate::mock::Runtime | ||
); | ||
} |
Oops, something went wrong.
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.
Check failure
Code scanning / clippy
redundant clone Error