Skip to content

Commit

Permalink
Pallet Staking Lottery (#1036)
Browse files Browse the repository at this point in the history
Co-authored-by: Charles Ferrell <[email protected]>
  • Loading branch information
Adam Reif and ferrell-code authored Jul 6, 2023
1 parent 429109e commit aefac61
Show file tree
Hide file tree
Showing 46 changed files with 6,062 additions and 36 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ runtime/**/target
.vscode
.idea
/tests/node_modules/
/scripts/**/node_modules
/scripts/**/package-lock.json
/scripts/benchmarking/benchmarking_errors.txt
/scripts/benchmarking/machine_benchmark_result.txt
/scripts/benchmarking/rocksdb_weights.rs
Expand Down
81 changes: 81 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ xcm = { git = "https://github.com/paritytech/polkadot.git", branch = "release-v0
calamari-runtime = { path = '../runtime/calamari' }
manta-primitives = { path = '../primitives/manta' }
manta-runtime = { path = '../runtime/manta' }
pallet-lottery = { path = '../pallets/pallet-lottery', features = ["rpc"] }
pallet-manta-pay = { path = '../pallets/manta-pay', features = ["rpc", "runtime"] }
pallet-manta-sbt = { path = '../pallets/manta-sbt', features = ["rpc", "runtime"] }
pallet-parachain-staking = { path = '../pallets/parachain-staking' }
Expand Down
8 changes: 6 additions & 2 deletions node/src/chain_specs/calamari.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::command::CALAMARI_PARACHAIN_ID;
#[allow(unused_imports)]
use calamari_runtime::{
currency::KMA, opaque::SessionKeys, CouncilConfig, DemocracyConfig, GenesisConfig,
ParachainStakingConfig, TechnicalCommitteeConfig,
LotteryConfig, ParachainStakingConfig, TechnicalCommitteeConfig,
};
use session_key_primitives::util::unchecked_account_id;
/// Calamari Protocol Identifier
Expand Down Expand Up @@ -158,7 +158,6 @@ pub fn calamari_local_config(localdev: bool) -> CalamariChainSpec {

fn calamari_dev_genesis(
invulnerables: Vec<(AccountId, SessionKeys)>,

delegations: Vec<(AccountId, AccountId, Balance)>,
endowed_accounts: Vec<AccountId>,
) -> GenesisConfig {
Expand Down Expand Up @@ -235,6 +234,11 @@ fn calamari_dev_genesis(
polkadot_xcm: calamari_runtime::PolkadotXcmConfig {
safe_xcm_version: Some(CALAMARI_SAFE_XCM_VERSION),
},
lottery: LotteryConfig {
min_deposit: 5_000 * KMA,
min_withdraw: 5_000 * KMA,
gas_reserve: 10_000 * KMA,
},
}
}
/// Returns the Calamari testnet chainspec.
Expand Down
8 changes: 7 additions & 1 deletion node/src/chain_specs/manta/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ use super::*;
use crate::command::MANTA_PARACHAIN_ID;
use manta_runtime::{
opaque::SessionKeys, staking::NORMAL_COLLATOR_MINIMUM_STAKE, CouncilConfig, DemocracyConfig,
GenesisConfig, ParachainStakingConfig, PolkadotXcmConfig, TechnicalCommitteeConfig,
GenesisConfig, LotteryConfig, ParachainStakingConfig, PolkadotXcmConfig,
TechnicalCommitteeConfig,
};
use sc_network_common::config::MultiaddrWithPeerId;

Expand Down Expand Up @@ -125,6 +126,11 @@ fn manta_devnet_genesis(genesis_collators: Vec<Collator>) -> GenesisConfig {
delegations: vec![],
inflation_config: manta_runtime::staking::inflation_config::<manta_runtime::Runtime>(),
},
lottery: LotteryConfig {
min_deposit: 500 * MANTA,
min_withdraw: 10 * MANTA,
gas_reserve: 1_000 * MANTA,
},
parachain_info: manta_runtime::ParachainInfoConfig {
parachain_id: MANTA_PARACHAIN_ID.into(),
},
Expand Down
11 changes: 10 additions & 1 deletion node/src/rpc/calamari.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ use super::*;
use manta_primitives::types::{CalamariAssetId, PoolId};
use pallet_farming_rpc_api::{FarmingRpc, FarmingRpcApiServer};
use pallet_farming_rpc_runtime_api::FarmingRuntimeApi;
use pallet_lottery::{
rpc::{Lottery, LotteryRpcServer},
runtime::LotteryApi,
};
use pallet_manta_pay::{
rpc::{Pull, PullApiServer},
runtime::PullLedgerDiffApi,
Expand Down Expand Up @@ -48,6 +52,7 @@ where
C::Api: BlockBuilder<Block>,
C::Api: PullLedgerDiffApi<Block>,
C::Api: SBTPullLedgerDiffApi<Block>,
C::Api: LotteryApi<Block>,
C::Api: FarmingRuntimeApi<Block, AccountId, CalamariAssetId, PoolId>,
C::Api: ZenlinkProtocolRuntimeApi<Block, AccountId, ZenlinkAssetId>,
P: TransactionPool + Sync + Send + 'static,
Expand Down Expand Up @@ -85,7 +90,11 @@ where
.map_err(|e| sc_service::Error::Other(e.to_string()))?;

module
.merge(FarmingRpc::new(client).into_rpc())
.merge(FarmingRpc::new(client.clone()).into_rpc())
.map_err(|e| sc_service::Error::Other(e.to_string()))?;

module
.merge(Lottery::new(client).into_rpc())
.map_err(|e| sc_service::Error::Other(e.to_string()))?;

Ok(module)
Expand Down
11 changes: 10 additions & 1 deletion node/src/rpc/manta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ use super::*;
use manta_primitives::types::{MantaAssetId, PoolId};
use pallet_farming_rpc_api::{FarmingRpc, FarmingRpcApiServer};
use pallet_farming_rpc_runtime_api::FarmingRuntimeApi;
use pallet_lottery::{
rpc::{Lottery, LotteryRpcServer},
runtime::LotteryApi,
};
use pallet_manta_pay::{
rpc::{Pull, PullApiServer},
runtime::PullLedgerDiffApi,
Expand Down Expand Up @@ -47,6 +51,7 @@ where
C::Api: BlockBuilder<Block>,
C::Api: PullLedgerDiffApi<Block>,
C::Api: SBTPullLedgerDiffApi<Block>,
C::Api: LotteryApi<Block>,
C::Api: FarmingRuntimeApi<Block, AccountId, MantaAssetId, PoolId>,
C::Api: ZenlinkProtocolRuntimeApi<Block, AccountId, ZenlinkAssetId>,
P: TransactionPool + Sync + Send + 'static,
Expand Down Expand Up @@ -84,7 +89,11 @@ where
.map_err(|e| sc_service::Error::Other(e.to_string()))?;

module
.merge(FarmingRpc::new(client).into_rpc())
.merge(FarmingRpc::new(client.clone()).into_rpc())
.map_err(|e| sc_service::Error::Other(e.to_string()))?;

module
.merge(Lottery::new(client).into_rpc())
.map_err(|e| sc_service::Error::Other(e.to_string()))?;

Ok(module)
Expand Down
82 changes: 82 additions & 0 deletions pallets/pallet-lottery/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
[package]
authors = ["Manta Network"]
description = 'Pallet implementing an APY-maximizing no-loss lottery'
edition = "2021"
homepage = 'https://manta.network'
license = 'GPL-3.0'
name = 'pallet-lottery'
repository = 'https://github.com/Manta-Network/Manta/'
version = '4.2.0'

[dependencies]
codec = { version = '3.4.0', default-features = false, features = ['derive'], package = 'parity-scale-codec' }
function_name = "0.3"
jsonrpsee = { version = "0.16.2", features = ["server", "macros"], optional = true }
log = { version = "0.4.0", default-features = false }
scale-info = { version = "2.1.2", default-features = false, features = ["derive"] }

# Substrate dependencies
frame-support = { git = 'https://github.com/paritytech/substrate.git', default-features = false, branch = "polkadot-v0.9.37" }
frame-system = { git = 'https://github.com/paritytech/substrate.git', default-features = false, branch = "polkadot-v0.9.37" }
sp-api = { git = 'https://github.com/paritytech/substrate.git', default-features = false, branch = "polkadot-v0.9.37" }
sp-arithmetic = { git = 'https://github.com/paritytech/substrate.git', default-features = false, branch = "polkadot-v0.9.37" }
sp-blockchain = { git = 'https://github.com/paritytech/substrate.git', default-features = false, branch = "polkadot-v0.9.37", optional = true }
sp-core = { git = 'https://github.com/paritytech/substrate.git', default-features = false, branch = "polkadot-v0.9.37" }
sp-io = { git = 'https://github.com/paritytech/substrate.git', default-features = false, branch = "polkadot-v0.9.37" }
sp-runtime = { git = 'https://github.com/paritytech/substrate.git', default-features = false, branch = "polkadot-v0.9.37" }
sp-std = { git = 'https://github.com/paritytech/substrate.git', default-features = false, branch = "polkadot-v0.9.37" }

# Self dependencies
manta-primitives = { path = "../../primitives/manta", default-features = false }
pallet-parachain-staking = { path = '../parachain-staking', default-features = false }
runtime-common = { path = "../../runtime/common", default-features = false }
session-key-primitives = { path = '../../primitives/session-keys', default-features = false }

# Benchmarking dependencies
frame-benchmarking = { git = 'https://github.com/paritytech/substrate.git', branch = "polkadot-v0.9.37", default-features = false, optional = true }
rand = { version = "0.8.5", default-features = false, optional = true }

[dev-dependencies]
calamari-runtime = { path = "../../runtime/calamari", default-features = false }
lazy_static = "1.4.0"
manta-collator-selection = { path = "../collator-selection", default-features = false }
pallet-balances = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
pallet-preimage = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
pallet-randomness = { path = '../randomness', default-features = false }
pallet-scheduler = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
pallet-transaction-payment = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
rand = "0.8"
similar-asserts = "1.1.0"
sp-staking = { git = 'https://github.com/paritytech/substrate.git', default-features = false, branch = "polkadot-v0.9.37" }

[features]
default = ["std"]
# RPC Interface
rpc = [
"jsonrpsee",
"sp-blockchain",
]
runtime-benchmarks = [
'frame-benchmarking/runtime-benchmarks',
'frame-support/runtime-benchmarks',
'pallet-parachain-staking/runtime-benchmarks',
'rand/std_rng',
]
std = [
"manta-primitives/std",
"pallet-parachain-staking/std",
"pallet-randomness/std",
"calamari-runtime/std",
"session-key-primitives/std",
"sp-core/std",
"sp-std/std",
"sp-io/std",
"sp-runtime/std",
'frame-benchmarking/std',
"frame-support/std",
"frame-system/std",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
]
Loading

0 comments on commit aefac61

Please sign in to comment.