You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
1.1 KiB
JavaScript
34 lines
1.1 KiB
JavaScript
const { ethers } = require('hardhat');
|
|
const { BigNumber } = require('ethers');
|
|
|
|
const deployContract = async function (contractName, constructorArgs) {
|
|
let factory;
|
|
try {
|
|
factory = await ethers.getContractFactory(contractName);
|
|
} catch (e) {
|
|
factory = await ethers.getContractFactory(contractName + 'UpgradeableWithInit');
|
|
}
|
|
let contract = await factory.deploy(...(constructorArgs || []));
|
|
await contract.deployed();
|
|
return contract;
|
|
};
|
|
|
|
const getBlockTimestamp = async function () {
|
|
return parseInt((await ethers.provider.getBlock('latest'))['timestamp']);
|
|
};
|
|
|
|
const mineBlockTimestamp = async function (timestamp) {
|
|
await ethers.provider.send('evm_setNextBlockTimestamp', [timestamp]);
|
|
await ethers.provider.send('evm_mine');
|
|
};
|
|
|
|
const offsettedIndex = function (startTokenId, arr) {
|
|
// return one item if arr length is 1
|
|
if (arr.length === 1) {
|
|
return BigNumber.from(startTokenId + arr[0]);
|
|
}
|
|
return arr.map((num) => BigNumber.from(startTokenId + num));
|
|
};
|
|
|
|
module.exports = { deployContract, getBlockTimestamp, mineBlockTimestamp, offsettedIndex };
|