Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Treasury proposal 2024 #1246

Merged
merged 14 commits into from
Jul 2, 2024
1 change: 1 addition & 0 deletions control/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
.local

/scratch
chopsticks-execute-upgrade.js
1 change: 1 addition & 0 deletions control/preimage/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ mod polkadot {
pub const ASSET_HUB_API: &str = "wss://polkadot-asset-hub-rpc.polkadot.io";
pub const BRIDGE_HUB_ID: u32 = 1002;
pub const BRIDGE_HUB_API: &str = "wss://polkadot-bridge-hub-rpc.polkadot.io";
pub const RELAY_API: &str = "wss://polkadot.api.onfinality.io/public-ws";
}

#[cfg(feature = "polkadot")]
Expand Down
88 changes: 87 additions & 1 deletion control/preimage/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ pub async fn query_weight_asset_hub(

pub fn utility_force_batch(calls: Vec<RelayRuntimeCall>) -> RelayRuntimeCall {
RelayRuntimeCall::Utility(
crate::relay_runtime::runtime_types::pallet_utility::pallet::Call::force_batch { calls },
crate::relay_runtime::runtime_types::pallet_utility::pallet::Call::batch_all { calls },
)
}

Expand Down Expand Up @@ -222,3 +222,89 @@ pub async fn calculate_delivery_fee(

Ok(fee)
}

use polkadot_runtime::api::runtime_types::pallet_vesting::vesting_info::VestingInfo;
use polkadot_runtime::api::*;
use subxt::utils::MultiAddress;

pub async fn instant_payout(
_context: &Context,
amount: u128,
account: [u8; 32],
) -> Result<RelayRuntimeCall, Box<dyn std::error::Error>> {
let call = RelayRuntimeCall::Treasury(treasury::Call::spend_local {
amount,
beneficiary: MultiAddress::Address32(account),
});

Ok(call)
}

pub async fn schedule_payout(
ctx: &Context,
amount: u128,
account: [u8; 32],
delay: u32,
) -> Result<RelayRuntimeCall, Box<dyn std::error::Error>> {
use crate::relay_runtime::runtime_types::{
staging_xcm::v3::multilocation::MultiLocation,
xcm::{
v3::{junction::Junction, junctions::Junctions},
VersionedLocation,
},
};
let current_block = ctx.relay_api.blocks().at_latest().await?.number();
let future_block = current_block + delay;
let call = RelayRuntimeCall::Treasury(treasury::Call::spend {
asset_kind: Box::new(
runtime_types::polkadot_runtime_common::impls::VersionedLocatableAsset::V3 {
location: MultiLocation {
parents: 0,
interior: Junctions::X1(Junction::Parachain(ASSET_HUB_ID)),
},
asset_id: runtime_types::xcm::v3::multiasset::AssetId::Concrete {
0: MultiLocation {
parents: 1,
interior: Junctions::Here,
},
},
},
),
beneficiary: Box::new(VersionedLocation::V3 {
0: MultiLocation {
parents: 0,
interior: Junctions::X1(Junction::AccountId32 {
network: None,
id: account,
}),
},
}),
amount,
valid_from: Some(future_block),
});

Ok(call)
}

pub async fn vesting_payout(
ctx: &Context,
locked: u128,
per_block: u128,
source: [u8; 32],
target: [u8; 32],
delay: u32,
) -> Result<RelayRuntimeCall, Box<dyn std::error::Error>> {
let current_block = ctx.relay_api.blocks().at_latest().await?.number();
let starting_block = current_block + delay;
let call = RelayRuntimeCall::Vesting(vesting::Call::force_vested_transfer {
source: MultiAddress::Address32(source),
target: MultiAddress::Address32(target),
schedule: VestingInfo {
locked,
per_block,
starting_block,
},
});

Ok(call)
}
70 changes: 68 additions & 2 deletions control/preimage/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ use alloy_primitives::{utils::parse_units, Address, Bytes, FixedBytes, U128, U25
use chopsticks::generate_chopsticks_script;
use clap::{Args, Parser, Subcommand, ValueEnum};
use codec::Encode;
use constants::{ASSET_HUB_API, BRIDGE_HUB_API, POLKADOT_DECIMALS, POLKADOT_SYMBOL};
use helpers::{force_xcm_version, send_xcm_asset_hub, send_xcm_bridge_hub, utility_force_batch};
use constants::{ASSET_HUB_API, BRIDGE_HUB_API, POLKADOT_DECIMALS, POLKADOT_SYMBOL, RELAY_API};
use helpers::{
force_xcm_version, instant_payout, schedule_payout, send_xcm_asset_hub, send_xcm_bridge_hub,
utility_force_batch, vesting_payout,
};
use sp_crypto_hashing::blake2_256;
use std::{io::Write, path::PathBuf};
use subxt::{OnlineClient, PolkadotConfig};
Expand Down Expand Up @@ -44,6 +47,8 @@ pub enum Command {
PricingParameters(PricingParametersArgs),
/// Set the checkpoint for the beacon light client
ForceCheckpoint(ForceCheckpointArgs),
/// Treasury proposal
TreasuryProposal2024,
}

#[derive(Debug, Args)]
Expand Down Expand Up @@ -173,11 +178,15 @@ pub struct ApiEndpoints {

#[arg(long, value_name = "URL")]
asset_hub_api: Option<String>,

#[arg(long, value_name = "URL")]
relay_api: Option<String>,
}

fn parse_eth_address(v: &str) -> Result<Address, String> {
Address::parse_checksummed(v, None).map_err(|_| "invalid ethereum address".to_owned())
}
use hex_literal::hex;
use std::str::FromStr;

fn parse_eth_address_without_validation(v: &str) -> Result<Address, String> {
Expand Down Expand Up @@ -220,6 +229,7 @@ pub enum Format {
struct Context {
bridge_hub_api: Box<OnlineClient<PolkadotConfig>>,
asset_hub_api: Box<OnlineClient<PolkadotConfig>>,
relay_api: Box<OnlineClient<PolkadotConfig>>,
}

#[tokio::main]
Expand All @@ -246,9 +256,13 @@ async fn run() -> Result<(), Box<dyn std::error::Error>> {
)
.await?;

let relay_api: OnlineClient<PolkadotConfig> =
OnlineClient::from_url(cli.api_endpoints.relay_api.unwrap_or(RELAY_API.to_owned())).await?;

let context = Context {
bridge_hub_api: Box::new(bridge_hub_api),
asset_hub_api: Box::new(asset_hub_api),
relay_api: Box::new(relay_api),
};

let call = match &cli.command {
Expand Down Expand Up @@ -298,6 +312,58 @@ async fn run() -> Result<(), Box<dyn std::error::Error>> {
let call2 = send_xcm_asset_hub(&context, vec![set_ethereum_fee]).await?;
utility_force_batch(vec![call1, call2])
}
Command::TreasuryProposal2024 => {
let beneficiary: [u8; 32] =
hex!("40ff75e9f6e5eea6579fd37a8296c58b0ff0f0940ea873e5d26b701163b1b325");

let mut scheduled_calls: Vec<
polkadot_runtime::api::runtime_types::polkadot_runtime::RuntimeCall,
> = vec![];

// Immediate direct payout of 191379 DOT
let instant_pay_amount: u128 = 1913790000000000;
let call = instant_payout(&context, instant_pay_amount, beneficiary).await?;
scheduled_calls.push(call);

// Immediate 2-year vesting payout of 323275 DOT
let vesting_pay_amount: u128 = 3232750000000000;
let vesting_period: u32 = 2 * 365 * 24 * 3600 / 6;
let per_block: u128 = vesting_pay_amount / (vesting_period as u128);
let treasury: [u8; 32] =
hex!("6d6f646c70792f74727372790000000000000000000000000000000000000000");
// consider the proposal unconfirmed, start vesting after 45 days to make sure the
// starting_block is valid.
let delay: u32 = 45 * 24 * 3600 / 6;
let call = vesting_payout(
&context,
vesting_pay_amount,
per_block,
treasury,
beneficiary,
delay,
)
.await?;
scheduled_calls.push(call);

// Scheduled payout in 75 days from now of 161637 DOT
let scheduled_pay_amount: u128 = 1616370000000000;
yrong marked this conversation as resolved.
Show resolved Hide resolved
let delay: u32 = 75 * 24 * 3600 / 6;
let call = schedule_payout(&context, scheduled_pay_amount, beneficiary, delay).await?;
scheduled_calls.push(call);

// 6 x scheduled payouts of 53879 DOT each, starting 3.5 months from now
// and repeating 6 times from Sept 2024 - Feb 2025 every month
let scheduled_pay_amount: u128 = 538790000000000;
let mut delay: u32 = 105 * 24 * 3600 / 6;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for _ in 0..6 {
let call =
schedule_payout(&context, scheduled_pay_amount, beneficiary, delay).await?;
scheduled_calls.push(call);
delay = delay + (30 * 24 * 3600 / 6)
}

utility_force_batch(scheduled_calls)
}
};

let preimage = call.encode();
Expand Down
4 changes: 2 additions & 2 deletions control/preimage/src/relay_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ pub use rococo_runtime::runtime_types::rococo_runtime::RuntimeCall;
pub use rococo_runtime::*;

#[cfg(feature = "polkadot")]
pub use polkadot_runtime::runtime_types::polkadot_runtime::RuntimeCall;
pub use polkadot_runtime::api::*;
#[cfg(feature = "polkadot")]
pub use polkadot_runtime::*;
pub use polkadot_runtime::runtime::api::runtime_types::polkadot_runtime::RuntimeCall;
6 changes: 1 addition & 5 deletions control/runtimes/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
#[subxt::subxt(
runtime_metadata_path = "polkadot-metadata.bin",
derive_for_all_types = "Clone"
)]
mod runtime {}
pub mod runtime;

pub use runtime::*;
Loading