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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: edit product grace period #409

Merged
merged 10 commits into from
Oct 13, 2022

Conversation

0xdewy
Copy link
Contributor

@0xdewy 0xdewy commented Oct 6, 2022

Context

Resolves #287

Changes proposed in this pull request

This PR adds the ability to edit gracePeriodInDays. To do this gracePeriodInDays was added to the CoverSegments struct. Deallocation and claims should now use the grace period from the cover segment. Allocations should use the product level grace period.

Test plan

Checklist

  • Rebased the base branch
  • Attached corresponding Github issue
  • Prefixed the name with the type of change (i.e. feat, chore, test)
  • Performed a self-review of my own code
  • Followed the style guidelines of this project
  • Made corresponding changes to the documentation
  • Didn't generate new warnings
  • Didn't generate failures on existing tests
  • Added tests that prove my fix is effective or that my feature works

Review

When reviewing a PR, please indicate intention in comments using the following emojis:

  • 馃嵃 = Nice to have but not essential.
  • 馃挕 = Suggestion or a comment based on personal opinion
  • 馃敤 = I believe this should be changed.
  • 馃 = I don鈥檛 understand something, do you mind giving me more context?
  • 馃殌 = Feedback

@0xdewy 0xdewy linked an issue Oct 6, 2022 that may be closed by this pull request
@0xdewy 0xdewy marked this pull request as ready for review October 6, 2022 12:17
@@ -51,6 +51,7 @@ struct CoverSegment {
uint96 amount;
uint32 start;
uint32 period; // seconds
uint16 gracePeriodInDays;
Copy link
Contributor

Choose a reason for hiding this comment

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

Total current struct size:

96 + 32 + 32 + 16 + 16 + 8 + 24
224

Looks fine.

@@ -35,7 +35,7 @@ describe('getClaimsToDisplay', function () {
coverOwner.address,
0, // productId
ASSET.ETH,
[[coverAmount, timestamp + 1, coverPeriod, 0, false, 0]],
[[coverAmount, timestamp + 1, coverPeriod, 7, 0, false, 0]],
Copy link
Contributor

Choose a reason for hiding this comment

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

consider using a constant test variable here for the test since it's the same throughout

@@ -24,7 +24,7 @@ describe('redeemClaimPayout', function () {
coverOwner.address,
0, // productId
ASSET.ETH,
[[coverAmount, timestamp + 1, coverPeriod, 0, false, 0]],
[[coverAmount, timestamp + 1, coverPeriod, 7, 0, false, 0]],
Copy link
Contributor

Choose a reason for hiding this comment

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

same here use a named constant for the value 7 since it's the same in every test case

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea these are a bit tedious in the case that CoverSegment structure changes. I thought about storing this struct as a fixture somewhere and have each tests just modify which field it is adjusting?

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah agree with fixture

@@ -18,7 +18,7 @@ describe('redeemPayout', function () {
coverOwner.address,
2, // productId
ASSET.ETH,
[[parseEther('10000'), timestamp + 1, segmentPeriod, 0, false, 0]],
[[parseEther('10000'), timestamp + 1, segmentPeriod, 7, 0, false, 0]],
Copy link
Contributor

Choose a reason for hiding this comment

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

use a constant

@@ -680,7 +681,7 @@ contract Cover is ICover, MasterAwareV2, IStakingPoolBeacon, ReentrancyGuard {
Product memory product,
uint32 _coverAssetsFallback,
uint productTypesCount
) internal {
) internal pure {
Copy link
Contributor

Choose a reason for hiding this comment

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

馃憤

@danoctavian
Copy link
Contributor

Add an assertion here for gracePeriod

async function assertCoverFields(

Copy link
Contributor

@danoctavian danoctavian left a comment

Choose a reason for hiding this comment

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

The changes mentioned above.

Otherwise looks good

@@ -400,7 +401,7 @@ contract Cover is ICover, MasterAwareV2, IStakingPoolBeacon, ReentrancyGuard {
cover.productId,
allocation.coverAmountInNXM,
lastCoverSegment.period,
_productTypes[product.productType].gracePeriodInDays * 1 days,
uint(lastCoverSegment.gracePeriodInDays) * 1 days,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had to cast gracePeriodInDays as a uint here as it was overflowing.


describe('performStakeBurn', function () {
describe.only('performStakeBurn', function () {
Copy link
Contributor

Choose a reason for hiding this comment

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

forgot an .only here

@shark0der shark0der changed the title Feature/ editproduct grace period Feature: edit product grace period Oct 10, 2022
@shark0der shark0der force-pushed the feature/edit-product-grace-period branch from 8fee40e to 891708c Compare October 10, 2022 11:00
@shark0der
Copy link
Collaborator

Missed a refactor from productType.gracePeriodInDays to segment.gracePeriodInDays in CoverViewer.sol:93

Copy link
Contributor

@danoctavian danoctavian left a comment

Choose a reason for hiding this comment

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

LGTM

@shark0der shark0der force-pushed the feature/edit-product-grace-period branch from cf4bf9a to 924e31f Compare October 13, 2022 09:20
@shark0der shark0der merged commit f275722 into nexus-v2 Oct 13, 2022
@shark0der shark0der deleted the feature/edit-product-grace-period branch October 13, 2022 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cover / Staking: Allow editing grace periods
4 participants