Skip to content

Commit

Permalink
feat: apply cliversion, auto verify
Browse files Browse the repository at this point in the history
  • Loading branch information
markjung96 committed Oct 25, 2024
1 parent 59f0681 commit 8c6daa9
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 23 deletions.
6 changes: 2 additions & 4 deletions src/components/interaction/activate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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({
Expand Down
13 changes: 9 additions & 4 deletions src/components/interaction/compile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -49,6 +49,7 @@ export const Compile = ({}: CompileProps) => {
setTimestamp,
setFileName,
setCompileErrorMsg,
compilerVersion,
project,
upload,
deployLoading,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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);
Expand Down
36 changes: 35 additions & 1 deletion src/components/interaction/deploy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand All @@ -29,6 +37,7 @@ export const Deploy = ({}: DeployProps) => {
account,
project,
upload,
compilerVersion,
compileLoading,
timestamp,
transactionData,
Expand All @@ -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,
Expand Down Expand Up @@ -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 {
Expand All @@ -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",
Expand All @@ -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<ReturnType<typeof web3.eth.getTransactionReceipt> | null> => {
Expand Down
19 changes: 7 additions & 12 deletions src/const/endpoint.ts
Original file line number Diff line number Diff line change
@@ -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];
7 changes: 5 additions & 2 deletions src/const/network.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
export const ARBITRUM_ONE = {
chainName: "Arbitrum One",
network: "ARBITRUM_ONE",
chainId: "0xa4b1",
rpcUrls: ["https://arb1.arbitrum.io/rpc"],
blockExplorerUrls: ["https://arbiscan.io"],
};

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];
Expand Down

0 comments on commit 8c6daa9

Please sign in to comment.