-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1198 from alleslabs/feat/verify-via-foundary
feat: verify with third party framework
- Loading branch information
Showing
5 changed files
with
120 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 39 additions & 2 deletions
41
src/lib/pages/evm-contract-verify/components/solidity/EvmContractVerifySolidityFoundry.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}; |
74 changes: 72 additions & 2 deletions
74
src/lib/pages/evm-contract-verify/components/solidity/EvmContractVerifySolidityHardhat.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters