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] Feat: multichain feature toggle #4209

Merged
merged 2 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 12 additions & 1 deletion src/components/common/NetworkSelector/NetworkMultiSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { SetNameStepFields } from '@/components/new-safe/create/steps/SetNameSte
import { getSafeSingletonDeployments } from '@safe-global/safe-deployments'
import { getLatestSafeVersion } from '@/utils/chains'
import { hasCanonicalDeployment } from '@/services/contracts/deployments'
import { hasMultiChainCreationFeatures } from '@/components/welcome/MyAccounts/utils/multiChainSafe'

const NetworkMultiSelector = ({
name,
Expand Down Expand Up @@ -55,12 +56,22 @@ const NetworkMultiSelector = ({

const isOptionDisabled = useCallback(
(optionNetwork: ChainInfo) => {
if (selectedNetworks.length === 0) return false
// Initially all networks are always available
if (selectedNetworks.length === 0) {
return false
}

const firstSelectedNetwork = selectedNetworks[0]

// do not allow multi chain safes for advanced setup flow.
if (isAdvancedFlow) return optionNetwork.chainId != firstSelectedNetwork.chainId

// Check required feature toggles
if (!hasMultiChainCreationFeatures(optionNetwork)) {
return true
}

// Check if required deployments are available
const optionHasCanonicalSingletonDeployment = hasCanonicalDeployment(
getSafeSingletonDeployments({
network: optionNetwork.chainId,
Expand Down
11 changes: 10 additions & 1 deletion src/components/welcome/MyAccounts/utils/multiChainSafe.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type SafeOverview } from '@safe-global/safe-gateway-typescript-sdk'
import { type ChainInfo, type SafeOverview } from '@safe-global/safe-gateway-typescript-sdk'
import { type SafeItem } from '../useAllSafes'
import { type UndeployedSafesState, type UndeployedSafe, type ReplayedSafeProps } from '@/store/slices'
import { sameAddress } from '@/utils/addresses'
Expand All @@ -8,6 +8,7 @@ import { keccak256, ethers, solidityPacked, getCreate2Address, type Provider } f
import { extractCounterfactualSafeSetup } from '@/features/counterfactual/utils'
import { encodeSafeSetupCall } from '@/components/new-safe/create/logic'
import { memoize } from 'lodash'
import { FEATURES, hasFeature } from '@/utils/chains'

export const isMultiChainSafeItem = (safe: SafeItem | MultiChainSafeItem): safe is MultiChainSafeItem => {
if ('safes' in safe && 'address' in safe) {
Expand Down Expand Up @@ -126,3 +127,11 @@ export const predictAddressBasedOnReplayData = async (safeCreationData: Replayed
const initCode = proxyCreationCode + solidityPacked(['uint256'], [constructorData]).slice(2)
return getCreate2Address(safeCreationData.factoryAddress, salt, keccak256(initCode))
}

export const hasMultiChainCreationFeatures = (chain: ChainInfo): boolean => {
return (
hasFeature(chain, FEATURES.MULTI_CHAIN_SAFE_CREATION) &&
hasFeature(chain, FEATURES.COUNTERFACTUAL) &&
hasFeature(chain, FEATURES.SAFE_141)
)
}
1 change: 1 addition & 0 deletions src/utils/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export enum FEATURES {
ZODIAC_ROLES = 'ZODIAC_ROLES',
SAFE_141 = 'SAFE_141',
STAKING = 'STAKING',
MULTI_CHAIN_SAFE_CREATION = 'MULTI_CHAIN_SAFE_CREATION',
}

export const FeatureRoutes = {
Expand Down
Loading