Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Multichain] fix: check for canonical deployments #4193

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/components/common/NetworkSelector/NetworkMultiSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
17 changes: 16 additions & 1 deletion src/services/contracts/deployments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading