refactor(contracts): remove deprecated AIPowerRental contract in favor of bounty system

- Delete AIPowerRental.sol (566 lines) - replaced by AgentBounty.sol
- Remove rental agreement system with provider/consumer model
- Remove performance metrics and SLA tracking
- Remove dispute resolution mechanism
- Remove ZK-proof verification for performance
- Remove provider/consumer authorization system
- Bounty system provides superior developer incentive structure
This commit is contained in:
oib
2026-02-27 21:46:54 +01:00
parent a477681c4b
commit 864ef4343e
152 changed files with 45716 additions and 94 deletions

View File

@@ -0,0 +1,44 @@
const { ethers } = require("hardhat");
async function main() {
try {
const [deployer] = await ethers.getSigners();
const balance = await deployer.getBalance();
const balanceEth = ethers.utils.formatEther(balance);
console.log("💰 Deployer Account Balance");
console.log("==========================");
console.log(`Address: ${deployer.address}`);
console.log(`Balance: ${balanceEth} ETH`);
// Calculate USD value (assuming $2000/ETH)
const balanceUsd = parseFloat(balanceEth) * 2000;
console.log(`USD Value: $${balanceUsd.toFixed(2)}`);
// Balance recommendations
const minRecommended = 10; // Minimum ETH recommended for deployment
const safeAmount = 20; // Safe amount for deployment + buffer
if (parseFloat(balanceEth) >= safeAmount) {
console.log("✅ Sufficient balance for deployment");
} else if (parseFloat(balanceEth) >= minRecommended) {
console.log("⚠️ Minimum balance met, but consider adding more ETH for safety");
} else {
console.log("❌ Insufficient balance. Minimum 10 ETH recommended for deployment");
}
// Output just the balance for script consumption
console.log(balanceEth);
} catch (error) {
console.error("Error checking balance:", error);
process.exit(1);
}
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});

View File

@@ -0,0 +1,47 @@
const { ethers } = require("hardhat");
async function main() {
try {
// Get current gas price
const gasPrice = await ethers.provider.getGasPrice();
const gasPriceGwei = ethers.utils.formatUnits(gasPrice, "gwei");
// Get gas limit estimates
const block = await ethers.provider.getBlock("latest");
const baseFeePerGas = block.baseFeePerGas ? ethers.utils.formatUnits(block.baseFeePerGas, "gwei") : "N/A";
// Calculate estimated deployment costs
const estimatedGasLimit = 8000000; // Estimated total gas for all contracts
const estimatedCostEth = parseFloat(gasPriceGwei) * estimatedGasLimit / 1e9;
console.log("🔍 Mainnet Gas Analysis");
console.log("======================");
console.log(`Current Gas Price: ${gasPriceGwei} gwei`);
console.log(`Base Fee: ${baseFeePerGas} gwei`);
console.log(`Estimated Deployment Cost: ${estimatedCostEth.toFixed(4)} ETH`);
console.log(`Estimated Deployment Cost: $${(estimatedCostEth * 2000).toFixed(2)} USD (assuming $2000/ETH)`);
// Gas price recommendations
if (parseFloat(gasPriceGwei) < 20) {
console.log("✅ Gas price is LOW - Good time to deploy");
} else if (parseFloat(gasPriceGwei) < 50) {
console.log("⚠️ Gas price is MODERATE - Consider waiting if possible");
} else {
console.log("❌ Gas price is HIGH - Consider waiting for lower gas");
}
// Output just the gas price for script consumption
console.log(gasPriceGwei);
} catch (error) {
console.error("Error checking gas price:", error);
process.exit(1);
}
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});

View File

@@ -0,0 +1,324 @@
const { ethers } = require("hardhat");
const fs = require("fs");
const path = require("path");
async function main() {
console.log("🚀 Deploying Advanced Agent Features Contracts");
console.log("=============================================");
const [deployer] = await ethers.getSigners();
const balance = await deployer.getBalance();
console.log(`Deployer: ${deployer.address}`);
console.log(`Balance: ${ethers.utils.formatEther(balance)} ETH`);
if (balance.lt(ethers.utils.parseEther("1"))) {
throw new Error("Insufficient ETH balance. Minimum 1 ETH recommended for deployment.");
}
console.log("");
console.log("Proceeding with advanced contracts deployment...");
// Deployment configuration
const deployedContracts = {
network: hre.network.name,
deployer: deployer.address,
timestamp: new Date().toISOString(),
contracts: {}
};
try {
// Get existing contracts
let aitbcTokenAddress, paymentProcessorAddress, agentWalletAddress, aiPowerRentalAddress;
try {
const existingContractsFile = `deployed-contracts-${hre.network.name}.json`;
if (fs.existsSync(existingContractsFile)) {
const existingContracts = JSON.parse(fs.readFileSync(existingContractsFile, 'utf8'));
aitbcTokenAddress = existingContracts.contracts.AITBCToken?.address;
paymentProcessorAddress = existingContracts.contracts.AITBCPaymentProcessor?.address;
agentWalletAddress = existingContracts.contracts.AgentWallet?.address;
aiPowerRentalAddress = existingContracts.contracts.AIPowerRental?.address;
}
} catch (error) {
console.log("Could not load existing contracts, deploying mock ones...");
}
// Deploy Mock ERC20 if needed
if (!aitbcTokenAddress) {
console.log("📦 Deploying mock AITBC token...");
const MockERC20 = await ethers.getContractFactory("MockERC20");
const aitbcToken = await MockERC20.deploy(
"AITBC Token",
"AITBC",
ethers.utils.parseEther("1000000")
);
await aitbcToken.deployed();
aitbcTokenAddress = aitbcToken.address;
deployedContracts.contracts.AITBCToken = {
address: aitbcTokenAddress,
deploymentHash: aitbcToken.deployTransaction.hash,
gasUsed: (await aitbcToken.deployTransaction.wait()).gasUsed.toString()
};
console.log(`✅ AITBC Token: ${aitbcTokenAddress}`);
}
// Deploy Mock Payment Processor if needed
if (!paymentProcessorAddress) {
console.log("📦 Deploying mock AITBC Payment Processor...");
const MockPaymentProcessor = await ethers.getContractFactory("AITBCPaymentProcessor");
const paymentProcessor = await MockPaymentProcessor.deploy(aitbcTokenAddress);
await paymentProcessor.deployed();
paymentProcessorAddress = paymentProcessor.address;
deployedContracts.contracts.AITBCPaymentProcessor = {
address: paymentProcessorAddress,
deploymentHash: paymentProcessor.deployTransaction.hash,
gasUsed: (await paymentProcessor.deployTransaction.wait()).gasUsed.toString()
};
console.log(`✅ Payment Processor: ${paymentProcessorAddress}`);
}
// Deploy CrossChainReputation contract
console.log("📦 Deploying CrossChainReputation contract...");
const CrossChainReputation = await ethers.getContractFactory("CrossChainReputation");
const crossChainReputation = await CrossChainReputation.deploy();
await crossChainReputation.deployed();
deployedContracts.contracts.CrossChainReputation = {
address: crossChainReputation.address,
deploymentHash: crossChainReputation.deployTransaction.hash,
gasUsed: (await crossChainReputation.deployTransaction.wait()).gasUsed.toString()
};
console.log(`✅ CrossChainReputation: ${crossChainReputation.address}`);
// Deploy AgentCommunication contract
console.log("📦 Deploying AgentCommunication contract...");
const AgentCommunication = await ethers.getContractFactory("AgentCommunication");
const agentCommunication = await AgentCommunication.deploy(crossChainReputation.address);
await agentCommunication.deployed();
deployedContracts.contracts.AgentCommunication = {
address: agentCommunication.address,
deploymentHash: agentCommunication.deployTransaction.hash,
gasUsed: (await agentCommunication.deployTransaction.wait()).gasUsed.toString()
};
console.log(`✅ AgentCommunication: ${agentCommunication.address}`);
// Deploy AgentCollaboration contract
console.log("📦 Deploying AgentCollaboration contract...");
const AgentCollaboration = await ethers.getContractFactory("AgentCollaboration");
const agentCollaboration = await AgentCollaboration.deploy(
aitbcTokenAddress,
crossChainReputation.address,
agentCommunication.address
);
await agentCollaboration.deployed();
deployedContracts.contracts.AgentCollaboration = {
address: agentCollaboration.address,
deploymentHash: agentCollaboration.deployTransaction.hash,
gasUsed: (await agentCollaboration.deployTransaction.wait()).gasUsed.toString()
};
console.log(`✅ AgentCollaboration: ${agentCollaboration.address}`);
// Deploy AgentLearning contract
console.log("📦 Deploying AgentLearning contract...");
const AgentLearning = await ethers.getContractFactory("AgentLearning");
const agentLearning = await AgentLearning.deploy(
crossChainReputation.address,
agentCollaboration.address
);
await agentLearning.deployed();
deployedContracts.contracts.AgentLearning = {
address: agentLearning.address,
deploymentHash: agentLearning.deployTransaction.hash,
gasUsed: (await agentLearning.deployTransaction.wait()).gasUsed.toString()
};
console.log(`✅ AgentLearning: ${agentLearning.address}`);
// Deploy AgentMarketplaceV2 contract
console.log("📦 Deploying AgentMarketplaceV2 contract...");
const AgentMarketplaceV2 = await ethers.getContractFactory("AgentMarketplaceV2");
const agentMarketplaceV2 = await AgentMarketplaceV2.deploy(
aitbcTokenAddress,
paymentProcessorAddress,
crossChainReputation.address,
agentCommunication.address,
agentCollaboration.address,
agentLearning.address
);
await agentMarketplaceV2.deployed();
deployedContracts.contracts.AgentMarketplaceV2 = {
address: agentMarketplaceV2.address,
deploymentHash: agentMarketplaceV2.deployTransaction.hash,
gasUsed: (await agentMarketplaceV2.deployTransaction.wait()).gasUsed.toString()
};
console.log(`✅ AgentMarketplaceV2: ${agentMarketplaceV2.address}`);
// Deploy ReputationNFT contract
console.log("📦 Deploying ReputationNFT contract...");
const ReputationNFT = await ethers.getContractFactory("ReputationNFT");
const reputationNFT = await ReputationNFT.deploy(
"AITBC Reputation NFT",
"AITBC-RNFT",
crossChainReputation.address
);
await reputationNFT.deployed();
deployedContracts.contracts.ReputationNFT = {
address: reputationNFT.address,
deploymentHash: reputationNFT.deployTransaction.hash,
gasUsed: (await reputationNFT.deployTransaction.wait()).gasUsed.toString()
};
console.log(`✅ ReputationNFT: ${reputationNFT.address}`);
// Initialize contracts
console.log("🔧 Initializing contracts...");
// Initialize CrossChainReputation
await crossChainReputation.updateGlobalSettings(
1000, // baseReputationScore
100, // successBonus
50, // failurePenalty
ethers.utils.parseEther("100"), // minStakeAmount
10000, // maxDelegationRatio (100%)
3600 // syncCooldown (1 hour)
);
console.log("✅ CrossChainReputation initialized");
// Initialize AgentCommunication
await agentCommunication.updateGlobalSettings(
1000, // minReputationScore
ethers.utils.parseEther("0.001"), // baseMessagePrice
100000, // maxMessageSize (100KB)
86400, // messageTimeout (24 hours)
2592000 // channelTimeout (30 days)
);
console.log("✅ AgentCommunication initialized");
// Authorize deployer as agent
await crossChainReputation.initializeReputation(deployer.address, 1000);
await agentCommunication.authorizeAgent(deployer.address);
await agentCollaboration.authorizeAgent(deployer.address);
await agentLearning.authorizeAgent(deployer.address);
console.log("✅ Deployer authorized as agent");
// Add supported chains to CrossChainReputation
await crossChainReputation.addSupportedChain(1, crossChainReputation.address); // Ethereum
await crossChainReputation.addSupportedChain(137, crossChainReputation.address); // Polygon
await crossChainReputation.addSupportedChain(42161, crossChainReputation.address); // Arbitrum
await crossChainReputation.addSupportedChain(10, crossChainReputation.address); // Optimism
console.log("✅ Supported chains added to CrossChainReputation");
// Save deployment information
const deploymentFile = `deployed-contracts-${hre.network.name}.json`;
// Load existing contracts if file exists
let existingContracts = {};
if (fs.existsSync(deploymentFile)) {
existingContracts = JSON.parse(fs.readFileSync(deploymentFile, 'utf8'));
}
// Merge with existing contracts
const allContracts = {
...existingContracts,
...deployedContracts
};
fs.writeFileSync(
path.join(__dirname, "..", deploymentFile),
JSON.stringify(allContracts, null, 2)
);
// Generate environment variables for frontend
const envVars = `
# AITBC Advanced Agent Features - ${hre.network.name.toUpperCase()}
# Generated on ${new Date().toISOString()}
# Advanced Contract Addresses
VITE_CROSS_CHAIN_REPUTATION_ADDRESS=${crossChainReputation.address}
VITE_AGENT_COMMUNICATION_ADDRESS=${agentCommunication.address}
VITE_AGENT_COLLABORATION_ADDRESS=${agentCollaboration.address}
VITE_AGENT_LEARNING_ADDRESS=${agentLearning.address}
VITE_AGENT_MARKETPLACE_V2_ADDRESS=${agentMarketplaceV2.address}
VITE_REPUTATION_NFT_ADDRESS=${reputationNFT.address}
# Network Configuration
VITE_NETWORK_NAME=${hre.network.name}
VITE_CHAIN_ID=${hre.network.config.chainId || 1}
VITE_RPC_URL=${hre.network.config.url || 'http://localhost:8545'}
# Advanced Features Configuration
VITE_MIN_REPUTATION_SCORE=1000
VITE_BASE_MESSAGE_PRICE=0.001
VITE_MAX_MESSAGE_SIZE=100000
VITE_MESSAGE_TIMEOUT=86400
VITE_CHANNEL_TIMEOUT=2592000
VITE_MAX_MODEL_SIZE=104857600
VITE_MAX_TRAINING_TIME=3600
VITE_DEFAULT_LEARNING_RATE=0.001
VITE_CONVERGENCE_THRESHOLD=0.001
VITE_SYNC_COOLDOWN=3600
VITE_MIN_STAKE_AMOUNT=100000000000000000000
VITE_MAX_DELEGATION_RATIO=1.0
`;
const envFile = path.join(__dirname, "..", "..", "apps", "marketplace-web", ".env.advanced-features");
fs.writeFileSync(envFile, envVars);
console.log("");
console.log("🎉 ADVANCED CONTRACTS DEPLOYMENT COMPLETED");
console.log("=====================================");
console.log(`Total gas used: ${calculateTotalGas(deployedContracts)}`);
console.log(`Deployment file: ${deploymentFile}`);
console.log(`Environment file: ${envFile}`);
console.log("");
console.log("📋 Contract Addresses:");
console.log(` CrossChainReputation: ${crossChainReputation.address}`);
console.log(` AgentCommunication: ${agentCommunication.address}`);
console.log(` AgentCollaboration: ${agentCollaboration.address}`);
console.log(` AgentLearning: ${agentLearning.address}`);
console.log(` AgentMarketplaceV2: ${agentMarketplaceV2.address}`);
console.log(` ReputationNFT: ${reputationNFT.address}`);
console.log("");
console.log("🔧 Next Steps:");
console.log(" 1. Verify contracts on Etherscan (if on testnet/mainnet)");
console.log(" 2. Initialize cross-chain reputation for agents");
console.log(" 3. Set up agent communication channels");
console.log(" 4. Configure advanced learning models");
console.log(" 5. Test agent collaboration protocols");
} catch (error) {
console.error("❌ Deployment failed:", error);
process.exit(1);
}
}
function calculateTotalGas(deployedContracts) {
let totalGas = 0;
for (const contract of Object.values(deployedContracts.contracts)) {
if (contract.gasUsed) {
totalGas += parseInt(contract.gasUsed);
}
}
return totalGas.toLocaleString();
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});

View File

@@ -0,0 +1,258 @@
const { ethers } = require("hardhat");
const fs = require("fs");
const path = require("path");
async function main() {
console.log("🚀 Deploying OpenClaw Autonomous Economics Contracts");
console.log("==============================================");
const [deployer] = await ethers.getSigners();
const balance = await deployer.getBalance();
console.log(`Deployer: ${deployer.address}`);
console.log(`Balance: ${ethers.utils.formatEther(balance)} ETH`);
if (balance.lt(ethers.utils.parseEther("1"))) {
throw new Error("Insufficient ETH balance. Minimum 1 ETH recommended for deployment.");
}
console.log("");
console.log("Proceeding with contract deployment...");
// Deployment configuration
const deployedContracts = {
network: hre.network.name,
deployer: deployer.address,
timestamp: new Date().toISOString(),
contracts: {}
};
try {
// Get existing contracts
let aitbcTokenAddress, paymentProcessorAddress, aiPowerRentalAddress;
try {
const existingContractsFile = `deployed-contracts-${hre.network.name}.json`;
if (fs.existsSync(existingContractsFile)) {
const existingContracts = JSON.parse(fs.readFileSync(existingContractsFile, 'utf8'));
aitbcTokenAddress = existingContracts.contracts.AITBCToken?.address;
paymentProcessorAddress = existingContracts.contracts.AITBCPaymentProcessor?.address;
aiPowerRentalAddress = existingContracts.contracts.AIPowerRental?.address;
}
} catch (error) {
console.log("Could not load existing contracts, deploying mock ones...");
}
// Deploy Mock ERC20 if needed
if (!aitbcTokenAddress) {
console.log("📦 Deploying mock AITBC token...");
const MockERC20 = await ethers.getContractFactory("MockERC20");
const aitbcToken = await MockERC20.deploy(
"AITBC Token",
"AITBC",
ethers.utils.parseEther("1000000")
);
await aitbcToken.deployed();
aitbcTokenAddress = aitbcToken.address;
deployedContracts.contracts.AITBCToken = {
address: aitbcTokenAddress,
deploymentHash: aitbcToken.deployTransaction.hash,
gasUsed: (await aitbcToken.deployTransaction.wait()).gasUsed.toString()
};
console.log(`✅ AITBC Token: ${aitbcTokenAddress}`);
}
// Deploy Mock Payment Processor if needed
if (!paymentProcessorAddress) {
console.log("📦 Deploying mock AITBC Payment Processor...");
const MockPaymentProcessor = await ethers.getContractFactory("AITBCPaymentProcessor");
const paymentProcessor = await MockPaymentProcessor.deploy(aitbcTokenAddress);
await paymentProcessor.deployed();
paymentProcessorAddress = paymentProcessor.address;
deployedContracts.contracts.AITBCPaymentProcessor = {
address: paymentProcessorAddress,
deploymentHash: paymentProcessor.deployTransaction.hash,
gasUsed: (await paymentProcessor.deployTransaction.wait()).gasUsed.toString()
};
console.log(`✅ Payment Processor: ${paymentProcessorAddress}`);
}
// Deploy AgentWallet contract
console.log("📦 Deploying AgentWallet contract...");
const AgentWallet = await ethers.getContractFactory("AgentWallet");
const agentWallet = await AgentWallet.deploy(
aitbcTokenAddress,
paymentProcessorAddress
);
await agentWallet.deployed();
deployedContracts.contracts.AgentWallet = {
address: agentWallet.address,
deploymentHash: agentWallet.deployTransaction.hash,
gasUsed: (await agentWallet.deployTransaction.wait()).gasUsed.toString()
};
console.log(`✅ AgentWallet: ${agentWallet.address}`);
// Deploy AgentOrchestration contract
console.log("📦 Deploying AgentOrchestration contract...");
const AgentOrchestration = await ethers.getContractFactory("AgentOrchestration");
const agentOrchestration = await AgentOrchestration.deploy();
await agentOrchestration.deployed();
deployedContracts.contracts.AgentOrchestration = {
address: agentOrchestration.address,
deploymentHash: agentOrchestration.deployTransaction.hash,
gasUsed: (await agentOrchestration.deployTransaction.wait()).gasUsed.toString()
};
console.log(`✅ AgentOrchestration: ${agentOrchestration.address}`);
// Deploy or extend AIPowerRental contract
if (!aiPowerRentalAddress) {
console.log("📦 Deploying AIPowerRental contract...");
const AIPowerRental = await ethers.getContractFactory("AIPowerRental");
const aiPowerRental = await AIPowerRental.deploy(
aitbcTokenAddress
);
await aiPowerRental.deployed();
aiPowerRentalAddress = aiPowerRental.address;
deployedContracts.contracts.AIPowerRental = {
address: aiPowerRentalAddress,
deploymentHash: aiPowerRental.deployTransaction.hash,
gasUsed: (await aiPowerRental.deployTransaction.wait()).gasUsed.toString()
};
console.log(`✅ AIPowerRental: ${aiPowerRentalAddress}`);
} else {
console.log(`📦 Using existing AIPowerRental: ${aiPowerRentalAddress}`);
deployedContracts.contracts.AIPowerRental = {
address: aiPowerRentalAddress,
note: "Existing contract - agent features added"
};
}
// Initialize contracts
console.log("🔧 Initializing contracts...");
// Authorize deployer as agent
await agentWallet.authorizeAgent(deployer.address, deployer.address);
console.log("✅ Authorized deployer as agent");
// Authorize deployer as provider
await agentWallet.authorizeProvider(deployer.address);
console.log("✅ Authorized deployer as provider");
// Authorize agent for AIPowerRental
const aiPowerRentalContract = await ethers.getContractAt("AIPowerRental", aiPowerRentalAddress);
await aiPowerRentalContract.authorizeAgent(deployer.address, deployer.address);
console.log("✅ Authorized agent for AIPowerRental");
// Authorize provider for AIPowerRental
await aiPowerRentalContract.authorizeProvider(deployer.address);
console.log("✅ Authorized provider for AIPowerRental");
// Save deployment information
const deploymentFile = `deployed-contracts-${hre.network.name}.json`;
// Load existing contracts if file exists
let existingContracts = {};
if (fs.existsSync(deploymentFile)) {
existingContracts = JSON.parse(fs.readFileSync(deploymentFile, 'utf8'));
}
// Merge with existing contracts
const allContracts = {
...existingContracts,
...deployedContracts
};
fs.writeFileSync(
path.join(__dirname, "..", deploymentFile),
JSON.stringify(allContracts, null, 2)
);
// Generate environment variables for frontend
const envVars = `
# AITBC OpenClaw Autonomous Economics - ${hre.network.name.toUpperCase()}
# Generated on ${new Date().toISOString()}
# Contract Addresses
VITE_AGENT_WALLET_ADDRESS=${agentWallet.address}
VITE_AGENT_ORCHESTRATION_ADDRESS=${agentOrchestration.address}
VITE_AI_POWER_RENTAL_ADDRESS=${aiPowerRentalAddress}
VITE_AITBC_TOKEN_ADDRESS=${aitbcTokenAddress}
VITE_PAYMENT_PROCESSOR_ADDRESS=${paymentProcessorAddress}
# Network Configuration
VITE_NETWORK_NAME=${hre.network.name}
VITE_CHAIN_ID=${hre.network.config.chainId || 1}
VITE_RPC_URL=${hre.network.config.url || 'http://localhost:8545'}
# Agent Configuration
VITE_DEFAULT_SPENDING_LIMIT=1000
VITE_MICRO_TRANSACTION_THRESHOLD=0.001
VITE_MIN_ALLOWANCE=10
VITE_MAX_ALLOWANCE=100000
# Bid Strategy Configuration
VITE_MARKET_WINDOW=24
VITE_PRICE_HISTORY_DAYS=30
VITE_VOLATILITY_THRESHOLD=0.15
VITE_MAX_CONCURRENT_PLANS=10
VITE_ASSIGNMENT_TIMEOUT=300
VITE_MONITORING_INTERVAL=30
VITE_RETRY_LIMIT=3
`;
const envFile = path.join(__dirname, "..", "..", "apps", "marketplace-web", ".env.agent-economics");
fs.writeFileSync(envFile, envVars);
console.log("");
console.log("🎉 CONTRACT DEPLOYMENT COMPLETED");
console.log("===============================");
console.log(`Total gas used: ${calculateTotalGas(deployedContracts)}`);
console.log(`Deployment file: ${deploymentFile}`);
console.log(`Environment file: ${envFile}`);
console.log("");
console.log("📋 Contract Addresses:");
console.log(` AgentWallet: ${agentWallet.address}`);
console.log(` AgentOrchestration: ${agentOrchestration.address}`);
console.log(` AIPowerRental: ${aiPowerRentalAddress}`);
console.log(` AITBC Token: ${aitbcTokenAddress}`);
console.log(` Payment Processor: ${paymentProcessorAddress}`);
console.log("");
console.log("🔧 Next Steps:");
console.log(" 1. Verify contracts on Etherscan (if on testnet/mainnet)");
console.log(" 2. Update frontend with new contract addresses");
console.log(" 3. Test agent wallet functionality");
console.log(" 4. Initialize bid strategy engine");
console.log(" 5. Set up agent orchestrator");
} catch (error) {
console.error("❌ Deployment failed:", error);
process.exit(1);
}
}
function calculateTotalGas(deployedContracts) {
let totalGas = 0;
for (const contract of Object.values(deployedContracts.contracts)) {
if (contract.gasUsed) {
totalGas += parseInt(contract.gasUsed);
}
}
return totalGas.toLocaleString();
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});

View File

@@ -0,0 +1,276 @@
const { ethers } = require("hardhat");
const fs = require("fs");
const path = require("path");
async function main() {
console.log("🚀 Deploying AITBC Developer Ecosystem Contracts");
console.log("==============================================");
const network = network.name;
const [deployer] = await ethers.getSigners();
console.log(`Deploying contracts to ${network} with account: ${deployer.address}`);
console.log(`Account balance: ${ethers.utils.formatEther(await deployer.getBalance())} ETH`);
console.log("");
// Deployed contracts storage
const deployedContracts = {
network: network,
deployer: deployer.address,
timestamp: new Date().toISOString(),
contracts: {}
};
try {
// Step 1: Deploy Mock AITBC Token (if not already deployed)
console.log("📦 Step 1: Deploying AITBC Token...");
const AITBCToken = await ethers.getContractFactory("MockERC20");
const aitbcToken = await AITBCToken.deploy("AITBC Token", "AITBC", ethers.utils.parseEther("1000000"));
await aitbcToken.deployed();
deployedContracts.contracts.AITBCToken = {
address: aitbcToken.address,
deploymentHash: aitbcToken.deployTransaction.hash
};
console.log(`✅ AITBC Token deployed to: ${aitbcToken.address}`);
console.log("");
// Step 2: Deploy Mock Verifiers
console.log("🔍 Step 2: Deploying Mock Verifiers...");
// Deploy Mock ZK Verifier
const MockZKVerifier = await ethers.getContractFactory("MockZKVerifier");
const zkVerifier = await MockZKVerifier.deploy();
await zkVerifier.deployed();
deployedContracts.contracts.ZKVerifier = {
address: zkVerifier.address,
deploymentHash: zkVerifier.deployTransaction.hash
};
console.log(`✅ ZK Verifier deployed to: ${zkVerifier.address}`);
// Deploy Mock Groth16 Verifier
const MockGroth16Verifier = await ethers.getContractFactory("MockGroth16Verifier");
const groth16Verifier = await MockGroth16Verifier.deploy();
await groth16Verifier.deployed();
deployedContracts.contracts.Groth16Verifier = {
address: groth16Verifier.address,
deploymentHash: groth16Verifier.deployTransaction.hash
};
console.log(`✅ Groth16 Verifier deployed to: ${groth16Verifier.address}`);
console.log("");
// Step 3: Deploy Core Developer Ecosystem Contracts
console.log("🎯 Step 3: Deploying Core Developer Ecosystem Contracts...");
// Deploy AgentBounty
const AgentBounty = await ethers.getContractFactory("AgentBounty");
const agentBounty = await AgentBounty.deploy(
aitbcToken.address,
zkVerifier.address,
groth16Verifier.address
);
await agentBounty.deployed();
deployedContracts.contracts.AgentBounty = {
address: agentBounty.address,
deploymentHash: agentBounty.deployTransaction.hash
};
console.log(`✅ AgentBounty deployed to: ${agentBounty.address}`);
// Deploy AgentStaking
const AgentStaking = await ethers.getContractFactory("AgentStaking");
const agentStaking = await AgentStaking.deploy(aitbcToken.address);
await agentStaking.deployed();
deployedContracts.contracts.AgentStaking = {
address: agentStaking.address,
deploymentHash: agentStaking.deployTransaction.hash
};
console.log(`✅ AgentStaking deployed to: ${agentStaking.address}`);
console.log("");
// Step 4: Deploy Supporting Contracts
console.log("🔧 Step 4: Deploying Supporting Contracts...");
// Deploy PerformanceVerifier
const PerformanceVerifier = await ethers.getContractFactory("PerformanceVerifier");
const performanceVerifier = await PerformanceVerifier.deploy(
zkVerifier.address,
groth16Verifier.address,
agentBounty.address
);
await performanceVerifier.deployed();
deployedContracts.contracts.PerformanceVerifier = {
address: performanceVerifier.address,
deploymentHash: performanceVerifier.deployTransaction.hash
};
console.log(`✅ PerformanceVerifier deployed to: ${performanceVerifier.address}`);
// Deploy DisputeResolution
const DisputeResolution = await ethers.getContractFactory("DisputeResolution");
const disputeResolution = await DisputeResolution.deploy(
agentBounty.address,
aitbcToken.address,
performanceVerifier.address
);
await disputeResolution.deployed();
deployedContracts.contracts.DisputeResolution = {
address: disputeResolution.address,
deploymentHash: disputeResolution.deployTransaction.hash
};
console.log(`✅ DisputeResolution deployed to: ${disputeResolution.address}`);
// Deploy EscrowService
const EscrowService = await ethers.getContractFactory("EscrowService");
const escrowService = await EscrowService.deploy(
aitbcToken.address,
agentBounty.address,
agentStaking.address
);
await escrowService.deployed();
deployedContracts.contracts.EscrowService = {
address: escrowService.address,
deploymentHash: escrowService.deployTransaction.hash
};
console.log(`✅ EscrowService deployed to: ${escrowService.address}`);
console.log("");
// Step 5: Initialize Contracts
console.log("⚙️ Step 5: Initializing Contracts...");
// Initialize AgentBounty with owner settings
await agentBounty.updateCreationFee(50); // 0.5%
await agentBounty.updateSuccessFee(200); // 2%
await agentBounty.updateDisputeFee(10); // 0.1%
await agentBounty.updatePlatformFee(100); // 1%
console.log("✅ AgentBounty initialized with fee settings");
// Initialize AgentStaking with performance recorder
await agentStaking.setPerformanceRecorder(deployer.address);
console.log("✅ AgentStaking initialized with performance recorder");
// Initialize PerformanceVerifier with settings
await performanceVerifier.setMinimumAccuracy(80); // 80% minimum accuracy
await performanceVerifier.setMaximumResponseTime(3600); // 1 hour max response time
console.log("✅ PerformanceVerifier initialized with performance thresholds");
console.log("");
// Step 6: Setup Contract Interactions
console.log("🔗 Step 6: Setting up Contract Interactions...");
// Transfer some tokens to the contracts for testing
const initialTokenAmount = ethers.utils.parseEther("10000");
await aitbcToken.transfer(agentBounty.address, initialTokenAmount);
await aitbcToken.transfer(escrowService.address, initialTokenAmount);
console.log("✅ Initial tokens transferred to contracts");
console.log("");
// Step 7: Save Deployment Information
console.log("💾 Step 7: Saving Deployment Information...");
const deploymentFile = `deployed-contracts-${network}.json`;
fs.writeFileSync(
path.join(__dirname, "..", deploymentFile),
JSON.stringify(deployedContracts, null, 2)
);
console.log(`✅ Deployment information saved to ${deploymentFile}`);
console.log("");
// Step 8: Generate Environment Variables
console.log("📝 Step 8: Generating Environment Variables...");
const envVars = `
# AITBC Developer Ecosystem - ${network.toUpperCase()} Deployment
# Generated on ${new Date().toISOString()}
# Contract Addresses
NEXT_PUBLIC_AITBC_TOKEN_ADDRESS=${aitbcToken.address}
NEXT_PUBLIC_AGENT_BOUNTY_ADDRESS=${agentBounty.address}
NEXT_PUBLIC_AGENT_STAKING_ADDRESS=${agentStaking.address}
NEXT_PUBLIC_PERFORMANCE_VERIFIER_ADDRESS=${performanceVerifier.address}
NEXT_PUBLIC_DISPUTE_RESOLUTION_ADDRESS=${disputeResolution.address}
NEXT_PUBLIC_ESCROW_SERVICE_ADDRESS=${escrowService.address}
NEXT_PUBLIC_ZK_VERIFIER_ADDRESS=${zkVerifier.address}
NEXT_PUBLIC_GROTH16_VERIFIER_ADDRESS=${groth16Verifier.address}
# Network Configuration
NEXT_PUBLIC_NETWORK_NAME=${network}
NEXT_PUBLIC_CHAIN_ID=${network.config.chainId}
NEXT_PUBLIC_RPC_URL=${network.config.url}
# Deployment Info
NEXT_PUBLIC_DEPLOYER_ADDRESS=${deployer.address}
NEXT_PUBLIC_DEPLOYMENT_TIMESTAMP=${new Date().toISOString()}
`;
const envFile = `.env.${network}`;
fs.writeFileSync(path.join(__dirname, "..", envFile), envVars);
console.log(`✅ Environment variables saved to ${envFile}`);
console.log("");
// Step 9: Display Deployment Summary
console.log("🎉 Deployment Summary");
console.log("===================");
console.log(`Network: ${network}`);
console.log(`Deployer: ${deployer.address}`);
console.log(`Total Contracts: ${Object.keys(deployedContracts.contracts).length}`);
console.log("");
console.log("Deployed Contracts:");
for (const [name, contract] of Object.entries(deployedContracts.contracts)) {
console.log(` ${name}: ${contract.address}`);
}
console.log("");
// Step 10: Verification Instructions
if (network !== "localhost" && network !== "hardhat") {
console.log("🔍 Contract Verification");
console.log("=======================");
console.log("To verify contracts on Etherscan, run:");
console.log(`npx hardhat run scripts/verify-contracts.js --network ${network}`);
console.log("");
}
// Step 11: Next Steps
console.log("📋 Next Steps");
console.log("=============");
console.log("1. Copy environment variables to frontend application");
console.log("2. Update API configuration with contract addresses");
console.log("3. Deploy frontend application");
console.log("4. Run integration tests");
console.log("5. Monitor contract operations");
console.log("");
print_success("🎉 Developer Ecosystem deployment completed successfully!");
} catch (error) {
console.error("❌ Deployment failed:", error);
process.exit(1);
}
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});

View File

@@ -0,0 +1,207 @@
#!/usr/bin/env bash
# AITBC Developer Ecosystem Deployment Script
# Deploys all smart contracts for the Developer Ecosystem & DAO Grants system
#
# Usage: ./deploy-developer-ecosystem.sh [network] [verify]
# Networks: localhost, sepolia, goerli, mainnet
# Verify: true/false - whether to verify contracts on Etherscan
set -euo pipefail
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
print_status() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Parse arguments
NETWORK="${1:-localhost}"
VERIFY_CONTRACTS="${2:-false}"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
CONTRACTS_DIR="$(dirname "$SCRIPT_DIR")"
ROOT_DIR="$(dirname "$CONTRACTS_DIR")"
echo "🚀 AITBC Developer Ecosystem Deployment"
echo "=========================================="
echo "Network: $NETWORK"
echo "Verify Contracts: $VERIFY_CONTRACTS"
echo "Contracts Directory: $CONTRACTS_DIR"
echo ""
# Check prerequisites
check_prerequisites() {
print_status "Checking prerequisites..."
# Check if hardhat is available
if ! command -v npx &>/dev/null; then
print_error "npx not found. Please install Node.js and npm."
exit 1
fi
# Check if we're in the contracts directory
if [[ ! -f "$CONTRACTS_DIR/hardhat.config.js" ]]; then
print_error "hardhat.config.js not found in $CONTRACTS_DIR"
exit 1
fi
# Check if .env file exists for network configuration
if [[ ! -f "$CONTRACTS_DIR/.env" ]]; then
print_warning ".env file not found. Creating template..."
cat > "$CONTRACTS_DIR/.env" << EOF
# Network Configuration
PRIVATE_KEY=your_private_key_here
INFURA_PROJECT_ID=your_infura_project_id
ETHERSCAN_API_KEY=your_etherscan_api_key
# Network URLs
SEPOLIA_URL=https://sepolia.infura.io/v3/\${INFURA_PROJECT_ID}
GOERLI_URL=https://goerli.infura.io/v3/\${INFURA_PROJECT_ID}
MAINNET_URL=https://mainnet.infura.io/v3/\${INFURA_PROJECT_ID}
EOF
print_warning "Please update .env file with your credentials"
fi
print_success "Prerequisites check completed"
}
# Compile contracts
compile_contracts() {
print_status "Compiling contracts..."
cd "$CONTRACTS_DIR"
if npx hardhat compile; then
print_success "Contracts compiled successfully"
else
print_error "Contract compilation failed"
exit 1
fi
}
# Deploy contracts
deploy_contracts() {
print_status "Deploying contracts to $NETWORK..."
cd "$CONTRACTS_DIR"
# Run deployment script
if npx hardhat run scripts/deploy-developer-ecosystem.js --network "$NETWORK"; then
print_success "Contracts deployed successfully"
else
print_error "Contract deployment failed"
exit 1
fi
}
# Verify contracts on Etherscan
verify_contracts() {
if [[ "$VERIFY_CONTRACTS" != "true" ]]; then
print_status "Contract verification skipped"
return
fi
if [[ "$NETWORK" == "localhost" || "$NETWORK" == "hardhat" ]]; then
print_status "Skipping verification for local network"
return
fi
print_status "Verifying contracts on Etherscan..."
cd "$CONTRACTS_DIR"
# Read deployed addresses from deployment output
if [[ -f "deployed-contracts-$NETWORK.json" ]]; then
# Verify each contract
npx hardhat run scripts/verify-contracts.js --network "$NETWORK"
print_success "Contract verification completed"
else
print_warning "No deployed contracts file found. Skipping verification."
fi
}
# Run post-deployment tests
run_post_deployment_tests() {
print_status "Running post-deployment tests..."
cd "$ROOT_DIR"
# Run contract tests
if npx hardhat test tests/contracts/ --network "$NETWORK"; then
print_success "Post-deployment tests passed"
else
print_error "Post-deployment tests failed"
exit 1
fi
}
# Generate deployment report
generate_deployment_report() {
print_status "Generating deployment report..."
local report_file="$ROOT_DIR/deployment-report-$NETWORK-$(date +%Y%m%d-%H%M%S).json"
cd "$CONTRACTS_DIR"
if [[ -f "deployed-contracts-$NETWORK.json" ]]; then
cp "deployed-contracts-$NETWORK.json" "$report_file"
print_success "Deployment report saved to $report_file"
else
print_warning "No deployment data found for report generation"
fi
}
# Main execution
main() {
print_status "Starting Developer Ecosystem deployment..."
# Check prerequisites
check_prerequisites
# Compile contracts
compile_contracts
# Deploy contracts
deploy_contracts
# Verify contracts (if requested)
verify_contracts
# Run post-deployment tests
run_post_deployment_tests
# Generate deployment report
generate_deployment_report
print_success "🎉 Developer Ecosystem deployment completed successfully!"
echo ""
echo "Next steps:"
echo "1. Update frontend environment variables with contract addresses"
echo "2. Deploy the frontend application"
echo "3. Configure API endpoints"
echo "4. Run integration tests"
}
# Handle script interruption
trap 'print_error "Deployment interrupted"; exit 1' INT TERM
# Run main function
main "$@"

View File

@@ -0,0 +1,100 @@
import hardhat from "hardhat";
const { ethers } = hardhat;
import fs from "fs";
async function main() {
console.log("🚀 Deploying AITBC Smart Contracts to Mainnet");
console.log("==============================================");
const [deployer] = await ethers.getSigners();
const balance = await ethers.provider.getBalance(deployer.address);
console.log(`Deployer: ${deployer.address}`);
console.log(`Balance: ${ethers.formatEther(balance)} ETH`);
if (balance < ethers.parseEther("1")) {
throw new Error("Insufficient ETH balance. Minimum 1 ETH recommended for deployment.");
}
console.log("");
console.log("Proceeding with contract deployment...");
// Deployment configuration
const deployedContracts = {
network: hardhat.network.name,
deployer: deployer.address,
timestamp: new Date().toISOString(),
contracts: {}
};
try {
// Deploy core contracts
console.log("📦 Deploying AgentWallet...");
const AgentWallet = await ethers.getContractFactory("AgentWallet");
const agentWallet = await AgentWallet.deploy();
await agentWallet.waitForDeployment();
const agentWalletAddr = await agentWallet.getAddress();
deployedContracts.contracts.AgentWallet = agentWalletAddr;
console.log(`✅ AgentWallet deployed: ${agentWalletAddr}`);
console.log("📦 Deploying AIPowerRental...");
const AIPowerRental = await ethers.getContractFactory("AIPowerRental");
const aiPowerRental = await AIPowerRental.deploy();
await aiPowerRental.waitForDeployment();
const aiPowerRentalAddr = await aiPowerRental.getAddress();
deployedContracts.contracts.AIPowerRental = aiPowerRentalAddr;
console.log(`✅ AIPowerRental deployed: ${aiPowerRentalAddr}`);
console.log("📦 Deploying AgentServiceMarketplace...");
const AgentServiceMarketplace = await ethers.getContractFactory("AgentServiceMarketplace");
const agentServiceMarketplace = await AgentServiceMarketplace.deploy();
await agentServiceMarketplace.waitForDeployment();
const agentServiceMarketplaceAddr = await agentServiceMarketplace.getAddress();
deployedContracts.contracts.AgentServiceMarketplace = agentServiceMarketplaceAddr;
console.log(`✅ AgentServiceMarketplace deployed: ${agentServiceMarketplaceAddr}`);
console.log("📦 Deploying DynamicPricing...");
const DynamicPricing = await ethers.getContractFactory("DynamicPricing");
const dynamicPricing = await DynamicPricing.deploy();
await dynamicPricing.waitForDeployment();
const dynamicPricingAddr = await dynamicPricing.getAddress();
deployedContracts.contracts.DynamicPricing = dynamicPricingAddr;
console.log(`✅ DynamicPricing deployed: ${dynamicPricingAddr}`);
console.log("📦 Deploying AgentStaking...");
const AgentStaking = await ethers.getContractFactory("AgentStaking");
const agentStaking = await AgentStaking.deploy();
await agentStaking.waitForDeployment();
const agentStakingAddr = await agentStaking.getAddress();
deployedContracts.contracts.AgentStaking = agentStakingAddr;
console.log(`✅ AgentStaking deployed: ${agentStakingAddr}`);
// Save deployment info
fs.writeFileSync("deployments.json", JSON.stringify(deployedContracts, null, 2));
console.log("");
console.log("🎉 Deployment Summary:");
console.log("====================");
console.log(`Network: ${deployedContracts.network}`);
console.log(`Deployer: ${deployedContracts.deployer}`);
console.log(`Timestamp: ${deployedContracts.timestamp}`);
console.log("");
console.log("Deployed Contracts:");
for (const [name, address] of Object.entries(deployedContracts.contracts)) {
console.log(` ${name}: ${address}`);
}
console.log("");
console.log("✅ All contracts deployed successfully!");
console.log("📁 Deployment saved to: deployments.json");
} catch (error) {
console.error("❌ Deployment failed:", error);
process.exitCode = 1;
}
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});

View File

@@ -0,0 +1,225 @@
const { ethers } = require("hardhat");
const fs = require("fs");
const path = require("path");
async function main() {
console.log("🚀 Deploying Decentralized Memory & Storage Contracts");
console.log("==============================================");
const [deployer] = await ethers.getSigners();
const balance = await deployer.getBalance();
console.log(`Deployer: ${deployer.address}`);
console.log(`Balance: ${ethers.utils.formatEther(balance)} ETH`);
if (balance.lt(ethers.utils.parseEther("1"))) {
throw new Error("Insufficient ETH balance. Minimum 1 ETH recommended for deployment.");
}
console.log("");
console.log("Proceeding with contract deployment...");
// Deployment configuration
const deployedContracts = {
network: hre.network.name,
deployer: deployer.address,
timestamp: new Date().toISOString(),
contracts: {}
};
try {
// Deploy AgentMemory contract
console.log("📦 Deploying AgentMemory contract...");
const AgentMemory = await ethers.getContractFactory("AgentMemory");
const agentMemory = await AgentMemory.deploy();
await agentMemory.deployed();
deployedContracts.contracts.AgentMemory = {
address: agentMemory.address,
deploymentHash: agentMemory.deployTransaction.hash,
gasUsed: (await agentMemory.deployTransaction.wait()).gasUsed.toString()
};
console.log(`✅ AgentMemory: ${agentMemory.address}`);
// Deploy MemoryVerifier contract
console.log("📦 Deploying MemoryVerifier contract...");
const ZKReceiptVerifier = await ethers.getContractFactory("ZKReceiptVerifier");
const zkVerifier = await ZKReceiptVerifier.deploy();
await zkVerifier.deployed();
const MemoryVerifier = await ethers.getContractFactory("MemoryVerifier", {
libraries: {
ZKReceiptVerifier: zkVerifier.address
}
});
const memoryVerifier = await MemoryVerifier.deploy(zkVerifier.address);
await memoryVerifier.deployed();
deployedContracts.contracts.MemoryVerifier = {
address: memoryVerifier.address,
deploymentHash: memoryVerifier.deployTransaction.hash,
gasUsed: (await memoryVerifier.deployTransaction.wait()).gasUsed.toString()
};
console.log(`✅ MemoryVerifier: ${memoryVerifier.address}`);
// Deploy KnowledgeGraphMarket contract
console.log("📦 Deploying KnowledgeGraphMarket contract...");
// Get existing AITBCPaymentProcessor address or deploy a mock one
let paymentProcessorAddress;
let aitbcTokenAddress;
try {
// Try to get existing payment processor
const paymentProcessorFile = `deployed-contracts-${hre.network.name}.json`;
if (fs.existsSync(paymentProcessorFile)) {
const existingContracts = JSON.parse(fs.readFileSync(paymentProcessorFile, 'utf8'));
paymentProcessorAddress = existingContracts.contracts.AITBCPaymentProcessor?.address;
aitbcTokenAddress = existingContracts.contracts.AITBCToken?.address;
}
} catch (error) {
console.log("Could not load existing contracts, deploying mock ones...");
}
// Deploy mock AITBC token if needed
if (!aitbcTokenAddress) {
console.log("📦 Deploying mock AITBC token...");
const MockERC20 = await ethers.getContractFactory("MockERC20");
const aitbcToken = await MockERC20.deploy(
"AITBC Token",
"AITBC",
ethers.utils.parseEther("1000000")
);
await aitbcToken.deployed();
aitbcTokenAddress = aitbcToken.address;
deployedContracts.contracts.AITBCToken = {
address: aitbcTokenAddress,
deploymentHash: aitbcToken.deployTransaction.hash,
gasUsed: (await aitbcToken.deployTransaction.wait()).gasUsed.toString()
};
console.log(`✅ AITBC Token: ${aitbcTokenAddress}`);
}
// Deploy mock payment processor if needed
if (!paymentProcessorAddress) {
console.log("📦 Deploying mock AITBC Payment Processor...");
const MockPaymentProcessor = await ethers.getContractFactory("AITBCPaymentProcessor");
const paymentProcessor = await MockPaymentProcessor.deploy(aitbcTokenAddress);
await paymentProcessor.deployed();
paymentProcessorAddress = paymentProcessor.address;
deployedContracts.contracts.AITBCPaymentProcessor = {
address: paymentProcessorAddress,
deploymentHash: paymentProcessor.deployTransaction.hash,
gasUsed: (await paymentProcessor.deployTransaction.wait()).gasUsed.toString()
};
console.log(`✅ Payment Processor: ${paymentProcessorAddress}`);
}
// Deploy KnowledgeGraphMarket
const KnowledgeGraphMarket = await ethers.getContractFactory("KnowledgeGraphMarket");
const knowledgeGraphMarket = await KnowledgeGraphMarket.deploy(
paymentProcessorAddress,
aitbcTokenAddress
);
await knowledgeGraphMarket.deployed();
deployedContracts.contracts.KnowledgeGraphMarket = {
address: knowledgeGraphMarket.address,
deploymentHash: knowledgeGraphMarket.deployTransaction.hash,
gasUsed: (await knowledgeGraphMarket.deployTransaction.wait()).gasUsed.toString()
};
console.log(`✅ KnowledgeGraphMarket: ${knowledgeGraphMarket.address}`);
// Initialize contracts
console.log("🔧 Initializing contracts...");
// Authorize deployer as memory verifier
await memoryVerifier.authorizeVerifier(deployer.address, 100000, 300);
console.log("✅ Authorized deployer as memory verifier");
// Save deployment information
const deploymentFile = `deployed-contracts-${hre.network.name}.json`;
fs.writeFileSync(
path.join(__dirname, "..", deploymentFile),
JSON.stringify(deployedContracts, null, 2)
);
// Generate environment variables for frontend
const envVars = `
# AITBC Decentralized Memory & Storage - ${hre.network.name.toUpperCase()}
# Generated on ${new Date().toISOString()}
# Contract Addresses
VITE_AGENT_MEMORY_ADDRESS=${agentMemory.address}
VITE_MEMORY_VERIFIER_ADDRESS=${memoryVerifier.address}
VITE_KNOWLEDGE_GRAPH_MARKET_ADDRESS=${knowledgeGraphMarket.address}
VITE_AITBC_TOKEN_ADDRESS=${aitbcTokenAddress}
VITE_PAYMENT_PROCESSOR_ADDRESS=${paymentProcessorAddress}
# Network Configuration
VITE_NETWORK_NAME=${hre.network.name}
VITE_CHAIN_ID=${hre.network.config.chainId || 1}
VITE_RPC_URL=${hre.network.config.url || 'http://localhost:8545'}
# IPFS Configuration
VITE_IPFS_URL=http://localhost:5001
VITE_IPFS_GATEWAY_URL=http://localhost:8080/ipfs/
# Memory Configuration
VITE_MEMORY_UPLOAD_THRESHOLD=100
VITE_MEMORY_BATCH_SIZE=50
VITE_MEMORY_EXPIRY_DAYS=30
`;
const envFile = path.join(__dirname, "..", "..", "apps", "marketplace-web", ".env.memory");
fs.writeFileSync(envFile, envVars);
console.log("");
console.log("🎉 CONTRACT DEPLOYMENT COMPLETED");
console.log("===============================");
console.log(`Total gas used: ${calculateTotalGas(deployedContracts)}`);
console.log(`Deployment file: ${deploymentFile}`);
console.log(`Environment file: ${envFile}`);
console.log("");
console.log("📋 Contract Addresses:");
console.log(` AgentMemory: ${agentMemory.address}`);
console.log(` MemoryVerifier: ${memoryVerifier.address}`);
console.log(` KnowledgeGraphMarket: ${knowledgeGraphMarket.address}`);
console.log(` AITBC Token: ${aitbcTokenAddress}`);
console.log(` Payment Processor: ${paymentProcessorAddress}`);
console.log("");
console.log("🔧 Next Steps:");
console.log(" 1. Verify contracts on Etherscan (if on testnet/mainnet)");
console.log(" 2. Update frontend with new contract addresses");
console.log(" 3. Test contract functionality");
console.log(" 4. Set up IPFS node for storage");
} catch (error) {
console.error("❌ Deployment failed:", error);
process.exit(1);
}
}
function calculateTotalGas(deployedContracts) {
let totalGas = 0;
for (const contract of Object.values(deployedContracts.contracts)) {
if (contract.gasUsed) {
totalGas += parseInt(contract.gasUsed);
}
}
return totalGas.toLocaleString();
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});

View File

@@ -0,0 +1,216 @@
const { ethers } = require("hardhat");
const fs = require("fs");
const path = require("path");
async function main() {
console.log("🔍 Verifying OpenClaw Autonomous Economics Contracts");
console.log("==============================================");
const networkName = hre.network.name;
const deploymentFile = `deployed-contracts-${networkName}.json`;
// Check if deployment file exists
if (!fs.existsSync(deploymentFile)) {
console.error(`❌ Deployment file not found: ${deploymentFile}`);
console.log("Please run the deployment script first.");
process.exit(1);
}
// Load deployment information
const deployedContracts = JSON.parse(fs.readFileSync(deploymentFile, 'utf8'));
console.log(`Network: ${networkName}`);
console.log(`Deployer: ${deployedContracts.deployer}`);
console.log(`Timestamp: ${deployedContracts.timestamp}`);
console.log("");
// Check if Etherscan API key is configured
const etherscanApiKey = process.env.ETHERSCAN_API_KEY;
if (!etherscanApiKey) {
console.warn("⚠️ ETHERSCAN_API_KEY not configured");
console.log("Set ETHERSCAN_API_KEY in your .env file for automatic verification");
console.log("Skipping verification...");
return;
}
const contracts = [
{
name: "AgentWallet",
address: deployedContracts.contracts.AgentWallet?.address,
constructorArgs: [
deployedContracts.contracts.AITBCToken?.address,
deployedContracts.contracts.AITBCPaymentProcessor?.address
]
},
{
name: "AgentOrchestration",
address: deployedContracts.contracts.AgentOrchestration?.address,
constructorArgs: []
},
{
name: "AIPowerRental",
address: deployedContracts.contracts.AIPowerRental?.address,
constructorArgs: [
deployedContracts.contracts.AITBCToken?.address
]
},
{
name: "AITBCToken",
address: deployedContracts.contracts.AITBCToken?.address,
constructorArgs: [
"AITBC Token",
"AITBC",
"1000000000000000000000000"
]
},
{
name: "AITBCPaymentProcessor",
address: deployedContracts.contracts.AITBCPaymentProcessor?.address,
constructorArgs: [
deployedContracts.contracts.AITBCToken?.address
]
}
];
console.log(`Found ${contracts.length} contracts to verify`);
console.log("");
let verificationResults = {
verified: [],
failed: [],
skipped: []
};
for (const contract of contracts) {
if (!contract.address) {
console.log(`⏭️ Skipping ${contract.name} - no address found`);
verificationResults.skipped.push({
name: contract.name,
reason: "No address found"
});
continue;
}
console.log(`🔍 Verifying ${contract.name} at ${contract.address}...`);
try {
// Wait for a few seconds to ensure the contract is properly deployed
await new Promise(resolve => setTimeout(resolve, 5000));
// Verify the contract
await hre.run("verify:verify", {
address: contract.address,
constructorArgs: contract.constructorArgs
});
console.log(`${contract.name} verified successfully`);
verificationResults.verified.push({
name: contract.name,
address: contract.address,
etherscanUrl: `https://${networkName === "mainnet" ? "" : networkName + "."}etherscan.io/address/${contract.address}`
});
} catch (error) {
console.error(`❌ Failed to verify ${contract.name}:`, error.message);
// Check if it's already verified
if (error.message.includes("Already Verified") || error.message.includes("already verified")) {
console.log(`${contract.name} is already verified`);
verificationResults.verified.push({
name: contract.name,
address: contract.address,
etherscanUrl: `https://${networkName === "mainnet" ? "" : networkName + "."}etherscan.io/address/${contract.address}`,
alreadyVerified: true
});
} else {
verificationResults.failed.push({
name: contract.name,
address: contract.address,
error: error.message
});
}
}
// Add delay between verifications to avoid rate limiting
await new Promise(resolve => setTimeout(resolve, 3000));
}
console.log("");
console.log("🎉 VERIFICATION SUMMARY");
console.log("=======================");
console.log(`✅ Verified: ${verificationResults.verified.length}`);
console.log(`❌ Failed: ${verificationResults.failed.length}`);
console.log(`⏭️ Skipped: ${verificationResults.skipped.length}`);
console.log("");
// Show verification results
if (verificationResults.verified.length > 0) {
console.log("✅ Successfully Verified Contracts:");
verificationResults.verified.forEach(contract => {
const status = contract.alreadyVerified ? "(Already Verified)" : "";
console.log(` ${contract.name}: ${contract.etherscanUrl} ${status}`);
});
}
if (verificationResults.failed.length > 0) {
console.log("");
console.log("❌ Failed Verifications:");
verificationResults.failed.forEach(contract => {
console.log(` ${contract.name}: ${contract.error}`);
});
console.log("");
console.log("💡 Tips for failed verifications:");
console.log(" 1. Wait a few minutes and try again");
console.log(" 2. Check if the contract address is correct");
console.log(" 3. Verify constructor arguments match exactly");
console.log(" 4. Check Etherscan API rate limits");
}
if (verificationResults.skipped.length > 0) {
console.log("");
console.log("⏭️ Skipped Contracts:");
verificationResults.skipped.forEach(contract => {
console.log(` ${contract.name}: ${contract.reason}`);
});
}
// Save verification results
const verificationReport = {
timestamp: new Date().toISOString(),
network: networkName,
results: verificationResults,
summary: {
total: contracts.length,
verified: verificationResults.verified.length,
failed: verificationResults.failed.length,
skipped: verificationResults.skipped.length
}
};
const reportFile = `agent-contract-verification-${networkName}-${Date.now()}.json`;
fs.writeFileSync(
path.join(__dirname, "..", reportFile),
JSON.stringify(verificationReport, null, 2)
);
console.log(`📄 Verification report saved to: ${reportFile}`);
// Return appropriate exit code
if (verificationResults.failed.length > 0) {
console.log("");
console.log("⚠️ Some contracts failed verification");
console.log("Please check the errors above and try manual verification if needed");
process.exit(1);
} else {
console.log("");
console.log("🎉 All contracts verified successfully!");
process.exit(0);
}
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});

View File

@@ -0,0 +1,182 @@
const { ethers } = require("hardhat");
const fs = require("fs");
const path = require("path");
async function main() {
console.log("🔍 Verifying AITBC Developer Ecosystem Contracts");
console.log("==============================================");
const network = network.name;
if (network === "localhost" || network === "hardhat") {
console.log("⏭️ Skipping verification for local network");
return;
}
// Read deployed contracts
const deploymentFile = `deployed-contracts-${network}.json`;
const deploymentPath = path.join(__dirname, "..", deploymentFile);
if (!fs.existsSync(deploymentPath)) {
console.error(`❌ Deployment file not found: ${deploymentFile}`);
process.exit(1);
}
const deployedContracts = JSON.parse(fs.readFileSync(deploymentPath, "utf8"));
console.log(`Network: ${network}`);
console.log(`Contracts to verify: ${Object.keys(deployedContracts.contracts).length}`);
console.log("");
const verificationResults = {
verified: [],
failed: [],
skipped: []
};
// Verification configurations for each contract
const verificationConfigs = {
AITBCToken: {
constructorArguments: ["AITBC Token", "AITBC", ethers.utils.parseEther("1000000")]
},
ZKVerifier: {
constructorArguments: []
},
Groth16Verifier: {
constructorArguments: []
},
AgentBounty: {
constructorArguments: [
deployedContracts.contracts.AITBCToken.address,
deployedContracts.contracts.ZKVerifier.address,
deployedContracts.contracts.Groth16Verifier.address
]
},
AgentStaking: {
constructorArguments: [deployedContracts.contracts.AITBCToken.address]
},
PerformanceVerifier: {
constructorArguments: [
deployedContracts.contracts.ZKVerifier.address,
deployedContracts.contracts.Groth16Verifier.address,
deployedContracts.contracts.AgentBounty.address
]
},
DisputeResolution: {
constructorArguments: [
deployedContracts.contracts.AgentBounty.address,
deployedContracts.contracts.AITBCToken.address,
deployedContracts.contracts.PerformanceVerifier.address
]
},
EscrowService: {
constructorArguments: [
deployedContracts.contracts.AITBCToken.address,
deployedContracts.contracts.AgentBounty.address,
deployedContracts.contracts.AgentStaking.address
]
}
};
// Verify each contract
for (const [contractName, contractInfo] of Object.entries(deployedContracts.contracts)) {
console.log(`🔍 Verifying ${contractName}...`);
try {
const config = verificationConfigs[contractName];
if (!config) {
console.log(`⏭️ Skipping ${contractName} (no verification config)`);
verificationResults.skipped.push(contractName);
continue;
}
// Wait for a few block confirmations
console.log(`⏳ Waiting for block confirmations...`);
await ethers.provider.waitForTransaction(contractInfo.deploymentHash, 3);
// Verify contract
await hre.run("verify:verify", {
address: contractInfo.address,
constructorArguments: config.constructorArguments
});
console.log(`${contractName} verified successfully`);
verificationResults.verified.push(contractName);
} catch (error) {
if (error.message.includes("Already Verified")) {
console.log(`${contractName} already verified`);
verificationResults.verified.push(contractName);
} else {
console.log(`${contractName} verification failed: ${error.message}`);
verificationResults.failed.push({
contract: contractName,
error: error.message
});
}
}
// Add delay between verifications to avoid rate limiting
await new Promise(resolve => setTimeout(resolve, 2000));
}
console.log("");
console.log("📊 Verification Summary");
console.log("======================");
console.log(`Verified: ${verificationResults.verified.length}`);
console.log(`Failed: ${verificationResults.failed.length}`);
console.log(`Skipped: ${verificationResults.skipped.length}`);
console.log("");
if (verificationResults.verified.length > 0) {
console.log("✅ Verified Contracts:");
verificationResults.verified.forEach(name => {
console.log(` - ${name}: ${deployedContracts.contracts[name].address}`);
});
console.log("");
}
if (verificationResults.failed.length > 0) {
console.log("❌ Failed Verifications:");
verificationResults.failed.forEach(({ contract, error }) => {
console.log(` - ${contract}: ${error}`);
});
console.log("");
}
if (verificationResults.skipped.length > 0) {
console.log("⏭️ Skipped Verifications:");
verificationResults.skipped.forEach(name => {
console.log(` - ${name}`);
});
console.log("");
}
// Save verification results
const verificationResultsFile = `verification-results-${network}.json`;
fs.writeFileSync(
path.join(__dirname, "..", verificationResultsFile),
JSON.stringify({
network: network,
timestamp: new Date().toISOString(),
results: verificationResults
}, null, 2)
);
console.log(`📄 Verification results saved to ${verificationResultsFile}`);
console.log("");
if (verificationResults.failed.length > 0) {
console.log("⚠️ Some contracts failed verification. Check the logs above.");
process.exit(1);
} else {
console.log("🎉 All contracts verified successfully!");
}
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});

View File

@@ -0,0 +1,216 @@
const { ethers } = require("hardhat");
const fs = require("fs");
const path = require("path");
async function main() {
console.log("🔍 Verifying Decentralized Memory & Storage Contracts");
console.log("==============================================");
const networkName = hre.network.name;
const deploymentFile = `deployed-contracts-${networkName}.json`;
// Check if deployment file exists
if (!fs.existsSync(deploymentFile)) {
console.error(`❌ Deployment file not found: ${deploymentFile}`);
console.log("Please run the deployment script first.");
process.exit(1);
}
// Load deployment information
const deployedContracts = JSON.parse(fs.readFileSync(deploymentFile, 'utf8'));
console.log(`Network: ${networkName}`);
console.log(`Deployer: ${deployedContracts.deployer}`);
console.log(`Timestamp: ${deployedContracts.timestamp}`);
console.log("");
// Check if Etherscan API key is configured
const etherscanApiKey = process.env.ETHERSCAN_API_KEY;
if (!etherscanApiKey) {
console.warn("⚠️ ETHERSCAN_API_KEY not configured");
console.log("Set ETHERSCAN_API_KEY in your .env file for automatic verification");
console.log("Skipping verification...");
return;
}
const contracts = [
{
name: "AgentMemory",
address: deployedContracts.contracts.AgentMemory?.address,
constructorArgs: []
},
{
name: "MemoryVerifier",
address: deployedContracts.contracts.MemoryVerifier?.address,
constructorArgs: [
deployedContracts.contracts.ZKReceiptVerifier?.address
]
},
{
name: "KnowledgeGraphMarket",
address: deployedContracts.contracts.KnowledgeGraphMarket?.address,
constructorArgs: [
deployedContracts.contracts.AITBCPaymentProcessor?.address,
deployedContracts.contracts.AITBCToken?.address
]
},
{
name: "AITBCToken",
address: deployedContracts.contracts.AITBCToken?.address,
constructorArgs: [
"AITBC Token",
"AITBC",
"1000000000000000000000000"
]
},
{
name: "AITBCPaymentProcessor",
address: deployedContracts.contracts.AITBCPaymentProcessor?.address,
constructorArgs: [
deployedContracts.contracts.AITBCToken?.address
]
}
];
console.log(`Found ${contracts.length} contracts to verify`);
console.log("");
let verificationResults = {
verified: [],
failed: [],
skipped: []
};
for (const contract of contracts) {
if (!contract.address) {
console.log(`⏭️ Skipping ${contract.name} - no address found`);
verificationResults.skipped.push({
name: contract.name,
reason: "No address found"
});
continue;
}
console.log(`🔍 Verifying ${contract.name} at ${contract.address}...`);
try {
// Wait for a few seconds to ensure the contract is properly deployed
await new Promise(resolve => setTimeout(resolve, 5000));
// Verify the contract
await hre.run("verify:verify", {
address: contract.address,
constructorArgs: contract.constructorArgs
});
console.log(`${contract.name} verified successfully`);
verificationResults.verified.push({
name: contract.name,
address: contract.address,
etherscanUrl: `https://${networkName === "mainnet" ? "" : networkName + "."}etherscan.io/address/${contract.address}`
});
} catch (error) {
console.error(`❌ Failed to verify ${contract.name}:`, error.message);
// Check if it's already verified
if (error.message.includes("Already Verified") || error.message.includes("already verified")) {
console.log(`${contract.name} is already verified`);
verificationResults.verified.push({
name: contract.name,
address: contract.address,
etherscanUrl: `https://${networkName === "mainnet" ? "" : networkName + "."}etherscan.io/address/${contract.address}`,
alreadyVerified: true
});
} else {
verificationResults.failed.push({
name: contract.name,
address: contract.address,
error: error.message
});
}
}
// Add delay between verifications to avoid rate limiting
await new Promise(resolve => setTimeout(resolve, 3000));
}
console.log("");
console.log("🎉 VERIFICATION SUMMARY");
console.log("======================");
console.log(`✅ Verified: ${verificationResults.verified.length}`);
console.log(`❌ Failed: ${verificationResults.failed.length}`);
console.log(`⏭️ Skipped: ${verificationResults.skipped.length}`);
console.log("");
// Show verification results
if (verificationResults.verified.length > 0) {
console.log("✅ Successfully Verified Contracts:");
verificationResults.verified.forEach(contract => {
const status = contract.alreadyVerified ? "(Already Verified)" : "";
console.log(` ${contract.name}: ${contract.etherscanUrl} ${status}`);
});
}
if (verificationResults.failed.length > 0) {
console.log("");
console.log("❌ Failed Verifications:");
verificationResults.failed.forEach(contract => {
console.log(` ${contract.name}: ${contract.error}`);
});
console.log("");
console.log("💡 Tips for failed verifications:");
console.log(" 1. Wait a few minutes and try again");
console.log(" 2. Check if the contract address is correct");
console.log(" 3. Verify constructor arguments match exactly");
console.log(" 4. Check Etherscan API rate limits");
}
if (verificationResults.skipped.length > 0) {
console.log("");
console.log("⏭️ Skipped Contracts:");
verificationResults.skipped.forEach(contract => {
console.log(` ${contract.name}: ${contract.reason}`);
});
}
// Save verification results
const verificationReport = {
timestamp: new Date().toISOString(),
network: networkName,
results: verificationResults,
summary: {
total: contracts.length,
verified: verificationResults.verified.length,
failed: verificationResults.failed.length,
skipped: verificationResults.skipped.length
}
};
const reportFile = `memory-contract-verification-${networkName}-${Date.now()}.json`;
fs.writeFileSync(
path.join(__dirname, "..", reportFile),
JSON.stringify(verificationReport, null, 2)
);
console.log(`📄 Verification report saved to: ${reportFile}`);
// Return appropriate exit code
if (verificationResults.failed.length > 0) {
console.log("");
console.log("⚠️ Some contracts failed verification");
console.log("Please check the errors above and try manual verification if needed");
process.exit(1);
} else {
console.log("");
console.log("🎉 All contracts verified successfully!");
process.exit(0);
}
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});