-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculate_contract_stats.js
More file actions
113 lines (96 loc) · 4.14 KB
/
calculate_contract_stats.js
File metadata and controls
113 lines (96 loc) · 4.14 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
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
// Main contracts to analyze (excluding libraries and interfaces)
const MAIN_CONTRACTS = [
'Diamond.sol/Diamond.json',
'DiamondCutFacet.sol/DiamondCutFacet.json',
'DiamondLoupeFacet.sol/DiamondLoupeFacet.json',
'DiamondFramePool.sol/DiamondFramePool.json',
'FileStore.sol/FileStore.json',
'ScriptyStorageV2.sol/ScriptyStorageV2.json',
'ScriptyBuilderV2.sol/ScriptyBuilderV2.json',
'OnchainRugsHTMLGenerator.sol/OnchainRugsHTMLGenerator.json',
'RugNFTFacet.sol/RugNFTFacet.json',
'RugAdminFacet.sol/RugAdminFacet.json',
'RugAgingFacet.sol/RugAgingFacet.json',
'RugMaintenanceFacet.sol/RugMaintenanceFacet.json',
'RugCommerceFacet.sol/RugCommerceFacet.json',
'RugLaunderingFacet.sol/RugLaunderingFacet.json',
'RugTransferSecurityFacet.sol/RugTransferSecurityFacet.json',
'RugMarketplaceFacet.sol/RugMarketplaceFacet.json',
'ERC721CFacet.sol/ERC721CFacet.json',
'RugAgentRegistryFacet.sol/RugAgentRegistryFacet.json',
'RugAgentReputationFacet.sol/RugAgentReputationFacet.json',
'RugAgentValidationFacet.sol/RugAgentValidationFacet.json',
'RugReferralRegistryFacet.sol/RugReferralRegistryFacet.json',
];
function getBytecodeSize(artifactPath) {
try {
const fullPath = path.join(__dirname, 'out', artifactPath);
if (!fs.existsSync(fullPath)) {
return null;
}
const artifact = JSON.parse(fs.readFileSync(fullPath, 'utf8'));
// Get deployed bytecode size (runtime bytecode)
const bytecode = artifact.deployedBytecode?.object || artifact.bytecode?.object;
if (!bytecode || bytecode === '0x') {
return null;
}
// Remove '0x' prefix and calculate size in bytes
const bytecodeHex = bytecode.replace('0x', '');
return bytecodeHex.length / 2; // Each byte is 2 hex characters
} catch (error) {
console.error(`Error reading ${artifactPath}:`, error.message);
return null;
}
}
function formatBytes(bytes) {
if (bytes >= 1024 * 1024) {
return `${(bytes / (1024 * 1024)).toFixed(2)} MB`;
} else if (bytes >= 1024) {
return `${(bytes / 1024).toFixed(2)} KB`;
}
return `${bytes} bytes`;
}
console.log('=====================================');
console.log('SMART CONTRACT SIZE ANALYSIS');
console.log('=====================================\n');
let totalSize = 0;
const contractSizes = [];
MAIN_CONTRACTS.forEach(contractPath => {
const size = getBytecodeSize(contractPath);
if (size !== null) {
const contractName = path.basename(contractPath, '.json');
contractSizes.push({ name: contractName, size });
totalSize += size;
console.log(`${contractName.padEnd(40)} ${formatBytes(size).padStart(15)}`);
}
});
console.log('\n=====================================');
console.log(`TOTAL CONTRACT SIZE: ${formatBytes(totalSize)}`);
console.log(`TOTAL CONTRACT SIZE: ${totalSize.toLocaleString()} bytes`);
console.log('=====================================\n');
// Gas information from deployment logs
console.log('=====================================');
console.log('DEPLOYMENT GAS USAGE');
console.log('=====================================\n');
const deploymentLogs = [
{ network: 'Base Sepolia', gas: 36271055, logFile: 'deployment.log' },
{ network: 'Shape Sepolia', gas: 36331941, logFile: 'shape_sepolia_deploy.log' },
{ network: 'Ethereum Sepolia', gas: 44523782, logFile: 'eth_sepolia_deployment.log' },
];
deploymentLogs.forEach(({ network, gas }) => {
console.log(`${network.padEnd(25)} ${gas.toLocaleString().padStart(15)} gas`);
});
const avgGas = Math.round(deploymentLogs.reduce((sum, d) => sum + d.gas, 0) / deploymentLogs.length);
console.log('\n-------------------------------------');
console.log(`AVERAGE DEPLOYMENT GAS: ${avgGas.toLocaleString()} gas`);
console.log('=====================================\n');
// Summary
console.log('=====================================');
console.log('SUMMARY');
console.log('=====================================');
console.log(`Total Contract Size: ${formatBytes(totalSize)} (${totalSize.toLocaleString()} bytes)`);
console.log(`Average Deployment Gas: ${avgGas.toLocaleString()} gas`);
console.log('=====================================');