Skip to content

Commit

Permalink
Fix: Broken storage and final renames
Browse files Browse the repository at this point in the history
  • Loading branch information
Anny0nn committed Sep 2, 2024
1 parent a9b4141 commit 227eab9
Show file tree
Hide file tree
Showing 44 changed files with 1,989 additions and 2,029 deletions.
2 changes: 1 addition & 1 deletion invarch/node/src/rpc.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! A collection of node-specific RPC methods.
//! Substrate provides the `sc-rpc` crate, which defines the core RPC layer
//! Substrate provides the `sc-rpc` crate, which defines the dao RPC layer
//! used by Substrate nodes. This file extends those RPC definitions with
//! capabilities that are specific to this project's runtime configuration.
Expand Down
46 changes: 23 additions & 23 deletions invarch/runtime/src/dao_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ use sp_runtime::traits::{One, SignedExtension, Zero};
parameter_types! {
pub const MaxMetadata: u32 = 10000;
pub const MaxCallers: u32 = 10000;
pub const CoreSeedBalance: Balance = 1000000u128;
pub const CoreCreationFee: Balance = UNIT * 1000;
pub const DaoSeedBalance: Balance = 1000000u128;
pub const DaoCreationFee: Balance = UNIT * 1000;

pub const RelayCoreCreationFee: Balance = UNIT;
pub const RelayDaoCreationFee: Balance = UNIT;
pub const MaxCallSize: u32 = 50 * 1024;

pub ParaId: u32 = ParachainInfo::parachain_id().into();
Expand All @@ -33,21 +33,21 @@ parameter_types! {

impl pallet_dao_manager::Config for Runtime {
type MaxMetadata = MaxMetadata;
type CoreId = CommonId;
type DaoId = CommonId;
type RuntimeEvent = RuntimeEvent;
type Currency = Balances;
type RuntimeCall = RuntimeCall;
type MaxCallers = MaxCallers;
type CoreSeedBalance = CoreSeedBalance;
type DaoSeedBalance = DaoSeedBalance;
type AssetsProvider = CoreAssets;
type RuntimeOrigin = RuntimeOrigin;
type CoreCreationFee = CoreCreationFee;
type DaoCreationFee = DaoCreationFee;
type FeeCharger = FeeCharger;
type WeightInfo = pallet_dao_manager::weights::SubstrateWeight<Runtime>;

type Tokens = NoTokens;
type RelayAssetId = NoId;
type RelayCoreCreationFee = RelayCoreCreationFee;
type RelayDaoCreationFee = RelayDaoCreationFee;

type MaxCallSize = MaxCallSize;

Expand Down Expand Up @@ -196,13 +196,13 @@ impl MultisigFeeHandler<Runtime> for FeeCharger {
}

orml_traits::parameter_type_with_key! {
pub CoreExistentialDeposits: |_currency_id: <Runtime as pallet_dao_manager::Config>::CoreId| -> Balance {
pub DaoExistentialDeposits: |_currency_id: <Runtime as pallet_dao_manager::Config>::DaoId| -> Balance {
Balance::one()
};
}

pub struct CoreDustRemovalWhitelist;
impl Contains<AccountId> for CoreDustRemovalWhitelist {
pub struct DaoDustRemovalWhitelist;
impl Contains<AccountId> for DaoDustRemovalWhitelist {
fn contains(_: &AccountId) -> bool {
true
}
Expand All @@ -212,17 +212,17 @@ pub struct DisallowIfFrozen;
impl
orml_traits::currency::OnTransfer<
AccountId,
<Runtime as pallet_dao_manager::Config>::CoreId,
<Runtime as pallet_dao_manager::Config>::DaoId,
Balance,
> for DisallowIfFrozen
{
fn on_transfer(
currency_id: <Runtime as pallet_dao_manager::Config>::CoreId,
currency_id: <Runtime as pallet_dao_manager::Config>::DaoId,
_from: &AccountId,
_to: &AccountId,
_amount: Balance,
) -> sp_runtime::DispatchResult {
if let Some(true) = crate::DaoManager::is_asset_frozen(currency_id) {
if let Some(true) = crate::INV4::is_asset_frozen(currency_id) {
Err(sp_runtime::DispatchError::Token(
sp_runtime::TokenError::Frozen,
))
Expand All @@ -233,28 +233,28 @@ impl
}

pub struct HandleNewMembers;
impl orml_traits::Happened<(AccountId, <Runtime as pallet_dao_manager::Config>::CoreId)>
impl orml_traits::Happened<(AccountId, <Runtime as pallet_dao_manager::Config>::DaoId)>
for HandleNewMembers
{
fn happened((member, core_id): &(AccountId, <Runtime as pallet_dao_manager::Config>::CoreId)) {
crate::DaoManager::add_member(core_id, member)
fn happened((member, dao_id): &(AccountId, <Runtime as pallet_dao_manager::Config>::DaoId)) {
crate::INV4::add_member(dao_id, member)
}
}

pub struct HandleRemovedMembers;
impl orml_traits::Happened<(AccountId, <Runtime as pallet_dao_manager::Config>::CoreId)>
impl orml_traits::Happened<(AccountId, <Runtime as pallet_dao_manager::Config>::DaoId)>
for HandleRemovedMembers
{
fn happened((member, core_id): &(AccountId, <Runtime as pallet_dao_manager::Config>::CoreId)) {
crate::DaoManager::remove_member(core_id, member)
fn happened((member, dao_id): &(AccountId, <Runtime as pallet_dao_manager::Config>::DaoId)) {
crate::INV4::remove_member(dao_id, member)
}
}

pub struct INV4TokenHooks;
impl
orml_traits::currency::MutationHooks<
AccountId,
<Runtime as pallet_dao_manager::Config>::CoreId,
<Runtime as pallet_dao_manager::Config>::DaoId,
Balance,
> for INV4TokenHooks
{
Expand All @@ -272,12 +272,12 @@ impl orml_tokens::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Balance = Balance;
type Amount = i128;
type CurrencyId = <Runtime as pallet_dao_manager::Config>::CoreId;
type CurrencyId = <Runtime as pallet_dao_manager::Config>::DaoId;
type WeightInfo = ();
type ExistentialDeposits = CoreExistentialDeposits;
type ExistentialDeposits = DaoExistentialDeposits;
type MaxLocks = ConstU32<0u32>;
type MaxReserves = ConstU32<0u32>;
type DustRemovalWhitelist = CoreDustRemovalWhitelist;
type DustRemovalWhitelist = DaoDustRemovalWhitelist;
type ReserveIdentifier = [u8; 8];
type CurrencyHooks = INV4TokenHooks;
}
6 changes: 3 additions & 3 deletions invarch/runtime/src/inflation.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
balances::NegativeImbalance, Balance, Balances, BlockNumber, DaoStaking, Runtime, RuntimeEvent,
DAYS,
balances::NegativeImbalance, Balance, Balances, BlockNumber, OcifStaking, Runtime,
RuntimeEvent, DAYS,
};
use frame_support::{parameter_types, traits::OnUnbalanced};
use sp_runtime::Perbill;
Expand All @@ -19,7 +19,7 @@ parameter_types! {
pub struct DealWithInflation;
impl OnUnbalanced<NegativeImbalance> for DealWithInflation {
fn on_unbalanced(amount: NegativeImbalance) {
DaoStaking::rewards(amount);
OcifStaking::rewards(amount);
}
}

Expand Down
8 changes: 4 additions & 4 deletions invarch/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ pub type Executive = frame_executive::Executive<
/// Opaque types. These are used by the CLI to instantiate machinery that don't need to know
/// the specifics of the runtime. They can then be made to be agnostic over specific formats
/// of data like extrinsics, allowing for them to continue syncing the network through upgrades
/// to even the core data structures.
/// to even the dao data structures.
pub mod opaque {
use super::*;
use sp_runtime::{generic, traits::BlakeTwo256};
Expand Down Expand Up @@ -448,7 +448,7 @@ impl From<RuntimeOrigin> for Result<frame_system::RawOrigin<AccountId>, RuntimeO
fn from(val: RuntimeOrigin) -> Self {
match val.caller {
OriginCaller::system(l) => Ok(l),
OriginCaller::DaoManager(pallet_dao_manager::origin::INV4Origin::Multisig(l)) => {
OriginCaller::INV4(pallet_dao_manager::origin::DaoOrigin::Multisig(l)) => {
Ok(frame_system::RawOrigin::Signed(l.to_account_id()))
}
_ => Err(val),
Expand Down Expand Up @@ -494,9 +494,9 @@ construct_runtime_modified!(
Identity: pallet_identity = 40,

CheckedInflation: pallet_checked_inflation= 50,
DaoStaking: pallet_dao_staking = 51,
OcifStaking: pallet_dao_staking = 51,

DaoManager: pallet_dao_manager = 71,
INV4: pallet_dao_manager = 71,
CoreAssets: orml_tokens = 72,
// 73 reserved for pallet-rings

Expand Down
8 changes: 4 additions & 4 deletions invarch/runtime/src/staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ use pallet_dao_staking::primitives::CustomAggregateMessageOrigin;
parameter_types! {
pub const BlocksPerEra: BlockNumber = DAYS;
pub const RegisterDeposit: Balance = 5000 * UNIT;
pub const MaxStakersPerCore: u32 = 10000;
pub const MaxStakersPerDao: u32 = 10000;
// Temporarily dropping down from 50 to 5.
pub const MinimumStakingAmount: Balance = 5 * UNIT;
pub const MaxEraStakeValues: u32 = 5;
pub const MaxUnlockingChunks: u32 = 5;
pub const UnbondingPeriod: u32 = 28;
pub const OcifStakingPot: PalletId = PalletId(*b"inv/stak");
pub const RewardRatio: (u32, u32) = (60, 40);
pub const StakeThresholdForActiveCore: Balance = 250_000 * UNIT;
pub const StakeThresholdForActiveDao: Balance = 250_000 * UNIT;
pub const MaxNameLength: u32 = 20;
pub const MaxDescriptionLength: u32 = 300;
pub const MaxImageUrlLength: u32 = 100;
Expand All @@ -28,15 +28,15 @@ impl pallet_dao_staking::Config for Runtime {
type BlocksPerEra = BlocksPerEra;
type RegisterDeposit = RegisterDeposit;
type RuntimeEvent = RuntimeEvent;
type MaxStakersPerCore = MaxStakersPerCore;
type MaxStakersPerDao = MaxStakersPerDao;
type ExistentialDeposit = ExistentialDeposit;
type PotId = OcifStakingPot;
type MaxUnlocking = MaxUnlockingChunks;
type UnbondingPeriod = UnbondingPeriod;
type MinimumStakingAmount = MinimumStakingAmount;
type MaxEraStakeValues = MaxEraStakeValues;
type RewardRatio = RewardRatio;
type StakeThresholdForActiveCore = StakeThresholdForActiveCore;
type StakeThresholdForActiveDao = StakeThresholdForActiveDao;
type MaxNameLength = MaxNameLength;
type MaxDescriptionLength = MaxDescriptionLength;
type MaxImageUrlLength = MaxImageUrlLength;
Expand Down
2 changes: 1 addition & 1 deletion pallets/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Currently, InvArch features a multichain multisignature solution & DAO staking p
# Pallet Library

## [DAO Manager](./pallet-dao-manager/)
- The DAO Manager pallet is designed to manage advanced virtual multisigs (DAOs), internally referred to as cores.
- The DAO Manager pallet is designed to manage advanced virtual multisigs (DAOs), OLD: internally referred to as cores.
- [`Docs.rs`](https://abstracted-labs.github.io/InvArch/pallet_dao_manager/index.html)
- Articles:
- [`The SDK. (Old)`](https://invarch.medium.com/the-saturn-sdk-c46b4e40f46e)
Expand Down
8 changes: 3 additions & 5 deletions pallets/pallet-dao-manager/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# DAO Manager Pallet

## Introduction
*TODO!(Rename all code referenced of core to DAO).*
*core == DAO or multisig.*

The DAO Manager pallet is designed to manage advanced virtual multisigs, internally referred to as DAOs. It provides the functionality to create DAOs, mint and burn the DAO's voting tokens, and manage multisig proposals. This pallet is a comprehensive solution for decentralized decision-making processes, allowing for flexible and secure management of multisig operations.

Expand All @@ -18,7 +16,7 @@ The DAO Manager pallet is designed to manage advanced virtual multisigs, interna

### DAO Management

- `create_core`: Initialize a new DAO with specific parameters and distribute initial voting tokens to the creator.
- `create_dao`: Initialize a new DAO with specific parameters and distribute initial voting tokens to the creator.
- `set_parameters`: Modify DAO parameters, including voting thresholds, metadata, and token freeze state.

### Token Operations
Expand All @@ -35,8 +33,8 @@ The DAO Manager pallet is designed to manage advanced virtual multisigs, interna

### Utility Functions

- `CoreAccountDerivation`: Derive consistent DAO AccountIds across parachains for seamless interaction.
- `INV4Lookup`: Custom account lookup implementation for converting DaoIds to AccountIds.
- `DaoAccountDerivation`: Derive consistent DAO AccountIds across parachains for seamless interaction.
- `DaoLookup`: Custom account lookup implementation for converting DaoIds to AccountIds.
- `FeeAsset`: Define the asset used by the multisig for paying transaction fees.
- `MultisigFeeHandler`: Manage fee payments for multisig operations, supporting both native and non-native assets.

Expand Down
30 changes: 14 additions & 16 deletions pallets/pallet-dao-manager/src/account_derivation.rs
Original file line number Diff line number Diff line change
@@ -1,54 +1,52 @@
//! Dao Account Derivation.
//!
//! ## Overview
//! *TODO!( rename all code referenced of core to dao).*
//! *core == DAO or multisig.*
//!
//! This module defines a method for generating account addresses, and how it's implemented within this
//! pallet. We use a custom derivation scheme to ensure that when a multisig is created, its AccountId
//! remains consistent across different parachains, promoting seamless interaction.
//!
//! ### The module contains:
//! - `CoreAccountDerivation` trait: The interface for our derivation method.
//! - `DaoAccountDerivation` trait: The interface for our derivation method.
//! - Pallet implementation: The specific logic used to derive AccountIds.
use crate::{Config, Pallet};
use codec::{Compact, Encode};
use frame_support::traits::Get;
use sp_io::hashing::blake2_256;
use xcm::v3::{BodyId, BodyPart, Junction, Junctions};
/// Trait providing the XCM location and the derived account of a core.
pub trait CoreAccountDerivation<T: Config> {
/// Derives the core's AccountId.
fn derive_core_account(core_id: T::CoreId) -> T::AccountId;
/// Specifies a core's location.
fn core_location(core_id: T::CoreId) -> Junctions;
/// Trait providing the XCM location and the derived account of a dao.
pub trait DaoAccountDerivation<T: Config> {
/// Derives the dao's AccountId.
fn derive_dao_account(dao_id: T::DaoId) -> T::AccountId;
/// Specifies a dao's location.
fn dao_location(dao_id: T::DaoId) -> Junctions;
}

impl<T: Config> CoreAccountDerivation<T> for Pallet<T>
impl<T: Config> DaoAccountDerivation<T> for Pallet<T>
where
T::AccountId: From<[u8; 32]>,
{
/// HashedDescription of the core location from the perspective of a sibling chain.
/// HashedDescription of the dao location from the perspective of a sibling chain.
/// This derivation allows the local account address to match the account address in other parachains.
/// Reference: https://github.com/paritytech/polkadot-sdk/blob/master/polkadot/xcm/xcm-builder/src/location_conversion.rs
fn derive_core_account(core_id: T::CoreId) -> T::AccountId {
fn derive_dao_account(dao_id: T::DaoId) -> T::AccountId {
blake2_256(
&(
b"SiblingChain",
Compact::<u32>::from(T::ParaId::get()),
(b"Body", BodyId::Index(core_id.into()), BodyPart::Voice).encode(),
(b"Body", BodyId::Index(dao_id.into()), BodyPart::Voice).encode(),
)
.encode(),
)
.into()
}
/// Core location is defined as a plurality within the parachain.
fn core_location(core_id: T::CoreId) -> Junctions {
/// DAO location is defined as a plurality within the parachain.
fn dao_location(dao_id: T::DaoId) -> Junctions {
Junctions::X2(
Junction::Parachain(T::ParaId::get()),
Junction::Plurality {
id: BodyId::Index(core_id.into()),
id: BodyId::Index(dao_id.into()),
part: BodyPart::Voice,
},
)
Expand Down
Loading

0 comments on commit 227eab9

Please sign in to comment.