Skip to content

Commit

Permalink
fix: do not migrate without migration deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
schmanu committed Oct 2, 2024
1 parent a5b4870 commit cae47e2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
14 changes: 14 additions & 0 deletions src/utils/__tests__/transactions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,20 @@ describe('transactions', () => {
)
})

it('should not modify tx if the chain has no migration lib deployed', () => {
const safeTx = safeTxBuilder()
.with({ data: safeTxDataBuilder().with({ nonce: 0 }).build() })
.build()

const safeInfo = extendedSafeInfoBuilder()
.with({ implementationVersionState: ImplementationVersionState.UNKNOWN })
.build()

expect(
prependSafeToL2Migration(safeTx, safeInfo, chainBuilder().with({ l2: true, chainId: '69420' }).build()),
).resolves.toEqual(safeTx)
})

it('should not modify tx if the tx already migrates', () => {
const safeL2SingletonDeployment = getSafeL2SingletonDeployment()?.defaultAddress

Expand Down
23 changes: 9 additions & 14 deletions src/utils/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,33 +261,28 @@ export const prependSafeToL2Migration = (
throw new Error('No Network information available')
}

const safeL2Deployment = getSafeContractDeployment(chain, safe.version)
const safeL2DeploymentAddress = safeL2Deployment?.networkAddresses[chain.chainId]
const safeToL2MigrationDeployment = getSafeToL2MigrationDeployment({ network: chain.chainId })
const safeToL2MigrationAddress = safeToL2MigrationDeployment?.networkAddresses[chain.chainId]

if (
!safeTx ||
safeTx.signatures.size > 0 ||
!chain.l2 ||
safeTx.data.nonce > 0 ||
isValidMasterCopy(safe.implementationVersionState)
isValidMasterCopy(safe.implementationVersionState) ||
!safeToL2MigrationAddress ||
!safeL2DeploymentAddress
) {
// We do not migrate on L1s
// We cannot migrate if the nonce is > 0
// We do not modify already signed txs
// We do not modify supported masterCopies
// We cannot migrate if no migration contract or L2 contract exists
return Promise.resolve(safeTx)
}

const safeL2Deployment = getSafeContractDeployment(chain, safe.version)
const safeL2DeploymentAddress = safeL2Deployment?.networkAddresses[chain.chainId]
const safeToL2MigrationDeployment = getSafeToL2MigrationDeployment({ network: chain?.chainId })

if (!safeL2DeploymentAddress) {
throw new Error('No L2 MasterCopy found')
}

if (!safeToL2MigrationDeployment) {
throw new Error('No safe to L2 migration contract found')
}

const safeToL2MigrationAddress = safeToL2MigrationDeployment.defaultAddress
const safeToL2MigrationInterface = Safe_to_l2_migration__factory.createInterface()

if (sameAddress(safe.implementation.value, safeL2DeploymentAddress)) {
Expand Down

0 comments on commit cae47e2

Please sign in to comment.