chore(systemd): remove obsolete systemd service files and update infrastructure documentation

- Remove 8 unused systemd service files from coordinator-api/systemd/
  - aitbc-adaptive-learning.service (port 8005)
  - aitbc-advanced-ai.service
  - aitbc-enterprise-api.service
  - aitbc-gpu-multimodal.service (port 8003)
  - aitbc-marketplace-enhanced.service (port 8006)
  - aitbc-modality-optimization.service (port 8004)
  - aitbc-multimodal.service (port 8002)
  - aitbc-openclaw-enhanced.service (port 8007
This commit is contained in:
oib
2026-03-04 12:16:50 +01:00
parent 581309369d
commit 50954a4b31
101 changed files with 1655 additions and 4871 deletions

View File

@@ -0,0 +1,73 @@
#!/bin/bash
echo "=== AITBC Smart Contract Compilation ==="
# Check if solc is installed
if ! command -v solc &> /dev/null; then
echo "Error: solc (Solidity compiler) not found"
echo "Please install solc: npm install -g solc"
exit 1
fi
# Create artifacts directory
mkdir -p artifacts
mkdir -p cache
# Contract files to compile
contracts=(
"contracts/AIPowerRental.sol"
"contracts/AITBCPaymentProcessor.sol"
"contracts/PerformanceVerifier.sol"
"contracts/DisputeResolution.sol"
"contracts/EscrowService.sol"
"contracts/DynamicPricing.sol"
"test/contracts/MockERC20.sol"
"test/contracts/MockZKVerifier.sol"
"test/contracts/MockGroth16Verifier.sol"
)
echo "Compiling contracts..."
# Compile each contract
for contract in "${contracts[@]}"; do
if [ -f "$contract" ]; then
echo "Compiling $contract..."
# Extract contract name from file path
contract_name=$(basename "$contract" .sol)
# Compile with solc
solc --bin --abi --optimize --output-dir artifacts \
--base-path . \
--include-path node_modules/@openzeppelin/contracts/node_modules/@openzeppelin/contracts \
"$contract"
if [ $? -eq 0 ]; then
echo "$contract_name compiled successfully"
else
echo "$contract_name compilation failed"
exit 1
fi
else
echo "⚠️ Contract file not found: $contract"
fi
done
echo ""
echo "=== Compilation Summary ==="
echo "✅ All contracts compiled successfully"
echo "📁 Artifacts saved to: artifacts/"
echo "📋 ABI files available for integration"
# List compiled artifacts
echo ""
echo "Compiled artifacts:"
ls -la artifacts/*.bin 2>/dev/null | wc -l | xargs echo "Binary files:"
ls -la artifacts/*.abi 2>/dev/null | wc -l | xargs echo "ABI files:"
echo ""
echo "=== Next Steps ==="
echo "1. Review compilation artifacts"
echo "2. Run integration tests"
echo "3. Deploy to testnet"
echo "4. Perform security audit"

View File

@@ -0,0 +1,173 @@
const { ethers } = require("hardhat");
async function main() {
console.log("=== AITBC Smart Contract Deployment ===");
// Get deployer account
const [deployer] = await ethers.getSigners();
console.log("Deploying contracts with the account:", deployer.address);
console.log("Account balance:", (await deployer.getBalance()).toString());
// Deployment addresses (to be replaced with actual addresses)
const AITBC_TOKEN_ADDRESS = process.env.AITBC_TOKEN_ADDRESS || "0x0000000000000000000000000000000000000000";
const ZK_VERIFIER_ADDRESS = process.env.ZK_VERIFIER_ADDRESS || "0x0000000000000000000000000000000000000000";
const GROTH16_VERIFIER_ADDRESS = process.env.GROTH16_VERIFIER_ADDRESS || "0x0000000000000000000000000000000000000000";
try {
// 1. Deploy AI Power Rental Contract
console.log("\n1. Deploying AIPowerRental...");
const AIPowerRental = await ethers.getContractFactory("AIPowerRental");
const aiPowerRental = await AIPowerRental.deploy(
AITBC_TOKEN_ADDRESS,
ZK_VERIFIER_ADDRESS,
GROTH16_VERIFIER_ADDRESS
);
await aiPowerRental.deployed();
console.log("AIPowerRental deployed to:", aiPowerRental.address);
// 2. Deploy AITBC Payment Processor
console.log("\n2. Deploying AITBCPaymentProcessor...");
const AITBCPaymentProcessor = await ethers.getContractFactory("AITBCPaymentProcessor");
const paymentProcessor = await AITBCPaymentProcessor.deploy(
AITBC_TOKEN_ADDRESS,
aiPowerRental.address
);
await paymentProcessor.deployed();
console.log("AITBCPaymentProcessor deployed to:", paymentProcessor.address);
// 3. Deploy Performance Verifier
console.log("\n3. Deploying PerformanceVerifier...");
const PerformanceVerifier = await ethers.getContractFactory("PerformanceVerifier");
const performanceVerifier = await PerformanceVerifier.deploy(
ZK_VERIFIER_ADDRESS,
GROTH16_VERIFIER_ADDRESS,
aiPowerRental.address
);
await performanceVerifier.deployed();
console.log("PerformanceVerifier deployed to:", performanceVerifier.address);
// 4. Deploy Dispute Resolution
console.log("\n4. Deploying DisputeResolution...");
const DisputeResolution = await ethers.getContractFactory("DisputeResolution");
const disputeResolution = await DisputeResolution.deploy(
aiPowerRental.address,
paymentProcessor.address,
performanceVerifier.address
);
await disputeResolution.deployed();
console.log("DisputeResolution deployed to:", disputeResolution.address);
// 5. Deploy Escrow Service
console.log("\n5. Deploying EscrowService...");
const EscrowService = await ethers.getContractFactory("EscrowService");
const escrowService = await EscrowService.deploy(
AITBC_TOKEN_ADDRESS,
aiPowerRental.address,
paymentProcessor.address
);
await escrowService.deployed();
console.log("EscrowService deployed to:", escrowService.address);
// 6. Deploy Dynamic Pricing
console.log("\n6. Deploying DynamicPricing...");
const DynamicPricing = await ethers.getContractFactory("DynamicPricing");
const dynamicPricing = await DynamicPricing.deploy(
aiPowerRental.address,
performanceVerifier.address,
AITBC_TOKEN_ADDRESS
);
await dynamicPricing.deployed();
console.log("DynamicPricing deployed to:", dynamicPricing.address);
// Initialize contracts with cross-references
console.log("\n7. Initializing contract cross-references...");
// Set payment processor in AI Power Rental
await aiPowerRental.setPaymentProcessor(paymentProcessor.address);
console.log("Payment processor set in AIPowerRental");
// Set performance verifier in AI Power Rental
await aiPowerRental.setPerformanceVerifier(performanceVerifier.address);
console.log("Performance verifier set in AIPowerRental");
// Set dispute resolver in payment processor
await paymentProcessor.setDisputeResolver(disputeResolution.address);
console.log("Dispute resolver set in PaymentProcessor");
// Set escrow service in payment processor
await paymentProcessor.setEscrowService(escrowService.address);
console.log("Escrow service set in PaymentProcessor");
// Authorize initial oracles and arbiters
console.log("\n8. Setting up initial oracles and arbiters...");
// Authorize deployer as price oracle
await dynamicPricing.authorizePriceOracle(deployer.address);
console.log("Deployer authorized as price oracle");
// Authorize deployer as performance oracle
await performanceVerifier.authorizeOracle(deployer.address);
console.log("Deployer authorized as performance oracle");
// Authorize deployer as arbitrator
await disputeResolution.authorizeArbitrator(deployer.address);
console.log("Deployer authorized as arbitrator");
// Authorize deployer as escrow arbiter
await escrowService.authorizeArbiter(deployer.address);
console.log("Deployer authorized as escrow arbiter");
// Save deployment addresses
const deploymentInfo = {
network: network.name,
deployer: deployer.address,
timestamp: new Date().toISOString(),
contracts: {
AITBC_TOKEN_ADDRESS,
ZK_VERIFIER_ADDRESS,
GROTH16_VERIFIER_ADDRESS,
AIPowerRental: aiPowerRental.address,
AITBCPaymentProcessor: paymentProcessor.address,
PerformanceVerifier: performanceVerifier.address,
DisputeResolution: disputeResolution.address,
EscrowService: escrowService.address,
DynamicPricing: dynamicPricing.address
}
};
// Write deployment info to file
const fs = require('fs');
fs.writeFileSync(
`deployment-${network.name}-${Date.now()}.json`,
JSON.stringify(deploymentInfo, null, 2)
);
console.log("\n=== Deployment Summary ===");
console.log("All contracts deployed successfully!");
console.log("Deployment info saved to deployment file");
console.log("\nContract Addresses:");
console.log("- AIPowerRental:", aiPowerRental.address);
console.log("- AITBCPaymentProcessor:", paymentProcessor.address);
console.log("- PerformanceVerifier:", performanceVerifier.address);
console.log("- DisputeResolution:", disputeResolution.address);
console.log("- EscrowService:", escrowService.address);
console.log("- DynamicPricing:", dynamicPricing.address);
console.log("\n=== Next Steps ===");
console.log("1. Update environment variables with contract addresses");
console.log("2. Run integration tests");
console.log("3. Configure marketplace API to use new contracts");
console.log("4. Perform security audit");
} 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,225 @@
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
console.log("=== AITBC Smart Contract Validation ===");
// Contract files to validate
const contracts = [
'contracts/AIPowerRental.sol',
'contracts/AITBCPaymentProcessor.sol',
'contracts/PerformanceVerifier.sol',
'contracts/DisputeResolution.sol',
'contracts/EscrowService.sol',
'contracts/DynamicPricing.sol'
];
// Validation checks
const validationResults = {
totalContracts: 0,
validContracts: 0,
totalLines: 0,
contracts: []
};
console.log("\n🔍 Validating smart contracts...");
contracts.forEach(contractPath => {
if (fs.existsSync(contractPath)) {
const content = fs.readFileSync(contractPath, 'utf8');
const lines = content.split('\n').length;
// Basic validation checks
const checks = {
hasSPDXLicense: content.includes('SPDX-License-Identifier'),
hasPragma: content.includes('pragma solidity'),
hasContractDefinition: content.includes('contract ') || content.includes('interface ') || content.includes('library '),
hasConstructor: content.includes('constructor'),
hasFunctions: content.includes('function '),
hasEvents: content.includes('event '),
hasModifiers: content.includes('modifier '),
importsOpenZeppelin: content.includes('@openzeppelin/contracts'),
hasErrorHandling: content.includes('require(') || content.includes('revert('),
hasAccessControl: content.includes('onlyOwner') || content.includes('require(msg.sender'),
lineCount: lines
};
// Calculate validation score
const score = Object.values(checks).filter(Boolean).length;
const maxScore = Object.keys(checks).length;
const isValid = score >= (maxScore * 0.7); // 70% threshold
validationResults.totalContracts++;
validationResults.totalLines += lines;
if (isValid) {
validationResults.validContracts++;
}
validationResults.contracts.push({
name: path.basename(contractPath),
path: contractPath,
lines: lines,
checks: checks,
score: score,
maxScore: maxScore,
isValid: isValid
});
console.log(`${isValid ? '✅' : '❌'} ${path.basename(contractPath)} (${lines} lines, ${score}/${maxScore} checks)`);
} else {
console.log(`${contractPath} (file not found)`);
}
});
console.log("\n📊 Validation Summary:");
console.log(`Total contracts: ${validationResults.totalContracts}`);
console.log(`Valid contracts: ${validationResults.validContracts}`);
console.log(`Total lines of code: ${validationResults.totalLines}`);
console.log(`Validation rate: ${((validationResults.validContracts / validationResults.totalContracts) * 100).toFixed(1)}%`);
// Detailed contract analysis
console.log("\n📋 Contract Details:");
validationResults.contracts.forEach(contract => {
console.log(`\n📄 ${contract.name}:`);
console.log(` Lines: ${contract.lines}`);
console.log(` Score: ${contract.score}/${contract.maxScore}`);
console.log(` Status: ${contract.isValid ? '✅ Valid' : '❌ Needs Review'}`);
const failedChecks = Object.entries(contract.checks)
.filter(([key, value]) => !value)
.map(([key]) => key);
if (failedChecks.length > 0) {
console.log(` Missing: ${failedChecks.join(', ')}`);
}
});
// Integration validation
console.log("\n🔗 Integration Validation:");
// Check for cross-contract references
const crossReferences = {
'AIPowerRental': ['AITBCPaymentProcessor', 'PerformanceVerifier'],
'AITBCPaymentProcessor': ['AIPowerRental', 'DisputeResolution', 'EscrowService'],
'PerformanceVerifier': ['AIPowerRental'],
'DisputeResolution': ['AIPowerRental', 'AITBCPaymentProcessor', 'PerformanceVerifier'],
'EscrowService': ['AIPowerRental', 'AITBCPaymentProcessor'],
'DynamicPricing': ['AIPowerRental', 'PerformanceVerifier']
};
Object.entries(crossReferences).forEach(([contract, dependencies]) => {
const contractData = validationResults.contracts.find(c => c.name === `${contract}.sol`);
if (contractData) {
const content = fs.readFileSync(contractData.path, 'utf8');
const foundDependencies = dependencies.filter(dep => content.includes(dep));
console.log(`${foundDependencies.length === dependencies.length ? '✅' : '❌'} ${contract} references: ${foundDependencies.length}/${dependencies.length}`);
if (foundDependencies.length < dependencies.length) {
const missing = dependencies.filter(dep => !foundDependencies.includes(dep));
console.log(` Missing references: ${missing.join(', ')}`);
}
}
});
// Security validation
console.log("\n🔒 Security Validation:");
let securityScore = 0;
const securityChecks = {
'ReentrancyGuard': 0,
'Pausable': 0,
'Ownable': 0,
'AccessControl': 0,
'SafeMath': 0,
'IERC20': 0
};
validationResults.contracts.forEach(contract => {
const content = fs.readFileSync(contract.path, 'utf8');
Object.keys(securityChecks).forEach(securityFeature => {
if (content.includes(securityFeature)) {
securityChecks[securityFeature]++;
}
});
});
Object.entries(securityChecks).forEach(([feature, count]) => {
const percentage = (count / validationResults.totalContracts) * 100;
console.log(`${feature}: ${count}/${validationResults.totalContracts} contracts (${percentage.toFixed(1)}%)`);
if (count > 0) securityScore++;
});
console.log(`\n🛡️ Security Score: ${securityScore}/${Object.keys(securityChecks).length}`);
// Gas optimization validation
console.log("\n⛽ Gas Optimization Validation:");
let gasOptimizationScore = 0;
const gasOptimizationFeatures = [
'constant',
'immutable',
'view',
'pure',
'external',
'internal',
'private',
'memory',
'storage',
'calldata'
];
validationResults.contracts.forEach(contract => {
const content = fs.readFileSync(contract.path, 'utf8');
let contractGasScore = 0;
gasOptimizationFeatures.forEach(feature => {
if (content.includes(feature)) {
contractGasScore++;
}
});
if (contractGasScore >= 5) {
gasOptimizationScore++;
console.log(`${contract.name}: Optimized (${contractGasScore}/${gasOptimizationFeatures.length} features)`);
} else {
console.log(`⚠️ ${contract.name}: Could be optimized (${contractGasScore}/${gasOptimizationFeatures.length} features)`);
}
});
console.log(`\n⚡ Gas Optimization Score: ${gasOptimizationScore}/${validationResults.totalContracts}`);
// Final assessment
console.log("\n🎯 Final Assessment:");
const overallScore = validationResults.validContracts + securityScore + gasOptimizationScore;
const maxScore = validationResults.totalContracts + Object.keys(securityChecks).length + validationResults.totalContracts;
const overallPercentage = (overallScore / maxScore) * 100;
console.log(`Overall Score: ${overallScore}/${maxScore} (${overallPercentage.toFixed(1)}%)`);
if (overallPercentage >= 80) {
console.log("🚀 Status: EXCELLENT - Ready for deployment");
} else if (overallPercentage >= 60) {
console.log("✅ Status: GOOD - Minor improvements recommended");
} else if (overallPercentage >= 40) {
console.log("⚠️ Status: FAIR - Significant improvements needed");
} else {
console.log("❌ Status: POOR - Major improvements required");
}
console.log("\n📝 Recommendations:");
if (validationResults.validContracts < validationResults.totalContracts) {
console.log("- Fix contract validation issues");
}
if (securityScore < Object.keys(securityChecks).length) {
console.log("- Add missing security features");
}
if (gasOptimizationScore < validationResults.totalContracts) {
console.log("- Optimize gas usage");
}
console.log("- Run comprehensive tests");
console.log("- Perform security audit");
console.log("- Deploy to testnet first");
console.log("\n✨ Validation completed!");