2020-05-29 14:55:31 +00:00
|
|
|
import BigNumber from "bignumber.js";
|
|
|
|
import BN = require("bn.js");
|
|
|
|
import low from "lowdb";
|
|
|
|
import FileSync from "lowdb/adapters/FileSync";
|
2020-06-03 10:44:10 +00:00
|
|
|
import {WAD} from "./constants";
|
|
|
|
import {Wallet} from "ethers";
|
|
|
|
import {BuidlerRuntimeEnvironment} from "@nomiclabs/buidler/types";
|
2020-05-29 14:55:31 +00:00
|
|
|
|
|
|
|
export const toWad = (value: string | number) =>
|
|
|
|
new BigNumber(value).times(WAD).toFixed();
|
|
|
|
|
|
|
|
export const bnToBigNumber = (amount: BN): BigNumber =>
|
|
|
|
new BigNumber(<any>amount);
|
|
|
|
export const stringToBigNumber = (amount: string): BigNumber =>
|
|
|
|
new BigNumber(amount);
|
|
|
|
|
|
|
|
export const getDb = () => low(new FileSync("./deployed-contracts.json"));
|
|
|
|
|
|
|
|
export let BRE: BuidlerRuntimeEnvironment = {} as BuidlerRuntimeEnvironment;
|
|
|
|
export const setBRE = (_BRE: BuidlerRuntimeEnvironment) => {
|
|
|
|
BRE = _BRE;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const sleep = (milliseconds: number) => {
|
|
|
|
return new Promise((resolve) => setTimeout(resolve, milliseconds));
|
|
|
|
};
|
2020-06-03 10:44:10 +00:00
|
|
|
|
|
|
|
export const createRandomAddress = () => Wallet.createRandom().address;
|
2020-06-08 12:03:40 +00:00
|
|
|
|
2020-06-12 13:41:52 +00:00
|
|
|
export const evmSnapshot = async () =>
|
|
|
|
await BRE.ethereum.send("evm_snapshot", []);
|
2020-06-08 12:03:40 +00:00
|
|
|
|
|
|
|
export const evmRevert = async (id: string) =>
|
|
|
|
BRE.ethereum.send("evm_revert", [id]);
|