Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/pm-quality-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ jobs:
- "pallets/qpow"
- "pallets/reversible-transfers"
- "pallets/scheduler"
- "pallets/vesting"
- "pallets/wormhole"
- "primitives/consensus/qpow"
- "primitives/dilithium-crypto"
Expand Down
9 changes: 6 additions & 3 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ members = [
"pallets/qpow",
"pallets/reversible-transfers",
"pallets/scheduler",
"pallets/vesting",
"pallets/wormhole",
"primitives/consensus/pow",
"primitives/consensus/qpow",
Expand Down Expand Up @@ -133,6 +134,7 @@ pallet-mining-rewards = { path = "./pallets/mining-rewards", default-features =
pallet-qpow = { path = "./pallets/qpow", default-features = false }
pallet-reversible-transfers = { path = "./pallets/reversible-transfers", default-features = false }
pallet-scheduler = { path = "./pallets/scheduler", default-features = false }
pallet-vesting = { path = "./pallets/vesting", default-features = false }
pallet-wormhole = { path = "./pallets/wormhole", default-features = false }
qp-dilithium-crypto = { path = "./primitives/dilithium-crypto", version = "0.2.0", default-features = false }
qp-scheduler = { path = "./primitives/scheduler", default-features = false }
Expand Down Expand Up @@ -182,7 +184,6 @@ pallet-transaction-payment-rpc = { version = "44.0.0", default-features = false
pallet-transaction-payment-rpc-runtime-api = { version = "41.0.0", default-features = false }
pallet-treasury = { version = "40.0.0", default-features = false }
pallet-utility = { version = "41.0.0", default-features = false }
pallet-vesting = { version = "41.0.0", default-features = false }
prometheus-endpoint = { version = "0.17.2", default-features = false, package = "substrate-prometheus-endpoint" }
sc-basic-authorship = { version = "0.50.0", default-features = false }
sc-block-builder = { version = "0.45.0", default-features = true }
Expand Down
1 change: 1 addition & 0 deletions pallets/merkle-airdrop/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ sp-runtime.workspace = true
[dev-dependencies]
pallet-balances.features = ["std"]
pallet-balances.workspace = true
pallet-timestamp.workspace = true
pallet-vesting.workspace = true
sp-core.workspace = true
sp-io.workspace = true
Expand Down
9 changes: 6 additions & 3 deletions pallets/merkle-airdrop/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fn calculate_expected_root_for_benchmark(
#[benchmarks(
where
T: Send + Sync,
T: Config + pallet_vesting::Config<Currency = CurrencyOf<T>>,
T: Config + pallet_vesting::Config,
)]
mod benchmarks {
use super::*;
Expand Down Expand Up @@ -71,7 +71,7 @@ mod benchmarks {

NextAirdropId::<T>::put(airdrop_id + 1);

let amount: BalanceOf<T> = <T as pallet_vesting::Config>::MinVestedTransfer::get();
let amount: BalanceOf<T> = 100u32.into();

// Get ED and ensure caller has sufficient balance
let ed = CurrencyOf::<T>::minimum_balance();
Expand All @@ -90,7 +90,10 @@ mod benchmarks {
let caller: T::AccountId = whitelisted_caller();
let recipient: T::AccountId = account("recipient", 0, 0);

let amount: BalanceOf<T> = <T as pallet_vesting::Config>::MinVestedTransfer::get();
// Use large amount to cover existential deposit requirements
// 10 billion = 10 * 1_000_000_000
let amount: BalanceOf<T> = 1000u32.into();
let amount = amount.saturating_mul(10_000_000u32.into());

// 1. Calculate the initial leaf hash
let leaf_hash = MerkleAirdrop::<T>::calculate_leaf_hash_blake2(&recipient, amount);
Expand Down
41 changes: 25 additions & 16 deletions pallets/merkle-airdrop/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ pub mod pallet {
);

ensure!(airdrop_metadata.balance >= amount, Error::<T>::InsufficientAirdropBalance);
ensure!(!amount.is_zero(), Error::<T>::InsufficientAirdropBalance);

// Mark as claimed before performing the transfer
Claimed::<T>::insert(airdrop_id, &recipient, ());
Expand All @@ -477,25 +478,33 @@ pub mod pallet {
}
});

let per_block = if let Some(vesting_period) = airdrop_metadata.vesting_period {
amount
// If there's no vesting period, do a direct transfer
// Otherwise, use vested_transfer for gradual unlocking
if let Some(vesting_period) = airdrop_metadata.vesting_period {
let per_block = amount
.checked_div(&T::BlockNumberToBalance::convert(vesting_period))
.ok_or(Error::<T>::InsufficientAirdropBalance)?
} else {
amount
};
.ok_or(Error::<T>::InsufficientAirdropBalance)?;

let current_block = T::BlockNumberProvider::current_block_number();
let vesting_start =
current_block.saturating_add(airdrop_metadata.vesting_delay.unwrap_or_default());
let current_block = T::BlockNumberProvider::current_block_number();
let vesting_start = current_block
.saturating_add(airdrop_metadata.vesting_delay.unwrap_or_default());

T::Vesting::vested_transfer(
&Self::account_id(),
&recipient,
amount,
per_block,
vesting_start,
)?;
T::Vesting::vested_transfer(
&Self::account_id(),
&recipient,
amount,
per_block,
vesting_start,
)?;
} else {
// No vesting - direct transfer from airdrop pallet account to recipient
CurrencyOf::<T>::transfer(
&Self::account_id(),
&recipient,
amount,
frame_support::traits::ExistenceRequirement::AllowDeath,
)?;
}

Self::deposit_event(Event::Claimed { airdrop_id, account: recipient, amount });

Expand Down
29 changes: 17 additions & 12 deletions pallets/merkle-airdrop/src/mock.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate as pallet_merkle_airdrop;
use frame_support::{
parameter_types,
traits::{ConstU32, Everything, WithdrawReasons},
traits::{ConstU32, Everything},
PalletId,
};
use frame_system::{self as system};
Expand All @@ -17,6 +17,7 @@ type Block = frame_system::mocking::MockBlock<Test>;
frame_support::construct_runtime!(
pub enum Test {
System: frame_system,
Timestamp: pallet_timestamp,
Vesting: pallet_vesting,
Balances: pallet_balances,
MerkleAirdrop: pallet_merkle_airdrop,
Expand Down Expand Up @@ -83,21 +84,25 @@ impl pallet_balances::Config for Test {
}

parameter_types! {
pub const MinVestedTransfer: u64 = 1;
pub UnvestedFundsAllowedWithdrawReasons: WithdrawReasons =
WithdrawReasons::except(WithdrawReasons::TRANSFER | WithdrawReasons::RESERVE);
pub const MinimumPeriod: u64 = 1;
}

impl pallet_vesting::Config for Test {
type RuntimeEvent = RuntimeEvent;
type Currency = Balances;
impl pallet_timestamp::Config for Test {
type Moment = u64;
type OnTimestampSet = ();
type MinimumPeriod = MinimumPeriod;
type WeightInfo = ();
type BlockNumberProvider = System;
type MinVestedTransfer = MinVestedTransfer;
type BlockNumberToBalance = ConvertInto;
type UnvestedFundsAllowedWithdrawReasons = UnvestedFundsAllowedWithdrawReasons;
}

const MAX_VESTING_SCHEDULES: u32 = 3;
parameter_types! {
pub const VestingPalletId: PalletId = PalletId(*b"vestpal_");
pub const MaxSchedulesPerBeneficiary: u32 = 50;
}

impl pallet_vesting::Config for Test {
type PalletId = VestingPalletId;
type WeightInfo = ();
type MaxSchedulesPerBeneficiary = MaxSchedulesPerBeneficiary;
}

parameter_types! {
Expand Down
Loading
Loading