Skip to content

Commit

Permalink
feat: send contract verification packets (#132)
Browse files Browse the repository at this point in the history
* feat: send contract verification packets

* Update package.json

Co-authored-by: Kevin Weaver <kevinweaver2@gmail.com>

* fix: remove disable logging code

* fix: remove comment

---------

Co-authored-by: Kevin Weaver <kevinweaver2@gmail.com>
  • Loading branch information
colinnielsen and kevinweaver committed Jul 2, 2024
1 parent bfdc39e commit ddca6c7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@0xmetropolis/metal",
"version": "0.8.3",
"description": "Smart contract visualization tool.",
"version": "0.9.0",
"description": "Smart contract deployment tool.",
"author": "Metropolis (@0xmetropolis)",
"bin": {
"metal": "./bin/run"
Expand Down
19 changes: 17 additions & 2 deletions src/commands/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,13 @@ async function validateInputs({ _: [, scriptPath], 'chain-id': chainId }: Handle
}

// @dev pulls any args from process.argv and replaces any fork-url aliases with the preview-service's fork url
export const configureForgeScriptInputs = ({ rpcUrl }: { rpcUrl: string }): string[] => {
export const configureForgeScriptInputs = ({
rpcUrl,
previewId,
}: {
rpcUrl: string;
previewId: string;
}): string[] => {
// pull anything after `metal preview <path>` as forge arguments
let forgeArguments = process.argv.slice(3);
// rewrap function signatures in quotes, ex: --sig "run()"
Expand Down Expand Up @@ -123,6 +129,14 @@ export const configureForgeScriptInputs = ({ rpcUrl }: { rpcUrl: string }): stri
if (!forgeArguments.includes('--broadcast')) forgeArguments.push('--broadcast');
if (!forgeArguments.includes('--slow')) forgeArguments.push('--slow');

if (forgeArguments.includes('--verify') || forgeArguments.includes('--verifier-url'))
throw Error(
'Must verify contracts against the metal backend, please do not include --verify or --verifier-url flags',
);
forgeArguments.push(
`--verify --verifier-url ${METAL_SERVICE_URL}/contracts/verification/${previewId} --etherscan-api-key null`,
);

return forgeArguments;
};

Expand All @@ -137,7 +151,7 @@ export const sendDataToMetalService = async (
? authenticationStatus.access_token
: undefined;

let headers: HeadersInit = {
const headers: HeadersInit = {
'Content-Type': 'application/json',
};
if (authToken) headers['Authorization'] = `Bearer ${authToken}`;
Expand Down Expand Up @@ -192,6 +206,7 @@ export const handler = async (yargs: HandlerInput) => {
logInfo(`Running Forge Script at ${forgeScriptPath}...`);
const foundryArguments = configureForgeScriptInputs({
rpcUrl: yargs['UNSAFE-RPC-OVERRIDE'] ?? rpcUrl,
previewId,
});

await runForgeScriptForPreviewCommand(foundryArguments);
Expand Down
17 changes: 12 additions & 5 deletions src/utils/foundry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ const mutateForgeMessages = (msg: string | number | bigint | boolean | object):
// search the output for messages that should be filtered

if (msgAsString.includes('Sending transactions')) return '';
if (msgAsString.includes('Total Paid')) return '';
if (msgAsString.includes('txes (') && msgAsString.includes('[00:0')) return '';
else if (msgAsString.includes('ONCHAIN EXECUTION COMPLETE & SUCCESSFUL.'))
return msgAsString.replace('ONCHAIN EXECUTION COMPLETE & SUCCESSFUL.\n', '');
Expand All @@ -246,7 +247,12 @@ const watchForgeOutput = (
const magicEmojis = ['🧙', '🪄', '🧚', '✨'];

stdout.on('data', (chunk: any) => {
// if the chunk contains the succes label, then it's related to a transaction
if (chunk.toString().includes('Start verification for')) {
logInfo('Submitting contract verification to metal ⛓️...\n\n');
return;
}

// if the chunk contains the success label, then it's related to a transaction
if (chunk.toString().includes('[Success]Hash')) {
// increment the transaction counter
state.transactionCounter++;
Expand All @@ -256,11 +262,12 @@ const watchForgeOutput = (
state.transactionCounter +
'...',
);
} else {
// otherwise, use the normal filter flow
const msg = mutateForgeMessages(chunk);
if (msg) logInfo(msg);
return;
}

// otherwise, use the normal filter flow
const msg = mutateForgeMessages(chunk);
if (msg) logInfo(msg);
});
};

Expand Down

0 comments on commit ddca6c7

Please sign in to comment.