-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhardhat.config.ts
181 lines (160 loc) · 5.79 KB
/
hardhat.config.ts
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import { HardhatUserConfig, task } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";
import * as dotenv from "dotenv";
require('@nomicfoundation/hardhat-toolbox')
dotenv.config();
const GOERLI_RPC_URL = process.env.ALCHEMY_GOERLI_RPC_URL;
const POLYGON_RPC_URL = process.env.ALCHEMY_POLYGON_RPC_URL;
const PRIVATE_KEY = process.env.WALLET_PRIVATE_KEY || "";
const DELEGATE_REGISTRY_ADDRESS = process.env.GOERLI_CONTRACT_ADDRESS || "";
const config: HardhatUserConfig = {
networks: {
goerli: {
url: GOERLI_RPC_URL,
accounts: [PRIVATE_KEY]
},
mumbai: {
chainId: 80001,
url: POLYGON_RPC_URL,
accounts: [PRIVATE_KEY]
}
},
solidity: "0.8.17"
};
export default config;
// define task with a name as 1st argument and handler function as the 2nd argument
task("createWallet", "print out address, public and private key").setAction(
async (_taskArgs, hre) => {
const wallet = hre.ethers.Wallet.createRandom();
console.log({
address: wallet.address,
publicKey: wallet.publicKey,
privateKey: wallet.privateKey
});
}
);
task("getBalance")
.addParam("address")
.setAction(async (taskArgs, hre) => {
const provider = hre.ethers.getDefaultProvider("goerli");
let balance = await provider.getBalance(taskArgs.address);
console.log("$TOKEN", hre.ethers.utils.formatEther(balance));
});
task(
"getBalanceMumbai",
"Get the balance of a wallet in Polygon Mumbai Testnet"
)
.addParam("address", "The wallet address")
.setAction(async (taskArgs, hre) => {
const { address } = taskArgs;
const networkConfig = hre.network.config;
const provider = new hre.ethers.providers.JsonRpcProvider(
"https://rpc.decentraland.org/mumbai",
{
name: hre.network.name,
chainId: networkConfig.chainId
}
);
try {
const balance = await provider.getBalance(address);
const balanceEth = hre.ethers.utils.formatEther(balance);
console.log(`Balance of wallet ${address}: ${balanceEth} TOKEN`);
} catch (error) {
console.error("Error retrieving address balance:", error);
throw error;
}
});
/**
* Usage
* npx hardhat --network networkName setDelegate --id spaceName --delegate address
* networkName should be defined in the hardhat config above
*/
task("setDelegate", "Set a delegate for a given project ID")
.addParam("id", "The ID of the project to set the delegate for")
.addParam("delegate", "The address of the delegate to set")
.setAction(async (taskArgs, hre) => {
const { id, delegate } = taskArgs;
const formattedProjectId = hre.ethers.utils.formatBytes32String(id);
const [delegator] = await hre.ethers.getSigners();
console.log("Delegator", delegator.address);
console.log(`Setting delegate ${delegate} for project ${id}...`);
// Get the contract instance
const DelegateRegistry = await hre.ethers.getContractFactory(
"DelegateRegistry"
);
const delegateRegistry = await DelegateRegistry.attach(
DELEGATE_REGISTRY_ADDRESS
);
// Connect Delegator Wallet
delegateRegistry.connect(delegator);
// Set the delegate
const tx = await delegateRegistry.setDelegate(formattedProjectId, delegate);
await tx.wait();
console.log(`Delegate set.`);
});
/**
* Usage
* npx hardhat --network networkName clearDelegate --id spaceName --delegate address
* networkName should be defined in the hardhat config above
*/
task("clearDelegate", "Clear a delegate for a given project ID")
.addParam("id", "The ID of the project to remove the delegate for")
.addParam("delegate", "The address of the delegate to remove")
.setAction(async (taskArgs, hre) => {
const { id, delegate } = taskArgs;
const formattedProjectId = hre.ethers.utils.formatBytes32String(id);
console.log("formattedProjectId", formattedProjectId);
const [delegator] = await hre.ethers.getSigners();
console.log("Delegator", delegator.address);
console.log(`Removing delegate ${delegate} for project ${id}...`);
// Get the contract instance
const DelegateRegistry = await hre.ethers.getContractFactory(
"DelegateRegistry"
);
const delegateRegistry = await DelegateRegistry.attach(
DELEGATE_REGISTRY_ADDRESS
);
// Connect Delegator Wallet
delegateRegistry.connect(delegator);
// Set the delegate
const tx = await delegateRegistry.clearDelegate(
formattedProjectId,
delegate
);
await tx.wait();
console.log(`Delegate removed.`);
});
/**
* Usage
* npx hardhat --network networkName clearAllDelegates --id spaceName
* networkName should be defined in the hardhat config above
*/
task("clearAllDelegates", "Clear all delegate for a given project ID")
.addParam("id", "The ID of the project to remove the delegates for")
.setAction(async (taskArgs, hre) => {
const { id } = taskArgs;
const formattedProjectId = hre.ethers.utils.formatBytes32String(id);
const [delegator] = await hre.ethers.getSigners();
console.log("Delegator", delegator.address);
console.log(`Removing all delegates for project ${id}...`);
// Get the contract instance
const DelegateRegistry = await hre.ethers.getContractFactory(
"DelegateRegistry"
);
const delegateRegistry = await DelegateRegistry.attach(
DELEGATE_REGISTRY_ADDRESS
);
// Connect Delegator Wallet
delegateRegistry.connect(delegator);
// Set the delegate
const tx = await delegateRegistry.clearAllDelegates(formattedProjectId);
await tx.wait();
console.log(`Delegates removed.`);
});
task("getFormattedProjectId")
.addParam("id", "The ID of the project")
.setAction(async (taskArgs, hre) => {
const { id } = taskArgs;
const formattedProjectId = hre.ethers.utils.formatBytes32String(id);
console.log("formattedProjectId", formattedProjectId);
});