forked from dovuofficial/hedera-hardhat-tooling
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hardhat.config.js
115 lines (102 loc) · 3.22 KB
/
hardhat.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
require("dotenv").config();
require("module-alias/register");
require("@nomiclabs/hardhat-waffle");
const shell = require("shelljs");
const { TokenId } = require("@hashgraph/sdk");
const {
Network,
Config,
Hashgraph,
SDK: { ContractFunctionParameters },
} = require("hashgraph-support");
/**
* Leave this as a helper for deploying a smart contract,
*/
task("deploy", "Deploy a hedera contract")
.addParam(
"contract",
"Name of contract that you wish to deploy to Hedera, from your /contracts folder"
)
.addOptionalParam(
"destination",
"The network that you are deploying to. Currently supporting previewnet/testnet",
""
)
.setAction(async (args) => {
const destinationNetwork = args.destination || Config.network;
const client = Network.getNodeNetworkClient(destinationNetwork);
const contractInitialisation = {
contractName: args.contract,
// Optional, injected into the constructor, in this case for the "HelloWorld" Contract
constructorParams: new ContractFunctionParameters().addAddress(
TokenId.fromString(process.env.STAKABLE_TOKEN_ID).toSolidityAddress()
),
};
const contractId = await Hashgraph(client).contract.create(
contractInitialisation
);
// Check that contract test exist
shell.exec(`bin/check-for-contract-test ${args.contract.toUpperCase()}`);
// Inject the latest deployed contract ID into the env
shell.exec(
`bin/update-contract-id ${args.contract.toUpperCase()} ${contractId.toString()}`
);
console.log("Contract id: " + contractId.toString());
});
/**
* This task deploys some sensible defaults projects to the StakableProject Contract
*
* Run this once for a new StakableProject Contract
*
* WARN: This will only work once
*/
task(
"add-demo-projects",
"Add initial demo projects to StakableProject "
).setAction(async (args) => {
const destinationNetwork = args.destination || Config.network;
const client = Network.getNodeNetworkClient(destinationNetwork);
const hashgraph = Hashgraph(client);
const contractId = process.env.STAKABLEPROJECT_CONTRACT_ID;
const addProject = async (projectName, address) => {
await hashgraph.contract.call({
contractId: contractId,
method: "addProject",
params: new ContractFunctionParameters()
.addString(projectName)
.addAddress(address),
});
};
try {
// TODO: In the future the project name and address will refer to the actual project and the token ID
await addProject(
"farm-one",
TokenId.fromString("0.0.1").toSolidityAddress()
);
await addProject(
"farm-two",
TokenId.fromString("0.0.2").toSolidityAddress()
);
await addProject(
"farm-three",
TokenId.fromString("0.0.3").toSolidityAddress()
);
} catch (e) {
console.warn(
"If you are seeing this these projects have already been deployed onto the contract"
);
}
});
// You need to export an object to set up your config
// Go to https://hardhat.org/config/ to learn more
/**
* @type import('hardhat/config').HardhatUserConfig
*/
module.exports = {
solidity: "0.8.0",
// NOTE: Adding the optimiser by default, may remove later
optimizer: {
enabled: true,
runs: 1000,
},
};