Skip to content

Commit

Permalink
Add MantaSBT to Manta Runtime (Manta-Network#1135)
Browse files Browse the repository at this point in the history
* add manta sbt to manta runtime

Signed-off-by: Charles Ferrell <[email protected]>

* add rpc call to manta node

Signed-off-by: Charles Ferrell <[email protected]>

* fix ambiguous name

Signed-off-by: Charles Ferrell <[email protected]>

---------

Signed-off-by: Charles Ferrell <[email protected]>
  • Loading branch information
ferrell-code authored Jun 1, 2023
1 parent fa10f39 commit 3a7f7b9
Show file tree
Hide file tree
Showing 13 changed files with 319 additions and 19 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ pub fn run_with(cli: Cli) -> Result {
collator_options,
id,
hwbench,
rpc::create_common_full,
rpc::create_manta_full,
)
.await
.map(|r| r.0)
Expand Down
64 changes: 64 additions & 0 deletions node/src/rpc/manta.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright 2020-2023 Manta Network.
// This file is part of Manta.
//
// Manta is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Manta is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Manta. If not, see <http://www.gnu.org/licenses/>.

//! Calamari RPC Extensions
use super::*;
use pallet_manta_sbt::{
rpc::{SBTPull, SBTPullApiServer},
runtime::SBTPullLedgerDiffApi,
};

/// Instantiate all RPC extensions for calamari.
pub fn create_manta_full<C, P>(deps: FullDeps<C, P>) -> Result<RpcExtension, sc_service::Error>
where
C: ProvideRuntimeApi<Block>
+ HeaderBackend<Block>
+ AuxStore
+ HeaderMetadata<Block, Error = BlockChainError>
+ Send
+ Sync
+ 'static,
C::Api: frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>,
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
C::Api: BlockBuilder<Block>,
C::Api: SBTPullLedgerDiffApi<Block>,
P: TransactionPool + Sync + Send + 'static,
{
use frame_rpc_system::{System, SystemApiServer};
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};

let mut module = RpcExtension::new(());
let FullDeps {
client,
pool,
deny_unsafe,
} = deps;

module
.merge(System::new(client.clone(), pool, deny_unsafe).into_rpc())
.map_err(|e| sc_service::Error::Other(e.to_string()))?;
module
.merge(TransactionPayment::new(client.clone()).into_rpc())
.map_err(|e| sc_service::Error::Other(e.to_string()))?;

let manta_sbt_rpc: jsonrpsee::RpcModule<SBTPull<Block, C>> = SBTPull::new(client).into_rpc();
module
.merge(manta_sbt_rpc)
.map_err(|e| sc_service::Error::Other(e.to_string()))?;

Ok(module)
}
2 changes: 2 additions & 0 deletions node/src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ use std::sync::Arc;
mod calamari;
mod common;
mod dolphin;
mod manta;

pub use self::manta::create_manta_full;
pub use calamari::create_calamari_full;
pub use common::create_common_full;
pub use dolphin::create_dolphin_full;
Expand Down
4 changes: 0 additions & 4 deletions pallets/manta-sbt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,6 @@ pub mod pallet {
/// Max size in bytes of `mint_name` entered in `RegisteredMint`
#[pallet::constant]
type RegistryBound: Get<u32>;

/// The minimum weight that should remain as lazy migration executes.
#[pallet::constant]
type MinimumWeightRemainInBlock: Get<Weight>;
}

/// Counter for SBT AssetId. Increments by one every time a new asset id is requested.
Expand Down
4 changes: 1 addition & 3 deletions pallets/manta-sbt/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use frame_support::{
AsEnsureOriginWithArg, ConstU128, ConstU16, ConstU32, ConstU64, Everything, GenesisBuild,
IsInVec,
},
weights::{RuntimeDbWeight, Weight},
weights::RuntimeDbWeight,
PalletId,
};

Expand Down Expand Up @@ -136,7 +136,6 @@ parameter_types! {
parameter_types! {
pub const MantaSBTPalletId: PalletId = MANTA_SBT_PALLET_ID;
pub const CustodialAccount: AccountId32 = ALICE;
pub const MinimumWeightRemainInBlock: Weight = Weight::from_ref_time(10000);
}

impl crate::Config for Test {
Expand All @@ -150,7 +149,6 @@ impl crate::Config for Test {
type AdminOrigin = EnsureRoot<AccountId32>;
type Now = Timestamp;
type RegistryBound = ConstU32<200>;
type MinimumWeightRemainInBlock = MinimumWeightRemainInBlock;
}

parameter_types! {
Expand Down
4 changes: 0 additions & 4 deletions runtime/calamari/src/assets_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ use manta_primitives::{
},
constants::{
ASSET_MANAGER_PALLET_ID, CALAMARI_DECIMAL, MANTA_PAY_PALLET_ID, MANTA_SBT_PALLET_ID,
WEIGHT_PER_MILLIS,
},
types::{AccountId, Balance, CalamariAssetId},
};
Expand All @@ -36,7 +35,6 @@ use frame_support::{
pallet_prelude::DispatchResult,
parameter_types,
traits::{AsEnsureOriginWithArg, ConstU128, ConstU16, ConstU32, EitherOfDiverse},
weights::Weight,
PalletId,
};

Expand Down Expand Up @@ -198,7 +196,6 @@ impl pallet_manta_pay::Config for Runtime {

parameter_types! {
pub const MantaSbtPalletId: PalletId = MANTA_SBT_PALLET_ID;
pub const MinimumWeightRemainInBlock: Weight = Weight::from_ref_time(25 * WEIGHT_PER_MILLIS);
}

impl pallet_manta_sbt::Config for Runtime {
Expand All @@ -213,7 +210,6 @@ impl pallet_manta_sbt::Config for Runtime {
EnsureRoot<AccountId>,
pallet_collective::EnsureProportionAtLeast<AccountId, TechnicalCollective, 2, 3>,
>;
type MinimumWeightRemainInBlock = MinimumWeightRemainInBlock;
type Now = Timestamp;
type WeightInfo = weights::pallet_manta_sbt::SubstrateWeight<Runtime>;
}
4 changes: 0 additions & 4 deletions runtime/dolphin/src/assets_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ use manta_primitives::{
},
constants::{
ASSET_MANAGER_PALLET_ID, DOLPHIN_DECIMAL, MANTA_PAY_PALLET_ID, MANTA_SBT_PALLET_ID,
WEIGHT_PER_MILLIS,
},
types::{AccountId, Balance, DolphinAssetId},
};
Expand All @@ -36,7 +35,6 @@ use frame_support::{
pallet_prelude::DispatchResult,
parameter_types,
traits::{AsEnsureOriginWithArg, ConstU128, ConstU16, ConstU32, EitherOfDiverse},
weights::Weight,
PalletId,
};
use frame_system::EnsureRoot;
Expand Down Expand Up @@ -208,7 +206,6 @@ impl pallet_manta_pay::Config for Runtime {

parameter_types! {
pub const MantaSbtPalletId: PalletId = MANTA_SBT_PALLET_ID;
pub const MinimumWeightRemainInBlock: Weight = Weight::from_ref_time(25 * WEIGHT_PER_MILLIS);
}

impl pallet_manta_sbt::Config for Runtime {
Expand All @@ -223,7 +220,6 @@ impl pallet_manta_sbt::Config for Runtime {
pallet_collective::EnsureMembers<AccountId, TechnicalCollective, 2>,
>;
type Now = Timestamp;
type MinimumWeightRemainInBlock = MinimumWeightRemainInBlock;
type RegistryBound = ConstU32<300>;
type WeightInfo = ();
}
6 changes: 6 additions & 0 deletions runtime/manta/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ orml-xtokens = { git = 'https://github.com/manta-network/open-runtime-module-lib
# Self dependencies
manta-collator-selection = { path = '../../pallets/collator-selection', default-features = false }
manta-primitives = { path = '../../primitives/manta', default-features = false }
manta-support = { package = "pallet-manta-support", path = "../../pallets/manta-support", default-features = false }
pallet-asset-manager = { path = '../../pallets/asset-manager', default-features = false }
pallet-manta-sbt = { path = '../../pallets/manta-sbt', default-features = false, features = ["runtime"] }
pallet-parachain-staking = { path = '../../pallets/parachain-staking', default-features = false }
pallet-tx-pause = { path = '../../pallets/tx-pause', default-features = false }
runtime-common = { path = '../common', default-features = false }
Expand Down Expand Up @@ -143,6 +145,7 @@ runtime-benchmarks = [
'orml-xtokens/runtime-benchmarks',
'cumulus-pallet-parachain-system/runtime-benchmarks',
'pallet-xcm-benchmarks/runtime-benchmarks',
'pallet-manta-sbt/runtime-benchmarks',
]
try-runtime = [
'frame-try-runtime',
Expand Down Expand Up @@ -180,6 +183,7 @@ try-runtime = [
'cumulus-pallet-xcm/try-runtime',
'pallet-asset-manager/try-runtime',
'orml-xtokens/try-runtime',
'pallet-manta-sbt/try-runtime',
]
# Set timing constants (e.g. session period) to faster versions to speed up testing.
fast-runtime = []
Expand Down Expand Up @@ -247,6 +251,8 @@ std = [
'pallet-asset-manager/std',
'orml-traits/std',
'orml-xtokens/std',
'pallet-manta-sbt/std',
'manta-support/std',
]
# A feature that should be enabled when the runtime should be build for on-chain
# deployment. This will disable stuff that shouldn't be part of the on-chain wasm
Expand Down
27 changes: 24 additions & 3 deletions runtime/manta/src/assets_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,23 @@

use super::{
weights, xcm_config::SelfReserve, AssetManager, Assets, Balances, CouncilCollective,
NativeTokenExistentialDeposit, Runtime, RuntimeEvent, RuntimeOrigin,
NativeTokenExistentialDeposit, Runtime, RuntimeEvent, RuntimeOrigin, TechnicalCollective,
Timestamp, MANTA,
};

use manta_primitives::{
assets::{
AssetConfig, AssetIdType, AssetLocation, AssetRegistry, AssetRegistryMetadata,
AssetStorageMetadata, BalanceType, LocationType, NativeAndNonNative,
},
constants::{ASSET_MANAGER_PALLET_ID, MANTA_DECIMAL},
constants::{ASSET_MANAGER_PALLET_ID, MANTA_DECIMAL, MANTA_SBT_PALLET_ID},
types::{AccountId, Balance, MantaAssetId},
};

use frame_support::{
pallet_prelude::DispatchResult,
parameter_types,
traits::{AsEnsureOriginWithArg, ConstU32, EitherOfDiverse},
traits::{AsEnsureOriginWithArg, ConstU128, ConstU16, ConstU32, EitherOfDiverse},
PalletId,
};
use frame_system::EnsureRoot;
Expand Down Expand Up @@ -181,3 +182,23 @@ impl pallet_asset_manager::Config for Runtime {
type PalletId = AssetManagerPalletId;
type WeightInfo = weights::pallet_asset_manager::SubstrateWeight<Runtime>;
}

parameter_types! {
pub const MantaSbtPalletId: PalletId = MANTA_SBT_PALLET_ID;
}

impl pallet_manta_sbt::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type PalletId = MantaSbtPalletId;
type Currency = Balances;
type MintsPerReserve = ConstU16<5>;
type ReservePrice = ConstU128<{ 100_000 * MANTA }>;
type SbtMetadataBound = ConstU32<300>;
type RegistryBound = ConstU32<300>;
type AdminOrigin = EitherOfDiverse<
EnsureRoot<AccountId>,
pallet_collective::EnsureProportionAtLeast<AccountId, TechnicalCollective, 2, 3>,
>;
type Now = Timestamp;
type WeightInfo = weights::pallet_manta_sbt::SubstrateWeight<Runtime>;
}
17 changes: 17 additions & 0 deletions runtime/manta/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ use manta_primitives::{
constants::{time::*, RocksDbWeight, STAKING_PALLET_ID, TREASURY_PALLET_ID, WEIGHT_PER_SECOND},
types::{AccountId, Balance, BlockNumber, Hash, Header, Index, Signature},
};
use manta_support::manta_pay::{PullResponse, RawCheckpoint};
pub use pallet_parachain_staking::{InflationInfo, Range};
use pallet_session::ShouldEndSession;
use runtime_common::{
Expand Down Expand Up @@ -260,6 +261,7 @@ impl Contains<RuntimeCall> for MantaFilter {
| RuntimeCall::XTokens(orml_xtokens::Call::transfer {..})
| RuntimeCall::Balances(_)
| RuntimeCall::Preimage(_)
| RuntimeCall::MantaSbt(_)
| RuntimeCall::TransactionPause(_)
| RuntimeCall::AssetManager(pallet_asset_manager::Call::update_outgoing_filtered_assets {..})
| RuntimeCall::Utility(_) => true,
Expand Down Expand Up @@ -810,6 +812,7 @@ construct_runtime!(
// Assets management
Assets: pallet_assets::{Pallet, Call, Storage, Event<T>} = 45,
AssetManager: pallet_asset_manager::{Pallet, Call, Storage, Config<T>, Event<T>} = 46,
MantaSbt: pallet_manta_sbt::{Pallet, Call, Storage, Event<T>} = 49,
}
);

Expand Down Expand Up @@ -880,6 +883,7 @@ mod benches {
[pallet_tx_pause, TransactionPause]
[manta_collator_selection, CollatorSelection]
[pallet_parachain_staking, ParachainStaking]
[pallet_manta_sbt, MantaSbt]
// Nimbus pallets
[pallet_author_inherent, AuthorInherent]
);
Expand Down Expand Up @@ -1051,6 +1055,19 @@ impl_runtime_apis! {
}
}

impl pallet_manta_sbt::runtime::SBTPullLedgerDiffApi<Block> for Runtime {
fn sbt_pull_ledger_diff(
checkpoint: RawCheckpoint,
max_receiver: u64,
max_sender: u64
) -> PullResponse {
MantaSbt::pull_ledger_diff(checkpoint.into(), max_receiver, max_sender)
}
fn sbt_pull_ledger_total_count() -> [u8; 16] {
MantaSbt::pull_ledger_total_count()
}
}

#[cfg(feature = "try-runtime")]
impl frame_try_runtime::TryRuntime<Block> for Runtime {
fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) {
Expand Down
1 change: 1 addition & 0 deletions runtime/manta/src/weights/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub mod pallet_author_inherent;
pub mod pallet_balances;
pub mod pallet_collective;
pub mod pallet_democracy;
pub mod pallet_manta_sbt;
pub mod pallet_membership;
pub mod pallet_multisig;
pub mod pallet_parachain_staking;
Expand Down
Loading

0 comments on commit 3a7f7b9

Please sign in to comment.