::Randomness::random_seed().0.encode();
59 | log::trace!(
60 | target: "runtime",
61 | "[ChainExtension]|call|func_id:{:}",
62 | func_id
63 | );
64 | env.write(&random_slice, false, None)
65 | .map_err(|_| DispatchError::Other("ChainExtension failed to call random"))?;
66 |
67 | Ok(RetVal::Converging(0))
68 | },
69 | // 0x10001-0x10040(65537-65600): token-fungible
70 | id if id >= 65537 && id < 65600 => FungibleTokenExtension::call(func_id, env),
71 |
72 | // // 0x10041-0x10080(65601-65664): token-non-fungible
73 | // id if id >= 65601 && id < 65664 => NonFungibleTokenExtension::call(func_id, env),
74 | //
75 | // // 0x10081-0x100c1(65665-65729): token-multi
76 | // id if id >= 65665 && id < 65729 => MultiTokenExtension::call(func_id, env),
77 | _ => {
78 | log::error!("call an unregistered `func_id`, func_id:{:}", func_id);
79 | return Err(DispatchError::Other("Unimplemented func_id"))
80 | },
81 | }
82 | }
83 |
84 | fn enabled() -> bool {
85 | true
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/client/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | [](https://github.com/web3gamesofficial/web3games-blockchain/actions)
8 | [](https://github.com/web3gamesofficial/web3games-blockchain/blob/main/LICENSE)
9 | [](https://twitter.com/web3games)
10 | [](https://discord.gg/web3games)
11 | [](https://blog.web3games.com/)
12 |
13 |
14 |
15 | ## 1. Introduction
16 | Web3Games Chain Node Client File.
--------------------------------------------------------------------------------
/docker-compose.yml:
--------------------------------------------------------------------------------
1 | version: "3.2"
2 |
3 | services:
4 | dev:
5 | container_name: web3games-node
6 | image: paritytech/ci-linux:002c04ad-20211021
7 | working_dir: /var/www/web3games-node
8 | ports:
9 | - "9944:9944"
10 | environment:
11 | - CARGO_HOME=/var/www/web3games-node/.cargo
12 | volumes:
13 | - .:/var/www/web3games-node
14 | - type: bind
15 | source: ./.local
16 | target: /root/.local
17 | command: bash -c "cargo build --release && ./target/release/web3games-node --dev --ws-external"
18 |
--------------------------------------------------------------------------------
/docker/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | [](https://github.com/web3gamesofficial/web3games-blockchain/actions)
8 | [](https://github.com/web3gamesofficial/web3games-blockchain/blob/main/LICENSE)
9 | [](https://twitter.com/web3games)
10 | [](https://discord.gg/web3games)
11 | [](https://blog.web3games.com/)
12 |
13 |
14 |
15 | ## 1. Introduction
16 | Web3Games Chain Image Container File.
--------------------------------------------------------------------------------
/media/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | [](https://github.com/web3gamesofficial/web3games-blockchain/actions)
8 | [](https://github.com/web3gamesofficial/web3games-blockchain/blob/main/LICENSE)
9 | [](https://twitter.com/web3games)
10 | [](https://discord.gg/web3games)
11 | [](https://blog.web3games.com/)
12 |
13 |
14 |
15 | ## 1. Introduction
16 | Web3Games Chain Media Brand Resource File.
--------------------------------------------------------------------------------
/node/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | [](https://github.com/web3gamesofficial/web3games-blockchain/actions)
8 | [](https://github.com/web3gamesofficial/web3games-blockchain/blob/main/LICENSE)
9 | [](https://twitter.com/web3games)
10 | [](https://discord.gg/web3games)
11 | [](https://blog.web3games.com/)
12 |
13 |
14 |
15 | ## 1. Introduction
16 | Web3Games Chain Node File.
--------------------------------------------------------------------------------
/node/build.rs:
--------------------------------------------------------------------------------
1 | // This file is part of Web3Games.
2 |
3 | // Copyright (C) 2021-2022 Web3Games https://web3games.org
4 | // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
5 |
6 | // This program is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published by
8 | // the Free Software Foundation, either version 3 of the License, or
9 | // (at your option) any later version.
10 |
11 | // This program is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 |
16 | // You should have received a copy of the GNU General Public License
17 | // along with this program. If not, see .
18 |
19 | use substrate_build_script_utils::{generate_cargo_keys, rerun_if_git_head_changed};
20 |
21 | fn main() {
22 | generate_cargo_keys();
23 |
24 | rerun_if_git_head_changed();
25 | }
26 |
--------------------------------------------------------------------------------
/node/src/cli.rs:
--------------------------------------------------------------------------------
1 | // This file is part of Web3Games.
2 |
3 | // Copyright (C) 2021-2022 Web3Games https://web3games.org
4 | // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
5 |
6 | // This program is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published by
8 | // the Free Software Foundation, either version 3 of the License, or
9 | // (at your option) any later version.
10 |
11 | // This program is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 |
16 | // You should have received a copy of the GNU General Public License
17 | // along with this program. If not, see .
18 |
19 | #[cfg(feature = "manual-seal")]
20 | #[derive(Debug, Copy, Clone, clap::ArgEnum)]
21 | pub enum Sealing {
22 | // Seal using rpc method.
23 | Manual,
24 | // Seal when transaction is executed.
25 | Instant,
26 | }
27 |
28 | #[cfg(feature = "manual-seal")]
29 | impl Default for Sealing {
30 | fn default() -> Sealing {
31 | Sealing::Manual
32 | }
33 | }
34 |
35 | #[allow(missing_docs)]
36 | #[derive(Debug, clap::Parser)]
37 | pub struct RunCmd {
38 | #[allow(missing_docs)]
39 | #[clap(flatten)]
40 | pub base: sc_cli::RunCmd,
41 |
42 | /// Choose sealing method.
43 | #[cfg(feature = "manual-seal")]
44 | #[clap(long, arg_enum, ignore_case = true)]
45 | pub sealing: Sealing,
46 |
47 | #[clap(long)]
48 | pub enable_dev_signer: bool,
49 |
50 | /// Maximum number of logs in a query.
51 | #[clap(long, default_value = "10000")]
52 | pub max_past_logs: u32,
53 |
54 | /// Maximum fee history cache size.
55 | #[clap(long, default_value = "2048")]
56 | pub fee_history_limit: u64,
57 |
58 | /// The dynamic-fee pallet target gas price set by block author
59 | #[clap(long, default_value = "1")]
60 | pub target_gas_price: u64,
61 | }
62 |
63 | #[derive(Debug, clap::Parser)]
64 | pub struct Cli {
65 | #[clap(subcommand)]
66 | pub subcommand: Option,
67 |
68 | #[clap(flatten)]
69 | pub run: RunCmd,
70 |
71 | /// Disable automatic hardware benchmarks.
72 | ///
73 | /// By default these benchmarks are automatically ran at startup and measure
74 | /// the CPU speed, the memory bandwidth and the disk speed.
75 | ///
76 | /// The results are then printed out in the logs, and also sent as part of
77 | /// telemetry, if telemetry is enabled.
78 | #[clap(long)]
79 | pub no_hardware_benchmarks: bool,
80 | }
81 |
82 | #[derive(Debug, clap::Subcommand)]
83 | pub enum Subcommand {
84 | /// Key management cli utilities
85 | #[clap(subcommand)]
86 | Key(sc_cli::KeySubcommand),
87 |
88 | /// Build a chain specification.
89 | BuildSpec(sc_cli::BuildSpecCmd),
90 |
91 | /// Validate blocks.
92 | CheckBlock(sc_cli::CheckBlockCmd),
93 |
94 | /// Export blocks.
95 | ExportBlocks(sc_cli::ExportBlocksCmd),
96 |
97 | /// Export the state of a given block into a chain spec.
98 | ExportState(sc_cli::ExportStateCmd),
99 |
100 | /// Import blocks.
101 | ImportBlocks(sc_cli::ImportBlocksCmd),
102 |
103 | /// Remove the whole chain.
104 | PurgeChain(sc_cli::PurgeChainCmd),
105 |
106 | /// Revert the chain to a previous state.
107 | Revert(sc_cli::RevertCmd),
108 |
109 | /// Sub-commands concerned with benchmarking.
110 | #[clap(subcommand)]
111 | Benchmark(frame_benchmarking_cli::BenchmarkCmd),
112 | }
113 |
--------------------------------------------------------------------------------
/node/src/command_helper.rs:
--------------------------------------------------------------------------------
1 | // This file is part of Web3Games.
2 |
3 | // Copyright (C) 2021-2022 Web3Games https://web3games.org
4 | // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
5 |
6 | // This program is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published by
8 | // the Free Software Foundation, either version 3 of the License, or
9 | // (at your option) any later version.
10 |
11 | // This program is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 |
16 | // You should have received a copy of the GNU General Public License
17 | // along with this program. If not, see .
18 |
19 | //! Contains code to setup the command invocations in [`super::command`] which would
20 | //! otherwise bloat that module.
21 |
22 | use crate::service::FullClient;
23 |
24 | use runtime::SystemCall;
25 | use sc_cli::Result;
26 | use sc_client_api::BlockBackend;
27 | use sp_core::{Encode, Pair};
28 | use sp_inherents::{InherentData, InherentDataProvider};
29 | use sp_keyring::Sr25519Keyring;
30 | use sp_runtime::{OpaqueExtrinsic, SaturatedConversion};
31 | use web3games_runtime as runtime;
32 |
33 | use std::{sync::Arc, time::Duration};
34 |
35 | /// Generates extrinsics for the `benchmark overhead` command.
36 | ///
37 | /// Note: Should only be used for benchmarking.
38 | pub struct BenchmarkExtrinsicBuilder {
39 | client: Arc,
40 | }
41 |
42 | impl BenchmarkExtrinsicBuilder {
43 | /// Creates a new [`Self`] from the given client.
44 | pub fn new(client: Arc) -> Self {
45 | Self { client }
46 | }
47 | }
48 |
49 | impl frame_benchmarking_cli::ExtrinsicBuilder for BenchmarkExtrinsicBuilder {
50 | fn remark(&self, nonce: u32) -> std::result::Result {
51 | let acc = Sr25519Keyring::Bob.pair();
52 | let extrinsic: OpaqueExtrinsic = create_benchmark_extrinsic(
53 | self.client.as_ref(),
54 | acc,
55 | SystemCall::remark { remark: vec![] }.into(),
56 | nonce,
57 | )
58 | .into();
59 |
60 | Ok(extrinsic)
61 | }
62 | }
63 |
64 | /// Create a transaction using the given `call`.
65 | ///
66 | /// Note: Should only be used for benchmarking.
67 | pub fn create_benchmark_extrinsic(
68 | client: &FullClient,
69 | sender: sp_core::sr25519::Pair,
70 | call: runtime::Call,
71 | nonce: u32,
72 | ) -> runtime::UncheckedExtrinsic {
73 | let genesis_hash = client.block_hash(0).ok().flatten().expect("Genesis block exists; qed");
74 | let best_hash = client.chain_info().best_hash;
75 | let best_block = client.chain_info().best_number;
76 |
77 | let period = runtime::BlockHashCount::get()
78 | .checked_next_power_of_two()
79 | .map(|c| c / 2)
80 | .unwrap_or(2) as u64;
81 | let extra: runtime::SignedExtra = (
82 | frame_system::CheckNonZeroSender::::new(),
83 | frame_system::CheckSpecVersion::::new(),
84 | frame_system::CheckTxVersion::::new(),
85 | frame_system::CheckGenesis::::new(),
86 | frame_system::CheckEra::::from(sp_runtime::generic::Era::mortal(
87 | period,
88 | best_block.saturated_into(),
89 | )),
90 | frame_system::CheckNonce::::from(nonce),
91 | frame_system::CheckWeight::::new(),
92 | pallet_transaction_payment::ChargeTransactionPayment::::from(0),
93 | );
94 |
95 | let raw_payload = runtime::SignedPayload::from_raw(
96 | call.clone(),
97 | extra.clone(),
98 | (
99 | (),
100 | runtime::VERSION.spec_version,
101 | runtime::VERSION.transaction_version,
102 | genesis_hash,
103 | best_hash,
104 | (),
105 | (),
106 | (),
107 | ),
108 | );
109 | let signature = raw_payload.using_encoded(|e| sender.sign(e));
110 |
111 | runtime::UncheckedExtrinsic::new_signed(
112 | call.clone(),
113 | sp_runtime::AccountId32::from(sender.public()).into(),
114 | runtime::Signature::Sr25519(signature.clone()),
115 | extra.clone(),
116 | )
117 | }
118 |
119 | /// Generates inherent data for the `benchmark overhead` command.
120 | ///
121 | /// Note: Should only be used for benchmarking.
122 | pub fn inherent_benchmark_data() -> Result {
123 | let mut inherent_data = InherentData::new();
124 | let d = Duration::from_millis(0);
125 | let timestamp = sp_timestamp::InherentDataProvider::new(d.into());
126 |
127 | timestamp
128 | .provide_inherent_data(&mut inherent_data)
129 | .map_err(|e| format!("creating inherent data: {:?}", e))?;
130 | Ok(inherent_data)
131 | }
132 |
--------------------------------------------------------------------------------
/node/src/main.rs:
--------------------------------------------------------------------------------
1 | // This file is part of Web3Games.
2 |
3 | // Copyright (C) 2021-2022 Web3Games https://web3games.org
4 | // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
5 |
6 | // This program is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published by
8 | // the Free Software Foundation, either version 3 of the License, or
9 | // (at your option) any later version.
10 |
11 | // This program is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 |
16 | // You should have received a copy of the GNU General Public License
17 | // along with this program. If not, see .
18 |
19 | //! Web3Games Node CLI library.
20 |
21 | #![warn(missing_docs)]
22 |
23 | mod chain_spec;
24 | #[macro_use]
25 | mod service;
26 | mod cli;
27 | mod command;
28 | mod command_helper;
29 | mod rpc;
30 |
31 | fn main() -> sc_cli::Result<()> {
32 | command::run()
33 | }
34 |
--------------------------------------------------------------------------------
/pallets/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | [](https://github.com/web3gamesofficial/web3games-blockchain/actions)
8 | [](https://github.com/web3gamesofficial/web3games-blockchain/blob/main/LICENSE)
9 | [](https://twitter.com/web3games)
10 | [](https://discord.gg/web3games)
11 | [](https://blog.web3games.com/)
12 |
13 |
14 |
15 | ## 1. Introduction
16 |
17 | The main modules of the Web3Games chain are used for the public business layer to provide open capabilities,
18 | and the production module that has passed the security audit
--------------------------------------------------------------------------------
/pallets/call-switchgear/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "web3games-call-switchgear"
3 | version = "0.1.0"
4 | authors = ["Web3Games Developers"]
5 | edition = "2021"
6 |
7 | [dependencies]
8 | serde = { version = "1.0.137", optional = true }
9 | codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] }
10 | sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false }
11 | frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false }
12 | frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false }
13 | frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false, optional = true }
14 | sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false }
15 | sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false }
16 | scale-info = { version = "2.1.2", default-features = false, features = ["derive"] }
17 |
18 | [dev-dependencies]
19 | sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" }
20 | pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" }
21 | primitives = { path = "../../primitives"}
22 | smallvec = "1.9.0"
23 |
24 |
25 | [features]
26 | default = ["std"]
27 | std = [
28 | "serde",
29 | "codec/std",
30 | "sp-runtime/std",
31 | "frame-support/std",
32 | "frame-system/std",
33 | "sp-io/std",
34 | "sp-std/std",
35 | "scale-info/std",
36 | ]
37 | try-runtime = ["frame-support/try-runtime"]
38 |
39 | runtime-benchmarks = [
40 | "frame-benchmarking",
41 | "frame-support/runtime-benchmarks",
42 | "frame-system/runtime-benchmarks",
43 | ]
44 |
45 |
--------------------------------------------------------------------------------
/pallets/call-switchgear/src/benchmarking.rs:
--------------------------------------------------------------------------------
1 | //! Benchmarking setup for pallet-template
2 |
3 | #![cfg(feature = "runtime-benchmarks")]
4 |
5 | use super::*;
6 | use crate::Pallet as CallSwitchgear;
7 | use frame_benchmarking::{account, benchmarks};
8 | use frame_support::assert_ok;
9 | use frame_system::RawOrigin;
10 |
11 | benchmarks! {
12 | switchoff_transaction {
13 | let alice: T::AccountId = account("alice", 0, 0);
14 | }: _(RawOrigin::Root,
15 | b"Balances".to_vec(),
16 | b"transfer".to_vec()
17 | )
18 | verify {
19 | assert_eq!(CallSwitchgear::::get_switchoff_transactions((b"Balances".to_vec(),b"transfer".to_vec())),Some(()));
20 | }
21 |
22 | switchon_transaction {
23 | let alice: T::AccountId = account("alice", 0, 0);
24 | assert_ok!(CallSwitchgear::::switchoff_transaction(
25 | RawOrigin::Root.into(),
26 | b"Balances".to_vec(),
27 | b"transfer".to_vec()
28 | ));
29 | assert_eq!(
30 | CallSwitchgear::::get_switchoff_transactions((
31 | b"Balances".to_vec(),
32 | b"transfer".to_vec()
33 | )),
34 | Some(())
35 | );
36 | }: _(RawOrigin::Root,
37 | b"Balances".to_vec(),
38 | b"transfer".to_vec()
39 | )
40 | verify {
41 | assert_eq!(CallSwitchgear::::get_switchoff_transactions((b"Balances".to_vec(),b"transfer".to_vec())),None);
42 | }
43 |
44 |
45 | impl_benchmark_test_suite!(CallSwitchgear, crate::mock::new_test_ext(), crate::mock::Test);
46 | }
47 |
--------------------------------------------------------------------------------
/pallets/call-switchgear/src/mock.rs:
--------------------------------------------------------------------------------
1 | // This file is part of Web3Games.
2 |
3 | // Copyright (C) 2021-2022 Web3Games https://web3games.org
4 | // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
5 |
6 | // This program is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published by
8 | // the Free Software Foundation, either version 3 of the License, or
9 | // (at your option) any later version.
10 |
11 | // This program is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 |
16 | // You should have received a copy of the GNU General Public License
17 | // along with this program. If not, see .
18 |
19 | #![cfg(test)]
20 |
21 | use frame_support::{construct_runtime, parameter_types};
22 | use primitives::Balance;
23 | use sp_core::H256;
24 | use sp_runtime::{testing::Header, traits::IdentityLookup};
25 |
26 | type AccountId = u128;
27 |
28 | use super::*;
29 |
30 | use crate as web3games_call_switchgear;
31 |
32 | pub const MILLICENTS: Balance = 10_000_000_000_000;
33 | pub const CENTS: Balance = 1_000 * MILLICENTS; // assume this is worth about a cent.
34 | pub const DOLLARS: Balance = 100 * CENTS;
35 |
36 | parameter_types! {
37 | pub const BlockHashCount: u64 = 250;
38 | }
39 |
40 | impl frame_system::Config for Test {
41 | type Origin = Origin;
42 | type Index = u64;
43 | type BlockNumber = u64;
44 | type Call = Call;
45 | type Hash = H256;
46 | type Hashing = ::sp_runtime::traits::BlakeTwo256;
47 | type AccountId = AccountId;
48 | type Lookup = IdentityLookup;
49 | type Header = Header;
50 | type Event = Event;
51 | type BlockHashCount = BlockHashCount;
52 | type BlockWeights = ();
53 | type BlockLength = ();
54 | type Version = ();
55 | type PalletInfo = PalletInfo;
56 | type AccountData = pallet_balances::AccountData;
57 | type OnNewAccount = ();
58 | type OnKilledAccount = ();
59 | type DbWeight = ();
60 | type BaseCallFilter = frame_support::traits::Everything;
61 | type SystemWeightInfo = ();
62 | type SS58Prefix = ();
63 | type OnSetCode = ();
64 | type MaxConsumers = frame_support::traits::ConstU32<16>;
65 | }
66 |
67 | parameter_types! {
68 | pub const NativeTokenExistentialDeposit: Balance = 10;
69 | pub const MaxReserves: u32 = 50;
70 | }
71 |
72 | impl pallet_balances::Config for Test {
73 | type Balance = Balance;
74 | type DustRemoval = ();
75 | type Event = Event;
76 | type ExistentialDeposit = NativeTokenExistentialDeposit;
77 | type AccountStore = System;
78 | type MaxLocks = ();
79 | type MaxReserves = MaxReserves;
80 | type ReserveIdentifier = ();
81 | type WeightInfo = ();
82 | }
83 |
84 | impl web3games_call_switchgear::Config for Test {
85 | type Event = Event;
86 | type WeightInfo = ();
87 | }
88 |
89 | type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic;
90 | type Block = frame_system::mocking::MockBlock;
91 |
92 | construct_runtime!(
93 | pub enum Test where
94 | Block = Block,
95 | NodeBlock = Block,
96 | UncheckedExtrinsic = UncheckedExtrinsic
97 | {
98 | System: frame_system::{Pallet, Call, Config, Storage, Event},
99 | CallSwitchgear: web3games_call_switchgear::{Pallet, Storage, Call, Event},
100 | Balances: pallet_balances::{Pallet, Storage, Call, Event},
101 | }
102 | );
103 |
104 | // Build genesis storage according to the mock runtime.
105 | pub fn new_test_ext() -> sp_io::TestExternalities {
106 | let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap();
107 | pallet_balances::GenesisConfig:: {
108 | balances: vec![(1, 100 * DOLLARS), (2, 100 * DOLLARS)],
109 | }
110 | .assimilate_storage(&mut t)
111 | .unwrap();
112 | let mut ext = sp_io::TestExternalities::new(t);
113 | ext.execute_with(|| System::set_block_number(1));
114 | ext
115 | }
116 |
--------------------------------------------------------------------------------
/pallets/call-switchgear/src/tests.rs:
--------------------------------------------------------------------------------
1 | // This file is part of Web3Games.
2 |
3 | // Copyright (C) 2021-2022 Web3Games https://web3games.org
4 | // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
5 |
6 | // This program is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published by
8 | // the Free Software Foundation, either version 3 of the License, or
9 | // (at your option) any later version.
10 |
11 | // This program is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 |
16 | // You should have received a copy of the GNU General Public License
17 | // along with this program. If not, see .
18 |
19 | #![cfg(test)]
20 |
21 | use frame_support::{assert_noop, assert_ok};
22 | use mock::{Event, *};
23 | use sp_runtime::traits::BadOrigin;
24 |
25 | use super::*;
26 |
27 | #[test]
28 | fn switchoff_transaction_should_work() {
29 | new_test_ext().execute_with(|| {
30 | assert_noop!(
31 | CallSwitchgear::switchoff_transaction(
32 | Origin::signed(5),
33 | b"Balances".to_vec(),
34 | b"transfer".to_vec()
35 | ),
36 | BadOrigin
37 | );
38 |
39 | assert_eq!(
40 | CallSwitchgear::get_switchoff_transactions((
41 | b"Balances".to_vec(),
42 | b"transfer".to_vec()
43 | )),
44 | None
45 | );
46 | assert_ok!(CallSwitchgear::switchoff_transaction(
47 | Origin::root(),
48 | b"Balances".to_vec(),
49 | b"transfer".to_vec()
50 | ));
51 | System::assert_last_event(Event::CallSwitchgear(crate::Event::TransactionSwitchedoff(
52 | b"Balances".to_vec(),
53 | b"transfer".to_vec(),
54 | )));
55 | assert_eq!(
56 | CallSwitchgear::get_switchoff_transactions((
57 | b"Balances".to_vec(),
58 | b"transfer".to_vec()
59 | )),
60 | Some(())
61 | );
62 |
63 | assert_noop!(
64 | CallSwitchgear::switchoff_transaction(
65 | Origin::root(),
66 | b"CallSwitchgear".to_vec(),
67 | b"switchoff_transaction".to_vec()
68 | ),
69 | Error::::CannotSwitchOff
70 | );
71 | assert_noop!(
72 | CallSwitchgear::switchoff_transaction(
73 | Origin::root(),
74 | b"CallSwitchgear".to_vec(),
75 | b"some_other_call".to_vec()
76 | ),
77 | Error::::CannotSwitchOff
78 | );
79 | assert_ok!(CallSwitchgear::switchoff_transaction(
80 | Origin::root(),
81 | b"OtherPallet".to_vec(),
82 | b"switchoff_transaction".to_vec()
83 | ));
84 | });
85 | }
86 |
87 | #[test]
88 | fn switchon_transaction_transaction_should_work() {
89 | new_test_ext().execute_with(|| {
90 | System::set_block_number(1);
91 |
92 | assert_ok!(CallSwitchgear::switchoff_transaction(
93 | Origin::root(),
94 | b"Balances".to_vec(),
95 | b"transfer".to_vec()
96 | ));
97 | assert_eq!(
98 | CallSwitchgear::get_switchoff_transactions((
99 | b"Balances".to_vec(),
100 | b"transfer".to_vec()
101 | )),
102 | Some(())
103 | );
104 |
105 | assert_noop!(
106 | CallSwitchgear::switchoff_transaction(
107 | Origin::signed(5),
108 | b"Balances".to_vec(),
109 | b"transfer".to_vec()
110 | ),
111 | BadOrigin
112 | );
113 |
114 | assert_ok!(CallSwitchgear::switchon_transaction(
115 | Origin::root(),
116 | b"Balances".to_vec(),
117 | b"transfer".to_vec()
118 | ));
119 | System::assert_last_event(Event::CallSwitchgear(crate::Event::TransactionSwitchedOn(
120 | b"Balances".to_vec(),
121 | b"transfer".to_vec(),
122 | )));
123 | assert_eq!(
124 | CallSwitchgear::get_switchoff_transactions((
125 | b"Balances".to_vec(),
126 | b"transfer".to_vec()
127 | )),
128 | None
129 | );
130 |
131 | assert_eq!(CallSwitchgear::get_overall_indicator(), false);
132 |
133 | assert_ok!(CallSwitchgear::switchoff_transaction(
134 | Origin::root(),
135 | b"All".to_vec(),
136 | b"transfer".to_vec()
137 | ));
138 |
139 | assert_eq!(CallSwitchgear::get_overall_indicator(), true);
140 |
141 | assert_ok!(CallSwitchgear::switchon_transaction(
142 | Origin::root(),
143 | b"All".to_vec(),
144 | b"transfer".to_vec()
145 | ));
146 |
147 | assert_eq!(CallSwitchgear::get_overall_indicator(), false);
148 | });
149 | }
150 |
--------------------------------------------------------------------------------
/pallets/call-switchgear/src/weights.rs:
--------------------------------------------------------------------------------
1 | // This file is part of Web3Games.
2 |
3 | // Copyright (C) 2021-2022 Web3Games https://web3games.org
4 | // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
5 |
6 | // This program is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published by
8 | // the Free Software Foundation, either version 3 of the License, or
9 | // (at your option) any later version.
10 |
11 | // This program is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 |
16 | // You should have received a copy of the GNU General Public License
17 | // along with this program. If not, see .
18 |
19 | //! Autogenerated weights for web3games_call_switchgear
20 | //!
21 | //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
22 | //! DATE: 2022-12-22, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
23 | //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024
24 |
25 | // Executed Command:
26 | // target/release/web3games-node
27 | // benchmark
28 | // pallet
29 | // --chain=dev
30 | // --steps=50
31 | // --repeat=20
32 | // --pallet=web3games_call_switchgear
33 | // --extrinsic=*
34 | // --execution=wasm
35 | // --wasm-execution=compiled
36 | // --output=./pallets/call-switchgear/src/weights.rs
37 | // --template=./.maintain/w3g-weight-template.hbs
38 |
39 | #![cfg_attr(rustfmt, rustfmt_skip)]
40 | #![allow(unused_parens)]
41 | #![allow(unused_imports)]
42 | #![allow(clippy::unnecessary_cast)]
43 |
44 | use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
45 | use sp_std::marker::PhantomData;
46 |
47 | /// Weight functions needed for web3games_call_switchgear.
48 | pub trait WeightInfo {
49 | fn switchoff_transaction() -> Weight;
50 | fn switchon_transaction() -> Weight;
51 | }
52 |
53 | /// Weights for web3games_call_switchgear using the Web3Games node and recommended hardware.
54 | pub struct W3GWeight(PhantomData);
55 | impl WeightInfo for W3GWeight {
56 | // Storage: CallSwitchgear SwitchedOffTransactions (r:1 w:1)
57 | fn switchoff_transaction() -> Weight {
58 | (14_000_000 as Weight)
59 | .saturating_add(T::DbWeight::get().reads(1 as Weight))
60 | .saturating_add(T::DbWeight::get().writes(1 as Weight))
61 | }
62 | // Storage: CallSwitchgear SwitchedOffTransactions (r:1 w:1)
63 | fn switchon_transaction() -> Weight {
64 | (14_000_000 as Weight)
65 | .saturating_add(T::DbWeight::get().reads(1 as Weight))
66 | .saturating_add(T::DbWeight::get().writes(1 as Weight))
67 | }
68 | }
69 |
70 | // For backwards compatibility and tests
71 | impl WeightInfo for () {
72 | fn switchoff_transaction() -> Weight {
73 | (14_000_000 as Weight)
74 | .saturating_add(RocksDbWeight::get().reads(1 as Weight))
75 | .saturating_add(RocksDbWeight::get().writes(1 as Weight))
76 | }
77 | fn switchon_transaction() -> Weight {
78 | (14_000_000 as Weight)
79 | .saturating_add(RocksDbWeight::get().reads(1 as Weight))
80 | .saturating_add(RocksDbWeight::get().writes(1 as Weight))
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/pallets/ethereum-chain-id/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "web3games-ethereum-chain-id"
3 | version = "0.1.0"
4 | authors = ["Web3Games Developers"]
5 | edition = "2021"
6 |
7 | [dependencies]
8 | serde = { version = "1.0.137", optional = true, features = [ "derive" ] }
9 |
10 | # Substrate
11 | frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false }
12 | frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false }
13 | parity-scale-codec = { version = "3.0.0", default-features = false, features = [ "derive" ] }
14 | scale-info = { version = "2.1.2", default-features = false, features = [ "derive" ] }
15 |
16 | [features]
17 | default = [ "std" ]
18 | std = [
19 | "frame-support/std",
20 | "frame-system/std",
21 | "parity-scale-codec/std",
22 | "scale-info/std",
23 | "serde",
24 | ]
25 | try-runtime = [ "frame-support/try-runtime" ]
26 |
--------------------------------------------------------------------------------
/pallets/ethereum-chain-id/src/lib.rs:
--------------------------------------------------------------------------------
1 | // This file is part of Web3Games.
2 |
3 | // Copyright (C) 2021-2022 Web3Games https://web3games.org
4 | // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
5 |
6 | // This program is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published by
8 | // the Free Software Foundation, either version 3 of the License, or
9 | // (at your option) any later version.
10 |
11 | // This program is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 |
16 | // You should have received a copy of the GNU General Public License
17 | // along with this program. If not, see .
18 |
19 | #![cfg_attr(not(feature = "std"), no_std)]
20 |
21 | pub use pallet::*;
22 |
23 | #[frame_support::pallet]
24 | pub mod pallet {
25 |
26 | use frame_support::pallet_prelude::*;
27 |
28 | /// The Ethereum Chain Id Pallet
29 | #[pallet::pallet]
30 | pub struct Pallet(_);
31 |
32 | /// Configuration trait of this pallet.
33 | #[pallet::config]
34 | pub trait Config: frame_system::Config {}
35 |
36 | impl Get for Pallet {
37 | fn get() -> u64 {
38 | Self::chain_id()
39 | }
40 | }
41 |
42 | #[pallet::storage]
43 | #[pallet::getter(fn chain_id)]
44 | pub type ChainId = StorageValue<_, u64, ValueQuery>;
45 |
46 | #[pallet::genesis_config]
47 | #[derive(Default)]
48 | pub struct GenesisConfig {
49 | pub chain_id: u64,
50 | }
51 |
52 | #[pallet::genesis_build]
53 | impl GenesisBuild for GenesisConfig {
54 | fn build(&self) {
55 | ChainId::::put(self.chain_id);
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/pallets/exchange/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "web3games-exchange"
3 | version = "0.1.0"
4 | authors = ["Web3Games Developers"]
5 | edition = "2021"
6 |
7 | [dependencies]
8 | codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] }
9 | scale-info = { version = "2.1.2", default-features = false, features = ["derive"] }
10 |
11 | log = { version = "0.4.17", default-features = false }
12 | integer-sqrt = "0.1.2"
13 | frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" , default-features = false }
14 | frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" , default-features = false }
15 | sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" , default-features = false }
16 | sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" , default-features = false }
17 | sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" , default-features = false }
18 | pallet-timestamp = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" , default-features = false }
19 | pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false }
20 | sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" , default-features = false }
21 | frame-benchmarking = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true , branch = "polkadot-v0.9.26" }
22 |
23 | primitives = { path = "../../primitives", default-features = false }
24 | web3games-token-fungible = { path = "../token-fungible", default-features = false }
25 | web3games-wrap-currency = { path = "../wrap-currency", default-features = false }
26 |
27 | [dev-dependencies]
28 | pallet-randomness-collective-flip = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" }
29 |
30 | [features]
31 | default = ["std"]
32 | std = [
33 | "codec/std",
34 | "scale-info/std",
35 | "log/std",
36 | "frame-support/std",
37 | "frame-system/std",
38 | "frame-benchmarking/std",
39 | "sp-std/std",
40 | "sp-io/std",
41 | "sp-runtime/std",
42 | "pallet-timestamp/std",
43 | "pallet-balances/std",
44 | "sp-core/std",
45 | "primitives/std",
46 | "web3games-token-fungible/std",
47 | "web3games-wrap-currency/std",
48 | ]
49 | runtime-benchmarks = ["frame-benchmarking"]
50 |
51 |
--------------------------------------------------------------------------------
/pallets/exchange/rpc/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "web3games-exchange-rpc"
3 | version = "0.1.0"
4 | authors = ["Web3Games Developers"]
5 | edition = "2021"
6 |
7 | [dependencies]
8 | codec = { package = "parity-scale-codec", version = "3.0.0" }
9 | jsonrpsee = { version = "0.14.0", features = ["server", "macros"] }
10 | sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" }
11 | sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" }
12 | sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" }
13 | sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" }
14 | sp-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" }
15 | pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" }
16 | web3games-exchange-rpc-runtime-api = { path = "./runtime-api", default-features = false }
17 | primitives = { path = "../../../primitives", default-features = false }
18 |
19 | [features]
20 | default = ["std"]
21 | std = [
22 | "codec/std",
23 | "sp-api/std",
24 | "sp-runtime/std",
25 | "sp-core/std",
26 | "pallet-transaction-payment-rpc-runtime-api/std",
27 | "web3games-exchange-rpc-runtime-api/std",
28 | "primitives/std",
29 | ]
30 |
--------------------------------------------------------------------------------
/pallets/exchange/rpc/runtime-api/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "web3games-exchange-rpc-runtime-api"
3 | version = "0.1.0"
4 | authors = ["Web3Games Developers"]
5 | edition = "2021"
6 |
7 | [dependencies]
8 | codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] }
9 | sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false }
10 | sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false }
11 | web3games-exchange = { path = "../../../exchange", default-features = false }
12 | web3games-token-fungible = { path = "../../../token-fungible", default-features = false }
13 | primitives = { path = "../../../../primitives", default-features = false }
14 |
15 | [features]
16 | default = ["std"]
17 | std = [
18 | "codec/std",
19 | "sp-api/std",
20 | "sp-std/std",
21 | "web3games-exchange/std",
22 | "web3games-token-fungible/std",
23 | "primitives/std",
24 | ]
25 |
--------------------------------------------------------------------------------
/pallets/exchange/rpc/runtime-api/src/lib.rs:
--------------------------------------------------------------------------------
1 | // This file is part of Web3Games.
2 |
3 | // Copyright (C) 2021-2022 Web3Games https://web3games.org
4 | // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
5 |
6 | // This program is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published by
8 | // the Free Software Foundation, either version 3 of the License, or
9 | // (at your option) any later version.
10 |
11 | // This program is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 |
16 | // You should have received a copy of the GNU General Public License
17 | // along with this program. If not, see .
18 |
19 | #![cfg_attr(not(feature = "std"), no_std)]
20 |
21 | use codec::Codec;
22 | use primitives::Balance;
23 | use sp_api::decl_runtime_apis;
24 | use sp_std::vec::Vec;
25 |
26 | decl_runtime_apis! {
27 | pub trait ExchangeRuntimeApi where
28 | AccountId: Codec,
29 | {
30 | fn get_amount_in_price(supply: Balance, path: Vec) -> Option>;
31 | fn get_amount_out_price(supply: Balance, path: Vec) -> Option>;
32 | fn get_estimate_lp_token(
33 | token_0: u128,
34 | amount_0: Balance,
35 | token_1: u128,
36 | amount_1: Balance,
37 | ) -> Option;
38 | fn get_estimate_out_token(supply: Balance,token_0:u128,token_1:u128)-> Option;
39 | fn get_liquidity_to_tokens(lp_token_0:u128,lp_balance:Balance)-> Option<(Balance,Balance)>;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/pallets/farming/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "web3games-farming"
3 | version = "0.1.0"
4 | authors = ["Web3Games Developers"]
5 | edition = "2021"
6 |
7 | [dependencies]
8 | serde = { version = "1.0.137", optional = true }
9 | codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] }
10 | sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false }
11 | frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false }
12 | frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false }
13 | frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false, optional = true }
14 | sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false }
15 | sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false }
16 | scale-info = { version = "2.1.2", default-features = false, features = ["derive"] }
17 |
18 | web3games-token-fungible = { path = "../token-fungible", default-features = false }
19 | primitives = { path = "../../primitives", default-features = false }
20 |
21 | [dev-dependencies]
22 | sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" }
23 | pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" }
24 | smallvec = "1.9.0"
25 |
26 |
27 | [features]
28 | default = ["std"]
29 | std = [
30 | "serde",
31 | "codec/std",
32 | "sp-runtime/std",
33 | "frame-support/std",
34 | "frame-system/std",
35 | "sp-io/std",
36 | "sp-std/std",
37 | "scale-info/std",
38 | "web3games-token-fungible/std",
39 | "primitives/std",
40 | ]
41 | try-runtime = ["frame-support/try-runtime"]
42 |
43 | runtime-benchmarks = [
44 | "frame-benchmarking",
45 | "frame-support/runtime-benchmarks",
46 | "frame-system/runtime-benchmarks",
47 | ]
48 |
49 |
--------------------------------------------------------------------------------
/pallets/farming/src/benchmarking.rs:
--------------------------------------------------------------------------------
1 | //! Benchmarking setup for pallet-template
2 |
3 | #![cfg(feature = "runtime-benchmarks")]
4 |
5 | use super::*;
6 | use crate::Pallet as Farming;
7 | use frame_benchmarking::{account, benchmarks};
8 | use frame_support::assert_ok;
9 | use frame_system::{Pallet as System, RawOrigin};
10 | use sp_runtime::traits::UniqueSaturatedFrom;
11 | use web3games_token_fungible::Pallet as TokenFungible;
12 |
13 | const W3G: u128 = 1;
14 | const USDT: u128 = 2;
15 | const W3G_DECIMALS: u128 = 1_000_000_000_000_000_000;
16 | const USDT_DECIMALS: u128 = 1_000_000;
17 |
18 | fn setup() -> DispatchResult {
19 | let alice: T::AccountId = account("alice", 0, 0);
20 | let bob: T::AccountId = account("bob", 0, 0);
21 |
22 | assert_ok!(TokenFungible::::create_token(
23 | RawOrigin::Signed(alice.clone()).into(),
24 | ::FungibleTokenId::unique_saturated_from(W3G),
25 | b"TestToken".to_vec(),
26 | b"TK".to_vec(),
27 | 18
28 | ));
29 | assert_ok!(TokenFungible::::create_token(
30 | RawOrigin::Signed(alice.clone()).into(),
31 | ::FungibleTokenId::unique_saturated_from(USDT),
32 | b"TestToken".to_vec(),
33 | b"TK".to_vec(),
34 | 18
35 | ));
36 | assert_ok!(TokenFungible::::mint(
37 | RawOrigin::Signed(alice.clone()).into(),
38 | ::FungibleTokenId::unique_saturated_from(USDT),
39 | alice.clone(),
40 | 100 * USDT_DECIMALS,
41 | ));
42 | assert_ok!(TokenFungible::::mint(
43 | RawOrigin::Signed(alice.clone()).into(),
44 | ::FungibleTokenId::unique_saturated_from(W3G),
45 | bob,
46 | 100 * W3G_DECIMALS,
47 | ));
48 | Ok(())
49 | }
50 |
51 | benchmarks! {
52 | set_admin {
53 | let alice: T::AccountId = account("alice", 0, 0);
54 | }: _(RawOrigin::Root,alice)
55 |
56 | create_pool {
57 | let alice: T::AccountId = account("alice", 0, 0);
58 | let bob: T::AccountId = account("bob", 0, 0);
59 | setup::()?;
60 | assert_ok!(Farming::::set_admin(RawOrigin::Root.into(),alice.clone()));
61 | }: _(RawOrigin::Signed(alice),T::BlockNumber::from(1u32),T::BlockNumber::from(10u32),T::BlockNumber::from(10u32),W3G,USDT,10 * USDT_DECIMALS)
62 |
63 | staking {
64 | let alice: T::AccountId = account("alice", 0, 0);
65 | let bob: T::AccountId = account("bob", 0, 0);
66 | setup::()?;
67 | assert_ok!(Farming::::set_admin(RawOrigin::Root.into(),alice.clone()));
68 | assert_ok!(Farming::::create_pool(
69 | RawOrigin::Signed(alice.clone()).into(),
70 | T::BlockNumber::from(10u32),
71 | T::BlockNumber::from(10u32),
72 | T::BlockNumber::from(10u32),
73 | W3G,
74 | USDT,
75 | 10 * USDT_DECIMALS,
76 | ));
77 | System::::set_block_number(T::BlockNumber::from(10u32));
78 | }: _(RawOrigin::Signed(bob),0,10 * W3G_DECIMALS)
79 |
80 | claim {
81 | let alice: T::AccountId = account("alice", 0, 0);
82 | let bob: T::AccountId = account("bob", 0, 0);
83 | setup::()?;
84 | assert_ok!(Farming::::set_admin(RawOrigin::Root.into(),alice.clone()));
85 | assert_ok!(Farming::::create_pool(
86 | RawOrigin::Signed(alice.clone()).into(),
87 | T::BlockNumber::from(10u32),
88 | T::BlockNumber::from(10u32),
89 | T::BlockNumber::from(10u32),
90 | W3G,
91 | USDT,
92 | 10 * USDT_DECIMALS,
93 | ));
94 | System::::set_block_number(T::BlockNumber::from(10u32));
95 | assert_ok!(Farming::::staking(
96 | RawOrigin::Signed(bob.clone()).into(),
97 | 0,
98 | 10 * W3G_DECIMALS,
99 | ));
100 | System::::set_block_number(T::BlockNumber::from(30u32));
101 | }: _(RawOrigin::Signed(bob),0)
102 |
103 | force_claim {
104 | let alice: T::AccountId = account("alice", 0, 0);
105 | let bob: T::AccountId = account("bob", 0, 0);
106 | setup::()?;
107 | assert_ok!(Farming::::set_admin(RawOrigin::Root.into(),alice.clone()));
108 | assert_ok!(Farming::::create_pool(
109 | RawOrigin::Signed(alice.clone()).into(),
110 | T::BlockNumber::from(10u32),
111 | T::BlockNumber::from(10u32),
112 | T::BlockNumber::from(10u32),
113 | W3G,
114 | USDT,
115 | 10 * USDT_DECIMALS,
116 | ));
117 | System::::set_block_number(T::BlockNumber::from(10u32));
118 | assert_ok!(Farming::::staking(
119 | RawOrigin::Signed(bob.clone()).into(),
120 | 0,
121 | 10 * W3G_DECIMALS,
122 | ));
123 | }: _(RawOrigin::Signed(alice),bob,0)
124 |
125 | impl_benchmark_test_suite!(Farming, crate::mock::new_test_ext(), crate::mock::Test);
126 | }
127 |
--------------------------------------------------------------------------------
/pallets/farming/src/mock.rs:
--------------------------------------------------------------------------------
1 | // This file is part of Web3Games.
2 |
3 | // Copyright (C) 2021-2022 Web3Games https://web3games.org
4 | // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
5 |
6 | // This program is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published by
8 | // the Free Software Foundation, either version 3 of the License, or
9 | // (at your option) any later version.
10 |
11 | // This program is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 |
16 | // You should have received a copy of the GNU General Public License
17 | // along with this program. If not, see .
18 |
19 | use crate as web3games_farming;
20 | use frame_support::{
21 | construct_runtime, parameter_types,
22 | traits::{ConstU16, ConstU64},
23 | PalletId,
24 | };
25 | use primitives::Balance;
26 | use sp_core::H256;
27 | use sp_runtime::{
28 | testing::Header,
29 | traits::{BlakeTwo256, IdentityLookup},
30 | };
31 |
32 | type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic;
33 | type Block = frame_system::mocking::MockBlock;
34 |
35 | pub const MILLICENTS: Balance = 10_000_000_000_000;
36 | pub const CENTS: Balance = 1_000 * MILLICENTS; // assume this is worth about a cent.
37 | pub const DOLLARS: Balance = 100 * CENTS;
38 |
39 | // Configure a mock runtime to test the pallet.
40 | construct_runtime!(
41 | pub enum Test where
42 | Block = Block,
43 | NodeBlock = Block,
44 | UncheckedExtrinsic = UncheckedExtrinsic,
45 | {
46 | System: frame_system::{Pallet, Call, Config, Storage, Event},
47 | Balances: pallet_balances::{Pallet, Call, Storage, Config, Event},
48 | TokenFungible: web3games_token_fungible::{Pallet, Call, Storage, Event},
49 | Farming: web3games_farming::{Pallet, Call, Storage, Event},
50 | }
51 | );
52 |
53 | impl frame_system::Config for Test {
54 | type BaseCallFilter = frame_support::traits::Everything;
55 | type BlockWeights = ();
56 | type BlockLength = ();
57 | type DbWeight = ();
58 | type Origin = Origin;
59 | type Call = Call;
60 | type Index = u64;
61 | type BlockNumber = u64;
62 | type Hash = H256;
63 | type Hashing = BlakeTwo256;
64 | type AccountId = u64;
65 | type Lookup = IdentityLookup;
66 | type Header = Header;
67 | type Event = Event;
68 | type BlockHashCount = ConstU64<250>;
69 | type Version = ();
70 | type PalletInfo = PalletInfo;
71 | type AccountData = pallet_balances::AccountData;
72 | type OnNewAccount = ();
73 | type OnKilledAccount = ();
74 | type SystemWeightInfo = ();
75 | type SS58Prefix = ConstU16<42>;
76 | type OnSetCode = ();
77 | type MaxConsumers = frame_support::traits::ConstU32<16>;
78 | }
79 |
80 | parameter_types! {
81 | pub const ExistentialDeposit: Balance = 1;
82 | }
83 |
84 | impl pallet_balances::Config for Test {
85 | type Balance = Balance;
86 | type DustRemoval = ();
87 | type Event = Event;
88 | type ExistentialDeposit = ExistentialDeposit;
89 | type AccountStore = System;
90 | type WeightInfo = ();
91 | type MaxLocks = ();
92 | type MaxReserves = ();
93 | type ReserveIdentifier = [u8; 8];
94 | }
95 |
96 | parameter_types! {
97 | pub const TokenFungiblePalletId: PalletId = PalletId(*b"w3g/tfpi");
98 | pub const StringLimit: u32 = 50;
99 | pub const CreateTokenDeposit: Balance = 500 * MILLICENTS;
100 | }
101 |
102 | impl web3games_token_fungible::Config for Test {
103 | type Event = Event;
104 | type PalletId = TokenFungiblePalletId;
105 | type FungibleTokenId = u128;
106 | type StringLimit = StringLimit;
107 | type CreateTokenDeposit = CreateTokenDeposit;
108 | type Currency = Balances;
109 | type WeightInfo = ();
110 | }
111 |
112 | parameter_types! {
113 | pub const FarmingPalletId: PalletId = PalletId(*b"w3g/farm");
114 | }
115 |
116 | impl web3games_farming::Config for Test {
117 | type Event = Event;
118 | type PalletId = FarmingPalletId;
119 | type WeightInfo = ();
120 | }
121 |
122 | // Build genesis storage according to the mock runtime.
123 | pub fn new_test_ext() -> sp_io::TestExternalities {
124 | let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap();
125 | pallet_balances::GenesisConfig:: {
126 | balances: vec![(1, 100 * DOLLARS), (2, 100 * DOLLARS)],
127 | }
128 | .assimilate_storage(&mut t)
129 | .unwrap();
130 | let mut ext = sp_io::TestExternalities::new(t);
131 | ext.execute_with(|| System::set_block_number(1));
132 | ext
133 | }
134 |
135 | /// Run until a particular block.
136 | pub fn run_to_block(n: u64) {
137 | while System::block_number() < n {
138 | System::finalize();
139 | System::set_block_number(System::block_number() + 1);
140 | }
141 | }
142 |
--------------------------------------------------------------------------------
/pallets/launchpad/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "web3games-launchpad"
3 | version = "0.1.0"
4 | authors = ["Web3Games Developers"]
5 | edition = "2021"
6 |
7 | [dependencies]
8 | serde = { version = "1.0.137", optional = true }
9 | codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] }
10 | sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false }
11 | frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false }
12 | frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false }
13 | frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false, optional = true }
14 | sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false }
15 | sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false }
16 | scale-info = { version = "2.1.2", default-features = false, features = ["derive"] }
17 |
18 | web3games-token-fungible = { path = "../token-fungible", default-features = false }
19 | web3games-support = { path = "../support", default-features = false }
20 | primitives = { path = "../../primitives", default-features = false }
21 |
22 | [dev-dependencies]
23 | sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" }
24 | pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" }
25 | smallvec = "1.9.0"
26 |
27 |
28 | [features]
29 | default = ["std"]
30 | std = [
31 | "serde",
32 | "codec/std",
33 | "sp-runtime/std",
34 | "frame-support/std",
35 | "frame-system/std",
36 | "sp-io/std",
37 | "sp-std/std",
38 | "scale-info/std",
39 | "web3games-token-fungible/std",
40 | "web3games-support/std",
41 | "primitives/std",
42 | ]
43 | try-runtime = ["frame-support/try-runtime"]
44 |
45 | runtime-benchmarks = [
46 | "frame-benchmarking",
47 | "frame-support/runtime-benchmarks",
48 | "frame-system/runtime-benchmarks",
49 | ]
50 |
51 |
--------------------------------------------------------------------------------
/pallets/launchpad/src/benchmarking.rs:
--------------------------------------------------------------------------------
1 | //! Benchmarking setup for pallet-template
2 |
3 | #![cfg(feature = "runtime-benchmarks")]
4 |
5 | use super::*;
6 | use crate::Pallet as Launchpad;
7 | use frame_benchmarking::{account, benchmarks};
8 | use frame_support::assert_ok;
9 | use frame_system::{Pallet as System, RawOrigin};
10 | use sp_runtime::traits::UniqueSaturatedFrom;
11 | use web3games_token_fungible::Pallet as TokenFungible;
12 |
13 | const W3G: u128 = 1;
14 | const USDT: u128 = 2;
15 | const W3G_DECIMALS: u128 = 1_000_000_000_000_000_000;
16 | const USDT_DECIMALS: u128 = 1_000_000;
17 |
18 | fn setup() -> DispatchResult {
19 | let alice: T::AccountId = account("alice", 0, 0);
20 | let bob: T::AccountId = account("bob", 0, 0);
21 |
22 | assert_ok!(TokenFungible::::create_token(
23 | RawOrigin::Signed(alice.clone()).into(),
24 | ::FungibleTokenId::unique_saturated_from(W3G),
25 | b"TestToken".to_vec(),
26 | b"TK".to_vec(),
27 | 18
28 | ));
29 | assert_ok!(TokenFungible::::create_token(
30 | RawOrigin::Signed(alice.clone()).into(),
31 | ::FungibleTokenId::unique_saturated_from(USDT),
32 | b"TestToken".to_vec(),
33 | b"TK".to_vec(),
34 | 6
35 | ));
36 | assert_ok!(TokenFungible::::mint(
37 | RawOrigin::Signed(alice.clone()).into(),
38 | ::FungibleTokenId::unique_saturated_from(USDT),
39 | bob.clone(),
40 | 100 * USDT_DECIMALS,
41 | ));
42 | assert_ok!(TokenFungible::::mint(
43 | RawOrigin::Signed(alice.clone()).into(),
44 | ::FungibleTokenId::unique_saturated_from(W3G),
45 | alice,
46 | 100 * W3G_DECIMALS,
47 | ));
48 | Ok(())
49 | }
50 |
51 | benchmarks! {
52 | create_pool {
53 | let alice: T::AccountId = account("alice", 0, 0);
54 | setup::()?;
55 | }: _(RawOrigin::Signed(alice),T::BlockNumber::from(10u32),T::BlockNumber::from(10u32),W3G,USDT,10 * W3G_DECIMALS,1 * USDT_DECIMALS)
56 |
57 | buy_token {
58 | let alice: T::AccountId = account("alice", 0, 0);
59 | let bob: T::AccountId = account("bob", 0, 0);
60 | setup::()?;
61 | assert_ok!(Launchpad::::create_pool(
62 | RawOrigin::Signed(alice.clone()).into(),
63 | T::BlockNumber::from(10u32),
64 | T::BlockNumber::from(10u32),
65 | W3G,
66 | USDT,
67 | 10 * W3G_DECIMALS,
68 | 1 * USDT_DECIMALS,
69 | ));
70 | System::::set_block_number(T::BlockNumber::from(10u32));
71 | }: _(RawOrigin::Signed(bob),0,2)
72 |
73 | claim {
74 | let alice: T::AccountId = account("alice", 0, 0);
75 | let bob: T::AccountId = account("bob", 0, 0);
76 | setup::()?;
77 | assert_ok!(Launchpad::::create_pool(
78 | RawOrigin::Signed(alice.clone()).into(),
79 | T::BlockNumber::from(10u32),
80 | T::BlockNumber::from(10u32),
81 | W3G,
82 | USDT,
83 | 10 * W3G_DECIMALS,
84 | 1 * USDT_DECIMALS,
85 | ));
86 | System::::set_block_number(T::BlockNumber::from(10u32));
87 | assert_ok!(Launchpad::::buy_token(
88 | RawOrigin::Signed(bob.clone()).into(),
89 | 0,
90 | 2
91 | ));
92 | System::::set_block_number(T::BlockNumber::from(21u32));
93 | }: _(RawOrigin::Signed(bob),0)
94 |
95 | owner_claim {
96 | let alice: T::AccountId = account("alice", 0, 0);
97 | let bob: T::AccountId = account("bob", 0, 0);
98 | setup::()?;
99 | assert_ok!(Launchpad::::create_pool(
100 | RawOrigin::Signed(alice.clone()).into(),
101 | T::BlockNumber::from(10u32),
102 | T::BlockNumber::from(10u32),
103 | W3G,
104 | USDT,
105 | 10 * W3G_DECIMALS,
106 | 1 * USDT_DECIMALS,
107 | ));
108 | System::::set_block_number(T::BlockNumber::from(21u32));
109 | }: _(RawOrigin::Signed(alice),0)
110 |
111 | impl_benchmark_test_suite!(Launchpad, crate::mock::new_test_ext(), crate::mock::Test);
112 | }
113 |
--------------------------------------------------------------------------------
/pallets/launchpad/src/weights.rs:
--------------------------------------------------------------------------------
1 | // This file is part of Web3Games.
2 |
3 | // Copyright (C) 2021-2022 Web3Games https://web3games.org
4 | // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
5 |
6 | // This program is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published by
8 | // the Free Software Foundation, either version 3 of the License, or
9 | // (at your option) any later version.
10 |
11 | // This program is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 |
16 | // You should have received a copy of the GNU General Public License
17 | // along with this program. If not, see .
18 |
19 | //! Autogenerated weights for web3games_launchpad
20 | //!
21 | //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
22 | //! DATE: 2022-12-22, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
23 | //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024
24 |
25 | // Executed Command:
26 | // target/release/web3games-node
27 | // benchmark
28 | // pallet
29 | // --chain=dev
30 | // --steps=50
31 | // --repeat=20
32 | // --pallet=web3games_launchpad
33 | // --extrinsic=*
34 | // --execution=wasm
35 | // --wasm-execution=compiled
36 | // --output=./pallets/launchpad/src/weights.rs
37 | // --template=./.maintain/w3g-weight-template.hbs
38 |
39 | #![cfg_attr(rustfmt, rustfmt_skip)]
40 | #![allow(unused_parens)]
41 | #![allow(unused_imports)]
42 | #![allow(clippy::unnecessary_cast)]
43 |
44 | use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
45 | use sp_std::marker::PhantomData;
46 |
47 | /// Weight functions needed for web3games_launchpad.
48 | pub trait WeightInfo {
49 | fn create_pool() -> Weight;
50 | fn buy_token() -> Weight;
51 | fn claim() -> Weight;
52 | fn owner_claim() -> Weight;
53 | }
54 |
55 | /// Weights for web3games_launchpad using the Web3Games node and recommended hardware.
56 | pub struct W3GWeight(PhantomData);
57 | impl WeightInfo for W3GWeight {
58 | // Storage: Launchpad NextPoolId (r:1 w:1)
59 | // Storage: TokenFungible Balances (r:2 w:2)
60 | // Storage: Launchpad Pools (r:0 w:1)
61 | fn create_pool() -> Weight {
62 | (27_000_000 as Weight)
63 | .saturating_add(T::DbWeight::get().reads(3 as Weight))
64 | .saturating_add(T::DbWeight::get().writes(4 as Weight))
65 | }
66 | // Storage: Launchpad Pools (r:1 w:1)
67 | // Storage: TokenFungible Balances (r:2 w:2)
68 | // Storage: TokenFungible Tokens (r:1 w:0)
69 | // Storage: Launchpad AccountPoolIdLocked (r:1 w:1)
70 | fn buy_token() -> Weight {
71 | (36_000_000 as Weight)
72 | .saturating_add(T::DbWeight::get().reads(5 as Weight))
73 | .saturating_add(T::DbWeight::get().writes(4 as Weight))
74 | }
75 | // Storage: Launchpad Pools (r:1 w:0)
76 | // Storage: Launchpad AccountPoolIdLocked (r:1 w:1)
77 | // Storage: TokenFungible Balances (r:2 w:2)
78 | fn claim() -> Weight {
79 | (34_000_000 as Weight)
80 | .saturating_add(T::DbWeight::get().reads(4 as Weight))
81 | .saturating_add(T::DbWeight::get().writes(3 as Weight))
82 | }
83 | // Storage: Launchpad Pools (r:1 w:0)
84 | // Storage: TokenFungible Balances (r:4 w:4)
85 | fn owner_claim() -> Weight {
86 | (41_000_000 as Weight)
87 | .saturating_add(T::DbWeight::get().reads(5 as Weight))
88 | .saturating_add(T::DbWeight::get().writes(4 as Weight))
89 | }
90 | }
91 |
92 | // For backwards compatibility and tests
93 | impl WeightInfo for () {
94 | fn create_pool() -> Weight {
95 | (27_000_000 as Weight)
96 | .saturating_add(RocksDbWeight::get().reads(3 as Weight))
97 | .saturating_add(RocksDbWeight::get().writes(4 as Weight))
98 | }
99 | fn buy_token() -> Weight {
100 | (36_000_000 as Weight)
101 | .saturating_add(RocksDbWeight::get().reads(5 as Weight))
102 | .saturating_add(RocksDbWeight::get().writes(4 as Weight))
103 | }
104 | fn claim() -> Weight {
105 | (34_000_000 as Weight)
106 | .saturating_add(RocksDbWeight::get().reads(4 as Weight))
107 | .saturating_add(RocksDbWeight::get().writes(3 as Weight))
108 | }
109 | fn owner_claim() -> Weight {
110 | (41_000_000 as Weight)
111 | .saturating_add(RocksDbWeight::get().reads(5 as Weight))
112 | .saturating_add(RocksDbWeight::get().writes(4 as Weight))
113 | }
114 | }
115 |
--------------------------------------------------------------------------------
/pallets/marketplace/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "web3games-marketplace"
3 | version = "0.1.0"
4 | authors = ["Web3Games Developers"]
5 | edition = "2021"
6 |
7 | [dependencies]
8 | codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] }
9 | scale-info = { version = "2.1.2", default-features = false, features = ["derive"] }
10 |
11 | frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false, optional = true }
12 | frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" , default-features = false }
13 | frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" , default-features = false }
14 | sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" , default-features = false}
15 | sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" , default-features = false }
16 | sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" , default-features = false }
17 | sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" , default-features = false }
18 | pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false }
19 | web3games-token-non-fungible = { path = "../token-non-fungible", default-features = false }
20 | web3games-token-multi = { path = "../token-multi", default-features = false }
21 |
22 | primitives = { path = "../../primitives", default-features = false }
23 |
24 | [dev-dependencies]
25 | pallet-timestamp = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" }
26 |
27 | [features]
28 | default = ["std"]
29 | std = [
30 | "codec/std",
31 | "scale-info/std",
32 | "frame-support/std",
33 | "frame-system/std",
34 | "sp-std/std",
35 | "sp-io/std",
36 | "sp-runtime/std",
37 | "sp-core/std",
38 | "primitives/std",
39 | "web3games-token-non-fungible/std",
40 | "web3games-token-multi/std",
41 | "pallet-balances/std"
42 | ]
43 | try-runtime = ["frame-support/try-runtime"]
44 |
45 | runtime-benchmarks = [
46 | "frame-benchmarking",
47 | "frame-support/runtime-benchmarks",
48 | "frame-system/runtime-benchmarks",
49 | ]
50 |
--------------------------------------------------------------------------------
/pallets/marketplace/src/tests.rs:
--------------------------------------------------------------------------------
1 | #![cfg(test)]
2 |
3 | use super::*;
4 | use crate::mock::*;
5 | use frame_support::assert_ok;
6 |
7 | const ALICE: u64 = 1;
8 | const BOB: u64 = 2;
9 |
10 | const W3G: u128 = 1_000_000_000_000_000_000;
11 | const BLOCK: u64 = 1;
12 |
13 | fn create_non_fungible_token() {
14 | assert_ok!(TokenNonFungible::create_token(
15 | Origin::signed(ALICE),
16 | 1,
17 | b"W3G".to_vec(),
18 | b"W3G".to_vec(),
19 | b"https://web3games.com/".to_vec(),
20 | ));
21 | assert_eq!(TokenNonFungible::exists(1), true);
22 |
23 | //mint 2 to ALICE
24 | assert_ok!(TokenNonFungible::mint(Origin::signed(ALICE), 1, ALICE, 2));
25 | assert_eq!(TokenNonFungible::owner_of(1, 2), Some(ALICE));
26 | }
27 |
28 | #[test]
29 | fn create_order_should_work() {
30 | new_test_ext().execute_with(|| {
31 | create_non_fungible_token();
32 | assert_ok!(Marketplace::create_order(
33 | Origin::signed(ALICE),
34 | Asset::NonFungibleToken(1, 2),
35 | 100 * W3G,
36 | 100 * BLOCK
37 | ));
38 | assert_eq!(
39 | Marketplace::orders(Asset::NonFungibleToken(1, 2)),
40 | Some(Order {
41 | creater: ALICE,
42 | price: 100 * W3G,
43 | start: 1 * BLOCK,
44 | duration: 100 * BLOCK
45 | })
46 | );
47 |
48 | assert_ok!(
49 | Marketplace::cancel_order(Origin::signed(ALICE), Asset::NonFungibleToken(1, 2),)
50 | );
51 | })
52 | }
53 |
54 | #[test]
55 | fn execute_order_should_work() {
56 | new_test_ext().execute_with(|| {
57 | create_non_fungible_token();
58 | assert_ok!(Marketplace::create_order(
59 | Origin::signed(ALICE),
60 | Asset::NonFungibleToken(1, 2),
61 | 100 * W3G,
62 | 100 * BLOCK
63 | ));
64 |
65 | assert_ok!(Marketplace::execute_order(Origin::signed(BOB), Asset::NonFungibleToken(1, 2),));
66 | })
67 | }
68 |
--------------------------------------------------------------------------------
/pallets/player-id/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "web3games-player-id"
3 | version = "0.1.0"
4 | authors = ["Web3Games Developers"]
5 | edition = "2021"
6 |
7 | [dependencies]
8 | hex-literal = "0.3.4"
9 | codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] }
10 | scale-info = { version = "2.1.2", default-features = false, features = ["derive"] }
11 | log = { version = "0.4.17", default-features = false }
12 | frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" , default-features = false, optional = true }
13 | frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" , default-features = false }
14 | frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" , default-features = false }
15 | sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" , default-features = false }
16 | sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" , default-features = false }
17 | sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" , default-features = false }
18 | sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" , default-features = false }
19 |
20 | [dev-dependencies]
21 | pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" }
22 |
23 | [features]
24 | default = ["std"]
25 | std = [
26 | "codec/std",
27 | "scale-info/std",
28 | "log/std",
29 | "frame-support/std",
30 | "frame-system/std",
31 | "sp-core/std",
32 | "sp-std/std",
33 | "sp-io/std",
34 | "sp-runtime/std",
35 | ]
36 | runtime-benchmarks = [
37 | "frame-benchmarking",
38 | "frame-support/runtime-benchmarks",
39 | "frame-system/runtime-benchmarks",
40 | ]
41 |
--------------------------------------------------------------------------------
/pallets/player-id/src/benchmarking.rs:
--------------------------------------------------------------------------------
1 | //! Benchmarking setup for pallet-template
2 |
3 | #![cfg(feature = "runtime-benchmarks")]
4 |
5 | use super::*;
6 | use crate::Pallet as PlayerIdModule;
7 | use frame_benchmarking::{account, benchmarks};
8 | use frame_support::assert_ok;
9 | use frame_system::RawOrigin;
10 | use hex_literal::hex;
11 |
12 | benchmarks! {
13 | where_clause {
14 | where
15 | T::AccountId: AsRef<[u8]>
16 | }
17 |
18 | register {
19 | }: _(RawOrigin::Signed(account("alice", 0, 0)),"tester".as_bytes().to_vec(),account("alice", 0, 0))
20 |
21 | add_address {
22 | let player_id_vec = "tester".as_bytes().to_vec();
23 | let player_id: PlayerId = player_id_vec.clone().try_into().unwrap();
24 | assert_ok!(PlayerIdModule::::register(RawOrigin::Signed(account("alice", 0, 0)).into(),player_id_vec,account("alice", 0, 0)));
25 | let eth_address = hex!["6Be02d1d3665660d22FF9624b7BE0551ee1Ac91b"];
26 | }: _(RawOrigin::Signed(account("alice", 0, 0)),player_id,Chains::ETH,eth_address.to_vec())
27 |
28 | remove_address {
29 | let player_id_vec = "tester".as_bytes().to_vec();
30 | let player_id: PlayerId = player_id_vec.clone().try_into().unwrap();
31 | assert_ok!(PlayerIdModule::::register(RawOrigin::Signed(account("alice", 0, 0)).into(),player_id_vec,account("alice", 0, 0)));
32 | let eth_address = hex!["6Be02d1d3665660d22FF9624b7BE0551ee1Ac91b"];
33 | assert_ok!(PlayerIdModule::::add_address(RawOrigin::Signed(account("alice", 0, 0)).into(),player_id.clone(),Chains::ETH,eth_address.clone().to_vec()));
34 | }: _(RawOrigin::Signed(account("alice", 0, 0)),player_id.clone(),Chains::ETH,Address::try_from(eth_address.to_vec()).unwrap())
35 |
36 | impl_benchmark_test_suite!(PlayerIdModule, crate::mock::new_test_ext(), crate::mock::Test);
37 | }
38 |
--------------------------------------------------------------------------------
/pallets/player-id/src/mock.rs:
--------------------------------------------------------------------------------
1 | // This file is part of Web3Games.
2 |
3 | // Copyright (C) 2021-2022 Web3Games https://web3games.org
4 | // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
5 |
6 | // This program is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published by
8 | // the Free Software Foundation, either version 3 of the License, or
9 | // (at your option) any later version.
10 |
11 | // This program is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 |
16 | // You should have received a copy of the GNU General Public License
17 | // along with this program. If not, see .
18 |
19 | use super::*;
20 | use crate as pallet_palyer_id;
21 | use frame_support::{
22 | construct_runtime, parameter_types,
23 | traits::{ConstU16, ConstU64},
24 | };
25 | use sp_core::H256;
26 | use sp_runtime::{
27 | testing::Header,
28 | traits::{BlakeTwo256, IdentityLookup},
29 | AccountId32,
30 | };
31 |
32 | type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic;
33 | type Block = frame_system::mocking::MockBlock;
34 |
35 | pub type Balance = u128;
36 |
37 | pub const MILLICENTS: Balance = 10_000_000_000_000;
38 | pub const CENTS: Balance = 1_000 * MILLICENTS; // assume this is worth about a cent.
39 | pub const DOLLARS: Balance = 100 * CENTS;
40 |
41 | pub const ALICE: AccountId32 = AccountId32::new([1u8; 32]);
42 | pub const BOB: AccountId32 = AccountId32::new([2u8; 32]);
43 |
44 | construct_runtime!(
45 | pub enum Test where
46 | Block = Block,
47 | NodeBlock = Block,
48 | UncheckedExtrinsic = UncheckedExtrinsic,
49 | {
50 | System: frame_system::{Pallet, Call, Config, Storage, Event},
51 | Balances: pallet_balances::{Pallet, Call, Storage, Config, Event},
52 | PlayerIdModule: pallet_palyer_id::{Pallet, Call, Storage, Event},
53 | }
54 | );
55 |
56 | impl frame_system::Config for Test {
57 | type BaseCallFilter = frame_support::traits::Everything;
58 | type BlockWeights = ();
59 | type BlockLength = ();
60 | type DbWeight = ();
61 | type Origin = Origin;
62 | type Call = Call;
63 | type Index = u64;
64 | type BlockNumber = u64;
65 | type Hash = H256;
66 | type Hashing = BlakeTwo256;
67 | type AccountId = AccountId32;
68 | type Lookup = IdentityLookup;
69 | type Header = Header;
70 | type Event = Event;
71 | type BlockHashCount = ConstU64<250>;
72 | type Version = ();
73 | type PalletInfo = PalletInfo;
74 | type AccountData = pallet_balances::AccountData;
75 | type OnNewAccount = ();
76 | type OnKilledAccount = ();
77 | type SystemWeightInfo = ();
78 | type SS58Prefix = ConstU16<42>;
79 | type OnSetCode = ();
80 | type MaxConsumers = frame_support::traits::ConstU32<16>;
81 | }
82 |
83 | parameter_types! {
84 | pub const ExistentialDeposit: Balance = 1;
85 | }
86 |
87 | impl pallet_balances::Config for Test {
88 | type Balance = Balance;
89 | type DustRemoval = ();
90 | type Event = Event;
91 | type ExistentialDeposit = ExistentialDeposit;
92 | type AccountStore = System;
93 | type WeightInfo = ();
94 | type MaxLocks = ();
95 | type MaxReserves = ();
96 | type ReserveIdentifier = [u8; 8];
97 | }
98 |
99 | parameter_types! {
100 | pub const MaxAddressesPerChain: u32 = 10;
101 | }
102 |
103 | impl pallet_palyer_id::Config for Test {
104 | type Event = Event;
105 | type MaxAddressesPerChain = MaxAddressesPerChain;
106 | type WeightInfo = ();
107 | }
108 |
109 | // Build genesis storage according to the mock runtime.
110 | pub fn new_test_ext() -> sp_io::TestExternalities {
111 | let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap();
112 | pallet_balances::GenesisConfig:: {
113 | balances: vec![(ALICE, 100 * DOLLARS), (BOB, 100 * DOLLARS)],
114 | }
115 | .assimilate_storage(&mut t)
116 | .unwrap();
117 | t.into()
118 | }
119 |
--------------------------------------------------------------------------------
/pallets/player-id/src/tests.rs:
--------------------------------------------------------------------------------
1 | // This file is part of Web3Games.
2 |
3 | // Copyright (C) 2021-2022 Web3Games https://web3games.org
4 | // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
5 |
6 | // This program is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published by
8 | // the Free Software Foundation, either version 3 of the License, or
9 | // (at your option) any later version.
10 |
11 | // This program is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 |
16 | // You should have received a copy of the GNU General Public License
17 | // along with this program. If not, see .
18 |
19 | use super::*;
20 | use crate::mock::*;
21 | use frame_support::assert_ok;
22 | use hex_literal::hex;
23 |
24 | #[test]
25 | fn test_register_works() {
26 | new_test_ext().execute_with(|| {
27 | let address: Address = PlayerIdModule::account_to_address(ALICE);
28 | let player_id_vec = "tester".as_bytes().to_vec();
29 | let player_id: PlayerId = player_id_vec.clone().try_into().unwrap();
30 |
31 | let addresses: BoundedVec> =
32 | BoundedVec::try_from(vec![address.clone()]).unwrap();
33 |
34 | assert_ok!(PlayerIdModule::register(Origin::signed(ALICE), player_id_vec, ALICE));
35 |
36 | assert_eq!(PlayerIdOf::::get(address.clone(), Chains::W3G).unwrap(), player_id);
37 | assert_eq!(Addresses::::get(player_id.clone(), Chains::W3G).unwrap(), addresses);
38 |
39 | let eth_address = hex!["6Be02d1d3665660d22FF9624b7BE0551ee1Ac91b"];
40 | assert_ok!(PlayerIdModule::add_address(
41 | Origin::signed(ALICE),
42 | player_id.clone(),
43 | Chains::ETH,
44 | eth_address.clone().to_vec()
45 | ));
46 |
47 | assert_ok!(PlayerIdModule::remove_address(
48 | Origin::signed(ALICE),
49 | player_id,
50 | Chains::ETH,
51 | Address::try_from(eth_address.to_vec()).unwrap()
52 | ));
53 | });
54 | }
55 |
--------------------------------------------------------------------------------
/pallets/player-id/src/weights.rs:
--------------------------------------------------------------------------------
1 | // This file is part of Web3Games.
2 |
3 | // Copyright (C) 2021-2022 Web3Games https://web3games.org
4 | // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
5 |
6 | // This program is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published by
8 | // the Free Software Foundation, either version 3 of the License, or
9 | // (at your option) any later version.
10 |
11 | // This program is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 |
16 | // You should have received a copy of the GNU General Public License
17 | // along with this program. If not, see .
18 |
19 | //! Autogenerated weights for web3games_player_id
20 | //!
21 | //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
22 | //! DATE: 2022-12-22, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
23 | //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024
24 |
25 | // Executed Command:
26 | // target/release/web3games-node
27 | // benchmark
28 | // pallet
29 | // --chain=dev
30 | // --steps=50
31 | // --repeat=20
32 | // --pallet=web3games_player_id
33 | // --extrinsic=*
34 | // --execution=wasm
35 | // --wasm-execution=compiled
36 | // --output=./pallets/player-id/src/weights.rs
37 | // --template=./.maintain/w3g-weight-template.hbs
38 |
39 | #![cfg_attr(rustfmt, rustfmt_skip)]
40 | #![allow(unused_parens)]
41 | #![allow(unused_imports)]
42 | #![allow(clippy::unnecessary_cast)]
43 |
44 | use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
45 | use sp_std::marker::PhantomData;
46 |
47 | /// Weight functions needed for web3games_player_id.
48 | pub trait WeightInfo {
49 | fn register() -> Weight;
50 | fn add_address() -> Weight;
51 | fn remove_address() -> Weight;
52 | }
53 |
54 | /// Weights for web3games_player_id using the Web3Games node and recommended hardware.
55 | pub struct W3GWeight(PhantomData);
56 | impl WeightInfo for W3GWeight {
57 | // Storage: PlayerId Addresses (r:1 w:1)
58 | // Storage: PlayerId PlayerIdOf (r:0 w:1)
59 | fn register() -> Weight {
60 | (18_000_000 as Weight)
61 | .saturating_add(T::DbWeight::get().reads(1 as Weight))
62 | .saturating_add(T::DbWeight::get().writes(2 as Weight))
63 | }
64 | // Storage: PlayerId Addresses (r:2 w:1)
65 | // Storage: PlayerId PlayerIdOf (r:0 w:1)
66 | fn add_address() -> Weight {
67 | (21_000_000 as Weight)
68 | .saturating_add(T::DbWeight::get().reads(2 as Weight))
69 | .saturating_add(T::DbWeight::get().writes(2 as Weight))
70 | }
71 | // Storage: PlayerId Addresses (r:2 w:1)
72 | // Storage: PlayerId PlayerIdOf (r:0 w:1)
73 | fn remove_address() -> Weight {
74 | (22_000_000 as Weight)
75 | .saturating_add(T::DbWeight::get().reads(2 as Weight))
76 | .saturating_add(T::DbWeight::get().writes(2 as Weight))
77 | }
78 | }
79 |
80 | // For backwards compatibility and tests
81 | impl WeightInfo for () {
82 | fn register() -> Weight {
83 | (18_000_000 as Weight)
84 | .saturating_add(RocksDbWeight::get().reads(1 as Weight))
85 | .saturating_add(RocksDbWeight::get().writes(2 as Weight))
86 | }
87 | fn add_address() -> Weight {
88 | (21_000_000 as Weight)
89 | .saturating_add(RocksDbWeight::get().reads(2 as Weight))
90 | .saturating_add(RocksDbWeight::get().writes(2 as Weight))
91 | }
92 | fn remove_address() -> Weight {
93 | (22_000_000 as Weight)
94 | .saturating_add(RocksDbWeight::get().reads(2 as Weight))
95 | .saturating_add(RocksDbWeight::get().writes(2 as Weight))
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/pallets/proxy-pay/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "web3games-proxy-pay"
3 | version = "0.1.0"
4 | authors = ["Web3Games Developers"]
5 | edition = "2021"
6 |
7 | [dependencies]
8 | codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = [
9 | "derive",
10 | ] }
11 | scale-info = { version = "2.1.2", default-features = false, features = [
12 | "derive",
13 | ] }
14 | frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false, optional = true }
15 | frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false }
16 | frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false }
17 | pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false }
18 | sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false }
19 | sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false }
20 | primitives = { path = "../../primitives", default-features = false }
21 |
22 |
23 | [dev-dependencies]
24 | balances = { package = "pallet-balances", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false }
25 | sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" }
26 | sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" }
27 | smallvec = "1.9.0"
28 |
29 | [features]
30 | default = ["std"]
31 | std = [
32 | "codec/std",
33 | "scale-info/std",
34 | "frame-support/std",
35 | "frame-system/std",
36 | "primitives/std",
37 | "sp-runtime/std",
38 | "sp-std/std",
39 | "pallet-transaction-payment/std",
40 | ]
41 |
42 | runtime-benchmarks = [
43 | "frame-benchmarking",
44 | "frame-support/runtime-benchmarks",
45 | "frame-system/runtime-benchmarks",
46 | ]
47 |
--------------------------------------------------------------------------------
/pallets/support/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "web3games-support"
3 | version = "0.1.0"
4 | authors = ["Web3Games Developers"]
5 | edition = "2021"
6 |
7 | [dependencies]
8 | codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive", "max-encoded-len"] }
9 | scale-info = { version = "2.1.2", default-features = false, features = ["derive"] }
10 | log = { version = "0.4.17", default-features = false }
11 | frame-support = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" , default-features = false }
12 | frame-system = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" , default-features = false }
13 | sp-io = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" , default-features = false }
14 | sp-runtime = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" , default-features = false }
15 | sp-core = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" , default-features = false }
16 | sp-std = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" , default-features = false }
17 |
18 | primitives = {path = "../../primitives", default-features = false }
19 |
20 | [features]
21 | default = ["std"]
22 | std = [
23 | "codec/std",
24 | "scale-info/std",
25 | "log/std",
26 | "frame-support/std",
27 | "frame-system/std",
28 | "sp-std/std",
29 | "sp-io/std",
30 | "sp-runtime/std",
31 | "primitives/std",
32 | "sp-core/std",
33 | ]
34 |
--------------------------------------------------------------------------------
/pallets/support/src/lib.rs:
--------------------------------------------------------------------------------
1 | // This file is part of Web3Games.
2 |
3 | // Copyright (C) 2021-2022 Web3Games https://web3games.org
4 | // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
5 |
6 | // This program is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published by
8 | // the Free Software Foundation, either version 3 of the License, or
9 | // (at your option) any later version.
10 |
11 | // This program is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 |
16 | // You should have received a copy of the GNU General Public License
17 | // along with this program. If not, see .
18 |
19 | #![cfg_attr(not(feature = "std"), no_std)]
20 |
21 | use primitives::TokenIndex;
22 | use sp_core::H160;
23 | use sp_std::prelude::*;
24 |
25 | /// This trait ensure we can convert EVM Address to FungibleTokenId,
26 | /// NonFungibleTokenId, or MultiTokenId.
27 | /// We will require each mod to have this trait implemented
28 | pub trait TokenIdConversion {
29 | /// Try to convert an evm address into token ID. Might not succeed.
30 | fn try_from_address(address: H160) -> Option;
31 | /// Convert into an evm address. This is infallible.
32 | fn into_address(id: A) -> H160;
33 | }
34 |
35 | pub trait AccountMapping {
36 | /// Convert account ID into an evm address.
37 | fn into_evm_address(account: A) -> H160;
38 | }
39 |
40 | pub trait FungibleMetadata {
41 | type FungibleTokenId;
42 |
43 | fn token_name(id: Self::FungibleTokenId) -> Vec;
44 | fn token_symbol(id: Self::FungibleTokenId) -> Vec;
45 | fn token_decimals(id: Self::FungibleTokenId) -> u8;
46 | }
47 |
48 | pub trait NonFungibleMetadata {
49 | type NonFungibleTokenId;
50 | type TokenId;
51 |
52 | fn token_name(id: Self::NonFungibleTokenId) -> Vec;
53 | fn token_symbol(id: Self::NonFungibleTokenId) -> Vec;
54 | fn token_uri(id: Self::NonFungibleTokenId, token_id: Self::TokenId) -> Vec;
55 | }
56 |
57 | pub trait NonFungibleEnumerable {
58 | type NonFungibleTokenId;
59 | type TokenId;
60 |
61 | fn total_supply(id: Self::NonFungibleTokenId) -> u32;
62 | fn token_by_index(id: Self::NonFungibleTokenId, index: TokenIndex) -> Self::TokenId;
63 | fn token_of_owner_by_index(
64 | id: Self::NonFungibleTokenId,
65 | owner: AccountId,
66 | index: TokenIndex,
67 | ) -> Self::TokenId;
68 | }
69 |
70 | pub trait MultiMetadata {
71 | type MultiTokenId;
72 | type TokenId;
73 |
74 | fn uri(id: Self::MultiTokenId, token_id: Self::TokenId) -> Vec;
75 | }
76 |
--------------------------------------------------------------------------------
/pallets/token-fungible/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "web3games-token-fungible"
3 | version = "0.1.0"
4 | authors = ["Web3Games Developers"]
5 | edition = "2021"
6 |
7 | [dependencies]
8 | codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive", "max-encoded-len"] }
9 | scale-info = { version = "2.1.2", default-features = false, features = ["derive"] }
10 | serde = { version = "1.0.137", optional = true }
11 | log = { version = "0.4.17", default-features = false }
12 | sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" , default-features = false }
13 | sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" , default-features = false }
14 | sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" , default-features = false }
15 | sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" , default-features = false }
16 |
17 | # FRAME library
18 | frame-benchmarking = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true , branch = "polkadot-v0.9.26" }
19 | frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" , default-features = false }
20 | frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" , default-features = false }
21 |
22 | primitives = {path = "../../primitives", default-features = false }
23 | web3games-support = { path = "../support", default-features = false }
24 |
25 | [dev-dependencies]
26 | pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" }
27 |
28 | [features]
29 | default = ["std"]
30 | std = [
31 | "serde/std",
32 | "codec/std",
33 | "scale-info/std",
34 | "log/std",
35 | "sp-std/std",
36 | "sp-io/std",
37 | "sp-runtime/std",
38 | "primitives/std",
39 | "sp-core/std",
40 | "web3games-support/std",
41 | "frame-support/std",
42 | "frame-system/std",
43 | "frame-benchmarking/std",
44 | ]
45 | runtime-benchmarks = ["frame-benchmarking"]
46 |
--------------------------------------------------------------------------------
/pallets/token-fungible/README.md:
--------------------------------------------------------------------------------
1 | # web3games-token-fungible
2 |
3 | ## call
4 |
5 | ### create_token
6 |
7 | ### approve
8 |
9 | ### transfer
10 |
11 | ### transfer_from
12 |
13 | ### mint
14 |
15 | ### burn
16 |
17 | ## storage
18 |
19 | ### Allowances
20 |
21 | FungibleTokenId<===>(T::AccountId, T::AccountId) ===>Balance
22 |
23 | Query the authorized balance
24 |
25 | ```rust
26 | #[pallet::storage]
27 | #[pallet::getter(fn allowances)]
28 | pub(super) type Allowances = StorageDoubleMap<
29 | _,
30 | Blake2_128Concat,
31 | T::FungibleTokenId,
32 | Blake2_128Concat,
33 | // (owner, operator)
34 | (T::AccountId, T::AccountId),
35 | Balance,
36 | ValueQuery,
37 | >;
38 | ```
39 |
40 | ### Balances
41 |
42 | FungibleTokenId<===>T::AccountId ===>Balance
43 |
44 | Query account balance
45 |
46 | ```rust
47 | #[pallet::storage]
48 | #[pallet::getter(fn balance_of)]
49 | pub(super) type Balances = StorageDoubleMap<
50 | _,
51 | Blake2_128Concat,
52 | T::FungibleTokenId,
53 | Blake2_128Concat,
54 | T::AccountId,
55 | Balance,
56 | ValueQuery,
57 | >;
58 | ```
59 |
60 | ### Tokens
61 |
62 | FungibleTokenId ===> Token
63 |
64 | Query token info
65 |
66 | ```rust
67 | #[pallet::storage]
68 | pub(super) type Tokens = StorageMap<
69 | _,
70 | Blake2_128Concat,
71 | T::FungibleTokenId,
72 | Token>,
73 | >;
74 | ```
75 |
76 | ```rust
77 | #[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, MaxEncodedLen, TypeInfo)]
78 | pub struct Token {
79 | owner: AccountId,
80 | name: BoundedString,
81 | symbol: BoundedString,
82 | decimals: u8,
83 | total_supply: Balance,
84 | }
85 | ```
86 |
87 |
--------------------------------------------------------------------------------
/pallets/token-fungible/src/benchmarking.rs:
--------------------------------------------------------------------------------
1 | //! Benchmarking setup for pallet-template
2 |
3 | #![cfg(feature = "runtime-benchmarks")]
4 |
5 | use super::*;
6 |
7 | #[allow(unused)]
8 | use crate::Pallet as TokenFungible;
9 | use codec::alloc::string::ToString;
10 | use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite};
11 | use frame_system::RawOrigin;
12 |
13 | const SEED: u32 = 0;
14 |
15 | benchmarks! {
16 | create_token {
17 | let alice: T::AccountId = account("alice", 0, SEED);
18 | }: _(RawOrigin::Signed(alice), 1u32.into(), "TestToken".to_string().into(), "TK".to_string().into(), 18)
19 |
20 | mint {
21 | let alice: T::AccountId = account("alice", 0, SEED);
22 | let bob: T::AccountId = account("bob", 0, SEED);
23 |
24 | // let recipient: T::AccountId = account("recipient", 0, SEED);
25 | let _ = TokenFungible::::create_token(::Origin::from(RawOrigin::Signed(alice.clone())), 1u32.into(), "TestToken".to_string().into(), "TK".to_string().into(), 18);
26 | }: _(RawOrigin::Signed(alice.clone()), 1u32.into(), alice.clone(), 100_000_000_000_000u128)
27 |
28 | approve {
29 | let alice: T::AccountId = account("alice", 0, SEED);
30 | let bob: T::AccountId = account("bob", 0, SEED);
31 |
32 | let _ = TokenFungible::::create_token(::Origin::from(RawOrigin::Signed(alice.clone())), 1u32.into(), "TestToken".to_string().into(), "TK".to_string().into(), 18);
33 | let _ = TokenFungible::::mint(::Origin::from(RawOrigin::Signed(alice.clone())), 1u32.into(), alice.clone(), 100_000_000_000_000u128);
34 | }: _(RawOrigin::Signed(alice), 1u32.into(), bob, 100_000_000_000u128)
35 |
36 | burn {
37 | let alice: T::AccountId = account("alice", 0, SEED);
38 | let bob: T::AccountId = account("bob", 0, SEED);
39 |
40 | let _ = TokenFungible::::create_token(::Origin::from(RawOrigin::Signed(alice.clone())), 1u32.into(), "TestToken".to_string().into(), "TK".to_string().into(), 18);
41 | let _ = TokenFungible::::mint(::Origin::from(RawOrigin::Signed(alice.clone())), 1u32.into(), alice.clone(), 100_000_000_000_000u128);
42 | }: _(RawOrigin::Signed(alice), 1u32.into(), 100_000_000_000_000u128)
43 |
44 | transfer {
45 | let alice: T::AccountId = account("alice", 0, SEED);
46 | let bob: T::AccountId = account("bob", 0, SEED);
47 |
48 | let _ = TokenFungible::::create_token(::Origin::from(RawOrigin::Signed(alice.clone())), 1u32.into(), "TestToken".to_string().into(), "TK".to_string().into(), 18);
49 | let _ = TokenFungible::::mint(::Origin::from(RawOrigin::Signed(alice.clone())), 1u32.into(), alice.clone(), 100_000_000_000_000u128);
50 | }: _(RawOrigin::Signed(alice), 1u32.into(), bob, 100_000_000_000u128)
51 |
52 | transfer_from {
53 | let alice: T::AccountId = account("alice", 0, SEED);
54 | let bob: T::AccountId = account("bob", 0, SEED);
55 | let charlie: T::AccountId = account("charlie", 0, SEED);
56 |
57 | let _ = TokenFungible::::create_token(::Origin::from(RawOrigin::Signed(alice.clone())), 1u32.into(), "TestToken".to_string().into(), "TK".to_string().into(), 18);
58 | let _ = TokenFungible::::mint(::Origin::from(RawOrigin::Signed(alice.clone())), 1u32.into(), alice.clone(), 100_000_000_000_000u128);
59 | let _ = TokenFungible::::approve(::Origin::from(RawOrigin::Signed(alice.clone())), 1u32.into(), charlie.clone(), 100_000_000_000_000u128);
60 | }: _(RawOrigin::Signed(charlie), 1u32.into(), alice, bob, 100_000_000_000u128)
61 | }
62 |
63 | impl_benchmark_test_suite!(TokenFungible, crate::mock::new_test_ext(), crate::mock::Test,);
64 |
--------------------------------------------------------------------------------
/pallets/token-fungible/src/mock.rs:
--------------------------------------------------------------------------------
1 | // This file is part of Web3Games.
2 |
3 | // Copyright (C) 2021-2022 Web3Games https://web3games.org
4 | // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
5 |
6 | // This program is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published by
8 | // the Free Software Foundation, either version 3 of the License, or
9 | // (at your option) any later version.
10 |
11 | // This program is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 |
16 | // You should have received a copy of the GNU General Public License
17 | // along with this program. If not, see .
18 |
19 | use crate as web3games_token_fungible;
20 | use frame_support::{
21 | construct_runtime, parameter_types,
22 | traits::{ConstU16, ConstU64},
23 | PalletId,
24 | };
25 | pub use pallet_balances::Error as BalancesError;
26 | use primitives::Balance;
27 | use sp_core::H256;
28 | use sp_runtime::{
29 | testing::Header,
30 | traits::{BlakeTwo256, IdentityLookup},
31 | };
32 | pub use web3games_token_fungible::{Error, Event as TokenFungibleEvent, Token};
33 |
34 | type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic;
35 | type Block = frame_system::mocking::MockBlock;
36 |
37 | pub const MILLICENTS: Balance = 10_000_000_000_000;
38 | pub const CENTS: Balance = 1_000 * MILLICENTS; // assume this is worth about a cent.
39 | pub const DOLLARS: Balance = 100 * CENTS;
40 |
41 | construct_runtime!(
42 | pub enum Test where
43 | Block = Block,
44 | NodeBlock = Block,
45 | UncheckedExtrinsic = UncheckedExtrinsic,
46 | {
47 | System: frame_system::{Pallet, Call, Config, Storage, Event},
48 | Balances: pallet_balances::{Pallet, Call, Storage, Config, Event},
49 | TokenFungible: web3games_token_fungible::{Pallet, Call, Storage, Config, Event},
50 | }
51 | );
52 |
53 | impl frame_system::Config for Test {
54 | type BaseCallFilter = frame_support::traits::Everything;
55 | type BlockWeights = ();
56 | type BlockLength = ();
57 | type DbWeight = ();
58 | type Origin = Origin;
59 | type Call = Call;
60 | type Index = u64;
61 | type BlockNumber = u64;
62 | type Hash = H256;
63 | type Hashing = BlakeTwo256;
64 | type AccountId = u64;
65 | type Lookup = IdentityLookup;
66 | type Header = Header;
67 | type Event = Event;
68 | type BlockHashCount = ConstU64<250>;
69 | type Version = ();
70 | type PalletInfo = PalletInfo;
71 | type AccountData = pallet_balances::AccountData;
72 | type OnNewAccount = ();
73 | type OnKilledAccount = ();
74 | type SystemWeightInfo = ();
75 | type SS58Prefix = ConstU16<42>;
76 | type OnSetCode = ();
77 | type MaxConsumers = frame_support::traits::ConstU32<16>;
78 | }
79 |
80 | parameter_types! {
81 | pub const ExistentialDeposit: Balance = 1;
82 | }
83 |
84 | impl pallet_balances::Config for Test {
85 | type Balance = Balance;
86 | type DustRemoval = ();
87 | type Event = Event;
88 | type ExistentialDeposit = ExistentialDeposit;
89 | type AccountStore = System;
90 | type WeightInfo = ();
91 | type MaxLocks = ();
92 | type MaxReserves = ();
93 | type ReserveIdentifier = [u8; 8];
94 | }
95 |
96 | parameter_types! {
97 | pub const TokenFungiblePalletId: PalletId = PalletId(*b"w3g/tfpi");
98 | pub const StringLimit: u32 = 50;
99 | pub const CreateTokenDeposit: Balance = 500 * MILLICENTS;
100 | }
101 |
102 | impl web3games_token_fungible::Config for Test {
103 | type Event = Event;
104 | type PalletId = TokenFungiblePalletId;
105 | type FungibleTokenId = u32;
106 | type StringLimit = StringLimit;
107 | type CreateTokenDeposit = CreateTokenDeposit;
108 | type Currency = Balances;
109 | type WeightInfo = ();
110 | }
111 |
112 | // Build genesis storage according to the mock runtime.
113 | pub fn new_test_ext() -> sp_io::TestExternalities {
114 | let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap();
115 | pallet_balances::GenesisConfig:: {
116 | balances: vec![(1, 100 * DOLLARS), (2, 100 * DOLLARS)],
117 | }
118 | .assimilate_storage(&mut t)
119 | .unwrap();
120 | let mut ext = sp_io::TestExternalities::new(t);
121 | ext.execute_with(|| System::set_block_number(1));
122 | ext
123 | }
124 |
--------------------------------------------------------------------------------
/pallets/token-multi/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "web3games-token-multi"
3 | version = "0.1.0"
4 | authors = ["Web3Games Developers"]
5 | edition = "2021"
6 |
7 | [dependencies]
8 | codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive", "max-encoded-len"] }
9 | scale-info = { version = "2.1.2", default-features = false, features = ["derive"] }
10 | serde = { version = "1.0.137", optional = true }
11 |
12 | sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" , default-features = false }
13 | sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" , default-features = false }
14 | sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" , default-features = false }
15 | sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" , default-features = false }
16 |
17 | # FRAME library
18 | frame-benchmarking = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true , branch = "polkadot-v0.9.26" }
19 | frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" , default-features = false }
20 | frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" , default-features = false }
21 |
22 | primitives = {path = "../../primitives", default-features = false }
23 | web3games-support = { path = "../support", default-features = false }
24 |
25 | [dev-dependencies]
26 | pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" }
27 |
28 | [features]
29 | default = ["std"]
30 | std = [
31 | "serde/std",
32 | "codec/std",
33 | "scale-info/std",
34 | "frame-support/std",
35 | "frame-system/std",
36 | "sp-io/std",
37 | "sp-runtime/std",
38 | "sp-core/std",
39 | "sp-std/std",
40 | "primitives/std",
41 | "web3games-support/std",
42 | "frame-benchmarking/std",
43 | ]
44 | runtime-benchmarks = ["frame-benchmarking"]
45 |
--------------------------------------------------------------------------------
/pallets/token-multi/README.md:
--------------------------------------------------------------------------------
1 | # web3games-token-multi-fungible
2 |
3 | ## call
4 |
5 | ### create_token
6 |
7 | ### set_approve_for_all
8 |
9 | ### transfer_from
10 |
11 | ### batch_transfer_from
12 |
13 | ### mint
14 |
15 | ### mint_batch
16 |
17 | ### burn
18 |
19 | ### burn_batch
20 |
21 | ## storage
22 |
23 | ### Balances
24 |
25 | MultiTokenId<===>(T::TokenId, T::AccountId) ===> Balance
26 |
27 | Query balance based on NonFungibleTokenId
28 |
29 | ```rust
30 | #[pallet::storage]
31 | #[pallet::getter(fn balance_of)]
32 | pub(super) type Balances = StorageDoubleMap<
33 | _,
34 | Blake2_128Concat,
35 | T::MultiTokenId,
36 | Blake2_128Concat,
37 | (T::TokenId, T::AccountId),
38 | Balance,
39 | ValueQuery,
40 | >;
41 | ```
42 |
43 | ### OperatorApprovals
44 |
45 | MultiTokenId<===>(T::AccountId, T::AccountId) ===> bool
46 |
47 | Query if it is an operator based on NonFungibleTokenId
48 |
49 | ```rust
50 | #[pallet::storage]
51 | #[pallet::getter(fn is_approved_for_all)]
52 | pub(super) type OperatorApprovals = StorageDoubleMap<
53 | _,
54 | Blake2_128Concat,
55 | T::MultiTokenId,
56 | Blake2_128Concat,
57 | // (owner, operator)
58 | (T::AccountId, T::AccountId),
59 | bool,
60 | ValueQuery,
61 | >;
62 | ```
63 |
64 | ### Tokens
65 |
66 | NonFungibleTokenId ===> Token
67 |
68 | Query token info
69 |
70 | ```rust
71 | #[pallet::storage]
72 | pub(super) type Tokens = StorageMap<
73 | _,
74 | Blake2_128Concat,
75 | T::MultiTokenId,
76 | Token>,
77 | >;
78 | ```
79 |
80 | ```rust
81 | #[derive(Encode, Decode, Clone, Eq, PartialEq, RuntimeDebug, MaxEncodedLen, TypeInfo)]
82 | pub struct Token {
83 | owner: AccountId,
84 | uri: BoundedString,
85 | total_supply: Balance,
86 | }
87 | ```
88 |
--------------------------------------------------------------------------------
/pallets/token-multi/src/benchmarking.rs:
--------------------------------------------------------------------------------
1 | //! Benchmarking setup for pallet-template
2 |
3 | #![cfg(feature = "runtime-benchmarks")]
4 |
5 | use super::*;
6 |
7 | use crate::Pallet as TokenMulti;
8 | use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite};
9 | use frame_system::RawOrigin;
10 |
11 | const SEED: u32 = 0;
12 |
13 | benchmarks! {
14 | create_token {
15 | let alice: T::AccountId = account("alice", 0, SEED);
16 | }: _(RawOrigin::Signed(alice), 1u32.into(), vec![0u8; 20])
17 |
18 | mint {
19 | let alice: T::AccountId = account("alice", 0, SEED);
20 |
21 | let _ = TokenMulti::::create_token(::Origin::from(RawOrigin::Signed(alice.clone())), 1u32.into(), vec![0u8; 20]);
22 | }: _(RawOrigin::Signed(alice.clone()), 1u32.into(), alice.clone(), 1u32.into(), 10u128)
23 |
24 | mint_batch {
25 | let alice: T::AccountId = account("alice", 0, SEED);
26 |
27 | let _ = TokenMulti::::create_token(::Origin::from(RawOrigin::Signed(alice.clone())), 1u32.into(), vec![0u8; 20]);
28 | }: _(RawOrigin::Signed(alice.clone()), 1u32.into(), alice.clone(), vec![1u32.into(), 2u32.into(), 3u32.into(), 4u32.into(), 5u32.into()], vec![10u128; 5])
29 |
30 | set_approval_for_all {
31 | let alice: T::AccountId = account("alice", 0, SEED);
32 | let bob: T::AccountId = account("bob", 0, SEED);
33 |
34 | let _ = TokenMulti::::create_token(::Origin::from(RawOrigin::Signed(alice.clone())), 1u32.into(), vec![0u8; 20]);
35 | let _ = TokenMulti::::mint(::Origin::from(RawOrigin::Signed(alice.clone())), 1u32.into(), alice.clone(), 1u32.into(), 10u128);
36 | }: _(RawOrigin::Signed(alice), 1u32.into(), bob, true)
37 |
38 | burn {
39 | let alice: T::AccountId = account("alice", 0, SEED);
40 |
41 | let _ = TokenMulti::::create_token(::Origin::from(RawOrigin::Signed(alice.clone())), 1u32.into(), vec![0u8; 20]);
42 | let _ = TokenMulti::::mint(::Origin::from(RawOrigin::Signed(alice.clone())), 1u32.into(), alice.clone(), 1u32.into(), 10u128);
43 | }: _(RawOrigin::Signed(alice), 1u32.into(), 1u32.into(), 5u128)
44 |
45 | burn_batch {
46 | let alice: T::AccountId = account("alice", 0, SEED);
47 |
48 | let _ = TokenMulti::::create_token(::Origin::from(RawOrigin::Signed(alice.clone())), 1u32.into(), vec![0u8; 20]);
49 | let _ = TokenMulti::::mint_batch(::Origin::from(RawOrigin::Signed(alice.clone())),1u32.into(), alice.clone(), vec![1u32.into(), 2u32.into(), 3u32.into(), 4u32.into(), 5u32.into()], vec![10u128; 5]);
50 | }: _(RawOrigin::Signed(alice), 1u32.into(), vec![1u32.into(), 2u32.into(), 3u32.into(), 4u32.into(), 5u32.into()], vec![5u128; 5])
51 |
52 | transfer_from {
53 | let alice: T::AccountId = account("alice", 0, SEED);
54 | let bob: T::AccountId = account("bob", 0, SEED);
55 |
56 | let _ = TokenMulti::::create_token(::Origin::from(RawOrigin::Signed(alice.clone())), 1u32.into(), vec![0u8; 20]);
57 | let _ = TokenMulti::::mint(::Origin::from(RawOrigin::Signed(alice.clone())), 1u32.into(), alice.clone(), 1u32.into(), 10u128);
58 | }: _(RawOrigin::Signed(alice.clone()), 1u32.into(), alice.clone(), bob.clone(), 1u32.into(), 5u128)
59 |
60 | batch_transfer_from {
61 | let alice: T::AccountId = account("alice", 0, SEED);
62 | let bob: T::AccountId = account("bob", 0, SEED);
63 |
64 | let _ = TokenMulti::::create_token(::Origin::from(RawOrigin::Signed(alice.clone())), 1u32.into(), vec![0u8; 20]);
65 | let _ = TokenMulti::::mint_batch(::Origin::from(RawOrigin::Signed(alice.clone())), 1u32.into(), alice.clone(), vec![1u32.into(), 2u32.into(), 3u32.into(), 4u32.into(), 5u32.into()], vec![10u128; 5]);
66 | }: _(RawOrigin::Signed(alice.clone()), 1u32.into(), alice.clone(), bob.clone(), vec![1u32.into(), 2u32.into(), 3u32.into(), 4u32.into(), 5u32.into()], vec![5u128; 5])
67 | }
68 |
69 | impl_benchmark_test_suite!(TokenMulti, crate::mock::new_test_ext(), crate::mock::Test,);
70 |
--------------------------------------------------------------------------------
/pallets/token-multi/src/mock.rs:
--------------------------------------------------------------------------------
1 | // This file is part of Web3Games.
2 |
3 | // Copyright (C) 2021-2022 Web3Games https://web3games.org
4 | // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
5 |
6 | // This program is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published by
8 | // the Free Software Foundation, either version 3 of the License, or
9 | // (at your option) any later version.
10 |
11 | // This program is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 |
16 | // You should have received a copy of the GNU General Public License
17 | // along with this program. If not, see .
18 |
19 | use crate as web3games_token_multi;
20 | use frame_support::{
21 | construct_runtime, parameter_types,
22 | traits::{ConstU16, ConstU64},
23 | PalletId,
24 | };
25 | use primitives::Balance;
26 | use sp_core::H256;
27 | use sp_runtime::{
28 | testing::Header,
29 | traits::{BlakeTwo256, IdentityLookup},
30 | };
31 |
32 | type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic;
33 | type Block = frame_system::mocking::MockBlock;
34 |
35 | pub const MILLICENTS: Balance = 10_000_000_000_000;
36 | pub const CENTS: Balance = 1_000 * MILLICENTS; // assume this is worth about a cent.
37 | pub const DOLLARS: Balance = 100 * CENTS;
38 |
39 | // Configure a mock runtime to test the pallet.
40 | construct_runtime!(
41 | pub enum Test where
42 | Block = Block,
43 | NodeBlock = Block,
44 | UncheckedExtrinsic = UncheckedExtrinsic,
45 | {
46 | System: frame_system::{Pallet, Call, Config, Storage, Event},
47 | Balances: pallet_balances::{Pallet, Call, Storage, Config, Event},
48 | TokenMulti: web3games_token_multi::{Pallet, Call, Storage, Event},
49 | }
50 | );
51 |
52 | impl frame_system::Config for Test {
53 | type BaseCallFilter = frame_support::traits::Everything;
54 | type BlockWeights = ();
55 | type BlockLength = ();
56 | type DbWeight = ();
57 | type Origin = Origin;
58 | type Call = Call;
59 | type Index = u64;
60 | type BlockNumber = u64;
61 | type Hash = H256;
62 | type Hashing = BlakeTwo256;
63 | type AccountId = u64;
64 | type Lookup = IdentityLookup;
65 | type Header = Header;
66 | type Event = Event;
67 | type BlockHashCount = ConstU64<250>;
68 | type Version = ();
69 | type PalletInfo = PalletInfo;
70 | type AccountData = pallet_balances::AccountData;
71 | type OnNewAccount = ();
72 | type OnKilledAccount = ();
73 | type SystemWeightInfo = ();
74 | type SS58Prefix = ConstU16<42>;
75 | type OnSetCode = ();
76 | type MaxConsumers = frame_support::traits::ConstU32<16>;
77 | }
78 |
79 | parameter_types! {
80 | pub const ExistentialDeposit: Balance = 1;
81 | }
82 |
83 | impl pallet_balances::Config for Test {
84 | type Balance = Balance;
85 | type DustRemoval = ();
86 | type Event = Event;
87 | type ExistentialDeposit = ExistentialDeposit;
88 | type AccountStore = System;
89 | type WeightInfo = ();
90 | type MaxLocks = ();
91 | type MaxReserves = ();
92 | type ReserveIdentifier = [u8; 8];
93 | }
94 |
95 | parameter_types! {
96 | pub const TokenMultiPalletId: PalletId = PalletId(*b"w3g/tmpi");
97 | pub const StringLimit: u32 = 50;
98 | pub const CreateTokenDeposit: Balance = 500 * MILLICENTS;
99 | }
100 |
101 | impl web3games_token_multi::Config for Test {
102 | type Event = Event;
103 | type PalletId = TokenMultiPalletId;
104 | type MultiTokenId = u32;
105 | type TokenId = u128;
106 | type StringLimit = StringLimit;
107 | type CreateTokenDeposit = CreateTokenDeposit;
108 | type Currency = Balances;
109 | type WeightInfo = ();
110 | }
111 |
112 | pub fn new_test_ext() -> sp_io::TestExternalities {
113 | let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap();
114 | pallet_balances::GenesisConfig:: {
115 | balances: vec![(1, 100 * DOLLARS), (2, 100 * DOLLARS)],
116 | }
117 | .assimilate_storage(&mut t)
118 | .unwrap();
119 | t.into()
120 | }
121 |
--------------------------------------------------------------------------------
/pallets/token-non-fungible/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "web3games-token-non-fungible"
3 | version = "0.1.0"
4 | authors = ["Web3Games Developers"]
5 | edition = "2021"
6 |
7 | [dependencies]
8 | codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive", "max-encoded-len"] }
9 | scale-info = { version = "2.1.2", default-features = false, features = ["derive"] }
10 | serde = { version = "1.0.137", optional = true }
11 | log = { version = "0.4.17", default-features = false }
12 | sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" , default-features = false }
13 | sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" , default-features = false }
14 | sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" , default-features = false }
15 | sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" , default-features = false }
16 |
17 | # FRAME library
18 | frame-benchmarking = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true , branch = "polkadot-v0.9.26" }
19 | frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" , default-features = false }
20 | frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" , default-features = false }
21 |
22 | primitives = {path = "../../primitives", default-features = false }
23 | web3games-support = { path = "../support", default-features = false }
24 |
25 | [dev-dependencies]
26 | pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" }
27 |
28 | [features]
29 | default = ["std"]
30 | std = [
31 | "serde/std",
32 | "codec/std",
33 | "scale-info/std",
34 | "log/std",
35 | "frame-support/std",
36 | "frame-system/std",
37 | "sp-io/std",
38 | "sp-runtime/std",
39 | "sp-core/std",
40 | "sp-std/std",
41 | "primitives/std",
42 | "web3games-support/std",
43 | "frame-benchmarking/std",
44 | ]
45 | runtime-benchmarks = ["frame-benchmarking"]
46 |
--------------------------------------------------------------------------------
/pallets/token-non-fungible/README.md:
--------------------------------------------------------------------------------
1 | # web3games-token-non-fungible
2 |
3 | ## call
4 |
5 | ### create_token
6 |
7 | ### approve
8 |
9 | ### set_approve_for_all
10 |
11 | ### transfer_from
12 |
13 | ### mint
14 |
15 | ### burn
16 |
17 | ## storage
18 |
19 | ### AllTokens
20 |
21 | NonFungibleTokenId<===>TokenIndex ===>TokenId
22 |
23 | Query TokenId based on TokenIndex
24 |
25 | ```rust
26 | #[pallet::storage]
27 | pub(super) type AllTokens = StorageDoubleMap<
28 | _,
29 | Blake2_128Concat,
30 | T::NonFungibleTokenId,
31 | Blake2_128Concat,
32 | TokenIndex,
33 | T::TokenId,
34 | ValueQuery,
35 | >;
36 | ```
37 |
38 | ### AllTokensIndex
39 |
40 | NonFungibleTokenId<===>TokenId ===> TokenIndex
41 |
42 | Query TokenIndex based on TokenId
43 |
44 | ```rust
45 | #[pallet::storage]
46 | pub(super) type AllTokensIndex = StorageDoubleMap<
47 | _,
48 | Blake2_128Concat,
49 | T::NonFungibleTokenId,
50 | Blake2_128Concat,
51 | T::TokenId,
52 | TokenIndex,
53 | ValueQuery,
54 | >;
55 | ```
56 |
57 | ### Balances
58 |
59 | NonFungibleTokenId<===>AccountId ===> u32
60 |
61 | Query balance based on NonFungibleTokenId
62 |
63 | ```rust
64 | #[pallet::storage]
65 | #[pallet::getter(fn balance_of)]
66 | pub(super) type Balances = StorageDoubleMap<
67 | _,
68 | Blake2_128Concat,
69 | T::NonFungibleTokenId,
70 | Blake2_128Concat,
71 | T::AccountId,
72 | u32,
73 | ValueQuery,
74 | >;
75 | ```
76 |
77 | ### OperatorApprovals
78 |
79 | NonFungibleTokenId<===>(T::AccountId, T::AccountId) ===> bool
80 |
81 | Query if it is an operator based on NonFungibleTokenId
82 |
83 | ```rust
84 | #[pallet::storage]
85 | #[pallet::getter(fn is_approved_for_all)]
86 | pub(super) type OperatorApprovals = StorageDoubleMap<
87 | _,
88 | Blake2_128Concat,
89 | T::NonFungibleTokenId,
90 | Blake2_128Concat,
91 | // (owner, operator)
92 | (T::AccountId, T::AccountId),
93 | bool,
94 | ValueQuery,
95 | >;
96 | ```
97 |
98 | ### OwnedTokens
99 |
100 | NonFungibleTokenId<===>(T::AccountId, TokenIndex) ===> TokenId
101 |
102 | Query the user's tokenId based on TokenIndex
103 |
104 | ```rust
105 | #[pallet::storage]
106 | pub(super) type OwnedTokens = StorageDoubleMap<
107 | _,
108 | Blake2_128Concat,
109 | T::NonFungibleTokenId,
110 | Blake2_128Concat,
111 | (T::AccountId, TokenIndex),
112 | T::TokenId,
113 | ValueQuery,
114 | >;
115 | ```
116 |
117 | ### OwnedTokensIndex
118 |
119 | NonFungibleTokenId<===>(T::AccountId, TokenId) ===> TokenIndex
120 |
121 | Query the user's TokenIndex based on TokenId
122 |
123 | ```rust
124 | #[pallet::storage]
125 | pub(super) type OwnedTokensIndex = StorageDoubleMap<
126 | _,
127 | Blake2_128Concat,
128 | T::NonFungibleTokenId,
129 | Blake2_128Concat,
130 | (T::AccountId, T::TokenId),
131 | TokenIndex,
132 | ValueQuery,
133 | >;
134 | ```
135 |
136 | ### owners
137 |
138 | NonFungibleTokenId<===>TokenId , ===> AccountId
139 |
140 | Query the TokenId's owner
141 |
142 | ```rust
143 | #[pallet::storage]
144 | #[pallet::getter(fn owner_of)]
145 | pub(super) type Owners = StorageDoubleMap<
146 | _,
147 | Blake2_128Concat,
148 | T::NonFungibleTokenId,
149 | Blake2_128Concat,
150 | T::TokenId,
151 | T::AccountId,
152 | OptionQuery,
153 | GetDefault,
154 | ConstU32<300_000>,
155 | >;
156 | ```
157 |
158 | ### TokenApprovals
159 |
160 | NonFungibleTokenId<===>TokenId , ===> AccountId
161 |
162 | Query the TokenId's approver
163 |
164 | ```rust
165 | #[pallet::storage]
166 | #[pallet::getter(fn get_approved)]
167 | pub(super) type TokenApprovals = StorageDoubleMap<
168 | _,
169 | Blake2_128Concat,
170 | T::NonFungibleTokenId,
171 | Blake2_128Concat,
172 | T::TokenId,
173 | T::AccountId,
174 | OptionQuery,
175 | GetDefault,
176 | ConstU32<300_000>,
177 | >;
178 | ```
179 |
180 | ### Tokens
181 |
182 | NonFungibleTokenId ===> Token
183 |
184 | Query token info
185 |
186 | ```rust
187 | #[pallet::storage]
188 | pub(super) type Tokens = StorageMap<
189 | _,
190 | Blake2_128Concat,
191 | T::NonFungibleTokenId,
192 | Token>,
193 | >;
194 | ```
195 |
196 | ```rust
197 | #[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, MaxEncodedLen, TypeInfo)]
198 | pub struct Token {
199 | owner: AccountId,
200 | name: BoundedString,
201 | symbol: BoundedString,
202 | base_uri: BoundedString,
203 | }
204 | ```
205 |
206 | ### TotalSupply
207 |
208 | NonFungibleTokenId ===> u32
209 |
210 | Query token totalSupply
211 |
212 | ```rust
213 | #[pallet::storage]
214 | pub(super) type TotalSupply =
215 | StorageMap<_, Blake2_128Concat, T::NonFungibleTokenId, u32, ValueQuery>;
216 | ```
217 |
--------------------------------------------------------------------------------
/pallets/token-non-fungible/src/benchmarking.rs:
--------------------------------------------------------------------------------
1 | //! Benchmarking setup for pallet-template
2 |
3 | #![cfg(feature = "runtime-benchmarks")]
4 |
5 | use super::*;
6 |
7 | use crate::Pallet as TokenNonFungible;
8 | use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite};
9 | use frame_system::RawOrigin;
10 |
11 | const SEED: u32 = 0;
12 |
13 | benchmarks! {
14 | create_token {
15 | let alice: T::AccountId = account("alice", 0, SEED);
16 | }: _(RawOrigin::Signed(alice), 1u32.into(), vec![0u8; 10], vec![0u8; 10], vec![0u8; 20])
17 |
18 | mint {
19 | let alice: T::AccountId = account("alice", 0, SEED);
20 | // let bob: T::AccountId = account("bob", 0, SEED);
21 |
22 | let _ = TokenNonFungible::::create_token(::Origin::from(RawOrigin::Signed(alice.clone())), 1u32.into(), vec![0u8; 10], vec![0u8; 10], vec![0u8; 20]);
23 | }: _(RawOrigin::Signed(alice.clone()), 1u32.into(), alice.clone(), 1u32.into())
24 |
25 | burn {
26 | let alice: T::AccountId = account("alice", 0, SEED);
27 |
28 | let _ = TokenNonFungible::::create_token(::Origin::from(RawOrigin::Signed(alice.clone())), 1u32.into(), vec![0u8; 10], vec![0u8; 10], vec![0u8; 20]);
29 | let _ = TokenNonFungible::::mint(::Origin::from(RawOrigin::Signed(alice.clone())), 1u32.into(), alice.clone(), 1u32.into());
30 | }: _(RawOrigin::Signed(alice), 1u32.into(), 1u32.into())
31 |
32 | approve {
33 | let alice: T::AccountId = account("alice", 0, SEED);
34 | let bob: T::AccountId = account("bob", 0, SEED);
35 |
36 | let _ = TokenNonFungible::::create_token(::Origin::from(RawOrigin::Signed(alice.clone())), 1u32.into(), vec![0u8; 10], vec![0u8; 10], vec![0u8; 20]);
37 | let _ = TokenNonFungible::