Skip to content

Conversation

0xdewy
Copy link
Contributor

@0xdewy 0xdewy commented Oct 3, 2022

Context

closes #334
closes #329
closes #328

Changes proposed in this pull request

334 - Add ability for manager to add/remove/edit products in the staking pool by creating a setProducts(ProductParams[] products) function that lets the manager add/remove or edit existing products. The product must exist in the Cover contract to be added.
329 - Enforce max 20x leverage. The staking pool has a global variable targetWeight that must be below 20x.
328 - setProducts() allows managers to adjust any product in one tx

This PR adds a setProducts() function that allows managers to add, edit or remove products from their staking pool. The staking pool can offer full capacity for up to 20 products. This is managed by keeping track of a totalTargetWeight and a totalEffectiveWeight. Allocation for a product cannot exceed that products target weight. When setting targetWeight, the totalTargetWeight and the totalEffectiveWeight cannot exceed 20x. This means if the stakingpool is at full allocation, the manager will not be able to add another product even if they reduce the targetWeight of other products.

totalEffectiveWeight is the sum of max(product.targetWeight, product.allocatedWeight).

totalTargetWeight is the max amount the contract will allocate....can never be above 2000 (20.00)

_setInitialProducts()

  • Sets all initial parameters and only checks totalTargetWeight as the pool should have no allocations yet

setProducts()

  • Cannot add deprecated or non existing products
  • Must evaluate current allocations if manager wants to change target weight of any products
  • Can edit prices and avoid evaluating current allocations
  • For targetWeight to increase on a product, there must be available capacity, even if totalTargetWeight is still below the max.

cover.getCapacityRatios()

  • Added this view function in cover for when current allocations need to be evaluated in setProducts().

Note: There was some fixes made to activeStake/totalCapacities as totalCapacities was being stored/retrieved with 12 extra decimal places relative to allocatedCapacities

Test plan

Added unit tests at: test/unit/StakingPool/setProducts.js

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’t understand something, do you mind giving me more context?
  • 🚀 = Feedback

@0xdewy 0xdewy force-pushed the feature/staking-pool-management branch from e5c7b87 to 2f071b4 Compare October 3, 2022 14:48
@0xdewy 0xdewy marked this pull request as ready for review October 4, 2022 08:54
@roxdanila roxdanila linked an issue Oct 4, 2022 that may be closed by this pull request
@0xdewy 0xdewy force-pushed the feature/staking-pool-management branch from 08584bd to aaa56c2 Compare October 5, 2022 07:42
@danoctavian
Copy link
Contributor

A meta discussion about solving 3 issues in 1 PR

I've been doing 1 issue per PR, should we be more strict with that or just leave it to reasonable judgement case by case

@roxdanila
Copy link
Contributor

A meta discussion about solving 3 issues in 1 PR

I've been doing 1 issue per PR, should we be more strict with that or just leave it to reasonable judgement case by case

I ended up merging the 3 issues into one, as they were too interdependent. So overall it does follow the 1 issue - 1 pr structure.

@0xdewy 0xdewy force-pushed the feature/staking-pool-management branch from aaa56c2 to db913c3 Compare October 10, 2022 08:38
@0xdewy 0xdewy requested a review from danoctavian October 12, 2022 07:49
@shark0der shark0der force-pushed the feature/staking-pool-management branch from 1fa212f to 9b87833 Compare October 13, 2022 13:27
@0xdewy 0xdewy marked this pull request as draft October 13, 2022 15:54
@0xdewy 0xdewy force-pushed the feature/staking-pool-management branch 5 times, most recently from 9ac893b to 4e9b4ea Compare October 21, 2022 14:38
@0xdewy 0xdewy force-pushed the feature/staking-pool-management branch from 2be0da8 to 9e4b1e6 Compare October 24, 2022 11:53
@0xdewy 0xdewy requested a review from shark0der October 24, 2022 12:03
@0xdewy 0xdewy marked this pull request as ready for review October 24, 2022 12:33
@0xdewy 0xdewy force-pushed the feature/staking-pool-management branch 2 times, most recently from 9e4b1e6 to b0da140 Compare October 24, 2022 13:39
@roxdanila roxdanila force-pushed the feature/staking-pool-management branch 2 times, most recently from 31da612 to c54acd1 Compare October 27, 2022 07:04
@0xdewy 0xdewy requested a review from shark0der October 27, 2022 07:09
@roxdanila roxdanila force-pushed the feature/staking-pool-management branch from 4b07e98 to d773e62 Compare October 27, 2022 10:06
@0xdewy 0xdewy force-pushed the feature/staking-pool-management branch from d773e62 to 3fade5f Compare October 27, 2022 11:34
@0xdewy 0xdewy requested a review from shark0der October 27, 2022 14:33
Copy link
Contributor

@shark0der shark0der left a comment

Choose a reason for hiding this comment

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

🚀

@0xdewy 0xdewy force-pushed the feature/staking-pool-management branch from fa4487d to 57bc95c Compare October 27, 2022 16:46
@0xdewy 0xdewy force-pushed the feature/staking-pool-management branch from 57bc95c to c33d757 Compare October 28, 2022 06:55
@0xdewy 0xdewy requested a review from shark0der October 28, 2022 06:56
@0xdewy 0xdewy merged commit eb93329 into nexus-v2 Oct 28, 2022
@0xdewy 0xdewy deleted the feature/staking-pool-management branch October 28, 2022 07:37
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.

Staking: Implement pool management operations
4 participants