@@ -24,12 +24,34 @@ import {
2424 DeployStatusModal ,
2525 useDeployStatusModal ,
2626} from "components/contract-components/contract-deploy-form/deploy-context-modal" ;
27+ import {
28+ getModuleInstallParams ,
29+ showPrimarySaleFiedset ,
30+ showRoyaltyFieldset ,
31+ showSuperchainBridgeFieldset ,
32+ } from "components/contract-components/contract-deploy-form/modular-contract-default-modules-fieldset" ;
2733import { useTxNotifications } from "hooks/useTxNotifications" ;
28- import { defineChain } from "thirdweb" ;
29- import type { FetchDeployMetadataResult } from "thirdweb/contract" ;
34+ import {
35+ ZERO_ADDRESS ,
36+ defineChain ,
37+ getContract ,
38+ readContract ,
39+ sendTransaction ,
40+ waitForReceipt ,
41+ } from "thirdweb" ;
42+ import type {
43+ FetchDeployMetadataResult ,
44+ ThirdwebContract ,
45+ } from "thirdweb/contract" ;
3046import { deployContractfromDeployMetadata } from "thirdweb/deploys" ;
47+ import { installPublishedModule } from "thirdweb/modules" ;
3148import { useActiveAccount , useSwitchActiveWalletChain } from "thirdweb/react" ;
32- import { concatHex , padHex } from "thirdweb/utils" ;
49+ import {
50+ type AbiFunction ,
51+ concatHex ,
52+ encodeAbiParameters ,
53+ padHex ,
54+ } from "thirdweb/utils" ;
3355
3456export type CrossChain = {
3557 id : number ;
@@ -41,11 +63,13 @@ export type CrossChain = {
4163export function DataTable ( {
4264 data,
4365 coreMetadata,
66+ coreContract,
4467 modulesMetadata,
4568 initializeData,
4669} : {
4770 data : CrossChain [ ] ;
4871 coreMetadata : FetchDeployMetadataResult ;
72+ coreContract : ThirdwebContract ;
4973 modulesMetadata : FetchDeployMetadataResult [ ] ;
5074 initializeData ?: `0x${string } `;
5175} ) {
@@ -131,6 +155,100 @@ export function DataTable({
131155 client,
132156 } ) ;
133157
158+ const owner = await readContract ( {
159+ contract : coreContract ,
160+ method : "function owner() view returns (address)" ,
161+ params : [ ] ,
162+ } ) ;
163+ console . log ( "owner" , owner ) ;
164+
165+ const moduleInitializeParams = modulesMetadata . reduce (
166+ ( acc , mod ) => {
167+ const params = getModuleInstallParams ( mod ) ;
168+ const paramNames = params
169+ . map ( ( param ) => param . name )
170+ . filter ( ( p ) => p !== undefined ) ;
171+ const returnVal : Record < string , string > = { } ;
172+
173+ // set connected wallet address as default "royaltyRecipient"
174+ if ( showRoyaltyFieldset ( paramNames ) ) {
175+ returnVal . royaltyRecipient = owner || "" ;
176+ returnVal . royaltyBps = "0" ;
177+ returnVal . transferValidator = ZERO_ADDRESS ;
178+ }
179+
180+ // set connected wallet address as default "primarySaleRecipient"
181+ else if ( showPrimarySaleFiedset ( paramNames ) ) {
182+ returnVal . primarySaleRecipient = owner || "" ;
183+ }
184+
185+ // set superchain bridge address
186+ else if ( showSuperchainBridgeFieldset ( paramNames ) ) {
187+ returnVal . superchainBridge =
188+ "0x4200000000000000000000000000000000000010" ; // OP Superchain Bridge
189+ }
190+
191+ acc [ mod . name ] = returnVal ;
192+ return acc ;
193+ } ,
194+ { } as Record < string , Record < string , string > > ,
195+ ) ;
196+ console . log ( "moduleInitializeParams" , moduleInitializeParams ) ;
197+
198+ const moduleDeployData = modulesMetadata . map ( ( m ) => ( {
199+ deployMetadata : m ,
200+ initializeParams : moduleInitializeParams [ m . name ] ,
201+ } ) ) ;
202+ console . log ( "module deploy data" , moduleDeployData ) ;
203+
204+ const contract = getContract ( {
205+ address : crosschainContractAddress ,
206+ chain,
207+ client,
208+ } ) ;
209+
210+ await Promise . all (
211+ moduleDeployData . map ( async ( m ) => {
212+ let moduleData : `0x${string } ` | undefined ;
213+
214+ const moduleInstallParams = m . deployMetadata . abi . find (
215+ ( abiType ) =>
216+ ( abiType as AbiFunction ) . name === "encodeBytesOnInstall" ,
217+ ) as AbiFunction | undefined ;
218+
219+ if ( m . initializeParams && moduleInstallParams ) {
220+ moduleData = encodeAbiParameters (
221+ (
222+ moduleInstallParams . inputs as { name : string ; type : string } [ ]
223+ ) . map ( ( p ) => ( {
224+ name : p . name ,
225+ type : p . type ,
226+ } ) ) ,
227+ Object . values ( m . initializeParams ) ,
228+ ) ;
229+ }
230+ console . log ( "module install params" , moduleInstallParams ) ;
231+
232+ const installTransaction = installPublishedModule ( {
233+ contract,
234+ account : activeAccount ,
235+ moduleName : m . deployMetadata . name ,
236+ publisher : m . deployMetadata . publisher ,
237+ version : m . deployMetadata . version ,
238+ moduleData,
239+ } ) ;
240+ console . log ( "install transaction" , installTransaction ) ;
241+
242+ const txResult = await sendTransaction ( {
243+ transaction : installTransaction ,
244+ account : activeAccount ,
245+ } ) ;
246+ console . log ( "tx result" , txResult ) ;
247+
248+ return await waitForReceipt ( txResult ) ;
249+ } ) ,
250+ ) ;
251+
134252 deployStatusModal . nextStep ( ) ;
135253 deployStatusModal . setViewContractLink (
136254 `/${ chain . id } /${ crosschainContractAddress } ` ,
0 commit comments