Skip to content

Commit

Permalink
Merge pull request #170 from Abstracted-Labs/francisco-mono_repo
Browse files Browse the repository at this point in the history
Merges InvArch-Frames into this repository
  • Loading branch information
Anny0nn authored Aug 20, 2024
2 parents b17cc62 + 291fb10 commit 948abf1
Show file tree
Hide file tree
Showing 55 changed files with 14,322 additions and 18 deletions.
4 changes: 0 additions & 4 deletions invarch/Cargo.lock

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

8 changes: 4 additions & 4 deletions invarch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ pallet-tx-pause = { git = "https://github.com/paritytech/polkadot-sdk.git", bran


# InvArch
pallet-inv4 = { git = "https://github.com/InvArch/InvArch-Frames", branch = "francisco-weight_fixes", default-features = false }
pallet-ocif-staking = { git = "https://github.com/InvArch/InvArch-Frames", branch = "francisco-weight_fixes", default-features = false }
pallet-checked-inflation = { git = "https://github.com/InvArch/InvArch-Frames", branch = "francisco-weight_fixes", default-features = false }
pallet-rings = { git = "https://github.com/InvArch/InvArch-Frames", branch = "francisco-weight_fixes", default-features = false }
pallet-inv4 = { path = "../pallets/INV4/pallet-inv4", default-features = false }
pallet-ocif-staking = { path = "../pallets/OCIF/staking", default-features = false }
pallet-checked-inflation = { path = "../pallets/pallet-checked-inflation", default-features = false }
pallet-rings = { path = "../pallets/pallet-rings", default-features = false }

# Substrate
frame-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.6.0", default-features = false }
Expand Down
46 changes: 46 additions & 0 deletions pallets/.github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Checks

on:
push:
branches: [ main, development ]
pull_request:
branches: [ main, development ]

env:
CARGO_TERM_COLOR: always

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install & display rust toolchain
run: rustup show
- name: Build
run: cargo build --verbose

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install & display rust toolchain
run: rustup show
- name: Run tests
run: cargo test --verbose

clippy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install & display rust toolchain
run: rustup show
- name: Run clippy
run: cargo clippy -- -D warnings
fmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install & display rust toolchain
run: rustup show
- name: Run cargofmt
run: cargo fmt --all -- --check
32 changes: 32 additions & 0 deletions pallets/.github/workflows/rustdoc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Build Rust Docs

on:
push:
branches:
- main

jobs:
rustdoc:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Install deps
run: sudo apt -y install protobuf-compiler

- name: Install & display rust toolchain
run: rustup show

- name: Check targets are installed correctly
run: rustup target list --installed

- name: Build Documentation
run: RUSTDOCFLAGS="--enable-index-page -Zunstable-options" cargo doc --no-deps --document-private-items

- name: Deploy Docs
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_branch: gh-pages
publish_dir: ./target/doc
8 changes: 8 additions & 0 deletions pallets/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Generated by Cargo
# will have compiled files and executables
**/target/

#local dependencies
**/Cargo.lock
.idea/vcs.xml
.idea/workspace.xml
58 changes: 58 additions & 0 deletions pallets/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
[workspace]
resolver = "2"
members = [
"INV4/pallet-inv4",
"OCIF/staking",
"pallet-checked-inflation",
"pallet-rings",
]

[workspace.dependencies]

# crates.io dependencies
codec = { package = "parity-scale-codec", version = "3.6.5", features = [
"derive",
], default-features = false }
log = { version = "0.4.20", default-features = false }
num-traits = { version = "0.2", default-features = false }
scale-info = { version = "2.10.0", default-features = false, features = [
"derive",
] }
serde = { version = "1.0.189", features = ["derive"] }
smallvec = { version = "1.6.1" }

# polkadot-sdk dependencies
frame-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk.git", default-features = false, branch = "release-polkadot-v1.6.0" }
frame-support = { git = "https://github.com/paritytech/polkadot-sdk.git", default-features = false, branch = "release-polkadot-v1.6.0" }
frame-system = { git = "https://github.com/paritytech/polkadot-sdk.git", default-features = false, branch = "release-polkadot-v1.6.0" }
pallet-balances = { git = "https://github.com/paritytech/polkadot-sdk.git", default-features = false, branch = "release-polkadot-v1.6.0" }
pallet-message-queue = { git = "https://github.com/paritytech/polkadot-sdk.git", default-features = false, branch = "release-polkadot-v1.6.0" }
pallet-session = { git = "https://github.com/paritytech/polkadot-sdk.git", default-features = false, branch = "release-polkadot-v1.6.0" }
pallet-timestamp = { git = "https://github.com/paritytech/polkadot-sdk.git", default-features = false, branch = "release-polkadot-v1.6.0" }
pallet-xcm = { git = "https://github.com/paritytech/polkadot-sdk.git", default-features = false, branch = "release-polkadot-v1.6.0" }
sp-api = { git = "https://github.com/paritytech/polkadot-sdk.git", default-features = false, branch = "release-polkadot-v1.6.0" }
sp-arithmetic = { git = "https://github.com/paritytech/polkadot-sdk.git", default-features = false, branch = "release-polkadot-v1.6.0" }
sp-core = { git = "https://github.com/paritytech/polkadot-sdk.git", default-features = false, branch = "release-polkadot-v1.6.0" }
sp-io = { git = "https://github.com/paritytech/polkadot-sdk.git", default-features = false, branch = "release-polkadot-v1.6.0" }
sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk.git", default-features = false, branch = "release-polkadot-v1.6.0" }
sp-staking = { git = "https://github.com/paritytech/polkadot-sdk.git", default-features = false, branch = "release-polkadot-v1.6.0" }
sp-std = { git = "https://github.com/paritytech/polkadot-sdk.git", default-features = false, branch = "release-polkadot-v1.6.0" }
xcm = { package = "staging-xcm", git = "https://github.com/paritytech/polkadot-sdk.git", default-features = false, branch = "release-polkadot-v1.6.0" }
xcm-builder = { package = "staging-xcm-builder", git = "https://github.com/paritytech/polkadot-sdk.git", default-features = false, branch = "release-polkadot-v1.6.0" }
xcm-executor = { package = "staging-xcm-executor", git = "https://github.com/paritytech/polkadot-sdk.git", default-features = false, branch = "release-polkadot-v1.6.0" }


# dev dependencies

cumulus-primitives-core = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.6.0", default-features = false }

orml-asset-registry = { git = "https://github.com/InvArch/open-runtime-module-library.git", default-features = false, branch = "polkadot-v1.6.0" }
orml-tokens2 = { package = "orml-tokens", git = "https://github.com/arrudagates/open-runtime-module-library.git", default-features = false, rev = "bc6b41e8a9539971a2da5d62cf8f550cde985f00" }
orml-traits2 = { package = "orml-traits", git = "https://github.com/arrudagates/open-runtime-module-library.git", default-features = false, rev = "bc6b41e8a9539971a2da5d62cf8f550cde985f00" }

orml-tokens = { package = "orml-tokens", git = "https://github.com/InvArch/open-runtime-module-library.git", default-features = false, branch = "polkadot-v1.6.0" }
orml-traits = { package = "orml-traits", git = "https://github.com/InvArch/open-runtime-module-library.git", default-features = false, branch = "polkadot-v1.6.0" }

# orml-asset-registry = { git = "https://github.com/open-web3-stack/open-runtime-module-library", default-features = false, rev = "7ecebeab7e3dbc2226ed58d32ee159271a8176ae" }
# orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", default-features = false, rev = "7ecebeab7e3dbc2226ed58d32ee159271a8176ae" }
# orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", default-features = false, rev = "7ecebeab7e3dbc2226ed58d32ee159271a8176ae" }
76 changes: 76 additions & 0 deletions pallets/INV4/pallet-inv4/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
[package]
authors = ['InvArchitects <https://github.com/InvArch>']
description = ''
edition = '2021'
homepage = 'https://invarch.network'
license = 'GPLv3'
name = 'pallet-inv4'
repository = 'https://github.com/InvArch/InvArch-Frames'
version = '0.1.0-dev'

[dependencies]
serde = { workspace = true, optional = true }
codec = { package = "parity-scale-codec", version = "3.6.5", default-features = false, features = [
"derive",
"max-encoded-len",
] }
sp-runtime = { workspace = true, default-features = false }
sp-arithmetic = { workspace = true, default-features = false }
sp-std = { workspace = true, default-features = false }
frame-support = { workspace = true, default-features = false }
smallvec = { workspace = true }

scale-info = { workspace = true, default-features = false }

log = { workspace = true, default-features = false }

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

sp-io = { workspace = true, default-features = false }
sp-api = { workspace = true, default-features = false }
sp-core = { workspace = true, default-features = false }

pallet-balances = { workspace = true, default-features = false }

frame-system = { workspace = true, default-features = false } # frame-benchmarking requires system
frame-benchmarking = { workspace = true, default-features = false, optional = true }


xcm = { workspace = true, default-features = false }
orml-tokens2 = { workspace = true, default-features = false }

[dev-dependencies]

orml-traits2 = { workspace = true, default-features = false }
orml-tokens = { workspace = true, default-features = false }
orml-traits = { workspace = true, default-features = false }
orml-asset-registry = { workspace = true, default-features = false }


[features]
default = ["std"]
std = [
"serde",
"codec/std",
"sp-runtime/std",
"sp-std/std",
"frame-support/std",
"frame-system/std",
"sp-io/std",
"scale-info/std",
"pallet-balances/std",
"frame-benchmarking?/std",
"xcm/std",
"orml-asset-registry/std",
"orml-tokens/std",
"orml-tokens2/std",
"orml-traits/std",
"orml-traits2/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"frame-system/runtime-benchmarks",
]
try-runtime = ["frame-support/try-runtime"]
43 changes: 43 additions & 0 deletions pallets/INV4/pallet-inv4/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# INV4 Pallet

## Introduction

The INV4 pallet is designed to manage advanced virtual multisigs, internally referred to as cores. It provides the functionality to create cores, mint and burn the core'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.

## Features

- **Core Creation**: Establish new cores with customizable parameters, including metadata, voting thresholds, and token freeze state.
- **Token Management**: Mint and burn the core's voting tokens to manage the voting power within the core.
- **Multisig Proposals**: Create, vote on, and cancel multisig proposals. Proposals automatically execute if they meet the execution threshold requirements.
- **Vote Management**: Members can vote on proposals, withdraw their votes, and influence the outcome of decisions.
- **Parameter Adjustment**: Core parameters, such as voting thresholds and token freeze state, can be dynamically adjusted by core origins.

## Functionality Overview

### Core Management

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

### Token Operations

- `token_mint`: Mint the core's voting tokens to a specified target, increasing their voting power within the core.
- `token_burn`: Burn the core's voting tokens from a specified target, decreasing their voting power.

### Multisig Operations

- `operate_multisig`: Submit a new multisig proposal. If the proposal meets execution thresholds, it is automatically executed.
- `vote_multisig`: Cast a vote on an existing multisig proposal. Proposals execute automatically if they meet threshold requirements after the vote.
- `withdraw_vote_multisig`: Withdraw a previously cast vote from a multisig proposal.
- `cancel_multisig_proposal`: Cancel an existing multisig proposal. This action can only be performed by a core origin.

### Utility Functions

- `CoreAccountDerivation`: Derive consistent core AccountIds across parachains for seamless interaction.
- `INV4Lookup`: Custom account lookup implementation for converting CoreIds 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.

## Usage

To utilize the INV4 pallet, users must first create a core and receive initial voting tokens. Cores can propose actions, vote on proposals, and execute decisions based on the collective voting power of their members. The pallet's flexible design supports a wide range of multisig use cases, from simple governance decisions to complex, conditional executions.
54 changes: 54 additions & 0 deletions pallets/INV4/pallet-inv4/src/account_derivation.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//! Core Account Derivation.
//!
//! ## Overview
//!
//! 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.
//! - 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;
}

impl<T: Config> CoreAccountDerivation<T> for Pallet<T>
where
T::AccountId: From<[u8; 32]>,
{
/// HashedDescription of the core 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 {
blake2_256(
&(
b"SiblingChain",
Compact::<u32>::from(T::ParaId::get()),
(b"Body", BodyId::Index(core_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 {
Junctions::X2(
Junction::Parachain(T::ParaId::get()),
Junction::Plurality {
id: BodyId::Index(core_id.into()),
part: BodyPart::Voice,
},
)
}
}
Loading

0 comments on commit 948abf1

Please sign in to comment.