Skip to content

Commit

Permalink
Fix: rm circular dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
katspaugh committed Dec 19, 2024
1 parent cb19058 commit 3064533
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import useSafeInfo from '@/hooks/useSafeInfo'
import { getExplorerLink } from '@/utils/gateway'
import ErrorMessage from '../ErrorMessage'
import { isValidMasterCopy } from '@/services/contracts/safeContracts'
import { extractMigrationL2MasterCopyAddress } from '@/utils/safe-migrations'
import { extractMigrationL2MasterCopyAddress } from '@/features/multichain/utils/extract-migration-data'

const UnknownContractError = ({ txData }: { txData: TransactionData | undefined }): ReactElement | null => {
const { safe, safeAddress } = useSafeInfo()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Alert, AlertTitle, Box, SvgIcon, Typography } from '@mui/material'
import type { TransactionData } from '@safe-global/safe-gateway-typescript-sdk'
import InfoOutlinedIcon from '@/public/images/notifications/info.svg'
import NamedAddressInfo from '@/components/common/NamedAddressInfo'
import { extractMigrationL2MasterCopyAddress } from '@/utils/safe-migrations'
import { extractMigrationL2MasterCopyAddress } from '@/features/multichain/utils/extract-migration-data'

export const MigrateToL2Information = ({
variant,
Expand Down
32 changes: 32 additions & 0 deletions src/features/multichain/utils/extract-migration-data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import type { TransactionData } from '@safe-global/safe-gateway-typescript-sdk'
import { Safe_to_l2_migration__factory } from '@/types/contracts'
import { sameAddress } from '@/utils/addresses'
import { isMultiSendCalldata } from '@/utils/transaction-calldata'
import { decodeMultiSendData } from '@safe-global/protocol-kit/dist/src/utils'
import { getSafeToL2MigrationDeployment } from '@safe-global/safe-deployments'

export const extractMigrationL2MasterCopyAddress = (txData: TransactionData): string | undefined => {
if (!isMultiSendCalldata(txData.hexData || '')) {
return undefined
}

const innerTxs = decodeMultiSendData(txData.hexData || '')
const firstInnerTx = innerTxs[0]
if (!firstInnerTx) {
return undefined
}

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

if (
firstInnerTx.data.startsWith(safeToL2MigrationInterface.getFunction('migrateToL2').selector) &&
sameAddress(firstInnerTx.to, safeToL2MigrationAddress)
) {
const callParams = safeToL2MigrationInterface.decodeFunctionData('migrateToL2', firstInnerTx.data)
return callParams[0]
}

return undefined
}
3 changes: 2 additions & 1 deletion src/utils/__tests__/safe-migrations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
type TransactionData,
} from '@safe-global/safe-gateway-typescript-sdk'
import { OperationType } from '@safe-global/safe-core-sdk-types'
import { extractMigrationL2MasterCopyAddress, prependSafeToL2Migration } from '../safe-migrations'
import { prependSafeToL2Migration } from '../safe-migrations'
import { extractMigrationL2MasterCopyAddress } from '@/features/multichain/utils/extract-migration-data'
import { extendedSafeInfoBuilder } from '@/tests/builders/safe'
import { chainBuilder } from '@/tests/builders/chains'
import { safeSignatureBuilder, safeTxBuilder, safeTxDataBuilder } from '@/tests/builders/safeTx'
Expand Down
28 changes: 1 addition & 27 deletions src/utils/safe-migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getSafeContractDeployment } from '@/services/contracts/deployments'
import { sameAddress } from './addresses'
import { getSafeToL2MigrationDeployment, getSafeMigrationDeployment } from '@safe-global/safe-deployments'
import { type MetaTransactionData, OperationType, type SafeTransaction } from '@safe-global/safe-core-sdk-types'
import type { ChainInfo, TransactionData } from '@safe-global/safe-gateway-typescript-sdk'
import type { ChainInfo } from '@safe-global/safe-gateway-typescript-sdk'
import { isValidMasterCopy } from '@/services/contracts/safeContracts'
import { isMultiSendCalldata } from './transaction-calldata'
import { decodeMultiSendData } from '@safe-global/protocol-kit/dist/src/utils'
Expand Down Expand Up @@ -95,32 +95,6 @@ export const prependSafeToL2Migration = (
return __unsafe_createMultiSendTx(newTxs)
}

export const extractMigrationL2MasterCopyAddress = (txData: TransactionData): string | undefined => {
if (!isMultiSendCalldata(txData.hexData || '')) {
return undefined
}

const innerTxs = decodeMultiSendData(txData.hexData || '')
const firstInnerTx = innerTxs[0]
if (!firstInnerTx) {
return undefined
}

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

if (
firstInnerTx.data.startsWith(safeToL2MigrationInterface.getFunction('migrateToL2').selector) &&
sameAddress(firstInnerTx.to, safeToL2MigrationAddress)
) {
const callParams = safeToL2MigrationInterface.decodeFunctionData('migrateToL2', firstInnerTx.data)
return callParams[0]
}

return undefined
}

export const createUpdateMigration = (chain: ChainInfo): MetaTransactionData => {
const interfce = Safe_migration__factory.createInterface()

Expand Down
2 changes: 1 addition & 1 deletion src/utils/transaction-guards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ import { isMultiSendCalldata } from './transaction-calldata'
import { decodeMultiSendData } from '@safe-global/protocol-kit/dist/src/utils'
import { OperationType } from '@safe-global/safe-core-sdk-types'
import { LATEST_SAFE_VERSION } from '@/config/constants'
import { extractMigrationL2MasterCopyAddress } from './safe-migrations'
import { extractMigrationL2MasterCopyAddress } from '@/features/multichain/utils/extract-migration-data'

export const isTxQueued = (value: TransactionStatus): boolean => {
return [TransactionStatus.AWAITING_CONFIRMATIONS, TransactionStatus.AWAITING_EXECUTION].includes(value)
Expand Down

0 comments on commit 3064533

Please sign in to comment.