Skip to content

Commit

Permalink
NFI Pallet (#866)
Browse files Browse the repository at this point in the history
* Add NFI pallet + some tests

* Add extra unit tests

* Add benchmarks and temp weights

* include weights in lib

* Rebase and add weights

* Fix build errors

* fmt

* Remove Jen subtype

* Address PR comments

* Add burn handling + permissions for collection owner to manually request data

* Update comments and naming for check_permissions function

* Update comments and naming for check_permissions function + add data removed event

* Update dependencies to workspace deps

* Update benchmarks for pallet-nfi on feat/add-nfi-pallet

---------

Co-authored-by: GitHub Action <[email protected]>
  • Loading branch information
JasonTulp and actions-user authored Aug 25, 2024
1 parent 5a722c6 commit b4b578c
Show file tree
Hide file tree
Showing 27 changed files with 2,650 additions and 83 deletions.
23 changes: 23 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ pallet-fee-proxy = { path = "pallet/fee-proxy", default-features = false }
pallet-futurepass = { path = "pallet/futurepass", default-features = false }
pallet-maintenance-mode = { path = "pallet/maintenance-mode", default-features = false }
pallet-marketplace = { path = "pallet/marketplace", default-features = false }
pallet-nfi = { path = "pallet/nfi", default-features = false }
pallet-nft = { path = "pallet/nft", default-features = false }
pallet-nft-rpc = { path = "pallet/nft/rpc", default-features = false }
pallet-nft-rpc-runtime-api = { path = "pallet/nft/rpc/runtime-api", default-features = false }
Expand Down
56 changes: 54 additions & 2 deletions pallet/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ use frame_system::Config;
use scale_info::TypeInfo;
use seed_primitives::{
ethy::{EventClaimId, EventProofId},
AssetId, Balance, CollectionUuid, MetadataScheme, OriginChain, RoyaltiesSchedule, SerialNumber,
TokenCount, TokenId, TokenLockReason,
AccountId, AssetId, Balance, CollectionUuid, MetadataScheme, OriginChain, RoyaltiesSchedule,
SerialNumber, TokenCount, TokenId, TokenLockReason,
};
use sp_core::{bounded::BoundedVec, H160, U256};
use sp_std::{fmt::Debug, vec::Vec};
Expand Down Expand Up @@ -146,6 +146,10 @@ pub trait OnTransferSubscriber {
fn on_nft_transfer(token_id: &TokenId);
}

impl OnTransferSubscriber for () {
fn on_nft_transfer(_token_id: &TokenId) {}
}

/// Subscriber for when a new asset or nft is created
pub trait OnNewAssetSubscriber<RuntimeId> {
/// The nft with the given token_id was transferred.
Expand Down Expand Up @@ -361,6 +365,44 @@ pub trait Xls20MintRequest {
) -> DispatchResult;
}

impl Xls20MintRequest for () {
type AccountId = AccountId;
fn request_xls20_mint(
_who: &Self::AccountId,
_collection_id: CollectionUuid,
_serial_numbers: Vec<SerialNumber>,
_metadata_scheme: MetadataScheme,
) -> DispatchResult {
Ok(())
}
}

pub trait NFIRequest {
type AccountId;

fn request(
who: &Self::AccountId,
collection_id: CollectionUuid,
serial_numbers: Vec<SerialNumber>,
) -> DispatchResult;

fn on_burn(token_id: TokenId);
}

impl NFIRequest for () {
type AccountId = AccountId;

fn request(
_who: &Self::AccountId,
_collection_id: CollectionUuid,
_serial_numbers: Vec<SerialNumber>,
) -> DispatchResult {
Ok(())
}

fn on_burn(_token_id: TokenId) {}
}

pub trait FeeConfig {
fn evm_base_fee_per_gas() -> U256;
fn weight_multiplier() -> Perbill;
Expand Down Expand Up @@ -507,6 +549,10 @@ pub trait NFTExt {

/// Remove a token lock without performing checks
fn remove_token_lock(token_id: TokenId);

fn get_collection_owner(
collection_id: CollectionUuid,
) -> Result<Self::AccountId, DispatchError>;
}

pub trait SFTExt {
Expand All @@ -531,4 +577,10 @@ pub trait SFTExt {
fn get_royalties_schedule(
collection_id: CollectionUuid,
) -> Result<Option<RoyaltiesSchedule<Self::AccountId>>, DispatchError>;

fn get_collection_owner(
collection_id: CollectionUuid,
) -> Result<Self::AccountId, DispatchError>;

fn token_exists(token_id: TokenId) -> bool;
}
36 changes: 6 additions & 30 deletions pallet/common/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,24 +240,6 @@ macro_rules! impl_pallet_assets_ext_config {
#[macro_export]
macro_rules! impl_pallet_nft_config {
($test:ident) => {
pub struct MockXls20MintRequest;
impl Xls20MintRequest for MockXls20MintRequest {
type AccountId = AccountId;
fn request_xls20_mint(
_who: &Self::AccountId,
_collection_id: CollectionUuid,
_serial_numbers: Vec<SerialNumber>,
_metadata_scheme: MetadataScheme,
) -> DispatchResult {
Ok(())
}
}

pub struct MockTransferSubscriber;
impl OnTransferSubscriber for MockTransferSubscriber {
fn on_nft_transfer(_token_id: &TokenId) {}
}

parameter_types! {
pub const NftPalletId: PalletId = PalletId(*b"nftokens");
pub const MaxTokensPerCollection: u32 = 10_000;
Expand All @@ -272,29 +254,22 @@ macro_rules! impl_pallet_nft_config {
type RuntimeCall = RuntimeCall;
type MaxTokensPerCollection = MaxTokensPerCollection;
type MintLimit = MintLimit;
type OnTransferSubscription = MockTransferSubscriber;
type OnTransferSubscription = ();
type OnNewAssetSubscription = ();
type MultiCurrency = AssetsExt;
type PalletId = NftPalletId;
type ParachainId = TestParachainId;
type Xls20MintRequest = MockXls20MintRequest;
type Xls20MintRequest = ();
type WeightInfo = ();
type StringLimit = StringLimit;
type NFIRequest = ();
}
};
}

#[macro_export]
macro_rules! impl_pallet_sft_config {
($test:ident) => {
pub struct MockSftNewAssetSubscription;
impl<RuntimeId> OnNewAssetSubscriber<RuntimeId> for MockSftNewAssetSubscription
where
RuntimeId: From<u32> + Into<u32>,
{
fn on_asset_create(_runtime_id: RuntimeId, _precompile_address_prefix: &[u8; 4]) {}
}

parameter_types! {
pub const SftPalletId: PalletId = PalletId(*b"sftokens");
pub const MaxTokensPerSftCollection: u32 = 10_000;
Expand All @@ -306,15 +281,16 @@ macro_rules! impl_pallet_sft_config {
type RuntimeEvent = RuntimeEvent;
type MultiCurrency = AssetsExt;
type NFTExt = Nft;
type OnTransferSubscription = MockTransferSubscriber;
type OnNewAssetSubscription = MockSftNewAssetSubscription;
type OnTransferSubscription = ();
type OnNewAssetSubscription = ();
type PalletId = SftPalletId;
type ParachainId = TestParachainId;
type StringLimit = StringLimit;
type WeightInfo = ();
type MaxTokensPerSftCollection = MaxTokensPerSftCollection;
type MaxSerialsPerMint = MaxSerialsPerSftMint;
type MaxOwnersPerSftToken = MaxOwnersPerSftToken;
type NFIRequest = ();
}
};
}
Expand Down
1 change: 0 additions & 1 deletion pallet/marketplace/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

use crate as pallet_marketplace;
use seed_pallet_common::test_prelude::*;
use seed_primitives::MetadataScheme;

construct_runtime!(
pub enum Test
Expand Down
Loading

0 comments on commit b4b578c

Please sign in to comment.