-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeploy_abraham.ts
More file actions
265 lines (228 loc) · 10 KB
/
deploy_abraham.ts
File metadata and controls
265 lines (228 loc) · 10 KB
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
import hre from "hardhat";
import { createWalletClient, http, publicActions } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { sepolia } from "viem/chains";
import { config as dotenvConfig } from "dotenv";
import { writeFileSync, existsSync, mkdirSync } from "fs";
import { join } from "path";
// Load .env.local
dotenvConfig({ path: ".env.local" });
/**
* Deploy AbrahamCovenant and AbrahamAuction contracts to Ethereum Sepolia
*
* This deployment script:
* 1. Deploys AbrahamCovenant NFT contract
* 2. Deploys AbrahamAuction contract
* 3. Sets up permissions (covenant approves auction)
* 4. Starts the covenant
* 5. Saves ABIs and addresses to lib folder
* 6. Updates .env file with deployed addresses
*/
async function main() {
console.log("=== Abraham Contracts Deployment to Sepolia ===\n");
// Get network config
const chain = sepolia;
const rpcUrl = process.env.SEPOLIA_RPC_URL || "https://rpc.sepolia.org";
if (!process.env.PRIVATE_KEY) {
throw new Error("PRIVATE_KEY not found in environment variables");
}
// Create wallet client
const account = privateKeyToAccount(`0x${process.env.PRIVATE_KEY.replace("0x", "")}`);
const client = createWalletClient({
account,
chain,
transport: http(rpcUrl),
}).extend(publicActions);
console.log("Deployer:", account.address);
console.log("Network: Sepolia");
console.log("RPC URL:", rpcUrl);
console.log("");
// Get compiled contracts
const AbrahamCovenant = await hre.artifacts.readArtifact("AbrahamCovenant");
const AbrahamAuction = await hre.artifacts.readArtifact("AbrahamAuction");
// ============================================================
// 1. Deploy AbrahamCovenant
// ============================================================
console.log("1️⃣ Deploying AbrahamCovenant...");
console.log(" Name: Abraham Covenant");
console.log(" Symbol: ABRAHAM");
console.log(" Max Supply: 4745 (13 years * 365 days)");
console.log(" Work Cycle: 6 days (rest on 7th)");
console.log(" Abraham: ", account.address);
console.log("");
const covenantHash = await client.deployContract({
abi: AbrahamCovenant.abi as any,
bytecode: AbrahamCovenant.bytecode as `0x${string}`,
args: [
"Abraham Covenant", // _name
"ABRAHAM", // _symbol
account.address, // _owner (deployer)
account.address, // _abraham (for testing, use same address)
4745n, // _maxSupply (13 years * 365 days)
6n, // _daysOfWork (6 days work, 1 day rest)
],
});
console.log(" Transaction hash:", covenantHash);
console.log(" Waiting for confirmation...");
const covenantReceipt = await client.waitForTransactionReceipt({ hash: covenantHash });
const covenantAddress = covenantReceipt.contractAddress;
if (!covenantAddress) {
throw new Error("AbrahamCovenant deployment failed - no address returned");
}
console.log(" ✅ AbrahamCovenant deployed at:", covenantAddress);
console.log(" Block number:", covenantReceipt.blockNumber);
console.log("");
// ============================================================
// 2. Deploy AbrahamAuction
// ============================================================
console.log("2️⃣ Deploying AbrahamAuction...");
console.log(" NFT Contract:", covenantAddress);
console.log(" Owner:", account.address);
console.log(" Payout Address:", account.address);
console.log("");
const auctionHash = await client.deployContract({
abi: AbrahamAuction.abi as any,
bytecode: AbrahamAuction.bytecode as `0x${string}`,
args: [
covenantAddress, // _nftContract
account.address, // _owner
account.address, // _payoutAddress
],
});
console.log(" Transaction hash:", auctionHash);
console.log(" Waiting for confirmation...");
const auctionReceipt = await client.waitForTransactionReceipt({ hash: auctionHash });
const auctionAddress = auctionReceipt.contractAddress;
if (!auctionAddress) {
throw new Error("AbrahamAuction deployment failed - no address returned");
}
console.log(" ✅ AbrahamAuction deployed at:", auctionAddress);
console.log(" Block number:", auctionReceipt.blockNumber);
console.log("");
// ============================================================
// 3. Set up permissions
// ============================================================
console.log("3️⃣ Setting up permissions...");
console.log(" Configuring AbrahamCovenant to allow AbrahamAuction to transfer NFTs");
console.log("");
// Update sales mechanic
console.log(" a) Setting sales mechanic address...");
const updateMechanicHash = await client.writeContract({
address: covenantAddress,
abi: AbrahamCovenant.abi as any,
functionName: "updateSalesMechanic",
args: [auctionAddress],
});
await client.waitForTransactionReceipt({ hash: updateMechanicHash });
console.log(" ✅ Sales mechanic set to:", auctionAddress);
// Set mechanic operator approval
console.log(" b) Granting operator approval...");
const setOperatorHash = await client.writeContract({
address: covenantAddress,
abi: AbrahamCovenant.abi as any,
functionName: "setMechanicOperator",
args: [true],
});
await client.waitForTransactionReceipt({ hash: setOperatorHash });
console.log(" ✅ Operator approval granted");
console.log("");
// ============================================================
// 4. Start the covenant
// ============================================================
console.log("4️⃣ Starting the covenant...");
const currentTimestamp = BigInt(Math.floor(Date.now() / 1000));
const startCovenantHash = await client.writeContract({
address: covenantAddress,
abi: AbrahamCovenant.abi as any,
functionName: "startCovenant",
args: [currentTimestamp],
});
await client.waitForTransactionReceipt({ hash: startCovenantHash });
console.log(" ✅ Covenant started at:", new Date().toISOString());
console.log("");
// ============================================================
// 5. Save ABIs to lib/abi folder
// ============================================================
console.log("5️⃣ Saving ABIs and addresses...");
const abiDir = join(process.cwd(), "lib", "abi");
if (!existsSync(abiDir)) {
mkdirSync(abiDir, { recursive: true });
}
// Save AbrahamCovenant ABI
const covenantAbiPath = join(abiDir, "abrahamCovenant.ts");
const covenantAbiContent = `// AbrahamCovenant Contract ABI
// Auto-generated by deployment script on ${new Date().toISOString()}
// Deployed to Sepolia at: ${covenantAddress}
export const ABRAHAM_COVENANT_ADDRESS = "${covenantAddress}";
export const ABRAHAM_COVENANT_ABI = ${JSON.stringify(AbrahamCovenant.abi, null, 2)} as const;
`;
writeFileSync(covenantAbiPath, covenantAbiContent);
console.log(" ✅ Saved AbrahamCovenant ABI to:", covenantAbiPath);
// Save AbrahamAuction ABI
const auctionAbiPath = join(abiDir, "abrahamAuction.ts");
const auctionAbiContent = `// AbrahamAuction Contract ABI
// Auto-generated by deployment script on ${new Date().toISOString()}
// Deployed to Sepolia at: ${auctionAddress}
export const ABRAHAM_AUCTION_ADDRESS = "${auctionAddress}";
export const ABRAHAM_AUCTION_ABI = ${JSON.stringify(AbrahamAuction.abi, null, 2)} as const;
`;
writeFileSync(auctionAbiPath, auctionAbiContent);
console.log(" ✅ Saved AbrahamAuction ABI to:", auctionAbiPath);
console.log("");
// ============================================================
// 6. Save deployment info
// ============================================================
const deploymentInfoPath = join(process.cwd(), "lib", "abi", "deployment-info.json");
const deploymentInfo = {
network: "sepolia",
timestamp: new Date().toISOString(),
deployer: account.address,
contracts: {
abrahamCovenant: {
address: covenantAddress,
blockNumber: covenantReceipt.blockNumber.toString(),
txHash: covenantHash,
},
abrahamAuction: {
address: auctionAddress,
blockNumber: auctionReceipt.blockNumber.toString(),
txHash: auctionHash,
},
},
};
writeFileSync(deploymentInfoPath, JSON.stringify(deploymentInfo, null, 2));
console.log(" ✅ Saved deployment info to:", deploymentInfoPath);
console.log("");
// ============================================================
// 7. Print environment variables to add
// ============================================================
console.log("=== Deployment Successful ===\n");
console.log("📝 Add these to your .env.local file:\n");
console.log(`# Abraham Contracts (Sepolia)`);
console.log(`ABRAHAM_COVENANT_ADDRESS=${covenantAddress}`);
console.log(`ABRAHAM_AUCTION_ADDRESS=${auctionAddress}`);
console.log(`SEPOLIA_RPC_URL=${rpcUrl}`);
console.log("");
console.log("=== Next Steps ===");
console.log("1. ✅ Contracts deployed and configured");
console.log("2. ✅ ABIs saved to lib/abi/ folder");
console.log("3. ✅ Covenant started and ready for daily work");
console.log("4. ⏳ Add environment variables to .env.local (see above)");
console.log("5. ⏳ Test the flow:");
console.log(" - Select a winner on TheSeeds (Base)");
console.log(" - Call /api/admin/select-winner");
console.log(" - Winner should be minted on Sepolia");
console.log(" - Auction should start automatically");
console.log("");
console.log("=== Useful Commands ===");
console.log(`View covenant on Etherscan: https://sepolia.etherscan.io/address/${covenantAddress}`);
console.log(`View auction on Etherscan: https://sepolia.etherscan.io/address/${auctionAddress}`);
console.log("");
console.log("Verify contracts:");
console.log(`npx hardhat verify --network sepolia ${covenantAddress} "Abraham Covenant" "ABRAHAM" ${account.address} ${account.address} 4745 6`);
console.log(`npx hardhat verify --network sepolia ${auctionAddress} ${covenantAddress} ${account.address} ${account.address}`);
}
main().catch((e) => {
console.error(e);
process.exit(1);
});