Skip to content

Commit

Permalink
Linear release merging schedules
Browse files Browse the repository at this point in the history
  • Loading branch information
JuaniRios committed Sep 3, 2024
1 parent 1787628 commit e243ba0
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 23 deletions.
2 changes: 2 additions & 0 deletions pallets/funding/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pallets/funding/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1451,7 +1451,7 @@ mod benchmarks {
HoldReason::Participation.into(),
);
assert_eq!(
<T as Config>::Vesting::total_scheduled_amount(&contributor, HoldReason::Participation.into()),
VestingOf::<T>::total_scheduled_amount(&contributor, HoldReason::Participation.into()),
Some(contribution_to_settle.plmc_bond)
);
let funding_account = project_metadata.funding_destination_account;
Expand Down
4 changes: 2 additions & 2 deletions pallets/funding/src/functions/6_settlement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ impl<T: Config> Pallet<T> {
Self::calculate_vesting_info(&bid.bidder, bid.multiplier, bid.plmc_bond.saturating_sub(refunded_plmc))
.map_err(|_| Error::<T>::BadMath)?;

T::Vesting::add_release_schedule(
VestingOf::<T>::add_release_schedule(
&bid.bidder,
plmc_vesting_info.total_amount,
plmc_vesting_info.amount_per_block,
Expand Down Expand Up @@ -257,7 +257,7 @@ impl<T: Config> Pallet<T> {
)
.map_err(|_| Error::<T>::BadMath)?;

T::Vesting::add_release_schedule(
VestingOf::<T>::add_release_schedule(
&contribution.contributor,
vest_info.total_amount,
vest_info.amount_per_block,
Expand Down
20 changes: 8 additions & 12 deletions pallets/funding/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ pub type ContributionInfoOf<T> =

pub type BucketOf<T> = Bucket<BalanceOf<T>, PriceOf<T>>;
pub type WeightInfoOf<T> = <T as Config>::WeightInfo;
pub type VestingOf<T> = pallet_linear_release::Pallet<T>;

pub const PLMC_FOREIGN_ID: u32 = 3344;
pub const PLMC_DECIMALS: u8 = 10;
Expand Down Expand Up @@ -176,7 +177,13 @@ pub mod pallet {

#[pallet::config]
pub trait Config:
frame_system::Config + pallet_balances::Config<Balance = BalanceOf<Self>> + pallet_xcm::Config
frame_system::Config
+ pallet_balances::Config<Balance = BalanceOf<Self>>
+ pallet_xcm::Config
+ pallet_linear_release::Config<
Balance = BalanceOf<Self>,
RuntimeHoldReason = <Self as Config>::RuntimeHoldReason,
>
{
/// A way to convert from and to the account type used in CT migrations
type AccountId32Conversion: ConvertBack<Self::AccountId, [u8; 32]>;
Expand All @@ -194,9 +201,6 @@ pub mod pallet {
/// BlockNumber used for PLMC vesting durations on this chain, and CT vesting durations on funded chains.
type BlockNumber: IsType<BlockNumberFor<Self>> + Into<u64>;

/// The length (expressed in number of blocks) of the Auction Round, Closing period.
type BlockNumberToBalance: Convert<BlockNumberFor<Self>, BalanceOf<Self>>;

/// The length (expressed in number of blocks) of the Community Round.
#[pallet::constant]
type CommunityRoundDuration: Get<BlockNumberFor<Self>>;
Expand Down Expand Up @@ -367,14 +371,6 @@ pub mod pallet {
#[pallet::constant]
type VerifierPublicKey: Get<[u8; 32]>;

/// The type used for vesting
type Vesting: polimec_common::ReleaseSchedule<
AccountIdOf<Self>,
<Self as Config>::RuntimeHoldReason,
Currency = Self::NativeCurrency,
Moment = BlockNumberFor<Self>,
>;

/// Struct holding information about extrinsic weights
type WeightInfo: weights::WeightInfo;
}
Expand Down
2 changes: 0 additions & 2 deletions pallets/funding/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -436,7 +435,6 @@ impl Config for TestRuntime {
type SetPrices = ();
type StringLimit = ConstU32<64>;
type VerifierPublicKey = VerifierPublicKey;
type Vesting = LinearRelease;
type WeightInfo = weights::SubstrateWeight<TestRuntime>;
}

Expand Down
8 changes: 4 additions & 4 deletions pallets/funding/src/tests/6_settlement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(|| {
<TestRuntime as Config>::Vesting::total_scheduled_amount(&BUYER_6, HoldReason::Participation.into())
VestingOf::<TestRuntime>::total_scheduled_amount(&BUYER_6, HoldReason::Participation.into())
});

assert_eq!(plmc_free_amount, inst.get_ed());
Expand All @@ -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(|| {
<TestRuntime as Config>::Vesting::total_scheduled_amount(&BUYER_6, HoldReason::Participation.into())
VestingOf::<TestRuntime>::total_scheduled_amount(&BUYER_6, HoldReason::Participation.into())
});

assert_eq!(plmc_free_amount, inst.get_ed() + stored_contribution.plmc_bond);
Expand All @@ -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(|| {
<TestRuntime as Config>::Vesting::total_scheduled_amount(&BUYER_7, HoldReason::Participation.into())
VestingOf::<TestRuntime>::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);
Expand All @@ -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(|| {
<TestRuntime as Config>::Vesting::total_scheduled_amount(&BUYER_7, HoldReason::Participation.into())
VestingOf::<TestRuntime>::total_scheduled_amount(&BUYER_7, HoldReason::Participation.into())
});

assert_eq!(plmc_free_amount, inst.get_ed() + stored_contribution.plmc_bond);
Expand Down
2 changes: 0 additions & 2 deletions runtimes/polimec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Runtime>;
}

Expand Down

0 comments on commit e243ba0

Please sign in to comment.