-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploySparkAIForum.ts
81 lines (59 loc) · 2.91 KB
/
deploySparkAIForum.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
import { ethers } from "ethers";
import hre from "hardhat";
import {PRIVATE_KEY, RPC_URL} from "./arguments/blockchainArgs"
import {unsparkingAIProxy, firstAITokenAddressLaunched} from "./arguments/sparkFactoryArgs"
(async () => {
try {
if (!PRIVATE_KEY) {
throw new Error("Missing environment variable: PRIVATE_KEY");
}
const provider = ethers.getDefaultProvider(RPC_URL); // or your local node URL
const wallet = new ethers.Wallet(PRIVATE_KEY, provider);
const initialOwner = wallet.address;
// =================== Deploy SparkAIForum ===================
const SparkAIForum = await hre.ethers.getContractFactory("SparkAIForum");
const sparkAIForum = await SparkAIForum.deploy();
await sparkAIForum.waitForDeployment();
console.log(`SparkAIForum deployed to ${sparkAIForum.target}`);
// ===========================================================
// =================== Deploy ERC1967Proxy ===================
const ERC1967Proxy = await hre.ethers.getContractFactory("contracts/proxy/ERC1967.sol:ERC1967Proxy");
const erc1967Proxy = await ERC1967Proxy.deploy(sparkAIForum.target, "0x");
await erc1967Proxy.waitForDeployment();
console.log(`SparkAIForum Proxy deployed to ${erc1967Proxy.target}`);
// ===========================================================
// =================== Initialize Contracts ===================
const sparkAIForumThruProxy = SparkAIForum.attach(erc1967Proxy.target);
await sparkAIForumThruProxy.initialize(initialOwner, initialOwner, initialOwner, unsparkingAIProxy);
console.log(`SparkAIForum initialized`);
// ===========================================================
// =================== Add Token Approval for Deployer ===================
if (firstAITokenAddressLaunched != "0x0000000000000000000000000000000000000000"){
const FERC20 = await hre.ethers.getContractFactory("FERC20");
const ferc20 = await FERC20.attach(firstAITokenAddressLaunched);
await ferc20.approve(sparkAIForumThruProxy.target, "115792089237316195423570985008687907853269984665640564039457584007913129639935");
console.log(`Token approved for SparkAIForum`);
}
else{
console.log(`No token address provided for approval`);
}
// ===========================================================
// =================== Verify Contracts ===================
await hre.run("verify:verify", {
address: sparkAIForum.target,
constructorArguments: [],
});
await hre.run("verify:verify", {
address: erc1967Proxy.target,
constructorArguments: [
sparkAIForum.target,
"0x"
],
contract: "contracts/proxy/ERC1967.sol:ERC1967Proxy",
sourcePath: "./contracts/proxy/ERC1967.sol" // Ensure this path is correct
});
// ========================================================
} catch (e) {
console.log(e);
}
})();