-
Notifications
You must be signed in to change notification settings - Fork 399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Dashboard] Feature: UI for crosschain modules #5399
Open
GWSzeto
wants to merge
25
commits into
main
Choose a base branch
from
crosschain-ui
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
fe50d84
UI for crosschain modules
GWSzeto d14ec4b
Merge remote-tracking branch 'origin/main' into crosschain-ui
GWSzeto d442dfe
Merge remote-tracking branch 'origin/main' into crosschain-ui
GWSzeto c4acff6
Merge remote-tracking branch 'origin/main' into crosschain-ui
GWSzeto 9fedac3
WIP: hardcoded modified version of TWCloneFactory to be used
GWSzeto 4595d58
WIP: TODO's created to fetch for ContractInitialized event and update…
GWSzeto d08b33c
WIP: Testing out deploying bare core contract with modules installed …
GWSzeto 9f5289b
Merge remote-tracking branch 'origin/main' into crosschain-ui
GWSzeto 1f74bf6
WIP: staging to get help
GWSzeto 3248212
successfully deploys using the initialize data from the event
GWSzeto 6b9dd33
able to install modules successfully when crosschain deploying
GWSzeto 64ca579
updated to be promise.allSettled when installing modules to not block…
GWSzeto 9143857
removing console logs
GWSzeto 051028b
fixing liniting issues
GWSzeto 97e6b99
fixed linting issues
GWSzeto 55158b4
created isSuperchain and isCrosschain flag in favour of case switch s…
GWSzeto 67db04d
god bless greg it works
GWSzeto f6ee6a2
Merge remote-tracking branch 'origin/main' into crosschain-ui
GWSzeto 828c198
addressed comments in PR
GWSzeto 429d10c
updated wording
GWSzeto 71b8a97
updated superchain bridge address
GWSzeto 3cc27b6
Merge remote-tracking branch 'origin/main' into crosschain-ui
GWSzeto 1a7f7cb
updated to show links
GWSzeto ec1a0a1
implemented cross chain transfers
GWSzeto 52c3f44
tweaked input + button on crosschain transfer for OP Interop
GWSzeto File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
184 changes: 184 additions & 0 deletions
184
...board/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/cross-chain/data-table.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 |
---|---|---|
@@ -0,0 +1,184 @@ | ||
"use client"; | ||
|
||
import { Badge } from "@/components/ui/badge"; | ||
import { Button } from "@/components/ui/button"; | ||
import { | ||
Table, | ||
TableBody, | ||
TableCell, | ||
TableContainer, | ||
TableHead, | ||
TableHeader, | ||
TableRow, | ||
} from "@/components/ui/table"; | ||
import { getThirdwebClient } from "@/constants/thirdweb.server"; | ||
import { | ||
type ColumnDef, | ||
flexRender, | ||
getCoreRowModel, | ||
useReactTable, | ||
} from "@tanstack/react-table"; | ||
import { verifyContract } from "app/(dashboard)/(chain)/[chain_id]/[contractAddress]/sources/ContractSourcesPage"; | ||
import { | ||
type DeployModalStep, | ||
DeployStatusModal, | ||
useDeployStatusModal, | ||
} from "components/contract-components/contract-deploy-form/deploy-context-modal"; | ||
import { useTxNotifications } from "hooks/useTxNotifications"; | ||
import { defineChain } from "thirdweb"; | ||
import type { FetchDeployMetadataResult } from "thirdweb/contract"; | ||
import { deployContractfromDeployMetadata } from "thirdweb/deploys"; | ||
import { useActiveAccount, useSwitchActiveWalletChain } from "thirdweb/react"; | ||
import { concatHex, padHex } from "thirdweb/utils"; | ||
|
||
export type CrossChain = { | ||
id: number; | ||
network: string; | ||
chainId: number; | ||
status: "DEPLOYED" | "NOT_DEPLOYED"; | ||
}; | ||
|
||
export function DataTable({ | ||
data, | ||
coreMetadata, | ||
modulesMetadata, | ||
initializerCalldata, | ||
}: { | ||
data: CrossChain[]; | ||
coreMetadata: FetchDeployMetadataResult; | ||
modulesMetadata: FetchDeployMetadataResult[]; | ||
initializerCalldata: `0x${string}`; | ||
}) { | ||
const activeAccount = useActiveAccount(); | ||
const switchChain = useSwitchActiveWalletChain(); | ||
const deployStatusModal = useDeployStatusModal(); | ||
const { onError } = useTxNotifications( | ||
"Successfully deployed contract", | ||
"Failed to deploy contract", | ||
); | ||
|
||
const columns: ColumnDef<CrossChain>[] = [ | ||
{ | ||
accessorKey: "network", | ||
header: "Network", | ||
}, | ||
{ | ||
accessorKey: "chainId", | ||
header: "Chain ID", | ||
}, | ||
{ | ||
accessorKey: "status", | ||
header: "Status", | ||
cell: ({ row }) => { | ||
if (row.getValue("status") === "DEPLOYED") { | ||
return <Badge variant="success">Deployed</Badge>; | ||
} | ||
return ( | ||
<Button onClick={() => deployContract(row.getValue("chainId"))}> | ||
Deploy | ||
</Button> | ||
); | ||
}, | ||
}, | ||
]; | ||
|
||
const table = useReactTable({ | ||
data, | ||
columns, | ||
getCoreRowModel: getCoreRowModel(), | ||
}); | ||
|
||
const deployContract = async (chainId: number) => { | ||
try { | ||
if (!activeAccount) { | ||
throw new Error("No active account"); | ||
} | ||
|
||
// TODO: deploy the core contract directly with the initializer calldata | ||
|
||
const chain = defineChain(chainId); | ||
const client = getThirdwebClient(); | ||
const salt = concatHex(["0x0101", padHex("0x", { size: 30 })]).toString(); | ||
|
||
await switchChain(chain); | ||
|
||
const steps: DeployModalStep[] = [ | ||
{ | ||
type: "deploy", | ||
signatureCount: 1, | ||
}, | ||
]; | ||
|
||
deployStatusModal.setViewContractLink(""); | ||
deployStatusModal.open(steps); | ||
|
||
const crosschainContractAddress = await deployContractfromDeployMetadata({ | ||
account: activeAccount, | ||
chain, | ||
client, | ||
deployMetadata: coreMetadata, | ||
initializeParams: coreInitializeParams, | ||
salt, | ||
modules: modulesMetadata.map((m) => ({ | ||
deployMetadata: m, | ||
initializeParams: moduleInitializeParams[m.name], | ||
})), | ||
}); | ||
|
||
await verifyContract({ | ||
address: crosschainContractAddress, | ||
chain, | ||
client, | ||
}); | ||
|
||
deployStatusModal.nextStep(); | ||
deployStatusModal.setViewContractLink( | ||
`/${chain.id}/${crosschainContractAddress}`, | ||
); | ||
} catch (e) { | ||
onError(e); | ||
console.error("failed to deploy contract", e); | ||
deployStatusModal.close(); | ||
} | ||
}; | ||
|
||
return ( | ||
<TableContainer> | ||
<Table> | ||
<TableHeader> | ||
{table.getHeaderGroups().map((headerGroup) => ( | ||
<TableRow key={headerGroup.id}> | ||
{headerGroup.headers.map((header) => { | ||
return ( | ||
<TableHead key={header.id}> | ||
{header.isPlaceholder | ||
? null | ||
: flexRender( | ||
header.column.columnDef.header, | ||
header.getContext(), | ||
)} | ||
</TableHead> | ||
); | ||
})} | ||
</TableRow> | ||
))} | ||
</TableHeader> | ||
<TableBody> | ||
{table.getRowModel().rows.map((row) => ( | ||
<TableRow | ||
key={row.id} | ||
data-state={row.getIsSelected() && "selected"} | ||
> | ||
{row.getVisibleCells().map((cell) => ( | ||
<TableCell key={cell.id}> | ||
{flexRender(cell.column.columnDef.cell, cell.getContext())} | ||
</TableCell> | ||
))} | ||
</TableRow> | ||
))} | ||
</TableBody> | ||
</Table> | ||
<DeployStatusModal deployStatusModal={deployStatusModal} /> | ||
</TableContainer> | ||
); | ||
} |
151 changes: 151 additions & 0 deletions
151
apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/cross-chain/page.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 |
---|---|---|
@@ -0,0 +1,151 @@ | ||
import { fetchPublishedContractsFromDeploy } from "components/contract-components/fetchPublishedContractsFromDeploy"; | ||
import { notFound, redirect } from "next/navigation"; | ||
import { readContract } from "thirdweb"; | ||
import { getContractEvents, prepareEvent } from "thirdweb"; | ||
import { defineChain, getChainMetadata, localhost } from "thirdweb/chains"; | ||
import { type FetchDeployMetadataResult, getContract } from "thirdweb/contract"; | ||
import { getInstalledModules } from "thirdweb/modules"; | ||
import { eth_getCode, getRpcClient } from "thirdweb/rpc"; | ||
import { getContractPageParamsInfo } from "../_utils/getContractFromParams"; | ||
import { getContractPageMetadata } from "../_utils/getContractPageMetadata"; | ||
import { DataTable } from "./data-table"; | ||
|
||
export function getModuleInstallParams(mod: FetchDeployMetadataResult) { | ||
return ( | ||
mod.abi | ||
.filter((a) => a.type === "function") | ||
.find((f) => f.name === "encodeBytesOnInstall")?.inputs || [] | ||
); | ||
} | ||
|
||
export default async function Page(props: { | ||
params: Promise<{ | ||
contractAddress: string; | ||
chain_id: string; | ||
}>; | ||
}) { | ||
const params = await props.params; | ||
const info = await getContractPageParamsInfo(params); | ||
|
||
if (!info) { | ||
notFound(); | ||
} | ||
|
||
const { contract } = info; | ||
|
||
if (contract.chain.id === localhost.id) { | ||
return <div>asd</div>; | ||
} | ||
|
||
const { isModularCore } = await getContractPageMetadata(contract); | ||
|
||
if (!isModularCore) { | ||
redirect(`/${params.chain_id}/${params.contractAddress}`); | ||
} | ||
|
||
const originalCode = await eth_getCode( | ||
getRpcClient({ | ||
client: contract.client, | ||
chain: contract.chain, | ||
}), | ||
{ | ||
address: contract.address, | ||
}, | ||
); | ||
|
||
const topOPStackTestnetChainIds = [ | ||
84532, // Base | ||
11155420, // OP testnet | ||
919, // Mode Network | ||
111557560, // Cyber | ||
999999999, // Zora | ||
]; | ||
|
||
const chainsDeployedOn = await Promise.all( | ||
topOPStackTestnetChainIds.map(async (chainId) => { | ||
const chain = defineChain(chainId); | ||
const chainMetadata = await getChainMetadata(chain); | ||
|
||
const rpcRequest = getRpcClient({ | ||
client: contract.client, | ||
chain, | ||
}); | ||
const code = await eth_getCode(rpcRequest, { | ||
address: params.contractAddress, | ||
}); | ||
|
||
return { | ||
id: chainId, | ||
network: chainMetadata.name, | ||
chainId: chain.id, | ||
status: | ||
code === originalCode | ||
? ("DEPLOYED" as const) | ||
: ("NOT_DEPLOYED" as const), | ||
}; | ||
}), | ||
); | ||
|
||
const modules = await getInstalledModules({ contract }); | ||
|
||
const coreMetadata = ( | ||
await fetchPublishedContractsFromDeploy({ | ||
contract, | ||
client: contract.client, | ||
}) | ||
).at(-1) as FetchDeployMetadataResult; | ||
const modulesMetadata = (await Promise.all( | ||
modules.map(async (m) => | ||
( | ||
await fetchPublishedContractsFromDeploy({ | ||
contract: getContract({ | ||
chain: contract.chain, | ||
client: contract.client, | ||
address: m.implementation, | ||
}), | ||
client: contract.client, | ||
}) | ||
).at(-1), | ||
), | ||
)) as FetchDeployMetadataResult[]; | ||
|
||
const _erc20InitialData = await Promise.all([ | ||
readContract({ | ||
contract: contract, | ||
method: "function name() view returns (string)", | ||
}), | ||
readContract({ | ||
contract: contract, | ||
method: "function symbol() view returns (string)", | ||
}), | ||
readContract({ | ||
contract: contract, | ||
method: "function contractURI() view returns (string)", | ||
}), | ||
readContract({ | ||
contract: contract, | ||
method: "function owner() view returns (address)", | ||
}), | ||
]); | ||
|
||
const ProxyDeployedEvent = prepareEvent({ | ||
signature: | ||
"event ProxyDeployed(address indexed implementation, address proxy, address indexed deployer, bytes data)", | ||
}); | ||
|
||
// TODO: figure out how to fetch the events properly | ||
const [event] = await getContractEvents({ | ||
contract, | ||
events: [ProxyDeployedEvent], | ||
blockRange: 123456n, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Decide on what an appropriate way is to parse for this event |
||
}); | ||
|
||
return ( | ||
<DataTable | ||
coreMetadata={coreMetadata} | ||
modulesMetadata={modulesMetadata} | ||
initializerCalldata={event?.args.data} | ||
data={chainsDeployedOn} | ||
/> | ||
); | ||
} |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace the placeholder
asd
with a descriptive message that communicates the localhost limitation to users, such asCross-chain deployment is not available on localhost networks
Spotted by Graphite Reviewer
Is this helpful? React 👍 or 👎 to let us know.