Fix/staking env bigint parsing #1533
Open
+18
−14
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Tasks for protocol staking currently convert numeric environment variables with
parseInt(...)and then wrap them inBigInt(...). SinceparseIntreturns aJavaScript Number, this may lose precision for large 256-bit values (e.g. token
amounts in 18 decimals).
This PR updates the staking tasks to convert env vars directly to
BigIntusing the string returned by
getRequiredEnvVar.Changes
protocol-contracts/staking/tasks/setRewardRate.ts:BigInt(getRequiredEnvVar(...))forPROTOCOL_STAKING_COPRO_REWARD_RATEand
PROTOCOL_STAKING_KMS_REWARD_RATE.protocol-contracts/staking/tasks/deposit.ts:BigInt(getRequiredEnvVar(...))forOPERATOR_STAKING_COPRO_INITIAL_DEPOSIT_ASSETS_*andOPERATOR_STAKING_KMS_INITIAL_DEPOSIT_ASSETS_*.protocol-contracts/staking/tasks/setOwnerFee.ts:BigInt(getRequiredEnvVar(...))forOPERATOR_REWARDER_COPRO_OWNER_FEE_*andOPERATOR_REWARDER_KMS_OWNER_FEE_*.Rationale
getRequiredEnvVaralready returns a string, which is a valid input toBigInt.Numberand the associated precision limits.Testing
cd protocol-contracts/stakingnpm test/pnpm test(as used in the repo)