-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.js
More file actions
183 lines (163 loc) · 7.88 KB
/
deploy.js
File metadata and controls
183 lines (163 loc) · 7.88 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
/**
* Agora — Kite Chain Deployment Script
* Run with: npx hardhat run deploy.js --network kite
*
* Deploys contracts in the correct dependency order:
* 1. AgentRegistry
* 2. AttestationLogger (needs AgentRegistry)
* 3. X402PaymentGate (needs USDC, AgentRegistry, AttestationLogger)
* 4. PredictionMarket (needs USDC, AttestationLogger, AgentRegistry)
* 5. CreditVault (needs USDC, AgentRegistry, AttestationLogger)
* 6. Wire up all cross-contract permissions
*/
const hre = require("hardhat");
const { ethers } = hre;
// Kite chain USDC address (mainnet)
// From: https://docs.gokite.ai/kite-chain/1-getting-started/network-information
const KITE_USDC = process.env.USDC_ADDRESS || "0x92E2391d0836e10b9e5EAB5d56BfC286Fadec25b";
const ENABLE_DEMO_SEED = (process.env.ENABLE_DEMO_SEED || "false").toLowerCase() === "true";
async function main() {
const [deployer] = await ethers.getSigners();
console.log("===========================================");
console.log(" AGORA — Deploying to Kite Chain");
console.log("===========================================");
console.log("Deployer:", deployer.address);
console.log("Balance: ", ethers.formatEther(await deployer.provider.getBalance(deployer.address)), "KITE");
console.log("");
// ─── 1. AgentRegistry ─────────────────────────────────────────
console.log("1. Deploying AgentRegistry...");
const AgentRegistry = await ethers.getContractFactory("AgentRegistry");
const registry = await AgentRegistry.deploy();
await registry.waitForDeployment();
const registryAddress = await registry.getAddress();
console.log(" AgentRegistry deployed:", registryAddress);
// ─── 2. AttestationLogger ─────────────────────────────────────
console.log("2. Deploying AttestationLogger...");
const AttestationLogger = await ethers.getContractFactory("AttestationLogger");
const logger = await AttestationLogger.deploy(registryAddress);
await logger.waitForDeployment();
const loggerAddress = await logger.getAddress();
console.log(" AttestationLogger deployed:", loggerAddress);
// ─── 3. X402PaymentGate ───────────────────────────────────────
console.log("3. Deploying X402PaymentGate...");
const X402PaymentGate = await ethers.getContractFactory("X402PaymentGate");
const gate = await X402PaymentGate.deploy(
KITE_USDC,
registryAddress,
loggerAddress,
50, // 0.5% protocol fee
deployer.address // fee recipient (update to multisig in production)
);
await gate.waitForDeployment();
const gateAddress = await gate.getAddress();
console.log(" X402PaymentGate deployed:", gateAddress);
// ─── 4. PredictionMarket ──────────────────────────────────────
console.log("4. Deploying PredictionMarket...");
const PredictionMarket = await ethers.getContractFactory("PredictionMarket");
const market = await PredictionMarket.deploy(
KITE_USDC,
loggerAddress,
registryAddress,
100, // 1% protocol fee
deployer.address
);
await market.waitForDeployment();
const marketAddress = await market.getAddress();
console.log(" PredictionMarket deployed:", marketAddress);
// ─── 5. CreditVault ───────────────────────────────────────────
console.log("5. Deploying CreditVault...");
const CreditVault = await ethers.getContractFactory("CreditVault");
const vault = await CreditVault.deploy(
KITE_USDC,
registryAddress,
loggerAddress
);
await vault.waitForDeployment();
const vaultAddress = await vault.getAddress();
console.log(" CreditVault deployed:", vaultAddress);
// ─── 6. Wire up permissions ───────────────────────────────────
console.log("\n6. Wiring up contract permissions...");
// Allow AttestationLogger to update reputation in AgentRegistry
await registry.setAttestationLogger(loggerAddress);
console.log(" AgentRegistry: set AttestationLogger =", loggerAddress);
// Tell AttestationLogger which contracts are authorized to log
await logger.setX402Gate(gateAddress);
await logger.setPredictionMarket(marketAddress);
await logger.setCreditVault(vaultAddress);
console.log(" AttestationLogger: authorized X402Gate, PredictionMarket, CreditVault");
// ─── 7. Optional demo seed data ───────────────────────────────
if (ENABLE_DEMO_SEED) {
console.log("\n7. Registering demo data feeds on X402Gate...");
const feeds = [
{ id: "NEWS-FEED-US", price: "80000" }, // 0.08 USDC (6 decimals)
{ id: "WEATHER-API", price: "30000" }, // 0.03 USDC
{ id: "STOCK-DATA-RT", price: "220000" }, // 0.22 USDC
{ id: "SENTIMENT-NLP", price: "110000" }, // 0.11 USDC
{ id: "ON-CHAIN-SIG", price: "450000" }, // 0.45 USDC
{ id: "DEFI-RATES", price: "60000" }, // 0.06 USDC
];
for (const feed of feeds) {
await gate.registerFeed(feed.id, feed.price);
console.log(` Feed registered: ${feed.id} @ ${feed.price} (USDC 6dp)`);
}
// ─── 8. Create sample prediction markets (for demo) ───────────
console.log("\n8. Creating demo prediction markets...");
const oneDay = 86400;
const oneWeek = 86400 * 7;
const now = Math.floor(Date.now() / 1000);
await market.createMarket(
"Will BTC be above $72,000 by Kite block 4,900,000?",
"BTC/USD price at block 4,900,000 must exceed $72,000",
now + oneDay
);
await market.createMarket(
"Will AGT-7F2 earn more than 10 USDC today?",
"Total USDC earned by AGT-7F2 address in 24 hours must exceed 10 USDC",
now + oneDay
);
await market.createMarket(
"Will USDC/KITE settle above 0.12 this week?",
"USDC/KITE price on Kite chain DEX at week end must exceed 0.12",
now + oneWeek
);
console.log(" 3 prediction markets created");
} else {
console.log("\n7-8. Demo seed skipped (ENABLE_DEMO_SEED=false)");
}
// ─── 9. Summary ───────────────────────────────────────────────
console.log("\n===========================================");
console.log(" DEPLOYMENT COMPLETE");
console.log("===========================================");
console.log("AgentRegistry: ", registryAddress);
console.log("AttestationLogger:", loggerAddress);
console.log("X402PaymentGate: ", gateAddress);
console.log("PredictionMarket: ", marketAddress);
console.log("CreditVault: ", vaultAddress);
console.log("\nSave these addresses to your .env file.");
console.log("===========================================\n");
// Save to a JSON file for the frontend to consume
const fs = require("fs");
const deployedAddresses = {
network: "kite-mainnet",
chainId: Number(hre?.network?.config?.chainId || 2366),
usdc: KITE_USDC,
agentRegistry: registryAddress,
attestationLogger: loggerAddress,
x402PaymentGate: gateAddress,
predictionMarket: marketAddress,
creditVault: vaultAddress,
demoSeedEnabled: ENABLE_DEMO_SEED,
deployedAt: new Date().toISOString(),
};
fs.writeFileSync(
"./deployed-addresses.json",
JSON.stringify(deployedAddresses, null, 2)
);
console.log("Addresses saved to deployed-addresses.json");
}
main()
.then(() => process.exit(0))
.catch((err) => {
console.error("Deployment failed:", err);
process.exit(1);
});