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

Add a new ReleaseSchedule trait #49

Merged
merged 81 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from 73 commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
f3eabc8
wip: Add initial trait
lrazovic Jul 17, 2023
69a52f2
feat: start to draft the ReleaseSchedule trait
lrazovic Jul 17, 2023
f3fc15e
wip: start linear-release pallet
lrazovic Jul 18, 2023
15d326a
Delete Cargo.toml
lrazovic Jul 18, 2023
3b10eb1
revert: Delete Cargo.toml
lrazovic Jul 18, 2023
9f0250e
revert pallet-funding changes
lrazovic Jul 18, 2023
51e6758
feat; hardcode the LockType to focus on the main logic
lrazovic Jul 18, 2023
17a8e57
wip: add release schedule
lrazovic Jul 18, 2023
afcd124
feat: add linear release to the funding pallet
lrazovic Jul 18, 2023
2a394d6
feat: relax the genesis config type
lrazovic Jul 19, 2023
a898aba
feat: the lock should now implement Ser and Des
lrazovic Jul 19, 2023
4f31ef3
fix: few tests
lrazovic Jul 19, 2023
280713a
feat: add the Ser and Des trait to LockType
lrazovic Jul 19, 2023
f0f063f
feat: the vesting_balance now uses the latest Inspect API
lrazovic Jul 19, 2023
b5830d8
tests: git gud
lrazovic Jul 19, 2023
38857e6
wip: save
JuaniRios Jul 14, 2023
8d3f835
feat(214): ProjectDetails changed. Evaluation total bond now stored i…
JuaniRios Jul 18, 2023
065dbe1
feat(214): bid refunds on failure due to candle end and ct soldout im…
JuaniRios Jul 19, 2023
926cb93
fix(funding): re-add serde into the Cargo.toml
lrazovic Jul 19, 2023
c513dd6
feat(214): tried to add final price check on new_with for CommunityFu…
JuaniRios Jul 19, 2023
f3d113b
fix(214): reflecting BidInfoFilter changes on tests
JuaniRios Jul 19, 2023
f3d83aa
feat: homogeneous parameters
lrazovic Jul 20, 2023
90d126c
feat: use multiple reasons
lrazovic Jul 20, 2023
0f503c6
doc: add TODO about different reasons
lrazovic Jul 20, 2023
e726198
test: add a new account
lrazovic Jul 21, 2023
2facc32
test: check what happens when merging different locks
lrazovic Jul 21, 2023
b32ff48
chore: move the imports to the main lib.rs
lrazovic Jul 21, 2023
7ca9262
feat: remove unused constraint
lrazovic Jul 21, 2023
0bd5d85
feat: add VestingTransferred event
lrazovic Jul 21, 2023
927fd91
chore: remove unused file
lrazovic Jul 12, 2023
485cc43
wip
lrazovic Jul 12, 2023
ebc45af
feat: the big cleanup
lrazovic Jul 13, 2023
edb84f6
make integration tests compile
lrazovic Jul 13, 2023
cc1cb23
feat: update to 0.9.42
lrazovic Jul 14, 2023
272b760
feat: add parachain staking
lrazovic Jul 14, 2023
4489e8c
fix: building using workspace inheritance
lrazovic Jul 14, 2023
79a616c
chore: fmt
JuaniRios Jul 14, 2023
5cd3a9f
chore(214): fix warnings
JuaniRios Jul 21, 2023
dee16ba
fix(214): broken auction unbond test fixed
JuaniRios Jul 21, 2023
6affad0
chore(214): cargo fmt
JuaniRios Jul 21, 2023
cca032c
chore(214): unsafe math fix
JuaniRios Jul 21, 2023
0b3beb8
chore(220): reorder imports
JuaniRios Jul 21, 2023
69ff08e
feat(220): do_evaluation_end uses the config type as threshold. Confi…
JuaniRios Jul 21, 2023
d5b4430
feat: add linear release to the funding pallet
lrazovic Jul 18, 2023
1020a30
tests: fix the used reason
lrazovic Jul 21, 2023
640ce58
Revert "tests: fix the used reason"
lrazovic Jul 21, 2023
749be27
Revert "feat: add linear release to the funding pallet"
lrazovic Jul 21, 2023
ef0f2e9
Revert "feat(220): do_evaluation_end uses the config type as threshol…
lrazovic Jul 21, 2023
daac339
Revert "chore(220): reorder imports"
lrazovic Jul 21, 2023
2b0a9ac
Revert "chore(214): unsafe math fix"
lrazovic Jul 21, 2023
fc4c5b9
Revert "chore(214): cargo fmt"
lrazovic Jul 21, 2023
528e6f0
Revert "fix(214): broken auction unbond test fixed"
lrazovic Jul 21, 2023
a8baa84
Revert "chore(214): fix warnings"
lrazovic Jul 21, 2023
f57bd6a
Revert "chore: fmt"
lrazovic Jul 21, 2023
fb2fb80
Revert "fix: building using workspace inheritance"
lrazovic Jul 21, 2023
4617300
Revert "feat: add parachain staking"
lrazovic Jul 21, 2023
384b203
Revert "feat: update to 0.9.42"
lrazovic Jul 21, 2023
15371ac
Revert "make integration tests compile"
lrazovic Jul 21, 2023
b6ee734
Revert "feat: the big cleanup"
lrazovic Jul 21, 2023
295c3da
Revert "wip"
lrazovic Jul 21, 2023
0f1d2e6
Revert "chore: remove unused file"
lrazovic Jul 21, 2023
3d4b136
Merge branch 'main' into feature/add-pallet-vesting
lrazovic Jul 21, 2023
499e2b3
feat: add vesting to funding
lrazovic Jul 21, 2023
326977a
chore: add missing headers
lrazovic Jul 21, 2023
78506e6
chore: cargo fmt
lrazovic Jul 21, 2023
0706439
rename total_{locked->held}_now & typos
Lederstrumpf Jul 22, 2023
e8916c9
feat: use Exact preceision
lrazovic Jul 23, 2023
61663e3
chore: rename for clarity
lrazovic Jul 23, 2023
9274cbd
feat: accrue, not add
lrazovic Jul 23, 2023
434e29e
feat: new extrinsics to "release" all the reasons
lrazovic Jul 23, 2023
e7f9b1f
feat: modify what the "vesting_balance" is
lrazovic Jul 23, 2023
87b89b8
test: add tests for the new vest_all extrinsics
lrazovic Jul 23, 2023
5db9099
chore: clippy warnings
lrazovic Jul 24, 2023
c68e994
feat: add pallet-linear-release to the runtime
lrazovic Jul 24, 2023
0817995
feat: add default genesis config to the node
lrazovic Jul 24, 2023
3d14489
chore: fmt
lrazovic Jul 24, 2023
c9f89c9
feat: move the ReleaseSchedule trait outside of the pallet
lrazovic Jul 24, 2023
ff1432f
doc: remove "\"
lrazovic Jul 24, 2023
a53332a
doc: add a TODO to a possible future improvement
lrazovic Jul 24, 2023
729f6e2
doc: README revamp
lrazovic Jul 24, 2023
435210a
docs: fix markdown
lrazovic Jul 24, 2023
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
19 changes: 19 additions & 0 deletions polimec-skeleton/Cargo.lock

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

5 changes: 4 additions & 1 deletion polimec-skeleton/pallets/funding/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ version = "0.1.0"
rust-version = "1.69.0"

[dependencies]
serde = { version = "*", optional = true }
parity-scale-codec = { version = "3.0.0", features = [
"derive",
], default-features = false }
Expand All @@ -28,14 +29,14 @@ sp-std = { git = "https://github.com/paritytech/substrate", default-features = f
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42" }
sp-arithmetic = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42" }
polimec-traits = { path = "../../traits", default-features = false }
pallet-linear-release = { path = "../linear-release", default-features = false }

[dev-dependencies]
sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42" }
sp-io = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42" }
pallet-balances = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42" }
pallet-insecure-randomness-collective-flip = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42" }
pallet-assets = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42" }

pallet-credentials = { path = "../credentials", default-features = false }

[features]
Expand All @@ -53,7 +54,9 @@ std = [
"pallet-balances/std",
"pallet-credentials/std",
"polimec-traits/std",
"pallet-linear-release/std",
"frame-benchmarking?/std",
"serde",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
Expand Down
2 changes: 1 addition & 1 deletion polimec-skeleton/pallets/funding/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ impl<T: Config> Pallet<T> {
let mut caller_existing_evaluations = Evaluations::<T>::get(project_id, evaluator.clone());
let plmc_usd_price = T::PriceProvider::get_price(PLMC_STATEMINT_ID).ok_or(Error::<T>::PLMCPriceNotAvailable)?;
let early_evaluation_reward_threshold_usd =
T::EvaluationSuccessThreshold::get() * project_details.fundraising_target;
T::EvaluationSuccessThreshold::get() * project_details.fundraising_target;
lrazovic marked this conversation as resolved.
Show resolved Hide resolved
let evaluation_round_info = &mut project_details.evaluation_round_info;

// * Validity Checks *
Expand Down
2 changes: 2 additions & 0 deletions polimec-skeleton/pallets/funding/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@ pub mod pallet {
/// Something that provides the members of Polimec
type HandleMembers: PolimecMembers<AccountIdOf<Self>>;

type Vesting: traits::ReleaseSchedule<AccountIdOf<Self>, BondTypeOf<Self>>;
JuaniRios marked this conversation as resolved.
Show resolved Hide resolved

/// The maximum length of data stored on-chain.
#[pallet::constant]
type StringLimit: Get<u32>;
Expand Down
24 changes: 22 additions & 2 deletions polimec-skeleton/pallets/funding/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use sp_arithmetic::Percent;
use sp_core::H256;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
traits::{BlakeTwo256, IdentityLookup, ConvertInto},
BuildStorage,
};
use system::EnsureSigned;
Expand Down Expand Up @@ -65,6 +65,7 @@ frame_support::construct_runtime!(
Balances: pallet_balances,
FundingModule: pallet_funding,
Credentials: pallet_credentials,
Vesting: pallet_linear_release,
LocalAssets: pallet_assets::<Instance1>::{Pallet, Call, Storage, Event<T>},
StatemintAssets: pallet_assets::<Instance2>::{Pallet, Call, Storage, Event<T>, Config<T>},
}
Expand Down Expand Up @@ -199,7 +200,6 @@ impl pallet_credentials::Config for TestRuntime {
type MembershipInitialized = ();
type MembershipChanged = ();
}

pub const HOURS: BlockNumber = 300u64;

// REMARK: In the production configuration we use DAYS instead of HOURS.
Expand All @@ -225,6 +225,25 @@ parameter_types! {
pub EarlyEvaluationThreshold: Percent = Percent::from_percent(10);
}

use frame_support::traits::WithdrawReasons;

parameter_types! {
pub const MinVestedTransfer: u64 = 256 * 2;
pub UnvestedFundsAllowedWithdrawReasons: WithdrawReasons =
WithdrawReasons::except(WithdrawReasons::TRANSFER | WithdrawReasons::RESERVE);
Copy link
Contributor

Choose a reason for hiding this comment

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

If I understood correctly, this means that funds that are locked (or "held") can still be used for paying fees, transaction costs, and tipping. Is this the behavior we want?

I can imagine someone with locked PLMC that wants it out could just tip the whole locked amount to another account of his to take the money out

}
impl pallet_linear_release::Config for TestRuntime {
type Balance = Balance;
type BlockNumberToBalance = ConvertInto;
type Currency = Balances;
type MinVestedTransfer = MinVestedTransfer;
type RuntimeEvent = RuntimeEvent;
type UnvestedFundsAllowedWithdrawReasons = UnvestedFundsAllowedWithdrawReasons;
type WeightInfo = ();
type Reason = LockType<u32>;
const MAX_VESTING_SCHEDULES: u32 = 3;
}

impl pallet_funding::Config for TestRuntime {
type RuntimeEvent = RuntimeEvent;
type ProjectIdentifier = Identifier;
Expand Down Expand Up @@ -258,6 +277,7 @@ impl pallet_funding::Config for TestRuntime {
type WeightInfo = ();
type FeeBrackets = FeeBrackets;
type EvaluationSuccessThreshold = EarlyEvaluationThreshold;
type Vesting = Vesting;
}

// Build genesis storage according to the mock runtime.
Expand Down
5 changes: 0 additions & 5 deletions polimec-skeleton/pallets/funding/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1966,7 +1966,6 @@ mod evaluation_round_success {

remainder_funding_project.end_funding();
test_env.advance_time(10).unwrap();

let post_unbond_amounts: UserToPLMCBalance = prev_reserved_plmc
.iter()
.map(|(evaluator, _amount)| (*evaluator, Zero::zero()))
Expand Down Expand Up @@ -2011,7 +2010,6 @@ mod evaluation_round_success {
let project_id = remainder_funding_project.get_project_id();
let prev_reserved_plmc =
test_env.get_reserved_plmc_balances_for(evaluators.clone(), LockType::Evaluation(project_id));

let prev_free_plmc = test_env.get_free_plmc_balances_for(evaluators.clone());

let finished_project = remainder_funding_project.end_funding();
Expand Down Expand Up @@ -2897,7 +2895,6 @@ mod auction_round_failure {
auctioning_project
.bid_for_users(vec![bid_in])
.expect("Bids should pass");

test_env
.advance_time(
<TestRuntime as Config>::EnglishAuctionDuration::get()
Expand Down Expand Up @@ -2930,9 +2927,7 @@ mod auction_round_failure {
],
project_id,
);

let _community_funding_project = auctioning_project.start_community_funding();

test_env.do_free_plmc_assertions(vec![(BIDDER_1, get_ed()), (BIDDER_2, plmc_fundings[1].1 + get_ed())]);

test_env.do_reserved_plmc_assertions(
Expand Down
2 changes: 2 additions & 0 deletions polimec-skeleton/pallets/funding/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ pub trait DoRemainingOperation {
fn do_one_operation<T: crate::Config>(&mut self, project_id: T::ProjectIdentifier)
-> Result<Weight, DispatchError>;
}

lrazovic marked this conversation as resolved.
Show resolved Hide resolved
pub use pallet_linear_release::traits::ReleaseSchedule;
1 change: 1 addition & 0 deletions polimec-skeleton/pallets/funding/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pub mod config_types {

/// Enum used to identify PLMC holds
#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen, Copy, Ord, PartialOrd)]
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
JuaniRios marked this conversation as resolved.
Show resolved Hide resolved
pub enum LockType<ProjectId> {
Evaluation(ProjectId),
Participation(ProjectId),
Expand Down
43 changes: 43 additions & 0 deletions polimec-skeleton/pallets/linear-release/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[package]
name = "pallet-linear-release"
version = "4.0.0-dev"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2021"
license = "MIT-0"
homepage = "https://substrate.io"
repository = "https://github.com/paritytech/substrate/"
description = "FRAME example pallet"
readme = "README.md"

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
serde = { version = "1.0.136", optional = true }
codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false }
log = { version = "0.4.17", default-features = false }
scale-info = { version = "2.5.0", default-features = false, features = ["derive"] }
frame-support = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42" }
frame-system = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42" }
sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42" }
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42" }

[dev-dependencies]
sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42" }
sp-io = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42" }
pallet-balances = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42" }

[features]
default = ["std"]
std = [
"codec/std",
"frame-support/std",
"frame-system/std",
"log/std",
"scale-info/std",
"sp-runtime/std",
"sp-std/std",
"pallet-balances/std",
"serde"
]
try-runtime = ["frame-support/try-runtime"]
11 changes: 11 additions & 0 deletions polimec-skeleton/pallets/linear-release/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- markdown-link-check-disable -->
# Dev Mode Example Pallet

A simple example of a FRAME pallet demonstrating
the ease of requirements for a pallet in dev mode.

Run `cargo doc --package pallet-dev-mode --open` to view this pallet's documentation.
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need much documentation right now for this pallet, but let's remove the deprecated info from the template at least

Copy link
Member Author

Choose a reason for hiding this comment

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

Done in 729f6e2.


**Dev mode is not meant to be used in production.**

License: MIT-0
Loading