diff --git a/src/services/contracts/__tests__/safeContracts.test.ts b/src/services/contracts/__tests__/safeContracts.test.ts index 6e269bdc85..d81dcc21c1 100644 --- a/src/services/contracts/__tests__/safeContracts.test.ts +++ b/src/services/contracts/__tests__/safeContracts.test.ts @@ -1,5 +1,11 @@ import { ImplementationVersionState } from '@safe-global/safe-gateway-typescript-sdk' -import { _getValidatedGetContractProps, isValidMasterCopy, _getMinimumMultiSendCallOnlyVersion } from '../safeContracts' +import { + _getValidatedGetContractProps, + isValidMasterCopy, + _getMinimumMultiSendCallOnlyVersion, + isMigrationToL2Possible, +} from '../safeContracts' +import { safeInfoBuilder } from '@/tests/builders/safe' describe('safeContracts', () => { describe('isValidMasterCopy', () => { @@ -63,4 +69,18 @@ describe('safeContracts', () => { expect(_getMinimumMultiSendCallOnlyVersion('1.4.1')).toBe('1.4.1') }) }) + + describe('isMigrationToL2Possible', () => { + it('should not be possible to migrate Safes on chains without migration lib', () => { + expect(isMigrationToL2Possible(safeInfoBuilder().with({ nonce: 0, chainId: '69420' }).build())).toBeFalsy() + }) + + it('should not be possible to migrate Safes with nonce > 0', () => { + expect(isMigrationToL2Possible(safeInfoBuilder().with({ nonce: 2, chainId: '10' }).build())).toBeFalsy() + }) + + it('should be possible to migrate Safes with nonce 0 on chains with migration lib', () => { + expect(isMigrationToL2Possible(safeInfoBuilder().with({ nonce: 0, chainId: '10' }).build())).toBeTruthy() + }) + }) }) diff --git a/src/services/contracts/safeContracts.ts b/src/services/contracts/safeContracts.ts index 044186a0ec..8a545fae69 100644 --- a/src/services/contracts/safeContracts.ts +++ b/src/services/contracts/safeContracts.ts @@ -15,6 +15,7 @@ import type { SafeVersion } from '@safe-global/safe-core-sdk-types' import { assertValidSafeVersion, getSafeSDK } from '@/hooks/coreSDK/safeCoreSDK' import semver from 'semver' import { getLatestSafeVersion } from '@/utils/chains' +import { getSafeToL2MigrationDeployment } from '@safe-global/safe-deployments' // `UNKNOWN` is returned if the mastercopy does not match supported ones // @see https://github.com/safe-global/safe-client-gateway/blob/main/src/routes/safes/handlers/safes.rs#L28-L31 @@ -24,7 +25,10 @@ export const isValidMasterCopy = (implementationVersionState: SafeInfo['implemen } export const isMigrationToL2Possible = (safe: SafeInfo): boolean => { - return safe.nonce === 0 + return ( + safe.nonce === 0 && + Boolean(getSafeToL2MigrationDeployment({ network: safe.chainId })?.networkAddresses[safe.chainId]) + ) } export const _getValidatedGetContractProps = (