@@ -3,23 +3,7 @@ import type { ThirdwebClient } from "../../client/client.js";
33import { deployPublishedContract } from "./deploy-published.js" ;
44import { encodeAbiParameters } from "../../utils/abi/encodeAbiParameters.js" ;
55import type { Account } from "../../wallets/interfaces/wallet.js" ;
6-
7- export type DynamicParams = {
8- type : "address" | "address[]" | "bytes" | "bytes[]" ;
9- refContracts : {
10- publisherAddress : string ;
11- version : string ;
12- contractId : string ;
13- salt ?: string ;
14- } [ ] ;
15- paramsToEncode : Array <
16- Array < {
17- type : string ;
18- defaultValue ?: string ;
19- dynamicValue ?: DynamicParams ;
20- } >
21- > ;
22- }
6+ import type { DynamicParams } from "src/utils/any-evm/deploy-metadata.js" ;
237
248 export type ImplementationConstructorParam = {
259 defaultValue ?: string ;
@@ -35,7 +19,7 @@ export type DynamicParams = {
3519
3620 export async function processRefDeployments (
3721 options : ProcessRefDeploymentsOptions ,
38- ) : Promise < string > {
22+ ) : Promise < string | string [ ] > {
3923 const { client, account, chain, paramValue } = options ;
4024
4125 try {
@@ -53,6 +37,9 @@ export type DynamicParams = {
5337 const contracts = dynamicValue . refContracts ;
5438
5539 if ( dynamicValue . type === "address" ) {
40+ if ( ! contracts || contracts . length === 0 ) {
41+ throw new Error ( "Invalid or empty param value" ) ;
42+ }
5643 const salt =
5744 contracts [ 0 ] ?. salt && contracts [ 0 ] ?. salt . length > 0
5845 ? contracts [ 0 ] ?. salt
@@ -72,6 +59,9 @@ export type DynamicParams = {
7259 }
7360
7461 if ( dynamicValue . type === "address[]" ) {
62+ if ( ! contracts || contracts . length === 0 ) {
63+ throw new Error ( "Invalid or empty param value" ) ;
64+ }
7565 const addressArray = [ ] ;
7666
7767 for ( const c of contracts ) {
@@ -90,10 +80,13 @@ export type DynamicParams = {
9080 ) ;
9181 }
9282
93- return JSON . stringify ( addressArray ) ;
83+ return addressArray ;
9484 }
9585
9686 if ( dynamicValue . type === "bytes" ) {
87+ if ( ! dynamicValue . paramsToEncode ) {
88+ throw new Error ( "Invalid or empty param value" ) ;
89+ }
9790 const paramsToEncode = dynamicValue . paramsToEncode [ 0 ] ;
9891
9992 if ( paramsToEncode ) {
@@ -118,14 +111,17 @@ export type DynamicParams = {
118111
119112 return encodeAbiParameters (
120113 types . map ( ( t ) => {
121- return { name : "" , type : t } ;
114+ return { type : t } ;
122115 } ) ,
123116 values ,
124117 ) ;
125118 }
126119 }
127120
128121 if ( dynamicValue . type === "bytes[]" ) {
122+ if ( ! dynamicValue . paramsToEncode ) {
123+ throw new Error ( "Invalid or empty param value" ) ;
124+ }
129125 const bytesArray = [ ] ;
130126 const paramArray = dynamicValue . paramsToEncode ;
131127
@@ -155,26 +151,22 @@ export type DynamicParams = {
155151 bytesArray . push (
156152 encodeAbiParameters (
157153 types . map ( ( t ) => {
158- return { name : "" , type : t } ;
154+ return { type : t } ;
159155 } ) ,
160156 values ,
161157 ) ,
162158 ) ;
163159 }
164160 }
165161
166- return JSON . stringify ( bytesArray ) ;
162+ return bytesArray ;
167163 }
164+ } else {
165+ throw new Error ( "Invalid or empty param value" ) ;
168166 }
169167 }
170168 // biome-ignore lint/suspicious/noExplicitAny: catch multiple errors
171169 } catch ( e : any ) {
172- const err = "error" in e ? e . error ?. message : e ?. message ;
173-
174- if ( err . toString ( ) . includes ( "Contract already deployed" ) ) {
175- return paramValue as string ;
176- }
177-
178170 throw e ;
179171 }
180172
0 commit comments