Skip to content

Commit

Permalink
feat: create script insert_op_stack_abi
Browse files Browse the repository at this point in the history
  • Loading branch information
fibonacci998 committed Jul 29, 2024
1 parent e83f5c6 commit f4118fc
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 124 deletions.
File renamed without changes.
77 changes: 77 additions & 0 deletions script/insert_op_stack_abi/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import _ from 'lodash';
import { EVMContractVerification } from '../../src/models';
import proxy from './abis/proxy.json';
import l1_block from './abis/l1_block.json';
import l2_cross_domain_messenger from './abis/l2_cross_domain_messenger.json';
import l2_standard_bridge from './abis/l2_standard_bridge.json';
import l2_to_l1_message_passer from './abis/l2_to_l1_message_passer.json';

export async function insertContractVerification(_payload: {
contracts: {
address: string;
contractVerification: {
contractName: string;
compilerVersion: string;
abi: any;

Check warning on line 15 in script/insert_op_stack_abi/index.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
compilerSetting: any;

Check warning on line 16 in script/insert_op_stack_abi/index.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
};
}[];
}) {
console.log('Inserting contract verification');

Check warning on line 20 in script/insert_op_stack_abi/index.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
const foundContracts = await EVMContractVerification.query()
.whereIn(
'contract_address',
_payload.contracts.map((contract) => contract.address)
)
.select('id', 'contract_address');
if (foundContracts.length > 0) {
console.warn(`Found contracts in DB: ${JSON.stringify(foundContracts)}`);

Check warning on line 28 in script/insert_op_stack_abi/index.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
}
const foundContractByAddress = _.keyBy(foundContracts, 'contract_address');
const newContracts = _payload.contracts.filter(
(contract) => !foundContractByAddress[contract.address]
);
const evmContractVerification = newContracts.map((contract) =>
EVMContractVerification.fromJson({
contract_address: contract.address,
abi: JSON.stringify(contract.contractVerification.abi),
compiler_setting: JSON.stringify(
contract.contractVerification.compilerSetting
),
contract_name: contract.contractVerification.contractName,
status: EVMContractVerification.VERIFICATION_STATUS.SUCCESS,
})
);
await EVMContractVerification.query().insert(evmContractVerification);
console.log('Inserted done contract verification');

Check warning on line 46 in script/insert_op_stack_abi/index.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
}

const opContracts = [
[
'0x4200000000000000000000000000000000000007',
'0x4200000000000000000000000000000000000010',
'0x4200000000000000000000000000000000000015',
'0x4200000000000000000000000000000000000016',
].map((address) => ({
address,
contractVerification: proxy,
})),
{
address: '0xc0d3c0d3c0d3c0d3c0d3c0d3c0d3c0d3c0d30007',
contractVerification: l2_cross_domain_messenger,
},
{
address: '0xc0d3c0d3c0d3c0d3c0d3c0d3c0d3c0d3c0d30010',
contractVerification: l2_standard_bridge,
},
{
address: '0x07dbe8500fc591d1852b76fee44d5a05e13097ff',
contractVerification: l1_block,
},
{
address: '0xc0d3c0d3c0d3c0d3c0d3c0d3c0d3c0d3c0d30016',
contractVerification: l2_to_l1_message_passer,
},
].flat();

insertContractVerification({ contracts: opContracts });
4 changes: 0 additions & 4 deletions src/services/evm/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,6 @@ export const SERVICE = {
key: 'HandleOptimismWithdrawalEVM',
path: 'v1.HandleOptimismWithdrawalEVM',
},
InsertOptimismContractVerification: {
key: 'InsertOptimismContractVerification',
},
},
V2: {
EvmProxyService: {
Expand Down Expand Up @@ -286,7 +283,6 @@ export const BULL_JOB_NAME = {
'crawl:optimism-withdrawal-event-on-l1',
INSERT_VERIFY_BY_CODEHASH: 'job:insert-verify-by-codehash',
HANDLE_SELF_DESTRUCT: 'handle:self-destruct',
INSERT_CONTRACT_VERIFICATION: 'job:insert-contract-verification',
};

export const MSG_TYPE = {
Expand Down
61 changes: 0 additions & 61 deletions src/services/evm/optimism/insert_abi_optimism_contract.service.ts

This file was deleted.

59 changes: 0 additions & 59 deletions src/services/evm/verify_contract_evm.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { createHash } from 'crypto';
import { Context, ServiceBroker } from 'moleculer';
import { lt } from 'semver';
import { keccak256, toBytes } from 'viem';
import _ from 'lodash';
import config from '../../../config.json' assert { type: 'json' };
import networks from '../../../network.json' assert { type: 'json' };
import BullableService, { QueueHandler } from '../../base/bullable.service';
Expand Down Expand Up @@ -574,62 +573,4 @@ export default class VerifyContractEVM extends BullableService {
isVerifiable(contract: CheckedContract) {
return isEmpty(contract.missing) && isEmpty(contract.invalid);
}

@QueueHandler({
queueName: BULL_JOB_NAME.INSERT_CONTRACT_VERIFICATION,
jobName: BULL_JOB_NAME.INSERT_CONTRACT_VERIFICATION,
})
async insertContractVerification(_payload: {
contracts: {
address: string;
contractVerification: {
contractName: string;
compilerVersion: string;
abi: any;
compilerSetting: any;
};
}[];
}) {
this.logger.info('Inserting contract verification');
const foundContracts = await EVMContractVerification.query()
.whereIn(
'contract_address',
_payload.contracts.map((contract) => contract.address)
)
.select('id', 'contract_address');
if (foundContracts.length > 0) {
this.logger.warn(
`Found contracts in DB: ${JSON.stringify(foundContracts)}`
);
}
const foundContractByAddress = _.keyBy(foundContracts, 'contract_address');
const newContracts = _payload.contracts.filter(
(contract) => !foundContractByAddress[contract.address]
);
const evmContractVerification = newContracts.map((contract) =>
EVMContractVerification.fromJson({
contract_address: contract.address,
abi: JSON.stringify(contract.contractVerification.abi),
compiler_setting: JSON.stringify(
contract.contractVerification.compilerSetting
),
contract_name: contract.contractVerification.contractName,
status: EVMContractVerification.VERIFICATION_STATUS.SUCCESS,
})
);
await EVMContractVerification.query().insert(evmContractVerification);
newContracts.forEach((contract) => {
this.createJob(
BULL_JOB_NAME.HANDLE_EVM_SIGNATURE_MAPPING,
BULL_JOB_NAME.HANDLE_EVM_SIGNATURE_MAPPING,
{ contract_address: contract.address },
{
removeOnComplete: true,
removeOnFail: {
count: 3,
},
}
);
});
}
}

0 comments on commit f4118fc

Please sign in to comment.