-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(sdk): [NET-1388] Use
bigint
for Wei amounts in `operatorCo…
…ntractUtils` (#2952) ## Summary The `operatorContractUtils` functions now use Wei units instead of full DATA token units. The parameter type for those functions is now `WeiAmount` instead of `number`. The `WeiAmount` is a type alias for `bigint`. The purpose for `WeiAmount` is similar to `HexString`: it improves readability as it tells more about what _kind_ of `bigint` value the variable stores. I.e. that the value is a token amount, and the unit of the token amount is Wei. (The same information could be in the variable name, but this approach is more readable). ## Changes - function signatures: `delegate`/`delegate`, `stake`/`unstake`, `sponsor`, `transferTokens` - `earningsPerSeconds` field type in `DeployOperatorContractOpts` Also moved `multiply` utility from `node` to `utils` and renamed it to `multiplyWeiAmount`. It is now used also in the `sdk` package. ## Other changes - Improved logging for `sumDataWei` and `maxAllowedEarningsDataWei` in `checkOperatorValueBreach`, ensuring a more readable format. Previously these values were sometimes logged using scientific notation. - Small renames: - `operatorsCutPercent` -> `operatorsCutPercentage` - shortened some variable names as we now use `WeiAmount` type (no need have the type also in the variable name, e.g. `maxAllowedEarningsDataWei`) - unified Wei amount variable naming in `inspect.test.ts` ## Future improvements We use `ether`'s `parseEther()` to convert full DATA token units to Wei units. The word Ether is maybe bit misleading there, so we could consider having a wrapper to make it more readable? Possible higher level approach would be to have a `TokenAmount` class for holding the value. In that case we'd have builder functions like `TokenAmount.full(123.45)` and `TokenAmount.wei(123450000000000000000n)`.
- Loading branch information
Showing
15 changed files
with
139 additions
and
130 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 6 additions & 7 deletions
13
packages/node/src/plugins/operator/maintainOperatorValue.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.