-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from keep-network/packages-update
Packages update ### Why Update of core packages like `ethers` and `hardhat` to make `hardhat-helpers` package compatible with projects using new versions of these packages. ### What #### Packages updates: - adding `.nvmrc` with specified node version `v20.10.0` as node older than LTS won't support new packages - updating `typescript` to version `>5` (and related packages) to be able to compile these new packages - updating `eslint` and related packages to correctly lint codebase - updating `hardhat` packages to newest versions: - replacing deprecated `hardhat-etherscan` with `hardhat-verify` - updating `ethers` package to version `>6` #### Codebase updates: - no more `BigNumbers` - as ethers v6 is not longer using `BigNumbers` they are replaced with native `bigints` calculations - wherever possible types and utils are imported directly from `ethers`, sometimes it means that the function or type is slightly changed, moved out of `utils` or renamed - some types like `SignerWithAddress` were removed completely and they were replaced with similar types - some functions started to return default values like `null` or `undefined` which broke our code - optional chaining with default values has been used to fix these places #### Remaining problems: - there are some problems with incompatible types - some places has been changed more than others - see `upgrades` file - and we should make sure their test coverage was enough to be sure they are working correctly
- Loading branch information
Showing
17 changed files
with
2,037 additions
and
1,315 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
lts/iron |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,31 @@ | ||
import { formatFixed } from "@ethersproject/bignumber" | ||
import { BigNumber } from "ethers" | ||
import { BigNumberish } from "ethers" | ||
|
||
export interface HardhatNumberHelpers { | ||
to1e18(n: any): BigNumber | ||
to1ePrecision(n: any, precision: number): BigNumber | ||
from1e18(n: any): string | ||
from1ePrecision(n: any, precision: number): string | ||
to1e18(n: BigNumberish): bigint | ||
to1ePrecision(n: BigNumberish, precision: number): bigint | ||
from1e18(n: BigNumberish): string | ||
from1ePrecision(n: BigNumberish, precision: number): string | ||
} | ||
|
||
export function to1e18(n: any): BigNumber { | ||
export function to1e18(n: BigNumberish): bigint { | ||
return to1ePrecision(n, 18) | ||
} | ||
|
||
export function to1ePrecision(n: any, precision: number): BigNumber { | ||
const decimalMultiplier = BigNumber.from(10).pow(precision) | ||
return BigNumber.from(n).mul(decimalMultiplier) | ||
export function to1ePrecision(n: BigNumberish, precision: number): bigint { | ||
const decimalMultiplier = 10n ** BigInt(precision) | ||
return BigInt(n) * decimalMultiplier | ||
} | ||
|
||
export function from1e18(n: any): string { | ||
export function from1e18(n: BigNumberish): string { | ||
return from1ePrecision(n, 18) | ||
} | ||
|
||
export function from1ePrecision(n: any, precision: number): string { | ||
const value: BigNumber = BigNumber.from(n) | ||
const decimalMultiplier: BigNumber = BigNumber.from(10).pow(precision) | ||
export function from1ePrecision(n: BigNumberish, precision: number): string { | ||
const value = BigInt(n) | ||
const decimalMultiplier = 10n ** BigInt(precision) | ||
|
||
return value.gte(decimalMultiplier) && value.mod(decimalMultiplier).isZero() | ||
? value.div(decimalMultiplier).toString() | ||
return value >= decimalMultiplier && value % decimalMultiplier === 0n | ||
? (value / decimalMultiplier).toString() | ||
: formatFixed(n, precision) | ||
} |
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.