Skip to content

Commit

Permalink
Merge pull request #289 from bit-country/feature/spp-wip
Browse files Browse the repository at this point in the history
SPP implementation v0
  • Loading branch information
justinphamnz authored Nov 30, 2023
2 parents 141df64 + f2c6049 commit 0f29ab8
Show file tree
Hide file tree
Showing 62 changed files with 4,544 additions and 595 deletions.
57 changes: 57 additions & 0 deletions Cargo.lock

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

89 changes: 45 additions & 44 deletions Cargo.toml

Large diffs are not rendered by default.

18 changes: 11 additions & 7 deletions modules/bridge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use sp_core::{H160, U256};
use sp_std::prelude::*;

pub use pallet::*;
use primitives::{Balance, FungibleTokenId};
use primitives::FungibleTokenId;

pub type ResourceId = H160;
pub type ChainId = u8;
Expand All @@ -29,12 +29,12 @@ pub mod pallet {
use frame_support::traits::{Currency, ExistenceRequirement, LockableCurrency, ReservableCurrency};
use frame_support::PalletId;
use orml_traits::MultiCurrency;
use sp_arithmetic::traits::{CheckedMul, Saturating, Zero};
use sp_runtime::traits::{AccountIdConversion, CheckedDiv};
use sp_runtime::{ArithmeticError, ModuleError};
use sp_arithmetic::traits::{Saturating, Zero};
use sp_runtime::traits::AccountIdConversion;
use sp_runtime::ModuleError;

use core_primitives::NFTTrait;
use primitives::evm::CurrencyIdType::FungibleToken;

use primitives::{Attributes, ClassId, NftMetadata, TokenId};

use super::*;
Expand Down Expand Up @@ -300,7 +300,11 @@ pub mod pallet {
Ok(())
}
Err(err) => match err {
DispatchError::Module(ModuleError { index, error, message }) => {
DispatchError::Module(ModuleError {
index: _,
error: _,
message,
}) => {
if message == Some("AssetInfoNotFound") {
if let Ok(_mint_succeeded) =
T::NFTHandler::mint_token_with_id(&to, class_id, token_id, metadata, Attributes::new())
Expand Down Expand Up @@ -335,7 +339,7 @@ pub mod pallet {
let bridge_id = T::PalletId::get().into_account_truncating();

ensure!(BridgeFee::<T>::contains_key(&chain_id), Error::<T>::FeeOptionsMissing);
let (min_fee, fee_scale) = Self::bridge_fee(chain_id);
let (min_fee, _fee_scale) = Self::bridge_fee(chain_id);

T::Currency::transfer(&source, &bridge_id, min_fee.into(), ExistenceRequirement::AllowDeath)?;

Expand Down
84 changes: 40 additions & 44 deletions modules/bridge/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,18 @@
use std::collections::BTreeMap;
use std::vec;

use frame_support::traits::{EqualPrivilegeOnly, Nothing};
use frame_support::traits::Nothing;
use frame_support::{construct_runtime, ord_parameter_types, pallet_prelude::Hooks, parameter_types, PalletId};
use frame_system::{EnsureRoot, EnsureSignedBy};
use frame_system::EnsureRoot;
use orml_traits::parameter_type_with_key;
use sp_core::H256;
use sp_runtime::traits::AccountIdConversion;
use sp_runtime::{testing::Header, traits::IdentityLookup, ModuleError, Perbill};

use auction_manager::{Auction, AuctionInfo, AuctionItem, AuctionType, CheckAuctionItemHandler, ListingLevel};
use core_primitives::{
Attributes, CollectionType, MetaverseInfo, MetaverseMetadata, MetaverseTrait, NFTTrait, NftAssetData, NftClassData,
NftMetadata, TokenType,
};
use core_primitives::{Attributes, CollectionType, NFTTrait, NftClassData, NftMetadata, TokenType};
use primitives::{
continuum::MapTrait, estate::Estate, Amount, AuctionId, ClassId, EstateId, FungibleTokenId, GroupCollectionId,
ItemId, MapSpotId, NftOffer, TokenId, UndeployedLandBlockId,
continuum::MapTrait, Amount, ClassId, EstateId, FungibleTokenId, GroupCollectionId, MapSpotId, TokenId,
UndeployedLandBlockId,
};

use crate as bridge;
Expand Down Expand Up @@ -283,7 +279,7 @@ impl NFTTrait<AccountId, Balance> for MockNFTHandler {
{
return Ok(true);
}
if (nft_value.1 == 5) {
if nft_value.1 == 5 {
return Err(DispatchError::Module(ModuleError {
index: 5,
error: [0, 0, 0, 0],
Expand All @@ -293,7 +289,7 @@ impl NFTTrait<AccountId, Balance> for MockNFTHandler {
Ok(false)
}

fn is_stackable(asset_id: (Self::ClassId, Self::TokenId)) -> Result<bool, DispatchError> {
fn is_stackable(_asset_id: (Self::ClassId, Self::TokenId)) -> Result<bool, DispatchError> {
Ok(false)
}

Expand All @@ -306,19 +302,19 @@ impl NFTTrait<AccountId, Balance> for MockNFTHandler {
}
Ok(false)
}
fn get_nft_group_collection(nft_collection: &Self::ClassId) -> Result<GroupCollectionId, DispatchError> {
fn get_nft_group_collection(_nft_collection: &Self::ClassId) -> Result<GroupCollectionId, DispatchError> {
Ok(ASSET_COLLECTION_ID)
}

fn create_token_class(
sender: &AccountId,
metadata: NftMetadata,
attributes: Attributes,
_metadata: NftMetadata,
_attributes: Attributes,
collection_id: GroupCollectionId,
token_type: TokenType,
collection_type: CollectionType,
royalty_fee: Perbill,
mint_limit: Option<u32>,
_token_type: TokenType,
_collection_type: CollectionType,
_royalty_fee: Perbill,
_mint_limit: Option<u32>,
) -> Result<ClassId, DispatchError> {
match *sender {
ALICE => {
Expand All @@ -339,8 +335,8 @@ impl NFTTrait<AccountId, Balance> for MockNFTHandler {
fn mint_token(
sender: &AccountId,
class_id: ClassId,
metadata: NftMetadata,
attributes: Attributes,
_metadata: NftMetadata,
_attributes: Attributes,
) -> Result<TokenId, DispatchError> {
match *sender {
ALICE => Ok(1),
Expand All @@ -364,26 +360,26 @@ impl NFTTrait<AccountId, Balance> for MockNFTHandler {
}
}

fn transfer_nft(from: &AccountId, to: &AccountId, nft: &(Self::ClassId, Self::TokenId)) -> DispatchResult {
fn transfer_nft(_from: &AccountId, _to: &AccountId, _nft: &(Self::ClassId, Self::TokenId)) -> DispatchResult {
Ok(())
}

fn check_item_on_listing(class_id: Self::ClassId, token_id: Self::TokenId) -> Result<bool, DispatchError> {
fn check_item_on_listing(_class_id: Self::ClassId, _token_id: Self::TokenId) -> Result<bool, DispatchError> {
Ok(true)
}

fn burn_nft(account: &AccountId, nft: &(Self::ClassId, Self::TokenId)) -> DispatchResult {
fn burn_nft(_account: &AccountId, _nft: &(Self::ClassId, Self::TokenId)) -> DispatchResult {
Ok(())
}
fn is_transferable(nft: &(Self::ClassId, Self::TokenId)) -> Result<bool, DispatchError> {
fn is_transferable(_nft: &(Self::ClassId, Self::TokenId)) -> Result<bool, DispatchError> {
Ok(true)
}

fn get_class_fund(class_id: &Self::ClassId) -> AccountId {
fn get_class_fund(_class_id: &Self::ClassId) -> AccountId {
CLASS_FUND_ID
}

fn get_nft_detail(asset_id: (Self::ClassId, Self::TokenId)) -> Result<NftClassData<Balance>, DispatchError> {
fn get_nft_detail(_asset_id: (Self::ClassId, Self::TokenId)) -> Result<NftClassData<Balance>, DispatchError> {
let new_data = NftClassData {
deposit: 0,
attributes: test_attributes(1),
Expand All @@ -397,11 +393,11 @@ impl NFTTrait<AccountId, Balance> for MockNFTHandler {
Ok(new_data)
}

fn set_lock_collection(class_id: Self::ClassId, is_locked: bool) -> sp_runtime::DispatchResult {
fn set_lock_collection(_class_id: Self::ClassId, _is_locked: bool) -> sp_runtime::DispatchResult {
todo!()
}

fn set_lock_nft(token_id: (Self::ClassId, Self::TokenId), is_locked: bool) -> sp_runtime::DispatchResult {
fn set_lock_nft(_token_id: (Self::ClassId, Self::TokenId), _is_locked: bool) -> sp_runtime::DispatchResult {
todo!()
}

Expand All @@ -419,20 +415,20 @@ impl NFTTrait<AccountId, Balance> for MockNFTHandler {
Ok(new_data)
}

fn get_total_issuance(class_id: Self::ClassId) -> Result<Self::TokenId, DispatchError> {
fn get_total_issuance(_class_id: Self::ClassId) -> Result<Self::TokenId, DispatchError> {
Ok(10u64)
}

fn get_asset_owner(asset_id: &(Self::ClassId, Self::TokenId)) -> Result<AccountId, DispatchError> {
fn get_asset_owner(_asset_id: &(Self::ClassId, Self::TokenId)) -> Result<AccountId, DispatchError> {
Ok(ALICE)
}

fn mint_token_with_id(
sender: &AccountId,
class_id: Self::ClassId,
token_id: Self::TokenId,
metadata: NftMetadata,
attributes: Attributes,
_token_id: Self::TokenId,
_metadata: NftMetadata,
_attributes: Attributes,
) -> Result<Self::TokenId, DispatchError> {
match *sender {
ALICE => Ok(1),
Expand All @@ -456,31 +452,31 @@ impl NFTTrait<AccountId, Balance> for MockNFTHandler {
}
}

fn get_free_stackable_nft_balance(who: &AccountId, asset_id: &(Self::ClassId, Self::TokenId)) -> Balance {
fn get_free_stackable_nft_balance(_who: &AccountId, _asset_id: &(Self::ClassId, Self::TokenId)) -> Balance {
1000
}

fn reserve_stackable_nft_balance(
who: &AccountId,
asset_id: &(Self::ClassId, Self::TokenId),
amount: Balance,
_who: &AccountId,
_asset_id: &(Self::ClassId, Self::TokenId),
_amount: Balance,
) -> DispatchResult {
Ok(())
}

fn unreserve_stackable_nft_balance(
who: &AccountId,
asset_id: &(Self::ClassId, Self::TokenId),
amount: Balance,
_who: &AccountId,
_asset_id: &(Self::ClassId, Self::TokenId),
_amount: Balance,
) -> sp_runtime::DispatchResult {
Ok(())
}

fn transfer_stackable_nft(
sender: &AccountId,
to: &AccountId,
nft: &(Self::ClassId, Self::TokenId),
amount: Balance,
_sender: &AccountId,
_to: &AccountId,
_nft: &(Self::ClassId, Self::TokenId),
_amount: Balance,
) -> sp_runtime::DispatchResult {
Ok(())
}
Expand Down
11 changes: 4 additions & 7 deletions modules/bridge/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
#![cfg(test)]

use std::str::{from_utf8, FromStr};
use std::str::FromStr;

use frame_support::{assert_noop, assert_ok};
use frame_support::assert_ok;
use sp_core::H160;

use mock::{Balances, BridgeModule, ExtBuilder, One, Runtime, RuntimeEvent, RuntimeOrigin, System, Tokens};
use primitives::evm::{CurrencyIdType, EvmAddress, H160_POSITION_CURRENCY_ID_TYPE, H160_POSITION_TOKEN};
use primitives::FungibleTokenId::FungibleToken;
use primitives::{TokenId, TokenSymbol};
use mock::{Balances, BridgeModule, ExtBuilder, RuntimeOrigin};

use crate::mock::{BridgeSovereignPalletId, ALICE, BOB};
use crate::mock::{ALICE, BOB};

use super::*;

Expand Down
10 changes: 3 additions & 7 deletions node/src/chain_spec/metaverse.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::collections::BTreeMap;
use std::str::FromStr;

use hex_literal::hex;
Expand All @@ -8,16 +7,13 @@ use sp_consensus_aura::sr25519::AuthorityId as AuraId;
use sp_core::crypto::UncheckedInto;
use sp_core::{sr25519, Pair, Public, H160, U256};
use sp_finality_grandpa::AuthorityId as GrandpaId;
use sp_runtime::{
traits::{IdentifyAccount, Verify},
Perbill,
};
use sp_runtime::traits::{IdentifyAccount, Verify};

use metaverse_runtime::{
constants::currency::*, opaque::SessionKeys, wasm_binary_unwrap, AccountId, AuraConfig, BalancesConfig,
BaseFeeConfig, CollatorSelectionConfig, DemocracyConfig, EVMConfig, EstateConfig, EthereumConfig, GenesisAccount,
GenesisConfig, GrandpaConfig, MintingRange, MintingRateInfo, OracleMembershipConfig, SessionConfig, Signature,
SudoConfig, SystemConfig,
GenesisConfig, GrandpaConfig, MintingRateInfo, OracleMembershipConfig, SessionConfig, Signature, SudoConfig,
SystemConfig,
};
use primitives::Balance;

Expand Down
Loading

0 comments on commit 0f29ab8

Please sign in to comment.