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

M-01 token conversion #621

Merged
merged 7 commits into from
Oct 22, 2024
Merged

M-01 token conversion #621

merged 7 commits into from
Oct 22, 2024

Conversation

cam-schultz
Copy link
Contributor

Why this should be merged

Parameterizes weight to value conversion factor.

How this works

  • Adds an initialization parameter to PoSValidatorManager to specify the weight to value conversion factor. This was previously hardcoded to 1e12.
  • Disallows values that round down to 0 weight.

How this was tested

CI, new unit tests

How is this documented

Documents gotchas when selecting the conversion factor

Copy link
Collaborator

@michaelkaplan13 michaelkaplan13 left a comment

Choose a reason for hiding this comment

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

Makes sense to me, just one suggestion

@@ -58,6 +58,11 @@ Proof-of-Authority Validator management is provided via `PoAValidatorManager`, w

Proof-of-Stake Validator management is provided by the abstract contract `PoSValidatorManager`, which has two concrete implementations: `NativeTokenStakingManager` and `ERC20TokenStakingManager`. In addition to basic Validator management provided in `ValidatorManager`, `PoSValidatorManager` supports uptime-based Validation rewards, as well as Delegation to a Validator. This [state transition diagram](./StateTransition.md) illustrates the relationship between Validators and Delegators.

> [!NOTE]
> The `weightToValueFactor` fields of the `PoSValidatorManagerSettings` passed to `PoSValidatorManager`'s `initialize` function sets the factor used to convert between the value transferred to the contract as stake, and the weight that the Validator is registered with on the P-Chain. This involves integer division, which may result in loss of precision. When selecting `weightToValueFactor`, it's important to make the following considerations:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
> The `weightToValueFactor` fields of the `PoSValidatorManagerSettings` passed to `PoSValidatorManager`'s `initialize` function sets the factor used to convert between the value transferred to the contract as stake, and the weight that the Validator is registered with on the P-Chain. This involves integer division, which may result in loss of precision. When selecting `weightToValueFactor`, it's important to make the following considerations:
> The `weightToValueFactor` fields of the `PoSValidatorManagerSettings` passed to `PoSValidatorManager`'s `initialize` function sets the factor used to convert between the weight that the Validator is registered with on the P-Chain, and the value transferred to the contract as stake. This involves integer division, which may result in loss of precision. When selecting `weightToValueFactor`, it's important to make the following considerations:

We may want to note here that weight on the P-Chain is represented as a uint64, so the weightToValueFactor should be set with that in mind to ensure that the weight value will not overflow. We may even want to add a require statement when registering a validator that the weight is <= UINT64_MAX.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call. Added documentation, a check against UINT64_MAX, and a test.

cam-schultz and others added 2 commits October 22, 2024 09:32
Co-authored-by: Michael Kaplan <55204436+michaelkaplan13@users.noreply.github.com>
Signed-off-by: cam-schultz <78878559+cam-schultz@users.noreply.github.com>
Copy link
Contributor

@bernard-avalabs bernard-avalabs left a comment

Choose a reason for hiding this comment

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

LGTM. Adding an example in the README about possible issues with conversion might help clarify any possible misunderstandings.

@@ -58,6 +58,12 @@ Proof-of-Authority Validator management is provided via `PoAValidatorManager`, w

Proof-of-Stake Validator management is provided by the abstract contract `PoSValidatorManager`, which has two concrete implementations: `NativeTokenStakingManager` and `ERC20TokenStakingManager`. In addition to basic Validator management provided in `ValidatorManager`, `PoSValidatorManager` supports uptime-based Validation rewards, as well as Delegation to a Validator. This [state transition diagram](./StateTransition.md) illustrates the relationship between Validators and Delegators.

> [!NOTE]
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: It may be helpful to include an example that illustrates the first 2 considerations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added examples

@cam-schultz cam-schultz merged commit ac0c893 into validator-manager Oct 22, 2024
14 checks passed
@cam-schultz cam-schultz deleted the M-01-token-conversion branch October 22, 2024 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants