From 8c6daa9d779facdbf961232890ad8b528a51c553 Mon Sep 17 00:00:00 2001 From: Mark_Jeong <81726531+markjung96@users.noreply.github.com> Date: Fri, 25 Oct 2024 18:33:13 +0900 Subject: [PATCH] feat: apply cliversion, auto verify --- src/components/interaction/activate.tsx | 6 ++--- src/components/interaction/compile.tsx | 13 ++++++--- src/components/interaction/deploy.tsx | 36 ++++++++++++++++++++++++- src/const/endpoint.ts | 19 +++++-------- src/const/network.ts | 7 +++-- 5 files changed, 58 insertions(+), 23 deletions(-) diff --git a/src/components/interaction/activate.tsx b/src/components/interaction/activate.tsx index f109a6c..d8ed6ca 100644 --- a/src/components/interaction/activate.tsx +++ b/src/components/interaction/activate.tsx @@ -5,7 +5,7 @@ import { Button } from "react-bootstrap"; import { LoaderWrapper } from "../common/loader"; import { useStore } from "../../zustand"; -import { ARBITRUM_COMPILER_CONSUMER_API_ENDPOINT, COMPILER_API_ENDPOINT } from "../../const/endpoint"; +import { COMPILER_API_ENDPOINT } from "../../const/endpoint"; import { log } from "../../utils/logger"; const ACTIVATION_TO_ADDR = "0x0000000000000000000000000000000000000071"; @@ -68,9 +68,7 @@ export const Activate = ({}: ActivateProps) => { let tx = ""; try { - const res = await axios.get( - ARBITRUM_COMPILER_CONSUMER_API_ENDPOINT + `/arbitrum/activation-tx?contractAddr=${address}` - ); + const res = await axios.get(COMPILER_API_ENDPOINT + `/arbitrum/activation-tx?contractAddr=${address}`); tx = res.data?.tx; if (!tx) { await client.terminal.log({ diff --git a/src/components/interaction/compile.tsx b/src/components/interaction/compile.tsx index ca0893c..a1d6d8f 100644 --- a/src/components/interaction/compile.tsx +++ b/src/components/interaction/compile.tsx @@ -26,7 +26,7 @@ import { log } from "../../utils/logger"; import { isEmptyList } from "../../utils/list-utils"; import { EditorClient } from "../../utils/editor"; import { CHAIN_NAME } from "../../const/chain"; -import { ARBITRUM_COMPILER_CONSUMER_ENDPOINT, COMPILER_API_ENDPOINT } from "../../const/endpoint"; +import { COMPILER_WEBSOCKET_ENDPOINT, COMPILER_API_ENDPOINT } from "../../const/endpoint"; import { cleanupSocketArbitrum } from "../../utils/socket"; import { getPositionDetails, isRealError, stringify } from "../../const/helper"; import { S3Path } from "../../const/s3-path"; @@ -49,6 +49,7 @@ export const Compile = ({}: CompileProps) => { setTimestamp, setFileName, setCompileErrorMsg, + compilerVersion, project, upload, deployLoading, @@ -73,6 +74,7 @@ export const Compile = ({}: CompileProps) => { setTimestamp: state.compile.setTimestamp, setFileName: state.compile.setFileName, setCompileErrorMsg: state.compile.setErrorMsg, + compilerVersion: state.project.compilerVersion.data, project: state.project.project, upload: state.project.upload, setDeployTransactionData: state.deploy.setTransactionData, @@ -237,7 +239,7 @@ export const Compile = ({}: CompileProps) => { return; } - const socket = io(ARBITRUM_COMPILER_CONSUMER_ENDPOINT, { + const socket = io(COMPILER_WEBSOCKET_ENDPOINT, { reconnection: false, transports: ["websocket"], timeout: 120_000, @@ -353,7 +355,8 @@ export const Compile = ({}: CompileProps) => { method: "GET", url: `${COMPILER_API_ENDPOINT}/s3Proxy`, params: { - bucket: S3Path.bucket(), + // bucket: S3Path.bucket(), + bucket: "wds-code-build", fileKey: S3Path.outKey(CHAIN_NAME.arbitrum, network, account, timestamp, BUILD_FILE_TYPE.rs), }, responseType: "arraybuffer", @@ -430,13 +433,15 @@ export const Compile = ({}: CompileProps) => { } }); - const remixArbitrumCompileRequestedV1: RemixArbitrumCompileRequestedV1 = { + // FIXME: + const remixArbitrumCompileRequestedV1: RemixArbitrumCompileRequestedV1 & { cliVersion: string } = { compileId: compileIdV2(CHAIN_NAME.arbitrum, network, account, timestamp), chainName: CHAIN_NAME.arbitrum, chainId: network, address: account, timestamp: timestamp.toString() || "0", fileType: "arbitrum", + cliVersion: compilerVersion, }; socket.emit(REMIX_ARBITRUM_COMPILE_REQUESTED_V1, remixArbitrumCompileRequestedV1); diff --git a/src/components/interaction/deploy.tsx b/src/components/interaction/deploy.tsx index a84a578..fc83a67 100644 --- a/src/components/interaction/deploy.tsx +++ b/src/components/interaction/deploy.tsx @@ -7,6 +7,7 @@ import { LoaderWrapper } from "../common/loader"; import { useStore } from "../../zustand"; import { COMPILER_API_ENDPOINT } from "../../const/endpoint"; import { log } from "../../utils/logger"; +import { ARBITRUM_NETWORK } from "../../const/network"; interface ArbitrumContractCreateDto { chainId: string; @@ -20,6 +21,13 @@ interface ArbitrumContractCreateDto { cliVersion: string | null; } +interface ArbitrumVerifyContractDto { + network: string; + contractAddress: string; + cliVersion: string; + srcFileId?: string; +} + interface DeployProps {} export const Deploy = ({}: DeployProps) => { const { @@ -29,6 +37,7 @@ export const Deploy = ({}: DeployProps) => { account, project, upload, + compilerVersion, compileLoading, timestamp, transactionData, @@ -51,6 +60,7 @@ export const Deploy = ({}: DeployProps) => { account: state.account.address.data, project: state.project.project.data, upload: state.project.upload.data, + compilerVersion: state.project.compilerVersion.data, compileLoading: state.compile.loading, timestamp: state.compile.timestamp, transactionData: state.deploy.transactionData.data, @@ -150,7 +160,7 @@ export const Deploy = ({}: DeployProps) => { txHash: hash, isSrcUploaded: upload, status: txReceipt.status ? "true" : "false", - cliVersion: null, // todo + cliVersion: compilerVersion, }; log.info("arbitrumContractCreateDto", arbitrumContractCreateDto); try { @@ -164,6 +174,13 @@ export const Deploy = ({}: DeployProps) => { if (activated || !activatedReady) { setContractAddresses([...contractAddresses, txReceipt.contractAddress]); } + + verifyContract({ + network, + contractAddress: txReceipt.contractAddress, + srcFileId: String(timestamp), + cliVersion: compilerVersion, + }); } client.terminal.log({ type: "info", @@ -176,6 +193,23 @@ export const Deploy = ({}: DeployProps) => { setLoading(false); }; + const verifyContract = async ({ network, contractAddress, srcFileId, cliVersion }: ArbitrumVerifyContractDto) => { + const targetNetwork = ARBITRUM_NETWORK.find((item) => item.chainId === network); + if (!targetNetwork) return; + log.info("verifyContract", { network: targetNetwork.network, contractAddress, srcFileId, cliVersion }); + try { + const res = await axios.post(COMPILER_API_ENDPOINT + "/arbitrum/verifications", { + network: targetNetwork.network, + contractAddress, + srcFileId, + cliVersion, + }); + console.log("verifyContract", res); + } catch (error) { + log.error("verifyContract error", error); + } + }; + const getReceiptRecursively = async ( hash: string ): Promise | null> => { diff --git a/src/const/endpoint.ts b/src/const/endpoint.ts index 624b5de..a1fe1a6 100644 --- a/src/const/endpoint.ts +++ b/src/const/endpoint.ts @@ -1,23 +1,18 @@ import { STAGE } from "./stage"; const COMPILER_API_ENDPOINT_POOL = { - local: "http://localhost:8000", + // local: "http://localhost:8000", + // local: "https://cargo-test.veriwell.dev", + local: "https://arbitrum.compiler.welldonestudio.io", dev: "https://dev.compiler.welldonestudio.io", prod: "https://verify.welldonestudio.io", }; export const COMPILER_API_ENDPOINT = COMPILER_API_ENDPOINT_POOL[STAGE]; -const ARBITRUM_COMPILER_CONSUMER_ENDPOINT_POOL = { - local: "ws://localhost:8000", +const COMPILER_WEBSOCKET_ENDPOINT_POOL = { + // local: "ws://localhost:8000", + local: "wss://arbitrum.compiler.welldonestudio.io", dev: "wss://dev.compiler.welldonestudio.io", prod: "wss://prod.near.compiler.welldonestudio.io", }; -export const ARBITRUM_COMPILER_CONSUMER_ENDPOINT = ARBITRUM_COMPILER_CONSUMER_ENDPOINT_POOL[STAGE]; - -const ARBITRUM_COMPILER_CONSUMER_API_ENDPOINT_POOL = { - local: "http://localhost:8000", - dev: "https://dev.compiler.welldonestudio.io", - prod: "https://verify.welldonestudio.io", -}; - -export const ARBITRUM_COMPILER_CONSUMER_API_ENDPOINT = ARBITRUM_COMPILER_CONSUMER_API_ENDPOINT_POOL[STAGE]; +export const COMPILER_WEBSOCKET_ENDPOINT = COMPILER_WEBSOCKET_ENDPOINT_POOL[STAGE]; diff --git a/src/const/network.ts b/src/const/network.ts index 008b4e1..eda26b6 100644 --- a/src/const/network.ts +++ b/src/const/network.ts @@ -1,5 +1,6 @@ export const ARBITRUM_ONE = { chainName: "Arbitrum One", + network: "ARBITRUM_ONE", chainId: "0xa4b1", rpcUrls: ["https://arb1.arbitrum.io/rpc"], blockExplorerUrls: ["https://arbiscan.io"], @@ -7,16 +8,18 @@ export const ARBITRUM_ONE = { export const ARBITRUM_SEPOLIA = { chainName: "Arbitrum Sepolia (Testnet)", + network: "ARBITRUM_SEPOLIA", chainId: "0x66eee", rpcUrls: ["https://sepolia-rollup.arbitrum.io/rpc"], - blockExplorerUrls: ["https://sepolia.arbiscan.io/"], + blockExplorerUrls: ["https://sepolia.arbiscan.io"], }; export const OPEN_CAMPUS_CODEX = { chainName: "Open Campus Codex", + network: "OPEN_CAMPUS_CODEX", chainId: "0xa045c", rpcUrls: [" https://rpc.open-campus-codex.gelato.digital"], - blockExplorerUrls: ["https://opencampus-codex.blockscout.com/"], + blockExplorerUrls: ["https://opencampus-codex.blockscout.com"], }; export const ARBITRUM_NETWORK = [ARBITRUM_ONE, ARBITRUM_SEPOLIA, OPEN_CAMPUS_CODEX];