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

Feature/plmc 242 implement correct duration of vesting #70

Merged
merged 7 commits into from
Aug 23, 2023

Conversation

JuaniRios
Copy link
Contributor

No description provided.

@JuaniRios JuaniRios self-assigned this Aug 16, 2023
@linear
Copy link

linear bot commented Aug 16, 2023

@lrazovic lrazovic changed the base branch from main to feature/plmc-244-use-rust-stable-instead-of-nightly August 16, 2023 13:55
@JuaniRios JuaniRios force-pushed the feature/plmc-242-implement-correct-duration-of-vesting branch from f8b4243 to 5a1a59b Compare August 16, 2023 14:03
@lrazovic lrazovic changed the base branch from feature/plmc-244-use-rust-stable-instead-of-nightly to main August 17, 2023 07:19
pallets/funding/src/types.rs Outdated Show resolved Hide resolved
pallets/funding/src/types.rs Outdated Show resolved Hide resolved
pallets/funding/src/types.rs Outdated Show resolved Hide resolved
Comment on lines 109 to 124
fn convert(a: FixedU128) -> u64 {
if a == Zero::zero() {
return 1u64
} else {
let one_week_in_blocks = DAYS * 7;
a.saturating_mul_int(one_week_in_blocks as u64)
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Not a big fan of having DAYS in the pallet, but I can't think of any alternative/better solutions at the moment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Our chain would produce blocks and the rate specified in our runtime. If we want to speed up or slow down block production I think we will necessarily need a runtime upgrade, therefore the DAYS will be automatically updated when using the latest version of that library.

But let's check with @joepetrowski

Copy link
Collaborator

Choose a reason for hiding this comment

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

But you are pulling DAYS from Cumulus's parachains-common. Nothing in Substrate/Polkadot depend on anything in Cumulus. So it's weird to have a pallet that depends on Cumulus. I think it makes more sense to have:

pub trait Config: frame_system::Config {
	/// The reference duration against which vesting schedules are calculated.
	#[pallet::constant]
	type VestingReference: Get<Self::BlockNumber>;
}

Then you can remove this WeeksToBlocks thing and do:

fn calculate_vesting_duration<T: Config>(&self) -> T::BlockNumber {
	// gradient "m" of the linear curve function y = m*x + b
	const GRADIENT: FixedU128 = FixedU128::from_rational(2167u128, 1000u128);
	// negative constant (because we cannot have negative values, so we take the negative and do
	// "-b" instead of "+b") "b" of the linear curve function y = m*x + b
	const NEG_CONSTANT: FixedU128 = FixedU128::from_rational(2167u128, 1000u128);

	let multiplier_as_fixed = FixedU128::saturating_from_integer(self.0);
	let duration = GRADIENT.saturating_mul(multiplier_as_fixed).saturating_sub(NEG_CONSTANT);
	duration.saturating_mul(T::VestingReference::get()).max(1)
}

Copy link
Contributor Author

@JuaniRios JuaniRios Aug 21, 2023

Choose a reason for hiding this comment

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

  • calculate_vesting_duration was already using a config type WeeksToBlocks, so how would adding VestingReference improve it?
  • We only use DAYS inside types.rs, which provides default values to use for the config types, so I don't see a problem with this.
  • I changed it now to DaysToBlocks to make it more usable.
  • I believe DaysToBlocks is a more useful name than VestingReference

If you agree @lrazovic @joepetrowski I think this PR is ready to merge

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't agree. You are introducing the concept of days/weeks to this type because weeks is x in y = m*x + b.
https://github.com/Polimec/polimec-node/pull/70/files#diff-d5a7ca3423acfb2236018006a4ac93760a9e9893a8c864e55bef34403cafcb5dR68

What I mean by reference is that it's the independent variable against which vesting schedules...reference.

IMO the pallet (no matter how you split it into different files) should only deal with block numbers. Specific implementations related to days/weeks/etc. should be in the runtime. So perhaps just leave this as a trait and then implement it alongside the runtime.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  • Weeks is y. x is the multiplier stored inside self.0
  • This type defined in the pallet is used only in the runtime. In the pallet we use the trait VestingDurationCalculation. We also have several other default implementations of config types inside types.rs. Would you suggest then to move them all inside the runtime file?
    That would make it harder to use them across other runtimes like the mock
  • We cannot abstract away the concept of weeks in the pallet because that is what is calculated based on the multiplier. But the pallet does not need to know how many blocks a week is, since it is being converted with the config type.
  • I like the .max(1) instead of the if statement

@JuaniRios JuaniRios force-pushed the feature/plmc-242-implement-correct-duration-of-vesting branch from 3f8d287 to 17e65ba Compare August 21, 2023 09:12
@lrazovic lrazovic self-requested a review August 23, 2023 13:16
@lrazovic lrazovic merged commit 6894904 into main Aug 23, 2023
@JuaniRios JuaniRios deleted the feature/plmc-242-implement-correct-duration-of-vesting branch August 23, 2023 13:58
lrazovic added a commit that referenced this pull request Aug 28, 2023
Squashed commit of the following:

commit a71eff7
Author: Juan Ignacio Rios <juani.rios.99@gmail.com>
Date:   Mon Aug 14 16:20:48 2023 +0200

    feat(243): Remove T::StorageItemId and replace it with hardcoded u32

commit 368abd9
Author: Juan Ignacio Rios <juani.rios.99@gmail.com>
Date:   Mon Aug 14 16:20:48 2023 +0200

    feat(249): Remove Option from Multipliers

    feat(249): Option no longer required for multipliers

    fix(243): rebase error

    chore(243): add import

    feat(245): manual and automatic release of PLMC and funding assets implemented and tested

    feat(247): manual and automatic release of PLMC and funding assets implemented and tested

    feat(247): manual release implemented and tested

    feat(247): automatic release implemented and tested

    feat(247): automatic release implemented and tested

    feat(248): manual release implemented and tested

    feat(248): automatic release implemented and tested

    wip

    feat(242): small optimization

    chore(242): fmt

    feat(242): change week to day conversion on config type

    feat(242): small changes from Leonardo's feedback

    Update pallets/funding/src/types.rs

    Co-authored-by: Leonardo Razovic <4128940+lrazovic@users.noreply.github.com>

    feat(244): linear increase of duration based on vesting

    wip

commit e576cdc
Author: Juan Ignacio Rios <54085674+JuaniRios@users.noreply.github.com>
Date:   Fri Aug 25 10:39:03 2023 +0100

    fix(243): rebase error (#72)

    chore(243): add import

    feat(245): manual and automatic release of PLMC and funding assets implemented and tested

    feat(247): manual and automatic release of PLMC and funding assets implemented and tested

    feat(247): manual release implemented and tested

    feat(247): automatic release implemented and tested

    feat(247): automatic release implemented and tested

    feat(248): manual release implemented and tested

    feat(248): automatic release implemented and tested

commit bdc9075
Author: Leonardo Razovic <4128940+lrazovic@users.noreply.github.com>
Date:   Thu Aug 24 16:47:25 2023 +0200

    Update check.yml (#78)

    * Update check.yml

    * Update check.yml

commit 6894904
Author: Juan Ignacio Rios <54085674+JuaniRios@users.noreply.github.com>
Date:   Wed Aug 23 14:17:19 2023 +0100

    Feature/plmc 242 implement correct duration of vesting (#70)

    * wip

    * feat(244): linear increase of duration based on vesting

    * Update pallets/funding/src/types.rs

    Co-authored-by: Leonardo Razovic <4128940+lrazovic@users.noreply.github.com>

    * feat(242): small changes from Leonardo's feedback

    * feat(242): change week to day conversion on config type

    * chore(242): fmt

    * feat(242): small optimization

    ---------

    Co-authored-by: Leonardo Razovic <4128940+lrazovic@users.noreply.github.com>

commit 8057e2e
Author: Leonardo Razovic <4128940+lrazovic@users.noreply.github.com>
Date:   Wed Aug 23 11:38:43 2023 +0200

    Update check.yml (#76)

commit b4579cc
Author: Leonardo Razovic <4128940+lrazovic@users.noreply.github.com>
Date:   Wed Aug 23 10:01:42 2023 +0200

    feat: update the CI to use paritytech/ci-linux:production (#73)

    * feat: update the CI to use paritytech/ci-linux:production

    * ci: execute fmt as a fail fast job

    * fmt: format to test the CI

    * feat: remove the check job
lrazovic added a commit that referenced this pull request Aug 28, 2023
wip

wip: align TestBid creation

wip: switch to stable compiler

test: check the remainder

Update rust-toolchain.toml

Co-authored-by: Leonardo Razovic <4128940+lrazovic@users.noreply.github.com>

chore(244): move dep to workspace

wip: check the ct amount

feat: restore assert_matches macro

test: add the remainder round from excel

test: add more dbg outputs

refactor: split the fees calculation login in several fn

test: cleanup debug artefacts

feat: calculate the CT amount in CT directly

fix: use the Y from the KH

feat: just return the total_fee_weight

doc: specify the denomination of the pot

test: restore the assert_matches macro

git merge --squash -Xours origin/main

Squashed commit of the following:

commit a71eff7
Author: Juan Ignacio Rios <juani.rios.99@gmail.com>
Date:   Mon Aug 14 16:20:48 2023 +0200

    feat(243): Remove T::StorageItemId and replace it with hardcoded u32

commit 368abd9
Author: Juan Ignacio Rios <juani.rios.99@gmail.com>
Date:   Mon Aug 14 16:20:48 2023 +0200

    feat(249): Remove Option from Multipliers

    feat(249): Option no longer required for multipliers

    fix(243): rebase error

    chore(243): add import

    feat(245): manual and automatic release of PLMC and funding assets implemented and tested

    feat(247): manual and automatic release of PLMC and funding assets implemented and tested

    feat(247): manual release implemented and tested

    feat(247): automatic release implemented and tested

    feat(247): automatic release implemented and tested

    feat(248): manual release implemented and tested

    feat(248): automatic release implemented and tested

    wip

    feat(242): small optimization

    chore(242): fmt

    feat(242): change week to day conversion on config type

    feat(242): small changes from Leonardo's feedback

    Update pallets/funding/src/types.rs

    Co-authored-by: Leonardo Razovic <4128940+lrazovic@users.noreply.github.com>

    feat(244): linear increase of duration based on vesting

    wip

commit e576cdc
Author: Juan Ignacio Rios <54085674+JuaniRios@users.noreply.github.com>
Date:   Fri Aug 25 10:39:03 2023 +0100

    fix(243): rebase error (#72)

    chore(243): add import

    feat(245): manual and automatic release of PLMC and funding assets implemented and tested

    feat(247): manual and automatic release of PLMC and funding assets implemented and tested

    feat(247): manual release implemented and tested

    feat(247): automatic release implemented and tested

    feat(247): automatic release implemented and tested

    feat(248): manual release implemented and tested

    feat(248): automatic release implemented and tested

commit bdc9075
Author: Leonardo Razovic <4128940+lrazovic@users.noreply.github.com>
Date:   Thu Aug 24 16:47:25 2023 +0200

    Update check.yml (#78)

    * Update check.yml

    * Update check.yml

commit 6894904
Author: Juan Ignacio Rios <54085674+JuaniRios@users.noreply.github.com>
Date:   Wed Aug 23 14:17:19 2023 +0100

    Feature/plmc 242 implement correct duration of vesting (#70)

    * wip

    * feat(244): linear increase of duration based on vesting

    * Update pallets/funding/src/types.rs

    Co-authored-by: Leonardo Razovic <4128940+lrazovic@users.noreply.github.com>

    * feat(242): small changes from Leonardo's feedback

    * feat(242): change week to day conversion on config type

    * chore(242): fmt

    * feat(242): small optimization

    ---------

    Co-authored-by: Leonardo Razovic <4128940+lrazovic@users.noreply.github.com>

commit 8057e2e
Author: Leonardo Razovic <4128940+lrazovic@users.noreply.github.com>
Date:   Wed Aug 23 11:38:43 2023 +0200

    Update check.yml (#76)

commit b4579cc
Author: Leonardo Razovic <4128940+lrazovic@users.noreply.github.com>
Date:   Wed Aug 23 10:01:42 2023 +0200

    feat: update the CI to use paritytech/ci-linux:production (#73)

    * feat: update the CI to use paritytech/ci-linux:production

    * ci: execute fmt as a fail fast job

    * fmt: format to test the CI

    * feat: remove the check job
JuaniRios added a commit that referenced this pull request Aug 30, 2023
* feat: for testing purposes let's assume 1 USDT = 1USD

* wip

* wip: align TestBid creation

* wip: switch to stable compiler

* test: check the remainder

* feat(244): move to rust stable

* Update rust-toolchain.toml

Co-authored-by: Leonardo Razovic <4128940+lrazovic@users.noreply.github.com>

* chore(244): move dep to workspace

* fix: remove unstable feature

* wip: check the ct amount

* feat: restore assert_matches macro

* test: add the remainder round from excel

* test: add more dbg outputs

* refactor: split the fees calculation login in several fn

* test: cleanup debug artefacts

* feat: calculate the CT amount in CT directly

* fix: use the Y from the KH

* feat: just return the total_fee_weight

* doc: specify the denomination of the pot

* test: restore the assert_matches macro

* git merge --squash -Xours origin/main

Squashed commit of the following:

commit a71eff7
Author: Juan Ignacio Rios <juani.rios.99@gmail.com>
Date:   Mon Aug 14 16:20:48 2023 +0200

    feat(243): Remove T::StorageItemId and replace it with hardcoded u32

commit 368abd9
Author: Juan Ignacio Rios <juani.rios.99@gmail.com>
Date:   Mon Aug 14 16:20:48 2023 +0200

    feat(249): Remove Option from Multipliers

    feat(249): Option no longer required for multipliers

    fix(243): rebase error

    chore(243): add import

    feat(245): manual and automatic release of PLMC and funding assets implemented and tested

    feat(247): manual and automatic release of PLMC and funding assets implemented and tested

    feat(247): manual release implemented and tested

    feat(247): automatic release implemented and tested

    feat(247): automatic release implemented and tested

    feat(248): manual release implemented and tested

    feat(248): automatic release implemented and tested

    wip

    feat(242): small optimization

    chore(242): fmt

    feat(242): change week to day conversion on config type

    feat(242): small changes from Leonardo's feedback

    Update pallets/funding/src/types.rs

    Co-authored-by: Leonardo Razovic <4128940+lrazovic@users.noreply.github.com>

    feat(244): linear increase of duration based on vesting

    wip

commit e576cdc
Author: Juan Ignacio Rios <54085674+JuaniRios@users.noreply.github.com>
Date:   Fri Aug 25 10:39:03 2023 +0100

    fix(243): rebase error (#72)

    chore(243): add import

    feat(245): manual and automatic release of PLMC and funding assets implemented and tested

    feat(247): manual and automatic release of PLMC and funding assets implemented and tested

    feat(247): manual release implemented and tested

    feat(247): automatic release implemented and tested

    feat(247): automatic release implemented and tested

    feat(248): manual release implemented and tested

    feat(248): automatic release implemented and tested

commit bdc9075
Author: Leonardo Razovic <4128940+lrazovic@users.noreply.github.com>
Date:   Thu Aug 24 16:47:25 2023 +0200

    Update check.yml (#78)

    * Update check.yml

    * Update check.yml

commit 6894904
Author: Juan Ignacio Rios <54085674+JuaniRios@users.noreply.github.com>
Date:   Wed Aug 23 14:17:19 2023 +0100

    Feature/plmc 242 implement correct duration of vesting (#70)

    * wip

    * feat(244): linear increase of duration based on vesting

    * Update pallets/funding/src/types.rs

    Co-authored-by: Leonardo Razovic <4128940+lrazovic@users.noreply.github.com>

    * feat(242): small changes from Leonardo's feedback

    * feat(242): change week to day conversion on config type

    * chore(242): fmt

    * feat(242): small optimization

    ---------

    Co-authored-by: Leonardo Razovic <4128940+lrazovic@users.noreply.github.com>

commit 8057e2e
Author: Leonardo Razovic <4128940+lrazovic@users.noreply.github.com>
Date:   Wed Aug 23 11:38:43 2023 +0200

    Update check.yml (#76)

commit b4579cc
Author: Leonardo Razovic <4128940+lrazovic@users.noreply.github.com>
Date:   Wed Aug 23 10:01:42 2023 +0200

    feat: update the CI to use paritytech/ci-linux:production (#73)

    * feat: update the CI to use paritytech/ci-linux:production

    * ci: execute fmt as a fail fast job

    * fmt: format to test the CI

    * feat: remove the check job

* feat: for testing purposes let's assume 1 USDT = 1USD

wip

wip: align TestBid creation

wip: switch to stable compiler

test: check the remainder

Update rust-toolchain.toml

Co-authored-by: Leonardo Razovic <4128940+lrazovic@users.noreply.github.com>

chore(244): move dep to workspace

wip: check the ct amount

feat: restore assert_matches macro

test: add the remainder round from excel

test: add more dbg outputs

refactor: split the fees calculation login in several fn

test: cleanup debug artefacts

feat: calculate the CT amount in CT directly

fix: use the Y from the KH

feat: just return the total_fee_weight

doc: specify the denomination of the pot

test: restore the assert_matches macro

git merge --squash -Xours origin/main

Squashed commit of the following:

commit a71eff7
Author: Juan Ignacio Rios <juani.rios.99@gmail.com>
Date:   Mon Aug 14 16:20:48 2023 +0200

    feat(243): Remove T::StorageItemId and replace it with hardcoded u32

commit 368abd9
Author: Juan Ignacio Rios <juani.rios.99@gmail.com>
Date:   Mon Aug 14 16:20:48 2023 +0200

    feat(249): Remove Option from Multipliers

    feat(249): Option no longer required for multipliers

    fix(243): rebase error

    chore(243): add import

    feat(245): manual and automatic release of PLMC and funding assets implemented and tested

    feat(247): manual and automatic release of PLMC and funding assets implemented and tested

    feat(247): manual release implemented and tested

    feat(247): automatic release implemented and tested

    feat(247): automatic release implemented and tested

    feat(248): manual release implemented and tested

    feat(248): automatic release implemented and tested

    wip

    feat(242): small optimization

    chore(242): fmt

    feat(242): change week to day conversion on config type

    feat(242): small changes from Leonardo's feedback

    Update pallets/funding/src/types.rs

    Co-authored-by: Leonardo Razovic <4128940+lrazovic@users.noreply.github.com>

    feat(244): linear increase of duration based on vesting

    wip

commit e576cdc
Author: Juan Ignacio Rios <54085674+JuaniRios@users.noreply.github.com>
Date:   Fri Aug 25 10:39:03 2023 +0100

    fix(243): rebase error (#72)

    chore(243): add import

    feat(245): manual and automatic release of PLMC and funding assets implemented and tested

    feat(247): manual and automatic release of PLMC and funding assets implemented and tested

    feat(247): manual release implemented and tested

    feat(247): automatic release implemented and tested

    feat(247): automatic release implemented and tested

    feat(248): manual release implemented and tested

    feat(248): automatic release implemented and tested

commit bdc9075
Author: Leonardo Razovic <4128940+lrazovic@users.noreply.github.com>
Date:   Thu Aug 24 16:47:25 2023 +0200

    Update check.yml (#78)

    * Update check.yml

    * Update check.yml

commit 6894904
Author: Juan Ignacio Rios <54085674+JuaniRios@users.noreply.github.com>
Date:   Wed Aug 23 14:17:19 2023 +0100

    Feature/plmc 242 implement correct duration of vesting (#70)

    * wip

    * feat(244): linear increase of duration based on vesting

    * Update pallets/funding/src/types.rs

    Co-authored-by: Leonardo Razovic <4128940+lrazovic@users.noreply.github.com>

    * feat(242): small changes from Leonardo's feedback

    * feat(242): change week to day conversion on config type

    * chore(242): fmt

    * feat(242): small optimization

    ---------

    Co-authored-by: Leonardo Razovic <4128940+lrazovic@users.noreply.github.com>

commit 8057e2e
Author: Leonardo Razovic <4128940+lrazovic@users.noreply.github.com>
Date:   Wed Aug 23 11:38:43 2023 +0200

    Update check.yml (#76)

commit b4579cc
Author: Leonardo Razovic <4128940+lrazovic@users.noreply.github.com>
Date:   Wed Aug 23 10:01:42 2023 +0200

    feat: update the CI to use paritytech/ci-linux:production (#73)

    * feat: update the CI to use paritytech/ci-linux:production

    * ci: execute fmt as a fail fast job

    * fmt: format to test the CI

    * feat: remove the check job

* feat(239): add remark to a skipped user

feat(239): add comments to `generate_evaluator_rewards_info` function

fmt

---------

Co-authored-by: Juan Ignacio Rios <juani.rios.99@gmail.com>
Co-authored-by: Juan Ignacio Rios <54085674+JuaniRios@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants