From 542e3d85b71541ec35fe08e9fc12b4635bc61b5d Mon Sep 17 00:00:00 2001 From: schmanu Date: Tue, 17 Sep 2024 18:28:18 +0200 Subject: [PATCH] fix: check for canonical deployments --- .../NetworkSelector/NetworkMultiSelector.tsx | 17 ++++++++++------- src/services/contracts/deployments.ts | 17 ++++++++++++++++- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/components/common/NetworkSelector/NetworkMultiSelector.tsx b/src/components/common/NetworkSelector/NetworkMultiSelector.tsx index a54ecabf24..83a3f8cad8 100644 --- a/src/components/common/NetworkSelector/NetworkMultiSelector.tsx +++ b/src/components/common/NetworkSelector/NetworkMultiSelector.tsx @@ -9,8 +9,9 @@ import { useRouter } from 'next/router' import { getNetworkLink } from '.' import useWallet from '@/hooks/wallets/useWallet' import { SetNameStepFields } from '@/components/new-safe/create/steps/SetNameStep' -import { getSafeSingletonDeployment } from '@safe-global/safe-deployments' +import { getSafeSingletonDeployments } from '@safe-global/safe-deployments' import { getLatestSafeVersion } from '@/utils/chains' +import { hasCanonicalDeployment } from '@/services/contracts/deployments' const NetworkMultiSelector = ({ name, @@ -60,17 +61,19 @@ const NetworkMultiSelector = ({ // do not allow multi chain safes for advanced setup flow. if (isAdvancedFlow) return optionNetwork.chainId != firstSelectedNetwork.chainId - const optionHasCanonicalSingletonDeployment = Boolean( - getSafeSingletonDeployment({ + const optionHasCanonicalSingletonDeployment = hasCanonicalDeployment( + getSafeSingletonDeployments({ network: optionNetwork.chainId, version: getLatestSafeVersion(firstSelectedNetwork), - })?.deployments.canonical, + }), + optionNetwork.chainId, ) - const selectedHasCanonicalSingletonDeployment = Boolean( - getSafeSingletonDeployment({ + const selectedHasCanonicalSingletonDeployment = hasCanonicalDeployment( + getSafeSingletonDeployments({ network: firstSelectedNetwork.chainId, version: getLatestSafeVersion(firstSelectedNetwork), - })?.deployments.canonical, + }), + firstSelectedNetwork.chainId, ) // Only 1.4.1 safes with canonical deployment addresses can be deployed as part of a multichain group diff --git a/src/services/contracts/deployments.ts b/src/services/contracts/deployments.ts index b4b2ee8682..6995cf6317 100644 --- a/src/services/contracts/deployments.ts +++ b/src/services/contracts/deployments.ts @@ -9,9 +9,24 @@ import { getSignMessageLibDeployment, getCreateCallDeployment, } from '@safe-global/safe-deployments' -import type { SingletonDeployment, DeploymentFilter } from '@safe-global/safe-deployments' +import type { SingletonDeployment, DeploymentFilter, SingletonDeploymentV2 } from '@safe-global/safe-deployments' import type { ChainInfo, SafeInfo } from '@safe-global/safe-gateway-typescript-sdk' import { getLatestSafeVersion } from '@/utils/chains' +import { sameAddress } from '@/utils/addresses' + +const toNetworkAddressList = (addresses: string | string[]) => (Array.isArray(addresses) ? addresses : [addresses]) + +export const hasCanonicalDeployment = (deployment: SingletonDeploymentV2 | undefined, chainId: string) => { + const canonicalAddress = deployment?.deployments.canonical?.address + + if (!canonicalAddress) { + return false + } + + const networkAddresses = toNetworkAddressList(deployment.networkAddresses[chainId]) + + return networkAddresses.some((networkAddress) => sameAddress(canonicalAddress, networkAddress)) +} export const _tryDeploymentVersions = ( getDeployment: (filter?: DeploymentFilter) => SingletonDeployment | undefined,