Skip to content

Commit 0194ac3

Browse files
committed
remove deprecated ABI files and update contract references in the EVM DAO creation store; add Firestore network name utility function
1 parent 726ef99 commit 0194ac3

7 files changed

Lines changed: 50 additions & 49 deletions

File tree

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@
4747
{ "internalType": "address[]","name": "initialMembers", "type": "address[]" },
4848
{ "internalType": "uint256[]","name": "initialAmounts", "type": "uint256[]" },
4949
{ "internalType": "string[]","name": "keys", "type": "string[]" },
50-
{ "internalType": "string[]","name": "values", "type": "string[]" },
51-
{ "internalType": "bool", "name": "transferrable", "type": "bool" }
50+
{ "internalType": "string[]","name": "values", "type": "string[]" }
5251
],
5352
"internalType": "struct WrapperContract.DaoParams",
5453
"name": "params",

src/modules/etherlink/types.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export interface IEvmFirebaseContract {
77
daoFactory: IEthereumAddress
88
timelockFactory: IEthereumAddress
99
registryFactory: IEthereumAddress
10-
// wrapper: IEthereumAddress // Not in use and deprecated
10+
wrapper?: IEthereumAddress
1111
wrapper_t: IEthereumAddress
1212
wrapper_w: IEthereumAddress
1313
nativeCurrency: string

src/modules/etherlink/utils.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ export const networkConfig = {
2121
}
2222
}
2323

24+
export function getFirestoreNetworkName(internalNetwork: string): string {
25+
if (internalNetwork === "etherlink_testnet") return "Etherlink-Testnet"
26+
if (internalNetwork === "etherlink_mainnet") return "Etherlink"
27+
if (internalNetwork === "localhost") return "Localhost"
28+
return internalNetwork
29+
}
30+
2431
export const isInvalidEvmAddress = (address: string) => {
2532
return !ethers.isAddress(address)
2633
}

src/services/config/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export enum EnvKey {
1818
REACT_APP_BASE_URL = "REACT_APP_BASE_URL",
1919
REACT_APP_DAO_DEPLOYER_API = "REACT_APP_DAO_DEPLOYER_API",
2020
// Optional overrides for Etherlink wrapper contract addresses (dev/debug)
21+
REACT_APP_EVM_WRAPPER_ADDRESS = "REACT_APP_EVM_WRAPPER_ADDRESS",
2122
REACT_APP_EVM_WRAPPER_T_ADDRESS = "REACT_APP_EVM_WRAPPER_T_ADDRESS",
2223
REACT_APP_EVM_WRAPPER_W_ADDRESS = "REACT_APP_EVM_WRAPPER_W_ADDRESS",
2324
REACT_APP_RPC_NETWORK_GHOSTNET = "REACT_APP_RPC_NETWORK_GHOSTNET",

src/services/contracts/etherlinkDAO/hooks/useEvmDaoCreateStore.tsx

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import { persist, createJSONStorage } from "zustand/middleware"
66
import { STEPS } from "modules/etherlink/config"
77
import { useHistory } from "react-router-dom"
88

9-
import WrapperContractAbi from "assets/abis/hb_wrapper_v2.json"
10-
import HbWrapperWLegacyAbi from "assets/abis/hb_wrapper_w_legacy.json"
9+
import WrapperStandardAbi from "assets/abis/hb_wrapper_standard.json"
1110

1211
import { useCallback, useContext, useState } from "react"
1312
import { useTezos } from "services/beacon/hooks/useTezos"
@@ -165,12 +164,6 @@ const useEvmDaoCreateStore = () => {
165164
const data = useEvmDaoCreateZustantStore()
166165
const history = useHistory()
167166
const { contractData } = useContext(EtherlinkContext)
168-
const wrapperAddressOverride = getEnv(EnvKey.REACT_APP_EVM_WRAPPER_T_ADDRESS)
169-
const wrapperWrappedOverride = getEnv(EnvKey.REACT_APP_EVM_WRAPPER_W_ADDRESS)
170-
const wrapperAddress = wrapperAddressOverride || contractData?.wrapper
171-
const wrapperAddressForWrapped = wrapperWrappedOverride || contractData?.wrapper
172-
console.log("Wrapper wrapped address:", wrapperAddressForWrapped)
173-
console.log("Wrapper address:", wrapperAddress)
174167

175168
const { etherlink, network } = useTezos()
176169
const notify = useNotification()
@@ -180,9 +173,18 @@ const useEvmDaoCreateStore = () => {
180173
console.log("=== Starting DAO Deployment ===")
181174
console.log("Full DAO Data:", daoData)
182175

183-
// Determine wrapper address before attempting deployment (for error reporting)
184-
const selectedWrapperAddress =
185-
daoData.tokenDeploymentMechanism === "wrapped" ? wrapperAddressForWrapped : wrapperAddress
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+
180+
let selectedWrapperAddress: string | undefined
181+
if (daoData.tokenDeploymentMechanism === "wrapped") {
182+
selectedWrapperAddress = wrapperWrappedOverride || contractData?.wrapper_w
183+
} else if (daoData.nonTransferable) {
184+
selectedWrapperAddress = wrapperAddressOverride || contractData?.wrapper
185+
} else {
186+
selectedWrapperAddress = wrapperTAddressOverride || contractData?.wrapper_t
187+
}
186188

187189
try {
188190
const proposalThreshold = daoData.quorum.proposalThreshold || daoData.quorum.proposalThresholdPercentage || 0
@@ -213,12 +215,20 @@ const useEvmDaoCreateStore = () => {
213215
console.log("Signer:", etherlink.signer)
214216

215217
if (!selectedWrapperAddress) {
218+
const factoryType =
219+
daoData.tokenDeploymentMechanism === "wrapped"
220+
? "wrapped ERC20"
221+
: daoData.nonTransferable
222+
? "non-transferable"
223+
: "transferable"
216224
console.error("No wrapper address found!", {
217-
wrapperAddress,
218-
wrapperAddressForWrapped,
219-
tokenDeploymentMechanism: daoData.tokenDeploymentMechanism
225+
factoryType,
226+
tokenDeploymentMechanism: daoData.tokenDeploymentMechanism,
227+
nonTransferable: daoData.nonTransferable
220228
})
221-
throw new Error("Wrapper contract address not found. Please check your network configuration.")
229+
throw new Error(
230+
`Wrapper contract address not found for ${factoryType} token DAO. Please check your network configuration.`
231+
)
222232
}
223233

224234
// Validate signer
@@ -227,20 +237,7 @@ const useEvmDaoCreateStore = () => {
227237
throw new Error("Wallet not connected. Please connect your wallet.")
228238
}
229239

230-
// Use legacy ABI if using the fallback address
231-
// TODO: Move to use wrapper only
232-
// const isUsingFallbackAddress = selectedWrapperAddress === "0xf4B3022b0fb4e8A73082ba9081722d6a276195c2"
233-
// const wrapperAbi = Array.isArray(WrapperContractAbi)
234-
// ? (WrapperContractAbi as any)
235-
// : (WrapperContractAbi as any)?.abi
236-
// const selectedAbi =
237-
// daoData.tokenDeploymentMechanism === "wrapped"
238-
// ? isUsingFallbackAddress
239-
// ? HbWrapperWLegacyAbi.abi
240-
// : wrapperAbi
241-
// : wrapperAbi
242-
243-
const selectedAbi = HbWrapperWLegacyAbi.abi
240+
const selectedAbi = WrapperStandardAbi.abi
244241

245242
// Preflight: verify contract code exists at address
246243
const onChainCode = await etherlink.provider.getCode(selectedWrapperAddress)
@@ -299,8 +296,8 @@ const useEvmDaoCreateStore = () => {
299296
})
300297

301298
const wrappedDaoPayload = {
302-
// Legacy structure without wrappedTokenName
303299
daoName: daoData.name || "",
300+
wrappedTokenName: daoData.wrappedTokenName || `Wrapped ${daoData.wrappedTokenSymbol || "Token"}`,
304301
wrappedTokenSymbol: daoData.wrappedTokenSymbol || "",
305302
description: daoData.description || "",
306303
executionDelay: Math.floor(executationDelayinSeconds),
@@ -403,8 +400,7 @@ const useEvmDaoCreateStore = () => {
403400
initialMembers: daoData.members.map((member: any) => member.address),
404401
initialAmounts: initialAmountsWithSettings,
405402
keys: Object.keys(registryForDeploy),
406-
values: Object.values(registryForDeploy).map(v => String(v)),
407-
transferrable: !daoData.nonTransferable // Note: fixed spelling to match ABI
403+
values: Object.values(registryForDeploy).map(v => String(v))
408404
}
409405

410406
try {
@@ -450,7 +446,7 @@ const useEvmDaoCreateStore = () => {
450446
}
451447
setIsDeploying(false)
452448
// eslint-disable-next-line react-hooks/exhaustive-deps
453-
}, [data.data, etherlink.signer, wrapperAddress, wrapperAddressForWrapped])
449+
}, [data.data, etherlink.signer, contractData])
454450
const isFinalStep = data.currentStep === STEPS.length - 1
455451

456452
return {

src/services/wagmi/etherlink/hooks/useDaoState.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import useFirestoreStore from "services/contracts/etherlinkDAO/hooks/useFirestor
33
import dayjs from "dayjs"
44
import BigNumber from "bignumber.js"
55
import { Timestamp } from "firebase/firestore"
6-
import { networkConfig } from "modules/etherlink/utils"
6+
import { networkConfig, getFirestoreNetworkName } from "modules/etherlink/utils"
77
import { getCallDataFromBytes, getBlockExplorerUrl } from "modules/etherlink/utils"
88
import { fetchOffchainProposals } from "services/services/lite/lite-services"
99
import { IEvmDAO, IEvmFirebaseContract, IEvmFirebaseDAOMember, IEvmFirebaseProposal } from "modules/etherlink/types"
@@ -25,7 +25,7 @@ export const useDaoState = ({ network }: { network: string }) => {
2525

2626
const [isLoadingDaos, setIsLoadingDaos] = useState(!!firebaseRootCollection)
2727
const [isLoadingDaoProposals, setIsLoadingDaoProposals] = useState(true)
28-
const [contractData, setContractData] = useState<any[]>([])
28+
const [contractData, setContractData] = useState<IEvmFirebaseContract | null>(null)
2929
const [daoData, setDaoData] = useState<IEvmDAO[]>([])
3030
const [daoSelected, setDaoSelected] = useState<IEvmDAO | null>(null)
3131
const [daoProposals, setDaoProposals] = useState<any[]>([])
@@ -73,10 +73,11 @@ export const useDaoState = ({ network }: { network: string }) => {
7373

7474
// Initial fetch triggers
7575
useEffect(() => {
76-
fetchCollection("contracts")
76+
const firestoreNetworkName = getFirestoreNetworkName(network)
77+
fetchDoc("contracts", firestoreNetworkName)
7778
if (firebaseRootCollection) fetchCollection(firebaseRootCollection)
7879
if (firebaseRootTokenCollection) fetchCollection(firebaseRootTokenCollection)
79-
}, [fetchCollection, firebaseRootCollection, firebaseRootTokenCollection])
80+
}, [fetchCollection, fetchDoc, firebaseRootCollection, firebaseRootTokenCollection, network])
8081

8182
// When the root collection changes (i.e., network change), clear previous data promptly
8283
useEffect(() => {
@@ -103,16 +104,13 @@ export const useDaoState = ({ network }: { network: string }) => {
103104
setDaoData(allDaoList)
104105
setIsLoadingDaos(false)
105106
}
106-
if (firestoreData?.["contracts"]) {
107-
const isTestnet = firebaseRootCollection?.toLowerCase().includes("testnet")
108-
const contractDataForNetwork = firestoreData["contracts"]?.find((contract: IEvmFirebaseContract) => {
109-
return isTestnet
110-
? contract.id?.toLowerCase().includes("testnet")
111-
: !contract.id?.toLowerCase().includes("testnet")
112-
})
113-
setContractData(contractDataForNetwork)
107+
const firestoreNetworkName = getFirestoreNetworkName(network)
108+
const contractDocKey = `contracts/${firestoreNetworkName}`
109+
if (firestoreData?.[contractDocKey]) {
110+
const contractDoc = firestoreData[contractDocKey]
111+
setContractData(Array.isArray(contractDoc) ? contractDoc[0] : contractDoc)
114112
}
115-
}, [firestoreData, firebaseRootCollection])
113+
}, [firestoreData, firebaseRootCollection, network])
116114

117115
// When a DAO is selected, subscribe to its subcollections and compute proposal summaries
118116
useEffect(() => {

0 commit comments

Comments
 (0)