Skip to content

Commit

Permalink
working distributions
Browse files Browse the repository at this point in the history
  • Loading branch information
1xstj committed Jan 17, 2024
1 parent 8ad4fae commit 59c81d2
Show file tree
Hide file tree
Showing 9 changed files with 222 additions and 74 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

28 changes: 13 additions & 15 deletions node/src/chainspec/mainnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ use sp_runtime::{
use tangle_primitives::types::{BlockNumber, Signature};
use tangle_runtime::{
AccountId, BabeConfig, Balance, BalancesConfig, ClaimsConfig, EVMChainIdConfig,
Eth2ClientConfig, ImOnlineConfig, MaxVestingSchedules, Perbill, RuntimeGenesisConfig,
SessionConfig, StakerStatus, StakingConfig, SudoConfig, SystemConfig, TreasuryPalletId,
VestingConfig, UNIT, WASM_BINARY,
Eth2ClientConfig, ImOnlineConfig, MaxVestingSchedules, Perbill, RoleKeyId,
RuntimeGenesisConfig, SessionConfig, StakerStatus, StakingConfig, SudoConfig, SystemConfig,
TreasuryPalletId, VestingConfig, UNIT, WASM_BINARY,
};
use webb_consensus_types::network_config::{Network, NetworkConfig};

Expand All @@ -64,14 +64,14 @@ where

/// Generate an babe authority key.
pub fn authority_keys_from_seed(
controller: &str,
stash: &str,
) -> (AccountId, BabeId, GrandpaId, ImOnlineId) {
) -> (AccountId, BabeId, GrandpaId, ImOnlineId, RoleKeyId) {
(
get_account_id_from_seed::<sr25519::Public>(stash),
get_from_seed::<BabeId>(controller),
get_from_seed::<GrandpaId>(controller),
get_from_seed::<BabeId>(stash),
get_from_seed::<GrandpaId>(stash),
get_from_seed::<ImOnlineId>(stash),
get_from_seed::<RoleKeyId>(stash),
)
}

Expand All @@ -83,8 +83,9 @@ fn generate_session_keys(
babe: BabeId,
grandpa: GrandpaId,
im_online: ImOnlineId,
role: RoleKeyId,
) -> tangle_runtime::opaque::SessionKeys {
tangle_runtime::opaque::SessionKeys { babe, grandpa, im_online }
tangle_runtime::opaque::SessionKeys { babe, grandpa, im_online, role }
}

pub fn local_mainnet_config(chain_id: u64) -> Result<ChainSpec, String> {
Expand All @@ -105,10 +106,7 @@ pub fn local_mainnet_config(chain_id: u64) -> Result<ChainSpec, String> {
// Wasm binary
wasm_binary,
// Initial validators
vec![
authority_keys_from_seed("Alice", "Alice//stash"),
authority_keys_from_seed("Bob", "Bob//stash"),
],
vec![authority_keys_from_seed("Alice"), authority_keys_from_seed("Bob")],
// Endowed accounts
vec![
(get_account_id_from_seed::<sr25519::Public>("Alice"), endowment),
Expand Down Expand Up @@ -168,7 +166,7 @@ pub fn tangle_mainnet_config(chain_id: u64) -> Result<ChainSpec, String> {
// Initial validators
get_initial_authorities(),
// Endowed accounts
vec![mainnet::get_treasury_balance(), mainnet::get_foundation_balance()],
vec![mainnet::get_treasury_balance(), mainnet::get_foundation_endowment()],
// Sudo account
get_root_key(),
// EVM chain ID
Expand Down Expand Up @@ -205,7 +203,7 @@ pub fn tangle_mainnet_config(chain_id: u64) -> Result<ChainSpec, String> {
#[allow(clippy::too_many_arguments)]
fn mainnet_genesis(
wasm_binary: &[u8],
initial_authorities: Vec<(AccountId, BabeId, GrandpaId, ImOnlineId)>,
initial_authorities: Vec<(AccountId, BabeId, GrandpaId, ImOnlineId, RoleKeyId)>,
endowed_accounts: Vec<(AccountId, Balance)>,
root_key: AccountId,
chain_id: u64,
Expand Down Expand Up @@ -260,7 +258,7 @@ fn mainnet_genesis(
(
x.0.clone(),
x.0.clone(),
generate_session_keys(x.1.clone(), x.2.clone(), x.3.clone()),
generate_session_keys(x.1.clone(), x.2.clone(), x.3.clone(), x.4.clone()),
)
})
.collect::<Vec<_>>(),
Expand Down
68 changes: 56 additions & 12 deletions node/src/distributions/mainnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ use sp_core::H160;
use sp_runtime::{traits::AccountIdConversion, AccountId32};
use std::{collections::BTreeMap, str::FromStr};
use tangle_primitives::types::BlockNumber;
use tangle_runtime::UNIT;
use tangle_testnet_runtime::{AccountId, Balance, ExistentialDeposit};
use tangle_runtime::{AccountId, Balance, ExistentialDeposit, Perbill, UNIT};

/// The contents of the file should be a map of accounts to balances.
fn read_contents_to_substrate_accounts(path_str: &str) -> BTreeMap<AccountId, f64> {
Expand Down Expand Up @@ -98,19 +97,39 @@ pub struct DistributionResult {
pub vesting_cliff: BlockNumber,
}

fn ninety_nine_percent_endowment(endowment: u128) -> u128 {
endowment * 99 / 100
fn ninety_five_percent_endowment(endowment: u128) -> u128 {
endowment * 95 / 100
}

fn one_percent_endowment(endowment: u128) -> u128 {
endowment - ninety_nine_percent_endowment(endowment)
fn five_percent_endowment(endowment: u128) -> u128 {
endowment - ninety_five_percent_endowment(endowment)
}

fn vesting_per_block(endowment: u128, blocks: u64) -> u128 {
print!("Endowment {:?} Blocks {:?} ", endowment, blocks);
endowment / blocks as u128
}

fn get_team_distribution_share() -> Perbill {
Perbill::from_rational(25_u32, 100_u32)
}

fn get_investor_distribution_share() -> Perbill {
Perbill::from_rational(20_u32, 100_u32)
}

fn get_foundation_distribution_share() -> Perbill {
Perbill::from_rational(15_u32, 100_u32)
}

fn get_treasury_distribution_share() -> Perbill {
Perbill::from_rational(34_u32, 100_u32)
}

fn get_initial_liquidity_share() -> Perbill {
Perbill::from_rational(5_u32, 100_u32)
}

pub fn get_edgeware_genesis_balance_distribution() -> DistributionResult {
let list = get_edgeware_genesis_list();
let endowment = ONE_PERCENT_TOTAL_SUPPLY / list.len() as u128;
Expand Down Expand Up @@ -193,12 +212,24 @@ pub fn get_investor_balance_distribution() -> Vec<(MultiAddress, u128, u64, u64,
compute_balance_distribution_with_cliff_and_vesting(investor_accounts)
}

pub fn get_team_balance_distribution() -> Vec<(MultiAddress, u128, u64, u64, u128)> {
pub fn get_team_endowment() -> Vec<(MultiAddress, u128)> {
// TODO : Ensure this sums up to 5%
let team_accounts: Vec<(MultiAddress, u128)> = get_team_balance_distribution_list()
.into_iter()
.map(|(address, balance)| (MultiAddress::Native(address), balance as u128))
.collect();
compute_balance_distribution_with_cliff_and_vesting(team_accounts)
team_accounts
}

pub fn get_team_balance_distribution() -> Vec<(MultiAddress, u128, u64, u64, u128)> {
// the team vesting is completely sent to a single account and vested and claimed by that
// account TODO : Finalise this account
let pallet_id = tangle_primitives::treasury::TREASURY_PALLET_ID;
let address: AccountId = pallet_id.into_account_truncating();
let balance =
(get_team_distribution_share() - get_initial_liquidity_share()).mul_floor(TOTAL_SUPPLY);
let team_account = (MultiAddress::Native(address), balance as u128);
compute_balance_distribution_with_cliff_and_vesting(vec![team_account])
}

pub fn get_treasury_balance() -> (AccountId, u128) {
Expand All @@ -207,11 +238,24 @@ pub fn get_treasury_balance() -> (AccountId, u128) {
(acc, UNIT * 100_000)
}

pub fn get_foundation_balance() -> (AccountId, u128) {
pub fn get_foundation_endowment() -> (AccountId, u128) {
// TODO : Setup foundation account here
let pallet_id = tangle_primitives::treasury::TREASURY_PALLET_ID;
let acc: AccountId = pallet_id.into_account_truncating();
(acc, UNIT * 100_000)
let balance = (get_foundation_distribution_share() * get_initial_liquidity_share())
.mul_floor(TOTAL_SUPPLY);
(acc, balance)
}

pub fn get_foundation_balance_distribution() -> Vec<(MultiAddress, u128, u64, u64, u128)> {
// TODO : Setup foundation account here
let pallet_id = tangle_primitives::treasury::TREASURY_PALLET_ID;
let address: AccountId = pallet_id.into_account_truncating();
let balance = get_foundation_distribution_share().mul_floor(TOTAL_SUPPLY) -
get_initial_liquidity_share()
.mul_floor(get_foundation_distribution_share().mul_floor(TOTAL_SUPPLY));
let foundation_account = (MultiAddress::Native(address), balance as u128);
compute_balance_distribution_with_cliff_and_vesting(vec![foundation_account])
}

pub fn compute_balance_distribution_with_cliff_and_vesting(
Expand All @@ -225,7 +269,7 @@ pub fn compute_balance_distribution_with_cliff_and_vesting(
value,
ONE_YEAR_BLOCKS,
TWO_YEARS_BLOCKS - ONE_YEAR_BLOCKS,
one_percent_endowment(value),
five_percent_endowment(value),
)
})
.collect()
Expand All @@ -240,7 +284,7 @@ pub fn get_distribution_for(
let mut claims = vec![];
let mut vesting = vec![];
arr.into_iter().filter(|(_, value)| *value > 0).for_each(|(address, value)| {
let claimable_amount = one_percent_endowment(value);
let claimable_amount = five_percent_endowment(value);
let vested_amount = value - claimable_amount;
let cliff_fraction = vesting_cliff as f64 / total_vesting_schedule as f64;
let remaining_fraction = 1.0 - cliff_fraction;
Expand Down
72 changes: 41 additions & 31 deletions node/src/mainnet_fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ use sc_consensus_grandpa::AuthorityId as GrandpaId;
use sc_network::config::MultiaddrWithPeerId;
use sp_consensus_babe::AuthorityId as BabeId;
use sp_core::crypto::UncheckedInto;
use tangle_testnet_runtime::AccountId;
use tangle_crypto_primitives::crypto::AuthorityId as RoleKeyId;
use tangle_runtime::AccountId;

/// Mainnet root key
pub fn get_root_key() -> AccountId {
// Standalone sudo key: 5CDZpRSZ14TmXorHTsTeksY7223FzsaLXPbpTPBUV6NaZSr1
hex!["06c225d97d596c57e620aba15e1a8a69c7b334ffdab175788c6553f7dd181a56"].into()
hex!["9c2c928c3b9ac62c6dc4caaf5777c16ce28984dedc92687ef427f8f4f6d61d2f"].into()
}

/// Mainnet bootnodes
Expand All @@ -37,7 +37,7 @@ pub fn get_bootnodes() -> Vec<MultiaddrWithPeerId> {
"/ip4/18.119.14.21/tcp/30333/p2p/12D3KooWJP5NbEjEK1YihofJm3MMSJWrbRWjeEkRf3LtKvkj6mr9"
.parse()
.unwrap(),
"/ip4/18.188.183.185/tcp/30333/p2p/12D3KooWDL3KiR6CpnEbgUgheje1cMGQtwH4euxGMPQBkwU5cZdu"
"/ip4/3.15.186.160/tcp/30333/p2p/12D3KooWDL3KiR6CpnEbgUgheje1cMGQtwH4euxGMPQBkwU5cZdu"
.parse()
.unwrap(),
"/ip4/3.137.213.159/tcp/30333/p2p/12D3KooWS4aniCJTz2RiNfNUka8TTa3gXak63FJgdAgfAWLCnsAi"
Expand All @@ -49,57 +49,67 @@ pub fn get_bootnodes() -> Vec<MultiaddrWithPeerId> {
]
}

/// Standalone initial authorities
pub fn get_initial_authorities() -> Vec<(AccountId, BabeId, GrandpaId, ImOnlineId)> {
/// Tangle runtime initial authorities
pub fn get_initial_authorities() -> Vec<(AccountId, BabeId, GrandpaId, ImOnlineId, RoleKeyId)> {
vec![
// standalone 1
// tangle 1
(
hex!["6c99e8e4ae3fe7e3328d7e9d85eb98e86bdc6410695797349fa536ebb9bb0a4a"].into(),
hex!["d8a00a2454cd7455c040e363e6e76f4abd9e4d3876253964d9f40a66ad79694b"]
hex!["4e85271af1330e5e9384bd3ac5bdc04c0f8ef5a8cc29c1a8ae483d674164745c"].into(),
hex!["82a764a9835b2ac7aacd8ec96479d872e91256fba11cc0393b0e98dd320bbf38"]
.unchecked_into(),
hex!["5bcf983a969f8de7628b271a5bf523924856c3935b15eb3e03f20146ced2c57f"]
hex!["71bf01524c555f1e0f6b7dc7243caf00851d3afc543422f98d3eb6bca78acd8c"]
.unchecked_into(),
hex!["0297bc051d94b25787482e60fa4eba19f15af30fa244240ae4439d219ee00e78"]
hex!["2c7d0dbc639d8d52d02e9e03b6dd19b50f44a6a491ca75c9ebd6a1a29782e743"]
.unchecked_into(),
hex!["02a1af3c93d94e9b658a9aaa994bfa3fc156c9d38c60872d3dd33f63cd7aa12a6b"]
.unchecked_into(),
),
// standalone 2
// tangle 2
(
hex!["444dbfd0220eb1a993a7a2b9e1530aee1d17388ba3db34a0ee2b8ff971bfd073"].into(),
hex!["f02ee9baa32c490cf06eabe3580a90be704618f04636b321ee599c8912392c7a"]
hex!["587c2ef00ec0a1b98af4c655763acd76ece690fccbb255f01663660bc274960d"].into(),
hex!["020af75377d0b400946938970c47055a2a48ad4fd728a427b7a1dd96e75db65f"]
.unchecked_into(),
hex!["61f771ebfdb0a6de08b8e0ca7a39a01f24e7eaa3d1e7f1001e6503490c25c044"]
.unchecked_into(),
hex!["2d6ac10cde791863771847c035c36e13ad60e6129465e1aefad8f5fee8dff5c7"]
hex!["ecb58b3d1eaaad8ef42c27e183e41830628ca5fee5bb06cdf13883e57c4a0770"]
.unchecked_into(),
hex!["de6d5010678fd2175fe70c857d3eba80838e3735b1051f4aed98671800ec483f"]
hex!["0305c8dd5a251ed604350f50a993edc9baa66fb72b56091346316dd94052a068fa"]
.unchecked_into(),
),
// standalone 3
// tangle 3
(
hex!["2c4e648b0fbbb88ff6b92b208273eb144383b2b19edc992e91448a4371d4d97d"].into(),
hex!["a41b35f75e5509ce96e62bc27bb9a1b5587cc3d596f8afa867962b0e03230513"]
hex!["a24f729f085de51eebaeaeca97d6d499761b8f6daeca9b99d754a06ef8bcec3f"].into(),
hex!["a8f14e015ced0b21e680e577231519c33484d1b63f5529bf4fbb137a920bb82e"]
.unchecked_into(),
hex!["a41a815db90b9bd3d9ec462f90ba77ba1d627a9fccc9f7847e34c9e9e9b57c90"]
.unchecked_into(),
hex!["340e5969c8dd40ff77184fa73fbdcda77dcc90dd9b68b8b28eef5f01ce42339c"]
hex!["2ef4f718a407e0b4d86913a989f749b7edfe836bae1d726b07f9c419ad94c42c"]
.unchecked_into(),
hex!["8472336050c4e4a51ac69865a4a31c6dd0e5c2f79555d8646cafb3bd8f12d75c"]
hex!["02825faaf113b15b28dfdfe52eeee66554fe2892825e146d20ac49dd7c37d6e793"]
.unchecked_into(),
),
// standalone 4
// tangle 4
(
hex!["c884c8eb280327221a3ae6a45fe6c8805f09bcfc11b409c8e2daa621c0d99608"].into(),
hex!["06e0a0d39503a101ca9c36f84b3ccf53015ee625a546bc570e550af963d13164"]
hex!["0a55e5245382700f35d16a5ea6d60a56c36c435bef7204353b8c36871f347857"].into(),
hex!["2296eb6f84cafd066c07e19fd127e7f5ca0d6e26ce305f9facc0e0221c7ecb1a"]
.unchecked_into(),
hex!["57eda010788108257f4c148cf0c3112d620b9067546777dc393a65dd34732079"]
hex!["b0f002333f4fd657155dfcb4ac5c6ce04d0b2c68b64befa178d4357ceb05fe2d"]
.unchecked_into(),
hex!["029cb182ddb9c5560aaa299f7b445e575007b8295bd85a80a7b2eb7baa3e2b7c"]
hex!["dc8be4d69084d5bb8a6a0cd48c4d3ab82def85e996b87c63176b49f70c028c35"]
.unchecked_into(),
hex!["02745849fbb4cf0f1f9f310cf67740431fd4cd1b4292bb1a3efeb93956e612e75f"]
.unchecked_into(),
),
// standalone 5
// tangle 5
(
hex!["483e0b8d6801c51115fd4b124c91e2d5dcd642b30335f6c5a1738ea18f66c251"].into(),
hex!["ce80df4851003f6ffd4ee88d9be85966f1de8b2e494c009dbf336177485f023f"]
hex!["e0948453e7acbc6ac937e124eb01580191e99f4262d588d4524994deb6134349"].into(),
hex!["0e08bb5a9cc4e7dbd279ba53bd5aecd78956c34a2dae678c5490c52bc754521e"]
.unchecked_into(),
hex!["d2eb206f8c7a64ce47828b33314806ac6cb915d464990eaff9f6435880c6e54f"]
.unchecked_into(),
hex!["9027284e6cad3f73eee950695c56f87330311331139616640c9168934dba82df"]
hex!["363e33c500396cc52ef58924a005227eed67801bd376ca886fd6432ba7070711"]
.unchecked_into(),
hex!["1ea007d87f91f96c31b1062548eb77c40d47a43f1c84c36caa8586fc7c359729"]
hex!["03dd29b916c41662207e2e5b7dd7c5c7054681bef8897bd4f0634b9075463159ca"]
.unchecked_into(),
),
]
Expand Down
17 changes: 8 additions & 9 deletions primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ pub mod currency {
pub const WEIGHT_FEE: Balance = 100 * MEGAWEI;
/// Return the cost to add an item to storage based on size
pub const fn deposit(items: u32, bytes: u32) -> Balance {
items as Balance * 20 * DOLLAR + (bytes as Balance) * 100 * MILLICENT
items as Balance * 10 * DOLLAR + (bytes as Balance) * 100 * MILLICENT
}
}

Expand Down Expand Up @@ -226,13 +226,12 @@ pub mod evm {

pub mod democracy {
use crate::{currency::UNIT, time::MINUTES, Balance, BlockNumber};

pub const LAUNCH_PERIOD: BlockNumber = 28 * 24 * 60 * MINUTES;
pub const VOTING_PERIOD: BlockNumber = 28 * 24 * 60 * MINUTES;
pub const FASTTRACK_VOTING_PERIOD: BlockNumber = 3 * 24 * 60 * MINUTES;
pub const MINIMUM_DEPOSIT: Balance = 100 * UNIT;
pub const ENACTMENT_PERIOD: BlockNumber = 30 * 24 * 60 * MINUTES;
pub const COOLOFF_PERIOD: BlockNumber = 28 * 24 * 60 * MINUTES;
pub const LAUNCH_PERIOD: BlockNumber = 10 * 24 * 60 * MINUTES; // 10 days
pub const VOTING_PERIOD: BlockNumber = 10 * 24 * 60 * MINUTES; // 10 days
pub const FASTTRACK_VOTING_PERIOD: BlockNumber = 3 * 24 * 60 * MINUTES; // 3 days
pub const MINIMUM_DEPOSIT: Balance = 1000 * UNIT; // 1000 TNT
pub const ENACTMENT_PERIOD: BlockNumber = 3 * 24 * 60 * MINUTES; // 3 days
pub const COOLOFF_PERIOD: BlockNumber = 3 * 24 * 60 * MINUTES; // 3 days
pub const MAX_PROPOSALS: u32 = 100;
}

Expand Down Expand Up @@ -260,7 +259,7 @@ pub mod treasury {
pub const PROPOSAL_BOND: Permill = Permill::from_percent(5);
pub const PROPOSAL_BOND_MINIMUM: Balance = UNIT;
pub const SPEND_PERIOD: BlockNumber = DAYS;
pub const BURN: Permill = Permill::from_percent(50);
pub const BURN: Permill = Permill::from_percent(0);
pub const TIP_COUNTDOWN: BlockNumber = DAYS;
pub const TIP_FINDERS_FEE: Percent = Percent::from_percent(20);
pub const TIP_REPORT_DEPOSIT_BASE: Balance = UNIT;
Expand Down
4 changes: 4 additions & 0 deletions runtime/mainnet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ pallet-vesting = { workspace = true }
# Webb dependencies
tangle-crypto-primitives = { workspace = true }
tangle-primitives = { workspace = true }
pallet-roles = { workspace = true }
pallet-jobs = { workspace = true }

# Frontier dependencies
fp-account = { workspace = true }
Expand Down Expand Up @@ -202,7 +204,9 @@ std = [
"pallet-airdrop-claims/std",
"pallet-identity/std",
"frame-system-benchmarking?/std",
"pallet-roles/std",
"sp-storage/std",
"pallet-jobs/std",

# Tangle dependencies
"tangle-primitives/std",
Expand Down
Loading

0 comments on commit 59c81d2

Please sign in to comment.