Skip to content

Commit

Permalink
Gov2 Precompiles (#1885)
Browse files Browse the repository at this point in the history
* stash precompile changes in other branch and push pallet changes leaking std librar

* still leaking std

* using sp std phantomdata did not fix

* ty @nanocryk for std leak fix

* init referenda precompile needs tryfrom u8 for origins

* referenda submit precompile fn

* signed extrinsics for referenda precompile

* preimage precompile

* init conviction voting precompile

* referenda delegate undelegate unlock

* fixes

* fix

* clean

* improve revert reasons for class and index inputs

* clean

* init accessors and clean

* referenda precompile

* clean

* clean and init referenda precompile interface

* fix merge

* try mock referenda precompile but did not succeed

* save

* fix referenda mock

* add dot sol files for preimage and voting

* add to moonbase precompiles

* fix

* precompile existence test fix

* update solidity addresses as per moonbase config

* rename standard vote to vote in conviction voting pallet

* start moving origins out of pallet and using additional generic instead

* fix finish moving pallet custom origins back into runtime

* add opengov precompiles in proxy evm filter

* SolidityConvert no longer necessary

Co-authored-by: Éloïs <c@elo.tf>
Co-authored-by: Stephen Shelton <steve@brewcraft.org>

* rm SolidityConvert and add Conviction enum

* use trackId as input for submit instead of origin and convert from trackId to origin based on mapping

* camelCase error msgs

Co-authored-by: Éloïs <c@elo.tf>

* Update precompiles/referenda/src/lib.rs

Co-authored-by: Éloïs <c@elo.tf>

* fix conviction precompile interface

* fix referenda precompile interface

* test to ensure all tracks have min enactment period less than vote locking period

* update tracks based on wiki

* revert accidental commit

* fix referenda precompile unit tests

* update config based on polkadot 6372 gov2 config tweaks

* fix

* Configure moonriver OpenGov (#2038)

* configure opengov for movr

* Staking precompile: candidateAutoCompoundingDelegationCount (#2037)

* candidateAutoCompoundingDelegationCount

* Remove unecessary `.into()`

Co-authored-by: Amar Singh <asinghchrony@protonmail.com>

* typo

Co-authored-by: Stephen Shelton <steve@brewcraft.org>

Co-authored-by: Amar Singh <asinghchrony@protonmail.com>
Co-authored-by: Stephen Shelton <steve@brewcraft.org>

* precompiles

* address some review todos not done yet

* Fixes balance smoke test (#2040)

Co-authored-by: Crystalin None <crystalin@Crystalins-MacBook-Pro.local>

* trackIds getter and full TrackInfo impl with Curves

* patch evm version (#2026)

* Removes treasurer in Moonriver

* Update eth contract code smoke test (#2043)

Change account limit

* Adds OpenGov to Moonriver (#2041)

* Adds OpenGov to Moonriver

* Updates Moonbase

* fmt

* fixes test

* fix impoty

Co-authored-by: nanocryk <6422796+nanocryk@users.noreply.github.com>
Co-authored-by: Stephen Shelton <steve@brewcraft.org>
Co-authored-by: Alan Sapede <alan@purestake.com>
Co-authored-by: Crystalin None <crystalin@Crystalins-MacBook-Pro.local>
Co-authored-by: Crystalin <alan.sapede@gmail.com>
Co-authored-by: Tim B <79199034+timbrinded@users.noreply.github.com>

* remove TryFrom u8 impl for Origin unused

* split convictionVoting vote into voteYes and voteNo so can add voteAbstain in future version without breaking backwards compatibility

* fix consistent conversion test

* follow suggestions

* add doc note to removeOtherVote

* fix

Co-authored-by: nanocryk <6422796+nanocryk@users.noreply.github.com>
Co-authored-by: librelois <c@elo.tf>
Co-authored-by: Stephen Shelton <steve@brewcraft.org>
Co-authored-by: Alan Sapede <alan@purestake.com>
Co-authored-by: Crystalin None <crystalin@Crystalins-MacBook-Pro.local>
Co-authored-by: Crystalin <alan.sapede@gmail.com>
Co-authored-by: Tim B <79199034+timbrinded@users.noreply.github.com>
  • Loading branch information
8 people committed Jan 18, 2023
1 parent 9a59551 commit f680485
Show file tree
Hide file tree
Showing 26 changed files with 2,119 additions and 58 deletions.
166 changes: 137 additions & 29 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
57 changes: 57 additions & 0 deletions precompiles/conviction-voting/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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",
]
97 changes: 97 additions & 0 deletions precompiles/conviction-voting/ConvictionVoting.sol
Original file line number Diff line number Diff line change
@@ -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;
}
Loading

0 comments on commit f680485

Please sign in to comment.