Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NFT Origins Pallet #215

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ members = [
"INV4/pallet-inv4",
"OCIF/staking",
"pallet-checked-inflation",
"pallet-rings"
"pallet-rings",
"pallet-nft-origins",
"pallet-core-assets",
]
1 change: 1 addition & 0 deletions INV4/pallet-inv4/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ log = { version = "0.4.14", default-features = false }

# InvArch dependencies
primitives = { package = "invarch-primitives", path = "../../primitives", default-features = false }
pallet-nft-origins = { path = "../../pallet-nft-origins", default-features = false }

sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.43" }
sp-core = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.43" }
Expand Down
7 changes: 4 additions & 3 deletions INV4/pallet-inv4/src/fee_handling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ use sp_runtime::{
};

#[derive(Clone, TypeInfo, Encode, Decode, MaxEncodedLen, Debug, PartialEq, Eq)]
#[repr(u8)]
pub enum FeeAsset {
TNKR,
KSM,
TNKR = 0,
KSM = 1,
}

pub enum FeeAssetNegativeImbalance<TNKRNegativeImbalance, KSMNegativeImbalance> {
Expand Down Expand Up @@ -43,7 +44,7 @@ pub trait MultisigFeeHandler<T: Config> {

fn handle_creation_fee(
imbalance: FeeAssetNegativeImbalance<
<T::Currency as Currency<T::AccountId>>::NegativeImbalance,
<<T as Config>::Currency as Currency<T::AccountId>>::NegativeImbalance,
Credit<T::AccountId, T::Tokens>,
>,
);
Expand Down
33 changes: 32 additions & 1 deletion INV4/pallet-inv4/src/inv4_core.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::pallet::*;
use crate::{
fee_handling::{FeeAsset, FeeAssetNegativeImbalance, MultisigFeeHandler},
multisig::{MultisigMember, MultisigMemberOf},
origin::{ensure_multisig, INV4Origin},
util::derive_core_account,
};
Expand Down Expand Up @@ -54,7 +55,11 @@ where

let seed_balance = <T as Config>::CoreSeedBalance::get();

T::AssetsProvider::mint_into(current_id, &creator, seed_balance)?;
T::AssetsProvider::mint_into(
current_id,
&MultisigMember::AccountId(creator.clone()),
seed_balance,
)?;

let info = CoreInfo {
account: core_account.clone(),
Expand Down Expand Up @@ -143,6 +148,32 @@ where
})
}

pub(crate) fn inner_set_frozen(origin: OriginFor<T>, frozen: bool) -> DispatchResult {
let core_origin = ensure_multisig::<T, OriginFor<T>>(origin)?;
let core_id = core_origin.id;

if frozen {
<T::AssetsProvider as frame_support::traits::fungibles::MutateFreeze<
MultisigMemberOf<T>,
>>::set_freeze(
core_id,
// None of the other arguments matter, the implementation expects set_freeze to freeze the whole asset.
&(),
&MultisigMember::AccountId(core_origin.to_account_id()),
Default::default(),
)
} else {
<T::AssetsProvider as frame_support::traits::fungibles::MutateFreeze<
MultisigMemberOf<T>,
>>::thaw(
core_id,
// None of the other arguments matter, the implementation expects thaw to thaw the whole asset.
&(),
&MultisigMember::AccountId(core_origin.to_account_id()),
)
}
}

pub fn is_asset_frozen(core_id: T::CoreId) -> Option<bool> {
CoreStorage::<T>::get(core_id).map(|c| c.frozen_tokens)
}
Expand Down
103 changes: 85 additions & 18 deletions INV4/pallet-inv4/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ pub mod pallet {

use crate::{
fee_handling::MultisigFeeHandler,
multisig::MultisigMemberOf,
origin::{ensure_multisig_member_account_id, ensure_multisig_member_nft},
voting::{Tally, VoteRecord},
};

Expand Down Expand Up @@ -87,7 +89,9 @@ pub mod pallet {
pub type CallOf<T> = <T as Config>::RuntimeCall;

#[pallet::config]
pub trait Config: frame_system::Config + pallet_balances::Config {
pub trait Config:
frame_system::Config + pallet_balances::Config + pallet_nft_origins::Config
{
/// The IPS Pallet Events
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
/// The IPS ID type
Expand Down Expand Up @@ -142,8 +146,13 @@ pub mod pallet {
#[pallet::constant]
type KSMAssetId: Get<<<Self as Config>::Tokens as Inspect<<Self as frame_system::Config>::AccountId>>::AssetId>;

type AssetsProvider: fungibles::Inspect<Self::AccountId, Balance = BalanceOf<Self>, AssetId = Self::CoreId>
+ fungibles::Mutate<Self::AccountId, AssetId = Self::CoreId>; // + fungibles::Transfer<Self::AccountId, AssetId = Self::CoreId>;
type AssetsProvider: fungibles::Inspect<
MultisigMemberOf<Self>,
Balance = BalanceOf<Self>,
AssetId = Self::CoreId,
> + fungibles::Mutate<MultisigMemberOf<Self>, AssetId = Self::CoreId>
+ fungibles::InspectFreeze<MultisigMemberOf<Self>, Id = ()>
+ fungibles::MutateFreeze<MultisigMemberOf<Self>, AssetId = Self::CoreId>;

type Tokens: Balanced<Self::AccountId> + Inspect<Self::AccountId>;

Expand Down Expand Up @@ -203,7 +212,7 @@ pub mod pallet {
#[pallet::storage]
#[pallet::getter(fn core_members)]
pub type CoreMembers<T: Config> =
StorageDoubleMap<_, Blake2_128Concat, T::CoreId, Blake2_128Concat, T::AccountId, ()>;
StorageDoubleMap<_, Blake2_128Concat, T::CoreId, Blake2_128Concat, MultisigMemberOf<T>, ()>;

#[pallet::event]
#[pallet::generate_deposit(pub(crate) fn deposit_event)]
Expand All @@ -226,13 +235,13 @@ pub mod pallet {
/// IP Tokens were minted
Minted {
core_id: T::CoreId,
target: T::AccountId,
target: MultisigMemberOf<T>,
amount: BalanceOf<T>,
},
/// IP Tokens were burned
Burned {
core_id: T::CoreId,
target: T::AccountId,
target: MultisigMemberOf<T>,
amount: BalanceOf<T>,
},
/// A vote to execute a call has begun. The call needs more votes to pass.
Expand All @@ -241,7 +250,7 @@ pub mod pallet {
MultisigVoteStarted {
core_id: T::CoreId,
executor_account: T::AccountId,
voter: T::AccountId,
voter: MultisigMemberOf<T>,
votes_added: VoteRecord<T>,
call_hash: T::Hash,
},
Expand All @@ -251,15 +260,15 @@ pub mod pallet {
MultisigVoteAdded {
core_id: T::CoreId,
executor_account: T::AccountId,
voter: T::AccountId,
voter: MultisigMemberOf<T>,
votes_added: VoteRecord<T>,
current_votes: Tally<T>,
call_hash: T::Hash,
},
MultisigVoteWithdrawn {
core_id: T::CoreId,
executor_account: T::AccountId,
voter: T::AccountId,
voter: MultisigMemberOf<T>,
votes_removed: VoteRecord<T>,
call_hash: T::Hash,
},
Expand All @@ -269,7 +278,7 @@ pub mod pallet {
MultisigExecuted {
core_id: T::CoreId,
executor_account: T::AccountId,
voter: T::AccountId,
voter: MultisigMemberOf<T>,
call_hash: T::Hash,
call: CallOf<T>,
result: DispatchResult,
Expand Down Expand Up @@ -321,6 +330,7 @@ pub mod pallet {
INV4Origin<T, <T as pallet::Config>::CoreId, <T as frame_system::Config>::AccountId>,
<T as frame_system::Config>::RuntimeOrigin,
>: From<<T as frame_system::Config>::RuntimeOrigin>,
Result<pallet_nft_origins::origin::NftOrigin, <T as frame_system::Config>::RuntimeOrigin>: From<<T as frame_system::Config>::RuntimeOrigin>,
<<T as pallet::Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance: Sum,
{
/// Create IP (Intellectual Property) Set (IPS)
Expand Down Expand Up @@ -354,7 +364,7 @@ pub mod pallet {
pub fn token_mint(
origin: OriginFor<T>,
amount: BalanceOf<T>,
target: T::AccountId,
target: MultisigMemberOf<T>,
) -> DispatchResult {
Pallet::<T>::inner_token_mint(origin, amount, target)
}
Expand All @@ -365,7 +375,7 @@ pub mod pallet {
pub fn token_burn(
origin: OriginFor<T>,
amount: BalanceOf<T>,
target: T::AccountId,
target: MultisigMemberOf<T>,
) -> DispatchResult {
Pallet::<T>::inner_token_burn(origin, amount, target)
}
Expand All @@ -378,34 +388,82 @@ pub mod pallet {
)
)]
pub fn operate_multisig(
caller: OriginFor<T>,
origin: OriginFor<T>,
core_id: T::CoreId,
metadata: Option<BoundedVec<u8, T::MaxMetadata>>,
fee_asset: FeeAsset,
call: Box<<T as pallet::Config>::RuntimeCall>,
) -> DispatchResultWithPostInfo {
let member = ensure_multisig_member_account_id::<T, OriginFor<T>>(origin)?;

Pallet::<T>::inner_operate_multisig(member, core_id, metadata, fee_asset, call)
}

#[pallet::call_index(12)]
#[pallet::weight(1)]
pub fn nft_operate_multisig(
origin: OriginFor<T>,
core_id: T::CoreId,
metadata: Option<BoundedVec<u8, T::MaxMetadata>>,
fee_asset: FeeAsset,
call: Box<<T as pallet::Config>::RuntimeCall>,
) -> DispatchResultWithPostInfo {
Pallet::<T>::inner_operate_multisig(caller, core_id, metadata, fee_asset, call)
let member = ensure_multisig_member_nft::<T, OriginFor<T>>(origin)?;

Pallet::<T>::inner_operate_multisig(member, core_id, metadata, fee_asset, call)
}

#[pallet::call_index(4)]
#[pallet::weight(<T as Config>::WeightInfo::vote_multisig())]
pub fn vote_multisig(
caller: OriginFor<T>,
origin: OriginFor<T>,
core_id: T::CoreId,
call_hash: T::Hash,
aye: bool,
) -> DispatchResultWithPostInfo {
Pallet::<T>::inner_vote_multisig(caller, core_id, call_hash, aye)
let member = ensure_multisig_member_account_id::<T, OriginFor<T>>(origin)?;
//let caller = MultisigMember::AccountId(ensure_signed(caller)?);

Pallet::<T>::inner_vote_multisig(member, core_id, call_hash, aye)
}

#[pallet::call_index(10)]
#[pallet::weight(1)]
pub fn nft_vote_multisig(
origin: OriginFor<T>,
core_id: T::CoreId,
call_hash: T::Hash,
aye: bool,
) -> DispatchResultWithPostInfo {
let member = ensure_multisig_member_nft::<T, OriginFor<T>>(origin)?;

//let caller = MultisigMember::Nft(pallet_nft_origins::origin::ensure_nft::<T, OriginFor<T>>(origin)?);

Pallet::<T>::inner_vote_multisig(member, core_id, call_hash, aye)
}

#[pallet::call_index(5)]
#[pallet::weight(<T as Config>::WeightInfo::withdraw_vote_multisig())]
pub fn withdraw_vote_multisig(
caller: OriginFor<T>,
origin: OriginFor<T>,
core_id: T::CoreId,
call_hash: T::Hash,
) -> DispatchResultWithPostInfo {
Pallet::<T>::inner_withdraw_vote_multisig(caller, core_id, call_hash)
let member = ensure_multisig_member_account_id::<T, OriginFor<T>>(origin)?;

Pallet::<T>::inner_withdraw_vote_multisig(member, core_id, call_hash)
}

#[pallet::call_index(11)]
#[pallet::weight(1)]
pub fn nft_withdraw_vote_multisig(
origin: OriginFor<T>,
core_id: T::CoreId,
call_hash: T::Hash,
) -> DispatchResultWithPostInfo {
let member = ensure_multisig_member_nft::<T, OriginFor<T>>(origin)?;

Pallet::<T>::inner_withdraw_vote_multisig(member, core_id, call_hash)
}

#[pallet::call_index(6)]
Expand All @@ -430,5 +488,14 @@ pub mod pallet {
) -> DispatchResult {
Pallet::<T>::inner_set_parameters(origin, metadata, minimum_support, required_approval, frozen_tokens)
}

#[pallet::call_index(13)]
#[pallet::weight(1)]
pub fn set_frozen(
origin: OriginFor<T>,
frozen: bool,
) -> DispatchResult {
Pallet::<T>::inner_set_frozen(origin, frozen)
}
}
}
Loading
Loading