From a3347fa63c1ea363d685592c3f73e27b9ded1b46 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Rios Date: Tue, 3 Sep 2024 10:23:03 +0200 Subject: [PATCH] Linear release merging schedules --- pallets/funding/Cargo.toml | 2 ++ pallets/funding/src/benchmarking.rs | 2 +- pallets/funding/src/functions/6_settlement.rs | 4 ++-- pallets/funding/src/lib.rs | 20 ++++++++----------- pallets/funding/src/mock.rs | 2 -- pallets/funding/src/tests/6_settlement.rs | 8 ++++---- runtimes/polimec/src/lib.rs | 2 -- 7 files changed, 17 insertions(+), 23 deletions(-) diff --git a/pallets/funding/Cargo.toml b/pallets/funding/Cargo.toml index 430f2fa90..c21ef635e 100644 --- a/pallets/funding/Cargo.toml +++ b/pallets/funding/Cargo.toml @@ -27,6 +27,8 @@ scale-info = { workspace = true, default-features = false, features = [ log.workspace = true variant_count = "1.1.0" +pallet-linear-release.workspace = true + # Substrate dependencies frame-support.workspace = true frame-system.workspace = true diff --git a/pallets/funding/src/benchmarking.rs b/pallets/funding/src/benchmarking.rs index 145ab87b9..5df91e157 100644 --- a/pallets/funding/src/benchmarking.rs +++ b/pallets/funding/src/benchmarking.rs @@ -1451,7 +1451,7 @@ mod benchmarks { HoldReason::Participation.into(), ); assert_eq!( - ::Vesting::total_scheduled_amount(&contributor, HoldReason::Participation.into()), + VestingOf::::total_scheduled_amount(&contributor, HoldReason::Participation.into()), Some(contribution_to_settle.plmc_bond) ); let funding_account = project_metadata.funding_destination_account; diff --git a/pallets/funding/src/functions/6_settlement.rs b/pallets/funding/src/functions/6_settlement.rs index a72977c6a..89a211983 100644 --- a/pallets/funding/src/functions/6_settlement.rs +++ b/pallets/funding/src/functions/6_settlement.rs @@ -160,7 +160,7 @@ impl Pallet { Self::calculate_vesting_info(&bid.bidder, bid.multiplier, bid.plmc_bond.saturating_sub(refunded_plmc)) .map_err(|_| Error::::BadMath)?; - T::Vesting::add_release_schedule( + VestingOf::::add_release_schedule( &bid.bidder, plmc_vesting_info.total_amount, plmc_vesting_info.amount_per_block, @@ -257,7 +257,7 @@ impl Pallet { ) .map_err(|_| Error::::BadMath)?; - T::Vesting::add_release_schedule( + VestingOf::::add_release_schedule( &contribution.contributor, vest_info.total_amount, vest_info.amount_per_block, diff --git a/pallets/funding/src/lib.rs b/pallets/funding/src/lib.rs index 8c49ca64d..9950ece28 100644 --- a/pallets/funding/src/lib.rs +++ b/pallets/funding/src/lib.rs @@ -145,6 +145,7 @@ pub type ContributionInfoOf = pub type BucketOf = Bucket, PriceOf>; pub type WeightInfoOf = ::WeightInfo; +pub type VestingOf = pallet_linear_release::Pallet; pub const PLMC_FOREIGN_ID: u32 = 3344; pub const PLMC_DECIMALS: u8 = 10; @@ -179,7 +180,13 @@ pub mod pallet { #[pallet::config] pub trait Config: - frame_system::Config + pallet_balances::Config> + pallet_xcm::Config + frame_system::Config + + pallet_balances::Config> + + pallet_xcm::Config + + pallet_linear_release::Config< + Balance = BalanceOf, + RuntimeHoldReason = ::RuntimeHoldReason, + > { /// A way to convert from and to the account type used in CT migrations type AccountId32Conversion: ConvertBack; @@ -197,9 +204,6 @@ pub mod pallet { /// BlockNumber used for PLMC vesting durations on this chain, and CT vesting durations on funded chains. type BlockNumber: IsType> + Into; - /// The length (expressed in number of blocks) of the Auction Round, Closing period. - type BlockNumberToBalance: Convert, BalanceOf>; - /// The length (expressed in number of blocks) of the Community Round. #[pallet::constant] type CommunityRoundDuration: Get>; @@ -370,14 +374,6 @@ pub mod pallet { #[pallet::constant] type VerifierPublicKey: Get<[u8; 32]>; - /// The type used for vesting - type Vesting: polimec_common::ReleaseSchedule< - AccountIdOf, - ::RuntimeHoldReason, - Currency = Self::NativeCurrency, - Moment = BlockNumberFor, - >; - /// Struct holding information about extrinsic weights type WeightInfo: weights::WeightInfo; } diff --git a/pallets/funding/src/mock.rs b/pallets/funding/src/mock.rs index 559d75e88..a0455490c 100644 --- a/pallets/funding/src/mock.rs +++ b/pallets/funding/src/mock.rs @@ -398,7 +398,6 @@ impl Config for TestRuntime { type AuctionRoundDuration = AuctionRoundDuration; type Balance = Balance; type BlockNumber = BlockNumber; - type BlockNumberToBalance = ConvertInto; type BlockchainOperationTreasury = BlockchainOperationTreasuryAccount; type CommunityRoundDuration = CommunityRoundDuration; type ContributionTokenCurrency = ContributionTokens; @@ -436,7 +435,6 @@ impl Config for TestRuntime { type SetPrices = (); type StringLimit = ConstU32<64>; type VerifierPublicKey = VerifierPublicKey; - type Vesting = LinearRelease; type WeightInfo = weights::SubstrateWeight; } diff --git a/pallets/funding/src/tests/6_settlement.rs b/pallets/funding/src/tests/6_settlement.rs index a999a99b7..65f16ff18 100644 --- a/pallets/funding/src/tests/6_settlement.rs +++ b/pallets/funding/src/tests/6_settlement.rs @@ -1124,7 +1124,7 @@ mod settle_contribution_extrinsic { let issuer_usdt_balance = inst.get_free_funding_asset_balance_for(stored_contribution.funding_asset.id(), issuer); let unvested_amount = inst.execute(|| { - ::Vesting::total_scheduled_amount(&BUYER_6, HoldReason::Participation.into()) + VestingOf::::total_scheduled_amount(&BUYER_6, HoldReason::Participation.into()) }); assert_eq!(plmc_free_amount, inst.get_ed()); @@ -1144,7 +1144,7 @@ mod settle_contribution_extrinsic { let issuer_usdt_balance = inst.get_free_funding_asset_balance_for(stored_contribution.funding_asset.id(), issuer); let unvested_amount = inst.execute(|| { - ::Vesting::total_scheduled_amount(&BUYER_6, HoldReason::Participation.into()) + VestingOf::::total_scheduled_amount(&BUYER_6, HoldReason::Participation.into()) }); assert_eq!(plmc_free_amount, inst.get_ed() + stored_contribution.plmc_bond); @@ -1170,7 +1170,7 @@ mod settle_contribution_extrinsic { let issuer_usdt_balance_2 = inst.get_free_funding_asset_balance_for(stored_contribution.funding_asset.id(), issuer); let unvested_amount = inst.execute(|| { - ::Vesting::total_scheduled_amount(&BUYER_7, HoldReason::Participation.into()) + VestingOf::::total_scheduled_amount(&BUYER_7, HoldReason::Participation.into()) }); assert_eq!(plmc_free_amount, inst.get_ed()); assert_eq!(plmc_held_amount, stored_contribution.plmc_bond); @@ -1189,7 +1189,7 @@ mod settle_contribution_extrinsic { let issuer_usdt_balance_2 = inst.get_free_funding_asset_balance_for(stored_contribution.funding_asset.id(), issuer); let unvested_amount = inst.execute(|| { - ::Vesting::total_scheduled_amount(&BUYER_7, HoldReason::Participation.into()) + VestingOf::::total_scheduled_amount(&BUYER_7, HoldReason::Participation.into()) }); assert_eq!(plmc_free_amount, inst.get_ed() + stored_contribution.plmc_bond); diff --git a/runtimes/polimec/src/lib.rs b/runtimes/polimec/src/lib.rs index 238aa8d01..88796a8be 100644 --- a/runtimes/polimec/src/lib.rs +++ b/runtimes/polimec/src/lib.rs @@ -1037,7 +1037,6 @@ impl pallet_funding::Config for Runtime { type AuctionRoundDuration = AuctionRoundDuration; type Balance = Balance; type BlockNumber = BlockNumber; - type BlockNumberToBalance = ConvertInto; type BlockchainOperationTreasury = BlockchainOperationTreasury; type CommunityRoundDuration = CommunityRoundDuration; type ContributionTokenCurrency = ContributionTokens; @@ -1075,7 +1074,6 @@ impl pallet_funding::Config for Runtime { type SetPrices = benchmark_helpers::SetOraclePrices; type StringLimit = ConstU32<64>; type VerifierPublicKey = VerifierPublicKey; - type Vesting = LinearRelease; type WeightInfo = weights::pallet_funding::WeightInfo; }