Skip to content

Commit

Permalink
fix: check deployed contracts in isMigrationToL2Possible
Browse files Browse the repository at this point in the history
  • Loading branch information
schmanu committed Oct 2, 2024
1 parent cae47e2 commit e8e316b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
22 changes: 21 additions & 1 deletion src/services/contracts/__tests__/safeContracts.test.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down Expand Up @@ -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()
})
})
})
6 changes: 5 additions & 1 deletion src/services/contracts/safeContracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = (
Expand Down

0 comments on commit e8e316b

Please sign in to comment.