Skip to content

Commit

Permalink
fix: check for canonical deployments
Browse files Browse the repository at this point in the history
  • Loading branch information
schmanu committed Sep 17, 2024
1 parent 6555c95 commit 542e3d8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
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

0 comments on commit 542e3d8

Please sign in to comment.