@@ -6,12 +6,13 @@ import { persist, createJSONStorage } from "zustand/middleware"
66import { STEPS } from "modules/etherlink/config"
77import { useHistory } from "react-router-dom"
88
9- import WrapperStandardAbi from "assets/abis/hb_wrapper_standard.json"
9+ import StandardFactoryAbi from "assets/abis/StandardFactoryNonTransferable.json"
10+ import StandardFactoryTAbi from "assets/abis/StandardFactoryTransferable.json"
11+ import StandardFactoryWAbi from "assets/abis/StandardFactoryWrapped.json"
1012
1113import { useCallback , useContext , useState } from "react"
1214import { useTezos } from "services/beacon/hooks/useTezos"
1315import { EtherlinkContext } from "services/wagmi/context"
14- import { EnvKey , getEnv } from "services/config"
1516import { useNotification } from "modules/common/hooks/useNotification"
1617
1718interface EvmDaoCreateStore {
@@ -163,7 +164,11 @@ const useEvmDaoCreateStore = () => {
163164 const [ isDeploying , setIsDeploying ] = useState ( false )
164165 const data = useEvmDaoCreateZustantStore ( )
165166 const history = useHistory ( )
166- const { contractData } = useContext ( EtherlinkContext )
167+ const { contractData } = useContext < {
168+ wrapper : string
169+ wrapper_t : string
170+ wrapper_w : string
171+ } > ( EtherlinkContext )
167172
168173 const { etherlink, network } = useTezos ( )
169174 const notify = useNotification ( )
@@ -173,17 +178,13 @@ const useEvmDaoCreateStore = () => {
173178 console . log ( "=== Starting DAO Deployment ===" )
174179 console . log ( "Full DAO Data:" , daoData )
175180
176- const wrapperAddressOverride = getEnv ( EnvKey . REACT_APP_EVM_WRAPPER_ADDRESS )
177- const wrapperTAddressOverride = getEnv ( EnvKey . REACT_APP_EVM_WRAPPER_T_ADDRESS )
178- const wrapperWrappedOverride = getEnv ( EnvKey . REACT_APP_EVM_WRAPPER_W_ADDRESS )
179-
180181 let selectedWrapperAddress : string | undefined
181182 if ( daoData . tokenDeploymentMechanism === "wrapped" ) {
182- selectedWrapperAddress = wrapperWrappedOverride || contractData ?. wrapper_w
183+ selectedWrapperAddress = ( contractData as any ) ?. wrapper_w
183184 } else if ( daoData . nonTransferable ) {
184- selectedWrapperAddress = wrapperAddressOverride || contractData ?. wrapper
185+ selectedWrapperAddress = ( contractData as any ) ?. wrapper
185186 } else {
186- selectedWrapperAddress = wrapperTAddressOverride || contractData ?. wrapper_t
187+ selectedWrapperAddress = ( contractData as any ) ?. wrapper_t
187188 }
188189
189190 try {
@@ -221,6 +222,7 @@ const useEvmDaoCreateStore = () => {
221222 : daoData . nonTransferable
222223 ? "non-transferable"
223224 : "transferable"
225+
224226 console . error ( "No wrapper address found!" , {
225227 factoryType,
226228 tokenDeploymentMechanism : daoData . tokenDeploymentMechanism ,
@@ -237,7 +239,15 @@ const useEvmDaoCreateStore = () => {
237239 throw new Error ( "Wallet not connected. Please connect your wallet." )
238240 }
239241
240- const selectedAbi = WrapperStandardAbi . abi
242+ // Select ABI based on flow; fall back to StandardFactoryAbi when a specific variant isn't available
243+ let selectedAbi : any
244+ if ( daoData . tokenDeploymentMechanism === "wrapped" ) {
245+ selectedAbi = ( StandardFactoryWAbi as any ) ?. abi
246+ } else if ( daoData . nonTransferable ) {
247+ selectedAbi = ( StandardFactoryAbi as any ) ?. abi
248+ } else {
249+ selectedAbi = ( StandardFactoryTAbi as any ) ?. abi
250+ }
241251
242252 // Preflight: verify contract code exists at address
243253 const onChainCode = await etherlink . provider . getCode ( selectedWrapperAddress )
@@ -276,71 +286,29 @@ const useEvmDaoCreateStore = () => {
276286 let wrapper : any // This will be a TransactionResponse
277287
278288 if ( daoData . tokenDeploymentMechanism === "wrapped" ) {
279- // Deploy with wrapped token
280- // Ensure registry is initialized
289+ // Deploy with wrapped token using the StandardFactoryWrapped tuple structure
281290 const registryKeys = Object . keys ( daoData . registry || { } )
282291 const registryValues = Object . values ( daoData . registry || { } ) . map ( v => String ( v ) )
283292
284- console . log ( "Registry data for wrapped token:" , {
285- registry : daoData . registry ,
286- keys : registryKeys ,
287- values : registryValues ,
288- keyTypes : registryKeys . map ( k => typeof k ) ,
289- valueTypes : registryValues . map ( v => typeof v )
290- } )
291-
292- console . log ( "Preparing proposal threshold:" , {
293- proposalThreshold,
294- proposalThresholdType : typeof proposalThreshold ,
295- proposalThresholdAsBigInt : BigInt ( proposalThreshold || 0 ) . toString ( )
296- } )
293+ const governanceSettings = [
294+ BigInt ( proposalThreshold || 0 ) ,
295+ BigInt ( Math . min ( Math . max ( votingDelayInMinutes , 0 ) , 2 ** 48 - 1 ) ) , // voting delay (minutes)
296+ BigInt ( Math . min ( Math . max ( votingDurationInMinutes , 0 ) , 2 ** 32 - 1 ) ) , // voting period (minutes)
297+ BigInt ( Math . min ( Math . max ( Number ( quorumThreshold ) , 0 ) , 100 ) ) // quorum fraction percentage
298+ ]
297299
298300 const wrappedDaoPayload = {
299- daoName : daoData . name || "" ,
300- wrappedTokenName : daoData . wrappedTokenName || `Wrapped ${ daoData . wrappedTokenSymbol || "Token" } ` ,
301- wrappedTokenSymbol : daoData . wrappedTokenSymbol || "" ,
301+ name : daoData . name || "" ,
302+ symbol : daoData . wrappedTokenSymbol || "" ,
302303 description : daoData . description || "" ,
303- executionDelay : Math . floor ( executationDelayinSeconds ) ,
304+ executionDelay : BigInt ( Math . max ( Math . floor ( executationDelayinSeconds ) , 0 ) ) ,
304305 underlyingTokenAddress : daoData . underlyingTokenAddress ,
305- minsVotingDelay : Math . min ( Math . max ( votingDelayInMinutes , 0 ) , 2 ** 48 - 1 ) , // uint48
306- minsVotingPeriod : Math . min ( Math . max ( votingDurationInMinutes , 0 ) , 2 ** 32 - 1 ) , // uint32
307- proposalThreshold : BigInt ( proposalThreshold || 0 ) , // uint256 - raw token amount
308- quorumFraction : Math . min ( Math . max ( Number ( quorumThreshold ) , 0 ) , 100 ) , // uint8
309- keys : Object . keys ( daoData . registry || { } ) ,
310- values : Object . values ( daoData . registry || { } ) . map ( v => String ( v ) )
306+ governanceSettings,
307+ keys : registryKeys ,
308+ values : registryValues ,
309+ transferrableStr : String ( ! daoData . nonTransferable ) . toLowerCase ( )
311310 }
312311
313- // const wrappedDaoPayload = isUsingFallbackAddress
314- // ? {
315- // // Legacy structure without wrappedTokenName
316- // daoName: daoData.name || "",
317- // wrappedTokenSymbol: daoData.wrappedTokenSymbol || "",
318- // description: daoData.description || "",
319- // executionDelay: Math.floor(executationDelayinSeconds),
320- // underlyingTokenAddress: daoData.underlyingTokenAddress,
321- // minsVotingDelay: Math.min(Math.max(votingDelayInMinutes, 0), 2 ** 48 - 1), // uint48
322- // minsVotingPeriod: Math.min(Math.max(votingDurationInMinutes, 0), 2 ** 32 - 1), // uint32
323- // proposalThreshold: BigInt(proposalThreshold || 0), // uint256 - raw token amount
324- // quorumFraction: Math.min(Math.max(Number(quorumThreshold), 0), 100), // uint8
325- // keys: Object.keys(daoData.registry || {}),
326- // values: Object.values(daoData.registry || {}).map(v => String(v))
327- // }
328- // : {
329- // // New structure with wrappedTokenName
330- // daoName: daoData.name || "",
331- // wrappedTokenName: `Wrapped ${daoData.wrappedTokenSymbol || "Token"}`,
332- // wrappedTokenSymbol: daoData.wrappedTokenSymbol || "",
333- // description: daoData.description || "",
334- // executionDelay: Math.floor(executationDelayinSeconds),
335- // underlyingTokenAddress: daoData.underlyingTokenAddress,
336- // minsVotingDelay: Math.min(Math.max(votingDelayInMinutes, 0), 2 ** 48 - 1), // uint48
337- // minsVotingPeriod: Math.min(Math.max(votingDurationInMinutes, 0), 2 ** 32 - 1), // uint32
338- // proposalThreshold: BigInt(proposalThreshold || 0), // uint256 - raw token amount
339- // quorumFraction: Math.min(Math.max(Number(quorumThreshold), 0), 100), // uint8
340- // keys: Object.keys(daoData.registry || {}),
341- // values: Object.values(daoData.registry || {}).map(v => String(v))
342- // }
343-
344312 console . log (
345313 "Deploying wrapped token DAO with payload:" ,
346314 JSON . stringify ( wrappedDaoPayload , ( key , value ) => ( typeof value === "bigint" ? value . toString ( ) : value ) , 2 )
0 commit comments