generated from ahmedali8/hardhat-ts-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
25 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,33 @@ | ||
import type { SignerWithAddress } from "@nomicfoundation/hardhat-ethers/signers"; | ||
import { time } from "@nomicfoundation/hardhat-network-helpers"; | ||
import { ethers } from "hardhat"; | ||
import { ignition } from "hardhat"; | ||
|
||
import LockModule from "../../../ignition/modules/Lock"; | ||
import type { Lock } from "../../../types/Lock"; | ||
import type { Lock__factory } from "../../../types/factories/Lock__factory"; | ||
|
||
const ONE_YEAR_IN_SECS = time.duration.years(1); | ||
const ONE_GWEI = 1_000_000_000n; | ||
|
||
async function getUnlockTime(): Promise<number> { | ||
return (await time.latest()) + ONE_YEAR_IN_SECS; | ||
} | ||
|
||
export async function lockFixture(): Promise<{ | ||
lock: Lock; | ||
unlockTime: number; | ||
lockedAmount: number; | ||
lockedAmount: bigint; | ||
}> { | ||
const signers = await ethers.getSigners(); | ||
const deployer: SignerWithAddress = signers[0]; | ||
|
||
const LockFactory: Lock__factory = (await ethers.getContractFactory("Lock")) as Lock__factory; | ||
|
||
const ONE_YEAR_IN_SECS = time.duration.years(1); | ||
const ONE_GWEI = 1_000_000_000; | ||
|
||
const lockedAmount = ONE_GWEI; | ||
const unlockTime = (await time.latest()) + ONE_YEAR_IN_SECS; | ||
|
||
type DeployArgs = Parameters<typeof LockFactory.deploy>; | ||
const args: DeployArgs = [unlockTime, { value: lockedAmount }]; | ||
|
||
const lock: Lock = (await LockFactory.connect(deployer).deploy(...args)) as Lock; | ||
await lock.waitForDeployment(); | ||
const lockedAmount: bigint = ONE_GWEI; | ||
const unlockTime: number = await getUnlockTime(); | ||
|
||
const deployedLock = await ignition.deploy(LockModule, { | ||
parameters: { | ||
Lock: { | ||
unlockTime, | ||
lockedAmount, | ||
}, | ||
}, | ||
}); | ||
const lock = deployedLock.lock as unknown as Lock; | ||
|
||
return { lock, unlockTime, lockedAmount }; | ||
} |