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

Add missing interfaces for hardhat-network-helpers #5895

Merged
merged 6 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion v-next/hardhat-network-helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
"author": "Nomic Foundation",
"license": "MIT",
"type": "module",
"types": "dist/src/index.d.ts",
"exports": {
".": "./dist/src/index.js"
".": "./dist/src/index.js",
"./types": "./dist/src/types.js"
},
"keywords": [
"ethereum",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,98 +1,30 @@
export class Duration {
/**
* Converts the given number of years into seconds.
*
* @param n - The number of years.
* @returns The equivalent duration in seconds.
*
* @example
* const { networkHelpers } = await hre.network.connect();
* const seconds = networkHelpers.time.duration.years(1);
*/
import type { Duration as DurationI } from "../../../types.js";

export class Duration implements DurationI {
public years(n: number): number {
return this.days(n) * 365;
}

/**
* Converts the given number of weeks into seconds.
*
* @param n - The number of weeks.
* @returns The equivalent duration in seconds.
*
* @example
* const { networkHelpers } = await hre.network.connect();
* const seconds = networkHelpers.time.duration.weeks(1);
*/
public weeks(n: number): number {
return this.days(n) * 7;
}

/**
* Converts the given number of days into seconds.
*
* @param n - The number of days.
* @returns The equivalent duration in seconds.
*
* @example
* const { networkHelpers } = await hre.network.connect();
* const seconds = networkHelpers.time.duration.days(1);
*/
public days(n: number): number {
return this.hours(n) * 24;
}

/**
* Converts the given number of hours into seconds.
*
* @param n - The number of hours.
* @returns The equivalent duration in seconds.
*
* @example
* const { networkHelpers } = await hre.network.connect();
* const seconds = networkHelpers.time.duration.hours(1);
*/
public hours(n: number): number {
return this.minutes(n) * 60;
}

/**
* Converts the given number of minutes into seconds.
*
* @param n - The number of minutes.
* @returns The equivalent duration in seconds.
*
* @example
* const { networkHelpers } = await hre.network.connect();
* const seconds = networkHelpers.time.duration.minutes(1);
*/
public minutes(n: number): number {
return n * 60;
}

/**
* Returns the number of seconds.
*
* @param n - The number of seconds.
* @returns The same number of seconds.
*
* @example
* const { networkHelpers } = await hre.network.connect();
* const seconds = networkHelpers.time.duration.seconds(1);
*/
public seconds(n: number): number {
return n;
}

/**
* Converts the given number of milliseconds into seconds, rounded down to the nearest whole number.
*
* @param n - The number of milliseconds.
* @returns The equivalent duration in seconds.
*
* @example
* const { networkHelpers } = await hre.network.connect();
* const seconds = networkHelpers.time.duration.millis(1500); // Returns 1
*/
public millis(n: number): number {
return Math.floor(n / 1000);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Fixture, Snapshot } from "../../../types.js";
import type { NetworkHelpers } from "../network-helpers.js";
import type { Fixture, NetworkHelpers, Snapshot } from "../../../types.js";

import { HardhatError } from "@ignored/hardhat-vnext-errors";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { NumberLike } from "../../../types.js";
import type { NetworkHelpers } from "../network-helpers.js";
import type { NetworkHelpers, NumberLike } from "../../../types.js";
import type { EthereumProvider } from "@ignored/hardhat-vnext/types/providers";

import { toNumber } from "../../conversion.js";
Expand Down
Loading