diff --git a/Cargo.lock b/Cargo.lock
index 26317f6937..48fa6aaae7 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -24,7 +24,7 @@ dependencies = [
"parity-scale-codec",
"scale-info",
"serde",
- "sha3",
+ "sha3 0.10.6",
"sp-core",
"sp-io",
"sp-runtime",
@@ -690,7 +690,7 @@ version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b"
dependencies = [
- "block-padding",
+ "block-padding 0.1.5",
"byte-tools",
"byteorder",
"generic-array 0.12.4",
@@ -702,6 +702,7 @@ version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4"
dependencies = [
+ "block-padding 0.2.1",
"generic-array 0.14.6",
]
@@ -723,6 +724,12 @@ dependencies = [
"byte-tools",
]
+[[package]]
+name = "block-padding"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae"
+
[[package]]
name = "blocking"
version = "1.2.0"
@@ -2260,7 +2267,7 @@ dependencies = [
"rlp",
"scale-info",
"serde",
- "sha3",
+ "sha3 0.10.6",
"triehash",
]
@@ -2303,7 +2310,7 @@ dependencies = [
"rlp",
"scale-info",
"serde",
- "sha3",
+ "sha3 0.10.6",
]
[[package]]
@@ -2337,7 +2344,7 @@ dependencies = [
"environmental",
"evm-core",
"primitive-types",
- "sha3",
+ "sha3 0.10.6",
]
[[package]]
@@ -4876,13 +4883,16 @@ dependencies = [
"pallet-evm-precompile-bn128",
"pallet-evm-precompile-call-permit",
"pallet-evm-precompile-collective",
+ "pallet-evm-precompile-conviction-voting",
"pallet-evm-precompile-crowdloan-rewards",
"pallet-evm-precompile-democracy",
"pallet-evm-precompile-dispatch",
"pallet-evm-precompile-modexp",
"pallet-evm-precompile-parachain-staking",
+ "pallet-evm-precompile-preimage",
"pallet-evm-precompile-proxy",
"pallet-evm-precompile-randomness",
+ "pallet-evm-precompile-referenda",
"pallet-evm-precompile-relay-encoder",
"pallet-evm-precompile-sha3fips",
"pallet-evm-precompile-simple",
@@ -4923,7 +4933,7 @@ dependencies = [
"scale-info",
"serde",
"session-keys-primitives",
- "sha3",
+ "sha3 0.10.6",
"smallvec",
"sp-api",
"sp-block-builder",
@@ -5003,7 +5013,7 @@ dependencies = [
"clap",
"libsecp256k1",
"primitive-types",
- "sha3",
+ "sha3 0.10.6",
"sp-runtime",
"tiny-bip39",
"url",
@@ -5229,7 +5239,7 @@ dependencies = [
"sc-network",
"sc-utils",
"serde",
- "sha3",
+ "sha3 0.10.6",
"sp-api",
"sp-block-builder",
"sp-blockchain",
@@ -5255,7 +5265,7 @@ dependencies = [
"sc-transaction-pool",
"sc-transaction-pool-api",
"serde",
- "sha3",
+ "sha3 0.10.6",
"sp-api",
"sp-blockchain",
"sp-io",
@@ -5367,7 +5377,7 @@ dependencies = [
"scale-info",
"serde",
"session-keys-primitives",
- "sha3",
+ "sha3 0.10.6",
"smallvec",
"sp-api",
"sp-block-builder",
@@ -5515,7 +5525,7 @@ dependencies = [
"serde",
"serde_json",
"session-keys-primitives",
- "sha3",
+ "sha3 0.10.6",
"sp-api",
"sp-block-builder",
"sp-blockchain",
@@ -5651,13 +5661,16 @@ dependencies = [
"pallet-evm-precompile-bn128",
"pallet-evm-precompile-call-permit",
"pallet-evm-precompile-collective",
+ "pallet-evm-precompile-conviction-voting",
"pallet-evm-precompile-crowdloan-rewards",
"pallet-evm-precompile-democracy",
"pallet-evm-precompile-dispatch",
"pallet-evm-precompile-modexp",
"pallet-evm-precompile-parachain-staking",
+ "pallet-evm-precompile-preimage",
"pallet-evm-precompile-proxy",
"pallet-evm-precompile-randomness",
+ "pallet-evm-precompile-referenda",
"pallet-evm-precompile-relay-encoder",
"pallet-evm-precompile-sha3fips",
"pallet-evm-precompile-simple",
@@ -5697,7 +5710,7 @@ dependencies = [
"scale-info",
"serde",
"session-keys-primitives",
- "sha3",
+ "sha3 0.10.6",
"smallvec",
"sp-api",
"sp-block-builder",
@@ -5761,7 +5774,7 @@ dependencies = [
"digest 0.10.5",
"multihash-derive",
"sha2 0.10.6",
- "sha3",
+ "sha3 0.10.6",
"unsigned-varint",
]
@@ -6847,7 +6860,7 @@ dependencies = [
"precompile-utils",
"scale-info",
"serde",
- "sha3",
+ "sha3 0.10.6",
"slices",
"sp-core",
"sp-io",
@@ -6875,7 +6888,7 @@ dependencies = [
"precompile-utils",
"scale-info",
"serde",
- "sha3",
+ "sha3 0.10.6",
"slices",
"sp-core",
"sp-io",
@@ -6922,7 +6935,7 @@ dependencies = [
"precompile-utils",
"scale-info",
"serde",
- "sha3",
+ "sha3 0.10.6",
"slices",
"sp-core",
"sp-io",
@@ -6952,7 +6965,7 @@ dependencies = [
"precompile-utils",
"scale-info",
"serde",
- "sha3",
+ "sha3 0.10.6",
"similar-asserts",
"slices",
"sp-core",
@@ -6961,6 +6974,33 @@ dependencies = [
"sp-std",
]
+[[package]]
+name = "pallet-evm-precompile-conviction-voting"
+version = "0.1.0"
+dependencies = [
+ "derive_more",
+ "fp-evm",
+ "frame-support",
+ "frame-system",
+ "hex-literal",
+ "log",
+ "num_enum",
+ "pallet-balances",
+ "pallet-conviction-voting",
+ "pallet-evm",
+ "pallet-timestamp",
+ "parity-scale-codec",
+ "precompile-utils",
+ "rustc-hex",
+ "scale-info",
+ "serde",
+ "sha3 0.9.1",
+ "sp-core",
+ "sp-io",
+ "sp-runtime",
+ "sp-std",
+]
+
[[package]]
name = "pallet-evm-precompile-crowdloan-rewards"
version = "0.6.0"
@@ -6985,7 +7025,7 @@ dependencies = [
"rustc-hex",
"scale-info",
"serde",
- "sha3",
+ "sha3 0.10.6",
"sp-core",
"sp-io",
"sp-runtime",
@@ -7057,7 +7097,34 @@ dependencies = [
"rustc-hex",
"scale-info",
"serde",
- "sha3",
+ "sha3 0.10.6",
+ "sp-core",
+ "sp-io",
+ "sp-runtime",
+ "sp-std",
+]
+
+[[package]]
+name = "pallet-evm-precompile-preimage"
+version = "0.1.0"
+dependencies = [
+ "derive_more",
+ "fp-evm",
+ "frame-support",
+ "frame-system",
+ "hex-literal",
+ "log",
+ "num_enum",
+ "pallet-balances",
+ "pallet-evm",
+ "pallet-preimage",
+ "pallet-timestamp",
+ "parity-scale-codec",
+ "precompile-utils",
+ "rustc-hex",
+ "scale-info",
+ "serde",
+ "sha3 0.9.1",
"sp-core",
"sp-io",
"sp-runtime",
@@ -7085,7 +7152,7 @@ dependencies = [
"rustc-hex",
"scale-info",
"serde",
- "sha3",
+ "sha3 0.10.6",
"sp-core",
"sp-io",
"sp-runtime",
@@ -7121,6 +7188,35 @@ dependencies = [
"sp-std",
]
+[[package]]
+name = "pallet-evm-precompile-referenda"
+version = "0.1.0"
+dependencies = [
+ "derive_more",
+ "fp-evm",
+ "frame-support",
+ "frame-system",
+ "hex-literal",
+ "log",
+ "num_enum",
+ "pallet-balances",
+ "pallet-evm",
+ "pallet-preimage",
+ "pallet-referenda",
+ "pallet-scheduler",
+ "pallet-timestamp",
+ "parity-scale-codec",
+ "precompile-utils",
+ "rustc-hex",
+ "scale-info",
+ "serde",
+ "sha3 0.9.1",
+ "sp-core",
+ "sp-io",
+ "sp-runtime",
+ "sp-std",
+]
+
[[package]]
name = "pallet-evm-precompile-relay-encoder"
version = "0.1.0"
@@ -7143,7 +7239,7 @@ dependencies = [
"rustc-hex",
"scale-info",
"serde",
- "sha3",
+ "sha3 0.10.6",
"sp-core",
"sp-io",
"sp-runtime",
@@ -7194,7 +7290,7 @@ dependencies = [
"rustc-hex",
"scale-info",
"serde",
- "sha3",
+ "sha3 0.10.6",
"sp-core",
"sp-io",
"sp-runtime",
@@ -7225,7 +7321,7 @@ dependencies = [
"precompile-utils",
"scale-info",
"serde",
- "sha3",
+ "sha3 0.10.6",
"sp-core",
"sp-io",
"sp-runtime",
@@ -7258,7 +7354,7 @@ dependencies = [
"rustc-hex",
"scale-info",
"serde",
- "sha3",
+ "sha3 0.10.6",
"sp-core",
"sp-io",
"sp-runtime",
@@ -7290,7 +7386,7 @@ dependencies = [
"precompile-utils",
"scale-info",
"serde",
- "sha3",
+ "sha3 0.10.6",
"slices",
"sp-core",
"sp-io",
@@ -9651,7 +9747,7 @@ dependencies = [
"precompile-utils-macro",
"scale-info",
"serde",
- "sha3",
+ "sha3 0.10.6",
"similar-asserts",
"sp-core",
"sp-io",
@@ -9672,7 +9768,7 @@ dependencies = [
"prettyplease",
"proc-macro2",
"quote",
- "sha3",
+ "sha3 0.10.6",
"sp-core",
"sp-std",
"syn",
@@ -11924,6 +12020,18 @@ dependencies = [
"digest 0.10.5",
]
+[[package]]
+name = "sha3"
+version = "0.9.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f81199417d4e5de3f04b1e871023acea7389672c4135918f05aa9cbf2f2fa809"
+dependencies = [
+ "block-buffer 0.9.0",
+ "digest 0.9.0",
+ "keccak",
+ "opaque-debug 0.3.0",
+]
+
[[package]]
name = "sha3"
version = "0.10.6"
@@ -12368,7 +12476,7 @@ dependencies = [
"byteorder",
"digest 0.10.5",
"sha2 0.10.6",
- "sha3",
+ "sha3 0.10.6",
"sp-std",
"twox-hash",
]
@@ -14729,7 +14837,7 @@ dependencies = [
"parity-scale-codec",
"scale-info",
"serde",
- "sha3",
+ "sha3 0.10.6",
"sp-io",
"sp-runtime",
"sp-std",
diff --git a/Cargo.toml b/Cargo.toml
index 780934d6b8..ae51c346a4 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -17,11 +17,14 @@ members = [
"precompiles/batch",
"precompiles/call-permit",
"precompiles/collective",
+ "precompiles/conviction-voting",
"precompiles/crowdloan-rewards",
"precompiles/pallet-democracy",
"precompiles/parachain-staking",
+ "precompiles/preimage",
"precompiles/proxy",
"precompiles/randomness",
+ "precompiles/referenda",
"precompiles/relay-encoder",
"precompiles/utils",
"precompiles/utils/macro",
diff --git a/precompiles/conviction-voting/Cargo.toml b/precompiles/conviction-voting/Cargo.toml
new file mode 100644
index 0000000000..26214880c4
--- /dev/null
+++ b/precompiles/conviction-voting/Cargo.toml
@@ -0,0 +1,57 @@
+[package]
+name = "pallet-evm-precompile-conviction-voting"
+authors = [ "PureStake" ]
+description = "A Precompile to make pallet-conviction-voting calls encoding accessible to pallet-evm"
+edition = "2021"
+version = "0.1.0"
+
+[dependencies]
+log = "0.4"
+num_enum = { version = "0.5.3", default-features = false }
+rustc-hex = { version = "2.0.1", default-features = false }
+
+# Moonbeam
+precompile-utils = { path = "../utils", default-features = false }
+
+# Substrate
+frame-support = { git = "https://github.com/purestake/substrate", branch = "moonbeam-polkadot-v0.9.32", default-features = false }
+frame-system = { git = "https://github.com/purestake/substrate", branch = "moonbeam-polkadot-v0.9.32", default-features = false }
+pallet-conviction-voting = { git = "https://github.com/purestake/substrate", branch = "moonbeam-polkadot-v0.9.32", default-features = false }
+parity-scale-codec = { version = "3.0.0", default-features = false, features = [ "derive" ] }
+sp-core = { git = "https://github.com/purestake/substrate", branch = "moonbeam-polkadot-v0.9.32", default-features = false }
+sp-runtime = { git = "https://github.com/purestake/substrate", branch = "moonbeam-polkadot-v0.9.32", default-features = false }
+sp-std = { git = "https://github.com/purestake/substrate", branch = "moonbeam-polkadot-v0.9.32", default-features = false }
+
+# Frontier
+fp-evm = { git = "https://github.com/purestake/frontier", branch = "moonbeam-polkadot-v0.9.32", default-features = false }
+pallet-evm = { git = "https://github.com/purestake/frontier", branch = "moonbeam-polkadot-v0.9.32", default-features = false, features = [ "forbid-evm-reentrancy" ] }
+
+[dev-dependencies]
+derive_more = "0.99"
+hex-literal = "0.3.3"
+serde = "1.0.100"
+sha3 = "0.9"
+
+# Moonbeam
+precompile-utils = { path = "../utils", features = [ "testing" ] }
+
+# Substrate
+pallet-balances = { git = "https://github.com/purestake/substrate", branch = "moonbeam-polkadot-v0.9.32" }
+pallet-timestamp = { git = "https://github.com/purestake/substrate", branch = "moonbeam-polkadot-v0.9.32" }
+scale-info = { version = "2.0", default-features = false, features = [ "derive" ] }
+sp-io = { git = "https://github.com/purestake/substrate", branch = "moonbeam-polkadot-v0.9.32", default-features = false }
+
+[features]
+default = [ "std" ]
+std = [
+ "fp-evm/std",
+ "frame-support/std",
+ "frame-system/std",
+ "pallet-conviction-voting/std",
+ "pallet-evm/std",
+ "parity-scale-codec/std",
+ "parity-scale-codec/std",
+ "precompile-utils/std",
+ "sp-runtime/std",
+ "sp-std/std",
+]
diff --git a/precompiles/conviction-voting/ConvictionVoting.sol b/precompiles/conviction-voting/ConvictionVoting.sol
new file mode 100644
index 0000000000..a35670b31d
--- /dev/null
+++ b/precompiles/conviction-voting/ConvictionVoting.sol
@@ -0,0 +1,97 @@
+// SPDX-License-Identifier: GPL-3.0-only
+pragma solidity >=0.8.3;
+
+/// @dev The Conviction Voting contract's address.
+address constant Conviction_Voting_ADDRESS = 0x0000000000000000000000000000000000000812;
+
+/// @dev The Conviction Voting contract's instance.
+ConvictionVoting constant Conviction_Voting_CONTRACT = ConvictionVoting(
+ Conviction_Voting_ADDRESS
+);
+
+/// @author The Moonbeam Team
+/// @title Pallet Conviction Voting Interface
+/// @title The interface through which solidity contracts will interact with the Conviction Voting pallet
+/// @custom:address 0x0000000000000000000000000000000000000812
+interface ConvictionVoting {
+ /// @dev Defines the conviction multiplier type.
+ /// The values start at `0` and are represented as `uint8`.
+ /// None => 0.1x votes, unlocked.
+ /// Locked1x => 1x votes, locked for an enactment period following a successful vote.
+ /// Locked2x => 2x votes, locked for 2x enactment periods following a successful vote
+ /// Locked3x => 3x votes, locked for 4x...
+ /// Locked4x => 4x votes, locked for 8x...,
+ /// Locked5x => 5x votes, locked for 16x...
+ /// Locked6x => 6x votes, locked for 32x...
+ enum Conviction {
+ None,
+ Locked1x,
+ Locked2x,
+ Locked3x,
+ Locked4x,
+ Locked5x,
+ Locked6x
+ }
+
+ /// @dev Vote yes in a poll.
+ /// @custom:selector da9df518
+ /// @param pollIndex Index of poll
+ /// @param voteAmount Balance locked for vote
+ /// @param conviction Conviction multiplier for length of vote lock
+ function voteYes(
+ uint32 pollIndex,
+ uint256 voteAmount,
+ Conviction conviction
+ ) external;
+
+ /// @dev Vote no in a poll.
+ /// @custom:selector cc600eba
+ /// @param pollIndex Index of poll
+ /// @param voteAmount Balance locked for vote
+ /// @param conviction Conviction multiplier for length of vote lock
+ function voteNo(
+ uint32 pollIndex,
+ uint256 voteAmount,
+ Conviction conviction
+ ) external;
+
+ /// @dev Remove vote in poll
+ /// @custom:selector 79cae220
+ /// @param pollIndex Index of the poll
+ function removeVote(uint32 pollIndex) external;
+
+ /// @dev Remove vote in poll for other voter
+ /// @custom:selector cbcb9276
+ //// @param target The voter to have vote removed. The removed vote must already be expired.
+ /// @param trackId The trackId
+ /// @param pollIndex the poll index
+ function removeOtherVote(
+ address target,
+ uint16 trackId,
+ uint32 pollIndex
+ ) external;
+
+ /// @dev Delegate to a representative for the vote trackId
+ /// @custom:selector 681750e8
+ /// @param trackId The trackId
+ /// @param representative The representative for the trackId
+ /// @param conviction The conviction multiplier
+ /// @param amount delegated to representative for this vote trackId
+ function delegate(
+ uint16 trackId,
+ address representative,
+ Conviction conviction,
+ uint256 amount
+ ) external;
+
+ /// @dev Undelegate for the trackId
+ /// @custom:selector 98be4094
+ /// @param trackId The trackId
+ function undelegate(uint16 trackId) external;
+
+ /// @dev Unlock tokens locked for trackId
+ /// @custom:selector 4259d98c
+ /// @param trackId The trackId
+ /// @param target The target address
+ function unlock(uint16 trackId, address target) external;
+}
diff --git a/precompiles/conviction-voting/src/lib.rs b/precompiles/conviction-voting/src/lib.rs
new file mode 100644
index 0000000000..90bedd252c
--- /dev/null
+++ b/precompiles/conviction-voting/src/lib.rs
@@ -0,0 +1,292 @@
+// Copyright 2019-2022 PureStake Inc.
+// This file is part of Moonbeam.
+
+// Moonbeam is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Moonbeam is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Moonbeam. If not, see .
+
+#![cfg_attr(not(feature = "std"), no_std)]
+#![feature(assert_matches)]
+
+use fp_evm::PrecompileHandle;
+use frame_support::dispatch::{Dispatchable, GetDispatchInfo, PostDispatchInfo};
+use frame_support::traits::{Currency, Polling};
+use pallet_conviction_voting::Call as ConvictionVotingCall;
+use pallet_conviction_voting::{AccountVote, Conviction, Tally, Vote};
+use pallet_evm::AddressMapping;
+use precompile_utils::prelude::*;
+use sp_core::{H160, U256};
+use sp_runtime::traits::StaticLookup;
+use sp_std::marker::PhantomData;
+
+#[cfg(test)]
+mod mock;
+#[cfg(test)]
+mod tests;
+
+type BalanceOf = <::Currency as Currency<
+ ::AccountId,
+>>::Balance;
+type IndexOf = <::Polls as Polling<
+ Tally<
+ <::Currency as Currency<
+ ::AccountId,
+ >>::Balance,
+ ::MaxTurnout,
+ >,
+>>::Index;
+type ClassOf = <::Polls as Polling<
+ Tally<
+ <::Currency as Currency<
+ ::AccountId,
+ >>::Balance,
+ ::MaxTurnout,
+ >,
+>>::Class;
+
+/// Direction of vote
+enum VoteDirection {
+ Yes,
+ No,
+ #[allow(unused)]
+ Abstain,
+}
+
+/// A precompile to wrap the functionality from pallet-conviction-voting.
+pub struct ConvictionVotingPrecompile(PhantomData);
+
+#[precompile_utils::precompile]
+impl ConvictionVotingPrecompile
+where
+ Runtime: pallet_conviction_voting::Config + pallet_evm::Config + frame_system::Config,
+ BalanceOf: TryFrom,
+ ::RuntimeCall:
+ Dispatchable + GetDispatchInfo,
+ <::RuntimeCall as Dispatchable>::RuntimeOrigin:
+ From