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

πŸ‘¨πŸ»β€πŸ’» Tightly couple linear-release to funding pallet #391

Merged
merged 1 commit into from
Sep 12, 2024
Merged
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
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 @@ -145,6 +145,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 @@ -179,7 +180,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 @@ -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<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 @@ -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<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