Skip to content

Commit

Permalink
add rme info
Browse files Browse the repository at this point in the history
  • Loading branch information
0xCardinalError committed Dec 4, 2024
1 parent 20e90ff commit da017e6
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 16 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,15 @@ Feel free to use public RPCs but if you want extra security and speed, feel free
- **Network**: Configure network name
- **Script**: Configure script name and path
#### Tasks
To run hardhat task put in CLI
npx hardhat (hh) contracts --target main
hh compare --source main --target test
There are 4 tasks currently copyBatch, signatures, contracts and compare
## Releasing
To release a new rc version, tag the commit with the `-rcX` suffix, where `X` is the release candidate number.
Expand Down
93 changes: 93 additions & 0 deletions tasks/compare.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { task } from 'hardhat/config';
import fs from 'fs';
import path from 'path';

interface NetworkDeployment {
chainId: number;
contracts: {
[key: string]: {
bytecode: string;
address: string;
};
};
}

task('compare', 'Compare bytecodes between two deployments')
.addParam('source', 'Source network (main, test, local, pretestnet, tenderly)')
.addParam('target', 'Target network to compare against')
.setAction(async (taskArgs: { source: string; target: string }) => {
const sourceType = taskArgs.source.toLowerCase();
const targetType = taskArgs.target.toLowerCase();

const validNetworks = ['main', 'test', 'local', 'pretestnet', 'tenderly'];
if (!validNetworks.includes(sourceType) || !validNetworks.includes(targetType)) {
throw new Error('Network parameters must be one of: ' + validNetworks.join(', '));
}

const fileNames = {
main: 'mainnet_deployed.json',
test: 'testnet_deployed.json',
local: 'localhost_deployed.json',
pretestnet: 'pretestnet_deployed.json',
tenderly: 'tenderly_deployed.json',
};

const sourceFile = fileNames[sourceType as keyof typeof fileNames];
const targetFile = fileNames[targetType as keyof typeof fileNames];

try {
// Read deployment files
const sourceData: NetworkDeployment = JSON.parse(fs.readFileSync(path.join(__dirname, '..', sourceFile), 'utf8'));
const targetData: NetworkDeployment = JSON.parse(fs.readFileSync(path.join(__dirname, '..', targetFile), 'utf8'));

console.log(`\nComparing bytecodes between ${sourceType} and ${targetType}`);
console.log('=============================================');

// Compare bytecodes for each contract
Object.keys(sourceData.contracts).forEach((contractName) => {
if (targetData.contracts[contractName]) {
const sourceBytecode = sourceData.contracts[contractName].bytecode;
const targetBytecode = targetData.contracts[contractName].bytecode;

console.log(`\nContract: ${contractName}`);

if (sourceBytecode === targetBytecode) {
console.log('Bytecodes are identical');
} else {
// Find the first differing character position
let firstDiff = -1;
for (let i = 0; i < Math.max(sourceBytecode.length, targetBytecode.length); i++) {
if (sourceBytecode[i] !== targetBytecode[i]) {
firstDiff = i;
break;
}
}

console.log(`Bytecodes differ at position: ${firstDiff}`);
if (firstDiff !== -1) {
// Show a snippet around the difference
const start = Math.max(0, firstDiff - 10);
const end = firstDiff + 10;

console.log('\nSource bytecode snippet:');
console.log(sourceBytecode.slice(start, end));
console.log(' ^');
console.log('Target bytecode snippet:');
console.log(targetBytecode.slice(start, end));
console.log(' ^');
}

console.log(`\nSource length: ${sourceBytecode.length}`);
console.log(`Target length: ${targetBytecode.length}`);
}
} else {
console.log(`\nContract ${contractName} not found in ${targetType} deployment`);
}
});
} catch (error) {
if (error instanceof Error) {
console.error('Error comparing bytecodes:');
console.error(error.message);
}
}
});
49 changes: 33 additions & 16 deletions tasks/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,45 @@ import fs from 'fs';
import path from 'path';

task('contracts', 'Display contract deployment information')
.addParam('target', 'Network type (main or test)')
.addParam('target', 'Network type (main, test, local, pretestnet, tenderly)')
.setAction(async (taskArgs: { target: string }) => {
const networkType = taskArgs.target.toLowerCase();

if (networkType !== 'main' && networkType !== 'test') {
throw new Error('Network parameter must be either "main" or "test"');
const validNetworks = ['main', 'test', 'local', 'pretestnet', 'tenderly'];
if (!validNetworks.includes(networkType)) {
throw new Error('Network parameter must be one of: ' + validNetworks.join(', '));
}

const fileName = networkType === 'main' ? 'mainnet_deployed.json' : 'testnet_deployed.json';
const fileNames = {
main: 'mainnet_deployed.json',
test: 'testnet_deployed.json',
local: 'localhost_deployed.json',
pretestnet: 'pretestnet_deployed.json',
tenderly: 'tenderly_deployed.json',
};

const fileName = fileNames[networkType as keyof typeof fileNames];

// Read JSON file
const filePath = path.join(__dirname, '..', fileName);
const fileContent = fs.readFileSync(filePath, 'utf8');
const deploymentData = JSON.parse(fileContent);

// Extract and display contract information
console.log(`\nDeployed Contracts (${networkType})`);
console.log('========================');

Object.entries(deploymentData.contracts).forEach(([name, data]: [string, any]) => {
console.log(`\n${name}:`);
console.log(`Address: ${data.address}`);
console.log(`Explorer: ${data.url}`);
});

try {
const fileContent = fs.readFileSync(filePath, 'utf8');
const deploymentData = JSON.parse(fileContent);

// Extract and display contract information
console.log(`\nDeployed Contracts (${networkType})`);
console.log('========================');

Object.entries(deploymentData.contracts).forEach(([name, data]: [string, any]) => {
console.log(`\n${name}:`);
console.log(`Address: ${data.address}`);
console.log(`Explorer: ${data.url}`);
});
} catch (error) {
if (error instanceof Error) {
console.error(`Error: Could not read or parse ${fileName}`);
console.error(`Details: ${error.message}`);
}
}
});
1 change: 1 addition & 0 deletions tasks/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './signatures';
export * from './copybatch';
export * from './contracts';
export * from './compare';

0 comments on commit da017e6

Please sign in to comment.