Skip to content

Commit

Permalink
Merge pull request #1198 from alleslabs/feat/verify-via-foundary
Browse files Browse the repository at this point in the history
feat: verify with third party framework
  • Loading branch information
Poafs1 authored Jan 20, 2025
2 parents 70e721d + 61a2be1 commit c33dff4
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Features

- [#1199](https://github.com/alleslabs/celatone-frontend/pull/1199) Add EVM contract verification with Hardhat
- [#1198](https://github.com/alleslabs/celatone-frontend/pull/1198) Add EVM contract verification with Foundry
- [#1197](https://github.com/alleslabs/celatone-frontend/pull/1197) Add EVM contract verification with standard JSON input both for Solidity and Vyper
- [#1194](https://github.com/alleslabs/celatone-frontend/pull/1194) Add EVM contract verification with Vyper upload file method
- [#1193](https://github.com/alleslabs/celatone-frontend/pull/1193) Add optimizer configuration to EVM contract verify page, fix constructor args, and Zod type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ const EvmContractVerifySolidityOptions = ({
case VerificationOptions.JsonInput:
return <EvmContractVerifySolidityJsonInput control={control} />;
case VerificationOptions.Hardhat:
return <EvmContractVerifySolidityHardhat />;
return <EvmContractVerifySolidityHardhat control={control} />;
case VerificationOptions.Foundry:
return <EvmContractVerifySolidityFoundry />;
return <EvmContractVerifySolidityFoundry control={control} />;
default:
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,40 @@
export const EvmContractVerifySolidityFoundry = () => {
return <div>TODO: EvmContractVerifySolidityFoundry</div>;
import { Stack, Text } from "@chakra-ui/react";
import { useEvmConfig } from "lib/app-provider";
import { TextReadOnly } from "lib/components/json/TextReadOnly";
import { useMemo } from "react";

import { Control, useWatch } from "react-hook-form";
import { EvmContractVerifyForm } from "../../types";

interface EvmContractVerifySolidityFoundryProps {
control: Control<EvmContractVerifyForm>;
}

export const EvmContractVerifySolidityFoundry = ({
control,
}: EvmContractVerifySolidityFoundryProps) => {
const evm = useEvmConfig({ shouldRedirect: false });
const jsonRpc = evm.enabled ? evm.jsonRpc : "<invalid_network>";

const contractAddress = useWatch({ control, name: "contractAddress" });

// TODO: get verifier url from chain config
const verifierUrl = "https://eth-sepolia.blockscout.com/api/";

const cmd = useMemo(() => {
return `forge verify-contract \\
--rpc-url ${jsonRpc} \\
--verifier custom \\
--verifier-url ${verifierUrl} \\
--constructor-args <constructor-args> \\
${contractAddress || "<contract-address>"} \\
[contractFile]:[contractName]`;
}, [jsonRpc, contractAddress]);

return (
<Stack gap={4}>
<Text>Foundry</Text>
<TextReadOnly text={cmd} canCopy />
</Stack>
);
};
Original file line number Diff line number Diff line change
@@ -1,3 +1,73 @@
export const EvmContractVerifySolidityHardhat = () => {
return <div>TODO: EvmContractVerifySolidityHardhat</div>;
import { Stack, Text } from "@chakra-ui/react";
import { useCelatoneApp, useEvmConfig } from "lib/app-provider";
import { TextReadOnly } from "lib/components/json/TextReadOnly";
import { useMemo } from "react";

import { Control, useWatch } from "react-hook-form";
import { EvmContractVerifyForm } from "../../types";
import { convertCosmosChainIdToEvmChainId } from "lib/utils/evm";

interface EvmContractVerifySolidityHardhatProps {
control: Control<EvmContractVerifyForm>;
}

export const EvmContractVerifySolidityHardhat = ({
control,
}: EvmContractVerifySolidityHardhatProps) => {
const {
chainConfig: { chainId },
} = useCelatoneApp();
const evm = useEvmConfig({ shouldRedirect: false });
const jsonRpc = evm.enabled ? evm.jsonRpc : "<invalid_network>";

const contractAddress = useWatch({ control, name: "contractAddress" });
const evmChainId = convertCosmosChainIdToEvmChainId(chainId);

// TODO: get verifier url from chain config
const verifierUrl = "https://eth-sepolia.blockscout.com/api/";

const step1Cmd = useMemo(() => {
return `const config: HardhatUserConfig = {
solidity: "v0.8.28", // replace with your solidity version
networks: {
'${chainId}': {
url: '${jsonRpc}'
},
},
etherscan: {
apiKey: {
'${chainId}': 'empty'
},
customChains: [
{
network: "${chainId}",
chainId: ${evmChainId},
urls: {
apiURL: "${verifierUrl}",
}
}
]
}
};`;
}, [chainId, evmChainId, jsonRpc]);

const step2Cmd = useMemo(() => {
return `npx hardhat verify \\
--network ${chainId} \\
${contractAddress || "<contract-address>"} \\
[...constructorArgs]`;
}, [chainId, contractAddress]);

return (
<Stack gap={12}>
<Stack gap={4}>
<Text>Step 1 - Update hardhat.config.ts</Text>
<TextReadOnly text={step1Cmd} canCopy />
</Stack>
<Stack gap={4}>
<Text>Step 2 - Run verification command</Text>
<TextReadOnly text={step2Cmd} canCopy />
</Stack>
</Stack>
);
};
5 changes: 5 additions & 0 deletions src/lib/pages/evm-contract-verify/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ export const getVerifyFormInitialValue = (
option: verificationOption,
constructorArgs,
};
case VerificationOptions.Hardhat:
case VerificationOptions.Foundry:
return {
option: verificationOption,
};
default:
throw new Error("Invalid verification option for Solidity");
}
Expand Down

0 comments on commit c33dff4

Please sign in to comment.